A618 COMPLETE RESEARCH REPORT Generated: 2026-11-26 19:29:00 Repository: C:\Users\qwertyhorik\Desktop\GPU_TRANSFER_2026-11-26\external\qualcomm-kgsl Total repository files: 250 TEXT FILES SCANNED: 213 PREVIOUS RESEARCH FILES: 36 ========================================================================================== SUBSYSTEM: A618_CONFIGURATION ========================================================================================== --- FILE: \adreno-gpulist.h | HITS: 12 --- MATCH LINES: 695 683: {A6XX_RBBM_CLOCK_MODE_HLSQ, 0x00002222}, 684: {A6XX_RBBM_CLOCK_CNTL_GMU_GX, 0x00000222}, 685: {A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111}, 686: {A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555}, 687: }; 688: 689: static const struct kgsl_regmap_list a630_vbif_regs[] = { 690: {A6XX_VBIF_GATE_OFF_WRREQ_EN, 0x00000009}, 691: {A6XX_RBBM_VBIF_CLIENT_QOS_CNTL, 0x3}, 692: }; 693: 694: 695: /* For a615, a616, a618, A619, a630, a640 and a680 */ 696: static const struct adreno_protected_regs a630_protected_regs[] = { 697: { A6XX_CP_PROTECT_REG + 0, 0x00000, 0x004ff, 0 }, 698: { A6XX_CP_PROTECT_REG + 1, 0x00501, 0x00506, 0 }, 699: { A6XX_CP_PROTECT_REG + 2, 0x0050b, 0x007ff, 0 }, 700: { A6XX_CP_PROTECT_REG + 3, 0x0050e, 0x0050e, 1 }, 701: { A6XX_CP_PROTECT_REG + 4, 0x00510, 0x00510, 1 }, 702: { A6XX_CP_PROTECT_REG + 5, 0x00534, 0x00534, 1 }, 703: { A6XX_CP_PROTECT_REG + 6, 0x00800, 0x00882, 1 }, 704: { A6XX_CP_PROTECT_REG + 7, 0x008a0, 0x008a8, 1 }, 705: { A6XX_CP_PROTECT_REG + 8, 0x008ab, 0x008cf, 1 }, 706: { A6XX_CP_PROTECT_REG + 9, 0x008d0, 0x0098c, 0 }, 707: { A6XX_CP_PROTECT_REG + 10, 0x00900, 0x0094d, 1 }, 708: { A6XX_CP_PROTECT_REG + 11, 0x0098d, 0x00bff, 1 }, 709: { A6XX_CP_PROTECT_REG + 12, 0x00e00, 0x00e01, 1 }, 710: { A6XX_CP_PROTECT_REG + 13, 0x00e03, 0x00e0f, 1 }, 711: { A6XX_CP_PROTECT_REG + 14, 0x03c00, 0x03cc3, 1 }, 712: { A6XX_CP_PROTECT_REG + 15, 0x03cc4, 0x05cc3, 0 }, 713: { A6XX_CP_PROTECT_REG + 16, 0x08630, 0x087ff, 1 }, 714: { A6XX_CP_PROTECT_REG + 17, 0x08e00, 0x08e00, 1 }, 715: { A6XX_CP_PROTECT_REG + 18, 0x08e08, 0x08e08, 1 }, 716: { A6XX_CP_PROTECT_REG + 19, 0x08e50, 0x08e6f, 1 }, 717: { A6XX_CP_PROTECT_REG + 20, 0x09624, 0x097ff, 1 }, 718: { A6XX_CP_PROTECT_REG + 21, 0x09e70, 0x09e71, 1 }, 719: { A6XX_CP_PROTECT_REG + 22, 0x09e78, 0x09fff, 1 }, MATCH LINES: 737, 759 725: { A6XX_CP_PROTECT_REG + 28, 0x0be20, 0x0d5ff, 1 }, 726: { A6XX_CP_PROTECT_REG + 29, 0x0f000, 0x0fbff, 1 }, 727: { A6XX_CP_PROTECT_REG + 30, 0x0fc00, 0x11bff, 0 }, 728: { A6XX_CP_PROTECT_REG + 31, 0x11c00, 0x11c00, 1 }, 729: { 0 }, 730: }; 731: 732: static const struct adreno_a6xx_core adreno_gpu_core_a630v2 = { 733: .base = { 734: DEFINE_ADRENO_REV(ADRENO_REV_A630, 6, 3, 0, ANY_ID), 735: .features = ADRENO_IFPC | ADRENO_CONTENT_PROTECTION | 736: ADRENO_IOCOHERENT | ADRENO_PREEMPTION, 737: .gpudev = &adreno_a630_gpudev.base, 738: .perfcounters = &adreno_a630_perfcounters, 739: .uche_gmem_alignment = SZ_1M, 740: .gmem_size = SZ_1M, 741: .bus_width = 32, 742: .snapshot_size = SZ_1M, 743: .highest_bank_bit = 15, 744: }, 745: .prim_fifo_threshold = 0x0018000, 746: .gmu_major = 1, 747: .gmu_minor = 3, 748: .sqefw_name = "a630_sqe.fw", 749: .gmufw_name = "a630_gmu.bin", 750: .zap_name = "a630_zap.mdt", 751: .hwcg = a630_hwcg_regs, 752: .hwcg_count = ARRAY_SIZE(a630_hwcg_regs), 753: .vbif = a630_vbif_regs, 754: .vbif_count = ARRAY_SIZE(a630_vbif_regs), 755: .hang_detect_cycles = 0xcfffff, 756: .protected_regs = a630_protected_regs, 757: }; 758: 759: /* For a615, a616, a618 and a619 */ 760: static const struct kgsl_regmap_list a615_hwcg_regs[] = { 761: {A6XX_RBBM_CLOCK_CNTL_SP0, 0x02222222}, 762: {A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220}, 763: {A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000080}, 764: {A6XX_RBBM_CLOCK_HYST_SP0, 0x0000F3CF}, 765: {A6XX_RBBM_CLOCK_CNTL_TP0, 0x02222222}, 766: {A6XX_RBBM_CLOCK_CNTL_TP1, 0x02222222}, 767: {A6XX_RBBM_CLOCK_CNTL2_TP0, 0x22222222}, 768: {A6XX_RBBM_CLOCK_CNTL2_TP1, 0x22222222}, 769: {A6XX_RBBM_CLOCK_CNTL3_TP0, 0x22222222}, 770: {A6XX_RBBM_CLOCK_CNTL3_TP1, 0x22222222}, 771: {A6XX_RBBM_CLOCK_CNTL4_TP0, 0x00022222}, 772: {A6XX_RBBM_CLOCK_CNTL4_TP1, 0x00022222}, 773: {A6XX_RBBM_CLOCK_HYST_TP0, 0x77777777}, 774: {A6XX_RBBM_CLOCK_HYST_TP1, 0x77777777}, 775: {A6XX_RBBM_CLOCK_HYST2_TP0, 0x77777777}, 776: {A6XX_RBBM_CLOCK_HYST2_TP1, 0x77777777}, 777: {A6XX_RBBM_CLOCK_HYST3_TP0, 0x77777777}, 778: {A6XX_RBBM_CLOCK_HYST3_TP1, 0x77777777}, 779: {A6XX_RBBM_CLOCK_HYST4_TP0, 0x00077777}, 780: {A6XX_RBBM_CLOCK_HYST4_TP1, 0x00077777}, 781: {A6XX_RBBM_CLOCK_DELAY_TP0, 0x11111111}, 782: {A6XX_RBBM_CLOCK_DELAY_TP1, 0x11111111}, 783: {A6XX_RBBM_CLOCK_DELAY2_TP0, 0x11111111}, MATCH LINES: 826, 837, 859, 861, 865, 893 814: {A6XX_RBBM_CLOCK_HYST_VFD, 0x00000000}, 815: {A6XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000}, 816: {A6XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000}, 817: {A6XX_RBBM_CLOCK_DELAY_GPC, 0x00000200}, 818: {A6XX_RBBM_CLOCK_DELAY_VFD, 0x00002222}, 819: {A6XX_RBBM_CLOCK_DELAY_HLSQ_2, 0x00000002}, 820: {A6XX_RBBM_CLOCK_MODE_HLSQ, 0x00002222}, 821: {A6XX_RBBM_CLOCK_CNTL_GMU_GX, 0x00000222}, 822: {A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111}, 823: {A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555} 824: }; 825: 826: /* For a615, a616, a618 and a619 */ 827: static const struct kgsl_regmap_list a615_gbif_regs[] = { 828: {A6XX_RBBM_VBIF_CLIENT_QOS_CNTL, 0x3}, 829: }; 830: 831: static const struct adreno_a6xx_core adreno_gpu_core_a615 = { 832: .base = { 833: DEFINE_ADRENO_REV(ADRENO_REV_A615, 6, 1, 5, ANY_ID), 834: .features = ADRENO_PREEMPTION | 835: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | 836: ADRENO_IOCOHERENT, 837: .gpudev = &adreno_a630_gpudev.base, 838: .perfcounters = &adreno_a6xx_legacy_perfcounters, 839: .uche_gmem_alignment = SZ_1M, 840: .gmem_size = SZ_512K, 841: .bus_width = 32, 842: .snapshot_size = SZ_1M, 843: .highest_bank_bit = 14, 844: }, 845: .prim_fifo_threshold = 0x0018000, 846: .gmu_major = 1, 847: .gmu_minor = 3, 848: .sqefw_name = "a630_sqe.fw", 849: .gmufw_name = "a630_gmu.bin", 850: .zap_name = "a615_zap.mdt", 851: .hwcg = a615_hwcg_regs, 852: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs), 853: .vbif = a615_gbif_regs, 854: .vbif_count = ARRAY_SIZE(a615_gbif_regs), 855: .hang_detect_cycles = 0xcfffff, 856: .protected_regs = a630_protected_regs, 857: }; 858: 859: static const struct adreno_a6xx_core adreno_gpu_core_a618 = { 860: .base = { 861: DEFINE_ADRENO_REV(ADRENO_REV_A618, 6, 1, 8, ANY_ID), 862: .features = ADRENO_PREEMPTION | 863: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | 864: ADRENO_IOCOHERENT, 865: .gpudev = &adreno_a630_gpudev.base, 866: .perfcounters = &adreno_a6xx_legacy_perfcounters, 867: .uche_gmem_alignment = SZ_1M, 868: .gmem_size = SZ_512K, 869: .bus_width = 32, 870: .snapshot_size = SZ_1M, 871: .highest_bank_bit = 14, 872: }, 873: .prim_fifo_threshold = 0x0018000, 874: .gmu_major = 1, 875: .gmu_minor = 7, 876: .sqefw_name = "a630_sqe.fw", 877: .gmufw_name = "a630_gmu.bin", 878: .zap_name = "a615_zap.mdt", 879: .hwcg = a615_hwcg_regs, 880: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs), 881: .vbif = a615_gbif_regs, 882: .vbif_count = ARRAY_SIZE(a615_gbif_regs), 883: .hang_detect_cycles = 0x3fffff, 884: .protected_regs = a630_protected_regs, 885: }; 886: 887: static const struct adreno_a6xx_core adreno_gpu_core_a619 = { 888: .base = { 889: DEFINE_ADRENO_REV(ADRENO_REV_A619, 6, 1, 9, ANY_ID), 890: .features = ADRENO_PREEMPTION | 891: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | 892: ADRENO_IOCOHERENT, 893: .gpudev = &adreno_a630_gpudev.base, 894: .perfcounters = &adreno_a6xx_legacy_perfcounters, 895: .uche_gmem_alignment = SZ_1M, 896: .gmem_size = SZ_512K, 897: .bus_width = 32, 898: .snapshot_size = SZ_2M, 899: .highest_bank_bit = 14, 900: }, 901: .prim_fifo_threshold = 0x0018000, 902: .gmu_major = 1, 903: .gmu_minor = 9, 904: .sqefw_name = "a630_sqe.fw", 905: .gmufw_name = "a619_gmu.bin", 906: .zap_name = "a615_zap.mdt", 907: .hwcg = a615_hwcg_regs, 908: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs), 909: .vbif = a615_gbif_regs, 910: .vbif_count = ARRAY_SIZE(a615_gbif_regs), 911: .hang_detect_cycles = 0x3fffff, 912: .protected_regs = a630_protected_regs, 913: }; 914: 915: static const struct adreno_a6xx_core adreno_gpu_core_a619_variant = { 916: .base = { 917: DEFINE_ADRENO_REV(ADRENO_REV_A619, 6, 1, 9, ANY_ID), MATCH LINES: 1052 1040: { A6XX_CP_PROTECT_REG + 37, 0x1f844, 0x1f8bf, 0 }, 1041: { A6XX_CP_PROTECT_REG + 38, 0x1f887, 0x1f8a2, 1 }, 1042: { A6XX_CP_PROTECT_REG + 47, 0x1f8c0, 0x1f8c0, 1 }, 1043: { 0 }, 1044: }; 1045: 1046: static const struct adreno_a6xx_core adreno_gpu_core_a620 = { 1047: .base = { 1048: DEFINE_ADRENO_REV(ADRENO_REV_A620, 6, 2, 0, ANY_ID), 1049: .features = ADRENO_CONTENT_PROTECTION | ADRENO_IOCOHERENT | 1050: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_ACD | 1051: ADRENO_APRIV, 1052: .gpudev = &adreno_a630_gpudev.base, 1053: .perfcounters = &adreno_a6xx_perfcounters, 1054: .uche_gmem_alignment = 0, 1055: .gmem_size = SZ_512K, 1056: .bus_width = 32, 1057: .snapshot_size = 2 * SZ_1M, 1058: .highest_bank_bit = 14, 1059: }, 1060: .prim_fifo_threshold = 0x0010000, 1061: .gmu_major = 2, 1062: .gmu_minor = 0, 1063: .sqefw_name = "a650_sqe.fw", 1064: .gmufw_name = "a650_gmu.bin", 1065: .zap_name = "a620_zap.mdt", 1066: .hwcg = a620_hwcg_regs, 1067: .hwcg_count = ARRAY_SIZE(a620_hwcg_regs), 1068: .vbif = a650_gbif_regs, 1069: .vbif_count = ARRAY_SIZE(a650_gbif_regs), 1070: .veto_fal10 = true, 1071: .hang_detect_cycles = 0x3ffff, 1072: .protected_regs = a620_protected_regs, 1073: .disable_tseskip = true, 1074: }; 1075: 1076: static const struct adreno_a6xx_core adreno_gpu_core_a621 = { MATCH LINES: 1507 1495: .vbif = a640_vbif_regs, 1496: .vbif_count = ARRAY_SIZE(a640_vbif_regs), 1497: .hang_detect_cycles = 0x3fffff, 1498: .protected_regs = a630_protected_regs, 1499: }; 1500: 1501: static const struct adreno_a6xx_core adreno_gpu_core_a616 = { 1502: .base = { 1503: DEFINE_ADRENO_REV(ADRENO_REV_A616, 6, 1, 6, ANY_ID), 1504: .features = ADRENO_PREEMPTION | 1505: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | 1506: ADRENO_IOCOHERENT, 1507: .gpudev = &adreno_a630_gpudev.base, 1508: .perfcounters = &adreno_a6xx_legacy_perfcounters, 1509: .uche_gmem_alignment = SZ_1M, 1510: .gmem_size = SZ_512K, 1511: .bus_width = 32, 1512: .snapshot_size = SZ_1M, 1513: .highest_bank_bit = 14, 1514: }, 1515: .prim_fifo_threshold = 0x0018000, 1516: .gmu_major = 1, 1517: .gmu_minor = 3, 1518: .sqefw_name = "a630_sqe.fw", 1519: .gmufw_name = "a630_gmu.bin", 1520: .zap_name = "a615_zap.mdt", 1521: .hwcg = a615_hwcg_regs, 1522: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs), 1523: .vbif = a615_gbif_regs, 1524: .vbif_count = ARRAY_SIZE(a615_gbif_regs), 1525: .hang_detect_cycles = 0xcfffff, 1526: .protected_regs = a630_protected_regs, 1527: }; 1528: 1529: static const struct adreno_a6xx_core adreno_gpu_core_a610 = { 1530: .base = { 1531: DEFINE_ADRENO_REV(ADRENO_REV_A610, 6, 1, 0, ANY_ID), MATCH LINES: 5080 5068: &adreno_gpu_core_a530v2.base, 5069: &adreno_gpu_core_a530v3.base, 5070: &adreno_gpu_core_a505.base, 5071: &adreno_gpu_core_a506.base, 5072: &adreno_gpu_core_a510.base, 5073: &adreno_gpu_core_a540v1, /* Deprecated */ 5074: &adreno_gpu_core_a540v2.base, 5075: &adreno_gpu_core_a512.base, 5076: &adreno_gpu_core_a508.base, 5077: &adreno_gpu_core_a630v1, /* Deprecated */ 5078: &adreno_gpu_core_a630v2.base, 5079: &adreno_gpu_core_a615.base, 5080: &adreno_gpu_core_a618.base, 5081: &adreno_gpu_core_a619.base, 5082: &adreno_gpu_core_a619_variant.base, 5083: &adreno_gpu_core_a620.base, 5084: &adreno_gpu_core_a621.base, 5085: &adreno_gpu_core_a622.base, 5086: &adreno_gpu_core_a623.base, 5087: &adreno_gpu_core_a640.base, 5088: &adreno_gpu_core_a642l.base, 5089: &adreno_gpu_core_a643.base, 5090: &adreno_gpu_core_a650.base, 5091: &adreno_gpu_core_a650v2.base, 5092: &adreno_gpu_core_a660.base, 5093: &adreno_gpu_core_a660v2.base, 5094: &adreno_gpu_core_a663.base, 5095: &adreno_gpu_core_a680.base, 5096: &adreno_gpu_core_a612.base, 5097: &adreno_gpu_core_a616.base, 5098: &adreno_gpu_core_a610.base, 5099: &adreno_gpu_core_a611.base, 5100: &adreno_gpu_core_a660_shima.base, 5101: &adreno_gpu_core_gen6_3_26_0.base, 5102: &adreno_gpu_core_a702.base, 5103: &adreno_gpu_core_a704.base, 5104: &adreno_gpu_core_gen7_0_0.base, --- FILE: \adreno.h | HITS: 4 --- MATCH LINES: 281 269: ADRENO_REV_A505 = 505, 270: ADRENO_REV_A506 = 506, 271: ADRENO_REV_A508 = 508, 272: ADRENO_REV_A510 = 510, 273: ADRENO_REV_A512 = 512, 274: ADRENO_REV_A530 = 530, 275: ADRENO_REV_A540 = 540, 276: ADRENO_REV_A610 = 610, 277: ADRENO_REV_A611 = 611, 278: ADRENO_REV_A612 = 612, 279: ADRENO_REV_A615 = 615, 280: ADRENO_REV_A616 = 616, 281: ADRENO_REV_A618 = 618, 282: ADRENO_REV_A619 = 619, 283: ADRENO_REV_A620 = 620, 284: ADRENO_REV_A621 = 621, 285: ADRENO_REV_A622 = 622, 286: ADRENO_REV_A623 = 623, 287: ADRENO_REV_A630 = 630, 288: ADRENO_REV_A640 = 640, 289: ADRENO_REV_A642 = 642, 290: ADRENO_REV_A643 = 643, 291: ADRENO_REV_A650 = 650, 292: ADRENO_REV_A660 = 660, 293: ADRENO_REV_A662 = 662, 294: ADRENO_REV_A663 = 663, 295: ADRENO_REV_A680 = 680, 296: ADRENO_REV_A702 = 702, 297: ADRENO_REV_A704 = 704, 298: /* 299: * Version numbers may exceed 1 digit 300: * Bits 16-23: Major 301: * Bits 8-15: Minor 302: * Bits 0-7: Patch id 303: */ 304: ADRENO_REV_GEN6_3_26_0 = ADRENO_GPUREV_VALUE(3, 26, 0), 305: ADRENO_REV_GEN7_0_0 = ADRENO_GPUREV_VALUE(7, 0, 0), MATCH LINES: 1382, 1409, 1416 1370: 1371: static inline int adreno_is_a660_shima(struct adreno_device *adreno_dev) 1372: { 1373: return (ADRENO_GPUREV(adreno_dev) == ADRENO_REV_A660) && 1374: (adreno_dev->gpucore->compatible && 1375: !strcmp(adreno_dev->gpucore->compatible, 1376: "qcom,adreno-gpu-a660-shima")); 1377: } 1378: 1379: ADRENO_TARGET(a610, ADRENO_REV_A610) 1380: ADRENO_TARGET(a611, ADRENO_REV_A611) 1381: ADRENO_TARGET(a612, ADRENO_REV_A612) 1382: ADRENO_TARGET(a618, ADRENO_REV_A618) 1383: ADRENO_TARGET(a619, ADRENO_REV_A619) 1384: ADRENO_TARGET(a621, ADRENO_REV_A621) 1385: ADRENO_TARGET(a622, ADRENO_REV_A622) 1386: ADRENO_TARGET(a623, ADRENO_REV_A623) 1387: ADRENO_TARGET(a630, ADRENO_REV_A630) 1388: ADRENO_TARGET(a662, ADRENO_REV_A662) 1389: ADRENO_TARGET(a640, ADRENO_REV_A640) 1390: ADRENO_TARGET(a643, ADRENO_REV_A643) 1391: ADRENO_TARGET(a650, ADRENO_REV_A650) 1392: ADRENO_TARGET(a663, ADRENO_REV_A663) 1393: ADRENO_TARGET(a680, ADRENO_REV_A680) 1394: ADRENO_TARGET(gen6_3_26_0, ADRENO_REV_GEN6_3_26_0) 1395: ADRENO_TARGET(a702, ADRENO_REV_A702) 1396: ADRENO_TARGET(a704, ADRENO_REV_A704) 1397: 1398: /* A642L and A643 is derived from A660 and shares same logic */ 1399: static inline int adreno_is_a660(struct adreno_device *adreno_dev) 1400: { 1401: unsigned int rev = ADRENO_GPUREV(adreno_dev); 1402: 1403: return (rev == ADRENO_REV_A660 || adreno_is_a642l(adreno_dev) || 1404: rev == ADRENO_REV_A643 || rev == ADRENO_REV_A662); 1405: } 1406: 1407: /* 1408: * All the derived chipsets from A615 needs to be added to this 1409: * list such as A616, A618, A619 etc. 1410: */ 1411: static inline int adreno_is_a615_family(struct adreno_device *adreno_dev) 1412: { 1413: unsigned int rev = ADRENO_GPUREV(adreno_dev); 1414: 1415: return (rev == ADRENO_REV_A615 || rev == ADRENO_REV_A616 || 1416: rev == ADRENO_REV_A618 || rev == ADRENO_REV_A619); 1417: } 1418: 1419: /* 1420: * Derived GPUs from A640 needs to be added to this list. 1421: * A640 and A680 belongs to this family. 1422: */ 1423: static inline int adreno_is_a640_family(struct adreno_device *adreno_dev) 1424: { 1425: unsigned int rev = ADRENO_GPUREV(adreno_dev); 1426: 1427: return (rev == ADRENO_REV_A640 || rev == ADRENO_REV_A680); 1428: } 1429: 1430: /* 1431: * Derived GPUs from A650 needs to be added to this list. 1432: * A650 is derived from A640 but register specs has been 1433: * changed hence do not belongs to A640 family. A620, A621, 1434: * A622, A642L, A643, A660, A663, A690 follows the register 1435: * specs of A650. 1436: * 1437: */ 1438: static inline int adreno_is_a650_family(struct adreno_device *adreno_dev) 1439: { 1440: unsigned int rev = ADRENO_GPUREV(adreno_dev); --- FILE: \adreno_a6xx.c | HITS: 1 --- MATCH LINES: 2510 2498: .read_alwayson = a6xx_read_alwayson, 2499: .power_ops = &adreno_power_operations, 2500: .clear_pending_transactions = a6xx_clear_pending_transactions, 2501: .deassert_gbif_halt = a6xx_deassert_gbif_halt, 2502: .remove = a6xx_remove, 2503: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2504: .is_hw_collapsible = adreno_isidle, 2505: .power_stats = a6xx_power_stats, 2506: .add_to_va_minidump = a6xx_dev_add_to_minidump, 2507: .gx_is_on = a619_holi_gx_is_on, 2508: }; 2509: 2510: const struct a6xx_gpudev adreno_a630_gpudev = { 2511: .base = { 2512: .reg_offsets = a6xx_register_offsets, 2513: .probe = a6xx_gmu_device_probe, 2514: .snapshot = a6xx_gmu_snapshot, 2515: .irq_handler = a6xx_irq_handler, 2516: .rb_start = a6xx_rb_start, 2517: .regulator_enable = a6xx_sptprac_enable, 2518: .regulator_disable = a6xx_sptprac_disable, 2519: .gpu_keepalive = a6xx_gpu_keepalive, 2520: .hw_isidle = a6xx_hw_isidle, 2521: .iommu_fault_block = a6xx_iommu_fault_block, 2522: .reset = a6xx_gmu_reset, 2523: .preemption_schedule = a6xx_preemption_schedule, 2524: .read_alwayson = a6xx_read_alwayson, 2525: .power_ops = &a630_gmu_power_ops, 2526: .remove = a6xx_remove, 2527: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2528: .power_stats = a6xx_power_stats, 2529: .add_to_va_minidump = a6xx_gmu_add_to_minidump, 2530: .gx_is_on = a6xx_gmu_gx_is_on, 2531: }, 2532: .hfi_probe = a6xx_gmu_hfi_probe, 2533: .handle_watchdog = a6xx_gmu_handle_watchdog, 2534: }; --- FILE: \adreno_a6xx.h | HITS: 1 --- MATCH LINES: 28 16: extern const struct adreno_power_ops a6xx_gmu_power_ops; 17: extern const struct adreno_power_ops a6xx_rgmu_power_ops; 18: extern const struct adreno_power_ops a630_gmu_power_ops; 19: extern const struct adreno_power_ops a6xx_hwsched_power_ops; 20: 21: struct a6xx_gpudev { 22: struct adreno_gpudev base; 23: int (*hfi_probe)(struct adreno_device *adreno_dev); 24: void (*hfi_remove)(struct adreno_device *adreno_dev); 25: void (*handle_watchdog)(struct adreno_device *adreno_dev); 26: }; 27: 28: extern const struct a6xx_gpudev adreno_a630_gpudev; 29: extern const struct a6xx_gpudev adreno_a6xx_gmu_gpudev; 30: extern const struct a6xx_gpudev adreno_a6xx_hwsched_gpudev; 31: 32: /** 33: * struct a6xx_device - Container for the a6xx_device 34: */ 35: struct a6xx_device { 36: /** @gmu: Container for the a6xx GMU device */ 37: struct a6xx_gmu_device gmu; 38: /** @rgmu: Container for the a6xx rGMU device */ 39: struct a6xx_rgmu_device rgmu; 40: /** @adreno_dev: Container for the generic adreno device */ 41: struct adreno_device adreno_dev; 42: }; 43: 44: /** 45: * struct adreno_a6xx_core - a6xx specific GPU core definitions 46: */ 47: struct adreno_a6xx_core { 48: /** @base: Container for the generic GPU definitions */ 49: struct adreno_gpu_core base; 50: /** @gmu_major: The maximum GMU version supported by the core */ 51: u32 gmu_major; 52: /** @gmu_minor: The minimum GMU version supported by the core */ --- FILE: \adreno_a6xx_gmu.c | HITS: 1 --- MATCH LINES: 513 501: 0x0); 502: } 503: 504: _regwrite(cfg, PDC_GPU_TCS3_CMD_ENABLE_BANK, 7); 505: _regwrite(cfg, PDC_GPU_TCS3_CMD_WAIT_FOR_CMPL_BANK, 0); 506: _regwrite(cfg, PDC_GPU_TCS3_CONTROL, 0); 507: _regwrite(cfg, PDC_GPU_TCS3_CMD0_MSGID, 0x10108); 508: _regwrite(cfg, PDC_GPU_TCS3_CMD0_ADDR, mx_res_addr); 509: _regwrite(cfg, PDC_GPU_TCS3_CMD0_DATA, 2); 510: _regwrite(cfg, PDC_GPU_TCS3_CMD0_MSGID + PDC_CMD_OFFSET, 0x10108); 511: _regwrite(cfg, PDC_GPU_TCS3_CMD0_ADDR + PDC_CMD_OFFSET, cx_res_addr); 512: 513: if (adreno_is_a618(adreno_dev) || adreno_is_a619(adreno_dev) || 514: adreno_is_a650_family(adreno_dev)) 515: _regwrite(cfg, PDC_GPU_TCS3_CMD0_DATA + PDC_CMD_OFFSET, 0x2); 516: else 517: _regwrite(cfg, PDC_GPU_TCS3_CMD0_DATA + PDC_CMD_OFFSET, 0x3); 518: 519: _regwrite(cfg, PDC_GPU_TCS3_CMD0_MSGID + PDC_CMD_OFFSET * 2, 0x10108); 520: 521: _regwrite(cfg, PDC_GPU_TCS3_CMD0_ADDR + PDC_CMD_OFFSET * 2, 522: xo_resource_addr); 523: 524: _regwrite(cfg, PDC_GPU_TCS3_CMD0_DATA + PDC_CMD_OFFSET * 2, 0x3); 525: 526: if (vrm_resource_addr && adreno_is_a620(adreno_dev)) { 527: _regwrite(cfg, PDC_GPU_TCS3_CMD0_MSGID + PDC_CMD_OFFSET * 3, 528: 0x10108); 529: _regwrite(cfg, PDC_GPU_TCS3_CMD0_ADDR + PDC_CMD_OFFSET * 3, 530: vrm_resource_addr + 0x4); 531: _regwrite(cfg, PDC_GPU_TCS3_CMD0_DATA + PDC_CMD_OFFSET * 3, 532: 0x1); 533: } 534: 535: done: 536: /* Setup GPU PDC */ 537: _regwrite(cfg, PDC_GPU_SEQ_START_ADDR, 0); --- FILE: \adreno_a6xx_perfcounter.c | HITS: 1 --- MATCH LINES: 945 933: a6xx_counter_alwayson_enable, a6xx_counter_alwayson_read, NULL), 934: A6XX_PERFCOUNTER_GROUP_FLAGS(GMU_XOCLK, gmu_xoclk, 0, 935: a6xx_counter_gmu_xoclk_enable, a6xx_counter_read_norestore, 936: NULL), 937: A6XX_PERFCOUNTER_GROUP_FLAGS(GMU_GMUCLK, gmu_gmuclk, 0, 938: a6xx_counter_gmu_gmuclk_enable, a6xx_counter_read_norestore, 939: NULL), 940: A6XX_PERFCOUNTER_GROUP_FLAGS(GMU_PERF, gmu_perf, 0, 941: a6xx_counter_gmu_perf_enable, a6xx_counter_read_norestore, 942: NULL), 943: }; 944: 945: /* a610, a612, gen6_3_26_0, a616, a618 and a619 do not have the GMU registers. 946: * a605, a608, a615, a630, a640 and a680 don't have enough room in the 947: * CP_PROTECT registers so the GMU counters are not accessible 948: */ 949: const struct adreno_perfcounters adreno_a6xx_legacy_perfcounters = { 950: a6xx_legacy_perfcounter_groups, 951: ARRAY_SIZE(a6xx_legacy_perfcounter_groups), 952: }; 953: 954: const struct adreno_perfcounters adreno_a630_perfcounters = { 955: a630_perfcounter_groups, 956: ARRAY_SIZE(a630_perfcounter_groups), 957: }; 958: 959: const struct adreno_perfcounters adreno_a6xx_perfcounters = { 960: a6xx_perfcounter_groups, 961: ARRAY_SIZE(a6xx_perfcounter_groups), 962: }; --- FILE: \gen7_reg.h | HITS: 1 --- MATCH LINES: 848 836: #define GEN7_PC_PERFCTR_PC_SEL_14 0x9e50 837: #define GEN7_PC_PERFCTR_PC_SEL_15 0x9e51 838: 839: /* VFD registers */ 840: #define GEN7_VFD_PERFCTR_VFD_SEL_0 0xa610 841: #define GEN7_VFD_PERFCTR_VFD_SEL_1 0xa611 842: #define GEN7_VFD_PERFCTR_VFD_SEL_2 0xa612 843: #define GEN7_VFD_PERFCTR_VFD_SEL_3 0xa613 844: #define GEN7_VFD_PERFCTR_VFD_SEL_4 0xa614 845: #define GEN7_VFD_PERFCTR_VFD_SEL_5 0xa615 846: #define GEN7_VFD_PERFCTR_VFD_SEL_6 0xa616 847: #define GEN7_VFD_PERFCTR_VFD_SEL_7 0xa617 848: #define GEN7_VFD_PERFCTR_VFD_SEL_8 0xa618 849: #define GEN7_VFD_PERFCTR_VFD_SEL_9 0xa619 850: #define GEN7_VFD_PERFCTR_VFD_SEL_10 0xa61a 851: #define GEN7_VFD_PERFCTR_VFD_SEL_11 0xa61b 852: #define GEN7_VFD_PERFCTR_VFD_SEL_12 0xa61c 853: #define GEN7_VFD_PERFCTR_VFD_SEL_13 0xa61d 854: #define GEN7_VFD_PERFCTR_VFD_SEL_14 0xa61e 855: #define GEN7_VFD_PERFCTR_VFD_SEL_15 0xa61f 856: 857: /* SP registers */ 858: #define GEN7_SP_READ_SEL 0xae6d 859: #define GEN7_SP_DBG_CNTL 0xae71 860: #define GEN7_SP_AHB_READ_APERTURE 0xc000 861: 862: /* VPC registers */ 863: #define GEN7_VPC_PERFCTR_VPC_SEL_0 0x960b 864: #define GEN7_VPC_PERFCTR_VPC_SEL_1 0x960c 865: #define GEN7_VPC_PERFCTR_VPC_SEL_2 0x960c 866: #define GEN7_VPC_PERFCTR_VPC_SEL_3 0x960e 867: #define GEN7_VPC_PERFCTR_VPC_SEL_4 0x960f 868: #define GEN7_VPC_PERFCTR_VPC_SEL_5 0x9610 869: #define GEN7_VPC_PERFCTR_VPC_SEL_6 0x9611 870: #define GEN7_VPC_PERFCTR_VPC_SEL_7 0x9612 871: #define GEN7_VPC_PERFCTR_VPC_SEL_8 0x9613 872: #define GEN7_VPC_PERFCTR_VPC_SEL_9 0x9614 --- FILE: \gen8_reg.h | HITS: 1 --- MATCH LINES: 1143 1131: 1132: 1133: /* VFD registers */ 1134: #define GEN8_VFD_DBG_ECO_CNTL 0xa600 1135: #define GEN8_VFD_PERFCTR_VFD_SEL_0 0xa610 1136: #define GEN8_VFD_PERFCTR_VFD_SEL_1 0xa611 1137: #define GEN8_VFD_PERFCTR_VFD_SEL_2 0xa612 1138: #define GEN8_VFD_PERFCTR_VFD_SEL_3 0xa613 1139: #define GEN8_VFD_PERFCTR_VFD_SEL_4 0xa614 1140: #define GEN8_VFD_PERFCTR_VFD_SEL_5 0xa615 1141: #define GEN8_VFD_PERFCTR_VFD_SEL_6 0xa616 1142: #define GEN8_VFD_PERFCTR_VFD_SEL_7 0xa617 1143: #define GEN8_VFD_PERFCTR_VFD_SEL_8 0xa618 1144: #define GEN8_VFD_PERFCTR_VFD_SEL_9 0xa619 1145: #define GEN8_VFD_PERFCTR_VFD_SEL_10 0xa61a 1146: #define GEN8_VFD_PERFCTR_VFD_SEL_11 0xa61b 1147: #define GEN8_VFD_PERFCTR_VFD_SEL_12 0xa61c 1148: #define GEN8_VFD_PERFCTR_VFD_SEL_13 0xa61d 1149: #define GEN8_VFD_PERFCTR_VFD_SEL_14 0xa61e 1150: #define GEN8_VFD_PERFCTR_VFD_SEL_15 0xa61f 1151: #define GEN8_VFD_CB_BV_THRESHOLD 0xa639 1152: #define GEN8_VFD_CB_BR_THRESHOLD 0xa63a 1153: #define GEN8_VFD_CB_BUSY_REQ_CNT 0xa63b 1154: #define GEN8_VFD_CB_LP_REQ_CNT 0xa63c 1155: 1156: /* SP registers */ 1157: #define GEN8_SP_DBG_ECO_CNTL 0xae00 1158: #define GEN8_SP_SHADER_PROFILING 0xae01 1159: #define GEN8_SP_NC_MODE_CNTL 0xae02 1160: #define GEN8_SP_CHICKEN_BITS 0xae03 1161: #define GEN8_SP_NC_MODE_CNTL_2 0xae04 1162: #define GEN8_SP_SS_CHICKEN_BITS_0 0xae05 1163: #define GEN8_SP_ISDB_CNTL 0xae06 1164: #define GEN8_SP_PERFCTR_CNTL 0xae07 1165: #define GEN8_SP_CHICKEN_BITS_1 0xae08 1166: #define GEN8_SP_CHICKEN_BITS_2 0xae09 1167: #define GEN8_SP_CHICKEN_BITS_3 0xae0a TOTAL MATCHES: 22 ========================================================================================== SUBSYSTEM: GPU_INITIALIZATION ========================================================================================== --- FILE: \adreno.c | HITS: 16 --- MATCH LINES: 463 451: 452: kgsl_sharedmem_readl(device->scratch, &rptr, 453: SCRATCH_RB_OFFSET(rb->id, rptr)); 454: 455: return rptr; 456: } 457: 458: static void adreno_touch_wakeup(struct adreno_device *adreno_dev) 459: { 460: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 461: 462: /* 463: * Don't schedule adreno_start in a high priority workqueue, we are 464: * already in a workqueue which should be sufficient 465: */ 466: kgsl_pwrctrl_change_state(device, KGSL_STATE_ACTIVE); 467: 468: /* 469: * When waking up from a touch event we want to stay active long enough 470: * for the user to send a draw command. The default idle timer timeout 471: * is shorter than we want so go ahead and push the idle timer out 472: * further for this special case 473: */ 474: mod_timer(&device->idle_timer, 475: jiffies + msecs_to_jiffies(adreno_wake_timeout)); 476: 477: } 478: 479: /* 480: * A workqueue callback responsible for actually turning on the GPU after a 481: * touch event. kgsl_pwrctrl_change_state(ACTIVE) is used without any 482: * active_count protection to avoid the need to maintain state. Either 483: * somebody will start using the GPU or the idle timer will fire and put the 484: * GPU back into slumber. 485: */ 486: static void adreno_input_work(struct work_struct *work) 487: { MATCH LINES: 2453 2441: kgsl_device_platform_remove(device); 2442: 2443: component_unbind_all(dev, NULL); 2444: 2445: kgsl_bus_close(device); 2446: device->pdev = NULL; 2447: 2448: if (device->num_l3_pwrlevels != 0) 2449: qcom_dcvs_unregister_voter(KGSL_L3_DEVICE, DCVS_L3, 2450: DCVS_SLOW_PATH); 2451: 2452: clear_bit(ADRENO_DEVICE_PWRON_FIXUP, &adreno_dev->priv); 2453: clear_bit(ADRENO_DEVICE_INITIALIZED, &adreno_dev->priv); 2454: } 2455: 2456: static void adreno_resume(struct adreno_device *adreno_dev) 2457: { 2458: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2459: 2460: if (device->state == KGSL_STATE_SUSPEND) { 2461: adreno_put_gpu_halt(adreno_dev); 2462: kgsl_pwrctrl_change_state(device, KGSL_STATE_SLUMBER); 2463: } else if (device->state != KGSL_STATE_INIT) { 2464: /* 2465: * This is an error situation so wait for the device to idle and 2466: * then put the device in SLUMBER state. This will get us to 2467: * the right place when we resume. 2468: */ 2469: if (device->state == KGSL_STATE_ACTIVE) 2470: adreno_wait_idle(device); 2471: kgsl_pwrctrl_change_state(device, KGSL_STATE_SLUMBER); 2472: dev_err(device->dev, "resume invoked without a suspend\n"); 2473: } 2474: } 2475: 2476: static int adreno_pm_resume(struct device *dev) 2477: { MATCH LINES: 2587, 2594 2575: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 2576: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 2577: int ret; 2578: 2579: ret = kgsl_pwrctrl_change_state(device, KGSL_STATE_INIT); 2580: if (ret) 2581: return ret; 2582: 2583: /* 2584: * initialization only needs to be done once initially until 2585: * device is shutdown 2586: */ 2587: if (test_bit(ADRENO_DEVICE_INITIALIZED, &adreno_dev->priv)) 2588: return 0; 2589: 2590: ret = gpudev->init(adreno_dev); 2591: if (ret) 2592: return ret; 2593: 2594: set_bit(ADRENO_DEVICE_INITIALIZED, &adreno_dev->priv); 2595: 2596: return 0; 2597: } 2598: 2599: static bool gdscs_left_on(struct kgsl_device *device) 2600: { 2601: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 2602: 2603: if (gmu_core_gpmu_isenabled(device)) 2604: return false; 2605: 2606: if (pwr->cx_regulator) 2607: return regulator_is_enabled(pwr->cx_regulator); 2608: 2609: if (pwr->gx_regulator) 2610: return regulator_is_enabled(pwr->gx_regulator); 2611: 2612: if (pwr->gmu_cx_pd) 2613: return kgsl_genpd_is_enabled(pwr->gmu_cx_pd); 2614: 2615: if (pwr->gx_pd) 2616: return kgsl_genpd_is_enabled(pwr->gx_pd); 2617: 2618: return false; MATCH LINES: 2656 2644: * active_cnt special case: we are starting up for the first 2645: * time, so use this sequence instead of the kgsl_pwrctrl_wake() 2646: * which will be called by adreno_active_count_get(). 2647: */ 2648: atomic_inc(&device->active_cnt); 2649: 2650: memset(device->memstore->hostptr, 0, device->memstore->size); 2651: 2652: ret = adreno_init(device); 2653: if (ret) 2654: goto err; 2655: 2656: ret = adreno_start(device, 0); 2657: if (ret) 2658: goto err; 2659: 2660: complete_all(&device->hwaccess_gate); 2661: set_bit(ADRENO_DEVICE_FIRST_BOOT_DONE, &adreno_dev->priv); 2662: kgsl_pwrctrl_change_state(device, KGSL_STATE_ACTIVE); 2663: adreno_active_count_put(adreno_dev); 2664: 2665: return 0; 2666: err: 2667: kgsl_pwrctrl_change_state(device, KGSL_STATE_INIT); 2668: atomic_dec(&device->active_cnt); 2669: 2670: return ret; 2671: } 2672: 2673: static int adreno_first_open(struct kgsl_device *device) 2674: { 2675: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 2676: const struct adreno_power_ops *ops = ADRENO_POWER_OPS(adreno_dev); 2677: 2678: if (!device->pdev_loaded) 2679: return -ENODEV; 2680: MATCH LINES: 2863, 2869 2851: dev_warn(adreno_dev->dev.dev, "Invalid AHB timeout_val %u\n", timeout_val); 2852: return 0; 2853: } 2854: 2855: /* 2856: * Return (timeout_val - 1). Based on timeout_val programmed, a timeout will occur if 2857: * an AHB transaction is not completed in 2 ^ (timeout_val + 1) cycles. 2858: */ 2859: return (timeout_val - 1); 2860: } 2861: 2862: /** 2863: * _adreno_start - Power up the GPU and prepare to accept commands 2864: * @adreno_dev: Pointer to an adreno_device structure 2865: * 2866: * The core function that powers up and initalizes the GPU. This function is 2867: * called at init and after coming out of SLUMBER 2868: */ 2869: static int _adreno_start(struct adreno_device *adreno_dev) 2870: { 2871: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2872: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 2873: int status; 2874: unsigned int state = device->state; 2875: bool gdsc_left_on; 2876: 2877: /* make sure ADRENO_DEVICE_STARTED is not set here */ 2878: WARN_ON(test_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv)); 2879: 2880: gdsc_left_on = gdscs_left_on(device); 2881: 2882: /* Clear any GPU faults that might have been left over */ 2883: adreno_clear_gpu_fault(adreno_dev); 2884: 2885: /* Put the GPU in a responsive state */ 2886: status = kgsl_pwrctrl_change_state(device, KGSL_STATE_AWARE); 2887: if (status) 2888: goto error_pwr_off; 2889: 2890: /* Set any stale active contexts to NULL */ 2891: adreno_set_active_ctxs_null(adreno_dev); 2892: 2893: /* Set the bit to indicate that we've just powered on */ MATCH LINES: 2918 2906: goto error_pwr_off; 2907: 2908: /* Re-initialize the coresight registers if applicable */ 2909: adreno_coresight_start(adreno_dev); 2910: 2911: adreno_irqctrl(adreno_dev, 1); 2912: 2913: adreno_perfcounter_start(adreno_dev); 2914: 2915: /* Clear FSR here in case it is set from a previous pagefault */ 2916: kgsl_mmu_clear_fsr(&device->mmu); 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 MATCH LINES: 2961, 2969, 2978 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 2964: * latency work queue 2965: * 2966: * Power up the GPU and initialize it. If priority is specified then elevate 2967: * the thread priority for the duration of the start operation 2968: */ 2969: int adreno_start(struct kgsl_device *device, int priority) 2970: { 2971: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 2972: int nice = task_nice(current); 2973: int ret; 2974: 2975: if (priority && (adreno_wake_nice < nice)) 2976: set_user_nice(current, adreno_wake_nice); 2977: 2978: ret = _adreno_start(adreno_dev); 2979: 2980: if (priority) 2981: set_user_nice(current, nice); 2982: 2983: return ret; 2984: } 2985: 2986: static int adreno_stop(struct kgsl_device *device) 2987: { 2988: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 2989: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 2990: int error = 0; 2991: 2992: if (!test_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv)) 2993: return 0; 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*/ MATCH LINES: 3055, 3059 3043: */ 3044: 3045: if (!(fault & ADRENO_IOMMU_STALL_ON_PAGE_FAULT)) 3046: ret = adreno_soft_reset(device); 3047: 3048: if (ret) { 3049: /* If soft reset failed/skipped, then pull the power */ 3050: kgsl_pwrctrl_change_state(device, KGSL_STATE_INIT); 3051: /* since device is officially off now clear start bit */ 3052: clear_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv); 3053: 3054: /* Try to reset the device */ 3055: ret = adreno_start(device, 0); 3056: 3057: for (i = 0; ret && i < 4; i++) { 3058: msleep(20); 3059: ret = adreno_start(device, 0); 3060: } 3061: 3062: if (ret) 3063: return ret; 3064: 3065: if (i != 0) 3066: dev_warn(device->dev, 3067: "Device hard reset tried %d tries\n", i); 3068: } 3069: 3070: /* 3071: * If active_cnt is non-zero then the system was active before 3072: * going into a reset - put it back in that state 3073: */ 3074: 3075: if (atomic_read(&device->active_cnt)) 3076: kgsl_pwrctrl_change_state(device, KGSL_STATE_ACTIVE); 3077: 3078: return ret; 3079: } 3080: 3081: static int copy_prop(struct kgsl_device_getproperty *param, 3082: void *src, size_t size) 3083: { MATCH LINES: 3643 3631: break; 3632: } 3633: 3634: return status; 3635: } 3636: 3637: /* 3638: * adreno_soft_reset - Do a soft reset of the GPU hardware 3639: * @device: KGSL device to soft reset 3640: * 3641: * "soft reset" the GPU hardware - this is a fast path GPU reset 3642: * The GPU hardware is reset but we never pull power so we can skip 3643: * a lot of the standard adreno_stop/adreno_start sequence 3644: */ 3645: static int adreno_soft_reset(struct kgsl_device *device) 3646: { 3647: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 3648: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 3649: int ret; 3650: 3651: if (gpudev->clear_pending_transactions) { 3652: ret = gpudev->clear_pending_transactions(adreno_dev); 3653: if (ret) 3654: return ret; 3655: } 3656: 3657: kgsl_pwrctrl_change_state(device, KGSL_STATE_AWARE); 3658: adreno_set_active_ctxs_null(adreno_dev); 3659: 3660: adreno_irqctrl(adreno_dev, 0); 3661: 3662: adreno_clear_gpu_fault(adreno_dev); 3663: /* since device is oficially off now clear start bit */ 3664: clear_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv); 3665: 3666: /* save physical performance counter values before GPU soft reset */ 3667: adreno_perfcounter_save(adreno_dev); MATCH LINES: 3693 3681: gpudev->start(adreno_dev); 3682: 3683: /* Re-initialize the coresight registers if applicable */ 3684: adreno_coresight_start(adreno_dev); 3685: 3686: /* Enable IRQ */ 3687: adreno_irqctrl(adreno_dev, 1); 3688: 3689: /* stop all ringbuffers to cancel RB events */ 3690: adreno_ringbuffer_stop(adreno_dev); 3691: 3692: /* Start the ringbuffer(s) again */ 3693: ret = gpudev->rb_start(adreno_dev); 3694: if (ret == 0) { 3695: device->reset_counter++; 3696: set_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv); 3697: } 3698: 3699: /* Restore physical performance counter values after soft reset */ 3700: adreno_perfcounter_restore(adreno_dev); 3701: 3702: if (ret) 3703: dev_err(device->dev, "Device soft reset failed: %d\n", ret); 3704: 3705: return ret; 3706: } 3707: 3708: bool adreno_isidle(struct adreno_device *adreno_dev) 3709: { 3710: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 3711: struct adreno_ringbuffer *rb; 3712: int i; 3713: 3714: if (!kgsl_state_is_awake(KGSL_DEVICE(adreno_dev))) 3715: return true; 3716: 3717: /* MATCH LINES: 4715 4703: 4704: static bool adreno_is_first_boot_done(struct kgsl_device *device) 4705: { 4706: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4707: 4708: return test_bit(ADRENO_DEVICE_FIRST_BOOT_DONE, &adreno_dev->priv); 4709: } 4710: 4711: static const struct kgsl_functable adreno_functable = { 4712: /* Mandatory functions */ 4713: .check_idle = adreno_check_idle, 4714: .first_open = adreno_first_open, 4715: .start = adreno_start, 4716: .stop = adreno_stop, 4717: .last_close = adreno_last_close, 4718: .getproperty = adreno_getproperty, 4719: .getproperty_compat = adreno_getproperty_compat, 4720: .waittimestamp = adreno_waittimestamp, 4721: .readtimestamp = adreno_readtimestamp, 4722: .queue_cmds = adreno_queue_cmds, 4723: .ioctl = adreno_ioctl, 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, --- FILE: \adreno.h | HITS: 3 --- MATCH LINES: 971 959: * profiling via the ALWAYSON counter 960: * @ADRENO_DEVICE_PREEMPTION - Turn on/off preemption 961: * @ADRENO_DEVICE_SOFT_FAULT_DETECT - Set if soft fault detect is enabled 962: * @ADRENO_DEVICE_GPMU_INITIALIZED - Set if GPMU firmware initialization succeed 963: * @ADRENO_DEVICE_ISDB_ENABLED - Set if the Integrated Shader DeBugger is 964: * attached and enabled 965: * @ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED - Set if a CACHE_FLUSH_TS irq storm 966: * is in progress 967: */ 968: enum adreno_device_flags { 969: ADRENO_DEVICE_PWRON = 0, 970: ADRENO_DEVICE_PWRON_FIXUP = 1, 971: ADRENO_DEVICE_INITIALIZED = 2, 972: ADRENO_DEVICE_STARTED = 5, 973: ADRENO_DEVICE_FAULT = 6, 974: ADRENO_DEVICE_DRAWOBJ_PROFILE = 7, 975: ADRENO_DEVICE_GPU_REGULATOR_ENABLED = 8, 976: ADRENO_DEVICE_PREEMPTION = 9, 977: ADRENO_DEVICE_SOFT_FAULT_DETECT = 10, 978: ADRENO_DEVICE_GPMU_INITIALIZED = 11, 979: ADRENO_DEVICE_ISDB_ENABLED = 12, 980: ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED = 13, 981: /** @ADRENO_DEVICE_DMS: Set if DMS is enabled */ 982: ADRENO_DEVICE_DMS = 14, 983: /** @ADRENO_DEVICE_GMU_AB: Set if AB vote via GMU is enabled */ 984: ADRENO_DEVICE_GMU_AB = 15, 985: /** @ADRENO_DEVICE_CX_TIMER_INITIALIZED: Set if the CX timer is initialized */ 986: ADRENO_DEVICE_CX_TIMER_INITIALIZED = 17, 987: /** @ADRENO_DEVICE_RESET_RECOVERY: Set if the ADRENO device under goes reset recovery */ 988: ADRENO_DEVICE_RESET_RECOVERY = 18, 989: /** @ADRENO_DEVICE_FIRST_BOOT_DONE: Set if the ADRENO device first boot is done */ 990: ADRENO_DEVICE_FIRST_BOOT_DONE = 19, 991: /** @ADRENO_DEVICE_FAST_CONTEXT_DESTROY: Set if fast context destroy is enabled on GMU */ 992: ADRENO_DEVICE_FAST_CONTEXT_DESTROY = 20, 993: /** @ADRENO_DEVICE_ALLOW_MALU_WORKLOAD: mALU workload is supported by GMU and GPU */ 994: ADRENO_DEVICE_ALLOW_MALU_WORKLOAD = 21, 995: }; MATCH LINES: 1095 1083: * so define them in the structure and use them as variables. 1084: */ 1085: unsigned int *const reg_offsets; 1086: 1087: /* GPU specific function hooks */ 1088: int (*probe)(struct platform_device *pdev, u32 chipid, 1089: const struct adreno_gpu_core *gpucore); 1090: void (*snapshot)(struct adreno_device *adreno_dev, 1091: struct kgsl_snapshot *snapshot); 1092: irqreturn_t (*irq_handler)(struct adreno_device *adreno_dev); 1093: int (*init)(struct adreno_device *adreno_dev); 1094: void (*remove)(struct adreno_device *adreno_dev); 1095: int (*rb_start)(struct adreno_device *adreno_dev); 1096: int (*start)(struct adreno_device *adreno_dev); 1097: int (*regulator_enable)(struct adreno_device *adreno_dev); 1098: void (*regulator_disable)(struct adreno_device *adreno_dev); 1099: void (*pwrlevel_change_settings)(struct adreno_device *adreno_dev, 1100: unsigned int prelevel, unsigned int postlevel, 1101: bool post); 1102: void (*preemption_schedule)(struct adreno_device *adreno_dev); 1103: void (*context_detach)(struct adreno_context *drawctxt); 1104: void (*pre_reset)(struct adreno_device *adreno_dev); 1105: void (*gpu_keepalive)(struct adreno_device *adreno_dev, 1106: bool state); 1107: bool (*hw_isidle)(struct adreno_device *adreno_dev); 1108: const char *(*iommu_fault_block)(struct kgsl_device *device, 1109: unsigned int fsynr1); 1110: int (*reset)(struct adreno_device *adreno_dev); 1111: /** @soft_reset: Soft reset GPU on fault recovery */ 1112: int (*soft_reset)(struct adreno_device *adreno_dev, 1113: struct kgsl_context *context, bool ctx_guilty); 1114: /** @read_alwayson: Return the current value of the alwayson counter */ 1115: u64 (*read_alwayson)(struct adreno_device *adreno_dev); 1116: /** 1117: * @power_ops: Target specific function pointers to power up/down the 1118: * gpu 1119: */ MATCH LINES: 1245 1233: 1234: extern const struct adreno_power_ops adreno_power_operations; 1235: 1236: extern const struct adreno_gpudev adreno_a5xx_gpudev; 1237: extern const struct adreno_gpudev adreno_a6xx_gpudev; 1238: extern const struct adreno_gpudev adreno_a6xx_rgmu_gpudev; 1239: extern const struct adreno_gpudev adreno_a619_holi_gpudev; 1240: extern const struct adreno_gpudev adreno_a611_gpudev; 1241: 1242: extern int adreno_wake_nice; 1243: extern unsigned int adreno_wake_timeout; 1244: 1245: int adreno_start(struct kgsl_device *device, int priority); 1246: long adreno_ioctl(struct kgsl_device_private *dev_priv, 1247: unsigned int cmd, unsigned long arg); 1248: 1249: long adreno_ioctl_helper(struct kgsl_device_private *dev_priv, 1250: unsigned int cmd, unsigned long arg, 1251: const struct kgsl_ioctl *cmds, int len); 1252: 1253: int adreno_spin_idle(struct adreno_device *device, unsigned int timeout); 1254: int adreno_wait_idle(struct kgsl_device *device); 1255: 1256: int adreno_set_constraint(struct kgsl_device *device, 1257: struct kgsl_context *context, 1258: struct kgsl_device_constraint *constraint); 1259: 1260: void adreno_snapshot(struct kgsl_device *device, 1261: struct kgsl_snapshot *snapshot, 1262: struct kgsl_context *context, struct kgsl_context *context_lpac); 1263: 1264: int adreno_reset(struct kgsl_device *device, int fault); 1265: 1266: void adreno_fault_skipcmd_detached(struct adreno_device *adreno_dev, 1267: struct adreno_context *drawctxt, 1268: struct kgsl_drawobj *drawobj); 1269: --- FILE: \adreno_a5xx.c | HITS: 5 --- MATCH LINES: 1557 1545: *cmds++ = cp_type7_packet(CP_YIELD_ENABLE, 1); 1546: *cmds++ = 1; 1547: 1548: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1549: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 1550: *cmds++ = 0; 1551: /* generate interrupt on preemption completion */ 1552: *cmds++ = 1; 1553: 1554: return cmds - cmds_orig; 1555: } 1556: 1557: static int a5xx_post_start(struct adreno_device *adreno_dev) 1558: { 1559: int ret; 1560: unsigned int *cmds, *start; 1561: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1562: 1563: if (!adreno_is_a530(adreno_dev) && 1564: !adreno_is_preemption_enabled(adreno_dev)) 1565: return 0; 1566: 1567: cmds = adreno_ringbuffer_allocspace(rb, 42); 1568: if (IS_ERR(cmds)) { 1569: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1570: 1571: dev_err(device->dev, 1572: "error allocating preemtion init cmds\n"); 1573: return PTR_ERR(cmds); 1574: } 1575: start = cmds; 1576: 1577: /* 1578: * Send a pipeline stat event whenever the GPU gets powered up 1579: * to cause misbehaving perf counters to start ticking 1580: */ 1581: if (adreno_is_a530(adreno_dev)) { MATCH LINES: 1804, 1807 1792: ret = a5xx_ringbuffer_submit(rb, NULL, true); 1793: if (!ret) { 1794: ret = adreno_spin_idle(adreno_dev, 2000); 1795: if (ret) 1796: a5xx_spin_idle_debug(adreno_dev, 1797: "CP initialization failed to idle\n"); 1798: } 1799: 1800: return ret; 1801: } 1802: 1803: /* 1804: * a5xx_rb_start() - Start the ringbuffer 1805: * @adreno_dev: Pointer to adreno device 1806: */ 1807: static int a5xx_rb_start(struct adreno_device *adreno_dev) 1808: { 1809: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1810: struct adreno_ringbuffer *rb; 1811: uint64_t addr; 1812: unsigned int *cmds; 1813: int ret, i; 1814: 1815: /* Clear all the ringbuffers */ 1816: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1817: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 1818: kgsl_sharedmem_writel(device->scratch, 1819: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1820: 1821: rb->wptr = 0; 1822: rb->_wptr = 0; 1823: rb->wptr_preempt_end = ~0; 1824: } 1825: 1826: /* Set up the current ringbuffer */ 1827: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 1828: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 1829: 1830: kgsl_regwrite(device, A5XX_CP_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1831: kgsl_regwrite(device, A5XX_CP_RB_RPTR_ADDR_HI, upper_32_bits(addr)); MATCH LINES: 1896 1884: if (ret) { 1885: a5xx_spin_idle_debug(adreno_dev, 1886: "Switch to unsecure failed to idle\n"); 1887: return ret; 1888: } 1889: } 1890: } 1891: 1892: ret = a5xx_gpmu_init(adreno_dev); 1893: if (ret) 1894: return ret; 1895: 1896: a5xx_post_start(adreno_dev); 1897: 1898: return 0; 1899: } 1900: 1901: /* 1902: * a5xx_microcode_read() - Read microcode 1903: * @adreno_dev: Pointer to adreno device 1904: */ 1905: static int a5xx_microcode_read(struct adreno_device *adreno_dev) 1906: { 1907: int ret; 1908: struct adreno_firmware *pm4_fw = ADRENO_FW(adreno_dev, ADRENO_FW_PM4); 1909: struct adreno_firmware *pfp_fw = ADRENO_FW(adreno_dev, ADRENO_FW_PFP); 1910: const struct adreno_a5xx_core *a5xx_core = to_a5xx_core(adreno_dev); 1911: 1912: ret = adreno_get_firmware(adreno_dev, a5xx_core->pm4fw_name, pm4_fw); 1913: if (ret) 1914: return ret; 1915: 1916: ret = adreno_get_firmware(adreno_dev, a5xx_core->pfpfw_name, pfp_fw); 1917: if (ret) 1918: return ret; 1919: 1920: ret = _load_gpmu_firmware(adreno_dev); MATCH LINES: 2435 2423: 2424: stats->ram_wait = counter_delta(device, adreno_dev->starved_ram_lo, 2425: &busy->bif_starved_ram); 2426: } 2427: 2428: const struct adreno_gpudev adreno_a5xx_gpudev = { 2429: .reg_offsets = a5xx_register_offsets, 2430: .probe = a5xx_probe, 2431: .start = a5xx_start, 2432: .snapshot = a5xx_snapshot, 2433: .init = a5xx_init, 2434: .irq_handler = a5xx_irq_handler, 2435: .rb_start = a5xx_rb_start, 2436: .regulator_enable = a5xx_regulator_enable, 2437: .regulator_disable = a5xx_regulator_disable, 2438: .pwrlevel_change_settings = a5xx_pwrlevel_change_settings, 2439: .preemption_schedule = a5xx_preemption_schedule, 2440: .read_alwayson = a5xx_read_alwayson, 2441: .hw_isidle = a5xx_hw_isidle, 2442: .power_ops = &adreno_power_operations, 2443: .clear_pending_transactions = a5xx_clear_pending_transactions, 2444: .remove = a5xx_remove, 2445: .ringbuffer_submitcmd = a5xx_ringbuffer_submitcmd, 2446: .is_hw_collapsible = a5xx_is_hw_collapsible, 2447: .power_stats = a5xx_power_stats, 2448: }; --- FILE: \adreno_a6xx.c | HITS: 9 --- MATCH LINES: 1117, 1150 1105: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 1106: cmds += cp_protected_mode(adreno_dev, cmds, 1); 1107: 1108: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1109: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 1110: *cmds++ = 0; 1111: /* generate interrupt on preemption completion */ 1112: *cmds++ = 0; 1113: 1114: return cmds - cmds_orig; 1115: } 1116: 1117: static int a6xx_post_start(struct adreno_device *adreno_dev) 1118: { 1119: int ret; 1120: unsigned int *cmds, *start; 1121: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1122: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1123: 1124: if (!adreno_is_preemption_enabled(adreno_dev)) 1125: return 0; 1126: 1127: cmds = adreno_ringbuffer_allocspace(rb, 42); 1128: if (IS_ERR(cmds)) { 1129: dev_err(device->dev, 1130: "error allocating preemption init cmds\n"); 1131: return PTR_ERR(cmds); 1132: } 1133: start = cmds; 1134: 1135: cmds += _preemption_init(adreno_dev, rb, cmds, NULL); 1136: 1137: rb->_wptr = rb->_wptr - (42 - (cmds - start)); 1138: 1139: ret = a6xx_ringbuffer_submit(rb, NULL, false); 1140: if (!ret) { 1141: ret = adreno_spin_idle(adreno_dev, 2000); 1142: if (ret) 1143: a6xx_spin_idle_debug(adreno_dev, 1144: "hw preemption initialization failed to idle\n"); 1145: } 1146: 1147: return ret; 1148: } 1149: 1150: int a6xx_rb_start(struct adreno_device *adreno_dev) 1151: { 1152: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev); 1153: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1154: u32 cp_rb_cntl = A6XX_CP_RB_CNTL_DEFAULT | 1155: (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? 0 : (1 << 27)); 1156: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 1157: struct adreno_ringbuffer *rb; 1158: uint64_t addr; 1159: int ret, i; 1160: unsigned int *cmds; 1161: 1162: /* Clear all the ringbuffers */ 1163: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1164: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 1165: kgsl_sharedmem_writel(device->scratch, 1166: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1167: 1168: rb->wptr = 0; 1169: rb->_wptr = 0; 1170: rb->wptr_preempt_end = ~0; 1171: } 1172: 1173: a6xx_preemption_start(adreno_dev); 1174: MATCH LINES: 1236 1224: 1225: ret = a6xx_ringbuffer_submit(rb, NULL, true); 1226: if (!ret) { 1227: ret = adreno_spin_idle(adreno_dev, 2000); 1228: if (ret) { 1229: a6xx_spin_idle_debug(adreno_dev, 1230: "Switch to unsecure failed to idle\n"); 1231: return ret; 1232: } 1233: } 1234: } 1235: 1236: return a6xx_post_start(adreno_dev); 1237: } 1238: 1239: /* 1240: * a6xx_sptprac_enable() - Power on SPTPRAC 1241: * @adreno_dev: Pointer to Adreno device 1242: */ 1243: static int a6xx_sptprac_enable(struct adreno_device *adreno_dev) 1244: { 1245: return a6xx_gmu_sptprac_enable(adreno_dev); 1246: } 1247: 1248: /* 1249: * a6xx_sptprac_disable() - Power off SPTPRAC 1250: * @adreno_dev: Pointer to Adreno device 1251: */ 1252: static void a6xx_sptprac_disable(struct adreno_device *adreno_dev) 1253: { 1254: a6xx_gmu_sptprac_disable(adreno_dev); 1255: } 1256: 1257: /* 1258: * a6xx_prepare_for_regulator_disable() - Prepare for regulator disable 1259: * @adreno_dev: Pointer to Adreno device 1260: */ MATCH LINES: 1494 1482: return ret; 1483: 1484: /* Clear ctrl_flags to ensure clocks and regulators are turned off */ 1485: device->pwrctrl.ctrl_flags = 0; 1486: 1487: kgsl_pwrctrl_change_state(device, KGSL_STATE_INIT); 1488: 1489: /* since device is officially off now clear start bit */ 1490: clear_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv); 1491: 1492: a6xx_reset_preempt_records(adreno_dev); 1493: 1494: ret = adreno_start(device, 0); 1495: if (ret) 1496: return ret; 1497: 1498: kgsl_pwrctrl_change_state(device, KGSL_STATE_ACTIVE); 1499: 1500: device->pwrctrl.ctrl_flags = flags; 1501: 1502: /* Toggle GX CPR on demand */ 1503: a6xx_gx_cpr_toggle(device); 1504: 1505: /* 1506: * If active_cnt is zero, there is no need to keep the GPU active. So, 1507: * we should transition to SLUMBER. 1508: */ 1509: if (!atomic_read(&device->active_cnt)) 1510: kgsl_pwrctrl_change_state(device, KGSL_STATE_SLUMBER); 1511: 1512: return 0; 1513: } 1514: 1515: static void a6xx_cp_hw_err_callback(struct adreno_device *adreno_dev, int bit) 1516: { 1517: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1518: unsigned int status1, status2; MATCH LINES: 2391 2379: SPTPRAC_POWEROFF_STATUS_MASK, 10, 10 * 1000)) 2380: dev_err(device->dev, "power off SPTPRAC fail\n"); 2381: } 2382: 2383: /* This is a non GMU/RGMU part */ 2384: const struct adreno_gpudev adreno_a6xx_gpudev = { 2385: .reg_offsets = a6xx_register_offsets, 2386: .probe = a6xx_probe, 2387: .start = a6xx_nogmu_start, 2388: .snapshot = a6xx_snapshot, 2389: .init = a6xx_nogmu_init, 2390: .irq_handler = a6xx_irq_handler, 2391: .rb_start = a6xx_rb_start, 2392: .regulator_disable = a6xx_prepare_for_regulator_disable, 2393: .gpu_keepalive = a6xx_gpu_keepalive, 2394: .hw_isidle = a6xx_hw_isidle, 2395: .iommu_fault_block = a6xx_iommu_fault_block, 2396: .reset = a6xx_reset, 2397: .preemption_schedule = a6xx_preemption_schedule, 2398: .read_alwayson = a6xx_read_alwayson, 2399: .power_ops = &adreno_power_operations, 2400: .clear_pending_transactions = a6xx_clear_pending_transactions, 2401: .deassert_gbif_halt = a6xx_deassert_gbif_halt, 2402: .remove = a6xx_remove, 2403: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2404: .is_hw_collapsible = adreno_isidle, 2405: .power_stats = a6xx_power_stats, 2406: .add_to_va_minidump = a6xx_dev_add_to_minidump, 2407: .gx_is_on = a6xx_gx_is_on, 2408: }; 2409: 2410: const struct a6xx_gpudev adreno_a6xx_hwsched_gpudev = { 2411: .base = { 2412: .reg_offsets = a6xx_register_offsets, 2413: .probe = a6xx_hwsched_probe, 2414: .snapshot = a6xx_hwsched_snapshot, 2415: .irq_handler = a6xx_hwsched_irq_handler, MATCH LINES: 2439, 2465, 2490, 2516 2427: }, 2428: .hfi_probe = a6xx_hwsched_hfi_probe, 2429: .hfi_remove = a6xx_hwsched_hfi_remove, 2430: .handle_watchdog = a6xx_hwsched_handle_watchdog, 2431: }; 2432: 2433: const struct a6xx_gpudev adreno_a6xx_gmu_gpudev = { 2434: .base = { 2435: .reg_offsets = a6xx_register_offsets, 2436: .probe = a6xx_gmu_device_probe, 2437: .snapshot = a6xx_gmu_snapshot, 2438: .irq_handler = a6xx_irq_handler, 2439: .rb_start = a6xx_rb_start, 2440: .regulator_enable = a6xx_sptprac_enable, 2441: .regulator_disable = a6xx_sptprac_disable, 2442: .gpu_keepalive = a6xx_gpu_keepalive, 2443: .hw_isidle = a6xx_hw_isidle, 2444: .iommu_fault_block = a6xx_iommu_fault_block, 2445: .reset = a6xx_gmu_reset, 2446: .preemption_schedule = a6xx_preemption_schedule, 2447: .read_alwayson = a6xx_read_alwayson, 2448: .power_ops = &a6xx_gmu_power_ops, 2449: .remove = a6xx_remove, 2450: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2451: .power_stats = a6xx_power_stats, 2452: .add_to_va_minidump = a6xx_gmu_add_to_minidump, 2453: .gx_is_on = a6xx_gmu_gx_is_on, 2454: .set_isdb_breakpoint_registers = a6xx_set_isdb_breakpoint_registers, 2455: }, 2456: .hfi_probe = a6xx_gmu_hfi_probe, 2457: .handle_watchdog = a6xx_gmu_handle_watchdog, 2458: }; 2459: 2460: const struct adreno_gpudev adreno_a6xx_rgmu_gpudev = { 2461: .reg_offsets = a6xx_register_offsets, 2462: .probe = a6xx_rgmu_device_probe, 2463: .snapshot = a6xx_rgmu_snapshot, 2464: .irq_handler = a6xx_irq_handler, 2465: .rb_start = a6xx_rb_start, 2466: .regulator_enable = a6xx_sptprac_enable, 2467: .regulator_disable = a6xx_sptprac_disable, 2468: .gpu_keepalive = a6xx_gpu_keepalive, 2469: .hw_isidle = a6xx_hw_isidle, 2470: .iommu_fault_block = a6xx_iommu_fault_block, 2471: .reset = a6xx_rgmu_reset, 2472: .preemption_schedule = a6xx_preemption_schedule, 2473: .read_alwayson = a6xx_read_alwayson, 2474: .power_ops = &a6xx_rgmu_power_ops, 2475: .remove = a6xx_remove, 2476: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2477: .power_stats = a6xx_power_stats, 2478: .add_to_va_minidump = a6xx_rgmu_add_to_minidump, 2479: .gx_is_on = a6xx_rgmu_gx_is_on, 2480: }; 2481: 2482: /* This is a non GMU/RGMU part */ 2483: const struct adreno_gpudev adreno_a619_holi_gpudev = { 2484: .reg_offsets = a6xx_register_offsets, 2485: .probe = a6xx_probe, 2486: .start = a6xx_nogmu_start, 2487: .snapshot = a6xx_snapshot, 2488: .init = a6xx_nogmu_init, 2489: .irq_handler = a6xx_irq_handler, 2490: .rb_start = a6xx_rb_start, 2491: .regulator_enable = a619_holi_sptprac_enable, 2492: .regulator_disable = a619_holi_sptprac_disable, 2493: .gpu_keepalive = a6xx_gpu_keepalive, 2494: .hw_isidle = a619_holi_hw_isidle, 2495: .iommu_fault_block = a6xx_iommu_fault_block, 2496: .reset = a6xx_reset, 2497: .preemption_schedule = a6xx_preemption_schedule, 2498: .read_alwayson = a6xx_read_alwayson, 2499: .power_ops = &adreno_power_operations, 2500: .clear_pending_transactions = a6xx_clear_pending_transactions, 2501: .deassert_gbif_halt = a6xx_deassert_gbif_halt, 2502: .remove = a6xx_remove, 2503: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2504: .is_hw_collapsible = adreno_isidle, 2505: .power_stats = a6xx_power_stats, 2506: .add_to_va_minidump = a6xx_dev_add_to_minidump, 2507: .gx_is_on = a619_holi_gx_is_on, 2508: }; 2509: 2510: const struct a6xx_gpudev adreno_a630_gpudev = { 2511: .base = { 2512: .reg_offsets = a6xx_register_offsets, 2513: .probe = a6xx_gmu_device_probe, 2514: .snapshot = a6xx_gmu_snapshot, 2515: .irq_handler = a6xx_irq_handler, 2516: .rb_start = a6xx_rb_start, 2517: .regulator_enable = a6xx_sptprac_enable, 2518: .regulator_disable = a6xx_sptprac_disable, 2519: .gpu_keepalive = a6xx_gpu_keepalive, 2520: .hw_isidle = a6xx_hw_isidle, 2521: .iommu_fault_block = a6xx_iommu_fault_block, 2522: .reset = a6xx_gmu_reset, 2523: .preemption_schedule = a6xx_preemption_schedule, 2524: .read_alwayson = a6xx_read_alwayson, 2525: .power_ops = &a630_gmu_power_ops, 2526: .remove = a6xx_remove, 2527: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2528: .power_stats = a6xx_power_stats, 2529: .add_to_va_minidump = a6xx_gmu_add_to_minidump, 2530: .gx_is_on = a6xx_gmu_gx_is_on, 2531: }, 2532: .hfi_probe = a6xx_gmu_hfi_probe, 2533: .handle_watchdog = a6xx_gmu_handle_watchdog, 2534: }; --- FILE: \adreno_a6xx.h | HITS: 2 --- MATCH LINES: 278, 286 266: * a6xx_init - Initialize a6xx resources 267: * @adreno_dev: An Adreno GPU handle 268: * 269: * This function does a6xx specific one time initialization 270: * and is invoked when the very first client opens a 271: * kgsl instance 272: * 273: * Return: Zero on success and negative error on failure 274: */ 275: int a6xx_init(struct adreno_device *adreno_dev); 276: 277: /** 278: * a6xx_rb_start - A6xx specific ringbuffer setup 279: * @adreno_dev: An Adreno GPU handle 280: * 281: * This function does a6xx specific ringbuffer setup and 282: * attempts to submit CP INIT and bring GPU out of secure mode 283: * 284: * Return: Zero on success and negative error on failure 285: */ 286: int a6xx_rb_start(struct adreno_device *adreno_dev); 287: 288: /** 289: * a6xx_microcode_read - Get the cp microcode from the filesystem 290: * @adreno_dev: An Adreno GPU handle 291: * 292: * This function gets the firmware from filesystem and sets up 293: * the micorocode global buffer 294: * 295: * Return: Zero on success and negative error on failure 296: */ 297: int a6xx_microcode_read(struct adreno_device *adreno_dev); 298: 299: /** 300: * a6xx_probe_common - Probe common a6xx resources 301: * @pdev: Pointer to the platform device 302: * @adreno_dev: Pointer to the adreno device 303: * @chipid: Chipid of the target 304: * @gpucore: Pointer to the gpucore strucure 305: * 306: * This function sets up the a6xx resources common across all 307: * a6xx targets 308: */ 309: int a6xx_probe_common(struct platform_device *pdev, 310: struct adreno_device *adreno_dev, u32 chipid, --- FILE: \adreno_a6xx_gmu.c | HITS: 12 --- MATCH LINES: 1194, 1196, 1198 1182: 1183: gmu_core_regwrite(device, A6XX_GMU_GX_SPTPRAC_POWER_CONTROL, 1184: SPTPRAC_POWEROFF_CTRL_MASK); 1185: 1186: if (gmu_core_timed_poll_check(device, 1187: A6XX_GMU_SPTPRAC_PWR_CLK_STATUS, 1188: SPTPRAC_POWEROFF_STATUS_MASK, 1189: SPTPRAC_CTRL_TIMEOUT, 1190: SPTPRAC_POWEROFF_STATUS_MASK)) 1191: dev_err(GMU_PDEV_DEV(device), "power off SPTPRAC fail\n"); 1192: } 1193: 1194: #define SPTPRAC_POWER_OFF BIT(2) 1195: #define SP_CLK_OFF BIT(4) 1196: #define GX_GDSC_POWER_OFF BIT(6) 1197: #define GX_CLK_OFF BIT(7) 1198: #define is_on(val) (!(val & (GX_GDSC_POWER_OFF | GX_CLK_OFF))) 1199: 1200: bool a6xx_gmu_gx_is_on(struct adreno_device *adreno_dev) 1201: { 1202: unsigned int val; 1203: 1204: gmu_core_regread(KGSL_DEVICE(adreno_dev), 1205: A6XX_GMU_SPTPRAC_PWR_CLK_STATUS, &val); 1206: return is_on(val); 1207: } 1208: 1209: bool a619_holi_gx_is_on(struct adreno_device *adreno_dev) 1210: { 1211: unsigned int val; 1212: 1213: gmu_core_regread(KGSL_DEVICE(adreno_dev), 1214: A6XX_GMU_SPTPRAC_PWR_CLK_STATUS, &val); 1215: return is_on(val); 1216: } 1217: 1218: static bool a6xx_gmu_rpmh_pwr_state_is_active(struct kgsl_device *device) 1219: { 1220: u32 val; 1221: 1222: gmu_core_regread(device, A6XX_GPU_GMU_CX_GMU_RPMH_POWER_STATE, &val); MATCH LINES: 1247 1235: unsigned int val; 1236: 1237: if (!adreno_is_a630(adreno_dev) && !adreno_is_a615_family(adreno_dev)) 1238: return true; 1239: 1240: if (adreno_is_a619_holi(adreno_dev)) 1241: kgsl_regread(device, 1242: A6XX_GMU_SPTPRAC_PWR_CLK_STATUS, &val); 1243: else 1244: gmu_core_regread(device, A6XX_GMU_SPTPRAC_PWR_CLK_STATUS, 1245: &val); 1246: 1247: return !(val & (SPTPRAC_POWER_OFF | SP_CLK_OFF)); 1248: } 1249: 1250: /* 1251: * a6xx_gmu_gfx_rail_on() - request GMU to power GPU at given OPP. 1252: * @device: Pointer to KGSL device 1253: * 1254: */ 1255: static int a6xx_gmu_gfx_rail_on(struct adreno_device *adreno_dev) 1256: { 1257: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1258: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 1259: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 1260: u32 perf_idx = gmu->hfi.dcvs_table.gpu_level_num - 1261: pwr->default_pwrlevel - 1; 1262: u32 default_opp = gmu->hfi.dcvs_table.gx_votes[perf_idx].vote; 1263: 1264: gmu_core_regwrite(device, A6XX_GMU_BOOT_SLUMBER_OPTION, 1265: OOB_BOOT_OPTION); 1266: gmu_core_regwrite(device, A6XX_GMU_GX_VOTE_IDX, 1267: ARC_VOTE_GET_PRI(default_opp)); 1268: gmu_core_regwrite(device, A6XX_GMU_MX_VOTE_IDX, 1269: ARC_VOTE_GET_SEC(default_opp)); 1270: 1271: gmu_core_rdpm_mx_freq_update(device, gmu->hfi.dcvs_table.gx_votes[perf_idx].freq); MATCH LINES: 2833 2821: A6XX_GBIF_HALT_ACK, A6XX_GBIF_CLIENT_HALT_MASK); 2822: 2823: /* Halt all AXI requests */ 2824: kgsl_regwrite(device, A6XX_GBIF_HALT, A6XX_GBIF_ARB_HALT_MASK); 2825: ret = adreno_wait_for_halt_ack(device, 2826: A6XX_GBIF_HALT_ACK, A6XX_GBIF_ARB_HALT_MASK); 2827: 2828: return ret; 2829: } 2830: 2831: #define RPMH_VOTE_TIMEOUT 2 /* ms */ 2832: 2833: static int a6xx_gmu_power_off(struct adreno_device *adreno_dev) 2834: { 2835: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2836: int ret = 0; 2837: 2838: if (device->gmu_fault) 2839: goto error; 2840: 2841: /* Wait for the lowest idle level we requested */ 2842: ret = a6xx_gmu_wait_for_lowest_idle(adreno_dev); 2843: if (ret) 2844: goto error; 2845: 2846: ret = a6xx_complete_rpmh_votes(adreno_dev, RPMH_VOTE_TIMEOUT); 2847: if (ret) 2848: goto error; 2849: 2850: ret = a6xx_gmu_notify_slumber(adreno_dev); 2851: if (ret) 2852: goto error; 2853: 2854: ret = a6xx_gmu_wait_for_idle(adreno_dev); 2855: if (ret) 2856: goto error; 2857: MATCH LINES: 2972, 3006 2960: a6xx_start(adreno_dev); 2961: 2962: /* Re-initialize the coresight registers if applicable */ 2963: adreno_coresight_start(adreno_dev); 2964: 2965: adreno_perfcounter_start(adreno_dev); 2966: 2967: /* Clear FSR here in case it is set from a previous pagefault */ 2968: kgsl_mmu_clear_fsr(&device->mmu); 2969: 2970: a6xx_enable_gpu_irq(adreno_dev); 2971: 2972: ret = a6xx_rb_start(adreno_dev); 2973: if (ret) { 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: { 3021: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 3022: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3023: int ret; 3024: 3025: if (WARN_ON(test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags))) 3026: return 0; 3027: 3028: kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE); 3029: 3030: if (IS_ENABLED(CONFIG_QCOM_KGSL_HIBERNATION) && MATCH LINES: 3159 3147: int ret; 3148: 3149: kgsl_regwrite(device, A6XX_VBIF_XIN_HALT_CTRL0, 3150: A6XX_VBIF_XIN_HALT_CTRL0_MASK); 3151: ret = adreno_wait_for_halt_ack(device, 3152: A6XX_VBIF_XIN_HALT_CTRL1, 3153: A6XX_VBIF_XIN_HALT_CTRL0_MASK); 3154: kgsl_regwrite(device, A6XX_VBIF_XIN_HALT_CTRL0, 0); 3155: 3156: return ret; 3157: } 3158: 3159: static int a6xx_power_off(struct adreno_device *adreno_dev) 3160: { 3161: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3162: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 3163: int ret; 3164: 3165: WARN_ON(!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)); 3166: 3167: adreno_check_idle(device); 3168: 3169: kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); 3170: 3171: ret = a6xx_gmu_oob_set(device, oob_gpu); 3172: if (ret) { 3173: a6xx_gmu_oob_clear(device, oob_gpu); 3174: goto no_gx_power; 3175: } 3176: 3177: if (a6xx_irq_pending(adreno_dev)) { 3178: a6xx_gmu_oob_clear(device, oob_gpu); 3179: return -EBUSY; 3180: } 3181: 3182: kgsl_pwrscale_update_stats(device); 3183: MATCH LINES: 3204 3192: * GX halt is handled by the GMU FW. 3193: */ 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: { MATCH LINES: 3260 3248: spin_lock(&device->submit_lock); 3249: 3250: if (device->submit_now) { 3251: spin_unlock(&device->submit_lock); 3252: kgsl_pwrscale_update(device); 3253: kgsl_start_idle_timer(device); 3254: goto done; 3255: } 3256: 3257: device->skip_inline_submit = true; 3258: spin_unlock(&device->submit_lock); 3259: 3260: ret = a6xx_power_off(adreno_dev); 3261: if (ret == -EBUSY) { 3262: kgsl_pwrscale_update(device); 3263: kgsl_start_idle_timer(device); 3264: } 3265: 3266: done: 3267: kgsl_mutex_unlock(&device->mutex); 3268: } 3269: 3270: static int a6xx_gmu_first_open(struct adreno_device *adreno_dev) 3271: { 3272: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3273: int ret; 3274: 3275: /* 3276: * Do the one time settings that need to happen when we 3277: * attempt to boot the gpu the very first time 3278: */ 3279: ret = a6xx_first_boot(adreno_dev); 3280: if (ret) 3281: return ret; 3282: 3283: /* 3284: * A client that does a first_open but never closes the device MATCH LINES: 3299 3287: */ 3288: atomic_inc(&device->active_cnt); 3289: adreno_active_count_put(adreno_dev); 3290: 3291: return 0; 3292: } 3293: 3294: static int a6xx_gmu_last_close(struct adreno_device *adreno_dev) 3295: { 3296: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 3297: 3298: if (test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 3299: return a6xx_power_off(adreno_dev); 3300: 3301: return 0; 3302: } 3303: 3304: static int a6xx_gmu_active_count_get(struct adreno_device *adreno_dev) 3305: { 3306: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3307: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 3308: int ret = 0; 3309: 3310: if (WARN_ON(!kgsl_mutex_is_locked(&device->mutex))) 3311: return -EINVAL; 3312: 3313: if (test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags)) 3314: return -EINVAL; 3315: 3316: if ((atomic_read(&device->active_cnt) == 0) && 3317: !test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 3318: ret = a6xx_boot(adreno_dev); 3319: 3320: if (ret == 0) 3321: atomic_inc(&device->active_cnt); 3322: 3323: trace_kgsl_active_count(device, MATCH LINES: 3345 3333: int ret; 3334: 3335: if (test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags)) 3336: return 0; 3337: 3338: kgsl_pwrctrl_request_state(device, KGSL_STATE_SUSPEND); 3339: 3340: ret = adreno_drain_and_idle(device); 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: --- FILE: \adreno_a6xx_hwsched.c | HITS: 7 --- MATCH LINES: 291 279: ret = a6xx_hfi_send_cmd_async(adreno_dev, &req, sizeof(req)); 280: 281: /* 282: * GEMNOC can enter power collapse state during GPU power down sequence. 283: * This could abort CX GDSC collapse. Assert Qactive to avoid this. 284: */ 285: if ((adreno_is_a662(adreno_dev) || adreno_is_a621(adreno_dev) || 286: adreno_is_a622(adreno_dev) || adreno_is_a642l(adreno_dev))) 287: gmu_core_regwrite(device, A6XX_GPU_GMU_CX_GMU_CX_FALNEXT_INTF, 0x1); 288: 289: return ret; 290: } 291: static int a6xx_hwsched_gmu_power_off(struct adreno_device *adreno_dev) 292: { 293: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 294: int ret = 0; 295: 296: if (device->gmu_fault) 297: goto error; 298: 299: /* Wait for the lowest idle level we requested */ 300: ret = a6xx_gmu_wait_for_lowest_idle(adreno_dev); 301: if (ret) 302: goto error; 303: 304: ret = a6xx_hwsched_notify_slumber(adreno_dev); 305: if (ret) 306: goto error; 307: 308: ret = a6xx_gmu_wait_for_idle(adreno_dev); 309: if (ret) 310: goto error; 311: 312: ret = a6xx_rscc_sleep_sequence(adreno_dev); 313: 314: gmu_core_rdpm_mx_freq_update(device, 0); 315: MATCH LINES: 396 384: * At this point it is safe to assume that we recovered. Setting 385: * this field allows us to take a new snapshot for the next failure 386: * if we are prioritizing the first unrecoverable snapshot. 387: */ 388: if (device->snapshot) 389: device->snapshot->recovered = true; 390: 391: device->reset_counter++; 392: err: 393: a6xx_gmu_oob_clear(device, oob_gpu); 394: 395: if (ret) 396: a6xx_hwsched_gmu_power_off(adreno_dev); 397: 398: return ret; 399: } 400: 401: static void hwsched_idle_timer(struct timer_list *t) 402: { 403: struct kgsl_device *device = container_of(t, struct kgsl_device, 404: idle_timer); 405: 406: kgsl_schedule_work(&device->idle_check_ws); 407: } 408: 409: static int a6xx_hwsched_gmu_init(struct adreno_device *adreno_dev) 410: { 411: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 412: int ret; 413: 414: ret = a6xx_gmu_parse_fw(adreno_dev); 415: if (ret) 416: return ret; 417: 418: ret = a6xx_gmu_memory_init(adreno_dev); 419: if (ret) 420: return ret; MATCH LINES: 606, 638 594: */ 595: device->pwrscale.devfreq_enabled = true; 596: 597: device->pwrctrl.last_stat_updated = ktime_get(); 598: 599: set_bit(ADRENO_DEVICE_FIRST_BOOT_DONE, &adreno_dev->priv); 600: 601: kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE); 602: 603: return 0; 604: } 605: 606: static int a6xx_hwsched_power_off(struct adreno_device *adreno_dev) 607: { 608: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 609: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 610: int ret; 611: 612: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 613: return 0; 614: 615: kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); 616: 617: ret = a6xx_gmu_oob_set(device, oob_gpu); 618: if (ret) { 619: a6xx_gmu_oob_clear(device, oob_gpu); 620: goto no_gx_power; 621: } 622: 623: kgsl_pwrscale_update_stats(device); 624: 625: /* Save active coresight registers if applicable */ 626: adreno_coresight_stop(adreno_dev); 627: 628: /* Save physical performance counter values before GPU power down*/ 629: adreno_perfcounter_save(adreno_dev); 630: 631: adreno_irqctrl(adreno_dev, 0); 632: 633: a6xx_gmu_oob_clear(device, oob_gpu); 634: 635: no_gx_power: 636: kgsl_pwrctrl_irq(device, false); 637: 638: a6xx_hwsched_gmu_power_off(adreno_dev); 639: 640: adreno_hwsched_unregister_contexts(adreno_dev); 641: 642: adreno_llcc_slice_deactivate(adreno_dev); 643: 644: clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags); 645: 646: kgsl_delete_timer_sync(&device->idle_timer); 647: 648: kgsl_pwrscale_sleep(device); 649: 650: kgsl_pwrctrl_clear_l3_vote(device); 651: 652: kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER); 653: 654: return ret; 655: } 656: 657: static void hwsched_idle_check(struct work_struct *work) 658: { 659: struct kgsl_device *device = container_of(work, 660: struct kgsl_device, idle_check_ws); 661: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 662: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); MATCH LINES: 690 678: kgsl_start_idle_timer(device); 679: goto done; 680: } 681: 682: device->skip_inline_submit = true; 683: spin_unlock(&device->submit_lock); 684: 685: if (!gpudev->hw_isidle(adreno_dev)) { 686: dev_err(device->dev, "GPU isn't idle before SLUMBER\n"); 687: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 688: } 689: 690: a6xx_hwsched_power_off(adreno_dev); 691: 692: done: 693: kgsl_mutex_unlock(&device->mutex); 694: } 695: 696: static int a6xx_hwsched_first_open(struct adreno_device *adreno_dev) 697: { 698: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 699: int ret; 700: 701: /* 702: * Do the one time settings that need to happen when we 703: * attempt to boot the gpu the very first time 704: */ 705: ret = a6xx_hwsched_first_boot(adreno_dev); 706: if (ret) 707: return ret; 708: 709: /* 710: * A client that does a first_open but never closes the device 711: * may prevent us from going back to SLUMBER. So trigger the idle 712: * check by incrementing the active count and immediately releasing it. 713: */ 714: atomic_inc(&device->active_cnt); MATCH LINES: 864 852: goto err; 853: 854: active_count = atomic_read(&device->active_cnt); 855: 856: if (active_count > 0) { 857: ret = -ETIMEDOUT; 858: dev_err_ratelimited(GMU_PDEV_DEV(device), 859: "Aborting suspend because of active count:%d\n", 860: active_count); 861: goto err; 862: } 863: 864: a6xx_hwsched_power_off(adreno_dev); 865: 866: adreno_get_gpu_halt(adreno_dev); 867: 868: set_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags); 869: 870: kgsl_pwrctrl_set_state(device, KGSL_STATE_SUSPEND); 871: 872: return 0; 873: 874: err: 875: adreno_hwsched_start(adreno_dev); 876: 877: return ret; 878: } 879: 880: void a6xx_hwsched_handle_watchdog(struct adreno_device *adreno_dev) 881: { 882: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 883: u32 mask; 884: 885: /* Temporarily mask the watchdog interrupt to prevent a storm */ 886: gmu_core_regread(device, A6XX_GMU_AO_HOST_INTERRUPT_MASK, 887: &mask); 888: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_MASK, MATCH LINES: 971 959: ret = a6xx_hwsched_boot(adreno_dev); 960: 961: if (!ret) 962: adreno_hwsched_replay(adreno_dev); 963: 964: BUG_ON(ret); 965: 966: return ret; 967: } 968: 969: const struct adreno_power_ops a6xx_hwsched_power_ops = { 970: .first_open = a6xx_hwsched_first_open, 971: .last_close = a6xx_hwsched_power_off, 972: .active_count_get = a6xx_hwsched_active_count_get, 973: .touch_wakeup = a6xx_hwsched_touch_wakeup, 974: .pm_suspend = a6xx_hwsched_pm_suspend, 975: .pm_resume = a6xx_hwsched_pm_resume, 976: .gpu_clock_set = a6xx_hwsched_clock_set, 977: .gpu_bus_set = a6xx_hwsched_bus_set, 978: }; 979: 980: const struct adreno_hwsched_ops a6xx_hwsched_ops = { 981: .submit_drawobj = a6xx_hwsched_submit_drawobj, 982: .preempt_count = a6xx_hwsched_preempt_count_get, 983: }; 984: 985: int a6xx_hwsched_probe(struct platform_device *pdev, 986: u32 chipid, const struct adreno_gpu_core *gpucore) 987: { 988: struct adreno_device *adreno_dev; 989: struct kgsl_device *device; 990: struct a6xx_hwsched_device *a6xx_hwsched_dev; 991: int ret; 992: 993: a6xx_hwsched_dev = devm_kzalloc(&pdev->dev, sizeof(*a6xx_hwsched_dev), 994: GFP_KERNEL); 995: if (!a6xx_hwsched_dev) --- FILE: \adreno_a6xx_rgmu.c | HITS: 14 --- MATCH LINES: 273, 280, 302, 315 261: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(ADRENO_DEVICE(device)); 262: 263: return rgmu->idle_level == GPU_HW_IFPC; 264: } 265: 266: 267: static void a6xx_rgmu_prepare_stop(struct kgsl_device *device) 268: { 269: /* Turn off GX_MEM retention */ 270: kgsl_regwrite(device, A6XX_RBBM_BLOCK_GX_RETENTION_CNTL, 0); 271: } 272: 273: #define GX_GDSC_POWER_OFF BIT(6) 274: bool a6xx_rgmu_gx_is_on(struct adreno_device *adreno_dev) 275: { 276: unsigned int val; 277: 278: gmu_core_regread(KGSL_DEVICE(adreno_dev), 279: A6XX_GMU_SPTPRAC_PWR_CLK_STATUS, &val); 280: return !(val & GX_GDSC_POWER_OFF); 281: } 282: 283: static int a6xx_rgmu_wait_for_lowest_idle(struct adreno_device *adreno_dev) 284: { 285: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 286: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 287: unsigned int reg[10] = {0}; 288: unsigned long t; 289: uint64_t ts1, ts2, ts3; 290: 291: if (rgmu->idle_level != GPU_HW_IFPC) 292: return 0; 293: 294: ts1 = a6xx_read_alwayson(adreno_dev); 295: 296: /* FIXME: readl_poll_timeout? */ 297: t = jiffies + msecs_to_jiffies(RGMU_IDLE_TIMEOUT); 298: do { 299: gmu_core_regread(device, 300: A6XX_GMU_SPTPRAC_PWR_CLK_STATUS, ®[0]); 301: 302: if (reg[0] & GX_GDSC_POWER_OFF) 303: return 0; 304: 305: /* Wait 10us to reduce unnecessary AHB bus traffic */ 306: usleep_range(10, 100); 307: } while (!time_after(jiffies, t)); 308: 309: ts2 = a6xx_read_alwayson(adreno_dev); 310: 311: /* Do one last read incase it succeeds */ 312: gmu_core_regread(device, 313: A6XX_GMU_SPTPRAC_PWR_CLK_STATUS, ®[0]); 314: 315: if (reg[0] & GX_GDSC_POWER_OFF) 316: return 0; 317: 318: ts3 = a6xx_read_alwayson(adreno_dev); 319: 320: /* Collect abort data to help with debugging */ 321: gmu_core_regread(device, A6XX_RGMU_CX_PCC_DEBUG, ®[1]); 322: gmu_core_regread(device, A6XX_RGMU_CX_PCC_STATUS, ®[2]); 323: gmu_core_regread(device, A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS, ®[3]); 324: kgsl_regread(device, A6XX_CP_STATUS_1, ®[4]); 325: gmu_core_regread(device, A6XX_GMU_RBBM_INT_UNMASKED_STATUS, ®[5]); 326: gmu_core_regread(device, A6XX_GMU_GMU_PWR_COL_KEEPALIVE, ®[6]); 327: kgsl_regread(device, A6XX_CP_CP2GMU_STATUS, ®[7]); 328: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, ®[8]); 329: gmu_core_regread(device, A6XX_GMU_AO_SPARE_CNTL, ®[9]); 330: 331: dev_err(&rgmu->pdev->dev, 332: "----------------------[ RGMU error ]----------------------\n"); 333: dev_err(&rgmu->pdev->dev, "Timeout waiting for lowest idle level\n"); 334: dev_err(&rgmu->pdev->dev, 335: "Timestamps: %llx %llx %llx\n", ts1, ts2, ts3); 336: dev_err(&rgmu->pdev->dev, 337: "SPTPRAC_PWR_CLK_STATUS=%x PCC_DEBUG=%x PCC_STATUS=%x\n", 338: reg[0], reg[1], reg[2]); 339: dev_err(&rgmu->pdev->dev, MATCH LINES: 650 638: 639: /* Halt all AXI requests */ 640: kgsl_regwrite(device, A6XX_GBIF_HALT, A6XX_GBIF_ARB_HALT_MASK); 641: adreno_wait_for_halt_ack(device, A6XX_GBIF_HALT_ACK, 642: A6XX_GBIF_ARB_HALT_MASK); 643: 644: /* De-assert the halts */ 645: kgsl_regwrite(device, A6XX_GBIF_HALT, 0x0); 646: } 647: 648: 649: /* Caller shall ensure GPU is ready for SLUMBER */ 650: static void a6xx_rgmu_power_off(struct adreno_device *adreno_dev) 651: { 652: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 653: int ret; 654: 655: kgsl_pwrctrl_axi(device, false); 656: 657: if (device->gmu_fault) 658: return a6xx_rgmu_suspend(adreno_dev); 659: 660: /* Wait for the lowest idle level we requested */ 661: ret = a6xx_rgmu_wait_for_lowest_idle(adreno_dev); 662: if (ret) 663: return a6xx_rgmu_suspend(adreno_dev); 664: 665: a6xx_rgmu_notify_slumber(adreno_dev); 666: 667: /* Halt CX traffic and de-assert halt */ 668: halt_gbif_arb(adreno_dev); 669: 670: a6xx_rgmu_irq_disable(adreno_dev); 671: a6xx_rgmu_disable_clks(adreno_dev); 672: kgsl_pwrctrl_disable_cx_gdsc(device); 673: 674: kgsl_pwrctrl_clear_l3_vote(device); MATCH LINES: 770, 798 758: a6xx_start(adreno_dev); 759: 760: /* Re-initialize the coresight registers if applicable */ 761: adreno_coresight_start(adreno_dev); 762: 763: adreno_perfcounter_start(adreno_dev); 764: 765: /* Clear FSR here in case it is set from a previous pagefault */ 766: kgsl_mmu_clear_fsr(&device->mmu); 767: 768: a6xx_enable_gpu_irq(adreno_dev); 769: 770: ret = a6xx_rb_start(adreno_dev); 771: if (ret) { 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: } 819: 820: a6xx_rgmu_irq_enable(adreno_dev); 821: 822: /* Clear any GPU faults that might have been left over */ MATCH LINES: 840, 845, 880 828: 829: ret = kgsl_pwrctrl_setup_default_votes(device); 830: if (ret) 831: goto err; 832: 833: device->gmu_fault = false; 834: 835: kgsl_pwrctrl_set_state(device, KGSL_STATE_AWARE); 836: 837: return 0; 838: 839: err: 840: a6xx_rgmu_power_off(adreno_dev); 841: 842: return ret; 843: } 844: 845: static int a6xx_power_off(struct adreno_device *adreno_dev); 846: 847: static void rgmu_idle_check(struct work_struct *work) 848: { 849: struct kgsl_device *device = container_of(work, 850: struct kgsl_device, idle_check_ws); 851: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 852: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 853: int ret; 854: 855: kgsl_mutex_lock(&device->mutex); 856: 857: if (test_bit(GMU_DISABLE_SLUMBER, &device->gmu_core.flags)) 858: goto done; 859: 860: if (atomic_read(&device->active_cnt) || time_is_after_jiffies(device->idle_jiffies)) { 861: kgsl_pwrscale_update(device); 862: goto done; 863: } 864: 865: if (!test_bit(RGMU_PRIV_GPU_STARTED, &rgmu->flags)) 866: goto done; 867: 868: spin_lock(&device->submit_lock); 869: 870: if (device->submit_now) { 871: spin_unlock(&device->submit_lock); 872: kgsl_pwrscale_update(device); 873: kgsl_start_idle_timer(device); 874: goto done; 875: } 876: 877: device->skip_inline_submit = true; 878: spin_unlock(&device->submit_lock); 879: 880: ret = a6xx_power_off(adreno_dev); 881: if (ret == -EBUSY) { 882: kgsl_pwrscale_update(device); 883: kgsl_start_idle_timer(device); 884: } 885: 886: done: 887: kgsl_mutex_unlock(&device->mutex); 888: } 889: 890: static void rgmu_idle_timer(struct timer_list *t) 891: { 892: struct kgsl_device *device = container_of(t, struct kgsl_device, 893: idle_timer); 894: 895: kgsl_schedule_work(&device->idle_check_ws); 896: } 897: 898: static int a6xx_boot(struct adreno_device *adreno_dev) 899: { 900: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 901: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 902: int ret; 903: 904: if (WARN_ON(test_bit(RGMU_PRIV_GPU_STARTED, &rgmu->flags))) MATCH LINES: 1066 1054: 1055: /* 1056: * A client that does a first_open but never closes the device 1057: * may prevent us from going back to SLUMBER. So trigger the idle 1058: * check by incrementing the active count and immediately releasing it. 1059: */ 1060: atomic_inc(&device->active_cnt); 1061: adreno_active_count_put(adreno_dev); 1062: 1063: return 0; 1064: } 1065: 1066: static int a6xx_power_off(struct adreno_device *adreno_dev) 1067: { 1068: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1069: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 1070: int ret; 1071: 1072: WARN_ON(!test_bit(RGMU_PRIV_GPU_STARTED, &rgmu->flags)); 1073: 1074: adreno_check_idle(device); 1075: 1076: kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); 1077: 1078: ret = a6xx_rgmu_oob_set(device, oob_gpu); 1079: if (ret) { 1080: a6xx_rgmu_oob_clear(device, oob_gpu); 1081: goto no_gx_power; 1082: } 1083: 1084: if (a6xx_irq_pending(adreno_dev)) { 1085: a6xx_rgmu_oob_clear(device, oob_gpu); 1086: return -EBUSY; 1087: } 1088: 1089: kgsl_pwrscale_update_stats(device); 1090: MATCH LINES: 1112, 1138 1100: 1101: a6xx_rgmu_oob_clear(device, oob_gpu); 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: 1149: /* Hard reset the rgmu and gpu */ 1150: a6xx_rgmu_suspend(adreno_dev); 1151: 1152: a6xx_reset_preempt_records(adreno_dev); 1153: 1154: adreno_llcc_slice_deactivate(adreno_dev); 1155: 1156: clear_bit(RGMU_PRIV_GPU_STARTED, &rgmu->flags); 1157: 1158: /* Attempt rebooting the rgmu and gpu */ 1159: return a6xx_boot(adreno_dev); 1160: } 1161: 1162: static int a6xx_rgmu_active_count_get(struct adreno_device *adreno_dev) MATCH LINES: 1203 1191: int ret; 1192: 1193: if (test_bit(RGMU_PRIV_PM_SUSPEND, &rgmu->flags)) 1194: return 0; 1195: 1196: kgsl_pwrctrl_request_state(device, KGSL_STATE_SUSPEND); 1197: 1198: ret = adreno_drain_and_idle(device); 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: --- FILE: \adreno_gen7.c | HITS: 6 --- MATCH LINES: 1096, 1111 1084: * miss any register programming when we patch the power up register 1085: * list. 1086: */ 1087: if (!adreno_dev->patch_reglist && 1088: (adreno_dev->pwrup_reglist->gpuaddr != 0)) { 1089: gen7_patch_pwrup_reglist(adreno_dev); 1090: adreno_dev->patch_reglist = true; 1091: } 1092: 1093: return 0; 1094: } 1095: 1096: int gen7_scm_gpu_init_cx_regs(struct adreno_device *adreno_dev) 1097: { 1098: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1099: u32 gpu_req = GPU_ALWAYS_EN_REQ; 1100: int ret; 1101: 1102: if (ADRENO_FEATURE(adreno_dev, ADRENO_BCL)) 1103: gpu_req |= GPU_BCL_EN_REQ; 1104: 1105: if (ADRENO_FEATURE(adreno_dev, ADRENO_CLX)) 1106: gpu_req |= GPU_CLX_EN_REQ; 1107: 1108: if (adreno_is_gen7_9_x(adreno_dev)) 1109: gpu_req |= GPU_TSENSE_EN_REQ; 1110: 1111: ret = kgsl_scm_gpu_init_regs(&device->pdev->dev, gpu_req, 1112: adreno_dev->zap_enabled); 1113: 1114: /* 1115: * For targets that support this scm call to program BCL id , enable BCL. 1116: * For other targets, BCL is enabled after first GMU boot. 1117: */ 1118: if (!ret && ADRENO_FEATURE(adreno_dev, ADRENO_BCL)) 1119: adreno_dev->bcl_enabled = true; 1120: 1121: /* If programming TZ CLX was successful, then program KMD owned CLX regs */ 1122: if (!ret && ADRENO_FEATURE(adreno_dev, ADRENO_CLX)) 1123: adreno_dev->clx_enabled = true; 1124: 1125: /* 1126: * If scm call returned EOPNOTSUPP, either we are on a kernel version 1127: * lesser than 6.1 where scm call is not supported or we are sending an 1128: * empty request. Ignore the error in such cases. 1129: */ 1130: return (ret == -EOPNOTSUPP) ? 0 : ret; 1131: } 1132: 1133: void gen7_spin_idle_debug(struct adreno_device *adreno_dev, 1134: const char *str) 1135: { MATCH LINES: 1194 1182: ret = adreno_spin_idle(adreno_dev, 2000); 1183: if (ret) { 1184: gen7_spin_idle_debug(adreno_dev, 1185: "CP initialization failed to idle\n"); 1186: rb->wptr = 0; 1187: rb->_wptr = 0; 1188: } 1189: } 1190: 1191: return ret; 1192: } 1193: 1194: static int gen7_post_start(struct adreno_device *adreno_dev) 1195: { 1196: int ret; 1197: unsigned int *cmds; 1198: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1199: struct adreno_preemption *preempt = &adreno_dev->preempt; 1200: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1201: u64 kmd_postamble_addr; 1202: u32 count = 9; 1203: 1204: if (!adreno_is_preemption_enabled(adreno_dev)) 1205: return 0; 1206: 1207: kmd_postamble_addr = SCRATCH_POSTAMBLE_ADDR(KGSL_DEVICE(adreno_dev)); 1208: gen7_preemption_prepare_postamble(adreno_dev); 1209: 1210: if (kgsl_mmu_is_secured(&device->mmu)) 1211: count += 3; 1212: 1213: if (preempt->postamble_bootup_len) 1214: count += 4; 1215: 1216: cmds = adreno_ringbuffer_allocspace(rb, count); 1217: if (IS_ERR(cmds)) 1218: return PTR_ERR(cmds); MATCH LINES: 1258 1246: 1247: ret = gen7_ringbuffer_submit(rb, NULL); 1248: if (!ret) { 1249: ret = adreno_spin_idle(adreno_dev, 2000); 1250: if (ret) 1251: gen7_spin_idle_debug(adreno_dev, 1252: "hw preemption initialization failed to idle\n"); 1253: } 1254: 1255: return ret; 1256: } 1257: 1258: int gen7_rb_start(struct adreno_device *adreno_dev) 1259: { 1260: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 1261: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 1262: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1263: struct adreno_ringbuffer *rb; 1264: u64 addr; 1265: int ret, i; 1266: unsigned int *cmds; 1267: 1268: /* Clear all the ringbuffers */ 1269: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1270: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 1271: kgsl_sharedmem_writel(device->scratch, 1272: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1273: kgsl_sharedmem_writel(device->scratch, 1274: SCRATCH_RB_OFFSET(rb->id, bv_rptr), 0); 1275: 1276: rb->wptr = 0; 1277: rb->_wptr = 0; 1278: rb->wptr_preempt_end = UINT_MAX; 1279: } 1280: 1281: gen7_preemption_start(adreno_dev); 1282: MATCH LINES: 1346 1334: 1335: ret = gen7_ringbuffer_submit(rb, NULL); 1336: if (!ret) { 1337: ret = adreno_spin_idle(adreno_dev, 2000); 1338: if (ret) { 1339: gen7_spin_idle_debug(adreno_dev, 1340: "Switch to unsecure failed to idle\n"); 1341: return ret; 1342: } 1343: } 1344: } 1345: 1346: return gen7_post_start(adreno_dev); 1347: } 1348: 1349: /* 1350: * gen7_gpu_keepalive() - GMU reg write to request GPU stays on 1351: * @adreno_dev: Pointer to the adreno device that has the GMU 1352: * @state: State to set: true is ON, false is OFF 1353: */ 1354: static void gen7_gpu_keepalive(struct adreno_device *adreno_dev, 1355: bool state) 1356: { 1357: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), 1358: GEN7_GMU_GMU_PWR_COL_KEEPALIVE, state); 1359: } 1360: 1361: bool gen7_hw_isidle(struct adreno_device *adreno_dev) 1362: { 1363: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1364: unsigned int reg; 1365: 1366: gmu_core_regread(device, GEN7_GPU_GMU_AO_GPU_CX_BUSY_STATUS, ®); 1367: 1368: /* Bit 23 is GPUBUSYIGNAHB */ 1369: return (reg & BIT(23)) ? false : true; 1370: } MATCH LINES: 2569 2557: }, 2558: .hfi_probe = gen7_hwsched_hfi_probe, 2559: .hfi_remove = gen7_hwsched_hfi_remove, 2560: .handle_watchdog = gen7_hwsched_handle_watchdog, 2561: }; 2562: 2563: const struct gen7_gpudev adreno_gen7_gmu_gpudev = { 2564: .base = { 2565: .reg_offsets = gen7_register_offsets, 2566: .probe = gen7_gmu_device_probe, 2567: .snapshot = gen7_gmu_snapshot, 2568: .irq_handler = gen7_irq_handler, 2569: .rb_start = gen7_rb_start, 2570: .gpu_keepalive = gen7_gpu_keepalive, 2571: .hw_isidle = gen7_hw_isidle, 2572: .iommu_fault_block = gen7_iommu_fault_block, 2573: .reset = gen7_gmu_reset, 2574: .preemption_schedule = gen7_preemption_schedule, 2575: .read_alwayson = gen7_read_alwayson, 2576: .power_ops = &gen7_gmu_power_ops, 2577: .remove = gen7_remove, 2578: .ringbuffer_submitcmd = gen7_ringbuffer_submitcmd, 2579: .power_stats = gen7_power_stats, 2580: .add_to_va_minidump = gen7_gmu_add_to_minidump, 2581: .gx_is_on = gen7_gmu_gx_is_on, 2582: .perfcounter_remove = gen7_perfcounter_remove, 2583: .set_isdb_breakpoint_registers = gen7_set_isdb_breakpoint_registers, 2584: .swfuse_irqctrl = gen7_swfuse_irqctrl, 2585: .get_uche_trap_base = gen7_get_uche_trap_base, 2586: .fault_header = gen7_fault_header, 2587: .acquire_cp_semaphore = gen7_acquire_cp_semaphore, 2588: .release_cp_semaphore = gen7_release_cp_semaphore, 2589: }, 2590: .hfi_probe = gen7_gmu_hfi_probe, 2591: .handle_watchdog = gen7_gmu_handle_watchdog, 2592: }; --- FILE: \adreno_gen7.h | HITS: 4 --- MATCH LINES: 334, 342 322: */ 323: void gen7_cx_timer_init(struct adreno_device *adreno_dev); 324: 325: /** 326: * gen7_get_gpu_feature_info - Get hardware supported feature info 327: * @adreno_dev: Pointer to the adreno device 328: * 329: * Get HW supported feature info and update sofware feature configuration 330: */ 331: void gen7_get_gpu_feature_info(struct adreno_device *adreno_dev); 332: 333: /** 334: * gen7_rb_start - Gen7 specific ringbuffer setup 335: * @adreno_dev: An Adreno GPU handle 336: * 337: * This function does gen7 specific ringbuffer setup and 338: * attempts to submit CP INIT and bring GPU out of secure mode 339: * 340: * Return: Zero on success and negative error on failure 341: */ 342: int gen7_rb_start(struct adreno_device *adreno_dev); 343: 344: /** 345: * gen7_microcode_read - Get the cp microcode from the filesystem 346: * @adreno_dev: An Adreno GPU handle 347: * 348: * This function gets the firmware from filesystem and sets up 349: * the micorocode global buffer 350: * 351: * Return: Zero on success and negative error on failure 352: */ 353: int gen7_microcode_read(struct adreno_device *adreno_dev); 354: 355: /** 356: * gen7_probe_common - Probe common gen7 resources 357: * @pdev: Pointer to the platform device 358: * @adreno_dev: Pointer to the adreno device 359: * @chipid: Chipid of the target 360: * @gpucore: Pointer to the gpucore strucure 361: * 362: * This function sets up the gen7 resources common across all 363: * gen7 targets 364: */ 365: int gen7_probe_common(struct platform_device *pdev, 366: struct adreno_device *adreno_dev, u32 chipid, MATCH LINES: 493, 501 481: */ 482: void gen7_reset_preempt_records(struct adreno_device *adreno_dev); 483: 484: /** 485: * gen7_enable_ahb_timeout_detection - Program AHB control registers 486: * @adreno_dev: An Adreno GPU handle 487: * 488: * Program AHB control registers to enable AHB timeout detection. 489: */ 490: void gen7_enable_ahb_timeout_detection(struct adreno_device *adreno_dev); 491: 492: /** 493: * gen7_scm_gpu_init_cx_regs - Program gpu regs for feature support 494: * @adreno_dev: Handle to the adreno device 495: * 496: * Program gpu regs for feature support. Scm call for the same 497: * is added from kernel version 6.0 onwards. 498: * 499: * Return: 0 on success or negative on failure 500: */ 501: int gen7_scm_gpu_init_cx_regs(struct adreno_device *adreno_dev); 502: 503: /** 504: * gen7_host_aperture_set - Program CP aperture register 505: * @adreno_dev: Handle to the adreno device 506: * @pipe_id: Pipe for which the register is to be set 507: * 508: * This function programs CP aperture register. 509: */ 510: void gen7_host_aperture_set(struct adreno_device *adreno_dev, u32 pipe_id); 511: 512: #ifdef CONFIG_QCOM_KGSL_CORESIGHT 513: void gen7_coresight_init(struct adreno_device *device); 514: #else 515: static inline void gen7_coresight_init(struct adreno_device *device) { } 516: #endif 517: 518: /** 519: * gen7_periph_regread64 - Read 64 bit peripheral register values 520: * @device: Handle to the KGSL device 521: * @offsetwords_lo: Lower 32 bit address to read 522: * @offsetwords_hi: Higher 32 bit address to read 523: * @value: The value of register at offsetwords 524: * @pipe: Pipe for which the register is to be read 525: * --- FILE: \adreno_gen7_gmu.c | HITS: 11 --- MATCH LINES: 739, 741 727: ret |= gen7_timed_poll_check_rscc(gmu, 728: gen7_rscc_tcsm_drv0_status_reglist[i], BIT(0), timeout, 729: BIT(0)); 730: } 731: 732: if (ret) 733: dev_err(GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)), 734: "RPMH votes timedout: %d\n", ret); 735: 736: return ret; 737: } 738: 739: #define GX_GDSC_POWER_OFF BIT(0) 740: #define GX_CLK_OFF BIT(1) 741: #define is_on(val) (!(val & (GX_GDSC_POWER_OFF | GX_CLK_OFF))) 742: 743: bool gen7_gmu_gx_is_on(struct adreno_device *adreno_dev) 744: { 745: unsigned int val; 746: 747: gmu_core_regread(KGSL_DEVICE(adreno_dev), 748: GEN7_GMU_GFX_PWR_CLK_STATUS, &val); 749: return is_on(val); 750: } 751: 752: static bool gen7_gmu_rpmh_pwr_state_is_active(struct kgsl_device *device) 753: { 754: u32 val; 755: 756: gmu_core_regread(device, GEN7_GPU_GMU_CX_GMU_RPMH_POWER_STATE, &val); 757: return (val == GPU_HW_ACTIVE) ? true : false; 758: } 759: 760: static const char *idle_level_name(int level) 761: { 762: if (level == GPU_HW_ACTIVE) 763: return "GPU_HW_ACTIVE"; 764: else if (level == GPU_HW_IFPC) 765: return "GPU_HW_IFPC"; MATCH LINES: 1635 1623: ret = gen7_gmu_load_fw(adreno_dev); 1624: if (ret) 1625: goto clks_gdsc_off; 1626: 1627: ret = gen7_gmu_version_info(adreno_dev); 1628: if (ret) 1629: goto clks_gdsc_off; 1630: 1631: ret = gen7_gmu_itcm_shadow(adreno_dev); 1632: if (ret) 1633: goto clks_gdsc_off; 1634: 1635: ret = gen7_scm_gpu_init_cx_regs(adreno_dev); 1636: if (ret) 1637: goto clks_gdsc_off; 1638: 1639: gen7_gmu_register_config(adreno_dev); 1640: 1641: gen7_gmu_irq_enable(adreno_dev); 1642: 1643: /* Vote for minimal DDR BW for GMU to init */ 1644: level = pwr->pwrlevels[pwr->default_pwrlevel].bus_min; 1645: icc_set_bw(pwr->icc_path, 0, kBps_to_icc(pwr->ddr_table[level])); 1646: 1647: /* Clear any GPU faults that might have been left over */ 1648: adreno_clear_gpu_fault(adreno_dev); 1649: 1650: ret = gen7_gmu_device_start(adreno_dev); 1651: if (ret) 1652: goto err; 1653: 1654: if (!test_bit(GMU_PRIV_PDC_RSC_LOADED, &gmu->flags)) { 1655: ret = gen7_load_pdc_ucode(adreno_dev); 1656: if (ret) 1657: goto err; 1658: 1659: gen7_load_rsc_ucode(adreno_dev); MATCH LINES: 2218 2206: 2207: /* Halt all AXI requests */ 2208: kgsl_regwrite(device, GEN7_GBIF_HALT, GEN7_GBIF_ARB_HALT_MASK); 2209: ret = adreno_wait_for_halt_ack(device, 2210: GEN7_GBIF_HALT_ACK, GEN7_GBIF_ARB_HALT_MASK); 2211: 2212: /* De-assert the halts */ 2213: kgsl_regwrite(device, GEN7_GBIF_HALT, 0x0); 2214: 2215: return ret; 2216: } 2217: 2218: static int gen7_gmu_power_off(struct adreno_device *adreno_dev) 2219: { 2220: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2221: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2222: int ret = 0; 2223: 2224: if (device->gmu_fault) 2225: goto error; 2226: 2227: /* Wait for the lowest idle level we requested */ 2228: ret = gen7_gmu_wait_for_lowest_idle(adreno_dev); 2229: if (ret) 2230: goto error; 2231: 2232: ret = gen7_complete_rpmh_votes(gmu, 2); 2233: if (ret) 2234: goto error; 2235: 2236: ret = gen7_gmu_notify_slumber(adreno_dev); 2237: if (ret) 2238: goto error; 2239: 2240: ret = gen7_gmu_wait_for_idle(adreno_dev); 2241: if (ret) 2242: goto error; MATCH LINES: 2333, 2361 2321: gen7_core->qos_value[adreno_dev->cur_rb->id]); 2322: 2323: /* Re-initialize the coresight registers if applicable */ 2324: adreno_coresight_start(adreno_dev); 2325: 2326: adreno_perfcounter_start(adreno_dev); 2327: 2328: /* Clear FSR here in case it is set from a previous pagefault */ 2329: kgsl_mmu_clear_fsr(&device->mmu); 2330: 2331: gen7_enable_gpu_irq(adreno_dev); 2332: 2333: ret = gen7_rb_start(adreno_dev); 2334: if (ret) { 2335: gen7_disable_gpu_irq(adreno_dev); 2336: adreno_llcc_slice_deactivate(adreno_dev); 2337: goto oob_clear; 2338: } 2339: 2340: /* 2341: * At this point it is safe to assume that we recovered. Setting 2342: * this field allows us to take a new snapshot for the next failure 2343: * if we are prioritizing the first unrecoverable snapshot. 2344: */ 2345: if (device->snapshot) 2346: device->snapshot->recovered = true; 2347: 2348: /* Start the dispatcher */ 2349: adreno_dispatcher_start(device); 2350: 2351: device->reset_counter++; 2352: 2353: gen7_gmu_oob_clear(device, oob_gpu); 2354: 2355: return 0; 2356: 2357: oob_clear: 2358: gen7_gmu_oob_clear(device, oob_gpu); 2359: 2360: err: 2361: gen7_gmu_power_off(adreno_dev); 2362: 2363: return ret; 2364: } 2365: 2366: static void gmu_idle_timer(struct timer_list *t) 2367: { 2368: struct kgsl_device *device = container_of(t, struct kgsl_device, 2369: idle_timer); 2370: 2371: kgsl_schedule_work(&device->idle_check_ws); 2372: } 2373: 2374: static int gen7_boot(struct adreno_device *adreno_dev) 2375: { 2376: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2377: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2378: bool bcl_state = adreno_dev->bcl_enabled; 2379: int ret; 2380: 2381: if (WARN_ON(test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags))) 2382: return 0; 2383: 2384: kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE); 2385: MATCH LINES: 2520, 2553 2508: static bool gen7_irq_pending(struct adreno_device *adreno_dev) 2509: { 2510: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2511: u32 status; 2512: 2513: kgsl_regread(device, GEN7_RBBM_INT_0_STATUS, &status); 2514: 2515: /* Return busy if a interrupt is pending */ 2516: return ((status & adreno_dev->irq_mask) || 2517: atomic_read(&adreno_dev->pending_irq_refcnt)); 2518: } 2519: 2520: static int gen7_power_off(struct adreno_device *adreno_dev) 2521: { 2522: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2523: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2524: int ret; 2525: 2526: WARN_ON(!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)); 2527: 2528: adreno_check_idle(device); 2529: 2530: kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); 2531: 2532: ret = gen7_gmu_oob_set(device, oob_gpu); 2533: if (ret) 2534: goto no_gx_power; 2535: 2536: if (gen7_irq_pending(adreno_dev)) { 2537: gen7_gmu_oob_clear(device, oob_gpu); 2538: return -EBUSY; 2539: } 2540: 2541: kgsl_pwrscale_update_stats(device); 2542: 2543: /* Save active coresight registers if applicable */ 2544: adreno_coresight_stop(adreno_dev); 2545: 2546: adreno_irqctrl(adreno_dev, 0); 2547: 2548: no_gx_power: 2549: gen7_gmu_oob_clear(device, oob_gpu); 2550: 2551: kgsl_pwrctrl_irq(device, false); 2552: 2553: gen7_gmu_power_off(adreno_dev); 2554: 2555: adreno_set_active_ctxs_null(adreno_dev); 2556: 2557: adreno_dispatcher_stop(adreno_dev); 2558: 2559: adreno_ringbuffer_stop(adreno_dev); 2560: 2561: adreno_llcc_slice_deactivate(adreno_dev); 2562: 2563: clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags); 2564: 2565: kgsl_delete_timer_sync(&device->idle_timer); 2566: 2567: kgsl_pwrscale_sleep(device); 2568: 2569: kgsl_pwrctrl_clear_l3_vote(device); 2570: 2571: /* 2572: * Reset the context records so that CP can start 2573: * at the correct read pointer for BV thread after 2574: * coming out of slumber. 2575: */ 2576: gen7_reset_preempt_records(adreno_dev); 2577: MATCH LINES: 2616 2604: spin_lock(&device->submit_lock); 2605: 2606: if (device->submit_now) { 2607: spin_unlock(&device->submit_lock); 2608: kgsl_pwrscale_update(device); 2609: kgsl_start_idle_timer(device); 2610: goto done; 2611: } 2612: 2613: device->skip_inline_submit = true; 2614: spin_unlock(&device->submit_lock); 2615: 2616: ret = gen7_power_off(adreno_dev); 2617: if (ret == -EBUSY) { 2618: kgsl_pwrscale_update(device); 2619: kgsl_start_idle_timer(device); 2620: } 2621: 2622: done: 2623: kgsl_mutex_unlock(&device->mutex); 2624: } 2625: 2626: static int gen7_gmu_first_open(struct adreno_device *adreno_dev) 2627: { 2628: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2629: int ret; 2630: 2631: /* 2632: * Do the one time settings that need to happen when we 2633: * attempt to boot the gpu the very first time 2634: */ 2635: ret = gen7_first_boot(adreno_dev); 2636: if (ret) 2637: return ret; 2638: 2639: /* 2640: * A client that does a first_open but never closes the device MATCH LINES: 2655 2643: */ 2644: atomic_inc(&device->active_cnt); 2645: adreno_active_count_put(adreno_dev); 2646: 2647: return 0; 2648: } 2649: 2650: static int gen7_gmu_last_close(struct adreno_device *adreno_dev) 2651: { 2652: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2653: 2654: if (test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 2655: return gen7_power_off(adreno_dev); 2656: 2657: return 0; 2658: } 2659: 2660: static int gen7_gmu_active_count_get(struct adreno_device *adreno_dev) 2661: { 2662: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2663: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2664: int ret = 0; 2665: 2666: if (WARN_ON(!kgsl_mutex_is_locked(&device->mutex))) 2667: return -EINVAL; 2668: 2669: if (test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags)) 2670: return -EINVAL; 2671: 2672: if ((atomic_read(&device->active_cnt) == 0) && 2673: !test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 2674: ret = gen7_boot(adreno_dev); 2675: 2676: if (ret == 0) 2677: atomic_inc(&device->active_cnt); 2678: 2679: trace_kgsl_active_count(device, MATCH LINES: 2701 2689: int ret; 2690: 2691: if (test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags)) 2692: return 0; 2693: 2694: kgsl_pwrctrl_request_state(device, KGSL_STATE_SUSPEND); 2695: 2696: ret = adreno_drain_and_idle(device); 2697: if (ret) 2698: goto err; 2699: 2700: if (test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 2701: gen7_power_off(adreno_dev); 2702: 2703: set_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags); 2704: 2705: adreno_get_gpu_halt(adreno_dev); 2706: 2707: kgsl_pwrctrl_set_state(device, KGSL_STATE_SUSPEND); 2708: 2709: return 0; 2710: err: 2711: adreno_dispatcher_start(device); 2712: return ret; 2713: } 2714: 2715: static void gen7_gmu_pm_resume(struct adreno_device *adreno_dev) 2716: { 2717: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2718: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2719: 2720: if (WARN(!test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags), 2721: "resume invoked without a suspend\n")) 2722: return; 2723: 2724: adreno_put_gpu_halt(adreno_dev); 2725: --- FILE: \adreno_gen7_hwsched.c | HITS: 8 --- MATCH LINES: 204 192: if (ret) 193: goto clks_gdsc_off; 194: 195: if (!test_bit(GMU_PRIV_PDC_RSC_LOADED, &gmu->flags)) { 196: ret = gen7_load_pdc_ucode(adreno_dev); 197: if (ret) 198: goto clks_gdsc_off; 199: 200: gen7_load_rsc_ucode(adreno_dev); 201: set_bit(GMU_PRIV_PDC_RSC_LOADED, &gmu->flags); 202: } 203: 204: ret = gen7_scm_gpu_init_cx_regs(adreno_dev); 205: if (ret) 206: goto clks_gdsc_off; 207: 208: gen7_gmu_register_config(adreno_dev); 209: 210: ret = gen7_gmu_version_info(adreno_dev); 211: if (ret) 212: goto clks_gdsc_off; 213: 214: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2) 215: set_bit(ADRENO_HWSCHED_CTX_BAD_LEGACY, &adreno_dev->hwsched.flags); 216: 217: gen7_gmu_irq_enable(adreno_dev); 218: 219: /* Vote for minimal DDR BW for GMU to init */ 220: level = pwr->pwrlevels[pwr->default_pwrlevel].bus_min; 221: 222: /* From this GMU FW all RBBM interrupts are handled at GMU */ 223: if (device->gmu_core.ver.core >= GMU_VERSION(5, 01, 06)) 224: adreno_irq_free(adreno_dev); 225: 226: /* GMU supports force retire command from this GMU FW */ 227: if (gmu_core_capabilities_enabled(&device->gmu_core.common_caps, 228: FAC_FORCE_RETIRE_COMMAND)) MATCH LINES: 400 388: gmu_core_regwrite(device, GEN7_GMU_CX_GMU_POWER_COUNTER_ENABLE, 0); 389: 390: ret = gen7_hfi_send_cmd_async(adreno_dev, &req, sizeof(req)); 391: 392: /* 393: * GEMNOC can enter power collapse state during GPU power down sequence. 394: * This could abort CX GDSC collapse. Assert Qactive to avoid this. 395: */ 396: gmu_core_regwrite(device, GEN7_GPU_GMU_CX_GMU_CX_FALNEXT_INTF, 0x1); 397: 398: return ret; 399: } 400: static int gen7_hwsched_gmu_power_off(struct adreno_device *adreno_dev) 401: { 402: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 403: int ret = 0; 404: 405: if (device->gmu_fault) 406: goto error; 407: 408: /* Wait for the lowest idle level we requested */ 409: ret = gen7_gmu_wait_for_lowest_idle(adreno_dev); 410: if (ret) 411: goto error; 412: 413: ret = gen7_hwsched_notify_slumber(adreno_dev); 414: if (ret) 415: goto error; 416: 417: ret = gen7_gmu_wait_for_idle(adreno_dev); 418: if (ret) 419: goto error; 420: 421: ret = gen7_rscc_sleep_sequence(adreno_dev); 422: 423: gmu_core_rdpm_mx_freq_update(device, 0); 424: MATCH LINES: 538 526: device->reset_counter++; 527: 528: /* 529: * If warmboot is enabled and we switched a sysfs node, we will do a coldboot 530: * in the subseqent slumber exit. Once that is done we need to mark this bool 531: * as false so that in the next run we can do warmboot 532: */ 533: clear_bit(GMU_FORCE_COLDBOOT, &device->gmu_core.flags); 534: err: 535: gen7_gmu_oob_clear(device, oob_gpu); 536: 537: if (ret) 538: gen7_hwsched_gmu_power_off(adreno_dev); 539: 540: return ret; 541: } 542: 543: static void hwsched_idle_timer(struct timer_list *t) 544: { 545: struct kgsl_device *device = container_of(t, struct kgsl_device, 546: idle_timer); 547: 548: kgsl_schedule_work(&device->idle_check_ws); 549: } 550: 551: static int gen7_gmu_warmboot_init(struct adreno_device *adreno_dev) 552: { 553: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 554: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 555: int ret = 0; 556: 557: if (!ADRENO_FEATURE(adreno_dev, ADRENO_GMU_WARMBOOT)) 558: return ret; 559: 560: if (IS_ERR_OR_NULL(gmu->gmu_init_scratch)) { 561: gmu->gmu_init_scratch = gmu_core_reserve_kernel_block(device, 0, 562: SZ_4K, GMU_CACHE, 0); MATCH LINES: 853, 887 841: if (ret) 842: break; 843: } 844: } 845: read_unlock(&device->context_lock); 846: 847: if (ret) 848: gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE); 849: 850: return ret; 851: } 852: 853: static int gen7_hwsched_power_off(struct adreno_device *adreno_dev) 854: { 855: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 856: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 857: int ret = 0; 858: bool drain_cpu = false; 859: 860: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 861: return 0; 862: 863: kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); 864: 865: ret = gen7_gmu_oob_set(device, oob_gpu); 866: if (ret) { 867: gen7_gmu_oob_clear(device, oob_gpu); 868: goto no_gx_power; 869: } 870: 871: kgsl_pwrscale_update_stats(device); 872: 873: /* Save active coresight registers if applicable */ 874: adreno_coresight_stop(adreno_dev); 875: 876: adreno_irqctrl(adreno_dev, 0); 877: 878: gen7_gmu_oob_clear(device, oob_gpu); 879: 880: no_gx_power: 881: kgsl_pwrctrl_irq(device, false); 882: 883: /* Make sure GMU has sent all hardware fences to TxQueue */ 884: if (check_inflight_hw_fences(adreno_dev)) 885: drain_cpu = true; 886: 887: gen7_hwsched_gmu_power_off(adreno_dev); 888: 889: /* Now that we are sure that GMU is powered off, drain pending fences */ 890: if (drain_cpu) 891: drain_hw_fences_cpu(adreno_dev); 892: 893: adreno_hwsched_unregister_contexts(adreno_dev); 894: 895: adreno_llcc_slice_deactivate(adreno_dev); 896: 897: clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags); 898: 899: kgsl_delete_timer_sync(&device->idle_timer); 900: 901: kgsl_pwrscale_sleep(device); 902: 903: kgsl_pwrctrl_clear_l3_vote(device); 904: 905: kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER); 906: 907: return ret; 908: } 909: 910: static void check_hw_fence_unack_count(struct adreno_device *adreno_dev) 911: { MATCH LINES: 969 957: } 958: 959: device->skip_inline_submit = true; 960: spin_unlock(&device->submit_lock); 961: 962: if (!gpudev->hw_isidle(adreno_dev)) { 963: dev_err(device->dev, "GPU isn't idle before SLUMBER\n"); 964: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 965: } 966: 967: check_hw_fence_unack_count(adreno_dev); 968: 969: gen7_hwsched_power_off(adreno_dev); 970: 971: done: 972: kgsl_mutex_unlock(&device->mutex); 973: } 974: 975: static int gen7_hwsched_first_open(struct adreno_device *adreno_dev) 976: { 977: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 978: int ret; 979: 980: /* 981: * Do the one time settings that need to happen when we 982: * attempt to boot the gpu the very first time 983: */ 984: ret = gen7_hwsched_first_boot(adreno_dev); 985: if (ret) 986: return ret; 987: 988: /* 989: * A client that does a first_open but never closes the device 990: * may prevent us from going back to SLUMBER. So trigger the idle 991: * check by incrementing the active count and immediately releasing it. 992: */ 993: atomic_inc(&device->active_cnt); MATCH LINES: 1157 1145: goto err; 1146: 1147: active_count = atomic_read(&device->active_cnt); 1148: 1149: if (active_count > 0) { 1150: ret = -ETIMEDOUT; 1151: dev_err_ratelimited(GMU_PDEV_DEV(device), 1152: "Aborting suspend because of active count:%d\n", 1153: active_count); 1154: goto err; 1155: } 1156: 1157: gen7_hwsched_power_off(adreno_dev); 1158: 1159: adreno_get_gpu_halt(adreno_dev); 1160: 1161: set_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags); 1162: 1163: kgsl_pwrctrl_set_state(device, KGSL_STATE_SUSPEND); 1164: 1165: return 0; 1166: 1167: err: 1168: adreno_hwsched_start(adreno_dev); 1169: 1170: return ret; 1171: } 1172: 1173: static void gen7_hwsched_pm_resume(struct adreno_device *adreno_dev) 1174: { 1175: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 1176: 1177: if (WARN(!test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags), 1178: "resume invoked without a suspend\n")) 1179: return; 1180: 1181: adreno_put_gpu_halt(adreno_dev); MATCH LINES: 1538 1526: return; 1527: 1528: /* If GMU is up, send the constraint to GMU */ 1529: ret = gen7_hwsched_hfi_set_value(adreno_dev, HFI_VALUE_MAX_GPU_THERMAL_INDEX, 0, 1530: (pwr->num_pwrlevels - pwr->thermal_pwrlevel)); 1531: if (ret) 1532: dev_err(GMU_PDEV_DEV(device), "Failed to set thermal level %u, ret: %d\n", 1533: pwr->thermal_pwrlevel, ret); 1534: } 1535: 1536: const struct adreno_power_ops gen7_hwsched_power_ops = { 1537: .first_open = gen7_hwsched_first_open, 1538: .last_close = gen7_hwsched_power_off, 1539: .active_count_get = gen7_hwsched_active_count_get, 1540: .touch_wakeup = gen7_hwsched_touch_wakeup, 1541: .pm_suspend = gen7_hwsched_pm_suspend, 1542: .pm_resume = gen7_hwsched_pm_resume, 1543: .gpu_clock_set = gen7_hwsched_clock_set, 1544: .gpu_bus_set = gen7_hwsched_bus_set, 1545: .set_thermal_index = gen7_hwsched_set_thermal_index, 1546: }; 1547: 1548: const struct adreno_hwsched_ops gen7_hwsched_ops = { 1549: .submit_drawobj = gen7_hwsched_submit_drawobj, 1550: .preempt_count = gen7_hwsched_preempt_count_get, 1551: .create_hw_fence = gen7_hwsched_create_hw_fence, 1552: }; 1553: 1554: int gen7_hwsched_probe(struct platform_device *pdev, 1555: u32 chipid, const struct adreno_gpu_core *gpucore) 1556: { 1557: struct adreno_device *adreno_dev; 1558: struct kgsl_device *device; 1559: struct gen7_hwsched_device *gen7_hwsched_dev; 1560: int ret; 1561: 1562: gen7_hwsched_dev = devm_kzalloc(&pdev->dev, sizeof(*gen7_hwsched_dev), --- FILE: \adreno_gen8.c | HITS: 7 --- MATCH LINES: 2292, 2295, 2309 2280: 2281: void gen8_scm_gpu_tsense_default(struct adreno_device *adreno_dev, bool default_req) 2282: { 2283: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2284: u32 gpu_req = GPU_TSENSE_EN_REQ; 2285: 2286: if (!ADRENO_FEATURE(adreno_dev, ADRENO_TSENSE_DYNAMIC_PERIOD)) 2287: return; 2288: 2289: if (!default_req) 2290: gpu_req |= GPU_TSENSE_MEASURE_DEFAULT_DISABLE; 2291: 2292: kgsl_scm_gpu_init_regs(&device->pdev->dev, gpu_req, adreno_dev->zap_enabled); 2293: } 2294: 2295: int gen8_scm_gpu_init_cx_regs(struct adreno_device *adreno_dev) 2296: { 2297: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2298: u32 gpu_req = GPU_ALWAYS_EN_REQ; 2299: int ret; 2300: 2301: if (ADRENO_FEATURE(adreno_dev, ADRENO_BCL)) 2302: gpu_req |= GPU_BCL_EN_REQ; 2303: 2304: if (ADRENO_FEATURE(adreno_dev, ADRENO_CLX)) 2305: gpu_req |= GPU_CLX_EN_REQ; 2306: 2307: gpu_req |= GPU_TSENSE_EN_REQ; 2308: 2309: ret = kgsl_scm_gpu_init_regs(&device->pdev->dev, gpu_req, 2310: adreno_dev->zap_enabled); 2311: 2312: /* 2313: * For targets that support this scm call to program BCL id , enable BCL. 2314: * For other targets, BCL is enabled after first GMU boot. 2315: */ 2316: if (!ret && ADRENO_FEATURE(adreno_dev, ADRENO_BCL)) 2317: adreno_dev->bcl_enabled = true; 2318: 2319: /* If programming TZ CLX was successful, then program KMD owned CLX regs */ 2320: if (!ret && ADRENO_FEATURE(adreno_dev, ADRENO_CLX)) 2321: adreno_dev->clx_enabled = true; 2322: 2323: /* 2324: * If scm call returned EOPNOTSUPP, either we are on a kernel version 2325: * lesser than 6.1 where scm call is not supported or we are sending an 2326: * empty request. Ignore the error in such cases. 2327: */ 2328: return (ret == -EOPNOTSUPP) ? 0 : ret; 2329: } 2330: 2331: void gen8_spin_idle_debug(struct adreno_device *adreno_dev, 2332: const char *str) 2333: { MATCH LINES: 2388 2376: 2377: ret = adreno_spin_idle(adreno_dev, 2000); 2378: if (ret) { 2379: gen8_spin_idle_debug(adreno_dev, 2380: "CP initialization failed to idle\n"); 2381: rb->wptr = 0; 2382: rb->_wptr = 0; 2383: } 2384: 2385: return ret; 2386: } 2387: 2388: static int gen8_post_start(struct adreno_device *adreno_dev) 2389: { 2390: int ret; 2391: u32 *cmds; 2392: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 2393: struct adreno_preemption *preempt = &adreno_dev->preempt; 2394: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2395: u64 kmd_postamble_addr; 2396: u32 count = 9; 2397: 2398: if (!adreno_is_preemption_enabled(adreno_dev)) 2399: return 0; 2400: 2401: kmd_postamble_addr = SCRATCH_POSTAMBLE_ADDR(KGSL_DEVICE(adreno_dev)); 2402: gen8_preemption_prepare_postamble(adreno_dev); 2403: 2404: if (kgsl_mmu_is_secured(&device->mmu)) 2405: count += 3; 2406: 2407: if (preempt->postamble_bootup_len) 2408: count += 4; 2409: 2410: cmds = adreno_ringbuffer_allocspace(rb, count); 2411: if (IS_ERR(cmds)) 2412: return PTR_ERR(cmds); MATCH LINES: 2454 2442: 2443: ret = gen8_ringbuffer_submit(rb, NULL); 2444: if (!ret) { 2445: ret = adreno_spin_idle(adreno_dev, 2000); 2446: if (ret) 2447: gen8_spin_idle_debug(adreno_dev, 2448: "hw preemption initialization failed to idle\n"); 2449: } 2450: 2451: return ret; 2452: } 2453: 2454: int gen8_rb_start(struct adreno_device *adreno_dev) 2455: { 2456: const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev); 2457: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 2458: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2459: struct adreno_ringbuffer *rb; 2460: u64 addr; 2461: int ret, i; 2462: u32 *cmds; 2463: 2464: /* Clear all the ringbuffers */ 2465: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2466: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 2467: kgsl_sharedmem_writel(device->scratch, 2468: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 2469: kgsl_sharedmem_writel(device->scratch, 2470: SCRATCH_RB_OFFSET(rb->id, bv_rptr), 0); 2471: 2472: rb->wptr = 0; 2473: rb->_wptr = 0; 2474: rb->wptr_preempt_end = UINT_MAX; 2475: } 2476: 2477: gen8_preemption_start(adreno_dev); 2478: MATCH LINES: 2557 2545: 2546: /* 2547: * All registers must be written before this point so that we don't 2548: * miss any register programming when we patch the power up register 2549: * list. 2550: */ 2551: if (!adreno_dev->patch_reglist && 2552: (adreno_dev->pwrup_reglist->gpuaddr != 0)) { 2553: gen8_patch_pwrup_reglist(adreno_dev); 2554: adreno_dev->patch_reglist = true; 2555: } 2556: 2557: ret = gen8_post_start(adreno_dev); 2558: if (!ret && (adreno_is_gen8_2_x(adreno_dev) || adreno_is_gen8_1_0(adreno_dev) || 2559: adreno_is_gen8_10_0(adreno_dev))) 2560: gen8_hwcg_set(adreno_dev, true); 2561: 2562: return ret; 2563: } 2564: 2565: /* 2566: * gen8_gpu_keepalive() - GMU reg write to request GPU stays on 2567: * @adreno_dev: Pointer to the adreno device that has the GMU 2568: * @state: State to set: true is ON, false is OFF 2569: */ 2570: static void gen8_gpu_keepalive(struct adreno_device *adreno_dev, 2571: bool state) 2572: { 2573: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), 2574: GEN8_GMUCX_PWR_COL_KEEPALIVE, state); 2575: } 2576: 2577: bool gen8_hw_isidle(struct adreno_device *adreno_dev) 2578: { 2579: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2580: u32 reg; 2581: MATCH LINES: 3887 3875: }, 3876: .hfi_probe = gen8_hwsched_hfi_probe, 3877: .hfi_remove = gen8_hwsched_hfi_remove, 3878: .handle_watchdog = gen8_hwsched_handle_watchdog, 3879: }; 3880: 3881: const struct gen8_gpudev adreno_gen8_gmu_gpudev = { 3882: .base = { 3883: .reg_offsets = gen8_register_offsets, 3884: .probe = gen8_gmu_device_probe, 3885: .snapshot = gen8_gmu_snapshot, 3886: .irq_handler = gen8_irq_handler, 3887: .rb_start = gen8_rb_start, 3888: .gpu_keepalive = gen8_gpu_keepalive, 3889: .hw_isidle = gen8_hw_isidle, 3890: .iommu_fault_block = gen8_iommu_fault_block, 3891: .reset = gen8_gmu_reset, 3892: .preemption_schedule = gen8_preemption_schedule, 3893: .read_alwayson = gen8_read_alwayson, 3894: .power_ops = &gen8_gmu_power_ops, 3895: .remove = gen8_remove, 3896: .ringbuffer_submitcmd = gen8_ringbuffer_submitcmd, 3897: .power_stats = gen8_power_stats, 3898: .add_to_va_minidump = gen8_gmu_add_to_minidump, 3899: .gx_is_on = gen8_gmu_gx_is_on, 3900: .perfcounter_remove = gen8_perfcounter_remove, 3901: .set_isdb_breakpoint_registers = gen8_set_isdb_breakpoint_registers, 3902: .swfuse_irqctrl = gen8_swfuse_irqctrl, 3903: .get_uche_trap_base = gen8_get_uche_trap_base, 3904: .fault_header = gen8_fault_header, 3905: .acquire_cp_semaphore = gen8_acquire_cp_semaphore, 3906: .release_cp_semaphore = gen8_release_cp_semaphore, 3907: .get_gmem_size = gen8_get_gmem_size, 3908: .read_speedbin = gen8_read_softfuse_speedbin, 3909: }, 3910: .hfi_probe = gen8_gmu_hfi_probe, 3911: .handle_watchdog = gen8_gmu_handle_watchdog, --- FILE: \adreno_gen8.h | HITS: 4 --- MATCH LINES: 441, 449 429: */ 430: void gen8_get_gpu_feature_info(struct adreno_device *adreno_dev); 431: 432: /** 433: * gen8_get_gpu_slice_info - Get information about the active slices 434: * @adreno_dev: Pointer to the adreno device 435: * 436: * Get information about the active slices and save it in the gen8 device 437: */ 438: void gen8_get_gpu_slice_info(struct adreno_device *adreno_dev); 439: 440: /** 441: * gen8_rb_start - Gen8 specific ringbuffer setup 442: * @adreno_dev: An Adreno GPU handle 443: * 444: * This function does gen8 specific ringbuffer setup and 445: * attempts to submit CP INIT and bring GPU out of secure mode 446: * 447: * Return: Zero on success and negative error on failure 448: */ 449: int gen8_rb_start(struct adreno_device *adreno_dev); 450: 451: /** 452: * gen8_microcode_read - Get the cp microcode from the filesystem 453: * @adreno_dev: An Adreno GPU handle 454: * 455: * This function gets the firmware from filesystem and sets up 456: * the micorocode global buffer 457: * 458: * Return: Zero on success and negative error on failure 459: */ 460: int gen8_microcode_read(struct adreno_device *adreno_dev); 461: 462: /** 463: * gen8_probe_common - Probe common gen8 resources 464: * @pdev: Pointer to the platform device 465: * @adreno_dev: Pointer to the adreno device 466: * @chipid: Chipid of the target 467: * @gpucore: Pointer to the gpucore strucure 468: * 469: * This function sets up the gen8 resources common across all 470: * gen8 targets 471: */ 472: int gen8_probe_common(struct platform_device *pdev, 473: struct adreno_device *adreno_dev, u32 chipid, MATCH LINES: 591, 599 579: return container_of(gpudev, struct gen8_gpudev, base); 580: } 581: 582: /** 583: * gen8_reset_preempt_records - Reset the preemption buffers 584: * @adreno_dev: Handle to the adreno device 585: * 586: * Reset the preemption records at the time of hard reset 587: */ 588: void gen8_reset_preempt_records(struct adreno_device *adreno_dev); 589: 590: /** 591: * gen8_scm_gpu_init_cx_regs - Program gpu regs for feature support 592: * @adreno_dev: Handle to the adreno device 593: * 594: * Program gpu regs for feature support. Scm call for the same 595: * is added from kernel version 6.0 onwards. 596: * 597: * Return: 0 on success or negative on failure 598: */ 599: int gen8_scm_gpu_init_cx_regs(struct adreno_device *adreno_dev); 600: 601: /** 602: * gen8_scm_gpu_tsense_default - Program gpu tsense measurement interval 603: * @adreno_dev: Handle to the adreno device 604: * @default_req: Bool on if should update tsense with default or slow interval 605: * 606: * Program gpu tsense reg for measurement granularity. Scm call for the same 607: * is added from kernel version 6.0 onwards. 608: */ 609: void gen8_scm_gpu_tsense_default(struct adreno_device *adreno_dev, bool default_req); 610: 611: /** 612: * gen8_legacy_snapshot_registers - Dump registers for GPU/GMU 613: * @device: Handle to the KGSL device 614: * @buf: Target buffer to copy the data 615: * @remain: Buffer size remaining for dump 616: * @priv: Private data to dump the registers 617: * 618: * Return: Size of the section 619: */ 620: size_t gen8_legacy_snapshot_registers(struct kgsl_device *device, 621: u8 *buf, size_t remain, void *priv); 622: 623: /** --- FILE: \adreno_gen8_gmu.c | HITS: 17 --- MATCH LINES: 642, 644, 646, 649, 650, 651 630: 631: for (i = 0; i < ARRAY_SIZE(gen8_rscc_tcsm_drv0_status_reglist); i++) 632: ret |= gen8_timed_poll_check_rscc(gmu, 633: gen8_rscc_tcsm_drv0_status_reglist[i], BIT(0), timeout, 634: BIT(0)); 635: 636: if (ret) 637: dev_err(GMU_PDEV_DEV(device), "RPMH votes timedout: %d\n", ret); 638: 639: return ret; 640: } 641: 642: #define GX_GDSC_POWER_OFF BIT(0) 643: #define GX_CLK_OFF BIT(1) 644: #define MALU_GDSC_POWER_OFF BIT(9) 645: #define MALU_CLK_OFF BIT(10) 646: #define CX_MISC_GX_GDSC_POWER_OFF BIT(3) 647: #define CX_MISC_GX_CLK_OFF BIT(4) 648: 649: #define is_on(val) (!(val & (GX_GDSC_POWER_OFF | GX_CLK_OFF))) 650: #define is_cx_misc_gx_on(val) (!(val & (CX_MISC_GX_GDSC_POWER_OFF | CX_MISC_GX_CLK_OFF))) 651: #define is_malu_on(val) (!(val & (MALU_GDSC_POWER_OFF | MALU_CLK_OFF))) 652: 653: bool gen8_gmu_gx_is_on(struct adreno_device *adreno_dev) 654: { 655: u32 val = 0; 656: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 657: 658: if (adreno_is_gen8_11_x(adreno_dev)) { 659: kgsl_regread(device, GEN8_GPU_CX_MISC_GFX_PWR_CLK_STATUS, &val); 660: return is_cx_misc_gx_on(val); 661: } 662: 663: gmu_core_regread(device, GEN8_GMUCX_GFX_PWR_CLK_STATUS, &val); 664: return is_on(val); 665: } 666: 667: bool gen8_gmu_malu_is_on(struct adreno_device *adreno_dev) 668: { 669: u32 val; 670: 671: kgsl_regread(KGSL_DEVICE(adreno_dev), 672: GEN8_GPU_CX_MISC_GFX_PWR_CLK_STATUS, &val); 673: return is_malu_on(val); 674: } 675: MATCH LINES: 1189, 1190 1177: kgsl_regwrite(device, GEN8_GPU_GX_CLKCTL_GX_MALU_GDSCR, GDSC_SW_COLLAPSE); 1178: 1179: if (gmu_core_timed_poll_check(device, GEN8_GPU_GX_CLKCTL_GX_MALU_CFG_GDSCR, 1180: GDSC_CFG_POWER_DOWN_COMPLETE, MALU_GDSC_TIMEOUT_MS, 1181: GDSC_CFG_POWER_DOWN_COMPLETE)) { 1182: 1183: gmu_core_regread(device, GEN8_GPU_GX_CLKCTL_GX_MALU_CFG_GDSCR, ®); 1184: dev_err(GMU_PDEV_DEV(device), "malu cfg gdsc stuck on:0x%x\n", reg); 1185: return; 1186: } 1187: 1188: if (gmu_core_timed_poll_check(device, GEN8_GPU_CX_MISC_GFX_PWR_CLK_STATUS, 1189: MALU_GDSC_POWER_OFF | MALU_CLK_OFF, MALU_GDSC_TIMEOUT_MS, 1190: MALU_GDSC_POWER_OFF | MALU_CLK_OFF)) { 1191: gmu_core_regread(device, GEN8_GPU_CX_MISC_GFX_PWR_CLK_STATUS, ®); 1192: dev_err(GMU_PDEV_DEV(device), "malu gdsc stuck on:0x%x\n", reg); 1193: } 1194: } 1195: 1196: static void gen8_gmu_pwrctrl_suspend(struct adreno_device *adreno_dev) 1197: { 1198: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1199: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1200: 1201: /* Disconnect GPU from BUS is not needed if CX GDSC goes off later */ 1202: 1203: /* 1204: * GEMNOC can enter power collapse state during GPU power down sequence. 1205: * This could abort CX GDSC collapse. Assert Qactive to avoid this. 1206: */ 1207: gmu_core_regwrite(device, GEN8_GMUCX_CX_FALNEXT_INTF, 0x1); 1208: 1209: /* Check no outstanding RPMh voting */ 1210: gen8_complete_rpmh_votes(gmu, 1); 1211: 1212: /* Clear the WRITEDROPPED fields and set fence to allow mode */ 1213: gmu_core_regwrite(device, GEN8_GMUAO_AHB_FENCE_STATUS_CLR, 0x7); 1214: gmu_core_regwrite(device, GEN8_GMUAO_AHB_FENCE_CTRL, 0); MATCH LINES: 1643 1631: ret = kgsl_pwrctrl_enable_cx_gdsc(device); 1632: if (ret) 1633: return ret; 1634: 1635: ret = kgsl_pwrctrl_enable_mx_gdsc(device); 1636: if (ret) 1637: goto cx_gdsc_off; 1638: 1639: ret = gmu_core_enable_clks(device, 0); 1640: if (ret) 1641: goto gdsc_off; 1642: 1643: ret = gen8_scm_gpu_init_cx_regs(adreno_dev); 1644: if (ret) 1645: goto clks_gdsc_off; 1646: 1647: gen8_get_gpu_slice_info(adreno_dev); 1648: 1649: /* 1650: * Enable AHB timeout detection to catch any register access taking longer 1651: * time before NOC timeout gets detected. Enable this logic before any 1652: * register access which happens to be just after enabling clocks. 1653: */ 1654: gen8_enable_ahb_timeout_detection(adreno_dev); 1655: 1656: /* Initialize the CX timer */ 1657: gen8_cx_timer_init(adreno_dev); 1658: 1659: ret = gen8_gmu_load_fw(adreno_dev); 1660: if (ret) 1661: goto clks_gdsc_off; 1662: 1663: ret = gen8_gmu_version_info(adreno_dev); 1664: if (ret) 1665: goto clks_gdsc_off; 1666: 1667: ret = gen8_gmu_itcm_shadow(adreno_dev); MATCH LINES: 2243 2231: 2232: /* Halt all AXI requests */ 2233: kgsl_regwrite(device, GEN8_GBIF_HALT, GEN8_GBIF_ARB_HALT_MASK); 2234: ret = adreno_wait_for_halt_ack(device, 2235: GEN8_GBIF_HALT_ACK, GEN8_GBIF_ARB_HALT_MASK); 2236: 2237: /* De-assert the halts */ 2238: kgsl_regwrite(device, GEN8_GBIF_HALT, 0x0); 2239: 2240: return ret; 2241: } 2242: 2243: static int gen8_gmu_power_off(struct adreno_device *adreno_dev) 2244: { 2245: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2246: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2247: int ret = 0; 2248: 2249: if (device->gmu_fault) 2250: goto error; 2251: 2252: /* Wait for the lowest idle level we requested */ 2253: ret = gen8_gmu_wait_for_lowest_idle(adreno_dev); 2254: if (ret) 2255: goto error; 2256: 2257: ret = gen8_complete_rpmh_votes(gmu, 2); 2258: if (ret) 2259: goto error; 2260: 2261: ret = gen8_gmu_notify_slumber(adreno_dev); 2262: if (ret) 2263: goto error; 2264: 2265: ret = gen8_gmu_wait_for_idle(adreno_dev); 2266: if (ret) 2267: goto error; MATCH LINES: 2360, 2388 2348: gen8_core->qos_value[adreno_dev->cur_rb->id]); 2349: 2350: /* Re-initialize the coresight registers if applicable */ 2351: adreno_coresight_start(adreno_dev); 2352: 2353: adreno_perfcounter_start(adreno_dev); 2354: 2355: /* Clear FSR here in case it is set from a previous pagefault */ 2356: kgsl_mmu_clear_fsr(&device->mmu); 2357: 2358: gen8_enable_gpu_irq(adreno_dev); 2359: 2360: ret = gen8_rb_start(adreno_dev); 2361: if (ret) { 2362: gen8_disable_gpu_irq(adreno_dev); 2363: adreno_llcc_slice_deactivate(adreno_dev); 2364: goto oob_clear; 2365: } 2366: 2367: /* 2368: * At this point it is safe to assume that we recovered. Setting 2369: * this field allows us to take a new snapshot for the next failure 2370: * if we are prioritizing the first unrecoverable snapshot. 2371: */ 2372: if (device->snapshot) 2373: device->snapshot->recovered = true; 2374: 2375: /* Start the dispatcher */ 2376: adreno_dispatcher_start(device); 2377: 2378: device->reset_counter++; 2379: 2380: gen8_gmu_oob_clear(device, oob_gpu); 2381: 2382: return 0; 2383: 2384: oob_clear: 2385: gen8_gmu_oob_clear(device, oob_gpu); 2386: 2387: err: 2388: gen8_gmu_power_off(adreno_dev); 2389: 2390: return ret; 2391: } 2392: 2393: static void gmu_idle_timer(struct timer_list *t) 2394: { 2395: struct kgsl_device *device = container_of(t, struct kgsl_device, 2396: idle_timer); 2397: 2398: kgsl_schedule_work(&device->idle_check_ws); 2399: } 2400: 2401: static int gen8_boot(struct adreno_device *adreno_dev) 2402: { 2403: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2404: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2405: int ret; 2406: 2407: if (WARN_ON(test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags))) 2408: return 0; 2409: 2410: kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE); 2411: 2412: ret = gen8_gmu_boot(adreno_dev); MATCH LINES: 2531, 2564 2519: static bool gen8_irq_pending(struct adreno_device *adreno_dev) 2520: { 2521: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2522: u32 status; 2523: 2524: kgsl_regread(device, GEN8_RBBM_INT_0_STATUS, &status); 2525: 2526: /* Return busy if a interrupt is pending */ 2527: return ((status & adreno_dev->irq_mask) || 2528: atomic_read(&adreno_dev->pending_irq_refcnt)); 2529: } 2530: 2531: static int gen8_power_off(struct adreno_device *adreno_dev) 2532: { 2533: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2534: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2535: int ret; 2536: 2537: WARN_ON(!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)); 2538: 2539: adreno_check_idle(device); 2540: 2541: kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); 2542: 2543: ret = gen8_gmu_oob_set(device, oob_gpu); 2544: if (ret) 2545: goto no_gx_power; 2546: 2547: if (gen8_irq_pending(adreno_dev)) { 2548: gen8_gmu_oob_clear(device, oob_gpu); 2549: return -EBUSY; 2550: } 2551: 2552: kgsl_pwrscale_update_stats(device); 2553: 2554: /* Save active coresight registers if applicable */ 2555: adreno_coresight_stop(adreno_dev); 2556: 2557: adreno_irqctrl(adreno_dev, 0); 2558: 2559: no_gx_power: 2560: gen8_gmu_oob_clear(device, oob_gpu); 2561: 2562: kgsl_pwrctrl_irq(device, false); 2563: 2564: gen8_gmu_power_off(adreno_dev); 2565: 2566: adreno_set_active_ctxs_null(adreno_dev); 2567: 2568: adreno_dispatcher_stop(adreno_dev); 2569: 2570: adreno_ringbuffer_stop(adreno_dev); 2571: 2572: adreno_llcc_slice_deactivate(adreno_dev); 2573: 2574: clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags); 2575: 2576: kgsl_delete_timer_sync(&device->idle_timer); 2577: 2578: kgsl_pwrscale_sleep(device); 2579: 2580: kgsl_pwrctrl_clear_l3_vote(device); 2581: 2582: /* 2583: * Reset the context records so that CP can start 2584: * at the correct read pointer for BV thread after 2585: * coming out of slumber. 2586: */ 2587: gen8_reset_preempt_records(adreno_dev); 2588: MATCH LINES: 2627 2615: spin_lock(&device->submit_lock); 2616: 2617: if (device->submit_now) { 2618: spin_unlock(&device->submit_lock); 2619: kgsl_pwrscale_update(device); 2620: kgsl_start_idle_timer(device); 2621: goto done; 2622: } 2623: 2624: device->skip_inline_submit = true; 2625: spin_unlock(&device->submit_lock); 2626: 2627: ret = gen8_power_off(adreno_dev); 2628: if (ret == -EBUSY) { 2629: kgsl_pwrscale_update(device); 2630: kgsl_start_idle_timer(device); 2631: } 2632: 2633: done: 2634: kgsl_mutex_unlock(&device->mutex); 2635: } 2636: 2637: static int gen8_gmu_first_open(struct adreno_device *adreno_dev) 2638: { 2639: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2640: int ret; 2641: 2642: /* 2643: * Do the one time settings that need to happen when we 2644: * attempt to boot the gpu the very first time 2645: */ 2646: ret = gen8_first_boot(adreno_dev); 2647: if (ret) 2648: return ret; 2649: 2650: /* 2651: * A client that does a first_open but never closes the device MATCH LINES: 2666 2654: */ 2655: atomic_inc(&device->active_cnt); 2656: adreno_active_count_put(adreno_dev); 2657: 2658: return 0; 2659: } 2660: 2661: static int gen8_gmu_last_close(struct adreno_device *adreno_dev) 2662: { 2663: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2664: 2665: if (test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 2666: return gen8_power_off(adreno_dev); 2667: 2668: return 0; 2669: } 2670: 2671: static int gen8_gmu_active_count_get(struct adreno_device *adreno_dev) 2672: { 2673: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2674: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2675: int ret = 0; 2676: 2677: if (WARN_ON(!kgsl_mutex_is_locked(&device->mutex))) 2678: return -EINVAL; 2679: 2680: if (test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags)) 2681: return -EINVAL; 2682: 2683: if ((atomic_read(&device->active_cnt) == 0) && 2684: !test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 2685: ret = gen8_boot(adreno_dev); 2686: 2687: if (ret == 0) 2688: atomic_inc(&device->active_cnt); 2689: 2690: trace_kgsl_active_count(device, MATCH LINES: 2712 2700: int ret; 2701: 2702: if (test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags)) 2703: return 0; 2704: 2705: kgsl_pwrctrl_request_state(device, KGSL_STATE_SUSPEND); 2706: 2707: ret = adreno_drain_and_idle(device); 2708: if (ret) 2709: goto err; 2710: 2711: if (test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 2712: gen8_power_off(adreno_dev); 2713: 2714: set_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags); 2715: 2716: adreno_get_gpu_halt(adreno_dev); 2717: 2718: kgsl_pwrctrl_set_state(device, KGSL_STATE_SUSPEND); 2719: 2720: return 0; 2721: err: 2722: adreno_dispatcher_start(device); 2723: return ret; 2724: } 2725: 2726: static void gen8_gmu_pm_resume(struct adreno_device *adreno_dev) 2727: { 2728: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2729: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2730: 2731: if (WARN(!test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags), 2732: "resume invoked without a suspend\n")) 2733: return; 2734: 2735: adreno_put_gpu_halt(adreno_dev); 2736: --- FILE: \adreno_gen8_hwsched.c | HITS: 8 --- MATCH LINES: 277 265: if (ret) 266: return ret; 267: 268: ret = kgsl_pwrctrl_enable_mx_gdsc(device); 269: if (ret) 270: goto cx_gdsc_off; 271: 272: /* Start the GMU at the lowest available frequency level */ 273: ret = gmu_core_enable_clks(device, 0); 274: if (ret) 275: goto gdsc_off; 276: 277: ret = gen8_scm_gpu_init_cx_regs(adreno_dev); 278: if (ret) 279: goto clks_gdsc_off; 280: 281: gen8_get_gpu_slice_info(adreno_dev); 282: 283: /* 284: * Set context record size after determining slice mask, 285: * as GMEM size depends on it. 286: */ 287: gen8_populate_ctxt_record_size(adreno_dev); 288: 289: gen8_hwsched_set_ctxt_record_vrb(adreno_dev); 290: 291: /* 292: * Enable AHB timeout detection to catch any register access taking longer 293: * time before NOC timeout gets detected. Enable this logic before any 294: * register access which happens to be just after enabling clocks. 295: */ 296: gen8_enable_ahb_timeout_detection(adreno_dev); 297: 298: /* Initialize the CX timer */ 299: gen8_cx_timer_init(adreno_dev); 300: 301: ret = gen8_gmu_load_fw(adreno_dev); MATCH LINES: 550 538: gen8_scm_gpu_tsense_suspend(adreno_dev); 539: 540: ret = gen8_hfi_send_cmd_async(adreno_dev, &req, sizeof(req)); 541: 542: /* 543: * GEMNOC can enter power collapse state during GPU power down sequence. 544: * This could abort CX GDSC collapse. Assert Qactive to avoid this. 545: */ 546: gmu_core_regwrite(device, GEN8_GMUCX_CX_FALNEXT_INTF, 0x1); 547: 548: return ret; 549: } 550: static int gen8_hwsched_gmu_power_off(struct adreno_device *adreno_dev) 551: { 552: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 553: int ret = 0; 554: 555: if (device->gmu_fault) 556: goto error; 557: 558: /* Wait for the lowest idle level we requested */ 559: ret = gen8_gmu_wait_for_lowest_idle(adreno_dev); 560: if (ret) 561: goto error; 562: 563: ret = gen8_hwsched_notify_slumber(adreno_dev); 564: if (ret) 565: goto error; 566: 567: ret = gen8_gmu_wait_for_idle(adreno_dev); 568: if (ret) 569: goto error; 570: 571: ret = gen8_rscc_sleep_sequence(adreno_dev); 572: 573: gmu_core_rdpm_mx_freq_update(device, 0); 574: MATCH LINES: 693 681: device->reset_counter++; 682: 683: /* 684: * If warmboot is enabled and we switched a sysfs node, we will do a coldboot 685: * in the subseqent slumber exit. Once that is done we need to mark this bool 686: * as false so that in the next run we can do warmboot 687: */ 688: clear_bit(GMU_FORCE_COLDBOOT, &device->gmu_core.flags); 689: err: 690: gen8_gmu_oob_clear(device, oob_gpu); 691: 692: if (ret) 693: gen8_hwsched_gmu_power_off(adreno_dev); 694: 695: return ret; 696: } 697: 698: static void hwsched_idle_timer(struct timer_list *t) 699: { 700: struct kgsl_device *device = container_of(t, struct kgsl_device, 701: idle_timer); 702: 703: kgsl_schedule_work(&device->idle_check_ws); 704: } 705: 706: static int gen8_gmu_warmboot_init(struct adreno_device *adreno_dev) 707: { 708: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 709: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 710: int ret = 0; 711: 712: if (!ADRENO_FEATURE(adreno_dev, ADRENO_GMU_WARMBOOT)) 713: return ret; 714: 715: if (IS_ERR_OR_NULL(gmu->gmu_init_scratch)) { 716: gmu->gmu_init_scratch = gmu_core_reserve_kernel_block(device, 0, 717: SZ_4K, GMU_CACHE, 0); MATCH LINES: 1009, 1043 997: if (ret) 998: break; 999: } 1000: } 1001: read_unlock(&device->context_lock); 1002: 1003: if (ret) 1004: gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE); 1005: 1006: return ret; 1007: } 1008: 1009: static int gen8_hwsched_power_off(struct adreno_device *adreno_dev) 1010: { 1011: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1012: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1013: int ret = 0; 1014: bool drain_cpu = false; 1015: 1016: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 1017: return 0; 1018: 1019: kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); 1020: 1021: ret = gen8_gmu_oob_set(device, oob_gpu); 1022: if (ret) { 1023: gen8_gmu_oob_clear(device, oob_gpu); 1024: goto no_gx_power; 1025: } 1026: 1027: kgsl_pwrscale_update_stats(device); 1028: 1029: /* Save active coresight registers if applicable */ 1030: adreno_coresight_stop(adreno_dev); 1031: 1032: adreno_irqctrl(adreno_dev, 0); 1033: 1034: gen8_gmu_oob_clear(device, oob_gpu); 1035: 1036: no_gx_power: 1037: kgsl_pwrctrl_irq(device, false); 1038: 1039: /* Make sure GMU has sent all hardware fences to TxQueue */ 1040: if (check_inflight_hw_fences(adreno_dev)) 1041: drain_cpu = true; 1042: 1043: gen8_hwsched_gmu_power_off(adreno_dev); 1044: 1045: /* Now that we are sure that GMU is powered off, drain pending fences */ 1046: if (drain_cpu) 1047: drain_hw_fences_cpu(adreno_dev); 1048: 1049: adreno_hwsched_unregister_contexts(adreno_dev); 1050: 1051: adreno_llcc_slice_deactivate(adreno_dev); 1052: 1053: clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags); 1054: 1055: kgsl_delete_timer_sync(&device->idle_timer); 1056: 1057: kgsl_pwrscale_sleep(device); 1058: 1059: kgsl_pwrctrl_clear_l3_vote(device); 1060: 1061: gen8_hwsched_soccp_vote(adreno_dev, false); 1062: 1063: kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER); 1064: 1065: return ret; 1066: } 1067: MATCH LINES: 1127 1115: } 1116: 1117: device->skip_inline_submit = true; 1118: spin_unlock(&device->submit_lock); 1119: 1120: if (!gpudev->hw_isidle(adreno_dev)) { 1121: dev_err(device->dev, "GPU isn't idle before SLUMBER\n"); 1122: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 1123: } 1124: 1125: check_hw_fence_unack_count(adreno_dev); 1126: 1127: gen8_hwsched_power_off(adreno_dev); 1128: 1129: done: 1130: kgsl_mutex_unlock(&device->mutex); 1131: } 1132: 1133: static int gen8_hwsched_first_open(struct adreno_device *adreno_dev) 1134: { 1135: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1136: int ret; 1137: 1138: /* 1139: * Do the one time settings that need to happen when we 1140: * attempt to boot the gpu the very first time 1141: */ 1142: ret = gen8_hwsched_first_boot(adreno_dev); 1143: if (ret) 1144: return ret; 1145: 1146: /* 1147: * A client that does a first_open but never closes the device 1148: * may prevent us from going back to SLUMBER. So trigger the idle 1149: * check by incrementing the active count and immediately releasing it. 1150: */ 1151: atomic_inc(&device->active_cnt); MATCH LINES: 1311 1299: goto err; 1300: 1301: active_count = atomic_read(&device->active_cnt); 1302: 1303: if (active_count > 0) { 1304: ret = -ETIMEDOUT; 1305: dev_err_ratelimited(GMU_PDEV_DEV(device), 1306: "Aborting suspend because of active count:%d\n", 1307: active_count); 1308: goto err; 1309: } 1310: 1311: gen8_hwsched_power_off(adreno_dev); 1312: 1313: adreno_get_gpu_halt(adreno_dev); 1314: 1315: set_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags); 1316: 1317: kgsl_pwrctrl_set_state(device, KGSL_STATE_SUSPEND); 1318: 1319: return 0; 1320: 1321: err: 1322: adreno_hwsched_start(adreno_dev); 1323: 1324: return ret; 1325: } 1326: 1327: static void gen8_hwsched_pm_resume(struct adreno_device *adreno_dev) 1328: { 1329: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1330: 1331: if (WARN(!test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags), 1332: "resume invoked without a suspend\n")) 1333: return; 1334: 1335: adreno_put_gpu_halt(adreno_dev); MATCH LINES: 2082 2070: break; 2071: case GPU_PWRLEVEL_OP_DCVS_ENABLE: 2072: gen8_hwsched_set_dcvs_enable(adreno_dev, arg); 2073: break; 2074: case GPU_PWRLEVEL_OP_TUNING_ATTR: 2075: gen8_hwsched_set_tuning_param(adreno_dev, arg); 2076: break; 2077: } 2078: } 2079: 2080: const struct adreno_power_ops gen8_hwsched_power_ops = { 2081: .first_open = gen8_hwsched_first_open, 2082: .last_close = gen8_hwsched_power_off, 2083: .active_count_get = gen8_hwsched_active_count_get, 2084: .touch_wakeup = gen8_hwsched_touch_wakeup, 2085: .pm_suspend = gen8_hwsched_pm_suspend, 2086: .pm_resume = gen8_hwsched_pm_resume, 2087: .gpu_clock_set = gen8_hwsched_clock_set, 2088: .gpu_bus_set = gen8_hwsched_bus_set, 2089: .gmu_based_dcvs_pwr_ops = gen8_hwsched_gmu_based_dcvs_pwr_ops, 2090: }; 2091: 2092: const struct adreno_hwsched_ops gen8_hwsched_ops = { 2093: .submit_drawobj = gen8_hwsched_submit_drawobj, 2094: .preempt_count = gen8_hwsched_preempt_count_get, 2095: .preempt_info = gen8_hwsched_preempt_info_get, 2096: .create_hw_fence = gen8_hwsched_create_hw_fence, 2097: .set_dcvs_profile = gen8_hwsched_set_dcvs_profile, 2098: }; 2099: 2100: int gen8_hwsched_probe(struct platform_device *pdev, 2101: u32 chipid, const struct adreno_gpu_core *gpucore) 2102: { 2103: struct adreno_device *adreno_dev; 2104: struct kgsl_device *device; 2105: struct gen8_hwsched_device *gen8_hwsched_dev; 2106: struct gen8_device *gen8_dev; --- FILE: \kgsl_pwrctrl.c | HITS: 8 --- MATCH LINES: 698 686: { 687: if (on) { 688: switch (flag) { 689: case KGSL_PWRFLAGS_CLK_ON: 690: /* make sure pwrrail is ON before enabling clocks */ 691: kgsl_pwrctrl_pwrrail(device, true); 692: kgsl_pwrctrl_clk(device, true, 693: KGSL_STATE_ACTIVE); 694: break; 695: case KGSL_PWRFLAGS_AXI_ON: 696: kgsl_pwrctrl_axi(device, true); 697: break; 698: case KGSL_PWRFLAGS_POWER_ON: 699: kgsl_pwrctrl_pwrrail(device, true); 700: break; 701: } 702: set_bit(flag, &device->pwrctrl.ctrl_flags); 703: } else { 704: clear_bit(flag, &device->pwrctrl.ctrl_flags); 705: } 706: } 707: 708: static ssize_t __force_on_show(struct device *dev, 709: struct device_attribute *attr, 710: char *buf, int flag) 711: { 712: struct kgsl_device *device = dev_get_drvdata(dev); 713: 714: return scnprintf(buf, PAGE_SIZE, "%d\n", 715: test_bit(flag, &device->pwrctrl.ctrl_flags)); 716: } 717: 718: static ssize_t __force_on_store(struct device *dev, 719: struct device_attribute *attr, 720: const char *buf, size_t count, 721: int flag) 722: { MATCH LINES: 770, 777 758: } 759: 760: static ssize_t force_bus_on_store(struct device *dev, 761: struct device_attribute *attr, 762: const char *buf, size_t count) 763: { 764: return __force_on_store(dev, attr, buf, count, KGSL_PWRFLAGS_AXI_ON); 765: } 766: 767: static ssize_t force_rail_on_show(struct device *dev, 768: struct device_attribute *attr, char *buf) 769: { 770: return __force_on_show(dev, attr, buf, KGSL_PWRFLAGS_POWER_ON); 771: } 772: 773: static ssize_t force_rail_on_store(struct device *dev, 774: struct device_attribute *attr, 775: const char *buf, size_t count) 776: { 777: return __force_on_store(dev, attr, buf, count, KGSL_PWRFLAGS_POWER_ON); 778: } 779: 780: static ssize_t force_no_nap_show(struct device *dev, 781: struct device_attribute *attr, char *buf) 782: { 783: /* force_no_nap is deprecated, so return it as always disabled */ 784: return scnprintf(buf, PAGE_SIZE, "0\n"); 785: } 786: 787: static ssize_t force_no_nap_store(struct device *dev, 788: struct device_attribute *attr, 789: const char *buf, size_t count) 790: { 791: /* force_no_nap is deprecated, so return EOPNOTSUPP */ 792: return -EOPNOTSUPP; 793: } 794: 795: static ssize_t bus_split_show(struct device *dev, 796: struct device_attribute *attr, char *buf) 797: { 798: struct kgsl_device *device = dev_get_drvdata(dev); 799: 800: return scnprintf(buf, PAGE_SIZE, "%d\n", 801: device->pwrctrl.bus_control); MATCH LINES: 1521, 1535, 1539 1509: else 1510: ret = kgsl_genpd_disable_wait(pwr->gx_pd, GX_GDSC_TIMEOUT_MS); 1511: 1512: if (ret) 1513: dev_err(device->dev, "vdd is stuck on, error %d\n", ret); 1514: } 1515: 1516: static int enable_gdscs(struct kgsl_device *device) 1517: { 1518: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 1519: int ret; 1520: 1521: if (test_and_set_bit(KGSL_PWRFLAGS_POWER_ON, &pwr->power_flags)) 1522: return 0; 1523: 1524: ret = kgsl_pwrctrl_enable_cx_gdsc(device); 1525: if (!ret) { 1526: /* Set parent in retention voltage to power up vdd supply */ 1527: ret = kgsl_regulator_set_voltage(device->dev, 1528: pwr->gx_regulator_parent, 1529: pwr->gx_regulator_parent_min_corner); 1530: if (!ret) 1531: ret = kgsl_pwrctrl_enable_gx_gdsc(device); 1532: } 1533: 1534: if (ret) { 1535: clear_bit(KGSL_PWRFLAGS_POWER_ON, &pwr->power_flags); 1536: return ret; 1537: } 1538: 1539: trace_kgsl_rail(device, KGSL_PWRFLAGS_POWER_ON); 1540: return 0; 1541: } 1542: 1543: #ifdef CONFIG_QCOM_KGSL_UPSTREAM 1544: static int kgsl_device_link_add_cxpd_iommu(struct kgsl_device *device) 1545: { 1546: struct device_node *phandle; 1547: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 1548: struct platform_device *pdev = iommu->user_context.pdev; 1549: struct platform_device *iommu_pdev; 1550: 1551: if (!device->pwrctrl.cx_pd) 1552: return 0; 1553: 1554: /* 1555: * With standard bindings, iommus property is defined in the GPU node. 1556: * If the property is not found in GPU node, try the legacy way by 1557: * checking for the property in user context node. 1558: */ 1559: phandle = of_parse_phandle(device->pdev->dev.of_node, "iommus", 0); 1560: if (!phandle) 1561: phandle = of_parse_phandle(pdev->dev.of_node, "iommus", 0); 1562: 1563: if (!phandle) MATCH LINES: 1768, 1773 1756: 1757: static int kgsl_pwrctrl_pwrrail(struct kgsl_device *device, bool state) 1758: { 1759: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 1760: int status = 0; 1761: 1762: if (gmu_core_gpmu_isenabled(device)) 1763: return 0; 1764: /* 1765: * Disabling the regulator means also disabling dependent clocks. 1766: * Hence don't disable it if force clock ON is set. 1767: */ 1768: if (test_bit(KGSL_PWRFLAGS_POWER_ON, &pwr->ctrl_flags) || 1769: test_bit(KGSL_PWRFLAGS_CLK_ON, &pwr->ctrl_flags)) 1770: return 0; 1771: 1772: if (!state) { 1773: if (test_and_clear_bit(KGSL_PWRFLAGS_POWER_ON, 1774: &pwr->power_flags)) { 1775: kgsl_mmu_send_tlb_hint(&device->mmu, true); 1776: trace_kgsl_rail(device, state); 1777: 1778: /* Set the parent in retention voltage to disable CPR interrupts */ 1779: kgsl_regulator_set_voltage(device->dev, pwr->gx_regulator_parent, 1780: pwr->gx_regulator_parent_min_corner); 1781: 1782: kgsl_pwrctrl_disable_gx_gdsc(device); 1783: 1784: /* Remove the vote for the vdd parent supply */ 1785: kgsl_regulator_set_voltage(device->dev, pwr->gx_regulator_parent, 0); 1786: 1787: kgsl_pwrctrl_disable_cx_gdsc(device); 1788: } 1789: } else { 1790: status = enable_gdscs(device); 1791: kgsl_mmu_send_tlb_hint(&device->mmu, false); 1792: } 1793: 1794: return status; 1795: } 1796: 1797: void kgsl_pwrctrl_irq(struct kgsl_device *device, bool state) --- FILE: \kgsl_pwrctrl.h | HITS: 1 --- MATCH LINES: 19 7: #define __KGSL_PWRCTRL_H 8: 9: #include 10: #include 11: 12: /***************************************************************************** 13: * power flags 14: ****************************************************************************/ 15: #define KGSL_MAX_CLKS 19 16: 17: #define KGSL_MAX_PWRLEVELS 32 18: 19: #define KGSL_PWRFLAGS_POWER_ON 0 20: #define KGSL_PWRFLAGS_CLK_ON 1 21: #define KGSL_PWRFLAGS_AXI_ON 2 22: #define KGSL_PWRFLAGS_IRQ_ON 3 23: 24: /* Use to enable all the force power on states at once */ 25: #define KGSL_PWR_ON GENMASK(5, 0) 26: 27: /* Only two supported levels, min & max */ 28: #define KGSL_CONSTRAINT_PWR_MAXLEVELS 2 29: 30: #define KGSL_XO_CLK_FREQ 19200000 31: #define KGSL_ISENSE_CLK_FREQ 200000000 32: 33: #define KGSL_PWRCTRL_LOG_FREQLIM(device) dev_err_ratelimited(device->dev, \ 34: "GPU req freq %u from prev freq %u unsupported for speed_bin: %d, soc_code: 0x%x\n", \ 35: device->pwrctrl.pwrlevels[device->pwrctrl.active_pwrlevel].gpu_freq, \ 36: device->pwrctrl.pwrlevels[device->pwrctrl.previous_pwrlevel].gpu_freq, \ 37: device->speed_bin, \ 38: device->soc_code) 39: 40: struct platform_device; 41: struct icc_path; 42: 43: struct kgsl_clk_stats { --- FILE: \kgsl_util.c | HITS: 7 --- MATCH LINES: 107, 112, 114, 117, 122, 128, 135 95: alt_id[new_len] = '\0'; 96: clk = kgsl_of_clk_by_name(clks, num_clks, alt_id); 97: } 98: } 99: 100: if (!clk) 101: return -ENODEV; 102: 103: return clk_set_rate(clk, rate); 104: } 105: 106: #if (KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE) 107: static int _kgsl_scm_gpu_init_regs(u32 gpu_req) 108: { 109: return -EOPNOTSUPP; 110: } 111: #elif (KERNEL_VERSION(6, 11, 0) <= LINUX_VERSION_CODE) 112: static int _kgsl_scm_gpu_init_regs(u32 gpu_req) 113: { 114: return qcom_scm_gpu_init_regs(gpu_req); 115: } 116: #elif (IS_ENABLED(CONFIG_QCOM_KGSL_UPSTREAM) && !IS_ENABLED(CONFIG_QCOM_SCM_ADDON)) 117: static int _kgsl_scm_gpu_init_regs(u32 gpu_req) 118: { 119: return -EINVAL; 120: } 121: #else 122: static int _kgsl_scm_gpu_init_regs(u32 gpu_req) 123: { 124: return qcom_scm_kgsl_init_regs(gpu_req); 125: } 126: #endif 127: 128: int kgsl_scm_gpu_init_regs(struct device *dev, u32 gpu_req, bool zap_enabled) 129: { 130: int ret; 131: 132: if (!gpu_req) 133: return -EOPNOTSUPP; 134: 135: ret = _kgsl_scm_gpu_init_regs(gpu_req); 136: if (ret && (ret != -EOPNOTSUPP)) { 137: if (zap_enabled) 138: dev_err(dev, "Scm call for requests:0x%x failed with ret:: %d\n", 139: gpu_req, ret); 140: else 141: return -EOPNOTSUPP; 142: } 143: 144: return ret; 145: } 146: 147: int kgsl_hwlock(struct cpu_gpu_lock *lock) 148: { 149: unsigned long timeout = jiffies + msecs_to_jiffies(1000); 150: 151: /* Indicate that the CPU wants the lock */ 152: lock->cpu_req = 1; 153: 154: /* post the request */ 155: wmb(); 156: 157: /* Wait for our turn */ 158: lock->turn = 0; 159: --- FILE: \kgsl_util.h | HITS: 2 --- MATCH LINES: 198, 206 186: 187: /** 188: * kgsl_detach_iommu_group() - Detach iommu domain from group 189: * 190: * @domain: iommu domain to detach 191: * @group: iommu group to be used for detach 192: * 193: * Detach iommu domain from iommu group 194: */ 195: void kgsl_detach_iommu_group(struct iommu_domain *domain, struct iommu_group *group); 196: 197: /** 198: * kgsl_scm_gpu_init_regs - Load secure registers through tz 199: * @dev: Pointer to the GPU platform device 200: * @gpu_req: Bit mask of requests to enable 201: * @zap_enabled: True when there is no zap-shader 202: * 203: * Return: 0 on success or negative on failure and EOPNOTSUPP if scm call 204: * not supported 205: */ 206: int kgsl_scm_gpu_init_regs(struct device *dev, u32 gpu_req, bool zap_enabled); 207: 208: #if IS_ENABLED(CONFIG_QCOM_VA_MINIDUMP) 209: /** 210: * kgsl_add_to_minidump - Add a physically contiguous section to minidump 211: * @name: Name of the section 212: * @virt_addr: Virtual address of the section 213: * @phy_addr: Physical address of the section 214: * @size: Size of the section 215: */ 216: void kgsl_add_to_minidump(char *name, u64 virt_addr, u64 phy_addr, size_t size); 217: 218: /** 219: * kgsl_remove_from_minidump - Remove a contiguous section from minidump 220: * @name: Name of the section 221: * @virt_addr: Virtual address of the section 222: * @phy_addr: Physical address of the section 223: * @size: Size of the section 224: */ 225: void kgsl_remove_from_minidump(char *name, u64 virt_addr, u64 phy_addr, size_t size); 226: 227: /** 228: * kgsl_add_va_to_minidump - Add a physically non-contiguous section to minidump 229: * @dev: Pointer to the struct device for the GPU platform device 230: * @name: Name of the section TOTAL MATCHES: 151 ========================================================================================== SUBSYSTEM: RINGBUFFER_AND_CP ========================================================================================== --- FILE: \a5xx_reg.h | HITS: 7 --- MATCH LINES: 90, 91, 92, 93, 94, 95, 96 78: #define A5XX_CP_MERCIU_DBG_DATA_2 0x829 79: #define A5XX_CP_PFP_UCODE_DBG_ADDR 0x82A 80: #define A5XX_CP_PFP_UCODE_DBG_DATA 0x82B 81: #define A5XX_CP_ME_UCODE_DBG_ADDR 0x82F 82: #define A5XX_CP_ME_UCODE_DBG_DATA 0x830 83: #define A5XX_CP_CNTL 0x831 84: #define A5XX_CP_ME_CNTL 0x832 85: #define A5XX_CP_CHICKEN_DBG 0x833 86: #define A5XX_CP_PFP_INSTR_BASE_LO 0x835 87: #define A5XX_CP_PFP_INSTR_BASE_HI 0x836 88: #define A5XX_CP_PM4_INSTR_BASE_LO 0x838 89: #define A5XX_CP_PM4_INSTR_BASE_HI 0x839 90: #define A5XX_CP_CONTEXT_SWITCH_CNTL 0x83B 91: #define A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_LO 0x83C 92: #define A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_HI 0x83D 93: #define A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_LO 0x83E 94: #define A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_HI 0x83F 95: #define A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x840 96: #define A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x841 97: #define A5XX_CP_ADDR_MODE_CNTL 0x860 98: #define A5XX_CP_ME_STAT_DATA 0xB14 99: #define A5XX_CP_WFI_PEND_CTR 0xB15 100: #define A5XX_CP_INTERRUPT_STATUS 0xB18 101: #define A5XX_CP_HW_FAULT 0xB1A 102: #define A5XX_CP_PROTECT_STATUS 0xB1C 103: #define A5XX_CP_IB1_BASE 0xB1F 104: #define A5XX_CP_IB1_BASE_HI 0xB20 105: #define A5XX_CP_IB1_BUFSZ 0xB21 106: #define A5XX_CP_IB2_BASE 0xB22 107: #define A5XX_CP_IB2_BASE_HI 0xB23 108: #define A5XX_CP_IB2_BUFSZ 0xB24 109: #define A5XX_CP_PROTECT_REG_0 0x880 110: #define A5XX_CP_PROTECT_CNTL 0x8A0 111: #define A5XX_CP_AHB_FAULT 0xB1B 112: #define A5XX_CP_PERFCTR_CP_SEL_0 0xBB0 113: #define A5XX_CP_PERFCTR_CP_SEL_1 0xBB1 114: #define A5XX_CP_PERFCTR_CP_SEL_2 0xBB2 115: #define A5XX_CP_PERFCTR_CP_SEL_3 0xBB3 116: #define A5XX_CP_PERFCTR_CP_SEL_4 0xBB4 117: #define A5XX_CP_PERFCTR_CP_SEL_5 0xBB5 118: #define A5XX_CP_PERFCTR_CP_SEL_6 0xBB6 119: #define A5XX_CP_PERFCTR_CP_SEL_7 0xBB7 120: --- FILE: \a6xx_reg.h | HITS: 10 --- MATCH LINES: 71, 72, 73, 74, 75, 76, 77, 78, 79, 80 59: #define A6XX_CP_SQE_INSTR_BASE_LO 0x830 60: #define A6XX_CP_SQE_INSTR_BASE_HI 0x831 61: #define A6XX_CP_MISC_CNTL 0x840 62: #define A6XX_CP_APRIV_CNTL 0X844 63: #define A6XX_CP_ROQ_THRESHOLDS_1 0x8C1 64: #define A6XX_CP_ROQ_THRESHOLDS_2 0x8C2 65: #define A6XX_CP_MEM_POOL_SIZE 0x8C3 66: #define A6XX_CP_CHICKEN_DBG 0x841 67: #define A6XX_CP_ADDR_MODE_CNTL 0x842 68: #define A6XX_CP_DBG_ECO_CNTL 0x843 69: #define A6XX_CP_PROTECT_CNTL 0x84F 70: #define A6XX_CP_PROTECT_REG 0x850 71: #define A6XX_CP_CONTEXT_SWITCH_CNTL 0x8A0 72: #define A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x8A1 73: #define A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x8A2 74: #define A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO 0x8A3 75: #define A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI 0x8A4 76: #define A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO 0x8A5 77: #define A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI 0x8A6 78: #define A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO 0x8A7 79: #define A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI 0x8A8 80: #define A6XX_CP_CONTEXT_SWITCH_LEVEL_STATUS 0x8AB 81: #define A6XX_CP_PERFCTR_CP_SEL_0 0x8D0 82: #define A6XX_CP_PERFCTR_CP_SEL_1 0x8D1 83: #define A6XX_CP_PERFCTR_CP_SEL_2 0x8D2 84: #define A6XX_CP_PERFCTR_CP_SEL_3 0x8D3 85: #define A6XX_CP_PERFCTR_CP_SEL_4 0x8D4 86: #define A6XX_CP_PERFCTR_CP_SEL_5 0x8D5 87: #define A6XX_CP_PERFCTR_CP_SEL_6 0x8D6 88: #define A6XX_CP_PERFCTR_CP_SEL_7 0x8D7 89: #define A6XX_CP_PERFCTR_CP_SEL_8 0x8D8 90: #define A6XX_CP_PERFCTR_CP_SEL_9 0x8D9 91: #define A6XX_CP_PERFCTR_CP_SEL_10 0x8DA 92: #define A6XX_CP_PERFCTR_CP_SEL_11 0x8DB 93: #define A6XX_CP_PERFCTR_CP_SEL_12 0x8DC 94: #define A6XX_CP_PERFCTR_CP_SEL_13 0x8DD 95: #define A6XX_CP_CRASH_SCRIPT_BASE_LO 0x900 96: #define A6XX_CP_CRASH_SCRIPT_BASE_HI 0x901 97: #define A6XX_CP_CRASH_DUMP_CNTL 0x902 98: #define A6XX_CP_CRASH_DUMP_STATUS 0x903 99: #define A6XX_CP_SQE_STAT_ADDR 0x908 100: #define A6XX_CP_SQE_STAT_DATA 0x909 101: #define A6XX_CP_DRAW_STATE_ADDR 0x90A 102: #define A6XX_CP_DRAW_STATE_DATA 0x90B 103: #define A6XX_CP_ROQ_DBG_ADDR 0x90C 104: #define A6XX_CP_ROQ_DBG_DATA 0x90D --- FILE: \adreno.c | HITS: 16 --- MATCH LINES: 441, 442, 446 429: unsigned int val_lo = 0, val_hi = 0; 430: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 431: 432: if (adreno_checkreg_off(adreno_dev, lo)) 433: kgsl_regread(device, gpudev->reg_offsets[lo], &val_lo); 434: if (adreno_checkreg_off(adreno_dev, hi)) 435: kgsl_regread(device, gpudev->reg_offsets[hi], &val_hi); 436: 437: *val = (val_lo | ((uint64_t)val_hi << 32)); 438: } 439: 440: /** 441: * adreno_get_rptr() - Get the current ringbuffer read pointer 442: * @rb: Pointer the ringbuffer to query 443: * 444: * Get the latest rptr 445: */ 446: unsigned int adreno_get_rptr(struct adreno_ringbuffer *rb) 447: { 448: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 449: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 450: u32 rptr = 0; 451: 452: kgsl_sharedmem_readl(device->scratch, &rptr, 453: SCRATCH_RB_OFFSET(rb->id, rptr)); 454: 455: return rptr; 456: } 457: 458: static void adreno_touch_wakeup(struct adreno_device *adreno_dev) 459: { 460: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 461: 462: /* 463: * Don't schedule adreno_start in a high priority workqueue, we are 464: * already in a workqueue which should be sufficient 465: */ 466: kgsl_pwrctrl_change_state(device, KGSL_STATE_ACTIVE); 467: 468: /* 469: * When waking up from a touch event we want to stay active long enough 470: * for the user to send a draw command. The default idle timer timeout MATCH LINES: 1842, 1843 1830: adreno_dev->ft_policy = BIT(KGSL_FT_REPLAY) | 1831: BIT(KGSL_FT_SKIPCMD) | BIT(KGSL_FT_THROTTLE); 1832: 1833: /* Enable command timeouts by default */ 1834: adreno_dev->long_ib_detect = true; 1835: 1836: INIT_WORK(&adreno_dev->input_work, adreno_input_work); 1837: 1838: INIT_LIST_HEAD(&adreno_dev->active_list); 1839: spin_lock_init(&adreno_dev->active_list_lock); 1840: rwlock_init(&adreno_dev->fault_stats_lock); 1841: 1842: for (i = 0; i < ARRAY_SIZE(adreno_dev->ringbuffers); i++) { 1843: struct adreno_ringbuffer *rb = &adreno_dev->ringbuffers[i]; 1844: 1845: INIT_LIST_HEAD(&rb->events.group); 1846: } 1847: 1848: /* 1849: * Some GPUs needs specific alignment for UCHE GMEM base address. 1850: * Configure UCHE GMEM base based on GMEM size and align it accordingly. 1851: * This needs to be done based on GMEM size to avoid overlap between 1852: * RB and UCHE GMEM range. 1853: */ 1854: if (adreno_dev->gpucore->uche_gmem_alignment) 1855: adreno_dev->uche_gmem_base = 1856: ALIGN(adreno_dev->gpucore->gmem_size, 1857: adreno_dev->gpucore->uche_gmem_alignment); 1858: } 1859: 1860: static const struct of_device_id adreno_component_match[] = { 1861: { .compatible = "qcom,adreno-gmu" }, 1862: { .compatible = "qcom,adreno-rgmu" }, 1863: {}, 1864: }; 1865: 1866: static const struct of_device_id adreno_component_match_legacy[] = { 1867: { .compatible = "qcom,gen8-gmu" }, MATCH LINES: 2624, 2627 2612: if (pwr->gmu_cx_pd) 2613: return kgsl_genpd_is_enabled(pwr->gmu_cx_pd); 2614: 2615: if (pwr->gx_pd) 2616: return kgsl_genpd_is_enabled(pwr->gx_pd); 2617: 2618: return false; 2619: } 2620: 2621: void adreno_set_active_ctxs_null(struct adreno_device *adreno_dev) 2622: { 2623: int i; 2624: struct adreno_ringbuffer *rb; 2625: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2626: 2627: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2628: if (rb->drawctxt_active) 2629: kgsl_context_put(&(rb->drawctxt_active->base)); 2630: rb->drawctxt_active = NULL; 2631: 2632: kgsl_sharedmem_writel(device->scratch, 2633: SCRATCH_RB_OFFSET(rb->id, current_rb_ptname), 2634: 0); 2635: } 2636: } 2637: 2638: static int adreno_open(struct adreno_device *adreno_dev) 2639: { 2640: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2641: int ret; 2642: 2643: /* 2644: * active_cnt special case: we are starting up for the first 2645: * time, so use this sequence instead of the kgsl_pwrctrl_wake() 2646: * which will be called by adreno_active_count_get(). 2647: */ 2648: atomic_inc(&device->active_cnt); 2649: 2650: memset(device->memstore->hostptr, 0, device->memstore->size); 2651: MATCH LINES: 3010 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; MATCH LINES: 3689, 3690, 3692, 3711, 3718, 3724, 3728 3677: adreno_dev->busy_data.bif_starved_ram = 0; 3678: adreno_dev->busy_data.bif_starved_ram_ch1 = 0; 3679: 3680: /* Reinitialize the GPU */ 3681: gpudev->start(adreno_dev); 3682: 3683: /* Re-initialize the coresight registers if applicable */ 3684: adreno_coresight_start(adreno_dev); 3685: 3686: /* Enable IRQ */ 3687: adreno_irqctrl(adreno_dev, 1); 3688: 3689: /* stop all ringbuffers to cancel RB events */ 3690: adreno_ringbuffer_stop(adreno_dev); 3691: 3692: /* Start the ringbuffer(s) again */ 3693: ret = gpudev->rb_start(adreno_dev); 3694: if (ret == 0) { 3695: device->reset_counter++; 3696: set_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv); 3697: } 3698: 3699: /* Restore physical performance counter values after soft reset */ 3700: adreno_perfcounter_restore(adreno_dev); 3701: 3702: if (ret) 3703: dev_err(device->dev, "Device soft reset failed: %d\n", ret); 3704: 3705: return ret; 3706: } 3707: 3708: bool adreno_isidle(struct adreno_device *adreno_dev) 3709: { 3710: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 3711: struct adreno_ringbuffer *rb; 3712: int i; 3713: 3714: if (!kgsl_state_is_awake(KGSL_DEVICE(adreno_dev))) 3715: return true; 3716: 3717: /* 3718: * wptr is updated when we add commands to ringbuffer, add a barrier 3719: * to make sure updated wptr is compared to rptr 3720: */ 3721: smp_mb(); 3722: 3723: /* 3724: * ringbuffer is truly idle when all ringbuffers read and write 3725: * pointers are equal 3726: */ 3727: 3728: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 3729: if (!adreno_rb_empty(rb)) 3730: return false; 3731: } 3732: 3733: return gpudev->hw_isidle(adreno_dev); 3734: } 3735: 3736: /** 3737: * adreno_spin_idle() - Spin wait for the GPU to idle 3738: * @adreno_dev: Pointer to an adreno device 3739: * @timeout: milliseconds to wait before returning error 3740: * 3741: * Spin the CPU waiting for the RBBM status to return idle 3742: */ 3743: int adreno_spin_idle(struct adreno_device *adreno_dev, unsigned int timeout) 3744: { 3745: unsigned long wait = jiffies + msecs_to_jiffies(timeout); 3746: 3747: do { 3748: /* 3749: * If we fault, stop waiting and return an error. The dispatcher 3750: * will clean up the fault from the work queue, but we need to 3751: * make sure we don't block it by waiting for an idle that 3752: * will never come. MATCH LINES: 3999 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. --- FILE: \adreno.h | HITS: 22 --- MATCH LINES: 19 7: #define __ADRENO_H 8: 9: #include 10: #include 11: #include 12: #include 13: #include "adreno_coresight.h" 14: #include "adreno_dispatch.h" 15: #include "adreno_drawctxt.h" 16: #include "adreno_hwsched.h" 17: #include "adreno_perfcounter.h" 18: #include "adreno_profile.h" 19: #include "adreno_ringbuffer.h" 20: #include "kgsl_sharedmem.h" 21: 22: /* Used to point CP to the SMMU record during preemption */ 23: #define SET_PSEUDO_SMMU_INFO 0 24: /* Used to inform CP where to save preemption data at the time of switch out */ 25: #define SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR 1 26: /* Used to inform CP where to save secure preemption data at the time of switch out */ 27: #define SET_PSEUDO_PRIV_SECURE_SAVE_ADDR 2 28: /* Used to inform CP where to save per context non-secure data at the time of switch out */ 29: #define SET_PSEUDO_NON_PRIV_SAVE_ADDR 3 30: /* Used to inform CP where to save preemption counter data at the time of switch out */ 31: #define SET_PSEUDO_COUNTER 4 32: 33: /* Index to preemption scratch buffer to store current QOS value */ 34: #define QOS_VALUE_IDX KGSL_PRIORITY_MAX_RB_LEVELS 35: 36: /* Size of the user context record block (in bytes) */ 37: #define ADRENO_CP_CTXRECORD_USER_RESTORE_SIZE (192 * SZ_1K) 38: 39: /* ADRENO_DEVICE - Given a kgsl_device return the adreno device struct */ 40: #define ADRENO_DEVICE(device) \ 41: container_of(device, struct adreno_device, dev) 42: 43: /* KGSL_DEVICE - given an adreno_device, return the KGSL device struct */ MATCH LINES: 161 149: #define ADRENO_IFPC BIT(6) 150: /* The core supports IO-coherent memory */ 151: #define ADRENO_IOCOHERENT BIT(7) 152: /* 153: * The GMU supports Adaptive Clock Distribution (ACD) 154: * for droop mitigation 155: */ 156: #define ADRENO_ACD BIT(8) 157: /* Cooperative reset enabled GMU */ 158: #define ADRENO_COOP_RESET BIT(9) 159: /* Indicates that the specific target is no longer supported */ 160: #define ADRENO_DEPRECATED BIT(10) 161: /* The target supports ringbuffer level APRIV */ 162: #define ADRENO_APRIV BIT(11) 163: /* The GMU supports Battery Current Limiting */ 164: #define ADRENO_BCL BIT(12) 165: /* L3 voting is supported with L3 constraints */ 166: #define ADRENO_L3_VOTE BIT(13) 167: /* LPAC is supported */ 168: #define ADRENO_LPAC BIT(14) 169: /* Late Stage Reprojection (LSR) enablment for GMU */ 170: #define ADRENO_LSR BIT(15) 171: /* GMU and kernel supports hardware fences */ 172: #define ADRENO_HW_FENCE BIT(16) 173: /* Dynamic Mode Switching supported on this target */ 174: #define ADRENO_DMS BIT(17) 175: /* AQE supported on this target */ 176: #define ADRENO_AQE BIT(18) 177: /* Warm Boot supported on this target */ 178: #define ADRENO_GMU_WARMBOOT BIT(19) 179: /* The GPU supports CLX */ 180: #define ADRENO_CLX BIT(20) 181: /* Enable GMU support for GMU based thermal mitigation */ 182: #define ADRENO_GMU_THERMAL_MITIGATION BIT(21) 183: /* GMU Based DCVS */ 184: #define ADRENO_GMU_BASED_DCVS BIT(22) 185: /* RT hint feature for RB0 workloads */ MATCH LINES: 667, 668, 669, 670, 671 655: }; 656: 657: #define ADRENO_MAX_FAULTING_PROCS 10 658: 659: /** 660: * struct adreno_device - The mothership structure for all adreno related info 661: * @dev: Reference to struct kgsl_device 662: * @priv: Holds the private flags specific to the adreno_device 663: * @chipid: Chip ID specific to the GPU 664: * @gpucore: Pointer to the adreno_gpu_core structure 665: * @gpmu_cmds_size: Length of gpmu cmd stream 666: * @gpmu_cmds: gpmu cmd stream 667: * @ringbuffers: Array of pointers to adreno_ringbuffers 668: * @num_ringbuffers: Number of ringbuffers for the GPU 669: * @cur_rb: Pointer to the current ringbuffer 670: * @next_rb: Ringbuffer we are switching to during preemption 671: * @prev_rb: Ringbuffer we are switching from during preemption 672: * @ft_policy: Defines the fault tolerance policy 673: * @long_ib_detect: Long IB detection availability 674: * @cooperative_reset: Indicates if graceful death handshake is enabled 675: * between GMU and GPU 676: * @profile: Container for adreno profiler information 677: * @dispatcher: Container for adreno GPU dispatcher 678: * @pwron_fixup: Command buffer to run a post-power collapse shader workaround 679: * @pwron_fixup_dwords: Number of dwords in the command buffer 680: * @input_work: Work struct for turning on the GPU after a touch event 681: * @busy_data: Struct holding GPU VBIF busy stats 682: * @ram_cycles_lo: Number of DDR clock cycles for the monitor session (Only 683: * DDR channel 0 read cycles in case of GBIF) 684: * @ram_cycles_lo_ch1_read: Number of DDR channel 1 Read clock cycles for 685: * the monitor session 686: * @ram_cycles_lo_ch0_write: Number of DDR channel 0 Write clock cycles for 687: * the monitor session 688: * @ram_cycles_lo_ch1_write: Number of DDR channel 0 Write clock cycles for 689: * the monitor session 690: * @starved_ram_lo: Number of cycles VBIF/GBIF is stalled by DDR (Only channel 0 691: * stall cycles in case of GBIF) 692: * @starved_ram_lo_ch1: Number of cycles GBIF is stalled by DDR channel 1 693: * @halt: Atomic variable to check whether the GPU is currently halted 694: * @pending_irq_refcnt: Atomic variable to keep track of running IRQ handlers 695: * @ctx_d_debugfs: Context debugfs node MATCH LINES: 730, 731, 732, 733, 734 718: * @zap_loaded: Used to track if zap was successfully loaded or not 719: */ 720: struct adreno_device { 721: struct kgsl_device dev; /* Must be first field in this struct */ 722: unsigned long priv; 723: unsigned int chipid; 724: /** @uche_gmem_base: Base address of GMEM for UCHE access */ 725: u64 uche_gmem_base; 726: const struct adreno_gpu_core *gpucore; 727: struct adreno_firmware fw[2]; 728: size_t gpmu_cmds_size; 729: unsigned int *gpmu_cmds; 730: struct adreno_ringbuffer ringbuffers[KGSL_PRIORITY_MAX_RB_LEVELS]; 731: int num_ringbuffers; 732: struct adreno_ringbuffer *cur_rb; 733: struct adreno_ringbuffer *next_rb; 734: struct adreno_ringbuffer *prev_rb; 735: unsigned long ft_policy; 736: bool long_ib_detect; 737: bool cooperative_reset; 738: struct adreno_profile profile; 739: struct adreno_dispatcher dispatcher; 740: struct kgsl_memdesc *pwron_fixup; 741: unsigned int pwron_fixup_dwords; 742: struct work_struct input_work; 743: struct adreno_busy_data busy_data; 744: unsigned int ram_cycles_lo; 745: unsigned int ram_cycles_lo_ch1_read; 746: unsigned int ram_cycles_lo_ch0_write; 747: unsigned int ram_cycles_lo_ch1_write; 748: unsigned int starved_ram_lo; 749: unsigned int starved_ram_lo_ch1; 750: atomic_t halt; 751: atomic_t pending_irq_refcnt; 752: struct dentry *ctx_d_debugfs; 753: /** @lm_enabled: True if limits management is enabled for this target */ 754: bool lm_enabled; 755: /** @acd_enabled: True if acd is enabled for this target */ 756: bool acd_enabled; 757: /** @hwcg_enabled: True if hardware clock gating is enabled */ 758: bool hwcg_enabled; MATCH LINES: 957 945: }; 946: 947: /* Time to wait for suspend recovery gate to complete */ 948: #define ADRENO_SUSPEND_RECOVERY_GATE_TIMEOUT_MS 5000 949: 950: /** 951: * enum adreno_device_flags - Private flags for the adreno_device 952: * @ADRENO_DEVICE_PWRON - Set during init after a power collapse 953: * @ADRENO_DEVICE_PWRON_FIXUP - Set if the target requires the shader fixup 954: * after power collapse 955: * @ADRENO_DEVICE_STARTED - Set if the device start sequence is in progress 956: * @ADRENO_DEVICE_FAULT - Set if the device is currently in fault (and shouldn't 957: * send any more commands to the ringbuffer) 958: * @ADRENO_DEVICE_DRAWOBJ_PROFILE - Set if the device supports drawobj 959: * profiling via the ALWAYSON counter 960: * @ADRENO_DEVICE_PREEMPTION - Turn on/off preemption 961: * @ADRENO_DEVICE_SOFT_FAULT_DETECT - Set if soft fault detect is enabled 962: * @ADRENO_DEVICE_GPMU_INITIALIZED - Set if GPMU firmware initialization succeed 963: * @ADRENO_DEVICE_ISDB_ENABLED - Set if the Integrated Shader DeBugger is 964: * attached and enabled 965: * @ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED - Set if a CACHE_FLUSH_TS irq storm 966: * is in progress 967: */ 968: enum adreno_device_flags { 969: ADRENO_DEVICE_PWRON = 0, 970: ADRENO_DEVICE_PWRON_FIXUP = 1, 971: ADRENO_DEVICE_INITIALIZED = 2, 972: ADRENO_DEVICE_STARTED = 5, 973: ADRENO_DEVICE_FAULT = 6, 974: ADRENO_DEVICE_DRAWOBJ_PROFILE = 7, 975: ADRENO_DEVICE_GPU_REGULATOR_ENABLED = 8, 976: ADRENO_DEVICE_PREEMPTION = 9, 977: ADRENO_DEVICE_SOFT_FAULT_DETECT = 10, 978: ADRENO_DEVICE_GPMU_INITIALIZED = 11, 979: ADRENO_DEVICE_ISDB_ENABLED = 12, 980: ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED = 13, 981: /** @ADRENO_DEVICE_DMS: Set if DMS is enabled */ MATCH LINES: 1123 1111: /** @soft_reset: Soft reset GPU on fault recovery */ 1112: int (*soft_reset)(struct adreno_device *adreno_dev, 1113: struct kgsl_context *context, bool ctx_guilty); 1114: /** @read_alwayson: Return the current value of the alwayson counter */ 1115: u64 (*read_alwayson)(struct adreno_device *adreno_dev); 1116: /** 1117: * @power_ops: Target specific function pointers to power up/down the 1118: * gpu 1119: */ 1120: const struct adreno_power_ops *power_ops; 1121: int (*clear_pending_transactions)(struct adreno_device *adreno_dev); 1122: void (*deassert_gbif_halt)(struct adreno_device *adreno_dev); 1123: int (*ringbuffer_submitcmd)(struct adreno_device *adreno_dev, 1124: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 1125: struct adreno_submit_time *time); 1126: /** 1127: * @is_hw_collapsible: Return true if the hardware can be collapsed. 1128: * Only used by non GMU/RGMU targets 1129: */ 1130: bool (*is_hw_collapsible)(struct adreno_device *adreno_dev); 1131: /** 1132: * @power_stats - Return the perfcounter statistics for DCVS 1133: */ 1134: void (*power_stats)(struct adreno_device *adreno_dev, 1135: struct kgsl_power_stats *stats); 1136: int (*add_to_va_minidump)(struct adreno_device *adreno_dev); 1137: /** 1138: * @gx_is_on - Return true if both gfx clock and gxgdsc are enabled. 1139: */ 1140: bool (*gx_is_on)(struct adreno_device *adreno_dev); 1141: /** 1142: * @send_recurring_cmdobj - Target specific function to send recurring IBs to GMU 1143: */ 1144: int (*send_recurring_cmdobj)(struct adreno_device *adreno_dev, 1145: struct kgsl_drawobj_cmd *cmdobj); 1146: /** 1147: * @perfcounter_remove: Remove perfcounter from the power up list MATCH LINES: 1229, 1230, 1231 1217: KGSL_FT_TEMP_DISABLE, 1218: KGSL_FT_THROTTLE, 1219: KGSL_FT_SKIPCMD, 1220: /* KGSL_FT_MAX_BITS is used to calculate the mask */ 1221: KGSL_FT_MAX_BITS, 1222: /* Internal bits - set during GFT */ 1223: /* Skip the PM dump on replayed command obj's */ 1224: KGSL_FT_SKIP_PMDUMP = 31, 1225: }; 1226: 1227: #define KGSL_FT_POLICY_MASK GENMASK(KGSL_FT_MAX_BITS - 1, 0) 1228: 1229: #define FOR_EACH_RINGBUFFER(_dev, _rb, _i) \ 1230: for ((_i) = 0, (_rb) = &((_dev)->ringbuffers[0]); \ 1231: (_i) < (_dev)->num_ringbuffers; \ 1232: (_i)++, (_rb)++) 1233: 1234: extern const struct adreno_power_ops adreno_power_operations; 1235: 1236: extern const struct adreno_gpudev adreno_a5xx_gpudev; 1237: extern const struct adreno_gpudev adreno_a6xx_gpudev; 1238: extern const struct adreno_gpudev adreno_a6xx_rgmu_gpudev; 1239: extern const struct adreno_gpudev adreno_a619_holi_gpudev; 1240: extern const struct adreno_gpudev adreno_a611_gpudev; 1241: 1242: extern int adreno_wake_nice; 1243: extern unsigned int adreno_wake_timeout; 1244: 1245: int adreno_start(struct kgsl_device *device, int priority); 1246: long adreno_ioctl(struct kgsl_device_private *dev_priv, 1247: unsigned int cmd, unsigned long arg); 1248: 1249: long adreno_ioctl_helper(struct kgsl_device_private *dev_priv, 1250: unsigned int cmd, unsigned long arg, 1251: const struct kgsl_ioctl *cmds, int len); 1252: 1253: int adreno_spin_idle(struct adreno_device *device, unsigned int timeout); 1254: int adreno_wait_idle(struct kgsl_device *device); 1255: MATCH LINES: 1918, 1922, 1950, 1951 1906: */ 1907: static inline int adreno_compare_prio_level(int p1, int p2) 1908: { 1909: return p2 - p1; 1910: } 1911: 1912: void adreno_readreg64(struct adreno_device *adreno_dev, 1913: enum adreno_regs lo, enum adreno_regs hi, uint64_t *val); 1914: 1915: void adreno_writereg64(struct adreno_device *adreno_dev, 1916: enum adreno_regs lo, enum adreno_regs hi, uint64_t val); 1917: 1918: unsigned int adreno_get_rptr(struct adreno_ringbuffer *rb); 1919: 1920: void adreno_touch_wake(struct kgsl_device *device); 1921: 1922: static inline bool adreno_rb_empty(struct adreno_ringbuffer *rb) 1923: { 1924: return (adreno_get_rptr(rb) == rb->wptr); 1925: } 1926: 1927: static inline bool adreno_long_ib_detect(struct adreno_device *adreno_dev) 1928: { 1929: return adreno_dev->long_ib_detect && 1930: !test_bit(ADRENO_DEVICE_ISDB_ENABLED, &adreno_dev->priv); 1931: } 1932: 1933: /** 1934: * adreno_support_64bit - Return true if the GPU supports 64 bit addressing 1935: * @adreno_dev: An Adreno GPU device handle 1936: * 1937: * Return: True if the device supports 64 bit addressing 1938: */ 1939: static inline bool adreno_support_64bit(struct adreno_device *adreno_dev) 1940: { 1941: /* 1942: * The IOMMU API takes a unsigned long for the iova so we can't support 1943: * 64 bit addresses when the kernel is in 32 bit mode even if we wanted 1944: * so we need to check that we are using a5xx or newer and that the 1945: * unsigned long is big enough for our purposes. 1946: */ 1947: return (BITS_PER_LONG > 32 && ADRENO_GPUREV(adreno_dev) >= 500); 1948: } 1949: 1950: static inline void adreno_ringbuffer_set_pagetable(struct kgsl_device *device, 1951: struct adreno_ringbuffer *rb, struct kgsl_pagetable *pt) 1952: { 1953: unsigned long flags; 1954: 1955: spin_lock_irqsave(&rb->preempt_lock, flags); 1956: 1957: kgsl_sharedmem_writel(device->scratch, 1958: SCRATCH_RB_OFFSET(rb->id, current_rb_ptname), pt->name); 1959: 1960: kgsl_sharedmem_writeq(device->scratch, 1961: SCRATCH_RB_OFFSET(rb->id, ttbr0), 1962: kgsl_mmu_pagetable_get_ttbr0(pt)); 1963: 1964: kgsl_sharedmem_writel(device->scratch, 1965: SCRATCH_RB_OFFSET(rb->id, contextidr), 0); 1966: 1967: spin_unlock_irqrestore(&rb->preempt_lock, flags); 1968: } 1969: 1970: static inline u32 counter_delta(struct kgsl_device *device, 1971: unsigned int reg, unsigned int *counter) 1972: { 1973: u32 val, ret = 0; 1974: 1975: if (!reg) MATCH LINES: 2202 2190: * resumes the device. 2191: * 2192: * Return: 0 on success or negative on failure 2193: */ 2194: int adreno_power_cycle_u32(struct adreno_device *adreno_dev, 2195: u32 *flag, u32 val); 2196: 2197: /** 2198: * adreno_set_active_ctxs_null - Give up active context refcount 2199: * @adreno_dev: Adreno GPU device handle 2200: * 2201: * This puts back the reference for that last active context on 2202: * each ringbuffer when going in and out of slumber. 2203: */ 2204: void adreno_set_active_ctxs_null(struct adreno_device *adreno_dev); 2205: 2206: /** 2207: * adreno_get_bus_counters - Allocate the bus dcvs counters 2208: * @adreno_dev: Adreno GPU device handle 2209: * 2210: * This function allocates the various gpu counters to measure 2211: * gpu bus usage for bus dcvs 2212: */ 2213: void adreno_get_bus_counters(struct adreno_device *adreno_dev); 2214: 2215: /** 2216: * adreno_gmu_bus_ab_quantize - Calculate the AB vote that needs to be sent to GMU 2217: * @adreno_dev: Handle to the adreno device 2218: * @ab: ab request that needs to be scaled in MBps 2219: * 2220: * Returns the AB value that needs to be prefixed to bandwidth vote in kbps 2221: */ 2222: u32 adreno_gmu_bus_ab_quantize(struct adreno_device *adreno_dev, u32 ab); 2223: 2224: /** 2225: * adreno_check_idle - Make sure device is idle 2226: * @device: Pointer to the kgsl device --- FILE: \adreno_a5xx.c | HITS: 38 --- MATCH LINES: 187 175: 176: critical_packet_constructed = 1; 177: 178: return 0; 179: } 180: 181: static int a5xx_microcode_read(struct adreno_device *adreno_dev); 182: 183: static int a5xx_init(struct adreno_device *adreno_dev) 184: { 185: int ret; 186: 187: ret = a5xx_ringbuffer_init(adreno_dev); 188: if (ret) 189: return ret; 190: 191: ret = a5xx_microcode_read(adreno_dev); 192: if (ret) 193: return ret; 194: 195: if (a5xx_has_gpmu(adreno_dev)) 196: INIT_WORK(&adreno_dev->gpmu_work, a5xx_gpmu_reset); 197: 198: INIT_WORK(&adreno_dev->irq_storm_work, a5xx_irq_storm_worker); 199: 200: if (ADRENO_QUIRK(adreno_dev, ADRENO_QUIRK_CRITICAL_PACKETS)) 201: a5xx_critical_packet_construct(adreno_dev); 202: 203: adreno_create_profile_buffer(adreno_dev); 204: a5xx_crashdump_init(adreno_dev); 205: 206: return 0; 207: } 208: 209: static const struct { 210: u32 reg; 211: u32 base; MATCH LINES: 643, 651, 660 631: 632: dev_err(device->dev, 633: "rb=%d pos=%X/%X rbbm_status=%8.8X/%8.8X int_0_status=%8.8X\n", 634: adreno_dev->cur_rb->id, rptr, wptr, status, status3, intstatus); 635: 636: dev_err(device->dev, " hwfault=%8.8X\n", hwfault); 637: 638: kgsl_device_snapshot(device, NULL, NULL, false); 639: } 640: 641: static int _gpmu_send_init_cmds(struct adreno_device *adreno_dev) 642: { 643: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 644: uint32_t *cmds; 645: uint32_t size = adreno_dev->gpmu_cmds_size; 646: int ret; 647: 648: if (size == 0 || adreno_dev->gpmu_cmds == NULL) 649: return -EINVAL; 650: 651: cmds = adreno_ringbuffer_allocspace(rb, size); 652: if (IS_ERR(cmds)) 653: return PTR_ERR(cmds); 654: if (cmds == NULL) 655: return -ENOSPC; 656: 657: /* Copy to the RB the predefined fw sequence cmds */ 658: memcpy(cmds, adreno_dev->gpmu_cmds, size << 2); 659: 660: ret = a5xx_ringbuffer_submit(rb, NULL, true); 661: if (!ret) { 662: ret = adreno_spin_idle(adreno_dev, 2000); 663: if (ret) 664: a5xx_spin_idle_debug(adreno_dev, 665: "gpmu initialization failed to idle\n"); 666: } 667: return ret; 668: } 669: 670: /* 671: * a5xx_gpmu_start() - Initialize and start the GPMU 672: * @adreno_dev: Pointer to adreno device 673: * 674: * Load the GPMU microcode, set up any features such as hardware clock gating 675: * or IFPC, and take the GPMU out of reset. 676: */ 677: static int a5xx_gpmu_start(struct adreno_device *adreno_dev) 678: { 679: int ret; 680: unsigned int reg, retry = GPMU_FW_INIT_RETRY; 681: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 682: 683: if (!a5xx_has_gpmu(adreno_dev)) 684: return 0; MATCH LINES: 1514, 1518, 1530, 1532, 1548, 1561, 1567, 1582, 1589, 1592 1502: FIELD_PREP(GENMASK(31, 12), 1503: (KGSL_IOMMU_SECURE_SIZE(&device->mmu) / SZ_4K))); 1504: } 1505: 1506: a5xx_preemption_start(adreno_dev); 1507: a5xx_protect_init(adreno_dev); 1508: 1509: return 0; 1510: } 1511: 1512: /* 1513: * Follow the ME_INIT sequence with a preemption yield to allow the GPU to move 1514: * to a different ringbuffer, if desired 1515: */ 1516: static int _preemption_init( 1517: struct adreno_device *adreno_dev, 1518: struct adreno_ringbuffer *rb, unsigned int *cmds, 1519: struct kgsl_context *context) 1520: { 1521: unsigned int *cmds_orig = cmds; 1522: uint64_t gpuaddr = rb->preemption_desc->gpuaddr; 1523: 1524: /* Turn CP protection OFF */ 1525: cmds += cp_protected_mode(adreno_dev, cmds, 0); 1526: /* 1527: * CP during context switch will save context switch info to 1528: * a5xx_cp_preemption_record pointed by CONTEXT_SWITCH_SAVE_ADDR 1529: */ 1530: *cmds++ = cp_type4_packet(A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_LO, 1); 1531: *cmds++ = lower_32_bits(gpuaddr); 1532: *cmds++ = cp_type4_packet(A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_HI, 1); 1533: *cmds++ = upper_32_bits(gpuaddr); 1534: 1535: /* Turn CP protection ON */ 1536: cmds += cp_protected_mode(adreno_dev, cmds, 1); 1537: 1538: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_GLOBAL, 1); 1539: *cmds++ = 0; 1540: 1541: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_LOCAL, 1); 1542: *cmds++ = 1; 1543: 1544: /* Enable yield in RB only */ 1545: *cmds++ = cp_type7_packet(CP_YIELD_ENABLE, 1); 1546: *cmds++ = 1; 1547: 1548: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1549: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 1550: *cmds++ = 0; 1551: /* generate interrupt on preemption completion */ 1552: *cmds++ = 1; 1553: 1554: return cmds - cmds_orig; 1555: } 1556: 1557: static int a5xx_post_start(struct adreno_device *adreno_dev) 1558: { 1559: int ret; 1560: unsigned int *cmds, *start; 1561: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1562: 1563: if (!adreno_is_a530(adreno_dev) && 1564: !adreno_is_preemption_enabled(adreno_dev)) 1565: return 0; 1566: 1567: cmds = adreno_ringbuffer_allocspace(rb, 42); 1568: if (IS_ERR(cmds)) { 1569: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1570: 1571: dev_err(device->dev, 1572: "error allocating preemtion init cmds\n"); 1573: return PTR_ERR(cmds); 1574: } 1575: start = cmds; 1576: 1577: /* 1578: * Send a pipeline stat event whenever the GPU gets powered up 1579: * to cause misbehaving perf counters to start ticking 1580: */ 1581: if (adreno_is_a530(adreno_dev)) { 1582: *cmds++ = cp_packet(adreno_dev, CP_EVENT_WRITE, 1); 1583: *cmds++ = 0xF; 1584: } 1585: 1586: if (adreno_is_preemption_enabled(adreno_dev)) { 1587: cmds += _preemption_init(adreno_dev, rb, cmds, NULL); 1588: rb->_wptr = rb->_wptr - (42 - (cmds - start)); 1589: ret = a5xx_ringbuffer_submit(rb, NULL, false); 1590: } else { 1591: rb->_wptr = rb->_wptr - (42 - (cmds - start)); 1592: ret = a5xx_ringbuffer_submit(rb, NULL, true); 1593: } 1594: 1595: if (!ret) { 1596: ret = adreno_spin_idle(adreno_dev, 2000); 1597: if (ret) 1598: a5xx_spin_idle_debug(adreno_dev, 1599: "hw initialization failed to idle\n"); 1600: } 1601: 1602: return ret; 1603: } 1604: 1605: static int a5xx_gpmu_init(struct adreno_device *adreno_dev) 1606: { 1607: int ret; 1608: 1609: /* Set up LM before initializing the GPMU */ 1610: a5xx_lm_init(adreno_dev); 1611: 1612: /* Enable SPTP based power collapse before enabling GPMU */ 1613: a5xx_enable_pc(adreno_dev); 1614: 1615: ret = a5xx_gpmu_start(adreno_dev); 1616: if (ret) MATCH LINES: 1720, 1728, 1732, 1736, 1748, 1750, 1755, 1760, 1764, 1792, 1804, 1810, 1815, 1816, 1826, 1827, 1834 1708: #define CP_INIT_DRAWCALL_FILTER_RANGE BIT(4) 1709: 1710: /* Ucode workaround masks */ 1711: #define CP_INIT_UCODE_WORKAROUND_MASK BIT(5) 1712: 1713: #define CP_INIT_MASK (CP_INIT_MAX_CONTEXT | \ 1714: CP_INIT_ERROR_DETECTION_CONTROL | \ 1715: CP_INIT_HEADER_DUMP | \ 1716: CP_INIT_DEFAULT_RESET_STATE | \ 1717: CP_INIT_UCODE_WORKAROUND_MASK) 1718: 1719: static int a5xx_critical_packet_submit(struct adreno_device *adreno_dev, 1720: struct adreno_ringbuffer *rb) 1721: { 1722: unsigned int *cmds; 1723: int ret; 1724: 1725: if (!critical_packet_constructed) 1726: return 0; 1727: 1728: cmds = adreno_ringbuffer_allocspace(rb, 4); 1729: if (IS_ERR(cmds)) 1730: return PTR_ERR(cmds); 1731: 1732: *cmds++ = cp_mem_packet(adreno_dev, CP_INDIRECT_BUFFER_PFE, 2, 1); 1733: cmds += cp_gpuaddr(adreno_dev, cmds, adreno_dev->critpkts->gpuaddr); 1734: *cmds++ = crit_pkts_dwords; 1735: 1736: ret = a5xx_ringbuffer_submit(rb, NULL, true); 1737: if (!ret) { 1738: ret = adreno_spin_idle(adreno_dev, 20); 1739: if (ret) 1740: a5xx_spin_idle_debug(adreno_dev, 1741: "Critical packet submission failed to idle\n"); 1742: } 1743: 1744: return ret; 1745: } 1746: 1747: /* 1748: * a5xx_send_me_init() - Initialize ringbuffer 1749: * @adreno_dev: Pointer to adreno device 1750: * @rb: Pointer to the ringbuffer of device 1751: * 1752: * Submit commands for ME initialization, 1753: */ 1754: static int a5xx_send_me_init(struct adreno_device *adreno_dev, 1755: struct adreno_ringbuffer *rb) 1756: { 1757: unsigned int *cmds; 1758: int i = 0, ret; 1759: 1760: cmds = adreno_ringbuffer_allocspace(rb, 9); 1761: if (IS_ERR(cmds)) 1762: return PTR_ERR(cmds); 1763: 1764: cmds[i++] = cp_type7_packet(CP_ME_INIT, 8); 1765: 1766: /* Enabled ordinal mask */ 1767: cmds[i++] = CP_INIT_MASK; 1768: 1769: if (CP_INIT_MASK & CP_INIT_MAX_CONTEXT) 1770: cmds[i++] = 0x00000003; 1771: 1772: if (CP_INIT_MASK & CP_INIT_ERROR_DETECTION_CONTROL) 1773: cmds[i++] = 0x20000000; 1774: 1775: if (CP_INIT_MASK & CP_INIT_HEADER_DUMP) { 1776: /* Header dump address */ 1777: cmds[i++] = 0x00000000; 1778: /* Header dump enable and dump size */ 1779: cmds[i++] = 0x00000000; 1780: } 1781: 1782: if (CP_INIT_MASK & CP_INIT_DRAWCALL_FILTER_RANGE) { 1783: /* Start range */ 1784: cmds[i++] = 0x00000000; 1785: /* End range (inclusive) */ 1786: cmds[i++] = 0x00000000; 1787: } 1788: 1789: if (CP_INIT_MASK & CP_INIT_UCODE_WORKAROUND_MASK) 1790: cmds[i++] = _me_init_ucode_workarounds(adreno_dev); 1791: 1792: ret = a5xx_ringbuffer_submit(rb, NULL, true); 1793: if (!ret) { 1794: ret = adreno_spin_idle(adreno_dev, 2000); 1795: if (ret) 1796: a5xx_spin_idle_debug(adreno_dev, 1797: "CP initialization failed to idle\n"); 1798: } 1799: 1800: return ret; 1801: } 1802: 1803: /* 1804: * a5xx_rb_start() - Start the ringbuffer 1805: * @adreno_dev: Pointer to adreno device 1806: */ 1807: static int a5xx_rb_start(struct adreno_device *adreno_dev) 1808: { 1809: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1810: struct adreno_ringbuffer *rb; 1811: uint64_t addr; 1812: unsigned int *cmds; 1813: int ret, i; 1814: 1815: /* Clear all the ringbuffers */ 1816: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1817: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 1818: kgsl_sharedmem_writel(device->scratch, 1819: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1820: 1821: rb->wptr = 0; 1822: rb->_wptr = 0; 1823: rb->wptr_preempt_end = ~0; 1824: } 1825: 1826: /* Set up the current ringbuffer */ 1827: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 1828: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 1829: 1830: kgsl_regwrite(device, A5XX_CP_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1831: kgsl_regwrite(device, A5XX_CP_RB_RPTR_ADDR_HI, upper_32_bits(addr)); 1832: 1833: /* 1834: * The size of the ringbuffer in the hardware is the log2 1835: * representation of the size in quadwords (sizedwords / 2). 1836: * Also disable the host RPTR shadow register as it might be unreliable 1837: * in certain circumstances. 1838: */ 1839: 1840: kgsl_regwrite(device, A5XX_CP_RB_CNTL, 1841: A5XX_CP_RB_CNTL_DEFAULT); 1842: 1843: kgsl_regwrite(device, A5XX_CP_RB_BASE, 1844: lower_32_bits(rb->buffer_desc->gpuaddr)); 1845: kgsl_regwrite(device, A5XX_CP_RB_BASE_HI, 1846: upper_32_bits(rb->buffer_desc->gpuaddr)); 1847: 1848: ret = a5xx_microcode_load(adreno_dev); 1849: if (ret) 1850: return ret; 1851: 1852: /* clear ME_HALT to start micro engine */ 1853: 1854: kgsl_regwrite(device, A5XX_CP_ME_CNTL, 0); 1855: 1856: ret = a5xx_send_me_init(adreno_dev, rb); 1857: if (ret) 1858: return ret; MATCH LINES: 1874, 1881 1862: ret = a5xx_critical_packet_submit(adreno_dev, rb); 1863: if (ret) 1864: return ret; 1865: } 1866: 1867: /* 1868: * Try to execute the zap shader if it exists, otherwise just try 1869: * directly writing to the control register 1870: */ 1871: if (!adreno_dev->zap_loaded) 1872: kgsl_regwrite(device, A5XX_RBBM_SECVID_TRUST_CNTL, 0); 1873: else { 1874: cmds = adreno_ringbuffer_allocspace(rb, 2); 1875: if (IS_ERR(cmds)) 1876: return PTR_ERR(cmds); 1877: 1878: *cmds++ = cp_packet(adreno_dev, CP_SET_SECURE_MODE, 1); 1879: *cmds++ = 0; 1880: 1881: ret = a5xx_ringbuffer_submit(rb, NULL, true); 1882: if (!ret) { 1883: ret = adreno_spin_idle(adreno_dev, 2000); 1884: if (ret) { 1885: a5xx_spin_idle_debug(adreno_dev, 1886: "Switch to unsecure failed to idle\n"); 1887: return ret; 1888: } 1889: } 1890: } 1891: 1892: ret = a5xx_gpmu_init(adreno_dev); 1893: if (ret) 1894: return ret; 1895: 1896: a5xx_post_start(adreno_dev); 1897: 1898: return 0; 1899: } 1900: 1901: /* 1902: * a5xx_microcode_read() - Read microcode 1903: * @adreno_dev: Pointer to adreno device 1904: */ 1905: static int a5xx_microcode_read(struct adreno_device *adreno_dev) MATCH LINES: 1969, 1974, 1978, 1993 1957: unsigned int val; 1958: 1959: kgsl_regwrite(device, A5XX_CP_PFP_STAT_ADDR, 0); 1960: 1961: /* 1962: * A5XX_CP_PFP_STAT_DATA is indexed, so read it twice to get the 1963: * value we want 1964: */ 1965: kgsl_regread(device, A5XX_CP_PFP_STAT_DATA, &val); 1966: kgsl_regread(device, A5XX_CP_PFP_STAT_DATA, &val); 1967: 1968: dev_crit_ratelimited(device->dev, 1969: "ringbuffer opcode error | possible opcode=0x%8.8X\n", 1970: val); 1971: } 1972: if (status1 & BIT(A5XX_CP_RESERVED_BIT_ERROR)) 1973: dev_crit_ratelimited(device->dev, 1974: "ringbuffer reserved bit error interrupt\n"); 1975: if (status1 & BIT(A5XX_CP_HW_FAULT_ERROR)) { 1976: kgsl_regread(device, A5XX_CP_HW_FAULT, &status2); 1977: dev_crit_ratelimited(device->dev, 1978: "CP | Ringbuffer HW fault | status=%x\n", 1979: status2); 1980: } 1981: if (status1 & BIT(A5XX_CP_DMA_ERROR)) 1982: dev_crit_ratelimited(device->dev, "CP | DMA error\n"); 1983: if (status1 & BIT(A5XX_CP_REGISTER_PROTECTION_ERROR)) { 1984: kgsl_regread(device, A5XX_CP_PROTECT_STATUS, &status2); 1985: dev_crit_ratelimited(device->dev, 1986: "CP | Protected mode error| %s | addr=%x | status=%x\n", 1987: status2 & (1 << 24) ? "WRITE" : "READ", 1988: (status2 & 0xFFFFF) >> 2, status2); 1989: } 1990: if (status1 & BIT(A5XX_CP_AHB_ERROR)) { 1991: kgsl_regread(device, A5XX_CP_AHB_FAULT, &status2); 1992: dev_crit_ratelimited(device->dev, 1993: "ringbuffer AHB error interrupt | status=%x\n", 1994: status2); 1995: } 1996: } 1997: 1998: static void a5xx_err_callback(struct adreno_device *adreno_dev, int bit) 1999: { 2000: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2001: unsigned int reg; 2002: 2003: switch (bit) { 2004: case A5XX_INT_RBBM_AHB_ERROR: { 2005: kgsl_regread(device, A5XX_RBBM_AHB_ERROR_STATUS, ®); 2006: 2007: /* 2008: * Return the word address of the erroring register so that it 2009: * matches the register specification 2010: */ 2011: dev_crit_ratelimited(device->dev, 2012: "RBBM | AHB bus error | %s | addr=%x | ports=%x:%x\n", 2013: reg & (1 << 28) ? "WRITE" : "READ", 2014: (reg & 0xFFFFF) >> 2, 2015: (reg >> 20) & 0x3, 2016: (reg >> 24) & 0xF); 2017: MATCH LINES: 2445 2433: .init = a5xx_init, 2434: .irq_handler = a5xx_irq_handler, 2435: .rb_start = a5xx_rb_start, 2436: .regulator_enable = a5xx_regulator_enable, 2437: .regulator_disable = a5xx_regulator_disable, 2438: .pwrlevel_change_settings = a5xx_pwrlevel_change_settings, 2439: .preemption_schedule = a5xx_preemption_schedule, 2440: .read_alwayson = a5xx_read_alwayson, 2441: .hw_isidle = a5xx_hw_isidle, 2442: .power_ops = &adreno_power_operations, 2443: .clear_pending_transactions = a5xx_clear_pending_transactions, 2444: .remove = a5xx_remove, 2445: .ringbuffer_submitcmd = a5xx_ringbuffer_submitcmd, 2446: .is_hw_collapsible = a5xx_is_hw_collapsible, 2447: .power_stats = a5xx_power_stats, 2448: }; --- FILE: \adreno_a5xx.h | HITS: 17 --- MATCH LINES: 57 45: #define A5XX_CP_CTXRECORD_MAGIC_REF 0x27C4BAFCUL 46: /* Size of each CP preemption record */ 47: #define A5XX_CP_CTXRECORD_SIZE_IN_BYTES 0x10000 48: /* Size of the preemption counter block (in bytes) */ 49: #define A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE (16 * 4) 50: 51: /** 52: * struct a5xx_cp_preemption_record - CP context record for 53: * preemption. 54: * @magic: (00) Value at this offset must be equal to 55: * A5XX_CP_CTXRECORD_MAGIC_REF. 56: * @info: (04) Type of record. Written non-zero (usually) by CP. 57: * we must set to zero for all ringbuffers. 58: * @data: (08) DATA field in SET_RENDER_MODE or checkpoint packets. 59: * Written by CP when switching out. Not used on switch-in. 60: * we must initialize to zero. 61: * @cntl: (12) RB_CNTL, saved and restored by CP. 62: * @rptr: (16) RB_RPTR, saved and restored by CP. 63: * @wptr: (20) RB_WPTR, saved and restored by CP. 64: * @rptr_addr: (24) RB_RPTR_ADDR_LO|HI saved and restored. 65: * rbase: (32) RB_BASE_LO|HI saved and restored. 66: * counter: (40) Pointer to preemption counter 67: */ 68: struct a5xx_cp_preemption_record { 69: uint32_t magic; 70: uint32_t info; 71: uint32_t data; 72: uint32_t cntl; 73: uint32_t rptr; 74: uint32_t wptr; 75: uint64_t rptr_addr; 76: uint64_t rbase; 77: uint64_t counter; 78: }; 79: 80: #define A5XX_CP_SMMU_INFO_MAGIC_REF 0x3618CDA3UL 81: MATCH LINES: 234, 243, 245, 250, 260, 263, 266, 269, 271, 275, 280, 283, 284, 289, 297, 301 222: return container_of(core, struct adreno_a5xx_core, base); 223: } 224: 225: /* Preemption functions */ 226: void a5xx_preemption_trigger(struct adreno_device *adreno_dev); 227: void a5xx_preemption_schedule(struct adreno_device *adreno_dev); 228: void a5xx_preemption_start(struct adreno_device *adreno_dev); 229: int a5xx_preemption_init(struct adreno_device *adreno_dev); 230: 231: /** 232: * a5xx_preemption_post_ibsubmit - Insert commands following a submission 233: * @adreno_dev: Adreno GPU handle 234: * @cmds: Pointer to the ringbuffer to insert opcodes 235: * 236: * Return: The number of opcodes written to @cmds 237: */ 238: u32 a5xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, u32 *cmds); 239: 240: /** 241: * a5xx_preemption_post_ibsubmit - Insert opcodes before a submission 242: * @adreno_dev: Adreno GPU handle 243: * @rb: The ringbuffer being written 244: * @drawctxt: The draw context being written 245: * @cmds: Pointer to the ringbuffer to insert opcodes 246: * 247: * Return: The number of opcodes written to @cmds 248: */ 249: u32 a5xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 250: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 251: u32 *cmds); 252: 253: void a5xx_preempt_callback(struct adreno_device *adreno_dev, int bit); 254: 255: u64 a5xx_read_alwayson(struct adreno_device *adreno_dev); 256: 257: extern const struct adreno_perfcounters adreno_a5xx_perfcounters; 258: 259: /** 260: * a5xx_ringbuffer_init - Initialize the ringbuffers 261: * @adreno_dev: An Adreno GPU handle 262: * 263: * Initialize the ringbuffer(s) for a5xx. 264: * Return: 0 on success or negative on failure 265: */ 266: int a5xx_ringbuffer_init(struct adreno_device *adreno_dev); 267: 268: /** 269: * a5xx_ringbuffer_addcmds - Submit a command to the ringbuffer 270: * @adreno_dev: An Adreno GPU handle 271: * @rb: Pointer to the ringbuffer to submit on 272: * @drawctxt: Pointer to the draw context for the submission, or NULL for 273: * internal submissions 274: * @flags: Flags for the submission 275: * @in: Commands to write to the ringbuffer 276: * @dwords: Size of @in (in dwords) 277: * @timestamp: Timestamp for the submission 278: * @time: Optional pointer to a submit time structure 279: * 280: * Submit a command to the ringbuffer. 281: * Return: 0 on success or negative on failure 282: */ 283: int a5xx_ringbuffer_addcmds(struct adreno_device *adreno_dev, 284: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 285: u32 flags, u32 *in, u32 dwords, u32 timestamp, 286: struct adreno_submit_time *time); 287: 288: /** 289: * a5xx_ringbuffer_submitcmd - Submit a user command to the ringbuffer 290: * @adreno_dev: An Adreno GPU handle 291: * @cmdobj: Pointer to a user command object 292: * @flags: Internal submit flags 293: * @time: Optional pointer to a adreno_submit_time container 294: * 295: * Return: 0 on success or negative on failure 296: */ 297: int a5xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 298: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 299: struct adreno_submit_time *time); 300: 301: int a5xx_ringbuffer_submit(struct adreno_ringbuffer *rb, 302: struct adreno_submit_time *time, bool sync); 303: 304: static inline bool a5xx_has_gpmu(struct adreno_device *adreno_dev) 305: { 306: return (adreno_is_a530(adreno_dev) || adreno_is_a540(adreno_dev)); 307: } 308: 309: #ifdef CONFIG_QCOM_KGSL_CORESIGHT 310: void a5xx_coresight_init(struct adreno_device *device); 311: #else 312: static inline void a5xx_coresight_init(struct adreno_device *device) { } 313: #endif 314: 315: #endif --- FILE: \adreno_a5xx_perfcounter.c | HITS: 3 --- MATCH LINES: 70, 83, 98 58: kgsl_regwrite(device, reg->select, countable); 59: reg->value = 0; 60: 61: return 0; 62: } 63: 64: static int a5xx_counter_inline_enable(struct adreno_device *adreno_dev, 65: const struct adreno_perfcount_group *group, 66: unsigned int counter, unsigned int countable) 67: { 68: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 69: struct adreno_perfcount_register *reg = &group->regs[counter]; 70: struct adreno_ringbuffer *rb = &adreno_dev->ringbuffers[0]; 71: u32 cmds[3]; 72: int ret; 73: 74: if (!(device->state == KGSL_STATE_ACTIVE)) 75: return a5xx_counter_enable(adreno_dev, group, counter, 76: countable); 77: 78: cmds[0] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 79: cmds[1] = cp_type4_packet(reg->select, 1); 80: cmds[2] = countable; 81: 82: /* submit to highest priority RB always */ 83: ret = a5xx_ringbuffer_addcmds(adreno_dev, rb, NULL, 84: F_NOTPROTECTED, cmds, 3, 0, NULL); 85: 86: if (ret) 87: return ret; 88: 89: /* 90: * schedule dispatcher to make sure rb[0] is run, because 91: * if the current RB is not rb[0] and gpu is idle then 92: * rb[0] will not get scheduled to run 93: */ 94: if (adreno_dev->cur_rb != rb) 95: adreno_scheduler_queue(adreno_dev); 96: 97: /* wait for the above commands submitted to complete */ 98: ret = adreno_ringbuffer_waittimestamp(rb, rb->timestamp, 99: ADRENO_IDLE_TIMEOUT); 100: 101: if (ret) { 102: /* 103: * If we were woken up because of cancelling rb events 104: * either due to soft reset or adreno_stop, ignore the 105: * error and return 0 here. The perfcounter is already 106: * set up in software and it will be programmed in 107: * hardware when we wake up or come up after soft reset, 108: * by adreno_perfcounter_restore. 109: */ 110: if (ret == -EAGAIN) 111: ret = 0; 112: else 113: dev_err(device->dev, 114: "Perfcounter %s/%u/%u start via commands failed %d\n", 115: group->name, counter, countable, ret); 116: } 117: 118: if (!ret) 119: reg->value = 0; 120: 121: return ret; 122: } --- FILE: \adreno_a5xx_preempt.c | HITS: 36 --- MATCH LINES: 22, 59 10: #include "adreno_trace.h" 11: #include "kgsl_util.h" 12: 13: #define PREEMPT_RECORD(_field) \ 14: offsetof(struct a5xx_cp_preemption_record, _field) 15: 16: #define PREEMPT_SMMU_RECORD(_field) \ 17: offsetof(struct a5xx_cp_smmu_info, _field) 18: 19: static void _update_wptr(struct adreno_device *adreno_dev, bool reset_timer) 20: { 21: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 22: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 23: unsigned int wptr; 24: unsigned long flags; 25: 26: spin_lock_irqsave(&rb->preempt_lock, flags); 27: 28: kgsl_regread(device, A5XX_CP_RB_WPTR, &wptr); 29: 30: if (wptr != rb->wptr) { 31: kgsl_regwrite(device, A5XX_CP_RB_WPTR, rb->wptr); 32: /* 33: * In case something got submitted while preemption was on 34: * going, reset the timer. 35: */ 36: reset_timer = true; 37: } 38: 39: if (reset_timer) 40: rb->dispatch_q.expires = jiffies + 41: msecs_to_jiffies(adreno_drawobj_timeout); 42: 43: spin_unlock_irqrestore(&rb->preempt_lock, flags); 44: } 45: 46: static void _a5xx_preemption_done(struct adreno_device *adreno_dev) 47: { 48: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 49: unsigned int status; 50: 51: /* 52: * In the very unlikely case that the power is off, do nothing - the 53: * state will be reset on power up and everybody will be happy 54: */ 55: 56: if (!kgsl_state_is_awake(device)) 57: return; 58: 59: kgsl_regread(device, A5XX_CP_CONTEXT_SWITCH_CNTL, &status); 60: 61: if (status != 0) { 62: dev_err(device->dev, 63: "Preemption not complete: status=%X cur=%d R/W=%X/%X next=%d R/W=%X/%X\n", 64: status, adreno_dev->cur_rb->id, 65: adreno_get_rptr(adreno_dev->cur_rb), 66: adreno_dev->cur_rb->wptr, 67: adreno_dev->next_rb->id, 68: adreno_get_rptr(adreno_dev->next_rb), 69: adreno_dev->next_rb->wptr); 70: 71: /* Set a fault and restart */ 72: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 73: 74: return; 75: } 76: 77: kgsl_delete_timer_sync(&adreno_dev->preempt.timer); 78: 79: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 0, 0); 80: 81: /* Clean up all the bits */ 82: adreno_dev->prev_rb = adreno_dev->cur_rb; 83: adreno_dev->cur_rb = adreno_dev->next_rb; MATCH LINES: 107 95: } 96: 97: static void _a5xx_preemption_fault(struct adreno_device *adreno_dev) 98: { 99: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 100: unsigned int status; 101: 102: /* 103: * If the power is on check the preemption status one more time - if it 104: * was successful then just transition to the complete state 105: */ 106: if (kgsl_state_is_awake(device)) { 107: kgsl_regread(device, A5XX_CP_CONTEXT_SWITCH_CNTL, &status); 108: 109: if (status == 0) { 110: adreno_set_preempt_state(adreno_dev, 111: ADRENO_PREEMPT_COMPLETE); 112: 113: adreno_scheduler_queue(adreno_dev); 114: return; 115: } 116: } 117: 118: dev_err(device->dev, 119: "Preemption timed out: cur=%d R/W=%X/%X, next=%d R/W=%X/%X\n", 120: adreno_dev->cur_rb->id, 121: adreno_get_rptr(adreno_dev->cur_rb), 122: adreno_dev->cur_rb->wptr, 123: adreno_dev->next_rb->id, 124: adreno_get_rptr(adreno_dev->next_rb), 125: adreno_dev->next_rb->wptr); 126: 127: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 128: } 129: 130: static void _a5xx_preemption_worker(struct work_struct *work) 131: { MATCH LINES: 147, 148, 151, 155, 173, 183, 184, 187, 188, 193 135: struct adreno_device, preempt); 136: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 137: 138: /* Need to take the mutex to make sure that the power stays on */ 139: kgsl_mutex_lock(&device->mutex); 140: 141: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_FAULTED)) 142: _a5xx_preemption_fault(adreno_dev); 143: 144: kgsl_mutex_unlock(&device->mutex); 145: } 146: 147: /* Find the highest priority active ringbuffer */ 148: static struct adreno_ringbuffer *a5xx_next_ringbuffer( 149: struct adreno_device *adreno_dev) 150: { 151: struct adreno_ringbuffer *rb; 152: unsigned long flags; 153: unsigned int i; 154: 155: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 156: bool empty; 157: 158: spin_lock_irqsave(&rb->preempt_lock, flags); 159: empty = adreno_rb_empty(rb); 160: spin_unlock_irqrestore(&rb->preempt_lock, flags); 161: 162: if (!empty) 163: return rb; 164: } 165: 166: return NULL; 167: } 168: 169: void a5xx_preemption_trigger(struct adreno_device *adreno_dev) 170: { 171: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 172: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 173: struct adreno_ringbuffer *next; 174: uint64_t ttbr0; 175: unsigned int contextidr; 176: unsigned long flags; 177: 178: /* Put ourselves into a possible trigger state */ 179: if (!adreno_move_preempt_state(adreno_dev, 180: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START)) 181: return; 182: 183: /* Get the next ringbuffer to preempt in */ 184: next = a5xx_next_ringbuffer(adreno_dev); 185: 186: /* 187: * Nothing to do if every ringbuffer is empty or if the current 188: * ringbuffer is the only active one 189: */ 190: if (next == NULL || next == adreno_dev->cur_rb) { 191: /* 192: * Update any critical things that might have been skipped while 193: * we were looking for a new ringbuffer 194: */ 195: 196: if (next != NULL) { 197: _update_wptr(adreno_dev, false); 198: 199: mod_timer(&adreno_dev->dispatcher.timer, 200: adreno_dev->cur_rb->dispatch_q.expires); 201: } 202: 203: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 204: return; 205: } 206: 207: /* Turn off the dispatcher timer */ 208: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 209: 210: /* 211: * This is the most critical section - we need to take care not to race 212: * until we have programmed the CP for the switch 213: */ 214: 215: spin_lock_irqsave(&next->preempt_lock, flags); 216: 217: /* Get the pagetable from the pagetable info. */ MATCH LINES: 236, 238, 253, 265 224: PREEMPT_RECORD(wptr), next->wptr); 225: 226: spin_unlock_irqrestore(&next->preempt_lock, flags); 227: 228: /* And write it to the smmu info */ 229: if (kgsl_mmu_is_perprocess(&device->mmu)) { 230: kgsl_sharedmem_writeq(iommu->smmu_info, 231: PREEMPT_SMMU_RECORD(ttbr0), ttbr0); 232: kgsl_sharedmem_writel(iommu->smmu_info, 233: PREEMPT_SMMU_RECORD(context_idr), contextidr); 234: } 235: 236: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_LO, 237: lower_32_bits(next->preemption_desc->gpuaddr)); 238: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_HI, 239: upper_32_bits(next->preemption_desc->gpuaddr)); 240: 241: adreno_dev->next_rb = next; 242: 243: /* Start the timer to detect a stuck preemption */ 244: mod_timer(&adreno_dev->preempt.timer, 245: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 246: 247: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 248: 1, 0); 249: 250: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 251: 252: /* Trigger the preemption */ 253: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_CNTL, 1); 254: } 255: 256: void a5xx_preempt_callback(struct adreno_device *adreno_dev, int bit) 257: { 258: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 259: unsigned int status; 260: 261: if (!adreno_move_preempt_state(adreno_dev, 262: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 263: return; 264: 265: kgsl_regread(device, A5XX_CP_CONTEXT_SWITCH_CNTL, &status); 266: 267: if (status != 0) { 268: dev_err(KGSL_DEVICE(adreno_dev)->dev, 269: "preempt interrupt with non-zero status: %X\n", 270: status); 271: 272: /* 273: * Under the assumption that this is a race between the 274: * interrupt and the register, schedule the worker to clean up. 275: * If the status still hasn't resolved itself by the time we get 276: * there then we have to assume something bad happened 277: */ 278: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE); 279: adreno_scheduler_queue(adreno_dev); 280: return; 281: } 282: 283: kgsl_delete_timer(&adreno_dev->preempt.timer); 284: 285: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 0, 0); 286: 287: adreno_dev->prev_rb = adreno_dev->cur_rb; 288: adreno_dev->cur_rb = adreno_dev->next_rb; 289: adreno_dev->next_rb = NULL; MATCH LINES: 321, 337, 340, 348, 368, 370, 388, 403, 417, 441, 444, 448, 458, 464, 465 309: 310: kgsl_mutex_lock(&device->mutex); 311: 312: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE)) 313: _a5xx_preemption_done(adreno_dev); 314: 315: a5xx_preemption_trigger(adreno_dev); 316: 317: kgsl_mutex_unlock(&device->mutex); 318: } 319: 320: u32 a5xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 321: struct adreno_ringbuffer *rb, 322: struct adreno_context *drawctxt, u32 *cmds) 323: { 324: unsigned int *cmds_orig = cmds; 325: uint64_t gpuaddr = rb->preemption_desc->gpuaddr; 326: unsigned int preempt_style = 0; 327: 328: if (!adreno_is_preemption_enabled(adreno_dev)) 329: return 0; 330: 331: if (drawctxt) { 332: /* 333: * Preemption from secure to unsecure needs Zap shader to be 334: * run to clear all secure content. CP does not know during 335: * preemption if it is switching between secure and unsecure 336: * contexts so restrict Secure contexts to be preempted at 337: * ringbuffer level. 338: */ 339: if (drawctxt->base.flags & KGSL_CONTEXT_SECURE) 340: preempt_style = KGSL_CONTEXT_PREEMPT_STYLE_RINGBUFFER; 341: else 342: preempt_style = FIELD_GET(KGSL_CONTEXT_PREEMPT_STYLE_MASK, 343: drawctxt->base.flags); 344: } 345: 346: /* 347: * CP_PREEMPT_ENABLE_GLOBAL(global preemption) can only be set by KMD 348: * in ringbuffer. 349: * 1) set global preemption to 0x0 to disable global preemption. 350: * Only RB level preemption is allowed in this mode 351: * 2) Set global preemption to defer(0x2) for finegrain preemption. 352: * when global preemption is set to defer(0x2), 353: * CP_PREEMPT_ENABLE_LOCAL(local preemption) determines the 354: * preemption point. Local preemption 355: * can be enabled by both UMD(within IB) and KMD. 356: */ 357: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_GLOBAL, 1); 358: *cmds++ = ((preempt_style == KGSL_CONTEXT_PREEMPT_STYLE_FINEGRAIN) 359: ? 2 : 0); 360: 361: /* Turn CP protection OFF */ 362: cmds += cp_protected_mode(adreno_dev, cmds, 0); 363: 364: /* 365: * CP during context switch will save context switch info to 366: * a5xx_cp_preemption_record pointed by CONTEXT_SWITCH_SAVE_ADDR 367: */ 368: *cmds++ = cp_type4_packet(A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_LO, 1); 369: *cmds++ = lower_32_bits(gpuaddr); 370: *cmds++ = cp_type4_packet(A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_HI, 1); 371: *cmds++ = upper_32_bits(gpuaddr); 372: 373: /* Turn CP protection ON */ 374: cmds += cp_protected_mode(adreno_dev, cmds, 1); 375: 376: /* 377: * Enable local preemption for finegrain preemption in case of 378: * a misbehaving IB 379: */ 380: if (preempt_style == KGSL_CONTEXT_PREEMPT_STYLE_FINEGRAIN) { 381: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_LOCAL, 1); 382: *cmds++ = 1; 383: } else { 384: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_LOCAL, 1); 385: *cmds++ = 0; 386: } 387: 388: /* Enable CP_CONTEXT_SWITCH_YIELD packets in the IB2s */ 389: *cmds++ = cp_type7_packet(CP_YIELD_ENABLE, 1); 390: *cmds++ = 2; 391: 392: return (unsigned int) (cmds - cmds_orig); 393: } 394: 395: unsigned int a5xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 396: unsigned int *cmds) 397: { 398: int dwords = 0; 399: 400: if (!adreno_is_preemption_enabled(adreno_dev)) 401: return 0; 402: 403: cmds[dwords++] = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 404: /* Write NULL to the address to skip the data write */ 405: dwords += cp_gpuaddr(adreno_dev, &cmds[dwords], 0x0); 406: cmds[dwords++] = 1; 407: /* generate interrupt on preemption completion */ 408: cmds[dwords++] = 1; 409: 410: return dwords; 411: } 412: 413: void a5xx_preemption_start(struct adreno_device *adreno_dev) 414: { 415: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 416: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 417: struct adreno_ringbuffer *rb; 418: unsigned int i; 419: 420: if (!adreno_is_preemption_enabled(adreno_dev)) 421: return; 422: 423: /* Force the state to be clear */ 424: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 425: 426: /* Only set up smmu info when per-process pagetables are enabled */ 427: 428: if (kgsl_mmu_is_perprocess(&device->mmu)) { 429: /* smmu_info is allocated and mapped in a5xx_preemption_iommu_init */ 430: kgsl_sharedmem_writel(iommu->smmu_info, 431: PREEMPT_SMMU_RECORD(magic), A5XX_CP_SMMU_INFO_MAGIC_REF); 432: kgsl_sharedmem_writeq(iommu->smmu_info, 433: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 434: 435: /* The CP doesn't use the asid record, so poison it */ 436: kgsl_sharedmem_writel(iommu->smmu_info, 437: PREEMPT_SMMU_RECORD(asid), 0xDECAFBAD); 438: kgsl_sharedmem_writel(iommu->smmu_info, 439: PREEMPT_SMMU_RECORD(context_idr), 0); 440: 441: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 442: lower_32_bits(iommu->smmu_info->gpuaddr)); 443: 444: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 445: upper_32_bits(iommu->smmu_info->gpuaddr)); 446: } 447: 448: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 449: /* 450: * preemption_desc is allocated and mapped at init time, 451: * so no need to check sharedmem_writel return value 452: */ 453: kgsl_sharedmem_writel(rb->preemption_desc, 454: PREEMPT_RECORD(rptr), 0); 455: kgsl_sharedmem_writel(rb->preemption_desc, 456: PREEMPT_RECORD(wptr), 0); 457: 458: adreno_ringbuffer_set_pagetable(device, rb, 459: device->mmu.defaultpagetable); 460: } 461: 462: } 463: 464: static int a5xx_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 465: struct adreno_ringbuffer *rb, uint64_t counteraddr) 466: { 467: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 468: 469: if (IS_ERR_OR_NULL(rb->preemption_desc)) 470: rb->preemption_desc = kgsl_allocate_global(device, 471: A5XX_CP_CTXRECORD_SIZE_IN_BYTES, SZ_16K, 0, 472: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 473: 474: if (IS_ERR(rb->preemption_desc)) 475: return PTR_ERR(rb->preemption_desc); 476: 477: kgsl_sharedmem_writel(rb->preemption_desc, 478: PREEMPT_RECORD(magic), A5XX_CP_CTXRECORD_MAGIC_REF); 479: kgsl_sharedmem_writel(rb->preemption_desc, 480: PREEMPT_RECORD(info), 0); 481: kgsl_sharedmem_writel(rb->preemption_desc, 482: PREEMPT_RECORD(data), 0); 483: kgsl_sharedmem_writel(rb->preemption_desc, 484: PREEMPT_RECORD(cntl), A5XX_CP_RB_CNTL_DEFAULT); 485: kgsl_sharedmem_writel(rb->preemption_desc, 486: PREEMPT_RECORD(rptr), 0); 487: kgsl_sharedmem_writel(rb->preemption_desc, 488: PREEMPT_RECORD(wptr), 0); 489: kgsl_sharedmem_writeq(rb->preemption_desc, MATCH LINES: 505, 519, 530, 531 493: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 494: kgsl_sharedmem_writeq(rb->preemption_desc, 495: PREEMPT_RECORD(counter), counteraddr); 496: 497: return 0; 498: } 499: 500: int a5xx_preemption_init(struct adreno_device *adreno_dev) 501: { 502: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 503: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 504: struct adreno_preemption *preempt = &adreno_dev->preempt; 505: struct adreno_ringbuffer *rb; 506: int ret; 507: unsigned int i; 508: uint64_t addr; 509: 510: /* We are dependent on IOMMU to make preemption go on the CP side */ 511: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) 512: return -ENODEV; 513: 514: INIT_WORK(&preempt->work, _a5xx_preemption_worker); 515: 516: /* Allocate mem for storing preemption counters */ 517: if (IS_ERR_OR_NULL(preempt->scratch)) 518: preempt->scratch = kgsl_allocate_global(device, 519: adreno_dev->num_ringbuffers * 520: A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE, 0, 0, 0, 521: "preemption_counters"); 522: 523: ret = PTR_ERR_OR_ZERO(preempt->scratch); 524: if (ret) 525: return ret; 526: 527: addr = preempt->scratch->gpuaddr; 528: 529: /* Allocate mem for storing preemption switch record */ 530: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 531: ret = a5xx_preemption_ringbuffer_init(adreno_dev, rb, addr); 532: if (ret) 533: return ret; 534: 535: addr += A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE; 536: } 537: 538: /* Allocate mem for storing preemption smmu record */ 539: if (kgsl_mmu_is_perprocess(&device->mmu) && IS_ERR_OR_NULL(iommu->smmu_info)) 540: iommu->smmu_info = kgsl_allocate_global(device, PAGE_SIZE, 0, 541: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 542: "smmu_info"); 543: 544: if (IS_ERR(iommu->smmu_info)) 545: return PTR_ERR(iommu->smmu_info); 546: 547: set_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 548: return 0; 549: } --- FILE: \adreno_a5xx_ringbuffer.c | HITS: 38 --- MATCH LINES: 10, 16, 35, 62, 73, 97, 110, 113, 114, 115, 118, 120, 123, 124, 136, 137, 159, 175, 182, 190, 218, 234, 242, 246, 252, 260, 281, 308, 323, 334, 350, 357, 367, 372 1: // SPDX-License-Identifier: GPL-2.0-only 2: /* 3: * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include "adreno.h" 8: #include "adreno_a5xx.h" 9: #include "adreno_pm4types.h" 10: #include "adreno_ringbuffer.h" 11: #include "adreno_trace.h" 12: #include "kgsl_trace.h" 13: 14: static int a5xx_rb_pagetable_switch(struct kgsl_device *device, 15: struct adreno_context *drawctxt, 16: struct adreno_ringbuffer *rb, 17: struct kgsl_pagetable *pagetable, u32 *cmds) 18: { 19: u64 ttbr0 = kgsl_mmu_pagetable_get_ttbr0(pagetable); 20: u32 id = drawctxt ? drawctxt->base.id : 0; 21: 22: if (pagetable == device->mmu.defaultpagetable) 23: return 0; 24: 25: cmds[0] = cp_type7_packet(CP_SMMU_TABLE_UPDATE, 3); 26: cmds[1] = lower_32_bits(ttbr0); 27: cmds[2] = upper_32_bits(ttbr0); 28: cmds[3] = id; 29: 30: cmds[4] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 31: cmds[5] = cp_type7_packet(CP_WAIT_FOR_ME, 0); 32: cmds[6] = cp_type4_packet(A5XX_CP_CNTL, 1); 33: cmds[7] = 1; 34: 35: cmds[8] = cp_type7_packet(CP_MEM_WRITE, 5); 36: cmds[9] = lower_32_bits(SCRATCH_RB_GPU_ADDR(device, 37: rb->id, ttbr0)); 38: cmds[10] = upper_32_bits(SCRATCH_RB_GPU_ADDR(device, 39: rb->id, ttbr0)); 40: cmds[11] = lower_32_bits(ttbr0); 41: cmds[12] = upper_32_bits(ttbr0); 42: cmds[13] = id; 43: 44: cmds[14] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 45: cmds[15] = cp_type7_packet(CP_WAIT_FOR_ME, 0); 46: cmds[16] = cp_type4_packet(A5XX_CP_CNTL, 1); 47: cmds[17] = 0; 48: 49: return 18; 50: } 51: 52: #define RB_SOPTIMESTAMP(device, rb) \ 53: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 54: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 55: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 56: 57: #define RB_EOPTIMESTAMP(device, rb) \ 58: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 59: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 60: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 61: 62: int a5xx_ringbuffer_submit(struct adreno_ringbuffer *rb, 63: struct adreno_submit_time *time, bool sync) 64: { 65: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 66: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 67: unsigned long flags; 68: 69: adreno_get_submit_time(adreno_dev, rb, time); 70: adreno_profile_submit_time(time); 71: 72: if (sync) { 73: u32 *cmds = adreno_ringbuffer_allocspace(rb, 3); 74: 75: if (IS_ERR(cmds)) 76: return PTR_ERR(cmds); 77: 78: cmds[0] = cp_type7_packet(CP_WHERE_AM_I, 2); 79: cmds[1] = lower_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id, 80: rptr)); 81: cmds[2] = upper_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id, 82: rptr)); 83: } 84: 85: spin_lock_irqsave(&rb->preempt_lock, flags); 86: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 87: if (adreno_dev->cur_rb == rb) 88: kgsl_regwrite(device, A5XX_CP_RB_WPTR, rb->_wptr); 89: } 90: 91: rb->wptr = rb->_wptr; 92: spin_unlock_irqrestore(&rb->preempt_lock, flags); 93: 94: return 0; 95: } 96: 97: int a5xx_ringbuffer_init(struct adreno_device *adreno_dev) 98: { 99: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 100: int i; 101: 102: if (IS_ERR_OR_NULL(device->scratch)) 103: device->scratch = kgsl_allocate_global(device, PAGE_SIZE, 104: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED, 105: "scratch"); 106: 107: if (IS_ERR(device->scratch)) 108: return PTR_ERR(device->scratch); 109: 110: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]); 111: 112: if (!adreno_preemption_feature_set(adreno_dev)) { 113: adreno_dev->num_ringbuffers = 1; 114: return adreno_ringbuffer_setup(adreno_dev, 115: &adreno_dev->ringbuffers[0], 0); 116: } 117: 118: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers); 119: 120: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 121: int ret; 122: 123: ret = adreno_ringbuffer_setup(adreno_dev, 124: &adreno_dev->ringbuffers[i], i); 125: if (ret) 126: return ret; 127: } 128: 129: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 130: a5xx_preemption_init(adreno_dev); 131: return 0; 132: } 133: 134: #define A5XX_SUBMIT_MAX 64 135: 136: int a5xx_ringbuffer_addcmds(struct adreno_device *adreno_dev, 137: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 138: u32 flags, u32 *in, u32 dwords, u32 timestamp, 139: struct adreno_submit_time *time) 140: { 141: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 142: static u32 sequence; 143: u32 size = A5XX_SUBMIT_MAX + dwords; 144: u32 *cmds, index = 0; 145: u64 profile_gpuaddr; 146: u32 profile_dwords; 147: 148: if (adreno_drawctxt_detached(drawctxt)) 149: return -ENOENT; 150: 151: if (adreno_gpu_fault(adreno_dev) != 0) 152: return -EPROTO; 153: 154: rb->timestamp++; 155: 156: if (drawctxt) 157: drawctxt->internal_timestamp = rb->timestamp; 158: 159: cmds = adreno_ringbuffer_allocspace(rb, size); 160: if (IS_ERR(cmds)) 161: return PTR_ERR(cmds); 162: 163: /* Identify the start of a command */ 164: cmds[index++] = cp_type7_packet(CP_NOP, 1); 165: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 166: 167: /* 14 dwords */ 168: index += a5xx_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 169: &cmds[index]); 170: 171: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 172: drawctxt, &profile_dwords); 173: 174: if (profile_gpuaddr) { 175: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 176: cmds[index++] = lower_32_bits(profile_gpuaddr); 177: cmds[index++] = upper_32_bits(profile_gpuaddr); 178: cmds[index++] = profile_dwords; 179: } 180: 181: if (drawctxt) { 182: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 183: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 184: drawctxt)); 185: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 186: drawctxt)); 187: cmds[index++] = timestamp; 188: } 189: 190: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 191: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 192: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); 193: cmds[index++] = rb->timestamp; 194: 195: if (IS_SECURE(flags)) { 196: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 197: cmds[index++] = 1; 198: } 199: 200: if (IS_NOTPROTECTED(flags)) { 201: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1); 202: cmds[index++] = 0; 203: } 204: 205: memcpy(&cmds[index], in, dwords << 2); 206: index += dwords; 207: 208: if (IS_NOTPROTECTED(flags)) { 209: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1); 210: cmds[index++] = 1; 211: } 212: 213: /* 4 dwords */ 214: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev, 215: drawctxt, &profile_dwords); 216: 217: if (profile_gpuaddr) { 218: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 219: cmds[index++] = lower_32_bits(profile_gpuaddr); 220: cmds[index++] = upper_32_bits(profile_gpuaddr); 221: cmds[index++] = profile_dwords; 222: } 223: 224: if (!adreno_is_a510(adreno_dev) && 225: test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, 226: &device->mmu.pfpolicy)) 227: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0); 228: 229: /* 230: * Do a unique memory write from the GPU to assist in early detection of 231: * interrupt storms 232: */ 233: 234: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 235: cmds[index++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 236: KGSL_MEMSTORE_GLOBAL, ref_wait_ts)); 237: cmds[index++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 238: KGSL_MEMSTORE_GLOBAL, ref_wait_ts)); 239: cmds[index++] = ++sequence; 240: 241: /* 242: * If this is an internal command, just write the ringbuffer timestamp, 243: * otherwise, write both 244: */ 245: if (!drawctxt) { 246: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 247: cmds[index++] = CACHE_FLUSH_TS | (1 << 31); 248: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 249: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 250: cmds[index++] = rb->timestamp; 251: } else { 252: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 253: cmds[index++] = CACHE_FLUSH_TS | (1 << 31); 254: cmds[index++] = lower_32_bits(CTXT_EOPTIMESTAMP(device, 255: drawctxt)); 256: cmds[index++] = upper_32_bits(CTXT_EOPTIMESTAMP(device, 257: drawctxt)); 258: cmds[index++] = timestamp; 259: 260: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 261: cmds[index++] = CACHE_FLUSH_TS; 262: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 263: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 264: cmds[index++] = rb->timestamp; 265: } 266: 267: if (IS_WFI(flags)) 268: cmds[index++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 269: 270: if (IS_SECURE(flags)) { 271: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 272: cmds[index++] = 0; 273: } 274: 275: /* 5 dwords */ 276: index += a5xx_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 277: 278: /* Adjust the thing for the number of bytes we actually wrote */ 279: rb->_wptr -= (size - index); 280: 281: a5xx_ringbuffer_submit(rb, time, 282: !adreno_is_preemption_enabled(adreno_dev)); 283: 284: return 0; 285: } 286: 287: static u32 a5xx_get_alwayson_counter(struct adreno_device *adreno_dev, 288: u32 *cmds, u64 gpuaddr) 289: { 290: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 291: cmds[1] = A5XX_RBBM_ALWAYSON_COUNTER_LO; 292: 293: /* On some targets the upper 32 bits are not reliable */ 294: if (ADRENO_GPUREV(adreno_dev) > ADRENO_REV_A530) 295: cmds[1] |= (1 << 30) | (2 << 18); 296: 297: cmds[2] = lower_32_bits(gpuaddr); 298: cmds[3] = upper_32_bits(gpuaddr); 299: 300: return 4; 301: } 302: 303: /* This is the maximum possible size for 64 bit targets */ 304: #define PROFILE_IB_DWORDS 4 305: #define PROFILE_IB_SLOTS (PAGE_SIZE / (PROFILE_IB_DWORDS << 2)) 306: 307: static u64 a5xx_get_user_profiling_ib(struct adreno_device *adreno_dev, 308: struct adreno_ringbuffer *rb, struct kgsl_drawobj_cmd *cmdobj, 309: u32 target_offset, u32 *cmds) 310: { 311: u32 offset, *ib, dwords; 312: u64 gpuaddr; 313: 314: if (IS_ERR(rb->profile_desc)) 315: return 0; 316: 317: offset = rb->profile_index * (PROFILE_IB_DWORDS << 2); 318: ib = rb->profile_desc->hostptr + offset; 319: gpuaddr = rb->profile_desc->gpuaddr + offset; 320: dwords = a5xx_get_alwayson_counter(adreno_dev, ib, 321: cmdobj->profiling_buffer_gpuaddr + target_offset); 322: 323: cmds[0] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 324: cmds[1] = lower_32_bits(gpuaddr); 325: cmds[2] = upper_32_bits(gpuaddr); 326: cmds[3] = dwords; 327: 328: rb->profile_index = (rb->profile_index + 1) % PROFILE_IB_SLOTS; 329: 330: return 4; 331: } 332: 333: static int a5xx_rb_context_switch(struct adreno_device *adreno_dev, 334: struct adreno_ringbuffer *rb, 335: struct adreno_context *drawctxt) 336: { 337: struct kgsl_pagetable *pagetable = 338: adreno_drawctxt_get_pagetable(drawctxt); 339: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 340: int count = 0; 341: u32 cmds[32]; 342: 343: if (adreno_drawctxt_get_pagetable(rb->drawctxt_active) != pagetable) 344: count += a5xx_rb_pagetable_switch(device, drawctxt, 345: rb, pagetable, cmds); 346: 347: cmds[count++] = cp_type7_packet(CP_NOP, 1); 348: cmds[count++] = CONTEXT_TO_MEM_IDENTIFIER; 349: 350: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 351: cmds[count++] = lower_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb, 352: current_context)); 353: cmds[count++] = upper_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb, 354: current_context)); 355: cmds[count++] = drawctxt->base.id; 356: 357: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 358: cmds[count++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 359: KGSL_MEMSTORE_GLOBAL, current_context)); 360: cmds[count++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 361: KGSL_MEMSTORE_GLOBAL, current_context)); 362: cmds[count++] = drawctxt->base.id; 363: 364: cmds[count++] = cp_type4_packet(A5XX_UCHE_INVALIDATE0, 1); 365: cmds[count++] = 0x12; 366: 367: return a5xx_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED, 368: cmds, count, 0, NULL); 369: } 370: 371: static int a5xx_drawctxt_switch(struct adreno_device *adreno_dev, 372: struct adreno_ringbuffer *rb, 373: struct adreno_context *drawctxt) 374: { 375: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 376: 377: if (rb->drawctxt_active == drawctxt) 378: return 0; 379: 380: if (kgsl_context_detached(&drawctxt->base)) 381: return -ENOENT; 382: 383: if (!_kgsl_context_get(&drawctxt->base)) 384: return -ENOENT; 385: 386: trace_adreno_drawctxt_switch(rb, drawctxt); 387: 388: a5xx_rb_context_switch(adreno_dev, rb, drawctxt); 389: 390: /* Release the current drawctxt as soon as the new one is switched */ 391: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active, 392: rb, rb->timestamp); 393: 394: rb->drawctxt_active = drawctxt; 395: return 0; 396: } MATCH LINES: 412, 419 400: a5xx_get_user_profiling_ib((dev), (rb), (cmdobj), \ 401: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 402: (cmds)) 403: 404: #define A5XX_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 405: a5xx_get_alwayson_counter((dev), (cmds), \ 406: (dev)->profile_buffer->gpuaddr + \ 407: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 408: field)) 409: 410: #define A5XX_COMMAND_DWORDS 32 411: 412: int a5xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 413: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 414: struct adreno_submit_time *time) 415: { 416: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 417: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 418: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 419: struct adreno_ringbuffer *rb = drawctxt->rb; 420: int ret = 0, numibs = 0, index = 0; 421: u32 *cmds; 422: 423: /* Count the number of IBs (if we are not skipping) */ 424: if (!IS_SKIP(flags)) { 425: struct list_head *tmp; 426: 427: list_for_each(tmp, &cmdobj->cmdlist) 428: numibs++; 429: } 430: 431: cmds = kmalloc((A5XX_COMMAND_DWORDS + (numibs * 5)) << 2, GFP_KERNEL); 432: if (!cmds) { 433: ret = -ENOMEM; 434: goto done; 435: } 436: 437: cmds[index++] = cp_type7_packet(CP_NOP, 1); 438: cmds[index++] = START_IB_IDENTIFIER; 439: 440: /* Kernel profiling: 4 dwords */ 441: if (IS_KERNEL_PROFILE(flags)) 442: index += A5XX_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index], 443: started); MATCH LINES: 460 448: &cmds[index], gpu_ticks_submitted); 449: 450: if (numibs) { 451: struct kgsl_memobj_node *ib; 452: 453: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 454: if (ib->priv & MEMOBJ_SKIP || 455: (ib->flags & KGSL_CMDLIST_CTXTSWITCH_PREAMBLE 456: && !IS_PREAMBLE(flags))) 457: cmds[index++] = cp_type7_packet(CP_NOP, 4); 458: 459: cmds[index++] = 460: cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 461: cmds[index++] = lower_32_bits(ib->gpuaddr); 462: cmds[index++] = upper_32_bits(ib->gpuaddr); 463: 464: /* Double check that IB_PRIV is never set */ 465: cmds[index++] = (ib->size >> 2) & 0xfffff; 466: } 467: } 468: 469: /* 470: * SRM -- set render mode (ex binning, direct render etc) 471: * SRM is set by UMD usually at start of IB to tell CP the type of 472: * preemption. 473: * KMD needs to set SRM to NULL to indicate CP that rendering is 474: * done by IB. 475: */ 476: cmds[index++] = cp_type7_packet(CP_SET_RENDER_MODE, 5); 477: cmds[index++] = 0; 478: cmds[index++] = 0; 479: cmds[index++] = 0; 480: cmds[index++] = 0; 481: cmds[index++] = 0; 482: 483: cmds[index++] = cp_type7_packet(CP_YIELD_ENABLE, 1); 484: cmds[index++] = 1; MATCH LINES: 519 507: * It is "normal" to get a -ENOSPC or a -ENOENT. Don't log it, 508: * the upper layers know how to handle it 509: */ 510: if (ret != -ENOSPC && ret != -ENOENT) 511: dev_err(device->dev, 512: "Unable to switch draw context: %d\n", 513: ret); 514: goto done; 515: } 516: 517: adreno_drawobj_set_constraint(device, drawobj); 518: 519: ret = a5xx_ringbuffer_addcmds(adreno_dev, drawctxt->rb, drawctxt, 520: flags, cmds, index, drawobj->timestamp, time); 521: 522: done: 523: trace_kgsl_issueibcmds(device, drawctxt->base.id, numibs, 524: drawobj->timestamp, drawobj->flags, ret, drawctxt->type); 525: 526: kfree(cmds); 527: return ret; 528: } --- FILE: \adreno_a6xx.c | HITS: 29 --- MATCH LINES: 275 263: 264: return adreno_allocate_global(KGSL_DEVICE(adreno_dev), 265: &adreno_dev->pwrup_reglist, 266: PAGE_SIZE, 0, 0, KGSL_MEMDESC_PRIVILEGED, 267: "powerup_register_list"); 268: } 269: 270: static int a6xx_nogmu_init(struct adreno_device *adreno_dev) 271: { 272: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 273: int ret; 274: 275: ret = a6xx_ringbuffer_init(adreno_dev); 276: if (ret) 277: return ret; 278: 279: ret = a6xx_microcode_read(adreno_dev); 280: if (ret) 281: return ret; 282: 283: /* Try to map the GMU wrapper region if applicable */ 284: ret = kgsl_regmap_add_region(&device->regmap, device->pdev, 285: "gmu_wrapper", -EINVAL, NULL, NULL); 286: if (ret && ret != -ENODEV) 287: dev_err(device->dev, "Couldn't map the GMU wrapper registers\n"); 288: 289: adreno_create_profile_buffer(adreno_dev); 290: 291: return a6xx_init(adreno_dev); 292: } 293: 294: static void a6xx_protect_init(struct adreno_device *adreno_dev) 295: { 296: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 297: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev); 298: const struct adreno_protected_regs *regs = a6xx_core->protected_regs; 299: int i; MATCH LINES: 627, 628 615: 616: return (gdsc_on & clk_on); 617: } 618: 619: /* 620: * Some targets support marking certain transactions as always privileged which 621: * allows us to mark more memory as privileged without having to explicitly set 622: * the APRIV bit. For those targets, choose the following transactions to be 623: * privileged by default: 624: * CDWRITE [6:6] - Crashdumper writes 625: * CDREAD [5:5] - Crashdumper reads 626: * RBRPWB [3:3] - RPTR shadow writes 627: * RBPRIVLEVEL [2:2] - Memory accesses from PM4 packets in the ringbuffer 628: * RBFETCH [1:1] - Ringbuffer reads 629: */ 630: #define A6XX_APRIV_DEFAULT \ 631: ((1 << 6) | (1 << 5) | (1 << 3) | (1 << 2) | (1 << 1)) 632: 633: void a6xx_start(struct adreno_device *adreno_dev) 634: { 635: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 636: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev); 637: unsigned int hbb_hi = 0, hbb_lo = 0; 638: unsigned int uavflagprd_inv; 639: struct adreno_ubwc_props *ubwc_props = &adreno_dev->ubwc_props; 640: u32 mal = adreno_dev->mal; 641: 642: /* Enable 64 bit addressing */ 643: kgsl_regwrite(device, A6XX_CP_ADDR_MODE_CNTL, 0x1); 644: kgsl_regwrite(device, A6XX_VSC_ADDR_MODE_CNTL, 0x1); 645: kgsl_regwrite(device, A6XX_GRAS_ADDR_MODE_CNTL, 0x1); 646: kgsl_regwrite(device, A6XX_RB_ADDR_MODE_CNTL, 0x1); 647: kgsl_regwrite(device, A6XX_PC_ADDR_MODE_CNTL, 0x1); 648: kgsl_regwrite(device, A6XX_HLSQ_ADDR_MODE_CNTL, 0x1); 649: kgsl_regwrite(device, A6XX_VFD_ADDR_MODE_CNTL, 0x1); 650: kgsl_regwrite(device, A6XX_VPC_ADDR_MODE_CNTL, 0x1); 651: kgsl_regwrite(device, A6XX_UCHE_ADDR_MODE_CNTL, 0x1); 652: kgsl_regwrite(device, A6XX_SP_ADDR_MODE_CNTL, 0x1); MATCH LINES: 977 965: #define CP_INIT_MASK (CP_INIT_MAX_CONTEXT | \ 966: CP_INIT_ERROR_DETECTION_CONTROL | \ 967: CP_INIT_HEADER_DUMP | \ 968: CP_INIT_DEFAULT_RESET_STATE | \ 969: CP_INIT_UCODE_WORKAROUND_MASK | \ 970: CP_INIT_OPERATION_MODE_MASK | \ 971: CP_INIT_REGISTER_INIT_LIST_WITH_SPINLOCK) 972: 973: void a6xx_cp_init_cmds(struct adreno_device *adreno_dev, u32 *cmds) 974: { 975: int i = 0; 976: 977: cmds[i++] = cp_type7_packet(CP_ME_INIT, A6XX_CP_INIT_DWORDS - 1); 978: 979: /* Enabled ordinal mask */ 980: cmds[i++] = CP_INIT_MASK; 981: 982: if (CP_INIT_MASK & CP_INIT_MAX_CONTEXT) 983: cmds[i++] = 0x00000003; 984: 985: if (CP_INIT_MASK & CP_INIT_ERROR_DETECTION_CONTROL) 986: cmds[i++] = 0x20000000; 987: 988: if (CP_INIT_MASK & CP_INIT_HEADER_DUMP) { 989: /* Header dump address */ 990: cmds[i++] = 0x00000000; 991: /* Header dump enable and dump size */ 992: cmds[i++] = 0x00000000; 993: } 994: 995: if (CP_INIT_MASK & CP_INIT_UCODE_WORKAROUND_MASK) 996: cmds[i++] = 0x00000000; 997: 998: if (CP_INIT_MASK & CP_INIT_OPERATION_MODE_MASK) 999: cmds[i++] = 0x00000002; 1000: 1001: if (CP_INIT_MASK & CP_INIT_REGISTER_INIT_LIST_WITH_SPINLOCK) { MATCH LINES: 1041, 1043, 1048, 1054, 1060, 1079, 1082, 1108, 1121, 1127, 1139, 1157, 1162, 1163, 1175, 1176, 1183, 1218, 1225 1029: dev_err(device->dev, 1030: "rb=%d pos=%X/%X rbbm_status=%8.8X/%8.8X int_0_status=%8.8X\n", 1031: adreno_dev->cur_rb ? adreno_dev->cur_rb->id : -1, rptr, wptr, 1032: status, status3, intstatus); 1033: 1034: dev_err(device->dev, " hwfault=%8.8X\n", hwfault); 1035: 1036: kgsl_device_snapshot(device, NULL, NULL, false); 1037: 1038: } 1039: 1040: /* 1041: * a6xx_send_cp_init() - Initialize ringbuffer 1042: * @adreno_dev: Pointer to adreno device 1043: * @rb: Pointer to the ringbuffer of device 1044: * 1045: * Submit commands for ME initialization, 1046: */ 1047: static int a6xx_send_cp_init(struct adreno_device *adreno_dev, 1048: struct adreno_ringbuffer *rb) 1049: { 1050: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1051: unsigned int *cmds; 1052: int ret; 1053: 1054: cmds = adreno_ringbuffer_allocspace(rb, A6XX_CP_INIT_DWORDS); 1055: if (IS_ERR(cmds)) 1056: return PTR_ERR(cmds); 1057: 1058: a6xx_cp_init_cmds(adreno_dev, cmds); 1059: 1060: ret = a6xx_ringbuffer_submit(rb, NULL, true); 1061: if (!ret) { 1062: ret = adreno_spin_idle(adreno_dev, 2000); 1063: if (ret) { 1064: a6xx_spin_idle_debug(adreno_dev, 1065: "CP initialization failed to idle\n"); 1066: 1067: kgsl_sharedmem_writel(device->scratch, 1068: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1069: rb->wptr = 0; 1070: rb->_wptr = 0; 1071: } 1072: } 1073: 1074: return ret; 1075: } 1076: 1077: /* 1078: * Follow the ME_INIT sequence with a preemption yield to allow the GPU to move 1079: * to a different ringbuffer, if desired 1080: */ 1081: static int _preemption_init(struct adreno_device *adreno_dev, 1082: struct adreno_ringbuffer *rb, unsigned int *cmds, 1083: struct kgsl_context *context) 1084: { 1085: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1086: unsigned int *cmds_orig = cmds; 1087: 1088: /* Turn CP protection OFF on legacy targets */ 1089: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 1090: cmds += cp_protected_mode(adreno_dev, cmds, 0); 1091: 1092: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 1093: kgsl_mmu_is_secured(&device->mmu) ? 6 : 3); 1094: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 1095: cmds += cp_gpuaddr(adreno_dev, cmds, 1096: rb->preemption_desc->gpuaddr); 1097: 1098: if (kgsl_mmu_is_secured(&device->mmu)) { 1099: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 1100: cmds += cp_gpuaddr(adreno_dev, cmds, 1101: rb->secure_preemption_desc->gpuaddr); 1102: } 1103: 1104: /* Turn CP protection back ON */ 1105: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 1106: cmds += cp_protected_mode(adreno_dev, cmds, 1); 1107: 1108: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1109: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 1110: *cmds++ = 0; 1111: /* generate interrupt on preemption completion */ 1112: *cmds++ = 0; 1113: 1114: return cmds - cmds_orig; 1115: } 1116: 1117: static int a6xx_post_start(struct adreno_device *adreno_dev) 1118: { 1119: int ret; 1120: unsigned int *cmds, *start; 1121: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1122: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1123: 1124: if (!adreno_is_preemption_enabled(adreno_dev)) 1125: return 0; 1126: 1127: cmds = adreno_ringbuffer_allocspace(rb, 42); 1128: if (IS_ERR(cmds)) { 1129: dev_err(device->dev, 1130: "error allocating preemption init cmds\n"); 1131: return PTR_ERR(cmds); 1132: } 1133: start = cmds; 1134: 1135: cmds += _preemption_init(adreno_dev, rb, cmds, NULL); 1136: 1137: rb->_wptr = rb->_wptr - (42 - (cmds - start)); 1138: 1139: ret = a6xx_ringbuffer_submit(rb, NULL, false); 1140: if (!ret) { 1141: ret = adreno_spin_idle(adreno_dev, 2000); 1142: if (ret) 1143: a6xx_spin_idle_debug(adreno_dev, 1144: "hw preemption initialization failed to idle\n"); 1145: } 1146: 1147: return ret; 1148: } 1149: 1150: int a6xx_rb_start(struct adreno_device *adreno_dev) 1151: { 1152: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev); 1153: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1154: u32 cp_rb_cntl = A6XX_CP_RB_CNTL_DEFAULT | 1155: (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? 0 : (1 << 27)); 1156: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 1157: struct adreno_ringbuffer *rb; 1158: uint64_t addr; 1159: int ret, i; 1160: unsigned int *cmds; 1161: 1162: /* Clear all the ringbuffers */ 1163: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1164: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 1165: kgsl_sharedmem_writel(device->scratch, 1166: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1167: 1168: rb->wptr = 0; 1169: rb->_wptr = 0; 1170: rb->wptr_preempt_end = ~0; 1171: } 1172: 1173: a6xx_preemption_start(adreno_dev); 1174: 1175: /* Set up the current ringbuffer */ 1176: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 1177: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 1178: 1179: kgsl_regwrite(device, A6XX_CP_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1180: kgsl_regwrite(device, A6XX_CP_RB_RPTR_ADDR_HI, upper_32_bits(addr)); 1181: 1182: /* 1183: * The size of the ringbuffer in the hardware is the log2 1184: * representation of the size in quadwords (sizedwords / 2). 1185: */ 1186: kgsl_regwrite(device, A6XX_CP_RB_CNTL, cp_rb_cntl); 1187: 1188: kgsl_regwrite(device, A6XX_CP_RB_BASE, 1189: lower_32_bits(rb->buffer_desc->gpuaddr)); 1190: 1191: kgsl_regwrite(device, A6XX_CP_RB_BASE_HI, 1192: upper_32_bits(rb->buffer_desc->gpuaddr)); 1193: 1194: /* Program the ucode base for CP */ 1195: kgsl_regwrite(device, A6XX_CP_SQE_INSTR_BASE_LO, 1196: lower_32_bits(fw->memdesc->gpuaddr)); 1197: kgsl_regwrite(device, A6XX_CP_SQE_INSTR_BASE_HI, 1198: upper_32_bits(fw->memdesc->gpuaddr)); 1199: 1200: /* Clear the SQE_HALT to start the CP engine */ 1201: kgsl_regwrite(device, A6XX_CP_SQE_CNTL, 1); 1202: 1203: ret = a6xx_send_cp_init(adreno_dev, rb); 1204: if (ret) 1205: return ret; 1206: 1207: ret = adreno_zap_shader_load(adreno_dev, a6xx_core->zap_name); 1208: if (ret) 1209: return ret; 1210: 1211: /* 1212: * Take the GPU out of secure mode. Try the zap shader if it is loaded, 1213: * otherwise just try to write directly to the secure control register 1214: */ 1215: if (!adreno_dev->zap_loaded) 1216: kgsl_regwrite(device, A6XX_RBBM_SECVID_TRUST_CNTL, 0); 1217: else { 1218: cmds = adreno_ringbuffer_allocspace(rb, 2); 1219: if (IS_ERR(cmds)) 1220: return PTR_ERR(cmds); 1221: 1222: *cmds++ = cp_packet(adreno_dev, CP_SET_SECURE_MODE, 1); 1223: *cmds++ = 0; 1224: 1225: ret = a6xx_ringbuffer_submit(rb, NULL, true); 1226: if (!ret) { 1227: ret = adreno_spin_idle(adreno_dev, 2000); 1228: if (ret) { 1229: a6xx_spin_idle_debug(adreno_dev, 1230: "Switch to unsecure failed to idle\n"); 1231: return ret; 1232: } 1233: } 1234: } 1235: 1236: return a6xx_post_start(adreno_dev); 1237: } 1238: 1239: /* 1240: * a6xx_sptprac_enable() - Power on SPTPRAC 1241: * @adreno_dev: Pointer to Adreno device 1242: */ 1243: static int a6xx_sptprac_enable(struct adreno_device *adreno_dev) 1244: { 1245: return a6xx_gmu_sptprac_enable(adreno_dev); 1246: } 1247: 1248: /* 1249: * a6xx_sptprac_disable() - Power off SPTPRAC MATCH LINES: 1535 1523: unsigned int opcode; 1524: 1525: kgsl_regwrite(device, A6XX_CP_SQE_STAT_ADDR, 1); 1526: kgsl_regread(device, A6XX_CP_SQE_STAT_DATA, &opcode); 1527: dev_crit_ratelimited(device->dev, 1528: "CP opcode error interrupt | opcode=0x%8.8x\n", opcode); 1529: } 1530: if (status1 & BIT(A6XX_CP_UCODE_ERROR)) 1531: dev_crit_ratelimited(device->dev, "CP ucode error interrupt\n"); 1532: if (status1 & BIT(A6XX_CP_HW_FAULT_ERROR)) { 1533: kgsl_regread(device, A6XX_CP_HW_FAULT, &status2); 1534: dev_crit_ratelimited(device->dev, 1535: "CP | Ringbuffer HW fault | status=%x\n", status2); 1536: } 1537: if (status1 & BIT(A6XX_CP_REGISTER_PROTECTION_ERROR)) { 1538: kgsl_regread(device, A6XX_CP_PROTECT_STATUS, &status2); 1539: dev_crit_ratelimited(device->dev, 1540: "CP | Protected mode error | %s | addr=%x | status=%x\n", 1541: status2 & (1 << 20) ? "READ" : "WRITE", 1542: status2 & 0x3FFFF, status2); 1543: } 1544: if (status1 & BIT(A6XX_CP_AHB_ERROR)) 1545: dev_crit_ratelimited(device->dev, 1546: "CP AHB error interrupt\n"); 1547: if (status1 & BIT(A6XX_CP_VSD_PARITY_ERROR)) 1548: dev_crit_ratelimited(device->dev, 1549: "CP VSD decoder parity error\n"); 1550: if (status1 & BIT(A6XX_CP_ILLEGAL_INSTR_ERROR)) 1551: dev_crit_ratelimited(device->dev, 1552: "CP Illegal instruction error\n"); 1553: 1554: } 1555: 1556: static void a6xx_err_callback(struct adreno_device *adreno_dev, int bit) 1557: { 1558: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1559: MATCH LINES: 2403 2391: .rb_start = a6xx_rb_start, 2392: .regulator_disable = a6xx_prepare_for_regulator_disable, 2393: .gpu_keepalive = a6xx_gpu_keepalive, 2394: .hw_isidle = a6xx_hw_isidle, 2395: .iommu_fault_block = a6xx_iommu_fault_block, 2396: .reset = a6xx_reset, 2397: .preemption_schedule = a6xx_preemption_schedule, 2398: .read_alwayson = a6xx_read_alwayson, 2399: .power_ops = &adreno_power_operations, 2400: .clear_pending_transactions = a6xx_clear_pending_transactions, 2401: .deassert_gbif_halt = a6xx_deassert_gbif_halt, 2402: .remove = a6xx_remove, 2403: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2404: .is_hw_collapsible = adreno_isidle, 2405: .power_stats = a6xx_power_stats, 2406: .add_to_va_minidump = a6xx_dev_add_to_minidump, 2407: .gx_is_on = a6xx_gx_is_on, 2408: }; 2409: 2410: const struct a6xx_gpudev adreno_a6xx_hwsched_gpudev = { 2411: .base = { 2412: .reg_offsets = a6xx_register_offsets, 2413: .probe = a6xx_hwsched_probe, 2414: .snapshot = a6xx_hwsched_snapshot, 2415: .irq_handler = a6xx_hwsched_irq_handler, 2416: .iommu_fault_block = a6xx_iommu_fault_block, 2417: .context_detach = a6xx_hwsched_context_detach, 2418: .read_alwayson = a6xx_read_alwayson, 2419: .reset = a6xx_hwsched_reset_replay, 2420: .power_ops = &a6xx_hwsched_power_ops, 2421: .power_stats = a6xx_power_stats, 2422: .hw_isidle = a6xx_hw_isidle, 2423: .add_to_va_minidump = a6xx_hwsched_add_to_minidump, 2424: .gx_is_on = a6xx_gmu_gx_is_on, 2425: .send_recurring_cmdobj = a6xx_hwsched_send_recurring_cmdobj, 2426: .set_isdb_breakpoint_registers = a6xx_set_isdb_breakpoint_registers, 2427: }, MATCH LINES: 2450, 2476, 2503, 2527 2438: .irq_handler = a6xx_irq_handler, 2439: .rb_start = a6xx_rb_start, 2440: .regulator_enable = a6xx_sptprac_enable, 2441: .regulator_disable = a6xx_sptprac_disable, 2442: .gpu_keepalive = a6xx_gpu_keepalive, 2443: .hw_isidle = a6xx_hw_isidle, 2444: .iommu_fault_block = a6xx_iommu_fault_block, 2445: .reset = a6xx_gmu_reset, 2446: .preemption_schedule = a6xx_preemption_schedule, 2447: .read_alwayson = a6xx_read_alwayson, 2448: .power_ops = &a6xx_gmu_power_ops, 2449: .remove = a6xx_remove, 2450: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2451: .power_stats = a6xx_power_stats, 2452: .add_to_va_minidump = a6xx_gmu_add_to_minidump, 2453: .gx_is_on = a6xx_gmu_gx_is_on, 2454: .set_isdb_breakpoint_registers = a6xx_set_isdb_breakpoint_registers, 2455: }, 2456: .hfi_probe = a6xx_gmu_hfi_probe, 2457: .handle_watchdog = a6xx_gmu_handle_watchdog, 2458: }; 2459: 2460: const struct adreno_gpudev adreno_a6xx_rgmu_gpudev = { 2461: .reg_offsets = a6xx_register_offsets, 2462: .probe = a6xx_rgmu_device_probe, 2463: .snapshot = a6xx_rgmu_snapshot, 2464: .irq_handler = a6xx_irq_handler, 2465: .rb_start = a6xx_rb_start, 2466: .regulator_enable = a6xx_sptprac_enable, 2467: .regulator_disable = a6xx_sptprac_disable, 2468: .gpu_keepalive = a6xx_gpu_keepalive, 2469: .hw_isidle = a6xx_hw_isidle, 2470: .iommu_fault_block = a6xx_iommu_fault_block, 2471: .reset = a6xx_rgmu_reset, 2472: .preemption_schedule = a6xx_preemption_schedule, 2473: .read_alwayson = a6xx_read_alwayson, 2474: .power_ops = &a6xx_rgmu_power_ops, 2475: .remove = a6xx_remove, 2476: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2477: .power_stats = a6xx_power_stats, 2478: .add_to_va_minidump = a6xx_rgmu_add_to_minidump, 2479: .gx_is_on = a6xx_rgmu_gx_is_on, 2480: }; 2481: 2482: /* This is a non GMU/RGMU part */ 2483: const struct adreno_gpudev adreno_a619_holi_gpudev = { 2484: .reg_offsets = a6xx_register_offsets, 2485: .probe = a6xx_probe, 2486: .start = a6xx_nogmu_start, 2487: .snapshot = a6xx_snapshot, 2488: .init = a6xx_nogmu_init, 2489: .irq_handler = a6xx_irq_handler, 2490: .rb_start = a6xx_rb_start, 2491: .regulator_enable = a619_holi_sptprac_enable, 2492: .regulator_disable = a619_holi_sptprac_disable, 2493: .gpu_keepalive = a6xx_gpu_keepalive, 2494: .hw_isidle = a619_holi_hw_isidle, 2495: .iommu_fault_block = a6xx_iommu_fault_block, 2496: .reset = a6xx_reset, 2497: .preemption_schedule = a6xx_preemption_schedule, 2498: .read_alwayson = a6xx_read_alwayson, 2499: .power_ops = &adreno_power_operations, 2500: .clear_pending_transactions = a6xx_clear_pending_transactions, 2501: .deassert_gbif_halt = a6xx_deassert_gbif_halt, 2502: .remove = a6xx_remove, 2503: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2504: .is_hw_collapsible = adreno_isidle, 2505: .power_stats = a6xx_power_stats, 2506: .add_to_va_minidump = a6xx_dev_add_to_minidump, 2507: .gx_is_on = a619_holi_gx_is_on, 2508: }; 2509: 2510: const struct a6xx_gpudev adreno_a630_gpudev = { 2511: .base = { 2512: .reg_offsets = a6xx_register_offsets, 2513: .probe = a6xx_gmu_device_probe, 2514: .snapshot = a6xx_gmu_snapshot, 2515: .irq_handler = a6xx_irq_handler, 2516: .rb_start = a6xx_rb_start, 2517: .regulator_enable = a6xx_sptprac_enable, 2518: .regulator_disable = a6xx_sptprac_disable, 2519: .gpu_keepalive = a6xx_gpu_keepalive, 2520: .hw_isidle = a6xx_hw_isidle, 2521: .iommu_fault_block = a6xx_iommu_fault_block, 2522: .reset = a6xx_gmu_reset, 2523: .preemption_schedule = a6xx_preemption_schedule, 2524: .read_alwayson = a6xx_read_alwayson, 2525: .power_ops = &a630_gmu_power_ops, 2526: .remove = a6xx_remove, 2527: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2528: .power_stats = a6xx_power_stats, 2529: .add_to_va_minidump = a6xx_gmu_add_to_minidump, 2530: .gx_is_on = a6xx_gmu_gx_is_on, 2531: }, 2532: .hfi_probe = a6xx_gmu_hfi_probe, 2533: .handle_watchdog = a6xx_gmu_handle_watchdog, 2534: }; --- FILE: \adreno_a6xx.h | HITS: 19 --- MATCH LINES: 111 99: #define CP_CLUSTER_PC_VS 0x2 100: #define CP_CLUSTER_GRAS 0x3 101: #define CP_CLUSTER_SP_PS 0x4 102: #define CP_CLUSTER_PS 0x5 103: #define CP_CLUSTER_VPC_PS 0x6 104: 105: /** 106: * struct a6xx_cp_preemption_record - CP context record for 107: * preemption. 108: * @magic: (00) Value at this offset must be equal to 109: * A6XX_CP_CTXRECORD_MAGIC_REF. 110: * @info: (04) Type of record. Written non-zero (usually) by CP. 111: * we must set to zero for all ringbuffers. 112: * @errno: (08) Error code. Initialize this to A6XX_CP_CTXRECORD_ERROR_NONE. 113: * CP will update to another value if a preemption error occurs. 114: * @data: (12) DATA field in YIELD and SET_MARKER packets. 115: * Written by CP when switching out. Not used on switch-in. Initialized to 0. 116: * @cntl: (16) RB_CNTL, saved and restored by CP. We must initialize this. 117: * @rptr: (20) RB_RPTR, saved and restored by CP. We must initialize this. 118: * @wptr: (24) RB_WPTR, saved and restored by CP. We must initialize this. 119: * @_pad28: (28) Reserved/padding. 120: * @rptr_addr: (32) RB_RPTR_ADDR_LO|HI saved and restored. We must initialize. 121: * rbase: (40) RB_BASE_LO|HI saved and restored. 122: * counter: (48) Pointer to preemption counter. 123: */ 124: struct a6xx_cp_preemption_record { 125: uint32_t magic; 126: uint32_t info; 127: uint32_t errno; 128: uint32_t data; 129: uint32_t cntl; 130: uint32_t rptr; 131: uint32_t wptr; 132: uint32_t _pad28; 133: uint64_t rptr_addr; 134: uint64_t rbase; 135: uint64_t counter; MATCH LINES: 217, 226, 228, 233 205: return container_of(core, struct adreno_a6xx_core, base); 206: } 207: 208: /* Preemption functions */ 209: void a6xx_preemption_trigger(struct adreno_device *adreno_dev, bool atomic); 210: void a6xx_preemption_schedule(struct adreno_device *adreno_dev); 211: void a6xx_preemption_start(struct adreno_device *adreno_dev); 212: int a6xx_preemption_init(struct adreno_device *adreno_dev); 213: 214: /** 215: * a6xx_preemption_post_ibsubmit - Insert commands following a submission 216: * @adreno_dev: Adreno GPU handle 217: * @cmds: Pointer to the ringbuffer to insert opcodes 218: * 219: * Return: The number of dwords written to @cmds 220: */ 221: u32 a6xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, u32 *cmds); 222: 223: /** 224: * a6xx_preemption_post_ibsubmit - Insert opcodes before a submission 225: * @adreno_dev: Adreno GPU handle 226: * @rb: The ringbuffer being written 227: * @drawctxt: The draw context being written 228: * @cmds: Pointer to the ringbuffer to insert opcodes 229: * 230: * Return: The number of dwords written to @cmds 231: */ 232: u32 a6xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 233: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 234: u32 *cmds); 235: 236: void a6xx_preemption_callback(struct adreno_device *adreno_dev, int bit); 237: 238: void a6xx_preemption_context_destroy(struct kgsl_context *context); 239: 240: void a6xx_snapshot(struct adreno_device *adreno_dev, 241: struct kgsl_snapshot *snapshot); 242: void a6xx_crashdump_init(struct adreno_device *adreno_dev); 243: int a6xx_gmu_sptprac_enable(struct adreno_device *adreno_dev); 244: void a6xx_gmu_sptprac_disable(struct adreno_device *adreno_dev); 245: bool a6xx_gmu_sptprac_is_on(struct adreno_device *adreno_dev); 246: bool a619_holi_gx_is_on(struct adreno_device *adreno_dev); 247: 248: /** 249: * a6xx_read_alwayson - Read the current always on clock value 250: * @adreno_dev: An Adreno GPU handle 251: * 252: * Return: The current value of the GMU always on counter 253: */ 254: u64 a6xx_read_alwayson(struct adreno_device *adreno_dev); 255: 256: /** 257: * a6xx_start - Program a6xx registers MATCH LINES: 278, 281 266: * a6xx_init - Initialize a6xx resources 267: * @adreno_dev: An Adreno GPU handle 268: * 269: * This function does a6xx specific one time initialization 270: * and is invoked when the very first client opens a 271: * kgsl instance 272: * 273: * Return: Zero on success and negative error on failure 274: */ 275: int a6xx_init(struct adreno_device *adreno_dev); 276: 277: /** 278: * a6xx_rb_start - A6xx specific ringbuffer setup 279: * @adreno_dev: An Adreno GPU handle 280: * 281: * This function does a6xx specific ringbuffer setup and 282: * attempts to submit CP INIT and bring GPU out of secure mode 283: * 284: * Return: Zero on success and negative error on failure 285: */ 286: int a6xx_rb_start(struct adreno_device *adreno_dev); 287: 288: /** 289: * a6xx_microcode_read - Get the cp microcode from the filesystem 290: * @adreno_dev: An Adreno GPU handle 291: * 292: * This function gets the firmware from filesystem and sets up 293: * the micorocode global buffer 294: * 295: * Return: Zero on success and negative error on failure 296: */ 297: int a6xx_microcode_read(struct adreno_device *adreno_dev); 298: 299: /** 300: * a6xx_probe_common - Probe common a6xx resources 301: * @pdev: Pointer to the platform device 302: * @adreno_dev: Pointer to the adreno device 303: * @chipid: Chipid of the target 304: * @gpucore: Pointer to the gpucore strucure 305: * MATCH LINES: 334, 337, 340, 347, 349, 353, 358, 361, 362, 366, 374, 382 322: /** 323: * a6xx_perfcounter_update - Update the IFPC perfcounter list 324: * @adreno_dev: An Adreno GPU handle 325: * @reg: Perfcounter reg struct to add/remove to the list 326: * @update_reg: true if the perfcounter needs to be programmed by the CPU 327: * 328: * Return: 0 on success or -EBUSY if the lock couldn't be taken 329: */ 330: int a6xx_perfcounter_update(struct adreno_device *adreno_dev, 331: struct adreno_perfcount_register *reg, bool update_reg); 332: 333: /* 334: * a6xx_ringbuffer_init - Initialize the ringbuffers 335: * @adreno_dev: An Adreno GPU handle 336: * 337: * Initialize the ringbuffer(s) for a6xx. 338: * Return: 0 on success or negative on failure 339: */ 340: int a6xx_ringbuffer_init(struct adreno_device *adreno_dev); 341: 342: extern const struct adreno_perfcounters adreno_a630_perfcounters; 343: extern const struct adreno_perfcounters adreno_a6xx_perfcounters; 344: extern const struct adreno_perfcounters adreno_a6xx_legacy_perfcounters; 345: 346: /** 347: * a6xx_ringbuffer_addcmds - Submit a command to the ringbuffer 348: * @adreno_dev: An Adreno GPU handle 349: * @rb: Pointer to the ringbuffer to submit on 350: * @drawctxt: Pointer to the draw context for the submission, or NULL for 351: * internal submissions 352: * @flags: Flags for the submission 353: * @in: Commands to write to the ringbuffer 354: * @dwords: Size of @in (in dwords) 355: * @timestamp: Timestamp for the submission 356: * @time: Optional pointer to a submit time structure 357: * 358: * Submit a command to the ringbuffer. 359: * Return: 0 on success or negative on failure 360: */ 361: int a6xx_ringbuffer_addcmds(struct adreno_device *adreno_dev, 362: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 363: u32 flags, u32 *in, u32 dwords, u32 timestamp, 364: struct adreno_submit_time *time); 365: /** 366: * a6xx_ringbuffer_submitcmd - Submit a user command to the ringbuffer 367: * @adreno_dev: An Adreno GPU handle 368: * @cmdobj: Pointer to a user command object 369: * @flags: Internal submit flags 370: * @time: Optional pointer to a adreno_submit_time container 371: * 372: * Return: 0 on success or negative on failure 373: */ 374: int a6xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 375: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 376: struct adreno_submit_time *time); 377: 378: 379: int a6xx_fenced_write(struct adreno_device *adreno_dev, u32 offset, 380: u32 value, u32 mask); 381: 382: int a6xx_ringbuffer_submit(struct adreno_ringbuffer *rb, 383: struct adreno_submit_time *time, bool sync); 384: 385: void a6xx_cp_init_cmds(struct adreno_device *adreno_dev, u32 *cmds); 386: 387: int a6xx_gmu_hfi_probe(struct adreno_device *adreno_dev); 388: 389: static inline const struct a6xx_gpudev * 390: to_a6xx_gpudev(const struct adreno_gpudev *gpudev) 391: { 392: return container_of(gpudev, struct a6xx_gpudev, base); 393: } 394: 395: /** 396: * a6xx_reset_preempt_records - Reset the preemption buffers 397: * @adreno_dev: Handle to the adreno device 398: * 399: * Reset the preemption records at the time of hard reset 400: */ 401: void a6xx_reset_preempt_records(struct adreno_device *adreno_dev); 402: 403: /** 404: * a6xx_irq_pending - Check if there is any gpu irq pending 405: * @adreno_dev: Handle to the adreno device 406: * --- FILE: \adreno_a6xx_gmu.c | HITS: 3 --- MATCH LINES: 1373 1361: if (adreno_is_a660(adreno_dev)) { 1362: u32 val; 1363: 1364: gmu_core_regread(device, A6XX_GMU_PWR_COL_PREEMPT_KEEPALIVE, &val); 1365: dev_err(gmu_pdev_dev, 1366: "PWR_COL_PREEMPT_KEEPALIVE=%x\n", val); 1367: } 1368: 1369: /* Access GX registers only when GX is ON */ 1370: if (is_on(reg1)) { 1371: kgsl_regread(device, A6XX_CP_STATUS_1, ®6); 1372: kgsl_regread(device, A6XX_CP_CP2GMU_STATUS, ®7); 1373: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, ®8); 1374: 1375: dev_err(gmu_pdev_dev, "A6XX_CP_STATUS_1=%x\n", reg6); 1376: dev_err(gmu_pdev_dev, 1377: "CP2GMU_STATUS=%x CONTEXT_SWITCH_CNTL=%x\n", 1378: reg7, reg8); 1379: } 1380: 1381: WARN_ON(1); 1382: gmu_core_fault_snapshot(device, GMU_FAULT_WAIT_FOR_LOWEST_IDLE); 1383: return -ETIMEDOUT; 1384: } 1385: 1386: /* Bitmask for GPU idle status check */ 1387: #define CXGXCPUBUSYIGNAHB BIT(30) 1388: int a6xx_gmu_wait_for_idle(struct adreno_device *adreno_dev) 1389: { 1390: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1391: unsigned int status2; 1392: uint64_t ts1; 1393: 1394: ts1 = a6xx_read_alwayson(adreno_dev); 1395: if (gmu_core_timed_poll_check(device, A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS, 1396: 0, GMU_START_TIMEOUT, CXGXCPUBUSYIGNAHB)) { 1397: gmu_core_regread(device, MATCH LINES: 3070 3058: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 3059: int ret; 3060: 3061: if (test_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags)) { 3062: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 3063: return a6xx_boot(adreno_dev); 3064: 3065: return 0; 3066: } 3067: 3068: KGSL_BOOT_MARKER("ADRENO Init"); 3069: 3070: ret = a6xx_ringbuffer_init(adreno_dev); 3071: if (ret) 3072: return ret; 3073: 3074: ret = a6xx_microcode_read(adreno_dev); 3075: if (ret) 3076: return ret; 3077: 3078: ret = a6xx_init(adreno_dev); 3079: if (ret) 3080: return ret; 3081: 3082: ret = a6xx_gmu_init(adreno_dev); 3083: if (ret) 3084: return ret; 3085: 3086: kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE); 3087: 3088: ret = a6xx_gmu_first_boot(adreno_dev); 3089: if (ret) 3090: return ret; 3091: 3092: a6xx_fusa_init(adreno_dev); 3093: 3094: ret = a6xx_gpu_boot(adreno_dev); MATCH LINES: 3210 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: --- FILE: \adreno_a6xx_hwsched.c | HITS: 3 --- MATCH LINES: 34, 35, 36 22: { 23: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 24: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 25: u32 i; 26: bool skip_memkind_rb = false; 27: bool parse_payload; 28: 29: a6xx_gmu_snapshot(adreno_dev, snapshot); 30: 31: adreno_hwsched_parse_fault_cmdobj(adreno_dev, snapshot); 32: 33: /* 34: * First try to dump ringbuffers using context bad HFI payloads 35: * because they have all the ringbuffer parameters. If ringbuffer 36: * payloads are not present, fall back to dumping ringbuffers 37: * based on MEMKIND_RB 38: */ 39: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2) 40: parse_payload = adreno_hwsched_parse_payload_rb_legacy(adreno_dev, snapshot); 41: else 42: parse_payload = adreno_hwsched_parse_payload_rb(adreno_dev, snapshot); 43: 44: if (parse_payload) 45: skip_memkind_rb = true; 46: 47: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 48: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 49: 50: if (entry->desc.mem_kind == HFI_MEMKIND_RB && !skip_memkind_rb) 51: kgsl_snapshot_add_section(device, 52: KGSL_SNAPSHOT_SECTION_RB_V2, 53: snapshot, adreno_hwsched_snapshot_rb, 54: entry->md); 55: 56: if (entry->desc.mem_kind == HFI_MEMKIND_SCRATCH) 57: kgsl_snapshot_add_section(device, 58: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 59: snapshot, adreno_snapshot_global, 60: entry->md); --- FILE: \adreno_a6xx_hwsched_hfi.c | HITS: 3 --- MATCH LINES: 202 190: status & (1 << 20) ? "READ" : "WRITE", 191: status & 0x3FFFF, status); 192: } 193: break; 194: case GMU_CP_ILLEGAL_INST_ERROR: 195: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 196: break; 197: case GMU_CP_UCODE_ERROR: 198: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 199: break; 200: case GMU_CP_HW_FAULT_ERROR: 201: dev_crit_ratelimited(gmu_pdev_dev, 202: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 203: a6xx_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 204: KEY_CP_HW_FAULT)); 205: break; 206: case GMU_GPU_PREEMPT_TIMEOUT: { 207: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 208: 209: cur = a6xx_hwsched_lookup_key_value_legacy(adreno_dev, 210: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 211: next = a6xx_hwsched_lookup_key_value_legacy(adreno_dev, 212: PAYLOAD_PREEMPT_TIMEOUT, 213: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 214: cur_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_RPTR); 215: cur_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_WPTR); 216: next_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_RPTR); 217: next_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_WPTR); 218: 219: dev_crit_ratelimited(gmu_pdev_dev, 220: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 221: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 222: } 223: break; 224: case GMU_CP_GPC_ERROR: 225: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: GPC error\n"); 226: break; MATCH LINES: 299 287: status & (1 << 20) ? "READ" : "WRITE", 288: status & 0x3FFFF, status); 289: } 290: break; 291: case GMU_CP_ILLEGAL_INST_ERROR: 292: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 293: break; 294: case GMU_CP_UCODE_ERROR: 295: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 296: break; 297: case GMU_CP_HW_FAULT_ERROR: 298: dev_crit_ratelimited(gmu_pdev_dev, 299: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 300: a6xx_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 301: KEY_CP_HW_FAULT)); 302: break; 303: case GMU_GPU_PREEMPT_TIMEOUT: { 304: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 305: 306: cur = a6xx_hwsched_lookup_key_value(adreno_dev, 307: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 308: next = a6xx_hwsched_lookup_key_value(adreno_dev, 309: PAYLOAD_PREEMPT_TIMEOUT, 310: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 311: cur_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_RPTR); 312: cur_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_WPTR); 313: next_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_RPTR); 314: next_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_WPTR); 315: 316: dev_crit_ratelimited(gmu_pdev_dev, 317: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 318: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 319: } 320: break; 321: case GMU_CP_GPC_ERROR: 322: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: GPC error\n"); 323: break; MATCH LINES: 855 843: * Bit 3 is to enable/disable skipsaverestore 844: */ 845: data = FIELD_PREP(GENMASK(1, 0), adreno_dev->preempt.preempt_level) | 846: FIELD_PREP(BIT(2), adreno_dev->preempt.usesgmem) | 847: FIELD_PREP(BIT(3), adreno_dev->preempt.skipsaverestore); 848: 849: ret = a6xx_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_PREEMPTION, 1, 850: data); 851: if (ret) 852: return ret; 853: 854: /* 855: * Bits[3:0] contain the preemption timeout enable bit per ringbuffer 856: * Bits[31:4] contain the timeout in ms 857: */ 858: return a6xx_hfi_send_set_value(adreno_dev, HFI_VALUE_BIN_TIME, 1, 859: FIELD_PREP(GENMASK(31, 4), ADRENO_PREEMPT_TIMEOUT) | 860: FIELD_PREP(GENMASK(3, 0), 0xf)); 861: } 862: 863: static int enable_gmu_stats(struct adreno_device *adreno_dev) 864: { 865: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 866: u32 data; 867: 868: if (!gmu->stats_enable) 869: return 0; 870: 871: /* 872: * Bits [23:0] contains the countables mask 873: * Bits [31:24] is the sampling interval 874: */ 875: data = FIELD_PREP(GENMASK(23, 0), gmu->stats_mask) | 876: FIELD_PREP(GENMASK(31, 24), gmu->stats_interval); 877: 878: return a6xx_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_GMU_STATS, 1, data); 879: } --- FILE: \adreno_a6xx_perfcounter.c | HITS: 3 --- MATCH LINES: 99, 111, 125 87: 88: if (!ret) 89: reg->value = 0; 90: 91: return ret; 92: } 93: 94: static int a6xx_swsched_counter_inline_enable(struct adreno_device *adreno_dev, 95: const struct adreno_perfcount_group *group, 96: unsigned int counter, unsigned int countable) 97: { 98: struct adreno_perfcount_register *reg = &group->regs[counter]; 99: struct adreno_ringbuffer *rb = &adreno_dev->ringbuffers[0]; 100: u32 cmds[3]; 101: int ret; 102: 103: if (group->flags & ADRENO_PERFCOUNTER_GROUP_RESTORE) 104: a6xx_perfcounter_update(adreno_dev, reg, false); 105: 106: cmds[0] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 107: cmds[1] = cp_type4_packet(reg->select, 1); 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: } --- FILE: \adreno_a6xx_preempt.c | HITS: 40 --- MATCH LINES: 23 11: #include "kgsl_util.h" 12: 13: #define PREEMPT_RECORD(_field) \ 14: offsetof(struct a6xx_cp_preemption_record, _field) 15: 16: #define PREEMPT_SMMU_RECORD(_field) \ 17: offsetof(struct a6xx_cp_smmu_info, _field) 18: 19: static void _update_wptr(struct adreno_device *adreno_dev, bool reset_timer, 20: bool atomic) 21: { 22: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 23: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 24: unsigned long flags; 25: int ret = 0; 26: 27: spin_lock_irqsave(&rb->preempt_lock, flags); 28: 29: if (!atomic) { 30: /* 31: * We might have skipped updating the wptr in case we are in 32: * dispatcher context. Do it now. 33: */ 34: if (rb->skip_inline_wptr) { 35: 36: ret = a6xx_fenced_write(adreno_dev, 37: A6XX_CP_RB_WPTR, rb->wptr, 38: FENCE_STATUS_WRITEDROPPED0_MASK); 39: 40: reset_timer = true; 41: rb->skip_inline_wptr = false; 42: } 43: } else { 44: unsigned int wptr; 45: 46: kgsl_regread(device, A6XX_CP_RB_WPTR, &wptr); 47: if (wptr != rb->wptr) { MATCH LINES: 108, 141, 172 96: { 97: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 98: unsigned int status; 99: 100: /* 101: * In the very unlikely case that the power is off, do nothing - the 102: * state will be reset on power up and everybody will be happy 103: */ 104: 105: if (!kgsl_state_is_awake(device)) 106: return; 107: 108: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, &status); 109: 110: if (status & 0x1) { 111: dev_err(device->dev, 112: "Preemption not complete: status=%X cur=%d R/W=%X/%X next=%d R/W=%X/%X\n", 113: status, adreno_dev->cur_rb->id, 114: adreno_get_rptr(adreno_dev->cur_rb), 115: adreno_dev->cur_rb->wptr, 116: adreno_dev->next_rb->id, 117: adreno_get_rptr(adreno_dev->next_rb), 118: adreno_dev->next_rb->wptr); 119: 120: /* Set a fault and restart */ 121: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 122: 123: return; 124: } 125: 126: adreno_dev->preempt.count++; 127: 128: /* 129: * In normal scenarios, preemption keep alive bit is cleared during 130: * CP interrupt callback. However, if preemption is successful 131: * immediately after preemption timer expires or there is a preemption 132: * interrupt with non-zero status, the state is transitioned to complete 133: * state. Once dispatcher is scheduled, it calls this function. 134: * We can now safely clear the preemption keepalive bit, allowing 135: * power collapse to resume its regular activity. 136: */ 137: _power_collapse_set(adreno_dev, false); 138: 139: kgsl_delete_timer_sync(&adreno_dev->preempt.timer); 140: 141: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 142: 143: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 144: status, 0); 145: 146: /* Clean up all the bits */ 147: adreno_dev->prev_rb = adreno_dev->cur_rb; 148: adreno_dev->cur_rb = adreno_dev->next_rb; 149: adreno_dev->next_rb = NULL; 150: 151: /* Update the wptr for the new command queue */ 152: _update_wptr(adreno_dev, true, false); 153: 154: /* Update the dispatcher timer for the new command queue */ 155: mod_timer(&adreno_dev->dispatcher.timer, 156: adreno_dev->cur_rb->dispatch_q.expires); 157: 158: /* Clear the preempt state */ 159: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 160: } 161: 162: static void _a6xx_preemption_fault(struct adreno_device *adreno_dev) 163: { 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: { MATCH LINES: 212, 213, 216, 220, 238, 249, 250, 253, 254, 259 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: } 211: 212: /* Find the highest priority active ringbuffer */ 213: static struct adreno_ringbuffer *a6xx_next_ringbuffer( 214: struct adreno_device *adreno_dev) 215: { 216: struct adreno_ringbuffer *rb; 217: unsigned long flags; 218: unsigned int i; 219: 220: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 221: bool empty; 222: 223: spin_lock_irqsave(&rb->preempt_lock, flags); 224: empty = adreno_rb_empty(rb); 225: spin_unlock_irqrestore(&rb->preempt_lock, flags); 226: 227: if (!empty) 228: return rb; 229: } 230: 231: return NULL; 232: } 233: 234: void a6xx_preemption_trigger(struct adreno_device *adreno_dev, bool atomic) 235: { 236: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 237: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 238: struct adreno_ringbuffer *next; 239: uint64_t ttbr0, gpuaddr; 240: unsigned int contextidr, cntl; 241: unsigned long flags; 242: struct adreno_preemption *preempt = &adreno_dev->preempt; 243: 244: /* Put ourselves into a possible trigger state */ 245: if (!adreno_move_preempt_state(adreno_dev, 246: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START)) 247: return; 248: 249: /* Get the next ringbuffer to preempt in */ 250: next = a6xx_next_ringbuffer(adreno_dev); 251: 252: /* 253: * Nothing to do if every ringbuffer is empty or if the current 254: * ringbuffer is the only active one 255: */ 256: if (next == NULL || next == adreno_dev->cur_rb) { 257: /* 258: * Update any critical things that might have been skipped while 259: * we were looking for a new ringbuffer 260: */ 261: 262: if (next != NULL) { 263: _update_wptr(adreno_dev, false, atomic); 264: 265: mod_timer(&adreno_dev->dispatcher.timer, 266: adreno_dev->cur_rb->dispatch_q.expires); 267: } 268: 269: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 270: return; 271: } 272: 273: /* Turn off the dispatcher timer */ 274: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 275: 276: /* 277: * This is the most critical section - we need to take care not to race 278: * until we have programmed the CP for the switch 279: */ 280: 281: spin_lock_irqsave(&next->preempt_lock, flags); 282: 283: /* Get the pagetable from the pagetable info. */ MATCH LINES: 326, 344, 351, 357, 364, 370, 397, 429, 457 314: * It is more efficient to use a keepalive+wake-on-fence approach here 315: * rather than an OOB. Both keepalive and the fence are effectively 316: * free when the GPU is already powered on, whereas an OOB requires an 317: * unconditional handshake with the GMU. 318: */ 319: _power_collapse_set(adreno_dev, true); 320: 321: /* 322: * Fenced writes on this path will make sure the GPU is woken up 323: * in case it was power collapsed by the GMU. 324: */ 325: if (a6xx_fenced_write(adreno_dev, 326: A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO, 327: lower_32_bits(next->preemption_desc->gpuaddr), 328: FENCE_STATUS_WRITEDROPPED1_MASK)) 329: goto err; 330: 331: /* 332: * Above fence writes will make sure GMU comes out of 333: * IFPC state if its was in IFPC state but it doesn't 334: * guarantee that GMU FW actually moved to ACTIVE state 335: * i.e. wake-up from IFPC is complete. 336: * Wait for GMU to move to ACTIVE state before triggering 337: * preemption. This is require to make sure CP doesn't 338: * interrupt GMU during wake-up from IFPC. 339: */ 340: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 341: goto err; 342: 343: if (a6xx_fenced_write(adreno_dev, 344: A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI, 345: upper_32_bits(next->preemption_desc->gpuaddr), 346: FENCE_STATUS_WRITEDROPPED1_MASK)) 347: goto err; 348: 349: if (kgsl_mmu_is_secured(&device->mmu)) { 350: if (a6xx_fenced_write(adreno_dev, 351: A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO, 352: lower_32_bits(next->secure_preemption_desc->gpuaddr), 353: FENCE_STATUS_WRITEDROPPED1_MASK)) 354: goto err; 355: 356: if (a6xx_fenced_write(adreno_dev, 357: A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI, 358: upper_32_bits(next->secure_preemption_desc->gpuaddr), 359: FENCE_STATUS_WRITEDROPPED1_MASK)) 360: goto err; 361: } 362: 363: if (a6xx_fenced_write(adreno_dev, 364: A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO, 365: lower_32_bits(gpuaddr), 366: FENCE_STATUS_WRITEDROPPED1_MASK)) 367: goto err; 368: 369: if (a6xx_fenced_write(adreno_dev, 370: A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI, 371: upper_32_bits(gpuaddr), 372: FENCE_STATUS_WRITEDROPPED1_MASK)) 373: goto err; 374: 375: adreno_dev->next_rb = next; 376: 377: /* Start the timer to detect a stuck preemption */ 378: mod_timer(&adreno_dev->preempt.timer, 379: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 380: 381: cntl = (preempt->preempt_level << 6) | 0x01; 382: 383: /* Skip save/restore during L1 preemption */ 384: if (preempt->skipsaverestore) 385: cntl |= (1 << 9); 386: 387: /* Enable GMEM save/restore across preemption */ 388: if (preempt->usesgmem) 389: cntl |= (1 << 8); 390: 391: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 392: cntl, 0); 393: 394: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 395: 396: /* Trigger the preemption */ 397: if (a6xx_fenced_write(adreno_dev, A6XX_CP_CONTEXT_SWITCH_CNTL, cntl, 398: FENCE_STATUS_WRITEDROPPED1_MASK)) { 399: adreno_dev->next_rb = NULL; 400: kgsl_delete_timer(&adreno_dev->preempt.timer); 401: goto err; 402: } 403: 404: return; 405: err: 406: /* If fenced write fails, take inline snapshot and trigger recovery */ 407: if (!atomic) { 408: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 409: adreno_scheduler_fault(adreno_dev, 410: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 411: } else { 412: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 413: } 414: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 415: /* Clear the keep alive */ 416: _power_collapse_set(adreno_dev, false); 417: 418: } 419: 420: void a6xx_preemption_callback(struct adreno_device *adreno_dev, int bit) 421: { 422: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 423: unsigned int status; 424: 425: if (!adreno_move_preempt_state(adreno_dev, 426: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 427: return; 428: 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); 476: } 477: 478: void a6xx_preemption_schedule(struct adreno_device *adreno_dev) 479: { 480: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 481: MATCH LINES: 496 484: 485: kgsl_mutex_lock(&device->mutex); 486: 487: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE)) 488: _a6xx_preemption_done(adreno_dev); 489: 490: a6xx_preemption_trigger(adreno_dev, false); 491: 492: kgsl_mutex_unlock(&device->mutex); 493: } 494: 495: u32 a6xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 496: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 497: u32 *cmds) 498: { 499: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 500: u32 count = kgsl_mmu_is_secured(&device->mmu) ? 12 : 9; 501: unsigned int *cmds_orig = cmds; 502: uint64_t gpuaddr = 0; 503: 504: if (!adreno_is_preemption_enabled(adreno_dev)) 505: return 0; 506: 507: if (drawctxt && drawctxt->base.user_ctxt_record) 508: gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 509: 510: if (gpuaddr) 511: count += 3; 512: 513: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, count); 514: /* NULL SMMU_INFO buffer - we track in KMD */ 515: *cmds++ = SET_PSEUDO_SMMU_INFO; 516: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 517: 518: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 519: cmds += cp_gpuaddr(adreno_dev, cmds, rb->preemption_desc->gpuaddr); 520: MATCH LINES: 537, 567, 574, 587, 609, 612, 616, 622, 628, 649, 654, 659, 660 525: } 526: 527: if (gpuaddr) { 528: *cmds++ = SET_PSEUDO_NON_PRIV_SAVE_ADDR; 529: cmds += cp_gpuaddr(adreno_dev, cmds, gpuaddr); 530: } 531: 532: /* 533: * There is no need to specify this address when we are about to 534: * trigger preemption. This is because CP internally stores this 535: * address specified here in the CP_SET_PSEUDO_REGISTER payload to 536: * the context record and thus knows from where to restore 537: * the saved perfcounters for the new ringbuffer. 538: */ 539: *cmds++ = SET_PSEUDO_COUNTER; 540: cmds += cp_gpuaddr(adreno_dev, cmds, 541: rb->perfcounter_save_restore_desc->gpuaddr); 542: 543: if (!drawctxt) 544: goto done; 545: 546: cmds += adreno_prepare_preib_preempt_scratch(adreno_dev, drawctxt, cmds); 547: 548: /* Add a KMD post amble to clear the perf counters during preemption */ 549: if (!adreno_dev->perfcounter) 550: cmds += adreno_prepare_preib_postamble_scratch(adreno_dev, cmds); 551: 552: done: 553: return (u32) (cmds - cmds_orig); 554: } 555: 556: u32 a6xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 557: u32 *cmds) 558: { 559: u32 index = 0; 560: 561: if (!adreno_is_preemption_enabled(adreno_dev)) 562: return 0; 563: 564: if (adreno_dev->cur_rb) { 565: u64 dest = PREEMPT_SCRATCH_ADDR(adreno_dev, adreno_dev->cur_rb->id); 566: 567: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 4); 568: cmds[index++] = lower_32_bits(dest); 569: cmds[index++] = upper_32_bits(dest); 570: cmds[index++] = 0; 571: cmds[index++] = 0; 572: } 573: 574: cmds[index++] = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 575: cmds[index++] = 0; 576: cmds[index++] = 0; 577: cmds[index++] = 1; 578: cmds[index++] = 0; 579: 580: return index; 581: } 582: 583: void a6xx_preemption_start(struct adreno_device *adreno_dev) 584: { 585: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 586: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 587: struct adreno_ringbuffer *rb; 588: unsigned int i; 589: 590: if (!adreno_is_preemption_enabled(adreno_dev)) 591: return; 592: 593: /* Force the state to be clear */ 594: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 595: 596: if (kgsl_mmu_is_perprocess(&device->mmu)) { 597: /* smmu_info is allocated and mapped in a6xx_preemption_iommu_init */ 598: kgsl_sharedmem_writel(iommu->smmu_info, 599: PREEMPT_SMMU_RECORD(magic), A6XX_CP_SMMU_INFO_MAGIC_REF); 600: kgsl_sharedmem_writeq(iommu->smmu_info, 601: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 602: 603: /* The CP doesn't use the asid record, so poison it */ 604: kgsl_sharedmem_writel(iommu->smmu_info, 605: PREEMPT_SMMU_RECORD(asid), 0xDECAFBAD); 606: kgsl_sharedmem_writel(iommu->smmu_info, 607: PREEMPT_SMMU_RECORD(context_idr), 0); 608: 609: kgsl_regwrite(device, A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 610: lower_32_bits(iommu->smmu_info->gpuaddr)); 611: 612: kgsl_regwrite(device, A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 613: upper_32_bits(iommu->smmu_info->gpuaddr)); 614: } 615: 616: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 617: kgsl_sharedmem_writel(rb->preemption_desc, 618: PREEMPT_RECORD(rptr), 0); 619: kgsl_sharedmem_writel(rb->preemption_desc, 620: PREEMPT_RECORD(wptr), 0); 621: 622: adreno_ringbuffer_set_pagetable(device, rb, 623: device->mmu.defaultpagetable); 624: } 625: } 626: 627: static void reset_rb_preempt_record(struct adreno_device *adreno_dev, 628: struct adreno_ringbuffer *rb) 629: { 630: u32 cp_rb_cntl = A6XX_CP_RB_CNTL_DEFAULT | 631: (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? 0 : (1 << 27)); 632: 633: memset(rb->preemption_desc->hostptr, 0x0, rb->preemption_desc->size); 634: 635: kgsl_sharedmem_writel(rb->preemption_desc, 636: PREEMPT_RECORD(magic), A6XX_CP_CTXRECORD_MAGIC_REF); 637: kgsl_sharedmem_writel(rb->preemption_desc, 638: PREEMPT_RECORD(cntl), cp_rb_cntl); 639: kgsl_sharedmem_writeq(rb->preemption_desc, 640: PREEMPT_RECORD(rptr_addr), SCRATCH_RB_GPU_ADDR( 641: KGSL_DEVICE(adreno_dev), rb->id, rptr)); 642: kgsl_sharedmem_writeq(rb->preemption_desc, 643: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 644: } 645: 646: void a6xx_reset_preempt_records(struct adreno_device *adreno_dev) 647: { 648: int i; 649: struct adreno_ringbuffer *rb; 650: 651: if (!adreno_is_preemption_enabled(adreno_dev)) 652: return; 653: 654: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 655: reset_rb_preempt_record(adreno_dev, rb); 656: } 657: } 658: 659: static int a6xx_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 660: struct adreno_ringbuffer *rb) 661: { 662: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 663: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev); 664: u64 ctxt_record_size = A6XX_CP_CTXRECORD_SIZE_IN_BYTES; 665: int ret; 666: 667: if (a6xx_core->ctxt_record_size) 668: ctxt_record_size = a6xx_core->ctxt_record_size; 669: 670: ret = adreno_allocate_global(device, &rb->preemption_desc, 671: ctxt_record_size, SZ_16K, 0, KGSL_MEMDESC_PRIVILEGED, 672: "preemption_desc"); 673: if (ret) 674: return ret; 675: 676: if (kgsl_mmu_is_secured(&device->mmu)) { 677: ret = adreno_allocate_global(device, &rb->secure_preemption_desc, 678: ctxt_record_size, 0, KGSL_MEMFLAGS_SECURE, 679: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 680: if (ret) 681: return ret; 682: } 683: 684: ret = adreno_allocate_global(device, &rb->perfcounter_save_restore_desc, MATCH LINES: 702, 713, 714 690: 691: reset_rb_preempt_record(adreno_dev, rb); 692: 693: return 0; 694: } 695: 696: int a6xx_preemption_init(struct adreno_device *adreno_dev) 697: { 698: u32 flags = ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? KGSL_MEMDESC_PRIVILEGED : 0; 699: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 700: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 701: struct adreno_preemption *preempt = &adreno_dev->preempt; 702: struct adreno_ringbuffer *rb; 703: int ret; 704: unsigned int i; 705: 706: /* We are dependent on IOMMU to make preemption go on the CP side */ 707: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) 708: return -ENODEV; 709: 710: INIT_WORK(&preempt->work, _a6xx_preemption_worker); 711: 712: /* Allocate mem for storing preemption switch record */ 713: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 714: ret = a6xx_preemption_ringbuffer_init(adreno_dev, rb); 715: if (ret) 716: return ret; 717: } 718: 719: ret = adreno_allocate_global(device, &preempt->scratch, 720: PAGE_SIZE, 0, 0, flags, "preempt_scratch"); 721: if (ret) 722: return ret; 723: 724: /* Allocate mem for storing preemption smmu record */ 725: if (kgsl_mmu_is_perprocess(&device->mmu)) { 726: ret = adreno_allocate_global(device, &iommu->smmu_info, PAGE_SIZE, 0, 727: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 728: "smmu_info"); 729: if (ret) 730: return ret; 731: } 732: 733: /* 734: * First 28 dwords of the device scratch buffer are used to store shadow rb data. 735: * Insert PM4 packets in device scratch buffer to clear perfcounters. This should 736: * be in *device->scratch* so that userspace cannot access it. 737: */ 738: if (!adreno_dev->perfcounter) { --- FILE: \adreno_a6xx_rgmu.c | HITS: 3 --- MATCH LINES: 328 316: return 0; 317: 318: ts3 = a6xx_read_alwayson(adreno_dev); 319: 320: /* Collect abort data to help with debugging */ 321: gmu_core_regread(device, A6XX_RGMU_CX_PCC_DEBUG, ®[1]); 322: gmu_core_regread(device, A6XX_RGMU_CX_PCC_STATUS, ®[2]); 323: gmu_core_regread(device, A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS, ®[3]); 324: kgsl_regread(device, A6XX_CP_STATUS_1, ®[4]); 325: gmu_core_regread(device, A6XX_GMU_RBBM_INT_UNMASKED_STATUS, ®[5]); 326: gmu_core_regread(device, A6XX_GMU_GMU_PWR_COL_KEEPALIVE, ®[6]); 327: kgsl_regread(device, A6XX_CP_CP2GMU_STATUS, ®[7]); 328: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, ®[8]); 329: gmu_core_regread(device, A6XX_GMU_AO_SPARE_CNTL, ®[9]); 330: 331: dev_err(&rgmu->pdev->dev, 332: "----------------------[ RGMU error ]----------------------\n"); 333: dev_err(&rgmu->pdev->dev, "Timeout waiting for lowest idle level\n"); 334: dev_err(&rgmu->pdev->dev, 335: "Timestamps: %llx %llx %llx\n", ts1, ts2, ts3); 336: dev_err(&rgmu->pdev->dev, 337: "SPTPRAC_PWR_CLK_STATUS=%x PCC_DEBUG=%x PCC_STATUS=%x\n", 338: reg[0], reg[1], reg[2]); 339: dev_err(&rgmu->pdev->dev, 340: "CX_BUSY_STATUS=%x CP_STATUS_1=%x\n", reg[3], reg[4]); 341: dev_err(&rgmu->pdev->dev, 342: "RBBM_INT_UNMASKED_STATUS=%x PWR_COL_KEEPALIVE=%x\n", 343: reg[5], reg[6]); 344: dev_err(&rgmu->pdev->dev, 345: "CP2GMU_STATUS=%x CONTEXT_SWITCH_CNTL=%x AO_SPARE_CNTL=%x\n", 346: reg[7], reg[8], reg[9]); 347: 348: WARN_ON(1); 349: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 350: return -ETIMEDOUT; 351: } 352: MATCH LINES: 990 978: { 979: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 980: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 981: int ret; 982: 983: if (test_bit(RGMU_PRIV_FIRST_BOOT_DONE, &rgmu->flags)) { 984: if (!test_bit(RGMU_PRIV_GPU_STARTED, &rgmu->flags)) 985: return a6xx_boot(adreno_dev); 986: 987: return 0; 988: } 989: 990: ret = a6xx_ringbuffer_init(adreno_dev); 991: if (ret) 992: return ret; 993: 994: ret = a6xx_microcode_read(adreno_dev); 995: if (ret) 996: return ret; 997: 998: ret = a6xx_init(adreno_dev); 999: if (ret) 1000: return ret; 1001: 1002: ret = a6xx_rgmu_load_firmware(adreno_dev); 1003: if (ret) 1004: return ret; 1005: 1006: kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE); 1007: 1008: ret = a6xx_rgmu_boot(adreno_dev); 1009: if (ret) 1010: return ret; 1011: 1012: ret = a6xx_gpu_boot(adreno_dev); 1013: if (ret) 1014: return ret; MATCH LINES: 1118 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: --- FILE: \adreno_a6xx_ringbuffer.c | HITS: 40 --- MATCH LINES: 10, 15, 38, 58, 93, 100, 107, 110, 124, 136 1: // SPDX-License-Identifier: GPL-2.0-only 2: /* 3: * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include "adreno.h" 8: #include "adreno_a6xx.h" 9: #include "adreno_pm4types.h" 10: #include "adreno_ringbuffer.h" 11: #include "adreno_trace.h" 12: #include "kgsl_trace.h" 13: 14: static int a6xx_rb_pagetable_switch(struct adreno_device *adreno_dev, 15: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 16: struct kgsl_pagetable *pagetable, u32 *cmds) 17: { 18: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 19: u64 ttbr0 = kgsl_mmu_pagetable_get_ttbr0(pagetable); 20: int count = 0; 21: u32 id = drawctxt ? drawctxt->base.id : 0; 22: 23: if (pagetable == device->mmu.defaultpagetable) 24: return 0; 25: 26: cmds[count++] = cp_type7_packet(CP_SMMU_TABLE_UPDATE, 3); 27: cmds[count++] = lower_32_bits(ttbr0); 28: cmds[count++] = upper_32_bits(ttbr0); 29: cmds[count++] = id; 30: 31: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) { 32: cmds[count++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 33: cmds[count++] = cp_type7_packet(CP_WAIT_FOR_ME, 0); 34: cmds[count++] = cp_type4_packet(A6XX_CP_MISC_CNTL, 1); 35: cmds[count++] = 1; 36: } 37: 38: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 5); 39: cmds[count++] = lower_32_bits(SCRATCH_RB_GPU_ADDR(device, 40: rb->id, ttbr0)); 41: cmds[count++] = upper_32_bits(SCRATCH_RB_GPU_ADDR(device, 42: rb->id, ttbr0)); 43: cmds[count++] = lower_32_bits(ttbr0); 44: cmds[count++] = upper_32_bits(ttbr0); 45: cmds[count++] = id; 46: 47: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) { 48: cmds[count++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 49: cmds[count++] = cp_type7_packet(CP_WAIT_FOR_ME, 0); 50: cmds[count++] = cp_type4_packet(A6XX_CP_MISC_CNTL, 1); 51: cmds[count++] = 0; 52: } 53: 54: return count; 55: } 56: 57: static int a6xx_rb_context_switch(struct adreno_device *adreno_dev, 58: struct adreno_ringbuffer *rb, 59: struct adreno_context *drawctxt) 60: { 61: struct kgsl_pagetable *pagetable = 62: adreno_drawctxt_get_pagetable(drawctxt); 63: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 64: int count = 0; 65: u32 cmds[41]; 66: 67: if (adreno_drawctxt_get_pagetable(rb->drawctxt_active) != pagetable) { 68: 69: /* Clear performance counters during context switches */ 70: if (!adreno_dev->perfcounter) { 71: cmds[count++] = cp_type4_packet(A6XX_RBBM_PERFCTR_SRAM_INIT_CMD, 1); 72: cmds[count++] = 0x1; 73: } 74: 75: count += a6xx_rb_pagetable_switch(adreno_dev, rb, drawctxt, 76: pagetable, &cmds[count]); 77: 78: /* Wait for performance counter clear to finish */ 79: if (!adreno_dev->perfcounter) { 80: cmds[count++] = cp_type7_packet(CP_WAIT_REG_MEM, 6); 81: cmds[count++] = 0x3; 82: cmds[count++] = A6XX_RBBM_PERFCTR_SRAM_INIT_STATUS; 83: cmds[count++] = 0x0; 84: cmds[count++] = 0x1; 85: cmds[count++] = 0x1; 86: cmds[count++] = 0x0; 87: } 88: } 89: 90: cmds[count++] = cp_type7_packet(CP_NOP, 1); 91: cmds[count++] = CONTEXT_TO_MEM_IDENTIFIER; 92: 93: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 94: cmds[count++] = lower_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb, 95: current_context)); 96: cmds[count++] = upper_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb, 97: current_context)); 98: cmds[count++] = drawctxt->base.id; 99: 100: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 101: cmds[count++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 102: KGSL_MEMSTORE_GLOBAL, current_context)); 103: cmds[count++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 104: KGSL_MEMSTORE_GLOBAL, current_context)); 105: cmds[count++] = drawctxt->base.id; 106: 107: cmds[count++] = cp_type7_packet(CP_EVENT_WRITE, 1); 108: cmds[count++] = 0x31; 109: 110: return a6xx_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED, 111: cmds, count, 0, NULL); 112: } 113: 114: #define RB_SOPTIMESTAMP(device, rb) \ 115: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 116: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 117: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 118: 119: #define RB_EOPTIMESTAMP(device, rb) \ 120: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 121: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 122: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 123: 124: int a6xx_ringbuffer_submit(struct adreno_ringbuffer *rb, 125: struct adreno_submit_time *time, bool sync) 126: { 127: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 128: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 129: int ret = 0; 130: unsigned long flags; 131: 132: adreno_get_submit_time(adreno_dev, rb, time); 133: adreno_profile_submit_time(time); 134: 135: if (sync && !ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) { 136: u32 *cmds = adreno_ringbuffer_allocspace(rb, 3); 137: 138: if (IS_ERR(cmds)) 139: return PTR_ERR(cmds); 140: 141: cmds[0] = cp_type7_packet(CP_WHERE_AM_I, 2); 142: cmds[1] = lower_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id, 143: rptr)); 144: cmds[2] = upper_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id, 145: rptr)); 146: } 147: 148: spin_lock_irqsave(&rb->preempt_lock, flags); 149: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 150: if (adreno_dev->cur_rb == rb) { 151: ret = a6xx_fenced_write(adreno_dev, 152: A6XX_CP_RB_WPTR, rb->_wptr, 153: FENCE_STATUS_WRITEDROPPED0_MASK); 154: rb->skip_inline_wptr = false; 155: } 156: } else { 157: if (adreno_dev->cur_rb == rb) 158: rb->skip_inline_wptr = true; 159: } 160: MATCH LINES: 177, 188, 191, 192, 193, 196, 198, 201, 202, 214, 215, 243, 262, 269, 277, 304, 314, 318, 324, 332, 356, 383, 398, 409 165: /* 166: * If WPTR update fails, take inline snapshot and trigger 167: * recovery. 168: */ 169: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 170: adreno_scheduler_fault(adreno_dev, 171: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 172: } 173: 174: return ret; 175: } 176: 177: int a6xx_ringbuffer_init(struct adreno_device *adreno_dev) 178: { 179: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 180: int i, ret; 181: 182: ret = adreno_allocate_global(device, &device->scratch, PAGE_SIZE, 183: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED, 184: "scratch"); 185: if (ret) 186: return ret; 187: 188: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]); 189: 190: if (!adreno_preemption_feature_set(adreno_dev)) { 191: adreno_dev->num_ringbuffers = 1; 192: return adreno_ringbuffer_setup(adreno_dev, 193: &adreno_dev->ringbuffers[0], 0); 194: } 195: 196: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers); 197: 198: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 199: int ret; 200: 201: ret = adreno_ringbuffer_setup(adreno_dev, 202: &adreno_dev->ringbuffers[i], i); 203: if (ret) 204: return ret; 205: } 206: 207: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 208: a6xx_preemption_init(adreno_dev); 209: return 0; 210: } 211: 212: #define A6XX_SUBMIT_MAX 79 213: 214: int a6xx_ringbuffer_addcmds(struct adreno_device *adreno_dev, 215: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 216: u32 flags, u32 *in, u32 dwords, u32 timestamp, 217: struct adreno_submit_time *time) 218: { 219: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 220: u32 size = A6XX_SUBMIT_MAX + dwords; 221: u32 *cmds, index = 0; 222: u64 profile_gpuaddr; 223: u32 profile_dwords; 224: 225: if (adreno_drawctxt_detached(drawctxt)) 226: return -ENOENT; 227: 228: if (adreno_gpu_fault(adreno_dev) != 0) 229: return -EPROTO; 230: 231: rb->timestamp++; 232: 233: if (drawctxt) 234: drawctxt->internal_timestamp = rb->timestamp; 235: 236: /* 237: * if APRIV is enabled we assume all submissions are run with protected 238: * mode off 239: */ 240: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 241: flags &= ~F_NOTPROTECTED; 242: 243: cmds = adreno_ringbuffer_allocspace(rb, size); 244: if (IS_ERR(cmds)) 245: return PTR_ERR(cmds); 246: 247: /* Identify the start of a command */ 248: cmds[index++] = cp_type7_packet(CP_NOP, 1); 249: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 250: 251: /* This is 25 dwords when drawctxt is not NULL and perfcounter needs to be zapped */ 252: index += a6xx_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 253: &cmds[index]); 254: 255: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 256: cmds[index++] = 0x101; /* IFPC disable */ 257: 258: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 259: drawctxt, &profile_dwords); 260: 261: if (profile_gpuaddr) { 262: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 263: cmds[index++] = lower_32_bits(profile_gpuaddr); 264: cmds[index++] = upper_32_bits(profile_gpuaddr); 265: cmds[index++] = profile_dwords; 266: } 267: 268: if (drawctxt) { 269: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 270: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 271: drawctxt)); 272: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 273: drawctxt)); 274: cmds[index++] = timestamp; 275: } 276: 277: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 278: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 279: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); 280: cmds[index++] = rb->timestamp; 281: 282: if (IS_SECURE(flags)) { 283: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 284: cmds[index++] = 1; 285: } 286: 287: if (IS_NOTPROTECTED(flags)) { 288: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1); 289: cmds[index++] = 0; 290: } 291: 292: memcpy(&cmds[index], in, dwords << 2); 293: index += dwords; 294: 295: if (IS_NOTPROTECTED(flags)) { 296: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1); 297: cmds[index++] = 1; 298: } 299: 300: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev, 301: drawctxt, &dwords); 302: 303: if (profile_gpuaddr) { 304: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 305: cmds[index++] = lower_32_bits(profile_gpuaddr); 306: cmds[index++] = upper_32_bits(profile_gpuaddr); 307: cmds[index++] = profile_dwords; 308: } 309: 310: if (test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &device->mmu.pfpolicy)) 311: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0); 312: 313: /* 314: * If this is an internal command, just write the ringbuffer timestamp, 315: * otherwise, write both 316: */ 317: if (!drawctxt) { 318: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 319: cmds[index++] = CACHE_FLUSH_TS | (1 << 31); 320: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 321: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 322: cmds[index++] = rb->timestamp; 323: } else { 324: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 325: cmds[index++] = CACHE_FLUSH_TS | (1 << 31); 326: cmds[index++] = lower_32_bits(CTXT_EOPTIMESTAMP(device, 327: drawctxt)); 328: cmds[index++] = upper_32_bits(CTXT_EOPTIMESTAMP(device, 329: drawctxt)); 330: cmds[index++] = timestamp; 331: 332: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 333: cmds[index++] = CACHE_FLUSH_TS; 334: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 335: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 336: cmds[index++] = rb->timestamp; 337: } 338: 339: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 340: cmds[index++] = 0x100; /* IFPC enable */ 341: 342: if (IS_WFI(flags)) 343: cmds[index++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 344: 345: if (IS_SECURE(flags)) { 346: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 347: cmds[index++] = 0; 348: } 349: 350: /* 10 dwords */ 351: index += a6xx_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 352: 353: /* Adjust the thing for the number of dwords we actually wrote */ 354: rb->_wptr -= (size - index); 355: 356: return a6xx_ringbuffer_submit(rb, time, 357: !adreno_is_preemption_enabled(adreno_dev)); 358: } 359: 360: static u32 a6xx_get_alwayson_counter(u32 *cmds, u64 gpuaddr) 361: { 362: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 363: cmds[1] = A6XX_CP_ALWAYS_ON_COUNTER_LO | (1 << 30) | (2 << 18); 364: cmds[2] = lower_32_bits(gpuaddr); 365: cmds[3] = upper_32_bits(gpuaddr); 366: 367: return 4; 368: } 369: 370: static u32 a6xx_get_alwayson_context(u32 *cmds, u64 gpuaddr) 371: { 372: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 373: cmds[1] = A6XX_CP_ALWAYS_ON_CONTEXT_LO | (1 << 30) | (2 << 18); 374: cmds[2] = lower_32_bits(gpuaddr); 375: cmds[3] = upper_32_bits(gpuaddr); 376: 377: return 4; 378: } 379: 380: #define PROFILE_IB_DWORDS 4 381: #define PROFILE_IB_SLOTS (PAGE_SIZE / (PROFILE_IB_DWORDS << 2)) 382: 383: static u64 a6xx_get_user_profiling_ib(struct adreno_ringbuffer *rb, 384: struct kgsl_drawobj_cmd *cmdobj, u32 target_offset, u32 *cmds) 385: { 386: u32 offset, *ib, dwords; 387: u64 gpuaddr; 388: 389: if (IS_ERR(rb->profile_desc)) 390: return 0; 391: 392: offset = rb->profile_index * (PROFILE_IB_DWORDS << 2); 393: ib = rb->profile_desc->hostptr + offset; 394: gpuaddr = rb->profile_desc->gpuaddr + offset; 395: dwords = a6xx_get_alwayson_counter(ib, 396: cmdobj->profiling_buffer_gpuaddr + target_offset); 397: 398: cmds[0] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 399: cmds[1] = lower_32_bits(gpuaddr); 400: cmds[2] = upper_32_bits(gpuaddr); 401: cmds[3] = dwords; 402: 403: rb->profile_index = (rb->profile_index + 1) % PROFILE_IB_SLOTS; 404: 405: return 4; 406: } 407: 408: static int a6xx_drawctxt_switch(struct adreno_device *adreno_dev, 409: struct adreno_ringbuffer *rb, 410: struct adreno_context *drawctxt) 411: { 412: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 413: int ret; 414: 415: if (rb->drawctxt_active == drawctxt) 416: return 0; 417: 418: if (kgsl_context_detached(&drawctxt->base)) 419: return -ENOENT; 420: 421: if (!_kgsl_context_get(&drawctxt->base)) 422: return -ENOENT; 423: 424: ret = a6xx_rb_context_switch(adreno_dev, rb, drawctxt); 425: if (ret) { 426: kgsl_context_put(&drawctxt->base); 427: return ret; 428: } 429: 430: trace_adreno_drawctxt_switch(rb, drawctxt); 431: 432: /* Release the current drawctxt as soon as the new one is switched */ 433: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active, MATCH LINES: 459, 466 447: (dev)->profile_buffer->gpuaddr + \ 448: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 449: field)) 450: 451: #define A6XX_KERNEL_PROFILE_CONTEXT(dev, cmdobj, cmds, field) \ 452: a6xx_get_alwayson_context((cmds), \ 453: (dev)->profile_buffer->gpuaddr + \ 454: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 455: field)) 456: 457: #define A6XX_COMMAND_DWORDS 40 458: 459: int a6xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 460: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 461: struct adreno_submit_time *time) 462: { 463: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 464: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 465: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 466: struct adreno_ringbuffer *rb = drawctxt->rb; 467: int ret = 0, numibs = 0, index = 0; 468: u32 *cmds; 469: 470: /* Count the number of IBs (if we are not skipping) */ 471: if (!IS_SKIP(flags)) { 472: struct list_head *tmp; 473: 474: list_for_each(tmp, &cmdobj->cmdlist) 475: numibs++; 476: } 477: 478: cmds = kvmalloc((A6XX_COMMAND_DWORDS + (numibs * 5)) << 2, GFP_KERNEL); 479: if (!cmds) { 480: ret = -ENOMEM; 481: goto done; 482: } 483: 484: cmds[index++] = cp_type7_packet(CP_NOP, 1); 485: cmds[index++] = START_IB_IDENTIFIER; 486: 487: /* Kernel profiling: 8 dwords */ 488: if (IS_KERNEL_PROFILE(flags)) { 489: index += A6XX_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index], 490: started); MATCH LINES: 513, 526, 529 501: struct kgsl_memobj_node *ib; 502: 503: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 504: cmds[index++] = 0x00d; /* IB1LIST start */ 505: 506: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 507: if (ib->priv & MEMOBJ_SKIP || 508: (ib->flags & KGSL_CMDLIST_CTXTSWITCH_PREAMBLE 509: && !IS_PREAMBLE(flags))) 510: cmds[index++] = cp_type7_packet(CP_NOP, 4); 511: 512: cmds[index++] = 513: cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 514: cmds[index++] = lower_32_bits(ib->gpuaddr); 515: cmds[index++] = upper_32_bits(ib->gpuaddr); 516: 517: /* Double check that IB_PRIV is never set */ 518: cmds[index++] = (ib->size >> 2) & 0xfffff; 519: } 520: 521: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 522: cmds[index++] = 0x00e; /* IB1LIST end */ 523: } 524: 525: /* CCU invalidate */ 526: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1); 527: cmds[index++] = 24; 528: 529: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1); 530: cmds[index++] = 25; 531: 532: /* 8 dwords */ 533: if (IS_KERNEL_PROFILE(flags)) { 534: index += A6XX_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index], 535: retired); 536: index += A6XX_KERNEL_PROFILE_CONTEXT(adreno_dev, cmdobj, &cmds[index], 537: ctx_end); 538: } 539: 540: /* 4 dwords */ 541: if (IS_USER_PROFILE(flags)) 542: index += A6XX_USER_PROFILE_IB(rb, cmdobj, &cmds[index], 543: gpu_ticks_retired); 544: 545: cmds[index++] = cp_type7_packet(CP_NOP, 1); 546: cmds[index++] = END_IB_IDENTIFIER; 547: 548: ret = a6xx_drawctxt_switch(adreno_dev, rb, drawctxt); 549: 550: /* 551: * In the unlikely event of an error in the drawctxt switch, 552: * treat it like a hang 553: */ MATCH LINES: 568 556: * It is "normal" to get a -ENOSPC or a -ENOENT. Don't log it, 557: * the upper layers know how to handle it 558: */ 559: if (ret != -ENOSPC && ret != -ENOENT) 560: dev_err(device->dev, 561: "Unable to switch draw context: %d\n", 562: ret); 563: goto done; 564: } 565: 566: adreno_drawobj_set_constraint(device, drawobj); 567: 568: ret = a6xx_ringbuffer_addcmds(adreno_dev, drawctxt->rb, drawctxt, 569: flags, cmds, index, drawobj->timestamp, time); 570: 571: done: 572: trace_kgsl_issueibcmds(device, drawctxt->base.id, numibs, 573: drawobj->timestamp, drawobj->flags, ret, drawctxt->type); 574: 575: kvfree(cmds); 576: return ret; 577: } --- FILE: \adreno_dispatch.c | HITS: 47 --- MATCH LINES: 39, 60, 62, 64, 77, 112 27: static unsigned int _context_drawobj_burst = 5; 28: 29: /* 30: * GFT throttle parameters. If GFT recovered more than 31: * X times in Y ms invalidate the context and do not attempt recovery. 32: * X -> _fault_throttle_burst 33: * Y -> _fault_throttle_time 34: */ 35: static unsigned int _fault_throttle_time = 3000; 36: static unsigned int _fault_throttle_burst = 3; 37: 38: /* 39: * Maximum ringbuffer inflight for the single submitting context case - this 40: * should be sufficiently high to keep the GPU loaded 41: */ 42: static unsigned int _dispatcher_q_inflight_hi = 15; 43: 44: /* 45: * Minimum inflight for the multiple context case - this should sufficiently low 46: * to allow for lower latency context switching 47: */ 48: static unsigned int _dispatcher_q_inflight_lo = 4; 49: 50: /* Command batch timeout (in milliseconds) */ 51: unsigned int adreno_drawobj_timeout = 2000; 52: 53: /* Interval for reading and comparing fault detection registers */ 54: static unsigned int _fault_timer_interval = 200; 55: 56: /* Use a kmem cache to speed up allocations for dispatcher jobs */ 57: static struct kmem_cache *jobs_cache; 58: 59: #define DRAWQUEUE_RB(_drawqueue) \ 60: ((struct adreno_ringbuffer *) \ 61: container_of((_drawqueue),\ 62: struct adreno_ringbuffer, dispatch_q)) 63: 64: #define DRAWQUEUE(_ringbuffer) (&(_ringbuffer)->dispatch_q) 65: 66: static bool adreno_drawqueue_is_empty(struct adreno_dispatcher_drawqueue *drawqueue) 67: { 68: return (drawqueue && drawqueue->head == drawqueue->tail); 69: } 70: 71: static int adreno_dispatch_retire_drawqueue(struct adreno_device *adreno_dev, 72: struct adreno_dispatcher_drawqueue *drawqueue); 73: 74: static inline bool drawqueue_is_current( 75: struct adreno_dispatcher_drawqueue *drawqueue) 76: { 77: struct adreno_ringbuffer *rb = DRAWQUEUE_RB(drawqueue); 78: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 79: 80: return (adreno_dev->cur_rb == rb); 81: } 82: 83: /* 84: * If only one context has queued in the last 100 milliseconds increase 85: * inflight to a high number to load up the GPU. If multiple contexts 86: * have queued drop the inflight for better context switch latency. 87: * If no contexts have queued what are you even doing here? 88: */ 89: 90: static inline int 91: _drawqueue_inflight(struct adreno_dispatcher_drawqueue *drawqueue) 92: { 93: return (drawqueue->active_context_count > 1) 94: ? _dispatcher_q_inflight_lo : _dispatcher_q_inflight_hi; 95: } 96: 97: /** 98: * _retire_timestamp() - Retire object without sending it 99: * to the hardware 100: * @drawobj: Pointer to the object to retire 101: * 102: * In some cases ibs can be retired by the software 103: * without going to the GPU. In those cases, update the 104: * memstore from the CPU, kick off the event engine to handle 105: * expired events and destroy the ib. 106: */ 107: static void _retire_timestamp(struct kgsl_drawobj *drawobj) 108: { 109: struct kgsl_context *context = drawobj->context; 110: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 111: struct kgsl_device *device = context->device; 112: struct adreno_ringbuffer *rb = drawctxt->rb; 113: struct retire_info info = {0}; 114: 115: /* 116: * Write the start and end timestamp to the memstore to keep the 117: * accounting sane 118: */ 119: kgsl_sharedmem_writel(device->memstore, 120: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 121: drawobj->timestamp); 122: 123: kgsl_sharedmem_writel(device->memstore, 124: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 125: drawobj->timestamp); 126: 127: drawctxt->submitted_timestamp = drawobj->timestamp; 128: 129: /* Retire pending GPU events for the object */ 130: kgsl_process_event_group(device, &context->events); 131: 132: info.inflight = -1; 133: info.rb_id = rb->id; 134: info.wptr = rb->wptr; 135: info.timestamp = drawobj->timestamp; 136: MATCH LINES: 281 269: _kgsl_context_get(&drawctxt->base); 270: kref_get(&drawobj->refcount); 271: 272: kgsl_sharedmem_bind_ranges(bindobj->bind); 273: } 274: 275: return -EAGAIN; 276: } 277: 278: /* 279: * Retires all expired marker and sync objs from the context 280: * queue and returns one of the below 281: * a) next drawobj that needs to be sent to ringbuffer 282: * b) -EAGAIN for syncobj with syncpoints pending. 283: * c) -EAGAIN for markerobj whose marker timestamp has not expired yet. 284: * c) NULL for no commands remaining in drawqueue. 285: */ 286: static struct kgsl_drawobj *_process_drawqueue_get_next_drawobj( 287: struct adreno_context *drawctxt) 288: { 289: struct kgsl_drawobj *drawobj; 290: unsigned int i = drawctxt->drawqueue_head; 291: 292: if (drawctxt->drawqueue_head == drawctxt->drawqueue_tail) 293: return NULL; 294: 295: for (i = drawctxt->drawqueue_head; i != drawctxt->drawqueue_tail; 296: i = DRAWQUEUE_NEXT(i, ADRENO_CONTEXT_DRAWQUEUE_SIZE)) { 297: int ret = 0; 298: 299: drawobj = drawctxt->drawqueue[i]; 300: if (!drawobj) 301: return NULL; 302: 303: switch (drawobj->type) { 304: case CMDOBJ_TYPE: 305: return drawobj; MATCH LINES: 339, 365 327: return ERR_PTR(ret); 328: } 329: 330: return NULL; 331: } 332: 333: /** 334: * adreno_dispatcher_requeue_cmdobj() - Put a command back on the context 335: * queue 336: * @drawctxt: Pointer to the adreno draw context 337: * @cmdobj: Pointer to the KGSL command object to requeue 338: * 339: * Failure to submit a command to the ringbuffer isn't the fault of the command 340: * being submitted so if a failure happens, push it back on the head of the 341: * context queue to be reconsidered again unless the context got detached. 342: */ 343: static inline int adreno_dispatcher_requeue_cmdobj( 344: struct adreno_context *drawctxt, 345: struct kgsl_drawobj_cmd *cmdobj) 346: { 347: unsigned int prev; 348: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 349: 350: spin_lock(&drawctxt->lock); 351: 352: if (kgsl_context_is_bad(&drawctxt->base)) { 353: spin_unlock(&drawctxt->lock); 354: /* get rid of this drawobj since the context is bad */ 355: kgsl_drawobj_destroy(drawobj); 356: return -ENOENT; 357: } 358: 359: prev = drawctxt->drawqueue_head == 0 ? 360: (ADRENO_CONTEXT_DRAWQUEUE_SIZE - 1) : 361: (drawctxt->drawqueue_head - 1); 362: 363: /* 364: * The maximum queue size always needs to be one less then the size of 365: * the ringbuffer queue so there is "room" to put the drawobj back in 366: */ 367: 368: WARN_ON(prev == drawctxt->drawqueue_tail); 369: 370: drawctxt->drawqueue[prev] = drawobj; 371: drawctxt->queued++; 372: 373: /* Reset the command queue head to reflect the newly requeued change */ 374: drawctxt->drawqueue_head = prev; 375: cmdobj->requeue_cnt++; 376: spin_unlock(&drawctxt->lock); 377: return 0; 378: } 379: 380: /** 381: * dispatcher_queue_context() - Queue a context in the dispatcher pending list 382: * @dispatcher: Pointer to the adreno dispatcher struct 383: * @drawctxt: Pointer to the adreno draw context 384: * 385: * Add a context to the dispatcher pending list. 386: */ 387: static int dispatcher_queue_context(struct adreno_device *adreno_dev, 388: struct adreno_context *drawctxt) 389: { MATCH LINES: 425 413: } 414: 415: /* 416: * Real time clients may demand high BW and have strict latency requirement. 417: * GPU bus DCVS is not fast enough to account for sudden BW requirements. 418: * Bus hint helps to bump up the bus vote (IB) upfront for known time-critical 419: * workloads. 420: */ 421: static void process_rt_bus_hint(struct kgsl_device *device, bool on) 422: { 423: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 424: struct adreno_dispatcher_drawqueue *drawqueue = 425: DRAWQUEUE(&adreno_dev->ringbuffers[0]); 426: 427: if (!adreno_is_preemption_enabled(adreno_dev) || 428: !device->pwrctrl.rt_bus_hint) 429: return; 430: 431: if (device->pwrctrl.rt_bus_hint_active == on) 432: return; 433: 434: if (on && drawqueue->inflight == 1) 435: kgsl_bus_update(device, KGSL_BUS_VOTE_RT_HINT_ON); 436: 437: if (!on && drawqueue->inflight == 0) 438: kgsl_bus_update(device, KGSL_BUS_VOTE_RT_HINT_OFF); 439: } 440: 441: #define ADRENO_DRAWOBJ_PROFILE_COUNT \ 442: (PAGE_SIZE / sizeof(struct adreno_drawobj_profile_entry)) 443: 444: /** 445: * sendcmd() - Send a drawobj to the GPU hardware 446: * @dispatcher: Pointer to the adreno dispatcher struct 447: * @drawobj: Pointer to the KGSL drawobj being sent 448: * 449: * Send a KGSL drawobj to the GPU hardware MATCH LINES: 502, 532, 538 490: } 491: 492: if (test_bit(ADRENO_DEVICE_DRAWOBJ_PROFILE, &adreno_dev->priv)) { 493: set_bit(CMDOBJ_PROFILE, &cmdobj->priv); 494: cmdobj->profile_index = adreno_dev->profile_index; 495: adreno_dev->profile_index = 496: (adreno_dev->profile_index + 1) % 497: ADRENO_DRAWOBJ_PROFILE_COUNT; 498: } 499: 500: process_rt_bus_hint(device, true); 501: 502: ret = adreno_ringbuffer_submitcmd(adreno_dev, cmdobj, &time); 503: 504: /* 505: * On the first command, if the submission was successful, then read the 506: * fault registers. If it failed then turn off the GPU. Sad face. 507: */ 508: 509: if (dispatcher->inflight == 1) { 510: if (ret == 0) { 511: if (!test_and_set_bit(ADRENO_DISPATCHER_ACTIVE, 512: &dispatcher->priv)) 513: reinit_completion(&dispatcher->idle_gate); 514: } else { 515: adreno_active_count_put(adreno_dev); 516: clear_bit(ADRENO_DISPATCHER_POWER, &dispatcher->priv); 517: } 518: } 519: 520: 521: if (ret) { 522: dispatcher->inflight--; 523: dispatch_q->inflight--; 524: 525: process_rt_bus_hint(device, false); 526: 527: /* 528: * Don't log a message in case of: 529: * -ENOENT means that the context was detached before the 530: * command was submitted 531: * -ENOSPC means that there temporarily isn't any room in the 532: * ringbuffer 533: * -PROTO means that a fault is currently being worked 534: */ 535: 536: if (ret != -ENOENT && ret != -ENOSPC && ret != -EPROTO) 537: dev_err(device->dev, 538: "Unable to submit command to the ringbuffer %d\n", 539: ret); 540: goto err; 541: } 542: 543: secs = time.ktime; 544: nsecs = do_div(secs, 1000000000); 545: 546: /* 547: * For the first submission in any given command queue update the 548: * expected expire time - this won't actually be used / updated until 549: * the command queue in question goes current, but universally setting 550: * it here avoids the possibilty of some race conditions with preempt 551: */ 552: 553: if (dispatch_q->inflight == 1) 554: dispatch_q->expires = jiffies + 555: msecs_to_jiffies(adreno_drawobj_timeout); 556: 557: info.inflight = (int) dispatcher->inflight; 558: info.rb_id = drawctxt->rb->id; 559: info.rptr = adreno_get_rptr(drawctxt->rb); 560: info.wptr = drawctxt->rb->wptr; 561: info.gmu_dispatch_queue = -1; 562: MATCH LINES: 595 583: /* 584: * If we believe ourselves to be current and preemption isn't a thing, 585: * then set up the timer. If this misses, then preemption is indeed a 586: * thing and the timer will be set up in due time 587: */ 588: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 589: if (drawqueue_is_current(dispatch_q)) 590: mod_timer(&dispatcher->timer, dispatch_q->expires); 591: } 592: 593: 594: /* 595: * we just submitted something, readjust ringbuffer 596: * execution level 597: */ 598: if (gpudev->preemption_schedule) 599: gpudev->preemption_schedule(adreno_dev); 600: return 0; 601: err: 602: kgsl_mutex_unlock(&device->mutex); 603: return ret; 604: } 605: 606: /** 607: * dispatcher_context_sendcmds() - Send commands from a context to the GPU 608: * @adreno_dev: Pointer to the adreno device struct 609: * @drawctxt: Pointer to the adreno context to dispatch commands from 610: * 611: * Dequeue and send a burst of commands from the specified context to the GPU 612: * Returns postive if the context needs to be put back on the pending queue 613: * 0 if the context is empty or detached and negative on error 614: */ 615: static int dispatcher_context_sendcmds(struct adreno_device *adreno_dev, 616: struct adreno_context *drawctxt) 617: { 618: struct adreno_dispatcher_drawqueue *dispatch_q = 619: &(drawctxt->rb->dispatch_q); MATCH LINES: 776 764: 765: /* 766: * If the context had nothing queued or the context has been 767: * destroyed then drop the job 768: */ 769: if (!ret || ret == -ENOENT) { 770: kgsl_context_put(&job->drawctxt->base); 771: kmem_cache_free(jobs_cache, job); 772: continue; 773: } 774: 775: /* 776: * If the ringbuffer is full then requeue the job to be 777: * considered first next time. Otherwise the context 778: * either successfully submmitted to the GPU or another error 779: * happened and it should go back on the regular queue 780: */ 781: if (ret == -EBUSY) 782: llist_add(&job->node, &dispatcher->requeue[id]); 783: else 784: llist_add(&job->node, &dispatcher->jobs[id]); 785: } 786: } 787: 788: static void dispatcher_handle_jobs(struct adreno_device *adreno_dev, int id) 789: { 790: struct adreno_dispatcher *dispatcher = &adreno_dev->dispatcher; 791: unsigned long map[BITS_TO_LONGS(KGSL_MEMSTORE_MAX)]; 792: struct llist_node *requeue, *jobs; 793: 794: memset(map, 0, sizeof(map)); 795: 796: requeue = llist_del_all(&dispatcher->requeue[id]); 797: jobs = llist_del_all(&dispatcher->jobs[id]); 798: 799: dispatcher_handle_jobs_list(adreno_dev, id, map, requeue); 800: dispatcher_handle_jobs_list(adreno_dev, id, map, jobs); MATCH LINES: 1326 1314: if (dispatch_q->inflight < _context_drawobj_burst) 1315: adreno_dispatcher_issuecmds(adreno_dev); 1316: done: 1317: if (test_and_clear_bit(ADRENO_CONTEXT_FAULT, &context->priv)) 1318: return -EPROTO; 1319: 1320: return 0; 1321: } 1322: 1323: /* 1324: * If an IB inside of the drawobj has a gpuaddr that matches the base 1325: * passed in then zero the size which effectively skips it when it is submitted 1326: * in the ringbuffer. 1327: */ 1328: static void _skip_ib(struct kgsl_drawobj_cmd *cmdobj, uint64_t base) 1329: { 1330: struct kgsl_memobj_node *ib; 1331: 1332: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 1333: if (ib->gpuaddr == base) { 1334: ib->priv |= MEMOBJ_SKIP; 1335: if (base) 1336: return; 1337: } 1338: } 1339: } 1340: 1341: static void _skip_cmd(struct kgsl_drawobj_cmd *cmdobj, 1342: struct kgsl_drawobj_cmd **replay, int count) 1343: { 1344: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 1345: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 1346: int i; 1347: 1348: /* 1349: * SKIPCMD policy: next IB issued for this context is tentative 1350: * if it fails we assume that GFT failed and if it succeeds MATCH LINES: 1467 1455: &drawobj->context->events, drawobj->timestamp); 1456: kgsl_mutex_unlock(&device->mutex); 1457: 1458: kgsl_drawobj_destroy(drawobj); 1459: } 1460: } 1461: } 1462: 1463: #define pr_fault(_d, _c, fmt, args...) \ 1464: pr_context(_d, (_c)->context, fmt, ##args) 1465: 1466: static void adreno_fault_header(struct kgsl_device *device, 1467: struct adreno_ringbuffer *rb, struct kgsl_drawobj_cmd *cmdobj, 1468: int fault) 1469: { 1470: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1471: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 1472: struct adreno_context *drawctxt = 1473: drawobj ? ADRENO_CONTEXT(drawobj->context) : NULL; 1474: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1475: unsigned int status, rptr, wptr, ib1sz, ib2sz; 1476: uint64_t ib1base, ib2base; 1477: bool gx_on = adreno_gx_is_on(adreno_dev); 1478: int id = (rb != NULL) ? rb->id : -1; 1479: const char *type = fault & ADRENO_GMU_FAULT ? "gmu" : "gpu"; 1480: 1481: if (!gx_on) { 1482: if (drawobj != NULL) { 1483: pr_fault(device, drawobj, 1484: "%s fault ctx %u ctx_type %s ts %u and GX is OFF\n", 1485: type, drawobj->context->id, 1486: kgsl_context_type(drawctxt->type), 1487: drawobj->timestamp); 1488: pr_fault(device, drawobj, "cmdline: %s\n", 1489: drawctxt->base.proc_priv->cmdline); 1490: } else 1491: dev_err(device->dev, "RB[%d] : %s fault and GX is OFF\n", MATCH LINES: 1849, 1883, 1884 1837: remove_invalidated_cmdobjs(device, &replay[i], 1838: count - i); 1839: } 1840: } 1841: 1842: /* Clear the fault bit */ 1843: clear_bit(ADRENO_DEVICE_FAULT, &adreno_dev->priv); 1844: 1845: kfree(replay); 1846: } 1847: 1848: static void do_header_and_snapshot(struct kgsl_device *device, int fault, 1849: struct adreno_ringbuffer *rb, struct kgsl_drawobj_cmd *cmdobj) 1850: { 1851: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 1852: 1853: /* Always dump the snapshot on a non-drawobj failure */ 1854: if (cmdobj == NULL) { 1855: adreno_fault_header(device, rb, NULL, fault); 1856: 1857: /* GMU snapshot will also pull a full device snapshot */ 1858: if (fault & ADRENO_GMU_FAULT) 1859: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 1860: else 1861: kgsl_device_snapshot(device, NULL, NULL, false); 1862: return; 1863: } 1864: 1865: /* Skip everything if the PMDUMP flag is set */ 1866: if (test_bit(KGSL_FT_SKIP_PMDUMP, &cmdobj->fault_policy)) 1867: return; 1868: 1869: /* Print the fault header */ 1870: adreno_fault_header(device, rb, cmdobj, fault); 1871: 1872: if (!(drawobj->context->flags & KGSL_CONTEXT_NO_SNAPSHOT)) 1873: kgsl_device_snapshot(device, drawobj->context, NULL, 1874: fault & ADRENO_GMU_FAULT); 1875: } 1876: 1877: static int dispatcher_do_fault(struct adreno_device *adreno_dev) 1878: { 1879: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1880: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1881: struct adreno_dispatcher *dispatcher = &adreno_dev->dispatcher; 1882: struct adreno_dispatcher_drawqueue *dispatch_q = NULL, *dispatch_q_temp; 1883: struct adreno_ringbuffer *rb; 1884: struct adreno_ringbuffer *hung_rb = NULL; 1885: unsigned int reg; 1886: uint64_t base = 0; 1887: struct kgsl_drawobj_cmd *cmdobj = NULL; 1888: int ret, i; 1889: int fault; 1890: int halt; 1891: bool gx_on; 1892: 1893: fault = adreno_gpu_fault(adreno_dev); 1894: if (fault == 0) 1895: return 0; 1896: 1897: /* 1898: * Return early if there is a concurrent suspend in progress. The suspend thread will error 1899: * out in the presence of this hwsched fault and requeue the dispatcher to handle this fault 1900: */ 1901: if (!mutex_trylock(&adreno_dev->fault_recovery_mutex)) 1902: return 1; 1903: 1904: /* 1905: * Wait long enough to allow the system to come out of suspend completely, which can take 1906: * variable amount of time especially if it has to rewind suspend processes and devices. 1907: */ 1908: if (!wait_for_completion_timeout(&adreno_dev->suspend_recovery_gate, MATCH LINES: 1983 1971: adreno_readreg(adreno_dev, ADRENO_REG_CP_ME_CNTL, ®); 1972: 1973: if (adreno_is_a5xx(adreno_dev) || adreno_is_a6xx(adreno_dev)) 1974: reg |= 1 | (1 << 1); 1975: else 1976: reg = 0x0; 1977: 1978: adreno_writereg(adreno_dev, ADRENO_REG_CP_ME_CNTL, reg); 1979: } 1980: /* 1981: * retire cmdobj's from all the dispatch_q's before starting recovery 1982: */ 1983: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1984: adreno_dispatch_retire_drawqueue(adreno_dev, 1985: &(rb->dispatch_q)); 1986: /* Select the active dispatch_q */ 1987: if (base == rb->buffer_desc->gpuaddr) { 1988: dispatch_q = &(rb->dispatch_q); 1989: hung_rb = rb; 1990: if (adreno_dev->cur_rb != hung_rb) { 1991: adreno_dev->prev_rb = adreno_dev->cur_rb; 1992: adreno_dev->cur_rb = hung_rb; 1993: } 1994: } 1995: } 1996: 1997: if (dispatch_q && !adreno_drawqueue_is_empty(dispatch_q)) { 1998: cmdobj = dispatch_q->cmd_q[dispatch_q->head]; 1999: trace_adreno_cmdbatch_fault(cmdobj, fault); 2000: } 2001: 2002: if (gx_on) 2003: adreno_readreg64(adreno_dev, ADRENO_REG_CP_IB1_BASE, 2004: ADRENO_REG_CP_IB1_BASE_HI, &base); 2005: 2006: if (!test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &device->mmu.pfpolicy) 2007: && adreno_dev->cooperative_reset) MATCH LINES: 2034, 2067 2022: 2023: /* Reset the dispatcher queue */ 2024: dispatcher->inflight = 0; 2025: 2026: /* Remove the bus hint */ 2027: device->pwrctrl.rt_bus_hint_active = false; 2028: 2029: /* Reset the GPU and make sure halt is not set during recovery */ 2030: halt = adreno_gpu_halt(adreno_dev); 2031: adreno_clear_gpu_halt(adreno_dev); 2032: 2033: /* 2034: * If there is a stall in the ringbuffer after all commands have been 2035: * retired then we could hit problems if contexts are waiting for 2036: * internal timestamps that will never retire 2037: */ 2038: 2039: if (hung_rb != NULL) { 2040: kgsl_sharedmem_writel(device->memstore, 2041: MEMSTORE_RB_OFFSET(hung_rb, soptimestamp), 2042: hung_rb->timestamp); 2043: 2044: kgsl_sharedmem_writel(device->memstore, 2045: MEMSTORE_RB_OFFSET(hung_rb, eoptimestamp), 2046: hung_rb->timestamp); 2047: 2048: /* Schedule any pending events to be run */ 2049: kgsl_process_event_group(device, &hung_rb->events); 2050: } 2051: 2052: ret = adreno_reset(device, fault); 2053: 2054: /* If adreno_reset() fails then what hope do we have for the future? */ 2055: BUG_ON(ret); 2056: 2057: /* if any other fault got in until reset then ignore */ 2058: adreno_clear_gpu_fault(adreno_dev); 2059: 2060: kgsl_mutex_unlock(&device->mutex); 2061: 2062: mutex_unlock(&adreno_dev->fault_recovery_mutex); 2063: 2064: /* recover all the dispatch_q's starting with the one that hung */ 2065: if (dispatch_q) 2066: recover_dispatch_q(device, dispatch_q, fault, base); 2067: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2068: dispatch_q_temp = &(rb->dispatch_q); 2069: if (dispatch_q_temp != dispatch_q) 2070: recover_dispatch_q(device, dispatch_q_temp, 0, base); 2071: } 2072: 2073: atomic_add(halt, &adreno_dev->halt); 2074: 2075: return 1; 2076: } 2077: 2078: static inline int drawobj_consumed(struct kgsl_drawobj *drawobj, 2079: unsigned int consumed, unsigned int retired) 2080: { 2081: return ((timestamp_cmp(drawobj->timestamp, consumed) >= 0) && 2082: (timestamp_cmp(retired, drawobj->timestamp) < 0)); 2083: } 2084: 2085: static const char *_ft_type(enum kgsl_ft_policy_bits nr) 2086: { 2087: if (nr == KGSL_FT_OFF) 2088: return "off"; 2089: else if (nr == KGSL_FT_REPLAY) 2090: return "replay"; 2091: else if (nr == KGSL_FT_SKIPIB) MATCH LINES: 2145 2133: if (ADRENO_GPUREV(adreno_dev) < 600) 2134: *active = entry->retired - entry->started; 2135: else 2136: *active = entry->ctx_end - entry->ctx_start; 2137: } 2138: 2139: static void retire_cmdobj(struct adreno_device *adreno_dev, 2140: struct kgsl_drawobj_cmd *cmdobj) 2141: { 2142: struct adreno_dispatcher *dispatcher = &adreno_dev->dispatcher; 2143: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 2144: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 2145: struct adreno_ringbuffer *rb = drawctxt->rb; 2146: struct kgsl_context *context = drawobj->context; 2147: uint64_t start = 0, end = 0, active = 0; 2148: struct retire_info info = {0}; 2149: 2150: if (cmdobj->fault_recovery != 0) { 2151: set_bit(ADRENO_CONTEXT_FAULT, &drawobj->context->priv); 2152: _print_recovery(KGSL_DEVICE(adreno_dev), cmdobj); 2153: } 2154: 2155: if (test_bit(CMDOBJ_PROFILE, &cmdobj->priv)) 2156: cmdobj_profile_ticks(adreno_dev, cmdobj, &start, &end, &active); 2157: 2158: info.inflight = (int)dispatcher->inflight; 2159: info.rb_id = rb->id; 2160: info.wptr = rb->wptr; 2161: info.timestamp = drawobj->timestamp; 2162: info.sop = start; 2163: info.eop = end; 2164: info.active = active; 2165: 2166: /* protected GPU work must not be reported */ 2167: if (!(context->flags & KGSL_CONTEXT_SECURE)) 2168: kgsl_work_period_update(KGSL_DEVICE(adreno_dev), 2169: context->proc_priv->period, active); MATCH LINES: 2277, 2288 2265: { 2266: int count = adreno_dispatch_retire_drawqueue(adreno_dev, drawqueue); 2267: 2268: /* Nothing to do if there are no pending commands */ 2269: if (adreno_drawqueue_is_empty(drawqueue)) 2270: return count; 2271: 2272: /* Don't update the drawqueue timeout if it isn't active */ 2273: if (!drawqueue_is_current(drawqueue)) 2274: return count; 2275: 2276: /* 2277: * If the current ringbuffer retired any commands then universally 2278: * reset the timeout 2279: */ 2280: 2281: if (count) { 2282: drawqueue->expires = jiffies + 2283: msecs_to_jiffies(adreno_drawobj_timeout); 2284: return count; 2285: } 2286: 2287: /* 2288: * If we get here then 1) the ringbuffer is current and 2) we haven't 2289: * retired anything. Check to see if the timeout if valid for the 2290: * current drawobj and fault if it has expired 2291: */ 2292: _adreno_dispatch_check_timeout(adreno_dev, drawqueue); 2293: return 0; 2294: } 2295: 2296: /* Take down the dispatcher and release any power states */ 2297: static void _dispatcher_power_down(struct adreno_device *adreno_dev) 2298: { 2299: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2300: struct adreno_dispatcher *dispatcher = &adreno_dev->dispatcher; 2301: 2302: kgsl_mutex_lock(&device->mutex); 2303: 2304: if (test_and_clear_bit(ADRENO_DISPATCHER_ACTIVE, &dispatcher->priv)) 2305: complete_all(&dispatcher->idle_gate); 2306: 2307: process_rt_bus_hint(device, false); 2308: 2309: if (test_bit(ADRENO_DISPATCHER_POWER, &dispatcher->priv)) { 2310: adreno_active_count_put(adreno_dev); 2311: clear_bit(ADRENO_DISPATCHER_POWER, &dispatcher->priv); 2312: } MATCH LINES: 2333, 2335 2321: struct adreno_dispatcher *dispatcher = &adreno_dev->dispatcher; 2322: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2323: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 2324: int count = 0; 2325: unsigned int i = 0; 2326: 2327: mutex_lock(&dispatcher->mutex); 2328: 2329: /* 2330: * As long as there are inflight commands, process retired comamnds from 2331: * all drawqueues 2332: */ 2333: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 2334: struct adreno_dispatcher_drawqueue *drawqueue = 2335: DRAWQUEUE(&adreno_dev->ringbuffers[i]); 2336: 2337: count += adreno_dispatch_process_drawqueue(adreno_dev, 2338: drawqueue); 2339: if (dispatcher->inflight == 0) 2340: break; 2341: } 2342: 2343: kgsl_process_event_groups(device); 2344: 2345: /* 2346: * dispatcher_do_fault() returns 0 if no faults occurred. If that is the 2347: * case, then clean up preemption and try to schedule more work 2348: */ 2349: if (dispatcher_do_fault(adreno_dev) == 0) { 2350: 2351: /* Clean up after preemption */ 2352: if (gpudev->preemption_schedule) 2353: gpudev->preemption_schedule(adreno_dev); 2354: 2355: /* Run the scheduler for to dispatch new commands */ 2356: _adreno_dispatcher_issuecmds(adreno_dev); 2357: } 2358: 2359: /* MATCH LINES: 2422, 2423, 2428, 2430, 2434, 2436, 2437, 2439, 2454, 2457, 2458, 2459, 2463, 2470, 2474, 2482 2410: * adreno_dispatcher_stop() - stop the dispatcher 2411: * @adreno_dev: pointer to the adreno device structure 2412: * 2413: * Stop the dispatcher and close all the timers 2414: */ 2415: void adreno_dispatcher_stop(struct adreno_device *adreno_dev) 2416: { 2417: struct adreno_dispatcher *dispatcher = &adreno_dev->dispatcher; 2418: 2419: kgsl_delete_timer_sync(&dispatcher->timer); 2420: } 2421: 2422: /* Return the ringbuffer that matches the draw context priority */ 2423: static struct adreno_ringbuffer *dispatch_get_rb(struct adreno_device *adreno_dev, 2424: struct adreno_context *drawctxt) 2425: { 2426: int level; 2427: 2428: /* If preemption is disabled everybody goes on the same ringbuffer */ 2429: if (!adreno_is_preemption_enabled(adreno_dev)) 2430: return &adreno_dev->ringbuffers[0]; 2431: 2432: /* 2433: * Math to convert the priority field in context structure to an RB ID. 2434: * Divide up the context priority based on number of ringbuffer levels. 2435: */ 2436: level = min_t(int, drawctxt->base.priority / adreno_dev->num_ringbuffers, 2437: adreno_dev->num_ringbuffers - 1); 2438: 2439: return &adreno_dev->ringbuffers[level]; 2440: } 2441: 2442: static int adreno_dispatcher_setup_context(struct adreno_device *adreno_dev, 2443: struct adreno_context *drawctxt) 2444: { 2445: drawctxt->rb = dispatch_get_rb(adreno_dev, drawctxt); 2446: return 0; 2447: } 2448: 2449: static void change_preemption(struct adreno_device *adreno_dev, void *priv) 2450: { 2451: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2452: struct kgsl_context *context; 2453: struct adreno_context *drawctxt; 2454: struct adreno_ringbuffer *rb; 2455: int id, i, ret; 2456: 2457: /* Make sure all ringbuffers are finished */ 2458: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2459: ret = adreno_ringbuffer_waittimestamp(rb, rb->timestamp, 2460: 2 * 1000); 2461: if (ret) { 2462: dev_err(device->dev, 2463: "Cannot disable preemption because couldn't idle ringbuffer[%d] ret: %d\n", 2464: rb->id, ret); 2465: return; 2466: } 2467: } 2468: 2469: change_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 2470: adreno_dev->cur_rb = &adreno_dev->ringbuffers[0]; 2471: adreno_dev->next_rb = NULL; 2472: adreno_dev->prev_rb = NULL; 2473: 2474: /* Update the ringbuffer for each draw context */ 2475: write_lock(&device->context_lock); 2476: idr_for_each_entry(&device->context_idr, context, id) { 2477: drawctxt = ADRENO_CONTEXT(context); 2478: drawctxt->rb = dispatch_get_rb(adreno_dev, drawctxt); 2479: 2480: /* 2481: * Make sure context destroy checks against the correct 2482: * ringbuffer's timestamp. 2483: */ 2484: adreno_rb_readtimestamp(adreno_dev, drawctxt->rb, 2485: KGSL_TIMESTAMP_RETIRED, &drawctxt->internal_timestamp); 2486: } 2487: write_unlock(&device->context_lock); 2488: } 2489: 2490: static int _preemption_store(struct adreno_device *adreno_dev, bool val) 2491: { 2492: if (!adreno_preemption_feature_set(adreno_dev) || 2493: (test_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv) == val)) 2494: return 0; 2495: 2496: return adreno_power_cycle(adreno_dev, change_preemption, NULL); 2497: } 2498: 2499: static bool _preemption_show(struct adreno_device *adreno_dev) 2500: { 2501: return adreno_is_preemption_enabled(adreno_dev); 2502: } 2503: 2504: static unsigned int _preempt_count_show(struct adreno_device *adreno_dev) 2505: { 2506: return adreno_dev->preempt.count; MATCH LINES: 2535, 2540 2523: 2524: static const struct attribute *_dispatch_attr_list[] = { 2525: &adreno_attr_preemption.attr.attr, 2526: &adreno_attr_preempt_count.attr.attr, 2527: &adreno_attr_ft_long_ib_detect.attr.attr, 2528: NULL, 2529: }; 2530: 2531: static void adreno_dispatcher_close(struct adreno_device *adreno_dev) 2532: { 2533: struct adreno_dispatcher *dispatcher = &adreno_dev->dispatcher; 2534: int i; 2535: struct adreno_ringbuffer *rb; 2536: 2537: mutex_lock(&dispatcher->mutex); 2538: kgsl_delete_timer_sync(&dispatcher->timer); 2539: 2540: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2541: struct adreno_dispatcher_drawqueue *dispatch_q = 2542: &(rb->dispatch_q); 2543: while (!adreno_drawqueue_is_empty(dispatch_q)) { 2544: kgsl_drawobj_destroy( 2545: DRAWOBJ(dispatch_q->cmd_q[dispatch_q->head])); 2546: dispatch_q->head = (dispatch_q->head + 1) 2547: % ADRENO_DISPATCH_DRAWQUEUE_SIZE; 2548: } 2549: } 2550: 2551: mutex_unlock(&dispatcher->mutex); 2552: 2553: kthread_destroy_worker(adreno_dev->scheduler_worker); 2554: 2555: adreno_set_dispatch_ops(adreno_dev, NULL); 2556: 2557: kobject_put(&dispatcher->kobj); 2558: 2559: kmem_cache_destroy(jobs_cache); 2560: 2561: clear_bit(ADRENO_DISPATCHER_INIT, &dispatcher->priv); 2562: } 2563: 2564: struct dispatcher_attribute { MATCH LINES: 2622 2610: return scnprintf(buf, PAGE_SIZE, "%u\n", 2611: *((unsigned int *) attr->value)); 2612: } 2613: 2614: static DISPATCHER_UINT_ATTR(inflight, 0644, ADRENO_DISPATCH_DRAWQUEUE_SIZE, 2615: _dispatcher_q_inflight_hi); 2616: 2617: static DISPATCHER_UINT_ATTR(inflight_low_latency, 0644, 2618: ADRENO_DISPATCH_DRAWQUEUE_SIZE, _dispatcher_q_inflight_lo); 2619: /* 2620: * Our code that "puts back" a command from the context is much cleaner 2621: * if we are sure that there will always be enough room in the 2622: * ringbuffer so restrict the maximum size of the context queue to 2623: * ADRENO_CONTEXT_DRAWQUEUE_SIZE - 1 2624: */ 2625: static DISPATCHER_UINT_ATTR(context_drawqueue_size, 0644, 2626: ADRENO_CONTEXT_DRAWQUEUE_SIZE - 1, _context_drawqueue_size); 2627: static DISPATCHER_UINT_ATTR(context_burst_count, 0644, 0, 2628: _context_drawobj_burst); 2629: static DISPATCHER_UINT_ATTR(drawobj_timeout, 0644, 0, 2630: adreno_drawobj_timeout); 2631: static DISPATCHER_UINT_ATTR(context_queue_wait, 0644, 0, _context_queue_wait); 2632: static DISPATCHER_UINT_ATTR(fault_detect_interval, 0644, 0, 2633: _fault_timer_interval); 2634: static DISPATCHER_UINT_ATTR(fault_throttle_time, 0644, 0, 2635: _fault_throttle_time); 2636: static DISPATCHER_UINT_ATTR(fault_throttle_burst, 0644, 0, 2637: _fault_throttle_burst); 2638: 2639: static struct attribute *dispatcher_attrs[] = { 2640: &dispatcher_attr_inflight.attr, 2641: &dispatcher_attr_inflight_low_latency.attr, 2642: &dispatcher_attr_context_drawqueue_size.attr, 2643: &dispatcher_attr_context_burst_count.attr, 2644: &dispatcher_attr_drawobj_timeout.attr, 2645: &dispatcher_attr_context_queue_wait.attr, 2646: &dispatcher_attr_fault_detect_interval.attr, --- FILE: \adreno_dispatch.h | HITS: 2 --- MATCH LINES: 17 5: */ 6: 7: #ifndef ____ADRENO_DISPATCHER_H 8: #define ____ADRENO_DISPATCHER_H 9: 10: #include 11: #include 12: #include 13: 14: extern unsigned int adreno_drawobj_timeout; 15: 16: /* 17: * Maximum size of the dispatcher ringbuffer - the actual inflight size will be 18: * smaller then this but this size will allow for a larger range of inflight 19: * sizes that can be chosen at runtime 20: */ 21: 22: #define ADRENO_DISPATCH_DRAWQUEUE_SIZE 128 23: 24: #define DRAWQUEUE_NEXT(_i, _s) (((_i) + 1) % (_s)) 25: 26: /** 27: * struct adreno_dispatcher_drawqueue - List of commands for a RB level 28: * @cmd_q: List of command obj's submitted to dispatcher 29: * @inflight: Number of commands inflight in this q 30: * @head: Head pointer to the q 31: * @tail: Queues tail pointer 32: * @active_context_count: Number of active contexts seen in this rb drawqueue 33: * @expires: The jiffies value at which this drawqueue has run too long 34: */ 35: struct adreno_dispatcher_drawqueue { 36: struct kgsl_drawobj_cmd *cmd_q[ADRENO_DISPATCH_DRAWQUEUE_SIZE]; 37: unsigned int inflight; 38: unsigned int head; 39: unsigned int tail; 40: int active_context_count; 41: unsigned long expires; MATCH LINES: 64 52: * through a dispatch cycle 53: */ 54: struct adreno_dispatch_job { 55: struct llist_node node; 56: struct adreno_context *drawctxt; 57: }; 58: 59: /** 60: * struct adreno_dispatcher - container for the adreno GPU dispatcher 61: * @mutex: Mutex to protect the structure 62: * @state: Current state of the dispatcher (active or paused) 63: * @timer: Timer to monitor the progress of the drawobjs 64: * @inflight: Number of drawobj operations pending in the ringbuffer 65: * @pending: Priority list of contexts waiting to submit drawobjs 66: * @kobj: kobject for the dispatcher directory in the device sysfs node 67: * @idle_gate: Gate to wait on for dispatcher to idle 68: */ 69: struct adreno_dispatcher { 70: struct mutex mutex; 71: unsigned long priv; 72: struct timer_list timer; 73: struct timer_list fault_timer; 74: unsigned int inflight; 75: /** @jobs - Array of dispatch job lists for each priority level */ 76: struct llist_head jobs[16]; 77: /** @requeue - Array of lists for dispatch jobs that got requeued */ 78: struct llist_head requeue[16]; 79: struct kobject kobj; 80: struct completion idle_gate; 81: }; 82: 83: enum adreno_dispatcher_flags { 84: ADRENO_DISPATCHER_POWER = 0, 85: ADRENO_DISPATCHER_ACTIVE, 86: ADRENO_DISPATCHER_INIT, 87: }; 88: --- FILE: \adreno_drawctxt.c | HITS: 6 --- MATCH LINES: 224 212: /* 213: * If the context is invalid (OR) not submitted commands to GPU 214: * then return immediately - we may end up waiting for a timestamp 215: * that will never come 216: */ 217: if (kgsl_context_invalid(context) || 218: !test_bit(KGSL_CONTEXT_PRIV_SUBMITTED, &context->priv)) 219: goto done; 220: 221: trace_adreno_drawctxt_wait_start(drawctxt->rb->id, context->id, 222: timestamp); 223: 224: ret = adreno_ringbuffer_waittimestamp(drawctxt->rb, timestamp, timeout); 225: done: 226: trace_adreno_drawctxt_wait_done(drawctxt->rb->id, context->id, 227: timestamp, ret); 228: return ret; 229: } 230: 231: static int drawctxt_detach_drawobjs(struct adreno_context *drawctxt, 232: struct kgsl_drawobj **list) 233: { 234: int count = 0; 235: 236: while (drawctxt->drawqueue_head != drawctxt->drawqueue_tail) { 237: struct kgsl_drawobj *drawobj = 238: drawctxt->drawqueue[drawctxt->drawqueue_head]; 239: 240: drawctxt->drawqueue_head = (drawctxt->drawqueue_head + 1) % 241: ADRENO_CONTEXT_DRAWQUEUE_SIZE; 242: 243: list[count++] = drawobj; 244: } 245: 246: return count; 247: } 248: MATCH LINES: 317, 327, 362 305: { 306: if (!context) 307: return; 308: 309: context->reset_status = KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT; 310: 311: adreno_drawctxt_invalidate(device, context); 312: } 313: 314: u32 adreno_prepare_preib_preempt_scratch(struct adreno_device *adreno_dev, 315: struct adreno_context *drawctxt, u32 *cmds) 316: { 317: struct adreno_ringbuffer *rb = drawctxt->rb; 318: u32 *cmds_orig = cmds; 319: u64 gpuaddr, dest; 320: 321: if (!drawctxt->base.user_ctxt_record) 322: return 0; 323: 324: dest = PREEMPT_SCRATCH_ADDR(adreno_dev, rb->id); 325: gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 326: 327: *cmds++ = cp_mem_packet(adreno_dev, CP_MEM_WRITE, 2, 2); 328: cmds += cp_gpuaddr(adreno_dev, cmds, dest); 329: *cmds++ = lower_32_bits(gpuaddr); 330: *cmds++ = upper_32_bits(gpuaddr); 331: 332: return (u32) (cmds - cmds_orig); 333: } 334: 335: u32 adreno_prepare_preib_postamble_scratch(struct adreno_device *adreno_dev, u32 *cmds) 336: { 337: u32 *cmds_orig = cmds; 338: u64 kmd_postamble_addr; 339: 340: if (!adreno_dev->preempt.postamble_len) 341: return 0; 342: 343: kmd_postamble_addr = SCRATCH_POSTAMBLE_ADDR(KGSL_DEVICE(adreno_dev)); 344: 345: *cmds++ = cp_type7_packet(CP_SET_AMBLE, 3); 346: *cmds++ = lower_32_bits(kmd_postamble_addr); 347: *cmds++ = upper_32_bits(kmd_postamble_addr); 348: *cmds++ = FIELD_PREP(GENMASK(22, 20), CP_KMD_AMBLE_TYPE) 349: | (FIELD_PREP(GENMASK(19, 0), adreno_dev->preempt.postamble_len)); 350: 351: return (u32) (cmds - cmds_orig); 352: } 353: 354: static int drawctxt_preemption_init(struct kgsl_context *context) 355: { 356: struct kgsl_device *device = context->device; 357: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 358: u64 flags = 0; 359: 360: /* 361: * User context record is needed for a6x and beyond targets only. Also, 362: * highest priority ringbuffer i.e. RB0 always runs to completion without 363: * preemption. Thus, user context records are not needed for RB0. 364: */ 365: if (!adreno_preemption_feature_set(adreno_dev) || (ADRENO_GPUREV(adreno_dev) < 600) || 366: (adreno_get_level(context) == 0)) 367: return 0; 368: 369: if (context->flags & KGSL_CONTEXT_SECURE) 370: flags |= KGSL_MEMFLAGS_SECURE; 371: 372: if (is_compat_task()) 373: flags |= KGSL_MEMFLAGS_FORCE_32BIT; 374: 375: /* 376: * gpumem_alloc_entry takes an extra refcount. Put it only when 377: * destroying the context to keep the context record valid 378: */ 379: context->user_ctxt_record = gpumem_alloc_entry(context->dev_priv, 380: ADRENO_CP_CTXRECORD_USER_RESTORE_SIZE, flags); 381: if (IS_ERR(context->user_ctxt_record)) { 382: int ret = PTR_ERR(context->user_ctxt_record); 383: 384: context->user_ctxt_record = NULL; 385: return ret; 386: } MATCH LINES: 543 531: 532: return &drawctxt->base; 533: } 534: 535: static void wait_for_timestamp_rb(struct kgsl_device *device, 536: struct adreno_context *drawctxt) 537: { 538: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 539: struct kgsl_context *context = &drawctxt->base; 540: int ret; 541: 542: /* 543: * internal_timestamp is set in adreno_ringbuffer_addcmds, 544: * which holds the device mutex. 545: */ 546: kgsl_mutex_lock(&device->mutex); 547: 548: /* 549: * Wait for the last global timestamp to pass before continuing. 550: * The maxumum wait time is 30s, some large IB's can take longer 551: * than 10s and if hang happens then the time for the context's 552: * commands to retire will be greater than 10s. 30s should be sufficient 553: * time to wait for the commands even if a hang happens. 554: */ 555: ret = adreno_drawctxt_wait_rb(adreno_dev, &drawctxt->base, 556: drawctxt->internal_timestamp, 30 * 1000); 557: 558: /* 559: * If the wait for global fails due to timeout then mark it as 560: * context detach timeout fault and schedule dispatcher to kick 561: * in GPU recovery. For a ADRENO_CTX_DETATCH_TIMEOUT_FAULT we clear 562: * the policy and invalidate the context. If EAGAIN error is returned 563: * then recovery will kick in and there will be no more commands in the 564: * RB pipe from this context which is what we are waiting for, so ignore 565: * -EAGAIN error. 566: */ 567: if (ret && ret != -EAGAIN) { MATCH LINES: 688 676: 677: static void _drawctxt_switch_wait_callback(struct kgsl_device *device, 678: struct kgsl_event_group *group, 679: void *priv, int result) 680: { 681: struct adreno_context *drawctxt = (struct adreno_context *) priv; 682: 683: kgsl_context_put(&drawctxt->base); 684: } 685: 686: void adreno_put_drawctxt_on_timestamp(struct kgsl_device *device, 687: struct adreno_context *drawctxt, 688: struct adreno_ringbuffer *rb, u32 timestamp) 689: { 690: if (!drawctxt) 691: return; 692: 693: if (kgsl_add_event(device, &rb->events, timestamp, 694: _drawctxt_switch_wait_callback, drawctxt)) 695: kgsl_context_put(&drawctxt->base); 696: } 697: 698: static void _add_context(struct adreno_device *adreno_dev, 699: struct adreno_context *drawctxt) 700: { 701: /* Remove it from the list */ 702: list_del_init(&drawctxt->active_node); 703: 704: /* And push it to the front */ 705: drawctxt->active_time = jiffies; 706: list_add(&drawctxt->active_node, &adreno_dev->active_list); 707: } 708: 709: static int __count_context(struct adreno_context *drawctxt, void *data) 710: { 711: unsigned long expires = drawctxt->active_time + msecs_to_jiffies(100); 712: --- FILE: \adreno_drawctxt.h | HITS: 7 --- MATCH LINES: 43, 72 31: * @mutex: Mutex to protect the drawqueue 32: * @drawqueue: Queue of drawobjs waiting to be dispatched for this 33: * context 34: * @drawqueue_head: Head of the drawqueue queue 35: * @drawqueue_tail: Tail of the drawqueue queue 36: * @wq: Workqueue structure for contexts to sleep pending room in the queue 37: * @waiting: Workqueue structure for contexts waiting for a timestamp or event 38: * @timeout: Workqueue structure for contexts waiting to invalidate 39: * @queued: Number of commands queued in the drawqueue 40: * @fault_policy: GFT fault policy set in _skip_cmd(); 41: * @debug_root: debugfs entry for this context. 42: * @queued_timestamp: The last timestamp that was queued on this context 43: * @rb: The ringbuffer in which this context submits commands. 44: * @submitted_timestamp: The last timestamp that was submitted for this context 45: * @submit_retire_ticks: Array to hold command obj execution times from submit 46: * to retire 47: * @ticks_index: The index into submit_retire_ticks[] where the new delta will 48: * be written. 49: * @active_node: Linkage for nodes in active_list 50: * @active_time: Time when this context last seen 51: */ 52: struct adreno_context { 53: struct kgsl_context base; 54: unsigned int timestamp; 55: unsigned int internal_timestamp; 56: unsigned int type; 57: spinlock_t lock; 58: 59: /* Dispatcher */ 60: struct kgsl_drawobj *drawqueue[ADRENO_CONTEXT_DRAWQUEUE_SIZE]; 61: unsigned int drawqueue_head; 62: unsigned int drawqueue_tail; 63: 64: wait_queue_head_t wq; 65: wait_queue_head_t waiting; 66: wait_queue_head_t timeout; 67: 68: int queued; 69: unsigned int fault_policy; 70: struct dentry *debug_root; 71: unsigned int queued_timestamp; 72: struct adreno_ringbuffer *rb; 73: unsigned int submitted_timestamp; 74: uint64_t submit_retire_ticks[SUBMIT_RETIRE_TICKS_SIZE]; 75: int ticks_index; 76: 77: struct list_head active_node; 78: unsigned long active_time; 79: /** @gmu_context_queue: Queue to dispatch submissions to GMU */ 80: struct kgsl_memdesc gmu_context_queue; 81: /** @gmu_hw_fence_queue: Queue for GMU to store hardware fences for this context */ 82: struct kgsl_memdesc gmu_hw_fence_queue; 83: /** @hw_fence_list: List of hardware fences(sorted by timestamp) not yet submitted to GMU */ 84: struct list_head hw_fence_list; 85: /** @hw_fence_inflight_list: List of hardware fences submitted to GMU */ 86: struct list_head hw_fence_inflight_list; 87: /** @hw_fence_count: Number of hardware fences not yet sent to Tx Queue */ 88: u32 hw_fence_count; 89: /** @syncobj_timestamp: Timestamp to check whether GMU has consumed a syncobj */ 90: u32 syncobj_timestamp; 91: /** 92: * @gmu_hw_fence_ready_ts: This timestamp is used to figure out whether a hardware fence 93: * is ready to be submitted to GMU at the time of its creation or not. This timestamp 94: * tracks the timestamp of the most recently submitted cmdbatch submission to the GMU 95: * context queue for this context. This is different from the internal_timestamp (which gets 96: * reset to 0 in some cases). MATCH LINES: 139, 168, 177, 211, 221 127: ADRENO_CONTEXT_SKIP_CMD, 128: ADRENO_CONTEXT_FENCE_LOG, 129: }; 130: 131: struct kgsl_context *adreno_drawctxt_create( 132: struct kgsl_device_private *dev_priv, 133: uint32_t *flags); 134: 135: void adreno_drawctxt_detach(struct kgsl_context *context); 136: 137: void adreno_drawctxt_destroy(struct kgsl_context *context); 138: 139: struct adreno_ringbuffer; 140: struct adreno_dispatcher_drawqueue; 141: 142: int adreno_drawctxt_wait(struct adreno_device *adreno_dev, 143: struct kgsl_context *context, 144: uint32_t timestamp, unsigned int timeout); 145: 146: void adreno_drawctxt_invalidate(struct kgsl_device *device, 147: struct kgsl_context *context); 148: 149: void adreno_drawctxt_dump(struct kgsl_device *device, 150: struct kgsl_context *context); 151: 152: /** 153: * adreno_drawctxt_detached - Helper function to check if a context is detached 154: * @drawctxt: Adreno drawctxt to check 155: * 156: * Return: True if the context isn't null and it has been detached 157: */ 158: static inline bool adreno_drawctxt_detached(struct adreno_context *drawctxt) 159: { 160: return (drawctxt && kgsl_context_detached(&drawctxt->base)); 161: } 162: 163: /** 164: * adreno_put_drawctxt_on_timestamp - Put the refcount on the drawctxt when the 165: * timestamp expires 166: * @device: A KGSL device handle 167: * @drawctxt: The draw context to put away 168: * @rb: The ringbuffer that will trigger the timestamp event 169: * @timestamp: The timestamp on @rb that will trigger the event 170: * 171: * Add an event to put the refcount on @drawctxt after @timestamp expires on 172: * @rb. This is used by the context switch to safely put away the context after 173: * a new context is switched in. 174: */ 175: void adreno_put_drawctxt_on_timestamp(struct kgsl_device *device, 176: struct adreno_context *drawctxt, 177: struct adreno_ringbuffer *rb, u32 timestamp); 178: 179: /** 180: * adreno_drawctxt_get_pagetable - Helper function to return the pagetable for a 181: * context 182: * @drawctxt: The adreno draw context to query 183: * 184: * Return: A pointer to the pagetable for the process that owns the context or 185: * NULL 186: */ 187: static inline struct kgsl_pagetable * 188: adreno_drawctxt_get_pagetable(struct adreno_context *drawctxt) 189: { 190: if (drawctxt) 191: return drawctxt->base.proc_priv->pagetable; 192: 193: return NULL; 194: } 195: 196: /** 197: * adreno_drawctxt_set_guilty - Mark a context as guilty and invalidate it 198: * @device: Pointer to a GPU device handle 199: * @context: Pointer to the context to invalidate 200: * 201: * Mark the specified context as guilty and invalidate it 202: */ 203: void adreno_drawctxt_set_guilty(struct kgsl_device *device, 204: struct kgsl_context *context); 205: 206: /** 207: * adreno_prepare_preib_preempt_scratch - Update drawctxt pointer in preemption 208: * scratch buffer before IB commands 209: * @adreno_dev: Pointer to the adreno device 210: * @drawctxt: Pointer to the adreno draw context 211: * @cmds: Pointer to the ringbuffer to insert opcodes 212: * 213: * Return: The number of dwords written to @cmds 214: */ 215: u32 adreno_prepare_preib_preempt_scratch(struct adreno_device *adreno_dev, 216: struct adreno_context *drawctxt, u32 *cmds); 217: 218: /** 219: * adreno_prepare_preib_postamble_scratch - Insert postamble packets before IB commands 220: * @adreno_dev: Pointer to the adreno device 221: * @cmds: Pointer to the ringbuffer to insert opcodes 222: * 223: * Return: The number of dwords written to @cmds 224: */ 225: u32 adreno_prepare_preib_postamble_scratch(struct adreno_device *adreno_dev, u32 *cmds); 226: 227: /** 228: * adreno_track_context - Add a context to active list and keep track of active contexts 229: * @adreno_dev: Pointer to adreno device 230: * @drawqueue: Pointer to the dispatch queue to which context send commands 231: * @drawctxt: Draw context which is to be tracked 232: * 233: * Add the given draw context to the active list and update number of contexts which 234: * are active overall as well as which are active on the dispatch queue to which 235: * the given context sends commands. 236: */ 237: void adreno_track_context(struct adreno_device *adreno_dev, 238: struct adreno_dispatcher_drawqueue *drawqueue, 239: struct adreno_context *drawctxt); 240: #endif /* __ADRENO_DRAWCTXT_H */ --- FILE: \adreno_gen7.c | HITS: 22 --- MATCH LINES: 277 265: mask |= BIT(3); 266: 267: /* Disable save/restore of performance counters across preemption */ 268: mask |= BIT(6); 269: 270: /* Enable the register init list with the spinlock */ 271: mask |= BIT(8); 272: 273: /* By default DMS is enabled from CP side, disable it if not supported */ 274: if (!adreno_dev->dms_enabled) 275: mask |= BIT(11); 276: 277: cmds[i++] = cp_type7_packet(CP_ME_INIT, 7); 278: 279: /* Enabled ordinal mask */ 280: cmds[i++] = mask; 281: cmds[i++] = 0x00000003; /* Set number of HW contexts */ 282: cmds[i++] = 0x20000000; /* Enable error detection */ 283: cmds[i++] = 0x00000002; /* Operation mode mask */ 284: 285: /* Register initialization list with spinlock */ 286: cmds[i++] = lower_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 287: cmds[i++] = upper_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 288: /* 289: * Gen7 targets with concurrent binning are expected to have a dynamic 290: * power up list with triplets which contains the pipe id in it. 291: * Bit 31 of POWER_UP_REGISTER_LIST_LENGTH is reused here to let CP 292: * know if the power up contains the triplets. If 293: * REGISTER_INIT_LIST_WITH_SPINLOCK is set and bit 31 below is set, 294: * CP expects a dynamic list with triplets. 295: */ 296: cmds[i++] = BIT(31); 297: } 298: 299: int gen7_fenced_write(struct adreno_device *adreno_dev, u32 offset, 300: u32 value, u32 mask) 301: { MATCH LINES: 847, 848 835: { 836: return GEN7_UCHE_TRAP_BASE; 837: } 838: 839: /* 840: * All Gen7 targets support marking certain transactions as always privileged 841: * which allows us to mark more memory as privileged without having to 842: * explicitly set the APRIV bit. Choose the following transactions to be 843: * privileged by default: 844: * CDWRITE [6:6] - Crashdumper writes 845: * CDREAD [5:5] - Crashdumper reads 846: * RBRPWB [3:3] - RPTR shadow writes 847: * RBPRIVLEVEL [2:2] - Memory accesses from PM4 packets in the ringbuffer 848: * RBFETCH [1:1] - Ringbuffer reads 849: * ICACHE [0:0] - Instruction cache fetches 850: */ 851: 852: #define GEN7_APRIV_DEFAULT (BIT(3) | BIT(2) | BIT(1) | BIT(0)) 853: /* Add crashdumper permissions for the BR APRIV */ 854: #define GEN7_BR_APRIV_DEFAULT (GEN7_APRIV_DEFAULT | BIT(6) | BIT(5)) 855: 856: void gen7_enable_ahb_timeout_detection(struct adreno_device *adreno_dev) 857: { 858: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 859: u32 val; 860: 861: if (!adreno_dev->ahb_timeout_val) 862: return; 863: 864: val = (ADRENO_AHB_CNTL_DEFAULT | FIELD_PREP(GENMASK(4, 0), 865: adreno_dev->ahb_timeout_val)); 866: kgsl_regwrite(device, GEN7_GPU_CX_MISC_CX_AHB_AON_CNTL, val); 867: kgsl_regwrite(device, GEN7_GPU_CX_MISC_CX_AHB_GMU_CNTL, val); 868: kgsl_regwrite(device, GEN7_GPU_CX_MISC_CX_AHB_CP_CNTL, val); 869: kgsl_regwrite(device, GEN7_GPU_CX_MISC_CX_AHB_VBIF_SMMU_CNTL, val); 870: kgsl_regwrite(device, GEN7_GPU_CX_MISC_CX_AHB_HOST_CNTL, val); 871: } 872: MATCH LINES: 1162, 1164, 1169, 1174, 1180, 1198, 1216, 1240, 1247, 1263, 1268, 1269, 1283, 1284 1150: 1151: dev_err(device->dev, 1152: "rb=%d pos=%X/%X rbbm_status=%8.8X/%8.8X int_0_status=%8.8X\n", 1153: adreno_dev->cur_rb ? adreno_dev->cur_rb->id : -1, rptr, wptr, 1154: status, status3, intstatus); 1155: 1156: dev_err(device->dev, " hwfault=%8.8X\n", hwfault); 1157: 1158: kgsl_device_snapshot(device, NULL, NULL, false); 1159: } 1160: 1161: /* 1162: * gen7_send_cp_init() - Initialize ringbuffer 1163: * @adreno_dev: Pointer to adreno device 1164: * @rb: Pointer to the ringbuffer of device 1165: * 1166: * Submit commands for ME initialization, 1167: */ 1168: static int gen7_send_cp_init(struct adreno_device *adreno_dev, 1169: struct adreno_ringbuffer *rb) 1170: { 1171: unsigned int *cmds; 1172: int ret; 1173: 1174: cmds = adreno_ringbuffer_allocspace(rb, GEN7_CP_INIT_DWORDS); 1175: if (IS_ERR(cmds)) 1176: return PTR_ERR(cmds); 1177: 1178: gen7_cp_init_cmds(adreno_dev, cmds); 1179: 1180: ret = gen7_ringbuffer_submit(rb, NULL); 1181: if (!ret) { 1182: ret = adreno_spin_idle(adreno_dev, 2000); 1183: if (ret) { 1184: gen7_spin_idle_debug(adreno_dev, 1185: "CP initialization failed to idle\n"); 1186: rb->wptr = 0; 1187: rb->_wptr = 0; 1188: } 1189: } 1190: 1191: return ret; 1192: } 1193: 1194: static int gen7_post_start(struct adreno_device *adreno_dev) 1195: { 1196: int ret; 1197: unsigned int *cmds; 1198: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1199: struct adreno_preemption *preempt = &adreno_dev->preempt; 1200: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1201: u64 kmd_postamble_addr; 1202: u32 count = 9; 1203: 1204: if (!adreno_is_preemption_enabled(adreno_dev)) 1205: return 0; 1206: 1207: kmd_postamble_addr = SCRATCH_POSTAMBLE_ADDR(KGSL_DEVICE(adreno_dev)); 1208: gen7_preemption_prepare_postamble(adreno_dev); 1209: 1210: if (kgsl_mmu_is_secured(&device->mmu)) 1211: count += 3; 1212: 1213: if (preempt->postamble_bootup_len) 1214: count += 4; 1215: 1216: cmds = adreno_ringbuffer_allocspace(rb, count); 1217: if (IS_ERR(cmds)) 1218: return PTR_ERR(cmds); 1219: 1220: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 1221: kgsl_mmu_is_secured(&device->mmu) ? 6 : 3); 1222: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 1223: *cmds++ = lower_32_bits(rb->preemption_desc->gpuaddr); 1224: *cmds++ = upper_32_bits(rb->preemption_desc->gpuaddr); 1225: 1226: if (kgsl_mmu_is_secured(&device->mmu)) { 1227: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 1228: *cmds++ = lower_32_bits(rb->secure_preemption_desc->gpuaddr); 1229: *cmds++ = upper_32_bits(rb->secure_preemption_desc->gpuaddr); 1230: } 1231: 1232: if (preempt->postamble_bootup_len) { 1233: *cmds++ = cp_type7_packet(CP_SET_AMBLE, 3); 1234: *cmds++ = lower_32_bits(kmd_postamble_addr); 1235: *cmds++ = upper_32_bits(kmd_postamble_addr); 1236: *cmds++ = FIELD_PREP(GENMASK(22, 20), CP_KMD_AMBLE_TYPE) 1237: | (FIELD_PREP(GENMASK(19, 0), adreno_dev->preempt.postamble_bootup_len)); 1238: } 1239: 1240: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1241: *cmds++ = 0; 1242: *cmds++ = 0; 1243: *cmds++ = 0; 1244: /* generate interrupt on preemption completion */ 1245: *cmds++ = 0; 1246: 1247: ret = gen7_ringbuffer_submit(rb, NULL); 1248: if (!ret) { 1249: ret = adreno_spin_idle(adreno_dev, 2000); 1250: if (ret) 1251: gen7_spin_idle_debug(adreno_dev, 1252: "hw preemption initialization failed to idle\n"); 1253: } 1254: 1255: return ret; 1256: } 1257: 1258: int gen7_rb_start(struct adreno_device *adreno_dev) 1259: { 1260: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 1261: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 1262: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1263: struct adreno_ringbuffer *rb; 1264: u64 addr; 1265: int ret, i; 1266: unsigned int *cmds; 1267: 1268: /* Clear all the ringbuffers */ 1269: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1270: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 1271: kgsl_sharedmem_writel(device->scratch, 1272: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1273: kgsl_sharedmem_writel(device->scratch, 1274: SCRATCH_RB_OFFSET(rb->id, bv_rptr), 0); 1275: 1276: rb->wptr = 0; 1277: rb->_wptr = 0; 1278: rb->wptr_preempt_end = UINT_MAX; 1279: } 1280: 1281: gen7_preemption_start(adreno_dev); 1282: 1283: /* Set up the current ringbuffer */ 1284: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 1285: 1286: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 1287: kgsl_regwrite(device, GEN7_CP_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1288: kgsl_regwrite(device, GEN7_CP_RB_RPTR_ADDR_HI, upper_32_bits(addr)); 1289: 1290: /* Skip this regwrite for Gen7 targets that do not have BV */ 1291: if (!adreno_is_gen7_no_cb_family(adreno_dev)) { 1292: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, bv_rptr); 1293: kgsl_regwrite(device, GEN7_CP_BV_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1294: kgsl_regwrite(device, GEN7_CP_BV_RB_RPTR_ADDR_HI, upper_32_bits(addr)); 1295: } 1296: 1297: kgsl_regwrite(device, GEN7_CP_RB_CNTL, GEN7_CP_RB_CNTL_DEFAULT); 1298: 1299: kgsl_regwrite(device, GEN7_CP_RB_BASE, 1300: lower_32_bits(rb->buffer_desc->gpuaddr)); 1301: kgsl_regwrite(device, GEN7_CP_RB_BASE_HI, 1302: upper_32_bits(rb->buffer_desc->gpuaddr)); 1303: 1304: /* Program the ucode base for CP */ 1305: kgsl_regwrite(device, GEN7_CP_SQE_INSTR_BASE_LO, 1306: lower_32_bits(fw->memdesc->gpuaddr)); 1307: kgsl_regwrite(device, GEN7_CP_SQE_INSTR_BASE_HI, 1308: upper_32_bits(fw->memdesc->gpuaddr)); MATCH LINES: 1328, 1335 1316: 1317: ret = adreno_zap_shader_load(adreno_dev, gen7_core->zap_name); 1318: if (ret) 1319: return ret; 1320: 1321: /* 1322: * Take the GPU out of secure mode. Try the zap shader if it is loaded, 1323: * otherwise just try to write directly to the secure control register 1324: */ 1325: if (!adreno_dev->zap_loaded) 1326: kgsl_regwrite(device, GEN7_RBBM_SECVID_TRUST_CNTL, 0); 1327: else { 1328: cmds = adreno_ringbuffer_allocspace(rb, 2); 1329: if (IS_ERR(cmds)) 1330: return PTR_ERR(cmds); 1331: 1332: *cmds++ = cp_type7_packet(CP_SET_SECURE_MODE, 1); 1333: *cmds++ = 0; 1334: 1335: ret = gen7_ringbuffer_submit(rb, NULL); 1336: if (!ret) { 1337: ret = adreno_spin_idle(adreno_dev, 2000); 1338: if (ret) { 1339: gen7_spin_idle_debug(adreno_dev, 1340: "Switch to unsecure failed to idle\n"); 1341: return ret; 1342: } 1343: } 1344: } 1345: 1346: return gen7_post_start(adreno_dev); 1347: } 1348: 1349: /* 1350: * gen7_gpu_keepalive() - GMU reg write to request GPU stays on 1351: * @adreno_dev: Pointer to the adreno device that has the GMU 1352: * @state: State to set: true is ON, false is OFF 1353: */ 1354: static void gen7_gpu_keepalive(struct adreno_device *adreno_dev, 1355: bool state) 1356: { 1357: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), 1358: GEN7_GMU_GMU_PWR_COL_KEEPALIVE, state); 1359: } MATCH LINES: 1420 1408: kgsl_regwrite(device, GEN7_CP_SQE_STAT_ADDR, 1); 1409: kgsl_regread(device, GEN7_CP_SQE_STAT_DATA, &opcode); 1410: dev_crit_ratelimited(dev, 1411: "CP opcode error interrupt | opcode=0x%8.8x\n", opcode); 1412: } 1413: 1414: if (status1 & BIT(CP_INT_UCODEERROR)) 1415: dev_crit_ratelimited(dev, "CP ucode error interrupt\n"); 1416: 1417: if (status1 & BIT(CP_INT_CPHWFAULT)) { 1418: kgsl_regread(device, GEN7_CP_HW_FAULT, &status2); 1419: dev_crit_ratelimited(dev, 1420: "CP | Ringbuffer HW fault | status=%x\n", status2); 1421: } 1422: 1423: if (status1 & BIT(CP_INT_REGISTERPROTECTION)) { 1424: kgsl_regread(device, GEN7_CP_PROTECT_STATUS, &status2); 1425: dev_crit_ratelimited(dev, 1426: "CP | Protected mode error | %s | addr=%x | status=%x\n", 1427: status2 & BIT(20) ? "READ" : "WRITE", 1428: status2 & 0x3ffff, status2); 1429: } 1430: 1431: if (status1 & BIT(CP_INT_VSDPARITYERROR)) 1432: dev_crit_ratelimited(dev, "CP VSD decoder parity error\n"); 1433: 1434: if (status1 & BIT(CP_INT_ILLEGALINSTRUCTION)) 1435: dev_crit_ratelimited(dev, "CP Illegal instruction error\n"); 1436: 1437: if (ADRENO_FEATURE(adreno_dev, ADRENO_LPAC)) { 1438: if (status1 & BIT(CP_INT_OPCODEERRORLPAC)) 1439: dev_crit_ratelimited(dev, "CP Opcode error LPAC\n"); 1440: 1441: if (status1 & BIT(CP_INT_UCODEERRORLPAC)) 1442: dev_crit_ratelimited(dev, "CP ucode error LPAC\n"); 1443: 1444: if (status1 & BIT(CP_INT_CPHWFAULTLPAC)) MATCH LINES: 1467 1455: if (status1 & BIT(CP_INT_OPCODEERRORBV)) { 1456: kgsl_regwrite(device, GEN7_CP_BV_SQE_STAT_ADDR, 1); 1457: kgsl_regread(device, GEN7_CP_BV_SQE_STAT_DATA, &opcode); 1458: dev_crit_ratelimited(dev, "CP opcode error BV | opcode=0x%8.8x\n", opcode); 1459: } 1460: 1461: if (status1 & BIT(CP_INT_UCODEERRORBV)) 1462: dev_crit_ratelimited(dev, "CP ucode error BV\n"); 1463: 1464: if (status1 & BIT(CP_INT_CPHWFAULTBV)) { 1465: kgsl_regread(device, GEN7_CP_BV_HW_FAULT, &status2); 1466: dev_crit_ratelimited(dev, 1467: "CP BV | Ringbuffer HW fault | status=%x\n", status2); 1468: } 1469: 1470: if (status1 & BIT(CP_INT_REGISTERPROTECTIONBV)) { 1471: kgsl_regread(device, GEN7_CP_BV_PROTECT_STATUS, &status2); 1472: dev_crit_ratelimited(dev, 1473: "CP BV | Protected mode error | %s | addr=%x | status=%x\n", 1474: status2 & BIT(20) ? "READ" : "WRITE", 1475: status2 & 0x3ffff, status2); 1476: } 1477: 1478: if (status1 & BIT(CP_INT_ILLEGALINSTRUCTIONBV)) 1479: dev_crit_ratelimited(dev, "CP illegal instruction BV\n"); 1480: } 1481: } 1482: 1483: static void gen7_err_callback(struct adreno_device *adreno_dev, int bit) 1484: { 1485: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1486: struct device *dev = device->dev; 1487: 1488: switch (bit) { 1489: case GEN7_INT_AHBERROR: 1490: { 1491: u32 err_details_0, err_details_1; MATCH LINES: 2578 2566: .probe = gen7_gmu_device_probe, 2567: .snapshot = gen7_gmu_snapshot, 2568: .irq_handler = gen7_irq_handler, 2569: .rb_start = gen7_rb_start, 2570: .gpu_keepalive = gen7_gpu_keepalive, 2571: .hw_isidle = gen7_hw_isidle, 2572: .iommu_fault_block = gen7_iommu_fault_block, 2573: .reset = gen7_gmu_reset, 2574: .preemption_schedule = gen7_preemption_schedule, 2575: .read_alwayson = gen7_read_alwayson, 2576: .power_ops = &gen7_gmu_power_ops, 2577: .remove = gen7_remove, 2578: .ringbuffer_submitcmd = gen7_ringbuffer_submitcmd, 2579: .power_stats = gen7_power_stats, 2580: .add_to_va_minidump = gen7_gmu_add_to_minidump, 2581: .gx_is_on = gen7_gmu_gx_is_on, 2582: .perfcounter_remove = gen7_perfcounter_remove, 2583: .set_isdb_breakpoint_registers = gen7_set_isdb_breakpoint_registers, 2584: .swfuse_irqctrl = gen7_swfuse_irqctrl, 2585: .get_uche_trap_base = gen7_get_uche_trap_base, 2586: .fault_header = gen7_fault_header, 2587: .acquire_cp_semaphore = gen7_acquire_cp_semaphore, 2588: .release_cp_semaphore = gen7_release_cp_semaphore, 2589: }, 2590: .hfi_probe = gen7_gmu_hfi_probe, 2591: .handle_watchdog = gen7_gmu_handle_watchdog, 2592: }; --- FILE: \adreno_gen7.h | HITS: 17 --- MATCH LINES: 160 148: * GEN7_GMU_GENERAL_10 to tell the GMU firmware which chip it is 149: * running on. 150: */ 151: u32 gmu_chipid; 152: }; 153: 154: /** 155: * struct gen7_cp_preemption_record - CP context record for 156: * preemption. 157: * @magic: (00) Value at this offset must be equal to 158: * GEN7_CP_CTXRECORD_MAGIC_REF. 159: * @info: (04) Type of record. Written non-zero (usually) by CP. 160: * we must set to zero for all ringbuffers. 161: * @errno: (08) Error code. Initialize this to GEN7_CP_CTXRECORD_ERROR_NONE. 162: * CP will update to another value if a preemption error occurs. 163: * @data: (12) DATA field in YIELD and SET_MARKER packets. 164: * Written by CP when switching out. Not used on switch-in. Initialized to 0. 165: * @cntl: (16) RB_CNTL, saved and restored by CP. We must initialize this. 166: * @rptr: (20) RB_RPTR, saved and restored by CP. We must initialize this. 167: * @wptr: (24) RB_WPTR, saved and restored by CP. We must initialize this. 168: * @_pad28: (28) Reserved/padding. 169: * @rptr_addr: (32) RB_RPTR_ADDR_LO|HI saved and restored. We must initialize. 170: * rbase: (40) RB_BASE_LO|HI saved and restored. 171: * counter: (48) Pointer to preemption counter. 172: * @bv_rptr_addr: (56) BV_RB_RPTR_ADDR_LO|HI save and restored. We must initialize. 173: */ 174: struct gen7_cp_preemption_record { 175: u32 magic; 176: u32 info; 177: u32 errno; 178: u32 data; 179: u32 cntl; 180: u32 rptr; 181: u32 wptr; 182: u32 _pad28; 183: u64 rptr_addr; 184: u64 rbase; MATCH LINES: 271 259: return container_of(core, struct adreno_gen7_core, base); 260: } 261: 262: /* Preemption functions */ 263: void gen7_preemption_trigger(struct adreno_device *adreno_dev, bool atomic); 264: void gen7_preemption_schedule(struct adreno_device *adreno_dev); 265: void gen7_preemption_start(struct adreno_device *adreno_dev); 266: int gen7_preemption_init(struct adreno_device *adreno_dev); 267: 268: u32 gen7_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 269: unsigned int *cmds); 270: u32 gen7_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 271: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 272: u32 *cmds); 273: 274: void gen7_preemption_callback(struct adreno_device *adreno_dev, int bit); 275: 276: void gen7_preemption_context_destroy(struct kgsl_context *context); 277: 278: void gen7_preemption_prepare_postamble(struct adreno_device *adreno_dev); 279: 280: void gen7_snapshot(struct adreno_device *adreno_dev, 281: struct kgsl_snapshot *snapshot); 282: void gen7_crashdump_init(struct adreno_device *adreno_dev); 283: 284: /** 285: * gen7_snapshot_external_core_regs - Dump external registers into snapshot 286: * @device: Pointer to KGSL device 287: * @snapshot: Pointer to the snapshot 288: * 289: * Dump external core registers like GPUCC, CPR into GPU snapshot. 290: */ 291: void gen7_snapshot_external_core_regs(struct kgsl_device *device, 292: struct kgsl_snapshot *snapshot); 293: 294: /** 295: * gen7_start - Program gen7 registers MATCH LINES: 334, 337 322: */ 323: void gen7_cx_timer_init(struct adreno_device *adreno_dev); 324: 325: /** 326: * gen7_get_gpu_feature_info - Get hardware supported feature info 327: * @adreno_dev: Pointer to the adreno device 328: * 329: * Get HW supported feature info and update sofware feature configuration 330: */ 331: void gen7_get_gpu_feature_info(struct adreno_device *adreno_dev); 332: 333: /** 334: * gen7_rb_start - Gen7 specific ringbuffer setup 335: * @adreno_dev: An Adreno GPU handle 336: * 337: * This function does gen7 specific ringbuffer setup and 338: * attempts to submit CP INIT and bring GPU out of secure mode 339: * 340: * Return: Zero on success and negative error on failure 341: */ 342: int gen7_rb_start(struct adreno_device *adreno_dev); 343: 344: /** 345: * gen7_microcode_read - Get the cp microcode from the filesystem 346: * @adreno_dev: An Adreno GPU handle 347: * 348: * This function gets the firmware from filesystem and sets up 349: * the micorocode global buffer 350: * 351: * Return: Zero on success and negative error on failure 352: */ 353: int gen7_microcode_read(struct adreno_device *adreno_dev); 354: 355: /** 356: * gen7_probe_common - Probe common gen7 resources 357: * @pdev: Pointer to the platform device 358: * @adreno_dev: Pointer to the adreno device 359: * @chipid: Chipid of the target 360: * @gpucore: Pointer to the gpucore strucure 361: * MATCH LINES: 394, 397, 400, 403, 411, 416, 417, 422, 438, 440, 443, 450, 451 382: * @reg: Perfcounter reg struct to add/remove to the list 383: * @update_reg: true if the perfcounter needs to be programmed by the CPU 384: * @pipe: pipe id for CP aperture control 385: * @flags: Flags set for requested perfcounter group 386: * 387: * Return: 0 on success or -EBUSY if the lock couldn't be taken 388: */ 389: int gen7_perfcounter_update(struct adreno_device *adreno_dev, 390: struct adreno_perfcount_register *reg, bool update_reg, u32 pipe, 391: unsigned long flags); 392: 393: /* 394: * gen7_ringbuffer_init - Initialize the ringbuffers 395: * @adreno_dev: An Adreno GPU handle 396: * 397: * Initialize the ringbuffer(s) for a5xx. 398: * Return: 0 on success or negative on failure 399: */ 400: int gen7_ringbuffer_init(struct adreno_device *adreno_dev); 401: 402: /** 403: * gen7_ringbuffer_submitcmd - Submit a user command to the ringbuffer 404: * @adreno_dev: An Adreno GPU handle 405: * @cmdobj: Pointer to a user command object 406: * @flags: Internal submit flags 407: * @time: Optional pointer to a adreno_submit_time container 408: * 409: * Return: 0 on success or negative on failure 410: */ 411: int gen7_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 412: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 413: struct adreno_submit_time *time); 414: 415: /** 416: * gen7_ringbuffer_submit - Submit a command to the ringbuffer 417: * @rb: Ringbuffer pointer 418: * @time: Optional pointer to a adreno_submit_time container 419: * 420: * Return: 0 on success or negative on failure 421: */ 422: int gen7_ringbuffer_submit(struct adreno_ringbuffer *rb, 423: struct adreno_submit_time *time); 424: 425: /** 426: * gen7_fenced_write - Write to a fenced register 427: * @adreno_dev: An Adreno GPU handle 428: * @offset: Register offset 429: * @value: Value to write 430: * @mask: Expected FENCE_STATUS for successful write 431: * 432: * Return: 0 on success or negative on failure 433: */ 434: int gen7_fenced_write(struct adreno_device *adreno_dev, u32 offset, 435: u32 value, u32 mask); 436: 437: /** 438: * gen77ringbuffer_addcmds - Wrap and submit commands to the ringbuffer 439: * @adreno_dev: An Adreno GPU handle 440: * @rb: Ringbuffer pointer 441: * @drawctxt: Draw context submitting the commands 442: * @flags: Submission flags 443: * @in: Input buffer to write to ringbuffer 444: * @dwords: Dword length of @in 445: * @timestamp: Draw context timestamp for the submission 446: * @time: Optional pointer to a adreno_submit_time container 447: * 448: * Return: 0 on success or negative on failure 449: */ 450: int gen7_ringbuffer_addcmds(struct adreno_device *adreno_dev, 451: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 452: u32 flags, u32 *in, u32 dwords, u32 timestamp, 453: struct adreno_submit_time *time); 454: 455: /** 456: * gen7_cp_init_cmds - Create the CP_INIT commands 457: * @adreno_dev: An Adreno GPU handle 458: * @cmd: Buffer to write the CP_INIT commands into 459: */ 460: void gen7_cp_init_cmds(struct adreno_device *adreno_dev, u32 *cmds); 461: 462: /** 463: * gen7_gmu_hfi_probe - Probe Gen7 HFI specific data 464: * @adreno_dev: An Adreno GPU handle 465: * 466: * Return: 0 on success or negative on failure 467: */ 468: int gen7_gmu_hfi_probe(struct adreno_device *adreno_dev); 469: 470: static inline const struct gen7_gpudev * 471: to_gen7_gpudev(const struct adreno_gpudev *gpudev) 472: { 473: return container_of(gpudev, struct gen7_gpudev, base); 474: } 475: --- FILE: \adreno_gen7_gmu.c | HITS: 4 --- MATCH LINES: 837 825: dev_err(gmu_pdev_dev, 826: "Poll: %llx (ticks relative to start)\n", ts2-ts1); 827: dev_err(gmu_pdev_dev, 828: "RPMH_POWER_STATE=%x GFX_PWR_CLK_STATUS=%x\n", reg, reg1); 829: dev_err(gmu_pdev_dev, "CX_BUSY_STATUS=%x\n", reg2); 830: dev_err(gmu_pdev_dev, 831: "RBBM_INT_UNMASKED_STATUS=%x PWR_COL_KEEPALIVE=%x\n", reg3, reg4); 832: 833: /* Access GX registers only when GX is ON */ 834: if (is_on(reg1)) { 835: kgsl_regread(device, GEN7_CP_STATUS_1, ®2); 836: kgsl_regread(device, GEN7_CP_CP2GMU_STATUS, ®3); 837: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_CNTL, ®4); 838: 839: dev_err(gmu_pdev_dev, "GEN7_CP_STATUS_1=%x\n", reg2); 840: dev_err(gmu_pdev_dev, 841: "CP2GMU_STATUS=%x CONTEXT_SWITCH_CNTL=%x\n", reg3, reg4); 842: } 843: 844: WARN_ON(1); 845: gmu_core_fault_snapshot(device, GMU_FAULT_WAIT_FOR_LOWEST_IDLE); 846: return -ETIMEDOUT; 847: } 848: 849: /* Bitmask for GPU idle status check */ 850: #define CXGXCPUBUSYIGNAHB BIT(30) 851: int gen7_gmu_wait_for_idle(struct adreno_device *adreno_dev) 852: { 853: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 854: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 855: u32 status2; 856: u64 ts1; 857: 858: ts1 = gpudev->read_alwayson(adreno_dev); 859: if (gmu_core_timed_poll_check(device, GEN7_GPU_GMU_AO_GPU_CX_BUSY_STATUS, 860: 0, 100, CXGXCPUBUSYIGNAHB)) { 861: gmu_core_regread(device, MATCH LINES: 948 936: gmu_core_regwrite(device, GEN7_GPU_GMU_CX_GMU_CX_FAL_INTF, 0x1); 937: 938: /* Clear init result to make sure we are getting fresh value */ 939: gmu_core_regwrite(device, GEN7_GMU_CM3_FW_INIT_RESULT, 0); 940: gmu_core_regwrite(device, GEN7_GMU_CM3_BOOT_CONFIG, 0x2); 941: 942: gmu_core_regwrite(device, GEN7_GMU_HFI_QTBL_ADDR, 943: gmu->hfi.hfi_mem->gmuaddr); 944: gmu_core_regwrite(device, GEN7_GMU_HFI_QTBL_INFO, 1); 945: 946: gmu_core_regwrite(device, GEN7_GMU_AHB_FENCE_RANGE_0, BIT(31) | 947: FIELD_PREP(GENMASK(30, 18), 0x32) | 948: FIELD_PREP(GENMASK(17, 0), GEN7_CP_CONTEXT_SWITCH_CNTL)); 949: 950: /* 951: * Make sure that CM3 state is at reset value. Snapshot is changing 952: * NMI bit and if we boot up GMU with NMI bit set GMU will boot 953: * straight in to NMI handler without executing __main code 954: */ 955: gmu_core_regwrite(device, GEN7_GMU_CM3_CFG, 0x4052); 956: 957: /* Set up GBIF registers from the GPU core definition */ 958: kgsl_regmap_multi_write(&device->regmap, gen7_core->gbif, 959: gen7_core->gbif_count); 960: 961: if (adreno_is_gen7_13_0(adreno_dev) || adreno_is_gen7_9_x(adreno_dev)) 962: kgsl_regrmw(device, GEN7_GBIF_CX_CONFIG, GENMASK(31, 29), 963: FIELD_PREP(GENMASK(31, 29), 1)); 964: else if (adreno_is_gen7_14_0_family(adreno_dev)) 965: kgsl_regrmw(device, GEN7_GBIF_CX_CONFIG, GENMASK(31, 29), 966: FIELD_PREP(GENMASK(31, 29), 2)); 967: 968: /** 969: * We may have asserted gbif halt as part of reset sequence which may 970: * not get cleared if the gdsc was not reset. So clear it before 971: * attempting GMU boot. 972: */ MATCH LINES: 2438 2426: { 2427: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2428: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2429: int ret; 2430: 2431: if (test_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags)) { 2432: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 2433: return gen7_boot(adreno_dev); 2434: 2435: return 0; 2436: } 2437: 2438: ret = gen7_ringbuffer_init(adreno_dev); 2439: if (ret) 2440: return ret; 2441: 2442: ret = gen7_microcode_read(adreno_dev); 2443: if (ret) 2444: return ret; 2445: 2446: ret = gen7_init(adreno_dev); 2447: if (ret) 2448: return ret; 2449: 2450: ret = gen7_gmu_init(adreno_dev); 2451: if (ret) 2452: return ret; 2453: 2454: kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE); 2455: 2456: ret = gen7_gmu_first_boot(adreno_dev); 2457: if (ret) 2458: return ret; 2459: 2460: ret = gen7_gpu_boot(adreno_dev); 2461: if (ret) 2462: return ret; MATCH LINES: 2559 2547: 2548: no_gx_power: 2549: gen7_gmu_oob_clear(device, oob_gpu); 2550: 2551: kgsl_pwrctrl_irq(device, false); 2552: 2553: gen7_gmu_power_off(adreno_dev); 2554: 2555: adreno_set_active_ctxs_null(adreno_dev); 2556: 2557: adreno_dispatcher_stop(adreno_dev); 2558: 2559: adreno_ringbuffer_stop(adreno_dev); 2560: 2561: adreno_llcc_slice_deactivate(adreno_dev); 2562: 2563: clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags); 2564: 2565: kgsl_delete_timer_sync(&device->idle_timer); 2566: 2567: kgsl_pwrscale_sleep(device); 2568: 2569: kgsl_pwrctrl_clear_l3_vote(device); 2570: 2571: /* 2572: * Reset the context records so that CP can start 2573: * at the correct read pointer for BV thread after 2574: * coming out of slumber. 2575: */ 2576: gen7_reset_preempt_records(adreno_dev); 2577: 2578: kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER); 2579: 2580: return ret; 2581: } 2582: 2583: static void gmu_idle_check(struct work_struct *work) --- FILE: \adreno_gen7_hwsched.c | HITS: 3 --- MATCH LINES: 79, 80, 81 67: { 68: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 69: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 70: bool skip_memkind_rb = false; 71: u32 i; 72: bool parse_payload; 73: 74: gen7_gmu_snapshot(adreno_dev, snapshot); 75: 76: adreno_hwsched_parse_fault_cmdobj(adreno_dev, snapshot); 77: 78: /* 79: * First try to dump ringbuffers using context bad HFI payloads 80: * because they have all the ringbuffer parameters. If ringbuffer 81: * payloads are not present, fall back to dumping ringbuffers 82: * based on MEMKIND_RB 83: */ 84: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2) 85: parse_payload = adreno_hwsched_parse_payload_rb_legacy(adreno_dev, snapshot); 86: else 87: parse_payload = adreno_hwsched_parse_payload_rb(adreno_dev, snapshot); 88: 89: if (parse_payload) 90: skip_memkind_rb = true; 91: 92: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 93: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 94: 95: if (entry->desc.mem_kind == HFI_MEMKIND_RB && !skip_memkind_rb) 96: kgsl_snapshot_add_section(device, 97: KGSL_SNAPSHOT_SECTION_RB_V2, 98: snapshot, adreno_hwsched_snapshot_rb, 99: entry->md); 100: 101: if (entry->desc.mem_kind == HFI_MEMKIND_SCRATCH) 102: kgsl_snapshot_add_section(device, 103: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 104: snapshot, adreno_snapshot_global, 105: entry->md); --- FILE: \adreno_gen7_hwsched_hfi.c | HITS: 6 --- MATCH LINES: 311 299: status & (1 << 20) ? "READ" : "WRITE", 300: status & 0x3FFFF, status); 301: } 302: break; 303: case GMU_CP_ILLEGAL_INST_ERROR: 304: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 305: break; 306: case GMU_CP_UCODE_ERROR: 307: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 308: break; 309: case GMU_CP_HW_FAULT_ERROR: 310: dev_crit_ratelimited(gmu_pdev_dev, 311: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 312: gen7_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 313: KEY_CP_HW_FAULT)); 314: break; 315: case GMU_GPU_PREEMPT_TIMEOUT: { 316: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 317: 318: cur = gen7_hwsched_lookup_key_value_legacy(adreno_dev, 319: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 320: next = gen7_hwsched_lookup_key_value_legacy(adreno_dev, 321: PAYLOAD_PREEMPT_TIMEOUT, 322: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 323: cur_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_RPTR); 324: cur_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_WPTR); 325: next_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_RPTR); 326: next_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_WPTR); 327: 328: dev_crit_ratelimited(gmu_pdev_dev, 329: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 330: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 331: } 332: break; 333: case GMU_CP_GPC_ERROR: 334: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: GPC error\n"); 335: break; MATCH LINES: 354 342: case GMU_CP_BV_PROTECTED_ERROR: { 343: u32 status = gen7_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 344: KEY_CP_BV_PROTECTED_ERROR); 345: 346: dev_crit_ratelimited(gmu_pdev_dev, 347: "CP BV | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 348: status & (1 << 20) ? "READ" : "WRITE", 349: status & 0x3FFFF, status); 350: } 351: break; 352: case GMU_CP_BV_HW_FAULT_ERROR: 353: dev_crit_ratelimited(gmu_pdev_dev, 354: "CP BV | Ringbuffer HW fault | status=0x%8.8x\n", 355: gen7_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 356: KEY_CP_BV_HW_FAULT)); 357: break; 358: case GMU_CP_BV_ILLEGAL_INST_ERROR: 359: dev_crit_ratelimited(gmu_pdev_dev, "CP BV Illegal instruction error\n"); 360: break; 361: case GMU_CP_BV_UCODE_ERROR: 362: dev_crit_ratelimited(gmu_pdev_dev, "CP BV ucode error interrupt\n"); 363: break; 364: case GMU_GPU_SW_FUSE_VIOLATION: 365: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: SW Feature Fuse violation status=0x%8.8x\n", 366: gen7_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 367: KEY_SWFUSE_VIOLATION_FAULT)); 368: break; 369: case GMU_GPU_AQE0_OPCODE_ERROR: 370: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 opcode error | opcode=0x%8.8x\n", 371: gen7_hwsched_lookup_key_value_legacy(adreno_dev, 372: PAYLOAD_FAULT_REGS, KEY_AQE0_OPCODE_ERROR)); 373: break; 374: case GMU_GPU_AQE0_UCODE_ERROR: 375: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 ucode error interrupt\n"); 376: break; 377: case GMU_GPU_AQE0_HW_FAULT_ERROR: 378: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 HW fault | status=0x%8.8x\n", MATCH LINES: 484 472: status & (1 << 20) ? "READ" : "WRITE", 473: status & 0x3FFFF, status); 474: } 475: break; 476: case GMU_CP_ILLEGAL_INST_ERROR: 477: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 478: break; 479: case GMU_CP_UCODE_ERROR: 480: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 481: break; 482: case GMU_CP_HW_FAULT_ERROR: 483: dev_crit_ratelimited(gmu_pdev_dev, 484: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 485: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 486: KEY_CP_HW_FAULT)); 487: break; 488: case GMU_GPU_PREEMPT_TIMEOUT: { 489: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 490: 491: cur = gen7_hwsched_lookup_key_value(adreno_dev, 492: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 493: next = gen7_hwsched_lookup_key_value(adreno_dev, 494: PAYLOAD_PREEMPT_TIMEOUT, 495: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 496: cur_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_RPTR); 497: cur_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_WPTR); 498: next_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_RPTR); 499: next_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_WPTR); 500: 501: dev_crit_ratelimited(gmu_pdev_dev, 502: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 503: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 504: } 505: break; 506: case GMU_CP_GPC_ERROR: 507: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: GPC error\n"); 508: break; MATCH LINES: 527, 555 515: case GMU_CP_BV_PROTECTED_ERROR: { 516: u32 status = gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 517: KEY_CP_BV_PROTECTED_ERROR); 518: 519: dev_crit_ratelimited(gmu_pdev_dev, 520: "CP BV | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 521: status & (1 << 20) ? "READ" : "WRITE", 522: status & 0x3FFFF, status); 523: } 524: break; 525: case GMU_CP_BV_HW_FAULT_ERROR: 526: dev_crit_ratelimited(gmu_pdev_dev, 527: "CP BV | Ringbuffer HW fault | status=0x%8.8x\n", 528: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 529: KEY_CP_BV_HW_FAULT)); 530: break; 531: case GMU_CP_BV_ILLEGAL_INST_ERROR: 532: dev_crit_ratelimited(gmu_pdev_dev, "CP BV Illegal instruction error\n"); 533: break; 534: case GMU_CP_BV_UCODE_ERROR: 535: dev_crit_ratelimited(gmu_pdev_dev, "CP BV ucode error interrupt\n"); 536: break; 537: case GMU_CP_LPAC_OPCODE_ERROR: 538: dev_crit_ratelimited(gmu_pdev_dev, 539: "CP LPAC opcode error | opcode=0x%8.8x\n", 540: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 541: KEY_CP_LPAC_OPCODE_ERROR)); 542: break; 543: case GMU_CP_LPAC_PROTECTED_ERROR: { 544: u32 status = gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 545: KEY_CP_LPAC_PROTECTED_ERROR); 546: 547: dev_crit_ratelimited(gmu_pdev_dev, 548: "CP LPAC | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 549: status & (1 << 20) ? "READ" : "WRITE", 550: status & 0x3FFFF, status); 551: } 552: break; 553: case GMU_CP_LPAC_HW_FAULT_ERROR: 554: dev_crit_ratelimited(gmu_pdev_dev, 555: "CP LPAC | Ringbuffer HW fault | status=0x%8.8x\n", 556: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 557: KEY_CP_LPAC_HW_FAULT)); 558: break; 559: case GMU_CP_LPAC_ILLEGAL_INST_ERROR: 560: dev_crit_ratelimited(gmu_pdev_dev, "CP LPAC Illegal instruction error\n"); 561: break; 562: case GMU_CP_LPAC_UCODE_ERROR: 563: dev_crit_ratelimited(gmu_pdev_dev, "CP LPAC ucode error interrupt\n"); 564: break; 565: case GMU_GPU_LPAC_SW_HANG: 566: dev_crit_ratelimited(gmu_pdev_dev, "LPAC: gpu timeout ctx %u ts %u\n", 567: cmd->lpac.ctxt_id, cmd->lpac.ts); 568: break; 569: case GMU_GPU_SW_FUSE_VIOLATION: 570: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: SW Feature Fuse violation status=0x%8.8x\n", 571: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 572: KEY_SWFUSE_VIOLATION_FAULT)); 573: break; 574: case GMU_GPU_AQE0_OPCODE_ERROR: 575: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 opcode error | opcode=0x%8.8x\n", 576: gen7_hwsched_lookup_key_value(adreno_dev, 577: PAYLOAD_FAULT_REGS, KEY_AQE0_OPCODE_ERROR)); 578: break; 579: case GMU_GPU_AQE0_UCODE_ERROR: MATCH LINES: 1707 1695: if (pwr->rt_pwrlevel_hint != INVALID_DCVS_IDX) { 1696: ret = gen7_hfi_send_set_value(adreno_dev, HFI_VALUE_RB_GPULEVEL_RULE, 0, 1697: pwr->num_pwrlevels - pwr->rt_pwrlevel_hint); 1698: if (ret) { 1699: dev_err(GMU_PDEV_DEV(device), "Failed to set rt pwrlevel hint %u, ret: %d\n", 1700: pwr->rt_pwrlevel_hint, ret); 1701: pwr->rt_pwrlevel_hint = INVALID_DCVS_IDX; 1702: } 1703: } 1704: } 1705: 1706: /* 1707: * Bits[3:0] contain the preemption timeout enable bit per ringbuffer 1708: * Bits[31:4] contain the timeout in ms 1709: */ 1710: return gen7_hfi_send_set_value(adreno_dev, HFI_VALUE_BIN_TIME, 1, 1711: FIELD_PREP(GENMASK(31, 4), ADRENO_PREEMPT_TIMEOUT) | 1712: FIELD_PREP(GENMASK(3, 0), 0xf)); 1713: 1714: } 1715: 1716: static int enable_gmu_stats(struct adreno_device *adreno_dev) 1717: { 1718: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 1719: u32 data; 1720: 1721: if (!gmu->stats_enable) 1722: return 0; 1723: 1724: /* 1725: * Bits [23:0] contains the countables mask 1726: * Bits [31:24] is the sampling interval 1727: */ 1728: data = FIELD_PREP(GENMASK(23, 0), gmu->stats_mask) | 1729: FIELD_PREP(GENMASK(31, 24), gmu->stats_interval); 1730: 1731: return gen7_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_GMU_STATS, 1, data); --- FILE: \adreno_gen7_perfcounter.c | HITS: 3 --- MATCH LINES: 74, 86, 100 62: FIELD_PREP(GENMASK(13, 12), PIPE_NONE), group->flags); 63: if (!ret) 64: reg->value = 0; 65: 66: return ret; 67: } 68: 69: static int gen7_swsched_counter_inline_enable(struct adreno_device *adreno_dev, 70: const struct adreno_perfcount_group *group, 71: unsigned int counter, unsigned int countable) 72: { 73: struct adreno_perfcount_register *reg = &group->regs[counter]; 74: struct adreno_ringbuffer *rb = &adreno_dev->ringbuffers[0]; 75: u32 cmds[3]; 76: int ret; 77: 78: gen7_perfcounter_update(adreno_dev, reg, false, 79: FIELD_PREP(GENMASK(13, 12), PIPE_NONE), group->flags); 80: 81: cmds[0] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 82: cmds[1] = cp_type4_packet(reg->select, 1); 83: cmds[2] = countable; 84: 85: /* submit to highest priority RB always */ 86: ret = gen7_ringbuffer_addcmds(adreno_dev, rb, NULL, 87: F_NOTPROTECTED, cmds, 3, 0, NULL); 88: if (ret) 89: return ret; 90: 91: /* 92: * schedule dispatcher to make sure rb[0] is run, because 93: * if the current RB is not rb[0] and gpu is idle then 94: * rb[0] will not get scheduled to run 95: */ 96: if (adreno_dev->cur_rb != rb) 97: adreno_scheduler_queue(adreno_dev); 98: 99: /* wait for the above commands submitted to complete */ 100: ret = adreno_ringbuffer_waittimestamp(rb, rb->timestamp, 101: ADRENO_IDLE_TIMEOUT); 102: 103: if (ret) { 104: /* 105: * If we were woken up because of cancelling rb events 106: * either due to soft reset or adreno_stop, ignore the 107: * error and return 0 here. The perfcounter is already 108: * set up in software and it will be programmed in 109: * hardware when we wake up or come up after soft reset, 110: * by adreno_perfcounter_restore. 111: */ 112: if (ret == -EAGAIN) 113: ret = 0; 114: else 115: dev_err_ratelimited(KGSL_DEVICE(adreno_dev)->dev, 116: "Perfcounter %s/%u/%u start via commands failed %d\n", 117: group->name, counter, countable, ret); 118: } 119: 120: if (!ret) 121: reg->value = 0; 122: 123: return ret; 124: } --- FILE: \adreno_gen7_preempt.c | HITS: 40 --- MATCH LINES: 23 11: #include "kgsl_util.h" 12: 13: #define PREEMPT_RECORD(_field) \ 14: offsetof(struct gen7_cp_preemption_record, _field) 15: 16: #define PREEMPT_SMMU_RECORD(_field) \ 17: offsetof(struct gen7_cp_smmu_info, _field) 18: 19: static void _update_wptr(struct adreno_device *adreno_dev, bool reset_timer, 20: bool atomic) 21: { 22: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 23: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 24: unsigned long flags; 25: int ret = 0; 26: 27: spin_lock_irqsave(&rb->preempt_lock, flags); 28: 29: if (!atomic) { 30: /* 31: * We might have skipped updating the wptr in case we are in 32: * dispatcher context. Do it now. 33: */ 34: if (rb->skip_inline_wptr) { 35: 36: ret = gen7_fenced_write(adreno_dev, 37: GEN7_CP_RB_WPTR, rb->wptr, 38: FENCE_STATUS_WRITEDROPPED0_MASK); 39: 40: reset_timer = true; 41: rb->skip_inline_wptr = false; 42: } 43: } else { 44: unsigned int wptr; 45: 46: kgsl_regread(device, GEN7_CP_RB_WPTR, &wptr); 47: if (wptr != rb->wptr) { MATCH LINES: 90, 112, 143 78: { 79: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 80: unsigned int status; 81: 82: /* 83: * In the very unlikely case that the power is off, do nothing - the 84: * state will be reset on power up and everybody will be happy 85: */ 86: 87: if (!kgsl_state_is_awake(device)) 88: return; 89: 90: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_CNTL, &status); 91: 92: if (status & 0x1) { 93: dev_err(device->dev, 94: "Preemption not complete: status=%X cur=%d R/W=%X/%X next=%d R/W=%X/%X\n", 95: status, adreno_dev->cur_rb->id, 96: adreno_get_rptr(adreno_dev->cur_rb), 97: adreno_dev->cur_rb->wptr, 98: adreno_dev->next_rb->id, 99: adreno_get_rptr(adreno_dev->next_rb), 100: adreno_dev->next_rb->wptr); 101: 102: /* Set a fault and restart */ 103: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 104: 105: return; 106: } 107: 108: adreno_dev->preempt.count++; 109: 110: kgsl_delete_timer_sync(&adreno_dev->preempt.timer); 111: 112: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 113: 114: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 115: status, 0); 116: 117: /* Clean up all the bits */ 118: adreno_dev->prev_rb = adreno_dev->cur_rb; 119: adreno_dev->cur_rb = adreno_dev->next_rb; 120: adreno_dev->next_rb = NULL; 121: 122: /* Update the wptr for the new command queue */ 123: _update_wptr(adreno_dev, true, false); 124: 125: /* Update the dispatcher timer for the new command queue */ 126: mod_timer(&adreno_dev->dispatcher.timer, 127: adreno_dev->cur_rb->dispatch_q.expires); 128: 129: /* Clear the preempt state */ 130: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 131: } 132: 133: static void _gen7_preemption_fault(struct adreno_device *adreno_dev) 134: { 135: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 136: unsigned int status; 137: 138: /* 139: * If the power is on check the preemption status one more time - if it 140: * was successful then just transition to the complete state 141: */ 142: if (kgsl_state_is_awake(device)) { 143: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_CNTL, &status); 144: 145: if (!(status & 0x1)) { 146: adreno_set_preempt_state(adreno_dev, 147: ADRENO_PREEMPT_COMPLETE); 148: 149: adreno_scheduler_queue(adreno_dev); 150: return; 151: } 152: } 153: 154: dev_err(device->dev, 155: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 156: adreno_dev->cur_rb->id, 157: adreno_get_rptr(adreno_dev->cur_rb), 158: adreno_dev->cur_rb->wptr, 159: adreno_dev->next_rb->id, 160: adreno_get_rptr(adreno_dev->next_rb), 161: adreno_dev->next_rb->wptr); 162: 163: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 164: } 165: 166: static void _gen7_preemption_worker(struct work_struct *work) 167: { MATCH LINES: 183, 184, 187, 191, 210, 221, 222, 225, 226, 231 171: struct adreno_device, preempt); 172: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 173: 174: /* Need to take the mutex to make sure that the power stays on */ 175: kgsl_mutex_lock(&device->mutex); 176: 177: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_FAULTED)) 178: _gen7_preemption_fault(adreno_dev); 179: 180: kgsl_mutex_unlock(&device->mutex); 181: } 182: 183: /* Find the highest priority active ringbuffer */ 184: static struct adreno_ringbuffer *gen7_next_ringbuffer( 185: struct adreno_device *adreno_dev) 186: { 187: struct adreno_ringbuffer *rb; 188: unsigned long flags; 189: unsigned int i; 190: 191: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 192: bool empty; 193: 194: spin_lock_irqsave(&rb->preempt_lock, flags); 195: empty = adreno_rb_empty(rb); 196: spin_unlock_irqrestore(&rb->preempt_lock, flags); 197: 198: if (!empty) 199: return rb; 200: } 201: 202: return NULL; 203: } 204: 205: void gen7_preemption_trigger(struct adreno_device *adreno_dev, bool atomic) 206: { 207: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 208: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 209: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 210: struct adreno_ringbuffer *next; 211: u64 ttbr0, gpuaddr; 212: u32 contextidr, cntl; 213: unsigned long flags; 214: struct adreno_preemption *preempt = &adreno_dev->preempt; 215: 216: /* Put ourselves into a possible trigger state */ 217: if (!adreno_move_preempt_state(adreno_dev, 218: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START)) 219: return; 220: 221: /* Get the next ringbuffer to preempt in */ 222: next = gen7_next_ringbuffer(adreno_dev); 223: 224: /* 225: * Nothing to do if every ringbuffer is empty or if the current 226: * ringbuffer is the only active one 227: */ 228: if (next == NULL || next == adreno_dev->cur_rb) { 229: /* 230: * Update any critical things that might have been skipped while 231: * we were looking for a new ringbuffer 232: */ 233: 234: if (next != NULL) { 235: _update_wptr(adreno_dev, false, atomic); 236: 237: mod_timer(&adreno_dev->dispatcher.timer, 238: adreno_dev->cur_rb->dispatch_q.expires); 239: } 240: 241: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 242: return; 243: } 244: 245: /* Turn off the dispatcher timer */ 246: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 247: 248: /* 249: * This is the most critical section - we need to take care not to race 250: * until we have programmed the CP for the switch 251: */ 252: 253: spin_lock_irqsave(&next->preempt_lock, flags); 254: 255: /* Get the pagetable from the pagetable info. */ MATCH LINES: 297, 315, 322, 328, 335, 341, 373, 405, 433 285: * It is more efficient to use a keepalive+wake-on-fence approach here 286: * rather than an OOB. Both keepalive and the fence are effectively 287: * free when the GPU is already powered on, whereas an OOB requires an 288: * unconditional handshake with the GMU. 289: */ 290: _power_collapse_set(adreno_dev, true); 291: 292: /* 293: * Fenced writes on this path will make sure the GPU is woken up 294: * in case it was power collapsed by the GMU. 295: */ 296: if (gen7_fenced_write(adreno_dev, 297: GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO, 298: lower_32_bits(next->preemption_desc->gpuaddr), 299: FENCE_STATUS_WRITEDROPPED1_MASK)) 300: goto err; 301: 302: /* 303: * Above fence writes will make sure GMU comes out of 304: * IFPC state if its was in IFPC state but it doesn't 305: * guarantee that GMU FW actually moved to ACTIVE state 306: * i.e. wake-up from IFPC is complete. 307: * Wait for GMU to move to ACTIVE state before triggering 308: * preemption. This is require to make sure CP doesn't 309: * interrupt GMU during wake-up from IFPC. 310: */ 311: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 312: goto err; 313: 314: if (gen7_fenced_write(adreno_dev, 315: GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI, 316: upper_32_bits(next->preemption_desc->gpuaddr), 317: FENCE_STATUS_WRITEDROPPED1_MASK)) 318: goto err; 319: 320: if (kgsl_mmu_is_secured(&device->mmu)) { 321: if (gen7_fenced_write(adreno_dev, 322: GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO, 323: lower_32_bits(next->secure_preemption_desc->gpuaddr), 324: FENCE_STATUS_WRITEDROPPED1_MASK)) 325: goto err; 326: 327: if (gen7_fenced_write(adreno_dev, 328: GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI, 329: upper_32_bits(next->secure_preemption_desc->gpuaddr), 330: FENCE_STATUS_WRITEDROPPED1_MASK)) 331: goto err; 332: } 333: 334: if (gen7_fenced_write(adreno_dev, 335: GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO, 336: lower_32_bits(gpuaddr), 337: FENCE_STATUS_WRITEDROPPED1_MASK)) 338: goto err; 339: 340: if (gen7_fenced_write(adreno_dev, 341: GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI, 342: upper_32_bits(gpuaddr), 343: FENCE_STATUS_WRITEDROPPED1_MASK)) 344: goto err; 345: 346: adreno_dev->next_rb = next; 347: 348: /* Start the timer to detect a stuck preemption */ 349: mod_timer(&adreno_dev->preempt.timer, 350: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 351: 352: cntl = (preempt->preempt_level << 6) | 0x01; 353: 354: /* Skip save/restore during L1 preemption */ 355: if (preempt->skipsaverestore) 356: cntl |= (1 << 9); 357: 358: /* Enable GMEM save/restore across preemption */ 359: if (preempt->usesgmem) 360: cntl |= (1 << 8); 361: 362: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 363: cntl, 0); 364: 365: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 366: 367: if (gen7_core->qos_value) 368: kgsl_sharedmem_writel(preempt->scratch, 369: PREEMPT_SCRATCH_OFFSET(QOS_VALUE_IDX), 370: gen7_core->qos_value[next->id]); 371: 372: /* Trigger the preemption */ 373: if (gen7_fenced_write(adreno_dev, GEN7_CP_CONTEXT_SWITCH_CNTL, cntl, 374: FENCE_STATUS_WRITEDROPPED1_MASK)) { 375: adreno_dev->next_rb = NULL; 376: kgsl_delete_timer(&adreno_dev->preempt.timer); 377: goto err; 378: } 379: 380: return; 381: err: 382: /* If fenced write fails, take inline snapshot and trigger recovery */ 383: if (!in_interrupt()) { 384: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 385: adreno_scheduler_fault(adreno_dev, 386: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 387: } else { 388: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 389: } 390: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 391: /* Clear the keep alive */ 392: _power_collapse_set(adreno_dev, false); 393: 394: } 395: 396: void gen7_preemption_callback(struct adreno_device *adreno_dev, int bit) 397: { 398: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 399: unsigned int status; 400: 401: if (!adreno_move_preempt_state(adreno_dev, 402: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 403: return; 404: 405: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_CNTL, &status); 406: 407: if (status & 0x1) { 408: dev_err(KGSL_DEVICE(adreno_dev)->dev, 409: "preempt interrupt with non-zero status: %X\n", 410: status); 411: 412: /* 413: * Under the assumption that this is a race between the 414: * interrupt and the register, schedule the worker to clean up. 415: * If the status still hasn't resolved itself by the time we get 416: * there then we have to assume something bad happened 417: */ 418: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE); 419: adreno_scheduler_queue(adreno_dev); 420: return; 421: } 422: 423: adreno_dev->preempt.count++; 424: 425: /* 426: * We can now safely clear the preemption keepalive bit, allowing 427: * power collapse to resume its regular activity. 428: */ 429: _power_collapse_set(adreno_dev, false); 430: 431: kgsl_delete_timer(&adreno_dev->preempt.timer); 432: 433: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 434: 435: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 436: status, 0); 437: 438: adreno_dev->prev_rb = adreno_dev->cur_rb; 439: adreno_dev->cur_rb = adreno_dev->next_rb; 440: adreno_dev->next_rb = NULL; 441: 442: /* Update the wptr if it changed while preemption was ongoing */ 443: _update_wptr(adreno_dev, true, true); 444: 445: /* Update the dispatcher timer for the new command queue */ 446: mod_timer(&adreno_dev->dispatcher.timer, 447: adreno_dev->cur_rb->dispatch_q.expires); 448: 449: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 450: 451: gen7_preemption_trigger(adreno_dev, true); 452: } 453: 454: void gen7_preemption_prepare_postamble(struct adreno_device *adreno_dev) 455: { 456: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 457: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); MATCH LINES: 523, 559, 585, 594, 607, 629, 632, 636, 642, 650, 671, 676, 681, 682 511: 512: kgsl_mutex_lock(&device->mutex); 513: 514: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE)) 515: _gen7_preemption_done(adreno_dev); 516: 517: gen7_preemption_trigger(adreno_dev, false); 518: 519: kgsl_mutex_unlock(&device->mutex); 520: } 521: 522: u32 gen7_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 523: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 524: u32 *cmds) 525: { 526: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 527: u32 count = kgsl_mmu_is_secured(&device->mmu) ? 12 : 9; 528: u32 *cmds_orig = cmds; 529: 530: if (!adreno_is_preemption_enabled(adreno_dev)) 531: return 0; 532: 533: if (test_and_set_bit(ADRENO_RB_SET_PSEUDO_DONE, &rb->flags)) 534: goto done; 535: 536: *cmds++ = cp_type7_packet(CP_THREAD_CONTROL, 1); 537: *cmds++ = CP_SET_THREAD_BR; 538: 539: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, count); 540: 541: /* NULL SMMU_INFO buffer - we track in KMD */ 542: *cmds++ = SET_PSEUDO_SMMU_INFO; 543: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 544: 545: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 546: cmds += cp_gpuaddr(adreno_dev, cmds, rb->preemption_desc->gpuaddr); 547: 548: if (kgsl_mmu_is_secured(&device->mmu)) { 549: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 550: cmds += cp_gpuaddr(adreno_dev, cmds, 551: rb->secure_preemption_desc->gpuaddr); 552: } 553: 554: /* 555: * There is no need to specify this address when we are about to 556: * trigger preemption. This is because CP internally stores this 557: * address specified here in the CP_SET_PSEUDO_REGISTER payload to 558: * the context record and thus knows from where to restore 559: * the saved perfcounters for the new ringbuffer. 560: */ 561: *cmds++ = SET_PSEUDO_COUNTER; 562: cmds += cp_gpuaddr(adreno_dev, cmds, 563: rb->perfcounter_save_restore_desc->gpuaddr); 564: 565: done: 566: if (drawctxt) { 567: cmds += adreno_prepare_preib_preempt_scratch(adreno_dev, drawctxt, cmds); 568: cmds += adreno_prepare_preib_postamble_scratch(adreno_dev, cmds); 569: } 570: 571: return (u32) (cmds - cmds_orig); 572: } 573: 574: u32 gen7_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 575: u32 *cmds) 576: { 577: u32 index = 0; 578: 579: if (!adreno_is_preemption_enabled(adreno_dev)) 580: return 0; 581: 582: if (adreno_dev->cur_rb) { 583: u64 dest = PREEMPT_SCRATCH_ADDR(adreno_dev, adreno_dev->cur_rb->id); 584: 585: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 4); 586: cmds[index++] = lower_32_bits(dest); 587: cmds[index++] = upper_32_bits(dest); 588: cmds[index++] = 0; 589: cmds[index++] = 0; 590: } 591: 592: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 593: cmds[index++] = CP_SET_THREAD_BOTH; 594: cmds[index++] = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 595: cmds[index++] = 0; 596: cmds[index++] = 0; 597: cmds[index++] = 1; 598: cmds[index++] = 0; 599: 600: return index; 601: } 602: 603: void gen7_preemption_start(struct adreno_device *adreno_dev) 604: { 605: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 606: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 607: struct adreno_ringbuffer *rb; 608: unsigned int i; 609: 610: if (!adreno_is_preemption_enabled(adreno_dev)) 611: return; 612: 613: /* Force the state to be clear */ 614: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 615: 616: if (kgsl_mmu_is_perprocess(&device->mmu)) { 617: /* smmu_info is allocated and mapped in gen7_preemption_iommu_init */ 618: kgsl_sharedmem_writel(iommu->smmu_info, 619: PREEMPT_SMMU_RECORD(magic), GEN7_CP_SMMU_INFO_MAGIC_REF); 620: kgsl_sharedmem_writeq(iommu->smmu_info, 621: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 622: 623: /* The CP doesn't use the asid record, so poison it */ 624: kgsl_sharedmem_writel(iommu->smmu_info, 625: PREEMPT_SMMU_RECORD(asid), 0xdecafbad); 626: kgsl_sharedmem_writel(iommu->smmu_info, 627: PREEMPT_SMMU_RECORD(context_idr), 0); 628: 629: kgsl_regwrite(device, GEN7_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 630: lower_32_bits(iommu->smmu_info->gpuaddr)); 631: 632: kgsl_regwrite(device, GEN7_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 633: upper_32_bits(iommu->smmu_info->gpuaddr)); 634: } 635: 636: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 637: kgsl_sharedmem_writel(rb->preemption_desc, 638: PREEMPT_RECORD(rptr), 0); 639: kgsl_sharedmem_writel(rb->preemption_desc, 640: PREEMPT_RECORD(wptr), 0); 641: 642: adreno_ringbuffer_set_pagetable(device, rb, 643: device->mmu.defaultpagetable); 644: 645: clear_bit(ADRENO_RB_SET_PSEUDO_DONE, &rb->flags); 646: } 647: } 648: 649: static void reset_rb_preempt_record(struct adreno_device *adreno_dev, 650: struct adreno_ringbuffer *rb) 651: { 652: memset(rb->preemption_desc->hostptr, 0x0, rb->preemption_desc->size); 653: 654: kgsl_sharedmem_writel(rb->preemption_desc, 655: PREEMPT_RECORD(magic), GEN7_CP_CTXRECORD_MAGIC_REF); 656: kgsl_sharedmem_writel(rb->preemption_desc, 657: PREEMPT_RECORD(cntl), GEN7_CP_RB_CNTL_DEFAULT); 658: kgsl_sharedmem_writeq(rb->preemption_desc, 659: PREEMPT_RECORD(rptr_addr), SCRATCH_RB_GPU_ADDR( 660: KGSL_DEVICE(adreno_dev), rb->id, rptr)); 661: kgsl_sharedmem_writeq(rb->preemption_desc, 662: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 663: kgsl_sharedmem_writeq(rb->preemption_desc, 664: PREEMPT_RECORD(bv_rptr_addr), SCRATCH_RB_GPU_ADDR( 665: KGSL_DEVICE(adreno_dev), rb->id, bv_rptr)); 666: } 667: 668: void gen7_reset_preempt_records(struct adreno_device *adreno_dev) 669: { 670: int i; 671: struct adreno_ringbuffer *rb; 672: 673: if (!adreno_is_preemption_enabled(adreno_dev)) 674: return; 675: 676: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 677: reset_rb_preempt_record(adreno_dev, rb); 678: } 679: } 680: 681: static int gen7_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 682: struct adreno_ringbuffer *rb) 683: { 684: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 685: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 686: u64 ctxt_record_size = GEN7_CP_CTXRECORD_SIZE_IN_BYTES; 687: int ret; 688: 689: if (gen7_core->ctxt_record_size) 690: ctxt_record_size = gen7_core->ctxt_record_size; 691: 692: ret = adreno_allocate_global(device, &rb->preemption_desc, 693: ctxt_record_size, SZ_16K, 0, 694: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 695: if (ret) 696: return ret; 697: 698: if (kgsl_mmu_is_secured(&device->mmu)) { 699: ret = adreno_allocate_global(device, &rb->secure_preemption_desc, 700: ctxt_record_size, 0, 701: KGSL_MEMFLAGS_SECURE, KGSL_MEMDESC_PRIVILEGED, 702: "secure_preemption_desc"); 703: if (ret) 704: return ret; 705: } 706: MATCH LINES: 725, 738, 739 713: 714: reset_rb_preempt_record(adreno_dev, rb); 715: 716: return 0; 717: } 718: 719: int gen7_preemption_init(struct adreno_device *adreno_dev) 720: { 721: u32 flags = ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? KGSL_MEMDESC_PRIVILEGED : 0; 722: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 723: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 724: struct adreno_preemption *preempt = &adreno_dev->preempt; 725: struct adreno_ringbuffer *rb; 726: int ret; 727: unsigned int i; 728: 729: /* We are dependent on IOMMU to make preemption go on the CP side */ 730: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) { 731: ret = -ENODEV; 732: goto done; 733: } 734: 735: INIT_WORK(&preempt->work, _gen7_preemption_worker); 736: 737: /* Allocate mem for storing preemption switch record */ 738: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 739: ret = gen7_preemption_ringbuffer_init(adreno_dev, rb); 740: if (ret) 741: goto done; 742: } 743: 744: ret = adreno_allocate_global(device, &preempt->scratch, PAGE_SIZE, 745: 0, 0, flags, "preempt_scratch"); 746: if (ret) 747: goto done; 748: 749: /* Allocate mem for storing preemption smmu record */ 750: if (kgsl_mmu_is_perprocess(&device->mmu)) { 751: ret = adreno_allocate_global(device, &iommu->smmu_info, PAGE_SIZE, 0, 752: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 753: "smmu_info"); 754: if (ret) 755: goto done; 756: } 757: 758: return 0; 759: done: 760: clear_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 761: return ret; 762: } --- FILE: \adreno_gen7_ringbuffer.c | HITS: 41 --- MATCH LINES: 10, 23, 40, 61, 91 1: // SPDX-License-Identifier: GPL-2.0-only 2: /* 3: * Copyright (c) 2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include "adreno.h" 8: #include "adreno_gen7.h" 9: #include "adreno_pm4types.h" 10: #include "adreno_ringbuffer.h" 11: #include "adreno_trace.h" 12: #include "kgsl_trace.h" 13: 14: static bool is_concurrent_binning(struct adreno_context *drawctxt) 15: { 16: if (!drawctxt) 17: return false; 18: 19: return !(drawctxt->base.flags & KGSL_CONTEXT_SECURE); 20: } 21: 22: static int gen7_rb_pagetable_switch(struct adreno_device *adreno_dev, 23: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 24: struct kgsl_pagetable *pagetable, u32 *cmds) 25: { 26: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 27: u64 ttbr0 = kgsl_mmu_pagetable_get_ttbr0(pagetable); 28: int count = 0; 29: u32 id = drawctxt ? drawctxt->base.id : 0; 30: 31: if (pagetable == device->mmu.defaultpagetable) 32: return 0; 33: 34: /* CP switches the pagetable and flushes the Caches */ 35: cmds[count++] = cp_type7_packet(CP_SMMU_TABLE_UPDATE, 3); 36: cmds[count++] = lower_32_bits(ttbr0); 37: cmds[count++] = upper_32_bits(ttbr0); 38: cmds[count++] = id; 39: 40: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 5); 41: cmds[count++] = lower_32_bits(SCRATCH_RB_GPU_ADDR(device, 42: rb->id, ttbr0)); 43: cmds[count++] = upper_32_bits(SCRATCH_RB_GPU_ADDR(device, 44: rb->id, ttbr0)); 45: cmds[count++] = lower_32_bits(ttbr0); 46: cmds[count++] = upper_32_bits(ttbr0); 47: cmds[count++] = id; 48: 49: /* 50: * Sync both threads after switching pagetables and enable BR only 51: * to make sure BV doesn't race ahead while BR is still switching 52: * pagetables. 53: */ 54: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 55: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BR; 56: 57: return count; 58: } 59: 60: static int gen7_rb_context_switch(struct adreno_device *adreno_dev, 61: struct adreno_ringbuffer *rb, 62: struct adreno_context *drawctxt) 63: { 64: struct kgsl_pagetable *pagetable = 65: adreno_drawctxt_get_pagetable(drawctxt); 66: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 67: int count = 0; 68: u32 cmds[61]; 69: 70: /* Sync both threads */ 71: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 72: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BOTH; 73: /* Reset context state */ 74: cmds[count++] = cp_type7_packet(CP_RESET_CONTEXT_STATE, 1); 75: cmds[count++] = CP_RESET_GLOBAL_LOCAL_TS | CP_CLEAR_BV_BR_COUNTER | 76: CP_CLEAR_RESOURCE_TABLE | CP_CLEAR_ON_CHIP_TS; 77: /* 78: * Enable/disable concurrent binning for pagetable switch and 79: * set the thread to BR since only BR can execute the pagetable 80: * switch packets. 81: */ 82: /* Sync both threads and enable BR only */ 83: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 84: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BR; 85: 86: if (adreno_drawctxt_get_pagetable(rb->drawctxt_active) != pagetable) { 87: /* Flush LRZ before every pagetable switch */ 88: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 89: cmds[count++] = CP_SET_THREAD_BOTH; 90: 91: cmds[count++] = cp_type7_packet(CP_EVENT_WRITE, 1); 92: /* Add event ID for LRZ flush as packet payload */ 93: cmds[count++] = LRZ_CACHE_FLUSH; 94: 95: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 96: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BR; 97: 98: /* Clear performance counters during context switches */ 99: if (!adreno_dev->perfcounter) { 100: cmds[count++] = cp_type4_packet(GEN7_RBBM_PERFCTR_SRAM_INIT_CMD, 1); 101: cmds[count++] = 0x1; 102: } 103: 104: count += gen7_rb_pagetable_switch(adreno_dev, rb, 105: drawctxt, pagetable, &cmds[count]); 106: 107: /* Wait for performance counter clear to finish */ 108: if (!adreno_dev->perfcounter) { 109: cmds[count++] = cp_type7_packet(CP_WAIT_REG_MEM, 6); 110: cmds[count++] = 0x3; 111: cmds[count++] = GEN7_RBBM_PERFCTR_SRAM_INIT_STATUS; 112: cmds[count++] = 0x0; 113: cmds[count++] = 0x1; 114: cmds[count++] = 0x1; 115: cmds[count++] = 0x0; MATCH LINES: 134, 141, 148, 160, 174 122: /* 123: * Set the CONTEXTIDR register to the current context id so we 124: * can use it in pagefault debugging. Unlike TTBR0 we don't 125: * need any special sequence or locking to change it 126: */ 127: cmds[count++] = cp_type4_packet(offset, 1); 128: cmds[count++] = drawctxt->base.id; 129: } 130: 131: cmds[count++] = cp_type7_packet(CP_NOP, 1); 132: cmds[count++] = CONTEXT_TO_MEM_IDENTIFIER; 133: 134: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 135: cmds[count++] = lower_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb, 136: current_context)); 137: cmds[count++] = upper_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb, 138: current_context)); 139: cmds[count++] = drawctxt->base.id; 140: 141: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 142: cmds[count++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 143: KGSL_MEMSTORE_GLOBAL, current_context)); 144: cmds[count++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 145: KGSL_MEMSTORE_GLOBAL, current_context)); 146: cmds[count++] = drawctxt->base.id; 147: 148: cmds[count++] = cp_type7_packet(CP_EVENT_WRITE, 1); 149: cmds[count++] = 0x31; 150: 151: if (adreno_is_preemption_enabled(adreno_dev) && drawctxt->base.user_ctxt_record) { 152: u64 gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 153: 154: cmds[count++] = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 3); 155: cmds[count++] = SET_PSEUDO_NON_PRIV_SAVE_ADDR; 156: cmds[count++] = lower_32_bits(gpuaddr); 157: cmds[count++] = upper_32_bits(gpuaddr); 158: } 159: 160: return gen7_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED, 161: cmds, count, 0, NULL); 162: } 163: 164: #define RB_SOPTIMESTAMP(device, rb) \ 165: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 166: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 167: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 168: 169: #define RB_EOPTIMESTAMP(device, rb) \ 170: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 171: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 172: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 173: 174: int gen7_ringbuffer_submit(struct adreno_ringbuffer *rb, 175: struct adreno_submit_time *time) 176: { 177: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 178: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 179: int ret = 0; 180: unsigned long flags; 181: 182: adreno_get_submit_time(adreno_dev, rb, time); 183: adreno_profile_submit_time(time); 184: 185: spin_lock_irqsave(&rb->preempt_lock, flags); 186: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 187: if (adreno_dev->cur_rb == rb) { 188: ret = gen7_fenced_write(adreno_dev, 189: GEN7_CP_RB_WPTR, rb->_wptr, 190: FENCE_STATUS_WRITEDROPPED0_MASK); 191: rb->skip_inline_wptr = false; 192: } 193: } else { 194: if (adreno_dev->cur_rb == rb) 195: rb->skip_inline_wptr = true; 196: } 197: 198: rb->wptr = rb->_wptr; MATCH LINES: 214, 225, 228, 229, 230, 233, 235, 238, 239, 251, 252, 276, 301, 308, 316, 336, 355, 377, 381, 387, 395, 429, 455, 468, 479 202: /* 203: * If WPTR update fails, take inline snapshot and trigger 204: * recovery. 205: */ 206: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 207: adreno_scheduler_fault(adreno_dev, 208: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 209: } 210: 211: return ret; 212: } 213: 214: int gen7_ringbuffer_init(struct adreno_device *adreno_dev) 215: { 216: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 217: int i, ret; 218: 219: ret = adreno_allocate_global(device, &device->scratch, PAGE_SIZE, 220: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED, 221: "scratch"); 222: if (ret) 223: return ret; 224: 225: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]); 226: 227: if (!adreno_preemption_feature_set(adreno_dev)) { 228: adreno_dev->num_ringbuffers = 1; 229: return adreno_ringbuffer_setup(adreno_dev, 230: &adreno_dev->ringbuffers[0], 0); 231: } 232: 233: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers); 234: 235: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 236: int ret; 237: 238: ret = adreno_ringbuffer_setup(adreno_dev, 239: &adreno_dev->ringbuffers[i], i); 240: if (ret) 241: return ret; 242: } 243: 244: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 245: gen7_preemption_init(adreno_dev); 246: return 0; 247: } 248: 249: #define GEN7_SUBMIT_MAX 104 250: 251: int gen7_ringbuffer_addcmds(struct adreno_device *adreno_dev, 252: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 253: u32 flags, u32 *in, u32 dwords, u32 timestamp, 254: struct adreno_submit_time *time) 255: { 256: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 257: u32 size = GEN7_SUBMIT_MAX + dwords; 258: u32 *cmds, index = 0; 259: u64 profile_gpuaddr; 260: u32 profile_dwords; 261: 262: if (adreno_drawctxt_detached(drawctxt)) 263: return -ENOENT; 264: 265: if (adreno_gpu_fault(adreno_dev) != 0) 266: return -EPROTO; 267: 268: rb->timestamp++; 269: 270: if (drawctxt) 271: drawctxt->internal_timestamp = rb->timestamp; 272: 273: /* All submissions are run with protected mode off due to APRIV */ 274: flags &= ~F_NOTPROTECTED; 275: 276: cmds = adreno_ringbuffer_allocspace(rb, size); 277: if (IS_ERR(cmds)) 278: return PTR_ERR(cmds); 279: 280: /* Identify the start of a command */ 281: cmds[index++] = cp_type7_packet(CP_NOP, 1); 282: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 283: 284: /* This is 25 dwords when drawctxt is not NULL and perfcounter needs to be zapped*/ 285: index += gen7_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 286: &cmds[index]); 287: 288: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 289: cmds[index++] = CP_SET_THREAD_BOTH; 290: 291: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 292: cmds[index++] = 0x101; /* IFPC disable */ 293: 294: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 295: cmds[index++] = CP_SET_THREAD_BR; 296: 297: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 298: drawctxt, &profile_dwords); 299: 300: if (profile_gpuaddr) { 301: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 302: cmds[index++] = lower_32_bits(profile_gpuaddr); 303: cmds[index++] = upper_32_bits(profile_gpuaddr); 304: cmds[index++] = profile_dwords; 305: } 306: 307: if (drawctxt) { 308: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 309: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 310: drawctxt)); 311: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 312: drawctxt)); 313: cmds[index++] = timestamp; 314: } 315: 316: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 317: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 318: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); 319: cmds[index++] = rb->timestamp; 320: 321: if (IS_SECURE(flags)) { 322: /* Sync BV and BR if entering secure mode */ 323: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 324: cmds[index++] = CP_SYNC_THREADS | CP_CONCURRENT_BIN_DISABLE; 325: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 326: cmds[index++] = 1; 327: } 328: 329: memcpy(&cmds[index], in, dwords << 2); 330: index += dwords; 331: 332: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev, 333: drawctxt, &dwords); 334: 335: if (profile_gpuaddr) { 336: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 337: cmds[index++] = lower_32_bits(profile_gpuaddr); 338: cmds[index++] = upper_32_bits(profile_gpuaddr); 339: cmds[index++] = profile_dwords; 340: } 341: 342: if (test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &device->mmu.pfpolicy)) 343: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0); 344: 345: if (is_concurrent_binning(drawctxt)) { 346: u64 addr = SCRATCH_RB_GPU_ADDR(device, rb->id, bv_ts); 347: 348: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 349: cmds[index++] = CP_SET_THREAD_BV; 350: 351: /* 352: * Make sure the timestamp is committed once BV pipe is 353: * completely done with this submission. 354: */ 355: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 356: cmds[index++] = CACHE_CLEAN | BIT(27); 357: cmds[index++] = lower_32_bits(addr); 358: cmds[index++] = upper_32_bits(addr); 359: cmds[index++] = rb->timestamp; 360: 361: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 362: cmds[index++] = CP_SET_THREAD_BR; 363: 364: /* 365: * This makes sure that BR doesn't race ahead and commit 366: * timestamp to memstore while BV is still processing 367: * this submission. 368: */ 369: cmds[index++] = cp_type7_packet(CP_WAIT_TIMESTAMP, 4); 370: cmds[index++] = 0; 371: cmds[index++] = lower_32_bits(addr); 372: cmds[index++] = upper_32_bits(addr); 373: cmds[index++] = rb->timestamp; 374: } 375: 376: /* 377: * If this is an internal command, just write the ringbuffer timestamp, 378: * otherwise, write both 379: */ 380: if (!drawctxt) { 381: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 382: cmds[index++] = CACHE_CLEAN | BIT(31) | BIT(27); 383: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 384: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 385: cmds[index++] = rb->timestamp; 386: } else { 387: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 388: cmds[index++] = CACHE_CLEAN | BIT(31) | BIT(27); 389: cmds[index++] = lower_32_bits(CTXT_EOPTIMESTAMP(device, 390: drawctxt)); 391: cmds[index++] = upper_32_bits(CTXT_EOPTIMESTAMP(device, 392: drawctxt)); 393: cmds[index++] = timestamp; 394: 395: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 396: cmds[index++] = CACHE_CLEAN | BIT(27); 397: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 398: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 399: cmds[index++] = rb->timestamp; 400: } 401: 402: if (IS_WFI(flags)) 403: cmds[index++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 404: 405: if (IS_SECURE(flags)) { 406: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 407: cmds[index++] = CP_CONCURRENT_BIN_DISABLE; 408: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 409: cmds[index++] = 0; 410: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 411: cmds[index++] = CP_SYNC_THREADS; 412: } 413: 414: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 415: cmds[index++] = CP_SET_THREAD_BOTH; 416: 417: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 418: cmds[index++] = 0x100; /* IFPC enable */ 419: 420: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 421: cmds[index++] = CP_SET_THREAD_BR; 422: 423: /* 10 dwords */ 424: index += gen7_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 425: 426: /* Adjust the thing for the number of bytes we actually wrote */ 427: rb->_wptr -= (size - index); 428: 429: return gen7_ringbuffer_submit(rb, time); 430: } 431: 432: static u32 gen7_get_alwayson_counter(u32 *cmds, u64 gpuaddr) 433: { 434: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 435: cmds[1] = GEN7_CP_ALWAYS_ON_COUNTER_LO | (1 << 30) | (2 << 18); 436: cmds[2] = lower_32_bits(gpuaddr); 437: cmds[3] = upper_32_bits(gpuaddr); 438: 439: return 4; 440: } 441: 442: static u32 gen7_get_alwayson_context(u32 *cmds, u64 gpuaddr) 443: { 444: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 445: cmds[1] = GEN7_CP_ALWAYS_ON_CONTEXT_LO | (1 << 30) | (2 << 18); 446: cmds[2] = lower_32_bits(gpuaddr); 447: cmds[3] = upper_32_bits(gpuaddr); 448: 449: return 4; 450: } 451: 452: #define PROFILE_IB_DWORDS 4 453: #define PROFILE_IB_SLOTS (PAGE_SIZE / (PROFILE_IB_DWORDS << 2)) 454: 455: static u64 gen7_get_user_profiling_ib(struct adreno_ringbuffer *rb, 456: struct kgsl_drawobj_cmd *cmdobj, u32 target_offset, u32 *cmds) 457: { 458: u32 offset, *ib, dwords; 459: 460: if (IS_ERR(rb->profile_desc)) 461: return 0; 462: 463: offset = rb->profile_index * (PROFILE_IB_DWORDS << 2); 464: ib = rb->profile_desc->hostptr + offset; 465: dwords = gen7_get_alwayson_counter(ib, 466: cmdobj->profiling_buffer_gpuaddr + target_offset); 467: 468: cmds[0] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 469: cmds[1] = lower_32_bits(rb->profile_desc->gpuaddr + offset); 470: cmds[2] = upper_32_bits(rb->profile_desc->gpuaddr + offset); 471: cmds[3] = dwords; 472: 473: rb->profile_index = (rb->profile_index + 1) % PROFILE_IB_SLOTS; 474: 475: return 4; 476: } 477: 478: static int gen7_drawctxt_switch(struct adreno_device *adreno_dev, 479: struct adreno_ringbuffer *rb, 480: struct adreno_context *drawctxt) 481: { 482: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 483: int ret; 484: 485: if (rb->drawctxt_active == drawctxt) 486: return 0; 487: 488: if (kgsl_context_detached(&drawctxt->base)) 489: return -ENOENT; 490: 491: if (!_kgsl_context_get(&drawctxt->base)) 492: return -ENOENT; 493: 494: ret = gen7_rb_context_switch(adreno_dev, rb, drawctxt); 495: if (ret) { 496: kgsl_context_put(&drawctxt->base); 497: return ret; 498: } 499: 500: trace_adreno_drawctxt_switch(rb, drawctxt); 501: 502: /* Release the current drawctxt as soon as the new one is switched */ 503: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active, MATCH LINES: 530, 537 518: (dev)->profile_buffer->gpuaddr + \ 519: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 520: field)) 521: 522: #define GEN7_KERNEL_PROFILE_CONTEXT(dev, cmdobj, cmds, field) \ 523: gen7_get_alwayson_context((cmds), \ 524: (dev)->profile_buffer->gpuaddr + \ 525: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 526: field)) 527: 528: #define GEN7_COMMAND_DWORDS 60 529: 530: int gen7_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 531: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 532: struct adreno_submit_time *time) 533: { 534: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 535: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 536: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 537: struct adreno_ringbuffer *rb = drawctxt->rb; 538: int ret = 0, numibs = 0, index = 0; 539: u32 *cmds; 540: 541: /* Count the number of IBs (if we are not skipping) */ 542: if (!IS_SKIP(flags)) { 543: struct list_head *tmp; 544: 545: list_for_each(tmp, &cmdobj->cmdlist) 546: numibs++; 547: } 548: 549: cmds = kvmalloc((GEN7_COMMAND_DWORDS + (numibs * 5)) << 2, GFP_KERNEL); 550: if (!cmds) { 551: ret = -ENOMEM; 552: goto done; 553: } 554: 555: cmds[index++] = cp_type7_packet(CP_NOP, 1); 556: cmds[index++] = START_IB_IDENTIFIER; 557: 558: /* Kernel profiling: 8 dwords */ 559: if (IS_KERNEL_PROFILE(flags)) { 560: index += GEN7_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index], 561: started); MATCH LINES: 588, 605, 609, 647 576: struct kgsl_memobj_node *ib; 577: 578: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 579: cmds[index++] = 0x00d; /* IB1LIST start */ 580: 581: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 582: if (ib->priv & MEMOBJ_SKIP || 583: (ib->flags & KGSL_CMDLIST_CTXTSWITCH_PREAMBLE && 584: !IS_PREAMBLE(flags))) 585: cmds[index++] = cp_type7_packet(CP_NOP, 4); 586: 587: cmds[index++] = 588: cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 589: cmds[index++] = lower_32_bits(ib->gpuaddr); 590: cmds[index++] = upper_32_bits(ib->gpuaddr); 591: 592: /* Double check that IB_PRIV is never set */ 593: cmds[index++] = (ib->size >> 2) & 0xfffff; 594: } 595: 596: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 597: cmds[index++] = 0x00e; /* IB1LIST end */ 598: } 599: 600: if (is_concurrent_binning(drawctxt)) { 601: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 602: cmds[index++] = CP_SET_THREAD_BR; 603: } 604: /* CCU invalidate depth */ 605: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1); 606: cmds[index++] = 24; 607: 608: /* CCU invalidate color */ 609: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1); 610: cmds[index++] = 25; 611: 612: /* 8 dwords */ 613: if (IS_KERNEL_PROFILE(flags)) { 614: index += GEN7_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index], 615: retired); 616: index += GEN7_KERNEL_PROFILE_CONTEXT(adreno_dev, cmdobj, &cmds[index], 617: ctx_end); 618: } 619: 620: /* 4 dwords */ 621: if (IS_USER_PROFILE(flags)) 622: index += GEN7_USER_PROFILE_IB(rb, cmdobj, &cmds[index], 623: gpu_ticks_retired); 624: 625: cmds[index++] = cp_type7_packet(CP_NOP, 1); 626: cmds[index++] = END_IB_IDENTIFIER; 627: 628: ret = gen7_drawctxt_switch(adreno_dev, rb, drawctxt); 629: 630: /* 631: * In the unlikely event of an error in the drawctxt switch, 632: * treat it like a hang 633: */ 634: if (ret) { 635: /* 636: * It is "normal" to get a -ENOSPC or a -ENOENT. Don't log it, 637: * the upper layers know how to handle it 638: */ 639: if (ret != -ENOSPC && ret != -ENOENT) 640: dev_err(device->dev, 641: "Unable to switch draw context: %d\n", ret); 642: goto done; 643: } 644: 645: adreno_drawobj_set_constraint(device, drawobj); 646: 647: ret = gen7_ringbuffer_addcmds(adreno_dev, drawctxt->rb, drawctxt, 648: flags, cmds, index, drawobj->timestamp, time); 649: 650: done: 651: trace_kgsl_issueibcmds(device, drawctxt->base.id, numibs, 652: drawobj->timestamp, drawobj->flags, ret, drawctxt->type); 653: 654: kvfree(cmds); 655: return ret; 656: } --- FILE: \adreno_gen8.c | HITS: 20 --- MATCH LINES: 1128 1116: /* Enable error detection */ 1117: mask |= BIT(1); 1118: 1119: /* Set default reset state */ 1120: mask |= BIT(3); 1121: 1122: /* Disable save/restore of performance counters across preemption */ 1123: mask |= BIT(6); 1124: 1125: /* Enable the register init list with the spinlock */ 1126: mask |= BIT(8); 1127: 1128: cmds[i++] = cp_type7_packet(CP_ME_INIT, 7); 1129: 1130: /* Enabled ordinal mask */ 1131: cmds[i++] = mask; 1132: cmds[i++] = 0x00000003; /* Set number of HW contexts */ 1133: cmds[i++] = 0x20000000; /* Enable error detection */ 1134: cmds[i++] = 0x00000002; /* Operation mode mask */ 1135: 1136: /* Register initialization list with spinlock */ 1137: cmds[i++] = lower_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 1138: cmds[i++] = upper_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 1139: /* 1140: * Gen8 targets with concurrent binning are expected to have a dynamic 1141: * power up list with triplets which contains the pipe id in it. 1142: * Bit 31 of POWER_UP_REGISTER_LIST_LENGTH is reused here to let CP 1143: * know if the power up contains the triplets. If 1144: * REGISTER_INIT_LIST_WITH_SPINLOCK is set and bit 31 below is set, 1145: * CP expects a dynamic list with triplets. 1146: */ 1147: cmds[i++] = BIT(31); 1148: } 1149: 1150: int gen8_fenced_write(struct adreno_device *adreno_dev, u32 offset, 1151: u32 value, u32 mask) 1152: { MATCH LINES: 2006, 2007 1994: adreno_dev->viz_flush_draw_count = FIELD_GET(GENMASK(7, 0), reg); 1995: adreno_dev->viz_flush_prim_count = FIELD_GET(GENMASK(23, 8), reg); 1996: } 1997: 1998: /* 1999: * All Gen8 targets support marking certain transactions as always privileged 2000: * which allows us to mark more memory as privileged without having to 2001: * explicitly set the APRIV bit. Choose the following transactions to be 2002: * privileged by default: 2003: * CDWRITE [6:6] - Crashdumper writes 2004: * CDREAD [5:5] - Crashdumper reads 2005: * RBRPWB [3:3] - RPTR shadow writes 2006: * RBPRIVLEVEL [2:2] - Memory accesses from PM4 packets in the ringbuffer 2007: * RBFETCH [1:1] - Ringbuffer reads 2008: * ICACHE [0:0] - Instruction cache fetches 2009: */ 2010: 2011: #define GEN8_APRIV_DEFAULT (BIT(3) | BIT(2) | BIT(1) | BIT(0)) 2012: /* Add crashdumper permissions for the BR APRIV */ 2013: #define GEN8_BR_APRIV_DEFAULT (GEN8_APRIV_DEFAULT | BIT(6) | BIT(5)) 2014: 2015: static const struct kgsl_regmap_list gen8_0_0_bicubic_regs[] = { 2016: /*GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_0 default and recomended values are same */ 2017: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_1, 0x3fe05ff4 }, 2018: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_2, 0x3fa0ebee }, 2019: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_3, 0x3f5193ed }, 2020: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_4, 0x3f0243f0 }, 2021: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_5, 0x00000000 }, 2022: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_6, 0x3fd093e8 }, 2023: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_7, 0x3f4133dc }, 2024: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_8, 0x3ea1dfdb }, 2025: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_9, 0x3e0283e0 }, 2026: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_10, 0x0000ac2b }, 2027: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_11, 0x0000f01d }, 2028: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_12, 0x00114412 }, 2029: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_13, 0x0021980a }, 2030: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_14, 0x0051ec05 }, 2031: { GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_15, 0x0000380e }, MATCH LINES: 2355, 2357, 2362, 2367, 2373, 2392, 2410, 2436, 2443, 2459, 2464, 2465, 2479, 2480 2343: kgsl_regread(device, GEN8_RBBM_INT_0_STATUS, &intstatus); 2344: kgsl_regread(device, GEN8_CP_INTERRUPT_STATUS_GLOBAL, &global_status); 2345: 2346: dev_err(device->dev, 2347: "rb=%d pos=%X/%X rbbm_status=%8.8X int_0_status=%8.8X global_status=%8.8X\n", 2348: adreno_dev->cur_rb ? adreno_dev->cur_rb->id : -1, rptr, wptr, 2349: status, intstatus, global_status); 2350: 2351: kgsl_device_snapshot(device, NULL, NULL, false); 2352: } 2353: 2354: /* 2355: * gen8_send_cp_init() - Initialize ringbuffer 2356: * @adreno_dev: Pointer to adreno device 2357: * @rb: Pointer to the ringbuffer of device 2358: * 2359: * Submit commands for ME initialization, 2360: */ 2361: static int gen8_send_cp_init(struct adreno_device *adreno_dev, 2362: struct adreno_ringbuffer *rb) 2363: { 2364: u32 *cmds; 2365: int ret; 2366: 2367: cmds = adreno_ringbuffer_allocspace(rb, GEN8_CP_INIT_DWORDS); 2368: if (IS_ERR(cmds)) 2369: return PTR_ERR(cmds); 2370: 2371: gen8_cp_init_cmds(adreno_dev, cmds); 2372: 2373: ret = gen8_ringbuffer_submit(rb, NULL); 2374: if (ret) 2375: return ret; 2376: 2377: ret = adreno_spin_idle(adreno_dev, 2000); 2378: if (ret) { 2379: gen8_spin_idle_debug(adreno_dev, 2380: "CP initialization failed to idle\n"); 2381: rb->wptr = 0; 2382: rb->_wptr = 0; 2383: } 2384: 2385: return ret; 2386: } 2387: 2388: static int gen8_post_start(struct adreno_device *adreno_dev) 2389: { 2390: int ret; 2391: u32 *cmds; 2392: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 2393: struct adreno_preemption *preempt = &adreno_dev->preempt; 2394: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2395: u64 kmd_postamble_addr; 2396: u32 count = 9; 2397: 2398: if (!adreno_is_preemption_enabled(adreno_dev)) 2399: return 0; 2400: 2401: kmd_postamble_addr = SCRATCH_POSTAMBLE_ADDR(KGSL_DEVICE(adreno_dev)); 2402: gen8_preemption_prepare_postamble(adreno_dev); 2403: 2404: if (kgsl_mmu_is_secured(&device->mmu)) 2405: count += 3; 2406: 2407: if (preempt->postamble_bootup_len) 2408: count += 4; 2409: 2410: cmds = adreno_ringbuffer_allocspace(rb, count); 2411: if (IS_ERR(cmds)) 2412: return PTR_ERR(cmds); 2413: 2414: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 2415: kgsl_mmu_is_secured(&device->mmu) ? 6 : 3); 2416: 2417: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 2418: *cmds++ = lower_32_bits(rb->preemption_desc->gpuaddr); 2419: *cmds++ = upper_32_bits(rb->preemption_desc->gpuaddr); 2420: 2421: if (kgsl_mmu_is_secured(&device->mmu)) { 2422: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 2423: *cmds++ = lower_32_bits(rb->secure_preemption_desc->gpuaddr); 2424: *cmds++ = upper_32_bits(rb->secure_preemption_desc->gpuaddr); 2425: } 2426: 2427: if (preempt->postamble_bootup_len) { 2428: *cmds++ = cp_type7_packet(CP_SET_AMBLE, 3); 2429: *cmds++ = lower_32_bits(kmd_postamble_addr); 2430: *cmds++ = upper_32_bits(kmd_postamble_addr); 2431: *cmds++ = FIELD_PREP(GENMASK(22, 20), CP_KMD_AMBLE_TYPE) 2432: | (FIELD_PREP(GENMASK(19, 0), 2433: adreno_dev->preempt.postamble_bootup_len)); 2434: } 2435: 2436: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 2437: *cmds++ = 0; 2438: *cmds++ = 0; 2439: *cmds++ = 0; 2440: /* generate interrupt on preemption completion */ 2441: *cmds++ = 0; 2442: 2443: ret = gen8_ringbuffer_submit(rb, NULL); 2444: if (!ret) { 2445: ret = adreno_spin_idle(adreno_dev, 2000); 2446: if (ret) 2447: gen8_spin_idle_debug(adreno_dev, 2448: "hw preemption initialization failed to idle\n"); 2449: } 2450: 2451: return ret; 2452: } 2453: 2454: int gen8_rb_start(struct adreno_device *adreno_dev) 2455: { 2456: const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev); 2457: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 2458: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2459: struct adreno_ringbuffer *rb; 2460: u64 addr; 2461: int ret, i; 2462: u32 *cmds; 2463: 2464: /* Clear all the ringbuffers */ 2465: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2466: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 2467: kgsl_sharedmem_writel(device->scratch, 2468: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 2469: kgsl_sharedmem_writel(device->scratch, 2470: SCRATCH_RB_OFFSET(rb->id, bv_rptr), 0); 2471: 2472: rb->wptr = 0; 2473: rb->_wptr = 0; 2474: rb->wptr_preempt_end = UINT_MAX; 2475: } 2476: 2477: gen8_preemption_start(adreno_dev); 2478: 2479: /* Set up the current ringbuffer */ 2480: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 2481: 2482: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 2483: kgsl_regwrite(device, GEN8_CP_RB_RPTR_ADDR_LO_BR, lower_32_bits(addr)); 2484: kgsl_regwrite(device, GEN8_CP_RB_RPTR_ADDR_HI_BR, upper_32_bits(addr)); 2485: 2486: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, bv_rptr); 2487: kgsl_regwrite(device, GEN8_CP_RB_RPTR_ADDR_LO_BV, lower_32_bits(addr)); 2488: kgsl_regwrite(device, GEN8_CP_RB_RPTR_ADDR_HI_BV, upper_32_bits(addr)); 2489: 2490: kgsl_regwrite(device, GEN8_CP_RB_CNTL_GC, GEN8_CP_RB_CNTL_DEFAULT); 2491: 2492: kgsl_regwrite(device, GEN8_CP_RB_BASE_LO_GC, 2493: lower_32_bits(rb->buffer_desc->gpuaddr)); 2494: kgsl_regwrite(device, GEN8_CP_RB_BASE_HI_GC, 2495: upper_32_bits(rb->buffer_desc->gpuaddr)); 2496: 2497: /* Program the ucode base for CP */ 2498: kgsl_regwrite(device, GEN8_CP_SQE_INSTR_BASE_LO, 2499: lower_32_bits(fw->memdesc->gpuaddr)); 2500: kgsl_regwrite(device, GEN8_CP_SQE_INSTR_BASE_HI, 2501: upper_32_bits(fw->memdesc->gpuaddr)); 2502: 2503: /* Clear the SQE_HALT to start the CP engine */ 2504: kgsl_regwrite(device, GEN8_CP_SQE_CNTL, 1); MATCH LINES: 2521, 2528 2509: 2510: ret = adreno_zap_shader_load(adreno_dev, gen8_core->zap_name); 2511: if (ret) 2512: return ret; 2513: 2514: /* 2515: * Take the GPU out of secure mode. Try the zap shader if it is loaded, 2516: * otherwise just try to write directly to the secure control register 2517: */ 2518: if (!adreno_dev->zap_loaded) 2519: kgsl_regwrite(device, GEN8_RBBM_SECVID_TRUST_CNTL, 0); 2520: else { 2521: cmds = adreno_ringbuffer_allocspace(rb, 2); 2522: if (IS_ERR(cmds)) 2523: return PTR_ERR(cmds); 2524: 2525: *cmds++ = cp_type7_packet(CP_SET_SECURE_MODE, 1); 2526: *cmds++ = 0; 2527: 2528: ret = gen8_ringbuffer_submit(rb, NULL); 2529: if (!ret) { 2530: ret = adreno_spin_idle(adreno_dev, 2000); 2531: if (ret) { 2532: gen8_spin_idle_debug(adreno_dev, 2533: "Switch to unsecure failed to idle\n"); 2534: return ret; 2535: } 2536: } 2537: } 2538: 2539: /* 2540: * When the GPU is in secure mode, any writes to the RB_GC_GMEM_PROTECT 2541: * register are ignored. At this point, the GPU should be in unsecure 2542: * mode, so program the RB_GC_GMEM_PROTECT register. 2543: */ 2544: gen8_set_gmem_protect(adreno_dev); 2545: 2546: /* 2547: * All registers must be written before this point so that we don't 2548: * miss any register programming when we patch the power up register 2549: * list. 2550: */ 2551: if (!adreno_dev->patch_reglist && 2552: (adreno_dev->pwrup_reglist->gpuaddr != 0)) { MATCH LINES: 3896 3884: .probe = gen8_gmu_device_probe, 3885: .snapshot = gen8_gmu_snapshot, 3886: .irq_handler = gen8_irq_handler, 3887: .rb_start = gen8_rb_start, 3888: .gpu_keepalive = gen8_gpu_keepalive, 3889: .hw_isidle = gen8_hw_isidle, 3890: .iommu_fault_block = gen8_iommu_fault_block, 3891: .reset = gen8_gmu_reset, 3892: .preemption_schedule = gen8_preemption_schedule, 3893: .read_alwayson = gen8_read_alwayson, 3894: .power_ops = &gen8_gmu_power_ops, 3895: .remove = gen8_remove, 3896: .ringbuffer_submitcmd = gen8_ringbuffer_submitcmd, 3897: .power_stats = gen8_power_stats, 3898: .add_to_va_minidump = gen8_gmu_add_to_minidump, 3899: .gx_is_on = gen8_gmu_gx_is_on, 3900: .perfcounter_remove = gen8_perfcounter_remove, 3901: .set_isdb_breakpoint_registers = gen8_set_isdb_breakpoint_registers, 3902: .swfuse_irqctrl = gen8_swfuse_irqctrl, 3903: .get_uche_trap_base = gen8_get_uche_trap_base, 3904: .fault_header = gen8_fault_header, 3905: .acquire_cp_semaphore = gen8_acquire_cp_semaphore, 3906: .release_cp_semaphore = gen8_release_cp_semaphore, 3907: .get_gmem_size = gen8_get_gmem_size, 3908: .read_speedbin = gen8_read_softfuse_speedbin, 3909: }, 3910: .hfi_probe = gen8_gmu_hfi_probe, 3911: .handle_watchdog = gen8_gmu_handle_watchdog, 3912: }; --- FILE: \adreno_gen8.h | HITS: 17 --- MATCH LINES: 241 229: /** @three_rail_memory: This target has BX rail in addition to GX and MX */ 230: bool three_rail_memory; 231: /** @malu: This target has MALU */ 232: bool malu; 233: }; 234: 235: /** 236: * struct gen8_cp_preemption_record - CP context record for 237: * preemption. 238: * @magic: (00) Value at this offset must be equal to 239: * GEN8_CP_CTXRECORD_MAGIC_REF. 240: * @info: (04) Type of record. Written non-zero (usually) by CP. 241: * we must set to zero for all ringbuffers. 242: * @errno: (08) Error code. Initialize this to GEN8_CP_CTXRECORD_ERROR_NONE. 243: * CP will update to another value if a preemption error occurs. 244: * @data: (12) DATA field in YIELD and SET_MARKER packets. 245: * Written by CP when switching out. Not used on switch-in. Initialized to 0. 246: * @cntl: (16) RB_CNTL, saved and restored by CP. We must initialize this. 247: * @rptr: (20) RB_RPTR, saved and restored by CP. We must initialize this. 248: * @wptr: (24) RB_WPTR, saved and restored by CP. We must initialize this. 249: * @_pad28: (28) Reserved/padding. 250: * @rptr_addr: (32) RB_RPTR_ADDR_LO|HI saved and restored. We must initialize. 251: * rbase: (40) RB_BASE_LO|HI saved and restored. 252: * counter: (48) Pointer to preemption counter. 253: * @bv_rptr_addr: (56) BV_RB_RPTR_ADDR_LO|HI save and restored. We must initialize. 254: */ 255: struct gen8_cp_preemption_record { 256: u32 magic; 257: u32 info; 258: u32 errno; 259: u32 data; 260: u32 cntl; 261: u32 rptr; 262: u32 wptr; 263: u32 _pad28; 264: u64 rptr_addr; 265: u64 rbase; MATCH LINES: 361 349: return container_of(core, struct adreno_gen8_core, base); 350: } 351: 352: /* Preemption functions */ 353: void gen8_preemption_trigger(struct adreno_device *adreno_dev, bool atomic); 354: void gen8_preemption_schedule(struct adreno_device *adreno_dev); 355: void gen8_preemption_start(struct adreno_device *adreno_dev); 356: int gen8_preemption_init(struct adreno_device *adreno_dev); 357: 358: u32 gen8_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 359: u32 *cmds); 360: u32 gen8_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 361: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 362: u32 *cmds); 363: 364: void gen8_preemption_callback(struct adreno_device *adreno_dev, int bit); 365: 366: void gen8_preemption_context_destroy(struct kgsl_context *context); 367: 368: void gen8_preemption_prepare_postamble(struct adreno_device *adreno_dev); 369: 370: void gen8_snapshot(struct adreno_device *adreno_dev, 371: struct kgsl_snapshot *snapshot); 372: void gen8_crashdump_init(struct adreno_device *adreno_dev); 373: 374: /** 375: * gen8_snapshot_external_core_regs - Dump external registers into snapshot 376: * @device: Pointer to KGSL device 377: * @snapshot: Pointer to the snapshot 378: * 379: * Dump external core registers like GPUCC, CPR into GPU snapshot. 380: */ 381: void gen8_snapshot_external_core_regs(struct kgsl_device *device, 382: struct kgsl_snapshot *snapshot); 383: 384: /** 385: * gen8_enable_ahb_timeout_detection - Program AHB control registers MATCH LINES: 441, 444 429: */ 430: void gen8_get_gpu_feature_info(struct adreno_device *adreno_dev); 431: 432: /** 433: * gen8_get_gpu_slice_info - Get information about the active slices 434: * @adreno_dev: Pointer to the adreno device 435: * 436: * Get information about the active slices and save it in the gen8 device 437: */ 438: void gen8_get_gpu_slice_info(struct adreno_device *adreno_dev); 439: 440: /** 441: * gen8_rb_start - Gen8 specific ringbuffer setup 442: * @adreno_dev: An Adreno GPU handle 443: * 444: * This function does gen8 specific ringbuffer setup and 445: * attempts to submit CP INIT and bring GPU out of secure mode 446: * 447: * Return: Zero on success and negative error on failure 448: */ 449: int gen8_rb_start(struct adreno_device *adreno_dev); 450: 451: /** 452: * gen8_microcode_read - Get the cp microcode from the filesystem 453: * @adreno_dev: An Adreno GPU handle 454: * 455: * This function gets the firmware from filesystem and sets up 456: * the micorocode global buffer 457: * 458: * Return: Zero on success and negative error on failure 459: */ 460: int gen8_microcode_read(struct adreno_device *adreno_dev); 461: 462: /** 463: * gen8_probe_common - Probe common gen8 resources 464: * @pdev: Pointer to the platform device 465: * @adreno_dev: Pointer to the adreno device 466: * @chipid: Chipid of the target 467: * @gpucore: Pointer to the gpucore strucure 468: * MATCH LINES: 500, 503, 506, 509, 517, 522, 523, 528, 544, 546, 549, 556, 557 488: * @reg: Perfcounter reg struct to add/remove to the list 489: * @update_reg: true if the perfcounter needs to be programmed by the CPU 490: * @pipe: pipe id for CP aperture control 491: * @flags: Flags set for requested perfcounter group 492: * 493: * Return: 0 on success or -EBUSY if the lock couldn't be taken 494: */ 495: int gen8_perfcounter_update(struct adreno_device *adreno_dev, 496: struct adreno_perfcount_register *reg, bool update_reg, u32 pipe, 497: unsigned long flags); 498: 499: /* 500: * gen8_ringbuffer_init - Initialize the ringbuffers 501: * @adreno_dev: An Adreno GPU handle 502: * 503: * Initialize the ringbuffer(s) for a5xx. 504: * Return: 0 on success or negative on failure 505: */ 506: int gen8_ringbuffer_init(struct adreno_device *adreno_dev); 507: 508: /** 509: * gen8_ringbuffer_submitcmd - Submit a user command to the ringbuffer 510: * @adreno_dev: An Adreno GPU handle 511: * @cmdobj: Pointer to a user command object 512: * @flags: Internal submit flags 513: * @time: Optional pointer to a adreno_submit_time container 514: * 515: * Return: 0 on success or negative on failure 516: */ 517: int gen8_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 518: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 519: struct adreno_submit_time *time); 520: 521: /** 522: * gen8_ringbuffer_submit - Submit a command to the ringbuffer 523: * @rb: Ringbuffer pointer 524: * @time: Optional pointer to a adreno_submit_time container 525: * 526: * Return: 0 on success or negative on failure 527: */ 528: int gen8_ringbuffer_submit(struct adreno_ringbuffer *rb, 529: struct adreno_submit_time *time); 530: 531: /** 532: * gen8_fenced_write - Write to a fenced register 533: * @adreno_dev: An Adreno GPU handle 534: * @offset: Register offset 535: * @value: Value to write 536: * @mask: Expected FENCE_STATUS for successful write 537: * 538: * Return: 0 on success or negative on failure 539: */ 540: int gen8_fenced_write(struct adreno_device *adreno_dev, u32 offset, 541: u32 value, u32 mask); 542: 543: /** 544: * gen87ringbuffer_addcmds - Wrap and submit commands to the ringbuffer 545: * @adreno_dev: An Adreno GPU handle 546: * @rb: Ringbuffer pointer 547: * @drawctxt: Draw context submitting the commands 548: * @flags: Submission flags 549: * @in: Input buffer to write to ringbuffer 550: * @dwords: Dword length of @in 551: * @timestamp: Draw context timestamp for the submission 552: * @time: Optional pointer to a adreno_submit_time container 553: * 554: * Return: 0 on success or negative on failure 555: */ 556: int gen8_ringbuffer_addcmds(struct adreno_device *adreno_dev, 557: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 558: u32 flags, u32 *in, u32 dwords, u32 timestamp, 559: struct adreno_submit_time *time); 560: 561: /** 562: * gen8_cp_init_cmds - Create the CP_INIT commands 563: * @adreno_dev: An Adreno GPU handle 564: * @cmd: Buffer to write the CP_INIT commands into 565: */ 566: void gen8_cp_init_cmds(struct adreno_device *adreno_dev, u32 *cmds); 567: 568: /** 569: * gen8_gmu_hfi_probe - Probe Gen8 HFI specific data 570: * @adreno_dev: An Adreno GPU handle 571: * 572: * Return: 0 on success or negative on failure 573: */ 574: int gen8_gmu_hfi_probe(struct adreno_device *adreno_dev); 575: 576: static inline const struct gen8_gpudev * 577: to_gen8_gpudev(const struct adreno_gpudev *gpudev) 578: { 579: return container_of(gpudev, struct gen8_gpudev, base); 580: } 581: --- FILE: \adreno_gen8_gmu.c | HITS: 4 --- MATCH LINES: 767 755: "RPMH_POWER_STATE=%x GFX_PWR_CLK_STATUS=%x\n", reg, reg1); 756: dev_err(gmu_pdev_dev, "CX_BUSY_STATUS=%x\n", reg2); 757: dev_err(gmu_pdev_dev, 758: "RBBM_INT_UNMASKED_STATUS=%x PWR_COL_KEEPALIVE=%x\n", reg3, reg4); 759: 760: /* Access GX registers only when GX is ON */ 761: if (is_on(reg1)) { 762: gen8_regread_aperture(device, GEN8_CP_PIPE_STATUS_PIPE, ®, PIPE_BV, 0, 0); 763: gen8_regread_aperture(device, GEN8_CP_PIPE_STATUS_PIPE, ®1, PIPE_BR, 0, 0); 764: /* Clear aperture register */ 765: gen8_host_aperture_set(adreno_dev, 0, 0, 0); 766: kgsl_regread(device, GEN8_CP_CP2GMU_STATUS, ®2); 767: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_CNTL, ®3); 768: 769: dev_err(gmu_pdev_dev, 770: "GEN8_CP_PIPE_STATUS_PIPE BV:%x BR:%x\n", reg, reg1); 771: dev_err(gmu_pdev_dev, 772: "CP2GMU_STATUS=%x CONTEXT_SWITCH_CNTL=%x\n", reg2, reg3); 773: } 774: 775: WARN_ON(1); 776: gmu_core_fault_snapshot(device, GMU_FAULT_WAIT_FOR_LOWEST_IDLE); 777: return -ETIMEDOUT; 778: } 779: 780: /* Bitmask for GPU idle status check */ 781: #define CXGXCPUBUSYIGNAHB BIT(30) 782: int gen8_gmu_wait_for_idle(struct adreno_device *adreno_dev) 783: { 784: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 785: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 786: u32 status2; 787: u64 ts1; 788: 789: ts1 = gpudev->read_alwayson(adreno_dev); 790: if (gmu_core_timed_poll_check(device, GEN8_GMUAO_GPU_CX_BUSY_STATUS, 791: 0, 100, CXGXCPUBUSYIGNAHB)) { MATCH LINES: 887 875: gmu_core_regwrite(device, GEN8_GMUCX_CX_FAL_INTF, 0x1); 876: 877: /* Clear init result to make sure we are getting fresh value */ 878: gmu_core_regwrite(device, GEN8_GMUCX_CM3_FW_INIT_RESULT, 0); 879: gmu_core_regwrite(device, GEN8_GMUCX_CM3_BOOT_CONFIG, 0x2); 880: 881: gmu_core_regwrite(device, GEN8_GMUCX_HFI_QTBL_ADDR, 882: gmu->hfi.hfi_mem->gmuaddr); 883: gmu_core_regwrite(device, GEN8_GMUCX_HFI_QTBL_INFO, 1); 884: 885: gmu_core_regwrite(device, GEN8_GMUAO_AHB_FENCE_RANGE_0, BIT(31) | 886: FIELD_PREP(GENMASK(30, 18), 0x32) | 887: FIELD_PREP(GENMASK(17, 0), GEN8_CP_CONTEXT_SWITCH_CNTL)); 888: 889: /* 890: * Make sure that CM3 state is at reset value. Snapshot is changing 891: * NMI bit and if we boot up GMU with NMI bit set GMU will boot 892: * straight in to NMI handler without executing __main code 893: */ 894: gmu_core_regwrite(device, GEN8_GMUCX_CM3_CFG, 0x4052); 895: 896: /* Set up GBIF registers from the GPU core definition */ 897: kgsl_regmap_multi_write(&device->regmap, gen8_core->gbif, 898: gen8_core->gbif_count); 899: 900: /** 901: * We may have asserted gbif halt as part of reset sequence which may 902: * not get cleared if the gdsc was not reset. So clear it before 903: * attempting GMU boot. 904: */ 905: kgsl_regwrite(device, GEN8_GBIF_HALT, BIT(3)); 906: 907: /* Set vrb address before starting GMU */ 908: if (!IS_ERR_OR_NULL(device->gmu_core.vrb)) 909: gmu_core_regwrite(device, GEN8_GMUCX_GENERAL_11, device->gmu_core.vrb->gmuaddr); 910: 911: /* Set the log wptr index */ MATCH LINES: 2445 2433: { 2434: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2435: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2436: int ret; 2437: 2438: if (test_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags)) { 2439: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 2440: return gen8_boot(adreno_dev); 2441: 2442: return 0; 2443: } 2444: 2445: ret = gen8_ringbuffer_init(adreno_dev); 2446: if (ret) 2447: return ret; 2448: 2449: ret = gen8_microcode_read(adreno_dev); 2450: if (ret) 2451: return ret; 2452: 2453: ret = gen8_init(adreno_dev); 2454: if (ret) 2455: return ret; 2456: 2457: ret = gen8_gmu_init(adreno_dev); 2458: if (ret) 2459: return ret; 2460: 2461: kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE); 2462: 2463: ret = gen8_gmu_first_boot(adreno_dev); 2464: if (ret) 2465: return ret; 2466: 2467: gen8_populate_ctxt_record_size(adreno_dev); 2468: 2469: gen8_preemption_init(adreno_dev); MATCH LINES: 2570 2558: 2559: no_gx_power: 2560: gen8_gmu_oob_clear(device, oob_gpu); 2561: 2562: kgsl_pwrctrl_irq(device, false); 2563: 2564: gen8_gmu_power_off(adreno_dev); 2565: 2566: adreno_set_active_ctxs_null(adreno_dev); 2567: 2568: adreno_dispatcher_stop(adreno_dev); 2569: 2570: adreno_ringbuffer_stop(adreno_dev); 2571: 2572: adreno_llcc_slice_deactivate(adreno_dev); 2573: 2574: clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags); 2575: 2576: kgsl_delete_timer_sync(&device->idle_timer); 2577: 2578: kgsl_pwrscale_sleep(device); 2579: 2580: kgsl_pwrctrl_clear_l3_vote(device); 2581: 2582: /* 2583: * Reset the context records so that CP can start 2584: * at the correct read pointer for BV thread after 2585: * coming out of slumber. 2586: */ 2587: gen8_reset_preempt_records(adreno_dev); 2588: 2589: kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER); 2590: 2591: return ret; 2592: } 2593: 2594: static void gmu_idle_check(struct work_struct *work) --- FILE: \adreno_gen8_hwsched.c | HITS: 3 --- MATCH LINES: 80, 81, 82 68: { 69: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 70: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 71: bool skip_memkind_rb = false; 72: u32 i; 73: bool parse_payload; 74: 75: gen8_gmu_snapshot(adreno_dev, snapshot); 76: 77: adreno_hwsched_parse_fault_cmdobj(adreno_dev, snapshot); 78: 79: /* 80: * First try to dump ringbuffers using context bad HFI payloads 81: * because they have all the ringbuffer parameters. If ringbuffer 82: * payloads are not present, fall back to dumping ringbuffers 83: * based on MEMKIND_RB 84: */ 85: parse_payload = adreno_hwsched_parse_payload_rb(adreno_dev, snapshot); 86: 87: if (parse_payload) 88: skip_memkind_rb = true; 89: 90: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 91: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 92: 93: if (entry->desc.mem_kind == HFI_MEMKIND_RB && !skip_memkind_rb) 94: kgsl_snapshot_add_section(device, 95: KGSL_SNAPSHOT_SECTION_RB_V2, 96: snapshot, adreno_hwsched_snapshot_rb, 97: entry->md); 98: 99: if (entry->desc.mem_kind == HFI_MEMKIND_SCRATCH) 100: kgsl_snapshot_add_section(device, 101: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 102: snapshot, adreno_snapshot_global, 103: entry->md); 104: 105: if (entry->desc.mem_kind == HFI_MEMKIND_PROFILE) 106: kgsl_snapshot_add_section(device, --- FILE: \adreno_gen8_hwsched_hfi.c | HITS: 6 --- MATCH LINES: 309 297: status & (1 << 20) ? "READ" : "WRITE", 298: status & 0x3FFFF, status); 299: } 300: break; 301: case GMU_CP_ILLEGAL_INST_ERROR: 302: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 303: break; 304: case GMU_CP_UCODE_ERROR: 305: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 306: break; 307: case GMU_CP_HW_FAULT_ERROR: 308: dev_crit_ratelimited(gmu_pdev_dev, 309: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 310: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 311: KEY_CP_HW_FAULT)); 312: break; 313: case GMU_GPU_PREEMPT_TIMEOUT: { 314: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 315: 316: cur = gen8_hwsched_lookup_key_value(adreno_dev, 317: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 318: next = gen8_hwsched_lookup_key_value(adreno_dev, 319: PAYLOAD_PREEMPT_TIMEOUT, 320: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 321: cur_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_RPTR); 322: cur_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_WPTR); 323: next_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_RPTR); 324: next_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_WPTR); 325: 326: dev_crit_ratelimited(gmu_pdev_dev, 327: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 328: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 329: } 330: break; 331: case GMU_CP_GPC_ERROR: 332: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: GPC error\n"); 333: break; MATCH LINES: 352, 380 340: case GMU_CP_BV_PROTECTED_ERROR: { 341: u32 status = gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 342: KEY_CP_BV_PROTECTED_ERROR); 343: 344: dev_crit_ratelimited(gmu_pdev_dev, 345: "CP BV | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 346: status & (1 << 20) ? "READ" : "WRITE", 347: status & 0x3FFFF, status); 348: } 349: break; 350: case GMU_CP_BV_HW_FAULT_ERROR: 351: dev_crit_ratelimited(gmu_pdev_dev, 352: "CP BV | Ringbuffer HW fault | status=0x%8.8x\n", 353: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 354: KEY_CP_BV_HW_FAULT)); 355: break; 356: case GMU_CP_BV_ILLEGAL_INST_ERROR: 357: dev_crit_ratelimited(gmu_pdev_dev, "CP BV Illegal instruction error\n"); 358: break; 359: case GMU_CP_BV_UCODE_ERROR: 360: dev_crit_ratelimited(gmu_pdev_dev, "CP BV ucode error interrupt\n"); 361: break; 362: case GMU_CP_LPAC_OPCODE_ERROR: 363: dev_crit_ratelimited(gmu_pdev_dev, 364: "CP LPAC opcode error | opcode=0x%8.8x\n", 365: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 366: KEY_CP_LPAC_OPCODE_ERROR)); 367: break; 368: case GMU_CP_LPAC_PROTECTED_ERROR: { 369: u32 status = gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 370: KEY_CP_LPAC_PROTECTED_ERROR); 371: 372: dev_crit_ratelimited(gmu_pdev_dev, 373: "CP LPAC | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 374: status & (1 << 20) ? "READ" : "WRITE", 375: status & 0x3FFFF, status); 376: } 377: break; 378: case GMU_CP_LPAC_HW_FAULT_ERROR: 379: dev_crit_ratelimited(gmu_pdev_dev, 380: "CP LPAC | Ringbuffer HW fault | status=0x%8.8x\n", 381: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 382: KEY_CP_LPAC_HW_FAULT)); 383: break; 384: case GMU_CP_LPAC_ILLEGAL_INST_ERROR: 385: dev_crit_ratelimited(gmu_pdev_dev, "CP LPAC Illegal instruction error\n"); 386: break; 387: case GMU_CP_LPAC_UCODE_ERROR: 388: dev_crit_ratelimited(gmu_pdev_dev, "CP LPAC ucode error interrupt\n"); 389: break; 390: case GMU_GPU_LPAC_SW_HANG: 391: dev_crit_ratelimited(gmu_pdev_dev, "LPAC: gpu timeout ctx %u ts %u\n", 392: cmd->lpac.ctxt_id, cmd->lpac.ts); 393: break; 394: case GMU_GPU_SW_FUSE_VIOLATION: 395: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: SW Feature Fuse violation status=0x%8.8x\n", 396: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 397: KEY_SWFUSE_VIOLATION_FAULT)); 398: break; 399: case GMU_GPU_AQE0_OPCODE_ERROR: 400: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 opcode error | opcode=0x%8.8x\n", 401: gen8_hwsched_lookup_key_value(adreno_dev, 402: PAYLOAD_FAULT_REGS, KEY_AQE0_OPCODE_ERROR)); 403: break; 404: case GMU_GPU_AQE0_UCODE_ERROR: MATCH LINES: 438, 466 426: PAYLOAD_FAULT_REGS, KEY_AQE1_HW_FAULT)); 427: break; 428: case GMU_GPU_AQE1_ILLEGAL_INST_ERROR: 429: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 Illegal instruction error\n"); 430: break; 431: case GMU_SYNCOBJ_TIMEOUT_ERROR: 432: dev_crit_ratelimited(gmu_pdev_dev, "syncobj timeout ctx %d ts %u\n", 433: cmd->gc.ctxt_id, cmd->gc.ts); 434: find_timeout_syncobj(adreno_dev, cmd->gc.ctxt_id, cmd->gc.ts); 435: break; 436: case GMU_CP_DDEBR_HW_FAULT_ERROR: 437: dev_crit_ratelimited(gmu_pdev_dev, 438: "CP DDE BR | Ringbuffer HW fault | status=0x%8.8x\n", 439: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 440: KEY_CP_DDEBR_HW_FAULT)); 441: break; 442: case GMU_CP_DDEBR_OPCODE_ERROR: 443: dev_crit_ratelimited(gmu_pdev_dev, 444: "CP DDE BR opcode error | opcode=0x%8.8x\n", 445: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 446: KEY_CP_DDEBR_OPCODE_ERROR)); 447: break; 448: case GMU_CP_DDEBR_UCODE_ERROR: 449: dev_crit_ratelimited(gmu_pdev_dev, "CP DDE BR ucode error\n"); 450: break; 451: case GMU_CP_DDEBR_PROTECTED_ERROR: { 452: u32 status = gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 453: KEY_CP_DDEBR_PROTECTED_ERROR); 454: 455: dev_crit_ratelimited(gmu_pdev_dev, 456: "CP DDE BR | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 457: status & (1 << 20) ? "READ" : "WRITE", 458: status & 0x3FFFF, status); 459: } 460: break; 461: case GMU_CP_DDEBR_ILLEGAL_INST_ERROR: 462: dev_crit_ratelimited(gmu_pdev_dev, "CP DDEBR Illegal instruction error\n"); 463: break; 464: case GMU_CP_DDEBV_HW_FAULT_ERROR: 465: dev_crit_ratelimited(gmu_pdev_dev, 466: "CP DDE BV | Ringbuffer HW fault | status=0x%8.8x\n", 467: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 468: KEY_CP_DDEBV_HW_FAULT)); 469: break; 470: case GMU_CP_DDEBV_OPCODE_ERROR: 471: dev_crit_ratelimited(gmu_pdev_dev, 472: "CP DDE BV opcode error | opcode=0x%8.8x\n", 473: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 474: KEY_CP_DDEBV_OPCODE_ERROR)); 475: break; 476: case GMU_CP_DDEBV_UCODE_ERROR: 477: dev_crit_ratelimited(gmu_pdev_dev, "CP DDE BV ucode error\n"); 478: break; 479: case GMU_CP_DDEBV_PROTECTED_ERROR: { 480: u32 status = gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 481: KEY_CP_DDEBV_PROTECTED_ERROR); 482: 483: dev_crit_ratelimited(gmu_pdev_dev, 484: "CP DDE BV | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 485: status & (1 << 20) ? "READ" : "WRITE", 486: status & 0x3FFFF, status); 487: } 488: break; 489: case GMU_CP_DDEBV_ILLEGAL_INST_ERROR: 490: dev_crit_ratelimited(gmu_pdev_dev, "CP DDE BV Illegal instruction error\n"); MATCH LINES: 1617 1605: gen8_core->qos_value[i]); 1606: } 1607: } 1608: 1609: if (device->pwrctrl.rt_bus_hint) { 1610: ret = gen8_hfi_send_set_value(adreno_dev, HFI_VALUE_RB_IB_RULE, 0, 1611: device->pwrctrl.rt_bus_hint); 1612: if (ret) 1613: device->pwrctrl.rt_bus_hint = 0; 1614: } 1615: 1616: /* 1617: * Bits[3:0] contain the preemption timeout enable bit per ringbuffer 1618: * Bits[31:4] contain the timeout in ms 1619: */ 1620: return gen8_hfi_send_set_value(adreno_dev, HFI_VALUE_BIN_TIME, 1, 1621: FIELD_PREP(GENMASK(31, 4), ADRENO_PREEMPT_TIMEOUT) | 1622: FIELD_PREP(GENMASK(3, 0), 0xf)); 1623: 1624: } 1625: 1626: static int enable_gmu_stats(struct adreno_device *adreno_dev) 1627: { 1628: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1629: u32 data; 1630: 1631: if (!gmu->stats_enable) 1632: return 0; 1633: 1634: /* 1635: * Bits [23:0] contains the countables mask 1636: * Bits [31:24] is the sampling interval 1637: */ 1638: data = FIELD_PREP(GENMASK(23, 0), gmu->stats_mask) | 1639: FIELD_PREP(GENMASK(31, 24), gmu->stats_interval); 1640: 1641: return gen8_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_GMU_STATS, 1, data); --- FILE: \adreno_gen8_preempt.c | HITS: 40 --- MATCH LINES: 23 11: #include "kgsl_util.h" 12: 13: #define PREEMPT_RECORD(_field) \ 14: offsetof(struct gen8_cp_preemption_record, _field) 15: 16: #define PREEMPT_SMMU_RECORD(_field) \ 17: offsetof(struct gen8_cp_smmu_info, _field) 18: 19: static void _update_wptr(struct adreno_device *adreno_dev, bool reset_timer, 20: bool atomic) 21: { 22: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 23: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 24: unsigned long flags; 25: int ret = 0; 26: 27: spin_lock_irqsave(&rb->preempt_lock, flags); 28: 29: if (!atomic) { 30: /* 31: * We might have skipped updating the wptr in case we are in 32: * dispatcher context. Do it now. 33: */ 34: if (rb->skip_inline_wptr) { 35: 36: ret = gen8_fenced_write(adreno_dev, 37: GEN8_CP_RB_WPTR_GC, rb->wptr, 38: FENCE_STATUS_WRITEDROPPED0_MASK); 39: 40: reset_timer = true; 41: rb->skip_inline_wptr = false; 42: } 43: } else { 44: u32 wptr; 45: 46: kgsl_regread(device, GEN8_CP_RB_WPTR_GC, &wptr); 47: if (wptr != rb->wptr) { MATCH LINES: 90, 112, 143 78: { 79: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 80: u32 status; 81: 82: /* 83: * In the very unlikely case that the power is off, do nothing - the 84: * state will be reset on power up and everybody will be happy 85: */ 86: 87: if (!kgsl_state_is_awake(device)) 88: return; 89: 90: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_CNTL, &status); 91: 92: if (status & 0x1) { 93: dev_err(device->dev, 94: "Preemption not complete: status=%X cur=%d R/W=%X/%X next=%d R/W=%X/%X\n", 95: status, adreno_dev->cur_rb->id, 96: adreno_get_rptr(adreno_dev->cur_rb), 97: adreno_dev->cur_rb->wptr, 98: adreno_dev->next_rb->id, 99: adreno_get_rptr(adreno_dev->next_rb), 100: adreno_dev->next_rb->wptr); 101: 102: /* Set a fault and restart */ 103: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 104: 105: return; 106: } 107: 108: adreno_dev->preempt.count++; 109: 110: kgsl_delete_timer_sync(&adreno_dev->preempt.timer); 111: 112: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 113: 114: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 115: status, 0); 116: 117: /* Clean up all the bits */ 118: adreno_dev->prev_rb = adreno_dev->cur_rb; 119: adreno_dev->cur_rb = adreno_dev->next_rb; 120: adreno_dev->next_rb = NULL; 121: 122: /* Update the wptr for the new command queue */ 123: _update_wptr(adreno_dev, true, false); 124: 125: /* Update the dispatcher timer for the new command queue */ 126: mod_timer(&adreno_dev->dispatcher.timer, 127: adreno_dev->cur_rb->dispatch_q.expires); 128: 129: /* Clear the preempt state */ 130: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 131: } 132: 133: static void _gen8_preemption_fault(struct adreno_device *adreno_dev) 134: { 135: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 136: u32 status; 137: 138: /* 139: * If the power is on check the preemption status one more time - if it 140: * was successful then just transition to the complete state 141: */ 142: if (kgsl_state_is_awake(device)) { 143: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_CNTL, &status); 144: 145: if (!(status & 0x1)) { 146: adreno_set_preempt_state(adreno_dev, 147: ADRENO_PREEMPT_COMPLETE); 148: 149: adreno_scheduler_queue(adreno_dev); 150: return; 151: } 152: } 153: 154: dev_err(device->dev, 155: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 156: adreno_dev->cur_rb->id, 157: adreno_get_rptr(adreno_dev->cur_rb), 158: adreno_dev->cur_rb->wptr, 159: adreno_dev->next_rb->id, 160: adreno_get_rptr(adreno_dev->next_rb), 161: adreno_dev->next_rb->wptr); 162: 163: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 164: } 165: 166: static void _gen8_preemption_worker(struct work_struct *work) 167: { MATCH LINES: 183, 184, 187, 191, 210, 221, 222, 225, 226, 231 171: struct adreno_device, preempt); 172: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 173: 174: /* Need to take the mutex to make sure that the power stays on */ 175: kgsl_mutex_lock(&device->mutex); 176: 177: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_FAULTED)) 178: _gen8_preemption_fault(adreno_dev); 179: 180: kgsl_mutex_unlock(&device->mutex); 181: } 182: 183: /* Find the highest priority active ringbuffer */ 184: static struct adreno_ringbuffer *gen8_next_ringbuffer( 185: struct adreno_device *adreno_dev) 186: { 187: struct adreno_ringbuffer *rb; 188: unsigned long flags; 189: u32 i; 190: 191: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 192: bool empty; 193: 194: spin_lock_irqsave(&rb->preempt_lock, flags); 195: empty = adreno_rb_empty(rb); 196: spin_unlock_irqrestore(&rb->preempt_lock, flags); 197: 198: if (!empty) 199: return rb; 200: } 201: 202: return NULL; 203: } 204: 205: void gen8_preemption_trigger(struct adreno_device *adreno_dev, bool atomic) 206: { 207: const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev); 208: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 209: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 210: struct adreno_ringbuffer *next; 211: u64 ttbr0, gpuaddr; 212: u32 contextidr, cntl; 213: unsigned long flags; 214: struct adreno_preemption *preempt = &adreno_dev->preempt; 215: 216: /* Put ourselves into a possible trigger state */ 217: if (!adreno_move_preempt_state(adreno_dev, 218: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START)) 219: return; 220: 221: /* Get the next ringbuffer to preempt in */ 222: next = gen8_next_ringbuffer(adreno_dev); 223: 224: /* 225: * Nothing to do if every ringbuffer is empty or if the current 226: * ringbuffer is the only active one 227: */ 228: if (next == NULL || next == adreno_dev->cur_rb) { 229: /* 230: * Update any critical things that might have been skipped while 231: * we were looking for a new ringbuffer 232: */ 233: 234: if (next != NULL) { 235: _update_wptr(adreno_dev, false, atomic); 236: 237: mod_timer(&adreno_dev->dispatcher.timer, 238: adreno_dev->cur_rb->dispatch_q.expires); 239: } 240: 241: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 242: return; 243: } 244: 245: /* Turn off the dispatcher timer */ 246: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 247: 248: /* 249: * This is the most critical section - we need to take care not to race 250: * until we have programmed the CP for the switch 251: */ 252: 253: spin_lock_irqsave(&next->preempt_lock, flags); 254: 255: /* Get the pagetable from the pagetable info. */ MATCH LINES: 297, 315, 322, 328, 335, 341, 373, 405, 433 285: * It is more efficient to use a keepalive+wake-on-fence approach here 286: * rather than an OOB. Both keepalive and the fence are effectively 287: * free when the GPU is already powered on, whereas an OOB requires an 288: * unconditional handshake with the GMU. 289: */ 290: _power_collapse_set(adreno_dev, true); 291: 292: /* 293: * Fenced writes on this path will make sure the GPU is woken up 294: * in case it was power collapsed by the GMU. 295: */ 296: if (gen8_fenced_write(adreno_dev, 297: GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_LO, 298: lower_32_bits(next->preemption_desc->gpuaddr), 299: FENCE_STATUS_WRITEDROPPED1_MASK)) 300: goto err; 301: 302: /* 303: * Above fence writes will make sure GMU comes out of 304: * IFPC state if its was in IFPC state but it doesn't 305: * guarantee that GMU FW actually moved to ACTIVE state 306: * i.e. wake-up from IFPC is complete. 307: * Wait for GMU to move to ACTIVE state before triggering 308: * preemption. This is require to make sure CP doesn't 309: * interrupt GMU during wake-up from IFPC. 310: */ 311: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 312: goto err; 313: 314: if (gen8_fenced_write(adreno_dev, 315: GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_HI, 316: upper_32_bits(next->preemption_desc->gpuaddr), 317: FENCE_STATUS_WRITEDROPPED1_MASK)) 318: goto err; 319: 320: if (kgsl_mmu_is_secured(&device->mmu)) { 321: if (gen8_fenced_write(adreno_dev, 322: GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_LO, 323: lower_32_bits(next->secure_preemption_desc->gpuaddr), 324: FENCE_STATUS_WRITEDROPPED1_MASK)) 325: goto err; 326: 327: if (gen8_fenced_write(adreno_dev, 328: GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_HI, 329: upper_32_bits(next->secure_preemption_desc->gpuaddr), 330: FENCE_STATUS_WRITEDROPPED1_MASK)) 331: goto err; 332: } 333: 334: if (gen8_fenced_write(adreno_dev, 335: GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_LO, 336: lower_32_bits(gpuaddr), 337: FENCE_STATUS_WRITEDROPPED1_MASK)) 338: goto err; 339: 340: if (gen8_fenced_write(adreno_dev, 341: GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_HI, 342: upper_32_bits(gpuaddr), 343: FENCE_STATUS_WRITEDROPPED1_MASK)) 344: goto err; 345: 346: adreno_dev->next_rb = next; 347: 348: /* Start the timer to detect a stuck preemption */ 349: mod_timer(&adreno_dev->preempt.timer, 350: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 351: 352: cntl = (preempt->preempt_level << 6) | 0x01; 353: 354: /* Skip save/restore during L1 preemption */ 355: if (preempt->skipsaverestore) 356: cntl |= (1 << 9); 357: 358: /* Enable GMEM save/restore across preemption */ 359: if (preempt->usesgmem) 360: cntl |= (1 << 8); 361: 362: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 363: cntl, 0); 364: 365: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 366: 367: if (gen8_core->qos_value) 368: kgsl_sharedmem_writel(preempt->scratch, 369: PREEMPT_SCRATCH_OFFSET(QOS_VALUE_IDX), 370: gen8_core->qos_value[next->id]); 371: 372: /* Trigger the preemption */ 373: if (gen8_fenced_write(adreno_dev, GEN8_CP_CONTEXT_SWITCH_CNTL, cntl, 374: FENCE_STATUS_WRITEDROPPED1_MASK)) { 375: adreno_dev->next_rb = NULL; 376: kgsl_delete_timer(&adreno_dev->preempt.timer); 377: goto err; 378: } 379: 380: return; 381: err: 382: /* If fenced write fails, take inline snapshot and trigger recovery */ 383: if (!in_interrupt()) { 384: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 385: adreno_scheduler_fault(adreno_dev, 386: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 387: } else { 388: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 389: } 390: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 391: /* Clear the keep alive */ 392: _power_collapse_set(adreno_dev, false); 393: 394: } 395: 396: void gen8_preemption_callback(struct adreno_device *adreno_dev, int bit) 397: { 398: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 399: u32 status; 400: 401: if (!adreno_move_preempt_state(adreno_dev, 402: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 403: return; 404: 405: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_CNTL, &status); 406: 407: if (status & 0x1) { 408: dev_err(KGSL_DEVICE(adreno_dev)->dev, 409: "preempt interrupt with non-zero status: %X\n", 410: status); 411: 412: /* 413: * Under the assumption that this is a race between the 414: * interrupt and the register, schedule the worker to clean up. 415: * If the status still hasn't resolved itself by the time we get 416: * there then we have to assume something bad happened 417: */ 418: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE); 419: adreno_scheduler_queue(adreno_dev); 420: return; 421: } 422: 423: adreno_dev->preempt.count++; 424: 425: /* 426: * We can now safely clear the preemption keepalive bit, allowing 427: * power collapse to resume its regular activity. 428: */ 429: _power_collapse_set(adreno_dev, false); 430: 431: kgsl_delete_timer(&adreno_dev->preempt.timer); 432: 433: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 434: 435: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 436: status, 0); 437: 438: adreno_dev->prev_rb = adreno_dev->cur_rb; 439: adreno_dev->cur_rb = adreno_dev->next_rb; 440: adreno_dev->next_rb = NULL; 441: 442: /* Update the wptr if it changed while preemption was ongoing */ 443: _update_wptr(adreno_dev, true, true); 444: 445: /* Update the dispatcher timer for the new command queue */ 446: mod_timer(&adreno_dev->dispatcher.timer, 447: adreno_dev->cur_rb->dispatch_q.expires); 448: 449: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 450: 451: gen8_preemption_trigger(adreno_dev, true); 452: } 453: 454: void gen8_preemption_prepare_postamble(struct adreno_device *adreno_dev) 455: { 456: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 457: const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev); MATCH LINES: 525, 561, 587, 596, 609, 631, 634, 638, 644, 652, 673, 678, 683, 684 513: 514: kgsl_mutex_lock(&device->mutex); 515: 516: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE)) 517: _gen8_preemption_done(adreno_dev); 518: 519: gen8_preemption_trigger(adreno_dev, false); 520: 521: kgsl_mutex_unlock(&device->mutex); 522: } 523: 524: u32 gen8_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 525: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 526: u32 *cmds) 527: { 528: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 529: u32 count = kgsl_mmu_is_secured(&device->mmu) ? 12 : 9; 530: u32 *cmds_orig = cmds; 531: 532: if (!adreno_is_preemption_enabled(adreno_dev)) 533: return 0; 534: 535: if (test_and_set_bit(ADRENO_RB_SET_PSEUDO_DONE, &rb->flags)) 536: goto done; 537: 538: *cmds++ = cp_type7_packet(CP_THREAD_CONTROL, 1); 539: *cmds++ = CP_SET_THREAD_BR; 540: 541: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, count); 542: 543: /* NULL SMMU_INFO buffer - we track in KMD */ 544: *cmds++ = SET_PSEUDO_SMMU_INFO; 545: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 546: 547: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 548: cmds += cp_gpuaddr(adreno_dev, cmds, rb->preemption_desc->gpuaddr); 549: 550: if (kgsl_mmu_is_secured(&device->mmu)) { 551: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 552: cmds += cp_gpuaddr(adreno_dev, cmds, 553: rb->secure_preemption_desc->gpuaddr); 554: } 555: 556: /* 557: * There is no need to specify this address when we are about to 558: * trigger preemption. This is because CP internally stores this 559: * address specified here in the CP_SET_PSEUDO_REGISTER payload to 560: * the context record and thus knows from where to restore 561: * the saved perfcounters for the new ringbuffer. 562: */ 563: *cmds++ = SET_PSEUDO_COUNTER; 564: cmds += cp_gpuaddr(adreno_dev, cmds, 565: rb->perfcounter_save_restore_desc->gpuaddr); 566: 567: done: 568: if (drawctxt) { 569: cmds += adreno_prepare_preib_preempt_scratch(adreno_dev, drawctxt, cmds); 570: cmds += adreno_prepare_preib_postamble_scratch(adreno_dev, cmds); 571: } 572: 573: return (u32) (cmds - cmds_orig); 574: } 575: 576: u32 gen8_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 577: u32 *cmds) 578: { 579: u32 index = 0; 580: 581: if (!adreno_is_preemption_enabled(adreno_dev)) 582: return 0; 583: 584: if (adreno_dev->cur_rb) { 585: u64 dest = PREEMPT_SCRATCH_ADDR(adreno_dev, adreno_dev->cur_rb->id); 586: 587: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 4); 588: cmds[index++] = lower_32_bits(dest); 589: cmds[index++] = upper_32_bits(dest); 590: cmds[index++] = 0; 591: cmds[index++] = 0; 592: } 593: 594: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 595: cmds[index++] = CP_SET_THREAD_BOTH; 596: cmds[index++] = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 597: cmds[index++] = 0; 598: cmds[index++] = 0; 599: cmds[index++] = 1; 600: cmds[index++] = 0; 601: 602: return index; 603: } 604: 605: void gen8_preemption_start(struct adreno_device *adreno_dev) 606: { 607: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 608: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 609: struct adreno_ringbuffer *rb; 610: u32 i; 611: 612: if (!adreno_is_preemption_enabled(adreno_dev)) 613: return; 614: 615: /* Force the state to be clear */ 616: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 617: 618: if (kgsl_mmu_is_perprocess(&device->mmu)) { 619: /* smmu_info is allocated and mapped in gen8_preemption_iommu_init */ 620: kgsl_sharedmem_writel(iommu->smmu_info, 621: PREEMPT_SMMU_RECORD(magic), GEN8_CP_SMMU_INFO_MAGIC_REF); 622: kgsl_sharedmem_writeq(iommu->smmu_info, 623: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 624: 625: /* The CP doesn't use the asid record, so poison it */ 626: kgsl_sharedmem_writel(iommu->smmu_info, 627: PREEMPT_SMMU_RECORD(asid), 0xdecafbad); 628: kgsl_sharedmem_writel(iommu->smmu_info, 629: PREEMPT_SMMU_RECORD(context_idr), 0); 630: 631: kgsl_regwrite(device, GEN8_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 632: lower_32_bits(iommu->smmu_info->gpuaddr)); 633: 634: kgsl_regwrite(device, GEN8_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 635: upper_32_bits(iommu->smmu_info->gpuaddr)); 636: } 637: 638: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 639: kgsl_sharedmem_writel(rb->preemption_desc, 640: PREEMPT_RECORD(rptr), 0); 641: kgsl_sharedmem_writel(rb->preemption_desc, 642: PREEMPT_RECORD(wptr), 0); 643: 644: adreno_ringbuffer_set_pagetable(device, rb, 645: device->mmu.defaultpagetable); 646: 647: clear_bit(ADRENO_RB_SET_PSEUDO_DONE, &rb->flags); 648: } 649: } 650: 651: static void reset_rb_preempt_record(struct adreno_device *adreno_dev, 652: struct adreno_ringbuffer *rb) 653: { 654: memset(rb->preemption_desc->hostptr, 0x0, rb->preemption_desc->size); 655: 656: kgsl_sharedmem_writel(rb->preemption_desc, 657: PREEMPT_RECORD(magic), GEN8_CP_CTXRECORD_MAGIC_REF); 658: kgsl_sharedmem_writel(rb->preemption_desc, 659: PREEMPT_RECORD(cntl), GEN8_CP_RB_CNTL_DEFAULT); 660: kgsl_sharedmem_writeq(rb->preemption_desc, 661: PREEMPT_RECORD(rptr_addr), SCRATCH_RB_GPU_ADDR( 662: KGSL_DEVICE(adreno_dev), rb->id, rptr)); 663: kgsl_sharedmem_writeq(rb->preemption_desc, 664: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 665: kgsl_sharedmem_writeq(rb->preemption_desc, 666: PREEMPT_RECORD(bv_rptr_addr), SCRATCH_RB_GPU_ADDR( 667: KGSL_DEVICE(adreno_dev), rb->id, bv_rptr)); 668: } 669: 670: void gen8_reset_preempt_records(struct adreno_device *adreno_dev) 671: { 672: int i; 673: struct adreno_ringbuffer *rb; 674: 675: if (!adreno_is_preemption_enabled(adreno_dev)) 676: return; 677: 678: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 679: reset_rb_preempt_record(adreno_dev, rb); 680: } 681: } 682: 683: static int gen8_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 684: struct adreno_ringbuffer *rb) 685: { 686: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 687: u64 ctxt_record_size = adreno_dev->total_ctxt_record_sz; 688: u64 curr_gmem_size = adreno_gmem_size(adreno_dev); 689: int ret; 690: 691: /* 692: * Since RB0 always runs to completion, there is no need to 693: * save/restore GMEM data for RB0. 694: */ 695: if (rb->id == 0) 696: ctxt_record_size -= curr_gmem_size; 697: 698: ret = adreno_allocate_global(device, &rb->preemption_desc, 699: ctxt_record_size, SZ_16K, 0, 700: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 701: if (ret) 702: return ret; 703: 704: if (kgsl_mmu_is_secured(&device->mmu)) { 705: ret = adreno_allocate_global(device, &rb->secure_preemption_desc, 706: ctxt_record_size, 0, 707: KGSL_MEMFLAGS_SECURE, KGSL_MEMDESC_PRIVILEGED, 708: "secure_preemption_desc"); MATCH LINES: 731, 744, 745 719: 720: reset_rb_preempt_record(adreno_dev, rb); 721: 722: return 0; 723: } 724: 725: int gen8_preemption_init(struct adreno_device *adreno_dev) 726: { 727: u32 flags = ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? KGSL_MEMDESC_PRIVILEGED : 0; 728: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 729: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 730: struct adreno_preemption *preempt = &adreno_dev->preempt; 731: struct adreno_ringbuffer *rb; 732: int ret; 733: u32 i; 734: 735: /* We are dependent on IOMMU to make preemption go on the CP side */ 736: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) { 737: ret = -ENODEV; 738: goto done; 739: } 740: 741: INIT_WORK(&preempt->work, _gen8_preemption_worker); 742: 743: /* Allocate mem for storing preemption switch record */ 744: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 745: ret = gen8_preemption_ringbuffer_init(adreno_dev, rb); 746: if (ret) 747: goto done; 748: } 749: 750: ret = adreno_allocate_global(device, &preempt->scratch, PAGE_SIZE, 751: 0, 0, flags, "preempt_scratch"); 752: if (ret) 753: goto done; 754: 755: /* Allocate mem for storing preemption smmu record */ 756: if (kgsl_mmu_is_perprocess(&device->mmu)) { 757: ret = adreno_allocate_global(device, &iommu->smmu_info, PAGE_SIZE, 0, 758: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 759: "smmu_info"); 760: if (ret) 761: goto done; 762: } 763: 764: return 0; 765: done: 766: clear_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 767: return ret; 768: } --- FILE: \adreno_gen8_ringbuffer.c | HITS: 41 --- MATCH LINES: 10, 23, 40, 61, 91 1: // SPDX-License-Identifier: GPL-2.0-only 2: /* 3: * Copyright (c) 2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include "adreno.h" 8: #include "adreno_gen8.h" 9: #include "adreno_pm4types.h" 10: #include "adreno_ringbuffer.h" 11: #include "adreno_trace.h" 12: #include "kgsl_trace.h" 13: 14: static bool is_concurrent_binning(struct adreno_context *drawctxt) 15: { 16: if (!drawctxt) 17: return false; 18: 19: return !(drawctxt->base.flags & KGSL_CONTEXT_SECURE); 20: } 21: 22: static int gen8_rb_pagetable_switch(struct adreno_device *adreno_dev, 23: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 24: struct kgsl_pagetable *pagetable, u32 *cmds) 25: { 26: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 27: u64 ttbr0 = kgsl_mmu_pagetable_get_ttbr0(pagetable); 28: int count = 0; 29: u32 id = drawctxt ? drawctxt->base.id : 0; 30: 31: if (pagetable == device->mmu.defaultpagetable) 32: return 0; 33: 34: /* CP switches the pagetable and flushes the Caches */ 35: cmds[count++] = cp_type7_packet(CP_SMMU_TABLE_UPDATE, 3); 36: cmds[count++] = lower_32_bits(ttbr0); 37: cmds[count++] = upper_32_bits(ttbr0); 38: cmds[count++] = id; 39: 40: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 5); 41: cmds[count++] = lower_32_bits(SCRATCH_RB_GPU_ADDR(device, 42: rb->id, ttbr0)); 43: cmds[count++] = upper_32_bits(SCRATCH_RB_GPU_ADDR(device, 44: rb->id, ttbr0)); 45: cmds[count++] = lower_32_bits(ttbr0); 46: cmds[count++] = upper_32_bits(ttbr0); 47: cmds[count++] = id; 48: 49: /* 50: * Sync both threads after switching pagetables and enable BR only 51: * to make sure BV doesn't race ahead while BR is still switching 52: * pagetables. 53: */ 54: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 55: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BR; 56: 57: return count; 58: } 59: 60: static int gen8_rb_context_switch(struct adreno_device *adreno_dev, 61: struct adreno_ringbuffer *rb, 62: struct adreno_context *drawctxt) 63: { 64: struct kgsl_pagetable *pagetable = 65: adreno_drawctxt_get_pagetable(drawctxt); 66: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 67: int count = 0; 68: u32 cmds[63]; 69: 70: /* Sync both threads */ 71: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 72: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BOTH; 73: /* Reset context state */ 74: cmds[count++] = cp_type7_packet(CP_RESET_CONTEXT_STATE, 1); 75: cmds[count++] = CP_RESET_GLOBAL_LOCAL_TS | CP_CLEAR_BV_BR_COUNTER | 76: CP_CLEAR_RESOURCE_TABLE | CP_CLEAR_ON_CHIP_TS; 77: /* 78: * Enable/disable concurrent binning for pagetable switch and 79: * set the thread to BR since only BR can execute the pagetable 80: * switch packets. 81: */ 82: /* Sync both threads and enable BR only */ 83: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 84: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BR; 85: 86: if (adreno_drawctxt_get_pagetable(rb->drawctxt_active) != pagetable) { 87: /* Flush LRZ before every pagetable switch */ 88: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 89: cmds[count++] = CP_SET_THREAD_BOTH; 90: 91: cmds[count++] = cp_type7_packet(CP_EVENT_WRITE, 1); 92: /* Add event ID for LRZ flush as packet payload */ 93: cmds[count++] = LRZ_CACHE_FLUSH; 94: 95: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 96: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BR; 97: 98: /* Clear performance counters during context switches */ 99: if (!adreno_dev->perfcounter) { 100: cmds[count++] = cp_type4_packet(GEN8_RBBM_PERFCTR_SRAM_INIT_CMD, 1); 101: cmds[count++] = 0x1; 102: cmds[count++] = cp_type4_packet(GEN8_RBBM_SLICE_PERFCTR_SRAM_INIT_CMD, 1); 103: cmds[count++] = 0x1; 104: } 105: 106: count += gen8_rb_pagetable_switch(adreno_dev, rb, 107: drawctxt, pagetable, &cmds[count]); 108: 109: /* Wait for performance counter clear to finish */ 110: if (!adreno_dev->perfcounter) { 111: cmds[count++] = cp_type7_packet(CP_WAIT_REG_MEM, 6); 112: cmds[count++] = 0x3; 113: cmds[count++] = GEN8_RBBM_PERFCTR_SRAM_INIT_STATUS; 114: cmds[count++] = 0x0; 115: cmds[count++] = 0x1; MATCH LINES: 136, 143, 150, 162, 176 124: /* 125: * Set the CONTEXTIDR register to the current context id so we 126: * can use it in pagefault debugging. Unlike TTBR0 we don't 127: * need any special sequence or locking to change it 128: */ 129: cmds[count++] = cp_type4_packet(offset, 1); 130: cmds[count++] = drawctxt->base.id; 131: } 132: 133: cmds[count++] = cp_type7_packet(CP_NOP, 1); 134: cmds[count++] = CONTEXT_TO_MEM_IDENTIFIER; 135: 136: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 137: cmds[count++] = lower_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb, 138: current_context)); 139: cmds[count++] = upper_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb, 140: current_context)); 141: cmds[count++] = drawctxt->base.id; 142: 143: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 144: cmds[count++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 145: KGSL_MEMSTORE_GLOBAL, current_context)); 146: cmds[count++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 147: KGSL_MEMSTORE_GLOBAL, current_context)); 148: cmds[count++] = drawctxt->base.id; 149: 150: cmds[count++] = cp_type7_packet(CP_EVENT_WRITE, 1); 151: cmds[count++] = 0x31; 152: 153: if (adreno_is_preemption_enabled(adreno_dev) && drawctxt->base.user_ctxt_record) { 154: u64 gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 155: 156: cmds[count++] = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 3); 157: cmds[count++] = SET_PSEUDO_NON_PRIV_SAVE_ADDR; 158: cmds[count++] = lower_32_bits(gpuaddr); 159: cmds[count++] = upper_32_bits(gpuaddr); 160: } 161: 162: return gen8_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED, 163: cmds, count, 0, NULL); 164: } 165: 166: #define RB_SOPTIMESTAMP(device, rb) \ 167: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 168: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 169: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 170: 171: #define RB_EOPTIMESTAMP(device, rb) \ 172: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 173: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 174: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 175: 176: int gen8_ringbuffer_submit(struct adreno_ringbuffer *rb, 177: struct adreno_submit_time *time) 178: { 179: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 180: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 181: int ret = 0; 182: unsigned long flags; 183: 184: adreno_get_submit_time(adreno_dev, rb, time); 185: adreno_profile_submit_time(time); 186: 187: spin_lock_irqsave(&rb->preempt_lock, flags); 188: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 189: if (adreno_dev->cur_rb == rb) { 190: ret = gen8_fenced_write(adreno_dev, 191: GEN8_CP_RB_WPTR_GC, rb->_wptr, 192: FENCE_STATUS_WRITEDROPPED0_MASK); 193: rb->skip_inline_wptr = false; 194: } 195: } else { 196: if (adreno_dev->cur_rb == rb) 197: rb->skip_inline_wptr = true; 198: } 199: 200: rb->wptr = rb->_wptr; MATCH LINES: 216, 227, 230, 231, 232, 235, 237, 240, 241, 252, 253, 277, 312, 319, 327, 347, 366, 388, 392, 398, 406, 440, 466, 479, 490 204: /* 205: * If WPTR update fails, take inline snapshot and trigger 206: * recovery. 207: */ 208: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 209: adreno_scheduler_fault(adreno_dev, 210: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 211: } 212: 213: return ret; 214: } 215: 216: int gen8_ringbuffer_init(struct adreno_device *adreno_dev) 217: { 218: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 219: int i, ret; 220: 221: ret = adreno_allocate_global(device, &device->scratch, PAGE_SIZE, 222: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED, 223: "scratch"); 224: if (ret) 225: return ret; 226: 227: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]); 228: 229: if (!adreno_preemption_feature_set(adreno_dev)) { 230: adreno_dev->num_ringbuffers = 1; 231: return adreno_ringbuffer_setup(adreno_dev, 232: &adreno_dev->ringbuffers[0], 0); 233: } 234: 235: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers); 236: 237: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 238: int ret; 239: 240: ret = adreno_ringbuffer_setup(adreno_dev, 241: &adreno_dev->ringbuffers[i], i); 242: if (ret) 243: return ret; 244: } 245: 246: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 247: return 0; 248: } 249: 250: #define GEN8_SUBMIT_MAX 104 251: 252: int gen8_ringbuffer_addcmds(struct adreno_device *adreno_dev, 253: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 254: u32 flags, u32 *in, u32 dwords, u32 timestamp, 255: struct adreno_submit_time *time) 256: { 257: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 258: u32 size = GEN8_SUBMIT_MAX + dwords; 259: u32 *cmds, index = 0; 260: u64 profile_gpuaddr; 261: u32 profile_dwords; 262: 263: if (adreno_drawctxt_detached(drawctxt)) 264: return -ENOENT; 265: 266: if (adreno_gpu_fault(adreno_dev) != 0) 267: return -EPROTO; 268: 269: rb->timestamp++; 270: 271: if (drawctxt) 272: drawctxt->internal_timestamp = rb->timestamp; 273: 274: /* All submissions are run with protected mode off due to APRIV */ 275: flags &= ~F_NOTPROTECTED; 276: 277: cmds = adreno_ringbuffer_allocspace(rb, size); 278: if (IS_ERR(cmds)) 279: return PTR_ERR(cmds); 280: 281: /* Identify the start of a command */ 282: cmds[index++] = cp_type7_packet(CP_NOP, 1); 283: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 284: 285: /* This is 25 dwords when drawctxt is not NULL and perfcounter needs to be zapped*/ 286: index += gen8_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 287: &cmds[index]); 288: 289: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 290: cmds[index++] = CP_SET_THREAD_BOTH; 291: 292: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 293: cmds[index++] = 0x101; /* IFPC disable */ 294: 295: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 296: cmds[index++] = CP_SET_THREAD_BR; 297: 298: /* 299: * The POWER_CONTROL packet should always be after IFPC disable MARKER 300: * to avoid opcode errors 301: */ 302: if (flags & F_MALU) { 303: cmds[index++] = cp_type7_packet(CP_POWER_CONTROL, 2); 304: cmds[index++] = 1; /* Control mALU power */ 305: cmds[index++] = 1; /* Turn on mALU */ 306: } 307: 308: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 309: drawctxt, &profile_dwords); 310: 311: if (profile_gpuaddr) { 312: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 313: cmds[index++] = lower_32_bits(profile_gpuaddr); 314: cmds[index++] = upper_32_bits(profile_gpuaddr); 315: cmds[index++] = profile_dwords; 316: } 317: 318: if (drawctxt) { 319: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 320: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 321: drawctxt)); 322: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 323: drawctxt)); 324: cmds[index++] = timestamp; 325: } 326: 327: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 328: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 329: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); 330: cmds[index++] = rb->timestamp; 331: 332: if (IS_SECURE(flags)) { 333: /* Sync BV and BR if entering secure mode */ 334: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 335: cmds[index++] = CP_SYNC_THREADS | CP_CONCURRENT_BIN_DISABLE; 336: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 337: cmds[index++] = 1; 338: } 339: 340: memcpy(&cmds[index], in, dwords << 2); 341: index += dwords; 342: 343: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev, 344: drawctxt, &dwords); 345: 346: if (profile_gpuaddr) { 347: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 348: cmds[index++] = lower_32_bits(profile_gpuaddr); 349: cmds[index++] = upper_32_bits(profile_gpuaddr); 350: cmds[index++] = profile_dwords; 351: } 352: 353: if (test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &device->mmu.pfpolicy)) 354: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0); 355: 356: if (is_concurrent_binning(drawctxt)) { 357: u64 addr = SCRATCH_RB_GPU_ADDR(device, rb->id, bv_ts); 358: 359: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 360: cmds[index++] = CP_SET_THREAD_BV; 361: 362: /* 363: * Make sure the timestamp is committed once BV pipe is 364: * completely done with this submission. 365: */ 366: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 367: cmds[index++] = CACHE_CLEAN | BIT(27); 368: cmds[index++] = lower_32_bits(addr); 369: cmds[index++] = upper_32_bits(addr); 370: cmds[index++] = rb->timestamp; 371: 372: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 373: cmds[index++] = CP_SET_THREAD_BR; 374: 375: /* 376: * This makes sure that BR doesn't race ahead and commit 377: * timestamp to memstore while BV is still processing 378: * this submission. 379: */ 380: cmds[index++] = cp_type7_packet(CP_WAIT_TIMESTAMP, 4); 381: cmds[index++] = 0; 382: cmds[index++] = lower_32_bits(addr); 383: cmds[index++] = upper_32_bits(addr); 384: cmds[index++] = rb->timestamp; 385: } 386: 387: /* 388: * If this is an internal command, just write the ringbuffer timestamp, 389: * otherwise, write both 390: */ 391: if (!drawctxt) { 392: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 393: cmds[index++] = CACHE_CLEAN | BIT(31) | BIT(27); 394: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 395: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 396: cmds[index++] = rb->timestamp; 397: } else { 398: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 399: cmds[index++] = CACHE_CLEAN | BIT(31) | BIT(27); 400: cmds[index++] = lower_32_bits(CTXT_EOPTIMESTAMP(device, 401: drawctxt)); 402: cmds[index++] = upper_32_bits(CTXT_EOPTIMESTAMP(device, 403: drawctxt)); 404: cmds[index++] = timestamp; 405: 406: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 407: cmds[index++] = CACHE_CLEAN | BIT(27); 408: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 409: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 410: cmds[index++] = rb->timestamp; 411: } 412: 413: if (IS_WFI(flags)) 414: cmds[index++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 415: 416: if (IS_SECURE(flags)) { 417: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 418: cmds[index++] = CP_CONCURRENT_BIN_DISABLE; 419: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 420: cmds[index++] = 0; 421: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 422: cmds[index++] = CP_SYNC_THREADS; 423: } 424: 425: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 426: cmds[index++] = CP_SET_THREAD_BOTH; 427: 428: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 429: cmds[index++] = 0x100; /* IFPC enable */ 430: 431: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 432: cmds[index++] = CP_SET_THREAD_BR; 433: 434: /* 10 dwords */ 435: index += gen8_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 436: 437: /* Adjust the thing for the number of bytes we actually wrote */ 438: rb->_wptr -= (size - index); 439: 440: return gen8_ringbuffer_submit(rb, time); 441: } 442: 443: static u32 gen8_get_alwayson_counter(u32 *cmds, u64 gpuaddr) 444: { 445: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 446: cmds[1] = GEN8_CP_ALWAYS_ON_COUNTER_LO | (1 << 30) | (2 << 18); 447: cmds[2] = lower_32_bits(gpuaddr); 448: cmds[3] = upper_32_bits(gpuaddr); 449: 450: return 4; 451: } 452: 453: static u32 gen8_get_alwayson_context(u32 *cmds, u64 gpuaddr) 454: { 455: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 456: cmds[1] = GEN8_CP_ALWAYS_ON_CONTEXT_LO | (1 << 30) | (2 << 18); 457: cmds[2] = lower_32_bits(gpuaddr); 458: cmds[3] = upper_32_bits(gpuaddr); 459: 460: return 4; 461: } 462: 463: #define PROFILE_IB_DWORDS 4 464: #define PROFILE_IB_SLOTS (PAGE_SIZE / (PROFILE_IB_DWORDS << 2)) 465: 466: static u64 gen8_get_user_profiling_ib(struct adreno_ringbuffer *rb, 467: struct kgsl_drawobj_cmd *cmdobj, u32 target_offset, u32 *cmds) 468: { 469: u32 offset, *ib, dwords; 470: 471: if (IS_ERR(rb->profile_desc)) 472: return 0; 473: 474: offset = rb->profile_index * (PROFILE_IB_DWORDS << 2); 475: ib = rb->profile_desc->hostptr + offset; 476: dwords = gen8_get_alwayson_counter(ib, 477: cmdobj->profiling_buffer_gpuaddr + target_offset); 478: 479: cmds[0] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 480: cmds[1] = lower_32_bits(rb->profile_desc->gpuaddr + offset); 481: cmds[2] = upper_32_bits(rb->profile_desc->gpuaddr + offset); 482: cmds[3] = dwords; 483: 484: rb->profile_index = (rb->profile_index + 1) % PROFILE_IB_SLOTS; 485: 486: return 4; 487: } 488: 489: static int gen8_drawctxt_switch(struct adreno_device *adreno_dev, 490: struct adreno_ringbuffer *rb, 491: struct adreno_context *drawctxt) 492: { 493: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 494: int ret; 495: 496: if (rb->drawctxt_active == drawctxt) 497: return 0; 498: 499: if (kgsl_context_detached(&drawctxt->base)) 500: return -ENOENT; 501: 502: if (!_kgsl_context_get(&drawctxt->base)) 503: return -ENOENT; 504: 505: ret = gen8_rb_context_switch(adreno_dev, rb, drawctxt); 506: if (ret) { 507: kgsl_context_put(&drawctxt->base); 508: return ret; 509: } 510: 511: trace_adreno_drawctxt_switch(rb, drawctxt); 512: 513: /* Release the current drawctxt as soon as the new one is switched */ 514: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active, MATCH LINES: 541, 548 529: (dev)->profile_buffer->gpuaddr + \ 530: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 531: field)) 532: 533: #define GEN8_KERNEL_PROFILE_CONTEXT(dev, cmdobj, cmds, field) \ 534: gen8_get_alwayson_context((cmds), \ 535: (dev)->profile_buffer->gpuaddr + \ 536: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 537: field)) 538: 539: #define GEN8_COMMAND_DWORDS 63 540: 541: int gen8_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 542: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 543: struct adreno_submit_time *time) 544: { 545: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 546: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 547: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 548: struct adreno_ringbuffer *rb = drawctxt->rb; 549: int ret = 0, numibs = 0, index = 0; 550: u32 *cmds; 551: 552: /* Count the number of IBs (if we are not skipping) */ 553: if (!IS_SKIP(flags)) { 554: struct list_head *tmp; 555: 556: list_for_each(tmp, &cmdobj->cmdlist) 557: numibs++; 558: } 559: 560: cmds = kvmalloc((GEN8_COMMAND_DWORDS + (numibs * 5)) << 2, GFP_KERNEL); 561: if (!cmds) { 562: ret = -ENOMEM; 563: goto done; 564: } 565: 566: cmds[index++] = cp_type7_packet(CP_NOP, 1); 567: cmds[index++] = START_IB_IDENTIFIER; 568: 569: /* Kernel profiling: 8 dwords */ 570: if (IS_KERNEL_PROFILE(flags)) { 571: index += GEN8_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index], 572: started); MATCH LINES: 599, 616, 620 587: struct kgsl_memobj_node *ib; 588: 589: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 590: cmds[index++] = 0x00d; /* IB1LIST start */ 591: 592: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 593: if (ib->priv & MEMOBJ_SKIP || 594: (ib->flags & KGSL_CMDLIST_CTXTSWITCH_PREAMBLE && 595: !IS_PREAMBLE(flags))) 596: cmds[index++] = cp_type7_packet(CP_NOP, 4); 597: 598: cmds[index++] = 599: cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 600: cmds[index++] = lower_32_bits(ib->gpuaddr); 601: cmds[index++] = upper_32_bits(ib->gpuaddr); 602: 603: /* Double check that IB_PRIV is never set */ 604: cmds[index++] = (ib->size >> 2) & 0xfffff; 605: } 606: 607: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 608: cmds[index++] = 0x00e; /* IB1LIST end */ 609: } 610: 611: if (is_concurrent_binning(drawctxt)) { 612: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 613: cmds[index++] = CP_SET_THREAD_BR; 614: } 615: /* CCU invalidate depth */ 616: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1); 617: cmds[index++] = 24; 618: 619: /* CCU invalidate color */ 620: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1); 621: cmds[index++] = 25; 622: 623: /* 8 dwords */ 624: if (IS_KERNEL_PROFILE(flags)) { 625: index += GEN8_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index], 626: retired); 627: index += GEN8_KERNEL_PROFILE_CONTEXT(adreno_dev, cmdobj, &cmds[index], 628: ctx_end); 629: } 630: 631: /* 4 dwords */ 632: if (IS_USER_PROFILE(flags)) 633: index += GEN8_USER_PROFILE_IB(rb, cmdobj, &cmds[index], 634: gpu_ticks_retired); 635: 636: cmds[index++] = cp_type7_packet(CP_NOP, 1); 637: cmds[index++] = END_IB_IDENTIFIER; 638: 639: ret = gen8_drawctxt_switch(adreno_dev, rb, drawctxt); 640: 641: /* 642: * In the unlikely event of an error in the drawctxt switch, 643: * treat it like a hang 644: */ MATCH LINES: 661 649: */ 650: if (ret != -ENOSPC && ret != -ENOENT) 651: dev_err(device->dev, 652: "Unable to switch draw context: %d\n", ret); 653: goto done; 654: } 655: 656: adreno_drawobj_set_constraint(device, drawobj); 657: 658: if (drawobj->flags & KGSL_DRAWOBJ_USES_MALU) 659: flags |= F_MALU; 660: 661: ret = gen8_ringbuffer_addcmds(adreno_dev, drawctxt->rb, drawctxt, 662: flags, cmds, index, drawobj->timestamp, time); 663: 664: done: 665: trace_kgsl_issueibcmds(device, drawctxt->base.id, numibs, 666: drawobj->timestamp, drawobj->flags, ret, drawctxt->type); 667: 668: kvfree(cmds); 669: return ret; 670: } --- FILE: \adreno_hfi.h | HITS: 2 --- MATCH LINES: 178 166: #define HFI_CTXT_FLAG_TYPE_UNKNOWN 0x1e 167: #define HFI_CTXT_FLAG_PREEMPT_STYLE_MASK GENMASK(27, 25) 168: #define HFI_CTXT_FLAG_PREEMPT_STYLE_ANY 0 169: #define HFI_CTXT_FLAG_PREEMPT_STYLE_RB 1 170: #define HFI_CTXT_FLAG_PREEMPT_STYLE_FG 2 171: 172: /* Default sampling interval in units of 50 us */ 173: #define HFI_FEATURE_GMU_STATS_INTERVAL 4 174: 175: enum hfi_mem_kind { 176: /** @HFI_MEMKIND_GENERIC: Used for requesting generic memory */ 177: HFI_MEMKIND_GENERIC = 0, 178: /** @HFI_MEMKIND_RB: Used for requesting ringbuffer memory */ 179: HFI_MEMKIND_RB, 180: /** @HFI_MEMKIND_SCRATCH: Used for requesting scratch memory */ 181: HFI_MEMKIND_SCRATCH, 182: /** 183: * @HFI_MEMKIND_CSW_SMMU_INFO: Used for requesting SMMU record for 184: * preemption context switching 185: */ 186: HFI_MEMKIND_CSW_SMMU_INFO, 187: /** 188: * @HFI_MEMKIND_CSW_PRIV_NON_SECURE: Used for requesting privileged non 189: * secure preemption records 190: */ 191: HFI_MEMKIND_CSW_PRIV_NON_SECURE, 192: /** 193: * @HFI_MEMKIND_CSW_PRIV_SECURE: Used for requesting privileged secure 194: * preemption records 195: */ 196: HFI_MEMKIND_CSW_PRIV_SECURE, 197: /** 198: * @HFI_MEMKIND_CSW_NON_PRIV: Used for requesting non privileged per 199: * context preemption buffer 200: */ 201: HFI_MEMKIND_CSW_NON_PRIV, 202: /** MATCH LINES: 235 223: * doorbells) register space 224: */ 225: HFI_MEMKIND_MMIO_TCSR, 226: /** 227: * @HFI_MEMKIND_MMIO_QDSS_STM: Used for requesting QDSS STM register 228: * space 229: */ 230: HFI_MEMKIND_MMIO_QDSS_STM, 231: /** @HFI_MEMKIND_PROFILE: Used for kernel profiling */ 232: HFI_MEMKIND_PROFILE, 233: /** @HFI_MEMKIND_USER_PROFILING_IBS: Used for user profiling */ 234: HFI_MEMKIND_USER_PROFILE_IBS, 235: /** @MEMKIND_CMD_BUFFER: Used for composing ringbuffer content */ 236: HFI_MEMKIND_CMD_BUFFER, 237: /** 238: * @HFI_MEMKIND_GPU_BUSY_DATA_BUFFER: Used for GPU busy buffer for 239: * all the contexts 240: */ 241: HFI_MEMKIND_GPU_BUSY_DATA_BUFFER, 242: /** @HFI_MEMKIND_GPU_BUSY_CMD_BUFFER: Used for GPU busy cmd buffer 243: * (Only readable to GPU) 244: */ 245: HFI_MEMKIND_GPU_BUSY_CMD_BUFFER, 246: /** 247: *@MEMKIND_MMIO_IPC_CORE: Used for IPC_core region mapping to GMU space 248: * for EVA to GPU communication. 249: */ 250: HFI_MEMKIND_MMIO_IPC_CORE, 251: /** @HFIMEMKIND_MMIO_IPCC_AOSS: Used for IPCC AOSS, second memory region */ 252: HFI_MEMKIND_MMIO_IPCC_AOSS, 253: /** 254: * @MEMKIND_CSW_LPAC_PRIV_NON_SECURE: Used for privileged nonsecure 255: * memory for LPAC context record 256: */ 257: HFI_MEMKIND_CSW_LPAC_PRIV_NON_SECURE, 258: /** @HFI_MEMKIND_MEMSTORE: Buffer used to query a context's GPU sop/eop timestamps */ 259: HFI_MEMKIND_MEMSTORE, --- FILE: \adreno_hwsched.c | HITS: 5 --- MATCH LINES: 26 14: #include "kgsl_pwrctrl.h" 15: #include "kgsl_timeline.h" 16: #include 17: #include 18: #include 19: 20: #define POLL_SLEEP_US 100 21: 22: /* 23: * Number of commands that can be queued in a context before it sleeps 24: * 25: * Our code that "puts back" a command from the context is much cleaner 26: * if we are sure that there will always be enough room in the ringbuffer 27: * so restrict the size of the context queue to ADRENO_CONTEXT_DRAWQUEUE_SIZE - 1 28: */ 29: static u32 _context_drawqueue_size = ADRENO_CONTEXT_DRAWQUEUE_SIZE - 1; 30: 31: /* Number of milliseconds to wait for the context queue to clear */ 32: static unsigned int _context_queue_wait = 10000; 33: 34: /* 35: * GFT throttle parameters. If GFT recovered more than 36: * X times in Y ms invalidate the context and do not attempt recovery. 37: * X -> _fault_throttle_burst 38: * Y -> _fault_throttle_time 39: */ 40: static unsigned int _fault_throttle_time = 2000; 41: static unsigned int _fault_throttle_burst = 3; 42: 43: /* Use a kmem cache to speed up allocations for dispatcher jobs */ 44: static struct kmem_cache *jobs_cache; 45: /* Use a kmem cache to speed up allocations for inflight command objects */ 46: static struct kmem_cache *obj_cache; 47: 48: inline bool adreno_hwsched_context_queue_enabled(struct adreno_device *adreno_dev) 49: { 50: return test_bit(ADRENO_HWSCHED_CONTEXT_QUEUE, &adreno_dev->hwsched.flags); MATCH LINES: 646 634: _kgsl_context_get(&drawctxt->base); 635: kref_get(&drawobj->refcount); 636: 637: kgsl_sharedmem_bind_ranges(bindobj->bind); 638: } 639: 640: return -EAGAIN; 641: } 642: 643: /* 644: * Retires all expired marker and sync objs from the context 645: * queue and returns one of the below 646: * a) next drawobj that needs to be sent to ringbuffer 647: * b) -EAGAIN for syncobj with syncpoints pending. 648: * c) -EAGAIN for markerobj whose marker timestamp has not expired yet. 649: * c) NULL for no commands remaining in drawqueue. 650: */ 651: static struct kgsl_drawobj *_process_drawqueue_get_next_drawobj( 652: struct adreno_device *adreno_dev, struct adreno_context *drawctxt) 653: { 654: struct kgsl_drawobj *drawobj; 655: unsigned int i = drawctxt->drawqueue_head; 656: struct kgsl_drawobj_cmd *cmdobj; 657: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 658: int ret = 0; 659: 660: if (drawctxt->drawqueue_head == drawctxt->drawqueue_tail) 661: return NULL; 662: 663: for (i = drawctxt->drawqueue_head; i != drawctxt->drawqueue_tail; 664: i = DRAWQUEUE_NEXT(i, ADRENO_CONTEXT_DRAWQUEUE_SIZE)) { 665: 666: drawobj = drawctxt->drawqueue[i]; 667: 668: if (!drawobj) 669: return NULL; 670: MATCH LINES: 716, 741 704: return ERR_PTR(ret); 705: } 706: 707: return NULL; 708: } 709: 710: /** 711: * hwsched_dispatcher_requeue_drawobj() - Put a draw objet back on the context 712: * queue 713: * @drawctxt: Pointer to the adreno draw context 714: * @drawobj: Pointer to the KGSL draw object to requeue 715: * 716: * Failure to submit a drawobj to the ringbuffer isn't the fault of the drawobj 717: * being submitted so if a failure happens, push it back on the head of the 718: * context queue to be reconsidered again unless the context got detached. 719: */ 720: static inline int hwsched_dispatcher_requeue_drawobj( 721: struct adreno_context *drawctxt, 722: struct kgsl_drawobj *drawobj) 723: { 724: unsigned int prev; 725: 726: spin_lock(&drawctxt->lock); 727: 728: if (kgsl_context_is_bad(&drawctxt->base)) { 729: spin_unlock(&drawctxt->lock); 730: /* get rid of this drawobj since the context is bad */ 731: kgsl_drawobj_destroy(drawobj); 732: return -ENOENT; 733: } 734: 735: prev = drawctxt->drawqueue_head == 0 ? 736: (ADRENO_CONTEXT_DRAWQUEUE_SIZE - 1) : 737: (drawctxt->drawqueue_head - 1); 738: 739: /* 740: * The maximum queue size always needs to be one less then the size of 741: * the ringbuffer queue so there is "room" to put the drawobj back in 742: */ 743: 744: WARN_ON(prev == drawctxt->drawqueue_tail); 745: 746: drawctxt->drawqueue[prev] = drawobj; 747: drawctxt->queued++; 748: 749: /* Reset the command queue head to reflect the newly requeued change */ 750: drawctxt->drawqueue_head = prev; 751: if (is_cmdobj(drawobj)) { 752: struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj); 753: 754: cmdobj->requeue_cnt++; 755: } 756: spin_unlock(&drawctxt->lock); 757: return 0; 758: } 759: 760: /** 761: * hwsched_queue_context() - Queue a context in the dispatcher list of jobs 762: * @adreno_dev: Pointer to the adreno device structure 763: * @drawctxt: Pointer to the adreno draw context 764: * 765: * Add a context to the dispatcher list of jobs. MATCH LINES: 1976 1964: KGSL_TIMESTAMP_CONSUMED, &consumed); 1965: kgsl_readtimestamp(device, drawobj->context, 1966: KGSL_TIMESTAMP_RETIRED, &retired); 1967: 1968: if (!consumed) 1969: continue; 1970: 1971: if (consumed == retired) 1972: continue; 1973: 1974: /* 1975: * Find the first submission that started but didn't finish 1976: * We only care about one ringbuffer for LPAC so just look for the 1977: * first unfinished submission 1978: */ 1979: if (!active_obj) 1980: active_obj = obj; 1981: } 1982: 1983: if (active_obj) { 1984: drawobj = active_obj->drawobj; 1985: 1986: if (kref_get_unless_zero(&drawobj->refcount)) { 1987: struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj); 1988: 1989: set_bit(CMDOBJ_FAULT, &cmdobj->priv); 1990: return active_obj; 1991: } 1992: } 1993: 1994: return NULL; 1995: } 1996: 1997: static struct cmd_list_obj *get_active_cmdobj( 1998: struct adreno_device *adreno_dev) 1999: { 2000: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; --- FILE: \adreno_hwsched.h | HITS: 1 --- MATCH LINES: 196 184: /** @tunables_kobj: Kobj for dcvs tunables **/ 185: struct kobject tunables_kobj; 186: /** @dcvs_kobj: Kobj for dcvs params **/ 187: struct kobject dcvs_kobj; 188: /** @sysfs_dcvs_tunables : Tuning parameters for GMU based DCVS **/ 189: struct adreno_dcvs_tunable sysfs_dcvs_tunables[GPU_TUNING_KEY_MAX]; 190: /** @default_dcvs_tunables: Default value of GMU based DCVS tunables **/ 191: u32 default_dcvs_tunables[GPU_TUNING_KEY_MAX]; 192: }; 193: 194: /* 195: * This value is based on maximum number of IBs that can fit 196: * in the ringbuffer. 197: */ 198: #define HWSCHED_MAX_IBS 2000 199: 200: enum adreno_hwsched_flags { 201: ADRENO_HWSCHED_POWER = 0, 202: ADRENO_HWSCHED_ACTIVE, 203: ADRENO_HWSCHED_CTX_BAD_LEGACY, 204: ADRENO_HWSCHED_CONTEXT_QUEUE, 205: ADRENO_HWSCHED_HW_FENCE, 206: ADRENO_HWSCHED_FORCE_RETIRE_GMU, 207: ADRENO_HWSCHED_GPU_SOFT_RESET, 208: }; 209: 210: /** 211: * adreno_hwsched_process_mem_alloc - Process memory allocation for hwsched 212: * @adreno_dev: Pointer to the adreno device 213: * @mad: Pointer to the HFI memory allocation descriptor 214: * 215: * This function processes the memory allocation request for the hwsched. 216: * It retrieves or allocates the necessary memory based on the provided 217: * descriptor and updates the descriptor with the allocated memory addresses. 218: * 219: * Return: 0 on success, or a negative error code on failure. 220: */ --- FILE: \adreno_ioctl.c | HITS: 1 --- MATCH LINES: 169 157: 158: if (!adreno_is_a5xx(adreno_dev) || 159: !adreno_is_preemption_enabled(adreno_dev)) 160: return -EOPNOTSUPP; 161: 162: if (read->size_user < size_level) 163: return -EINVAL; 164: 165: /* Calculate number of preemption counter levels to copy to userspace */ 166: levels_to_copy = (read->size_user / size_level); 167: 168: levels_to_copy = min_t(int, levels_to_copy, 169: ARRAY_SIZE(adreno_dev->ringbuffers)); 170: 171: if (copy_to_user(u64_to_user_ptr(read->counters), 172: adreno_dev->preempt.scratch->hostptr, 173: levels_to_copy * size_level)) 174: return -EFAULT; 175: 176: read->max_priority_level = levels_to_copy; 177: read->size_priority_level = size_level; 178: 179: return 0; 180: } 181: 182: static long adreno_ioctl_read_calibrated_ts(struct kgsl_device_private *dev_priv, 183: unsigned int cmd, void *data) 184: { 185: struct adreno_device *adreno_dev = ADRENO_DEVICE(dev_priv->device); 186: struct kgsl_read_calibrated_timestamps *reads = data; 187: unsigned long flags; 188: u32 *sources = NULL; 189: u64 *ts = NULL; 190: u64 start; 191: u64 samples[KGSL_CALIBRATED_TIME_DOMAIN_MAX] = {0}; 192: u32 i; 193: int ret = 0; --- FILE: \adreno_pm4types.h | HITS: 9 --- MATCH LINES: 27, 33, 69, 78, 92, 118, 132 15: 16: /* Enable preemption flag */ 17: #define CP_PREEMPT_ENABLE 0x1C 18: /* Preemption token command on which preemption occurs */ 19: #define CP_PREEMPT_TOKEN 0x1E 20: /* Bit to set in CP_PREEMPT_TOKEN ordinal for interrupt on preemption */ 21: #define CP_PREEMPT_ORDINAL_INTERRUPT 24 22: 23: /* Wait for memory writes to complete */ 24: #define CP_WAIT_MEM_WRITES 0x12 25: 26: /* initialize CP's micro-engine */ 27: #define CP_ME_INIT 0x48 28: 29: /* skip N 32-bit words to get to the next packet */ 30: #define CP_NOP 0x10 31: 32: /* indirect buffer dispatch. same as IB, but init is pipelined */ 33: #define CP_INDIRECT_BUFFER_PFD 0x37 34: 35: /* wait for the IDLE state of the engine */ 36: #define CP_WAIT_FOR_IDLE 0x26 37: 38: /* wait until a register or memory location is a specific value */ 39: #define CP_WAIT_REG_MEM 0x3c 40: 41: /* wait until a register location is equal to a specific value */ 42: #define CP_WAIT_REG_EQ 0x52 43: 44: /* switches SMMU pagetable, used on a5xx only */ 45: #define CP_SMMU_TABLE_UPDATE 0x53 46: 47: /* Designate command streams to be executed before/after CP does state restore during preemption */ 48: #define CP_SET_AMBLE 0x55 49: 50: /* Set internal CP registers, used to indicate context save data addresses */ 51: #define CP_SET_PSEUDO_REGISTER 0x56 52: 53: /* Tell CP the current operation mode, indicates save and restore procedure */ 54: #define CP_SET_MARKER 0x65 55: 56: /* register read/modify/write */ 57: #define CP_REG_RMW 0x21 58: 59: /* Set binning configuration registers */ 60: #define CP_SET_BIN_DATA 0x2f 61: 62: /* reads register in chip and writes to memory */ 63: #define CP_REG_TO_MEM 0x3e 64: 65: /* reads memory and writes to register in chip */ 66: #define CP_MEM_TO_REG 0x42 67: 68: /* write N 32-bit words to memory */ 69: #define CP_MEM_WRITE 0x3d 70: 71: /* conditional execution of a sequence of packets */ 72: #define CP_COND_EXEC 0x44 73: 74: /* conditional write to memory or register */ 75: #define CP_COND_WRITE 0x45 76: 77: /* generate an event that creates a write to memory when completed */ 78: #define CP_EVENT_WRITE 0x46 79: 80: /* A5XX Enable yield in RB only */ 81: #define CP_YIELD_ENABLE 0x1C 82: 83: #define CP_WHERE_AM_I 0x62 84: 85: /* Enable/Disable/Defer A5x global preemption model */ 86: #define CP_PREEMPT_ENABLE_GLOBAL 0x69 87: 88: /* Enable/Disable A5x local preemption model */ 89: #define CP_PREEMPT_ENABLE_LOCAL 0x6A 90: 91: /* Yeild token on a5xx similar to CP_PREEMPT on a4xx */ 92: #define CP_CONTEXT_SWITCH_YIELD 0x6B 93: 94: /* Inform CP about current render mode (needed for a5xx preemption) */ 95: #define CP_SET_RENDER_MODE 0x6C 96: 97: /* PFP waits until the FIFO between the PFP and the ME is empty */ 98: #define CP_WAIT_FOR_ME 0x13 99: 100: /* Stall the SQE until the CP processing pipeline is empty */ 101: #define CP_WAIT_FOR_CP_FLUSH 0x13 102: 103: #define CP_POWER_CONTROL 0x5b /* Control mALU power */ 104: #define CP_SET_PROTECTED_MODE 0x5f /* sets the register protection mode */ 105: 106: /* Used to switch GPU between secure and non-secure modes */ 107: #define CP_SET_SECURE_MODE 0x66 108: 109: #define CP_BOOTSTRAP_UCODE 0x6f /* bootstraps microcode */ 110: 111: #define CP_LOAD_STATE 0x30 /* load high level sequencer command */ 112: 113: /* Conditionally load a IB based on a flag */ 114: #define CP_COND_INDIRECT_BUFFER_PFE 0x3A /* prefetch enabled */ 115: #define CP_COND_INDIRECT_BUFFER_PFD 0x32 /* prefetch disabled */ 116: 117: /* Load a buffer with pre-fetch enabled */ 118: #define CP_INDIRECT_BUFFER_PFE 0x3F 119: 120: #define CP_EXEC_CL 0x31 121: 122: /* (A4x) save PM4 stream pointers to execute upon a visible draw */ 123: #define CP_SET_DRAW_STATE 0x43 124: 125: #define CP_LOADSTATE_DSTOFFSET_SHIFT 0x00000000 126: #define CP_LOADSTATE_STATESRC_SHIFT 0x00000010 127: #define CP_LOADSTATE_STATEBLOCKID_SHIFT 0x00000013 128: #define CP_LOADSTATE_NUMOFUNITS_SHIFT 0x00000016 129: #define CP_LOADSTATE_STATETYPE_SHIFT 0x00000000 130: #define CP_LOADSTATE_EXTSRCADDR_SHIFT 0x00000002 131: 132: /* This is a commonly used CP_EVENT_WRITE */ 133: #define CACHE_FLUSH_TS 4 134: #define CACHE_CLEAN 0x31 135: #define LRZ_CACHE_FLUSH 0x26 136: 137: /* Controls which threads execute the PM4 commands the follow this packet */ 138: #define CP_THREAD_CONTROL 0x17 139: 140: #define CP_WAIT_TIMESTAMP 0x14 141: 142: #define CP_SET_THREAD_BR FIELD_PREP(GENMASK(1, 0), 1) 143: #define CP_SET_THREAD_BV FIELD_PREP(GENMASK(1, 0), 2) 144: #define CP_SET_THREAD_BOTH FIELD_PREP(GENMASK(1, 0), 3) 145: #define CP_SYNC_THREADS BIT(31) 146: #define CP_CONCURRENT_BIN_DISABLE BIT(27) 147: 148: #define CP_RESET_CONTEXT_STATE 0x1F 149: 150: #define CP_RESET_GLOBAL_LOCAL_TS BIT(3) 151: #define CP_CLEAR_BV_BR_COUNTER BIT(2) 152: #define CP_CLEAR_RESOURCE_TABLE BIT(1) 153: #define CP_CLEAR_ON_CHIP_TS BIT(0) 154: 155: /* Used to define amble type in SET_AMBLE packet to execute during preemption */ 156: #define CP_KMD_AMBLE_TYPE 3 MATCH LINES: 242, 244 230: */ 231: static inline uint cp_mem_packet(struct adreno_device *adreno_dev, 232: int opcode, uint size, uint num_mem) 233: { 234: return cp_type7_packet(opcode, size + num_mem); 235: } 236: 237: /* Return 1 if the command is an indirect buffer of any kind */ 238: static inline int adreno_cmd_is_ib(struct adreno_device *adreno_dev, 239: unsigned int cmd) 240: { 241: return cmd == cp_mem_packet(adreno_dev, 242: CP_INDIRECT_BUFFER_PFE, 2, 1) || 243: cmd == cp_mem_packet(adreno_dev, 244: CP_INDIRECT_BUFFER_PFD, 2, 1) || 245: cmd == cp_mem_packet(adreno_dev, 246: CP_COND_INDIRECT_BUFFER_PFE, 2, 1) || 247: cmd == cp_mem_packet(adreno_dev, 248: CP_COND_INDIRECT_BUFFER_PFD, 2, 1); 249: } 250: 251: /** 252: * cp_gpuaddr - Generic function to add 64bit and 32bit gpuaddr 253: * to pm4 commands 254: * @adreno_dev: The adreno device 255: * @cmds: command pointer to add gpuaddr 256: * @gpuaddr: gpuaddr to add 257: */ 258: static inline uint cp_gpuaddr(struct adreno_device *adreno_dev, 259: uint *cmds, uint64_t gpuaddr) 260: { 261: uint *start = cmds; 262: 263: *cmds++ = lower_32_bits(gpuaddr); 264: *cmds++ = upper_32_bits(gpuaddr); 265: 266: return cmds - start; 267: } 268: --- FILE: \adreno_profile.c | HITS: 5 --- MATCH LINES: 16 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include 8: #include 9: #include 10: #include 11: 12: #include "adreno.h" 13: #include "adreno_hwsched.h" 14: #include "adreno_profile.h" 15: #include "adreno_pm4types.h" 16: #include "adreno_ringbuffer.h" 17: 18: #define ASSIGNS_STR_FORMAT "%.8s:%u " 19: 20: /* 21: * Raw Data for processing later: 22: * : 3 - timestamp, count, context id 23: * [per counter] - data for each counter 24: * : 1 - Register offset 25: * : 2 - Pre IB register hi/lo value 26: * : 2 - Post IB register hi/lo value 27: * [per counter end] 28: */ 29: #define SIZE_DATA(cnt) (6 + (cnt) * 5) 30: 31: /* 32: * Pre-IB command size (in dwords): 33: * : 2 - NOP start identifier 34: * : 4 - timestamp 35: * : 4 - count 36: * : 4 - context id 37: * : 4 - pid 38: * : 4 - tid 39: * : 4 - type 40: * [loop count start] - for each counter to watch MATCH LINES: 76 64: /* 65: * Space for following string :"%u %u %u %.5s %u " 66: * [count iterations]: "%.8s:%u %llu %llu%c" 67: */ 68: #define SIZE_PIPE_ENTRY(cnt) (50 + (cnt) * 62) 69: #define SIZE_LOG_ENTRY(cnt) (6 + (cnt) * 5) 70: 71: static inline uint _ib_cmd_mem_write(struct adreno_device *adreno_dev, 72: uint *cmds, uint64_t gpuaddr, uint val, uint *off) 73: { 74: unsigned int *start = cmds; 75: 76: *cmds++ = cp_mem_packet(adreno_dev, CP_MEM_WRITE, 2, 1); 77: cmds += cp_gpuaddr(adreno_dev, cmds, gpuaddr); 78: *cmds++ = val; 79: 80: *off += sizeof(unsigned int); 81: return cmds - start; 82: } 83: 84: static inline uint _ib_cmd_reg_to_mem(struct adreno_device *adreno_dev, 85: uint *cmds, uint64_t gpuaddr, uint val, uint *off) 86: { 87: unsigned int *start = cmds; 88: 89: *cmds++ = cp_mem_packet(adreno_dev, CP_REG_TO_MEM, 2, 1); 90: *cmds++ = val; 91: cmds += cp_gpuaddr(adreno_dev, cmds, gpuaddr); 92: 93: *off += sizeof(unsigned int); 94: return cmds - start; 95: } 96: 97: static u64 _build_pre_ib_cmds(struct adreno_device *adreno_dev, 98: struct adreno_profile *profile, 99: unsigned int head, unsigned int timestamp, 100: struct adreno_context *drawctxt, MATCH LINES: 116 104: unsigned int *start, *ibcmds; 105: unsigned int count = profile->assignment_count; 106: uint64_t gpuaddr = profile->shared_buffer->gpuaddr; 107: unsigned int ib_offset = head + SIZE_DATA(count); 108: unsigned int data_offset = head * sizeof(unsigned int); 109: 110: ibcmds = ib_offset + ((unsigned int *) profile->shared_buffer->hostptr); 111: start = ibcmds; 112: 113: ibcmds += cp_identifier(adreno_dev, ibcmds, START_PROFILE_IDENTIFIER); 114: 115: /* 116: * Write ringbuffer commands to save the following to memory: 117: * timestamp, count, context_id, pid, tid, context type 118: */ 119: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 120: timestamp, &data_offset); 121: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 122: profile->assignment_count, &data_offset); 123: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 124: drawctxt->base.id, &data_offset); 125: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 126: pid_nr(drawctxt->base.proc_priv->pid), &data_offset); 127: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 128: drawctxt->base.tid, &data_offset); 129: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 130: drawctxt->type, &data_offset); 131: 132: /* loop for each countable assigned */ 133: list_for_each_entry(entry, &profile->assignments_list, list) { 134: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, 135: gpuaddr + data_offset, entry->offset, 136: &data_offset); 137: ibcmds += _ib_cmd_reg_to_mem(adreno_dev, ibcmds, 138: gpuaddr + data_offset, entry->offset, 139: &data_offset); 140: ibcmds += _ib_cmd_reg_to_mem(adreno_dev, ibcmds, MATCH LINES: 1094, 1105 1082: transfer_results(profile, shared_buf_tail); 1083: 1084: return 1; 1085: } 1086: 1087: u64 adreno_profile_preib_processing(struct adreno_device *adreno_dev, 1088: struct adreno_context *drawctxt, u32 *dwords) 1089: { 1090: struct adreno_profile *profile = &adreno_dev->profile; 1091: int count = profile->assignment_count; 1092: unsigned int entry_head = profile->shared_head; 1093: unsigned int *shared_ptr; 1094: struct adreno_ringbuffer *rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 1095: 1096: if (adreno_dev->hwsched_enabled) 1097: return 0; 1098: 1099: if (!drawctxt || !adreno_profile_assignments_ready(profile)) 1100: return 0; 1101: 1102: /* 1103: * check if space available, include the post_ib in space available 1104: * check so don't have to handle trying to undo the pre_ib insertion in 1105: * ringbuffer in the case where only the post_ib fails enough space 1106: */ 1107: if (SIZE_SHARED_ENTRY(count) >= shared_buf_available(profile)) 1108: return 0; 1109: 1110: if (entry_head + SIZE_SHARED_ENTRY(count) >= profile->shared_size) { 1111: /* entry_head would wrap, start entry_head at 0 in buffer */ 1112: entry_head = 0; 1113: profile->shared_size = profile->shared_head; 1114: profile->shared_head = 0; 1115: 1116: /* recheck space available */ 1117: if (SIZE_SHARED_ENTRY(count) >= shared_buf_available(profile)) 1118: return 0; 1119: } 1120: 1121: /* zero out the counter area of shared_buffer entry_head */ 1122: shared_ptr = entry_head + ((unsigned int *) 1123: profile->shared_buffer->hostptr); 1124: memset(shared_ptr, 0, SIZE_SHARED_ENTRY(count) * sizeof(unsigned int)); 1125: 1126: /* reserve space for the pre ib shared buffer */ 1127: shared_buf_inc(profile->shared_size, &profile->shared_head, 1128: SIZE_SHARED_ENTRY(count)); 1129: --- FILE: \adreno_ringbuffer.c | HITS: 28 --- MATCH LINES: 14, 28, 66, 83, 84, 105, 107, 110, 122, 123, 137 2: /* 3: * Copyright (c) 2002,2007-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include 8: #include 9: #include 10: #include 11: 12: #include "adreno.h" 13: #include "adreno_pm4types.h" 14: #include "adreno_ringbuffer.h" 15: #include "adreno_trace.h" 16: #include "kgsl_trace.h" 17: #include "kgsl_util.h" 18: 19: 20: #define RB_HOSTPTR(_rb, _pos) \ 21: ((unsigned int *) ((_rb)->buffer_desc->hostptr + \ 22: ((_pos) * sizeof(unsigned int)))) 23: 24: #define RB_GPUADDR(_rb, _pos) \ 25: ((_rb)->buffer_desc->gpuaddr + ((_pos) * sizeof(unsigned int))) 26: 27: void adreno_get_submit_time(struct adreno_device *adreno_dev, 28: struct adreno_ringbuffer *rb, 29: struct adreno_submit_time *time) 30: { 31: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 32: unsigned long flags; 33: struct adreno_context *drawctxt = rb->drawctxt_active; 34: struct kgsl_context *context = &drawctxt->base; 35: 36: if (!time) 37: return; 38: 39: /* 40: * Here we are attempting to create a mapping between the 41: * GPU time domain (alwayson counter) and the CPU time domain 42: * (local_clock) by sampling both values as close together as 43: * possible. This is useful for many types of debugging and 44: * profiling. In order to make this mapping as accurate as 45: * possible, we must turn off interrupts to avoid running 46: * interrupt handlers between the two samples. 47: */ 48: 49: local_irq_save(flags); 50: 51: time->ticks = gpudev->read_alwayson(adreno_dev); 52: 53: /* Trace the GPU time to create a mapping to ftrace time */ 54: trace_adreno_cmdbatch_sync(context->id, context->priority, 55: drawctxt->timestamp, time->ticks); 56: 57: /* Get the kernel clock for time since boot */ 58: time->ktime = local_clock(); 59: 60: /* Get the timeofday for the wall time (for the user) */ 61: ktime_get_real_ts64(&time->utime); 62: 63: local_irq_restore(flags); 64: } 65: 66: unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb, 67: unsigned int dwords) 68: { 69: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 70: unsigned int rptr = adreno_get_rptr(rb); 71: unsigned int ret; 72: 73: if (rptr <= rb->_wptr) { 74: unsigned int *cmds; 75: 76: if (rb->_wptr + dwords <= (KGSL_RB_DWORDS - 2)) { 77: ret = rb->_wptr; 78: rb->_wptr = (rb->_wptr + dwords) % KGSL_RB_DWORDS; 79: return RB_HOSTPTR(rb, ret); 80: } 81: 82: /* 83: * There isn't enough space toward the end of ringbuffer. So 84: * look for space from the beginning of ringbuffer upto the 85: * read pointer. 86: */ 87: if (dwords < rptr) { 88: cmds = RB_HOSTPTR(rb, rb->_wptr); 89: *cmds = cp_packet(adreno_dev, CP_NOP, 90: KGSL_RB_DWORDS - rb->_wptr - 1); 91: rb->_wptr = dwords; 92: return RB_HOSTPTR(rb, 0); 93: } 94: } 95: 96: if (rb->_wptr + dwords < rptr) { 97: ret = rb->_wptr; 98: rb->_wptr = (rb->_wptr + dwords) % KGSL_RB_DWORDS; 99: return RB_HOSTPTR(rb, ret); 100: } 101: 102: return ERR_PTR(-ENOSPC); 103: } 104: 105: void adreno_ringbuffer_stop(struct adreno_device *adreno_dev) 106: { 107: struct adreno_ringbuffer *rb; 108: int i; 109: 110: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) 111: kgsl_cancel_events(KGSL_DEVICE(adreno_dev), &(rb->events)); 112: } 113: 114: static int _rb_readtimestamp(struct kgsl_device *device, 115: void *priv, enum kgsl_timestamp_type type, 116: unsigned int *timestamp) 117: { 118: return adreno_rb_readtimestamp(ADRENO_DEVICE(device), priv, type, 119: timestamp); 120: } 121: 122: int adreno_ringbuffer_setup(struct adreno_device *adreno_dev, 123: struct adreno_ringbuffer *rb, int id) 124: { 125: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 126: unsigned int priv = 0; 127: int ret; 128: 129: /* allocate a chunk of memory to create user profiling IB1s */ 130: adreno_allocate_global(device, &rb->profile_desc, PAGE_SIZE, 131: 0, KGSL_MEMFLAGS_GPUREADONLY, 0, "profile_desc"); 132: 133: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 134: priv |= KGSL_MEMDESC_PRIVILEGED; 135: 136: ret = adreno_allocate_global(device, &rb->buffer_desc, KGSL_RB_SIZE, 137: SZ_4K, KGSL_MEMFLAGS_GPUREADONLY, priv, "ringbuffer"); 138: if (ret) 139: return ret; 140: 141: if (!list_empty(&rb->events.group)) 142: return 0; 143: 144: rb->id = id; 145: kgsl_add_event_group(device, &rb->events, NULL, _rb_readtimestamp, rb, 146: "rb_events-%d", id); 147: 148: rb->timestamp = 0; 149: init_waitqueue_head(&rb->ts_expire_waitq); 150: 151: spin_lock_init(&rb->preempt_lock); 152: 153: return 0; 154: } 155: 156: void adreno_preemption_timer(struct timer_list *t) 157: { 158: struct adreno_preemption *preempt = kgsl_timer_container_of(preempt, t, timer); 159: struct adreno_device *adreno_dev = container_of(preempt, 160: struct adreno_device, preempt); 161: MATCH LINES: 241, 248, 285 229: device->cur_l3_pwrlevel = new_l3; 230: } else { 231: dev_err_ratelimited(device->dev, 232: "Could not set l3_vote: %d\n", 233: ret); 234: } 235: break; 236: } 237: } 238: } 239: } 240: 241: int adreno_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 242: struct kgsl_drawobj_cmd *cmdobj, 243: struct adreno_submit_time *time) 244: { 245: struct adreno_submit_time local = { 0 }; 246: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 247: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 248: struct adreno_ringbuffer *rb = drawctxt->rb; 249: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 250: u32 flags = 0; 251: int ret; 252: 253: /* 254: * If SKIP CMD flag is set for current context 255: * a) set SKIPCMD as fault_recovery for current commandbatch 256: * b) store context's commandbatch fault_policy in current 257: * commandbatch fault_policy and clear context's commandbatch 258: * fault_policy 259: * c) force preamble for commandbatch 260: */ 261: if (test_bit(ADRENO_CONTEXT_SKIP_CMD, &drawctxt->base.priv) && 262: (!test_bit(CMDOBJ_SKIP, &cmdobj->priv))) { 263: 264: set_bit(KGSL_FT_SKIPCMD, &cmdobj->fault_recovery); 265: cmdobj->fault_policy = drawctxt->fault_policy; 266: set_bit(CMDOBJ_FORCE_PREAMBLE, &cmdobj->priv); 267: 268: /* if context is detached print fault recovery */ 269: adreno_fault_skipcmd_detached(adreno_dev, drawctxt, drawobj); 270: 271: /* clear the drawctxt flags */ 272: clear_bit(ADRENO_CONTEXT_SKIP_CMD, &drawctxt->base.priv); 273: drawctxt->fault_policy = 0; 274: } 275: 276: /* Check if user profiling should be enabled */ 277: 278: if ((drawobj->flags & KGSL_DRAWOBJ_PROFILING) && 279: cmdobj->profiling_buf_entry) { 280: flags |= F_USER_PROFILE; 281: 282: /* 283: * we want to use an adreno_submit_time struct to get the 284: * precise moment when the command is submitted to the 285: * ringbuffer. If an upstream caller already passed down a 286: * pointer piggyback on that otherwise use a local struct 287: */ 288: if (!time) 289: time = &local; 290: 291: time->drawobj = drawobj; 292: } 293: 294: flags |= F_PREAMBLE; 295: 296: /* 297: * When preamble is enabled, the preamble buffer with state restoration 298: * commands are stored in the first node of the IB chain. 299: * We can skip that if a context switch hasn't occurred. 300: */ 301: if ((drawctxt->base.flags & KGSL_CONTEXT_PREAMBLE) && 302: !test_bit(CMDOBJ_FORCE_PREAMBLE, &cmdobj->priv) && 303: (rb->drawctxt_active == drawctxt)) 304: flags &= ~F_PREAMBLE; 305: 306: /* 307: * In skip mode don't issue the draw IBs but keep all the other 308: * accoutrements of a submision (including the interrupt) to keep 309: * the accounting sane. Set start_index and numibs to 0 to just MATCH LINES: 340, 352, 353, 359, 363, 369, 370, 382, 383, 387, 398, 402, 411, 420 328: */ 329: if (test_and_clear_bit(ADRENO_DEVICE_PWRON, &adreno_dev->priv) && 330: test_bit(ADRENO_DEVICE_PWRON_FIXUP, &adreno_dev->priv)) 331: flags |= F_PWRON_FIXUP; 332: 333: /* Check to see the submission should be secure */ 334: if (drawobj->context->flags & KGSL_CONTEXT_SECURE) 335: flags |= F_SECURE; 336: 337: /* process any profiling results that are available into the log_buf */ 338: adreno_profile_process_results(adreno_dev); 339: 340: ret = gpudev->ringbuffer_submitcmd(adreno_dev, cmdobj, 341: flags, time); 342: 343: if (!ret) { 344: set_bit(KGSL_CONTEXT_PRIV_SUBMITTED, &drawobj->context->priv); 345: cmdobj->global_ts = drawctxt->internal_timestamp; 346: } 347: 348: return ret; 349: } 350: 351: /** 352: * adreno_ringbuffer_wait_callback() - Callback function for event registered 353: * on a ringbuffer timestamp 354: * @device: Device for which the callback is valid 355: * @context: The context of the event 356: * @priv: The private parameter of the event 357: * @result: Result of the event trigger 358: */ 359: static void adreno_ringbuffer_wait_callback(struct kgsl_device *device, 360: struct kgsl_event_group *group, 361: void *priv, int result) 362: { 363: struct adreno_ringbuffer *rb = group->priv; 364: 365: wake_up_all(&rb->ts_expire_waitq); 366: } 367: 368: /* check if timestamp is greater than the current rb timestamp */ 369: static inline int adreno_ringbuffer_check_timestamp( 370: struct adreno_ringbuffer *rb, 371: unsigned int timestamp, int type) 372: { 373: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 374: unsigned int ts; 375: 376: adreno_rb_readtimestamp(adreno_dev, rb, type, &ts); 377: return (timestamp_cmp(ts, timestamp) >= 0); 378: } 379: 380: 381: /** 382: * adreno_ringbuffer_waittimestamp() - Wait for a RB timestamp 383: * @rb: The ringbuffer to wait on 384: * @timestamp: The timestamp to wait for 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 | HITS: 33 --- MATCH LINES: 6, 7, 9, 11, 12, 17, 21 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2002,2007-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: #ifndef __ADRENO_RINGBUFFER_H 7: #define __ADRENO_RINGBUFFER_H 8: 9: /* Given a ringbuffer, return the adreno device that owns it */ 10: 11: #define _RB_OFFSET(_id) (offsetof(struct adreno_device, ringbuffers) + \ 12: ((_id) * sizeof(struct adreno_ringbuffer))) 13: 14: #define ADRENO_RB_DEVICE(_rb) \ 15: ((struct adreno_device *) (((void *) (_rb)) - _RB_OFFSET((_rb)->id))) 16: 17: /* Adreno ringbuffer size in bytes */ 18: #define KGSL_RB_SIZE (32 * 1024) 19: 20: /* 21: * A handy macro to convert the RB size to dwords since most ringbuffer 22: * operations happen in dword increments 23: */ 24: #define KGSL_RB_DWORDS (KGSL_RB_SIZE >> 2) 25: 26: /* Specifies that the command should be run in protected mode */ 27: #define F_NOTPROTECTED BIT(0) 28: /* Indicates that the CP should wait for idle after executing the command */ 29: #define F_WFI BIT(1) 30: /* Indicates that the poweron fixup should be executed before the command */ 31: #define F_PWRON_FIXUP BIT(2) 32: /* Indicates that the submission should be secure */ 33: #define F_SECURE BIT(3) 34: /* Indicates that the IBs in the submission should be skipped */ 35: #define F_SKIP BIT(4) 36: /* Indicates that user always on timer profiling is enabled */ 37: #define F_USER_PROFILE BIT(5) 38: /* Indicates that kernel always on timer profiling is enabled */ 39: #define F_KERNEL_PROFILE BIT(6) 40: /* Indicates that the submission has a preamble */ 41: #define F_PREAMBLE BIT(7) 42: /* Indicates that the submission has mALU workload */ 43: #define F_MALU BIT(8) 44: 45: #define IS_NOTPROTECTED(flags) ((flags) & F_NOTPROTECTED) MATCH LINES: 64, 65, 66, 70, 71, 76, 84, 95, 124, 130, 131, 134, 136, 137, 139, 142, 143, 145, 150, 152, 155, 163, 172, 179, 186, 189 52: #define IS_PREAMBLE(flags) ((flags) & F_PREAMBLE) 53: 54: struct kgsl_device; 55: struct kgsl_device_private; 56: 57: /** 58: * This is to keep track whether the SET_PSEUDO_REGISTER packet needs to be submitted 59: * or not 60: */ 61: #define ADRENO_RB_SET_PSEUDO_DONE 0 62: 63: /** 64: * struct adreno_ringbuffer - Definition for an adreno ringbuffer object 65: * @flags: Internal control flags for the ringbuffer 66: * @buffer_desc: Pointer to the ringbuffer memory descriptor 67: * @_wptr: The next value of wptr to be written to the hardware on submit 68: * @wptr: Local copy of the wptr offset last written to hardware 69: * @last_wptr: offset of the last wptr that was written to CFF 70: * @rb_ctx: The context that represents a ringbuffer 71: * @id: Priority level of the ringbuffer, also used as an ID 72: * @fault_detect_ts: The last retired global timestamp read during fault detect 73: * @timestamp: The RB's global timestamp 74: * @events: A kgsl_event_group for this context - contains the list of GPU 75: * events 76: * @drawctxt_active: The last pagetable that this ringbuffer is set to 77: * @preemption_desc: The memory descriptor containing 78: * preemption info written/read by CP 79: * @secure_preemption_desc: The memory descriptor containing 80: * preemption info written/read by CP for secure contexts 81: * @perfcounter_save_restore_desc: Used by CP to save/restore the perfcounter 82: * values across preemption 83: * and the commands to switch pagetable on the RB 84: * @dispatch_q: The dispatcher side queue for this ringbuffer 85: * @ts_expire_waitq: Wait queue to wait for rb timestamp to expire 86: * @ts_expire_waitq: Wait q to wait for rb timestamp to expire 87: * @wptr_preempt_end: Used during preemption to check that preemption occurred 88: * at the right rptr 89: * @gpr11: The gpr11 value of this RB 90: * @preempted_midway: Indicates that the RB was preempted before rptr = wptr 91: * @preempt_lock: Lock to protect the wptr pointer while it is being updated 92: * @skip_inline_wptr: Used during preemption to make sure wptr is updated in 93: * hardware 94: */ 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: */ 142: int adreno_ringbuffer_setup(struct adreno_device *adreno_dev, 143: struct adreno_ringbuffer *rb, int id); 144: 145: int adreno_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 146: struct kgsl_drawobj_cmd *cmdobj, 147: struct adreno_submit_time *time); 148: 149: 150: void adreno_ringbuffer_stop(struct adreno_device *adreno_dev); 151: 152: unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb, 153: unsigned int numcmds); 154: 155: int adreno_ringbuffer_waittimestamp(struct adreno_ringbuffer *rb, 156: unsigned int timestamp, 157: unsigned int msecs); 158: 159: int adreno_rb_readtimestamp(struct adreno_device *adreno_dev, 160: void *priv, enum kgsl_timestamp_type type, 161: unsigned int *timestamp); 162: 163: static inline int adreno_ringbuffer_count(struct adreno_ringbuffer *rb, 164: unsigned int rptr) 165: { 166: if (rb->wptr >= rptr) 167: return rb->wptr - rptr; 168: return rb->wptr + KGSL_RB_DWORDS - rptr; 169: } 170: 171: /* Increment a value by 4 bytes with wrap-around based on size */ 172: static inline unsigned int adreno_ringbuffer_inc_wrapped(unsigned int val, 173: unsigned int size) 174: { 175: return (val + sizeof(unsigned int)) % size; 176: } 177: 178: /* Decrement a value by 4 bytes with wrap-around based on size */ 179: static inline unsigned int adreno_ringbuffer_dec_wrapped(unsigned int val, 180: unsigned int size) 181: { 182: return (val + size - sizeof(unsigned int)) % size; 183: } 184: 185: void adreno_get_submit_time(struct adreno_device *adreno_dev, 186: struct adreno_ringbuffer *rb, 187: struct adreno_submit_time *time); 188: 189: #endif /* __ADRENO_RINGBUFFER_H */ --- FILE: \adreno_snapshot.c | HITS: 21 --- MATCH LINES: 23 11: #include "adreno_pm4types.h" 12: #include "adreno_snapshot.h" 13: 14: /* Maintain a list of the objects we see during parsing */ 15: 16: #define SNAPSHOT_OBJ_BUFSIZE 64 17: 18: /* Used to print error message if an IB has too many objects in it */ 19: static int ib_max_objs; 20: 21: struct snapshot_rb_params { 22: struct kgsl_snapshot *snapshot; 23: struct adreno_ringbuffer *rb; 24: }; 25: 26: /* Keep track of how many bytes are frozen after a snapshot and tell the user */ 27: static size_t snapshot_frozen_objsize; 28: 29: static struct kgsl_snapshot_object objbuf[SNAPSHOT_OBJ_BUFSIZE]; 30: 31: /* Pointer to the next open entry in the object list */ 32: static unsigned int objbufptr; 33: 34: static inline int adreno_rb_ctxtswitch(struct adreno_device *adreno_dev, 35: unsigned int *cmd) 36: { 37: return cmd[0] == cp_packet(adreno_dev, CP_NOP, 1) && 38: cmd[1] == CONTEXT_TO_MEM_IDENTIFIER; 39: } 40: 41: /* Push a new buffer object onto the list */ 42: void kgsl_snapshot_push_object(struct kgsl_device *device, 43: struct kgsl_process_private *process, 44: uint64_t gpuaddr, uint64_t dwords) 45: { 46: int index; 47: struct kgsl_mem_entry *entry; MATCH LINES: 213, 251 201: { 202: struct adreno_ib_object_list *ib_obj_list; 203: 204: /* 205: * Check the IB address - if it is either the last executed IB1 206: * then push it into the static blob otherwise put it in the dynamic 207: * list 208: */ 209: if (adreno_ib_addr_overlap(snapshot->ib1base, gpuaddr, dwords)) { 210: /* 211: * During restore after preemption, ib1base in the register 212: * can be updated by CP. In such scenarios, to dump complete 213: * IB1 in snapshot, we should consider ib1base from ringbuffer. 214: */ 215: snapshot->ib1base = gpuaddr; 216: snapshot->ib1size = dwords; 217: kgsl_snapshot_push_object(device, process, gpuaddr, dwords); 218: return; 219: } 220: 221: if (kgsl_snapshot_have_object(snapshot, process, 222: gpuaddr, dwords << 2)) 223: return; 224: 225: if (-E2BIG == adreno_ib_create_object_list(device, process, 226: gpuaddr, dwords, snapshot->ib2base, 227: &ib_obj_list)) 228: ib_max_objs = 1; 229: 230: if (ib_obj_list) 231: kgsl_snapshot_add_ib_obj_list(snapshot, ib_obj_list); 232: 233: } 234: 235: void adreno_parse_ib_lpac(struct kgsl_device *device, 236: struct kgsl_snapshot *snapshot, 237: struct kgsl_process_private *process, 238: u64 gpuaddr, u64 dwords) 239: { 240: struct adreno_ib_object_list *ib_obj_list; 241: 242: /* 243: * Check the IB address - if it is either the last executed IB1 244: * then push it into the static blob otherwise put it in the dynamic 245: * list 246: */ 247: if (adreno_ib_addr_overlap(snapshot->ib1base_lpac, gpuaddr, dwords)) { 248: /* 249: * During restore after preemption, ib1base in the register 250: * can be updated by CP. In such scenarios, to dump complete 251: * IB1 in snapshot, we should consider ib1base from ringbuffer. 252: */ 253: snapshot->ib1base_lpac = gpuaddr; 254: snapshot->ib1size_lpac = dwords; 255: kgsl_snapshot_push_object(device, process, gpuaddr, dwords); 256: return; 257: } 258: 259: if (kgsl_snapshot_have_object(snapshot, process, 260: gpuaddr, dwords << 2)) 261: return; 262: 263: if (-E2BIG == adreno_ib_create_object_list(device, process, 264: gpuaddr, dwords, snapshot->ib2base_lpac, 265: &ib_obj_list)) 266: ib_max_objs = 1; 267: 268: if (ib_obj_list) 269: kgsl_snapshot_add_ib_obj_list(snapshot, ib_obj_list); 270: 271: } 272: 273: void adreno_snapshot_dump_all_ibs(struct kgsl_device *device, 274: unsigned int *rbptr, struct kgsl_snapshot *snapshot) 275: { MATCH LINES: 315, 343, 376, 388 303: index = index + 1; 304: } 305: } 306: 307: /** 308: * snapshot_rb_ibs() - Dump rb data and capture the IB's in the RB as well 309: * @device: Pointer to a KGSL device 310: * @rb: The RB to dump 311: * @data: Pointer to memory where the RB data is to be dumped 312: * @snapshot: Pointer to information about the current snapshot being taken 313: */ 314: static void snapshot_rb_ibs(struct kgsl_device *device, 315: struct adreno_ringbuffer *rb, 316: struct kgsl_snapshot *snapshot) 317: { 318: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 319: unsigned int *rbptr, rptr = adreno_get_rptr(rb); 320: int index, i; 321: int parse_ibs = 0, ib_parse_start; 322: 323: /* 324: * During IB parse, vmalloc is called which can sleep and 325: * should not be called from atomic context. Since IBs are not 326: * dumped during atomic snapshot, there is no need to parse it. 327: */ 328: if (device->snapshot_atomic) 329: return; 330: 331: rbptr = rb->buffer_desc->hostptr; 332: /* 333: * KGSL tries to dump the active IB first. If it is not present, then 334: * only it dumps all the IBs. In few cases, non-active IBs may help to 335: * establish the flow and understand the hardware state better. 336: */ 337: if (device->dump_all_ibs) { 338: adreno_snapshot_dump_all_ibs(device, rbptr, snapshot); 339: return; 340: } 341: 342: /* 343: * Figure out the window of ringbuffer data to dump. First we need to 344: * find where the last processed IB ws submitted. Start walking back 345: * from the rptr 346: */ 347: index = rptr; 348: 349: do { 350: index--; 351: 352: if (index < 0) { 353: index = KGSL_RB_DWORDS - 4; 354: 355: /* We wrapped without finding what we wanted */ 356: if (index < rb->wptr) { 357: index = rb->wptr; 358: break; 359: } 360: } 361: 362: if (adreno_cmd_is_ib(adreno_dev, rbptr[index])) { 363: uint64_t ibaddr; 364: uint64_t ibsize; 365: 366: ibaddr = rbptr[index + 2]; 367: ibaddr = ibaddr << 32 | rbptr[index + 1]; 368: ibsize = rbptr[index + 3]; 369: 370: if (adreno_ib_addr_overlap(snapshot->ib1base, 371: ibaddr, ibsize)) { 372: /* 373: * During restore after preemption, ib1base in 374: * the register can be updated by CP. In such 375: * scenario, to dump complete IB1 in snapshot, 376: * we should consider ib1base from ringbuffer. 377: */ 378: snapshot->ib1base = ibaddr; 379: snapshot->ib1size = ibsize; 380: break; 381: } 382: } 383: } while (index != rb->wptr); 384: 385: /* 386: * If the ib1 was not found, for example, if ib1base was restored 387: * incorrectly after preemption, then simply dump the entire 388: * ringbuffer along with all the IBs in the ringbuffer. 389: */ 390: 391: if (index == rb->wptr) { 392: adreno_snapshot_dump_all_ibs(device, rb->buffer_desc->hostptr, snapshot); 393: return; 394: } 395: 396: /* 397: * index points at the last submitted IB. We can only trust that the 398: * memory between the context switch and the hanging IB is valid, so 399: * the next step is to find the context switch before the submission 400: */ 401: 402: while (index != rb->wptr) { 403: index--; 404: 405: if (index < 0) { 406: index = KGSL_RB_DWORDS - 2; 407: 408: /* 409: * Wrapped without finding the context switch. This is 410: * harmless - we should still have enough data to dump a 411: * valid state 412: */ MATCH LINES: 479, 488, 491, 518 467: if (kgsl_gpuaddr_in_memdesc(adreno_dev->pwron_fixup, 468: ibaddr, ibsize)) 469: continue; 470: 471: adreno_parse_ib(device, snapshot, snapshot->process, 472: ibaddr, ibsize); 473: } else 474: index = (index + 1) % KGSL_RB_DWORDS; 475: } 476: 477: } 478: 479: /* Snapshot the ringbuffer memory */ 480: static size_t snapshot_rb(struct kgsl_device *device, u8 *buf, 481: size_t remain, void *priv) 482: { 483: struct kgsl_snapshot_rb_v2 *header = (struct kgsl_snapshot_rb_v2 *)buf; 484: unsigned int *data = (unsigned int *)(buf + sizeof(*header)); 485: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 486: struct snapshot_rb_params *snap_rb_params = priv; 487: struct kgsl_snapshot *snapshot = snap_rb_params->snapshot; 488: struct adreno_ringbuffer *rb = snap_rb_params->rb; 489: 490: /* 491: * Dump the entire ringbuffer - the parser can choose how much of it to 492: * process 493: */ 494: 495: if (remain < KGSL_RB_SIZE + sizeof(*header)) { 496: dev_err(device->dev, 497: "snapshot: Not enough memory for the rb section\n"); 498: return 0; 499: } 500: 501: /* Write the sub-header for the section */ 502: header->start = 0; 503: header->end = KGSL_RB_DWORDS; 504: header->wptr = rb->wptr; 505: header->rptr = adreno_get_rptr(rb); 506: header->rbsize = KGSL_RB_DWORDS; 507: header->count = KGSL_RB_DWORDS; 508: adreno_rb_readtimestamp(adreno_dev, rb, KGSL_TIMESTAMP_QUEUED, 509: &header->timestamp_queued); 510: adreno_rb_readtimestamp(adreno_dev, rb, KGSL_TIMESTAMP_RETIRED, 511: &header->timestamp_retired); 512: header->gpuaddr = rb->buffer_desc->gpuaddr; 513: header->id = rb->id; 514: 515: if (rb == adreno_dev->cur_rb) 516: snapshot_rb_ibs(device, rb, snapshot); 517: 518: /* Just copy the ringbuffer, there are no active IBs */ 519: memcpy(data, rb->buffer_desc->hostptr, KGSL_RB_SIZE); 520: 521: /* Return the size of the section */ 522: return KGSL_RB_SIZE + sizeof(*header); 523: } 524: 525: static int _count_mem_entries(int id, void *ptr, void *data) 526: { 527: int *count = data; 528: *count = *count + 1; 529: return 0; 530: } 531: 532: struct mem_entry { 533: uint64_t gpuaddr; 534: uint64_t size; 535: unsigned int type; 536: } __packed; 537: 538: static size_t snapshot_capture_mem_list(struct kgsl_device *device, 539: u8 *buf, size_t remain, void *priv) 540: { 541: struct kgsl_snapshot_mem_list_v2 *header = 542: (struct kgsl_snapshot_mem_list_v2 *)buf; MATCH LINES: 919, 920 907: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 908: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 909: 910: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 911: snapshot, adreno_snapshot_global, iommu->setstate); 912: 913: if (adreno_is_preemption_enabled(adreno_dev)) 914: kgsl_snapshot_add_section(device, 915: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 916: snapshot, adreno_snapshot_global, iommu->smmu_info); 917: } 918: 919: static void adreno_snapshot_ringbuffer(struct kgsl_device *device, 920: struct kgsl_snapshot *snapshot, struct adreno_ringbuffer *rb) 921: { 922: struct snapshot_rb_params params = { 923: .snapshot = snapshot, 924: .rb = rb, 925: }; 926: 927: if (rb == NULL) 928: return; 929: 930: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_RB_V2, snapshot, 931: snapshot_rb, ¶ms); 932: } 933: 934: static void adreno_snapshot_os(struct kgsl_device *device, 935: struct kgsl_snapshot *snapshot, struct kgsl_context *guilty, 936: struct kgsl_context *guilty_lpac) 937: { 938: struct kgsl_snapshot_section_header *sect = 939: (struct kgsl_snapshot_section_header *) snapshot->ptr; 940: struct kgsl_snapshot_linux_v4 *header = (struct kgsl_snapshot_linux_v4 *) 941: (snapshot->ptr + sizeof(*sect)); 942: struct kgsl_context *context; 943: u32 remain; 944: void *mem; MATCH LINES: 1029, 1057 1017: } 1018: 1019: static void adreno_static_ib_dump(struct kgsl_device *device, 1020: struct kgsl_process_private *process, u64 ib1base, 1021: u32 ib1size, u64 ib2base, u32 ib2size, 1022: u64 ib3base, u32 ib3size) 1023: { 1024: if (process == NULL) 1025: return; 1026: 1027: /* Make sure that the last IB1 that was being executed is dumped. 1028: * Since this was the last IB1 that was processed, we should have 1029: * already added it to the list during the ringbuffer parse but we 1030: * want to be double plus sure. 1031: * The problem is that IB size from the register is the unprocessed size 1032: * of the buffer not the original size, so if we didn't catch this 1033: * buffer being directly used in the RB, then we might not be able to 1034: * dump the whole thing. Try to dump the maximum possible size from the 1035: * IB1 base address till the end of memdesc size so that we dont miss 1036: * what we are interested in. Print a warning message so we can try to 1037: * figure how often this really happens. 1038: */ 1039: 1040: if (ib1base && (-ENOENT == find_object(ib1base, process))) { 1041: struct kgsl_mem_entry *entry; 1042: u64 ibsize; 1043: 1044: entry = kgsl_sharedmem_find(process, ib1base); 1045: if (entry == NULL) { 1046: dev_err(device->dev, 1047: "Can't find a memory entry containing IB1BASE %16llx\n", 1048: ib1base); 1049: } else { 1050: ibsize = entry->memdesc.size - 1051: (ib1base - entry->memdesc.gpuaddr); 1052: kgsl_mem_entry_put(entry); 1053: 1054: kgsl_snapshot_push_object(device, process, 1055: ib1base, ibsize >> 2); 1056: dev_err(device->dev, 1057: "CP_IB1_BASE %16llx is not found in the ringbuffer. Dumping %llx dwords of the buffer\n", 1058: ib1base, ibsize >> 2); 1059: } 1060: } 1061: 1062: /* 1063: * Add the last parsed IB2 and IB3 to the list. These should be found as we 1064: * parse the objects below, but we try to add them to the list first, so 1065: * they too can be parsed. Don't print an error message in this case - if 1066: * the IB2 and IB3 are found during parsing, the list will be updated with 1067: * the correct size. 1068: */ 1069: if (ib2base && (-ENOENT == find_object(ib2base, process))) 1070: kgsl_snapshot_push_object(device, process, ib2base, ib2size); 1071: 1072: if (ib3base && (-ENOENT == find_object(ib3base, process))) 1073: kgsl_snapshot_push_object(device, process, ib3base, ib3size); 1074: } 1075: 1076: /** 1077: * adreno_snapshot_sqe - Dump the SQE firmware version and few dwords 1078: * @device: Pointer to the kgsl device 1079: * @buf: Pointer to the snapshot buffer 1080: * @remain: Remaining size in snapshot buffer 1081: * @priv: Private pointer to pass to the function MATCH LINES: 1201, 1203, 1205, 1210 1189: /* Dump firmware version and few dwords */ 1190: adreno_snapshot_firmware(device, snapshot); 1191: 1192: /* Add GPU specific sections - registers mainly, but other stuff too */ 1193: if (gpudev->snapshot) 1194: gpudev->snapshot(adreno_dev, snapshot); 1195: 1196: snapshot->ib1dumped = false; 1197: snapshot->ib2dumped = false; 1198: snapshot->ib1dumped_lpac = false; 1199: snapshot->ib2dumped_lpac = false; 1200: 1201: adreno_snapshot_ringbuffer(device, snapshot, adreno_dev->cur_rb); 1202: 1203: /* Dump the prev ringbuffer */ 1204: if (adreno_dev->prev_rb != adreno_dev->cur_rb) 1205: adreno_snapshot_ringbuffer(device, snapshot, 1206: adreno_dev->prev_rb); 1207: 1208: if ((adreno_dev->next_rb != adreno_dev->prev_rb) && 1209: (adreno_dev->next_rb != adreno_dev->cur_rb)) 1210: adreno_snapshot_ringbuffer(device, snapshot, 1211: adreno_dev->next_rb); 1212: 1213: if (device->snapshot_atomic) 1214: return; 1215: 1216: /* Dump selected global buffers */ 1217: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 1218: snapshot, adreno_snapshot_global, device->memstore); 1219: 1220: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 1221: snapshot, adreno_snapshot_global, device->scratch); 1222: 1223: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 1224: snapshot, adreno_snapshot_global, 1225: adreno_dev->pwron_fixup); 1226: 1227: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 1228: snapshot, adreno_snapshot_global, 1229: adreno_dev->profile_buffer); 1230: 1231: if (kgsl_mmu_get_mmutype(device) == KGSL_MMU_TYPE_IOMMU) 1232: adreno_snapshot_iommu(device, snapshot); 1233: 1234: /* MATCH LINES: 1455, 1459 1443: kgsl_mmu_pagetable_get_ttbr0(device->mmu.defaultpagetable); 1444: header->type = SNAPSHOT_GPU_OBJECT_GLOBAL; 1445: 1446: memcpy(ptr, memdesc->hostptr, ctxt_record_size); 1447: 1448: return ctxt_record_size + sizeof(*header); 1449: } 1450: 1451: void adreno_snapshot_preemption_record(struct kgsl_device *device, 1452: struct kgsl_snapshot *snapshot) 1453: { 1454: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1455: struct adreno_ringbuffer *rb; 1456: u32 i; 1457: 1458: if (adreno_is_preemption_enabled(adreno_dev)) { 1459: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1460: kgsl_snapshot_add_section(device, 1461: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 1462: snapshot, snapshot_preemption_record, 1463: rb->preemption_desc); 1464: } 1465: } 1466: } --- FILE: \adreno_snapshot.h | HITS: 3 --- MATCH LINES: 143, 145, 148 131: * adreno_snapshot_global - Add global buffer to snapshot 132: * @device: Pointer to the kgsl device 133: * @buf: Where the global buffer section is to be written 134: * @remain: Remaining bytes in snapshot buffer 135: * @priv: Opaque data 136: * 137: * Return: Number of bytes written to the snapshot buffer 138: */ 139: size_t adreno_snapshot_global(struct kgsl_device *device, u8 *buf, 140: size_t remain, void *priv); 141: 142: /** 143: * adreno_snapshot_dump_all_ibs - To dump all ibs from ringbuffer 144: * @device: Pointer to the kgsl device 145: * @rbptr: Ringbuffer host pointer 146: * @snapshot: Pointer to the snapshot structure 147: * 148: * Parse all IBs from the ringbuffer and add to IB dump list. 149: */ 150: void adreno_snapshot_dump_all_ibs(struct kgsl_device *device, 151: unsigned int *rbptr, 152: struct kgsl_snapshot *snapshot); 153: 154: /** 155: * adreno_snapshot_gmu_versions - To dump gmu versions info to snapshot buffer 156: * @device: Pointer to the kgsl device 157: * @snapshot: Pointer to the snapshot structure 158: * 159: * Dump gmu versions info to the snapshot buffer. 160: */ 161: void adreno_snapshot_gmu_versions(struct kgsl_device *device, 162: struct kgsl_snapshot *snapshot); 163: 164: /** 165: * kgsl_snapshot_gmu_mem - Snapshot a GMU memory descriptor 166: * @device: Pointer to the kgsl device 167: * @buf: Destination snapshot buffer 168: * @remain: Remaining size of the snapshot buffer 169: * @priv: Opaque handle 170: * 171: * Return: Number of bytes written to snapshot buffer 172: */ --- FILE: \adreno_trace.h | HITS: 13 --- MATCH LINES: 521 509: __entry->rb_id = rb_id; 510: __entry->ctx_id = ctx_id; 511: __entry->ts = ts; 512: __entry->status = status; 513: ), 514: TP_printk( 515: "rb=%u ctx=%u ts=%u status=%d", 516: __entry->rb_id, __entry->ctx_id, __entry->ts, __entry->status 517: ) 518: ); 519: 520: TRACE_EVENT(adreno_drawctxt_switch, 521: TP_PROTO(struct adreno_ringbuffer *rb, 522: struct adreno_context *newctx), 523: TP_ARGS(rb, newctx), 524: TP_STRUCT__entry( 525: __field(int, rb_level) 526: __field(unsigned int, oldctx) 527: __field(unsigned int, newctx) 528: __field(unsigned int, flags) 529: ), 530: TP_fast_assign( 531: __entry->rb_level = rb->id; 532: __entry->oldctx = rb->drawctxt_active ? 533: rb->drawctxt_active->base.id : 0; 534: __entry->newctx = newctx ? newctx->base.id : 0; 535: ), 536: TP_printk( 537: "rb level=%d oldctx=%u newctx=%u", 538: __entry->rb_level, __entry->oldctx, __entry->newctx 539: ) 540: ); 541: 542: TRACE_EVENT(adreno_gpu_fault, 543: TP_PROTO(unsigned int ctx, unsigned int ts, 544: unsigned int status, unsigned int rptr, unsigned int wptr, 545: u64 ib1base, unsigned int ib1size, MATCH LINES: 799, 800, 831, 832, 838, 839, 845, 846, 852, 853, 886, 887 787: "DEBUGBUSINTERRUPT0" }, 788: { BIT(GEN8_INT_DEBUGBUSINTERRUPT1), 789: "DEBUGBUSINTERRUPT1" }, 790: { BIT(GEN8_INT_TSBWRITEERROR), "TSBWRITEERROR" }, 791: { BIT(GEN8_INT_SWFUSEVIOLATION), "SWFUSEVIOLATION" }, 792: { BIT(GEN8_INT_ISDBCPUIRQ), "ISDBCPUIRQ" }, 793: { BIT(GEN8_INT_ISDBUNDERDEBUG), "ISDBUNDERDEBUG" }) 794: : "None" 795: ) 796: ); 797: 798: DECLARE_EVENT_CLASS(adreno_hw_preempt_template, 799: TP_PROTO(struct adreno_ringbuffer *cur_rb, 800: struct adreno_ringbuffer *new_rb, 801: unsigned int cur_rptr, unsigned int new_rptr), 802: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr), 803: TP_STRUCT__entry(__field(int, cur_level) 804: __field(int, new_level) 805: __field(unsigned int, cur_rptr) 806: __field(unsigned int, new_rptr) 807: __field(unsigned int, cur_wptr) 808: __field(unsigned int, new_wptr) 809: __field(unsigned int, cur_rbbase) 810: __field(unsigned int, new_rbbase) 811: ), 812: TP_fast_assign(__entry->cur_level = cur_rb->id; 813: __entry->new_level = new_rb->id; 814: __entry->cur_rptr = cur_rptr; 815: __entry->new_rptr = new_rptr; 816: __entry->cur_wptr = cur_rb->wptr; 817: __entry->new_wptr = new_rb->wptr; 818: __entry->cur_rbbase = cur_rb->buffer_desc->gpuaddr; 819: __entry->new_rbbase = new_rb->buffer_desc->gpuaddr; 820: ), 821: TP_printk( 822: "cur_rb_lvl=%d rptr=%x wptr=%x rbbase=%x new_rb_lvl=%d rptr=%x wptr=%x rbbase=%x", 823: __entry->cur_level, __entry->cur_rptr, 824: __entry->cur_wptr, __entry->cur_rbbase, 825: __entry->new_level, __entry->new_rptr, 826: __entry->new_wptr, __entry->new_rbbase 827: ) 828: ); 829: 830: DEFINE_EVENT(adreno_hw_preempt_template, adreno_hw_preempt_clear_to_trig, 831: TP_PROTO(struct adreno_ringbuffer *cur_rb, 832: struct adreno_ringbuffer *new_rb, 833: unsigned int cur_rptr, unsigned int new_rptr), 834: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr) 835: ); 836: 837: DEFINE_EVENT(adreno_hw_preempt_template, adreno_hw_preempt_trig_to_comp, 838: TP_PROTO(struct adreno_ringbuffer *cur_rb, 839: struct adreno_ringbuffer *new_rb, 840: unsigned int cur_rptr, unsigned int new_rptr), 841: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr) 842: ); 843: 844: DEFINE_EVENT(adreno_hw_preempt_template, adreno_hw_preempt_trig_to_comp_int, 845: TP_PROTO(struct adreno_ringbuffer *cur_rb, 846: struct adreno_ringbuffer *new_rb, 847: unsigned int cur_rptr, unsigned int new_rptr), 848: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr) 849: ); 850: 851: TRACE_EVENT(adreno_hw_preempt_comp_to_clear, 852: TP_PROTO(struct adreno_ringbuffer *cur_rb, 853: struct adreno_ringbuffer *new_rb, 854: unsigned int cur_rptr, unsigned int new_rptr), 855: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr), 856: TP_STRUCT__entry(__field(int, cur_level) 857: __field(int, new_level) 858: __field(unsigned int, cur_rptr) 859: __field(unsigned int, new_rptr) 860: __field(unsigned int, cur_wptr) 861: __field(unsigned int, new_wptr_end) 862: __field(unsigned int, new_wptr) 863: __field(unsigned int, cur_rbbase) 864: __field(unsigned int, new_rbbase) 865: ), 866: TP_fast_assign(__entry->cur_level = cur_rb->id; 867: __entry->new_level = new_rb->id; 868: __entry->cur_rptr = cur_rptr; 869: __entry->new_rptr = new_rptr; 870: __entry->cur_wptr = cur_rb->wptr; 871: __entry->new_wptr_end = new_rb->wptr_preempt_end; 872: __entry->new_wptr = new_rb->wptr; 873: __entry->cur_rbbase = cur_rb->buffer_desc->gpuaddr; 874: __entry->new_rbbase = new_rb->buffer_desc->gpuaddr; 875: ), 876: TP_printk( 877: "cur_rb_lvl=%d rptr=%x wptr=%x rbbase=%x prev_rb_lvl=%d rptr=%x wptr_preempt_end=%x wptr=%x rbbase=%x", 878: __entry->cur_level, __entry->cur_rptr, 879: __entry->cur_wptr, __entry->cur_rbbase, 880: __entry->new_level, __entry->new_rptr, 881: __entry->new_wptr_end, __entry->new_wptr, __entry->new_rbbase 882: ) 883: ); 884: 885: TRACE_EVENT(adreno_hw_preempt_token_submit, 886: TP_PROTO(struct adreno_ringbuffer *cur_rb, 887: struct adreno_ringbuffer *new_rb, 888: unsigned int cur_rptr, unsigned int new_rptr), 889: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr), 890: TP_STRUCT__entry(__field(int, cur_level) 891: __field(int, new_level) 892: __field(unsigned int, cur_rptr) 893: __field(unsigned int, new_rptr) 894: __field(unsigned int, cur_wptr) 895: __field(unsigned int, cur_wptr_end) 896: __field(unsigned int, new_wptr) 897: __field(unsigned int, cur_rbbase) 898: __field(unsigned int, new_rbbase) 899: ), 900: TP_fast_assign(__entry->cur_level = cur_rb->id; 901: __entry->new_level = new_rb->id; 902: __entry->cur_rptr = cur_rptr; 903: __entry->new_rptr = new_rptr; 904: __entry->cur_wptr = cur_rb->wptr; 905: __entry->cur_wptr_end = cur_rb->wptr_preempt_end; 906: __entry->new_wptr = new_rb->wptr; 907: __entry->cur_rbbase = cur_rb->buffer_desc->gpuaddr; 908: __entry->new_rbbase = new_rb->buffer_desc->gpuaddr; 909: ), 910: TP_printk( 911: "cur_rb_lvl=%d rptr=%x wptr_preempt_end=%x wptr=%x rbbase=%x new_rb_lvl=%d rptr=%x wptr=%x rbbase=%x", --- FILE: \gen7_reg.h | HITS: 10 --- MATCH LINES: 61, 62, 63, 64, 65, 66, 67, 68, 69, 70 49: #define GEN7_CP_INTERRUPT_STATUS 0x823 50: #define GEN7_CP_PROTECT_STATUS 0x824 51: #define GEN7_CP_STATUS_1 0x825 52: #define GEN7_CP_SQE_INSTR_BASE_LO 0x830 53: #define GEN7_CP_SQE_INSTR_BASE_HI 0x831 54: #define GEN7_CP_MISC_CNTL 0x840 55: #define GEN7_CP_CHICKEN_DBG 0x841 56: #define GEN7_CP_DBG_ECO_CNTL 0x843 57: #define GEN7_CP_APRIV_CNTL 0x844 58: #define GEN7_CP_SEMAPHORE_REG_0 0x846 59: #define GEN7_CP_PROTECT_CNTL 0x84f 60: #define GEN7_CP_PROTECT_REG 0x850 61: #define GEN7_CP_CONTEXT_SWITCH_CNTL 0x8a0 62: #define GEN7_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x8a1 63: #define GEN7_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x8a2 64: #define GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO 0x8a3 65: #define GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI 0x8a4 66: #define GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO 0x8a5 67: #define GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI 0x8a6 68: #define GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO 0x8a7 69: #define GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI 0x8a8 70: #define GEN7_CP_CONTEXT_SWITCH_LEVEL_STATUS 0x8ab 71: #define GEN7_CP_PERFCTR_CP_SEL_0 0x8d0 72: #define GEN7_CP_PERFCTR_CP_SEL_1 0x8d1 73: #define GEN7_CP_PERFCTR_CP_SEL_2 0x8d2 74: #define GEN7_CP_PERFCTR_CP_SEL_3 0x8d3 75: #define GEN7_CP_PERFCTR_CP_SEL_4 0x8d4 76: #define GEN7_CP_PERFCTR_CP_SEL_5 0x8d5 77: #define GEN7_CP_PERFCTR_CP_SEL_6 0x8d6 78: #define GEN7_CP_PERFCTR_CP_SEL_7 0x8d7 79: #define GEN7_CP_PERFCTR_CP_SEL_8 0x8d8 80: #define GEN7_CP_PERFCTR_CP_SEL_9 0x8d9 81: #define GEN7_CP_PERFCTR_CP_SEL_10 0x8da 82: #define GEN7_CP_PERFCTR_CP_SEL_11 0x8db 83: #define GEN7_CP_PERFCTR_CP_SEL_12 0x8dc 84: #define GEN7_CP_PERFCTR_CP_SEL_13 0x8dd 85: #define GEN7_CP_BV_PERFCTR_CP_SEL_0 0x8e0 86: #define GEN7_CP_BV_PERFCTR_CP_SEL_1 0x8e1 87: #define GEN7_CP_BV_PERFCTR_CP_SEL_2 0x8e2 88: #define GEN7_CP_BV_PERFCTR_CP_SEL_3 0x8e3 89: #define GEN7_CP_BV_PERFCTR_CP_SEL_4 0x8e4 90: #define GEN7_CP_BV_PERFCTR_CP_SEL_5 0x8e5 91: #define GEN7_CP_BV_PERFCTR_CP_SEL_6 0x8e6 92: #define GEN7_CP_CRASH_SCRIPT_BASE_LO 0x900 93: #define GEN7_CP_CRASH_SCRIPT_BASE_HI 0x901 94: #define GEN7_CP_CRASH_DUMP_CNTL 0x902 --- FILE: \gen8_reg.h | HITS: 10 --- MATCH LINES: 820, 821, 822, 823, 824, 825, 826, 827, 828, 829 808: #define GEN8_CP_SQE_ICACHE_CNTL_PIPE 0x8b0 809: #define GEN8_CP_SQE_DCACHE_CNTL_PIPE 0x8b1 810: #define GEN8_CP_CHICKEN_DBG_PIPE 0x8b2 811: #define GEN8_CP_HW_FAULT_STATUS_PIPE 0x8b3 812: #define GEN8_CP_HW_FAULT_STATUS_MASK_PIPE 0x8b4 813: #define GEN8_CP_INTERRUPT_STATUS_GLOBAL 0x8b5 814: #define GEN8_CP_INTERRUPT_STATUS_MASK_GLOBAL 0x8b6 815: #define GEN8_CP_INTERRUPT_STATUS_PIPE 0x8b7 816: #define GEN8_CP_INTERRUPT_STATUS_MASK_PIPE 0x8b8 817: #define GEN8_CP_PIPE_STATUS_PIPE 0x8b9 818: #define GEN8_CP_GPU_BATCH_ID_PIPE 0x8ba 819: #define GEN8_CP_SQE_STATUS_PIPE 0x8bb 820: #define GEN8_CP_CONTEXT_SWITCH_CNTL 0x8c0 821: #define GEN8_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x8c1 822: #define GEN8_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x8c2 823: #define GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_LO 0x8c3 824: #define GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_HI 0x8c4 825: #define GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_LO 0x8c5 826: #define GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_HI 0x8c6 827: #define GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_LO 0x8c7 828: #define GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_HI 0x8c8 829: #define GEN8_CP_CONTEXT_SWITCH_LEVEL_STATUS 0x8cb 830: #define GEN8_CP_PERFCTR_CP_SEL_0 0x8d0 831: #define GEN8_CP_PERFCTR_CP_SEL_1 0x8d1 832: #define GEN8_CP_PERFCTR_CP_SEL_2 0x8d2 833: #define GEN8_CP_PERFCTR_CP_SEL_3 0x8d3 834: #define GEN8_CP_PERFCTR_CP_SEL_4 0x8d4 835: #define GEN8_CP_PERFCTR_CP_SEL_5 0x8d5 836: #define GEN8_CP_PERFCTR_CP_SEL_6 0x8d6 837: #define GEN8_CP_PERFCTR_CP_SEL_7 0x8d7 838: #define GEN8_CP_PERFCTR_CP_SEL_8 0x8d8 839: #define GEN8_CP_PERFCTR_CP_SEL_9 0x8d9 840: #define GEN8_CP_PERFCTR_CP_SEL_10 0x8da 841: #define GEN8_CP_PERFCTR_CP_SEL_11 0x8db 842: #define GEN8_CP_PERFCTR_CP_SEL_12 0x8dc 843: #define GEN8_CP_PERFCTR_CP_SEL_13 0x8dd 844: #define GEN8_CP_PERFCTR_CP_SEL_14 0x8de 845: #define GEN8_CP_PERFCTR_CP_SEL_15 0x8df 846: #define GEN8_CP_PERFCTR_CP_SEL_16 0x8e0 847: #define GEN8_CP_PERFCTR_CP_SEL_17 0x8e1 848: #define GEN8_CP_PERFCTR_CP_SEL_18 0x8e2 849: #define GEN8_CP_PERFCTR_CP_SEL_19 0x8e3 850: #define GEN8_CP_PERFCTR_CP_SEL_20 0x8e4 851: #define GEN8_CP_ALWAYS_ON_COUNTER_LO 0x8e7 852: #define GEN8_CP_ALWAYS_ON_COUNTER_HI 0x8e8 853: #define GEN8_CP_ALWAYS_ON_CONTEXT_LO 0x8e9 --- FILE: \kgsl.c | HITS: 1 --- MATCH LINES: 2098 2086: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, 2087: &temp_cur_ts); 2088: trace_kgsl_waittimestamp_exit(device, temp_cur_ts, result); 2089: 2090: kgsl_context_put(context); 2091: 2092: return result; 2093: } 2094: 2095: long kgsl_ioctl_rb_issueibcmds(struct kgsl_device_private *dev_priv, 2096: unsigned int cmd, void *data) 2097: { 2098: struct kgsl_ringbuffer_issueibcmds *param = data; 2099: struct kgsl_device *device = dev_priv->device; 2100: struct kgsl_context *context; 2101: struct kgsl_drawobj *drawobj; 2102: struct kgsl_drawobj_cmd *cmdobj; 2103: long result = -EINVAL; 2104: 2105: /* The legacy functions don't support synchronization commands */ 2106: if ((param->flags & (KGSL_DRAWOBJ_SYNC | KGSL_DRAWOBJ_MARKER))) 2107: return -EINVAL; 2108: 2109: /* Sanity check the number of IBs */ 2110: if (param->flags & KGSL_DRAWOBJ_SUBMIT_IB_LIST && 2111: (param->numibs == 0 || param->numibs > KGSL_MAX_NUMIBS)) 2112: return -EINVAL; 2113: 2114: /* Get the context */ 2115: context = kgsl_context_get_owner(dev_priv, param->drawctxt_id); 2116: if (context == NULL) 2117: return -EINVAL; 2118: 2119: cmdobj = kgsl_drawobj_cmd_create(device, context, param->flags, 2120: CMDOBJ_TYPE); 2121: if (IS_ERR(cmdobj)) { 2122: kgsl_context_put(context); --- FILE: \kgsl.h | HITS: 10 --- MATCH LINES: 88, 90, 92 76: /* Last context id is reserved for global context */ 77: #define KGSL_GLOBAL_CTXT_ID (KGSL_MEMSTORE_MAX - 1) 78: 79: /* 80: * SCRATCH MEMORY: The scratch memory is one page worth of data that 81: * is mapped into the GPU. This allows for some 'shared' data between 82: * the GPU and CPU. For example, it will be used by the GPU to write 83: * each updated RPTR for each RB. 84: */ 85: 86: /* Shadow global helpers */ 87: struct adreno_rb_shadow { 88: /** @rptr: per ringbuffer address where GPU writes the rptr */ 89: u32 rptr; 90: /** @bv_rptr: per ringbuffer address where GPU writes BV rptr */ 91: u32 bv_rptr; 92: /** @bv_ts: per ringbuffer address where BV ringbuffer timestamp is written to */ 93: u32 bv_ts; 94: /** @current_rb_ptname: The current pagetable active on the given RB */ 95: u32 current_rb_ptname; 96: /** @ttbr0: value to program into TTBR0 during pagetable switch */ 97: u64 ttbr0; 98: /** @contextidr: value to program into CONTEXTIDR during pagetable switch */ 99: u32 contextidr; 100: }; 101: 102: /** 103: * struct gpu_work_period - App specific GPU work period stats 104: */ 105: struct gpu_work_period { 106: struct kref refcount; 107: struct list_head list; 108: /** @uid: application unique identifier */ 109: uid_t uid; 110: /** @active: Total amount of time the GPU spent running work */ 111: u64 active; 112: /** @cmds: Total number of commands completed within work period */ 113: u32 cmds; 114: /** @frames: Total number of frames completed within work period */ 115: atomic_t frames; 116: /** @flags: Flags to accumulate GPU busy stats */ MATCH LINES: 294, 295, 296, 310, 311, 312, 315 282: spinlock_t lock; 283: struct list_head events; 284: struct list_head group; 285: unsigned int processed; 286: char name[64]; 287: readtimestamp_func readtimestamp; 288: void *priv; 289: }; 290: 291: /** 292: * struct submission_info - Container for submission statistics 293: * @inflight: Number of commands that are inflight 294: * @rb_id: id of the ringbuffer to which this submission is made 295: * @rptr: Read pointer of the ringbuffer 296: * @wptr: Write pointer of the ringbuffer 297: * @gmu_dispatch_queue: GMU dispach queue to which this submission is made 298: */ 299: struct submission_info { 300: int inflight; 301: u32 rb_id; 302: u32 rptr; 303: u32 wptr; 304: u32 gmu_dispatch_queue; 305: }; 306: 307: /** 308: * struct retire_info - Container for retire statistics 309: * @inflight: NUmber of commands that are inflight 310: * @rb_id: id of the ringbuffer to which this submission is made 311: * @rptr: Read pointer of the ringbuffer 312: * @wptr: Write pointer of the ringbuffer 313: * @gmu_dispatch_queue: GMU dispach queue to which this submission is made 314: * @timestamp: Timestamp of submission that retired 315: * @submitted_to_rb: AO ticks when GMU put this submission on ringbuffer 316: * @sop: AO ticks when GPU started procssing this submission 317: * @eop: AO ticks when GPU finished this submission 318: * @retired_on_gmu: AO ticks when GMU retired this submission 319: * @active: Number AO of ticks taken by GPU to complete the command 320: */ 321: struct retire_info { 322: int inflight; 323: int rb_id; 324: u32 rptr; 325: u32 wptr; 326: u32 gmu_dispatch_queue; 327: u32 timestamp; 328: u64 submitted_to_rb; 329: u64 sop; 330: u64 eop; 331: u64 retired_on_gmu; 332: u64 active; 333: }; 334: 335: long kgsl_ioctl_device_getproperty(struct kgsl_device_private *dev_priv, 336: unsigned int cmd, void *data); 337: long kgsl_ioctl_device_setproperty(struct kgsl_device_private *dev_priv, 338: unsigned int cmd, void *data); 339: long kgsl_ioctl_device_waittimestamp_ctxtid(struct kgsl_device_private --- FILE: \kgsl_compat.c | HITS: 3 --- MATCH LINES: 67, 68 55: result = kgsl_ioctl_submit_commands(dev_priv, cmd, ¶m); 56: 57: param32->timestamp = param.timestamp; 58: 59: return result; 60: } 61: 62: static long 63: kgsl_ioctl_rb_issueibcmds_compat(struct kgsl_device_private *dev_priv, 64: unsigned int cmd, void *data) 65: { 66: int result; 67: struct kgsl_ringbuffer_issueibcmds_compat *param32 = data; 68: struct kgsl_ringbuffer_issueibcmds param; 69: 70: param.drawctxt_id = param32->drawctxt_id; 71: param.flags = param32->flags; 72: param.ibdesc_addr = (unsigned long)param32->ibdesc_addr; 73: param.numibs = param32->numibs; 74: param.timestamp = param32->timestamp; 75: 76: result = kgsl_ioctl_rb_issueibcmds(dev_priv, cmd, ¶m); 77: 78: param32->timestamp = param.timestamp; 79: 80: return result; 81: } 82: 83: static long kgsl_ioctl_cmdstream_freememontimestamp_ctxtid_compat( 84: struct kgsl_device_private 85: *dev_priv, unsigned int cmd, 86: void *data) 87: { 88: struct kgsl_cmdstream_freememontimestamp_ctxtid_compat *param32 = data; 89: struct kgsl_cmdstream_freememontimestamp_ctxtid param; 90: 91: param.context_id = param32->context_id; 92: param.gpuaddr = (unsigned long)param32->gpuaddr; MATCH LINES: 286 274: param.len = (size_t)param32->len; 275: 276: return kgsl_ioctl_timestamp_event(dev_priv, cmd, ¶m); 277: } 278: 279: 280: static const struct kgsl_ioctl kgsl_compat_ioctl_funcs[] = { 281: KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_GETPROPERTY_COMPAT, 282: kgsl_ioctl_device_getproperty_compat), 283: /* IOCTL_KGSL_DEVICE_WAITTIMESTAMP is no longer supported */ 284: KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID, 285: kgsl_ioctl_device_waittimestamp_ctxtid), 286: KGSL_IOCTL_FUNC(IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS_COMPAT, 287: kgsl_ioctl_rb_issueibcmds_compat), 288: KGSL_IOCTL_FUNC(IOCTL_KGSL_SUBMIT_COMMANDS_COMPAT, 289: kgsl_ioctl_submit_commands_compat), 290: /* IOCTL_KGSL_CMDSTREAM_READTIMESTAMP is no longer supported */ 291: KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID, 292: kgsl_ioctl_cmdstream_readtimestamp_ctxtid), 293: /* IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP is no longer supported */ 294: KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID_COMPAT, 295: kgsl_ioctl_cmdstream_freememontimestamp_ctxtid_compat), 296: KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_CREATE, 297: kgsl_ioctl_drawctxt_create), 298: KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_DESTROY, 299: kgsl_ioctl_drawctxt_destroy), 300: KGSL_IOCTL_FUNC(IOCTL_KGSL_MAP_USER_MEM_COMPAT, 301: kgsl_ioctl_map_user_mem_compat), 302: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FREE_COMPAT, 303: kgsl_ioctl_sharedmem_free_compat), 304: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE_COMPAT, 305: kgsl_ioctl_sharedmem_flush_cache_compat), 306: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_ALLOC_COMPAT, 307: kgsl_ioctl_gpumem_alloc_compat), 308: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMESTAMP_EVENT_COMPAT, 309: kgsl_ioctl_timestamp_event_compat), 310: KGSL_IOCTL_FUNC(IOCTL_KGSL_SETPROPERTY_COMPAT, --- FILE: \kgsl_compat.h | HITS: 3 --- MATCH LINES: 77, 85, 86 65: compat_uptr_t cmdlist; 66: unsigned int numcmds; 67: compat_uptr_t synclist; 68: unsigned int numsyncs; 69: unsigned int timestamp; 70: /* private: reserved for future use */ 71: unsigned int __pad[4]; 72: }; 73: 74: #define IOCTL_KGSL_SUBMIT_COMMANDS_COMPAT \ 75: _IOWR(KGSL_IOC_TYPE, 0x3D, struct kgsl_submit_commands_compat) 76: 77: struct kgsl_ringbuffer_issueibcmds_compat { 78: unsigned int drawctxt_id; 79: compat_ulong_t ibdesc_addr; 80: unsigned int numibs; 81: unsigned int timestamp; /* output param */ 82: unsigned int flags; 83: }; 84: 85: #define IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS_COMPAT \ 86: _IOWR(KGSL_IOC_TYPE, 0x10, struct kgsl_ringbuffer_issueibcmds_compat) 87: 88: struct kgsl_cmdstream_freememontimestamp_ctxtid_compat { 89: unsigned int context_id; 90: compat_ulong_t gpuaddr; 91: unsigned int type; 92: unsigned int timestamp; 93: }; 94: 95: #define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID_COMPAT \ 96: _IOW(KGSL_IOC_TYPE, 0x17, \ 97: struct kgsl_cmdstream_freememontimestamp_ctxtid_compat) 98: 99: struct kgsl_map_user_mem_compat { 100: int fd; 101: compat_ulong_t gpuaddr; 102: compat_size_t len; 103: compat_size_t offset; 104: compat_ulong_t hostptr; 105: enum kgsl_user_mem_type memtype; 106: unsigned int flags; 107: }; 108: 109: #define IOCTL_KGSL_MAP_USER_MEM_COMPAT \ 110: _IOWR(KGSL_IOC_TYPE, 0x15, struct kgsl_map_user_mem_compat) --- FILE: \kgsl_drawobj.h | HITS: 1 --- MATCH LINES: 53 41: /** @destroy: Callbak function to take down the object */ 42: void (*destroy)(struct kgsl_drawobj *drawobj); 43: /** @destroy_object: Callback function to free the object memory */ 44: void (*destroy_object)(struct kgsl_drawobj *drawobj); 45: }; 46: 47: /** 48: * struct kgsl_drawobj_cmd - KGSL command obj, This covers marker 49: * cmds also since markers are special form of cmds that do not 50: * need their cmds to be executed. 51: * @base: Base kgsl_drawobj, this needs to be the first entry 52: * @priv: Internal flags 53: * @global_ts: The ringbuffer timestamp corresponding to this 54: * command obj 55: * @fault_policy: Internal policy describing how to handle this command in case 56: * of a fault 57: * @fault_recovery: recovery actions actually tried for this batch 58: * be hung 59: * @refcount: kref structure to maintain the reference count 60: * @cmdlist: List of IBs to issue 61: * @memlist: List of all memory used in this command batch 62: * @marker_timestamp: For markers, the timestamp of the last "real" command that 63: * was queued 64: * @profiling_buf_entry: Mem entry containing the profiling buffer 65: * @profiling_buffer_gpuaddr: GPU virt address of the profile buffer added here 66: * for easy access 67: * @profile_index: Index to store the start/stop ticks in the kernel profiling 68: * buffer 69: * @submit_ticks: Variable to hold ticks at the time of 70: * command obj submit. 71: 72: */ 73: struct kgsl_drawobj_cmd { 74: struct kgsl_drawobj base; 75: unsigned long priv; 76: unsigned int global_ts; 77: unsigned long fault_policy; --- FILE: \kgsl_eventlog.c | HITS: 1 --- MATCH LINES: 26 14: #include "kgsl_snapshot.h" 15: #include "kgsl_util.h" 16: 17: #define EVENTLOG_SIZE (SZ_64K + SZ_32K) 18: #define MAGIC 0xabbaabba 19: #define LOG_FENCE_NAME_LEN 74 20: 21: #define KGSL_SNAPSHOT_EVENTLOG_TYPE 0x1 22: #define KGSL_SNAPSHOT_EVENTLOG_VERSION 0x0 23: 24: /* 25: * This an internal event used to skip empty space at the bottom of the 26: * ringbuffer 27: */ 28: 29: #define LOG_SKIP 1 30: #define LOG_FIRE_EVENT 2 31: #define LOG_CMDBATCH_SUBMITTED_EVENT 3 32: #define LOG_CMDBATCH_RETIRED_EVENT 4 33: #define LOG_SYNCPOINT_FENCE_EVENT 5 34: #define LOG_SYNCPOINT_FENCE_EXPIRE_EVENT 6 35: #define LOG_TIMELINE_FENCE_ALLOC_EVENT 7 36: #define LOG_TIMELINE_FENCE_RELEASE_EVENT 8 37: #define LOG_CX_WAIT_TIMEOUT_EVENT 9 38: 39: static spinlock_t lock; 40: static void *kgsl_eventlog; 41: static int eventlog_wptr; 42: 43: struct kgsl_log_header { 44: /** @magic: Magic value to identify header */ 45: u32 magic; 46: /** @pid: : PID of the process */ 47: int pid; 48: /** @time: System time in nanoseconds */ 49: u64 time; 50: /** @event: bits[0:15] specify the event ID. bits[16:31] specify event version */ --- FILE: \kgsl_ioctl.c | HITS: 1 --- MATCH LINES: 16 4: * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 5: */ 6: 7: #include "kgsl_device.h" 8: #include "kgsl_sync.h" 9: 10: static const struct kgsl_ioctl kgsl_ioctl_funcs[] = { 11: KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_GETPROPERTY, 12: kgsl_ioctl_device_getproperty), 13: /* IOCTL_KGSL_DEVICE_WAITTIMESTAMP is no longer supported */ 14: KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID, 15: kgsl_ioctl_device_waittimestamp_ctxtid), 16: KGSL_IOCTL_FUNC(IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS, 17: kgsl_ioctl_rb_issueibcmds), 18: KGSL_IOCTL_FUNC(IOCTL_KGSL_SUBMIT_COMMANDS, 19: kgsl_ioctl_submit_commands), 20: /* IOCTL_KGSL_CMDSTREAM_READTIMESTAMP is no longer supported */ 21: KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID, 22: kgsl_ioctl_cmdstream_readtimestamp_ctxtid), 23: /* IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP is no longer supported */ 24: KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID, 25: kgsl_ioctl_cmdstream_freememontimestamp_ctxtid), 26: KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_CREATE, 27: kgsl_ioctl_drawctxt_create), 28: KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_DESTROY, 29: kgsl_ioctl_drawctxt_destroy), 30: KGSL_IOCTL_FUNC(IOCTL_KGSL_MAP_USER_MEM, 31: kgsl_ioctl_map_user_mem), 32: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FROM_PMEM, 33: kgsl_ioctl_map_user_mem), 34: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FREE, 35: kgsl_ioctl_sharedmem_free), 36: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE, 37: kgsl_ioctl_sharedmem_flush_cache), 38: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_ALLOC, 39: kgsl_ioctl_gpumem_alloc), 40: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMESTAMP_EVENT, --- FILE: \kgsl_snapshot.h | HITS: 4 --- MATCH LINES: 104, 108, 114, 115 92: /* 93: * This structure contains a record of an active context. 94: * These are appended one after another in the OS section below 95: * the header above 96: */ 97: struct kgsl_snapshot_linux_context_v2 { 98: __u32 id; /* The context ID */ 99: __u32 timestamp_queued; /* The last queued timestamp */ 100: __u32 timestamp_consumed; /* The last timestamp consumed by HW */ 101: __u32 timestamp_retired; /* The last timestamp retired by HW */ 102: }; 103: 104: /* Ringbuffer sub-section header */ 105: struct kgsl_snapshot_rb_v2 { 106: int start; /* dword at the start of the dump */ 107: int end; /* dword at the end of the dump */ 108: int rbsize; /* Size (in dwords) of the ringbuffer */ 109: int wptr; /* Current index of the CPU write pointer */ 110: int rptr; /* Current index of the GPU read pointer */ 111: int count; /* Number of dwords in the dump */ 112: __u32 timestamp_queued; /* The last queued timestamp */ 113: __u32 timestamp_retired; /* The last timestamp retired by HW */ 114: __u64 gpuaddr; /* The GPU address of the ringbuffer */ 115: __u32 id; /* Ringbuffer identifier */ 116: } __packed; 117: 118: /* Replay or Memory list section, both sections have same header */ 119: struct kgsl_snapshot_mem_list_v2 { 120: /* 121: * Number of IBs to replay for replay section or 122: * number of memory list entries for mem list section 123: */ 124: int num_entries; 125: /* Pagetable base to which the replay IBs or memory entries belong */ 126: __u64 ptbase; 127: } __packed; 128: 129: /* Indirect buffer sub-section header (v2) */ 130: struct kgsl_snapshot_ib_v2 { 131: __u64 gpuaddr; /* GPU address of the IB */ 132: __u64 ptbase; /* Base for the pagetable the GPU address is valid in */ 133: __u64 size; /* Size of the IB */ 134: } __packed; 135: 136: /* GMU memory ID's */ 137: #define SNAPSHOT_GMU_MEM_UNKNOWN 0x00 138: #define SNAPSHOT_GMU_MEM_HFI 0x01 139: #define SNAPSHOT_GMU_MEM_LOG 0x02 --- FILE: \kgsl_trace.h | HITS: 1 --- MATCH LINES: 48 36: __print_symbolic(type, \ 37: { KGSL_MEM_ENTRY_KERNEL, "gpumem" }, \ 38: { KGSL_MEM_ENTRY_USER, "usermem" }, \ 39: { KGSL_MEM_ENTRY_ION, "ion" }) 40: 41: #define show_constraint(type) \ 42: __print_symbolic(type, \ 43: { KGSL_CONSTRAINT_NONE, "None" }, \ 44: { KGSL_CONSTRAINT_PWRLEVEL, "Pwrlevel" }, \ 45: { KGSL_CONSTRAINT_L3_NONE, "L3_none" }, \ 46: { KGSL_CONSTRAINT_L3_PWRLEVEL, "L3_pwrlevel" }) 47: 48: struct kgsl_ringbuffer_issueibcmds; 49: struct kgsl_device_waittimestamp; 50: 51: /* 52: * Tracepoint for kgsl issue ib commands 53: */ 54: TRACE_EVENT(kgsl_issueibcmds, 55: 56: TP_PROTO(struct kgsl_device *device, 57: int drawctxt_id, 58: unsigned int numibs, 59: int timestamp, 60: int flags, 61: int result, 62: unsigned int type), 63: 64: TP_ARGS(device, drawctxt_id, numibs, timestamp, 65: flags, result, type), 66: 67: TP_STRUCT__entry( 68: __string(device_name, device->name) 69: __field(unsigned int, drawctxt_id) 70: __field(unsigned int, numibs) 71: __field(unsigned int, timestamp) 72: __field(unsigned int, flags) --- FILE: \kgsl_util.c | HITS: 1 --- MATCH LINES: 321 309: entry.vaddr = (u64)(ptr); 310: entry.size = size; 311: ret = qcom_va_md_add_region(&entry); 312: if (ret < 0) 313: dev_err(dev, "Failed to register %s with va_minidump: %d\n", name, 314: ret); 315: 316: return ret; 317: } 318: 319: static bool include_global_in_minidump(struct kgsl_global_memdesc *md) 320: { 321: static const char * const globals[] = {"ringbuffer", "memstore", "scratch", 322: "profile", "profile_desc", "alwayson"}; 323: int i; 324: 325: for (i = 0; i < ARRAY_SIZE(globals); i++) { 326: if (!strcmp(md->name, globals[i])) 327: return true; 328: } 329: 330: return false; 331: } 332: 333: #ifdef CONFIG_QCOM_KGSL_USE_SHMEM 334: static int kgsl_add_page_pools_to_va_minidump(struct kgsl_device *device) 335: { 336: return 0; 337: } 338: #else 339: static int kgsl_add_page_pools_to_va_minidump(struct kgsl_device *device) 340: { 341: int i, ret; 342: 343: for (i = 0; i < kgsl_num_pools; i++) { 344: ret = kgsl_add_va_to_minidump(device->dev, KGSL_PAGE_POOL_ENTRY, 345: (void *)&kgsl_pools[i], sizeof(kgsl_pools[i])); --- FILE: \include\uapi\linux\msm_kgsl.h | HITS: 7 --- MATCH LINES: 64 52: #define KGSL_CONTEXT_PRIORITY_MASK 0x0000F000 53: #define KGSL_CONTEXT_PRIORITY_SHIFT 12 54: #define KGSL_CONTEXT_PRIORITY_UNDEF 0 55: 56: #define KGSL_CONTEXT_IFH_NOP 0x00010000 57: #define KGSL_CONTEXT_SECURE 0x00020000 58: #define KGSL_CONTEXT_NO_SNAPSHOT 0x00040000 59: #define KGSL_CONTEXT_SPARSE 0x00080000 60: 61: #define KGSL_CONTEXT_PREEMPT_STYLE_MASK 0x0E000000 62: #define KGSL_CONTEXT_PREEMPT_STYLE_SHIFT 25 63: #define KGSL_CONTEXT_PREEMPT_STYLE_DEFAULT 0x0 64: #define KGSL_CONTEXT_PREEMPT_STYLE_RINGBUFFER 0x1 65: #define KGSL_CONTEXT_PREEMPT_STYLE_FINEGRAIN 0x2 66: 67: #define KGSL_CONTEXT_TYPE_MASK 0x01F00000 68: #define KGSL_CONTEXT_TYPE_SHIFT 20 69: #define KGSL_CONTEXT_TYPE_ANY 0 70: #define KGSL_CONTEXT_TYPE_GL 1 71: #define KGSL_CONTEXT_TYPE_CL 2 72: #define KGSL_CONTEXT_TYPE_C2D 3 73: #define KGSL_CONTEXT_TYPE_RS 4 74: #define KGSL_CONTEXT_TYPE_VK 5 75: #define KGSL_CONTEXT_TYPE_UNKNOWN 0x1E 76: 77: #define KGSL_CONTEXT_INVALIDATE_ON_FAULT 0x10000000 78: #define KGSL_CONTEXT_LPAC 0x20000000 79: #define KGSL_CONTEXT_FAULT_INFO 0x40000000 80: 81: #define KGSL_CONTEXT_INVALID 0xffffffff 82: 83: /* 84: * --- command batch flags --- 85: * The bits that are linked to a KGSL_CONTEXT equivalent are either legacy 86: * definitions or bits that are valid for both contexts and cmdbatches. To be 87: * safe the other 8 bits that are still available in the context field should be 88: * omitted here in case we need to share - the other bits are available for MATCH LINES: 533, 536, 539 521: #define KGSL_PERFCOUNTER_BROKEN 0xFFFFFFFE 522: 523: /* structure holds list of ibs */ 524: struct kgsl_ibdesc { 525: unsigned long gpuaddr; 526: unsigned long __pad; 527: __kernel_size_t sizedwords; 528: unsigned int ctrl; 529: }; 530: 531: /** 532: * struct kgsl_cmdbatch_profiling_buffer 533: * @wall_clock_s: Ringbuffer submission time (seconds). 534: * If KGSL_CMDBATCH_PROFILING_KTIME is set, time is provided 535: * in kernel clocks, otherwise wall clock time is used. 536: * @wall_clock_ns: Ringbuffer submission time (nanoseconds). 537: * If KGSL_CMDBATCH_PROFILING_KTIME is set time is provided 538: * in kernel clocks, otherwise wall clock time is used. 539: * @gpu_ticks_queued: GPU ticks at ringbuffer submission 540: * @gpu_ticks_submitted: GPU ticks when starting cmdbatch execution 541: * @gpu_ticks_retired: GPU ticks when finishing cmdbatch execution 542: * 543: * This structure defines the profiling buffer used to measure cmdbatch 544: * execution time 545: */ 546: struct kgsl_cmdbatch_profiling_buffer { 547: __u64 wall_clock_s; 548: __u64 wall_clock_ns; 549: __u64 gpu_ticks_queued; 550: __u64 gpu_ticks_submitted; 551: __u64 gpu_ticks_retired; 552: }; 553: 554: /* ioctls */ 555: #define KGSL_IOC_TYPE 0x09 556: 557: /* 558: * get misc info about the GPU 559: * type should be a value from enum kgsl_property_type 560: * value points to a structure that varies based on type 561: * sizebytes is sizeof() that structure 562: * for KGSL_PROP_DEVICE_INFO, use struct kgsl_devinfo 563: * this structure contaings hardware versioning info. MATCH LINES: 612, 620, 621 600: /* DEPRECATED: issue indirect commands to the GPU. 601: * drawctxt_id must have been created with IOCTL_KGSL_DRAWCTXT_CREATE 602: * ibaddr and sizedwords must specify a subset of a buffer created 603: * with IOCTL_KGSL_SHAREDMEM_FROM_PMEM 604: * flags may be a mask of KGSL_CONTEXT_ values 605: * timestamp is a returned counter value which can be passed to 606: * other ioctls to determine when the commands have been executed by 607: * the GPU. 608: * 609: * This function is deprecated - consider using IOCTL_KGSL_SUBMIT_COMMANDS 610: * instead 611: */ 612: struct kgsl_ringbuffer_issueibcmds { 613: unsigned int drawctxt_id; 614: unsigned long ibdesc_addr; 615: unsigned int numibs; 616: unsigned int timestamp; /*output param */ 617: unsigned int flags; 618: }; 619: 620: #define IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS \ 621: _IOWR(KGSL_IOC_TYPE, 0x10, struct kgsl_ringbuffer_issueibcmds) 622: 623: /* read the most recently executed timestamp value 624: * type should be a value from enum kgsl_timestamp_type 625: */ 626: struct kgsl_cmdstream_readtimestamp { 627: unsigned int type; 628: unsigned int timestamp; /*output param */ 629: }; 630: 631: #define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_OLD \ 632: _IOR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp) 633: 634: #define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP \ 635: _IOWR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp) 636: 637: /* free memory when the GPU reaches a given timestamp. 638: * gpuaddr specify a memory region created by a 639: * IOCTL_KGSL_SHAREDMEM_FROM_PMEM call 640: * type should be a value from enum kgsl_timestamp_type 641: */ 642: struct kgsl_cmdstream_freememontimestamp { 643: unsigned long gpuaddr; 644: unsigned int type; 645: unsigned int timestamp; TOTAL MATCHES: 833 ========================================================================================== SUBSYSTEM: PREEMPTION ========================================================================================== --- FILE: \a5xx_reg.h | HITS: 7 --- MATCH LINES: 90, 91, 92, 93, 94, 95, 96 78: #define A5XX_CP_MERCIU_DBG_DATA_2 0x829 79: #define A5XX_CP_PFP_UCODE_DBG_ADDR 0x82A 80: #define A5XX_CP_PFP_UCODE_DBG_DATA 0x82B 81: #define A5XX_CP_ME_UCODE_DBG_ADDR 0x82F 82: #define A5XX_CP_ME_UCODE_DBG_DATA 0x830 83: #define A5XX_CP_CNTL 0x831 84: #define A5XX_CP_ME_CNTL 0x832 85: #define A5XX_CP_CHICKEN_DBG 0x833 86: #define A5XX_CP_PFP_INSTR_BASE_LO 0x835 87: #define A5XX_CP_PFP_INSTR_BASE_HI 0x836 88: #define A5XX_CP_PM4_INSTR_BASE_LO 0x838 89: #define A5XX_CP_PM4_INSTR_BASE_HI 0x839 90: #define A5XX_CP_CONTEXT_SWITCH_CNTL 0x83B 91: #define A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_LO 0x83C 92: #define A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_HI 0x83D 93: #define A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_LO 0x83E 94: #define A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_HI 0x83F 95: #define A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x840 96: #define A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x841 97: #define A5XX_CP_ADDR_MODE_CNTL 0x860 98: #define A5XX_CP_ME_STAT_DATA 0xB14 99: #define A5XX_CP_WFI_PEND_CTR 0xB15 100: #define A5XX_CP_INTERRUPT_STATUS 0xB18 101: #define A5XX_CP_HW_FAULT 0xB1A 102: #define A5XX_CP_PROTECT_STATUS 0xB1C 103: #define A5XX_CP_IB1_BASE 0xB1F 104: #define A5XX_CP_IB1_BASE_HI 0xB20 105: #define A5XX_CP_IB1_BUFSZ 0xB21 106: #define A5XX_CP_IB2_BASE 0xB22 107: #define A5XX_CP_IB2_BASE_HI 0xB23 108: #define A5XX_CP_IB2_BUFSZ 0xB24 109: #define A5XX_CP_PROTECT_REG_0 0x880 110: #define A5XX_CP_PROTECT_CNTL 0x8A0 111: #define A5XX_CP_AHB_FAULT 0xB1B 112: #define A5XX_CP_PERFCTR_CP_SEL_0 0xBB0 113: #define A5XX_CP_PERFCTR_CP_SEL_1 0xBB1 114: #define A5XX_CP_PERFCTR_CP_SEL_2 0xBB2 115: #define A5XX_CP_PERFCTR_CP_SEL_3 0xBB3 116: #define A5XX_CP_PERFCTR_CP_SEL_4 0xBB4 117: #define A5XX_CP_PERFCTR_CP_SEL_5 0xBB5 118: #define A5XX_CP_PERFCTR_CP_SEL_6 0xBB6 119: #define A5XX_CP_PERFCTR_CP_SEL_7 0xBB7 120: --- FILE: \a6xx_reg.h | HITS: 12 --- MATCH LINES: 71, 72, 73, 74, 75, 76, 77, 78, 79, 80 59: #define A6XX_CP_SQE_INSTR_BASE_LO 0x830 60: #define A6XX_CP_SQE_INSTR_BASE_HI 0x831 61: #define A6XX_CP_MISC_CNTL 0x840 62: #define A6XX_CP_APRIV_CNTL 0X844 63: #define A6XX_CP_ROQ_THRESHOLDS_1 0x8C1 64: #define A6XX_CP_ROQ_THRESHOLDS_2 0x8C2 65: #define A6XX_CP_MEM_POOL_SIZE 0x8C3 66: #define A6XX_CP_CHICKEN_DBG 0x841 67: #define A6XX_CP_ADDR_MODE_CNTL 0x842 68: #define A6XX_CP_DBG_ECO_CNTL 0x843 69: #define A6XX_CP_PROTECT_CNTL 0x84F 70: #define A6XX_CP_PROTECT_REG 0x850 71: #define A6XX_CP_CONTEXT_SWITCH_CNTL 0x8A0 72: #define A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x8A1 73: #define A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x8A2 74: #define A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO 0x8A3 75: #define A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI 0x8A4 76: #define A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO 0x8A5 77: #define A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI 0x8A6 78: #define A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO 0x8A7 79: #define A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI 0x8A8 80: #define A6XX_CP_CONTEXT_SWITCH_LEVEL_STATUS 0x8AB 81: #define A6XX_CP_PERFCTR_CP_SEL_0 0x8D0 82: #define A6XX_CP_PERFCTR_CP_SEL_1 0x8D1 83: #define A6XX_CP_PERFCTR_CP_SEL_2 0x8D2 84: #define A6XX_CP_PERFCTR_CP_SEL_3 0x8D3 85: #define A6XX_CP_PERFCTR_CP_SEL_4 0x8D4 86: #define A6XX_CP_PERFCTR_CP_SEL_5 0x8D5 87: #define A6XX_CP_PERFCTR_CP_SEL_6 0x8D6 88: #define A6XX_CP_PERFCTR_CP_SEL_7 0x8D7 89: #define A6XX_CP_PERFCTR_CP_SEL_8 0x8D8 90: #define A6XX_CP_PERFCTR_CP_SEL_9 0x8D9 91: #define A6XX_CP_PERFCTR_CP_SEL_10 0x8DA 92: #define A6XX_CP_PERFCTR_CP_SEL_11 0x8DB 93: #define A6XX_CP_PERFCTR_CP_SEL_12 0x8DC 94: #define A6XX_CP_PERFCTR_CP_SEL_13 0x8DD 95: #define A6XX_CP_CRASH_SCRIPT_BASE_LO 0x900 96: #define A6XX_CP_CRASH_SCRIPT_BASE_HI 0x901 97: #define A6XX_CP_CRASH_DUMP_CNTL 0x902 98: #define A6XX_CP_CRASH_DUMP_STATUS 0x903 99: #define A6XX_CP_SQE_STAT_ADDR 0x908 100: #define A6XX_CP_SQE_STAT_DATA 0x909 101: #define A6XX_CP_DRAW_STATE_ADDR 0x90A 102: #define A6XX_CP_DRAW_STATE_DATA 0x90B 103: #define A6XX_CP_ROQ_DBG_ADDR 0x90C 104: #define A6XX_CP_ROQ_DBG_DATA 0x90D MATCH LINES: 686 674: #define A6XX_RB_PERFCTR_RB_SEL_7 0x8E17 675: #define A6XX_RB_PERFCTR_CCU_SEL_0 0x8E18 676: #define A6XX_RB_PERFCTR_CCU_SEL_1 0x8E19 677: #define A6XX_RB_PERFCTR_CCU_SEL_2 0x8E1A 678: #define A6XX_RB_PERFCTR_CCU_SEL_3 0x8E1B 679: #define A6XX_RB_PERFCTR_CCU_SEL_4 0x8E1C 680: #define A6XX_RB_PERFCTR_CMP_SEL_0 0x8E2C 681: #define A6XX_RB_PERFCTR_CMP_SEL_1 0x8E2D 682: #define A6XX_RB_PERFCTR_CMP_SEL_2 0x8E2E 683: #define A6XX_RB_PERFCTR_CMP_SEL_3 0x8E2F 684: #define A6XX_RB_RB_SUB_BLOCK_SEL_CNTL_HOST 0x8E3B 685: #define A6XX_RB_RB_SUB_BLOCK_SEL_CNTL_CD 0x8E3D 686: #define A6XX_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE 0x8E50 687: 688: /* PC registers */ 689: #define A6XX_PC_DBG_ECO_CNTL 0x9E00 690: #define A6XX_PC_ADDR_MODE_CNTL 0x9E01 691: #define A6XX_PC_PERFCTR_PC_SEL_0 0x9E34 692: #define A6XX_PC_PERFCTR_PC_SEL_1 0x9E35 693: #define A6XX_PC_PERFCTR_PC_SEL_2 0x9E36 694: #define A6XX_PC_PERFCTR_PC_SEL_3 0x9E37 695: #define A6XX_PC_PERFCTR_PC_SEL_4 0x9E38 696: #define A6XX_PC_PERFCTR_PC_SEL_5 0x9E39 697: #define A6XX_PC_PERFCTR_PC_SEL_6 0x9E3A 698: #define A6XX_PC_PERFCTR_PC_SEL_7 0x9E3B 699: 700: /* HLSQ registers */ 701: #define A6XX_HLSQ_ADDR_MODE_CNTL 0xBE05 702: #define A6XX_HLSQ_PERFCTR_HLSQ_SEL_0 0xBE10 703: #define A6XX_HLSQ_PERFCTR_HLSQ_SEL_1 0xBE11 704: #define A6XX_HLSQ_PERFCTR_HLSQ_SEL_2 0xBE12 705: #define A6XX_HLSQ_PERFCTR_HLSQ_SEL_3 0xBE13 706: #define A6XX_HLSQ_PERFCTR_HLSQ_SEL_4 0xBE14 707: #define A6XX_HLSQ_PERFCTR_HLSQ_SEL_5 0xBE15 708: #define A6XX_HLSQ_DBG_AHB_READ_APERTURE 0xC800 709: #define A6XX_HLSQ_DBG_READ_SEL 0xD000 710: MATCH LINES: 1056 1044: #define A6XX_GMU_RPMH_HYST_CTRL 0x1F8E9 1045: #define A6XX_GPU_GMU_CX_GMU_RPMH_POWER_STATE 0x1F8EC 1046: #define A6XX_GPU_GMU_CX_GMU_PWR_COL_CP_MSG 0x1F900 1047: #define A6XX_GPU_GMU_CX_GMU_PWR_COL_CP_RESP 0x1F901 1048: #define A6XX_GMU_BOOT_KMD_LM_HANDSHAKE 0x1F9F0 1049: #define A6XX_GMU_LLM_GLM_SLEEP_CTRL 0x1F957 1050: #define A6XX_GMU_LLM_GLM_SLEEP_STATUS 0x1F958 1051: 1052: /* HFI registers*/ 1053: #define A6XX_GMU_ALWAYS_ON_COUNTER_L 0x1F888 1054: #define A6XX_GMU_ALWAYS_ON_COUNTER_H 0x1F889 1055: #define A6XX_GMU_GMU_PWR_COL_KEEPALIVE 0x1F8C3 1056: #define A6XX_GMU_PWR_COL_PREEMPT_KEEPALIVE 0x1F8C4 1057: #define A6XX_GMU_HFI_CTRL_STATUS 0x1F980 1058: #define A6XX_GMU_HFI_VERSION_INFO 0x1F981 1059: #define A6XX_GMU_HFI_SFR_ADDR 0x1F982 1060: #define A6XX_GMU_HFI_MMAP_ADDR 0x1F983 1061: #define A6XX_GMU_HFI_QTBL_INFO 0x1F984 1062: #define A6XX_GMU_HFI_QTBL_ADDR 0x1F985 1063: #define A6XX_GMU_HFI_CTRL_INIT 0x1F986 1064: #define A6XX_GMU_GMU2HOST_INTR_SET 0x1F990 1065: #define A6XX_GMU_GMU2HOST_INTR_CLR 0x1F991 1066: #define A6XX_GMU_GMU2HOST_INTR_INFO 0x1F992 1067: #define A6XX_GMU_GMU2HOST_INTR_MASK 0x1F993 1068: #define A6XX_GMU_HOST2GMU_INTR_SET 0x1F994 1069: #define A6XX_GMU_HOST2GMU_INTR_CLR 0x1F995 1070: #define A6XX_GMU_HOST2GMU_INTR_RAW_INFO 0x1F996 1071: #define A6XX_GMU_HOST2GMU_INTR_EN_0 0x1F997 1072: #define A6XX_GMU_HOST2GMU_INTR_EN_1 0x1F998 1073: #define A6XX_GMU_HOST2GMU_INTR_EN_2 0x1F999 1074: #define A6XX_GMU_HOST2GMU_INTR_EN_3 0x1F99A 1075: #define A6XX_GMU_HOST2GMU_INTR_INFO_0 0x1F99B 1076: #define A6XX_GMU_HOST2GMU_INTR_INFO_1 0x1F99C 1077: #define A6XX_GMU_HOST2GMU_INTR_INFO_2 0x1F99D 1078: #define A6XX_GMU_HOST2GMU_INTR_INFO_3 0x1F99E 1079: #define A6XX_GMU_GENERAL_0 0x1F9C5 1080: #define A6XX_GMU_GENERAL_1 0x1F9C6 --- FILE: \adreno-gpulist.h | HITS: 105 --- MATCH LINES: 137, 164 125: {A5XX_RBBM_CLOCK_DELAY_VFD, 0x00002222}, 126: }; 127: 128: /* VBIF control registers for a530, a510, a508, a505 and a506 */ 129: static const struct kgsl_regmap_list a530_vbif_regs[] = { 130: {A5XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x00000003}, 131: }; 132: 133: static const struct adreno_a5xx_core adreno_gpu_core_a530v2 = { 134: .base = { 135: DEFINE_ADRENO_REV(ADRENO_REV_A530, 5, 3, 0, 1), 136: .features = ADRENO_SPTP_PC | ADRENO_LM | 137: ADRENO_PREEMPTION | 138: ADRENO_CONTENT_PROTECTION, 139: .gpudev = &adreno_a5xx_gpudev, 140: .perfcounters = &adreno_a5xx_perfcounters, 141: .uche_gmem_alignment = SZ_1M, 142: .gmem_size = SZ_1M, 143: .bus_width = 32, 144: .snapshot_size = SZ_1M, 145: .highest_bank_bit = 15, 146: }, 147: .gpmu_tsens = 0x00060007, 148: .max_power = 5448, 149: .pm4fw_name = "a530_pm4.fw", 150: .pfpfw_name = "a530_pfp.fw", 151: .gpmufw_name = "a530_gpmu.fw2", 152: .regfw_name = "a530v2_seq.fw2", 153: .zap_name = "a530_zap.mdt", 154: .hwcg = a530_hwcg_regs, 155: .hwcg_count = ARRAY_SIZE(a530_hwcg_regs), 156: .vbif = a530_vbif_regs, 157: .vbif_count = ARRAY_SIZE(a530_vbif_regs), 158: }; 159: 160: static const struct adreno_a5xx_core adreno_gpu_core_a530v3 = { 161: .base = { 162: DEFINE_ADRENO_REV(ADRENO_REV_A530, 5, 3, 0, ANY_ID), 163: .features = ADRENO_SPTP_PC | ADRENO_LM | 164: ADRENO_PREEMPTION | 165: ADRENO_CONTENT_PROTECTION, 166: .gpudev = &adreno_a5xx_gpudev, 167: .perfcounters = &adreno_a5xx_perfcounters, 168: .uche_gmem_alignment = SZ_1M, 169: .gmem_size = SZ_1M, 170: .bus_width = 32, 171: .snapshot_size = SZ_1M, 172: .highest_bank_bit = 15, 173: }, 174: .gpmu_tsens = 0x00060007, 175: .max_power = 5448, 176: .pm4fw_name = "a530_pm4.fw", 177: .pfpfw_name = "a530_pfp.fw", 178: .gpmufw_name = "a530v3_gpmu.fw2", 179: .regfw_name = "a530v3_seq.fw2", 180: .zap_name = "a530_zap.mdt", 181: .hwcg = a530_hwcg_regs, 182: .hwcg_count = ARRAY_SIZE(a530_hwcg_regs), 183: .vbif = a530_vbif_regs, 184: .vbif_count = ARRAY_SIZE(a530_vbif_regs), 185: }; 186: 187: /* For a505, a506 and a508 */ 188: static const struct kgsl_regmap_list a50x_hwcg_regs[] = { MATCH LINES: 232, 251 220: {A5XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00000000}, 221: {A5XX_RBBM_CLOCK_HYST_GPC, 0x04104004}, 222: {A5XX_RBBM_CLOCK_HYST_VFD, 0x00000000}, 223: {A5XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000}, 224: {A5XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000}, 225: {A5XX_RBBM_CLOCK_DELAY_GPC, 0x00000200}, 226: {A5XX_RBBM_CLOCK_DELAY_VFD, 0x00002222} 227: }; 228: 229: static const struct adreno_a5xx_core adreno_gpu_core_a505 = { 230: .base = { 231: DEFINE_ADRENO_REV(ADRENO_REV_A505, 5, 0, 5, ANY_ID), 232: .features = ADRENO_PREEMPTION, 233: .gpudev = &adreno_a5xx_gpudev, 234: .perfcounters = &adreno_a5xx_perfcounters, 235: .uche_gmem_alignment = SZ_1M, 236: .gmem_size = (SZ_128K + SZ_8K), 237: .bus_width = 16, 238: .snapshot_size = SZ_1M, 239: }, 240: .pm4fw_name = "a530_pm4.fw", 241: .pfpfw_name = "a530_pfp.fw", 242: .hwcg = a50x_hwcg_regs, 243: .hwcg_count = ARRAY_SIZE(a50x_hwcg_regs), 244: .vbif = a530_vbif_regs, 245: .vbif_count = ARRAY_SIZE(a530_vbif_regs), 246: }; 247: 248: static const struct adreno_a5xx_core adreno_gpu_core_a506 = { 249: .base = { 250: DEFINE_ADRENO_REV(ADRENO_REV_A506, 5, 0, 6, ANY_ID), 251: .features = ADRENO_PREEMPTION | 252: ADRENO_CONTENT_PROTECTION | ADRENO_CPZ_RETENTION, 253: .gpudev = &adreno_a5xx_gpudev, 254: .perfcounters = &adreno_a5xx_perfcounters, 255: .uche_gmem_alignment = SZ_1M, 256: .gmem_size = (SZ_128K + SZ_8K), 257: .bus_width = 16, 258: .snapshot_size = SZ_1M, 259: .highest_bank_bit = 14, 260: }, 261: .pm4fw_name = "a530_pm4.fw", 262: .pfpfw_name = "a530_pfp.fw", 263: .zap_name = "a506_zap.mdt", 264: .hwcg = a50x_hwcg_regs, 265: .hwcg_count = ARRAY_SIZE(a50x_hwcg_regs), 266: .vbif = a530_vbif_regs, 267: .vbif_count = ARRAY_SIZE(a530_vbif_regs), 268: }; 269: 270: static const struct kgsl_regmap_list a510_hwcg_regs[] = { 271: {A5XX_RBBM_CLOCK_CNTL_SP0, 0x02222222}, 272: {A5XX_RBBM_CLOCK_CNTL_SP1, 0x02222222}, 273: {A5XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220}, 274: {A5XX_RBBM_CLOCK_CNTL2_SP1, 0x02222220}, 275: {A5XX_RBBM_CLOCK_HYST_SP0, 0x0000F3CF}, MATCH LINES: 455 443: {A5XX_RBBM_CLOCK_DELAY_GPMU, 0x00000770}, 444: {A5XX_RBBM_CLOCK_HYST_GPMU, 0x00000004}, 445: }; 446: 447: static const struct kgsl_regmap_list a540_vbif_regs[] = { 448: {A5XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x00000003}, 449: {A5XX_VBIF_GATE_OFF_WRREQ_EN, 0x00000009}, 450: }; 451: 452: static const struct adreno_a5xx_core adreno_gpu_core_a540v2 = { 453: .base = { 454: DEFINE_ADRENO_REV(ADRENO_REV_A540, 5, 4, 0, ANY_ID), 455: .features = ADRENO_PREEMPTION | 456: ADRENO_CONTENT_PROTECTION | 457: ADRENO_SPTP_PC, 458: .gpudev = &adreno_a5xx_gpudev, 459: .perfcounters = &adreno_a5xx_perfcounters, 460: .uche_gmem_alignment = SZ_1M, 461: .gmem_size = SZ_1M, 462: .bus_width = 32, 463: .snapshot_size = SZ_1M, 464: .highest_bank_bit = 15, 465: }, 466: .gpmu_tsens = 0x000c000d, 467: .max_power = 5448, 468: .pm4fw_name = "a530_pm4.fw", 469: .pfpfw_name = "a530_pfp.fw", 470: .gpmufw_name = "a540_gpmu.fw2", 471: .zap_name = "a540_zap.mdt", 472: .hwcg = a540_hwcg_regs, 473: .hwcg_count = ARRAY_SIZE(a540_hwcg_regs), 474: .vbif = a540_vbif_regs, 475: .vbif_count = ARRAY_SIZE(a540_vbif_regs), 476: }; 477: 478: static const struct kgsl_regmap_list a512_hwcg_regs[] = { 479: {A5XX_RBBM_CLOCK_CNTL_SP0, 0x02222222}, MATCH LINES: 540, 560 528: {A5XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00000000}, 529: {A5XX_RBBM_CLOCK_HYST_GPC, 0x04104004}, 530: {A5XX_RBBM_CLOCK_HYST_VFD, 0x00000000}, 531: {A5XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000}, 532: {A5XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000}, 533: {A5XX_RBBM_CLOCK_DELAY_GPC, 0x00000200}, 534: {A5XX_RBBM_CLOCK_DELAY_VFD, 0x00002222}, 535: }; 536: 537: static const struct adreno_a5xx_core adreno_gpu_core_a512 = { 538: .base = { 539: DEFINE_ADRENO_REV(ADRENO_REV_A512, 5, 1, 2, ANY_ID), 540: .features = ADRENO_PREEMPTION | 541: ADRENO_CONTENT_PROTECTION | ADRENO_CPZ_RETENTION, 542: .gpudev = &adreno_a5xx_gpudev, 543: .perfcounters = &adreno_a5xx_perfcounters, 544: .uche_gmem_alignment = SZ_1M, 545: .gmem_size = (SZ_256K + SZ_16K), 546: .bus_width = 32, 547: .snapshot_size = SZ_1M, 548: .highest_bank_bit = 14, 549: }, 550: .pm4fw_name = "a530_pm4.fw", 551: .pfpfw_name = "a530_pfp.fw", 552: .zap_name = "a512_zap.mdt", 553: .hwcg = a512_hwcg_regs, 554: .hwcg_count = ARRAY_SIZE(a512_hwcg_regs), 555: }; 556: 557: static const struct adreno_a5xx_core adreno_gpu_core_a508 = { 558: .base = { 559: DEFINE_ADRENO_REV(ADRENO_REV_A508, 5, 0, 8, ANY_ID), 560: .features = ADRENO_PREEMPTION | 561: ADRENO_CONTENT_PROTECTION | ADRENO_CPZ_RETENTION, 562: .gpudev = &adreno_a5xx_gpudev, 563: .perfcounters = &adreno_a5xx_perfcounters, 564: .uche_gmem_alignment = SZ_1M, 565: .gmem_size = (SZ_128K + SZ_8K), 566: .bus_width = 32, 567: .snapshot_size = SZ_1M, 568: .highest_bank_bit = 14, 569: }, 570: .pm4fw_name = "a530_pm4.fw", 571: .pfpfw_name = "a530_pfp.fw", 572: .zap_name = "a508_zap.mdt", 573: .hwcg = a50x_hwcg_regs, 574: .hwcg_count = ARRAY_SIZE(a50x_hwcg_regs), 575: .vbif = a530_vbif_regs, 576: .vbif_count = ARRAY_SIZE(a530_vbif_regs), 577: }; 578: 579: DEFINE_DEPRECATED_CORE(a630v1, ADRENO_REV_A630, 6, 3, 0, 0); 580: 581: static const struct kgsl_regmap_list a630_hwcg_regs[] = { 582: {A6XX_RBBM_CLOCK_CNTL_SP0, 0x02222222}, 583: {A6XX_RBBM_CLOCK_CNTL_SP1, 0x02222222}, 584: {A6XX_RBBM_CLOCK_CNTL_SP2, 0x02222222}, MATCH LINES: 736 724: { A6XX_CP_PROTECT_REG + 27, 0x0be02, 0x0be03, 1 }, 725: { A6XX_CP_PROTECT_REG + 28, 0x0be20, 0x0d5ff, 1 }, 726: { A6XX_CP_PROTECT_REG + 29, 0x0f000, 0x0fbff, 1 }, 727: { A6XX_CP_PROTECT_REG + 30, 0x0fc00, 0x11bff, 0 }, 728: { A6XX_CP_PROTECT_REG + 31, 0x11c00, 0x11c00, 1 }, 729: { 0 }, 730: }; 731: 732: static const struct adreno_a6xx_core adreno_gpu_core_a630v2 = { 733: .base = { 734: DEFINE_ADRENO_REV(ADRENO_REV_A630, 6, 3, 0, ANY_ID), 735: .features = ADRENO_IFPC | ADRENO_CONTENT_PROTECTION | 736: ADRENO_IOCOHERENT | ADRENO_PREEMPTION, 737: .gpudev = &adreno_a630_gpudev.base, 738: .perfcounters = &adreno_a630_perfcounters, 739: .uche_gmem_alignment = SZ_1M, 740: .gmem_size = SZ_1M, 741: .bus_width = 32, 742: .snapshot_size = SZ_1M, 743: .highest_bank_bit = 15, 744: }, 745: .prim_fifo_threshold = 0x0018000, 746: .gmu_major = 1, 747: .gmu_minor = 3, 748: .sqefw_name = "a630_sqe.fw", 749: .gmufw_name = "a630_gmu.bin", 750: .zap_name = "a630_zap.mdt", 751: .hwcg = a630_hwcg_regs, 752: .hwcg_count = ARRAY_SIZE(a630_hwcg_regs), 753: .vbif = a630_vbif_regs, 754: .vbif_count = ARRAY_SIZE(a630_vbif_regs), 755: .hang_detect_cycles = 0xcfffff, 756: .protected_regs = a630_protected_regs, 757: }; 758: 759: /* For a615, a616, a618 and a619 */ 760: static const struct kgsl_regmap_list a615_hwcg_regs[] = { MATCH LINES: 834, 862, 890, 919 822: {A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111}, 823: {A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555} 824: }; 825: 826: /* For a615, a616, a618 and a619 */ 827: static const struct kgsl_regmap_list a615_gbif_regs[] = { 828: {A6XX_RBBM_VBIF_CLIENT_QOS_CNTL, 0x3}, 829: }; 830: 831: static const struct adreno_a6xx_core adreno_gpu_core_a615 = { 832: .base = { 833: DEFINE_ADRENO_REV(ADRENO_REV_A615, 6, 1, 5, ANY_ID), 834: .features = ADRENO_PREEMPTION | 835: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | 836: ADRENO_IOCOHERENT, 837: .gpudev = &adreno_a630_gpudev.base, 838: .perfcounters = &adreno_a6xx_legacy_perfcounters, 839: .uche_gmem_alignment = SZ_1M, 840: .gmem_size = SZ_512K, 841: .bus_width = 32, 842: .snapshot_size = SZ_1M, 843: .highest_bank_bit = 14, 844: }, 845: .prim_fifo_threshold = 0x0018000, 846: .gmu_major = 1, 847: .gmu_minor = 3, 848: .sqefw_name = "a630_sqe.fw", 849: .gmufw_name = "a630_gmu.bin", 850: .zap_name = "a615_zap.mdt", 851: .hwcg = a615_hwcg_regs, 852: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs), 853: .vbif = a615_gbif_regs, 854: .vbif_count = ARRAY_SIZE(a615_gbif_regs), 855: .hang_detect_cycles = 0xcfffff, 856: .protected_regs = a630_protected_regs, 857: }; 858: 859: static const struct adreno_a6xx_core adreno_gpu_core_a618 = { 860: .base = { 861: DEFINE_ADRENO_REV(ADRENO_REV_A618, 6, 1, 8, ANY_ID), 862: .features = ADRENO_PREEMPTION | 863: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | 864: ADRENO_IOCOHERENT, 865: .gpudev = &adreno_a630_gpudev.base, 866: .perfcounters = &adreno_a6xx_legacy_perfcounters, 867: .uche_gmem_alignment = SZ_1M, 868: .gmem_size = SZ_512K, 869: .bus_width = 32, 870: .snapshot_size = SZ_1M, 871: .highest_bank_bit = 14, 872: }, 873: .prim_fifo_threshold = 0x0018000, 874: .gmu_major = 1, 875: .gmu_minor = 7, 876: .sqefw_name = "a630_sqe.fw", 877: .gmufw_name = "a630_gmu.bin", 878: .zap_name = "a615_zap.mdt", 879: .hwcg = a615_hwcg_regs, 880: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs), 881: .vbif = a615_gbif_regs, 882: .vbif_count = ARRAY_SIZE(a615_gbif_regs), 883: .hang_detect_cycles = 0x3fffff, 884: .protected_regs = a630_protected_regs, 885: }; 886: 887: static const struct adreno_a6xx_core adreno_gpu_core_a619 = { 888: .base = { 889: DEFINE_ADRENO_REV(ADRENO_REV_A619, 6, 1, 9, ANY_ID), 890: .features = ADRENO_PREEMPTION | 891: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | 892: ADRENO_IOCOHERENT, 893: .gpudev = &adreno_a630_gpudev.base, 894: .perfcounters = &adreno_a6xx_legacy_perfcounters, 895: .uche_gmem_alignment = SZ_1M, 896: .gmem_size = SZ_512K, 897: .bus_width = 32, 898: .snapshot_size = SZ_2M, 899: .highest_bank_bit = 14, 900: }, 901: .prim_fifo_threshold = 0x0018000, 902: .gmu_major = 1, 903: .gmu_minor = 9, 904: .sqefw_name = "a630_sqe.fw", 905: .gmufw_name = "a619_gmu.bin", 906: .zap_name = "a615_zap.mdt", 907: .hwcg = a615_hwcg_regs, 908: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs), 909: .vbif = a615_gbif_regs, 910: .vbif_count = ARRAY_SIZE(a615_gbif_regs), 911: .hang_detect_cycles = 0x3fffff, 912: .protected_regs = a630_protected_regs, 913: }; 914: 915: static const struct adreno_a6xx_core adreno_gpu_core_a619_variant = { 916: .base = { 917: DEFINE_ADRENO_REV(ADRENO_REV_A619, 6, 1, 9, ANY_ID), 918: .compatible = "qcom,adreno-gpu-a619-holi", 919: .features = ADRENO_PREEMPTION | ADRENO_CONTENT_PROTECTION, 920: .gpudev = &adreno_a619_holi_gpudev, 921: .perfcounters = &adreno_a6xx_legacy_perfcounters, 922: .uche_gmem_alignment = SZ_1M, 923: .gmem_size = SZ_512K, 924: .bus_width = 32, 925: .snapshot_size = SZ_2M, 926: .highest_bank_bit = 14, 927: }, 928: .prim_fifo_threshold = 0x0018000, 929: .sqefw_name = "a630_sqe.fw", 930: .zap_name = "gen6_3_25_0_zap.mdt", 931: .hwcg = a615_hwcg_regs, 932: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs), 933: .vbif = a615_gbif_regs, 934: .vbif_count = ARRAY_SIZE(a615_gbif_regs), 935: .hang_detect_cycles = 0x3fffff, 936: .protected_regs = a630_protected_regs, 937: .gx_cpr_toggle = true, 938: }; 939: 940: static const struct kgsl_regmap_list a620_hwcg_regs[] = { 941: {A6XX_RBBM_CLOCK_CNTL_SP0, 0x02222222}, 942: {A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220}, 943: {A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000080}, MATCH LINES: 1050, 1081, 1114 1038: { A6XX_CP_PROTECT_REG + 35, 0x1c800, 0x1e7ff, 1 }, 1039: { A6XX_CP_PROTECT_REG + 36, 0x1f400, 0x1f843, 1 }, 1040: { A6XX_CP_PROTECT_REG + 37, 0x1f844, 0x1f8bf, 0 }, 1041: { A6XX_CP_PROTECT_REG + 38, 0x1f887, 0x1f8a2, 1 }, 1042: { A6XX_CP_PROTECT_REG + 47, 0x1f8c0, 0x1f8c0, 1 }, 1043: { 0 }, 1044: }; 1045: 1046: static const struct adreno_a6xx_core adreno_gpu_core_a620 = { 1047: .base = { 1048: DEFINE_ADRENO_REV(ADRENO_REV_A620, 6, 2, 0, ANY_ID), 1049: .features = ADRENO_CONTENT_PROTECTION | ADRENO_IOCOHERENT | 1050: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_ACD | 1051: ADRENO_APRIV, 1052: .gpudev = &adreno_a630_gpudev.base, 1053: .perfcounters = &adreno_a6xx_perfcounters, 1054: .uche_gmem_alignment = 0, 1055: .gmem_size = SZ_512K, 1056: .bus_width = 32, 1057: .snapshot_size = 2 * SZ_1M, 1058: .highest_bank_bit = 14, 1059: }, 1060: .prim_fifo_threshold = 0x0010000, 1061: .gmu_major = 2, 1062: .gmu_minor = 0, 1063: .sqefw_name = "a650_sqe.fw", 1064: .gmufw_name = "a650_gmu.bin", 1065: .zap_name = "a620_zap.mdt", 1066: .hwcg = a620_hwcg_regs, 1067: .hwcg_count = ARRAY_SIZE(a620_hwcg_regs), 1068: .vbif = a650_gbif_regs, 1069: .vbif_count = ARRAY_SIZE(a650_gbif_regs), 1070: .veto_fal10 = true, 1071: .hang_detect_cycles = 0x3ffff, 1072: .protected_regs = a620_protected_regs, 1073: .disable_tseskip = true, 1074: }; 1075: 1076: static const struct adreno_a6xx_core adreno_gpu_core_a621 = { 1077: .base = { 1078: DEFINE_ADRENO_REV(ADRENO_REV_A621, 6, 2, 1, ANY_ID), 1079: .compatible = "qcom,adreno-gpu-a621", 1080: .features = ADRENO_CONTENT_PROTECTION | ADRENO_IOCOHERENT | 1081: ADRENO_APRIV | ADRENO_LSR | ADRENO_PREEMPTION | 1082: ADRENO_IFPC | ADRENO_ACD | ADRENO_BCL, 1083: .gpudev = &adreno_a6xx_hwsched_gpudev.base, 1084: .perfcounters = &adreno_a6xx_perfcounters, 1085: .uche_gmem_alignment = 0, 1086: .gmem_size = SZ_512K, 1087: .bus_width = 32, 1088: .snapshot_size = 2 * SZ_1M, 1089: .highest_bank_bit = 13, 1090: }, 1091: .prim_fifo_threshold = 0x0010000, 1092: .gmu_major = 2, 1093: .gmu_minor = 0, 1094: .sqefw_name = "a650_sqe.fw", 1095: .gmufw_name = "a621_gmu.bin", 1096: .zap_name = "a620_zap.mdt", 1097: .hwcg = a620_hwcg_regs, 1098: .hwcg_count = ARRAY_SIZE(a620_hwcg_regs), 1099: .vbif = a650_gbif_regs, 1100: .vbif_count = ARRAY_SIZE(a650_gbif_regs), 1101: .veto_fal10 = true, 1102: .pdc_in_aop = true, 1103: .hang_detect_cycles = 0x3ffff, 1104: .protected_regs = a620_protected_regs, 1105: .disable_tseskip = true, 1106: .gmu_hub_clk_freq = 200000000, 1107: }; 1108: 1109: static const struct adreno_a6xx_core adreno_gpu_core_a622 = { 1110: .base = { 1111: DEFINE_ADRENO_REV(ADRENO_REV_A622, 6, 2, 2, ANY_ID), 1112: .compatible = "qcom,adreno-gpu-a622", 1113: .features = ADRENO_CONTENT_PROTECTION | ADRENO_IOCOHERENT | 1114: ADRENO_APRIV | ADRENO_PREEMPTION | ADRENO_BCL | 1115: ADRENO_IFPC, 1116: .gpudev = &adreno_a6xx_hwsched_gpudev.base, 1117: .perfcounters = &adreno_a6xx_perfcounters, 1118: .uche_gmem_alignment = 0, 1119: .gmem_size = SZ_512K, 1120: .bus_width = 32, 1121: .snapshot_size = 2 * SZ_1M, 1122: .highest_bank_bit = 14, 1123: }, 1124: .prim_fifo_threshold = 0x0010000, 1125: .gmu_major = 2, 1126: .gmu_minor = 0, 1127: .sqefw_name = "a650_sqe.fw", 1128: .gmufw_name = "a622_gmu.bin", 1129: .zap_name = "a622_zap.mdt", 1130: .hwcg = a620_hwcg_regs, 1131: .hwcg_count = ARRAY_SIZE(a620_hwcg_regs), 1132: .vbif = a650_gbif_regs, 1133: .vbif_count = ARRAY_SIZE(a650_gbif_regs), 1134: .veto_fal10 = true, 1135: .pdc_in_aop = true, 1136: .hang_detect_cycles = 0x3ffff, 1137: .protected_regs = a620_protected_regs, 1138: .disable_tseskip = true, MATCH LINES: 1259 1247: static const struct kgsl_regmap_list a640_vbif_regs[] = { 1248: {A6XX_GBIF_QSB_SIDE0, 0x00071620}, 1249: {A6XX_GBIF_QSB_SIDE1, 0x00071620}, 1250: {A6XX_GBIF_QSB_SIDE2, 0x00071620}, 1251: {A6XX_GBIF_QSB_SIDE3, 0x00071620}, 1252: {A6XX_RBBM_GBIF_CLIENT_QOS_CNTL, 0x3}, 1253: }; 1254: 1255: static const struct adreno_a6xx_core adreno_gpu_core_a640 = { 1256: .base = { 1257: DEFINE_ADRENO_REV(ADRENO_REV_A640, 6, 4, 0, ANY_ID), 1258: .features = ADRENO_CONTENT_PROTECTION | ADRENO_IOCOHERENT | 1259: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_L3_VOTE, 1260: .gpudev = &adreno_a6xx_gmu_gpudev.base, 1261: .perfcounters = &adreno_a6xx_legacy_perfcounters, 1262: .uche_gmem_alignment = SZ_1M, 1263: .gmem_size = SZ_1M, //Verified 1MB 1264: .bus_width = 32, 1265: .snapshot_size = 2 * SZ_1M, 1266: .highest_bank_bit = 15, 1267: }, 1268: .prim_fifo_threshold = 0x00200000, 1269: .gmu_major = 2, 1270: .gmu_minor = 0, 1271: .sqefw_name = "a630_sqe.fw", 1272: .gmufw_name = "a640_gmu.bin", 1273: .zap_name = "a640_zap.mdt", 1274: .hwcg = a640_hwcg_regs, 1275: .hwcg_count = ARRAY_SIZE(a640_hwcg_regs), 1276: .vbif = a640_vbif_regs, 1277: .vbif_count = ARRAY_SIZE(a640_vbif_regs), 1278: .hang_detect_cycles = 0xcfffff, 1279: .protected_regs = a630_protected_regs, 1280: .disable_tseskip = true, 1281: }; 1282: 1283: static const struct kgsl_regmap_list a650_hwcg_regs[] = { MATCH LINES: 1369, 1400 1357: .vbif_count = ARRAY_SIZE(a650_gbif_regs), 1358: .veto_fal10 = true, 1359: .pdc_in_aop = true, 1360: .hang_detect_cycles = 0xcfffff, 1361: .protected_regs = a620_protected_regs, 1362: .disable_tseskip = true, 1363: }; 1364: 1365: static const struct adreno_a6xx_core adreno_gpu_core_a650v2 = { 1366: .base = { 1367: DEFINE_ADRENO_REV(ADRENO_REV_A650, 6, 5, 0, ANY_ID), 1368: .features = ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION | 1369: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_ACD | 1370: ADRENO_LM | ADRENO_APRIV | ADRENO_L3_VOTE, 1371: .gpudev = &adreno_a6xx_gmu_gpudev.base, 1372: .perfcounters = &adreno_a6xx_perfcounters, 1373: .uche_gmem_alignment = 0, 1374: .gmem_size = SZ_1M + SZ_128K, /* verified 1152kB */ 1375: .bus_width = 32, 1376: .snapshot_size = 2 * SZ_1M, 1377: .highest_bank_bit = 16, 1378: }, 1379: .prim_fifo_threshold = 0x00300000, 1380: .gmu_major = 2, 1381: .gmu_minor = 0, 1382: .sqefw_name = "a650_sqe.fw", 1383: .gmufw_name = "a650_gmu.bin", 1384: .zap_name = "a650_zap.mdt", 1385: .hwcg = a650_hwcg_regs, 1386: .hwcg_count = ARRAY_SIZE(a650_hwcg_regs), 1387: .vbif = a650_gbif_regs, 1388: .vbif_count = ARRAY_SIZE(a650_gbif_regs), 1389: .veto_fal10 = true, 1390: .pdc_in_aop = true, 1391: .hang_detect_cycles = 0x3ffff, 1392: .protected_regs = a620_protected_regs, 1393: .disable_tseskip = true, 1394: }; 1395: 1396: static const struct adreno_a6xx_core adreno_gpu_core_a680 = { 1397: .base = { 1398: DEFINE_ADRENO_REV(ADRENO_REV_A680, 6, 8, 0, ANY_ID), 1399: .features = ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION | 1400: ADRENO_IFPC | ADRENO_PREEMPTION, 1401: .gpudev = &adreno_a6xx_gmu_gpudev.base, 1402: .perfcounters = &adreno_a6xx_legacy_perfcounters, 1403: .uche_gmem_alignment = SZ_1M, 1404: .gmem_size = SZ_2M, 1405: .bus_width = 32, 1406: .snapshot_size = SZ_2M, 1407: .highest_bank_bit = 16, 1408: }, 1409: .prim_fifo_threshold = 0x00400000, 1410: .gmu_major = 2, 1411: .gmu_minor = 0, 1412: .sqefw_name = "a630_sqe.fw", 1413: .gmufw_name = "a640_gmu.bin", 1414: .zap_name = "a640_zap.mdt", 1415: .hwcg = a680_hwcg_regs, 1416: .hwcg_count = ARRAY_SIZE(a680_hwcg_regs), 1417: .vbif = a640_vbif_regs, 1418: .vbif_count = ARRAY_SIZE(a640_vbif_regs), 1419: .hang_detect_cycles = 0xcfffff, 1420: .protected_regs = a630_protected_regs, 1421: .disable_tseskip = true, 1422: }; 1423: 1424: static const struct kgsl_regmap_list a612_hwcg_regs[] = { MATCH LINES: 1477, 1504, 1533, 1558 1465: {A6XX_RBBM_ISDB_CNT, 0x00000182}, 1466: {A6XX_RBBM_RAC_THRESHOLD_CNT, 0x00000000}, 1467: {A6XX_RBBM_SP_HYST_CNT, 0x00000000}, 1468: {A6XX_RBBM_CLOCK_CNTL_GMU_GX, 0x00000222}, 1469: {A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111}, 1470: {A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555}, 1471: }; 1472: 1473: static const struct adreno_a6xx_core adreno_gpu_core_a612 = { 1474: .base = { 1475: DEFINE_ADRENO_REV(ADRENO_REV_A612, 6, 1, 2, ANY_ID), 1476: .features = ADRENO_CONTENT_PROTECTION | 1477: ADRENO_IOCOHERENT | ADRENO_PREEMPTION | ADRENO_IFPC, 1478: .gpudev = &adreno_a6xx_rgmu_gpudev, 1479: .perfcounters = &adreno_a6xx_legacy_perfcounters, 1480: .uche_gmem_alignment = SZ_1M, 1481: .gmem_size = (SZ_128K + SZ_4K), 1482: .bus_width = 32, 1483: .snapshot_size = SZ_1M, 1484: .chipid = 0x06010200, 1485: .ubwc_mode = 2, 1486: .mal = 32, 1487: .highest_bank_bit = 14, 1488: }, 1489: .prim_fifo_threshold = 0x00080000, 1490: .sqefw_name = "a630_sqe.fw", 1491: .gmufw_name = "a612_rgmu.bin", 1492: .zap_name = "a612_zap.mbn", 1493: .hwcg = a612_hwcg_regs, 1494: .hwcg_count = ARRAY_SIZE(a612_hwcg_regs), 1495: .vbif = a640_vbif_regs, 1496: .vbif_count = ARRAY_SIZE(a640_vbif_regs), 1497: .hang_detect_cycles = 0x3fffff, 1498: .protected_regs = a630_protected_regs, 1499: }; 1500: 1501: static const struct adreno_a6xx_core adreno_gpu_core_a616 = { 1502: .base = { 1503: DEFINE_ADRENO_REV(ADRENO_REV_A616, 6, 1, 6, ANY_ID), 1504: .features = ADRENO_PREEMPTION | 1505: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | 1506: ADRENO_IOCOHERENT, 1507: .gpudev = &adreno_a630_gpudev.base, 1508: .perfcounters = &adreno_a6xx_legacy_perfcounters, 1509: .uche_gmem_alignment = SZ_1M, 1510: .gmem_size = SZ_512K, 1511: .bus_width = 32, 1512: .snapshot_size = SZ_1M, 1513: .highest_bank_bit = 14, 1514: }, 1515: .prim_fifo_threshold = 0x0018000, 1516: .gmu_major = 1, 1517: .gmu_minor = 3, 1518: .sqefw_name = "a630_sqe.fw", 1519: .gmufw_name = "a630_gmu.bin", 1520: .zap_name = "a615_zap.mdt", 1521: .hwcg = a615_hwcg_regs, 1522: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs), 1523: .vbif = a615_gbif_regs, 1524: .vbif_count = ARRAY_SIZE(a615_gbif_regs), 1525: .hang_detect_cycles = 0xcfffff, 1526: .protected_regs = a630_protected_regs, 1527: }; 1528: 1529: static const struct adreno_a6xx_core adreno_gpu_core_a610 = { 1530: .base = { 1531: DEFINE_ADRENO_REV(ADRENO_REV_A610, 6, 1, 0, ANY_ID), 1532: .features = ADRENO_CONTENT_PROTECTION | 1533: ADRENO_PREEMPTION, 1534: .gpudev = &adreno_a6xx_gpudev, 1535: .perfcounters = &adreno_a6xx_legacy_perfcounters, 1536: .uche_gmem_alignment = SZ_1M, 1537: .gmem_size = (SZ_128K + SZ_4K), 1538: .bus_width = 32, 1539: .snapshot_size = SZ_1M, 1540: .highest_bank_bit = 14, 1541: }, 1542: .prim_fifo_threshold = 0x00080000, 1543: .sqefw_name = "a630_sqe.fw", 1544: .zap_name = "a610_zap.mdt", 1545: .hwcg = a612_hwcg_regs, 1546: .hwcg_count = ARRAY_SIZE(a612_hwcg_regs), 1547: .vbif = a640_vbif_regs, 1548: .vbif_count = ARRAY_SIZE(a640_vbif_regs), 1549: .hang_detect_cycles = 0x3ffff, 1550: .protected_regs = a630_protected_regs, 1551: }; 1552: 1553: static const struct adreno_a6xx_core adreno_gpu_core_a611 = { 1554: .base = { 1555: DEFINE_ADRENO_REV(ADRENO_REV_A611, 6, 1, 1, ANY_ID), 1556: .compatible = "qcom,adreno-gpu-a611", 1557: .features = ADRENO_CONTENT_PROTECTION | 1558: ADRENO_PREEMPTION, 1559: .gpudev = &adreno_a6xx_gpudev, 1560: .perfcounters = &adreno_a6xx_legacy_perfcounters, 1561: .uche_gmem_alignment = SZ_1M, 1562: .gmem_size = (SZ_128K + SZ_4K), 1563: .bus_width = 32, 1564: .snapshot_size = SZ_1M, 1565: .highest_bank_bit = 14, 1566: }, 1567: .prim_fifo_threshold = 0x00080000, 1568: .sqefw_name = "a630_sqe.fw", 1569: .zap_name = "a610_zap.mbn", 1570: .hwcg = a612_hwcg_regs, 1571: .hwcg_count = ARRAY_SIZE(a612_hwcg_regs), 1572: .vbif = a640_vbif_regs, 1573: .vbif_count = ARRAY_SIZE(a640_vbif_regs), 1574: .hang_detect_cycles = 0x3ffff, 1575: .protected_regs = a630_protected_regs, 1576: }; 1577: 1578: static const struct kgsl_regmap_list a660_hwcg_regs[] = { 1579: {A6XX_RBBM_CLOCK_CNTL_SP0, 0x02222222}, 1580: {A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220}, 1581: {A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000080}, 1582: {A6XX_RBBM_CLOCK_HYST_SP0, 0x0000F3CF}, MATCH LINES: 1682, 1714, 1748 1670: { A6XX_CP_PROTECT_REG + 38, 0x1f844, 0x1f8bf, 0 }, 1671: { A6XX_CP_PROTECT_REG + 39, 0x1f860, 0x1f860, 1 }, 1672: { A6XX_CP_PROTECT_REG + 40, 0x1f887, 0x1f8a2, 1 }, 1673: { A6XX_CP_PROTECT_REG + 47, 0x1f8c0, 0x1f8c0, 1 }, 1674: { 0 }, 1675: }; 1676: 1677: static const struct adreno_a6xx_core adreno_gpu_core_a660 = { 1678: .base = { 1679: DEFINE_ADRENO_REV(ADRENO_REV_A660, 6, 6, 0, 0), 1680: .features = ADRENO_APRIV | 1681: ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION | 1682: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_L3_VOTE, 1683: .gpudev = &adreno_a6xx_gmu_gpudev.base, 1684: .perfcounters = &adreno_a6xx_perfcounters, 1685: .uche_gmem_alignment = 0, 1686: .gmem_size = SZ_1M + SZ_512K, 1687: .bus_width = 32, 1688: .snapshot_size = SZ_2M, 1689: .highest_bank_bit = 16, 1690: }, 1691: .prim_fifo_threshold = 0x00300000, 1692: .gmu_major = 2, 1693: .gmu_minor = 0, 1694: .sqefw_name = "a660_sqe.fw", 1695: .gmufw_name = "a660_gmu.bin", 1696: .zap_name = "a660_zap.mdt", 1697: .hwcg = a660_hwcg_regs, 1698: .hwcg_count = ARRAY_SIZE(a660_hwcg_regs), 1699: .vbif = a650_gbif_regs, 1700: .vbif_count = ARRAY_SIZE(a650_gbif_regs), 1701: .hang_detect_cycles = 0xcfffff, 1702: .veto_fal10 = true, 1703: .protected_regs = a660_protected_regs, 1704: .disable_tseskip = true, 1705: .pdc_in_aop = true, 1706: .ctxt_record_size = 2496 * 1024, 1707: }; 1708: 1709: static const struct adreno_a6xx_core adreno_gpu_core_a660v2 = { 1710: .base = { 1711: DEFINE_ADRENO_REV(ADRENO_REV_A660, 6, 6, 0, ANY_ID), 1712: .features = ADRENO_APRIV | 1713: ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION | 1714: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_ACD | 1715: ADRENO_L3_VOTE, 1716: .gpudev = &adreno_a6xx_gmu_gpudev.base, 1717: .perfcounters = &adreno_a6xx_perfcounters, 1718: .uche_gmem_alignment = 0, 1719: .gmem_size = SZ_1M + SZ_512K, 1720: .bus_width = 32, 1721: .snapshot_size = SZ_2M, 1722: .highest_bank_bit = 16, 1723: }, 1724: .prim_fifo_threshold = 0x00300000, 1725: .gmu_major = 2, 1726: .gmu_minor = 0, 1727: .sqefw_name = "a660_sqe.fw", 1728: .gmufw_name = "a660_gmu.bin", 1729: .zap_name = "a660_zap.mdt", 1730: .hwcg = a660_hwcg_regs, 1731: .hwcg_count = ARRAY_SIZE(a660_hwcg_regs), 1732: .vbif = a650_gbif_regs, 1733: .vbif_count = ARRAY_SIZE(a650_gbif_regs), 1734: .hang_detect_cycles = 0xcfffff, 1735: .veto_fal10 = true, 1736: .protected_regs = a660_protected_regs, 1737: .disable_tseskip = true, 1738: .pdc_in_aop = true, 1739: .ctxt_record_size = 2496 * 1024, 1740: }; 1741: 1742: static const struct adreno_a6xx_core adreno_gpu_core_a660_shima = { 1743: .base = { 1744: DEFINE_ADRENO_REV(ADRENO_REV_A660, 6, 6, 0, ANY_ID), 1745: .compatible = "qcom,adreno-gpu-a660-shima", 1746: .features = ADRENO_APRIV | 1747: ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION | 1748: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_ACD, 1749: .gpudev = &adreno_a6xx_gmu_gpudev.base, 1750: .perfcounters = &adreno_a6xx_perfcounters, 1751: .uche_gmem_alignment = 0, 1752: .gmem_size = SZ_1M + SZ_512K, 1753: .bus_width = 32, 1754: .snapshot_size = SZ_2M, 1755: .highest_bank_bit = 15, 1756: }, 1757: .prim_fifo_threshold = 0x00300000, 1758: .gmu_major = 2, 1759: .gmu_minor = 0, 1760: .sqefw_name = "a660_sqe.fw", 1761: .gmufw_name = "a660_gmu.bin", 1762: .zap_name = "a660_zap.mdt", 1763: .hwcg = a660_hwcg_regs, 1764: .hwcg_count = ARRAY_SIZE(a660_hwcg_regs), 1765: .vbif = a650_gbif_regs, 1766: .vbif_count = ARRAY_SIZE(a650_gbif_regs), 1767: .hang_detect_cycles = 0x3ffff, 1768: .veto_fal10 = true, 1769: .protected_regs = a660_protected_regs, 1770: .disable_tseskip = true, 1771: .pdc_in_aop = true, 1772: .ctxt_record_size = 2496 * 1024, MATCH LINES: 1813 1801: .protected_regs = a660_protected_regs, 1802: .disable_tseskip = true, 1803: .pdc_in_aop = true, 1804: .ctxt_record_size = 2496 * 1024, 1805: }; 1806: 1807: static const struct adreno_a6xx_core adreno_gpu_core_a643 = { 1808: .base = { 1809: DEFINE_ADRENO_REV(ADRENO_REV_A643, ANY_ID, ANY_ID, ANY_ID, ANY_ID), 1810: .compatible = "qcom,adreno-gpu-a643", 1811: .features = ADRENO_APRIV | 1812: ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION | 1813: ADRENO_PREEMPTION | ADRENO_IFPC, 1814: .gpudev = &adreno_a6xx_gmu_gpudev.base, 1815: .perfcounters = &adreno_a6xx_perfcounters, 1816: .uche_gmem_alignment = 0, 1817: .gmem_size = SZ_512K, 1818: .bus_width = 32, 1819: .snapshot_size = SZ_2M, 1820: .chipid = 0x06030500, 1821: .speedbins = KGSL_SPEEDBINS( 1822: { 0, 0 }, 1823: { 117, 0 }, 1824: { 129, 4 }, 1825: { 172, 2 }, 1826: { 190, 1 }, 1827: ), 1828: .ubwc_mode = 3, 1829: .mal = 32, 1830: .highest_bank_bit = 15, 1831: }, 1832: .prim_fifo_threshold = 0x00200000, 1833: .gmu_major = 2, 1834: .gmu_minor = 0, 1835: .sqefw_name = "a660_sqe.fw", 1836: .gmufw_name = "a660_gmu.bin", 1837: .zap_name = "a660_zap.mbn", MATCH LINES: 1855, 1888 1843: .veto_fal10 = true, 1844: .protected_regs = a660_protected_regs, 1845: .disable_tseskip = true, 1846: .pdc_in_aop = true, 1847: .ctxt_record_size = 2496 * 1024, 1848: }; 1849: 1850: static const struct adreno_a6xx_core adreno_gpu_core_a662 = { 1851: .base = { 1852: DEFINE_ADRENO_REV(ADRENO_REV_A662, ANY_ID, ANY_ID, ANY_ID, ANY_ID), 1853: .compatible = "qcom,adreno-gpu-a662", 1854: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 1855: ADRENO_CONTENT_PROTECTION | ADRENO_PREEMPTION | 1856: ADRENO_IFPC | ADRENO_BCL | ADRENO_ACD, 1857: .gpudev = &adreno_a6xx_gmu_gpudev.base, 1858: .perfcounters = &adreno_a6xx_perfcounters, 1859: .uche_gmem_alignment = 0, 1860: .gmem_size = SZ_1M + SZ_512K, 1861: .bus_width = 32, 1862: .snapshot_size = SZ_2M, 1863: .highest_bank_bit = 15, 1864: }, 1865: .prim_fifo_threshold = 0x00300000, 1866: .gmu_major = 2, 1867: .gmu_minor = 0, 1868: .sqefw_name = "a660_sqe.fw", 1869: .gmufw_name = "a662_gmu.bin", 1870: .zap_name = "a662_zap.mdt", 1871: .hwcg = a660_hwcg_regs, 1872: .hwcg_count = ARRAY_SIZE(a660_hwcg_regs), 1873: .vbif = a650_gbif_regs, 1874: .vbif_count = ARRAY_SIZE(a650_gbif_regs), 1875: .hang_detect_cycles = 0x3ffff, 1876: .veto_fal10 = true, 1877: .protected_regs = a660_protected_regs, 1878: .disable_tseskip = true, 1879: .pdc_in_aop = true, 1880: .ctxt_record_size = 2496 * 1024, 1881: }; 1882: 1883: static const struct adreno_a6xx_core adreno_gpu_core_gen6_3_26_0 = { 1884: .base = { 1885: DEFINE_ADRENO_REV(ADRENO_REV_GEN6_3_26_0, ANY_ID, ANY_ID, ANY_ID, ANY_ID), 1886: .compatible = "qcom,adreno-gpu-gen6-3-26-0", 1887: .features = ADRENO_CONTENT_PROTECTION | ADRENO_IOCOHERENT | 1888: ADRENO_PREEMPTION, 1889: .gpudev = &adreno_a6xx_gpudev, 1890: .perfcounters = &adreno_a6xx_legacy_perfcounters, 1891: .uche_gmem_alignment = SZ_1M, 1892: .gmem_size = (SZ_128K + SZ_4K), 1893: .bus_width = 32, 1894: .snapshot_size = SZ_2M, 1895: .highest_bank_bit = 15, 1896: }, 1897: .prim_fifo_threshold = 0x00080000, 1898: .sqefw_name = "a630_sqe.fw", 1899: .zap_name = "gen6_3_26_0_zap.mdt", 1900: .hwcg = a612_hwcg_regs, 1901: .hwcg_count = ARRAY_SIZE(a612_hwcg_regs), 1902: .vbif = a640_vbif_regs, 1903: .vbif_count = ARRAY_SIZE(a640_vbif_regs), 1904: .hang_detect_cycles = 0x3fffff, 1905: .protected_regs = a630_protected_regs, 1906: }; 1907: 1908: extern const struct gen7_snapshot_block_list gen7_0_0_snapshot_block_list; 1909: 1910: static const struct kgsl_regmap_list gen7_0_0_gbif_cx_regs[] = { 1911: { GEN7_GBIF_QSB_SIDE0, 0x00071620 }, 1912: { GEN7_GBIF_QSB_SIDE1, 0x00071620 }, MATCH LINES: 1979, 2017 1967: {A6XX_RBBM_CLOCK_CNTL_GLC, 0x00222222}, 1968: {A6XX_RBBM_CLOCK_DELAY_GLC, 0x00000000}, 1969: {A6XX_RBBM_CLOCK_HYST_GLC, 0x00000000}, 1970: {A6XX_RBBM_CLOCK_CNTL_MHUB, 0x00000002}, 1971: {A6XX_RBBM_CLOCK_DELAY_MHUB, 0x00000000}, 1972: {A6XX_RBBM_CLOCK_HYST_MHUB, 0x00000000}, 1973: }; 1974: 1975: static const struct adreno_a6xx_core adreno_gpu_core_a702 = { 1976: .base = { 1977: DEFINE_ADRENO_REV(ADRENO_REV_A702, 7, 0, 2, ANY_ID), 1978: .features = ADRENO_CONTENT_PROTECTION | 1979: ADRENO_APRIV | ADRENO_PREEMPTION, 1980: .gpudev = &adreno_a6xx_gpudev, 1981: .perfcounters = &adreno_a6xx_legacy_perfcounters, 1982: .gmem_size = SZ_128K, 1983: .bus_width = 16, 1984: .snapshot_size = SZ_1M, 1985: .highest_bank_bit = 14, 1986: .chipid = 0x07000200, 1987: .speedbins = KGSL_SPEEDBINS( 1988: { 0, 0 }, 1989: { 236, 1 }, 1990: { 178, 2 }, 1991: { 142, 3 }, 1992: ), 1993: .ubwc_mode = 1, 1994: .mal = 64, 1995: }, 1996: .prim_fifo_threshold = 0x0000c000, 1997: .sqefw_name = "a702_sqe.fw", 1998: .zap_name = "a702_zap.mdt", 1999: .hwcg = a702_hwcg_regs, 2000: .hwcg_count = ARRAY_SIZE(a702_hwcg_regs), 2001: .vbif = a640_vbif_regs, 2002: .vbif_count = ARRAY_SIZE(a640_vbif_regs), 2003: .hang_detect_cycles = 0x3ffff, 2004: .protected_regs = a620_protected_regs, 2005: }; 2006: 2007: /* SMMU aperture registers: GC to context bank 0, LPAC disabled */ 2008: static const struct kgsl_regmap_list a704_smmu_aperture_regs[] = { 2009: { 0x0, 0x000a8000 }, /* GC: CB0 */ 2010: { 0x2, 0x00000000 }, /* CTRL: GC only */ 2011: }; 2012: 2013: static const struct adreno_a6xx_core adreno_gpu_core_a704 = { 2014: .base = { 2015: DEFINE_ADRENO_REV(ADRENO_REV_A704, 7, 0, 4, ANY_ID), 2016: .features = ADRENO_CONTENT_PROTECTION | 2017: ADRENO_APRIV | ADRENO_PREEMPTION, 2018: .gpudev = &adreno_a6xx_gpudev, 2019: .perfcounters = &adreno_a6xx_legacy_perfcounters, 2020: .gmem_size = SZ_128K, 2021: .bus_width = 16, 2022: .snapshot_size = SZ_1M, 2023: .highest_bank_bit = 14, 2024: .chipid = 0x07000400, 2025: .ubwc_mode = 2, 2026: .mal = 32, 2027: .gpu_model = "Adreno704v1", 2028: .smmu_aperture = a704_smmu_aperture_regs, 2029: .smmu_aperture_count = ARRAY_SIZE(a704_smmu_aperture_regs), 2030: }, 2031: .prim_fifo_threshold = 0x0000c000, 2032: .sqefw_name = "a702_sqe.fw", 2033: .zap_name = "a704_zap.mbn", 2034: .hwcg = a702_hwcg_regs, 2035: .hwcg_count = ARRAY_SIZE(a702_hwcg_regs), 2036: .vbif = a640_vbif_regs, 2037: .vbif_count = ARRAY_SIZE(a640_vbif_regs), 2038: .hang_detect_cycles = 0x3ffff, 2039: .protected_regs = a620_protected_regs, 2040: }; 2041: MATCH LINES: 2163, 2186, 2199, 2222 2151: { GEN7_CP_PROTECT_REG + 47, 0x1f8c0, 0x1f8c0, 1 }, 2152: { 0 }, 2153: }; 2154: 2155: static const struct adreno_gen7_core adreno_gpu_core_gen7_0_0 = { 2156: .base = { 2157: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_0_0, 2158: UINT_MAX, UINT_MAX, UINT_MAX, 0), 2159: .compatible = "qcom,adreno-gpu-gen7-0-0", 2160: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 2161: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | 2162: ADRENO_ACD | ADRENO_L3_VOTE | ADRENO_BCL | 2163: ADRENO_PREEMPTION, 2164: .gpudev = &adreno_gen7_gmu_gpudev.base, 2165: .perfcounters = &adreno_gen7_perfcounters, 2166: .uche_gmem_alignment = 0, 2167: .gmem_size = SZ_2M, 2168: .bus_width = 32, 2169: .snapshot_size = SZ_4M, 2170: .highest_bank_bit = 16, 2171: }, 2172: .gmu_fw_version = GMU_VERSION(4, 0, 0), 2173: .sqefw_name = "a730_sqe.fw", 2174: .gmufw_name = "gmu_gen70000.bin", 2175: .gmufw_bak_name = "c500_gmu.bin", 2176: .zap_name = "a730_zap.mdt", 2177: .hwcg = gen7_0_0_hwcg_regs, 2178: .hwcg_count = ARRAY_SIZE(gen7_0_0_hwcg_regs), 2179: .ao_hwcg = gen7_0_0_ao_hwcg_regs, 2180: .ao_hwcg_count = ARRAY_SIZE(gen7_0_0_ao_hwcg_regs), 2181: .gbif = gen7_0_0_gbif_cx_regs, 2182: .gbif_count = ARRAY_SIZE(gen7_0_0_gbif_cx_regs), 2183: .hang_detect_cycles = 0xcfffff, 2184: .protected_regs = gen7_0_0_protected_regs, 2185: .gen7_snapshot_block_list = &gen7_0_0_snapshot_block_list, 2186: .preempt_level = 1, 2187: .ctxt_record_size = (2860 * SZ_1K), 2188: .fast_bus_hint = true, 2189: }; 2190: 2191: static const struct adreno_gen7_core adreno_gpu_core_gen7_0_1 = { 2192: .base = { 2193: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_0_1, 2194: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2195: .compatible = "qcom,adreno-gpu-gen7-0-1", 2196: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 2197: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | 2198: ADRENO_ACD | ADRENO_L3_VOTE | ADRENO_BCL | 2199: ADRENO_PREEMPTION, 2200: .gpudev = &adreno_gen7_gmu_gpudev.base, 2201: .perfcounters = &adreno_gen7_perfcounters, 2202: .uche_gmem_alignment = 0, 2203: .gmem_size = SZ_2M, 2204: .bus_width = 32, 2205: .snapshot_size = SZ_4M, 2206: .highest_bank_bit = 16, 2207: }, 2208: .gmu_fw_version = GMU_VERSION(4, 0, 0), 2209: .sqefw_name = "a730_sqe.fw", 2210: .gmufw_name = "gmu_gen70000.bin", 2211: .gmufw_bak_name = "c500_gmu.bin", 2212: .zap_name = "a730_zap.mdt", 2213: .hwcg = gen7_0_0_hwcg_regs, 2214: .hwcg_count = ARRAY_SIZE(gen7_0_0_hwcg_regs), 2215: .ao_hwcg = gen7_0_0_ao_hwcg_regs, 2216: .ao_hwcg_count = ARRAY_SIZE(gen7_0_0_ao_hwcg_regs), 2217: .gbif = gen7_0_0_gbif_cx_regs, 2218: .gbif_count = ARRAY_SIZE(gen7_0_0_gbif_cx_regs), 2219: .hang_detect_cycles = 0xcfffff, 2220: .protected_regs = gen7_0_0_protected_regs, 2221: .gen7_snapshot_block_list = &gen7_0_0_snapshot_block_list, 2222: .preempt_level = 1, 2223: .ctxt_record_size = (2860 * SZ_1K), 2224: .fast_bus_hint = true, 2225: }; 2226: 2227: extern const struct gen7_snapshot_block_list gen7_2_0_snapshot_block_list; 2228: extern const struct gen7_snapshot_block_list gen7_6_0_snapshot_block_list; 2229: 2230: static const struct kgsl_regmap_list gen7_2_0_gbif_cx_regs[] = { 2231: { GEN7_GBIF_QSB_SIDE0, 0x00071e20 }, 2232: { GEN7_GBIF_QSB_SIDE1, 0x00071e20 }, 2233: { GEN7_GBIF_QSB_SIDE2, 0x00071e20 }, 2234: { GEN7_GBIF_QSB_SIDE3, 0x00071e20 }, 2235: { GEN7_GMU_CX_MRC_GBIF_QOS_CTRL, 0x33 }, 2236: }; 2237: 2238: extern const struct gen7_snapshot_block_list gen7_3_0_snapshot_block_list; 2239: 2240: static const u32 gen7_6_0_gbif_client_qos_values[KGSL_PRIORITY_MAX_RB_LEVELS] = { 2241: 0x03230323, 2242: }; 2243: 2244: static const struct kgsl_regmap_list gen7_2_0_hwcg_regs[] = { 2245: { GEN7_RBBM_CLOCK_CNTL_SP0, 0x02222222 }, 2246: { GEN7_RBBM_CLOCK_CNTL2_SP0, 0x22022222 }, MATCH LINES: 2419, 2443, 2456, 2480, 2492, 2514, 2525, 2549, 2569, 2603, 2615, 2641 2407: { GEN7_CP_PROTECT_REG + 47, 0x1f8b8, 0x1f8b8, 1 }, 2408: { 0 }, 2409: }; 2410: 2411: static const struct adreno_gen7_core adreno_gpu_core_gen7_2_0 = { 2412: .base = { 2413: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_2_0, 2414: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2415: .compatible = "qcom,adreno-gpu-gen7-2-0", 2416: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_IFPC | 2417: ADRENO_CONTENT_PROTECTION | ADRENO_ACD | 2418: ADRENO_LPAC | ADRENO_BCL | ADRENO_L3_VOTE | 2419: ADRENO_PREEMPTION | ADRENO_DMS, 2420: .gpudev = &adreno_gen7_hwsched_gpudev.base, 2421: .perfcounters = &adreno_gen7_2_0_perfcounters, 2422: .uche_gmem_alignment = SZ_16M, 2423: .gmem_size = 3 * SZ_1M, 2424: .bus_width = 32, 2425: .snapshot_size = SZ_8M, 2426: .highest_bank_bit = 16, 2427: }, 2428: .gmu_fw_version = GMU_VERSION(4, 1, 0), 2429: .sqefw_name = "a740_sqe.fw", 2430: .gmufw_name = "gmu_gen70200.bin", 2431: .zap_name = "a740_zap.mbn", 2432: .hwcg = gen7_2_0_hwcg_regs, 2433: .hwcg_count = ARRAY_SIZE(gen7_2_0_hwcg_regs), 2434: .ao_hwcg = gen7_2_0_ao_hwcg_regs, 2435: .ao_hwcg_count = ARRAY_SIZE(gen7_2_0_ao_hwcg_regs), 2436: .gbif = gen7_2_0_gbif_cx_regs, 2437: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs), 2438: .hang_detect_cycles = 0xcfffff, 2439: .protected_regs = gen7_2_0_protected_regs, 2440: .gmu_hub_clk_freq = 200000000, 2441: .gen7_snapshot_block_list = &gen7_2_0_snapshot_block_list, 2442: .bcl_data = 1, 2443: .preempt_level = 1, 2444: .ctxt_record_size = (4192 * SZ_1K), 2445: .fast_bus_hint = true, 2446: }; 2447: 2448: static const struct adreno_gen7_core adreno_gpu_core_gen7_2_1 = { 2449: .base = { 2450: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_2_1, 2451: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2452: .compatible = "qcom,adreno-gpu-gen7-2-1", 2453: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_IFPC | 2454: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | 2455: ADRENO_BCL | ADRENO_L3_VOTE | ADRENO_ACD | 2456: ADRENO_PREEMPTION | ADRENO_DMS, 2457: .gpudev = &adreno_gen7_hwsched_gpudev.base, 2458: .perfcounters = &adreno_gen7_2_0_perfcounters, 2459: .uche_gmem_alignment = SZ_16M, 2460: .gmem_size = 3 * SZ_1M, 2461: .bus_width = 32, 2462: .snapshot_size = SZ_8M, 2463: .highest_bank_bit = 16, 2464: }, 2465: .gmu_fw_version = GMU_VERSION(4, 1, 0), 2466: .sqefw_name = "a740_sqe.fw", 2467: .gmufw_name = "gmu_gen70200.bin", 2468: .zap_name = "a740_zap.mbn", 2469: .hwcg = gen7_2_0_hwcg_regs, 2470: .hwcg_count = ARRAY_SIZE(gen7_2_0_hwcg_regs), 2471: .ao_hwcg = gen7_2_0_ao_hwcg_regs, 2472: .ao_hwcg_count = ARRAY_SIZE(gen7_2_0_ao_hwcg_regs), 2473: .gbif = gen7_2_0_gbif_cx_regs, 2474: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs), 2475: .hang_detect_cycles = 0xcfffff, 2476: .protected_regs = gen7_2_0_protected_regs, 2477: .gmu_hub_clk_freq = 200000000, 2478: .gen7_snapshot_block_list = &gen7_2_0_snapshot_block_list, 2479: .bcl_data = 1, 2480: .preempt_level = 1, 2481: .ctxt_record_size = (4192 * SZ_1K), 2482: .fast_bus_hint = true, 2483: }; 2484: 2485: static const struct adreno_gen7_core adreno_gpu_core_gen7_3_0 = { 2486: .base = { 2487: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_3_0, 2488: UINT_MAX, UINT_MAX, UINT_MAX, 0), 2489: .compatible = "qcom,adreno-gpu-gen7-3-0", 2490: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 2491: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | 2492: ADRENO_PREEMPTION | ADRENO_BCL | ADRENO_ACD, 2493: .gpudev = &adreno_gen7_gmu_gpudev.base, 2494: .perfcounters = &adreno_gen7_no_cb_perfcounters, 2495: .uche_gmem_alignment = SZ_16M, 2496: .gmem_size = SZ_512K, 2497: .bus_width = 32, 2498: .snapshot_size = SZ_2M, 2499: .highest_bank_bit = 15, 2500: }, 2501: .gmu_fw_version = GMU_VERSION(4, 0, 0), 2502: .sqefw_name = "a710_sqe.fw", 2503: .gmufw_name = "gmu_gen70000.bin", 2504: .zap_name = "a710_zap.mdt", 2505: .hwcg = gen7_3_0_hwcg_regs, 2506: .hwcg_count = ARRAY_SIZE(gen7_3_0_hwcg_regs), 2507: .ao_hwcg = gen7_0_0_ao_hwcg_regs, 2508: .ao_hwcg_count = ARRAY_SIZE(gen7_0_0_ao_hwcg_regs), 2509: .gbif = gen7_0_0_gbif_cx_regs, 2510: .gbif_count = ARRAY_SIZE(gen7_0_0_gbif_cx_regs), 2511: .hang_detect_cycles = 0xcfffff, 2512: .protected_regs = gen7_0_0_protected_regs, 2513: .gen7_snapshot_block_list = &gen7_3_0_snapshot_block_list, 2514: .preempt_level = 1, 2515: .ctxt_record_size = (862 * SZ_1K), 2516: }; 2517: 2518: static const struct adreno_gen7_core adreno_gpu_core_gen7_4_0 = { 2519: .base = { 2520: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_4_0, 2521: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2522: .compatible = "qcom,adreno-gpu-gen7-4-0", 2523: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 2524: ADRENO_CONTENT_PROTECTION | ADRENO_L3_VOTE | 2525: ADRENO_PREEMPTION | ADRENO_IFPC | ADRENO_ACD | 2526: ADRENO_BCL, 2527: .gpudev = &adreno_gen7_gmu_gpudev.base, 2528: .perfcounters = &adreno_gen7_perfcounters, 2529: .uche_gmem_alignment = 0, 2530: .gmem_size = SZ_2M, 2531: .bus_width = 32, 2532: .snapshot_size = SZ_4M, 2533: .highest_bank_bit = 16, 2534: }, 2535: .gmu_fw_version = GMU_VERSION(4, 0, 7), 2536: .sqefw_name = "a730_sqe.fw", 2537: .gmufw_name = "gmu_gen70000.bin", 2538: .gmufw_bak_name = "c500_gmu.bin", 2539: .zap_name = "a730_zap.mdt", 2540: .hwcg = gen7_0_0_hwcg_regs, 2541: .hwcg_count = ARRAY_SIZE(gen7_0_0_hwcg_regs), 2542: .ao_hwcg = gen7_0_0_ao_hwcg_regs, 2543: .ao_hwcg_count = ARRAY_SIZE(gen7_0_0_ao_hwcg_regs), 2544: .gbif = gen7_0_0_gbif_cx_regs, 2545: .gbif_count = ARRAY_SIZE(gen7_0_0_gbif_cx_regs), 2546: .hang_detect_cycles = 0xcfffff, 2547: .protected_regs = gen7_0_0_protected_regs, 2548: .gen7_snapshot_block_list = &gen7_0_0_snapshot_block_list, 2549: .preempt_level = 1, 2550: .ctxt_record_size = (2860 * SZ_1K), 2551: .fast_bus_hint = true, 2552: }; 2553: 2554: static const struct kgsl_regmap_list gen7_9_0_ao_hwcg_regs[] = { 2555: { GEN7_GPU_GMU_AO_GMU_CGC_MODE_CNTL, 0x00020222 }, 2556: { GEN7_GPU_GMU_AO_GMU_CGC_DELAY_CNTL, 0x00010111 }, 2557: { GEN7_GPU_GMU_AO_GMU_CGC_HYST_CNTL, 0x00005555 }, 2558: { GEN7_GMU_CX_GMU_WFI_CONFIG, 0x00000003 }, 2559: }; 2560: 2561: extern const struct gen7_snapshot_block_list gen7_5_0_snapshot_block_list; 2562: 2563: static const struct adreno_gen7_core adreno_gpu_core_gen7_5_0 = { 2564: .base = { 2565: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_5_0, 2566: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2567: .compatible = "qcom,adreno-gpu-gen7-5-0", 2568: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_IFPC | 2569: ADRENO_PREEMPTION | ADRENO_L3_VOTE | ADRENO_DMS | ADRENO_LPAC, 2570: .gpudev = &adreno_gen7_gmu_gpudev.base, 2571: .perfcounters = &adreno_gen7_2_0_perfcounters, 2572: .uche_gmem_alignment = SZ_16M, 2573: .gmem_size = 3 * SZ_1M, 2574: .bus_width = 32, 2575: .snapshot_size = SZ_8M, 2576: .num_ddr_channels = 8, 2577: .chipid = 0x43050c01, 2578: .speedbins = KGSL_SPEEDBINS( 2579: { 0, 0 }, 2580: { 59, 1 }, 2581: { 7, 2 }, 2582: { 232, 3 }, 2583: { 146, 4 }, 2584: ), 2585: .ubwc_mode = 4, 2586: .mal = 32, 2587: .highest_bank_bit = 17, 2588: .gpu_model = "Adreno X1-85", 2589: }, 2590: .sqefw_name = "gen70500_sqe.fw", 2591: .gmufw_name = "gen70500_gmu.bin", 2592: .zap_name = "gen70500_zap.mbn", 2593: .hwcg = gen7_2_0_hwcg_regs, 2594: .hwcg_count = ARRAY_SIZE(gen7_2_0_hwcg_regs), 2595: .ao_hwcg = gen7_9_0_ao_hwcg_regs, 2596: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs), 2597: .gbif = gen7_2_0_gbif_cx_regs, 2598: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs), 2599: .hang_detect_cycles = 0xcfffff, 2600: .protected_regs = gen7_2_0_protected_regs, 2601: .gmu_hub_clk_freq = 200000000, 2602: .gen7_snapshot_block_list = &gen7_5_0_snapshot_block_list, 2603: .preempt_level = 1, 2604: .ctxt_record_size = (4192 * SZ_1K), 2605: .fast_bus_hint = true, 2606: }; 2607: 2608: static const struct adreno_gen7_core adreno_gpu_core_gen7_6_0 = { 2609: .base = { 2610: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_6_0, 2611: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2612: .compatible = "qcom,adreno-gpu-gen7-6-0", 2613: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 2614: ADRENO_CONTENT_PROTECTION | ADRENO_L3_VOTE | 2615: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_BCL | 2616: ADRENO_ACD | ADRENO_LPAC | ADRENO_DMS, 2617: .gpudev = &adreno_gen7_hwsched_gpudev.base, 2618: .perfcounters = &adreno_gen7_2_0_perfcounters, 2619: .uche_gmem_alignment = SZ_16M, 2620: .gmem_size = 3 * SZ_1M, 2621: .bus_width = 32, 2622: .snapshot_size = SZ_4M, 2623: .highest_bank_bit = 16, 2624: }, 2625: .gmu_fw_version = GMU_VERSION(4, 1, 9), 2626: .sqefw_name = "a740v3_sqe.fw", 2627: .gmufw_name = "gmu_gen70200.bin", 2628: .zap_name = "a740v3_zap.mbn", 2629: .hwcg = gen7_2_0_hwcg_regs, 2630: .hwcg_count = ARRAY_SIZE(gen7_2_0_hwcg_regs), 2631: .ao_hwcg = gen7_2_0_ao_hwcg_regs, 2632: .ao_hwcg_count = ARRAY_SIZE(gen7_2_0_ao_hwcg_regs), 2633: .gbif = gen7_2_0_gbif_cx_regs, 2634: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs), 2635: .hang_detect_cycles = 0xcfffff, 2636: .protected_regs = gen7_2_0_protected_regs, 2637: .gmu_hub_clk_freq = 200000000, 2638: .bcl_data = 1, 2639: .gen7_snapshot_block_list = &gen7_6_0_snapshot_block_list, 2640: .qos_value = gen7_6_0_gbif_client_qos_values, 2641: .preempt_level = 1, 2642: .ctxt_record_size = (4192 * SZ_1K), 2643: }; 2644: 2645: extern const struct gen7_snapshot_block_list gen7_9_0_snapshot_block_list; 2646: 2647: /* GEN7_9_0 protected register list */ 2648: static const struct gen7_protected_regs gen7_9_0_protected_regs[] = { 2649: { GEN7_CP_PROTECT_REG + 0, 0x00000, 0x004ff, 0 }, 2650: { GEN7_CP_PROTECT_REG + 1, 0x0050b, 0x00563, 0 }, 2651: { GEN7_CP_PROTECT_REG + 2, 0x00584, 0x006c1, 0 }, 2652: { GEN7_CP_PROTECT_REG + 3, 0x00706, 0x00706, 0 }, 2653: { GEN7_CP_PROTECT_REG + 4, 0x00720, 0x0073f, 0 }, 2654: { GEN7_CP_PROTECT_REG + 5, 0x00760, 0x007ff, 0 }, 2655: { GEN7_CP_PROTECT_REG + 6, 0x00800, 0x00882, 1 }, 2656: { GEN7_CP_PROTECT_REG + 7, 0x008a0, 0x008a8, 1 }, 2657: { GEN7_CP_PROTECT_REG + 8, 0x008ab, 0x00a40, 0 }, 2658: { GEN7_CP_PROTECT_REG + 9, 0x00900, 0x0094d, 1 }, 2659: { GEN7_CP_PROTECT_REG + 10, 0x0098d, 0x00a3f, 1 }, 2660: { GEN7_CP_PROTECT_REG + 11, 0x00a41, 0x00bff, 1 }, 2661: { GEN7_CP_PROTECT_REG + 12, 0x00df0, 0x00df1, 1 }, 2662: { GEN7_CP_PROTECT_REG + 13, 0x00e01, 0x00e01, 1 }, 2663: { GEN7_CP_PROTECT_REG + 14, 0x00e07, 0x00e0f, 1 }, 2664: { GEN7_CP_PROTECT_REG + 15, 0x02840, 0x03cc3, 1 }, 2665: { GEN7_CP_PROTECT_REG + 16, 0x03cc4, 0x05cc3, 0 }, MATCH LINES: 2708, 2735, 2747, 2774 2696: { GEN7_CP_PROTECT_REG + 47, 0x27c02, 0x27c02, 1 }, 2697: { 0 }, 2698: }; 2699: 2700: static const struct adreno_gen7_core adreno_gpu_core_gen7_9_0 = { 2701: .base = { 2702: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_9_0, 2703: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2704: .compatible = "qcom,adreno-gpu-gen7-9-0", 2705: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_AQE | 2706: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_IFPC | 2707: ADRENO_L3_VOTE | ADRENO_BCL | ADRENO_DMS | 2708: ADRENO_HW_FENCE | ADRENO_PREEMPTION | ADRENO_ACD | 2709: ADRENO_GMU_WARMBOOT | ADRENO_GMU_AB, 2710: .gpudev = &adreno_gen7_9_0_hwsched_gpudev.base, 2711: .perfcounters = &adreno_gen7_9_0_perfcounters, 2712: .uche_gmem_alignment = SZ_16M, 2713: .gmem_size = 3 * SZ_1M, 2714: .bus_width = 32, 2715: .snapshot_size = SZ_8M, 2716: .num_ddr_channels = 4, 2717: .highest_bank_bit = 16, 2718: }, 2719: .aqefw_name = "gen70900_aqe.fw", 2720: .sqefw_name = "gen70900_sqe.fw", 2721: .gmufw_name = "gmu_gen70900.bin", 2722: .zap_name = "gen70900_zap.mbn", 2723: .ao_hwcg = gen7_9_0_ao_hwcg_regs, 2724: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs), 2725: .gbif = gen7_2_0_gbif_cx_regs, 2726: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs), 2727: .hang_detect_cycles = 0xcfffff, 2728: .protected_regs = gen7_9_0_protected_regs, 2729: .gmu_hub_clk_freq = 200000000, 2730: .gen7_snapshot_block_list = &gen7_9_0_snapshot_block_list, 2731: .bcl_data = 1, 2732: .acv_perfmode_vote = BIT(2), 2733: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 2734: .ctxt_record_size = (4208 * SZ_1K), 2735: .preempt_level = 1, 2736: .fast_bus_hint = true, 2737: }; 2738: 2739: static const struct adreno_gen7_core adreno_gpu_core_gen7_9_1 = { 2740: .base = { 2741: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_9_1, 2742: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2743: .compatible = "qcom,adreno-gpu-gen7-9-1", 2744: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_AQE | 2745: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_IFPC | 2746: ADRENO_L3_VOTE | ADRENO_BCL | ADRENO_DMS | 2747: ADRENO_HW_FENCE | ADRENO_PREEMPTION | ADRENO_ACD | 2748: ADRENO_GMU_WARMBOOT | ADRENO_GMU_AB, 2749: .gpudev = &adreno_gen7_9_0_hwsched_gpudev.base, 2750: .perfcounters = &adreno_gen7_9_0_perfcounters, 2751: .uche_gmem_alignment = SZ_16M, 2752: .gmem_size = 3 * SZ_1M, 2753: .bus_width = 32, 2754: .snapshot_size = SZ_8M, 2755: .num_ddr_channels = 4, 2756: .highest_bank_bit = 16, 2757: }, 2758: .aqefw_name = "gen70900_aqe.fw", 2759: .sqefw_name = "gen70900_sqe.fw", 2760: .gmufw_name = "gmu_gen70900.bin", 2761: .zap_name = "gen70900_zap.mbn", 2762: .ao_hwcg = gen7_9_0_ao_hwcg_regs, 2763: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs), 2764: .gbif = gen7_2_0_gbif_cx_regs, 2765: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs), 2766: .hang_detect_cycles = 0xcfffff, 2767: .protected_regs = gen7_9_0_protected_regs, 2768: .gmu_hub_clk_freq = 200000000, 2769: .gen7_snapshot_block_list = &gen7_9_0_snapshot_block_list, 2770: .bcl_data = 1, 2771: .acv_perfmode_vote = BIT(2), 2772: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 2773: .ctxt_record_size = (4208 * SZ_1K), 2774: .preempt_level = 1, 2775: .fast_bus_hint = true, 2776: }; 2777: 2778: extern const struct gen7_snapshot_block_list gen7_13_0_snapshot_block_list; 2779: 2780: /* SMMU aperture registers: GC to context bank 0, LPAC to context bank 1 */ 2781: static const struct kgsl_regmap_list gen7_13_0_smmu_aperture_regs[] = { 2782: { 0x0, 0x000c0000 }, /* GC: CB0 */ 2783: { 0x1, 0x000c1000 }, /* LPAC: CB1 */ 2784: { 0x2, 0x00000002 }, /* CTRL: GC + LPAC */ 2785: }; 2786: 2787: static const struct adreno_gen7_core adreno_gpu_core_gen7_13_0 = { 2788: .base = { 2789: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_13_0, 2790: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2791: .features = ADRENO_APRIV | ADRENO_IOCOHERENT, 2792: .gpudev = &adreno_gen7_gmu_gpudev.base, 2793: .perfcounters = &adreno_gen7_9_0_perfcounters, 2794: .uche_gmem_alignment = SZ_16M, 2795: .gmem_size = 3 * SZ_1M, 2796: .bus_width = 32, 2797: .snapshot_size = SZ_8M, 2798: .num_ddr_channels = 4, MATCH LINES: 2817, 2828, 2849, 2861, 2886, 2898, 2932, 2944, 2968 2805: .gmufw_name = "gen71300_gmu.bin", 2806: .zap_name = "gen71300_zap.mbn", 2807: .gmu_chipid = 0x70D0000, 2808: .ao_hwcg = gen7_9_0_ao_hwcg_regs, 2809: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs), 2810: .gbif = gen7_2_0_gbif_cx_regs, 2811: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs), 2812: .hang_detect_cycles = 0xcfffff, 2813: .protected_regs = gen7_9_0_protected_regs, 2814: .gmu_hub_clk_freq = 200000000, 2815: .gen7_snapshot_block_list = &gen7_13_0_snapshot_block_list, 2816: .ctxt_record_size = (4208 * SZ_1K), 2817: .preempt_level = 1, 2818: }; 2819: 2820: extern const struct gen7_snapshot_block_list gen7_14_0_snapshot_block_list; 2821: 2822: static const struct adreno_gen7_core adreno_gpu_core_gen7_14_0 = { 2823: .base = { 2824: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_14_0, 2825: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2826: .compatible = "qcom,adreno-gpu-gen7-14-0", 2827: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION | 2828: ADRENO_PREEMPTION | ADRENO_IFPC | ADRENO_BCL | ADRENO_ACD, 2829: .gpudev = &adreno_gen7_gmu_gpudev.base, 2830: .perfcounters = &adreno_gen7_no_cb_perfcounters, 2831: .uche_gmem_alignment = 0, 2832: .gmem_size = SZ_1M, 2833: .bus_width = 32, 2834: .snapshot_size = SZ_4M, 2835: .highest_bank_bit = 15, 2836: }, 2837: .sqefw_name = "gen70e00_sqe.fw", 2838: .gmufw_name = "gmu_gen70e00.bin", 2839: .zap_name = "gen70e00_zap.mbn", 2840: .hwcg = gen7_0_0_hwcg_regs, 2841: .hwcg_count = ARRAY_SIZE(gen7_0_0_hwcg_regs), 2842: .ao_hwcg = gen7_0_0_ao_hwcg_regs, 2843: .ao_hwcg_count = ARRAY_SIZE(gen7_0_0_ao_hwcg_regs), 2844: .gbif = gen7_0_0_gbif_cx_regs, 2845: .gbif_count = ARRAY_SIZE(gen7_0_0_gbif_cx_regs), 2846: .hang_detect_cycles = 0xcfffff, 2847: .protected_regs = gen7_0_0_protected_regs, 2848: .gen7_snapshot_block_list = &gen7_14_0_snapshot_block_list, 2849: .preempt_level = 1, 2850: .fast_bus_hint = false, 2851: }; 2852: 2853: extern const struct gen7_snapshot_block_list gen7_11_0_snapshot_block_list; 2854: 2855: static const struct adreno_gen7_core adreno_gpu_core_gen7_11_0 = { 2856: .base = { 2857: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_11_0, 2858: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2859: .compatible = "qcom,adreno-gpu-gen7-11-0", 2860: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION | 2861: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_L3_VOTE | 2862: ADRENO_DMS | ADRENO_GMU_AB, 2863: .gpudev = &adreno_gen7_hwsched_gpudev.base, 2864: .perfcounters = &adreno_gen7_2_0_perfcounters, 2865: .uche_gmem_alignment = SZ_16M, 2866: .gmem_size = SZ_1M + SZ_512K, 2867: .bus_width = 32, 2868: .snapshot_size = SZ_4M, 2869: .num_ddr_channels = 4, 2870: .highest_bank_bit = 16, 2871: }, 2872: .gmu_fw_version = GMU_VERSION(4, 5, 0), 2873: .sqefw_name = "gen71100_sqe.fw", 2874: .gmufw_name = "gen71100_gmu.bin", 2875: .zap_name = "gen71100_zap.mbn", 2876: .hwcg = gen7_2_0_hwcg_regs, 2877: .hwcg_count = ARRAY_SIZE(gen7_2_0_hwcg_regs), 2878: .ao_hwcg = gen7_9_0_ao_hwcg_regs, 2879: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs), 2880: .gbif = gen7_2_0_gbif_cx_regs, 2881: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs), 2882: .hang_detect_cycles = 0xcfffff, 2883: .protected_regs = gen7_2_0_protected_regs, 2884: .gmu_hub_clk_freq = 200000000, 2885: .gen7_snapshot_block_list = &gen7_11_0_snapshot_block_list, 2886: .preempt_level = 1, 2887: .fast_bus_hint = true, 2888: }; 2889: 2890: extern const struct gen7_snapshot_block_list gen7_15_0_snapshot_block_list; 2891: 2892: static const struct adreno_gen7_core adreno_gpu_core_gen7_15_0 = { 2893: .base = { 2894: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_15_0, 2895: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2896: .compatible = "qcom,adreno-gpu-gen7-15-0", 2897: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_IFPC | 2898: ADRENO_PREEMPTION | ADRENO_L3_VOTE | ADRENO_DMS, 2899: .gpudev = &adreno_gen7_gmu_gpudev.base, 2900: .perfcounters = &adreno_gen7_2_0_perfcounters, 2901: .uche_gmem_alignment = SZ_16M, 2902: .gmem_size = SZ_1M + SZ_512K, 2903: .bus_width = 32, 2904: .snapshot_size = SZ_4M, 2905: .num_ddr_channels = 8, 2906: .highest_bank_bit = 16, 2907: .chipid = 0x43030c00, 2908: .speedbins = KGSL_SPEEDBINS( 2909: { 0, 0 }, 2910: { 294, 1 }, 2911: { 263, 2 }, 2912: { 233, 3 }, 2913: { 141, 4 }, 2914: ), 2915: .ubwc_mode = 4, 2916: .mal = 32, 2917: .gpu_model = "Adreno X1-45", 2918: }, 2919: .sqefw_name = "gen71500_sqe.fw", 2920: .gmufw_name = "gen71500_gmu.bin", 2921: .zap_name = "gen71500_zap.mbn", 2922: .hwcg = gen7_2_0_hwcg_regs, 2923: .hwcg_count = ARRAY_SIZE(gen7_2_0_hwcg_regs), 2924: .ao_hwcg = gen7_9_0_ao_hwcg_regs, 2925: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs), 2926: .gbif = gen7_2_0_gbif_cx_regs, 2927: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs), 2928: .hang_detect_cycles = 0xcfffff, 2929: .protected_regs = gen7_2_0_protected_regs, 2930: .gmu_hub_clk_freq = 200000000, 2931: .gen7_snapshot_block_list = &gen7_15_0_snapshot_block_list, 2932: .preempt_level = 1, 2933: .fast_bus_hint = true, 2934: }; 2935: 2936: extern const struct gen7_snapshot_block_list gen7_17_0_snapshot_block_list; 2937: 2938: static const struct adreno_gen7_core adreno_gpu_core_gen7_17_0 = { 2939: .base = { 2940: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_17_0, 2941: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2942: .compatible = "qcom,adreno-gpu-gen7-17-0", 2943: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION | 2944: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_BCL, 2945: .gpudev = &adreno_gen7_gmu_gpudev.base, 2946: .perfcounters = &adreno_gen7_no_cb_perfcounters, 2947: .uche_gmem_alignment = SZ_16M, 2948: .gmem_size = SZ_1M, 2949: .bus_width = 32, 2950: .snapshot_size = SZ_2M, 2951: .chipid = 0x43020100, 2952: .ubwc_mode = 5, 2953: .mal = 32, 2954: .highest_bank_bit = 15, 2955: }, 2956: .sqefw_name = "gen70e00_sqe.fw", 2957: .gmufw_name = "gen71700_gmu.bin", 2958: .zap_name = "gen70e00_zap.mbn", 2959: .hwcg = gen7_0_0_hwcg_regs, 2960: .hwcg_count = ARRAY_SIZE(gen7_0_0_hwcg_regs), 2961: .ao_hwcg = gen7_0_0_ao_hwcg_regs, 2962: .ao_hwcg_count = ARRAY_SIZE(gen7_0_0_ao_hwcg_regs), 2963: .gbif = gen7_0_0_gbif_cx_regs, 2964: .gbif_count = ARRAY_SIZE(gen7_0_0_gbif_cx_regs), 2965: .hang_detect_cycles = 0xcfffff, 2966: .protected_regs = gen7_0_0_protected_regs, 2967: .gen7_snapshot_block_list = &gen7_17_0_snapshot_block_list, 2968: .preempt_level = 1, 2969: .ctxt_record_size = 1536 * 1024 2970: }; 2971: 2972: static const struct kgsl_regmap_list a663_hwcg_regs[] = { 2973: {A6XX_RBBM_CLOCK_CNTL_SP0, 0x02222222}, 2974: {A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220}, 2975: {A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000080}, 2976: {A6XX_RBBM_CLOCK_HYST_SP0, 0x0000F3CF}, 2977: {A6XX_RBBM_CLOCK_CNTL_TP0, 0x22222222}, 2978: {A6XX_RBBM_CLOCK_CNTL2_TP0, 0x22222222}, 2979: {A6XX_RBBM_CLOCK_CNTL3_TP0, 0x22222222}, 2980: {A6XX_RBBM_CLOCK_CNTL4_TP0, 0x00022222}, 2981: {A6XX_RBBM_CLOCK_DELAY_TP0, 0x11111111}, 2982: {A6XX_RBBM_CLOCK_DELAY2_TP0, 0x11111111}, 2983: {A6XX_RBBM_CLOCK_DELAY3_TP0, 0x11111111}, 2984: {A6XX_RBBM_CLOCK_DELAY4_TP0, 0x00011111}, 2985: {A6XX_RBBM_CLOCK_HYST_TP0, 0x77777777}, 2986: {A6XX_RBBM_CLOCK_HYST2_TP0, 0x77777777}, 2987: {A6XX_RBBM_CLOCK_HYST3_TP0, 0x77777777}, 2988: {A6XX_RBBM_CLOCK_HYST4_TP0, 0x00077777}, 2989: {A6XX_RBBM_CLOCK_CNTL_RB0, 0x22222222}, 2990: {A6XX_RBBM_CLOCK_CNTL2_RB0, 0x01002222}, 2991: {A6XX_RBBM_CLOCK_CNTL_CCU0, 0x00002220}, 2992: {A6XX_RBBM_CLOCK_HYST_RB_CCU0, 0x00040F00}, MATCH LINES: 3034 3022: {A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555}, 3023: {A6XX_GMUAO_GMU_CGC_MODE_CNTL, 0x00020200}, 3024: {A6XX_GMUAO_GMU_CGC_DELAY_CNTL, 0x00010111}, 3025: {A6XX_GMUAO_GMU_CGC_HYST_CNTL, 0x00005555}, 3026: {A6XX_GMUCX_GMU_WFI_CONFIG, 0x00000000}, 3027: }; 3028: 3029: static const struct adreno_a6xx_core adreno_gpu_core_a663 = { 3030: .base = { 3031: DEFINE_ADRENO_REV(ADRENO_REV_A663, 6, 6, 3, ANY_ID), 3032: .features = ADRENO_APRIV | 3033: ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION | 3034: ADRENO_PREEMPTION | ADRENO_ACD, 3035: .gpudev = &adreno_a6xx_gmu_gpudev.base, 3036: .perfcounters = &adreno_a6xx_perfcounters, 3037: .gmem_size = SZ_1M + SZ_512K, 3038: .bus_width = 32, 3039: .snapshot_size = SZ_2M, 3040: .chipid = 0x06060300, 3041: .speedbins = KGSL_SPEEDBINS( 3042: { 0, 0 }, 3043: { 169, 0 }, 3044: { 113, 1 }, 3045: ), 3046: .ubwc_mode = 4, 3047: .mal = 32, 3048: .highest_bank_bit = 13, 3049: }, 3050: .prim_fifo_threshold = 0x00300000, 3051: .gmu_major = 2, 3052: .gmu_minor = 0, 3053: .sqefw_name = "a660_sqe.fw", 3054: .gmufw_name = "a663_gmu.bin", 3055: .zap_name = "a663_zap.mbn", 3056: .hwcg = a663_hwcg_regs, 3057: .hwcg_count = ARRAY_SIZE(a663_hwcg_regs), 3058: .vbif = a650_gbif_regs, MATCH LINES: 3085 3073: { GEN8_GBIF_QSB_SIDE2, 0x00071e20 }, 3074: { GEN8_GBIF_QSB_SIDE3, 0x00071e20 }, 3075: { GEN8_GBIF_CX_CONFIG, 0x20023000 }, 3076: { GEN8_GMUCX_MRC_GBIF_QOS_CTRL, 0x33 }, 3077: }; 3078: 3079: /* GEN8_0_0 noncontext register list */ 3080: static const struct gen8_nonctxt_regs gen8_0_0_nonctxt_regs[] = { 3081: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 3082: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3083: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3084: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3085: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3086: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3087: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3088: /* Disable BR throttling */ 3089: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3090: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3091: /* Configure GBIF GX registers */ 3092: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) }, 3093: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) }, 3094: /* Enable full concurrent resolve and unresolves */ 3095: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 3096: { GEN8_RB_GC_GMEM_PROTECT, 0x0c000000, BIT(PIPE_BR) }, 3097: /* Configure number of outstanding transactions to 32 */ 3098: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 3099: /* Configure UCHE request time out to 16 cycles for CCU/UCHE arbitration */ 3100: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 3101: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3102: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3103: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 3104: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 3105: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, 3106: /* Enable contribution of all shader stages to SP perfcounters */ 3107: { GEN8_SP_PERFCTR_SHADER_MASK, 0x0000003f, BIT(PIPE_NONE) }, 3108: /* 3109: * BIT(26): Limit the number of wave-slots for Eviction buffer to 1 per ALU GRP MATCH LINES: 3265, 3295, 3309, 3312 3253: }, 3254: }, 3255: }; 3256: 3257: static const struct adreno_gen8_core adreno_gpu_core_gen8_0_0 = { 3258: .base = { 3259: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_0_0, 3260: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3261: .compatible = "qcom,adreno-gpu-gen8-0-0", 3262: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 3263: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_AQE | 3264: ADRENO_GMU_WARMBOOT | ADRENO_L3_VOTE | ADRENO_BCL | 3265: ADRENO_IFPC | ADRENO_HW_FENCE | ADRENO_PREEMPTION | 3266: ADRENO_ACD | ADRENO_CLX | ADRENO_GMU_THERMAL_MITIGATION | 3267: ADRENO_GMU_AB, 3268: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3269: .perfcounters = &adreno_gen8_perfcounters, 3270: .uche_gmem_alignment = SZ_64M, 3271: .gmem_size = 12 * SZ_1M, 3272: .bus_width = 32, 3273: .snapshot_size = SZ_8M, 3274: .num_ddr_channels = 4, 3275: .highest_bank_bit = 16, 3276: }, 3277: .aqefw_name = "gen80000_aqe.fw", 3278: .sqefw_name = "gen80000_sqe.fw", 3279: .gmufw_name = "gen80000_gmu.bin", 3280: .zap_name = "gen80000_zap.mbn", 3281: .ao_hwcg = gen8_ao_hwcg_regs, 3282: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs), 3283: .gbif = gen8_0_0_gbif_cx_regs, 3284: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 3285: .hang_detect_cycles = 0xcfffff, 3286: .protected_regs = gen8_0_0_protected_regs, 3287: .nonctxt_regs = gen8_0_0_nonctxt_regs, 3288: .gmu_hub_clk_freq = 200000000, 3289: .gen8_snapshot_block_list = &gen8_0_0_snapshot_block_list, 3290: .fast_bus_hint = true, 3291: .bcl_data = 1, 3292: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 3293: .noc_timeout_us = 3410, /* 3.41 msec */ 3294: .ctxt_record_size = (13536 * SZ_1K), 3295: .preempt_level = 1, 3296: .cl_no_ft_timeout_ms = 6500, 3297: .therm_cfg = &therm_mit_cfg_8_0_0, 3298: .clx_tbl = &gen8_0_0_clx_table, 3299: }; 3300: 3301: static const struct adreno_gen8_core adreno_gpu_core_gen8_0_1 = { 3302: .base = { 3303: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_0_1, 3304: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3305: .compatible = "qcom,adreno-gpu-gen8-0-1", 3306: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 3307: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_AQE | 3308: ADRENO_GMU_WARMBOOT | ADRENO_L3_VOTE | ADRENO_BCL | 3309: ADRENO_IFPC | ADRENO_HW_FENCE | ADRENO_PREEMPTION | 3310: ADRENO_ACD | ADRENO_CLX | ADRENO_GMU_THERMAL_MITIGATION | 3311: ADRENO_GMU_AB, 3312: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION | 3313: ADRENO_IFPC | ADRENO_AQE | ADRENO_CONTENT_PROTECTION, 3314: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3315: .perfcounters = &adreno_gen8_perfcounters, 3316: .uche_gmem_alignment = SZ_64M, 3317: .gmem_size = 12 * SZ_1M, 3318: .bus_width = 32, 3319: .snapshot_size = SZ_8M, 3320: .num_ddr_channels = 4, 3321: .highest_bank_bit = 16, 3322: .chipid = 0x44050001, 3323: .speedbins = KGSL_SPEEDBINS( 3324: { 0, 0 }, 3325: { 252, 1 }, 3326: { 242, 2 }, 3327: { 232, 3 }, 3328: { 221, 4 }, 3329: { 190, 5 }, 3330: ), 3331: .ubwc_mode = 5, 3332: .mal = 32, 3333: .gpu_model = "Adreno830", 3334: }, 3335: .aqefw_name = "gen80000_aqe.fw", 3336: .sqefw_name = "gen80000_sqe.fw", MATCH LINES: 3353 3341: .gbif = gen8_0_0_gbif_cx_regs, 3342: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 3343: .hang_detect_cycles = 0xcfffff, 3344: .protected_regs = gen8_0_0_protected_regs, 3345: .nonctxt_regs = gen8_0_0_nonctxt_regs, 3346: .gmu_hub_clk_freq = 200000000, 3347: .gen8_snapshot_block_list = &gen8_0_0_snapshot_block_list, 3348: .fast_bus_hint = true, 3349: .bcl_data = 1, 3350: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 3351: .noc_timeout_us = 3410, /* 3.41 msec */ 3352: .ctxt_record_size = (13536 * SZ_1K), 3353: .preempt_level = 1, 3354: .cl_no_ft_timeout_ms = 6500, 3355: .therm_cfg = &therm_mit_cfg_8_0_0, 3356: .clx_tbl = &gen8_0_0_clx_table, 3357: }; 3358: 3359: extern const struct gen8_snapshot_block_list gen8_2_0_snapshot_block_list; 3360: 3361: static const struct hfi_clx_table_v2_cmd gen8_2_0_clx_table = { 3362: .version = (2 << 16) | 1, 3363: .domain = { 3364: /* GFX domain */ 3365: { 3366: .data0 = CLX_DATA(60, 5, 1, 1), 3367: .clxt = 0, 3368: .clxh = 0, 3369: .urgmode = 1, 3370: .lkgen = 0, 3371: .currbudget = 100, 3372: }, 3373: /* MxG domain */ 3374: { 3375: .data0 = CLX_DATA(60, 1, 1, 1), 3376: .clxt = 0, 3377: .clxh = 0, MATCH LINES: 3521 3509: { GEN8_CP_PROTECT_REG_GLOBAL + 52, 0x27882, 0x2788b, 1 }, 3510: { GEN8_CP_PROTECT_REG_GLOBAL + 63, 0x27c06, 0x27c06, 1 }, 3511: { 0 }, 3512: }; 3513: 3514: /* GEN8_2_0 noncontext register list */ 3515: static const struct gen8_nonctxt_regs gen8_2_0_nonctxt_regs[] = { 3516: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 3517: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3518: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3519: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3520: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3521: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3522: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3523: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3524: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3525: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3526: /* Disable Dead Draw Merge scheme on RB-HLSQ */ 3527: { GEN8_RB_RBP_CNTL, BIT(5), BIT(PIPE_BV) | BIT(PIPE_BR) }, 3528: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 3529: /* Partially enable perf clear, Disable DINT to c/z be data forwarding */ 3530: { GEN8_RB_CCU_DBG_ECO_CNTL, 0x00002200, BIT(PIPE_BR) }, 3531: { GEN8_RB_GC_GMEM_PROTECT, 0x12000000, BIT(PIPE_BR) }, 3532: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 3533: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 3534: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3535: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3536: { GEN8_RBBM_POWER_UP_RESET_SW_OVERRIDE, 0x70809060, BIT(PIPE_NONE) }, 3537: { GEN8_RBBM_POWER_UP_RESET_SW_BV_OVERRIDE, 0x30000000, BIT(PIPE_NONE) }, 3538: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 3539: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 3540: { GEN8_RBBM_INTERFACE_HANG_INT_CNTL, 0x0fffffff, BIT(PIPE_NONE) }, 3541: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) }, 3542: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, 3543: /* Disable mode_switch optimization in UMAS */ 3544: { GEN8_SP_CHICKEN_BITS, BIT(26), BIT(PIPE_NONE) }, 3545: /* Disable LPAC large-LM mode */ MATCH LINES: 3617, 3653, 3663, 3669 3605: .throttle_cfg.throttle_lvls[2] = 20, 3606: }; 3607: 3608: /* Set the BCL throttle levels to 62/75/83 percent */ 3609: #define GEN8_2_X_BCL_DATA ((62 << 15) | (75 << 8) | (83 << 1) | 0x1) 3610: 3611: static const struct adreno_gen8_core adreno_gpu_core_gen8_2_0 = { 3612: .base = { 3613: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_2_0, 3614: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3615: .compatible = "qcom,adreno-gpu-gen8-2-0", 3616: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 3617: ADRENO_PREEMPTION | ADRENO_LPAC | ADRENO_AQE | 3618: ADRENO_GMU_WARMBOOT | ADRENO_IFPC | ADRENO_CONTENT_PROTECTION | 3619: ADRENO_HW_FENCE | ADRENO_BCL | ADRENO_ACD | ADRENO_GMU_BASED_DCVS | 3620: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_CLX | ADRENO_DEFER_GMEM_ALLOC | 3621: ADRENO_GMU_MINBW | ADRENO_DCVS_PROFILE | ADRENO_TSENSE_DYNAMIC_PERIOD | 3622: ADRENO_GMU_AB, 3623: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3624: .perfcounters = &adreno_gen8_2_x_perfcounters, 3625: .uche_gmem_alignment = SZ_64M, 3626: .gmem_size = 18 * SZ_1M, 3627: .bus_width = 32, 3628: .snapshot_size = SZ_8M, 3629: .num_ddr_channels = 4, 3630: .highest_bank_bit = 16, 3631: }, 3632: .aqefw_name = "gen80200_aqe.fw", 3633: .sqefw_name = "gen80200_sqe.fw", 3634: .gmufw_name = "gen80200_gmu.bin", 3635: .zap_name = "gen80200_zap.mbn", 3636: .ao_hwcg = gen8_2_0_ao_hwcg_regs, 3637: .ao_hwcg_count = ARRAY_SIZE(gen8_2_0_ao_hwcg_regs), 3638: .gbif = gen8_0_0_gbif_cx_regs, 3639: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 3640: .hang_detect_cycles = 0xcfffff, 3641: .protected_regs = gen8_2_0_protected_regs, 3642: .nonctxt_regs = gen8_2_0_nonctxt_regs, 3643: .gmu_hub_clk_freq = 150000000, 3644: .gen8_snapshot_block_list = &gen8_2_0_snapshot_block_list, 3645: .fast_bus_hint = true, 3646: .bcl_data = GEN8_2_X_BCL_DATA, 3647: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 3648: .noc_timeout_us = 3410, /* 3.41 msec */ 3649: .cl_no_ft_timeout_ms = 6500, 3650: .ctxt_record_size = (19708 * SZ_1K), 3651: .therm_cfg = &therm_mit_cfg_8_2_0, 3652: .limits_mit_cfg = &gen8_2_0_limits_mit_cfg, 3653: .preempt_level = 1, 3654: .clx_tbl = &gen8_2_0_clx_table, 3655: }; 3656: 3657: static const struct adreno_gen8_core adreno_gpu_core_gen8_2_1 = { 3658: .base = { 3659: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_2_1, 3660: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3661: .compatible = "qcom,adreno-gpu-gen8-2-1", 3662: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 3663: ADRENO_PREEMPTION | ADRENO_LPAC | ADRENO_AQE | 3664: ADRENO_GMU_WARMBOOT | ADRENO_IFPC | ADRENO_CONTENT_PROTECTION | 3665: ADRENO_HW_FENCE | ADRENO_BCL | ADRENO_ACD | ADRENO_GMU_BASED_DCVS | 3666: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_CLX | ADRENO_DEFER_GMEM_ALLOC | 3667: ADRENO_GMU_MINBW | ADRENO_DCVS_PROFILE | ADRENO_TSENSE_DYNAMIC_PERIOD | 3668: ADRENO_GMU_AB, 3669: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION | 3670: ADRENO_IFPC | ADRENO_AQE | ADRENO_CONTENT_PROTECTION, 3671: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3672: .perfcounters = &adreno_gen8_2_x_perfcounters, 3673: .uche_gmem_alignment = SZ_64M, 3674: .gmem_size = 18 * SZ_1M, 3675: .bus_width = 32, 3676: .snapshot_size = SZ_8M, 3677: .num_ddr_channels = 4, 3678: .highest_bank_bit = 16, 3679: .chipid = 0x44050a01, 3680: .speedbins = KGSL_SPEEDBINS( 3681: { 0, 0 }, 3682: { 273, 1 }, 3683: { 252, 2 }, 3684: { 221, 3 }, 3685: ), 3686: .ubwc_mode = 6, 3687: .mal = 32, 3688: .gpu_model = "Adreno840", 3689: }, 3690: .aqefw_name = "gen80200_aqe.fw", 3691: .sqefw_name = "gen80200_sqe.fw", 3692: .gmufw_name = "gen80200_gmu.bin", 3693: .zap_name = "gen80200_zap.mbn", MATCH LINES: 3711, 3721 3699: .protected_regs = gen8_2_0_protected_regs, 3700: .nonctxt_regs = gen8_2_0_nonctxt_regs, 3701: .gmu_hub_clk_freq = 150000000, 3702: .gen8_snapshot_block_list = &gen8_2_0_snapshot_block_list, 3703: .fast_bus_hint = true, 3704: .bcl_data = GEN8_2_X_BCL_DATA, 3705: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 3706: .noc_timeout_us = 3410, /* 3.41 msec */ 3707: .cl_no_ft_timeout_ms = 6500, 3708: .ctxt_record_size = (19708 * SZ_1K), 3709: .therm_cfg = &therm_mit_cfg_8_2_0, 3710: .limits_mit_cfg = &gen8_2_0_limits_mit_cfg, 3711: .preempt_level = 1, 3712: .clx_tbl = &gen8_2_0_clx_table, 3713: }; 3714: 3715: static const struct gen8_nonctxt_regs gen8_1_0_nonctxt_regs[] = { 3716: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 3717: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3718: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3719: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3720: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3721: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3722: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3723: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3724: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3725: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3726: { GEN8_RB_GC_GMEM_PROTECT, 0x15000000, BIT(PIPE_BR) }, 3727: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 3728: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 3729: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3730: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3731: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 3732: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 3733: { GEN8_RBBM_INTERFACE_HANG_INT_CNTL, 0x0fffffff, BIT(PIPE_NONE) }, 3734: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) }, 3735: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, 3736: { GEN8_SP_CHICKEN_BITS_2, 0x00820800, BIT(PIPE_NONE) }, 3737: { GEN8_SP_CHICKEN_BITS_3, 0x00300000, BIT(PIPE_NONE) }, 3738: { GEN8_SP_PERFCTR_SHADER_MASK, 0x0000003f, BIT(PIPE_NONE) }, 3739: /* Disable CS dead batch merge */ 3740: { GEN8_SP_HLSQ_DBG_ECO_CNTL_2, BIT(31), BIT(PIPE_NONE) }, 3741: { GEN8_SP_HLSQ_TIMEOUT_THRESHOLD_DP, 0x00000080, BIT(PIPE_NONE) }, 3742: { GEN8_SP_READ_SEL, 0x0001ff00, BIT(PIPE_NONE) }, 3743: { GEN8_TPL1_DBG_ECO_CNTL, 0x10000000, BIT(PIPE_NONE) }, 3744: /* BIT(26): Disable final clamp for bicubic filtering */ 3745: { GEN8_TPL1_DBG_ECO_CNTL1, 0x04000720, BIT(PIPE_NONE) }, MATCH LINES: 3829, 3867, 3875, 3911, 3921 3817: { GEN8_GMUAO_CGC_MODE_CNTL, 0x00020202 }, 3818: { GEN8_GMUAO_CGC_DELAY_CNTL, 0x00110111 }, 3819: { GEN8_GMUAO_CGC_HYST_CNTL, 0x00055555 }, 3820: }; 3821: 3822: extern const struct gen8_snapshot_block_list gen8_1_0_snapshot_block_list; 3823: 3824: static const struct adreno_gen8_core adreno_gpu_core_gen8_1_0 = { 3825: .base = { 3826: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_1_0, 3827: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3828: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION | 3829: ADRENO_SOFTFUSE | ADRENO_ACD | ADRENO_PREEMPTION | ADRENO_AQE, 3830: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3831: .perfcounters = &adreno_gen8_perfcounters, 3832: .uche_gmem_alignment = SZ_64M, 3833: .gmem_size = 21 * SZ_1M, 3834: .bus_width = 32, 3835: .snapshot_size = SZ_8M, 3836: .num_ddr_channels = 4, 3837: /* bits[7:4] patched at runtime with active slice count */ 3838: .chipid = 0x44070001, 3839: .speedbins = KGSL_SPEEDBINS( 3840: { 0, 0 }, 3841: { 388, 1 }, 3842: { 357, 2 }, 3843: { 284, 3 }, 3844: ), 3845: .ubwc_mode = 5, 3846: .mal = 32, 3847: .highest_bank_bit = 16, 3848: .gpu_model = "Adreno X2-90", 3849: }, 3850: .aqefw_name = "gen80100_aqe.fw", 3851: .sqefw_name = "gen80100_sqe.fw", 3852: .gmufw_name = "gen80100_gmu.bin", 3853: .zap_name = "gen80100_zap.mbn", 3854: .ao_hwcg = gen8_1_0_ao_hwcg_regs, 3855: .ao_hwcg_count = ARRAY_SIZE(gen8_1_0_ao_hwcg_regs), 3856: .gbif = gen8_0_0_gbif_cx_regs, 3857: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 3858: .hang_detect_cycles = 0xcfffff, 3859: .protected_regs = gen8_1_0_protected_regs, 3860: .nonctxt_regs = gen8_1_0_nonctxt_regs, 3861: .gmu_hub_clk_freq = 200000000, 3862: .gen8_snapshot_block_list = &gen8_1_0_snapshot_block_list, 3863: .fast_bus_hint = true, 3864: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 3865: .noc_timeout_us = 3410, /* 3.41 msec */ 3866: .ctxt_record_size = (23088 * SZ_1K), 3867: .preempt_level = 1, 3868: }; 3869: 3870: static const struct adreno_gen8_core adreno_gpu_core_gen8_5_0 = { 3871: .base = { 3872: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_5_0, 3873: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3874: .compatible = "qcom,adreno-gpu-gen8-5-0", 3875: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION | 3876: ADRENO_LPAC | ADRENO_AQE | ADRENO_GMU_WARMBOOT | ADRENO_IFPC | 3877: ADRENO_CONTENT_PROTECTION | ADRENO_HW_FENCE | ADRENO_BCL | 3878: ADRENO_GMU_AB | ADRENO_GMU_BASED_DCVS | ADRENO_GMU_THERMAL_MITIGATION | 3879: ADRENO_DEFER_GMEM_ALLOC | ADRENO_GMU_MINBW | 3880: ADRENO_TSENSE_DYNAMIC_PERIOD | ADRENO_DCVS_PROFILE, 3881: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3882: .perfcounters = &adreno_gen8_2_x_perfcounters, 3883: .uche_gmem_alignment = SZ_64M, 3884: .gmem_size = 18 * SZ_1M, 3885: .bus_width = 32, 3886: .snapshot_size = SZ_8M, 3887: .num_ddr_channels = 4, 3888: .highest_bank_bit = 16, 3889: }, 3890: .aqefw_name = "gen80200_aqe.fw", 3891: .sqefw_name = "gen80200_sqe.fw", 3892: .gmufw_name = "gen80200_gmu.bin", 3893: .zap_name = "gen80200_zap.mbn", 3894: .ao_hwcg = gen8_2_0_ao_hwcg_regs, 3895: .ao_hwcg_count = ARRAY_SIZE(gen8_2_0_ao_hwcg_regs), 3896: .gbif = gen8_0_0_gbif_cx_regs, 3897: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 3898: .hang_detect_cycles = 0xcfffff, 3899: .protected_regs = gen8_2_0_protected_regs, 3900: .nonctxt_regs = gen8_2_0_nonctxt_regs, 3901: .gmu_hub_clk_freq = 150000000, 3902: .gen8_snapshot_block_list = &gen8_2_0_snapshot_block_list, 3903: .fast_bus_hint = true, 3904: .bcl_data = GEN8_2_X_BCL_DATA, 3905: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 3906: .noc_timeout_us = 3410, /* 3.41 msec */ 3907: .cl_no_ft_timeout_ms = 6500, 3908: .ctxt_record_size = (19708 * SZ_1K), 3909: .therm_cfg = &therm_mit_cfg_8_2_0, 3910: .limits_mit_cfg = &gen8_2_0_limits_mit_cfg, 3911: .preempt_level = 1, 3912: .clx_tbl = &gen8_2_0_clx_table, 3913: }; 3914: 3915: /* GEN8_4_0 noncontext register list */ 3916: static const struct gen8_nonctxt_regs gen8_4_0_nonctxt_regs[] = { 3917: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 3918: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3919: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3920: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3921: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3922: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3923: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3924: /* Disable BR throttling */ 3925: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3926: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3927: /* Configure GBIF GX registers */ 3928: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) }, 3929: /* Reset value of RBBM_GBIF_CLIENT_QOS_CNTL is 0. So, no need to program explicitly. */ 3930: /* Enable full concurrent resolve and unresolves */ 3931: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 3932: { GEN8_RB_GC_GMEM_PROTECT, 0x0c000000, BIT(PIPE_BR) }, 3933: /* Configure number of outstanding transactions to 32 */ 3934: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 3935: /* Configure UCHE request time out to 16 cycles for CCU/UCHE arbitration */ 3936: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 3937: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3938: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3939: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 3940: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 3941: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, 3942: /* Enable contribution of all shader stages to SP perfcounters */ 3943: { GEN8_SP_PERFCTR_SHADER_MASK, 0x0000003f, BIT(PIPE_NONE) }, 3944: /* 3945: * BIT(26): Limit the number of wave-slots for Eviction buffer to 1 per ALU GRP MATCH LINES: 3993, 4019, 4049 3981: 0x33233323, 3982: }; 3983: 3984: static const struct adreno_gen8_core adreno_gpu_core_gen8_4_0 = { 3985: .base = { 3986: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_4_0, 3987: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3988: .compatible = "qcom,adreno-gpu-gen8-4-0", 3989: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 3990: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_AQE | 3991: ADRENO_GMU_WARMBOOT | ADRENO_L3_VOTE | ADRENO_IFPC | 3992: ADRENO_BCL | ADRENO_ACD | ADRENO_HW_FENCE | 3993: ADRENO_PREEMPTION | ADRENO_GMU_AB, 3994: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3995: .perfcounters = &adreno_gen8_perfcounters, 3996: .uche_gmem_alignment = SZ_64M, 3997: .gmem_size = 12 * SZ_1M, 3998: .bus_width = 32, 3999: .snapshot_size = SZ_8M, 4000: .num_ddr_channels = 4, 4001: .highest_bank_bit = 16, 4002: }, 4003: .aqefw_name = "gen80000_aqe.fw", 4004: .sqefw_name = "gen80000_sqe.fw", 4005: .gmufw_name = "gen80000_gmu.bin", 4006: .zap_name = "gen80000_zap.mbn", 4007: .ao_hwcg = gen8_ao_hwcg_regs, 4008: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs), 4009: .gbif = gen8_0_0_gbif_cx_regs, 4010: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 4011: .hang_detect_cycles = 0xcfffff, 4012: .protected_regs = gen8_0_0_protected_regs, 4013: .nonctxt_regs = gen8_4_0_nonctxt_regs, 4014: .gmu_hub_clk_freq = 200000000, 4015: .gen8_snapshot_block_list = &gen8_0_0_snapshot_block_list, 4016: .qos_value = gen8_4_0_gbif_client_qos_values, 4017: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 4018: .bcl_data = 1, 4019: .preempt_level = 1, 4020: .ctxt_record_size = (13536 * SZ_1K), 4021: .noc_timeout_us = 3410, /* 3.41 msec */ 4022: .cl_no_ft_timeout_ms = 10000, 4023: }; 4024: 4025: extern const struct gen8_snapshot_block_list gen8_3_0_snapshot_block_list; 4026: 4027: static const struct kgsl_regmap_list gen8_3_0_gbif_cx_regs[] = { 4028: { GEN8_GBIF_QSB_SIDE0, 0x00071e20 }, 4029: { GEN8_GBIF_QSB_SIDE1, 0x00071e20 }, 4030: { GEN8_GBIF_QSB_SIDE2, 0x00071e20 }, 4031: { GEN8_GBIF_QSB_SIDE3, 0x00071e20 }, 4032: { GEN8_GBIF_CX_CONFIG, 0x20023000 }, 4033: }; 4034: 4035: static const struct kgsl_regmap_list gen8_8_0_gbif_cx_regs[] = { 4036: { GEN8_GBIF_QSB_SIDE0, 0x00071e20 }, 4037: { GEN8_GBIF_QSB_SIDE1, 0x00071e20 }, 4038: { GEN8_GBIF_QSB_SIDE2, 0x00071e20 }, 4039: { GEN8_GBIF_QSB_SIDE3, 0x00071e20 }, 4040: { GEN8_GBIF_CX_CONFIG, 0x40023000 }, 4041: }; 4042: 4043: /* GEN8_3_0 noncontext register list */ 4044: static const struct gen8_nonctxt_regs gen8_3_0_nonctxt_regs[] = { 4045: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 4046: { GEN8_GRAS_DBG_ECO_CNTL, 0x00f80800, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4047: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4048: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4049: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4050: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) }, 4051: { GEN8_PC_CHICKEN_BITS_1, 0x00000023, BIT(PIPE_BV) }, /* Avoid partial waves at VFD */ 4052: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4053: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4054: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4055: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 4056: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 4057: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 4058: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4059: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4060: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 4061: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 4062: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) }, 4063: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) }, 4064: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, 4065: { GEN8_SP_CHICKEN_BITS_2, BIT(22) | BIT(23), BIT(PIPE_NONE) }, 4066: { GEN8_SP_CHICKEN_BITS_3, 0x00300000, BIT(PIPE_NONE) }, 4067: { GEN8_SP_PERFCTR_SHADER_MASK, 0x0000003f, BIT(PIPE_NONE) }, 4068: { GEN8_SP_HLSQ_TIMEOUT_THRESHOLD_DP, 0x00000080, BIT(PIPE_NONE) }, 4069: { GEN8_TPL1_DBG_ECO_CNTL, 0x10000000, BIT(PIPE_NONE) }, 4070: /* BIT(26): Disable final clamp for bicubic filtering */ 4071: { GEN8_TPL1_DBG_ECO_CNTL1, 0x04000724, BIT(PIPE_NONE) }, 4072: { GEN8_UCHE_MODE_CNTL, 0x00020000, BIT(PIPE_NONE) }, 4073: { GEN8_UCHE_CCHE_MODE_CNTL, 0x00001000, BIT(PIPE_NONE) }, MATCH LINES: 4094, 4118, 4127 4082: { GEN8_VFD_CB_LP_REQ_CNT, 0x00100020, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4083: { GEN8_VPC_FLATSHADE_MODE_CNTL, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4084: { GEN8_RB_GC_GMEM_PROTECT, 0x00900000, BIT(PIPE_BR) }, 4085: { 0 }, 4086: }; 4087: 4088: static const struct adreno_gen8_core adreno_gpu_core_gen8_3_0 = { 4089: .base = { 4090: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_3_0, 4091: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 4092: .compatible = "qcom,adreno-gpu-gen8-3-0", 4093: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 4094: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | ADRENO_PREEMPTION | 4095: ADRENO_GMU_AB, 4096: .gpudev = &adreno_gen8_hwsched_gpudev.base, 4097: .perfcounters = &adreno_gen8_perfcounters, 4098: .uche_gmem_alignment = SZ_64M, 4099: .gmem_size = (SZ_512K + SZ_64K), 4100: .bus_width = 32, 4101: .snapshot_size = SZ_8M, 4102: .num_ddr_channels = 2, 4103: .highest_bank_bit = 15, 4104: }, 4105: .sqefw_name = "gen80300_sqe.fw", 4106: .gmufw_name = "gen80300_gmu.bin", 4107: .zap_name = "gen80300_zap.mbn", 4108: .ao_hwcg = gen8_ao_hwcg_regs, 4109: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs), 4110: .gbif = gen8_3_0_gbif_cx_regs, 4111: .gbif_count = ARRAY_SIZE(gen8_3_0_gbif_cx_regs), 4112: .hang_detect_cycles = 0xcfffff, 4113: .protected_regs = gen8_0_0_protected_regs, /* Reuse the protected regs list from Gen8_0_0 */ 4114: .nonctxt_regs = gen8_3_0_nonctxt_regs, 4115: .gmu_hub_clk_freq = 200000000, 4116: .gen8_snapshot_block_list = &gen8_3_0_snapshot_block_list, 4117: .ctxt_record_size = (4558 * SZ_1K), 4118: .preempt_level = 1, 4119: }; 4120: 4121: /* GEN8_6_0 noncontext register list */ 4122: static const struct gen8_nonctxt_regs gen8_6_0_nonctxt_regs[] = { 4123: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 4124: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4125: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4126: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4127: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4128: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4129: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4130: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4131: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4132: /* Configure GBIF GX registers */ 4133: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) }, 4134: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) }, 4135: /* Enable full concurrent resolve and unresolves */ 4136: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 4137: { GEN8_RB_GC_GMEM_PROTECT, 0x02600000, BIT(PIPE_BR) }, 4138: /* Configure number of outstanding transactions to 32 */ 4139: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 4140: /* Configure UCHE request time out to 16 cycles for CCU/UCHE arbitration */ 4141: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 4142: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4143: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4144: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 4145: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 4146: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, 4147: /* Enable contribution of all shader stages to SP perfcounters */ 4148: { GEN8_SP_PERFCTR_SHADER_MASK, 0x0000003f, BIT(PIPE_NONE) }, 4149: /* 4150: * BIT(26): Limit the number of wave-slots for Eviction buffer to 1 per ALU GRP 4151: * BIT(30): Disable LPAC auto-promotion MATCH LINES: 4195, 4220, 4231, 4255 4183: }; 4184: 4185: extern const struct gen8_snapshot_block_list gen8_6_0_snapshot_block_list; 4186: 4187: static const struct adreno_gen8_core adreno_gpu_core_gen8_6_0 = { 4188: .base = { 4189: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_6_0, 4190: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 4191: .compatible = "qcom,adreno-gpu-gen8-6-0", 4192: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 4193: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_AQE | 4194: ADRENO_GMU_WARMBOOT | ADRENO_L3_VOTE | ADRENO_IFPC | 4195: ADRENO_PREEMPTION | ADRENO_BCL | ADRENO_ACD | ADRENO_GMU_AB, 4196: .gpudev = &adreno_gen8_hwsched_gpudev.base, 4197: .perfcounters = &adreno_gen8_perfcounters, 4198: .uche_gmem_alignment = SZ_64M, 4199: .gmem_size = (SZ_2M + SZ_256K + SZ_128K), 4200: .bus_width = 32, 4201: .snapshot_size = SZ_8M, 4202: .num_ddr_channels = 4, 4203: .highest_bank_bit = 16, 4204: }, 4205: .aqefw_name = "gen80000_aqe.fw", 4206: .sqefw_name = "gen80000_sqe.fw", 4207: .gmufw_name = "gen80600_gmu.bin", 4208: .zap_name = "gen80000_zap.mbn", 4209: .ao_hwcg = gen8_ao_hwcg_regs, 4210: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs), 4211: .gbif = gen8_3_0_gbif_cx_regs, 4212: .gbif_count = ARRAY_SIZE(gen8_3_0_gbif_cx_regs), 4213: .hang_detect_cycles = 0xcfffff, 4214: .protected_regs = gen8_0_0_protected_regs, 4215: .nonctxt_regs = gen8_6_0_nonctxt_regs, 4216: .gmu_hub_clk_freq = 200000000, 4217: .gen8_snapshot_block_list = &gen8_6_0_snapshot_block_list, 4218: .noc_timeout_us = 6800, /* 6.8 msec */ 4219: .ctxt_record_size = (3372 * SZ_1K), 4220: .preempt_level = 1, 4221: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 4222: .bcl_data = 1, 4223: }; 4224: 4225: static const struct adreno_gen8_core adreno_gpu_core_gen8_8_0 = { 4226: .base = { 4227: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_8_0, 4228: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 4229: .compatible = "qcom,adreno-gpu-gen8-8-0", 4230: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 4231: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | ADRENO_PREEMPTION | 4232: ADRENO_HW_FENCE | ADRENO_BCL | ADRENO_GMU_AB, 4233: .gpudev = &adreno_gen8_hwsched_gpudev.base, 4234: .perfcounters = &adreno_gen8_perfcounters, 4235: .uche_gmem_alignment = SZ_64M, 4236: .gmem_size = (SZ_512K + SZ_64K), 4237: .bus_width = 32, 4238: .snapshot_size = SZ_8M, 4239: .num_ddr_channels = 1, 4240: .highest_bank_bit = 14, 4241: }, 4242: .sqefw_name = "gen80300_sqe.fw", 4243: .gmufw_name = "gen80800_gmu.bin", 4244: .zap_name = "gen80300_zap.mbn", 4245: .ao_hwcg = gen8_ao_hwcg_regs, 4246: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs), 4247: .gbif = gen8_8_0_gbif_cx_regs, 4248: .gbif_count = ARRAY_SIZE(gen8_8_0_gbif_cx_regs), 4249: .hang_detect_cycles = 0xcfffff, 4250: .protected_regs = gen8_0_0_protected_regs, /* Reuse the protected regs list from Gen8_0_0 */ 4251: .nonctxt_regs = gen8_3_0_nonctxt_regs, 4252: .gmu_hub_clk_freq = 200000000, 4253: .gen8_snapshot_block_list = &gen8_3_0_snapshot_block_list, 4254: .ctxt_record_size = (4558 * SZ_1K), 4255: .preempt_level = 1, 4256: .noc_timeout_us = 3410, /* 3.41 msec */ 4257: .bcl_data = 1, 4258: }; 4259: 4260: /* GEN8_9_0 noncontext register list */ 4261: static const struct gen8_nonctxt_regs gen8_9_0_nonctxt_regs[] = { 4262: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) }, 4263: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 4264: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 4265: /* Disable Dead Draw Merge scheme on RB-HLSQ */ 4266: { GEN8_RB_RBP_CNTL, BIT(5), BIT(PIPE_BV) | BIT(PIPE_BR) }, 4267: { GEN8_RBBM_INTERFACE_HANG_INT_CNTL, 0x0fffffff, BIT(PIPE_NONE) }, 4268: { GEN8_RBBM_POWER_UP_RESET_SW_OVERRIDE, 0x70809060, BIT(PIPE_NONE) }, 4269: { GEN8_RBBM_POWER_UP_RESET_SW_BV_OVERRIDE, 0x30000000, BIT(PIPE_NONE) }, 4270: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, 4271: /* Disable mode_switch optimization in UMAS */ 4272: { GEN8_SP_CHICKEN_BITS, BIT(26), BIT(PIPE_NONE) }, 4273: /* Disable LPAC large-LM mode */ 4274: { GEN8_SP_SS_CHICKEN_BITS_0, BIT(3), BIT(PIPE_NONE) }, 4275: /* Disable PS out of order retire */ 4276: { GEN8_SP_CHICKEN_BITS_2, 0xc21800, BIT(PIPE_NONE) }, 4277: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4278: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4279: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, MATCH LINES: 4298, 4328, 4359, 4369 4286: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4287: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 4288: { GEN8_RB_CCU_DBG_ECO_CNTL, 0x00002200, BIT(PIPE_BR) }, 4289: { GEN8_RB_GC_GMEM_PROTECT, 0x02600000, BIT(PIPE_BR) }, 4290: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 4291: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 4292: { GEN8_VPC_FLATSHADE_MODE_CNTL, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4293: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4294: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4295: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4296: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4297: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4298: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4299: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4300: { GEN8_VFD_DBG_ECO_CNTL, 0x00008000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4301: { GEN8_VFD_CB_BV_THRESHOLD, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4302: { GEN8_VFD_CB_BR_THRESHOLD, 0x00600060, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4303: { GEN8_VFD_CB_BUSY_REQ_CNT, 0x00200020, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4304: { GEN8_VFD_CB_LP_REQ_CNT, 0x00000020, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4305: { GEN8_SP_CHICKEN_BITS_3, 0x00300000, BIT(PIPE_NONE) }, 4306: { GEN8_SP_PERFCTR_SHADER_MASK, 0x0000003f, BIT(PIPE_NONE) }, 4307: /* Ignore HLSQ shared constant feedback from SP */ 4308: { GEN8_SP_HLSQ_DBG_ECO_CNTL_1, BIT(17), BIT(PIPE_NONE) }, 4309: /* Disable CS dead batch merge */ 4310: { GEN8_SP_HLSQ_DBG_ECO_CNTL_2, BIT(24), BIT(PIPE_NONE) }, 4311: { GEN8_SP_HLSQ_TIMEOUT_THRESHOLD_DP, 0x00000080, BIT(PIPE_NONE) }, 4312: { GEN8_SP_READ_SEL, 0x0001ff00, BIT(PIPE_NONE) }, 4313: { GEN8_TPL1_DBG_ECO_CNTL, 0x10100000, BIT(PIPE_NONE) }, 4314: { GEN8_TPL1_DBG_ECO_CNTL1, 0x04000720, BIT(PIPE_NONE) }, 4315: { 0 }, 4316: }; 4317: 4318: extern const struct gen8_snapshot_block_list gen8_9_0_snapshot_block_list; 4319: 4320: static const struct adreno_gen8_core adreno_gpu_core_gen8_9_0 = { 4321: .base = { 4322: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_9_0, 4323: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 4324: .compatible = "qcom,adreno-gpu-gen8-9-0", 4325: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_LPAC | 4326: ADRENO_GMU_WARMBOOT | ADRENO_AQE | ADRENO_IFPC | 4327: ADRENO_CONTENT_PROTECTION | ADRENO_GMU_BASED_DCVS | 4328: ADRENO_DEFER_GMEM_ALLOC | ADRENO_PREEMPTION | ADRENO_GMU_AB | 4329: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_HW_FENCE | 4330: ADRENO_DCVS_PROFILE | ADRENO_GMU_MINBW | 4331: ADRENO_BCL | ADRENO_ACD, 4332: .gpudev = &adreno_gen8_hwsched_gpudev.base, 4333: .perfcounters = &adreno_gen8_perfcounters, 4334: .uche_gmem_alignment = SZ_64M, 4335: .gmem_size = 2432 * SZ_1K, 4336: .bus_width = 32, 4337: .snapshot_size = SZ_8M, 4338: .num_ddr_channels = 4, 4339: .highest_bank_bit = 16, 4340: }, 4341: .aqefw_name = "gen80900_aqe.fw", 4342: .sqefw_name = "gen80900_sqe.fw", 4343: .gmufw_name = "gen80900_gmu.bin", 4344: .zap_name = "gen80900_zap.mbn", 4345: .ao_hwcg = gen8_2_0_ao_hwcg_regs, 4346: .ao_hwcg_count = ARRAY_SIZE(gen8_2_0_ao_hwcg_regs), 4347: .gbif = gen8_0_0_gbif_cx_regs, 4348: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 4349: .hang_detect_cycles = 0xcfffff, 4350: .protected_regs = gen8_2_0_protected_regs, 4351: .nonctxt_regs = gen8_9_0_nonctxt_regs, 4352: .gmu_hub_clk_freq = 200000000, 4353: .gen8_snapshot_block_list = &gen8_9_0_snapshot_block_list, 4354: .fast_bus_hint = true, 4355: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 4356: .noc_timeout_us = 3410, /* 3.41 msec */ 4357: .cl_no_ft_timeout_ms = 6500, 4358: .ctxt_record_size = (3708 * SZ_1K), 4359: .preempt_level = 1, 4360: .therm_cfg = &therm_mit_cfg_8_2_0, 4361: .bcl_data = 1, 4362: }; 4363: 4364: static const struct adreno_a6xx_core adreno_gpu_core_a623 = { 4365: .base = { 4366: DEFINE_ADRENO_REV(ADRENO_REV_A623, 6, 2, 3, ANY_ID), 4367: .features = ADRENO_APRIV | 4368: ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION | 4369: ADRENO_PREEMPTION | ADRENO_ACD, 4370: .gpudev = &adreno_a6xx_gmu_gpudev.base, 4371: .perfcounters = &adreno_a6xx_perfcounters, 4372: .uche_gmem_alignment = SZ_1M + SZ_512K, 4373: .gmem_size = SZ_512K, 4374: .bus_width = 32, 4375: .snapshot_size = SZ_2M, 4376: .chipid = 0x06020300, 4377: .speedbins = KGSL_SPEEDBINS( 4378: { 0, 0 }, 4379: { 185, 0 }, 4380: { 127, 1 }, 4381: ), 4382: .ubwc_mode = 4, 4383: .mal = 32, 4384: .highest_bank_bit = 16, 4385: }, 4386: .prim_fifo_threshold = 0x0010000, 4387: .gmu_major = 2, 4388: .gmu_minor = 0, 4389: .sqefw_name = "a650_sqe.fw", 4390: .gmufw_name = "a623_gmu.bin", 4391: .zap_name = "a623_zap.mbn", 4392: .hwcg = a620_hwcg_regs, 4393: .hwcg_count = ARRAY_SIZE(a620_hwcg_regs), MATCH LINES: 4411, 4412 4399: .disable_tseskip = true, 4400: .pdc_in_aop = true, 4401: .ctxt_record_size = 2496 * 1024, 4402: }; 4403: 4404: extern const struct gen8_snapshot_block_list gen8_10_0_snapshot_block_list; 4405: 4406: static const struct adreno_gen8_core adreno_gpu_core_gen8_10_0 = { 4407: .base = { 4408: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_10_0, 4409: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 4410: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_BCL | ADRENO_ACD 4411: | ADRENO_IFPC | ADRENO_CONTENT_PROTECTION | ADRENO_PREEMPTION, 4412: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION | 4413: ADRENO_CONTENT_PROTECTION | ADRENO_SOFTFUSE, 4414: .compatible = "qcom,adreno-gpu-gen8-10-0", 4415: .gpudev = &adreno_gen8_hwsched_gpudev.base, 4416: .perfcounters = &adreno_gen8_perfcounters, 4417: .uche_gmem_alignment = SZ_64M, 4418: .gmem_size = (15 * SZ_1M + 768 * SZ_1K), 4419: .bus_width = 32, 4420: .snapshot_size = SZ_8M, 4421: .num_ddr_channels = 8, 4422: .chipid = 0x44060000, 4423: .speedbins = KGSL_SPEEDBINS( 4424: { 0, 0 }, 4425: { 388, 1 }, 4426: { 357, 2 }, 4427: { 284, 3 }, 4428: ), 4429: .ubwc_mode = 5, 4430: .mal = 32, 4431: .highest_bank_bit = 16, 4432: .gpu_model = "Adreno X2-85", 4433: }, 4434: .aqefw_name = "gen80100_aqe.fw", 4435: .sqefw_name = "gen80100_sqe.fw", 4436: .gmufw_name = "gen80100_gmu.bin", MATCH LINES: 4453 4441: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 4442: .hang_detect_cycles = 0xcfffff, 4443: .protected_regs = gen8_1_0_protected_regs, 4444: .nonctxt_regs = gen8_1_0_nonctxt_regs, 4445: .gmu_hub_clk_freq = 200000000, 4446: .fast_bus_hint = true, 4447: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 4448: .noc_timeout_us = 3410, /* 3.41 msec */ 4449: .cl_no_ft_timeout_ms = 6500, 4450: .ctxt_record_size = (23088 * SZ_1K), 4451: .bcl_data = 1, 4452: .gen8_snapshot_block_list = &gen8_10_0_snapshot_block_list, 4453: .preempt_level = 1, 4454: }; 4455: 4456: static const struct hfi_clx_table_v2_cmd gen8_11_0_clx_table = { 4457: .version = (2 << 16) | 1, 4458: .domain = { 4459: /* GFX domain */ 4460: { 4461: .data0 = CLX_DATA(60, 5, 0, 1), 4462: .clxt = 0, 4463: .clxh = 0, 4464: .urgmode = 1, 4465: .lkgen = 0, 4466: .currbudget = 100, 4467: }, 4468: /* MxG domain */ 4469: { 4470: .data0 = CLX_DATA(30, 1, 1, 1), 4471: .clxt = 0, 4472: .clxh = 0, 4473: .urgmode = 1, 4474: .lkgen = 0, 4475: .currbudget = 100, 4476: }, 4477: }, MATCH LINES: 4639 4627: { 0 }, 4628: }; 4629: 4630: /* GEN8_11_0 noncontext register list */ 4631: static const struct gen8_nonctxt_regs gen8_11_0_nonctxt_regs[] = { 4632: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 4633: { GEN8_CP_MULTIDRAW_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4634: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4635: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4636: { GEN8_GRAS_NC_MODE_CNTL, 0x00000220, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4637: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4638: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4639: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4640: /* BIT(11): Disable skipIdx to avoid PDMA hang with restart-index draws */ 4641: { GEN8_PC_CHICKEN_BITS_1, 0x00000803, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4642: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4643: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4644: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4645: /* 4646: * BIT(28): Disable GS Quad primitive 4647: * BIT(30): Disable skipIdx to avoid PDMA hang with restart-index draws 4648: */ 4649: { GEN8_PC_CHICKEN_BITS_5, BIT(28) | BIT(30), BIT(PIPE_BV) | BIT(PIPE_BR) }, 4650: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 4651: /* 4652: * BIT(10): Disable sysmem nonfclear feature 4653: * BIT(9): Disable DINT to c/z be data forwarding 4654: */ 4655: { GEN8_RB_CCU_DBG_ECO_CNTL, BIT(10) | BIT(9), BIT(PIPE_BR) }, 4656: { GEN8_RB_CCU_NC_MODE_CNTL, 0x00000002, BIT(PIPE_BR) }, 4657: { GEN8_RB_CMP_NC_MODE_CNTL, 0x00028000, BIT(PIPE_BR) }, 4658: /* Disable early EOBlk return */ 4659: { GEN8_RB_DBG_ECO_CNTL, BIT(17), BIT(PIPE_BV) | BIT(PIPE_BR) }, 4660: { GEN8_RB_GC_GMEM_PROTECT, 0x12000000, BIT(PIPE_BR) }, 4661: /* Disable pre-mvcc dead draw merge scheme on LRZ-RB */ 4662: { GEN8_RB_RBP_CNTL, BIT(6), BIT(PIPE_BV) | BIT(PIPE_BR) }, 4663: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, MATCH LINES: 4762, 4779 4750: .hang_detect_cycles = 0xcfffff, 4751: .protected_regs = gen8_11_0_protected_regs, 4752: .nonctxt_regs = gen8_11_0_nonctxt_regs, 4753: .gmu_hub_clk_freq = 150000000, 4754: .gen8_snapshot_block_list = &gen8_11_0_snapshot_block_list, 4755: .fast_bus_hint = true, 4756: .bcl_data = 1, 4757: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 4758: .noc_timeout_us = 3410, /* 3.41 msec */ 4759: .cl_no_ft_timeout_ms = 6500, 4760: .ctxt_record_size = (19708 * SZ_1K), 4761: .limits_mit_cfg = &gen8_11_0_limits_mit_cfg, 4762: .preempt_level = 1, 4763: .gmu_mx_gdsc = true, 4764: .three_rail_memory = true, 4765: .malu = true, 4766: .clx_tbl = &gen8_11_0_clx_table, 4767: }; 4768: 4769: /* GEN8_11_1 noncontext register list */ 4770: static const struct gen8_nonctxt_regs gen8_11_1_nonctxt_regs[] = { 4771: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 4772: { GEN8_CP_MULTIDRAW_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4773: /* Keep the raster direction as topleft */ 4774: { GEN8_GRAS_DBG_ECO_CNTL, 0x01000800, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4775: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4776: /* GEN8_GRAS_NC_MODE_CNTL explicitly set elsewhere */ 4777: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4778: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4779: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4780: /* BIT(11): Disable skipIdx to avoid PDMA hang with restart-index draws */ 4781: { GEN8_PC_CHICKEN_BITS_1, 0x00000803, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4782: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4783: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4784: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4785: /* 4786: * BIT(28): Disable GS Quad primitive 4787: * BIT(30): Disable skipIdx to avoid PDMA hang with restart-index draws 4788: */ 4789: { GEN8_PC_CHICKEN_BITS_5, BIT(28) | BIT(30), BIT(PIPE_BV) | BIT(PIPE_BR) }, 4790: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 4791: /* 4792: * BIT(10): Disable sysmem nonfclear feature 4793: * BIT(9): Disable DINT to c/z be data forwarding 4794: */ 4795: { GEN8_RB_CCU_DBG_ECO_CNTL, BIT(10) | BIT(9), BIT(PIPE_BR) }, 4796: /* GEN8_RB_CCU_NC_MODE_CNTL explicitly set elsewhere */ 4797: /* GEN8_RB_CMP_NC_MODE_CNTL explicitly set elsewhere */ 4798: /* Disable early EOBlk return */ 4799: { GEN8_RB_DBG_ECO_CNTL, BIT(17), BIT(PIPE_BV) | BIT(PIPE_BR) }, 4800: { GEN8_RB_GC_GMEM_PROTECT, 0x12000000, BIT(PIPE_BR) }, 4801: /* 4802: * BIT(5): Disable dead draw merge scheme on RB-HLSQ 4803: * BIT(6): Disable pre-mvcc dead draw merge scheme on LRZ-RB MATCH LINES: 4863, 4869 4851: { GEN8_VFD_CB_BUSY_REQ_CNT, 0x00200020, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4852: { GEN8_VFD_CB_LP_REQ_CNT, 0x00080020, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4853: { GEN8_VPC_FLATSHADE_MODE_CNTL, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4854: { GEN8_VSC_VISIBILITY_FLUSH_CNTL, 0x00080004, BIT(PIPE_NONE) }, 4855: { 0 }, 4856: }; 4857: 4858: static const struct adreno_gen8_core adreno_gpu_core_gen8_11_1 = { 4859: .base = { 4860: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_11_1, 4861: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 4862: .compatible = "qcom,adreno-gpu-gen8-11-1", 4863: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_LPAC | ADRENO_PREEMPTION | 4864: ADRENO_GMU_WARMBOOT | ADRENO_GMU_BASED_DCVS | ADRENO_CLX | 4865: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_AQE | ADRENO_CONTENT_PROTECTION | 4866: ADRENO_BCL | ADRENO_DCVS_PROFILE | ADRENO_IFPC | ADRENO_GMU_MINBW | 4867: ADRENO_DEFER_GMEM_ALLOC | ADRENO_GMU_FAST_CONTEXT_DESTROY | 4868: ADRENO_ACD | ADRENO_GMU_AB | ADRENO_HW_FENCE, 4869: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION | 4870: ADRENO_IFPC | ADRENO_AQE | ADRENO_CONTENT_PROTECTION | ADRENO_CLX | 4871: ADRENO_GMU_FAST_CONTEXT_DESTROY | ADRENO_GMU_BASED_DCVS | ADRENO_ACD, 4872: .gpudev = &adreno_gen8_hwsched_gpudev.base, 4873: .perfcounters = &adreno_gen8_2_x_perfcounters, 4874: .uche_gmem_alignment = SZ_64M, 4875: .gmem_size = 18 * SZ_1M, 4876: .bus_width = 32, 4877: .snapshot_size = SZ_8M, 4878: .num_ddr_channels = 4, 4879: .highest_bank_bit = 16, 4880: .chipid = 0x44051401, 4881: .speedbins = KGSL_SPEEDBINS( 4882: { 0, 0 }, 4883: { 284, 2 }, 4884: { 216, 3 }, 4885: ), 4886: .ubwc_mode = 7, 4887: .mal = 32, 4888: }, 4889: .aqefw_name = "gen81100_aqe.fw", 4890: .sqefw_name = "gen81100_sqe.fw", 4891: .gmufw_name = "gen81100_gmu.bin", 4892: .zap_name = "gen81100_zap.mbn", 4893: .ao_hwcg = gen8_2_0_ao_hwcg_regs, MATCH LINES: 4909, 4925 4897: .hang_detect_cycles = 0xcfffff, 4898: .protected_regs = gen8_11_0_protected_regs, 4899: .nonctxt_regs = gen8_11_1_nonctxt_regs, 4900: .gmu_hub_clk_freq = 150000000, 4901: .gen8_snapshot_block_list = &gen8_11_0_snapshot_block_list, 4902: .fast_bus_hint = true, 4903: .bcl_data = GEN8_2_X_BCL_DATA, 4904: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(4224, 4), 4905: .noc_timeout_us = 3410, /* 3.41 msec */ 4906: .cl_no_ft_timeout_ms = 6500, 4907: .ctxt_record_size = (19708 * SZ_1K), 4908: .limits_mit_cfg = &gen8_11_0_limits_mit_cfg, 4909: .preempt_level = 1, 4910: .gmu_mx_gdsc = true, 4911: .three_rail_memory = true, 4912: .malu = true, 4913: .clx_tbl = &gen8_11_0_clx_table, 4914: }; 4915: 4916: static const struct gen8_nonctxt_regs gen8_14_0_nonctxt_regs[] = { 4917: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 4918: { GEN8_CP_MULTIDRAW_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4919: /* Keep the raster direction as topleft */ 4920: { GEN8_GRAS_DBG_ECO_CNTL, 0x01000800, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4921: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4922: /* GEN8_GRAS_NC_MODE_CNTL explicitly set elsewhere */ 4923: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4924: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4925: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4926: /* BIT(11): Disable skipIdx to avoid PDMA hang with restart-index draws */ 4927: { GEN8_PC_CHICKEN_BITS_1, 0x00000803, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4928: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4929: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4930: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4931: /* 4932: * BIT(28): Disable GS Quad primitive 4933: * BIT(30): Disable skipIdx to avoid PDMA hang with restart-index draws 4934: */ 4935: { GEN8_PC_CHICKEN_BITS_5, BIT(28) | BIT(30), BIT(PIPE_BV) | BIT(PIPE_BR) }, 4936: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 4937: /* 4938: * BIT(10): Disable sysmem nonfclear feature 4939: * BIT(9): Disable DINT to c/z be data forwarding 4940: */ 4941: { GEN8_RB_CCU_DBG_ECO_CNTL, BIT(10) | BIT(9), BIT(PIPE_BR) }, 4942: /* GEN8_RB_CCU_NC_MODE_CNTL explicitly set elsewhere */ 4943: /* GEN8_RB_CMP_NC_MODE_CNTL explicitly set elsewhere */ 4944: /* Disable early EOBlk return */ 4945: { GEN8_RB_DBG_ECO_CNTL, BIT(17), BIT(PIPE_BV) | BIT(PIPE_BR) }, 4946: { GEN8_RB_GC_GMEM_PROTECT, 0xC000000, BIT(PIPE_BR) }, 4947: /* 4948: * BIT(5): Disable dead draw merge scheme on RB-HLSQ 4949: * BIT(6): Disable pre-mvcc dead draw merge scheme on LRZ-RB MATCH LINES: 5007, 5013 4995: { GEN8_VFD_CB_BUSY_REQ_CNT, 0x00200020, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4996: { GEN8_VFD_CB_LP_REQ_CNT, 0x00080020, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4997: { GEN8_VPC_FLATSHADE_MODE_CNTL, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4998: { GEN8_VSC_VISIBILITY_FLUSH_CNTL, 0x00080004, BIT(PIPE_NONE) }, 4999: { 0 }, 5000: }; 5001: 5002: static const struct adreno_gen8_core adreno_gpu_core_gen8_14_0 = { 5003: .base = { 5004: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_14_0, 5005: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 5006: .compatible = "qcom,adreno-gpu-gen8-14-0", 5007: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_LPAC | ADRENO_PREEMPTION | 5008: ADRENO_GMU_WARMBOOT | ADRENO_GMU_BASED_DCVS | 5009: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_AQE | ADRENO_CONTENT_PROTECTION | 5010: ADRENO_DCVS_PROFILE | ADRENO_IFPC | ADRENO_GMU_MINBW | 5011: ADRENO_DEFER_GMEM_ALLOC | ADRENO_GMU_FAST_CONTEXT_DESTROY | 5012: ADRENO_GMU_AB | ADRENO_HW_FENCE | ADRENO_CLX | ADRENO_ACD, 5013: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION | 5014: ADRENO_IFPC | ADRENO_AQE | ADRENO_CONTENT_PROTECTION | ADRENO_CLX | 5015: ADRENO_GMU_FAST_CONTEXT_DESTROY | ADRENO_GMU_BASED_DCVS, 5016: .gpudev = &adreno_gen8_hwsched_gpudev.base, 5017: .perfcounters = &adreno_gen8_2_x_perfcounters, 5018: .uche_gmem_alignment = SZ_64M, 5019: .gmem_size = 12 * SZ_1M, 5020: .bus_width = 32, 5021: .snapshot_size = SZ_8M, 5022: .num_ddr_channels = 4, 5023: .highest_bank_bit = 16, 5024: .chipid = 0x44041400, 5025: .speedbins = KGSL_SPEEDBINS( 5026: { 0, 0 }, 5027: { 216, 0 }, 5028: { 284, 1 }, 5029: ), 5030: .ubwc_mode = 7, 5031: .mal = 32, 5032: }, 5033: .aqefw_name = "gen81100_aqe.fw", 5034: .sqefw_name = "gen81100_sqe.fw", 5035: .gmufw_name = "gen81400_gmu.bin", 5036: .zap_name = "gen81100_zap.mbn", 5037: .ao_hwcg = gen8_2_0_ao_hwcg_regs, MATCH LINES: 5052 5040: .gbif_count = ARRAY_SIZE(gen8_11_0_gbif_cx_regs), 5041: .hang_detect_cycles = 0xcfffff, 5042: .protected_regs = gen8_11_0_protected_regs, 5043: .nonctxt_regs = gen8_14_0_nonctxt_regs, 5044: .gmu_hub_clk_freq = 150000000, 5045: .gen8_snapshot_block_list = &gen8_11_0_snapshot_block_list, 5046: .fast_bus_hint = true, 5047: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(4224, 4), 5048: .noc_timeout_us = 3410, /* 3.41 msec */ 5049: .cl_no_ft_timeout_ms = 6500, 5050: .ctxt_record_size = (13564 * SZ_1K), 5051: .limits_mit_cfg = &gen8_11_0_limits_mit_cfg, 5052: .preempt_level = 1, 5053: .gmu_mx_gdsc = true, 5054: .three_rail_memory = true, 5055: .malu = false, 5056: .clx_tbl = &gen8_14_0_clx_table, 5057: }; 5058: 5059: static const struct adreno_gpu_core *adreno_gpulist[] = { 5060: &adreno_gpu_core_a306, /* Deprecated */ 5061: &adreno_gpu_core_a306a, /* Deprecated */ 5062: &adreno_gpu_core_a304, /* Deprecated */ 5063: &adreno_gpu_core_a405, /* Deprecated */ 5064: &adreno_gpu_core_a418, /* Deprecated */ 5065: &adreno_gpu_core_a420, /* Deprecated */ 5066: &adreno_gpu_core_a430, /* Deprecated */ 5067: &adreno_gpu_core_a530v1, /* Deprecated */ 5068: &adreno_gpu_core_a530v2.base, 5069: &adreno_gpu_core_a530v3.base, 5070: &adreno_gpu_core_a505.base, 5071: &adreno_gpu_core_a506.base, 5072: &adreno_gpu_core_a510.base, 5073: &adreno_gpu_core_a540v1, /* Deprecated */ 5074: &adreno_gpu_core_a540v2.base, 5075: &adreno_gpu_core_a512.base, 5076: &adreno_gpu_core_a508.base, --- FILE: \adreno.c | HITS: 10 --- MATCH LINES: 76, 78, 106 64: * If a ucode is shared by multiple targets, there will be multiple instances 65: * of this structure embedded in the ucode. Instances of this structure will be 66: * present immediately after ctxt_record_info. 67: */ 68: struct gpu_ctxt_record { 69: /** 70: * @hw_version: GPU hardware version 71: * [15:0]: Step, should be 0. 72: * [27:16]: Minor 73: * [31:28]: Major 74: */ 75: u32 hw_version; 76: /** @ctxt_record_size: Size of preemption record in KB */ 77: u32 ctxt_record_size; 78: /** aqe_size: Size of AQE in preemption record in KB */ 79: u32 aqe_size; 80: } __packed; 81: 82: struct ctxt_record_info { 83: /** 84: * @version: Version of the ctxt_record_info structure 85: * [11:0]: Minor, [31:12]: Major. 86: * Major version changes whenever a true incompatibility is generated. 87: */ 88: u32 version; 89: /** @dwords_per_gpu: DWORD size of struct gpu_ctxt_record */ 90: u16 dwords_per_gpu; 91: /** @num_gpus: For targets that share same ucode binary, num_gpus > 1, otherwise 1 */ 92: u16 num_gpus; 93: /** @reserved: for future use */ 94: u32 reserved[2]; 95: } __packed; 96: 97: static void adreno_unbind(struct device *dev); 98: static void adreno_input_work(struct work_struct *work); 99: static int adreno_soft_reset(struct kgsl_device *device); 100: static unsigned int counter_delta(struct kgsl_device *device, 101: unsigned int reg, unsigned int *counter); 102: static struct device_node * 103: adreno_get_gpu_model_node(struct platform_device *pdev); 104: 105: static struct adreno_device device_3d0; 106: static bool adreno_preemption_enable; 107: static u32 kgsl_gpu_sku_override = U32_MAX; 108: static u32 kgsl_gpu_speed_bin_override = U32_MAX; 109: u32 adreno_slice_mask_override = U32_MAX; 110: 111: /* Nice level for the higher priority GPU start thread */ 112: int adreno_wake_nice = -7; 113: 114: /* Number of milliseconds to stay active after a wake on touch */ 115: unsigned int adreno_wake_timeout = 100; 116: 117: static u32 get_ucode_version(const u32 *data) 118: { 119: u32 version; 120: 121: version = data[1]; 122: 123: if ((version & 0xf) != 0xa) 124: return version; 125: 126: version &= ~0xfff; 127: return version | ((data[3] & 0xfff000) >> 12); 128: } 129: 130: int adreno_populate_ctxt_record_size(struct adreno_device *adreno_dev) MATCH LINES: 1754, 1755 1742: static int adreno_probe_llcc(struct adreno_device *adreno_dev, 1743: struct platform_device *pdev) 1744: { 1745: return 0; 1746: } 1747: #endif 1748: 1749: const char *hfi_feature_to_string(u32 feature) 1750: { 1751: switch (feature) { 1752: case HFI_FEATURE_HWSCHED: 1753: return "HWSCHED"; 1754: case HFI_FEATURE_PREEMPTION: 1755: return "PREEMPTION"; 1756: case HFI_FEATURE_LM: 1757: return "LM"; 1758: case HFI_FEATURE_IFPC: 1759: return "IFPC"; 1760: case HFI_FEATURE_BCL: 1761: return "BCL"; 1762: case HFI_FEATURE_ACD: 1763: return "ACD"; 1764: case HFI_FEATURE_KPROF: 1765: return "KPROF"; 1766: case HFI_FEATURE_BAIL_OUT_TIMER: 1767: return "BAIL_OUT_TIMER"; 1768: case HFI_FEATURE_GMU_STATS: 1769: return "GMU_STATS"; 1770: case HFI_FEATURE_CLX: 1771: return "CLX"; 1772: case HFI_FEATURE_LSR: 1773: return "LSR"; 1774: case HFI_FEATURE_LPAC: 1775: return "LPAC"; 1776: case HFI_FEATURE_HW_FENCE: 1777: return "HW_FENCE"; 1778: case HFI_FEATURE_PERF_NORETAIN: 1779: return "PERF_NORETAIN"; MATCH LINES: 2185, 2186 2173: kgsl_mmu_set_feature(device, KGSL_MMU_SMMU_APERTURE); 2174: 2175: if (ADRENO_FEATURE(adreno_dev, ADRENO_IOCOHERENT)) 2176: kgsl_mmu_set_feature(device, KGSL_MMU_IO_COHERENT); 2177: 2178: /* 2179: * Support VBOs on hardware where HLOS has access to PRR registers 2180: * configuration. 2181: */ 2182: if (!adreno_is_a650(adreno_dev)) 2183: kgsl_mmu_set_feature(device, KGSL_MMU_SUPPORT_VBO); 2184: 2185: if (adreno_preemption_enable) 2186: adreno_dev->preempt_override = true; 2187: 2188: device->pwrctrl.bus_width = adreno_dev->gpucore->bus_width; 2189: 2190: device->mmu.secured = (IS_ENABLED(CONFIG_QCOM_SECURE_BUFFER) && 2191: ADRENO_FEATURE(adreno_dev, ADRENO_CONTENT_PROTECTION) && 2192: adreno_dev->zap_enabled); 2193: 2194: /* Probe the LLCC - this could return -EPROBE_DEFER */ 2195: status = adreno_probe_llcc(adreno_dev, pdev); 2196: if (status) 2197: goto err_bus_close; 2198: 2199: /* 2200: * IF the GPU HTW slice was successsful set the MMU feature so the 2201: * domain can set the appropriate attributes 2202: */ 2203: if (!IS_ERR_OR_NULL(adreno_dev->gpuhtw_llc_slice)) 2204: kgsl_mmu_set_feature(device, KGSL_MMU_LLCC_ENABLE); 2205: 2206: /* 2207: * Force no write allocate for A5x, A6x and all gen7 targets 2208: * except gen_7_9_x and gen_7_14_0_family. gen_7_9_x and gen_7_14_0_family 2209: * use write allocate. 2210: */ MATCH LINES: 3764 3752: * will never come. 3753: */ 3754: 3755: if (adreno_gpu_fault(adreno_dev) != 0) 3756: return -EDEADLK; 3757: 3758: if (adreno_isidle(adreno_dev)) 3759: return 0; 3760: 3761: } while (time_before(jiffies, wait)); 3762: 3763: /* 3764: * Under rare conditions, preemption can cause the while loop to exit 3765: * without checking if the gpu is idle. check one last time before we 3766: * return failure. 3767: */ 3768: if (adreno_gpu_fault(adreno_dev) != 0) 3769: return -EDEADLK; 3770: 3771: if (adreno_isidle(adreno_dev)) 3772: return 0; 3773: 3774: return -ETIMEDOUT; 3775: } 3776: 3777: /** 3778: * adreno_wait_idle() - wait for the GPU hardware to go idle 3779: * @device: Pointer to the KGSL device structure for the GPU 3780: * 3781: * Wait up to ADRENO_IDLE_TIMEOUT milliseconds for the GPU hardware to go quiet. 3782: * Caller must hold the device mutex, and must not hold the dispatcher mutex. 3783: */ 3784: 3785: int adreno_wait_idle(struct kgsl_device *device) 3786: { 3787: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 3788: int ret; MATCH LINES: 5120, 5121 5108: 5109: return ret; 5110: } 5111: 5112: static void __exit kgsl_3d_exit(void) 5113: { 5114: platform_driver_unregister(&adreno_platform_driver); 5115: gmu_core_unregister(); 5116: kgsl_mmu_exit(); 5117: kgsl_core_exit(); 5118: } 5119: 5120: module_param_named(preempt_enable, adreno_preemption_enable, bool, 0600); 5121: MODULE_PARM_DESC(preempt_enable, "Enable GPU HW Preemption"); 5122: 5123: module_param_named(gpu_sku_override, kgsl_gpu_sku_override, uint, 0600); 5124: MODULE_PARM_DESC(gpu_sku_override, "Override SKU code identifier for GPU driver"); 5125: 5126: module_param_named(gpu_speed_bin_override, kgsl_gpu_speed_bin_override, uint, 0600); 5127: MODULE_PARM_DESC(gpu_speed_bin_override, "Override GPU speed bin"); 5128: 5129: module_param_named(slice_mask_override, adreno_slice_mask_override, uint, 0600); 5130: MODULE_PARM_DESC(slice_mask_override, "Override GPU slice mask"); 5131: 5132: module_init(kgsl_3d_init); 5133: module_exit(kgsl_3d_exit); 5134: 5135: MODULE_DESCRIPTION("3D Graphics driver"); 5136: MODULE_LICENSE("GPL v2"); 5137: MODULE_SOFTDEP("pre: arm_smmu nvmem_qfprom socinfo governor_msm_adreno_tz governor_gpubw_mon governor_msm_adreno_ro"); 5138: #if (KERNEL_VERSION(6, 13, 0) <= LINUX_VERSION_CODE) 5139: MODULE_IMPORT_NS("DMA_BUF"); 5140: #elif (KERNEL_VERSION(5, 18, 0) <= LINUX_VERSION_CODE) 5141: MODULE_IMPORT_NS(DMA_BUF); 5142: #endif --- FILE: \adreno.h | HITS: 85 --- MATCH LINES: 22, 23, 24, 25, 26, 27, 29, 30, 31, 33 10: #include 11: #include 12: #include 13: #include "adreno_coresight.h" 14: #include "adreno_dispatch.h" 15: #include "adreno_drawctxt.h" 16: #include "adreno_hwsched.h" 17: #include "adreno_perfcounter.h" 18: #include "adreno_profile.h" 19: #include "adreno_ringbuffer.h" 20: #include "kgsl_sharedmem.h" 21: 22: /* Used to point CP to the SMMU record during preemption */ 23: #define SET_PSEUDO_SMMU_INFO 0 24: /* Used to inform CP where to save preemption data at the time of switch out */ 25: #define SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR 1 26: /* Used to inform CP where to save secure preemption data at the time of switch out */ 27: #define SET_PSEUDO_PRIV_SECURE_SAVE_ADDR 2 28: /* Used to inform CP where to save per context non-secure data at the time of switch out */ 29: #define SET_PSEUDO_NON_PRIV_SAVE_ADDR 3 30: /* Used to inform CP where to save preemption counter data at the time of switch out */ 31: #define SET_PSEUDO_COUNTER 4 32: 33: /* Index to preemption scratch buffer to store current QOS value */ 34: #define QOS_VALUE_IDX KGSL_PRIORITY_MAX_RB_LEVELS 35: 36: /* Size of the user context record block (in bytes) */ 37: #define ADRENO_CP_CTXRECORD_USER_RESTORE_SIZE (192 * SZ_1K) 38: 39: /* ADRENO_DEVICE - Given a kgsl_device return the adreno device struct */ 40: #define ADRENO_DEVICE(device) \ 41: container_of(device, struct adreno_device, dev) 42: 43: /* KGSL_DEVICE - given an adreno_device, return the KGSL device struct */ 44: #define KGSL_DEVICE(_dev) (&((_dev)->dev)) 45: 46: /* ADRENO_CONTEXT - Given a context return the adreno context struct */ 47: #define ADRENO_CONTEXT(context) \ 48: container_of(context, struct adreno_context, base) 49: 50: /* ADRENO_GPU_DEVICE - Given an adreno device return the GPU specific struct */ 51: #define ADRENO_GPU_DEVICE(_a) ((_a)->gpucore->gpudev) 52: 53: /* 54: * ADRENO_POWER_OPS - Given an adreno device return the GPU specific power 55: * ops 56: */ 57: #define ADRENO_POWER_OPS(_a) ((_a)->gpucore->gpudev->power_ops) MATCH LINES: 83, 93, 96, 111, 140, 141 71: #define ADRENO_REV_MINOR(_rev) FIELD_GET(GENMASK(15, 8), _rev) 72: #define ADRENO_REV_PATCH(_rev) FIELD_GET(GENMASK(7, 0), _rev) 73: 74: #define ADRENO_GMU_REV(_rev) \ 75: (FIELD_PREP(GENMASK(31, 24), ADRENO_REV_MAJOR(_rev)) | \ 76: FIELD_PREP(GENMASK(23, 16), ADRENO_REV_MINOR(_rev)) | \ 77: FIELD_PREP(GENMASK(15, 8), ADRENO_REV_PATCH(_rev))) 78: 79: /* ADRENO_GPUREV - Return the GPU ID for the given adreno_device */ 80: #define ADRENO_GPUREV(_a) ((_a)->gpucore->gpurev) 81: 82: /* 83: * Disable local interrupts and CPU preemption to avoid interruptions 84: * while holding the CP semaphore; otherwise, it could stall the CP. 85: * Make sure to call ADRENO_RELEASE_CP_SEMAPHORE after calling the 86: * below macro to reenable CPU interrupts. 87: */ 88: #define ADRENO_ACQUIRE_CP_SEMAPHORE(_adreno_dev, _flags) \ 89: ({ \ 90: bool ret = true; \ 91: if ((_adreno_dev)->gpucore->gpudev->acquire_cp_semaphore) { \ 92: local_irq_save(_flags); \ 93: preempt_disable(); \ 94: ret = (_adreno_dev)->gpucore->gpudev->acquire_cp_semaphore(_adreno_dev); \ 95: if (!ret) { \ 96: preempt_enable(); \ 97: local_irq_restore(_flags); \ 98: dev_err_ratelimited(KGSL_DEVICE(_adreno_dev)->dev, \ 99: "Timed out waiting to acquire CP semaphore: status=0x%08x\n", \ 100: ret); \ 101: } \ 102: } \ 103: ret; \ 104: }) 105: 106: #define ADRENO_RELEASE_CP_SEMAPHORE(_adreno_dev, _flags) \ 107: ({ \ 108: do { \ 109: if ((_adreno_dev)->gpucore->gpudev->release_cp_semaphore) { \ 110: (_adreno_dev)->gpucore->gpudev->release_cp_semaphore(_adreno_dev); \ 111: preempt_enable(); \ 112: local_irq_restore(_flags); \ 113: } \ 114: } while (0);\ 115: }) 116: 117: /* 118: * ADRENO_FEATURE - return true if the specified feature is supported by the GPU 119: * core 120: */ 121: #define ADRENO_FEATURE(_dev, _bit) \ 122: (((_dev)->gpucore->features_standard && \ 123: of_device_is_compatible((_dev)->dev.pdev->dev.of_node, "qcom,adreno")) \ 124: ? ((_dev)->gpucore->features_standard & (_bit)) \ 125: : ((_dev)->gpucore->features & (_bit))) 126: 127: /** 128: * ADRENO_QUIRK - return true if the specified quirk is required by the GPU 129: */ 130: #define ADRENO_QUIRK(_dev, _bit) \ 131: ((_dev)->quirks & (_bit)) 132: 133: #define ADRENO_FW(a, f) (&(a->fw[f])) 134: 135: /* Adreno core features */ 136: /* The core supports SP/TP hw controlled power collapse */ 137: #define ADRENO_SPTP_PC BIT(0) 138: /* The GPU supports content protection */ 139: #define ADRENO_CONTENT_PROTECTION BIT(1) 140: /* The GPU supports preemption */ 141: #define ADRENO_PREEMPTION BIT(2) 142: /* The GPMU supports Limits Management */ 143: #define ADRENO_LM BIT(3) 144: /* The GPU supports retention for cpz registers */ 145: #define ADRENO_CPZ_RETENTION BIT(4) 146: /* The core has soft fault detection available */ 147: #define ADRENO_SOFT_FAULT_DETECT BIT(5) 148: /* The GMU supports IFPC power management*/ 149: #define ADRENO_IFPC BIT(6) 150: /* The core supports IO-coherent memory */ 151: #define ADRENO_IOCOHERENT BIT(7) 152: /* 153: * The GMU supports Adaptive Clock Distribution (ACD) 154: * for droop mitigation 155: */ 156: #define ADRENO_ACD BIT(8) 157: /* Cooperative reset enabled GMU */ 158: #define ADRENO_COOP_RESET BIT(9) 159: /* Indicates that the specific target is no longer supported */ 160: #define ADRENO_DEPRECATED BIT(10) 161: /* The target supports ringbuffer level APRIV */ 162: #define ADRENO_APRIV BIT(11) 163: /* The GMU supports Battery Current Limiting */ 164: #define ADRENO_BCL BIT(12) 165: /* L3 voting is supported with L3 constraints */ MATCH LINES: 187 175: /* AQE supported on this target */ 176: #define ADRENO_AQE BIT(18) 177: /* Warm Boot supported on this target */ 178: #define ADRENO_GMU_WARMBOOT BIT(19) 179: /* The GPU supports CLX */ 180: #define ADRENO_CLX BIT(20) 181: /* Enable GMU support for GMU based thermal mitigation */ 182: #define ADRENO_GMU_THERMAL_MITIGATION BIT(21) 183: /* GMU Based DCVS */ 184: #define ADRENO_GMU_BASED_DCVS BIT(22) 185: /* RT hint feature for RB0 workloads */ 186: #define ADRENO_RT_HINT BIT(23) 187: /* Defer allocation of preemption record gmem memory when needed */ 188: #define ADRENO_DEFER_GMEM_ALLOC BIT(24) 189: /* The GMU supports MINBW voting */ 190: #define ADRENO_GMU_MINBW BIT(25) 191: /* Enable GMU Based DCVS profile */ 192: #define ADRENO_DCVS_PROFILE BIT(26) 193: /* Enable TSENSE power savings during sleep */ 194: #define ADRENO_TSENSE_DYNAMIC_PERIOD BIT(27) 195: /* Enable GMU Based AB voting */ 196: #define ADRENO_GMU_AB BIT(28) 197: /* Enable GMU Fast Context Destroy optimization */ 198: #define ADRENO_GMU_FAST_CONTEXT_DESTROY BIT(29) 199: /* 200: * The target uses the GPU_CX_MISC_SW_FUSE_FREQ_LIMIT_STATUS register to 201: * get combined (HW + SW) speedbin when no nvmem speed_bin cell exists. 202: */ 203: #define ADRENO_SOFTFUSE BIT_ULL(32) 204: /* 205: * Adreno GPU quirks - control bits for various workarounds 206: */ 207: 208: /* Set TWOPASSUSEWFI in PC_DBG_ECO_CNTL (5XX/6XX) */ 209: #define ADRENO_QUIRK_TWO_PASS_USE_WFI BIT(0) 210: /* Submit critical packets at GPU wake up */ 211: #define ADRENO_QUIRK_CRITICAL_PACKETS BIT(1) MATCH LINES: 341, 372, 373, 375, 377, 378, 381, 382, 383, 384, 385, 386, 387, 390, 391, 392, 393, 394, 395, 396, 420, 421, 423, 424, 425, 426, 427, 428, 430, 435 329: ADRENO_REV_GEN8_8_0 = ADRENO_GPUREV_VALUE(8, 8, 0), 330: ADRENO_REV_GEN8_9_0 = ADRENO_GPUREV_VALUE(8, 9, 0), 331: ADRENO_REV_GEN8_10_0 = ADRENO_GPUREV_VALUE(8, 10, 0), 332: ADRENO_REV_GEN8_11_0 = ADRENO_GPUREV_VALUE(8, 11, 0), 333: ADRENO_REV_GEN8_11_1 = ADRENO_GPUREV_VALUE(8, 11, 1), 334: ADRENO_REV_GEN8_14_0 = ADRENO_GPUREV_VALUE(8, 14, 0), 335: }; 336: 337: #define ADRENO_SOFT_FAULT BIT(0) 338: #define ADRENO_HARD_FAULT BIT(1) 339: #define ADRENO_TIMEOUT_FAULT BIT(2) 340: #define ADRENO_IOMMU_STALL_ON_PAGE_FAULT BIT(3) 341: #define ADRENO_PREEMPT_FAULT BIT(4) 342: #define ADRENO_GMU_FAULT BIT(5) 343: #define ADRENO_CTX_DETATCH_TIMEOUT_FAULT BIT(6) 344: #define ADRENO_GMU_FAULT_SKIP_SNAPSHOT BIT(7) 345: #define ADRENO_FAULT_TYPES 8 346: 347: /** 348: * Bit fields for GPU_CX_MISC_CX_AHB_*_CNTL registers 349: * AHB_TXFRTIMEOUTRELEASE [8:8] 350: * AHB_TXFRTIMEOUTENABLE [9:9] 351: * AHB_RESPONDERROR [11:11] 352: * AHB_ERRORSTATUSENABLE [12:12] 353: */ 354: #define ADRENO_AHB_CNTL_DEFAULT (BIT(12) | BIT(11) | BIT(9) | BIT(8)) 355: 356: enum adreno_pipe_type { 357: PIPE_NONE = 0, 358: PIPE_BR = 1, 359: PIPE_BV = 2, 360: PIPE_LPAC = 3, 361: PIPE_AQE0 = 4, 362: PIPE_AQE1 = 5, 363: PIPE_DDE_BR = 6, 364: PIPE_DDE_BV = 7, 365: }; 366: 367: /* number of throttle counters for DCVS adjustment */ 368: #define ADRENO_GPMU_THROTTLE_COUNTERS 4 369: 370: struct adreno_gpudev; 371: 372: /* Time to allow preemption to complete (in ms) */ 373: #define ADRENO_PREEMPT_TIMEOUT 10000 374: 375: #define PREEMPT_SCRATCH_OFFSET(id) (id * sizeof(u64)) 376: 377: #define PREEMPT_SCRATCH_ADDR(dev, id) \ 378: ((dev)->preempt.scratch->gpuaddr + PREEMPT_SCRATCH_OFFSET(id)) 379: 380: /** 381: * enum adreno_preempt_states 382: * ADRENO_PREEMPT_NONE: No preemption is scheduled 383: * ADRENO_PREEMPT_START: The S/W has started 384: * ADRENO_PREEMPT_TRIGGERED: A preeempt has been triggered in the HW 385: * ADRENO_PREEMPT_FAULTED: The preempt timer has fired 386: * ADRENO_PREEMPT_PENDING: The H/W has signaled preemption complete 387: * ADRENO_PREEMPT_COMPLETE: Preemption could not be finished in the IRQ handler, 388: * worker has been scheduled 389: */ 390: enum adreno_preempt_states { 391: ADRENO_PREEMPT_NONE = 0, 392: ADRENO_PREEMPT_START, 393: ADRENO_PREEMPT_TRIGGERED, 394: ADRENO_PREEMPT_FAULTED, 395: ADRENO_PREEMPT_PENDING, 396: ADRENO_PREEMPT_COMPLETE, 397: }; 398: 399: /** 400: * struct adreno_protected_regs - container for a protect register span 401: */ 402: struct adreno_protected_regs { 403: /** @reg: Physical protected mode register to write to */ 404: u32 reg; 405: /** @start: Dword offset of the starting register in the range */ 406: u32 start; 407: /** 408: * @end: Dword offset of the ending register in the range 409: * (inclusive) 410: */ 411: u32 end; 412: /** 413: * @noaccess: 1 if the register should not be accessible from 414: * userspace, 0 if it can be read (but not written) 415: */ 416: u32 noaccess; 417: }; 418: 419: /** 420: * struct adreno_preemption 421: * @state: The current state of preemption 422: * @scratch: Per-target scratch memory for implementation specific functionality 423: * @timer: A timer to make sure preemption doesn't stall 424: * @work: A work struct for the preemption worker (for 5XX) 425: * preempt_level: The level of preemption (for 6XX) 426: * skipsaverestore: To skip saverestore during L1 preemption (for 6XX) 427: * usesgmem: enable GMEM save/restore across preemption (for 6XX) 428: * count: Track the number of preemptions triggered 429: */ 430: struct adreno_preemption { 431: atomic_t state; 432: struct kgsl_memdesc *scratch; 433: struct timer_list timer; 434: struct work_struct work; 435: unsigned int preempt_level; 436: bool skipsaverestore; 437: bool usesgmem; 438: unsigned int count; 439: /* @postamble_len: Number of dwords in KMD postamble pm4 packet */ 440: u32 postamble_len; 441: /* 442: * @postamble_bootup_len: Number of dwords in KMD postamble pm4 packet 443: * that needs to be sent before first submission to GPU. 444: * Note: Postambles are not preserved across slumber. 445: */ 446: u32 postamble_bootup_len; 447: }; 448: 449: struct adreno_busy_data { 450: unsigned int gpu_busy; 451: unsigned int bif_ram_cycles; 452: unsigned int bif_ram_cycles_read_ch1; 453: unsigned int bif_ram_cycles_write_ch0; 454: unsigned int bif_ram_cycles_write_ch1; 455: unsigned int bif_starved_ram; 456: unsigned int bif_starved_ram_ch1; 457: unsigned int num_ifpc; 458: unsigned int throttle_cycles[ADRENO_GPMU_THROTTLE_COUNTERS]; 459: u32 bcl_throttle; MATCH LINES: 670, 671, 700 658: 659: /** 660: * struct adreno_device - The mothership structure for all adreno related info 661: * @dev: Reference to struct kgsl_device 662: * @priv: Holds the private flags specific to the adreno_device 663: * @chipid: Chip ID specific to the GPU 664: * @gpucore: Pointer to the adreno_gpu_core structure 665: * @gpmu_cmds_size: Length of gpmu cmd stream 666: * @gpmu_cmds: gpmu cmd stream 667: * @ringbuffers: Array of pointers to adreno_ringbuffers 668: * @num_ringbuffers: Number of ringbuffers for the GPU 669: * @cur_rb: Pointer to the current ringbuffer 670: * @next_rb: Ringbuffer we are switching to during preemption 671: * @prev_rb: Ringbuffer we are switching from during preemption 672: * @ft_policy: Defines the fault tolerance policy 673: * @long_ib_detect: Long IB detection availability 674: * @cooperative_reset: Indicates if graceful death handshake is enabled 675: * between GMU and GPU 676: * @profile: Container for adreno profiler information 677: * @dispatcher: Container for adreno GPU dispatcher 678: * @pwron_fixup: Command buffer to run a post-power collapse shader workaround 679: * @pwron_fixup_dwords: Number of dwords in the command buffer 680: * @input_work: Work struct for turning on the GPU after a touch event 681: * @busy_data: Struct holding GPU VBIF busy stats 682: * @ram_cycles_lo: Number of DDR clock cycles for the monitor session (Only 683: * DDR channel 0 read cycles in case of GBIF) 684: * @ram_cycles_lo_ch1_read: Number of DDR channel 1 Read clock cycles for 685: * the monitor session 686: * @ram_cycles_lo_ch0_write: Number of DDR channel 0 Write clock cycles for 687: * the monitor session 688: * @ram_cycles_lo_ch1_write: Number of DDR channel 0 Write clock cycles for 689: * the monitor session 690: * @starved_ram_lo: Number of cycles VBIF/GBIF is stalled by DDR (Only channel 0 691: * stall cycles in case of GBIF) 692: * @starved_ram_lo_ch1: Number of cycles GBIF is stalled by DDR channel 1 693: * @halt: Atomic variable to check whether the GPU is currently halted 694: * @pending_irq_refcnt: Atomic variable to keep track of running IRQ handlers 695: * @ctx_d_debugfs: Context debugfs node 696: * @profile_buffer: Memdesc holding the drawobj profiling buffer 697: * @profile_index: Index to store the start/stop ticks in the profiling 698: * buffer 699: * @pwrup_reglist: Memdesc holding the power up register list 700: * which is used by CP during preemption and IFPC 701: * @lm_sequence: Pointer to the start of the register write sequence for LM 702: * @lm_size: The dword size of the LM sequence 703: * @lm_limit: limiting value for LM 704: * @lm_threshold_count: register value for counter for lm threshold breakin 705: * @lm_threshold_cross: number of current peaks exceeding threshold 706: * @ifpc_count: Number of times the GPU went into IFPC 707: * @highest_bank_bit: Value of the highest bank bit 708: * @gpmu_throttle_counters - counters for number of throttled clocks 709: * @irq_storm_work: Worker to handle possible interrupt storms 710: * @active_list: List to track active contexts 711: * @active_list_lock: Lock to protect active_list 712: * @gpu_llc_slice: GPU system cache slice descriptor 713: * @gpu_llc_slice_enable: To enable the GPU system cache slice or not 714: * @gpuhtw_llc_slice: GPU pagetables system cache slice descriptor 715: * @gpuhtw_llc_slice_enable: To enable the GPUHTW system cache slice or not 716: * @gpumv_llc_slice: GPU MV buffer system cache slice descriptor 717: * @gpumv_llc_slice_enable: To enable GPUMV buffer system cache slice or not 718: * @zap_loaded: Used to track if zap was successfully loaded or not 719: */ 720: struct adreno_device { 721: struct kgsl_device dev; /* Must be first field in this struct */ 722: unsigned long priv; 723: unsigned int chipid; 724: /** @uche_gmem_base: Base address of GMEM for UCHE access */ MATCH LINES: 777, 778, 784 765: /** @clx_enabled: True if CLX is enabled */ 766: bool clx_enabled; 767: /** @isense_reg_mapped: True if isense registers are mapped to regmap */ 768: bool isense_reg_mapped; 769: /** @lpac_enabled: True if LPAC is enabled */ 770: bool lpac_enabled; 771: /** @dms_enabled: True if DMS is enabled */ 772: bool dms_enabled; 773: /** @minbw_enabled: True if minbw vote is enabled */ 774: bool minbw_enabled; 775: /** @malu_enabled: True if mALU is enabled */ 776: bool malu_enabled; 777: /** @preempt_override: True if command line param enables preemption */ 778: bool preempt_override; 779: struct kgsl_memdesc *profile_buffer; 780: unsigned int profile_index; 781: struct kgsl_memdesc *pwrup_reglist; 782: uint32_t *lm_sequence; 783: uint32_t lm_size; 784: struct adreno_preemption preempt; 785: struct work_struct gpmu_work; 786: uint32_t lm_leakage; 787: uint32_t lm_limit; 788: uint32_t lm_threshold_count; 789: uint32_t lm_threshold_cross; 790: uint32_t ifpc_count; 791: 792: unsigned int highest_bank_bit; 793: /** @ubwc_mode: Supported UBWC mode */ 794: u32 ubwc_mode; 795: /** @mal: Minimum access length */ 796: u32 mal; 797: unsigned int quirks; 798: 799: #ifdef CONFIG_QCOM_KGSL_CORESIGHT 800: /** @gx_coresight: A coresight instance for GX */ 801: struct adreno_coresight_device gx_coresight; 802: /** @gx_coresight: A coresight instance for CX */ 803: struct adreno_coresight_device cx_coresight; 804: /** @funnel_gfx: A coresight instance for gfx funnel */ 805: struct adreno_funnel_device funnel_gfx; 806: /** 807: * @coresight_en_cnt: Retain mask if either coresight-gfx 808: * or coresight-gfx-cx is enabled; remove only when both MATCH LINES: 870, 871 858: * @bcl_data: bit 0 contains response type for bcl alarms and bits 1:24 controls 859: * throttle level for bcl alarm levels 0-2. If not set, gmu fw sets default throttle levels. 860: */ 861: u32 bcl_data; 862: /* @minbw_data: Min bw level to vote for when entering ifpc */ 863: u32 minbw_data; 864: /* 865: * @bcl_debugfs_dir: Debugfs directory node for bcl related nodes 866: */ 867: struct dentry *bcl_debugfs_dir; 868: /** @bcl_throttle_time_us: Total time in us spent in BCL throttling */ 869: u32 bcl_throttle_time_us; 870: /* @preemption_debugfs_dir: Debugfs directory node for preemption related nodes */ 871: struct dentry *preemption_debugfs_dir; 872: /* @hwsched_enabled: If true, hwsched is enabled */ 873: bool hwsched_enabled; 874: /* @fastblend_enabled: True if fastblend feature is enabled */ 875: bool fastblend_enabled; 876: /* @raytracing_enabled: True if raytracing feature is enabled */ 877: bool raytracing_enabled; 878: /* @feature_fuse: feature fuse value read from HW */ 879: u32 feature_fuse; 880: /** @gmu_ab: Track if GMU supports ab vote */ 881: bool gmu_ab; 882: /** @ifpc_hyst: IFPC long hysteresis value */ 883: u32 ifpc_hyst; 884: /** @ifpc_hyst_floor: IFPC long hysteresis floor value */ 885: u32 ifpc_hyst_floor; 886: /* 887: * @no_restore_count: Keep track of perfcounter requests that don't have 888: * ADRENO_PERFCOUNTER_GROUP_RESTORE flag set 889: */ 890: u32 no_restore_count; 891: /* 892: * @ahb_timeout_val: AHB transaction timeout value. 893: * If set, a timeout will occur in 2 ^ (ahb_timeout_val + 1) cycles. 894: */ 895: u32 ahb_timeout_val; MATCH LINES: 925, 929, 960, 976 913: /** @scheduler_work: work_struct to put the gpu command scheduler in a work queue */ 914: struct kthread_work scheduler_work; 915: /** @scheduler_fault: Atomic to trigger scheduler based fault recovery */ 916: atomic_t scheduler_fault; 917: /** @dcvs_tuning_mutex: Mutex taken during dcvs tuning */ 918: struct mutex dcvs_tuning_mutex; 919: /** @dcvs_tuning_mingap_lvl: Current DCVS tuning level for mingap */ 920: u32 dcvs_tuning_mingap_lvl; 921: /** @dcvs_tuning_penalty_lvl: Current DCVS tuning level for penalty */ 922: u32 dcvs_tuning_penalty_lvl; 923: /** @dcvs_tuning_numbusy_lvl: Current DCVS tuning level for numbusy */ 924: u32 dcvs_tuning_numbusy_lvl; 925: /** @total_ctxt_record_sz: Size of the total preemption record in bytes */ 926: u64 total_ctxt_record_sz; 927: /** @dcvs_profile_enabled: True if DCVS profile is enabled */ 928: bool dcvs_profile_enabled; 929: /** @aqe_ctxt_record_sz: Size of the AQE section in preemption record in bytes */ 930: u64 aqe_ctxt_record_sz; 931: /** @ubwc_cfg: Pointer to hold struct qcom_ubwc_cfg_data fetched from 932: * qcom_ubwc_config_get_data() API 933: */ 934: void *ubwc_cfg_data; 935: /** @adreno_ubwc_props: Container of all UBWC props required to program NC_MODE_CNTL 936: * registers 937: */ 938: struct adreno_ubwc_props ubwc_props; 939: /** @multidraw_mode: Whether PC unroll is enabled for multidraw **/ 940: u32 multidraw_mode; 941: /** @viz_flush_draw_count: Draw count to flush visibility stream **/ 942: u32 viz_flush_draw_count; 943: /** @viz_flush_prim_count: Prim count to flush visibility stream **/ 944: u32 viz_flush_prim_count; 945: }; 946: 947: /* Time to wait for suspend recovery gate to complete */ 948: #define ADRENO_SUSPEND_RECOVERY_GATE_TIMEOUT_MS 5000 949: 950: /** 951: * enum adreno_device_flags - Private flags for the adreno_device 952: * @ADRENO_DEVICE_PWRON - Set during init after a power collapse 953: * @ADRENO_DEVICE_PWRON_FIXUP - Set if the target requires the shader fixup 954: * after power collapse 955: * @ADRENO_DEVICE_STARTED - Set if the device start sequence is in progress 956: * @ADRENO_DEVICE_FAULT - Set if the device is currently in fault (and shouldn't 957: * send any more commands to the ringbuffer) 958: * @ADRENO_DEVICE_DRAWOBJ_PROFILE - Set if the device supports drawobj 959: * profiling via the ALWAYSON counter 960: * @ADRENO_DEVICE_PREEMPTION - Turn on/off preemption 961: * @ADRENO_DEVICE_SOFT_FAULT_DETECT - Set if soft fault detect is enabled 962: * @ADRENO_DEVICE_GPMU_INITIALIZED - Set if GPMU firmware initialization succeed 963: * @ADRENO_DEVICE_ISDB_ENABLED - Set if the Integrated Shader DeBugger is 964: * attached and enabled 965: * @ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED - Set if a CACHE_FLUSH_TS irq storm 966: * is in progress 967: */ 968: enum adreno_device_flags { 969: ADRENO_DEVICE_PWRON = 0, 970: ADRENO_DEVICE_PWRON_FIXUP = 1, 971: ADRENO_DEVICE_INITIALIZED = 2, 972: ADRENO_DEVICE_STARTED = 5, 973: ADRENO_DEVICE_FAULT = 6, 974: ADRENO_DEVICE_DRAWOBJ_PROFILE = 7, 975: ADRENO_DEVICE_GPU_REGULATOR_ENABLED = 8, 976: ADRENO_DEVICE_PREEMPTION = 9, 977: ADRENO_DEVICE_SOFT_FAULT_DETECT = 10, 978: ADRENO_DEVICE_GPMU_INITIALIZED = 11, 979: ADRENO_DEVICE_ISDB_ENABLED = 12, 980: ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED = 13, 981: /** @ADRENO_DEVICE_DMS: Set if DMS is enabled */ 982: ADRENO_DEVICE_DMS = 14, 983: /** @ADRENO_DEVICE_GMU_AB: Set if AB vote via GMU is enabled */ 984: ADRENO_DEVICE_GMU_AB = 15, 985: /** @ADRENO_DEVICE_CX_TIMER_INITIALIZED: Set if the CX timer is initialized */ 986: ADRENO_DEVICE_CX_TIMER_INITIALIZED = 17, 987: /** @ADRENO_DEVICE_RESET_RECOVERY: Set if the ADRENO device under goes reset recovery */ 988: ADRENO_DEVICE_RESET_RECOVERY = 18, 989: /** @ADRENO_DEVICE_FIRST_BOOT_DONE: Set if the ADRENO device first boot is done */ 990: ADRENO_DEVICE_FIRST_BOOT_DONE = 19, 991: /** @ADRENO_DEVICE_FAST_CONTEXT_DESTROY: Set if fast context destroy is enabled on GMU */ 992: ADRENO_DEVICE_FAST_CONTEXT_DESTROY = 20, 993: /** @ADRENO_DEVICE_ALLOW_MALU_WORKLOAD: mALU workload is supported by GMU and GPU */ 994: ADRENO_DEVICE_ALLOW_MALU_WORKLOAD = 21, 995: }; 996: 997: /** 998: * struct adreno_drawobj_profile_entry - a single drawobj entry in the 999: * kernel profiling buffer 1000: * @started: Number of GPU ticks at start of the drawobj MATCH LINES: 1102 1090: void (*snapshot)(struct adreno_device *adreno_dev, 1091: struct kgsl_snapshot *snapshot); 1092: irqreturn_t (*irq_handler)(struct adreno_device *adreno_dev); 1093: int (*init)(struct adreno_device *adreno_dev); 1094: void (*remove)(struct adreno_device *adreno_dev); 1095: int (*rb_start)(struct adreno_device *adreno_dev); 1096: int (*start)(struct adreno_device *adreno_dev); 1097: int (*regulator_enable)(struct adreno_device *adreno_dev); 1098: void (*regulator_disable)(struct adreno_device *adreno_dev); 1099: void (*pwrlevel_change_settings)(struct adreno_device *adreno_dev, 1100: unsigned int prelevel, unsigned int postlevel, 1101: bool post); 1102: void (*preemption_schedule)(struct adreno_device *adreno_dev); 1103: void (*context_detach)(struct adreno_context *drawctxt); 1104: void (*pre_reset)(struct adreno_device *adreno_dev); 1105: void (*gpu_keepalive)(struct adreno_device *adreno_dev, 1106: bool state); 1107: bool (*hw_isidle)(struct adreno_device *adreno_dev); 1108: const char *(*iommu_fault_block)(struct kgsl_device *device, 1109: unsigned int fsynr1); 1110: int (*reset)(struct adreno_device *adreno_dev); 1111: /** @soft_reset: Soft reset GPU on fault recovery */ 1112: int (*soft_reset)(struct adreno_device *adreno_dev, 1113: struct kgsl_context *context, bool ctx_guilty); 1114: /** @read_alwayson: Return the current value of the alwayson counter */ 1115: u64 (*read_alwayson)(struct adreno_device *adreno_dev); 1116: /** 1117: * @power_ops: Target specific function pointers to power up/down the 1118: * gpu 1119: */ 1120: const struct adreno_power_ops *power_ops; 1121: int (*clear_pending_transactions)(struct adreno_device *adreno_dev); 1122: void (*deassert_gbif_halt)(struct adreno_device *adreno_dev); 1123: int (*ringbuffer_submitcmd)(struct adreno_device *adreno_dev, 1124: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 1125: struct adreno_submit_time *time); 1126: /** MATCH LINES: 1842, 1843, 1846, 1847, 1849, 1852, 1853, 1856, 1857, 1864, 1870, 1873, 1890, 1892, 1894, 1896 1830: * the current code is older, 0 if equal or 1 if newer. 1831: */ 1832: static inline int adreno_compare_pfp_version(struct adreno_device *adreno_dev, 1833: unsigned int version) 1834: { 1835: if (adreno_dev->fw[ADRENO_FW_PFP].version == version) 1836: return 0; 1837: 1838: return (adreno_dev->fw[ADRENO_FW_PFP].version > version) ? 1 : -1; 1839: } 1840: 1841: /** 1842: * adreno_in_preempt_state() - Check if preemption state is equal to given state 1843: * @adreno_dev: Device whose preemption state is checked 1844: * @state: State to compare against 1845: */ 1846: static inline bool adreno_in_preempt_state(struct adreno_device *adreno_dev, 1847: enum adreno_preempt_states state) 1848: { 1849: return atomic_read(&adreno_dev->preempt.state) == state; 1850: } 1851: /** 1852: * adreno_set_preempt_state() - Set the specified preemption state 1853: * @adreno_dev: Device to change preemption state 1854: * @state: State to set 1855: */ 1856: static inline void adreno_set_preempt_state(struct adreno_device *adreno_dev, 1857: enum adreno_preempt_states state) 1858: { 1859: /* 1860: * atomic_set doesn't use barriers, so we need to do it ourselves. One 1861: * before... 1862: */ 1863: smp_wmb(); 1864: atomic_set(&adreno_dev->preempt.state, state); 1865: 1866: /* ... and one after */ 1867: smp_wmb(); 1868: } 1869: 1870: static inline bool adreno_is_preemption_enabled( 1871: struct adreno_device *adreno_dev) 1872: { 1873: return test_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 1874: } 1875: 1876: /** 1877: * adreno_is_fast_context_destroy_enabled() - Check whether the GMU fast context 1878: * destroy optimization is statically enabled and if the GMU supports the 1879: * capability. 1880: * @adreno_dev: Pointer to the adreno_device struct 1881: */ 1882: static inline bool adreno_is_fast_context_destroy_enabled( 1883: struct adreno_device *adreno_dev) 1884: { 1885: return test_bit(ADRENO_DEVICE_FAST_CONTEXT_DESTROY, &adreno_dev->priv); 1886: } 1887: 1888: 1889: /** 1890: * adreno_preemption_feature_set() - Check whether adreno preemption feature is statically enabled 1891: * either via adreno feature bit, or via the cmdline override 1892: * @adreno_dev: Device whose preemption state is checked 1893: */ 1894: static inline bool adreno_preemption_feature_set(struct adreno_device *adreno_dev) 1895: { 1896: return ADRENO_FEATURE(adreno_dev, ADRENO_PREEMPTION) || adreno_dev->preempt_override; 1897: } 1898: 1899: /* 1900: * adreno_compare_prio_level() - Compares 2 priority levels based on enum values 1901: * @p1: First priority level 1902: * @p2: Second priority level 1903: * 1904: * Returns greater than 0 if p1 is higher priority, 0 if levels are equal else 1905: * less than 0 1906: */ 1907: static inline int adreno_compare_prio_level(int p1, int p2) 1908: { 1909: return p2 - p1; 1910: } 1911: 1912: void adreno_readreg64(struct adreno_device *adreno_dev, 1913: enum adreno_regs lo, enum adreno_regs hi, uint64_t *val); 1914: 1915: void adreno_writereg64(struct adreno_device *adreno_dev, 1916: enum adreno_regs lo, enum adreno_regs hi, uint64_t val); 1917: 1918: unsigned int adreno_get_rptr(struct adreno_ringbuffer *rb); 1919: 1920: void adreno_touch_wake(struct kgsl_device *device); MATCH LINES: 1955, 1967 1943: * 64 bit addresses when the kernel is in 32 bit mode even if we wanted 1944: * so we need to check that we are using a5xx or newer and that the 1945: * unsigned long is big enough for our purposes. 1946: */ 1947: return (BITS_PER_LONG > 32 && ADRENO_GPUREV(adreno_dev) >= 500); 1948: } 1949: 1950: static inline void adreno_ringbuffer_set_pagetable(struct kgsl_device *device, 1951: struct adreno_ringbuffer *rb, struct kgsl_pagetable *pt) 1952: { 1953: unsigned long flags; 1954: 1955: spin_lock_irqsave(&rb->preempt_lock, flags); 1956: 1957: kgsl_sharedmem_writel(device->scratch, 1958: SCRATCH_RB_OFFSET(rb->id, current_rb_ptname), pt->name); 1959: 1960: kgsl_sharedmem_writeq(device->scratch, 1961: SCRATCH_RB_OFFSET(rb->id, ttbr0), 1962: kgsl_mmu_pagetable_get_ttbr0(pt)); 1963: 1964: kgsl_sharedmem_writel(device->scratch, 1965: SCRATCH_RB_OFFSET(rb->id, contextidr), 0); 1966: 1967: spin_unlock_irqrestore(&rb->preempt_lock, flags); 1968: } 1969: 1970: static inline u32 counter_delta(struct kgsl_device *device, 1971: unsigned int reg, unsigned int *counter) 1972: { 1973: u32 val, ret = 0; 1974: 1975: if (!reg) 1976: return 0; 1977: 1978: kgsl_regread(device, reg, &val); 1979: 1980: if (*counter) { 1981: if (val >= *counter) 1982: ret = val - *counter; 1983: else 1984: ret = (UINT_MAX - *counter) + val; 1985: } 1986: 1987: *counter = val; 1988: return ret; 1989: } 1990: 1991: static inline int adreno_perfcntr_active_oob_get( MATCH LINES: 2038, 2040, 2041, 2045, 2046, 2048 2026: int ret = kgsl_regmap_read_poll_timeout(&device->regmap, ack_reg, 2027: val, (val & mask) == mask, 100, 100 * 1000); 2028: 2029: if (ret) 2030: dev_err(device->dev, 2031: "GBIF/VBIF Halt ack timeout: reg=%08x mask=%08x status=%08x\n", 2032: ack_reg, mask, val); 2033: 2034: return ret; 2035: } 2036: 2037: /** 2038: * adreno_move_preempt_state - Update the preemption state 2039: * @adreno_dev: An Adreno GPU device handle 2040: * @old: The current state of the preemption 2041: * @new: The new state of the preemption 2042: * 2043: * Return: True if the state was updated or false if not 2044: */ 2045: static inline bool adreno_move_preempt_state(struct adreno_device *adreno_dev, 2046: enum adreno_preempt_states old, enum adreno_preempt_states new) 2047: { 2048: return (atomic_cmpxchg(&adreno_dev->preempt.state, old, new) == old); 2049: } 2050: 2051: /** 2052: * adreno_reg_offset_init - Helper function to initialize reg_offsets 2053: * @reg_offsets: Pointer to an array of register offsets 2054: * 2055: * Helper function to setup register_offsets for a target. Go through 2056: * and set ADRENO_REG_UNUSED for all unused entries in the list. 2057: */ 2058: static inline void adreno_reg_offset_init(u32 *reg_offsets) 2059: { 2060: int i; 2061: 2062: /* 2063: * Initialize uninitialzed gpu registers, only needs to be done once. 2064: * Make all offsets that are not initialized to ADRENO_REG_UNUSED 2065: */ 2066: for (i = 0; i < ADRENO_REG_REGISTER_MAX; i++) { 2067: if (!reg_offsets[i]) 2068: reg_offsets[i] = ADRENO_REG_UNUSED; 2069: } 2070: } 2071: 2072: static inline u32 adreno_get_level(struct kgsl_context *context) MATCH LINES: 2243 2231: void adreno_check_idle(struct kgsl_device *device); 2232: 2233: /* 2234: * adreno_profile_submit_time - Populate profiling buffer with timestamps 2235: * @time: Container for the statistics 2236: * 2237: * Populate the draw object user profiling buffer with the timestamps 2238: * recored in the adreno_submit_time structure at the time of draw object 2239: * submission. 2240: */ 2241: void adreno_profile_submit_time(struct adreno_submit_time *time); 2242: 2243: void adreno_preemption_timer(struct timer_list *t); 2244: 2245: /** 2246: * adreno_create_profile_buffer - Create a buffer to store profiling data 2247: * @adreno_dev: Adreno GPU device handle 2248: */ 2249: void adreno_create_profile_buffer(struct adreno_device *adreno_dev); 2250: 2251: /** 2252: * adreno_isidle - return true if the hardware is idle 2253: * @adreno_dev: Adreno GPU device handle 2254: * 2255: * Return: True if the hardware is idle 2256: */ 2257: bool adreno_isidle(struct adreno_device *adreno_dev); 2258: 2259: /** 2260: * adreno_allocate_global - Helper function to allocate a global GPU object 2261: * @device: A GPU device handle 2262: * @memdesc: Pointer to a &struct kgsl_memdesc pointer 2263: * @size: Size of the allocation in bytes 2264: * @padding: Amount of extra adding to add to the VA allocation 2265: * @flags: Control flags for the allocation 2266: * @priv: Internal flags for the allocation 2267: * @name: Name of the allocation (for the debugfs file) --- FILE: \adreno_a5xx.c | HITS: 20 --- MATCH LINES: 1506, 1513, 1516, 1522, 1528, 1530, 1532, 1538, 1541, 1548, 1551, 1564, 1586, 1587 1494: 1495: if (device->mmu.secured) { 1496: kgsl_regwrite(device, A5XX_RBBM_SECVID_TSB_CNTL, 0x0); 1497: kgsl_regwrite(device, A5XX_RBBM_SECVID_TSB_TRUSTED_BASE_LO, 1498: lower_32_bits(KGSL_IOMMU_SECURE_BASE32)); 1499: kgsl_regwrite(device, A5XX_RBBM_SECVID_TSB_TRUSTED_BASE_HI, 1500: upper_32_bits(KGSL_IOMMU_SECURE_BASE32)); 1501: kgsl_regwrite(device, A5XX_RBBM_SECVID_TSB_TRUSTED_SIZE, 1502: FIELD_PREP(GENMASK(31, 12), 1503: (KGSL_IOMMU_SECURE_SIZE(&device->mmu) / SZ_4K))); 1504: } 1505: 1506: a5xx_preemption_start(adreno_dev); 1507: a5xx_protect_init(adreno_dev); 1508: 1509: return 0; 1510: } 1511: 1512: /* 1513: * Follow the ME_INIT sequence with a preemption yield to allow the GPU to move 1514: * to a different ringbuffer, if desired 1515: */ 1516: static int _preemption_init( 1517: struct adreno_device *adreno_dev, 1518: struct adreno_ringbuffer *rb, unsigned int *cmds, 1519: struct kgsl_context *context) 1520: { 1521: unsigned int *cmds_orig = cmds; 1522: uint64_t gpuaddr = rb->preemption_desc->gpuaddr; 1523: 1524: /* Turn CP protection OFF */ 1525: cmds += cp_protected_mode(adreno_dev, cmds, 0); 1526: /* 1527: * CP during context switch will save context switch info to 1528: * a5xx_cp_preemption_record pointed by CONTEXT_SWITCH_SAVE_ADDR 1529: */ 1530: *cmds++ = cp_type4_packet(A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_LO, 1); 1531: *cmds++ = lower_32_bits(gpuaddr); 1532: *cmds++ = cp_type4_packet(A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_HI, 1); 1533: *cmds++ = upper_32_bits(gpuaddr); 1534: 1535: /* Turn CP protection ON */ 1536: cmds += cp_protected_mode(adreno_dev, cmds, 1); 1537: 1538: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_GLOBAL, 1); 1539: *cmds++ = 0; 1540: 1541: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_LOCAL, 1); 1542: *cmds++ = 1; 1543: 1544: /* Enable yield in RB only */ 1545: *cmds++ = cp_type7_packet(CP_YIELD_ENABLE, 1); 1546: *cmds++ = 1; 1547: 1548: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1549: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 1550: *cmds++ = 0; 1551: /* generate interrupt on preemption completion */ 1552: *cmds++ = 1; 1553: 1554: return cmds - cmds_orig; 1555: } 1556: 1557: static int a5xx_post_start(struct adreno_device *adreno_dev) 1558: { 1559: int ret; 1560: unsigned int *cmds, *start; 1561: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1562: 1563: if (!adreno_is_a530(adreno_dev) && 1564: !adreno_is_preemption_enabled(adreno_dev)) 1565: return 0; 1566: 1567: cmds = adreno_ringbuffer_allocspace(rb, 42); 1568: if (IS_ERR(cmds)) { 1569: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1570: 1571: dev_err(device->dev, 1572: "error allocating preemtion init cmds\n"); 1573: return PTR_ERR(cmds); 1574: } 1575: start = cmds; 1576: 1577: /* 1578: * Send a pipeline stat event whenever the GPU gets powered up 1579: * to cause misbehaving perf counters to start ticking 1580: */ 1581: if (adreno_is_a530(adreno_dev)) { 1582: *cmds++ = cp_packet(adreno_dev, CP_EVENT_WRITE, 1); 1583: *cmds++ = 0xF; 1584: } 1585: 1586: if (adreno_is_preemption_enabled(adreno_dev)) { 1587: cmds += _preemption_init(adreno_dev, rb, cmds, NULL); 1588: rb->_wptr = rb->_wptr - (42 - (cmds - start)); 1589: ret = a5xx_ringbuffer_submit(rb, NULL, false); 1590: } else { 1591: rb->_wptr = rb->_wptr - (42 - (cmds - start)); 1592: ret = a5xx_ringbuffer_submit(rb, NULL, true); 1593: } 1594: 1595: if (!ret) { 1596: ret = adreno_spin_idle(adreno_dev, 2000); 1597: if (ret) 1598: a5xx_spin_idle_debug(adreno_dev, 1599: "hw initialization failed to idle\n"); 1600: } 1601: 1602: return ret; 1603: } 1604: 1605: static int a5xx_gpmu_init(struct adreno_device *adreno_dev) 1606: { 1607: int ret; 1608: 1609: /* Set up LM before initializing the GPMU */ 1610: a5xx_lm_init(adreno_dev); 1611: MATCH LINES: 1823 1811: uint64_t addr; 1812: unsigned int *cmds; 1813: int ret, i; 1814: 1815: /* Clear all the ringbuffers */ 1816: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1817: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 1818: kgsl_sharedmem_writel(device->scratch, 1819: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1820: 1821: rb->wptr = 0; 1822: rb->_wptr = 0; 1823: rb->wptr_preempt_end = ~0; 1824: } 1825: 1826: /* Set up the current ringbuffer */ 1827: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 1828: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 1829: 1830: kgsl_regwrite(device, A5XX_CP_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1831: kgsl_regwrite(device, A5XX_CP_RB_RPTR_ADDR_HI, upper_32_bits(addr)); 1832: 1833: /* 1834: * The size of the ringbuffer in the hardware is the log2 1835: * representation of the size in quadwords (sizedwords / 2). 1836: * Also disable the host RPTR shadow register as it might be unreliable 1837: * in certain circumstances. 1838: */ 1839: 1840: kgsl_regwrite(device, A5XX_CP_RB_CNTL, 1841: A5XX_CP_RB_CNTL_DEFAULT); 1842: 1843: kgsl_regwrite(device, A5XX_CP_RB_BASE, 1844: lower_32_bits(rb->buffer_desc->gpuaddr)); 1845: kgsl_regwrite(device, A5XX_CP_RB_BASE_HI, 1846: upper_32_bits(rb->buffer_desc->gpuaddr)); 1847: MATCH LINES: 2140 2128: kgsl_regwrite(device, A5XX_RBBM_INT_0_MASK, 2129: adreno_dev->irq_mask); 2130: 2131: kgsl_schedule_work(&adreno_dev->irq_storm_work); 2132: 2133: return; 2134: } 2135: } else { 2136: count = 0; 2137: prev = cur; 2138: } 2139: 2140: a5xx_preemption_trigger(adreno_dev); 2141: adreno_scheduler_queue(adreno_dev); 2142: } 2143: 2144: static const char *gpmu_int_msg[32] = { 2145: [FW_INTR_INFO] = "FW_INTR_INFO", 2146: [LLM_ACK_ERR_INTR] = "LLM_ACK_ERR_INTR", 2147: [ISENS_TRIM_ERR_INTR] = "ISENS_TRIM_ERR_INTR", 2148: [ISENS_ERR_INTR] = "ISENS_ERR_INTR", 2149: [ISENS_IDLE_ERR_INTR] = "ISENS_IDLE_ERR_INTR", 2150: [ISENS_PWR_ON_ERR_INTR] = "ISENS_PWR_ON_ERR_INTR", 2151: [6 ... 30] = "", 2152: [WDOG_EXPITED] = "WDOG_EXPITED"}; 2153: 2154: static void a5xx_gpmu_int_callback(struct adreno_device *adreno_dev, int bit) 2155: { 2156: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2157: unsigned int reg, i; 2158: 2159: kgsl_regread(device, A5XX_GPMU_RBBM_INTR_INFO, ®); 2160: 2161: if (reg & (~VALID_GPMU_IRQ)) { 2162: dev_crit_ratelimited(device->dev, 2163: "GPMU: Unknown IRQ mask 0x%08lx in 0x%08x\n", 2164: reg & (~VALID_GPMU_IRQ), reg); MATCH LINES: 2247 2235: ADRENO_IRQ_CALLBACK(NULL), /* 0 - RBBM_GPU_IDLE */ 2236: ADRENO_IRQ_CALLBACK(a5xx_err_callback), /* 1 - RBBM_AHB_ERROR */ 2237: ADRENO_IRQ_CALLBACK(a5xx_err_callback), /* 2 - RBBM_TRANSFER_TIMEOUT */ 2238: /* 3 - RBBM_ME_MASTER_SPLIT_TIMEOUT */ 2239: ADRENO_IRQ_CALLBACK(a5xx_err_callback), 2240: /* 4 - RBBM_PFP_MASTER_SPLIT_TIMEOUT */ 2241: ADRENO_IRQ_CALLBACK(a5xx_err_callback), 2242: /* 5 - RBBM_ETS_MASTER_SPLIT_TIMEOUT */ 2243: ADRENO_IRQ_CALLBACK(a5xx_err_callback), 2244: /* 6 - RBBM_ATB_ASYNC_OVERFLOW */ 2245: ADRENO_IRQ_CALLBACK(a5xx_err_callback), 2246: ADRENO_IRQ_CALLBACK(a5x_gpc_err_int_callback), /* 7 - GPC_ERR */ 2247: ADRENO_IRQ_CALLBACK(a5xx_preempt_callback),/* 8 - CP_SW */ 2248: ADRENO_IRQ_CALLBACK(a5xx_cp_hw_err_callback), /* 9 - CP_HW_ERROR */ 2249: /* 10 - CP_CCU_FLUSH_DEPTH_TS */ 2250: ADRENO_IRQ_CALLBACK(NULL), 2251: /* 11 - CP_CCU_FLUSH_COLOR_TS */ 2252: ADRENO_IRQ_CALLBACK(NULL), 2253: /* 12 - CP_CCU_RESOLVE_TS */ 2254: ADRENO_IRQ_CALLBACK(NULL), 2255: ADRENO_IRQ_CALLBACK(NULL), /* 13 - CP_IB2_INT */ 2256: ADRENO_IRQ_CALLBACK(NULL), /* 14 - CP_IB1_INT */ 2257: ADRENO_IRQ_CALLBACK(NULL), /* 15 - CP_RB_INT */ 2258: /* 16 - CCP_UNUSED_1 */ 2259: ADRENO_IRQ_CALLBACK(NULL), 2260: ADRENO_IRQ_CALLBACK(NULL), /* 17 - CP_RB_DONE_TS */ 2261: ADRENO_IRQ_CALLBACK(NULL), /* 18 - CP_WT_DONE_TS */ 2262: ADRENO_IRQ_CALLBACK(NULL), /* 19 - UNKNOWN_1 */ 2263: ADRENO_IRQ_CALLBACK(a5xx_cp_callback), /* 20 - CP_CACHE_FLUSH_TS */ 2264: /* 21 - UNUSED_2 */ 2265: ADRENO_IRQ_CALLBACK(NULL), 2266: ADRENO_IRQ_CALLBACK(a5xx_err_callback), /* 22 - RBBM_ATB_BUS_OVERFLOW */ 2267: /* 23 - MISC_HANG_DETECT */ 2268: ADRENO_IRQ_CALLBACK(adreno_hang_int_callback), 2269: ADRENO_IRQ_CALLBACK(a5xx_err_callback), /* 24 - UCHE_OOB_ACCESS */ 2270: ADRENO_IRQ_CALLBACK(a5xx_err_callback), /* 25 - UCHE_TRAP_INTR */ 2271: ADRENO_IRQ_CALLBACK(NULL), /* 26 - DEBBUS_INTR_0 */ MATCH LINES: 2365, 2366 2353: /* If feature is not supported or enabled, no worry */ 2354: if (!adreno_dev->sptp_pc_enabled) 2355: return true; 2356: kgsl_regread(device, A5XX_GPMU_SP_PWR_CLK_STATUS, ®); 2357: if (reg & BIT(20)) 2358: return false; 2359: kgsl_regread(device, A5XX_GPMU_RBCCU_PWR_CLK_STATUS, ®); 2360: return !(reg & BIT(20)); 2361: } 2362: 2363: static void a5xx_remove(struct adreno_device *adreno_dev) 2364: { 2365: if (adreno_preemption_feature_set(adreno_dev)) 2366: kgsl_delete_timer(&adreno_dev->preempt.timer); 2367: } 2368: 2369: static void a5xx_power_stats(struct adreno_device *adreno_dev, 2370: struct kgsl_power_stats *stats) 2371: { 2372: static u32 rbbm0_hi; 2373: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2374: s64 freq = kgsl_pwrctrl_active_freq(&device->pwrctrl) / 1000000; 2375: struct adreno_busy_data *busy = &adreno_dev->busy_data; 2376: s64 gpu_busy = 0; 2377: u32 lo, hi; 2378: s64 adj; 2379: 2380: /* Sometimes this counter can go backwards, so try to detect that */ 2381: kgsl_regread(device, A5XX_RBBM_PERFCTR_RBBM_0_LO, &lo); 2382: kgsl_regread(device, A5XX_RBBM_PERFCTR_RBBM_0_HI, &hi); 2383: 2384: if (busy->gpu_busy) { 2385: if (lo < busy->gpu_busy) { 2386: if (hi == rbbm0_hi) { 2387: dev_warn_once(device->dev, 2388: "abmormal value from RBBM_0 perfcounter: %x %x\n", 2389: lo, busy->gpu_busy); 2390: gpu_busy = 0; MATCH LINES: 2439 2427: 2428: const struct adreno_gpudev adreno_a5xx_gpudev = { 2429: .reg_offsets = a5xx_register_offsets, 2430: .probe = a5xx_probe, 2431: .start = a5xx_start, 2432: .snapshot = a5xx_snapshot, 2433: .init = a5xx_init, 2434: .irq_handler = a5xx_irq_handler, 2435: .rb_start = a5xx_rb_start, 2436: .regulator_enable = a5xx_regulator_enable, 2437: .regulator_disable = a5xx_regulator_disable, 2438: .pwrlevel_change_settings = a5xx_pwrlevel_change_settings, 2439: .preemption_schedule = a5xx_preemption_schedule, 2440: .read_alwayson = a5xx_read_alwayson, 2441: .hw_isidle = a5xx_hw_isidle, 2442: .power_ops = &adreno_power_operations, 2443: .clear_pending_transactions = a5xx_clear_pending_transactions, 2444: .remove = a5xx_remove, 2445: .ringbuffer_submitcmd = a5xx_ringbuffer_submitcmd, 2446: .is_hw_collapsible = a5xx_is_hw_collapsible, 2447: .power_stats = a5xx_power_stats, 2448: }; --- FILE: \adreno_a5xx.h | HITS: 18 --- MATCH LINES: 46, 48, 49, 52, 53, 66, 68, 83 34: const char *zap_name; 35: /** @hwcg: List of registers and values to write for HWCG */ 36: const struct kgsl_regmap_list *hwcg; 37: /** @hwcg_count: Number of registers in @hwcg */ 38: u32 hwcg_count; 39: /** @vbif: List of registers and values to write for VBIF */ 40: const struct kgsl_regmap_list *vbif; 41: /** @vbif_count: Number of registers in @vbif */ 42: u32 vbif_count; 43: }; 44: 45: #define A5XX_CP_CTXRECORD_MAGIC_REF 0x27C4BAFCUL 46: /* Size of each CP preemption record */ 47: #define A5XX_CP_CTXRECORD_SIZE_IN_BYTES 0x10000 48: /* Size of the preemption counter block (in bytes) */ 49: #define A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE (16 * 4) 50: 51: /** 52: * struct a5xx_cp_preemption_record - CP context record for 53: * preemption. 54: * @magic: (00) Value at this offset must be equal to 55: * A5XX_CP_CTXRECORD_MAGIC_REF. 56: * @info: (04) Type of record. Written non-zero (usually) by CP. 57: * we must set to zero for all ringbuffers. 58: * @data: (08) DATA field in SET_RENDER_MODE or checkpoint packets. 59: * Written by CP when switching out. Not used on switch-in. 60: * we must initialize to zero. 61: * @cntl: (12) RB_CNTL, saved and restored by CP. 62: * @rptr: (16) RB_RPTR, saved and restored by CP. 63: * @wptr: (20) RB_WPTR, saved and restored by CP. 64: * @rptr_addr: (24) RB_RPTR_ADDR_LO|HI saved and restored. 65: * rbase: (32) RB_BASE_LO|HI saved and restored. 66: * counter: (40) Pointer to preemption counter 67: */ 68: struct a5xx_cp_preemption_record { 69: uint32_t magic; 70: uint32_t info; 71: uint32_t data; 72: uint32_t cntl; 73: uint32_t rptr; 74: uint32_t wptr; 75: uint64_t rptr_addr; 76: uint64_t rbase; 77: uint64_t counter; 78: }; 79: 80: #define A5XX_CP_SMMU_INFO_MAGIC_REF 0x3618CDA3UL 81: 82: /** 83: * struct a5xx_cp_smmu_info - CP preemption SMMU info. 84: * @magic: (00) The value at this offset must be equal to 85: * A5XX_CP_SMMU_INFO_MAGIC_REF. 86: * @_pad4: (04) Reserved/padding 87: * @ttbr0: (08) Base address of the page table for the 88: * incoming context. 89: * @context_idr: (16) Context Identification Register value. 90: */ 91: struct a5xx_cp_smmu_info { 92: uint32_t magic; 93: uint32_t _pad4; 94: uint64_t ttbr0; 95: uint32_t asid; 96: uint32_t context_idr; 97: }; 98: 99: void a5xx_snapshot(struct adreno_device *adreno_dev, 100: struct kgsl_snapshot *snapshot); 101: unsigned int a5xx_num_registers(void); 102: 103: void a5xx_crashdump_init(struct adreno_device *adreno_dev); 104: 105: void a5xx_hwcg_set(struct adreno_device *adreno_dev, bool on); 106: 107: #define A5XX_CP_RB_CNTL_DEFAULT ((1 << 27) | ((ilog2(4) << 8) & 0x1F00) | \ MATCH LINES: 225, 226, 227, 228, 229, 232, 238, 241, 249, 253 213: * 214: * Returns: 215: * A pointer to the a5xx specific GPU core struct 216: */ 217: static inline const struct adreno_a5xx_core * 218: to_a5xx_core(struct adreno_device *adreno_dev) 219: { 220: const struct adreno_gpu_core *core = adreno_dev->gpucore; 221: 222: return container_of(core, struct adreno_a5xx_core, base); 223: } 224: 225: /* Preemption functions */ 226: void a5xx_preemption_trigger(struct adreno_device *adreno_dev); 227: void a5xx_preemption_schedule(struct adreno_device *adreno_dev); 228: void a5xx_preemption_start(struct adreno_device *adreno_dev); 229: int a5xx_preemption_init(struct adreno_device *adreno_dev); 230: 231: /** 232: * a5xx_preemption_post_ibsubmit - Insert commands following a submission 233: * @adreno_dev: Adreno GPU handle 234: * @cmds: Pointer to the ringbuffer to insert opcodes 235: * 236: * Return: The number of opcodes written to @cmds 237: */ 238: u32 a5xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, u32 *cmds); 239: 240: /** 241: * a5xx_preemption_post_ibsubmit - Insert opcodes before a submission 242: * @adreno_dev: Adreno GPU handle 243: * @rb: The ringbuffer being written 244: * @drawctxt: The draw context being written 245: * @cmds: Pointer to the ringbuffer to insert opcodes 246: * 247: * Return: The number of opcodes written to @cmds 248: */ 249: u32 a5xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 250: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 251: u32 *cmds); 252: 253: void a5xx_preempt_callback(struct adreno_device *adreno_dev, int bit); 254: 255: u64 a5xx_read_alwayson(struct adreno_device *adreno_dev); 256: 257: extern const struct adreno_perfcounters adreno_a5xx_perfcounters; 258: 259: /** 260: * a5xx_ringbuffer_init - Initialize the ringbuffers 261: * @adreno_dev: An Adreno GPU handle 262: * 263: * Initialize the ringbuffer(s) for a5xx. 264: * Return: 0 on success or negative on failure 265: */ 266: int a5xx_ringbuffer_init(struct adreno_device *adreno_dev); 267: 268: /** 269: * a5xx_ringbuffer_addcmds - Submit a command to the ringbuffer 270: * @adreno_dev: An Adreno GPU handle 271: * @rb: Pointer to the ringbuffer to submit on 272: * @drawctxt: Pointer to the draw context for the submission, or NULL for 273: * internal submissions 274: * @flags: Flags for the submission 275: * @in: Commands to write to the ringbuffer 276: * @dwords: Size of @in (in dwords) 277: * @timestamp: Timestamp for the submission --- FILE: \adreno_a5xx_packets.h | HITS: 5 --- MATCH LINES: 301 289: 0x00000003, /* [0x0111] A5X_PC_POWER_CNTL_CTX_0 (0xE3B0)*/ 290: 0x48E4F001, /* [0x0112] == TYPE4 == */ 291: 0x00000003, /* [0x0113] A5X_VFD_POWER_CNTL_CTX_0 (0xE4F0)*/ 292: 0x70268000, /* [0x0114] == TYPE7: WAIT_FOR_IDLE (26) == */ 293: 0x400CC701, /* [0x0115] == TYPE4 == */ 294: 0x7C13C080, /* [0x0116] A5X_RB_CCU_CNTL (0x0CC7)*/ 295: 0x70EC8005, /* [0x0117] == TYPE7: SET_RENDER_MODE (6C) == */ 296: 0x00000001, /* [0x0118] */ 297: 0x00000000, /* [0x0119] */ 298: 0x00000000, /* [0x011A] */ 299: 0x00000010, /* [0x011B] */ 300: 0x00000001, /* [0x011C] */ 301: 0x70EA0001, /* [0x011D] == TYPE7: PREEMPT_ENABLE_LOCAL (6A) == */ 302: 0x00000000, /* [0x011E] */ 303: 0x48E0EA02, /* [0x011F] == TYPE4 == */ 304: 0x00000000, /* [0x0120] A5X_GRAS_SC_WINDOW_SCISSOR_TL_CTX_0 (0xE0EA)*/ 305: 0x001F0073, /* [0x0121] A5X_GRAS_SC_WINDOW_SCISSOR_BR_CTX_0 (0xE0EB)*/ 306: 0x48E21102, /* [0x0122] == TYPE4 == */ 307: 0x00000000, /* [0x0123] A5X_RB_RESOLVE_CNTL_1_CTX_0 (0xE211)*/ 308: 0x00030007, /* [0x0124] A5X_RB_RESOLVE_CNTL_2_CTX_0 (0xE212)*/ 309: 0x70138000, /* [0x0125] == TYPE7: WAIT_FOR_ME (13) == */ 310: 0x70640001, /* [0x0126] == TYPE7: SET_VISIBILITY_OVERRIDE (64) == */ 311: 0x00000000, /* [0x0127] */ 312: 0x702F8005, /* [0x0128] == TYPE7: SET_BIN_DATA (2F) == */ 313: 0x00010000, /* [0x0129] */ 314: 0x00000000, /* [0x012A] */ 315: 0x00000000, /* [0x012B] */ 316: 0x00000000, /* [0x012C] */ 317: 0x00000000, /* [0x012D] */ 318: 0x40E1D001, /* [0x012E] == TYPE4 == */ 319: 0x00000000, /* [0x012F] A5X_RB_WINDOW_OFFSET_CTX_0 (0xE1D0)*/ 320: 0x40E2A201, /* [0x0130] == TYPE4 == */ 321: 0x00000001, /* [0x0131] A5X_VPC_SO_OVERRIDE_CTX_0 (0xE2A2)*/ 322: 0x70640001, /* [0x0132] == TYPE7: SET_VISIBILITY_OVERRIDE (64) == */ 323: 0x00000000, /* [0x0133] */ 324: 0x48E1B285, /* [0x0134] == TYPE4 == */ 325: 0x00000001, /* [0x0135] A5X_RB_DEPTH_BUFFER_INFO_CTX_0 (0xE1B2)*/ MATCH LINES: 416 404: 0x00000000, /* [0x0180] A5X_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_LO_CTX_0 405: * (0xE104) 406: */ 407: 0x00000000, /* [0x0181] A5X_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE_HI_CTX_0 408: * (0xE105) 409: */ 410: 0x70460001, /* [0x0182] == TYPE7: EVENT_WRITE (46) == */ 411: 0x00000025, /* [0x0183] */ 412: 0x70460001, /* [0x0184] == TYPE7: EVENT_WRITE (46) == */ 413: 0x00000019, /* [0x0185] */ 414: 0x70460001, /* [0x0186] == TYPE7: EVENT_WRITE (46) == */ 415: 0x00000018, /* [0x0187] */ 416: 0x70EA0001, /* [0x0188] == TYPE7: PREEMPT_ENABLE_LOCAL (6A) == */ 417: 0x00000000, /* [0x0189] */ 418: 0x70EC0001, /* [0x018A] == TYPE7: SET_RENDER_MODE (6C) == */ 419: 0x00000006, /* [0x018B] */ 420: 0x70438003, /* [0x018C] == TYPE7: SET_DRAW_STATE (43) == */ 421: 0x00080059, /* [0x018D] */ 422: 0x00000000, /* [0x018E] */ 423: 0x00000000, /* [0x018F] */ 424: 0x70DC0002, /* [0x0190] == TYPE7: CONTEXT_REG_BUNCH (5C) == */ 425: 0x0000E2A1, /* [0x0191] */ 426: 0x00008001, /* [0x0192] */ 427: 0x709D0001, /* [0x0193] == TYPE7: SKIP_IB2_ENABLE_GLOBAL (1D) == */ 428: 0x00000000, /* [0x0194] */ 429: 0x70138000, /* [0x0195] == TYPE7: WAIT_FOR_ME (13) == */ 430: 0x70640001, /* [0x0196] == TYPE7: SET_VISIBILITY_OVERRIDE (64) == */ 431: 0x00000001, /* [0x0197] */ 432: 0x70380007, /* [0x0198] == TYPE7: DRAW_INDX_OFFSET (38) == */ 433: 0x00200506, /* [0x0199] */ 434: 0x00000000, /* [0x019A] */ 435: 0x00000004, /* [0x019B] */ 436: 0x00000000, /* [0x019C] */ 437: 0x00000000, /* [0x019D] */ 438: 0x00000000, /* [0x019E] */ 439: 0x00000004, /* [0x019F] */ 440: 0x703D8005, /* [0x01A0] == TYPE7: MEM_WRITE (3D) == */ MATCH LINES: 466 454: 0x00000000, /* [0x01AE] */ 455: 0x00000000, /* [0x01AF] */ 456: 0x00000001, /* [0x01B0] */ 457: 0x00000002, /* [0x01B1] */ 458: 0x70100001, /* [0x01B2] == TYPE7: NOP (10) == */ 459: 0x00000000, /* [0x01B3] */ 460: 0x70C28003, /* [0x01B4] == TYPE7: MEM_TO_REG (42) == */ 461: 0xC000E2AB, /* [0x01B5] */ 462: 0x00000000, /* [0x01B6] */ 463: 0x00000000, /* [0x01B7] */ 464: 0x70230001, /* [0x01B8] == TYPE7: SKIP_IB2_ENABLE_LOCAL (23) == */ 465: 0x00000000, /* [0x01B9] */ 466: 0x70E90001, /* [0x01BA] == TYPE7: PREEMPT_ENABLE_GLOBAL (69) == */ 467: 0x00000000, /* [0x01BB] */ 468: 0x70BC8006, /* [0x01BC] == TYPE7: WAIT_REG_MEM (3C) == */ 469: 0x00000010, /* [0x01BD] */ 470: 0x00000000, /* [0x01BE] */ 471: 0x00000000, /* [0x01BF] */ 472: 0x00000001, /* [0x01C0] */ 473: 0xFFFFFFFF, /* [0x01C1] */ 474: 0x00000001, /* [0x01C2] */ 475: 0x70738009, /* [0x01C3] == TYPE7: MEM_TO_MEM (73) == */ 476: 0x20000004, /* [0x01C4] */ 477: 0x00000000, /* [0x01C5] */ 478: 0x00000000, /* [0x01C6] */ 479: 0x00000000, /* [0x01C7] */ 480: 0x00000000, /* [0x01C8] */ 481: 0x00000000, /* [0x01C9] */ 482: 0x00000000, /* [0x01CA] */ 483: 0x00000000, /* [0x01CB] */ 484: 0x00000000, /* [0x01CC] */ 485: 0x70738009, /* [0x01CD] == TYPE7: MEM_TO_MEM (73) == */ 486: 0xE0000004, /* [0x01CE] */ 487: 0x00000000, /* [0x01CF] */ 488: 0x00000000, /* [0x01D0] */ 489: 0x00000000, /* [0x01D1] */ 490: 0x00000000, /* [0x01D2] */ MATCH LINES: 535, 537 523: 0x00000001, /* [0x01F3] */ 524: 0x48E78401, /* [0x01F4] == TYPE4 == */ 525: 0x00000881, /* [0x01F5] A5X_HLSQ_CNTL_0_CTX_0 (0xE784)*/ 526: 0x40E5F001, /* [0x01F6] == TYPE4 == */ 527: 0x00000C06, /* [0x01F7] A5X_SP_CS_CNTL_0_CTX_0 (0xE5F0)*/ 528: 0x48E79001, /* [0x01F8] == TYPE4 == */ 529: 0x00000001, /* [0x01F9] A5X_HLSQ_CS_CONFIG_CTX_0 (0xE790)*/ 530: 0x48E79601, /* [0x01FA] == TYPE4 == */ 531: 0x00000005, /* [0x01FB] A5X_HLSQ_CS_CNTL_CTX_0 (0xE796)*/ 532: 0x48E58901, /* [0x01FC] == TYPE4 == */ 533: 0x00000001, /* [0x01FD] A5X_SP_CS_CONFIG_CTX_0 (0xE589)*/ 534: 0x40E7DC01, /* [0x01FE] == TYPE4 == */ 535: 0x00000030, /* [0x01FF] A5X_HLSQ_CONTEXT_SWITCH_CS_SW_3_CTX_0 (0xE7DC)*/ 536: 0x48E7DD01, /* [0x0200] == TYPE4 == */ 537: 0x00000002, /* [0x0201] A5X_HLSQ_CONTEXT_SWITCH_CS_SW_4_CTX_0 (0xE7DD)*/ 538: 0x40E7B001, /* [0x0202] == TYPE4 == */ 539: 0x00000003, /* [0x0203] A5X_HLSQ_CS_NDRANGE_0_CTX_0 (0xE7B0)*/ 540: 0x48E7B702, /* [0x0204] == TYPE4 == */ 541: 0x00FCC0CF, /* [0x0205] A5X_HLSQ_CS_CNTL_0_CTX_0 (0xE7B7)*/ 542: 0x00000000, /* [0x0206] A5X_HLSQ_CS_CNTL_1_CTX_0 (0xE7B8)*/ 543: 0x40E7B983, /* [0x0207] == TYPE4 == */ 544: 0x00000001, /* [0x0208] A5X_HLSQ_CS_KERNEL_GROUP_X_CTX_0 (0xE7B9)*/ 545: 0x00000001, /* [0x0209] A5X_HLSQ_CS_KERNEL_GROUP_Y_CTX_0 (0xE7BA)*/ 546: 0x00000001, /* [0x020A] A5X_HLSQ_CS_KERNEL_GROUP_Z_CTX_0 (0xE7BB)*/ 547: 0x70B08003, /* [0x020B] == TYPE7: LOAD_STATE (30) == */ 548: 0x00B60000, /* [0x020C] */ 549: 0x00000000, /* [0x020D] */ 550: 0x00000000, /* [0x020E] */ 551: 0x70B08003, /* [0x020F] == TYPE7: LOAD_STATE (30) == */ 552: 0x01360008, /* [0x0210] */ 553: 0x00000000, /* [0x0211] */ 554: 0x00000000, /* [0x0212] */ 555: 0x70B0000B, /* [0x0213] == TYPE7: LOAD_STATE (30) == */ 556: 0x00BC0000, /* [0x0214] */ 557: 0x00000000, /* [0x0215] */ 558: 0x00000000, /* [0x0216] */ 559: 0x00000000, /* [0x0217] */ 560: 0x00000000, /* [0x0218] */ 561: 0x00000000, /* [0x0219] */ --- FILE: \adreno_a5xx_preempt.c | HITS: 153 --- MATCH LINES: 13, 14, 16, 26, 33, 43, 46, 59, 63, 72, 77, 79, 93, 94, 97, 103, 107, 110, 111, 119, 127, 130, 132, 133, 134, 135, 141, 142, 158, 160, 169, 179, 180, 183, 203, 215, 223, 224, 226, 231, 233, 236, 237, 238, 239, 243, 244, 245, 247, 250, 252, 253, 256, 261, 262, 265, 269, 278, 283, 285, 291, 298, 300, 303, 307, 312, 313, 315, 320, 325, 326, 328, 333, 335, 336, 340, 342, 347, 349, 350, 351, 352, 353, 354, 357, 358, 366, 368, 370, 377, 380, 381, 384, 388, 395, 400, 403, 407, 413, 420, 424, 429, 431, 433, 437, 439, 441, 444, 450, 453, 454, 455, 456, 464, 469, 470, 472, 474, 475, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 492, 493, 494, 495, 500, 504, 510, 514, 516, 517, 518, 520, 521, 523, 527, 529, 531, 535, 538, 547 1: // SPDX-License-Identifier: GPL-2.0-only 2: /* 3: * Copyright (c) 2014-2017,2021 The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include "adreno.h" 8: #include "adreno_a5xx.h" 9: #include "adreno_pm4types.h" 10: #include "adreno_trace.h" 11: #include "kgsl_util.h" 12: 13: #define PREEMPT_RECORD(_field) \ 14: offsetof(struct a5xx_cp_preemption_record, _field) 15: 16: #define PREEMPT_SMMU_RECORD(_field) \ 17: offsetof(struct a5xx_cp_smmu_info, _field) 18: 19: static void _update_wptr(struct adreno_device *adreno_dev, bool reset_timer) 20: { 21: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 22: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 23: unsigned int wptr; 24: unsigned long flags; 25: 26: spin_lock_irqsave(&rb->preempt_lock, flags); 27: 28: kgsl_regread(device, A5XX_CP_RB_WPTR, &wptr); 29: 30: if (wptr != rb->wptr) { 31: kgsl_regwrite(device, A5XX_CP_RB_WPTR, rb->wptr); 32: /* 33: * In case something got submitted while preemption was on 34: * going, reset the timer. 35: */ 36: reset_timer = true; 37: } 38: 39: if (reset_timer) 40: rb->dispatch_q.expires = jiffies + 41: msecs_to_jiffies(adreno_drawobj_timeout); 42: 43: spin_unlock_irqrestore(&rb->preempt_lock, flags); 44: } 45: 46: static void _a5xx_preemption_done(struct adreno_device *adreno_dev) 47: { 48: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 49: unsigned int status; 50: 51: /* 52: * In the very unlikely case that the power is off, do nothing - the 53: * state will be reset on power up and everybody will be happy 54: */ 55: 56: if (!kgsl_state_is_awake(device)) 57: return; 58: 59: kgsl_regread(device, A5XX_CP_CONTEXT_SWITCH_CNTL, &status); 60: 61: if (status != 0) { 62: dev_err(device->dev, 63: "Preemption not complete: status=%X cur=%d R/W=%X/%X next=%d R/W=%X/%X\n", 64: status, adreno_dev->cur_rb->id, 65: adreno_get_rptr(adreno_dev->cur_rb), 66: adreno_dev->cur_rb->wptr, 67: adreno_dev->next_rb->id, 68: adreno_get_rptr(adreno_dev->next_rb), 69: adreno_dev->next_rb->wptr); 70: 71: /* Set a fault and restart */ 72: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 73: 74: return; 75: } 76: 77: kgsl_delete_timer_sync(&adreno_dev->preempt.timer); 78: 79: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 0, 0); 80: 81: /* Clean up all the bits */ 82: adreno_dev->prev_rb = adreno_dev->cur_rb; 83: adreno_dev->cur_rb = adreno_dev->next_rb; 84: adreno_dev->next_rb = NULL; 85: 86: /* Update the wptr for the new command queue */ 87: _update_wptr(adreno_dev, true); 88: 89: /* Update the dispatcher timer for the new command queue */ 90: mod_timer(&adreno_dev->dispatcher.timer, 91: adreno_dev->cur_rb->dispatch_q.expires); 92: 93: /* Clear the preempt state */ 94: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 95: } 96: 97: static void _a5xx_preemption_fault(struct adreno_device *adreno_dev) 98: { 99: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 100: unsigned int status; 101: 102: /* 103: * If the power is on check the preemption status one more time - if it 104: * was successful then just transition to the complete state 105: */ 106: if (kgsl_state_is_awake(device)) { 107: kgsl_regread(device, A5XX_CP_CONTEXT_SWITCH_CNTL, &status); 108: 109: if (status == 0) { 110: adreno_set_preempt_state(adreno_dev, 111: ADRENO_PREEMPT_COMPLETE); 112: 113: adreno_scheduler_queue(adreno_dev); 114: return; 115: } 116: } 117: 118: dev_err(device->dev, 119: "Preemption timed out: cur=%d R/W=%X/%X, next=%d R/W=%X/%X\n", 120: adreno_dev->cur_rb->id, 121: adreno_get_rptr(adreno_dev->cur_rb), 122: adreno_dev->cur_rb->wptr, 123: adreno_dev->next_rb->id, 124: adreno_get_rptr(adreno_dev->next_rb), 125: adreno_dev->next_rb->wptr); 126: 127: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 128: } 129: 130: static void _a5xx_preemption_worker(struct work_struct *work) 131: { 132: struct adreno_preemption *preempt = container_of(work, 133: struct adreno_preemption, work); 134: struct adreno_device *adreno_dev = container_of(preempt, 135: struct adreno_device, preempt); 136: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 137: 138: /* Need to take the mutex to make sure that the power stays on */ 139: kgsl_mutex_lock(&device->mutex); 140: 141: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_FAULTED)) 142: _a5xx_preemption_fault(adreno_dev); 143: 144: kgsl_mutex_unlock(&device->mutex); 145: } 146: 147: /* Find the highest priority active ringbuffer */ 148: static struct adreno_ringbuffer *a5xx_next_ringbuffer( 149: struct adreno_device *adreno_dev) 150: { 151: struct adreno_ringbuffer *rb; 152: unsigned long flags; 153: unsigned int i; 154: 155: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 156: bool empty; 157: 158: spin_lock_irqsave(&rb->preempt_lock, flags); 159: empty = adreno_rb_empty(rb); 160: spin_unlock_irqrestore(&rb->preempt_lock, flags); 161: 162: if (!empty) 163: return rb; 164: } 165: 166: return NULL; 167: } 168: 169: void a5xx_preemption_trigger(struct adreno_device *adreno_dev) 170: { 171: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 172: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 173: struct adreno_ringbuffer *next; 174: uint64_t ttbr0; 175: unsigned int contextidr; 176: unsigned long flags; 177: 178: /* Put ourselves into a possible trigger state */ 179: if (!adreno_move_preempt_state(adreno_dev, 180: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START)) 181: return; 182: 183: /* Get the next ringbuffer to preempt in */ 184: next = a5xx_next_ringbuffer(adreno_dev); 185: 186: /* 187: * Nothing to do if every ringbuffer is empty or if the current 188: * ringbuffer is the only active one 189: */ 190: if (next == NULL || next == adreno_dev->cur_rb) { 191: /* 192: * Update any critical things that might have been skipped while 193: * we were looking for a new ringbuffer 194: */ 195: 196: if (next != NULL) { 197: _update_wptr(adreno_dev, false); 198: 199: mod_timer(&adreno_dev->dispatcher.timer, 200: adreno_dev->cur_rb->dispatch_q.expires); 201: } 202: 203: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 204: return; 205: } 206: 207: /* Turn off the dispatcher timer */ 208: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 209: 210: /* 211: * This is the most critical section - we need to take care not to race 212: * until we have programmed the CP for the switch 213: */ 214: 215: spin_lock_irqsave(&next->preempt_lock, flags); 216: 217: /* Get the pagetable from the pagetable info. */ 218: kgsl_sharedmem_readq(device->scratch, &ttbr0, 219: SCRATCH_RB_OFFSET(next->id, ttbr0)); 220: kgsl_sharedmem_readl(device->scratch, &contextidr, 221: SCRATCH_RB_OFFSET(next->id, contextidr)); 222: 223: kgsl_sharedmem_writel(next->preemption_desc, 224: PREEMPT_RECORD(wptr), next->wptr); 225: 226: spin_unlock_irqrestore(&next->preempt_lock, flags); 227: 228: /* And write it to the smmu info */ 229: if (kgsl_mmu_is_perprocess(&device->mmu)) { 230: kgsl_sharedmem_writeq(iommu->smmu_info, 231: PREEMPT_SMMU_RECORD(ttbr0), ttbr0); 232: kgsl_sharedmem_writel(iommu->smmu_info, 233: PREEMPT_SMMU_RECORD(context_idr), contextidr); 234: } 235: 236: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_LO, 237: lower_32_bits(next->preemption_desc->gpuaddr)); 238: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_HI, 239: upper_32_bits(next->preemption_desc->gpuaddr)); 240: 241: adreno_dev->next_rb = next; 242: 243: /* Start the timer to detect a stuck preemption */ 244: mod_timer(&adreno_dev->preempt.timer, 245: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 246: 247: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 248: 1, 0); 249: 250: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 251: 252: /* Trigger the preemption */ 253: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_CNTL, 1); 254: } 255: 256: void a5xx_preempt_callback(struct adreno_device *adreno_dev, int bit) 257: { 258: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 259: unsigned int status; 260: 261: if (!adreno_move_preempt_state(adreno_dev, 262: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 263: return; 264: 265: kgsl_regread(device, A5XX_CP_CONTEXT_SWITCH_CNTL, &status); 266: 267: if (status != 0) { 268: dev_err(KGSL_DEVICE(adreno_dev)->dev, 269: "preempt interrupt with non-zero status: %X\n", 270: status); 271: 272: /* 273: * Under the assumption that this is a race between the 274: * interrupt and the register, schedule the worker to clean up. 275: * If the status still hasn't resolved itself by the time we get 276: * there then we have to assume something bad happened 277: */ 278: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE); 279: adreno_scheduler_queue(adreno_dev); 280: return; 281: } 282: 283: kgsl_delete_timer(&adreno_dev->preempt.timer); 284: 285: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 0, 0); 286: 287: adreno_dev->prev_rb = adreno_dev->cur_rb; 288: adreno_dev->cur_rb = adreno_dev->next_rb; 289: adreno_dev->next_rb = NULL; 290: 291: /* Update the wptr if it changed while preemption was ongoing */ 292: _update_wptr(adreno_dev, true); 293: 294: /* Update the dispatcher timer for the new command queue */ 295: mod_timer(&adreno_dev->dispatcher.timer, 296: adreno_dev->cur_rb->dispatch_q.expires); 297: 298: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 299: 300: a5xx_preemption_trigger(adreno_dev); 301: } 302: 303: void a5xx_preemption_schedule(struct adreno_device *adreno_dev) 304: { 305: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 306: 307: if (!adreno_is_preemption_enabled(adreno_dev)) 308: return; 309: 310: kgsl_mutex_lock(&device->mutex); 311: 312: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE)) 313: _a5xx_preemption_done(adreno_dev); 314: 315: a5xx_preemption_trigger(adreno_dev); 316: 317: kgsl_mutex_unlock(&device->mutex); 318: } 319: 320: u32 a5xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 321: struct adreno_ringbuffer *rb, 322: struct adreno_context *drawctxt, u32 *cmds) 323: { 324: unsigned int *cmds_orig = cmds; 325: uint64_t gpuaddr = rb->preemption_desc->gpuaddr; 326: unsigned int preempt_style = 0; 327: 328: if (!adreno_is_preemption_enabled(adreno_dev)) 329: return 0; 330: 331: if (drawctxt) { 332: /* 333: * Preemption from secure to unsecure needs Zap shader to be 334: * run to clear all secure content. CP does not know during 335: * preemption if it is switching between secure and unsecure 336: * contexts so restrict Secure contexts to be preempted at 337: * ringbuffer level. 338: */ 339: if (drawctxt->base.flags & KGSL_CONTEXT_SECURE) 340: preempt_style = KGSL_CONTEXT_PREEMPT_STYLE_RINGBUFFER; 341: else 342: preempt_style = FIELD_GET(KGSL_CONTEXT_PREEMPT_STYLE_MASK, 343: drawctxt->base.flags); 344: } 345: 346: /* 347: * CP_PREEMPT_ENABLE_GLOBAL(global preemption) can only be set by KMD 348: * in ringbuffer. 349: * 1) set global preemption to 0x0 to disable global preemption. 350: * Only RB level preemption is allowed in this mode 351: * 2) Set global preemption to defer(0x2) for finegrain preemption. 352: * when global preemption is set to defer(0x2), 353: * CP_PREEMPT_ENABLE_LOCAL(local preemption) determines the 354: * preemption point. Local preemption 355: * can be enabled by both UMD(within IB) and KMD. 356: */ 357: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_GLOBAL, 1); 358: *cmds++ = ((preempt_style == KGSL_CONTEXT_PREEMPT_STYLE_FINEGRAIN) 359: ? 2 : 0); 360: 361: /* Turn CP protection OFF */ 362: cmds += cp_protected_mode(adreno_dev, cmds, 0); 363: 364: /* 365: * CP during context switch will save context switch info to 366: * a5xx_cp_preemption_record pointed by CONTEXT_SWITCH_SAVE_ADDR 367: */ 368: *cmds++ = cp_type4_packet(A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_LO, 1); 369: *cmds++ = lower_32_bits(gpuaddr); 370: *cmds++ = cp_type4_packet(A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_HI, 1); 371: *cmds++ = upper_32_bits(gpuaddr); 372: 373: /* Turn CP protection ON */ 374: cmds += cp_protected_mode(adreno_dev, cmds, 1); 375: 376: /* 377: * Enable local preemption for finegrain preemption in case of 378: * a misbehaving IB 379: */ 380: if (preempt_style == KGSL_CONTEXT_PREEMPT_STYLE_FINEGRAIN) { 381: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_LOCAL, 1); 382: *cmds++ = 1; 383: } else { 384: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_LOCAL, 1); 385: *cmds++ = 0; 386: } 387: 388: /* Enable CP_CONTEXT_SWITCH_YIELD packets in the IB2s */ 389: *cmds++ = cp_type7_packet(CP_YIELD_ENABLE, 1); 390: *cmds++ = 2; 391: 392: return (unsigned int) (cmds - cmds_orig); 393: } 394: 395: unsigned int a5xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 396: unsigned int *cmds) 397: { 398: int dwords = 0; 399: 400: if (!adreno_is_preemption_enabled(adreno_dev)) 401: return 0; 402: 403: cmds[dwords++] = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 404: /* Write NULL to the address to skip the data write */ 405: dwords += cp_gpuaddr(adreno_dev, &cmds[dwords], 0x0); 406: cmds[dwords++] = 1; 407: /* generate interrupt on preemption completion */ 408: cmds[dwords++] = 1; 409: 410: return dwords; 411: } 412: 413: void a5xx_preemption_start(struct adreno_device *adreno_dev) 414: { 415: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 416: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 417: struct adreno_ringbuffer *rb; 418: unsigned int i; 419: 420: if (!adreno_is_preemption_enabled(adreno_dev)) 421: return; 422: 423: /* Force the state to be clear */ 424: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 425: 426: /* Only set up smmu info when per-process pagetables are enabled */ 427: 428: if (kgsl_mmu_is_perprocess(&device->mmu)) { 429: /* smmu_info is allocated and mapped in a5xx_preemption_iommu_init */ 430: kgsl_sharedmem_writel(iommu->smmu_info, 431: PREEMPT_SMMU_RECORD(magic), A5XX_CP_SMMU_INFO_MAGIC_REF); 432: kgsl_sharedmem_writeq(iommu->smmu_info, 433: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 434: 435: /* The CP doesn't use the asid record, so poison it */ 436: kgsl_sharedmem_writel(iommu->smmu_info, 437: PREEMPT_SMMU_RECORD(asid), 0xDECAFBAD); 438: kgsl_sharedmem_writel(iommu->smmu_info, 439: PREEMPT_SMMU_RECORD(context_idr), 0); 440: 441: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 442: lower_32_bits(iommu->smmu_info->gpuaddr)); 443: 444: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 445: upper_32_bits(iommu->smmu_info->gpuaddr)); 446: } 447: 448: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 449: /* 450: * preemption_desc is allocated and mapped at init time, 451: * so no need to check sharedmem_writel return value 452: */ 453: kgsl_sharedmem_writel(rb->preemption_desc, 454: PREEMPT_RECORD(rptr), 0); 455: kgsl_sharedmem_writel(rb->preemption_desc, 456: PREEMPT_RECORD(wptr), 0); 457: 458: adreno_ringbuffer_set_pagetable(device, rb, 459: device->mmu.defaultpagetable); 460: } 461: 462: } 463: 464: static int a5xx_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 465: struct adreno_ringbuffer *rb, uint64_t counteraddr) 466: { 467: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 468: 469: if (IS_ERR_OR_NULL(rb->preemption_desc)) 470: rb->preemption_desc = kgsl_allocate_global(device, 471: A5XX_CP_CTXRECORD_SIZE_IN_BYTES, SZ_16K, 0, 472: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 473: 474: if (IS_ERR(rb->preemption_desc)) 475: return PTR_ERR(rb->preemption_desc); 476: 477: kgsl_sharedmem_writel(rb->preemption_desc, 478: PREEMPT_RECORD(magic), A5XX_CP_CTXRECORD_MAGIC_REF); 479: kgsl_sharedmem_writel(rb->preemption_desc, 480: PREEMPT_RECORD(info), 0); 481: kgsl_sharedmem_writel(rb->preemption_desc, 482: PREEMPT_RECORD(data), 0); 483: kgsl_sharedmem_writel(rb->preemption_desc, 484: PREEMPT_RECORD(cntl), A5XX_CP_RB_CNTL_DEFAULT); 485: kgsl_sharedmem_writel(rb->preemption_desc, 486: PREEMPT_RECORD(rptr), 0); 487: kgsl_sharedmem_writel(rb->preemption_desc, 488: PREEMPT_RECORD(wptr), 0); 489: kgsl_sharedmem_writeq(rb->preemption_desc, 490: PREEMPT_RECORD(rptr_addr), SCRATCH_RB_GPU_ADDR(device, 491: rb->id, rptr)); 492: kgsl_sharedmem_writeq(rb->preemption_desc, 493: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 494: kgsl_sharedmem_writeq(rb->preemption_desc, 495: PREEMPT_RECORD(counter), counteraddr); 496: 497: return 0; 498: } 499: 500: int a5xx_preemption_init(struct adreno_device *adreno_dev) 501: { 502: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 503: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 504: struct adreno_preemption *preempt = &adreno_dev->preempt; 505: struct adreno_ringbuffer *rb; 506: int ret; 507: unsigned int i; 508: uint64_t addr; 509: 510: /* We are dependent on IOMMU to make preemption go on the CP side */ 511: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) 512: return -ENODEV; 513: 514: INIT_WORK(&preempt->work, _a5xx_preemption_worker); 515: 516: /* Allocate mem for storing preemption counters */ 517: if (IS_ERR_OR_NULL(preempt->scratch)) 518: preempt->scratch = kgsl_allocate_global(device, 519: adreno_dev->num_ringbuffers * 520: A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE, 0, 0, 0, 521: "preemption_counters"); 522: 523: ret = PTR_ERR_OR_ZERO(preempt->scratch); 524: if (ret) 525: return ret; 526: 527: addr = preempt->scratch->gpuaddr; 528: 529: /* Allocate mem for storing preemption switch record */ 530: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 531: ret = a5xx_preemption_ringbuffer_init(adreno_dev, rb, addr); 532: if (ret) 533: return ret; 534: 535: addr += A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE; 536: } 537: 538: /* Allocate mem for storing preemption smmu record */ 539: if (kgsl_mmu_is_perprocess(&device->mmu) && IS_ERR_OR_NULL(iommu->smmu_info)) 540: iommu->smmu_info = kgsl_allocate_global(device, PAGE_SIZE, 0, 541: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 542: "smmu_info"); 543: 544: if (IS_ERR(iommu->smmu_info)) 545: return PTR_ERR(iommu->smmu_info); 546: 547: set_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 548: return 0; 549: } --- FILE: \adreno_a5xx_ringbuffer.c | HITS: 12 --- MATCH LINES: 85, 86, 92, 112, 129, 130, 168 73: u32 *cmds = adreno_ringbuffer_allocspace(rb, 3); 74: 75: if (IS_ERR(cmds)) 76: return PTR_ERR(cmds); 77: 78: cmds[0] = cp_type7_packet(CP_WHERE_AM_I, 2); 79: cmds[1] = lower_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id, 80: rptr)); 81: cmds[2] = upper_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id, 82: rptr)); 83: } 84: 85: spin_lock_irqsave(&rb->preempt_lock, flags); 86: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 87: if (adreno_dev->cur_rb == rb) 88: kgsl_regwrite(device, A5XX_CP_RB_WPTR, rb->_wptr); 89: } 90: 91: rb->wptr = rb->_wptr; 92: spin_unlock_irqrestore(&rb->preempt_lock, flags); 93: 94: return 0; 95: } 96: 97: int a5xx_ringbuffer_init(struct adreno_device *adreno_dev) 98: { 99: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 100: int i; 101: 102: if (IS_ERR_OR_NULL(device->scratch)) 103: device->scratch = kgsl_allocate_global(device, PAGE_SIZE, 104: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED, 105: "scratch"); 106: 107: if (IS_ERR(device->scratch)) 108: return PTR_ERR(device->scratch); 109: 110: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]); 111: 112: if (!adreno_preemption_feature_set(adreno_dev)) { 113: adreno_dev->num_ringbuffers = 1; 114: return adreno_ringbuffer_setup(adreno_dev, 115: &adreno_dev->ringbuffers[0], 0); 116: } 117: 118: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers); 119: 120: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 121: int ret; 122: 123: ret = adreno_ringbuffer_setup(adreno_dev, 124: &adreno_dev->ringbuffers[i], i); 125: if (ret) 126: return ret; 127: } 128: 129: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 130: a5xx_preemption_init(adreno_dev); 131: return 0; 132: } 133: 134: #define A5XX_SUBMIT_MAX 64 135: 136: int a5xx_ringbuffer_addcmds(struct adreno_device *adreno_dev, 137: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 138: u32 flags, u32 *in, u32 dwords, u32 timestamp, 139: struct adreno_submit_time *time) 140: { 141: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 142: static u32 sequence; 143: u32 size = A5XX_SUBMIT_MAX + dwords; 144: u32 *cmds, index = 0; 145: u64 profile_gpuaddr; 146: u32 profile_dwords; 147: 148: if (adreno_drawctxt_detached(drawctxt)) 149: return -ENOENT; 150: 151: if (adreno_gpu_fault(adreno_dev) != 0) 152: return -EPROTO; 153: 154: rb->timestamp++; 155: 156: if (drawctxt) 157: drawctxt->internal_timestamp = rb->timestamp; 158: 159: cmds = adreno_ringbuffer_allocspace(rb, size); 160: if (IS_ERR(cmds)) 161: return PTR_ERR(cmds); 162: 163: /* Identify the start of a command */ 164: cmds[index++] = cp_type7_packet(CP_NOP, 1); 165: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 166: 167: /* 14 dwords */ 168: index += a5xx_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 169: &cmds[index]); 170: 171: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 172: drawctxt, &profile_dwords); 173: 174: if (profile_gpuaddr) { 175: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 176: cmds[index++] = lower_32_bits(profile_gpuaddr); 177: cmds[index++] = upper_32_bits(profile_gpuaddr); 178: cmds[index++] = profile_dwords; 179: } 180: 181: if (drawctxt) { 182: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 183: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 184: drawctxt)); 185: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 186: drawctxt)); 187: cmds[index++] = timestamp; 188: } 189: 190: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 191: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 192: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); MATCH LINES: 276, 282 264: cmds[index++] = rb->timestamp; 265: } 266: 267: if (IS_WFI(flags)) 268: cmds[index++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 269: 270: if (IS_SECURE(flags)) { 271: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 272: cmds[index++] = 0; 273: } 274: 275: /* 5 dwords */ 276: index += a5xx_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 277: 278: /* Adjust the thing for the number of bytes we actually wrote */ 279: rb->_wptr -= (size - index); 280: 281: a5xx_ringbuffer_submit(rb, time, 282: !adreno_is_preemption_enabled(adreno_dev)); 283: 284: return 0; 285: } 286: 287: static u32 a5xx_get_alwayson_counter(struct adreno_device *adreno_dev, 288: u32 *cmds, u64 gpuaddr) 289: { 290: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 291: cmds[1] = A5XX_RBBM_ALWAYSON_COUNTER_LO; 292: 293: /* On some targets the upper 32 bits are not reliable */ 294: if (ADRENO_GPUREV(adreno_dev) > ADRENO_REV_A530) 295: cmds[1] |= (1 << 30) | (2 << 18); 296: 297: cmds[2] = lower_32_bits(gpuaddr); 298: cmds[3] = upper_32_bits(gpuaddr); 299: 300: return 4; 301: } 302: 303: /* This is the maximum possible size for 64 bit targets */ 304: #define PROFILE_IB_DWORDS 4 305: #define PROFILE_IB_SLOTS (PAGE_SIZE / (PROFILE_IB_DWORDS << 2)) 306: MATCH LINES: 333 321: cmdobj->profiling_buffer_gpuaddr + target_offset); 322: 323: cmds[0] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 324: cmds[1] = lower_32_bits(gpuaddr); 325: cmds[2] = upper_32_bits(gpuaddr); 326: cmds[3] = dwords; 327: 328: rb->profile_index = (rb->profile_index + 1) % PROFILE_IB_SLOTS; 329: 330: return 4; 331: } 332: 333: static int a5xx_rb_context_switch(struct adreno_device *adreno_dev, 334: struct adreno_ringbuffer *rb, 335: struct adreno_context *drawctxt) 336: { 337: struct kgsl_pagetable *pagetable = 338: adreno_drawctxt_get_pagetable(drawctxt); 339: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 340: int count = 0; 341: u32 cmds[32]; 342: 343: if (adreno_drawctxt_get_pagetable(rb->drawctxt_active) != pagetable) 344: count += a5xx_rb_pagetable_switch(device, drawctxt, 345: rb, pagetable, cmds); 346: 347: cmds[count++] = cp_type7_packet(CP_NOP, 1); 348: cmds[count++] = CONTEXT_TO_MEM_IDENTIFIER; 349: 350: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 351: cmds[count++] = lower_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb, 352: current_context)); 353: cmds[count++] = upper_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb, 354: current_context)); 355: cmds[count++] = drawctxt->base.id; 356: 357: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); MATCH LINES: 388 376: 377: if (rb->drawctxt_active == drawctxt) 378: return 0; 379: 380: if (kgsl_context_detached(&drawctxt->base)) 381: return -ENOENT; 382: 383: if (!_kgsl_context_get(&drawctxt->base)) 384: return -ENOENT; 385: 386: trace_adreno_drawctxt_switch(rb, drawctxt); 387: 388: a5xx_rb_context_switch(adreno_dev, rb, drawctxt); 389: 390: /* Release the current drawctxt as soon as the new one is switched */ 391: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active, 392: rb, rb->timestamp); 393: 394: rb->drawctxt_active = drawctxt; 395: return 0; 396: } 397: 398: 399: #define A5XX_USER_PROFILE_IB(dev, rb, cmdobj, cmds, field) \ 400: a5xx_get_user_profiling_ib((dev), (rb), (cmdobj), \ 401: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 402: (cmds)) 403: 404: #define A5XX_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 405: a5xx_get_alwayson_counter((dev), (cmds), \ 406: (dev)->profile_buffer->gpuaddr + \ 407: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 408: field)) 409: 410: #define A5XX_COMMAND_DWORDS 32 411: 412: int a5xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev, MATCH LINES: 472 460: cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 461: cmds[index++] = lower_32_bits(ib->gpuaddr); 462: cmds[index++] = upper_32_bits(ib->gpuaddr); 463: 464: /* Double check that IB_PRIV is never set */ 465: cmds[index++] = (ib->size >> 2) & 0xfffff; 466: } 467: } 468: 469: /* 470: * SRM -- set render mode (ex binning, direct render etc) 471: * SRM is set by UMD usually at start of IB to tell CP the type of 472: * preemption. 473: * KMD needs to set SRM to NULL to indicate CP that rendering is 474: * done by IB. 475: */ 476: cmds[index++] = cp_type7_packet(CP_SET_RENDER_MODE, 5); 477: cmds[index++] = 0; 478: cmds[index++] = 0; 479: cmds[index++] = 0; 480: cmds[index++] = 0; 481: cmds[index++] = 0; 482: 483: cmds[index++] = cp_type7_packet(CP_YIELD_ENABLE, 1); 484: cmds[index++] = 1; 485: 486: /* 4 dwords */ 487: if (IS_KERNEL_PROFILE(flags)) 488: index += A5XX_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index], 489: retired); 490: 491: /* 4 dwords */ 492: if (IS_USER_PROFILE(flags)) 493: index += A5XX_USER_PROFILE_IB(adreno_dev, rb, cmdobj, 494: &cmds[index], gpu_ticks_retired); 495: 496: cmds[index++] = cp_type7_packet(CP_NOP, 1); --- FILE: \adreno_a5xx_snapshot.c | HITS: 2 --- MATCH LINES: 1010, 1011 998: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, 999: snapshot, a5xx_snapshot_cp_pfp, NULL); 1000: 1001: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, 1002: snapshot, a5xx_snapshot_cp_pm4, NULL); 1003: 1004: /* Debug bus */ 1005: a5xx_snapshot_debugbus(device, snapshot); 1006: 1007: /* Shader memory */ 1008: a5xx_snapshot_shader(device, snapshot); 1009: 1010: /* Preemption record */ 1011: adreno_snapshot_preemption_record(device, snapshot); 1012: } 1013: 1014: static int _a5xx_crashdump_init_shader(struct a5xx_shader_block *block, 1015: uint64_t *ptr, uint64_t *offset) 1016: { 1017: int qwords = 0; 1018: unsigned int j; 1019: 1020: /* Capture each bank in the block */ 1021: for (j = 0; j < A5XX_NUM_SHADER_BANKS; j++) { 1022: /* Program the aperture */ 1023: ptr[qwords++] = 1024: (block->statetype << A5XX_SHADER_STATETYPE_SHIFT) | j; 1025: ptr[qwords++] = (((uint64_t) A5XX_HLSQ_DBG_READ_SEL << 44)) | 1026: (1 << 21) | 1; 1027: 1028: /* Read all the data in one chunk */ 1029: ptr[qwords++] = registers->gpuaddr + *offset; 1030: ptr[qwords++] = 1031: (((uint64_t) A5XX_HLSQ_DBG_AHB_READ_APERTURE << 44)) | 1032: block->sz; 1033: 1034: /* Remember the offset of the first bank for easy access */ 1035: if (j == 0) --- FILE: \adreno_a6xx.c | HITS: 39 --- MATCH LINES: 28, 57 16: #include 17: #endif 18: 19: #include "adreno.h" 20: #include "adreno_a6xx.h" 21: #include "adreno_a6xx_hwsched.h" 22: #include "adreno_pm4types.h" 23: #include "adreno_trace.h" 24: #include "kgsl_gmu_core.h" 25: #include "kgsl_trace.h" 26: #include "kgsl_util.h" 27: 28: /* IFPC & Preemption static powerup restore list */ 29: static u32 a6xx_pwrup_reglist[] = { 30: A6XX_VSC_ADDR_MODE_CNTL, 31: A6XX_GRAS_ADDR_MODE_CNTL, 32: A6XX_RB_ADDR_MODE_CNTL, 33: A6XX_PC_ADDR_MODE_CNTL, 34: A6XX_HLSQ_ADDR_MODE_CNTL, 35: A6XX_VFD_ADDR_MODE_CNTL, 36: A6XX_VPC_ADDR_MODE_CNTL, 37: A6XX_UCHE_ADDR_MODE_CNTL, 38: A6XX_SP_ADDR_MODE_CNTL, 39: A6XX_TPL1_ADDR_MODE_CNTL, 40: A6XX_UCHE_WRITE_RANGE_MAX_LO, 41: A6XX_UCHE_WRITE_RANGE_MAX_HI, 42: A6XX_UCHE_TRAP_BASE_LO, 43: A6XX_UCHE_TRAP_BASE_HI, 44: A6XX_UCHE_WRITE_THRU_BASE_LO, 45: A6XX_UCHE_WRITE_THRU_BASE_HI, 46: A6XX_UCHE_GMEM_RANGE_MIN_LO, 47: A6XX_UCHE_GMEM_RANGE_MIN_HI, 48: A6XX_UCHE_GMEM_RANGE_MAX_LO, 49: A6XX_UCHE_GMEM_RANGE_MAX_HI, 50: A6XX_UCHE_FILTER_CNTL, 51: A6XX_UCHE_CACHE_WAYS, 52: A6XX_UCHE_MODE_CNTL, 53: A6XX_RB_NC_MODE_CNTL, 54: A6XX_TPL1_NC_MODE_CNTL, 55: A6XX_SP_NC_MODE_CNTL, 56: A6XX_PC_DBG_ECO_CNTL, 57: A6XX_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, 58: A6XX_UCHE_GBIF_GX_CONFIG, 59: A6XX_UCHE_CLIENT_PF, 60: }; 61: 62: /* IFPC only static powerup restore list */ 63: static u32 a6xx_ifpc_pwrup_reglist[] = { 64: A6XX_CP_CHICKEN_DBG, 65: A6XX_CP_DBG_ECO_CNTL, 66: A6XX_CP_PROTECT_CNTL, 67: A6XX_CP_PROTECT_REG, 68: A6XX_CP_PROTECT_REG+1, 69: A6XX_CP_PROTECT_REG+2, 70: A6XX_CP_PROTECT_REG+3, 71: A6XX_CP_PROTECT_REG+4, 72: A6XX_CP_PROTECT_REG+5, 73: A6XX_CP_PROTECT_REG+6, 74: A6XX_CP_PROTECT_REG+7, 75: A6XX_CP_PROTECT_REG+8, 76: A6XX_CP_PROTECT_REG+9, 77: A6XX_CP_PROTECT_REG+10, 78: A6XX_CP_PROTECT_REG+11, 79: A6XX_CP_PROTECT_REG+12, 80: A6XX_CP_PROTECT_REG+13, 81: A6XX_CP_PROTECT_REG+14, MATCH LINES: 502 490: u32 *dest = ptr + sizeof(*lock); 491: u16 list_offset = 0; 492: 493: /* Static IFPC-only registers */ 494: reglist[items] = REGLIST(a6xx_ifpc_pwrup_reglist); 495: list_offset += reglist[items++].count * 2; 496: 497: if (adreno_is_a650_family(adreno_dev)) { 498: reglist[items] = REGLIST(a650_ifpc_pwrup_reglist); 499: list_offset += reglist[items++].count * 2; 500: } 501: 502: /* Static IFPC + preemption registers */ 503: reglist[items++] = REGLIST(a6xx_pwrup_reglist); 504: 505: /* Add target specific registers */ 506: if (adreno_is_a615_family(adreno_dev)) 507: reglist[items++] = REGLIST(a615_pwrup_reglist); 508: else if (adreno_is_a650_family(adreno_dev)) 509: reglist[items++] = REGLIST(a650_pwrup_reglist); 510: 511: /* 512: * For each entry in each of the lists, write the offset and the current 513: * register value into the GPU buffer 514: */ 515: for (i = 0; i < items; i++) { 516: u32 *r = reglist[i].regs; 517: 518: for (j = 0; j < reglist[i].count; j++) { 519: *dest++ = r[j]; 520: kgsl_regread(KGSL_DEVICE(adreno_dev), r[j], dest++); 521: } 522: 523: lock->list_length += reglist[i].count * 2; 524: 525: if ((r == a6xx_ifpc_pwrup_reglist) || (r == a650_ifpc_pwrup_reglist)) { 526: u32 cs_len = adreno_coresight_patch_pwrup_reglist(adreno_dev, dest); MATCH LINES: 554, 555 542: A6XX_RBBM_GBIF_CLIENT_QOS_CNTL, dest++); 543: } 544: 545: lock->list_length += 2; 546: 547: *dest++ = A6XX_RBBM_PERFCTR_CNTL; 548: *dest++ = 1; 549: lock->list_length += 2; 550: 551: /* 552: * The overall register list is composed of 553: * 1. Static IFPC-only registers 554: * 2. Static IFPC + preemption registers 555: * 3. Dynamic IFPC + preemption registers (ex: perfcounter selects) 556: * 557: * The CP views the second and third entries as one dynamic list 558: * starting from list_offset. list_length should be the total dwords in 559: * all the lists and list_offset should be specified as the size in 560: * dwords of the first entry in the list. 561: */ 562: lock->list_offset = list_offset; 563: } 564: 565: 566: static void a6xx_llc_configure_gpu_scid(struct adreno_device *adreno_dev); 567: static void a6xx_llc_configure_gpuhtw_scid(struct adreno_device *adreno_dev); 568: static void a6xx_llc_configure_gpumv_scid(struct adreno_device *adreno_dev); 569: static void a6xx_llc_enable_overrides(struct adreno_device *adreno_dev); 570: 571: static void a6xx_set_secvid(struct kgsl_device *device) 572: { 573: static bool set; 574: 575: if (set || !device->mmu.secured) 576: return; 577: 578: kgsl_regwrite(device, A6XX_RBBM_SECVID_TSB_CNTL, 0x0); 579: kgsl_regwrite(device, A6XX_RBBM_SECVID_TSB_TRUSTED_BASE_LO, MATCH LINES: 822, 823, 824 810: /* Set TWOPASSUSEWFI in A6XX_PC_DBG_ECO_CNTL if requested */ 811: if (ADRENO_QUIRK(adreno_dev, ADRENO_QUIRK_TWO_PASS_USE_WFI)) 812: kgsl_regrmw(device, A6XX_PC_DBG_ECO_CNTL, 0, (1 << 8)); 813: 814: /* Set the bit vccCacheSkipDis=1 to get rid of TSEskip logic */ 815: if (a6xx_core->disable_tseskip) 816: kgsl_regrmw(device, A6XX_PC_DBG_ECO_CNTL, 0, (1 << 9)); 817: 818: /* Set the bit in HLSQ Cluster for A702 family */ 819: if (adreno_is_a702_family(adreno_dev)) 820: kgsl_regwrite(device, A6XX_CP_CHICKEN_DBG, (1 << 24)); 821: 822: /* Enable the GMEM save/restore feature for preemption */ 823: if (adreno_is_preemption_enabled(adreno_dev)) 824: kgsl_regwrite(device, A6XX_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, 825: 0x1); 826: 827: /* 828: * Enable GMU power counter 0 to count GPU busy. This is applicable to 829: * all a6xx targets 830: */ 831: kgsl_regwrite(device, A6XX_GPU_GMU_AO_GPU_CX_BUSY_MASK, 0xff000000); 832: kgsl_regrmw(device, A6XX_GMU_CX_GMU_POWER_COUNTER_SELECT_0, 0xff, 0x20); 833: kgsl_regwrite(device, A6XX_GMU_CX_GMU_POWER_COUNTER_ENABLE, 0x1); 834: 835: a6xx_protect_init(adreno_dev); 836: /* 837: * We start LM here because we want all the following to be up 838: * 1. GX HS 839: * 2. SPTPRAC 840: * 3. HFI 841: * At this point, we are guaranteed all. 842: */ 843: 844: /* Configure LLCC */ 845: a6xx_llc_configure_gpu_scid(adreno_dev); 846: a6xx_llc_configure_gpuhtw_scid(adreno_dev); 847: a6xx_llc_configure_gpumv_scid(adreno_dev); 848: MATCH LINES: 955 943: #define CP_INIT_DEFAULT_RESET_STATE BIT(3) 944: 945: /* Drawcall filter range */ 946: #define CP_INIT_DRAWCALL_FILTER_RANGE BIT(4) 947: 948: /* Ucode workaround masks */ 949: #define CP_INIT_UCODE_WORKAROUND_MASK BIT(5) 950: 951: /* 952: * Operation mode mask 953: * 954: * This ordinal provides the option to disable the 955: * save/restore of performance counters across preemption. 956: */ 957: #define CP_INIT_OPERATION_MODE_MASK BIT(6) 958: 959: /* Register initialization list */ 960: #define CP_INIT_REGISTER_INIT_LIST BIT(7) 961: 962: /* Register initialization list with spinlock */ 963: #define CP_INIT_REGISTER_INIT_LIST_WITH_SPINLOCK BIT(8) 964: 965: #define CP_INIT_MASK (CP_INIT_MAX_CONTEXT | \ 966: CP_INIT_ERROR_DETECTION_CONTROL | \ 967: CP_INIT_HEADER_DUMP | \ 968: CP_INIT_DEFAULT_RESET_STATE | \ 969: CP_INIT_UCODE_WORKAROUND_MASK | \ 970: CP_INIT_OPERATION_MODE_MASK | \ 971: CP_INIT_REGISTER_INIT_LIST_WITH_SPINLOCK) 972: 973: void a6xx_cp_init_cmds(struct adreno_device *adreno_dev, u32 *cmds) 974: { 975: int i = 0; 976: 977: cmds[i++] = cp_type7_packet(CP_ME_INIT, A6XX_CP_INIT_DWORDS - 1); 978: 979: /* Enabled ordinal mask */ MATCH LINES: 1078, 1081, 1092, 1094, 1096, 1099, 1101, 1108, 1111, 1124, 1130, 1135, 1144, 1170, 1173 1066: 1067: kgsl_sharedmem_writel(device->scratch, 1068: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1069: rb->wptr = 0; 1070: rb->_wptr = 0; 1071: } 1072: } 1073: 1074: return ret; 1075: } 1076: 1077: /* 1078: * Follow the ME_INIT sequence with a preemption yield to allow the GPU to move 1079: * to a different ringbuffer, if desired 1080: */ 1081: static int _preemption_init(struct adreno_device *adreno_dev, 1082: struct adreno_ringbuffer *rb, unsigned int *cmds, 1083: struct kgsl_context *context) 1084: { 1085: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1086: unsigned int *cmds_orig = cmds; 1087: 1088: /* Turn CP protection OFF on legacy targets */ 1089: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 1090: cmds += cp_protected_mode(adreno_dev, cmds, 0); 1091: 1092: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 1093: kgsl_mmu_is_secured(&device->mmu) ? 6 : 3); 1094: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 1095: cmds += cp_gpuaddr(adreno_dev, cmds, 1096: rb->preemption_desc->gpuaddr); 1097: 1098: if (kgsl_mmu_is_secured(&device->mmu)) { 1099: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 1100: cmds += cp_gpuaddr(adreno_dev, cmds, 1101: rb->secure_preemption_desc->gpuaddr); 1102: } 1103: 1104: /* Turn CP protection back ON */ 1105: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 1106: cmds += cp_protected_mode(adreno_dev, cmds, 1); 1107: 1108: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1109: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 1110: *cmds++ = 0; 1111: /* generate interrupt on preemption completion */ 1112: *cmds++ = 0; 1113: 1114: return cmds - cmds_orig; 1115: } 1116: 1117: static int a6xx_post_start(struct adreno_device *adreno_dev) 1118: { 1119: int ret; 1120: unsigned int *cmds, *start; 1121: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1122: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1123: 1124: if (!adreno_is_preemption_enabled(adreno_dev)) 1125: return 0; 1126: 1127: cmds = adreno_ringbuffer_allocspace(rb, 42); 1128: if (IS_ERR(cmds)) { 1129: dev_err(device->dev, 1130: "error allocating preemption init cmds\n"); 1131: return PTR_ERR(cmds); 1132: } 1133: start = cmds; 1134: 1135: cmds += _preemption_init(adreno_dev, rb, cmds, NULL); 1136: 1137: rb->_wptr = rb->_wptr - (42 - (cmds - start)); 1138: 1139: ret = a6xx_ringbuffer_submit(rb, NULL, false); 1140: if (!ret) { 1141: ret = adreno_spin_idle(adreno_dev, 2000); 1142: if (ret) 1143: a6xx_spin_idle_debug(adreno_dev, 1144: "hw preemption initialization failed to idle\n"); 1145: } 1146: 1147: return ret; 1148: } 1149: 1150: int a6xx_rb_start(struct adreno_device *adreno_dev) 1151: { 1152: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev); 1153: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1154: u32 cp_rb_cntl = A6XX_CP_RB_CNTL_DEFAULT | 1155: (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? 0 : (1 << 27)); 1156: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 1157: struct adreno_ringbuffer *rb; 1158: uint64_t addr; 1159: int ret, i; 1160: unsigned int *cmds; 1161: 1162: /* Clear all the ringbuffers */ 1163: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1164: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 1165: kgsl_sharedmem_writel(device->scratch, 1166: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1167: 1168: rb->wptr = 0; 1169: rb->_wptr = 0; 1170: rb->wptr_preempt_end = ~0; 1171: } 1172: 1173: a6xx_preemption_start(adreno_dev); 1174: 1175: /* Set up the current ringbuffer */ 1176: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 1177: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 1178: 1179: kgsl_regwrite(device, A6XX_CP_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1180: kgsl_regwrite(device, A6XX_CP_RB_RPTR_ADDR_HI, upper_32_bits(addr)); 1181: 1182: /* 1183: * The size of the ringbuffer in the hardware is the log2 1184: * representation of the size in quadwords (sizedwords / 2). 1185: */ 1186: kgsl_regwrite(device, A6XX_CP_RB_CNTL, cp_rb_cntl); 1187: 1188: kgsl_regwrite(device, A6XX_CP_RB_BASE, 1189: lower_32_bits(rb->buffer_desc->gpuaddr)); 1190: 1191: kgsl_regwrite(device, A6XX_CP_RB_BASE_HI, 1192: upper_32_bits(rb->buffer_desc->gpuaddr)); 1193: 1194: /* Program the ucode base for CP */ 1195: kgsl_regwrite(device, A6XX_CP_SQE_INSTR_BASE_LO, 1196: lower_32_bits(fw->memdesc->gpuaddr)); 1197: kgsl_regwrite(device, A6XX_CP_SQE_INSTR_BASE_HI, MATCH LINES: 1492 1480: ret = a6xx_clear_pending_transactions(adreno_dev); 1481: if (ret) 1482: return ret; 1483: 1484: /* Clear ctrl_flags to ensure clocks and regulators are turned off */ 1485: device->pwrctrl.ctrl_flags = 0; 1486: 1487: kgsl_pwrctrl_change_state(device, KGSL_STATE_INIT); 1488: 1489: /* since device is officially off now clear start bit */ 1490: clear_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv); 1491: 1492: a6xx_reset_preempt_records(adreno_dev); 1493: 1494: ret = adreno_start(device, 0); 1495: if (ret) 1496: return ret; 1497: 1498: kgsl_pwrctrl_change_state(device, KGSL_STATE_ACTIVE); 1499: 1500: device->pwrctrl.ctrl_flags = flags; 1501: 1502: /* Toggle GX CPR on demand */ 1503: a6xx_gx_cpr_toggle(device); 1504: 1505: /* 1506: * If active_cnt is zero, there is no need to keep the GPU active. So, 1507: * we should transition to SLUMBER. 1508: */ 1509: if (!atomic_read(&device->active_cnt)) 1510: kgsl_pwrctrl_change_state(device, KGSL_STATE_SLUMBER); 1511: 1512: return 0; 1513: } 1514: 1515: static void a6xx_cp_hw_err_callback(struct adreno_device *adreno_dev, int bit) 1516: { MATCH LINES: 1803, 1804, 1841 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 */ MATCH LINES: 2002, 2008, 2009, 2010 1990: device->pwrctrl.cx_cfg_gdsc_offset = (adreno_is_a662(adreno_dev) || 1991: adreno_is_a621(adreno_dev) || adreno_is_a663(adreno_dev) || 1992: adreno_is_a623(adreno_dev)) ? 1993: A662_GPU_CC_CX_CFG_GDSCR : A6XX_GPU_CC_CX_CFG_GDSCR; 1994: 1995: if (adreno_is_a622(adreno_dev)) 1996: device->pwrctrl.cx_cfg_gdsc_offset = A622_GPU_CC_CX_CFG_GDSCR; 1997: } 1998: 1999: adreno_dev->hwcg_enabled = true; 2000: adreno_dev->uche_client_pf = 1; 2001: 2002: if (adreno_preemption_feature_set(adreno_dev)) { 2003: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev); 2004: 2005: adreno_dev->total_ctxt_record_sz = a6xx_core->ctxt_record_size ? 2006: a6xx_core->ctxt_record_size : A6XX_CP_CTXRECORD_SIZE_IN_BYTES; 2007: 2008: adreno_dev->preempt.preempt_level = 1; 2009: adreno_dev->preempt.skipsaverestore = true; 2010: adreno_dev->preempt.usesgmem = true; 2011: } 2012: 2013: ret = adreno_device_probe(pdev, adreno_dev); 2014: 2015: if (ret) 2016: return ret; 2017: 2018: a6xx_coresight_init(adreno_dev); 2019: return 0; 2020: } 2021: 2022: static int a6xx_probe(struct platform_device *pdev, 2023: u32 chipid, const struct adreno_gpu_core *gpucore) 2024: { 2025: struct adreno_device *adreno_dev; 2026: struct kgsl_device *device; 2027: struct platform_device *gmu_wrapper_pdev; 2028: int ret; 2029: 2030: adreno_dev = (struct adreno_device *) 2031: of_device_get_match_data(&pdev->dev); 2032: 2033: memset(adreno_dev, 0, sizeof(*adreno_dev)); 2034: MATCH LINES: 2209, 2210 2197: if (hi != tmp) { 2198: gmu_core_regread(device, A6XX_GMU_ALWAYS_ON_COUNTER_L, 2199: &lo); 2200: hi = tmp; 2201: } 2202: } 2203: 2204: return (((u64) hi) << 32) | lo; 2205: } 2206: 2207: static void a6xx_remove(struct adreno_device *adreno_dev) 2208: { 2209: if (adreno_preemption_feature_set(adreno_dev)) 2210: kgsl_delete_timer(&adreno_dev->preempt.timer); 2211: } 2212: 2213: static void a6xx_read_bus_stats(struct kgsl_device *device, 2214: struct kgsl_power_stats *stats, 2215: struct adreno_busy_data *busy) 2216: { 2217: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 2218: u64 ram_cycles, starved_ram; 2219: 2220: ram_cycles = counter_delta(device, adreno_dev->ram_cycles_lo, 2221: &busy->bif_ram_cycles); 2222: 2223: starved_ram = counter_delta(device, adreno_dev->starved_ram_lo, 2224: &busy->bif_starved_ram); 2225: 2226: if (!adreno_is_a630(adreno_dev)) { 2227: ram_cycles += counter_delta(device, 2228: adreno_dev->ram_cycles_lo_ch1_read, 2229: &busy->bif_ram_cycles_read_ch1); 2230: 2231: ram_cycles += counter_delta(device, 2232: adreno_dev->ram_cycles_lo_ch0_write, 2233: &busy->bif_ram_cycles_write_ch0); 2234: MATCH LINES: 2397 2385: .reg_offsets = a6xx_register_offsets, 2386: .probe = a6xx_probe, 2387: .start = a6xx_nogmu_start, 2388: .snapshot = a6xx_snapshot, 2389: .init = a6xx_nogmu_init, 2390: .irq_handler = a6xx_irq_handler, 2391: .rb_start = a6xx_rb_start, 2392: .regulator_disable = a6xx_prepare_for_regulator_disable, 2393: .gpu_keepalive = a6xx_gpu_keepalive, 2394: .hw_isidle = a6xx_hw_isidle, 2395: .iommu_fault_block = a6xx_iommu_fault_block, 2396: .reset = a6xx_reset, 2397: .preemption_schedule = a6xx_preemption_schedule, 2398: .read_alwayson = a6xx_read_alwayson, 2399: .power_ops = &adreno_power_operations, 2400: .clear_pending_transactions = a6xx_clear_pending_transactions, 2401: .deassert_gbif_halt = a6xx_deassert_gbif_halt, 2402: .remove = a6xx_remove, 2403: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2404: .is_hw_collapsible = adreno_isidle, 2405: .power_stats = a6xx_power_stats, 2406: .add_to_va_minidump = a6xx_dev_add_to_minidump, 2407: .gx_is_on = a6xx_gx_is_on, 2408: }; 2409: 2410: const struct a6xx_gpudev adreno_a6xx_hwsched_gpudev = { 2411: .base = { 2412: .reg_offsets = a6xx_register_offsets, 2413: .probe = a6xx_hwsched_probe, 2414: .snapshot = a6xx_hwsched_snapshot, 2415: .irq_handler = a6xx_hwsched_irq_handler, 2416: .iommu_fault_block = a6xx_iommu_fault_block, 2417: .context_detach = a6xx_hwsched_context_detach, 2418: .read_alwayson = a6xx_read_alwayson, 2419: .reset = a6xx_hwsched_reset_replay, 2420: .power_ops = &a6xx_hwsched_power_ops, 2421: .power_stats = a6xx_power_stats, MATCH LINES: 2446, 2472, 2497, 2523 2434: .base = { 2435: .reg_offsets = a6xx_register_offsets, 2436: .probe = a6xx_gmu_device_probe, 2437: .snapshot = a6xx_gmu_snapshot, 2438: .irq_handler = a6xx_irq_handler, 2439: .rb_start = a6xx_rb_start, 2440: .regulator_enable = a6xx_sptprac_enable, 2441: .regulator_disable = a6xx_sptprac_disable, 2442: .gpu_keepalive = a6xx_gpu_keepalive, 2443: .hw_isidle = a6xx_hw_isidle, 2444: .iommu_fault_block = a6xx_iommu_fault_block, 2445: .reset = a6xx_gmu_reset, 2446: .preemption_schedule = a6xx_preemption_schedule, 2447: .read_alwayson = a6xx_read_alwayson, 2448: .power_ops = &a6xx_gmu_power_ops, 2449: .remove = a6xx_remove, 2450: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2451: .power_stats = a6xx_power_stats, 2452: .add_to_va_minidump = a6xx_gmu_add_to_minidump, 2453: .gx_is_on = a6xx_gmu_gx_is_on, 2454: .set_isdb_breakpoint_registers = a6xx_set_isdb_breakpoint_registers, 2455: }, 2456: .hfi_probe = a6xx_gmu_hfi_probe, 2457: .handle_watchdog = a6xx_gmu_handle_watchdog, 2458: }; 2459: 2460: const struct adreno_gpudev adreno_a6xx_rgmu_gpudev = { 2461: .reg_offsets = a6xx_register_offsets, 2462: .probe = a6xx_rgmu_device_probe, 2463: .snapshot = a6xx_rgmu_snapshot, 2464: .irq_handler = a6xx_irq_handler, 2465: .rb_start = a6xx_rb_start, 2466: .regulator_enable = a6xx_sptprac_enable, 2467: .regulator_disable = a6xx_sptprac_disable, 2468: .gpu_keepalive = a6xx_gpu_keepalive, 2469: .hw_isidle = a6xx_hw_isidle, 2470: .iommu_fault_block = a6xx_iommu_fault_block, 2471: .reset = a6xx_rgmu_reset, 2472: .preemption_schedule = a6xx_preemption_schedule, 2473: .read_alwayson = a6xx_read_alwayson, 2474: .power_ops = &a6xx_rgmu_power_ops, 2475: .remove = a6xx_remove, 2476: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2477: .power_stats = a6xx_power_stats, 2478: .add_to_va_minidump = a6xx_rgmu_add_to_minidump, 2479: .gx_is_on = a6xx_rgmu_gx_is_on, 2480: }; 2481: 2482: /* This is a non GMU/RGMU part */ 2483: const struct adreno_gpudev adreno_a619_holi_gpudev = { 2484: .reg_offsets = a6xx_register_offsets, 2485: .probe = a6xx_probe, 2486: .start = a6xx_nogmu_start, 2487: .snapshot = a6xx_snapshot, 2488: .init = a6xx_nogmu_init, 2489: .irq_handler = a6xx_irq_handler, 2490: .rb_start = a6xx_rb_start, 2491: .regulator_enable = a619_holi_sptprac_enable, 2492: .regulator_disable = a619_holi_sptprac_disable, 2493: .gpu_keepalive = a6xx_gpu_keepalive, 2494: .hw_isidle = a619_holi_hw_isidle, 2495: .iommu_fault_block = a6xx_iommu_fault_block, 2496: .reset = a6xx_reset, 2497: .preemption_schedule = a6xx_preemption_schedule, 2498: .read_alwayson = a6xx_read_alwayson, 2499: .power_ops = &adreno_power_operations, 2500: .clear_pending_transactions = a6xx_clear_pending_transactions, 2501: .deassert_gbif_halt = a6xx_deassert_gbif_halt, 2502: .remove = a6xx_remove, 2503: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2504: .is_hw_collapsible = adreno_isidle, 2505: .power_stats = a6xx_power_stats, 2506: .add_to_va_minidump = a6xx_dev_add_to_minidump, 2507: .gx_is_on = a619_holi_gx_is_on, 2508: }; 2509: 2510: const struct a6xx_gpudev adreno_a630_gpudev = { 2511: .base = { 2512: .reg_offsets = a6xx_register_offsets, 2513: .probe = a6xx_gmu_device_probe, 2514: .snapshot = a6xx_gmu_snapshot, 2515: .irq_handler = a6xx_irq_handler, 2516: .rb_start = a6xx_rb_start, 2517: .regulator_enable = a6xx_sptprac_enable, 2518: .regulator_disable = a6xx_sptprac_disable, 2519: .gpu_keepalive = a6xx_gpu_keepalive, 2520: .hw_isidle = a6xx_hw_isidle, 2521: .iommu_fault_block = a6xx_iommu_fault_block, 2522: .reset = a6xx_gmu_reset, 2523: .preemption_schedule = a6xx_preemption_schedule, 2524: .read_alwayson = a6xx_read_alwayson, 2525: .power_ops = &a630_gmu_power_ops, 2526: .remove = a6xx_remove, 2527: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2528: .power_stats = a6xx_power_stats, 2529: .add_to_va_minidump = a6xx_gmu_add_to_minidump, 2530: .gx_is_on = a6xx_gmu_gx_is_on, 2531: }, 2532: .hfi_probe = a6xx_gmu_hfi_probe, 2533: .handle_watchdog = a6xx_gmu_handle_watchdog, 2534: }; --- FILE: \adreno_a6xx.h | HITS: 22 --- MATCH LINES: 85, 106, 107, 113, 122, 124, 139, 158 73: /** @veto_fal10: veto status for fal10 feature */ 74: bool veto_fal10; 75: /** @pdc_in_aop: True if PDC programmed in AOP */ 76: bool pdc_in_aop; 77: /** @hang_detect_cycles: Hang detect counter timeout value */ 78: u32 hang_detect_cycles; 79: /** @protected_regs: Array of protected registers for the target */ 80: const struct adreno_protected_regs *protected_regs; 81: /** @disable_tseskip: True if TSESkip logic is disabled */ 82: bool disable_tseskip; 83: /** @gx_cpr_toggle: True to toggle GX CPR FSM to avoid CPR stalls */ 84: bool gx_cpr_toggle; 85: /** @ctxt_record_size: Size of the preemption record in bytes */ 86: u64 ctxt_record_size; 87: /** @gmu_hub_clk_freq: Gmu hub interface clock frequency */ 88: u64 gmu_hub_clk_freq; 89: }; 90: 91: #define SPTPRAC_POWERON_CTRL_MASK 0x00778000 92: #define SPTPRAC_POWEROFF_CTRL_MASK 0x00778001 93: #define SPTPRAC_POWEROFF_STATUS_MASK BIT(2) 94: #define SPTPRAC_POWERON_STATUS_MASK BIT(3) 95: #define A6XX_RETAIN_FF_ENABLE_ENABLE_MASK BIT(11) 96: 97: #define CP_CLUSTER_FE 0x0 98: #define CP_CLUSTER_SP_VS 0x1 99: #define CP_CLUSTER_PC_VS 0x2 100: #define CP_CLUSTER_GRAS 0x3 101: #define CP_CLUSTER_SP_PS 0x4 102: #define CP_CLUSTER_PS 0x5 103: #define CP_CLUSTER_VPC_PS 0x6 104: 105: /** 106: * struct a6xx_cp_preemption_record - CP context record for 107: * preemption. 108: * @magic: (00) Value at this offset must be equal to 109: * A6XX_CP_CTXRECORD_MAGIC_REF. 110: * @info: (04) Type of record. Written non-zero (usually) by CP. 111: * we must set to zero for all ringbuffers. 112: * @errno: (08) Error code. Initialize this to A6XX_CP_CTXRECORD_ERROR_NONE. 113: * CP will update to another value if a preemption error occurs. 114: * @data: (12) DATA field in YIELD and SET_MARKER packets. 115: * Written by CP when switching out. Not used on switch-in. Initialized to 0. 116: * @cntl: (16) RB_CNTL, saved and restored by CP. We must initialize this. 117: * @rptr: (20) RB_RPTR, saved and restored by CP. We must initialize this. 118: * @wptr: (24) RB_WPTR, saved and restored by CP. We must initialize this. 119: * @_pad28: (28) Reserved/padding. 120: * @rptr_addr: (32) RB_RPTR_ADDR_LO|HI saved and restored. We must initialize. 121: * rbase: (40) RB_BASE_LO|HI saved and restored. 122: * counter: (48) Pointer to preemption counter. 123: */ 124: struct a6xx_cp_preemption_record { 125: uint32_t magic; 126: uint32_t info; 127: uint32_t errno; 128: uint32_t data; 129: uint32_t cntl; 130: uint32_t rptr; 131: uint32_t wptr; 132: uint32_t _pad28; 133: uint64_t rptr_addr; 134: uint64_t rbase; 135: uint64_t counter; 136: }; 137: 138: /** 139: * struct a6xx_cp_smmu_info - CP preemption SMMU info. 140: * @magic: (00) The value at this offset must be equal to 141: * A6XX_CP_SMMU_INFO_MAGIC_REF. 142: * @_pad4: (04) Reserved/padding 143: * @ttbr0: (08) Base address of the page table for the 144: * incoming context. 145: * @context_idr: (16) Context Identification Register value. 146: */ 147: struct a6xx_cp_smmu_info { 148: uint32_t magic; 149: uint32_t _pad4; 150: uint64_t ttbr0; 151: uint32_t asid; 152: uint32_t context_idr; 153: }; 154: 155: #define A6XX_CP_SMMU_INFO_MAGIC_REF 0x241350D5UL 156: 157: #define A6XX_CP_CTXRECORD_MAGIC_REF 0xAE399D6EUL 158: /* Size of each CP preemption record */ 159: #define A6XX_CP_CTXRECORD_SIZE_IN_BYTES (2112 * 1024) 160: /* Size of the performance counter save/restore block (in bytes) */ 161: #define A6XX_CP_PERFCOUNTER_SAVE_RESTORE_SIZE (4 * 1024) 162: 163: #define A6XX_CP_RB_CNTL_DEFAULT (((ilog2(4) << 8) & 0x1F00) | \ 164: (ilog2(KGSL_RB_DWORDS >> 1) & 0x3F)) 165: 166: /* Size of the CP_INIT pm4 stream in dwords */ 167: #define A6XX_CP_INIT_DWORDS 11 168: 169: #define A6XX_INT_MASK \ 170: ((1 << A6XX_INT_CP_AHB_ERROR) | \ 171: (1 << A6XX_INT_ATB_ASYNCFIFO_OVERFLOW) | \ 172: (1 << A6XX_INT_RBBM_GPC_ERROR) | \ 173: (1 << A6XX_INT_CP_SW) | \ 174: (1 << A6XX_INT_CP_HW_ERROR) | \ 175: (1 << A6XX_INT_CP_IB2) | \ 176: (1 << A6XX_INT_CP_IB1) | \ 177: (1 << A6XX_INT_CP_RB) | \ 178: (1 << A6XX_INT_CP_CACHE_FLUSH_TS) | \ 179: (1 << A6XX_INT_RBBM_ATB_BUS_OVERFLOW) | \ 180: (1 << A6XX_INT_RBBM_HANG_DETECT) | \ 181: (1 << A6XX_INT_UCHE_OOB_ACCESS) | \ 182: (1 << A6XX_INT_UCHE_TRAP_INTR) | \ MATCH LINES: 208, 209, 210, 211, 212, 215, 221, 224, 232, 236, 238 196: * 197: * Returns: 198: * A pointer to the a6xx specific GPU core struct 199: */ 200: static inline const struct adreno_a6xx_core * 201: to_a6xx_core(struct adreno_device *adreno_dev) 202: { 203: const struct adreno_gpu_core *core = adreno_dev->gpucore; 204: 205: return container_of(core, struct adreno_a6xx_core, base); 206: } 207: 208: /* Preemption functions */ 209: void a6xx_preemption_trigger(struct adreno_device *adreno_dev, bool atomic); 210: void a6xx_preemption_schedule(struct adreno_device *adreno_dev); 211: void a6xx_preemption_start(struct adreno_device *adreno_dev); 212: int a6xx_preemption_init(struct adreno_device *adreno_dev); 213: 214: /** 215: * a6xx_preemption_post_ibsubmit - Insert commands following a submission 216: * @adreno_dev: Adreno GPU handle 217: * @cmds: Pointer to the ringbuffer to insert opcodes 218: * 219: * Return: The number of dwords written to @cmds 220: */ 221: u32 a6xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, u32 *cmds); 222: 223: /** 224: * a6xx_preemption_post_ibsubmit - Insert opcodes before a submission 225: * @adreno_dev: Adreno GPU handle 226: * @rb: The ringbuffer being written 227: * @drawctxt: The draw context being written 228: * @cmds: Pointer to the ringbuffer to insert opcodes 229: * 230: * Return: The number of dwords written to @cmds 231: */ 232: u32 a6xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 233: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 234: u32 *cmds); 235: 236: void a6xx_preemption_callback(struct adreno_device *adreno_dev, int bit); 237: 238: void a6xx_preemption_context_destroy(struct kgsl_context *context); 239: 240: void a6xx_snapshot(struct adreno_device *adreno_dev, 241: struct kgsl_snapshot *snapshot); 242: void a6xx_crashdump_init(struct adreno_device *adreno_dev); 243: int a6xx_gmu_sptprac_enable(struct adreno_device *adreno_dev); 244: void a6xx_gmu_sptprac_disable(struct adreno_device *adreno_dev); 245: bool a6xx_gmu_sptprac_is_on(struct adreno_device *adreno_dev); 246: bool a619_holi_gx_is_on(struct adreno_device *adreno_dev); 247: 248: /** 249: * a6xx_read_alwayson - Read the current always on clock value 250: * @adreno_dev: An Adreno GPU handle 251: * 252: * Return: The current value of the GMU always on counter 253: */ 254: u64 a6xx_read_alwayson(struct adreno_device *adreno_dev); 255: 256: /** 257: * a6xx_start - Program a6xx registers 258: * @adreno_dev: An Adreno GPU handle 259: * 260: * This function does all a6xx register programming every 261: * time we boot the gpu 262: */ MATCH LINES: 396, 399, 401 384: 385: void a6xx_cp_init_cmds(struct adreno_device *adreno_dev, u32 *cmds); 386: 387: int a6xx_gmu_hfi_probe(struct adreno_device *adreno_dev); 388: 389: static inline const struct a6xx_gpudev * 390: to_a6xx_gpudev(const struct adreno_gpudev *gpudev) 391: { 392: return container_of(gpudev, struct a6xx_gpudev, base); 393: } 394: 395: /** 396: * a6xx_reset_preempt_records - Reset the preemption buffers 397: * @adreno_dev: Handle to the adreno device 398: * 399: * Reset the preemption records at the time of hard reset 400: */ 401: void a6xx_reset_preempt_records(struct adreno_device *adreno_dev); 402: 403: /** 404: * a6xx_irq_pending - Check if there is any gpu irq pending 405: * @adreno_dev: Handle to the adreno device 406: * 407: * Return true if there is any gpu irq pending 408: */ 409: bool a6xx_irq_pending(struct adreno_device *adreno_dev); 410: 411: #ifdef CONFIG_QCOM_KGSL_CORESIGHT 412: void a6xx_coresight_init(struct adreno_device *device); 413: #else 414: static inline void a6xx_coresight_init(struct adreno_device *device) { } 415: #endif 416: 417: #endif --- FILE: \adreno_a6xx_gmu.c | HITS: 5 --- MATCH LINES: 1364, 1366, 1373, 1377 1352: ts3-ts2); 1353: dev_err(gmu_pdev_dev, 1354: "RPMH_POWER_STATE=%x SPTPRAC_PWR_CLK_STATUS=%x\n", reg, reg1); 1355: dev_err(gmu_pdev_dev, "CX_BUSY_STATUS=%x\n", reg2); 1356: dev_err(gmu_pdev_dev, 1357: "RBBM_INT_UNMASKED_STATUS=%x PWR_COL_KEEPALIVE=%x\n", 1358: reg3, reg4); 1359: dev_err(gmu_pdev_dev, "A6XX_GMU_AO_SPARE_CNTL=%x\n", reg5); 1360: 1361: if (adreno_is_a660(adreno_dev)) { 1362: u32 val; 1363: 1364: gmu_core_regread(device, A6XX_GMU_PWR_COL_PREEMPT_KEEPALIVE, &val); 1365: dev_err(gmu_pdev_dev, 1366: "PWR_COL_PREEMPT_KEEPALIVE=%x\n", val); 1367: } 1368: 1369: /* Access GX registers only when GX is ON */ 1370: if (is_on(reg1)) { 1371: kgsl_regread(device, A6XX_CP_STATUS_1, ®6); 1372: kgsl_regread(device, A6XX_CP_CP2GMU_STATUS, ®7); 1373: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, ®8); 1374: 1375: dev_err(gmu_pdev_dev, "A6XX_CP_STATUS_1=%x\n", reg6); 1376: dev_err(gmu_pdev_dev, 1377: "CP2GMU_STATUS=%x CONTEXT_SWITCH_CNTL=%x\n", 1378: reg7, reg8); 1379: } 1380: 1381: WARN_ON(1); 1382: gmu_core_fault_snapshot(device, GMU_FAULT_WAIT_FOR_LOWEST_IDLE); 1383: return -ETIMEDOUT; 1384: } 1385: 1386: /* Bitmask for GPU idle status check */ 1387: #define CXGXCPUBUSYIGNAHB BIT(30) 1388: int a6xx_gmu_wait_for_idle(struct adreno_device *adreno_dev) 1389: { 1390: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1391: unsigned int status2; 1392: uint64_t ts1; 1393: 1394: ts1 = a6xx_read_alwayson(adreno_dev); 1395: if (gmu_core_timed_poll_check(device, A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS, 1396: 0, GMU_START_TIMEOUT, CXGXCPUBUSYIGNAHB)) { 1397: gmu_core_regread(device, 1398: A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS2, &status2); 1399: dev_err(GMU_PDEV_DEV(device), 1400: "GMU not idling: status2=0x%x %llx %llx\n", 1401: status2, ts1, MATCH LINES: 3490 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 */ 3497: return a6xx_boot(adreno_dev); 3498: } 3499: 3500: int a6xx_gmu_hfi_probe(struct adreno_device *adreno_dev) 3501: { 3502: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 3503: struct a6xx_hfi *hfi = &gmu->hfi; 3504: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3505: 3506: /* Try with "hfi" irq first. Use Fallback legacy name "kgsl_hfi_irq" if not found. */ 3507: hfi->irq = kgsl_request_irq(GMU_PDEV(device), "hfi", "kgsl_hfi_irq", -EINVAL, 3508: a6xx_hfi_irq_handler, KGSL_DEVICE(adreno_dev)); 3509: 3510: return hfi->irq < 0 ? hfi->irq : 0; 3511: } 3512: 3513: int a6xx_gmu_add_to_minidump(struct adreno_device *adreno_dev) 3514: { --- FILE: \adreno_a6xx_hwsched.c | HITS: 5 --- MATCH LINES: 75, 78 63: kgsl_snapshot_add_section(device, 64: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 65: snapshot, adreno_snapshot_global, 66: entry->md); 67: 68: if (entry->desc.mem_kind == HFI_MEMKIND_CSW_SMMU_INFO) 69: kgsl_snapshot_add_section(device, 70: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 71: snapshot, adreno_snapshot_global, 72: entry->md); 73: 74: if (entry->desc.mem_kind == HFI_MEMKIND_CSW_PRIV_NON_SECURE) 75: adreno_hwsched_snapshot_preemption_records(device, snapshot, 76: entry->md); 77: 78: if (entry->desc.mem_kind == HFI_MEMKIND_PREEMPT_SCRATCH) 79: kgsl_snapshot_add_section(device, 80: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 81: snapshot, adreno_snapshot_global, 82: entry->md); 83: } 84: } 85: 86: static void a6xx_hwsched_gmu_suspend(struct adreno_device *adreno_dev, bool force) 87: { 88: a6xx_gmu_suspend(adreno_dev, force); 89: adreno_hwsched_reset_hfi_mem(adreno_dev); 90: } 91: 92: static int a6xx_hwsched_gmu_first_boot(struct adreno_device *adreno_dev) 93: { 94: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 95: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 96: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 97: int level, ret = 0; 98: 99: kgsl_pwrctrl_request_state(device, KGSL_STATE_AWARE); 100: 101: a6xx_gmu_aop_send_acd_state(gmu, adreno_dev->acd_enabled); 102: MATCH LINES: 537, 538 525: return ret; 526: } 527: 528: static int a6xx_hwsched_first_boot(struct adreno_device *adreno_dev) 529: { 530: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 531: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 532: int ret; 533: 534: if (test_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags)) 535: return a6xx_hwsched_boot(adreno_dev); 536: 537: if (adreno_preemption_feature_set(adreno_dev)) 538: set_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 539: 540: adreno_hwsched_start(adreno_dev); 541: 542: ret = a6xx_microcode_read(adreno_dev); 543: if (ret) 544: return ret; 545: 546: ret = a6xx_init(adreno_dev); 547: if (ret) 548: return ret; 549: 550: ret = a6xx_hwsched_gmu_init(adreno_dev); 551: if (ret) 552: return ret; 553: 554: kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE); 555: 556: ret = a6xx_hwsched_gmu_first_boot(adreno_dev); 557: if (ret) 558: return ret; 559: 560: ret = a6xx_hwsched_gpu_boot(adreno_dev); 561: if (ret) 562: return ret; MATCH LINES: 982 970: .first_open = a6xx_hwsched_first_open, 971: .last_close = a6xx_hwsched_power_off, 972: .active_count_get = a6xx_hwsched_active_count_get, 973: .touch_wakeup = a6xx_hwsched_touch_wakeup, 974: .pm_suspend = a6xx_hwsched_pm_suspend, 975: .pm_resume = a6xx_hwsched_pm_resume, 976: .gpu_clock_set = a6xx_hwsched_clock_set, 977: .gpu_bus_set = a6xx_hwsched_bus_set, 978: }; 979: 980: const struct adreno_hwsched_ops a6xx_hwsched_ops = { 981: .submit_drawobj = a6xx_hwsched_submit_drawobj, 982: .preempt_count = a6xx_hwsched_preempt_count_get, 983: }; 984: 985: int a6xx_hwsched_probe(struct platform_device *pdev, 986: u32 chipid, const struct adreno_gpu_core *gpucore) 987: { 988: struct adreno_device *adreno_dev; 989: struct kgsl_device *device; 990: struct a6xx_hwsched_device *a6xx_hwsched_dev; 991: int ret; 992: 993: a6xx_hwsched_dev = devm_kzalloc(&pdev->dev, sizeof(*a6xx_hwsched_dev), 994: GFP_KERNEL); 995: if (!a6xx_hwsched_dev) 996: return -ENOMEM; 997: 998: adreno_dev = &a6xx_hwsched_dev->a6xx_dev.adreno_dev; 999: 1000: adreno_dev->hwsched_enabled = true; 1001: 1002: adreno_dev->irq_mask = A6XX_HWSCHED_INT_MASK; 1003: 1004: ret = a6xx_probe_common(pdev, adreno_dev, chipid, gpucore); 1005: if (ret) 1006: return ret; --- FILE: \adreno_a6xx_hwsched_hfi.c | HITS: 22 --- MATCH LINES: 206, 210, 212, 213, 220 194: case GMU_CP_ILLEGAL_INST_ERROR: 195: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 196: break; 197: case GMU_CP_UCODE_ERROR: 198: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 199: break; 200: case GMU_CP_HW_FAULT_ERROR: 201: dev_crit_ratelimited(gmu_pdev_dev, 202: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 203: a6xx_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 204: KEY_CP_HW_FAULT)); 205: break; 206: case GMU_GPU_PREEMPT_TIMEOUT: { 207: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 208: 209: cur = a6xx_hwsched_lookup_key_value_legacy(adreno_dev, 210: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 211: next = a6xx_hwsched_lookup_key_value_legacy(adreno_dev, 212: PAYLOAD_PREEMPT_TIMEOUT, 213: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 214: cur_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_RPTR); 215: cur_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_WPTR); 216: next_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_RPTR); 217: next_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_WPTR); 218: 219: dev_crit_ratelimited(gmu_pdev_dev, 220: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 221: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 222: } 223: break; 224: case GMU_CP_GPC_ERROR: 225: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: GPC error\n"); 226: break; 227: default: 228: dev_crit_ratelimited(gmu_pdev_dev, "Unknown GPU fault: %u\n", 229: cmd->error); 230: break; 231: } 232: } 233: 234: /* Look up a particular key's value for a given type of payload */ 235: static u32 a6xx_hwsched_lookup_key_value(struct adreno_device *adreno_dev, 236: u32 type, u32 key) 237: { 238: struct hfi_context_bad_cmd *cmd = adreno_dev->hwsched.ctxt_bad; 239: u32 i = 0, payload_bytes; 240: void *start; 241: 242: if (!cmd->hdr) 243: return 0; 244: MATCH LINES: 303, 307, 309, 310, 317 291: case GMU_CP_ILLEGAL_INST_ERROR: 292: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 293: break; 294: case GMU_CP_UCODE_ERROR: 295: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 296: break; 297: case GMU_CP_HW_FAULT_ERROR: 298: dev_crit_ratelimited(gmu_pdev_dev, 299: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 300: a6xx_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 301: KEY_CP_HW_FAULT)); 302: break; 303: case GMU_GPU_PREEMPT_TIMEOUT: { 304: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 305: 306: cur = a6xx_hwsched_lookup_key_value(adreno_dev, 307: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 308: next = a6xx_hwsched_lookup_key_value(adreno_dev, 309: PAYLOAD_PREEMPT_TIMEOUT, 310: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 311: cur_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_RPTR); 312: cur_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_WPTR); 313: next_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_RPTR); 314: next_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_WPTR); 315: 316: dev_crit_ratelimited(gmu_pdev_dev, 317: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 318: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 319: } 320: break; 321: case GMU_CP_GPC_ERROR: 322: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: GPC error\n"); 323: break; 324: default: 325: dev_crit_ratelimited(gmu_pdev_dev, "Unknown GPU fault: %u\n", 326: cmd->error); 327: break; 328: } 329: } 330: 331: static void process_ctx_bad(struct adreno_device *adreno_dev) 332: { 333: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 334: 335: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2) 336: log_gpu_fault_legacy(adreno_dev); 337: else 338: log_gpu_fault(adreno_dev); 339: 340: adreno_scheduler_fault(adreno_dev, ADRENO_HARD_FAULT); 341: } MATCH LINES: 832, 837, 841, 845, 846, 847, 849, 855, 859 820: } 821: 822: static void enable_async_hfi(struct adreno_device *adreno_dev) 823: { 824: struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev); 825: 826: hfi->irq_mask |= HFI_IRQ_MSGQ_MASK; 827: 828: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), A6XX_GMU_GMU2HOST_INTR_MASK, 829: (u32)~hfi->irq_mask); 830: } 831: 832: static int enable_preemption(struct adreno_device *adreno_dev) 833: { 834: u32 data; 835: int ret; 836: 837: if (!adreno_is_preemption_enabled(adreno_dev)) 838: return 0; 839: 840: /* 841: * Bits [0:1] contains the preemption level 842: * Bit 2 is to enable/disable gmem save/restore 843: * Bit 3 is to enable/disable skipsaverestore 844: */ 845: data = FIELD_PREP(GENMASK(1, 0), adreno_dev->preempt.preempt_level) | 846: FIELD_PREP(BIT(2), adreno_dev->preempt.usesgmem) | 847: FIELD_PREP(BIT(3), adreno_dev->preempt.skipsaverestore); 848: 849: ret = a6xx_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_PREEMPTION, 1, 850: data); 851: if (ret) 852: return ret; 853: 854: /* 855: * Bits[3:0] contain the preemption timeout enable bit per ringbuffer 856: * Bits[31:4] contain the timeout in ms 857: */ 858: return a6xx_hfi_send_set_value(adreno_dev, HFI_VALUE_BIN_TIME, 1, 859: FIELD_PREP(GENMASK(31, 4), ADRENO_PREEMPT_TIMEOUT) | 860: FIELD_PREP(GENMASK(3, 0), 0xf)); 861: } 862: 863: static int enable_gmu_stats(struct adreno_device *adreno_dev) 864: { 865: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 866: u32 data; 867: 868: if (!gmu->stats_enable) 869: return 0; 870: 871: /* 872: * Bits [23:0] contains the countables mask 873: * Bits [31:24] is the sampling interval 874: */ 875: data = FIELD_PREP(GENMASK(23, 0), gmu->stats_mask) | 876: FIELD_PREP(GENMASK(31, 24), gmu->stats_interval); 877: 878: return a6xx_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_GMU_STATS, 1, data); 879: } 880: 881: static int a6xx_hfi_send_perfcounter_feature_ctrl(struct adreno_device *adreno_dev) 882: { 883: /* MATCH LINES: 969 957: 958: if (gmu->log_stream_enable) 959: a6xx_hfi_send_set_value(adreno_dev, 960: HFI_VALUE_LOG_STREAM_ENABLE, 0, 1); 961: 962: if (gmu->log_group_mask) 963: a6xx_hfi_send_set_value(adreno_dev, HFI_VALUE_LOG_GROUP, 0, gmu->log_group_mask); 964: 965: ret = a6xx_hfi_send_core_fw_start(adreno_dev); 966: if (ret) 967: goto err; 968: 969: ret = enable_preemption(adreno_dev); 970: if (ret) 971: goto err; 972: 973: ret = send_start_msg(adreno_dev); 974: if (ret) 975: goto err; 976: 977: enable_async_hfi(adreno_dev); 978: 979: set_bit(GMU_PRIV_HFI_STARTED, &gmu->flags); 980: 981: ret = kgsl_pwrctrl_setup_default_votes(device); 982: 983: err: 984: if (ret) 985: a6xx_hwsched_hfi_stop(adreno_dev); 986: 987: return ret; 988: } 989: 990: static int submit_raw_cmds(struct adreno_device *adreno_dev, void *cmds, u32 size_bytes, 991: const char *str) 992: { 993: int ret; MATCH LINES: 1746, 1765 1734: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), drawctxt->timestamp); 1735: 1736: kgsl_sharedmem_writel(device->memstore, 1737: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), drawctxt->timestamp); 1738: 1739: adreno_profile_process_results(adreno_dev); 1740: context->gmu_registered = false; 1741: 1742: out: 1743: kgsl_mutex_unlock(&device->mutex); 1744: } 1745: 1746: u32 a6xx_hwsched_preempt_count_get(struct adreno_device *adreno_dev) 1747: { 1748: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1749: struct hfi_get_value_cmd cmd; 1750: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 1751: struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev); 1752: struct pending_cmd pending_ack; 1753: int rc; 1754: u32 seqnum; 1755: 1756: if (device->state != KGSL_STATE_ACTIVE) 1757: return 0; 1758: 1759: rc = CMD_MSG_HDR(cmd, H2F_MSG_GET_VALUE); 1760: if (rc) 1761: return 0; 1762: 1763: seqnum = atomic_inc_return(&gmu->hfi.seqnum); 1764: cmd.hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd.hdr, seqnum, sizeof(cmd) >> 2); 1765: cmd.type = HFI_VALUE_PREEMPT_COUNT; 1766: cmd.subtype = 0; 1767: 1768: add_waiter(hfi, cmd.hdr, &pending_ack); 1769: 1770: rc = a6xx_hfi_cmdq_write(adreno_dev, (u32 *)&cmd, sizeof(cmd)); 1771: if (rc) 1772: goto done; 1773: 1774: rc = adreno_hwsched_wait_ack_completion(adreno_dev, 1775: GMU_PDEV_DEV(device), &pending_ack, a6xx_hwsched_process_msgq); 1776: if (rc) 1777: goto done; 1778: 1779: rc = check_ack_failure(adreno_dev, &pending_ack); 1780: 1781: done: 1782: del_waiter(hfi, &pending_ack); 1783: 1784: return rc ? 0 : pending_ack.results[2]; 1785: } --- FILE: \adreno_a6xx_hwsched_hfi.h | HITS: 4 --- MATCH LINES: 140, 144, 146, 148 128: * a6xx_hwsched_context_detach - Unregister a context with GMU 129: * @drawctxt: Pointer to the adreno context 130: * 131: * This function sends context unregister HFI and waits for the ack 132: * to ensure all submissions from this context have retired 133: */ 134: void a6xx_hwsched_context_detach(struct adreno_context *drawctxt); 135: 136: /* Helper function to get to a6xx hwsched hfi device from adreno device */ 137: struct a6xx_hwsched_hfi *to_a6xx_hwsched_hfi(struct adreno_device *adreno_dev); 138: 139: /** 140: * a6xx_hwsched_preempt_count_get - Get preemption count from GMU 141: * @adreno_dev: Pointer to adreno device 142: * 143: * This function sends a GET_VALUE HFI packet to get the number of 144: * preemptions completed since last SLUMBER exit. 145: * 146: * Return: Preemption count 147: */ 148: u32 a6xx_hwsched_preempt_count_get(struct adreno_device *adreno_dev); 149: #endif --- FILE: \adreno_a6xx_perfcounter.c | HITS: 2 --- MATCH LINES: 824, 825 812: A6XX_GMU_CX_GMU_PERF_COUNTER_5_H, 813: A6XX_GMU_CX_GMU_PERF_COUNTER_SELECT_1), 814: }; 815: 816: static struct adreno_perfcount_register a6xx_perfcounters_alwayson[] = { 817: { KGSL_PERFCOUNTER_NOT_USED, 0, 0, A6XX_CP_ALWAYS_ON_COUNTER_LO, 818: A6XX_CP_ALWAYS_ON_COUNTER_HI, -1 }, 819: }; 820: 821: /* 822: * ADRENO_PERFCOUNTER_GROUP_RESTORE flag is enabled by default 823: * because most of the perfcounter groups need to be restored 824: * as part of preemption and IFPC. Perfcounter groups that are 825: * not restored as part of preemption and IFPC should be defined 826: * using A6XX_PERFCOUNTER_GROUP_FLAGS macro 827: */ 828: #define A6XX_PERFCOUNTER_GROUP(offset, name, enable, read, load) \ 829: ADRENO_PERFCOUNTER_GROUP_FLAGS(a6xx, offset, name, \ 830: ADRENO_PERFCOUNTER_GROUP_RESTORE, enable, read, load) 831: 832: #define A6XX_PERFCOUNTER_GROUP_FLAGS(offset, name, flags, enable, read, load) \ 833: ADRENO_PERFCOUNTER_GROUP_FLAGS(a6xx, offset, name, flags, enable, \ 834: read, load) 835: 836: #define A6XX_REGULAR_PERFCOUNTER_GROUP(offset, name) \ 837: A6XX_PERFCOUNTER_GROUP(offset, name, \ 838: a6xx_counter_enable, a6xx_counter_read, a6xx_counter_load) 839: 840: static const struct adreno_perfcount_group a630_perfcounter_groups 841: [KGSL_PERFCOUNTER_GROUP_MAX] = { 842: A6XX_REGULAR_PERFCOUNTER_GROUP(CP, cp), 843: A6XX_PERFCOUNTER_GROUP_FLAGS(RBBM, rbbm, 0, 844: a6xx_counter_enable, a6xx_counter_read, a6xx_counter_load), 845: A6XX_REGULAR_PERFCOUNTER_GROUP(PC, pc), 846: A6XX_REGULAR_PERFCOUNTER_GROUP(VFD, vfd), 847: A6XX_PERFCOUNTER_GROUP(HLSQ, hlsq, a6xx_counter_inline_enable, 848: a6xx_counter_read, a6xx_counter_load), 849: A6XX_REGULAR_PERFCOUNTER_GROUP(VPC, vpc), --- FILE: \adreno_a6xx_preempt.c | HITS: 158 --- MATCH LINES: 13, 14, 16, 27, 57, 80, 88, 95, 108, 112, 121, 126, 129, 130, 131, 134, 139, 141, 143, 158, 159, 162, 168, 172, 175, 176, 184, 192, 195, 197, 198, 199, 200, 206, 207, 223, 225, 234, 242, 245, 246, 249, 269, 281, 289, 290, 292, 298, 300, 303, 307, 312, 326, 327, 337, 344, 345, 351, 352, 357, 358, 364, 370, 377, 378, 379, 381, 383, 384, 387, 388, 391, 394, 396, 397, 400, 414, 420, 425, 426, 429, 433, 442, 447, 450, 455, 457, 459, 466, 473, 475, 478, 482, 487, 488, 490, 495, 504, 513, 515, 518, 519, 522, 524, 528, 534, 535, 539, 546, 548, 556, 561, 565, 574, 583, 590, 594, 597, 599, 601, 605, 607, 609, 612, 617, 618, 619, 620, 627, 633, 635, 636, 637, 638, 639, 640, 642, 643, 646, 651, 655, 659, 670, 672, 677, 679, 691, 696, 701, 706, 710, 712, 714, 719, 720, 724, 753, 756 1: // SPDX-License-Identifier: GPL-2.0-only 2: /* 3: * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include "adreno.h" 8: #include "adreno_a6xx.h" 9: #include "adreno_pm4types.h" 10: #include "adreno_trace.h" 11: #include "kgsl_util.h" 12: 13: #define PREEMPT_RECORD(_field) \ 14: offsetof(struct a6xx_cp_preemption_record, _field) 15: 16: #define PREEMPT_SMMU_RECORD(_field) \ 17: offsetof(struct a6xx_cp_smmu_info, _field) 18: 19: static void _update_wptr(struct adreno_device *adreno_dev, bool reset_timer, 20: bool atomic) 21: { 22: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 23: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 24: unsigned long flags; 25: int ret = 0; 26: 27: spin_lock_irqsave(&rb->preempt_lock, flags); 28: 29: if (!atomic) { 30: /* 31: * We might have skipped updating the wptr in case we are in 32: * dispatcher context. Do it now. 33: */ 34: if (rb->skip_inline_wptr) { 35: 36: ret = a6xx_fenced_write(adreno_dev, 37: A6XX_CP_RB_WPTR, rb->wptr, 38: FENCE_STATUS_WRITEDROPPED0_MASK); 39: 40: reset_timer = true; 41: rb->skip_inline_wptr = false; 42: } 43: } else { 44: unsigned int wptr; 45: 46: kgsl_regread(device, A6XX_CP_RB_WPTR, &wptr); 47: if (wptr != rb->wptr) { 48: kgsl_regwrite(device, A6XX_CP_RB_WPTR, rb->wptr); 49: reset_timer = true; 50: } 51: } 52: 53: if (reset_timer) 54: rb->dispatch_q.expires = jiffies + 55: msecs_to_jiffies(adreno_drawobj_timeout); 56: 57: spin_unlock_irqrestore(&rb->preempt_lock, flags); 58: 59: if (!atomic) { 60: /* If WPTR update fails, set the fault and trigger recovery */ 61: if (ret) { 62: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 63: adreno_scheduler_fault(adreno_dev, 64: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 65: } 66: } 67: } 68: 69: static void _power_collapse_set(struct adreno_device *adreno_dev, bool val) 70: { 71: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 72: 73: if (!gmu_core_isenabled(device)) 74: return; 75: 76: if (val) { 77: if (adreno_is_a660(adreno_dev) || 78: adreno_is_a663(adreno_dev)) 79: gmu_core_regwrite(device, 80: A6XX_GMU_PWR_COL_PREEMPT_KEEPALIVE, 0x1); 81: else 82: gmu_core_regrmw(device, 83: A6XX_GMU_AO_SPARE_CNTL, 0x0, 0x2); 84: } else { 85: if (adreno_is_a660(adreno_dev) || 86: adreno_is_a663(adreno_dev)) 87: gmu_core_regwrite(device, 88: A6XX_GMU_PWR_COL_PREEMPT_KEEPALIVE, 0x0); 89: else 90: gmu_core_regrmw(device, 91: A6XX_GMU_AO_SPARE_CNTL, 0x2, 0x0); 92: } 93: } 94: 95: static void _a6xx_preemption_done(struct adreno_device *adreno_dev) 96: { 97: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 98: unsigned int status; 99: 100: /* 101: * In the very unlikely case that the power is off, do nothing - the 102: * state will be reset on power up and everybody will be happy 103: */ 104: 105: if (!kgsl_state_is_awake(device)) 106: return; 107: 108: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, &status); 109: 110: if (status & 0x1) { 111: dev_err(device->dev, 112: "Preemption not complete: status=%X cur=%d R/W=%X/%X next=%d R/W=%X/%X\n", 113: status, adreno_dev->cur_rb->id, 114: adreno_get_rptr(adreno_dev->cur_rb), 115: adreno_dev->cur_rb->wptr, 116: adreno_dev->next_rb->id, 117: adreno_get_rptr(adreno_dev->next_rb), 118: adreno_dev->next_rb->wptr); 119: 120: /* Set a fault and restart */ 121: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 122: 123: return; 124: } 125: 126: adreno_dev->preempt.count++; 127: 128: /* 129: * In normal scenarios, preemption keep alive bit is cleared during 130: * CP interrupt callback. However, if preemption is successful 131: * immediately after preemption timer expires or there is a preemption 132: * interrupt with non-zero status, the state is transitioned to complete 133: * state. Once dispatcher is scheduled, it calls this function. 134: * We can now safely clear the preemption keepalive bit, allowing 135: * power collapse to resume its regular activity. 136: */ 137: _power_collapse_set(adreno_dev, false); 138: 139: kgsl_delete_timer_sync(&adreno_dev->preempt.timer); 140: 141: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 142: 143: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 144: status, 0); 145: 146: /* Clean up all the bits */ 147: adreno_dev->prev_rb = adreno_dev->cur_rb; 148: adreno_dev->cur_rb = adreno_dev->next_rb; 149: adreno_dev->next_rb = NULL; 150: 151: /* Update the wptr for the new command queue */ 152: _update_wptr(adreno_dev, true, false); 153: 154: /* Update the dispatcher timer for the new command queue */ 155: mod_timer(&adreno_dev->dispatcher.timer, 156: adreno_dev->cur_rb->dispatch_q.expires); 157: 158: /* Clear the preempt state */ 159: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 160: } 161: 162: static void _a6xx_preemption_fault(struct adreno_device *adreno_dev) 163: { 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: } 211: 212: /* Find the highest priority active ringbuffer */ 213: static struct adreno_ringbuffer *a6xx_next_ringbuffer( 214: struct adreno_device *adreno_dev) 215: { 216: struct adreno_ringbuffer *rb; 217: unsigned long flags; 218: unsigned int i; 219: 220: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 221: bool empty; 222: 223: spin_lock_irqsave(&rb->preempt_lock, flags); 224: empty = adreno_rb_empty(rb); 225: spin_unlock_irqrestore(&rb->preempt_lock, flags); 226: 227: if (!empty) 228: return rb; 229: } 230: 231: return NULL; 232: } 233: 234: void a6xx_preemption_trigger(struct adreno_device *adreno_dev, bool atomic) 235: { 236: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 237: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 238: struct adreno_ringbuffer *next; 239: uint64_t ttbr0, gpuaddr; 240: unsigned int contextidr, cntl; 241: unsigned long flags; 242: struct adreno_preemption *preempt = &adreno_dev->preempt; 243: 244: /* Put ourselves into a possible trigger state */ 245: if (!adreno_move_preempt_state(adreno_dev, 246: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START)) 247: return; 248: 249: /* Get the next ringbuffer to preempt in */ 250: next = a6xx_next_ringbuffer(adreno_dev); 251: 252: /* 253: * Nothing to do if every ringbuffer is empty or if the current 254: * ringbuffer is the only active one 255: */ 256: if (next == NULL || next == adreno_dev->cur_rb) { 257: /* 258: * Update any critical things that might have been skipped while 259: * we were looking for a new ringbuffer 260: */ 261: 262: if (next != NULL) { 263: _update_wptr(adreno_dev, false, atomic); 264: 265: mod_timer(&adreno_dev->dispatcher.timer, 266: adreno_dev->cur_rb->dispatch_q.expires); 267: } 268: 269: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 270: return; 271: } 272: 273: /* Turn off the dispatcher timer */ 274: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 275: 276: /* 277: * This is the most critical section - we need to take care not to race 278: * until we have programmed the CP for the switch 279: */ 280: 281: spin_lock_irqsave(&next->preempt_lock, flags); 282: 283: /* Get the pagetable from the pagetable info. */ 284: kgsl_sharedmem_readq(device->scratch, &ttbr0, 285: SCRATCH_RB_OFFSET(next->id, ttbr0)); 286: kgsl_sharedmem_readl(device->scratch, &contextidr, 287: SCRATCH_RB_OFFSET(next->id, contextidr)); 288: 289: kgsl_sharedmem_writel(next->preemption_desc, 290: PREEMPT_RECORD(wptr), next->wptr); 291: 292: spin_unlock_irqrestore(&next->preempt_lock, flags); 293: 294: /* And write it to the smmu info */ 295: 296: if (kgsl_mmu_is_perprocess(&device->mmu)) { 297: kgsl_sharedmem_writeq(iommu->smmu_info, 298: PREEMPT_SMMU_RECORD(ttbr0), ttbr0); 299: kgsl_sharedmem_writel(iommu->smmu_info, 300: PREEMPT_SMMU_RECORD(context_idr), contextidr); 301: } 302: 303: kgsl_sharedmem_readq(preempt->scratch, &gpuaddr, 304: next->id * sizeof(u64)); 305: 306: /* 307: * Set a keepalive bit before the first preemption register write. 308: * This is required since while each individual write to the context 309: * switch registers will wake the GPU from collapse, it will not in 310: * itself cause GPU activity. Thus, the GPU could technically be 311: * re-collapsed between subsequent register writes leading to a 312: * prolonged preemption sequence. The keepalive bit prevents any 313: * further power collapse while it is set. 314: * It is more efficient to use a keepalive+wake-on-fence approach here 315: * rather than an OOB. Both keepalive and the fence are effectively 316: * free when the GPU is already powered on, whereas an OOB requires an 317: * unconditional handshake with the GMU. 318: */ 319: _power_collapse_set(adreno_dev, true); 320: 321: /* 322: * Fenced writes on this path will make sure the GPU is woken up 323: * in case it was power collapsed by the GMU. 324: */ 325: if (a6xx_fenced_write(adreno_dev, 326: A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO, 327: lower_32_bits(next->preemption_desc->gpuaddr), 328: FENCE_STATUS_WRITEDROPPED1_MASK)) 329: goto err; 330: 331: /* 332: * Above fence writes will make sure GMU comes out of 333: * IFPC state if its was in IFPC state but it doesn't 334: * guarantee that GMU FW actually moved to ACTIVE state 335: * i.e. wake-up from IFPC is complete. 336: * Wait for GMU to move to ACTIVE state before triggering 337: * preemption. This is require to make sure CP doesn't 338: * interrupt GMU during wake-up from IFPC. 339: */ 340: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 341: goto err; 342: 343: if (a6xx_fenced_write(adreno_dev, 344: A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI, 345: upper_32_bits(next->preemption_desc->gpuaddr), 346: FENCE_STATUS_WRITEDROPPED1_MASK)) 347: goto err; 348: 349: if (kgsl_mmu_is_secured(&device->mmu)) { 350: if (a6xx_fenced_write(adreno_dev, 351: A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO, 352: lower_32_bits(next->secure_preemption_desc->gpuaddr), 353: FENCE_STATUS_WRITEDROPPED1_MASK)) 354: goto err; 355: 356: if (a6xx_fenced_write(adreno_dev, 357: A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI, 358: upper_32_bits(next->secure_preemption_desc->gpuaddr), 359: FENCE_STATUS_WRITEDROPPED1_MASK)) 360: goto err; 361: } 362: 363: if (a6xx_fenced_write(adreno_dev, 364: A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO, 365: lower_32_bits(gpuaddr), 366: FENCE_STATUS_WRITEDROPPED1_MASK)) 367: goto err; 368: 369: if (a6xx_fenced_write(adreno_dev, 370: A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI, 371: upper_32_bits(gpuaddr), 372: FENCE_STATUS_WRITEDROPPED1_MASK)) 373: goto err; 374: 375: adreno_dev->next_rb = next; 376: 377: /* Start the timer to detect a stuck preemption */ 378: mod_timer(&adreno_dev->preempt.timer, 379: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 380: 381: cntl = (preempt->preempt_level << 6) | 0x01; 382: 383: /* Skip save/restore during L1 preemption */ 384: if (preempt->skipsaverestore) 385: cntl |= (1 << 9); 386: 387: /* Enable GMEM save/restore across preemption */ 388: if (preempt->usesgmem) 389: cntl |= (1 << 8); 390: 391: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 392: cntl, 0); 393: 394: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 395: 396: /* Trigger the preemption */ 397: if (a6xx_fenced_write(adreno_dev, A6XX_CP_CONTEXT_SWITCH_CNTL, cntl, 398: FENCE_STATUS_WRITEDROPPED1_MASK)) { 399: adreno_dev->next_rb = NULL; 400: kgsl_delete_timer(&adreno_dev->preempt.timer); 401: goto err; 402: } 403: 404: return; 405: err: 406: /* If fenced write fails, take inline snapshot and trigger recovery */ 407: if (!atomic) { 408: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 409: adreno_scheduler_fault(adreno_dev, 410: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 411: } else { 412: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 413: } 414: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 415: /* Clear the keep alive */ 416: _power_collapse_set(adreno_dev, false); 417: 418: } 419: 420: void a6xx_preemption_callback(struct adreno_device *adreno_dev, int bit) 421: { 422: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 423: unsigned int status; 424: 425: if (!adreno_move_preempt_state(adreno_dev, 426: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 427: return; 428: 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); 476: } 477: 478: void a6xx_preemption_schedule(struct adreno_device *adreno_dev) 479: { 480: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 481: 482: if (!adreno_is_preemption_enabled(adreno_dev)) 483: return; 484: 485: kgsl_mutex_lock(&device->mutex); 486: 487: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE)) 488: _a6xx_preemption_done(adreno_dev); 489: 490: a6xx_preemption_trigger(adreno_dev, false); 491: 492: kgsl_mutex_unlock(&device->mutex); 493: } 494: 495: u32 a6xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 496: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 497: u32 *cmds) 498: { 499: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 500: u32 count = kgsl_mmu_is_secured(&device->mmu) ? 12 : 9; 501: unsigned int *cmds_orig = cmds; 502: uint64_t gpuaddr = 0; 503: 504: if (!adreno_is_preemption_enabled(adreno_dev)) 505: return 0; 506: 507: if (drawctxt && drawctxt->base.user_ctxt_record) 508: gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 509: 510: if (gpuaddr) 511: count += 3; 512: 513: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, count); 514: /* NULL SMMU_INFO buffer - we track in KMD */ 515: *cmds++ = SET_PSEUDO_SMMU_INFO; 516: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 517: 518: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 519: cmds += cp_gpuaddr(adreno_dev, cmds, rb->preemption_desc->gpuaddr); 520: 521: if (kgsl_mmu_is_secured(&device->mmu)) { 522: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 523: cmds += cp_gpuaddr(adreno_dev, cmds, 524: rb->secure_preemption_desc->gpuaddr); 525: } 526: 527: if (gpuaddr) { 528: *cmds++ = SET_PSEUDO_NON_PRIV_SAVE_ADDR; 529: cmds += cp_gpuaddr(adreno_dev, cmds, gpuaddr); 530: } 531: 532: /* 533: * There is no need to specify this address when we are about to 534: * trigger preemption. This is because CP internally stores this 535: * address specified here in the CP_SET_PSEUDO_REGISTER payload to 536: * the context record and thus knows from where to restore 537: * the saved perfcounters for the new ringbuffer. 538: */ 539: *cmds++ = SET_PSEUDO_COUNTER; 540: cmds += cp_gpuaddr(adreno_dev, cmds, 541: rb->perfcounter_save_restore_desc->gpuaddr); 542: 543: if (!drawctxt) 544: goto done; 545: 546: cmds += adreno_prepare_preib_preempt_scratch(adreno_dev, drawctxt, cmds); 547: 548: /* Add a KMD post amble to clear the perf counters during preemption */ 549: if (!adreno_dev->perfcounter) 550: cmds += adreno_prepare_preib_postamble_scratch(adreno_dev, cmds); 551: 552: done: 553: return (u32) (cmds - cmds_orig); 554: } 555: 556: u32 a6xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 557: u32 *cmds) 558: { 559: u32 index = 0; 560: 561: if (!adreno_is_preemption_enabled(adreno_dev)) 562: return 0; 563: 564: if (adreno_dev->cur_rb) { 565: u64 dest = PREEMPT_SCRATCH_ADDR(adreno_dev, adreno_dev->cur_rb->id); 566: 567: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 4); 568: cmds[index++] = lower_32_bits(dest); 569: cmds[index++] = upper_32_bits(dest); 570: cmds[index++] = 0; 571: cmds[index++] = 0; 572: } 573: 574: cmds[index++] = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 575: cmds[index++] = 0; 576: cmds[index++] = 0; 577: cmds[index++] = 1; 578: cmds[index++] = 0; 579: 580: return index; 581: } 582: 583: void a6xx_preemption_start(struct adreno_device *adreno_dev) 584: { 585: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 586: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 587: struct adreno_ringbuffer *rb; 588: unsigned int i; 589: 590: if (!adreno_is_preemption_enabled(adreno_dev)) 591: return; 592: 593: /* Force the state to be clear */ 594: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 595: 596: if (kgsl_mmu_is_perprocess(&device->mmu)) { 597: /* smmu_info is allocated and mapped in a6xx_preemption_iommu_init */ 598: kgsl_sharedmem_writel(iommu->smmu_info, 599: PREEMPT_SMMU_RECORD(magic), A6XX_CP_SMMU_INFO_MAGIC_REF); 600: kgsl_sharedmem_writeq(iommu->smmu_info, 601: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 602: 603: /* The CP doesn't use the asid record, so poison it */ 604: kgsl_sharedmem_writel(iommu->smmu_info, 605: PREEMPT_SMMU_RECORD(asid), 0xDECAFBAD); 606: kgsl_sharedmem_writel(iommu->smmu_info, 607: PREEMPT_SMMU_RECORD(context_idr), 0); 608: 609: kgsl_regwrite(device, A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 610: lower_32_bits(iommu->smmu_info->gpuaddr)); 611: 612: kgsl_regwrite(device, A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 613: upper_32_bits(iommu->smmu_info->gpuaddr)); 614: } 615: 616: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 617: kgsl_sharedmem_writel(rb->preemption_desc, 618: PREEMPT_RECORD(rptr), 0); 619: kgsl_sharedmem_writel(rb->preemption_desc, 620: PREEMPT_RECORD(wptr), 0); 621: 622: adreno_ringbuffer_set_pagetable(device, rb, 623: device->mmu.defaultpagetable); 624: } 625: } 626: 627: static void reset_rb_preempt_record(struct adreno_device *adreno_dev, 628: struct adreno_ringbuffer *rb) 629: { 630: u32 cp_rb_cntl = A6XX_CP_RB_CNTL_DEFAULT | 631: (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? 0 : (1 << 27)); 632: 633: memset(rb->preemption_desc->hostptr, 0x0, rb->preemption_desc->size); 634: 635: kgsl_sharedmem_writel(rb->preemption_desc, 636: PREEMPT_RECORD(magic), A6XX_CP_CTXRECORD_MAGIC_REF); 637: kgsl_sharedmem_writel(rb->preemption_desc, 638: PREEMPT_RECORD(cntl), cp_rb_cntl); 639: kgsl_sharedmem_writeq(rb->preemption_desc, 640: PREEMPT_RECORD(rptr_addr), SCRATCH_RB_GPU_ADDR( 641: KGSL_DEVICE(adreno_dev), rb->id, rptr)); 642: kgsl_sharedmem_writeq(rb->preemption_desc, 643: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 644: } 645: 646: void a6xx_reset_preempt_records(struct adreno_device *adreno_dev) 647: { 648: int i; 649: struct adreno_ringbuffer *rb; 650: 651: if (!adreno_is_preemption_enabled(adreno_dev)) 652: return; 653: 654: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 655: reset_rb_preempt_record(adreno_dev, rb); 656: } 657: } 658: 659: static int a6xx_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 660: struct adreno_ringbuffer *rb) 661: { 662: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 663: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev); 664: u64 ctxt_record_size = A6XX_CP_CTXRECORD_SIZE_IN_BYTES; 665: int ret; 666: 667: if (a6xx_core->ctxt_record_size) 668: ctxt_record_size = a6xx_core->ctxt_record_size; 669: 670: ret = adreno_allocate_global(device, &rb->preemption_desc, 671: ctxt_record_size, SZ_16K, 0, KGSL_MEMDESC_PRIVILEGED, 672: "preemption_desc"); 673: if (ret) 674: return ret; 675: 676: if (kgsl_mmu_is_secured(&device->mmu)) { 677: ret = adreno_allocate_global(device, &rb->secure_preemption_desc, 678: ctxt_record_size, 0, KGSL_MEMFLAGS_SECURE, 679: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 680: if (ret) 681: return ret; 682: } 683: 684: ret = adreno_allocate_global(device, &rb->perfcounter_save_restore_desc, 685: A6XX_CP_PERFCOUNTER_SAVE_RESTORE_SIZE, 0, 0, 686: KGSL_MEMDESC_PRIVILEGED, 687: "perfcounter_save_restore_desc"); 688: if (ret) 689: return ret; 690: 691: reset_rb_preempt_record(adreno_dev, rb); 692: 693: return 0; 694: } 695: 696: int a6xx_preemption_init(struct adreno_device *adreno_dev) 697: { 698: u32 flags = ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? KGSL_MEMDESC_PRIVILEGED : 0; 699: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 700: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 701: struct adreno_preemption *preempt = &adreno_dev->preempt; 702: struct adreno_ringbuffer *rb; 703: int ret; 704: unsigned int i; 705: 706: /* We are dependent on IOMMU to make preemption go on the CP side */ 707: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) 708: return -ENODEV; 709: 710: INIT_WORK(&preempt->work, _a6xx_preemption_worker); 711: 712: /* Allocate mem for storing preemption switch record */ 713: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 714: ret = a6xx_preemption_ringbuffer_init(adreno_dev, rb); 715: if (ret) 716: return ret; 717: } 718: 719: ret = adreno_allocate_global(device, &preempt->scratch, 720: PAGE_SIZE, 0, 0, flags, "preempt_scratch"); 721: if (ret) 722: return ret; 723: 724: /* Allocate mem for storing preemption smmu record */ 725: if (kgsl_mmu_is_perprocess(&device->mmu)) { 726: ret = adreno_allocate_global(device, &iommu->smmu_info, PAGE_SIZE, 0, 727: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 728: "smmu_info"); 729: if (ret) 730: return ret; 731: } 732: 733: /* 734: * First 28 dwords of the device scratch buffer are used to store shadow rb data. 735: * Insert PM4 packets in device scratch buffer to clear perfcounters. This should 736: * be in *device->scratch* so that userspace cannot access it. 737: */ 738: if (!adreno_dev->perfcounter) { 739: u32 *postamble = device->scratch->hostptr + SCRATCH_POSTAMBLE_OFFSET; 740: u32 count = 0; 741: 742: postamble[count++] = cp_type4_packet(A6XX_RBBM_PERFCTR_SRAM_INIT_CMD, 1); 743: postamble[count++] = 0x1; 744: 745: postamble[count++] = cp_type7_packet(CP_WAIT_REG_MEM, 6); 746: postamble[count++] = 0x3; 747: postamble[count++] = A6XX_RBBM_PERFCTR_SRAM_INIT_STATUS; 748: postamble[count++] = 0x0; 749: postamble[count++] = 0x1; 750: postamble[count++] = 0x1; 751: postamble[count++] = 0x0; 752: 753: preempt->postamble_len = count; 754: } 755: 756: set_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 757: return 0; 758: } --- FILE: \adreno_a6xx_rgmu.c | HITS: 3 --- MATCH LINES: 328, 345 316: return 0; 317: 318: ts3 = a6xx_read_alwayson(adreno_dev); 319: 320: /* Collect abort data to help with debugging */ 321: gmu_core_regread(device, A6XX_RGMU_CX_PCC_DEBUG, ®[1]); 322: gmu_core_regread(device, A6XX_RGMU_CX_PCC_STATUS, ®[2]); 323: gmu_core_regread(device, A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS, ®[3]); 324: kgsl_regread(device, A6XX_CP_STATUS_1, ®[4]); 325: gmu_core_regread(device, A6XX_GMU_RBBM_INT_UNMASKED_STATUS, ®[5]); 326: gmu_core_regread(device, A6XX_GMU_GMU_PWR_COL_KEEPALIVE, ®[6]); 327: kgsl_regread(device, A6XX_CP_CP2GMU_STATUS, ®[7]); 328: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, ®[8]); 329: gmu_core_regread(device, A6XX_GMU_AO_SPARE_CNTL, ®[9]); 330: 331: dev_err(&rgmu->pdev->dev, 332: "----------------------[ RGMU error ]----------------------\n"); 333: dev_err(&rgmu->pdev->dev, "Timeout waiting for lowest idle level\n"); 334: dev_err(&rgmu->pdev->dev, 335: "Timestamps: %llx %llx %llx\n", ts1, ts2, ts3); 336: dev_err(&rgmu->pdev->dev, 337: "SPTPRAC_PWR_CLK_STATUS=%x PCC_DEBUG=%x PCC_STATUS=%x\n", 338: reg[0], reg[1], reg[2]); 339: dev_err(&rgmu->pdev->dev, 340: "CX_BUSY_STATUS=%x CP_STATUS_1=%x\n", reg[3], reg[4]); 341: dev_err(&rgmu->pdev->dev, 342: "RBBM_INT_UNMASKED_STATUS=%x PWR_COL_KEEPALIVE=%x\n", 343: reg[5], reg[6]); 344: dev_err(&rgmu->pdev->dev, 345: "CP2GMU_STATUS=%x CONTEXT_SWITCH_CNTL=%x AO_SPARE_CNTL=%x\n", 346: reg[7], reg[8], reg[9]); 347: 348: WARN_ON(1); 349: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 350: return -ETIMEDOUT; 351: } 352: 353: /* 354: * The lowest 16 bits of this value are the number of XO clock cycles 355: * for main hysteresis. This is the first hysteresis. Here we set it 356: * to 0x1680 cycles, or 300 us. The highest 16 bits of this value are 357: * the number of XO clock cycles for short hysteresis. This happens 358: * after main hysteresis. Here we set it to 0xA cycles, or 0.5 us. 359: */ 360: #define A6X_RGMU_LONG_IFPC_HYST FIELD_PREP(GENMASK(15, 0), 0x1680) 361: #define A6X_RGMU_SHORT_IFPC_HYST FIELD_PREP(GENMASK(31, 16), 0xA) 362: 363: /* Minimum IFPC timer (200usec) allowed to override default value */ 364: #define A6X_RGMU_LONG_IFPC_HYST_FLOOR FIELD_PREP(GENMASK(15, 0), 0x0F00) 365: 366: /* HOSTTOGMU and TIMER0/1 interrupt mask: 0x20060 */ 367: #define RGMU_INTR_EN_MASK (BIT(5) | BIT(6) | BIT(17)) 368: 369: /* RGMU FENCE RANGE MASK */ MATCH LINES: 1152 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: 1149: /* Hard reset the rgmu and gpu */ 1150: a6xx_rgmu_suspend(adreno_dev); 1151: 1152: a6xx_reset_preempt_records(adreno_dev); 1153: 1154: adreno_llcc_slice_deactivate(adreno_dev); 1155: 1156: clear_bit(RGMU_PRIV_GPU_STARTED, &rgmu->flags); 1157: 1158: /* Attempt rebooting the rgmu and gpu */ 1159: return a6xx_boot(adreno_dev); 1160: } 1161: 1162: static int a6xx_rgmu_active_count_get(struct adreno_device *adreno_dev) 1163: { 1164: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1165: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 1166: int ret = 0; 1167: 1168: if (WARN_ON(!kgsl_mutex_is_locked(&device->mutex))) 1169: return -EINVAL; 1170: 1171: if (test_bit(RGMU_PRIV_PM_SUSPEND, &rgmu->flags)) 1172: return -EINVAL; 1173: 1174: if ((atomic_read(&device->active_cnt) == 0) && 1175: !test_bit(RGMU_PRIV_GPU_STARTED, &rgmu->flags)) 1176: ret = a6xx_boot(adreno_dev); --- FILE: \adreno_a6xx_ringbuffer.c | HITS: 11 --- MATCH LINES: 57 45: cmds[count++] = id; 46: 47: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) { 48: cmds[count++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 49: cmds[count++] = cp_type7_packet(CP_WAIT_FOR_ME, 0); 50: cmds[count++] = cp_type4_packet(A6XX_CP_MISC_CNTL, 1); 51: cmds[count++] = 0; 52: } 53: 54: return count; 55: } 56: 57: static int a6xx_rb_context_switch(struct adreno_device *adreno_dev, 58: struct adreno_ringbuffer *rb, 59: struct adreno_context *drawctxt) 60: { 61: struct kgsl_pagetable *pagetable = 62: adreno_drawctxt_get_pagetable(drawctxt); 63: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 64: int count = 0; 65: u32 cmds[41]; 66: 67: if (adreno_drawctxt_get_pagetable(rb->drawctxt_active) != pagetable) { 68: 69: /* Clear performance counters during context switches */ 70: if (!adreno_dev->perfcounter) { 71: cmds[count++] = cp_type4_packet(A6XX_RBBM_PERFCTR_SRAM_INIT_CMD, 1); 72: cmds[count++] = 0x1; 73: } 74: 75: count += a6xx_rb_pagetable_switch(adreno_dev, rb, drawctxt, 76: pagetable, &cmds[count]); 77: 78: /* Wait for performance counter clear to finish */ 79: if (!adreno_dev->perfcounter) { 80: cmds[count++] = cp_type7_packet(CP_WAIT_REG_MEM, 6); 81: cmds[count++] = 0x3; MATCH LINES: 148, 149, 162, 190, 207, 208 136: u32 *cmds = adreno_ringbuffer_allocspace(rb, 3); 137: 138: if (IS_ERR(cmds)) 139: return PTR_ERR(cmds); 140: 141: cmds[0] = cp_type7_packet(CP_WHERE_AM_I, 2); 142: cmds[1] = lower_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id, 143: rptr)); 144: cmds[2] = upper_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id, 145: rptr)); 146: } 147: 148: spin_lock_irqsave(&rb->preempt_lock, flags); 149: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 150: if (adreno_dev->cur_rb == rb) { 151: ret = a6xx_fenced_write(adreno_dev, 152: A6XX_CP_RB_WPTR, rb->_wptr, 153: FENCE_STATUS_WRITEDROPPED0_MASK); 154: rb->skip_inline_wptr = false; 155: } 156: } else { 157: if (adreno_dev->cur_rb == rb) 158: rb->skip_inline_wptr = true; 159: } 160: 161: rb->wptr = rb->_wptr; 162: spin_unlock_irqrestore(&rb->preempt_lock, flags); 163: 164: if (ret) { 165: /* 166: * If WPTR update fails, take inline snapshot and trigger 167: * recovery. 168: */ 169: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 170: adreno_scheduler_fault(adreno_dev, 171: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 172: } 173: 174: return ret; 175: } 176: 177: int a6xx_ringbuffer_init(struct adreno_device *adreno_dev) 178: { 179: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 180: int i, ret; 181: 182: ret = adreno_allocate_global(device, &device->scratch, PAGE_SIZE, 183: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED, 184: "scratch"); 185: if (ret) 186: return ret; 187: 188: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]); 189: 190: if (!adreno_preemption_feature_set(adreno_dev)) { 191: adreno_dev->num_ringbuffers = 1; 192: return adreno_ringbuffer_setup(adreno_dev, 193: &adreno_dev->ringbuffers[0], 0); 194: } 195: 196: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers); 197: 198: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 199: int ret; 200: 201: ret = adreno_ringbuffer_setup(adreno_dev, 202: &adreno_dev->ringbuffers[i], i); 203: if (ret) 204: return ret; 205: } 206: 207: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 208: a6xx_preemption_init(adreno_dev); 209: return 0; 210: } 211: 212: #define A6XX_SUBMIT_MAX 79 213: 214: int a6xx_ringbuffer_addcmds(struct adreno_device *adreno_dev, 215: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 216: u32 flags, u32 *in, u32 dwords, u32 timestamp, 217: struct adreno_submit_time *time) 218: { 219: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 220: u32 size = A6XX_SUBMIT_MAX + dwords; 221: u32 *cmds, index = 0; 222: u64 profile_gpuaddr; 223: u32 profile_dwords; 224: 225: if (adreno_drawctxt_detached(drawctxt)) 226: return -ENOENT; 227: 228: if (adreno_gpu_fault(adreno_dev) != 0) 229: return -EPROTO; 230: 231: rb->timestamp++; 232: MATCH LINES: 252 240: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 241: flags &= ~F_NOTPROTECTED; 242: 243: cmds = adreno_ringbuffer_allocspace(rb, size); 244: if (IS_ERR(cmds)) 245: return PTR_ERR(cmds); 246: 247: /* Identify the start of a command */ 248: cmds[index++] = cp_type7_packet(CP_NOP, 1); 249: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 250: 251: /* This is 25 dwords when drawctxt is not NULL and perfcounter needs to be zapped */ 252: index += a6xx_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 253: &cmds[index]); 254: 255: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 256: cmds[index++] = 0x101; /* IFPC disable */ 257: 258: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 259: drawctxt, &profile_dwords); 260: 261: if (profile_gpuaddr) { 262: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 263: cmds[index++] = lower_32_bits(profile_gpuaddr); 264: cmds[index++] = upper_32_bits(profile_gpuaddr); 265: cmds[index++] = profile_dwords; 266: } 267: 268: if (drawctxt) { 269: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 270: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 271: drawctxt)); 272: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 273: drawctxt)); 274: cmds[index++] = timestamp; 275: } 276: MATCH LINES: 351, 357 339: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 340: cmds[index++] = 0x100; /* IFPC enable */ 341: 342: if (IS_WFI(flags)) 343: cmds[index++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 344: 345: if (IS_SECURE(flags)) { 346: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 347: cmds[index++] = 0; 348: } 349: 350: /* 10 dwords */ 351: index += a6xx_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 352: 353: /* Adjust the thing for the number of dwords we actually wrote */ 354: rb->_wptr -= (size - index); 355: 356: return a6xx_ringbuffer_submit(rb, time, 357: !adreno_is_preemption_enabled(adreno_dev)); 358: } 359: 360: static u32 a6xx_get_alwayson_counter(u32 *cmds, u64 gpuaddr) 361: { 362: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 363: cmds[1] = A6XX_CP_ALWAYS_ON_COUNTER_LO | (1 << 30) | (2 << 18); 364: cmds[2] = lower_32_bits(gpuaddr); 365: cmds[3] = upper_32_bits(gpuaddr); 366: 367: return 4; 368: } 369: 370: static u32 a6xx_get_alwayson_context(u32 *cmds, u64 gpuaddr) 371: { 372: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 373: cmds[1] = A6XX_CP_ALWAYS_ON_CONTEXT_LO | (1 << 30) | (2 << 18); 374: cmds[2] = lower_32_bits(gpuaddr); 375: cmds[3] = upper_32_bits(gpuaddr); 376: 377: return 4; 378: } 379: 380: #define PROFILE_IB_DWORDS 4 381: #define PROFILE_IB_SLOTS (PAGE_SIZE / (PROFILE_IB_DWORDS << 2)) MATCH LINES: 424 412: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 413: int ret; 414: 415: if (rb->drawctxt_active == drawctxt) 416: return 0; 417: 418: if (kgsl_context_detached(&drawctxt->base)) 419: return -ENOENT; 420: 421: if (!_kgsl_context_get(&drawctxt->base)) 422: return -ENOENT; 423: 424: ret = a6xx_rb_context_switch(adreno_dev, rb, drawctxt); 425: if (ret) { 426: kgsl_context_put(&drawctxt->base); 427: return ret; 428: } 429: 430: trace_adreno_drawctxt_switch(rb, drawctxt); 431: 432: /* Release the current drawctxt as soon as the new one is switched */ 433: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active, 434: rb, rb->timestamp); 435: 436: rb->drawctxt_active = drawctxt; 437: return 0; 438: } 439: 440: #define A6XX_USER_PROFILE_IB(rb, cmdobj, cmds, field) \ 441: a6xx_get_user_profiling_ib((rb), (cmdobj), \ 442: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 443: (cmds)) 444: 445: #define A6XX_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 446: a6xx_get_alwayson_counter((cmds), \ 447: (dev)->profile_buffer->gpuaddr + \ 448: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ --- FILE: \adreno_a6xx_snapshot.c | HITS: 2 --- MATCH LINES: 1834, 1835 1822: if (adreno_is_a660(adreno_dev)) { 1823: u32 val; 1824: 1825: kgsl_regread(device, A6XX_RBBM_SNAPSHOT_STATUS, &val); 1826: 1827: if (!val) 1828: dev_err(device->dev, 1829: "Interface signals may have changed during snapshot\n"); 1830: 1831: kgsl_regwrite(device, A6XX_RBBM_SNAPSHOT_STATUS, 0x0); 1832: } 1833: 1834: /* Preemption record */ 1835: adreno_snapshot_preemption_record(device, snapshot); 1836: } 1837: 1838: static int _a6xx_crashdump_init_mvc(struct adreno_device *adreno_dev, 1839: uint64_t *ptr, uint64_t *offset) 1840: { 1841: int qwords = 0; 1842: unsigned int i, j, k; 1843: unsigned int count; 1844: 1845: for (i = 0; i < ARRAY_SIZE(a6xx_clusters); i++) { 1846: struct a6xx_cluster_registers *cluster = &a6xx_clusters[i]; 1847: 1848: /* Skip registers that dont exists on targets other than A660 */ 1849: if (!adreno_is_a660(adreno_dev) && 1850: (cluster->regs == a660_fe_cluster)) 1851: continue; 1852: 1853: /* The VPC registers are driven by VPC_PS cluster on a650 */ 1854: if (adreno_is_a650_family(adreno_dev) && 1855: (cluster->regs == a6xx_vpc_ps_cluster)) 1856: cluster->id = CP_CLUSTER_VPC_PS; 1857: 1858: if (cluster->sel) { 1859: ptr[qwords++] = cluster->sel->val; --- FILE: \adreno_debugfs.c | HITS: 18 --- MATCH LINES: 559, 561, 570, 583, 585, 594, 600, 606, 609, 614, 618, 622 547: *val = (u64) adreno_dev->bcl_throttle_time_us; 548: 549: return 0; 550: } 551: DEFINE_DEBUGFS_ATTRIBUTE(_bcl_throttle_fops, _bcl_throttle_time_us_get, NULL, "%llu\n"); 552: 553: static int _skipsaverestore_store(void *data, u64 val) 554: { 555: struct adreno_device *adreno_dev = data; 556: 557: if (adreno_dev->hwsched_enabled) 558: return adreno_power_cycle_bool(adreno_dev, 559: &adreno_dev->preempt.skipsaverestore, val); 560: 561: adreno_dev->preempt.skipsaverestore = val ? true : false; 562: return 0; 563: 564: } 565: 566: static int _skipsaverestore_show(void *data, u64 *val) 567: { 568: struct adreno_device *adreno_dev = data; 569: 570: *val = (u64) adreno_dev->preempt.skipsaverestore; 571: return 0; 572: } 573: 574: DEFINE_DEBUGFS_ATTRIBUTE(skipsaverestore_fops, _skipsaverestore_show, _skipsaverestore_store, 575: "%llu\n"); 576: 577: static int _usesgmem_store(void *data, u64 val) 578: { 579: struct adreno_device *adreno_dev = data; 580: 581: if (adreno_dev->hwsched_enabled) 582: return adreno_power_cycle_bool(adreno_dev, 583: &adreno_dev->preempt.usesgmem, val); 584: 585: adreno_dev->preempt.usesgmem = val ? true : false; 586: return 0; 587: 588: } 589: 590: static int _usesgmem_show(void *data, u64 *val) 591: { 592: struct adreno_device *adreno_dev = data; 593: 594: *val = (u64) adreno_dev->preempt.usesgmem; 595: return 0; 596: } 597: 598: DEFINE_DEBUGFS_ATTRIBUTE(usesgmem_fops, _usesgmem_show, _usesgmem_store, "%llu\n"); 599: 600: static int _preempt_level_store(void *data, u64 val) 601: { 602: struct adreno_device *adreno_dev = data; 603: 604: if (adreno_dev->hwsched_enabled) 605: return adreno_power_cycle_u32(adreno_dev, 606: &adreno_dev->preempt.preempt_level, 607: min_t(u64, val, 2)); 608: 609: adreno_dev->preempt.preempt_level = min_t(u64, val, 2); 610: return 0; 611: 612: } 613: 614: static int _preempt_level_show(void *data, u64 *val) 615: { 616: struct adreno_device *adreno_dev = data; 617: 618: *val = (u64) adreno_dev->preempt.preempt_level; 619: return 0; 620: } 621: 622: DEFINE_DEBUGFS_ATTRIBUTE(preempt_level_fops, _preempt_level_show, _preempt_level_store, "%llu\n"); 623: 624: static int _warmboot_show(void *data, u64 *val) 625: { 626: struct adreno_device *adreno_dev = data; 627: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 628: struct gmu_core_device *gmu = &device->gmu_core; 629: 630: *val = (u64)gmu->warmboot_enabled; 631: return 0; 632: } 633: 634: /* 635: * When warmboot feature is enabled from debugfs, the first slumber exit will be a cold boot 636: * and all hfi messages will be recorded, so that warmboot can happen on subsequent slumber 637: * exit. When warmboot feature is disabled from debugfs, every slumber exit will be a coldboot. 638: */ 639: static int _warmboot_store(void *data, u64 val) 640: { 641: struct adreno_device *adreno_dev = data; 642: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 643: struct gmu_core_device *gmu_core = &device->gmu_core; 644: 645: if (gmu_core->warmboot_enabled == val) 646: return 0; MATCH LINES: 862, 863, 864, 865, 866, 868 850: debugfs_create_file("prealloc_atomic_snapshot_mem", 0644, snapshot_dir, 851: device, &_prealloc_atomic_snapshot_mem_fops); 852: 853: adreno_dev->bcl_debugfs_dir = debugfs_create_dir("bcl", device->d_debugfs); 854: if (!IS_ERR_OR_NULL(adreno_dev->bcl_debugfs_dir)) { 855: debugfs_create_file("sid0", 0644, adreno_dev->bcl_debugfs_dir, device, &_sid0_fops); 856: debugfs_create_file("sid1", 0644, adreno_dev->bcl_debugfs_dir, device, &_sid1_fops); 857: debugfs_create_file("sid2", 0644, adreno_dev->bcl_debugfs_dir, device, &_sid2_fops); 858: debugfs_create_file("bcl_throttle_time_us", 0444, adreno_dev->bcl_debugfs_dir, 859: device, &_bcl_throttle_fops); 860: } 861: 862: adreno_dev->preemption_debugfs_dir = debugfs_create_dir("preemption", device->d_debugfs); 863: if (!IS_ERR_OR_NULL(adreno_dev->preemption_debugfs_dir)) { 864: debugfs_create_file("preempt_level", 0644, adreno_dev->preemption_debugfs_dir, 865: device, &preempt_level_fops); 866: debugfs_create_file("usesgmem", 0644, adreno_dev->preemption_debugfs_dir, device, 867: &usesgmem_fops); 868: debugfs_create_file("skipsaverestore", 0644, adreno_dev->preemption_debugfs_dir, 869: device, &skipsaverestore_fops); 870: } 871: 872: if (ADRENO_FEATURE(adreno_dev, ADRENO_GMU_BASED_DCVS)) 873: debugfs_create_file("host_based_dcvs", 0644, device->d_debugfs, 874: device, &host_based_dcvs_fops); 875: } --- FILE: \adreno_dispatch.c | HITS: 31 --- MATCH LINES: 427 415: /* 416: * Real time clients may demand high BW and have strict latency requirement. 417: * GPU bus DCVS is not fast enough to account for sudden BW requirements. 418: * Bus hint helps to bump up the bus vote (IB) upfront for known time-critical 419: * workloads. 420: */ 421: static void process_rt_bus_hint(struct kgsl_device *device, bool on) 422: { 423: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 424: struct adreno_dispatcher_drawqueue *drawqueue = 425: DRAWQUEUE(&adreno_dev->ringbuffers[0]); 426: 427: if (!adreno_is_preemption_enabled(adreno_dev) || 428: !device->pwrctrl.rt_bus_hint) 429: return; 430: 431: if (device->pwrctrl.rt_bus_hint_active == on) 432: return; 433: 434: if (on && drawqueue->inflight == 1) 435: kgsl_bus_update(device, KGSL_BUS_VOTE_RT_HINT_ON); 436: 437: if (!on && drawqueue->inflight == 0) 438: kgsl_bus_update(device, KGSL_BUS_VOTE_RT_HINT_OFF); 439: } 440: 441: #define ADRENO_DRAWOBJ_PROFILE_COUNT \ 442: (PAGE_SIZE / sizeof(struct adreno_drawobj_profile_entry)) 443: 444: /** 445: * sendcmd() - Send a drawobj to the GPU hardware 446: * @dispatcher: Pointer to the adreno dispatcher struct 447: * @drawobj: Pointer to the KGSL drawobj being sent 448: * 449: * Send a KGSL drawobj to the GPU hardware 450: */ 451: static int sendcmd(struct adreno_device *adreno_dev, MATCH LINES: 550, 584, 585, 588, 598, 599 538: "Unable to submit command to the ringbuffer %d\n", 539: ret); 540: goto err; 541: } 542: 543: secs = time.ktime; 544: nsecs = do_div(secs, 1000000000); 545: 546: /* 547: * For the first submission in any given command queue update the 548: * expected expire time - this won't actually be used / updated until 549: * the command queue in question goes current, but universally setting 550: * it here avoids the possibilty of some race conditions with preempt 551: */ 552: 553: if (dispatch_q->inflight == 1) 554: dispatch_q->expires = jiffies + 555: msecs_to_jiffies(adreno_drawobj_timeout); 556: 557: info.inflight = (int) dispatcher->inflight; 558: info.rb_id = drawctxt->rb->id; 559: info.rptr = adreno_get_rptr(drawctxt->rb); 560: info.wptr = drawctxt->rb->wptr; 561: info.gmu_dispatch_queue = -1; 562: 563: msm_perf_events_update(MSM_PERF_GFX, MSM_PERF_SUBMIT, 564: pid_nr(context->proc_priv->pid), 565: context->id, drawobj->timestamp, 566: !!(drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME)); 567: 568: trace_adreno_cmdbatch_submitted(drawobj, &info, 569: time.ticks, (unsigned long) secs, nsecs / 1000, 570: dispatch_q->inflight); 571: 572: log_kgsl_cmdbatch_submitted_event(context->id, drawobj->timestamp, 573: context->priority, drawobj->flags); 574: 575: kgsl_mutex_unlock(&device->mutex); 576: 577: cmdobj->submit_ticks = time.ticks; 578: 579: dispatch_q->cmd_q[dispatch_q->tail] = cmdobj; 580: dispatch_q->tail = (dispatch_q->tail + 1) % 581: ADRENO_DISPATCH_DRAWQUEUE_SIZE; 582: 583: /* 584: * If we believe ourselves to be current and preemption isn't a thing, 585: * then set up the timer. If this misses, then preemption is indeed a 586: * thing and the timer will be set up in due time 587: */ 588: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 589: if (drawqueue_is_current(dispatch_q)) 590: mod_timer(&dispatcher->timer, dispatch_q->expires); 591: } 592: 593: 594: /* 595: * we just submitted something, readjust ringbuffer 596: * execution level 597: */ 598: if (gpudev->preemption_schedule) 599: gpudev->preemption_schedule(adreno_dev); 600: return 0; 601: err: 602: kgsl_mutex_unlock(&device->mutex); 603: return ret; 604: } 605: 606: /** 607: * dispatcher_context_sendcmds() - Send commands from a context to the GPU 608: * @adreno_dev: Pointer to the adreno device struct 609: * @drawctxt: Pointer to the adreno context to dispatch commands from 610: * 611: * Dequeue and send a burst of commands from the specified context to the GPU 612: * Returns postive if the context needs to be put back on the pending queue 613: * 0 if the context is empty or detached and negative on error 614: */ 615: static int dispatcher_context_sendcmds(struct adreno_device *adreno_dev, 616: struct adreno_context *drawctxt) 617: { 618: struct adreno_dispatcher_drawqueue *dispatch_q = 619: &(drawctxt->rb->dispatch_q); 620: int count = 0; 621: int ret = 0; 622: int inflight = _drawqueue_inflight(dispatch_q); 623: unsigned int timestamp; MATCH LINES: 837 825: { 826: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 827: struct adreno_dispatcher *dispatcher = &adreno_dev->dispatcher; 828: 829: /* Kick the idle timer */ 830: kgsl_mutex_lock(&device->mutex); 831: kgsl_pwrscale_update(device); 832: process_rt_bus_hint(device, false); 833: kgsl_start_idle_timer(device); 834: kgsl_mutex_unlock(&device->mutex); 835: 836: /* Check to see if we need to update the command timer */ 837: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 838: struct adreno_dispatcher_drawqueue *drawqueue = 839: DRAWQUEUE(adreno_dev->cur_rb); 840: 841: if (!adreno_drawqueue_is_empty(drawqueue)) 842: mod_timer(&dispatcher->timer, drawqueue->expires); 843: } 844: } 845: 846: static inline void _decrement_submit_now(struct kgsl_device *device) 847: { 848: spin_lock(&device->submit_lock); 849: device->submit_now--; 850: spin_unlock(&device->submit_lock); 851: } 852: 853: /** 854: * adreno_dispatcher_issuecmds() - Issue commmands from pending contexts 855: * @adreno_dev: Pointer to the adreno device struct 856: * 857: * Lock the dispatcher and call _adreno_dispatcher_issueibcmds 858: */ 859: static void adreno_dispatcher_issuecmds(struct adreno_device *adreno_dev) 860: { 861: struct adreno_dispatcher *dispatcher = &adreno_dev->dispatcher; MATCH LINES: 1962, 1963 1950: "SMMU is stalled without a pagefault\n"); 1951: return -EBUSY; 1952: } 1953: } 1954: 1955: /* Turn off all the timers */ 1956: kgsl_delete_timer_sync(&dispatcher->timer); 1957: 1958: /* 1959: * Deleting uninitialized timer will block for ever on kernel debug 1960: * disable build. Hence skip del timer if it is not initialized. 1961: */ 1962: if (adreno_is_preemption_enabled(adreno_dev)) 1963: kgsl_delete_timer_sync(&adreno_dev->preempt.timer); 1964: 1965: if (gx_on) 1966: adreno_readreg64(adreno_dev, ADRENO_REG_CP_RB_BASE, 1967: ADRENO_REG_CP_RB_BASE_HI, &base); 1968: 1969: /* Force the CP off for all faults to make sure it is good and stopped */ 1970: if (gx_on) { 1971: adreno_readreg(adreno_dev, ADRENO_REG_CP_ME_CNTL, ®); 1972: 1973: if (adreno_is_a5xx(adreno_dev) || adreno_is_a6xx(adreno_dev)) 1974: reg |= 1 | (1 << 1); 1975: else 1976: reg = 0x0; 1977: 1978: adreno_writereg(adreno_dev, ADRENO_REG_CP_ME_CNTL, reg); 1979: } 1980: /* 1981: * retire cmdobj's from all the dispatch_q's before starting recovery 1982: */ 1983: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1984: adreno_dispatch_retire_drawqueue(adreno_dev, 1985: &(rb->dispatch_q)); 1986: /* Select the active dispatch_q */ 1987: if (base == rb->buffer_desc->gpuaddr) { MATCH LINES: 2347, 2351, 2352, 2353 2335: DRAWQUEUE(&adreno_dev->ringbuffers[i]); 2336: 2337: count += adreno_dispatch_process_drawqueue(adreno_dev, 2338: drawqueue); 2339: if (dispatcher->inflight == 0) 2340: break; 2341: } 2342: 2343: kgsl_process_event_groups(device); 2344: 2345: /* 2346: * dispatcher_do_fault() returns 0 if no faults occurred. If that is the 2347: * case, then clean up preemption and try to schedule more work 2348: */ 2349: if (dispatcher_do_fault(adreno_dev) == 0) { 2350: 2351: /* Clean up after preemption */ 2352: if (gpudev->preemption_schedule) 2353: gpudev->preemption_schedule(adreno_dev); 2354: 2355: /* Run the scheduler for to dispatch new commands */ 2356: _adreno_dispatcher_issuecmds(adreno_dev); 2357: } 2358: 2359: /* 2360: * If there are commands pending, update the timers, otherwise release 2361: * the power state to prepare for power down 2362: */ 2363: if (dispatcher->inflight > 0) 2364: _dispatcher_update_timers(adreno_dev); 2365: else 2366: _dispatcher_power_down(adreno_dev); 2367: 2368: mutex_unlock(&dispatcher->mutex); 2369: } 2370: 2371: /* 2372: * Put a draw context on the dispatcher pending queue and schedule the 2373: * dispatcher. This is used to reschedule changes that might have been blocked 2374: * for sync points or other concerns 2375: */ 2376: static void adreno_dispatcher_queue_context(struct adreno_device *adreno_dev, 2377: struct adreno_context *drawctxt) MATCH LINES: 2428, 2429, 2449, 2463, 2469, 2490, 2492, 2493, 2496, 2499, 2501, 2504, 2506, 2520, 2521, 2525, 2526 2416: { 2417: struct adreno_dispatcher *dispatcher = &adreno_dev->dispatcher; 2418: 2419: kgsl_delete_timer_sync(&dispatcher->timer); 2420: } 2421: 2422: /* Return the ringbuffer that matches the draw context priority */ 2423: static struct adreno_ringbuffer *dispatch_get_rb(struct adreno_device *adreno_dev, 2424: struct adreno_context *drawctxt) 2425: { 2426: int level; 2427: 2428: /* If preemption is disabled everybody goes on the same ringbuffer */ 2429: if (!adreno_is_preemption_enabled(adreno_dev)) 2430: return &adreno_dev->ringbuffers[0]; 2431: 2432: /* 2433: * Math to convert the priority field in context structure to an RB ID. 2434: * Divide up the context priority based on number of ringbuffer levels. 2435: */ 2436: level = min_t(int, drawctxt->base.priority / adreno_dev->num_ringbuffers, 2437: adreno_dev->num_ringbuffers - 1); 2438: 2439: return &adreno_dev->ringbuffers[level]; 2440: } 2441: 2442: static int adreno_dispatcher_setup_context(struct adreno_device *adreno_dev, 2443: struct adreno_context *drawctxt) 2444: { 2445: drawctxt->rb = dispatch_get_rb(adreno_dev, drawctxt); 2446: return 0; 2447: } 2448: 2449: static void change_preemption(struct adreno_device *adreno_dev, void *priv) 2450: { 2451: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2452: struct kgsl_context *context; 2453: struct adreno_context *drawctxt; 2454: struct adreno_ringbuffer *rb; 2455: int id, i, ret; 2456: 2457: /* Make sure all ringbuffers are finished */ 2458: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2459: ret = adreno_ringbuffer_waittimestamp(rb, rb->timestamp, 2460: 2 * 1000); 2461: if (ret) { 2462: dev_err(device->dev, 2463: "Cannot disable preemption because couldn't idle ringbuffer[%d] ret: %d\n", 2464: rb->id, ret); 2465: return; 2466: } 2467: } 2468: 2469: change_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 2470: adreno_dev->cur_rb = &adreno_dev->ringbuffers[0]; 2471: adreno_dev->next_rb = NULL; 2472: adreno_dev->prev_rb = NULL; 2473: 2474: /* Update the ringbuffer for each draw context */ 2475: write_lock(&device->context_lock); 2476: idr_for_each_entry(&device->context_idr, context, id) { 2477: drawctxt = ADRENO_CONTEXT(context); 2478: drawctxt->rb = dispatch_get_rb(adreno_dev, drawctxt); 2479: 2480: /* 2481: * Make sure context destroy checks against the correct 2482: * ringbuffer's timestamp. 2483: */ 2484: adreno_rb_readtimestamp(adreno_dev, drawctxt->rb, 2485: KGSL_TIMESTAMP_RETIRED, &drawctxt->internal_timestamp); 2486: } 2487: write_unlock(&device->context_lock); 2488: } 2489: 2490: static int _preemption_store(struct adreno_device *adreno_dev, bool val) 2491: { 2492: if (!adreno_preemption_feature_set(adreno_dev) || 2493: (test_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv) == val)) 2494: return 0; 2495: 2496: return adreno_power_cycle(adreno_dev, change_preemption, NULL); 2497: } 2498: 2499: static bool _preemption_show(struct adreno_device *adreno_dev) 2500: { 2501: return adreno_is_preemption_enabled(adreno_dev); 2502: } 2503: 2504: static unsigned int _preempt_count_show(struct adreno_device *adreno_dev) 2505: { 2506: return adreno_dev->preempt.count; 2507: } 2508: 2509: static int _ft_long_ib_detect_store(struct adreno_device *adreno_dev, bool val) 2510: { 2511: adreno_dev->long_ib_detect = val ? true : false; 2512: return 0; 2513: } 2514: 2515: static bool _ft_long_ib_detect_show(struct adreno_device *adreno_dev) 2516: { 2517: return adreno_dev->long_ib_detect; 2518: } 2519: 2520: static ADRENO_SYSFS_BOOL(preemption); 2521: static ADRENO_SYSFS_RO_U32(preempt_count); 2522: static ADRENO_SYSFS_BOOL(ft_long_ib_detect); 2523: 2524: static const struct attribute *_dispatch_attr_list[] = { 2525: &adreno_attr_preemption.attr.attr, 2526: &adreno_attr_preempt_count.attr.attr, 2527: &adreno_attr_ft_long_ib_detect.attr.attr, 2528: NULL, 2529: }; 2530: 2531: static void adreno_dispatcher_close(struct adreno_device *adreno_dev) 2532: { 2533: struct adreno_dispatcher *dispatcher = &adreno_dev->dispatcher; 2534: int i; 2535: struct adreno_ringbuffer *rb; 2536: 2537: mutex_lock(&dispatcher->mutex); 2538: kgsl_delete_timer_sync(&dispatcher->timer); 2539: 2540: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2541: struct adreno_dispatcher_drawqueue *dispatch_q = 2542: &(rb->dispatch_q); 2543: while (!adreno_drawqueue_is_empty(dispatch_q)) { 2544: kgsl_drawobj_destroy( 2545: DRAWOBJ(dispatch_q->cmd_q[dispatch_q->head])); 2546: dispatch_q->head = (dispatch_q->head + 1) 2547: % ADRENO_DISPATCH_DRAWQUEUE_SIZE; 2548: } 2549: } 2550: --- FILE: \adreno_drawctxt.c | HITS: 12 --- MATCH LINES: 314, 324, 340, 349, 354, 363, 365 302: 303: void adreno_drawctxt_set_guilty(struct kgsl_device *device, 304: struct kgsl_context *context) 305: { 306: if (!context) 307: return; 308: 309: context->reset_status = KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT; 310: 311: adreno_drawctxt_invalidate(device, context); 312: } 313: 314: u32 adreno_prepare_preib_preempt_scratch(struct adreno_device *adreno_dev, 315: struct adreno_context *drawctxt, u32 *cmds) 316: { 317: struct adreno_ringbuffer *rb = drawctxt->rb; 318: u32 *cmds_orig = cmds; 319: u64 gpuaddr, dest; 320: 321: if (!drawctxt->base.user_ctxt_record) 322: return 0; 323: 324: dest = PREEMPT_SCRATCH_ADDR(adreno_dev, rb->id); 325: gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 326: 327: *cmds++ = cp_mem_packet(adreno_dev, CP_MEM_WRITE, 2, 2); 328: cmds += cp_gpuaddr(adreno_dev, cmds, dest); 329: *cmds++ = lower_32_bits(gpuaddr); 330: *cmds++ = upper_32_bits(gpuaddr); 331: 332: return (u32) (cmds - cmds_orig); 333: } 334: 335: u32 adreno_prepare_preib_postamble_scratch(struct adreno_device *adreno_dev, u32 *cmds) 336: { 337: u32 *cmds_orig = cmds; 338: u64 kmd_postamble_addr; 339: 340: if (!adreno_dev->preempt.postamble_len) 341: return 0; 342: 343: kmd_postamble_addr = SCRATCH_POSTAMBLE_ADDR(KGSL_DEVICE(adreno_dev)); 344: 345: *cmds++ = cp_type7_packet(CP_SET_AMBLE, 3); 346: *cmds++ = lower_32_bits(kmd_postamble_addr); 347: *cmds++ = upper_32_bits(kmd_postamble_addr); 348: *cmds++ = FIELD_PREP(GENMASK(22, 20), CP_KMD_AMBLE_TYPE) 349: | (FIELD_PREP(GENMASK(19, 0), adreno_dev->preempt.postamble_len)); 350: 351: return (u32) (cmds - cmds_orig); 352: } 353: 354: static int drawctxt_preemption_init(struct kgsl_context *context) 355: { 356: struct kgsl_device *device = context->device; 357: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 358: u64 flags = 0; 359: 360: /* 361: * User context record is needed for a6x and beyond targets only. Also, 362: * highest priority ringbuffer i.e. RB0 always runs to completion without 363: * preemption. Thus, user context records are not needed for RB0. 364: */ 365: if (!adreno_preemption_feature_set(adreno_dev) || (ADRENO_GPUREV(adreno_dev) < 600) || 366: (adreno_get_level(context) == 0)) 367: return 0; 368: 369: if (context->flags & KGSL_CONTEXT_SECURE) 370: flags |= KGSL_MEMFLAGS_SECURE; 371: 372: if (is_compat_task()) 373: flags |= KGSL_MEMFLAGS_FORCE_32BIT; 374: 375: /* 376: * gpumem_alloc_entry takes an extra refcount. Put it only when 377: * destroying the context to keep the context record valid 378: */ 379: context->user_ctxt_record = gpumem_alloc_entry(context->dev_priv, 380: ADRENO_CP_CTXRECORD_USER_RESTORE_SIZE, flags); 381: if (IS_ERR(context->user_ctxt_record)) { 382: int ret = PTR_ERR(context->user_ctxt_record); 383: 384: context->user_ctxt_record = NULL; 385: return ret; 386: } 387: 388: return 0; 389: } MATCH LINES: 422, 429, 430, 431 410: local = *flags & (KGSL_CONTEXT_PREAMBLE | 411: KGSL_CONTEXT_NO_GMEM_ALLOC | 412: KGSL_CONTEXT_PER_CONTEXT_TS | 413: KGSL_CONTEXT_USER_GENERATED_TS | 414: KGSL_CONTEXT_NO_FAULT_TOLERANCE | 415: KGSL_CONTEXT_INVALIDATE_ON_FAULT | 416: KGSL_CONTEXT_CTX_SWITCH | 417: KGSL_CONTEXT_PRIORITY_MASK | 418: KGSL_CONTEXT_TYPE_MASK | 419: KGSL_CONTEXT_PWR_CONSTRAINT | 420: KGSL_CONTEXT_IFH_NOP | 421: KGSL_CONTEXT_SECURE | 422: KGSL_CONTEXT_PREEMPT_STYLE_MASK | 423: KGSL_CONTEXT_LPAC | 424: KGSL_CONTEXT_NO_SNAPSHOT | 425: KGSL_CONTEXT_FAULT_INFO); 426: 427: /* Check for errors before trying to initialize */ 428: 429: /* If preemption is not supported, ignore preemption request */ 430: if (!adreno_preemption_feature_set(adreno_dev)) 431: local &= ~KGSL_CONTEXT_PREEMPT_STYLE_MASK; 432: 433: /* We no longer support legacy context switching */ 434: if ((local & KGSL_CONTEXT_PREAMBLE) == 0 || 435: (local & KGSL_CONTEXT_NO_GMEM_ALLOC) == 0) { 436: dev_err_once(device->dev, 437: "legacy context switch not supported\n"); 438: return ERR_PTR(-EINVAL); 439: } 440: 441: /* Make sure that our target can support secure contexts if requested */ 442: if (!kgsl_mmu_is_secured(&device->mmu) && 443: (local & KGSL_CONTEXT_SECURE)) { 444: dev_err_once(device->dev, "Secure context not supported\n"); 445: return ERR_PTR(-EOPNOTSUPP); 446: } 447: 448: if ((local & KGSL_CONTEXT_LPAC) && 449: (!(adreno_dev->lpac_enabled))) { 450: dev_err_once(device->dev, "LPAC context not supported\n"); 451: return ERR_PTR(-EOPNOTSUPP); 452: } 453: 454: if ((local & KGSL_CONTEXT_LPAC) && (local & KGSL_CONTEXT_SECURE)) { 455: dev_err_once(device->dev, "LPAC secure context not supported\n"); MATCH LINES: 523 511: INIT_LIST_HEAD(&drawctxt->hw_fence_inflight_list); 512: 513: if (adreno_dev->dispatch_ops && adreno_dev->dispatch_ops->setup_context) { 514: ret = adreno_dev->dispatch_ops->setup_context(adreno_dev, drawctxt); 515: if (ret) { 516: dev_err_ratelimited(device->dev, 517: "Context initialization failed ret:%d\n", ret); 518: kgsl_context_detach(&drawctxt->base); 519: return ERR_PTR(ret); 520: } 521: } 522: 523: ret = drawctxt_preemption_init(&drawctxt->base); 524: if (ret) { 525: kgsl_context_detach(&drawctxt->base); 526: return ERR_PTR(ret); 527: } 528: 529: /* copy back whatever flags we dediced were valid */ 530: *flags = drawctxt->base.flags; 531: 532: return &drawctxt->base; 533: } 534: 535: static void wait_for_timestamp_rb(struct kgsl_device *device, 536: struct adreno_context *drawctxt) 537: { 538: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 539: struct kgsl_context *context = &drawctxt->base; 540: int ret; 541: 542: /* 543: * internal_timestamp is set in adreno_ringbuffer_addcmds, 544: * which holds the device mutex. 545: */ 546: kgsl_mutex_lock(&device->mutex); 547: --- FILE: \adreno_drawctxt.h | HITS: 2 --- MATCH LINES: 207, 215 195: 196: /** 197: * adreno_drawctxt_set_guilty - Mark a context as guilty and invalidate it 198: * @device: Pointer to a GPU device handle 199: * @context: Pointer to the context to invalidate 200: * 201: * Mark the specified context as guilty and invalidate it 202: */ 203: void adreno_drawctxt_set_guilty(struct kgsl_device *device, 204: struct kgsl_context *context); 205: 206: /** 207: * adreno_prepare_preib_preempt_scratch - Update drawctxt pointer in preemption 208: * scratch buffer before IB commands 209: * @adreno_dev: Pointer to the adreno device 210: * @drawctxt: Pointer to the adreno draw context 211: * @cmds: Pointer to the ringbuffer to insert opcodes 212: * 213: * Return: The number of dwords written to @cmds 214: */ 215: u32 adreno_prepare_preib_preempt_scratch(struct adreno_device *adreno_dev, 216: struct adreno_context *drawctxt, u32 *cmds); 217: 218: /** 219: * adreno_prepare_preib_postamble_scratch - Insert postamble packets before IB commands 220: * @adreno_dev: Pointer to the adreno device 221: * @cmds: Pointer to the ringbuffer to insert opcodes 222: * 223: * Return: The number of dwords written to @cmds 224: */ 225: u32 adreno_prepare_preib_postamble_scratch(struct adreno_device *adreno_dev, u32 *cmds); 226: 227: /** 228: * adreno_track_context - Add a context to active list and keep track of active contexts 229: * @adreno_dev: Pointer to adreno device 230: * @drawqueue: Pointer to the dispatch queue to which context send commands 231: * @drawctxt: Draw context which is to be tracked 232: * 233: * Add the given draw context to the active list and update number of contexts which 234: * are active overall as well as which are active on the dispatch queue to which 235: * the given context sends commands. 236: */ 237: void adreno_track_context(struct adreno_device *adreno_dev, 238: struct adreno_dispatcher_drawqueue *drawqueue, 239: struct adreno_context *drawctxt); --- FILE: \adreno_gen7.c | HITS: 44 --- MATCH LINES: 27, 40, 59 15: #include 16: #endif 17: 18: #include "adreno.h" 19: #include "adreno_gen7.h" 20: #include "adreno_gen7_hwsched.h" 21: #include "adreno_pm4types.h" 22: #include "adreno_trace.h" 23: #include "kgsl_pwrscale.h" 24: #include "kgsl_trace.h" 25: #include "kgsl_util.h" 26: 27: /* IFPC & Preemption static powerup restore list */ 28: static const u32 gen7_pwrup_reglist[] = { 29: GEN7_UCHE_TRAP_BASE_LO, 30: GEN7_UCHE_TRAP_BASE_HI, 31: GEN7_UCHE_WRITE_THRU_BASE_LO, 32: GEN7_UCHE_WRITE_THRU_BASE_HI, 33: GEN7_UCHE_GMEM_RANGE_MIN_LO, 34: GEN7_UCHE_GMEM_RANGE_MIN_HI, 35: GEN7_UCHE_GMEM_RANGE_MAX_LO, 36: GEN7_UCHE_GMEM_RANGE_MAX_HI, 37: GEN7_UCHE_CACHE_WAYS, 38: GEN7_UCHE_MODE_CNTL, 39: GEN7_RB_NC_MODE_CNTL, 40: GEN7_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, 41: GEN7_UCHE_GBIF_GX_CONFIG, 42: GEN7_UCHE_CLIENT_PF, 43: GEN7_TPL1_DBG_ECO_CNTL1, 44: }; 45: 46: static const u32 gen7_0_0_pwrup_reglist[] = { 47: GEN7_UCHE_TRAP_BASE_LO, 48: GEN7_UCHE_TRAP_BASE_HI, 49: GEN7_UCHE_WRITE_THRU_BASE_LO, 50: GEN7_UCHE_WRITE_THRU_BASE_HI, 51: GEN7_UCHE_GMEM_RANGE_MIN_LO, 52: GEN7_UCHE_GMEM_RANGE_MIN_HI, 53: GEN7_UCHE_GMEM_RANGE_MAX_LO, 54: GEN7_UCHE_GMEM_RANGE_MAX_HI, 55: GEN7_UCHE_CACHE_WAYS, 56: GEN7_UCHE_MODE_CNTL, 57: GEN7_RB_NC_MODE_CNTL, 58: GEN7_SP_NC_MODE_CNTL, 59: GEN7_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, 60: GEN7_UCHE_GBIF_GX_CONFIG, 61: GEN7_UCHE_CLIENT_PF, 62: }; 63: 64: /* IFPC only static powerup restore list */ 65: static const u32 gen7_ifpc_pwrup_reglist[] = { 66: GEN7_TPL1_NC_MODE_CNTL, 67: GEN7_SP_NC_MODE_CNTL, 68: GEN7_CP_DBG_ECO_CNTL, 69: GEN7_CP_PROTECT_CNTL, 70: GEN7_CP_LPAC_PROTECT_CNTL, 71: GEN7_CP_PROTECT_REG, 72: GEN7_CP_PROTECT_REG+1, 73: GEN7_CP_PROTECT_REG+2, 74: GEN7_CP_PROTECT_REG+3, 75: GEN7_CP_PROTECT_REG+4, 76: GEN7_CP_PROTECT_REG+5, 77: GEN7_CP_PROTECT_REG+6, 78: GEN7_CP_PROTECT_REG+7, 79: GEN7_CP_PROTECT_REG+8, 80: GEN7_CP_PROTECT_REG+9, 81: GEN7_CP_PROTECT_REG+10, 82: GEN7_CP_PROTECT_REG+11, 83: GEN7_CP_PROTECT_REG+12, MATCH LINES: 209 197: GEN7_UCHE_WRITE_THRU_BASE_LO, 198: GEN7_UCHE_WRITE_THRU_BASE_HI, 199: GEN7_UCHE_GMEM_RANGE_MIN_LO, 200: GEN7_UCHE_GMEM_RANGE_MIN_HI, 201: GEN7_UCHE_GMEM_RANGE_MAX_LO, 202: GEN7_UCHE_GMEM_RANGE_MAX_HI, 203: GEN7_UCHE_CACHE_WAYS, 204: GEN7_UCHE_MODE_CNTL, 205: GEN7_RB_NC_MODE_CNTL, 206: GEN7_RB_CMP_DBG_ECO_CNTL, 207: GEN7_GRAS_NC_MODE_CNTL, 208: GEN7_SP_NC_MODE_CNTL, 209: GEN7_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, 210: GEN7_UCHE_GBIF_GX_CONFIG, 211: GEN7_UCHE_CLIENT_PF, 212: }; 213: 214: static int acd_calibrate_set(void *data, u64 val) 215: { 216: struct kgsl_device *device = data; 217: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 218: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 219: u32 debug_val = (u32) val; 220: int ret; 221: 222: kgsl_mutex_lock(&device->mutex); 223: ret = adreno_active_count_get(adreno_dev); 224: if (ret) 225: goto err; 226: 227: ret = gen7_hfi_send_set_value(adreno_dev, HFI_VALUE_DBG, F_PWR_ACD_CALIBRATE, debug_val); 228: if (!ret) 229: gmu->acd_debug_val = debug_val; 230: 231: adreno_active_count_put(adreno_dev); 232: err: 233: kgsl_mutex_unlock(&device->mutex); MATCH LINES: 267 255: cmds[i++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 256: cmds[i++] = BIT(27); 257: 258: /* Use multiple HW contexts */ 259: mask |= BIT(0); 260: 261: /* Enable error detection */ 262: mask |= BIT(1); 263: 264: /* Set default reset state */ 265: mask |= BIT(3); 266: 267: /* Disable save/restore of performance counters across preemption */ 268: mask |= BIT(6); 269: 270: /* Enable the register init list with the spinlock */ 271: mask |= BIT(8); 272: 273: /* By default DMS is enabled from CP side, disable it if not supported */ 274: if (!adreno_dev->dms_enabled) 275: mask |= BIT(11); 276: 277: cmds[i++] = cp_type7_packet(CP_ME_INIT, 7); 278: 279: /* Enabled ordinal mask */ 280: cmds[i++] = mask; 281: cmds[i++] = 0x00000003; /* Set number of HW contexts */ 282: cmds[i++] = 0x20000000; /* Enable error detection */ 283: cmds[i++] = 0x00000002; /* Operation mode mask */ 284: 285: /* Register initialization list with spinlock */ 286: cmds[i++] = lower_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 287: cmds[i++] = upper_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 288: /* 289: * Gen7 targets with concurrent binning are expected to have a dynamic 290: * power up list with triplets which contains the pipe id in it. 291: * Bit 31 of POWER_UP_REGISTER_LIST_LENGTH is reused here to let CP MATCH LINES: 699, 710, 736, 737, 740 687: lock->ifpc_list_len += reglist[items].count; 688: items++; 689: } 690: } 691: 692: if (adreno_is_gen7_9_x(adreno_dev)) { 693: reglist[items].regs = gen7_9_x_ifpc_pwrup_reglist; 694: reglist[items].count = ARRAY_SIZE(gen7_9_x_ifpc_pwrup_reglist); 695: lock->ifpc_list_len += reglist[items].count; 696: items++; 697: } 698: 699: /* Static IFPC + preemption registers */ 700: if (adreno_is_gen7_no_cb_family(adreno_dev)) { 701: reglist[items].regs = gen7_pwrup_reglist_no_cb; 702: reglist[items].count = ARRAY_SIZE(gen7_pwrup_reglist_no_cb); 703: } else if (adreno_is_gen7_0_x_family(adreno_dev)) { 704: reglist[items].regs = gen7_0_0_pwrup_reglist; 705: reglist[items].count = ARRAY_SIZE(gen7_0_0_pwrup_reglist); 706: } else { 707: reglist[items].regs = gen7_pwrup_reglist; 708: reglist[items].count = ARRAY_SIZE(gen7_pwrup_reglist); 709: } 710: lock->preemption_list_len = reglist[items].count; 711: items++; 712: 713: /* 714: * For each entry in each of the lists, write the offset and the current 715: * register value into the GPU buffer 716: */ 717: for (i = 0; i < items; i++) { 718: const u32 *r = reglist[i].regs; 719: 720: for (j = 0; j < reglist[i].count; j++) { 721: *dest++ = r[j]; 722: kgsl_regread(device, r[j], dest++); 723: } 724: 725: if ((r == gen7_ifpc_pwrup_reglist) || (r == gen7_0_0_ifpc_pwrup_reglist)) { 726: u32 cs_len = adreno_coresight_patch_pwrup_reglist(adreno_dev, dest); 727: 728: lock->ifpc_list_len += cs_len; 729: dest += (cs_len * 2); 730: } 731: } 732: 733: /* 734: * The overall register list is composed of 735: * 1. Static IFPC restore only registers 736: * 2. Static IFPC + preemption registers 737: * 3. Dynamic IFPC + preemption registers (ex: perfcounter selects) 738: * 739: * The first two lists are static. Size of these lists are stored as 740: * number of pairs in ifpc_list_len and preemption_list_len 741: * respectively. With concurrent binning, Some of the perfcounter 742: * registers being virtualized, CP needs to know the pipe id to program 743: * the aperture inorder to restore the same. Thus, third list is a 744: * dynamic list with triplets as 745: * (
), and the length is 746: * stored as number for triplets in dynamic_list_len. 747: * 748: * Starting with Gen7, some of the registers that are initialized statically 749: * by the kernel are pipe-specific. Because only the dynamic list is able to 750: * support specifying a pipe ID, these registers are bundled along with any 751: * dynamic entries such as perf counter selects into a single dynamic list. 752: */ 753: gen7_dev->ext_pwrup_list_len = 0; 754: 755: /* 756: * Write external pipe specific regs (
- triplets) 757: * offset and the current value into GPU buffer 758: */ 759: if (adreno_is_gen7_no_cb_family(adreno_dev)) { 760: lock->dynamic_list_len = 0; 761: return; 762: } 763: 764: for (pipe_id = PIPE_BR; pipe_id <= PIPE_BV; pipe_id++) { MATCH LINES: 1008, 1009, 1010 996: } 997: 998: kgsl_regwrite(device, GEN7_UCHE_MODE_CNTL, 999: ((mal == 64) ? BIT(23) : 0) | 1000: FIELD_PREP(GENMASK(22, 21), hbb_lo)); 1001: 1002: kgsl_regwrite(device, GEN7_RBBM_INTERFACE_HANG_INT_CNTL, BIT(30) | 1003: FIELD_PREP(GENMASK(27, 0), 1004: gen7_core->hang_detect_cycles)); 1005: kgsl_regwrite(device, GEN7_UCHE_CLIENT_PF, BIT(7) | 1006: FIELD_PREP(GENMASK(3, 0), adreno_dev->uche_client_pf)); 1007: 1008: /* Enable the GMEM save/restore feature for preemption */ 1009: if (adreno_is_preemption_enabled(adreno_dev)) 1010: kgsl_regwrite(device, GEN7_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, 1011: 0x1); 1012: 1013: if (adreno_is_gen7_9_x(adreno_dev)) { 1014: /* Disable ubwc merged UFC request feature */ 1015: kgsl_regrmw(device, GEN7_RB_CMP_DBG_ECO_CNTL, BIT(19), BIT(19)); 1016: 1017: /* Enable TP flaghint and other performance settings */ 1018: kgsl_regwrite(device, GEN7_TPL1_DBG_ECO_CNTL1, 0xc0700); 1019: } else { 1020: /* Disable non-ubwc read reqs from passing write reqs */ 1021: if (!adreno_is_gen7_15_0(adreno_dev) && !adreno_is_gen7_11_0(adreno_dev)) 1022: kgsl_regrmw(device, GEN7_RB_CMP_DBG_ECO_CNTL, BIT(11), BIT(11)); 1023: } 1024: 1025: /* Enable GMU power counter 0 to count GPU busy */ 1026: kgsl_regwrite(device, GEN7_GPU_GMU_AO_GPU_CX_BUSY_MASK, 0xff000000); 1027: kgsl_regrmw(device, GEN7_GMU_CX_GMU_POWER_COUNTER_SELECT_0, 1028: 0xFF, 0x20); 1029: kgsl_regwrite(device, GEN7_GMU_CX_GMU_POWER_COUNTER_ENABLE, 0x1); 1030: 1031: gen7_protect_init(adreno_dev); 1032: 1033: /* Configure LLCC */ 1034: _llc_configure_gpu_scid(adreno_dev); MATCH LINES: 1199, 1204, 1208, 1213, 1220, 1222, 1223, 1224, 1227, 1228, 1229, 1232, 1237, 1240, 1244, 1252, 1278, 1281 1187: rb->_wptr = 0; 1188: } 1189: } 1190: 1191: return ret; 1192: } 1193: 1194: static int gen7_post_start(struct adreno_device *adreno_dev) 1195: { 1196: int ret; 1197: unsigned int *cmds; 1198: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1199: struct adreno_preemption *preempt = &adreno_dev->preempt; 1200: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1201: u64 kmd_postamble_addr; 1202: u32 count = 9; 1203: 1204: if (!adreno_is_preemption_enabled(adreno_dev)) 1205: return 0; 1206: 1207: kmd_postamble_addr = SCRATCH_POSTAMBLE_ADDR(KGSL_DEVICE(adreno_dev)); 1208: gen7_preemption_prepare_postamble(adreno_dev); 1209: 1210: if (kgsl_mmu_is_secured(&device->mmu)) 1211: count += 3; 1212: 1213: if (preempt->postamble_bootup_len) 1214: count += 4; 1215: 1216: cmds = adreno_ringbuffer_allocspace(rb, count); 1217: if (IS_ERR(cmds)) 1218: return PTR_ERR(cmds); 1219: 1220: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 1221: kgsl_mmu_is_secured(&device->mmu) ? 6 : 3); 1222: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 1223: *cmds++ = lower_32_bits(rb->preemption_desc->gpuaddr); 1224: *cmds++ = upper_32_bits(rb->preemption_desc->gpuaddr); 1225: 1226: if (kgsl_mmu_is_secured(&device->mmu)) { 1227: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 1228: *cmds++ = lower_32_bits(rb->secure_preemption_desc->gpuaddr); 1229: *cmds++ = upper_32_bits(rb->secure_preemption_desc->gpuaddr); 1230: } 1231: 1232: if (preempt->postamble_bootup_len) { 1233: *cmds++ = cp_type7_packet(CP_SET_AMBLE, 3); 1234: *cmds++ = lower_32_bits(kmd_postamble_addr); 1235: *cmds++ = upper_32_bits(kmd_postamble_addr); 1236: *cmds++ = FIELD_PREP(GENMASK(22, 20), CP_KMD_AMBLE_TYPE) 1237: | (FIELD_PREP(GENMASK(19, 0), adreno_dev->preempt.postamble_bootup_len)); 1238: } 1239: 1240: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1241: *cmds++ = 0; 1242: *cmds++ = 0; 1243: *cmds++ = 0; 1244: /* generate interrupt on preemption completion */ 1245: *cmds++ = 0; 1246: 1247: ret = gen7_ringbuffer_submit(rb, NULL); 1248: if (!ret) { 1249: ret = adreno_spin_idle(adreno_dev, 2000); 1250: if (ret) 1251: gen7_spin_idle_debug(adreno_dev, 1252: "hw preemption initialization failed to idle\n"); 1253: } 1254: 1255: return ret; 1256: } 1257: 1258: int gen7_rb_start(struct adreno_device *adreno_dev) 1259: { 1260: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 1261: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 1262: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1263: struct adreno_ringbuffer *rb; 1264: u64 addr; 1265: int ret, i; 1266: unsigned int *cmds; 1267: 1268: /* Clear all the ringbuffers */ 1269: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1270: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 1271: kgsl_sharedmem_writel(device->scratch, 1272: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1273: kgsl_sharedmem_writel(device->scratch, 1274: SCRATCH_RB_OFFSET(rb->id, bv_rptr), 0); 1275: 1276: rb->wptr = 0; 1277: rb->_wptr = 0; 1278: rb->wptr_preempt_end = UINT_MAX; 1279: } 1280: 1281: gen7_preemption_start(adreno_dev); 1282: 1283: /* Set up the current ringbuffer */ 1284: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 1285: 1286: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 1287: kgsl_regwrite(device, GEN7_CP_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1288: kgsl_regwrite(device, GEN7_CP_RB_RPTR_ADDR_HI, upper_32_bits(addr)); 1289: 1290: /* Skip this regwrite for Gen7 targets that do not have BV */ 1291: if (!adreno_is_gen7_no_cb_family(adreno_dev)) { 1292: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, bv_rptr); 1293: kgsl_regwrite(device, GEN7_CP_BV_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1294: kgsl_regwrite(device, GEN7_CP_BV_RB_RPTR_ADDR_HI, upper_32_bits(addr)); 1295: } 1296: 1297: kgsl_regwrite(device, GEN7_CP_RB_CNTL, GEN7_CP_RB_CNTL_DEFAULT); 1298: 1299: kgsl_regwrite(device, GEN7_CP_RB_BASE, 1300: lower_32_bits(rb->buffer_desc->gpuaddr)); 1301: kgsl_regwrite(device, GEN7_CP_RB_BASE_HI, 1302: upper_32_bits(rb->buffer_desc->gpuaddr)); 1303: 1304: /* Program the ucode base for CP */ 1305: kgsl_regwrite(device, GEN7_CP_SQE_INSTR_BASE_LO, MATCH LINES: 1631, 1632 1619: case 0x7: 1620: return "GMU"; 1621: case 0x8: 1622: return gen7_fault_block_uche(device, str, sizeof(str), true); 1623: } 1624: 1625: snprintf(str, sizeof(str), "Unknown (mid: %u)", mid); 1626: return str; 1627: } 1628: 1629: static void gen7_cp_callback(struct adreno_device *adreno_dev, int bit) 1630: { 1631: if (adreno_is_preemption_enabled(adreno_dev)) 1632: gen7_preemption_trigger(adreno_dev, true); 1633: 1634: adreno_scheduler_queue(adreno_dev); 1635: } 1636: 1637: /* 1638: * gen7_gpc_err_int_callback() - Isr for GPC error interrupts 1639: * @adreno_dev: Pointer to device 1640: * @bit: Interrupt bit 1641: */ 1642: static void gen7_gpc_err_int_callback(struct adreno_device *adreno_dev, int bit) 1643: { 1644: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1645: 1646: /* 1647: * GPC error is typically the result of mistake SW programming. 1648: * Force GPU fault for this interrupt so that we can debug it 1649: * with help of register dump. 1650: */ 1651: 1652: dev_crit(device->dev, "RBBM: GPC error\n"); 1653: adreno_irqctrl(adreno_dev, 0); 1654: 1655: /* Trigger a fault in the dispatcher - this will effect a restart */ 1656: adreno_scheduler_fault(adreno_dev, ADRENO_SOFT_FAULT); MATCH LINES: 1705 1693: } 1694: } 1695: 1696: static const struct adreno_irq_funcs gen7_irq_funcs[32] = { 1697: ADRENO_IRQ_CALLBACK(NULL), /* 0 - RBBM_GPU_IDLE */ 1698: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 1 - RBBM_AHB_ERROR */ 1699: ADRENO_IRQ_CALLBACK(NULL), /* 2 - UNUSED */ 1700: ADRENO_IRQ_CALLBACK(NULL), /* 3 - UNUSED */ 1701: ADRENO_IRQ_CALLBACK(NULL), /* 4 - CPIPCINT0 */ 1702: ADRENO_IRQ_CALLBACK(NULL), /* 5 - CPIPCINT1 */ 1703: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 6 - ATBASYNCOVERFLOW */ 1704: ADRENO_IRQ_CALLBACK(gen7_gpc_err_int_callback), /* 7 - GPC_ERR */ 1705: ADRENO_IRQ_CALLBACK(gen7_preemption_callback),/* 8 - CP_SW */ 1706: ADRENO_IRQ_CALLBACK(gen7_cp_hw_err_callback), /* 9 - CP_HW_ERROR */ 1707: ADRENO_IRQ_CALLBACK(NULL), /* 10 - CP_CCU_FLUSH_DEPTH_TS */ 1708: ADRENO_IRQ_CALLBACK(NULL), /* 11 - CP_CCU_FLUSH_COLOR_TS */ 1709: ADRENO_IRQ_CALLBACK(NULL), /* 12 - CP_CCU_RESOLVE_TS */ 1710: ADRENO_IRQ_CALLBACK(NULL), /* 13 - UNUSED */ 1711: ADRENO_IRQ_CALLBACK(NULL), /* 14 - UNUSED */ 1712: ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 15 - CP_RB_INT */ 1713: ADRENO_IRQ_CALLBACK(NULL), /* 16 - CP_RB_INT_LPAC*/ 1714: ADRENO_IRQ_CALLBACK(NULL), /* 17 - CP_RB_DONE_TS */ 1715: ADRENO_IRQ_CALLBACK(NULL), /* 18 - UNUSED */ 1716: ADRENO_IRQ_CALLBACK(NULL), /* 19 - UNUSED */ 1717: ADRENO_IRQ_CALLBACK(gen7_cp_callback), /* 20 - CP_CACHE_FLUSH_TS */ 1718: ADRENO_IRQ_CALLBACK(NULL), /* 21 - CP_CACHE_TS_LPAC */ 1719: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 22 - RBBM_ATB_BUS_OVERFLOW */ 1720: ADRENO_IRQ_CALLBACK(adreno_hang_int_callback), /* 23 - MISHANGDETECT */ 1721: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 24 - UCHE_OOB_ACCESS */ 1722: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 25 - UCHE_TRAP_INTR */ 1723: ADRENO_IRQ_CALLBACK(NULL), /* 26 - DEBBUS_INTR_0 */ 1724: ADRENO_IRQ_CALLBACK(NULL), /* 27 - DEBBUS_INTR_1 */ 1725: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 28 - TSBWRITEERROR */ 1726: ADRENO_IRQ_CALLBACK(gen7_swfuse_violation_callback), /* 29 - SWFUSEVIOLATION */ 1727: ADRENO_IRQ_CALLBACK(NULL), /* 30 - ISDB_CPU_IRQ */ 1728: ADRENO_IRQ_CALLBACK(NULL), /* 31 - ISDB_UNDER_DEBUG */ 1729: }; MATCH LINES: 1873, 1879, 1880, 1881, 1882 1861: pwr->cx_cfg_gdsc_offset = GEN7_11_0_GPU_CC_CX_CFG_GDSCR; 1862: else if (adreno_is_gen7_17_0(adreno_dev)) 1863: pwr->cx_cfg_gdsc_offset = GEN7_17_0_GPU_CC_CX_CFG_GDSCR; 1864: else if (adreno_is_gen7_13_0(adreno_dev)) 1865: pwr->cx_cfg_gdsc_offset = GEN7_13_0_GPU_CC_CX_CFG_GDSCR; 1866: else 1867: pwr->cx_cfg_gdsc_offset = GEN7_GPU_CC_CX_CFG_GDSCR; 1868: 1869: ret = adreno_device_probe(pdev, adreno_dev); 1870: if (ret) 1871: return ret; 1872: 1873: if (adreno_preemption_feature_set(adreno_dev)) { 1874: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 1875: 1876: adreno_dev->total_ctxt_record_sz = gen7_core->ctxt_record_size ? 1877: gen7_core->ctxt_record_size : GEN7_CP_CTXRECORD_SIZE_IN_BYTES; 1878: 1879: adreno_dev->preempt.preempt_level = gen7_core->preempt_level; 1880: adreno_dev->preempt.skipsaverestore = true; 1881: adreno_dev->preempt.usesgmem = true; 1882: set_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 1883: } 1884: 1885: /* debugfs node for ACD calibration */ 1886: debugfs_create_file("acd_calibrate", 0644, device->d_debugfs, device, &acd_cal_fops); 1887: 1888: gen7_coresight_init(adreno_dev); 1889: 1890: /* Dump additional AQE 16KB data on top of default 96KB(48(BR)+48(BV)) */ 1891: device->snapshot_ctxt_record_size = ADRENO_FEATURE(adreno_dev, ADRENO_AQE) ? 1892: 112 * SZ_1K : 96 * SZ_1K; 1893: 1894: return 0; 1895: } 1896: 1897: /* Register offset defines for Gen7, in order of enum adreno_regs */ 1898: static unsigned int gen7_register_offsets[ADRENO_REG_REGISTER_MAX] = { 1899: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_BASE, GEN7_CP_RB_BASE), 1900: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_BASE_HI, GEN7_CP_RB_BASE_HI), 1901: ADRENO_REG_DEFINE(ADRENO_REG_CP_LPAC_RB_BASE, GEN7_CP_LPAC_RB_BASE), 1902: ADRENO_REG_DEFINE(ADRENO_REG_CP_LPAC_RB_BASE_HI, GEN7_CP_LPAC_RB_BASE_HI), 1903: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_RPTR, GEN7_CP_RB_RPTR), 1904: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_WPTR, GEN7_CP_RB_WPTR), 1905: ADRENO_REG_DEFINE(ADRENO_REG_CP_ME_CNTL, GEN7_CP_SQE_CNTL), 1906: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BASE, GEN7_CP_IB1_BASE), MATCH LINES: 1964 1952: } 1953: } 1954: 1955: int gen7_perfcounter_remove(struct adreno_device *adreno_dev, 1956: struct adreno_perfcount_register *reg, u32 groupid) 1957: { 1958: const struct adreno_perfcounters *counters = ADRENO_PERFCOUNTERS(adreno_dev); 1959: struct gen7_device *gen7_dev = container_of(adreno_dev, struct gen7_device, adreno_dev); 1960: const struct adreno_perfcount_group *group; 1961: void *ptr = adreno_dev->pwrup_reglist->hostptr; 1962: struct cpu_gpu_lock *lock = ptr; 1963: bool remove_counter = false; 1964: u32 offset = ((lock->ifpc_list_len + lock->preemption_list_len) * 2) + 1965: (gen7_dev->ext_pwrup_list_len * 3); 1966: int i, last_offset, second_last_offset; 1967: u32 *data = ptr + sizeof(*lock), pipe = FIELD_PREP(GENMASK(13, 12), _get_pipeid(groupid)); 1968: u16 perfcntr_list_len = lock->dynamic_list_len - gen7_dev->ext_pwrup_list_len; 1969: 1970: if (!perfcntr_list_len) 1971: return -EINVAL; 1972: 1973: group = &(counters->groups[groupid]); 1974: 1975: if (!(group->flags & ADRENO_PERFCOUNTER_GROUP_RESTORE)) { 1976: if (perfcntr_list_len != 1) 1977: return 0; 1978: 1979: if (kgsl_hwlock(lock)) { 1980: kgsl_hwunlock(lock); 1981: return -EBUSY; 1982: } 1983: goto disable_perfcounter; 1984: } 1985: 1986: second_last_offset = offset + (lock->dynamic_list_len - 2) * 3; 1987: last_offset = second_last_offset + 3; 1988: MATCH LINES: 2079 2067: 2068: static void gen7_release_cp_semaphore(struct adreno_device *adreno_dev) 2069: { 2070: kgsl_regwrite(KGSL_DEVICE(adreno_dev), GEN7_CP_SEMAPHORE_REG_0, 0); 2071: } 2072: 2073: int gen7_perfcounter_update(struct adreno_device *adreno_dev, 2074: struct adreno_perfcount_register *reg, bool update_reg, u32 pipe, unsigned long flags) 2075: { 2076: struct gen7_device *gen7_dev = container_of(adreno_dev, struct gen7_device, adreno_dev); 2077: void *ptr = adreno_dev->pwrup_reglist->hostptr; 2078: struct cpu_gpu_lock *lock = ptr; 2079: u32 offset = ((lock->ifpc_list_len + lock->preemption_list_len) * 2) + 2080: (gen7_dev->ext_pwrup_list_len * 3); 2081: u32 *data = ptr + sizeof(*lock); 2082: u64 reglist_size_dwords = adreno_dev->pwrup_reglist->size / sizeof(u32); 2083: u64 lock_size_dwords = sizeof(*lock) / sizeof(u32); 2084: int i; 2085: u16 perfcntr_list_len = lock->dynamic_list_len - gen7_dev->ext_pwrup_list_len; 2086: bool select_reg_present = false; 2087: unsigned long irq_flags; 2088: int ret = 0; 2089: u32 pending_triplets = 1; 2090: 2091: if (!ADRENO_ACQUIRE_CP_SEMAPHORE(adreno_dev, irq_flags)) 2092: return -EBUSY; 2093: 2094: if (flags & ADRENO_PERFCOUNTER_GROUP_RESTORE) { 2095: /* No of triplet to add if restoring: 1 main + 1 control otherwise: 1 control */ 2096: pending_triplets++; 2097: for (i = 0; i < perfcntr_list_len; i++) { 2098: if ((data[offset + 1] == reg->select) && (data[offset] == pipe)) { 2099: select_reg_present = true; 2100: break; 2101: } 2102: 2103: if (data[offset + 1] == GEN7_RBBM_PERFCTR_CNTL) MATCH LINES: 2241, 2243 2229: return 0; 2230: 2231: /* Power down the GPU before changing the lpac setting */ 2232: return adreno_power_cycle_bool(adreno_dev, &adreno_dev->lpac_enabled, 2233: enable); 2234: } 2235: 2236: static void gen7_remove(struct adreno_device *adreno_dev) 2237: { 2238: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2239: 2240: /* Make sure timer is initialized, otherwise WARN_ON is generated */ 2241: if (adreno_preemption_feature_set(adreno_dev) && 2242: (test_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags))) 2243: kgsl_delete_timer(&adreno_dev->preempt.timer); 2244: } 2245: 2246: static void gen7_read_bus_stats(struct kgsl_device *device, 2247: struct kgsl_power_stats *stats, 2248: struct adreno_busy_data *busy) 2249: { 2250: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 2251: u64 ram_cycles, starved_ram; 2252: 2253: ram_cycles = counter_delta(device, adreno_dev->ram_cycles_lo, 2254: &busy->bif_ram_cycles); 2255: 2256: starved_ram = counter_delta(device, adreno_dev->starved_ram_lo, 2257: &busy->bif_starved_ram); 2258: 2259: ram_cycles += counter_delta(device, 2260: adreno_dev->ram_cycles_lo_ch1_read, 2261: &busy->bif_ram_cycles_read_ch1); 2262: 2263: ram_cycles += counter_delta(device, 2264: adreno_dev->ram_cycles_lo_ch0_write, 2265: &busy->bif_ram_cycles_write_ch0); 2266: 2267: ram_cycles += counter_delta(device, MATCH LINES: 2574 2562: 2563: const struct gen7_gpudev adreno_gen7_gmu_gpudev = { 2564: .base = { 2565: .reg_offsets = gen7_register_offsets, 2566: .probe = gen7_gmu_device_probe, 2567: .snapshot = gen7_gmu_snapshot, 2568: .irq_handler = gen7_irq_handler, 2569: .rb_start = gen7_rb_start, 2570: .gpu_keepalive = gen7_gpu_keepalive, 2571: .hw_isidle = gen7_hw_isidle, 2572: .iommu_fault_block = gen7_iommu_fault_block, 2573: .reset = gen7_gmu_reset, 2574: .preemption_schedule = gen7_preemption_schedule, 2575: .read_alwayson = gen7_read_alwayson, 2576: .power_ops = &gen7_gmu_power_ops, 2577: .remove = gen7_remove, 2578: .ringbuffer_submitcmd = gen7_ringbuffer_submitcmd, 2579: .power_stats = gen7_power_stats, 2580: .add_to_va_minidump = gen7_gmu_add_to_minidump, 2581: .gx_is_on = gen7_gmu_gx_is_on, 2582: .perfcounter_remove = gen7_perfcounter_remove, 2583: .set_isdb_breakpoint_registers = gen7_set_isdb_breakpoint_registers, 2584: .swfuse_irqctrl = gen7_swfuse_irqctrl, 2585: .get_uche_trap_base = gen7_get_uche_trap_base, 2586: .fault_header = gen7_fault_header, 2587: .acquire_cp_semaphore = gen7_acquire_cp_semaphore, 2588: .release_cp_semaphore = gen7_release_cp_semaphore, 2589: }, 2590: .hfi_probe = gen7_gmu_hfi_probe, 2591: .handle_watchdog = gen7_gmu_handle_watchdog, 2592: }; --- FILE: \adreno_gen7.h | HITS: 23 --- MATCH LINES: 117, 129, 130, 155, 156, 162, 171, 174, 190, 211 105: /** @ao_hwcg: List of registers and values to write for HWCG in AO block */ 106: const struct kgsl_regmap_list *ao_hwcg; 107: /** @ao_hwcg_count: Number of registers in @ao_hwcg */ 108: u32 ao_hwcg_count; 109: /** @gbif: List of registers and values to write for GBIF */ 110: const struct kgsl_regmap_list *gbif; 111: /** @gbif_count: Number of registers in @gbif */ 112: u32 gbif_count; 113: /** @hang_detect_cycles: Hang detect counter timeout value */ 114: u32 hang_detect_cycles; 115: /** @protected_regs: Array of protected registers for the target */ 116: const struct gen7_protected_regs *protected_regs; 117: /** @ctxt_record_size: Size of the preemption record in bytes */ 118: u64 ctxt_record_size; 119: /** @gen7_snapshot_block_list: Device-specific blocks dumped in the snapshot */ 120: const struct gen7_snapshot_block_list *gen7_snapshot_block_list; 121: /** @gmu_hub_clk_freq: Gmu hub interface clock frequency */ 122: u64 gmu_hub_clk_freq; 123: /** 124: * @bcl_data: bit 0 contains response type for bcl alarms and bits 1:21 controls sid vals 125: * to configure throttle levels for bcl alarm levels 0-2. If sid vals are not set, 126: * gmu fw sets default throttle levels. 127: */ 128: u32 bcl_data; 129: /** @preempt_level: Preemption level valid ranges [0 to 2] */ 130: u32 preempt_level; 131: /** @qos_value: GPU qos value to set for each RB. */ 132: const u32 *qos_value; 133: /** 134: * @acv_perfmode_ddr_freq: Vote perfmode when DDR frequency >= acv_perfmode_ddr_freq. 135: * If not specified, vote perfmode for highest DDR level only. 136: */ 137: u32 acv_perfmode_ddr_freq; 138: /** @acv_perfmode_vote: ACV vote for GPU perfmode */ 139: u32 acv_perfmode_vote; 140: /** @rt_bus_hint: IB level hint for real time clients i.e. RB-0 */ 141: const u32 rt_bus_hint; 142: /** @fast_bus_hint: Whether or not to increase IB vote on high ddr stall */ 143: bool fast_bus_hint; 144: /** @noc_timeout_us: GPU config NOC port timeout in usec */ 145: u32 noc_timeout_us; 146: /** 147: * @gmu_chipid: If non-zero, the exact value programmed into 148: * GEN7_GMU_GENERAL_10 to tell the GMU firmware which chip it is 149: * running on. 150: */ 151: u32 gmu_chipid; 152: }; 153: 154: /** 155: * struct gen7_cp_preemption_record - CP context record for 156: * preemption. 157: * @magic: (00) Value at this offset must be equal to 158: * GEN7_CP_CTXRECORD_MAGIC_REF. 159: * @info: (04) Type of record. Written non-zero (usually) by CP. 160: * we must set to zero for all ringbuffers. 161: * @errno: (08) Error code. Initialize this to GEN7_CP_CTXRECORD_ERROR_NONE. 162: * CP will update to another value if a preemption error occurs. 163: * @data: (12) DATA field in YIELD and SET_MARKER packets. 164: * Written by CP when switching out. Not used on switch-in. Initialized to 0. 165: * @cntl: (16) RB_CNTL, saved and restored by CP. We must initialize this. 166: * @rptr: (20) RB_RPTR, saved and restored by CP. We must initialize this. 167: * @wptr: (24) RB_WPTR, saved and restored by CP. We must initialize this. 168: * @_pad28: (28) Reserved/padding. 169: * @rptr_addr: (32) RB_RPTR_ADDR_LO|HI saved and restored. We must initialize. 170: * rbase: (40) RB_BASE_LO|HI saved and restored. 171: * counter: (48) Pointer to preemption counter. 172: * @bv_rptr_addr: (56) BV_RB_RPTR_ADDR_LO|HI save and restored. We must initialize. 173: */ 174: struct gen7_cp_preemption_record { 175: u32 magic; 176: u32 info; 177: u32 errno; 178: u32 data; 179: u32 cntl; 180: u32 rptr; 181: u32 wptr; 182: u32 _pad28; 183: u64 rptr_addr; 184: u64 rbase; 185: u64 counter; 186: u64 bv_rptr_addr; 187: }; 188: 189: /** 190: * struct gen7_cp_smmu_info - CP preemption SMMU info. 191: * @magic: (00) The value at this offset must be equal to 192: * GEN7_CP_SMMU_INFO_MAGIC_REF 193: * @_pad4: (04) Reserved/padding 194: * @ttbr0: (08) Base address of the page table for the * incoming context 195: * @asid: (16) Address Space IDentifier (ASID) of the incoming context 196: * @context_idr: (20) Context Identification Register value 197: * @context_bank: (24) Which Context Bank in SMMU to update 198: */ 199: struct gen7_cp_smmu_info { 200: u32 magic; 201: u32 _pad4; 202: u64 ttbr0; 203: u32 asid; 204: u32 context_idr; 205: u32 context_bank; 206: }; 207: 208: #define GEN7_CP_SMMU_INFO_MAGIC_REF 0x241350d5UL 209: 210: #define GEN7_CP_CTXRECORD_MAGIC_REF 0xae399d6eUL 211: /* Size of each CP preemption record */ 212: #define GEN7_CP_CTXRECORD_SIZE_IN_BYTES (4192 * 1024) 213: /* Size of the performance counter save/restore block (in bytes) */ 214: #define GEN7_CP_PERFCOUNTER_SAVE_RESTORE_SIZE (4 * 1024) 215: 216: #define GEN7_CP_RB_CNTL_DEFAULT \ 217: (FIELD_PREP(GENMASK(7, 0), ilog2(KGSL_RB_DWORDS >> 1)) | \ 218: FIELD_PREP(GENMASK(12, 8), ilog2(4))) 219: 220: /* Size of the CP_INIT pm4 stream in dwords */ 221: #define GEN7_CP_INIT_DWORDS 10 222: 223: #define GEN7_INT_MASK \ 224: ((1 << GEN7_INT_AHBERROR) | \ 225: (1 << GEN7_INT_ATBASYNCFIFOOVERFLOW) | \ 226: (1 << GEN7_INT_GPCERROR) | \ 227: (1 << GEN7_INT_SWINTERRUPT) | \ 228: (1 << GEN7_INT_HWERROR) | \ 229: (1 << GEN7_INT_PM4CPINTERRUPT) | \ 230: (1 << GEN7_INT_RB_DONE_TS) | \ 231: (1 << GEN7_INT_CACHE_CLEAN_TS) | \ 232: (1 << GEN7_INT_ATBBUSOVERFLOW) | \ 233: (1 << GEN7_INT_HANGDETECTINTERRUPT) | \ 234: (1 << GEN7_INT_OUTOFBOUNDACCESS) | \ 235: (1 << GEN7_INT_UCHETRAPINTERRUPT) | \ MATCH LINES: 262, 263, 264, 265, 266, 268, 270, 274, 276, 278 250: * 251: * Returns: 252: * A pointer to the gen7 specific GPU core struct 253: */ 254: static inline const struct adreno_gen7_core * 255: to_gen7_core(struct adreno_device *adreno_dev) 256: { 257: const struct adreno_gpu_core *core = adreno_dev->gpucore; 258: 259: return container_of(core, struct adreno_gen7_core, base); 260: } 261: 262: /* Preemption functions */ 263: void gen7_preemption_trigger(struct adreno_device *adreno_dev, bool atomic); 264: void gen7_preemption_schedule(struct adreno_device *adreno_dev); 265: void gen7_preemption_start(struct adreno_device *adreno_dev); 266: int gen7_preemption_init(struct adreno_device *adreno_dev); 267: 268: u32 gen7_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 269: unsigned int *cmds); 270: u32 gen7_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 271: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 272: u32 *cmds); 273: 274: void gen7_preemption_callback(struct adreno_device *adreno_dev, int bit); 275: 276: void gen7_preemption_context_destroy(struct kgsl_context *context); 277: 278: void gen7_preemption_prepare_postamble(struct adreno_device *adreno_dev); 279: 280: void gen7_snapshot(struct adreno_device *adreno_dev, 281: struct kgsl_snapshot *snapshot); 282: void gen7_crashdump_init(struct adreno_device *adreno_dev); 283: 284: /** 285: * gen7_snapshot_external_core_regs - Dump external registers into snapshot 286: * @device: Pointer to KGSL device 287: * @snapshot: Pointer to the snapshot 288: * 289: * Dump external core registers like GPUCC, CPR into GPU snapshot. 290: */ 291: void gen7_snapshot_external_core_regs(struct kgsl_device *device, 292: struct kgsl_snapshot *snapshot); 293: 294: /** 295: * gen7_start - Program gen7 registers 296: * @adreno_dev: An Adreno GPU handle 297: * 298: * This function does all gen7 register programming every 299: * time we boot the gpu 300: * 301: * Return: 0 on success or negative on failure 302: */ MATCH LINES: 477, 480, 482 465: * 466: * Return: 0 on success or negative on failure 467: */ 468: int gen7_gmu_hfi_probe(struct adreno_device *adreno_dev); 469: 470: static inline const struct gen7_gpudev * 471: to_gen7_gpudev(const struct adreno_gpudev *gpudev) 472: { 473: return container_of(gpudev, struct gen7_gpudev, base); 474: } 475: 476: /** 477: * gen7_reset_preempt_records - Reset the preemption buffers 478: * @adreno_dev: Handle to the adreno device 479: * 480: * Reset the preemption records at the time of hard reset 481: */ 482: void gen7_reset_preempt_records(struct adreno_device *adreno_dev); 483: 484: /** 485: * gen7_enable_ahb_timeout_detection - Program AHB control registers 486: * @adreno_dev: An Adreno GPU handle 487: * 488: * Program AHB control registers to enable AHB timeout detection. 489: */ 490: void gen7_enable_ahb_timeout_detection(struct adreno_device *adreno_dev); 491: 492: /** 493: * gen7_scm_gpu_init_cx_regs - Program gpu regs for feature support 494: * @adreno_dev: Handle to the adreno device 495: * 496: * Program gpu regs for feature support. Scm call for the same 497: * is added from kernel version 6.0 onwards. 498: * 499: * Return: 0 on success or negative on failure 500: */ 501: int gen7_scm_gpu_init_cx_regs(struct adreno_device *adreno_dev); 502: 503: /** 504: * gen7_host_aperture_set - Program CP aperture register 505: * @adreno_dev: Handle to the adreno device 506: * @pipe_id: Pipe for which the register is to be set --- FILE: \adreno_gen7_gmu.c | HITS: 6 --- MATCH LINES: 837, 841 825: dev_err(gmu_pdev_dev, 826: "Poll: %llx (ticks relative to start)\n", ts2-ts1); 827: dev_err(gmu_pdev_dev, 828: "RPMH_POWER_STATE=%x GFX_PWR_CLK_STATUS=%x\n", reg, reg1); 829: dev_err(gmu_pdev_dev, "CX_BUSY_STATUS=%x\n", reg2); 830: dev_err(gmu_pdev_dev, 831: "RBBM_INT_UNMASKED_STATUS=%x PWR_COL_KEEPALIVE=%x\n", reg3, reg4); 832: 833: /* Access GX registers only when GX is ON */ 834: if (is_on(reg1)) { 835: kgsl_regread(device, GEN7_CP_STATUS_1, ®2); 836: kgsl_regread(device, GEN7_CP_CP2GMU_STATUS, ®3); 837: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_CNTL, ®4); 838: 839: dev_err(gmu_pdev_dev, "GEN7_CP_STATUS_1=%x\n", reg2); 840: dev_err(gmu_pdev_dev, 841: "CP2GMU_STATUS=%x CONTEXT_SWITCH_CNTL=%x\n", reg3, reg4); 842: } 843: 844: WARN_ON(1); 845: gmu_core_fault_snapshot(device, GMU_FAULT_WAIT_FOR_LOWEST_IDLE); 846: return -ETIMEDOUT; 847: } 848: 849: /* Bitmask for GPU idle status check */ 850: #define CXGXCPUBUSYIGNAHB BIT(30) 851: int gen7_gmu_wait_for_idle(struct adreno_device *adreno_dev) 852: { 853: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 854: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 855: u32 status2; 856: u64 ts1; 857: 858: ts1 = gpudev->read_alwayson(adreno_dev); 859: if (gmu_core_timed_poll_check(device, GEN7_GPU_GMU_AO_GPU_CX_BUSY_STATUS, 860: 0, 100, CXGXCPUBUSYIGNAHB)) { 861: gmu_core_regread(device, 862: GEN7_GPU_GMU_AO_GPU_CX_BUSY_STATUS2, &status2); 863: dev_err(GMU_PDEV_DEV(device), 864: "GMU not idling: status2=0x%x %llx %llx\n", 865: status2, ts1, MATCH LINES: 948 936: gmu_core_regwrite(device, GEN7_GPU_GMU_CX_GMU_CX_FAL_INTF, 0x1); 937: 938: /* Clear init result to make sure we are getting fresh value */ 939: gmu_core_regwrite(device, GEN7_GMU_CM3_FW_INIT_RESULT, 0); 940: gmu_core_regwrite(device, GEN7_GMU_CM3_BOOT_CONFIG, 0x2); 941: 942: gmu_core_regwrite(device, GEN7_GMU_HFI_QTBL_ADDR, 943: gmu->hfi.hfi_mem->gmuaddr); 944: gmu_core_regwrite(device, GEN7_GMU_HFI_QTBL_INFO, 1); 945: 946: gmu_core_regwrite(device, GEN7_GMU_AHB_FENCE_RANGE_0, BIT(31) | 947: FIELD_PREP(GENMASK(30, 18), 0x32) | 948: FIELD_PREP(GENMASK(17, 0), GEN7_CP_CONTEXT_SWITCH_CNTL)); 949: 950: /* 951: * Make sure that CM3 state is at reset value. Snapshot is changing 952: * NMI bit and if we boot up GMU with NMI bit set GMU will boot 953: * straight in to NMI handler without executing __main code 954: */ 955: gmu_core_regwrite(device, GEN7_GMU_CM3_CFG, 0x4052); 956: 957: /* Set up GBIF registers from the GPU core definition */ 958: kgsl_regmap_multi_write(&device->regmap, gen7_core->gbif, 959: gen7_core->gbif_count); 960: 961: if (adreno_is_gen7_13_0(adreno_dev) || adreno_is_gen7_9_x(adreno_dev)) 962: kgsl_regrmw(device, GEN7_GBIF_CX_CONFIG, GENMASK(31, 29), 963: FIELD_PREP(GENMASK(31, 29), 1)); 964: else if (adreno_is_gen7_14_0_family(adreno_dev)) 965: kgsl_regrmw(device, GEN7_GBIF_CX_CONFIG, GENMASK(31, 29), 966: FIELD_PREP(GENMASK(31, 29), 2)); 967: 968: /** 969: * We may have asserted gbif halt as part of reset sequence which may 970: * not get cleared if the gdsc was not reset. So clear it before 971: * attempting GMU boot. 972: */ MATCH LINES: 2319 2307: if (ret) 2308: goto oob_clear; 2309: 2310: ret = gen7_gmu_hfi_start_msg(adreno_dev); 2311: if (ret) 2312: goto oob_clear; 2313: 2314: /* Clear the busy_data stats - we're starting over from scratch */ 2315: memset(&adreno_dev->busy_data, 0, sizeof(adreno_dev->busy_data)); 2316: 2317: gen7_start(adreno_dev); 2318: 2319: if (gen7_core->qos_value && adreno_is_preemption_enabled(adreno_dev)) 2320: kgsl_regwrite(device, GEN7_RBBM_GBIF_CLIENT_QOS_CNTL, 2321: gen7_core->qos_value[adreno_dev->cur_rb->id]); 2322: 2323: /* Re-initialize the coresight registers if applicable */ 2324: adreno_coresight_start(adreno_dev); 2325: 2326: adreno_perfcounter_start(adreno_dev); 2327: 2328: /* Clear FSR here in case it is set from a previous pagefault */ 2329: kgsl_mmu_clear_fsr(&device->mmu); 2330: 2331: gen7_enable_gpu_irq(adreno_dev); 2332: 2333: ret = gen7_rb_start(adreno_dev); 2334: if (ret) { 2335: gen7_disable_gpu_irq(adreno_dev); 2336: adreno_llcc_slice_deactivate(adreno_dev); 2337: goto oob_clear; 2338: } 2339: 2340: /* 2341: * At this point it is safe to assume that we recovered. Setting 2342: * this field allows us to take a new snapshot for the next failure 2343: * if we are prioritizing the first unrecoverable snapshot. MATCH LINES: 2576 2564: 2565: kgsl_delete_timer_sync(&device->idle_timer); 2566: 2567: kgsl_pwrscale_sleep(device); 2568: 2569: kgsl_pwrctrl_clear_l3_vote(device); 2570: 2571: /* 2572: * Reset the context records so that CP can start 2573: * at the correct read pointer for BV thread after 2574: * coming out of slumber. 2575: */ 2576: gen7_reset_preempt_records(adreno_dev); 2577: 2578: kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER); 2579: 2580: return ret; 2581: } 2582: 2583: static void gmu_idle_check(struct work_struct *work) 2584: { 2585: struct kgsl_device *device = container_of(work, 2586: struct kgsl_device, idle_check_ws); 2587: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 2588: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2589: int ret; 2590: 2591: kgsl_mutex_lock(&device->mutex); 2592: 2593: if (test_bit(GMU_DISABLE_SLUMBER, &device->gmu_core.flags)) 2594: goto done; 2595: 2596: if (atomic_read(&device->active_cnt) || time_is_after_jiffies(device->idle_jiffies)) { 2597: kgsl_pwrscale_update(device); 2598: goto done; 2599: } 2600: MATCH LINES: 2842 2830: { 2831: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2832: 2833: gen7_disable_gpu_irq(adreno_dev); 2834: 2835: gen7_gmu_irq_disable(adreno_dev); 2836: 2837: gen7_hfi_stop(adreno_dev); 2838: 2839: /* Hard reset the gmu and gpu */ 2840: gen7_gmu_suspend(adreno_dev, true); 2841: 2842: gen7_reset_preempt_records(adreno_dev); 2843: 2844: adreno_llcc_slice_deactivate(adreno_dev); 2845: 2846: clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags); 2847: 2848: /* Attempt to reboot the gmu and gpu */ 2849: return gen7_boot(adreno_dev); 2850: } 2851: 2852: int gen7_gmu_hfi_probe(struct adreno_device *adreno_dev) 2853: { 2854: struct platform_device *gmu_pdev = GMU_PDEV(KGSL_DEVICE(adreno_dev)); 2855: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2856: struct gen7_hfi *hfi = &gmu->hfi; 2857: 2858: hfi->irq = kgsl_request_irq(gmu_pdev, "hfi", NULL, -EINVAL, 2859: gen7_hfi_irq_handler, KGSL_DEVICE(adreno_dev)); 2860: 2861: return hfi->irq < 0 ? hfi->irq : 0; 2862: } 2863: 2864: int gen7_gmu_add_to_minidump(struct adreno_device *adreno_dev) 2865: { 2866: struct gen7_device *gen7_dev = container_of(adreno_dev, --- FILE: \adreno_gen7_hwsched.c | HITS: 3 --- MATCH LINES: 120, 123 108: kgsl_snapshot_add_section(device, 109: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 110: snapshot, adreno_snapshot_global, 111: entry->md); 112: 113: if (entry->desc.mem_kind == HFI_MEMKIND_CSW_SMMU_INFO) 114: kgsl_snapshot_add_section(device, 115: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 116: snapshot, adreno_snapshot_global, 117: entry->md); 118: 119: if (entry->desc.mem_kind == HFI_MEMKIND_CSW_PRIV_NON_SECURE) 120: adreno_hwsched_snapshot_preemption_records(device, snapshot, 121: entry->md); 122: 123: if (entry->desc.mem_kind == HFI_MEMKIND_PREEMPT_SCRATCH) 124: kgsl_snapshot_add_section(device, 125: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 126: snapshot, adreno_snapshot_global, 127: entry->md); 128: 129: if (entry->desc.mem_kind == HFI_MEMKIND_AQE_BUFFER) 130: kgsl_snapshot_add_section(device, 131: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 132: snapshot, adreno_hwsched_snapshot_aqe_buffer, 133: entry->md); 134: 135: if (entry->desc.mem_kind == HFI_MEMKIND_HW_FENCE) { 136: struct gmu_mem_type_desc desc; 137: 138: desc.memdesc = entry->md; 139: desc.type = SNAPSHOT_GMU_MEM_HW_FENCE; 140: 141: kgsl_snapshot_add_section(device, 142: KGSL_SNAPSHOT_SECTION_GMU_MEMORY, 143: snapshot, adreno_snapshot_gmu_mem, &desc); 144: } 145: 146: } 147: MATCH LINES: 1550 1538: .last_close = gen7_hwsched_power_off, 1539: .active_count_get = gen7_hwsched_active_count_get, 1540: .touch_wakeup = gen7_hwsched_touch_wakeup, 1541: .pm_suspend = gen7_hwsched_pm_suspend, 1542: .pm_resume = gen7_hwsched_pm_resume, 1543: .gpu_clock_set = gen7_hwsched_clock_set, 1544: .gpu_bus_set = gen7_hwsched_bus_set, 1545: .set_thermal_index = gen7_hwsched_set_thermal_index, 1546: }; 1547: 1548: const struct adreno_hwsched_ops gen7_hwsched_ops = { 1549: .submit_drawobj = gen7_hwsched_submit_drawobj, 1550: .preempt_count = gen7_hwsched_preempt_count_get, 1551: .create_hw_fence = gen7_hwsched_create_hw_fence, 1552: }; 1553: 1554: int gen7_hwsched_probe(struct platform_device *pdev, 1555: u32 chipid, const struct adreno_gpu_core *gpucore) 1556: { 1557: struct adreno_device *adreno_dev; 1558: struct kgsl_device *device; 1559: struct gen7_hwsched_device *gen7_hwsched_dev; 1560: int ret; 1561: 1562: gen7_hwsched_dev = devm_kzalloc(&pdev->dev, sizeof(*gen7_hwsched_dev), 1563: GFP_KERNEL); 1564: if (!gen7_hwsched_dev) 1565: return -ENOMEM; 1566: 1567: adreno_dev = &gen7_hwsched_dev->gen7_dev.adreno_dev; 1568: 1569: adreno_dev->hwsched_enabled = true; 1570: 1571: adreno_dev->irq_mask = GEN7_HWSCHED_INT_MASK; 1572: 1573: ret = gen7_probe_common(pdev, adreno_dev, chipid, gpucore); 1574: if (ret) --- FILE: \adreno_gen7_hwsched_hfi.c | HITS: 24 --- MATCH LINES: 315, 319, 321, 322, 329 303: case GMU_CP_ILLEGAL_INST_ERROR: 304: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 305: break; 306: case GMU_CP_UCODE_ERROR: 307: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 308: break; 309: case GMU_CP_HW_FAULT_ERROR: 310: dev_crit_ratelimited(gmu_pdev_dev, 311: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 312: gen7_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 313: KEY_CP_HW_FAULT)); 314: break; 315: case GMU_GPU_PREEMPT_TIMEOUT: { 316: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 317: 318: cur = gen7_hwsched_lookup_key_value_legacy(adreno_dev, 319: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 320: next = gen7_hwsched_lookup_key_value_legacy(adreno_dev, 321: PAYLOAD_PREEMPT_TIMEOUT, 322: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 323: cur_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_RPTR); 324: cur_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_WPTR); 325: next_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_RPTR); 326: next_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_WPTR); 327: 328: dev_crit_ratelimited(gmu_pdev_dev, 329: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 330: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 331: } 332: break; 333: case GMU_CP_GPC_ERROR: 334: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: GPC error\n"); 335: break; 336: case GMU_CP_BV_OPCODE_ERROR: 337: dev_crit_ratelimited(gmu_pdev_dev, 338: "CP BV opcode error | opcode=0x%8.8x\n", 339: gen7_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 340: KEY_CP_BV_OPCODE_ERROR)); 341: break; 342: case GMU_CP_BV_PROTECTED_ERROR: { 343: u32 status = gen7_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 344: KEY_CP_BV_PROTECTED_ERROR); 345: 346: dev_crit_ratelimited(gmu_pdev_dev, 347: "CP BV | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 348: status & (1 << 20) ? "READ" : "WRITE", 349: status & 0x3FFFF, status); 350: } 351: break; 352: case GMU_CP_BV_HW_FAULT_ERROR: 353: dev_crit_ratelimited(gmu_pdev_dev, MATCH LINES: 488, 492, 494, 495, 502 476: case GMU_CP_ILLEGAL_INST_ERROR: 477: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 478: break; 479: case GMU_CP_UCODE_ERROR: 480: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 481: break; 482: case GMU_CP_HW_FAULT_ERROR: 483: dev_crit_ratelimited(gmu_pdev_dev, 484: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 485: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 486: KEY_CP_HW_FAULT)); 487: break; 488: case GMU_GPU_PREEMPT_TIMEOUT: { 489: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 490: 491: cur = gen7_hwsched_lookup_key_value(adreno_dev, 492: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 493: next = gen7_hwsched_lookup_key_value(adreno_dev, 494: PAYLOAD_PREEMPT_TIMEOUT, 495: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 496: cur_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_RPTR); 497: cur_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_WPTR); 498: next_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_RPTR); 499: next_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_WPTR); 500: 501: dev_crit_ratelimited(gmu_pdev_dev, 502: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 503: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 504: } 505: break; 506: case GMU_CP_GPC_ERROR: 507: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: GPC error\n"); 508: break; 509: case GMU_CP_BV_OPCODE_ERROR: 510: dev_crit_ratelimited(gmu_pdev_dev, 511: "CP BV opcode error | opcode=0x%8.8x\n", 512: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 513: KEY_CP_BV_OPCODE_ERROR)); 514: break; 515: case GMU_CP_BV_PROTECTED_ERROR: { 516: u32 status = gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 517: KEY_CP_BV_PROTECTED_ERROR); 518: 519: dev_crit_ratelimited(gmu_pdev_dev, 520: "CP BV | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 521: status & (1 << 20) ? "READ" : "WRITE", 522: status & 0x3FFFF, status); 523: } 524: break; 525: case GMU_CP_BV_HW_FAULT_ERROR: 526: dev_crit_ratelimited(gmu_pdev_dev, MATCH LINES: 1647, 1654, 1658, 1662, 1663, 1664, 1666 1635: } 1636: 1637: static void gen7_hwsched_enable_async_hfi(struct adreno_device *adreno_dev) 1638: { 1639: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 1640: 1641: hfi->irq_mask |= HFI_IRQ_MSGQ_MASK; 1642: 1643: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN7_GMU_GMU2HOST_INTR_MASK, 1644: (u32)~hfi->irq_mask); 1645: } 1646: 1647: static int enable_preemption(struct adreno_device *adreno_dev) 1648: { 1649: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 1650: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1651: u32 data; 1652: int ret; 1653: 1654: if (!adreno_is_preemption_enabled(adreno_dev)) 1655: return 0; 1656: 1657: /* 1658: * Bits [0:1] contains the preemption level 1659: * Bit 2 is to enable/disable gmem save/restore 1660: * Bit 3 is to enable/disable skipsaverestore 1661: */ 1662: data = FIELD_PREP(GENMASK(1, 0), adreno_dev->preempt.preempt_level) | 1663: FIELD_PREP(BIT(2), adreno_dev->preempt.usesgmem) | 1664: FIELD_PREP(BIT(3), adreno_dev->preempt.skipsaverestore); 1665: 1666: ret = gen7_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_PREEMPTION, 1, 1667: data); 1668: if (ret) 1669: return ret; 1670: 1671: if (gen7_core->qos_value) { 1672: int i; 1673: 1674: for (i = 0; i < KGSL_PRIORITY_MAX_RB_LEVELS; i++) { 1675: if (!gen7_core->qos_value[i]) 1676: continue; 1677: 1678: gen7_hfi_send_set_value(adreno_dev, 1679: HFI_VALUE_RB_GPU_QOS, i, 1680: gen7_core->qos_value[i]); 1681: } 1682: } 1683: if (ADRENO_FEATURE(adreno_dev, ADRENO_RT_HINT)) { 1684: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 1685: 1686: if (pwr->rt_bus_hint) { 1687: ret = gen7_hfi_send_set_value(adreno_dev, HFI_VALUE_RB_IB_RULE, 0, 1688: pwr->rt_bus_hint); 1689: if (ret) { 1690: dev_err(GMU_PDEV_DEV(device), "Failed to set rt bus hint %u, ret: %d\n", MATCH LINES: 1707, 1711 1695: if (pwr->rt_pwrlevel_hint != INVALID_DCVS_IDX) { 1696: ret = gen7_hfi_send_set_value(adreno_dev, HFI_VALUE_RB_GPULEVEL_RULE, 0, 1697: pwr->num_pwrlevels - pwr->rt_pwrlevel_hint); 1698: if (ret) { 1699: dev_err(GMU_PDEV_DEV(device), "Failed to set rt pwrlevel hint %u, ret: %d\n", 1700: pwr->rt_pwrlevel_hint, ret); 1701: pwr->rt_pwrlevel_hint = INVALID_DCVS_IDX; 1702: } 1703: } 1704: } 1705: 1706: /* 1707: * Bits[3:0] contain the preemption timeout enable bit per ringbuffer 1708: * Bits[31:4] contain the timeout in ms 1709: */ 1710: return gen7_hfi_send_set_value(adreno_dev, HFI_VALUE_BIN_TIME, 1, 1711: FIELD_PREP(GENMASK(31, 4), ADRENO_PREEMPT_TIMEOUT) | 1712: FIELD_PREP(GENMASK(3, 0), 0xf)); 1713: 1714: } 1715: 1716: static int enable_gmu_stats(struct adreno_device *adreno_dev) 1717: { 1718: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 1719: u32 data; 1720: 1721: if (!gmu->stats_enable) 1722: return 0; 1723: 1724: /* 1725: * Bits [23:0] contains the countables mask 1726: * Bits [31:24] is the sampling interval 1727: */ 1728: data = FIELD_PREP(GENMASK(23, 0), gmu->stats_mask) | 1729: FIELD_PREP(GENMASK(31, 24), gmu->stats_interval); 1730: 1731: return gen7_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_GMU_STATS, 1, data); 1732: } 1733: 1734: static int gen7_hfi_send_perfcounter_feature_ctrl(struct adreno_device *adreno_dev) 1735: { MATCH LINES: 1881 1869: adreno_dev->dms_enabled = false; 1870: return 0; 1871: } 1872: 1873: return ret; 1874: } 1875: 1876: static void gen7_spin_idle_debug_lpac(struct adreno_device *adreno_dev, 1877: const char *str) 1878: { 1879: struct kgsl_device *device = &adreno_dev->dev; 1880: u32 rptr, wptr, status, status3, intstatus, hwfault; 1881: bool val = adreno_is_preemption_enabled(adreno_dev); 1882: 1883: dev_err(device->dev, str); 1884: 1885: kgsl_regread(device, GEN7_CP_LPAC_RB_RPTR, &rptr); 1886: kgsl_regread(device, GEN7_CP_LPAC_RB_WPTR, &wptr); 1887: 1888: kgsl_regread(device, GEN7_RBBM_STATUS, &status); 1889: kgsl_regread(device, GEN7_RBBM_STATUS3, &status3); 1890: kgsl_regread(device, GEN7_RBBM_INT_0_STATUS, &intstatus); 1891: kgsl_regread(device, GEN7_CP_HW_FAULT, &hwfault); 1892: 1893: dev_err(device->dev, 1894: "LPAC rb=%d pos=%X/%X rbbm_status=%8.8X/%8.8X int_0_status=%8.8X\n", 1895: val ? KGSL_LPAC_RB_ID : 1, rptr, wptr, 1896: status, status3, intstatus); 1897: 1898: dev_err(device->dev, " hwfault=%8.8X\n", hwfault); 1899: 1900: kgsl_device_snapshot(device, NULL, NULL, false); 1901: } 1902: 1903: static bool gen7_hwsched_warmboot_possible(struct adreno_device *adreno_dev) 1904: { 1905: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); MATCH LINES: 2226 2214: 2215: /* 2216: * HFI_VALUE_CONTEXT_QUEUE can only be queried after GMU has initialized some of the 2217: * required resources as part of handling gen7_hfi_send_core_fw_start() 2218: */ 2219: if (!test_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags)) 2220: _context_queue_hw_fence_enable(adreno_dev); 2221: 2222: ret = gen7_hfi_send_hw_fence_feature_ctrl(adreno_dev); 2223: if (ret) 2224: goto err; 2225: 2226: ret = enable_preemption(adreno_dev); 2227: if (ret) 2228: goto err; 2229: 2230: ret = gen7_hfi_send_lpac_feature_ctrl(adreno_dev); 2231: if (ret) 2232: goto err; 2233: 2234: if (ADRENO_FEATURE(adreno_dev, ADRENO_AQE)) { 2235: ret = gen7_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_AQE, 1, 0); 2236: if (ret) 2237: goto err; 2238: } 2239: 2240: ret = send_start_msg(adreno_dev); 2241: if (ret) 2242: goto err; 2243: 2244: /* 2245: * Send this additional start message on cold boot if warmboot is enabled. 2246: * This message will be recorded and on a warmboot this will trigger the 2247: * sequence to replay memory allocation requests and ECP task setup 2248: */ 2249: ret = send_warmboot_start_msg(adreno_dev); 2250: if (ret) MATCH LINES: 2714 2702: } 2703: 2704: #define HFI_DSP_IRQ_BASE 2 2705: 2706: #define DISPQ_IRQ_BIT(_idx) BIT((_idx) + HFI_DSP_IRQ_BASE) 2707: #define DISPQ_SYNC_IRQ_BIT(_idx) ((DISPQ_IRQ_BIT(_idx) << (KGSL_PRIORITY_MAX_RB_LEVELS + 1))) 2708: 2709: static u32 get_irq_bit(struct adreno_device *adreno_dev, struct kgsl_drawobj *drawobj) 2710: { 2711: if (!adreno_hwsched_context_queue_enabled(adreno_dev)) 2712: return drawobj->context->gmu_dispatch_queue; 2713: 2714: if (adreno_is_preemption_enabled(adreno_dev)) 2715: return adreno_get_level(drawobj->context); 2716: 2717: if (kgsl_context_is_lpac(drawobj->context)) 2718: return 1; 2719: 2720: return 0; 2721: } 2722: 2723: static bool _is_kgsl_hw_fence_signaled(struct kgsl_drawobj_sync_hw_fence *hw_fence) 2724: { 2725: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)hw_fence->fence; 2726: struct kgsl_sync_timeline *ktimeline = kfence->parent; 2727: 2728: if (dma_fence_is_signaled_locked(&kfence->fence)) 2729: return true; 2730: 2731: /* 2732: * If we fail to get the context refcount that means this context is detached. 2733: * In that case, treat all hardware fences from detached context as signaled. 2734: */ 2735: if ((!hw_fence->context) && (!_kgsl_context_get(ktimeline->context))) 2736: return true; 2737: 2738: return false; MATCH LINES: 3765, 3772 3753: adreno_profile_process_results(adreno_dev); 3754: context->gmu_registered = false; 3755: 3756: out: 3757: WARN_RATELIMIT(!list_empty(&drawctxt->hw_fence_list) || 3758: !list_empty(&drawctxt->hw_fence_inflight_list), 3759: "detached ctx:%u has active hw fences\n", 3760: context->id); 3761: 3762: kgsl_mutex_unlock(&device->mutex); 3763: } 3764: 3765: u32 gen7_hwsched_preempt_count_get(struct adreno_device *adreno_dev) 3766: { 3767: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3768: 3769: if (device->state != KGSL_STATE_ACTIVE) 3770: return 0; 3771: 3772: return gen7_hwsched_hfi_get_value(adreno_dev, HFI_VALUE_PREEMPT_COUNT); 3773: } 3774: 3775: void gen7_hwsched_context_destroy(struct adreno_device *adreno_dev, 3776: struct adreno_context *drawctxt) 3777: { 3778: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3779: 3780: if (!adreno_hwsched_context_queue_enabled(adreno_dev)) 3781: return; 3782: 3783: if (drawctxt->gmu_context_queue.gmuaddr) 3784: gmu_core_free_block(device, &drawctxt->gmu_context_queue); 3785: 3786: if (drawctxt->gmu_hw_fence_queue.gmuaddr) 3787: gmu_core_free_block(device, &drawctxt->gmu_hw_fence_queue); 3788: } 3789: 3790: static int register_global_ctxt(struct adreno_device *adreno_dev) 3791: { 3792: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3793: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3794: struct hfi_register_ctxt_cmd rcmd = {0}; 3795: struct hfi_context_pointers_cmd pcmd = {0}; 3796: int ret; --- FILE: \adreno_gen7_hwsched_hfi.h | HITS: 4 --- MATCH LINES: 184, 188, 190, 192 172: * gen7_hwsched_context_detach - Unregister a context with GMU 173: * @drawctxt: Pointer to the adreno context 174: * 175: * This function sends context unregister HFI and waits for the ack 176: * to ensure all submissions from this context have retired 177: */ 178: void gen7_hwsched_context_detach(struct adreno_context *drawctxt); 179: 180: /* Helper function to get to gen7 hwsched hfi device from adreno device */ 181: struct gen7_hwsched_hfi *to_gen7_hwsched_hfi(struct adreno_device *adreno_dev); 182: 183: /** 184: * gen7_hwsched_preempt_count_get - Get preemption count from GMU 185: * @adreno_dev: Pointer to adreno device 186: * 187: * This function sends a GET_VALUE HFI packet to get the number of 188: * preemptions completed since last SLUMBER exit. 189: * 190: * Return: Preemption count 191: */ 192: u32 gen7_hwsched_preempt_count_get(struct adreno_device *adreno_dev); 193: 194: /** 195: * gen7_hwsched_lpac_cp_init - Send CP_INIT to LPAC via HFI 196: * @adreno_dev: Pointer to adreno device structure 197: * 198: * This function is used to send CP INIT packet to LPAC and 199: * enable submission to LPAC queue. 200: * 201: * Return: 0 on success and negative error on failure. 202: */ 203: int gen7_hwsched_lpac_cp_init(struct adreno_device *adreno_dev); 204: 205: /** 206: * gen7_hwsched_hfi_set_value - Send SET_VALUE packet to GMU to set the value of a property 207: * @adreno_dev: Pointer to adreno device 208: * @type: Type of the property to set 209: * @subtype: Sub type of the property to set 210: * @data: Value to be set to the property 211: * 212: * This functions sends SET_VALUE HFI packet to set value of a property 213: * 214: * Return: On success, return 0. On failure, return error code 215: */ 216: int gen7_hwsched_hfi_set_value(struct adreno_device *adreno_dev, u32 type, u32 subtype, u32 data); --- FILE: \adreno_gen7_perfcounter.c | HITS: 2 --- MATCH LINES: 1016, 1017 1004: GEN7_GMU_CX_GMU_PERF_COUNTER_5_H, 1005: GEN7_GMU_CX_GMU_PERF_COUNTER_SELECT_1), 1006: }; 1007: 1008: static struct adreno_perfcount_register gen7_perfcounters_alwayson[] = { 1009: { KGSL_PERFCOUNTER_NOT_USED, 0, 0, GEN7_CP_ALWAYS_ON_COUNTER_LO, 1010: GEN7_CP_ALWAYS_ON_COUNTER_HI, -1 }, 1011: }; 1012: 1013: /* 1014: * ADRENO_PERFCOUNTER_GROUP_RESTORE flag is enabled by default 1015: * because most of the perfcounter groups need to be restored 1016: * as part of preemption and IFPC. Perfcounter groups that are 1017: * not restored as part of preemption and IFPC should be defined 1018: * using GEN7_PERFCOUNTER_GROUP_FLAGS macro 1019: */ 1020: 1021: #define GEN7_PERFCOUNTER_GROUP_FLAGS(core, offset, name, flags, \ 1022: enable, read) \ 1023: [KGSL_PERFCOUNTER_GROUP_##offset] = { core##_perfcounters_##name, \ 1024: ARRAY_SIZE(core##_perfcounters_##name), __stringify(name), flags, \ 1025: enable, read } 1026: 1027: #define GEN7_PERFCOUNTER_GROUP(offset, name, enable, read) \ 1028: GEN7_PERFCOUNTER_GROUP_FLAGS(gen7, offset, name, \ 1029: ADRENO_PERFCOUNTER_GROUP_RESTORE, enable, read) 1030: 1031: #define GEN7_REGULAR_PERFCOUNTER_GROUP(offset, name) \ 1032: GEN7_PERFCOUNTER_GROUP(offset, name, \ 1033: gen7_counter_enable, gen7_counter_read) 1034: 1035: #define GEN7_BV_PERFCOUNTER_GROUP(offset, name, enable, read) \ 1036: GEN7_PERFCOUNTER_GROUP_FLAGS(gen7, BV_##offset, bv_##name, \ 1037: ADRENO_PERFCOUNTER_GROUP_RESTORE, enable, read) 1038: 1039: #define GEN7_BV_REGULAR_PERFCOUNTER_GROUP(offset, name) \ 1040: GEN7_BV_PERFCOUNTER_GROUP(offset, name, \ 1041: gen7_counter_enable, gen7_counter_read) --- FILE: \adreno_gen7_preempt.c | HITS: 163 --- MATCH LINES: 13, 14, 16, 27, 57, 74, 77, 90, 94, 103, 108, 110, 112, 114, 129, 130, 133, 139, 143, 146, 147, 155, 163, 166, 168, 169, 170, 171, 177, 178, 194, 196, 205, 214, 217, 218, 221, 241, 253, 261, 262, 264, 269, 271, 274, 278, 283, 297, 298, 308, 315, 316, 322, 323, 328, 329, 335, 341, 348, 349, 350, 352, 354, 355, 358, 359, 362, 365, 368, 369, 372, 373, 376, 390, 396, 401, 402, 405, 409, 418, 423, 426, 431, 433, 435, 442, 449, 451, 454, 458, 471, 476, 477, 486, 502, 505, 509, 514, 515, 517, 522, 530, 533, 539, 542, 545, 546, 549, 551, 556, 557, 561, 567, 574, 579, 583, 594, 603, 610, 614, 617, 619, 621, 625, 627, 629, 632, 637, 638, 639, 640, 645, 649, 652, 654, 655, 656, 657, 658, 659, 661, 662, 663, 664, 668, 673, 677, 681, 692, 694, 699, 702, 714, 719, 724, 729, 735, 737, 739, 744, 745, 749, 760 1: // SPDX-License-Identifier: GPL-2.0-only 2: /* 3: * Copyright (c) 2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include "adreno.h" 8: #include "adreno_gen7.h" 9: #include "adreno_pm4types.h" 10: #include "adreno_trace.h" 11: #include "kgsl_util.h" 12: 13: #define PREEMPT_RECORD(_field) \ 14: offsetof(struct gen7_cp_preemption_record, _field) 15: 16: #define PREEMPT_SMMU_RECORD(_field) \ 17: offsetof(struct gen7_cp_smmu_info, _field) 18: 19: static void _update_wptr(struct adreno_device *adreno_dev, bool reset_timer, 20: bool atomic) 21: { 22: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 23: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 24: unsigned long flags; 25: int ret = 0; 26: 27: spin_lock_irqsave(&rb->preempt_lock, flags); 28: 29: if (!atomic) { 30: /* 31: * We might have skipped updating the wptr in case we are in 32: * dispatcher context. Do it now. 33: */ 34: if (rb->skip_inline_wptr) { 35: 36: ret = gen7_fenced_write(adreno_dev, 37: GEN7_CP_RB_WPTR, rb->wptr, 38: FENCE_STATUS_WRITEDROPPED0_MASK); 39: 40: reset_timer = true; 41: rb->skip_inline_wptr = false; 42: } 43: } else { 44: unsigned int wptr; 45: 46: kgsl_regread(device, GEN7_CP_RB_WPTR, &wptr); 47: if (wptr != rb->wptr) { 48: kgsl_regwrite(device, GEN7_CP_RB_WPTR, rb->wptr); 49: reset_timer = true; 50: } 51: } 52: 53: if (reset_timer) 54: rb->dispatch_q.expires = jiffies + 55: msecs_to_jiffies(adreno_drawobj_timeout); 56: 57: spin_unlock_irqrestore(&rb->preempt_lock, flags); 58: 59: if (!atomic) { 60: /* If WPTR update fails, set the fault and trigger recovery */ 61: if (ret) { 62: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 63: adreno_scheduler_fault(adreno_dev, 64: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 65: } 66: } 67: } 68: 69: static void _power_collapse_set(struct adreno_device *adreno_dev, bool val) 70: { 71: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 72: 73: gmu_core_regwrite(device, 74: GEN7_GMU_PWR_COL_PREEMPT_KEEPALIVE, (val ? 1 : 0)); 75: } 76: 77: static void _gen7_preemption_done(struct adreno_device *adreno_dev) 78: { 79: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 80: unsigned int status; 81: 82: /* 83: * In the very unlikely case that the power is off, do nothing - the 84: * state will be reset on power up and everybody will be happy 85: */ 86: 87: if (!kgsl_state_is_awake(device)) 88: return; 89: 90: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_CNTL, &status); 91: 92: if (status & 0x1) { 93: dev_err(device->dev, 94: "Preemption not complete: status=%X cur=%d R/W=%X/%X next=%d R/W=%X/%X\n", 95: status, adreno_dev->cur_rb->id, 96: adreno_get_rptr(adreno_dev->cur_rb), 97: adreno_dev->cur_rb->wptr, 98: adreno_dev->next_rb->id, 99: adreno_get_rptr(adreno_dev->next_rb), 100: adreno_dev->next_rb->wptr); 101: 102: /* Set a fault and restart */ 103: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 104: 105: return; 106: } 107: 108: adreno_dev->preempt.count++; 109: 110: kgsl_delete_timer_sync(&adreno_dev->preempt.timer); 111: 112: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 113: 114: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 115: status, 0); 116: 117: /* Clean up all the bits */ 118: adreno_dev->prev_rb = adreno_dev->cur_rb; 119: adreno_dev->cur_rb = adreno_dev->next_rb; 120: adreno_dev->next_rb = NULL; 121: 122: /* Update the wptr for the new command queue */ 123: _update_wptr(adreno_dev, true, false); 124: 125: /* Update the dispatcher timer for the new command queue */ 126: mod_timer(&adreno_dev->dispatcher.timer, 127: adreno_dev->cur_rb->dispatch_q.expires); 128: 129: /* Clear the preempt state */ 130: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 131: } 132: 133: static void _gen7_preemption_fault(struct adreno_device *adreno_dev) 134: { 135: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 136: unsigned int status; 137: 138: /* 139: * If the power is on check the preemption status one more time - if it 140: * was successful then just transition to the complete state 141: */ 142: if (kgsl_state_is_awake(device)) { 143: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_CNTL, &status); 144: 145: if (!(status & 0x1)) { 146: adreno_set_preempt_state(adreno_dev, 147: ADRENO_PREEMPT_COMPLETE); 148: 149: adreno_scheduler_queue(adreno_dev); 150: return; 151: } 152: } 153: 154: dev_err(device->dev, 155: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 156: adreno_dev->cur_rb->id, 157: adreno_get_rptr(adreno_dev->cur_rb), 158: adreno_dev->cur_rb->wptr, 159: adreno_dev->next_rb->id, 160: adreno_get_rptr(adreno_dev->next_rb), 161: adreno_dev->next_rb->wptr); 162: 163: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 164: } 165: 166: static void _gen7_preemption_worker(struct work_struct *work) 167: { 168: struct adreno_preemption *preempt = container_of(work, 169: struct adreno_preemption, work); 170: struct adreno_device *adreno_dev = container_of(preempt, 171: struct adreno_device, preempt); 172: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 173: 174: /* Need to take the mutex to make sure that the power stays on */ 175: kgsl_mutex_lock(&device->mutex); 176: 177: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_FAULTED)) 178: _gen7_preemption_fault(adreno_dev); 179: 180: kgsl_mutex_unlock(&device->mutex); 181: } 182: 183: /* Find the highest priority active ringbuffer */ 184: static struct adreno_ringbuffer *gen7_next_ringbuffer( 185: struct adreno_device *adreno_dev) 186: { 187: struct adreno_ringbuffer *rb; 188: unsigned long flags; 189: unsigned int i; 190: 191: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 192: bool empty; 193: 194: spin_lock_irqsave(&rb->preempt_lock, flags); 195: empty = adreno_rb_empty(rb); 196: spin_unlock_irqrestore(&rb->preempt_lock, flags); 197: 198: if (!empty) 199: return rb; 200: } 201: 202: return NULL; 203: } 204: 205: void gen7_preemption_trigger(struct adreno_device *adreno_dev, bool atomic) 206: { 207: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 208: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 209: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 210: struct adreno_ringbuffer *next; 211: u64 ttbr0, gpuaddr; 212: u32 contextidr, cntl; 213: unsigned long flags; 214: struct adreno_preemption *preempt = &adreno_dev->preempt; 215: 216: /* Put ourselves into a possible trigger state */ 217: if (!adreno_move_preempt_state(adreno_dev, 218: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START)) 219: return; 220: 221: /* Get the next ringbuffer to preempt in */ 222: next = gen7_next_ringbuffer(adreno_dev); 223: 224: /* 225: * Nothing to do if every ringbuffer is empty or if the current 226: * ringbuffer is the only active one 227: */ 228: if (next == NULL || next == adreno_dev->cur_rb) { 229: /* 230: * Update any critical things that might have been skipped while 231: * we were looking for a new ringbuffer 232: */ 233: 234: if (next != NULL) { 235: _update_wptr(adreno_dev, false, atomic); 236: 237: mod_timer(&adreno_dev->dispatcher.timer, 238: adreno_dev->cur_rb->dispatch_q.expires); 239: } 240: 241: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 242: return; 243: } 244: 245: /* Turn off the dispatcher timer */ 246: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 247: 248: /* 249: * This is the most critical section - we need to take care not to race 250: * until we have programmed the CP for the switch 251: */ 252: 253: spin_lock_irqsave(&next->preempt_lock, flags); 254: 255: /* Get the pagetable from the pagetable info. */ 256: kgsl_sharedmem_readq(device->scratch, &ttbr0, 257: SCRATCH_RB_OFFSET(next->id, ttbr0)); 258: kgsl_sharedmem_readl(device->scratch, &contextidr, 259: SCRATCH_RB_OFFSET(next->id, contextidr)); 260: 261: kgsl_sharedmem_writel(next->preemption_desc, 262: PREEMPT_RECORD(wptr), next->wptr); 263: 264: spin_unlock_irqrestore(&next->preempt_lock, flags); 265: 266: /* And write it to the smmu info */ 267: if (kgsl_mmu_is_perprocess(&device->mmu)) { 268: kgsl_sharedmem_writeq(iommu->smmu_info, 269: PREEMPT_SMMU_RECORD(ttbr0), ttbr0); 270: kgsl_sharedmem_writel(iommu->smmu_info, 271: PREEMPT_SMMU_RECORD(context_idr), contextidr); 272: } 273: 274: kgsl_sharedmem_readq(preempt->scratch, &gpuaddr, 275: next->id * sizeof(u64)); 276: 277: /* 278: * Set a keepalive bit before the first preemption register write. 279: * This is required since while each individual write to the context 280: * switch registers will wake the GPU from collapse, it will not in 281: * itself cause GPU activity. Thus, the GPU could technically be 282: * re-collapsed between subsequent register writes leading to a 283: * prolonged preemption sequence. The keepalive bit prevents any 284: * further power collapse while it is set. 285: * It is more efficient to use a keepalive+wake-on-fence approach here 286: * rather than an OOB. Both keepalive and the fence are effectively 287: * free when the GPU is already powered on, whereas an OOB requires an 288: * unconditional handshake with the GMU. 289: */ 290: _power_collapse_set(adreno_dev, true); 291: 292: /* 293: * Fenced writes on this path will make sure the GPU is woken up 294: * in case it was power collapsed by the GMU. 295: */ 296: if (gen7_fenced_write(adreno_dev, 297: GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO, 298: lower_32_bits(next->preemption_desc->gpuaddr), 299: FENCE_STATUS_WRITEDROPPED1_MASK)) 300: goto err; 301: 302: /* 303: * Above fence writes will make sure GMU comes out of 304: * IFPC state if its was in IFPC state but it doesn't 305: * guarantee that GMU FW actually moved to ACTIVE state 306: * i.e. wake-up from IFPC is complete. 307: * Wait for GMU to move to ACTIVE state before triggering 308: * preemption. This is require to make sure CP doesn't 309: * interrupt GMU during wake-up from IFPC. 310: */ 311: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 312: goto err; 313: 314: if (gen7_fenced_write(adreno_dev, 315: GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI, 316: upper_32_bits(next->preemption_desc->gpuaddr), 317: FENCE_STATUS_WRITEDROPPED1_MASK)) 318: goto err; 319: 320: if (kgsl_mmu_is_secured(&device->mmu)) { 321: if (gen7_fenced_write(adreno_dev, 322: GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO, 323: lower_32_bits(next->secure_preemption_desc->gpuaddr), 324: FENCE_STATUS_WRITEDROPPED1_MASK)) 325: goto err; 326: 327: if (gen7_fenced_write(adreno_dev, 328: GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI, 329: upper_32_bits(next->secure_preemption_desc->gpuaddr), 330: FENCE_STATUS_WRITEDROPPED1_MASK)) 331: goto err; 332: } 333: 334: if (gen7_fenced_write(adreno_dev, 335: GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO, 336: lower_32_bits(gpuaddr), 337: FENCE_STATUS_WRITEDROPPED1_MASK)) 338: goto err; 339: 340: if (gen7_fenced_write(adreno_dev, 341: GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI, 342: upper_32_bits(gpuaddr), 343: FENCE_STATUS_WRITEDROPPED1_MASK)) 344: goto err; 345: 346: adreno_dev->next_rb = next; 347: 348: /* Start the timer to detect a stuck preemption */ 349: mod_timer(&adreno_dev->preempt.timer, 350: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 351: 352: cntl = (preempt->preempt_level << 6) | 0x01; 353: 354: /* Skip save/restore during L1 preemption */ 355: if (preempt->skipsaverestore) 356: cntl |= (1 << 9); 357: 358: /* Enable GMEM save/restore across preemption */ 359: if (preempt->usesgmem) 360: cntl |= (1 << 8); 361: 362: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 363: cntl, 0); 364: 365: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 366: 367: if (gen7_core->qos_value) 368: kgsl_sharedmem_writel(preempt->scratch, 369: PREEMPT_SCRATCH_OFFSET(QOS_VALUE_IDX), 370: gen7_core->qos_value[next->id]); 371: 372: /* Trigger the preemption */ 373: if (gen7_fenced_write(adreno_dev, GEN7_CP_CONTEXT_SWITCH_CNTL, cntl, 374: FENCE_STATUS_WRITEDROPPED1_MASK)) { 375: adreno_dev->next_rb = NULL; 376: kgsl_delete_timer(&adreno_dev->preempt.timer); 377: goto err; 378: } 379: 380: return; 381: err: 382: /* If fenced write fails, take inline snapshot and trigger recovery */ 383: if (!in_interrupt()) { 384: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 385: adreno_scheduler_fault(adreno_dev, 386: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 387: } else { 388: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 389: } 390: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 391: /* Clear the keep alive */ 392: _power_collapse_set(adreno_dev, false); 393: 394: } 395: 396: void gen7_preemption_callback(struct adreno_device *adreno_dev, int bit) 397: { 398: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 399: unsigned int status; 400: 401: if (!adreno_move_preempt_state(adreno_dev, 402: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 403: return; 404: 405: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_CNTL, &status); 406: 407: if (status & 0x1) { 408: dev_err(KGSL_DEVICE(adreno_dev)->dev, 409: "preempt interrupt with non-zero status: %X\n", 410: status); 411: 412: /* 413: * Under the assumption that this is a race between the 414: * interrupt and the register, schedule the worker to clean up. 415: * If the status still hasn't resolved itself by the time we get 416: * there then we have to assume something bad happened 417: */ 418: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE); 419: adreno_scheduler_queue(adreno_dev); 420: return; 421: } 422: 423: adreno_dev->preempt.count++; 424: 425: /* 426: * We can now safely clear the preemption keepalive bit, allowing 427: * power collapse to resume its regular activity. 428: */ 429: _power_collapse_set(adreno_dev, false); 430: 431: kgsl_delete_timer(&adreno_dev->preempt.timer); 432: 433: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 434: 435: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 436: status, 0); 437: 438: adreno_dev->prev_rb = adreno_dev->cur_rb; 439: adreno_dev->cur_rb = adreno_dev->next_rb; 440: adreno_dev->next_rb = NULL; 441: 442: /* Update the wptr if it changed while preemption was ongoing */ 443: _update_wptr(adreno_dev, true, true); 444: 445: /* Update the dispatcher timer for the new command queue */ 446: mod_timer(&adreno_dev->dispatcher.timer, 447: adreno_dev->cur_rb->dispatch_q.expires); 448: 449: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 450: 451: gen7_preemption_trigger(adreno_dev, true); 452: } 453: 454: void gen7_preemption_prepare_postamble(struct adreno_device *adreno_dev) 455: { 456: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 457: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 458: struct adreno_preemption *preempt = &adreno_dev->preempt; 459: u32 *postamble, count = 0; 460: 461: /* 462: * First 28 dwords of the device scratch buffer are used to store shadow rb data. 463: * Reserve 15 dwords in the device scratch buffer from SCRATCH_POSTAMBLE_OFFSET for 464: * KMD postamble pm4 packets. This should be in *device->scratch* so that userspace 465: * cannot access it. 466: */ 467: postamble = device->scratch->hostptr + SCRATCH_POSTAMBLE_OFFSET; 468: 469: /* 470: * Reserve 4 dwords in the scratch buffer for dynamic QOS control feature. To ensure QOS 471: * value is updated for first preemption, send it during bootup 472: */ 473: if (gen7_core->qos_value) { 474: postamble[count++] = cp_type7_packet(CP_MEM_TO_REG, 3); 475: postamble[count++] = GEN7_RBBM_GBIF_CLIENT_QOS_CNTL; 476: postamble[count++] = lower_32_bits(PREEMPT_SCRATCH_ADDR(adreno_dev, QOS_VALUE_IDX)); 477: postamble[count++] = upper_32_bits(PREEMPT_SCRATCH_ADDR(adreno_dev, QOS_VALUE_IDX)); 478: } 479: 480: /* 481: * Since postambles are not preserved across slumber, necessary packets 482: * must be sent to GPU before first submission. 483: * 484: * If a packet needs to be sent before first submission, add it above this. 485: */ 486: preempt->postamble_bootup_len = count; 487: 488: /* Insert PM4 packets in device scratch buffer to clear perfcounters */ 489: if (!adreno_dev->perfcounter) { 490: postamble[count++] = cp_type4_packet(GEN7_RBBM_PERFCTR_SRAM_INIT_CMD, 1); 491: postamble[count++] = 0x1; 492: 493: postamble[count++] = cp_type7_packet(CP_WAIT_REG_MEM, 6); 494: postamble[count++] = 0x3; 495: postamble[count++] = GEN7_RBBM_PERFCTR_SRAM_INIT_STATUS; 496: postamble[count++] = 0x0; 497: postamble[count++] = 0x1; 498: postamble[count++] = 0x1; 499: postamble[count++] = 0x0; 500: } 501: 502: preempt->postamble_len = count; 503: } 504: 505: void gen7_preemption_schedule(struct adreno_device *adreno_dev) 506: { 507: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 508: 509: if (!adreno_is_preemption_enabled(adreno_dev)) 510: return; 511: 512: kgsl_mutex_lock(&device->mutex); 513: 514: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE)) 515: _gen7_preemption_done(adreno_dev); 516: 517: gen7_preemption_trigger(adreno_dev, false); 518: 519: kgsl_mutex_unlock(&device->mutex); 520: } 521: 522: u32 gen7_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 523: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 524: u32 *cmds) 525: { 526: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 527: u32 count = kgsl_mmu_is_secured(&device->mmu) ? 12 : 9; 528: u32 *cmds_orig = cmds; 529: 530: if (!adreno_is_preemption_enabled(adreno_dev)) 531: return 0; 532: 533: if (test_and_set_bit(ADRENO_RB_SET_PSEUDO_DONE, &rb->flags)) 534: goto done; 535: 536: *cmds++ = cp_type7_packet(CP_THREAD_CONTROL, 1); 537: *cmds++ = CP_SET_THREAD_BR; 538: 539: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, count); 540: 541: /* NULL SMMU_INFO buffer - we track in KMD */ 542: *cmds++ = SET_PSEUDO_SMMU_INFO; 543: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 544: 545: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 546: cmds += cp_gpuaddr(adreno_dev, cmds, rb->preemption_desc->gpuaddr); 547: 548: if (kgsl_mmu_is_secured(&device->mmu)) { 549: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 550: cmds += cp_gpuaddr(adreno_dev, cmds, 551: rb->secure_preemption_desc->gpuaddr); 552: } 553: 554: /* 555: * There is no need to specify this address when we are about to 556: * trigger preemption. This is because CP internally stores this 557: * address specified here in the CP_SET_PSEUDO_REGISTER payload to 558: * the context record and thus knows from where to restore 559: * the saved perfcounters for the new ringbuffer. 560: */ 561: *cmds++ = SET_PSEUDO_COUNTER; 562: cmds += cp_gpuaddr(adreno_dev, cmds, 563: rb->perfcounter_save_restore_desc->gpuaddr); 564: 565: done: 566: if (drawctxt) { 567: cmds += adreno_prepare_preib_preempt_scratch(adreno_dev, drawctxt, cmds); 568: cmds += adreno_prepare_preib_postamble_scratch(adreno_dev, cmds); 569: } 570: 571: return (u32) (cmds - cmds_orig); 572: } 573: 574: u32 gen7_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 575: u32 *cmds) 576: { 577: u32 index = 0; 578: 579: if (!adreno_is_preemption_enabled(adreno_dev)) 580: return 0; 581: 582: if (adreno_dev->cur_rb) { 583: u64 dest = PREEMPT_SCRATCH_ADDR(adreno_dev, adreno_dev->cur_rb->id); 584: 585: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 4); 586: cmds[index++] = lower_32_bits(dest); 587: cmds[index++] = upper_32_bits(dest); 588: cmds[index++] = 0; 589: cmds[index++] = 0; 590: } 591: 592: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 593: cmds[index++] = CP_SET_THREAD_BOTH; 594: cmds[index++] = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 595: cmds[index++] = 0; 596: cmds[index++] = 0; 597: cmds[index++] = 1; 598: cmds[index++] = 0; 599: 600: return index; 601: } 602: 603: void gen7_preemption_start(struct adreno_device *adreno_dev) 604: { 605: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 606: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 607: struct adreno_ringbuffer *rb; 608: unsigned int i; 609: 610: if (!adreno_is_preemption_enabled(adreno_dev)) 611: return; 612: 613: /* Force the state to be clear */ 614: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 615: 616: if (kgsl_mmu_is_perprocess(&device->mmu)) { 617: /* smmu_info is allocated and mapped in gen7_preemption_iommu_init */ 618: kgsl_sharedmem_writel(iommu->smmu_info, 619: PREEMPT_SMMU_RECORD(magic), GEN7_CP_SMMU_INFO_MAGIC_REF); 620: kgsl_sharedmem_writeq(iommu->smmu_info, 621: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 622: 623: /* The CP doesn't use the asid record, so poison it */ 624: kgsl_sharedmem_writel(iommu->smmu_info, 625: PREEMPT_SMMU_RECORD(asid), 0xdecafbad); 626: kgsl_sharedmem_writel(iommu->smmu_info, 627: PREEMPT_SMMU_RECORD(context_idr), 0); 628: 629: kgsl_regwrite(device, GEN7_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 630: lower_32_bits(iommu->smmu_info->gpuaddr)); 631: 632: kgsl_regwrite(device, GEN7_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 633: upper_32_bits(iommu->smmu_info->gpuaddr)); 634: } 635: 636: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 637: kgsl_sharedmem_writel(rb->preemption_desc, 638: PREEMPT_RECORD(rptr), 0); 639: kgsl_sharedmem_writel(rb->preemption_desc, 640: PREEMPT_RECORD(wptr), 0); 641: 642: adreno_ringbuffer_set_pagetable(device, rb, 643: device->mmu.defaultpagetable); 644: 645: clear_bit(ADRENO_RB_SET_PSEUDO_DONE, &rb->flags); 646: } 647: } 648: 649: static void reset_rb_preempt_record(struct adreno_device *adreno_dev, 650: struct adreno_ringbuffer *rb) 651: { 652: memset(rb->preemption_desc->hostptr, 0x0, rb->preemption_desc->size); 653: 654: kgsl_sharedmem_writel(rb->preemption_desc, 655: PREEMPT_RECORD(magic), GEN7_CP_CTXRECORD_MAGIC_REF); 656: kgsl_sharedmem_writel(rb->preemption_desc, 657: PREEMPT_RECORD(cntl), GEN7_CP_RB_CNTL_DEFAULT); 658: kgsl_sharedmem_writeq(rb->preemption_desc, 659: PREEMPT_RECORD(rptr_addr), SCRATCH_RB_GPU_ADDR( 660: KGSL_DEVICE(adreno_dev), rb->id, rptr)); 661: kgsl_sharedmem_writeq(rb->preemption_desc, 662: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 663: kgsl_sharedmem_writeq(rb->preemption_desc, 664: PREEMPT_RECORD(bv_rptr_addr), SCRATCH_RB_GPU_ADDR( 665: KGSL_DEVICE(adreno_dev), rb->id, bv_rptr)); 666: } 667: 668: void gen7_reset_preempt_records(struct adreno_device *adreno_dev) 669: { 670: int i; 671: struct adreno_ringbuffer *rb; 672: 673: if (!adreno_is_preemption_enabled(adreno_dev)) 674: return; 675: 676: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 677: reset_rb_preempt_record(adreno_dev, rb); 678: } 679: } 680: 681: static int gen7_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 682: struct adreno_ringbuffer *rb) 683: { 684: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 685: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 686: u64 ctxt_record_size = GEN7_CP_CTXRECORD_SIZE_IN_BYTES; 687: int ret; 688: 689: if (gen7_core->ctxt_record_size) 690: ctxt_record_size = gen7_core->ctxt_record_size; 691: 692: ret = adreno_allocate_global(device, &rb->preemption_desc, 693: ctxt_record_size, SZ_16K, 0, 694: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 695: if (ret) 696: return ret; 697: 698: if (kgsl_mmu_is_secured(&device->mmu)) { 699: ret = adreno_allocate_global(device, &rb->secure_preemption_desc, 700: ctxt_record_size, 0, 701: KGSL_MEMFLAGS_SECURE, KGSL_MEMDESC_PRIVILEGED, 702: "secure_preemption_desc"); 703: if (ret) 704: return ret; 705: } 706: 707: ret = adreno_allocate_global(device, &rb->perfcounter_save_restore_desc, 708: GEN7_CP_PERFCOUNTER_SAVE_RESTORE_SIZE, 0, 0, 709: KGSL_MEMDESC_PRIVILEGED, 710: "perfcounter_save_restore_desc"); 711: if (ret) 712: return ret; 713: 714: reset_rb_preempt_record(adreno_dev, rb); 715: 716: return 0; 717: } 718: 719: int gen7_preemption_init(struct adreno_device *adreno_dev) 720: { 721: u32 flags = ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? KGSL_MEMDESC_PRIVILEGED : 0; 722: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 723: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 724: struct adreno_preemption *preempt = &adreno_dev->preempt; 725: struct adreno_ringbuffer *rb; 726: int ret; 727: unsigned int i; 728: 729: /* We are dependent on IOMMU to make preemption go on the CP side */ 730: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) { 731: ret = -ENODEV; 732: goto done; 733: } 734: 735: INIT_WORK(&preempt->work, _gen7_preemption_worker); 736: 737: /* Allocate mem for storing preemption switch record */ 738: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 739: ret = gen7_preemption_ringbuffer_init(adreno_dev, rb); 740: if (ret) 741: goto done; 742: } 743: 744: ret = adreno_allocate_global(device, &preempt->scratch, PAGE_SIZE, 745: 0, 0, flags, "preempt_scratch"); 746: if (ret) 747: goto done; 748: 749: /* Allocate mem for storing preemption smmu record */ 750: if (kgsl_mmu_is_perprocess(&device->mmu)) { 751: ret = adreno_allocate_global(device, &iommu->smmu_info, PAGE_SIZE, 0, 752: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 753: "smmu_info"); 754: if (ret) 755: goto done; 756: } 757: 758: return 0; 759: done: 760: clear_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 761: return ret; 762: } --- FILE: \adreno_gen7_ringbuffer.c | HITS: 13 --- MATCH LINES: 60 48: 49: /* 50: * Sync both threads after switching pagetables and enable BR only 51: * to make sure BV doesn't race ahead while BR is still switching 52: * pagetables. 53: */ 54: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 55: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BR; 56: 57: return count; 58: } 59: 60: static int gen7_rb_context_switch(struct adreno_device *adreno_dev, 61: struct adreno_ringbuffer *rb, 62: struct adreno_context *drawctxt) 63: { 64: struct kgsl_pagetable *pagetable = 65: adreno_drawctxt_get_pagetable(drawctxt); 66: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 67: int count = 0; 68: u32 cmds[61]; 69: 70: /* Sync both threads */ 71: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 72: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BOTH; 73: /* Reset context state */ 74: cmds[count++] = cp_type7_packet(CP_RESET_CONTEXT_STATE, 1); 75: cmds[count++] = CP_RESET_GLOBAL_LOCAL_TS | CP_CLEAR_BV_BR_COUNTER | 76: CP_CLEAR_RESOURCE_TABLE | CP_CLEAR_ON_CHIP_TS; 77: /* 78: * Enable/disable concurrent binning for pagetable switch and 79: * set the thread to BR since only BR can execute the pagetable 80: * switch packets. 81: */ 82: /* Sync both threads and enable BR only */ 83: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 84: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BR; MATCH LINES: 151, 154, 155, 185, 186, 199, 227, 244, 245 139: cmds[count++] = drawctxt->base.id; 140: 141: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 142: cmds[count++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 143: KGSL_MEMSTORE_GLOBAL, current_context)); 144: cmds[count++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 145: KGSL_MEMSTORE_GLOBAL, current_context)); 146: cmds[count++] = drawctxt->base.id; 147: 148: cmds[count++] = cp_type7_packet(CP_EVENT_WRITE, 1); 149: cmds[count++] = 0x31; 150: 151: if (adreno_is_preemption_enabled(adreno_dev) && drawctxt->base.user_ctxt_record) { 152: u64 gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 153: 154: cmds[count++] = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 3); 155: cmds[count++] = SET_PSEUDO_NON_PRIV_SAVE_ADDR; 156: cmds[count++] = lower_32_bits(gpuaddr); 157: cmds[count++] = upper_32_bits(gpuaddr); 158: } 159: 160: return gen7_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED, 161: cmds, count, 0, NULL); 162: } 163: 164: #define RB_SOPTIMESTAMP(device, rb) \ 165: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 166: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 167: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 168: 169: #define RB_EOPTIMESTAMP(device, rb) \ 170: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 171: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 172: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 173: 174: int gen7_ringbuffer_submit(struct adreno_ringbuffer *rb, 175: struct adreno_submit_time *time) 176: { 177: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 178: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 179: int ret = 0; 180: unsigned long flags; 181: 182: adreno_get_submit_time(adreno_dev, rb, time); 183: adreno_profile_submit_time(time); 184: 185: spin_lock_irqsave(&rb->preempt_lock, flags); 186: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 187: if (adreno_dev->cur_rb == rb) { 188: ret = gen7_fenced_write(adreno_dev, 189: GEN7_CP_RB_WPTR, rb->_wptr, 190: FENCE_STATUS_WRITEDROPPED0_MASK); 191: rb->skip_inline_wptr = false; 192: } 193: } else { 194: if (adreno_dev->cur_rb == rb) 195: rb->skip_inline_wptr = true; 196: } 197: 198: rb->wptr = rb->_wptr; 199: spin_unlock_irqrestore(&rb->preempt_lock, flags); 200: 201: if (ret) { 202: /* 203: * If WPTR update fails, take inline snapshot and trigger 204: * recovery. 205: */ 206: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 207: adreno_scheduler_fault(adreno_dev, 208: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 209: } 210: 211: return ret; 212: } 213: 214: int gen7_ringbuffer_init(struct adreno_device *adreno_dev) 215: { 216: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 217: int i, ret; 218: 219: ret = adreno_allocate_global(device, &device->scratch, PAGE_SIZE, 220: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED, 221: "scratch"); 222: if (ret) 223: return ret; 224: 225: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]); 226: 227: if (!adreno_preemption_feature_set(adreno_dev)) { 228: adreno_dev->num_ringbuffers = 1; 229: return adreno_ringbuffer_setup(adreno_dev, 230: &adreno_dev->ringbuffers[0], 0); 231: } 232: 233: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers); 234: 235: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 236: int ret; 237: 238: ret = adreno_ringbuffer_setup(adreno_dev, 239: &adreno_dev->ringbuffers[i], i); 240: if (ret) 241: return ret; 242: } 243: 244: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 245: gen7_preemption_init(adreno_dev); 246: return 0; 247: } 248: 249: #define GEN7_SUBMIT_MAX 104 250: 251: int gen7_ringbuffer_addcmds(struct adreno_device *adreno_dev, 252: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 253: u32 flags, u32 *in, u32 dwords, u32 timestamp, 254: struct adreno_submit_time *time) 255: { 256: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 257: u32 size = GEN7_SUBMIT_MAX + dwords; 258: u32 *cmds, index = 0; 259: u64 profile_gpuaddr; 260: u32 profile_dwords; 261: 262: if (adreno_drawctxt_detached(drawctxt)) 263: return -ENOENT; 264: 265: if (adreno_gpu_fault(adreno_dev) != 0) 266: return -EPROTO; 267: 268: rb->timestamp++; 269: MATCH LINES: 285 273: /* All submissions are run with protected mode off due to APRIV */ 274: flags &= ~F_NOTPROTECTED; 275: 276: cmds = adreno_ringbuffer_allocspace(rb, size); 277: if (IS_ERR(cmds)) 278: return PTR_ERR(cmds); 279: 280: /* Identify the start of a command */ 281: cmds[index++] = cp_type7_packet(CP_NOP, 1); 282: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 283: 284: /* This is 25 dwords when drawctxt is not NULL and perfcounter needs to be zapped*/ 285: index += gen7_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 286: &cmds[index]); 287: 288: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 289: cmds[index++] = CP_SET_THREAD_BOTH; 290: 291: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 292: cmds[index++] = 0x101; /* IFPC disable */ 293: 294: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 295: cmds[index++] = CP_SET_THREAD_BR; 296: 297: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 298: drawctxt, &profile_dwords); 299: 300: if (profile_gpuaddr) { 301: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 302: cmds[index++] = lower_32_bits(profile_gpuaddr); 303: cmds[index++] = upper_32_bits(profile_gpuaddr); 304: cmds[index++] = profile_dwords; 305: } 306: 307: if (drawctxt) { 308: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 309: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, MATCH LINES: 424 412: } 413: 414: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 415: cmds[index++] = CP_SET_THREAD_BOTH; 416: 417: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 418: cmds[index++] = 0x100; /* IFPC enable */ 419: 420: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 421: cmds[index++] = CP_SET_THREAD_BR; 422: 423: /* 10 dwords */ 424: index += gen7_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 425: 426: /* Adjust the thing for the number of bytes we actually wrote */ 427: rb->_wptr -= (size - index); 428: 429: return gen7_ringbuffer_submit(rb, time); 430: } 431: 432: static u32 gen7_get_alwayson_counter(u32 *cmds, u64 gpuaddr) 433: { 434: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 435: cmds[1] = GEN7_CP_ALWAYS_ON_COUNTER_LO | (1 << 30) | (2 << 18); 436: cmds[2] = lower_32_bits(gpuaddr); 437: cmds[3] = upper_32_bits(gpuaddr); 438: 439: return 4; 440: } 441: 442: static u32 gen7_get_alwayson_context(u32 *cmds, u64 gpuaddr) 443: { 444: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 445: cmds[1] = GEN7_CP_ALWAYS_ON_CONTEXT_LO | (1 << 30) | (2 << 18); 446: cmds[2] = lower_32_bits(gpuaddr); 447: cmds[3] = upper_32_bits(gpuaddr); 448: MATCH LINES: 494 482: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 483: int ret; 484: 485: if (rb->drawctxt_active == drawctxt) 486: return 0; 487: 488: if (kgsl_context_detached(&drawctxt->base)) 489: return -ENOENT; 490: 491: if (!_kgsl_context_get(&drawctxt->base)) 492: return -ENOENT; 493: 494: ret = gen7_rb_context_switch(adreno_dev, rb, drawctxt); 495: if (ret) { 496: kgsl_context_put(&drawctxt->base); 497: return ret; 498: } 499: 500: trace_adreno_drawctxt_switch(rb, drawctxt); 501: 502: /* Release the current drawctxt as soon as the new one is switched */ 503: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active, 504: rb, rb->timestamp); 505: 506: rb->drawctxt_active = drawctxt; 507: return 0; 508: } 509: 510: 511: #define GEN7_USER_PROFILE_IB(rb, cmdobj, cmds, field) \ 512: gen7_get_user_profiling_ib((rb), (cmdobj), \ 513: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 514: (cmds)) 515: 516: #define GEN7_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 517: gen7_get_alwayson_counter((cmds), \ 518: (dev)->profile_buffer->gpuaddr + \ --- FILE: \adreno_gen7_snapshot.c | HITS: 2 --- MATCH LINES: 1895, 1896 1883: /* registers dumped through DBG AHB */ 1884: gen7_snapshot_dbgahb_regs(device, snapshot); 1885: 1886: /* Shader memory */ 1887: gen7_snapshot_shader(device, snapshot); 1888: 1889: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS_V2, 1890: snapshot, adreno_snapshot_registers_v2, 1891: (void *) gen7_snapshot_block_list->post_crashdumper_regs); 1892: 1893: kgsl_regwrite(device, GEN7_RBBM_SNAPSHOT_STATUS, 0x0); 1894: 1895: /* Preemption record */ 1896: adreno_snapshot_preemption_record(device, snapshot); 1897: 1898: if (is_current_rt) 1899: sched_set_fifo(current); 1900: } 1901: 1902: void gen7_crashdump_init(struct adreno_device *adreno_dev) 1903: { 1904: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1905: 1906: if (IS_ERR_OR_NULL(gen7_capturescript)) 1907: gen7_capturescript = kgsl_allocate_global(device, 1908: 3 * PAGE_SIZE, 0, KGSL_MEMFLAGS_GPUREADONLY, 1909: KGSL_MEMDESC_PRIVILEGED, "capturescript"); 1910: 1911: if (IS_ERR(gen7_capturescript)) 1912: return; 1913: 1914: if (IS_ERR_OR_NULL(gen7_crashdump_registers)) 1915: gen7_crashdump_registers = kgsl_allocate_global(device, 1916: 25 * PAGE_SIZE, 0, 0, KGSL_MEMDESC_PRIVILEGED, 1917: "capturescript_regs"); 1918: 1919: if (IS_ERR(gen7_crashdump_registers)) 1920: return; --- FILE: \adreno_gen8.c | HITS: 56 --- MATCH LINES: 129 117: BIT(CP_SW_SMMUFAULT) | \ 118: BIT(CP_SW_VBIFRESPCLIENT) | \ 119: BIT(CP_SW_VBIFRESPTYPE) | \ 120: BIT(CP_SW_VBIFRESPREAD) | \ 121: BIT(CP_SW_VBIFRESP) | \ 122: BIT(CP_SW_RTWROVF) | \ 123: BIT(CP_SW_LRZRTWROVF) | \ 124: BIT(CP_SW_LRZRTREFCNTOVF) | \ 125: BIT(CP_SW_LRZRTCLRRESMISS)) 126: 127: extern u32 adreno_slice_mask_override; 128: 129: /* IFPC & Preemption static powerup restore list */ 130: static const u32 gen8_pwrup_reglist[] = { 131: GEN8_UCHE_MODE_CNTL, 132: GEN8_UCHE_VARB_IDLE_TIMEOUT, 133: GEN8_UCHE_GBIF_GX_CONFIG, 134: GEN8_UCHE_CACHE_WAYS, 135: GEN8_UCHE_CCHE_MODE_CNTL, 136: GEN8_UCHE_CCHE_CACHE_WAYS, 137: GEN8_UCHE_CCHE_GC_GMEM_RANGE_MIN_LO, 138: GEN8_UCHE_CCHE_GC_GMEM_RANGE_MIN_HI, 139: GEN8_UCHE_CCHE_LPAC_GMEM_RANGE_MIN_LO, 140: GEN8_UCHE_CCHE_LPAC_GMEM_RANGE_MIN_HI, 141: GEN8_UCHE_CCHE_TRAP_BASE_LO, 142: GEN8_UCHE_CCHE_TRAP_BASE_HI, 143: GEN8_UCHE_CCHE_WRITE_THRU_BASE_LO, 144: GEN8_UCHE_CCHE_WRITE_THRU_BASE_HI, 145: GEN8_UCHE_HW_DBG_CNTL, 146: GEN8_UCHE_WRITE_THRU_BASE_LO, 147: GEN8_UCHE_WRITE_THRU_BASE_HI, 148: GEN8_UCHE_TRAP_BASE_LO, 149: GEN8_UCHE_TRAP_BASE_HI, 150: GEN8_UCHE_CLIENT_PF, 151: GEN8_VSC_KMD_DBG_ECO_CNTL, 152: GEN8_RB_CMP_NC_MODE_CNTL, 153: GEN8_SP_HLSQ_TIMEOUT_THRESHOLD_DP, MATCH LINES: 232 220: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_10, 221: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_11, 222: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_12, 223: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_13, 224: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_14, 225: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_15, 226: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_16, 227: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_17, 228: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_18, 229: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_19, 230: }; 231: 232: /* IFPC & Preemption static powerup restore list for gen8_3_0 */ 233: static const u32 gen8_3_0_pwrup_reglist[] = { 234: GEN8_UCHE_MODE_CNTL, 235: GEN8_UCHE_VARB_IDLE_TIMEOUT, 236: GEN8_UCHE_GBIF_GX_CONFIG, 237: GEN8_UCHE_CACHE_WAYS, 238: GEN8_UCHE_CCHE_MODE_CNTL, 239: GEN8_UCHE_CCHE_CACHE_WAYS, 240: GEN8_UCHE_CCHE_GC_GMEM_RANGE_MIN_LO, 241: GEN8_UCHE_CCHE_GC_GMEM_RANGE_MIN_HI, 242: GEN8_UCHE_CCHE_TRAP_BASE_LO, 243: GEN8_UCHE_CCHE_TRAP_BASE_HI, 244: GEN8_UCHE_CCHE_WRITE_THRU_BASE_LO, 245: GEN8_UCHE_CCHE_WRITE_THRU_BASE_HI, 246: GEN8_UCHE_HW_DBG_CNTL, 247: GEN8_UCHE_WRITE_THRU_BASE_LO, 248: GEN8_UCHE_WRITE_THRU_BASE_HI, 249: GEN8_UCHE_TRAP_BASE_LO, 250: GEN8_UCHE_TRAP_BASE_HI, 251: GEN8_UCHE_CLIENT_PF, 252: GEN8_RB_CMP_NC_MODE_CNTL, 253: GEN8_SP_HLSQ_TIMEOUT_THRESHOLD_DP, 254: GEN8_SP_HLSQ_GC_GMEM_RANGE_MIN_LO, 255: GEN8_SP_HLSQ_GC_GMEM_RANGE_MIN_HI, 256: GEN8_SP_READ_SEL, MATCH LINES: 281 269: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_10, 270: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_11, 271: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_12, 272: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_13, 273: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_14, 274: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_15, 275: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_16, 276: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_17, 277: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_18, 278: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_19, 279: }; 280: 281: /* IFPC & Preemption static powerup restore list for gen8_11_0 */ 282: static const u32 gen8_11_0_pwrup_reglist[] = { 283: GEN8_RB_CMP_NC_MODE_CNTL, 284: GEN8_SP_HLSQ_GC_GMEM_RANGE_MIN_LO, 285: GEN8_SP_HLSQ_GC_GMEM_RANGE_MIN_HI, 286: GEN8_SP_HLSQ_TIMEOUT_THRESHOLD_DP, 287: GEN8_SP_READ_SEL, 288: GEN8_CP_MULTIDRAW_CNTL, 289: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_0, 290: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_1, 291: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_2, 292: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_3, 293: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_4, 294: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_5, 295: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_6, 296: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_7, 297: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_8, 298: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_9, 299: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_10, 300: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_11, 301: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_12, 302: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_13, 303: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_14, 304: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_15, 305: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_16, MATCH LINES: 597 585: GEN8_CP_PROTECT_REG_GLOBAL + 38, 586: GEN8_CP_PROTECT_REG_GLOBAL + 39, 587: GEN8_CP_PROTECT_REG_GLOBAL + 40, 588: GEN8_CP_PROTECT_REG_GLOBAL + 41, 589: GEN8_CP_PROTECT_REG_GLOBAL + 42, 590: GEN8_CP_PROTECT_REG_GLOBAL + 43, 591: GEN8_CP_PROTECT_REG_GLOBAL + 44, 592: GEN8_CP_PROTECT_REG_GLOBAL + 45, 593: GEN8_CP_PROTECT_REG_GLOBAL + 46, 594: GEN8_CP_PROTECT_REG_GLOBAL + 63, 595: }; 596: 597: /* IFPC + Preemption static powerup restore list for gen8_1_0 */ 598: static const u32 gen8_1_0_pwrup_reglist[] = { 599: GEN8_SP_HLSQ_TIMEOUT_THRESHOLD_DP, 600: GEN8_SP_READ_SEL, 601: GEN8_UCHE_MODE_CNTL, 602: GEN8_UCHE_VARB_IDLE_TIMEOUT, 603: GEN8_UCHE_GBIF_GX_CONFIG, 604: GEN8_UCHE_CCHE_MODE_CNTL, 605: GEN8_UCHE_CCHE_CACHE_WAYS, 606: GEN8_UCHE_CCHE_GC_GMEM_RANGE_MIN_LO, 607: GEN8_UCHE_CCHE_GC_GMEM_RANGE_MIN_HI, 608: GEN8_UCHE_CCHE_TRAP_BASE_LO, 609: GEN8_UCHE_CCHE_TRAP_BASE_HI, 610: GEN8_UCHE_CCHE_WRITE_THRU_BASE_LO, 611: GEN8_UCHE_CCHE_WRITE_THRU_BASE_HI, 612: GEN8_UCHE_WRITE_THRU_BASE_LO, 613: GEN8_UCHE_WRITE_THRU_BASE_HI, 614: GEN8_UCHE_TRAP_BASE_LO, 615: GEN8_UCHE_TRAP_BASE_HI, 616: GEN8_UCHE_CLIENT_PF, 617: GEN8_RB_CMP_NC_MODE_CNTL, 618: GEN8_SP_HLSQ_GC_GMEM_RANGE_MIN_LO, 619: GEN8_SP_HLSQ_GC_GMEM_RANGE_MIN_HI, 620: GEN8_TPL1_NC_MODE_CNTL, 621: GEN8_TPL1_DBG_ECO_CNTL, MATCH LINES: 644, 654, 674 632: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_10, 633: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_11, 634: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_12, 635: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_13, 636: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_14, 637: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_15, 638: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_16, 639: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_17, 640: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_18, 641: GEN8_TPL1_BICUBIC_WEIGHTS_TABLE_19, 642: }; 643: 644: /* Dynamic IFPC + Preemption extlist for gen8_1_0 */ 645: static const struct gen8_pwrup_extlist gen8_1_0_pwrup_extlist[] = { 646: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 647: { GEN8_GRAS_NC_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 648: { GEN8_GRAS_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 649: { GEN8_PC_AUTO_VERTEX_STRIDE, BIT(PIPE_BV) | BIT(PIPE_BR) }, 650: { GEN8_PC_CHICKEN_BITS_1, BIT(PIPE_BV) | BIT(PIPE_BR) }, 651: { GEN8_PC_CHICKEN_BITS_2, BIT(PIPE_BV) | BIT(PIPE_BR) }, 652: { GEN8_PC_CHICKEN_BITS_3, BIT(PIPE_BV) | BIT(PIPE_BR) }, 653: { GEN8_PC_CHICKEN_BITS_4, BIT(PIPE_BV) | BIT(PIPE_BR) }, 654: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, BIT(PIPE_BV) | BIT(PIPE_BR) }, 655: { GEN8_PC_VIS_STREAM_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 656: { GEN8_RB_CCU_NC_MODE_CNTL, BIT(PIPE_BR) }, 657: { GEN8_RB_CMP_NC_MODE_CNTL, BIT(PIPE_BR) }, 658: { GEN8_RB_RESOLVE_PREFETCH_CNTL, BIT(PIPE_BR) }, 659: /* Note: RB_DBG_ECO_CNTL intentionally absent (x285 differs from a840) */ 660: { GEN8_RB_CMP_DBG_ECO_CNTL, BIT(PIPE_BR) }, 661: { GEN8_VFD_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 662: { GEN8_VFD_CB_BV_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR) }, 663: { GEN8_VFD_CB_BR_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR) }, 664: { GEN8_VFD_CB_BUSY_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR) }, 665: { GEN8_VFD_CB_LP_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR) }, 666: { GEN8_VPC_FLATSHADE_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 667: { GEN8_CP_HW_FAULT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 668: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 669: { GEN8_CP_INTERRUPT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 670: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 671: { GEN8_CP_PROTECT_CNTL_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) }, 672: { GEN8_CP_PROTECT_REG_PIPE + 15, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) }, 673: { GEN8_RB_GC_GMEM_PROTECT, BIT(PIPE_BR) }, 674: { GEN8_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, BIT(PIPE_BR) }, 675: }; 676: 677: /* IFPC only static powerup restore list for gen8_11_0 */ 678: static const u32 gen8_11_0_ifpc_pwrup_reglist[] = { 679: GEN8_CP_INTERRUPT_STATUS_MASK_GLOBAL, 680: GEN8_RBBM_NC_MODE_CNTL, 681: GEN8_RBBM_SLICE_INTERFACE_HANG_INT_CNTL, 682: GEN8_RBBM_SLICE_NC_MODE_CNTL, 683: GEN8_RBBM_SLICE_PERFCTR_CNTL, 684: GEN8_SP_CHICKEN_BITS, 685: GEN8_SP_CHICKEN_BITS_2, 686: GEN8_SP_CHICKEN_BITS_3, 687: GEN8_SP_CHICKEN_BITS_5, 688: GEN8_SP_HLSQ_DBG_ECO_CNTL, 689: GEN8_SP_HLSQ_DBG_ECO_CNTL_1, 690: GEN8_SP_HLSQ_DBG_ECO_CNTL_3, 691: GEN8_SP_HLSQ_LPAC_GMEM_RANGE_MIN_LO, 692: GEN8_SP_HLSQ_LPAC_GMEM_RANGE_MIN_HI, 693: GEN8_SP_NC_MODE_CNTL, 694: GEN8_SP_PERFCTR_SHADER_MASK, 695: GEN8_SP_L0_PERF_TUNE, 696: GEN8_CP_PROTECT_REG_GLOBAL + 0, 697: GEN8_CP_PROTECT_REG_GLOBAL + 1, 698: GEN8_CP_PROTECT_REG_GLOBAL + 2, MATCH LINES: 771, 779, 796, 819, 834, 842, 863, 873 759: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 760: { GEN8_CP_PROTECT_CNTL_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC)}, 761: { GEN8_CP_PROTECT_REG_PIPE + 15, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC)}, 762: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 763: { GEN8_GRAS_NC_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 764: { GEN8_GRAS_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 765: { GEN8_RB_CCU_CNTL, BIT(PIPE_BR)}, 766: { GEN8_RB_CCU_NC_MODE_CNTL, BIT(PIPE_BR)}, 767: { GEN8_RB_CMP_NC_MODE_CNTL, BIT(PIPE_BR)}, 768: { GEN8_RB_RESOLVE_PREFETCH_CNTL, BIT(PIPE_BR)}, 769: { GEN8_RB_CMP_DBG_ECO_CNTL, BIT(PIPE_BR)}, 770: { GEN8_RB_GC_GMEM_PROTECT, BIT(PIPE_BR)}, 771: { GEN8_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, BIT(PIPE_BR)}, 772: { GEN8_VPC_FLATSHADE_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 773: { GEN8_PC_CHICKEN_BITS_1, BIT(PIPE_BV) | BIT(PIPE_BR)}, 774: { GEN8_PC_CHICKEN_BITS_2, BIT(PIPE_BV) | BIT(PIPE_BR)}, 775: { GEN8_PC_CHICKEN_BITS_3, BIT(PIPE_BV) | BIT(PIPE_BR)}, 776: { GEN8_PC_CHICKEN_BITS_4, BIT(PIPE_BV) | BIT(PIPE_BR)}, 777: { GEN8_PC_AUTO_VERTEX_STRIDE, BIT(PIPE_BR) | BIT(PIPE_BV)}, 778: { GEN8_PC_VIS_STREAM_CNTL, BIT(PIPE_BR) | BIT(PIPE_BV)}, 779: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, BIT(PIPE_BR) | BIT(PIPE_BV)}, 780: { GEN8_VFD_CB_BV_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR)}, 781: { GEN8_VFD_CB_BR_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR)}, 782: { GEN8_VFD_CB_BUSY_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR)}, 783: { GEN8_VFD_CB_LP_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR)}, 784: { GEN8_VFD_DBG_ECO_CNTL, BIT(PIPE_BR) | BIT(PIPE_BV)}, 785: }; 786: 787: static const struct gen8_pwrup_extlist gen8_2_0_pwrup_extlist[] = { 788: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 789: { GEN8_GRAS_NC_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 790: { GEN8_GRAS_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 791: { GEN8_PC_AUTO_VERTEX_STRIDE, BIT(PIPE_BV) | BIT(PIPE_BR) }, 792: { GEN8_PC_CHICKEN_BITS_1, BIT(PIPE_BV) | BIT(PIPE_BR) }, 793: { GEN8_PC_CHICKEN_BITS_2, BIT(PIPE_BV) | BIT(PIPE_BR) }, 794: { GEN8_PC_CHICKEN_BITS_3, BIT(PIPE_BV) | BIT(PIPE_BR) }, 795: { GEN8_PC_CHICKEN_BITS_4, BIT(PIPE_BV) | BIT(PIPE_BR) }, 796: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, BIT(PIPE_BV) | BIT(PIPE_BR) }, 797: { GEN8_PC_VIS_STREAM_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 798: { GEN8_RB_CCU_CNTL, BIT(PIPE_BR) }, 799: { GEN8_RB_CCU_DBG_ECO_CNTL, BIT(PIPE_BR)}, 800: { GEN8_RB_CCU_NC_MODE_CNTL, BIT(PIPE_BR) }, 801: { GEN8_RB_CMP_NC_MODE_CNTL, BIT(PIPE_BR) }, 802: { GEN8_RB_RBP_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 803: { GEN8_RB_RESOLVE_PREFETCH_CNTL, BIT(PIPE_BR) }, 804: { GEN8_RB_CMP_DBG_ECO_CNTL, BIT(PIPE_BR) }, 805: { GEN8_VFD_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 806: { GEN8_VFD_CB_BV_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR) }, 807: { GEN8_VFD_CB_BR_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR) }, 808: { GEN8_VFD_CB_BUSY_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR) }, 809: { GEN8_VFD_CB_LP_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR) }, 810: { GEN8_VPC_FLATSHADE_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 811: { GEN8_CP_HW_FAULT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 812: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 813: { GEN8_CP_INTERRUPT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 814: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 815: { GEN8_CP_PROTECT_CNTL_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC)}, 816: { GEN8_CP_PROTECT_REG_PIPE + 15, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) }, 817: { GEN8_RB_GC_GMEM_PROTECT, BIT(PIPE_BR) }, 818: { GEN8_RB_LPAC_GMEM_PROTECT, BIT(PIPE_BR) }, 819: { GEN8_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, BIT(PIPE_BR) }, 820: }; 821: 822: static const struct gen8_pwrup_extlist gen8_3_0_pwrup_extlist[] = { 823: { GEN8_CP_PROTECT_CNTL_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) }, 824: { GEN8_CP_PROTECT_REG_PIPE + 15, BIT(PIPE_BR) | BIT(PIPE_BV) }, 825: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 826: { GEN8_GRAS_NC_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 827: { GEN8_GRAS_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 828: { GEN8_RB_CCU_CNTL, BIT(PIPE_BR)}, 829: { GEN8_RB_CCU_NC_MODE_CNTL, BIT(PIPE_BR)}, 830: { GEN8_RB_CMP_NC_MODE_CNTL, BIT(PIPE_BR)}, 831: { GEN8_RB_RESOLVE_PREFETCH_CNTL, BIT(PIPE_BR)}, 832: { GEN8_RB_CMP_DBG_ECO_CNTL, BIT(PIPE_BR)}, 833: { GEN8_RB_GC_GMEM_PROTECT, BIT(PIPE_BR)}, 834: { GEN8_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, BIT(PIPE_BR)}, 835: { GEN8_VPC_FLATSHADE_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 836: { GEN8_PC_CHICKEN_BITS_1, BIT(PIPE_BV) | BIT(PIPE_BR)}, 837: { GEN8_PC_CHICKEN_BITS_2, BIT(PIPE_BV) | BIT(PIPE_BR)}, 838: { GEN8_PC_CHICKEN_BITS_3, BIT(PIPE_BV) | BIT(PIPE_BR)}, 839: { GEN8_PC_CHICKEN_BITS_4, BIT(PIPE_BV) | BIT(PIPE_BR)}, 840: { GEN8_PC_AUTO_VERTEX_STRIDE, BIT(PIPE_BR) | BIT(PIPE_BV)}, 841: { GEN8_PC_VIS_STREAM_CNTL, BIT(PIPE_BR) | BIT(PIPE_BV)}, 842: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, BIT(PIPE_BR) | BIT(PIPE_BV)}, 843: { GEN8_VFD_CB_BV_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR)}, 844: { GEN8_VFD_CB_BR_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR)}, 845: { GEN8_VFD_CB_BUSY_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR)}, 846: { GEN8_VFD_CB_LP_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR)}, 847: { GEN8_VFD_DBG_ECO_CNTL, BIT(PIPE_BR) | BIT(PIPE_BV)}, 848: }; 849: 850: /* Static powerup external list for gen8_11_0 */ 851: static const struct gen8_pwrup_extlist gen8_11_0_pwrup_extlist[] = { 852: { GEN8_CP_HW_FAULT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 853: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 854: { GEN8_CP_INTERRUPT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 855: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 856: { GEN8_CP_PROTECT_CNTL_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC)}, 857: { GEN8_CP_PROTECT_REG_PIPE + 15, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) }, 858: { GEN8_GRAS_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 859: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 860: { GEN8_GRAS_NC_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 861: { GEN8_PC_AUTO_VERTEX_STRIDE, BIT(PIPE_BV) | BIT(PIPE_BR) }, 862: { GEN8_PC_VIS_STREAM_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 863: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, BIT(PIPE_BV) | BIT(PIPE_BR) }, 864: { GEN8_PC_CHICKEN_BITS_1, BIT(PIPE_BV) | BIT(PIPE_BR) }, 865: { GEN8_PC_CHICKEN_BITS_2, BIT(PIPE_BV) | BIT(PIPE_BR) }, 866: { GEN8_PC_CHICKEN_BITS_3, BIT(PIPE_BV) | BIT(PIPE_BR) }, 867: { GEN8_PC_CHICKEN_BITS_4, BIT(PIPE_BV) | BIT(PIPE_BR) }, 868: { GEN8_PC_CHICKEN_BITS_5, BIT(PIPE_BV) | BIT(PIPE_BR) }, 869: { GEN8_RB_CCU_CNTL, BIT(PIPE_BR) }, 870: { GEN8_RB_CCU_DBG_ECO_CNTL, BIT(PIPE_BR)}, 871: { GEN8_RB_CCU_NC_MODE_CNTL, BIT(PIPE_BR) }, 872: { GEN8_RB_CMP_NC_MODE_CNTL, BIT(PIPE_BR) }, 873: { GEN8_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, BIT(PIPE_BR) }, 874: { GEN8_RB_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 875: { GEN8_RB_RBP_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 876: { GEN8_RB_RESOLVE_PREFETCH_CNTL, BIT(PIPE_BR) }, 877: { GEN8_RB_CMP_DBG_ECO_CNTL, BIT(PIPE_BR) }, 878: { GEN8_RB_GC_GMEM_PROTECT, BIT(PIPE_BR) }, 879: { GEN8_RB_LPAC_GMEM_PROTECT, BIT(PIPE_BR) }, 880: { GEN8_VFD_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 881: { GEN8_VFD_CB_BV_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR) }, 882: { GEN8_VFD_CB_BR_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR) }, 883: { GEN8_VFD_CB_BUSY_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR) }, 884: { GEN8_VFD_CB_LP_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR) }, 885: { GEN8_VPC_FLATSHADE_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 886: }; 887: 888: struct gen8_nonctxt_overrides gen8_nc_overrides[] = { 889: { GEN8_CP_RESERVED_REG_0, BIT(PIPE_NONE), 0, 0, 1, }, 890: { GEN8_CP_CHICKEN_DBG_PIPE, BIT(PIPE_BV) | BIT(PIPE_BR) | BIT(PIPE_LPAC) | BIT(PIPE_AQE0) | 891: BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV), 0, 0, 0, }, 892: { GEN8_CP_MULTIDRAW_CNTL, BIT(PIPE_NONE), 0, 0, 0, }, 893: { GEN8_GPU_CX_MISC_SMMU_INTR_MASK0, BIT(PIPE_NONE), 0, 0, 0, }, 894: { GEN8_GPU_CX_MISC_SMMU_INTR_MASK1, BIT(PIPE_NONE), 0, 0, 0, }, 895: { GEN8_UCHE_MODE_CNTL, BIT(PIPE_NONE), 0, 0, 0, }, 896: { GEN8_UCHE_CACHE_WAYS, BIT(PIPE_NONE), 0, 0, 0, }, 897: { GEN8_UCHE_CLIENT_PF, BIT(PIPE_NONE), 0, 0, 0, }, MATCH LINES: 1122 1110: cmds[i++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 1111: cmds[i++] = BIT(27); 1112: 1113: /* Use multiple HW contexts */ 1114: mask |= BIT(0); 1115: 1116: /* Enable error detection */ 1117: mask |= BIT(1); 1118: 1119: /* Set default reset state */ 1120: mask |= BIT(3); 1121: 1122: /* Disable save/restore of performance counters across preemption */ 1123: mask |= BIT(6); 1124: 1125: /* Enable the register init list with the spinlock */ 1126: mask |= BIT(8); 1127: 1128: cmds[i++] = cp_type7_packet(CP_ME_INIT, 7); 1129: 1130: /* Enabled ordinal mask */ 1131: cmds[i++] = mask; 1132: cmds[i++] = 0x00000003; /* Set number of HW contexts */ 1133: cmds[i++] = 0x20000000; /* Enable error detection */ 1134: cmds[i++] = 0x00000002; /* Operation mode mask */ 1135: 1136: /* Register initialization list with spinlock */ 1137: cmds[i++] = lower_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 1138: cmds[i++] = upper_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 1139: /* 1140: * Gen8 targets with concurrent binning are expected to have a dynamic 1141: * power up list with triplets which contains the pipe id in it. 1142: * Bit 31 of POWER_UP_REGISTER_LIST_LENGTH is reused here to let CP 1143: * know if the power up contains the triplets. If 1144: * REGISTER_INIT_LIST_WITH_SPINLOCK is set and bit 31 below is set, 1145: * CP expects a dynamic list with triplets. 1146: */ MATCH LINES: 1757, 1774 1745: reglist[items].regs = gen8_1_0_ifpc_pwrup_reglist; 1746: reglist[items].count = ARRAY_SIZE(gen8_1_0_ifpc_pwrup_reglist); 1747: } else if (adreno_is_gen8_11_x(adreno_dev)) { 1748: reglist[items].regs = gen8_11_0_ifpc_pwrup_reglist; 1749: reglist[items].count = ARRAY_SIZE(gen8_11_0_ifpc_pwrup_reglist); 1750: } else { 1751: reglist[items].regs = gen8_ifpc_pwrup_reglist; 1752: reglist[items].count = ARRAY_SIZE(gen8_ifpc_pwrup_reglist); 1753: } 1754: lock->ifpc_list_len = reglist[items].count; 1755: items++; 1756: 1757: /* Static IFPC + preemption registers */ 1758: if (adreno_is_gen8_3_0(adreno_dev) || adreno_is_gen8_8_0(adreno_dev)) { 1759: reglist[items].regs = gen8_3_0_pwrup_reglist; 1760: reglist[items].count = ARRAY_SIZE(gen8_3_0_pwrup_reglist); 1761: } else if (adreno_is_gen8_2_x(adreno_dev)) { 1762: reglist[items].regs = gen8_2_0_pwrup_reglist; 1763: reglist[items].count = ARRAY_SIZE(gen8_2_0_pwrup_reglist); 1764: } else if (adreno_is_gen8_1_0(adreno_dev)) { 1765: reglist[items].regs = gen8_1_0_pwrup_reglist; 1766: reglist[items].count = ARRAY_SIZE(gen8_1_0_pwrup_reglist); 1767: } else if (adreno_is_gen8_11_x(adreno_dev)) { 1768: reglist[items].regs = gen8_11_0_pwrup_reglist; 1769: reglist[items].count = ARRAY_SIZE(gen8_11_0_pwrup_reglist); 1770: } else { 1771: reglist[items].regs = gen8_pwrup_reglist; 1772: reglist[items].count = ARRAY_SIZE(gen8_pwrup_reglist); 1773: } 1774: lock->preemption_list_len = reglist[items].count; 1775: items++; 1776: 1777: /* 1778: * For each entry in each of the lists, write the offset and the current 1779: * register value into the GPU buffer 1780: */ 1781: for (i = 0; i < items; i++) { 1782: const u32 *r = reglist[i].regs; 1783: 1784: for (j = 0; j < reglist[i].count; j++) { 1785: *dest++ = r[j]; 1786: kgsl_regread(device, r[j], dest++); 1787: } 1788: 1789: if ((r == gen8_ifpc_pwrup_reglist || 1790: r == gen8_1_0_ifpc_pwrup_reglist || 1791: r == gen8_2_0_ifpc_pwrup_reglist || 1792: r == gen8_3_0_ifpc_pwrup_reglist || 1793: r == gen8_11_0_ifpc_pwrup_reglist)) { 1794: u32 cs_len = adreno_coresight_patch_pwrup_reglist(adreno_dev, dest); 1795: 1796: lock->ifpc_list_len += cs_len; 1797: dest += (cs_len * 2); 1798: } MATCH LINES: 1825, 1835, 1836, 1839 1813: (nc_overrides[j].list_type == 1)) { 1814: *dest++ = nc_overrides[j].offset; 1815: kgsl_regread(device, nc_overrides[j].offset, dest++); 1816: lock->ifpc_list_len++; 1817: } else if ((reglist[i].regs == gen8_pwrup_reglist || 1818: reglist[i].regs == gen8_1_0_pwrup_reglist || 1819: reglist[i].regs == gen8_3_0_pwrup_reglist || 1820: reglist[i].regs == gen8_2_0_pwrup_reglist || 1821: reglist[i].regs == gen8_11_0_pwrup_reglist) && 1822: (nc_overrides[j].list_type == 2)) { 1823: *dest++ = nc_overrides[j].offset; 1824: kgsl_regread(device, nc_overrides[j].offset, dest++); 1825: lock->preemption_list_len++; 1826: } 1827: } 1828: mutex_unlock(&gen8_dev->nc_mutex); 1829: 1830: } 1831: 1832: /* 1833: * The overall register list is composed of 1834: * 1. Static IFPC-only registers 1835: * 2. Static IFPC + preemption registers 1836: * 3. Dynamic IFPC + preemption registers (ex: perfcounter selects) 1837: * 1838: * The first two lists are static. Size of these lists are stored as 1839: * number of pairs in ifpc_list_len and preemption_list_len 1840: * respectively. With concurrent binning, Some of the perfcounter 1841: * registers being virtualized, CP needs to know the pipe id to program 1842: * the aperture inorder to restore the same. Thus, third list is a 1843: * dynamic list with triplets as 1844: * (
), and the length is 1845: * stored as number for triplets in dynamic_list_len. 1846: * 1847: * Starting with Gen8, some of the registers that are initialized statically 1848: * by the kernel are pipe-specific. Because only the dynamic list is able to 1849: * support specifying a pipe ID, these registers are bundled along with any 1850: * dynamic entries such as perf counter selects into a single dynamic list. 1851: */ 1852: 1853: gen8_dev->ext_pwrup_list_len = 0; 1854: 1855: /* 1856: * Write external pipe specific regs (
- triplets) 1857: * offset and the current value into GPU buffer 1858: */ 1859: for (pipe_id = PIPE_BR; pipe_id <= PIPE_DDE_BV; pipe_id++) { 1860: const struct gen8_pwrup_extlist *ext_list; 1861: u32 ext_len; 1862: 1863: if (adreno_is_gen8_2_x(adreno_dev)) { MATCH LINES: 2206, 2207, 2209 2194: 2195: /* Program noncontext registers */ 2196: gen8_nonctxt_regconfig(adreno_dev); 2197: 2198: /* Read GPU registers with the GMU OOB set to update adreno props */ 2199: gen8_setup_adreno_props(adreno_dev); 2200: 2201: /* Enable hardware hang detection */ 2202: kgsl_regwrite(device, GEN8_RBBM_INTERFACE_HANG_INT_CNTL, BIT(30) | 2203: FIELD_PREP(GENMASK(27, 0), gen8_core->hang_detect_cycles)); 2204: kgsl_regwrite(device, GEN8_RBBM_SLICE_INTERFACE_HANG_INT_CNTL, BIT(30)); 2205: 2206: /* Enable the GMEM save/restore feature for preemption */ 2207: if (adreno_is_preemption_enabled(adreno_dev)) { 2208: gen8_regwrite_aperture(device, 2209: GEN8_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, 2210: 0x1, PIPE_BR, 0, 0); 2211: /* Clear aperture register */ 2212: gen8_host_aperture_set(adreno_dev, 0, 0, 0); 2213: } 2214: 2215: /* Enable GMU power counter 0 to count GPU busy */ 2216: kgsl_regwrite(device, GEN8_GMUAO_GPU_CX_BUSY_MASK, 0xff000000); 2217: kgsl_regrmw(device, GEN8_GMUCX_POWER_COUNTER_SELECT_XOCLK_0, 0xFF, 0x20); 2218: kgsl_regwrite(device, GEN8_GMUCX_POWER_COUNTER_ENABLE, 0x1); 2219: 2220: gen8_protect_init(adreno_dev); 2221: 2222: /* Configure LLCC */ 2223: _llc_configure_gpu_scid(adreno_dev); 2224: _llc_gpuhtw_slice_activate(adreno_dev); 2225: 2226: for (pipe_id = PIPE_BR; pipe_id <= PIPE_DDE_BV; pipe_id++) { 2227: u32 val = CP_SW_FAULT_STATUS_MASK_PIPE; 2228: 2229: if ((pipe_id == PIPE_LPAC) && !ADRENO_FEATURE(adreno_dev, ADRENO_LPAC)) 2230: continue; 2231: if (((pipe_id == PIPE_AQE0) || (pipe_id == PIPE_AQE1)) && 2232: !ADRENO_FEATURE(adreno_dev, ADRENO_AQE)) 2233: continue; MATCH LINES: 2393, 2398, 2402, 2407, 2414, 2417, 2418, 2419, 2422, 2423, 2424, 2427, 2433, 2436, 2440, 2448, 2474, 2477 2381: rb->wptr = 0; 2382: rb->_wptr = 0; 2383: } 2384: 2385: return ret; 2386: } 2387: 2388: static int gen8_post_start(struct adreno_device *adreno_dev) 2389: { 2390: int ret; 2391: u32 *cmds; 2392: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 2393: struct adreno_preemption *preempt = &adreno_dev->preempt; 2394: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2395: u64 kmd_postamble_addr; 2396: u32 count = 9; 2397: 2398: if (!adreno_is_preemption_enabled(adreno_dev)) 2399: return 0; 2400: 2401: kmd_postamble_addr = SCRATCH_POSTAMBLE_ADDR(KGSL_DEVICE(adreno_dev)); 2402: gen8_preemption_prepare_postamble(adreno_dev); 2403: 2404: if (kgsl_mmu_is_secured(&device->mmu)) 2405: count += 3; 2406: 2407: if (preempt->postamble_bootup_len) 2408: count += 4; 2409: 2410: cmds = adreno_ringbuffer_allocspace(rb, count); 2411: if (IS_ERR(cmds)) 2412: return PTR_ERR(cmds); 2413: 2414: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 2415: kgsl_mmu_is_secured(&device->mmu) ? 6 : 3); 2416: 2417: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 2418: *cmds++ = lower_32_bits(rb->preemption_desc->gpuaddr); 2419: *cmds++ = upper_32_bits(rb->preemption_desc->gpuaddr); 2420: 2421: if (kgsl_mmu_is_secured(&device->mmu)) { 2422: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 2423: *cmds++ = lower_32_bits(rb->secure_preemption_desc->gpuaddr); 2424: *cmds++ = upper_32_bits(rb->secure_preemption_desc->gpuaddr); 2425: } 2426: 2427: if (preempt->postamble_bootup_len) { 2428: *cmds++ = cp_type7_packet(CP_SET_AMBLE, 3); 2429: *cmds++ = lower_32_bits(kmd_postamble_addr); 2430: *cmds++ = upper_32_bits(kmd_postamble_addr); 2431: *cmds++ = FIELD_PREP(GENMASK(22, 20), CP_KMD_AMBLE_TYPE) 2432: | (FIELD_PREP(GENMASK(19, 0), 2433: adreno_dev->preempt.postamble_bootup_len)); 2434: } 2435: 2436: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 2437: *cmds++ = 0; 2438: *cmds++ = 0; 2439: *cmds++ = 0; 2440: /* generate interrupt on preemption completion */ 2441: *cmds++ = 0; 2442: 2443: ret = gen8_ringbuffer_submit(rb, NULL); 2444: if (!ret) { 2445: ret = adreno_spin_idle(adreno_dev, 2000); 2446: if (ret) 2447: gen8_spin_idle_debug(adreno_dev, 2448: "hw preemption initialization failed to idle\n"); 2449: } 2450: 2451: return ret; 2452: } 2453: 2454: int gen8_rb_start(struct adreno_device *adreno_dev) 2455: { 2456: const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev); 2457: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 2458: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2459: struct adreno_ringbuffer *rb; 2460: u64 addr; 2461: int ret, i; 2462: u32 *cmds; 2463: 2464: /* Clear all the ringbuffers */ 2465: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2466: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 2467: kgsl_sharedmem_writel(device->scratch, 2468: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 2469: kgsl_sharedmem_writel(device->scratch, 2470: SCRATCH_RB_OFFSET(rb->id, bv_rptr), 0); 2471: 2472: rb->wptr = 0; 2473: rb->_wptr = 0; 2474: rb->wptr_preempt_end = UINT_MAX; 2475: } 2476: 2477: gen8_preemption_start(adreno_dev); 2478: 2479: /* Set up the current ringbuffer */ 2480: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 2481: 2482: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 2483: kgsl_regwrite(device, GEN8_CP_RB_RPTR_ADDR_LO_BR, lower_32_bits(addr)); 2484: kgsl_regwrite(device, GEN8_CP_RB_RPTR_ADDR_HI_BR, upper_32_bits(addr)); 2485: 2486: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, bv_rptr); 2487: kgsl_regwrite(device, GEN8_CP_RB_RPTR_ADDR_LO_BV, lower_32_bits(addr)); 2488: kgsl_regwrite(device, GEN8_CP_RB_RPTR_ADDR_HI_BV, upper_32_bits(addr)); 2489: 2490: kgsl_regwrite(device, GEN8_CP_RB_CNTL_GC, GEN8_CP_RB_CNTL_DEFAULT); 2491: 2492: kgsl_regwrite(device, GEN8_CP_RB_BASE_LO_GC, 2493: lower_32_bits(rb->buffer_desc->gpuaddr)); 2494: kgsl_regwrite(device, GEN8_CP_RB_BASE_HI_GC, 2495: upper_32_bits(rb->buffer_desc->gpuaddr)); 2496: 2497: /* Program the ucode base for CP */ 2498: kgsl_regwrite(device, GEN8_CP_SQE_INSTR_BASE_LO, 2499: lower_32_bits(fw->memdesc->gpuaddr)); 2500: kgsl_regwrite(device, GEN8_CP_SQE_INSTR_BASE_HI, 2501: upper_32_bits(fw->memdesc->gpuaddr)); MATCH LINES: 2901, 2902 2889: case 0x8: 2890: return gen8_fault_block_uche(device, str, sizeof(str), true); 2891: case 0x9: 2892: return "UCHE_HPAC"; 2893: } 2894: 2895: snprintf(str, sizeof(str), "Unknown (mid: %u)", mid); 2896: return str; 2897: } 2898: 2899: static void gen8_cp_callback(struct adreno_device *adreno_dev, int bit) 2900: { 2901: if (adreno_is_preemption_enabled(adreno_dev)) 2902: gen8_preemption_trigger(adreno_dev, true); 2903: 2904: adreno_scheduler_queue(adreno_dev); 2905: } 2906: 2907: /* 2908: * gen8_gpc_err_int_callback() - Isr for GPC error interrupts 2909: * @adreno_dev: Pointer to device 2910: * @bit: Interrupt bit 2911: */ 2912: static void gen8_gpc_err_int_callback(struct adreno_device *adreno_dev, int bit) 2913: { 2914: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2915: 2916: /* 2917: * GPC error is typically the result of mistake SW programming. 2918: * Force GPU fault for this interrupt so that we can debug it 2919: * with help of register dump. 2920: */ 2921: 2922: dev_crit(device->dev, "RBBM: GPC error\n"); 2923: adreno_irqctrl(adreno_dev, 0); 2924: 2925: /* Trigger a fault in the dispatcher - this will effect a restart */ 2926: adreno_scheduler_fault(adreno_dev, ADRENO_SOFT_FAULT); MATCH LINES: 2993 2981: adreno_scheduler_fault(adreno_dev, ADRENO_HARD_FAULT); 2982: } 2983: 2984: static const struct adreno_irq_funcs gen8_irq_funcs[32] = { 2985: ADRENO_IRQ_CALLBACK(NULL), /* 0 - RBBM_GPU_IDLE */ 2986: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 1 - RBBM_AHB_ERROR */ 2987: ADRENO_IRQ_CALLBACK(NULL), /* 2 - UNUSED */ 2988: ADRENO_IRQ_CALLBACK(NULL), /* 3 - UNUSED */ 2989: ADRENO_IRQ_CALLBACK(NULL), /* 4 - CPIPCINT0 */ 2990: ADRENO_IRQ_CALLBACK(NULL), /* 5 - CPIPCINT1 */ 2991: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 6 - ATBASYNCOVERFLOW */ 2992: ADRENO_IRQ_CALLBACK(gen8_gpc_err_int_callback), /* 7 - GPC_ERR */ 2993: ADRENO_IRQ_CALLBACK(gen8_preemption_callback),/* 8 - CP_SW */ 2994: ADRENO_IRQ_CALLBACK(gen8_cp_hw_err_callback), /* 9 - CP_HW_ERROR */ 2995: ADRENO_IRQ_CALLBACK(NULL), /* 10 - CP_CCU_FLUSH_DEPTH_TS */ 2996: ADRENO_IRQ_CALLBACK(NULL), /* 11 - CP_CCU_FLUSH_COLOR_TS */ 2997: ADRENO_IRQ_CALLBACK(NULL), /* 12 - CP_CCU_RESOLVE_TS */ 2998: ADRENO_IRQ_CALLBACK(NULL), /* 13 - UNUSED */ 2999: ADRENO_IRQ_CALLBACK(NULL), /* 14 - UNUSED */ 3000: ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 15 - CP_RB_INT */ 3001: ADRENO_IRQ_CALLBACK(NULL), /* 16 - CP_RB_INT_LPAC*/ 3002: ADRENO_IRQ_CALLBACK(NULL), /* 17 - CP_RB_DONE_TS */ 3003: ADRENO_IRQ_CALLBACK(NULL), /* 18 - UNUSED */ 3004: ADRENO_IRQ_CALLBACK(NULL), /* 19 - UNUSED */ 3005: ADRENO_IRQ_CALLBACK(gen8_cp_callback), /* 20 - CP_CACHE_FLUSH_TS */ 3006: ADRENO_IRQ_CALLBACK(NULL), /* 21 - CP_CACHE_TS_LPAC */ 3007: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 22 - RBBM_ATB_BUS_OVERFLOW */ 3008: ADRENO_IRQ_CALLBACK(adreno_hang_int_callback), /* 23 - MISHANGDETECT */ 3009: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 24 - UCHE_OOB_ACCESS */ 3010: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 25 - UCHE_TRAP_INTR */ 3011: ADRENO_IRQ_CALLBACK(gen8_dbgc_intr_callback), /* 26 - DEBUG_BUS_INTR_0 */ 3012: ADRENO_IRQ_CALLBACK(gen8_dbgc_intr_callback), /* 27 - DEBUG_BUS_INTR_1 */ 3013: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 28 - TSBWRITEERROR */ 3014: ADRENO_IRQ_CALLBACK(gen8_swfuse_violation_callback), /* 29 - SWFUSEVIOLATION */ 3015: ADRENO_IRQ_CALLBACK(NULL), /* 30 - ISDB_CPU_IRQ */ 3016: ADRENO_IRQ_CALLBACK(NULL), /* 31 - ISDB_UNDER_DEBUG */ 3017: }; MATCH LINES: 3173, 3177, 3178, 3179, 3180 3161: kgsl_pwrscale_fast_bus_hint(gen8_core->fast_bus_hint); 3162: device->pwrctrl.cx_cfg_gdsc_offset = GEN8_GPU_CC_CX_CFG_GDSCR; 3163: 3164: device->pwrctrl.rt_bus_hint = gen8_core->rt_bus_hint; 3165: 3166: device->cx_host_irq_num = kgsl_request_irq_optional(pdev, 3167: "cx_host_irq", gen8_cx_host_irq_handler, device); 3168: 3169: ret = adreno_device_probe(pdev, adreno_dev); 3170: if (ret) 3171: return ret; 3172: 3173: if (adreno_preemption_feature_set(adreno_dev)) { 3174: adreno_dev->total_ctxt_record_sz = gen8_core->ctxt_record_size ? 3175: gen8_core->ctxt_record_size : GEN8_CP_CTXRECORD_SIZE_IN_BYTES; 3176: 3177: adreno_dev->preempt.preempt_level = gen8_core->preempt_level; 3178: adreno_dev->preempt.skipsaverestore = true; 3179: adreno_dev->preempt.usesgmem = true; 3180: set_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 3181: } 3182: 3183: /* debugfs node for ACD calibration */ 3184: debugfs_create_file("acd_calibrate", 0644, device->d_debugfs, device, &acd_cal_fops); 3185: 3186: gen8_coresight_init(adreno_dev); 3187: 3188: /* Dump additional AQE 16KB data on top of default 128KB(64(BR)+64(BV)) */ 3189: device->snapshot_ctxt_record_size = ADRENO_FEATURE(adreno_dev, ADRENO_AQE) ? 3190: (GEN8_SNAPSHOT_CTXRECORD_SIZE_IN_BYTES + GEN8_CP_AQE_CTXRECORD_SIZE_IN_BYTES) : 3191: GEN8_SNAPSHOT_CTXRECORD_SIZE_IN_BYTES; 3192: 3193: return 0; 3194: } 3195: 3196: /* Register offset defines for Gen8, in order of enum adreno_regs */ 3197: static u32 gen8_register_offsets[ADRENO_REG_REGISTER_MAX] = { 3198: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_BASE, GEN8_CP_RB_BASE_LO_GC), 3199: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_BASE_HI, GEN8_CP_RB_BASE_HI_GC), 3200: ADRENO_REG_DEFINE(ADRENO_REG_CP_LPAC_RB_BASE, GEN8_CP_RB_BASE_LO_LPAC), 3201: ADRENO_REG_DEFINE(ADRENO_REG_CP_LPAC_RB_BASE_HI, GEN8_CP_RB_BASE_HI_LPAC), 3202: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_RPTR, GEN8_CP_RB_RPTR_BR), 3203: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_WPTR, GEN8_CP_RB_WPTR_GC), 3204: ADRENO_REG_DEFINE(ADRENO_REG_CP_ME_CNTL, GEN8_CP_SQE_CNTL), MATCH LINES: 3305 3293: { 3294: kgsl_regwrite(KGSL_DEVICE(adreno_dev), GEN8_CP_SEMAPHORE_REG_0, 0); 3295: } 3296: 3297: int gen8_perfcounter_remove(struct adreno_device *adreno_dev, 3298: struct adreno_perfcount_register *reg, u32 groupid) 3299: { 3300: const struct adreno_perfcounters *counters = ADRENO_PERFCOUNTERS(adreno_dev); 3301: struct gen8_device *gen8_dev = container_of(adreno_dev, struct gen8_device, adreno_dev); 3302: const struct adreno_perfcount_group *group; 3303: void *ptr = adreno_dev->pwrup_reglist->hostptr; 3304: struct cpu_gpu_lock *lock = ptr; 3305: u32 offset = ((lock->ifpc_list_len + lock->preemption_list_len) * 2) + 3306: (gen8_dev->ext_pwrup_list_len * 3); 3307: int i, last_offset, num_removed, start_offset = -1; 3308: u32 *data = ptr + sizeof(*lock), pipe = FIELD_PREP(GENMASK(13, 12), _get_pipeid(groupid)); 3309: u16 perfcntr_list_len = lock->dynamic_list_len - gen8_dev->ext_pwrup_list_len; 3310: 3311: if (!perfcntr_list_len) 3312: return -EINVAL; 3313: 3314: group = &(counters->groups[groupid]); 3315: 3316: if (!(group->flags & ADRENO_PERFCOUNTER_GROUP_RESTORE)) { 3317: if (perfcntr_list_len != 2) 3318: return 0; 3319: 3320: if (kgsl_hwlock(lock)) { 3321: kgsl_hwunlock(lock); 3322: return -EBUSY; 3323: } 3324: goto disable_perfcounter; 3325: } 3326: 3327: last_offset = offset + (perfcntr_list_len * 3); 3328: 3329: /* Look for the perfcounter to remove in the list */ MATCH LINES: 3381 3369: } 3370: 3371: kgsl_hwunlock(lock); 3372: return 0; 3373: } 3374: 3375: int gen8_perfcounter_update(struct adreno_device *adreno_dev, 3376: struct adreno_perfcount_register *reg, bool update_reg, u32 pipe, unsigned long flags) 3377: { 3378: struct gen8_device *gen8_dev = container_of(adreno_dev, struct gen8_device, adreno_dev); 3379: void *ptr = adreno_dev->pwrup_reglist->hostptr; 3380: struct cpu_gpu_lock *lock = ptr; 3381: u32 offset = ((lock->ifpc_list_len + lock->preemption_list_len) * 2) + 3382: (gen8_dev->ext_pwrup_list_len * 3); 3383: u32 *data = ptr + sizeof(*lock); 3384: u64 reglist_size_dwords = adreno_dev->pwrup_reglist->size / sizeof(u32); 3385: u64 lock_size_dwords = sizeof(*lock) / sizeof(u32); 3386: int i, start_offset = -1; 3387: u16 perfcntr_list_len = lock->dynamic_list_len - gen8_dev->ext_pwrup_list_len; 3388: unsigned long irq_flags; 3389: int ret = 0; 3390: u32 num_dependencies = 0; 3391: u32 pending_triplets = 2; 3392: 3393: if (!ADRENO_ACQUIRE_CP_SEMAPHORE(adreno_dev, irq_flags)) 3394: return -EBUSY; 3395: 3396: if (flags & ADRENO_PERFCOUNTER_GROUP_RESTORE) { 3397: for (i = 0; i < PERFCOUNTER_REG_DEPENDENCY_LEN && reg->reg_dependency[i]; i++) 3398: num_dependencies++; 3399: 3400: /* Number of triplets to add: 1 main + dependencies + 2 controls */ 3401: pending_triplets += num_dependencies + 1; 3402: 3403: for (i = 0; i < perfcntr_list_len - 2; i++) { 3404: if ((data[offset + 1] == reg->select) && (data[offset] == pipe)) { 3405: start_offset = offset; MATCH LINES: 3527, 3528 3515: return -EINVAL; 3516: 3517: if (!(adreno_dev->feature_fuse & BIT(GEN8_LPAC_SW_FUSE)) || 3518: (adreno_dev->lpac_enabled == enable)) 3519: return 0; 3520: 3521: /* Power down the GPU before changing the lpac setting */ 3522: return adreno_power_cycle_bool(adreno_dev, &adreno_dev->lpac_enabled, enable); 3523: } 3524: 3525: static void gen8_remove(struct adreno_device *adreno_dev) 3526: { 3527: if (adreno_preemption_feature_set(adreno_dev)) 3528: kgsl_delete_timer(&adreno_dev->preempt.timer); 3529: } 3530: 3531: static void gen8_read_bus_stats(struct kgsl_device *device, 3532: struct kgsl_power_stats *stats, 3533: struct adreno_busy_data *busy) 3534: { 3535: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 3536: u64 ram_cycles, starved_ram; 3537: 3538: ram_cycles = counter_delta(device, adreno_dev->ram_cycles_lo, 3539: &busy->bif_ram_cycles); 3540: 3541: starved_ram = counter_delta(device, adreno_dev->starved_ram_lo, 3542: &busy->bif_starved_ram); 3543: 3544: ram_cycles += counter_delta(device, 3545: adreno_dev->ram_cycles_lo_ch1_read, 3546: &busy->bif_ram_cycles_read_ch1); 3547: 3548: ram_cycles += counter_delta(device, 3549: adreno_dev->ram_cycles_lo_ch0_write, 3550: &busy->bif_ram_cycles_write_ch0); 3551: 3552: ram_cycles += counter_delta(device, MATCH LINES: 3892 3880: 3881: const struct gen8_gpudev adreno_gen8_gmu_gpudev = { 3882: .base = { 3883: .reg_offsets = gen8_register_offsets, 3884: .probe = gen8_gmu_device_probe, 3885: .snapshot = gen8_gmu_snapshot, 3886: .irq_handler = gen8_irq_handler, 3887: .rb_start = gen8_rb_start, 3888: .gpu_keepalive = gen8_gpu_keepalive, 3889: .hw_isidle = gen8_hw_isidle, 3890: .iommu_fault_block = gen8_iommu_fault_block, 3891: .reset = gen8_gmu_reset, 3892: .preemption_schedule = gen8_preemption_schedule, 3893: .read_alwayson = gen8_read_alwayson, 3894: .power_ops = &gen8_gmu_power_ops, 3895: .remove = gen8_remove, 3896: .ringbuffer_submitcmd = gen8_ringbuffer_submitcmd, 3897: .power_stats = gen8_power_stats, 3898: .add_to_va_minidump = gen8_gmu_add_to_minidump, 3899: .gx_is_on = gen8_gmu_gx_is_on, 3900: .perfcounter_remove = gen8_perfcounter_remove, 3901: .set_isdb_breakpoint_registers = gen8_set_isdb_breakpoint_registers, 3902: .swfuse_irqctrl = gen8_swfuse_irqctrl, 3903: .get_uche_trap_base = gen8_get_uche_trap_base, 3904: .fault_header = gen8_fault_header, 3905: .acquire_cp_semaphore = gen8_acquire_cp_semaphore, 3906: .release_cp_semaphore = gen8_release_cp_semaphore, 3907: .get_gmem_size = gen8_get_gmem_size, 3908: .read_speedbin = gen8_read_softfuse_speedbin, 3909: }, 3910: .hfi_probe = gen8_gmu_hfi_probe, 3911: .handle_watchdog = gen8_gmu_handle_watchdog, 3912: }; --- FILE: \adreno_gen8.h | HITS: 25 --- MATCH LINES: 57 45: struct gen8_nonctxt_overrides { 46: /** offset: Dword offset of the register to write */ 47: u32 offset; 48: /** pipelines: Pipelines to write */ 49: u32 pipelines; 50: /** val: Value to be written to the register */ 51: u32 val; 52: /** set: True for user override request */ 53: bool set; 54: /** 55: * list_type: 0 If the register already present in any of exisiting static pwrup list 56: 1 if the register fits into IFPC static pwrup only list 57: 2 if the register fits into IFPC + preemption static list 58: 3 if the register fits into external powerup list 59: */ 60: u32 list_type; 61: }; 62: 63: /** 64: * struct gen8_device - Container for the gen8_device 65: */ 66: struct gen8_device { 67: /** @gmu: Container for the gen8 GMU device */ 68: struct gen8_gmu_device gmu; 69: /** @adreno_dev: Container for the generic adreno device */ 70: struct adreno_device adreno_dev; 71: /** @aperture: The last value that the host aperture register was programmed to */ 72: u32 aperture; 73: /** @ext_pwrup_list_len: External pwrup reglist length */ 74: u16 ext_pwrup_list_len; 75: /** 76: * @nc_overrides: Noncontext registers overrides whitelist if defined, 77: * must be null terminated 78: */ 79: struct gen8_nonctxt_overrides *nc_overrides; 80: /** @nc_mutex: Mutex to protect nc_overrides updates */ 81: struct mutex nc_mutex; MATCH LINES: 192, 204, 205, 236, 237, 243, 252, 255, 271, 292, 294 180: /** @ao_hwcg_count: Number of registers in @ao_hwcg */ 181: u32 ao_hwcg_count; 182: /** @gbif: List of registers and values to write for GBIF */ 183: const struct kgsl_regmap_list *gbif; 184: /** @gbif_count: Number of registers in @gbif */ 185: u32 gbif_count; 186: /** @hang_detect_cycles: Hang detect counter timeout value */ 187: u32 hang_detect_cycles; 188: /** @protected_regs: Array of protected registers for the target */ 189: const struct gen8_protected_regs *protected_regs; 190: /** @nonctxt_regs: Array of non context register list */ 191: const struct gen8_nonctxt_regs *nonctxt_regs; 192: /** @ctxt_record_size: Size of the preemption record in bytes */ 193: u64 ctxt_record_size; 194: /** @gen8_snapshot_block_list: Device-specific blocks dumped in the snapshot */ 195: const struct gen8_snapshot_block_list *gen8_snapshot_block_list; 196: /** @gmu_hub_clk_freq: Gmu hub interface clock frequency */ 197: u64 gmu_hub_clk_freq; 198: /** 199: * @bcl_data: bit 0 contains response type for bcl alarms and bits 1:21 controls sid vals 200: * to configure throttle levels for bcl alarm levels 0-2. If sid vals are not set, 201: * gmu fw sets default throttle levels. 202: */ 203: u32 bcl_data; 204: /** @preempt_level: Preemption level valid ranges [0 to 2] */ 205: u32 preempt_level; 206: /** @qos_value: GPU qos value to set for each RB. */ 207: const u32 *qos_value; 208: /** 209: * @acv_perfmode_ddr_freq: Vote perfmode when DDR frequency >= acv_perfmode_ddr_freq. 210: * If not specified, vote perfmode for highest DDR level only. 211: */ 212: u32 acv_perfmode_ddr_freq; 213: /** @rt_bus_hint: IB level hint for real time clients i.e. RB-0 */ 214: const u32 rt_bus_hint; 215: /** @fast_bus_hint: Whether or not to increase IB vote on high ddr stall */ 216: bool fast_bus_hint; 217: /** @noc_timeout_us: GPU config NOC port timeout in usec */ 218: u32 noc_timeout_us; 219: /** @cl_no_ft_timeout_ms: Use this timeout for CL NO_FT instead of infinite */ 220: u32 cl_no_ft_timeout_ms; 221: /** @therm_profile: GMU thermal mitigation profile */ 222: struct gen8_thermal_mit_cfg *therm_cfg; 223: /** @limits_mit_cfg: GPU limits mitigation configuration */ 224: const struct gen8_limits_mit_cfg *limits_mit_cfg; 225: /** @clx_tbl: GPU CLX table */ 226: const struct hfi_clx_table_v2_cmd *clx_tbl; 227: /** @gmu_mx_gdsc: This target has separate MX GDSC for the GMU */ 228: bool gmu_mx_gdsc; 229: /** @three_rail_memory: This target has BX rail in addition to GX and MX */ 230: bool three_rail_memory; 231: /** @malu: This target has MALU */ 232: bool malu; 233: }; 234: 235: /** 236: * struct gen8_cp_preemption_record - CP context record for 237: * preemption. 238: * @magic: (00) Value at this offset must be equal to 239: * GEN8_CP_CTXRECORD_MAGIC_REF. 240: * @info: (04) Type of record. Written non-zero (usually) by CP. 241: * we must set to zero for all ringbuffers. 242: * @errno: (08) Error code. Initialize this to GEN8_CP_CTXRECORD_ERROR_NONE. 243: * CP will update to another value if a preemption error occurs. 244: * @data: (12) DATA field in YIELD and SET_MARKER packets. 245: * Written by CP when switching out. Not used on switch-in. Initialized to 0. 246: * @cntl: (16) RB_CNTL, saved and restored by CP. We must initialize this. 247: * @rptr: (20) RB_RPTR, saved and restored by CP. We must initialize this. 248: * @wptr: (24) RB_WPTR, saved and restored by CP. We must initialize this. 249: * @_pad28: (28) Reserved/padding. 250: * @rptr_addr: (32) RB_RPTR_ADDR_LO|HI saved and restored. We must initialize. 251: * rbase: (40) RB_BASE_LO|HI saved and restored. 252: * counter: (48) Pointer to preemption counter. 253: * @bv_rptr_addr: (56) BV_RB_RPTR_ADDR_LO|HI save and restored. We must initialize. 254: */ 255: struct gen8_cp_preemption_record { 256: u32 magic; 257: u32 info; 258: u32 errno; 259: u32 data; 260: u32 cntl; 261: u32 rptr; 262: u32 wptr; 263: u32 _pad28; 264: u64 rptr_addr; 265: u64 rbase; 266: u64 counter; 267: u64 bv_rptr_addr; 268: }; 269: 270: /** 271: * struct gen8_cp_smmu_info - CP preemption SMMU info. 272: * @magic: (00) The value at this offset must be equal to 273: * GEN8_CP_SMMU_INFO_MAGIC_REF 274: * @_pad4: (04) Reserved/padding 275: * @ttbr0: (08) Base address of the page table for the * incoming context 276: * @asid: (16) Address Space IDentifier (ASID) of the incoming context 277: * @context_idr: (20) Context Identification Register value 278: * @context_bank: (24) Which Context Bank in SMMU to update 279: */ 280: struct gen8_cp_smmu_info { 281: u32 magic; 282: u32 _pad4; 283: u64 ttbr0; 284: u32 asid; 285: u32 context_idr; 286: u32 context_bank; 287: }; 288: 289: #define GEN8_CP_SMMU_INFO_MAGIC_REF 0x241350d5UL 290: 291: #define GEN8_CP_CTXRECORD_MAGIC_REF 0xae399d6eUL 292: /* Size of each CP preemption record */ 293: #define GEN8_CP_CTXRECORD_SIZE_IN_BYTES (13536 * SZ_1K) 294: /* Size of preemption record to be dumped in snapshot */ 295: #define GEN8_SNAPSHOT_CTXRECORD_SIZE_IN_BYTES (128 * 1024) 296: /* Size of AQE context record */ 297: #define GEN8_CP_AQE_CTXRECORD_SIZE_IN_BYTES (16 * 1024) 298: /* Size of the performance counter save/restore block (in bytes) */ 299: #define GEN8_CP_PERFCOUNTER_SAVE_RESTORE_SIZE (4 * 1024) 300: 301: #define GEN8_CP_RB_CNTL_DEFAULT \ 302: (FIELD_PREP(GENMASK(7, 0), ilog2(KGSL_RB_DWORDS >> 1)) | \ 303: FIELD_PREP(GENMASK(12, 8), ilog2(4))) 304: 305: /* Size of the CP_INIT pm4 stream in dwords */ 306: #define GEN8_CP_INIT_DWORDS 10 307: 308: #define GEN8_INT_MASK \ 309: ((1 << GEN8_INT_AHBERROR) | \ 310: (1 << GEN8_INT_ATBASYNCFIFOOVERFLOW) | \ 311: (1 << GEN8_INT_GPCERROR) | \ 312: (1 << GEN8_INT_SWINTERRUPT) | \ 313: (1 << GEN8_INT_HWERROR) | \ 314: (1 << GEN8_INT_PM4CPINTERRUPT) | \ 315: (1 << GEN8_INT_RB_DONE_TS) | \ 316: (1 << GEN8_INT_CACHE_CLEAN_TS) | \ 317: (1 << GEN8_INT_ATBBUSOVERFLOW) | \ 318: (1 << GEN8_INT_HANGDETECTINTERRUPT) | \ MATCH LINES: 352, 353, 354, 355, 356, 358, 360, 364, 366, 368 340: * 341: * Returns: 342: * A pointer to the gen8 specific GPU core struct 343: */ 344: static inline const struct adreno_gen8_core * 345: to_gen8_core(struct adreno_device *adreno_dev) 346: { 347: const struct adreno_gpu_core *core = adreno_dev->gpucore; 348: 349: return container_of(core, struct adreno_gen8_core, base); 350: } 351: 352: /* Preemption functions */ 353: void gen8_preemption_trigger(struct adreno_device *adreno_dev, bool atomic); 354: void gen8_preemption_schedule(struct adreno_device *adreno_dev); 355: void gen8_preemption_start(struct adreno_device *adreno_dev); 356: int gen8_preemption_init(struct adreno_device *adreno_dev); 357: 358: u32 gen8_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 359: u32 *cmds); 360: u32 gen8_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 361: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 362: u32 *cmds); 363: 364: void gen8_preemption_callback(struct adreno_device *adreno_dev, int bit); 365: 366: void gen8_preemption_context_destroy(struct kgsl_context *context); 367: 368: void gen8_preemption_prepare_postamble(struct adreno_device *adreno_dev); 369: 370: void gen8_snapshot(struct adreno_device *adreno_dev, 371: struct kgsl_snapshot *snapshot); 372: void gen8_crashdump_init(struct adreno_device *adreno_dev); 373: 374: /** 375: * gen8_snapshot_external_core_regs - Dump external registers into snapshot 376: * @device: Pointer to KGSL device 377: * @snapshot: Pointer to the snapshot 378: * 379: * Dump external core registers like GPUCC, CPR into GPU snapshot. 380: */ 381: void gen8_snapshot_external_core_regs(struct kgsl_device *device, 382: struct kgsl_snapshot *snapshot); 383: 384: /** 385: * gen8_enable_ahb_timeout_detection - Program AHB control registers 386: * @adreno_dev: An Adreno GPU handle 387: * 388: * Program AHB control registers to enable AHB timeout detection. 389: * 390: */ 391: void gen8_enable_ahb_timeout_detection(struct adreno_device *adreno_dev); 392: MATCH LINES: 583, 586, 588 571: * 572: * Return: 0 on success or negative on failure 573: */ 574: int gen8_gmu_hfi_probe(struct adreno_device *adreno_dev); 575: 576: static inline const struct gen8_gpudev * 577: to_gen8_gpudev(const struct adreno_gpudev *gpudev) 578: { 579: return container_of(gpudev, struct gen8_gpudev, base); 580: } 581: 582: /** 583: * gen8_reset_preempt_records - Reset the preemption buffers 584: * @adreno_dev: Handle to the adreno device 585: * 586: * Reset the preemption records at the time of hard reset 587: */ 588: void gen8_reset_preempt_records(struct adreno_device *adreno_dev); 589: 590: /** 591: * gen8_scm_gpu_init_cx_regs - Program gpu regs for feature support 592: * @adreno_dev: Handle to the adreno device 593: * 594: * Program gpu regs for feature support. Scm call for the same 595: * is added from kernel version 6.0 onwards. 596: * 597: * Return: 0 on success or negative on failure 598: */ 599: int gen8_scm_gpu_init_cx_regs(struct adreno_device *adreno_dev); 600: 601: /** 602: * gen8_scm_gpu_tsense_default - Program gpu tsense measurement interval 603: * @adreno_dev: Handle to the adreno device 604: * @default_req: Bool on if should update tsense with default or slow interval 605: * 606: * Program gpu tsense reg for measurement granularity. Scm call for the same 607: * is added from kernel version 6.0 onwards. 608: */ 609: void gen8_scm_gpu_tsense_default(struct adreno_device *adreno_dev, bool default_req); 610: 611: /** 612: * gen8_legacy_snapshot_registers - Dump registers for GPU/GMU --- FILE: \adreno_gen8_11_0_snapshot.h | HITS: 2 --- MATCH LINES: 2483, 2485 2471: { GEN8_CP_MEM_POOL_DBG_ADDR_PIPE, GEN8_CP_MEM_POOL_DBG_DATA_PIPE, 2472: UNSLICE, PIPE_BR, 0x02400}, 2473: { GEN8_CP_MEM_POOL_DBG_ADDR_PIPE, GEN8_CP_MEM_POOL_DBG_DATA_PIPE, 2474: UNSLICE, PIPE_BV, 0x02400}, 2475: { GEN8_CP_SLICE_MEM_POOL_DBG_ADDR_PIPE, GEN8_CP_SLICE_MEM_POOL_DBG_DATA_PIPE, 2476: SLICE, PIPE_BR, 0x02400}, 2477: { GEN8_CP_SLICE_MEM_POOL_DBG_ADDR_PIPE, GEN8_CP_SLICE_MEM_POOL_DBG_DATA_PIPE, 2478: SLICE, PIPE_BV, 0x02400}, 2479: }; 2480: 2481: 2482: static struct gen8_pc_indexed_reg gen8_11_0_pc_indexed_reg_list[] = { 2483: { GEN8_PC_US_CONTEXT_SWITCH_SAVE_RESTORE_ADDR, GEN8_PC_US_CONTEXT_SWITCH_SAVE_RESTORE_DATA, 2484: UNSLICE, PIPE_BR, 0x002bc}, 2485: { GEN8_PC_US_CONTEXT_SWITCH_SAVE_RESTORE_ADDR, GEN8_PC_US_CONTEXT_SWITCH_SAVE_RESTORE_DATA, 2486: UNSLICE, PIPE_BV, 0x002bc}, 2487: }; 2488: 2489: static struct gen8_reg_list gen8_11_0_misc_registers[] = { 2490: { UNSLICE, gen8_11_0_gpu_registers }, 2491: { SLICE, gen8_11_0_gpu_slice_registers }, 2492: { UNSLICE, gen8_11_0_cx_misc_registers }, 2493: { UNSLICE, gen8_11_0_dbgc_registers }, 2494: { SLICE, gen8_11_0_dbgc_slice_registers }, 2495: { UNSLICE, gen8_11_0_cx_dbgc_registers }, 2496: { UNSLICE, NULL }, 2497: }; 2498: 2499: static struct gen8_reg_list gen8_11_0_ahb_registers[] = { 2500: { UNSLICE, gen8_11_0_gbif_registers }, 2501: { UNSLICE, gen8_11_0_ahb_precd_gpu_registers }, 2502: { SLICE, gen8_11_0_ahb_precd_gpu_slice_registers }, 2503: { UNSLICE, gen8_11_0_ahb_secure_gpu_registers }, 2504: }; 2505: 2506: static struct gen8_reg_list gen8_11_0_gmu_registers[] = { 2507: { UNSLICE, gen8_11_0_gmugx_registers }, 2508: { SLICE, gen8_11_0_gmugx_slice_registers }, 2509: { UNSLICE, gen8_11_0_gmuao_registers }, --- FILE: \adreno_gen8_gmu.c | HITS: 7 --- MATCH LINES: 767, 772 755: "RPMH_POWER_STATE=%x GFX_PWR_CLK_STATUS=%x\n", reg, reg1); 756: dev_err(gmu_pdev_dev, "CX_BUSY_STATUS=%x\n", reg2); 757: dev_err(gmu_pdev_dev, 758: "RBBM_INT_UNMASKED_STATUS=%x PWR_COL_KEEPALIVE=%x\n", reg3, reg4); 759: 760: /* Access GX registers only when GX is ON */ 761: if (is_on(reg1)) { 762: gen8_regread_aperture(device, GEN8_CP_PIPE_STATUS_PIPE, ®, PIPE_BV, 0, 0); 763: gen8_regread_aperture(device, GEN8_CP_PIPE_STATUS_PIPE, ®1, PIPE_BR, 0, 0); 764: /* Clear aperture register */ 765: gen8_host_aperture_set(adreno_dev, 0, 0, 0); 766: kgsl_regread(device, GEN8_CP_CP2GMU_STATUS, ®2); 767: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_CNTL, ®3); 768: 769: dev_err(gmu_pdev_dev, 770: "GEN8_CP_PIPE_STATUS_PIPE BV:%x BR:%x\n", reg, reg1); 771: dev_err(gmu_pdev_dev, 772: "CP2GMU_STATUS=%x CONTEXT_SWITCH_CNTL=%x\n", reg2, reg3); 773: } 774: 775: WARN_ON(1); 776: gmu_core_fault_snapshot(device, GMU_FAULT_WAIT_FOR_LOWEST_IDLE); 777: return -ETIMEDOUT; 778: } 779: 780: /* Bitmask for GPU idle status check */ 781: #define CXGXCPUBUSYIGNAHB BIT(30) 782: int gen8_gmu_wait_for_idle(struct adreno_device *adreno_dev) 783: { 784: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 785: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 786: u32 status2; 787: u64 ts1; 788: 789: ts1 = gpudev->read_alwayson(adreno_dev); 790: if (gmu_core_timed_poll_check(device, GEN8_GMUAO_GPU_CX_BUSY_STATUS, 791: 0, 100, CXGXCPUBUSYIGNAHB)) { 792: gmu_core_regread(device, 793: GEN8_GMUAO_GPU_CX_BUSY_STATUS2, &status2); 794: dev_err(GMU_PDEV_DEV(device), 795: "GMU not idling: status2=0x%x %llx %llx\n", 796: status2, ts1, MATCH LINES: 887 875: gmu_core_regwrite(device, GEN8_GMUCX_CX_FAL_INTF, 0x1); 876: 877: /* Clear init result to make sure we are getting fresh value */ 878: gmu_core_regwrite(device, GEN8_GMUCX_CM3_FW_INIT_RESULT, 0); 879: gmu_core_regwrite(device, GEN8_GMUCX_CM3_BOOT_CONFIG, 0x2); 880: 881: gmu_core_regwrite(device, GEN8_GMUCX_HFI_QTBL_ADDR, 882: gmu->hfi.hfi_mem->gmuaddr); 883: gmu_core_regwrite(device, GEN8_GMUCX_HFI_QTBL_INFO, 1); 884: 885: gmu_core_regwrite(device, GEN8_GMUAO_AHB_FENCE_RANGE_0, BIT(31) | 886: FIELD_PREP(GENMASK(30, 18), 0x32) | 887: FIELD_PREP(GENMASK(17, 0), GEN8_CP_CONTEXT_SWITCH_CNTL)); 888: 889: /* 890: * Make sure that CM3 state is at reset value. Snapshot is changing 891: * NMI bit and if we boot up GMU with NMI bit set GMU will boot 892: * straight in to NMI handler without executing __main code 893: */ 894: gmu_core_regwrite(device, GEN8_GMUCX_CM3_CFG, 0x4052); 895: 896: /* Set up GBIF registers from the GPU core definition */ 897: kgsl_regmap_multi_write(&device->regmap, gen8_core->gbif, 898: gen8_core->gbif_count); 899: 900: /** 901: * We may have asserted gbif halt as part of reset sequence which may 902: * not get cleared if the gdsc was not reset. So clear it before 903: * attempting GMU boot. 904: */ 905: kgsl_regwrite(device, GEN8_GBIF_HALT, BIT(3)); 906: 907: /* Set vrb address before starting GMU */ 908: if (!IS_ERR_OR_NULL(device->gmu_core.vrb)) 909: gmu_core_regwrite(device, GEN8_GMUCX_GENERAL_11, device->gmu_core.vrb->gmuaddr); 910: 911: /* Set the log wptr index */ MATCH LINES: 2346 2334: if (ret) 2335: goto oob_clear; 2336: 2337: ret = gen8_gmu_hfi_start_msg(adreno_dev); 2338: if (ret) 2339: goto oob_clear; 2340: 2341: /* Clear the busy_data stats - we're starting over from scratch */ 2342: memset(&adreno_dev->busy_data, 0, sizeof(adreno_dev->busy_data)); 2343: 2344: gen8_start(adreno_dev); 2345: 2346: if (gen8_core->qos_value && adreno_is_preemption_enabled(adreno_dev)) 2347: kgsl_regwrite(device, GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 2348: gen8_core->qos_value[adreno_dev->cur_rb->id]); 2349: 2350: /* Re-initialize the coresight registers if applicable */ 2351: adreno_coresight_start(adreno_dev); 2352: 2353: adreno_perfcounter_start(adreno_dev); 2354: 2355: /* Clear FSR here in case it is set from a previous pagefault */ 2356: kgsl_mmu_clear_fsr(&device->mmu); 2357: 2358: gen8_enable_gpu_irq(adreno_dev); 2359: 2360: ret = gen8_rb_start(adreno_dev); 2361: if (ret) { 2362: gen8_disable_gpu_irq(adreno_dev); 2363: adreno_llcc_slice_deactivate(adreno_dev); 2364: goto oob_clear; 2365: } 2366: 2367: /* 2368: * At this point it is safe to assume that we recovered. Setting 2369: * this field allows us to take a new snapshot for the next failure 2370: * if we are prioritizing the first unrecoverable snapshot. MATCH LINES: 2469 2457: ret = gen8_gmu_init(adreno_dev); 2458: if (ret) 2459: return ret; 2460: 2461: kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE); 2462: 2463: ret = gen8_gmu_first_boot(adreno_dev); 2464: if (ret) 2465: return ret; 2466: 2467: gen8_populate_ctxt_record_size(adreno_dev); 2468: 2469: gen8_preemption_init(adreno_dev); 2470: 2471: ret = gen8_gpu_boot(adreno_dev); 2472: if (ret) 2473: return ret; 2474: 2475: adreno_get_bus_counters(adreno_dev); 2476: 2477: adreno_dev->cooperative_reset = ADRENO_FEATURE(adreno_dev, 2478: ADRENO_COOP_RESET); 2479: 2480: adreno_create_profile_buffer(adreno_dev); 2481: 2482: set_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags); 2483: set_bit(GMU_PRIV_GPU_STARTED, &gmu->flags); 2484: 2485: /* 2486: * BCL needs respective Central Broadcast register to 2487: * be programed from TZ. For kernel version prior to 6.1, this 2488: * programing happens only when zap shader firmware load is successful. 2489: * Zap firmware load can fail in boot up path hence enable BCL only 2490: * after we successfully complete first boot to ensure that Central 2491: * Broadcast register was programed before enabling BCL. 2492: */ 2493: if (ADRENO_FEATURE(adreno_dev, ADRENO_BCL)) MATCH LINES: 2587 2575: 2576: kgsl_delete_timer_sync(&device->idle_timer); 2577: 2578: kgsl_pwrscale_sleep(device); 2579: 2580: kgsl_pwrctrl_clear_l3_vote(device); 2581: 2582: /* 2583: * Reset the context records so that CP can start 2584: * at the correct read pointer for BV thread after 2585: * coming out of slumber. 2586: */ 2587: gen8_reset_preempt_records(adreno_dev); 2588: 2589: kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER); 2590: 2591: return ret; 2592: } 2593: 2594: static void gmu_idle_check(struct work_struct *work) 2595: { 2596: struct kgsl_device *device = container_of(work, 2597: struct kgsl_device, idle_check_ws); 2598: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 2599: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2600: int ret; 2601: 2602: kgsl_mutex_lock(&device->mutex); 2603: 2604: if (test_bit(GMU_DISABLE_SLUMBER, &device->gmu_core.flags)) 2605: goto done; 2606: 2607: if (atomic_read(&device->active_cnt) || time_is_after_jiffies(device->idle_jiffies)) { 2608: kgsl_pwrscale_update(device); 2609: goto done; 2610: } 2611: MATCH LINES: 2846 2834: { 2835: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2836: 2837: gen8_disable_gpu_irq(adreno_dev); 2838: 2839: gen8_gmu_irq_disable(adreno_dev); 2840: 2841: gen8_hfi_stop(adreno_dev); 2842: 2843: /* Hard reset the gmu and gpu */ 2844: gen8_gmu_suspend(adreno_dev, true); 2845: 2846: gen8_reset_preempt_records(adreno_dev); 2847: 2848: adreno_llcc_slice_deactivate(adreno_dev); 2849: 2850: clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags); 2851: 2852: /* Attempt to reboot the gmu and gpu */ 2853: return gen8_boot(adreno_dev); 2854: } 2855: 2856: int gen8_gmu_hfi_probe(struct adreno_device *adreno_dev) 2857: { 2858: struct platform_device *gmu_pdev = GMU_PDEV(KGSL_DEVICE(adreno_dev)); 2859: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2860: struct gen8_hfi *hfi = &gmu->hfi; 2861: 2862: hfi->irq = kgsl_request_irq(gmu_pdev, "hfi", NULL, -EINVAL, 2863: gen8_hfi_irq_handler, KGSL_DEVICE(adreno_dev)); 2864: 2865: return hfi->irq < 0 ? hfi->irq : 0; 2866: } 2867: 2868: int gen8_gmu_add_to_minidump(struct adreno_device *adreno_dev) 2869: { 2870: struct gen8_device *gen8_dev = container_of(adreno_dev, --- FILE: \adreno_gen8_hwsched.c | HITS: 12 --- MATCH LINES: 118, 121 106: kgsl_snapshot_add_section(device, 107: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 108: snapshot, adreno_snapshot_global, 109: entry->md); 110: 111: if (entry->desc.mem_kind == HFI_MEMKIND_CSW_SMMU_INFO) 112: kgsl_snapshot_add_section(device, 113: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 114: snapshot, adreno_snapshot_global, 115: entry->md); 116: 117: if (entry->desc.mem_kind == HFI_MEMKIND_CSW_PRIV_NON_SECURE) 118: adreno_hwsched_snapshot_preemption_records(device, snapshot, 119: entry->md); 120: 121: if (entry->desc.mem_kind == HFI_MEMKIND_PREEMPT_SCRATCH) 122: kgsl_snapshot_add_section(device, 123: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 124: snapshot, adreno_snapshot_global, 125: entry->md); 126: 127: if (entry->desc.mem_kind == HFI_MEMKIND_AQE_BUFFER) 128: kgsl_snapshot_add_section(device, 129: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 130: snapshot, adreno_hwsched_snapshot_aqe_buffer, 131: entry->md); 132: 133: if (entry->desc.mem_kind == HFI_MEMKIND_HW_FENCE) { 134: struct gmu_mem_type_desc desc; 135: 136: desc.memdesc = entry->md; 137: desc.type = SNAPSHOT_GMU_MEM_HW_FENCE; 138: kgsl_snapshot_add_section(device, 139: KGSL_SNAPSHOT_SECTION_GMU_MEMORY, 140: snapshot, adreno_snapshot_gmu_mem, &desc); 141: } 142: 143: } 144: 145: adreno_hwsched_snapshot_context_queue(device, snapshot); MATCH LINES: 1641, 1644, 1649, 1651, 1653, 1661, 1663, 1665 1629: if (ret) 1630: goto done; 1631: 1632: adreno_hwsched_replay(adreno_dev); 1633: 1634: ret = handle_hw_fences_after_reset(adreno_dev); 1635: done: 1636: BUG_ON(ret); 1637: 1638: return ret; 1639: } 1640: 1641: ssize_t gen8_hwsched_preempt_info_get(struct adreno_device *adreno_dev, char *buf) 1642: { 1643: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1644: u32 preempt_count_l0, preempt_count_l1a, preempt_count_l1b; 1645: u32 count = 0, max_size = PAGE_SIZE; 1646: int ret; 1647: 1648: ret = gmu_core_get_vrb_register(device->gmu_core.vrb, 1649: VRB_PREEMPT_COUNT_L0, &preempt_count_l0); 1650: ret |= gmu_core_get_vrb_register(device->gmu_core.vrb, 1651: VRB_PREEMPT_COUNT_L1A, &preempt_count_l1a); 1652: ret |= gmu_core_get_vrb_register(device->gmu_core.vrb, 1653: VRB_PREEMPT_COUNT_L1B, &preempt_count_l1b); 1654: 1655: if (ret) 1656: return ret; 1657: 1658: count += scnprintf(buf + count, max_size - count, 1659: "%-8s %-8s\n", "Level:", "Count"); 1660: count += scnprintf(buf + count, max_size - count, 1661: "%-8s 0x%-8x\n", "L0:", preempt_count_l0); 1662: count += scnprintf(buf + count, max_size - count, 1663: "%-8s 0x%-8x\n", "L1A:", preempt_count_l1a); 1664: count += scnprintf(buf + count, max_size - count, 1665: "%-8s 0x%-8x\n", "L1B:", preempt_count_l1b); 1666: 1667: return count; 1668: } 1669: 1670: static void gen8_hwsched_set_dcvs_enable(struct adreno_device *adreno_dev, u32 enable) 1671: { 1672: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1673: struct gmu_core_device *gmu_core = &device->gmu_core; 1674: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1675: 1676: gmu_core->gpu_pwrscale_enable = (enable >= 1) ? 1 : enable; 1677: 1678: if (device->state == KGSL_STATE_ACTIVE) { 1679: /* If GMU is up, send the HFI */ 1680: gen8_hwsched_set_gmu_based_dcvs_value(adreno_dev, HFI_VALUE_DCVS_ENABLE, 0, 1681: gmu_core->gpu_pwrscale_enable, false); 1682: } else { 1683: hwsched->dcvs_param_update = true; 1684: } 1685: } 1686: 1687: void gen8_hwsched_set_pwrconstraint(struct adreno_device *adreno_dev, 1688: u32 context_id) 1689: { MATCH LINES: 2094, 2095 2082: .last_close = gen8_hwsched_power_off, 2083: .active_count_get = gen8_hwsched_active_count_get, 2084: .touch_wakeup = gen8_hwsched_touch_wakeup, 2085: .pm_suspend = gen8_hwsched_pm_suspend, 2086: .pm_resume = gen8_hwsched_pm_resume, 2087: .gpu_clock_set = gen8_hwsched_clock_set, 2088: .gpu_bus_set = gen8_hwsched_bus_set, 2089: .gmu_based_dcvs_pwr_ops = gen8_hwsched_gmu_based_dcvs_pwr_ops, 2090: }; 2091: 2092: const struct adreno_hwsched_ops gen8_hwsched_ops = { 2093: .submit_drawobj = gen8_hwsched_submit_drawobj, 2094: .preempt_count = gen8_hwsched_preempt_count_get, 2095: .preempt_info = gen8_hwsched_preempt_info_get, 2096: .create_hw_fence = gen8_hwsched_create_hw_fence, 2097: .set_dcvs_profile = gen8_hwsched_set_dcvs_profile, 2098: }; 2099: 2100: int gen8_hwsched_probe(struct platform_device *pdev, 2101: u32 chipid, const struct adreno_gpu_core *gpucore) 2102: { 2103: struct adreno_device *adreno_dev; 2104: struct kgsl_device *device; 2105: struct gen8_hwsched_device *gen8_hwsched_dev; 2106: struct gen8_device *gen8_dev; 2107: struct device *gmu_dev; 2108: int ret; 2109: int i; 2110: 2111: gen8_hwsched_dev = devm_kzalloc(&pdev->dev, sizeof(*gen8_hwsched_dev), 2112: GFP_KERNEL); 2113: if (!gen8_hwsched_dev) 2114: return -ENOMEM; 2115: 2116: gen8_dev = &gen8_hwsched_dev->gen8_dev; 2117: adreno_dev = &gen8_dev->adreno_dev; 2118: 2119: adreno_dev->hwsched_enabled = true; --- FILE: \adreno_gen8_hwsched_hfi.c | HITS: 23 --- MATCH LINES: 313, 317, 319, 320, 327 301: case GMU_CP_ILLEGAL_INST_ERROR: 302: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 303: break; 304: case GMU_CP_UCODE_ERROR: 305: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 306: break; 307: case GMU_CP_HW_FAULT_ERROR: 308: dev_crit_ratelimited(gmu_pdev_dev, 309: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 310: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 311: KEY_CP_HW_FAULT)); 312: break; 313: case GMU_GPU_PREEMPT_TIMEOUT: { 314: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 315: 316: cur = gen8_hwsched_lookup_key_value(adreno_dev, 317: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 318: next = gen8_hwsched_lookup_key_value(adreno_dev, 319: PAYLOAD_PREEMPT_TIMEOUT, 320: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 321: cur_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_RPTR); 322: cur_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_WPTR); 323: next_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_RPTR); 324: next_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_WPTR); 325: 326: dev_crit_ratelimited(gmu_pdev_dev, 327: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 328: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 329: } 330: break; 331: case GMU_CP_GPC_ERROR: 332: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: GPC error\n"); 333: break; 334: case GMU_CP_BV_OPCODE_ERROR: 335: dev_crit_ratelimited(gmu_pdev_dev, 336: "CP BV opcode error | opcode=0x%8.8x\n", 337: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 338: KEY_CP_BV_OPCODE_ERROR)); 339: break; 340: case GMU_CP_BV_PROTECTED_ERROR: { 341: u32 status = gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 342: KEY_CP_BV_PROTECTED_ERROR); 343: 344: dev_crit_ratelimited(gmu_pdev_dev, 345: "CP BV | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 346: status & (1 << 20) ? "READ" : "WRITE", 347: status & 0x3FFFF, status); 348: } 349: break; 350: case GMU_CP_BV_HW_FAULT_ERROR: 351: dev_crit_ratelimited(gmu_pdev_dev, MATCH LINES: 1572, 1579, 1583, 1587, 1588, 1589, 1591, 1617, 1621 1560: } 1561: 1562: static void gen8_hwsched_enable_async_hfi(struct adreno_device *adreno_dev) 1563: { 1564: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 1565: 1566: hfi->irq_mask |= HFI_IRQ_MSGQ_MASK; 1567: 1568: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN8_GMUCX_GMU2HOST_INTR_MASK, 1569: (u32)~hfi->irq_mask); 1570: } 1571: 1572: static int enable_preemption(struct adreno_device *adreno_dev) 1573: { 1574: const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev); 1575: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1576: u32 data; 1577: int ret; 1578: 1579: if (!adreno_is_preemption_enabled(adreno_dev)) 1580: return 0; 1581: 1582: /* 1583: * Bits [0:1] contains the preemption level 1584: * Bit 2 is to enable/disable gmem save/restore 1585: * Bit 3 is to enable/disable skipsaverestore 1586: */ 1587: data = FIELD_PREP(GENMASK(1, 0), adreno_dev->preempt.preempt_level) | 1588: FIELD_PREP(BIT(2), adreno_dev->preempt.usesgmem) | 1589: FIELD_PREP(BIT(3), adreno_dev->preempt.skipsaverestore); 1590: 1591: ret = gen8_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_PREEMPTION, 1, 1592: data); 1593: if (ret) 1594: return ret; 1595: 1596: if (gen8_core->qos_value) { 1597: int i; 1598: 1599: for (i = 0; i < KGSL_PRIORITY_MAX_RB_LEVELS; i++) { 1600: if (!gen8_core->qos_value[i]) 1601: continue; 1602: 1603: gen8_hfi_send_set_value(adreno_dev, 1604: HFI_VALUE_RB_GPU_QOS, i, 1605: gen8_core->qos_value[i]); 1606: } 1607: } 1608: 1609: if (device->pwrctrl.rt_bus_hint) { 1610: ret = gen8_hfi_send_set_value(adreno_dev, HFI_VALUE_RB_IB_RULE, 0, 1611: device->pwrctrl.rt_bus_hint); 1612: if (ret) 1613: device->pwrctrl.rt_bus_hint = 0; 1614: } 1615: 1616: /* 1617: * Bits[3:0] contain the preemption timeout enable bit per ringbuffer 1618: * Bits[31:4] contain the timeout in ms 1619: */ 1620: return gen8_hfi_send_set_value(adreno_dev, HFI_VALUE_BIN_TIME, 1, 1621: FIELD_PREP(GENMASK(31, 4), ADRENO_PREEMPT_TIMEOUT) | 1622: FIELD_PREP(GENMASK(3, 0), 0xf)); 1623: 1624: } 1625: 1626: static int enable_gmu_stats(struct adreno_device *adreno_dev) 1627: { 1628: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1629: u32 data; 1630: 1631: if (!gmu->stats_enable) 1632: return 0; 1633: 1634: /* 1635: * Bits [23:0] contains the countables mask 1636: * Bits [31:24] is the sampling interval 1637: */ 1638: data = FIELD_PREP(GENMASK(23, 0), gmu->stats_mask) | 1639: FIELD_PREP(GENMASK(31, 24), gmu->stats_interval); 1640: 1641: return gen8_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_GMU_STATS, 1, data); 1642: } 1643: 1644: static int gen8_hfi_send_perfcounter_feature_ctrl(struct adreno_device *adreno_dev) 1645: { MATCH LINES: 1792 1780: ret = gen8_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_FAST_CONTEXT_DESTROY, 1, 0); 1781: if (!ret) 1782: set_bit(ADRENO_DEVICE_FAST_CONTEXT_DESTROY, &adreno_dev->priv); 1783: 1784: return ret; 1785: } 1786: 1787: static void gen8_spin_idle_debug_lpac(struct adreno_device *adreno_dev, 1788: const char *str) 1789: { 1790: struct kgsl_device *device = &adreno_dev->dev; 1791: u32 rptr, wptr, status, intstatus, global_status; 1792: bool val = adreno_is_preemption_enabled(adreno_dev); 1793: 1794: dev_err(device->dev, str); 1795: 1796: kgsl_regread(device, GEN8_CP_RB_RPTR_LPAC, &rptr); 1797: kgsl_regread(device, GEN8_CP_RB_WPTR_LPAC, &wptr); 1798: 1799: kgsl_regread(device, GEN8_RBBM_STATUS, &status); 1800: kgsl_regread(device, GEN8_RBBM_INT_0_STATUS, &intstatus); 1801: kgsl_regread(device, GEN8_CP_INTERRUPT_STATUS_GLOBAL, &global_status); 1802: 1803: dev_err(device->dev, 1804: "LPAC rb=%d pos=%X/%X rbbm_status=%8.8X int_0_status=%8.8X global_status=%8.8X\n", 1805: val ? KGSL_LPAC_RB_ID : 1, rptr, wptr, 1806: status, intstatus, global_status); 1807: 1808: kgsl_device_snapshot(device, NULL, NULL, false); 1809: } 1810: 1811: static bool gen8_hwsched_warmboot_possible(struct adreno_device *adreno_dev) 1812: { 1813: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1814: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1815: struct gmu_core_device *gmu_core = &device->gmu_core; 1816: MATCH LINES: 2643 2631: if (gmu->log_group_mask) 2632: gen8_hfi_send_set_value(adreno_dev, 2633: HFI_VALUE_LOG_GROUP, 0, gmu->log_group_mask); 2634: 2635: ret = gen8_hfi_send_core_fw_start(adreno_dev); 2636: if (ret) 2637: goto err; 2638: 2639: ret = gen8_hfi_send_hw_fence_feature_ctrl(adreno_dev); 2640: if (ret) 2641: goto err; 2642: 2643: ret = enable_preemption(adreno_dev); 2644: if (ret) 2645: goto err; 2646: 2647: ret = gen8_hfi_send_lpac_feature_ctrl(adreno_dev); 2648: if (ret) 2649: goto err; 2650: 2651: if (ADRENO_FEATURE(adreno_dev, ADRENO_AQE)) { 2652: ret = gen8_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_AQE, 1, 0); 2653: if (ret) 2654: goto err; 2655: } 2656: 2657: ret = gen8_hfi_send_soft_reset_feature_ctrl(adreno_dev); 2658: if (ret) 2659: goto err; 2660: 2661: ret = gen8_hfi_send_fast_context_destroy_feature_ctrl(adreno_dev); 2662: if (ret) 2663: goto err; 2664: 2665: if (adreno_dev->dcvs_profile_enabled) { 2666: ret = gen8_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_DCVS_PROFILE, 1, 0); 2667: if (ret) MATCH LINES: 3193 3181: 3182: cmd->numibs = cmdobj->numibs; 3183: } 3184: 3185: #define HFI_DSP_IRQ_BASE 2 3186: 3187: #define DISPQ_IRQ_BIT(_idx) BIT((_idx) + HFI_DSP_IRQ_BASE) 3188: #define DISPQ_SYNC_IRQ_BIT(_idx) ((DISPQ_IRQ_BIT(_idx) << (KGSL_PRIORITY_MAX_RB_LEVELS + 1))) 3189: 3190: 3191: static u32 get_irq_bit(struct adreno_device *adreno_dev, struct kgsl_context *context) 3192: { 3193: if (adreno_is_preemption_enabled(adreno_dev)) 3194: return adreno_get_level(context); 3195: 3196: if (kgsl_context_is_lpac(context)) 3197: return 1; 3198: 3199: return 0; 3200: } 3201: 3202: static bool _is_kgsl_hw_fence_signaled(struct kgsl_drawobj_sync_hw_fence *hw_fence) 3203: { 3204: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)hw_fence->fence; 3205: struct kgsl_sync_timeline *ktimeline = kfence->parent; 3206: 3207: if (dma_fence_is_signaled_locked(&kfence->fence)) 3208: return true; 3209: 3210: /* 3211: * If we fail to get the context refcount that means this context is detached. 3212: * In that case, treat all hardware fences from detached context as signaled. 3213: */ 3214: if ((!hw_fence->context) && (!_kgsl_context_get(ktimeline->context))) 3215: return true; 3216: 3217: return false; MATCH LINES: 4410, 4413, 4416, 4420, 4421, 4423 4398: */ 4399: if (device->snapshot) 4400: device->snapshot->recovered = true; 4401: 4402: device->reset_counter++; 4403: done: 4404: if (ret) 4405: dev_err(device->dev, "GPU soft reset failed: %d\n", ret); 4406: 4407: return ret; 4408: } 4409: 4410: u32 gen8_hwsched_preempt_count_get(struct adreno_device *adreno_dev) 4411: { 4412: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 4413: int ret, preempt_count = 0; 4414: 4415: ret = gmu_core_get_vrb_register(device->gmu_core.vrb, 4416: VRB_PREEMPT_COUNT_TOTAL, &preempt_count); 4417: if (ret) 4418: return 0; 4419: 4420: if ((preempt_count != 0) || (device->state != KGSL_STATE_ACTIVE)) 4421: return preempt_count; 4422: 4423: return gen8_hwsched_hfi_get_value(adreno_dev, HFI_VALUE_PREEMPT_COUNT, 0); 4424: } 4425: 4426: void gen8_hwsched_context_destroy(struct adreno_device *adreno_dev, 4427: struct adreno_context *drawctxt) 4428: { 4429: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 4430: 4431: if (drawctxt->gmu_context_queue.gmuaddr) 4432: gmu_core_free_block(device, &drawctxt->gmu_context_queue); 4433: 4434: if (drawctxt->gmu_hw_fence_queue.gmuaddr) 4435: gmu_core_free_block(device, &drawctxt->gmu_hw_fence_queue); 4436: } 4437: 4438: int gen8_hwsched_disable_hw_fence_throttle(struct adreno_device *adreno_dev) 4439: { 4440: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 4441: struct adreno_context *drawctxt = NULL; 4442: u32 ts = 0; 4443: int ret = 0; 4444: 4445: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags)) 4446: return 0; 4447: --- FILE: \adreno_gen8_hwsched_hfi.h | HITS: 4 --- MATCH LINES: 232, 236, 238, 240 220: * @context: Pointer to the KGSL context 221: * @ctx_guilty: Set to true if context is invalidated on the fault 222: * 223: * Return: 0 on success and negative error on failure 224: */ 225: int gen8_hwsched_soft_reset(struct adreno_device *adreno_dev, 226: struct kgsl_context *context, bool ctx_guilty); 227: 228: /* Helper function to get to gen8 hwsched hfi device from adreno device */ 229: struct gen8_hwsched_hfi *to_gen8_hwsched_hfi(struct adreno_device *adreno_dev); 230: 231: /** 232: * gen8_hwsched_preempt_count_get - Get preemption count from GMU 233: * @adreno_dev: Pointer to adreno device 234: * 235: * This function sends a GET_VALUE HFI packet to get the number of 236: * preemptions completed since last SLUMBER exit. 237: * 238: * Return: Preemption count 239: */ 240: u32 gen8_hwsched_preempt_count_get(struct adreno_device *adreno_dev); 241: 242: /** 243: * gen8_hwsched_lpac_cp_init - Send CP_INIT to LPAC via HFI 244: * @adreno_dev: Pointer to adreno device structure 245: * 246: * This function is used to send CP INIT packet to LPAC and 247: * enable submission to LPAC queue. 248: * 249: * Return: 0 on success and negative error on failure. 250: */ 251: int gen8_hwsched_lpac_cp_init(struct adreno_device *adreno_dev); 252: 253: /** 254: * gen8_hfi_send_lpac_feature_ctrl - Send the lpac feature hfi packet 255: * @adreno_dev: Pointer to the adreno device 256: * 257: * Return: 0 on success or negative error on failure 258: */ 259: int gen8_hfi_send_lpac_feature_ctrl(struct adreno_device *adreno_dev); 260: 261: /** 262: * gen8_hwsched_context_destroy - Destroy any hwsched related resources during context destruction 263: * @adreno_dev: Pointer to adreno device 264: * @drawctxt: Pointer to the adreno context --- FILE: \adreno_gen8_perfcounter.c | HITS: 3 --- MATCH LINES: 31 19: /* 20: * Flush delta counters (both perf counters and pipe stats) present in 21: * RBBM_S and RBBM_US to perf RAM logic to get the latest data. 22: */ 23: kgsl_regwrite(device, GEN8_RBBM_PERFCTR_FLUSH_HOST_CMD, BIT(0)); 24: kgsl_regwrite(device, GEN8_RBBM_SLICE_PERFCTR_FLUSH_HOST_CMD, BIT(0)); 25: 26: /* Ensure all writes are posted before polling status register */ 27: wmb(); 28: 29: /* 30: * Poll RBBM_PERFCTR_FLUSH_HOST_STATUS to wait for perfcounter flush completion. 31: * Use a busy loop as this is called with interrupts and preemption disabled. 32: */ 33: for (i = 0; i < 10; i++) { 34: kgsl_regread(device, GEN8_RBBM_PERFCTR_FLUSH_HOST_STATUS, &status); 35: if (((status & PERFCOUNTER_FLUSH_DONE_MASK) == PERFCOUNTER_FLUSH_DONE_MASK)) 36: return; 37: 38: udelay(10); 39: } 40: 41: /* Check status one last time */ 42: kgsl_regread(device, GEN8_RBBM_PERFCTR_FLUSH_HOST_STATUS, &status); 43: 44: if ((status & PERFCOUNTER_FLUSH_DONE_MASK) != PERFCOUNTER_FLUSH_DONE_MASK) 45: dev_err_ratelimited(device->dev, 46: "Perfcounter flush timed out: status=0x%08x\n", status); 47: } 48: 49: static int gen8_counter_br_enable(struct adreno_device *adreno_dev, 50: const struct adreno_perfcount_group *group, 51: u32 counter, u32 countable) 52: { 53: struct adreno_perfcount_register *reg = &group->regs[counter]; 54: int ret; 55: MATCH LINES: 1076, 1077 1064: GEN8_GMUCX_PERF_COUNTER_H_5, 1065: GEN8_GMUCX_PERF_COUNTER_SELECT_1), 1066: }; 1067: 1068: static struct adreno_perfcount_register gen8_perfcounters_alwayson[] = { 1069: { KGSL_PERFCOUNTER_NOT_USED, 0, 0, GEN8_CP_ALWAYS_ON_COUNTER_LO, 1070: GEN8_CP_ALWAYS_ON_COUNTER_HI, -1 }, 1071: }; 1072: 1073: /* 1074: * ADRENO_PERFCOUNTER_GROUP_RESTORE flag is enabled by default 1075: * because most of the perfcounter groups need to be restored 1076: * as part of preemption and IFPC. Perfcounter groups that are 1077: * not restored as part of preemption and IFPC should be defined 1078: * using GEN8_PERFCOUNTER_GROUP_FLAGS macro 1079: */ 1080: 1081: #define GEN8_PERFCOUNTER_GROUP_FLAGS(core, offset, name, flags, \ 1082: enable, read) \ 1083: [KGSL_PERFCOUNTER_GROUP_##offset] = { core##_perfcounters_##name, \ 1084: ARRAY_SIZE(core##_perfcounters_##name), __stringify(name), flags, \ 1085: enable, read } 1086: 1087: #define GEN8_PERFCOUNTER_GROUP(offset, name, enable, read) \ 1088: GEN8_PERFCOUNTER_GROUP_FLAGS(gen8, offset, name, \ 1089: ADRENO_PERFCOUNTER_GROUP_RESTORE, enable, read) 1090: 1091: #define GEN8_REGULAR_PERFCOUNTER_GROUP(offset, name) \ 1092: GEN8_PERFCOUNTER_GROUP(offset, name, \ 1093: gen8_counter_enable, gen8_counter_read) 1094: 1095: #define GEN8_BV_PERFCOUNTER_GROUP(offset, name, enable, read) \ 1096: GEN8_PERFCOUNTER_GROUP_FLAGS(gen8, BV_##offset, bv_##name, \ 1097: ADRENO_PERFCOUNTER_GROUP_RESTORE, enable, read) 1098: 1099: #define GEN8_BV_REGULAR_PERFCOUNTER_GROUP(offset, name) \ 1100: GEN8_BV_PERFCOUNTER_GROUP(offset, name, \ 1101: gen8_counter_enable, gen8_counter_read) --- FILE: \adreno_gen8_preempt.c | HITS: 163 --- MATCH LINES: 13, 14, 16, 27, 57, 74, 77, 90, 94, 103, 108, 110, 112, 114, 129, 130, 133, 139, 143, 146, 147, 155, 163, 166, 168, 169, 170, 171, 177, 178, 194, 196, 205, 214, 217, 218, 221, 241, 253, 261, 262, 264, 269, 271, 274, 278, 283, 297, 298, 308, 315, 316, 322, 323, 328, 329, 335, 341, 348, 349, 350, 352, 354, 355, 358, 359, 362, 365, 368, 369, 372, 373, 376, 390, 396, 401, 402, 405, 409, 418, 423, 426, 431, 433, 435, 442, 449, 451, 454, 458, 471, 476, 477, 486, 504, 507, 511, 516, 517, 519, 524, 532, 535, 541, 544, 547, 548, 551, 553, 558, 559, 563, 569, 576, 581, 585, 596, 605, 612, 616, 619, 621, 623, 627, 629, 631, 634, 639, 640, 641, 642, 647, 651, 654, 656, 657, 658, 659, 660, 661, 663, 664, 665, 666, 670, 675, 679, 683, 698, 700, 705, 708, 720, 725, 730, 735, 741, 743, 745, 750, 751, 755, 766 1: // SPDX-License-Identifier: GPL-2.0-only 2: /* 3: * Copyright (c) 2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include "adreno.h" 8: #include "adreno_gen8.h" 9: #include "adreno_pm4types.h" 10: #include "adreno_trace.h" 11: #include "kgsl_util.h" 12: 13: #define PREEMPT_RECORD(_field) \ 14: offsetof(struct gen8_cp_preemption_record, _field) 15: 16: #define PREEMPT_SMMU_RECORD(_field) \ 17: offsetof(struct gen8_cp_smmu_info, _field) 18: 19: static void _update_wptr(struct adreno_device *adreno_dev, bool reset_timer, 20: bool atomic) 21: { 22: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 23: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 24: unsigned long flags; 25: int ret = 0; 26: 27: spin_lock_irqsave(&rb->preempt_lock, flags); 28: 29: if (!atomic) { 30: /* 31: * We might have skipped updating the wptr in case we are in 32: * dispatcher context. Do it now. 33: */ 34: if (rb->skip_inline_wptr) { 35: 36: ret = gen8_fenced_write(adreno_dev, 37: GEN8_CP_RB_WPTR_GC, rb->wptr, 38: FENCE_STATUS_WRITEDROPPED0_MASK); 39: 40: reset_timer = true; 41: rb->skip_inline_wptr = false; 42: } 43: } else { 44: u32 wptr; 45: 46: kgsl_regread(device, GEN8_CP_RB_WPTR_GC, &wptr); 47: if (wptr != rb->wptr) { 48: kgsl_regwrite(device, GEN8_CP_RB_WPTR_GC, rb->wptr); 49: reset_timer = true; 50: } 51: } 52: 53: if (reset_timer) 54: rb->dispatch_q.expires = jiffies + 55: msecs_to_jiffies(adreno_drawobj_timeout); 56: 57: spin_unlock_irqrestore(&rb->preempt_lock, flags); 58: 59: if (!atomic) { 60: /* If WPTR update fails, set the fault and trigger recovery */ 61: if (ret) { 62: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 63: adreno_scheduler_fault(adreno_dev, 64: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 65: } 66: } 67: } 68: 69: static void _power_collapse_set(struct adreno_device *adreno_dev, bool val) 70: { 71: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 72: 73: gmu_core_regwrite(device, 74: GEN8_GMUCX_PWR_COL_PREEMPTION_KEEPALIVE, (val ? 1 : 0)); 75: } 76: 77: static void _gen8_preemption_done(struct adreno_device *adreno_dev) 78: { 79: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 80: u32 status; 81: 82: /* 83: * In the very unlikely case that the power is off, do nothing - the 84: * state will be reset on power up and everybody will be happy 85: */ 86: 87: if (!kgsl_state_is_awake(device)) 88: return; 89: 90: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_CNTL, &status); 91: 92: if (status & 0x1) { 93: dev_err(device->dev, 94: "Preemption not complete: status=%X cur=%d R/W=%X/%X next=%d R/W=%X/%X\n", 95: status, adreno_dev->cur_rb->id, 96: adreno_get_rptr(adreno_dev->cur_rb), 97: adreno_dev->cur_rb->wptr, 98: adreno_dev->next_rb->id, 99: adreno_get_rptr(adreno_dev->next_rb), 100: adreno_dev->next_rb->wptr); 101: 102: /* Set a fault and restart */ 103: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 104: 105: return; 106: } 107: 108: adreno_dev->preempt.count++; 109: 110: kgsl_delete_timer_sync(&adreno_dev->preempt.timer); 111: 112: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 113: 114: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 115: status, 0); 116: 117: /* Clean up all the bits */ 118: adreno_dev->prev_rb = adreno_dev->cur_rb; 119: adreno_dev->cur_rb = adreno_dev->next_rb; 120: adreno_dev->next_rb = NULL; 121: 122: /* Update the wptr for the new command queue */ 123: _update_wptr(adreno_dev, true, false); 124: 125: /* Update the dispatcher timer for the new command queue */ 126: mod_timer(&adreno_dev->dispatcher.timer, 127: adreno_dev->cur_rb->dispatch_q.expires); 128: 129: /* Clear the preempt state */ 130: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 131: } 132: 133: static void _gen8_preemption_fault(struct adreno_device *adreno_dev) 134: { 135: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 136: u32 status; 137: 138: /* 139: * If the power is on check the preemption status one more time - if it 140: * was successful then just transition to the complete state 141: */ 142: if (kgsl_state_is_awake(device)) { 143: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_CNTL, &status); 144: 145: if (!(status & 0x1)) { 146: adreno_set_preempt_state(adreno_dev, 147: ADRENO_PREEMPT_COMPLETE); 148: 149: adreno_scheduler_queue(adreno_dev); 150: return; 151: } 152: } 153: 154: dev_err(device->dev, 155: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 156: adreno_dev->cur_rb->id, 157: adreno_get_rptr(adreno_dev->cur_rb), 158: adreno_dev->cur_rb->wptr, 159: adreno_dev->next_rb->id, 160: adreno_get_rptr(adreno_dev->next_rb), 161: adreno_dev->next_rb->wptr); 162: 163: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 164: } 165: 166: static void _gen8_preemption_worker(struct work_struct *work) 167: { 168: struct adreno_preemption *preempt = container_of(work, 169: struct adreno_preemption, work); 170: struct adreno_device *adreno_dev = container_of(preempt, 171: struct adreno_device, preempt); 172: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 173: 174: /* Need to take the mutex to make sure that the power stays on */ 175: kgsl_mutex_lock(&device->mutex); 176: 177: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_FAULTED)) 178: _gen8_preemption_fault(adreno_dev); 179: 180: kgsl_mutex_unlock(&device->mutex); 181: } 182: 183: /* Find the highest priority active ringbuffer */ 184: static struct adreno_ringbuffer *gen8_next_ringbuffer( 185: struct adreno_device *adreno_dev) 186: { 187: struct adreno_ringbuffer *rb; 188: unsigned long flags; 189: u32 i; 190: 191: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 192: bool empty; 193: 194: spin_lock_irqsave(&rb->preempt_lock, flags); 195: empty = adreno_rb_empty(rb); 196: spin_unlock_irqrestore(&rb->preempt_lock, flags); 197: 198: if (!empty) 199: return rb; 200: } 201: 202: return NULL; 203: } 204: 205: void gen8_preemption_trigger(struct adreno_device *adreno_dev, bool atomic) 206: { 207: const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev); 208: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 209: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 210: struct adreno_ringbuffer *next; 211: u64 ttbr0, gpuaddr; 212: u32 contextidr, cntl; 213: unsigned long flags; 214: struct adreno_preemption *preempt = &adreno_dev->preempt; 215: 216: /* Put ourselves into a possible trigger state */ 217: if (!adreno_move_preempt_state(adreno_dev, 218: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START)) 219: return; 220: 221: /* Get the next ringbuffer to preempt in */ 222: next = gen8_next_ringbuffer(adreno_dev); 223: 224: /* 225: * Nothing to do if every ringbuffer is empty or if the current 226: * ringbuffer is the only active one 227: */ 228: if (next == NULL || next == adreno_dev->cur_rb) { 229: /* 230: * Update any critical things that might have been skipped while 231: * we were looking for a new ringbuffer 232: */ 233: 234: if (next != NULL) { 235: _update_wptr(adreno_dev, false, atomic); 236: 237: mod_timer(&adreno_dev->dispatcher.timer, 238: adreno_dev->cur_rb->dispatch_q.expires); 239: } 240: 241: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 242: return; 243: } 244: 245: /* Turn off the dispatcher timer */ 246: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 247: 248: /* 249: * This is the most critical section - we need to take care not to race 250: * until we have programmed the CP for the switch 251: */ 252: 253: spin_lock_irqsave(&next->preempt_lock, flags); 254: 255: /* Get the pagetable from the pagetable info. */ 256: kgsl_sharedmem_readq(device->scratch, &ttbr0, 257: SCRATCH_RB_OFFSET(next->id, ttbr0)); 258: kgsl_sharedmem_readl(device->scratch, &contextidr, 259: SCRATCH_RB_OFFSET(next->id, contextidr)); 260: 261: kgsl_sharedmem_writel(next->preemption_desc, 262: PREEMPT_RECORD(wptr), next->wptr); 263: 264: spin_unlock_irqrestore(&next->preempt_lock, flags); 265: 266: /* And write it to the smmu info */ 267: if (kgsl_mmu_is_perprocess(&device->mmu)) { 268: kgsl_sharedmem_writeq(iommu->smmu_info, 269: PREEMPT_SMMU_RECORD(ttbr0), ttbr0); 270: kgsl_sharedmem_writel(iommu->smmu_info, 271: PREEMPT_SMMU_RECORD(context_idr), contextidr); 272: } 273: 274: kgsl_sharedmem_readq(preempt->scratch, &gpuaddr, 275: next->id * sizeof(u64)); 276: 277: /* 278: * Set a keepalive bit before the first preemption register write. 279: * This is required since while each individual write to the context 280: * switch registers will wake the GPU from collapse, it will not in 281: * itself cause GPU activity. Thus, the GPU could technically be 282: * re-collapsed between subsequent register writes leading to a 283: * prolonged preemption sequence. The keepalive bit prevents any 284: * further power collapse while it is set. 285: * It is more efficient to use a keepalive+wake-on-fence approach here 286: * rather than an OOB. Both keepalive and the fence are effectively 287: * free when the GPU is already powered on, whereas an OOB requires an 288: * unconditional handshake with the GMU. 289: */ 290: _power_collapse_set(adreno_dev, true); 291: 292: /* 293: * Fenced writes on this path will make sure the GPU is woken up 294: * in case it was power collapsed by the GMU. 295: */ 296: if (gen8_fenced_write(adreno_dev, 297: GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_LO, 298: lower_32_bits(next->preemption_desc->gpuaddr), 299: FENCE_STATUS_WRITEDROPPED1_MASK)) 300: goto err; 301: 302: /* 303: * Above fence writes will make sure GMU comes out of 304: * IFPC state if its was in IFPC state but it doesn't 305: * guarantee that GMU FW actually moved to ACTIVE state 306: * i.e. wake-up from IFPC is complete. 307: * Wait for GMU to move to ACTIVE state before triggering 308: * preemption. This is require to make sure CP doesn't 309: * interrupt GMU during wake-up from IFPC. 310: */ 311: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 312: goto err; 313: 314: if (gen8_fenced_write(adreno_dev, 315: GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_HI, 316: upper_32_bits(next->preemption_desc->gpuaddr), 317: FENCE_STATUS_WRITEDROPPED1_MASK)) 318: goto err; 319: 320: if (kgsl_mmu_is_secured(&device->mmu)) { 321: if (gen8_fenced_write(adreno_dev, 322: GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_LO, 323: lower_32_bits(next->secure_preemption_desc->gpuaddr), 324: FENCE_STATUS_WRITEDROPPED1_MASK)) 325: goto err; 326: 327: if (gen8_fenced_write(adreno_dev, 328: GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_HI, 329: upper_32_bits(next->secure_preemption_desc->gpuaddr), 330: FENCE_STATUS_WRITEDROPPED1_MASK)) 331: goto err; 332: } 333: 334: if (gen8_fenced_write(adreno_dev, 335: GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_LO, 336: lower_32_bits(gpuaddr), 337: FENCE_STATUS_WRITEDROPPED1_MASK)) 338: goto err; 339: 340: if (gen8_fenced_write(adreno_dev, 341: GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_HI, 342: upper_32_bits(gpuaddr), 343: FENCE_STATUS_WRITEDROPPED1_MASK)) 344: goto err; 345: 346: adreno_dev->next_rb = next; 347: 348: /* Start the timer to detect a stuck preemption */ 349: mod_timer(&adreno_dev->preempt.timer, 350: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 351: 352: cntl = (preempt->preempt_level << 6) | 0x01; 353: 354: /* Skip save/restore during L1 preemption */ 355: if (preempt->skipsaverestore) 356: cntl |= (1 << 9); 357: 358: /* Enable GMEM save/restore across preemption */ 359: if (preempt->usesgmem) 360: cntl |= (1 << 8); 361: 362: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 363: cntl, 0); 364: 365: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 366: 367: if (gen8_core->qos_value) 368: kgsl_sharedmem_writel(preempt->scratch, 369: PREEMPT_SCRATCH_OFFSET(QOS_VALUE_IDX), 370: gen8_core->qos_value[next->id]); 371: 372: /* Trigger the preemption */ 373: if (gen8_fenced_write(adreno_dev, GEN8_CP_CONTEXT_SWITCH_CNTL, cntl, 374: FENCE_STATUS_WRITEDROPPED1_MASK)) { 375: adreno_dev->next_rb = NULL; 376: kgsl_delete_timer(&adreno_dev->preempt.timer); 377: goto err; 378: } 379: 380: return; 381: err: 382: /* If fenced write fails, take inline snapshot and trigger recovery */ 383: if (!in_interrupt()) { 384: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 385: adreno_scheduler_fault(adreno_dev, 386: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 387: } else { 388: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 389: } 390: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 391: /* Clear the keep alive */ 392: _power_collapse_set(adreno_dev, false); 393: 394: } 395: 396: void gen8_preemption_callback(struct adreno_device *adreno_dev, int bit) 397: { 398: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 399: u32 status; 400: 401: if (!adreno_move_preempt_state(adreno_dev, 402: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 403: return; 404: 405: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_CNTL, &status); 406: 407: if (status & 0x1) { 408: dev_err(KGSL_DEVICE(adreno_dev)->dev, 409: "preempt interrupt with non-zero status: %X\n", 410: status); 411: 412: /* 413: * Under the assumption that this is a race between the 414: * interrupt and the register, schedule the worker to clean up. 415: * If the status still hasn't resolved itself by the time we get 416: * there then we have to assume something bad happened 417: */ 418: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE); 419: adreno_scheduler_queue(adreno_dev); 420: return; 421: } 422: 423: adreno_dev->preempt.count++; 424: 425: /* 426: * We can now safely clear the preemption keepalive bit, allowing 427: * power collapse to resume its regular activity. 428: */ 429: _power_collapse_set(adreno_dev, false); 430: 431: kgsl_delete_timer(&adreno_dev->preempt.timer); 432: 433: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 434: 435: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 436: status, 0); 437: 438: adreno_dev->prev_rb = adreno_dev->cur_rb; 439: adreno_dev->cur_rb = adreno_dev->next_rb; 440: adreno_dev->next_rb = NULL; 441: 442: /* Update the wptr if it changed while preemption was ongoing */ 443: _update_wptr(adreno_dev, true, true); 444: 445: /* Update the dispatcher timer for the new command queue */ 446: mod_timer(&adreno_dev->dispatcher.timer, 447: adreno_dev->cur_rb->dispatch_q.expires); 448: 449: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 450: 451: gen8_preemption_trigger(adreno_dev, true); 452: } 453: 454: void gen8_preemption_prepare_postamble(struct adreno_device *adreno_dev) 455: { 456: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 457: const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev); 458: struct adreno_preemption *preempt = &adreno_dev->preempt; 459: u32 *postamble, count = 0; 460: 461: /* 462: * First 28 dwords of the device scratch buffer are used to store shadow rb data. 463: * Reserve 15 dwords in the device scratch buffer from SCRATCH_POSTAMBLE_OFFSET for 464: * KMD postamble pm4 packets. This should be in *device->scratch* so that userspace 465: * cannot access it. 466: */ 467: postamble = device->scratch->hostptr + SCRATCH_POSTAMBLE_OFFSET; 468: 469: /* 470: * Reserve 4 dwords in the scratch buffer for dynamic QOS control feature. To ensure QOS 471: * value is updated for first preemption, send it during bootup 472: */ 473: if (gen8_core->qos_value) { 474: postamble[count++] = cp_type7_packet(CP_MEM_TO_REG, 3); 475: postamble[count++] = GEN8_RBBM_GBIF_CLIENT_QOS_CNTL; 476: postamble[count++] = lower_32_bits(PREEMPT_SCRATCH_ADDR(adreno_dev, QOS_VALUE_IDX)); 477: postamble[count++] = upper_32_bits(PREEMPT_SCRATCH_ADDR(adreno_dev, QOS_VALUE_IDX)); 478: } 479: 480: /* 481: * Since postambles are not preserved across slumber, necessary packets 482: * must be sent to GPU before first submission. 483: * 484: * If a packet needs to be sent before first submission, add it above this. 485: */ 486: preempt->postamble_bootup_len = count; 487: 488: /* Insert PM4 packets in device scratch buffer to clear perfcounters */ 489: if (!adreno_dev->perfcounter) { 490: postamble[count++] = cp_type4_packet(GEN8_RBBM_PERFCTR_SRAM_INIT_CMD, 1); 491: postamble[count++] = 0x1; 492: postamble[count++] = cp_type4_packet(GEN8_RBBM_SLICE_PERFCTR_SRAM_INIT_CMD, 1); 493: postamble[count++] = 0x1; 494: 495: postamble[count++] = cp_type7_packet(CP_WAIT_REG_MEM, 6); 496: postamble[count++] = 0x3; 497: postamble[count++] = GEN8_RBBM_PERFCTR_SRAM_INIT_STATUS; 498: postamble[count++] = 0x0; 499: postamble[count++] = 0x1; 500: postamble[count++] = 0x1; 501: postamble[count++] = 0x0; 502: } 503: 504: preempt->postamble_len = count; 505: } 506: 507: void gen8_preemption_schedule(struct adreno_device *adreno_dev) 508: { 509: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 510: 511: if (!adreno_is_preemption_enabled(adreno_dev)) 512: return; 513: 514: kgsl_mutex_lock(&device->mutex); 515: 516: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE)) 517: _gen8_preemption_done(adreno_dev); 518: 519: gen8_preemption_trigger(adreno_dev, false); 520: 521: kgsl_mutex_unlock(&device->mutex); 522: } 523: 524: u32 gen8_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 525: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 526: u32 *cmds) 527: { 528: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 529: u32 count = kgsl_mmu_is_secured(&device->mmu) ? 12 : 9; 530: u32 *cmds_orig = cmds; 531: 532: if (!adreno_is_preemption_enabled(adreno_dev)) 533: return 0; 534: 535: if (test_and_set_bit(ADRENO_RB_SET_PSEUDO_DONE, &rb->flags)) 536: goto done; 537: 538: *cmds++ = cp_type7_packet(CP_THREAD_CONTROL, 1); 539: *cmds++ = CP_SET_THREAD_BR; 540: 541: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, count); 542: 543: /* NULL SMMU_INFO buffer - we track in KMD */ 544: *cmds++ = SET_PSEUDO_SMMU_INFO; 545: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 546: 547: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 548: cmds += cp_gpuaddr(adreno_dev, cmds, rb->preemption_desc->gpuaddr); 549: 550: if (kgsl_mmu_is_secured(&device->mmu)) { 551: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 552: cmds += cp_gpuaddr(adreno_dev, cmds, 553: rb->secure_preemption_desc->gpuaddr); 554: } 555: 556: /* 557: * There is no need to specify this address when we are about to 558: * trigger preemption. This is because CP internally stores this 559: * address specified here in the CP_SET_PSEUDO_REGISTER payload to 560: * the context record and thus knows from where to restore 561: * the saved perfcounters for the new ringbuffer. 562: */ 563: *cmds++ = SET_PSEUDO_COUNTER; 564: cmds += cp_gpuaddr(adreno_dev, cmds, 565: rb->perfcounter_save_restore_desc->gpuaddr); 566: 567: done: 568: if (drawctxt) { 569: cmds += adreno_prepare_preib_preempt_scratch(adreno_dev, drawctxt, cmds); 570: cmds += adreno_prepare_preib_postamble_scratch(adreno_dev, cmds); 571: } 572: 573: return (u32) (cmds - cmds_orig); 574: } 575: 576: u32 gen8_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 577: u32 *cmds) 578: { 579: u32 index = 0; 580: 581: if (!adreno_is_preemption_enabled(adreno_dev)) 582: return 0; 583: 584: if (adreno_dev->cur_rb) { 585: u64 dest = PREEMPT_SCRATCH_ADDR(adreno_dev, adreno_dev->cur_rb->id); 586: 587: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 4); 588: cmds[index++] = lower_32_bits(dest); 589: cmds[index++] = upper_32_bits(dest); 590: cmds[index++] = 0; 591: cmds[index++] = 0; 592: } 593: 594: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 595: cmds[index++] = CP_SET_THREAD_BOTH; 596: cmds[index++] = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 597: cmds[index++] = 0; 598: cmds[index++] = 0; 599: cmds[index++] = 1; 600: cmds[index++] = 0; 601: 602: return index; 603: } 604: 605: void gen8_preemption_start(struct adreno_device *adreno_dev) 606: { 607: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 608: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 609: struct adreno_ringbuffer *rb; 610: u32 i; 611: 612: if (!adreno_is_preemption_enabled(adreno_dev)) 613: return; 614: 615: /* Force the state to be clear */ 616: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 617: 618: if (kgsl_mmu_is_perprocess(&device->mmu)) { 619: /* smmu_info is allocated and mapped in gen8_preemption_iommu_init */ 620: kgsl_sharedmem_writel(iommu->smmu_info, 621: PREEMPT_SMMU_RECORD(magic), GEN8_CP_SMMU_INFO_MAGIC_REF); 622: kgsl_sharedmem_writeq(iommu->smmu_info, 623: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 624: 625: /* The CP doesn't use the asid record, so poison it */ 626: kgsl_sharedmem_writel(iommu->smmu_info, 627: PREEMPT_SMMU_RECORD(asid), 0xdecafbad); 628: kgsl_sharedmem_writel(iommu->smmu_info, 629: PREEMPT_SMMU_RECORD(context_idr), 0); 630: 631: kgsl_regwrite(device, GEN8_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 632: lower_32_bits(iommu->smmu_info->gpuaddr)); 633: 634: kgsl_regwrite(device, GEN8_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 635: upper_32_bits(iommu->smmu_info->gpuaddr)); 636: } 637: 638: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 639: kgsl_sharedmem_writel(rb->preemption_desc, 640: PREEMPT_RECORD(rptr), 0); 641: kgsl_sharedmem_writel(rb->preemption_desc, 642: PREEMPT_RECORD(wptr), 0); 643: 644: adreno_ringbuffer_set_pagetable(device, rb, 645: device->mmu.defaultpagetable); 646: 647: clear_bit(ADRENO_RB_SET_PSEUDO_DONE, &rb->flags); 648: } 649: } 650: 651: static void reset_rb_preempt_record(struct adreno_device *adreno_dev, 652: struct adreno_ringbuffer *rb) 653: { 654: memset(rb->preemption_desc->hostptr, 0x0, rb->preemption_desc->size); 655: 656: kgsl_sharedmem_writel(rb->preemption_desc, 657: PREEMPT_RECORD(magic), GEN8_CP_CTXRECORD_MAGIC_REF); 658: kgsl_sharedmem_writel(rb->preemption_desc, 659: PREEMPT_RECORD(cntl), GEN8_CP_RB_CNTL_DEFAULT); 660: kgsl_sharedmem_writeq(rb->preemption_desc, 661: PREEMPT_RECORD(rptr_addr), SCRATCH_RB_GPU_ADDR( 662: KGSL_DEVICE(adreno_dev), rb->id, rptr)); 663: kgsl_sharedmem_writeq(rb->preemption_desc, 664: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 665: kgsl_sharedmem_writeq(rb->preemption_desc, 666: PREEMPT_RECORD(bv_rptr_addr), SCRATCH_RB_GPU_ADDR( 667: KGSL_DEVICE(adreno_dev), rb->id, bv_rptr)); 668: } 669: 670: void gen8_reset_preempt_records(struct adreno_device *adreno_dev) 671: { 672: int i; 673: struct adreno_ringbuffer *rb; 674: 675: if (!adreno_is_preemption_enabled(adreno_dev)) 676: return; 677: 678: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 679: reset_rb_preempt_record(adreno_dev, rb); 680: } 681: } 682: 683: static int gen8_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 684: struct adreno_ringbuffer *rb) 685: { 686: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 687: u64 ctxt_record_size = adreno_dev->total_ctxt_record_sz; 688: u64 curr_gmem_size = adreno_gmem_size(adreno_dev); 689: int ret; 690: 691: /* 692: * Since RB0 always runs to completion, there is no need to 693: * save/restore GMEM data for RB0. 694: */ 695: if (rb->id == 0) 696: ctxt_record_size -= curr_gmem_size; 697: 698: ret = adreno_allocate_global(device, &rb->preemption_desc, 699: ctxt_record_size, SZ_16K, 0, 700: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 701: if (ret) 702: return ret; 703: 704: if (kgsl_mmu_is_secured(&device->mmu)) { 705: ret = adreno_allocate_global(device, &rb->secure_preemption_desc, 706: ctxt_record_size, 0, 707: KGSL_MEMFLAGS_SECURE, KGSL_MEMDESC_PRIVILEGED, 708: "secure_preemption_desc"); 709: if (ret) 710: return ret; 711: } 712: 713: ret = adreno_allocate_global(device, &rb->perfcounter_save_restore_desc, 714: GEN8_CP_PERFCOUNTER_SAVE_RESTORE_SIZE, 0, 0, 715: KGSL_MEMDESC_PRIVILEGED, 716: "perfcounter_save_restore_desc"); 717: if (ret) 718: return ret; 719: 720: reset_rb_preempt_record(adreno_dev, rb); 721: 722: return 0; 723: } 724: 725: int gen8_preemption_init(struct adreno_device *adreno_dev) 726: { 727: u32 flags = ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? KGSL_MEMDESC_PRIVILEGED : 0; 728: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 729: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 730: struct adreno_preemption *preempt = &adreno_dev->preempt; 731: struct adreno_ringbuffer *rb; 732: int ret; 733: u32 i; 734: 735: /* We are dependent on IOMMU to make preemption go on the CP side */ 736: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) { 737: ret = -ENODEV; 738: goto done; 739: } 740: 741: INIT_WORK(&preempt->work, _gen8_preemption_worker); 742: 743: /* Allocate mem for storing preemption switch record */ 744: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 745: ret = gen8_preemption_ringbuffer_init(adreno_dev, rb); 746: if (ret) 747: goto done; 748: } 749: 750: ret = adreno_allocate_global(device, &preempt->scratch, PAGE_SIZE, 751: 0, 0, flags, "preempt_scratch"); 752: if (ret) 753: goto done; 754: 755: /* Allocate mem for storing preemption smmu record */ 756: if (kgsl_mmu_is_perprocess(&device->mmu)) { 757: ret = adreno_allocate_global(device, &iommu->smmu_info, PAGE_SIZE, 0, 758: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 759: "smmu_info"); 760: if (ret) 761: goto done; 762: } 763: 764: return 0; 765: done: 766: clear_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 767: return ret; 768: } --- FILE: \adreno_gen8_ringbuffer.c | HITS: 12 --- MATCH LINES: 60 48: 49: /* 50: * Sync both threads after switching pagetables and enable BR only 51: * to make sure BV doesn't race ahead while BR is still switching 52: * pagetables. 53: */ 54: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 55: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BR; 56: 57: return count; 58: } 59: 60: static int gen8_rb_context_switch(struct adreno_device *adreno_dev, 61: struct adreno_ringbuffer *rb, 62: struct adreno_context *drawctxt) 63: { 64: struct kgsl_pagetable *pagetable = 65: adreno_drawctxt_get_pagetable(drawctxt); 66: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 67: int count = 0; 68: u32 cmds[63]; 69: 70: /* Sync both threads */ 71: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 72: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BOTH; 73: /* Reset context state */ 74: cmds[count++] = cp_type7_packet(CP_RESET_CONTEXT_STATE, 1); 75: cmds[count++] = CP_RESET_GLOBAL_LOCAL_TS | CP_CLEAR_BV_BR_COUNTER | 76: CP_CLEAR_RESOURCE_TABLE | CP_CLEAR_ON_CHIP_TS; 77: /* 78: * Enable/disable concurrent binning for pagetable switch and 79: * set the thread to BR since only BR can execute the pagetable 80: * switch packets. 81: */ 82: /* Sync both threads and enable BR only */ 83: cmds[count++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 84: cmds[count++] = CP_SYNC_THREADS | CP_SET_THREAD_BR; MATCH LINES: 153, 156, 157, 187, 188, 201, 229, 246 141: cmds[count++] = drawctxt->base.id; 142: 143: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 144: cmds[count++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 145: KGSL_MEMSTORE_GLOBAL, current_context)); 146: cmds[count++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 147: KGSL_MEMSTORE_GLOBAL, current_context)); 148: cmds[count++] = drawctxt->base.id; 149: 150: cmds[count++] = cp_type7_packet(CP_EVENT_WRITE, 1); 151: cmds[count++] = 0x31; 152: 153: if (adreno_is_preemption_enabled(adreno_dev) && drawctxt->base.user_ctxt_record) { 154: u64 gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 155: 156: cmds[count++] = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 3); 157: cmds[count++] = SET_PSEUDO_NON_PRIV_SAVE_ADDR; 158: cmds[count++] = lower_32_bits(gpuaddr); 159: cmds[count++] = upper_32_bits(gpuaddr); 160: } 161: 162: return gen8_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED, 163: cmds, count, 0, NULL); 164: } 165: 166: #define RB_SOPTIMESTAMP(device, rb) \ 167: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 168: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 169: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 170: 171: #define RB_EOPTIMESTAMP(device, rb) \ 172: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 173: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 174: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 175: 176: int gen8_ringbuffer_submit(struct adreno_ringbuffer *rb, 177: struct adreno_submit_time *time) 178: { 179: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 180: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 181: int ret = 0; 182: unsigned long flags; 183: 184: adreno_get_submit_time(adreno_dev, rb, time); 185: adreno_profile_submit_time(time); 186: 187: spin_lock_irqsave(&rb->preempt_lock, flags); 188: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 189: if (adreno_dev->cur_rb == rb) { 190: ret = gen8_fenced_write(adreno_dev, 191: GEN8_CP_RB_WPTR_GC, rb->_wptr, 192: FENCE_STATUS_WRITEDROPPED0_MASK); 193: rb->skip_inline_wptr = false; 194: } 195: } else { 196: if (adreno_dev->cur_rb == rb) 197: rb->skip_inline_wptr = true; 198: } 199: 200: rb->wptr = rb->_wptr; 201: spin_unlock_irqrestore(&rb->preempt_lock, flags); 202: 203: if (ret) { 204: /* 205: * If WPTR update fails, take inline snapshot and trigger 206: * recovery. 207: */ 208: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 209: adreno_scheduler_fault(adreno_dev, 210: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 211: } 212: 213: return ret; 214: } 215: 216: int gen8_ringbuffer_init(struct adreno_device *adreno_dev) 217: { 218: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 219: int i, ret; 220: 221: ret = adreno_allocate_global(device, &device->scratch, PAGE_SIZE, 222: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED, 223: "scratch"); 224: if (ret) 225: return ret; 226: 227: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]); 228: 229: if (!adreno_preemption_feature_set(adreno_dev)) { 230: adreno_dev->num_ringbuffers = 1; 231: return adreno_ringbuffer_setup(adreno_dev, 232: &adreno_dev->ringbuffers[0], 0); 233: } 234: 235: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers); 236: 237: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 238: int ret; 239: 240: ret = adreno_ringbuffer_setup(adreno_dev, 241: &adreno_dev->ringbuffers[i], i); 242: if (ret) 243: return ret; 244: } 245: 246: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 247: return 0; 248: } 249: 250: #define GEN8_SUBMIT_MAX 104 251: 252: int gen8_ringbuffer_addcmds(struct adreno_device *adreno_dev, 253: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 254: u32 flags, u32 *in, u32 dwords, u32 timestamp, 255: struct adreno_submit_time *time) 256: { 257: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 258: u32 size = GEN8_SUBMIT_MAX + dwords; 259: u32 *cmds, index = 0; 260: u64 profile_gpuaddr; 261: u32 profile_dwords; 262: 263: if (adreno_drawctxt_detached(drawctxt)) 264: return -ENOENT; 265: 266: if (adreno_gpu_fault(adreno_dev) != 0) 267: return -EPROTO; 268: 269: rb->timestamp++; 270: MATCH LINES: 286 274: /* All submissions are run with protected mode off due to APRIV */ 275: flags &= ~F_NOTPROTECTED; 276: 277: cmds = adreno_ringbuffer_allocspace(rb, size); 278: if (IS_ERR(cmds)) 279: return PTR_ERR(cmds); 280: 281: /* Identify the start of a command */ 282: cmds[index++] = cp_type7_packet(CP_NOP, 1); 283: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 284: 285: /* This is 25 dwords when drawctxt is not NULL and perfcounter needs to be zapped*/ 286: index += gen8_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 287: &cmds[index]); 288: 289: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 290: cmds[index++] = CP_SET_THREAD_BOTH; 291: 292: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 293: cmds[index++] = 0x101; /* IFPC disable */ 294: 295: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 296: cmds[index++] = CP_SET_THREAD_BR; 297: 298: /* 299: * The POWER_CONTROL packet should always be after IFPC disable MARKER 300: * to avoid opcode errors 301: */ 302: if (flags & F_MALU) { 303: cmds[index++] = cp_type7_packet(CP_POWER_CONTROL, 2); 304: cmds[index++] = 1; /* Control mALU power */ 305: cmds[index++] = 1; /* Turn on mALU */ 306: } 307: 308: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 309: drawctxt, &profile_dwords); 310: MATCH LINES: 435 423: } 424: 425: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 426: cmds[index++] = CP_SET_THREAD_BOTH; 427: 428: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 429: cmds[index++] = 0x100; /* IFPC enable */ 430: 431: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 432: cmds[index++] = CP_SET_THREAD_BR; 433: 434: /* 10 dwords */ 435: index += gen8_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 436: 437: /* Adjust the thing for the number of bytes we actually wrote */ 438: rb->_wptr -= (size - index); 439: 440: return gen8_ringbuffer_submit(rb, time); 441: } 442: 443: static u32 gen8_get_alwayson_counter(u32 *cmds, u64 gpuaddr) 444: { 445: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 446: cmds[1] = GEN8_CP_ALWAYS_ON_COUNTER_LO | (1 << 30) | (2 << 18); 447: cmds[2] = lower_32_bits(gpuaddr); 448: cmds[3] = upper_32_bits(gpuaddr); 449: 450: return 4; 451: } 452: 453: static u32 gen8_get_alwayson_context(u32 *cmds, u64 gpuaddr) 454: { 455: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 456: cmds[1] = GEN8_CP_ALWAYS_ON_CONTEXT_LO | (1 << 30) | (2 << 18); 457: cmds[2] = lower_32_bits(gpuaddr); 458: cmds[3] = upper_32_bits(gpuaddr); 459: MATCH LINES: 505 493: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 494: int ret; 495: 496: if (rb->drawctxt_active == drawctxt) 497: return 0; 498: 499: if (kgsl_context_detached(&drawctxt->base)) 500: return -ENOENT; 501: 502: if (!_kgsl_context_get(&drawctxt->base)) 503: return -ENOENT; 504: 505: ret = gen8_rb_context_switch(adreno_dev, rb, drawctxt); 506: if (ret) { 507: kgsl_context_put(&drawctxt->base); 508: return ret; 509: } 510: 511: trace_adreno_drawctxt_switch(rb, drawctxt); 512: 513: /* Release the current drawctxt as soon as the new one is switched */ 514: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active, 515: rb, rb->timestamp); 516: 517: rb->drawctxt_active = drawctxt; 518: return 0; 519: } 520: 521: 522: #define GEN8_USER_PROFILE_IB(rb, cmdobj, cmds, field) \ 523: gen8_get_user_profiling_ib((rb), (cmdobj), \ 524: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 525: (cmds)) 526: 527: #define GEN8_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 528: gen8_get_alwayson_counter((cmds), \ 529: (dev)->profile_buffer->gpuaddr + \ --- FILE: \adreno_gen8_snapshot.c | HITS: 2 --- MATCH LINES: 2245, 2246 2233: 2234: /* registers dumped through DBG AHB */ 2235: if (!gen8_snapshot_dbgahb_regs(device, snapshot)) 2236: goto err; 2237: 2238: /* Shader memory */ 2239: if (!gen8_snapshot_shader(device, snapshot)) 2240: goto err; 2241: 2242: kgsl_regwrite(device, GEN8_RBBM_SNAPSHOT_STATUS, 0x0); 2243: 2244: err: 2245: /* Preemption record */ 2246: adreno_snapshot_preemption_record(device, snapshot); 2247: 2248: if (is_current_rt) 2249: sched_set_fifo(current); 2250: } 2251: 2252: void gen8_crashdump_init(struct adreno_device *adreno_dev) 2253: { 2254: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2255: int ret; 2256: u64 capturescript_regs_pages = 2257: ((adreno_is_gen8_2_x(adreno_dev) || 2258: adreno_is_gen8_1_0(adreno_dev) || 2259: adreno_is_gen8_11_x(adreno_dev)) ? 400 : 200); 2260: 2261: ret = adreno_allocate_global(device, &gen8_capturescript, 2262: 50 * PAGE_SIZE, 0, KGSL_MEMFLAGS_GPUREADONLY, 2263: KGSL_MEMDESC_PRIVILEGED, "capturescript"); 2264: 2265: if (!ret) 2266: ret = adreno_allocate_global(device, &gen8_crashdump_registers, 2267: capturescript_regs_pages * PAGE_SIZE, 0, 0, 2268: KGSL_MEMDESC_PRIVILEGED, "capturescript_regs"); 2269: 2270: if (ret) --- FILE: \adreno_hfi.h | HITS: 25 --- MATCH LINES: 55 43: #define HFI_IRQ_DBGQ_MASK BIT(2) 44: #define HFI_IRQ_CM3_FAULT_MASK BIT(15) 45: #define HFI_IRQ_OOB_MASK GENMASK(31, 16) 46: #define HFI_IRQ_MASK (HFI_IRQ_SIDEMSGQ_MASK |\ 47: HFI_IRQ_DBGQ_MASK |\ 48: HFI_IRQ_CM3_FAULT_MASK) 49: 50: #define DCVS_ACK_NONBLOCK 0 51: #define DCVS_ACK_BLOCK 1 52: 53: #define HFI_FEATURE_DCVS 0 54: #define HFI_FEATURE_HWSCHED 1 55: #define HFI_FEATURE_PREEMPTION 2 56: #define HFI_FEATURE_CLOCKS_ON 3 57: #define HFI_FEATURE_BUS_ON 4 58: #define HFI_FEATURE_RAIL_ON 5 59: #define HFI_FEATURE_HWCG 6 60: #define HFI_FEATURE_LM 7 61: #define HFI_FEATURE_THROTTLE 8 62: #define HFI_FEATURE_IFPC 9 63: #define HFI_FEATURE_NAP 10 64: #define HFI_FEATURE_BCL 11 65: #define HFI_FEATURE_ACD 12 66: #define HFI_FEATURE_DIDT 13 67: #define HFI_FEATURE_DEPRECATED 14 68: #define HFI_FEATURE_CB 15 69: #define HFI_FEATURE_KPROF 16 70: #define HFI_FEATURE_BAIL_OUT_TIMER 17 71: #define HFI_FEATURE_GMU_STATS 18 72: #define HFI_FEATURE_DBQ 19 73: #define HFI_FEATURE_MINBW 20 74: #define HFI_FEATURE_CLX 21 75: #define HFI_FEATURE_LSR 23 76: #define HFI_FEATURE_LPAC 24 77: #define HFI_FEATURE_HW_FENCE 25 78: #define HFI_FEATURE_PERF_NORETAIN 26 79: #define HFI_FEATURE_DMS 27 MATCH LINES: 138, 167, 168, 169, 170, 184, 189, 194, 199, 203, 208, 211 126: #define HFI_VALUE_MIN_BW_PERF_INDEX 107 127: #define HFI_VALUE_MAX_GPU_THERMAL_INDEX 108 128: #define HFI_VALUE_GPUCLK 109 129: #define HFI_VALUE_CLK_TIME 110 130: #define HFI_VALUE_LOG_GROUP 111 131: #define HFI_VALUE_LOG_EVENT_ON 112 132: #define HFI_VALUE_LOG_EVENT_OFF 113 133: #define HFI_VALUE_DCVS_OBJ 114 134: #define HFI_VALUE_LM_CS0 115 135: #define HFI_VALUE_DBG 116 136: #define HFI_VALUE_BIN_TIME 117 137: #define HFI_VALUE_LOG_STREAM_ENABLE 119 138: #define HFI_VALUE_PREEMPT_COUNT 120 139: #define HFI_VALUE_CONTEXT_QUEUE 121 140: #define HFI_VALUE_GMU_AB_VOTE 122 141: #define HFI_VALUE_RB_GPU_QOS 123 142: #define HFI_VALUE_RB_IB_RULE 124 143: #define HFI_VALUE_GMU_WARMBOOT 125 144: #define HFI_VALUE_DCVS_ENABLE 131 145: #define HFI_VALUE_DCVS_TUNING_PARAM 132 146: #define HFI_VALUE_RB_GPULEVEL_RULE 133 147: #define HFI_VALUE_MALU 135 148: #define HFI_VALUE_GLOBAL_TOKEN 0xFFFFFFFF 149: 150: #define HFI_CTXT_FLAG_PMODE BIT(0) 151: #define HFI_CTXT_FLAG_SWITCH_INTERNAL BIT(1) 152: #define HFI_CTXT_FLAG_SWITCH BIT(3) 153: #define HFI_CTXT_FLAG_NOTIFY BIT(5) 154: #define HFI_CTXT_FLAG_NO_FAULT_TOLERANCE BIT(9) 155: #define HFI_CTXT_FLAG_PWR_RULE BIT(11) 156: #define HFI_CTXT_FLAG_PRIORITY_MASK GENMASK(15, 12) 157: #define HFI_CTXT_FLAG_IFH_NOP BIT(16) 158: #define HFI_CTXT_FLAG_SECURE BIT(17) 159: #define HFI_CTXT_FLAG_TYPE_MASK GENMASK(24, 20) 160: #define HFI_CTXT_FLAG_TYPE_ANY 0 161: #define HFI_CTXT_FLAG_TYPE_GL 1 162: #define HFI_CTXT_FLAG_TYPE_CL 2 163: #define HFI_CTXT_FLAG_TYPE_C2D 3 164: #define HFI_CTXT_FLAG_TYPE_RS 4 165: #define HFI_CTXT_FLAG_TYPE_VK 5 166: #define HFI_CTXT_FLAG_TYPE_UNKNOWN 0x1e 167: #define HFI_CTXT_FLAG_PREEMPT_STYLE_MASK GENMASK(27, 25) 168: #define HFI_CTXT_FLAG_PREEMPT_STYLE_ANY 0 169: #define HFI_CTXT_FLAG_PREEMPT_STYLE_RB 1 170: #define HFI_CTXT_FLAG_PREEMPT_STYLE_FG 2 171: 172: /* Default sampling interval in units of 50 us */ 173: #define HFI_FEATURE_GMU_STATS_INTERVAL 4 174: 175: enum hfi_mem_kind { 176: /** @HFI_MEMKIND_GENERIC: Used for requesting generic memory */ 177: HFI_MEMKIND_GENERIC = 0, 178: /** @HFI_MEMKIND_RB: Used for requesting ringbuffer memory */ 179: HFI_MEMKIND_RB, 180: /** @HFI_MEMKIND_SCRATCH: Used for requesting scratch memory */ 181: HFI_MEMKIND_SCRATCH, 182: /** 183: * @HFI_MEMKIND_CSW_SMMU_INFO: Used for requesting SMMU record for 184: * preemption context switching 185: */ 186: HFI_MEMKIND_CSW_SMMU_INFO, 187: /** 188: * @HFI_MEMKIND_CSW_PRIV_NON_SECURE: Used for requesting privileged non 189: * secure preemption records 190: */ 191: HFI_MEMKIND_CSW_PRIV_NON_SECURE, 192: /** 193: * @HFI_MEMKIND_CSW_PRIV_SECURE: Used for requesting privileged secure 194: * preemption records 195: */ 196: HFI_MEMKIND_CSW_PRIV_SECURE, 197: /** 198: * @HFI_MEMKIND_CSW_NON_PRIV: Used for requesting non privileged per 199: * context preemption buffer 200: */ 201: HFI_MEMKIND_CSW_NON_PRIV, 202: /** 203: * @HFI_MEMKIND_CSW_COUNTER: Used for requesting preemption performance 204: * counter save/restore buffer 205: */ 206: HFI_MEMKIND_CSW_COUNTER, 207: /** 208: * @HFI_MEMKIND_CTXTREC_PREEMPT_CNTR: Used for requesting preemption 209: * counter buffer 210: */ 211: HFI_MEMKIND_CTXTREC_PREEMPT_CNTR, 212: /** @HFI_MEMKIND_SYSLOG: Used for requesting system log memory */ 213: HFI_MEMKIND_SYS_LOG, 214: /** @HFI_MEMKIND_CRASH_DUMP: Used for requesting carsh dumper memory */ 215: HFI_MEMKIND_CRASH_DUMP, 216: /** 217: * @HFI_MEMKIND_MMIO_DPU: Used for requesting Display processing unit's 218: * register space 219: */ 220: HFI_MEMKIND_MMIO_DPU, 221: /** 222: * @HFI_MEMKIND_MMIO_TCSR: Used for requesting Top CSR(contains SoC 223: * doorbells) register space 224: */ 225: HFI_MEMKIND_MMIO_TCSR, 226: /** 227: * @HFI_MEMKIND_MMIO_QDSS_STM: Used for requesting QDSS STM register 228: * space 229: */ 230: HFI_MEMKIND_MMIO_QDSS_STM, 231: /** @HFI_MEMKIND_PROFILE: Used for kernel profiling */ 232: HFI_MEMKIND_PROFILE, 233: /** @HFI_MEMKIND_USER_PROFILING_IBS: Used for user profiling */ 234: HFI_MEMKIND_USER_PROFILE_IBS, 235: /** @MEMKIND_CMD_BUFFER: Used for composing ringbuffer content */ MATCH LINES: 262, 263, 278, 282, 298, 314 250: HFI_MEMKIND_MMIO_IPC_CORE, 251: /** @HFIMEMKIND_MMIO_IPCC_AOSS: Used for IPCC AOSS, second memory region */ 252: HFI_MEMKIND_MMIO_IPCC_AOSS, 253: /** 254: * @MEMKIND_CSW_LPAC_PRIV_NON_SECURE: Used for privileged nonsecure 255: * memory for LPAC context record 256: */ 257: HFI_MEMKIND_CSW_LPAC_PRIV_NON_SECURE, 258: /** @HFI_MEMKIND_MEMSTORE: Buffer used to query a context's GPU sop/eop timestamps */ 259: HFI_MEMKIND_MEMSTORE, 260: /** @HFI_MEMKIND_HW_FENCE: Hardware fence Tx/Rx headers and queues */ 261: HFI_MEMKIND_HW_FENCE, 262: /** @HFI_MEMKIND_PREEMPT_SCRATCH: Used for Preemption scratch memory */ 263: HFI_MEMKIND_PREEMPT_SCRATCH, 264: /** 265: * @HFI_MEMKIND_AQE_BUFFER: Sandbox memory used by AQE to switch 266: * between LPAC and GC 267: */ 268: HFI_MEMKIND_AQE_BUFFER, 269: /** @HFI_MEMKIND_HW_FENCE_SHADOW: Shadow memory used for caching external input fences */ 270: HFI_MEMKIND_HW_FENCE_SHADOW, 271: /** 272: * @HFI_MEMKIND_FREQMGR_SCRATCH: Scratch memory for FreqMgr task to retain information 273: * related to GMU based DCVS. 274: */ 275: HFI_MEMKIND_FREQMGR_SCRATCH, 276: /** 277: * @HFI_MEMKIND_DUMMY_CSW_PRIV_NON_SECURE: Used for requesting privileged non 278: * secure preemption records for the internal dummy buffer 279: */ 280: HFI_MEMKIND_DUMMY_CSW_PRIV_NON_SECURE, 281: /** 282: * @HFI_MEMKIND_DUMMY_CSW_COUNTER: Used for requesting preemption performance 283: * counter save/restore buffer for the internal dummy buffer 284: */ 285: HFI_MEMKIND_DUMMY_CSW_COUNTER, 286: HFI_MEMKIND_MAX, 287: }; 288: 289: static const char * const hfi_memkind_strings[] = { 290: [HFI_MEMKIND_GENERIC] = "GMU GENERIC", 291: [HFI_MEMKIND_RB] = "GMU RB", 292: [HFI_MEMKIND_SCRATCH] = "GMU SCRATCH", 293: [HFI_MEMKIND_CSW_SMMU_INFO] = "GMU SMMU INFO", 294: [HFI_MEMKIND_CSW_PRIV_NON_SECURE] = "GMU CSW PRIV NON SECURE", 295: [HFI_MEMKIND_CSW_PRIV_SECURE] = "GMU CSW PRIV SECURE", 296: [HFI_MEMKIND_CSW_NON_PRIV] = "GMU CSW NON PRIV", 297: [HFI_MEMKIND_CSW_COUNTER] = "GMU CSW COUNTER", 298: [HFI_MEMKIND_CTXTREC_PREEMPT_CNTR] = "GMU PREEMPT CNTR", 299: [HFI_MEMKIND_SYS_LOG] = "GMU SYS LOG", 300: [HFI_MEMKIND_CRASH_DUMP] = "GMU CRASHDUMP", 301: [HFI_MEMKIND_MMIO_DPU] = "GMU MMIO DPU", 302: [HFI_MEMKIND_MMIO_TCSR] = "GMU MMIO TCSR", 303: [HFI_MEMKIND_MMIO_QDSS_STM] = "GMU MMIO QDSS STM", 304: [HFI_MEMKIND_PROFILE] = "GMU KERNEL PROFILING", 305: [HFI_MEMKIND_USER_PROFILE_IBS] = "GMU USER PROFILING", 306: [HFI_MEMKIND_CMD_BUFFER] = "GMU CMD BUFFER", 307: [HFI_MEMKIND_GPU_BUSY_DATA_BUFFER] = "GMU BUSY DATA BUFFER", 308: [HFI_MEMKIND_GPU_BUSY_CMD_BUFFER] = "GMU BUSY CMD BUFFER", 309: [HFI_MEMKIND_MMIO_IPC_CORE] = "GMU MMIO IPC", 310: [HFI_MEMKIND_MMIO_IPCC_AOSS] = "GMU MMIO IPCC AOSS", 311: [HFI_MEMKIND_CSW_LPAC_PRIV_NON_SECURE] = "GMU CSW LPAC PRIV NON SECURE", 312: [HFI_MEMKIND_MEMSTORE] = "GMU MEMSTORE", 313: [HFI_MEMKIND_HW_FENCE] = "GMU HW FENCE", 314: [HFI_MEMKIND_PREEMPT_SCRATCH] = "GMU PREEMPTION", 315: [HFI_MEMKIND_AQE_BUFFER] = "GMU AQE BUFFER", 316: [HFI_MEMKIND_HW_FENCE_SHADOW] = "GMU HW FENCE SHADOW", 317: [HFI_MEMKIND_FREQMGR_SCRATCH] = "GMU FREQMGR SCRATCH", 318: [HFI_MEMKIND_DUMMY_CSW_PRIV_NON_SECURE] = "GMU DUMMY CSW PRIV NON SECURE", 319: [HFI_MEMKIND_DUMMY_CSW_COUNTER] = "GMU DUMMY CSW COUNTER", 320: [HFI_MEMKIND_MAX] = "GMU UNKNOWN", 321: }; 322: 323: /* CP/GFX pipeline can access */ 324: #define HFI_MEMFLAG_GFX_ACC BIT(0) 325: 326: /* Buffer has APRIV protection in GFX PTEs */ 327: #define HFI_MEMFLAG_GFX_PRIV BIT(1) 328: 329: /* Buffer is read-write for GFX PTEs. A 0 indicates read-only */ 330: #define HFI_MEMFLAG_GFX_WRITEABLE BIT(2) 331: 332: /* GMU can access */ 333: #define HFI_MEMFLAG_GMU_ACC BIT(3) 334: 335: /* Buffer has APRIV protection in GMU PTEs */ 336: #define HFI_MEMFLAG_GMU_PRIV BIT(4) 337: 338: /* Buffer is read-write for GMU PTEs. A 0 indicates read-only */ MATCH LINES: 1276 1264: struct payload_section { 1265: /** @type: Type of the payload */ 1266: u16 type; 1267: /** @dwords: Number of dwords in the data array. */ 1268: u16 dwords; 1269: /** @data: A sequence of key-value pairs. Each pair is 2 dwords. */ 1270: u32 data[]; 1271: } __packed; 1272: 1273: /* IDs for context bad hfi payloads */ 1274: #define PAYLOAD_FAULT_REGS 1 1275: #define PAYLOAD_RB 2 1276: #define PAYLOAD_PREEMPT_TIMEOUT 3 1277: #define PAYLOAD_FAULT_RESET_POLICY 4 1278: 1279: /* Keys for PAYLOAD_FAULT_REGS type payload */ 1280: #define KEY_CP_OPCODE_ERROR 1 1281: #define KEY_CP_PROTECTED_ERROR 2 1282: #define KEY_CP_HW_FAULT 3 1283: #define KEY_CP_BV_OPCODE_ERROR 4 1284: #define KEY_CP_BV_PROTECTED_ERROR 5 1285: #define KEY_CP_BV_HW_FAULT 6 1286: #define KEY_CP_LPAC_OPCODE_ERROR 7 1287: #define KEY_CP_LPAC_PROTECTED_ERROR 8 1288: #define KEY_CP_LPAC_HW_FAULT 9 1289: #define KEY_SWFUSE_VIOLATION_FAULT 10 1290: #define KEY_AQE0_OPCODE_ERROR 11 1291: #define KEY_AQE0_HW_FAULT 12 1292: #define KEY_AQE1_OPCODE_ERROR 13 1293: #define KEY_AQE1_HW_FAULT 14 1294: #define KEY_CP_BR_SW_FAULT 15 1295: #define KEY_CP_BV_SW_FAULT 16 1296: #define KEY_CP_LPAC_SW_FAULT 17 1297: #define KEY_CP_AQE0_SW_FAULT 18 1298: #define KEY_CP_AQE0_PROTECTED_ERROR 19 1299: #define KEY_CP_AQE1_SW_FAULT 20 1300: #define KEY_CP_AQE1_PROTECTED_ERROR 21 MATCH LINES: 1322, 1323, 1324, 1335, 1336 1310: #define KEY_TSB_WRITE_ERROR 31 1311: 1312: /* Keys for PAYLOAD_RB type payload */ 1313: #define KEY_RB_ID 1 1314: #define KEY_RB_RPTR 2 1315: #define KEY_RB_WPTR 3 1316: #define KEY_RB_SIZEDWORDS 4 1317: #define KEY_RB_QUEUED_TS 5 1318: #define KEY_RB_RETIRED_TS 6 1319: #define KEY_RB_GPUADDR_LO 7 1320: #define KEY_RB_GPUADDR_HI 8 1321: 1322: /* Keys for PAYLOAD_PREEMPT_TIMEOUT type payload */ 1323: #define KEY_PREEMPT_TIMEOUT_CUR_RB_ID 1 1324: #define KEY_PREEMPT_TIMEOUT_NEXT_RB_ID 2 1325: 1326: /* Keys for PAYLOAD_FAULT_RESET_POLICY type payload */ 1327: #define KEY_GPU_RESET_POLICY 1 1328: 1329: /* Types of errors that trigger context bad HFI */ 1330: 1331: /* GPU encountered a CP HW error */ 1332: #define GMU_CP_HW_ERROR 600 1333: /* GPU encountered a GPU Hang interrupt */ 1334: #define GMU_GPU_HW_HANG 601 1335: /* Preemption didn't complete in given time */ 1336: #define GMU_GPU_PREEMPT_TIMEOUT 602 1337: /* Fault due to Long IB timeout */ 1338: #define GMU_GPU_SW_HANG 603 1339: /* GPU encountered a bad opcode */ 1340: #define GMU_CP_OPCODE_ERROR 604 1341: /* GPU encountered protected mode error */ 1342: #define GMU_CP_PROTECTED_ERROR 605 1343: /* GPU encountered an illegal instruction */ 1344: #define GMU_CP_ILLEGAL_INST_ERROR 606 1345: /* GPU encountered a CP ucode error */ 1346: #define GMU_CP_UCODE_ERROR 607 1347: /* GPU encountered a CP hw fault error */ 1348: #define GMU_CP_HW_FAULT_ERROR 608 1349: /* GPU encountered a GPC error */ 1350: #define GMU_CP_GPC_ERROR 609 1351: /* GPU BV encountered a bad opcode */ 1352: #define GMU_CP_BV_OPCODE_ERROR 610 1353: /* GPU BV encountered protected mode error */ 1354: #define GMU_CP_BV_PROTECTED_ERROR 611 1355: /* GPU BV encountered a CP hw fault error */ 1356: #define GMU_CP_BV_HW_FAULT_ERROR 612 1357: /* GPU BV encountered a CP ucode error */ 1358: #define GMU_CP_BV_UCODE_ERROR 613 1359: /* GPU BV encountered an illegal instruction */ 1360: #define GMU_CP_BV_ILLEGAL_INST_ERROR 614 --- FILE: \adreno_hwsched.c | HITS: 45 --- MATCH LINES: 70, 94, 112, 148, 149, 162, 181 58: static void setup_gfx_flags_priv(u32 desc_flags, u64 *flags, u32 *priv) 59: { 60: if (desc_flags & HFI_MEMFLAG_GFX_PRIV) 61: *priv |= KGSL_MEMDESC_PRIVILEGED; 62: 63: if (!(desc_flags & HFI_MEMFLAG_GFX_WRITEABLE)) 64: *flags |= KGSL_MEMFLAGS_GPUREADONLY; 65: 66: if (desc_flags & HFI_MEMFLAG_GFX_SECURE) 67: *flags |= KGSL_MEMFLAGS_SECURE; 68: } 69: 70: static int reserve_preempt_record_va(struct adreno_device *adreno_dev, 71: struct hfi_mem_alloc_entry *entry, u64 flags, u32 priv) 72: { 73: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 74: struct hfi_mem_alloc_desc *desc = &entry->desc; 75: int ret = 0; 76: 77: if (!entry->md->gpuaddr) { 78: ret = kgsl_get_global_gpuaddr(device, entry->md, 79: desc->size, flags, priv); 80: if (ret) 81: return ret; 82: } 83: 84: if (!(entry->desc.flags & HFI_MEMFLAG_GMU_ACC)) 85: return ret; 86: 87: if (!entry->md->gmuaddr) 88: ret = gmu_core_reserve_gmuaddr(device, entry->md, 89: get_gmu_vma_id(desc->flags), desc->align); 90: 91: return ret; 92: } 93: 94: static int alloc_map_preempt_record(struct adreno_device *adreno_dev, 95: struct kgsl_memdesc **md, struct hfi_mem_alloc_entry *entry, u64 offset, 96: u64 flags, u32 priv) 97: { 98: u64 ctxt_record_size = adreno_dev->total_ctxt_record_sz; 99: u64 curr_gmem_size = adreno_gmem_size(adreno_dev); 100: u64 md_size = ctxt_record_size - curr_gmem_size; 101: struct hfi_mem_alloc_desc *desc = &entry->desc; 102: 103: if (*md) 104: return 0; 105: 106: if (offset >= (entry->md->size)) 107: return -ENOSPC; 108: 109: *md = kgsl_alloc_map_gpu_global(KGSL_DEVICE(adreno_dev), 110: entry->md->gpuaddr + offset, md_size, 0, flags, priv, 111: (entry->desc.mem_kind == HFI_MEMKIND_CSW_PRIV_SECURE) ? 112: "sec_preempt_record_non_gmem" : "preempt_record_non_gmem"); 113: if (IS_ERR(*md)) { 114: int ret = PTR_ERR(*md); 115: 116: *md = NULL; 117: return ret; 118: } 119: 120: if (!(desc->flags & HFI_MEMFLAG_GMU_ACC)) 121: return 0; 122: 123: if ((*md)->gmuaddr) 124: return 0; 125: 126: return gmu_core_map_gmu(KGSL_DEVICE(adreno_dev), *md, 127: entry->md->gmuaddr + offset, 128: get_gmu_vma_id(desc->flags), 129: gmu_core_get_attrs(desc->flags), desc->align); 130: } 131: 132: static int alloc_map_non_gmem(struct adreno_device *adreno_dev, 133: struct hfi_mem_alloc_entry *entry, u64 flags, u32 priv) 134: { 135: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 136: u64 ctxt_record_sz = adreno_dev->total_ctxt_record_sz, offset = 0; 137: u64 curr_gmem_size = adreno_gmem_size(adreno_dev); 138: bool no_rb0_gmem = false; 139: int i; 140: 141: /* Check whether GMU has removed GMEM size from RB0 context record */ 142: if (entry->desc.size == ((ctxt_record_sz * KGSL_PRIORITY_MAX_RB_LEVELS) - 143: curr_gmem_size)) 144: no_rb0_gmem = true; 145: 146: for (i = 0; i < KGSL_PRIORITY_MAX_RB_LEVELS; i++) { 147: struct kgsl_memdesc **md = (entry->desc.mem_kind == HFI_MEMKIND_CSW_PRIV_SECURE) ? 148: &hwsched->secure_preempt_rec[i] : &hwsched->preempt_rec[i]; 149: int ret = alloc_map_preempt_record(adreno_dev, md, entry, offset, flags, priv); 150: 151: if (ret) 152: return ret; 153: 154: offset += ctxt_record_sz; 155: if ((i == 0) && no_rb0_gmem) 156: offset -= curr_gmem_size; 157: } 158: 159: return 0; 160: } 161: 162: static int process_preempt_record_mem_alloc(struct adreno_device *adreno_dev, 163: struct hfi_mem_alloc_entry *entry) 164: { 165: u64 flags = 0; 166: u32 priv = 0; 167: int ret; 168: 169: if (!entry->md) { 170: struct gmu_core_device *gmu = &KGSL_DEVICE(adreno_dev)->gmu_core; 171: 172: if (gmu->global_entries == ARRAY_SIZE(gmu->gmu_globals)) 173: return -ENOMEM; 174: 175: entry->md = &gmu->gmu_globals[gmu->global_entries]; 176: gmu->global_entries++; 177: } 178: 179: setup_gfx_flags_priv(entry->desc.flags, &flags, &priv); 180: 181: ret = reserve_preempt_record_va(adreno_dev, entry, flags, priv); 182: if (ret) 183: return ret; 184: 185: return alloc_map_non_gmem(adreno_dev, entry, flags, priv); 186: } 187: 188: static struct hfi_mem_alloc_entry *lookup_mem_alloc_table( 189: struct adreno_device *adreno_dev, struct hfi_mem_alloc_desc *desc) 190: { 191: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 192: int i; 193: 194: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 195: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 196: 197: if ((entry->desc.mem_kind == desc->mem_kind) && 198: (entry->desc.gmu_mem_handle == desc->gmu_mem_handle)) 199: return entry; 200: } 201: 202: return NULL; 203: } 204: 205: static struct hfi_mem_alloc_entry *get_mem_alloc_entry( MATCH LINES: 280, 291 268: */ 269: switch (desc->mem_kind) { 270: case HFI_MEMKIND_HW_FENCE: 271: entry->md = &adreno_dev->hwsched.hw_fence.md; 272: break; 273: case HFI_MEMKIND_MEMSTORE: 274: entry->md = device->memstore; 275: break; 276: case HFI_MEMKIND_CSW_PRIV_NON_SECURE: 277: case HFI_MEMKIND_CSW_PRIV_SECURE: 278: /* 279: * Standard kernel does not support secure SIDs. But GMU FW 280: * always requests a secure preempt buffer regardless. Back it 281: * with a PAGE_SIZE non-secure dummy buffer to give CP a valid 282: * GPU VA to write to. 283: */ 284: if (desc->mem_kind == HFI_MEMKIND_CSW_PRIV_SECURE && 285: !kgsl_mmu_is_secured(&device->mmu)) { 286: entry->desc.flags &= ~HFI_MEMFLAG_GFX_SECURE; 287: flags &= ~KGSL_MEMFLAGS_SECURE; 288: entry->desc.size = PAGE_SIZE; 289: } 290: if (ADRENO_FEATURE(adreno_dev, ADRENO_DEFER_GMEM_ALLOC)) { 291: ret = process_preempt_record_mem_alloc(adreno_dev, entry); 292: if (ret) 293: return ERR_PTR(ret); 294: 295: entry->desc.size = entry->md->size; 296: entry->desc.gpu_addr = entry->md->gpuaddr; 297: entry->desc.gmu_addr = entry->md->gmuaddr; 298: 299: goto done; 300: } 301: /* Allocate global through legacy approach */ 302: fallthrough; 303: default: 304: entry->md = kgsl_allocate_global(device, entry->desc.size, 0, flags, 305: priv, memkind_string); 306: break; 307: } 308: if (IS_ERR(entry->md)) { 309: ret = PTR_ERR(entry->md); 310: 311: memset(entry, 0, sizeof(*entry)); 312: return ERR_PTR(ret); 313: } 314: 315: entry->desc.size = entry->md->size; MATCH LINES: 374, 392, 408, 412, 417, 418, 429, 432, 438, 452, 455 362: mad->gmu_addr = entry->md->gmuaddr; 363: } 364: 365: /* 366: * GMU uses the host_mem_handle to check if this memalloc was 367: * successful 368: */ 369: mad->host_mem_handle = mad->gmu_mem_handle; 370: 371: return 0; 372: } 373: 374: static struct hfi_mem_alloc_entry *get_preempt_record_entry(struct adreno_device *adreno_dev, 375: unsigned long flags) 376: { 377: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 378: u32 mem_kind = flags & KGSL_CONTEXT_SECURE ? 379: HFI_MEMKIND_CSW_PRIV_SECURE : HFI_MEMKIND_CSW_PRIV_NON_SECURE; 380: u32 i; 381: 382: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 383: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 384: 385: if (entry->desc.mem_kind == mem_kind) 386: return entry; 387: } 388: 389: return NULL; 390: } 391: 392: static int adreno_hwsched_alloc_preempt_record_gmem(struct adreno_device *adreno_dev, 393: struct adreno_context *drawctxt) 394: { 395: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 396: struct kgsl_context *context = &drawctxt->base; 397: struct kgsl_device *device = context->device; 398: struct hfi_mem_alloc_entry *entry = NULL; 399: struct kgsl_memdesc *pr_md, **md = NULL; 400: u32 priv = 0, level = adreno_get_level(context); 401: u64 curr_gmem_size = adreno_gmem_size(adreno_dev); 402: u64 flags = 0; 403: int ret = 0; 404: 405: if (context->flags & KGSL_CONTEXT_LPAC) 406: return 0; 407: 408: if (!ADRENO_FEATURE(adreno_dev, ADRENO_PREEMPTION) || 409: !ADRENO_FEATURE(adreno_dev, ADRENO_DEFER_GMEM_ALLOC)) 410: return 0; 411: 412: /* No need to allocate gmem for RB0 preemption record */ 413: if (!level) 414: return 0; 415: 416: md = context->flags & KGSL_CONTEXT_SECURE ? 417: &hwsched->secure_preempt_rec_gmem[level - 1] : 418: &hwsched->preempt_rec_gmem[level - 1]; 419: 420: /* Avoid device mutex if buffer is already allocated */ 421: if (*md) 422: return 0; 423: 424: kgsl_mutex_lock(&device->mutex); 425: 426: if (*md) 427: goto unlock; 428: 429: entry = get_preempt_record_entry(adreno_dev, context->flags); 430: if (!entry) { 431: dev_err_ratelimited(GMU_PDEV_DEV(device), 432: "preempt record entry not found\n"); 433: ret = -EINVAL; 434: goto unlock; 435: } 436: 437: pr_md = context->flags & KGSL_CONTEXT_SECURE ? 438: hwsched->secure_preempt_rec[level] : hwsched->preempt_rec[level]; 439: 440: if ((pr_md->gpuaddr + pr_md->size + curr_gmem_size) > 441: (entry->md->gpuaddr + entry->md->size)) { 442: ret = -ENOSPC; 443: goto unlock; 444: } 445: 446: setup_gfx_flags_priv(entry->desc.flags, &flags, &priv); 447: 448: /* gmem section only needs to be mapped to gpu */ 449: *md = kgsl_alloc_map_gpu_global(device, pr_md->gpuaddr + pr_md->size, 450: curr_gmem_size, 0, flags, priv, 451: (entry->desc.mem_kind == HFI_MEMKIND_CSW_PRIV_SECURE) ? 452: "sec_preempt_record_gmem" : "preempt_record_gmem"); 453: if (!*md) { 454: dev_err_ratelimited(GMU_PDEV_DEV(device), 455: "Failed to allocate gmem preempt record for rb:%d\n", level); 456: ret = PTR_ERR(*md); 457: kfree(*md); 458: } 459: unlock: 460: kgsl_mutex_unlock(&device->mutex); 461: return ret; 462: } 463: 464: static bool is_cmdobj(struct kgsl_drawobj *drawobj) 465: { 466: return (drawobj->type & CMDOBJ_TYPE); 467: } 468: 469: static bool _check_context_queue(struct adreno_context *drawctxt, u32 count) 470: { 471: bool ret; 472: 473: spin_lock(&drawctxt->lock); 474: 475: /* 476: * Wake up if there is room in the context or if the whole thing got 477: * invalidated while we were asleep 478: */ 479: MATCH LINES: 1674, 1676, 1679, 1681, 1682, 1685, 1688, 1690, 1693, 1702, 1709, 1714, 1715, 1720, 1721, 1734, 1735, 1739, 1740, 1741 1662: adreno_scheduler_queue(adreno_dev); 1663: } 1664: 1665: void adreno_hwsched_start(struct adreno_device *adreno_dev) 1666: { 1667: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1668: 1669: complete_all(&device->halt_gate); 1670: 1671: adreno_scheduler_queue(adreno_dev); 1672: } 1673: 1674: static void change_preemption(struct adreno_device *adreno_dev, void *priv) 1675: { 1676: change_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 1677: } 1678: 1679: static int _preemption_store(struct adreno_device *adreno_dev, bool val) 1680: { 1681: if (!adreno_preemption_feature_set(adreno_dev) || 1682: (test_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv) == val)) 1683: return 0; 1684: 1685: return adreno_power_cycle(adreno_dev, change_preemption, NULL); 1686: } 1687: 1688: static bool _preemption_show(struct adreno_device *adreno_dev) 1689: { 1690: return adreno_is_preemption_enabled(adreno_dev); 1691: } 1692: 1693: static unsigned int _preempt_count_show(struct adreno_device *adreno_dev) 1694: { 1695: const struct adreno_hwsched_ops *hwsched_ops = 1696: adreno_dev->hwsched.hwsched_ops; 1697: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1698: u32 count; 1699: 1700: kgsl_mutex_lock(&device->mutex); 1701: 1702: count = hwsched_ops->preempt_count(adreno_dev); 1703: 1704: kgsl_mutex_unlock(&device->mutex); 1705: 1706: return count; 1707: } 1708: 1709: ssize_t _preempt_info_show(struct device *dev, struct device_attribute *attr, char *buf) 1710: { 1711: struct adreno_device *adreno_dev = ADRENO_DEVICE(dev_get_drvdata(dev)); 1712: const struct adreno_hwsched_ops *hwsched_ops = adreno_dev->hwsched.hwsched_ops; 1713: 1714: if (hwsched_ops->preempt_info) 1715: return hwsched_ops->preempt_info(adreno_dev, buf); 1716: 1717: return -EOPNOTSUPP; 1718: } 1719: 1720: static struct device_attribute adreno_attr_preempt_info = 1721: __ATTR(preempt_info, 0444, _preempt_info_show, NULL); 1722: 1723: static int _ft_long_ib_detect_store(struct adreno_device *adreno_dev, bool val) 1724: { 1725: return adreno_power_cycle_bool(adreno_dev, &adreno_dev->long_ib_detect, 1726: val); 1727: } 1728: 1729: static bool _ft_long_ib_detect_show(struct adreno_device *adreno_dev) 1730: { 1731: return adreno_dev->long_ib_detect; 1732: } 1733: 1734: static ADRENO_SYSFS_BOOL(preemption); 1735: static ADRENO_SYSFS_RO_U32(preempt_count); 1736: static ADRENO_SYSFS_BOOL(ft_long_ib_detect); 1737: 1738: static const struct attribute *_hwsched_attr_list[] = { 1739: &adreno_attr_preemption.attr.attr, 1740: &adreno_attr_preempt_count.attr.attr, 1741: &adreno_attr_preempt_info.attr, 1742: &adreno_attr_ft_long_ib_detect.attr.attr, 1743: NULL, 1744: }; 1745: 1746: void adreno_hwsched_deregister_hw_fence(struct adreno_device *adreno_dev) 1747: { 1748: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1749: 1750: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags)) 1751: return; 1752: 1753: kgsl_hw_fence_close(KGSL_DEVICE(adreno_dev)); 1754: 1755: if (hwsched->hw_fence.md.sgt) 1756: sg_free_table(hwsched->hw_fence.md.sgt); 1757: 1758: memset(&hwsched->hw_fence.md, 0x0, sizeof(hwsched->hw_fence.md)); 1759: 1760: kmem_cache_destroy(hwsched->hw_fence_cache); 1761: 1762: clear_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags); 1763: } 1764: 1765: static void adreno_hwsched_dispatcher_close(struct adreno_device *adreno_dev) MATCH LINES: 2478 2466: return; 2467: 2468: /* Do not create a hardware backed fence, if this context is bad or going away */ 2469: if (kgsl_context_is_bad(context)) 2470: return; 2471: 2472: hwsched_ops->create_hw_fence(adreno_dev, kfence); 2473: } 2474: 2475: static int adreno_hwsched_setup_context(struct adreno_device *adreno_dev, 2476: struct adreno_context *drawctxt) 2477: { 2478: return adreno_hwsched_alloc_preempt_record_gmem(adreno_dev, drawctxt); 2479: } 2480: 2481: static const struct adreno_dispatch_ops hwsched_ops = { 2482: .close = adreno_hwsched_dispatcher_close, 2483: .queue_cmds = adreno_hwsched_queue_cmds, 2484: .queue_context = adreno_hwsched_queue_context, 2485: .create_hw_fence = adreno_hwsched_create_hw_fence, 2486: .setup_context = adreno_hwsched_setup_context, 2487: }; 2488: 2489: static void hwsched_lsr_check(struct work_struct *work) 2490: { 2491: struct adreno_hwsched *hwsched = container_of(work, 2492: struct adreno_hwsched, lsr_check_ws); 2493: struct adreno_device *adreno_dev = container_of(hwsched, 2494: struct adreno_device, hwsched); 2495: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2496: 2497: kgsl_mutex_lock(&device->mutex); 2498: kgsl_pwrscale_update_stats(device); 2499: kgsl_pwrscale_update(device); 2500: kgsl_mutex_unlock(&device->mutex); 2501: 2502: mod_timer(&hwsched->lsr_timer, jiffies + msecs_to_jiffies(10)); MATCH LINES: 2759 2747: if (ret) 2748: return ret; 2749: 2750: do { 2751: if (adreno_gpu_fault(adreno_dev)) 2752: return -EDEADLK; 2753: 2754: if (gpudev->hw_isidle(adreno_dev)) 2755: return 0; 2756: } while (time_before(jiffies, wait)); 2757: 2758: /* 2759: * Under rare conditions, preemption can cause the while loop to exit 2760: * without checking if the gpu is idle. check one last time before we 2761: * return failure. 2762: */ 2763: if (adreno_gpu_fault(adreno_dev)) 2764: return -EDEADLK; 2765: 2766: if (gpudev->hw_isidle(adreno_dev)) 2767: return 0; 2768: 2769: return -ETIMEDOUT; 2770: } 2771: 2772: void adreno_hwsched_register_hw_fence(struct adreno_device *adreno_dev) 2773: { 2774: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 2775: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2776: int ret; 2777: 2778: if (!ADRENO_FEATURE(adreno_dev, ADRENO_HW_FENCE)) 2779: return; 2780: 2781: if (test_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags)) 2782: return; 2783: MATCH LINES: 3390, 3394, 3396 3378: u32 i; 3379: 3380: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 3381: struct hfi_mem_alloc_desc *desc = &hwsched->mem_alloc_table[i].desc; 3382: 3383: if (desc->flags & HFI_MEMFLAG_HOST_INIT) { 3384: md = hwsched->mem_alloc_table[i].md; 3385: if (md->hostptr) 3386: memset(md->hostptr, 0x0, md->size); 3387: } 3388: } 3389: 3390: if (!(adreno_is_preemption_enabled(adreno_dev) && 3391: ADRENO_FEATURE(adreno_dev, ADRENO_DEFER_GMEM_ALLOC))) 3392: return; 3393: 3394: /* No need to reset gmem portion of the preemption records */ 3395: for (i = 0; i < KGSL_PRIORITY_MAX_RB_LEVELS; i++) { 3396: md = hwsched->preempt_rec[i]; 3397: if (md && md->hostptr) 3398: memset(md->hostptr, 0x0, md->size); 3399: } 3400: } --- FILE: \adreno_hwsched.h | HITS: 15 --- MATCH LINES: 84, 86, 88, 90 72: 73: /** 74: * struct adreno_hwsched_ops - Function table to hook hwscheduler things 75: * to target specific routines 76: */ 77: struct adreno_hwsched_ops { 78: /** 79: * @submit_drawobj - Target specific function to submit IBs to hardware 80: */ 81: int (*submit_drawobj)(struct adreno_device *adreno_dev, 82: struct kgsl_drawobj *drawobj); 83: /** 84: * @preempt_count - Target specific function to get preemption count 85: */ 86: u32 (*preempt_count)(struct adreno_device *adreno_dev); 87: /** 88: * @preempt_info - Target specific function to get preemption information 89: */ 90: ssize_t (*preempt_info)(struct adreno_device *adreno_dev, char *buf); 91: /** 92: * @create_hw_fence - Target specific function to create a hardware fence 93: */ 94: void (*create_hw_fence)(struct adreno_device *adreno_dev, 95: struct kgsl_sync_fence *kfence); 96: /** 97: * @set_dcvs_profile - Set dcvs profile for a process 98: */ 99: int (*set_dcvs_profile)(struct adreno_device *adreno_dev, 100: struct kgsl_process_private *proc_priv); 101: }; 102: 103: enum gpu_reset_type { 104: GMU_GPU_RESET_NONE, 105: GMU_GPU_SOFT_RESET, 106: GMU_GPU_HARD_RESET, 107: }; 108: 109: struct adreno_dcvs_tunable { 110: /** @value: Stores the requested value for the tunable **/ 111: u32 value; 112: /** @update: True if this value needs to be sent to GMU at slumber exit **/ 113: bool update; 114: }; MATCH LINES: 165, 166, 168, 169, 171, 173, 174, 176, 178, 179, 181 153: * @submission_seqnum: Sequence number for sending submissions to GMU context queues or 154: * dispatch queues 155: */ 156: atomic_t submission_seqnum; 157: /** @global_ctxtq: Memory descriptor for global context queue */ 158: struct kgsl_memdesc global_ctxtq; 159: /** @global_ctxt_gmu_registered: Whether global context is registered with gmu */ 160: bool global_ctxt_gmu_registered; 161: /** @hw_fence: Container for hw fence related structures */ 162: struct adreno_hwsched_hw_fence hw_fence; 163: /** @reset_type: GPU fault reset (hard/soft) type */ 164: enum gpu_reset_type reset_type; 165: /** @preempt_rec: Memory descriptors for non-gmem part of preemption records */ 166: struct kgsl_memdesc *preempt_rec[KGSL_PRIORITY_MAX_RB_LEVELS]; 167: /** 168: * @preempt_rec_gmem: Memory descriptors for gmem part of preemption 169: * records. No gmem buffer needed for rb0 preemption record. 170: */ 171: struct kgsl_memdesc *preempt_rec_gmem[KGSL_PRIORITY_MAX_RB_LEVELS - 1]; 172: /** 173: * @secure_preempt_rec: Memory descriptors for non-gmem part of secure 174: * preemption records 175: */ 176: struct kgsl_memdesc *secure_preempt_rec[KGSL_PRIORITY_MAX_RB_LEVELS]; 177: /** 178: * @secure_preempt_rec_gmem: Memory descriptors for gmem part of secure 179: * preemption records. No gmem buffer needed for rb0 preemption record. 180: */ 181: struct kgsl_memdesc *secure_preempt_rec_gmem[KGSL_PRIORITY_MAX_RB_LEVELS - 1]; 182: /** @dcvs_param_update: True if dcvs params have to be sent to GMU at slumber exit */ 183: bool dcvs_param_update; 184: /** @tunables_kobj: Kobj for dcvs tunables **/ 185: struct kobject tunables_kobj; 186: /** @dcvs_kobj: Kobj for dcvs params **/ 187: struct kobject dcvs_kobj; 188: /** @sysfs_dcvs_tunables : Tuning parameters for GMU based DCVS **/ 189: struct adreno_dcvs_tunable sysfs_dcvs_tunables[GPU_TUNING_KEY_MAX]; 190: /** @default_dcvs_tunables: Default value of GMU based DCVS tunables **/ 191: u32 default_dcvs_tunables[GPU_TUNING_KEY_MAX]; 192: }; 193: 194: /* 195: * This value is based on maximum number of IBs that can fit 196: * in the ringbuffer. 197: */ 198: #define HWSCHED_MAX_IBS 2000 199: 200: enum adreno_hwsched_flags { 201: ADRENO_HWSCHED_POWER = 0, 202: ADRENO_HWSCHED_ACTIVE, 203: ADRENO_HWSCHED_CTX_BAD_LEGACY, 204: ADRENO_HWSCHED_CONTEXT_QUEUE, 205: ADRENO_HWSCHED_HW_FENCE, --- FILE: \adreno_hwsched_snapshot.c | HITS: 9 --- MATCH LINES: 241, 254, 260, 283, 296, 297, 310, 313, 315 229: 230: void adreno_hwsched_snapshot_context_queue(struct kgsl_device *device, 231: struct kgsl_snapshot *snapshot) 232: { 233: if (!adreno_hwsched_context_queue_enabled(ADRENO_DEVICE(device))) 234: return; 235: 236: read_lock(&device->context_lock); 237: idr_for_each(&device->context_idr, snapshot_context_queue, snapshot); 238: read_unlock(&device->context_lock); 239: } 240: 241: static void snapshot_preemption_record(struct kgsl_device *device, 242: struct kgsl_snapshot *snapshot, struct kgsl_memdesc *md, u64 offset, u64 size) 243: { 244: struct kgsl_snapshot_section_header *section_header = 245: (struct kgsl_snapshot_section_header *)snapshot->ptr; 246: u8 *dest = snapshot->ptr + sizeof(*section_header); 247: struct kgsl_snapshot_gpu_object_v2 *header = 248: (struct kgsl_snapshot_gpu_object_v2 *)dest; 249: u64 ctxt_record_size = min_t(u64, device->snapshot_ctxt_record_size, size); 250: size_t section_size; 251: 252: if (WARN_RATELIMIT((ctxt_record_size > md->size) || 253: (offset > (md->size - ctxt_record_size)), 254: "Invalid preemption context record size: md_size: 0x%llx, ctxt_record_size: 0x%llx\n", 255: md->size, ctxt_record_size)) 256: return; 257: 258: section_size = sizeof(*section_header) + sizeof(*header) + ctxt_record_size; 259: if (snapshot->remain < section_size) { 260: SNAPSHOT_ERR_NOMEM(device, "PREEMPTION RECORD"); 261: return; 262: } 263: 264: section_header->magic = SNAPSHOT_SECTION_MAGIC; 265: section_header->id = KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2; 266: section_header->size = section_size; 267: 268: header->size = ctxt_record_size >> 2; 269: header->gpuaddr = md->gpuaddr + offset; 270: header->ptbase = 271: kgsl_mmu_pagetable_get_ttbr0(device->mmu.defaultpagetable); 272: header->type = SNAPSHOT_GPU_OBJECT_GLOBAL; 273: 274: dest += sizeof(*header); 275: 276: memcpy(dest, md->hostptr + offset, ctxt_record_size); 277: 278: snapshot->ptr += section_header->size; 279: snapshot->remain -= section_header->size; 280: snapshot->size += section_header->size; 281: } 282: 283: void adreno_hwsched_snapshot_preemption_records(struct kgsl_device *device, 284: struct kgsl_snapshot *snapshot, struct kgsl_memdesc *md) 285: { 286: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 287: u64 offset = 0, ctxt_record_size = md->size; 288: u64 rb0_ctxt_record_size = PAGE_ALIGN(adreno_dev->total_ctxt_record_sz); 289: u64 curr_gmem_size = adreno_gmem_size(adreno_dev); 290: int i; 291: 292: if (ADRENO_FEATURE(adreno_dev, ADRENO_DEFER_GMEM_ALLOC)) { 293: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 294: 295: for (i = 0; i < KGSL_PRIORITY_MAX_RB_LEVELS; i++) 296: snapshot_preemption_record(device, snapshot, 297: hwsched->preempt_rec[i], 0, hwsched->preempt_rec[i]->size); 298: return; 299: } 300: 301: /* Check whether GMU has removed GMEM size from RB0 context record */ 302: if (md->size == (rb0_ctxt_record_size * KGSL_PRIORITY_MAX_RB_LEVELS)) { 303: do_div(ctxt_record_size, KGSL_PRIORITY_MAX_RB_LEVELS); 304: } else { 305: rb0_ctxt_record_size -= PAGE_ALIGN(curr_gmem_size); 306: ctxt_record_size -= rb0_ctxt_record_size; 307: do_div(ctxt_record_size, KGSL_PRIORITY_MAX_RB_LEVELS - 1); 308: } 309: 310: snapshot_preemption_record(device, snapshot, md, offset, rb0_ctxt_record_size); 311: offset += rb0_ctxt_record_size; 312: 313: /* All preemption records exist as a single mem alloc entry */ 314: for (i = 1; i < KGSL_PRIORITY_MAX_RB_LEVELS; i++) { 315: snapshot_preemption_record(device, snapshot, md, 316: offset, ctxt_record_size); 317: offset += ctxt_record_size; 318: } 319: } --- FILE: \adreno_hwsched_snapshot.h | HITS: 1 --- MATCH LINES: 24 12: bool adreno_hwsched_parse_payload_rb(struct adreno_device *adreno_dev, 13: struct kgsl_snapshot *snapshot); 14: 15: size_t adreno_hwsched_snapshot_rb(struct kgsl_device *device, u8 *buf, 16: size_t remain, void *priv); 17: 18: size_t adreno_hwsched_snapshot_aqe_buffer(struct kgsl_device *device, u8 *buf, 19: size_t remain, void *priv); 20: 21: void adreno_hwsched_snapshot_context_queue(struct kgsl_device *device, 22: struct kgsl_snapshot *snapshot); 23: 24: void adreno_hwsched_snapshot_preemption_records(struct kgsl_device *device, 25: struct kgsl_snapshot *snapshot, struct kgsl_memdesc *md); 26: 27: #endif --- FILE: \adreno_ioctl.c | HITS: 8 --- MATCH LINES: 149, 154, 155, 159, 165, 172 137: /* 138: * When performance counter zapping is enabled, the counters are cleared 139: * across context switches. Reading the counters when they are zapped is 140: * not permitted. 141: */ 142: if (!adreno_dev->perfcounter) 143: return -EPERM; 144: 145: return (long) adreno_perfcounter_read_group(adreno_dev, read->reads, 146: read->count); 147: } 148: 149: static long adreno_ioctl_preemption_counters_query( 150: struct kgsl_device_private *dev_priv, 151: unsigned int cmd, void *data) 152: { 153: struct adreno_device *adreno_dev = ADRENO_DEVICE(dev_priv->device); 154: struct kgsl_preemption_counters_query *read = data; 155: int size_level = A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE; 156: int levels_to_copy; 157: 158: if (!adreno_is_a5xx(adreno_dev) || 159: !adreno_is_preemption_enabled(adreno_dev)) 160: return -EOPNOTSUPP; 161: 162: if (read->size_user < size_level) 163: return -EINVAL; 164: 165: /* Calculate number of preemption counter levels to copy to userspace */ 166: levels_to_copy = (read->size_user / size_level); 167: 168: levels_to_copy = min_t(int, levels_to_copy, 169: ARRAY_SIZE(adreno_dev->ringbuffers)); 170: 171: if (copy_to_user(u64_to_user_ptr(read->counters), 172: adreno_dev->preempt.scratch->hostptr, 173: levels_to_copy * size_level)) 174: return -EFAULT; 175: 176: read->max_priority_level = levels_to_copy; 177: read->size_priority_level = size_level; 178: 179: return 0; 180: } 181: 182: static long adreno_ioctl_read_calibrated_ts(struct kgsl_device_private *dev_priv, 183: unsigned int cmd, void *data) 184: { 185: struct adreno_device *adreno_dev = ADRENO_DEVICE(dev_priv->device); 186: struct kgsl_read_calibrated_timestamps *reads = data; 187: unsigned long flags; 188: u32 *sources = NULL; 189: u64 *ts = NULL; 190: u64 start; 191: u64 samples[KGSL_CALIBRATED_TIME_DOMAIN_MAX] = {0}; 192: u32 i; 193: int ret = 0; 194: 195: /* Reading calibrated timestamps requires the CX timer be initialized */ 196: if (!test_bit(ADRENO_DEVICE_CX_TIMER_INITIALIZED, &adreno_dev->priv)) MATCH LINES: 303, 304 291: 292: if (ret == 0 && _IOC_SIZE(cmds[i].cmd)) 293: ret = kgsl_ioctl_copy_out(cmds[i].cmd, cmd, arg, data); 294: 295: return ret; 296: } 297: 298: static struct kgsl_ioctl adreno_ioctl_funcs[] = { 299: { IOCTL_KGSL_PERFCOUNTER_GET, adreno_ioctl_perfcounter_get }, 300: { IOCTL_KGSL_PERFCOUNTER_PUT, adreno_ioctl_perfcounter_put }, 301: { IOCTL_KGSL_PERFCOUNTER_QUERY, adreno_ioctl_perfcounter_query }, 302: { IOCTL_KGSL_PERFCOUNTER_READ, adreno_ioctl_perfcounter_read }, 303: { IOCTL_KGSL_PREEMPTIONCOUNTER_QUERY, 304: adreno_ioctl_preemption_counters_query }, 305: { IOCTL_KGSL_READ_CALIBRATED_TIMESTAMPS, adreno_ioctl_read_calibrated_ts }, 306: }; 307: 308: long adreno_ioctl(struct kgsl_device_private *dev_priv, 309: unsigned int cmd, unsigned long arg) 310: { 311: return adreno_ioctl_helper(dev_priv, cmd, arg, 312: adreno_ioctl_funcs, ARRAY_SIZE(adreno_ioctl_funcs)); 313: } --- FILE: \adreno_perfcounter.h | HITS: 1 --- MATCH LINES: 80 68: /* 69: * ADRENO_PERFCOUNTER_GROUP_FIXED indicates that a perfcounter group is fixed - 70: * instead of having configurable countables like the other groups, registers in 71: * fixed groups have a hardwired countable. So when the user requests a 72: * countable in one of these groups, that countable should be used as the 73: * register offset to return 74: */ 75: 76: #define ADRENO_PERFCOUNTER_GROUP_FIXED BIT(0) 77: 78: /* 79: * ADRENO_PERFCOUNTER_GROUP_RESTORE indicates CP needs to restore the select 80: * registers of this perfcounter group as part of preemption and IFPC 81: */ 82: #define ADRENO_PERFCOUNTER_GROUP_RESTORE BIT(1) 83: 84: 85: /** 86: * adreno_perfcounts: all available perfcounter groups 87: * @groups: available groups for this device 88: * @group_count: total groups for this device 89: */ 90: struct adreno_perfcounters { 91: const struct adreno_perfcount_group *groups; 92: unsigned int group_count; 93: }; 94: 95: #define ADRENO_PERFCOUNTER_GROUP_FLAGS(core, offset, name, flags, \ 96: enable, read, load) \ 97: [KGSL_PERFCOUNTER_GROUP_##offset] = { core##_perfcounters_##name, \ 98: ARRAY_SIZE(core##_perfcounters_##name), __stringify(name), flags, \ 99: enable, read, load } 100: 101: #define ADRENO_PERFCOUNTER_GROUP(core, offset, name, enable, read, load) \ 102: ADRENO_PERFCOUNTER_GROUP_FLAGS(core, offset, name, 0, enable, read, \ 103: load) 104: --- FILE: \adreno_pm4types.h | HITS: 16 --- MATCH LINES: 16, 17, 18, 19, 20, 21, 47, 51, 85, 86, 88, 89, 91, 92, 94 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: #ifndef __ADRENO_PM4TYPES_H 7: #define __ADRENO_PM4TYPES_H 8: 9: #include "adreno.h" 10: 11: #define CP_TYPE4_PKT (4 << 28) 12: #define CP_TYPE7_PKT (7 << 28) 13: 14: #define PM4_TYPE4_PKT_SIZE_MAX 128 15: 16: /* Enable preemption flag */ 17: #define CP_PREEMPT_ENABLE 0x1C 18: /* Preemption token command on which preemption occurs */ 19: #define CP_PREEMPT_TOKEN 0x1E 20: /* Bit to set in CP_PREEMPT_TOKEN ordinal for interrupt on preemption */ 21: #define CP_PREEMPT_ORDINAL_INTERRUPT 24 22: 23: /* Wait for memory writes to complete */ 24: #define CP_WAIT_MEM_WRITES 0x12 25: 26: /* initialize CP's micro-engine */ 27: #define CP_ME_INIT 0x48 28: 29: /* skip N 32-bit words to get to the next packet */ 30: #define CP_NOP 0x10 31: 32: /* indirect buffer dispatch. same as IB, but init is pipelined */ 33: #define CP_INDIRECT_BUFFER_PFD 0x37 34: 35: /* wait for the IDLE state of the engine */ 36: #define CP_WAIT_FOR_IDLE 0x26 37: 38: /* wait until a register or memory location is a specific value */ 39: #define CP_WAIT_REG_MEM 0x3c 40: 41: /* wait until a register location is equal to a specific value */ 42: #define CP_WAIT_REG_EQ 0x52 43: 44: /* switches SMMU pagetable, used on a5xx only */ 45: #define CP_SMMU_TABLE_UPDATE 0x53 46: 47: /* Designate command streams to be executed before/after CP does state restore during preemption */ 48: #define CP_SET_AMBLE 0x55 49: 50: /* Set internal CP registers, used to indicate context save data addresses */ 51: #define CP_SET_PSEUDO_REGISTER 0x56 52: 53: /* Tell CP the current operation mode, indicates save and restore procedure */ 54: #define CP_SET_MARKER 0x65 55: 56: /* register read/modify/write */ 57: #define CP_REG_RMW 0x21 58: 59: /* Set binning configuration registers */ 60: #define CP_SET_BIN_DATA 0x2f 61: 62: /* reads register in chip and writes to memory */ 63: #define CP_REG_TO_MEM 0x3e 64: 65: /* reads memory and writes to register in chip */ 66: #define CP_MEM_TO_REG 0x42 67: 68: /* write N 32-bit words to memory */ 69: #define CP_MEM_WRITE 0x3d 70: 71: /* conditional execution of a sequence of packets */ 72: #define CP_COND_EXEC 0x44 73: 74: /* conditional write to memory or register */ 75: #define CP_COND_WRITE 0x45 76: 77: /* generate an event that creates a write to memory when completed */ 78: #define CP_EVENT_WRITE 0x46 79: 80: /* A5XX Enable yield in RB only */ 81: #define CP_YIELD_ENABLE 0x1C 82: 83: #define CP_WHERE_AM_I 0x62 84: 85: /* Enable/Disable/Defer A5x global preemption model */ 86: #define CP_PREEMPT_ENABLE_GLOBAL 0x69 87: 88: /* Enable/Disable A5x local preemption model */ 89: #define CP_PREEMPT_ENABLE_LOCAL 0x6A 90: 91: /* Yeild token on a5xx similar to CP_PREEMPT on a4xx */ 92: #define CP_CONTEXT_SWITCH_YIELD 0x6B 93: 94: /* Inform CP about current render mode (needed for a5xx preemption) */ 95: #define CP_SET_RENDER_MODE 0x6C 96: 97: /* PFP waits until the FIFO between the PFP and the ME is empty */ 98: #define CP_WAIT_FOR_ME 0x13 99: 100: /* Stall the SQE until the CP processing pipeline is empty */ 101: #define CP_WAIT_FOR_CP_FLUSH 0x13 102: 103: #define CP_POWER_CONTROL 0x5b /* Control mALU power */ 104: #define CP_SET_PROTECTED_MODE 0x5f /* sets the register protection mode */ 105: 106: /* Used to switch GPU between secure and non-secure modes */ 107: #define CP_SET_SECURE_MODE 0x66 108: 109: #define CP_BOOTSTRAP_UCODE 0x6f /* bootstraps microcode */ 110: 111: #define CP_LOAD_STATE 0x30 /* load high level sequencer command */ 112: 113: /* Conditionally load a IB based on a flag */ 114: #define CP_COND_INDIRECT_BUFFER_PFE 0x3A /* prefetch enabled */ 115: #define CP_COND_INDIRECT_BUFFER_PFD 0x32 /* prefetch disabled */ 116: 117: /* Load a buffer with pre-fetch enabled */ 118: #define CP_INDIRECT_BUFFER_PFE 0x3F MATCH LINES: 155 143: #define CP_SET_THREAD_BV FIELD_PREP(GENMASK(1, 0), 2) 144: #define CP_SET_THREAD_BOTH FIELD_PREP(GENMASK(1, 0), 3) 145: #define CP_SYNC_THREADS BIT(31) 146: #define CP_CONCURRENT_BIN_DISABLE BIT(27) 147: 148: #define CP_RESET_CONTEXT_STATE 0x1F 149: 150: #define CP_RESET_GLOBAL_LOCAL_TS BIT(3) 151: #define CP_CLEAR_BV_BR_COUNTER BIT(2) 152: #define CP_CLEAR_RESOURCE_TABLE BIT(1) 153: #define CP_CLEAR_ON_CHIP_TS BIT(0) 154: 155: /* Used to define amble type in SET_AMBLE packet to execute during preemption */ 156: #define CP_KMD_AMBLE_TYPE 3 157: 158: static inline uint pm4_calc_odd_parity_bit(uint val) 159: { 160: return (0x9669 >> (0xf & ((val) ^ 161: ((val) >> 4) ^ ((val) >> 8) ^ ((val) >> 12) ^ 162: ((val) >> 16) ^ ((val) >> 20) ^ ((val) >> 24) ^ 163: ((val) >> 28)))) & 1; 164: } 165: 166: static inline uint cp_type4_packet(uint opcode, uint cnt) 167: { 168: return CP_TYPE4_PKT | ((cnt) << 0) | 169: (pm4_calc_odd_parity_bit(cnt) << 7) | 170: (((opcode) & 0x3FFFF) << 8) | 171: ((pm4_calc_odd_parity_bit(opcode) << 27)); 172: } 173: 174: static inline uint cp_type7_packet(uint opcode, uint cnt) 175: { 176: return CP_TYPE7_PKT | ((cnt) << 0) | 177: (pm4_calc_odd_parity_bit(cnt) << 15) | 178: (((opcode) & 0x7F) << 16) | 179: ((pm4_calc_odd_parity_bit(opcode) << 23)); --- FILE: \adreno_ringbuffer.c | HITS: 8 --- MATCH LINES: 151, 156, 158, 159, 160, 163, 164, 168 139: return ret; 140: 141: if (!list_empty(&rb->events.group)) 142: return 0; 143: 144: rb->id = id; 145: kgsl_add_event_group(device, &rb->events, NULL, _rb_readtimestamp, rb, 146: "rb_events-%d", id); 147: 148: rb->timestamp = 0; 149: init_waitqueue_head(&rb->ts_expire_waitq); 150: 151: spin_lock_init(&rb->preempt_lock); 152: 153: return 0; 154: } 155: 156: void adreno_preemption_timer(struct timer_list *t) 157: { 158: struct adreno_preemption *preempt = kgsl_timer_container_of(preempt, t, timer); 159: struct adreno_device *adreno_dev = container_of(preempt, 160: struct adreno_device, preempt); 161: 162: /* We should only be here from a triggered state */ 163: if (!adreno_move_preempt_state(adreno_dev, 164: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_FAULTED)) 165: return; 166: 167: /* Schedule the worker to take care of the details */ 168: queue_work(system_unbound_wq, &adreno_dev->preempt.work); 169: } 170: 171: void adreno_drawobj_set_constraint(struct kgsl_device *device, 172: struct kgsl_drawobj *drawobj) 173: { 174: struct kgsl_context *context = drawobj->context; 175: unsigned long flags = drawobj->flags; 176: 177: /* 178: * Check if the context has a constraint and constraint flags are 179: * set. 180: */ 181: if (device->host_based_dcvs && 182: context->pwr_constraint.type && 183: ((context->flags & KGSL_CONTEXT_PWR_CONSTRAINT) || 184: (drawobj->flags & KGSL_CONTEXT_PWR_CONSTRAINT))) 185: kgsl_pwrctrl_set_constraint(device, &context->pwr_constraint, 186: context->id, drawobj->timestamp); 187: 188: if (context->l3_pwr_constraint.type && 189: ((context->flags & KGSL_CONTEXT_PWR_CONSTRAINT) || 190: (flags & KGSL_CONTEXT_PWR_CONSTRAINT))) { 191: 192: if (!device->num_l3_pwrlevels) { --- FILE: \adreno_ringbuffer.h | HITS: 16 --- MATCH LINES: 58, 61, 77, 78, 79, 80, 82, 87, 90, 91, 92, 106, 107, 111, 113, 114 46: #define IS_WFI(flags) ((flags) & F_WFI) 47: #define IS_PWRON_FIXUP(flags) ((flags) & F_PWRON_FIXUP) 48: #define IS_SECURE(flags) ((flags) & F_SECURE) 49: #define IS_SKIP(flags) ((flags) & F_SKIP) 50: #define IS_USER_PROFILE(flags) ((flags) & F_USER_PROFILE) 51: #define IS_KERNEL_PROFILE(flags) ((flags) & F_KERNEL_PROFILE) 52: #define IS_PREAMBLE(flags) ((flags) & F_PREAMBLE) 53: 54: struct kgsl_device; 55: struct kgsl_device_private; 56: 57: /** 58: * This is to keep track whether the SET_PSEUDO_REGISTER packet needs to be submitted 59: * or not 60: */ 61: #define ADRENO_RB_SET_PSEUDO_DONE 0 62: 63: /** 64: * struct adreno_ringbuffer - Definition for an adreno ringbuffer object 65: * @flags: Internal control flags for the ringbuffer 66: * @buffer_desc: Pointer to the ringbuffer memory descriptor 67: * @_wptr: The next value of wptr to be written to the hardware on submit 68: * @wptr: Local copy of the wptr offset last written to hardware 69: * @last_wptr: offset of the last wptr that was written to CFF 70: * @rb_ctx: The context that represents a ringbuffer 71: * @id: Priority level of the ringbuffer, also used as an ID 72: * @fault_detect_ts: The last retired global timestamp read during fault detect 73: * @timestamp: The RB's global timestamp 74: * @events: A kgsl_event_group for this context - contains the list of GPU 75: * events 76: * @drawctxt_active: The last pagetable that this ringbuffer is set to 77: * @preemption_desc: The memory descriptor containing 78: * preemption info written/read by CP 79: * @secure_preemption_desc: The memory descriptor containing 80: * preemption info written/read by CP for secure contexts 81: * @perfcounter_save_restore_desc: Used by CP to save/restore the perfcounter 82: * values across preemption 83: * and the commands to switch pagetable on the RB 84: * @dispatch_q: The dispatcher side queue for this ringbuffer 85: * @ts_expire_waitq: Wait queue to wait for rb timestamp to expire 86: * @ts_expire_waitq: Wait q to wait for rb timestamp to expire 87: * @wptr_preempt_end: Used during preemption to check that preemption occurred 88: * at the right rptr 89: * @gpr11: The gpr11 value of this RB 90: * @preempted_midway: Indicates that the RB was preempted before rptr = wptr 91: * @preempt_lock: Lock to protect the wptr pointer while it is being updated 92: * @skip_inline_wptr: Used during preemption to make sure wptr is updated in 93: * hardware 94: */ 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: * --- FILE: \adreno_snapshot.c | HITS: 12 --- MATCH LINES: 211, 249 199: struct kgsl_process_private *process, 200: uint64_t gpuaddr, uint64_t dwords) 201: { 202: struct adreno_ib_object_list *ib_obj_list; 203: 204: /* 205: * Check the IB address - if it is either the last executed IB1 206: * then push it into the static blob otherwise put it in the dynamic 207: * list 208: */ 209: if (adreno_ib_addr_overlap(snapshot->ib1base, gpuaddr, dwords)) { 210: /* 211: * During restore after preemption, ib1base in the register 212: * can be updated by CP. In such scenarios, to dump complete 213: * IB1 in snapshot, we should consider ib1base from ringbuffer. 214: */ 215: snapshot->ib1base = gpuaddr; 216: snapshot->ib1size = dwords; 217: kgsl_snapshot_push_object(device, process, gpuaddr, dwords); 218: return; 219: } 220: 221: if (kgsl_snapshot_have_object(snapshot, process, 222: gpuaddr, dwords << 2)) 223: return; 224: 225: if (-E2BIG == adreno_ib_create_object_list(device, process, 226: gpuaddr, dwords, snapshot->ib2base, 227: &ib_obj_list)) 228: ib_max_objs = 1; 229: 230: if (ib_obj_list) 231: kgsl_snapshot_add_ib_obj_list(snapshot, ib_obj_list); 232: 233: } 234: 235: void adreno_parse_ib_lpac(struct kgsl_device *device, 236: struct kgsl_snapshot *snapshot, 237: struct kgsl_process_private *process, 238: u64 gpuaddr, u64 dwords) 239: { 240: struct adreno_ib_object_list *ib_obj_list; 241: 242: /* 243: * Check the IB address - if it is either the last executed IB1 244: * then push it into the static blob otherwise put it in the dynamic 245: * list 246: */ 247: if (adreno_ib_addr_overlap(snapshot->ib1base_lpac, gpuaddr, dwords)) { 248: /* 249: * During restore after preemption, ib1base in the register 250: * can be updated by CP. In such scenarios, to dump complete 251: * IB1 in snapshot, we should consider ib1base from ringbuffer. 252: */ 253: snapshot->ib1base_lpac = gpuaddr; 254: snapshot->ib1size_lpac = dwords; 255: kgsl_snapshot_push_object(device, process, gpuaddr, dwords); 256: return; 257: } 258: 259: if (kgsl_snapshot_have_object(snapshot, process, 260: gpuaddr, dwords << 2)) 261: return; 262: 263: if (-E2BIG == adreno_ib_create_object_list(device, process, 264: gpuaddr, dwords, snapshot->ib2base_lpac, 265: &ib_obj_list)) 266: ib_max_objs = 1; 267: 268: if (ib_obj_list) 269: kgsl_snapshot_add_ib_obj_list(snapshot, ib_obj_list); 270: 271: } 272: 273: void adreno_snapshot_dump_all_ibs(struct kgsl_device *device, MATCH LINES: 373, 387 361: 362: if (adreno_cmd_is_ib(adreno_dev, rbptr[index])) { 363: uint64_t ibaddr; 364: uint64_t ibsize; 365: 366: ibaddr = rbptr[index + 2]; 367: ibaddr = ibaddr << 32 | rbptr[index + 1]; 368: ibsize = rbptr[index + 3]; 369: 370: if (adreno_ib_addr_overlap(snapshot->ib1base, 371: ibaddr, ibsize)) { 372: /* 373: * During restore after preemption, ib1base in 374: * the register can be updated by CP. In such 375: * scenario, to dump complete IB1 in snapshot, 376: * we should consider ib1base from ringbuffer. 377: */ 378: snapshot->ib1base = ibaddr; 379: snapshot->ib1size = ibsize; 380: break; 381: } 382: } 383: } while (index != rb->wptr); 384: 385: /* 386: * If the ib1 was not found, for example, if ib1base was restored 387: * incorrectly after preemption, then simply dump the entire 388: * ringbuffer along with all the IBs in the ringbuffer. 389: */ 390: 391: if (index == rb->wptr) { 392: adreno_snapshot_dump_all_ibs(device, rb->buffer_desc->hostptr, snapshot); 393: return; 394: } 395: 396: /* 397: * index points at the last submitted IB. We can only trust that the 398: * memory between the context switch and the hanging IB is valid, so 399: * the next step is to find the context switch before the submission 400: */ 401: 402: while (index != rb->wptr) { 403: index--; 404: 405: if (index < 0) { 406: index = KGSL_RB_DWORDS - 2; 407: 408: /* 409: * Wrapped without finding the context switch. This is 410: * harmless - we should still have enough data to dump a 411: * valid state MATCH LINES: 913 901: } 902: 903: /* Snapshot IOMMU specific buffers */ 904: static void adreno_snapshot_iommu(struct kgsl_device *device, 905: struct kgsl_snapshot *snapshot) 906: { 907: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 908: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 909: 910: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 911: snapshot, adreno_snapshot_global, iommu->setstate); 912: 913: if (adreno_is_preemption_enabled(adreno_dev)) 914: kgsl_snapshot_add_section(device, 915: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 916: snapshot, adreno_snapshot_global, iommu->smmu_info); 917: } 918: 919: static void adreno_snapshot_ringbuffer(struct kgsl_device *device, 920: struct kgsl_snapshot *snapshot, struct adreno_ringbuffer *rb) 921: { 922: struct snapshot_rb_params params = { 923: .snapshot = snapshot, 924: .rb = rb, 925: }; 926: 927: if (rb == NULL) 928: return; 929: 930: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_RB_V2, snapshot, 931: snapshot_rb, ¶ms); 932: } 933: 934: static void adreno_snapshot_os(struct kgsl_device *device, 935: struct kgsl_snapshot *snapshot, struct kgsl_context *guilty, 936: struct kgsl_context *guilty_lpac) 937: { MATCH LINES: 1425, 1426, 1436, 1451, 1458, 1462, 1463 1413: mem_hdr->gmuaddr = desc->memdesc->gmuaddr; 1414: mem_hdr->gpuaddr = 0; 1415: 1416: /* The hw fence queues are mapped as iomem in the kernel */ 1417: if (desc->type == SNAPSHOT_GMU_MEM_HW_FENCE) 1418: memcpy_fromio(data, desc->memdesc->hostptr, desc->memdesc->size); 1419: else 1420: memcpy(data, desc->memdesc->hostptr, desc->memdesc->size); 1421: 1422: return desc->memdesc->size + sizeof(*mem_hdr); 1423: } 1424: 1425: /* Snapshot the preemption related buffers */ 1426: static size_t snapshot_preemption_record(struct kgsl_device *device, 1427: u8 *buf, size_t remain, void *priv) 1428: { 1429: struct kgsl_memdesc *memdesc = priv; 1430: struct kgsl_snapshot_gpu_object_v2 *header = 1431: (struct kgsl_snapshot_gpu_object_v2 *)buf; 1432: u8 *ptr = buf + sizeof(*header); 1433: u64 ctxt_record_size = min_t(u64, device->snapshot_ctxt_record_size, memdesc->size); 1434: 1435: if (remain < (ctxt_record_size + sizeof(*header))) { 1436: SNAPSHOT_ERR_NOMEM(device, "PREEMPTION RECORD"); 1437: return 0; 1438: } 1439: 1440: header->size = ctxt_record_size >> 2; 1441: header->gpuaddr = memdesc->gpuaddr; 1442: header->ptbase = 1443: kgsl_mmu_pagetable_get_ttbr0(device->mmu.defaultpagetable); 1444: header->type = SNAPSHOT_GPU_OBJECT_GLOBAL; 1445: 1446: memcpy(ptr, memdesc->hostptr, ctxt_record_size); 1447: 1448: return ctxt_record_size + sizeof(*header); 1449: } 1450: 1451: void adreno_snapshot_preemption_record(struct kgsl_device *device, 1452: struct kgsl_snapshot *snapshot) 1453: { 1454: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1455: struct adreno_ringbuffer *rb; 1456: u32 i; 1457: 1458: if (adreno_is_preemption_enabled(adreno_dev)) { 1459: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1460: kgsl_snapshot_add_section(device, 1461: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 1462: snapshot, snapshot_preemption_record, 1463: rb->preemption_desc); 1464: } 1465: } 1466: } --- FILE: \adreno_snapshot.h | HITS: 3 --- MATCH LINES: 177, 181, 183 165: * kgsl_snapshot_gmu_mem - Snapshot a GMU memory descriptor 166: * @device: Pointer to the kgsl device 167: * @buf: Destination snapshot buffer 168: * @remain: Remaining size of the snapshot buffer 169: * @priv: Opaque handle 170: * 171: * Return: Number of bytes written to snapshot buffer 172: */ 173: size_t adreno_snapshot_gmu_mem(struct kgsl_device *device, 174: u8 *buf, size_t remain, void *priv); 175: 176: /** 177: * adreno_snapshot_preemption_record - To dump preemption related buffers 178: * @device: Pointer to the kgsl device 179: * @snapshot: Pointer to the snapshot structure 180: * 181: * Snapshot the preemption related buffers . 182: */ 183: void adreno_snapshot_preemption_record(struct kgsl_device *device, 184: struct kgsl_snapshot *snapshot); 185: 186: #endif /*__ADRENO_SNAPSHOT_H */ --- FILE: \adreno_trace.h | HITS: 12 --- MATCH LINES: 798, 830, 837, 844, 851, 871, 877, 885, 905, 911, 920, 941 786: { BIT(GEN8_INT_DEBUGBUSINTERRUPT0), 787: "DEBUGBUSINTERRUPT0" }, 788: { BIT(GEN8_INT_DEBUGBUSINTERRUPT1), 789: "DEBUGBUSINTERRUPT1" }, 790: { BIT(GEN8_INT_TSBWRITEERROR), "TSBWRITEERROR" }, 791: { BIT(GEN8_INT_SWFUSEVIOLATION), "SWFUSEVIOLATION" }, 792: { BIT(GEN8_INT_ISDBCPUIRQ), "ISDBCPUIRQ" }, 793: { BIT(GEN8_INT_ISDBUNDERDEBUG), "ISDBUNDERDEBUG" }) 794: : "None" 795: ) 796: ); 797: 798: DECLARE_EVENT_CLASS(adreno_hw_preempt_template, 799: TP_PROTO(struct adreno_ringbuffer *cur_rb, 800: struct adreno_ringbuffer *new_rb, 801: unsigned int cur_rptr, unsigned int new_rptr), 802: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr), 803: TP_STRUCT__entry(__field(int, cur_level) 804: __field(int, new_level) 805: __field(unsigned int, cur_rptr) 806: __field(unsigned int, new_rptr) 807: __field(unsigned int, cur_wptr) 808: __field(unsigned int, new_wptr) 809: __field(unsigned int, cur_rbbase) 810: __field(unsigned int, new_rbbase) 811: ), 812: TP_fast_assign(__entry->cur_level = cur_rb->id; 813: __entry->new_level = new_rb->id; 814: __entry->cur_rptr = cur_rptr; 815: __entry->new_rptr = new_rptr; 816: __entry->cur_wptr = cur_rb->wptr; 817: __entry->new_wptr = new_rb->wptr; 818: __entry->cur_rbbase = cur_rb->buffer_desc->gpuaddr; 819: __entry->new_rbbase = new_rb->buffer_desc->gpuaddr; 820: ), 821: TP_printk( 822: "cur_rb_lvl=%d rptr=%x wptr=%x rbbase=%x new_rb_lvl=%d rptr=%x wptr=%x rbbase=%x", 823: __entry->cur_level, __entry->cur_rptr, 824: __entry->cur_wptr, __entry->cur_rbbase, 825: __entry->new_level, __entry->new_rptr, 826: __entry->new_wptr, __entry->new_rbbase 827: ) 828: ); 829: 830: DEFINE_EVENT(adreno_hw_preempt_template, adreno_hw_preempt_clear_to_trig, 831: TP_PROTO(struct adreno_ringbuffer *cur_rb, 832: struct adreno_ringbuffer *new_rb, 833: unsigned int cur_rptr, unsigned int new_rptr), 834: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr) 835: ); 836: 837: DEFINE_EVENT(adreno_hw_preempt_template, adreno_hw_preempt_trig_to_comp, 838: TP_PROTO(struct adreno_ringbuffer *cur_rb, 839: struct adreno_ringbuffer *new_rb, 840: unsigned int cur_rptr, unsigned int new_rptr), 841: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr) 842: ); 843: 844: DEFINE_EVENT(adreno_hw_preempt_template, adreno_hw_preempt_trig_to_comp_int, 845: TP_PROTO(struct adreno_ringbuffer *cur_rb, 846: struct adreno_ringbuffer *new_rb, 847: unsigned int cur_rptr, unsigned int new_rptr), 848: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr) 849: ); 850: 851: TRACE_EVENT(adreno_hw_preempt_comp_to_clear, 852: TP_PROTO(struct adreno_ringbuffer *cur_rb, 853: struct adreno_ringbuffer *new_rb, 854: unsigned int cur_rptr, unsigned int new_rptr), 855: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr), 856: TP_STRUCT__entry(__field(int, cur_level) 857: __field(int, new_level) 858: __field(unsigned int, cur_rptr) 859: __field(unsigned int, new_rptr) 860: __field(unsigned int, cur_wptr) 861: __field(unsigned int, new_wptr_end) 862: __field(unsigned int, new_wptr) 863: __field(unsigned int, cur_rbbase) 864: __field(unsigned int, new_rbbase) 865: ), 866: TP_fast_assign(__entry->cur_level = cur_rb->id; 867: __entry->new_level = new_rb->id; 868: __entry->cur_rptr = cur_rptr; 869: __entry->new_rptr = new_rptr; 870: __entry->cur_wptr = cur_rb->wptr; 871: __entry->new_wptr_end = new_rb->wptr_preempt_end; 872: __entry->new_wptr = new_rb->wptr; 873: __entry->cur_rbbase = cur_rb->buffer_desc->gpuaddr; 874: __entry->new_rbbase = new_rb->buffer_desc->gpuaddr; 875: ), 876: TP_printk( 877: "cur_rb_lvl=%d rptr=%x wptr=%x rbbase=%x prev_rb_lvl=%d rptr=%x wptr_preempt_end=%x wptr=%x rbbase=%x", 878: __entry->cur_level, __entry->cur_rptr, 879: __entry->cur_wptr, __entry->cur_rbbase, 880: __entry->new_level, __entry->new_rptr, 881: __entry->new_wptr_end, __entry->new_wptr, __entry->new_rbbase 882: ) 883: ); 884: 885: TRACE_EVENT(adreno_hw_preempt_token_submit, 886: TP_PROTO(struct adreno_ringbuffer *cur_rb, 887: struct adreno_ringbuffer *new_rb, 888: unsigned int cur_rptr, unsigned int new_rptr), 889: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr), 890: TP_STRUCT__entry(__field(int, cur_level) 891: __field(int, new_level) 892: __field(unsigned int, cur_rptr) 893: __field(unsigned int, new_rptr) 894: __field(unsigned int, cur_wptr) 895: __field(unsigned int, cur_wptr_end) 896: __field(unsigned int, new_wptr) 897: __field(unsigned int, cur_rbbase) 898: __field(unsigned int, new_rbbase) 899: ), 900: TP_fast_assign(__entry->cur_level = cur_rb->id; 901: __entry->new_level = new_rb->id; 902: __entry->cur_rptr = cur_rptr; 903: __entry->new_rptr = new_rptr; 904: __entry->cur_wptr = cur_rb->wptr; 905: __entry->cur_wptr_end = cur_rb->wptr_preempt_end; 906: __entry->new_wptr = new_rb->wptr; 907: __entry->cur_rbbase = cur_rb->buffer_desc->gpuaddr; 908: __entry->new_rbbase = new_rb->buffer_desc->gpuaddr; 909: ), 910: TP_printk( 911: "cur_rb_lvl=%d rptr=%x wptr_preempt_end=%x wptr=%x rbbase=%x new_rb_lvl=%d rptr=%x wptr=%x rbbase=%x", 912: __entry->cur_level, __entry->cur_rptr, 913: __entry->cur_wptr_end, __entry->cur_wptr, 914: __entry->cur_rbbase, 915: __entry->new_level, __entry->new_rptr, 916: __entry->new_wptr, __entry->new_rbbase 917: ) 918: ); 919: 920: TRACE_EVENT(adreno_preempt_trigger, 921: TP_PROTO(u32 cur_rb_id, u32 next_rb_id, 922: u32 cntl, u64 gmu_ticks), 923: TP_ARGS(cur_rb_id, next_rb_id, cntl, gmu_ticks), 924: TP_STRUCT__entry( 925: __field(u32, cur) 926: __field(u32, next) 927: __field(u32, cntl) 928: __field(u64, ticks) 929: ), 930: TP_fast_assign( 931: __entry->cur = cur_rb_id; 932: __entry->next = next_rb_id; 933: __entry->cntl = cntl; 934: __entry->ticks = gmu_ticks; 935: ), 936: TP_printk("trigger from id=%d to id=%d cntl=%x ticks=%llu", 937: __entry->cur, __entry->next, __entry->cntl, __entry->ticks 938: ) 939: ); 940: 941: TRACE_EVENT(adreno_preempt_done, 942: TP_PROTO(u32 cur_rb_id, u32 next_rb_id, 943: u32 level, u64 gmu_ticks), 944: TP_ARGS(cur_rb_id, next_rb_id, level, gmu_ticks), 945: TP_STRUCT__entry( 946: __field(u32, cur) 947: __field(u32, next) 948: __field(u32, level) 949: __field(u64, ticks) 950: ), 951: TP_fast_assign( 952: __entry->cur = cur_rb_id; 953: __entry->next = next_rb_id; 954: __entry->level = level; 955: __entry->ticks = gmu_ticks; 956: ), 957: TP_printk("done switch to id=%d from id=%d level=%x ticks=%llu", 958: __entry->next, __entry->cur, __entry->level, __entry->ticks 959: ) 960: ); 961: 962: TRACE_EVENT(adreno_ext_hw_fence_signal, 963: TP_PROTO(u64 context, u64 seq_no, u32 flags, u64 gmu_ticks), 964: TP_ARGS(context, seq_no, flags, gmu_ticks), 965: TP_STRUCT__entry( --- FILE: \gen7_reg.h | HITS: 12 --- MATCH LINES: 61, 62, 63, 64, 65, 66, 67, 68, 69, 70 49: #define GEN7_CP_INTERRUPT_STATUS 0x823 50: #define GEN7_CP_PROTECT_STATUS 0x824 51: #define GEN7_CP_STATUS_1 0x825 52: #define GEN7_CP_SQE_INSTR_BASE_LO 0x830 53: #define GEN7_CP_SQE_INSTR_BASE_HI 0x831 54: #define GEN7_CP_MISC_CNTL 0x840 55: #define GEN7_CP_CHICKEN_DBG 0x841 56: #define GEN7_CP_DBG_ECO_CNTL 0x843 57: #define GEN7_CP_APRIV_CNTL 0x844 58: #define GEN7_CP_SEMAPHORE_REG_0 0x846 59: #define GEN7_CP_PROTECT_CNTL 0x84f 60: #define GEN7_CP_PROTECT_REG 0x850 61: #define GEN7_CP_CONTEXT_SWITCH_CNTL 0x8a0 62: #define GEN7_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x8a1 63: #define GEN7_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x8a2 64: #define GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO 0x8a3 65: #define GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI 0x8a4 66: #define GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO 0x8a5 67: #define GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI 0x8a6 68: #define GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO 0x8a7 69: #define GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI 0x8a8 70: #define GEN7_CP_CONTEXT_SWITCH_LEVEL_STATUS 0x8ab 71: #define GEN7_CP_PERFCTR_CP_SEL_0 0x8d0 72: #define GEN7_CP_PERFCTR_CP_SEL_1 0x8d1 73: #define GEN7_CP_PERFCTR_CP_SEL_2 0x8d2 74: #define GEN7_CP_PERFCTR_CP_SEL_3 0x8d3 75: #define GEN7_CP_PERFCTR_CP_SEL_4 0x8d4 76: #define GEN7_CP_PERFCTR_CP_SEL_5 0x8d5 77: #define GEN7_CP_PERFCTR_CP_SEL_6 0x8d6 78: #define GEN7_CP_PERFCTR_CP_SEL_7 0x8d7 79: #define GEN7_CP_PERFCTR_CP_SEL_8 0x8d8 80: #define GEN7_CP_PERFCTR_CP_SEL_9 0x8d9 81: #define GEN7_CP_PERFCTR_CP_SEL_10 0x8da 82: #define GEN7_CP_PERFCTR_CP_SEL_11 0x8db 83: #define GEN7_CP_PERFCTR_CP_SEL_12 0x8dc 84: #define GEN7_CP_PERFCTR_CP_SEL_13 0x8dd 85: #define GEN7_CP_BV_PERFCTR_CP_SEL_0 0x8e0 86: #define GEN7_CP_BV_PERFCTR_CP_SEL_1 0x8e1 87: #define GEN7_CP_BV_PERFCTR_CP_SEL_2 0x8e2 88: #define GEN7_CP_BV_PERFCTR_CP_SEL_3 0x8e3 89: #define GEN7_CP_BV_PERFCTR_CP_SEL_4 0x8e4 90: #define GEN7_CP_BV_PERFCTR_CP_SEL_5 0x8e5 91: #define GEN7_CP_BV_PERFCTR_CP_SEL_6 0x8e6 92: #define GEN7_CP_CRASH_SCRIPT_BASE_LO 0x900 93: #define GEN7_CP_CRASH_SCRIPT_BASE_HI 0x901 94: #define GEN7_CP_CRASH_DUMP_CNTL 0x902 MATCH LINES: 819 807: #define GEN7_RB_PERFCTR_CMP_SEL_0 0x8e2c 808: #define GEN7_RB_PERFCTR_CMP_SEL_1 0x8e2d 809: #define GEN7_RB_PERFCTR_CMP_SEL_2 0x8e2e 810: #define GEN7_RB_PERFCTR_CMP_SEL_3 0x8e2f 811: #define GEN7_RB_PERFCTR_UFC_SEL_0 0x8e30 812: #define GEN7_RB_PERFCTR_UFC_SEL_1 0x8e31 813: #define GEN7_RB_PERFCTR_UFC_SEL_2 0x8e32 814: #define GEN7_RB_PERFCTR_UFC_SEL_3 0x8e33 815: #define GEN7_RB_PERFCTR_UFC_SEL_4 0x8e34 816: #define GEN7_RB_PERFCTR_UFC_SEL_5 0x8e35 817: #define GEN7_RB_SUB_BLOCK_SEL_CNTL_HOST 0x8e3b 818: #define GEN7_RB_SUB_BLOCK_SEL_CNTL_CD 0x8e3d 819: #define GEN7_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE 0x8e50 820: 821: /* PC registers */ 822: #define GEN7_PC_PERFCTR_PC_SEL_0 0x9e42 823: #define GEN7_PC_PERFCTR_PC_SEL_1 0x9e43 824: #define GEN7_PC_PERFCTR_PC_SEL_2 0x9e44 825: #define GEN7_PC_PERFCTR_PC_SEL_3 0x9e45 826: #define GEN7_PC_PERFCTR_PC_SEL_4 0x9e46 827: #define GEN7_PC_PERFCTR_PC_SEL_5 0x9e47 828: #define GEN7_PC_PERFCTR_PC_SEL_6 0x9e48 829: #define GEN7_PC_PERFCTR_PC_SEL_7 0x9e49 830: #define GEN7_PC_PERFCTR_PC_SEL_8 0x9e4a 831: #define GEN7_PC_PERFCTR_PC_SEL_9 0x9e4b 832: #define GEN7_PC_PERFCTR_PC_SEL_10 0x9e4c 833: #define GEN7_PC_PERFCTR_PC_SEL_11 0x9e4d 834: #define GEN7_PC_PERFCTR_PC_SEL_12 0x9e4e 835: #define GEN7_PC_PERFCTR_PC_SEL_13 0x9e4f 836: #define GEN7_PC_PERFCTR_PC_SEL_14 0x9e50 837: #define GEN7_PC_PERFCTR_PC_SEL_15 0x9e51 838: 839: /* VFD registers */ 840: #define GEN7_VFD_PERFCTR_VFD_SEL_0 0xa610 841: #define GEN7_VFD_PERFCTR_VFD_SEL_1 0xa611 842: #define GEN7_VFD_PERFCTR_VFD_SEL_2 0xa612 843: #define GEN7_VFD_PERFCTR_VFD_SEL_3 0xa613 MATCH LINES: 1210 1198: #define GEN7_GMU_CX_GMU_PERF_COUNTER_3_H 0x1f8ab 1199: #define GEN7_GMU_CX_GMU_PERF_COUNTER_4_L 0x1f8ac 1200: #define GEN7_GMU_CX_GMU_PERF_COUNTER_4_H 0x1f8ad 1201: #define GEN7_GMU_CX_GMU_PERF_COUNTER_5_L 0x1f8ae 1202: #define GEN7_GMU_CX_GMU_PERF_COUNTER_5_H 0x1f8af 1203: #define GEN7_GPU_GMU_CX_GMU_RPMH_POWER_STATE 0x1f8ec 1204: #define GEN7_GMU_BOOT_KMD_LM_HANDSHAKE 0x1f9f0 1205: 1206: /* HFI registers*/ 1207: #define GEN7_GMU_ALWAYS_ON_COUNTER_L 0x1f888 1208: #define GEN7_GMU_ALWAYS_ON_COUNTER_H 0x1f889 1209: #define GEN7_GMU_GMU_PWR_COL_KEEPALIVE 0x1f8c3 1210: #define GEN7_GMU_PWR_COL_PREEMPT_KEEPALIVE 0x1f8c4 1211: #define GEN7_GMU_HFI_CTRL_STATUS 0x1f980 1212: #define GEN7_GMU_HFI_QTBL_INFO 0x1f984 1213: #define GEN7_GMU_HFI_QTBL_ADDR 0x1f985 1214: #define GEN7_GMU_HFI_CTRL_INIT 0x1f986 1215: #define GEN7_GMU_GMU2HOST_INTR_SET 0x1f990 1216: #define GEN7_GMU_GMU2HOST_INTR_CLR 0x1f991 1217: #define GEN7_GMU_GMU2HOST_INTR_INFO 0x1f992 1218: #define GEN7_GMU_GMU2HOST_INTR_MASK 0x1f993 1219: #define GEN7_GMU_HOST2GMU_INTR_SET 0x1f994 1220: #define GEN7_GMU_HOST2GMU_INTR_CLR 0x1f995 1221: #define GEN7_GMU_HOST2GMU_INTR_RAW_INFO 0x1f996 1222: #define GEN7_GMU_HOST2GMU_INTR_EN_0 0x1f997 1223: #define GEN7_GMU_HOST2GMU_INTR_EN_1 0x1f998 1224: #define GEN7_GMU_HOST2GMU_INTR_EN_2 0x1f999 1225: #define GEN7_GMU_HOST2GMU_INTR_EN_3 0x1f99a 1226: #define GEN7_GMU_HOST2GMU_INTR_INFO_0 0x1f99b 1227: #define GEN7_GMU_HOST2GMU_INTR_INFO_1 0x1f99c 1228: #define GEN7_GMU_HOST2GMU_INTR_INFO_2 0x1f99d 1229: #define GEN7_GMU_HOST2GMU_INTR_INFO_3 0x1f99e 1230: #define GEN7_GMU_GENERAL_0 0x1f9c5 1231: #define GEN7_GMU_GENERAL_1 0x1f9c6 1232: #define GEN7_GMU_GENERAL_6 0x1f9cb 1233: #define GEN7_GMU_GENERAL_7 0x1f9cc 1234: #define GEN7_GMU_GENERAL_8 0x1f9cd --- FILE: \gen8_reg.h | HITS: 15 --- MATCH LINES: 820, 821, 822, 823, 824, 825, 826, 827, 828, 829 808: #define GEN8_CP_SQE_ICACHE_CNTL_PIPE 0x8b0 809: #define GEN8_CP_SQE_DCACHE_CNTL_PIPE 0x8b1 810: #define GEN8_CP_CHICKEN_DBG_PIPE 0x8b2 811: #define GEN8_CP_HW_FAULT_STATUS_PIPE 0x8b3 812: #define GEN8_CP_HW_FAULT_STATUS_MASK_PIPE 0x8b4 813: #define GEN8_CP_INTERRUPT_STATUS_GLOBAL 0x8b5 814: #define GEN8_CP_INTERRUPT_STATUS_MASK_GLOBAL 0x8b6 815: #define GEN8_CP_INTERRUPT_STATUS_PIPE 0x8b7 816: #define GEN8_CP_INTERRUPT_STATUS_MASK_PIPE 0x8b8 817: #define GEN8_CP_PIPE_STATUS_PIPE 0x8b9 818: #define GEN8_CP_GPU_BATCH_ID_PIPE 0x8ba 819: #define GEN8_CP_SQE_STATUS_PIPE 0x8bb 820: #define GEN8_CP_CONTEXT_SWITCH_CNTL 0x8c0 821: #define GEN8_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x8c1 822: #define GEN8_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x8c2 823: #define GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_LO 0x8c3 824: #define GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_HI 0x8c4 825: #define GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_LO 0x8c5 826: #define GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_HI 0x8c6 827: #define GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_LO 0x8c7 828: #define GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_HI 0x8c8 829: #define GEN8_CP_CONTEXT_SWITCH_LEVEL_STATUS 0x8cb 830: #define GEN8_CP_PERFCTR_CP_SEL_0 0x8d0 831: #define GEN8_CP_PERFCTR_CP_SEL_1 0x8d1 832: #define GEN8_CP_PERFCTR_CP_SEL_2 0x8d2 833: #define GEN8_CP_PERFCTR_CP_SEL_3 0x8d3 834: #define GEN8_CP_PERFCTR_CP_SEL_4 0x8d4 835: #define GEN8_CP_PERFCTR_CP_SEL_5 0x8d5 836: #define GEN8_CP_PERFCTR_CP_SEL_6 0x8d6 837: #define GEN8_CP_PERFCTR_CP_SEL_7 0x8d7 838: #define GEN8_CP_PERFCTR_CP_SEL_8 0x8d8 839: #define GEN8_CP_PERFCTR_CP_SEL_9 0x8d9 840: #define GEN8_CP_PERFCTR_CP_SEL_10 0x8da 841: #define GEN8_CP_PERFCTR_CP_SEL_11 0x8db 842: #define GEN8_CP_PERFCTR_CP_SEL_12 0x8dc 843: #define GEN8_CP_PERFCTR_CP_SEL_13 0x8dd 844: #define GEN8_CP_PERFCTR_CP_SEL_14 0x8de 845: #define GEN8_CP_PERFCTR_CP_SEL_15 0x8df 846: #define GEN8_CP_PERFCTR_CP_SEL_16 0x8e0 847: #define GEN8_CP_PERFCTR_CP_SEL_17 0x8e1 848: #define GEN8_CP_PERFCTR_CP_SEL_18 0x8e2 849: #define GEN8_CP_PERFCTR_CP_SEL_19 0x8e3 850: #define GEN8_CP_PERFCTR_CP_SEL_20 0x8e4 851: #define GEN8_CP_ALWAYS_ON_COUNTER_LO 0x8e7 852: #define GEN8_CP_ALWAYS_ON_COUNTER_HI 0x8e8 853: #define GEN8_CP_ALWAYS_ON_CONTEXT_LO 0x8e9 MATCH LINES: 1024 1012: #define GEN8_RB_PERFCTR_RB_SEL_3 0x8e13 1013: #define GEN8_RB_PERFCTR_RB_SEL_4 0x8e14 1014: #define GEN8_RB_PERFCTR_RB_SEL_5 0x8e15 1015: #define GEN8_RB_PERFCTR_RB_SEL_6 0x8e16 1016: #define GEN8_RB_PERFCTR_RB_SEL_7 0x8e17 1017: #define GEN8_RB_PERFCTR_CCU_SEL_0 0x8e18 1018: #define GEN8_RB_PERFCTR_CCU_SEL_1 0x8e19 1019: #define GEN8_RB_PERFCTR_CCU_SEL_2 0x8e1a 1020: #define GEN8_RB_PERFCTR_CCU_SEL_3 0x8e1b 1021: #define GEN8_RB_PERFCTR_CCU_SEL_4 0x8e1c 1022: #define GEN8_RB_SUB_BLOCK_SEL_CNTL_HOST 0x8e3b 1023: #define GEN8_RB_SUB_BLOCK_SEL_CNTL_CD 0x8e3d 1024: #define GEN8_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE 0x8e50 1025: #define GEN8_RB_SLICE_UFC_PREFETCH_CNTL 0x8e77 1026: #define GEN8_RB_SLICE_UFC_DBG_CNTL 0x8e78 1027: #define GEN8_RB_CMP_NC_MODE_CNTL 0x8f00 1028: #define GEN8_RB_RESOLVE_PREFETCH_CNTL 0x8f01 1029: #define GEN8_RB_CMP_DBG_ECO_CNTL 0x8f02 1030: #define GEN8_RB_UNSLICE_STATUS 0x8f03 1031: #define GEN8_RB_PERFCTR_CMP_SEL_0 0x8f04 1032: #define GEN8_RB_PERFCTR_CMP_SEL_1 0x8f05 1033: #define GEN8_RB_PERFCTR_CMP_SEL_2 0x8f06 1034: #define GEN8_RB_PERFCTR_CMP_SEL_3 0x8f07 1035: #define GEN8_RB_PERFCTR_UFC_SEL_0 0x8f10 1036: #define GEN8_RB_PERFCTR_UFC_SEL_1 0x8f11 1037: #define GEN8_RB_PERFCTR_UFC_SEL_2 0x8f12 1038: #define GEN8_RB_PERFCTR_UFC_SEL_3 0x8f13 1039: #define GEN8_RB_PERFCTR_UFC_SEL_4 0x8f14 1040: #define GEN8_RB_PERFCTR_UFC_SEL_5 0x8f15 1041: #define GEN8_RB_UFC_DBG_CNTL 0x8f29 1042: 1043: /* VPC registers */ 1044: #define GEN8_VPC_DBG_ECO_CNTL_2 0x9604 1045: #define GEN8_VPC_PERFCTR_VPC_SEL_2_0 0x9670 1046: #define GEN8_VPC_PERFCTR_VPC_SEL_2_1 0x9671 1047: #define GEN8_VPC_PERFCTR_VPC_SEL_2_2 0x9672 1048: #define GEN8_VPC_PERFCTR_VPC_SEL_2_3 0x9673 MATCH LINES: 1110, 1111, 1112 1098: #define GEN8_PC_PERFCTR_PC_SEL_6 0x9e36 1099: #define GEN8_PC_PERFCTR_PC_SEL_7 0x9e37 1100: #define GEN8_PC_PERFCTR_PC_SEL_8 0x9e38 1101: #define GEN8_PC_PERFCTR_PC_SEL_9 0x9e39 1102: #define GEN8_PC_PERFCTR_PC_SEL_10 0x9e3a 1103: #define GEN8_PC_PERFCTR_PC_SEL_11 0x9e3b 1104: #define GEN8_PC_PERFCTR_PC_SEL_12 0x9e3c 1105: #define GEN8_PC_PERFCTR_PC_SEL_13 0x9e3d 1106: #define GEN8_PC_PERFCTR_PC_SEL_14 0x9e3e 1107: #define GEN8_PC_PERFCTR_PC_SEL_15 0x9e3f 1108: #define GEN8_PC_CHICKEN_BITS_1 0x9e50 1109: #define GEN8_PC_DBG_ECO_CNTL 0x9e53 1110: #define GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1 0x9e64 1111: #define GEN8_PC_US_CONTEXT_SWITCH_SAVE_RESTORE_ADDR 0x9e6c 1112: #define GEN8_PC_US_CONTEXT_SWITCH_SAVE_RESTORE_DATA 0x9e6d 1113: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_0 0x9f00 1114: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_1 0x9f01 1115: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_2 0x9f02 1116: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_3 0x9f03 1117: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_4 0x9f04 1118: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_5 0x9f05 1119: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_6 0x9f06 1120: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_7 0x9f07 1121: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_8 0x9f08 1122: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_9 0x9f09 1123: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_10 0x9f0a 1124: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_11 0x9f0b 1125: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_12 0x9f0c 1126: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_13 0x9f0d 1127: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_14 0x9f0e 1128: #define GEN8_PC_SLICE_PERFCTR_PC_SEL_15 0x9f0f 1129: #define GEN8_PC_CHICKEN_BITS_2 0x9f20 1130: #define GEN8_PC_CHICKEN_BITS_5 0x9f23 1131: 1132: 1133: /* VFD registers */ 1134: #define GEN8_VFD_DBG_ECO_CNTL 0xa600 1135: #define GEN8_VFD_PERFCTR_VFD_SEL_0 0xa610 1136: #define GEN8_VFD_PERFCTR_VFD_SEL_1 0xa611 MATCH LINES: 1423 1411: 1412: #define GEN8_GPU_GX_CLKCTL_GX_MALU_GDSCR 0x1a08e 1413: #define GEN8_GPU_GX_CLKCTL_GX_MALU_CFG_GDSCR 0x1a08f 1414: 1415: /* GMU control registers */ 1416: #define GEN8_GMU_CM3_ITCM_START 0x1b400 1417: #define GEN8_GMU_CM3_DTCM_START 0x1c400 1418: #define GEN8_GMUCX_ICACHE_CONFIG 0x1f400 1419: #define GEN8_GMUCX_DCACHE_CONFIG 0x1f401 1420: #define GEN8_GMUCX_SYS_BUS_CONFIG 0x1f40f 1421: #define GEN8_GMUCX_MRC_GBIF_QOS_CTRL 0x1f50b 1422: #define GEN8_GMUCX_PWR_COL_KEEPALIVE 0x1f7e4 1423: #define GEN8_GMUCX_PWR_COL_PREEMPTION_KEEPALIVE 0x1f7e5 1424: #define GEN8_GMUCX_GFX_PWR_CLK_STATUS 0x1f7e8 1425: #define GEN8_GMUCX_RPMH_POWER_STATE 0x1f7e9 1426: /* FAL10 veto register */ 1427: #define GEN8_GMUCX_CX_FAL_INTF 0x1f7ec 1428: #define GEN8_GMUCX_CX_FALNEXT_INTF 0x1f7ed 1429: #define GEN8_GMUCX_CM3_SYSRESET 0x1f800 1430: #define GEN8_GMUCX_CM3_BOOT_CONFIG 0x1f801 1431: #define GEN8_GMUCX_WFI_CONFIG 0x1f802 1432: #define GEN8_GMUCX_WDOG_CTRL 0x1f813 1433: #define GEN8_GMUCX_CM3_FW_INIT_RESULT 0x1f81c 1434: #define GEN8_GMUCX_CM3_CFG 0x1f82d 1435: #define GEN8_GMUCX_AO_COUNTER_LO 0x1f840 1436: #define GEN8_GMUCX_AO_COUNTER_HI 0x1f841 1437: 1438: #define GEN8_GMUCX_PERF_COUNTER_ENABLE 0x1f848 1439: #define GEN8_GMUCX_PERF_COUNTER_SELECT_0 0x1f858 1440: #define GEN8_GMUCX_PERF_COUNTER_SELECT_1 0x1f859 1441: #define GEN8_GMUCX_PERF_COUNTER_SELECT_H_0 0x1f868 1442: #define GEN8_GMUCX_PERF_COUNTER_SELECT_H_1 0x1f869 1443: #define GEN8_GMUCX_PERF_COUNTER_L_0 0x1f878 1444: #define GEN8_GMUCX_PERF_COUNTER_H_0 0x1f879 1445: #define GEN8_GMUCX_PERF_COUNTER_L_1 0x1f87a 1446: #define GEN8_GMUCX_PERF_COUNTER_H_1 0x1f87b 1447: #define GEN8_GMUCX_PERF_COUNTER_L_2 0x1f87c --- FILE: \kgsl_device.h | HITS: 1 --- MATCH LINES: 502 490: * @priv: in-kernel context flags, use KGSL_CONTEXT_* values 491: * @reset_status: status indication whether a gpu reset occurred and whether 492: * this context was responsible for causing it 493: * @timeline: sync timeline used to create fences that can be signaled when a 494: * sync_pt timestamp expires 495: * @events: A kgsl_event_group for this context - contains the list of GPU 496: * events 497: * @flags: flags from userspace controlling the behavior of this context 498: * @pwr_constraint: power constraint from userspace for this context 499: * @fault_count: number of times gpu hanged in last _context_throttle_time ms 500: * @fault_time: time of the first gpu hang in last _context_throttle_time ms 501: * @user_ctxt_record: memory descriptor used by CP to save/restore VPC data 502: * across preemption 503: * @total_fault_count: number of times gpu faulted in this context 504: * @last_faulted_cmd_ts: last faulted command batch timestamp 505: * @gmu_registered: whether context is registered with gmu or not 506: */ 507: struct kgsl_context { 508: struct kref refcount; 509: uint32_t id; 510: uint32_t priority; 511: pid_t tid; 512: struct kgsl_device_private *dev_priv; 513: struct kgsl_process_private *proc_priv; 514: unsigned long priv; 515: struct kgsl_device *device; 516: unsigned int reset_status; 517: struct kgsl_sync_timeline *ktimeline; 518: struct kgsl_event_group events; 519: unsigned int flags; 520: struct kgsl_pwr_constraint pwr_constraint; 521: struct kgsl_pwr_constraint l3_pwr_constraint; 522: unsigned int fault_count; 523: ktime_t fault_time; 524: struct kgsl_mem_entry *user_ctxt_record; 525: unsigned int total_fault_count; 526: unsigned int last_faulted_cmd_ts; --- FILE: \kgsl_gmu_core.c | HITS: 8 --- MATCH LINES: 876, 877, 878, 880, 884, 885, 886, 888 864: 865: pwr->aggr_max_pwrlevel = data->aggr_max_pwrlevel; 866: 867: spin_lock(&pwr->stats_lock); 868: pwr->accum_busy_stats += data->gpu_time; 869: pwr->accum_total_time += data->total_time; 870: spin_unlock(&pwr->stats_lock); 871: } 872: 873: static void stream_trace_data(struct kgsl_device *device, struct gmu_trace_packet *pkt) 874: { 875: switch (pkt->trace_id) { 876: case GMU_TRACE_PREEMPT_TRIGGER: { 877: struct trace_preempt_trigger *data = 878: (struct trace_preempt_trigger *)pkt->payload; 879: 880: trace_adreno_preempt_trigger(data->cur_rb, data->next_rb, 881: data->ctx_switch_cntl, pkt->ticks); 882: break; 883: } 884: case GMU_TRACE_PREEMPT_DONE: { 885: struct trace_preempt_done *data = 886: (struct trace_preempt_done *)pkt->payload; 887: 888: trace_adreno_preempt_done(data->prev_rb, data->next_rb, 889: data->ctx_switch_cntl, pkt->ticks); 890: break; 891: } 892: case GMU_TRACE_EXTERNAL_HW_FENCE_SIGNAL: { 893: struct trace_ext_hw_fence_signal *data = 894: (struct trace_ext_hw_fence_signal *)pkt->payload; 895: 896: trace_adreno_ext_hw_fence_signal(data->context, data->seq_no, 897: data->flags, pkt->ticks); 898: break; 899: } 900: case GMU_TRACE_SYNCOBJ_RETIRE: { 901: struct trace_syncobj_retire *data = 902: (struct trace_syncobj_retire *)pkt->payload; 903: 904: trace_adreno_syncobj_retired(data->gmu_ctxt_id, data->timestamp, pkt->ticks); 905: break; 906: } 907: case GMU_TRACE_DCVS_PWRLVL: { 908: _gmu_trace_dcvs_pwrlevel(device, pkt); 909: break; 910: } 911: case GMU_TRACE_DCVS_BUSLVL: { 912: _gmu_trace_dcvs_buslevel(device, pkt); --- FILE: \kgsl_gmu_core.h | HITS: 13 --- MATCH LINES: 48 36: #if MAX_CNOC_LEVELS > MAX_GX_LEVELS 37: #error "CNOC levels cannot exceed GX levels" 38: #endif 39: 40: enum gmu_common_capabilities { 41: FCC_VERSION_INFO = 0, 42: }; 43: 44: enum gmu_platform_capabilities { 45: FAC_TRACE_BUFFER = 0, 46: FAC_VRB_HW_FENCE_SHADOW_NUM_ENTRIES = 1, 47: FAC_VRB_CL_NO_FT_TIMEOUT = 2, 48: FAC_VRB_PREEMPT_COUNT = 3, 49: FAC_RBBM_INTERRUPTS_HANDLE_ALL = 4, 50: FAC_FORCE_RETIRE_COMMAND = 5, 51: FAC_SOFT_RESET = 6, 52: FAC_FAST_CONTEXT_DESTROY = 7, 53: FAC_POWER_CONTROL_WA = 8, 54: }; 55: 56: /* 57: * These are the different ways the GMU can boot. GMU_WARM_BOOT is waking up 58: * from slumber. GMU_COLD_BOOT is booting for the first time. GMU_RESET 59: * is a soft reset of the GMU. 60: */ 61: enum gmu_core_boot { 62: GMU_WARM_BOOT = 0, 63: GMU_COLD_BOOT = 1, 64: GMU_RESET = 2 65: }; 66: 67: /* Bits for the flags field in the gmu structure */ 68: enum gmu_core_flags { 69: GMU_BOOT_INIT_DONE = 0, 70: GMU_HFI_ON, 71: GMU_FAULT, 72: GMU_DCVS_REPLAY, MATCH LINES: 219, 220, 221, 222, 223, 224, 225, 226 207: */ 208: enum gmu_vrb_idx { 209: /* Number of dwords supported by VRB */ 210: VRB_SIZE_IDX = 0, 211: /* Contains the address of warmboot scratch buffer */ 212: VRB_WARMBOOT_SCRATCH_IDX = 1, 213: /* Contains the address of GMU trace buffer */ 214: VRB_TRACE_BUFFER_ADDR_IDX = 2, 215: /* Contains the number of hw fence shadow table entries */ 216: VRB_HW_FENCE_SHADOW_NUM_ENTRIES = 3, 217: /* Contains OpenCL no fault tolerance timeout in ms */ 218: VRB_CL_NO_FT_TIMEOUT = 4, 219: /* Contains the total number of GPU preemptions */ 220: VRB_PREEMPT_COUNT_TOTAL = 5, 221: /* Contains the number of L0 GPU preemptions */ 222: VRB_PREEMPT_COUNT_L0 = 6, 223: /* Contains the number of L1A GPU preemptions */ 224: VRB_PREEMPT_COUNT_L1A = 7, 225: /* Contains the number of L1B GPU preemptions */ 226: VRB_PREEMPT_COUNT_L1B = 8, 227: /* Contains the GMU VA for power limits trace buffer */ 228: VRB_PWR_LIMITS_TRACE_BUF = 9, 229: /* Contains the total size of context record in KB */ 230: VRB_CTXRECORD_TOTAL_SZ = 10, 231: /* Contains the size of AQE context record in KB */ 232: VRB_CTXRECORD_AQE_SZ = 11, 233: /* Contains the size of GMEM inside context record in KB */ 234: VRB_CTXRECORD_GMEM_SZ = 12, 235: /* Contains whether to enable fault on DBGC interrupts */ 236: VRB_DBGC_FAULT_ENABLE = 17, 237: }; 238: 239: /* For GMU Trace */ 240: #define GMU_TRACE_SIZE SZ_16K 241: 242: /* Trace header defines */ 243: /* Logtype to decode the trace pkt data */ 244: #define TRACE_LOGTYPE_HWSCHED 1 245: /* Trace buffer threshold for GMU to send F2H message */ 246: #define TRACE_BUFFER_THRESHOLD 80 247: /* 248: * GMU Trace timer value to check trace packet consumption. GMU timer handler tracks the 249: * readindex, If it's not moved since last timer fired, GMU will send the f2h message to 250: * drain trace packets. GMU Trace Timer will be restarted if the readindex is moving. MATCH LINES: 326, 327, 338, 344 314: u64 cookie; 315: /** 316: * timeout: GMU Trace Timer value in msec - zero to disable trace timer else 317: * value for GMU trace timerhandler to send HFI msg. 318: */ 319: u32 timeout; 320: /** @log_type: To decode the trace buffer data */ 321: u32 log_type; 322: } __packed; 323: 324: /* Trace ID definition */ 325: enum gmu_trace_id { 326: GMU_TRACE_PREEMPT_TRIGGER = 1, 327: GMU_TRACE_PREEMPT_DONE = 2, 328: GMU_TRACE_EXTERNAL_HW_FENCE_SIGNAL = 3, 329: GMU_TRACE_SYNCOBJ_RETIRE = 4, 330: GMU_TRACE_DCVS_PWRLVL = 5, 331: GMU_TRACE_DCVS_BUSLVL = 6, 332: GMU_TRACE_DCVS_PWRSTATS = 7, 333: GMU_TRACE_PWR_CONSTRAINT = 8, 334: GMU_TRACE_DCVS_PROFILE = 9, 335: GMU_TRACE_MAX, 336: }; 337: 338: struct trace_preempt_trigger { 339: u32 cur_rb; 340: u32 next_rb; 341: u32 ctx_switch_cntl; 342: } __packed; 343: 344: struct trace_preempt_done { 345: u32 prev_rb; 346: u32 next_rb; 347: u32 ctx_switch_cntl; 348: } __packed; 349: 350: struct trace_ext_hw_fence_signal { 351: u64 context; 352: u64 seq_no; 353: u32 flags; 354: } __packed; 355: 356: struct trace_syncobj_retire { 357: u32 gmu_ctxt_id; 358: u32 timestamp; 359: } __packed; 360: 361: #define TRACE_FLAG_BIT_DCVS_VOTE 0 362: #define TRACE_FLAG_BIT_STRICT_FRAME 1 363: #define TRACE_FLAG_BIT_NON_LINEAR_UP 2 364: #define TRACE_FLAG_BIT_NON_LINEAR_DOWN 3 365: 366: struct trace_dcvs_pwrlvl { 367: u32 new_pwrlvl; 368: u32 prev_pwrlvl; --- FILE: \kgsl_iommu.h | HITS: 1 --- MATCH LINES: 174 162: }; 163: 164: #define KGSL_IOMMU_MAX_PF_PROCS 10 165: 166: /* 167: * struct kgsl_iommu - Structure holding iommu data for kgsl driver 168: * @regbase: Virtual address of the IOMMU register base 169: * @regstart: Physical address of the iommu registers 170: * @regsize: Length of the iommu register region. 171: * @setstate: Scratch GPU memory for IOMMU operations 172: * @clk_enable_count: The ref count of clock enable calls 173: * @clks: Array of pointers to IOMMU clocks 174: * @smmu_info: smmu info used in a5xx preemption 175: */ 176: struct kgsl_iommu { 177: /** @user_context: Container for the user iommu context */ 178: struct kgsl_iommu_context user_context; 179: /** @secure_context: Container for the secure iommu context */ 180: struct kgsl_iommu_context secure_context; 181: /** @lpac_context: Container for the LPAC iommu context */ 182: struct kgsl_iommu_context lpac_context; 183: void __iomem *regbase; 184: struct kgsl_memdesc *setstate; 185: atomic_t clk_enable_count; 186: struct clk_bulk_data *clks; 187: int num_clks; 188: struct kgsl_memdesc *smmu_info; 189: /** @pdev: Pointer to the platform device for the IOMMU device */ 190: struct platform_device *pdev; 191: /** 192: * @ppt_active: Set when the first per process pagetable is created. 193: * This is used to warn when global buffers are created that might not 194: * be mapped in all contexts 195: */ 196: bool ppt_active; 197: /** 198: * @smmu_aperture_set: Set once the SMMU aperture is programmed. Cleared --- FILE: \kgsl_util.h | HITS: 3 --- MATCH LINES: 79, 82, 96 67: #define GPU_TSENSE_MEASURE_DEFAULT_DISABLE BIT(4) 68: 69: struct regulator; 70: struct clk_bulk_data; 71: 72: /** 73: * struct cpu_gpu_lock - CP spinlock structure for power up list 74: * @gpu_req: flag value set by CP 75: * @cpu_req: flag value set by KMD 76: * @turn: turn variable set by both CP and KMD 77: * @list_length: this tells CP the last dword in the list: 78: * 16 + (4 * (List_Length - 1)) 79: * @list_offset: this tells CP the start of preemption only list: 80: * 16 + (4 * List_Offset) 81: * @ifpc_list_len: number of static ifpc duplets in the list 82: * @preemption_list_len: number of static preemption duplets in the list 83: * @dynamic_list_len: number of dynamically added triplets in the list 84: */ 85: struct cpu_gpu_lock { 86: u32 gpu_req; 87: u32 cpu_req; 88: u32 turn; 89: union { 90: struct { 91: u16 list_length; 92: u16 list_offset; 93: }; 94: struct { 95: u8 ifpc_list_len; 96: u8 preemption_list_len; 97: u16 dynamic_list_len; 98: }; 99: }; 100: }; 101: 102: /** 103: * kgsl_hwlock - Try to get the spinlock 104: * @lock: cpu_gpu_lock structure 105: * 106: * Spin while the GPU has the lock. 107: * 108: * Return: 0 if lock is successful, -EBUSY if timed out waiting for lock 109: */ 110: int kgsl_hwlock(struct cpu_gpu_lock *lock); 111: 112: /** 113: * kgsl_hwunlock - Release a previously grabbed lock 114: * @lock: cpu_gpu_lock structure 115: */ 116: void kgsl_hwunlock(struct cpu_gpu_lock *lock); 117: 118: /** 119: * kgsl_genpd_is_enabled - Check whether genpd is enabled or not 120: * @dev: Power domain handle --- FILE: \include\uapi\linux\msm_kgsl.h | HITS: 18 --- MATCH LINES: 61, 62, 63, 64, 65 49: /* This is a cmdbatch exclusive flag - use the CMDBATCH equivalent instead */ 50: #define KGSL_CONTEXT_SYNC 0x00000400 51: #define KGSL_CONTEXT_PWR_CONSTRAINT 0x00000800 52: #define KGSL_CONTEXT_PRIORITY_MASK 0x0000F000 53: #define KGSL_CONTEXT_PRIORITY_SHIFT 12 54: #define KGSL_CONTEXT_PRIORITY_UNDEF 0 55: 56: #define KGSL_CONTEXT_IFH_NOP 0x00010000 57: #define KGSL_CONTEXT_SECURE 0x00020000 58: #define KGSL_CONTEXT_NO_SNAPSHOT 0x00040000 59: #define KGSL_CONTEXT_SPARSE 0x00080000 60: 61: #define KGSL_CONTEXT_PREEMPT_STYLE_MASK 0x0E000000 62: #define KGSL_CONTEXT_PREEMPT_STYLE_SHIFT 25 63: #define KGSL_CONTEXT_PREEMPT_STYLE_DEFAULT 0x0 64: #define KGSL_CONTEXT_PREEMPT_STYLE_RINGBUFFER 0x1 65: #define KGSL_CONTEXT_PREEMPT_STYLE_FINEGRAIN 0x2 66: 67: #define KGSL_CONTEXT_TYPE_MASK 0x01F00000 68: #define KGSL_CONTEXT_TYPE_SHIFT 20 69: #define KGSL_CONTEXT_TYPE_ANY 0 70: #define KGSL_CONTEXT_TYPE_GL 1 71: #define KGSL_CONTEXT_TYPE_CL 2 72: #define KGSL_CONTEXT_TYPE_C2D 3 73: #define KGSL_CONTEXT_TYPE_RS 4 74: #define KGSL_CONTEXT_TYPE_VK 5 75: #define KGSL_CONTEXT_TYPE_UNKNOWN 0x1E 76: 77: #define KGSL_CONTEXT_INVALIDATE_ON_FAULT 0x10000000 78: #define KGSL_CONTEXT_LPAC 0x20000000 79: #define KGSL_CONTEXT_FAULT_INFO 0x40000000 80: 81: #define KGSL_CONTEXT_INVALID 0xffffffff 82: 83: /* 84: * --- command batch flags --- 85: * The bits that are linked to a KGSL_CONTEXT equivalent are either legacy 86: * definitions or bits that are valid for both contexts and cmdbatches. To be 87: * safe the other 8 bits that are still available in the context field should be 88: * omitted here in case we need to share - the other bits are available for 89: * cmdbatch only flags as needed MATCH LINES: 295, 307 283: }; 284: 285: /* 286: * struct kgsl_devmemstore - this structure defines the region of memory 287: * that can be mmap()ed from this driver. The timestamp fields are volatile 288: * because they are written by the GPU 289: * @soptimestamp: Start of pipeline timestamp written by GPU before the 290: * commands in concern are processed 291: * @sbz: Unused, kept for 8 byte alignment 292: * @eoptimestamp: End of pipeline timestamp written by GPU after the 293: * commands in concern are processed 294: * @sbz2: Unused, kept for 8 byte alignment 295: * @preempted: Indicates if the context was preempted 296: * @sbz3: Unused, kept for 8 byte alignment 297: * @ref_wait_ts: Timestamp on which to generate interrupt, unused now. 298: * @sbz4: Unused, kept for 8 byte alignment 299: * @current_context: The current context the GPU is working on 300: * @sbz5: Unused, kept for 8 byte alignment 301: */ 302: struct kgsl_devmemstore { 303: volatile unsigned int soptimestamp; 304: unsigned int sbz; 305: volatile unsigned int eoptimestamp; 306: unsigned int sbz2; 307: volatile unsigned int preempted; 308: unsigned int sbz3; 309: volatile unsigned int ref_wait_ts; 310: unsigned int sbz4; 311: unsigned int current_context; 312: unsigned int sbz5; 313: }; 314: 315: #define KGSL_MEMSTORE_OFFSET(ctxt_id, field) \ 316: ((ctxt_id)*sizeof(struct kgsl_devmemstore) + \ 317: offsetof(struct kgsl_devmemstore, field)) 318: 319: /* timestamp id*/ 320: enum kgsl_timestamp_type { 321: KGSL_TIMESTAMP_CONSUMED = 0x00000001, /* start-of-pipeline timestamp */ 322: KGSL_TIMESTAMP_RETIRED = 0x00000002, /* end-of-pipeline timestamp*/ 323: KGSL_TIMESTAMP_QUEUED = 0x00000003, 324: }; 325: 326: /* property types - used with kgsl_device_getproperty */ 327: #define KGSL_PROP_DEVICE_INFO 0x1 328: #define KGSL_PROP_DEVICE_SHADOW 0x2 329: #define KGSL_PROP_DEVICE_POWER 0x3 330: #define KGSL_PROP_SHMEM 0x4 331: #define KGSL_PROP_SHMEM_APERTURES 0x5 MATCH LINES: 1576, 1577, 1578, 1580, 1584, 1585, 1587, 1588, 1592, 1599, 1600 1564: unsigned int numobjs; 1565: __u64 __user synclist; 1566: unsigned int syncsize; 1567: unsigned int numsyncs; 1568: unsigned int context_id; 1569: unsigned int timestamp; 1570: }; 1571: 1572: #define IOCTL_KGSL_GPU_COMMAND \ 1573: _IOWR(KGSL_IOC_TYPE, 0x4A, struct kgsl_gpu_command) 1574: 1575: /** 1576: * struct kgsl_preemption_counters_query - argument to 1577: * IOCTL_KGSL_PREEMPTIONCOUNTER_QUERY 1578: * @counters: Return preemption counters array 1579: * @size_user: Size allocated by userspace 1580: * @size_priority_level: Size of preemption counters for each 1581: * priority level 1582: * @max_priority_level: Return max number of priority levels 1583: * 1584: * Query the available preemption counters. The array counters 1585: * is used to return preemption counters. The size of the array 1586: * is passed in so the kernel will only write at most size_user 1587: * or max available preemption counters. The total number of 1588: * preemption counters is returned in max_priority_level. If the 1589: * array or size passed in are invalid, then an error is 1590: * returned back. 1591: */ 1592: struct kgsl_preemption_counters_query { 1593: __u64 __user counters; 1594: unsigned int size_user; 1595: unsigned int size_priority_level; 1596: unsigned int max_priority_level; 1597: }; 1598: 1599: #define IOCTL_KGSL_PREEMPTIONCOUNTER_QUERY \ 1600: _IOWR(KGSL_IOC_TYPE, 0x4B, struct kgsl_preemption_counters_query) 1601: 1602: /** 1603: * struct kgsl_gpuobj_set_info - argument for IOCTL_KGSL_GPUOBJ_SET_INFO 1604: * @flags: Flags to indicate which parameters to change 1605: * @metadata: If KGSL_GPUOBJ_SET_INFO_METADATA is set, a pointer to the new 1606: * metadata 1607: * @id: GPU memory object ID to change 1608: * @metadata_len: If KGSL_GPUOBJ_SET_INFO_METADATA is set, the length of the 1609: * new metadata string 1610: * @type: If KGSL_GPUOBJ_SET_INFO_TYPE is set, the new type of the memory object 1611: */ 1612: 1613: #define KGSL_GPUOBJ_SET_INFO_METADATA (1 << 0) 1614: #define KGSL_GPUOBJ_SET_INFO_TYPE (1 << 1) 1615: 1616: struct kgsl_gpuobj_set_info { 1617: __u64 flags; 1618: __u64 metadata; 1619: unsigned int id; 1620: unsigned int metadata_len; 1621: unsigned int type; 1622: }; 1623: 1624: #define IOCTL_KGSL_GPUOBJ_SET_INFO \ TOTAL MATCHES: 1600 ========================================================================================== SUBSYSTEM: IRQ_AND_INTERRUPTS ========================================================================================== --- FILE: \a5xx_reg.h | HITS: 5 --- MATCH LINES: 10, 44 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2014-2016,2019, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #ifndef _A5XX_REG_H 8: #define _A5XX_REG_H 9: 10: /* A5XX interrupt bits */ 11: #define A5XX_INT_RBBM_GPU_IDLE 0 12: #define A5XX_INT_RBBM_AHB_ERROR 1 13: #define A5XX_INT_RBBM_TRANSFER_TIMEOUT 2 14: #define A5XX_INT_RBBM_ME_MS_TIMEOUT 3 15: #define A5XX_INT_RBBM_PFP_MS_TIMEOUT 4 16: #define A5XX_INT_RBBM_ETS_MS_TIMEOUT 5 17: #define A5XX_INT_RBBM_ATB_ASYNC_OVERFLOW 6 18: #define A5XX_INT_RBBM_GPC_ERROR 7 19: #define A5XX_INT_CP_SW 8 20: #define A5XX_INT_CP_HW_ERROR 9 21: #define A5XX_INT_CP_CCU_FLUSH_DEPTH_TS 10 22: #define A5XX_INT_CP_CCU_FLUSH_COLOR_TS 11 23: #define A5XX_INT_CP_CCU_RESOLVE_TS 12 24: #define A5XX_INT_CP_IB2 13 25: #define A5XX_INT_CP_IB1 14 26: #define A5XX_INT_CP_RB 15 27: #define A5XX_INT_CP_UNUSED_1 16 28: #define A5XX_INT_CP_RB_DONE_TS 17 29: #define A5XX_INT_CP_WT_DONE_TS 18 30: #define A5XX_INT_UNKNOWN_1 19 31: #define A5XX_INT_CP_CACHE_FLUSH_TS 20 32: #define A5XX_INT_UNUSED_2 21 33: #define A5XX_INT_RBBM_ATB_BUS_OVERFLOW 22 34: #define A5XX_INT_MISC_HANG_DETECT 23 35: #define A5XX_INT_UCHE_OOB_ACCESS 24 36: #define A5XX_INT_UCHE_TRAP_INTR 25 37: #define A5XX_INT_DEBBUS_INTR_0 26 38: #define A5XX_INT_DEBBUS_INTR_1 27 39: #define A5XX_INT_GPMU_VOLTAGE_DROOP 28 40: #define A5XX_INT_GPMU_FIRMWARE 29 41: #define A5XX_INT_ISDB_CPU_IRQ 30 42: #define A5XX_INT_ISDB_UNDER_DEBUG 31 43: 44: /* CP Interrupt bits */ 45: #define A5XX_CP_OPCODE_ERROR 0 46: #define A5XX_CP_RESERVED_BIT_ERROR 1 47: #define A5XX_CP_HW_FAULT_ERROR 2 48: #define A5XX_CP_DMA_ERROR 3 49: #define A5XX_CP_REGISTER_PROTECTION_ERROR 4 50: #define A5XX_CP_AHB_ERROR 5 51: 52: /* CP registers */ 53: #define A5XX_CP_RB_BASE 0x800 54: #define A5XX_CP_RB_BASE_HI 0x801 55: #define A5XX_CP_RB_CNTL 0x802 56: #define A5XX_CP_RB_RPTR_ADDR_LO 0x804 57: #define A5XX_CP_RB_RPTR_ADDR_HI 0x805 58: #define A5XX_CP_RB_RPTR 0x806 59: #define A5XX_CP_RB_WPTR 0x807 60: #define A5XX_CP_PFP_STAT_ADDR 0x808 61: #define A5XX_CP_PFP_STAT_DATA 0x809 62: #define A5XX_CP_DRAW_STATE_ADDR 0x80B 63: #define A5XX_CP_DRAW_STATE_DATA 0x80C 64: #define A5XX_CP_CRASH_SCRIPT_BASE_LO 0x817 65: #define A5XX_CP_CRASH_SCRIPT_BASE_HI 0x818 66: #define A5XX_CP_CRASH_DUMP_CNTL 0x819 67: #define A5XX_CP_ME_STAT_ADDR 0x81A 68: #define A5XX_CP_ROQ_THRESHOLDS_1 0x81F MATCH LINES: 100 88: #define A5XX_CP_PM4_INSTR_BASE_LO 0x838 89: #define A5XX_CP_PM4_INSTR_BASE_HI 0x839 90: #define A5XX_CP_CONTEXT_SWITCH_CNTL 0x83B 91: #define A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_LO 0x83C 92: #define A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_HI 0x83D 93: #define A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_LO 0x83E 94: #define A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_HI 0x83F 95: #define A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x840 96: #define A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x841 97: #define A5XX_CP_ADDR_MODE_CNTL 0x860 98: #define A5XX_CP_ME_STAT_DATA 0xB14 99: #define A5XX_CP_WFI_PEND_CTR 0xB15 100: #define A5XX_CP_INTERRUPT_STATUS 0xB18 101: #define A5XX_CP_HW_FAULT 0xB1A 102: #define A5XX_CP_PROTECT_STATUS 0xB1C 103: #define A5XX_CP_IB1_BASE 0xB1F 104: #define A5XX_CP_IB1_BASE_HI 0xB20 105: #define A5XX_CP_IB1_BUFSZ 0xB21 106: #define A5XX_CP_IB2_BASE 0xB22 107: #define A5XX_CP_IB2_BASE_HI 0xB23 108: #define A5XX_CP_IB2_BUFSZ 0xB24 109: #define A5XX_CP_PROTECT_REG_0 0x880 110: #define A5XX_CP_PROTECT_CNTL 0x8A0 111: #define A5XX_CP_AHB_FAULT 0xB1B 112: #define A5XX_CP_PERFCTR_CP_SEL_0 0xBB0 113: #define A5XX_CP_PERFCTR_CP_SEL_1 0xBB1 114: #define A5XX_CP_PERFCTR_CP_SEL_2 0xBB2 115: #define A5XX_CP_PERFCTR_CP_SEL_3 0xBB3 116: #define A5XX_CP_PERFCTR_CP_SEL_4 0xBB4 117: #define A5XX_CP_PERFCTR_CP_SEL_5 0xBB5 118: #define A5XX_CP_PERFCTR_CP_SEL_6 0xBB6 119: #define A5XX_CP_PERFCTR_CP_SEL_7 0xBB7 120: 121: #define A5XX_VSC_ADDR_MODE_CNTL 0xBC1 122: 123: /* CP Power Counter Registers Select */ 124: #define A5XX_CP_POWERCTR_CP_SEL_0 0xBBA MATCH LINES: 169 157: #define A5XX_RBBM_CFG_DBGBUS_MASKE_1 0x1B 158: #define A5XX_RBBM_CFG_DBGBUS_MASKE_2 0x1C 159: #define A5XX_RBBM_CFG_DBGBUS_MASKE_3 0x1D 160: #define A5XX_RBBM_CFG_DBGBUS_NIBBLEE 0x1E 161: #define A5XX_RBBM_CFG_DBGBUS_PTRC0 0x1F 162: #define A5XX_RBBM_CFG_DBGBUS_PTRC1 0x20 163: #define A5XX_RBBM_CFG_DBGBUS_LOADREG 0x21 164: #define A5XX_RBBM_CFG_DBGBUS_IDX 0x22 165: #define A5XX_RBBM_CFG_DBGBUS_CLRC 0x23 166: #define A5XX_RBBM_CFG_DBGBUS_LOADIVT 0x24 167: #define A5XX_RBBM_INTERFACE_HANG_INT_CNTL 0x2F 168: #define A5XX_RBBM_INT_CLEAR_CMD 0x37 169: #define A5XX_RBBM_INT_0_MASK 0x38 170: #define A5XX_RBBM_AHB_DBG_CNTL 0x3F 171: #define A5XX_RBBM_EXT_VBIF_DBG_CNTL 0x41 172: #define A5XX_RBBM_SW_RESET_CMD 0x43 173: #define A5XX_RBBM_BLOCK_SW_RESET_CMD 0x45 174: #define A5XX_RBBM_BLOCK_SW_RESET_CMD2 0x46 175: #define A5XX_RBBM_DBG_LO_HI_GPIO 0x48 176: #define A5XX_RBBM_EXT_TRACE_BUS_CNTL 0x49 177: #define A5XX_RBBM_CLOCK_CNTL_TP0 0x4A 178: #define A5XX_RBBM_CLOCK_CNTL_TP1 0x4B 179: #define A5XX_RBBM_CLOCK_CNTL_TP2 0x4C 180: #define A5XX_RBBM_CLOCK_CNTL_TP3 0x4D 181: #define A5XX_RBBM_CLOCK_CNTL2_TP0 0x4E 182: #define A5XX_RBBM_CLOCK_CNTL2_TP1 0x4F 183: #define A5XX_RBBM_CLOCK_CNTL2_TP2 0x50 184: #define A5XX_RBBM_CLOCK_CNTL2_TP3 0x51 185: #define A5XX_RBBM_CLOCK_CNTL3_TP0 0x52 186: #define A5XX_RBBM_CLOCK_CNTL3_TP1 0x53 187: #define A5XX_RBBM_CLOCK_CNTL3_TP2 0x54 188: #define A5XX_RBBM_CLOCK_CNTL3_TP3 0x55 189: #define A5XX_RBBM_READ_AHB_THROUGH_DBG 0x59 190: #define A5XX_RBBM_CLOCK_CNTL_UCHE 0x5A 191: #define A5XX_RBBM_CLOCK_CNTL2_UCHE 0x5B 192: #define A5XX_RBBM_CLOCK_CNTL3_UCHE 0x5C 193: #define A5XX_RBBM_CLOCK_CNTL4_UCHE 0x5D MATCH LINES: 490 478: #define A5XX_RBBM_PERFCTR_CMP_2_LO 0x460 479: #define A5XX_RBBM_PERFCTR_CMP_2_HI 0x461 480: #define A5XX_RBBM_PERFCTR_CMP_3_LO 0x462 481: #define A5XX_RBBM_PERFCTR_CMP_3_HI 0x463 482: #define A5XX_RBBM_PERFCTR_RBBM_SEL_0 0x46B 483: #define A5XX_RBBM_PERFCTR_RBBM_SEL_1 0x46C 484: #define A5XX_RBBM_PERFCTR_RBBM_SEL_2 0x46D 485: #define A5XX_RBBM_PERFCTR_RBBM_SEL_3 0x46E 486: #define A5XX_RBBM_ALWAYSON_COUNTER_LO 0x4D2 487: #define A5XX_RBBM_ALWAYSON_COUNTER_HI 0x4D3 488: #define A5XX_RBBM_STATUS 0x4F5 489: #define A5XX_RBBM_STATUS3 0x530 490: #define A5XX_RBBM_INT_0_STATUS 0x4E1 491: #define A5XX_RBBM_AHB_ME_SPLIT_STATUS 0x4F0 492: #define A5XX_RBBM_AHB_PFP_SPLIT_STATUS 0x4F1 493: #define A5XX_RBBM_AHB_ERROR_STATUS 0x4F4 494: #define A5XX_RBBM_PERFCTR_CNTL 0x464 495: #define A5XX_RBBM_PERFCTR_LOAD_CMD0 0x465 496: #define A5XX_RBBM_PERFCTR_LOAD_CMD1 0x466 497: #define A5XX_RBBM_PERFCTR_LOAD_CMD2 0x467 498: #define A5XX_RBBM_PERFCTR_LOAD_CMD3 0x468 499: #define A5XX_RBBM_PERFCTR_LOAD_VALUE_LO 0x469 500: #define A5XX_RBBM_PERFCTR_LOAD_VALUE_HI 0x46A 501: #define A5XX_RBBM_PERFCTR_RBBM_SEL_0 0x46B 502: #define A5XX_RBBM_PERFCTR_RBBM_SEL_1 0x46C 503: #define A5XX_RBBM_PERFCTR_RBBM_SEL_2 0x46D 504: #define A5XX_RBBM_PERFCTR_RBBM_SEL_3 0x46E 505: #define A5XX_RBBM_PERFCTR_GPU_BUSY_MASKED 0x46F 506: #define A5XX_RBBM_CFG_DBGBUS_EVENT_LOGIC 0x504 507: #define A5XX_RBBM_CFG_DBGBUS_OVER 0x505 508: #define A5XX_RBBM_CFG_DBGBUS_COUNT0 0x506 509: #define A5XX_RBBM_CFG_DBGBUS_COUNT1 0x507 510: #define A5XX_RBBM_CFG_DBGBUS_COUNT2 0x508 511: #define A5XX_RBBM_CFG_DBGBUS_COUNT3 0x509 512: #define A5XX_RBBM_CFG_DBGBUS_COUNT4 0x50A 513: #define A5XX_RBBM_CFG_DBGBUS_COUNT5 0x50B 514: #define A5XX_RBBM_CFG_DBGBUS_TRACE_ADDR 0x50C --- FILE: \a6xx_reg.h | HITS: 9 --- MATCH LINES: 10, 36, 56 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #ifndef _A6XX_REG_H 8: #define _A6XX_REG_H 9: 10: /* A6XX interrupt bits */ 11: #define A6XX_INT_RBBM_GPU_IDLE 0 12: #define A6XX_INT_CP_AHB_ERROR 1 13: #define A6XX_INT_ATB_ASYNCFIFO_OVERFLOW 6 14: #define A6XX_INT_RBBM_GPC_ERROR 7 15: #define A6XX_INT_CP_SW 8 16: #define A6XX_INT_CP_HW_ERROR 9 17: #define A6XX_INT_CP_CCU_FLUSH_DEPTH_TS 10 18: #define A6XX_INT_CP_CCU_FLUSH_COLOR_TS 11 19: #define A6XX_INT_CP_CCU_RESOLVE_TS 12 20: #define A6XX_INT_CP_IB2 13 21: #define A6XX_INT_CP_IB1 14 22: #define A6XX_INT_CP_RB 15 23: #define A6XX_INT_CP_RB_DONE_TS 17 24: #define A6XX_INT_CP_WT_DONE_TS 18 25: #define A6XX_INT_CP_CACHE_FLUSH_TS 20 26: #define A6XX_INT_RBBM_ATB_BUS_OVERFLOW 22 27: #define A6XX_INT_RBBM_HANG_DETECT 23 28: #define A6XX_INT_UCHE_OOB_ACCESS 24 29: #define A6XX_INT_UCHE_TRAP_INTR 25 30: #define A6XX_INT_DEBBUS_INTR_0 26 31: #define A6XX_INT_DEBBUS_INTR_1 27 32: #define A6XX_INT_TSB_WRITE_ERROR 28 33: #define A6XX_INT_ISDB_CPU_IRQ 30 34: #define A6XX_INT_ISDB_UNDER_DEBUG 31 35: 36: /* CP Interrupt bits */ 37: #define A6XX_CP_OPCODE_ERROR 0 38: #define A6XX_CP_UCODE_ERROR 1 39: #define A6XX_CP_HW_FAULT_ERROR 2 40: #define A6XX_CP_REGISTER_PROTECTION_ERROR 4 41: #define A6XX_CP_AHB_ERROR 5 42: #define A6XX_CP_VSD_PARITY_ERROR 6 43: #define A6XX_CP_ILLEGAL_INSTR_ERROR 7 44: 45: /* CP registers */ 46: #define A6XX_CP_RB_BASE 0x800 47: #define A6XX_CP_RB_BASE_HI 0x801 48: #define A6XX_CP_RB_CNTL 0x802 49: #define A6XX_CP_RB_RPTR_ADDR_LO 0x804 50: #define A6XX_CP_RB_RPTR_ADDR_HI 0x805 51: #define A6XX_CP_RB_RPTR 0x806 52: #define A6XX_CP_RB_WPTR 0x807 53: #define A6XX_CP_SQE_CNTL 0x808 54: #define A6XX_CP_CP2GMU_STATUS 0x812 55: #define A6XX_CP_HW_FAULT 0x821 56: #define A6XX_CP_INTERRUPT_STATUS 0x823 57: #define A6XX_CP_PROTECT_STATUS 0x824 58: #define A6XX_CP_STATUS_1 0x825 59: #define A6XX_CP_SQE_INSTR_BASE_LO 0x830 60: #define A6XX_CP_SQE_INSTR_BASE_HI 0x831 61: #define A6XX_CP_MISC_CNTL 0x840 62: #define A6XX_CP_APRIV_CNTL 0X844 63: #define A6XX_CP_ROQ_THRESHOLDS_1 0x8C1 64: #define A6XX_CP_ROQ_THRESHOLDS_2 0x8C2 65: #define A6XX_CP_MEM_POOL_SIZE 0x8C3 66: #define A6XX_CP_CHICKEN_DBG 0x841 67: #define A6XX_CP_ADDR_MODE_CNTL 0x842 68: #define A6XX_CP_DBG_ECO_CNTL 0x843 69: #define A6XX_CP_PROTECT_CNTL 0x84F 70: #define A6XX_CP_PROTECT_REG 0x850 71: #define A6XX_CP_CONTEXT_SWITCH_CNTL 0x8A0 72: #define A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x8A1 73: #define A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x8A2 74: #define A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO 0x8A3 75: #define A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI 0x8A4 76: #define A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO 0x8A5 77: #define A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI 0x8A6 78: #define A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO 0x8A7 79: #define A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI 0x8A8 80: #define A6XX_CP_CONTEXT_SWITCH_LEVEL_STATUS 0x8AB MATCH LINES: 140 128: #define A6XX_CP_SQE_AC_UCODE_DBG_ADDR 0xB27 129: #define A6XX_CP_SQE_AC_UCODE_DBG_DATA 0xB28 130: #define A6XX_CP_SQE_AC_STAT_ADDR 0xB29 131: #define A6XX_CP_SQE_AC_STAT_DATA 0xB2A 132: #define A6XX_CP_LPAC_ROQ_THRESHOLDS_1 0xB32 133: #define A6XX_CP_LPAC_ROQ_THRESHOLDS_2 0xB33 134: #define A6XX_CP_LPAC_PROG_FIFO_SIZE 0xB34 135: #define A6XX_CP_LPAC_ROQ_DBG_DATA 0xB35 136: #define A6XX_CP_LPAC_FIFO_DBG_DATA 0xB36 137: #define A6XX_CP_LPAC_FIFO_DBG_ADDR 0xB40 138: 139: /* RBBM registers */ 140: #define A6XX_RBBM_INT_0_STATUS 0x201 141: #define A6XX_RBBM_STATUS 0x210 142: #define A6XX_RBBM_STATUS3 0x213 143: #define A6XX_RBBM_VBIF_GX_RESET_STATUS 0x215 144: #define A6XX_RBBM_PERFCTR_CP_0_LO 0x400 145: #define A6XX_RBBM_PERFCTR_CP_0_HI 0x401 146: #define A6XX_RBBM_PERFCTR_CP_1_LO 0x402 147: #define A6XX_RBBM_PERFCTR_CP_1_HI 0x403 148: #define A6XX_RBBM_PERFCTR_CP_2_LO 0x404 149: #define A6XX_RBBM_PERFCTR_CP_2_HI 0x405 150: #define A6XX_RBBM_PERFCTR_CP_3_LO 0x406 151: #define A6XX_RBBM_PERFCTR_CP_3_HI 0x407 152: #define A6XX_RBBM_PERFCTR_CP_4_LO 0x408 153: #define A6XX_RBBM_PERFCTR_CP_4_HI 0x409 154: #define A6XX_RBBM_PERFCTR_CP_5_LO 0x40a 155: #define A6XX_RBBM_PERFCTR_CP_5_HI 0x40b 156: #define A6XX_RBBM_PERFCTR_CP_6_LO 0x40c 157: #define A6XX_RBBM_PERFCTR_CP_6_HI 0x40d 158: #define A6XX_RBBM_PERFCTR_CP_7_LO 0x40e 159: #define A6XX_RBBM_PERFCTR_CP_7_HI 0x40f 160: #define A6XX_RBBM_PERFCTR_CP_8_LO 0x410 161: #define A6XX_RBBM_PERFCTR_CP_8_HI 0x411 162: #define A6XX_RBBM_PERFCTR_CP_9_LO 0x412 163: #define A6XX_RBBM_PERFCTR_CP_9_HI 0x413 164: #define A6XX_RBBM_PERFCTR_CP_10_LO 0x414 MATCH LINES: 434 422: #define A6XX_RBBM_SECVID_TSB_TRUSTED_BASE_HI 0xF801 423: #define A6XX_RBBM_SECVID_TSB_TRUSTED_SIZE 0xF802 424: #define A6XX_RBBM_SECVID_TSB_CNTL 0xF803 425: #define A6XX_RBBM_SECVID_TSB_ADDR_MODE_CNTL 0xF810 426: 427: #define A6XX_RBBM_VBIF_CLIENT_QOS_CNTL 0x00010 428: #define A6XX_RBBM_GBIF_CLIENT_QOS_CNTL 0x00011 429: #define A6XX_RBBM_GBIF_HALT 0x00016 430: #define A6XX_RBBM_GBIF_HALT_ACK 0x00017 431: #define A6XX_RBBM_GPR0_CNTL 0x00018 432: #define A6XX_RBBM_INTERFACE_HANG_INT_CNTL 0x0001f 433: #define A6XX_RBBM_INT_CLEAR_CMD 0x00037 434: #define A6XX_RBBM_INT_0_MASK 0x00038 435: #define A6XX_RBBM_INT_2_MASK 0x0003A 436: #define A6XX_RBBM_SP_HYST_CNT 0x00042 437: #define A6XX_RBBM_SW_RESET_CMD 0x00043 438: #define A6XX_RBBM_RAC_THRESHOLD_CNT 0x00044 439: #define A6XX_RBBM_BLOCK_SW_RESET_CMD 0x00045 440: #define A6XX_RBBM_BLOCK_SW_RESET_CMD2 0x00046 441: #define A6XX_RBBM_BLOCK_GX_RETENTION_CNTL 0x00050 442: #define A6XX_RBBM_CLOCK_CNTL 0x000ae 443: #define A6XX_RBBM_CLOCK_CNTL_SP0 0x000b0 444: #define A6XX_RBBM_CLOCK_CNTL_SP1 0x000b1 445: #define A6XX_RBBM_CLOCK_CNTL_SP2 0x000b2 446: #define A6XX_RBBM_CLOCK_CNTL_SP3 0x000b3 447: #define A6XX_RBBM_CLOCK_CNTL2_SP0 0x000b4 448: #define A6XX_RBBM_CLOCK_CNTL2_SP1 0x000b5 449: #define A6XX_RBBM_CLOCK_CNTL2_SP2 0x000b6 450: #define A6XX_RBBM_CLOCK_CNTL2_SP3 0x000b7 451: #define A6XX_RBBM_CLOCK_DELAY_SP0 0x000b8 452: #define A6XX_RBBM_CLOCK_DELAY_SP1 0x000b9 453: #define A6XX_RBBM_CLOCK_DELAY_SP2 0x000ba 454: #define A6XX_RBBM_CLOCK_DELAY_SP3 0x000bb 455: #define A6XX_RBBM_CLOCK_HYST_SP0 0x000bc 456: #define A6XX_RBBM_CLOCK_HYST_SP1 0x000bd 457: #define A6XX_RBBM_CLOCK_HYST_SP2 0x000be 458: #define A6XX_RBBM_CLOCK_HYST_SP3 0x000bf MATCH LINES: 1097, 1098, 1099, 1100 1085: /* ISENSE registers */ 1086: #define A6XX_GMU_ISENSE_CTRL 0x1F95D 1087: #define A6XX_GPU_GMU_CX_GMU_ISENSE_CTRL 0x1f95d 1088: #define A6XX_GPU_CS_ENABLE_REG 0x23120 1089: 1090: /* LM registers */ 1091: #define A6XX_GPU_GMU_CX_GMU_PWR_THRESHOLD 0x1F94D 1092: 1093: /* FAL10 veto register */ 1094: #define A6XX_GPU_GMU_CX_GMU_CX_FAL_INTF 0x1F8F0 1095: #define A6XX_GPU_GMU_CX_GMU_CX_FALNEXT_INTF 0x1F8F1 1096: 1097: #define A6XX_GMU_AO_INTERRUPT_EN 0x23B03 1098: #define A6XX_GMU_AO_HOST_INTERRUPT_CLR 0x23B04 1099: #define A6XX_GMU_AO_HOST_INTERRUPT_STATUS 0x23B05 1100: #define A6XX_GMU_AO_HOST_INTERRUPT_MASK 0x23B06 1101: #define A6XX_GPU_GMU_AO_GMU_CGC_MODE_CNTL 0x23B09 1102: #define A6XX_GPU_GMU_AO_GMU_CGC_DELAY_CNTL 0x23B0A 1103: #define A6XX_GPU_GMU_AO_GMU_CGC_HYST_CNTL 0x23B0B 1104: #define A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS 0x23B0C 1105: #define A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS2 0x23B0D 1106: #define A6XX_GPU_GMU_AO_GPU_CX_BUSY_MASK 0x23B0E 1107: #define A6XX_GMU_AO_AHB_FENCE_CTRL 0x23B10 1108: #define A6XX_GMU_AHB_FENCE_STATUS 0x23B13 1109: #define A6XX_GMU_AHB_FENCE_STATUS_CLR 0x23B14 1110: #define A6XX_GMU_RBBM_INT_UNMASKED_STATUS 0x23B15 1111: #define A6XX_GMU_AO_SPARE_CNTL 0x23B16 1112: 1113: /* RGMU GLM registers */ 1114: #define A6XX_GMU_AO_RGMU_GLM_SLEEP_CTRL 0x23B80 1115: #define A6XX_GMU_AO_RGMU_GLM_SLEEP_STATUS 0x23B81 1116: #define A6XX_GMU_AO_RGMU_GLM_HW_CRC_DISABLE 0x23B82 1117: 1118: /* GMU RSC control registers */ 1119: #define A6XX_GMU_RSCC_CONTROL_REQ 0x23B07 1120: #define A6XX_GMU_RSCC_CONTROL_ACK 0x23B08 1121: 1122: /* FENCE control registers */ 1123: #define A6XX_GMU_AHB_FENCE_RANGE_0 0x23B11 1124: #define A6XX_GMU_AHB_FENCE_RANGE_1 0x23B12 --- FILE: \adreno.c | HITS: 20 --- MATCH LINES: 633, 646, 654, 656, 669, 673, 680, 685, 691, 702, 713, 717, 719, 728 621: */ 622: adreno_readreg(adreno_dev, ADRENO_REG_RBBM_SW_RESET_CMD, ®); 623: adreno_writereg(adreno_dev, ADRENO_REG_RBBM_SW_RESET_CMD, 0); 624: 625: /* The SP/TP regulator gets turned off after a soft reset */ 626: 627: clear_bit(ADRENO_DEVICE_GPU_REGULATOR_ENABLED, &adreno_dev->priv); 628: if (gpudev->regulator_enable) 629: gpudev->regulator_enable(adreno_dev); 630: } 631: 632: /** 633: * adreno_irqctrl() - Enables/disables the RBBM interrupt mask 634: * @adreno_dev: Pointer to an adreno_device 635: * @state: 1 for masked or 0 for unmasked 636: * Power: The caller of this function must make sure to use OOBs 637: * so that we know that the GPU is powered on 638: */ 639: void adreno_irqctrl(struct adreno_device *adreno_dev, int state) 640: { 641: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 642: 643: if (!adreno_dev->irq_mask) 644: return; 645: 646: adreno_writereg(adreno_dev, ADRENO_REG_RBBM_INT_0_MASK, 647: state ? adreno_dev->irq_mask : 0); 648: 649: if (gpudev->swfuse_irqctrl) 650: gpudev->swfuse_irqctrl(adreno_dev, state); 651: } 652: 653: /* 654: * adreno_hang_int_callback() - Isr for fatal interrupts that hang GPU 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: 710: return IRQ_HANDLED; 711: } 712: 713: irqreturn_t adreno_irq_callbacks(struct adreno_device *adreno_dev, 714: const struct adreno_irq_funcs *funcs, u32 status) 715: { 716: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 717: irqreturn_t ret = IRQ_NONE; 718: 719: /* Loop through all set interrupts and call respective handlers */ 720: while (status) { 721: int i = fls(status) - 1; 722: 723: if (funcs[i].func) { 724: if (adreno_dev->irq_mask & BIT(i)) 725: funcs[i].func(adreno_dev, i); 726: } else 727: dev_crit_ratelimited(device->dev, 728: "Unhandled interrupt bit %x\n", i); 729: 730: ret = IRQ_HANDLED; 731: 732: status &= ~BIT(i); 733: } 734: 735: return ret; 736: } 737: 738: static int adreno_get_chipid(struct platform_device *pdev, u32 *chipid); 739: 740: static inline bool _rev_match(unsigned int id, unsigned int entry) 741: { 742: return (entry == ANY_ID || entry == id); 743: } 744: 745: static const struct adreno_gpu_core * 746: _get_gpu_core_standard(struct platform_device *pdev, u32 *chipid) 747: { 748: const char *compat; 749: u32 core, major, minor, patchid; 750: u32 lookup_chipid = 0; 751: int i; 752: MATCH LINES: 1799 1787: return "unknown"; 1788: } 1789: 1790: static void adreno_regmap_op_preaccess(struct kgsl_regmap_region *region) 1791: { 1792: struct kgsl_device *device = region->priv; 1793: /* 1794: * kgsl panic notifier will be called in atomic context to get 1795: * GPU snapshot. Also panic handler will skip snapshot dumping 1796: * incase GPU is in SLUMBER state. So we can safely ignore the 1797: * kgsl_pre_hwaccess(). 1798: */ 1799: if (!device->snapshot_atomic && !in_interrupt()) 1800: kgsl_pre_hwaccess(device); 1801: } 1802: 1803: static const struct kgsl_regmap_ops adreno_regmap_ops = { 1804: .preaccess = adreno_regmap_op_preaccess, 1805: }; 1806: 1807: static const struct kgsl_functable adreno_functable; 1808: 1809: static void adreno_setup_device(struct adreno_device *adreno_dev) 1810: { 1811: u32 i; 1812: 1813: adreno_dev->dev.name = "kgsl-3d0"; 1814: adreno_dev->dev.ftbl = &adreno_functable; 1815: 1816: init_completion(&adreno_dev->dev.hwaccess_gate); 1817: init_completion(&adreno_dev->dev.halt_gate); 1818: init_completion(&adreno_dev->suspend_recovery_gate); 1819: complete_all(&adreno_dev->suspend_recovery_gate); 1820: 1821: idr_init(&adreno_dev->dev.context_idr); 1822: 1823: kgsl_mutex_init(&adreno_dev->dev.mutex); MATCH LINES: 1888 1876: 1877: static int adreno_irq_setup(struct platform_device *pdev, 1878: struct adreno_device *adreno_dev) 1879: { 1880: if (!adreno_dev->irq_mask) 1881: return 0; 1882: 1883: /* 1884: * Try to get the irq based on gpu irq name (i.e. "kgsl_3d0_irq") else fall back 1885: * to requesting it by index. 1886: * Note: kgsl_3d0_irq should always be the first in the gpu irq list. 1887: */ 1888: return kgsl_request_irq(pdev, "kgsl_3d0_irq", NULL, 0, adreno_irq_handler, 1889: KGSL_DEVICE(adreno_dev)); 1890: } 1891: 1892: static int adreno_pm_notifier(struct notifier_block *nb, unsigned long event, void *unused) 1893: { 1894: struct adreno_device *adreno_dev = container_of(nb, struct adreno_device, pm_nb); 1895: struct kgsl_pwrctrl *pwr = &adreno_dev->dev.pwrctrl; 1896: struct generic_pm_domain *pd = NULL; 1897: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1898: 1899: if ((event != PM_SUSPEND_PREPARE) && (event != PM_POST_SUSPEND)) 1900: return NOTIFY_DONE; 1901: 1902: if (pwr->gx_pd) { 1903: pd = container_of(pwr->gx_pd->pm_domain, struct generic_pm_domain, domain); 1904: 1905: if (pd->prepared_count) { 1906: dev_err_ratelimited(device->dev, 1907: "unexpected gx pd prepared_count:%d event:%lu\n", 1908: pd->prepared_count, event); 1909: return NOTIFY_BAD; 1910: } 1911: } 1912: MATCH LINES: 2224, 2227 2212: (adreno_is_gen7(adreno_dev) && !adreno_is_gen7_9_x(adreno_dev) && 2213: !adreno_is_gen7_14_0_family(adreno_dev))) 2214: kgsl_mmu_set_feature(device, KGSL_MMU_FORCE_LLCC_NWA); 2215: 2216: status = adreno_bind_components(dev); 2217: if (status) 2218: goto err_remove_llcc; 2219: 2220: status = adreno_irq_setup(pdev, adreno_dev); 2221: if (status < 0) 2222: goto err_unbind; 2223: 2224: device->pwrctrl.interrupt_num = status; 2225: 2226: device->freq_limiter_intr_num = kgsl_request_irq_optional(pdev, "freq_limiter_irq", 2227: adreno_freq_limiter_irq_handler, device); 2228: 2229: device->freq_limiter_irq_clear = 2230: devm_reset_control_get(&pdev->dev, "freq_limiter_irq_clear"); 2231: 2232: status = kgsl_device_platform_probe(device); 2233: if (status) 2234: goto err_unbind; 2235: 2236: adreno_fence_trace_array_init(device); 2237: 2238: /* Add CX_DBGC block to the regmap*/ 2239: kgsl_regmap_add_region(&device->regmap, pdev, "cx_dbgc", -EINVAL, NULL, NULL); 2240: 2241: res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "aperture"); 2242: if (res) { 2243: device->smmu_aperture_virt = devm_ioremap(dev, res->start, 2244: resource_size(res)); 2245: if (!device->smmu_aperture_virt) 2246: dev_warn(dev, "aperture ioremap failed\n"); 2247: } 2248: 2249: if (kgsl_regmap_add_region(&device->regmap, pdev, "isense_cntl", -EINVAL, NULL, NULL) == 0) 2250: adreno_dev->isense_reg_mapped = true; 2251: MATCH LINES: 3167 3155: } 3156: 3157: return copy_prop(param, &qtimerprop, sizeof(qtimerprop)); 3158: } 3159: 3160: static int adreno_prop_s32(struct kgsl_device *device, 3161: struct kgsl_device_getproperty *param) 3162: { 3163: int val = 0; 3164: 3165: if (param->type == KGSL_PROP_MMU_ENABLE) 3166: val = kgsl_mmu_has_feature(device, KGSL_MMU_PAGED); 3167: else if (param->type == KGSL_PROP_INTERRUPT_WAITS) 3168: val = 1; 3169: 3170: return copy_prop(param, &val, sizeof(val)); 3171: } 3172: 3173: static int adreno_prop_uche_gmem_addr(struct kgsl_device *device, 3174: struct kgsl_device_getproperty *param) 3175: { 3176: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 3177: 3178: return copy_prop(param, &adreno_dev->uche_gmem_base, 3179: sizeof(adreno_dev->uche_gmem_base)); 3180: } 3181: 3182: static int adreno_prop_ucode_version(struct kgsl_device *device, 3183: struct kgsl_device_getproperty *param) 3184: { 3185: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 3186: struct kgsl_ucode_version ucode = { 3187: .pfp = adreno_dev->fw[ADRENO_FW_PFP].version, 3188: .pm4 = adreno_dev->fw[ADRENO_FW_PM4].version, 3189: }; 3190: 3191: return copy_prop(param, &ucode, sizeof(ucode)); MATCH LINES: 3282 3270: } 3271: 3272: static const struct { 3273: int type; 3274: int (*func)(struct kgsl_device *device, 3275: struct kgsl_device_getproperty *param); 3276: } adreno_property_funcs[] = { 3277: { KGSL_PROP_DEVICE_INFO, adreno_prop_device_info }, 3278: { KGSL_PROP_DEVICE_SHADOW, adreno_prop_device_shadow }, 3279: { KGSL_PROP_DEVICE_QDSS_STM, adreno_prop_device_qdss_stm }, 3280: { KGSL_PROP_DEVICE_QTIMER, adreno_prop_device_qtimer }, 3281: { KGSL_PROP_MMU_ENABLE, adreno_prop_s32 }, 3282: { KGSL_PROP_INTERRUPT_WAITS, adreno_prop_s32 }, 3283: { KGSL_PROP_UCHE_GMEM_VADDR, adreno_prop_uche_gmem_addr }, 3284: { KGSL_PROP_UCODE_VERSION, adreno_prop_ucode_version }, 3285: { KGSL_PROP_HIGHEST_BANK_BIT, adreno_prop_u32 }, 3286: { KGSL_PROP_MIN_ACCESS_LENGTH, adreno_prop_u32 }, 3287: { KGSL_PROP_UBWC_MODE, adreno_prop_u32 }, 3288: { KGSL_PROP_DEVICE_BITNESS, adreno_prop_u32 }, 3289: { KGSL_PROP_SPEED_BIN, adreno_prop_u32 }, 3290: { KGSL_PROP_GAMING_BIN, adreno_prop_gaming_bin }, 3291: { KGSL_PROP_GPU_MODEL, adreno_prop_gpu_model}, 3292: { KGSL_PROP_VK_DEVICE_ID, adreno_prop_u32}, 3293: { KGSL_PROP_IS_LPAC_ENABLED, adreno_prop_u32 }, 3294: { KGSL_PROP_IS_RAYTRACING_ENABLED, adreno_prop_u32}, 3295: { KGSL_PROP_IS_FASTBLEND_ENABLED, adreno_prop_u32}, 3296: { KGSL_PROP_UCHE_TRAP_BASE, adreno_prop_uche_trap_base }, 3297: { KGSL_PROP_IS_AQE_ENABLED, adreno_prop_u32 }, 3298: { KGSL_PROP_MULTIDRAW_MODE, adreno_prop_u32 }, 3299: { KGSL_PROP_VIZ_FLUSH_DRAW_COUNT, adreno_prop_u32 }, 3300: { KGSL_PROP_VIZ_FLUSH_PRIM_COUNT, adreno_prop_u32 }, 3301: }; 3302: 3303: static int adreno_getproperty(struct kgsl_device *device, 3304: struct kgsl_device_getproperty *param) 3305: { 3306: int i; --- FILE: \adreno.h | HITS: 16 --- MATCH LINES: 83, 86 71: #define ADRENO_REV_MINOR(_rev) FIELD_GET(GENMASK(15, 8), _rev) 72: #define ADRENO_REV_PATCH(_rev) FIELD_GET(GENMASK(7, 0), _rev) 73: 74: #define ADRENO_GMU_REV(_rev) \ 75: (FIELD_PREP(GENMASK(31, 24), ADRENO_REV_MAJOR(_rev)) | \ 76: FIELD_PREP(GENMASK(23, 16), ADRENO_REV_MINOR(_rev)) | \ 77: FIELD_PREP(GENMASK(15, 8), ADRENO_REV_PATCH(_rev))) 78: 79: /* ADRENO_GPUREV - Return the GPU ID for the given adreno_device */ 80: #define ADRENO_GPUREV(_a) ((_a)->gpucore->gpurev) 81: 82: /* 83: * Disable local interrupts and CPU preemption to avoid interruptions 84: * while holding the CP semaphore; otherwise, it could stall the CP. 85: * Make sure to call ADRENO_RELEASE_CP_SEMAPHORE after calling the 86: * below macro to reenable CPU interrupts. 87: */ 88: #define ADRENO_ACQUIRE_CP_SEMAPHORE(_adreno_dev, _flags) \ 89: ({ \ 90: bool ret = true; \ 91: if ((_adreno_dev)->gpucore->gpudev->acquire_cp_semaphore) { \ 92: local_irq_save(_flags); \ 93: preempt_disable(); \ 94: ret = (_adreno_dev)->gpucore->gpudev->acquire_cp_semaphore(_adreno_dev); \ 95: if (!ret) { \ 96: preempt_enable(); \ 97: local_irq_restore(_flags); \ 98: dev_err_ratelimited(KGSL_DEVICE(_adreno_dev)->dev, \ 99: "Timed out waiting to acquire CP semaphore: status=0x%08x\n", \ 100: ret); \ 101: } \ 102: } \ 103: ret; \ 104: }) 105: 106: #define ADRENO_RELEASE_CP_SEMAPHORE(_adreno_dev, _flags) \ 107: ({ \ 108: do { \ 109: if ((_adreno_dev)->gpucore->gpudev->release_cp_semaphore) { \ 110: (_adreno_dev)->gpucore->gpudev->release_cp_semaphore(_adreno_dev); \ MATCH LINES: 709 697: * @profile_index: Index to store the start/stop ticks in the profiling 698: * buffer 699: * @pwrup_reglist: Memdesc holding the power up register list 700: * which is used by CP during preemption and IFPC 701: * @lm_sequence: Pointer to the start of the register write sequence for LM 702: * @lm_size: The dword size of the LM sequence 703: * @lm_limit: limiting value for LM 704: * @lm_threshold_count: register value for counter for lm threshold breakin 705: * @lm_threshold_cross: number of current peaks exceeding threshold 706: * @ifpc_count: Number of times the GPU went into IFPC 707: * @highest_bank_bit: Value of the highest bank bit 708: * @gpmu_throttle_counters - counters for number of throttled clocks 709: * @irq_storm_work: Worker to handle possible interrupt storms 710: * @active_list: List to track active contexts 711: * @active_list_lock: Lock to protect active_list 712: * @gpu_llc_slice: GPU system cache slice descriptor 713: * @gpu_llc_slice_enable: To enable the GPU system cache slice or not 714: * @gpuhtw_llc_slice: GPU pagetables system cache slice descriptor 715: * @gpuhtw_llc_slice_enable: To enable the GPUHTW system cache slice or not 716: * @gpumv_llc_slice: GPU MV buffer system cache slice descriptor 717: * @gpumv_llc_slice_enable: To enable GPUMV buffer system cache slice or not 718: * @zap_loaded: Used to track if zap was successfully loaded or not 719: */ 720: struct adreno_device { 721: struct kgsl_device dev; /* Must be first field in this struct */ 722: unsigned long priv; 723: unsigned int chipid; 724: /** @uche_gmem_base: Base address of GMEM for UCHE access */ 725: u64 uche_gmem_base; 726: const struct adreno_gpu_core *gpucore; 727: struct adreno_firmware fw[2]; 728: size_t gpmu_cmds_size; 729: unsigned int *gpmu_cmds; 730: struct adreno_ringbuffer ringbuffers[KGSL_PRIORITY_MAX_RB_LEVELS]; 731: int num_ringbuffers; 732: struct adreno_ringbuffer *cur_rb; 733: struct adreno_ringbuffer *next_rb; MATCH LINES: 837 825: bool gpumv_llc_slice_enable; 826: unsigned int zap_loaded; 827: /** @zap_enabled: True when zap-shader is present */ 828: bool zap_enabled; 829: /** 830: * @critpkts: Memory descriptor for 5xx critical packets if applicable 831: */ 832: struct kgsl_memdesc *critpkts; 833: /** 834: * @critpkts: Memory descriptor for 5xx secure critical packets 835: */ 836: struct kgsl_memdesc *critpkts_secure; 837: /** @irq_mask: The current interrupt mask for the GPU device */ 838: u32 irq_mask; 839: /* @dispatch_ops: A pointer to a set of adreno dispatch ops */ 840: const struct adreno_dispatch_ops *dispatch_ops; 841: /** @hwsched: Container for the hardware dispatcher */ 842: struct adreno_hwsched hwsched; 843: /* 844: * @perfcounter: Flag to clear perfcounters across contexts and 845: * controls perfcounter ioctl read 846: */ 847: bool perfcounter; 848: /** @gmu_hub_clk_freq: Gmu hub interface clock frequency */ 849: u64 gmu_hub_clk_freq; 850: /* @patch_reglist: If false power up register list needs to be patched */ 851: bool patch_reglist; 852: /* 853: * @uche_client_pf: uche_client_pf client register configuration 854: * for pf debugging 855: */ 856: u32 uche_client_pf; 857: /** 858: * @bcl_data: bit 0 contains response type for bcl alarms and bits 1:24 controls 859: * throttle level for bcl alarm levels 0-2. If not set, gmu fw sets default throttle levels. 860: */ 861: u32 bcl_data; MATCH LINES: 1054, 1056, 1092 1042: ADRENO_REG_CP_RB_RPTR, 1043: ADRENO_REG_CP_RB_WPTR, 1044: ADRENO_REG_CP_ME_CNTL, 1045: ADRENO_REG_CP_RB_CNTL, 1046: ADRENO_REG_CP_IB1_BASE, 1047: ADRENO_REG_CP_IB1_BASE_HI, 1048: ADRENO_REG_CP_IB1_BUFSZ, 1049: ADRENO_REG_CP_IB2_BASE, 1050: ADRENO_REG_CP_IB2_BASE_HI, 1051: ADRENO_REG_CP_IB2_BUFSZ, 1052: ADRENO_REG_RBBM_STATUS, 1053: ADRENO_REG_RBBM_STATUS3, 1054: ADRENO_REG_RBBM_INT_0_MASK, 1055: ADRENO_REG_RBBM_SW_RESET_CMD, 1056: ADRENO_REG_GMU_AO_HOST_INTERRUPT_MASK, 1057: ADRENO_REG_GMU_GMU2HOST_INTR_MASK, 1058: ADRENO_REG_REGISTER_MAX, 1059: }; 1060: 1061: #define ADRENO_REG_UNUSED 0xFFFFFFFF 1062: #define ADRENO_REG_SKIP 0xFFFFFFFE 1063: #define ADRENO_REG_DEFINE(_offset, _reg)[_offset] = _reg 1064: 1065: struct adreno_irq_funcs { 1066: void (*func)(struct adreno_device *adreno_dev, int mask); 1067: }; 1068: #define ADRENO_IRQ_CALLBACK(_c) { .func = _c } 1069: 1070: /* 1071: * struct adreno_debugbus_block - Holds info about debug buses of a chip 1072: * @block_id: Bus identifier 1073: * @dwords: Number of dwords of data that this block holds 1074: */ 1075: struct adreno_debugbus_block { 1076: unsigned int block_id; 1077: unsigned int dwords; 1078: }; 1079: 1080: struct adreno_gpudev { 1081: /* 1082: * These registers are in a different location on different devices, 1083: * so define them in the structure and use them as variables. 1084: */ 1085: unsigned int *const reg_offsets; 1086: 1087: /* GPU specific function hooks */ 1088: int (*probe)(struct platform_device *pdev, u32 chipid, 1089: const struct adreno_gpu_core *gpucore); 1090: void (*snapshot)(struct adreno_device *adreno_dev, 1091: struct kgsl_snapshot *snapshot); 1092: irqreturn_t (*irq_handler)(struct adreno_device *adreno_dev); 1093: int (*init)(struct adreno_device *adreno_dev); 1094: void (*remove)(struct adreno_device *adreno_dev); 1095: int (*rb_start)(struct adreno_device *adreno_dev); 1096: int (*start)(struct adreno_device *adreno_dev); 1097: int (*regulator_enable)(struct adreno_device *adreno_dev); 1098: void (*regulator_disable)(struct adreno_device *adreno_dev); 1099: void (*pwrlevel_change_settings)(struct adreno_device *adreno_dev, 1100: unsigned int prelevel, unsigned int postlevel, 1101: bool post); 1102: void (*preemption_schedule)(struct adreno_device *adreno_dev); 1103: void (*context_detach)(struct adreno_context *drawctxt); 1104: void (*pre_reset)(struct adreno_device *adreno_dev); 1105: void (*gpu_keepalive)(struct adreno_device *adreno_dev, 1106: bool state); 1107: bool (*hw_isidle)(struct adreno_device *adreno_dev); 1108: const char *(*iommu_fault_block)(struct kgsl_device *device, 1109: unsigned int fsynr1); 1110: int (*reset)(struct adreno_device *adreno_dev); 1111: /** @soft_reset: Soft reset GPU on fault recovery */ 1112: int (*soft_reset)(struct adreno_device *adreno_dev, 1113: struct kgsl_context *context, bool ctx_guilty); 1114: /** @read_alwayson: Return the current value of the alwayson counter */ 1115: u64 (*read_alwayson)(struct adreno_device *adreno_dev); 1116: /** MATCH LINES: 1160 1148: */ 1149: int (*perfcounter_remove)(struct adreno_device *adreno_dev, 1150: struct adreno_perfcount_register *reg, u32 groupid); 1151: /** 1152: * @set_isdb_breakpoint_registers - Program isdb registers to issue break command 1153: */ 1154: void (*set_isdb_breakpoint_registers)(struct adreno_device *adreno_dev); 1155: /** 1156: * @context_destroy: Target specific function called during context destruction 1157: */ 1158: void (*context_destroy)(struct adreno_device *adreno_dev, struct adreno_context *drawctxt); 1159: /** 1160: * @swfuse_irqctrl: To enable/disable sw fuse violation interrupt 1161: */ 1162: void (*swfuse_irqctrl)(struct adreno_device *adreno_dev, bool state); 1163: /** 1164: * @lpac_store: To enable/disable lpac at runtime 1165: */ 1166: int (*lpac_store)(struct adreno_device *adreno_dev, bool enable); 1167: /* 1168: * @get_uche_trap_base: Return the UCHE_TRAP_BASE value 1169: */ 1170: u64 (*get_uche_trap_base)(void); 1171: /** 1172: * @fault_header: Print fault header 1173: */ 1174: void (*fault_header)(struct adreno_device *adreno_dev, struct kgsl_drawobj *drawobj); 1175: /** 1176: * @lpac_fault_header: Print LPAC fault header 1177: */ 1178: void (*lpac_fault_header)(struct adreno_device *adreno_dev, struct kgsl_drawobj *drawobj); 1179: /** 1180: * @power_feature_stats: Sample feature related perfcounter stats 1181: */ 1182: void (*power_feature_stats)(struct adreno_device *adreno_dev); 1183: /** 1184: * @acquire_cp_semaphore: Return true if CP semaphore is acquired, otherwise false MATCH LINES: 2129, 2131, 2132, 2134 2117: * 2118: * A target indepedent helper function for loading the zap shader. 2119: * 2120: * Return: 0 on success or negative on failure. 2121: */ 2122: int adreno_zap_shader_load(struct adreno_device *adreno_dev, 2123: const char *name); 2124: 2125: /** 2126: * adreno_irq_callbacks - Helper function to handle IRQ callbacks 2127: * @adreno_dev: Adreno GPU device handle 2128: * @funcs: List of callback functions 2129: * @status: Interrupt status 2130: * 2131: * Walk the bits in the interrupt status and call any applicable callbacks. 2132: * Return: IRQ_HANDLED if one or more interrupt callbacks were called. 2133: */ 2134: irqreturn_t adreno_irq_callbacks(struct adreno_device *adreno_dev, 2135: const struct adreno_irq_funcs *funcs, u32 status); 2136: 2137: 2138: /** 2139: * adreno_device_probe - Generic adreno device probe function 2140: * @pdev: Pointer to the platform device 2141: * @adreno_dev: Adreno GPU device handle 2142: * 2143: * Do the generic setup for the Adreno device. Called from the target specific 2144: * probe functions. 2145: * 2146: * Return: 0 on success or negative on failure 2147: */ 2148: int adreno_device_probe(struct platform_device *pdev, 2149: struct adreno_device *adreno_dev); 2150: 2151: /** 2152: * adreno_power_cycle - Suspend and resume the device 2153: * @adreno_dev: Pointer to the adreno device 2154: * @callback: Function that needs to be executed 2155: * @priv: Argument to be passed to the callback 2156: * 2157: * Certain properties that can be set via sysfs need to power 2158: * cycle the device to take effect. This function suspends MATCH LINES: 2381, 2388, 2391, 2393 2369: 2370: /** 2371: * adreno_drain - Halt new submissions and drain pending work by waiting for active count to become 2372: * zero 2373: * @device: A handle to kgsl device 2374: * @wait_jiffies: jiffies to wait for active count to become zero 2375: * 2376: * Return: 0 on success or negative error on failure 2377: */ 2378: int adreno_drain(struct kgsl_device *device, unsigned long wait_jiffies); 2379: 2380: /** 2381: * adreno_irq_free - Free an interrupt allocated for GPU 2382: * @adreno_dev: Adreno device handle 2383: */ 2384: static inline void adreno_irq_free(struct adreno_device *adreno_dev) 2385: { 2386: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2387: 2388: if (!(adreno_dev->irq_mask || device->pwrctrl.interrupt_num)) 2389: return; 2390: 2391: devm_free_irq(&device->pdev->dev, device->pwrctrl.interrupt_num, device); 2392: adreno_dev->irq_mask = 0; 2393: device->pwrctrl.interrupt_num = 0; 2394: } 2395: 2396: /** 2397: * adreno_gpudev_reset - Adreno gpu device reset 2398: * @adreno_dev: Adreno device handle 2399: */ 2400: static inline int adreno_gpudev_reset(struct adreno_device *adreno_dev) 2401: { 2402: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 2403: int ret = -ENODEV; 2404: 2405: if (gpudev->reset) { 2406: set_bit(ADRENO_DEVICE_RESET_RECOVERY, &adreno_dev->priv); 2407: ret = gpudev->reset(adreno_dev); 2408: clear_bit(ADRENO_DEVICE_RESET_RECOVERY, &adreno_dev->priv); 2409: } 2410: 2411: return ret; 2412: } 2413: 2414: /** 2415: * adreno_gmem_size - Returns the GMEM size 2416: * @adreno_dev Adreno device handle 2417: * --- FILE: \adreno_a5xx.c | HITS: 30 --- MATCH LINES: 628, 633 616: struct kgsl_device *device = &adreno_dev->dev; 617: unsigned int rptr, wptr; 618: unsigned int status, status3, intstatus; 619: unsigned int hwfault; 620: 621: dev_err(device->dev, str); 622: 623: kgsl_regread(device, A5XX_CP_RB_RPTR, &rptr); 624: kgsl_regread(device, A5XX_CP_RB_WPTR, &wptr); 625: 626: kgsl_regread(device, A5XX_RBBM_STATUS, &status); 627: kgsl_regread(device, A5XX_RBBM_STATUS3, &status3); 628: kgsl_regread(device, A5XX_RBBM_INT_0_STATUS, &intstatus); 629: kgsl_regread(device, A5XX_CP_HW_FAULT, &hwfault); 630: 631: 632: dev_err(device->dev, 633: "rb=%d pos=%X/%X rbbm_status=%8.8X/%8.8X int_0_status=%8.8X\n", 634: adreno_dev->cur_rb->id, rptr, wptr, status, status3, intstatus); 635: 636: dev_err(device->dev, " hwfault=%8.8X\n", hwfault); 637: 638: kgsl_device_snapshot(device, NULL, NULL, false); 639: } 640: 641: static int _gpmu_send_init_cmds(struct adreno_device *adreno_dev) 642: { 643: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 644: uint32_t *cmds; 645: uint32_t size = adreno_dev->gpmu_cmds_size; 646: int ret; 647: 648: if (size == 0 || adreno_dev->gpmu_cmds == NULL) 649: return -EINVAL; 650: 651: cmds = adreno_ringbuffer_allocspace(rb, size); 652: if (IS_ERR(cmds)) 653: return PTR_ERR(cmds); 654: if (cmds == NULL) 655: return -ENOSPC; 656: 657: /* Copy to the RB the predefined fw sequence cmds */ MATCH LINES: 725, 729 713: 714: if (reg) { 715: dev_err(device->dev, 716: "GPMU firmware initialization failed: %d\n", 717: reg); 718: return -EIO; 719: } 720: } 721: set_bit(ADRENO_DEVICE_GPMU_INITIALIZED, &adreno_dev->priv); 722: /* 723: * We are in AWARE state and IRQ line from GPU to host is 724: * disabled. 725: * Read pending GPMU interrupts and clear GPMU_RBBM_INTR_INFO. 726: */ 727: kgsl_regread(device, A5XX_GPMU_RBBM_INTR_INFO, ®); 728: /* 729: * Clear RBBM interrupt mask if any of GPMU interrupts 730: * are pending. 731: */ 732: if (reg) 733: kgsl_regwrite(device, 734: A5XX_RBBM_INT_CLEAR_CMD, 735: 1 << A5XX_INT_GPMU_FIRMWARE); 736: return ret; 737: } 738: 739: void a5xx_hwcg_set(struct adreno_device *adreno_dev, bool on) 740: { 741: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 742: const struct adreno_a5xx_core *a5xx_core = to_a5xx_core(adreno_dev); 743: int i; 744: 745: if (!adreno_dev->hwcg_enabled) 746: return; 747: 748: for (i = 0; i < a5xx_core->hwcg_count; i++) 749: kgsl_regwrite(device, a5xx_core->hwcg[i].offset, 750: on ? a5xx_core->hwcg[i].val : 0); 751: 752: /* enable top level HWCG */ 753: kgsl_regwrite(device, A5XX_RBBM_CLOCK_CNTL, on ? 0xAAA8AA00 : 0); MATCH LINES: 1551 1539: *cmds++ = 0; 1540: 1541: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_LOCAL, 1); 1542: *cmds++ = 1; 1543: 1544: /* Enable yield in RB only */ 1545: *cmds++ = cp_type7_packet(CP_YIELD_ENABLE, 1); 1546: *cmds++ = 1; 1547: 1548: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1549: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 1550: *cmds++ = 0; 1551: /* generate interrupt on preemption completion */ 1552: *cmds++ = 1; 1553: 1554: return cmds - cmds_orig; 1555: } 1556: 1557: static int a5xx_post_start(struct adreno_device *adreno_dev) 1558: { 1559: int ret; 1560: unsigned int *cmds, *start; 1561: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1562: 1563: if (!adreno_is_a530(adreno_dev) && 1564: !adreno_is_preemption_enabled(adreno_dev)) 1565: return 0; 1566: 1567: cmds = adreno_ringbuffer_allocspace(rb, 42); 1568: if (IS_ERR(cmds)) { 1569: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1570: 1571: dev_err(device->dev, 1572: "error allocating preemtion init cmds\n"); 1573: return PTR_ERR(cmds); 1574: } 1575: start = cmds; MATCH LINES: 1945, 1954, 1974, 1993 1933: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_RPTR, A5XX_CP_RB_RPTR), 1934: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_WPTR, A5XX_CP_RB_WPTR), 1935: ADRENO_REG_DEFINE(ADRENO_REG_CP_ME_CNTL, A5XX_CP_ME_CNTL), 1936: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_CNTL, A5XX_CP_RB_CNTL), 1937: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BASE, A5XX_CP_IB1_BASE), 1938: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BASE_HI, A5XX_CP_IB1_BASE_HI), 1939: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BUFSZ, A5XX_CP_IB1_BUFSZ), 1940: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BASE, A5XX_CP_IB2_BASE), 1941: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BASE_HI, A5XX_CP_IB2_BASE_HI), 1942: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BUFSZ, A5XX_CP_IB2_BUFSZ), 1943: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_STATUS, A5XX_RBBM_STATUS), 1944: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_STATUS3, A5XX_RBBM_STATUS3), 1945: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_INT_0_MASK, A5XX_RBBM_INT_0_MASK), 1946: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_SW_RESET_CMD, A5XX_RBBM_SW_RESET_CMD), 1947: }; 1948: 1949: static void a5xx_cp_hw_err_callback(struct adreno_device *adreno_dev, int bit) 1950: { 1951: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1952: unsigned int status1, status2; 1953: 1954: kgsl_regread(device, A5XX_CP_INTERRUPT_STATUS, &status1); 1955: 1956: if (status1 & BIT(A5XX_CP_OPCODE_ERROR)) { 1957: unsigned int val; 1958: 1959: kgsl_regwrite(device, A5XX_CP_PFP_STAT_ADDR, 0); 1960: 1961: /* 1962: * A5XX_CP_PFP_STAT_DATA is indexed, so read it twice to get the 1963: * value we want 1964: */ 1965: kgsl_regread(device, A5XX_CP_PFP_STAT_DATA, &val); 1966: kgsl_regread(device, A5XX_CP_PFP_STAT_DATA, &val); 1967: 1968: dev_crit_ratelimited(device->dev, 1969: "ringbuffer opcode error | possible opcode=0x%8.8X\n", 1970: val); 1971: } 1972: if (status1 & BIT(A5XX_CP_RESERVED_BIT_ERROR)) 1973: dev_crit_ratelimited(device->dev, 1974: "ringbuffer reserved bit error interrupt\n"); 1975: if (status1 & BIT(A5XX_CP_HW_FAULT_ERROR)) { 1976: kgsl_regread(device, A5XX_CP_HW_FAULT, &status2); 1977: dev_crit_ratelimited(device->dev, 1978: "CP | Ringbuffer HW fault | status=%x\n", 1979: status2); 1980: } 1981: if (status1 & BIT(A5XX_CP_DMA_ERROR)) 1982: dev_crit_ratelimited(device->dev, "CP | DMA error\n"); 1983: if (status1 & BIT(A5XX_CP_REGISTER_PROTECTION_ERROR)) { 1984: kgsl_regread(device, A5XX_CP_PROTECT_STATUS, &status2); 1985: dev_crit_ratelimited(device->dev, 1986: "CP | Protected mode error| %s | addr=%x | status=%x\n", 1987: status2 & (1 << 24) ? "WRITE" : "READ", 1988: (status2 & 0xFFFFF) >> 2, status2); 1989: } 1990: if (status1 & BIT(A5XX_CP_AHB_ERROR)) { 1991: kgsl_regread(device, A5XX_CP_AHB_FAULT, &status2); 1992: dev_crit_ratelimited(device->dev, 1993: "ringbuffer AHB error interrupt | status=%x\n", 1994: status2); 1995: } 1996: } 1997: 1998: static void a5xx_err_callback(struct adreno_device *adreno_dev, int bit) 1999: { 2000: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2001: unsigned int reg; 2002: 2003: switch (bit) { 2004: case A5XX_INT_RBBM_AHB_ERROR: { 2005: kgsl_regread(device, A5XX_RBBM_AHB_ERROR_STATUS, ®); 2006: 2007: /* 2008: * Return the word address of the erroring register so that it 2009: * matches the register specification 2010: */ 2011: dev_crit_ratelimited(device->dev, 2012: "RBBM | AHB bus error | %s | addr=%x | ports=%x:%x\n", 2013: reg & (1 << 28) ? "WRITE" : "READ", 2014: (reg & 0xFFFFF) >> 2, 2015: (reg >> 20) & 0x3, 2016: (reg >> 24) & 0xF); 2017: MATCH LINES: 2055, 2061, 2079, 2082, 2084, 2111, 2113, 2121, 2128 2043: dev_crit_ratelimited(device->dev, 2044: "RBBM: ATB ASYNC overflow\n"); 2045: break; 2046: case A5XX_INT_RBBM_ATB_BUS_OVERFLOW: 2047: dev_crit_ratelimited(device->dev, 2048: "RBBM: ATB bus overflow\n"); 2049: break; 2050: case A5XX_INT_UCHE_OOB_ACCESS: 2051: dev_crit_ratelimited(device->dev, 2052: "UCHE: Out of bounds access\n"); 2053: break; 2054: case A5XX_INT_UCHE_TRAP_INTR: 2055: dev_crit_ratelimited(device->dev, "UCHE: Trap interrupt\n"); 2056: break; 2057: case A5XX_INT_GPMU_VOLTAGE_DROOP: 2058: dev_crit_ratelimited(device->dev, "GPMU: Voltage droop\n"); 2059: break; 2060: default: 2061: dev_crit_ratelimited(device->dev, "Unknown interrupt %d\n", 2062: bit); 2063: } 2064: } 2065: 2066: static void a5xx_irq_storm_worker(struct work_struct *work) 2067: { 2068: struct adreno_device *adreno_dev = container_of(work, 2069: struct adreno_device, irq_storm_work); 2070: struct kgsl_device *device = &adreno_dev->dev; 2071: unsigned int status; 2072: 2073: kgsl_mutex_lock(&device->mutex); 2074: 2075: /* Wait for the storm to clear up */ 2076: do { 2077: kgsl_regwrite(device, A5XX_RBBM_INT_CLEAR_CMD, 2078: BIT(A5XX_INT_CP_CACHE_FLUSH_TS)); 2079: kgsl_regread(device, A5XX_RBBM_INT_0_STATUS, &status); 2080: } while (status & BIT(A5XX_INT_CP_CACHE_FLUSH_TS)); 2081: 2082: /* Re-enable the interrupt bit in the mask */ 2083: adreno_dev->irq_mask |= BIT(A5XX_INT_CP_CACHE_FLUSH_TS); 2084: kgsl_regwrite(device, A5XX_RBBM_INT_0_MASK, adreno_dev->irq_mask); 2085: clear_bit(ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED, &adreno_dev->priv); 2086: 2087: dev_warn(device->dev, "Re-enabled A5XX_INT_CP_CACHE_FLUSH_TS\n"); 2088: kgsl_mutex_unlock(&device->mutex); 2089: 2090: /* Reschedule just to make sure everything retires */ 2091: adreno_scheduler_queue(adreno_dev); 2092: } 2093: 2094: static void a5xx_cp_callback(struct adreno_device *adreno_dev, int bit) 2095: { 2096: struct kgsl_device *device = &adreno_dev->dev; 2097: unsigned int cur; 2098: static unsigned int count; 2099: static unsigned int prev; 2100: 2101: if (test_bit(ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED, &adreno_dev->priv)) 2102: return; 2103: 2104: kgsl_sharedmem_readl(device->memstore, &cur, 2105: KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, 2106: ref_wait_ts)); 2107: 2108: /* 2109: * prev holds a previously read value 2110: * from memory. It should be changed by the GPU with every 2111: * interrupt. If the value we know about and the value we just 2112: * read are the same, then we are likely in a storm. 2113: * If this happens twice, disable the interrupt in the mask 2114: * so the dispatcher can take care of the issue. It is then 2115: * up to the dispatcher to re-enable the mask once all work 2116: * is done and the storm has ended. 2117: */ 2118: if (prev == cur) { 2119: count++; 2120: if (count == 2) { 2121: /* disable interrupt from the mask */ 2122: set_bit(ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED, 2123: &adreno_dev->priv); 2124: 2125: adreno_dev->irq_mask &= 2126: ~BIT(A5XX_INT_CP_CACHE_FLUSH_TS); 2127: 2128: kgsl_regwrite(device, A5XX_RBBM_INT_0_MASK, 2129: adreno_dev->irq_mask); 2130: 2131: kgsl_schedule_work(&adreno_dev->irq_storm_work); 2132: 2133: return; 2134: } 2135: } else { 2136: count = 0; 2137: prev = cur; 2138: } 2139: 2140: a5xx_preemption_trigger(adreno_dev); 2141: adreno_scheduler_queue(adreno_dev); 2142: } 2143: 2144: static const char *gpmu_int_msg[32] = { 2145: [FW_INTR_INFO] = "FW_INTR_INFO", 2146: [LLM_ACK_ERR_INTR] = "LLM_ACK_ERR_INTR", 2147: [ISENS_TRIM_ERR_INTR] = "ISENS_TRIM_ERR_INTR", 2148: [ISENS_ERR_INTR] = "ISENS_ERR_INTR", 2149: [ISENS_IDLE_ERR_INTR] = "ISENS_IDLE_ERR_INTR", 2150: [ISENS_PWR_ON_ERR_INTR] = "ISENS_PWR_ON_ERR_INTR", 2151: [6 ... 30] = "", 2152: [WDOG_EXPITED] = "WDOG_EXPITED"}; MATCH LINES: 2190, 2198, 2200, 2208 2178: case BIT(FW_INTR_INFO): 2179: fallthrough; 2180: case BIT(LLM_ACK_ERR_INTR): 2181: fallthrough; 2182: case BIT(ISENS_TRIM_ERR_INTR): 2183: fallthrough; 2184: case BIT(ISENS_ERR_INTR): 2185: fallthrough; 2186: case BIT(ISENS_IDLE_ERR_INTR): 2187: fallthrough; 2188: case BIT(ISENS_PWR_ON_ERR_INTR): 2189: dev_crit_ratelimited(device->dev, 2190: "GPMU: interrupt %s(%08lx)\n", 2191: gpmu_int_msg[i], 2192: BIT(i)); 2193: break; 2194: } 2195: } 2196: 2197: /* 2198: * a5x_gpc_err_int_callback() - Isr for GPC error interrupts 2199: * @adreno_dev: Pointer to device 2200: * @bit: Interrupt bit 2201: */ 2202: static void a5x_gpc_err_int_callback(struct adreno_device *adreno_dev, int bit) 2203: { 2204: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2205: 2206: /* 2207: * GPC error is typically the result of mistake SW programming. 2208: * Force GPU fault for this interrupt so that we can debug it 2209: * with help of register dump. 2210: */ 2211: 2212: dev_crit(device->dev, "RBBM: GPC error\n"); 2213: adreno_irqctrl(adreno_dev, 0); 2214: 2215: /* Trigger a fault in the dispatcher - this will effect a restart */ 2216: adreno_scheduler_fault(adreno_dev, ADRENO_SOFT_FAULT); 2217: } 2218: 2219: u64 a5xx_read_alwayson(struct adreno_device *adreno_dev) 2220: { 2221: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2222: u32 lo = 0, hi = 0; 2223: 2224: kgsl_regread(device, A5XX_RBBM_ALWAYSON_COUNTER_LO, &lo); 2225: 2226: /* The upper 32 bits are only reliable on A540 targets */ 2227: if (adreno_is_a540(adreno_dev)) 2228: kgsl_regread(device, A5XX_RBBM_ALWAYSON_COUNTER_HI, &hi); 2229: 2230: return (((u64) hi) << 32) | lo; 2231: } 2232: MATCH LINES: 2279, 2282, 2285, 2288, 2289, 2325, 2327 2267: /* 23 - MISC_HANG_DETECT */ 2268: ADRENO_IRQ_CALLBACK(adreno_hang_int_callback), 2269: ADRENO_IRQ_CALLBACK(a5xx_err_callback), /* 24 - UCHE_OOB_ACCESS */ 2270: ADRENO_IRQ_CALLBACK(a5xx_err_callback), /* 25 - UCHE_TRAP_INTR */ 2271: ADRENO_IRQ_CALLBACK(NULL), /* 26 - DEBBUS_INTR_0 */ 2272: ADRENO_IRQ_CALLBACK(NULL), /* 27 - DEBBUS_INTR_1 */ 2273: ADRENO_IRQ_CALLBACK(a5xx_err_callback), /* 28 - GPMU_VOLTAGE_DROOP */ 2274: ADRENO_IRQ_CALLBACK(a5xx_gpmu_int_callback), /* 29 - GPMU_FIRMWARE */ 2275: ADRENO_IRQ_CALLBACK(NULL), /* 30 - ISDB_CPU_IRQ */ 2276: ADRENO_IRQ_CALLBACK(NULL), /* 31 - ISDB_UNDER_DEBUG */ 2277: }; 2278: 2279: static irqreturn_t a5xx_irq_handler(struct adreno_device *adreno_dev) 2280: { 2281: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2282: irqreturn_t ret; 2283: u32 status; 2284: 2285: kgsl_regread(device, A5XX_RBBM_INT_0_STATUS, &status); 2286: 2287: /* 2288: * Clear all the interrupt bits except A5XX_INT_RBBM_AHB_ERROR. 2289: * The interrupt will stay asserted until it is cleared by the handler 2290: * so don't touch it yet to avoid a storm 2291: */ 2292: kgsl_regwrite(device, A5XX_RBBM_INT_CLEAR_CMD, 2293: status & ~A5XX_INT_RBBM_AHB_ERROR); 2294: 2295: /* Call the helper function for callbacks */ 2296: ret = adreno_irq_callbacks(adreno_dev, a5xx_irq_funcs, status); 2297: 2298: trace_kgsl_a5xx_irq_status(adreno_dev, status); 2299: 2300: /* Now chear AHB_ERROR if it was set */ 2301: if (status & A5XX_INT_RBBM_AHB_ERROR) 2302: kgsl_regwrite(device, A5XX_RBBM_INT_CLEAR_CMD, 2303: A5XX_INT_RBBM_AHB_ERROR); 2304: 2305: return ret; 2306: } 2307: 2308: static bool a5xx_hw_isidle(struct adreno_device *adreno_dev) 2309: { 2310: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2311: u32 status; 2312: 2313: /* 2314: * Due to CRC idle throttling the GPU idle hysteresis on a540 can take 2315: * up to 5uS to expire 2316: */ 2317: if (adreno_is_a540(adreno_dev)) 2318: udelay(5); 2319: 2320: kgsl_regread(device, A5XX_RBBM_STATUS, &status); 2321: 2322: if (status & 0xfffffffe) 2323: return false; 2324: 2325: kgsl_regread(device, A5XX_RBBM_INT_0_STATUS, &status); 2326: 2327: /* Return busy if a interrupt is pending */ 2328: return !((status & adreno_dev->irq_mask) || 2329: atomic_read(&adreno_dev->pending_irq_refcnt)); 2330: } 2331: 2332: static int a5xx_clear_pending_transactions(struct adreno_device *adreno_dev) 2333: { 2334: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2335: u32 mask = A5XX_VBIF_XIN_HALT_CTRL0_MASK; 2336: int ret; 2337: 2338: kgsl_regwrite(device, A5XX_VBIF_XIN_HALT_CTRL0, mask); 2339: ret = adreno_wait_for_halt_ack(device, A5XX_VBIF_XIN_HALT_CTRL1, mask); 2340: kgsl_regwrite(device, A5XX_VBIF_XIN_HALT_CTRL0, 0); 2341: 2342: return ret; 2343: } 2344: 2345: static bool a5xx_is_hw_collapsible(struct adreno_device *adreno_dev) 2346: { 2347: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2348: unsigned int reg; 2349: 2350: if (!adreno_isidle(adreno_dev)) 2351: return false; MATCH LINES: 2434 2422: &busy->bif_ram_cycles); 2423: 2424: stats->ram_wait = counter_delta(device, adreno_dev->starved_ram_lo, 2425: &busy->bif_starved_ram); 2426: } 2427: 2428: const struct adreno_gpudev adreno_a5xx_gpudev = { 2429: .reg_offsets = a5xx_register_offsets, 2430: .probe = a5xx_probe, 2431: .start = a5xx_start, 2432: .snapshot = a5xx_snapshot, 2433: .init = a5xx_init, 2434: .irq_handler = a5xx_irq_handler, 2435: .rb_start = a5xx_rb_start, 2436: .regulator_enable = a5xx_regulator_enable, 2437: .regulator_disable = a5xx_regulator_disable, 2438: .pwrlevel_change_settings = a5xx_pwrlevel_change_settings, 2439: .preemption_schedule = a5xx_preemption_schedule, 2440: .read_alwayson = a5xx_read_alwayson, 2441: .hw_isidle = a5xx_hw_isidle, 2442: .power_ops = &adreno_power_operations, 2443: .clear_pending_transactions = a5xx_clear_pending_transactions, 2444: .remove = a5xx_remove, 2445: .ringbuffer_submitcmd = a5xx_ringbuffer_submitcmd, 2446: .is_hw_collapsible = a5xx_is_hw_collapsible, 2447: .power_stats = a5xx_power_stats, 2448: }; --- FILE: \adreno_a5xx.h | HITS: 1 --- MATCH LINES: 109 97: }; 98: 99: void a5xx_snapshot(struct adreno_device *adreno_dev, 100: struct kgsl_snapshot *snapshot); 101: unsigned int a5xx_num_registers(void); 102: 103: void a5xx_crashdump_init(struct adreno_device *adreno_dev); 104: 105: void a5xx_hwcg_set(struct adreno_device *adreno_dev, bool on); 106: 107: #define A5XX_CP_RB_CNTL_DEFAULT ((1 << 27) | ((ilog2(4) << 8) & 0x1F00) | \ 108: (ilog2(KGSL_RB_DWORDS >> 1) & 0x3F)) 109: /* GPMU interrupt multiplexor */ 110: #define FW_INTR_INFO (0) 111: #define LLM_ACK_ERR_INTR (1) 112: #define ISENS_TRIM_ERR_INTR (2) 113: #define ISENS_ERR_INTR (3) 114: #define ISENS_IDLE_ERR_INTR (4) 115: #define ISENS_PWR_ON_ERR_INTR (5) 116: #define WDOG_EXPITED (31) 117: 118: #define VALID_GPMU_IRQ (\ 119: BIT(FW_INTR_INFO) | \ 120: BIT(LLM_ACK_ERR_INTR) | \ 121: BIT(ISENS_TRIM_ERR_INTR) | \ 122: BIT(ISENS_ERR_INTR) | \ 123: BIT(ISENS_IDLE_ERR_INTR) | \ 124: BIT(ISENS_PWR_ON_ERR_INTR) | \ 125: BIT(WDOG_EXPITED)) 126: 127: /* A5XX_GPMU_GPMU_LLM_GLM_SLEEP_CTRL */ 128: #define STATE_OF_CHILD GENMASK(5, 4) 129: #define STATE_OF_CHILD_01 BIT(4) 130: #define STATE_OF_CHILD_11 (BIT(4) | BIT(5)) 131: #define IDLE_FULL_LM_SLEEP BIT(0) 132: 133: /* A5XX_GPMU_GPMU_LLM_GLM_SLEEP_STATUS */ --- FILE: \adreno_a5xx_preempt.c | HITS: 3 --- MATCH LINES: 269, 274 257: { 258: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 259: unsigned int status; 260: 261: if (!adreno_move_preempt_state(adreno_dev, 262: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 263: return; 264: 265: kgsl_regread(device, A5XX_CP_CONTEXT_SWITCH_CNTL, &status); 266: 267: if (status != 0) { 268: dev_err(KGSL_DEVICE(adreno_dev)->dev, 269: "preempt interrupt with non-zero status: %X\n", 270: status); 271: 272: /* 273: * Under the assumption that this is a race between the 274: * interrupt and the register, schedule the worker to clean up. 275: * If the status still hasn't resolved itself by the time we get 276: * there then we have to assume something bad happened 277: */ 278: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE); 279: adreno_scheduler_queue(adreno_dev); 280: return; 281: } 282: 283: kgsl_delete_timer(&adreno_dev->preempt.timer); 284: 285: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 0, 0); 286: 287: adreno_dev->prev_rb = adreno_dev->cur_rb; 288: adreno_dev->cur_rb = adreno_dev->next_rb; 289: adreno_dev->next_rb = NULL; 290: 291: /* Update the wptr if it changed while preemption was ongoing */ 292: _update_wptr(adreno_dev, true); 293: 294: /* Update the dispatcher timer for the new command queue */ 295: mod_timer(&adreno_dev->dispatcher.timer, 296: adreno_dev->cur_rb->dispatch_q.expires); 297: 298: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); MATCH LINES: 407 395: unsigned int a5xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 396: unsigned int *cmds) 397: { 398: int dwords = 0; 399: 400: if (!adreno_is_preemption_enabled(adreno_dev)) 401: return 0; 402: 403: cmds[dwords++] = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 404: /* Write NULL to the address to skip the data write */ 405: dwords += cp_gpuaddr(adreno_dev, &cmds[dwords], 0x0); 406: cmds[dwords++] = 1; 407: /* generate interrupt on preemption completion */ 408: cmds[dwords++] = 1; 409: 410: return dwords; 411: } 412: 413: void a5xx_preemption_start(struct adreno_device *adreno_dev) 414: { 415: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 416: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 417: struct adreno_ringbuffer *rb; 418: unsigned int i; 419: 420: if (!adreno_is_preemption_enabled(adreno_dev)) 421: return; 422: 423: /* Force the state to be clear */ 424: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 425: 426: /* Only set up smmu info when per-process pagetables are enabled */ 427: 428: if (kgsl_mmu_is_perprocess(&device->mmu)) { 429: /* smmu_info is allocated and mapped in a5xx_preemption_iommu_init */ 430: kgsl_sharedmem_writel(iommu->smmu_info, 431: PREEMPT_SMMU_RECORD(magic), A5XX_CP_SMMU_INFO_MAGIC_REF); --- FILE: \adreno_a5xx_ringbuffer.c | HITS: 1 --- MATCH LINES: 231 219: cmds[index++] = lower_32_bits(profile_gpuaddr); 220: cmds[index++] = upper_32_bits(profile_gpuaddr); 221: cmds[index++] = profile_dwords; 222: } 223: 224: if (!adreno_is_a510(adreno_dev) && 225: test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, 226: &device->mmu.pfpolicy)) 227: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0); 228: 229: /* 230: * Do a unique memory write from the GPU to assist in early detection of 231: * interrupt storms 232: */ 233: 234: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 235: cmds[index++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 236: KGSL_MEMSTORE_GLOBAL, ref_wait_ts)); 237: cmds[index++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 238: KGSL_MEMSTORE_GLOBAL, ref_wait_ts)); 239: cmds[index++] = ++sequence; 240: 241: /* 242: * If this is an internal command, just write the ringbuffer timestamp, 243: * otherwise, write both 244: */ 245: if (!drawctxt) { 246: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 247: cmds[index++] = CACHE_FLUSH_TS | (1 << 31); 248: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 249: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 250: cmds[index++] = rb->timestamp; 251: } else { 252: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 253: cmds[index++] = CACHE_FLUSH_TS | (1 << 31); 254: cmds[index++] = lower_32_bits(CTXT_EOPTIMESTAMP(device, 255: drawctxt)); --- FILE: \adreno_a6xx.c | HITS: 34 --- MATCH LINES: 751 739: 740: /* Turn on performance counters */ 741: kgsl_regwrite(device, A6XX_RBBM_PERFCTR_CNTL, 0x1); 742: 743: /* Turn on the IFPC counter (countable 4 on XOCLK4) */ 744: if (gmu_core_isenabled(device)) 745: gmu_core_regrmw(device, A6XX_GMU_CX_GMU_POWER_COUNTER_SELECT_1, 746: 0xff, 0x4); 747: 748: /* Turn on GX_MEM retention */ 749: if (gmu_core_isenabled(device) && adreno_is_a612(adreno_dev)) { 750: kgsl_regwrite(device, A6XX_RBBM_BLOCK_GX_RETENTION_CNTL, 0x7FB); 751: /* For CP IPC interrupt */ 752: kgsl_regwrite(device, A6XX_RBBM_INT_2_MASK, 0x00000010); 753: } 754: 755: /* macrotilingmode 0: 4 channels (default) 756: * overwrite to 1: 8 channels for supported gpus 757: */ 758: if (adreno_is_a680(adreno_dev) || 759: adreno_is_a663(adreno_dev) || 760: adreno_is_a704(adreno_dev)) 761: kgsl_regwrite(device, A6XX_RBBM_NC_MODE_CNTL, 1); 762: 763: if (adreno_dev->highest_bank_bit) { 764: hbb_lo = (adreno_dev->highest_bank_bit - 13) & 3; 765: hbb_hi = ((adreno_dev->highest_bank_bit - 13) >> 2) & 1; 766: } 767: 768: mal = (mal == 64) ? 1 : 0; 769: 770: uavflagprd_inv = (adreno_is_a650_family(adreno_dev)) ? 2 : 0; 771: 772: kgsl_regwrite(device, A6XX_RB_NC_MODE_CNTL, 773: (ubwc_props->level2_swizzling_dis << 12) | 774: (ubwc_props->rgb565_predicator << 11) | 775: (hbb_hi << 10) | (ubwc_props->amsbc << 4) | (mal << 3) | MATCH LINES: 1025, 1030 1013: struct kgsl_device *device = &adreno_dev->dev; 1014: unsigned int rptr, wptr; 1015: unsigned int status, status3, intstatus; 1016: unsigned int hwfault; 1017: 1018: dev_err(device->dev, str); 1019: 1020: kgsl_regread(device, A6XX_CP_RB_RPTR, &rptr); 1021: kgsl_regread(device, A6XX_CP_RB_WPTR, &wptr); 1022: 1023: kgsl_regread(device, A6XX_RBBM_STATUS, &status); 1024: kgsl_regread(device, A6XX_RBBM_STATUS3, &status3); 1025: kgsl_regread(device, A6XX_RBBM_INT_0_STATUS, &intstatus); 1026: kgsl_regread(device, A6XX_CP_HW_FAULT, &hwfault); 1027: 1028: 1029: dev_err(device->dev, 1030: "rb=%d pos=%X/%X rbbm_status=%8.8X/%8.8X int_0_status=%8.8X\n", 1031: adreno_dev->cur_rb ? adreno_dev->cur_rb->id : -1, rptr, wptr, 1032: status, status3, intstatus); 1033: 1034: dev_err(device->dev, " hwfault=%8.8X\n", hwfault); 1035: 1036: kgsl_device_snapshot(device, NULL, NULL, false); 1037: 1038: } 1039: 1040: /* 1041: * a6xx_send_cp_init() - Initialize ringbuffer 1042: * @adreno_dev: Pointer to adreno device 1043: * @rb: Pointer to the ringbuffer of device 1044: * 1045: * Submit commands for ME initialization, 1046: */ 1047: static int a6xx_send_cp_init(struct adreno_device *adreno_dev, 1048: struct adreno_ringbuffer *rb) 1049: { 1050: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1051: unsigned int *cmds; 1052: int ret; 1053: 1054: cmds = adreno_ringbuffer_allocspace(rb, A6XX_CP_INIT_DWORDS); MATCH LINES: 1111 1099: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 1100: cmds += cp_gpuaddr(adreno_dev, cmds, 1101: rb->secure_preemption_desc->gpuaddr); 1102: } 1103: 1104: /* Turn CP protection back ON */ 1105: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 1106: cmds += cp_protected_mode(adreno_dev, cmds, 1); 1107: 1108: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1109: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 1110: *cmds++ = 0; 1111: /* generate interrupt on preemption completion */ 1112: *cmds++ = 0; 1113: 1114: return cmds - cmds_orig; 1115: } 1116: 1117: static int a6xx_post_start(struct adreno_device *adreno_dev) 1118: { 1119: int ret; 1120: unsigned int *cmds, *start; 1121: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1122: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1123: 1124: if (!adreno_is_preemption_enabled(adreno_dev)) 1125: return 0; 1126: 1127: cmds = adreno_ringbuffer_allocspace(rb, 42); 1128: if (IS_ERR(cmds)) { 1129: dev_err(device->dev, 1130: "error allocating preemption init cmds\n"); 1131: return PTR_ERR(cmds); 1132: } 1133: start = cmds; 1134: 1135: cmds += _preemption_init(adreno_dev, rb, cmds, NULL); MATCH LINES: 1297, 1299 1285: 1286: if (!gmu_core_isenabled(device)) 1287: return; 1288: 1289: gmu_core_regwrite(device, A6XX_GMU_GMU_PWR_COL_KEEPALIVE, state); 1290: } 1291: 1292: bool a6xx_irq_pending(struct adreno_device *adreno_dev) 1293: { 1294: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1295: u32 status; 1296: 1297: kgsl_regread(device, A6XX_RBBM_INT_0_STATUS, &status); 1298: 1299: /* Return busy if a interrupt is pending */ 1300: return ((status & adreno_dev->irq_mask) || 1301: atomic_read(&adreno_dev->pending_irq_refcnt)); 1302: } 1303: 1304: static bool a619_holi_hw_isidle(struct adreno_device *adreno_dev) 1305: { 1306: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1307: unsigned int reg; 1308: 1309: kgsl_regread(device, A6XX_RBBM_STATUS, ®); 1310: if (reg & 0xfffffffe) 1311: return false; 1312: 1313: return a6xx_irq_pending(adreno_dev) ? false : true; 1314: } 1315: 1316: bool a6xx_hw_isidle(struct adreno_device *adreno_dev) 1317: { 1318: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1319: unsigned int reg; 1320: 1321: /* Non GMU devices monitor the RBBM status */ 1322: if (!gmu_core_isenabled(device)) { 1323: kgsl_regread(device, A6XX_RBBM_STATUS, ®); MATCH LINES: 1520, 1528, 1531, 1546, 1577, 1580, 1583 1508: */ 1509: if (!atomic_read(&device->active_cnt)) 1510: kgsl_pwrctrl_change_state(device, KGSL_STATE_SLUMBER); 1511: 1512: return 0; 1513: } 1514: 1515: static void a6xx_cp_hw_err_callback(struct adreno_device *adreno_dev, int bit) 1516: { 1517: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1518: unsigned int status1, status2; 1519: 1520: kgsl_regread(device, A6XX_CP_INTERRUPT_STATUS, &status1); 1521: 1522: if (status1 & BIT(A6XX_CP_OPCODE_ERROR)) { 1523: unsigned int opcode; 1524: 1525: kgsl_regwrite(device, A6XX_CP_SQE_STAT_ADDR, 1); 1526: kgsl_regread(device, A6XX_CP_SQE_STAT_DATA, &opcode); 1527: dev_crit_ratelimited(device->dev, 1528: "CP opcode error interrupt | opcode=0x%8.8x\n", opcode); 1529: } 1530: if (status1 & BIT(A6XX_CP_UCODE_ERROR)) 1531: dev_crit_ratelimited(device->dev, "CP ucode error interrupt\n"); 1532: if (status1 & BIT(A6XX_CP_HW_FAULT_ERROR)) { 1533: kgsl_regread(device, A6XX_CP_HW_FAULT, &status2); 1534: dev_crit_ratelimited(device->dev, 1535: "CP | Ringbuffer HW fault | status=%x\n", status2); 1536: } 1537: if (status1 & BIT(A6XX_CP_REGISTER_PROTECTION_ERROR)) { 1538: kgsl_regread(device, A6XX_CP_PROTECT_STATUS, &status2); 1539: dev_crit_ratelimited(device->dev, 1540: "CP | Protected mode error | %s | addr=%x | status=%x\n", 1541: status2 & (1 << 20) ? "READ" : "WRITE", 1542: status2 & 0x3FFFF, status2); 1543: } 1544: if (status1 & BIT(A6XX_CP_AHB_ERROR)) 1545: dev_crit_ratelimited(device->dev, 1546: "CP AHB error interrupt\n"); 1547: if (status1 & BIT(A6XX_CP_VSD_PARITY_ERROR)) 1548: dev_crit_ratelimited(device->dev, 1549: "CP VSD decoder parity error\n"); 1550: if (status1 & BIT(A6XX_CP_ILLEGAL_INSTR_ERROR)) 1551: dev_crit_ratelimited(device->dev, 1552: "CP Illegal instruction error\n"); 1553: 1554: } 1555: 1556: static void a6xx_err_callback(struct adreno_device *adreno_dev, int bit) 1557: { 1558: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1559: 1560: switch (bit) { 1561: case A6XX_INT_CP_AHB_ERROR: 1562: dev_crit_ratelimited(device->dev, "CP: AHB bus error\n"); 1563: break; 1564: case A6XX_INT_ATB_ASYNCFIFO_OVERFLOW: 1565: dev_crit_ratelimited(device->dev, 1566: "RBBM: ATB ASYNC overflow\n"); 1567: break; 1568: case A6XX_INT_RBBM_ATB_BUS_OVERFLOW: 1569: dev_crit_ratelimited(device->dev, 1570: "RBBM: ATB bus overflow\n"); 1571: break; 1572: case A6XX_INT_UCHE_OOB_ACCESS: 1573: dev_crit_ratelimited(device->dev, 1574: "UCHE: Out of bounds access\n"); 1575: break; 1576: case A6XX_INT_UCHE_TRAP_INTR: 1577: dev_crit_ratelimited(device->dev, "UCHE: Trap interrupt\n"); 1578: break; 1579: case A6XX_INT_TSB_WRITE_ERROR: 1580: dev_crit_ratelimited(device->dev, "TSB: Write error interrupt\n"); 1581: break; 1582: default: 1583: dev_crit_ratelimited(device->dev, "Unknown interrupt %d\n", 1584: bit); 1585: } 1586: } 1587: 1588: /* 1589: * a6xx_llc_configure_gpu_scid() - Program the sub-cache ID for all GPU blocks 1590: * @adreno_dev: The adreno device pointer 1591: */ 1592: static void a6xx_llc_configure_gpu_scid(struct adreno_device *adreno_dev) 1593: { 1594: uint32_t gpu_scid; 1595: uint32_t gpu_cntl1_val = 0; 1596: int i; 1597: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1598: struct kgsl_mmu *mmu = &device->mmu; 1599: 1600: if (IS_ERR_OR_NULL(adreno_dev->gpu_llc_slice) || 1601: !adreno_dev->gpu_llc_slice_enable) 1602: return; 1603: 1604: if (llcc_slice_activate(adreno_dev->gpu_llc_slice)) 1605: return; 1606: 1607: gpu_scid = llcc_get_slice_id(adreno_dev->gpu_llc_slice); MATCH LINES: 1810, 1812, 1820 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 */ MATCH LINES: 1870 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: 1886: kgsl_regread(device, A6XX_GMU_AO_AHB_FENCE_CTRL, &fence); 1887: 1888: while (fence != 0) { 1889: b = a6xx_read_alwayson(adreno_dev); 1890: 1891: /* Wait for small time before trying again */ 1892: udelay(1); 1893: kgsl_regread(device, A6XX_GMU_AO_AHB_FENCE_CTRL, &fence); 1894: MATCH LINES: 1914, 1917, 1921, 1927, 1942, 1945, 1949, 1960 1902: "status=0x%x Unmasked status=0x%x Mask=0x%x timestamps: %llx %llx %llx\n", 1903: status & adreno_dev->irq_mask, status, 1904: adreno_dev->irq_mask, a, b, c); 1905: return -ETIMEDOUT; 1906: } 1907: 1908: fence_retries++; 1909: } 1910: 1911: return 0; 1912: } 1913: 1914: static irqreturn_t a6xx_hwsched_irq_handler(struct adreno_device *adreno_dev) 1915: { 1916: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1917: irqreturn_t ret = IRQ_NONE; 1918: u32 status; 1919: 1920: /* 1921: * On A6xx, the GPU can power down once the INT_0_STATUS is read 1922: * below. But there still might be some register reads required 1923: * so force the GMU/GPU into KEEPALIVE mode until done with the ISR. 1924: */ 1925: a6xx_gpu_keepalive(adreno_dev, true); 1926: 1927: kgsl_regread(device, A6XX_RBBM_INT_0_STATUS, &status); 1928: 1929: kgsl_regwrite(device, A6XX_RBBM_INT_CLEAR_CMD, status); 1930: 1931: ret = adreno_irq_callbacks(adreno_dev, a6xx_irq_funcs, status); 1932: 1933: trace_kgsl_a5xx_irq_status(adreno_dev, status); 1934: 1935: /* If hard fault, then let snapshot turn off the keepalive */ 1936: if (!(adreno_gpu_fault(adreno_dev) & ADRENO_HARD_FAULT)) 1937: a6xx_gpu_keepalive(adreno_dev, false); 1938: 1939: return ret; 1940: } 1941: 1942: static irqreturn_t a6xx_irq_handler(struct adreno_device *adreno_dev) 1943: { 1944: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1945: irqreturn_t ret = IRQ_NONE; 1946: u32 status; 1947: 1948: /* 1949: * On A6xx, the GPU can power down once the INT_0_STATUS is read 1950: * below. But there still might be some register reads required 1951: * so force the GMU/GPU into KEEPALIVE mode until done with the ISR. 1952: */ 1953: a6xx_gpu_keepalive(adreno_dev, true); 1954: 1955: if (a6xx_irq_poll_fence(adreno_dev)) { 1956: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 1957: goto done; 1958: } 1959: 1960: kgsl_regread(device, A6XX_RBBM_INT_0_STATUS, &status); 1961: 1962: kgsl_regwrite(device, A6XX_RBBM_INT_CLEAR_CMD, status); 1963: 1964: ret = adreno_irq_callbacks(adreno_dev, a6xx_irq_funcs, status); 1965: 1966: trace_kgsl_a5xx_irq_status(adreno_dev, status); 1967: 1968: done: 1969: /* If hard fault, then let snapshot turn off the keepalive */ 1970: if (!(adreno_gpu_fault(adreno_dev) & ADRENO_HARD_FAULT)) 1971: a6xx_gpu_keepalive(adreno_dev, false); 1972: 1973: return ret; 1974: } 1975: 1976: int a6xx_probe_common(struct platform_device *pdev, 1977: struct adreno_device *adreno_dev, u32 chipid, 1978: const struct adreno_gpu_core *gpucore) 1979: { 1980: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1981: const struct adreno_gpudev *gpudev = gpucore->gpudev; 1982: int ret; 1983: 1984: adreno_dev->gpucore = gpucore; MATCH LINES: 2108, 2110, 2111 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, 2113: A6XX_GMU_GMU2HOST_INTR_MASK), 2114: }; 2115: 2116: int a6xx_perfcounter_update(struct adreno_device *adreno_dev, 2117: struct adreno_perfcount_register *reg, bool update_reg) 2118: { 2119: void *ptr = adreno_dev->pwrup_reglist->hostptr; 2120: struct cpu_gpu_lock *lock = ptr; 2121: u32 *data = ptr + sizeof(*lock); 2122: u64 reglist_size_dwords = adreno_dev->pwrup_reglist->size / sizeof(u32); 2123: u64 lock_size_dwords = sizeof(*lock) / sizeof(u32); 2124: int i, offset = 0; 2125: bool select_reg_present = false; 2126: u32 pending_pairs = 2; /* No of pairs to add: and */ 2127: 2128: for (i = 0; i < lock->list_length >> 1; i++) { 2129: if (data[offset] == reg->select) { 2130: select_reg_present = true; 2131: break; 2132: } 2133: 2134: if (data[offset] == A6XX_RBBM_PERFCTR_CNTL) 2135: break; MATCH LINES: 2390, 2415, 2438, 2464, 2489, 2515 2378: (val & SPTPRAC_POWEROFF_STATUS_MASK) == 2379: SPTPRAC_POWEROFF_STATUS_MASK, 10, 10 * 1000)) 2380: dev_err(device->dev, "power off SPTPRAC fail\n"); 2381: } 2382: 2383: /* This is a non GMU/RGMU part */ 2384: const struct adreno_gpudev adreno_a6xx_gpudev = { 2385: .reg_offsets = a6xx_register_offsets, 2386: .probe = a6xx_probe, 2387: .start = a6xx_nogmu_start, 2388: .snapshot = a6xx_snapshot, 2389: .init = a6xx_nogmu_init, 2390: .irq_handler = a6xx_irq_handler, 2391: .rb_start = a6xx_rb_start, 2392: .regulator_disable = a6xx_prepare_for_regulator_disable, 2393: .gpu_keepalive = a6xx_gpu_keepalive, 2394: .hw_isidle = a6xx_hw_isidle, 2395: .iommu_fault_block = a6xx_iommu_fault_block, 2396: .reset = a6xx_reset, 2397: .preemption_schedule = a6xx_preemption_schedule, 2398: .read_alwayson = a6xx_read_alwayson, 2399: .power_ops = &adreno_power_operations, 2400: .clear_pending_transactions = a6xx_clear_pending_transactions, 2401: .deassert_gbif_halt = a6xx_deassert_gbif_halt, 2402: .remove = a6xx_remove, 2403: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2404: .is_hw_collapsible = adreno_isidle, 2405: .power_stats = a6xx_power_stats, 2406: .add_to_va_minidump = a6xx_dev_add_to_minidump, 2407: .gx_is_on = a6xx_gx_is_on, 2408: }; 2409: 2410: const struct a6xx_gpudev adreno_a6xx_hwsched_gpudev = { 2411: .base = { 2412: .reg_offsets = a6xx_register_offsets, 2413: .probe = a6xx_hwsched_probe, 2414: .snapshot = a6xx_hwsched_snapshot, 2415: .irq_handler = a6xx_hwsched_irq_handler, 2416: .iommu_fault_block = a6xx_iommu_fault_block, 2417: .context_detach = a6xx_hwsched_context_detach, 2418: .read_alwayson = a6xx_read_alwayson, 2419: .reset = a6xx_hwsched_reset_replay, 2420: .power_ops = &a6xx_hwsched_power_ops, 2421: .power_stats = a6xx_power_stats, 2422: .hw_isidle = a6xx_hw_isidle, 2423: .add_to_va_minidump = a6xx_hwsched_add_to_minidump, 2424: .gx_is_on = a6xx_gmu_gx_is_on, 2425: .send_recurring_cmdobj = a6xx_hwsched_send_recurring_cmdobj, 2426: .set_isdb_breakpoint_registers = a6xx_set_isdb_breakpoint_registers, 2427: }, 2428: .hfi_probe = a6xx_hwsched_hfi_probe, 2429: .hfi_remove = a6xx_hwsched_hfi_remove, 2430: .handle_watchdog = a6xx_hwsched_handle_watchdog, 2431: }; 2432: 2433: const struct a6xx_gpudev adreno_a6xx_gmu_gpudev = { 2434: .base = { 2435: .reg_offsets = a6xx_register_offsets, 2436: .probe = a6xx_gmu_device_probe, 2437: .snapshot = a6xx_gmu_snapshot, 2438: .irq_handler = a6xx_irq_handler, 2439: .rb_start = a6xx_rb_start, 2440: .regulator_enable = a6xx_sptprac_enable, 2441: .regulator_disable = a6xx_sptprac_disable, 2442: .gpu_keepalive = a6xx_gpu_keepalive, 2443: .hw_isidle = a6xx_hw_isidle, 2444: .iommu_fault_block = a6xx_iommu_fault_block, 2445: .reset = a6xx_gmu_reset, 2446: .preemption_schedule = a6xx_preemption_schedule, 2447: .read_alwayson = a6xx_read_alwayson, 2448: .power_ops = &a6xx_gmu_power_ops, 2449: .remove = a6xx_remove, 2450: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2451: .power_stats = a6xx_power_stats, 2452: .add_to_va_minidump = a6xx_gmu_add_to_minidump, 2453: .gx_is_on = a6xx_gmu_gx_is_on, 2454: .set_isdb_breakpoint_registers = a6xx_set_isdb_breakpoint_registers, 2455: }, 2456: .hfi_probe = a6xx_gmu_hfi_probe, 2457: .handle_watchdog = a6xx_gmu_handle_watchdog, 2458: }; 2459: 2460: const struct adreno_gpudev adreno_a6xx_rgmu_gpudev = { 2461: .reg_offsets = a6xx_register_offsets, 2462: .probe = a6xx_rgmu_device_probe, 2463: .snapshot = a6xx_rgmu_snapshot, 2464: .irq_handler = a6xx_irq_handler, 2465: .rb_start = a6xx_rb_start, 2466: .regulator_enable = a6xx_sptprac_enable, 2467: .regulator_disable = a6xx_sptprac_disable, 2468: .gpu_keepalive = a6xx_gpu_keepalive, 2469: .hw_isidle = a6xx_hw_isidle, 2470: .iommu_fault_block = a6xx_iommu_fault_block, 2471: .reset = a6xx_rgmu_reset, 2472: .preemption_schedule = a6xx_preemption_schedule, 2473: .read_alwayson = a6xx_read_alwayson, 2474: .power_ops = &a6xx_rgmu_power_ops, 2475: .remove = a6xx_remove, 2476: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2477: .power_stats = a6xx_power_stats, 2478: .add_to_va_minidump = a6xx_rgmu_add_to_minidump, 2479: .gx_is_on = a6xx_rgmu_gx_is_on, 2480: }; 2481: 2482: /* This is a non GMU/RGMU part */ 2483: const struct adreno_gpudev adreno_a619_holi_gpudev = { 2484: .reg_offsets = a6xx_register_offsets, 2485: .probe = a6xx_probe, 2486: .start = a6xx_nogmu_start, 2487: .snapshot = a6xx_snapshot, 2488: .init = a6xx_nogmu_init, 2489: .irq_handler = a6xx_irq_handler, 2490: .rb_start = a6xx_rb_start, 2491: .regulator_enable = a619_holi_sptprac_enable, 2492: .regulator_disable = a619_holi_sptprac_disable, 2493: .gpu_keepalive = a6xx_gpu_keepalive, 2494: .hw_isidle = a619_holi_hw_isidle, 2495: .iommu_fault_block = a6xx_iommu_fault_block, 2496: .reset = a6xx_reset, 2497: .preemption_schedule = a6xx_preemption_schedule, 2498: .read_alwayson = a6xx_read_alwayson, 2499: .power_ops = &adreno_power_operations, 2500: .clear_pending_transactions = a6xx_clear_pending_transactions, 2501: .deassert_gbif_halt = a6xx_deassert_gbif_halt, 2502: .remove = a6xx_remove, 2503: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2504: .is_hw_collapsible = adreno_isidle, 2505: .power_stats = a6xx_power_stats, 2506: .add_to_va_minidump = a6xx_dev_add_to_minidump, 2507: .gx_is_on = a619_holi_gx_is_on, 2508: }; 2509: 2510: const struct a6xx_gpudev adreno_a630_gpudev = { 2511: .base = { 2512: .reg_offsets = a6xx_register_offsets, 2513: .probe = a6xx_gmu_device_probe, 2514: .snapshot = a6xx_gmu_snapshot, 2515: .irq_handler = a6xx_irq_handler, 2516: .rb_start = a6xx_rb_start, 2517: .regulator_enable = a6xx_sptprac_enable, 2518: .regulator_disable = a6xx_sptprac_disable, 2519: .gpu_keepalive = a6xx_gpu_keepalive, 2520: .hw_isidle = a6xx_hw_isidle, 2521: .iommu_fault_block = a6xx_iommu_fault_block, 2522: .reset = a6xx_gmu_reset, 2523: .preemption_schedule = a6xx_preemption_schedule, 2524: .read_alwayson = a6xx_read_alwayson, 2525: .power_ops = &a630_gmu_power_ops, 2526: .remove = a6xx_remove, 2527: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2528: .power_stats = a6xx_power_stats, 2529: .add_to_va_minidump = a6xx_gmu_add_to_minidump, 2530: .gx_is_on = a6xx_gmu_gx_is_on, 2531: }, 2532: .hfi_probe = a6xx_gmu_hfi_probe, 2533: .handle_watchdog = a6xx_gmu_handle_watchdog, 2534: }; --- FILE: \adreno_a6xx_gmu.c | HITS: 27 --- MATCH LINES: 978, 986, 990, 1011, 1014 966: clear = BIT(31 - req * 2); 967: if (req >= oob_boot_slumber) { 968: dev_err(GMU_PDEV_DEV(device), "Unsupported OOB clear %s\n", 969: oob_to_str(req)); 970: return; 971: } 972: } 973: 974: gmu_core_regwrite(device, A6XX_GMU_HOST2GMU_INTR_SET, clear); 975: trace_kgsl_gmu_oob_clear(clear); 976: } 977: 978: void a6xx_gmu_irq_enable(struct adreno_device *adreno_dev) 979: { 980: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 981: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 982: struct a6xx_hfi *hfi = &gmu->hfi; 983: 984: /* Clear pending IRQs and Unmask needed IRQs */ 985: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, 0xffffffff); 986: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_CLR, 0xffffffff); 987: 988: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_MASK, 989: (unsigned int)~HFI_IRQ_MASK); 990: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_MASK, 991: (unsigned int)~GMU_AO_INT_MASK); 992: 993: 994: /* Enable all IRQs on host */ 995: enable_irq(hfi->irq); 996: enable_irq(gmu->irq); 997: } 998: 999: void a6xx_gmu_irq_disable(struct adreno_device *adreno_dev) 1000: { 1001: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1002: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 1003: struct a6xx_hfi *hfi = &gmu->hfi; 1004: 1005: /* Disable all IRQs on host */ 1006: disable_irq(gmu->irq); 1007: disable_irq(hfi->irq); 1008: 1009: /* Mask all IRQs and clear pending IRQs */ 1010: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_MASK, 0xffffffff); 1011: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_MASK, 0xffffffff); 1012: 1013: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, 0xffffffff); 1014: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_CLR, 0xffffffff); 1015: 1016: } 1017: 1018: static int a6xx_gmu_hfi_start_msg(struct adreno_device *adreno_dev) 1019: { 1020: struct hfi_start_cmd req; 1021: 1022: /* 1023: * This HFI was not supported in legacy firmware and this quirk 1024: * serves as a better means to identify targets that depend on 1025: * legacy firmware. 1026: */ 1027: if (!ADRENO_QUIRK(adreno_dev, ADRENO_QUIRK_HFI_USE_REG)) { 1028: int ret; 1029: 1030: ret = CMD_MSG_HDR(req, H2F_MSG_START); 1031: if (ret) 1032: return ret; 1033: 1034: return a6xx_hfi_send_generic_req(adreno_dev, &req, sizeof(req)); 1035: } 1036: 1037: return 0; 1038: MATCH LINES: 1526, 1527, 1528, 1531 1514: /* Turn on TCM retention */ 1515: gmu_core_regwrite(device, A6XX_GMU_GENERAL_7, 1); 1516: 1517: /* Clear init result to make sure we are getting fresh value */ 1518: gmu_core_regwrite(device, A6XX_GMU_CM3_FW_INIT_RESULT, 0); 1519: gmu_core_regwrite(device, A6XX_GMU_CM3_BOOT_CONFIG, 0x2); 1520: 1521: gmu_core_regwrite(device, A6XX_GMU_HFI_QTBL_ADDR, 1522: gmu->hfi.hfi_mem->gmuaddr); 1523: gmu_core_regwrite(device, A6XX_GMU_HFI_QTBL_INFO, 1); 1524: 1525: /* 1526: * For A6xx GMUAO interrupt line BIT[1] is combined for ipcc 1527: * and doorbell. Enable dbdWakeupEn interrupt for GMU to receive 1528: * IPC interrupt. 1529: */ 1530: if (ADRENO_FEATURE(adreno_dev, ADRENO_LSR)) 1531: gmu_core_regwrite(device, A6XX_GMU_AO_INTERRUPT_EN, BIT(1)); 1532: 1533: gmu_core_regwrite(device, A6XX_GMU_AHB_FENCE_RANGE_0, 1534: GMU_FENCE_RANGE_MASK); 1535: 1536: /* 1537: * Make sure that CM3 state is at reset value. Snapshot is changing 1538: * NMI bit and if we boot up GMU with NMI bit set GMU will boot 1539: * straight in to NMI handler without executing __main code 1540: */ 1541: gmu_core_regwrite(device, A6XX_GMU_CM3_CFG, 0x4052); 1542: 1543: /** 1544: * We may have asserted gbif halt as part of reset sequence which may 1545: * not get cleared if the gdsc was not reset. So clear it before 1546: * attempting GMU boot. 1547: */ 1548: if (!adreno_is_a630(adreno_dev)) 1549: kgsl_regwrite(device, A6XX_GBIF_HALT, 0x0); 1550: 1551: /* Set vrb address before starting GMU */ 1552: if (!IS_ERR_OR_NULL(device->gmu_core.vrb)) 1553: gmu_core_regwrite(device, A6XX_GMU_GENERAL_11, device->gmu_core.vrb->gmuaddr); 1554: 1555: /* Set the log wptr index */ MATCH LINES: 2070, 2087, 2090 2058: if (a6xx_gmu_gx_is_on(adreno_dev) && adreno_smmu_is_stalled(adreno_dev)) { 2059: dev_err(GMU_PDEV_DEV(device), 2060: "Skipping NMI because SMMU is stalled\n"); 2061: goto done; 2062: } 2063: 2064: if (force) 2065: goto nmi; 2066: 2067: /* 2068: * We should not send NMI if there was a CM3 fault reported because we 2069: * don't want to overwrite the critical CM3 state captured by gmu before 2070: * it sent the CM3 fault interrupt. Also don't send NMI if GMU reset is 2071: * already active. We could have hit a GMU assert and NMI might have 2072: * already been triggered. 2073: */ 2074: 2075: /* make sure we're reading the latest cm3_fault */ 2076: smp_rmb(); 2077: 2078: if (atomic_read(&gmu->cm3_fault)) 2079: return; 2080: 2081: gmu_core_regread(device, A6XX_GMU_CM3_FW_INIT_RESULT, &val); 2082: 2083: if (val & 0xE00) 2084: return; 2085: 2086: nmi: 2087: /* Mask so there's no interrupt caused by NMI */ 2088: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_MASK, 0xFFFFFFFF); 2089: 2090: /* Make sure the interrupt is masked before causing it */ 2091: wmb(); 2092: if (ADRENO_QUIRK(adreno_dev, ADRENO_QUIRK_HFI_USE_REG)) 2093: gmu_core_regwrite(device, 2094: A6XX_GMU_NMI_CONTROL_STATUS, 0); 2095: 2096: /* This will cause the GMU to save it's internal state to ddr */ 2097: gmu_core_regread(device, A6XX_GMU_CM3_CFG, &val); 2098: val |= BIT(9); 2099: gmu_core_regwrite(device, A6XX_GMU_CM3_CFG, val); 2100: 2101: /* Make sure the NMI is invoked before we proceed*/ 2102: wmb(); 2103: 2104: /* Wait for the NMI to be handled */ 2105: udelay(200); 2106: 2107: done: 2108: KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic, GMU_PDEV(device), ticks, gf_policy); 2109: } 2110: 2111: static void a6xx_gmu_cooperative_reset(struct kgsl_device *device) 2112: { 2113: unsigned int result; 2114: MATCH LINES: 2174, 2175, 2177, 2183, 2186, 2194, 2195, 2197, 2202, 2209, 2214 2162: static bool a6xx_gmu_scales_bandwidth(struct kgsl_device *device) 2163: { 2164: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 2165: 2166: return (ADRENO_GPUREV(adreno_dev) >= ADRENO_REV_A640); 2167: } 2168: 2169: void a6xx_gmu_handle_watchdog(struct adreno_device *adreno_dev) 2170: { 2171: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2172: u32 mask; 2173: 2174: /* Temporarily mask the watchdog interrupt to prevent a storm */ 2175: gmu_core_regread(device, A6XX_GMU_AO_HOST_INTERRUPT_MASK, 2176: &mask); 2177: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_MASK, 2178: (mask | GMU_INT_WDOG_BITE)); 2179: 2180: a6xx_gmu_send_nmi(device, false, GMU_FAULT_PANIC_NONE); 2181: 2182: dev_err_ratelimited(GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)), 2183: "GMU watchdog expired interrupt received\n"); 2184: } 2185: 2186: static irqreturn_t a6xx_gmu_irq_handler(int irq, void *data) 2187: { 2188: struct kgsl_device *device = data; 2189: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 2190: const struct a6xx_gpudev *a6xx_gpudev = 2191: to_a6xx_gpudev(ADRENO_GPU_DEVICE(adreno_dev)); 2192: unsigned int status = 0; 2193: 2194: gmu_core_regread(device, A6XX_GMU_AO_HOST_INTERRUPT_STATUS, &status); 2195: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_CLR, status); 2196: 2197: /* Ignore GMU_INT_RSCC_COMP and GMU_INT_DBD WAKEUP interrupts */ 2198: if (status & GMU_INT_WDOG_BITE) 2199: a6xx_gpudev->handle_watchdog(adreno_dev); 2200: if (status & GMU_INT_HOST_AHB_BUS_ERR) 2201: dev_err_ratelimited(GMU_PDEV_DEV(device), 2202: "AHB bus error interrupt received\n"); 2203: if (status & GMU_INT_FENCE_ERR) { 2204: unsigned int fence_status; 2205: 2206: gmu_core_regread(device, A6XX_GMU_AHB_FENCE_STATUS, 2207: &fence_status); 2208: dev_err_ratelimited(GMU_PDEV_DEV(device), 2209: "FENCE error interrupt received %x\n", fence_status); 2210: } 2211: 2212: if (status & ~GMU_AO_INT_MASK) 2213: dev_err_ratelimited(GMU_PDEV_DEV(device), 2214: "Unhandled GMU interrupts 0x%lx\n", 2215: status & ~GMU_AO_INT_MASK); 2216: 2217: return IRQ_HANDLED; 2218: } 2219: 2220: void a6xx_gmu_snapshot(struct adreno_device *adreno_dev, 2221: struct kgsl_snapshot *snapshot) 2222: { 2223: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2224: 2225: a6xx_gmu_device_snapshot(device, snapshot); 2226: 2227: a6xx_snapshot(adreno_dev, snapshot); 2228: 2229: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, 2230: 0xffffffff); 2231: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_MASK, 2232: HFI_IRQ_MASK); 2233: 2234: } 2235: 2236: void a6xx_gmu_aop_send_acd_state(struct a6xx_gmu_device *gmu, bool flag) 2237: { 2238: struct kgsl_device *device = KGSL_DEVICE(a6xx_gmu_to_adreno(gmu)); MATCH LINES: 2325 2313: ret = a6xx_gmu_load_fw(adreno_dev); 2314: if (ret) 2315: goto clks_gdsc_off; 2316: 2317: ret = a6xx_gmu_itcm_shadow(adreno_dev); 2318: if (ret) 2319: goto clks_gdsc_off; 2320: 2321: a6xx_gmu_register_config(adreno_dev); 2322: 2323: a6xx_gmu_version_info(adreno_dev); 2324: 2325: a6xx_gmu_irq_enable(adreno_dev); 2326: 2327: /* Vote for minimal DDR BW for GMU to init */ 2328: level = pwr->pwrlevels[pwr->default_pwrlevel].bus_min; 2329: icc_set_bw(pwr->icc_path, 0, kBps_to_icc(pwr->ddr_table[level])); 2330: 2331: /* Clear any GPU faults that might have been left over */ 2332: adreno_clear_gpu_fault(adreno_dev); 2333: 2334: ret = a6xx_gmu_device_start(adreno_dev); 2335: if (ret) 2336: goto err; 2337: 2338: /* 2339: * Load PDC and RSC ucode before turning on 2340: * GFX rail. This avoids oob set timeout 2341: * for oob_boot_slumber request during 2342: * GMU first boot 2343: */ 2344: if (!test_bit(GMU_PRIV_PDC_RSC_LOADED, &gmu->flags)) { 2345: ret = a6xx_load_pdc_ucode(adreno_dev); 2346: if (ret) 2347: goto err; 2348: 2349: a6xx_load_rsc_ucode(adreno_dev); MATCH LINES: 2428 2416: goto gdsc_off; 2417: 2418: ret = a6xx_rscc_wakeup_sequence(adreno_dev); 2419: if (ret) 2420: goto clks_gdsc_off; 2421: 2422: ret = a6xx_gmu_load_fw(adreno_dev); 2423: if (ret) 2424: goto clks_gdsc_off; 2425: 2426: a6xx_gmu_register_config(adreno_dev); 2427: 2428: a6xx_gmu_irq_enable(adreno_dev); 2429: 2430: /* Clear any GPU faults that might have been left over */ 2431: adreno_clear_gpu_fault(adreno_dev); 2432: 2433: ret = a6xx_gmu_device_start(adreno_dev); 2434: if (ret) 2435: goto err; 2436: 2437: if (ADRENO_QUIRK(adreno_dev, ADRENO_QUIRK_HFI_USE_REG)) { 2438: ret = a6xx_gmu_gfx_rail_on(adreno_dev); 2439: if (ret) { 2440: a6xx_gmu_oob_clear(device, oob_boot_slumber); 2441: goto err; 2442: } 2443: } 2444: 2445: if (gmu->idle_level == GPU_HW_ACTIVE) { 2446: ret = a6xx_gmu_sptprac_enable(adreno_dev); 2447: if (ret) 2448: goto err; 2449: } 2450: 2451: ret = a6xx_gmu_hfi_start(adreno_dev); 2452: if (ret) MATCH LINES: 2801 2789: 2790: /* GMU sysfs nodes setup */ 2791: ret = kobject_init_and_add(&gmu->log_kobj, &log_kobj_type, &dev->kobj, "log"); 2792: if (ret) 2793: dev_err(dev, "Failed to add log_kobj: %d\n", ret); 2794: 2795: ret = kobject_init_and_add(&gmu->stats_kobj, &stats_kobj_type, &dev->kobj, "stats"); 2796: if (ret) 2797: dev_err(dev, "Failed to add stats_kobj: %d\n", ret); 2798: 2799: /* Try with "gmu" irq first. Use Fallback legacy name "kgsl_gmu_irq" if not found. */ 2800: gmu->irq = kgsl_request_irq(GMU_PDEV(device), "gmu", "kgsl_gmu_irq", -EINVAL, 2801: a6xx_gmu_irq_handler, device); 2802: 2803: if (gmu->irq >= 0) 2804: return 0; 2805: 2806: ret = gmu->irq; 2807: 2808: error: 2809: a6xx_gmu_remove(device); 2810: return ret; 2811: } 2812: 2813: int a6xx_halt_gbif(struct adreno_device *adreno_dev) 2814: { 2815: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2816: int ret; 2817: 2818: /* Halt new client requests */ 2819: kgsl_regwrite(device, A6XX_GBIF_HALT, A6XX_GBIF_CLIENT_HALT_MASK); 2820: ret = adreno_wait_for_halt_ack(device, 2821: A6XX_GBIF_HALT_ACK, A6XX_GBIF_CLIENT_HALT_MASK); 2822: 2823: /* Halt all AXI requests */ 2824: kgsl_regwrite(device, A6XX_GBIF_HALT, A6XX_GBIF_ARB_HALT_MASK); 2825: ret = adreno_wait_for_halt_ack(device, MATCH LINES: 3508 3496: /* Attempt to reboot the gmu and gpu */ 3497: return a6xx_boot(adreno_dev); 3498: } 3499: 3500: int a6xx_gmu_hfi_probe(struct adreno_device *adreno_dev) 3501: { 3502: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 3503: struct a6xx_hfi *hfi = &gmu->hfi; 3504: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3505: 3506: /* Try with "hfi" irq first. Use Fallback legacy name "kgsl_hfi_irq" if not found. */ 3507: hfi->irq = kgsl_request_irq(GMU_PDEV(device), "hfi", "kgsl_hfi_irq", -EINVAL, 3508: a6xx_hfi_irq_handler, KGSL_DEVICE(adreno_dev)); 3509: 3510: return hfi->irq < 0 ? hfi->irq : 0; 3511: } 3512: 3513: int a6xx_gmu_add_to_minidump(struct adreno_device *adreno_dev) 3514: { 3515: struct a6xx_device *a6xx_dev = container_of(adreno_dev, 3516: struct a6xx_device, adreno_dev); 3517: int ret; 3518: 3519: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, KGSL_A6XX_DEVICE, 3520: (void *)(a6xx_dev), sizeof(struct a6xx_device)); 3521: if (ret) 3522: return ret; 3523: 3524: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, KGSL_GMU_LOG_ENTRY, 3525: a6xx_dev->gmu.gmu_log->hostptr, a6xx_dev->gmu.gmu_log->size); 3526: if (ret) 3527: return ret; 3528: 3529: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, KGSL_HFIMEM_ENTRY, 3530: a6xx_dev->gmu.hfi.hfi_mem->hostptr, a6xx_dev->gmu.hfi.hfi_mem->size); 3531: if (ret) 3532: return ret; --- FILE: \adreno_a6xx_gmu.h | HITS: 8 --- MATCH LINES: 17, 38 5: */ 6: #ifndef __ADRENO_A6XX_GMU_H 7: #define __ADRENO_A6XX_GMU_H 8: 9: #include 10: #include 11: 12: #include "adreno_a6xx_hfi.h" 13: #include "kgsl_gmu_core.h" 14: 15: /** 16: * struct a6xx_gmu_device - GMU device structure 17: * @irq: GMU interrupt number 18: * @fw_image: GMU FW image 19: * @dump_mem: pointer to GMU debug dump memory 20: * @gmu_log: gmu event log memory 21: * @hfi: HFI controller 22: * @idle_level: Minimal GPU idle power level 23: * @mailbox: Messages to AOP for ACD enable/disable go through this 24: * @log_wptr_retention: Store the log wptr offset on slumber 25: */ 26: struct a6xx_gmu_device { 27: int irq; 28: const struct firmware *fw_image; 29: struct kgsl_memdesc *dump_mem; 30: struct kgsl_memdesc *gmu_log; 31: struct a6xx_hfi hfi; 32: unsigned int idle_level; 33: /** @qmp: Pointer to qmp struct used for AOP messages*/ 34: struct qmp *qmp; 35: struct kgsl_mailbox mailbox; 36: bool preallocations; 37: unsigned int log_wptr_retention; 38: /** @cm3_fault: whether gmu received a cm3 fault interrupt */ 39: atomic_t cm3_fault; 40: /** 41: * @itcm_shadow: Copy of the itcm block in firmware binary used for 42: * snapshot 43: */ 44: void *itcm_shadow; 45: /** @flags: Internal gmu flags */ 46: unsigned long flags; 47: /** @rscc_virt: Pointer where RSCC block is mapped */ 48: void __iomem *rscc_virt; 49: /** @log_stream_enable: GMU log streaming enable. Disabled by default */ 50: bool log_stream_enable; 51: /** @log_group_mask: Allows overriding default GMU log group mask */ 52: u32 log_group_mask; 53: struct kobject log_kobj; 54: /** @num_oob_perfcntr: Number of active oob_perfcntr requests */ 55: u32 num_oob_perfcntr; 56: /** @pdc_cfg_base: Base address of PDC cfg registers */ 57: void __iomem *pdc_cfg_base; 58: /** @pdc_seq_base: Base address of PDC seq registers */ 59: void __iomem *pdc_seq_base; 60: /** @stats_enable: GMU stats feature enable */ 61: bool stats_enable; 62: /** @stats_mask: GMU performance countables to enable */ MATCH LINES: 126, 132 114: int a6xx_gmu_device_probe(struct platform_device *pdev, 115: u32 chipid, const struct adreno_gpu_core *gpucore); 116: 117: /** 118: * a6xx_gmu_reset - Reset and restart the gmu 119: * @adreno_dev: Pointer to the adreno device 120: * 121: * Return: 0 on success or negative error on failure 122: */ 123: int a6xx_gmu_reset(struct adreno_device *adreno_dev); 124: 125: /** 126: * a6xx_enable_gpu_irq - Enable gpu interrupt 127: * @adreno_dev: Pointer to the adreno device 128: */ 129: void a6xx_enable_gpu_irq(struct adreno_device *adreno_dev); 130: 131: /** 132: * a6xx_disable_gpu_irq - Disable gpu interrupt 133: * @adreno_dev: Pointer to the adreno device 134: */ 135: void a6xx_disable_gpu_irq(struct adreno_device *adreno_dev); 136: 137: /** 138: * a6xx_gmu_snapshot- Take snapshot for gmu targets 139: * @adreno_dev: Pointer to the adreno device 140: * @snapshot: Pointer to the snapshot structure 141: * 142: * Send an NMI to gmu if we hit a gmu fault. Then take gmu 143: * snapshot and carry on with rest of the a6xx snapshot 144: */ 145: void a6xx_gmu_snapshot(struct adreno_device *adreno_dev, 146: struct kgsl_snapshot *snapshot); 147: 148: /** 149: * a6xx_gmu_probe - Probe a6xx gmu resources 150: * @device: Pointer to the kgsl device 151: * @pdev: Pointer to the gmu platform device 152: * 153: * Probe the gmu and hfi resources 154: * 155: * Return: 0 on success or negative error on failure 156: */ MATCH LINES: 242, 245, 248 230: * 231: * Program gmu regsiters based on features 232: */ 233: void a6xx_gmu_register_config(struct adreno_device *adreno_dev); 234: 235: /** 236: * a6xx_gmu_version_info - Get gmu firmware version 237: * @adreno_dev: Pointer to the adreno device 238: */ 239: void a6xx_gmu_version_info(struct adreno_device *adreno_dev); 240: 241: /** 242: * a6xx_gmu_irq_enable - Enable gmu interrupts 243: * @adreno_dev: Pointer to the adreno device 244: */ 245: void a6xx_gmu_irq_enable(struct adreno_device *adreno_dev); 246: 247: /** 248: * a6xx_gmu_irq_disable - Disaable gmu interrupts 249: * @adreno_dev: Pointer to the adreno device 250: */ 251: void a6xx_gmu_irq_disable(struct adreno_device *adreno_dev); 252: 253: /** 254: * a6xx_gmu_suspend - Hard reset the gpu and gmu 255: * @adreno_dev: Pointer to the adreno device 256: * @force: Set to true to enforce a hard reset 257: * 258: * In case we hit a gmu fault, hard reset the gpu and gmu 259: * to recover from the fault 260: */ 261: void a6xx_gmu_suspend(struct adreno_device *adreno_dev, bool force); 262: 263: /** 264: * a6xx_gmu_oob_set - send gmu oob request 265: * @device: Pointer to the kgsl device 266: * @req: Type of oob request as defined in enum oob_request 267: * 268: * Request gmu to keep gpu powered up till the oob is cleared 269: * 270: * Return: 0 on success or negative error on failure 271: */ 272: int a6xx_gmu_oob_set(struct kgsl_device *device, enum oob_request oob); MATCH LINES: 350 338: * a6xx_load_rsc_ucode - Load rscc sequence 339: * @adreno_dev: Pointer to the adreno device 340: */ 341: void a6xx_load_rsc_ucode(struct adreno_device *adreno_dev); 342: 343: /** 344: * a6xx_gmu_remove - Clean up gmu probed resources 345: * @device: Pointer to the kgsl device 346: */ 347: void a6xx_gmu_remove(struct kgsl_device *device); 348: 349: /** 350: * a6xx_gmu_handle_watchdog - Handle watchdog interrupt 351: * @adreno_dev: Pointer to the adreno device 352: */ 353: void a6xx_gmu_handle_watchdog(struct adreno_device *adreno_dev); 354: 355: /** 356: * a6xx_gmu_send_nmi - Send NMI to GMU 357: * @device: Pointer to the kgsl device 358: * @gf_policy: GMU fault panic setting policy 359: * @force: Boolean to forcefully send NMI irrespective of GMU state 360: */ 361: void a6xx_gmu_send_nmi(struct kgsl_device *device, bool force, 362: enum gmu_fault_panic_policy gf_policy); 363: 364: /** 365: * a6xx_gmu_add_to_minidump - Register a6xx_device with va minidump 366: * @adreno_dev: Pointer to the adreno device 367: */ 368: int a6xx_gmu_add_to_minidump(struct adreno_device *adreno_dev); 369: 370: #endif --- FILE: \adreno_a6xx_hfi.c | HITS: 7 --- MATCH LINES: 156, 160 144: 145: return 0; 146: } 147: 148: int a6xx_hfi_cmdq_write(struct adreno_device *adreno_dev, u32 *msg, u32 size_bytes) 149: { 150: int ret; 151: 152: ret = a6xx_hfi_queue_write(adreno_dev, HFI_CMD_ID, msg, size_bytes); 153: 154: /* 155: * Memory barrier to make sure packet and write index are written before 156: * an interrupt is raised 157: */ 158: wmb(); 159: 160: /* Send interrupt to GMU to receive the message */ 161: if (!ret) 162: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), 163: A6XX_GMU_HOST2GMU_INTR_SET, 164: 0x1); 165: 166: return ret; 167: } 168: 169: /* Sizes of the queue and message are in unit of dwords */ 170: static void init_queues(struct adreno_device *adreno_dev) 171: { 172: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 173: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 174: int i; 175: struct hfi_queue_table *tbl; 176: struct hfi_queue_header *hdr; 177: struct { 178: unsigned int idx; 179: unsigned int pri; 180: unsigned int status; 181: } queue[HFI_QUEUE_MAX] = { 182: { HFI_CMD_IDX, HFI_CMD_PRI, HFI_QUEUE_STATUS_ENABLED }, 183: { HFI_MSG_IDX, HFI_MSG_PRI, HFI_QUEUE_STATUS_ENABLED }, 184: { HFI_DBG_IDX, HFI_DBG_PRI, HFI_QUEUE_STATUS_ENABLED }, MATCH LINES: 293 281: 282: rc = gmu_core_timed_poll_check(device, A6XX_GMU_GMU2HOST_INTR_INFO, 283: HFI_IRQ_MSGQ_MASK, HFI_RSP_TIMEOUT, HFI_IRQ_MSGQ_MASK); 284: 285: if (rc) { 286: dev_err(GMU_PDEV_DEV(device), 287: "Timed out waiting on ack for 0x%8.8x (id %d, sequence %d)\n", 288: cmd[0], MSG_HDR_GET_ID(*cmd), MSG_HDR_GET_SEQNUM(*cmd)); 289: gmu_core_fault_snapshot(device, GMU_FAULT_SEND_CMD_WAIT_INLINE); 290: return rc; 291: } 292: 293: /* Clear the interrupt */ 294: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, 295: HFI_IRQ_MSGQ_MASK); 296: 297: rc = a6xx_hfi_process_queue(gmu, HFI_MSG_ID, ret_cmd); 298: 299: return rc; 300: } 301: 302: int a6xx_hfi_send_generic_req(struct adreno_device *adreno_dev, void *cmd, u32 size_bytes) 303: { 304: struct pending_cmd ret_cmd; 305: int rc; 306: 307: memset(&ret_cmd, 0, sizeof(ret_cmd)); 308: 309: rc = a6xx_hfi_send_cmd_wait_inline(adreno_dev, cmd, size_bytes, &ret_cmd); 310: if (rc) 311: return rc; 312: 313: if (ret_cmd.results[2]) { 314: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 315: 316: dev_err(GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)), 317: "HFI ACK failure: Req=0x%8.8X, Result=0x%8.8X\n", MATCH LINES: 765, 766, 779, 787 753: } 754: 755: void a6xx_hfi_stop(struct adreno_device *adreno_dev) 756: { 757: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 758: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 759: 760: kgsl_pwrctrl_axi(device, false); 761: 762: clear_bit(GMU_PRIV_HFI_STARTED, &gmu->flags); 763: } 764: 765: /* HFI interrupt handler */ 766: irqreturn_t a6xx_hfi_irq_handler(int irq, void *data) 767: { 768: struct kgsl_device *device = data; 769: struct a6xx_gmu_device *gmu = to_a6xx_gmu(ADRENO_DEVICE(device)); 770: unsigned int status = 0; 771: 772: gmu_core_regread(device, A6XX_GMU_GMU2HOST_INTR_INFO, &status); 773: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, HFI_IRQ_MASK); 774: 775: if (status & HFI_IRQ_DBGQ_MASK) 776: a6xx_hfi_process_queue(gmu, HFI_DBG_ID, NULL); 777: if (status & HFI_IRQ_CM3_FAULT_MASK) { 778: dev_err_ratelimited(GMU_PDEV_DEV(device), 779: "GMU CM3 fault interrupt received\n"); 780: atomic_set(&gmu->cm3_fault, 1); 781: 782: /* make sure other CPUs see the update */ 783: smp_wmb(); 784: } 785: if (status & ~HFI_IRQ_MASK) 786: dev_err_ratelimited(GMU_PDEV_DEV(device), 787: "Unhandled HFI interrupts 0x%lx\n", 788: status & ~HFI_IRQ_MASK); 789: 790: return IRQ_HANDLED; 791: } --- FILE: \adreno_a6xx_hfi.h | HITS: 3 --- MATCH LINES: 19, 32, 33 7: #define __ADRENO_A6XX_HFI_H 8: 9: #include "adreno_hfi.h" 10: 11: /** 12: * struct a6xx_hfi - HFI control structure 13: * @seqnum: atomic counter that is incremented for each message sent. The 14: * value of the counter is used as sequence number for HFI message 15: * @bw_table: HFI BW table buffer 16: * @acd_table: HFI table for ACD data 17: */ 18: struct a6xx_hfi { 19: /** @irq: HFI interrupt line */ 20: int irq; 21: atomic_t seqnum; 22: /** @hfi_mem: Memory descriptor for the hfi memory */ 23: struct kgsl_memdesc *hfi_mem; 24: struct hfi_bwtable_cmd bw_table; 25: struct hfi_acd_table_cmd acd_table; 26: /** @dcvs_table: HFI table for gpu dcvs levels */ 27: struct hfi_dcvstable_cmd dcvs_table; 28: }; 29: 30: struct a6xx_gmu_device; 31: 32: /* a6xx_hfi_irq_handler - IRQ handler for HFI interripts */ 33: irqreturn_t a6xx_hfi_irq_handler(int irq, void *data); 34: 35: /** 36: * a6xx_hfi_start - Send the various HFIs during device boot up 37: * @adreno_dev: Pointer to the adreno device 38: * 39: * Return: 0 on success or negative error on failure 40: */ 41: int a6xx_hfi_start(struct adreno_device *adreno_dev); 42: 43: /** 44: * a6xx_hfi_start - Send the various HFIs during device boot up 45: * @adreno_dev: Pointer to the adreno device 46: * 47: * Return: 0 on success or negative error on failure 48: */ 49: void a6xx_hfi_stop(struct adreno_device *adreno_dev); 50: 51: /** 52: * a6xx_hfi_init - Initialize hfi resources 53: * @adreno_dev: Pointer to the adreno device 54: * 55: * This function allocates and sets up hfi queues 56: * when a process creates the very first kgsl instance 57: * --- FILE: \adreno_a6xx_hwsched.c | HITS: 6 --- MATCH LINES: 135 123: 124: a6xx_load_rsc_ucode(adreno_dev); 125: set_bit(GMU_PRIV_PDC_RSC_LOADED, &gmu->flags); 126: } 127: 128: a6xx_gmu_register_config(adreno_dev); 129: 130: a6xx_gmu_version_info(adreno_dev); 131: 132: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2) 133: set_bit(ADRENO_HWSCHED_CTX_BAD_LEGACY, &adreno_dev->hwsched.flags); 134: 135: a6xx_gmu_irq_enable(adreno_dev); 136: 137: /* Vote for minimal DDR BW for GMU to init */ 138: level = pwr->pwrlevels[pwr->default_pwrlevel].bus_min; 139: 140: icc_set_bw(pwr->icc_path, 0, kBps_to_icc(pwr->ddr_table[level])); 141: 142: /* Clear any hwsched faults that might have been left over */ 143: adreno_clear_gpu_fault(adreno_dev); 144: 145: ret = a6xx_gmu_device_start(adreno_dev); 146: if (ret) 147: goto err; 148: 149: ret = a6xx_hwsched_hfi_start(adreno_dev); 150: if (ret) 151: goto err; 152: 153: /* Switch to min GMU clock */ 154: ret = gmu_core_clock_set_rate(device, 0); 155: if (ret) { 156: a6xx_hwsched_hfi_stop(adreno_dev); 157: goto err; 158: } 159: MATCH LINES: 214 202: goto gdsc_off; 203: 204: ret = a6xx_rscc_wakeup_sequence(adreno_dev); 205: if (ret) 206: goto clks_gdsc_off; 207: 208: ret = a6xx_gmu_load_fw(adreno_dev); 209: if (ret) 210: goto clks_gdsc_off; 211: 212: a6xx_gmu_register_config(adreno_dev); 213: 214: a6xx_gmu_irq_enable(adreno_dev); 215: 216: /* Clear any hwsched faults that might have been left over */ 217: adreno_clear_gpu_fault(adreno_dev); 218: 219: ret = a6xx_gmu_device_start(adreno_dev); 220: if (ret) 221: goto err; 222: 223: ret = a6xx_hwsched_hfi_start(adreno_dev); 224: if (ret) 225: goto err; 226: 227: /* Switch to min GMU clock */ 228: ret = gmu_core_clock_set_rate(device, 0); 229: if (ret) { 230: a6xx_hwsched_hfi_stop(adreno_dev); 231: goto err; 232: } 233: 234: device->gmu_fault = false; 235: 236: kgsl_pwrctrl_set_state(device, KGSL_STATE_AWARE); 237: 238: return 0; MATCH LINES: 885, 886, 888, 894 873: 874: err: 875: adreno_hwsched_start(adreno_dev); 876: 877: return ret; 878: } 879: 880: void a6xx_hwsched_handle_watchdog(struct adreno_device *adreno_dev) 881: { 882: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 883: u32 mask; 884: 885: /* Temporarily mask the watchdog interrupt to prevent a storm */ 886: gmu_core_regread(device, A6XX_GMU_AO_HOST_INTERRUPT_MASK, 887: &mask); 888: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_MASK, 889: (mask | GMU_INT_WDOG_BITE)); 890: 891: a6xx_gmu_send_nmi(device, false, GMU_FAULT_PANIC_NONE); 892: 893: dev_err_ratelimited(GMU_PDEV_DEV(device), 894: "GMU watchdog expired interrupt received\n"); 895: 896: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 897: } 898: 899: static void a6xx_hwsched_pm_resume(struct adreno_device *adreno_dev) 900: { 901: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 902: 903: if (WARN(!test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags), 904: "resume invoked without a suspend\n")) 905: return; 906: 907: adreno_put_gpu_halt(adreno_dev); 908: 909: adreno_hwsched_start(adreno_dev); 910: 911: clear_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags); 912: } 913: 914: static void a6xx_hwsched_drain_ctxt_unregister(struct adreno_device *adreno_dev) 915: { 916: struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev); 917: struct pending_cmd *cmd = NULL; 918: --- FILE: \adreno_a6xx_hwsched.h | HITS: 2 --- MATCH LINES: 56, 73 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: * 72: * This function is used to register the context if needed and submit 73: * recurring IBs to the GMU. Upon receiving ipc interrupt GMU will submit 74: * recurring IBs to GPU. 75: 76: * Return: 0 on success and negative error on failure 77: */ 78: int a6xx_hwsched_send_recurring_cmdobj(struct adreno_device *adreno_dev, 79: struct kgsl_drawobj_cmd *cmdobj); 80: #endif --- FILE: \adreno_a6xx_hwsched_hfi.c | HITS: 17 --- MATCH LINES: 180, 198 168: struct hfi_context_bad_cmd_legacy *cmd = adreno_dev->hwsched.ctxt_bad; 169: 170: switch (cmd->error) { 171: case GMU_GPU_HW_HANG: 172: dev_crit_ratelimited(gmu_pdev_dev, "MISC: GPU hang detected\n"); 173: break; 174: case GMU_GPU_SW_HANG: 175: dev_crit_ratelimited(gmu_pdev_dev, "gpu timeout ctx %u ts %u\n", 176: cmd->ctxt_id, cmd->ts); 177: break; 178: case GMU_CP_OPCODE_ERROR: 179: dev_crit_ratelimited(gmu_pdev_dev, 180: "CP opcode error interrupt | opcode=0x%8.8x\n", 181: a6xx_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 182: KEY_CP_OPCODE_ERROR)); 183: break; 184: case GMU_CP_PROTECTED_ERROR: { 185: u32 status = a6xx_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 186: KEY_CP_PROTECTED_ERROR); 187: 188: dev_crit_ratelimited(gmu_pdev_dev, 189: "CP | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 190: status & (1 << 20) ? "READ" : "WRITE", 191: status & 0x3FFFF, status); 192: } 193: break; 194: case GMU_CP_ILLEGAL_INST_ERROR: 195: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 196: break; 197: case GMU_CP_UCODE_ERROR: 198: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 199: break; 200: case GMU_CP_HW_FAULT_ERROR: 201: dev_crit_ratelimited(gmu_pdev_dev, 202: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 203: a6xx_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 204: KEY_CP_HW_FAULT)); 205: break; 206: case GMU_GPU_PREEMPT_TIMEOUT: { 207: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 208: 209: cur = a6xx_hwsched_lookup_key_value_legacy(adreno_dev, 210: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 211: next = a6xx_hwsched_lookup_key_value_legacy(adreno_dev, 212: PAYLOAD_PREEMPT_TIMEOUT, 213: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 214: cur_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_RPTR); 215: cur_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_WPTR); 216: next_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_RPTR); 217: next_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_WPTR); 218: 219: dev_crit_ratelimited(gmu_pdev_dev, 220: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 221: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 222: } MATCH LINES: 277, 295 265: struct hfi_context_bad_cmd *cmd = adreno_dev->hwsched.ctxt_bad; 266: 267: switch (cmd->error) { 268: case GMU_GPU_HW_HANG: 269: dev_crit_ratelimited(gmu_pdev_dev, "MISC: GPU hang detected\n"); 270: break; 271: case GMU_GPU_SW_HANG: 272: dev_crit_ratelimited(gmu_pdev_dev, "gpu timeout ctx %u ts %u\n", 273: cmd->gc.ctxt_id, cmd->gc.ts); 274: break; 275: case GMU_CP_OPCODE_ERROR: 276: dev_crit_ratelimited(gmu_pdev_dev, 277: "CP opcode error interrupt | opcode=0x%8.8x\n", 278: a6xx_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 279: KEY_CP_OPCODE_ERROR)); 280: break; 281: case GMU_CP_PROTECTED_ERROR: { 282: u32 status = a6xx_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 283: KEY_CP_PROTECTED_ERROR); 284: 285: dev_crit_ratelimited(gmu_pdev_dev, 286: "CP | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 287: status & (1 << 20) ? "READ" : "WRITE", 288: status & 0x3FFFF, status); 289: } 290: break; 291: case GMU_CP_ILLEGAL_INST_ERROR: 292: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 293: break; 294: case GMU_CP_UCODE_ERROR: 295: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 296: break; 297: case GMU_CP_HW_FAULT_ERROR: 298: dev_crit_ratelimited(gmu_pdev_dev, 299: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 300: a6xx_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 301: KEY_CP_HW_FAULT)); 302: break; 303: case GMU_GPU_PREEMPT_TIMEOUT: { 304: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 305: 306: cur = a6xx_hwsched_lookup_key_value(adreno_dev, 307: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 308: next = a6xx_hwsched_lookup_key_value(adreno_dev, 309: PAYLOAD_PREEMPT_TIMEOUT, 310: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 311: cur_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_RPTR); 312: cur_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_WPTR); 313: next_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_RPTR); 314: next_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_WPTR); 315: 316: dev_crit_ratelimited(gmu_pdev_dev, 317: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 318: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 319: } MATCH LINES: 458, 459, 475, 483, 493, 503 446: 447: /* Process one debug queue message and return to not delay msgq processing */ 448: if (limited) 449: break; 450: } 451: 452: if (!recovery) 453: return; 454: 455: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 456: } 457: 458: /* HFI interrupt handler */ 459: static irqreturn_t a6xx_hwsched_hfi_handler(int irq, void *data) 460: { 461: struct adreno_device *adreno_dev = data; 462: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 463: struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev); 464: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 465: u32 status = 0; 466: 467: /* 468: * A6XX_GMU_GMU2HOST_INTR_INFO may have bits set not specified in hfi->irq_mask. 469: * Read and clear only those irq bits that we are processing here. 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); 517: 518: if (ack->results[2] != 0xffffffff) 519: return 0; 520: 521: dev_err(GMU_PDEV_DEV(device), 522: "ACK error: sender id %d seqnum %d\n", 523: MSG_HDR_GET_ID(ack->sent_hdr), 524: MSG_HDR_GET_SEQNUM(ack->sent_hdr)); 525: 526: KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic, 527: GMU_PDEV(device), ticks, GMU_FAULT_HFI_ACK); MATCH LINES: 773, 776, 777, 809 761: MSG_HDR_GET_ID(rcvd[0]), 762: MSG_HDR_GET_TYPE(rcvd[0])); 763: gmu_core_fault_snapshot(device, GMU_FAULT_H2F_MSG_START); 764: rc = -EINVAL; 765: goto done; 766: } 767: } 768: 769: if (!rc) 770: goto poll; 771: 772: done: 773: /* Clear the interrupt */ 774: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, HFI_IRQ_MSGQ_MASK); 775: /* 776: * Add a write barrier to post the interrupt clear so that we dont have a 777: * pending interrupt. 778: */ 779: wmb(); 780: return rc; 781: } 782: 783: static void reset_hfi_queues(struct adreno_device *adreno_dev) 784: { 785: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 786: struct hfi_queue_table *tbl = gmu->hfi.hfi_mem->hostptr; 787: u32 i; 788: 789: /* Flush HFI queues */ 790: for (i = 0; i < HFI_QUEUE_MAX; i++) { 791: struct hfi_queue_header *hdr = &tbl->qhdr[i]; 792: 793: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 794: continue; 795: 796: hdr->read_index = hdr->write_index; 797: } 798: } 799: 800: void a6xx_hwsched_hfi_stop(struct adreno_device *adreno_dev) 801: { 802: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 803: struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev); 804: 805: hfi->irq_mask &= ~HFI_IRQ_MSGQ_MASK; 806: 807: /* 808: * In some corner cases, it is possible that GMU put TS_RETIRE 809: * on the msgq after we have turned off gmu interrupts. Hence, 810: * drain the queue one last time before we reset HFI queues. 811: */ 812: a6xx_hwsched_process_msgq(adreno_dev); 813: 814: /* Drain the debug queue before we reset HFI queues */ 815: a6xx_hwsched_process_dbgq(adreno_dev, false); 816: 817: kgsl_pwrctrl_axi(KGSL_DEVICE(adreno_dev), false); 818: 819: clear_bit(GMU_PRIV_HFI_STARTED, &gmu->flags); 820: } 821: 822: static void enable_async_hfi(struct adreno_device *adreno_dev) 823: { 824: struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev); 825: 826: hfi->irq_mask |= HFI_IRQ_MSGQ_MASK; 827: 828: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), A6XX_GMU_GMU2HOST_INTR_MASK, 829: (u32)~hfi->irq_mask); 830: } 831: 832: static int enable_preemption(struct adreno_device *adreno_dev) 833: { MATCH LINES: 1127 1115: cmd.submit_cmd.ts = ++ts; 1116: cmd.submit_cmd.numibs = 1; 1117: 1118: cmd.issue_ib.addr = gpuaddr; 1119: cmd.issue_ib.size = size; 1120: 1121: seqnum = atomic_inc_return(&adreno_dev->hwsched.submission_seqnum); 1122: cmd.submit_cmd.hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_CMD, HFI_MSG_CMD); 1123: cmd.submit_cmd.hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd.submit_cmd.hdr, seqnum, cmd_size >> 2); 1124: 1125: ret = a6xx_hfi_dispatch_queue_write(adreno_dev, HFI_DSP_ID_0, 1126: (u32 *)&cmd, cmd_size, NULL, NULL); 1127: /* Send interrupt to GMU to receive the message */ 1128: if (!ret) 1129: gmu_core_regwrite(device, A6XX_GMU_HOST2GMU_INTR_SET, DISPQ_IRQ_BIT(0)); 1130: 1131: return ret; 1132: } 1133: 1134: int a6xx_hwsched_counter_inline_enable(struct adreno_device *adreno_dev, 1135: const struct adreno_perfcount_group *group, 1136: u32 counter, u32 countable) 1137: { 1138: struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev); 1139: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1140: struct adreno_perfcount_register *reg = &group->regs[counter]; 1141: u32 val, *cmds, count = 0; 1142: int ret; 1143: 1144: ret = register_global_ctxt(adreno_dev); 1145: if (ret) 1146: goto err; 1147: 1148: ret = adreno_allocate_global(device, &hfi->perfctr_scratch, 1149: PAGE_SIZE, 0, KGSL_MEMFLAGS_GPUREADONLY, 0, "perfctr_scratch"); 1150: if (ret) 1151: goto err; MATCH LINES: 1203 1191: return true; 1192: 1193: return false; 1194: } 1195: 1196: static int hfi_f2h_main(void *arg) 1197: { 1198: struct adreno_device *adreno_dev = arg; 1199: struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev); 1200: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1201: 1202: while (!kthread_should_stop()) { 1203: wait_event_interruptible(hfi->f2h_wq, kthread_should_stop() || 1204: /* If msgq irq is enabled and msgq has messages to process */ 1205: (((hfi->irq_mask & HFI_IRQ_MSGQ_MASK) && 1206: !is_queue_empty(adreno_dev, HFI_MSG_ID)) || 1207: /* Trace buffer has messages to process */ 1208: !gmu_core_is_trace_empty(device->gmu_core.trace.md->hostptr) || 1209: /* Dbgq has messages to process */ 1210: !is_queue_empty(adreno_dev, HFI_DBG_ID))); 1211: 1212: if (kthread_should_stop()) 1213: break; 1214: 1215: a6xx_hwsched_process_msgq(adreno_dev); 1216: gmu_core_process_trace_data(device, 1217: GMU_PDEV_DEV(device), &device->gmu_core.trace); 1218: a6xx_hwsched_process_dbgq(adreno_dev, true); 1219: } 1220: 1221: return 0; 1222: } 1223: 1224: int a6xx_hwsched_hfi_probe(struct adreno_device *adreno_dev) 1225: { 1226: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 1227: struct a6xx_hwsched_hfi *hw_hfi = to_a6xx_hwsched_hfi(adreno_dev); MATCH LINES: 1543 1531: adreno_drawobj_set_constraint(KGSL_DEVICE(adreno_dev), drawobj); 1532: 1533: seqnum = atomic_inc_return(&adreno_dev->hwsched.submission_seqnum); 1534: cmd->hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_CMD, HFI_MSG_CMD); 1535: cmd->hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd->hdr, seqnum, cmd_sizebytes >> 2); 1536: 1537: ret = a6xx_hfi_dispatch_queue_write(adreno_dev, 1538: HFI_DSP_ID_0 + drawobj->context->gmu_dispatch_queue, 1539: (u32 *)cmd, cmd_sizebytes, cmdobj, &time); 1540: if (ret) 1541: return ret; 1542: 1543: /* Send interrupt to GMU to receive the message */ 1544: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), A6XX_GMU_HOST2GMU_INTR_SET, 1545: DISPQ_IRQ_BIT(drawobj->context->gmu_dispatch_queue)); 1546: 1547: drawctxt->internal_timestamp = drawobj->timestamp; 1548: 1549: return ret; 1550: } 1551: 1552: int a6xx_hwsched_send_recurring_cmdobj(struct adreno_device *adreno_dev, 1553: struct kgsl_drawobj_cmd *cmdobj) 1554: { 1555: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1556: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 1557: struct hfi_submit_cmd *cmd; 1558: struct kgsl_memobj_node *ib; 1559: u32 cmd_sizebytes; 1560: int ret; 1561: static bool active; 1562: 1563: if (adreno_gpu_halt(adreno_dev) || adreno_gpu_fault(adreno_dev)) 1564: return -EBUSY; 1565: 1566: if (test_bit(CMDOBJ_RECURRING_STOP, &cmdobj->priv)) { 1567: cmdobj->numibs = 0; --- FILE: \adreno_a6xx_hwsched_hfi.h | HITS: 1 --- MATCH LINES: 11 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #ifndef _ADRENO_A6XX_HWSCHED_HFI_H_ 8: #define _ADRENO_A6XX_HWSCHED_HFI_H_ 9: 10: struct a6xx_hwsched_hfi { 11: /** @irq_mask: Store the hfi interrupt mask */ 12: u32 irq_mask; 13: /** @msglock: To protect the list of un-ACKed hfi packets */ 14: rwlock_t msglock; 15: /** @msglist: List of un-ACKed hfi packets */ 16: struct list_head msglist; 17: /** @f2h_task: Task for processing gmu fw to host packets */ 18: struct task_struct *f2h_task; 19: /** @f2h_wq: Waitqueue for the f2h_task */ 20: wait_queue_head_t f2h_wq; 21: /** @big_ib: GMU buffer to hold big IBs */ 22: struct kgsl_memdesc *big_ib; 23: /** @big_ib_recurring: GMU buffer to hold big recurring IBs */ 24: struct kgsl_memdesc *big_ib_recurring; 25: /** @perfctr_scratch: Buffer to hold perfcounter PM4 commands */ 26: struct kgsl_memdesc *perfctr_scratch; 27: /** @msg_mutex: Mutex for accessing the msgq */ 28: struct mutex msgq_mutex; 29: }; 30: 31: struct kgsl_drawobj_cmd; 32: 33: /** 34: * a6xx_hwsched_hfi_probe - Probe hwsched hfi resources 35: * @adreno_dev: Pointer to adreno device structure --- FILE: \adreno_a6xx_preempt.c | HITS: 5 --- MATCH LINES: 130, 132 118: adreno_dev->next_rb->wptr); 119: 120: /* Set a fault and restart */ 121: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT); 122: 123: return; 124: } 125: 126: adreno_dev->preempt.count++; 127: 128: /* 129: * In normal scenarios, preemption keep alive bit is cleared during 130: * CP interrupt callback. However, if preemption is successful 131: * immediately after preemption timer expires or there is a preemption 132: * interrupt with non-zero status, the state is transitioned to complete 133: * state. Once dispatcher is scheduled, it calls this function. 134: * We can now safely clear the preemption keepalive bit, allowing 135: * power collapse to resume its regular activity. 136: */ 137: _power_collapse_set(adreno_dev, false); 138: 139: kgsl_delete_timer_sync(&adreno_dev->preempt.timer); 140: 141: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 142: 143: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 144: status, 0); 145: 146: /* Clean up all the bits */ 147: adreno_dev->prev_rb = adreno_dev->cur_rb; 148: adreno_dev->cur_rb = adreno_dev->next_rb; 149: adreno_dev->next_rb = NULL; 150: 151: /* Update the wptr for the new command queue */ 152: _update_wptr(adreno_dev, true, false); 153: 154: /* Update the dispatcher timer for the new command queue */ 155: mod_timer(&adreno_dev->dispatcher.timer, 156: adreno_dev->cur_rb->dispatch_q.expires); MATCH LINES: 338 326: A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO, 327: lower_32_bits(next->preemption_desc->gpuaddr), 328: FENCE_STATUS_WRITEDROPPED1_MASK)) 329: goto err; 330: 331: /* 332: * Above fence writes will make sure GMU comes out of 333: * IFPC state if its was in IFPC state but it doesn't 334: * guarantee that GMU FW actually moved to ACTIVE state 335: * i.e. wake-up from IFPC is complete. 336: * Wait for GMU to move to ACTIVE state before triggering 337: * preemption. This is require to make sure CP doesn't 338: * interrupt GMU during wake-up from IFPC. 339: */ 340: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 341: goto err; 342: 343: if (a6xx_fenced_write(adreno_dev, 344: A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI, 345: upper_32_bits(next->preemption_desc->gpuaddr), 346: FENCE_STATUS_WRITEDROPPED1_MASK)) 347: goto err; 348: 349: if (kgsl_mmu_is_secured(&device->mmu)) { 350: if (a6xx_fenced_write(adreno_dev, 351: A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO, 352: lower_32_bits(next->secure_preemption_desc->gpuaddr), 353: FENCE_STATUS_WRITEDROPPED1_MASK)) 354: goto err; 355: 356: if (a6xx_fenced_write(adreno_dev, 357: A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI, 358: upper_32_bits(next->secure_preemption_desc->gpuaddr), 359: FENCE_STATUS_WRITEDROPPED1_MASK)) 360: goto err; 361: } 362: MATCH LINES: 433, 438 421: { 422: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 423: unsigned int status; 424: 425: if (!adreno_move_preempt_state(adreno_dev, 426: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 427: return; 428: 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; --- FILE: \adreno_a6xx_rgmu.c | HITS: 29 --- MATCH LINES: 52, 58, 65, 69, 74, 80, 98, 114 40: 0x24C00, 0x24C02, 0x25400, 0x25402, 0x25800, 0x25802, 0x25C00, 0x25C02, 41: 0x26000, 0x26002, 42: }; 43: 44: static struct a6xx_rgmu_device *to_a6xx_rgmu(struct adreno_device *adreno_dev) 45: { 46: struct a6xx_device *a6xx_dev = container_of(adreno_dev, 47: struct a6xx_device, adreno_dev); 48: 49: return &a6xx_dev->rgmu; 50: } 51: 52: static irqreturn_t a6xx_rgmu_irq_handler(int irq, void *data) 53: { 54: struct kgsl_device *device = data; 55: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(ADRENO_DEVICE(device)); 56: unsigned int status = 0; 57: 58: gmu_core_regread(device, A6XX_GMU_AO_HOST_INTERRUPT_STATUS, &status); 59: 60: if (status & RGMU_AO_IRQ_FENCE_ERR) { 61: unsigned int fence_status; 62: 63: gmu_core_regread(device, A6XX_GMU_AHB_FENCE_STATUS, 64: &fence_status); 65: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_CLR, 66: status); 67: 68: dev_err_ratelimited(&rgmu->pdev->dev, 69: "FENCE error interrupt received %x\n", fence_status); 70: } 71: 72: if (status & ~RGMU_AO_IRQ_MASK) 73: dev_err_ratelimited(&rgmu->pdev->dev, 74: "Unhandled RGMU interrupts 0x%lx\n", 75: status & ~RGMU_AO_IRQ_MASK); 76: 77: return IRQ_HANDLED; 78: } 79: 80: static irqreturn_t a6xx_oob_irq_handler(int irq, void *data) 81: { 82: struct kgsl_device *device = data; 83: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 84: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 85: unsigned int status = 0; 86: 87: gmu_core_regread(device, A6XX_GMU_GMU2HOST_INTR_INFO, &status); 88: 89: if (status & RGMU_OOB_IRQ_ERR_MSG) { 90: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, status); 91: 92: dev_err_ratelimited(&rgmu->pdev->dev, 93: "RGMU oob irq error\n"); 94: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 95: } 96: if (status & ~RGMU_OOB_IRQ_MASK) 97: dev_err_ratelimited(&rgmu->pdev->dev, 98: "Unhandled OOB interrupts 0x%lx\n", 99: status & ~RGMU_OOB_IRQ_MASK); 100: 101: return IRQ_HANDLED; 102: } 103: 104: static const char *oob_to_str(enum oob_request req) 105: { 106: if (req == oob_gpu) 107: return "oob_gpu"; 108: else if (req == oob_perfcntr) 109: return "oob_perfcntr"; 110: return "unknown"; 111: } 112: 113: /* 114: * a6xx_rgmu_oob_set() - Set OOB interrupt to RGMU 115: * @adreno_dev: Pointer to adreno device 116: * @req: Which of the OOB bits to request 117: */ 118: static int a6xx_rgmu_oob_set(struct kgsl_device *device, 119: enum oob_request req) 120: { 121: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(ADRENO_DEVICE(device)); 122: int ret, set, check; 123: 124: if (req == oob_perfcntr && rgmu->num_oob_perfcntr++) 125: return 0; 126: 127: set = BIT(req + 16); 128: check = BIT(req + 16); 129: 130: gmu_core_regwrite(device, A6XX_GMU_HOST2GMU_INTR_SET, set); 131: 132: ret = gmu_core_timed_poll_check(device, 133: A6XX_GMU_GMU2HOST_INTR_INFO, 134: check, 135: GPU_START_TIMEOUT, 136: check); 137: 138: if (ret) { MATCH LINES: 200, 207, 211, 215, 216, 225, 226, 230, 233 188: A6XX_GMU_AO_RGMU_GLM_SLEEP_STATUS, 189: BIT(1), GLM_SLEEP_TIMEOUT, BIT(1))) 190: dev_err_ratelimited(&rgmu->pdev->dev, 191: "Timed out waiting for HW CRC disable acknowledgment\n"); 192: 193: /* Pull down the valid RGMU_GLM_SLEEP_CTRL[7] to 0 */ 194: gmu_core_regrmw(device, A6XX_GMU_AO_RGMU_GLM_SLEEP_CTRL, 195: BIT(7), 0); 196: 197: } 198: } 199: 200: static void a6xx_rgmu_irq_enable(struct adreno_device *adreno_dev) 201: { 202: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 203: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 204: 205: /* Clear pending IRQs and Unmask needed IRQs */ 206: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, 0xffffffff); 207: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_CLR, 0xffffffff); 208: 209: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_MASK, 210: ~((unsigned int)RGMU_OOB_IRQ_MASK)); 211: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_MASK, 212: (unsigned int)~RGMU_AO_IRQ_MASK); 213: 214: /* Enable all IRQs on host */ 215: enable_irq(rgmu->oob_interrupt_num); 216: enable_irq(rgmu->rgmu_interrupt_num); 217: } 218: 219: static void a6xx_rgmu_irq_disable(struct adreno_device *adreno_dev) 220: { 221: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 222: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 223: 224: /* Disable all IRQs on host */ 225: disable_irq(rgmu->rgmu_interrupt_num); 226: disable_irq(rgmu->oob_interrupt_num); 227: 228: /* Mask all IRQs and clear pending IRQs */ 229: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_MASK, 0xffffffff); 230: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_MASK, 0xffffffff); 231: 232: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, 0xffffffff); 233: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_CLR, 0xffffffff); 234: } 235: 236: static int a6xx_rgmu_ifpc_store(struct kgsl_device *device, 237: unsigned int val) 238: { 239: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 240: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 241: unsigned int requested_idle_level; 242: 243: if (!ADRENO_FEATURE(adreno_dev, ADRENO_IFPC)) 244: return -EINVAL; 245: 246: if (val) 247: requested_idle_level = GPU_HW_IFPC; 248: else 249: requested_idle_level = GPU_HW_ACTIVE; 250: 251: if (requested_idle_level == rgmu->idle_level) 252: return 0; 253: 254: /* Power cycle the GPU for changes to take effect */ 255: return adreno_power_cycle_u32(adreno_dev, &rgmu->idle_level, 256: requested_idle_level); 257: } MATCH LINES: 366, 401, 404, 405 354: * The lowest 16 bits of this value are the number of XO clock cycles 355: * for main hysteresis. This is the first hysteresis. Here we set it 356: * to 0x1680 cycles, or 300 us. The highest 16 bits of this value are 357: * the number of XO clock cycles for short hysteresis. This happens 358: * after main hysteresis. Here we set it to 0xA cycles, or 0.5 us. 359: */ 360: #define A6X_RGMU_LONG_IFPC_HYST FIELD_PREP(GENMASK(15, 0), 0x1680) 361: #define A6X_RGMU_SHORT_IFPC_HYST FIELD_PREP(GENMASK(31, 16), 0xA) 362: 363: /* Minimum IFPC timer (200usec) allowed to override default value */ 364: #define A6X_RGMU_LONG_IFPC_HYST_FLOOR FIELD_PREP(GENMASK(15, 0), 0x0F00) 365: 366: /* HOSTTOGMU and TIMER0/1 interrupt mask: 0x20060 */ 367: #define RGMU_INTR_EN_MASK (BIT(5) | BIT(6) | BIT(17)) 368: 369: /* RGMU FENCE RANGE MASK */ 370: #define RGMU_FENCE_RANGE_MASK ((0x1 << 31) | ((0xA << 2) << 18) | (0x8A0)) 371: 372: static int a6xx_rgmu_fw_start(struct adreno_device *adreno_dev, 373: unsigned int boot_state) 374: { 375: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 376: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 377: unsigned int status; 378: int i; 379: 380: switch (boot_state) { 381: case GMU_COLD_BOOT: 382: case GMU_WARM_BOOT: 383: /* Turn on TCM retention */ 384: gmu_core_regwrite(device, A6XX_GMU_GENERAL_7, 1); 385: 386: /* Load RGMU FW image via AHB bus */ 387: for (i = 0; i < rgmu->fw_size; i++) 388: gmu_core_regwrite(device, A6XX_GMU_CM3_ITCM_START + i, 389: rgmu->fw_hostptr[i]); 390: break; 391: } 392: 393: /* IFPC Feature Enable */ 394: if (rgmu->idle_level == GPU_HW_IFPC) { 395: gmu_core_regwrite(device, A6XX_GMU_PWR_COL_INTER_FRAME_HYST, 396: A6X_RGMU_SHORT_IFPC_HYST | adreno_dev->ifpc_hyst); 397: gmu_core_regwrite(device, A6XX_GMU_PWR_COL_INTER_FRAME_CTRL, 398: BIT(0)); 399: } 400: 401: /* For RGMU CX interrupt */ 402: gmu_core_regwrite(device, A6XX_RGMU_CX_INTR_GEN_EN, RGMU_INTR_EN_MASK); 403: 404: /* Enable GMU AO to host interrupt */ 405: gmu_core_regwrite(device, A6XX_GMU_AO_INTERRUPT_EN, RGMU_AO_IRQ_MASK); 406: 407: /* For OOB */ 408: gmu_core_regwrite(device, A6XX_GMU_HOST2GMU_INTR_EN_2, 0x00FF0000); 409: gmu_core_regwrite(device, A6XX_GMU_HOST2GMU_INTR_EN_3, 0xFF000000); 410: 411: /* Fence Address range configuration */ 412: gmu_core_regwrite(device, A6XX_GMU_AHB_FENCE_RANGE_0, 413: RGMU_FENCE_RANGE_MASK); 414: 415: /* During IFPC RGMU will put fence in drop mode so we would 416: * need to put fence allow mode during slumber out sequence. 417: */ 418: gmu_core_regwrite(device, A6XX_GMU_AO_AHB_FENCE_CTRL, 0); 419: 420: /* BCL ON Sequence */ 421: a6xx_rgmu_bcl_config(device, true); 422: 423: /* Write 0 first to make sure that rgmu is reset */ 424: gmu_core_regwrite(device, A6XX_RGMU_CX_PCC_CTRL, 0); 425: 426: /* Make sure putting in reset doesn't happen after writing 1 */ 427: wmb(); 428: 429: /* Bring rgmu out of reset */ MATCH LINES: 606, 609 594: static void a6xx_rgmu_halt_execution(struct kgsl_device *device, bool force, 595: enum gmu_fault_panic_policy gf_policy) 596: { 597: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 598: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 599: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 600: u64 ticks = gpudev->read_alwayson(adreno_dev); 601: unsigned int index, status, fence; 602: 603: if (!device->gmu_fault) 604: return; 605: 606: /* Mask so there's no interrupt caused by NMI */ 607: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_MASK, 0xFFFFFFFF); 608: 609: /* Make sure the interrupt is masked */ 610: wmb(); 611: 612: gmu_core_regread(device, A6XX_RGMU_CX_PCC_DEBUG, &index); 613: gmu_core_regread(device, A6XX_RGMU_CX_PCC_STATUS, &status); 614: gmu_core_regread(device, A6XX_GMU_AO_AHB_FENCE_CTRL, &fence); 615: 616: dev_err(&rgmu->pdev->dev, 617: "RGMU Fault PCC_DEBUG:0x%x PCC_STATUS:0x%x FENCE_CTRL:0x%x\n", 618: index, status, fence); 619: 620: /* 621: * Write 0 to halt RGMU execution. We halt it in GMU/GPU fault and 622: * re start PCC execution in recovery path. 623: */ 624: gmu_core_regwrite(device, A6XX_RGMU_CX_PCC_CTRL, 0); 625: 626: /* 627: * Ensure that fence is in allow mode after halting RGMU. 628: * After halting RGMU we dump snapshot. 629: */ 630: gmu_core_regwrite(device, A6XX_GMU_AO_AHB_FENCE_CTRL, 0); 631: 632: KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic, rgmu->pdev, ticks, gf_policy); 633: } MATCH LINES: 820 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: } 819: 820: a6xx_rgmu_irq_enable(adreno_dev); 821: 822: /* Clear any GPU faults that might have been left over */ 823: adreno_clear_gpu_fault(adreno_dev); 824: 825: ret = a6xx_rgmu_fw_start(adreno_dev, GMU_COLD_BOOT); 826: if (ret) 827: goto err; 828: 829: ret = kgsl_pwrctrl_setup_default_votes(device); 830: if (ret) 831: goto err; 832: 833: device->gmu_fault = false; 834: 835: kgsl_pwrctrl_set_state(device, KGSL_STATE_AWARE); 836: 837: return 0; 838: 839: err: 840: a6xx_rgmu_power_off(adreno_dev); 841: 842: return ret; 843: } 844: MATCH LINES: 1248, 1253, 1257, 1262 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; 1263: return 0; 1264: } 1265: 1266: static int a6xx_rgmu_clocks_probe(struct a6xx_rgmu_device *rgmu, 1267: struct device_node *node) 1268: { 1269: struct a6xx_device *a6xx_dev = container_of(rgmu, 1270: struct a6xx_device, rgmu); 1271: struct kgsl_device *device = KGSL_DEVICE(&a6xx_dev->adreno_dev); 1272: int ret, i; 1273: 1274: ret = devm_clk_bulk_get_all(&rgmu->pdev->dev, &rgmu->clks); 1275: if (ret < 0) 1276: return ret; 1277: /* 1278: * Voting for apb_pclk will enable power and clocks required for 1279: * QDSS path to function. However, if QCOM_KGSL_QDSS_STM is not enabled, 1280: * QDSS is essentially unusable. Hence, if QDSS cannot be used, 1281: * don't vote for this clock. 1282: */ 1283: if (!IS_ENABLED(CONFIG_QCOM_KGSL_QDSS_STM)) { 1284: for (i = 0; i < ret; i++) { 1285: if (!strcmp(rgmu->clks[i].id, "apb_pclk")) { 1286: rgmu->clks[i].clk = NULL; MATCH LINES: 1394 1382: if (ret) 1383: return ret; 1384: 1385: /* Try to get the resource by index (i.e. 0), fallback to legacy "kgsl_rgmu" if not found */ 1386: ret = kgsl_regmap_add_region(&device->regmap, pdev, 1387: "kgsl_rgmu", 0, NULL, NULL); 1388: 1389: if (ret) { 1390: dev_err(&pdev->dev, "Unable to map the RGMU registers\n"); 1391: return ret; 1392: } 1393: 1394: /* Initialize OOB and RGMU interrupts */ 1395: ret = a6xx_rgmu_irq_probe(device); 1396: if (ret) 1397: return ret; 1398: 1399: /* Set up RGMU idle states */ 1400: if (ADRENO_FEATURE(ADRENO_DEVICE(device), ADRENO_IFPC)) { 1401: rgmu->idle_level = GPU_HW_IFPC; 1402: adreno_dev->ifpc_hyst = A6X_RGMU_LONG_IFPC_HYST; 1403: adreno_dev->ifpc_hyst_floor = A6X_RGMU_LONG_IFPC_HYST_FLOOR; 1404: } else { 1405: rgmu->idle_level = GPU_HW_ACTIVE; 1406: } 1407: 1408: set_bit(GMU_ENABLED, &device->gmu_core.flags); 1409: device->gmu_core.dev_ops = &a6xx_rgmudev; 1410: device->gmu_core.pdev = rgmu->pdev; 1411: 1412: return 0; 1413: } 1414: 1415: static void a6xx_rgmu_remove(struct kgsl_device *device) 1416: { 1417: 1418: memset(&device->gmu_core, 0, sizeof(device->gmu_core)); --- FILE: \adreno_a6xx_rgmu.h | HITS: 5 --- MATCH LINES: 13, 31, 32, 45, 46 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. 5: */ 6: #ifndef __ADRENO_A6XX_RGMU_H 7: #define __ADRENO_A6XX_RGMU_H 8: 9: #define RGMU_AO_IRQ_FENCE_ERR BIT(3) 10: #define RGMU_AO_IRQ_MASK RGMU_AO_IRQ_FENCE_ERR 11: 12: #define RGMU_OOB_IRQ_ERR_MSG BIT(24) 13: #define RGMU_OOB_IRQ_ACK_MASK GENMASK(23, 16) 14: #define RGMU_OOB_IRQ_ERR_MSG_MASK GENMASK(31, 24) 15: #define RGMU_OOB_IRQ_MASK RGMU_OOB_IRQ_ERR_MSG_MASK 16: 17: #define MAX_RGMU_CLKS 8 18: 19: enum { 20: /* @RGMU_PRIV_FIRST_BOOT_DONE: The very first ggpu boot is done */ 21: RGMU_PRIV_FIRST_BOOT_DONE, 22: /* @RGMU_PRIV_GPU_STARTED: GPU has been started */ 23: RGMU_PRIV_GPU_STARTED, 24: /* @RGMU_PRIV_PM_SUSPEND: The rgmu driver is suspended */ 25: RGMU_PRIV_PM_SUSPEND, 26: }; 27: 28: /** 29: * struct a6xx_rgmu_device - rGMU device structure 30: * @ver: RGMU firmware version 31: * @rgmu_interrupt_num: RGMU interrupt number 32: * @oob_interrupt_num: number of RGMU asserted OOB interrupt 33: * @fw_hostptr: Buffer which holds the RGMU firmware 34: * @fw_size: Size of RGMU firmware buffer 35: * @clks: RGMU clocks including the GPU 36: * @gpu_clk: Pointer to GPU core clock 37: * @rgmu_clk: Pointer to rgmu clock 38: * @flags: RGMU flags 39: * @idle_level: Minimal GPU idle power level 40: * @fault_count: RGMU fault count 41: */ 42: struct a6xx_rgmu_device { 43: u32 ver; 44: struct platform_device *pdev; 45: unsigned int rgmu_interrupt_num; 46: unsigned int oob_interrupt_num; 47: unsigned int *fw_hostptr; 48: uint32_t fw_size; 49: struct clk_bulk_data *clks; 50: /** @num_clks: Number of clocks in @clks */ 51: int num_clks; 52: struct clk *gpu_clk; 53: struct clk *rgmu_clk; 54: unsigned int idle_level; 55: unsigned int fault_count; 56: /** @flags: rgmu internal flags */ 57: unsigned long flags; 58: /** @num_oob_perfcntr: Number of active oob_perfcntr requests */ 59: u32 num_oob_perfcntr; 60: }; 61: 62: /** 63: * a6xx_rgmu_device_probe - Probe a6xx rgmu resources 64: * @pdev: Pointer to the platform device 65: * @chipid: Chipid of the target 66: * @gpucore: Pointer to the gpucore 67: * 68: * The target specific probe function for rgmu based a6xx targets. 69: */ 70: int a6xx_rgmu_device_probe(struct platform_device *pdev, --- FILE: \adreno_coresight.c | HITS: 6 --- MATCH LINES: 12, 13, 15, 16 1: // SPDX-License-Identifier: GPL-2.0-only 2: /* 3: * Copyright (c) 2013-2020, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include 8: #include 9: 10: #include "adreno.h" 11: 12: #define ADRENO_RBBM_INT_DEBUG_BUS_INTERRUPT0_MASK BIT(26) 13: #define ADRENO_RBBM_INT_DEBUG_BUS_INTERRUPT1_MASK BIT(27) 14: 15: #define ADRENO_DEBUG_BUS_INT_MASK ((ADRENO_RBBM_INT_DEBUG_BUS_INTERRUPT0_MASK) | \ 16: (ADRENO_RBBM_INT_DEBUG_BUS_INTERRUPT1_MASK)) 17: 18: #define TO_ADRENO_CORESIGHT_ATTR(_attr) \ 19: container_of(_attr, struct adreno_coresight_attr, attr) 20: 21: ssize_t adreno_coresight_show_register(struct device *dev, 22: struct device_attribute *attr, char *buf) 23: { 24: struct adreno_coresight_device *adreno_csdev = dev_get_drvdata(dev); 25: struct adreno_coresight_attr *cattr = TO_ADRENO_CORESIGHT_ATTR(attr); 26: struct kgsl_device *device = adreno_csdev->device; 27: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 28: unsigned int val = 0; 29: 30: kgsl_mutex_lock(&device->mutex); 31: /* 32: * Return the current value of the register if coresight is enabled, 33: * otherwise report 0 34: */ 35: 36: if (!adreno_csdev->enabled) 37: goto out; 38: 39: if (!adreno_active_count_get(adreno_dev)) { 40: kgsl_regread(device, cattr->reg->offset, &cattr->reg->value); MATCH LINES: 101 89: const struct adreno_coresight *coresight = adreno_csdev->coresight; 90: int i; 91: 92: kgsl_mutex_lock(&device->mutex); 93: 94: if (!adreno_csdev->enabled) { 95: kgsl_mutex_unlock(&device->mutex); 96: return; 97: } 98: 99: adreno_dev->coresight_en_cnt--; 100: 101: /* GMU takes care of DBGC interrupt mask for HWSCHED */ 102: if (!adreno_dev->coresight_en_cnt) { 103: if (adreno_dev->hwsched_enabled) 104: gmu_core_set_vrb_register(device->gmu_core.vrb, 105: VRB_DBGC_FAULT_ENABLE, 0); 106: else 107: adreno_dev->irq_mask &= ~ADRENO_DEBUG_BUS_INT_MASK; 108: } 109: 110: if (!adreno_active_count_get(adreno_dev)) { 111: for (i = 0; i < coresight->count; i++) 112: kgsl_regwrite(device, 113: coresight->registers[i].offset, 0); 114: adreno_active_count_put(adreno_dev); 115: } 116: 117: adreno_csdev->enabled = false; 118: 119: kgsl_mutex_unlock(&device->mutex); 120: } 121: 122: static void _adreno_coresight_get_and_clear(struct adreno_device *adreno_dev, 123: struct adreno_coresight_device *adreno_csdev) 124: { 125: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); MATCH LINES: 198 186: if (!adreno_csdev->enabled) { 187: int i; 188: 189: adreno_csdev->enabled = true; 190: 191: /* Reset all the debug registers to their default values */ 192: for (i = 0; i < coresight->count; i++) 193: coresight->registers[i].value = 194: coresight->registers[i].initial; 195: 196: adreno_dev->coresight_en_cnt++; 197: 198: /* GMU takes care of DBGC interrupt mask for HWSCHED */ 199: if (adreno_dev->coresight_en_cnt == 1) { 200: if (adreno_dev->hwsched_enabled) 201: gmu_core_set_vrb_register(device->gmu_core.vrb, 202: VRB_DBGC_FAULT_ENABLE, 1); 203: else 204: adreno_dev->irq_mask |= ADRENO_DEBUG_BUS_INT_MASK; 205: } 206: 207: ret = adreno_active_count_get(adreno_dev); 208: if (!ret) { 209: _adreno_coresight_set(adreno_dev, adreno_csdev); 210: adreno_active_count_put(adreno_dev); 211: } 212: 213: } 214: kgsl_mutex_unlock(&device->mutex); 215: return ret; 216: } 217: 218: #if (KERNEL_VERSION(6, 4, 0) >= LINUX_VERSION_CODE) 219: static int adreno_coresight_enable(struct coresight_device *csdev, 220: struct perf_event *event, u32 mode) 221: { 222: return _adreno_coresight_enable(csdev, event, mode); --- FILE: \adreno_dispatch.c | HITS: 3 --- MATCH LINES: 1010 998: int ret = 0; 999: 1000: /* 1001: * There is always a possibility that dispatcher may end up pushing 1002: * the last popped draw object back to the context drawqueue. Hence, 1003: * we can only queue up to _context_drawqueue_size - 1 here to make 1004: * sure we never let drawqueue->queued exceed _context_drawqueue_size. 1005: */ 1006: if ((drawctxt->queued + count) > (_context_drawqueue_size - 1)) { 1007: trace_adreno_drawctxt_sleep(drawctxt); 1008: spin_unlock(&drawctxt->lock); 1009: 1010: ret = wait_event_interruptible_timeout(drawctxt->wq, 1011: _check_context_queue(drawctxt, count), 1012: msecs_to_jiffies(_context_queue_wait)); 1013: 1014: spin_lock(&drawctxt->lock); 1015: trace_adreno_drawctxt_wake(drawctxt); 1016: 1017: /* 1018: * Account for the possibility that the context got invalidated 1019: * while we were sleeping 1020: */ 1021: if (ret > 0) 1022: ret = kgsl_check_context_state(&drawctxt->base); 1023: else if (ret == 0) 1024: ret = -ETIMEDOUT; 1025: } 1026: 1027: return ret; 1028: } 1029: 1030: static unsigned int _check_context_state_to_queue_cmds( 1031: struct adreno_context *drawctxt, u32 count) 1032: { 1033: int ret = kgsl_check_context_state(&drawctxt->base); 1034: MATCH LINES: 1928, 1931 1916: kgsl_mutex_lock(&device->mutex); 1917: 1918: /* 1919: * In the very unlikely case that the power is off, do nothing - the 1920: * state will be reset on power up and everybody will be happy 1921: */ 1922: if (!kgsl_state_is_awake(device)) { 1923: kgsl_mutex_unlock(&device->mutex); 1924: mutex_unlock(&adreno_dev->fault_recovery_mutex); 1925: return 0; 1926: } 1927: 1928: /* Mask all GMU interrupts */ 1929: if (gmu_core_isenabled(device)) { 1930: adreno_write_gmureg(adreno_dev, 1931: ADRENO_REG_GMU_AO_HOST_INTERRUPT_MASK, 1932: 0xFFFFFFFF); 1933: adreno_write_gmureg(adreno_dev, 1934: ADRENO_REG_GMU_GMU2HOST_INTR_MASK, 1935: 0xFFFFFFFF); 1936: } 1937: 1938: gx_on = adreno_gx_is_on(adreno_dev); 1939: 1940: /* 1941: * Check if this function was entered after a pagefault. If so, only 1942: * proceed if the fault handler has already run in the IRQ thread, 1943: * else return early to give the fault handler a chance to run. 1944: */ 1945: if (!(fault & ADRENO_IOMMU_STALL_ON_PAGE_FAULT) && gx_on) { 1946: if (adreno_smmu_is_stalled(adreno_dev)) { 1947: kgsl_mutex_unlock(&device->mutex); 1948: mutex_unlock(&adreno_dev->fault_recovery_mutex); 1949: dev_err(device->dev, 1950: "SMMU is stalled without a pagefault\n"); 1951: return -EBUSY; 1952: } 1953: } 1954: 1955: /* Turn off all the timers */ --- FILE: \adreno_drawctxt.c | HITS: 3 --- MATCH LINES: 54 42: { 43: unsigned int queue, start, retire; 44: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 45: int index, pos; 46: char buf[120]; 47: 48: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_QUEUED, &queue); 49: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_CONSUMED, &start); 50: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, &retire); 51: 52: /* 53: * We may have kgsl sync obj timer running, which also uses same 54: * lock, take a lock with software interrupt disabled (bh) 55: * to avoid spin lock recursion. 56: * 57: * Use Spin trylock because dispatcher can acquire drawctxt->lock 58: * if context is pending and the fence it is waiting on just got 59: * signalled. Dispatcher acquires drawctxt->lock and tries to 60: * delete the sync obj timer using kgsl_delete_timer_sync(). 61: * kgsl_delete_timer_sync() waits till timer and its pending handlers 62: * are deleted. But if the timer expires at the same time, 63: * timer handler could be waiting on drawctxt->lock leading to a 64: * deadlock. To prevent this use spin_trylock_bh. 65: */ 66: if (!spin_trylock_bh(&drawctxt->lock)) { 67: dev_err(device->dev, " context[%u]: could not get lock\n", 68: context->id); 69: return; 70: } 71: 72: dev_err(device->dev, 73: " context[%u]: queue=%u, submit=%u, start=%u, retire=%u\n", 74: context->id, queue, drawctxt->submitted_timestamp, 75: start, retire); 76: 77: if (drawctxt->drawqueue_head != drawctxt->drawqueue_tail) { 78: struct kgsl_drawobj *drawobj = MATCH LINES: 169 157: ret = kgsl_add_event(device, &context->events, timestamp, 158: wait_callback, (void *) drawctxt); 159: if (ret) 160: goto done; 161: 162: /* 163: * If timeout is 0, wait forever. msecs_to_jiffies will force 164: * values larger than INT_MAX to an infinite timeout. 165: */ 166: if (timeout == 0) 167: timeout = UINT_MAX; 168: 169: ret_temp = wait_event_interruptible_timeout(drawctxt->waiting, 170: _check_context_timestamp(device, context, timestamp), 171: msecs_to_jiffies(timeout)); 172: 173: if (ret_temp <= 0) { 174: kgsl_cancel_event(device, &context->events, timestamp, 175: wait_callback, (void *)drawctxt); 176: 177: ret = ret_temp ? (int)ret_temp : -ETIMEDOUT; 178: goto done; 179: } 180: ret = 0; 181: 182: /* -EDEADLK if the context was invalidated while we were waiting */ 183: if (kgsl_context_invalid(context)) 184: ret = -EDEADLK; 185: 186: 187: /* Return -EINVAL if the context was detached while we were waiting */ 188: if (kgsl_context_detached(context)) 189: ret = -ENOENT; 190: 191: done: 192: trace_adreno_drawctxt_wait_done(-1, context->id, timestamp, ret); 193: return ret; MATCH LINES: 581 569: "Wait for global ctx=%u ts=%u type=%d error=%d\n", 570: drawctxt->base.id, drawctxt->internal_timestamp, 571: drawctxt->type, ret); 572: 573: adreno_set_gpu_fault(adreno_dev, 574: ADRENO_CTX_DETATCH_TIMEOUT_FAULT); 575: kgsl_mutex_unlock(&device->mutex); 576: 577: /* Schedule dispatcher to kick in recovery */ 578: adreno_scheduler_queue(adreno_dev); 579: 580: /* Wait for context to be invalidated and release context */ 581: wait_event_interruptible_timeout(drawctxt->timeout, 582: kgsl_context_invalid(&drawctxt->base), 583: msecs_to_jiffies(5000)); 584: return; 585: } 586: 587: kgsl_sharedmem_writel(device->memstore, 588: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 589: drawctxt->timestamp); 590: 591: kgsl_sharedmem_writel(device->memstore, 592: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 593: drawctxt->timestamp); 594: 595: adreno_profile_process_results(adreno_dev); 596: 597: kgsl_mutex_unlock(&device->mutex); 598: } 599: 600: void adreno_drawctxt_detach(struct kgsl_context *context) 601: { 602: struct kgsl_device *device; 603: struct adreno_device *adreno_dev; 604: const struct adreno_gpudev *gpudev; 605: struct adreno_context *drawctxt; --- FILE: \adreno_gen7.c | HITS: 32 --- MATCH LINES: 1148, 1152 1136: struct kgsl_device *device = &adreno_dev->dev; 1137: unsigned int rptr, wptr; 1138: unsigned int status, status3, intstatus; 1139: unsigned int hwfault; 1140: 1141: dev_err(device->dev, str); 1142: 1143: kgsl_regread(device, GEN7_CP_RB_RPTR, &rptr); 1144: kgsl_regread(device, GEN7_CP_RB_WPTR, &wptr); 1145: 1146: kgsl_regread(device, GEN7_RBBM_STATUS, &status); 1147: kgsl_regread(device, GEN7_RBBM_STATUS3, &status3); 1148: kgsl_regread(device, GEN7_RBBM_INT_0_STATUS, &intstatus); 1149: kgsl_regread(device, GEN7_CP_HW_FAULT, &hwfault); 1150: 1151: dev_err(device->dev, 1152: "rb=%d pos=%X/%X rbbm_status=%8.8X/%8.8X int_0_status=%8.8X\n", 1153: adreno_dev->cur_rb ? adreno_dev->cur_rb->id : -1, rptr, wptr, 1154: status, status3, intstatus); 1155: 1156: dev_err(device->dev, " hwfault=%8.8X\n", hwfault); 1157: 1158: kgsl_device_snapshot(device, NULL, NULL, false); 1159: } 1160: 1161: /* 1162: * gen7_send_cp_init() - Initialize ringbuffer 1163: * @adreno_dev: Pointer to adreno device 1164: * @rb: Pointer to the ringbuffer of device 1165: * 1166: * Submit commands for ME initialization, 1167: */ 1168: static int gen7_send_cp_init(struct adreno_device *adreno_dev, 1169: struct adreno_ringbuffer *rb) 1170: { 1171: unsigned int *cmds; 1172: int ret; 1173: 1174: cmds = adreno_ringbuffer_allocspace(rb, GEN7_CP_INIT_DWORDS); 1175: if (IS_ERR(cmds)) 1176: return PTR_ERR(cmds); MATCH LINES: 1244 1232: if (preempt->postamble_bootup_len) { 1233: *cmds++ = cp_type7_packet(CP_SET_AMBLE, 3); 1234: *cmds++ = lower_32_bits(kmd_postamble_addr); 1235: *cmds++ = upper_32_bits(kmd_postamble_addr); 1236: *cmds++ = FIELD_PREP(GENMASK(22, 20), CP_KMD_AMBLE_TYPE) 1237: | (FIELD_PREP(GENMASK(19, 0), adreno_dev->preempt.postamble_bootup_len)); 1238: } 1239: 1240: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1241: *cmds++ = 0; 1242: *cmds++ = 0; 1243: *cmds++ = 0; 1244: /* generate interrupt on preemption completion */ 1245: *cmds++ = 0; 1246: 1247: ret = gen7_ringbuffer_submit(rb, NULL); 1248: if (!ret) { 1249: ret = adreno_spin_idle(adreno_dev, 2000); 1250: if (ret) 1251: gen7_spin_idle_debug(adreno_dev, 1252: "hw preemption initialization failed to idle\n"); 1253: } 1254: 1255: return ret; 1256: } 1257: 1258: int gen7_rb_start(struct adreno_device *adreno_dev) 1259: { 1260: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 1261: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 1262: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1263: struct adreno_ringbuffer *rb; 1264: u64 addr; 1265: int ret, i; 1266: unsigned int *cmds; 1267: 1268: /* Clear all the ringbuffers */ MATCH LINES: 1380, 1405, 1411, 1415 1368: /* Bit 23 is GPUBUSYIGNAHB */ 1369: return (reg & BIT(23)) ? false : true; 1370: } 1371: 1372: int gen7_microcode_read(struct adreno_device *adreno_dev) 1373: { 1374: struct adreno_firmware *sqe_fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 1375: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 1376: 1377: return adreno_get_firmware(adreno_dev, gen7_core->sqefw_name, sqe_fw); 1378: } 1379: 1380: /* CP Interrupt bits */ 1381: #define CP_INT_OPCODEERROR 0 1382: #define CP_INT_UCODEERROR 1 1383: #define CP_INT_CPHWFAULT 2 1384: #define CP_INT_REGISTERPROTECTION 4 1385: #define CP_INT_VSDPARITYERROR 6 1386: #define CP_INT_ILLEGALINSTRUCTION 7 1387: #define CP_INT_OPCODEERRORLPAC 8 1388: #define CP_INT_UCODEERRORLPAC 9 1389: #define CP_INT_CPHWFAULTLPAC 10 1390: #define CP_INT_REGISTERPROTECTIONLPAC 11 1391: #define CP_INT_ILLEGALINSTRUCTIONLPAC 12 1392: #define CP_INT_OPCODEERRORBV 13 1393: #define CP_INT_UCODEERRORBV 14 1394: #define CP_INT_CPHWFAULTBV 15 1395: #define CP_INT_REGISTERPROTECTIONBV 16 1396: #define CP_INT_ILLEGALINSTRUCTIONBV 17 1397: 1398: static void gen7_cp_hw_err_callback(struct adreno_device *adreno_dev, int bit) 1399: { 1400: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1401: unsigned int status1, status2; 1402: struct device *dev = device->dev; 1403: unsigned int opcode; 1404: 1405: kgsl_regread(device, GEN7_CP_INTERRUPT_STATUS, &status1); 1406: 1407: if (status1 & BIT(CP_INT_OPCODEERROR)) { 1408: kgsl_regwrite(device, GEN7_CP_SQE_STAT_ADDR, 1); 1409: kgsl_regread(device, GEN7_CP_SQE_STAT_DATA, &opcode); 1410: dev_crit_ratelimited(dev, 1411: "CP opcode error interrupt | opcode=0x%8.8x\n", opcode); 1412: } 1413: 1414: if (status1 & BIT(CP_INT_UCODEERROR)) 1415: dev_crit_ratelimited(dev, "CP ucode error interrupt\n"); 1416: 1417: if (status1 & BIT(CP_INT_CPHWFAULT)) { 1418: kgsl_regread(device, GEN7_CP_HW_FAULT, &status2); 1419: dev_crit_ratelimited(dev, 1420: "CP | Ringbuffer HW fault | status=%x\n", status2); 1421: } 1422: 1423: if (status1 & BIT(CP_INT_REGISTERPROTECTION)) { 1424: kgsl_regread(device, GEN7_CP_PROTECT_STATUS, &status2); 1425: dev_crit_ratelimited(dev, 1426: "CP | Protected mode error | %s | addr=%x | status=%x\n", 1427: status2 & BIT(20) ? "READ" : "WRITE", 1428: status2 & 0x3ffff, status2); 1429: } 1430: 1431: if (status1 & BIT(CP_INT_VSDPARITYERROR)) 1432: dev_crit_ratelimited(dev, "CP VSD decoder parity error\n"); 1433: 1434: if (status1 & BIT(CP_INT_ILLEGALINSTRUCTION)) 1435: dev_crit_ratelimited(dev, "CP Illegal instruction error\n"); 1436: 1437: if (ADRENO_FEATURE(adreno_dev, ADRENO_LPAC)) { 1438: if (status1 & BIT(CP_INT_OPCODEERRORLPAC)) 1439: dev_crit_ratelimited(dev, "CP Opcode error LPAC\n"); MATCH LINES: 1509, 1510, 1519, 1525 1497: err_details_0, err_details_1); 1498: break; 1499: } 1500: case GEN7_INT_ATBASYNCFIFOOVERFLOW: 1501: dev_crit_ratelimited(dev, "RBBM: ATB ASYNC overflow\n"); 1502: break; 1503: case GEN7_INT_ATBBUSOVERFLOW: 1504: dev_crit_ratelimited(dev, "RBBM: ATB bus overflow\n"); 1505: break; 1506: case GEN7_INT_OUTOFBOUNDACCESS: 1507: dev_crit_ratelimited(dev, "UCHE: Out of bounds access\n"); 1508: break; 1509: case GEN7_INT_UCHETRAPINTERRUPT: 1510: dev_crit_ratelimited(dev, "UCHE: Trap interrupt\n"); 1511: break; 1512: case GEN7_INT_TSBWRITEERROR: 1513: { 1514: u32 lo, hi; 1515: 1516: kgsl_regread(device, GEN7_RBBM_SECVID_TSB_STATUS_LO, &lo); 1517: kgsl_regread(device, GEN7_RBBM_SECVID_TSB_STATUS_HI, &hi); 1518: 1519: dev_crit_ratelimited(dev, "TSB: Write error interrupt: Address: 0x%lx MID: %lu\n", 1520: FIELD_GET(GENMASK(16, 0), hi) << 32 | lo, 1521: FIELD_GET(GENMASK(31, 23), hi)); 1522: break; 1523: } 1524: default: 1525: dev_crit_ratelimited(dev, "Unknown interrupt %d\n", bit); 1526: } 1527: } 1528: 1529: static const char *const uche_client[] = { 1530: "BR_VFD", "BR_SP", "BR_VSC", "BR_VPC", 1531: "BR_HLSQ", "BR_PC", "BR_LRZ", "BR_TP", 1532: "BV_VFD", "BV_SP", "BV_VSC", "BV_VPC", 1533: "BV_HLSQ", "BV_PC", "BV_LRZ", "BV_TP" 1534: }; 1535: 1536: static const char *const uche_lpac_client[] = { 1537: "-", "SP_LPAC", "-", "-", "HLSQ_LPAC", "-", "-", "TP_LPAC" 1538: }; 1539: 1540: #define SCOOBYDOO 0x5c00bd00 1541: 1542: static const char *gen7_fault_block_uche(struct kgsl_device *device, 1543: char *str, int size, bool lpac) 1544: { 1545: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1546: unsigned int uche_client_id = adreno_dev->uche_client_pf; 1547: const char *uche_client_str, *fault_block; 1548: 1549: /* MATCH LINES: 1638, 1640, 1648, 1660, 1662, 1681 1626: return str; 1627: } 1628: 1629: static void gen7_cp_callback(struct adreno_device *adreno_dev, int bit) 1630: { 1631: if (adreno_is_preemption_enabled(adreno_dev)) 1632: gen7_preemption_trigger(adreno_dev, true); 1633: 1634: adreno_scheduler_queue(adreno_dev); 1635: } 1636: 1637: /* 1638: * gen7_gpc_err_int_callback() - Isr for GPC error interrupts 1639: * @adreno_dev: Pointer to device 1640: * @bit: Interrupt bit 1641: */ 1642: static void gen7_gpc_err_int_callback(struct adreno_device *adreno_dev, int bit) 1643: { 1644: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1645: 1646: /* 1647: * GPC error is typically the result of mistake SW programming. 1648: * Force GPU fault for this interrupt so that we can debug it 1649: * with help of register dump. 1650: */ 1651: 1652: dev_crit(device->dev, "RBBM: GPC error\n"); 1653: adreno_irqctrl(adreno_dev, 0); 1654: 1655: /* Trigger a fault in the dispatcher - this will effect a restart */ 1656: adreno_scheduler_fault(adreno_dev, ADRENO_SOFT_FAULT); 1657: } 1658: 1659: /* 1660: * gen7_swfuse_violation_callback() - ISR for software fuse violation interrupt 1661: * @adreno_dev: Pointer to device 1662: * @bit: Interrupt bit 1663: */ 1664: static void gen7_swfuse_violation_callback(struct adreno_device *adreno_dev, int bit) 1665: { 1666: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1667: u32 status; 1668: 1669: /* 1670: * SWFUSEVIOLATION error is typically the result of enabling software 1671: * feature which is not supported by the hardware. Following are the 1672: * Feature violation will be reported 1673: * 1) FASTBLEND (BIT:0): NO Fault, RB will send the workload to legacy 1674: * blender HW pipeline. 1675: * 2) LPAC (BIT:1): Fault 1676: * 3) RAYTRACING (BIT:2): Fault 1677: */ 1678: kgsl_regread(device, GEN7_RBBM_SW_FUSE_INT_STATUS, &status); 1679: 1680: /* 1681: * RBBM_INT_CLEAR_CMD will not clear SWFUSEVIOLATION interrupt. Hence 1682: * do explicit swfuse irq clear. 1683: */ 1684: kgsl_regwrite(device, GEN7_RBBM_SW_FUSE_INT_MASK, 0); 1685: 1686: dev_crit_ratelimited(device->dev, 1687: "RBBM: SW Feature Fuse violation status=0x%8.8x\n", status); 1688: 1689: /* Trigger a fault in the dispatcher for LPAC and RAYTRACING violation */ 1690: if (status & GENMASK(GEN7_RAYTRACING_SW_FUSE, GEN7_LPAC_SW_FUSE)) { 1691: adreno_irqctrl(adreno_dev, 0); 1692: adreno_scheduler_fault(adreno_dev, ADRENO_HARD_FAULT); 1693: } 1694: } 1695: 1696: static const struct adreno_irq_funcs gen7_irq_funcs[32] = { 1697: ADRENO_IRQ_CALLBACK(NULL), /* 0 - RBBM_GPU_IDLE */ 1698: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 1 - RBBM_AHB_ERROR */ 1699: ADRENO_IRQ_CALLBACK(NULL), /* 2 - UNUSED */ 1700: ADRENO_IRQ_CALLBACK(NULL), /* 3 - UNUSED */ 1701: ADRENO_IRQ_CALLBACK(NULL), /* 4 - CPIPCINT0 */ 1702: ADRENO_IRQ_CALLBACK(NULL), /* 5 - CPIPCINT1 */ 1703: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 6 - ATBASYNCOVERFLOW */ 1704: ADRENO_IRQ_CALLBACK(gen7_gpc_err_int_callback), /* 7 - GPC_ERR */ 1705: ADRENO_IRQ_CALLBACK(gen7_preemption_callback),/* 8 - CP_SW */ MATCH LINES: 1733 1721: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 24 - UCHE_OOB_ACCESS */ 1722: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 25 - UCHE_TRAP_INTR */ 1723: ADRENO_IRQ_CALLBACK(NULL), /* 26 - DEBBUS_INTR_0 */ 1724: ADRENO_IRQ_CALLBACK(NULL), /* 27 - DEBBUS_INTR_1 */ 1725: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 28 - TSBWRITEERROR */ 1726: ADRENO_IRQ_CALLBACK(gen7_swfuse_violation_callback), /* 29 - SWFUSEVIOLATION */ 1727: ADRENO_IRQ_CALLBACK(NULL), /* 30 - ISDB_CPU_IRQ */ 1728: ADRENO_IRQ_CALLBACK(NULL), /* 31 - ISDB_UNDER_DEBUG */ 1729: }; 1730: 1731: /* 1732: * If the AHB fence is not in ALLOW mode when we receive an RBBM 1733: * interrupt, something went wrong. This means that we cannot proceed 1734: * since the IRQ status and clear registers are not accessible. 1735: * This is usually harmless because the GMU will abort power collapse 1736: * and change the fence back to ALLOW. Poll so that this can happen. 1737: */ 1738: static int gen7_irq_poll_fence(struct adreno_device *adreno_dev) 1739: { 1740: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1741: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1742: u32 status, fence, fence_retries = 0; 1743: u64 a, b, c; 1744: 1745: a = gpudev->read_alwayson(adreno_dev); 1746: 1747: kgsl_regread(device, GEN7_GMU_AO_AHB_FENCE_CTRL, &fence); 1748: 1749: while (fence != 0) { 1750: b = gpudev->read_alwayson(adreno_dev); 1751: 1752: /* Wait for small time before trying again */ 1753: udelay(1); 1754: kgsl_regread(device, GEN7_GMU_AO_AHB_FENCE_CTRL, &fence); 1755: 1756: if (fence_retries == 100 && fence != 0) { 1757: c = gpudev->read_alwayson(adreno_dev); MATCH LINES: 1775, 1778, 1782, 1788, 1803, 1806, 1810, 1821 1763: "status=0x%x Unmasked status=0x%x Mask=0x%x timestamps: %llx %llx %llx\n", 1764: status & adreno_dev->irq_mask, status, 1765: adreno_dev->irq_mask, a, b, c); 1766: return -ETIMEDOUT; 1767: } 1768: 1769: fence_retries++; 1770: } 1771: 1772: return 0; 1773: } 1774: 1775: static irqreturn_t gen7_hwsched_irq_handler(struct adreno_device *adreno_dev) 1776: { 1777: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1778: irqreturn_t ret = IRQ_NONE; 1779: u32 status; 1780: 1781: /* 1782: * GPU can power down once the INT_0_STATUS is read below. 1783: * But there still might be some register reads required so 1784: * force the GMU/GPU into KEEPALIVE mode until done with the ISR. 1785: */ 1786: gen7_gpu_keepalive(adreno_dev, true); 1787: 1788: kgsl_regread(device, GEN7_RBBM_INT_0_STATUS, &status); 1789: 1790: kgsl_regwrite(device, GEN7_RBBM_INT_CLEAR_CMD, status); 1791: 1792: ret = adreno_irq_callbacks(adreno_dev, gen7_irq_funcs, status); 1793: 1794: trace_kgsl_gen7_irq_status(adreno_dev, status); 1795: 1796: /* If hard fault, then let snapshot turn off the keepalive */ 1797: if (!(adreno_gpu_fault(adreno_dev) & ADRENO_HARD_FAULT)) 1798: gen7_gpu_keepalive(adreno_dev, false); 1799: 1800: return ret; 1801: } 1802: 1803: static irqreturn_t gen7_irq_handler(struct adreno_device *adreno_dev) 1804: { 1805: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1806: irqreturn_t ret = IRQ_NONE; 1807: u32 status; 1808: 1809: /* 1810: * GPU can power down once the INT_0_STATUS is read below. 1811: * But there still might be some register reads required so 1812: * force the GMU/GPU into KEEPALIVE mode until done with the ISR. 1813: */ 1814: gen7_gpu_keepalive(adreno_dev, true); 1815: 1816: if (gen7_irq_poll_fence(adreno_dev)) { 1817: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 1818: goto done; 1819: } 1820: 1821: kgsl_regread(device, GEN7_RBBM_INT_0_STATUS, &status); 1822: 1823: kgsl_regwrite(device, GEN7_RBBM_INT_CLEAR_CMD, status); 1824: 1825: ret = adreno_irq_callbacks(adreno_dev, gen7_irq_funcs, status); 1826: 1827: trace_kgsl_gen7_irq_status(adreno_dev, status); 1828: 1829: done: 1830: /* If hard fault, then let snapshot turn off the keepalive */ 1831: if (!(adreno_gpu_fault(adreno_dev) & ADRENO_HARD_FAULT)) 1832: gen7_gpu_keepalive(adreno_dev, false); 1833: 1834: return ret; 1835: } 1836: 1837: int gen7_probe_common(struct platform_device *pdev, 1838: struct adreno_device *adreno_dev, u32 chipid, 1839: const struct adreno_gpu_core *gpucore) 1840: { 1841: const struct adreno_gpudev *gpudev = gpucore->gpudev; 1842: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1843: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 1844: const struct adreno_gen7_core *gen7_core = container_of(gpucore, 1845: struct adreno_gen7_core, base); MATCH LINES: 1914, 1916, 1917 1902: ADRENO_REG_DEFINE(ADRENO_REG_CP_LPAC_RB_BASE_HI, GEN7_CP_LPAC_RB_BASE_HI), 1903: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_RPTR, GEN7_CP_RB_RPTR), 1904: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_WPTR, GEN7_CP_RB_WPTR), 1905: ADRENO_REG_DEFINE(ADRENO_REG_CP_ME_CNTL, GEN7_CP_SQE_CNTL), 1906: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BASE, GEN7_CP_IB1_BASE), 1907: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BASE_HI, GEN7_CP_IB1_BASE_HI), 1908: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BUFSZ, GEN7_CP_IB1_REM_SIZE), 1909: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BASE, GEN7_CP_IB2_BASE), 1910: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BASE_HI, GEN7_CP_IB2_BASE_HI), 1911: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BUFSZ, GEN7_CP_IB2_REM_SIZE), 1912: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_STATUS, GEN7_RBBM_STATUS), 1913: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_STATUS3, GEN7_RBBM_STATUS3), 1914: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_INT_0_MASK, GEN7_RBBM_INT_0_MASK), 1915: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_SW_RESET_CMD, GEN7_RBBM_SW_RESET_CMD), 1916: ADRENO_REG_DEFINE(ADRENO_REG_GMU_AO_HOST_INTERRUPT_MASK, 1917: GEN7_GMU_AO_HOST_INTERRUPT_MASK), 1918: ADRENO_REG_DEFINE(ADRENO_REG_GMU_GMU2HOST_INTR_MASK, 1919: GEN7_GMU_GMU2HOST_INTR_MASK), 1920: }; 1921: 1922: 1923: static u32 _get_pipeid(u32 groupid) 1924: { 1925: switch (groupid) { 1926: case KGSL_PERFCOUNTER_GROUP_BV_PC: 1927: fallthrough; 1928: case KGSL_PERFCOUNTER_GROUP_BV_VPC: 1929: fallthrough; 1930: case KGSL_PERFCOUNTER_GROUP_BV_TSE: 1931: fallthrough; 1932: case KGSL_PERFCOUNTER_GROUP_BV_RAS: 1933: fallthrough; 1934: case KGSL_PERFCOUNTER_GROUP_BV_LRZ: 1935: fallthrough; 1936: case KGSL_PERFCOUNTER_GROUP_BV_HLSQ: 1937: return PIPE_BV; 1938: case KGSL_PERFCOUNTER_GROUP_PC: 1939: fallthrough; 1940: case KGSL_PERFCOUNTER_GROUP_VPC: 1941: fallthrough; MATCH LINES: 2505, 2537, 2568 2493: "status %8.8X rb %4.4x/%4.4x ib1 %16.16llX/%4.4x ib2 %16.16llX/%4.4x\n", 2494: status, rptr, wptr, ib1base, ib1sz, ib2base, ib2sz); 2495: done: 2496: trace_adreno_gpu_fault(ctxt_id, ts, status, 2497: rptr, wptr, ib1base, ib1sz, ib2base, ib2sz, rb_id); 2498: } 2499: 2500: const struct gen7_gpudev adreno_gen7_9_0_hwsched_gpudev = { 2501: .base = { 2502: .reg_offsets = gen7_register_offsets, 2503: .probe = gen7_hwsched_probe, 2504: .snapshot = gen7_hwsched_snapshot, 2505: .irq_handler = gen7_hwsched_irq_handler, 2506: .iommu_fault_block = gen7_iommu_fault_block, 2507: .context_detach = gen7_hwsched_context_detach, 2508: .read_alwayson = gen7_9_0_read_alwayson, 2509: .reset = gen7_hwsched_reset_replay, 2510: .power_ops = &gen7_hwsched_power_ops, 2511: .power_stats = gen7_power_stats, 2512: .hw_isidle = gen7_hw_isidle, 2513: .add_to_va_minidump = gen7_hwsched_add_to_minidump, 2514: .gx_is_on = gen7_gmu_gx_is_on, 2515: .send_recurring_cmdobj = gen7_hwsched_send_recurring_cmdobj, 2516: .perfcounter_remove = gen7_perfcounter_remove, 2517: .set_isdb_breakpoint_registers = gen7_set_isdb_breakpoint_registers, 2518: .context_destroy = gen7_hwsched_context_destroy, 2519: .lpac_store = gen7_9_0_lpac_store, 2520: .get_uche_trap_base = gen7_get_uche_trap_base, 2521: .fault_header = gen7_fault_header, 2522: .lpac_fault_header = gen7_lpac_fault_header, 2523: .power_feature_stats = gen7_power_feature_stats, 2524: .acquire_cp_semaphore = gen7_acquire_cp_semaphore, 2525: .release_cp_semaphore = gen7_release_cp_semaphore, 2526: }, 2527: .hfi_probe = gen7_hwsched_hfi_probe, 2528: .hfi_remove = gen7_hwsched_hfi_remove, 2529: .handle_watchdog = gen7_hwsched_handle_watchdog, 2530: }; 2531: 2532: const struct gen7_gpudev adreno_gen7_hwsched_gpudev = { 2533: .base = { 2534: .reg_offsets = gen7_register_offsets, 2535: .probe = gen7_hwsched_probe, 2536: .snapshot = gen7_hwsched_snapshot, 2537: .irq_handler = gen7_hwsched_irq_handler, 2538: .iommu_fault_block = gen7_iommu_fault_block, 2539: .context_detach = gen7_hwsched_context_detach, 2540: .read_alwayson = gen7_read_alwayson, 2541: .reset = gen7_hwsched_reset_replay, 2542: .power_ops = &gen7_hwsched_power_ops, 2543: .power_stats = gen7_power_stats, 2544: .hw_isidle = gen7_hw_isidle, 2545: .add_to_va_minidump = gen7_hwsched_add_to_minidump, 2546: .gx_is_on = gen7_gmu_gx_is_on, 2547: .send_recurring_cmdobj = gen7_hwsched_send_recurring_cmdobj, 2548: .perfcounter_remove = gen7_perfcounter_remove, 2549: .set_isdb_breakpoint_registers = gen7_set_isdb_breakpoint_registers, 2550: .context_destroy = gen7_hwsched_context_destroy, 2551: .lpac_store = gen7_lpac_store, 2552: .get_uche_trap_base = gen7_get_uche_trap_base, 2553: .fault_header = gen7_fault_header, 2554: .lpac_fault_header = gen7_lpac_fault_header, 2555: .acquire_cp_semaphore = gen7_acquire_cp_semaphore, 2556: .release_cp_semaphore = gen7_release_cp_semaphore, 2557: }, 2558: .hfi_probe = gen7_hwsched_hfi_probe, 2559: .hfi_remove = gen7_hwsched_hfi_remove, 2560: .handle_watchdog = gen7_hwsched_handle_watchdog, 2561: }; 2562: 2563: const struct gen7_gpudev adreno_gen7_gmu_gpudev = { 2564: .base = { 2565: .reg_offsets = gen7_register_offsets, 2566: .probe = gen7_gmu_device_probe, 2567: .snapshot = gen7_gmu_snapshot, 2568: .irq_handler = gen7_irq_handler, 2569: .rb_start = gen7_rb_start, 2570: .gpu_keepalive = gen7_gpu_keepalive, 2571: .hw_isidle = gen7_hw_isidle, 2572: .iommu_fault_block = gen7_iommu_fault_block, 2573: .reset = gen7_gmu_reset, 2574: .preemption_schedule = gen7_preemption_schedule, 2575: .read_alwayson = gen7_read_alwayson, 2576: .power_ops = &gen7_gmu_power_ops, 2577: .remove = gen7_remove, 2578: .ringbuffer_submitcmd = gen7_ringbuffer_submitcmd, 2579: .power_stats = gen7_power_stats, 2580: .add_to_va_minidump = gen7_gmu_add_to_minidump, 2581: .gx_is_on = gen7_gmu_gx_is_on, 2582: .perfcounter_remove = gen7_perfcounter_remove, 2583: .set_isdb_breakpoint_registers = gen7_set_isdb_breakpoint_registers, 2584: .swfuse_irqctrl = gen7_swfuse_irqctrl, 2585: .get_uche_trap_base = gen7_get_uche_trap_base, 2586: .fault_header = gen7_fault_header, 2587: .acquire_cp_semaphore = gen7_acquire_cp_semaphore, 2588: .release_cp_semaphore = gen7_release_cp_semaphore, 2589: }, 2590: .hfi_probe = gen7_gmu_hfi_probe, 2591: .handle_watchdog = gen7_gmu_handle_watchdog, 2592: }; --- FILE: \adreno_gen7.h | HITS: 5 --- MATCH LINES: 227, 229, 233, 235, 244 215: 216: #define GEN7_CP_RB_CNTL_DEFAULT \ 217: (FIELD_PREP(GENMASK(7, 0), ilog2(KGSL_RB_DWORDS >> 1)) | \ 218: FIELD_PREP(GENMASK(12, 8), ilog2(4))) 219: 220: /* Size of the CP_INIT pm4 stream in dwords */ 221: #define GEN7_CP_INIT_DWORDS 10 222: 223: #define GEN7_INT_MASK \ 224: ((1 << GEN7_INT_AHBERROR) | \ 225: (1 << GEN7_INT_ATBASYNCFIFOOVERFLOW) | \ 226: (1 << GEN7_INT_GPCERROR) | \ 227: (1 << GEN7_INT_SWINTERRUPT) | \ 228: (1 << GEN7_INT_HWERROR) | \ 229: (1 << GEN7_INT_PM4CPINTERRUPT) | \ 230: (1 << GEN7_INT_RB_DONE_TS) | \ 231: (1 << GEN7_INT_CACHE_CLEAN_TS) | \ 232: (1 << GEN7_INT_ATBBUSOVERFLOW) | \ 233: (1 << GEN7_INT_HANGDETECTINTERRUPT) | \ 234: (1 << GEN7_INT_OUTOFBOUNDACCESS) | \ 235: (1 << GEN7_INT_UCHETRAPINTERRUPT) | \ 236: (1 << GEN7_INT_TSBWRITEERROR) | \ 237: (1 << GEN7_INT_SWFUSEVIOLATION)) 238: 239: #define GEN7_HWSCHED_INT_MASK \ 240: ((1 << GEN7_INT_AHBERROR) | \ 241: (1 << GEN7_INT_ATBASYNCFIFOOVERFLOW) | \ 242: (1 << GEN7_INT_ATBBUSOVERFLOW) | \ 243: (1 << GEN7_INT_OUTOFBOUNDACCESS) | \ 244: (1 << GEN7_INT_UCHETRAPINTERRUPT) | \ 245: (1 << GEN7_INT_TSBWRITEERROR)) 246: 247: /** 248: * to_gen7_core - return the gen7 specific GPU core struct 249: * @adreno_dev: An Adreno GPU device handle 250: * 251: * Returns: 252: * A pointer to the gen7 specific GPU core struct 253: */ 254: static inline const struct adreno_gen7_core * 255: to_gen7_core(struct adreno_device *adreno_dev) 256: { 257: const struct adreno_gpu_core *core = adreno_dev->gpucore; 258: 259: return container_of(core, struct adreno_gen7_core, base); 260: } 261: 262: /* Preemption functions */ 263: void gen7_preemption_trigger(struct adreno_device *adreno_dev, bool atomic); 264: void gen7_preemption_schedule(struct adreno_device *adreno_dev); 265: void gen7_preemption_start(struct adreno_device *adreno_dev); 266: int gen7_preemption_init(struct adreno_device *adreno_dev); 267: 268: u32 gen7_preemption_post_ibsubmit(struct adreno_device *adreno_dev, --- FILE: \adreno_gen7_gmu.c | HITS: 24 --- MATCH LINES: 638, 646, 650, 670, 673 626: return; 627: 628: if (req >= oob_boot_slumber) { 629: dev_err(GMU_PDEV_DEV(device), "Unsupported OOB clear %s\n", 630: oob_to_str(req)); 631: return; 632: } 633: 634: gmu_core_regwrite(device, GEN7_GMU_HOST2GMU_INTR_SET, clear); 635: trace_kgsl_gmu_oob_clear(clear); 636: } 637: 638: void gen7_gmu_irq_enable(struct adreno_device *adreno_dev) 639: { 640: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 641: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 642: struct gen7_hfi *hfi = &gmu->hfi; 643: 644: /* Clear pending IRQs and Unmask needed IRQs */ 645: gmu_core_regwrite(device, GEN7_GMU_GMU2HOST_INTR_CLR, UINT_MAX); 646: gmu_core_regwrite(device, GEN7_GMU_AO_HOST_INTERRUPT_CLR, UINT_MAX); 647: 648: gmu_core_regwrite(device, GEN7_GMU_GMU2HOST_INTR_MASK, 649: (unsigned int)~HFI_IRQ_MASK); 650: gmu_core_regwrite(device, GEN7_GMU_AO_HOST_INTERRUPT_MASK, 651: (unsigned int)~GMU_AO_INT_MASK); 652: 653: /* Enable all IRQs on host */ 654: enable_irq(hfi->irq); 655: enable_irq(gmu->irq); 656: } 657: 658: void gen7_gmu_irq_disable(struct adreno_device *adreno_dev) 659: { 660: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 661: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 662: struct gen7_hfi *hfi = &gmu->hfi; 663: 664: /* Disable all IRQs on host */ 665: disable_irq(gmu->irq); 666: disable_irq(hfi->irq); 667: 668: /* Mask all IRQs and clear pending IRQs */ 669: gmu_core_regwrite(device, GEN7_GMU_GMU2HOST_INTR_MASK, UINT_MAX); 670: gmu_core_regwrite(device, GEN7_GMU_AO_HOST_INTERRUPT_MASK, UINT_MAX); 671: 672: gmu_core_regwrite(device, GEN7_GMU_GMU2HOST_INTR_CLR, UINT_MAX); 673: gmu_core_regwrite(device, GEN7_GMU_AO_HOST_INTERRUPT_CLR, UINT_MAX); 674: } 675: 676: static int gen7_gmu_hfi_start_msg(struct adreno_device *adreno_dev) 677: { 678: struct hfi_start_cmd req; 679: int ret; 680: 681: ret = CMD_MSG_HDR(req, H2F_MSG_START); 682: if (ret) 683: return ret; 684: 685: return gen7_hfi_send_generic_req(adreno_dev, &req, sizeof(req)); 686: } 687: 688: static u32 gen7_rscc_tcsm_drv0_status_reglist[] = { 689: GEN7_RSCC_TCS0_DRV0_STATUS, 690: GEN7_RSCC_TCS1_DRV0_STATUS, 691: GEN7_RSCC_TCS2_DRV0_STATUS, 692: GEN7_RSCC_TCS3_DRV0_STATUS, 693: GEN7_RSCC_TCS4_DRV0_STATUS, 694: GEN7_RSCC_TCS5_DRV0_STATUS, 695: GEN7_RSCC_TCS6_DRV0_STATUS, 696: GEN7_RSCC_TCS7_DRV0_STATUS, 697: GEN7_RSCC_TCS8_DRV0_STATUS, MATCH LINES: 1395, 1412, 1415 1383: if (gen7_gmu_gx_is_on(adreno_dev) && adreno_smmu_is_stalled(adreno_dev)) { 1384: dev_err(GMU_PDEV_DEV(device), 1385: "Skipping NMI because SMMU is stalled\n"); 1386: goto done; 1387: } 1388: 1389: if (force) 1390: goto nmi; 1391: 1392: /* 1393: * We should not send NMI if there was a CM3 fault reported because we 1394: * don't want to overwrite the critical CM3 state captured by gmu before 1395: * it sent the CM3 fault interrupt. Also don't send NMI if GMU reset is 1396: * already active. We could have hit a GMU assert and NMI might have 1397: * already been triggered. 1398: */ 1399: 1400: /* make sure we're reading the latest cm3_fault */ 1401: smp_rmb(); 1402: 1403: if (atomic_read(&gmu->cm3_fault)) 1404: return; 1405: 1406: gmu_core_regread(device, GEN7_GMU_CM3_FW_INIT_RESULT, &result); 1407: 1408: if (result & 0xE00) 1409: return; 1410: 1411: nmi: 1412: /* Mask so there's no interrupt caused by NMI */ 1413: gmu_core_regwrite(device, GEN7_GMU_GMU2HOST_INTR_MASK, UINT_MAX); 1414: 1415: /* Make sure the interrupt is masked before causing it */ 1416: wmb(); 1417: 1418: /* This will cause the GMU to save it's internal state to ddr */ 1419: gmu_core_regrmw(device, GEN7_GMU_CM3_CFG, BIT(9), BIT(9)); 1420: 1421: /* Make sure the NMI is invoked before we proceed*/ 1422: wmb(); 1423: 1424: /* Wait for the NMI to be handled */ 1425: udelay(200); 1426: done: 1427: KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic, GMU_PDEV(device), ticks, gf_policy); 1428: } 1429: 1430: static void gen7_gmu_cooperative_reset(struct kgsl_device *device) 1431: { 1432: unsigned int result; 1433: 1434: gmu_core_regwrite(device, GEN7_GMU_CX_GMU_WDOG_CTRL, 0); 1435: gmu_core_regwrite(device, GEN7_GMU_HOST2GMU_INTR_SET, BIT(17)); 1436: 1437: /* 1438: * After triggering graceful death wait for snapshot ready 1439: * indication from GMU. MATCH LINES: 1487, 1488, 1489, 1495, 1498, 1507, 1508, 1512, 1523, 1528 1475: } 1476: 1477: static bool gen7_gmu_scales_bandwidth(struct kgsl_device *device) 1478: { 1479: return true; 1480: } 1481: 1482: void gen7_gmu_handle_watchdog(struct adreno_device *adreno_dev) 1483: { 1484: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1485: u32 mask; 1486: 1487: /* Temporarily mask the watchdog interrupt to prevent a storm */ 1488: gmu_core_regread(device, GEN7_GMU_AO_HOST_INTERRUPT_MASK, &mask); 1489: gmu_core_regwrite(device, GEN7_GMU_AO_HOST_INTERRUPT_MASK, 1490: (mask | GMU_INT_WDOG_BITE)); 1491: 1492: gen7_gmu_send_nmi(device, false, GMU_FAULT_PANIC_NONE); 1493: 1494: dev_err_ratelimited(GMU_PDEV_DEV(device), 1495: "GMU watchdog expired interrupt received\n"); 1496: } 1497: 1498: static irqreturn_t gen7_gmu_irq_handler(int irq, void *data) 1499: { 1500: struct kgsl_device *device = data; 1501: struct device *gmu_pdev_dev = GMU_PDEV_DEV(device); 1502: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1503: const struct gen7_gpudev *gen7_gpudev = 1504: to_gen7_gpudev(ADRENO_GPU_DEVICE(adreno_dev)); 1505: unsigned int status = 0; 1506: 1507: gmu_core_regread(device, GEN7_GMU_AO_HOST_INTERRUPT_STATUS, &status); 1508: gmu_core_regwrite(device, GEN7_GMU_AO_HOST_INTERRUPT_CLR, status); 1509: 1510: if (status & GMU_INT_HOST_AHB_BUS_ERR) 1511: dev_err_ratelimited(gmu_pdev_dev, 1512: "AHB bus error interrupt received\n"); 1513: 1514: if (status & GMU_INT_WDOG_BITE) 1515: gen7_gpudev->handle_watchdog(adreno_dev); 1516: 1517: if (status & GMU_INT_FENCE_ERR) { 1518: unsigned int fence_status; 1519: 1520: gmu_core_regread(device, GEN7_GMU_AHB_FENCE_STATUS, 1521: &fence_status); 1522: dev_err_ratelimited(gmu_pdev_dev, 1523: "FENCE error interrupt received %x\n", fence_status); 1524: } 1525: 1526: if (status & ~GMU_AO_INT_MASK) 1527: dev_err_ratelimited(gmu_pdev_dev, 1528: "Unhandled GMU interrupts 0x%lx\n", 1529: status & ~GMU_AO_INT_MASK); 1530: 1531: return IRQ_HANDLED; 1532: } 1533: 1534: void gen7_gmu_aop_send_acd_state(struct gen7_gmu_device *gmu, bool flag) 1535: { 1536: struct kgsl_device *device = KGSL_DEVICE(gen7_gmu_to_adreno(gmu)); 1537: char msg_buf[36]; 1538: u32 size; 1539: int ret; 1540: 1541: if (IS_ERR_OR_NULL(gmu->qmp) && IS_ERR_OR_NULL(gmu->mailbox.channel)) 1542: return; 1543: 1544: size = scnprintf(msg_buf, sizeof(msg_buf), 1545: "{class: gpu, res: acd, val: %d}", flag); 1546: 1547: /* mailbox controller expects 4-byte aligned buffer */ 1548: size = ALIGN((size + 1), SZ_4); 1549: 1550: if (gmu->qmp) { 1551: ret = qmp_send(gmu->qmp, msg_buf, size); 1552: } else { MATCH LINES: 1641 1629: goto clks_gdsc_off; 1630: 1631: ret = gen7_gmu_itcm_shadow(adreno_dev); 1632: if (ret) 1633: goto clks_gdsc_off; 1634: 1635: ret = gen7_scm_gpu_init_cx_regs(adreno_dev); 1636: if (ret) 1637: goto clks_gdsc_off; 1638: 1639: gen7_gmu_register_config(adreno_dev); 1640: 1641: gen7_gmu_irq_enable(adreno_dev); 1642: 1643: /* Vote for minimal DDR BW for GMU to init */ 1644: level = pwr->pwrlevels[pwr->default_pwrlevel].bus_min; 1645: icc_set_bw(pwr->icc_path, 0, kBps_to_icc(pwr->ddr_table[level])); 1646: 1647: /* Clear any GPU faults that might have been left over */ 1648: adreno_clear_gpu_fault(adreno_dev); 1649: 1650: ret = gen7_gmu_device_start(adreno_dev); 1651: if (ret) 1652: goto err; 1653: 1654: if (!test_bit(GMU_PRIV_PDC_RSC_LOADED, &gmu->flags)) { 1655: ret = gen7_load_pdc_ucode(adreno_dev); 1656: if (ret) 1657: goto err; 1658: 1659: gen7_load_rsc_ucode(adreno_dev); 1660: set_bit(GMU_PRIV_PDC_RSC_LOADED, &gmu->flags); 1661: } 1662: 1663: ret = gen7_gmu_hfi_start(adreno_dev); 1664: if (ret) 1665: goto err; MATCH LINES: 1745 1733: gen7_cx_timer_init(adreno_dev); 1734: 1735: ret = gen7_rscc_wakeup_sequence(adreno_dev); 1736: if (ret) 1737: goto clks_gdsc_off; 1738: 1739: ret = gen7_gmu_load_fw(adreno_dev); 1740: if (ret) 1741: goto clks_gdsc_off; 1742: 1743: gen7_gmu_register_config(adreno_dev); 1744: 1745: gen7_gmu_irq_enable(adreno_dev); 1746: 1747: /* Clear any GPU faults that might have been left over */ 1748: adreno_clear_gpu_fault(adreno_dev); 1749: 1750: ret = gen7_gmu_device_start(adreno_dev); 1751: if (ret) 1752: goto err; 1753: 1754: ret = gen7_gmu_hfi_start(adreno_dev); 1755: if (ret) 1756: goto err; 1757: 1758: ret = gen7_hfi_start(adreno_dev); 1759: if (ret) 1760: goto err; 1761: 1762: device->gmu_fault = false; 1763: 1764: kgsl_pwrctrl_set_state(device, KGSL_STATE_AWARE); 1765: 1766: return 0; 1767: 1768: err: 1769: gen7_gmu_irq_disable(adreno_dev); MATCH LINES: 2185 2173: /* GMU sysfs nodes setup */ 2174: ret = kobject_init_and_add(&gmu->log_kobj, &log_kobj_type, &dev->kobj, "log"); 2175: if (ret) 2176: dev_err(dev, "Failed to add log_kobj: %d\n", ret); 2177: 2178: ret = kobject_init_and_add(&gmu->stats_kobj, &stats_kobj_type, &dev->kobj, "stats"); 2179: if (ret) 2180: dev_err(dev, "Failed to add stats_kobj: %d\n", ret); 2181: 2182: spin_lock_init(&gmu->hfi.cmdq_lock); 2183: 2184: gmu->irq = kgsl_request_irq(GMU_PDEV(device), "gmu", NULL, -EINVAL, 2185: gen7_gmu_irq_handler, device); 2186: 2187: if (gmu->irq >= 0) 2188: return 0; 2189: 2190: ret = gmu->irq; 2191: 2192: error: 2193: gen7_gmu_remove(device); 2194: return ret; 2195: } 2196: 2197: int gen7_halt_gbif(struct adreno_device *adreno_dev) 2198: { 2199: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2200: int ret; 2201: 2202: /* Halt new client requests */ 2203: kgsl_regwrite(device, GEN7_GBIF_HALT, GEN7_GBIF_CLIENT_HALT_MASK); 2204: ret = adreno_wait_for_halt_ack(device, 2205: GEN7_GBIF_HALT_ACK, GEN7_GBIF_CLIENT_HALT_MASK); 2206: 2207: /* Halt all AXI requests */ 2208: kgsl_regwrite(device, GEN7_GBIF_HALT, GEN7_GBIF_ARB_HALT_MASK); 2209: ret = adreno_wait_for_halt_ack(device, MATCH LINES: 2513, 2515 2501: set_bit(ADRENO_DEVICE_FIRST_BOOT_DONE, &adreno_dev->priv); 2502: 2503: kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE); 2504: 2505: return 0; 2506: } 2507: 2508: static bool gen7_irq_pending(struct adreno_device *adreno_dev) 2509: { 2510: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2511: u32 status; 2512: 2513: kgsl_regread(device, GEN7_RBBM_INT_0_STATUS, &status); 2514: 2515: /* Return busy if a interrupt is pending */ 2516: return ((status & adreno_dev->irq_mask) || 2517: atomic_read(&adreno_dev->pending_irq_refcnt)); 2518: } 2519: 2520: static int gen7_power_off(struct adreno_device *adreno_dev) 2521: { 2522: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2523: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2524: int ret; 2525: 2526: WARN_ON(!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)); 2527: 2528: adreno_check_idle(device); 2529: 2530: kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); 2531: 2532: ret = gen7_gmu_oob_set(device, oob_gpu); 2533: if (ret) 2534: goto no_gx_power; 2535: 2536: if (gen7_irq_pending(adreno_dev)) { 2537: gen7_gmu_oob_clear(device, oob_gpu); 2538: return -EBUSY; 2539: } MATCH LINES: 2859 2847: 2848: /* Attempt to reboot the gmu and gpu */ 2849: return gen7_boot(adreno_dev); 2850: } 2851: 2852: int gen7_gmu_hfi_probe(struct adreno_device *adreno_dev) 2853: { 2854: struct platform_device *gmu_pdev = GMU_PDEV(KGSL_DEVICE(adreno_dev)); 2855: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2856: struct gen7_hfi *hfi = &gmu->hfi; 2857: 2858: hfi->irq = kgsl_request_irq(gmu_pdev, "hfi", NULL, -EINVAL, 2859: gen7_hfi_irq_handler, KGSL_DEVICE(adreno_dev)); 2860: 2861: return hfi->irq < 0 ? hfi->irq : 0; 2862: } 2863: 2864: int gen7_gmu_add_to_minidump(struct adreno_device *adreno_dev) 2865: { 2866: struct gen7_device *gen7_dev = container_of(adreno_dev, 2867: struct gen7_device, adreno_dev); 2868: int ret; 2869: 2870: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, KGSL_GEN7_DEVICE, 2871: (void *)(gen7_dev), sizeof(struct gen7_device)); 2872: if (ret) 2873: return ret; 2874: 2875: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, KGSL_GMU_LOG_ENTRY, 2876: gen7_dev->gmu.gmu_log->hostptr, gen7_dev->gmu.gmu_log->size); 2877: if (ret) 2878: return ret; 2879: 2880: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, KGSL_HFIMEM_ENTRY, 2881: gen7_dev->gmu.hfi.hfi_mem->hostptr, gen7_dev->gmu.hfi.hfi_mem->size); 2882: 2883: return ret; --- FILE: \adreno_gen7_gmu.h | HITS: 8 --- MATCH LINES: 25, 47 13: #include "kgsl_gmu_core.h" 14: 15: struct gen7_dcvs_table { 16: u32 gpu_level_num; 17: u32 gmu_level_num; 18: struct opp_gx_desc gx_votes[MAX_GX_LEVELS]; 19: struct opp_desc cx_votes[MAX_CX_LEVELS_LEGACY]; 20: }; 21: 22: /** 23: * struct gen7_gmu_device - GMU device structure 24: * @ver: GMU Version information 25: * @irq: GMU interrupt number 26: * @fw_image: GMU FW image 27: * @gmu_log: gmu event log memory 28: * @hfi: HFI controller 29: * @idle_level: Minimal GPU idle power level 30: * @mailbox: Messages to AOP for ACD enable/disable go through this 31: * @log_wptr_retention: Store the log wptr offset on slumber 32: */ 33: struct gen7_gmu_device { 34: int irq; 35: const struct firmware *fw_image; 36: struct kgsl_memdesc *gmu_log; 37: /** @gmu_init_scratch: Memory to store the initial HFI messages */ 38: struct kgsl_memdesc *gmu_init_scratch; 39: /** @gpu_boot_scratch: Memory to store the bootup HFI messages */ 40: struct kgsl_memdesc *gpu_boot_scratch; 41: struct gen7_hfi hfi; 42: unsigned int idle_level; 43: /** @qmp: Pointer to qmp struct used for AOP messages*/ 44: struct qmp *qmp; 45: struct kgsl_mailbox mailbox; 46: unsigned int log_wptr_retention; 47: /** @cm3_fault: whether gmu received a cm3 fault interrupt */ 48: atomic_t cm3_fault; 49: /** 50: * @itcm_shadow: Copy of the itcm block in firmware binary used for 51: * snapshot 52: */ 53: void *itcm_shadow; 54: /** @flags: Internal gmu flags */ 55: unsigned long flags; 56: /** @rscc_virt: Pointer where RSCC block is mapped */ 57: void __iomem *rscc_virt; 58: /** @log_stream_enable: GMU log streaming enable. Disabled by default */ 59: bool log_stream_enable; 60: /** @log_group_mask: Allows overriding default GMU log group mask */ 61: u32 log_group_mask; 62: struct kobject log_kobj; 63: /** @pdc_cfg_base: Base address of PDC cfg registers */ 64: void __iomem *pdc_cfg_base; 65: /** @num_oob_perfcntr: Number of active oob_perfcntr requests */ 66: u32 num_oob_perfcntr; 67: /** @acd_debug_val: DVM value to calibrate ACD for a level */ 68: u32 acd_debug_val; 69: /** @stats_enable: GMU stats feature enable */ 70: bool stats_enable; 71: /** @stats_mask: GMU performance countables to enable */ MATCH LINES: 130, 136 118: int gen7_gmu_device_probe(struct platform_device *pdev, 119: u32 chipid, const struct adreno_gpu_core *gpucore); 120: 121: /** 122: * gen7_gmu_reset - Reset and restart the gmu 123: * @adreno_dev: Pointer to the adreno device 124: * 125: * Return: 0 on success or negative error on failure 126: */ 127: int gen7_gmu_reset(struct adreno_device *adreno_dev); 128: 129: /** 130: * gen7_enable_gpu_irq - Enable gpu interrupt 131: * @adreno_dev: Pointer to the adreno device 132: */ 133: void gen7_enable_gpu_irq(struct adreno_device *adreno_dev); 134: 135: /** 136: * gen7_disable_gpu_irq - Disable gpu interrupt 137: * @adreno_dev: Pointer to the adreno device 138: */ 139: void gen7_disable_gpu_irq(struct adreno_device *adreno_dev); 140: 141: /** 142: * gen7_gmu_snapshot- Take snapshot for gmu targets 143: * @adreno_dev: Pointer to the adreno device 144: * @snapshot: Pointer to the snapshot structure 145: * 146: * Send an NMI to gmu if we hit a gmu fault. Then take gmu 147: * snapshot and carry on with rest of the gen7 snapshot 148: */ 149: void gen7_gmu_snapshot(struct adreno_device *adreno_dev, 150: struct kgsl_snapshot *snapshot); 151: 152: /** 153: * gen7_gmu_probe - Probe gen7 gmu resources 154: * @device: Pointer to the kgsl device 155: * @pdev: Pointer to the gmu platform device 156: * 157: * Probe the gmu and hfi resources 158: * 159: * Return: 0 on success or negative error on failure 160: */ MATCH LINES: 242, 245, 248 230: */ 231: void gen7_gmu_register_config(struct adreno_device *adreno_dev); 232: 233: /** 234: * gen7_gmu_version_info - Get gmu firmware version 235: * @adreno_dev: Pointer to the adreno device 236: * 237: * Return: 0 on success or negative error on failure 238: */ 239: int gen7_gmu_version_info(struct adreno_device *adreno_dev); 240: 241: /** 242: * gen7_gmu_irq_enable - Enable gmu interrupts 243: * @adreno_dev: Pointer to the adreno device 244: */ 245: void gen7_gmu_irq_enable(struct adreno_device *adreno_dev); 246: 247: /** 248: * gen7_gmu_irq_disable - Disaable gmu interrupts 249: * @adreno_dev: Pointer to the adreno device 250: */ 251: void gen7_gmu_irq_disable(struct adreno_device *adreno_dev); 252: 253: /** 254: * gen7_gmu_suspend - Hard reset the gpu and gmu 255: * @adreno_dev: Pointer to the adreno device 256: * @force:Set to true to enforce a hard reset 257: * 258: * In case we hit a gmu fault, hard reset the gpu and gmu 259: * to recover from the fault 260: */ 261: void gen7_gmu_suspend(struct adreno_device *adreno_dev, bool force); 262: 263: /** 264: * gen7_gmu_oob_set - send gmu oob request 265: * @device: Pointer to the kgsl device 266: * @req: Type of oob request as defined in enum oob_request 267: * 268: * Request gmu to keep gpu powered up till the oob is cleared 269: * 270: * Return: 0 on success or negative error on failure 271: */ 272: int gen7_gmu_oob_set(struct kgsl_device *device, enum oob_request oob); MATCH LINES: 350 338: * gen7_load_rsc_ucode - Load rscc sequence 339: * @adreno_dev: Pointer to the adreno device 340: */ 341: void gen7_load_rsc_ucode(struct adreno_device *adreno_dev); 342: 343: /** 344: * gen7_gmu_remove - Clean up gmu probed resources 345: * @device: Pointer to the kgsl device 346: */ 347: void gen7_gmu_remove(struct kgsl_device *device); 348: 349: /** 350: * gen7_gmu_handle_watchdog - Handle watchdog interrupt 351: * @adreno_dev: Pointer to the adreno device 352: */ 353: void gen7_gmu_handle_watchdog(struct adreno_device *adreno_dev); 354: 355: /** 356: * gen7_gmu_send_nmi - Send NMI to GMU 357: * @device: Pointer to the kgsl device 358: * @gf_policy: GMU fault panic setting policy 359: * @force: Boolean to forcefully send NMI irrespective of GMU state 360: */ 361: void gen7_gmu_send_nmi(struct kgsl_device *device, bool force, 362: enum gmu_fault_panic_policy gf_policy); 363: 364: /** 365: * gen7_gmu_add_to_minidump - Register gen7_device with va minidump 366: * @adreno_dev: Pointer to the adreno device 367: */ 368: int gen7_gmu_add_to_minidump(struct adreno_device *adreno_dev); 369: #endif --- FILE: \adreno_gen7_hfi.c | HITS: 7 --- MATCH LINES: 168, 172 156: *msg = RECORD_MSG_HDR(*msg); 157: 158: ret = gen7_hfi_queue_write(adreno_dev, HFI_CMD_ID, msg, size_bytes); 159: 160: /* 161: * Some messages like ACD table and perf table are saved in memory, so we need 162: * to reset the header to make sure we do not send a record enabled bit incase 163: * we change the warmboot setting from debugfs 164: */ 165: *msg = CLEAR_RECORD_MSG_HDR(*msg); 166: /* 167: * Memory barrier to make sure packet and write index are written before 168: * an interrupt is raised 169: */ 170: wmb(); 171: 172: /* Send interrupt to GMU to receive the message */ 173: if (!ret) 174: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), 175: GEN7_GMU_HOST2GMU_INTR_SET, 0x1); 176: 177: spin_unlock(&hfi->cmdq_lock); 178: 179: return ret; 180: } 181: 182: /* Sizes of the queue and message are in unit of dwords */ 183: static void init_queues(struct adreno_device *adreno_dev) 184: { 185: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 186: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 187: int i; 188: struct hfi_queue_table *tbl; 189: struct hfi_queue_header *hdr; 190: struct { 191: unsigned int idx; 192: unsigned int pri; 193: unsigned int status; 194: } queue[HFI_QUEUE_MAX] = { 195: { HFI_CMD_ID, HFI_CMD_PRI, HFI_QUEUE_STATUS_ENABLED }, 196: { HFI_MSG_ID, HFI_MSG_PRI, HFI_QUEUE_STATUS_ENABLED }, MATCH LINES: 341 329: 330: rc = poll_gmu_reg(adreno_dev, GEN7_GMU_GMU2HOST_INTR_INFO, 331: HFI_IRQ_MSGQ_MASK, HFI_IRQ_MSGQ_MASK, HFI_RSP_TIMEOUT); 332: 333: if (rc) { 334: dev_err(GMU_PDEV_DEV(device), 335: "Timed out waiting on ack for 0x%8.8x (id %d, sequence %d)\n", 336: cmd[0], MSG_HDR_GET_ID(*cmd), MSG_HDR_GET_SEQNUM(*cmd)); 337: gmu_core_fault_snapshot(device, GMU_FAULT_SEND_CMD_WAIT_INLINE); 338: return rc; 339: } 340: 341: /* Clear the interrupt */ 342: gmu_core_regwrite(device, GEN7_GMU_GMU2HOST_INTR_CLR, 343: HFI_IRQ_MSGQ_MASK); 344: 345: rc = gen7_hfi_process_queue(gmu, HFI_MSG_ID, ret_cmd); 346: 347: return rc; 348: } 349: 350: int gen7_hfi_send_generic_req(struct adreno_device *adreno_dev, void *cmd, u32 size_bytes) 351: { 352: struct pending_cmd ret_cmd; 353: int rc; 354: 355: memset(&ret_cmd, 0, sizeof(ret_cmd)); 356: 357: rc = gen7_hfi_send_cmd_wait_inline(adreno_dev, cmd, size_bytes, &ret_cmd); 358: if (rc) 359: return rc; 360: 361: if (ret_cmd.results[2]) { 362: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 363: 364: dev_err(GMU_PDEV_DEV(device), 365: "HFI ACK failure: Req=0x%8.8X, Result=0x%8.8X\n", MATCH LINES: 796, 797, 810, 818 784: } 785: 786: void gen7_hfi_stop(struct adreno_device *adreno_dev) 787: { 788: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 789: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 790: 791: kgsl_pwrctrl_axi(device, false); 792: 793: clear_bit(GMU_PRIV_HFI_STARTED, &gmu->flags); 794: } 795: 796: /* HFI interrupt handler */ 797: irqreturn_t gen7_hfi_irq_handler(int irq, void *data) 798: { 799: struct kgsl_device *device = data; 800: struct gen7_gmu_device *gmu = to_gen7_gmu(ADRENO_DEVICE(device)); 801: unsigned int status = 0; 802: 803: gmu_core_regread(device, GEN7_GMU_GMU2HOST_INTR_INFO, &status); 804: gmu_core_regwrite(device, GEN7_GMU_GMU2HOST_INTR_CLR, HFI_IRQ_MASK); 805: 806: if (status & HFI_IRQ_DBGQ_MASK) 807: gen7_hfi_process_queue(gmu, HFI_DBG_ID, NULL); 808: if (status & HFI_IRQ_CM3_FAULT_MASK) { 809: dev_err_ratelimited(GMU_PDEV_DEV(device), 810: "GMU CM3 fault interrupt received\n"); 811: atomic_set(&gmu->cm3_fault, 1); 812: 813: /* make sure other CPUs see the update */ 814: smp_wmb(); 815: } 816: if (status & ~HFI_IRQ_MASK) 817: dev_err_ratelimited(GMU_PDEV_DEV(device), 818: "Unhandled HFI interrupts 0x%lx\n", 819: status & ~HFI_IRQ_MASK); 820: 821: return IRQ_HANDLED; 822: } --- FILE: \adreno_gen7_hfi.h | HITS: 3 --- MATCH LINES: 15, 38, 39 3: * Copyright (c) 2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: #ifndef __ADRENO_GEN7_HFI_H 7: #define __ADRENO_GEN7_HFI_H 8: 9: #include "adreno_hfi.h" 10: 11: /** 12: * struct gen7_hfi - HFI control structure 13: */ 14: struct gen7_hfi { 15: /** @irq: HFI interrupt line */ 16: int irq; 17: /** @seqnum: atomic counter that is incremented for each message sent. 18: * The value of the counter is used as sequence number for HFI message. 19: */ 20: atomic_t seqnum; 21: /** @hfi_mem: Memory descriptor for the hfi memory */ 22: struct kgsl_memdesc *hfi_mem; 23: /** @bw_table: HFI BW table buffer */ 24: struct hfi_bwtable_cmd bw_table; 25: /** @acd_table: HFI table for ACD data */ 26: struct hfi_acd_table_cmd acd_table; 27: /** @cmdq_lock: Spinlock for accessing the cmdq */ 28: spinlock_t cmdq_lock; 29: /** 30: * @wb_set_record_bitmask: Bitmask to enable or disable the recording 31: * of messages in the GMU scratch. 32: */ 33: unsigned long wb_set_record_bitmask[BITS_TO_LONGS(HFI_MAX_ID)]; 34: }; 35: 36: struct gen7_gmu_device; 37: 38: /* gen7_hfi_irq_handler - IRQ handler for HFI interripts */ 39: irqreturn_t gen7_hfi_irq_handler(int irq, void *data); 40: 41: /** 42: * gen7_hfi_start - Send the various HFIs during device boot up 43: * @adreno_dev: Pointer to the adreno device 44: * 45: * Return: 0 on success or negative error on failure 46: */ 47: int gen7_hfi_start(struct adreno_device *adreno_dev); 48: 49: /** 50: * gen7_hfi_start - Send the various HFIs during device boot up 51: * @adreno_dev: Pointer to the adreno device 52: * 53: * Return: 0 on success or negative error on failure 54: */ 55: void gen7_hfi_stop(struct adreno_device *adreno_dev); 56: 57: /** 58: * gen7_hfi_init - Initialize hfi resources 59: * @adreno_dev: Pointer to the adreno device 60: * 61: * This function allocates and sets up hfi queues 62: * when a process creates the very first kgsl instance 63: * --- FILE: \adreno_gen7_hwsched.c | HITS: 11 --- MATCH LINES: 23, 29, 30, 31 11: #include "adreno_gen7_hwsched.h" 12: #include "adreno_snapshot.h" 13: #include "kgsl_bus.h" 14: #include "kgsl_device.h" 15: #include "kgsl_gmu_core.h" 16: #include "kgsl_trace.h" 17: #include "kgsl_util.h" 18: 19: static void _wakeup_hw_fence_waiters(struct adreno_device *adreno_dev, u32 fault) 20: { 21: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 22: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 23: bool lock = !in_interrupt(); 24: 25: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags)) 26: return; 27: 28: /* 29: * We could be in interrupt context here, which means we need to use spin_lock_irqsave 30: * (which disables interrupts) everywhere we take this lock. Instead of that, simply 31: * avoid taking this lock if we are recording a fault from an interrupt handler. 32: */ 33: if (lock) 34: spin_lock(&hwf->lock); 35: 36: clear_bit(GEN7_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags); 37: 38: /* Avoid creating new hardware fences until recovery is complete */ 39: set_bit(GEN7_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags); 40: 41: if (!lock) 42: /* 43: * This barrier ensures that the above bitops complete before we wake up the waiters 44: */ 45: smp_wmb(); 46: else 47: spin_unlock(&hwf->lock); 48: 49: wake_up_all(&hwf->unack_wq); 50: 51: kgsl_delete_timer(&hfi->hw_fence_timer); 52: } 53: 54: void gen7_hwsched_fault(struct adreno_device *adreno_dev, u32 fault) 55: { MATCH LINES: 217, 222 205: if (ret) 206: goto clks_gdsc_off; 207: 208: gen7_gmu_register_config(adreno_dev); 209: 210: ret = gen7_gmu_version_info(adreno_dev); 211: if (ret) 212: goto clks_gdsc_off; 213: 214: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2) 215: set_bit(ADRENO_HWSCHED_CTX_BAD_LEGACY, &adreno_dev->hwsched.flags); 216: 217: gen7_gmu_irq_enable(adreno_dev); 218: 219: /* Vote for minimal DDR BW for GMU to init */ 220: level = pwr->pwrlevels[pwr->default_pwrlevel].bus_min; 221: 222: /* From this GMU FW all RBBM interrupts are handled at GMU */ 223: if (device->gmu_core.ver.core >= GMU_VERSION(5, 01, 06)) 224: adreno_irq_free(adreno_dev); 225: 226: /* GMU supports force retire command from this GMU FW */ 227: if (gmu_core_capabilities_enabled(&device->gmu_core.common_caps, 228: FAC_FORCE_RETIRE_COMMAND)) 229: set_bit(ADRENO_HWSCHED_FORCE_RETIRE_GMU, &adreno_dev->hwsched.flags); 230: 231: icc_set_bw(pwr->icc_path, 0, kBps_to_icc(pwr->ddr_table[level])); 232: 233: /* Clear any hwsched faults that might have been left over */ 234: adreno_clear_gpu_fault(adreno_dev); 235: 236: ret = gen7_gmu_device_start(adreno_dev); 237: if (ret) 238: goto err; 239: 240: gen7_get_gpu_feature_info(adreno_dev); 241: 242: ret = gen7_hwsched_hfi_start(adreno_dev); 243: if (ret) 244: goto err; 245: 246: ret = gmu_core_clock_set_rate(device, 0); MATCH LINES: 326 314: gen7_cx_timer_init(adreno_dev); 315: 316: ret = gen7_rscc_wakeup_sequence(adreno_dev); 317: if (ret) 318: goto clks_gdsc_off; 319: 320: ret = gen7_gmu_load_fw(adreno_dev); 321: if (ret) 322: goto clks_gdsc_off; 323: 324: gen7_gmu_register_config(adreno_dev); 325: 326: gen7_gmu_irq_enable(adreno_dev); 327: 328: /* Clear any hwsched faults that might have been left over */ 329: adreno_clear_gpu_fault(adreno_dev); 330: 331: ret = gen7_gmu_device_start(adreno_dev); 332: if (ret) 333: goto err; 334: 335: ret = gen7_hwsched_hfi_start(adreno_dev); 336: if (ret) 337: goto err; 338: 339: ret = gmu_core_clock_set_rate(device, 0); 340: if (ret) { 341: gen7_hwsched_hfi_stop(adreno_dev); 342: goto err; 343: } 344: 345: device->gmu_fault = false; 346: 347: kgsl_pwrctrl_set_state(device, KGSL_STATE_AWARE); 348: 349: return 0; 350: err: MATCH LINES: 1193, 1194, 1196, 1202 1181: adreno_put_gpu_halt(adreno_dev); 1182: 1183: adreno_hwsched_start(adreno_dev); 1184: 1185: clear_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags); 1186: } 1187: 1188: void gen7_hwsched_handle_watchdog(struct adreno_device *adreno_dev) 1189: { 1190: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1191: u32 mask; 1192: 1193: /* Temporarily mask the watchdog interrupt to prevent a storm */ 1194: gmu_core_regread(device, GEN7_GMU_AO_HOST_INTERRUPT_MASK, 1195: &mask); 1196: gmu_core_regwrite(device, GEN7_GMU_AO_HOST_INTERRUPT_MASK, 1197: (mask | GMU_INT_WDOG_BITE)); 1198: 1199: gen7_gmu_send_nmi(device, false, GMU_FAULT_PANIC_NONE); 1200: 1201: dev_err_ratelimited(GMU_PDEV_DEV(device), 1202: "GMU watchdog expired interrupt received\n"); 1203: 1204: gen7_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 1205: } 1206: 1207: static void gen7_hwsched_drain_ctxt_unregister(struct adreno_device *adreno_dev) 1208: { 1209: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 1210: struct pending_cmd *cmd = NULL; 1211: 1212: read_lock(&hfi->msglock); 1213: 1214: list_for_each_entry(cmd, &hfi->msglist, node) { 1215: if (MSG_HDR_GET_ID(cmd->sent_hdr) == H2F_MSG_UNREGISTER_CONTEXT) 1216: complete(&cmd->complete); 1217: } 1218: 1219: read_unlock(&hfi->msglock); 1220: } 1221: 1222: /** 1223: * process_context_hw_fences_after_reset - This function processes all hardware fences that were 1224: * sent to GMU prior to recovery. If a fence is not retired by the GPU, and the context is still 1225: * good, then move them to the reset list. 1226: */ --- FILE: \adreno_gen7_hwsched.h | HITS: 2 --- MATCH LINES: 54, 71 42: 43: /** 44: * gen7_hwsched_snapshot - take gen7 hwsched snapshot 45: * @adreno_dev: Pointer to the adreno device 46: * @snapshot: Pointer to the snapshot instance 47: * 48: * Snapshot the faulty ib and then snapshot rest of gen7 gmu things 49: */ 50: void gen7_hwsched_snapshot(struct adreno_device *adreno_dev, 51: struct kgsl_snapshot *snapshot); 52: 53: /** 54: * gen7_hwsched_handle_watchdog - Handle watchdog interrupt 55: * @adreno_dev: Pointer to the adreno device 56: */ 57: void gen7_hwsched_handle_watchdog(struct adreno_device *adreno_dev); 58: 59: /** 60: * gen7_hwsched_add_to_minidump - Register hwsched_device with va minidump 61: * @adreno_dev: Pointer to the adreno device 62: */ 63: int gen7_hwsched_add_to_minidump(struct adreno_device *adreno_dev); 64: 65: /** 66: * gen7_hwsched_send_recurring_cmdobj - Dispatch IBs to GMU 67: * @adreno_dev: Pointer to adreno device structure 68: * @cmdobj: The command object which needs to be submitted 69: * 70: * This function is used to register the context if needed and submit 71: * recurring IBs to the GMU. Upon receiving ipc interrupt GMU will submit 72: * recurring IBs to GPU. 73: 74: * Return: 0 on success and negative error on failure 75: */ 76: int gen7_hwsched_send_recurring_cmdobj(struct adreno_device *adreno_dev, 77: struct kgsl_drawobj_cmd *cmdobj); 78: 79: /** 80: * gen7_hwsched_fault - Set hwsched fault to request recovery 81: * @adreno_dev: A handle to adreno device 82: * @fault: The type of fault 83: */ 84: void gen7_hwsched_fault(struct adreno_device *adreno_dev, u32 fault); 85: 86: #endif --- FILE: \adreno_gen7_hwsched_hfi.c | HITS: 28 --- MATCH LINES: 289, 307 277: struct hfi_context_bad_cmd_legacy *cmd = adreno_dev->hwsched.ctxt_bad; 278: 279: switch (cmd->error) { 280: case GMU_GPU_HW_HANG: 281: dev_crit_ratelimited(gmu_pdev_dev, "MISC: GPU hang detected\n"); 282: break; 283: case GMU_GPU_SW_HANG: 284: dev_crit_ratelimited(gmu_pdev_dev, "gpu timeout ctx %u ts %u\n", 285: cmd->ctxt_id, cmd->ts); 286: break; 287: case GMU_CP_OPCODE_ERROR: 288: dev_crit_ratelimited(gmu_pdev_dev, 289: "CP opcode error interrupt | opcode=0x%8.8x\n", 290: gen7_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 291: KEY_CP_OPCODE_ERROR)); 292: break; 293: case GMU_CP_PROTECTED_ERROR: { 294: u32 status = gen7_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 295: KEY_CP_PROTECTED_ERROR); 296: 297: dev_crit_ratelimited(gmu_pdev_dev, 298: "CP | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 299: status & (1 << 20) ? "READ" : "WRITE", 300: status & 0x3FFFF, status); 301: } 302: break; 303: case GMU_CP_ILLEGAL_INST_ERROR: 304: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 305: break; 306: case GMU_CP_UCODE_ERROR: 307: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 308: break; 309: case GMU_CP_HW_FAULT_ERROR: 310: dev_crit_ratelimited(gmu_pdev_dev, 311: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 312: gen7_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 313: KEY_CP_HW_FAULT)); 314: break; 315: case GMU_GPU_PREEMPT_TIMEOUT: { 316: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 317: 318: cur = gen7_hwsched_lookup_key_value_legacy(adreno_dev, 319: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 320: next = gen7_hwsched_lookup_key_value_legacy(adreno_dev, 321: PAYLOAD_PREEMPT_TIMEOUT, 322: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 323: cur_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_RPTR); 324: cur_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_WPTR); 325: next_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_RPTR); 326: next_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_WPTR); 327: 328: dev_crit_ratelimited(gmu_pdev_dev, 329: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 330: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 331: } MATCH LINES: 362, 375, 391 350: } 351: break; 352: case GMU_CP_BV_HW_FAULT_ERROR: 353: dev_crit_ratelimited(gmu_pdev_dev, 354: "CP BV | Ringbuffer HW fault | status=0x%8.8x\n", 355: gen7_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 356: KEY_CP_BV_HW_FAULT)); 357: break; 358: case GMU_CP_BV_ILLEGAL_INST_ERROR: 359: dev_crit_ratelimited(gmu_pdev_dev, "CP BV Illegal instruction error\n"); 360: break; 361: case GMU_CP_BV_UCODE_ERROR: 362: dev_crit_ratelimited(gmu_pdev_dev, "CP BV ucode error interrupt\n"); 363: break; 364: case GMU_GPU_SW_FUSE_VIOLATION: 365: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: SW Feature Fuse violation status=0x%8.8x\n", 366: gen7_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS, 367: KEY_SWFUSE_VIOLATION_FAULT)); 368: break; 369: case GMU_GPU_AQE0_OPCODE_ERROR: 370: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 opcode error | opcode=0x%8.8x\n", 371: gen7_hwsched_lookup_key_value_legacy(adreno_dev, 372: PAYLOAD_FAULT_REGS, KEY_AQE0_OPCODE_ERROR)); 373: break; 374: case GMU_GPU_AQE0_UCODE_ERROR: 375: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 ucode error interrupt\n"); 376: break; 377: case GMU_GPU_AQE0_HW_FAULT_ERROR: 378: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 HW fault | status=0x%8.8x\n", 379: gen7_hwsched_lookup_key_value_legacy(adreno_dev, 380: PAYLOAD_FAULT_REGS, KEY_AQE0_HW_FAULT)); 381: break; 382: case GMU_GPU_AQE0_ILLEGAL_INST_ERROR: 383: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 Illegal instruction error\n"); 384: break; 385: case GMU_GPU_AQE1_OPCODE_ERROR: 386: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 opcode error | opcode=0x%8.8x\n", 387: gen7_hwsched_lookup_key_value_legacy(adreno_dev, 388: PAYLOAD_FAULT_REGS, KEY_AQE1_OPCODE_ERROR)); 389: break; 390: case GMU_GPU_AQE1_UCODE_ERROR: 391: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 ucode error interrupt\n"); 392: break; 393: case GMU_GPU_AQE1_HW_FAULT_ERROR: 394: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 HW fault | status=0x%8.8x\n", 395: gen7_hwsched_lookup_key_value_legacy(adreno_dev, 396: PAYLOAD_FAULT_REGS, KEY_AQE1_HW_FAULT)); 397: break; 398: case GMU_GPU_AQE1_ILLEGAL_INST_ERROR: 399: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 Illegal instruction error\n"); 400: break; 401: case GMU_SYNCOBJ_TIMEOUT_ERROR: 402: dev_crit_ratelimited(gmu_pdev_dev, "syncobj timeout ctx %d ts %u\n", 403: cmd->ctxt_id, cmd->ts); 404: find_timeout_syncobj(adreno_dev, cmd->ctxt_id, cmd->ts); 405: break; 406: case GMU_CP_UNKNOWN_ERROR: 407: fallthrough; 408: default: 409: dev_crit_ratelimited(gmu_pdev_dev, "Unknown GPU fault: %u\n", 410: cmd->error); 411: break; 412: } 413: } 414: 415: /* Look up a particular key's value for a given type of payload */ MATCH LINES: 462, 480 450: return false; 451: 452: switch (cmd->error) { 453: case GMU_GPU_HW_HANG: 454: dev_crit_ratelimited(gmu_pdev_dev, "MISC: GPU hang detected\n"); 455: break; 456: case GMU_GPU_SW_HANG: 457: dev_crit_ratelimited(gmu_pdev_dev, "gpu timeout ctx %u ts %u\n", 458: cmd->gc.ctxt_id, cmd->gc.ts); 459: break; 460: case GMU_CP_OPCODE_ERROR: 461: dev_crit_ratelimited(gmu_pdev_dev, 462: "CP opcode error interrupt | opcode=0x%8.8x\n", 463: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 464: KEY_CP_OPCODE_ERROR)); 465: break; 466: case GMU_CP_PROTECTED_ERROR: { 467: u32 status = gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 468: KEY_CP_PROTECTED_ERROR); 469: 470: dev_crit_ratelimited(gmu_pdev_dev, 471: "CP | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 472: status & (1 << 20) ? "READ" : "WRITE", 473: status & 0x3FFFF, status); 474: } 475: break; 476: case GMU_CP_ILLEGAL_INST_ERROR: 477: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 478: break; 479: case GMU_CP_UCODE_ERROR: 480: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 481: break; 482: case GMU_CP_HW_FAULT_ERROR: 483: dev_crit_ratelimited(gmu_pdev_dev, 484: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 485: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 486: KEY_CP_HW_FAULT)); 487: break; 488: case GMU_GPU_PREEMPT_TIMEOUT: { 489: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 490: 491: cur = gen7_hwsched_lookup_key_value(adreno_dev, 492: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 493: next = gen7_hwsched_lookup_key_value(adreno_dev, 494: PAYLOAD_PREEMPT_TIMEOUT, 495: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 496: cur_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_RPTR); 497: cur_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_WPTR); 498: next_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_RPTR); 499: next_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_WPTR); 500: 501: dev_crit_ratelimited(gmu_pdev_dev, 502: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 503: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 504: } MATCH LINES: 535, 563, 580, 596 523: } 524: break; 525: case GMU_CP_BV_HW_FAULT_ERROR: 526: dev_crit_ratelimited(gmu_pdev_dev, 527: "CP BV | Ringbuffer HW fault | status=0x%8.8x\n", 528: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 529: KEY_CP_BV_HW_FAULT)); 530: break; 531: case GMU_CP_BV_ILLEGAL_INST_ERROR: 532: dev_crit_ratelimited(gmu_pdev_dev, "CP BV Illegal instruction error\n"); 533: break; 534: case GMU_CP_BV_UCODE_ERROR: 535: dev_crit_ratelimited(gmu_pdev_dev, "CP BV ucode error interrupt\n"); 536: break; 537: case GMU_CP_LPAC_OPCODE_ERROR: 538: dev_crit_ratelimited(gmu_pdev_dev, 539: "CP LPAC opcode error | opcode=0x%8.8x\n", 540: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 541: KEY_CP_LPAC_OPCODE_ERROR)); 542: break; 543: case GMU_CP_LPAC_PROTECTED_ERROR: { 544: u32 status = gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 545: KEY_CP_LPAC_PROTECTED_ERROR); 546: 547: dev_crit_ratelimited(gmu_pdev_dev, 548: "CP LPAC | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 549: status & (1 << 20) ? "READ" : "WRITE", 550: status & 0x3FFFF, status); 551: } 552: break; 553: case GMU_CP_LPAC_HW_FAULT_ERROR: 554: dev_crit_ratelimited(gmu_pdev_dev, 555: "CP LPAC | Ringbuffer HW fault | status=0x%8.8x\n", 556: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 557: KEY_CP_LPAC_HW_FAULT)); 558: break; 559: case GMU_CP_LPAC_ILLEGAL_INST_ERROR: 560: dev_crit_ratelimited(gmu_pdev_dev, "CP LPAC Illegal instruction error\n"); 561: break; 562: case GMU_CP_LPAC_UCODE_ERROR: 563: dev_crit_ratelimited(gmu_pdev_dev, "CP LPAC ucode error interrupt\n"); 564: break; 565: case GMU_GPU_LPAC_SW_HANG: 566: dev_crit_ratelimited(gmu_pdev_dev, "LPAC: gpu timeout ctx %u ts %u\n", 567: cmd->lpac.ctxt_id, cmd->lpac.ts); 568: break; 569: case GMU_GPU_SW_FUSE_VIOLATION: 570: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: SW Feature Fuse violation status=0x%8.8x\n", 571: gen7_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 572: KEY_SWFUSE_VIOLATION_FAULT)); 573: break; 574: case GMU_GPU_AQE0_OPCODE_ERROR: 575: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 opcode error | opcode=0x%8.8x\n", 576: gen7_hwsched_lookup_key_value(adreno_dev, 577: PAYLOAD_FAULT_REGS, KEY_AQE0_OPCODE_ERROR)); 578: break; 579: case GMU_GPU_AQE0_UCODE_ERROR: 580: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 ucode error interrupt\n"); 581: break; 582: case GMU_GPU_AQE0_HW_FAULT_ERROR: 583: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 HW fault | status=0x%8.8x\n", 584: gen7_hwsched_lookup_key_value(adreno_dev, 585: PAYLOAD_FAULT_REGS, KEY_AQE0_HW_FAULT)); 586: break; 587: case GMU_GPU_AQE0_ILLEGAL_INST_ERROR: 588: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 Illegal instruction error\n"); 589: break; 590: case GMU_GPU_AQE1_OPCODE_ERROR: 591: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 opcode error | opcode=0x%8.8x\n", 592: gen7_hwsched_lookup_key_value(adreno_dev, 593: PAYLOAD_FAULT_REGS, KEY_AQE1_OPCODE_ERROR)); 594: break; 595: case GMU_GPU_AQE1_UCODE_ERROR: 596: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 ucode error interrupt\n"); 597: break; 598: case GMU_GPU_AQE1_HW_FAULT_ERROR: 599: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 HW fault | status=0x%8.8x\n", 600: gen7_hwsched_lookup_key_value(adreno_dev, 601: PAYLOAD_FAULT_REGS, KEY_AQE1_HW_FAULT)); 602: break; 603: case GMU_GPU_AQE1_ILLEGAL_INST_ERROR: 604: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 Illegal instruction error\n"); 605: break; 606: case GMU_SYNCOBJ_TIMEOUT_ERROR: 607: dev_crit_ratelimited(gmu_pdev_dev, "syncobj timeout ctx %d ts %u\n", 608: cmd->gc.ctxt_id, cmd->gc.ts); 609: find_timeout_syncobj(adreno_dev, cmd->gc.ctxt_id, cmd->gc.ts); 610: break; 611: case GMU_CP_UNKNOWN_ERROR: 612: fallthrough; 613: default: 614: dev_crit_ratelimited(gmu_pdev_dev, "Unknown GPU fault: %u\n", 615: cmd->error); 616: break; 617: } 618: 619: /* Return true for fatal errors to perform recovery sequence */ 620: return true; MATCH LINES: 670 658: return queue[hdr->read_index]; 659: } 660: 661: static void process_ctx_bad(struct adreno_device *adreno_dev) 662: { 663: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 664: 665: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2) { 666: log_gpu_fault_legacy(adreno_dev); 667: goto done; 668: } 669: 670: /* Non fatal RBBM error interrupts don't go through reset and recovery */ 671: if (!log_gpu_fault(adreno_dev)) { 672: memset(adreno_dev->hwsched.ctxt_bad, 0x0, HFI_MAX_MSG_SIZE); 673: return; 674: } 675: 676: done: 677: gen7_hwsched_fault(adreno_dev, ADRENO_HARD_FAULT); 678: } 679: 680: #define GET_QUERIED_FENCE_INDEX(x) (x / BITS_PER_SYNCOBJ_QUERY) 681: #define GET_QUERIED_FENCE_BIT(x) (x % BITS_PER_SYNCOBJ_QUERY) 682: 683: static bool fence_is_queried(struct hfi_syncobj_query_cmd *cmd, u32 fence_index) 684: { 685: u32 index = GET_QUERIED_FENCE_INDEX(fence_index); 686: u32 bit = GET_QUERIED_FENCE_BIT(fence_index); 687: 688: return (cmd->queries[index].query_bitmask & BIT(bit)); 689: } 690: 691: static void set_fence_signal_bit(struct adreno_device *adreno_dev, 692: struct hfi_syncobj_query_cmd *reply, struct dma_fence *fence, u32 fence_index) 693: { 694: struct device *gmu_pdev_dev = GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)); MATCH LINES: 1246, 1247, 1263, 1271, 1281, 1291 1234: 1235: /* Process one debug queue message and return to not delay msgq processing */ 1236: if (limited) 1237: break; 1238: } 1239: 1240: if (!recovery) 1241: return; 1242: 1243: gen7_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 1244: } 1245: 1246: /* HFI interrupt handler */ 1247: static irqreturn_t gen7_hwsched_hfi_handler(int irq, void *data) 1248: { 1249: struct adreno_device *adreno_dev = data; 1250: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 1251: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 1252: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1253: u32 status = 0; 1254: 1255: /* 1256: * GEN7_GMU_GMU2HOST_INTR_INFO may have bits set not specified in hfi->irq_mask. 1257: * Read and clear only those irq bits that we are processing here. 1258: */ 1259: gmu_core_regread(device, GEN7_GMU_GMU2HOST_INTR_INFO, &status); 1260: gmu_core_regwrite(device, GEN7_GMU_GMU2HOST_INTR_CLR, status & hfi->irq_mask); 1261: 1262: /* 1263: * If interrupts are not enabled on the HFI message queue, 1264: * the inline message processing loop will process it, 1265: * else, process it here. 1266: */ 1267: if (!(hfi->irq_mask & HFI_IRQ_MSGQ_MASK)) 1268: status &= ~HFI_IRQ_MSGQ_MASK; 1269: 1270: if (status & (HFI_IRQ_MSGQ_MASK | HFI_IRQ_DBGQ_MASK)) { 1271: wake_up_interruptible(&hfi->f2h_wq); 1272: adreno_scheduler_queue(adreno_dev); 1273: } 1274: if (status & HFI_IRQ_CM3_FAULT_MASK) { 1275: atomic_set(&gmu->cm3_fault, 1); 1276: 1277: /* make sure other CPUs see the update */ 1278: smp_wmb(); 1279: 1280: dev_err_ratelimited(GMU_PDEV_DEV(device), 1281: "GMU CM3 fault interrupt received\n"); 1282: 1283: gen7_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 1284: } 1285: 1286: /* Ignore OOB bits */ 1287: status &= GENMASK(31 - (oob_max - 1), 0); 1288: 1289: if (status & ~hfi->irq_mask) 1290: dev_err_ratelimited(GMU_PDEV_DEV(device), 1291: "Unhandled HFI interrupts 0x%x\n", 1292: status & ~hfi->irq_mask); 1293: 1294: return IRQ_HANDLED; 1295: } 1296: 1297: #define HFI_IRQ_MSGQ_MASK BIT(0) 1298: 1299: static int check_ack_failure(struct adreno_device *adreno_dev, 1300: struct pending_cmd *ack) 1301: { 1302: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1303: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1304: u64 ticks = gpudev->read_alwayson(adreno_dev); 1305: 1306: if (ack->results[2] != 0xffffffff) 1307: return 0; 1308: 1309: dev_err(GMU_PDEV_DEV(device), 1310: "ACK error: sender id %d seqnum %d\n", 1311: MSG_HDR_GET_ID(ack->sent_hdr), 1312: MSG_HDR_GET_SEQNUM(ack->sent_hdr)); 1313: 1314: KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic, 1315: GMU_PDEV(device), ticks, GMU_FAULT_HFI_ACK); MATCH LINES: 1588, 1591, 1592, 1624 1576: MSG_HDR_GET_ID(rcvd[0]), 1577: MSG_HDR_GET_TYPE(rcvd[0])); 1578: gmu_core_fault_snapshot(device, GMU_FAULT_H2F_MSG_START); 1579: rc = -EINVAL; 1580: goto done; 1581: } 1582: } 1583: 1584: if (!rc) 1585: goto poll; 1586: 1587: done: 1588: /* Clear the interrupt */ 1589: gmu_core_regwrite(device, GEN7_GMU_GMU2HOST_INTR_CLR, HFI_IRQ_MSGQ_MASK); 1590: /* 1591: * Add a write barrier to post the interrupt clear so that we dont have a 1592: * pending interrupt. 1593: */ 1594: wmb(); 1595: return rc; 1596: } 1597: 1598: static void reset_hfi_queues(struct adreno_device *adreno_dev) 1599: { 1600: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 1601: struct hfi_queue_table *tbl = gmu->hfi.hfi_mem->hostptr; 1602: u32 i; 1603: 1604: /* Flush HFI queues */ 1605: for (i = 0; i < HFI_QUEUE_MAX; i++) { 1606: struct hfi_queue_header *hdr = &tbl->qhdr[i]; 1607: 1608: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 1609: continue; 1610: 1611: hdr->read_index = hdr->write_index; 1612: } 1613: } 1614: 1615: void gen7_hwsched_hfi_stop(struct adreno_device *adreno_dev) 1616: { 1617: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 1618: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 1619: 1620: hfi->irq_mask &= ~HFI_IRQ_MSGQ_MASK; 1621: 1622: /* 1623: * In some corner cases, it is possible that GMU put TS_RETIRE 1624: * on the msgq after we have turned off gmu interrupts. Hence, 1625: * drain the queue one last time before we reset HFI queues. 1626: */ 1627: gen7_hwsched_process_msgq(adreno_dev); 1628: 1629: /* Drain the debug queue before we reset HFI queues */ 1630: gen7_hwsched_process_dbgq(adreno_dev, false); 1631: 1632: kgsl_pwrctrl_axi(KGSL_DEVICE(adreno_dev), false); 1633: 1634: clear_bit(GMU_PRIV_HFI_STARTED, &gmu->flags); 1635: } 1636: 1637: static void gen7_hwsched_enable_async_hfi(struct adreno_device *adreno_dev) 1638: { 1639: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 1640: 1641: hfi->irq_mask |= HFI_IRQ_MSGQ_MASK; 1642: 1643: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN7_GMU_GMU2HOST_INTR_MASK, 1644: (u32)~hfi->irq_mask); 1645: } 1646: 1647: static int enable_preemption(struct adreno_device *adreno_dev) 1648: { MATCH LINES: 1890, 1894 1878: { 1879: struct kgsl_device *device = &adreno_dev->dev; 1880: u32 rptr, wptr, status, status3, intstatus, hwfault; 1881: bool val = adreno_is_preemption_enabled(adreno_dev); 1882: 1883: dev_err(device->dev, str); 1884: 1885: kgsl_regread(device, GEN7_CP_LPAC_RB_RPTR, &rptr); 1886: kgsl_regread(device, GEN7_CP_LPAC_RB_WPTR, &wptr); 1887: 1888: kgsl_regread(device, GEN7_RBBM_STATUS, &status); 1889: kgsl_regread(device, GEN7_RBBM_STATUS3, &status3); 1890: kgsl_regread(device, GEN7_RBBM_INT_0_STATUS, &intstatus); 1891: kgsl_regread(device, GEN7_CP_HW_FAULT, &hwfault); 1892: 1893: dev_err(device->dev, 1894: "LPAC rb=%d pos=%X/%X rbbm_status=%8.8X/%8.8X int_0_status=%8.8X\n", 1895: val ? KGSL_LPAC_RB_ID : 1, rptr, wptr, 1896: status, status3, intstatus); 1897: 1898: dev_err(device->dev, " hwfault=%8.8X\n", hwfault); 1899: 1900: kgsl_device_snapshot(device, NULL, NULL, false); 1901: } 1902: 1903: static bool gen7_hwsched_warmboot_possible(struct adreno_device *adreno_dev) 1904: { 1905: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 1906: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1907: struct gmu_core_device *gmu_core = &device->gmu_core; 1908: 1909: if (gmu_core->warmboot_enabled && test_bit(GMU_PRIV_WARMBOOT_GMU_INIT_DONE, &gmu->flags) 1910: && test_bit(GMU_PRIV_WARMBOOT_GPU_BOOT_DONE, &gmu->flags) && 1911: !test_bit(GMU_FORCE_COLDBOOT, &device->gmu_core.flags)) 1912: return true; 1913: 1914: return false; 1915: } 1916: 1917: static int gen7_hwsched_hfi_send_warmboot_cmd(struct adreno_device *adreno_dev, 1918: struct kgsl_memdesc *desc, u32 flag, bool async, struct pending_cmd *ack) MATCH LINES: 2392 2380: 2381: return submit_lpac_raw_cmds(adreno_dev, cmds, sizeof(cmds), 2382: "LPAC CP initialization failed to idle\n"); 2383: } 2384: 2385: static int hfi_f2h_main(void *arg) 2386: { 2387: struct adreno_device *adreno_dev = arg; 2388: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2389: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 2390: 2391: while (!kthread_should_stop()) { 2392: wait_event_interruptible(hfi->f2h_wq, kthread_should_stop() || 2393: /* If msgq irq is enabled and msgq has messages to process */ 2394: (((hfi->irq_mask & HFI_IRQ_MSGQ_MASK) && 2395: !is_queue_empty(adreno_dev, HFI_MSG_ID)) || 2396: /* Trace buffer has messages to process */ 2397: !gmu_core_is_trace_empty(device->gmu_core.trace.md->hostptr) || 2398: /* Dbgq has messages to process */ 2399: !is_queue_empty(adreno_dev, HFI_DBG_ID))); 2400: 2401: if (kthread_should_stop()) 2402: break; 2403: 2404: gen7_hwsched_process_msgq(adreno_dev); 2405: gmu_core_process_trace_data(KGSL_DEVICE(adreno_dev), 2406: GMU_PDEV_DEV(device), &device->gmu_core.trace); 2407: gen7_hwsched_process_dbgq(adreno_dev, true); 2408: } 2409: 2410: return 0; 2411: } 2412: 2413: static void gen7_hwsched_hw_fence_timeout(struct work_struct *work) 2414: { 2415: struct gen7_hwsched_hfi *hfi = container_of(work, struct gen7_hwsched_hfi, hw_fence_ws); 2416: struct gen7_hwsched_device *gen7_hw_dev = container_of(hfi, struct gen7_hwsched_device, MATCH LINES: 3142 3130: */ 3131: static int _hw_fence_sleep(struct adreno_device *adreno_dev, struct adreno_context *drawctxt) 3132: { 3133: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3134: int ret = 0; 3135: 3136: if (!test_bit(GEN7_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags)) 3137: return 0; 3138: 3139: spin_unlock(&hwf->lock); 3140: spin_unlock(&drawctxt->lock); 3141: 3142: ret = wait_event_interruptible(hwf->unack_wq, 3143: _hw_fence_end_sleep(adreno_dev)); 3144: 3145: spin_lock(&drawctxt->lock); 3146: spin_lock(&hwf->lock); 3147: 3148: /* 3149: * If the thread received a signal, or the context became bad in the meanwhile or the limit 3150: * is still not settled, then return error to avoid creating this hardware fence 3151: */ 3152: if ((ret == -ERESTARTSYS) || kgsl_context_is_bad(&drawctxt->base) || 3153: test_bit(GEN7_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags)) 3154: return -EINVAL; 3155: 3156: /* 3157: * If fault recovery is imminent then return error code to avoid creating new hardware 3158: * fences until recovery is complete 3159: */ 3160: if (test_bit(GEN7_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags)) 3161: return -EBUSY; 3162: 3163: return ret; 3164: } 3165: 3166: void gen7_hwsched_create_hw_fence(struct adreno_device *adreno_dev, MATCH LINES: 3491 3479: ret = adreno_gmu_context_queue_write(adreno_dev, 3480: &drawctxt->gmu_context_queue, (u32 *)cmd, cmd_sizebytes, drawobj, &time); 3481: else 3482: ret = gen7_hfi_dispatch_queue_write(adreno_dev, 3483: HFI_DSP_ID_0 + drawobj->context->gmu_dispatch_queue, 3484: (u32 *)cmd, cmd_sizebytes, cmdobj, &time); 3485: if (ret) 3486: return ret; 3487: 3488: hdr = drawctxt->gmu_context_queue.hostptr; 3489: /* The last sync object has been retired by the GMU */ 3490: if (timestamp_cmp(hdr->sync_obj_ts, drawctxt->syncobj_timestamp) >= 0) 3491: /* Send interrupt to GMU to receive the message */ 3492: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN7_GMU_HOST2GMU_INTR_SET, 3493: DISPQ_IRQ_BIT(get_irq_bit(adreno_dev, drawobj))); 3494: else 3495: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN7_GMU_HOST2GMU_INTR_SET, 3496: DISPQ_SYNC_IRQ_BIT(get_irq_bit(adreno_dev, drawobj))); 3497: 3498: drawctxt->internal_timestamp = drawobj->timestamp; 3499: 3500: spin_lock(&drawctxt->lock); 3501: process_hw_fence_queue(adreno_dev, drawctxt, drawobj->timestamp); 3502: /* 3503: * We need to update the gmu_hw_fence_ready_ts while holding the drawctxt lock since we 3504: * have to check it in the hardware fence creation path, where we are not taking the device 3505: * mutex. 3506: */ 3507: drawctxt->gmu_hw_fence_ready_ts = drawobj->timestamp; 3508: spin_unlock(&drawctxt->lock); 3509: 3510: return 0; 3511: } 3512: 3513: int gen7_hwsched_send_recurring_cmdobj(struct adreno_device *adreno_dev, 3514: struct kgsl_drawobj_cmd *cmdobj) 3515: { MATCH LINES: 3875 3863: 3864: seqnum = atomic_inc_return(&hwsched->submission_seqnum); 3865: cmd.submit_cmd.hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_CMD, HFI_MSG_CMD); 3866: cmd.submit_cmd.hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd.submit_cmd.hdr, seqnum, cmd_size >> 2); 3867: 3868: if (adreno_hwsched_context_queue_enabled(adreno_dev)) 3869: ret = adreno_gmu_context_queue_write(adreno_dev, 3870: &hwsched->global_ctxtq, (u32 *)&cmd, cmd_size, NULL, NULL); 3871: else 3872: ret = gen7_hfi_dispatch_queue_write(adreno_dev, HFI_DSP_ID_0, 3873: (u32 *)&cmd, cmd_size, NULL, NULL); 3874: 3875: /* Send interrupt to GMU to receive the message */ 3876: if (!ret) 3877: gmu_core_regwrite(device, GEN7_GMU_HOST2GMU_INTR_SET, DISPQ_IRQ_BIT(0)); 3878: 3879: return ret; 3880: } 3881: 3882: int gen7_hwsched_counter_inline_enable(struct adreno_device *adreno_dev, 3883: const struct adreno_perfcount_group *group, 3884: u32 counter, u32 countable) 3885: { 3886: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 3887: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3888: struct adreno_perfcount_register *reg = &group->regs[counter]; 3889: u32 val, *cmds, count = 0; 3890: int ret; 3891: 3892: ret = register_global_ctxt(adreno_dev); 3893: if (ret) 3894: goto err; 3895: 3896: ret = adreno_allocate_global(device, &hfi->perfctr_scratch, 3897: PAGE_SIZE, 0, KGSL_MEMFLAGS_GPUREADONLY, 0, "perfctr_scratch"); 3898: if (ret) 3899: goto err; --- FILE: \adreno_gen7_hwsched_hfi.h | HITS: 1 --- MATCH LINES: 42 30: * GEN7_HWSCHED_HW_FENCE_SLEEP_BIT will be cleared to wake up any sleeping threads. But, 31: * GEN7_HWSCHED_HW_FENCE_MAX_BIT will remain set to avoid creating any new hardware fences until 32: * recovery is complete and deferred drawctxt (if any) is handled. 33: */ 34: #define GEN7_HWSCHED_HW_FENCE_MAX_BIT 0x1 35: 36: /* 37: * This is used to avoid creating any more hardware fences until concurrent reset/recovery completes 38: */ 39: #define GEN7_HWSCHED_HW_FENCE_ABORT_BIT 0x2 40: 41: struct gen7_hwsched_hfi { 42: /** @irq_mask: Store the hfi interrupt mask */ 43: u32 irq_mask; 44: /** @msglock: To protect the list of un-ACKed hfi packets */ 45: rwlock_t msglock; 46: /** @msglist: List of un-ACKed hfi packets */ 47: struct list_head msglist; 48: /** @f2h_task: Task for processing gmu fw to host packets */ 49: struct task_struct *f2h_task; 50: /** @f2h_wq: Waitqueue for the f2h_task */ 51: wait_queue_head_t f2h_wq; 52: /** @big_ib: GMU buffer to hold big IBs */ 53: struct kgsl_memdesc *big_ib; 54: /** @big_ib_recurring: GMU buffer to hold big recurring IBs */ 55: struct kgsl_memdesc *big_ib_recurring; 56: /** @perfctr_scratch: Buffer to hold perfcounter PM4 commands */ 57: struct kgsl_memdesc *perfctr_scratch; 58: /** @msg_mutex: Mutex for accessing the msgq */ 59: struct mutex msgq_mutex; 60: /** 61: * @hw_fence_timer: Timer to trigger fault if unack'd hardware fence count does'nt drop 62: * to a desired threshold in given amount of time 63: */ 64: struct timer_list hw_fence_timer; 65: /** 66: * @hw_fence_ws: Work struct that gets scheduled when hw_fence_timer expires --- FILE: \adreno_gen7_preempt.c | HITS: 4 --- MATCH LINES: 309 297: GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO, 298: lower_32_bits(next->preemption_desc->gpuaddr), 299: FENCE_STATUS_WRITEDROPPED1_MASK)) 300: goto err; 301: 302: /* 303: * Above fence writes will make sure GMU comes out of 304: * IFPC state if its was in IFPC state but it doesn't 305: * guarantee that GMU FW actually moved to ACTIVE state 306: * i.e. wake-up from IFPC is complete. 307: * Wait for GMU to move to ACTIVE state before triggering 308: * preemption. This is require to make sure CP doesn't 309: * interrupt GMU during wake-up from IFPC. 310: */ 311: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 312: goto err; 313: 314: if (gen7_fenced_write(adreno_dev, 315: GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI, 316: upper_32_bits(next->preemption_desc->gpuaddr), 317: FENCE_STATUS_WRITEDROPPED1_MASK)) 318: goto err; 319: 320: if (kgsl_mmu_is_secured(&device->mmu)) { 321: if (gen7_fenced_write(adreno_dev, 322: GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO, 323: lower_32_bits(next->secure_preemption_desc->gpuaddr), 324: FENCE_STATUS_WRITEDROPPED1_MASK)) 325: goto err; 326: 327: if (gen7_fenced_write(adreno_dev, 328: GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI, 329: upper_32_bits(next->secure_preemption_desc->gpuaddr), 330: FENCE_STATUS_WRITEDROPPED1_MASK)) 331: goto err; 332: } 333: MATCH LINES: 383, 409, 414 371: 372: /* Trigger the preemption */ 373: if (gen7_fenced_write(adreno_dev, GEN7_CP_CONTEXT_SWITCH_CNTL, cntl, 374: FENCE_STATUS_WRITEDROPPED1_MASK)) { 375: adreno_dev->next_rb = NULL; 376: kgsl_delete_timer(&adreno_dev->preempt.timer); 377: goto err; 378: } 379: 380: return; 381: err: 382: /* If fenced write fails, take inline snapshot and trigger recovery */ 383: if (!in_interrupt()) { 384: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 385: adreno_scheduler_fault(adreno_dev, 386: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 387: } else { 388: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 389: } 390: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 391: /* Clear the keep alive */ 392: _power_collapse_set(adreno_dev, false); 393: 394: } 395: 396: void gen7_preemption_callback(struct adreno_device *adreno_dev, int bit) 397: { 398: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 399: unsigned int status; 400: 401: if (!adreno_move_preempt_state(adreno_dev, 402: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 403: return; 404: 405: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_CNTL, &status); 406: 407: if (status & 0x1) { 408: dev_err(KGSL_DEVICE(adreno_dev)->dev, 409: "preempt interrupt with non-zero status: %X\n", 410: status); 411: 412: /* 413: * Under the assumption that this is a race between the 414: * interrupt and the register, schedule the worker to clean up. 415: * If the status still hasn't resolved itself by the time we get 416: * there then we have to assume something bad happened 417: */ 418: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE); 419: adreno_scheduler_queue(adreno_dev); 420: return; 421: } 422: 423: adreno_dev->preempt.count++; 424: 425: /* 426: * We can now safely clear the preemption keepalive bit, allowing 427: * power collapse to resume its regular activity. 428: */ 429: _power_collapse_set(adreno_dev, false); 430: 431: kgsl_delete_timer(&adreno_dev->preempt.timer); 432: 433: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 434: 435: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 436: status, 0); 437: 438: adreno_dev->prev_rb = adreno_dev->cur_rb; --- FILE: \adreno_gen8.c | HITS: 53 --- MATCH LINES: 27, 43 15: #include 16: #endif 17: 18: #include "adreno.h" 19: #include "adreno_gen8.h" 20: #include "adreno_gen8_hwsched.h" 21: #include "adreno_pm4types.h" 22: #include "adreno_trace.h" 23: #include "kgsl_pwrscale.h" 24: #include "kgsl_trace.h" 25: #include "kgsl_util.h" 26: 27: /* CP Interrupt bits */ 28: #define GEN8_CP_GLOBAL_INT_HWFAULTBR 0 29: #define GEN8_CP_GLOBAL_INT_HWFAULTBV 1 30: #define GEN8_CP_GLOBAL_INT_HWFAULTLPAC 2 31: #define GEN8_CP_GLOBAL_INT_HWFAULTAQE0 3 32: #define GEN8_CP_GLOBAL_INT_HWFAULTAQE1 4 33: #define GEN8_CP_GLOBAL_INT_HWFAULTDDEBR 5 34: #define GEN8_CP_GLOBAL_INT_HWFAULTDDEBV 6 35: #define GEN8_CP_GLOBAL_INT_SWFAULTBR 16 36: #define GEN8_CP_GLOBAL_INT_SWFAULTBV 17 37: #define GEN8_CP_GLOBAL_INT_SWFAULTLPAC 18 38: #define GEN8_CP_GLOBAL_INT_SWFAULTAQE0 19 39: #define GEN8_CP_GLOBAL_INT_SWFAULTAQE1 20 40: #define GEN8_CP_GLOBAL_INT_SWFAULTDDEBR 21 41: #define GEN8_CP_GLOBAL_INT_SWFAULTDDEBV 22 42: 43: #define CP_INTERRUPT_STATUS_MASK_GLOBAL \ 44: (BIT(GEN8_CP_GLOBAL_INT_HWFAULTBR) | \ 45: BIT(GEN8_CP_GLOBAL_INT_HWFAULTBV) | \ 46: BIT(GEN8_CP_GLOBAL_INT_HWFAULTLPAC) | \ 47: BIT(GEN8_CP_GLOBAL_INT_HWFAULTAQE0) | \ 48: BIT(GEN8_CP_GLOBAL_INT_HWFAULTAQE1) | \ 49: BIT(GEN8_CP_GLOBAL_INT_HWFAULTDDEBR) | \ 50: BIT(GEN8_CP_GLOBAL_INT_HWFAULTDDEBV) | \ 51: BIT(GEN8_CP_GLOBAL_INT_SWFAULTBR) | \ 52: BIT(GEN8_CP_GLOBAL_INT_SWFAULTBV) | \ 53: BIT(GEN8_CP_GLOBAL_INT_SWFAULTLPAC) | \ 54: BIT(GEN8_CP_GLOBAL_INT_SWFAULTAQE0) | \ 55: BIT(GEN8_CP_GLOBAL_INT_SWFAULTAQE1) | \ 56: BIT(GEN8_CP_GLOBAL_INT_SWFAULTDDEBR) | \ 57: BIT(GEN8_CP_GLOBAL_INT_SWFAULTDDEBV)) 58: 59: /* CP HW Fault status bits */ 60: #define CP_HW_RBFAULT 0 61: #define CP_HW_IB1FAULT 1 62: #define CP_HW_IB2FAULT 2 63: #define CP_HW_IB3FAULT 3 64: #define CP_HW_SDSFAULT 4 65: #define CP_HW_MRBFAULT 5 66: #define CP_HW_VSDFAULT 6 67: #define CP_HW_SQEREADBRUSTOVF 8 MATCH LINES: 395, 410 383: GEN8_CP_PROTECT_REG_GLOBAL + 36, 384: GEN8_CP_PROTECT_REG_GLOBAL + 37, 385: GEN8_CP_PROTECT_REG_GLOBAL + 38, 386: GEN8_CP_PROTECT_REG_GLOBAL + 39, 387: GEN8_CP_PROTECT_REG_GLOBAL + 40, 388: GEN8_CP_PROTECT_REG_GLOBAL + 41, 389: GEN8_CP_PROTECT_REG_GLOBAL + 42, 390: GEN8_CP_PROTECT_REG_GLOBAL + 43, 391: GEN8_CP_PROTECT_REG_GLOBAL + 44, 392: GEN8_CP_PROTECT_REG_GLOBAL + 45, 393: GEN8_CP_PROTECT_REG_GLOBAL + 46, 394: GEN8_CP_PROTECT_REG_GLOBAL + 63, 395: GEN8_CP_INTERRUPT_STATUS_MASK_GLOBAL, 396: }; 397: 398: /* IFPC only static powerup restore list for gen8_1_0 */ 399: static const u32 gen8_1_0_ifpc_pwrup_reglist[] = { 400: GEN8_RBBM_NC_MODE_CNTL, 401: GEN8_RBBM_SLICE_NC_MODE_CNTL, 402: GEN8_RBBM_SLICE_PERFCTR_CNTL, 403: GEN8_RBBM_SLICE_INTERFACE_HANG_INT_CNTL, 404: GEN8_RBBM_PERFCTR_CNTL, 405: GEN8_SP_NC_MODE_CNTL, 406: GEN8_SP_CHICKEN_BITS_2, 407: GEN8_SP_CHICKEN_BITS_3, 408: GEN8_SP_PERFCTR_SHADER_MASK, 409: GEN8_SP_HLSQ_DBG_ECO_CNTL_2, 410: GEN8_CP_INTERRUPT_STATUS_MASK_GLOBAL, 411: GEN8_CP_PROTECT_REG_GLOBAL, 412: GEN8_CP_PROTECT_REG_GLOBAL + 1, 413: GEN8_CP_PROTECT_REG_GLOBAL + 2, 414: GEN8_CP_PROTECT_REG_GLOBAL + 3, 415: GEN8_CP_PROTECT_REG_GLOBAL + 4, 416: GEN8_CP_PROTECT_REG_GLOBAL + 5, 417: GEN8_CP_PROTECT_REG_GLOBAL + 6, 418: GEN8_CP_PROTECT_REG_GLOBAL + 7, 419: GEN8_CP_PROTECT_REG_GLOBAL + 8, 420: GEN8_CP_PROTECT_REG_GLOBAL + 9, 421: GEN8_CP_PROTECT_REG_GLOBAL + 10, 422: GEN8_CP_PROTECT_REG_GLOBAL + 11, 423: GEN8_CP_PROTECT_REG_GLOBAL + 12, 424: GEN8_CP_PROTECT_REG_GLOBAL + 13, 425: GEN8_CP_PROTECT_REG_GLOBAL + 14, 426: GEN8_CP_PROTECT_REG_GLOBAL + 15, 427: GEN8_CP_PROTECT_REG_GLOBAL + 16, 428: GEN8_CP_PROTECT_REG_GLOBAL + 17, 429: GEN8_CP_PROTECT_REG_GLOBAL + 18, 430: GEN8_CP_PROTECT_REG_GLOBAL + 19, 431: GEN8_CP_PROTECT_REG_GLOBAL + 20, 432: GEN8_CP_PROTECT_REG_GLOBAL + 21, 433: GEN8_CP_PROTECT_REG_GLOBAL + 22, 434: GEN8_CP_PROTECT_REG_GLOBAL + 23, MATCH LINES: 481 469: GEN8_SP_NC_MODE_CNTL, 470: GEN8_SP_CHICKEN_BITS, 471: GEN8_SP_SS_CHICKEN_BITS_0, 472: GEN8_SP_CHICKEN_BITS_2, 473: GEN8_SP_CHICKEN_BITS_3, 474: GEN8_SP_PERFCTR_SHADER_MASK, 475: GEN8_RBBM_SLICE_INTERFACE_HANG_INT_CNTL, 476: GEN8_SP_HLSQ_DBG_ECO_CNTL_1, 477: GEN8_SP_HLSQ_DBG_ECO_CNTL_2, 478: GEN8_SP_HLSQ_DBG_ECO_CNTL_3, 479: GEN8_SP_HLSQ_LPAC_GMEM_RANGE_MIN_LO, 480: GEN8_SP_HLSQ_LPAC_GMEM_RANGE_MIN_HI, 481: GEN8_CP_INTERRUPT_STATUS_MASK_GLOBAL, 482: GEN8_CP_PROTECT_REG_GLOBAL, 483: GEN8_CP_PROTECT_REG_GLOBAL + 1, 484: GEN8_CP_PROTECT_REG_GLOBAL + 2, 485: GEN8_CP_PROTECT_REG_GLOBAL + 3, 486: GEN8_CP_PROTECT_REG_GLOBAL + 4, 487: GEN8_CP_PROTECT_REG_GLOBAL + 5, 488: GEN8_CP_PROTECT_REG_GLOBAL + 6, 489: GEN8_CP_PROTECT_REG_GLOBAL + 7, 490: GEN8_CP_PROTECT_REG_GLOBAL + 8, 491: GEN8_CP_PROTECT_REG_GLOBAL + 9, 492: GEN8_CP_PROTECT_REG_GLOBAL + 10, 493: GEN8_CP_PROTECT_REG_GLOBAL + 11, 494: GEN8_CP_PROTECT_REG_GLOBAL + 12, 495: GEN8_CP_PROTECT_REG_GLOBAL + 13, 496: GEN8_CP_PROTECT_REG_GLOBAL + 14, 497: GEN8_CP_PROTECT_REG_GLOBAL + 15, 498: GEN8_CP_PROTECT_REG_GLOBAL + 16, 499: GEN8_CP_PROTECT_REG_GLOBAL + 17, 500: GEN8_CP_PROTECT_REG_GLOBAL + 18, 501: GEN8_CP_PROTECT_REG_GLOBAL + 19, 502: GEN8_CP_PROTECT_REG_GLOBAL + 20, 503: GEN8_CP_PROTECT_REG_GLOBAL + 21, 504: GEN8_CP_PROTECT_REG_GLOBAL + 22, 505: GEN8_CP_PROTECT_REG_GLOBAL + 23, MATCH LINES: 669, 679 657: { GEN8_RB_CMP_NC_MODE_CNTL, BIT(PIPE_BR) }, 658: { GEN8_RB_RESOLVE_PREFETCH_CNTL, BIT(PIPE_BR) }, 659: /* Note: RB_DBG_ECO_CNTL intentionally absent (x285 differs from a840) */ 660: { GEN8_RB_CMP_DBG_ECO_CNTL, BIT(PIPE_BR) }, 661: { GEN8_VFD_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 662: { GEN8_VFD_CB_BV_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR) }, 663: { GEN8_VFD_CB_BR_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR) }, 664: { GEN8_VFD_CB_BUSY_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR) }, 665: { GEN8_VFD_CB_LP_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR) }, 666: { GEN8_VPC_FLATSHADE_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 667: { GEN8_CP_HW_FAULT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 668: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 669: { GEN8_CP_INTERRUPT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 670: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 671: { GEN8_CP_PROTECT_CNTL_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) }, 672: { GEN8_CP_PROTECT_REG_PIPE + 15, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) }, 673: { GEN8_RB_GC_GMEM_PROTECT, BIT(PIPE_BR) }, 674: { GEN8_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, BIT(PIPE_BR) }, 675: }; 676: 677: /* IFPC only static powerup restore list for gen8_11_0 */ 678: static const u32 gen8_11_0_ifpc_pwrup_reglist[] = { 679: GEN8_CP_INTERRUPT_STATUS_MASK_GLOBAL, 680: GEN8_RBBM_NC_MODE_CNTL, 681: GEN8_RBBM_SLICE_INTERFACE_HANG_INT_CNTL, 682: GEN8_RBBM_SLICE_NC_MODE_CNTL, 683: GEN8_RBBM_SLICE_PERFCTR_CNTL, 684: GEN8_SP_CHICKEN_BITS, 685: GEN8_SP_CHICKEN_BITS_2, 686: GEN8_SP_CHICKEN_BITS_3, 687: GEN8_SP_CHICKEN_BITS_5, 688: GEN8_SP_HLSQ_DBG_ECO_CNTL, 689: GEN8_SP_HLSQ_DBG_ECO_CNTL_1, 690: GEN8_SP_HLSQ_DBG_ECO_CNTL_3, 691: GEN8_SP_HLSQ_LPAC_GMEM_RANGE_MIN_LO, 692: GEN8_SP_HLSQ_LPAC_GMEM_RANGE_MIN_HI, 693: GEN8_SP_NC_MODE_CNTL, 694: GEN8_SP_PERFCTR_SHADER_MASK, 695: GEN8_SP_L0_PERF_TUNE, 696: GEN8_CP_PROTECT_REG_GLOBAL + 0, 697: GEN8_CP_PROTECT_REG_GLOBAL + 1, 698: GEN8_CP_PROTECT_REG_GLOBAL + 2, 699: GEN8_CP_PROTECT_REG_GLOBAL + 3, 700: GEN8_CP_PROTECT_REG_GLOBAL + 4, 701: GEN8_CP_PROTECT_REG_GLOBAL + 5, 702: GEN8_CP_PROTECT_REG_GLOBAL + 6, 703: GEN8_CP_PROTECT_REG_GLOBAL + 7, MATCH LINES: 758 746: GEN8_CP_PROTECT_REG_GLOBAL + 50, 747: GEN8_CP_PROTECT_REG_GLOBAL + 51, 748: GEN8_CP_PROTECT_REG_GLOBAL + 52, 749: GEN8_CP_PROTECT_REG_GLOBAL + 53, 750: GEN8_CP_PROTECT_REG_GLOBAL + 54, 751: GEN8_CP_PROTECT_REG_GLOBAL + 55, 752: GEN8_CP_PROTECT_REG_GLOBAL + 63, 753: }; 754: 755: static const struct gen8_pwrup_extlist gen8_0_0_pwrup_extlist[] = { 756: { GEN8_CP_HW_FAULT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 757: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 758: { GEN8_CP_INTERRUPT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 759: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 760: { GEN8_CP_PROTECT_CNTL_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC)}, 761: { GEN8_CP_PROTECT_REG_PIPE + 15, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC)}, 762: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 763: { GEN8_GRAS_NC_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 764: { GEN8_GRAS_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 765: { GEN8_RB_CCU_CNTL, BIT(PIPE_BR)}, 766: { GEN8_RB_CCU_NC_MODE_CNTL, BIT(PIPE_BR)}, 767: { GEN8_RB_CMP_NC_MODE_CNTL, BIT(PIPE_BR)}, 768: { GEN8_RB_RESOLVE_PREFETCH_CNTL, BIT(PIPE_BR)}, 769: { GEN8_RB_CMP_DBG_ECO_CNTL, BIT(PIPE_BR)}, 770: { GEN8_RB_GC_GMEM_PROTECT, BIT(PIPE_BR)}, 771: { GEN8_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, BIT(PIPE_BR)}, 772: { GEN8_VPC_FLATSHADE_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 773: { GEN8_PC_CHICKEN_BITS_1, BIT(PIPE_BV) | BIT(PIPE_BR)}, 774: { GEN8_PC_CHICKEN_BITS_2, BIT(PIPE_BV) | BIT(PIPE_BR)}, 775: { GEN8_PC_CHICKEN_BITS_3, BIT(PIPE_BV) | BIT(PIPE_BR)}, 776: { GEN8_PC_CHICKEN_BITS_4, BIT(PIPE_BV) | BIT(PIPE_BR)}, 777: { GEN8_PC_AUTO_VERTEX_STRIDE, BIT(PIPE_BR) | BIT(PIPE_BV)}, 778: { GEN8_PC_VIS_STREAM_CNTL, BIT(PIPE_BR) | BIT(PIPE_BV)}, 779: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, BIT(PIPE_BR) | BIT(PIPE_BV)}, 780: { GEN8_VFD_CB_BV_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR)}, 781: { GEN8_VFD_CB_BR_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR)}, 782: { GEN8_VFD_CB_BUSY_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR)}, MATCH LINES: 813 801: { GEN8_RB_CMP_NC_MODE_CNTL, BIT(PIPE_BR) }, 802: { GEN8_RB_RBP_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 803: { GEN8_RB_RESOLVE_PREFETCH_CNTL, BIT(PIPE_BR) }, 804: { GEN8_RB_CMP_DBG_ECO_CNTL, BIT(PIPE_BR) }, 805: { GEN8_VFD_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 806: { GEN8_VFD_CB_BV_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR) }, 807: { GEN8_VFD_CB_BR_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR) }, 808: { GEN8_VFD_CB_BUSY_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR) }, 809: { GEN8_VFD_CB_LP_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR) }, 810: { GEN8_VPC_FLATSHADE_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 811: { GEN8_CP_HW_FAULT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 812: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 813: { GEN8_CP_INTERRUPT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 814: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 815: { GEN8_CP_PROTECT_CNTL_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC)}, 816: { GEN8_CP_PROTECT_REG_PIPE + 15, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) }, 817: { GEN8_RB_GC_GMEM_PROTECT, BIT(PIPE_BR) }, 818: { GEN8_RB_LPAC_GMEM_PROTECT, BIT(PIPE_BR) }, 819: { GEN8_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, BIT(PIPE_BR) }, 820: }; 821: 822: static const struct gen8_pwrup_extlist gen8_3_0_pwrup_extlist[] = { 823: { GEN8_CP_PROTECT_CNTL_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) }, 824: { GEN8_CP_PROTECT_REG_PIPE + 15, BIT(PIPE_BR) | BIT(PIPE_BV) }, 825: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 826: { GEN8_GRAS_NC_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 827: { GEN8_GRAS_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 828: { GEN8_RB_CCU_CNTL, BIT(PIPE_BR)}, 829: { GEN8_RB_CCU_NC_MODE_CNTL, BIT(PIPE_BR)}, 830: { GEN8_RB_CMP_NC_MODE_CNTL, BIT(PIPE_BR)}, 831: { GEN8_RB_RESOLVE_PREFETCH_CNTL, BIT(PIPE_BR)}, 832: { GEN8_RB_CMP_DBG_ECO_CNTL, BIT(PIPE_BR)}, 833: { GEN8_RB_GC_GMEM_PROTECT, BIT(PIPE_BR)}, 834: { GEN8_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, BIT(PIPE_BR)}, 835: { GEN8_VPC_FLATSHADE_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR)}, 836: { GEN8_PC_CHICKEN_BITS_1, BIT(PIPE_BV) | BIT(PIPE_BR)}, 837: { GEN8_PC_CHICKEN_BITS_2, BIT(PIPE_BV) | BIT(PIPE_BR)}, MATCH LINES: 854 842: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, BIT(PIPE_BR) | BIT(PIPE_BV)}, 843: { GEN8_VFD_CB_BV_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR)}, 844: { GEN8_VFD_CB_BR_THRESHOLD, BIT(PIPE_BV) | BIT(PIPE_BR)}, 845: { GEN8_VFD_CB_BUSY_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR)}, 846: { GEN8_VFD_CB_LP_REQ_CNT, BIT(PIPE_BV) | BIT(PIPE_BR)}, 847: { GEN8_VFD_DBG_ECO_CNTL, BIT(PIPE_BR) | BIT(PIPE_BV)}, 848: }; 849: 850: /* Static powerup external list for gen8_11_0 */ 851: static const struct gen8_pwrup_extlist gen8_11_0_pwrup_extlist[] = { 852: { GEN8_CP_HW_FAULT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 853: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 854: { GEN8_CP_INTERRUPT_STATUS_MASK_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) 855: | BIT(PIPE_AQE0) | BIT(PIPE_AQE1) | BIT(PIPE_DDE_BR) | BIT(PIPE_DDE_BV) }, 856: { GEN8_CP_PROTECT_CNTL_PIPE, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC)}, 857: { GEN8_CP_PROTECT_REG_PIPE + 15, BIT(PIPE_BR) | BIT(PIPE_BV) | BIT(PIPE_LPAC) }, 858: { GEN8_GRAS_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 859: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 860: { GEN8_GRAS_NC_MODE_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 861: { GEN8_PC_AUTO_VERTEX_STRIDE, BIT(PIPE_BV) | BIT(PIPE_BR) }, 862: { GEN8_PC_VIS_STREAM_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 863: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, BIT(PIPE_BV) | BIT(PIPE_BR) }, 864: { GEN8_PC_CHICKEN_BITS_1, BIT(PIPE_BV) | BIT(PIPE_BR) }, 865: { GEN8_PC_CHICKEN_BITS_2, BIT(PIPE_BV) | BIT(PIPE_BR) }, 866: { GEN8_PC_CHICKEN_BITS_3, BIT(PIPE_BV) | BIT(PIPE_BR) }, 867: { GEN8_PC_CHICKEN_BITS_4, BIT(PIPE_BV) | BIT(PIPE_BR) }, 868: { GEN8_PC_CHICKEN_BITS_5, BIT(PIPE_BV) | BIT(PIPE_BR) }, 869: { GEN8_RB_CCU_CNTL, BIT(PIPE_BR) }, 870: { GEN8_RB_CCU_DBG_ECO_CNTL, BIT(PIPE_BR)}, 871: { GEN8_RB_CCU_NC_MODE_CNTL, BIT(PIPE_BR) }, 872: { GEN8_RB_CMP_NC_MODE_CNTL, BIT(PIPE_BR) }, 873: { GEN8_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE, BIT(PIPE_BR) }, 874: { GEN8_RB_DBG_ECO_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 875: { GEN8_RB_RBP_CNTL, BIT(PIPE_BV) | BIT(PIPE_BR) }, 876: { GEN8_RB_RESOLVE_PREFETCH_CNTL, BIT(PIPE_BR) }, 877: { GEN8_RB_CMP_DBG_ECO_CNTL, BIT(PIPE_BR) }, 878: { GEN8_RB_GC_GMEM_PROTECT, BIT(PIPE_BR) }, MATCH LINES: 2239, 2243, 2253, 2254, 2255 2227: u32 val = CP_SW_FAULT_STATUS_MASK_PIPE; 2228: 2229: if ((pipe_id == PIPE_LPAC) && !ADRENO_FEATURE(adreno_dev, ADRENO_LPAC)) 2230: continue; 2231: if (((pipe_id == PIPE_AQE0) || (pipe_id == PIPE_AQE1)) && 2232: !ADRENO_FEATURE(adreno_dev, ADRENO_AQE)) 2233: continue; 2234: 2235: gen8_regwrite_aperture(device, GEN8_CP_APRIV_CNTL_PIPE, 2236: (pipe_id == PIPE_BR ? GEN8_BR_APRIV_DEFAULT : GEN8_APRIV_DEFAULT), 2237: pipe_id, 0, 0); 2238: 2239: /* Disable the CP_SW_RTWROVF bit for BV pipe to prevent false interrupt from CP */ 2240: if (adreno_is_gen8_11_x(adreno_dev) && (pipe_id == PIPE_BV)) 2241: val &= ~(BIT(CP_SW_RTWROVF)); 2242: 2243: gen8_regwrite_aperture(device, GEN8_CP_INTERRUPT_STATUS_MASK_PIPE, 2244: val, pipe_id, 0, 0); 2245: 2246: gen8_regwrite_aperture(device, GEN8_CP_HW_FAULT_STATUS_MASK_PIPE, 2247: CP_HW_FAULT_STATUS_MASK_PIPE, pipe_id, 0, 0); 2248: } 2249: 2250: /* Clear aperture register */ 2251: gen8_host_aperture_set(adreno_dev, 0, 0, 0); 2252: 2253: /* Program CP interrupt status mask to enable HW and SW error interrupts */ 2254: kgsl_regwrite(device, GEN8_CP_INTERRUPT_STATUS_MASK_GLOBAL, 2255: CP_INTERRUPT_STATUS_MASK_GLOBAL); 2256: 2257: _set_secvid(device); 2258: 2259: /* 2260: * Enable hardware clock gating here to prevent any register access 2261: * issue due to internal clock gating. 2262: * 2263: * Gen8_2_0, gen8_1_0 and gen8_10_0 need to set up HW clock gating after 2264: * CP INIT in the bootup sequence. 2265: */ 2266: if (!(adreno_is_gen8_2_x(adreno_dev) || 2267: adreno_is_gen8_1_0(adreno_dev) || 2268: adreno_is_gen8_10_0(adreno_dev))) 2269: gen8_hwcg_set(adreno_dev, true); 2270: 2271: /* Ensure very last register write is finished before we return from this function */ 2272: mb(); 2273: device->regmap.use_relaxed = true; 2274: 2275: if (!is_current_rt) 2276: sched_set_normal(current, nice); 2277: 2278: return 0; 2279: } MATCH LINES: 2343, 2344, 2347 2331: void gen8_spin_idle_debug(struct adreno_device *adreno_dev, 2332: const char *str) 2333: { 2334: struct kgsl_device *device = &adreno_dev->dev; 2335: u32 rptr, wptr, status, intstatus, global_status; 2336: 2337: dev_err(device->dev, str); 2338: 2339: kgsl_regread(device, GEN8_CP_RB_RPTR_BR, &rptr); 2340: kgsl_regread(device, GEN8_CP_RB_WPTR_GC, &wptr); 2341: 2342: kgsl_regread(device, GEN8_RBBM_STATUS, &status); 2343: kgsl_regread(device, GEN8_RBBM_INT_0_STATUS, &intstatus); 2344: kgsl_regread(device, GEN8_CP_INTERRUPT_STATUS_GLOBAL, &global_status); 2345: 2346: dev_err(device->dev, 2347: "rb=%d pos=%X/%X rbbm_status=%8.8X int_0_status=%8.8X global_status=%8.8X\n", 2348: adreno_dev->cur_rb ? adreno_dev->cur_rb->id : -1, rptr, wptr, 2349: status, intstatus, global_status); 2350: 2351: kgsl_device_snapshot(device, NULL, NULL, false); 2352: } 2353: 2354: /* 2355: * gen8_send_cp_init() - Initialize ringbuffer 2356: * @adreno_dev: Pointer to adreno device 2357: * @rb: Pointer to the ringbuffer of device 2358: * 2359: * Submit commands for ME initialization, 2360: */ 2361: static int gen8_send_cp_init(struct adreno_device *adreno_dev, 2362: struct adreno_ringbuffer *rb) 2363: { 2364: u32 *cmds; 2365: int ret; 2366: 2367: cmds = adreno_ringbuffer_allocspace(rb, GEN8_CP_INIT_DWORDS); 2368: if (IS_ERR(cmds)) 2369: return PTR_ERR(cmds); 2370: 2371: gen8_cp_init_cmds(adreno_dev, cmds); MATCH LINES: 2440 2428: *cmds++ = cp_type7_packet(CP_SET_AMBLE, 3); 2429: *cmds++ = lower_32_bits(kmd_postamble_addr); 2430: *cmds++ = upper_32_bits(kmd_postamble_addr); 2431: *cmds++ = FIELD_PREP(GENMASK(22, 20), CP_KMD_AMBLE_TYPE) 2432: | (FIELD_PREP(GENMASK(19, 0), 2433: adreno_dev->preempt.postamble_bootup_len)); 2434: } 2435: 2436: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 2437: *cmds++ = 0; 2438: *cmds++ = 0; 2439: *cmds++ = 0; 2440: /* generate interrupt on preemption completion */ 2441: *cmds++ = 0; 2442: 2443: ret = gen8_ringbuffer_submit(rb, NULL); 2444: if (!ret) { 2445: ret = adreno_spin_idle(adreno_dev, 2000); 2446: if (ret) 2447: gen8_spin_idle_debug(adreno_dev, 2448: "hw preemption initialization failed to idle\n"); 2449: } 2450: 2451: return ret; 2452: } 2453: 2454: int gen8_rb_start(struct adreno_device *adreno_dev) 2455: { 2456: const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev); 2457: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 2458: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2459: struct adreno_ringbuffer *rb; 2460: u64 addr; 2461: int ret, i; 2462: u32 *cmds; 2463: 2464: /* Clear all the ringbuffers */ MATCH LINES: 2699, 2711, 2733, 2771, 2772, 2781, 2787 2687: break; 2688: case BIT(GEN8_CP_GLOBAL_INT_SWFAULTAQE1): 2689: pipe_id = PIPE_AQE1; 2690: break; 2691: case BIT(GEN8_CP_GLOBAL_INT_SWFAULTDDEBR): 2692: pipe_id = PIPE_DDE_BR; 2693: break; 2694: case BIT(GEN8_CP_GLOBAL_INT_SWFAULTDDEBV): 2695: pipe_id = PIPE_DDE_BV; 2696: break; 2697: } 2698: 2699: gen8_regread_aperture(device, GEN8_CP_INTERRUPT_STATUS_PIPE, &sw_status, 2700: pipe_id, first_slice, 0); 2701: 2702: dev_crit_ratelimited(device->dev, "CP SW Fault pipe_id: %u %s\n", pipe_id, 2703: sw_status < ARRAY_SIZE(table) ? table[sw_status] : "UNKNOWN"); 2704: 2705: if (sw_status & BIT(CP_SW_OPCODEERROR)) { 2706: gen8_regwrite_aperture(device, GEN8_CP_SQE_STAT_ADDR_PIPE, 1, 2707: pipe_id, 0, 0); 2708: gen8_regread_aperture(device, GEN8_CP_SQE_STAT_DATA_PIPE, &opcode, 2709: pipe_id, first_slice, 0); 2710: dev_crit_ratelimited(device->dev, 2711: "CP opcode error interrupt | opcode=0x%8.8x\n", opcode); 2712: } 2713: 2714: if (sw_status & BIT(CP_SW_REGISTERPROTECTIONERROR)) { 2715: gen8_regread_aperture(device, GEN8_CP_PROTECT_STATUS_PIPE, &status1, 2716: pipe_id, first_slice, 0); 2717: dev_crit_ratelimited(device->dev, 2718: "CP | Protected mode error | %s | addr=%lx | status=%x\n", 2719: FIELD_GET(GENMASK(20, 20), status1) ? "READ" : "WRITE", 2720: FIELD_GET(GENMASK(17, 0), status1), status1); 2721: } 2722: 2723: /* Clear aperture register */ 2724: gen8_host_aperture_set(adreno_dev, 0, 0, 0); 2725: } 2726: 2727: static void gen8_cp_hw_err_callback(struct adreno_device *adreno_dev, int bit) 2728: { 2729: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2730: u32 global_status; 2731: u32 hw_fault, sw_fault; 2732: 2733: kgsl_regread(device, GEN8_CP_INTERRUPT_STATUS_GLOBAL, &global_status); 2734: 2735: dev_crit_ratelimited(device->dev, "CP fault int_status_global=0x%x\n", global_status); 2736: 2737: hw_fault = FIELD_GET(GENMASK(6, 0), global_status); 2738: sw_fault = FIELD_GET(GENMASK(22, 16), global_status); 2739: 2740: if (hw_fault) 2741: gen8_get_cp_hwfault_status(adreno_dev, hw_fault); 2742: else if (sw_fault) 2743: gen8_get_cp_swfault_status(adreno_dev, sw_fault); 2744: } 2745: 2746: static void gen8_err_callback(struct adreno_device *adreno_dev, int bit) 2747: { 2748: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2749: 2750: switch (bit) { 2751: case GEN8_INT_AHBERROR: 2752: { 2753: u32 err_details_0, err_details_1; 2754: 2755: kgsl_regread(device, GEN8_CP_RL_ERROR_DETAILS_0, &err_details_0); 2756: kgsl_regread(device, GEN8_CP_RL_ERROR_DETAILS_1, &err_details_1); 2757: dev_crit_ratelimited(device->dev, 2758: "CP: AHB bus error, CP_RL_ERROR_DETAILS_0:0x%x CP_RL_ERROR_DETAILS_1:0x%x\n", 2759: err_details_0, err_details_1); 2760: break; 2761: } 2762: case GEN8_INT_ATBASYNCFIFOOVERFLOW: 2763: dev_crit_ratelimited(device->dev, "RBBM: ATB ASYNC overflow\n"); 2764: break; 2765: case GEN8_INT_ATBBUSOVERFLOW: 2766: dev_crit_ratelimited(device->dev, "RBBM: ATB bus overflow\n"); 2767: break; 2768: case GEN8_INT_OUTOFBOUNDACCESS: 2769: dev_crit_ratelimited(device->dev, "UCHE: Out of bounds access\n"); 2770: break; 2771: case GEN8_INT_UCHETRAPINTERRUPT: 2772: dev_crit_ratelimited(device->dev, "UCHE: Trap interrupt\n"); 2773: break; 2774: case GEN8_INT_TSBWRITEERROR: 2775: { 2776: u32 lo, hi; 2777: 2778: kgsl_regread(device, GEN8_RBBM_SECVID_TSB_STATUS_LO, &lo); 2779: kgsl_regread(device, GEN8_RBBM_SECVID_TSB_STATUS_HI, &hi); 2780: 2781: dev_crit_ratelimited(device->dev, "TSB: Write error interrupt: Address: 0x%lx MID: %lu\n", 2782: FIELD_GET(GENMASK(16, 0), hi) << 32 | lo, 2783: FIELD_GET(GENMASK(31, 23), hi)); 2784: break; 2785: } 2786: default: 2787: dev_crit_ratelimited(device->dev, "Unknown interrupt %d\n", bit); 2788: } 2789: } 2790: 2791: static const char *const uche_client[] = { 2792: "BR_VFD", "BR_SP", "BR_VSC", "BR_VPC", 2793: "BR_HLSQ", "BR_PC", "BR_LRZ", "BR_TP", 2794: "BV_VFD", "BV_SP", "BV_VSC", "BV_VPC", 2795: "BV_HLSQ", "BV_PC", "BV_LRZ", "BV_TP", 2796: "STCHE", 2797: }; 2798: 2799: static const char *const uche_lpac_client[] = { 2800: "-", "SP_LPAC", "-", "-", "HLSQ_LPAC", "-", "-", "TP_LPAC" 2801: }; 2802: 2803: #define SCOOBYDOO 0x5c00bd00 2804: 2805: static const char *gen8_fault_block_uche(struct kgsl_device *device, 2806: char *str, int size, bool lpac) 2807: { 2808: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 2809: u32 uche_client_id = adreno_dev->uche_client_pf; 2810: const char *uche_client_str, *fault_block; 2811: MATCH LINES: 2908, 2910, 2918, 2930, 2932, 2952, 2971, 2973, 2979 2896: return str; 2897: } 2898: 2899: static void gen8_cp_callback(struct adreno_device *adreno_dev, int bit) 2900: { 2901: if (adreno_is_preemption_enabled(adreno_dev)) 2902: gen8_preemption_trigger(adreno_dev, true); 2903: 2904: adreno_scheduler_queue(adreno_dev); 2905: } 2906: 2907: /* 2908: * gen8_gpc_err_int_callback() - Isr for GPC error interrupts 2909: * @adreno_dev: Pointer to device 2910: * @bit: Interrupt bit 2911: */ 2912: static void gen8_gpc_err_int_callback(struct adreno_device *adreno_dev, int bit) 2913: { 2914: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2915: 2916: /* 2917: * GPC error is typically the result of mistake SW programming. 2918: * Force GPU fault for this interrupt so that we can debug it 2919: * with help of register dump. 2920: */ 2921: 2922: dev_crit(device->dev, "RBBM: GPC error\n"); 2923: adreno_irqctrl(adreno_dev, 0); 2924: 2925: /* Trigger a fault in the dispatcher - this will effect a restart */ 2926: adreno_scheduler_fault(adreno_dev, ADRENO_SOFT_FAULT); 2927: } 2928: 2929: /* 2930: * gen8_swfuse_violation_callback() - ISR for software fuse violation interrupt 2931: * @adreno_dev: Pointer to device 2932: * @bit: Interrupt bit 2933: */ 2934: static void gen8_swfuse_violation_callback(struct adreno_device *adreno_dev, int bit) 2935: { 2936: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2937: u32 status, mask = GENMASK(GEN8_RAYTRACING_SW_FUSE, GEN8_LPAC_SW_FUSE); 2938: 2939: /* 2940: * SWFUSEVIOLATION error is typically the result of enabling software 2941: * feature which is not supported by the hardware. Following are the 2942: * Feature violation will be reported 2943: * 1) FASTBLEND (BIT:0): NO Fault, RB will send the workload to legacy 2944: * blender HW pipeline. 2945: * 2) LPAC (BIT:1): Fault 2946: * 3) RAYTRACING (BIT:2): Fault 2947: * 4) mALU (BIT:3): Fault 2948: */ 2949: kgsl_regread(device, GEN8_RBBM_SW_FUSE_INT_STATUS, &status); 2950: 2951: /* 2952: * RBBM_INT_CLEAR_CMD will not clear SWFUSEVIOLATION interrupt. Hence 2953: * do explicit swfuse irq clear. 2954: */ 2955: kgsl_regwrite(device, GEN8_RBBM_SW_FUSE_INT_MASK, 0); 2956: 2957: dev_crit_ratelimited(device->dev, 2958: "RBBM: SW Feature Fuse violation status=0x%8.8x\n", status); 2959: 2960: if (adreno_dev->malu_enabled) 2961: mask |= BIT(GEN8_MALU_SW_FUSE); 2962: 2963: /* Trigger a fault in the dispatcher for LPAC, RAYTRACING and mALU violation */ 2964: if (status & mask) { 2965: adreno_irqctrl(adreno_dev, 0); 2966: adreno_scheduler_fault(adreno_dev, ADRENO_HARD_FAULT); 2967: } 2968: } 2969: 2970: /* 2971: * gen8_dbgc_intr_callback() - ISR for DBGC error interrupt 2972: * @adreno_dev: Pointer to device 2973: * @bit: Interrupt bit 2974: */ 2975: static void gen8_dbgc_intr_callback(struct adreno_device *adreno_dev, int bit) 2976: { 2977: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2978: 2979: dev_crit_ratelimited(device->dev, "RBBM: Debug bus interrupt: bit (%d)\n", bit); 2980: adreno_irqctrl(adreno_dev, 0); 2981: adreno_scheduler_fault(adreno_dev, ADRENO_HARD_FAULT); 2982: } 2983: 2984: static const struct adreno_irq_funcs gen8_irq_funcs[32] = { 2985: ADRENO_IRQ_CALLBACK(NULL), /* 0 - RBBM_GPU_IDLE */ 2986: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 1 - RBBM_AHB_ERROR */ 2987: ADRENO_IRQ_CALLBACK(NULL), /* 2 - UNUSED */ 2988: ADRENO_IRQ_CALLBACK(NULL), /* 3 - UNUSED */ 2989: ADRENO_IRQ_CALLBACK(NULL), /* 4 - CPIPCINT0 */ 2990: ADRENO_IRQ_CALLBACK(NULL), /* 5 - CPIPCINT1 */ 2991: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 6 - ATBASYNCOVERFLOW */ 2992: ADRENO_IRQ_CALLBACK(gen8_gpc_err_int_callback), /* 7 - GPC_ERR */ 2993: ADRENO_IRQ_CALLBACK(gen8_preemption_callback),/* 8 - CP_SW */ 2994: ADRENO_IRQ_CALLBACK(gen8_cp_hw_err_callback), /* 9 - CP_HW_ERROR */ 2995: ADRENO_IRQ_CALLBACK(NULL), /* 10 - CP_CCU_FLUSH_DEPTH_TS */ 2996: ADRENO_IRQ_CALLBACK(NULL), /* 11 - CP_CCU_FLUSH_COLOR_TS */ 2997: ADRENO_IRQ_CALLBACK(NULL), /* 12 - CP_CCU_RESOLVE_TS */ 2998: ADRENO_IRQ_CALLBACK(NULL), /* 13 - UNUSED */ 2999: ADRENO_IRQ_CALLBACK(NULL), /* 14 - UNUSED */ 3000: ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 15 - CP_RB_INT */ 3001: ADRENO_IRQ_CALLBACK(NULL), /* 16 - CP_RB_INT_LPAC*/ 3002: ADRENO_IRQ_CALLBACK(NULL), /* 17 - CP_RB_DONE_TS */ 3003: ADRENO_IRQ_CALLBACK(NULL), /* 18 - UNUSED */ MATCH LINES: 3021 3009: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 24 - UCHE_OOB_ACCESS */ 3010: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 25 - UCHE_TRAP_INTR */ 3011: ADRENO_IRQ_CALLBACK(gen8_dbgc_intr_callback), /* 26 - DEBUG_BUS_INTR_0 */ 3012: ADRENO_IRQ_CALLBACK(gen8_dbgc_intr_callback), /* 27 - DEBUG_BUS_INTR_1 */ 3013: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 28 - TSBWRITEERROR */ 3014: ADRENO_IRQ_CALLBACK(gen8_swfuse_violation_callback), /* 29 - SWFUSEVIOLATION */ 3015: ADRENO_IRQ_CALLBACK(NULL), /* 30 - ISDB_CPU_IRQ */ 3016: ADRENO_IRQ_CALLBACK(NULL), /* 31 - ISDB_UNDER_DEBUG */ 3017: }; 3018: 3019: /* 3020: * If the AHB fence is not in ALLOW mode when we receive an RBBM 3021: * interrupt, something went wrong. This means that we cannot proceed 3022: * since the IRQ status and clear registers are not accessible. 3023: * This is usually harmless because the GMU will abort power collapse 3024: * and change the fence back to ALLOW. Poll so that this can happen. 3025: */ 3026: static int gen8_irq_poll_fence(struct adreno_device *adreno_dev) 3027: { 3028: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3029: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 3030: u32 status, fence, fence_retries = 0; 3031: u64 a, b, c; 3032: 3033: a = gpudev->read_alwayson(adreno_dev); 3034: 3035: kgsl_regread(device, GEN8_GMUAO_AHB_FENCE_CTRL, &fence); 3036: 3037: while (fence != 0) { 3038: b = gpudev->read_alwayson(adreno_dev); 3039: 3040: /* Wait for small time before trying again */ 3041: udelay(1); 3042: kgsl_regread(device, GEN8_GMUAO_AHB_FENCE_CTRL, &fence); 3043: 3044: if (fence_retries == 100 && fence != 0) { 3045: c = gpudev->read_alwayson(adreno_dev); MATCH LINES: 3063, 3066, 3070, 3076, 3091, 3094, 3098, 3109, 3125, 3130, 3137, 3167 3051: "status=0x%x Unmasked status=0x%x Mask=0x%x timestamps: %llx %llx %llx\n", 3052: status & adreno_dev->irq_mask, status, 3053: adreno_dev->irq_mask, a, b, c); 3054: return -ETIMEDOUT; 3055: } 3056: 3057: fence_retries++; 3058: } 3059: 3060: return 0; 3061: } 3062: 3063: static irqreturn_t gen8_hwsched_irq_handler(struct adreno_device *adreno_dev) 3064: { 3065: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3066: irqreturn_t ret = IRQ_NONE; 3067: u32 status; 3068: 3069: /* 3070: * GPU can power down once the INT_0_STATUS is read below. 3071: * But there still might be some register reads required so 3072: * force the GMU/GPU into KEEPALIVE mode until done with the ISR. 3073: */ 3074: gen8_gpu_keepalive(adreno_dev, true); 3075: 3076: kgsl_regread(device, GEN8_RBBM_INT_0_STATUS, &status); 3077: 3078: kgsl_regwrite(device, GEN8_RBBM_INT_CLEAR_CMD, status); 3079: 3080: ret = adreno_irq_callbacks(adreno_dev, gen8_irq_funcs, status); 3081: 3082: trace_kgsl_gen8_irq_status(adreno_dev, status); 3083: 3084: /* If hard fault, then let snapshot turn off the keepalive */ 3085: if (!(adreno_gpu_fault(adreno_dev) & ADRENO_HARD_FAULT)) 3086: gen8_gpu_keepalive(adreno_dev, false); 3087: 3088: return ret; 3089: } 3090: 3091: static irqreturn_t gen8_irq_handler(struct adreno_device *adreno_dev) 3092: { 3093: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3094: irqreturn_t ret = IRQ_NONE; 3095: u32 status; 3096: 3097: /* 3098: * GPU can power down once the INT_0_STATUS is read below. 3099: * But there still might be some register reads required so 3100: * force the GMU/GPU into KEEPALIVE mode until done with the ISR. 3101: */ 3102: gen8_gpu_keepalive(adreno_dev, true); 3103: 3104: if (gen8_irq_poll_fence(adreno_dev)) { 3105: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 3106: goto done; 3107: } 3108: 3109: kgsl_regread(device, GEN8_RBBM_INT_0_STATUS, &status); 3110: 3111: kgsl_regwrite(device, GEN8_RBBM_INT_CLEAR_CMD, status); 3112: 3113: ret = adreno_irq_callbacks(adreno_dev, gen8_irq_funcs, status); 3114: 3115: trace_kgsl_gen8_irq_status(adreno_dev, status); 3116: 3117: done: 3118: /* If hard fault, then let snapshot turn off the keepalive */ 3119: if (!(adreno_gpu_fault(adreno_dev) & ADRENO_HARD_FAULT)) 3120: gen8_gpu_keepalive(adreno_dev, false); 3121: 3122: return ret; 3123: } 3124: 3125: static irqreturn_t gen8_cx_host_irq_handler(int irq, void *data) 3126: { 3127: struct kgsl_device *device = data; 3128: u32 status; 3129: 3130: kgsl_regread(device, GEN8_GPU_CX_MISC_INT_0_STATUS, &status); 3131: kgsl_regwrite(device, GEN8_GPU_CX_MISC_INT_CLEAR_CMD, status); 3132: 3133: if (status & BIT(GEN8_CX_MISC_GPU_CC_IRQ)) 3134: KGSL_PWRCTRL_LOG_FREQLIM(device); 3135: 3136: if (status & ~GEN8_CX_MISC_INT_MASK) 3137: dev_err_ratelimited(device->dev, "Unhandled CX MISC interrupts 0x%lx\n", 3138: status & ~GEN8_CX_MISC_INT_MASK); 3139: 3140: return IRQ_HANDLED; 3141: } 3142: 3143: int gen8_probe_common(struct platform_device *pdev, 3144: struct adreno_device *adreno_dev, u32 chipid, 3145: const struct adreno_gpu_core *gpucore) 3146: { 3147: const struct adreno_gpudev *gpudev = gpucore->gpudev; 3148: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3149: const struct adreno_gen8_core *gen8_core = container_of(gpucore, 3150: struct adreno_gen8_core, base); 3151: int ret; 3152: 3153: adreno_dev->gpucore = gpucore; 3154: adreno_dev->chipid = chipid; 3155: 3156: adreno_reg_offset_init(gpudev->reg_offsets); 3157: 3158: adreno_dev->hwcg_enabled = true; 3159: adreno_dev->uche_client_pf = 1; 3160: 3161: kgsl_pwrscale_fast_bus_hint(gen8_core->fast_bus_hint); 3162: device->pwrctrl.cx_cfg_gdsc_offset = GEN8_GPU_CC_CX_CFG_GDSCR; 3163: 3164: device->pwrctrl.rt_bus_hint = gen8_core->rt_bus_hint; 3165: 3166: device->cx_host_irq_num = kgsl_request_irq_optional(pdev, 3167: "cx_host_irq", gen8_cx_host_irq_handler, device); 3168: 3169: ret = adreno_device_probe(pdev, adreno_dev); 3170: if (ret) 3171: return ret; 3172: 3173: if (adreno_preemption_feature_set(adreno_dev)) { 3174: adreno_dev->total_ctxt_record_sz = gen8_core->ctxt_record_size ? 3175: gen8_core->ctxt_record_size : GEN8_CP_CTXRECORD_SIZE_IN_BYTES; 3176: 3177: adreno_dev->preempt.preempt_level = gen8_core->preempt_level; 3178: adreno_dev->preempt.skipsaverestore = true; 3179: adreno_dev->preempt.usesgmem = true; 3180: set_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 3181: } 3182: 3183: /* debugfs node for ACD calibration */ 3184: debugfs_create_file("acd_calibrate", 0644, device->d_debugfs, device, &acd_cal_fops); 3185: 3186: gen8_coresight_init(adreno_dev); 3187: 3188: /* Dump additional AQE 16KB data on top of default 128KB(64(BR)+64(BV)) */ 3189: device->snapshot_ctxt_record_size = ADRENO_FEATURE(adreno_dev, ADRENO_AQE) ? 3190: (GEN8_SNAPSHOT_CTXRECORD_SIZE_IN_BYTES + GEN8_CP_AQE_CTXRECORD_SIZE_IN_BYTES) : 3191: GEN8_SNAPSHOT_CTXRECORD_SIZE_IN_BYTES; MATCH LINES: 3212, 3214, 3215 3200: ADRENO_REG_DEFINE(ADRENO_REG_CP_LPAC_RB_BASE, GEN8_CP_RB_BASE_LO_LPAC), 3201: ADRENO_REG_DEFINE(ADRENO_REG_CP_LPAC_RB_BASE_HI, GEN8_CP_RB_BASE_HI_LPAC), 3202: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_RPTR, GEN8_CP_RB_RPTR_BR), 3203: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_WPTR, GEN8_CP_RB_WPTR_GC), 3204: ADRENO_REG_DEFINE(ADRENO_REG_CP_ME_CNTL, GEN8_CP_SQE_CNTL), 3205: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BASE, GEN8_CP_IB1_BASE_LO_PIPE), 3206: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BASE_HI, GEN8_CP_IB1_BASE_HI_PIPE), 3207: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BUFSZ, GEN8_CP_IB1_REM_SIZE_PIPE), 3208: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BASE, GEN8_CP_IB2_BASE_LO_PIPE), 3209: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BASE_HI, GEN8_CP_IB2_BASE_HI_PIPE), 3210: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BUFSZ, GEN8_CP_IB2_REM_SIZE_PIPE), 3211: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_STATUS, GEN8_RBBM_STATUS), 3212: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_INT_0_MASK, GEN8_RBBM_INT_0_MASK), 3213: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_SW_RESET_CMD, GEN8_RBBM_SW_RESET_CMD), 3214: ADRENO_REG_DEFINE(ADRENO_REG_GMU_AO_HOST_INTERRUPT_MASK, 3215: GEN8_GMUAO_AO_HOST_INTERRUPT_MASK), 3216: ADRENO_REG_DEFINE(ADRENO_REG_GMU_GMU2HOST_INTR_MASK, 3217: GEN8_GMUCX_GMU2HOST_INTR_MASK), 3218: }; 3219: 3220: static u32 _get_pipeid(u32 groupid) 3221: { 3222: switch (groupid) { 3223: case KGSL_PERFCOUNTER_GROUP_BV_PC: 3224: fallthrough; 3225: case KGSL_PERFCOUNTER_GROUP_BV_VFD: 3226: fallthrough; 3227: case KGSL_PERFCOUNTER_GROUP_BV_VPC: 3228: fallthrough; 3229: case KGSL_PERFCOUNTER_GROUP_BV_TSE: 3230: fallthrough; 3231: case KGSL_PERFCOUNTER_GROUP_BV_RAS: 3232: fallthrough; 3233: case KGSL_PERFCOUNTER_GROUP_BV_LRZ: 3234: fallthrough; 3235: case KGSL_PERFCOUNTER_GROUP_BV_HLSQ: 3236: return PIPE_BV; 3237: case KGSL_PERFCOUNTER_GROUP_PC: 3238: fallthrough; 3239: case KGSL_PERFCOUNTER_GROUP_VFD: MATCH LINES: 3851, 3886 3839: if (adreno_is_gen8_10_0(adreno_dev)) 3840: return (adreno_dev->gpucore->gmem_size / GEN8_10_0_NUM_PHYSICAL_SLICES) * 3841: gen8_get_num_slices(adreno_dev); 3842: 3843: return adreno_dev->gpucore->gmem_size; 3844: } 3845: 3846: const struct gen8_gpudev adreno_gen8_hwsched_gpudev = { 3847: .base = { 3848: .reg_offsets = gen8_register_offsets, 3849: .probe = gen8_hwsched_probe, 3850: .snapshot = gen8_hwsched_snapshot, 3851: .irq_handler = gen8_hwsched_irq_handler, 3852: .iommu_fault_block = gen8_iommu_fault_block, 3853: .context_detach = gen8_hwsched_context_detach, 3854: .read_alwayson = gen8_read_alwayson, 3855: .reset = gen8_hwsched_reset_replay, 3856: .soft_reset = gen8_hwsched_soft_reset, 3857: .power_ops = &gen8_hwsched_power_ops, 3858: .power_stats = gen8_power_stats, 3859: .hw_isidle = gen8_hw_isidle, 3860: .add_to_va_minidump = gen8_hwsched_add_to_minidump, 3861: .gx_is_on = gen8_gmu_gx_is_on, 3862: .send_recurring_cmdobj = gen8_hwsched_send_recurring_cmdobj, 3863: .perfcounter_remove = gen8_perfcounter_remove, 3864: .set_isdb_breakpoint_registers = gen8_set_isdb_breakpoint_registers, 3865: .context_destroy = gen8_hwsched_context_destroy, 3866: .lpac_store = gen8_lpac_store, 3867: .get_uche_trap_base = gen8_get_uche_trap_base, 3868: .fault_header = gen8_fault_header, 3869: .lpac_fault_header = gen8_lpac_fault_header, 3870: .power_feature_stats = gen8_power_feature_stats, 3871: .acquire_cp_semaphore = gen8_acquire_cp_semaphore, 3872: .release_cp_semaphore = gen8_release_cp_semaphore, 3873: .get_gmem_size = gen8_get_gmem_size, 3874: .read_speedbin = gen8_read_softfuse_speedbin, 3875: }, 3876: .hfi_probe = gen8_hwsched_hfi_probe, 3877: .hfi_remove = gen8_hwsched_hfi_remove, 3878: .handle_watchdog = gen8_hwsched_handle_watchdog, 3879: }; 3880: 3881: const struct gen8_gpudev adreno_gen8_gmu_gpudev = { 3882: .base = { 3883: .reg_offsets = gen8_register_offsets, 3884: .probe = gen8_gmu_device_probe, 3885: .snapshot = gen8_gmu_snapshot, 3886: .irq_handler = gen8_irq_handler, 3887: .rb_start = gen8_rb_start, 3888: .gpu_keepalive = gen8_gpu_keepalive, 3889: .hw_isidle = gen8_hw_isidle, 3890: .iommu_fault_block = gen8_iommu_fault_block, 3891: .reset = gen8_gmu_reset, 3892: .preemption_schedule = gen8_preemption_schedule, 3893: .read_alwayson = gen8_read_alwayson, 3894: .power_ops = &gen8_gmu_power_ops, 3895: .remove = gen8_remove, 3896: .ringbuffer_submitcmd = gen8_ringbuffer_submitcmd, 3897: .power_stats = gen8_power_stats, 3898: .add_to_va_minidump = gen8_gmu_add_to_minidump, 3899: .gx_is_on = gen8_gmu_gx_is_on, 3900: .perfcounter_remove = gen8_perfcounter_remove, 3901: .set_isdb_breakpoint_registers = gen8_set_isdb_breakpoint_registers, 3902: .swfuse_irqctrl = gen8_swfuse_irqctrl, 3903: .get_uche_trap_base = gen8_get_uche_trap_base, 3904: .fault_header = gen8_fault_header, 3905: .acquire_cp_semaphore = gen8_acquire_cp_semaphore, 3906: .release_cp_semaphore = gen8_release_cp_semaphore, 3907: .get_gmem_size = gen8_get_gmem_size, 3908: .read_speedbin = gen8_read_softfuse_speedbin, 3909: }, 3910: .hfi_probe = gen8_gmu_hfi_probe, --- FILE: \adreno_gen8.h | HITS: 6 --- MATCH LINES: 312, 314, 318, 320, 329, 332 300: 301: #define GEN8_CP_RB_CNTL_DEFAULT \ 302: (FIELD_PREP(GENMASK(7, 0), ilog2(KGSL_RB_DWORDS >> 1)) | \ 303: FIELD_PREP(GENMASK(12, 8), ilog2(4))) 304: 305: /* Size of the CP_INIT pm4 stream in dwords */ 306: #define GEN8_CP_INIT_DWORDS 10 307: 308: #define GEN8_INT_MASK \ 309: ((1 << GEN8_INT_AHBERROR) | \ 310: (1 << GEN8_INT_ATBASYNCFIFOOVERFLOW) | \ 311: (1 << GEN8_INT_GPCERROR) | \ 312: (1 << GEN8_INT_SWINTERRUPT) | \ 313: (1 << GEN8_INT_HWERROR) | \ 314: (1 << GEN8_INT_PM4CPINTERRUPT) | \ 315: (1 << GEN8_INT_RB_DONE_TS) | \ 316: (1 << GEN8_INT_CACHE_CLEAN_TS) | \ 317: (1 << GEN8_INT_ATBBUSOVERFLOW) | \ 318: (1 << GEN8_INT_HANGDETECTINTERRUPT) | \ 319: (1 << GEN8_INT_OUTOFBOUNDACCESS) | \ 320: (1 << GEN8_INT_UCHETRAPINTERRUPT) | \ 321: (1 << GEN8_INT_TSBWRITEERROR) | \ 322: (1 << GEN8_INT_SWFUSEVIOLATION)) 323: 324: #define GEN8_HWSCHED_INT_MASK \ 325: ((1 << GEN8_INT_AHBERROR) | \ 326: (1 << GEN8_INT_ATBASYNCFIFOOVERFLOW) | \ 327: (1 << GEN8_INT_ATBBUSOVERFLOW) | \ 328: (1 << GEN8_INT_OUTOFBOUNDACCESS) | \ 329: (1 << GEN8_INT_UCHETRAPINTERRUPT) | \ 330: (1 << GEN8_INT_TSBWRITEERROR)) 331: 332: /* GEN8 CX MISC interrupt bits */ 333: #define GEN8_CX_MISC_GPU_CC_IRQ 31 334: 335: #define GEN8_CX_MISC_INT_MASK BIT(GEN8_CX_MISC_GPU_CC_IRQ) 336: 337: /** 338: * to_gen8_core - return the gen8 specific GPU core struct 339: * @adreno_dev: An Adreno GPU device handle 340: * 341: * Returns: 342: * A pointer to the gen8 specific GPU core struct 343: */ 344: static inline const struct adreno_gen8_core * 345: to_gen8_core(struct adreno_device *adreno_dev) 346: { 347: const struct adreno_gpu_core *core = adreno_dev->gpucore; 348: 349: return container_of(core, struct adreno_gen8_core, base); 350: } 351: 352: /* Preemption functions */ 353: void gen8_preemption_trigger(struct adreno_device *adreno_dev, bool atomic); 354: void gen8_preemption_schedule(struct adreno_device *adreno_dev); 355: void gen8_preemption_start(struct adreno_device *adreno_dev); 356: int gen8_preemption_init(struct adreno_device *adreno_dev); --- FILE: \adreno_gen8_gmu.c | HITS: 28 --- MATCH LINES: 546, 554, 558, 568, 570, 586, 589, 594, 596 534: return; 535: 536: if (req >= oob_boot_slumber) { 537: dev_err(GMU_PDEV_DEV(device), "Unsupported OOB clear %s\n", 538: oob_to_str(req)); 539: return; 540: } 541: 542: gmu_core_regwrite(device, GEN8_GMUCX_HOST2GMU_INTR_SET, clear); 543: trace_kgsl_gmu_oob_clear(clear); 544: } 545: 546: void gen8_gmu_irq_enable(struct adreno_device *adreno_dev) 547: { 548: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 549: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 550: struct gen8_hfi *hfi = &gmu->hfi; 551: 552: /* Clear pending IRQs and Unmask needed IRQs */ 553: gmu_core_regwrite(device, GEN8_GMUCX_GMU2HOST_INTR_CLR, UINT_MAX); 554: gmu_core_regwrite(device, GEN8_GMUAO_AO_HOST_INTERRUPT_CLR, UINT_MAX); 555: 556: gmu_core_regwrite(device, GEN8_GMUCX_GMU2HOST_INTR_MASK, 557: (u32)~HFI_IRQ_MASK); 558: gmu_core_regwrite(device, GEN8_GMUAO_AO_HOST_INTERRUPT_MASK, 559: (u32)~GMU_AO_INT_MASK); 560: 561: /* Enable all IRQs on host */ 562: enable_irq(hfi->irq); 563: enable_irq(gmu->irq); 564: 565: if (device->cx_host_irq_num <= 0) 566: return; 567: 568: /* Clear pending IRQs, unmask needed interrupts and enable CX host IRQ */ 569: kgsl_regwrite(device, GEN8_GPU_CX_MISC_INT_CLEAR_CMD, UINT_MAX); 570: kgsl_regwrite(device, GEN8_GPU_CX_MISC_INT_0_MASK, GEN8_CX_MISC_INT_MASK); 571: enable_irq(device->cx_host_irq_num); 572: } 573: 574: void gen8_gmu_irq_disable(struct adreno_device *adreno_dev) 575: { 576: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 577: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 578: struct gen8_hfi *hfi = &gmu->hfi; 579: 580: /* Disable all IRQs on host */ 581: disable_irq(gmu->irq); 582: disable_irq(hfi->irq); 583: 584: /* Mask all IRQs and clear pending IRQs */ 585: gmu_core_regwrite(device, GEN8_GMUCX_GMU2HOST_INTR_MASK, UINT_MAX); 586: gmu_core_regwrite(device, GEN8_GMUAO_AO_HOST_INTERRUPT_MASK, UINT_MAX); 587: 588: gmu_core_regwrite(device, GEN8_GMUCX_GMU2HOST_INTR_CLR, UINT_MAX); 589: gmu_core_regwrite(device, GEN8_GMUAO_AO_HOST_INTERRUPT_CLR, UINT_MAX); 590: 591: if (device->cx_host_irq_num <= 0) 592: return; 593: 594: /* Disable CX host IRQ, mask all interrupts and clear pending IRQs */ 595: disable_irq(device->cx_host_irq_num); 596: kgsl_regwrite(device, GEN8_GPU_CX_MISC_INT_0_MASK, UINT_MAX); 597: kgsl_regwrite(device, GEN8_GPU_CX_MISC_INT_CLEAR_CMD, UINT_MAX); 598: } 599: 600: static int gen8_gmu_hfi_start_msg(struct adreno_device *adreno_dev) 601: { 602: struct hfi_start_cmd req; 603: int ret; 604: 605: ret = CMD_MSG_HDR(req, H2F_MSG_START); 606: if (ret) 607: return ret; 608: 609: return gen8_hfi_send_generic_req(adreno_dev, &req, sizeof(req)); 610: } 611: 612: static u32 gen8_rscc_tcsm_drv0_status_reglist[] = { 613: GEN8_RSCC_TCS0_DRV0_STATUS, 614: GEN8_RSCC_TCS1_DRV0_STATUS, 615: GEN8_RSCC_TCS2_DRV0_STATUS, 616: GEN8_RSCC_TCS3_DRV0_STATUS, 617: GEN8_RSCC_TCS4_DRV0_STATUS, 618: GEN8_RSCC_TCS5_DRV0_STATUS, 619: GEN8_RSCC_TCS6_DRV0_STATUS, 620: GEN8_RSCC_TCS7_DRV0_STATUS, MATCH LINES: 1461, 1478, 1481 1449: if (gen8_gmu_gx_is_on(adreno_dev) && adreno_smmu_is_stalled(adreno_dev)) { 1450: dev_err(GMU_PDEV_DEV(device), 1451: "Skipping NMI because SMMU is stalled\n"); 1452: goto done; 1453: } 1454: 1455: if (force) 1456: goto nmi; 1457: 1458: /* 1459: * We should not send NMI if there was a CM3 fault reported because we 1460: * don't want to overwrite the critical CM3 state captured by gmu before 1461: * it sent the CM3 fault interrupt. Also don't send NMI if GMU reset is 1462: * already active. We could have hit a GMU assert and NMI might have 1463: * already been triggered. 1464: */ 1465: 1466: /* make sure we're reading the latest cm3_fault */ 1467: smp_rmb(); 1468: 1469: if (atomic_read(&gmu->cm3_fault)) 1470: return; 1471: 1472: gmu_core_regread(device, GEN8_GMUCX_CM3_FW_INIT_RESULT, &result); 1473: 1474: if (result & 0xE00) 1475: return; 1476: 1477: nmi: 1478: /* Mask so there's no interrupt caused by NMI */ 1479: gmu_core_regwrite(device, GEN8_GMUCX_GMU2HOST_INTR_MASK, UINT_MAX); 1480: 1481: /* Make sure the interrupt is masked before causing it */ 1482: wmb(); 1483: 1484: /* This will cause the GMU to save it's internal state to ddr */ 1485: gmu_core_regrmw(device, GEN8_GMUCX_CM3_CFG, BIT(9), BIT(9)); 1486: 1487: /* Make sure the NMI is invoked before we proceed*/ 1488: wmb(); 1489: 1490: /* Wait for the NMI to be handled */ 1491: udelay(200); 1492: 1493: done: 1494: KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic, 1495: GMU_PDEV(device), ticks, gf_policy); 1496: } 1497: 1498: static void gen8_gmu_cooperative_reset(struct kgsl_device *device) 1499: { 1500: u32 result; 1501: 1502: gmu_core_regwrite(device, GEN8_GMUCX_WDOG_CTRL, 0); 1503: gmu_core_regwrite(device, GEN8_GMUCX_HOST2GMU_INTR_SET, BIT(17)); 1504: 1505: /* MATCH LINES: 1555, 1556, 1557, 1563, 1566, 1574, 1575, 1579, 1590, 1595 1543: } 1544: 1545: static bool gen8_gmu_scales_bandwidth(struct kgsl_device *device) 1546: { 1547: return true; 1548: } 1549: 1550: void gen8_gmu_handle_watchdog(struct adreno_device *adreno_dev) 1551: { 1552: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1553: u32 mask; 1554: 1555: /* Temporarily mask the watchdog interrupt to prevent a storm */ 1556: gmu_core_regread(device, GEN8_GMUAO_AO_HOST_INTERRUPT_MASK, &mask); 1557: gmu_core_regwrite(device, GEN8_GMUAO_AO_HOST_INTERRUPT_MASK, 1558: (mask | GMU_INT_WDOG_BITE)); 1559: 1560: gen8_gmu_send_nmi(device, false, GMU_FAULT_PANIC_NONE); 1561: 1562: dev_err_ratelimited(GMU_PDEV_DEV(device), 1563: "GMU watchdog expired interrupt received\n"); 1564: } 1565: 1566: static irqreturn_t gen8_gmu_irq_handler(int irq, void *data) 1567: { 1568: struct kgsl_device *device = data; 1569: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1570: const struct gen8_gpudev *gen8_gpudev = 1571: to_gen8_gpudev(ADRENO_GPU_DEVICE(adreno_dev)); 1572: u32 status = 0; 1573: 1574: gmu_core_regread(device, GEN8_GMUAO_AO_HOST_INTERRUPT_STATUS, &status); 1575: gmu_core_regwrite(device, GEN8_GMUAO_AO_HOST_INTERRUPT_CLR, status); 1576: 1577: if (status & GMU_INT_HOST_AHB_BUS_ERR) 1578: dev_err_ratelimited(GMU_PDEV_DEV(device), 1579: "AHB bus error interrupt received\n"); 1580: 1581: if (status & GMU_INT_WDOG_BITE) 1582: gen8_gpudev->handle_watchdog(adreno_dev); 1583: 1584: if (status & GMU_INT_FENCE_ERR) { 1585: u32 fence_status; 1586: 1587: gmu_core_regread(device, GEN8_GMUAO_AHB_FENCE_STATUS, 1588: &fence_status); 1589: dev_err_ratelimited(GMU_PDEV_DEV(device), 1590: "FENCE error interrupt received %x\n", fence_status); 1591: } 1592: 1593: if (status & ~GMU_AO_INT_MASK) 1594: dev_err_ratelimited(GMU_PDEV_DEV(device), 1595: "Unhandled GMU interrupts 0x%lx\n", 1596: status & ~GMU_AO_INT_MASK); 1597: 1598: return IRQ_HANDLED; 1599: } 1600: 1601: void gen8_gmu_aop_send_acd_state(struct gen8_gmu_device *gmu, bool flag) 1602: { 1603: struct kgsl_device *device = KGSL_DEVICE(gen8_gmu_to_adreno(gmu)); 1604: char msg_buf[36]; 1605: u32 size; 1606: int ret; 1607: 1608: if (IS_ERR_OR_NULL(gmu->qmp)) 1609: return; 1610: 1611: size = scnprintf(msg_buf, sizeof(msg_buf), 1612: "{class: gpu, res: acd, val: %d}", flag); 1613: 1614: ret = qmp_send(gmu->qmp, msg_buf, ALIGN((size + 1), SZ_4)); 1615: if (ret < 0) 1616: dev_err(GMU_PDEV_DEV(device), 1617: "AOP qmp send message failed: %d\n", ret); 1618: } 1619: MATCH LINES: 1673 1661: goto clks_gdsc_off; 1662: 1663: ret = gen8_gmu_version_info(adreno_dev); 1664: if (ret) 1665: goto clks_gdsc_off; 1666: 1667: ret = gen8_gmu_itcm_shadow(adreno_dev); 1668: if (ret) 1669: goto clks_gdsc_off; 1670: 1671: gen8_gmu_register_config(adreno_dev); 1672: 1673: gen8_gmu_irq_enable(adreno_dev); 1674: 1675: /* Vote for minimal DDR BW for GMU to init */ 1676: level = pwr->pwrlevels[pwr->default_pwrlevel].bus_min; 1677: icc_set_bw(pwr->icc_path, 0, kBps_to_icc(pwr->ddr_table[level])); 1678: 1679: /* Clear any GPU faults that might have been left over */ 1680: adreno_clear_gpu_fault(adreno_dev); 1681: 1682: ret = gen8_gmu_device_start(adreno_dev); 1683: if (ret) 1684: goto err; 1685: 1686: ret = gen8_gmu_hfi_start(adreno_dev); 1687: if (ret) 1688: goto err; 1689: 1690: gen8_get_gpu_feature_info(adreno_dev); 1691: 1692: ret = gen8_hfi_start(adreno_dev); 1693: if (ret) 1694: goto err; 1695: 1696: if (adreno_dev->gmu_ab && 1697: gen8_hfi_send_get_value(adreno_dev, HFI_VALUE_GMU_AB_VOTE, 0) == 1 && MATCH LINES: 1773 1761: gen8_cx_timer_init(adreno_dev); 1762: 1763: ret = gen8_rscc_wakeup_sequence(adreno_dev); 1764: if (ret) 1765: goto clks_gdsc_off; 1766: 1767: ret = gen8_gmu_load_fw(adreno_dev); 1768: if (ret) 1769: goto clks_gdsc_off; 1770: 1771: gen8_gmu_register_config(adreno_dev); 1772: 1773: gen8_gmu_irq_enable(adreno_dev); 1774: 1775: /* Clear any GPU faults that might have been left over */ 1776: adreno_clear_gpu_fault(adreno_dev); 1777: 1778: ret = gen8_gmu_device_start(adreno_dev); 1779: if (ret) 1780: goto err; 1781: 1782: ret = gen8_gmu_hfi_start(adreno_dev); 1783: if (ret) 1784: goto err; 1785: 1786: ret = gen8_hfi_start(adreno_dev); 1787: if (ret) 1788: goto err; 1789: 1790: device->gmu_fault = false; 1791: 1792: kgsl_pwrctrl_set_state(device, KGSL_STATE_AWARE); 1793: 1794: return 0; 1795: 1796: err: 1797: gen8_gmu_irq_disable(adreno_dev); MATCH LINES: 2210 2198: /* GMU sysfs nodes setup */ 2199: ret = kobject_init_and_add(&gmu->log_kobj, &log_kobj_type, &dev->kobj, "log"); 2200: if (ret) 2201: dev_err(dev, "Failed to add log_kobj: %d\n", ret); 2202: 2203: ret = kobject_init_and_add(&gmu->stats_kobj, &stats_kobj_type, &dev->kobj, "stats"); 2204: if (ret) 2205: dev_err(dev, "Failed to add stats_kobj: %d\n", ret); 2206: 2207: spin_lock_init(&gmu->hfi.cmdq_lock); 2208: 2209: gmu->irq = kgsl_request_irq(GMU_PDEV(device), "gmu", NULL, -EINVAL, 2210: gen8_gmu_irq_handler, device); 2211: 2212: if (gmu->irq >= 0) 2213: return 0; 2214: 2215: ret = gmu->irq; 2216: 2217: error: 2218: gen8_gmu_remove(device); 2219: return ret; 2220: } 2221: 2222: int gen8_halt_gbif(struct adreno_device *adreno_dev) 2223: { 2224: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2225: int ret; 2226: 2227: /* Halt new client requests */ 2228: kgsl_regwrite(device, GEN8_GBIF_HALT, GEN8_GBIF_CLIENT_HALT_MASK); 2229: ret = adreno_wait_for_halt_ack(device, 2230: GEN8_GBIF_HALT_ACK, GEN8_GBIF_CLIENT_HALT_MASK); 2231: 2232: /* Halt all AXI requests */ 2233: kgsl_regwrite(device, GEN8_GBIF_HALT, GEN8_GBIF_ARB_HALT_MASK); 2234: ret = adreno_wait_for_halt_ack(device, MATCH LINES: 2524, 2526 2512: set_bit(ADRENO_DEVICE_FIRST_BOOT_DONE, &adreno_dev->priv); 2513: 2514: kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE); 2515: 2516: return 0; 2517: } 2518: 2519: static bool gen8_irq_pending(struct adreno_device *adreno_dev) 2520: { 2521: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2522: u32 status; 2523: 2524: kgsl_regread(device, GEN8_RBBM_INT_0_STATUS, &status); 2525: 2526: /* Return busy if a interrupt is pending */ 2527: return ((status & adreno_dev->irq_mask) || 2528: atomic_read(&adreno_dev->pending_irq_refcnt)); 2529: } 2530: 2531: static int gen8_power_off(struct adreno_device *adreno_dev) 2532: { 2533: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2534: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2535: int ret; 2536: 2537: WARN_ON(!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)); 2538: 2539: adreno_check_idle(device); 2540: 2541: kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); 2542: 2543: ret = gen8_gmu_oob_set(device, oob_gpu); 2544: if (ret) 2545: goto no_gx_power; 2546: 2547: if (gen8_irq_pending(adreno_dev)) { 2548: gen8_gmu_oob_clear(device, oob_gpu); 2549: return -EBUSY; 2550: } MATCH LINES: 2863 2851: 2852: /* Attempt to reboot the gmu and gpu */ 2853: return gen8_boot(adreno_dev); 2854: } 2855: 2856: int gen8_gmu_hfi_probe(struct adreno_device *adreno_dev) 2857: { 2858: struct platform_device *gmu_pdev = GMU_PDEV(KGSL_DEVICE(adreno_dev)); 2859: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2860: struct gen8_hfi *hfi = &gmu->hfi; 2861: 2862: hfi->irq = kgsl_request_irq(gmu_pdev, "hfi", NULL, -EINVAL, 2863: gen8_hfi_irq_handler, KGSL_DEVICE(adreno_dev)); 2864: 2865: return hfi->irq < 0 ? hfi->irq : 0; 2866: } 2867: 2868: int gen8_gmu_add_to_minidump(struct adreno_device *adreno_dev) 2869: { 2870: struct gen8_device *gen8_dev = container_of(adreno_dev, 2871: struct gen8_device, adreno_dev); 2872: struct gen8_nonctxt_overrides *nc_overrides = gen8_dev->nc_overrides; 2873: int ret; 2874: 2875: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, KGSL_GEN8_DEVICE, 2876: (void *)(gen8_dev), sizeof(struct gen8_device)); 2877: if (ret) 2878: return ret; 2879: 2880: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, KGSL_GMU_LOG_ENTRY, 2881: gen8_dev->gmu.gmu_log->hostptr, gen8_dev->gmu.gmu_log->size); 2882: if (ret) 2883: return ret; 2884: 2885: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, KGSL_HFIMEM_ENTRY, 2886: gen8_dev->gmu.hfi.hfi_mem->hostptr, gen8_dev->gmu.hfi.hfi_mem->size); 2887: if (ret) --- FILE: \adreno_gen8_gmu.h | HITS: 8 --- MATCH LINES: 25, 45 13: #include "kgsl_gmu_core.h" 14: 15: struct gen8_dcvs_table { 16: u32 gpu_level_num; 17: u32 gmu_level_num; 18: struct opp_gx_desc gx_votes[MAX_GX_LEVELS]; 19: struct opp_desc cx_votes[MAX_CX_LEVELS]; 20: }; 21: 22: /** 23: * struct gen8_gmu_device - GMU device structure 24: * @ver: GMU Version information 25: * @irq: GMU interrupt number 26: * @fw_image: GMU FW image 27: * @gmu_log: gmu event log memory 28: * @hfi: HFI controller 29: * @idle_level: Minimal GPU idle power level 30: * @log_wptr_retention: Store the log wptr offset on slumber 31: */ 32: struct gen8_gmu_device { 33: int irq; 34: const struct firmware *fw_image; 35: struct kgsl_memdesc *gmu_log; 36: /** @gmu_init_scratch: Memory to store the initial HFI messages */ 37: struct kgsl_memdesc *gmu_init_scratch; 38: /** @gpu_boot_scratch: Memory to store the bootup HFI messages */ 39: struct kgsl_memdesc *gpu_boot_scratch; 40: struct gen8_hfi hfi; 41: u32 idle_level; 42: /** @qmp: aoss_qmp handle */ 43: struct qmp *qmp; 44: u32 log_wptr_retention; 45: /** @cm3_fault: whether gmu received a cm3 fault interrupt */ 46: atomic_t cm3_fault; 47: /** 48: * @itcm_shadow: Copy of the itcm block in firmware binary used for 49: * snapshot 50: */ 51: void *itcm_shadow; 52: /** @flags: Internal gmu flags */ 53: unsigned long flags; 54: /** @rscc_virt: Pointer where RSCC block is mapped */ 55: void __iomem *rscc_virt; 56: /** @log_stream_enable: GMU log streaming enable. Disabled by default */ 57: bool log_stream_enable; 58: /** @log_group_mask: Allows overriding default GMU log group mask */ 59: u32 log_group_mask; 60: struct kobject log_kobj; 61: /** @num_oob_perfcntr: Number of active oob_perfcntr requests */ 62: u32 num_oob_perfcntr; 63: /** @acd_debug_val: DVM value to calibrate ACD for a level */ 64: u32 acd_debug_val; 65: /** @stats_enable: GMU stats feature enable */ 66: bool stats_enable; 67: /** @stats_mask: GMU performance countables to enable */ 68: u32 stats_mask; 69: /** @stats_interval: GMU performance counters sampling interval */ MATCH LINES: 130, 136 118: int gen8_gmu_device_probe(struct platform_device *pdev, 119: u32 chipid, const struct adreno_gpu_core *gpucore); 120: 121: /** 122: * gen8_gmu_reset - Reset and restart the gmu 123: * @adreno_dev: Pointer to the adreno device 124: * 125: * Return: 0 on success or negative error on failure 126: */ 127: int gen8_gmu_reset(struct adreno_device *adreno_dev); 128: 129: /** 130: * gen8_enable_gpu_irq - Enable gpu interrupt 131: * @adreno_dev: Pointer to the adreno device 132: */ 133: void gen8_enable_gpu_irq(struct adreno_device *adreno_dev); 134: 135: /** 136: * gen8_disable_gpu_irq - Disable gpu interrupt 137: * @adreno_dev: Pointer to the adreno device 138: */ 139: void gen8_disable_gpu_irq(struct adreno_device *adreno_dev); 140: 141: /** 142: * gen8_gmu_snapshot- Take snapshot for gmu targets 143: * @adreno_dev: Pointer to the adreno device 144: * @snapshot: Pointer to the snapshot structure 145: * 146: * Send an NMI to gmu if we hit a gmu fault. Then take gmu 147: * snapshot and carry on with rest of the gen8 snapshot 148: */ 149: void gen8_gmu_snapshot(struct adreno_device *adreno_dev, 150: struct kgsl_snapshot *snapshot); 151: 152: /** 153: * gen8_gmu_probe - Probe gen8 gmu resources 154: * @device: Pointer to the kgsl device 155: * @pdev: Pointer to the gmu platform device 156: * 157: * Probe the gmu and hfi resources 158: * 159: * Return: 0 on success or negative error on failure 160: */ MATCH LINES: 242, 245, 248 230: */ 231: void gen8_gmu_register_config(struct adreno_device *adreno_dev); 232: 233: /** 234: * gen8_gmu_version_info - Get gmu firmware version 235: * @adreno_dev: Pointer to the adreno device 236: * 237: * Return: 0 on success or negative error on failure 238: */ 239: int gen8_gmu_version_info(struct adreno_device *adreno_dev); 240: 241: /** 242: * gen8_gmu_irq_enable - Enable gmu interrupts 243: * @adreno_dev: Pointer to the adreno device 244: */ 245: void gen8_gmu_irq_enable(struct adreno_device *adreno_dev); 246: 247: /** 248: * gen8_gmu_irq_disable - Disaable gmu interrupts 249: * @adreno_dev: Pointer to the adreno device 250: */ 251: void gen8_gmu_irq_disable(struct adreno_device *adreno_dev); 252: 253: /** 254: * gen8_gmu_suspend - Hard reset the gpu and gmu 255: * @adreno_dev: Pointer to the adreno device 256: * @force: Set to true to enforce a hard reset 257: * 258: * In case we hit a gmu fault, hard reset the gpu and gmu 259: * to recover from the fault 260: */ 261: void gen8_gmu_suspend(struct adreno_device *adreno_dev, bool force); 262: 263: /** 264: * gen8_gmu_oob_set - send gmu oob request 265: * @device: Pointer to the kgsl device 266: * @req: Type of oob request as defined in enum oob_request 267: * 268: * Request gmu to keep gpu powered up till the oob is cleared 269: * 270: * Return: 0 on success or negative error on failure 271: */ 272: int gen8_gmu_oob_set(struct kgsl_device *device, enum oob_request oob); MATCH LINES: 336 324: * 325: * Return: 0 on success or negative error on failure 326: */ 327: int gen8_halt_gbif(struct adreno_device *adreno_dev); 328: 329: /** 330: * gen8_gmu_remove - Clean up gmu probed resources 331: * @device: Pointer to the kgsl device 332: */ 333: void gen8_gmu_remove(struct kgsl_device *device); 334: 335: /** 336: * gen8_gmu_handle_watchdog - Handle watchdog interrupt 337: * @adreno_dev: Pointer to the adreno device 338: */ 339: void gen8_gmu_handle_watchdog(struct adreno_device *adreno_dev); 340: 341: /** 342: * gen8_gmu_send_nmi - Send NMI to GMU 343: * @device: Pointer to the kgsl device 344: * @gf_policy: GMU fault panic setting policy 345: * @force: Boolean to forcefully send NMI irrespective of GMU state 346: */ 347: void gen8_gmu_send_nmi(struct kgsl_device *device, bool force, 348: enum gmu_fault_panic_policy gf_policy); 349: 350: /** 351: * gen8_gmu_add_to_minidump - Register gen8_device with va minidump 352: * @adreno_dev: Pointer to the adreno device 353: */ 354: int gen8_gmu_add_to_minidump(struct adreno_device *adreno_dev); 355: 356: /** 357: * gen8_gmu_rpmh_pwr_state_is_active - Check the state of GPU HW 358: * @device: Pointer to the kgsl device 359: * 360: * Returns true on active or false otherwise --- FILE: \adreno_gen8_hfi.c | HITS: 8 --- MATCH LINES: 169, 173 157: *msg = RECORD_MSG_HDR(*msg); 158: 159: ret = gen8_hfi_queue_write(adreno_dev, HFI_CMD_ID, msg, size_bytes); 160: 161: /* 162: * Some messages like ACD table and perf table are saved in memory, so we need 163: * to reset the header to make sure we do not send a record enabled bit incase 164: * we change the warmboot setting from debugfs 165: */ 166: *msg = CLEAR_RECORD_MSG_HDR(*msg); 167: /* 168: * Memory barrier to make sure packet and write index are written before 169: * an interrupt is raised 170: */ 171: wmb(); 172: 173: /* Send interrupt to GMU to receive the message */ 174: if (!ret) 175: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), 176: GEN8_GMUCX_HOST2GMU_INTR_SET, 0x1); 177: 178: spin_unlock(&hfi->cmdq_lock); 179: 180: return ret; 181: } 182: 183: /* Sizes of the queue and message are in unit of dwords */ 184: static void init_queues(struct adreno_device *adreno_dev) 185: { 186: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 187: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 188: int i; 189: struct hfi_queue_table *tbl; 190: struct hfi_queue_header *hdr; 191: struct { 192: u32 idx; 193: u32 pri; 194: u32 status; 195: } queue[HFI_QUEUE_MAX] = { 196: { HFI_CMD_ID, HFI_CMD_PRI, HFI_QUEUE_STATUS_ENABLED }, 197: { HFI_MSG_ID, HFI_MSG_PRI, HFI_QUEUE_STATUS_ENABLED }, MATCH LINES: 341, 345 329: poll: 330: rc = poll_gmu_reg(adreno_dev, GEN8_GMUCX_GMU2HOST_INTR_INFO, 331: HFI_IRQ_MSGQ_MASK, HFI_IRQ_MSGQ_MASK, HFI_RSP_TIMEOUT); 332: 333: if (rc) { 334: dev_err(GMU_PDEV_DEV(device), 335: "Timed out waiting on ack for 0x%8.8x (id %d, sequence %d)\n", 336: cmd[0], MSG_HDR_GET_ID(*cmd), MSG_HDR_GET_SEQNUM(*cmd)); 337: gmu_core_fault_snapshot(device, GMU_FAULT_SEND_CMD_WAIT_INLINE); 338: return rc; 339: } 340: 341: /* Clear the interrupt */ 342: gmu_core_regwrite(device, GEN8_GMUCX_GMU2HOST_INTR_CLR, 343: HFI_IRQ_MSGQ_MASK); 344: 345: /* Add a barrier to ensure interrupt is cleared before reading queue and polling again */ 346: mb(); 347: 348: rc = gen8_hfi_process_queue(gmu, HFI_MSG_ID, ret_cmd); 349: 350: /* If ACK not received, try polling again */ 351: if (rc == -EAGAIN) 352: goto poll; 353: 354: return rc; 355: } 356: 357: int gen8_hfi_send_generic_req(struct adreno_device *adreno_dev, void *cmd, u32 size_bytes) 358: { 359: struct pending_cmd ret_cmd; 360: int rc; 361: 362: memset(&ret_cmd, 0, sizeof(ret_cmd)); 363: 364: rc = gen8_hfi_send_cmd_wait_inline(adreno_dev, cmd, size_bytes, &ret_cmd); 365: if (rc) 366: return rc; 367: 368: if (ret_cmd.results[2]) { 369: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); MATCH LINES: 853, 854, 867, 875 841: } 842: 843: void gen8_hfi_stop(struct adreno_device *adreno_dev) 844: { 845: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 846: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 847: 848: kgsl_pwrctrl_axi(device, false); 849: 850: clear_bit(GMU_PRIV_HFI_STARTED, &gmu->flags); 851: } 852: 853: /* HFI interrupt handler */ 854: irqreturn_t gen8_hfi_irq_handler(int irq, void *data) 855: { 856: struct kgsl_device *device = data; 857: struct gen8_gmu_device *gmu = to_gen8_gmu(ADRENO_DEVICE(device)); 858: u32 status = 0; 859: 860: gmu_core_regread(device, GEN8_GMUCX_GMU2HOST_INTR_INFO, &status); 861: gmu_core_regwrite(device, GEN8_GMUCX_GMU2HOST_INTR_CLR, HFI_IRQ_MASK); 862: 863: if (status & HFI_IRQ_DBGQ_MASK) 864: gen8_hfi_process_queue(gmu, HFI_DBG_ID, NULL); 865: if (status & HFI_IRQ_CM3_FAULT_MASK) { 866: dev_err_ratelimited(GMU_PDEV_DEV(device), 867: "GMU CM3 fault interrupt received\n"); 868: atomic_set(&gmu->cm3_fault, 1); 869: 870: /* make sure other CPUs see the update */ 871: smp_wmb(); 872: } 873: if (status & ~HFI_IRQ_MASK) 874: dev_err_ratelimited(GMU_PDEV_DEV(device), 875: "Unhandled HFI interrupts 0x%lx\n", 876: status & ~HFI_IRQ_MASK); 877: 878: return IRQ_HANDLED; 879: } --- FILE: \adreno_gen8_hfi.h | HITS: 3 --- MATCH LINES: 16, 39, 40 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #ifndef __ADRENO_GEN8_HFI_H 8: #define __ADRENO_GEN8_HFI_H 9: 10: #include "adreno_hfi.h" 11: 12: /** 13: * struct gen8_hfi - HFI control structure 14: */ 15: struct gen8_hfi { 16: /** @irq: HFI interrupt line */ 17: int irq; 18: /** @seqnum: atomic counter that is incremented for each message sent. 19: * The value of the counter is used as sequence number for HFI message. 20: */ 21: atomic_t seqnum; 22: /** @hfi_mem: Memory descriptor for the hfi memory */ 23: struct kgsl_memdesc *hfi_mem; 24: /** @bw_table: HFI BW table buffer */ 25: struct hfi_bwtable_cmd bw_table; 26: /** @acd_table: HFI table for ACD data */ 27: struct hfi_acd_table_cmd acd_table; 28: /** @cmdq_lock: Spinlock for accessing the cmdq */ 29: spinlock_t cmdq_lock; 30: /** 31: * @wb_set_record_bitmask: Bitmask to enable or disable the recording 32: * of messages in the GMU scratch. 33: */ 34: unsigned long wb_set_record_bitmask[BITS_TO_LONGS(HFI_MAX_ID)]; 35: }; 36: 37: struct gen8_gmu_device; 38: 39: /* gen8_hfi_irq_handler - IRQ handler for HFI interripts */ 40: irqreturn_t gen8_hfi_irq_handler(int irq, void *data); 41: 42: /** 43: * gen8_hfi_start - Send the various HFIs during device boot up 44: * @adreno_dev: Pointer to the adreno device 45: * 46: * Return: 0 on success or negative error on failure 47: */ 48: int gen8_hfi_start(struct adreno_device *adreno_dev); 49: 50: /** 51: * gen8_hfi_start - Send the various HFIs during device boot up 52: * @adreno_dev: Pointer to the adreno device 53: * 54: * Return: 0 on success or negative error on failure 55: */ 56: void gen8_hfi_stop(struct adreno_device *adreno_dev); 57: 58: /** 59: * gen8_hfi_init - Initialize hfi resources 60: * @adreno_dev: Pointer to the adreno device 61: * 62: * This function allocates and sets up hfi queues 63: * when a process creates the very first kgsl instance 64: * --- FILE: \adreno_gen8_hwsched.c | HITS: 11 --- MATCH LINES: 23, 29, 30, 31 11: #include "adreno_gen8_hwsched.h" 12: #include "adreno_snapshot.h" 13: #include "kgsl_bus.h" 14: #include "kgsl_device.h" 15: #include "kgsl_gmu_core.h" 16: #include "kgsl_trace.h" 17: #include "kgsl_util.h" 18: 19: static void _wakeup_hw_fence_waiters(struct adreno_device *adreno_dev, u32 fault) 20: { 21: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 22: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 23: bool lock = !in_interrupt(); 24: 25: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags)) 26: return; 27: 28: /* 29: * We could be in interrupt context here, which means we need to use spin_lock_irqsave 30: * (which disables interrupts) everywhere we take this lock. Instead of that, simply 31: * avoid taking this lock if we are recording a fault from an interrupt handler. 32: */ 33: if (lock) 34: spin_lock(&hwf->lock); 35: 36: clear_bit(GEN8_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags); 37: 38: /* Avoid creating new hardware fences until recovery is complete */ 39: set_bit(GEN8_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags); 40: 41: if (!lock) { 42: /* 43: * This barrier ensures that the above bitops complete before we wake up the waiters 44: */ 45: smp_wmb(); 46: } else { 47: spin_unlock(&hwf->lock); 48: } 49: 50: wake_up_all(&hwf->unack_wq); 51: 52: kgsl_delete_timer(&hfi->hw_fence_timer); 53: } 54: 55: void gen8_hwsched_fault(struct adreno_device *adreno_dev, u32 fault) MATCH LINES: 317, 328 305: ret = gen8_gmu_itcm_shadow(adreno_dev); 306: if (ret) 307: goto clks_gdsc_off; 308: 309: _get_hw_fence_entries(adreno_dev); 310: 311: gen8_gmu_register_config(adreno_dev); 312: 313: ret = gen8_gmu_version_info(adreno_dev); 314: if (ret) 315: goto clks_gdsc_off; 316: 317: gen8_gmu_irq_enable(adreno_dev); 318: 319: /* Vote for minimal DDR BW for GMU to init */ 320: level = pwr->pwrlevels[pwr->default_pwrlevel].bus_min; 321: 322: icc_set_bw(pwr->icc_path, 0, kBps_to_icc(pwr->ddr_table[level])); 323: 324: /* This is the minimum GMU FW HFI version required to enable hw fences */ 325: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) >= 7) 326: adreno_hwsched_register_hw_fence(adreno_dev); 327: 328: /* From this GMU FW all RBBM interrupts are handled at GMU */ 329: if (device->gmu_core.ver.core >= GMU_VERSION(5, 01, 06)) 330: adreno_irq_free(adreno_dev); 331: 332: gen8_hwsched_soccp_vote(adreno_dev, true); 333: 334: /* Clear any hwsched faults that might have been left over */ 335: adreno_clear_gpu_fault(adreno_dev); 336: 337: ret = gen8_gmu_device_start(adreno_dev); 338: if (ret) 339: goto err; 340: 341: gen8_get_gpu_feature_info(adreno_dev); 342: 343: ret = gen8_hwsched_hfi_start(adreno_dev); 344: if (ret) 345: goto err; 346: 347: if (adreno_dev->gmu_ab && 348: gen8_hwsched_hfi_get_value(adreno_dev, HFI_VALUE_GMU_AB_VOTE, 0) == 1 && 349: !WARN_ONCE(!adreno_dev->gpucore->num_ddr_channels, 350: "Number of DDR channel is not specified in gpu core")) { 351: set_bit(ADRENO_DEVICE_GMU_AB, &adreno_dev->priv); 352: } else { MATCH LINES: 451 439: gen8_cx_timer_init(adreno_dev); 440: 441: ret = gen8_rscc_wakeup_sequence(adreno_dev); 442: if (ret) 443: goto clks_gdsc_off; 444: 445: ret = gen8_gmu_load_fw(adreno_dev); 446: if (ret) 447: goto clks_gdsc_off; 448: 449: gen8_gmu_register_config(adreno_dev); 450: 451: gen8_gmu_irq_enable(adreno_dev); 452: 453: gen8_hwsched_soccp_vote(adreno_dev, true); 454: 455: /* Clear any hwsched faults that might have been left over */ 456: adreno_clear_gpu_fault(adreno_dev); 457: 458: ret = gen8_gmu_device_start(adreno_dev); 459: if (ret) 460: goto err; 461: 462: ret = gen8_hwsched_hfi_start(adreno_dev); 463: if (ret) 464: goto err; 465: 466: device->gmu_fault = false; 467: 468: kgsl_pwrctrl_set_state(device, KGSL_STATE_AWARE); 469: 470: return 0; 471: err: 472: gen8_gmu_irq_disable(adreno_dev); 473: gen8_hwsched_soccp_vote(adreno_dev, false); 474: 475: if (device->gmu_fault) { MATCH LINES: 1347, 1348, 1350, 1356 1335: adreno_put_gpu_halt(adreno_dev); 1336: 1337: adreno_hwsched_start(adreno_dev); 1338: 1339: clear_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags); 1340: } 1341: 1342: void gen8_hwsched_handle_watchdog(struct adreno_device *adreno_dev) 1343: { 1344: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1345: u32 mask; 1346: 1347: /* Temporarily mask the watchdog interrupt to prevent a storm */ 1348: gmu_core_regread(device, GEN8_GMUAO_AO_HOST_INTERRUPT_MASK, 1349: &mask); 1350: gmu_core_regwrite(device, GEN8_GMUAO_AO_HOST_INTERRUPT_MASK, 1351: (mask | GMU_INT_WDOG_BITE)); 1352: 1353: gen8_gmu_send_nmi(device, false, GMU_FAULT_PANIC_NONE); 1354: 1355: dev_err_ratelimited(GMU_PDEV_DEV(device), 1356: "GMU watchdog expired interrupt received\n"); 1357: 1358: gen8_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 1359: } 1360: 1361: static void gen8_hwsched_drain_ctxt_unregister(struct adreno_device *adreno_dev) 1362: { 1363: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 1364: struct pending_cmd *cmd = NULL; 1365: 1366: read_lock(&hfi->msglock); 1367: 1368: list_for_each_entry(cmd, &hfi->msglist, node) { 1369: if (MSG_HDR_GET_ID(cmd->sent_hdr) == H2F_MSG_UNREGISTER_CONTEXT) 1370: complete(&cmd->complete); 1371: } 1372: 1373: read_unlock(&hfi->msglock); 1374: } 1375: 1376: /** 1377: * process_context_hw_fences_after_reset - This function processes all hardware fences that were 1378: * sent to GMU prior to recovery. If a fence is not retired by the GPU, and the context is still 1379: * good, then move them to the reset list. 1380: */ --- FILE: \adreno_gen8_hwsched.h | HITS: 2 --- MATCH LINES: 70, 87 58: 59: /** 60: * gen8_hwsched_snapshot - take gen8 hwsched snapshot 61: * @adreno_dev: Pointer to the adreno device 62: * @snapshot: Pointer to the snapshot instance 63: * 64: * Snapshot the faulty ib and then snapshot rest of gen8 gmu things 65: */ 66: void gen8_hwsched_snapshot(struct adreno_device *adreno_dev, 67: struct kgsl_snapshot *snapshot); 68: 69: /** 70: * gen8_hwsched_handle_watchdog - Handle watchdog interrupt 71: * @adreno_dev: Pointer to the adreno device 72: */ 73: void gen8_hwsched_handle_watchdog(struct adreno_device *adreno_dev); 74: 75: /** 76: * gen8_hwsched_add_to_minidump - Register hwsched_device with va minidump 77: * @adreno_dev: Pointer to the adreno device 78: */ 79: int gen8_hwsched_add_to_minidump(struct adreno_device *adreno_dev); 80: 81: /** 82: * gen8_hwsched_send_recurring_cmdobj - Dispatch IBs to GMU 83: * @adreno_dev: Pointer to adreno device structure 84: * @cmdobj: The command object which needs to be submitted 85: * 86: * This function is used to register the context if needed and submit 87: * recurring IBs to the GMU. Upon receiving ipc interrupt GMU will submit 88: * recurring IBs to GPU. 89: 90: * Return: 0 on success and negative error on failure 91: */ 92: int gen8_hwsched_send_recurring_cmdobj(struct adreno_device *adreno_dev, 93: struct kgsl_drawobj_cmd *cmdobj); 94: 95: /** 96: * gen8_hwsched_fault - Set hwsched fault to request recovery 97: * @adreno_dev: A handle to adreno device 98: * @fault: The type of fault 99: */ 100: void gen8_hwsched_fault(struct adreno_device *adreno_dev, u32 fault); 101: 102: /** 103: * gen8_hwsched_soccp_vote - Vote for soccp power 104: * @adreno_dev: A handle to adreno device 105: * @pwr_on: Boolean to turn soccp on/off 106: */ 107: void gen8_hwsched_soccp_vote(struct adreno_device *adreno_dev, bool pwr_on); 108: 109: /** 110: * gen8_hwsched_set_pwrconstraint - Send perf hint to GMU 111: * @adreno_dev: A handle to adreno device --- FILE: \adreno_gen8_hwsched_hfi.c | HITS: 28 --- MATCH LINES: 287, 305 275: return false; 276: 277: switch (cmd->error) { 278: case GMU_GPU_HW_HANG: 279: dev_crit_ratelimited(gmu_pdev_dev, "MISC: GPU hang detected\n"); 280: break; 281: case GMU_GPU_SW_HANG: 282: dev_crit_ratelimited(gmu_pdev_dev, "gpu timeout ctx %u ts %u\n", 283: cmd->gc.ctxt_id, cmd->gc.ts); 284: break; 285: case GMU_CP_OPCODE_ERROR: 286: dev_crit_ratelimited(gmu_pdev_dev, 287: "CP opcode error interrupt | opcode=0x%8.8x\n", 288: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 289: KEY_CP_OPCODE_ERROR)); 290: break; 291: case GMU_CP_PROTECTED_ERROR: { 292: u32 status = gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 293: KEY_CP_PROTECTED_ERROR); 294: 295: dev_crit_ratelimited(gmu_pdev_dev, 296: "CP | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 297: status & (1 << 20) ? "READ" : "WRITE", 298: status & 0x3FFFF, status); 299: } 300: break; 301: case GMU_CP_ILLEGAL_INST_ERROR: 302: dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n"); 303: break; 304: case GMU_CP_UCODE_ERROR: 305: dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n"); 306: break; 307: case GMU_CP_HW_FAULT_ERROR: 308: dev_crit_ratelimited(gmu_pdev_dev, 309: "CP | Ringbuffer HW fault | status=0x%8.8x\n", 310: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 311: KEY_CP_HW_FAULT)); 312: break; 313: case GMU_GPU_PREEMPT_TIMEOUT: { 314: u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr; 315: 316: cur = gen8_hwsched_lookup_key_value(adreno_dev, 317: PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID); 318: next = gen8_hwsched_lookup_key_value(adreno_dev, 319: PAYLOAD_PREEMPT_TIMEOUT, 320: KEY_PREEMPT_TIMEOUT_NEXT_RB_ID); 321: cur_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_RPTR); 322: cur_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_WPTR); 323: next_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_RPTR); 324: next_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_WPTR); 325: 326: dev_crit_ratelimited(gmu_pdev_dev, 327: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n", 328: cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr); 329: } MATCH LINES: 360, 388, 405, 421 348: } 349: break; 350: case GMU_CP_BV_HW_FAULT_ERROR: 351: dev_crit_ratelimited(gmu_pdev_dev, 352: "CP BV | Ringbuffer HW fault | status=0x%8.8x\n", 353: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 354: KEY_CP_BV_HW_FAULT)); 355: break; 356: case GMU_CP_BV_ILLEGAL_INST_ERROR: 357: dev_crit_ratelimited(gmu_pdev_dev, "CP BV Illegal instruction error\n"); 358: break; 359: case GMU_CP_BV_UCODE_ERROR: 360: dev_crit_ratelimited(gmu_pdev_dev, "CP BV ucode error interrupt\n"); 361: break; 362: case GMU_CP_LPAC_OPCODE_ERROR: 363: dev_crit_ratelimited(gmu_pdev_dev, 364: "CP LPAC opcode error | opcode=0x%8.8x\n", 365: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 366: KEY_CP_LPAC_OPCODE_ERROR)); 367: break; 368: case GMU_CP_LPAC_PROTECTED_ERROR: { 369: u32 status = gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 370: KEY_CP_LPAC_PROTECTED_ERROR); 371: 372: dev_crit_ratelimited(gmu_pdev_dev, 373: "CP LPAC | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 374: status & (1 << 20) ? "READ" : "WRITE", 375: status & 0x3FFFF, status); 376: } 377: break; 378: case GMU_CP_LPAC_HW_FAULT_ERROR: 379: dev_crit_ratelimited(gmu_pdev_dev, 380: "CP LPAC | Ringbuffer HW fault | status=0x%8.8x\n", 381: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 382: KEY_CP_LPAC_HW_FAULT)); 383: break; 384: case GMU_CP_LPAC_ILLEGAL_INST_ERROR: 385: dev_crit_ratelimited(gmu_pdev_dev, "CP LPAC Illegal instruction error\n"); 386: break; 387: case GMU_CP_LPAC_UCODE_ERROR: 388: dev_crit_ratelimited(gmu_pdev_dev, "CP LPAC ucode error interrupt\n"); 389: break; 390: case GMU_GPU_LPAC_SW_HANG: 391: dev_crit_ratelimited(gmu_pdev_dev, "LPAC: gpu timeout ctx %u ts %u\n", 392: cmd->lpac.ctxt_id, cmd->lpac.ts); 393: break; 394: case GMU_GPU_SW_FUSE_VIOLATION: 395: dev_crit_ratelimited(gmu_pdev_dev, "RBBM: SW Feature Fuse violation status=0x%8.8x\n", 396: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 397: KEY_SWFUSE_VIOLATION_FAULT)); 398: break; 399: case GMU_GPU_AQE0_OPCODE_ERROR: 400: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 opcode error | opcode=0x%8.8x\n", 401: gen8_hwsched_lookup_key_value(adreno_dev, 402: PAYLOAD_FAULT_REGS, KEY_AQE0_OPCODE_ERROR)); 403: break; 404: case GMU_GPU_AQE0_UCODE_ERROR: 405: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 ucode error interrupt\n"); 406: break; 407: case GMU_GPU_AQE0_HW_FAULT_ERROR: 408: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 HW fault | status=0x%8.8x\n", 409: gen8_hwsched_lookup_key_value(adreno_dev, 410: PAYLOAD_FAULT_REGS, KEY_AQE0_HW_FAULT)); 411: break; 412: case GMU_GPU_AQE0_ILLEGAL_INST_ERROR: 413: dev_crit_ratelimited(gmu_pdev_dev, "AQE0 Illegal instruction error\n"); 414: break; 415: case GMU_GPU_AQE1_OPCODE_ERROR: 416: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 opcode error | opcode=0x%8.8x\n", 417: gen8_hwsched_lookup_key_value(adreno_dev, 418: PAYLOAD_FAULT_REGS, KEY_AQE1_OPCODE_ERROR)); 419: break; 420: case GMU_GPU_AQE1_UCODE_ERROR: 421: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 ucode error interrupt\n"); 422: break; 423: case GMU_GPU_AQE1_HW_FAULT_ERROR: 424: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 HW fault | status=0x%8.8x\n", 425: gen8_hwsched_lookup_key_value(adreno_dev, 426: PAYLOAD_FAULT_REGS, KEY_AQE1_HW_FAULT)); 427: break; 428: case GMU_GPU_AQE1_ILLEGAL_INST_ERROR: 429: dev_crit_ratelimited(gmu_pdev_dev, "AQE1 Illegal instruction error\n"); 430: break; 431: case GMU_SYNCOBJ_TIMEOUT_ERROR: 432: dev_crit_ratelimited(gmu_pdev_dev, "syncobj timeout ctx %d ts %u\n", 433: cmd->gc.ctxt_id, cmd->gc.ts); 434: find_timeout_syncobj(adreno_dev, cmd->gc.ctxt_id, cmd->gc.ts); 435: break; 436: case GMU_CP_DDEBR_HW_FAULT_ERROR: 437: dev_crit_ratelimited(gmu_pdev_dev, 438: "CP DDE BR | Ringbuffer HW fault | status=0x%8.8x\n", 439: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 440: KEY_CP_DDEBR_HW_FAULT)); 441: break; 442: case GMU_CP_DDEBR_OPCODE_ERROR: 443: dev_crit_ratelimited(gmu_pdev_dev, 444: "CP DDE BR opcode error | opcode=0x%8.8x\n", 445: gen8_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, MATCH LINES: 534 522: "CP AQE1 | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n", 523: status & (1 << 20) ? "READ" : "WRITE", 524: status & 0x3FFFF, status); 525: } 526: break; 527: case GMU_CP_DDEBR_SW_FAULT_ERROR: 528: handle_sw_fault(adreno_dev, "DDE BR", KEY_CP_DDEBR_SW_FAULT); 529: break; 530: case GMU_CP_DDEBV_SW_FAULT_ERROR: 531: handle_sw_fault(adreno_dev, "DDE BV", KEY_CP_DDEBV_SW_FAULT); 532: break; 533: case GMU_DBGC_INTR_ERROR: 534: dev_crit_ratelimited(gmu_pdev_dev, "DBGC error interrupt\n"); 535: break; 536: case GMU_CP_UNKNOWN_ERROR: 537: fallthrough; 538: default: 539: dev_crit_ratelimited(gmu_pdev_dev, "Unknown GPU fault: %u\n", 540: cmd->error); 541: break; 542: } 543: 544: /* Return true for fatal errors to perform recovery sequence */ 545: return true; 546: } 547: 548: static bool is_queue_empty(struct adreno_device *adreno_dev, u32 queue_idx) 549: { 550: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 551: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 552: struct hfi_queue_table *tbl = mem_addr->hostptr; 553: struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx]; 554: 555: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 556: return true; 557: 558: if (hdr->read_index == hdr->write_index) MATCH LINES: 588 576: u32 *queue; 577: 578: if (is_queue_empty(adreno_dev, queue_idx)) 579: return 0; 580: 581: queue = HOST_QUEUE_START_ADDR(mem_addr, queue_idx); 582: 583: return queue[hdr->read_index]; 584: } 585: 586: static void process_ctx_bad(struct adreno_device *adreno_dev) 587: { 588: /* Non fatal RBBM error interrupts don't go through reset and recovery */ 589: if (!log_gpu_fault(adreno_dev)) { 590: memset(adreno_dev->hwsched.ctxt_bad, 0x0, HFI_MAX_MSG_SIZE); 591: return; 592: } 593: 594: adreno_dev->hwsched.reset_type = gen8_hwsched_lookup_key_value(adreno_dev, 595: PAYLOAD_FAULT_RESET_POLICY, KEY_GPU_RESET_POLICY); 596: 597: gen8_hwsched_fault(adreno_dev, ADRENO_HARD_FAULT); 598: } 599: 600: #define GET_QUERIED_FENCE_INDEX(x) (x / BITS_PER_SYNCOBJ_QUERY) 601: #define GET_QUERIED_FENCE_BIT(x) (x % BITS_PER_SYNCOBJ_QUERY) 602: 603: static bool fence_is_queried(struct hfi_syncobj_query_cmd *cmd, u32 fence_index) 604: { 605: u32 index = GET_QUERIED_FENCE_INDEX(fence_index); 606: u32 bit = GET_QUERIED_FENCE_BIT(fence_index); 607: 608: return (cmd->queries[index].query_bitmask & BIT(bit)); 609: } 610: 611: static void set_fence_signal_bit(struct adreno_device *adreno_dev, 612: struct hfi_syncobj_query_cmd *reply, struct dma_fence *fence, u32 fence_index) MATCH LINES: 1183, 1184, 1202, 1210, 1220, 1233 1171: 1172: /* Process one debug queue message and return to not delay msgq processing */ 1173: if (limited) 1174: break; 1175: } 1176: 1177: if (!recovery) 1178: return; 1179: 1180: gen8_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 1181: } 1182: 1183: /* HFI interrupt handler */ 1184: static irqreturn_t gen8_hwsched_hfi_handler(int irq, void *data) 1185: { 1186: struct adreno_device *adreno_dev = data; 1187: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1188: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 1189: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1190: u32 status = 0; 1191: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1192: u64 ticks = gpudev->read_alwayson(adreno_dev); 1193: 1194: /* 1195: * GEN8_GMUCX_GMU2HOST_INTR_INFO may have bits set not specified in hfi->irq_mask. 1196: * Read and clear only those irq bits that we are processing here. 1197: */ 1198: gmu_core_regread(device, GEN8_GMUCX_GMU2HOST_INTR_INFO, &status); 1199: gmu_core_regwrite(device, GEN8_GMUCX_GMU2HOST_INTR_CLR, status & hfi->irq_mask); 1200: 1201: /* 1202: * If interrupts are not enabled on the HFI message queue, 1203: * the inline message processing loop will process it, 1204: * else, process it here. 1205: */ 1206: if (!(hfi->irq_mask & HFI_IRQ_MSGQ_MASK)) 1207: status &= ~HFI_IRQ_MSGQ_MASK; 1208: 1209: if (status & (HFI_IRQ_MSGQ_MASK | HFI_IRQ_DBGQ_MASK)) { 1210: wake_up_interruptible(&hfi->f2h_wq); 1211: adreno_scheduler_queue(adreno_dev); 1212: } 1213: if (status & HFI_IRQ_CM3_FAULT_MASK) { 1214: atomic_set(&gmu->cm3_fault, 1); 1215: 1216: /* make sure other CPUs see the update */ 1217: smp_wmb(); 1218: 1219: dev_err_ratelimited(GMU_PDEV_DEV(device), 1220: "GMU CM3 fault interrupt received\n"); 1221: 1222: KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic, 1223: GMU_PDEV(device), ticks, GMU_FAULT_CM3); 1224: 1225: gen8_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 1226: } 1227: 1228: /* Ignore OOB bits */ 1229: status &= GENMASK(31 - (oob_max - 1), 0); 1230: 1231: if (status & ~hfi->irq_mask) 1232: dev_err_ratelimited(GMU_PDEV_DEV(device), 1233: "Unhandled HFI interrupts 0x%x\n", 1234: status & ~hfi->irq_mask); 1235: 1236: return IRQ_HANDLED; 1237: } 1238: 1239: #define HFI_IRQ_MSGQ_MASK BIT(0) 1240: 1241: static int check_ack_failure(struct adreno_device *adreno_dev, 1242: struct pending_cmd *ack) 1243: { 1244: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1245: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1246: u64 ticks = gpudev->read_alwayson(adreno_dev); 1247: 1248: if (ack->results[2] != 0xffffffff) 1249: return 0; 1250: 1251: dev_err(GMU_PDEV_DEV(device), 1252: "ACK error: sender id %d seqnum %d\n", 1253: MSG_HDR_GET_ID(ack->sent_hdr), 1254: MSG_HDR_GET_SEQNUM(ack->sent_hdr)); 1255: 1256: KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic, 1257: GMU_PDEV(device), ticks, GMU_FAULT_HFI_ACK); MATCH LINES: 1513, 1516, 1517, 1549 1501: MSG_HDR_GET_ID(rcvd[0]), 1502: MSG_HDR_GET_TYPE(rcvd[0])); 1503: gmu_core_fault_snapshot(device, GMU_FAULT_H2F_MSG_START); 1504: rc = -EINVAL; 1505: goto done; 1506: } 1507: } 1508: 1509: if (!rc) 1510: goto poll; 1511: 1512: done: 1513: /* Clear the interrupt */ 1514: gmu_core_regwrite(device, GEN8_GMUCX_GMU2HOST_INTR_CLR, HFI_IRQ_MSGQ_MASK); 1515: /* 1516: * Add a write barrier to post the interrupt clear so that we dont have a 1517: * pending interrupt. 1518: */ 1519: wmb(); 1520: return rc; 1521: } 1522: 1523: static void reset_hfi_queues(struct adreno_device *adreno_dev) 1524: { 1525: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1526: struct hfi_queue_table *tbl = gmu->hfi.hfi_mem->hostptr; 1527: u32 i; 1528: 1529: /* Flush HFI queues */ 1530: for (i = 0; i < HFI_QUEUE_MAX; i++) { 1531: struct hfi_queue_header *hdr = &tbl->qhdr[i]; 1532: 1533: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 1534: continue; 1535: 1536: hdr->read_index = hdr->write_index; 1537: } 1538: } 1539: 1540: void gen8_hwsched_hfi_stop(struct adreno_device *adreno_dev) 1541: { 1542: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1543: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 1544: 1545: hfi->irq_mask &= ~HFI_IRQ_MSGQ_MASK; 1546: 1547: /* 1548: * In some corner cases, it is possible that GMU put TS_RETIRE 1549: * on the msgq after we have turned off gmu interrupts. Hence, 1550: * drain the queue one last time before we reset HFI queues. 1551: */ 1552: gen8_hwsched_process_msgq(adreno_dev); 1553: 1554: /* Drain the debug queue before we reset HFI queues */ 1555: gen8_hwsched_process_dbgq(adreno_dev, false); 1556: 1557: kgsl_pwrctrl_axi(KGSL_DEVICE(adreno_dev), false); 1558: 1559: clear_bit(GMU_PRIV_HFI_STARTED, &gmu->flags); 1560: } 1561: 1562: static void gen8_hwsched_enable_async_hfi(struct adreno_device *adreno_dev) 1563: { 1564: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 1565: 1566: hfi->irq_mask |= HFI_IRQ_MSGQ_MASK; 1567: 1568: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN8_GMUCX_GMU2HOST_INTR_MASK, 1569: (u32)~hfi->irq_mask); 1570: } 1571: 1572: static int enable_preemption(struct adreno_device *adreno_dev) 1573: { MATCH LINES: 1800, 1801, 1804 1788: const char *str) 1789: { 1790: struct kgsl_device *device = &adreno_dev->dev; 1791: u32 rptr, wptr, status, intstatus, global_status; 1792: bool val = adreno_is_preemption_enabled(adreno_dev); 1793: 1794: dev_err(device->dev, str); 1795: 1796: kgsl_regread(device, GEN8_CP_RB_RPTR_LPAC, &rptr); 1797: kgsl_regread(device, GEN8_CP_RB_WPTR_LPAC, &wptr); 1798: 1799: kgsl_regread(device, GEN8_RBBM_STATUS, &status); 1800: kgsl_regread(device, GEN8_RBBM_INT_0_STATUS, &intstatus); 1801: kgsl_regread(device, GEN8_CP_INTERRUPT_STATUS_GLOBAL, &global_status); 1802: 1803: dev_err(device->dev, 1804: "LPAC rb=%d pos=%X/%X rbbm_status=%8.8X int_0_status=%8.8X global_status=%8.8X\n", 1805: val ? KGSL_LPAC_RB_ID : 1, rptr, wptr, 1806: status, intstatus, global_status); 1807: 1808: kgsl_device_snapshot(device, NULL, NULL, false); 1809: } 1810: 1811: static bool gen8_hwsched_warmboot_possible(struct adreno_device *adreno_dev) 1812: { 1813: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1814: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1815: struct gmu_core_device *gmu_core = &device->gmu_core; 1816: 1817: if (gmu_core->warmboot_enabled && test_bit(GMU_PRIV_WARMBOOT_GMU_INIT_DONE, &gmu->flags) 1818: && test_bit(GMU_PRIV_WARMBOOT_GPU_BOOT_DONE, &gmu->flags) && 1819: !test_bit(GMU_FORCE_COLDBOOT, &device->gmu_core.flags)) 1820: return true; 1821: 1822: return false; 1823: } 1824: 1825: static int gen8_hwsched_hfi_send_warmboot_cmd(struct adreno_device *adreno_dev, 1826: struct kgsl_memdesc *desc, u32 flag, bool async, struct pending_cmd *ack) 1827: { 1828: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); MATCH LINES: 2878 2866: return submit_lpac_raw_cmds(adreno_dev, cmds, sizeof(cmds), 2867: "LPAC CP initialization failed to idle\n"); 2868: } 2869: 2870: static int hfi_f2h_main(void *arg) 2871: { 2872: struct adreno_device *adreno_dev = arg; 2873: struct device *gmu_pdev_dev = GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)); 2874: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 2875: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2876: 2877: while (!kthread_should_stop()) { 2878: wait_event_interruptible(hfi->f2h_wq, kthread_should_stop() || 2879: /* If msgq irq is enabled and msgq has messages to process */ 2880: (((hfi->irq_mask & HFI_IRQ_MSGQ_MASK) && 2881: !is_queue_empty(adreno_dev, HFI_MSG_ID)) || 2882: /* Trace buffer has messages to process */ 2883: !gmu_core_is_trace_empty(device->gmu_core.trace.md->hostptr) || 2884: /* Dbgq has messages to process */ 2885: !is_queue_empty(adreno_dev, HFI_DBG_ID))); 2886: 2887: if (kthread_should_stop()) 2888: break; 2889: 2890: gen8_hwsched_process_msgq(adreno_dev); 2891: gmu_core_process_trace_data(KGSL_DEVICE(adreno_dev), 2892: gmu_pdev_dev, &device->gmu_core.trace); 2893: gen8_hwsched_process_dbgq(adreno_dev, true); 2894: } 2895: 2896: return 0; 2897: } 2898: 2899: static void gen8_hwsched_hw_fence_timeout(struct work_struct *work) 2900: { 2901: struct gen8_hwsched_hfi *hfi = container_of(work, struct gen8_hwsched_hfi, hw_fence_ws); 2902: struct gen8_hwsched_device *gen8_hw_dev = container_of(hfi, struct gen8_hwsched_device, MATCH LINES: 3623 3611: */ 3612: static int _hw_fence_sleep(struct adreno_device *adreno_dev, struct adreno_context *drawctxt) 3613: { 3614: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3615: int ret = 0; 3616: 3617: if (!test_bit(GEN8_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags)) 3618: return 0; 3619: 3620: spin_unlock(&hwf->lock); 3621: spin_unlock(&drawctxt->lock); 3622: 3623: ret = wait_event_interruptible(hwf->unack_wq, _hw_fence_end_sleep(adreno_dev)); 3624: 3625: spin_lock(&drawctxt->lock); 3626: spin_lock(&hwf->lock); 3627: 3628: /* 3629: * If the thread received a signal, or the context became bad in the meanwhile or the limit 3630: * is still not settled, then return error to avoid creating this hardware fence 3631: */ 3632: if ((ret == -ERESTARTSYS) || kgsl_context_is_bad(&drawctxt->base) || 3633: test_bit(GEN8_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags)) 3634: return -EINVAL; 3635: 3636: /* 3637: * If fault recovery is imminent then return error code to avoid creating new hardware 3638: * fences until recovery is complete 3639: */ 3640: if (test_bit(GEN8_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags)) 3641: return -EBUSY; 3642: 3643: return ret; 3644: } 3645: 3646: void gen8_hwsched_create_hw_fence(struct adreno_device *adreno_dev, 3647: struct kgsl_sync_fence *kfence) MATCH LINES: 3907 3895: cmd->hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_CMD, HFI_MSG_CMD); 3896: seqnum = atomic_inc_return(&adreno_dev->hwsched.submission_seqnum); 3897: cmd->hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd->hdr, seqnum, cmd_sizebytes >> 2); 3898: 3899: ret = adreno_gmu_context_queue_write(adreno_dev, &drawctxt->gmu_context_queue, 3900: (u32 *)cmd, cmd_sizebytes, drawobj, &time); 3901: if (ret) 3902: return ret; 3903: 3904: hdr = drawctxt->gmu_context_queue.hostptr; 3905: /* The last sync object has been retired by the GMU */ 3906: if (timestamp_cmp(hdr->sync_obj_ts, drawctxt->syncobj_timestamp) >= 0) 3907: /* Send interrupt to GMU to receive the message */ 3908: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN8_GMUCX_HOST2GMU_INTR_SET, 3909: DISPQ_IRQ_BIT(get_irq_bit(adreno_dev, drawobj->context))); 3910: else 3911: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN8_GMUCX_HOST2GMU_INTR_SET, 3912: DISPQ_SYNC_IRQ_BIT(get_irq_bit(adreno_dev, drawobj->context))); 3913: 3914: drawctxt->internal_timestamp = drawobj->timestamp; 3915: 3916: spin_lock(&drawctxt->lock); 3917: process_hw_fence_queue(adreno_dev, drawctxt, drawobj->timestamp); 3918: /* 3919: * We need to update the gmu_hw_fence_ready_ts while holding the drawctxt lock since we 3920: * have to check it in the hardware fence creation path, where we are not taking the 3921: * device mutex. 3922: */ 3923: drawctxt->gmu_hw_fence_ready_ts = drawobj->timestamp; 3924: spin_unlock(&drawctxt->lock); 3925: 3926: return 0; 3927: } 3928: 3929: int gen8_hwsched_send_recurring_cmdobj(struct adreno_device *adreno_dev, 3930: struct kgsl_drawobj_cmd *cmdobj) 3931: { MATCH LINES: 4025 4013: /* Star LSR timer for power stats collection */ 4014: mod_timer(&hwsched->lsr_timer, jiffies + msecs_to_jiffies(10)); 4015: return ret; 4016: } 4017: 4018: /* We don't want to unnecessarily wake the GMU to trigger hardware fences */ 4019: static void drain_context_hw_fence_cpu(struct adreno_device *adreno_dev, 4020: struct adreno_context *drawctxt) 4021: { 4022: struct adreno_hw_fence_entry *entry, *tmp; 4023: 4024: /* 4025: * Triggering these fences from HLOS may send interrupts to soccp. Hence, vote for soccp 4026: * here 4027: */ 4028: gen8_hwsched_soccp_vote(adreno_dev, true); 4029: 4030: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_list, node) { 4031: 4032: kgsl_hw_fence_trigger_cpu(KGSL_DEVICE(adreno_dev), entry->kfence); 4033: 4034: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 4035: } 4036: 4037: gen8_hwsched_soccp_vote(adreno_dev, false); 4038: } 4039: 4040: /* 4041: * destroy_detached_context_inflight_hw_fences - Destroy context's hardware fences that were 4042: * dispatched to GMU 4043: */ 4044: static void destroy_detached_context_inflight_hw_fences(struct adreno_device *adreno_dev, 4045: struct adreno_context *drawctxt) 4046: { 4047: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 4048: struct adreno_hw_fence_entry *entry, *tmp; 4049: MATCH LINES: 4275, 4283 4263: if ((ack & ack_mask) == ack_mask) 4264: return; 4265: usleep_range(10, 100); 4266: } while (!time_after(jiffies, t)); 4267: 4268: kgsl_regread(device, ack_reg, &ack); 4269: if ((ack & ack_mask) == ack_mask) 4270: return; 4271: 4272: dev_err(device->dev, "%s GBIF halt timed out\n", client); 4273: } 4274: 4275: static void gen8_hwsched_raise_dispatch_interrupt(struct adreno_device *adreno_dev) 4276: { 4277: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 4278: struct cmd_list_obj *obj, *tmp; 4279: 4280: list_for_each_entry_safe(obj, tmp, &hwsched->cmd_list, node) { 4281: struct kgsl_drawobj *drawobj = obj->drawobj; 4282: 4283: /* Raise dispatch interrupt for inflight commands */ 4284: if (adreno_hwsched_drawobj_replay(adreno_dev, drawobj)) 4285: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN8_GMUCX_HOST2GMU_INTR_SET, 4286: DISPQ_IRQ_BIT(get_irq_bit(adreno_dev, drawobj->context))); 4287: else 4288: adreno_hwsched_retire_cmdlist_obj(adreno_dev, obj); 4289: } 4290: } 4291: 4292: int gen8_hwsched_soft_reset(struct adreno_device *adreno_dev, 4293: struct kgsl_context *context, bool ctx_guilty) 4294: { 4295: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 4296: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 4297: struct hfi_context_bad_cmd *in = (struct hfi_context_bad_cmd *)adreno_dev->hwsched.ctxt_bad; 4298: int ret; 4299: 4300: if (!test_bit(ADRENO_HWSCHED_GPU_SOFT_RESET, &adreno_dev->hwsched.flags)) 4301: return -EOPNOTSUPP; 4302: 4303: if (adreno_dev->hwsched.reset_type != GMU_GPU_SOFT_RESET) 4304: return -EINVAL; 4305: 4306: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 4307: return 0; MATCH LINES: 4367 4355: FIELD_PREP(GENMASK(11, 9), 6), 1000, GENMASK(11, 9)); 4356: if (ret) 4357: goto done; 4358: 4359: gen8_hwsched_init_ucode_regs(adreno_dev); 4360: 4361: gen8_enable_gpu_irq(adreno_dev); 4362: 4363: ret = gen8_hwsched_boot_gpu(adreno_dev); 4364: if (ret) 4365: goto done; 4366: 4367: gen8_hwsched_raise_dispatch_interrupt(adreno_dev); 4368: 4369: if (ctx_guilty) { 4370: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 4371: 4372: ret = handle_hw_fences_after_soft_reset(adreno_dev, drawctxt); 4373: if (ret) 4374: goto done; 4375: 4376: ret = send_context_unregister_hfi(adreno_dev, context, 4377: drawctxt->internal_timestamp); 4378: if (ret) 4379: goto done; 4380: 4381: kgsl_sharedmem_writel(device->memstore, 4382: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 4383: drawctxt->timestamp); 4384: 4385: kgsl_sharedmem_writel(device->memstore, 4386: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 4387: drawctxt->timestamp); 4388: 4389: adreno_profile_process_results(adreno_dev); 4390: 4391: context->gmu_registered = false; --- FILE: \adreno_gen8_hwsched_hfi.h | HITS: 1 --- MATCH LINES: 95 83: 84: /* H2F */ 85: struct hfi_thermaltable_cmd { 86: /** @hdr: HFI header message */ 87: u32 hdr; 88: /** @version: Version identifier for the format used for domains */ 89: u32 version; 90: /** @ctrl: Thermal profile control information */ 91: struct hfi_therm_profile_ctrl ctrl; 92: } __packed; 93: 94: struct gen8_hwsched_hfi { 95: /** @irq_mask: Store the hfi interrupt mask */ 96: u32 irq_mask; 97: /** @msglock: To protect the list of un-ACKed hfi packets */ 98: rwlock_t msglock; 99: /** @msglist: List of un-ACKed hfi packets */ 100: struct list_head msglist; 101: /** @f2h_task: Task for processing gmu fw to host packets */ 102: struct task_struct *f2h_task; 103: /** @f2h_wq: Waitqueue for the f2h_task */ 104: wait_queue_head_t f2h_wq; 105: /** @big_ib: GMU buffer to hold big IBs */ 106: struct kgsl_memdesc *big_ib; 107: /** @big_ib_recurring: GMU buffer to hold big recurring IBs */ 108: struct kgsl_memdesc *big_ib_recurring; 109: /** @msg_mutex: Mutex for accessing the msgq */ 110: struct mutex msgq_mutex; 111: /** 112: * @hw_fence_timer: Timer to trigger fault if unack'd hardware fence count does'nt drop 113: * to a desired threshold in given amount of time 114: */ 115: struct timer_list hw_fence_timer; 116: /** 117: * @hw_fence_ws: Work struct that gets scheduled when hw_fence_timer expires 118: */ 119: struct work_struct hw_fence_ws; --- FILE: \adreno_gen8_perfcounter.c | HITS: 1 --- MATCH LINES: 31 19: /* 20: * Flush delta counters (both perf counters and pipe stats) present in 21: * RBBM_S and RBBM_US to perf RAM logic to get the latest data. 22: */ 23: kgsl_regwrite(device, GEN8_RBBM_PERFCTR_FLUSH_HOST_CMD, BIT(0)); 24: kgsl_regwrite(device, GEN8_RBBM_SLICE_PERFCTR_FLUSH_HOST_CMD, BIT(0)); 25: 26: /* Ensure all writes are posted before polling status register */ 27: wmb(); 28: 29: /* 30: * Poll RBBM_PERFCTR_FLUSH_HOST_STATUS to wait for perfcounter flush completion. 31: * Use a busy loop as this is called with interrupts and preemption disabled. 32: */ 33: for (i = 0; i < 10; i++) { 34: kgsl_regread(device, GEN8_RBBM_PERFCTR_FLUSH_HOST_STATUS, &status); 35: if (((status & PERFCOUNTER_FLUSH_DONE_MASK) == PERFCOUNTER_FLUSH_DONE_MASK)) 36: return; 37: 38: udelay(10); 39: } 40: 41: /* Check status one last time */ 42: kgsl_regread(device, GEN8_RBBM_PERFCTR_FLUSH_HOST_STATUS, &status); 43: 44: if ((status & PERFCOUNTER_FLUSH_DONE_MASK) != PERFCOUNTER_FLUSH_DONE_MASK) 45: dev_err_ratelimited(device->dev, 46: "Perfcounter flush timed out: status=0x%08x\n", status); 47: } 48: 49: static int gen8_counter_br_enable(struct adreno_device *adreno_dev, 50: const struct adreno_perfcount_group *group, 51: u32 counter, u32 countable) 52: { 53: struct adreno_perfcount_register *reg = &group->regs[counter]; 54: int ret; 55: --- FILE: \adreno_gen8_preempt.c | HITS: 4 --- MATCH LINES: 309 297: GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_LO, 298: lower_32_bits(next->preemption_desc->gpuaddr), 299: FENCE_STATUS_WRITEDROPPED1_MASK)) 300: goto err; 301: 302: /* 303: * Above fence writes will make sure GMU comes out of 304: * IFPC state if its was in IFPC state but it doesn't 305: * guarantee that GMU FW actually moved to ACTIVE state 306: * i.e. wake-up from IFPC is complete. 307: * Wait for GMU to move to ACTIVE state before triggering 308: * preemption. This is require to make sure CP doesn't 309: * interrupt GMU during wake-up from IFPC. 310: */ 311: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 312: goto err; 313: 314: if (gen8_fenced_write(adreno_dev, 315: GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_HI, 316: upper_32_bits(next->preemption_desc->gpuaddr), 317: FENCE_STATUS_WRITEDROPPED1_MASK)) 318: goto err; 319: 320: if (kgsl_mmu_is_secured(&device->mmu)) { 321: if (gen8_fenced_write(adreno_dev, 322: GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_LO, 323: lower_32_bits(next->secure_preemption_desc->gpuaddr), 324: FENCE_STATUS_WRITEDROPPED1_MASK)) 325: goto err; 326: 327: if (gen8_fenced_write(adreno_dev, 328: GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_HI, 329: upper_32_bits(next->secure_preemption_desc->gpuaddr), 330: FENCE_STATUS_WRITEDROPPED1_MASK)) 331: goto err; 332: } 333: MATCH LINES: 383, 409, 414 371: 372: /* Trigger the preemption */ 373: if (gen8_fenced_write(adreno_dev, GEN8_CP_CONTEXT_SWITCH_CNTL, cntl, 374: FENCE_STATUS_WRITEDROPPED1_MASK)) { 375: adreno_dev->next_rb = NULL; 376: kgsl_delete_timer(&adreno_dev->preempt.timer); 377: goto err; 378: } 379: 380: return; 381: err: 382: /* If fenced write fails, take inline snapshot and trigger recovery */ 383: if (!in_interrupt()) { 384: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 385: adreno_scheduler_fault(adreno_dev, 386: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 387: } else { 388: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 389: } 390: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 391: /* Clear the keep alive */ 392: _power_collapse_set(adreno_dev, false); 393: 394: } 395: 396: void gen8_preemption_callback(struct adreno_device *adreno_dev, int bit) 397: { 398: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 399: u32 status; 400: 401: if (!adreno_move_preempt_state(adreno_dev, 402: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 403: return; 404: 405: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_CNTL, &status); 406: 407: if (status & 0x1) { 408: dev_err(KGSL_DEVICE(adreno_dev)->dev, 409: "preempt interrupt with non-zero status: %X\n", 410: status); 411: 412: /* 413: * Under the assumption that this is a race between the 414: * interrupt and the register, schedule the worker to clean up. 415: * If the status still hasn't resolved itself by the time we get 416: * there then we have to assume something bad happened 417: */ 418: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE); 419: adreno_scheduler_queue(adreno_dev); 420: return; 421: } 422: 423: adreno_dev->preempt.count++; 424: 425: /* 426: * We can now safely clear the preemption keepalive bit, allowing 427: * power collapse to resume its regular activity. 428: */ 429: _power_collapse_set(adreno_dev, false); 430: 431: kgsl_delete_timer(&adreno_dev->preempt.timer); 432: 433: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status); 434: 435: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 436: status, 0); 437: 438: adreno_dev->prev_rb = adreno_dev->cur_rb; --- FILE: \adreno_hfi.h | HITS: 4 --- MATCH LINES: 1333 1321: 1322: /* Keys for PAYLOAD_PREEMPT_TIMEOUT type payload */ 1323: #define KEY_PREEMPT_TIMEOUT_CUR_RB_ID 1 1324: #define KEY_PREEMPT_TIMEOUT_NEXT_RB_ID 2 1325: 1326: /* Keys for PAYLOAD_FAULT_RESET_POLICY type payload */ 1327: #define KEY_GPU_RESET_POLICY 1 1328: 1329: /* Types of errors that trigger context bad HFI */ 1330: 1331: /* GPU encountered a CP HW error */ 1332: #define GMU_CP_HW_ERROR 600 1333: /* GPU encountered a GPU Hang interrupt */ 1334: #define GMU_GPU_HW_HANG 601 1335: /* Preemption didn't complete in given time */ 1336: #define GMU_GPU_PREEMPT_TIMEOUT 602 1337: /* Fault due to Long IB timeout */ 1338: #define GMU_GPU_SW_HANG 603 1339: /* GPU encountered a bad opcode */ 1340: #define GMU_CP_OPCODE_ERROR 604 1341: /* GPU encountered protected mode error */ 1342: #define GMU_CP_PROTECTED_ERROR 605 1343: /* GPU encountered an illegal instruction */ 1344: #define GMU_CP_ILLEGAL_INST_ERROR 606 1345: /* GPU encountered a CP ucode error */ 1346: #define GMU_CP_UCODE_ERROR 607 1347: /* GPU encountered a CP hw fault error */ 1348: #define GMU_CP_HW_FAULT_ERROR 608 1349: /* GPU encountered a GPC error */ 1350: #define GMU_CP_GPC_ERROR 609 1351: /* GPU BV encountered a bad opcode */ 1352: #define GMU_CP_BV_OPCODE_ERROR 610 1353: /* GPU BV encountered protected mode error */ 1354: #define GMU_CP_BV_PROTECTED_ERROR 611 1355: /* GPU BV encountered a CP hw fault error */ 1356: #define GMU_CP_BV_HW_FAULT_ERROR 612 1357: /* GPU BV encountered a CP ucode error */ MATCH LINES: 1373 1361: /* GPU encountered a bad LPAC opcode */ 1362: #define GMU_CP_LPAC_OPCODE_ERROR 615 1363: /* GPU LPAC encountered a CP ucode error */ 1364: #define GMU_CP_LPAC_UCODE_ERROR 616 1365: /* GPU LPAC encountered a CP hw fault error */ 1366: #define GMU_CP_LPAC_HW_FAULT_ERROR 617 1367: /* GPU LPAC encountered protected mode error */ 1368: #define GMU_CP_LPAC_PROTECTED_ERROR 618 1369: /* GPU LPAC encountered an illegal instruction */ 1370: #define GMU_CP_LPAC_ILLEGAL_INST_ERROR 619 1371: /* Fault due to LPAC Long IB timeout */ 1372: #define GMU_GPU_LPAC_SW_HANG 620 1373: /* Fault due to software fuse violation interrupt */ 1374: #define GMU_GPU_SW_FUSE_VIOLATION 621 1375: /* AQE related error codes */ 1376: #define GMU_GPU_AQE0_OPCODE_ERROR 622 1377: #define GMU_GPU_AQE0_UCODE_ERROR 623 1378: #define GMU_GPU_AQE0_HW_FAULT_ERROR 624 1379: #define GMU_GPU_AQE0_ILLEGAL_INST_ERROR 625 1380: #define GMU_GPU_AQE1_OPCODE_ERROR 626 1381: #define GMU_GPU_AQE1_UCODE_ERROR 627 1382: #define GMU_GPU_AQE1_HW_FAULT_ERROR 628 1383: #define GMU_GPU_AQE1_ILLEGAL_INST_ERROR 629 1384: /* GMU encountered a sync object which is signaled via software but not via hardware */ 1385: #define GMU_SYNCOBJ_TIMEOUT_ERROR 630 1386: #define GMU_CP_DDEBR_HW_FAULT_ERROR 631 1387: #define GMU_CP_DDEBR_OPCODE_ERROR 632 1388: #define GMU_CP_DDEBR_UCODE_ERROR 633 1389: #define GMU_CP_DDEBR_PROTECTED_ERROR 634 1390: #define GMU_CP_DDEBR_ILLEGAL_INST_ERROR 635 1391: #define GMU_CP_DDEBV_HW_FAULT_ERROR 636 1392: #define GMU_CP_DDEBV_OPCODE_ERROR 637 1393: #define GMU_CP_DDEBV_UCODE_ERROR 638 1394: #define GMU_CP_DDEBV_PROTECTED_ERROR 639 1395: #define GMU_CP_DDEBV_ILLEGAL_INST_ERROR 640 1396: #define GMU_CP_BR_SW_FAULT_ERROR 641 1397: #define GMU_CP_BV_SW_FAULT_ERROR 642 MATCH LINES: 1412 1400: #define GMU_CP_AQE1_SW_FAULT_ERROR 645 1401: #define GMU_CP_AQE0_PROTECTED_ERROR 646 1402: #define GMU_CP_AQE1_PROTECTED_ERROR 647 1403: #define GMU_CP_DDEBR_SW_FAULT_ERROR 648 1404: #define GMU_CP_DDEBV_SW_FAULT_ERROR 649 1405: /* Non fatal GPU error codes */ 1406: #define GMU_CP_AHB_ERROR 650 1407: #define GMU_ATB_ASYNC_FIFO_OVERFLOW 651 1408: #define GMU_RBBM_ATB_BUF_OVERFLOW 652 1409: #define GMU_UCHE_OOB_ACCESS 653 1410: #define GMU_UCHE_TRAP_INTR 654 1411: #define GMU_TSB_WRITE_ERROR 655 1412: /* DBGC interrupt */ 1413: #define GMU_DBGC_INTR_ERROR 656 1414: 1415: /* GPU encountered an unknown CP error */ 1416: #define GMU_CP_UNKNOWN_ERROR 700 1417: 1418: #define GPU_DCVS_TUNING_INVALID_VALUE 0xffffffff 1419: #define GPU_DCVS_TUNING_INVALID_ACK_DATA 0xfffffffe 1420: 1421: /** 1422: * Keep this enum in sync with dcvs_tunables_strings[]. Each index in this enum must correspond 1423: * to the matching string entry. 1424: */ 1425: enum gpu_tuning_attr { 1426: GPU_TUNING_KEY_BUSY_PENALTY_UP = 0, 1427: GPU_TUNING_KEY_BUSY_PENALTY_DOWN = 1, 1428: GPU_TUNING_KEY_FIRST_STEP_DOWN_COUNT = 2, 1429: GPU_TUNING_KEY_SUBSEQUENT_STEP_DOWN_COUNT = 3, 1430: GPU_TUNING_KEY_MIN_GPU_FREQUENCY = 4, 1431: GPU_TUNING_KEY_MAX_GPU_FREQUENCY = 5, 1432: GPU_TUNING_KEY_TARGET_FPS = 6, 1433: GPU_TUNING_KEY_NUM_SAMPLES_UP = 7, 1434: GPU_TUNING_KEY_NUM_SAMPLES_DOWN = 8, 1435: GPU_TUNING_KEY_STRICT_FRAME = 9, 1436: GPU_TUNING_KEY_NON_LINEAR_RAMP_UP = 10, MATCH LINES: 1500 1488: static inline void hfi_update_write_idx(volatile u32 *write_idx, u32 index) 1489: { 1490: /* 1491: * This is to make sure packets are written out before gmu sees the 1492: * updated write index 1493: */ 1494: wmb(); 1495: 1496: *write_idx = index; 1497: 1498: /* 1499: * Memory barrier to make sure write index is written before an 1500: * interrupt is raised 1501: */ 1502: wmb(); 1503: } 1504: 1505: /** 1506: * hfi_get_mem_alloc_desc - Get the descriptor from F2H_MSG_MEM_ALLOC packet 1507: * rcvd: Pointer to the F2H_MSG_MEM_ALLOC packet 1508: * out: Pointer to copy the descriptor data to 1509: * 1510: * This function checks for the F2H_MSG_MEM_ALLOC packet version and based on that gets the 1511: * descriptor data from the packet. 1512: */ 1513: static inline void hfi_get_mem_alloc_desc(void *rcvd, struct hfi_mem_alloc_desc *out) 1514: { 1515: struct hfi_mem_alloc_cmd_legacy *in_legacy = (struct hfi_mem_alloc_cmd_legacy *)rcvd; 1516: struct hfi_mem_alloc_cmd *in = (struct hfi_mem_alloc_cmd *)rcvd; 1517: 1518: if (in->version > 0) 1519: memcpy(out, &in->desc, sizeof(in->desc)); 1520: else 1521: memcpy(out, &in_legacy->desc, sizeof(in_legacy->desc)); 1522: } 1523: 1524: /** --- FILE: \adreno_hwsched.c | HITS: 7 --- MATCH LINES: 1203 1191: int ret = 0; 1192: 1193: /* 1194: * There is always a possibility that dispatcher may end up pushing 1195: * the last popped draw object back to the context drawqueue. Hence, 1196: * we can only queue up to _context_drawqueue_size - 1 here to make 1197: * sure we never let drawqueue->queued exceed _context_drawqueue_size. 1198: */ 1199: if ((drawctxt->queued + count) > (_context_drawqueue_size - 1)) { 1200: trace_adreno_drawctxt_sleep(drawctxt); 1201: spin_unlock(&drawctxt->lock); 1202: 1203: ret = wait_event_interruptible_timeout(drawctxt->wq, 1204: _check_context_queue(drawctxt, count), 1205: msecs_to_jiffies(_context_queue_wait)); 1206: 1207: spin_lock(&drawctxt->lock); 1208: trace_adreno_drawctxt_wake(drawctxt); 1209: 1210: /* 1211: * Account for the possibility that the context got invalidated 1212: * while we were sleeping 1213: */ 1214: if (ret > 0) 1215: ret = kgsl_check_context_state(&drawctxt->base); 1216: else if (ret == 0) 1217: ret = -ETIMEDOUT; 1218: } 1219: 1220: return ret; 1221: } 1222: 1223: static unsigned int _check_context_state_to_queue_cmds( 1224: struct adreno_context *drawctxt, u32 count) 1225: { 1226: int ret = kgsl_check_context_state(&drawctxt->base); 1227: MATCH LINES: 2838 2826: */ 2827: if (rc) { 2828: /* 2829: * If an ack goes unprocessed, keep track of processed and unprocessed acks 2830: * because we may not log each unprocessed ack due to ratelimiting 2831: */ 2832: if (unprocessed) 2833: processed++; 2834: return 0; 2835: } 2836: 2837: /* 2838: * It is possible the ack came, but due to HLOS latencies in processing hfi interrupt 2839: * and/or the f2h daemon, the ack isn't processed yet. Hence, process the msgq one last 2840: * time. 2841: */ 2842: process_msgq(adreno_dev); 2843: end = gpudev->read_alwayson(adreno_dev); 2844: if (completion_done(&ack->complete)) { 2845: unprocessed++; 2846: if (__ratelimit(&_rs)) 2847: dev_err(dev, "Ack unprocessed for id:%d sequence=%d count=%d/%d ticks=0x%llx/0x%llx\n", 2848: MSG_HDR_GET_ID(ack->sent_hdr), MSG_HDR_GET_SEQNUM(ack->sent_hdr), 2849: unprocessed, processed, start, end); 2850: return 0; 2851: } 2852: 2853: dev_err(dev, "Ack timeout for id:%d sequence=%d ticks=0x%llx/0x%llx\n", 2854: MSG_HDR_GET_ID(ack->sent_hdr), MSG_HDR_GET_SEQNUM(ack->sent_hdr), start, end); 2855: gmu_core_fault_snapshot(KGSL_DEVICE(adreno_dev), GMU_FAULT_WAIT_ACK_COMPLETION); 2856: return -ETIMEDOUT; 2857: } 2858: 2859: int adreno_hwsched_ctxt_unregister_wait_completion( 2860: struct adreno_device *adreno_dev, 2861: struct device *dev, struct kgsl_context *context, struct pending_cmd *ack, 2862: void (*process_msgq)(struct adreno_device *adreno_dev), MATCH LINES: 2884 2872: char prefix[60]; 2873: 2874: start = gpudev->read_alwayson(adreno_dev); 2875: kgsl_mutex_unlock(&device->mutex); 2876: 2877: ret = wait_for_completion_timeout(&ack->complete, msecs_to_jiffies(30 * 1000)); 2878: 2879: kgsl_mutex_lock(&device->mutex); 2880: if (ret) 2881: return 0; 2882: 2883: /* 2884: * It is possible the ack came, but due to HLOS latencies in processing hfi interrupt 2885: * and/or the f2h daemon, the ack isn't processed yet. Hence, process the msgq one last 2886: * time. 2887: */ 2888: process_msgq(adreno_dev); 2889: end = gpudev->read_alwayson(adreno_dev); 2890: 2891: if (completion_done(&ack->complete)) { 2892: snprintf(prefix, sizeof(prefix), 2893: "Ack unprocessed for %scontext unregister", fast ? "fast " : ""); 2894: dev_err_ratelimited(dev, 2895: "%s type: %s rb: %d seq: %d ctx: %u ts: %u ticks=0x%llx/0x%llx\n", 2896: prefix, kgsl_context_type(drawctxt->type), rb, 2897: MSG_HDR_GET_SEQNUM(ack->sent_hdr), cmd->ctxt_id, cmd->ts, start, end); 2898: return 0; 2899: } 2900: 2901: snprintf(prefix, sizeof(prefix), 2902: "Ack timeout for %scontext unregister", fast ? "fast " : ""); 2903: dev_err_ratelimited(dev, 2904: "%s type: %s rb: %d seq: %d ctx: %u ts: %u ticks=0x%llx/0x%llx\n", 2905: prefix, kgsl_context_type(drawctxt->type), rb, 2906: MSG_HDR_GET_SEQNUM(ack->sent_hdr), cmd->ctxt_id, cmd->ts, start, end); 2907: return -ETIMEDOUT; 2908: } MATCH LINES: 3080, 3087 3068: break; 3069: } 3070: case GMU_ATB_ASYNC_FIFO_OVERFLOW: 3071: dev_crit_ratelimited(dev, "RBBM: ATB ASYNC overflow\n"); 3072: break; 3073: case GMU_RBBM_ATB_BUF_OVERFLOW: 3074: dev_crit_ratelimited(dev, "RBBM: ATB bus overflow\n"); 3075: break; 3076: case GMU_UCHE_OOB_ACCESS: 3077: dev_crit_ratelimited(dev, "UCHE: Out of bounds access\n"); 3078: break; 3079: case GMU_UCHE_TRAP_INTR: 3080: dev_crit_ratelimited(dev, "UCHE: Trap interrupt\n"); 3081: break; 3082: case GMU_TSB_WRITE_ERROR: { 3083: u32 addr[2]; 3084: 3085: adreno_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS, 3086: KEY_TSB_WRITE_ERROR, addr, 2); 3087: dev_crit_ratelimited(dev, "TSB: Write error interrupt: Address: 0x%lx MID: %lu\n", 3088: FIELD_GET(GENMASK(16, 0), addr[1]) << 32 | addr[0], 3089: FIELD_GET(GENMASK(31, 23), addr[1])); 3090: break; 3091: } 3092: default: 3093: non_fatal = false; 3094: break; 3095: } 3096: 3097: return non_fatal; 3098: } 3099: 3100: int adreno_hwsched_poll_msg_queue_write_index(struct kgsl_memdesc *hfi_mem) 3101: { 3102: struct hfi_queue_table *tbl = hfi_mem->hostptr; 3103: struct hfi_queue_header *hdr = &tbl->qhdr[HFI_MSG_ID]; 3104: unsigned long timeout = jiffies + msecs_to_jiffies(HFI_RSP_TIMEOUT); 3105: 3106: while (time_before(jiffies, timeout)) { 3107: if (hdr->write_index != hdr->read_index) 3108: goto done; 3109: 3110: /* Wait for up to 100 us before trying again */ 3111: usleep_range((POLL_SLEEP_US >> 2) + 1, POLL_SLEEP_US); MATCH LINES: 3169, 3170 3157: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3158: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 3159: 3160: if (!time) 3161: return; 3162: 3163: /* 3164: * Here we are attempting to create a mapping between the 3165: * GPU time domain (alwayson counter) and the CPU time domain 3166: * (local_clock) by sampling both values as close together as 3167: * possible. This is useful for many types of debugging and 3168: * profiling. In order to make this mapping as accurate as 3169: * possible, we must turn off interrupts to avoid running 3170: * interrupt handlers between the two samples. 3171: */ 3172: 3173: local_irq_save(flags); 3174: 3175: /* Read always on registers */ 3176: time->ticks = gpudev->read_alwayson(adreno_dev); 3177: 3178: /* Trace the GPU time to create a mapping to ftrace time */ 3179: trace_adreno_cmdbatch_sync(context->id, context->priority, 3180: drawobj->timestamp, time->ticks); 3181: 3182: /* Get the kernel clock for time since boot */ 3183: time->ktime = local_clock(); 3184: 3185: /* Get the timeofday for the wall time (for the user) */ 3186: ktime_get_real_ts64(&time->utime); 3187: 3188: local_irq_restore(flags); 3189: 3190: /* Return kernel clock time to the client if requested */ 3191: time_in_s = time->ktime; 3192: time_in_ns = do_div(time_in_s, 1000000000); 3193: 3194: info.inflight = hwsched->inflight; --- FILE: \adreno_pm4types.h | HITS: 2 --- MATCH LINES: 20, 21 8: 9: #include "adreno.h" 10: 11: #define CP_TYPE4_PKT (4 << 28) 12: #define CP_TYPE7_PKT (7 << 28) 13: 14: #define PM4_TYPE4_PKT_SIZE_MAX 128 15: 16: /* Enable preemption flag */ 17: #define CP_PREEMPT_ENABLE 0x1C 18: /* Preemption token command on which preemption occurs */ 19: #define CP_PREEMPT_TOKEN 0x1E 20: /* Bit to set in CP_PREEMPT_TOKEN ordinal for interrupt on preemption */ 21: #define CP_PREEMPT_ORDINAL_INTERRUPT 24 22: 23: /* Wait for memory writes to complete */ 24: #define CP_WAIT_MEM_WRITES 0x12 25: 26: /* initialize CP's micro-engine */ 27: #define CP_ME_INIT 0x48 28: 29: /* skip N 32-bit words to get to the next packet */ 30: #define CP_NOP 0x10 31: 32: /* indirect buffer dispatch. same as IB, but init is pipelined */ 33: #define CP_INDIRECT_BUFFER_PFD 0x37 34: 35: /* wait for the IDLE state of the engine */ 36: #define CP_WAIT_FOR_IDLE 0x26 37: 38: /* wait until a register or memory location is a specific value */ 39: #define CP_WAIT_REG_MEM 0x3c 40: 41: /* wait until a register location is equal to a specific value */ 42: #define CP_WAIT_REG_EQ 0x52 43: 44: /* switches SMMU pagetable, used on a5xx only */ 45: #define CP_SMMU_TABLE_UPDATE 0x53 --- FILE: \adreno_profile.c | HITS: 1 --- MATCH LINES: 934 922: /* there are no unread results, act accordingly */ 923: if (filep->f_flags & O_NONBLOCK) { 924: if (profile->shared_tail != profile->shared_head) { 925: status = _pipe_print_pending(usr_buf, max); 926: break; 927: } 928: 929: status = 0; 930: break; 931: } 932: 933: kgsl_mutex_unlock(&device->mutex); 934: set_current_state(TASK_INTERRUPTIBLE); 935: schedule_timeout(msecs_to_jiffies(100)); 936: kgsl_mutex_lock(&device->mutex); 937: 938: if (signal_pending(current)) { 939: status = 0; 940: break; 941: } 942: } 943: 944: kgsl_mutex_unlock(&device->mutex); 945: 946: return status; 947: } 948: 949: static int profile_groups_show(struct seq_file *s, void *unused) 950: { 951: struct kgsl_device *device = (struct kgsl_device *) s->private; 952: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 953: const struct adreno_perfcounters *counters = 954: ADRENO_PERFCOUNTERS(adreno_dev); 955: const struct adreno_perfcount_group *group; 956: int i, j, used; 957: 958: kgsl_mutex_lock(&device->mutex); --- FILE: \adreno_ringbuffer.c | HITS: 3 --- MATCH LINES: 45, 46 33: struct adreno_context *drawctxt = rb->drawctxt_active; 34: struct kgsl_context *context = &drawctxt->base; 35: 36: if (!time) 37: return; 38: 39: /* 40: * Here we are attempting to create a mapping between the 41: * GPU time domain (alwayson counter) and the CPU time domain 42: * (local_clock) by sampling both values as close together as 43: * possible. This is useful for many types of debugging and 44: * profiling. In order to make this mapping as accurate as 45: * possible, we must turn off interrupts to avoid running 46: * interrupt handlers between the two samples. 47: */ 48: 49: local_irq_save(flags); 50: 51: time->ticks = gpudev->read_alwayson(adreno_dev); 52: 53: /* Trace the GPU time to create a mapping to ftrace time */ 54: trace_adreno_cmdbatch_sync(context->id, context->priority, 55: drawctxt->timestamp, time->ticks); 56: 57: /* Get the kernel clock for time since boot */ 58: time->ktime = local_clock(); 59: 60: /* Get the timeofday for the wall time (for the user) */ 61: ktime_get_real_ts64(&time->utime); 62: 63: local_irq_restore(flags); 64: } 65: 66: unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb, 67: unsigned int dwords) 68: { 69: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 70: unsigned int rptr = adreno_get_rptr(rb); MATCH LINES: 308 296: /* 297: * When preamble is enabled, the preamble buffer with state restoration 298: * commands are stored in the first node of the IB chain. 299: * We can skip that if a context switch hasn't occurred. 300: */ 301: if ((drawctxt->base.flags & KGSL_CONTEXT_PREAMBLE) && 302: !test_bit(CMDOBJ_FORCE_PREAMBLE, &cmdobj->priv) && 303: (rb->drawctxt_active == drawctxt)) 304: flags &= ~F_PREAMBLE; 305: 306: /* 307: * In skip mode don't issue the draw IBs but keep all the other 308: * accoutrements of a submision (including the interrupt) to keep 309: * the accounting sane. Set start_index and numibs to 0 to just 310: * generate the start and end markers and skip everything else 311: */ 312: if (test_bit(CMDOBJ_SKIP, &cmdobj->priv)) { 313: flags &= ~F_PREAMBLE; 314: flags |= F_SKIP; 315: } 316: 317: /* Enable kernel profiling */ 318: if (test_bit(CMDOBJ_PROFILE, &cmdobj->priv)) 319: flags |= F_KERNEL_PROFILE; 320: 321: /* Add a WFI to the end of the submission */ 322: if (test_bit(CMDOBJ_WFI, &cmdobj->priv)) 323: flags |= F_WFI; 324: 325: /* 326: * For some targets, we need to execute a dummy shader operation after a 327: * power collapse 328: */ 329: if (test_and_clear_bit(ADRENO_DEVICE_PWRON, &adreno_dev->priv) && 330: test_bit(ADRENO_DEVICE_PWRON_FIXUP, &adreno_dev->priv)) 331: flags |= F_PWRON_FIXUP; 332: --- FILE: \adreno_sysfs.c | HITS: 1 --- MATCH LINES: 340 328: if (!IS_ERR_OR_NULL(adreno_dev->gpumv_llc_slice)) 329: adreno_dev->gpumv_llc_slice_enable = val; 330: return 0; 331: } 332: 333: static bool _gpumv_llc_slice_enable_show(struct adreno_device *adreno_dev) 334: { 335: return adreno_dev->gpumv_llc_slice_enable; 336: } 337: 338: static bool _ft_hang_intr_status_show(struct adreno_device *adreno_dev) 339: { 340: /* Hang interrupt is always on on all targets */ 341: return true; 342: } 343: 344: static int _hwcg_store(struct adreno_device *adreno_dev, bool val) 345: { 346: if (adreno_dev->hwcg_enabled == val) 347: return 0; 348: 349: /* UCHE_GBIF_GX_CONFIG register requires update of reglist */ 350: if (!adreno_is_gen8(adreno_dev) && !adreno_is_gen7_9_x(adreno_dev)) 351: adreno_dev->patch_reglist = false; 352: 353: return adreno_power_cycle_bool(adreno_dev, &adreno_dev->hwcg_enabled, 354: val); 355: } 356: 357: static bool _hwcg_show(struct adreno_device *adreno_dev) 358: { 359: return adreno_dev->hwcg_enabled; 360: } 361: 362: static int _throttling_store(struct adreno_device *adreno_dev, bool val) 363: { 364: if (!adreno_is_a540(adreno_dev) || --- FILE: \adreno_trace.h | HITS: 24 --- MATCH LINES: 699, 707, 708, 709, 715, 716, 719, 720, 721, 722, 723, 724 687: 688: TP_printk( 689: "d_name=%s status=%s", 690: __get_str(device_name), 691: __entry->status ? __print_flags(__entry->status, "|", 692: { BIT(GEN7_INT_GPUIDLE), "GPUIDLE" }, 693: { BIT(GEN7_INT_AHBERROR), "AHBERROR" }, 694: { BIT(GEN7_INT_CPIPCINT0), "CPIPCINT0" }, 695: { BIT(GEN7_INT_CPIPCINT1), "CPIPCINT1" }, 696: { BIT(GEN7_INT_ATBASYNCFIFOOVERFLOW), 697: "ATBASYNCFIFOOVERFLOW" }, 698: { BIT(GEN7_INT_GPCERROR), "GPCERROR" }, 699: { BIT(GEN7_INT_SWINTERRUPT), "SWINTERRUPT" }, 700: { BIT(GEN7_INT_HWERROR), "HWERROR" }, 701: { BIT(GEN7_INT_CCU_CLEAN_DEPTH_TS), 702: "CCU_CLEAN_DEPTH_TS" }, 703: { BIT(GEN7_INT_CCU_CLEAN_COLOR_TS), 704: "CCU_CLEAN_COLOR_TS" }, 705: { BIT(GEN7_INT_CCU_RESOLVE_CLEAN_TS), 706: "CCU_RESOLVE_CLEAN_TS" }, 707: { BIT(GEN7_INT_PM4CPINTERRUPT), "PM4CPINTERRUPT" }, 708: { BIT(GEN7_INT_PM4CPINTERRUPTLPAC), 709: "PM4CPINTERRUPTLPAC" }, 710: { BIT(GEN7_INT_RB_DONE_TS), "RB_DONE_TS" }, 711: { BIT(GEN7_INT_CACHE_CLEAN_TS), "CACHE_CLEAN_TS" }, 712: { BIT(GEN7_INT_CACHE_CLEAN_TS_LPAC), 713: "CACHE_CLEAN_TS_LPAC" }, 714: { BIT(GEN7_INT_ATBBUSOVERFLOW), "ATBBUSOVERFLOW" }, 715: { BIT(GEN7_INT_HANGDETECTINTERRUPT), 716: "HANGDETECTINTERRUPT" }, 717: { BIT(GEN7_INT_OUTOFBOUNDACCESS), 718: "OUTOFBOUNDACCESS" }, 719: { BIT(GEN7_INT_UCHETRAPINTERRUPT), 720: "UCHETRAPINTERRUPT" }, 721: { BIT(GEN7_INT_DEBUGBUSINTERRUPT0), 722: "DEBUGBUSINTERRUPT0" }, 723: { BIT(GEN7_INT_DEBUGBUSINTERRUPT1), 724: "DEBUGBUSINTERRUPT1" }, 725: { BIT(GEN7_INT_TSBWRITEERROR), "TSBWRITEERROR" }, 726: { BIT(GEN7_INT_SWFUSEVIOLATION), "SWFUSEVIOLATION" }, 727: { BIT(GEN7_INT_ISDBCPUIRQ), "ISDBCPUIRQ" }, 728: { BIT(GEN7_INT_ISDBUNDERDEBUG), "ISDBUNDERDEBUG" }, 729: { BIT(GEN7_INT_ISDBUNDERDEBUG), "ISDBUNDERDEBUG" }) 730: : "None" 731: ) 732: ); 733: 734: /* 735: * Tracepoint for gen8 irq. Includes status info 736: */ 737: TRACE_EVENT(kgsl_gen8_irq_status, 738: 739: TP_PROTO(struct adreno_device *adreno_dev, u32 status), 740: 741: TP_ARGS(adreno_dev, status), 742: 743: TP_STRUCT__entry( 744: __string(device_name, adreno_dev->dev.name) 745: __field(u32, status) 746: ), 747: 748: TP_fast_assign( MATCH LINES: 764, 772, 773, 774, 780, 781, 784, 785, 786, 787, 788, 789 752: 753: TP_printk( 754: "d_name=%s status=%s", 755: __get_str(device_name), 756: __entry->status ? __print_flags(__entry->status, "|", 757: { BIT(GEN8_INT_GPUIDLE), "GPUIDLE" }, 758: { BIT(GEN8_INT_AHBERROR), "AHBERROR" }, 759: { BIT(GEN8_INT_CPIPCINT0), "CPIPCINT0" }, 760: { BIT(GEN8_INT_CPIPCINT1), "CPIPCINT1" }, 761: { BIT(GEN8_INT_ATBASYNCFIFOOVERFLOW), 762: "ATBASYNCFIFOOVERFLOW" }, 763: { BIT(GEN8_INT_GPCERROR), "GPCERROR" }, 764: { BIT(GEN8_INT_SWINTERRUPT), "SWINTERRUPT" }, 765: { BIT(GEN8_INT_HWERROR), "HWERROR" }, 766: { BIT(GEN8_INT_CCU_CLEAN_DEPTH_TS), 767: "CCU_CLEAN_DEPTH_TS" }, 768: { BIT(GEN8_INT_CCU_CLEAN_COLOR_TS), 769: "CCU_CLEAN_COLOR_TS" }, 770: { BIT(GEN8_INT_CCU_RESOLVE_CLEAN_TS), 771: "CCU_RESOLVE_CLEAN_TS" }, 772: { BIT(GEN8_INT_PM4CPINTERRUPT), "PM4CPINTERRUPT" }, 773: { BIT(GEN8_INT_PM4CPINTERRUPTLPAC), 774: "PM4CPINTERRUPTLPAC" }, 775: { BIT(GEN8_INT_RB_DONE_TS), "RB_DONE_TS" }, 776: { BIT(GEN8_INT_CACHE_CLEAN_TS), "CACHE_CLEAN_TS" }, 777: { BIT(GEN8_INT_CACHE_CLEAN_TS_LPAC), 778: "CACHE_CLEAN_TS_LPAC" }, 779: { BIT(GEN8_INT_ATBBUSOVERFLOW), "ATBBUSOVERFLOW" }, 780: { BIT(GEN8_INT_HANGDETECTINTERRUPT), 781: "HANGDETECTINTERRUPT" }, 782: { BIT(GEN8_INT_OUTOFBOUNDACCESS), 783: "OUTOFBOUNDACCESS" }, 784: { BIT(GEN8_INT_UCHETRAPINTERRUPT), 785: "UCHETRAPINTERRUPT" }, 786: { BIT(GEN8_INT_DEBUGBUSINTERRUPT0), 787: "DEBUGBUSINTERRUPT0" }, 788: { BIT(GEN8_INT_DEBUGBUSINTERRUPT1), 789: "DEBUGBUSINTERRUPT1" }, 790: { BIT(GEN8_INT_TSBWRITEERROR), "TSBWRITEERROR" }, 791: { BIT(GEN8_INT_SWFUSEVIOLATION), "SWFUSEVIOLATION" }, 792: { BIT(GEN8_INT_ISDBCPUIRQ), "ISDBCPUIRQ" }, 793: { BIT(GEN8_INT_ISDBUNDERDEBUG), "ISDBUNDERDEBUG" }) 794: : "None" 795: ) 796: ); 797: 798: DECLARE_EVENT_CLASS(adreno_hw_preempt_template, 799: TP_PROTO(struct adreno_ringbuffer *cur_rb, 800: struct adreno_ringbuffer *new_rb, 801: unsigned int cur_rptr, unsigned int new_rptr), 802: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr), 803: TP_STRUCT__entry(__field(int, cur_level) 804: __field(int, new_level) 805: __field(unsigned int, cur_rptr) 806: __field(unsigned int, new_rptr) 807: __field(unsigned int, cur_wptr) 808: __field(unsigned int, new_wptr) 809: __field(unsigned int, cur_rbbase) 810: __field(unsigned int, new_rbbase) 811: ), 812: TP_fast_assign(__entry->cur_level = cur_rb->id; 813: __entry->new_level = new_rb->id; --- FILE: \gen7_reg.h | HITS: 15 --- MATCH LINES: 10, 17, 22, 23, 28, 30, 31, 32, 49 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #ifndef _GEN7_REG_H 8: #define _GEN7_REG_H 9: 10: /* GEN7 interrupt bits */ 11: #define GEN7_INT_GPUIDLE 0 12: #define GEN7_INT_AHBERROR 1 13: #define GEN7_INT_CPIPCINT0 4 14: #define GEN7_INT_CPIPCINT1 5 15: #define GEN7_INT_ATBASYNCFIFOOVERFLOW 6 16: #define GEN7_INT_GPCERROR 7 17: #define GEN7_INT_SWINTERRUPT 8 18: #define GEN7_INT_HWERROR 9 19: #define GEN7_INT_CCU_CLEAN_DEPTH_TS 10 20: #define GEN7_INT_CCU_CLEAN_COLOR_TS 11 21: #define GEN7_INT_CCU_RESOLVE_CLEAN_TS 12 22: #define GEN7_INT_PM4CPINTERRUPT 15 23: #define GEN7_INT_PM4CPINTERRUPTLPAC 16 24: #define GEN7_INT_RB_DONE_TS 17 25: #define GEN7_INT_CACHE_CLEAN_TS 20 26: #define GEN7_INT_CACHE_CLEAN_TS_LPAC 21 27: #define GEN7_INT_ATBBUSOVERFLOW 22 28: #define GEN7_INT_HANGDETECTINTERRUPT 23 29: #define GEN7_INT_OUTOFBOUNDACCESS 24 30: #define GEN7_INT_UCHETRAPINTERRUPT 25 31: #define GEN7_INT_DEBUGBUSINTERRUPT0 26 32: #define GEN7_INT_DEBUGBUSINTERRUPT1 27 33: #define GEN7_INT_TSBWRITEERROR 28 34: #define GEN7_INT_SWFUSEVIOLATION 29 35: #define GEN7_INT_ISDBCPUIRQ 30 36: #define GEN7_INT_ISDBUNDERDEBUG 31 37: 38: /* CP registers */ 39: #define GEN7_CP_RB_BASE 0x800 40: #define GEN7_CP_RB_BASE_HI 0x801 41: #define GEN7_CP_RB_CNTL 0x802 42: #define GEN7_CP_RB_RPTR_ADDR_LO 0x804 43: #define GEN7_CP_RB_RPTR_ADDR_HI 0x805 44: #define GEN7_CP_RB_RPTR 0x806 45: #define GEN7_CP_RB_WPTR 0x807 46: #define GEN7_CP_SQE_CNTL 0x808 47: #define GEN7_CP_CP2GMU_STATUS 0x812 48: #define GEN7_CP_HW_FAULT 0x821 49: #define GEN7_CP_INTERRUPT_STATUS 0x823 50: #define GEN7_CP_PROTECT_STATUS 0x824 51: #define GEN7_CP_STATUS_1 0x825 52: #define GEN7_CP_SQE_INSTR_BASE_LO 0x830 53: #define GEN7_CP_SQE_INSTR_BASE_HI 0x831 54: #define GEN7_CP_MISC_CNTL 0x840 55: #define GEN7_CP_CHICKEN_DBG 0x841 56: #define GEN7_CP_DBG_ECO_CNTL 0x843 57: #define GEN7_CP_APRIV_CNTL 0x844 58: #define GEN7_CP_SEMAPHORE_REG_0 0x846 59: #define GEN7_CP_PROTECT_CNTL 0x84f 60: #define GEN7_CP_PROTECT_REG 0x850 61: #define GEN7_CP_CONTEXT_SWITCH_CNTL 0x8a0 62: #define GEN7_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x8a1 63: #define GEN7_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x8a2 64: #define GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO 0x8a3 65: #define GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI 0x8a4 66: #define GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO 0x8a5 67: #define GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI 0x8a6 68: #define GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO 0x8a7 69: #define GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI 0x8a8 70: #define GEN7_CP_CONTEXT_SWITCH_LEVEL_STATUS 0x8ab 71: #define GEN7_CP_PERFCTR_CP_SEL_0 0x8d0 72: #define GEN7_CP_PERFCTR_CP_SEL_1 0x8d1 73: #define GEN7_CP_PERFCTR_CP_SEL_2 0x8d2 MATCH LINES: 201 189: #define GEN7_CP_PERIPH_IB1_SIZE(adreno_dev) (adreno_is_gen7_9_x(adreno_dev) ? 0x7007 : 0x7004) 190: #define GEN7_CP_PERIPH_IB1_OFFSET(adreno_dev) (adreno_is_gen7_9_x(adreno_dev) ? 0x7008 : 0x7005) 191: #define GEN7_CP_PERIPH_IB2_BASE_LO(adreno_dev) (adreno_is_gen7_9_x(adreno_dev) ? 0x7009 : 0x7006) 192: #define GEN7_CP_PERIPH_IB2_BASE_HI(adreno_dev) (adreno_is_gen7_9_x(adreno_dev) ? 0x700a : 0x7007) 193: #define GEN7_CP_PERIPH_IB2_SIZE(adreno_dev) (adreno_is_gen7_9_x(adreno_dev) ? 0x700b : 0x7008) 194: #define GEN7_CP_PERIPH_IB2_OFFSET(adreno_dev) (adreno_is_gen7_9_x(adreno_dev) ? 0x700c : 0x7009) 195: #define GEN7_CP_PERIPH_IB3_BASE_LO(adreno_dev) (adreno_is_gen7_9_x(adreno_dev) ? 0x700d : 0x700a) 196: #define GEN7_CP_PERIPH_IB3_BASE_HI(adreno_dev) (adreno_is_gen7_9_x(adreno_dev) ? 0x700e : 0x700b) 197: #define GEN7_CP_PERIPH_IB3_SIZE(adreno_dev) (adreno_is_gen7_9_x(adreno_dev) ? 0x700f : 0x700c) 198: #define GEN7_CP_PERIPH_IB3_OFFSET(adreno_dev) (adreno_is_gen7_9_x(adreno_dev) ? 0x7010 : 0x700d) 199: 200: /* RBBM registers */ 201: #define GEN7_RBBM_INT_0_STATUS 0x201 202: #define GEN7_RBBM_STATUS 0x210 203: #define GEN7_RBBM_STATUS3 0x213 204: #define GEN7_RBBM_PERFCTR_CP_0_LO 0x300 205: #define GEN7_RBBM_PERFCTR_CP_0_HI 0x301 206: #define GEN7_RBBM_PERFCTR_CP_1_LO 0x302 207: #define GEN7_RBBM_PERFCTR_CP_1_HI 0x303 208: #define GEN7_RBBM_PERFCTR_CP_2_LO 0x304 209: #define GEN7_RBBM_PERFCTR_CP_2_HI 0x305 210: #define GEN7_RBBM_PERFCTR_CP_3_LO 0x306 211: #define GEN7_RBBM_PERFCTR_CP_3_HI 0x307 212: #define GEN7_RBBM_PERFCTR_CP_4_LO 0x308 213: #define GEN7_RBBM_PERFCTR_CP_4_HI 0x309 214: #define GEN7_RBBM_PERFCTR_CP_5_LO 0x30a 215: #define GEN7_RBBM_PERFCTR_CP_5_HI 0x30b 216: #define GEN7_RBBM_PERFCTR_CP_6_LO 0x30c 217: #define GEN7_RBBM_PERFCTR_CP_6_HI 0x30d 218: #define GEN7_RBBM_PERFCTR_CP_7_LO 0x30e 219: #define GEN7_RBBM_PERFCTR_CP_7_HI 0x30f 220: #define GEN7_RBBM_PERFCTR_CP_8_LO 0x310 221: #define GEN7_RBBM_PERFCTR_CP_8_HI 0x311 222: #define GEN7_RBBM_PERFCTR_CP_9_LO 0x312 223: #define GEN7_RBBM_PERFCTR_CP_9_HI 0x313 224: #define GEN7_RBBM_PERFCTR_CP_10_LO 0x314 225: #define GEN7_RBBM_PERFCTR_CP_10_HI 0x315 MATCH LINES: 648 636: #define GEN7_RBBM_SECVID_TSB_TRUSTED_BASE_LO 0xf800 637: #define GEN7_RBBM_SECVID_TSB_TRUSTED_BASE_HI 0xf801 638: #define GEN7_RBBM_SECVID_TSB_TRUSTED_SIZE 0xf802 639: #define GEN7_RBBM_SECVID_TSB_CNTL 0xf803 640: #define GEN7_RBBM_SECVID_TSB_STATUS_LO 0xfc00 641: #define GEN7_RBBM_SECVID_TSB_STATUS_HI 0xfc01 642: 643: #define GEN7_RBBM_GBIF_CLIENT_QOS_CNTL 0x00011 644: #define GEN7_RBBM_GBIF_HALT 0x00016 645: #define GEN7_RBBM_GBIF_HALT_ACK 0x00017 646: #define GEN7_RBBM_INTERFACE_HANG_INT_CNTL 0x0001f 647: #define GEN7_RBBM_INT_CLEAR_CMD 0x00037 648: #define GEN7_RBBM_INT_0_MASK 0x00038 649: #define GEN7_RBBM_INT_2_MASK 0x0003a 650: #define GEN7_RBBM_SP_HYST_CNT 0x00042 651: #define GEN7_RBBM_SW_RESET_CMD 0x00043 652: #define GEN7_RBBM_RAC_THRESHOLD_CNT 0x00044 653: #define GEN7_RBBM_CLOCK_CNTL_GLOBAL 0x000ad 654: #define GEN7_RBBM_CLOCK_CNTL 0x000ae 655: #define GEN7_RBBM_CLOCK_CNTL_SP0 0x000b0 656: #define GEN7_RBBM_CLOCK_CNTL2_SP0 0x000b4 657: #define GEN7_RBBM_CLOCK_DELAY_SP0 0x000b8 658: #define GEN7_RBBM_CLOCK_HYST_SP0 0x000bc 659: #define GEN7_RBBM_CLOCK_CNTL_TP0 0x000c0 660: #define GEN7_RBBM_CLOCK_CNTL2_TP0 0x000c4 661: #define GEN7_RBBM_CLOCK_CNTL3_TP0 0x000c8 662: #define GEN7_RBBM_CLOCK_CNTL4_TP0 0x000cc 663: #define GEN7_RBBM_CLOCK_DELAY_TP0 0x000d0 664: #define GEN7_RBBM_CLOCK_DELAY2_TP0 0x000d4 665: #define GEN7_RBBM_CLOCK_DELAY3_TP0 0x000d8 666: #define GEN7_RBBM_CLOCK_DELAY4_TP0 0x000dc 667: #define GEN7_RBBM_CLOCK_HYST_TP0 0x000e0 668: #define GEN7_RBBM_CLOCK_HYST2_TP0 0x000e4 669: #define GEN7_RBBM_CLOCK_HYST3_TP0 0x000e8 670: #define GEN7_RBBM_CLOCK_HYST4_TP0 0x000ec 671: #define GEN7_RBBM_CLOCK_CNTL_RB0 0x000f0 672: #define GEN7_RBBM_CLOCK_CNTL2_RB0 0x000f4 MATCH LINES: 1248, 1249, 1250, 1251 1236: #define GEN7_GMU_GENERAL_10 0x1f9cf 1237: #define GEN7_GMU_GENERAL_11 0x1f9d0 1238: 1239: /* FAL10 veto register */ 1240: #define GEN7_GPU_GMU_CX_GMU_CX_FAL_INTF 0x1f8f0 1241: #define GEN7_GPU_GMU_CX_GMU_CX_FALNEXT_INTF 0x1f8f1 1242: 1243: /* CLX registers */ 1244: #define GEN7_GPU_GMU_CX_CBCAST_GENERIC_ID 0x20001 1245: #define GEN7_GPU_GMU_CX_PMIC_PAYLOAD 0x20003 1246: #define GEN7_GPU_GMU_CX_PMIC_PAYLOAD_1 0x20005 1247: 1248: #define GEN7_GMU_AO_INTERRUPT_EN 0x23b03 1249: #define GEN7_GMU_AO_HOST_INTERRUPT_CLR 0x23b04 1250: #define GEN7_GMU_AO_HOST_INTERRUPT_STATUS 0x23b05 1251: #define GEN7_GMU_AO_HOST_INTERRUPT_MASK 0x23b06 1252: #define GEN7_GPU_GMU_AO_GMU_CGC_MODE_CNTL 0x23b09 1253: #define GEN7_GPU_GMU_AO_GMU_CGC_DELAY_CNTL 0x23b0a 1254: #define GEN7_GPU_GMU_AO_GMU_CGC_HYST_CNTL 0x23b0b 1255: #define GEN7_GPU_GMU_AO_GPU_CX_BUSY_STATUS 0x23b0c 1256: #define GEN7_GPU_GMU_AO_GPU_CX_BUSY_STATUS2 0x23b0d 1257: #define GEN7_GPU_GMU_AO_GPU_CX_BUSY_MASK 0x23b0e 1258: #define GEN7_GMU_AO_AHB_FENCE_CTRL 0x23b10 1259: #define GEN7_GMU_AHB_FENCE_STATUS 0x23b13 1260: #define GEN7_GMU_AHB_FENCE_STATUS_CLR 0x23b14 1261: #define GEN7_GMU_RBBM_INT_UNMASKED_STATUS 0x23b15 1262: #define GEN7_GPU_GMU_AO_GPU_LPAC_BUSY_STATUS 0x23b30 1263: 1264: /* GMU RSC control registers */ 1265: #define GEN7_GMU_RSCC_CONTROL_REQ 0x23b07 1266: #define GEN7_GMU_RSCC_CONTROL_ACK 0x23b08 1267: 1268: /* FENCE control registers */ 1269: #define GEN7_GMU_AHB_FENCE_RANGE_0 0x23b11 1270: 1271: /* GMU countables */ 1272: #define GEN7_GMU_CM3_BUSY_CYCLES 0 1273: 1274: /* GPUCC registers */ 1275: #define GEN7_11_0_GPU_CC_CX_CFG_GDSCR 0x26424 --- FILE: \gen8_reg.h | HITS: 22 --- MATCH LINES: 10, 17, 22, 23, 28, 30, 31, 32, 55, 57 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #ifndef _GEN8_REG_H 8: #define _GEN8_REG_H 9: 10: /* GEN8 interrupt bits */ 11: #define GEN8_INT_GPUIDLE 0 12: #define GEN8_INT_AHBERROR 1 13: #define GEN8_INT_CPIPCINT0 4 14: #define GEN8_INT_CPIPCINT1 5 15: #define GEN8_INT_ATBASYNCFIFOOVERFLOW 6 16: #define GEN8_INT_GPCERROR 7 17: #define GEN8_INT_SWINTERRUPT 8 18: #define GEN8_INT_HWERROR 9 19: #define GEN8_INT_CCU_CLEAN_DEPTH_TS 10 20: #define GEN8_INT_CCU_CLEAN_COLOR_TS 11 21: #define GEN8_INT_CCU_RESOLVE_CLEAN_TS 12 22: #define GEN8_INT_PM4CPINTERRUPT 15 23: #define GEN8_INT_PM4CPINTERRUPTLPAC 16 24: #define GEN8_INT_RB_DONE_TS 17 25: #define GEN8_INT_CACHE_CLEAN_TS 20 26: #define GEN8_INT_CACHE_CLEAN_TS_LPAC 21 27: #define GEN8_INT_ATBBUSOVERFLOW 22 28: #define GEN8_INT_HANGDETECTINTERRUPT 23 29: #define GEN8_INT_OUTOFBOUNDACCESS 24 30: #define GEN8_INT_UCHETRAPINTERRUPT 25 31: #define GEN8_INT_DEBUGBUSINTERRUPT0 26 32: #define GEN8_INT_DEBUGBUSINTERRUPT1 27 33: #define GEN8_INT_TSBWRITEERROR 28 34: #define GEN8_INT_SWFUSEVIOLATION 29 35: #define GEN8_INT_ISDBCPUIRQ 30 36: #define GEN8_INT_ISDBUNDERDEBUG 31 37: 38: /* RBBM registers */ 39: #define GEN8_RBBM_GBIF_CLIENT_QOS_CNTL 0x008 40: #define GEN8_RBBM_GBIF_HALT 0x00a 41: #define GEN8_RBBM_GBIF_HALT_ACK 0x00b 42: #define GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL 0x010 43: #define GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2 0x011 44: #define GEN8_RBBM_STATUS 0x012 45: #define GEN8_RBBM_STATUS1 0x013 46: #define GEN8_RBBM_GFX_STATUS 0x015 47: #define GEN8_RBBM_GFX_STATUS1 0x016 48: #define GEN8_RBBM_LPAC_STATUS 0x018 49: #define GEN8_RBBM_GFX_BR_STATUS 0x01a 50: #define GEN8_RBBM_GFX_BV_STATUS 0x01c 51: #define GEN8_RBBM_ISDB_CNT 0x02d 52: #define GEN8_RBBM_SNAPSHOT_STATUS 0x02e 53: #define GEN8_RBBM_INTERFACE_HANG_INT_CNTL 0x02f 54: #define GEN8_RBBM_INT_CLEAR_CMD 0x061 55: #define GEN8_RBBM_INT_0_MASK 0x062 56: #define GEN8_RBBM_INT_2_MASK 0x064 57: #define GEN8_RBBM_INT_0_STATUS 0x06a 58: #define GEN8_RBBM_SW_FUSE_INT_STATUS 0x071 59: #define GEN8_RBBM_SW_FUSE_INT_MASK 0x072 60: #define GEN8_RBBM_SW_RESET_CMD 0x073 61: #define GEN8_RBBM_POWER_UP_RESET_SW_OVERRIDE 0x07d 62: #define GEN8_RBBM_POWER_UP_RESET_SW_BV_OVERRIDE 0x07e 63: #define GEN8_RBBM_CLOCK_CNTL_GLOBAL 0x09a 64: #define GEN8_RBBM_CGC_GLOBAL_LOAD_CMD 0x09b 65: #define GEN8_RBBM_CGC_P2S_TRIG_CMD 0x09c 66: #define GEN8_RBBM_CGC_P2S_CNTL 0x09d 67: #define GEN8_RBBM_CGC_P2S_STATUS 0x09f 68: 69: #define GEN8_RBBM_CGC_0_PC 0x10b 70: #define GEN8_RBBM_PERFCTR_GPU_BUSY_MASKED 0x19e 71: #define GEN8_RBBM_PERFCTR_SRAM_INIT_STATUS 0x19f 72: #define GEN8_RBBM_PERFCTR_FLUSH_HOST_STATUS 0x1a1 73: #define GEN8_RBBM_PERFCTR_CP_0_LO 0x1b0 74: #define GEN8_RBBM_PERFCTR_CP_0_HI 0x1b1 75: #define GEN8_RBBM_PERFCTR_CP_1_LO 0x1b2 76: #define GEN8_RBBM_PERFCTR_CP_1_HI 0x1b3 77: #define GEN8_RBBM_PERFCTR_CP_2_LO 0x1b4 78: #define GEN8_RBBM_PERFCTR_CP_2_HI 0x1b5 79: #define GEN8_RBBM_PERFCTR_CP_3_LO 0x1b6 80: #define GEN8_RBBM_PERFCTR_CP_3_HI 0x1b7 81: #define GEN8_RBBM_PERFCTR_CP_4_LO 0x1b8 MATCH LINES: 620 608: #define GEN8_DBGC_EVT_INTF_SEL_3_4 0x654 /* Indexed Register */ 609: #define GEN8_DBGC_EVT_INTF_SEL_3_5 0x655 /* Indexed Register */ 610: #define GEN8_DBGC_TRACE_BUFFER_STATUS 0x660 611: #define GEN8_DBGC_TRACE_BUFFER_CMD 0x661 612: #define GEN8_DBGC_DBG_TRACE_BUFFER_RD_ADDR 0x662 613: #define GEN8_DBGC_DBG_TRACE_BUFFER_RD_DATA 0x663 614: #define GEN8_DBGC_TRACE_BUFFER_ATB_RD_STATUS 0x664 615: #define GEN8_DBGC_SMMU_FAULT_BLOCK_HALT_CFG 0x665 616: #define GEN8_DBGC_DBG_LOPC_SB_RD_ADDR 0x666 617: #define GEN8_DBGC_DBG_LOPC_SB_RD_DATA 0x667 618: #define GEN8_DBGC_DBG_LOPC_SB_WR_ADDR 0x668 619: #define GEN8_DBGC_DBG_LOPC_SB_WR_DATA 0x669 620: #define GEN8_DBGC_INTERRUPT_STATUS 0x66a 621: #define GEN8_DBGC_GBIF_DBG_BASE_LO 0x680 622: #define GEN8_DBGC_GBIF_DBG_BASE_HI 0x681 623: #define GEN8_DBGC_GBIF_DBG_BUFF_SIZE 0x682 624: #define GEN8_DBGC_GBIF_DBG_CNTL 0x683 625: #define GEN8_DBGC_GBIF_DBG_CMD 0x684 626: #define GEN8_DBGC_GBIF_DBG_STATUS 0x685 627: #define GEN8_DBGC_SCOPE_PERF_COUNTER_CFG_US 0x700 628: #define GEN8_DBGC_CFG_PERF_TRIG_CLUSTER_FE_US 0x701 629: #define GEN8_DBGC_CFG_PERF_TRIG_CLUSTER_VPC_US 0x702 630: #define GEN8_DBGC_CFG_PERF_TRIG_CLUSTER_SP_VS_US 0x703 631: #define GEN8_DBGC_CFG_PERF_TRIG_CLUSTER_SP_PS_US 0x704 632: #define GEN8_DBGC_CFG_PERF_TRIG_CLUSTER_NONE_US 0x707 633: #define GEN8_DBGC_CFG_BV_PERF_TRIG_CLUSTER_FE_US 0x708 634: #define GEN8_DBGC_CFG_BV_PERF_TRIG_CLUSTER_VPC_US 0x709 635: #define GEN8_DBGC_CFG_BV_PERF_TRIG_CLUSTER_SP_VS_US 0x70a 636: #define GEN8_DBGC_CFG_BV_PERF_TRIG_CLUSTER_NONE_US 0x70f 637: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_FE_US 0x710 638: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_FE_US_1 0x711 639: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_FE_US_2 0x712 640: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_VPC_US 0x713 641: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_VPC_US_1 0x714 642: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_SP_VS_US 0x715 643: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_SP_PS_US 0x716 644: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_NONE_US 0x720 MATCH LINES: 668 656: #define GEN8_DBGC_CFG_GBIF_BR_PERF_CNTR_BASE_HI 0x745 657: #define GEN8_DBGC_CFG_GBIF_BR_BUFFER_SIZE 0x746 658: #define GEN8_DBGC_CFG_GBIF_BV_PERF_CNTR_BASE_LO 0x747 659: #define GEN8_DBGC_CFG_GBIF_BV_PERF_CNTR_BASE_HI 0x748 660: #define GEN8_DBGC_CFG_GBIF_BV_BUFFER_SIZE 0x749 661: #define GEN8_DBGC_CFG_GBIF_QOS_CTRL 0x74a 662: #define GEN8_DBGC_GBIF_BR_PERF_CNTR_WRITE_POINTER 0x750 663: #define GEN8_DBGC_GBIF_BV_PERF_CNTR_WRITE_POINTER 0x751 664: #define GEN8_DBGC_PERF_COUNTER_FE_LOCAL_BATCH_ID 0x752 665: #define GEN8_DBGC_CFG_PERF_WAIT_IDLE_CLOCKS_CNTL 0x753 666: #define GEN8_DBGC_PERF_COUNTER_SCOPING_CMD_US 0x754 667: #define GEN8_DBGC_PERF_SKEW_BUFFER_INIT_CMD 0x755 668: #define GEN8_DBGC_LOPC_INTERRUPT_STATUS 0x759 669: #define GEN8_DBGC_LOPC_BUFFER_PTR_STATUS 0x75a 670: #define GEN8_DBGC_PERF_SCOPING_STATUS 0x75b 671: #define GEN8_DBGC_PERF_COUNTER_PKT_STATUS 0x75c 672: #define GEN8_DBGC_GC_LIVE_MBX_PKT_STATUS 0x760 673: #define GEN8_DBGC_GC_ALW_MBX_PKT_STATUS 0x761 674: #define GEN8_DBGC_AO_CNTR_LO_STATUS 0x762 675: #define GEN8_DBGC_AO_CNTR_HI_STATUS 0x763 676: #define GEN8_DBGC_LOPC_GC_SB_DEPTH_STATUS 0x770 677: #define GEN8_DBGC_LPAC_SCOPE_PERF_COUNTER_CFG_US 0x780 678: #define GEN8_DBGC_CFG_PERF_TRIG_LPAC_US 0x781 679: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_LPAC_US 0x782 680: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_LPAC_US_1 0x783 681: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_LPAC_US_2 0x784 682: #define GEN8_DBGC_CFG_PERF_TIMESTAMP_TRIG_SEL_LPAC_US 0x785 683: #define GEN8_DBGC_CFG_GBIF_LPAC_PERF_CNTR_BASE_LO 0x786 684: #define GEN8_DBGC_CFG_GBIF_LPAC_PERF_CNTR_BASE_HI 0x787 685: #define GEN8_DBGC_CFG_GBIF_LPAC_BUFFER_SIZE 0x788 686: #define GEN8_DBGC_GBIF_LPAC_PERF_CNTR_WRITE_POINTER 0x789 687: #define GEN8_DBGC_CFG_LPAC_PERF_WAIT_IDLE_CLOCKS_CNTL 0x78a 688: #define GEN8_DBGC_LPAC_PERF_COUNTER_SCOPING_CMD_US 0x78b 689: #define GEN8_DBGC_LPAC_MBX_PKT_STATUS 0x78c 690: #define GEN8_DBGC_LPAC_PERF_SCOPING_STATUS 0x78d 691: #define GEN8_DBGC_LOPC_LPAC_SB_DEPTH_STATUS 0x790 692: #define GEN8_DBGC_SCOPE_PERF_COUNTER_CFG_S 0x7a0 MATCH LINES: 813, 814, 815, 816 801: #define GEN8_CP_MISC_CNTL 0x84c 802: #define GEN8_CP_APRIV_CNTL_PIPE 0x84d 803: #define GEN8_CP_PROTECT_CNTL_PIPE 0x84e 804: #define GEN8_CP_PROTECT_STATUS_PIPE 0x84f 805: #define GEN8_CP_PROTECT_REG_GLOBAL 0x850 806: #define GEN8_CP_PROTECT_REG_PIPE 0x8a0 807: 808: #define GEN8_CP_SQE_ICACHE_CNTL_PIPE 0x8b0 809: #define GEN8_CP_SQE_DCACHE_CNTL_PIPE 0x8b1 810: #define GEN8_CP_CHICKEN_DBG_PIPE 0x8b2 811: #define GEN8_CP_HW_FAULT_STATUS_PIPE 0x8b3 812: #define GEN8_CP_HW_FAULT_STATUS_MASK_PIPE 0x8b4 813: #define GEN8_CP_INTERRUPT_STATUS_GLOBAL 0x8b5 814: #define GEN8_CP_INTERRUPT_STATUS_MASK_GLOBAL 0x8b6 815: #define GEN8_CP_INTERRUPT_STATUS_PIPE 0x8b7 816: #define GEN8_CP_INTERRUPT_STATUS_MASK_PIPE 0x8b8 817: #define GEN8_CP_PIPE_STATUS_PIPE 0x8b9 818: #define GEN8_CP_GPU_BATCH_ID_PIPE 0x8ba 819: #define GEN8_CP_SQE_STATUS_PIPE 0x8bb 820: #define GEN8_CP_CONTEXT_SWITCH_CNTL 0x8c0 821: #define GEN8_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x8c1 822: #define GEN8_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x8c2 823: #define GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_LO 0x8c3 824: #define GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_HI 0x8c4 825: #define GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_LO 0x8c5 826: #define GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_HI 0x8c6 827: #define GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_LO 0x8c7 828: #define GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_HI 0x8c8 829: #define GEN8_CP_CONTEXT_SWITCH_LEVEL_STATUS 0x8cb 830: #define GEN8_CP_PERFCTR_CP_SEL_0 0x8d0 831: #define GEN8_CP_PERFCTR_CP_SEL_1 0x8d1 832: #define GEN8_CP_PERFCTR_CP_SEL_2 0x8d2 833: #define GEN8_CP_PERFCTR_CP_SEL_3 0x8d3 834: #define GEN8_CP_PERFCTR_CP_SEL_4 0x8d4 835: #define GEN8_CP_PERFCTR_CP_SEL_5 0x8d5 836: #define GEN8_CP_PERFCTR_CP_SEL_6 0x8d6 837: #define GEN8_CP_PERFCTR_CP_SEL_7 0x8d7 838: #define GEN8_CP_PERFCTR_CP_SEL_8 0x8d8 839: #define GEN8_CP_PERFCTR_CP_SEL_9 0x8d9 840: #define GEN8_CP_PERFCTR_CP_SEL_10 0x8da MATCH LINES: 1618, 1619, 1620, 1621 1606: #define GEN8_GMUCX_GMU2HOST_INTR_CLR 0x1f991 1607: #define GEN8_GMUCX_GMU2HOST_INTR_INFO 0x1f992 1608: #define GEN8_GMUCX_GMU2HOST_INTR_MASK 0x1f993 1609: #define GEN8_GMUCX_HOST2GMU_INTR_SET 0x1f994 1610: #define GEN8_GMUCX_HOST2GMU_INTR_CLR 0x1f995 1611: #define GEN8_GMUCX_HOST2GMU_INTR_RAW_INFO 0x1f996 1612: #define GEN8_GMUCX_GENERAL_8 0x1f9c8 1613: #define GEN8_GMUCX_GENERAL_9 0x1f9c9 1614: #define GEN8_GMUCX_GENERAL_10 0x1f9ca 1615: #define GEN8_GMUCX_GENERAL_11 0x1f9cb 1616: 1617: /* Always on registers */ 1618: #define GEN8_GMUAO_AO_INTERRUPT_EN 0x23b03 1619: #define GEN8_GMUAO_AO_HOST_INTERRUPT_CLR 0x23b04 1620: #define GEN8_GMUAO_AO_HOST_INTERRUPT_STATUS 0x23b05 1621: #define GEN8_GMUAO_AO_HOST_INTERRUPT_MASK 0x23b06 1622: 1623: /* GMU RSC control registers */ 1624: #define GEN8_GMUAO_RSCC_CONTROL_REQ 0x23b07 1625: #define GEN8_GMUAO_RSCC_CONTROL_ACK 0x23b08 1626: 1627: #define GEN8_GMUAO_CGC_MODE_CNTL 0x23b09 1628: #define GEN8_GMUAO_CGC_DELAY_CNTL 0x23b0a 1629: #define GEN8_GMUAO_CGC_HYST_CNTL 0x23b0b 1630: #define GEN8_GMUAO_GPU_CX_BUSY_STATUS 0x23b0c 1631: #define GEN8_GMUAO_GPU_CX_BUSY_STATUS2 0x23b0d 1632: #define GEN8_GMUAO_GPU_CX_BUSY_MASK 0x23b0e 1633: 1634: /* FENCE control registers */ 1635: #define GEN8_GMUAO_AHB_FENCE_CTRL 0x23b10 1636: #define GEN8_GMUAO_AHB_FENCE_RANGE_0 0x23b11 1637: #define GEN8_GMUAO_AHB_FENCE_STATUS 0x23b13 1638: #define GEN8_GMUAO_AHB_FENCE_STATUS_CLR 0x23b14 1639: #define GEN8_GMUAO_RBBM_INT_UNMASKED_STATUS_SHADOW 0x23b15 1640: #define GEN8_GMUAO_LPAC_BUSY_STATUS 0x23b30 1641: 1642: /* GMU countables */ 1643: #define GEN8_GMU_CM3_BUSY_CYCLES 0 1644: 1645: /* GPUCC registers */ MATCH LINES: 1672, 1673 1660: #define GEN8_RSCC_TCS8_DRV0_STATUS 0x0088a 1661: #define GEN8_RSCC_TCS9_DRV0_STATUS 0x00932 1662: 1663: #define GEN8_SMMU_BASE 0x28000 1664: 1665: /* GPU CX_MISC registers */ 1666: #define GEN8_GPU_CX_MISC_CX_AHB_AON_CNTL 0x27810 1667: #define GEN8_GPU_CX_MISC_CX_AHB_GMU_CNTL 0x27811 1668: #define GEN8_GPU_CX_MISC_CX_AHB_CP_CNTL 0x27812 1669: #define GEN8_GPU_CX_MISC_CX_AHB_VBIF_SMMU_CNTL 0x27813 1670: #define GEN8_GPU_CX_MISC_CX_AHB_HOST_CNTL 0x27814 1671: #define GEN8_GPU_CX_MISC_INT_CLEAR_CMD 0x27831 1672: #define GEN8_GPU_CX_MISC_INT_0_MASK 0x27833 1673: #define GEN8_GPU_CX_MISC_INT_0_STATUS 0x27834 1674: #define GEN8_GPU_CX_MISC_SMMU_INTR_MASK0 0x27846 1675: #define GEN8_GPU_CX_MISC_SMMU_INTR_MASK1 0x27847 1676: #define GEN8_GPU_CX_MISC_AO_COUNTER_LO 0x27880 1677: #define GEN8_GPU_CX_MISC_AO_COUNTER_HI 0x27881 1678: #define GEN8_GPU_CX_MISC_GFX_PWR_CLK_STATUS 0x27883 1679: #define GEN8_GPU_CX_MISC_SLICE_ENABLE_TEST 0x27886 1680: #define GEN8_GPU_CX_MISC_SLICE_ENABLE_FINAL 0x27887 1681: #define GEN8_GPU_CX_MISC_SW_FUSE_VALUE 0x27c00 1682: #define GEN8_GPU_CX_MISC_SW_FUSE_FREQ_LIMIT_STATUS 0x27c05 1683: 1684: /* GPU SW Fuse Feature bit fields */ 1685: #define GEN8_FASTBLEND_SW_FUSE 0 1686: #define GEN8_LPAC_SW_FUSE 1 1687: #define GEN8_RAYTRACING_SW_FUSE 2 1688: #define GEN8_MALU_SW_FUSE 3 1689: 1690: #define GEN8_SW_FUSE_INT_MASK \ 1691: ((1 << GEN8_FASTBLEND_SW_FUSE) | \ 1692: (1 << GEN8_LPAC_SW_FUSE) | \ 1693: (1 << GEN8_RAYTRACING_SW_FUSE)) 1694: 1695: /* QDSS register offsets */ 1696: #define QDSS_AOSS_APB_TMC_RSZ 0x04 1697: #define QDSS_AOSS_APB_TMC_RRD 0x10 --- FILE: \kgsl.c | HITS: 4 --- MATCH LINES: 5227, 5264, 5274, 5285 5215: 5216: dma_set_max_seg_size(device->dev, (u32)DMA_BIT_MASK(32)); 5217: 5218: set_dma_ops(device->dev, NULL); 5219: 5220: WARN_ON(kobject_init_and_add(&device->gpu_sysfs_kobj, &kgsl_gpu_sysfs_ktype, 5221: kernel_kobj, "gpu")); 5222: 5223: return 0; 5224: } 5225: 5226: int kgsl_request_irq(struct platform_device *pdev, const char *name, 5227: const char *alt_name, int index, irq_handler_t handler, void *data) 5228: { 5229: int ret, num = -EINVAL; 5230: const char *irq_name = name; 5231: 5232: /* 5233: * Get IRQ by name if available, else try alt_name if previous failed, 5234: * otherwise fall back to index-based retrieval. 5235: */ 5236: if (name) { 5237: num = platform_get_irq_byname_optional(pdev, name); 5238: if (num < 0 && alt_name) { 5239: num = platform_get_irq_byname_optional(pdev, alt_name); 5240: irq_name = alt_name; 5241: } 5242: } 5243: 5244: if (num < 0 && index >= 0) { 5245: num = platform_get_irq(pdev, index); 5246: irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "irq-index-%d", index); 5247: if (!irq_name) { 5248: dev_err(&pdev->dev, "Failed to allocate IRQ name string for index %d\n", 5249: index); 5250: return -ENOMEM; 5251: } 5252: } 5253: 5254: if (num < 0) { 5255: dev_err(&pdev->dev, "Unable to retrieve IRQ '%s' (alt: '%s', index: %d): error %d\n", 5256: name ? name : "N/A", alt_name ? alt_name : "N/A", index, num); 5257: return num; 5258: } 5259: 5260: ret = devm_request_irq(&pdev->dev, num, handler, IRQF_TRIGGER_HIGH, 5261: irq_name, data); 5262: 5263: if (ret) { 5264: dev_err(&pdev->dev, "Unable to get interrupt %s: %d\n", 5265: irq_name, ret); 5266: return ret; 5267: } 5268: 5269: disable_irq(num); 5270: return num; 5271: } 5272: 5273: int kgsl_request_irq_optional(struct platform_device *pdev, const char *name, 5274: irq_handler_t handler, void *data) 5275: { 5276: int ret, num = platform_get_irq_byname_optional(pdev, name); 5277: 5278: if (num < 0) 5279: return num; 5280: 5281: ret = devm_request_irq(&pdev->dev, num, handler, IRQF_TRIGGER_HIGH, 5282: name, data); 5283: 5284: if (ret) { 5285: dev_err(&pdev->dev, "Unable to get interrupt %s: %d\n", 5286: name, ret); 5287: return ret; 5288: } 5289: 5290: disable_irq(num); 5291: return num; 5292: } 5293: 5294: int kgsl_of_property_read_ddrtype(struct device_node *node, const char *base, 5295: u32 *ptr) 5296: { 5297: char str[32]; 5298: int ddr = kgsl_get_ddrtype(); 5299: 5300: /* kgsl_get_ddrtype returns error if the DDR type isn't determined */ 5301: if (ddr >= 0) { 5302: int ret; 5303: 5304: /* Construct expanded string for the DDR type */ 5305: ret = snprintf(str, sizeof(str), "%s-ddr%d", base, ddr); 5306: 5307: /* WARN_ON() if the array size was too small for the string */ 5308: if (WARN_ON(ret > sizeof(str))) 5309: return -ENOMEM; --- FILE: \kgsl.h | HITS: 3 --- MATCH LINES: 11 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2008-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: #ifndef __KGSL_H 7: #define __KGSL_H 8: 9: #include 10: #include 11: #include 12: #include 13: #include 14: #include 15: #include 16: #include 17: 18: #include "kgsl_gmu_core.h" 19: #include "kgsl_pwrscale.h" 20: #include "kgsl_sharedmem.h" 21: 22: #define KGSL_L3_DEVICE "kgsl-l3" 23: 24: #if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)) 25: #include 26: #define KGSL_BOOT_MARKER(str) place_marker("M - DRIVER " str) 27: #else 28: #define KGSL_BOOT_MARKER(str) pr_info("boot_kpi: M - DRIVER " str) 29: #endif 30: 31: /* 32: * --- kgsl drawobj flags --- 33: * These flags are same as --- drawobj flags --- 34: * but renamed to reflect that cmdbatch is renamed to drawobj. 35: */ MATCH LINES: 435, 438 423: kgsl_sharedmem_find_id(struct kgsl_process_private *process, unsigned int id); 424: 425: struct kgsl_mem_entry *gpumem_alloc_entry(struct kgsl_device_private *dev_priv, 426: uint64_t size, uint64_t flags); 427: long gpumem_free_entry(struct kgsl_mem_entry *entry); 428: 429: enum kgsl_mmutype kgsl_mmu_get_mmutype(struct kgsl_device *device); 430: 431: /* Helper functions */ 432: unsigned long kgsl_get_align(struct kgsl_memdesc *memdesc); 433: 434: int kgsl_request_irq(struct platform_device *pdev, const char *name, 435: const char *alt_name, int index, irq_handler_t handler, void *data); 436: 437: int kgsl_request_irq_optional(struct platform_device *pdev, const char *name, 438: irq_handler_t handler, void *data); 439: 440: int __init kgsl_core_init(void); 441: void kgsl_core_exit(void); 442: 443: static inline int timestamp_cmp(unsigned int a, unsigned int b) 444: { 445: /* check for equal */ 446: if (a == b) 447: return 0; 448: 449: /* check for greater-than for non-rollover case */ 450: if ((a > b) && (a - b < KGSL_TIMESTAMP_WINDOW)) 451: return 1; 452: 453: /* check for greater-than for rollover case 454: * note that <= is required to ensure that consistent 455: * results are returned for values whose difference is 456: * equal to the window size 457: */ 458: a += KGSL_TIMESTAMP_WINDOW; 459: b += KGSL_TIMESTAMP_WINDOW; 460: return ((a > b) && (a - b <= KGSL_TIMESTAMP_WINDOW)) ? 1 : -1; 461: } 462: --- FILE: \kgsl_device.h | HITS: 2 --- MATCH LINES: 419, 421 407: /** @flags: Flags for gpu_period stats */ 408: unsigned long flags; 409: struct { 410: u64 begin; 411: u64 end; 412: } gpu_period; 413: /** @idle_jiffies: Latest idle jiffies */ 414: unsigned long idle_jiffies; 415: /** @dump_all_ibs: Whether to dump all ibs in snapshot */ 416: bool dump_all_ibs; 417: /** @freq_limiter_irq_clear: reset controller to clear freq limiter irq */ 418: struct reset_control *freq_limiter_irq_clear; 419: /** @freq_limiter_intr_num: The interrupt number for freq limiter */ 420: int freq_limiter_intr_num; 421: /** @cx_host_irq_num: Interrupt number for cx_host_irq */ 422: int cx_host_irq_num; 423: /** 424: * @max_syncobj_hw_fence_count: Maximum number of hardware fences that are allowed in a sync 425: * object 426: */ 427: u32 max_syncobj_hw_fence_count; 428: /** @file_mutex: Mutex to protect device open and close operations */ 429: struct mutex file_mutex; 430: /** @host_based_dcvs: Set when KGSL is in charge of DCVS */ 431: bool host_based_dcvs; 432: }; 433: 434: #define KGSL_MMU_DEVICE(_mmu) \ 435: container_of((_mmu), struct kgsl_device, mmu) 436: 437: /** 438: * enum bits for struct kgsl_context.priv 439: * @KGSL_CONTEXT_PRIV_SUBMITTED - The context has submitted commands to gpu. 440: * @KGSL_CONTEXT_PRIV_DETACHED - The context has been destroyed by userspace 441: * and is no longer using the gpu. 442: * @KGSL_CONTEXT_PRIV_INVALID - The context has been destroyed by the kernel 443: * because it caused a GPU fault. 444: * @KGSL_CONTEXT_PRIV_PAGEFAULT - The context has caused a page fault. 445: * @KGSL_CONTEXT_PRIV_DEVICE_SPECIFIC - this value and higher values are --- FILE: \kgsl_gmu_core.h | HITS: 2 --- MATCH LINES: 49 37: #error "CNOC levels cannot exceed GX levels" 38: #endif 39: 40: enum gmu_common_capabilities { 41: FCC_VERSION_INFO = 0, 42: }; 43: 44: enum gmu_platform_capabilities { 45: FAC_TRACE_BUFFER = 0, 46: FAC_VRB_HW_FENCE_SHADOW_NUM_ENTRIES = 1, 47: FAC_VRB_CL_NO_FT_TIMEOUT = 2, 48: FAC_VRB_PREEMPT_COUNT = 3, 49: FAC_RBBM_INTERRUPTS_HANDLE_ALL = 4, 50: FAC_FORCE_RETIRE_COMMAND = 5, 51: FAC_SOFT_RESET = 6, 52: FAC_FAST_CONTEXT_DESTROY = 7, 53: FAC_POWER_CONTROL_WA = 8, 54: }; 55: 56: /* 57: * These are the different ways the GMU can boot. GMU_WARM_BOOT is waking up 58: * from slumber. GMU_COLD_BOOT is booting for the first time. GMU_RESET 59: * is a soft reset of the GMU. 60: */ 61: enum gmu_core_boot { 62: GMU_WARM_BOOT = 0, 63: GMU_COLD_BOOT = 1, 64: GMU_RESET = 2 65: }; 66: 67: /* Bits for the flags field in the gmu structure */ 68: enum gmu_core_flags { 69: GMU_BOOT_INIT_DONE = 0, 70: GMU_HFI_ON, 71: GMU_FAULT, 72: GMU_DCVS_REPLAY, 73: GMU_ENABLED, MATCH LINES: 235 223: /* Contains the number of L1A GPU preemptions */ 224: VRB_PREEMPT_COUNT_L1A = 7, 225: /* Contains the number of L1B GPU preemptions */ 226: VRB_PREEMPT_COUNT_L1B = 8, 227: /* Contains the GMU VA for power limits trace buffer */ 228: VRB_PWR_LIMITS_TRACE_BUF = 9, 229: /* Contains the total size of context record in KB */ 230: VRB_CTXRECORD_TOTAL_SZ = 10, 231: /* Contains the size of AQE context record in KB */ 232: VRB_CTXRECORD_AQE_SZ = 11, 233: /* Contains the size of GMEM inside context record in KB */ 234: VRB_CTXRECORD_GMEM_SZ = 12, 235: /* Contains whether to enable fault on DBGC interrupts */ 236: VRB_DBGC_FAULT_ENABLE = 17, 237: }; 238: 239: /* For GMU Trace */ 240: #define GMU_TRACE_SIZE SZ_16K 241: 242: /* Trace header defines */ 243: /* Logtype to decode the trace pkt data */ 244: #define TRACE_LOGTYPE_HWSCHED 1 245: /* Trace buffer threshold for GMU to send F2H message */ 246: #define TRACE_BUFFER_THRESHOLD 80 247: /* 248: * GMU Trace timer value to check trace packet consumption. GMU timer handler tracks the 249: * readindex, If it's not moved since last timer fired, GMU will send the f2h message to 250: * drain trace packets. GMU Trace Timer will be restarted if the readindex is moving. 251: */ 252: #define TRACE_TIMEOUT_MSEC 5 253: 254: /* Trace metadata defines */ 255: /* Trace drop mode hint for GMU to drop trace packets when trace buffer is full */ 256: #define TRACE_MODE_DROP 1 257: /* Trace buffer header version */ 258: #define TRACE_HEADER_VERSION_1 1 259: --- FILE: \kgsl_iommu.c | HITS: 6 --- MATCH LINES: 1230 1218: stall = kgsl_iommu_check_stall_on_fault(ctx, mmu, flags); 1219: terminate = test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &mmu->pfpolicy) && 1220: test_bit(KGSL_MMU_PAGEFAULT_TERMINATE, &mmu->features); 1221: 1222: kgsl_iommu_print_fault(mmu, ctx, addr, ptbase, contextidr, flags, private, 1223: context); 1224: kgsl_iommu_add_fault_info(context, addr, flags); 1225: 1226: if (stall || terminate) { 1227: u32 sctlr; 1228: 1229: /* 1230: * Disable context fault interrupts as we do not clear FSR in 1231: * the ISR. Will be re-enabled after FSR is cleared. 1232: */ 1233: sctlr = KGSL_IOMMU_GET_CTX_REG(ctx, KGSL_IOMMU_CTX_SCTLR); 1234: sctlr &= ~(0x1 << KGSL_IOMMU_SCTLR_CFIE_SHIFT); 1235: KGSL_IOMMU_SET_CTX_REG(ctx, KGSL_IOMMU_CTX_SCTLR, sctlr); 1236: 1237: /* Make sure the above write goes through before we return */ 1238: wmb(); 1239: 1240: /* This is used by reset/recovery path */ 1241: if (stall) { 1242: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1243: 1244: ctx->stalled_on_fault = true; 1245: 1246: /* Go ahead with recovery*/ 1247: adreno_scheduler_fault(adreno_dev, ADRENO_IOMMU_STALL_ON_PAGE_FAULT); 1248: } 1249: } 1250: 1251: kgsl_context_put(context); 1252: kgsl_process_private_put(private); 1253: 1254: /* MATCH LINES: 1997, 1998 1985: { 1986: unsigned int sctlr_val; 1987: 1988: if (ctx->stalled_on_fault || _ctx_terminated_on_fault(mmu, ctx)) { 1989: struct kgsl_device *device = KGSL_MMU_DEVICE(mmu); 1990: 1991: kgsl_iommu_enable_clk(mmu); 1992: 1993: dev_err_ratelimited(device->dev, "Clearing pagefault bits in FSR\n"); 1994: 1995: KGSL_IOMMU_SET_CTX_REG(ctx, KGSL_IOMMU_CTX_FSR, 0xffffffff); 1996: /* 1997: * Re-enable context fault interrupts after clearing 1998: * FSR to prevent the interrupt from firing repeatedly 1999: */ 2000: sctlr_val = KGSL_IOMMU_GET_CTX_REG(ctx, KGSL_IOMMU_CTX_SCTLR); 2001: sctlr_val |= (0x1 << KGSL_IOMMU_SCTLR_CFIE_SHIFT); 2002: KGSL_IOMMU_SET_CTX_REG(ctx, KGSL_IOMMU_CTX_SCTLR, sctlr_val); 2003: /* 2004: * Make sure the above register writes 2005: * are not reordered across the barrier 2006: * as we use writel_relaxed to write them 2007: */ 2008: wmb(); 2009: kgsl_iommu_disable_clk(mmu); 2010: if (ctx->stalled_on_fault) 2011: ctx->stalled_on_fault = false; 2012: } 2013: } 2014: 2015: static void kgsl_iommu_clear_fsr(struct kgsl_mmu *mmu) 2016: { 2017: struct kgsl_iommu *iommu = &mmu->iommu; 2018: 2019: kgsl_iommu_context_clear_fsr(mmu, &iommu->user_context); 2020: 2021: if (iommu->lpac_context.domain) 2022: kgsl_iommu_context_clear_fsr(mmu, &iommu->lpac_context); MATCH LINES: 2101, 2102, 2105 2089: static u64 2090: kgsl_iommu_get_current_ttbr0(struct kgsl_mmu *mmu, struct kgsl_context *context) 2091: { 2092: u64 val; 2093: struct kgsl_iommu *iommu = &mmu->iommu; 2094: struct kgsl_iommu_context *ctx = &iommu->user_context; 2095: struct kgsl_device *device = KGSL_MMU_DEVICE(mmu); 2096: 2097: if (kgsl_context_is_lpac(context)) 2098: ctx = &iommu->lpac_context; 2099: 2100: /* 2101: * We cannot enable or disable the clocks in interrupt and atomic context, this 2102: * function is called from interrupt context if there is an axi error and atomic 2103: * context GPU snapshot for panic notifier callback. 2104: */ 2105: if (in_interrupt() || device->snapshot_atomic) 2106: return 0; 2107: 2108: if (ctx->cb_num < 0) 2109: return 0; 2110: 2111: kgsl_iommu_enable_clk(mmu); 2112: val = KGSL_IOMMU_GET_CTX_REG_Q(ctx, KGSL_IOMMU_CTX_TTBR0); 2113: kgsl_iommu_disable_clk(mmu); 2114: return val; 2115: } 2116: 2117: /* 2118: * kgsl_iommu_set_pf_policy() - Set the pagefault policy for IOMMU 2119: * @mmu: Pointer to mmu structure 2120: * @pf_policy: The pagefault polict to set 2121: * 2122: * Check if the new policy indicated by pf_policy is same as current 2123: * policy, if same then return else set the policy 2124: */ 2125: static int kgsl_iommu_set_pf_policy_ctxt(struct kgsl_mmu *mmu, 2126: unsigned long pf_policy, struct kgsl_iommu_context *ctx) 2127: { 2128: int cur, new; 2129: struct kgsl_iommu *iommu = &mmu->iommu; --- FILE: \kgsl_mmu.h | HITS: 1 --- MATCH LINES: 34 22: /* Mask ASID fields to match 48bit ptbase address*/ 23: #define MMU_SW_PT_BASE(_ttbr0) \ 24: (_ttbr0 & (BIT_ULL(KGSL_IOMMU_ASID_START_BIT) - 1)) 25: 26: #define KGSL_MMU_DEVICE(_mmu) \ 27: container_of((_mmu), struct kgsl_device, mmu) 28: 29: /** 30: * enum kgsl_ft_pagefault_policy_bits - KGSL pagefault policy bits 31: * @KGSL_FT_PAGEFAULT_INT_ENABLE: No longer used, but retained for compatibility 32: * @KGSL_FT_PAGEFAULT_GPUHALT_ENABLE: enable GPU halt on pagefaults 33: * @KGSL_FT_PAGEFAULT_LOG_ONE_PER_PAGE: log one pagefault per page 34: * @KGSL_FT_PAGEFAULT_LOG_ONE_PER_INT: log one pagefault per interrupt 35: */ 36: enum { 37: KGSL_FT_PAGEFAULT_INT_ENABLE = 0, 38: KGSL_FT_PAGEFAULT_GPUHALT_ENABLE = 1, 39: KGSL_FT_PAGEFAULT_LOG_ONE_PER_PAGE = 2, 40: KGSL_FT_PAGEFAULT_LOG_ONE_PER_INT = 3, 41: /* KGSL_FT_PAGEFAULT_MAX_BITS is used to calculate the mask */ 42: KGSL_FT_PAGEFAULT_MAX_BITS, 43: }; 44: 45: #define KGSL_FT_PAGEFAULT_MASK GENMASK(KGSL_FT_PAGEFAULT_MAX_BITS - 1, 0) 46: 47: #define KGSL_FT_PAGEFAULT_DEFAULT_POLICY 0 48: 49: struct kgsl_device; 50: 51: enum kgsl_mmutype { 52: KGSL_MMU_TYPE_IOMMU = 0, 53: KGSL_MMU_TYPE_NONE 54: }; 55: 56: #define KGSL_IOMMU_SMMU_V500 1 57: 58: struct kgsl_pagetable { --- FILE: \kgsl_pwrctrl.c | HITS: 10 --- MATCH LINES: 1778, 1801, 1808, 1809, 1819, 1820, 1821, 1822 1766: * Hence don't disable it if force clock ON is set. 1767: */ 1768: if (test_bit(KGSL_PWRFLAGS_POWER_ON, &pwr->ctrl_flags) || 1769: test_bit(KGSL_PWRFLAGS_CLK_ON, &pwr->ctrl_flags)) 1770: return 0; 1771: 1772: if (!state) { 1773: if (test_and_clear_bit(KGSL_PWRFLAGS_POWER_ON, 1774: &pwr->power_flags)) { 1775: kgsl_mmu_send_tlb_hint(&device->mmu, true); 1776: trace_kgsl_rail(device, state); 1777: 1778: /* Set the parent in retention voltage to disable CPR interrupts */ 1779: kgsl_regulator_set_voltage(device->dev, pwr->gx_regulator_parent, 1780: pwr->gx_regulator_parent_min_corner); 1781: 1782: kgsl_pwrctrl_disable_gx_gdsc(device); 1783: 1784: /* Remove the vote for the vdd parent supply */ 1785: kgsl_regulator_set_voltage(device->dev, pwr->gx_regulator_parent, 0); 1786: 1787: kgsl_pwrctrl_disable_cx_gdsc(device); 1788: } 1789: } else { 1790: status = enable_gdscs(device); 1791: kgsl_mmu_send_tlb_hint(&device->mmu, false); 1792: } 1793: 1794: return status; 1795: } 1796: 1797: void kgsl_pwrctrl_irq(struct kgsl_device *device, bool state) 1798: { 1799: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 1800: 1801: if (!(device->freq_limiter_intr_num || pwr->interrupt_num)) 1802: return; 1803: 1804: if (state) { 1805: if (!test_and_set_bit(KGSL_PWRFLAGS_IRQ_ON, 1806: &pwr->power_flags)) { 1807: trace_kgsl_irq(device, state); 1808: if (pwr->interrupt_num > 0) 1809: enable_irq(pwr->interrupt_num); 1810: if (device->freq_limiter_intr_num > 0) 1811: enable_irq(device->freq_limiter_intr_num); 1812: } 1813: } else { 1814: if (test_and_clear_bit(KGSL_PWRFLAGS_IRQ_ON, 1815: &pwr->power_flags)) { 1816: trace_kgsl_irq(device, state); 1817: if (device->freq_limiter_intr_num > 0) 1818: disable_irq(device->freq_limiter_intr_num); 1819: if (in_interrupt() && (pwr->interrupt_num > 0)) 1820: disable_irq_nosync(pwr->interrupt_num); 1821: else if (pwr->interrupt_num > 0) 1822: disable_irq(pwr->interrupt_num); 1823: } 1824: } 1825: } 1826: 1827: static int _get_clocks(struct kgsl_device *device) 1828: { 1829: struct device *dev = &device->pdev->dev; 1830: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 1831: const char *name; 1832: struct property *prop; 1833: 1834: pwr->isense_clk_indx = 0; 1835: of_property_for_each_string(dev->of_node, "clock-names", prop, name) { 1836: int i; 1837: 1838: for (i = 0; i < KGSL_MAX_CLKS; i++) { 1839: bool match = false; 1840: 1841: /* Skip if clock already acquired */ 1842: if (pwr->grp_clks[i]) 1843: continue; 1844: 1845: /* 1846: * Try matching with the non-standard clk name first. If it is not matched, MATCH LINES: 2381 2369: } 2370: 2371: kgsl_pwrscale_update(device); 2372: kgsl_mutex_unlock(&device->mutex); 2373: } 2374: 2375: void kgsl_timer(struct timer_list *t) 2376: { 2377: struct kgsl_device *device = kgsl_timer_container_of(device, t, idle_timer); 2378: 2379: if (device->requested_state != KGSL_STATE_SUSPEND) { 2380: kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); 2381: /* Have work run in a non-interrupt context. */ 2382: kgsl_schedule_work(&device->idle_check_ws); 2383: } 2384: } 2385: 2386: static bool kgsl_pwrctrl_isenabled(struct kgsl_device *device) 2387: { 2388: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 2389: 2390: return ((test_bit(KGSL_PWRFLAGS_CLK_ON, &pwr->power_flags) != 0) && 2391: (test_bit(KGSL_PWRFLAGS_AXI_ON, &pwr->power_flags) != 0)); 2392: } 2393: 2394: /** 2395: * kgsl_pre_hwaccess - Enforce preconditions for touching registers 2396: * @device: The device 2397: * 2398: * This function ensures that the correct lock is held and that the GPU 2399: * clock is on immediately before a register is read or written. Note 2400: * that this function does not check active_cnt because the registers 2401: * must be accessed during device start and stop, when the active_cnt 2402: * may legitimately be 0. 2403: */ 2404: void kgsl_pre_hwaccess(struct kgsl_device *device) 2405: { MATCH LINES: 2574 2562: status = -EINVAL; 2563: break; 2564: } 2565: return status; 2566: } 2567: 2568: /* 2569: * _aware() - Put device into AWARE 2570: * @device: Device pointer 2571: * 2572: * The GPU should be available for register reads/writes and able 2573: * to communicate with the rest of the system. However disable all 2574: * paths that allow a switch to an interrupt context (interrupts & 2575: * timers). 2576: * Return 0 on success else error code 2577: */ 2578: static int 2579: _aware(struct kgsl_device *device) 2580: { 2581: int status = 0; 2582: 2583: switch (device->state) { 2584: case KGSL_STATE_INIT: 2585: status = kgsl_pwrctrl_enable(device); 2586: break; 2587: case KGSL_STATE_ACTIVE: 2588: kgsl_pwrctrl_irq(device, false); 2589: kgsl_delete_timer_sync(&device->idle_timer); 2590: break; 2591: case KGSL_STATE_SLUMBER: 2592: status = kgsl_pwrctrl_enable(device); 2593: break; 2594: default: 2595: status = -EINVAL; 2596: } 2597: 2598: if (!status) --- FILE: \kgsl_pwrctrl.h | HITS: 5 --- MATCH LINES: 82, 112 70: unsigned int bus_max; 71: unsigned int acd_level; 72: /** @cx_level: CX vote */ 73: u32 cx_level; 74: /** @voltage_level: Voltage level used by the GMU to vote RPMh */ 75: u32 voltage_level; 76: /** @opp: OPP node corresponding to GPU OPP table */ 77: struct dev_pm_opp *opp; 78: }; 79: 80: /** 81: * struct kgsl_pwrctrl - Power control settings for a KGSL device 82: * @interrupt_num - The interrupt number for the device 83: * @grp_clks - Array of clocks structures that we control 84: * @power_flags - Control flags for power 85: * @pwrlevels - List of supported power levels 86: * @active_pwrlevel - The currently active power level 87: * @previous_pwrlevel - The power level before transition 88: * @thermal_pwrlevel - maximum powerlevel constraint from thermal 89: * @default_pwrlevel - device wake up power level 90: * @max_pwrlevel - maximum allowable powerlevel per the user 91: * @min_pwrlevel - minimum allowable powerlevel per the user 92: * @min_render_pwrlevel - minimum allowable powerlevel for rendering 93: * @num_pwrlevels - number of available power levels 94: * @throttle_mask - LM throttle mask 95: * @interval_timeout - timeout to be idle before a power event 96: * @clock_times - Each GPU frequency's accumulated active time in us 97: * @clk_stats - structure of clock statistics 98: * @input_disable - To disable GPU wakeup on touch input event 99: * @bus_control - true if the bus calculation is independent 100: * @bus_mod - modifier from the current power level for the bus vote 101: * @bus_percent_ab - current percent of total possible bus usage 102: * @bus_width - target specific bus width in number of bytes 103: * @bus_ab_mbytes - AB vote in Mbytes for current bus usage 104: * @constraint - currently active power constraint 105: * @superfast - Boolean flag to indicate that the GPU start should be run in the 106: * higher priority thread 107: * isense_clk_indx - index of isense clock, 0 if no isense 108: * isense_clk_on_level - isense clock rate is XO rate below this level. 109: */ 110: 111: struct kgsl_pwrctrl { 112: int interrupt_num; 113: struct clk *grp_clks[KGSL_MAX_CLKS]; 114: struct clk *gpu_bimc_int_clk; 115: /** @cx_regulator: Pointer to the CX domain regulator if applicable */ 116: struct regulator *cx_regulator; 117: /** @gx_regulator: Pointer to the GX domain regulator if applicable */ 118: struct regulator *gx_regulator; 119: /** 120: * @cx_pd: Power domain for registering CX GDSC notifier 121: * 122: * Only GMU device votes for GMU_CX_PD. Other client votes are consolidated 123: * in the CX GenPD instance, so use this for registering the notifier. 124: */ 125: struct device *cx_pd; 126: /** @gmu_cx_pd: Power domain for controlling GMU CX GDSC instance */ 127: struct device *gmu_cx_pd; 128: /** @gmu_mx_pd: Power domain for controlling GMU MX GDSC instance */ 129: struct device *gmu_mx_pd; 130: /** @gx_pd: Power domain for controlling GX GDSC */ 131: struct device *gx_pd; 132: /** @gx_regulator_parent: Pointer to the GX domain parent supply */ 133: struct regulator *gx_regulator_parent; 134: /** @gx_regulator_parent_min_corner: Minimum supply voltage for GX parent */ 135: u32 gx_regulator_parent_min_corner; 136: /** @cx_gdsc_nb: Notifier block for cx gdsc regulator */ MATCH LINES: 302, 309, 311 290: * 291: * This function will propagate the default bus vote when coming out of 292: * slumber and set bus bandwidth to 0 when going into slumber 293: * 294: * Return: 0 on success or negative error on failure 295: */ 296: int kgsl_pwrctrl_axi(struct kgsl_device *device, bool state); 297: 298: /** 299: * kgsl_idle_check - kgsl idle function 300: * @work: work item being run by the function 301: * 302: * This function is called for work that is queued by the interrupt 303: * handler or the idle timer. It attempts to transition to a clocks 304: * off state if the active_cnt is 0 and the hardware is idle. 305: */ 306: void kgsl_idle_check(struct work_struct *work); 307: 308: /** 309: * kgsl_pwrctrl_irq - Enable or disable gpu interrupts 310: * @device: Handle to the kgsl device 311: * @state: Variable to decide whether interrupts need to be enabled or disabled 312: * 313: */ 314: void kgsl_pwrctrl_irq(struct kgsl_device *device, bool state); 315: 316: /** 317: * kgsl_pwrctrl_clear_l3_vote - Relinquish l3 vote 318: * @device: Handle to the kgsl device 319: * 320: * Clear the l3 vote when going into slumber 321: */ 322: void kgsl_pwrctrl_clear_l3_vote(struct kgsl_device *device); 323: 324: /** 325: * kgsl_pwrctrl_enable_cx_gdsc - Enable cx gdsc 326: * @device: Pointer to the kgsl device 327: * 328: * Return: 0 on success or negative error on failure 329: */ 330: int kgsl_pwrctrl_enable_cx_gdsc(struct kgsl_device *device); 331: 332: /** 333: * kgsl_pwrctrl_disable_cx_gdsc - Disable cx gdsc 334: * @device: Pointer to the kgsl device 335: */ --- FILE: \kgsl_snapshot.c | HITS: 2 --- MATCH LINES: 877, 880 865: snapshot->sysfs_read++; 866: } 867: kgsl_mutex_unlock(&device->mutex); 868: 869: if (ret) 870: return ret; 871: 872: /* Return nothing if we haven't taken a snapshot yet */ 873: if (snapshot == NULL) 874: return 0; 875: 876: /* 877: * Wait for the dump worker to finish. This is interruptible 878: * to allow userspace to bail if things go horribly wrong. 879: */ 880: ret = wait_for_completion_interruptible(&snapshot->dump_gate); 881: if (ret) { 882: snapshot_release(device, snapshot); 883: return ret; 884: } 885: 886: written = kgsl_snapshot_do_read(snapshot, buf, off, count); 887: 888: /* 889: * Make sure everything has been written out before destroying things. 890: * The best way to confirm this is to go all the way through without 891: * writing any bytes - so only release if we get this far and 892: * written is 0 and there are no concurrent reads pending 893: */ 894: if (written == 0) { 895: bool snapshot_free = false; 896: 897: kgsl_mutex_lock(&device->mutex); 898: if (--snapshot->sysfs_read == 0) { 899: if (device->snapshot == snapshot) 900: device->snapshot = NULL; 901: snapshot_free = true; 902: } 903: kgsl_mutex_unlock(&device->mutex); 904: --- FILE: \kgsl_vbo.c | HITS: 1 --- MATCH LINES: 735 723: if (!(param->flags & KGSL_GPUMEM_BIND_FENCE_OUT)) 724: kgsl_sharedmem_put_bind_op(op); 725: 726: return 0; 727: } 728: 729: /* 730: * Schedule the work. All the resources will be released after 731: * the bind operation is done 732: */ 733: kgsl_sharedmem_bind_ranges(op); 734: 735: ret = wait_for_completion_interruptible(&op->comp); 736: kgsl_sharedmem_put_bind_op(op); 737: 738: return ret; 739: } --- FILE: \downstream_dependencies\msm_hw_fence.h | HITS: 2 --- MATCH LINES: 83, 85 71: * @status: Active = 1, Inactive = 0. 72: * @start_addr: Starting address of the queue. 73: * @type: Queue type (rx/tx). 74: * @queue_size: Size of the queue. 75: * @pkt_size: Size of the queue packet entries, 76: * 0 - means variable size of message in the queue, 77: * non-zero - size of the packet, fixed. 78: * @pkt_drop_cnt: Number of packets drop by sender. 79: * @rx_wm: Receiver watermark, applicable in event driven mode. 80: * @tx_wm: Sender watermark, applicable in event driven mode. 81: * @rx_req: Receiver sets this bit if queue is empty. 82: * @tx_req: Sender sets this bit if queue is full. 83: * @rx_irq_status: Receiver sets this bit and triggers an interrupt to the 84: * sender after packets are dequeued. Sender clears this bit. 85: * @tx_irq_status: Sender sets this bit and triggers an interrupt to the 86: * receiver after packets are queued. Receiver clears this bit. 87: * @read_index: read index of the queue. 88: * @write_index: write index of the queue. 89: */ 90: struct msm_hw_fence_hfi_queue_header { 91: u32 status; 92: u32 start_addr; 93: u32 type; 94: u32 queue_size; 95: u32 pkt_size; 96: u32 pkt_drop_cnt; 97: u32 rx_wm; 98: u32 tx_wm; 99: u32 rx_req; 100: u32 tx_req; 101: u32 rx_irq_status; 102: u32 tx_irq_status; 103: u32 read_index; 104: u32 write_index; 105: }; 106: 107: /** 108: * struct msm_hw_fence_mem_addr - Memory descriptor of the queue allocated by 109: * the fence driver for each client during --- FILE: \include\uapi\linux\msm_kgsl.h | HITS: 2 --- MATCH LINES: 297, 333 285: /* 286: * struct kgsl_devmemstore - this structure defines the region of memory 287: * that can be mmap()ed from this driver. The timestamp fields are volatile 288: * because they are written by the GPU 289: * @soptimestamp: Start of pipeline timestamp written by GPU before the 290: * commands in concern are processed 291: * @sbz: Unused, kept for 8 byte alignment 292: * @eoptimestamp: End of pipeline timestamp written by GPU after the 293: * commands in concern are processed 294: * @sbz2: Unused, kept for 8 byte alignment 295: * @preempted: Indicates if the context was preempted 296: * @sbz3: Unused, kept for 8 byte alignment 297: * @ref_wait_ts: Timestamp on which to generate interrupt, unused now. 298: * @sbz4: Unused, kept for 8 byte alignment 299: * @current_context: The current context the GPU is working on 300: * @sbz5: Unused, kept for 8 byte alignment 301: */ 302: struct kgsl_devmemstore { 303: volatile unsigned int soptimestamp; 304: unsigned int sbz; 305: volatile unsigned int eoptimestamp; 306: unsigned int sbz2; 307: volatile unsigned int preempted; 308: unsigned int sbz3; 309: volatile unsigned int ref_wait_ts; 310: unsigned int sbz4; 311: unsigned int current_context; 312: unsigned int sbz5; 313: }; 314: 315: #define KGSL_MEMSTORE_OFFSET(ctxt_id, field) \ 316: ((ctxt_id)*sizeof(struct kgsl_devmemstore) + \ 317: offsetof(struct kgsl_devmemstore, field)) 318: 319: /* timestamp id*/ 320: enum kgsl_timestamp_type { 321: KGSL_TIMESTAMP_CONSUMED = 0x00000001, /* start-of-pipeline timestamp */ 322: KGSL_TIMESTAMP_RETIRED = 0x00000002, /* end-of-pipeline timestamp*/ 323: KGSL_TIMESTAMP_QUEUED = 0x00000003, 324: }; 325: 326: /* property types - used with kgsl_device_getproperty */ 327: #define KGSL_PROP_DEVICE_INFO 0x1 328: #define KGSL_PROP_DEVICE_SHADOW 0x2 329: #define KGSL_PROP_DEVICE_POWER 0x3 330: #define KGSL_PROP_SHMEM 0x4 331: #define KGSL_PROP_SHMEM_APERTURES 0x5 332: #define KGSL_PROP_MMU_ENABLE 0x6 333: #define KGSL_PROP_INTERRUPT_WAITS 0x7 334: #define KGSL_PROP_VERSION 0x8 335: #define KGSL_PROP_GPU_RESET_STAT 0x9 336: #define KGSL_PROP_PWRCTRL 0xE 337: #define KGSL_PROP_PWR_CONSTRAINT 0x12 338: #define KGSL_PROP_UCHE_GMEM_VADDR 0x13 339: #define KGSL_PROP_SP_GENERIC_MEM 0x14 340: #define KGSL_PROP_UCODE_VERSION 0x15 341: #define KGSL_PROP_GPMU_VERSION 0x16 342: #define KGSL_PROP_HIGHEST_BANK_BIT 0x17 343: #define KGSL_PROP_DEVICE_BITNESS 0x18 344: #define KGSL_PROP_DEVICE_QDSS_STM 0x19 345: #define KGSL_PROP_MIN_ACCESS_LENGTH 0x1A 346: #define KGSL_PROP_UBWC_MODE 0x1B 347: #define KGSL_PROP_DEVICE_QTIMER 0x20 348: #define KGSL_PROP_L3_PWR_CONSTRAINT 0x22 349: #define KGSL_PROP_SECURE_BUFFER_ALIGNMENT 0x23 350: #define KGSL_PROP_SECURE_CTXT_SUPPORT 0x24 351: #define KGSL_PROP_SPEED_BIN 0x25 352: #define KGSL_PROP_GAMING_BIN 0x26 353: #define KGSL_PROP_QUERY_CAPABILITIES 0x27 354: #define KGSL_PROP_CONTEXT_PROPERTY 0x28 355: #define KGSL_PROP_GPU_MODEL 0x29 356: #define KGSL_PROP_VK_DEVICE_ID 0x2A 357: #define KGSL_PROP_IS_LPAC_ENABLED 0x2B TOTAL MATCHES: 638 ========================================================================================== SUBSYSTEM: FENCE_AND_TIMESTAMP ========================================================================================== --- FILE: \a5xx_reg.h | HITS: 1 --- MATCH LINES: 31 19: #define A5XX_INT_CP_SW 8 20: #define A5XX_INT_CP_HW_ERROR 9 21: #define A5XX_INT_CP_CCU_FLUSH_DEPTH_TS 10 22: #define A5XX_INT_CP_CCU_FLUSH_COLOR_TS 11 23: #define A5XX_INT_CP_CCU_RESOLVE_TS 12 24: #define A5XX_INT_CP_IB2 13 25: #define A5XX_INT_CP_IB1 14 26: #define A5XX_INT_CP_RB 15 27: #define A5XX_INT_CP_UNUSED_1 16 28: #define A5XX_INT_CP_RB_DONE_TS 17 29: #define A5XX_INT_CP_WT_DONE_TS 18 30: #define A5XX_INT_UNKNOWN_1 19 31: #define A5XX_INT_CP_CACHE_FLUSH_TS 20 32: #define A5XX_INT_UNUSED_2 21 33: #define A5XX_INT_RBBM_ATB_BUS_OVERFLOW 22 34: #define A5XX_INT_MISC_HANG_DETECT 23 35: #define A5XX_INT_UCHE_OOB_ACCESS 24 36: #define A5XX_INT_UCHE_TRAP_INTR 25 37: #define A5XX_INT_DEBBUS_INTR_0 26 38: #define A5XX_INT_DEBBUS_INTR_1 27 39: #define A5XX_INT_GPMU_VOLTAGE_DROOP 28 40: #define A5XX_INT_GPMU_FIRMWARE 29 41: #define A5XX_INT_ISDB_CPU_IRQ 30 42: #define A5XX_INT_ISDB_UNDER_DEBUG 31 43: 44: /* CP Interrupt bits */ 45: #define A5XX_CP_OPCODE_ERROR 0 46: #define A5XX_CP_RESERVED_BIT_ERROR 1 47: #define A5XX_CP_HW_FAULT_ERROR 2 48: #define A5XX_CP_DMA_ERROR 3 49: #define A5XX_CP_REGISTER_PROTECTION_ERROR 4 50: #define A5XX_CP_AHB_ERROR 5 51: 52: /* CP registers */ 53: #define A5XX_CP_RB_BASE 0x800 54: #define A5XX_CP_RB_BASE_HI 0x801 55: #define A5XX_CP_RB_CNTL 0x802 --- FILE: \a6xx_reg.h | HITS: 11 --- MATCH LINES: 25 13: #define A6XX_INT_ATB_ASYNCFIFO_OVERFLOW 6 14: #define A6XX_INT_RBBM_GPC_ERROR 7 15: #define A6XX_INT_CP_SW 8 16: #define A6XX_INT_CP_HW_ERROR 9 17: #define A6XX_INT_CP_CCU_FLUSH_DEPTH_TS 10 18: #define A6XX_INT_CP_CCU_FLUSH_COLOR_TS 11 19: #define A6XX_INT_CP_CCU_RESOLVE_TS 12 20: #define A6XX_INT_CP_IB2 13 21: #define A6XX_INT_CP_IB1 14 22: #define A6XX_INT_CP_RB 15 23: #define A6XX_INT_CP_RB_DONE_TS 17 24: #define A6XX_INT_CP_WT_DONE_TS 18 25: #define A6XX_INT_CP_CACHE_FLUSH_TS 20 26: #define A6XX_INT_RBBM_ATB_BUS_OVERFLOW 22 27: #define A6XX_INT_RBBM_HANG_DETECT 23 28: #define A6XX_INT_UCHE_OOB_ACCESS 24 29: #define A6XX_INT_UCHE_TRAP_INTR 25 30: #define A6XX_INT_DEBBUS_INTR_0 26 31: #define A6XX_INT_DEBBUS_INTR_1 27 32: #define A6XX_INT_TSB_WRITE_ERROR 28 33: #define A6XX_INT_ISDB_CPU_IRQ 30 34: #define A6XX_INT_ISDB_UNDER_DEBUG 31 35: 36: /* CP Interrupt bits */ 37: #define A6XX_CP_OPCODE_ERROR 0 38: #define A6XX_CP_UCODE_ERROR 1 39: #define A6XX_CP_HW_FAULT_ERROR 2 40: #define A6XX_CP_REGISTER_PROTECTION_ERROR 4 41: #define A6XX_CP_AHB_ERROR 5 42: #define A6XX_CP_VSD_PARITY_ERROR 6 43: #define A6XX_CP_ILLEGAL_INSTR_ERROR 7 44: 45: /* CP registers */ 46: #define A6XX_CP_RB_BASE 0x800 47: #define A6XX_CP_RB_BASE_HI 0x801 48: #define A6XX_CP_RB_CNTL 0x802 49: #define A6XX_CP_RB_RPTR_ADDR_LO 0x804 MATCH LINES: 1107, 1108, 1109, 1122, 1123, 1124, 1154, 1155, 1156, 1157 1095: #define A6XX_GPU_GMU_CX_GMU_CX_FALNEXT_INTF 0x1F8F1 1096: 1097: #define A6XX_GMU_AO_INTERRUPT_EN 0x23B03 1098: #define A6XX_GMU_AO_HOST_INTERRUPT_CLR 0x23B04 1099: #define A6XX_GMU_AO_HOST_INTERRUPT_STATUS 0x23B05 1100: #define A6XX_GMU_AO_HOST_INTERRUPT_MASK 0x23B06 1101: #define A6XX_GPU_GMU_AO_GMU_CGC_MODE_CNTL 0x23B09 1102: #define A6XX_GPU_GMU_AO_GMU_CGC_DELAY_CNTL 0x23B0A 1103: #define A6XX_GPU_GMU_AO_GMU_CGC_HYST_CNTL 0x23B0B 1104: #define A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS 0x23B0C 1105: #define A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS2 0x23B0D 1106: #define A6XX_GPU_GMU_AO_GPU_CX_BUSY_MASK 0x23B0E 1107: #define A6XX_GMU_AO_AHB_FENCE_CTRL 0x23B10 1108: #define A6XX_GMU_AHB_FENCE_STATUS 0x23B13 1109: #define A6XX_GMU_AHB_FENCE_STATUS_CLR 0x23B14 1110: #define A6XX_GMU_RBBM_INT_UNMASKED_STATUS 0x23B15 1111: #define A6XX_GMU_AO_SPARE_CNTL 0x23B16 1112: 1113: /* RGMU GLM registers */ 1114: #define A6XX_GMU_AO_RGMU_GLM_SLEEP_CTRL 0x23B80 1115: #define A6XX_GMU_AO_RGMU_GLM_SLEEP_STATUS 0x23B81 1116: #define A6XX_GMU_AO_RGMU_GLM_HW_CRC_DISABLE 0x23B82 1117: 1118: /* GMU RSC control registers */ 1119: #define A6XX_GMU_RSCC_CONTROL_REQ 0x23B07 1120: #define A6XX_GMU_RSCC_CONTROL_ACK 0x23B08 1121: 1122: /* FENCE control registers */ 1123: #define A6XX_GMU_AHB_FENCE_RANGE_0 0x23B11 1124: #define A6XX_GMU_AHB_FENCE_RANGE_1 0x23B12 1125: 1126: /* GMU countables */ 1127: #define A6XX_GMU_CM3_BUSY_CYCLES 0 1128: 1129: /* GPUCC registers */ 1130: #define A6XX_GPU_CC_GX_GDSCR 0x24403 1131: #define A6XX_GPU_CC_GX_DOMAIN_MISC 0x24542 1132: #define A6XX_GPU_CC_GX_DOMAIN_MISC3 0x24563 1133: #define A6XX_GPU_CC_CX_CFG_GDSCR 0x2441C 1134: 1135: /* GPUCC offsets are different for A662 */ 1136: #define A662_GPU_CC_GX_GDSCR 0x26417 1137: #define A662_GPU_CC_GX_DOMAIN_MISC3 0x26541 1138: #define A662_GPU_CC_CX_CFG_GDSCR 0x26443 1139: 1140: /* GPUCC offsets are different for A622 */ 1141: #define A622_GPU_CC_CX_CFG_GDSCR 0x26445 1142: 1143: /* GPU CPR registers */ 1144: #define A6XX_GPU_CPR_FSM_CTL 0x26801 1145: 1146: /* GPU RSC sequencer registers */ 1147: #define A6XX_GPU_RSCC_RSC_STATUS0_DRV0 0x00004 1148: #define A6XX_RSCC_PDC_SEQ_START_ADDR 0x00008 1149: #define A6XX_RSCC_PDC_MATCH_VALUE_LO 0x00009 1150: #define A6XX_RSCC_PDC_MATCH_VALUE_HI 0x0000A 1151: #define A6XX_RSCC_PDC_SLAVE_ID_DRV0 0x0000B 1152: #define A6XX_RSCC_HIDDEN_TCS_CMD0_ADDR 0x0000D 1153: #define A6XX_RSCC_HIDDEN_TCS_CMD0_DATA 0x0000E 1154: #define A6XX_RSCC_TIMESTAMP_UNIT0_TIMESTAMP_L_DRV0 0x00082 1155: #define A6XX_RSCC_TIMESTAMP_UNIT0_TIMESTAMP_H_DRV0 0x00083 1156: #define A6XX_RSCC_TIMESTAMP_UNIT1_EN_DRV0 0x00089 1157: #define A6XX_RSCC_TIMESTAMP_UNIT1_OUTPUT_DRV0 0x0008C 1158: #define A6XX_RSCC_OVERRIDE_START_ADDR 0x00100 1159: #define A6XX_RSCC_SEQ_BUSY_DRV0 0x00101 1160: #define A6XX_RSCC_SEQ_MEM_0_DRV0 0x00180 1161: #define A6XX_RSCC_TCS0_DRV0_STATUS 0x00346 1162: #define A6XX_RSCC_TCS1_DRV0_STATUS 0x003EE 1163: #define A6XX_RSCC_TCS2_DRV0_STATUS 0x00496 1164: #define A6XX_RSCC_TCS3_DRV0_STATUS 0x0053E 1165: #define A6XX_RSCC_TCS4_DRV0_STATUS 0x005E6 1166: #define A6XX_RSCC_TCS5_DRV0_STATUS 0x0068E 1167: #define A6XX_RSCC_TCS6_DRV0_STATUS 0x00736 1168: #define A6XX_RSCC_TCS7_DRV0_STATUS 0x007DE 1169: #define A6XX_RSCC_TCS8_DRV0_STATUS 0x00886 1170: #define A6XX_RSCC_TCS9_DRV0_STATUS 0x0092E 1171: 1172: /* GPU RSC sequencer offsets are different for A622 */ 1173: #define A622_RSCC_SEQ_MEM_0_DRV0 0x00154 1174: #define A622_RSCC_TCS0_DRV0_STATUS 0x0034a 1175: #define A622_RSCC_TCS1_DRV0_STATUS 0x003f2 1176: #define A622_RSCC_TCS2_DRV0_STATUS 0x0049a 1177: #define A622_RSCC_TCS3_DRV0_STATUS 0x00542 1178: #define A622_RSCC_TCS4_DRV0_STATUS 0x005ea 1179: #define A622_RSCC_TCS5_DRV0_STATUS 0x00692 1180: #define A622_RSCC_TCS6_DRV0_STATUS 0x0073a 1181: #define A622_RSCC_TCS7_DRV0_STATUS 0x007e2 --- FILE: \adreno-gpulist.h | HITS: 12 --- MATCH LINES: 2708 2696: { GEN7_CP_PROTECT_REG + 47, 0x27c02, 0x27c02, 1 }, 2697: { 0 }, 2698: }; 2699: 2700: static const struct adreno_gen7_core adreno_gpu_core_gen7_9_0 = { 2701: .base = { 2702: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_9_0, 2703: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2704: .compatible = "qcom,adreno-gpu-gen7-9-0", 2705: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_AQE | 2706: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_IFPC | 2707: ADRENO_L3_VOTE | ADRENO_BCL | ADRENO_DMS | 2708: ADRENO_HW_FENCE | ADRENO_PREEMPTION | ADRENO_ACD | 2709: ADRENO_GMU_WARMBOOT | ADRENO_GMU_AB, 2710: .gpudev = &adreno_gen7_9_0_hwsched_gpudev.base, 2711: .perfcounters = &adreno_gen7_9_0_perfcounters, 2712: .uche_gmem_alignment = SZ_16M, 2713: .gmem_size = 3 * SZ_1M, 2714: .bus_width = 32, 2715: .snapshot_size = SZ_8M, 2716: .num_ddr_channels = 4, 2717: .highest_bank_bit = 16, 2718: }, 2719: .aqefw_name = "gen70900_aqe.fw", 2720: .sqefw_name = "gen70900_sqe.fw", 2721: .gmufw_name = "gmu_gen70900.bin", 2722: .zap_name = "gen70900_zap.mbn", 2723: .ao_hwcg = gen7_9_0_ao_hwcg_regs, 2724: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs), 2725: .gbif = gen7_2_0_gbif_cx_regs, 2726: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs), 2727: .hang_detect_cycles = 0xcfffff, 2728: .protected_regs = gen7_9_0_protected_regs, 2729: .gmu_hub_clk_freq = 200000000, 2730: .gen7_snapshot_block_list = &gen7_9_0_snapshot_block_list, 2731: .bcl_data = 1, 2732: .acv_perfmode_vote = BIT(2), MATCH LINES: 2747 2735: .preempt_level = 1, 2736: .fast_bus_hint = true, 2737: }; 2738: 2739: static const struct adreno_gen7_core adreno_gpu_core_gen7_9_1 = { 2740: .base = { 2741: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_9_1, 2742: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2743: .compatible = "qcom,adreno-gpu-gen7-9-1", 2744: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_AQE | 2745: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_IFPC | 2746: ADRENO_L3_VOTE | ADRENO_BCL | ADRENO_DMS | 2747: ADRENO_HW_FENCE | ADRENO_PREEMPTION | ADRENO_ACD | 2748: ADRENO_GMU_WARMBOOT | ADRENO_GMU_AB, 2749: .gpudev = &adreno_gen7_9_0_hwsched_gpudev.base, 2750: .perfcounters = &adreno_gen7_9_0_perfcounters, 2751: .uche_gmem_alignment = SZ_16M, 2752: .gmem_size = 3 * SZ_1M, 2753: .bus_width = 32, 2754: .snapshot_size = SZ_8M, 2755: .num_ddr_channels = 4, 2756: .highest_bank_bit = 16, 2757: }, 2758: .aqefw_name = "gen70900_aqe.fw", 2759: .sqefw_name = "gen70900_sqe.fw", 2760: .gmufw_name = "gmu_gen70900.bin", 2761: .zap_name = "gen70900_zap.mbn", 2762: .ao_hwcg = gen7_9_0_ao_hwcg_regs, 2763: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs), 2764: .gbif = gen7_2_0_gbif_cx_regs, 2765: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs), 2766: .hang_detect_cycles = 0xcfffff, 2767: .protected_regs = gen7_9_0_protected_regs, 2768: .gmu_hub_clk_freq = 200000000, 2769: .gen7_snapshot_block_list = &gen7_9_0_snapshot_block_list, 2770: .bcl_data = 1, 2771: .acv_perfmode_vote = BIT(2), MATCH LINES: 3265 3253: }, 3254: }, 3255: }; 3256: 3257: static const struct adreno_gen8_core adreno_gpu_core_gen8_0_0 = { 3258: .base = { 3259: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_0_0, 3260: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3261: .compatible = "qcom,adreno-gpu-gen8-0-0", 3262: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 3263: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_AQE | 3264: ADRENO_GMU_WARMBOOT | ADRENO_L3_VOTE | ADRENO_BCL | 3265: ADRENO_IFPC | ADRENO_HW_FENCE | ADRENO_PREEMPTION | 3266: ADRENO_ACD | ADRENO_CLX | ADRENO_GMU_THERMAL_MITIGATION | 3267: ADRENO_GMU_AB, 3268: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3269: .perfcounters = &adreno_gen8_perfcounters, 3270: .uche_gmem_alignment = SZ_64M, 3271: .gmem_size = 12 * SZ_1M, 3272: .bus_width = 32, 3273: .snapshot_size = SZ_8M, 3274: .num_ddr_channels = 4, 3275: .highest_bank_bit = 16, 3276: }, 3277: .aqefw_name = "gen80000_aqe.fw", 3278: .sqefw_name = "gen80000_sqe.fw", 3279: .gmufw_name = "gen80000_gmu.bin", 3280: .zap_name = "gen80000_zap.mbn", 3281: .ao_hwcg = gen8_ao_hwcg_regs, 3282: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs), 3283: .gbif = gen8_0_0_gbif_cx_regs, 3284: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 3285: .hang_detect_cycles = 0xcfffff, 3286: .protected_regs = gen8_0_0_protected_regs, 3287: .nonctxt_regs = gen8_0_0_nonctxt_regs, 3288: .gmu_hub_clk_freq = 200000000, 3289: .gen8_snapshot_block_list = &gen8_0_0_snapshot_block_list, MATCH LINES: 3309 3297: .therm_cfg = &therm_mit_cfg_8_0_0, 3298: .clx_tbl = &gen8_0_0_clx_table, 3299: }; 3300: 3301: static const struct adreno_gen8_core adreno_gpu_core_gen8_0_1 = { 3302: .base = { 3303: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_0_1, 3304: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3305: .compatible = "qcom,adreno-gpu-gen8-0-1", 3306: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 3307: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_AQE | 3308: ADRENO_GMU_WARMBOOT | ADRENO_L3_VOTE | ADRENO_BCL | 3309: ADRENO_IFPC | ADRENO_HW_FENCE | ADRENO_PREEMPTION | 3310: ADRENO_ACD | ADRENO_CLX | ADRENO_GMU_THERMAL_MITIGATION | 3311: ADRENO_GMU_AB, 3312: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION | 3313: ADRENO_IFPC | ADRENO_AQE | ADRENO_CONTENT_PROTECTION, 3314: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3315: .perfcounters = &adreno_gen8_perfcounters, 3316: .uche_gmem_alignment = SZ_64M, 3317: .gmem_size = 12 * SZ_1M, 3318: .bus_width = 32, 3319: .snapshot_size = SZ_8M, 3320: .num_ddr_channels = 4, 3321: .highest_bank_bit = 16, 3322: .chipid = 0x44050001, 3323: .speedbins = KGSL_SPEEDBINS( 3324: { 0, 0 }, 3325: { 252, 1 }, 3326: { 242, 2 }, 3327: { 232, 3 }, 3328: { 221, 4 }, 3329: { 190, 5 }, 3330: ), 3331: .ubwc_mode = 5, 3332: .mal = 32, 3333: .gpu_model = "Adreno830", MATCH LINES: 3619 3607: 3608: /* Set the BCL throttle levels to 62/75/83 percent */ 3609: #define GEN8_2_X_BCL_DATA ((62 << 15) | (75 << 8) | (83 << 1) | 0x1) 3610: 3611: static const struct adreno_gen8_core adreno_gpu_core_gen8_2_0 = { 3612: .base = { 3613: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_2_0, 3614: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3615: .compatible = "qcom,adreno-gpu-gen8-2-0", 3616: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 3617: ADRENO_PREEMPTION | ADRENO_LPAC | ADRENO_AQE | 3618: ADRENO_GMU_WARMBOOT | ADRENO_IFPC | ADRENO_CONTENT_PROTECTION | 3619: ADRENO_HW_FENCE | ADRENO_BCL | ADRENO_ACD | ADRENO_GMU_BASED_DCVS | 3620: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_CLX | ADRENO_DEFER_GMEM_ALLOC | 3621: ADRENO_GMU_MINBW | ADRENO_DCVS_PROFILE | ADRENO_TSENSE_DYNAMIC_PERIOD | 3622: ADRENO_GMU_AB, 3623: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3624: .perfcounters = &adreno_gen8_2_x_perfcounters, 3625: .uche_gmem_alignment = SZ_64M, 3626: .gmem_size = 18 * SZ_1M, 3627: .bus_width = 32, 3628: .snapshot_size = SZ_8M, 3629: .num_ddr_channels = 4, 3630: .highest_bank_bit = 16, 3631: }, 3632: .aqefw_name = "gen80200_aqe.fw", 3633: .sqefw_name = "gen80200_sqe.fw", 3634: .gmufw_name = "gen80200_gmu.bin", 3635: .zap_name = "gen80200_zap.mbn", 3636: .ao_hwcg = gen8_2_0_ao_hwcg_regs, 3637: .ao_hwcg_count = ARRAY_SIZE(gen8_2_0_ao_hwcg_regs), 3638: .gbif = gen8_0_0_gbif_cx_regs, 3639: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 3640: .hang_detect_cycles = 0xcfffff, 3641: .protected_regs = gen8_2_0_protected_regs, 3642: .nonctxt_regs = gen8_2_0_nonctxt_regs, 3643: .gmu_hub_clk_freq = 150000000, MATCH LINES: 3665 3653: .preempt_level = 1, 3654: .clx_tbl = &gen8_2_0_clx_table, 3655: }; 3656: 3657: static const struct adreno_gen8_core adreno_gpu_core_gen8_2_1 = { 3658: .base = { 3659: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_2_1, 3660: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3661: .compatible = "qcom,adreno-gpu-gen8-2-1", 3662: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 3663: ADRENO_PREEMPTION | ADRENO_LPAC | ADRENO_AQE | 3664: ADRENO_GMU_WARMBOOT | ADRENO_IFPC | ADRENO_CONTENT_PROTECTION | 3665: ADRENO_HW_FENCE | ADRENO_BCL | ADRENO_ACD | ADRENO_GMU_BASED_DCVS | 3666: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_CLX | ADRENO_DEFER_GMEM_ALLOC | 3667: ADRENO_GMU_MINBW | ADRENO_DCVS_PROFILE | ADRENO_TSENSE_DYNAMIC_PERIOD | 3668: ADRENO_GMU_AB, 3669: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION | 3670: ADRENO_IFPC | ADRENO_AQE | ADRENO_CONTENT_PROTECTION, 3671: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3672: .perfcounters = &adreno_gen8_2_x_perfcounters, 3673: .uche_gmem_alignment = SZ_64M, 3674: .gmem_size = 18 * SZ_1M, 3675: .bus_width = 32, 3676: .snapshot_size = SZ_8M, 3677: .num_ddr_channels = 4, 3678: .highest_bank_bit = 16, 3679: .chipid = 0x44050a01, 3680: .speedbins = KGSL_SPEEDBINS( 3681: { 0, 0 }, 3682: { 273, 1 }, 3683: { 252, 2 }, 3684: { 221, 3 }, 3685: ), 3686: .ubwc_mode = 6, 3687: .mal = 32, 3688: .gpu_model = "Adreno840", 3689: }, MATCH LINES: 3877 3865: .noc_timeout_us = 3410, /* 3.41 msec */ 3866: .ctxt_record_size = (23088 * SZ_1K), 3867: .preempt_level = 1, 3868: }; 3869: 3870: static const struct adreno_gen8_core adreno_gpu_core_gen8_5_0 = { 3871: .base = { 3872: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_5_0, 3873: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3874: .compatible = "qcom,adreno-gpu-gen8-5-0", 3875: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION | 3876: ADRENO_LPAC | ADRENO_AQE | ADRENO_GMU_WARMBOOT | ADRENO_IFPC | 3877: ADRENO_CONTENT_PROTECTION | ADRENO_HW_FENCE | ADRENO_BCL | 3878: ADRENO_GMU_AB | ADRENO_GMU_BASED_DCVS | ADRENO_GMU_THERMAL_MITIGATION | 3879: ADRENO_DEFER_GMEM_ALLOC | ADRENO_GMU_MINBW | 3880: ADRENO_TSENSE_DYNAMIC_PERIOD | ADRENO_DCVS_PROFILE, 3881: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3882: .perfcounters = &adreno_gen8_2_x_perfcounters, 3883: .uche_gmem_alignment = SZ_64M, 3884: .gmem_size = 18 * SZ_1M, 3885: .bus_width = 32, 3886: .snapshot_size = SZ_8M, 3887: .num_ddr_channels = 4, 3888: .highest_bank_bit = 16, 3889: }, 3890: .aqefw_name = "gen80200_aqe.fw", 3891: .sqefw_name = "gen80200_sqe.fw", 3892: .gmufw_name = "gen80200_gmu.bin", 3893: .zap_name = "gen80200_zap.mbn", 3894: .ao_hwcg = gen8_2_0_ao_hwcg_regs, 3895: .ao_hwcg_count = ARRAY_SIZE(gen8_2_0_ao_hwcg_regs), 3896: .gbif = gen8_0_0_gbif_cx_regs, 3897: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 3898: .hang_detect_cycles = 0xcfffff, 3899: .protected_regs = gen8_2_0_protected_regs, 3900: .nonctxt_regs = gen8_2_0_nonctxt_regs, 3901: .gmu_hub_clk_freq = 150000000, MATCH LINES: 3992 3980: static const u32 gen8_4_0_gbif_client_qos_values[KGSL_PRIORITY_MAX_RB_LEVELS] = { 3981: 0x33233323, 3982: }; 3983: 3984: static const struct adreno_gen8_core adreno_gpu_core_gen8_4_0 = { 3985: .base = { 3986: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_4_0, 3987: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 3988: .compatible = "qcom,adreno-gpu-gen8-4-0", 3989: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 3990: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_AQE | 3991: ADRENO_GMU_WARMBOOT | ADRENO_L3_VOTE | ADRENO_IFPC | 3992: ADRENO_BCL | ADRENO_ACD | ADRENO_HW_FENCE | 3993: ADRENO_PREEMPTION | ADRENO_GMU_AB, 3994: .gpudev = &adreno_gen8_hwsched_gpudev.base, 3995: .perfcounters = &adreno_gen8_perfcounters, 3996: .uche_gmem_alignment = SZ_64M, 3997: .gmem_size = 12 * SZ_1M, 3998: .bus_width = 32, 3999: .snapshot_size = SZ_8M, 4000: .num_ddr_channels = 4, 4001: .highest_bank_bit = 16, 4002: }, 4003: .aqefw_name = "gen80000_aqe.fw", 4004: .sqefw_name = "gen80000_sqe.fw", 4005: .gmufw_name = "gen80000_gmu.bin", 4006: .zap_name = "gen80000_zap.mbn", 4007: .ao_hwcg = gen8_ao_hwcg_regs, 4008: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs), 4009: .gbif = gen8_0_0_gbif_cx_regs, 4010: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 4011: .hang_detect_cycles = 0xcfffff, 4012: .protected_regs = gen8_0_0_protected_regs, 4013: .nonctxt_regs = gen8_4_0_nonctxt_regs, 4014: .gmu_hub_clk_freq = 200000000, 4015: .gen8_snapshot_block_list = &gen8_0_0_snapshot_block_list, 4016: .qos_value = gen8_4_0_gbif_client_qos_values, MATCH LINES: 4232 4220: .preempt_level = 1, 4221: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 4222: .bcl_data = 1, 4223: }; 4224: 4225: static const struct adreno_gen8_core adreno_gpu_core_gen8_8_0 = { 4226: .base = { 4227: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_8_0, 4228: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 4229: .compatible = "qcom,adreno-gpu-gen8-8-0", 4230: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | 4231: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | ADRENO_PREEMPTION | 4232: ADRENO_HW_FENCE | ADRENO_BCL | ADRENO_GMU_AB, 4233: .gpudev = &adreno_gen8_hwsched_gpudev.base, 4234: .perfcounters = &adreno_gen8_perfcounters, 4235: .uche_gmem_alignment = SZ_64M, 4236: .gmem_size = (SZ_512K + SZ_64K), 4237: .bus_width = 32, 4238: .snapshot_size = SZ_8M, 4239: .num_ddr_channels = 1, 4240: .highest_bank_bit = 14, 4241: }, 4242: .sqefw_name = "gen80300_sqe.fw", 4243: .gmufw_name = "gen80800_gmu.bin", 4244: .zap_name = "gen80300_zap.mbn", 4245: .ao_hwcg = gen8_ao_hwcg_regs, 4246: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs), 4247: .gbif = gen8_8_0_gbif_cx_regs, 4248: .gbif_count = ARRAY_SIZE(gen8_8_0_gbif_cx_regs), 4249: .hang_detect_cycles = 0xcfffff, 4250: .protected_regs = gen8_0_0_protected_regs, /* Reuse the protected regs list from Gen8_0_0 */ 4251: .nonctxt_regs = gen8_3_0_nonctxt_regs, 4252: .gmu_hub_clk_freq = 200000000, 4253: .gen8_snapshot_block_list = &gen8_3_0_snapshot_block_list, 4254: .ctxt_record_size = (4558 * SZ_1K), 4255: .preempt_level = 1, 4256: .noc_timeout_us = 3410, /* 3.41 msec */ MATCH LINES: 4329 4317: 4318: extern const struct gen8_snapshot_block_list gen8_9_0_snapshot_block_list; 4319: 4320: static const struct adreno_gen8_core adreno_gpu_core_gen8_9_0 = { 4321: .base = { 4322: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_9_0, 4323: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 4324: .compatible = "qcom,adreno-gpu-gen8-9-0", 4325: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_LPAC | 4326: ADRENO_GMU_WARMBOOT | ADRENO_AQE | ADRENO_IFPC | 4327: ADRENO_CONTENT_PROTECTION | ADRENO_GMU_BASED_DCVS | 4328: ADRENO_DEFER_GMEM_ALLOC | ADRENO_PREEMPTION | ADRENO_GMU_AB | 4329: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_HW_FENCE | 4330: ADRENO_DCVS_PROFILE | ADRENO_GMU_MINBW | 4331: ADRENO_BCL | ADRENO_ACD, 4332: .gpudev = &adreno_gen8_hwsched_gpudev.base, 4333: .perfcounters = &adreno_gen8_perfcounters, 4334: .uche_gmem_alignment = SZ_64M, 4335: .gmem_size = 2432 * SZ_1K, 4336: .bus_width = 32, 4337: .snapshot_size = SZ_8M, 4338: .num_ddr_channels = 4, 4339: .highest_bank_bit = 16, 4340: }, 4341: .aqefw_name = "gen80900_aqe.fw", 4342: .sqefw_name = "gen80900_sqe.fw", 4343: .gmufw_name = "gen80900_gmu.bin", 4344: .zap_name = "gen80900_zap.mbn", 4345: .ao_hwcg = gen8_2_0_ao_hwcg_regs, 4346: .ao_hwcg_count = ARRAY_SIZE(gen8_2_0_ao_hwcg_regs), 4347: .gbif = gen8_0_0_gbif_cx_regs, 4348: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs), 4349: .hang_detect_cycles = 0xcfffff, 4350: .protected_regs = gen8_2_0_protected_regs, 4351: .nonctxt_regs = gen8_9_0_nonctxt_regs, 4352: .gmu_hub_clk_freq = 200000000, 4353: .gen8_snapshot_block_list = &gen8_9_0_snapshot_block_list, MATCH LINES: 4868 4856: }; 4857: 4858: static const struct adreno_gen8_core adreno_gpu_core_gen8_11_1 = { 4859: .base = { 4860: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_11_1, 4861: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 4862: .compatible = "qcom,adreno-gpu-gen8-11-1", 4863: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_LPAC | ADRENO_PREEMPTION | 4864: ADRENO_GMU_WARMBOOT | ADRENO_GMU_BASED_DCVS | ADRENO_CLX | 4865: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_AQE | ADRENO_CONTENT_PROTECTION | 4866: ADRENO_BCL | ADRENO_DCVS_PROFILE | ADRENO_IFPC | ADRENO_GMU_MINBW | 4867: ADRENO_DEFER_GMEM_ALLOC | ADRENO_GMU_FAST_CONTEXT_DESTROY | 4868: ADRENO_ACD | ADRENO_GMU_AB | ADRENO_HW_FENCE, 4869: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION | 4870: ADRENO_IFPC | ADRENO_AQE | ADRENO_CONTENT_PROTECTION | ADRENO_CLX | 4871: ADRENO_GMU_FAST_CONTEXT_DESTROY | ADRENO_GMU_BASED_DCVS | ADRENO_ACD, 4872: .gpudev = &adreno_gen8_hwsched_gpudev.base, 4873: .perfcounters = &adreno_gen8_2_x_perfcounters, 4874: .uche_gmem_alignment = SZ_64M, 4875: .gmem_size = 18 * SZ_1M, 4876: .bus_width = 32, 4877: .snapshot_size = SZ_8M, 4878: .num_ddr_channels = 4, 4879: .highest_bank_bit = 16, 4880: .chipid = 0x44051401, 4881: .speedbins = KGSL_SPEEDBINS( 4882: { 0, 0 }, 4883: { 284, 2 }, 4884: { 216, 3 }, 4885: ), 4886: .ubwc_mode = 7, 4887: .mal = 32, 4888: }, 4889: .aqefw_name = "gen81100_aqe.fw", 4890: .sqefw_name = "gen81100_sqe.fw", 4891: .gmufw_name = "gen81100_gmu.bin", 4892: .zap_name = "gen81100_zap.mbn", MATCH LINES: 5012 5000: }; 5001: 5002: static const struct adreno_gen8_core adreno_gpu_core_gen8_14_0 = { 5003: .base = { 5004: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_14_0, 5005: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 5006: .compatible = "qcom,adreno-gpu-gen8-14-0", 5007: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_LPAC | ADRENO_PREEMPTION | 5008: ADRENO_GMU_WARMBOOT | ADRENO_GMU_BASED_DCVS | 5009: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_AQE | ADRENO_CONTENT_PROTECTION | 5010: ADRENO_DCVS_PROFILE | ADRENO_IFPC | ADRENO_GMU_MINBW | 5011: ADRENO_DEFER_GMEM_ALLOC | ADRENO_GMU_FAST_CONTEXT_DESTROY | 5012: ADRENO_GMU_AB | ADRENO_HW_FENCE | ADRENO_CLX | ADRENO_ACD, 5013: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION | 5014: ADRENO_IFPC | ADRENO_AQE | ADRENO_CONTENT_PROTECTION | ADRENO_CLX | 5015: ADRENO_GMU_FAST_CONTEXT_DESTROY | ADRENO_GMU_BASED_DCVS, 5016: .gpudev = &adreno_gen8_hwsched_gpudev.base, 5017: .perfcounters = &adreno_gen8_2_x_perfcounters, 5018: .uche_gmem_alignment = SZ_64M, 5019: .gmem_size = 12 * SZ_1M, 5020: .bus_width = 32, 5021: .snapshot_size = SZ_8M, 5022: .num_ddr_channels = 4, 5023: .highest_bank_bit = 16, 5024: .chipid = 0x44041400, 5025: .speedbins = KGSL_SPEEDBINS( 5026: { 0, 0 }, 5027: { 216, 0 }, 5028: { 284, 1 }, 5029: ), 5030: .ubwc_mode = 7, 5031: .mal = 32, 5032: }, 5033: .aqefw_name = "gen81100_aqe.fw", 5034: .sqefw_name = "gen81100_sqe.fw", 5035: .gmufw_name = "gen81400_gmu.bin", 5036: .zap_name = "gen81100_zap.mbn", --- FILE: \adreno.c | HITS: 67 --- MATCH LINES: 1776, 1777 1764: case HFI_FEATURE_KPROF: 1765: return "KPROF"; 1766: case HFI_FEATURE_BAIL_OUT_TIMER: 1767: return "BAIL_OUT_TIMER"; 1768: case HFI_FEATURE_GMU_STATS: 1769: return "GMU_STATS"; 1770: case HFI_FEATURE_CLX: 1771: return "CLX"; 1772: case HFI_FEATURE_LSR: 1773: return "LSR"; 1774: case HFI_FEATURE_LPAC: 1775: return "LPAC"; 1776: case HFI_FEATURE_HW_FENCE: 1777: return "HW_FENCE"; 1778: case HFI_FEATURE_PERF_NORETAIN: 1779: return "PERF_NORETAIN"; 1780: case HFI_FEATURE_DMS: 1781: return "DMS"; 1782: case HFI_FEATURE_AQE: 1783: return "AQE"; 1784: case HFI_FEATURE_FAST_CONTEXT_DESTROY: 1785: return "FAST_CONTEXT_DESTROY"; 1786: } 1787: return "unknown"; 1788: } 1789: 1790: static void adreno_regmap_op_preaccess(struct kgsl_regmap_region *region) 1791: { 1792: struct kgsl_device *device = region->priv; 1793: /* 1794: * kgsl panic notifier will be called in atomic context to get 1795: * GPU snapshot. Also panic handler will skip snapshot dumping 1796: * incase GPU is in SLUMBER state. So we can safely ignore the 1797: * kgsl_pre_hwaccess(). 1798: */ 1799: if (!device->snapshot_atomic && !in_interrupt()) 1800: kgsl_pre_hwaccess(device); 1801: } MATCH LINES: 2236, 2252, 2265, 2273 2224: device->pwrctrl.interrupt_num = status; 2225: 2226: device->freq_limiter_intr_num = kgsl_request_irq_optional(pdev, "freq_limiter_irq", 2227: adreno_freq_limiter_irq_handler, device); 2228: 2229: device->freq_limiter_irq_clear = 2230: devm_reset_control_get(&pdev->dev, "freq_limiter_irq_clear"); 2231: 2232: status = kgsl_device_platform_probe(device); 2233: if (status) 2234: goto err_unbind; 2235: 2236: adreno_fence_trace_array_init(device); 2237: 2238: /* Add CX_DBGC block to the regmap*/ 2239: kgsl_regmap_add_region(&device->regmap, pdev, "cx_dbgc", -EINVAL, NULL, NULL); 2240: 2241: res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "aperture"); 2242: if (res) { 2243: device->smmu_aperture_virt = devm_ioremap(dev, res->start, 2244: resource_size(res)); 2245: if (!device->smmu_aperture_virt) 2246: dev_warn(dev, "aperture ioremap failed\n"); 2247: } 2248: 2249: if (kgsl_regmap_add_region(&device->regmap, pdev, "isense_cntl", -EINVAL, NULL, NULL) == 0) 2250: adreno_dev->isense_reg_mapped = true; 2251: 2252: /* Allocate the memstore for storing timestamps and other useful info */ 2253: 2254: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 2255: priv |= KGSL_MEMDESC_PRIVILEGED; 2256: 2257: kgsl_mutex_lock(&device->mutex); 2258: device->memstore = kgsl_allocate_global(device, 2259: KGSL_MEMSTORE_SIZE, 0, 0, priv, "memstore"); 2260: adreno_profile_init(adreno_dev); 2261: kgsl_mutex_unlock(&device->mutex); 2262: 2263: status = PTR_ERR_OR_ZERO(device->memstore); 2264: if (status) { 2265: trace_array_put(device->fence_trace_array); 2266: kgsl_device_platform_remove(device); 2267: goto err_unbind; 2268: } 2269: 2270: /* Initialize UBWC mode and HBB */ 2271: status = adreno_init_ubwc(adreno_dev); 2272: if (status) { 2273: trace_array_put(device->fence_trace_array); 2274: kgsl_device_platform_remove(device); 2275: goto err_unbind; 2276: } 2277: 2278: /* Initialize the snapshot engine */ 2279: size = adreno_dev->gpucore->snapshot_size; 2280: 2281: /* 2282: * Use a default size if one wasn't specified, but print a warning so 2283: * the developer knows to fix it 2284: */ 2285: 2286: if (WARN(!size, "The snapshot size was not specified in the gpucore\n")) 2287: size = SZ_1M; 2288: 2289: kgsl_device_snapshot_probe(device, size); 2290: 2291: adreno_debugfs_init(adreno_dev); 2292: 2293: adreno_dev->perfcounter = false; 2294: 2295: adreno_sysfs_init(adreno_dev); 2296: 2297: if (!ADRENO_FEATURE(adreno_dev, ADRENO_GMU_BASED_DCVS)) MATCH LINES: 2412 2400: /* Return if cleanup happens in adreno_device_probe */ 2401: if (!device->pdev) 2402: return; 2403: 2404: if (device->pdev_loaded) { 2405: srcu_cleanup_notifier_head(&device->nh); 2406: device->pdev_loaded = false; 2407: } 2408: 2409: adreno_dev = ADRENO_DEVICE(device); 2410: gpudev = ADRENO_GPU_DEVICE(adreno_dev); 2411: 2412: trace_array_put(device->fence_trace_array); 2413: 2414: if (gpudev->remove != NULL) 2415: gpudev->remove(adreno_dev); 2416: 2417: #ifdef CONFIG_INPUT 2418: if (adreno_input_handler.private) 2419: input_unregister_handler(&adreno_input_handler); 2420: #endif 2421: 2422: kgsl_qcom_va_md_unregister(device); 2423: adreno_coresight_remove(adreno_dev); 2424: adreno_profile_close(adreno_dev); 2425: 2426: /* Release the system cache slice descriptor */ 2427: if (!IS_ERR_OR_NULL(adreno_dev->gpu_llc_slice)) 2428: llcc_slice_putd(adreno_dev->gpu_llc_slice); 2429: 2430: if (!IS_ERR_OR_NULL(adreno_dev->gpuhtw_llc_slice)) 2431: llcc_slice_putd(adreno_dev->gpuhtw_llc_slice); 2432: 2433: if (!IS_ERR_OR_NULL(adreno_dev->gpumv_llc_slice)) 2434: llcc_slice_putd(adreno_dev->gpumv_llc_slice); 2435: 2436: kgsl_pwrscale_close(device); MATCH LINES: 3128 3116: 3117: static int adreno_prop_device_shadow(struct kgsl_device *device, 3118: struct kgsl_device_getproperty *param) 3119: { 3120: struct kgsl_shadowprop shadowprop = { 0 }; 3121: 3122: if (device->memstore->hostptr) { 3123: /* Pass a dummy address to identify memstore */ 3124: shadowprop.gpuaddr = KGSL_MEMSTORE_TOKEN_ADDRESS; 3125: shadowprop.size = device->memstore->size; 3126: 3127: shadowprop.flags = KGSL_FLAGS_INITIALIZED | 3128: KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS; 3129: } 3130: 3131: return copy_prop(param, &shadowprop, sizeof(shadowprop)); 3132: } 3133: 3134: static int adreno_prop_device_qdss_stm(struct kgsl_device *device, 3135: struct kgsl_device_getproperty *param) 3136: { 3137: struct kgsl_qdss_stm_prop qdssprop = {0}; 3138: 3139: if (!IS_ERR_OR_NULL(device->qdss_desc)) { 3140: qdssprop.gpuaddr = device->qdss_desc->gpuaddr; 3141: qdssprop.size = device->qdss_desc->size; 3142: } 3143: 3144: return copy_prop(param, &qdssprop, sizeof(qdssprop)); 3145: } 3146: 3147: static int adreno_prop_device_qtimer(struct kgsl_device *device, 3148: struct kgsl_device_getproperty *param) 3149: { 3150: struct kgsl_qtimer_prop qtimerprop = {0}; 3151: 3152: if (!IS_ERR_OR_NULL(device->qtimer_desc)) { MATCH LINES: 3904, 3907, 3910, 3912, 3914, 3922, 3931, 3950, 3953, 3954, 3956, 3957, 3963, 3964, 3965, 3967, 3968, 3969, 3973, 3980, 3982, 3983, 3984, 3985, 3987, 3988, 3991, 3992, 3994, 3995, 3996, 4001, 4002, 4004, 4006, 4012, 4013, 4014, 4015, 4016, 4018, 4019, 4022, 4023, 4025, 4026, 4027, 4032, 4035, 4037, 4038 3892: profile_buffer->wall_clock_s = secs; 3893: } else { 3894: profile_buffer->wall_clock_s = time->utime.tv_sec; 3895: profile_buffer->wall_clock_ns = time->utime.tv_nsec; 3896: } 3897: 3898: profile_buffer->gpu_ticks_queued = time->ticks; 3899: 3900: kgsl_memdesc_unmap(&entry->memdesc); 3901: } 3902: 3903: /** 3904: * adreno_waittimestamp - sleep while waiting for the specified timestamp 3905: * @device - pointer to a KGSL device structure 3906: * @context - pointer to the active kgsl context 3907: * @timestamp - GPU timestamp to wait for 3908: * @msecs - amount of time to wait (in milliseconds) 3909: * 3910: * Wait up to 'msecs' milliseconds for the specified timestamp to expire. 3911: */ 3912: static int adreno_waittimestamp(struct kgsl_device *device, 3913: struct kgsl_context *context, 3914: unsigned int timestamp, 3915: unsigned int msecs) 3916: { 3917: int ret; 3918: 3919: if (context == NULL) { 3920: /* If they are doing then complain once */ 3921: dev_WARN_ONCE(device->dev, 1, 3922: "IOCTL_KGSL_DEVICE_WAITTIMESTAMP is deprecated\n"); 3923: return -ENOTTY; 3924: } 3925: 3926: /* Return -ENOENT if the context has been detached */ 3927: if (kgsl_context_detached(context)) 3928: return -ENOENT; 3929: 3930: ret = adreno_drawctxt_wait(ADRENO_DEVICE(device), context, 3931: timestamp, msecs); 3932: 3933: /* If the context got invalidated then return a specific error */ 3934: if (kgsl_context_invalid(context)) 3935: ret = -EDEADLK; 3936: 3937: /* 3938: * Return -EPROTO if the device has faulted since the last time we 3939: * checked. Userspace uses this as a marker for performing post 3940: * fault activities 3941: */ 3942: 3943: if (!ret && test_and_clear_bit(ADRENO_CONTEXT_FAULT, &context->priv)) 3944: ret = -EPROTO; 3945: 3946: return ret; 3947: } 3948: 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: 4051: if (adreno_priv) { 4052: INIT_LIST_HEAD(&adreno_priv->perfcounter_list); 4053: return &adreno_priv->dev_priv; 4054: } 4055: return NULL; 4056: } 4057: 4058: /** 4059: * adreno_device_private_destroy(): Destroy an adreno_device_private structure 4060: * and release the perfcounters held by the kgsl fd. 4061: * @dev_priv: The kgsl device private structure 4062: */ MATCH LINES: 4154, 4163 4142: postlevel, post); 4143: } 4144: 4145: static bool adreno_is_hwcg_on(struct kgsl_device *device) 4146: { 4147: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4148: 4149: return adreno_dev->hwcg_enabled; 4150: } 4151: 4152: static int adreno_queue_cmds(struct kgsl_device_private *dev_priv, 4153: struct kgsl_context *context, struct kgsl_drawobj *drawobj[], 4154: u32 count, u32 *timestamp) 4155: { 4156: struct kgsl_device *device = dev_priv->device; 4157: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4158: 4159: if (WARN_ON(!adreno_dev->dispatch_ops || !adreno_dev->dispatch_ops->queue_cmds)) 4160: return -ENODEV; 4161: 4162: return adreno_dev->dispatch_ops->queue_cmds(dev_priv, context, drawobj, 4163: count, timestamp); 4164: } 4165: 4166: static inline bool _verify_ib(struct kgsl_device_private *dev_priv, 4167: struct kgsl_context *context, struct kgsl_memobj_node *ib) 4168: { 4169: struct kgsl_device *device = dev_priv->device; 4170: struct kgsl_process_private *private = dev_priv->process_priv; 4171: 4172: /* The maximum allowable size for an IB in the CP is 0xFFFFF dwords */ 4173: if (ib->size == 0 || ((ib->size >> 2) > 0xFFFFF)) { 4174: pr_context(device, context, "ctxt %u invalid ib size %lld\n", 4175: context->id, ib->size); 4176: return false; 4177: } 4178: 4179: /* Make sure that the address is in range and dword aligned */ 4180: if (!kgsl_mmu_gpuaddr_in_range(private->pagetable, ib->gpuaddr, 4181: ib->size) || !IS_ALIGNED(ib->gpuaddr, 4)) { 4182: pr_context(device, context, "ctxt %u invalid ib gpuaddr %llX\n", 4183: context->id, ib->gpuaddr); 4184: return false; 4185: } 4186: 4187: return true; MATCH LINES: 4567, 4574, 4575 4555: return (FIELD_PREP(GENMASK(31, 16), vote) | FIELD_PREP(GENMASK(15, 8), 1)); 4556: } 4557: 4558: static void adreno_deassert_gbif_halt(struct kgsl_device *device) 4559: { 4560: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4561: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 4562: 4563: if (gpudev->deassert_gbif_halt) 4564: gpudev->deassert_gbif_halt(adreno_dev); 4565: } 4566: 4567: static void adreno_create_hw_fence(struct kgsl_device *device, struct kgsl_sync_fence *kfence) 4568: { 4569: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4570: 4571: if (WARN_ON(!adreno_dev->dispatch_ops)) 4572: return; 4573: 4574: if (adreno_dev->dispatch_ops->create_hw_fence) 4575: adreno_dev->dispatch_ops->create_hw_fence(adreno_dev, kfence); 4576: } 4577: 4578: u64 adreno_read_cx_timer(struct adreno_device *adreno_dev) 4579: { 4580: /* Check if the CX timer is initialized */ 4581: if (!test_bit(ADRENO_DEVICE_CX_TIMER_INITIALIZED, &adreno_dev->priv)) 4582: return 0; 4583: 4584: /* Since the GPU CX and CPU timers are synchronized return the CPU timer */ 4585: return arch_timer_read_counter(); 4586: } 4587: 4588: static void add_proc_fault_list(struct adreno_device *adreno_dev, 4589: struct kgsl_process_private *proc_priv) 4590: { 4591: int cur_idx = -1; 4592: int new_idx = -1; 4593: int i; 4594: 4595: /* 4596: * Add the process to array of faulting processes. This array is sorted (processes with 4597: * more faults are higher ranked). 4598: */ 4599: write_lock(&adreno_dev->fault_stats_lock); MATCH LINES: 4720, 4721, 4751 4708: return test_bit(ADRENO_DEVICE_FIRST_BOOT_DONE, &adreno_dev->priv); 4709: } 4710: 4711: static const struct kgsl_functable adreno_functable = { 4712: /* Mandatory functions */ 4713: .check_idle = adreno_check_idle, 4714: .first_open = adreno_first_open, 4715: .start = adreno_start, 4716: .stop = adreno_stop, 4717: .last_close = adreno_last_close, 4718: .getproperty = adreno_getproperty, 4719: .getproperty_compat = adreno_getproperty_compat, 4720: .waittimestamp = adreno_waittimestamp, 4721: .readtimestamp = adreno_readtimestamp, 4722: .queue_cmds = adreno_queue_cmds, 4723: .ioctl = adreno_ioctl, 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, 4771: }; 4772: 4773: static int _compare_of(struct device *dev, void *data) 4774: { 4775: return (dev->of_node == data); --- FILE: \adreno.h | HITS: 14 --- MATCH LINES: 171, 172 159: /* Indicates that the specific target is no longer supported */ 160: #define ADRENO_DEPRECATED BIT(10) 161: /* The target supports ringbuffer level APRIV */ 162: #define ADRENO_APRIV BIT(11) 163: /* The GMU supports Battery Current Limiting */ 164: #define ADRENO_BCL BIT(12) 165: /* L3 voting is supported with L3 constraints */ 166: #define ADRENO_L3_VOTE BIT(13) 167: /* LPAC is supported */ 168: #define ADRENO_LPAC BIT(14) 169: /* Late Stage Reprojection (LSR) enablment for GMU */ 170: #define ADRENO_LSR BIT(15) 171: /* GMU and kernel supports hardware fences */ 172: #define ADRENO_HW_FENCE BIT(16) 173: /* Dynamic Mode Switching supported on this target */ 174: #define ADRENO_DMS BIT(17) 175: /* AQE supported on this target */ 176: #define ADRENO_AQE BIT(18) 177: /* Warm Boot supported on this target */ 178: #define ADRENO_GMU_WARMBOOT BIT(19) 179: /* The GPU supports CLX */ 180: #define ADRENO_CLX BIT(20) 181: /* Enable GMU support for GMU based thermal mitigation */ 182: #define ADRENO_GMU_THERMAL_MITIGATION BIT(21) 183: /* GMU Based DCVS */ 184: #define ADRENO_GMU_BASED_DCVS BIT(22) 185: /* RT hint feature for RB0 workloads */ 186: #define ADRENO_RT_HINT BIT(23) 187: /* Defer allocation of preemption record gmem memory when needed */ 188: #define ADRENO_DEFER_GMEM_ALLOC BIT(24) 189: /* The GMU supports MINBW voting */ 190: #define ADRENO_GMU_MINBW BIT(25) 191: /* Enable GMU Based DCVS profile */ 192: #define ADRENO_DCVS_PROFILE BIT(26) 193: /* Enable TSENSE power savings during sleep */ 194: #define ADRENO_TSENSE_DYNAMIC_PERIOD BIT(27) 195: /* Enable GMU Based AB voting */ 196: #define ADRENO_GMU_AB BIT(28) MATCH LINES: 637, 643, 644 625: u32 smmu_aperture_count; 626: }; 627: 628: /** 629: * struct adreno_dispatch_ops - Common functions for dispatcher operations 630: */ 631: struct adreno_dispatch_ops { 632: /* @close: Shut down the dispatcher */ 633: void (*close)(struct adreno_device *adreno_dev); 634: /* @queue_cmds: Queue a command on the context */ 635: int (*queue_cmds)(struct kgsl_device_private *dev_priv, 636: struct kgsl_context *context, struct kgsl_drawobj *drawobj[], 637: u32 count, u32 *timestamp); 638: /* @queue_context: Queue a context to be dispatched */ 639: void (*queue_context)(struct adreno_device *adreno_dev, 640: struct adreno_context *drawctxt); 641: int (*setup_context)(struct adreno_device *adreno_dev, 642: struct adreno_context *drawctxt); 643: /* @create_hw_fence: Create a hardware fence */ 644: void (*create_hw_fence)(struct adreno_device *adreno_dev, struct kgsl_sync_fence *kfence); 645: }; 646: 647: /** 648: * struct adreno_fault_proc - Structure to hold data on faulting processes 649: */ 650: struct adreno_fault_proc { 651: /** @comm: Task name of the faulting process */ 652: char comm[TASK_COMM_LEN]; 653: /** @fault_count: Count of the GPU faults from this process */ 654: u32 fault_count; 655: }; 656: 657: #define ADRENO_MAX_FAULTING_PROCS 10 658: 659: /** 660: * struct adreno_device - The mothership structure for all adreno related info 661: * @dev: Reference to struct kgsl_device 662: * @priv: Holds the private flags specific to the adreno_device 663: * @chipid: Chip ID specific to the GPU 664: * @gpucore: Pointer to the adreno_gpu_core structure 665: * @gpmu_cmds_size: Length of gpmu cmd stream 666: * @gpmu_cmds: gpmu cmd stream 667: * @ringbuffers: Array of pointers to adreno_ringbuffers 668: * @num_ringbuffers: Number of ringbuffers for the GPU MATCH LINES: 965, 980 953: * @ADRENO_DEVICE_PWRON_FIXUP - Set if the target requires the shader fixup 954: * after power collapse 955: * @ADRENO_DEVICE_STARTED - Set if the device start sequence is in progress 956: * @ADRENO_DEVICE_FAULT - Set if the device is currently in fault (and shouldn't 957: * send any more commands to the ringbuffer) 958: * @ADRENO_DEVICE_DRAWOBJ_PROFILE - Set if the device supports drawobj 959: * profiling via the ALWAYSON counter 960: * @ADRENO_DEVICE_PREEMPTION - Turn on/off preemption 961: * @ADRENO_DEVICE_SOFT_FAULT_DETECT - Set if soft fault detect is enabled 962: * @ADRENO_DEVICE_GPMU_INITIALIZED - Set if GPMU firmware initialization succeed 963: * @ADRENO_DEVICE_ISDB_ENABLED - Set if the Integrated Shader DeBugger is 964: * attached and enabled 965: * @ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED - Set if a CACHE_FLUSH_TS irq storm 966: * is in progress 967: */ 968: enum adreno_device_flags { 969: ADRENO_DEVICE_PWRON = 0, 970: ADRENO_DEVICE_PWRON_FIXUP = 1, 971: ADRENO_DEVICE_INITIALIZED = 2, 972: ADRENO_DEVICE_STARTED = 5, 973: ADRENO_DEVICE_FAULT = 6, 974: ADRENO_DEVICE_DRAWOBJ_PROFILE = 7, 975: ADRENO_DEVICE_GPU_REGULATOR_ENABLED = 8, 976: ADRENO_DEVICE_PREEMPTION = 9, 977: ADRENO_DEVICE_SOFT_FAULT_DETECT = 10, 978: ADRENO_DEVICE_GPMU_INITIALIZED = 11, 979: ADRENO_DEVICE_ISDB_ENABLED = 12, 980: ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED = 13, 981: /** @ADRENO_DEVICE_DMS: Set if DMS is enabled */ 982: ADRENO_DEVICE_DMS = 14, 983: /** @ADRENO_DEVICE_GMU_AB: Set if AB vote via GMU is enabled */ 984: ADRENO_DEVICE_GMU_AB = 15, 985: /** @ADRENO_DEVICE_CX_TIMER_INITIALIZED: Set if the CX timer is initialized */ 986: ADRENO_DEVICE_CX_TIMER_INITIALIZED = 17, 987: /** @ADRENO_DEVICE_RESET_RECOVERY: Set if the ADRENO device under goes reset recovery */ 988: ADRENO_DEVICE_RESET_RECOVERY = 18, 989: /** @ADRENO_DEVICE_FIRST_BOOT_DONE: Set if the ADRENO device first boot is done */ 990: ADRENO_DEVICE_FIRST_BOOT_DONE = 19, 991: /** @ADRENO_DEVICE_FAST_CONTEXT_DESTROY: Set if fast context destroy is enabled on GMU */ 992: ADRENO_DEVICE_FAST_CONTEXT_DESTROY = 20, 993: /** @ADRENO_DEVICE_ALLOW_MALU_WORKLOAD: mALU workload is supported by GMU and GPU */ 994: ADRENO_DEVICE_ALLOW_MALU_WORKLOAD = 21, 995: }; 996: 997: /** 998: * struct adreno_drawobj_profile_entry - a single drawobj entry in the 999: * kernel profiling buffer 1000: * @started: Number of GPU ticks at start of the drawobj 1001: * @retired: Number of GPU ticks at the end of the drawobj 1002: * @ctx_start: CP_ALWAYS_ON_CONTEXT tick at start of the drawobj 1003: * @ctx_end: CP_ALWAYS_ON_CONTEXT tick at end of the drawobj 1004: */ MATCH LINES: 2234, 2237 2222: u32 adreno_gmu_bus_ab_quantize(struct adreno_device *adreno_dev, u32 ab); 2223: 2224: /** 2225: * adreno_check_idle - Make sure device is idle 2226: * @device: Pointer to the kgsl device 2227: * 2228: * This function processes the profiling results and log an error if 2229: * device is not idle 2230: */ 2231: void adreno_check_idle(struct kgsl_device *device); 2232: 2233: /* 2234: * adreno_profile_submit_time - Populate profiling buffer with timestamps 2235: * @time: Container for the statistics 2236: * 2237: * Populate the draw object user profiling buffer with the timestamps 2238: * recored in the adreno_submit_time structure at the time of draw object 2239: * submission. 2240: */ 2241: void adreno_profile_submit_time(struct adreno_submit_time *time); 2242: 2243: void adreno_preemption_timer(struct timer_list *t); 2244: 2245: /** 2246: * adreno_create_profile_buffer - Create a buffer to store profiling data 2247: * @adreno_dev: Adreno GPU device handle 2248: */ 2249: void adreno_create_profile_buffer(struct adreno_device *adreno_dev); 2250: 2251: /** 2252: * adreno_isidle - return true if the hardware is idle 2253: * @adreno_dev: Adreno GPU device handle 2254: * 2255: * Return: True if the hardware is idle 2256: */ 2257: bool adreno_isidle(struct adreno_device *adreno_dev); 2258: 2259: /** 2260: * adreno_allocate_global - Helper function to allocate a global GPU object 2261: * @device: A GPU device handle MATCH LINES: 2290, 2292, 2295, 2297, 2299 2278: return 0; 2279: 2280: *memdesc = kgsl_allocate_global(device, size, padding, flags, priv, name); 2281: return PTR_ERR_OR_ZERO(*memdesc); 2282: } 2283: 2284: static inline void adreno_set_dispatch_ops(struct adreno_device *adreno_dev, 2285: const struct adreno_dispatch_ops *ops) 2286: { 2287: adreno_dev->dispatch_ops = ops; 2288: } 2289: 2290: #ifdef CONFIG_QCOM_KGSL_FENCE_TRACE 2291: /** 2292: * adreno_fence_trace_array_init - Initialize an always on trace array 2293: * @device: A GPU device handle 2294: * 2295: * Register an always-on trace array to for fence timeout debugging 2296: */ 2297: void adreno_fence_trace_array_init(struct kgsl_device *device); 2298: #else 2299: static inline void adreno_fence_trace_array_init(struct kgsl_device *device) {} 2300: #endif 2301: 2302: /* 2303: * adreno_drawobj_set_constraint - Set a power constraint 2304: * @device: Pointer to a KGSL device structure 2305: * @drawobj: Draw object for which constraint is to be set 2306: * 2307: * Set the power constraint if requested by this context 2308: */ 2309: void adreno_drawobj_set_constraint(struct kgsl_device *device, 2310: struct kgsl_drawobj *drawobj); 2311: 2312: /** 2313: * adreno_get_gpu_model - Gets gpu model name from device tree (or) chipid 2314: * @device: A GPU device handle 2315: * 2316: * Return: GPU model name string 2317: */ 2318: const char *adreno_get_gpu_model(struct kgsl_device *device); 2319: 2320: int adreno_verify_cmdobj(struct kgsl_device_private *dev_priv, 2321: struct kgsl_context *context, struct kgsl_drawobj *drawobj[], 2322: uint32_t count); 2323: --- FILE: \adreno_a5xx.c | HITS: 10 --- MATCH LINES: 60 48: #define A530_QFPROM_RAW_PTE_ROW0_MSB 0x134 49: #define A530_QFPROM_RAW_PTE_ROW2_MSB 0x144 50: 51: #define A5XX_INT_MASK \ 52: ((1 << A5XX_INT_RBBM_AHB_ERROR) | \ 53: (1 << A5XX_INT_RBBM_TRANSFER_TIMEOUT) | \ 54: (1 << A5XX_INT_RBBM_ME_MS_TIMEOUT) | \ 55: (1 << A5XX_INT_RBBM_PFP_MS_TIMEOUT) | \ 56: (1 << A5XX_INT_RBBM_ETS_MS_TIMEOUT) | \ 57: (1 << A5XX_INT_RBBM_ATB_ASYNC_OVERFLOW) | \ 58: (1 << A5XX_INT_RBBM_GPC_ERROR) | \ 59: (1 << A5XX_INT_CP_HW_ERROR) | \ 60: (1 << A5XX_INT_CP_CACHE_FLUSH_TS) | \ 61: (1 << A5XX_INT_RBBM_ATB_BUS_OVERFLOW) | \ 62: (1 << A5XX_INT_MISC_HANG_DETECT) | \ 63: (1 << A5XX_INT_UCHE_OOB_ACCESS) | \ 64: (1 << A5XX_INT_UCHE_TRAP_INTR) | \ 65: (1 << A5XX_INT_CP_SW) | \ 66: (1 << A5XX_INT_GPMU_FIRMWARE) | \ 67: (1 << A5XX_INT_GPMU_VOLTAGE_DROOP)) 68: 69: static int a5xx_probe(struct platform_device *pdev, 70: u32 chipid, const struct adreno_gpu_core *gpucore) 71: { 72: struct adreno_device *adreno_dev; 73: struct kgsl_device *device; 74: int ret; 75: 76: adreno_dev = (struct adreno_device *) 77: of_device_get_match_data(&pdev->dev); 78: 79: memset(adreno_dev, 0, sizeof(*adreno_dev)); 80: 81: adreno_dev->gpucore = gpucore; 82: adreno_dev->chipid = chipid; 83: 84: adreno_reg_offset_init(gpucore->gpudev->reg_offsets); MATCH LINES: 2078, 2080, 2083, 2085, 2087, 2101, 2122, 2126 2066: static void a5xx_irq_storm_worker(struct work_struct *work) 2067: { 2068: struct adreno_device *adreno_dev = container_of(work, 2069: struct adreno_device, irq_storm_work); 2070: struct kgsl_device *device = &adreno_dev->dev; 2071: unsigned int status; 2072: 2073: kgsl_mutex_lock(&device->mutex); 2074: 2075: /* Wait for the storm to clear up */ 2076: do { 2077: kgsl_regwrite(device, A5XX_RBBM_INT_CLEAR_CMD, 2078: BIT(A5XX_INT_CP_CACHE_FLUSH_TS)); 2079: kgsl_regread(device, A5XX_RBBM_INT_0_STATUS, &status); 2080: } while (status & BIT(A5XX_INT_CP_CACHE_FLUSH_TS)); 2081: 2082: /* Re-enable the interrupt bit in the mask */ 2083: adreno_dev->irq_mask |= BIT(A5XX_INT_CP_CACHE_FLUSH_TS); 2084: kgsl_regwrite(device, A5XX_RBBM_INT_0_MASK, adreno_dev->irq_mask); 2085: clear_bit(ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED, &adreno_dev->priv); 2086: 2087: dev_warn(device->dev, "Re-enabled A5XX_INT_CP_CACHE_FLUSH_TS\n"); 2088: kgsl_mutex_unlock(&device->mutex); 2089: 2090: /* Reschedule just to make sure everything retires */ 2091: adreno_scheduler_queue(adreno_dev); 2092: } 2093: 2094: static void a5xx_cp_callback(struct adreno_device *adreno_dev, int bit) 2095: { 2096: struct kgsl_device *device = &adreno_dev->dev; 2097: unsigned int cur; 2098: static unsigned int count; 2099: static unsigned int prev; 2100: 2101: if (test_bit(ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED, &adreno_dev->priv)) 2102: return; 2103: 2104: kgsl_sharedmem_readl(device->memstore, &cur, 2105: KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, 2106: ref_wait_ts)); 2107: 2108: /* 2109: * prev holds a previously read value 2110: * from memory. It should be changed by the GPU with every 2111: * interrupt. If the value we know about and the value we just 2112: * read are the same, then we are likely in a storm. 2113: * If this happens twice, disable the interrupt in the mask 2114: * so the dispatcher can take care of the issue. It is then 2115: * up to the dispatcher to re-enable the mask once all work 2116: * is done and the storm has ended. 2117: */ 2118: if (prev == cur) { 2119: count++; 2120: if (count == 2) { 2121: /* disable interrupt from the mask */ 2122: set_bit(ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED, 2123: &adreno_dev->priv); 2124: 2125: adreno_dev->irq_mask &= 2126: ~BIT(A5XX_INT_CP_CACHE_FLUSH_TS); 2127: 2128: kgsl_regwrite(device, A5XX_RBBM_INT_0_MASK, 2129: adreno_dev->irq_mask); 2130: 2131: kgsl_schedule_work(&adreno_dev->irq_storm_work); 2132: 2133: return; 2134: } 2135: } else { 2136: count = 0; 2137: prev = cur; 2138: } 2139: 2140: a5xx_preemption_trigger(adreno_dev); 2141: adreno_scheduler_queue(adreno_dev); 2142: } 2143: 2144: static const char *gpmu_int_msg[32] = { 2145: [FW_INTR_INFO] = "FW_INTR_INFO", 2146: [LLM_ACK_ERR_INTR] = "LLM_ACK_ERR_INTR", 2147: [ISENS_TRIM_ERR_INTR] = "ISENS_TRIM_ERR_INTR", 2148: [ISENS_ERR_INTR] = "ISENS_ERR_INTR", 2149: [ISENS_IDLE_ERR_INTR] = "ISENS_IDLE_ERR_INTR", 2150: [ISENS_PWR_ON_ERR_INTR] = "ISENS_PWR_ON_ERR_INTR", MATCH LINES: 2263 2251: /* 11 - CP_CCU_FLUSH_COLOR_TS */ 2252: ADRENO_IRQ_CALLBACK(NULL), 2253: /* 12 - CP_CCU_RESOLVE_TS */ 2254: ADRENO_IRQ_CALLBACK(NULL), 2255: ADRENO_IRQ_CALLBACK(NULL), /* 13 - CP_IB2_INT */ 2256: ADRENO_IRQ_CALLBACK(NULL), /* 14 - CP_IB1_INT */ 2257: ADRENO_IRQ_CALLBACK(NULL), /* 15 - CP_RB_INT */ 2258: /* 16 - CCP_UNUSED_1 */ 2259: ADRENO_IRQ_CALLBACK(NULL), 2260: ADRENO_IRQ_CALLBACK(NULL), /* 17 - CP_RB_DONE_TS */ 2261: ADRENO_IRQ_CALLBACK(NULL), /* 18 - CP_WT_DONE_TS */ 2262: ADRENO_IRQ_CALLBACK(NULL), /* 19 - UNKNOWN_1 */ 2263: ADRENO_IRQ_CALLBACK(a5xx_cp_callback), /* 20 - CP_CACHE_FLUSH_TS */ 2264: /* 21 - UNUSED_2 */ 2265: ADRENO_IRQ_CALLBACK(NULL), 2266: ADRENO_IRQ_CALLBACK(a5xx_err_callback), /* 22 - RBBM_ATB_BUS_OVERFLOW */ 2267: /* 23 - MISC_HANG_DETECT */ 2268: ADRENO_IRQ_CALLBACK(adreno_hang_int_callback), 2269: ADRENO_IRQ_CALLBACK(a5xx_err_callback), /* 24 - UCHE_OOB_ACCESS */ 2270: ADRENO_IRQ_CALLBACK(a5xx_err_callback), /* 25 - UCHE_TRAP_INTR */ 2271: ADRENO_IRQ_CALLBACK(NULL), /* 26 - DEBBUS_INTR_0 */ 2272: ADRENO_IRQ_CALLBACK(NULL), /* 27 - DEBBUS_INTR_1 */ 2273: ADRENO_IRQ_CALLBACK(a5xx_err_callback), /* 28 - GPMU_VOLTAGE_DROOP */ 2274: ADRENO_IRQ_CALLBACK(a5xx_gpmu_int_callback), /* 29 - GPMU_FIRMWARE */ 2275: ADRENO_IRQ_CALLBACK(NULL), /* 30 - ISDB_CPU_IRQ */ 2276: ADRENO_IRQ_CALLBACK(NULL), /* 31 - ISDB_UNDER_DEBUG */ 2277: }; 2278: 2279: static irqreturn_t a5xx_irq_handler(struct adreno_device *adreno_dev) 2280: { 2281: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2282: irqreturn_t ret; 2283: u32 status; 2284: 2285: kgsl_regread(device, A5XX_RBBM_INT_0_STATUS, &status); 2286: 2287: /* --- FILE: \adreno_a5xx.h | HITS: 2 --- MATCH LINES: 277, 285 265: */ 266: int a5xx_ringbuffer_init(struct adreno_device *adreno_dev); 267: 268: /** 269: * a5xx_ringbuffer_addcmds - Submit a command to the ringbuffer 270: * @adreno_dev: An Adreno GPU handle 271: * @rb: Pointer to the ringbuffer to submit on 272: * @drawctxt: Pointer to the draw context for the submission, or NULL for 273: * internal submissions 274: * @flags: Flags for the submission 275: * @in: Commands to write to the ringbuffer 276: * @dwords: Size of @in (in dwords) 277: * @timestamp: Timestamp for the submission 278: * @time: Optional pointer to a submit time structure 279: * 280: * Submit a command to the ringbuffer. 281: * Return: 0 on success or negative on failure 282: */ 283: int a5xx_ringbuffer_addcmds(struct adreno_device *adreno_dev, 284: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 285: u32 flags, u32 *in, u32 dwords, u32 timestamp, 286: struct adreno_submit_time *time); 287: 288: /** 289: * a5xx_ringbuffer_submitcmd - Submit a user command to the ringbuffer 290: * @adreno_dev: An Adreno GPU handle 291: * @cmdobj: Pointer to a user command object 292: * @flags: Internal submit flags 293: * @time: Optional pointer to a adreno_submit_time container 294: * 295: * Return: 0 on success or negative on failure 296: */ 297: int a5xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 298: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 299: struct adreno_submit_time *time); 300: 301: int a5xx_ringbuffer_submit(struct adreno_ringbuffer *rb, 302: struct adreno_submit_time *time, bool sync); 303: 304: static inline bool a5xx_has_gpmu(struct adreno_device *adreno_dev) 305: { 306: return (adreno_is_a530(adreno_dev) || adreno_is_a540(adreno_dev)); 307: } 308: 309: #ifdef CONFIG_QCOM_KGSL_CORESIGHT --- FILE: \adreno_a5xx_perfcounter.c | HITS: 1 --- MATCH LINES: 98 86: if (ret) 87: return ret; 88: 89: /* 90: * schedule dispatcher to make sure rb[0] is run, because 91: * if the current RB is not rb[0] and gpu is idle then 92: * rb[0] will not get scheduled to run 93: */ 94: if (adreno_dev->cur_rb != rb) 95: adreno_scheduler_queue(adreno_dev); 96: 97: /* wait for the above commands submitted to complete */ 98: ret = adreno_ringbuffer_waittimestamp(rb, rb->timestamp, 99: ADRENO_IDLE_TIMEOUT); 100: 101: if (ret) { 102: /* 103: * If we were woken up because of cancelling rb events 104: * either due to soft reset or adreno_stop, ignore the 105: * error and return 0 here. The perfcounter is already 106: * set up in software and it will be programmed in 107: * hardware when we wake up or come up after soft reset, 108: * by adreno_perfcounter_restore. 109: */ 110: if (ret == -EAGAIN) 111: ret = 0; 112: else 113: dev_err(device->dev, 114: "Perfcounter %s/%u/%u start via commands failed %d\n", 115: group->name, counter, countable, ret); 116: } 117: 118: if (!ret) 119: reg->value = 0; 120: 121: return ret; 122: } --- FILE: \adreno_a5xx_ringbuffer.c | HITS: 34 --- MATCH LINES: 52, 53, 54, 55, 57, 58, 59, 60 40: cmds[11] = lower_32_bits(ttbr0); 41: cmds[12] = upper_32_bits(ttbr0); 42: cmds[13] = id; 43: 44: cmds[14] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 45: cmds[15] = cp_type7_packet(CP_WAIT_FOR_ME, 0); 46: cmds[16] = cp_type4_packet(A5XX_CP_CNTL, 1); 47: cmds[17] = 0; 48: 49: return 18; 50: } 51: 52: #define RB_SOPTIMESTAMP(device, rb) \ 53: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 54: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 55: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 56: 57: #define RB_EOPTIMESTAMP(device, rb) \ 58: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 59: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 60: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 61: 62: int a5xx_ringbuffer_submit(struct adreno_ringbuffer *rb, 63: struct adreno_submit_time *time, bool sync) 64: { 65: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 66: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 67: unsigned long flags; 68: 69: adreno_get_submit_time(adreno_dev, rb, time); 70: adreno_profile_submit_time(time); 71: 72: if (sync) { 73: u32 *cmds = adreno_ringbuffer_allocspace(rb, 3); 74: 75: if (IS_ERR(cmds)) 76: return PTR_ERR(cmds); 77: 78: cmds[0] = cp_type7_packet(CP_WHERE_AM_I, 2); 79: cmds[1] = lower_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id, 80: rptr)); 81: cmds[2] = upper_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id, 82: rptr)); 83: } 84: MATCH LINES: 138, 154, 157, 183, 185, 187, 191, 192, 193 126: return ret; 127: } 128: 129: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 130: a5xx_preemption_init(adreno_dev); 131: return 0; 132: } 133: 134: #define A5XX_SUBMIT_MAX 64 135: 136: int a5xx_ringbuffer_addcmds(struct adreno_device *adreno_dev, 137: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 138: u32 flags, u32 *in, u32 dwords, u32 timestamp, 139: struct adreno_submit_time *time) 140: { 141: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 142: static u32 sequence; 143: u32 size = A5XX_SUBMIT_MAX + dwords; 144: u32 *cmds, index = 0; 145: u64 profile_gpuaddr; 146: u32 profile_dwords; 147: 148: if (adreno_drawctxt_detached(drawctxt)) 149: return -ENOENT; 150: 151: if (adreno_gpu_fault(adreno_dev) != 0) 152: return -EPROTO; 153: 154: rb->timestamp++; 155: 156: if (drawctxt) 157: drawctxt->internal_timestamp = rb->timestamp; 158: 159: cmds = adreno_ringbuffer_allocspace(rb, size); 160: if (IS_ERR(cmds)) 161: return PTR_ERR(cmds); 162: 163: /* Identify the start of a command */ 164: cmds[index++] = cp_type7_packet(CP_NOP, 1); 165: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 166: 167: /* 14 dwords */ 168: index += a5xx_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 169: &cmds[index]); 170: 171: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 172: drawctxt, &profile_dwords); 173: 174: if (profile_gpuaddr) { 175: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 176: cmds[index++] = lower_32_bits(profile_gpuaddr); 177: cmds[index++] = upper_32_bits(profile_gpuaddr); 178: cmds[index++] = profile_dwords; 179: } 180: 181: if (drawctxt) { 182: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 183: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 184: drawctxt)); 185: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 186: drawctxt)); 187: cmds[index++] = timestamp; 188: } 189: 190: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 191: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 192: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); 193: cmds[index++] = rb->timestamp; 194: 195: if (IS_SECURE(flags)) { 196: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 197: cmds[index++] = 1; 198: } 199: 200: if (IS_NOTPROTECTED(flags)) { 201: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1); 202: cmds[index++] = 0; 203: } 204: 205: memcpy(&cmds[index], in, dwords << 2); 206: index += dwords; 207: 208: if (IS_NOTPROTECTED(flags)) { 209: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1); 210: cmds[index++] = 1; 211: } 212: 213: /* 4 dwords */ 214: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev, 215: drawctxt, &profile_dwords); 216: 217: if (profile_gpuaddr) { MATCH LINES: 242, 247, 248, 249, 250, 253, 254, 256, 258, 261, 262, 263, 264 230: * Do a unique memory write from the GPU to assist in early detection of 231: * interrupt storms 232: */ 233: 234: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 235: cmds[index++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 236: KGSL_MEMSTORE_GLOBAL, ref_wait_ts)); 237: cmds[index++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 238: KGSL_MEMSTORE_GLOBAL, ref_wait_ts)); 239: cmds[index++] = ++sequence; 240: 241: /* 242: * If this is an internal command, just write the ringbuffer timestamp, 243: * otherwise, write both 244: */ 245: if (!drawctxt) { 246: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 247: cmds[index++] = CACHE_FLUSH_TS | (1 << 31); 248: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 249: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 250: cmds[index++] = rb->timestamp; 251: } else { 252: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 253: cmds[index++] = CACHE_FLUSH_TS | (1 << 31); 254: cmds[index++] = lower_32_bits(CTXT_EOPTIMESTAMP(device, 255: drawctxt)); 256: cmds[index++] = upper_32_bits(CTXT_EOPTIMESTAMP(device, 257: drawctxt)); 258: cmds[index++] = timestamp; 259: 260: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 261: cmds[index++] = CACHE_FLUSH_TS; 262: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 263: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 264: cmds[index++] = rb->timestamp; 265: } 266: 267: if (IS_WFI(flags)) 268: cmds[index++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 269: 270: if (IS_SECURE(flags)) { 271: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 272: cmds[index++] = 0; 273: } 274: 275: /* 5 dwords */ 276: index += a5xx_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 277: 278: /* Adjust the thing for the number of bytes we actually wrote */ 279: rb->_wptr -= (size - index); 280: 281: a5xx_ringbuffer_submit(rb, time, 282: !adreno_is_preemption_enabled(adreno_dev)); 283: 284: return 0; 285: } 286: 287: static u32 a5xx_get_alwayson_counter(struct adreno_device *adreno_dev, 288: u32 *cmds, u64 gpuaddr) MATCH LINES: 391, 392 379: 380: if (kgsl_context_detached(&drawctxt->base)) 381: return -ENOENT; 382: 383: if (!_kgsl_context_get(&drawctxt->base)) 384: return -ENOENT; 385: 386: trace_adreno_drawctxt_switch(rb, drawctxt); 387: 388: a5xx_rb_context_switch(adreno_dev, rb, drawctxt); 389: 390: /* Release the current drawctxt as soon as the new one is switched */ 391: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active, 392: rb, rb->timestamp); 393: 394: rb->drawctxt_active = drawctxt; 395: return 0; 396: } 397: 398: 399: #define A5XX_USER_PROFILE_IB(dev, rb, cmdobj, cmds, field) \ 400: a5xx_get_user_profiling_ib((dev), (rb), (cmdobj), \ 401: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 402: (cmds)) 403: 404: #define A5XX_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 405: a5xx_get_alwayson_counter((dev), (cmds), \ 406: (dev)->profile_buffer->gpuaddr + \ 407: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 408: field)) 409: 410: #define A5XX_COMMAND_DWORDS 32 411: 412: int a5xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 413: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 414: struct adreno_submit_time *time) 415: { 416: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); MATCH LINES: 520, 524 508: * the upper layers know how to handle it 509: */ 510: if (ret != -ENOSPC && ret != -ENOENT) 511: dev_err(device->dev, 512: "Unable to switch draw context: %d\n", 513: ret); 514: goto done; 515: } 516: 517: adreno_drawobj_set_constraint(device, drawobj); 518: 519: ret = a5xx_ringbuffer_addcmds(adreno_dev, drawctxt->rb, drawctxt, 520: flags, cmds, index, drawobj->timestamp, time); 521: 522: done: 523: trace_kgsl_issueibcmds(device, drawctxt->base.id, numibs, 524: drawobj->timestamp, drawobj->flags, ret, drawctxt->type); 525: 526: kfree(cmds); 527: return ret; 528: } --- FILE: \adreno_a6xx.c | HITS: 19 --- MATCH LINES: 137, 153, 157, 160, 169, 179, 185 125: A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_1, 126: A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_2, 127: A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_3, 128: A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_4, 129: A6XX_UCHE_CMDQ_CONFIG, 130: A6XX_SP_DBG_ECO_CNTL, 131: }; 132: 133: static u32 a615_pwrup_reglist[] = { 134: A6XX_UCHE_GBIF_GX_CONFIG, 135: }; 136: 137: int a6xx_fenced_write(struct adreno_device *adreno_dev, u32 offset, 138: u32 value, u32 mask) 139: { 140: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 141: unsigned int status, i; 142: u64 ts1, ts2; 143: 144: kgsl_regwrite(device, offset, value); 145: 146: if (!gmu_core_isenabled(device)) 147: return 0; 148: 149: ts1 = a6xx_read_alwayson(adreno_dev); 150: for (i = 0; i < GMU_CORE_LONG_WAKEUP_RETRY_LIMIT; i++) { 151: /* 152: * Make sure the previous register write is posted before 153: * checking the fence status 154: */ 155: mb(); 156: 157: kgsl_regread(device, A6XX_GMU_AHB_FENCE_STATUS, &status); 158: 159: /* 160: * If !writedropped0/1, then the write to fenced register 161: * was successful 162: */ 163: if (!(status & mask)) 164: break; 165: 166: /* Wait a small amount of time before trying again */ 167: udelay(GMU_CORE_WAKEUP_DELAY_US); 168: 169: /* Try to write the fenced register again */ 170: kgsl_regwrite(device, offset, value); 171: } 172: 173: if (i < GMU_CORE_SHORT_WAKEUP_RETRY_LIMIT) 174: return 0; 175: 176: if (i == GMU_CORE_LONG_WAKEUP_RETRY_LIMIT) { 177: ts2 = a6xx_read_alwayson(adreno_dev); 178: dev_err(adreno_dev->dev.dev, 179: "Timed out waiting %d usecs to write fenced register 0x%x, timestamps: %llx %llx\n", 180: i * GMU_CORE_WAKEUP_DELAY_US, offset, ts1, ts2); 181: return -ETIMEDOUT; 182: } 183: 184: dev_err(adreno_dev->dev.dev, 185: "Waited %d usecs to write fenced register 0x%x\n", 186: i * GMU_CORE_WAKEUP_DELAY_US, offset); 187: 188: return 0; 189: } 190: 191: static void a6xx_calc_ubwc_config_legacy(struct adreno_device *adreno_dev) 192: { 193: struct adreno_ubwc_props *ubwc_props = &adreno_dev->ubwc_props; 194: 195: switch (adreno_dev->ubwc_mode) { 196: case KGSL_UBWC_1_0: 197: ubwc_props->mode = 1; 198: break; 199: case KGSL_UBWC_2_0: 200: ubwc_props->mode = 0; 201: break; 202: case KGSL_UBWC_3_0: 203: ubwc_props->mode = 0; 204: ubwc_props->amsbc = true; 205: break; 206: case KGSL_UBWC_4_0: 207: ubwc_props->mode = 0; 208: ubwc_props->rgb565_predicator = true; 209: ubwc_props->amsbc = true; MATCH LINES: 1853, 1869, 1873, 1875, 1878, 1886, 1888, 1893, 1895, 1902, 1908 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: 1886: kgsl_regread(device, A6XX_GMU_AO_AHB_FENCE_CTRL, &fence); 1887: 1888: while (fence != 0) { 1889: b = a6xx_read_alwayson(adreno_dev); 1890: 1891: /* Wait for small time before trying again */ 1892: udelay(1); 1893: kgsl_regread(device, A6XX_GMU_AO_AHB_FENCE_CTRL, &fence); 1894: 1895: if (fence_retries == 100 && fence != 0) { 1896: c = a6xx_read_alwayson(adreno_dev); 1897: 1898: kgsl_regread(device, A6XX_GMU_RBBM_INT_UNMASKED_STATUS, 1899: &status); 1900: 1901: dev_crit_ratelimited(device->dev, 1902: "status=0x%x Unmasked status=0x%x Mask=0x%x timestamps: %llx %llx %llx\n", 1903: status & adreno_dev->irq_mask, status, 1904: adreno_dev->irq_mask, a, b, c); 1905: return -ETIMEDOUT; 1906: } 1907: 1908: fence_retries++; 1909: } 1910: 1911: return 0; 1912: } 1913: 1914: static irqreturn_t a6xx_hwsched_irq_handler(struct adreno_device *adreno_dev) 1915: { 1916: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1917: irqreturn_t ret = IRQ_NONE; 1918: u32 status; 1919: 1920: /* 1921: * On A6xx, the GPU can power down once the INT_0_STATUS is read 1922: * below. But there still might be some register reads required 1923: * so force the GMU/GPU into KEEPALIVE mode until done with the ISR. 1924: */ 1925: a6xx_gpu_keepalive(adreno_dev, true); 1926: 1927: kgsl_regread(device, A6XX_RBBM_INT_0_STATUS, &status); 1928: 1929: kgsl_regwrite(device, A6XX_RBBM_INT_CLEAR_CMD, status); 1930: 1931: ret = adreno_irq_callbacks(adreno_dev, a6xx_irq_funcs, status); 1932: MATCH LINES: 1955 1943: { 1944: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1945: irqreturn_t ret = IRQ_NONE; 1946: u32 status; 1947: 1948: /* 1949: * On A6xx, the GPU can power down once the INT_0_STATUS is read 1950: * below. But there still might be some register reads required 1951: * so force the GMU/GPU into KEEPALIVE mode until done with the ISR. 1952: */ 1953: a6xx_gpu_keepalive(adreno_dev, true); 1954: 1955: if (a6xx_irq_poll_fence(adreno_dev)) { 1956: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 1957: goto done; 1958: } 1959: 1960: kgsl_regread(device, A6XX_RBBM_INT_0_STATUS, &status); 1961: 1962: kgsl_regwrite(device, A6XX_RBBM_INT_CLEAR_CMD, status); 1963: 1964: ret = adreno_irq_callbacks(adreno_dev, a6xx_irq_funcs, status); 1965: 1966: trace_kgsl_a5xx_irq_status(adreno_dev, status); 1967: 1968: done: 1969: /* If hard fault, then let snapshot turn off the keepalive */ 1970: if (!(adreno_gpu_fault(adreno_dev) & ADRENO_HARD_FAULT)) 1971: a6xx_gpu_keepalive(adreno_dev, false); 1972: 1973: return ret; 1974: } 1975: 1976: int a6xx_probe_common(struct platform_device *pdev, 1977: struct adreno_device *adreno_dev, u32 chipid, 1978: const struct adreno_gpu_core *gpucore) 1979: { --- FILE: \adreno_a6xx.h | HITS: 4 --- MATCH LINES: 178 166: /* Size of the CP_INIT pm4 stream in dwords */ 167: #define A6XX_CP_INIT_DWORDS 11 168: 169: #define A6XX_INT_MASK \ 170: ((1 << A6XX_INT_CP_AHB_ERROR) | \ 171: (1 << A6XX_INT_ATB_ASYNCFIFO_OVERFLOW) | \ 172: (1 << A6XX_INT_RBBM_GPC_ERROR) | \ 173: (1 << A6XX_INT_CP_SW) | \ 174: (1 << A6XX_INT_CP_HW_ERROR) | \ 175: (1 << A6XX_INT_CP_IB2) | \ 176: (1 << A6XX_INT_CP_IB1) | \ 177: (1 << A6XX_INT_CP_RB) | \ 178: (1 << A6XX_INT_CP_CACHE_FLUSH_TS) | \ 179: (1 << A6XX_INT_RBBM_ATB_BUS_OVERFLOW) | \ 180: (1 << A6XX_INT_RBBM_HANG_DETECT) | \ 181: (1 << A6XX_INT_UCHE_OOB_ACCESS) | \ 182: (1 << A6XX_INT_UCHE_TRAP_INTR) | \ 183: (1 << A6XX_INT_TSB_WRITE_ERROR)) 184: 185: #define A6XX_HWSCHED_INT_MASK \ 186: ((1 << A6XX_INT_CP_AHB_ERROR) | \ 187: (1 << A6XX_INT_ATB_ASYNCFIFO_OVERFLOW) | \ 188: (1 << A6XX_INT_RBBM_ATB_BUS_OVERFLOW) | \ 189: (1 << A6XX_INT_UCHE_OOB_ACCESS) | \ 190: (1 << A6XX_INT_UCHE_TRAP_INTR) | \ 191: (1 << A6XX_INT_TSB_WRITE_ERROR)) 192: 193: /** 194: * to_a6xx_core - return the a6xx specific GPU core struct 195: * @adreno_dev: An Adreno GPU device handle 196: * 197: * Returns: 198: * A pointer to the a6xx specific GPU core struct 199: */ 200: static inline const struct adreno_a6xx_core * 201: to_a6xx_core(struct adreno_device *adreno_dev) 202: { MATCH LINES: 355, 363, 379 343: extern const struct adreno_perfcounters adreno_a6xx_perfcounters; 344: extern const struct adreno_perfcounters adreno_a6xx_legacy_perfcounters; 345: 346: /** 347: * a6xx_ringbuffer_addcmds - Submit a command to the ringbuffer 348: * @adreno_dev: An Adreno GPU handle 349: * @rb: Pointer to the ringbuffer to submit on 350: * @drawctxt: Pointer to the draw context for the submission, or NULL for 351: * internal submissions 352: * @flags: Flags for the submission 353: * @in: Commands to write to the ringbuffer 354: * @dwords: Size of @in (in dwords) 355: * @timestamp: Timestamp for the submission 356: * @time: Optional pointer to a submit time structure 357: * 358: * Submit a command to the ringbuffer. 359: * Return: 0 on success or negative on failure 360: */ 361: int a6xx_ringbuffer_addcmds(struct adreno_device *adreno_dev, 362: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 363: u32 flags, u32 *in, u32 dwords, u32 timestamp, 364: struct adreno_submit_time *time); 365: /** 366: * a6xx_ringbuffer_submitcmd - Submit a user command to the ringbuffer 367: * @adreno_dev: An Adreno GPU handle 368: * @cmdobj: Pointer to a user command object 369: * @flags: Internal submit flags 370: * @time: Optional pointer to a adreno_submit_time container 371: * 372: * Return: 0 on success or negative on failure 373: */ 374: int a6xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 375: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 376: struct adreno_submit_time *time); 377: 378: 379: int a6xx_fenced_write(struct adreno_device *adreno_dev, u32 offset, 380: u32 value, u32 mask); 381: 382: int a6xx_ringbuffer_submit(struct adreno_ringbuffer *rb, 383: struct adreno_submit_time *time, bool sync); 384: 385: void a6xx_cp_init_cmds(struct adreno_device *adreno_dev, u32 *cmds); 386: 387: int a6xx_gmu_hfi_probe(struct adreno_device *adreno_dev); 388: 389: static inline const struct a6xx_gpudev * 390: to_a6xx_gpudev(const struct adreno_gpudev *gpudev) 391: { 392: return container_of(gpudev, struct a6xx_gpudev, base); 393: } 394: 395: /** 396: * a6xx_reset_preempt_records - Reset the preemption buffers 397: * @adreno_dev: Handle to the adreno device 398: * 399: * Reset the preemption records at the time of hard reset 400: */ 401: void a6xx_reset_preempt_records(struct adreno_device *adreno_dev); 402: 403: /** --- FILE: \adreno_a6xx_gmu.c | HITS: 14 --- MATCH LINES: 1410, 1411 1398: A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS2, &status2); 1399: dev_err(GMU_PDEV_DEV(device), 1400: "GMU not idling: status2=0x%x %llx %llx\n", 1401: status2, ts1, 1402: a6xx_read_alwayson(ADRENO_DEVICE(device))); 1403: gmu_core_fault_snapshot(device, GMU_FAULT_WAIT_FOR_IDLE); 1404: return -ETIMEDOUT; 1405: } 1406: 1407: return 0; 1408: } 1409: 1410: /* A6xx GMU FENCE RANGE MASK */ 1411: #define GMU_FENCE_RANGE_MASK ((0x1 << 31) | ((0xA << 2) << 18) | (0x8A0)) 1412: 1413: void a6xx_gmu_version_info(struct adreno_device *adreno_dev) 1414: { 1415: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1416: struct gmu_core_device *gmu = &device->gmu_core; 1417: 1418: /* GMU version info is at a fixed offset in the DTCM */ 1419: gmu_core_regread(device, A6XX_GMU_CM3_DTCM_START + 0xFF8, 1420: &gmu->ver.core); 1421: gmu_core_regread(device, A6XX_GMU_CM3_DTCM_START + 0xFF9, 1422: &gmu->ver.core_dev); 1423: gmu_core_regread(device, A6XX_GMU_CM3_DTCM_START + 0xFFA, 1424: &gmu->ver.pwr); 1425: gmu_core_regread(device, A6XX_GMU_CM3_DTCM_START + 0xFFB, 1426: &gmu->ver.pwr_dev); 1427: gmu_core_regread(device, A6XX_GMU_CM3_DTCM_START + 0xFFC, 1428: &gmu->ver.hfi); 1429: } 1430: 1431: int a6xx_gmu_itcm_shadow(struct adreno_device *adreno_dev) 1432: { 1433: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1434: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 1435: u32 i, *dest; MATCH LINES: 1533, 1534 1521: gmu_core_regwrite(device, A6XX_GMU_HFI_QTBL_ADDR, 1522: gmu->hfi.hfi_mem->gmuaddr); 1523: gmu_core_regwrite(device, A6XX_GMU_HFI_QTBL_INFO, 1); 1524: 1525: /* 1526: * For A6xx GMUAO interrupt line BIT[1] is combined for ipcc 1527: * and doorbell. Enable dbdWakeupEn interrupt for GMU to receive 1528: * IPC interrupt. 1529: */ 1530: if (ADRENO_FEATURE(adreno_dev, ADRENO_LSR)) 1531: gmu_core_regwrite(device, A6XX_GMU_AO_INTERRUPT_EN, BIT(1)); 1532: 1533: gmu_core_regwrite(device, A6XX_GMU_AHB_FENCE_RANGE_0, 1534: GMU_FENCE_RANGE_MASK); 1535: 1536: /* 1537: * Make sure that CM3 state is at reset value. Snapshot is changing 1538: * NMI bit and if we boot up GMU with NMI bit set GMU will boot 1539: * straight in to NMI handler without executing __main code 1540: */ 1541: gmu_core_regwrite(device, A6XX_GMU_CM3_CFG, 0x4052); 1542: 1543: /** 1544: * We may have asserted gbif halt as part of reset sequence which may 1545: * not get cleared if the gdsc was not reset. So clear it before 1546: * attempting GMU boot. 1547: */ 1548: if (!adreno_is_a630(adreno_dev)) 1549: kgsl_regwrite(device, A6XX_GBIF_HALT, 0x0); 1550: 1551: /* Set vrb address before starting GMU */ 1552: if (!IS_ERR_OR_NULL(device->gmu_core.vrb)) 1553: gmu_core_regwrite(device, A6XX_GMU_GENERAL_11, device->gmu_core.vrb->gmuaddr); 1554: 1555: /* Set the log wptr index */ 1556: gmu_core_regwrite(device, A6XX_GPU_GMU_CX_GMU_PWR_COL_CP_RESP, 1557: gmu->log_wptr_retention); 1558: MATCH LINES: 1785, 1786, 1787 1773: 1774: /* 1775: * GEMNOC can enter power collapse state during GPU power down sequence. 1776: * This could abort CX GDSC collapse. Assert Qactive to avoid this. 1777: */ 1778: if ((adreno_is_a662(adreno_dev) || adreno_is_a621(adreno_dev) || 1779: adreno_is_a622(adreno_dev) || adreno_is_a642l(adreno_dev))) 1780: gmu_core_regwrite(device, A6XX_GPU_GMU_CX_GMU_CX_FALNEXT_INTF, 0x1); 1781: 1782: /* Check no outstanding RPMh voting */ 1783: a6xx_complete_rpmh_votes(adreno_dev, GPU_RESET_TIMEOUT); 1784: 1785: /* Clear the WRITEDROPPED fields and set fence to allow mode */ 1786: gmu_core_regwrite(device, A6XX_GMU_AHB_FENCE_STATUS_CLR, 0x7); 1787: gmu_core_regwrite(device, A6XX_GMU_AO_AHB_FENCE_CTRL, 0); 1788: 1789: /* Make sure above writes are committed before we proceed to recovery */ 1790: wmb(); 1791: 1792: gmu_core_regwrite(device, A6XX_GMU_CM3_SYSRESET, 1); 1793: 1794: if (!adreno_is_a630(adreno_dev)) { 1795: /* Halt GX traffic */ 1796: if (a6xx_gmu_gx_is_on(adreno_dev)) { 1797: kgsl_regwrite(device, A6XX_RBBM_GBIF_HALT, 1798: A6XX_GBIF_GX_HALT_MASK); 1799: adreno_wait_for_halt_ack(device, 1800: A6XX_RBBM_GBIF_HALT_ACK, 1801: A6XX_GBIF_GX_HALT_MASK); 1802: } 1803: /* Halt CX traffic */ 1804: a6xx_halt_gbif(adreno_dev); 1805: /* De-assert the halts */ 1806: kgsl_regwrite(device, A6XX_GBIF_HALT, 0x0); 1807: } 1808: 1809: /* 1810: * GX_CXO_CLK is needed to access RBBM_SW_RESET_CMD register. There are 1811: * scenarios where the IFPC exit sequence is still in progress, and the MATCH LINES: 1912, 1913 1900: if (!ret) { 1901: gmu_core_regread(device, 1902: A6XX_GPU_GMU_CX_GMU_RPMH_POWER_STATE, &state); 1903: if (state != GPU_HW_SLUMBER) { 1904: dev_err(GMU_PDEV_DEV(device), 1905: "Failed to prepare for slumber: 0x%x\n", 1906: state); 1907: ret = -ETIMEDOUT; 1908: } 1909: } 1910: 1911: out: 1912: /* Make sure the fence is in ALLOW mode */ 1913: gmu_core_regwrite(device, A6XX_GMU_AO_AHB_FENCE_CTRL, 0); 1914: 1915: /* 1916: * GEMNOC can enter power collapse state during GPU power down sequence. 1917: * This could abort CX GDSC collapse. Assert Qactive to avoid this. 1918: */ 1919: if ((adreno_is_a662(adreno_dev) || adreno_is_a621(adreno_dev) || 1920: adreno_is_a622(adreno_dev) || adreno_is_a642l(adreno_dev))) 1921: gmu_core_regwrite(device, A6XX_GPU_GMU_CX_GMU_CX_FALNEXT_INTF, 0x1); 1922: 1923: return ret; 1924: } 1925: 1926: void a6xx_gmu_suspend(struct adreno_device *adreno_dev, bool force) 1927: { 1928: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1929: 1930: if (!force && test_bit(ADRENO_DEVICE_RESET_RECOVERY, &adreno_dev->priv)) 1931: return; 1932: 1933: a6xx_gmu_pwrctrl_suspend(adreno_dev); 1934: 1935: gmu_core_disable_clks(device); 1936: 1937: a6xx_gmu_disable_gdsc(adreno_dev); MATCH LINES: 2203, 2204, 2206, 2207, 2209 2191: to_a6xx_gpudev(ADRENO_GPU_DEVICE(adreno_dev)); 2192: unsigned int status = 0; 2193: 2194: gmu_core_regread(device, A6XX_GMU_AO_HOST_INTERRUPT_STATUS, &status); 2195: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_CLR, status); 2196: 2197: /* Ignore GMU_INT_RSCC_COMP and GMU_INT_DBD WAKEUP interrupts */ 2198: if (status & GMU_INT_WDOG_BITE) 2199: a6xx_gpudev->handle_watchdog(adreno_dev); 2200: if (status & GMU_INT_HOST_AHB_BUS_ERR) 2201: dev_err_ratelimited(GMU_PDEV_DEV(device), 2202: "AHB bus error interrupt received\n"); 2203: if (status & GMU_INT_FENCE_ERR) { 2204: unsigned int fence_status; 2205: 2206: gmu_core_regread(device, A6XX_GMU_AHB_FENCE_STATUS, 2207: &fence_status); 2208: dev_err_ratelimited(GMU_PDEV_DEV(device), 2209: "FENCE error interrupt received %x\n", fence_status); 2210: } 2211: 2212: if (status & ~GMU_AO_INT_MASK) 2213: dev_err_ratelimited(GMU_PDEV_DEV(device), 2214: "Unhandled GMU interrupts 0x%lx\n", 2215: status & ~GMU_AO_INT_MASK); 2216: 2217: return IRQ_HANDLED; 2218: } 2219: 2220: void a6xx_gmu_snapshot(struct adreno_device *adreno_dev, 2221: struct kgsl_snapshot *snapshot) 2222: { 2223: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2224: 2225: a6xx_gmu_device_snapshot(device, snapshot); 2226: 2227: a6xx_snapshot(adreno_dev, snapshot); 2228: 2229: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, 2230: 0xffffffff); 2231: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_MASK, 2232: HFI_IRQ_MASK); 2233: --- FILE: \adreno_a6xx_gmu_snapshot.c | HITS: 2 --- MATCH LINES: 373, 374 361: ARRAY_SIZE(a6xx_gmu_gpucc_registers) / 2); 362: 363: /* Snapshot A660 specific GMU registers */ 364: if (adreno_is_a660(adreno_dev)) 365: adreno_snapshot_registers(device, snapshot, a660_gmu_registers, 366: ARRAY_SIZE(a660_gmu_registers) / 2); 367: 368: snapshot_rscc_registers(adreno_dev, snapshot); 369: 370: if (!a6xx_gmu_gx_is_on(adreno_dev)) 371: goto dtcm; 372: 373: /* Set fence to ALLOW mode so registers can be read */ 374: kgsl_regwrite(device, A6XX_GMU_AO_AHB_FENCE_CTRL, 0); 375: /* Make sure the previous write posted before reading */ 376: wmb(); 377: 378: adreno_snapshot_registers(device, snapshot, 379: a6xx_gmu_gx_registers, 380: ARRAY_SIZE(a6xx_gmu_gx_registers) / 2); 381: 382: /* A stalled SMMU can lead to NoC timeouts when host accesses DTCM */ 383: if (adreno_smmu_is_stalled(adreno_dev)) { 384: dev_err(GMU_PDEV_DEV(device), 385: "Not dumping dtcm because SMMU is stalled\n"); 386: return; 387: } 388: 389: dtcm: 390: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_GMU_MEMORY, 391: snapshot, a6xx_gmu_snapshot_dtcm, gmu); 392: } --- FILE: \adreno_a6xx_hfi.c | HITS: 1 --- MATCH LINES: 494 482: (char *) cmd->data); 483: 484: KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic, 485: GMU_PDEV(device), ticks, GMU_FAULT_F2H_MSG_ERR); 486: } 487: 488: void adreno_a6xx_receive_debug_req(struct a6xx_gmu_device *gmu, void *rcvd) 489: { 490: struct kgsl_device *device = KGSL_DEVICE(a6xx_gmu_to_adreno(gmu)); 491: struct hfi_debug_cmd *cmd = rcvd; 492: 493: dev_dbg(GMU_PDEV_DEV(device), "HFI Debug Received: %d %d %d\n", 494: cmd->type, cmd->timestamp, cmd->data); 495: } 496: 497: static void a6xx_hfi_v1_receiver(struct a6xx_gmu_device *gmu, uint32_t *rcvd, 498: struct pending_cmd *ret_cmd) 499: { 500: struct kgsl_device *device = KGSL_DEVICE(a6xx_gmu_to_adreno(gmu)); 501: /* V1 ACK Handler */ 502: if (MSG_HDR_GET_TYPE(rcvd[0]) == HFI_V1_MSG_ACK) { 503: a6xx_receive_ack_cmd(gmu, rcvd, ret_cmd); 504: return; 505: } 506: 507: /* V1 Request Handler */ 508: switch (MSG_HDR_GET_ID(rcvd[0])) { 509: case F2H_MSG_ERR: /* No Reply */ 510: adreno_a6xx_receive_err_req(gmu, rcvd); 511: break; 512: case F2H_MSG_DEBUG: /* No Reply */ 513: adreno_a6xx_receive_debug_req(gmu, rcvd); 514: break; 515: default: /* No Reply */ 516: dev_err(GMU_PDEV_DEV(device), 517: "HFI V1 request %d not supported\n", 518: MSG_HDR_GET_ID(rcvd[0])); --- FILE: \adreno_a6xx_hwsched_hfi.c | HITS: 9 --- MATCH LINES: 1089, 1090 1077: rcmd.ctxt_id = KGSL_GLOBAL_CTXT_ID; 1078: rcmd.flags = (KGSL_CONTEXT_PRIORITY_HIGH << KGSL_CONTEXT_PRIORITY_SHIFT); 1079: 1080: ret = a6xx_hfi_send_cmd_async(adreno_dev, &rcmd, sizeof(rcmd)); 1081: if (ret) 1082: return ret; 1083: 1084: ret = CMD_MSG_HDR(pcmd, H2F_MSG_CONTEXT_POINTERS); 1085: if (ret) 1086: return ret; 1087: 1088: pcmd.ctxt_id = KGSL_GLOBAL_CTXT_ID; 1089: pcmd.sop_addr = MEMSTORE_ID_GPU_ADDR(device, KGSL_GLOBAL_CTXT_ID, soptimestamp); 1090: pcmd.eop_addr = MEMSTORE_ID_GPU_ADDR(device, KGSL_GLOBAL_CTXT_ID, eoptimestamp); 1091: 1092: ret = a6xx_hfi_send_cmd_async(adreno_dev, &pcmd, sizeof(pcmd)); 1093: if (!ret) 1094: hwsched->global_ctxt_gmu_registered = true; 1095: 1096: return ret; 1097: } 1098: 1099: #define HFI_DSP_IRQ_BASE 2 1100: 1101: #define DISPQ_IRQ_BIT(_idx) BIT((_idx) + HFI_DSP_IRQ_BASE) 1102: 1103: static int submit_global_ctxt_cmd(struct adreno_device *adreno_dev, u64 gpuaddr, u32 size) 1104: { 1105: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1106: struct { 1107: struct hfi_submit_cmd submit_cmd; 1108: struct hfi_issue_ib issue_ib; 1109: } cmd = {0}; 1110: u32 seqnum, cmd_size = sizeof(cmd); 1111: static u32 ts; 1112: int ret = 0; 1113: 1114: cmd.submit_cmd.ctxt_id = KGSL_GLOBAL_CTXT_ID; MATCH LINES: 1318, 1319 1306: static int send_context_pointers(struct adreno_device *adreno_dev, 1307: struct kgsl_context *context) 1308: { 1309: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1310: struct hfi_context_pointers_cmd cmd = {0}; 1311: int ret; 1312: 1313: ret = CMD_MSG_HDR(cmd, H2F_MSG_CONTEXT_POINTERS); 1314: if (ret) 1315: return ret; 1316: 1317: cmd.ctxt_id = context->id; 1318: cmd.sop_addr = MEMSTORE_ID_GPU_ADDR(device, context->id, soptimestamp); 1319: cmd.eop_addr = MEMSTORE_ID_GPU_ADDR(device, context->id, eoptimestamp); 1320: if (context->user_ctxt_record) 1321: cmd.user_ctxt_record_addr = 1322: context->user_ctxt_record->memdesc.gpuaddr; 1323: 1324: return a6xx_hfi_send_cmd_async(adreno_dev, &cmd, sizeof(cmd)); 1325: } 1326: 1327: static int hfi_context_register(struct adreno_device *adreno_dev, 1328: struct kgsl_context *context) 1329: { 1330: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1331: int ret; 1332: 1333: if (context->gmu_registered) 1334: return 0; 1335: 1336: ret = send_context_register(adreno_dev, context); 1337: if (ret) { 1338: dev_err(GMU_PDEV_DEV(device), 1339: "Unable to register context %u: %d\n", 1340: context->id, ret); 1341: 1342: if (device->gmu_fault) 1343: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); MATCH LINES: 1509, 1547 1497: if (WARN_ON(cmd_sizebytes > HFI_MAX_MSG_SIZE)) 1498: return -EMSGSIZE; 1499: 1500: memset(cmdbuf, 0x0, cmd_sizebytes); 1501: 1502: cmd = cmdbuf; 1503: 1504: cmd->ctxt_id = drawobj->context->id; 1505: cmd->flags = HFI_CTXT_FLAG_NOTIFY; 1506: if (drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME) 1507: cmd->flags |= CMDBATCH_EOF; 1508: 1509: cmd->ts = drawobj->timestamp; 1510: 1511: if (test_bit(CMDOBJ_SKIP, &cmdobj->priv)) 1512: goto skipib; 1513: 1514: populate_ibs(adreno_dev, cmd, cmdobj); 1515: 1516: if ((drawobj->flags & KGSL_DRAWOBJ_PROFILING) && 1517: cmdobj->profiling_buf_entry) { 1518: 1519: time.drawobj = drawobj; 1520: 1521: cmd->profile_gpuaddr_lo = 1522: lower_32_bits(cmdobj->profiling_buffer_gpuaddr); 1523: cmd->profile_gpuaddr_hi = 1524: upper_32_bits(cmdobj->profiling_buffer_gpuaddr); 1525: 1526: /* Indicate to GMU to do user profiling for this submission */ 1527: cmd->flags |= CMDBATCH_PROFILING; 1528: } 1529: 1530: skipib: 1531: adreno_drawobj_set_constraint(KGSL_DEVICE(adreno_dev), drawobj); 1532: 1533: seqnum = atomic_inc_return(&adreno_dev->hwsched.submission_seqnum); 1534: cmd->hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_CMD, HFI_MSG_CMD); 1535: cmd->hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd->hdr, seqnum, cmd_sizebytes >> 2); 1536: 1537: ret = a6xx_hfi_dispatch_queue_write(adreno_dev, 1538: HFI_DSP_ID_0 + drawobj->context->gmu_dispatch_queue, 1539: (u32 *)cmd, cmd_sizebytes, cmdobj, &time); 1540: if (ret) 1541: return ret; 1542: 1543: /* Send interrupt to GMU to receive the message */ 1544: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), A6XX_GMU_HOST2GMU_INTR_SET, 1545: DISPQ_IRQ_BIT(drawobj->context->gmu_dispatch_queue)); 1546: 1547: drawctxt->internal_timestamp = drawobj->timestamp; 1548: 1549: return ret; 1550: } 1551: 1552: int a6xx_hwsched_send_recurring_cmdobj(struct adreno_device *adreno_dev, 1553: struct kgsl_drawobj_cmd *cmdobj) 1554: { 1555: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1556: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 1557: struct hfi_submit_cmd *cmd; 1558: struct kgsl_memobj_node *ib; 1559: u32 cmd_sizebytes; 1560: int ret; 1561: static bool active; 1562: 1563: if (adreno_gpu_halt(adreno_dev) || adreno_gpu_fault(adreno_dev)) 1564: return -EBUSY; 1565: 1566: if (test_bit(CMDOBJ_RECURRING_STOP, &cmdobj->priv)) { 1567: cmdobj->numibs = 0; 1568: } else { 1569: list_for_each_entry(ib, &cmdobj->cmdlist, node) 1570: cmdobj->numibs++; 1571: } MATCH LINES: 1728, 1734, 1737 1716: } 1717: 1718: void a6xx_hwsched_context_detach(struct adreno_context *drawctxt) 1719: { 1720: struct kgsl_context *context = &drawctxt->base; 1721: struct kgsl_device *device = context->device; 1722: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1723: int ret = 0; 1724: 1725: kgsl_mutex_lock(&device->mutex); 1726: 1727: ret = send_context_unregister_hfi(adreno_dev, context, 1728: drawctxt->internal_timestamp); 1729: 1730: if (ret) 1731: goto out; 1732: 1733: kgsl_sharedmem_writel(device->memstore, 1734: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), drawctxt->timestamp); 1735: 1736: kgsl_sharedmem_writel(device->memstore, 1737: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), drawctxt->timestamp); 1738: 1739: adreno_profile_process_results(adreno_dev); 1740: context->gmu_registered = false; 1741: 1742: out: 1743: kgsl_mutex_unlock(&device->mutex); 1744: } 1745: 1746: u32 a6xx_hwsched_preempt_count_get(struct adreno_device *adreno_dev) 1747: { 1748: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1749: struct hfi_get_value_cmd cmd; 1750: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 1751: struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev); 1752: struct pending_cmd pending_ack; 1753: int rc; 1754: u32 seqnum; 1755: 1756: if (device->state != KGSL_STATE_ACTIVE) 1757: return 0; 1758: 1759: rc = CMD_MSG_HDR(cmd, H2F_MSG_GET_VALUE); 1760: if (rc) 1761: return 0; --- FILE: \adreno_a6xx_perfcounter.c | HITS: 1 --- MATCH LINES: 125 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: } --- FILE: \adreno_a6xx_preempt.c | HITS: 21 --- MATCH LINES: 36, 38 24: unsigned long flags; 25: int ret = 0; 26: 27: spin_lock_irqsave(&rb->preempt_lock, flags); 28: 29: if (!atomic) { 30: /* 31: * We might have skipped updating the wptr in case we are in 32: * dispatcher context. Do it now. 33: */ 34: if (rb->skip_inline_wptr) { 35: 36: ret = a6xx_fenced_write(adreno_dev, 37: A6XX_CP_RB_WPTR, rb->wptr, 38: FENCE_STATUS_WRITEDROPPED0_MASK); 39: 40: reset_timer = true; 41: rb->skip_inline_wptr = false; 42: } 43: } else { 44: unsigned int wptr; 45: 46: kgsl_regread(device, A6XX_CP_RB_WPTR, &wptr); 47: if (wptr != rb->wptr) { 48: kgsl_regwrite(device, A6XX_CP_RB_WPTR, rb->wptr); 49: reset_timer = true; 50: } 51: } 52: 53: if (reset_timer) 54: rb->dispatch_q.expires = jiffies + 55: msecs_to_jiffies(adreno_drawobj_timeout); 56: 57: spin_unlock_irqrestore(&rb->preempt_lock, flags); 58: 59: if (!atomic) { 60: /* If WPTR update fails, set the fault and trigger recovery */ 61: if (ret) { 62: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); MATCH LINES: 314, 315, 322, 325, 328, 332, 343, 346, 350, 353, 356, 359, 363, 366, 369, 372, 397, 398, 406 302: 303: kgsl_sharedmem_readq(preempt->scratch, &gpuaddr, 304: next->id * sizeof(u64)); 305: 306: /* 307: * Set a keepalive bit before the first preemption register write. 308: * This is required since while each individual write to the context 309: * switch registers will wake the GPU from collapse, it will not in 310: * itself cause GPU activity. Thus, the GPU could technically be 311: * re-collapsed between subsequent register writes leading to a 312: * prolonged preemption sequence. The keepalive bit prevents any 313: * further power collapse while it is set. 314: * It is more efficient to use a keepalive+wake-on-fence approach here 315: * rather than an OOB. Both keepalive and the fence are effectively 316: * free when the GPU is already powered on, whereas an OOB requires an 317: * unconditional handshake with the GMU. 318: */ 319: _power_collapse_set(adreno_dev, true); 320: 321: /* 322: * Fenced writes on this path will make sure the GPU is woken up 323: * in case it was power collapsed by the GMU. 324: */ 325: if (a6xx_fenced_write(adreno_dev, 326: A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO, 327: lower_32_bits(next->preemption_desc->gpuaddr), 328: FENCE_STATUS_WRITEDROPPED1_MASK)) 329: goto err; 330: 331: /* 332: * Above fence writes will make sure GMU comes out of 333: * IFPC state if its was in IFPC state but it doesn't 334: * guarantee that GMU FW actually moved to ACTIVE state 335: * i.e. wake-up from IFPC is complete. 336: * Wait for GMU to move to ACTIVE state before triggering 337: * preemption. This is require to make sure CP doesn't 338: * interrupt GMU during wake-up from IFPC. 339: */ 340: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 341: goto err; 342: 343: if (a6xx_fenced_write(adreno_dev, 344: A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI, 345: upper_32_bits(next->preemption_desc->gpuaddr), 346: FENCE_STATUS_WRITEDROPPED1_MASK)) 347: goto err; 348: 349: if (kgsl_mmu_is_secured(&device->mmu)) { 350: if (a6xx_fenced_write(adreno_dev, 351: A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO, 352: lower_32_bits(next->secure_preemption_desc->gpuaddr), 353: FENCE_STATUS_WRITEDROPPED1_MASK)) 354: goto err; 355: 356: if (a6xx_fenced_write(adreno_dev, 357: A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI, 358: upper_32_bits(next->secure_preemption_desc->gpuaddr), 359: FENCE_STATUS_WRITEDROPPED1_MASK)) 360: goto err; 361: } 362: 363: if (a6xx_fenced_write(adreno_dev, 364: A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO, 365: lower_32_bits(gpuaddr), 366: FENCE_STATUS_WRITEDROPPED1_MASK)) 367: goto err; 368: 369: if (a6xx_fenced_write(adreno_dev, 370: A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI, 371: upper_32_bits(gpuaddr), 372: FENCE_STATUS_WRITEDROPPED1_MASK)) 373: goto err; 374: 375: adreno_dev->next_rb = next; 376: 377: /* Start the timer to detect a stuck preemption */ 378: mod_timer(&adreno_dev->preempt.timer, 379: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 380: 381: cntl = (preempt->preempt_level << 6) | 0x01; 382: 383: /* Skip save/restore during L1 preemption */ 384: if (preempt->skipsaverestore) 385: cntl |= (1 << 9); 386: 387: /* Enable GMEM save/restore across preemption */ 388: if (preempt->usesgmem) 389: cntl |= (1 << 8); 390: 391: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 392: cntl, 0); 393: 394: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 395: 396: /* Trigger the preemption */ 397: if (a6xx_fenced_write(adreno_dev, A6XX_CP_CONTEXT_SWITCH_CNTL, cntl, 398: FENCE_STATUS_WRITEDROPPED1_MASK)) { 399: adreno_dev->next_rb = NULL; 400: kgsl_delete_timer(&adreno_dev->preempt.timer); 401: goto err; 402: } 403: 404: return; 405: err: 406: /* If fenced write fails, take inline snapshot and trigger recovery */ 407: if (!atomic) { 408: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 409: adreno_scheduler_fault(adreno_dev, 410: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 411: } else { 412: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 413: } 414: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 415: /* Clear the keep alive */ 416: _power_collapse_set(adreno_dev, false); 417: 418: } 419: 420: void a6xx_preemption_callback(struct adreno_device *adreno_dev, int bit) 421: { 422: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 423: unsigned int status; 424: 425: if (!adreno_move_preempt_state(adreno_dev, 426: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 427: return; 428: 429: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, &status); 430: --- FILE: \adreno_a6xx_rgmu.c | HITS: 20 --- MATCH LINES: 60, 61, 63, 64, 69 48: 49: return &a6xx_dev->rgmu; 50: } 51: 52: static irqreturn_t a6xx_rgmu_irq_handler(int irq, void *data) 53: { 54: struct kgsl_device *device = data; 55: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(ADRENO_DEVICE(device)); 56: unsigned int status = 0; 57: 58: gmu_core_regread(device, A6XX_GMU_AO_HOST_INTERRUPT_STATUS, &status); 59: 60: if (status & RGMU_AO_IRQ_FENCE_ERR) { 61: unsigned int fence_status; 62: 63: gmu_core_regread(device, A6XX_GMU_AHB_FENCE_STATUS, 64: &fence_status); 65: gmu_core_regwrite(device, A6XX_GMU_AO_HOST_INTERRUPT_CLR, 66: status); 67: 68: dev_err_ratelimited(&rgmu->pdev->dev, 69: "FENCE error interrupt received %x\n", fence_status); 70: } 71: 72: if (status & ~RGMU_AO_IRQ_MASK) 73: dev_err_ratelimited(&rgmu->pdev->dev, 74: "Unhandled RGMU interrupts 0x%lx\n", 75: status & ~RGMU_AO_IRQ_MASK); 76: 77: return IRQ_HANDLED; 78: } 79: 80: static irqreturn_t a6xx_oob_irq_handler(int irq, void *data) 81: { 82: struct kgsl_device *device = data; 83: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 84: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 85: unsigned int status = 0; 86: 87: gmu_core_regread(device, A6XX_GMU_GMU2HOST_INTR_INFO, &status); 88: 89: if (status & RGMU_OOB_IRQ_ERR_MSG) { 90: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, status); 91: 92: dev_err_ratelimited(&rgmu->pdev->dev, 93: "RGMU oob irq error\n"); MATCH LINES: 335, 369, 370 323: gmu_core_regread(device, A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS, ®[3]); 324: kgsl_regread(device, A6XX_CP_STATUS_1, ®[4]); 325: gmu_core_regread(device, A6XX_GMU_RBBM_INT_UNMASKED_STATUS, ®[5]); 326: gmu_core_regread(device, A6XX_GMU_GMU_PWR_COL_KEEPALIVE, ®[6]); 327: kgsl_regread(device, A6XX_CP_CP2GMU_STATUS, ®[7]); 328: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, ®[8]); 329: gmu_core_regread(device, A6XX_GMU_AO_SPARE_CNTL, ®[9]); 330: 331: dev_err(&rgmu->pdev->dev, 332: "----------------------[ RGMU error ]----------------------\n"); 333: dev_err(&rgmu->pdev->dev, "Timeout waiting for lowest idle level\n"); 334: dev_err(&rgmu->pdev->dev, 335: "Timestamps: %llx %llx %llx\n", ts1, ts2, ts3); 336: dev_err(&rgmu->pdev->dev, 337: "SPTPRAC_PWR_CLK_STATUS=%x PCC_DEBUG=%x PCC_STATUS=%x\n", 338: reg[0], reg[1], reg[2]); 339: dev_err(&rgmu->pdev->dev, 340: "CX_BUSY_STATUS=%x CP_STATUS_1=%x\n", reg[3], reg[4]); 341: dev_err(&rgmu->pdev->dev, 342: "RBBM_INT_UNMASKED_STATUS=%x PWR_COL_KEEPALIVE=%x\n", 343: reg[5], reg[6]); 344: dev_err(&rgmu->pdev->dev, 345: "CP2GMU_STATUS=%x CONTEXT_SWITCH_CNTL=%x AO_SPARE_CNTL=%x\n", 346: reg[7], reg[8], reg[9]); 347: 348: WARN_ON(1); 349: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 350: return -ETIMEDOUT; 351: } 352: 353: /* 354: * The lowest 16 bits of this value are the number of XO clock cycles 355: * for main hysteresis. This is the first hysteresis. Here we set it 356: * to 0x1680 cycles, or 300 us. The highest 16 bits of this value are 357: * the number of XO clock cycles for short hysteresis. This happens 358: * after main hysteresis. Here we set it to 0xA cycles, or 0.5 us. 359: */ 360: #define A6X_RGMU_LONG_IFPC_HYST FIELD_PREP(GENMASK(15, 0), 0x1680) 361: #define A6X_RGMU_SHORT_IFPC_HYST FIELD_PREP(GENMASK(31, 16), 0xA) 362: 363: /* Minimum IFPC timer (200usec) allowed to override default value */ 364: #define A6X_RGMU_LONG_IFPC_HYST_FLOOR FIELD_PREP(GENMASK(15, 0), 0x0F00) 365: 366: /* HOSTTOGMU and TIMER0/1 interrupt mask: 0x20060 */ 367: #define RGMU_INTR_EN_MASK (BIT(5) | BIT(6) | BIT(17)) 368: 369: /* RGMU FENCE RANGE MASK */ 370: #define RGMU_FENCE_RANGE_MASK ((0x1 << 31) | ((0xA << 2) << 18) | (0x8A0)) 371: 372: static int a6xx_rgmu_fw_start(struct adreno_device *adreno_dev, 373: unsigned int boot_state) 374: { 375: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 376: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 377: unsigned int status; 378: int i; 379: 380: switch (boot_state) { 381: case GMU_COLD_BOOT: 382: case GMU_WARM_BOOT: 383: /* Turn on TCM retention */ 384: gmu_core_regwrite(device, A6XX_GMU_GENERAL_7, 1); 385: 386: /* Load RGMU FW image via AHB bus */ 387: for (i = 0; i < rgmu->fw_size; i++) 388: gmu_core_regwrite(device, A6XX_GMU_CM3_ITCM_START + i, 389: rgmu->fw_hostptr[i]); 390: break; 391: } 392: 393: /* IFPC Feature Enable */ 394: if (rgmu->idle_level == GPU_HW_IFPC) { MATCH LINES: 411, 412, 413, 415, 416, 418 399: } 400: 401: /* For RGMU CX interrupt */ 402: gmu_core_regwrite(device, A6XX_RGMU_CX_INTR_GEN_EN, RGMU_INTR_EN_MASK); 403: 404: /* Enable GMU AO to host interrupt */ 405: gmu_core_regwrite(device, A6XX_GMU_AO_INTERRUPT_EN, RGMU_AO_IRQ_MASK); 406: 407: /* For OOB */ 408: gmu_core_regwrite(device, A6XX_GMU_HOST2GMU_INTR_EN_2, 0x00FF0000); 409: gmu_core_regwrite(device, A6XX_GMU_HOST2GMU_INTR_EN_3, 0xFF000000); 410: 411: /* Fence Address range configuration */ 412: gmu_core_regwrite(device, A6XX_GMU_AHB_FENCE_RANGE_0, 413: RGMU_FENCE_RANGE_MASK); 414: 415: /* During IFPC RGMU will put fence in drop mode so we would 416: * need to put fence allow mode during slumber out sequence. 417: */ 418: gmu_core_regwrite(device, A6XX_GMU_AO_AHB_FENCE_CTRL, 0); 419: 420: /* BCL ON Sequence */ 421: a6xx_rgmu_bcl_config(device, true); 422: 423: /* Write 0 first to make sure that rgmu is reset */ 424: gmu_core_regwrite(device, A6XX_RGMU_CX_PCC_CTRL, 0); 425: 426: /* Make sure putting in reset doesn't happen after writing 1 */ 427: wmb(); 428: 429: /* Bring rgmu out of reset */ 430: gmu_core_regwrite(device, A6XX_RGMU_CX_PCC_CTRL, 1); 431: 432: if (gmu_core_timed_poll_check(device, A6XX_RGMU_CX_PCC_INIT_RESULT, 433: BIT(0), RGMU_START_TIMEOUT, BIT(0))) { 434: gmu_core_regread(device, A6XX_RGMU_CX_PCC_DEBUG, &status); 435: dev_err(&rgmu->pdev->dev, 436: "rgmu boot Failed. status:%08x\n", status); 437: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 438: return -ETIMEDOUT; 439: } 440: 441: /* Read the RGMU firmware version from registers */ 442: gmu_core_regread(device, A6XX_GMU_GENERAL_0, &rgmu->ver); MATCH LINES: 601, 614, 617, 618, 627, 630 589: release_firmware(fw); 590: return rgmu->fw_hostptr ? 0 : -ENOMEM; 591: } 592: 593: /* Halt RGMU execution */ 594: static void a6xx_rgmu_halt_execution(struct kgsl_device *device, bool force, 595: enum gmu_fault_panic_policy gf_policy) 596: { 597: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 598: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev); 599: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 600: u64 ticks = gpudev->read_alwayson(adreno_dev); 601: unsigned int index, status, fence; 602: 603: if (!device->gmu_fault) 604: return; 605: 606: /* Mask so there's no interrupt caused by NMI */ 607: gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_MASK, 0xFFFFFFFF); 608: 609: /* Make sure the interrupt is masked */ 610: wmb(); 611: 612: gmu_core_regread(device, A6XX_RGMU_CX_PCC_DEBUG, &index); 613: gmu_core_regread(device, A6XX_RGMU_CX_PCC_STATUS, &status); 614: gmu_core_regread(device, A6XX_GMU_AO_AHB_FENCE_CTRL, &fence); 615: 616: dev_err(&rgmu->pdev->dev, 617: "RGMU Fault PCC_DEBUG:0x%x PCC_STATUS:0x%x FENCE_CTRL:0x%x\n", 618: index, status, fence); 619: 620: /* 621: * Write 0 to halt RGMU execution. We halt it in GMU/GPU fault and 622: * re start PCC execution in recovery path. 623: */ 624: gmu_core_regwrite(device, A6XX_RGMU_CX_PCC_CTRL, 0); 625: 626: /* 627: * Ensure that fence is in allow mode after halting RGMU. 628: * After halting RGMU we dump snapshot. 629: */ 630: gmu_core_regwrite(device, A6XX_GMU_AO_AHB_FENCE_CTRL, 0); 631: 632: KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic, rgmu->pdev, ticks, gf_policy); 633: } 634: 635: static void halt_gbif_arb(struct adreno_device *adreno_dev) 636: { 637: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 638: 639: /* Halt all AXI requests */ 640: kgsl_regwrite(device, A6XX_GBIF_HALT, A6XX_GBIF_ARB_HALT_MASK); 641: adreno_wait_for_halt_ack(device, A6XX_GBIF_HALT_ACK, 642: A6XX_GBIF_ARB_HALT_MASK); 643: 644: /* De-assert the halts */ 645: kgsl_regwrite(device, A6XX_GBIF_HALT, 0x0); 646: } 647: 648: 649: /* Caller shall ensure GPU is ready for SLUMBER */ 650: static void a6xx_rgmu_power_off(struct adreno_device *adreno_dev) 651: { 652: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 653: int ret; 654: --- FILE: \adreno_a6xx_rgmu.h | HITS: 2 --- MATCH LINES: 9, 10 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. 5: */ 6: #ifndef __ADRENO_A6XX_RGMU_H 7: #define __ADRENO_A6XX_RGMU_H 8: 9: #define RGMU_AO_IRQ_FENCE_ERR BIT(3) 10: #define RGMU_AO_IRQ_MASK RGMU_AO_IRQ_FENCE_ERR 11: 12: #define RGMU_OOB_IRQ_ERR_MSG BIT(24) 13: #define RGMU_OOB_IRQ_ACK_MASK GENMASK(23, 16) 14: #define RGMU_OOB_IRQ_ERR_MSG_MASK GENMASK(31, 24) 15: #define RGMU_OOB_IRQ_MASK RGMU_OOB_IRQ_ERR_MSG_MASK 16: 17: #define MAX_RGMU_CLKS 8 18: 19: enum { 20: /* @RGMU_PRIV_FIRST_BOOT_DONE: The very first ggpu boot is done */ 21: RGMU_PRIV_FIRST_BOOT_DONE, 22: /* @RGMU_PRIV_GPU_STARTED: GPU has been started */ 23: RGMU_PRIV_GPU_STARTED, 24: /* @RGMU_PRIV_PM_SUSPEND: The rgmu driver is suspended */ 25: RGMU_PRIV_PM_SUSPEND, 26: }; 27: 28: /** 29: * struct a6xx_rgmu_device - rGMU device structure 30: * @ver: RGMU firmware version 31: * @rgmu_interrupt_num: RGMU interrupt number 32: * @oob_interrupt_num: number of RGMU asserted OOB interrupt 33: * @fw_hostptr: Buffer which holds the RGMU firmware 34: * @fw_size: Size of RGMU firmware buffer --- FILE: \adreno_a6xx_ringbuffer.c | HITS: 36 --- MATCH LINES: 114, 115, 116, 117, 119, 120, 121, 122, 151, 153 102: KGSL_MEMSTORE_GLOBAL, current_context)); 103: cmds[count++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 104: KGSL_MEMSTORE_GLOBAL, current_context)); 105: cmds[count++] = drawctxt->base.id; 106: 107: cmds[count++] = cp_type7_packet(CP_EVENT_WRITE, 1); 108: cmds[count++] = 0x31; 109: 110: return a6xx_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED, 111: cmds, count, 0, NULL); 112: } 113: 114: #define RB_SOPTIMESTAMP(device, rb) \ 115: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 116: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 117: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 118: 119: #define RB_EOPTIMESTAMP(device, rb) \ 120: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 121: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 122: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 123: 124: int a6xx_ringbuffer_submit(struct adreno_ringbuffer *rb, 125: struct adreno_submit_time *time, bool sync) 126: { 127: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 128: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 129: int ret = 0; 130: unsigned long flags; 131: 132: adreno_get_submit_time(adreno_dev, rb, time); 133: adreno_profile_submit_time(time); 134: 135: if (sync && !ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) { 136: u32 *cmds = adreno_ringbuffer_allocspace(rb, 3); 137: 138: if (IS_ERR(cmds)) 139: return PTR_ERR(cmds); 140: 141: cmds[0] = cp_type7_packet(CP_WHERE_AM_I, 2); 142: cmds[1] = lower_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id, 143: rptr)); 144: cmds[2] = upper_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id, 145: rptr)); 146: } 147: 148: spin_lock_irqsave(&rb->preempt_lock, flags); 149: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 150: if (adreno_dev->cur_rb == rb) { 151: ret = a6xx_fenced_write(adreno_dev, 152: A6XX_CP_RB_WPTR, rb->_wptr, 153: FENCE_STATUS_WRITEDROPPED0_MASK); 154: rb->skip_inline_wptr = false; 155: } 156: } else { 157: if (adreno_dev->cur_rb == rb) 158: rb->skip_inline_wptr = true; 159: } 160: 161: rb->wptr = rb->_wptr; 162: spin_unlock_irqrestore(&rb->preempt_lock, flags); 163: 164: if (ret) { 165: /* 166: * If WPTR update fails, take inline snapshot and trigger 167: * recovery. 168: */ 169: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 170: adreno_scheduler_fault(adreno_dev, 171: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 172: } 173: 174: return ret; 175: } 176: 177: int a6xx_ringbuffer_init(struct adreno_device *adreno_dev) MATCH LINES: 216, 231, 234, 270, 272, 274, 278, 279, 280, 314, 319, 320, 321, 322, 325, 326, 328, 330, 333, 334, 335, 336 204: return ret; 205: } 206: 207: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 208: a6xx_preemption_init(adreno_dev); 209: return 0; 210: } 211: 212: #define A6XX_SUBMIT_MAX 79 213: 214: int a6xx_ringbuffer_addcmds(struct adreno_device *adreno_dev, 215: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 216: u32 flags, u32 *in, u32 dwords, u32 timestamp, 217: struct adreno_submit_time *time) 218: { 219: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 220: u32 size = A6XX_SUBMIT_MAX + dwords; 221: u32 *cmds, index = 0; 222: u64 profile_gpuaddr; 223: u32 profile_dwords; 224: 225: if (adreno_drawctxt_detached(drawctxt)) 226: return -ENOENT; 227: 228: if (adreno_gpu_fault(adreno_dev) != 0) 229: return -EPROTO; 230: 231: rb->timestamp++; 232: 233: if (drawctxt) 234: drawctxt->internal_timestamp = rb->timestamp; 235: 236: /* 237: * if APRIV is enabled we assume all submissions are run with protected 238: * mode off 239: */ 240: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 241: flags &= ~F_NOTPROTECTED; 242: 243: cmds = adreno_ringbuffer_allocspace(rb, size); 244: if (IS_ERR(cmds)) 245: return PTR_ERR(cmds); 246: 247: /* Identify the start of a command */ 248: cmds[index++] = cp_type7_packet(CP_NOP, 1); 249: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 250: 251: /* This is 25 dwords when drawctxt is not NULL and perfcounter needs to be zapped */ 252: index += a6xx_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 253: &cmds[index]); 254: 255: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 256: cmds[index++] = 0x101; /* IFPC disable */ 257: 258: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 259: drawctxt, &profile_dwords); 260: 261: if (profile_gpuaddr) { 262: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 263: cmds[index++] = lower_32_bits(profile_gpuaddr); 264: cmds[index++] = upper_32_bits(profile_gpuaddr); 265: cmds[index++] = profile_dwords; 266: } 267: 268: if (drawctxt) { 269: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 270: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 271: drawctxt)); 272: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 273: drawctxt)); 274: cmds[index++] = timestamp; 275: } 276: 277: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 278: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 279: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); 280: cmds[index++] = rb->timestamp; 281: 282: if (IS_SECURE(flags)) { 283: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 284: cmds[index++] = 1; 285: } 286: 287: if (IS_NOTPROTECTED(flags)) { 288: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1); 289: cmds[index++] = 0; 290: } 291: 292: memcpy(&cmds[index], in, dwords << 2); 293: index += dwords; 294: 295: if (IS_NOTPROTECTED(flags)) { 296: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1); 297: cmds[index++] = 1; 298: } 299: 300: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev, 301: drawctxt, &dwords); 302: 303: if (profile_gpuaddr) { 304: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 305: cmds[index++] = lower_32_bits(profile_gpuaddr); 306: cmds[index++] = upper_32_bits(profile_gpuaddr); 307: cmds[index++] = profile_dwords; 308: } 309: 310: if (test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &device->mmu.pfpolicy)) 311: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0); 312: 313: /* 314: * If this is an internal command, just write the ringbuffer timestamp, 315: * otherwise, write both 316: */ 317: if (!drawctxt) { 318: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 319: cmds[index++] = CACHE_FLUSH_TS | (1 << 31); 320: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 321: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 322: cmds[index++] = rb->timestamp; 323: } else { 324: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 325: cmds[index++] = CACHE_FLUSH_TS | (1 << 31); 326: cmds[index++] = lower_32_bits(CTXT_EOPTIMESTAMP(device, 327: drawctxt)); 328: cmds[index++] = upper_32_bits(CTXT_EOPTIMESTAMP(device, 329: drawctxt)); 330: cmds[index++] = timestamp; 331: 332: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 333: cmds[index++] = CACHE_FLUSH_TS; 334: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 335: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 336: cmds[index++] = rb->timestamp; 337: } 338: 339: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 340: cmds[index++] = 0x100; /* IFPC enable */ 341: 342: if (IS_WFI(flags)) 343: cmds[index++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 344: 345: if (IS_SECURE(flags)) { 346: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 347: cmds[index++] = 0; 348: } 349: 350: /* 10 dwords */ 351: index += a6xx_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 352: 353: /* Adjust the thing for the number of dwords we actually wrote */ 354: rb->_wptr -= (size - index); 355: 356: return a6xx_ringbuffer_submit(rb, time, 357: !adreno_is_preemption_enabled(adreno_dev)); 358: } 359: 360: static u32 a6xx_get_alwayson_counter(u32 *cmds, u64 gpuaddr) MATCH LINES: 433, 434 421: if (!_kgsl_context_get(&drawctxt->base)) 422: return -ENOENT; 423: 424: ret = a6xx_rb_context_switch(adreno_dev, rb, drawctxt); 425: if (ret) { 426: kgsl_context_put(&drawctxt->base); 427: return ret; 428: } 429: 430: trace_adreno_drawctxt_switch(rb, drawctxt); 431: 432: /* Release the current drawctxt as soon as the new one is switched */ 433: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active, 434: rb, rb->timestamp); 435: 436: rb->drawctxt_active = drawctxt; 437: return 0; 438: } 439: 440: #define A6XX_USER_PROFILE_IB(rb, cmdobj, cmds, field) \ 441: a6xx_get_user_profiling_ib((rb), (cmdobj), \ 442: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 443: (cmds)) 444: 445: #define A6XX_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 446: a6xx_get_alwayson_counter((cmds), \ 447: (dev)->profile_buffer->gpuaddr + \ 448: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 449: field)) 450: 451: #define A6XX_KERNEL_PROFILE_CONTEXT(dev, cmdobj, cmds, field) \ 452: a6xx_get_alwayson_context((cmds), \ 453: (dev)->profile_buffer->gpuaddr + \ 454: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 455: field)) 456: 457: #define A6XX_COMMAND_DWORDS 40 458: MATCH LINES: 569, 573 557: * the upper layers know how to handle it 558: */ 559: if (ret != -ENOSPC && ret != -ENOENT) 560: dev_err(device->dev, 561: "Unable to switch draw context: %d\n", 562: ret); 563: goto done; 564: } 565: 566: adreno_drawobj_set_constraint(device, drawobj); 567: 568: ret = a6xx_ringbuffer_addcmds(adreno_dev, drawctxt->rb, drawctxt, 569: flags, cmds, index, drawobj->timestamp, time); 570: 571: done: 572: trace_kgsl_issueibcmds(device, drawctxt->base.id, numibs, 573: drawobj->timestamp, drawobj->flags, ret, drawctxt->type); 574: 575: kvfree(cmds); 576: return ret; 577: } --- FILE: \adreno_compat.c | HITS: 1 --- MATCH LINES: 64 52: memset(&shadowprop, 0, sizeof(shadowprop)); 53: if (device->memstore->hostptr) { 54: /* Give a token address to identify memstore */ 55: shadowprop.gpuaddr = (unsigned int) 56: KGSL_MEMSTORE_TOKEN_ADDRESS; 57: shadowprop.size = 58: (unsigned int) device->memstore->size; 59: /* 60: * GSL needs this to be set, even if it 61: * appears to be meaningless 62: */ 63: shadowprop.flags = KGSL_FLAGS_INITIALIZED | 64: KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS; 65: } 66: if (copy_to_user(param->value, &shadowprop, 67: sizeof(shadowprop))) { 68: status = -EFAULT; 69: break; 70: } 71: status = 0; 72: } 73: break; 74: default: 75: status = device->ftbl->getproperty(device, param); 76: } 77: 78: return status; 79: } 80: 81: int adreno_setproperty_compat(struct kgsl_device_private *dev_priv, 82: unsigned int type, 83: void __user *value, 84: unsigned int sizebytes) 85: { 86: int status = -EINVAL; 87: struct kgsl_device *device = dev_priv->device; 88: --- FILE: \adreno_debugfs.c | HITS: 16 --- MATCH LINES: 236, 238, 241, 243, 245, 247 224: DEFINE_DEBUGFS_ATTRIBUTE(_prealloc_atomic_snapshot_mem_fops, _prealloc_atomic_snap_mem_get, 225: _prealloc_atomic_snap_mem_set, "%llu\n"); 226: 227: typedef void (*reg_read_init_t)(struct kgsl_device *device); 228: typedef void (*reg_read_fill_t)(struct kgsl_device *device, int i, 229: unsigned int *vals, int linec); 230: 231: 232: static void sync_event_print(struct seq_file *s, 233: struct kgsl_drawobj_sync_event *sync_event) 234: { 235: switch (sync_event->type) { 236: case KGSL_CMD_SYNCPOINT_TYPE_TIMESTAMP: { 237: seq_printf(s, "sync: ctx: %u ts: %u", 238: sync_event->context->id, sync_event->timestamp); 239: break; 240: } 241: case KGSL_CMD_SYNCPOINT_TYPE_FENCE: { 242: int i; 243: struct event_fence_info *info = sync_event->priv; 244: 245: for (i = 0; info && i < info->num_fences; i++) 246: seq_printf(s, "sync: %s", 247: info->fences[i].name); 248: break; 249: } 250: case KGSL_CMD_SYNCPOINT_TYPE_TIMELINE: { 251: int j; 252: struct event_timeline_info *info = sync_event->priv; 253: 254: for (j = 0; info && info[j].timeline; j++) 255: seq_printf(s, "timeline: %d seqno: %lld", 256: info[j].timeline, info[j].seqno); 257: break; 258: } 259: default: 260: seq_printf(s, "sync: type: %d", sync_event->type); 261: break; 262: } 263: } 264: 265: struct flag_entry { 266: unsigned long mask; 267: const char *str; 268: }; 269: 270: static void _print_flags(struct seq_file *s, const struct flag_entry *table, 271: unsigned long flags) MATCH LINES: 327 315: } 316: 317: static void cmdobj_print(struct seq_file *s, 318: struct kgsl_drawobj_cmd *cmdobj) 319: { 320: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 321: 322: if (drawobj->type == CMDOBJ_TYPE) 323: seq_puts(s, " cmdobj "); 324: else 325: seq_puts(s, " markerobj "); 326: 327: seq_printf(s, "\t %u ", drawobj->timestamp); 328: 329: seq_puts(s, " priv: "); 330: print_flags(s, cmdobj->priv, 331: { BIT(CMDOBJ_SKIP), "skip"}, 332: { BIT(CMDOBJ_FORCE_PREAMBLE), "force_preamble"}, 333: { BIT(CMDOBJ_WFI), "wait_for_idle" }); 334: } 335: 336: static void drawobj_print(struct seq_file *s, 337: struct kgsl_drawobj *drawobj) 338: { 339: if (!kref_get_unless_zero(&drawobj->refcount)) 340: return; 341: 342: if (drawobj->type == SYNCOBJ_TYPE) 343: syncobj_print(s, SYNCOBJ(drawobj)); 344: else if ((drawobj->type == CMDOBJ_TYPE) || 345: (drawobj->type == MARKEROBJ_TYPE)) 346: cmdobj_print(s, CMDOBJ(drawobj)); 347: 348: seq_puts(s, " flags: "); 349: print_flags(s, drawobj->flags, KGSL_DRAWOBJ_FLAGS); 350: kgsl_drawobj_put(drawobj); 351: seq_puts(s, "\n"); MATCH LINES: 385, 386, 387, 388, 389, 390, 391, 394, 408 373: print_flags(s, drawctxt->base.priv, 374: { BIT(KGSL_CONTEXT_PRIV_SUBMITTED), "submitted"}, 375: { BIT(KGSL_CONTEXT_PRIV_DETACHED), "detached"}, 376: { BIT(KGSL_CONTEXT_PRIV_INVALID), "invalid"}, 377: { BIT(KGSL_CONTEXT_PRIV_PAGEFAULT), "pagefault"}, 378: { BIT(ADRENO_CONTEXT_FAULT), "fault"}, 379: { BIT(ADRENO_CONTEXT_GPU_HANG), "gpu_hang"}, 380: { BIT(ADRENO_CONTEXT_GPU_HANG_FT), "gpu_hang_ft"}, 381: { BIT(ADRENO_CONTEXT_SKIP_EOF), "skip_end_of_frame" }, 382: { BIT(ADRENO_CONTEXT_FORCE_PREAMBLE), "force_preamble"}); 383: seq_puts(s, "\n"); 384: 385: seq_puts(s, "timestamps: "); 386: kgsl_readtimestamp(drawctxt->base.device, &drawctxt->base, 387: KGSL_TIMESTAMP_QUEUED, &queued); 388: kgsl_readtimestamp(drawctxt->base.device, &drawctxt->base, 389: KGSL_TIMESTAMP_CONSUMED, &consumed); 390: kgsl_readtimestamp(drawctxt->base.device, &drawctxt->base, 391: KGSL_TIMESTAMP_RETIRED, &retired); 392: seq_printf(s, "queued: %u consumed: %u retired: %u global:%u\n", 393: queued, consumed, retired, 394: drawctxt->internal_timestamp); 395: 396: seq_puts(s, "drawqueue:\n"); 397: 398: spin_lock(&drawctxt->lock); 399: for (i = drawctxt->drawqueue_head; 400: i != drawctxt->drawqueue_tail; 401: i = DRAWQUEUE_NEXT(i, ADRENO_CONTEXT_DRAWQUEUE_SIZE)) 402: drawobj_print(s, drawctxt->drawqueue[i]); 403: spin_unlock(&drawctxt->lock); 404: 405: seq_puts(s, "events:\n"); 406: spin_lock(&drawctxt->base.events.lock); 407: list_for_each_entry(event, &drawctxt->base.events.events, node) 408: seq_printf(s, "\t%d: %pS created: %u\n", event->timestamp, 409: event->func, event->created); 410: spin_unlock(&drawctxt->base.events.lock); 411: 412: return 0; 413: } 414: 415: static int ctx_open(struct inode *inode, struct file *file) 416: { 417: int ret; 418: struct adreno_context *ctx = inode->i_private; 419: 420: if (!_kgsl_context_get(&ctx->base)) 421: return -ENODEV; 422: 423: ret = single_open(file, ctx_print, &ctx->base); 424: if (ret) 425: kgsl_context_put(&ctx->base); 426: return ret; 427: } 428: 429: static int ctx_release(struct inode *inode, struct file *file) 430: { 431: struct kgsl_context *context; 432: --- FILE: \adreno_dispatch.c | HITS: 96 --- MATCH LINES: 98, 107, 116, 120, 121, 124, 125, 127, 135, 139, 152, 180, 188, 189, 206, 215, 217 86: * have queued drop the inflight for better context switch latency. 87: * If no contexts have queued what are you even doing here? 88: */ 89: 90: static inline int 91: _drawqueue_inflight(struct adreno_dispatcher_drawqueue *drawqueue) 92: { 93: return (drawqueue->active_context_count > 1) 94: ? _dispatcher_q_inflight_lo : _dispatcher_q_inflight_hi; 95: } 96: 97: /** 98: * _retire_timestamp() - Retire object without sending it 99: * to the hardware 100: * @drawobj: Pointer to the object to retire 101: * 102: * In some cases ibs can be retired by the software 103: * without going to the GPU. In those cases, update the 104: * memstore from the CPU, kick off the event engine to handle 105: * expired events and destroy the ib. 106: */ 107: static void _retire_timestamp(struct kgsl_drawobj *drawobj) 108: { 109: struct kgsl_context *context = drawobj->context; 110: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 111: struct kgsl_device *device = context->device; 112: struct adreno_ringbuffer *rb = drawctxt->rb; 113: struct retire_info info = {0}; 114: 115: /* 116: * Write the start and end timestamp to the memstore to keep the 117: * accounting sane 118: */ 119: kgsl_sharedmem_writel(device->memstore, 120: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 121: drawobj->timestamp); 122: 123: kgsl_sharedmem_writel(device->memstore, 124: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 125: drawobj->timestamp); 126: 127: drawctxt->submitted_timestamp = drawobj->timestamp; 128: 129: /* Retire pending GPU events for the object */ 130: kgsl_process_event_group(device, &context->events); 131: 132: info.inflight = -1; 133: info.rb_id = rb->id; 134: info.wptr = rb->wptr; 135: info.timestamp = drawobj->timestamp; 136: 137: msm_perf_events_update(MSM_PERF_GFX, MSM_PERF_RETIRED, 138: pid_nr(context->proc_priv->pid), 139: context->id, drawobj->timestamp, 140: !!(drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME)); 141: 142: if (drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME) { 143: atomic64_inc(&context->proc_priv->frame_count); 144: atomic_inc(&context->proc_priv->period->frames); 145: } 146: 147: info.rptr = adreno_get_rptr(rb); 148: 149: trace_adreno_cmdbatch_retired(context, &info, 150: drawobj->flags, rb->dispatch_q.inflight, 0); 151: 152: log_kgsl_cmdbatch_retired_event(context->id, drawobj->timestamp, 153: context->priority, drawobj->flags, 0, 0); 154: 155: kgsl_drawobj_destroy(drawobj); 156: } 157: 158: static int _check_context_queue(struct adreno_context *drawctxt, u32 count) 159: { 160: int ret; 161: 162: spin_lock(&drawctxt->lock); 163: 164: /* 165: * Wake up if there is room in the context or if the whole thing got 166: * invalidated while we were asleep 167: */ 168: 169: if (kgsl_context_invalid(&drawctxt->base)) 170: ret = 1; 171: else 172: ret = ((drawctxt->queued + count) < _context_drawqueue_size) ? 1 : 0; 173: 174: spin_unlock(&drawctxt->lock); 175: 176: return ret; 177: } 178: 179: /* 180: * return true if this is a marker command and the dependent timestamp has 181: * retired 182: */ 183: static bool _marker_expired(struct kgsl_drawobj_cmd *markerobj) 184: { 185: struct kgsl_drawobj *drawobj = DRAWOBJ(markerobj); 186: 187: return (drawobj->flags & KGSL_DRAWOBJ_MARKER) && 188: kgsl_check_timestamp(drawobj->device, drawobj->context, 189: markerobj->marker_timestamp); 190: } 191: 192: static inline void _pop_drawobj(struct adreno_context *drawctxt) 193: { 194: drawctxt->drawqueue_head = DRAWQUEUE_NEXT(drawctxt->drawqueue_head, 195: ADRENO_CONTEXT_DRAWQUEUE_SIZE); 196: drawctxt->queued--; 197: } 198: 199: static int dispatch_retire_markerobj(struct kgsl_drawobj *drawobj, 200: struct adreno_context *drawctxt) 201: { 202: struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj); 203: 204: if (_marker_expired(cmdobj)) { 205: _pop_drawobj(drawctxt); 206: _retire_timestamp(drawobj); 207: return 0; 208: } 209: 210: /* 211: * If the marker isn't expired but the SKIP bit 212: * is set then there are real commands following 213: * this one in the queue. This means that we 214: * need to dispatch the command so that we can 215: * keep the timestamp accounting correct. If 216: * skip isn't set then we block this queue 217: * until the dependent timestamp expires 218: */ 219: return test_bit(CMDOBJ_SKIP, &cmdobj->priv) ? 1 : -EAGAIN; 220: } 221: 222: static int dispatch_retire_syncobj(struct kgsl_drawobj *drawobj, 223: struct adreno_context *drawctxt) 224: { 225: struct kgsl_drawobj_sync *syncobj = SYNCOBJ(drawobj); 226: 227: if (!kgsl_drawobj_events_pending(syncobj)) { 228: _pop_drawobj(drawctxt); 229: kgsl_drawobj_destroy(drawobj); 230: return 0; 231: } 232: 233: /* 234: * If we got here, there are pending events for sync object. 235: * Start the canary timer if it hasnt been started already. 236: */ 237: if (!syncobj->timeout_jiffies) { 238: syncobj->timeout_jiffies = jiffies + msecs_to_jiffies(5000); 239: mod_timer(&syncobj->timer, syncobj->timeout_jiffies); 240: } 241: MATCH LINES: 260, 283 248: _pop_drawobj(drawctxt); 249: kgsl_drawobj_destroy(drawobj); 250: return 0; 251: } 252: 253: static int drawqueue_retire_bindobj(struct kgsl_drawobj *drawobj, 254: struct adreno_context *drawctxt) 255: { 256: struct kgsl_drawobj_bind *bindobj = BINDOBJ(drawobj); 257: 258: if (test_bit(KGSL_BINDOBJ_STATE_DONE, &bindobj->state)) { 259: _pop_drawobj(drawctxt); 260: _retire_timestamp(drawobj); 261: return 0; 262: } 263: 264: if (!test_and_set_bit(KGSL_BINDOBJ_STATE_START, &bindobj->state)) { 265: /* 266: * Take a referencre to the drawobj and the context because both 267: * get referenced in the bind callback 268: */ 269: _kgsl_context_get(&drawctxt->base); 270: kref_get(&drawobj->refcount); 271: 272: kgsl_sharedmem_bind_ranges(bindobj->bind); 273: } 274: 275: return -EAGAIN; 276: } 277: 278: /* 279: * Retires all expired marker and sync objs from the context 280: * queue and returns one of the below 281: * a) next drawobj that needs to be sent to ringbuffer 282: * b) -EAGAIN for syncobj with syncpoints pending. 283: * c) -EAGAIN for markerobj whose marker timestamp has not expired yet. 284: * c) NULL for no commands remaining in drawqueue. 285: */ 286: static struct kgsl_drawobj *_process_drawqueue_get_next_drawobj( 287: struct adreno_context *drawctxt) 288: { 289: struct kgsl_drawobj *drawobj; 290: unsigned int i = drawctxt->drawqueue_head; 291: 292: if (drawctxt->drawqueue_head == drawctxt->drawqueue_tail) 293: return NULL; 294: 295: for (i = drawctxt->drawqueue_head; i != drawctxt->drawqueue_tail; 296: i = DRAWQUEUE_NEXT(i, ADRENO_CONTEXT_DRAWQUEUE_SIZE)) { 297: int ret = 0; 298: 299: drawobj = drawctxt->drawqueue[i]; 300: if (!drawobj) 301: return NULL; 302: 303: switch (drawobj->type) { 304: case CMDOBJ_TYPE: 305: return drawobj; 306: case MARKEROBJ_TYPE: 307: ret = dispatch_retire_markerobj(drawobj, drawctxt); MATCH LINES: 565, 572 553: if (dispatch_q->inflight == 1) 554: dispatch_q->expires = jiffies + 555: msecs_to_jiffies(adreno_drawobj_timeout); 556: 557: info.inflight = (int) dispatcher->inflight; 558: info.rb_id = drawctxt->rb->id; 559: info.rptr = adreno_get_rptr(drawctxt->rb); 560: info.wptr = drawctxt->rb->wptr; 561: info.gmu_dispatch_queue = -1; 562: 563: msm_perf_events_update(MSM_PERF_GFX, MSM_PERF_SUBMIT, 564: pid_nr(context->proc_priv->pid), 565: context->id, drawobj->timestamp, 566: !!(drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME)); 567: 568: trace_adreno_cmdbatch_submitted(drawobj, &info, 569: time.ticks, (unsigned long) secs, nsecs / 1000, 570: dispatch_q->inflight); 571: 572: log_kgsl_cmdbatch_submitted_event(context->id, drawobj->timestamp, 573: context->priority, drawobj->flags); 574: 575: kgsl_mutex_unlock(&device->mutex); 576: 577: cmdobj->submit_ticks = time.ticks; 578: 579: dispatch_q->cmd_q[dispatch_q->tail] = cmdobj; 580: dispatch_q->tail = (dispatch_q->tail + 1) % 581: ADRENO_DISPATCH_DRAWQUEUE_SIZE; 582: 583: /* 584: * If we believe ourselves to be current and preemption isn't a thing, 585: * then set up the timer. If this misses, then preemption is indeed a 586: * thing and the timer will be set up in due time 587: */ 588: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 589: if (drawqueue_is_current(dispatch_q)) 590: mod_timer(&dispatcher->timer, dispatch_q->expires); 591: } 592: 593: 594: /* 595: * we just submitted something, readjust ringbuffer 596: * execution level MATCH LINES: 623 611: * Dequeue and send a burst of commands from the specified context to the GPU 612: * Returns postive if the context needs to be put back on the pending queue 613: * 0 if the context is empty or detached and negative on error 614: */ 615: static int dispatcher_context_sendcmds(struct adreno_device *adreno_dev, 616: struct adreno_context *drawctxt) 617: { 618: struct adreno_dispatcher_drawqueue *dispatch_q = 619: &(drawctxt->rb->dispatch_q); 620: int count = 0; 621: int ret = 0; 622: int inflight = _drawqueue_inflight(dispatch_q); 623: unsigned int timestamp; 624: 625: if (dispatch_q->inflight >= inflight) { 626: spin_lock(&drawctxt->lock); 627: _process_drawqueue_get_next_drawobj(drawctxt); 628: spin_unlock(&drawctxt->lock); 629: return -EBUSY; 630: } 631: 632: /* 633: * Each context can send a specific number of drawobjs per cycle 634: */ 635: while ((count < _context_drawobj_burst) && 636: (dispatch_q->inflight < inflight)) { 637: struct kgsl_drawobj *drawobj; 638: struct kgsl_drawobj_cmd *cmdobj; 639: struct kgsl_context *context; 640: 641: if (adreno_gpu_fault(adreno_dev) != 0) 642: break; 643: 644: spin_lock(&drawctxt->lock); 645: drawobj = _process_drawqueue_get_next_drawobj(drawctxt); 646: 647: /* MATCH LINES: 663, 667, 693 651: * reqeueued 652: */ 653: 654: if (IS_ERR_OR_NULL(drawobj)) { 655: if (IS_ERR(drawobj)) 656: ret = PTR_ERR(drawobj); 657: spin_unlock(&drawctxt->lock); 658: break; 659: } 660: _pop_drawobj(drawctxt); 661: spin_unlock(&drawctxt->lock); 662: 663: timestamp = drawobj->timestamp; 664: cmdobj = CMDOBJ(drawobj); 665: context = drawobj->context; 666: trace_adreno_cmdbatch_ready(context->id, context->priority, 667: drawobj->timestamp, cmdobj->requeue_cnt); 668: ret = sendcmd(adreno_dev, cmdobj); 669: 670: /* 671: * On error from sendcmd() try to requeue the cmdobj 672: * unless we got back -ENOENT which means that the context has 673: * been detached and there will be no more deliveries from here 674: */ 675: if (ret != 0) { 676: /* Destroy the cmdobj on -ENOENT */ 677: if (ret == -ENOENT) 678: kgsl_drawobj_destroy(drawobj); 679: else { 680: /* 681: * If the requeue returns an error, return that 682: * instead of whatever sendcmd() sent us 683: */ 684: int r = adreno_dispatcher_requeue_cmdobj( 685: drawctxt, cmdobj); 686: if (r) 687: ret = r; 688: } 689: 690: break; 691: } 692: 693: drawctxt->submitted_timestamp = timestamp; 694: 695: count++; 696: } 697: 698: /* 699: * Wake up any snoozing threads if we have consumed any real commands 700: * or marker commands and we have room in the context queue. 701: */ 702: 703: if (_check_context_queue(drawctxt, 0)) 704: wake_up_all(&drawctxt->wq); 705: 706: if (!ret) 707: ret = count; 708: 709: /* Return error or the number of commands queued */ 710: return ret; 711: } 712: 713: static bool adreno_gpu_stopped(struct adreno_device *adreno_dev) 714: { 715: return (adreno_gpu_fault(adreno_dev) || adreno_gpu_halt(adreno_dev)); 716: } 717: MATCH LINES: 892, 895, 896, 898, 901, 902, 908, 909, 911, 914, 916, 918, 919 880: 881: if (dispatcher->inflight) 882: _dispatcher_update_timers(adreno_dev); 883: 884: mutex_unlock(&dispatcher->mutex); 885: _decrement_submit_now(device); 886: return; 887: done: 888: adreno_scheduler_queue(adreno_dev); 889: } 890: 891: /** 892: * get_timestamp() - Return the next timestamp for the context 893: * @drawctxt - Pointer to an adreno draw context struct 894: * @drawobj - Pointer to a drawobj 895: * @timestamp - Pointer to a timestamp value possibly passed from the user 896: * @user_ts - user generated timestamp 897: * 898: * Assign a timestamp based on the settings of the draw context and the command 899: * batch. 900: */ 901: static int get_timestamp(struct adreno_context *drawctxt, 902: struct kgsl_drawobj *drawobj, unsigned int *timestamp, 903: unsigned int user_ts) 904: { 905: 906: if (drawctxt->base.flags & KGSL_CONTEXT_USER_GENERATED_TS) { 907: /* 908: * User specified timestamps need to be greater than the last 909: * issued timestamp in the context 910: */ 911: if (timestamp_cmp(drawctxt->timestamp, user_ts) >= 0) 912: return -ERANGE; 913: 914: drawctxt->timestamp = user_ts; 915: } else 916: drawctxt->timestamp++; 917: 918: *timestamp = drawctxt->timestamp; 919: drawobj->timestamp = *timestamp; 920: return 0; 921: } 922: 923: static void _set_ft_policy(struct adreno_device *adreno_dev, 924: struct adreno_context *drawctxt, 925: struct kgsl_drawobj_cmd *cmdobj) 926: { 927: /* 928: * Set the fault tolerance policy for the command batch - assuming the 929: * context hasn't disabled FT use the current device policy 930: */ 931: if (drawctxt->base.flags & KGSL_CONTEXT_NO_FAULT_TOLERANCE) 932: set_bit(KGSL_FT_DISABLE, &cmdobj->fault_policy); 933: /* 934: * Set the fault tolerance policy to FT_REPLAY - As context wants 935: * to invalidate it after a replay attempt fails. This doesn't 936: * require to execute the default FT policy. 937: */ 938: else if (drawctxt->base.flags & KGSL_CONTEXT_INVALIDATE_ON_FAULT) 939: set_bit(KGSL_FT_REPLAY, &cmdobj->fault_policy); 940: else 941: cmdobj->fault_policy = adreno_dev->ft_policy; 942: } 943: MATCH LINES: 1053, 1059, 1063, 1067, 1077, 1078, 1081, 1088, 1093, 1101, 1102, 1103, 1108, 1109, 1113, 1114, 1125, 1131, 1152, 1162, 1164, 1165, 1176 1041: static void _queue_drawobj(struct adreno_context *drawctxt, 1042: struct kgsl_drawobj *drawobj) 1043: { 1044: struct kgsl_context *context = drawobj->context; 1045: 1046: /* Put the command into the queue */ 1047: drawctxt->drawqueue[drawctxt->drawqueue_tail] = drawobj; 1048: drawctxt->drawqueue_tail = (drawctxt->drawqueue_tail + 1) % 1049: ADRENO_CONTEXT_DRAWQUEUE_SIZE; 1050: drawctxt->queued++; 1051: msm_perf_events_update(MSM_PERF_GFX, MSM_PERF_QUEUE, 1052: pid_nr(context->proc_priv->pid), 1053: context->id, drawobj->timestamp, 1054: !!(drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME)); 1055: trace_adreno_cmdbatch_queued(drawobj, drawctxt->queued); 1056: } 1057: 1058: static int drawctxt_queue_bindobj(struct adreno_context *drawctxt, 1059: struct kgsl_drawobj *drawobj, u32 *timestamp, u32 user_ts) 1060: { 1061: int ret; 1062: 1063: ret = get_timestamp(drawctxt, drawobj, timestamp, user_ts); 1064: if (ret) 1065: return ret; 1066: 1067: drawctxt->queued_timestamp = *timestamp; 1068: _queue_drawobj(drawctxt, drawobj); 1069: 1070: return 0; 1071: } 1072: 1073: static void drawctxt_queue_timelineobj(struct adreno_context *drawctxt, 1074: struct kgsl_drawobj *drawobj) 1075: { 1076: /* 1077: * This drawobj is not submitted to the GPU so use a timestamp of 0. 1078: * Update the timestamp through a subsequent marker to keep userspace 1079: * happy. 1080: */ 1081: drawobj->timestamp = 0; 1082: 1083: _queue_drawobj(drawctxt, drawobj); 1084: } 1085: 1086: static int drawctxt_queue_markerobj(struct adreno_device *adreno_dev, 1087: struct adreno_context *drawctxt, struct kgsl_drawobj *drawobj, 1088: uint32_t *timestamp, unsigned int user_ts) 1089: { 1090: struct kgsl_drawobj_cmd *markerobj = CMDOBJ(drawobj); 1091: int ret; 1092: 1093: ret = get_timestamp(drawctxt, drawobj, timestamp, user_ts); 1094: if (ret) 1095: return ret; 1096: 1097: /* 1098: * See if we can fastpath this thing - if nothing is queued 1099: * and nothing is inflight retire without bothering the GPU 1100: */ 1101: if (!drawctxt->queued && kgsl_check_timestamp(drawobj->device, 1102: drawobj->context, drawctxt->queued_timestamp)) { 1103: _retire_timestamp(drawobj); 1104: return 1; 1105: } 1106: 1107: /* 1108: * Remember the last queued timestamp - the marker will block 1109: * until that timestamp is expired (unless another command 1110: * comes along and forces the marker to execute) 1111: */ 1112: 1113: markerobj->marker_timestamp = drawctxt->queued_timestamp; 1114: drawctxt->queued_timestamp = *timestamp; 1115: _set_ft_policy(adreno_dev, drawctxt, markerobj); 1116: _cmdobj_set_flags(drawctxt, markerobj); 1117: 1118: _queue_drawobj(drawctxt, drawobj); 1119: 1120: return 0; 1121: } 1122: 1123: static int drawctxt_queue_cmdobj(struct adreno_device *adreno_dev, 1124: struct adreno_context *drawctxt, struct kgsl_drawobj *drawobj, 1125: uint32_t *timestamp, unsigned int user_ts) 1126: { 1127: struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj); 1128: unsigned int j; 1129: int ret; 1130: 1131: ret = get_timestamp(drawctxt, drawobj, timestamp, user_ts); 1132: if (ret) 1133: return ret; 1134: 1135: /* 1136: * If this is a real command then we need to force any markers 1137: * queued before it to dispatch to keep time linear - set the 1138: * skip bit so the commands get NOPed. 1139: */ 1140: j = drawctxt->drawqueue_head; 1141: 1142: while (j != drawctxt->drawqueue_tail) { 1143: if (drawctxt->drawqueue[j]->type == MARKEROBJ_TYPE) { 1144: struct kgsl_drawobj_cmd *markerobj = 1145: CMDOBJ(drawctxt->drawqueue[j]); 1146: set_bit(CMDOBJ_SKIP, &markerobj->priv); 1147: } 1148: 1149: j = DRAWQUEUE_NEXT(j, ADRENO_CONTEXT_DRAWQUEUE_SIZE); 1150: } 1151: 1152: drawctxt->queued_timestamp = *timestamp; 1153: _set_ft_policy(adreno_dev, drawctxt, cmdobj); 1154: _cmdobj_set_flags(drawctxt, cmdobj); 1155: 1156: _queue_drawobj(drawctxt, drawobj); 1157: 1158: return 0; 1159: } 1160: 1161: static void drawctxt_queue_syncobj(struct adreno_context *drawctxt, 1162: struct kgsl_drawobj *drawobj, uint32_t *timestamp) 1163: { 1164: *timestamp = 0; 1165: drawobj->timestamp = 0; 1166: 1167: _queue_drawobj(drawctxt, drawobj); 1168: } 1169: 1170: /* 1171: * Queue a command in the context - if there isn't any room in the queue, then 1172: * block until there is 1173: */ 1174: static int adreno_dispatcher_queue_cmds(struct kgsl_device_private *dev_priv, 1175: struct kgsl_context *context, struct kgsl_drawobj *drawobj[], 1176: uint32_t count, uint32_t *timestamp) 1177: 1178: { 1179: struct kgsl_device *device = dev_priv->device; 1180: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1181: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 1182: struct adreno_dispatcher_drawqueue *dispatch_q; 1183: struct adreno_dispatch_job *job; 1184: int ret; 1185: unsigned int i, user_ts; 1186: 1187: /* 1188: * There is always a possibility that dispatcher may end up pushing 1189: * the last popped draw object back to the context drawqueue. Hence, 1190: * we can only queue up to _context_drawqueue_size - 1 here to make 1191: * sure we never let drawqueue->queued exceed _context_drawqueue_size. 1192: */ 1193: if (!count || count > _context_drawqueue_size - 1) 1194: return -EINVAL; 1195: 1196: ret = kgsl_check_context_state(&drawctxt->base); 1197: if (ret) 1198: return ret; 1199: 1200: ret = adreno_verify_cmdobj(dev_priv, context, drawobj, count); MATCH LINES: 1222, 1231, 1232, 1234, 1246, 1259, 1267, 1271 1210: 1211: job->drawctxt = drawctxt; 1212: 1213: spin_lock(&drawctxt->lock); 1214: 1215: ret = _check_context_state_to_queue_cmds(drawctxt, count); 1216: if (ret) { 1217: spin_unlock(&drawctxt->lock); 1218: kmem_cache_free(jobs_cache, job); 1219: return ret; 1220: } 1221: 1222: user_ts = *timestamp; 1223: 1224: /* 1225: * If there is only one drawobj in the array and it is of 1226: * type SYNCOBJ_TYPE, skip comparing user_ts as it can be 0 1227: */ 1228: if (!(count == 1 && drawobj[0]->type == SYNCOBJ_TYPE) && 1229: (drawctxt->base.flags & KGSL_CONTEXT_USER_GENERATED_TS)) { 1230: /* 1231: * User specified timestamps need to be greater than the last 1232: * issued timestamp in the context 1233: */ 1234: if (timestamp_cmp(drawctxt->timestamp, user_ts) >= 0) { 1235: spin_unlock(&drawctxt->lock); 1236: kmem_cache_free(jobs_cache, job); 1237: return -ERANGE; 1238: } 1239: } 1240: 1241: for (i = 0; i < count; i++) { 1242: 1243: switch (drawobj[i]->type) { 1244: case MARKEROBJ_TYPE: 1245: ret = drawctxt_queue_markerobj(adreno_dev, drawctxt, 1246: drawobj[i], timestamp, user_ts); 1247: if (ret) { 1248: spin_unlock(&drawctxt->lock); 1249: kmem_cache_free(jobs_cache, job); 1250: } 1251: 1252: if (ret == 1) 1253: goto done; 1254: else if (ret) 1255: return ret; 1256: break; 1257: case CMDOBJ_TYPE: 1258: ret = drawctxt_queue_cmdobj(adreno_dev, drawctxt, 1259: drawobj[i], timestamp, user_ts); 1260: if (ret) { 1261: spin_unlock(&drawctxt->lock); 1262: kmem_cache_free(jobs_cache, job); 1263: return ret; 1264: } 1265: break; 1266: case SYNCOBJ_TYPE: 1267: drawctxt_queue_syncobj(drawctxt, drawobj[i], timestamp); 1268: break; 1269: case BINDOBJ_TYPE: 1270: ret = drawctxt_queue_bindobj(drawctxt, drawobj[i], 1271: timestamp, user_ts); 1272: if (ret) { 1273: spin_unlock(&drawctxt->lock); 1274: kmem_cache_free(jobs_cache, job); 1275: return ret; 1276: } 1277: break; 1278: case TIMELINEOBJ_TYPE: 1279: drawctxt_queue_timelineobj(drawctxt, drawobj[i]); 1280: break; 1281: default: 1282: spin_unlock(&drawctxt->lock); 1283: kmem_cache_free(jobs_cache, job); 1284: return -EINVAL; 1285: } 1286: 1287: } 1288: 1289: dispatch_q = &(ADRENO_CONTEXT(drawobj[0]->context)->rb->dispatch_q); 1290: 1291: adreno_track_context(adreno_dev, dispatch_q, drawctxt); 1292: 1293: spin_unlock(&drawctxt->lock); 1294: 1295: /* Add the context to the dispatcher pending list */ MATCH LINES: 1454, 1455, 1487, 1512, 1515, 1523 1442: 1443: for (i = 0; i < count; i++) { 1444: struct kgsl_drawobj_cmd *cmdobj = replay[i]; 1445: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 1446: 1447: if (cmdobj == NULL) 1448: continue; 1449: 1450: if (kgsl_context_is_bad(drawobj->context)) { 1451: replay[i] = NULL; 1452: 1453: kgsl_mutex_lock(&device->mutex); 1454: kgsl_cancel_events_timestamp(device, 1455: &drawobj->context->events, drawobj->timestamp); 1456: kgsl_mutex_unlock(&device->mutex); 1457: 1458: kgsl_drawobj_destroy(drawobj); 1459: } 1460: } 1461: } 1462: 1463: #define pr_fault(_d, _c, fmt, args...) \ 1464: pr_context(_d, (_c)->context, fmt, ##args) 1465: 1466: static void adreno_fault_header(struct kgsl_device *device, 1467: struct adreno_ringbuffer *rb, struct kgsl_drawobj_cmd *cmdobj, 1468: int fault) 1469: { 1470: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1471: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 1472: struct adreno_context *drawctxt = 1473: drawobj ? ADRENO_CONTEXT(drawobj->context) : NULL; 1474: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1475: unsigned int status, rptr, wptr, ib1sz, ib2sz; 1476: uint64_t ib1base, ib2base; 1477: bool gx_on = adreno_gx_is_on(adreno_dev); 1478: int id = (rb != NULL) ? rb->id : -1; 1479: const char *type = fault & ADRENO_GMU_FAULT ? "gmu" : "gpu"; 1480: 1481: if (!gx_on) { 1482: if (drawobj != NULL) { 1483: pr_fault(device, drawobj, 1484: "%s fault ctx %u ctx_type %s ts %u and GX is OFF\n", 1485: type, drawobj->context->id, 1486: kgsl_context_type(drawctxt->type), 1487: drawobj->timestamp); 1488: pr_fault(device, drawobj, "cmdline: %s\n", 1489: drawctxt->base.proc_priv->cmdline); 1490: } else 1491: dev_err(device->dev, "RB[%d] : %s fault and GX is OFF\n", 1492: id, type); 1493: 1494: return; 1495: } 1496: 1497: if (gpudev->fault_header) 1498: return gpudev->fault_header(adreno_dev, drawobj); 1499: 1500: adreno_readreg(adreno_dev, ADRENO_REG_RBBM_STATUS, &status); 1501: adreno_readreg(adreno_dev, ADRENO_REG_CP_RB_RPTR, &rptr); 1502: adreno_readreg(adreno_dev, ADRENO_REG_CP_RB_WPTR, &wptr); 1503: adreno_readreg64(adreno_dev, ADRENO_REG_CP_IB1_BASE, 1504: ADRENO_REG_CP_IB1_BASE_HI, &ib1base); 1505: adreno_readreg(adreno_dev, ADRENO_REG_CP_IB1_BUFSZ, &ib1sz); 1506: adreno_readreg64(adreno_dev, ADRENO_REG_CP_IB2_BASE, 1507: ADRENO_REG_CP_IB2_BASE_HI, &ib2base); 1508: adreno_readreg(adreno_dev, ADRENO_REG_CP_IB2_BUFSZ, &ib2sz); 1509: 1510: if (drawobj != NULL) { 1511: drawctxt->base.total_fault_count++; 1512: drawctxt->base.last_faulted_cmd_ts = drawobj->timestamp; 1513: 1514: trace_adreno_gpu_fault(drawobj->context->id, 1515: drawobj->timestamp, 1516: status, rptr, wptr, ib1base, ib1sz, 1517: ib2base, ib2sz, drawctxt->rb->id); 1518: 1519: pr_fault(device, drawobj, 1520: "%s fault ctx %u ctx_type %s ts %u status %8.8X rb %4.4x/%4.4x ib1 %16.16llX/%4.4x ib2 %16.16llX/%4.4x\n", 1521: type, drawobj->context->id, 1522: kgsl_context_type(drawctxt->type), 1523: drawobj->timestamp, status, 1524: rptr, wptr, ib1base, ib1sz, ib2base, ib2sz); 1525: 1526: pr_fault(device, drawobj, "cmdline: %s\n", 1527: drawctxt->base.proc_priv->cmdline); 1528: 1529: if (rb != NULL) 1530: pr_fault(device, drawobj, 1531: "%s fault rb %d rb sw r/w %4.4x/%4.4x\n", 1532: type, rb->id, rptr, rb->wptr); 1533: } else { 1534: dev_err(device->dev, 1535: "RB[%d] : %s fault status %8.8X rb %4.4x/%4.4x ib1 %16.16llX/%4.4x ib2 %16.16llX/%4.4x\n", 1536: id, type, status, rptr, wptr, ib1base, ib1sz, ib2base, 1537: ib2sz); 1538: if (rb != NULL) 1539: dev_err(device->dev, 1540: "RB[%d] : %s fault rb sw r/w %4.4x/%4.4x\n", 1541: rb->id, type, rptr, rb->wptr); 1542: } 1543: } 1544: 1545: void adreno_fault_skipcmd_detached(struct adreno_device *adreno_dev, 1546: struct adreno_context *drawctxt, 1547: struct kgsl_drawobj *drawobj) MATCH LINES: 1726 1714: 1715: /* 1716: * Skip all the pending cmdobj's for this context until 1717: * the EOF frame is seen 1718: */ 1719: _skip_frame(cmdobj, replay, count); 1720: return; 1721: } 1722: 1723: /* If we get here then all the policies failed */ 1724: 1725: pr_context(device, drawobj->context, "gpu %s ctx %d ts %u\n", 1726: state, drawobj->context->id, drawobj->timestamp); 1727: 1728: /* Mark the context as failed and invalidate it */ 1729: adreno_drawctxt_set_guilty(device, drawobj->context); 1730: } 1731: 1732: /** 1733: * recover_dispatch_q() - Recover all commands in a dispatch queue by 1734: * resubmitting the commands 1735: * @device: Device on which recovery is performed 1736: * @dispatch_q: The command queue to recover 1737: * @fault: Faults caused by the command in the dispatch q 1738: * @base: The IB1 base during the fault 1739: */ 1740: static void recover_dispatch_q(struct kgsl_device *device, 1741: struct adreno_dispatcher_drawqueue *dispatch_q, 1742: int fault, 1743: unsigned int base) 1744: { 1745: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1746: struct kgsl_drawobj_cmd **replay; 1747: unsigned int ptr; 1748: int first = 0; 1749: int count = 0; 1750: int i; MATCH LINES: 1833 1821: 1822: ret = sendcmd(adreno_dev, replay[i]); 1823: 1824: /* 1825: * If sending the command fails, then try to recover by 1826: * invalidating the context 1827: */ 1828: 1829: if (ret) { 1830: pr_context(device, replay[i]->base.context, 1831: "gpu reset failed ctx %u ts %u\n", 1832: replay[i]->base.context->id, 1833: replay[i]->base.timestamp); 1834: 1835: /* Mark this context as guilty (failed recovery) */ 1836: adreno_drawctxt_set_guilty(device, replay[i]->base.context); 1837: remove_invalidated_cmdobjs(device, &replay[i], 1838: count - i); 1839: } 1840: } 1841: 1842: /* Clear the fault bit */ 1843: clear_bit(ADRENO_DEVICE_FAULT, &adreno_dev->priv); 1844: 1845: kfree(replay); 1846: } 1847: 1848: static void do_header_and_snapshot(struct kgsl_device *device, int fault, 1849: struct adreno_ringbuffer *rb, struct kgsl_drawobj_cmd *cmdobj) 1850: { 1851: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 1852: 1853: /* Always dump the snapshot on a non-drawobj failure */ 1854: if (cmdobj == NULL) { 1855: adreno_fault_header(device, rb, NULL, fault); 1856: 1857: /* GMU snapshot will also pull a full device snapshot */ MATCH LINES: 2036, 2041, 2042, 2045, 2046, 2081, 2082, 2115 2024: dispatcher->inflight = 0; 2025: 2026: /* Remove the bus hint */ 2027: device->pwrctrl.rt_bus_hint_active = false; 2028: 2029: /* Reset the GPU and make sure halt is not set during recovery */ 2030: halt = adreno_gpu_halt(adreno_dev); 2031: adreno_clear_gpu_halt(adreno_dev); 2032: 2033: /* 2034: * If there is a stall in the ringbuffer after all commands have been 2035: * retired then we could hit problems if contexts are waiting for 2036: * internal timestamps that will never retire 2037: */ 2038: 2039: if (hung_rb != NULL) { 2040: kgsl_sharedmem_writel(device->memstore, 2041: MEMSTORE_RB_OFFSET(hung_rb, soptimestamp), 2042: hung_rb->timestamp); 2043: 2044: kgsl_sharedmem_writel(device->memstore, 2045: MEMSTORE_RB_OFFSET(hung_rb, eoptimestamp), 2046: hung_rb->timestamp); 2047: 2048: /* Schedule any pending events to be run */ 2049: kgsl_process_event_group(device, &hung_rb->events); 2050: } 2051: 2052: ret = adreno_reset(device, fault); 2053: 2054: /* If adreno_reset() fails then what hope do we have for the future? */ 2055: BUG_ON(ret); 2056: 2057: /* if any other fault got in until reset then ignore */ 2058: adreno_clear_gpu_fault(adreno_dev); 2059: 2060: kgsl_mutex_unlock(&device->mutex); 2061: 2062: mutex_unlock(&adreno_dev->fault_recovery_mutex); 2063: 2064: /* recover all the dispatch_q's starting with the one that hung */ 2065: if (dispatch_q) 2066: recover_dispatch_q(device, dispatch_q, fault, base); 2067: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2068: dispatch_q_temp = &(rb->dispatch_q); 2069: if (dispatch_q_temp != dispatch_q) 2070: recover_dispatch_q(device, dispatch_q_temp, 0, base); 2071: } 2072: 2073: atomic_add(halt, &adreno_dev->halt); 2074: 2075: return 1; 2076: } 2077: 2078: static inline int drawobj_consumed(struct kgsl_drawobj *drawobj, 2079: unsigned int consumed, unsigned int retired) 2080: { 2081: return ((timestamp_cmp(drawobj->timestamp, consumed) >= 0) && 2082: (timestamp_cmp(retired, drawobj->timestamp) < 0)); 2083: } 2084: 2085: static const char *_ft_type(enum kgsl_ft_policy_bits nr) 2086: { 2087: if (nr == KGSL_FT_OFF) 2088: return "off"; 2089: else if (nr == KGSL_FT_REPLAY) 2090: return "replay"; 2091: else if (nr == KGSL_FT_SKIPIB) 2092: return "skipib"; 2093: else if (nr == KGSL_FT_SKIPFRAME) 2094: return "skipfame"; 2095: else if (nr == KGSL_FT_DISABLE) 2096: return "disable"; 2097: else if (nr == KGSL_FT_TEMP_DISABLE) 2098: return "temp"; 2099: else if (nr == KGSL_FT_THROTTLE) 2100: return "throttle"; 2101: else if (nr == KGSL_FT_SKIPCMD) 2102: return "skipcmd"; 2103: 2104: return ""; 2105: } 2106: 2107: static void _print_recovery(struct kgsl_device *device, 2108: struct kgsl_drawobj_cmd *cmdobj) 2109: { 2110: int nr = find_first_bit(&cmdobj->fault_recovery, BITS_PER_LONG); 2111: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 2112: 2113: pr_context(device, drawobj->context, 2114: "gpu %s ctx %u ts %u policy %lX\n", 2115: _ft_type(nr), drawobj->context->id, drawobj->timestamp, 2116: cmdobj->fault_recovery); 2117: } 2118: 2119: static void cmdobj_profile_ticks(struct adreno_device *adreno_dev, 2120: struct kgsl_drawobj_cmd *cmdobj, uint64_t *start, uint64_t *retire, 2121: uint64_t *active) 2122: { 2123: void *ptr = adreno_dev->profile_buffer->hostptr; 2124: struct adreno_drawobj_profile_entry *entry; 2125: 2126: entry = (struct adreno_drawobj_profile_entry *) 2127: (ptr + (cmdobj->profile_index * sizeof(*entry))); 2128: 2129: /* get updated values of started and retired */ 2130: rmb(); 2131: *start = entry->started; 2132: *retire = entry->retired; 2133: if (ADRENO_GPUREV(adreno_dev) < 600) 2134: *active = entry->retired - entry->started; 2135: else 2136: *active = entry->ctx_end - entry->ctx_start; 2137: } 2138: 2139: static void retire_cmdobj(struct adreno_device *adreno_dev, MATCH LINES: 2161, 2173, 2186, 2196, 2212, 2213 2149: 2150: if (cmdobj->fault_recovery != 0) { 2151: set_bit(ADRENO_CONTEXT_FAULT, &drawobj->context->priv); 2152: _print_recovery(KGSL_DEVICE(adreno_dev), cmdobj); 2153: } 2154: 2155: if (test_bit(CMDOBJ_PROFILE, &cmdobj->priv)) 2156: cmdobj_profile_ticks(adreno_dev, cmdobj, &start, &end, &active); 2157: 2158: info.inflight = (int)dispatcher->inflight; 2159: info.rb_id = rb->id; 2160: info.wptr = rb->wptr; 2161: info.timestamp = drawobj->timestamp; 2162: info.sop = start; 2163: info.eop = end; 2164: info.active = active; 2165: 2166: /* protected GPU work must not be reported */ 2167: if (!(context->flags & KGSL_CONTEXT_SECURE)) 2168: kgsl_work_period_update(KGSL_DEVICE(adreno_dev), 2169: context->proc_priv->period, active); 2170: 2171: msm_perf_events_update(MSM_PERF_GFX, MSM_PERF_RETIRED, 2172: pid_nr(context->proc_priv->pid), 2173: context->id, drawobj->timestamp, 2174: !!(drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME)); 2175: 2176: if (drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME) { 2177: atomic64_inc(&context->proc_priv->frame_count); 2178: atomic_inc(&context->proc_priv->period->frames); 2179: } 2180: 2181: info.rptr = adreno_get_rptr(rb); 2182: trace_adreno_cmdbatch_retired(drawobj->context, &info, 2183: drawobj->flags, rb->dispatch_q.inflight, 2184: cmdobj->fault_recovery); 2185: 2186: log_kgsl_cmdbatch_retired_event(context->id, drawobj->timestamp, 2187: context->priority, drawobj->flags, start, end); 2188: 2189: drawctxt->submit_retire_ticks[drawctxt->ticks_index] = 2190: end - cmdobj->submit_ticks; 2191: 2192: drawctxt->ticks_index = (drawctxt->ticks_index + 1) % 2193: SUBMIT_RETIRE_TICKS_SIZE; 2194: 2195: trace_adreno_cmdbatch_done(drawobj->context->id, 2196: drawobj->context->priority, drawobj->timestamp); 2197: kgsl_drawobj_destroy(drawobj); 2198: } 2199: 2200: static int adreno_dispatch_retire_drawqueue(struct adreno_device *adreno_dev, 2201: struct adreno_dispatcher_drawqueue *drawqueue) 2202: { 2203: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2204: struct adreno_dispatcher *dispatcher = &adreno_dev->dispatcher; 2205: int count = 0; 2206: 2207: while (!adreno_drawqueue_is_empty(drawqueue)) { 2208: struct kgsl_drawobj_cmd *cmdobj = 2209: drawqueue->cmd_q[drawqueue->head]; 2210: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 2211: 2212: if (!kgsl_check_timestamp(device, drawobj->context, 2213: drawobj->timestamp)) 2214: break; 2215: 2216: retire_cmdobj(adreno_dev, cmdobj); 2217: 2218: dispatcher->inflight--; 2219: drawqueue->inflight--; 2220: 2221: drawqueue->cmd_q[drawqueue->head] = NULL; 2222: 2223: drawqueue->head = DRAWQUEUE_NEXT(drawqueue->head, 2224: ADRENO_DISPATCH_DRAWQUEUE_SIZE); 2225: 2226: count++; 2227: } 2228: 2229: return count; 2230: } 2231: 2232: static void _adreno_dispatch_check_timeout(struct adreno_device *adreno_dev, 2233: struct adreno_dispatcher_drawqueue *drawqueue) 2234: { 2235: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2236: struct kgsl_drawobj *drawobj = 2237: DRAWOBJ(drawqueue->cmd_q[drawqueue->head]); MATCH LINES: 2252 2240: if (time_is_after_jiffies(drawqueue->expires)) 2241: return; 2242: 2243: /* Don't timeout if the IB timeout is disabled globally */ 2244: if (!adreno_long_ib_detect(adreno_dev)) 2245: return; 2246: 2247: /* Don't time out if the context has disabled it */ 2248: if (drawobj->context->flags & KGSL_CONTEXT_NO_FAULT_TOLERANCE) 2249: return; 2250: 2251: pr_context(device, drawobj->context, "gpu timeout ctx %u ts %u\n", 2252: drawobj->context->id, drawobj->timestamp); 2253: 2254: adreno_set_gpu_fault(adreno_dev, ADRENO_TIMEOUT_FAULT); 2255: 2256: /* 2257: * This makes sure dispatcher doesn't run endlessly in cases where 2258: * we couldn't run recovery 2259: */ 2260: drawqueue->expires = jiffies + msecs_to_jiffies(adreno_drawobj_timeout); 2261: } 2262: 2263: static int adreno_dispatch_process_drawqueue(struct adreno_device *adreno_dev, 2264: struct adreno_dispatcher_drawqueue *drawqueue) 2265: { 2266: int count = adreno_dispatch_retire_drawqueue(adreno_dev, drawqueue); 2267: 2268: /* Nothing to do if there are no pending commands */ 2269: if (adreno_drawqueue_is_empty(drawqueue)) 2270: return count; 2271: 2272: /* Don't update the drawqueue timeout if it isn't active */ 2273: if (!drawqueue_is_current(drawqueue)) 2274: return count; 2275: 2276: /* MATCH LINES: 2459, 2482, 2484, 2485 2447: } 2448: 2449: static void change_preemption(struct adreno_device *adreno_dev, void *priv) 2450: { 2451: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2452: struct kgsl_context *context; 2453: struct adreno_context *drawctxt; 2454: struct adreno_ringbuffer *rb; 2455: int id, i, ret; 2456: 2457: /* Make sure all ringbuffers are finished */ 2458: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2459: ret = adreno_ringbuffer_waittimestamp(rb, rb->timestamp, 2460: 2 * 1000); 2461: if (ret) { 2462: dev_err(device->dev, 2463: "Cannot disable preemption because couldn't idle ringbuffer[%d] ret: %d\n", 2464: rb->id, ret); 2465: return; 2466: } 2467: } 2468: 2469: change_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 2470: adreno_dev->cur_rb = &adreno_dev->ringbuffers[0]; 2471: adreno_dev->next_rb = NULL; 2472: adreno_dev->prev_rb = NULL; 2473: 2474: /* Update the ringbuffer for each draw context */ 2475: write_lock(&device->context_lock); 2476: idr_for_each_entry(&device->context_idr, context, id) { 2477: drawctxt = ADRENO_CONTEXT(context); 2478: drawctxt->rb = dispatch_get_rb(adreno_dev, drawctxt); 2479: 2480: /* 2481: * Make sure context destroy checks against the correct 2482: * ringbuffer's timestamp. 2483: */ 2484: adreno_rb_readtimestamp(adreno_dev, drawctxt->rb, 2485: KGSL_TIMESTAMP_RETIRED, &drawctxt->internal_timestamp); 2486: } 2487: write_unlock(&device->context_lock); 2488: } 2489: 2490: static int _preemption_store(struct adreno_device *adreno_dev, bool val) 2491: { 2492: if (!adreno_preemption_feature_set(adreno_dev) || 2493: (test_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv) == val)) 2494: return 0; 2495: 2496: return adreno_power_cycle(adreno_dev, change_preemption, NULL); 2497: } 2498: 2499: static bool _preemption_show(struct adreno_device *adreno_dev) 2500: { 2501: return adreno_is_preemption_enabled(adreno_dev); 2502: } 2503: 2504: static unsigned int _preempt_count_show(struct adreno_device *adreno_dev) 2505: { 2506: return adreno_dev->preempt.count; 2507: } 2508: 2509: static int _ft_long_ib_detect_store(struct adreno_device *adreno_dev, bool val) --- FILE: \adreno_drawctxt.c | HITS: 56 --- MATCH LINES: 22, 23, 29, 38, 48, 49, 50, 58, 74, 81, 97, 130, 133, 136, 142, 155, 157, 170, 174, 192, 197, 199, 201, 207, 214, 222, 224, 227 10: #include "adreno_pm4types.h" 11: #include "adreno_trace.h" 12: #include "kgsl_util.h" 13: 14: static void wait_callback(struct kgsl_device *device, 15: struct kgsl_event_group *group, void *priv, int result) 16: { 17: struct adreno_context *drawctxt = priv; 18: 19: wake_up_all(&drawctxt->waiting); 20: } 21: 22: static int _check_context_timestamp(struct kgsl_device *device, 23: struct kgsl_context *context, unsigned int timestamp) 24: { 25: /* Bail if the drawctxt has been invalidated or destroyed */ 26: if (kgsl_context_is_bad(context)) 27: return 1; 28: 29: return kgsl_check_timestamp(device, context, timestamp); 30: } 31: 32: /** 33: * adreno_drawctxt_dump() - dump information about a draw context 34: * @device: KGSL device that owns the context 35: * @context: KGSL context to dump information about 36: * 37: * Dump specific information about the context to the kernel log. Used for 38: * fence timeout callbacks 39: */ 40: void adreno_drawctxt_dump(struct kgsl_device *device, 41: struct kgsl_context *context) 42: { 43: unsigned int queue, start, retire; 44: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 45: int index, pos; 46: char buf[120]; 47: 48: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_QUEUED, &queue); 49: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_CONSUMED, &start); 50: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, &retire); 51: 52: /* 53: * We may have kgsl sync obj timer running, which also uses same 54: * lock, take a lock with software interrupt disabled (bh) 55: * to avoid spin lock recursion. 56: * 57: * Use Spin trylock because dispatcher can acquire drawctxt->lock 58: * if context is pending and the fence it is waiting on just got 59: * signalled. Dispatcher acquires drawctxt->lock and tries to 60: * delete the sync obj timer using kgsl_delete_timer_sync(). 61: * kgsl_delete_timer_sync() waits till timer and its pending handlers 62: * are deleted. But if the timer expires at the same time, 63: * timer handler could be waiting on drawctxt->lock leading to a 64: * deadlock. To prevent this use spin_trylock_bh. 65: */ 66: if (!spin_trylock_bh(&drawctxt->lock)) { 67: dev_err(device->dev, " context[%u]: could not get lock\n", 68: context->id); 69: return; 70: } 71: 72: dev_err(device->dev, 73: " context[%u]: queue=%u, submit=%u, start=%u, retire=%u\n", 74: context->id, queue, drawctxt->submitted_timestamp, 75: start, retire); 76: 77: if (drawctxt->drawqueue_head != drawctxt->drawqueue_tail) { 78: struct kgsl_drawobj *drawobj = 79: drawctxt->drawqueue[drawctxt->drawqueue_head]; 80: 81: if (test_bit(ADRENO_CONTEXT_FENCE_LOG, &context->priv)) { 82: dev_err(device->dev, 83: " possible deadlock. Context %u might be blocked for itself\n", 84: context->id); 85: goto stats; 86: } 87: 88: if (!kref_get_unless_zero(&drawobj->refcount)) 89: goto stats; 90: 91: if (drawobj->type == SYNCOBJ_TYPE) { 92: struct kgsl_drawobj_sync *syncobj = SYNCOBJ(drawobj); 93: 94: if (kgsl_drawobj_events_pending(syncobj)) { 95: dev_err(device->dev, 96: " context[%u] (ts=%u) Active sync points:\n", 97: context->id, drawobj->timestamp); 98: 99: kgsl_dump_syncpoints(device, syncobj); 100: } 101: } 102: 103: kgsl_drawobj_put(drawobj); 104: } 105: 106: stats: 107: memset(buf, 0, sizeof(buf)); 108: 109: pos = 0; 110: 111: for (index = 0; index < SUBMIT_RETIRE_TICKS_SIZE; index++) { 112: uint64_t msecs; 113: unsigned int usecs; 114: 115: if (!drawctxt->submit_retire_ticks[index]) 116: continue; 117: msecs = drawctxt->submit_retire_ticks[index] * 10; 118: usecs = do_div(msecs, 192); 119: usecs = do_div(msecs, 1000); 120: pos += scnprintf(buf + pos, sizeof(buf) - pos, "%u.%0u ", 121: (unsigned int)msecs, usecs); 122: } 123: dev_err(device->dev, " context[%u]: submit times: %s\n", 124: context->id, buf); 125: 126: spin_unlock_bh(&drawctxt->lock); 127: } 128: 129: /** 130: * adreno_drawctxt_wait() - sleep until a timestamp expires 131: * @adreno_dev: pointer to the adreno_device struct 132: * @drawctxt: Pointer to the draw context to sleep for 133: * @timetamp: Timestamp to wait on 134: * @timeout: Number of jiffies to wait (0 for infinite) 135: * 136: * Register an event to wait for a timestamp on a context and sleep until it 137: * has past. Returns < 0 on error, -ETIMEDOUT if the timeout expires or 0 138: * on success 139: */ 140: int adreno_drawctxt_wait(struct adreno_device *adreno_dev, 141: struct kgsl_context *context, 142: uint32_t timestamp, unsigned int timeout) 143: { 144: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 145: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 146: int ret; 147: long ret_temp; 148: 149: if (kgsl_context_detached(context)) 150: return -ENOENT; 151: 152: if (kgsl_context_invalid(context)) 153: return -EDEADLK; 154: 155: trace_adreno_drawctxt_wait_start(-1, context->id, timestamp); 156: 157: ret = kgsl_add_event(device, &context->events, timestamp, 158: wait_callback, (void *) drawctxt); 159: if (ret) 160: goto done; 161: 162: /* 163: * If timeout is 0, wait forever. msecs_to_jiffies will force 164: * values larger than INT_MAX to an infinite timeout. 165: */ 166: if (timeout == 0) 167: timeout = UINT_MAX; 168: 169: ret_temp = wait_event_interruptible_timeout(drawctxt->waiting, 170: _check_context_timestamp(device, context, timestamp), 171: msecs_to_jiffies(timeout)); 172: 173: if (ret_temp <= 0) { 174: kgsl_cancel_event(device, &context->events, timestamp, 175: wait_callback, (void *)drawctxt); 176: 177: ret = ret_temp ? (int)ret_temp : -ETIMEDOUT; 178: goto done; 179: } 180: ret = 0; 181: 182: /* -EDEADLK if the context was invalidated while we were waiting */ 183: if (kgsl_context_invalid(context)) 184: ret = -EDEADLK; 185: 186: 187: /* Return -EINVAL if the context was detached while we were waiting */ 188: if (kgsl_context_detached(context)) 189: ret = -ENOENT; 190: 191: done: 192: trace_adreno_drawctxt_wait_done(-1, context->id, timestamp, ret); 193: return ret; 194: } 195: 196: /** 197: * adreno_drawctxt_wait_rb() - Wait for the last RB timestamp at which this 198: * context submitted a command to the corresponding RB 199: * @adreno_dev: The device on which the timestamp is active 200: * @context: The context which subbmitted command to RB 201: * @timestamp: The RB timestamp of last command submitted to RB by context 202: * @timeout: Timeout value for the wait 203: * Caller must hold the device mutex 204: */ 205: static int adreno_drawctxt_wait_rb(struct adreno_device *adreno_dev, 206: struct kgsl_context *context, 207: uint32_t timestamp, unsigned int timeout) 208: { 209: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 210: int ret = 0; 211: 212: /* 213: * If the context is invalid (OR) not submitted commands to GPU 214: * then return immediately - we may end up waiting for a timestamp 215: * that will never come 216: */ 217: if (kgsl_context_invalid(context) || 218: !test_bit(KGSL_CONTEXT_PRIV_SUBMITTED, &context->priv)) 219: goto done; 220: 221: trace_adreno_drawctxt_wait_start(drawctxt->rb->id, context->id, 222: timestamp); 223: 224: ret = adreno_ringbuffer_waittimestamp(drawctxt->rb, timestamp, timeout); 225: done: 226: trace_adreno_drawctxt_wait_done(drawctxt->rb->id, context->id, 227: timestamp, ret); 228: return ret; 229: } 230: 231: static int drawctxt_detach_drawobjs(struct adreno_context *drawctxt, 232: struct kgsl_drawobj **list) 233: { 234: int count = 0; 235: 236: while (drawctxt->drawqueue_head != drawctxt->drawqueue_tail) { 237: struct kgsl_drawobj *drawobj = 238: drawctxt->drawqueue[drawctxt->drawqueue_head]; 239: 240: drawctxt->drawqueue_head = (drawctxt->drawqueue_head + 1) % 241: ADRENO_CONTEXT_DRAWQUEUE_SIZE; 242: 243: list[count++] = drawobj; 244: } 245: 246: return count; 247: } 248: 249: /** 250: * adreno_drawctxt_invalidate() - Invalidate an adreno draw context 251: * @device: Pointer to the KGSL device structure for the GPU MATCH LINES: 269, 270, 273, 277, 278, 281, 282, 289, 290 257: void adreno_drawctxt_invalidate(struct kgsl_device *device, 258: struct kgsl_context *context) 259: { 260: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 261: struct kgsl_drawobj *list[ADRENO_CONTEXT_DRAWQUEUE_SIZE]; 262: int i, count; 263: 264: trace_adreno_drawctxt_invalidate(drawctxt); 265: 266: spin_lock(&drawctxt->lock); 267: set_bit(KGSL_CONTEXT_PRIV_INVALID, &context->priv); 268: 269: if (!list_empty(&drawctxt->hw_fence_list)) 270: set_bit(KGSL_CONTEXT_PRIV_INVALID_DRAIN_HW_FENCE, &context->priv); 271: 272: /* 273: * set the timestamp to the last value since the context is invalidated 274: * and we want the pending events for this context to go away 275: */ 276: kgsl_sharedmem_writel(device->memstore, 277: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 278: drawctxt->timestamp); 279: 280: kgsl_sharedmem_writel(device->memstore, 281: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 282: drawctxt->timestamp); 283: 284: /* Get rid of commands still waiting in the queue */ 285: count = drawctxt_detach_drawobjs(drawctxt, list); 286: spin_unlock(&drawctxt->lock); 287: 288: for (i = 0; i < count; i++) { 289: kgsl_cancel_events_timestamp(device, &context->events, 290: list[i]->timestamp); 291: kgsl_drawobj_destroy(list[i]); 292: } 293: 294: /* Make sure all pending events are processed or cancelled */ 295: kgsl_flush_event_group(device, &context->events); 296: 297: /* Give the bad news to everybody waiting around */ 298: wake_up_all(&drawctxt->waiting); 299: wake_up_all(&drawctxt->wq); 300: wake_up_all(&drawctxt->timeout); 301: } 302: 303: void adreno_drawctxt_set_guilty(struct kgsl_device *device, 304: struct kgsl_context *context) 305: { 306: if (!context) 307: return; 308: 309: context->reset_status = KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT; 310: 311: adreno_drawctxt_invalidate(device, context); 312: } 313: 314: u32 adreno_prepare_preib_preempt_scratch(struct adreno_device *adreno_dev, MATCH LINES: 464, 468, 501, 504, 510, 511, 535, 543, 549, 556, 570, 588, 589, 592, 593 452: } 453: 454: if ((local & KGSL_CONTEXT_LPAC) && (local & KGSL_CONTEXT_SECURE)) { 455: dev_err_once(device->dev, "LPAC secure context not supported\n"); 456: return ERR_PTR(-EOPNOTSUPP); 457: } 458: 459: drawctxt = kzalloc(sizeof(struct adreno_context), GFP_KERNEL); 460: 461: if (drawctxt == NULL) 462: return ERR_PTR(-ENOMEM); 463: 464: drawctxt->timestamp = 0; 465: 466: drawctxt->base.flags = local; 467: 468: /* Always enable per-context timestamps */ 469: drawctxt->base.flags |= KGSL_CONTEXT_PER_CONTEXT_TS; 470: drawctxt->type = (drawctxt->base.flags & KGSL_CONTEXT_TYPE_MASK) 471: >> KGSL_CONTEXT_TYPE_SHIFT; 472: spin_lock_init(&drawctxt->lock); 473: init_waitqueue_head(&drawctxt->wq); 474: init_waitqueue_head(&drawctxt->waiting); 475: init_waitqueue_head(&drawctxt->timeout); 476: 477: /* If the priority is not set by user, set it for them */ 478: if ((drawctxt->base.flags & KGSL_CONTEXT_PRIORITY_MASK) == 479: KGSL_CONTEXT_PRIORITY_UNDEF) 480: drawctxt->base.flags |= (KGSL_CONTEXT_PRIORITY_MED << 481: KGSL_CONTEXT_PRIORITY_SHIFT); 482: 483: /* Store the context priority */ 484: drawctxt->base.priority = 485: (drawctxt->base.flags & KGSL_CONTEXT_PRIORITY_MASK) >> 486: KGSL_CONTEXT_PRIORITY_SHIFT; 487: 488: /* 489: * Now initialize the common part of the context. This allocates the 490: * context id, and then possibly another thread could look it up. 491: * So we want all of our initializtion that doesn't require the context 492: * id to be done before this call. 493: */ 494: ret = kgsl_context_init(dev_priv, &drawctxt->base); 495: if (ret != 0) { 496: kfree(drawctxt); 497: return ERR_PTR(ret); 498: } 499: 500: kgsl_sharedmem_writel(device->memstore, 501: KGSL_MEMSTORE_OFFSET(drawctxt->base.id, soptimestamp), 502: 0); 503: kgsl_sharedmem_writel(device->memstore, 504: KGSL_MEMSTORE_OFFSET(drawctxt->base.id, eoptimestamp), 505: 0); 506: 507: adreno_context_debugfs_init(ADRENO_DEVICE(device), drawctxt); 508: 509: INIT_LIST_HEAD(&drawctxt->active_node); 510: INIT_LIST_HEAD(&drawctxt->hw_fence_list); 511: INIT_LIST_HEAD(&drawctxt->hw_fence_inflight_list); 512: 513: if (adreno_dev->dispatch_ops && adreno_dev->dispatch_ops->setup_context) { 514: ret = adreno_dev->dispatch_ops->setup_context(adreno_dev, drawctxt); 515: if (ret) { 516: dev_err_ratelimited(device->dev, 517: "Context initialization failed ret:%d\n", ret); 518: kgsl_context_detach(&drawctxt->base); 519: return ERR_PTR(ret); 520: } 521: } 522: 523: ret = drawctxt_preemption_init(&drawctxt->base); 524: if (ret) { 525: kgsl_context_detach(&drawctxt->base); 526: return ERR_PTR(ret); 527: } 528: 529: /* copy back whatever flags we dediced were valid */ 530: *flags = drawctxt->base.flags; 531: 532: return &drawctxt->base; 533: } 534: 535: static void wait_for_timestamp_rb(struct kgsl_device *device, 536: struct adreno_context *drawctxt) 537: { 538: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 539: struct kgsl_context *context = &drawctxt->base; 540: int ret; 541: 542: /* 543: * internal_timestamp is set in adreno_ringbuffer_addcmds, 544: * which holds the device mutex. 545: */ 546: kgsl_mutex_lock(&device->mutex); 547: 548: /* 549: * Wait for the last global timestamp to pass before continuing. 550: * The maxumum wait time is 30s, some large IB's can take longer 551: * than 10s and if hang happens then the time for the context's 552: * commands to retire will be greater than 10s. 30s should be sufficient 553: * time to wait for the commands even if a hang happens. 554: */ 555: ret = adreno_drawctxt_wait_rb(adreno_dev, &drawctxt->base, 556: drawctxt->internal_timestamp, 30 * 1000); 557: 558: /* 559: * If the wait for global fails due to timeout then mark it as 560: * context detach timeout fault and schedule dispatcher to kick 561: * in GPU recovery. For a ADRENO_CTX_DETATCH_TIMEOUT_FAULT we clear 562: * the policy and invalidate the context. If EAGAIN error is returned 563: * then recovery will kick in and there will be no more commands in the 564: * RB pipe from this context which is what we are waiting for, so ignore 565: * -EAGAIN error. 566: */ 567: if (ret && ret != -EAGAIN) { 568: dev_err(device->dev, 569: "Wait for global ctx=%u ts=%u type=%d error=%d\n", 570: drawctxt->base.id, drawctxt->internal_timestamp, 571: drawctxt->type, ret); 572: 573: adreno_set_gpu_fault(adreno_dev, 574: ADRENO_CTX_DETATCH_TIMEOUT_FAULT); 575: kgsl_mutex_unlock(&device->mutex); 576: 577: /* Schedule dispatcher to kick in recovery */ 578: adreno_scheduler_queue(adreno_dev); 579: 580: /* Wait for context to be invalidated and release context */ 581: wait_event_interruptible_timeout(drawctxt->timeout, 582: kgsl_context_invalid(&drawctxt->base), 583: msecs_to_jiffies(5000)); 584: return; 585: } 586: 587: kgsl_sharedmem_writel(device->memstore, 588: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 589: drawctxt->timestamp); 590: 591: kgsl_sharedmem_writel(device->memstore, 592: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 593: drawctxt->timestamp); 594: 595: adreno_profile_process_results(adreno_dev); 596: 597: kgsl_mutex_unlock(&device->mutex); 598: } 599: 600: void adreno_drawctxt_detach(struct kgsl_context *context) 601: { 602: struct kgsl_device *device; 603: struct adreno_device *adreno_dev; 604: const struct adreno_gpudev *gpudev; 605: struct adreno_context *drawctxt; 606: int count, i; 607: struct kgsl_drawobj *list[ADRENO_CONTEXT_DRAWQUEUE_SIZE]; 608: 609: if (context == NULL) 610: return; 611: 612: device = context->device; 613: adreno_dev = ADRENO_DEVICE(device); 614: gpudev = ADRENO_GPU_DEVICE(adreno_dev); 615: drawctxt = ADRENO_CONTEXT(context); 616: 617: spin_lock(&drawctxt->lock); MATCH LINES: 644 632: adreno_fault_skipcmd_detached(adreno_dev, drawctxt, list[i]); 633: kgsl_drawobj_destroy(list[i]); 634: } 635: 636: debugfs_remove_recursive(drawctxt->debug_root); 637: /* The debugfs file has a reference, release it */ 638: if (drawctxt->debug_root) 639: kgsl_context_put(context); 640: 641: if (gpudev->context_detach) 642: gpudev->context_detach(drawctxt); 643: else 644: wait_for_timestamp_rb(device, drawctxt); 645: 646: if (context->user_ctxt_record) { 647: gpumem_free_entry(context->user_ctxt_record); 648: 649: /* Put the extra ref from gpumem_alloc_entry() */ 650: kgsl_mem_entry_put(context->user_ctxt_record); 651: } 652: 653: /* wake threads waiting to submit commands from this context */ 654: wake_up_all(&drawctxt->waiting); 655: wake_up_all(&drawctxt->wq); 656: } 657: 658: void adreno_drawctxt_destroy(struct kgsl_context *context) 659: { 660: struct adreno_context *drawctxt; 661: struct adreno_device *adreno_dev; 662: const struct adreno_gpudev *gpudev; 663: 664: if (context == NULL) 665: return; 666: 667: drawctxt = ADRENO_CONTEXT(context); 668: MATCH LINES: 686, 688, 693 674: kfree(drawctxt); 675: } 676: 677: static void _drawctxt_switch_wait_callback(struct kgsl_device *device, 678: struct kgsl_event_group *group, 679: void *priv, int result) 680: { 681: struct adreno_context *drawctxt = (struct adreno_context *) priv; 682: 683: kgsl_context_put(&drawctxt->base); 684: } 685: 686: void adreno_put_drawctxt_on_timestamp(struct kgsl_device *device, 687: struct adreno_context *drawctxt, 688: struct adreno_ringbuffer *rb, u32 timestamp) 689: { 690: if (!drawctxt) 691: return; 692: 693: if (kgsl_add_event(device, &rb->events, timestamp, 694: _drawctxt_switch_wait_callback, drawctxt)) 695: kgsl_context_put(&drawctxt->base); 696: } 697: 698: static void _add_context(struct adreno_device *adreno_dev, 699: struct adreno_context *drawctxt) 700: { 701: /* Remove it from the list */ 702: list_del_init(&drawctxt->active_node); 703: 704: /* And push it to the front */ 705: drawctxt->active_time = jiffies; 706: list_add(&drawctxt->active_node, &adreno_dev->active_list); 707: } 708: 709: static int __count_context(struct adreno_context *drawctxt, void *data) 710: { 711: unsigned long expires = drawctxt->active_time + msecs_to_jiffies(100); 712: 713: return time_after(jiffies, expires) ? 0 : 1; 714: } 715: 716: static int __count_drawqueue_context(struct adreno_context *drawctxt, 717: void *data) --- FILE: \adreno_drawctxt.h | HITS: 37 --- MATCH LINES: 27, 28, 37, 42, 44, 54, 55, 71, 73, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 98, 100, 101, 103, 119, 128, 144, 164, 165, 168, 169, 171, 175, 177 15: const char *str; 16: }; 17: 18: #define ADRENO_CONTEXT_DRAWQUEUE_SIZE 128 19: #define SUBMIT_RETIRE_TICKS_SIZE 7 20: 21: struct kgsl_device; 22: struct adreno_device; 23: struct kgsl_device_private; 24: 25: /** 26: * struct adreno_context - Adreno GPU draw context 27: * @timestamp: Last issued context-specific timestamp 28: * @internal_timestamp: Global timestamp of the last issued command 29: * NOTE: guarded by device->mutex, not drawctxt->mutex! 30: * @type: Context type (GL, CL, RS) 31: * @mutex: Mutex to protect the drawqueue 32: * @drawqueue: Queue of drawobjs waiting to be dispatched for this 33: * context 34: * @drawqueue_head: Head of the drawqueue queue 35: * @drawqueue_tail: Tail of the drawqueue queue 36: * @wq: Workqueue structure for contexts to sleep pending room in the queue 37: * @waiting: Workqueue structure for contexts waiting for a timestamp or event 38: * @timeout: Workqueue structure for contexts waiting to invalidate 39: * @queued: Number of commands queued in the drawqueue 40: * @fault_policy: GFT fault policy set in _skip_cmd(); 41: * @debug_root: debugfs entry for this context. 42: * @queued_timestamp: The last timestamp that was queued on this context 43: * @rb: The ringbuffer in which this context submits commands. 44: * @submitted_timestamp: The last timestamp that was submitted for this context 45: * @submit_retire_ticks: Array to hold command obj execution times from submit 46: * to retire 47: * @ticks_index: The index into submit_retire_ticks[] where the new delta will 48: * be written. 49: * @active_node: Linkage for nodes in active_list 50: * @active_time: Time when this context last seen 51: */ 52: struct adreno_context { 53: struct kgsl_context base; 54: unsigned int timestamp; 55: unsigned int internal_timestamp; 56: unsigned int type; 57: spinlock_t lock; 58: 59: /* Dispatcher */ 60: struct kgsl_drawobj *drawqueue[ADRENO_CONTEXT_DRAWQUEUE_SIZE]; 61: unsigned int drawqueue_head; 62: unsigned int drawqueue_tail; 63: 64: wait_queue_head_t wq; 65: wait_queue_head_t waiting; 66: wait_queue_head_t timeout; 67: 68: int queued; 69: unsigned int fault_policy; 70: struct dentry *debug_root; 71: unsigned int queued_timestamp; 72: struct adreno_ringbuffer *rb; 73: unsigned int submitted_timestamp; 74: uint64_t submit_retire_ticks[SUBMIT_RETIRE_TICKS_SIZE]; 75: int ticks_index; 76: 77: struct list_head active_node; 78: unsigned long active_time; 79: /** @gmu_context_queue: Queue to dispatch submissions to GMU */ 80: struct kgsl_memdesc gmu_context_queue; 81: /** @gmu_hw_fence_queue: Queue for GMU to store hardware fences for this context */ 82: struct kgsl_memdesc gmu_hw_fence_queue; 83: /** @hw_fence_list: List of hardware fences(sorted by timestamp) not yet submitted to GMU */ 84: struct list_head hw_fence_list; 85: /** @hw_fence_inflight_list: List of hardware fences submitted to GMU */ 86: struct list_head hw_fence_inflight_list; 87: /** @hw_fence_count: Number of hardware fences not yet sent to Tx Queue */ 88: u32 hw_fence_count; 89: /** @syncobj_timestamp: Timestamp to check whether GMU has consumed a syncobj */ 90: u32 syncobj_timestamp; 91: /** 92: * @gmu_hw_fence_ready_ts: This timestamp is used to figure out whether a hardware fence 93: * is ready to be submitted to GMU at the time of its creation or not. This timestamp 94: * tracks the timestamp of the most recently submitted cmdbatch submission to the GMU 95: * context queue for this context. This is different from the internal_timestamp (which gets 96: * reset to 0 in some cases). 97: */ 98: u32 gmu_hw_fence_ready_ts; 99: /** 100: * @hw_fence_last_ts: This tracks the latest timestamp for which a hw fence was created. 101: * This is used to figure out if a new fence has an out-of-order timestamp. 102: */ 103: u32 hw_fence_last_ts; 104: }; 105: 106: /* Flag definitions for flag field in adreno_context */ 107: 108: /** 109: * enum adreno_context_priv - Private flags for an adreno draw context 110: * @ADRENO_CONTEXT_FAULT - set if the context has faulted (and recovered) 111: * @ADRENO_CONTEXT_GPU_HANG - Context has caused a GPU hang 112: * @ADRENO_CONTEXT_GPU_HANG_FT - Context has caused a GPU hang 113: * and fault tolerance was successful 114: * @ADRENO_CONTEXT_SKIP_EOF - Context skip IBs until the next end of frame 115: * marker. 116: * @ADRENO_CONTEXT_FORCE_PREAMBLE - Force the preamble for the next submission. 117: * @ADRENO_CONTEXT_SKIP_CMD - Context's drawobj's skipped during 118: fault tolerance. 119: * @ADRENO_CONTEXT_FENCE_LOG - Dump fences on this context. 120: */ 121: enum adreno_context_priv { 122: ADRENO_CONTEXT_FAULT = KGSL_CONTEXT_PRIV_DEVICE_SPECIFIC, 123: ADRENO_CONTEXT_GPU_HANG, 124: ADRENO_CONTEXT_GPU_HANG_FT, 125: ADRENO_CONTEXT_SKIP_EOF, 126: ADRENO_CONTEXT_FORCE_PREAMBLE, 127: ADRENO_CONTEXT_SKIP_CMD, 128: ADRENO_CONTEXT_FENCE_LOG, 129: }; 130: 131: struct kgsl_context *adreno_drawctxt_create( 132: struct kgsl_device_private *dev_priv, 133: uint32_t *flags); 134: 135: void adreno_drawctxt_detach(struct kgsl_context *context); 136: 137: void adreno_drawctxt_destroy(struct kgsl_context *context); 138: 139: struct adreno_ringbuffer; 140: struct adreno_dispatcher_drawqueue; 141: 142: int adreno_drawctxt_wait(struct adreno_device *adreno_dev, 143: struct kgsl_context *context, 144: uint32_t timestamp, unsigned int timeout); 145: 146: void adreno_drawctxt_invalidate(struct kgsl_device *device, 147: struct kgsl_context *context); 148: 149: void adreno_drawctxt_dump(struct kgsl_device *device, 150: struct kgsl_context *context); 151: 152: /** 153: * adreno_drawctxt_detached - Helper function to check if a context is detached 154: * @drawctxt: Adreno drawctxt to check 155: * 156: * Return: True if the context isn't null and it has been detached 157: */ 158: static inline bool adreno_drawctxt_detached(struct adreno_context *drawctxt) 159: { 160: return (drawctxt && kgsl_context_detached(&drawctxt->base)); 161: } 162: 163: /** 164: * adreno_put_drawctxt_on_timestamp - Put the refcount on the drawctxt when the 165: * timestamp expires 166: * @device: A KGSL device handle 167: * @drawctxt: The draw context to put away 168: * @rb: The ringbuffer that will trigger the timestamp event 169: * @timestamp: The timestamp on @rb that will trigger the event 170: * 171: * Add an event to put the refcount on @drawctxt after @timestamp expires on 172: * @rb. This is used by the context switch to safely put away the context after 173: * a new context is switched in. 174: */ 175: void adreno_put_drawctxt_on_timestamp(struct kgsl_device *device, 176: struct adreno_context *drawctxt, 177: struct adreno_ringbuffer *rb, u32 timestamp); 178: 179: /** 180: * adreno_drawctxt_get_pagetable - Helper function to return the pagetable for a 181: * context 182: * @drawctxt: The adreno draw context to query 183: * 184: * Return: A pointer to the pagetable for the process that owns the context or 185: * NULL 186: */ 187: static inline struct kgsl_pagetable * 188: adreno_drawctxt_get_pagetable(struct adreno_context *drawctxt) 189: { 190: if (drawctxt) 191: return drawctxt->base.proc_priv->pagetable; 192: 193: return NULL; 194: } 195: 196: /** 197: * adreno_drawctxt_set_guilty - Mark a context as guilty and invalidate it 198: * @device: Pointer to a GPU device handle 199: * @context: Pointer to the context to invalidate 200: * 201: * Mark the specified context as guilty and invalidate it --- FILE: \adreno_gen7.c | HITS: 25 --- MATCH LINES: 299, 312, 316, 319, 328, 338, 344 287: cmds[i++] = upper_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 288: /* 289: * Gen7 targets with concurrent binning are expected to have a dynamic 290: * power up list with triplets which contains the pipe id in it. 291: * Bit 31 of POWER_UP_REGISTER_LIST_LENGTH is reused here to let CP 292: * know if the power up contains the triplets. If 293: * REGISTER_INIT_LIST_WITH_SPINLOCK is set and bit 31 below is set, 294: * CP expects a dynamic list with triplets. 295: */ 296: cmds[i++] = BIT(31); 297: } 298: 299: int gen7_fenced_write(struct adreno_device *adreno_dev, u32 offset, 300: u32 value, u32 mask) 301: { 302: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 303: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 304: unsigned int status, i; 305: u64 ts1, ts2; 306: 307: kgsl_regwrite(device, offset, value); 308: ts1 = gpudev->read_alwayson(adreno_dev); 309: for (i = 0; i < GMU_CORE_LONG_WAKEUP_RETRY_LIMIT; i++) { 310: /* 311: * Make sure the previous register write is posted before 312: * checking the fence status 313: */ 314: mb(); 315: 316: gmu_core_regread(device, GEN7_GMU_AHB_FENCE_STATUS, &status); 317: 318: /* 319: * If !writedropped0/1, then the write to fenced register 320: * was successful 321: */ 322: if (!(status & mask)) 323: break; 324: 325: /* Wait a small amount of time before trying again */ 326: udelay(GMU_CORE_WAKEUP_DELAY_US); 327: 328: /* Try to write the fenced register again */ 329: kgsl_regwrite(device, offset, value); 330: } 331: 332: if (i < GMU_CORE_SHORT_WAKEUP_RETRY_LIMIT) 333: return 0; 334: 335: if (i == GMU_CORE_LONG_WAKEUP_RETRY_LIMIT) { 336: ts2 = gpudev->read_alwayson(adreno_dev); 337: dev_err(device->dev, 338: "Timed out waiting %d usecs to write fenced register 0x%x, timestamps: %llx %llx\n", 339: i * GMU_CORE_WAKEUP_DELAY_US, offset, ts1, ts2); 340: return -ETIMEDOUT; 341: } 342: 343: dev_info(device->dev, 344: "Waited %d usecs to write fenced register 0x%x\n", 345: i * GMU_CORE_WAKEUP_DELAY_US, offset); 346: 347: return 0; 348: } 349: 350: static void gen7_calc_ubwc_config_legacy(struct adreno_device *adreno_dev) 351: { 352: struct adreno_ubwc_props *ubwc_props = &adreno_dev->ubwc_props; 353: 354: if (adreno_dev->ubwc_mode == KGSL_UBWC_4_0) 355: ubwc_props->rgb565_predicator = true; 356: } 357: 358: #if (KERNEL_VERSION(6, 17, 0) <= LINUX_VERSION_CODE) 359: static void gen7_calc_ubwc_config(struct adreno_device *adreno_dev) 360: { 361: struct qcom_ubwc_cfg_data *cfg = (struct qcom_ubwc_cfg_data *)adreno_dev->ubwc_cfg_data; 362: struct adreno_ubwc_props *ubwc_props = &adreno_dev->ubwc_props; 363: 364: if (!cfg) 365: return gen7_calc_ubwc_config_legacy(adreno_dev); 366: 367: ubwc_props->rgb565_predicator = cfg->ubwc_enc_version >= UBWC_4_0; 368: } MATCH LINES: 1717, 1732, 1736, 1738, 1742, 1747, 1749, 1754, 1756, 1763, 1769 1705: ADRENO_IRQ_CALLBACK(gen7_preemption_callback),/* 8 - CP_SW */ 1706: ADRENO_IRQ_CALLBACK(gen7_cp_hw_err_callback), /* 9 - CP_HW_ERROR */ 1707: ADRENO_IRQ_CALLBACK(NULL), /* 10 - CP_CCU_FLUSH_DEPTH_TS */ 1708: ADRENO_IRQ_CALLBACK(NULL), /* 11 - CP_CCU_FLUSH_COLOR_TS */ 1709: ADRENO_IRQ_CALLBACK(NULL), /* 12 - CP_CCU_RESOLVE_TS */ 1710: ADRENO_IRQ_CALLBACK(NULL), /* 13 - UNUSED */ 1711: ADRENO_IRQ_CALLBACK(NULL), /* 14 - UNUSED */ 1712: ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 15 - CP_RB_INT */ 1713: ADRENO_IRQ_CALLBACK(NULL), /* 16 - CP_RB_INT_LPAC*/ 1714: ADRENO_IRQ_CALLBACK(NULL), /* 17 - CP_RB_DONE_TS */ 1715: ADRENO_IRQ_CALLBACK(NULL), /* 18 - UNUSED */ 1716: ADRENO_IRQ_CALLBACK(NULL), /* 19 - UNUSED */ 1717: ADRENO_IRQ_CALLBACK(gen7_cp_callback), /* 20 - CP_CACHE_FLUSH_TS */ 1718: ADRENO_IRQ_CALLBACK(NULL), /* 21 - CP_CACHE_TS_LPAC */ 1719: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 22 - RBBM_ATB_BUS_OVERFLOW */ 1720: ADRENO_IRQ_CALLBACK(adreno_hang_int_callback), /* 23 - MISHANGDETECT */ 1721: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 24 - UCHE_OOB_ACCESS */ 1722: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 25 - UCHE_TRAP_INTR */ 1723: ADRENO_IRQ_CALLBACK(NULL), /* 26 - DEBBUS_INTR_0 */ 1724: ADRENO_IRQ_CALLBACK(NULL), /* 27 - DEBBUS_INTR_1 */ 1725: ADRENO_IRQ_CALLBACK(gen7_err_callback), /* 28 - TSBWRITEERROR */ 1726: ADRENO_IRQ_CALLBACK(gen7_swfuse_violation_callback), /* 29 - SWFUSEVIOLATION */ 1727: ADRENO_IRQ_CALLBACK(NULL), /* 30 - ISDB_CPU_IRQ */ 1728: ADRENO_IRQ_CALLBACK(NULL), /* 31 - ISDB_UNDER_DEBUG */ 1729: }; 1730: 1731: /* 1732: * If the AHB fence is not in ALLOW mode when we receive an RBBM 1733: * interrupt, something went wrong. This means that we cannot proceed 1734: * since the IRQ status and clear registers are not accessible. 1735: * This is usually harmless because the GMU will abort power collapse 1736: * and change the fence back to ALLOW. Poll so that this can happen. 1737: */ 1738: static int gen7_irq_poll_fence(struct adreno_device *adreno_dev) 1739: { 1740: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1741: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1742: u32 status, fence, fence_retries = 0; 1743: u64 a, b, c; 1744: 1745: a = gpudev->read_alwayson(adreno_dev); 1746: 1747: kgsl_regread(device, GEN7_GMU_AO_AHB_FENCE_CTRL, &fence); 1748: 1749: while (fence != 0) { 1750: b = gpudev->read_alwayson(adreno_dev); 1751: 1752: /* Wait for small time before trying again */ 1753: udelay(1); 1754: kgsl_regread(device, GEN7_GMU_AO_AHB_FENCE_CTRL, &fence); 1755: 1756: if (fence_retries == 100 && fence != 0) { 1757: c = gpudev->read_alwayson(adreno_dev); 1758: 1759: kgsl_regread(device, GEN7_GMU_RBBM_INT_UNMASKED_STATUS, 1760: &status); 1761: 1762: dev_crit_ratelimited(device->dev, 1763: "status=0x%x Unmasked status=0x%x Mask=0x%x timestamps: %llx %llx %llx\n", 1764: status & adreno_dev->irq_mask, status, 1765: adreno_dev->irq_mask, a, b, c); 1766: return -ETIMEDOUT; 1767: } 1768: 1769: fence_retries++; 1770: } 1771: 1772: return 0; 1773: } 1774: 1775: static irqreturn_t gen7_hwsched_irq_handler(struct adreno_device *adreno_dev) 1776: { 1777: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1778: irqreturn_t ret = IRQ_NONE; 1779: u32 status; 1780: 1781: /* 1782: * GPU can power down once the INT_0_STATUS is read below. 1783: * But there still might be some register reads required so 1784: * force the GMU/GPU into KEEPALIVE mode until done with the ISR. 1785: */ 1786: gen7_gpu_keepalive(adreno_dev, true); 1787: 1788: kgsl_regread(device, GEN7_RBBM_INT_0_STATUS, &status); 1789: 1790: kgsl_regwrite(device, GEN7_RBBM_INT_CLEAR_CMD, status); 1791: 1792: ret = adreno_irq_callbacks(adreno_dev, gen7_irq_funcs, status); 1793: MATCH LINES: 1816 1804: { 1805: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1806: irqreturn_t ret = IRQ_NONE; 1807: u32 status; 1808: 1809: /* 1810: * GPU can power down once the INT_0_STATUS is read below. 1811: * But there still might be some register reads required so 1812: * force the GMU/GPU into KEEPALIVE mode until done with the ISR. 1813: */ 1814: gen7_gpu_keepalive(adreno_dev, true); 1815: 1816: if (gen7_irq_poll_fence(adreno_dev)) { 1817: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 1818: goto done; 1819: } 1820: 1821: kgsl_regread(device, GEN7_RBBM_INT_0_STATUS, &status); 1822: 1823: kgsl_regwrite(device, GEN7_RBBM_INT_CLEAR_CMD, status); 1824: 1825: ret = adreno_irq_callbacks(adreno_dev, gen7_irq_funcs, status); 1826: 1827: trace_kgsl_gen7_irq_status(adreno_dev, status); 1828: 1829: done: 1830: /* If hard fault, then let snapshot turn off the keepalive */ 1831: if (!(adreno_gpu_fault(adreno_dev) & ADRENO_HARD_FAULT)) 1832: gen7_gpu_keepalive(adreno_dev, false); 1833: 1834: return ret; 1835: } 1836: 1837: int gen7_probe_common(struct platform_device *pdev, 1838: struct adreno_device *adreno_dev, u32 chipid, 1839: const struct adreno_gpu_core *gpucore) 1840: { MATCH LINES: 2416, 2422, 2445, 2463, 2466, 2472 2404: } 2405: 2406: static void gen7_lpac_fault_header(struct adreno_device *adreno_dev, 2407: struct kgsl_drawobj *drawobj_lpac) 2408: { 2409: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2410: struct adreno_context *drawctxt_lpac; 2411: u32 status = 0, lpac_rptr = 0, lpac_wptr = 0, lpac_ib1sz = 0, lpac_ib2sz = 0; 2412: u64 lpac_ib1base = 0, lpac_ib2base = 0; 2413: bool gx_on = adreno_gx_is_on(adreno_dev); 2414: 2415: drawctxt_lpac = ADRENO_CONTEXT(drawobj_lpac->context); 2416: drawobj_lpac->context->last_faulted_cmd_ts = drawobj_lpac->timestamp; 2417: drawobj_lpac->context->total_fault_count++; 2418: 2419: pr_context(device, drawobj_lpac->context, 2420: "LPAC ctx %d ctx_type %s ts %d dispatch_queue=%d\n", 2421: drawobj_lpac->context->id, kgsl_context_type(drawctxt_lpac->type), 2422: drawobj_lpac->timestamp, drawobj_lpac->context->gmu_dispatch_queue); 2423: 2424: pr_context(device, drawobj_lpac->context, "lpac cmdline: %s\n", 2425: drawctxt_lpac->base.proc_priv->cmdline); 2426: if (!gx_on) 2427: goto done; 2428: 2429: kgsl_regread(device, GEN7_RBBM_STATUS, &status); 2430: kgsl_regread(device, GEN7_CP_LPAC_RB_RPTR, &lpac_rptr); 2431: kgsl_regread(device, GEN7_CP_LPAC_RB_WPTR, &lpac_wptr); 2432: gen7_periph_regread64(device, GEN7_CP_PERIPH_IB1_BASE_LO(adreno_dev), 2433: GEN7_CP_PERIPH_IB1_BASE_HI(adreno_dev), &lpac_ib1base, PIPE_LPAC); 2434: gen7_periph_regread(device, GEN7_CP_PERIPH_IB1_OFFSET(adreno_dev), &lpac_ib1sz, PIPE_LPAC); 2435: gen7_periph_regread64(device, GEN7_CP_PERIPH_IB2_BASE_LO(adreno_dev), 2436: GEN7_CP_PERIPH_IB2_BASE_HI(adreno_dev), &lpac_ib2base, PIPE_LPAC); 2437: gen7_periph_regread(device, GEN7_CP_PERIPH_IB2_OFFSET(adreno_dev), &lpac_ib2sz, PIPE_LPAC); 2438: 2439: pr_context(device, drawobj_lpac->context, 2440: "LPAC: status %8.8X rb %4.4x/%4.4x ib1 %16.16llX/%4.4x ib2 %16.16llX/%4.4x\n", 2441: status, lpac_rptr, lpac_wptr, lpac_ib1base, 2442: lpac_ib1sz, lpac_ib2base, lpac_ib2sz); 2443: 2444: done: 2445: trace_adreno_gpu_fault(drawobj_lpac->context->id, drawobj_lpac->timestamp, status, 2446: lpac_rptr, lpac_wptr, lpac_ib1base, lpac_ib1sz, lpac_ib2base, lpac_ib2sz, 2447: adreno_get_level(drawobj_lpac->context)); 2448: } 2449: 2450: static void gen7_fault_header(struct adreno_device *adreno_dev, 2451: struct kgsl_drawobj *drawobj) 2452: { 2453: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2454: struct adreno_context *drawctxt; 2455: u32 status = 0, rptr = 0, wptr = 0, ib1sz = 0, ib2sz = 0; 2456: u64 ib1base = 0, ib2base = 0; 2457: u32 ctxt_id = 0, ts = 0; 2458: int rb_id = -1; 2459: bool gx_on = adreno_gx_is_on(adreno_dev); 2460: 2461: if (drawobj) { 2462: drawctxt = ADRENO_CONTEXT(drawobj->context); 2463: drawobj->context->last_faulted_cmd_ts = drawobj->timestamp; 2464: drawobj->context->total_fault_count++; 2465: ctxt_id = drawobj->context->id; 2466: ts = drawobj->timestamp; 2467: rb_id = adreno_get_level(drawobj->context); 2468: 2469: pr_context(device, drawobj->context, 2470: "ctx %u ctx_type %s ts %u policy %lX dispatch_queue=%d\n", 2471: drawobj->context->id, kgsl_context_type(drawctxt->type), 2472: drawobj->timestamp, CMDOBJ(drawobj)->fault_recovery, 2473: drawobj->context->gmu_dispatch_queue); 2474: 2475: pr_context(device, drawobj->context, "cmdline: %s\n", 2476: drawctxt->base.proc_priv->cmdline); 2477: } 2478: 2479: if (!gx_on) 2480: goto done; 2481: 2482: kgsl_regread(device, GEN7_RBBM_STATUS, &status); 2483: kgsl_regread(device, GEN7_CP_RB_RPTR, &rptr); 2484: kgsl_regread(device, GEN7_CP_RB_WPTR, &wptr); 2485: gen7_periph_regread64(device, GEN7_CP_PERIPH_IB1_BASE_LO(adreno_dev), 2486: GEN7_CP_PERIPH_IB1_BASE_HI(adreno_dev), &ib1base, PIPE_BR); 2487: gen7_periph_regread(device, GEN7_CP_PERIPH_IB1_OFFSET(adreno_dev), &ib1sz, PIPE_BR); 2488: gen7_periph_regread64(device, GEN7_CP_PERIPH_IB2_BASE_LO(adreno_dev), 2489: GEN7_CP_PERIPH_IB2_BASE_HI(adreno_dev), &ib2base, PIPE_BR); 2490: gen7_periph_regread(device, GEN7_CP_PERIPH_IB2_OFFSET(adreno_dev), &ib2sz, PIPE_BR); 2491: 2492: dev_err(device->dev, 2493: "status %8.8X rb %4.4x/%4.4x ib1 %16.16llX/%4.4x ib2 %16.16llX/%4.4x\n", 2494: status, rptr, wptr, ib1base, ib1sz, ib2base, ib2sz); 2495: done: 2496: trace_adreno_gpu_fault(ctxt_id, ts, status, --- FILE: \adreno_gen7.h | HITS: 5 --- MATCH LINES: 426, 430, 434, 445, 452 414: 415: /** 416: * gen7_ringbuffer_submit - Submit a command to the ringbuffer 417: * @rb: Ringbuffer pointer 418: * @time: Optional pointer to a adreno_submit_time container 419: * 420: * Return: 0 on success or negative on failure 421: */ 422: int gen7_ringbuffer_submit(struct adreno_ringbuffer *rb, 423: struct adreno_submit_time *time); 424: 425: /** 426: * gen7_fenced_write - Write to a fenced register 427: * @adreno_dev: An Adreno GPU handle 428: * @offset: Register offset 429: * @value: Value to write 430: * @mask: Expected FENCE_STATUS for successful write 431: * 432: * Return: 0 on success or negative on failure 433: */ 434: int gen7_fenced_write(struct adreno_device *adreno_dev, u32 offset, 435: u32 value, u32 mask); 436: 437: /** 438: * gen77ringbuffer_addcmds - Wrap and submit commands to the ringbuffer 439: * @adreno_dev: An Adreno GPU handle 440: * @rb: Ringbuffer pointer 441: * @drawctxt: Draw context submitting the commands 442: * @flags: Submission flags 443: * @in: Input buffer to write to ringbuffer 444: * @dwords: Dword length of @in 445: * @timestamp: Draw context timestamp for the submission 446: * @time: Optional pointer to a adreno_submit_time container 447: * 448: * Return: 0 on success or negative on failure 449: */ 450: int gen7_ringbuffer_addcmds(struct adreno_device *adreno_dev, 451: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 452: u32 flags, u32 *in, u32 dwords, u32 timestamp, 453: struct adreno_submit_time *time); 454: 455: /** 456: * gen7_cp_init_cmds - Create the CP_INIT commands 457: * @adreno_dev: An Adreno GPU handle 458: * @cmd: Buffer to write the CP_INIT commands into 459: */ 460: void gen7_cp_init_cmds(struct adreno_device *adreno_dev, u32 *cmds); 461: 462: /** 463: * gen7_gmu_hfi_probe - Probe Gen7 HFI specific data 464: * @adreno_dev: An Adreno GPU handle 465: * 466: * Return: 0 on success or negative on failure 467: */ 468: int gen7_gmu_hfi_probe(struct adreno_device *adreno_dev); 469: 470: static inline const struct gen7_gpudev * 471: to_gen7_gpudev(const struct adreno_gpudev *gpudev) 472: { 473: return container_of(gpudev, struct gen7_gpudev, base); 474: } 475: 476: /** --- FILE: \adreno_gen7_gmu.c | HITS: 11 --- MATCH LINES: 946 934: /* Vote veto for FAL10 */ 935: gmu_core_regwrite(device, GEN7_GPU_GMU_CX_GMU_CX_FALNEXT_INTF, 0x1); 936: gmu_core_regwrite(device, GEN7_GPU_GMU_CX_GMU_CX_FAL_INTF, 0x1); 937: 938: /* Clear init result to make sure we are getting fresh value */ 939: gmu_core_regwrite(device, GEN7_GMU_CM3_FW_INIT_RESULT, 0); 940: gmu_core_regwrite(device, GEN7_GMU_CM3_BOOT_CONFIG, 0x2); 941: 942: gmu_core_regwrite(device, GEN7_GMU_HFI_QTBL_ADDR, 943: gmu->hfi.hfi_mem->gmuaddr); 944: gmu_core_regwrite(device, GEN7_GMU_HFI_QTBL_INFO, 1); 945: 946: gmu_core_regwrite(device, GEN7_GMU_AHB_FENCE_RANGE_0, BIT(31) | 947: FIELD_PREP(GENMASK(30, 18), 0x32) | 948: FIELD_PREP(GENMASK(17, 0), GEN7_CP_CONTEXT_SWITCH_CNTL)); 949: 950: /* 951: * Make sure that CM3 state is at reset value. Snapshot is changing 952: * NMI bit and if we boot up GMU with NMI bit set GMU will boot 953: * straight in to NMI handler without executing __main code 954: */ 955: gmu_core_regwrite(device, GEN7_GMU_CM3_CFG, 0x4052); 956: 957: /* Set up GBIF registers from the GPU core definition */ 958: kgsl_regmap_multi_write(&device->regmap, gen7_core->gbif, 959: gen7_core->gbif_count); 960: 961: if (adreno_is_gen7_13_0(adreno_dev) || adreno_is_gen7_9_x(adreno_dev)) 962: kgsl_regrmw(device, GEN7_GBIF_CX_CONFIG, GENMASK(31, 29), 963: FIELD_PREP(GENMASK(31, 29), 1)); 964: else if (adreno_is_gen7_14_0_family(adreno_dev)) 965: kgsl_regrmw(device, GEN7_GBIF_CX_CONFIG, GENMASK(31, 29), 966: FIELD_PREP(GENMASK(31, 29), 2)); 967: 968: /** 969: * We may have asserted gbif halt as part of reset sequence which may 970: * not get cleared if the gdsc was not reset. So clear it before MATCH LINES: 1159, 1160, 1161 1147: 1148: /* Disconnect GPU from BUS is not needed if CX GDSC goes off later */ 1149: 1150: /* 1151: * GEMNOC can enter power collapse state during GPU power down sequence. 1152: * This could abort CX GDSC collapse. Assert Qactive to avoid this. 1153: */ 1154: gmu_core_regwrite(device, GEN7_GPU_GMU_CX_GMU_CX_FALNEXT_INTF, 0x1); 1155: 1156: /* Check no outstanding RPMh voting */ 1157: gen7_complete_rpmh_votes(gmu, 1); 1158: 1159: /* Clear the WRITEDROPPED fields and set fence to allow mode */ 1160: gmu_core_regwrite(device, GEN7_GMU_AHB_FENCE_STATUS_CLR, 0x7); 1161: gmu_core_regwrite(device, GEN7_GMU_AO_AHB_FENCE_CTRL, 0); 1162: 1163: /* Make sure above writes are committed before we proceed to recovery */ 1164: wmb(); 1165: 1166: gmu_core_regwrite(device, GEN7_GMU_CM3_SYSRESET, 1); 1167: 1168: /* Halt GX traffic */ 1169: if (gen7_gmu_gx_is_on(adreno_dev)) 1170: _do_gbif_halt(device, GEN7_RBBM_GBIF_HALT, 1171: GEN7_RBBM_GBIF_HALT_ACK, 1172: GEN7_GBIF_GX_HALT_MASK, 1173: "GX"); 1174: 1175: /* Halt CX traffic */ 1176: _do_gbif_halt(device, GEN7_GBIF_HALT, GEN7_GBIF_HALT_ACK, 1177: GEN7_GBIF_ARB_HALT_MASK, "CX"); 1178: 1179: /* 1180: * GX_CXO_CLK is needed to access RBBM_SW_RESET_CMD register. There are 1181: * scenarios where the IFPC exit sequence is still in progress, and the 1182: * above clock may not be enabled. This situation leads to unclocked 1183: * access. Thus, trigger RBBM_SW_RESET_CMD only when GPU is fully active 1184: * i.e., IFPC sequence is completed. 1185: */ MATCH LINES: 1243, 1244 1231: 1232: req.bw |= adreno_gmu_bus_ab_quantize(adreno_dev, 0); 1233: 1234: /* Disable the power counter so that the GMU is not busy */ 1235: gmu_core_regwrite(device, GEN7_GMU_CX_GMU_POWER_COUNTER_ENABLE, 0); 1236: 1237: ret = CMD_MSG_HDR(req, H2F_MSG_PREPARE_SLUMBER); 1238: if (ret) 1239: return ret; 1240: 1241: ret = gen7_hfi_send_generic_req(adreno_dev, &req, sizeof(req)); 1242: 1243: /* Make sure the fence is in ALLOW mode */ 1244: gmu_core_regwrite(device, GEN7_GMU_AO_AHB_FENCE_CTRL, 0); 1245: 1246: /* 1247: * GEMNOC can enter power collapse state during GPU power down sequence. 1248: * This could abort CX GDSC collapse. Assert Qactive to avoid this. 1249: */ 1250: gmu_core_regwrite(device, GEN7_GPU_GMU_CX_GMU_CX_FALNEXT_INTF, 0x1); 1251: 1252: return ret; 1253: } 1254: 1255: void gen7_gmu_suspend(struct adreno_device *adreno_dev, bool force) 1256: { 1257: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1258: 1259: if (!force && test_bit(ADRENO_DEVICE_RESET_RECOVERY, &adreno_dev->priv)) 1260: return; 1261: 1262: gen7_gmu_pwrctrl_suspend(adreno_dev); 1263: 1264: gmu_core_disable_clks(device); 1265: 1266: kgsl_pwrctrl_disable_cx_gdsc(device); 1267: 1268: gmu_core_rdpm_cx_freq_update(device, 0); MATCH LINES: 1517, 1518, 1520, 1521, 1523 1505: unsigned int status = 0; 1506: 1507: gmu_core_regread(device, GEN7_GMU_AO_HOST_INTERRUPT_STATUS, &status); 1508: gmu_core_regwrite(device, GEN7_GMU_AO_HOST_INTERRUPT_CLR, status); 1509: 1510: if (status & GMU_INT_HOST_AHB_BUS_ERR) 1511: dev_err_ratelimited(gmu_pdev_dev, 1512: "AHB bus error interrupt received\n"); 1513: 1514: if (status & GMU_INT_WDOG_BITE) 1515: gen7_gpudev->handle_watchdog(adreno_dev); 1516: 1517: if (status & GMU_INT_FENCE_ERR) { 1518: unsigned int fence_status; 1519: 1520: gmu_core_regread(device, GEN7_GMU_AHB_FENCE_STATUS, 1521: &fence_status); 1522: dev_err_ratelimited(gmu_pdev_dev, 1523: "FENCE error interrupt received %x\n", fence_status); 1524: } 1525: 1526: if (status & ~GMU_AO_INT_MASK) 1527: dev_err_ratelimited(gmu_pdev_dev, 1528: "Unhandled GMU interrupts 0x%lx\n", 1529: status & ~GMU_AO_INT_MASK); 1530: 1531: return IRQ_HANDLED; 1532: } 1533: 1534: void gen7_gmu_aop_send_acd_state(struct gen7_gmu_device *gmu, bool flag) 1535: { 1536: struct kgsl_device *device = KGSL_DEVICE(gen7_gmu_to_adreno(gmu)); 1537: char msg_buf[36]; 1538: u32 size; 1539: int ret; 1540: 1541: if (IS_ERR_OR_NULL(gmu->qmp) && IS_ERR_OR_NULL(gmu->mailbox.channel)) 1542: return; 1543: 1544: size = scnprintf(msg_buf, sizeof(msg_buf), 1545: "{class: gpu, res: acd, val: %d}", flag); 1546: 1547: /* mailbox controller expects 4-byte aligned buffer */ --- FILE: \adreno_gen7_gmu_snapshot.c | HITS: 2 --- MATCH LINES: 202, 203 190: 191: if (regs_ptr && kgsl_regmap_valid_offset(&device->regmap, regs_ptr[0])) { 192: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS_V2, snapshot, 193: adreno_snapshot_registers_v2, (void *) gen7_snapshot_block_list->gmu_ao_regs); 194: } 195: 196: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS_V2, snapshot, 197: gen7_snapshot_rscc_registers, (void *) gen7_snapshot_block_list->rscc_regs); 198: 199: if (!gen7_gmu_gx_is_on(adreno_dev)) 200: goto dtcm; 201: 202: /* Set fence to ALLOW mode so registers can be read */ 203: kgsl_regwrite(device, GEN7_GMU_AO_AHB_FENCE_CTRL, 0); 204: /* Make sure the previous write posted before reading */ 205: wmb(); 206: 207: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS_V2, snapshot, 208: adreno_snapshot_registers_v2, (void *) gen7_snapshot_block_list->gmu_gx_regs); 209: 210: regs_ptr = (const u32 *)gen7_snapshot_block_list->gmu_gx_blk_dec0_dec1_regs; 211: if (regs_ptr && kgsl_regmap_valid_offset(&device->regmap, regs_ptr[0])) { 212: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS_V2, snapshot, 213: adreno_snapshot_registers_v2, 214: (void *) gen7_snapshot_block_list->gmu_gx_blk_dec0_dec1_regs); 215: } 216: 217: /* 218: * A stalled SMMU can lead to NoC timeouts when host accesses DTCM. 219: * DTCM can be read through side-band DBGC interface on gen7_2_x family. 220: */ 221: if (adreno_smmu_is_stalled(adreno_dev) && !adreno_is_gen7_2_x_family(adreno_dev)) { 222: dev_err(GMU_PDEV_DEV(device), 223: "Not dumping dtcm because SMMU is stalled\n"); 224: return; 225: } 226: 227: dtcm: --- FILE: \adreno_gen7_hfi.c | HITS: 1 --- MATCH LINES: 515 503: (char *) cmd->data); 504: 505: KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic, 506: GMU_PDEV(device), ticks, GMU_FAULT_F2H_MSG_ERR); 507: } 508: 509: void adreno_gen7_receive_debug_req(struct gen7_gmu_device *gmu, void *rcvd) 510: { 511: struct kgsl_device *device = KGSL_DEVICE(gen7_gmu_to_adreno(gmu)); 512: struct hfi_debug_cmd *cmd = rcvd; 513: 514: dev_dbg(GMU_PDEV_DEV(device), "HFI Debug Received: %d %d %d\n", 515: cmd->type, cmd->timestamp, cmd->data); 516: } 517: 518: int gen7_hfi_process_queue(struct gen7_gmu_device *gmu, 519: u32 queue_idx, struct pending_cmd *ret_cmd) 520: { 521: struct kgsl_device *device = KGSL_DEVICE(gen7_gmu_to_adreno(gmu)); 522: u32 rcvd[MAX_RCVD_SIZE]; 523: 524: while (gen7_hfi_queue_read(gmu, queue_idx, rcvd, sizeof(rcvd)) > 0) { 525: /* ACK Handler */ 526: if (MSG_HDR_GET_TYPE(rcvd[0]) == HFI_MSG_ACK) { 527: int ret = gen7_receive_ack_cmd(gmu, rcvd, ret_cmd); 528: 529: if (ret) 530: return ret; 531: continue; 532: } 533: 534: /* Request Handler */ 535: switch (MSG_HDR_GET_ID(rcvd[0])) { 536: case F2H_MSG_ERR: /* No Reply */ 537: adreno_gen7_receive_err_req(gmu, rcvd); 538: break; 539: case F2H_MSG_DEBUG: /* No Reply */ --- FILE: \adreno_gen7_hwsched.c | HITS: 102 --- MATCH LINES: 19, 22, 25, 36, 38, 39, 51, 57, 60 7: #include 8: 9: #include "adreno.h" 10: #include "adreno_gen7.h" 11: #include "adreno_gen7_hwsched.h" 12: #include "adreno_snapshot.h" 13: #include "kgsl_bus.h" 14: #include "kgsl_device.h" 15: #include "kgsl_gmu_core.h" 16: #include "kgsl_trace.h" 17: #include "kgsl_util.h" 18: 19: static void _wakeup_hw_fence_waiters(struct adreno_device *adreno_dev, u32 fault) 20: { 21: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 22: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 23: bool lock = !in_interrupt(); 24: 25: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags)) 26: return; 27: 28: /* 29: * We could be in interrupt context here, which means we need to use spin_lock_irqsave 30: * (which disables interrupts) everywhere we take this lock. Instead of that, simply 31: * avoid taking this lock if we are recording a fault from an interrupt handler. 32: */ 33: if (lock) 34: spin_lock(&hwf->lock); 35: 36: clear_bit(GEN7_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags); 37: 38: /* Avoid creating new hardware fences until recovery is complete */ 39: set_bit(GEN7_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags); 40: 41: if (!lock) 42: /* 43: * This barrier ensures that the above bitops complete before we wake up the waiters 44: */ 45: smp_wmb(); 46: else 47: spin_unlock(&hwf->lock); 48: 49: wake_up_all(&hwf->unack_wq); 50: 51: kgsl_delete_timer(&hfi->hw_fence_timer); 52: } 53: 54: void gen7_hwsched_fault(struct adreno_device *adreno_dev, u32 fault) 55: { 56: /* 57: * Wake up any threads that may be sleeping waiting for the hardware fence unack count to 58: * drop to a desired threshold. 59: */ 60: _wakeup_hw_fence_waiters(adreno_dev, fault); 61: 62: adreno_scheduler_fault(adreno_dev, fault); 63: } 64: 65: void gen7_hwsched_snapshot(struct adreno_device *adreno_dev, 66: struct kgsl_snapshot *snapshot) 67: { 68: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 69: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 70: bool skip_memkind_rb = false; 71: u32 i; 72: bool parse_payload; 73: 74: gen7_gmu_snapshot(adreno_dev, snapshot); 75: 76: adreno_hwsched_parse_fault_cmdobj(adreno_dev, snapshot); 77: 78: /* 79: * First try to dump ringbuffers using context bad HFI payloads 80: * because they have all the ringbuffer parameters. If ringbuffer 81: * payloads are not present, fall back to dumping ringbuffers 82: * based on MEMKIND_RB 83: */ 84: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2) MATCH LINES: 135, 139 123: if (entry->desc.mem_kind == HFI_MEMKIND_PREEMPT_SCRATCH) 124: kgsl_snapshot_add_section(device, 125: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 126: snapshot, adreno_snapshot_global, 127: entry->md); 128: 129: if (entry->desc.mem_kind == HFI_MEMKIND_AQE_BUFFER) 130: kgsl_snapshot_add_section(device, 131: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 132: snapshot, adreno_hwsched_snapshot_aqe_buffer, 133: entry->md); 134: 135: if (entry->desc.mem_kind == HFI_MEMKIND_HW_FENCE) { 136: struct gmu_mem_type_desc desc; 137: 138: desc.memdesc = entry->md; 139: desc.type = SNAPSHOT_GMU_MEM_HW_FENCE; 140: 141: kgsl_snapshot_add_section(device, 142: KGSL_SNAPSHOT_SECTION_GMU_MEMORY, 143: snapshot, adreno_snapshot_gmu_mem, &desc); 144: } 145: 146: } 147: 148: if (adreno_hwsched_context_queue_enabled(adreno_dev)) 149: adreno_hwsched_snapshot_context_queue(device, snapshot); 150: } 151: 152: static void gen7_hwsched_gmu_suspend(struct adreno_device *adreno_dev, bool force) 153: { 154: gen7_gmu_suspend(adreno_dev, force); 155: adreno_hwsched_reset_hfi_mem(adreno_dev); 156: } 157: 158: static int gen7_hwsched_gmu_first_boot(struct adreno_device *adreno_dev) 159: { 160: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 161: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 162: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 163: int level, ret = 0; MATCH LINES: 791, 794, 797, 800, 801, 802, 807, 816, 822, 825, 832, 839, 848, 883, 884, 889, 891, 910, 913, 916, 929, 931, 967 779: device->pwrscale.devfreq_enabled = true; 780: 781: device->pwrctrl.last_stat_updated = ktime_get(); 782: 783: set_bit(ADRENO_DEVICE_FIRST_BOOT_DONE, &adreno_dev->priv); 784: 785: kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE); 786: 787: return 0; 788: } 789: 790: /** 791: * drain_ctx_hw_fences_cpu - Force trigger the hardware fences that 792: * were not sent to TxQueue by the GMU 793: */ 794: static void drain_ctx_hw_fences_cpu(struct adreno_device *adreno_dev, 795: struct adreno_context *drawctxt) 796: { 797: struct adreno_hw_fence_entry *entry, *tmp; 798: 799: spin_lock(&drawctxt->lock); 800: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 801: kgsl_hw_fence_trigger_cpu(KGSL_DEVICE(adreno_dev), entry->kfence); 802: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 803: } 804: spin_unlock(&drawctxt->lock); 805: } 806: 807: static void drain_hw_fences_cpu(struct adreno_device *adreno_dev) 808: { 809: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 810: struct kgsl_context *context; 811: int id; 812: 813: read_lock(&device->context_lock); 814: idr_for_each_entry(&device->context_idr, context, id) { 815: if (context->gmu_registered) 816: drain_ctx_hw_fences_cpu(adreno_dev, ADRENO_CONTEXT(context)); 817: } 818: read_unlock(&device->context_lock); 819: } 820: 821: /** 822: * check_inflight_hw_fences - During SLUMBER entry, we must make sure all hardware fences across 823: * all registered contexts have been sent to TxQueue. If not, take a snapshot 824: */ 825: static int check_inflight_hw_fences(struct adreno_device *adreno_dev) 826: { 827: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 828: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 829: struct kgsl_context *context; 830: int id, ret = 0; 831: 832: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags)) 833: return 0; 834: 835: read_lock(&device->context_lock); 836: idr_for_each_entry(&device->context_idr, context, id) { 837: 838: if (context->gmu_registered) { 839: ret = gen7_hwsched_check_context_inflight_hw_fences(adreno_dev, 840: ADRENO_CONTEXT(context)); 841: if (ret) 842: break; 843: } 844: } 845: read_unlock(&device->context_lock); 846: 847: if (ret) 848: gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE); 849: 850: return ret; 851: } 852: 853: static int gen7_hwsched_power_off(struct adreno_device *adreno_dev) 854: { 855: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 856: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 857: int ret = 0; 858: bool drain_cpu = false; 859: 860: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 861: return 0; 862: 863: kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); 864: 865: ret = gen7_gmu_oob_set(device, oob_gpu); 866: if (ret) { 867: gen7_gmu_oob_clear(device, oob_gpu); 868: goto no_gx_power; 869: } 870: 871: kgsl_pwrscale_update_stats(device); 872: 873: /* Save active coresight registers if applicable */ 874: adreno_coresight_stop(adreno_dev); 875: 876: adreno_irqctrl(adreno_dev, 0); 877: 878: gen7_gmu_oob_clear(device, oob_gpu); 879: 880: no_gx_power: 881: kgsl_pwrctrl_irq(device, false); 882: 883: /* Make sure GMU has sent all hardware fences to TxQueue */ 884: if (check_inflight_hw_fences(adreno_dev)) 885: drain_cpu = true; 886: 887: gen7_hwsched_gmu_power_off(adreno_dev); 888: 889: /* Now that we are sure that GMU is powered off, drain pending fences */ 890: if (drain_cpu) 891: drain_hw_fences_cpu(adreno_dev); 892: 893: adreno_hwsched_unregister_contexts(adreno_dev); 894: 895: adreno_llcc_slice_deactivate(adreno_dev); 896: 897: clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags); 898: 899: kgsl_delete_timer_sync(&device->idle_timer); 900: 901: kgsl_pwrscale_sleep(device); 902: 903: kgsl_pwrctrl_clear_l3_vote(device); 904: 905: kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER); 906: 907: return ret; 908: } 909: 910: static void check_hw_fence_unack_count(struct adreno_device *adreno_dev) 911: { 912: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 913: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 914: u32 unack_count; 915: 916: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags)) 917: return; 918: 919: gen7_hwsched_process_msgq(adreno_dev); 920: 921: spin_lock(&hwf->lock); 922: unack_count = hwf->unack_count; 923: spin_unlock(&hwf->lock); 924: 925: if (!unack_count) 926: return; 927: 928: dev_err(GMU_PDEV_DEV(device), 929: "hardware fence unack_count(%d) isn't zero before SLUMBER\n", 930: unack_count); 931: gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE); 932: } 933: 934: static void hwsched_idle_check(struct work_struct *work) 935: { 936: struct kgsl_device *device = container_of(work, 937: struct kgsl_device, idle_check_ws); 938: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 939: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 940: 941: kgsl_mutex_lock(&device->mutex); 942: 943: if (test_bit(GMU_DISABLE_SLUMBER, &device->gmu_core.flags)) 944: goto done; 945: 946: if (atomic_read(&device->active_cnt) || time_is_after_jiffies(device->idle_jiffies)) { 947: kgsl_pwrscale_update(device); 948: goto done; 949: } 950: 951: spin_lock(&device->submit_lock); 952: if (device->submit_now) { 953: spin_unlock(&device->submit_lock); 954: kgsl_pwrscale_update(device); 955: kgsl_start_idle_timer(device); 956: goto done; 957: } 958: 959: device->skip_inline_submit = true; 960: spin_unlock(&device->submit_lock); 961: 962: if (!gpudev->hw_isidle(adreno_dev)) { 963: dev_err(device->dev, "GPU isn't idle before SLUMBER\n"); 964: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 965: } 966: 967: check_hw_fence_unack_count(adreno_dev); 968: 969: gen7_hwsched_power_off(adreno_dev); 970: 971: done: 972: kgsl_mutex_unlock(&device->mutex); 973: } 974: 975: static int gen7_hwsched_first_open(struct adreno_device *adreno_dev) 976: { 977: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 978: int ret; 979: 980: /* 981: * Do the one time settings that need to happen when we 982: * attempt to boot the gpu the very first time 983: */ 984: ret = gen7_hwsched_first_boot(adreno_dev); 985: if (ret) 986: return ret; 987: 988: /* 989: * A client that does a first_open but never closes the device 990: * may prevent us from going back to SLUMBER. So trigger the idle 991: * check by incrementing the active count and immediately releasing it. MATCH LINES: 1223, 1224, 1227, 1231, 1234, 1237, 1239, 1240, 1241, 1246, 1251, 1259, 1260, 1261, 1263, 1268, 1269, 1270, 1273, 1274, 1276, 1278, 1282, 1283, 1292, 1298, 1304, 1307, 1308, 1310, 1317, 1321, 1322, 1324, 1325, 1327, 1333, 1342, 1343, 1344, 1346, 1348, 1353, 1359, 1360, 1366, 1374, 1377, 1381, 1384, 1385, 1389, 1403, 1414, 1421, 1422, 1426, 1439, 1443, 1449, 1451, 1455, 1459, 1465 1211: 1212: read_lock(&hfi->msglock); 1213: 1214: list_for_each_entry(cmd, &hfi->msglist, node) { 1215: if (MSG_HDR_GET_ID(cmd->sent_hdr) == H2F_MSG_UNREGISTER_CONTEXT) 1216: complete(&cmd->complete); 1217: } 1218: 1219: read_unlock(&hfi->msglock); 1220: } 1221: 1222: /** 1223: * process_context_hw_fences_after_reset - This function processes all hardware fences that were 1224: * sent to GMU prior to recovery. If a fence is not retired by the GPU, and the context is still 1225: * good, then move them to the reset list. 1226: */ 1227: static void process_context_hw_fences_after_reset(struct adreno_device *adreno_dev, 1228: struct adreno_context *drawctxt, struct list_head *reset_list) 1229: { 1230: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1231: struct adreno_hw_fence_entry *entry, *tmp; 1232: 1233: spin_lock(&drawctxt->lock); 1234: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 1235: struct adreno_context *drawctxt = entry->drawctxt; 1236: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 1237: bool retired = kgsl_check_timestamp(device, &drawctxt->base, (u32)entry->cmd.ts); 1238: 1239: /* Delete the fences that GMU has sent to the TxQueue */ 1240: if (timestamp_cmp(hdr->out_fence_ts, (u32)entry->cmd.ts) >= 0) { 1241: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 1242: continue; 1243: } 1244: 1245: /* 1246: * Force retire the fences if the ts is retired and context is not 1247: * registered with GMU, or if the context is gone bad. 1248: */ 1249: if ((retired && !drawctxt->base.gmu_registered) || 1250: kgsl_context_is_bad(&drawctxt->base)) 1251: entry->cmd.flags |= HW_FENCE_FLAG_SKIP_MEMSTORE; 1252: 1253: list_add_tail(&entry->reset_node, reset_list); 1254: } 1255: spin_unlock(&drawctxt->lock); 1256: } 1257: 1258: /** 1259: * process_inflight_hw_fences_after_reset - Send hardware fences from all contexts back to the GMU 1260: * after fault recovery. We must wait for ack when sending each of these fences to GMU so as to 1261: * avoid sending a large number of hardware fences in a short span of time. 1262: */ 1263: static int process_inflight_hw_fences_after_reset(struct adreno_device *adreno_dev) 1264: { 1265: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1266: struct kgsl_context *context = NULL; 1267: int id, ret = 0; 1268: struct list_head hw_fence_list; 1269: struct adreno_hw_fence_entry *entry, *tmp; 1270: bool update_out_fence_ts = false; 1271: 1272: /* 1273: * Since we need to wait for ack from GMU when sending each inflight fence back to GMU, we 1274: * cannot send them from within atomic context. Hence, walk list of such hardware fences 1275: * for each context and add it to this local list and then walk this list to send all these 1276: * fences to GMU. 1277: */ 1278: INIT_LIST_HEAD(&hw_fence_list); 1279: 1280: read_lock(&device->context_lock); 1281: idr_for_each_entry(&device->context_idr, context, id) { 1282: process_context_hw_fences_after_reset(adreno_dev, ADRENO_CONTEXT(context), 1283: &hw_fence_list); 1284: } 1285: read_unlock(&device->context_lock); 1286: 1287: /* 1288: * Although we are not destroying the entries here, they can get destroyed concurrently 1289: * in f2h_main thread once they have been sent to GMU. Hence, to be safe against entry 1290: * destroy, use list_for_each_entry_safe. 1291: */ 1292: list_for_each_entry_safe(entry, tmp, &hw_fence_list, reset_node) { 1293: struct adreno_context *drawctxt = entry->drawctxt; 1294: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 1295: u32 entry_ts = (u32)entry->cmd.ts; 1296: 1297: /* 1298: * We must remove this entry from hw_fence_list before sending it to GMU to avoid 1299: * racing with the f2h_main thread 1300: */ 1301: list_del_init(&entry->reset_node); 1302: 1303: /* 1304: * We must access the hw fence entry before sending it to GMU as once it is 1305: * sent to GMU, it may be freed by f2h_main thread concurrently 1306: */ 1307: if (((entry->cmd.flags & HW_FENCE_FLAG_SKIP_MEMSTORE) != 0) && 1308: (timestamp_cmp(entry_ts, hdr->out_fence_ts) > 0)) { 1309: if (_kgsl_context_get(&drawctxt->base)) 1310: update_out_fence_ts = true; 1311: } 1312: 1313: /* 1314: * This is part of the reset sequence and any error in this path will be handled by 1315: * the caller. 1316: */ 1317: ret = gen7_send_hw_fence_hfi_wait_ack(adreno_dev, entry, 0); 1318: if (ret) 1319: break; 1320: /* 1321: * If HW_FENCE_FLAG_SKIP_MEMSTORE is set, then GMU context queue header will not be 1322: * updated for this fence. Hence, update it here. 1323: */ 1324: if (update_out_fence_ts) { 1325: hdr->out_fence_ts = entry_ts; 1326: kgsl_context_put(&drawctxt->base); 1327: update_out_fence_ts = false; 1328: } 1329: } 1330: 1331: /* Remove remaining entries from the list if we hit an error */ 1332: if (ret) { 1333: list_for_each_entry_safe(entry, tmp, &hw_fence_list, reset_node) { 1334: list_del_init(&entry->reset_node); 1335: } 1336: } 1337: 1338: return ret; 1339: } 1340: 1341: /** 1342: * process_detached_hw_fences_after_reset - Send fences that couldn't be sent to GMU when a context 1343: * got detached. We must wait for ack when sending each of these fences to GMU so as to avoid 1344: * sending a large number of hardware fences in a short span of time. 1345: */ 1346: static int process_detached_hw_fences_after_reset(struct adreno_device *adreno_dev) 1347: { 1348: struct adreno_hw_fence_entry *entry, *tmp; 1349: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 1350: struct kgsl_context *context = NULL; 1351: int ret = 0; 1352: 1353: list_for_each_entry_safe(entry, tmp, &hfi->detached_hw_fence_list, node) { 1354: 1355: /* 1356: * This is part of the reset sequence and any error in this path will be handled by 1357: * the caller. 1358: */ 1359: ret = gen7_send_hw_fence_hfi_wait_ack(adreno_dev, entry, 1360: HW_FENCE_FLAG_SKIP_MEMSTORE); 1361: if (ret) 1362: return ret; 1363: 1364: context = &entry->drawctxt->base; 1365: 1366: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 1367: 1368: kgsl_context_put(context); 1369: } 1370: 1371: return ret; 1372: } 1373: 1374: static int gen7_hwsched_drain_context_hw_fences(struct adreno_device *adreno_dev, 1375: struct adreno_context *drawctxt) 1376: { 1377: struct adreno_hw_fence_entry *entry, *tmp; 1378: int ret = 0; 1379: 1380: /* We don't need the drawctxt lock here as this context has already been invalidated */ 1381: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_list, node) { 1382: 1383: /* Any error here is fatal */ 1384: ret = gen7_send_hw_fence_hfi_wait_ack(adreno_dev, entry, 1385: HW_FENCE_FLAG_SKIP_MEMSTORE); 1386: if (ret) 1387: break; 1388: 1389: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 1390: } 1391: 1392: return ret; 1393: } 1394: 1395: static struct adreno_context *_get_guilty_context(struct kgsl_device *device) 1396: { 1397: struct kgsl_context *context = NULL; 1398: struct adreno_context *guilty = NULL; 1399: int id; 1400: 1401: read_lock(&device->context_lock); 1402: idr_for_each_entry(&device->context_idr, context, id) { 1403: if (test_and_clear_bit(KGSL_CONTEXT_PRIV_INVALID_DRAIN_HW_FENCE, &context->priv) && 1404: _kgsl_context_get(context)) { 1405: guilty = ADRENO_CONTEXT(context); 1406: break; 1407: } 1408: } 1409: read_unlock(&device->context_lock); 1410: 1411: return guilty; 1412: } 1413: 1414: static int drain_guilty_context_hw_fences(struct adreno_device *adreno_dev) 1415: { 1416: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1417: struct adreno_context *guilty = _get_guilty_context(device); 1418: int ret = 0; 1419: 1420: /* 1421: * We don't need drawctxt spinlock to signal these fences since the only other place 1422: * which can access these fences is the context detach path and device mutex 1423: * ensures mutual exclusion between recovery thread and detach thread. 1424: */ 1425: while (guilty) { 1426: ret = gen7_hwsched_drain_context_hw_fences(adreno_dev, guilty); 1427: 1428: kgsl_context_put(&guilty->base); 1429: 1430: if (ret) 1431: break; 1432: 1433: guilty = _get_guilty_context(device); 1434: } 1435: 1436: return ret; 1437: } 1438: 1439: static int handle_hw_fences_after_reset(struct adreno_device *adreno_dev) 1440: { 1441: int ret; 1442: 1443: ret = drain_guilty_context_hw_fences(adreno_dev); 1444: if (ret) 1445: return ret; 1446: 1447: /* 1448: * We must do this after adreno_hwsched_replay() so that context registration 1449: * is done before we re-send the un-retired hardware fences to the GMU 1450: */ 1451: ret = process_inflight_hw_fences_after_reset(adreno_dev); 1452: if (ret) 1453: return ret; 1454: 1455: ret = process_detached_hw_fences_after_reset(adreno_dev); 1456: if (ret) 1457: return ret; 1458: 1459: return gen7_hwsched_disable_hw_fence_throttle(adreno_dev); 1460: } 1461: 1462: int gen7_hwsched_reset_replay(struct adreno_device *adreno_dev) 1463: { 1464: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 1465: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 1466: int ret; 1467: 1468: /* 1469: * Any pending context unregister packets will be lost 1470: * since we hard reset the GMU. This means any threads waiting 1471: * for context unregister hfi ack will timeout. Wake them 1472: * to avoid false positive ack timeout messages later. 1473: */ 1474: gen7_hwsched_drain_ctxt_unregister(adreno_dev); 1475: 1476: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 1477: return 0; 1478: 1479: gen7_disable_gpu_irq(adreno_dev); 1480: 1481: gen7_gmu_irq_disable(adreno_dev); 1482: 1483: gen7_hwsched_hfi_stop(adreno_dev); 1484: 1485: gen7_hwsched_gmu_suspend(adreno_dev, true); 1486: 1487: adreno_hwsched_unregister_contexts(adreno_dev); 1488: 1489: adreno_llcc_slice_deactivate(adreno_dev); MATCH LINES: 1512 1500: /* 1501: * When we reset, we want to coldboot incase any scratch corruption 1502: * has occurred before we faulted. 1503: */ 1504: gmu_core_mark_for_coldboot(KGSL_DEVICE(adreno_dev)); 1505: 1506: ret = gen7_hwsched_boot(adreno_dev); 1507: if (ret) 1508: goto done; 1509: 1510: adreno_hwsched_replay(adreno_dev); 1511: 1512: ret = handle_hw_fences_after_reset(adreno_dev); 1513: done: 1514: BUG_ON(ret); 1515: 1516: return ret; 1517: } 1518: 1519: static void gen7_hwsched_set_thermal_index(struct adreno_device *adreno_dev) 1520: { 1521: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1522: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 1523: int ret; 1524: 1525: if (device->state != KGSL_STATE_ACTIVE) 1526: return; 1527: 1528: /* If GMU is up, send the constraint to GMU */ 1529: ret = gen7_hwsched_hfi_set_value(adreno_dev, HFI_VALUE_MAX_GPU_THERMAL_INDEX, 0, 1530: (pwr->num_pwrlevels - pwr->thermal_pwrlevel)); 1531: if (ret) 1532: dev_err(GMU_PDEV_DEV(device), "Failed to set thermal level %u, ret: %d\n", 1533: pwr->thermal_pwrlevel, ret); 1534: } 1535: 1536: const struct adreno_power_ops gen7_hwsched_power_ops = { MATCH LINES: 1551 1539: .active_count_get = gen7_hwsched_active_count_get, 1540: .touch_wakeup = gen7_hwsched_touch_wakeup, 1541: .pm_suspend = gen7_hwsched_pm_suspend, 1542: .pm_resume = gen7_hwsched_pm_resume, 1543: .gpu_clock_set = gen7_hwsched_clock_set, 1544: .gpu_bus_set = gen7_hwsched_bus_set, 1545: .set_thermal_index = gen7_hwsched_set_thermal_index, 1546: }; 1547: 1548: const struct adreno_hwsched_ops gen7_hwsched_ops = { 1549: .submit_drawobj = gen7_hwsched_submit_drawobj, 1550: .preempt_count = gen7_hwsched_preempt_count_get, 1551: .create_hw_fence = gen7_hwsched_create_hw_fence, 1552: }; 1553: 1554: int gen7_hwsched_probe(struct platform_device *pdev, 1555: u32 chipid, const struct adreno_gpu_core *gpucore) 1556: { 1557: struct adreno_device *adreno_dev; 1558: struct kgsl_device *device; 1559: struct gen7_hwsched_device *gen7_hwsched_dev; 1560: int ret; 1561: 1562: gen7_hwsched_dev = devm_kzalloc(&pdev->dev, sizeof(*gen7_hwsched_dev), 1563: GFP_KERNEL); 1564: if (!gen7_hwsched_dev) 1565: return -ENOMEM; 1566: 1567: adreno_dev = &gen7_hwsched_dev->gen7_dev.adreno_dev; 1568: 1569: adreno_dev->hwsched_enabled = true; 1570: 1571: adreno_dev->irq_mask = GEN7_HWSCHED_INT_MASK; 1572: 1573: ret = gen7_probe_common(pdev, adreno_dev, chipid, gpucore); 1574: if (ret) 1575: return ret; MATCH LINES: 1593, 1594 1581: timer_setup(&device->idle_timer, hwsched_idle_timer, 0); 1582: 1583: if (ADRENO_FEATURE(adreno_dev, ADRENO_LPAC)) 1584: adreno_dev->lpac_enabled = true; 1585: 1586: if (ADRENO_FEATURE(adreno_dev, ADRENO_DMS)) { 1587: set_bit(ADRENO_DEVICE_DMS, &adreno_dev->priv); 1588: adreno_dev->dms_enabled = true; 1589: } 1590: 1591: kgsl_mmu_set_feature(device, KGSL_MMU_PAGEFAULT_TERMINATE); 1592: 1593: if (ADRENO_FEATURE(adreno_dev, ADRENO_HW_FENCE)) 1594: device->max_syncobj_hw_fence_count = min_t(u32, HFI_SYNCOBJ_LEGACY_HW_FENCE_MAX, 1595: MAX_SYNCOBJ_QUERY_BITS); 1596: 1597: ret = adreno_hwsched_init(adreno_dev, &gen7_hwsched_ops); 1598: if (ret) 1599: dev_err(&pdev->dev, "adreno hardware scheduler init failed ret %d\n", ret); 1600: 1601: return ret; 1602: } 1603: 1604: int gen7_hwsched_add_to_minidump(struct adreno_device *adreno_dev) 1605: { 1606: struct gen7_device *gen7_dev = container_of(adreno_dev, 1607: struct gen7_device, adreno_dev); 1608: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1609: struct gmu_core_device *gmu_core = &device->gmu_core; 1610: struct gen7_hwsched_device *gen7_hwsched = container_of(gen7_dev, 1611: struct gen7_hwsched_device, gen7_dev); 1612: struct gen7_hwsched_hfi *hw_hfi = &gen7_hwsched->hwsched_hfi; 1613: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1614: int ret, i; 1615: 1616: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, KGSL_HWSCHED_DEVICE, 1617: (void *)(gen7_hwsched), sizeof(struct gen7_hwsched_device)); 1618: if (ret) --- FILE: \adreno_gen7_hwsched_hfi.c | HITS: 378 --- MATCH LINES: 61 49: { 4, 0, }, /* RB0 */ 50: { 4, 4, }, /* RB1 */ 51: { 3, 8, }, /* RB2 */ 52: { 3, 11, }, /* RB3 */ 53: }, gen7_hfi_dqs_lpac[KGSL_PRIORITY_MAX_RB_LEVELS + 1] = { 54: { 4, 0, }, /* RB0 */ 55: { 4, 4, }, /* RB1 */ 56: { 3, 8, }, /* RB2 */ 57: { 2, 11, }, /* RB3 */ 58: { 1, 13, }, /* RB LPAC */ 59: }; 60: 61: struct pending_cmd hw_fence_ack; 62: 63: struct gen7_hwsched_hfi *to_gen7_hwsched_hfi( 64: struct adreno_device *adreno_dev) 65: { 66: struct gen7_device *gen7_dev = container_of(adreno_dev, 67: struct gen7_device, adreno_dev); 68: struct gen7_hwsched_device *gen7_hwsched = container_of(gen7_dev, 69: struct gen7_hwsched_device, gen7_dev); 70: 71: return &gen7_hwsched->hwsched_hfi; 72: } 73: 74: int gen7_hfi_send_lpac_feature_ctrl(struct adreno_device *adreno_dev) 75: { 76: if (!adreno_dev->lpac_enabled) 77: return 0; 78: 79: return gen7_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_LPAC, 1, 0); 80: } 81: 82: static void add_waiter(struct gen7_hwsched_hfi *hfi, u32 hdr, 83: struct pending_cmd *ack) 84: { 85: memset(ack, 0x0, sizeof(*ack)); MATCH LINES: 259 247: hdr = drawctxt->gmu_context_queue.hostptr; 248: queue = (u32 *)(drawctxt->gmu_context_queue.hostptr + sizeof(*hdr)); 249: 250: for (i = hdr->read_index; i != hdr->write_index;) { 251: if (MSG_HDR_GET_ID(queue[i]) != H2F_MSG_ISSUE_SYNCOBJ) { 252: i = (i + MSG_HDR_GET_SIZE(queue[i])) % hdr->queue_size; 253: continue; 254: } 255: 256: if (adreno_gmu_context_queue_read(drawctxt, (u32 *) &cmd, i, sizeof(cmd) >> 2)) 257: break; 258: 259: if (cmd.timestamp == ts) { 260: log_syncobj(gmu, drawctxt, &cmd, 261: (i + (sizeof(cmd) >> 2)) % hdr->queue_size); 262: break; 263: } 264: i = (i + MSG_HDR_GET_SIZE(queue[i])) % hdr->queue_size; 265: } 266: 267: if (i == hdr->write_index) 268: dev_err(GMU_PDEV_DEV(device), "Couldn't find unsignaled syncobj ctx:%d ts:%d\n", 269: ctxt_id, ts); 270: 271: kgsl_context_put(context); 272: } 273: 274: static void log_gpu_fault_legacy(struct adreno_device *adreno_dev) 275: { 276: struct device *gmu_pdev_dev = GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)); 277: struct hfi_context_bad_cmd_legacy *cmd = adreno_dev->hwsched.ctxt_bad; 278: 279: switch (cmd->error) { 280: case GMU_GPU_HW_HANG: 281: dev_crit_ratelimited(gmu_pdev_dev, "MISC: GPU hang detected\n"); 282: break; 283: case GMU_GPU_SW_HANG: MATCH LINES: 680, 681, 683, 685, 686, 691, 692, 695, 696, 697, 698, 701, 703, 705, 706, 708, 711, 713, 724, 725, 727, 730 668: } 669: 670: /* Non fatal RBBM error interrupts don't go through reset and recovery */ 671: if (!log_gpu_fault(adreno_dev)) { 672: memset(adreno_dev->hwsched.ctxt_bad, 0x0, HFI_MAX_MSG_SIZE); 673: return; 674: } 675: 676: done: 677: gen7_hwsched_fault(adreno_dev, ADRENO_HARD_FAULT); 678: } 679: 680: #define GET_QUERIED_FENCE_INDEX(x) (x / BITS_PER_SYNCOBJ_QUERY) 681: #define GET_QUERIED_FENCE_BIT(x) (x % BITS_PER_SYNCOBJ_QUERY) 682: 683: static bool fence_is_queried(struct hfi_syncobj_query_cmd *cmd, u32 fence_index) 684: { 685: u32 index = GET_QUERIED_FENCE_INDEX(fence_index); 686: u32 bit = GET_QUERIED_FENCE_BIT(fence_index); 687: 688: return (cmd->queries[index].query_bitmask & BIT(bit)); 689: } 690: 691: static void set_fence_signal_bit(struct adreno_device *adreno_dev, 692: struct hfi_syncobj_query_cmd *reply, struct dma_fence *fence, u32 fence_index) 693: { 694: struct device *gmu_pdev_dev = GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)); 695: u32 index = GET_QUERIED_FENCE_INDEX(fence_index); 696: u32 bit = GET_QUERIED_FENCE_BIT(fence_index); 697: u64 flags = ADRENO_HW_FENCE_SW_STATUS_PENDING; 698: char name[KGSL_FENCE_NAME_LEN]; 699: char value[32] = "unknown"; 700: 701: kgsl_fence_timeline_value_str(fence, value, sizeof(value)); 702: 703: if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) { 704: dev_err(gmu_pdev_dev, 705: "GMU is waiting for signaled fence(ctx:%llu seqno:%llu value:%s)\n", 706: fence->context, fence->seqno, value); 707: reply->queries[index].query_bitmask |= BIT(bit); 708: flags = ADRENO_HW_FENCE_SW_STATUS_SIGNALED; 709: } 710: 711: kgsl_get_fence_name(fence, name, sizeof(name)); 712: 713: trace_adreno_hw_fence_query(fence->context, fence->seqno, flags, name, value); 714: } 715: 716: static void gen7_syncobj_query_reply(struct adreno_device *adreno_dev, 717: struct kgsl_drawobj *drawobj, struct hfi_syncobj_query_cmd *cmd) 718: { 719: struct hfi_syncobj_query_cmd reply = {0}; 720: int i; 721: struct kgsl_drawobj_sync *syncobj = SYNCOBJ(drawobj); 722: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 723: 724: for (i = 0; i < syncobj->num_hw_fence; i++) { 725: struct dma_fence *fence = syncobj->hw_fences[i].fence; 726: 727: if (!fence_is_queried(cmd, i)) 728: continue; 729: 730: set_fence_signal_bit(adreno_dev, &reply, fence, i); 731: } 732: 733: reply.hdr = CREATE_MSG_HDR(F2H_MSG_SYNCOBJ_QUERY, HFI_MSG_CMD); 734: reply.gmu_ctxt_id = cmd->gmu_ctxt_id; 735: reply.sync_obj_ts = cmd->sync_obj_ts; 736: 737: trace_adreno_syncobj_query_reply(reply.gmu_ctxt_id, reply.sync_obj_ts, 738: gpudev->read_alwayson(adreno_dev)); 739: 740: gen7_hfi_send_cmd_async(adreno_dev, &reply, sizeof(reply)); 741: } 742: 743: struct syncobj_query_work { 744: /** @cmd: The query command to be processed */ 745: struct hfi_syncobj_query_cmd cmd; 746: /** @context: kgsl context that is waiting for this sync object */ 747: struct kgsl_context *context; 748: /** @work: The work structure to execute syncobj query reply */ 749: struct kthread_work work; 750: }; 751: 752: static void gen7_process_syncobj_query_work(struct kthread_work *work) 753: { 754: struct syncobj_query_work *query_work = container_of(work, MATCH LINES: 774, 790, 794 762: bool missing = true; 763: 764: mutex_lock(&hwsched->mutex); 765: kgsl_mutex_lock(&device->mutex); 766: 767: list_for_each_entry(obj, &hwsched->cmd_list, node) { 768: struct kgsl_drawobj *drawobj = obj->drawobj; 769: 770: if ((drawobj->type & SYNCOBJ_TYPE) == 0) 771: continue; 772: 773: if ((drawobj->context->id == cmd->gmu_ctxt_id) && 774: (drawobj->timestamp == cmd->sync_obj_ts)) { 775: gen7_syncobj_query_reply(adreno_dev, drawobj, cmd); 776: missing = false; 777: break; 778: } 779: } 780: 781: if (missing) { 782: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 783: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 784: 785: /* 786: * If the sync object is not found, it can only mean that the sync object was 787: * retired by the GMU in the meanwhile. However, if that is not the case, then 788: * we have a problem. 789: */ 790: if (timestamp_cmp(cmd->sync_obj_ts, hdr->sync_obj_ts) > 0) { 791: dev_err(GMU_PDEV_DEV(device), 792: "Missing sync object ctx:%d ts:%d retired:%d\n", 793: context->id, cmd->sync_obj_ts, hdr->sync_obj_ts); 794: gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE); 795: gen7_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 796: } 797: } 798: 799: kgsl_mutex_unlock(&device->mutex); 800: mutex_unlock(&hwsched->mutex); 801: 802: kgsl_context_put(context); 803: kfree(query_work); 804: } 805: 806: static void gen7_trigger_syncobj_query(struct adreno_device *adreno_dev, 807: u32 *rcvd) 808: { 809: struct syncobj_query_work *query_work; 810: struct hfi_syncobj_query_cmd *cmd = (struct hfi_syncobj_query_cmd *)rcvd; 811: struct kgsl_context *context = NULL; 812: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 813: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 814: int ret; 815: 816: trace_adreno_syncobj_query(cmd->gmu_ctxt_id, cmd->sync_obj_ts, 817: gpudev->read_alwayson(adreno_dev)); 818: MATCH LINES: 846, 847, 848, 850, 853, 854, 856, 859, 860, 861, 864, 866, 869, 871, 872, 877, 880, 882, 884, 885, 889, 894, 895, 897, 907, 912, 914, 917, 919, 922, 923, 932, 935, 936, 938, 944, 946, 952, 954, 961, 964, 967, 971, 973, 976, 980, 985, 987, 994, 996, 997, 1001, 1004, 1012, 1015, 1021, 1040, 1048, 1054, 1061, 1073, 1077, 1083, 1085, 1091, 1092, 1094, 1097, 1099, 1103, 1104, 1113, 1117, 1121, 1122, 1126, 1161, 1163, 1164 834: kgsl_context_put(context); 835: return; 836: } 837: 838: kthread_init_work(&query_work->work, gen7_process_syncobj_query_work); 839: memcpy(&query_work->cmd, cmd, sizeof(*cmd)); 840: query_work->context = context; 841: 842: kthread_queue_work(adreno_dev->scheduler_worker, &query_work->work); 843: } 844: 845: /* 846: * This defines the maximum unack'd hardware fences that we allow. When this limit is reached, we 847: * will put all threads (that want to create a hardware fence) to sleep until the maximum unack'd 848: * hardware fence count drops to MIN_HW_FENCE_UNACK_COUNT 849: */ 850: #define MAX_HW_FENCE_UNACK_COUNT 20 851: 852: /* 853: * Once the maximum unack'd hardware fences drops to this value, wake up all the threads (that want 854: * to create hardware fences) 855: */ 856: #define MIN_HW_FENCE_UNACK_COUNT 10 857: 858: /* 859: * This is the maximum duration (in milliseconds) a thread (that wants to create a hardware fence) 860: * is put to sleep while we wait for the maximum number of unack'd hardware fences to drop from 861: * MAX_HW_FENCE_UNACK_COUNT to MIN_HW_FENCE_UNACK_COUNT. If the count doesn't drop to the desired 862: * value, then log an error and trigger snapshot and recovery. 863: */ 864: #define HW_FENCE_SLEEP_MS 200 865: 866: static void _enable_hw_fence_throttle(struct adreno_device *adreno_dev) 867: { 868: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 869: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 870: 871: set_bit(GEN7_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags); 872: set_bit(GEN7_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags); 873: 874: /* Avoid submitting new work to gpu until the unack count drops to a desired threshold */ 875: adreno_get_gpu_halt(adreno_dev); 876: 877: mod_timer(&hfi->hw_fence_timer, jiffies + msecs_to_jiffies(HW_FENCE_SLEEP_MS)); 878: } 879: 880: static void _increment_hw_fence_unack_count(struct adreno_device *adreno_dev) 881: { 882: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 883: 884: if ((++hwf->unack_count) == MAX_HW_FENCE_UNACK_COUNT) 885: _enable_hw_fence_throttle(adreno_dev); 886: } 887: 888: /** 889: * _send_hw_fence_no_ack - Send a hardware fence hfi packet to GMU without waiting for its ack. 890: * Increment the unack count on success 891: * 892: * Return: 0 on success or negative error on failure 893: */ 894: static int _send_hw_fence_no_ack(struct adreno_device *adreno_dev, 895: struct adreno_hw_fence_entry *entry) 896: { 897: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 898: u32 seqnum; 899: int ret; 900: 901: 902: seqnum = atomic_inc_return(&hwf->seqnum); 903: entry->cmd.hdr = MSG_HDR_SET_SEQNUM_SIZE(entry->cmd.hdr, seqnum, sizeof(entry->cmd) >> 2); 904: 905: ret = gen7_hfi_cmdq_write(adreno_dev, (u32 *)&entry->cmd, sizeof(entry->cmd)); 906: if (!ret) 907: _increment_hw_fence_unack_count(adreno_dev); 908: 909: return ret; 910: } 911: 912: static struct adreno_hw_fence_entry *_get_deferred_hw_fence(struct adreno_context *drawctxt, u32 ts) 913: { 914: struct adreno_hw_fence_entry *entry = NULL, *next, *deferred_hw_fence_entry = NULL; 915: 916: spin_lock(&drawctxt->lock); 917: list_for_each_entry_safe(entry, next, &drawctxt->hw_fence_list, node) { 918: 919: if (timestamp_cmp((u32)entry->cmd.ts, ts) > 0) 920: break; 921: 922: /* We found a deferred hardware fence */ 923: deferred_hw_fence_entry = entry; 924: break; 925: } 926: spin_unlock(&drawctxt->lock); 927: 928: /* 929: * This path executes in isolation from any paths that may release this entry. So, it is 930: * safe to handle this entry outside of the drawctxt spinlock 931: */ 932: return deferred_hw_fence_entry; 933: } 934: 935: static int _send_deferred_hw_fence(struct adreno_device *adreno_dev, 936: struct adreno_context *drawctxt, struct adreno_hw_fence_entry *entry, u32 ts) 937: { 938: bool retired = kgsl_check_timestamp(KGSL_DEVICE(adreno_dev), &drawctxt->base, ts) || 939: kgsl_context_is_bad(&drawctxt->base); 940: int ret = 0; 941: u32 flags = 0; 942: 943: if (retired) 944: flags |= HW_FENCE_FLAG_SKIP_MEMSTORE; 945: 946: ret = gen7_send_hw_fence_hfi_wait_ack(adreno_dev, entry, flags); 947: if (ret) 948: return ret; 949: 950: spin_lock(&drawctxt->lock); 951: if (!retired) 952: list_move_tail(&entry->node, &drawctxt->hw_fence_inflight_list); 953: else 954: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 955: spin_unlock(&drawctxt->lock); 956: 957: return 0; 958: } 959: 960: /** 961: * process_hw_fence_deferred_ctxt - This function sends hardware fences to GMU (from the 962: * deferred drawctxt) which couldn't be sent earlier 963: */ 964: static int process_hw_fence_deferred_ctxt(struct adreno_device *adreno_dev, 965: struct adreno_context *drawctxt, u32 ts) 966: { 967: struct adreno_hw_fence_entry *deferred_hw_fence_entry = NULL; 968: int ret = 0; 969: 970: do { 971: deferred_hw_fence_entry = _get_deferred_hw_fence(drawctxt, ts); 972: 973: if (!deferred_hw_fence_entry) 974: break; 975: 976: ret = _send_deferred_hw_fence(adreno_dev, drawctxt, deferred_hw_fence_entry, ts); 977: if (ret) 978: break; 979: 980: } while (deferred_hw_fence_entry != NULL); 981: 982: return ret; 983: } 984: 985: static void _disable_hw_fence_throttle(struct adreno_device *adreno_dev, bool clear_abort_bit) 986: { 987: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 988: bool max; 989: 990: spin_lock(&hwf->lock); 991: 992: hwf->defer_drawctxt = NULL; 993: hwf->defer_ts = 0; 994: max = test_bit(GEN7_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags); 995: if (max) { 996: clear_bit(GEN7_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags); 997: clear_bit(GEN7_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags); 998: } 999: 1000: if (clear_abort_bit) 1001: clear_bit(GEN7_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags); 1002: spin_unlock(&hwf->lock); 1003: 1004: /* Wake up dispatcher and any sleeping threads that want to create hardware fences */ 1005: if (max) { 1006: adreno_put_gpu_halt(adreno_dev); 1007: adreno_scheduler_queue(adreno_dev); 1008: wake_up_all(&hwf->unack_wq); 1009: } 1010: } 1011: 1012: static void gen7_defer_hw_fence_work(struct kthread_work *work) 1013: { 1014: struct gen7_hwsched_hfi *hfi = container_of(work, 1015: struct gen7_hwsched_hfi, defer_hw_fence_work); 1016: struct gen7_hwsched_device *gen7_hwsched = container_of(hfi, struct gen7_hwsched_device, 1017: hwsched_hfi); 1018: struct adreno_context *drawctxt; 1019: struct adreno_device *adreno_dev = &gen7_hwsched->gen7_dev.adreno_dev; 1020: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1021: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 1022: u32 ts; 1023: int ret; 1024: 1025: /* 1026: * Grab the dispatcher and device mutex as we don't want to race with concurrent fault 1027: * recovery 1028: */ 1029: mutex_lock(&adreno_dev->hwsched.mutex); 1030: kgsl_mutex_lock(&device->mutex); 1031: 1032: spin_lock(&hwf->lock); 1033: drawctxt = hwf->defer_drawctxt; 1034: ts = hwf->defer_ts; 1035: spin_unlock(&hwf->lock); 1036: 1037: if (!drawctxt) 1038: goto unlock; 1039: 1040: ret = process_hw_fence_deferred_ctxt(adreno_dev, drawctxt, ts); 1041: if (ret) { 1042: /* the deferred drawctxt will be handled post fault recovery */ 1043: gen7_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 1044: goto unlock; 1045: } 1046: 1047: /* 1048: * Put back the context reference which was incremented when hw_fence.defer_drawctxt was set 1049: */ 1050: kgsl_context_put(&drawctxt->base); 1051: 1052: adreno_active_count_put(adreno_dev); 1053: 1054: _disable_hw_fence_throttle(adreno_dev, false); 1055: 1056: unlock: 1057: kgsl_mutex_unlock(&device->mutex); 1058: mutex_unlock(&adreno_dev->hwsched.mutex); 1059: } 1060: 1061: static int _check_hw_fence_ack_failure(struct kgsl_device *device, u32 *result) 1062: { 1063: if (!result[2]) 1064: return 0; 1065: 1066: dev_err(GMU_PDEV_DEV(device), 1067: "HFI ACK failure: Req=0x%8.8X, Result=0x%8.8X\n", 1068: result[1], result[2]); 1069: 1070: return -EINVAL; 1071: } 1072: 1073: static void process_hw_fence_ack(struct adreno_device *adreno_dev, u32 *rcvd) 1074: { 1075: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 1076: struct adreno_context *drawctxt = NULL; 1077: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 1078: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1079: 1080: spin_lock(&hwf->lock); 1081: 1082: /* If this ack is being waited on, we don't need to touch the unack count */ 1083: if (hw_fence_ack.sent_hdr && CMP_HFI_ACK_HDR(hw_fence_ack.sent_hdr, rcvd[1])) { 1084: spin_unlock(&hwf->lock); 1085: complete(&hw_fence_ack.complete); 1086: return; 1087: } 1088: 1089: hwf->unack_count--; 1090: 1091: /* The unack count should never be greater than MAX_HW_FENCE_UNACK_COUNT */ 1092: if (hwf->unack_count > MAX_HW_FENCE_UNACK_COUNT) 1093: dev_err(GMU_PDEV_DEV(device), 1094: "unexpected hardware fence unack count:%d\n", 1095: hwf->unack_count); 1096: 1097: if (_check_hw_fence_ack_failure(device, rcvd)) { 1098: spin_unlock(&hwf->lock); 1099: gen7_hwsched_fault(adreno_dev, GMU_FAULT_HW_FENCE); 1100: return; 1101: } 1102: 1103: if (!test_bit(GEN7_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags) || 1104: (hwf->unack_count != MIN_HW_FENCE_UNACK_COUNT)) { 1105: spin_unlock(&hwf->lock); 1106: return; 1107: } 1108: 1109: drawctxt = hwf->defer_drawctxt; 1110: 1111: spin_unlock(&hwf->lock); 1112: 1113: kgsl_delete_timer_sync(&hfi->hw_fence_timer); 1114: 1115: /* 1116: * We need to handle the deferred context in another thread so that we can unblock the f2h 1117: * daemon here as it will need to process the acks for the hardware fences belonging to the 1118: * deferred context 1119: */ 1120: if (drawctxt) { 1121: kthread_init_work(&hfi->defer_hw_fence_work, gen7_defer_hw_fence_work); 1122: kthread_queue_work(adreno_dev->scheduler_worker, &hfi->defer_hw_fence_work); 1123: return; 1124: } 1125: 1126: _disable_hw_fence_throttle(adreno_dev, false); 1127: } 1128: 1129: void gen7_hwsched_process_msgq(struct adreno_device *adreno_dev) 1130: { 1131: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 1132: struct gen7_hwsched_hfi *hw_hfi = to_gen7_hwsched_hfi(adreno_dev); 1133: u32 rcvd[MAX_RCVD_SIZE], next_hdr, type; 1134: 1135: if (!(hw_hfi->irq_mask & HFI_IRQ_MSGQ_MASK)) 1136: return; 1137: 1138: mutex_lock(&hw_hfi->msgq_mutex); 1139: 1140: for (;;) { 1141: next_hdr = peek_next_header(adreno_dev, gmu, HFI_MSG_ID); 1142: 1143: if (!next_hdr) 1144: break; 1145: 1146: if (MSG_HDR_GET_TYPE(next_hdr) == HFI_MSG_ACK) 1147: type = HFI_MSG_ACK; 1148: else 1149: type = MSG_HDR_GET_ID(next_hdr); 1150: 1151: if (type != F2H_MSG_CONTEXT_BAD) { 1152: if (gen7_hfi_queue_read(gmu, HFI_MSG_ID, rcvd, sizeof(rcvd)) < 0) 1153: break; 1154: } 1155: 1156: switch (type) { 1157: case HFI_MSG_ACK: 1158: /* 1159: * We are assuming that there is only one outstanding ack because hfi 1160: * sending thread waits for completion while holding the device mutex 1161: * (except when we send H2F_MSG_HW_FENCE_INFO packets) 1162: */ 1163: if (MSG_HDR_GET_ID(rcvd[1]) == H2F_MSG_HW_FENCE_INFO) 1164: process_hw_fence_ack(adreno_dev, rcvd); 1165: else 1166: gen7_receive_ack_async(adreno_dev, rcvd); 1167: break; 1168: case F2H_MSG_CONTEXT_BAD: 1169: if (gen7_hfi_queue_read(gmu, HFI_MSG_ID, 1170: (u32 *)adreno_dev->hwsched.ctxt_bad, 1171: HFI_MAX_MSG_SIZE) < 0) 1172: break; 1173: process_ctx_bad(adreno_dev); 1174: break; 1175: case F2H_MSG_TS_RETIRE: 1176: adreno_hwsched_log_profiling_info(adreno_dev, rcvd); 1177: adreno_scheduler_queue(adreno_dev); 1178: break; 1179: case F2H_MSG_SYNCOBJ_QUERY: 1180: gen7_trigger_syncobj_query(adreno_dev, rcvd); 1181: break; 1182: case F2H_MSG_GMU_CNTR_RELEASE: { 1183: struct hfi_gmu_cntr_release_cmd *cmd = 1184: (struct hfi_gmu_cntr_release_cmd *) rcvd; 1185: 1186: adreno_perfcounter_put(adreno_dev, 1187: cmd->group_id, cmd->countable, PERFCOUNTER_FLAG_KERNEL); 1188: MATCH LINES: 1786, 1793 1774: rc = adreno_hwsched_wait_ack_completion(adreno_dev, gmu_pdev_dev, &pending_ack, 1775: gen7_hwsched_process_msgq); 1776: 1777: done: 1778: del_waiter(hfi, &pending_ack); 1779: 1780: if (rc || (pending_ack.results[2] == UINT_MAX)) 1781: return 0; 1782: 1783: return pending_ack.results[2]; 1784: } 1785: 1786: static void _context_queue_hw_fence_enable(struct adreno_device *adreno_dev) 1787: { 1788: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1789: 1790: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) >= 3) { 1791: if (gen7_hfi_send_get_value(adreno_dev, HFI_VALUE_CONTEXT_QUEUE, 0) == 1) { 1792: set_bit(ADRENO_HWSCHED_CONTEXT_QUEUE, &adreno_dev->hwsched.flags); 1793: adreno_hwsched_register_hw_fence(adreno_dev); 1794: } 1795: } 1796: } 1797: 1798: int gen7_hwsched_hfi_set_value(struct adreno_device *adreno_dev, u32 type, u32 subtype, u32 data) 1799: { 1800: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1801: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 1802: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 1803: struct pending_cmd pending_ack; 1804: int rc; 1805: u32 seqnum; 1806: struct hfi_set_value_cmd cmd = { 1807: .type = type, 1808: .subtype = subtype, 1809: .data = data, 1810: }; 1811: 1812: rc = CMD_MSG_HDR(cmd, H2F_MSG_SET_VALUE); 1813: if (rc) 1814: return 0; 1815: 1816: seqnum = atomic_inc_return(&gmu->hfi.seqnum); 1817: cmd.hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd.hdr, seqnum, sizeof(cmd) >> 2); MATCH LINES: 1838, 1843, 1846, 1849, 1850 1826: &pending_ack, gen7_hwsched_process_msgq); 1827: 1828: if (rc) 1829: goto done; 1830: 1831: rc = check_ack_failure(adreno_dev, &pending_ack); 1832: done: 1833: del_waiter(hfi, &pending_ack); 1834: 1835: return rc; 1836: } 1837: 1838: static int gen7_hfi_send_hw_fence_feature_ctrl(struct adreno_device *adreno_dev) 1839: { 1840: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1841: int ret; 1842: 1843: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags)) 1844: return 0; 1845: 1846: ret = gen7_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_HW_FENCE, 1, 0); 1847: if (ret && (ret == -ENOENT)) { 1848: dev_err(GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)), 1849: "GMU doesn't support HW_FENCE feature\n"); 1850: adreno_hwsched_deregister_hw_fence(adreno_dev); 1851: return 0; 1852: } 1853: 1854: return ret; 1855: } 1856: 1857: static int gen7_hfi_send_dms_feature_ctrl(struct adreno_device *adreno_dev) 1858: { 1859: int ret; 1860: 1861: if (!test_bit(ADRENO_DEVICE_DMS, &adreno_dev->priv)) 1862: return 0; 1863: 1864: ret = gen7_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_DMS, 1, 0); 1865: if (ret == -ENOENT) { 1866: dev_err(GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)), 1867: "GMU doesn't support DMS feature\n"); 1868: clear_bit(ADRENO_DEVICE_DMS, &adreno_dev->priv); 1869: adreno_dev->dms_enabled = false; 1870: return 0; 1871: } 1872: 1873: return ret; 1874: } MATCH LINES: 2220, 2222 2208: gen7_hfi_send_set_value(adreno_dev, 2209: HFI_VALUE_LOG_GROUP, 0, gmu->log_group_mask); 2210: 2211: ret = gen7_hfi_send_core_fw_start(adreno_dev); 2212: if (ret) 2213: goto err; 2214: 2215: /* 2216: * HFI_VALUE_CONTEXT_QUEUE can only be queried after GMU has initialized some of the 2217: * required resources as part of handling gen7_hfi_send_core_fw_start() 2218: */ 2219: if (!test_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags)) 2220: _context_queue_hw_fence_enable(adreno_dev); 2221: 2222: ret = gen7_hfi_send_hw_fence_feature_ctrl(adreno_dev); 2223: if (ret) 2224: goto err; 2225: 2226: ret = enable_preemption(adreno_dev); 2227: if (ret) 2228: goto err; 2229: 2230: ret = gen7_hfi_send_lpac_feature_ctrl(adreno_dev); 2231: if (ret) 2232: goto err; 2233: 2234: if (ADRENO_FEATURE(adreno_dev, ADRENO_AQE)) { 2235: ret = gen7_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_AQE, 1, 0); 2236: if (ret) 2237: goto err; 2238: } 2239: 2240: ret = send_start_msg(adreno_dev); 2241: if (ret) 2242: goto err; 2243: 2244: /* 2245: * Send this additional start message on cold boot if warmboot is enabled. 2246: * This message will be recorded and on a warmboot this will trigger the MATCH LINES: 2413, 2415, 2422, 2432, 2433, 2434, 2445, 2451, 2457, 2459, 2461, 2481, 2487, 2489, 2509, 2510, 2540, 2541, 2543, 2544, 2547, 2548 2401: if (kthread_should_stop()) 2402: break; 2403: 2404: gen7_hwsched_process_msgq(adreno_dev); 2405: gmu_core_process_trace_data(KGSL_DEVICE(adreno_dev), 2406: GMU_PDEV_DEV(device), &device->gmu_core.trace); 2407: gen7_hwsched_process_dbgq(adreno_dev, true); 2408: } 2409: 2410: return 0; 2411: } 2412: 2413: static void gen7_hwsched_hw_fence_timeout(struct work_struct *work) 2414: { 2415: struct gen7_hwsched_hfi *hfi = container_of(work, struct gen7_hwsched_hfi, hw_fence_ws); 2416: struct gen7_hwsched_device *gen7_hw_dev = container_of(hfi, struct gen7_hwsched_device, 2417: hwsched_hfi); 2418: struct adreno_device *adreno_dev = &gen7_hw_dev->gen7_dev.adreno_dev; 2419: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2420: u32 unack_count, ts; 2421: struct adreno_context *drawctxt = NULL; 2422: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 2423: bool fault; 2424: 2425: /* Check msgq one last time before recording a fault */ 2426: gen7_hwsched_process_msgq(adreno_dev); 2427: 2428: spin_lock(&hwf->lock); 2429: 2430: unack_count = hwf->unack_count; 2431: 2432: fault = test_bit(GEN7_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags) && 2433: test_bit(GEN7_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags) && 2434: (unack_count > MIN_HW_FENCE_UNACK_COUNT); 2435: 2436: drawctxt = hwf->defer_drawctxt; 2437: ts = hwf->defer_ts; 2438: 2439: spin_unlock(&hwf->lock); 2440: 2441: if (!fault) 2442: return; 2443: 2444: dev_err(GMU_PDEV_DEV(device), 2445: "Hardware fence unack(%d) timeout\n", unack_count); 2446: 2447: if (drawctxt) { 2448: struct kgsl_process_private *proc_priv = drawctxt->base.proc_priv; 2449: 2450: dev_err(GMU_PDEV_DEV(device), 2451: "Hardware fence got deferred for ctx:%d ts:%d pid:%d proc:%s\n", 2452: drawctxt->base.id, ts, pid_nr(proc_priv->pid), proc_priv->comm); 2453: } 2454: gen7_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 2455: } 2456: 2457: static void gen7_hwsched_hw_fence_timer(struct timer_list *t) 2458: { 2459: struct gen7_hwsched_hfi *hfi = kgsl_timer_container_of(hfi, t, hw_fence_timer); 2460: 2461: kgsl_schedule_work(&hfi->hw_fence_ws); 2462: } 2463: 2464: int gen7_hwsched_hfi_probe(struct adreno_device *adreno_dev) 2465: { 2466: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2467: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 2468: struct gen7_hwsched_hfi *hw_hfi = to_gen7_hwsched_hfi(adreno_dev); 2469: 2470: gmu->hfi.irq = kgsl_request_irq(GMU_PDEV(device), "hfi", NULL, -EINVAL, 2471: gen7_hwsched_hfi_handler, adreno_dev); 2472: 2473: if (gmu->hfi.irq < 0) 2474: return gmu->hfi.irq; 2475: 2476: hw_hfi->irq_mask = HFI_IRQ_MASK; 2477: 2478: rwlock_init(&hw_hfi->msglock); 2479: 2480: INIT_LIST_HEAD(&hw_hfi->msglist); 2481: INIT_LIST_HEAD(&hw_hfi->detached_hw_fence_list); 2482: 2483: init_waitqueue_head(&hw_hfi->f2h_wq); 2484: 2485: mutex_init(&hw_hfi->msgq_mutex); 2486: 2487: INIT_WORK(&hw_hfi->hw_fence_ws, gen7_hwsched_hw_fence_timeout); 2488: 2489: timer_setup(&hw_hfi->hw_fence_timer, gen7_hwsched_hw_fence_timer, 0); 2490: 2491: return 0; 2492: } 2493: 2494: void gen7_hwsched_hfi_remove(struct adreno_device *adreno_dev) 2495: { 2496: struct gen7_hwsched_hfi *hw_hfi = to_gen7_hwsched_hfi(adreno_dev); 2497: 2498: if (hw_hfi->f2h_task) 2499: kthread_stop(hw_hfi->f2h_task); 2500: } 2501: 2502: static void init_gmu_context_queue(struct adreno_context *drawctxt) 2503: { 2504: struct kgsl_memdesc *md = &drawctxt->gmu_context_queue; 2505: struct gmu_context_queue_header *hdr = md->hostptr; 2506: 2507: hdr->start_addr = md->gmuaddr + sizeof(*hdr); 2508: hdr->queue_size = (md->size - sizeof(*hdr)) >> 2; 2509: hdr->hw_fence_buffer_va = drawctxt->gmu_hw_fence_queue.gmuaddr; 2510: hdr->hw_fence_buffer_size = drawctxt->gmu_hw_fence_queue.size; 2511: } 2512: 2513: static u32 get_dq_id(struct adreno_device *adreno_dev, struct kgsl_context *context) 2514: { 2515: struct dq_info *info; 2516: u32 next; 2517: u32 priority = adreno_get_level(context); 2518: 2519: if (adreno_dev->lpac_enabled) 2520: info = &gen7_hfi_dqs_lpac[priority]; 2521: else 2522: info = &gen7_hfi_dqs[priority]; 2523: 2524: next = info->base_dq_id + info->offset; 2525: 2526: info->offset = (info->offset + 1) % info->max_dq; 2527: 2528: return next; 2529: } 2530: 2531: static int allocate_context_queues(struct adreno_device *adreno_dev, 2532: struct adreno_context *drawctxt) 2533: { 2534: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2535: int ret = 0; 2536: 2537: if (!adreno_hwsched_context_queue_enabled(adreno_dev)) 2538: return 0; 2539: 2540: if (test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags) && 2541: !drawctxt->gmu_hw_fence_queue.gmuaddr) { 2542: ret = gmu_core_alloc_kernel_block( 2543: device, &drawctxt->gmu_hw_fence_queue, 2544: HW_FENCE_QUEUE_SIZE, GMU_NONCACHED_KERNEL, 2545: IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV); 2546: if (ret) { 2547: memset(&drawctxt->gmu_hw_fence_queue, 0x0, 2548: sizeof(drawctxt->gmu_hw_fence_queue)); 2549: return ret; 2550: } 2551: } 2552: 2553: if (!drawctxt->gmu_context_queue.gmuaddr) { 2554: ret = gmu_core_alloc_kernel_block( 2555: device, &drawctxt->gmu_context_queue, 2556: SZ_4K, GMU_NONCACHED_KERNEL, 2557: IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV); 2558: if (ret) { 2559: memset(&drawctxt->gmu_context_queue, 0x0, 2560: sizeof(drawctxt->gmu_context_queue)); 2561: return ret; 2562: } 2563: init_gmu_context_queue(drawctxt); 2564: } 2565: 2566: return 0; 2567: } 2568: 2569: static int send_context_register(struct adreno_device *adreno_dev, 2570: struct kgsl_context *context) 2571: { 2572: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); MATCH LINES: 2617, 2618 2605: struct kgsl_context *context) 2606: { 2607: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2608: struct hfi_context_pointers_cmd cmd = {0}; 2609: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 2610: int ret; 2611: 2612: ret = CMD_MSG_HDR(cmd, H2F_MSG_CONTEXT_POINTERS); 2613: if (ret) 2614: return ret; 2615: 2616: cmd.ctxt_id = context->id; 2617: cmd.sop_addr = MEMSTORE_ID_GPU_ADDR(device, context->id, soptimestamp); 2618: cmd.eop_addr = MEMSTORE_ID_GPU_ADDR(device, context->id, eoptimestamp); 2619: if (context->user_ctxt_record) 2620: cmd.user_ctxt_record_addr = 2621: context->user_ctxt_record->memdesc.gpuaddr; 2622: 2623: if (adreno_hwsched_context_queue_enabled(adreno_dev)) 2624: cmd.gmu_context_queue_addr = drawctxt->gmu_context_queue.gmuaddr; 2625: 2626: return gen7_hfi_send_cmd_async(adreno_dev, &cmd, sizeof(cmd)); 2627: } 2628: 2629: static int hfi_context_register(struct adreno_device *adreno_dev, 2630: struct kgsl_context *context) 2631: { 2632: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2633: int ret; 2634: 2635: if (context->gmu_registered) 2636: return 0; 2637: 2638: ret = send_context_register(adreno_dev, context); 2639: if (ret) { 2640: dev_err(GMU_PDEV_DEV(device), 2641: "Unable to register context %u: %d\n", 2642: context->id, ret); MATCH LINES: 2723, 2725, 2726, 2728, 2733, 2735, 2741, 2744, 2745, 2748, 2752, 2755, 2759, 2760, 2763, 2778, 2785, 2788, 2789, 2791, 2792, 2794, 2797, 2799, 2804, 2805, 2808, 2809, 2811, 2812, 2813, 2819, 2823, 2824, 2834, 2837, 2841, 2844, 2846, 2847, 2852, 2860, 2861, 2864, 2867, 2871, 2874, 2876, 2880, 2885, 2886, 2888, 2892, 2895, 2898, 2899, 2901, 2902, 2906, 2910, 2911, 2919, 2920, 2921, 2922, 2925, 2929, 2931, 2934, 2937, 2940, 2944, 2945, 2949, 2953, 2956, 2957, 2963, 2964, 2966, 2969, 2973, 2978, 2979, 2981, 2987, 2989, 2991, 2992, 2995, 2999, 3005, 3011, 3015, 3025, 3030, 3032, 3035, 3040, 3043, 3044, 3046, 3047, 3050, 3052, 3053, 3056, 3062, 3068, 3071, 3072, 3077, 3079, 3080, 3088, 3089, 3091, 3092, 3094, 3095, 3096, 3101, 3102, 3103, 3110, 3112, 3116, 3123, 3127, 3131, 3133, 3136, 3143, 3150, 3153, 3158, 3160, 3166, 3167, 3170, 3173, 3176, 3180, 3185, 3188, 3190, 3192, 3195, 3198, 3199, 3204, 3205, 3208, 3213, 3214, 3216, 3217, 3221, 3224, 3228, 3229, 3233, 3238, 3239, 3242, 3245, 3246, 3247, 3249, 3253, 3258, 3263, 3264, 3265, 3267, 3270, 3278, 3285, 3286, 3289, 3292, 3293, 3296, 3297, 3299, 3304, 3305, 3310, 3318, 3321 2711: if (!adreno_hwsched_context_queue_enabled(adreno_dev)) 2712: return drawobj->context->gmu_dispatch_queue; 2713: 2714: if (adreno_is_preemption_enabled(adreno_dev)) 2715: return adreno_get_level(drawobj->context); 2716: 2717: if (kgsl_context_is_lpac(drawobj->context)) 2718: return 1; 2719: 2720: return 0; 2721: } 2722: 2723: static bool _is_kgsl_hw_fence_signaled(struct kgsl_drawobj_sync_hw_fence *hw_fence) 2724: { 2725: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)hw_fence->fence; 2726: struct kgsl_sync_timeline *ktimeline = kfence->parent; 2727: 2728: if (dma_fence_is_signaled_locked(&kfence->fence)) 2729: return true; 2730: 2731: /* 2732: * If we fail to get the context refcount that means this context is detached. 2733: * In that case, treat all hardware fences from detached context as signaled. 2734: */ 2735: if ((!hw_fence->context) && (!_kgsl_context_get(ktimeline->context))) 2736: return true; 2737: 2738: return false; 2739: } 2740: 2741: static void populate_kgsl_fence(struct kgsl_drawobj_sync_hw_fence *hw_fence, 2742: struct hfi_syncobj_legacy *obj) 2743: { 2744: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)hw_fence->fence; 2745: struct kgsl_sync_timeline *ktimeline = kfence->parent; 2746: unsigned long flags; 2747: 2748: obj->flags |= BIT(GMU_SYNCOBJ_FLAG_KGSL_FENCE_BIT); 2749: 2750: spin_lock_irqsave(&ktimeline->lock, flags); 2751: 2752: if (_is_kgsl_hw_fence_signaled(hw_fence)) 2753: obj->flags |= BIT(GMU_SYNCOBJ_FLAG_SIGNALED_BIT); 2754: else 2755: hw_fence->context = ktimeline->context; 2756: 2757: spin_unlock_irqrestore(&ktimeline->lock, flags); 2758: 2759: obj->ctxt_id = kfence->context_id; 2760: obj->seq_no = kfence->timestamp; 2761: } 2762: 2763: static int _submit_hw_fence(struct adreno_device *adreno_dev, 2764: struct kgsl_drawobj *drawobj, void *cmdbuf) 2765: { 2766: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 2767: int i; 2768: u32 cmd_sizebytes; 2769: struct kgsl_drawobj_sync *syncobj = SYNCOBJ(drawobj); 2770: struct hfi_submit_syncobj *cmd; 2771: struct hfi_syncobj_legacy *obj = NULL; 2772: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2773: u32 seqnum; 2774: 2775: /* Add hfi_syncobj struct for sync object */ 2776: cmd_sizebytes = sizeof(*cmd) + 2777: (sizeof(struct hfi_syncobj) * 2778: syncobj->num_hw_fence); 2779: 2780: if (WARN_ON(cmd_sizebytes > HFI_MAX_MSG_SIZE)) 2781: return -EMSGSIZE; 2782: 2783: memset(cmdbuf, 0x0, cmd_sizebytes); 2784: cmd = cmdbuf; 2785: cmd->num_syncobj = syncobj->num_hw_fence; 2786: obj = (struct hfi_syncobj_legacy *)&cmd[1]; 2787: 2788: for (i = 0; i < syncobj->num_hw_fence; i++) { 2789: struct dma_fence *fence = syncobj->hw_fences[i].fence; 2790: 2791: if (is_kgsl_fence(fence)) { 2792: populate_kgsl_fence(&syncobj->hw_fences[i], obj); 2793: } else { 2794: int ret = kgsl_hw_fence_add_waiter(device, fence, NULL); 2795: 2796: if (ret) { 2797: adreno_hwsched_syncobj_kfence_put(syncobj); 2798: clear_bit(KGSL_SYNCOBJ_HW, &syncobj->flags); 2799: drawobj->timestamp = 0; 2800: clear_bit(KGSL_SYNCOBJ_HW_TS, &syncobj->flags); 2801: return ret; 2802: } 2803: 2804: if (kgsl_hw_fence_signaled(fence) || 2805: test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) 2806: obj->flags |= BIT(GMU_SYNCOBJ_FLAG_SIGNALED_BIT); 2807: 2808: obj->ctxt_id = fence->context; 2809: obj->seq_no = fence->seqno; 2810: } 2811: trace_adreno_input_hw_fence(drawobj->context->id, obj->ctxt_id, 2812: obj->seq_no, obj->flags, fence->ops->get_timeline_name ? 2813: fence->ops->get_timeline_name(fence) : "unknown"); 2814: 2815: obj++; 2816: } 2817: 2818: /* 2819: * Attach a timestamp to this SYNCOBJ to keep track whether GMU has deemed it signaled 2820: * or not. 2821: */ 2822: if (!test_and_set_bit(KGSL_SYNCOBJ_HW_TS, &syncobj->flags)) 2823: drawobj->timestamp = ++drawctxt->syncobj_timestamp; 2824: cmd->timestamp = drawobj->timestamp; 2825: 2826: seqnum = atomic_inc_return(&adreno_dev->hwsched.submission_seqnum); 2827: cmd->hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_SYNCOBJ, HFI_MSG_CMD); 2828: cmd->hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd->hdr, seqnum, cmd_sizebytes >> 2); 2829: 2830: return adreno_gmu_context_queue_write(adreno_dev, &drawctxt->gmu_context_queue, 2831: (u32 *)cmd, cmd_sizebytes, drawobj, NULL); 2832: } 2833: 2834: int gen7_hwsched_check_context_inflight_hw_fences(struct adreno_device *adreno_dev, 2835: struct adreno_context *drawctxt) 2836: { 2837: struct adreno_hw_fence_entry *entry, *tmp; 2838: int ret = 0; 2839: 2840: spin_lock(&drawctxt->lock); 2841: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 2842: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 2843: 2844: if (timestamp_cmp((u32)entry->cmd.ts, hdr->out_fence_ts) > 0) { 2845: dev_err(GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)), 2846: "ctx:%d has unsignaled fence ts:%d retired:%d\n", 2847: drawctxt->base.id, (u32)entry->cmd.ts, hdr->out_fence_ts); 2848: ret = -EINVAL; 2849: break; 2850: } 2851: 2852: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 2853: } 2854: spin_unlock(&drawctxt->lock); 2855: 2856: return ret; 2857: } 2858: 2859: /** 2860: * move_detached_context_hardware_fences - Move all pending hardware fences belonging to this 2861: * context to the detached hardware fence list so as to send them to TxQueue after fault recovery. 2862: * This is needed because this context may get destroyed before fault recovery gets executed. 2863: */ 2864: static void move_detached_context_hardware_fences(struct adreno_device *adreno_dev, 2865: struct adreno_context *drawctxt) 2866: { 2867: struct adreno_hw_fence_entry *entry, *tmp; 2868: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 2869: 2870: spin_lock(&drawctxt->lock); 2871: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 2872: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 2873: 2874: if ((timestamp_cmp((u32)entry->cmd.ts, hdr->out_fence_ts) > 0)) { 2875: _kgsl_context_get(&drawctxt->base); 2876: list_move_tail(&entry->node, &hfi->detached_hw_fence_list); 2877: continue; 2878: } 2879: 2880: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 2881: } 2882: 2883: spin_unlock(&drawctxt->lock); 2884: 2885: /* Also grab all the hardware fences which were never sent to GMU */ 2886: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_list, node) { 2887: _kgsl_context_get(&drawctxt->base); 2888: list_move_tail(&entry->node, &hfi->detached_hw_fence_list); 2889: } 2890: } 2891: 2892: static int drain_context_hw_fence_gmu(struct adreno_device *adreno_dev, 2893: struct adreno_context *drawctxt) 2894: { 2895: struct adreno_hw_fence_entry *entry, *tmp; 2896: int ret = 0; 2897: 2898: /* Send hardware fences (to TxQueue) that were not dispatched to GMU */ 2899: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_list, node) { 2900: 2901: ret = gen7_send_hw_fence_hfi_wait_ack(adreno_dev, entry, 2902: HW_FENCE_FLAG_SKIP_MEMSTORE); 2903: if (ret) 2904: break; 2905: 2906: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 2907: } 2908: 2909: if (ret) { 2910: move_detached_context_hardware_fences(adreno_dev, drawctxt); 2911: gmu_core_fault_snapshot(KGSL_DEVICE(adreno_dev), GMU_FAULT_HW_FENCE); 2912: gen7_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 2913: } 2914: 2915: return ret; 2916: } 2917: 2918: /** 2919: * check_detached_context_hardware_fences - When this context has been un-registered with the GMU, 2920: * make sure all the hardware fences(that were sent to GMU) for this context have been sent to 2921: * TxQueue. Also, send any hardware fences (to GMU) that were not yet dispatched to the GMU. In case 2922: * of an error, move the pending hardware fences to detached hardware fence list, log the error, 2923: * take a snapshot and trigger recovery. 2924: */ 2925: static int check_detached_context_hardware_fences(struct adreno_device *adreno_dev, 2926: struct adreno_context *drawctxt) 2927: { 2928: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2929: struct adreno_hw_fence_entry *entry, *tmp; 2930: int ret = 0; 2931: u32 id, ts, fence_ts; 2932: 2933: spin_lock(&drawctxt->lock); 2934: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 2935: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 2936: 2937: if ((timestamp_cmp((u32)entry->cmd.ts, hdr->out_fence_ts) > 0)) { 2938: id = drawctxt->base.id; 2939: ts = (u32)entry->cmd.ts; 2940: fence_ts = hdr->out_fence_ts; 2941: 2942: spin_unlock(&drawctxt->lock); 2943: dev_err(GMU_PDEV_DEV(device), 2944: "detached ctx:%d has unsignaled fence ts:%d retired:%d\n", 2945: id, ts, fence_ts); 2946: ret = -EINVAL; 2947: goto fault; 2948: } 2949: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 2950: } 2951: 2952: spin_unlock(&drawctxt->lock); 2953: return drain_context_hw_fence_gmu(adreno_dev, drawctxt); 2954: 2955: fault: 2956: move_detached_context_hardware_fences(adreno_dev, drawctxt); 2957: gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE); 2958: gen7_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 2959: 2960: return ret; 2961: } 2962: 2963: static inline int setup_hw_fence_info_cmd(struct adreno_device *adreno_dev, 2964: struct adreno_hw_fence_entry *entry) 2965: { 2966: struct kgsl_sync_fence *kfence = entry->kfence; 2967: int ret; 2968: 2969: ret = CMD_MSG_HDR(entry->cmd, H2F_MSG_HW_FENCE_INFO); 2970: if (ret) 2971: return ret; 2972: 2973: ret = kgsl_hw_fence_create(KGSL_DEVICE(adreno_dev), kfence); 2974: if (ret) 2975: return ret; 2976: 2977: entry->cmd.gmu_ctxt_id = entry->drawctxt->base.id; 2978: entry->cmd.ctxt_id = kfence->fence.context; 2979: entry->cmd.ts = kfence->fence.seqno; 2980: 2981: entry->cmd.hash_index = kfence->hw_fence_index; 2982: 2983: return 0; 2984: } 2985: 2986: /* 2987: * gen7_send_hw_fence_hfi_wait_ack - This function is used in cases where multiple hardware fences 2988: * are to be sent to GMU. Hence, we must send them one by one to avoid overwhelming the GMU with 2989: * mutliple fences in a short span of time. 2990: */ 2991: int gen7_send_hw_fence_hfi_wait_ack(struct adreno_device *adreno_dev, 2992: struct adreno_hw_fence_entry *entry, u64 flags) 2993: { 2994: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2995: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 2996: u32 seqnum; 2997: int ret = 0; 2998: 2999: /* Device mutex is necessary to ensure only one hardware fence ack is being waited for */ 3000: if (WARN_ON(!kgsl_mutex_is_locked(&device->mutex))) 3001: return -EINVAL; 3002: 3003: spin_lock(&hwf->lock); 3004: 3005: init_completion(&hw_fence_ack.complete); 3006: 3007: entry->cmd.flags |= flags; 3008: seqnum = atomic_inc_return(&hwf->seqnum); 3009: entry->cmd.hdr = MSG_HDR_SET_SEQNUM_SIZE(entry->cmd.hdr, seqnum, sizeof(entry->cmd) >> 2); 3010: 3011: hw_fence_ack.sent_hdr = entry->cmd.hdr; 3012: 3013: /* 3014: * We don't need to increment the unack count here as we are waiting for the ack for 3015: * this fence before sending another hardware fence. 3016: */ 3017: ret = gen7_hfi_cmdq_write(adreno_dev, (u32 *)&entry->cmd, sizeof(entry->cmd)); 3018: 3019: spin_unlock(&hwf->lock); 3020: 3021: if (ret) 3022: goto done; 3023: 3024: ret = adreno_hwsched_wait_ack_completion(adreno_dev, 3025: GMU_PDEV_DEV(device), &hw_fence_ack, 3026: gen7_hwsched_process_msgq); 3027: if (ret) 3028: goto done; 3029: 3030: ret = _check_hw_fence_ack_failure(device, hw_fence_ack.results); 3031: if (ret) 3032: gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE); 3033: 3034: done: 3035: memset(&hw_fence_ack, 0x0, sizeof(hw_fence_ack)); 3036: return ret; 3037: } 3038: 3039: #define DRAWCTXT_SLOT_AVAILABLE(count) \ 3040: ((count + 1) < (HW_FENCE_QUEUE_SIZE / sizeof(struct hfi_hw_fence_info))) 3041: 3042: /** 3043: * allocate_hw_fence_entry - Allocate an entry to keep track of a hardware fence. This is free'd 3044: * when we know GMU has sent this fence to the TxQueue 3045: */ 3046: static struct adreno_hw_fence_entry *allocate_hw_fence_entry(struct adreno_device *adreno_dev, 3047: struct adreno_context *drawctxt, struct kgsl_sync_fence *kfence) 3048: { 3049: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3050: struct adreno_hw_fence_entry *entry; 3051: 3052: if (!kgsl_hw_fence_tx_slot_available(KGSL_DEVICE(adreno_dev), 3053: hwsched->hw_fence.pending_count)) 3054: return NULL; 3055: 3056: if (!DRAWCTXT_SLOT_AVAILABLE(drawctxt->hw_fence_count)) 3057: return NULL; 3058: 3059: if (!_kgsl_context_get(&drawctxt->base)) 3060: return NULL; 3061: 3062: entry = kmem_cache_zalloc(hwsched->hw_fence_cache, GFP_ATOMIC); 3063: if (!entry) { 3064: kgsl_context_put_deferred(&drawctxt->base); 3065: return NULL; 3066: } 3067: 3068: entry->kfence = kfence; 3069: entry->drawctxt = drawctxt; 3070: 3071: if (setup_hw_fence_info_cmd(adreno_dev, entry)) { 3072: kmem_cache_free(hwsched->hw_fence_cache, entry); 3073: kgsl_context_put_deferred(&drawctxt->base); 3074: return NULL; 3075: } 3076: 3077: dma_fence_get(&kfence->fence); 3078: 3079: drawctxt->hw_fence_count++; 3080: hwsched->hw_fence.pending_count++; 3081: 3082: INIT_LIST_HEAD(&entry->node); 3083: INIT_LIST_HEAD(&entry->reset_node); 3084: return entry; 3085: } 3086: 3087: /** 3088: * drawctxt_queue_hw_fence - Add a hardware fence to draw context's hardware fence list and make 3089: * sure the list remains sorted (with the fence with the largest timestamp at the end) 3090: */ 3091: static void drawctxt_queue_hw_fence(struct adreno_device *adreno_dev, 3092: struct adreno_context *drawctxt, struct kgsl_sync_fence *kfence) 3093: { 3094: struct adreno_hw_fence_entry *new = allocate_hw_fence_entry(adreno_dev, drawctxt, kfence); 3095: struct adreno_hw_fence_entry *entry = NULL; 3096: u32 ts = kfence->timestamp; 3097: 3098: if (!new) 3099: return; 3100: 3101: /* Walk the list backwards to find the right spot for this fence */ 3102: list_for_each_entry_reverse(entry, &drawctxt->hw_fence_list, node) { 3103: if (timestamp_cmp(ts, (u32)entry->cmd.ts) > 0) 3104: break; 3105: } 3106: 3107: list_add(&new->node, &entry->node); 3108: } 3109: 3110: static bool _hw_fence_end_sleep(struct adreno_device *adreno_dev) 3111: { 3112: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3113: bool ret; 3114: 3115: spin_lock(&hwf->lock); 3116: ret = !test_bit(GEN7_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags); 3117: spin_unlock(&hwf->lock); 3118: 3119: return ret; 3120: } 3121: 3122: /** 3123: * _hw_fence_sleep() - Check if the thread needs to sleep until the hardware fence unack count 3124: * drops to a desired threshold. 3125: * 3126: * Return: negative error code if the thread was woken up by a signal, or the context became bad in 3127: * the meanwhile, or the hardware fence unack count hasn't yet dropped to a desired threshold, or 3128: * if fault recovery is imminent. 3129: * Otherwise, return 0. 3130: */ 3131: static int _hw_fence_sleep(struct adreno_device *adreno_dev, struct adreno_context *drawctxt) 3132: { 3133: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3134: int ret = 0; 3135: 3136: if (!test_bit(GEN7_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags)) 3137: return 0; 3138: 3139: spin_unlock(&hwf->lock); 3140: spin_unlock(&drawctxt->lock); 3141: 3142: ret = wait_event_interruptible(hwf->unack_wq, 3143: _hw_fence_end_sleep(adreno_dev)); 3144: 3145: spin_lock(&drawctxt->lock); 3146: spin_lock(&hwf->lock); 3147: 3148: /* 3149: * If the thread received a signal, or the context became bad in the meanwhile or the limit 3150: * is still not settled, then return error to avoid creating this hardware fence 3151: */ 3152: if ((ret == -ERESTARTSYS) || kgsl_context_is_bad(&drawctxt->base) || 3153: test_bit(GEN7_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags)) 3154: return -EINVAL; 3155: 3156: /* 3157: * If fault recovery is imminent then return error code to avoid creating new hardware 3158: * fences until recovery is complete 3159: */ 3160: if (test_bit(GEN7_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags)) 3161: return -EBUSY; 3162: 3163: return ret; 3164: } 3165: 3166: void gen7_hwsched_create_hw_fence(struct adreno_device *adreno_dev, 3167: struct kgsl_sync_fence *kfence) 3168: { 3169: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3170: struct kgsl_sync_timeline *ktimeline = kfence->parent; 3171: struct kgsl_context *context = ktimeline->context; 3172: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 3173: struct adreno_hw_fence_entry *entry = NULL; 3174: /* Only allow a single log in a second */ 3175: static DEFINE_RATELIMIT_STATE(_rs, HZ, 1); 3176: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3177: u32 retired = 0; 3178: int ret = 0; 3179: bool destroy = false; 3180: u32 hw_fence_last_ts; 3181: 3182: spin_lock(&drawctxt->lock); 3183: spin_lock(&hwf->lock); 3184: 3185: hw_fence_last_ts = drawctxt->hw_fence_last_ts; 3186: 3187: /* 3188: * Only create hw fences if the timestamp is greater than timestamp of the last hw fence 3189: * that was created. Otherwise, we will hit a GMU assert as GMU doesn't expect duplicate 3190: * or out-of-order fences 3191: */ 3192: if (timestamp_cmp(hw_fence_last_ts, kfence->timestamp) >= 0) 3193: goto done; 3194: 3195: drawctxt->hw_fence_last_ts = kfence->timestamp; 3196: 3197: /* 3198: * If we create a hardware fence and this context is going away, we may never dispatch 3199: * this fence to the GMU. Hence, avoid creating a hardware fence if context is going away. 3200: */ 3201: if (kgsl_context_is_bad(context)) 3202: goto done; 3203: 3204: /* If recovery is imminent, then do not create a hardware fence */ 3205: if (test_bit(GEN7_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags)) 3206: goto done; 3207: 3208: ret = _hw_fence_sleep(adreno_dev, drawctxt); 3209: if (ret) 3210: goto done; 3211: 3212: /* 3213: * If this ts hasn't been submitted yet, then store it in the drawctxt hardware fence 3214: * list and return. This fence will be sent to GMU when this ts is dispatched to GMU. 3215: */ 3216: if (timestamp_cmp(kfence->timestamp, drawctxt->gmu_hw_fence_ready_ts) > 0) { 3217: drawctxt_queue_hw_fence(adreno_dev, drawctxt, kfence); 3218: goto done; 3219: } 3220: 3221: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, &retired); 3222: 3223: /* 3224: * Check if timestamp is retired. If we are in SLUMBER at this point, the timestamp is 3225: * guaranteed to be retired. This way, we don't need the device mutex to check the device 3226: * state explicitly. 3227: */ 3228: if (timestamp_cmp(retired, kfence->timestamp) >= 0) { 3229: kgsl_sync_timeline_signal(ktimeline, kfence->timestamp); 3230: goto done; 3231: } 3232: 3233: entry = allocate_hw_fence_entry(adreno_dev, drawctxt, kfence); 3234: if (!entry) 3235: goto done; 3236: 3237: /* 3238: * If timestamp is not retired then GMU must already be powered up. This is because SLUMBER 3239: * thread has to wait for hardware fence spinlock to make sure the hardware fence unack 3240: * count is zero. 3241: */ 3242: ret = _send_hw_fence_no_ack(adreno_dev, entry); 3243: if (ret) { 3244: if (__ratelimit(&_rs)) 3245: dev_err(GMU_PDEV_DEV(device), "hw fence for ctx:%d ts:%d ret:%d may not be destroyed\n", 3246: kfence->context_id, kfence->timestamp, ret); 3247: kgsl_hw_fence_destroy(kfence); 3248: destroy = true; 3249: drawctxt->hw_fence_last_ts = hw_fence_last_ts; 3250: goto done; 3251: } 3252: 3253: list_add_tail(&entry->node, &drawctxt->hw_fence_inflight_list); 3254: 3255: done: 3256: spin_unlock(&hwf->lock); 3257: if (destroy) 3258: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 3259: spin_unlock(&drawctxt->lock); 3260: } 3261: 3262: /** 3263: * setup_hw_fence_deferred_ctxt - The hardware fence(s) from this context couldn't be sent to the 3264: * GMU because the hardware fence unack count reached a threshold. Hence, setup this context such 3265: * that these hardware fences are sent to the GMU when the unack count drops to a desired threshold. 3266: */ 3267: static void setup_hw_fence_deferred_ctxt(struct adreno_device *adreno_dev, 3268: struct adreno_context *drawctxt, u32 ts) 3269: { 3270: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3271: 3272: if (!_kgsl_context_get(&drawctxt->base)) 3273: return; 3274: 3275: hwf->defer_drawctxt = drawctxt; 3276: hwf->defer_ts = ts; 3277: /* 3278: * Increment the active count so that device doesn't get powered off until this fence has 3279: * been sent to GMU 3280: */ 3281: adreno_active_count_get(adreno_dev); 3282: } 3283: 3284: /** 3285: * process_hw_fence_queue - This function walks the draw context's list of hardware fences 3286: * and sends the ones which have a timestamp less than or equal to the timestamp that just 3287: * got submitted to the GMU. 3288: */ 3289: static void process_hw_fence_queue(struct adreno_device *adreno_dev, 3290: struct adreno_context *drawctxt, u32 ts) 3291: { 3292: struct adreno_hw_fence_entry *entry = NULL, *next; 3293: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3294: int ret = 0; 3295: 3296: /* This list is sorted with smallest timestamp at head and highest timestamp at tail */ 3297: list_for_each_entry_safe(entry, next, &drawctxt->hw_fence_list, node) { 3298: 3299: if (timestamp_cmp((u32)entry->cmd.ts, ts) > 0) 3300: return; 3301: 3302: spin_lock(&hwf->lock); 3303: 3304: if (test_bit(GEN7_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags)) { 3305: setup_hw_fence_deferred_ctxt(adreno_dev, drawctxt, ts); 3306: spin_unlock(&hwf->lock); 3307: return; 3308: } 3309: 3310: ret = _send_hw_fence_no_ack(adreno_dev, entry); 3311: 3312: spin_unlock(&hwf->lock); 3313: 3314: if (ret) 3315: return; 3316: 3317: /* 3318: * A fence that is sent to GMU must be added to the drawctxt->hw_fence_inflight_list 3319: * so that we can keep track of when GMU sends it to the TxQueue 3320: */ 3321: list_move_tail(&entry->node, &drawctxt->hw_fence_inflight_list); 3322: } 3323: } 3324: 3325: /* Size in below functions are in unit of dwords */ 3326: static int gen7_hfi_dispatch_queue_write(struct adreno_device *adreno_dev, u32 queue_idx, 3327: u32 *msg, u32 size_bytes, struct kgsl_drawobj_cmd *cmdobj, struct adreno_submit_time *time) 3328: { 3329: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 3330: struct hfi_queue_table *tbl = gmu->hfi.hfi_mem->hostptr; 3331: struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx]; 3332: u32 *queue; 3333: u32 i, write, empty_space; 3334: u32 size_dwords = size_bytes >> 2; 3335: u32 align_size = ALIGN(size_dwords, SZ_4); 3336: u32 id = MSG_HDR_GET_ID(*msg); 3337: 3338: if (hdr->status == HFI_QUEUE_STATUS_DISABLED || !IS_ALIGNED(size_bytes, sizeof(u32))) 3339: return -EINVAL; 3340: 3341: queue = HOST_QUEUE_START_ADDR(gmu->hfi.hfi_mem, queue_idx); 3342: 3343: empty_space = (hdr->write_index >= hdr->read_index) ? 3344: (hdr->queue_size - (hdr->write_index - hdr->read_index)) 3345: : (hdr->read_index - hdr->write_index); MATCH LINES: 3412, 3418, 3422, 3447 3400: 3401: cmdbuf = devm_kzalloc(&device->pdev->dev, HFI_MAX_MSG_SIZE, 3402: GFP_KERNEL); 3403: if (!cmdbuf) 3404: return -ENOMEM; 3405: } 3406: 3407: ret = hfi_context_register(adreno_dev, drawobj->context); 3408: if (ret) 3409: return ret; 3410: 3411: if ((drawobj->type & SYNCOBJ_TYPE) != 0) 3412: return _submit_hw_fence(adreno_dev, drawobj, cmdbuf); 3413: 3414: cmdobj = CMDOBJ(drawobj); 3415: 3416: /* 3417: * If the MARKER object is retired, it doesn't need to be dispatched to GMU. Simply trigger 3418: * any pending fences that are less than/equal to this object's timestamp. 3419: */ 3420: if (test_bit(CMDOBJ_MARKER_EXPIRED, &cmdobj->priv)) { 3421: spin_lock(&drawctxt->lock); 3422: process_hw_fence_queue(adreno_dev, drawctxt, drawobj->timestamp); 3423: spin_unlock(&drawctxt->lock); 3424: return 0; 3425: } 3426: 3427: /* Add a *issue_ib struct for each IB */ 3428: if (cmdobj->numibs > HWSCHED_MAX_DISPATCH_NUMIBS || 3429: test_bit(CMDOBJ_SKIP, &cmdobj->priv)) 3430: cmd_sizebytes = sizeof(*cmd); 3431: else 3432: cmd_sizebytes = sizeof(*cmd) + 3433: (sizeof(struct hfi_issue_ib) * cmdobj->numibs); 3434: 3435: if (WARN_ON(cmd_sizebytes > HFI_MAX_MSG_SIZE)) 3436: return -EMSGSIZE; 3437: 3438: memset(cmdbuf, 0x0, cmd_sizebytes); 3439: 3440: cmd = cmdbuf; 3441: 3442: cmd->ctxt_id = drawobj->context->id; 3443: cmd->flags = HFI_CTXT_FLAG_NOTIFY; 3444: if (drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME) 3445: cmd->flags |= CMDBATCH_EOF; 3446: 3447: cmd->ts = drawobj->timestamp; 3448: 3449: if (test_bit(CMDOBJ_SKIP, &cmdobj->priv)) 3450: goto skipib; 3451: 3452: populate_ibs(adreno_dev, cmd, cmdobj); 3453: 3454: if ((drawobj->flags & KGSL_DRAWOBJ_PROFILING) && 3455: cmdobj->profiling_buf_entry) { 3456: 3457: time.drawobj = drawobj; 3458: 3459: cmd->profile_gpuaddr_lo = 3460: lower_32_bits(cmdobj->profiling_buffer_gpuaddr); 3461: cmd->profile_gpuaddr_hi = 3462: upper_32_bits(cmdobj->profiling_buffer_gpuaddr); 3463: 3464: /* Indicate to GMU to do user profiling for this submission */ 3465: cmd->flags |= CMDBATCH_PROFILING; 3466: } 3467: 3468: if (test_and_clear_bit(CMDOBJ_NOP_SUBMISSION, &cmdobj->priv)) 3469: cmd->flags |= CMDBATCH_NOP_SUBMISSION; 3470: 3471: skipib: MATCH LINES: 3490, 3498, 3501, 3503, 3504, 3507 3478: if (adreno_hwsched_context_queue_enabled(adreno_dev)) 3479: ret = adreno_gmu_context_queue_write(adreno_dev, 3480: &drawctxt->gmu_context_queue, (u32 *)cmd, cmd_sizebytes, drawobj, &time); 3481: else 3482: ret = gen7_hfi_dispatch_queue_write(adreno_dev, 3483: HFI_DSP_ID_0 + drawobj->context->gmu_dispatch_queue, 3484: (u32 *)cmd, cmd_sizebytes, cmdobj, &time); 3485: if (ret) 3486: return ret; 3487: 3488: hdr = drawctxt->gmu_context_queue.hostptr; 3489: /* The last sync object has been retired by the GMU */ 3490: if (timestamp_cmp(hdr->sync_obj_ts, drawctxt->syncobj_timestamp) >= 0) 3491: /* Send interrupt to GMU to receive the message */ 3492: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN7_GMU_HOST2GMU_INTR_SET, 3493: DISPQ_IRQ_BIT(get_irq_bit(adreno_dev, drawobj))); 3494: else 3495: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN7_GMU_HOST2GMU_INTR_SET, 3496: DISPQ_SYNC_IRQ_BIT(get_irq_bit(adreno_dev, drawobj))); 3497: 3498: drawctxt->internal_timestamp = drawobj->timestamp; 3499: 3500: spin_lock(&drawctxt->lock); 3501: process_hw_fence_queue(adreno_dev, drawctxt, drawobj->timestamp); 3502: /* 3503: * We need to update the gmu_hw_fence_ready_ts while holding the drawctxt lock since we 3504: * have to check it in the hardware fence creation path, where we are not taking the device 3505: * mutex. 3506: */ 3507: drawctxt->gmu_hw_fence_ready_ts = drawobj->timestamp; 3508: spin_unlock(&drawctxt->lock); 3509: 3510: return 0; 3511: } 3512: 3513: int gen7_hwsched_send_recurring_cmdobj(struct adreno_device *adreno_dev, 3514: struct kgsl_drawobj_cmd *cmdobj) 3515: { 3516: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3517: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 3518: struct hfi_submit_cmd *cmd; 3519: struct kgsl_memobj_node *ib; 3520: u32 cmd_sizebytes; 3521: int ret; 3522: static bool active; 3523: 3524: if (adreno_gpu_halt(adreno_dev) || adreno_gpu_fault(adreno_dev)) 3525: return -EBUSY; 3526: 3527: if (test_bit(CMDOBJ_RECURRING_STOP, &cmdobj->priv)) { 3528: cmdobj->numibs = 0; 3529: } else { 3530: list_for_each_entry(ib, &cmdobj->cmdlist, node) 3531: cmdobj->numibs++; MATCH LINES: 3603, 3606, 3610, 3613, 3616, 3618, 3619, 3621, 3626, 3627, 3630, 3632, 3634, 3636, 3640, 3645, 3647, 3651, 3653, 3661, 3662, 3681 3591: adreno_active_count_put(adreno_dev); 3592: active = false; 3593: return ret; 3594: } 3595: 3596: hwsched->recurring_cmdobj = cmdobj; 3597: /* Star LSR timer for power stats collection */ 3598: mod_timer(&hwsched->lsr_timer, jiffies + msecs_to_jiffies(10)); 3599: return ret; 3600: } 3601: 3602: /* 3603: * destroy_detached_context_inflight_hw_fences - Destroy context's hardware fences that were 3604: * dispatched to GMU 3605: */ 3606: static void destroy_detached_context_inflight_hw_fences(struct adreno_device *adreno_dev, 3607: struct adreno_context *drawctxt) 3608: { 3609: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3610: struct adreno_hw_fence_entry *entry, *tmp; 3611: 3612: spin_lock(&drawctxt->lock); 3613: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 3614: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 3615: 3616: if ((timestamp_cmp((u32)entry->cmd.ts, hdr->out_fence_ts) > 0)) { 3617: dev_err_ratelimited(GMU_PDEV_DEV(device), 3618: "destroying detached ctx:%d unsignaled hw fence ts:%d retired:%d\n", 3619: drawctxt->base.id, (u32)entry->cmd.ts, hdr->out_fence_ts); 3620: } 3621: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 3622: } 3623: spin_unlock(&drawctxt->lock); 3624: } 3625: 3626: /* We don't want to unnecessarily wake the GMU to trigger hardware fences */ 3627: static void drain_context_hw_fence_cpu(struct adreno_device *adreno_dev, 3628: struct adreno_context *drawctxt) 3629: { 3630: struct adreno_hw_fence_entry *entry, *tmp; 3631: 3632: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_list, node) { 3633: 3634: kgsl_hw_fence_trigger_cpu(KGSL_DEVICE(adreno_dev), entry->kfence); 3635: 3636: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 3637: } 3638: } 3639: 3640: static void drain_context_hw_fences(struct adreno_device *adreno_dev, 3641: struct adreno_context *drawctxt) 3642: { 3643: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 3644: 3645: destroy_detached_context_inflight_hw_fences(adreno_dev, drawctxt); 3646: 3647: if (list_empty(&drawctxt->hw_fence_list)) 3648: return; 3649: 3650: if (test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 3651: drain_context_hw_fence_gmu(adreno_dev, drawctxt); 3652: else 3653: drain_context_hw_fence_cpu(adreno_dev, drawctxt); 3654: } 3655: 3656: static void trigger_context_unregister_fault(struct adreno_device *adreno_dev, 3657: struct adreno_context *drawctxt) 3658: { 3659: gmu_core_fault_snapshot(KGSL_DEVICE(adreno_dev), GMU_FAULT_CTX_UNREGISTER); 3660: 3661: /* Make sure we send all fences from this context to the TxQueue after recovery */ 3662: move_detached_context_hardware_fences(adreno_dev, drawctxt); 3663: gen7_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 3664: } 3665: 3666: static int send_context_unregister_hfi(struct adreno_device *adreno_dev, 3667: struct kgsl_context *context, u32 ts) 3668: { 3669: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3670: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 3671: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 3672: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 3673: struct pending_cmd pending_ack; 3674: struct hfi_unregister_ctxt_cmd cmd; 3675: u32 seqnum; 3676: int ret; 3677: 3678: /* Only send HFI if device is not in SLUMBER */ 3679: if (!context->gmu_registered || 3680: !test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) { 3681: drain_context_hw_fences(adreno_dev, drawctxt); 3682: return 0; 3683: } 3684: 3685: ret = CMD_MSG_HDR(cmd, H2F_MSG_UNREGISTER_CONTEXT); 3686: if (ret) 3687: return ret; 3688: 3689: cmd.ctxt_id = context->id, 3690: cmd.ts = ts, 3691: 3692: /* 3693: * Although we know device is powered on, we can still enter SLUMBER 3694: * because the wait for ack below is done without holding the mutex. So 3695: * take an active count before releasing the mutex so as to avoid a 3696: * concurrent SLUMBER sequence while GMU is un-registering this context. 3697: */ 3698: ret = adreno_active_count_get(adreno_dev); 3699: if (ret) { 3700: trigger_context_unregister_fault(adreno_dev, drawctxt); 3701: return ret; 3702: } 3703: 3704: seqnum = atomic_inc_return(&gmu->hfi.seqnum); 3705: cmd.hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd.hdr, seqnum, sizeof(cmd) >> 2); MATCH LINES: 3721, 3742, 3748, 3751, 3757, 3758, 3759, 3786, 3787 3709: if (ret) { 3710: trigger_context_unregister_fault(adreno_dev, drawctxt); 3711: goto done; 3712: } 3713: 3714: ret = adreno_hwsched_ctxt_unregister_wait_completion(adreno_dev, 3715: GMU_PDEV_DEV(device), context, &pending_ack, gen7_hwsched_process_msgq, &cmd); 3716: if (ret) { 3717: trigger_context_unregister_fault(adreno_dev, drawctxt); 3718: goto done; 3719: } 3720: 3721: ret = check_detached_context_hardware_fences(adreno_dev, drawctxt); 3722: if (!ret) 3723: ret = check_ack_failure(adreno_dev, &pending_ack); 3724: 3725: done: 3726: adreno_active_count_put(adreno_dev); 3727: del_waiter(hfi, &pending_ack); 3728: 3729: return ret; 3730: } 3731: 3732: void gen7_hwsched_context_detach(struct adreno_context *drawctxt) 3733: { 3734: struct kgsl_context *context = &drawctxt->base; 3735: struct kgsl_device *device = context->device; 3736: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 3737: int ret = 0; 3738: 3739: kgsl_mutex_lock(&device->mutex); 3740: 3741: ret = send_context_unregister_hfi(adreno_dev, context, 3742: drawctxt->internal_timestamp); 3743: 3744: if (ret) 3745: goto out; 3746: 3747: kgsl_sharedmem_writel(device->memstore, 3748: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), drawctxt->timestamp); 3749: 3750: kgsl_sharedmem_writel(device->memstore, 3751: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), drawctxt->timestamp); 3752: 3753: adreno_profile_process_results(adreno_dev); 3754: context->gmu_registered = false; 3755: 3756: out: 3757: WARN_RATELIMIT(!list_empty(&drawctxt->hw_fence_list) || 3758: !list_empty(&drawctxt->hw_fence_inflight_list), 3759: "detached ctx:%u has active hw fences\n", 3760: context->id); 3761: 3762: kgsl_mutex_unlock(&device->mutex); 3763: } 3764: 3765: u32 gen7_hwsched_preempt_count_get(struct adreno_device *adreno_dev) 3766: { 3767: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3768: 3769: if (device->state != KGSL_STATE_ACTIVE) 3770: return 0; 3771: 3772: return gen7_hwsched_hfi_get_value(adreno_dev, HFI_VALUE_PREEMPT_COUNT); 3773: } 3774: 3775: void gen7_hwsched_context_destroy(struct adreno_device *adreno_dev, 3776: struct adreno_context *drawctxt) 3777: { 3778: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3779: 3780: if (!adreno_hwsched_context_queue_enabled(adreno_dev)) 3781: return; 3782: 3783: if (drawctxt->gmu_context_queue.gmuaddr) 3784: gmu_core_free_block(device, &drawctxt->gmu_context_queue); 3785: 3786: if (drawctxt->gmu_hw_fence_queue.gmuaddr) 3787: gmu_core_free_block(device, &drawctxt->gmu_hw_fence_queue); 3788: } 3789: 3790: static int register_global_ctxt(struct adreno_device *adreno_dev) 3791: { 3792: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3793: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3794: struct hfi_register_ctxt_cmd rcmd = {0}; 3795: struct hfi_context_pointers_cmd pcmd = {0}; 3796: int ret; 3797: 3798: if (hwsched->global_ctxt_gmu_registered) 3799: return 0; 3800: 3801: if (adreno_hwsched_context_queue_enabled(adreno_dev) && !hwsched->global_ctxtq.hostptr) { 3802: struct gmu_context_queue_header *hdr; 3803: 3804: ret = gmu_core_alloc_kernel_block(device, &hwsched->global_ctxtq, 3805: SZ_4K, GMU_NONCACHED_KERNEL, IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV); 3806: if (ret) { 3807: memset(&hwsched->global_ctxtq, 0x0, sizeof(hwsched->global_ctxtq)); 3808: return ret; 3809: } 3810: 3811: hdr = hwsched->global_ctxtq.hostptr; MATCH LINES: 3832, 3833 3820: rcmd.ctxt_id = KGSL_GLOBAL_CTXT_ID; 3821: rcmd.flags = (KGSL_CONTEXT_PRIORITY_HIGH << KGSL_CONTEXT_PRIORITY_SHIFT); 3822: 3823: ret = gen7_hfi_send_cmd_async(adreno_dev, &rcmd, sizeof(rcmd)); 3824: if (ret) 3825: return ret; 3826: 3827: ret = CMD_MSG_HDR(pcmd, H2F_MSG_CONTEXT_POINTERS); 3828: if (ret) 3829: return ret; 3830: 3831: pcmd.ctxt_id = KGSL_GLOBAL_CTXT_ID; 3832: pcmd.sop_addr = MEMSTORE_ID_GPU_ADDR(device, KGSL_GLOBAL_CTXT_ID, soptimestamp); 3833: pcmd.eop_addr = MEMSTORE_ID_GPU_ADDR(device, KGSL_GLOBAL_CTXT_ID, eoptimestamp); 3834: 3835: if (adreno_hwsched_context_queue_enabled(adreno_dev)) 3836: pcmd.gmu_context_queue_addr = hwsched->global_ctxtq.gmuaddr; 3837: 3838: ret = gen7_hfi_send_cmd_async(adreno_dev, &pcmd, sizeof(pcmd)); 3839: if (!ret) 3840: hwsched->global_ctxt_gmu_registered = true; 3841: 3842: return ret; 3843: } 3844: 3845: static int submit_global_ctxt_cmd(struct adreno_device *adreno_dev, u64 gpuaddr, u32 size) 3846: { 3847: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3848: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3849: struct { 3850: struct hfi_submit_cmd submit_cmd; 3851: struct hfi_issue_ib issue_ib; 3852: } cmd = {0}; 3853: u32 seqnum, cmd_size = sizeof(cmd); 3854: static u32 ts; 3855: int ret; 3856: 3857: cmd.submit_cmd.ctxt_id = KGSL_GLOBAL_CTXT_ID; MATCH LINES: 3930, 3932, 3937, 3950, 3953, 3961 3918: if (!ret) { 3919: reg->value = 0; 3920: return ret; 3921: } 3922: 3923: err: 3924: dev_err(device->dev, "Perfcounter %s/%u/%u start via commands failed\n", 3925: group->name, counter, countable); 3926: 3927: return ret; 3928: } 3929: 3930: int gen7_hwsched_disable_hw_fence_throttle(struct adreno_device *adreno_dev) 3931: { 3932: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3933: struct adreno_context *drawctxt = NULL; 3934: u32 ts = 0; 3935: int ret = 0; 3936: 3937: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags)) 3938: return 0; 3939: 3940: spin_lock(&hwf->lock); 3941: 3942: drawctxt = hwf->defer_drawctxt; 3943: ts = hwf->defer_ts; 3944: 3945: spin_unlock(&hwf->lock); 3946: 3947: if (!drawctxt) 3948: goto done; 3949: 3950: ret = process_hw_fence_deferred_ctxt(adreno_dev, drawctxt, ts); 3951: if (ret) { 3952: /* the deferred drawctxt will be handled post fault recovery */ 3953: gen7_hwsched_fault(adreno_dev, GMU_FAULT_HW_FENCE); 3954: return ret; 3955: } 3956: 3957: kgsl_context_put(&drawctxt->base); 3958: adreno_active_count_put(adreno_dev); 3959: 3960: done: 3961: _disable_hw_fence_throttle(adreno_dev, true); 3962: 3963: return ret; 3964: } --- FILE: \adreno_gen7_hwsched_hfi.h | HITS: 39 --- MATCH LINES: 16, 18, 22, 25, 26, 27, 28, 29, 30, 31, 34, 37, 39, 61, 64, 66, 68, 69, 70, 71, 72 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #ifndef _ADRENO_GEN7_HWSCHED_HFI_H_ 8: #define _ADRENO_GEN7_HWSCHED_HFI_H_ 9: 10: /* Maximum number of IBs in a submission */ 11: #define HWSCHED_MAX_NUMIBS \ 12: ((HFI_MAX_MSG_SIZE - offsetof(struct hfi_issue_cmd_cmd, ibs)) \ 13: / sizeof(struct hfi_issue_ib)) 14: 15: /* 16: * This is used to put userspace threads to sleep when hardware fence unack count reaches a 17: * threshold. This bit is cleared in two scenarios: 18: * 1. If the hardware fence unack count drops to a desired threshold. 19: * 2. If there is a GMU/GPU fault. Because we don't want the threads to keep sleeping through fault 20: * recovery, which can easily take 100s of milliseconds to complete. 21: */ 22: #define GEN7_HWSCHED_HW_FENCE_SLEEP_BIT 0x0 23: 24: /* 25: * This is used to avoid creating any more hardware fences until the hardware fence unack count 26: * drops to a desired threshold. This bit is required in cases where GEN7_HWSCHED_HW_FENCE_SLEEP_BIT 27: * will be cleared, but we still want to avoid creating any more hardware fences. For example, if 28: * hardware fence unack count reaches a maximum threshold, both GEN7_HWSCHED_HW_FENCE_SLEEP_BIT and 29: * GEN7_HWSCHED_HW_FENCE_MAX_BIT will be set. Say, a GMU/GPU fault happens and 30: * GEN7_HWSCHED_HW_FENCE_SLEEP_BIT will be cleared to wake up any sleeping threads. But, 31: * GEN7_HWSCHED_HW_FENCE_MAX_BIT will remain set to avoid creating any new hardware fences until 32: * recovery is complete and deferred drawctxt (if any) is handled. 33: */ 34: #define GEN7_HWSCHED_HW_FENCE_MAX_BIT 0x1 35: 36: /* 37: * This is used to avoid creating any more hardware fences until concurrent reset/recovery completes 38: */ 39: #define GEN7_HWSCHED_HW_FENCE_ABORT_BIT 0x2 40: 41: struct gen7_hwsched_hfi { 42: /** @irq_mask: Store the hfi interrupt mask */ 43: u32 irq_mask; 44: /** @msglock: To protect the list of un-ACKed hfi packets */ 45: rwlock_t msglock; 46: /** @msglist: List of un-ACKed hfi packets */ 47: struct list_head msglist; 48: /** @f2h_task: Task for processing gmu fw to host packets */ 49: struct task_struct *f2h_task; 50: /** @f2h_wq: Waitqueue for the f2h_task */ 51: wait_queue_head_t f2h_wq; 52: /** @big_ib: GMU buffer to hold big IBs */ 53: struct kgsl_memdesc *big_ib; 54: /** @big_ib_recurring: GMU buffer to hold big recurring IBs */ 55: struct kgsl_memdesc *big_ib_recurring; 56: /** @perfctr_scratch: Buffer to hold perfcounter PM4 commands */ 57: struct kgsl_memdesc *perfctr_scratch; 58: /** @msg_mutex: Mutex for accessing the msgq */ 59: struct mutex msgq_mutex; 60: /** 61: * @hw_fence_timer: Timer to trigger fault if unack'd hardware fence count does'nt drop 62: * to a desired threshold in given amount of time 63: */ 64: struct timer_list hw_fence_timer; 65: /** 66: * @hw_fence_ws: Work struct that gets scheduled when hw_fence_timer expires 67: */ 68: struct work_struct hw_fence_ws; 69: /** @detached_hw_fences_list: List of hardware fences belonging to detached contexts */ 70: struct list_head detached_hw_fence_list; 71: /** @defer_hw_fence_work: The work structure to send deferred hardware fences to GMU */ 72: struct kthread_work defer_hw_fence_work; 73: }; 74: 75: struct kgsl_drawobj_cmd; 76: 77: /** 78: * gen7_hwsched_hfi_probe - Probe hwsched hfi resources 79: * @adreno_dev: Pointer to adreno device structure 80: * 81: * Return: 0 on success and negative error on failure. 82: */ 83: int gen7_hwsched_hfi_probe(struct adreno_device *adreno_dev); 84: 85: /** 86: * gen7_hwsched_hfi_remove - Release hwsched hfi resources 87: * @adreno_dev: Pointer to adreno device structure 88: */ 89: void gen7_hwsched_hfi_remove(struct adreno_device *adreno_dev); 90: 91: /** 92: * gen7_hwsched_hfi_init - Initialize hfi resources 93: * @adreno_dev: Pointer to adreno device structure 94: * 95: * This function is used to initialize hfi resources 96: * once before the very first gmu boot MATCH LINES: 248, 250, 251, 253, 257, 258, 261, 263, 265, 267, 268, 271, 276, 281, 285, 288, 289, 293 236: /** 237: * gen7_hwsched_hfi_get_value - Send GET_VALUE packet to GMU to get the value of a property 238: * @adreno_dev: Pointer to adreno device 239: * @prop: property to get from GMU 240: * 241: * This functions sends GET_VALUE HFI packet to query value of a property 242: * 243: * Return: On success, return the value in the GMU response. On failure, return 0 244: */ 245: u32 gen7_hwsched_hfi_get_value(struct adreno_device *adreno_dev, u32 prop); 246: 247: /** 248: * gen7_send_hw_fence_hfi_wait_ack - Send hardware fence info to GMU 249: * @adreno_dev: Pointer to adreno device 250: * @entry: Pointer to the adreno hardware fence entry 251: * @flags: Flags for this hardware fence 252: * 253: * Send the hardware fence info to the GMU and wait for the ack 254: * 255: * Return: 0 on success or negative error on failure 256: */ 257: int gen7_send_hw_fence_hfi_wait_ack(struct adreno_device *adreno_dev, 258: struct adreno_hw_fence_entry *entry, u64 flags); 259: 260: /** 261: * gen7_hwsched_create_hw_fence - Create a hardware fence 262: * @adreno_dev: Pointer to adreno device 263: * @kfence: Pointer to the kgsl fence 264: * 265: * Create a hardware fence, set up hardware fence info and send it to GMU if required 266: */ 267: void gen7_hwsched_create_hw_fence(struct adreno_device *adreno_dev, 268: struct kgsl_sync_fence *kfence); 269: 270: /** 271: * gen7_hwsched_check_context_inflight_hw_fences - Check whether all hardware fences 272: * from a context have been sent to the TxQueue or not 273: * @adreno_dev: Pointer to adreno device 274: * @drawctxt: Pointer to the adreno context which is to be flushed 275: * 276: * Check if all hardware fences from this context have been sent to the 277: * TxQueue. If not, log an error and return error code. 278: * 279: * Return: Zero on success or negative error on failure 280: */ 281: int gen7_hwsched_check_context_inflight_hw_fences(struct adreno_device *adreno_dev, 282: struct adreno_context *drawctxt); 283: 284: /** 285: * gen7_hwsched_disable_hw_fence_throttle - Disable hardware fence throttling after reset 286: * @adreno_dev: pointer to the adreno device 287: * 288: * After device reset, clear hardware fence related data structures and send any hardware fences 289: * that got deferred (prior to reset) and re-open the gates for hardware fence creation 290: * 291: * Return: Zero on success or negative error on failure 292: */ 293: int gen7_hwsched_disable_hw_fence_throttle(struct adreno_device *adreno_dev); 294: 295: /** 296: * gen7_hwsched_process_msgq - Process msgq 297: * @adreno_dev: pointer to the adreno device 298: * 299: * This function grabs the msgq mutex and processes msgq for any outstanding hfi packets 300: */ 301: void gen7_hwsched_process_msgq(struct adreno_device *adreno_dev); 302: 303: /** 304: * gen7_hwsched_boot_gpu - Send the command to boot GPU 305: * @adreno_dev: Pointer to adreno device 306: * 307: * Send the hfi to boot GPU, and check the ack, incase of a failure 308: * get a snapshot and capture registers of interest. 309: * 310: * Return: Zero on success or negative error on failure 311: */ 312: int gen7_hwsched_boot_gpu(struct adreno_device *adreno_dev); 313: #endif --- FILE: \adreno_gen7_perfcounter.c | HITS: 1 --- MATCH LINES: 100 88: if (ret) 89: return ret; 90: 91: /* 92: * schedule dispatcher to make sure rb[0] is run, because 93: * if the current RB is not rb[0] and gpu is idle then 94: * rb[0] will not get scheduled to run 95: */ 96: if (adreno_dev->cur_rb != rb) 97: adreno_scheduler_queue(adreno_dev); 98: 99: /* wait for the above commands submitted to complete */ 100: ret = adreno_ringbuffer_waittimestamp(rb, rb->timestamp, 101: ADRENO_IDLE_TIMEOUT); 102: 103: if (ret) { 104: /* 105: * If we were woken up because of cancelling rb events 106: * either due to soft reset or adreno_stop, ignore the 107: * error and return 0 here. The perfcounter is already 108: * set up in software and it will be programmed in 109: * hardware when we wake up or come up after soft reset, 110: * by adreno_perfcounter_restore. 111: */ 112: if (ret == -EAGAIN) 113: ret = 0; 114: else 115: dev_err_ratelimited(KGSL_DEVICE(adreno_dev)->dev, 116: "Perfcounter %s/%u/%u start via commands failed %d\n", 117: group->name, counter, countable, ret); 118: } 119: 120: if (!ret) 121: reg->value = 0; 122: 123: return ret; 124: } --- FILE: \adreno_gen7_preempt.c | HITS: 21 --- MATCH LINES: 36, 38 24: unsigned long flags; 25: int ret = 0; 26: 27: spin_lock_irqsave(&rb->preempt_lock, flags); 28: 29: if (!atomic) { 30: /* 31: * We might have skipped updating the wptr in case we are in 32: * dispatcher context. Do it now. 33: */ 34: if (rb->skip_inline_wptr) { 35: 36: ret = gen7_fenced_write(adreno_dev, 37: GEN7_CP_RB_WPTR, rb->wptr, 38: FENCE_STATUS_WRITEDROPPED0_MASK); 39: 40: reset_timer = true; 41: rb->skip_inline_wptr = false; 42: } 43: } else { 44: unsigned int wptr; 45: 46: kgsl_regread(device, GEN7_CP_RB_WPTR, &wptr); 47: if (wptr != rb->wptr) { 48: kgsl_regwrite(device, GEN7_CP_RB_WPTR, rb->wptr); 49: reset_timer = true; 50: } 51: } 52: 53: if (reset_timer) 54: rb->dispatch_q.expires = jiffies + 55: msecs_to_jiffies(adreno_drawobj_timeout); 56: 57: spin_unlock_irqrestore(&rb->preempt_lock, flags); 58: 59: if (!atomic) { 60: /* If WPTR update fails, set the fault and trigger recovery */ 61: if (ret) { 62: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); MATCH LINES: 285, 286, 293, 296, 299, 303, 314, 317, 321, 324, 327, 330, 334, 337, 340, 343, 373, 374, 382 273: 274: kgsl_sharedmem_readq(preempt->scratch, &gpuaddr, 275: next->id * sizeof(u64)); 276: 277: /* 278: * Set a keepalive bit before the first preemption register write. 279: * This is required since while each individual write to the context 280: * switch registers will wake the GPU from collapse, it will not in 281: * itself cause GPU activity. Thus, the GPU could technically be 282: * re-collapsed between subsequent register writes leading to a 283: * prolonged preemption sequence. The keepalive bit prevents any 284: * further power collapse while it is set. 285: * It is more efficient to use a keepalive+wake-on-fence approach here 286: * rather than an OOB. Both keepalive and the fence are effectively 287: * free when the GPU is already powered on, whereas an OOB requires an 288: * unconditional handshake with the GMU. 289: */ 290: _power_collapse_set(adreno_dev, true); 291: 292: /* 293: * Fenced writes on this path will make sure the GPU is woken up 294: * in case it was power collapsed by the GMU. 295: */ 296: if (gen7_fenced_write(adreno_dev, 297: GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO, 298: lower_32_bits(next->preemption_desc->gpuaddr), 299: FENCE_STATUS_WRITEDROPPED1_MASK)) 300: goto err; 301: 302: /* 303: * Above fence writes will make sure GMU comes out of 304: * IFPC state if its was in IFPC state but it doesn't 305: * guarantee that GMU FW actually moved to ACTIVE state 306: * i.e. wake-up from IFPC is complete. 307: * Wait for GMU to move to ACTIVE state before triggering 308: * preemption. This is require to make sure CP doesn't 309: * interrupt GMU during wake-up from IFPC. 310: */ 311: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 312: goto err; 313: 314: if (gen7_fenced_write(adreno_dev, 315: GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI, 316: upper_32_bits(next->preemption_desc->gpuaddr), 317: FENCE_STATUS_WRITEDROPPED1_MASK)) 318: goto err; 319: 320: if (kgsl_mmu_is_secured(&device->mmu)) { 321: if (gen7_fenced_write(adreno_dev, 322: GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO, 323: lower_32_bits(next->secure_preemption_desc->gpuaddr), 324: FENCE_STATUS_WRITEDROPPED1_MASK)) 325: goto err; 326: 327: if (gen7_fenced_write(adreno_dev, 328: GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI, 329: upper_32_bits(next->secure_preemption_desc->gpuaddr), 330: FENCE_STATUS_WRITEDROPPED1_MASK)) 331: goto err; 332: } 333: 334: if (gen7_fenced_write(adreno_dev, 335: GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO, 336: lower_32_bits(gpuaddr), 337: FENCE_STATUS_WRITEDROPPED1_MASK)) 338: goto err; 339: 340: if (gen7_fenced_write(adreno_dev, 341: GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI, 342: upper_32_bits(gpuaddr), 343: FENCE_STATUS_WRITEDROPPED1_MASK)) 344: goto err; 345: 346: adreno_dev->next_rb = next; 347: 348: /* Start the timer to detect a stuck preemption */ 349: mod_timer(&adreno_dev->preempt.timer, 350: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 351: 352: cntl = (preempt->preempt_level << 6) | 0x01; 353: 354: /* Skip save/restore during L1 preemption */ 355: if (preempt->skipsaverestore) 356: cntl |= (1 << 9); 357: 358: /* Enable GMEM save/restore across preemption */ 359: if (preempt->usesgmem) 360: cntl |= (1 << 8); 361: 362: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 363: cntl, 0); 364: 365: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 366: 367: if (gen7_core->qos_value) 368: kgsl_sharedmem_writel(preempt->scratch, 369: PREEMPT_SCRATCH_OFFSET(QOS_VALUE_IDX), 370: gen7_core->qos_value[next->id]); 371: 372: /* Trigger the preemption */ 373: if (gen7_fenced_write(adreno_dev, GEN7_CP_CONTEXT_SWITCH_CNTL, cntl, 374: FENCE_STATUS_WRITEDROPPED1_MASK)) { 375: adreno_dev->next_rb = NULL; 376: kgsl_delete_timer(&adreno_dev->preempt.timer); 377: goto err; 378: } 379: 380: return; 381: err: 382: /* If fenced write fails, take inline snapshot and trigger recovery */ 383: if (!in_interrupt()) { 384: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 385: adreno_scheduler_fault(adreno_dev, 386: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 387: } else { 388: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 389: } 390: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 391: /* Clear the keep alive */ 392: _power_collapse_set(adreno_dev, false); 393: 394: } 395: 396: void gen7_preemption_callback(struct adreno_device *adreno_dev, int bit) 397: { 398: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 399: unsigned int status; 400: 401: if (!adreno_move_preempt_state(adreno_dev, 402: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 403: return; 404: 405: kgsl_regread(device, GEN7_CP_CONTEXT_SWITCH_CNTL, &status); 406: --- FILE: \adreno_gen7_ringbuffer.c | HITS: 38 --- MATCH LINES: 164, 165, 166, 167, 169, 170, 171, 172, 188, 190 152: u64 gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 153: 154: cmds[count++] = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 3); 155: cmds[count++] = SET_PSEUDO_NON_PRIV_SAVE_ADDR; 156: cmds[count++] = lower_32_bits(gpuaddr); 157: cmds[count++] = upper_32_bits(gpuaddr); 158: } 159: 160: return gen7_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED, 161: cmds, count, 0, NULL); 162: } 163: 164: #define RB_SOPTIMESTAMP(device, rb) \ 165: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 166: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 167: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 168: 169: #define RB_EOPTIMESTAMP(device, rb) \ 170: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 171: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 172: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 173: 174: int gen7_ringbuffer_submit(struct adreno_ringbuffer *rb, 175: struct adreno_submit_time *time) 176: { 177: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 178: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 179: int ret = 0; 180: unsigned long flags; 181: 182: adreno_get_submit_time(adreno_dev, rb, time); 183: adreno_profile_submit_time(time); 184: 185: spin_lock_irqsave(&rb->preempt_lock, flags); 186: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 187: if (adreno_dev->cur_rb == rb) { 188: ret = gen7_fenced_write(adreno_dev, 189: GEN7_CP_RB_WPTR, rb->_wptr, 190: FENCE_STATUS_WRITEDROPPED0_MASK); 191: rb->skip_inline_wptr = false; 192: } 193: } else { 194: if (adreno_dev->cur_rb == rb) 195: rb->skip_inline_wptr = true; 196: } 197: 198: rb->wptr = rb->_wptr; 199: spin_unlock_irqrestore(&rb->preempt_lock, flags); 200: 201: if (ret) { 202: /* 203: * If WPTR update fails, take inline snapshot and trigger 204: * recovery. 205: */ 206: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 207: adreno_scheduler_fault(adreno_dev, 208: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 209: } 210: 211: return ret; 212: } 213: 214: int gen7_ringbuffer_init(struct adreno_device *adreno_dev) MATCH LINES: 253, 268, 271, 309, 311, 313, 317, 318, 319, 352, 359, 366, 369, 373, 377, 383, 384, 385, 389, 391, 393, 397, 398, 399 241: return ret; 242: } 243: 244: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 245: gen7_preemption_init(adreno_dev); 246: return 0; 247: } 248: 249: #define GEN7_SUBMIT_MAX 104 250: 251: int gen7_ringbuffer_addcmds(struct adreno_device *adreno_dev, 252: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 253: u32 flags, u32 *in, u32 dwords, u32 timestamp, 254: struct adreno_submit_time *time) 255: { 256: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 257: u32 size = GEN7_SUBMIT_MAX + dwords; 258: u32 *cmds, index = 0; 259: u64 profile_gpuaddr; 260: u32 profile_dwords; 261: 262: if (adreno_drawctxt_detached(drawctxt)) 263: return -ENOENT; 264: 265: if (adreno_gpu_fault(adreno_dev) != 0) 266: return -EPROTO; 267: 268: rb->timestamp++; 269: 270: if (drawctxt) 271: drawctxt->internal_timestamp = rb->timestamp; 272: 273: /* All submissions are run with protected mode off due to APRIV */ 274: flags &= ~F_NOTPROTECTED; 275: 276: cmds = adreno_ringbuffer_allocspace(rb, size); 277: if (IS_ERR(cmds)) 278: return PTR_ERR(cmds); 279: 280: /* Identify the start of a command */ 281: cmds[index++] = cp_type7_packet(CP_NOP, 1); 282: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 283: 284: /* This is 25 dwords when drawctxt is not NULL and perfcounter needs to be zapped*/ 285: index += gen7_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 286: &cmds[index]); 287: 288: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 289: cmds[index++] = CP_SET_THREAD_BOTH; 290: 291: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 292: cmds[index++] = 0x101; /* IFPC disable */ 293: 294: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 295: cmds[index++] = CP_SET_THREAD_BR; 296: 297: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 298: drawctxt, &profile_dwords); 299: 300: if (profile_gpuaddr) { 301: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 302: cmds[index++] = lower_32_bits(profile_gpuaddr); 303: cmds[index++] = upper_32_bits(profile_gpuaddr); 304: cmds[index++] = profile_dwords; 305: } 306: 307: if (drawctxt) { 308: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 309: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 310: drawctxt)); 311: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 312: drawctxt)); 313: cmds[index++] = timestamp; 314: } 315: 316: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 317: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 318: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); 319: cmds[index++] = rb->timestamp; 320: 321: if (IS_SECURE(flags)) { 322: /* Sync BV and BR if entering secure mode */ 323: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 324: cmds[index++] = CP_SYNC_THREADS | CP_CONCURRENT_BIN_DISABLE; 325: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 326: cmds[index++] = 1; 327: } 328: 329: memcpy(&cmds[index], in, dwords << 2); 330: index += dwords; 331: 332: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev, 333: drawctxt, &dwords); 334: 335: if (profile_gpuaddr) { 336: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 337: cmds[index++] = lower_32_bits(profile_gpuaddr); 338: cmds[index++] = upper_32_bits(profile_gpuaddr); 339: cmds[index++] = profile_dwords; 340: } 341: 342: if (test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &device->mmu.pfpolicy)) 343: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0); 344: 345: if (is_concurrent_binning(drawctxt)) { 346: u64 addr = SCRATCH_RB_GPU_ADDR(device, rb->id, bv_ts); 347: 348: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 349: cmds[index++] = CP_SET_THREAD_BV; 350: 351: /* 352: * Make sure the timestamp is committed once BV pipe is 353: * completely done with this submission. 354: */ 355: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 356: cmds[index++] = CACHE_CLEAN | BIT(27); 357: cmds[index++] = lower_32_bits(addr); 358: cmds[index++] = upper_32_bits(addr); 359: cmds[index++] = rb->timestamp; 360: 361: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 362: cmds[index++] = CP_SET_THREAD_BR; 363: 364: /* 365: * This makes sure that BR doesn't race ahead and commit 366: * timestamp to memstore while BV is still processing 367: * this submission. 368: */ 369: cmds[index++] = cp_type7_packet(CP_WAIT_TIMESTAMP, 4); 370: cmds[index++] = 0; 371: cmds[index++] = lower_32_bits(addr); 372: cmds[index++] = upper_32_bits(addr); 373: cmds[index++] = rb->timestamp; 374: } 375: 376: /* 377: * If this is an internal command, just write the ringbuffer timestamp, 378: * otherwise, write both 379: */ 380: if (!drawctxt) { 381: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 382: cmds[index++] = CACHE_CLEAN | BIT(31) | BIT(27); 383: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 384: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 385: cmds[index++] = rb->timestamp; 386: } else { 387: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 388: cmds[index++] = CACHE_CLEAN | BIT(31) | BIT(27); 389: cmds[index++] = lower_32_bits(CTXT_EOPTIMESTAMP(device, 390: drawctxt)); 391: cmds[index++] = upper_32_bits(CTXT_EOPTIMESTAMP(device, 392: drawctxt)); 393: cmds[index++] = timestamp; 394: 395: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 396: cmds[index++] = CACHE_CLEAN | BIT(27); 397: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 398: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 399: cmds[index++] = rb->timestamp; 400: } 401: 402: if (IS_WFI(flags)) 403: cmds[index++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 404: 405: if (IS_SECURE(flags)) { 406: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 407: cmds[index++] = CP_CONCURRENT_BIN_DISABLE; 408: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 409: cmds[index++] = 0; 410: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 411: cmds[index++] = CP_SYNC_THREADS; 412: } 413: 414: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 415: cmds[index++] = CP_SET_THREAD_BOTH; 416: 417: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 418: cmds[index++] = 0x100; /* IFPC enable */ 419: 420: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 421: cmds[index++] = CP_SET_THREAD_BR; 422: 423: /* 10 dwords */ MATCH LINES: 503, 504 491: if (!_kgsl_context_get(&drawctxt->base)) 492: return -ENOENT; 493: 494: ret = gen7_rb_context_switch(adreno_dev, rb, drawctxt); 495: if (ret) { 496: kgsl_context_put(&drawctxt->base); 497: return ret; 498: } 499: 500: trace_adreno_drawctxt_switch(rb, drawctxt); 501: 502: /* Release the current drawctxt as soon as the new one is switched */ 503: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active, 504: rb, rb->timestamp); 505: 506: rb->drawctxt_active = drawctxt; 507: return 0; 508: } 509: 510: 511: #define GEN7_USER_PROFILE_IB(rb, cmdobj, cmds, field) \ 512: gen7_get_user_profiling_ib((rb), (cmdobj), \ 513: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 514: (cmds)) 515: 516: #define GEN7_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 517: gen7_get_alwayson_counter((cmds), \ 518: (dev)->profile_buffer->gpuaddr + \ 519: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 520: field)) 521: 522: #define GEN7_KERNEL_PROFILE_CONTEXT(dev, cmdobj, cmds, field) \ 523: gen7_get_alwayson_context((cmds), \ 524: (dev)->profile_buffer->gpuaddr + \ 525: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 526: field)) 527: 528: #define GEN7_COMMAND_DWORDS 60 MATCH LINES: 648, 652 636: * It is "normal" to get a -ENOSPC or a -ENOENT. Don't log it, 637: * the upper layers know how to handle it 638: */ 639: if (ret != -ENOSPC && ret != -ENOENT) 640: dev_err(device->dev, 641: "Unable to switch draw context: %d\n", ret); 642: goto done; 643: } 644: 645: adreno_drawobj_set_constraint(device, drawobj); 646: 647: ret = gen7_ringbuffer_addcmds(adreno_dev, drawctxt->rb, drawctxt, 648: flags, cmds, index, drawobj->timestamp, time); 649: 650: done: 651: trace_kgsl_issueibcmds(device, drawctxt->base.id, numibs, 652: drawobj->timestamp, drawobj->flags, ret, drawctxt->type); 653: 654: kvfree(cmds); 655: return ret; 656: } --- FILE: \adreno_gen8.c | HITS: 25 --- MATCH LINES: 1150, 1163, 1167, 1170, 1179, 1189, 1195 1138: cmds[i++] = upper_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 1139: /* 1140: * Gen8 targets with concurrent binning are expected to have a dynamic 1141: * power up list with triplets which contains the pipe id in it. 1142: * Bit 31 of POWER_UP_REGISTER_LIST_LENGTH is reused here to let CP 1143: * know if the power up contains the triplets. If 1144: * REGISTER_INIT_LIST_WITH_SPINLOCK is set and bit 31 below is set, 1145: * CP expects a dynamic list with triplets. 1146: */ 1147: cmds[i++] = BIT(31); 1148: } 1149: 1150: int gen8_fenced_write(struct adreno_device *adreno_dev, u32 offset, 1151: u32 value, u32 mask) 1152: { 1153: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1154: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1155: u32 status, i; 1156: u64 ts1, ts2; 1157: 1158: kgsl_regwrite(device, offset, value); 1159: ts1 = gpudev->read_alwayson(adreno_dev); 1160: for (i = 0; i < GMU_CORE_LONG_WAKEUP_RETRY_LIMIT; i++) { 1161: /* 1162: * Make sure the previous register write is posted before 1163: * checking the fence status 1164: */ 1165: mb(); 1166: 1167: gmu_core_regread(device, GEN8_GMUAO_AHB_FENCE_STATUS, &status); 1168: 1169: /* 1170: * If !writedropped0/1, then the write to fenced register 1171: * was successful 1172: */ 1173: if (!(status & mask)) 1174: break; 1175: 1176: /* Wait a small amount of time before trying again */ 1177: udelay(GMU_CORE_WAKEUP_DELAY_US); 1178: 1179: /* Try to write the fenced register again */ 1180: kgsl_regwrite(device, offset, value); 1181: } 1182: 1183: if (i < GMU_CORE_SHORT_WAKEUP_RETRY_LIMIT) 1184: return 0; 1185: 1186: if (i == GMU_CORE_LONG_WAKEUP_RETRY_LIMIT) { 1187: ts2 = gpudev->read_alwayson(adreno_dev); 1188: dev_err(device->dev, 1189: "Timed out waiting %d usecs to write fenced register 0x%x, timestamps: %llx %llx\n", 1190: i * GMU_CORE_WAKEUP_DELAY_US, offset, ts1, ts2); 1191: return -ETIMEDOUT; 1192: } 1193: 1194: dev_info(device->dev, 1195: "Waited %d usecs to write fenced register 0x%x\n", 1196: i * GMU_CORE_WAKEUP_DELAY_US, offset); 1197: 1198: return 0; 1199: } 1200: 1201: #define MIN_HBB 13 1202: 1203: static void gen8_calc_ubwc_config_legacy(struct adreno_device *adreno_dev) 1204: { 1205: struct adreno_ubwc_props *ubwc_props = &adreno_dev->ubwc_props; 1206: 1207: switch (adreno_dev->ubwc_mode) { 1208: case KGSL_UBWC_6_0: 1209: ubwc_props->yuvnotcomptofc = true; 1210: ubwc_props->mode2 = 5; 1211: break; 1212: case KGSL_UBWC_5_0: 1213: ubwc_props->amsbc = true; 1214: ubwc_props->rgb565_predicator = true; 1215: ubwc_props->mode2 = 4; 1216: break; 1217: case KGSL_UBWC_4_0: 1218: ubwc_props->amsbc = true; 1219: ubwc_props->rgb565_predicator = true; MATCH LINES: 3005, 3020, 3024, 3026, 3030, 3035, 3037, 3042, 3044, 3051, 3057 2993: ADRENO_IRQ_CALLBACK(gen8_preemption_callback),/* 8 - CP_SW */ 2994: ADRENO_IRQ_CALLBACK(gen8_cp_hw_err_callback), /* 9 - CP_HW_ERROR */ 2995: ADRENO_IRQ_CALLBACK(NULL), /* 10 - CP_CCU_FLUSH_DEPTH_TS */ 2996: ADRENO_IRQ_CALLBACK(NULL), /* 11 - CP_CCU_FLUSH_COLOR_TS */ 2997: ADRENO_IRQ_CALLBACK(NULL), /* 12 - CP_CCU_RESOLVE_TS */ 2998: ADRENO_IRQ_CALLBACK(NULL), /* 13 - UNUSED */ 2999: ADRENO_IRQ_CALLBACK(NULL), /* 14 - UNUSED */ 3000: ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 15 - CP_RB_INT */ 3001: ADRENO_IRQ_CALLBACK(NULL), /* 16 - CP_RB_INT_LPAC*/ 3002: ADRENO_IRQ_CALLBACK(NULL), /* 17 - CP_RB_DONE_TS */ 3003: ADRENO_IRQ_CALLBACK(NULL), /* 18 - UNUSED */ 3004: ADRENO_IRQ_CALLBACK(NULL), /* 19 - UNUSED */ 3005: ADRENO_IRQ_CALLBACK(gen8_cp_callback), /* 20 - CP_CACHE_FLUSH_TS */ 3006: ADRENO_IRQ_CALLBACK(NULL), /* 21 - CP_CACHE_TS_LPAC */ 3007: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 22 - RBBM_ATB_BUS_OVERFLOW */ 3008: ADRENO_IRQ_CALLBACK(adreno_hang_int_callback), /* 23 - MISHANGDETECT */ 3009: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 24 - UCHE_OOB_ACCESS */ 3010: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 25 - UCHE_TRAP_INTR */ 3011: ADRENO_IRQ_CALLBACK(gen8_dbgc_intr_callback), /* 26 - DEBUG_BUS_INTR_0 */ 3012: ADRENO_IRQ_CALLBACK(gen8_dbgc_intr_callback), /* 27 - DEBUG_BUS_INTR_1 */ 3013: ADRENO_IRQ_CALLBACK(gen8_err_callback), /* 28 - TSBWRITEERROR */ 3014: ADRENO_IRQ_CALLBACK(gen8_swfuse_violation_callback), /* 29 - SWFUSEVIOLATION */ 3015: ADRENO_IRQ_CALLBACK(NULL), /* 30 - ISDB_CPU_IRQ */ 3016: ADRENO_IRQ_CALLBACK(NULL), /* 31 - ISDB_UNDER_DEBUG */ 3017: }; 3018: 3019: /* 3020: * If the AHB fence is not in ALLOW mode when we receive an RBBM 3021: * interrupt, something went wrong. This means that we cannot proceed 3022: * since the IRQ status and clear registers are not accessible. 3023: * This is usually harmless because the GMU will abort power collapse 3024: * and change the fence back to ALLOW. Poll so that this can happen. 3025: */ 3026: static int gen8_irq_poll_fence(struct adreno_device *adreno_dev) 3027: { 3028: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3029: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 3030: u32 status, fence, fence_retries = 0; 3031: u64 a, b, c; 3032: 3033: a = gpudev->read_alwayson(adreno_dev); 3034: 3035: kgsl_regread(device, GEN8_GMUAO_AHB_FENCE_CTRL, &fence); 3036: 3037: while (fence != 0) { 3038: b = gpudev->read_alwayson(adreno_dev); 3039: 3040: /* Wait for small time before trying again */ 3041: udelay(1); 3042: kgsl_regread(device, GEN8_GMUAO_AHB_FENCE_CTRL, &fence); 3043: 3044: if (fence_retries == 100 && fence != 0) { 3045: c = gpudev->read_alwayson(adreno_dev); 3046: 3047: kgsl_regread(device, GEN8_GMUAO_RBBM_INT_UNMASKED_STATUS_SHADOW, 3048: &status); 3049: 3050: dev_crit_ratelimited(device->dev, 3051: "status=0x%x Unmasked status=0x%x Mask=0x%x timestamps: %llx %llx %llx\n", 3052: status & adreno_dev->irq_mask, status, 3053: adreno_dev->irq_mask, a, b, c); 3054: return -ETIMEDOUT; 3055: } 3056: 3057: fence_retries++; 3058: } 3059: 3060: return 0; 3061: } 3062: 3063: static irqreturn_t gen8_hwsched_irq_handler(struct adreno_device *adreno_dev) 3064: { 3065: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3066: irqreturn_t ret = IRQ_NONE; 3067: u32 status; 3068: 3069: /* 3070: * GPU can power down once the INT_0_STATUS is read below. 3071: * But there still might be some register reads required so 3072: * force the GMU/GPU into KEEPALIVE mode until done with the ISR. 3073: */ 3074: gen8_gpu_keepalive(adreno_dev, true); 3075: 3076: kgsl_regread(device, GEN8_RBBM_INT_0_STATUS, &status); 3077: 3078: kgsl_regwrite(device, GEN8_RBBM_INT_CLEAR_CMD, status); 3079: 3080: ret = adreno_irq_callbacks(adreno_dev, gen8_irq_funcs, status); 3081: MATCH LINES: 3104 3092: { 3093: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3094: irqreturn_t ret = IRQ_NONE; 3095: u32 status; 3096: 3097: /* 3098: * GPU can power down once the INT_0_STATUS is read below. 3099: * But there still might be some register reads required so 3100: * force the GMU/GPU into KEEPALIVE mode until done with the ISR. 3101: */ 3102: gen8_gpu_keepalive(adreno_dev, true); 3103: 3104: if (gen8_irq_poll_fence(adreno_dev)) { 3105: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 3106: goto done; 3107: } 3108: 3109: kgsl_regread(device, GEN8_RBBM_INT_0_STATUS, &status); 3110: 3111: kgsl_regwrite(device, GEN8_RBBM_INT_CLEAR_CMD, status); 3112: 3113: ret = adreno_irq_callbacks(adreno_dev, gen8_irq_funcs, status); 3114: 3115: trace_kgsl_gen8_irq_status(adreno_dev, status); 3116: 3117: done: 3118: /* If hard fault, then let snapshot turn off the keepalive */ 3119: if (!(adreno_gpu_fault(adreno_dev) & ADRENO_HARD_FAULT)) 3120: gen8_gpu_keepalive(adreno_dev, false); 3121: 3122: return ret; 3123: } 3124: 3125: static irqreturn_t gen8_cx_host_irq_handler(int irq, void *data) 3126: { 3127: struct kgsl_device *device = data; 3128: u32 status; MATCH LINES: 3700, 3706, 3734, 3754, 3757, 3762 3688: } 3689: 3690: static void gen8_lpac_fault_header(struct adreno_device *adreno_dev, 3691: struct kgsl_drawobj *drawobj) 3692: { 3693: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3694: struct adreno_context *drawctxt; 3695: u32 status = 0, rptr = 0, wptr = 0, ib1sz = 0, ib2sz = 0, ib3sz = 0; 3696: u64 ib1base = 0, ib2base = 0, ib3base = 0; 3697: bool gx_on = adreno_gx_is_on(adreno_dev); 3698: 3699: drawctxt = ADRENO_CONTEXT(drawobj->context); 3700: drawobj->context->last_faulted_cmd_ts = drawobj->timestamp; 3701: drawobj->context->total_fault_count++; 3702: 3703: pr_context(device, drawobj->context, 3704: "LPAC ctx %u ctx_type %s ts %u policy %lX dispatch_queue=%d\n", 3705: drawobj->context->id, kgsl_context_type(drawctxt->type), 3706: drawobj->timestamp, CMDOBJ(drawobj)->fault_recovery, 3707: drawobj->context->gmu_dispatch_queue); 3708: 3709: pr_context(device, drawobj->context, "lpac cmdline: %s\n", 3710: drawctxt->base.proc_priv->cmdline); 3711: 3712: if (!gen8_gmu_rpmh_pwr_state_is_active(device) || !gx_on) 3713: goto done; 3714: 3715: kgsl_regread(device, GEN8_RBBM_LPAC_STATUS, &status); 3716: kgsl_regread(device, GEN8_CP_RB_RPTR_LPAC, &rptr); 3717: kgsl_regread(device, GEN8_CP_RB_WPTR_LPAC, &wptr); 3718: gen8_periph_regread64(device, GEN8_CP_PERIPH_IB1_BASE_LO, 3719: GEN8_CP_PERIPH_IB1_BASE_HI, &ib1base, PIPE_LPAC); 3720: gen8_periph_regread(device, GEN8_CP_PERIPH_IB1_OFFSET, &ib1sz, PIPE_LPAC); 3721: gen8_periph_regread64(device, GEN8_CP_PERIPH_IB2_BASE_LO, 3722: GEN8_CP_PERIPH_IB2_BASE_HI, &ib2base, PIPE_LPAC); 3723: gen8_periph_regread(device, GEN8_CP_PERIPH_IB2_OFFSET, &ib2sz, PIPE_LPAC); 3724: gen8_periph_regread64(device, GEN8_CP_PERIPH_IB3_BASE_LO, 3725: GEN8_CP_PERIPH_IB3_BASE_HI, &ib3base, PIPE_LPAC); 3726: gen8_periph_regread(device, GEN8_CP_PERIPH_IB3_OFFSET, &ib3sz, PIPE_LPAC); 3727: gen8_host_aperture_set(adreno_dev, 0, 0, 0); 3728: 3729: pr_context(device, drawobj->context, 3730: "LPAC: status %8.8X rb %4.4x/%4.4x ib1 %16.16llX/%4.4x ib2 %16.16llX/%4.4x ib3 %16.16llX/%4.4x\n", 3731: status, rptr, wptr, ib1base, ib1sz, ib2base, ib2sz, ib3base, ib3sz); 3732: 3733: done: 3734: trace_adreno_gpu_fault(drawobj->context->id, drawobj->timestamp, status, 3735: rptr, wptr, ib1base, ib1sz, ib2base, ib2sz, 3736: adreno_get_level(drawobj->context)); 3737: 3738: } 3739: 3740: static void gen8_fault_header(struct adreno_device *adreno_dev, 3741: struct kgsl_drawobj *drawobj) 3742: { 3743: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3744: struct adreno_context *drawctxt; 3745: u32 status = 0, rptr = 0, wptr = 0, ib1sz = 0, ib2sz = 0, ib3sz, rptr_bv = 0; 3746: u32 ib1sz_bv = 0, ib2sz_bv = 0, ib3sz_bv, gfx_status, gfx_br_status, gfx_bv_status; 3747: u64 ib1base = 0, ib2base = 0, ib3base, ib1base_bv = 0, ib2base_bv, ib3base_bv; 3748: u32 ctxt_id = 0, ts = 0; 3749: int rb_id = -1; 3750: bool gx_on = adreno_gx_is_on(adreno_dev); 3751: 3752: if (drawobj) { 3753: drawctxt = ADRENO_CONTEXT(drawobj->context); 3754: drawobj->context->last_faulted_cmd_ts = drawobj->timestamp; 3755: drawobj->context->total_fault_count++; 3756: ctxt_id = drawobj->context->id; 3757: ts = drawobj->timestamp; 3758: rb_id = adreno_get_level(drawobj->context); 3759: 3760: pr_context(device, drawobj->context, "ctx %u ctx_type %s ts %u policy %lX\n", 3761: drawobj->context->id, kgsl_context_type(drawctxt->type), 3762: drawobj->timestamp, CMDOBJ(drawobj)->fault_recovery); 3763: 3764: pr_context(device, drawobj->context, "cmdline: %s\n", 3765: drawctxt->base.proc_priv->cmdline); 3766: } 3767: 3768: if (!gen8_gmu_rpmh_pwr_state_is_active(device) || !gx_on) 3769: goto done; 3770: 3771: kgsl_regread(device, GEN8_RBBM_STATUS, &status); 3772: kgsl_regread(device, GEN8_RBBM_GFX_STATUS, &gfx_status); 3773: kgsl_regread(device, GEN8_RBBM_GFX_BV_STATUS, &gfx_bv_status); 3774: kgsl_regread(device, GEN8_RBBM_GFX_BR_STATUS, &gfx_br_status); 3775: kgsl_regread(device, GEN8_CP_RB_RPTR_BR, &rptr); 3776: kgsl_regread(device, GEN8_CP_RB_WPTR_GC, &wptr); 3777: kgsl_regread(device, GEN8_CP_RB_RPTR_BV, &rptr_bv); 3778: gen8_periph_regread64(device, GEN8_CP_PERIPH_IB1_BASE_LO, 3779: GEN8_CP_PERIPH_IB1_BASE_HI, &ib1base, PIPE_BR); 3780: gen8_periph_regread(device, GEN8_CP_PERIPH_IB1_OFFSET, &ib1sz, PIPE_BR); 3781: gen8_periph_regread64(device, GEN8_CP_PERIPH_IB2_BASE_LO, 3782: GEN8_CP_PERIPH_IB2_BASE_HI, &ib2base, PIPE_BR); 3783: gen8_periph_regread(device, GEN8_CP_PERIPH_IB2_OFFSET, &ib2sz, PIPE_BR); 3784: gen8_periph_regread64(device, GEN8_CP_PERIPH_IB3_BASE_LO, 3785: GEN8_CP_PERIPH_IB3_BASE_HI, &ib3base, PIPE_BR); 3786: gen8_periph_regread(device, GEN8_CP_PERIPH_IB3_OFFSET, &ib3sz, PIPE_BR); --- FILE: \adreno_gen8.h | HITS: 5 --- MATCH LINES: 532, 536, 540, 551, 558 520: 521: /** 522: * gen8_ringbuffer_submit - Submit a command to the ringbuffer 523: * @rb: Ringbuffer pointer 524: * @time: Optional pointer to a adreno_submit_time container 525: * 526: * Return: 0 on success or negative on failure 527: */ 528: int gen8_ringbuffer_submit(struct adreno_ringbuffer *rb, 529: struct adreno_submit_time *time); 530: 531: /** 532: * gen8_fenced_write - Write to a fenced register 533: * @adreno_dev: An Adreno GPU handle 534: * @offset: Register offset 535: * @value: Value to write 536: * @mask: Expected FENCE_STATUS for successful write 537: * 538: * Return: 0 on success or negative on failure 539: */ 540: int gen8_fenced_write(struct adreno_device *adreno_dev, u32 offset, 541: u32 value, u32 mask); 542: 543: /** 544: * gen87ringbuffer_addcmds - Wrap and submit commands to the ringbuffer 545: * @adreno_dev: An Adreno GPU handle 546: * @rb: Ringbuffer pointer 547: * @drawctxt: Draw context submitting the commands 548: * @flags: Submission flags 549: * @in: Input buffer to write to ringbuffer 550: * @dwords: Dword length of @in 551: * @timestamp: Draw context timestamp for the submission 552: * @time: Optional pointer to a adreno_submit_time container 553: * 554: * Return: 0 on success or negative on failure 555: */ 556: int gen8_ringbuffer_addcmds(struct adreno_device *adreno_dev, 557: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 558: u32 flags, u32 *in, u32 dwords, u32 timestamp, 559: struct adreno_submit_time *time); 560: 561: /** 562: * gen8_cp_init_cmds - Create the CP_INIT commands 563: * @adreno_dev: An Adreno GPU handle 564: * @cmd: Buffer to write the CP_INIT commands into 565: */ 566: void gen8_cp_init_cmds(struct adreno_device *adreno_dev, u32 *cmds); 567: 568: /** 569: * gen8_gmu_hfi_probe - Probe Gen8 HFI specific data 570: * @adreno_dev: An Adreno GPU handle 571: * 572: * Return: 0 on success or negative on failure 573: */ 574: int gen8_gmu_hfi_probe(struct adreno_device *adreno_dev); 575: 576: static inline const struct gen8_gpudev * 577: to_gen8_gpudev(const struct adreno_gpudev *gpudev) 578: { 579: return container_of(gpudev, struct gen8_gpudev, base); 580: } 581: 582: /** --- FILE: \adreno_gen8_gmu.c | HITS: 11 --- MATCH LINES: 885 873: /* Vote veto for FAL10 */ 874: gmu_core_regwrite(device, GEN8_GMUCX_CX_FALNEXT_INTF, 0x1); 875: gmu_core_regwrite(device, GEN8_GMUCX_CX_FAL_INTF, 0x1); 876: 877: /* Clear init result to make sure we are getting fresh value */ 878: gmu_core_regwrite(device, GEN8_GMUCX_CM3_FW_INIT_RESULT, 0); 879: gmu_core_regwrite(device, GEN8_GMUCX_CM3_BOOT_CONFIG, 0x2); 880: 881: gmu_core_regwrite(device, GEN8_GMUCX_HFI_QTBL_ADDR, 882: gmu->hfi.hfi_mem->gmuaddr); 883: gmu_core_regwrite(device, GEN8_GMUCX_HFI_QTBL_INFO, 1); 884: 885: gmu_core_regwrite(device, GEN8_GMUAO_AHB_FENCE_RANGE_0, BIT(31) | 886: FIELD_PREP(GENMASK(30, 18), 0x32) | 887: FIELD_PREP(GENMASK(17, 0), GEN8_CP_CONTEXT_SWITCH_CNTL)); 888: 889: /* 890: * Make sure that CM3 state is at reset value. Snapshot is changing 891: * NMI bit and if we boot up GMU with NMI bit set GMU will boot 892: * straight in to NMI handler without executing __main code 893: */ 894: gmu_core_regwrite(device, GEN8_GMUCX_CM3_CFG, 0x4052); 895: 896: /* Set up GBIF registers from the GPU core definition */ 897: kgsl_regmap_multi_write(&device->regmap, gen8_core->gbif, 898: gen8_core->gbif_count); 899: 900: /** 901: * We may have asserted gbif halt as part of reset sequence which may 902: * not get cleared if the gdsc was not reset. So clear it before 903: * attempting GMU boot. 904: */ 905: kgsl_regwrite(device, GEN8_GBIF_HALT, BIT(3)); 906: 907: /* Set vrb address before starting GMU */ 908: if (!IS_ERR_OR_NULL(device->gmu_core.vrb)) 909: gmu_core_regwrite(device, GEN8_GMUCX_GENERAL_11, device->gmu_core.vrb->gmuaddr); MATCH LINES: 1212, 1213, 1214 1200: 1201: /* Disconnect GPU from BUS is not needed if CX GDSC goes off later */ 1202: 1203: /* 1204: * GEMNOC can enter power collapse state during GPU power down sequence. 1205: * This could abort CX GDSC collapse. Assert Qactive to avoid this. 1206: */ 1207: gmu_core_regwrite(device, GEN8_GMUCX_CX_FALNEXT_INTF, 0x1); 1208: 1209: /* Check no outstanding RPMh voting */ 1210: gen8_complete_rpmh_votes(gmu, 1); 1211: 1212: /* Clear the WRITEDROPPED fields and set fence to allow mode */ 1213: gmu_core_regwrite(device, GEN8_GMUAO_AHB_FENCE_STATUS_CLR, 0x7); 1214: gmu_core_regwrite(device, GEN8_GMUAO_AHB_FENCE_CTRL, 0); 1215: 1216: /* Make sure above writes are committed before we proceed to recovery */ 1217: wmb(); 1218: 1219: gmu_core_regwrite(device, GEN8_GMUCX_CM3_SYSRESET, 1); 1220: 1221: /* Flush out pending GX transactions using GBIF reinit mechanism */ 1222: gen8_gbif_gx_reinit(device); 1223: 1224: /* Halt CX traffic */ 1225: _do_gbif_halt(device, GEN8_GBIF_HALT, GEN8_GBIF_HALT_ACK, 1226: GEN8_GBIF_ARB_HALT_MASK, "CX"); 1227: 1228: _disable_malu_gdsc(adreno_dev); 1229: 1230: /* 1231: * Switch gx gdsc control from GMU to CPU force non-zero reference 1232: * count in clk driver so next disable call will turn off the GDSC 1233: */ 1234: if (gen8_gmu_gx_is_on(adreno_dev)) { 1235: kgsl_pwrctrl_enable_gx_gdsc(device); 1236: /* 1237: * The gxclkctl driver implements a custom disable callback that prevents 1238: * the OS from collapsing GX GDSC unless the GenPD synced_poweroff flag MATCH LINES: 1284, 1285 1272: 1273: req.bw |= adreno_gmu_bus_ab_quantize(adreno_dev, 0); 1274: 1275: /* Disable the power counter so that the GMU is not busy */ 1276: gmu_core_regwrite(device, GEN8_GMUCX_POWER_COUNTER_ENABLE, 0); 1277: 1278: ret = CMD_MSG_HDR(req, H2F_MSG_PREPARE_SLUMBER); 1279: if (ret) 1280: return ret; 1281: 1282: ret = gen8_hfi_send_generic_req(adreno_dev, &req, sizeof(req)); 1283: 1284: /* Make sure the fence is in ALLOW mode */ 1285: gmu_core_regwrite(device, GEN8_GMUAO_AHB_FENCE_CTRL, 0); 1286: 1287: /* 1288: * GEMNOC can enter power collapse state during GPU power down sequence. 1289: * This could abort CX GDSC collapse. Assert Qactive to avoid this. 1290: */ 1291: gmu_core_regwrite(device, GEN8_GMUCX_CX_FALNEXT_INTF, 0x1); 1292: 1293: return ret; 1294: } 1295: 1296: void gen8_gmu_suspend(struct adreno_device *adreno_dev, bool force) 1297: { 1298: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1299: 1300: if (!force && test_bit(ADRENO_DEVICE_RESET_RECOVERY, &adreno_dev->priv)) 1301: return; 1302: 1303: gen8_gmu_pwrctrl_suspend(adreno_dev); 1304: 1305: gmu_core_disable_clks(device); 1306: 1307: kgsl_pwrctrl_disable_mx_gdsc(device); 1308: 1309: kgsl_pwrctrl_disable_cx_gdsc(device); MATCH LINES: 1584, 1585, 1587, 1588, 1590 1572: u32 status = 0; 1573: 1574: gmu_core_regread(device, GEN8_GMUAO_AO_HOST_INTERRUPT_STATUS, &status); 1575: gmu_core_regwrite(device, GEN8_GMUAO_AO_HOST_INTERRUPT_CLR, status); 1576: 1577: if (status & GMU_INT_HOST_AHB_BUS_ERR) 1578: dev_err_ratelimited(GMU_PDEV_DEV(device), 1579: "AHB bus error interrupt received\n"); 1580: 1581: if (status & GMU_INT_WDOG_BITE) 1582: gen8_gpudev->handle_watchdog(adreno_dev); 1583: 1584: if (status & GMU_INT_FENCE_ERR) { 1585: u32 fence_status; 1586: 1587: gmu_core_regread(device, GEN8_GMUAO_AHB_FENCE_STATUS, 1588: &fence_status); 1589: dev_err_ratelimited(GMU_PDEV_DEV(device), 1590: "FENCE error interrupt received %x\n", fence_status); 1591: } 1592: 1593: if (status & ~GMU_AO_INT_MASK) 1594: dev_err_ratelimited(GMU_PDEV_DEV(device), 1595: "Unhandled GMU interrupts 0x%lx\n", 1596: status & ~GMU_AO_INT_MASK); 1597: 1598: return IRQ_HANDLED; 1599: } 1600: 1601: void gen8_gmu_aop_send_acd_state(struct gen8_gmu_device *gmu, bool flag) 1602: { 1603: struct kgsl_device *device = KGSL_DEVICE(gen8_gmu_to_adreno(gmu)); 1604: char msg_buf[36]; 1605: u32 size; 1606: int ret; 1607: 1608: if (IS_ERR_OR_NULL(gmu->qmp)) 1609: return; 1610: 1611: size = scnprintf(msg_buf, sizeof(msg_buf), 1612: "{class: gpu, res: acd, val: %d}", flag); 1613: 1614: ret = qmp_send(gmu->qmp, msg_buf, ALIGN((size + 1), SZ_4)); --- FILE: \adreno_gen8_gmu_snapshot.c | HITS: 2 --- MATCH LINES: 206, 207 194: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_GMU_MEMORY, 195: snapshot, gen8_gmu_snapshot_dtcm, gmu); 196: 197: /* Capture GMU registers which are on CX domain and unsliced */ 198: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS_V2, snapshot, 199: adreno_snapshot_registers_v2, 200: (void *) gen8_snapshot_block_list->gmu_cx_unsliced_regs); 201: 202: if (!gen8_gmu_rpmh_pwr_state_is_active(device) || 203: !gen8_gmu_gx_is_on(adreno_dev)) 204: return; 205: 206: /* Set fence to ALLOW mode so registers can be read */ 207: kgsl_regwrite(device, GEN8_GMUAO_AHB_FENCE_CTRL, 0); 208: 209: /* Capture GMU registers which are on GX domain */ 210: for (i = 0 ; i < gen8_snapshot_block_list->num_gmu_gx_regs; i++) { 211: struct gen8_reg_list *regs = &gen8_snapshot_block_list->gmu_gx_regs[i]; 212: 213: FOR_EACH_SLICE(j, regs->slice_region, slice_mask) { 214: info.regs = regs; 215: info.slice_id = SLICE_ID(regs->slice_region, j); 216: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_MVC_V3, snapshot, 217: gen8_legacy_snapshot_registers, &info); 218: } 219: } 220: } 221: 222: void gen8_gmu_snapshot(struct adreno_device *adreno_dev, 223: struct kgsl_snapshot *snapshot) 224: { 225: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 226: 227: /* 228: * Dump external register first to have GPUCC and other external 229: * register in snapshot to analyze the system state even in partial 230: * snapshot dump 231: */ --- FILE: \adreno_gen8_hfi.c | HITS: 1 --- MATCH LINES: 523 511: (char *) cmd->data); 512: 513: KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic, 514: GMU_PDEV(device), ticks, GMU_FAULT_F2H_MSG_ERR); 515: } 516: 517: void adreno_gen8_receive_debug_req(struct gen8_gmu_device *gmu, void *rcvd) 518: { 519: struct kgsl_device *device = KGSL_DEVICE(gen8_gmu_to_adreno(gmu)); 520: struct hfi_debug_cmd *cmd = rcvd; 521: 522: dev_dbg(GMU_PDEV_DEV(device), "HFI Debug Received: %d %d %d\n", 523: cmd->type, cmd->timestamp, cmd->data); 524: } 525: 526: int gen8_hfi_process_queue(struct gen8_gmu_device *gmu, 527: u32 queue_idx, struct pending_cmd *ret_cmd) 528: { 529: struct kgsl_device *device = KGSL_DEVICE(gen8_gmu_to_adreno(gmu)); 530: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 531: u32 rcvd[MAX_RCVD_SIZE]; 532: bool retry_for_ack = true; 533: 534: while (gen8_hfi_queue_read(gmu, queue_idx, rcvd, sizeof(rcvd)) > 0) { 535: /* ACK Handler */ 536: if (MSG_HDR_GET_TYPE(rcvd[0]) == HFI_MSG_ACK) { 537: int ret = gen8_receive_ack_cmd(gmu, rcvd, ret_cmd); 538: 539: if (ret) 540: return ret; 541: 542: retry_for_ack = false; 543: continue; 544: } 545: 546: /* Request Handler */ 547: switch (MSG_HDR_GET_ID(rcvd[0])) { --- FILE: \adreno_gen8_hwsched.c | HITS: 110 --- MATCH LINES: 19, 22, 25, 36, 38, 39, 52, 58, 61 7: #include 8: 9: #include "adreno.h" 10: #include "adreno_gen8.h" 11: #include "adreno_gen8_hwsched.h" 12: #include "adreno_snapshot.h" 13: #include "kgsl_bus.h" 14: #include "kgsl_device.h" 15: #include "kgsl_gmu_core.h" 16: #include "kgsl_trace.h" 17: #include "kgsl_util.h" 18: 19: static void _wakeup_hw_fence_waiters(struct adreno_device *adreno_dev, u32 fault) 20: { 21: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 22: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 23: bool lock = !in_interrupt(); 24: 25: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags)) 26: return; 27: 28: /* 29: * We could be in interrupt context here, which means we need to use spin_lock_irqsave 30: * (which disables interrupts) everywhere we take this lock. Instead of that, simply 31: * avoid taking this lock if we are recording a fault from an interrupt handler. 32: */ 33: if (lock) 34: spin_lock(&hwf->lock); 35: 36: clear_bit(GEN8_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags); 37: 38: /* Avoid creating new hardware fences until recovery is complete */ 39: set_bit(GEN8_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags); 40: 41: if (!lock) { 42: /* 43: * This barrier ensures that the above bitops complete before we wake up the waiters 44: */ 45: smp_wmb(); 46: } else { 47: spin_unlock(&hwf->lock); 48: } 49: 50: wake_up_all(&hwf->unack_wq); 51: 52: kgsl_delete_timer(&hfi->hw_fence_timer); 53: } 54: 55: void gen8_hwsched_fault(struct adreno_device *adreno_dev, u32 fault) 56: { 57: /* 58: * Wake up any threads that may be sleeping waiting for the hardware fence unack count to 59: * drop to a desired threshold. 60: */ 61: _wakeup_hw_fence_waiters(adreno_dev, fault); 62: 63: adreno_scheduler_fault(adreno_dev, fault); 64: } 65: 66: void gen8_hwsched_snapshot(struct adreno_device *adreno_dev, 67: struct kgsl_snapshot *snapshot) 68: { 69: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 70: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 71: bool skip_memkind_rb = false; 72: u32 i; 73: bool parse_payload; 74: 75: gen8_gmu_snapshot(adreno_dev, snapshot); 76: 77: adreno_hwsched_parse_fault_cmdobj(adreno_dev, snapshot); 78: 79: /* 80: * First try to dump ringbuffers using context bad HFI payloads 81: * because they have all the ringbuffer parameters. If ringbuffer 82: * payloads are not present, fall back to dumping ringbuffers 83: * based on MEMKIND_RB 84: */ 85: parse_payload = adreno_hwsched_parse_payload_rb(adreno_dev, snapshot); MATCH LINES: 133, 137, 148, 154, 157, 161, 164, 175, 182, 184, 190, 192, 196, 197, 200, 203 121: if (entry->desc.mem_kind == HFI_MEMKIND_PREEMPT_SCRATCH) 122: kgsl_snapshot_add_section(device, 123: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 124: snapshot, adreno_snapshot_global, 125: entry->md); 126: 127: if (entry->desc.mem_kind == HFI_MEMKIND_AQE_BUFFER) 128: kgsl_snapshot_add_section(device, 129: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 130: snapshot, adreno_hwsched_snapshot_aqe_buffer, 131: entry->md); 132: 133: if (entry->desc.mem_kind == HFI_MEMKIND_HW_FENCE) { 134: struct gmu_mem_type_desc desc; 135: 136: desc.memdesc = entry->md; 137: desc.type = SNAPSHOT_GMU_MEM_HW_FENCE; 138: kgsl_snapshot_add_section(device, 139: KGSL_SNAPSHOT_SECTION_GMU_MEMORY, 140: snapshot, adreno_snapshot_gmu_mem, &desc); 141: } 142: 143: } 144: 145: adreno_hwsched_snapshot_context_queue(device, snapshot); 146: } 147: 148: static void _get_hw_fence_entries(struct adreno_device *adreno_dev) 149: { 150: struct device_node *node = NULL; 151: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 152: u32 shadow_num_entries = 0; 153: 154: if (!ADRENO_FEATURE(adreno_dev, ADRENO_HW_FENCE)) 155: return; 156: 157: node = of_find_node_by_name(NULL, "qcom,hw-fence"); 158: if (!node) 159: return; 160: 161: if (of_property_read_u32(node, "qcom,hw-fence-table-entries", 162: &shadow_num_entries)) { 163: dev_err(GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)), 164: "qcom,hw-fence-table-entries property not found\n"); 165: shadow_num_entries = 8192; 166: } 167: 168: of_node_put(node); 169: 170: /* 171: * The return value is ignored as it does not need to be returned to the caller. 172: * Any errors are logged within the VRB set API if a failure occurs. 173: */ 174: gmu_core_set_vrb_register(device->gmu_core.vrb, 175: VRB_HW_FENCE_SHADOW_NUM_ENTRIES, shadow_num_entries); 176: } 177: 178: void gen8_hwsched_soccp_vote(struct adreno_device *adreno_dev, bool pwr_on) 179: { 180: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 181: struct device *gmu_pdev_dev = GMU_PDEV_DEV(device); 182: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 183: 184: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags)) 185: return; 186: 187: if (!gmu_core_soccp_vote(device, pwr_on)) 188: return; 189: 190: /* Make sure no more hardware fences are created */ 191: spin_lock(&hwf->lock); 192: set_bit(GEN8_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags); 193: spin_unlock(&hwf->lock); 194: 195: /* 196: * It is possible that some hardware fences were created while we were in slumber. Since 197: * soccp power vote failed, these hardware fences may never be signaled. Hence, log them 198: * for debug purposes. 199: */ 200: adreno_hwsched_log_remove_pending_hw_fences(adreno_dev, gmu_pdev_dev); 201: gmu_core_mark_for_coldboot(KGSL_DEVICE(adreno_dev)); 202: 203: adreno_hwsched_deregister_hw_fence(adreno_dev); 204: } 205: 206: static void gen8_hwsched_gmu_suspend(struct adreno_device *adreno_dev, bool force) 207: { 208: gen8_gmu_suspend(adreno_dev, force); 209: adreno_hwsched_reset_hfi_mem(adreno_dev); 210: } 211: 212: static void gen8_hwsched_set_ctxt_record_vrb(struct adreno_device *adreno_dev) 213: { 214: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 215: 216: if (IS_ERR_OR_NULL(device->gmu_core.vrb)) 217: return; 218: 219: /* Populate context record sizes in VRB */ 220: gmu_core_set_vrb_register(device->gmu_core.vrb, VRB_CTXRECORD_TOTAL_SZ, 221: adreno_dev->total_ctxt_record_sz >> 10); 222: gmu_core_set_vrb_register(device->gmu_core.vrb, VRB_CTXRECORD_GMEM_SZ, 223: adreno_gmem_size(adreno_dev) >> 10); 224: 225: /* Populate size of AQE context record */ 226: gmu_core_set_vrb_register(device->gmu_core.vrb, VRB_CTXRECORD_AQE_SZ, 227: adreno_dev->aqe_ctxt_record_sz >> 10); MATCH LINES: 309, 324, 326 297: 298: /* Initialize the CX timer */ 299: gen8_cx_timer_init(adreno_dev); 300: 301: ret = gen8_gmu_load_fw(adreno_dev); 302: if (ret) 303: goto clks_gdsc_off; 304: 305: ret = gen8_gmu_itcm_shadow(adreno_dev); 306: if (ret) 307: goto clks_gdsc_off; 308: 309: _get_hw_fence_entries(adreno_dev); 310: 311: gen8_gmu_register_config(adreno_dev); 312: 313: ret = gen8_gmu_version_info(adreno_dev); 314: if (ret) 315: goto clks_gdsc_off; 316: 317: gen8_gmu_irq_enable(adreno_dev); 318: 319: /* Vote for minimal DDR BW for GMU to init */ 320: level = pwr->pwrlevels[pwr->default_pwrlevel].bus_min; 321: 322: icc_set_bw(pwr->icc_path, 0, kBps_to_icc(pwr->ddr_table[level])); 323: 324: /* This is the minimum GMU FW HFI version required to enable hw fences */ 325: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) >= 7) 326: adreno_hwsched_register_hw_fence(adreno_dev); 327: 328: /* From this GMU FW all RBBM interrupts are handled at GMU */ 329: if (device->gmu_core.ver.core >= GMU_VERSION(5, 01, 06)) 330: adreno_irq_free(adreno_dev); 331: 332: gen8_hwsched_soccp_vote(adreno_dev, true); 333: 334: /* Clear any hwsched faults that might have been left over */ 335: adreno_clear_gpu_fault(adreno_dev); 336: 337: ret = gen8_gmu_device_start(adreno_dev); 338: if (ret) 339: goto err; 340: 341: gen8_get_gpu_feature_info(adreno_dev); 342: 343: ret = gen8_hwsched_hfi_start(adreno_dev); 344: if (ret) 345: goto err; 346: 347: if (adreno_dev->gmu_ab && 348: gen8_hwsched_hfi_get_value(adreno_dev, HFI_VALUE_GMU_AB_VOTE, 0) == 1 && 349: !WARN_ONCE(!adreno_dev->gpucore->num_ddr_channels, 350: "Number of DDR channel is not specified in gpu core")) { MATCH LINES: 947, 950, 953, 956, 957, 958, 963, 972, 978, 981, 988, 995, 1004, 1039, 1040, 1045, 1047, 1068, 1071, 1074, 1087, 1089, 1125 935: device->pwrscale.devfreq_enabled = true; 936: device->pwrctrl.last_stat_updated = ktime_get(); 937: } 938: 939: set_bit(ADRENO_DEVICE_FIRST_BOOT_DONE, &adreno_dev->priv); 940: 941: kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE); 942: 943: return 0; 944: } 945: 946: /** 947: * drain_ctx_hw_fences_cpu - Force trigger the hardware fences that 948: * were not sent to TxQueue by the GMU 949: */ 950: static void drain_ctx_hw_fences_cpu(struct adreno_device *adreno_dev, 951: struct adreno_context *drawctxt) 952: { 953: struct adreno_hw_fence_entry *entry, *tmp; 954: 955: spin_lock(&drawctxt->lock); 956: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 957: kgsl_hw_fence_trigger_cpu(KGSL_DEVICE(adreno_dev), entry->kfence); 958: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 959: } 960: spin_unlock(&drawctxt->lock); 961: } 962: 963: static void drain_hw_fences_cpu(struct adreno_device *adreno_dev) 964: { 965: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 966: struct kgsl_context *context; 967: int id; 968: 969: read_lock(&device->context_lock); 970: idr_for_each_entry(&device->context_idr, context, id) { 971: if (context->gmu_registered) 972: drain_ctx_hw_fences_cpu(adreno_dev, ADRENO_CONTEXT(context)); 973: } 974: read_unlock(&device->context_lock); 975: } 976: 977: /** 978: * check_inflight_hw_fences - During SLUMBER entry, we must make sure all hardware fences across 979: * all registered contexts have been sent to TxQueue. If not, take a snapshot 980: */ 981: static int check_inflight_hw_fences(struct adreno_device *adreno_dev) 982: { 983: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 984: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 985: struct kgsl_context *context; 986: int id, ret = 0; 987: 988: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags)) 989: return 0; 990: 991: read_lock(&device->context_lock); 992: idr_for_each_entry(&device->context_idr, context, id) { 993: 994: if (context->gmu_registered) { 995: ret = gen8_hwsched_check_context_inflight_hw_fences(adreno_dev, 996: ADRENO_CONTEXT(context)); 997: if (ret) 998: break; 999: } 1000: } 1001: read_unlock(&device->context_lock); 1002: 1003: if (ret) 1004: gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE); 1005: 1006: return ret; 1007: } 1008: 1009: static int gen8_hwsched_power_off(struct adreno_device *adreno_dev) 1010: { 1011: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1012: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1013: int ret = 0; 1014: bool drain_cpu = false; 1015: 1016: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 1017: return 0; 1018: 1019: kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); 1020: 1021: ret = gen8_gmu_oob_set(device, oob_gpu); 1022: if (ret) { 1023: gen8_gmu_oob_clear(device, oob_gpu); 1024: goto no_gx_power; 1025: } 1026: 1027: kgsl_pwrscale_update_stats(device); 1028: 1029: /* Save active coresight registers if applicable */ 1030: adreno_coresight_stop(adreno_dev); 1031: 1032: adreno_irqctrl(adreno_dev, 0); 1033: 1034: gen8_gmu_oob_clear(device, oob_gpu); 1035: 1036: no_gx_power: 1037: kgsl_pwrctrl_irq(device, false); 1038: 1039: /* Make sure GMU has sent all hardware fences to TxQueue */ 1040: if (check_inflight_hw_fences(adreno_dev)) 1041: drain_cpu = true; 1042: 1043: gen8_hwsched_gmu_power_off(adreno_dev); 1044: 1045: /* Now that we are sure that GMU is powered off, drain pending fences */ 1046: if (drain_cpu) 1047: drain_hw_fences_cpu(adreno_dev); 1048: 1049: adreno_hwsched_unregister_contexts(adreno_dev); 1050: 1051: adreno_llcc_slice_deactivate(adreno_dev); 1052: 1053: clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags); 1054: 1055: kgsl_delete_timer_sync(&device->idle_timer); 1056: 1057: kgsl_pwrscale_sleep(device); 1058: 1059: kgsl_pwrctrl_clear_l3_vote(device); 1060: 1061: gen8_hwsched_soccp_vote(adreno_dev, false); 1062: 1063: kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER); 1064: 1065: return ret; 1066: } 1067: 1068: static void check_hw_fence_unack_count(struct adreno_device *adreno_dev) 1069: { 1070: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1071: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 1072: u32 unack_count; 1073: 1074: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags)) 1075: return; 1076: 1077: gen8_hwsched_process_msgq(adreno_dev); 1078: 1079: spin_lock(&hwf->lock); 1080: unack_count = hwf->unack_count; 1081: spin_unlock(&hwf->lock); 1082: 1083: if (!unack_count) 1084: return; 1085: 1086: dev_err(GMU_PDEV_DEV(device), 1087: "hardware fence unack_count(%d) isn't zero before SLUMBER\n", 1088: unack_count); 1089: gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE); 1090: } 1091: 1092: static void hwsched_idle_check(struct work_struct *work) 1093: { 1094: struct kgsl_device *device = container_of(work, 1095: struct kgsl_device, idle_check_ws); 1096: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1097: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1098: 1099: kgsl_mutex_lock(&device->mutex); 1100: 1101: if (test_bit(GMU_DISABLE_SLUMBER, &device->gmu_core.flags)) 1102: goto done; 1103: 1104: if (atomic_read(&device->active_cnt) || time_is_after_jiffies(device->idle_jiffies)) { 1105: kgsl_pwrscale_update(device); 1106: goto done; 1107: } 1108: 1109: spin_lock(&device->submit_lock); 1110: if (device->submit_now) { 1111: spin_unlock(&device->submit_lock); 1112: kgsl_pwrscale_update(device); 1113: kgsl_start_idle_timer(device); 1114: goto done; 1115: } 1116: 1117: device->skip_inline_submit = true; 1118: spin_unlock(&device->submit_lock); 1119: 1120: if (!gpudev->hw_isidle(adreno_dev)) { 1121: dev_err(device->dev, "GPU isn't idle before SLUMBER\n"); 1122: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 1123: } 1124: 1125: check_hw_fence_unack_count(adreno_dev); 1126: 1127: gen8_hwsched_power_off(adreno_dev); 1128: 1129: done: 1130: kgsl_mutex_unlock(&device->mutex); 1131: } 1132: 1133: static int gen8_hwsched_first_open(struct adreno_device *adreno_dev) 1134: { 1135: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1136: int ret; 1137: 1138: /* 1139: * Do the one time settings that need to happen when we 1140: * attempt to boot the gpu the very first time 1141: */ 1142: ret = gen8_hwsched_first_boot(adreno_dev); 1143: if (ret) 1144: return ret; 1145: 1146: /* 1147: * A client that does a first_open but never closes the device 1148: * may prevent us from going back to SLUMBER. So trigger the idle 1149: * check by incrementing the active count and immediately releasing it. MATCH LINES: 1377, 1378, 1381, 1385, 1388, 1391, 1393, 1394, 1395, 1400, 1405, 1413, 1414, 1415, 1417, 1422, 1423, 1424, 1427, 1428, 1430, 1432, 1436, 1437, 1446, 1452, 1458, 1461, 1462, 1464, 1471, 1476, 1477, 1479, 1480, 1482, 1488, 1496, 1499, 1503, 1506, 1507, 1511, 1525, 1536, 1543, 1544, 1548, 1561, 1565, 1571, 1573, 1577, 1581, 1587 1365: 1366: read_lock(&hfi->msglock); 1367: 1368: list_for_each_entry(cmd, &hfi->msglist, node) { 1369: if (MSG_HDR_GET_ID(cmd->sent_hdr) == H2F_MSG_UNREGISTER_CONTEXT) 1370: complete(&cmd->complete); 1371: } 1372: 1373: read_unlock(&hfi->msglock); 1374: } 1375: 1376: /** 1377: * process_context_hw_fences_after_reset - This function processes all hardware fences that were 1378: * sent to GMU prior to recovery. If a fence is not retired by the GPU, and the context is still 1379: * good, then move them to the reset list. 1380: */ 1381: static void process_context_hw_fences_after_reset(struct adreno_device *adreno_dev, 1382: struct adreno_context *drawctxt, struct list_head *reset_list) 1383: { 1384: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1385: struct adreno_hw_fence_entry *entry, *tmp; 1386: 1387: spin_lock(&drawctxt->lock); 1388: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 1389: struct adreno_context *drawctxt = entry->drawctxt; 1390: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 1391: bool retired = kgsl_check_timestamp(device, &drawctxt->base, (u32)entry->cmd.ts); 1392: 1393: /* Delete the fences that GMU has sent to the TxQueue */ 1394: if (timestamp_cmp(hdr->out_fence_ts, (u32)entry->cmd.ts) >= 0) { 1395: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 1396: continue; 1397: } 1398: 1399: /* 1400: * Force retire the fences if the ts is retired and context is not 1401: * registered with GMU, or if the context is gone bad. 1402: */ 1403: if ((retired && !drawctxt->base.gmu_registered) || 1404: kgsl_context_is_bad(&drawctxt->base)) 1405: entry->cmd.flags |= HW_FENCE_FLAG_SKIP_MEMSTORE; 1406: 1407: list_add_tail(&entry->reset_node, reset_list); 1408: } 1409: spin_unlock(&drawctxt->lock); 1410: } 1411: 1412: /** 1413: * process_inflight_hw_fences_after_reset - Send hardware fences from all contexts back to the GMU 1414: * after fault recovery. We must wait for ack when sending each of these fences to GMU so as to 1415: * avoid sending a large number of hardware fences in a short span of time. 1416: */ 1417: static int process_inflight_hw_fences_after_reset(struct adreno_device *adreno_dev) 1418: { 1419: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1420: struct kgsl_context *context = NULL; 1421: int id, ret = 0; 1422: struct list_head hw_fence_list; 1423: struct adreno_hw_fence_entry *entry, *tmp; 1424: bool update_out_fence_ts = false; 1425: 1426: /** 1427: * Since we need to wait for ack from GMU when sending each inflight fence back to GMU, we 1428: * cannot send them from within atomic context. Hence, walk list of such hardware fences 1429: * for each context and add it to this local list and then walk this list to send all these 1430: * fences to GMU. 1431: */ 1432: INIT_LIST_HEAD(&hw_fence_list); 1433: 1434: read_lock(&device->context_lock); 1435: idr_for_each_entry(&device->context_idr, context, id) { 1436: process_context_hw_fences_after_reset(adreno_dev, ADRENO_CONTEXT(context), 1437: &hw_fence_list); 1438: } 1439: read_unlock(&device->context_lock); 1440: 1441: /* 1442: * Although we are not destroying the entries here, they can get destroyed concurrently 1443: * in f2h_main thread once they have been sent to GMU. Hence, to be safe against entry 1444: * destroy, use list_for_each_entry_safe. 1445: */ 1446: list_for_each_entry_safe(entry, tmp, &hw_fence_list, reset_node) { 1447: struct adreno_context *drawctxt = entry->drawctxt; 1448: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 1449: u32 entry_ts = (u32)entry->cmd.ts; 1450: 1451: /* 1452: * We must remove this entry from hw_fence_list before sending it to GMU to avoid 1453: * racing with the f2h_main thread 1454: */ 1455: list_del_init(&entry->reset_node); 1456: 1457: /* 1458: * We must access the hw fence entry before sending it to GMU as once it is 1459: * sent to GMU, it may be freed by f2h_main thread concurrently 1460: */ 1461: if (((entry->cmd.flags & HW_FENCE_FLAG_SKIP_MEMSTORE) != 0) && 1462: (timestamp_cmp(entry_ts, hdr->out_fence_ts) > 0)) { 1463: if (_kgsl_context_get(&drawctxt->base)) 1464: update_out_fence_ts = true; 1465: } 1466: 1467: /* 1468: * This is part of the reset sequence and any error in this path will be handled by 1469: * the caller. 1470: */ 1471: ret = gen8_send_hw_fence_hfi_wait_ack(adreno_dev, entry, 0); 1472: if (ret) 1473: break; 1474: 1475: /* 1476: * If HW_FENCE_FLAG_SKIP_MEMSTORE is set, then GMU context queue header will not be 1477: * updated for this fence. Hence, update it here. 1478: */ 1479: if (update_out_fence_ts) { 1480: hdr->out_fence_ts = entry_ts; 1481: kgsl_context_put(&drawctxt->base); 1482: update_out_fence_ts = false; 1483: } 1484: } 1485: 1486: /* Remove remaining entries from the list if we hit an error */ 1487: if (ret) { 1488: list_for_each_entry_safe(entry, tmp, &hw_fence_list, reset_node) { 1489: list_del_init(&entry->reset_node); 1490: } 1491: } 1492: 1493: return ret; 1494: } 1495: 1496: static int gen8_hwsched_drain_context_hw_fences(struct adreno_device *adreno_dev, 1497: struct adreno_context *drawctxt) 1498: { 1499: struct adreno_hw_fence_entry *entry, *tmp; 1500: int ret = 0; 1501: 1502: /* We don't need the drawctxt lock here as this context has already been invalidated */ 1503: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_list, node) { 1504: 1505: /* Any error here is fatal */ 1506: ret = gen8_send_hw_fence_hfi_wait_ack(adreno_dev, entry, 1507: HW_FENCE_FLAG_SKIP_MEMSTORE); 1508: if (ret) 1509: break; 1510: 1511: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 1512: } 1513: 1514: return ret; 1515: } 1516: 1517: static struct adreno_context *_get_guilty_context(struct kgsl_device *device) 1518: { 1519: struct kgsl_context *context = NULL; 1520: struct adreno_context *guilty = NULL; 1521: int id; 1522: 1523: read_lock(&device->context_lock); 1524: idr_for_each_entry(&device->context_idr, context, id) { 1525: if (test_and_clear_bit(KGSL_CONTEXT_PRIV_INVALID_DRAIN_HW_FENCE, &context->priv) && 1526: _kgsl_context_get(context)) { 1527: guilty = ADRENO_CONTEXT(context); 1528: break; 1529: } 1530: } 1531: read_unlock(&device->context_lock); 1532: 1533: return guilty; 1534: } 1535: 1536: static int drain_guilty_context_hw_fences(struct adreno_device *adreno_dev) 1537: { 1538: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1539: struct adreno_context *guilty = _get_guilty_context(device); 1540: int ret = 0; 1541: 1542: /* 1543: * We don't need drawctxt spinlock to signal these fences since the only other place 1544: * which can retire these fences is the context detach path and device mutex 1545: * ensures mutual exclusion between recovery thread and detach thread. 1546: */ 1547: while (guilty) { 1548: ret = gen8_hwsched_drain_context_hw_fences(adreno_dev, guilty); 1549: 1550: kgsl_context_put(&guilty->base); 1551: 1552: if (ret) 1553: break; 1554: 1555: guilty = _get_guilty_context(device); 1556: } 1557: 1558: return ret; 1559: } 1560: 1561: static int handle_hw_fences_after_reset(struct adreno_device *adreno_dev) 1562: { 1563: int ret; 1564: 1565: ret = drain_guilty_context_hw_fences(adreno_dev); 1566: if (ret) 1567: return ret; 1568: 1569: /* 1570: * We must do this after adreno_hwsched_replay() so that context registration 1571: * is done before we re-send the un-retired hardware fences to the GMU 1572: */ 1573: ret = process_inflight_hw_fences_after_reset(adreno_dev); 1574: if (ret) 1575: return ret; 1576: 1577: ret = gen8_hwsched_process_detached_hw_fences(adreno_dev); 1578: if (ret) 1579: return ret; 1580: 1581: return gen8_hwsched_disable_hw_fence_throttle(adreno_dev); 1582: } 1583: 1584: int gen8_hwsched_reset_replay(struct adreno_device *adreno_dev) 1585: { 1586: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1587: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 1588: int ret; 1589: 1590: /* 1591: * Any pending context unregister packets will be lost 1592: * since we hard reset the GMU. This means any threads waiting 1593: * for context unregister hfi ack will timeout. Wake them 1594: * to avoid false positive ack timeout messages later. 1595: */ 1596: gen8_hwsched_drain_ctxt_unregister(adreno_dev); 1597: 1598: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 1599: return 0; 1600: 1601: gen8_disable_gpu_irq(adreno_dev); 1602: 1603: gen8_gmu_irq_disable(adreno_dev); 1604: 1605: gen8_hwsched_hfi_stop(adreno_dev); 1606: 1607: gen8_hwsched_gmu_suspend(adreno_dev, true); 1608: 1609: adreno_hwsched_unregister_contexts(adreno_dev); 1610: 1611: adreno_llcc_slice_deactivate(adreno_dev); MATCH LINES: 1634 1622: /* 1623: * When we reset, we want to coldboot incase any scratch corruption 1624: * has occurred before we faulted. 1625: */ 1626: gmu_core_mark_for_coldboot(KGSL_DEVICE(adreno_dev)); 1627: 1628: ret = gen8_hwsched_boot(adreno_dev); 1629: if (ret) 1630: goto done; 1631: 1632: adreno_hwsched_replay(adreno_dev); 1633: 1634: ret = handle_hw_fences_after_reset(adreno_dev); 1635: done: 1636: BUG_ON(ret); 1637: 1638: return ret; 1639: } 1640: 1641: ssize_t gen8_hwsched_preempt_info_get(struct adreno_device *adreno_dev, char *buf) 1642: { 1643: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1644: u32 preempt_count_l0, preempt_count_l1a, preempt_count_l1b; 1645: u32 count = 0, max_size = PAGE_SIZE; 1646: int ret; 1647: 1648: ret = gmu_core_get_vrb_register(device->gmu_core.vrb, 1649: VRB_PREEMPT_COUNT_L0, &preempt_count_l0); 1650: ret |= gmu_core_get_vrb_register(device->gmu_core.vrb, 1651: VRB_PREEMPT_COUNT_L1A, &preempt_count_l1a); 1652: ret |= gmu_core_get_vrb_register(device->gmu_core.vrb, 1653: VRB_PREEMPT_COUNT_L1B, &preempt_count_l1b); 1654: 1655: if (ret) 1656: return ret; 1657: 1658: count += scnprintf(buf + count, max_size - count, MATCH LINES: 2096 2084: .touch_wakeup = gen8_hwsched_touch_wakeup, 2085: .pm_suspend = gen8_hwsched_pm_suspend, 2086: .pm_resume = gen8_hwsched_pm_resume, 2087: .gpu_clock_set = gen8_hwsched_clock_set, 2088: .gpu_bus_set = gen8_hwsched_bus_set, 2089: .gmu_based_dcvs_pwr_ops = gen8_hwsched_gmu_based_dcvs_pwr_ops, 2090: }; 2091: 2092: const struct adreno_hwsched_ops gen8_hwsched_ops = { 2093: .submit_drawobj = gen8_hwsched_submit_drawobj, 2094: .preempt_count = gen8_hwsched_preempt_count_get, 2095: .preempt_info = gen8_hwsched_preempt_info_get, 2096: .create_hw_fence = gen8_hwsched_create_hw_fence, 2097: .set_dcvs_profile = gen8_hwsched_set_dcvs_profile, 2098: }; 2099: 2100: int gen8_hwsched_probe(struct platform_device *pdev, 2101: u32 chipid, const struct adreno_gpu_core *gpucore) 2102: { 2103: struct adreno_device *adreno_dev; 2104: struct kgsl_device *device; 2105: struct gen8_hwsched_device *gen8_hwsched_dev; 2106: struct gen8_device *gen8_dev; 2107: struct device *gmu_dev; 2108: int ret; 2109: int i; 2110: 2111: gen8_hwsched_dev = devm_kzalloc(&pdev->dev, sizeof(*gen8_hwsched_dev), 2112: GFP_KERNEL); 2113: if (!gen8_hwsched_dev) 2114: return -ENOMEM; 2115: 2116: gen8_dev = &gen8_hwsched_dev->gen8_dev; 2117: adreno_dev = &gen8_dev->adreno_dev; 2118: 2119: adreno_dev->hwsched_enabled = true; 2120: MATCH LINES: 2138, 2139 2126: 2127: device = KGSL_DEVICE(adreno_dev); 2128: 2129: INIT_WORK(&device->idle_check_ws, hwsched_idle_check); 2130: 2131: timer_setup(&device->idle_timer, hwsched_idle_timer, 0); 2132: 2133: if (ADRENO_FEATURE(adreno_dev, ADRENO_LPAC)) 2134: adreno_dev->lpac_enabled = true; 2135: 2136: kgsl_mmu_set_feature(device, KGSL_MMU_PAGEFAULT_TERMINATE); 2137: 2138: if (ADRENO_FEATURE(adreno_dev, ADRENO_HW_FENCE)) 2139: device->max_syncobj_hw_fence_count = min_t(u32, HFI_SYNCOBJ_HW_FENCE_MAX, 2140: MAX_SYNCOBJ_QUERY_BITS); 2141: 2142: ret = adreno_hwsched_init(adreno_dev, &gen8_hwsched_ops); 2143: if (ret) 2144: return ret; 2145: 2146: /* Initialize the dcvs tunables */ 2147: for (i = 0; i < GPU_TUNING_KEY_MAX; i++) 2148: adreno_dev->hwsched.sysfs_dcvs_tunables[i].value = GPU_DCVS_TUNING_INVALID_VALUE; 2149: 2150: /* Initialize the TSENSE suspend work that is done at GPU suspend */ 2151: INIT_WORK(&gen8_dev->tsense_work, gen8_scm_gpu_tsense_suspend_work); 2152: 2153: gmu_dev = GMU_PDEV_DEV(device); 2154: WARN_ON(kobject_init_and_add(&adreno_dev->hwsched.tunables_kobj, &ktype_tunables, 2155: &gmu_dev->kobj, "dcvs_tunables")); 2156: 2157: WARN_ON(kobject_init_and_add(&adreno_dev->hwsched.dcvs_kobj, &ktype_dcvs, 2158: &gmu_dev->kobj, "dcvs")); 2159: 2160: return ret; 2161: } 2162: 2163: int gen8_hwsched_add_to_minidump(struct adreno_device *adreno_dev) --- FILE: \adreno_gen8_hwsched_hfi.c | HITS: 391 --- MATCH LINES: 45 33: .unused2 = 0, \ 34: .unused3 = 0, \ 35: .unused4 = 0, \ 36: .read_index = 0, \ 37: .write_index = 0, \ 38: } 39: 40: /* The GMU buffer address corresponds to the beginning of 41: * half the size of the shared buffer. 42: */ 43: #define GMU_BUF_ADDR(md) ((md.gmuaddr) + (md.size >> 1)) 44: 45: struct pending_cmd gen8_hw_fence_ack; 46: 47: struct gen8_hwsched_hfi *to_gen8_hwsched_hfi( 48: struct adreno_device *adreno_dev) 49: { 50: struct gen8_device *gen8_dev = container_of(adreno_dev, 51: struct gen8_device, adreno_dev); 52: struct gen8_hwsched_device *gen8_hwsched = container_of(gen8_dev, 53: struct gen8_hwsched_device, gen8_dev); 54: 55: return &gen8_hwsched->hwsched_hfi; 56: } 57: 58: int gen8_hfi_send_lpac_feature_ctrl(struct adreno_device *adreno_dev) 59: { 60: if (!adreno_dev->lpac_enabled) 61: return 0; 62: 63: return gen8_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_LPAC, 1, 0); 64: } 65: 66: static void add_waiter(struct gen8_hwsched_hfi *hfi, u32 hdr, 67: struct pending_cmd *ack) 68: { 69: memset(ack, 0x0, sizeof(*ack)); MATCH LINES: 214 202: hdr = drawctxt->gmu_context_queue.hostptr; 203: queue = (u32 *)(drawctxt->gmu_context_queue.hostptr + sizeof(*hdr)); 204: 205: for (i = hdr->read_index; i != hdr->write_index;) { 206: if (MSG_HDR_GET_ID(queue[i]) != H2F_MSG_ISSUE_SYNCOBJ) { 207: i = (i + MSG_HDR_GET_SIZE(queue[i])) % hdr->queue_size; 208: continue; 209: } 210: 211: if (adreno_gmu_context_queue_read(drawctxt, (u32 *) &cmd, i, sizeof(cmd) >> 2)) 212: break; 213: 214: if (cmd.timestamp == ts) { 215: log_syncobj(gmu, drawctxt, &cmd, 216: (i + (sizeof(cmd) >> 2)) % hdr->queue_size); 217: break; 218: } 219: i = (i + MSG_HDR_GET_SIZE(queue[i])) % hdr->queue_size; 220: } 221: 222: if (i == hdr->write_index) 223: dev_err(GMU_PDEV_DEV(device), "Couldn't find unsignaled syncobj ctx:%d ts:%d\n", 224: ctxt_id, ts); 225: 226: kgsl_context_put(context); 227: } 228: 229: /* Look up a particular key's value for a given type of payload */ 230: static u32 gen8_hwsched_lookup_key_value(struct adreno_device *adreno_dev, 231: u32 type, u32 key) 232: { 233: struct hfi_context_bad_cmd *cmd = adreno_dev->hwsched.ctxt_bad; 234: u32 i = 0, payload_bytes; 235: void *start; 236: 237: if (!cmd->hdr) 238: return 0; MATCH LINES: 600, 601, 603, 605, 606, 611, 612, 614, 615, 616, 617, 620, 622, 624, 625, 627, 629, 631, 642, 643, 645, 648 588: /* Non fatal RBBM error interrupts don't go through reset and recovery */ 589: if (!log_gpu_fault(adreno_dev)) { 590: memset(adreno_dev->hwsched.ctxt_bad, 0x0, HFI_MAX_MSG_SIZE); 591: return; 592: } 593: 594: adreno_dev->hwsched.reset_type = gen8_hwsched_lookup_key_value(adreno_dev, 595: PAYLOAD_FAULT_RESET_POLICY, KEY_GPU_RESET_POLICY); 596: 597: gen8_hwsched_fault(adreno_dev, ADRENO_HARD_FAULT); 598: } 599: 600: #define GET_QUERIED_FENCE_INDEX(x) (x / BITS_PER_SYNCOBJ_QUERY) 601: #define GET_QUERIED_FENCE_BIT(x) (x % BITS_PER_SYNCOBJ_QUERY) 602: 603: static bool fence_is_queried(struct hfi_syncobj_query_cmd *cmd, u32 fence_index) 604: { 605: u32 index = GET_QUERIED_FENCE_INDEX(fence_index); 606: u32 bit = GET_QUERIED_FENCE_BIT(fence_index); 607: 608: return (cmd->queries[index].query_bitmask & BIT(bit)); 609: } 610: 611: static void set_fence_signal_bit(struct adreno_device *adreno_dev, 612: struct hfi_syncobj_query_cmd *reply, struct dma_fence *fence, u32 fence_index) 613: { 614: u32 index = GET_QUERIED_FENCE_INDEX(fence_index); 615: u32 bit = GET_QUERIED_FENCE_BIT(fence_index); 616: u64 flags = ADRENO_HW_FENCE_SW_STATUS_PENDING; 617: char name[KGSL_FENCE_NAME_LEN]; 618: char value[32] = "unknown"; 619: 620: kgsl_fence_timeline_value_str(fence, value, sizeof(value)); 621: 622: if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) { 623: dev_err(GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)), 624: "GMU is waiting for signaled fence(ctx:%llu seqno:%llu value:%s)\n", 625: fence->context, fence->seqno, value); 626: reply->queries[index].query_bitmask |= BIT(bit); 627: flags = ADRENO_HW_FENCE_SW_STATUS_SIGNALED; 628: } 629: kgsl_get_fence_name(fence, name, sizeof(name)); 630: 631: trace_adreno_hw_fence_query(fence->context, fence->seqno, flags, name, value); 632: } 633: 634: static void gen8_syncobj_query_reply(struct adreno_device *adreno_dev, 635: struct kgsl_drawobj *drawobj, struct hfi_syncobj_query_cmd *cmd) 636: { 637: struct hfi_syncobj_query_cmd reply = {0}; 638: int i; 639: struct kgsl_drawobj_sync *syncobj = SYNCOBJ(drawobj); 640: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 641: 642: for (i = 0; i < syncobj->num_hw_fence; i++) { 643: struct dma_fence *fence = syncobj->hw_fences[i].fence; 644: 645: if (!fence_is_queried(cmd, i)) 646: continue; 647: 648: set_fence_signal_bit(adreno_dev, &reply, fence, i); 649: } 650: 651: reply.hdr = CREATE_MSG_HDR(F2H_MSG_SYNCOBJ_QUERY, HFI_MSG_CMD); 652: reply.gmu_ctxt_id = cmd->gmu_ctxt_id; 653: reply.sync_obj_ts = cmd->sync_obj_ts; 654: 655: trace_adreno_syncobj_query_reply(reply.gmu_ctxt_id, reply.sync_obj_ts, 656: gpudev->read_alwayson(adreno_dev)); 657: 658: gen8_hfi_send_cmd_async(adreno_dev, &reply, sizeof(reply)); 659: } 660: 661: struct syncobj_query_work { 662: /** @cmd: The query command to be processed */ 663: struct hfi_syncobj_query_cmd cmd; 664: /** @context: kgsl context that is waiting for this sync object */ 665: struct kgsl_context *context; 666: /** @work: The work structure to execute syncobj query reply */ 667: struct kthread_work work; 668: }; 669: 670: static void gen8_process_syncobj_query_work(struct kthread_work *work) 671: { 672: struct syncobj_query_work *query_work = container_of(work, MATCH LINES: 692, 708, 712 680: bool missing = true; 681: 682: mutex_lock(&hwsched->mutex); 683: kgsl_mutex_lock(&device->mutex); 684: 685: list_for_each_entry(obj, &hwsched->cmd_list, node) { 686: struct kgsl_drawobj *drawobj = obj->drawobj; 687: 688: if ((drawobj->type & SYNCOBJ_TYPE) == 0) 689: continue; 690: 691: if ((drawobj->context->id == cmd->gmu_ctxt_id) && 692: (drawobj->timestamp == cmd->sync_obj_ts)) { 693: gen8_syncobj_query_reply(adreno_dev, drawobj, cmd); 694: missing = false; 695: break; 696: } 697: } 698: 699: if (missing) { 700: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 701: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 702: 703: /* 704: * If the sync object is not found, it can only mean that the sync object was 705: * retired by the GMU in the meanwhile. However, if that is not the case, then 706: * we have a problem. 707: */ 708: if (timestamp_cmp(cmd->sync_obj_ts, hdr->sync_obj_ts) > 0) { 709: dev_err(GMU_PDEV_DEV(device), 710: "Missing sync object ctx:%d ts:%d retired:%d\n", 711: context->id, cmd->sync_obj_ts, hdr->sync_obj_ts); 712: gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE); 713: gen8_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 714: } 715: } 716: 717: kgsl_mutex_unlock(&device->mutex); 718: mutex_unlock(&hwsched->mutex); 719: 720: kgsl_context_put(context); 721: kfree(query_work); 722: } 723: 724: static void gen8_trigger_syncobj_query(struct adreno_device *adreno_dev, 725: u32 *rcvd) 726: { 727: struct syncobj_query_work *query_work; 728: struct hfi_syncobj_query_cmd *cmd = (struct hfi_syncobj_query_cmd *)rcvd; 729: struct kgsl_context *context = NULL; 730: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 731: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 732: int ret; 733: 734: trace_adreno_syncobj_query(cmd->gmu_ctxt_id, cmd->sync_obj_ts, 735: gpudev->read_alwayson(adreno_dev)); 736: MATCH LINES: 764, 765, 766, 768, 771, 772, 774, 777, 778, 779, 782, 784, 787, 789, 790, 795, 798, 800, 802, 803, 807, 812, 813, 815, 824, 829, 831, 834, 836, 839, 840, 849, 852, 853, 855, 861, 863, 869, 871, 878, 881, 884, 888, 890, 893, 897, 902, 904, 911, 913, 914, 918, 921, 929, 932, 937, 957, 965, 971, 978, 990, 992, 1000, 1001, 1003, 1009, 1010, 1012, 1015, 1017, 1021, 1022, 1031, 1035, 1039, 1040, 1044 752: kgsl_context_put(context); 753: return; 754: } 755: 756: kthread_init_work(&query_work->work, gen8_process_syncobj_query_work); 757: memcpy(&query_work->cmd, cmd, sizeof(*cmd)); 758: query_work->context = context; 759: 760: kthread_queue_work(adreno_dev->scheduler_worker, &query_work->work); 761: } 762: 763: /* 764: * This defines the maximum unack'd hardware fences that we allow. When this limit is reached, we 765: * will put all threads (that want to create a hardware fence) to sleep until the maximum unack'd 766: * hardware fence count drops to MIN_HW_FENCE_UNACK_COUNT 767: */ 768: #define MAX_HW_FENCE_UNACK_COUNT 20 769: 770: /* 771: * Once the maximum unack'd hardware fences drops to this value, wake up all the threads (that want 772: * to create hardware fences) 773: */ 774: #define MIN_HW_FENCE_UNACK_COUNT 10 775: 776: /* 777: * This is the maximum duration (in milliseconds) a thread (that wants to create a hardware fence) 778: * is put to sleep while we wait for the maximum number of unack'd hardware fences to drop from 779: * MAX_HW_FENCE_UNACK_COUNT to MIN_HW_FENCE_UNACK_COUNT. If the count doesn't drop to the desired 780: * value, then log an error and trigger snapshot and recovery. 781: */ 782: #define HW_FENCE_SLEEP_MS 200 783: 784: static void _enable_hw_fence_throttle(struct adreno_device *adreno_dev) 785: { 786: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 787: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 788: 789: set_bit(GEN8_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags); 790: set_bit(GEN8_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags); 791: 792: /* Avoid submitting new work to gpu until the unack count drops to a desired threshold */ 793: adreno_get_gpu_halt(adreno_dev); 794: 795: mod_timer(&hfi->hw_fence_timer, jiffies + msecs_to_jiffies(HW_FENCE_SLEEP_MS)); 796: } 797: 798: static void _increment_hw_fence_unack_count(struct adreno_device *adreno_dev) 799: { 800: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 801: 802: if ((++hwf->unack_count) == MAX_HW_FENCE_UNACK_COUNT) 803: _enable_hw_fence_throttle(adreno_dev); 804: } 805: 806: /** 807: * _send_hw_fence_no_ack - Send a hardware fence hfi packet to GMU without waiting for its ack. 808: * Increment the unack count on success 809: * 810: * Return: 0 on success or negative error on failure 811: */ 812: static int _send_hw_fence_no_ack(struct adreno_device *adreno_dev, 813: struct adreno_hw_fence_entry *entry) 814: { 815: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 816: u32 seqnum; 817: int ret; 818: 819: seqnum = atomic_inc_return(&hwf->seqnum); 820: entry->cmd.hdr = MSG_HDR_SET_SEQNUM_SIZE(entry->cmd.hdr, seqnum, sizeof(entry->cmd) >> 2); 821: 822: ret = gen8_hfi_cmdq_write(adreno_dev, (u32 *)&entry->cmd, sizeof(entry->cmd)); 823: if (!ret) 824: _increment_hw_fence_unack_count(adreno_dev); 825: 826: return ret; 827: } 828: 829: static struct adreno_hw_fence_entry *_get_deferred_hw_fence(struct adreno_context *drawctxt, u32 ts) 830: { 831: struct adreno_hw_fence_entry *entry = NULL, *next, *deferred_hw_fence_entry = NULL; 832: 833: spin_lock(&drawctxt->lock); 834: list_for_each_entry_safe(entry, next, &drawctxt->hw_fence_list, node) { 835: 836: if (timestamp_cmp((u32)entry->cmd.ts, ts) > 0) 837: break; 838: 839: /* We found a deferred hardware fence */ 840: deferred_hw_fence_entry = entry; 841: break; 842: } 843: spin_unlock(&drawctxt->lock); 844: 845: /* 846: * This path executes in isolation from any paths that may release this entry. So, it is 847: * safe to handle this entry outside of the drawctxt spinlock 848: */ 849: return deferred_hw_fence_entry; 850: } 851: 852: static int _send_deferred_hw_fence(struct adreno_device *adreno_dev, 853: struct adreno_context *drawctxt, struct adreno_hw_fence_entry *entry, u32 ts) 854: { 855: bool retired = kgsl_check_timestamp(KGSL_DEVICE(adreno_dev), &drawctxt->base, ts) || 856: kgsl_context_is_bad(&drawctxt->base); 857: int ret = 0; 858: u32 flags = 0; 859: 860: if (retired) 861: flags |= HW_FENCE_FLAG_SKIP_MEMSTORE; 862: 863: ret = gen8_send_hw_fence_hfi_wait_ack(adreno_dev, entry, flags); 864: if (ret) 865: return ret; 866: 867: spin_lock(&drawctxt->lock); 868: if (!retired) 869: list_move_tail(&entry->node, &drawctxt->hw_fence_inflight_list); 870: else 871: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 872: spin_unlock(&drawctxt->lock); 873: 874: return 0; 875: } 876: 877: /** 878: * process_hw_fence_deferred_ctxt - This function sends hardware fences to GMU (from the 879: * deferred drawctxt) which couldn't be sent earlier 880: */ 881: static int process_hw_fence_deferred_ctxt(struct adreno_device *adreno_dev, 882: struct adreno_context *drawctxt, u32 ts) 883: { 884: struct adreno_hw_fence_entry *deferred_hw_fence_entry = NULL; 885: int ret = 0; 886: 887: do { 888: deferred_hw_fence_entry = _get_deferred_hw_fence(drawctxt, ts); 889: 890: if (!deferred_hw_fence_entry) 891: break; 892: 893: ret = _send_deferred_hw_fence(adreno_dev, drawctxt, deferred_hw_fence_entry, ts); 894: if (ret) 895: break; 896: 897: } while (deferred_hw_fence_entry != NULL); 898: 899: return ret; 900: } 901: 902: static void _disable_hw_fence_throttle(struct adreno_device *adreno_dev, bool clear_abort_bit) 903: { 904: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 905: bool max; 906: 907: spin_lock(&hwf->lock); 908: 909: hwf->defer_drawctxt = NULL; 910: hwf->defer_ts = 0; 911: max = test_bit(GEN8_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags); 912: if (max) { 913: clear_bit(GEN8_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags); 914: clear_bit(GEN8_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags); 915: } 916: 917: if (clear_abort_bit) 918: clear_bit(GEN8_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags); 919: spin_unlock(&hwf->lock); 920: 921: /* Wake up dispatcher and any sleeping threads that want to create hardware fences */ 922: if (max) { 923: adreno_put_gpu_halt(adreno_dev); 924: adreno_scheduler_queue(adreno_dev); 925: wake_up_all(&hwf->unack_wq); 926: } 927: } 928: 929: static void gen8_defer_hw_fence_work(struct kthread_work *work) 930: { 931: struct gen8_hwsched_hfi *hfi = container_of(work, 932: struct gen8_hwsched_hfi, defer_hw_fence_work); 933: struct gen8_hwsched_device *gen8_hwsched = container_of(hfi, struct gen8_hwsched_device, 934: hwsched_hfi); 935: struct adreno_context *drawctxt; 936: struct adreno_device *adreno_dev = &gen8_hwsched->gen8_dev.adreno_dev; 937: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 938: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 939: u32 ts; 940: int ret; 941: 942: /* 943: * Grab the dispatcher and device mutex as we don't want to race with concurrent fault 944: * recovery 945: */ 946: mutex_lock(&adreno_dev->hwsched.mutex); 947: kgsl_mutex_lock(&device->mutex); 948: 949: spin_lock(&hwf->lock); 950: drawctxt = hwf->defer_drawctxt; 951: ts = hwf->defer_ts; 952: spin_unlock(&hwf->lock); 953: 954: if (!drawctxt) 955: goto unlock; 956: 957: ret = process_hw_fence_deferred_ctxt(adreno_dev, drawctxt, ts); 958: if (ret) { 959: /* the deferred drawctxt will be handled post fault recovery */ 960: gen8_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 961: goto unlock; 962: } 963: 964: /* 965: * Put back the context reference which was incremented when hw_fence.defer_drawctxt was set 966: */ 967: kgsl_context_put(&drawctxt->base); 968: 969: adreno_active_count_put(adreno_dev); 970: 971: _disable_hw_fence_throttle(adreno_dev, false); 972: 973: unlock: 974: kgsl_mutex_unlock(&device->mutex); 975: mutex_unlock(&adreno_dev->hwsched.mutex); 976: } 977: 978: static int _check_hw_fence_ack_failure(struct kgsl_device *device, u32 *result) 979: { 980: if (!result[2]) 981: return 0; 982: 983: dev_err(GMU_PDEV_DEV(device), 984: "HFI ACK failure: Req=0x%8.8X, Result=0x%8.8X\n", 985: result[1], result[2]); 986: 987: return -EINVAL; 988: } 989: 990: static void process_hw_fence_ack(struct adreno_device *adreno_dev, u32 *rcvd) 991: { 992: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 993: struct adreno_context *drawctxt = NULL; 994: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 995: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 996: 997: spin_lock(&hwf->lock); 998: 999: /* If this ack is being waited on, we don't need to touch the unack count */ 1000: if (gen8_hw_fence_ack.sent_hdr && 1001: CMP_HFI_ACK_HDR(gen8_hw_fence_ack.sent_hdr, rcvd[1])) { 1002: spin_unlock(&hwf->lock); 1003: complete(&gen8_hw_fence_ack.complete); 1004: return; 1005: } 1006: 1007: hwf->unack_count--; 1008: 1009: /* The unack count should never be greater than MAX_HW_FENCE_UNACK_COUNT */ 1010: if (hwf->unack_count > MAX_HW_FENCE_UNACK_COUNT) 1011: dev_err(GMU_PDEV_DEV(device), 1012: "unexpected hardware fence unack count:%d\n", 1013: hwf->unack_count); 1014: 1015: if (_check_hw_fence_ack_failure(device, rcvd)) { 1016: spin_unlock(&hwf->lock); 1017: gen8_hwsched_fault(adreno_dev, GMU_FAULT_HW_FENCE); 1018: return; 1019: } 1020: 1021: if (!test_bit(GEN8_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags) || 1022: (hwf->unack_count != MIN_HW_FENCE_UNACK_COUNT)) { 1023: spin_unlock(&hwf->lock); 1024: return; 1025: } 1026: 1027: drawctxt = hwf->defer_drawctxt; 1028: 1029: spin_unlock(&hwf->lock); 1030: 1031: kgsl_delete_timer_sync(&hfi->hw_fence_timer); 1032: 1033: /* 1034: * We need to handle the deferred context in another thread so that we can unblock the f2h 1035: * daemon here as it will need to process the acks for the hardware fences belonging to the 1036: * deferred context 1037: */ 1038: if (drawctxt) { 1039: kthread_init_work(&hfi->defer_hw_fence_work, gen8_defer_hw_fence_work); 1040: kthread_queue_work(adreno_dev->scheduler_worker, &hfi->defer_hw_fence_work); 1041: return; 1042: } 1043: 1044: _disable_hw_fence_throttle(adreno_dev, false); 1045: } 1046: 1047: int gen8_hwsched_process_f2h_platform_msg(struct adreno_device *adreno_dev, u32 *rcvd) 1048: { 1049: struct hfi_msg_platform *msg = (struct hfi_msg_platform *)rcvd; 1050: 1051: if (msg->sub_type == F2H_ST_MSG_SCALE_GMU) { 1052: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1053: struct hfi_scale_gmu_cmd *cmd = (struct hfi_scale_gmu_cmd *)rcvd; 1054: u32 index = cmd->gmu_pwrlevel; 1055: 1056: if ((index > 0) && (index <= device->gmu_core.num_freqs)) 1057: return gmu_core_clock_set_rate(device, index - 1); 1058: } 1059: 1060: return 0; 1061: } 1062: 1063: void gen8_hwsched_process_msgq(struct adreno_device *adreno_dev) 1064: { 1065: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 1066: struct gen8_hwsched_hfi *hw_hfi = to_gen8_hwsched_hfi(adreno_dev); 1067: u32 rcvd[MAX_RCVD_SIZE], next_hdr, type; 1068: MATCH LINES: 1095, 1097, 1098 1083: type = MSG_HDR_GET_ID(next_hdr); 1084: 1085: if (type != F2H_MSG_CONTEXT_BAD) { 1086: if (gen8_hfi_queue_read(gmu, HFI_MSG_ID, rcvd, sizeof(rcvd)) < 0) 1087: break; 1088: } 1089: 1090: switch (type) { 1091: case HFI_MSG_ACK: 1092: /* 1093: * We are assuming that there is only one outstanding ack because hfi 1094: * sending thread waits for completion while holding the device mutex 1095: * (except when we send H2F_MSG_HW_FENCE_INFO packets) 1096: */ 1097: if (MSG_HDR_GET_ID(rcvd[1]) == H2F_MSG_HW_FENCE_INFO) 1098: process_hw_fence_ack(adreno_dev, rcvd); 1099: else 1100: gen8_receive_ack_async(adreno_dev, rcvd); 1101: break; 1102: case F2H_MSG_CONTEXT_BAD: 1103: if (gen8_hfi_queue_read(gmu, HFI_MSG_ID, 1104: (u32 *)adreno_dev->hwsched.ctxt_bad, 1105: HFI_MAX_MSG_SIZE) < 0) 1106: break; 1107: process_ctx_bad(adreno_dev); 1108: break; 1109: case F2H_MSG_TS_RETIRE: 1110: adreno_hwsched_log_profiling_info(adreno_dev, rcvd); 1111: adreno_scheduler_queue(adreno_dev); 1112: break; 1113: case F2H_MSG_SYNCOBJ_QUERY: 1114: gen8_trigger_syncobj_query(adreno_dev, rcvd); 1115: break; 1116: case F2H_MSG_GMU_CNTR_RELEASE: { 1117: struct hfi_gmu_cntr_release_cmd *cmd = 1118: (struct hfi_gmu_cntr_release_cmd *) rcvd; 1119: 1120: adreno_perfcounter_put(adreno_dev, 1121: cmd->group_id, cmd->countable, PERFCOUNTER_FLAG_KERNEL); 1122: MATCH LINES: 1735, 1741, 1744, 1747, 1748 1723: &pending_ack, gen8_hwsched_process_msgq); 1724: 1725: if (rc) 1726: goto done; 1727: 1728: rc = check_ack_failure(adreno_dev, &pending_ack); 1729: done: 1730: del_waiter(hfi, &pending_ack); 1731: 1732: return rc; 1733: } 1734: 1735: static int gen8_hfi_send_hw_fence_feature_ctrl(struct adreno_device *adreno_dev) 1736: { 1737: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1738: struct device *gmu_pdev_dev = GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)); 1739: int ret; 1740: 1741: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags)) 1742: return 0; 1743: 1744: ret = gen8_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_HW_FENCE, 1, 0); 1745: if (ret && (ret == -ENOENT)) { 1746: dev_err(gmu_pdev_dev, 1747: "GMU doesn't support HW_FENCE feature\n"); 1748: adreno_hwsched_deregister_hw_fence(adreno_dev); 1749: return 0; 1750: } 1751: 1752: return ret; 1753: } 1754: 1755: static int gen8_hfi_send_soft_reset_feature_ctrl(struct adreno_device *adreno_dev) 1756: { 1757: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1758: 1759: if (!test_bit(ADRENO_HWSCHED_GPU_SOFT_RESET, &hwsched->flags)) 1760: return 0; 1761: 1762: return gen8_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_SOFT_RESET, 1, 0); 1763: } 1764: 1765: static int gen8_hfi_send_fast_context_destroy_feature_ctrl(struct adreno_device *adreno_dev) 1766: { 1767: int ret; 1768: 1769: if (!ADRENO_FEATURE(adreno_dev, ADRENO_GMU_FAST_CONTEXT_DESTROY)) 1770: return 0; 1771: 1772: if (!gmu_core_capabilities_enabled(&KGSL_DEVICE(adreno_dev)->gmu_core.platform_caps, MATCH LINES: 2639 2627: if (gmu->log_stream_enable) 2628: gen8_hfi_send_set_value(adreno_dev, 2629: HFI_VALUE_LOG_STREAM_ENABLE, 0, 1); 2630: 2631: if (gmu->log_group_mask) 2632: gen8_hfi_send_set_value(adreno_dev, 2633: HFI_VALUE_LOG_GROUP, 0, gmu->log_group_mask); 2634: 2635: ret = gen8_hfi_send_core_fw_start(adreno_dev); 2636: if (ret) 2637: goto err; 2638: 2639: ret = gen8_hfi_send_hw_fence_feature_ctrl(adreno_dev); 2640: if (ret) 2641: goto err; 2642: 2643: ret = enable_preemption(adreno_dev); 2644: if (ret) 2645: goto err; 2646: 2647: ret = gen8_hfi_send_lpac_feature_ctrl(adreno_dev); 2648: if (ret) 2649: goto err; 2650: 2651: if (ADRENO_FEATURE(adreno_dev, ADRENO_AQE)) { 2652: ret = gen8_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_AQE, 1, 0); 2653: if (ret) 2654: goto err; 2655: } 2656: 2657: ret = gen8_hfi_send_soft_reset_feature_ctrl(adreno_dev); 2658: if (ret) 2659: goto err; 2660: 2661: ret = gen8_hfi_send_fast_context_destroy_feature_ctrl(adreno_dev); 2662: if (ret) 2663: goto err; MATCH LINES: 2899, 2901, 2908, 2918, 2919, 2920, 2930, 2936, 2942, 2944, 2946, 2954, 2967, 2976, 2978, 2998, 2999, 3008, 3009, 3011, 3012, 3015, 3016 2887: if (kthread_should_stop()) 2888: break; 2889: 2890: gen8_hwsched_process_msgq(adreno_dev); 2891: gmu_core_process_trace_data(KGSL_DEVICE(adreno_dev), 2892: gmu_pdev_dev, &device->gmu_core.trace); 2893: gen8_hwsched_process_dbgq(adreno_dev, true); 2894: } 2895: 2896: return 0; 2897: } 2898: 2899: static void gen8_hwsched_hw_fence_timeout(struct work_struct *work) 2900: { 2901: struct gen8_hwsched_hfi *hfi = container_of(work, struct gen8_hwsched_hfi, hw_fence_ws); 2902: struct gen8_hwsched_device *gen8_hw_dev = container_of(hfi, struct gen8_hwsched_device, 2903: hwsched_hfi); 2904: struct adreno_device *adreno_dev = &gen8_hw_dev->gen8_dev.adreno_dev; 2905: struct device *gmu_pdev_dev = GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)); 2906: u32 unack_count, ts; 2907: struct adreno_context *drawctxt = NULL; 2908: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 2909: bool fault; 2910: 2911: /* Check msgq one last time before recording a fault */ 2912: gen8_hwsched_process_msgq(adreno_dev); 2913: 2914: spin_lock(&hwf->lock); 2915: 2916: unack_count = hwf->unack_count; 2917: 2918: fault = test_bit(GEN8_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags) && 2919: test_bit(GEN8_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags) && 2920: (unack_count > MIN_HW_FENCE_UNACK_COUNT); 2921: 2922: drawctxt = hwf->defer_drawctxt; 2923: ts = hwf->defer_ts; 2924: 2925: spin_unlock(&hwf->lock); 2926: 2927: if (!fault) 2928: return; 2929: 2930: dev_err(gmu_pdev_dev, "Hardware fence unack(%d) timeout\n", unack_count); 2931: 2932: if (drawctxt) { 2933: struct kgsl_process_private *proc_priv = drawctxt->base.proc_priv; 2934: 2935: dev_err(gmu_pdev_dev, 2936: "Hardware fence got deferred for ctx:%d ts:%d pid:%d proc:%s\n", 2937: drawctxt->base.id, ts, pid_nr(proc_priv->pid), proc_priv->comm); 2938: } 2939: gen8_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 2940: } 2941: 2942: static void gen8_hwsched_hw_fence_timer(struct timer_list *t) 2943: { 2944: struct gen8_hwsched_hfi *hfi = kgsl_timer_container_of(hfi, t, hw_fence_timer); 2945: 2946: kgsl_schedule_work(&hfi->hw_fence_ws); 2947: } 2948: 2949: int gen8_hwsched_hfi_probe(struct adreno_device *adreno_dev) 2950: { 2951: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2952: struct platform_device *gmu_pdev = GMU_PDEV(KGSL_DEVICE(adreno_dev)); 2953: struct gen8_hwsched_hfi *hw_hfi = to_gen8_hwsched_hfi(adreno_dev); 2954: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 2955: 2956: gmu->hfi.irq = kgsl_request_irq(gmu_pdev, "hfi", NULL, -EINVAL, 2957: gen8_hwsched_hfi_handler, adreno_dev); 2958: 2959: if (gmu->hfi.irq < 0) 2960: return gmu->hfi.irq; 2961: 2962: hw_hfi->irq_mask = HFI_IRQ_MASK; 2963: 2964: rwlock_init(&hw_hfi->msglock); 2965: 2966: INIT_LIST_HEAD(&hw_hfi->msglist); 2967: INIT_LIST_HEAD(&hw_hfi->detached_hw_fence_list); 2968: 2969: init_waitqueue_head(&hw_hfi->f2h_wq); 2970: init_waitqueue_head(&hwf->unack_wq); 2971: 2972: spin_lock_init(&hwf->lock); 2973: 2974: mutex_init(&hw_hfi->msgq_mutex); 2975: 2976: INIT_WORK(&hw_hfi->hw_fence_ws, gen8_hwsched_hw_fence_timeout); 2977: 2978: timer_setup(&hw_hfi->hw_fence_timer, gen8_hwsched_hw_fence_timer, 0); 2979: 2980: return 0; 2981: } 2982: 2983: void gen8_hwsched_hfi_remove(struct adreno_device *adreno_dev) 2984: { 2985: struct gen8_hwsched_hfi *hw_hfi = to_gen8_hwsched_hfi(adreno_dev); 2986: 2987: if (hw_hfi->f2h_task) 2988: kthread_stop(hw_hfi->f2h_task); 2989: } 2990: 2991: static void init_gmu_context_queue(struct adreno_context *drawctxt) 2992: { 2993: struct kgsl_memdesc *md = &drawctxt->gmu_context_queue; 2994: struct gmu_context_queue_header *hdr = md->hostptr; 2995: 2996: hdr->start_addr = md->gmuaddr + sizeof(*hdr); 2997: hdr->queue_size = (md->size - sizeof(*hdr)) >> 2; 2998: hdr->hw_fence_buffer_va = drawctxt->gmu_hw_fence_queue.gmuaddr; 2999: hdr->hw_fence_buffer_size = drawctxt->gmu_hw_fence_queue.size; 3000: } 3001: 3002: static int allocate_context_queues(struct adreno_device *adreno_dev, 3003: struct adreno_context *drawctxt) 3004: { 3005: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3006: int ret = 0; 3007: 3008: if (test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags) && 3009: !drawctxt->gmu_hw_fence_queue.gmuaddr) { 3010: ret = gmu_core_alloc_kernel_block( 3011: device, &drawctxt->gmu_hw_fence_queue, 3012: HW_FENCE_QUEUE_SIZE, GMU_NONCACHED_KERNEL, 3013: IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV); 3014: if (ret) { 3015: memset(&drawctxt->gmu_hw_fence_queue, 0x0, 3016: sizeof(drawctxt->gmu_hw_fence_queue)); 3017: return ret; 3018: } 3019: } 3020: 3021: if (!drawctxt->gmu_context_queue.gmuaddr) { 3022: ret = gmu_core_alloc_kernel_block( 3023: device, &drawctxt->gmu_context_queue, 3024: SZ_4K, GMU_NONCACHED_KERNEL, 3025: IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV); 3026: if (ret) { 3027: memset(&drawctxt->gmu_context_queue, 0x0, 3028: sizeof(drawctxt->gmu_context_queue)); 3029: return ret; 3030: } 3031: init_gmu_context_queue(drawctxt); 3032: } 3033: 3034: return 0; 3035: } 3036: 3037: static int send_context_register(struct adreno_device *adreno_dev, 3038: struct kgsl_context *context) 3039: { 3040: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); MATCH LINES: 3087, 3088 3075: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3076: struct hfi_context_pointers_cmd cmd = {0}; 3077: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 3078: struct kgsl_process_private *proc_priv = drawctxt->base.proc_priv; 3079: struct kgsl_memdesc md = proc_priv->profile.md; 3080: int ret; 3081: 3082: ret = CMD_MSG_HDR(cmd, H2F_MSG_CONTEXT_POINTERS); 3083: if (ret) 3084: return ret; 3085: 3086: cmd.ctxt_id = context->id; 3087: cmd.sop_addr = MEMSTORE_ID_GPU_ADDR(device, context->id, soptimestamp); 3088: cmd.eop_addr = MEMSTORE_ID_GPU_ADDR(device, context->id, eoptimestamp); 3089: cmd.version = 1; 3090: cmd.dcvs_profile_addr = GMU_BUF_ADDR(md); 3091: if (context->user_ctxt_record) 3092: cmd.user_ctxt_record_addr = 3093: context->user_ctxt_record->memdesc.gpuaddr; 3094: 3095: cmd.gmu_context_queue_addr = drawctxt->gmu_context_queue.gmuaddr; 3096: 3097: return gen8_hfi_send_cmd_async(adreno_dev, &cmd, sizeof(cmd)); 3098: } 3099: 3100: static int hfi_context_register(struct adreno_device *adreno_dev, 3101: struct kgsl_context *context) 3102: { 3103: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3104: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 3105: struct kgsl_process_private *proc_priv = drawctxt->base.proc_priv; 3106: int ret; 3107: 3108: if (context->gmu_registered) 3109: return 0; 3110: 3111: ret = send_context_register(adreno_dev, context); 3112: if (ret) { MATCH LINES: 3202, 3204, 3205, 3207, 3212, 3214, 3220, 3223, 3224, 3227, 3231, 3234, 3238, 3239, 3242, 3256, 3263, 3266, 3267, 3269, 3270, 3272, 3276, 3278, 3283, 3284, 3287, 3288, 3290, 3291, 3292, 3299, 3303, 3305, 3315, 3318, 3322, 3325, 3327, 3328, 3333, 3341, 3342, 3345, 3348, 3352, 3355, 3357, 3361, 3366, 3367, 3369, 3373, 3376, 3379, 3381, 3382, 3386, 3390, 3391, 3399, 3400, 3401, 3402, 3405, 3409, 3411, 3414, 3417, 3420, 3424, 3425, 3429, 3433, 3434, 3437, 3438, 3444, 3445, 3447, 3450, 3454, 3459, 3460, 3462, 3468, 3470, 3472, 3473, 3476, 3480, 3486, 3492, 3496, 3506, 3511, 3513, 3516, 3521, 3524, 3525, 3527, 3528, 3531, 3533, 3534, 3537, 3543, 3549, 3552, 3553, 3558, 3560, 3561, 3569, 3570, 3572, 3573, 3575, 3576, 3577, 3582, 3583, 3584, 3591, 3593, 3597, 3604, 3608, 3612, 3614, 3617, 3623, 3630, 3633, 3638, 3640, 3646, 3647, 3650, 3653, 3656, 3660, 3665, 3668, 3670, 3672, 3675, 3678, 3679, 3684, 3685, 3688, 3693, 3694, 3696, 3697, 3701, 3704, 3708, 3709, 3713, 3718, 3719, 3722, 3726, 3727, 3728, 3730, 3734, 3739, 3744, 3745, 3746, 3748, 3751, 3759, 3766, 3767, 3770, 3773, 3774, 3777, 3778, 3780, 3785, 3786, 3791, 3799, 3802, 3831, 3837, 3841, 3866 3190: 3191: static u32 get_irq_bit(struct adreno_device *adreno_dev, struct kgsl_context *context) 3192: { 3193: if (adreno_is_preemption_enabled(adreno_dev)) 3194: return adreno_get_level(context); 3195: 3196: if (kgsl_context_is_lpac(context)) 3197: return 1; 3198: 3199: return 0; 3200: } 3201: 3202: static bool _is_kgsl_hw_fence_signaled(struct kgsl_drawobj_sync_hw_fence *hw_fence) 3203: { 3204: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)hw_fence->fence; 3205: struct kgsl_sync_timeline *ktimeline = kfence->parent; 3206: 3207: if (dma_fence_is_signaled_locked(&kfence->fence)) 3208: return true; 3209: 3210: /* 3211: * If we fail to get the context refcount that means this context is detached. 3212: * In that case, treat all hardware fences from detached context as signaled. 3213: */ 3214: if ((!hw_fence->context) && (!_kgsl_context_get(ktimeline->context))) 3215: return true; 3216: 3217: return false; 3218: } 3219: 3220: static void populate_kgsl_fence(struct kgsl_drawobj_sync_hw_fence *hw_fence, 3221: struct hfi_syncobj *obj) 3222: { 3223: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)hw_fence->fence; 3224: struct kgsl_sync_timeline *ktimeline = kfence->parent; 3225: unsigned long flags; 3226: 3227: obj->flags |= BIT(GMU_SYNCOBJ_FLAG_KGSL_FENCE_BIT); 3228: 3229: spin_lock_irqsave(&ktimeline->lock, flags); 3230: 3231: if (_is_kgsl_hw_fence_signaled(hw_fence)) 3232: obj->flags |= BIT(GMU_SYNCOBJ_FLAG_SIGNALED_BIT); 3233: else 3234: hw_fence->context = ktimeline->context; 3235: 3236: spin_unlock_irqrestore(&ktimeline->lock, flags); 3237: 3238: obj->ctxt_id = kfence->context_id; 3239: obj->seq_no = kfence->timestamp; 3240: } 3241: 3242: static int _submit_hw_fence(struct adreno_device *adreno_dev, 3243: struct kgsl_drawobj *drawobj, void *cmdbuf) 3244: { 3245: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 3246: int i; 3247: u32 cmd_sizebytes, seqnum; 3248: struct kgsl_drawobj_sync *syncobj = SYNCOBJ(drawobj); 3249: struct hfi_submit_syncobj *cmd; 3250: struct hfi_syncobj *obj = NULL; 3251: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3252: 3253: /* Add hfi_syncobj struct for sync object */ 3254: cmd_sizebytes = sizeof(*cmd) + 3255: (sizeof(struct hfi_syncobj) * 3256: syncobj->num_hw_fence); 3257: 3258: if (WARN_ON(cmd_sizebytes > HFI_MAX_MSG_SIZE)) 3259: return -EMSGSIZE; 3260: 3261: memset(cmdbuf, 0x0, cmd_sizebytes); 3262: cmd = cmdbuf; 3263: cmd->num_syncobj = syncobj->num_hw_fence; 3264: obj = (struct hfi_syncobj *)&cmd[1]; 3265: 3266: for (i = 0; i < syncobj->num_hw_fence; i++) { 3267: struct dma_fence *fence = syncobj->hw_fences[i].fence; 3268: 3269: if (is_kgsl_fence(fence)) { 3270: populate_kgsl_fence(&syncobj->hw_fences[i], obj); 3271: } else { 3272: int ret = kgsl_hw_fence_add_waiter(device, fence, 3273: &obj->hash_index); 3274: 3275: if (ret) { 3276: adreno_hwsched_syncobj_kfence_put(syncobj); 3277: clear_bit(KGSL_SYNCOBJ_HW, &syncobj->flags); 3278: drawobj->timestamp = 0; 3279: clear_bit(KGSL_SYNCOBJ_HW_TS, &syncobj->flags); 3280: return ret; 3281: } 3282: 3283: if (kgsl_hw_fence_signaled(fence) || 3284: test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) 3285: obj->flags |= BIT(GMU_SYNCOBJ_FLAG_SIGNALED_BIT); 3286: 3287: obj->ctxt_id = fence->context; 3288: obj->seq_no = fence->seqno; 3289: } 3290: trace_adreno_input_hw_fence(drawobj->context->id, obj->ctxt_id, 3291: obj->seq_no, obj->flags, fence->ops->get_timeline_name ? 3292: fence->ops->get_timeline_name(fence) : "unknown"); 3293: 3294: obj->header = FIELD_PREP(GENMASK(15, 0), sizeof(*obj) >> 2); 3295: obj++; 3296: } 3297: 3298: /* 3299: * Attach a timestamp to this SYNCOBJ to keep track whether GMU has deemed it signaled 3300: * or not. 3301: */ 3302: if (!test_and_set_bit(KGSL_SYNCOBJ_HW_TS, &syncobj->flags)) 3303: drawobj->timestamp = ++drawctxt->syncobj_timestamp; 3304: 3305: cmd->timestamp = drawobj->timestamp; 3306: 3307: cmd->hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_SYNCOBJ, HFI_MSG_CMD); 3308: seqnum = atomic_inc_return(&adreno_dev->hwsched.submission_seqnum); 3309: cmd->hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd->hdr, seqnum, cmd_sizebytes >> 2); 3310: 3311: return adreno_gmu_context_queue_write(adreno_dev, &drawctxt->gmu_context_queue, 3312: (u32 *)cmd, cmd_sizebytes, drawobj, NULL); 3313: } 3314: 3315: int gen8_hwsched_check_context_inflight_hw_fences(struct adreno_device *adreno_dev, 3316: struct adreno_context *drawctxt) 3317: { 3318: struct adreno_hw_fence_entry *entry, *tmp; 3319: int ret = 0; 3320: 3321: spin_lock(&drawctxt->lock); 3322: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 3323: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 3324: 3325: if (timestamp_cmp((u32)entry->cmd.ts, hdr->out_fence_ts) > 0) { 3326: dev_err(GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)), 3327: "ctx:%d has unsignaled fence ts:%d retired:%d\n", 3328: drawctxt->base.id, (u32)entry->cmd.ts, hdr->out_fence_ts); 3329: ret = -EINVAL; 3330: break; 3331: } 3332: 3333: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 3334: } 3335: spin_unlock(&drawctxt->lock); 3336: 3337: return ret; 3338: } 3339: 3340: /** 3341: * move_detached_context_hardware_fences - Move all pending hardware fences belonging to this 3342: * context to the detached hardware fence list so as to send them to TxQueue after fault recovery. 3343: * This is needed because this context may get destroyed before fault recovery gets executed. 3344: */ 3345: static void move_detached_context_hardware_fences(struct adreno_device *adreno_dev, 3346: struct adreno_context *drawctxt) 3347: { 3348: struct adreno_hw_fence_entry *entry, *tmp; 3349: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 3350: 3351: spin_lock(&drawctxt->lock); 3352: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 3353: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 3354: 3355: if ((timestamp_cmp((u32)entry->cmd.ts, hdr->out_fence_ts) > 0)) { 3356: _kgsl_context_get(&drawctxt->base); 3357: list_move_tail(&entry->node, &hfi->detached_hw_fence_list); 3358: continue; 3359: } 3360: 3361: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 3362: } 3363: 3364: spin_unlock(&drawctxt->lock); 3365: 3366: /* Also grab all the hardware fences which were never sent to GMU */ 3367: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_list, node) { 3368: _kgsl_context_get(&drawctxt->base); 3369: list_move_tail(&entry->node, &hfi->detached_hw_fence_list); 3370: } 3371: } 3372: 3373: static int drain_context_hw_fence_gmu(struct adreno_device *adreno_dev, 3374: struct adreno_context *drawctxt) 3375: { 3376: struct adreno_hw_fence_entry *entry, *tmp; 3377: int ret = 0; 3378: 3379: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_list, node) { 3380: 3381: ret = gen8_send_hw_fence_hfi_wait_ack(adreno_dev, entry, 3382: HW_FENCE_FLAG_SKIP_MEMSTORE); 3383: if (ret) 3384: break; 3385: 3386: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 3387: } 3388: 3389: if (ret) { 3390: move_detached_context_hardware_fences(adreno_dev, drawctxt); 3391: gmu_core_fault_snapshot(KGSL_DEVICE(adreno_dev), GMU_FAULT_HW_FENCE); 3392: gen8_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 3393: } 3394: 3395: return ret; 3396: } 3397: 3398: /** 3399: * check_detached_context_hardware_fences - When this context has been un-registered with the GMU, 3400: * make sure all the hardware fences(that were sent to GMU) for this context have been sent to 3401: * TxQueue. Also, send any hardware fences (to GMU) that were not yet dispatched to the GMU. In case 3402: * of an error, move the pending hardware fences to detached hardware fence list, log the error, 3403: * take a snapshot and trigger recovery. 3404: */ 3405: static int check_detached_context_hardware_fences(struct adreno_device *adreno_dev, 3406: struct adreno_context *drawctxt) 3407: { 3408: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3409: struct adreno_hw_fence_entry *entry, *tmp; 3410: int ret = 0; 3411: u32 id, ts, fence_ts; 3412: 3413: spin_lock(&drawctxt->lock); 3414: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 3415: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 3416: 3417: if ((timestamp_cmp((u32)entry->cmd.ts, hdr->out_fence_ts) > 0)) { 3418: id = drawctxt->base.id; 3419: ts = (u32)entry->cmd.ts; 3420: fence_ts = hdr->out_fence_ts; 3421: spin_unlock(&drawctxt->lock); 3422: 3423: dev_err(GMU_PDEV_DEV(device), 3424: "detached ctx:%d has unsignaled fence ts:%d retired:%d\n", 3425: id, ts, fence_ts); 3426: ret = -EINVAL; 3427: goto fault; 3428: } 3429: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 3430: } 3431: 3432: spin_unlock(&drawctxt->lock); 3433: /* Send hardware fences (to TxQueue) that were not dispatched to GMU */ 3434: return drain_context_hw_fence_gmu(adreno_dev, drawctxt); 3435: 3436: fault: 3437: move_detached_context_hardware_fences(adreno_dev, drawctxt); 3438: gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE); 3439: gen8_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 3440: 3441: return ret; 3442: } 3443: 3444: static inline int setup_hw_fence_info_cmd(struct adreno_device *adreno_dev, 3445: struct adreno_hw_fence_entry *entry) 3446: { 3447: struct kgsl_sync_fence *kfence = entry->kfence; 3448: int ret; 3449: 3450: ret = CMD_MSG_HDR(entry->cmd, H2F_MSG_HW_FENCE_INFO); 3451: if (ret) 3452: return ret; 3453: 3454: ret = kgsl_hw_fence_create(KGSL_DEVICE(adreno_dev), kfence); 3455: if (ret) 3456: return ret; 3457: 3458: entry->cmd.gmu_ctxt_id = entry->drawctxt->base.id; 3459: entry->cmd.ctxt_id = kfence->fence.context; 3460: entry->cmd.ts = kfence->fence.seqno; 3461: 3462: entry->cmd.hash_index = kfence->hw_fence_index; 3463: 3464: return 0; 3465: } 3466: 3467: /* 3468: * gen8_send_hw_fence_hfi_wait_ack - This function is used in cases where multiple hardware fences 3469: * are to be sent to GMU. Hence, we must send them one by one to avoid overwhelming the GMU with 3470: * mutliple fences in a short span of time. 3471: */ 3472: int gen8_send_hw_fence_hfi_wait_ack(struct adreno_device *adreno_dev, 3473: struct adreno_hw_fence_entry *entry, u64 flags) 3474: { 3475: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3476: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3477: int ret = 0; 3478: u32 seqnum; 3479: 3480: /* Device mutex is necessary to ensure only one hardware fence ack is being waited for */ 3481: if (WARN_ON(!kgsl_mutex_is_locked(&device->mutex))) 3482: return -EINVAL; 3483: 3484: spin_lock(&hwf->lock); 3485: 3486: init_completion(&gen8_hw_fence_ack.complete); 3487: 3488: entry->cmd.flags |= flags; 3489: seqnum = atomic_inc_return(&hwf->seqnum); 3490: entry->cmd.hdr = MSG_HDR_SET_SEQNUM_SIZE(entry->cmd.hdr, seqnum, sizeof(entry->cmd) >> 2); 3491: 3492: gen8_hw_fence_ack.sent_hdr = entry->cmd.hdr; 3493: 3494: /* 3495: * We don't need to increment the unack count here as we are waiting for the ack for 3496: * this fence before sending another hardware fence. 3497: */ 3498: ret = gen8_hfi_cmdq_write(adreno_dev, (u32 *)&entry->cmd, sizeof(entry->cmd)); 3499: 3500: spin_unlock(&hwf->lock); 3501: 3502: if (ret) 3503: goto done; 3504: 3505: ret = adreno_hwsched_wait_ack_completion(adreno_dev, 3506: GMU_PDEV_DEV(device), &gen8_hw_fence_ack, 3507: gen8_hwsched_process_msgq); 3508: if (ret) 3509: goto done; 3510: 3511: ret = _check_hw_fence_ack_failure(device, gen8_hw_fence_ack.results); 3512: if (ret) 3513: gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE); 3514: 3515: done: 3516: memset(&gen8_hw_fence_ack, 0x0, sizeof(gen8_hw_fence_ack)); 3517: return ret; 3518: } 3519: 3520: #define DRAWCTXT_SLOT_AVAILABLE(count) \ 3521: ((count + 1) < (HW_FENCE_QUEUE_SIZE / sizeof(struct hfi_hw_fence_info))) 3522: 3523: /** 3524: * allocate_hw_fence_entry - Allocate an entry to keep track of a hardware fence. This is free'd 3525: * when we know GMU has sent this fence to the TxQueue 3526: */ 3527: static struct adreno_hw_fence_entry *allocate_hw_fence_entry(struct adreno_device *adreno_dev, 3528: struct adreno_context *drawctxt, struct kgsl_sync_fence *kfence) 3529: { 3530: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3531: struct adreno_hw_fence_entry *entry; 3532: 3533: if (!kgsl_hw_fence_tx_slot_available(KGSL_DEVICE(adreno_dev), 3534: hwsched->hw_fence.pending_count)) 3535: return NULL; 3536: 3537: if (!DRAWCTXT_SLOT_AVAILABLE(drawctxt->hw_fence_count)) 3538: return NULL; 3539: 3540: if (!_kgsl_context_get(&drawctxt->base)) 3541: return NULL; 3542: 3543: entry = kmem_cache_zalloc(hwsched->hw_fence_cache, GFP_ATOMIC); 3544: if (!entry) { 3545: kgsl_context_put_deferred(&drawctxt->base); 3546: return NULL; 3547: } 3548: 3549: entry->kfence = kfence; 3550: entry->drawctxt = drawctxt; 3551: 3552: if (setup_hw_fence_info_cmd(adreno_dev, entry)) { 3553: kmem_cache_free(hwsched->hw_fence_cache, entry); 3554: kgsl_context_put_deferred(&drawctxt->base); 3555: return NULL; 3556: } 3557: 3558: dma_fence_get(&kfence->fence); 3559: 3560: drawctxt->hw_fence_count++; 3561: hwsched->hw_fence.pending_count++; 3562: 3563: INIT_LIST_HEAD(&entry->node); 3564: INIT_LIST_HEAD(&entry->reset_node); 3565: return entry; 3566: } 3567: 3568: /** 3569: * drawctxt_queue_hw_fence - Add a hardware fence to draw context's hardware fence list and make 3570: * sure the list remains sorted (with the fence with the largest timestamp at the end) 3571: */ 3572: static void drawctxt_queue_hw_fence(struct adreno_device *adreno_dev, 3573: struct adreno_context *drawctxt, struct kgsl_sync_fence *kfence) 3574: { 3575: struct adreno_hw_fence_entry *entry = NULL; 3576: struct adreno_hw_fence_entry *new = allocate_hw_fence_entry(adreno_dev, drawctxt, kfence); 3577: u32 ts = kfence->timestamp; 3578: 3579: if (!new) 3580: return; 3581: 3582: /* Walk the list backwards to find the right spot for this fence */ 3583: list_for_each_entry_reverse(entry, &drawctxt->hw_fence_list, node) { 3584: if (timestamp_cmp(ts, (u32)entry->cmd.ts) > 0) 3585: break; 3586: } 3587: 3588: list_add(&new->node, &entry->node); 3589: } 3590: 3591: static bool _hw_fence_end_sleep(struct adreno_device *adreno_dev) 3592: { 3593: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3594: bool ret; 3595: 3596: spin_lock(&hwf->lock); 3597: ret = !test_bit(GEN8_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags); 3598: spin_unlock(&hwf->lock); 3599: 3600: return ret; 3601: } 3602: 3603: /** 3604: * _hw_fence_sleep() - Check if the thread needs to sleep until the hardware fence unack count 3605: * drops to a desired threshold. 3606: * 3607: * Return: negative error code if the thread was woken up by a signal, or the context became bad in 3608: * the meanwhile, or the hardware fence unack count hasn't yet dropped to a desired threshold, or 3609: * if fault recovery is imminent. 3610: * Otherwise, return 0. 3611: */ 3612: static int _hw_fence_sleep(struct adreno_device *adreno_dev, struct adreno_context *drawctxt) 3613: { 3614: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3615: int ret = 0; 3616: 3617: if (!test_bit(GEN8_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags)) 3618: return 0; 3619: 3620: spin_unlock(&hwf->lock); 3621: spin_unlock(&drawctxt->lock); 3622: 3623: ret = wait_event_interruptible(hwf->unack_wq, _hw_fence_end_sleep(adreno_dev)); 3624: 3625: spin_lock(&drawctxt->lock); 3626: spin_lock(&hwf->lock); 3627: 3628: /* 3629: * If the thread received a signal, or the context became bad in the meanwhile or the limit 3630: * is still not settled, then return error to avoid creating this hardware fence 3631: */ 3632: if ((ret == -ERESTARTSYS) || kgsl_context_is_bad(&drawctxt->base) || 3633: test_bit(GEN8_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags)) 3634: return -EINVAL; 3635: 3636: /* 3637: * If fault recovery is imminent then return error code to avoid creating new hardware 3638: * fences until recovery is complete 3639: */ 3640: if (test_bit(GEN8_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags)) 3641: return -EBUSY; 3642: 3643: return ret; 3644: } 3645: 3646: void gen8_hwsched_create_hw_fence(struct adreno_device *adreno_dev, 3647: struct kgsl_sync_fence *kfence) 3648: { 3649: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3650: struct kgsl_sync_timeline *ktimeline = kfence->parent; 3651: struct kgsl_context *context = ktimeline->context; 3652: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 3653: struct adreno_hw_fence_entry *entry = NULL; 3654: /* Only allow a single log in a second */ 3655: static DEFINE_RATELIMIT_STATE(_rs, HZ, 1); 3656: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3657: u32 retired = 0; 3658: int ret = 0; 3659: bool destroy = false; 3660: u32 hw_fence_last_ts; 3661: 3662: spin_lock(&drawctxt->lock); 3663: spin_lock(&hwf->lock); 3664: 3665: hw_fence_last_ts = drawctxt->hw_fence_last_ts; 3666: 3667: /* 3668: * Only create hw fences if the timestamp is greater than timestamp of the last hw fence 3669: * that was created. Otherwise, we will hit a GMU assert as GMU doesn't expect duplicate 3670: * or out-of-order fences 3671: */ 3672: if (timestamp_cmp(hw_fence_last_ts, kfence->timestamp) >= 0) 3673: goto done; 3674: 3675: drawctxt->hw_fence_last_ts = kfence->timestamp; 3676: 3677: /* 3678: * If we create a hardware fence and this context is going away, we may never dispatch 3679: * this fence to the GMU. Hence, avoid creating a hardware fence if context is going away. 3680: */ 3681: if (kgsl_context_is_bad(context)) 3682: goto done; 3683: 3684: /* If recovery is imminent, then do not create a hardware fence */ 3685: if (test_bit(GEN8_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags)) 3686: goto done; 3687: 3688: ret = _hw_fence_sleep(adreno_dev, drawctxt); 3689: if (ret) 3690: goto done; 3691: 3692: /* 3693: * If this ts hasn't been submitted yet, then store it in the drawctxt hardware fence 3694: * list and return. This fence will be sent to GMU when this ts is dispatched to GMU. 3695: */ 3696: if (timestamp_cmp(kfence->timestamp, drawctxt->gmu_hw_fence_ready_ts) > 0) { 3697: drawctxt_queue_hw_fence(adreno_dev, drawctxt, kfence); 3698: goto done; 3699: } 3700: 3701: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, &retired); 3702: 3703: /* 3704: * Check if timestamp is retired. If we are in SLUMBER at this point, the timestamp is 3705: * guaranteed to be retired. This way, we don't need the device mutex to check the device 3706: * state explicitly. 3707: */ 3708: if (timestamp_cmp(retired, kfence->timestamp) >= 0) { 3709: kgsl_sync_timeline_signal(ktimeline, kfence->timestamp); 3710: goto done; 3711: } 3712: 3713: entry = allocate_hw_fence_entry(adreno_dev, drawctxt, kfence); 3714: if (!entry) 3715: goto done; 3716: 3717: /* 3718: * If timestamp is not retired then GMU must already be powered up. This is because SLUMBER 3719: * thread has to wait for hardware fence spinlock to make sure the hardware fence unack 3720: * count is zero. 3721: */ 3722: ret = _send_hw_fence_no_ack(adreno_dev, entry); 3723: if (ret) { 3724: if (__ratelimit(&_rs)) 3725: dev_err(GMU_PDEV_DEV(device), 3726: "hw fence for ctx:%d ts:%d ret:%d may not be destroyed\n", 3727: kfence->context_id, kfence->timestamp, ret); 3728: kgsl_hw_fence_destroy(kfence); 3729: destroy = true; 3730: drawctxt->hw_fence_last_ts = hw_fence_last_ts; 3731: goto done; 3732: } 3733: 3734: list_add_tail(&entry->node, &drawctxt->hw_fence_inflight_list); 3735: 3736: done: 3737: spin_unlock(&hwf->lock); 3738: if (destroy) 3739: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 3740: spin_unlock(&drawctxt->lock); 3741: } 3742: 3743: /** 3744: * setup_hw_fence_deferred_ctxt - The hardware fence(s) from this context couldn't be sent to the 3745: * GMU because the hardware fence unack count reached a threshold. Hence, setup this context such 3746: * that these hardware fences are sent to the GMU when the unack count drops to a desired threshold. 3747: */ 3748: static void setup_hw_fence_deferred_ctxt(struct adreno_device *adreno_dev, 3749: struct adreno_context *drawctxt, u32 ts) 3750: { 3751: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3752: 3753: if (!_kgsl_context_get(&drawctxt->base)) 3754: return; 3755: 3756: hwf->defer_drawctxt = drawctxt; 3757: hwf->defer_ts = ts; 3758: /* 3759: * Increment the active count so that device doesn't get powered off until this fence has 3760: * been sent to GMU 3761: */ 3762: adreno_active_count_get(adreno_dev); 3763: } 3764: 3765: /** 3766: * process_hw_fence_queue - This function walks the draw context's list of hardware fences 3767: * and sends the ones which have a timestamp less than or equal to the timestamp that just 3768: * got submitted to the GMU. 3769: */ 3770: static void process_hw_fence_queue(struct adreno_device *adreno_dev, 3771: struct adreno_context *drawctxt, u32 ts) 3772: { 3773: struct adreno_hw_fence_entry *entry = NULL, *next; 3774: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3775: int ret = 0; 3776: 3777: /* This list is sorted with smallest timestamp at head and highest timestamp at tail */ 3778: list_for_each_entry_safe(entry, next, &drawctxt->hw_fence_list, node) { 3779: 3780: if (timestamp_cmp((u32)entry->cmd.ts, ts) > 0) 3781: return; 3782: 3783: spin_lock(&hwf->lock); 3784: 3785: if (test_bit(GEN8_HWSCHED_HW_FENCE_MAX_BIT, &hwf->flags)) { 3786: setup_hw_fence_deferred_ctxt(adreno_dev, drawctxt, ts); 3787: spin_unlock(&hwf->lock); 3788: return; 3789: } 3790: 3791: ret = _send_hw_fence_no_ack(adreno_dev, entry); 3792: 3793: spin_unlock(&hwf->lock); 3794: 3795: if (ret) 3796: return; 3797: 3798: /* 3799: * A fence that is sent to GMU must be added to the drawctxt->hw_fence_inflight_list 3800: * so that we can keep track of when GMU sends it to the TxQueue 3801: */ 3802: list_move_tail(&entry->node, &drawctxt->hw_fence_inflight_list); 3803: } 3804: } 3805: 3806: int gen8_hwsched_submit_drawobj(struct adreno_device *adreno_dev, struct kgsl_drawobj *drawobj) 3807: { 3808: int ret = 0; 3809: u32 cmd_sizebytes, seqnum; 3810: struct kgsl_drawobj_cmd *cmdobj = NULL; 3811: struct hfi_submit_cmd *cmd; 3812: struct adreno_submit_time time = {0}; 3813: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 3814: static void *cmdbuf; 3815: struct gmu_context_queue_header *hdr = NULL; 3816: 3817: if (cmdbuf == NULL) { 3818: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3819: 3820: cmdbuf = devm_kzalloc(&device->pdev->dev, HFI_MAX_MSG_SIZE, 3821: GFP_KERNEL); 3822: if (!cmdbuf) 3823: return -ENOMEM; 3824: } 3825: 3826: ret = hfi_context_register(adreno_dev, drawobj->context); 3827: if (ret) 3828: return ret; 3829: 3830: if ((drawobj->type & SYNCOBJ_TYPE) != 0) 3831: return _submit_hw_fence(adreno_dev, drawobj, cmdbuf); 3832: 3833: cmdobj = CMDOBJ(drawobj); 3834: 3835: /* 3836: * If the MARKER object is retired, it doesn't need to be dispatched to GMU. Simply trigger 3837: * any pending fences that are less than/equal to this object's timestamp. 3838: */ 3839: if (test_bit(CMDOBJ_MARKER_EXPIRED, &cmdobj->priv)) { 3840: spin_lock(&drawctxt->lock); 3841: process_hw_fence_queue(adreno_dev, drawctxt, drawobj->timestamp); 3842: spin_unlock(&drawctxt->lock); 3843: return 0; 3844: } 3845: 3846: /* Add a *issue_ib struct for each IB */ 3847: if (cmdobj->numibs > HWSCHED_MAX_DISPATCH_NUMIBS || 3848: test_bit(CMDOBJ_SKIP, &cmdobj->priv)) 3849: cmd_sizebytes = sizeof(*cmd); 3850: else 3851: cmd_sizebytes = sizeof(*cmd) + 3852: (sizeof(struct hfi_issue_ib) * cmdobj->numibs); 3853: 3854: if (WARN_ON(cmd_sizebytes > HFI_MAX_MSG_SIZE)) 3855: return -EMSGSIZE; 3856: 3857: memset(cmdbuf, 0x0, cmd_sizebytes); 3858: 3859: cmd = cmdbuf; 3860: 3861: cmd->ctxt_id = drawobj->context->id; 3862: cmd->flags = HFI_CTXT_FLAG_NOTIFY; 3863: if (drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME) 3864: cmd->flags |= CMDBATCH_EOF; 3865: 3866: cmd->ts = drawobj->timestamp; 3867: 3868: if (test_bit(CMDOBJ_SKIP, &cmdobj->priv)) 3869: goto skipib; 3870: 3871: populate_ibs(adreno_dev, cmd, cmdobj); 3872: 3873: if ((drawobj->flags & KGSL_DRAWOBJ_PROFILING) && 3874: cmdobj->profiling_buf_entry) { 3875: 3876: time.drawobj = drawobj; 3877: 3878: cmd->profile_gpuaddr_lo = 3879: lower_32_bits(cmdobj->profiling_buffer_gpuaddr); 3880: cmd->profile_gpuaddr_hi = 3881: upper_32_bits(cmdobj->profiling_buffer_gpuaddr); 3882: 3883: /* Indicate to GMU to do user profiling for this submission */ 3884: cmd->flags |= CMDBATCH_PROFILING; 3885: } 3886: 3887: if (test_and_clear_bit(CMDOBJ_NOP_SUBMISSION, &cmdobj->priv)) 3888: cmd->flags |= CMDBATCH_NOP_SUBMISSION; 3889: 3890: if (drawobj->flags & KGSL_DRAWOBJ_USES_MALU) MATCH LINES: 3906, 3914, 3917, 3919, 3920, 3923 3894: 3895: cmd->hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_CMD, HFI_MSG_CMD); 3896: seqnum = atomic_inc_return(&adreno_dev->hwsched.submission_seqnum); 3897: cmd->hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd->hdr, seqnum, cmd_sizebytes >> 2); 3898: 3899: ret = adreno_gmu_context_queue_write(adreno_dev, &drawctxt->gmu_context_queue, 3900: (u32 *)cmd, cmd_sizebytes, drawobj, &time); 3901: if (ret) 3902: return ret; 3903: 3904: hdr = drawctxt->gmu_context_queue.hostptr; 3905: /* The last sync object has been retired by the GMU */ 3906: if (timestamp_cmp(hdr->sync_obj_ts, drawctxt->syncobj_timestamp) >= 0) 3907: /* Send interrupt to GMU to receive the message */ 3908: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN8_GMUCX_HOST2GMU_INTR_SET, 3909: DISPQ_IRQ_BIT(get_irq_bit(adreno_dev, drawobj->context))); 3910: else 3911: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), GEN8_GMUCX_HOST2GMU_INTR_SET, 3912: DISPQ_SYNC_IRQ_BIT(get_irq_bit(adreno_dev, drawobj->context))); 3913: 3914: drawctxt->internal_timestamp = drawobj->timestamp; 3915: 3916: spin_lock(&drawctxt->lock); 3917: process_hw_fence_queue(adreno_dev, drawctxt, drawobj->timestamp); 3918: /* 3919: * We need to update the gmu_hw_fence_ready_ts while holding the drawctxt lock since we 3920: * have to check it in the hardware fence creation path, where we are not taking the 3921: * device mutex. 3922: */ 3923: drawctxt->gmu_hw_fence_ready_ts = drawobj->timestamp; 3924: spin_unlock(&drawctxt->lock); 3925: 3926: return 0; 3927: } 3928: 3929: int gen8_hwsched_send_recurring_cmdobj(struct adreno_device *adreno_dev, 3930: struct kgsl_drawobj_cmd *cmdobj) 3931: { 3932: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3933: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 3934: struct hfi_submit_cmd *cmd; 3935: struct kgsl_memobj_node *ib; 3936: u32 cmd_sizebytes; 3937: int ret; 3938: static bool active; 3939: 3940: if (adreno_gpu_halt(adreno_dev) || adreno_gpu_fault(adreno_dev)) 3941: return -EBUSY; 3942: 3943: if (test_bit(CMDOBJ_RECURRING_STOP, &cmdobj->priv)) { 3944: cmdobj->numibs = 0; 3945: } else { 3946: list_for_each_entry(ib, &cmdobj->cmdlist, node) 3947: cmdobj->numibs++; MATCH LINES: 4018, 4019, 4022, 4025, 4030, 4032, 4034, 4041, 4044, 4048, 4051, 4054, 4056, 4057, 4059, 4064, 4069, 4071, 4075, 4077, 4085, 4086, 4090, 4092, 4097, 4103, 4104, 4110, 4134 4006: if (active) 4007: adreno_active_count_put(adreno_dev); 4008: active = false; 4009: return ret; 4010: } 4011: 4012: hwsched->recurring_cmdobj = cmdobj; 4013: /* Star LSR timer for power stats collection */ 4014: mod_timer(&hwsched->lsr_timer, jiffies + msecs_to_jiffies(10)); 4015: return ret; 4016: } 4017: 4018: /* We don't want to unnecessarily wake the GMU to trigger hardware fences */ 4019: static void drain_context_hw_fence_cpu(struct adreno_device *adreno_dev, 4020: struct adreno_context *drawctxt) 4021: { 4022: struct adreno_hw_fence_entry *entry, *tmp; 4023: 4024: /* 4025: * Triggering these fences from HLOS may send interrupts to soccp. Hence, vote for soccp 4026: * here 4027: */ 4028: gen8_hwsched_soccp_vote(adreno_dev, true); 4029: 4030: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_list, node) { 4031: 4032: kgsl_hw_fence_trigger_cpu(KGSL_DEVICE(adreno_dev), entry->kfence); 4033: 4034: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 4035: } 4036: 4037: gen8_hwsched_soccp_vote(adreno_dev, false); 4038: } 4039: 4040: /* 4041: * destroy_detached_context_inflight_hw_fences - Destroy context's hardware fences that were 4042: * dispatched to GMU 4043: */ 4044: static void destroy_detached_context_inflight_hw_fences(struct adreno_device *adreno_dev, 4045: struct adreno_context *drawctxt) 4046: { 4047: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 4048: struct adreno_hw_fence_entry *entry, *tmp; 4049: 4050: spin_lock(&drawctxt->lock); 4051: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 4052: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 4053: 4054: if ((timestamp_cmp((u32)entry->cmd.ts, hdr->out_fence_ts) > 0)) { 4055: dev_err_ratelimited(GMU_PDEV_DEV(device), 4056: "destroying detached ctx:%d unsignaled hw fence ts:%d retired:%d\n", 4057: drawctxt->base.id, (u32)entry->cmd.ts, hdr->out_fence_ts); 4058: } 4059: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 4060: } 4061: spin_unlock(&drawctxt->lock); 4062: } 4063: 4064: static void drain_context_hw_fences(struct adreno_device *adreno_dev, 4065: struct adreno_context *drawctxt) 4066: { 4067: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 4068: 4069: destroy_detached_context_inflight_hw_fences(adreno_dev, drawctxt); 4070: 4071: if (list_empty(&drawctxt->hw_fence_list)) 4072: return; 4073: 4074: if (test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 4075: drain_context_hw_fence_gmu(adreno_dev, drawctxt); 4076: else 4077: drain_context_hw_fence_cpu(adreno_dev, drawctxt); 4078: } 4079: 4080: static void trigger_context_unregister_fault(struct adreno_device *adreno_dev, 4081: struct adreno_context *drawctxt) 4082: { 4083: gmu_core_fault_snapshot(KGSL_DEVICE(adreno_dev), GMU_FAULT_CTX_UNREGISTER); 4084: 4085: /* Make sure we send all fences from this context to the TxQueue after recovery */ 4086: move_detached_context_hardware_fences(adreno_dev, drawctxt); 4087: gen8_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); 4088: } 4089: 4090: int gen8_hwsched_process_detached_hw_fences(struct adreno_device *adreno_dev) 4091: { 4092: struct adreno_hw_fence_entry *entry, *tmp; 4093: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 4094: struct kgsl_context *context = NULL; 4095: int ret = 0; 4096: 4097: list_for_each_entry_safe(entry, tmp, &hfi->detached_hw_fence_list, node) { 4098: 4099: /* 4100: * This is part of the reset sequence and any error in this path will be handled by 4101: * the caller. 4102: */ 4103: ret = gen8_send_hw_fence_hfi_wait_ack(adreno_dev, entry, 4104: HW_FENCE_FLAG_SKIP_MEMSTORE); 4105: if (ret) 4106: return ret; 4107: 4108: context = &entry->drawctxt->base; 4109: 4110: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 4111: 4112: kgsl_context_put(context); 4113: } 4114: 4115: return ret; 4116: } 4117: 4118: static int send_context_unregister_hfi(struct adreno_device *adreno_dev, 4119: struct kgsl_context *context, u32 ts) 4120: { 4121: struct device *gmu_pdev_dev = GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)); 4122: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 4123: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 4124: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 4125: struct pending_cmd pending_ack; 4126: struct hfi_unregister_ctxt_cmd cmd; 4127: struct kgsl_process_private *proc_priv = drawctxt->base.proc_priv; 4128: u32 seqnum; 4129: int ret; 4130: 4131: /* Only send HFI if device is not in SLUMBER */ 4132: if (!context->gmu_registered || 4133: !test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) { 4134: drain_context_hw_fences(adreno_dev, drawctxt); 4135: proc_priv->profile.gmu_registered = false; 4136: 4137: return 0; 4138: } 4139: 4140: ret = CMD_MSG_HDR(cmd, H2F_MSG_UNREGISTER_CONTEXT); 4141: if (ret) 4142: return ret; 4143: 4144: cmd.ctxt_id = context->id, 4145: cmd.ts = ts, 4146: 4147: /* 4148: * Although we know device is powered on, we can still enter SLUMBER 4149: * because the wait for ack below is done without holding the mutex. So 4150: * take an active count before releasing the mutex so as to avoid a 4151: * concurrent SLUMBER sequence while GMU is un-registering this context. 4152: */ 4153: ret = adreno_active_count_get(adreno_dev); 4154: if (ret) { 4155: trigger_context_unregister_fault(adreno_dev, drawctxt); 4156: return ret; 4157: } 4158: MATCH LINES: 4177, 4198, 4204, 4207, 4213, 4214, 4215, 4221, 4229, 4233 4165: trigger_context_unregister_fault(adreno_dev, drawctxt); 4166: goto done; 4167: } 4168: 4169: ret = adreno_hwsched_ctxt_unregister_wait_completion(adreno_dev, 4170: gmu_pdev_dev, context, &pending_ack, 4171: gen8_hwsched_process_msgq, &cmd); 4172: if (ret) { 4173: trigger_context_unregister_fault(adreno_dev, drawctxt); 4174: goto done; 4175: } 4176: 4177: ret = check_detached_context_hardware_fences(adreno_dev, drawctxt); 4178: if (!ret) 4179: ret = check_ack_failure(adreno_dev, &pending_ack); 4180: 4181: done: 4182: adreno_active_count_put(adreno_dev); 4183: del_waiter(hfi, &pending_ack); 4184: 4185: return ret; 4186: } 4187: 4188: void gen8_hwsched_context_detach(struct adreno_context *drawctxt) 4189: { 4190: struct kgsl_context *context = &drawctxt->base; 4191: struct kgsl_device *device = context->device; 4192: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4193: int ret = 0; 4194: 4195: kgsl_mutex_lock(&device->mutex); 4196: 4197: ret = send_context_unregister_hfi(adreno_dev, context, 4198: drawctxt->internal_timestamp); 4199: 4200: if (ret) 4201: goto out; 4202: 4203: kgsl_sharedmem_writel(device->memstore, 4204: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), drawctxt->timestamp); 4205: 4206: kgsl_sharedmem_writel(device->memstore, 4207: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), drawctxt->timestamp); 4208: 4209: adreno_profile_process_results(adreno_dev); 4210: context->gmu_registered = false; 4211: 4212: out: 4213: WARN_RATELIMIT(!list_empty(&drawctxt->hw_fence_list) || 4214: !list_empty(&drawctxt->hw_fence_inflight_list), 4215: "detached ctx:%u has active hw fences\n", 4216: context->id); 4217: 4218: kgsl_mutex_unlock(&device->mutex); 4219: } 4220: 4221: static int handle_hw_fences_after_soft_reset(struct adreno_device *adreno_dev, 4222: struct adreno_context *drawctxt) 4223: { 4224: int ret = 0; 4225: 4226: if (!drawctxt) 4227: return ret; 4228: 4229: ret = gen8_hwsched_process_detached_hw_fences(adreno_dev); 4230: if (ret) 4231: return ret; 4232: 4233: return gen8_hwsched_disable_hw_fence_throttle(adreno_dev); 4234: } 4235: 4236: static int gen8_hwsched_hfi_msg_reply(struct adreno_device *adreno_dev, 4237: enum hfi_msg_type msg, u32 hdr) 4238: { 4239: struct hfi_msg_ret_cmd out = {0}; 4240: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 4241: u32 seqnum; 4242: 4243: out.hdr = ACK_MSG_HDR(msg); 4244: seqnum = atomic_inc_return(&gmu->hfi.seqnum); 4245: out.hdr = MSG_HDR_SET_SEQNUM_SIZE(out.hdr, seqnum, sizeof(out) >> 2); 4246: out.error = GMU_SUCCESS; 4247: out.req_hdr = hdr; 4248: 4249: return gen8_hfi_cmdq_write(adreno_dev, (u32 *)&out, sizeof(out)); 4250: } 4251: 4252: static void _do_gbif_halt(struct kgsl_device *device, u32 reg, u32 ack_reg, 4253: u32 mask, u32 ack_mask, const char *client) 4254: { 4255: u32 ack; 4256: unsigned long t; 4257: MATCH LINES: 4372, 4377, 4382, 4383, 4386, 4387 4360: 4361: gen8_enable_gpu_irq(adreno_dev); 4362: 4363: ret = gen8_hwsched_boot_gpu(adreno_dev); 4364: if (ret) 4365: goto done; 4366: 4367: gen8_hwsched_raise_dispatch_interrupt(adreno_dev); 4368: 4369: if (ctx_guilty) { 4370: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 4371: 4372: ret = handle_hw_fences_after_soft_reset(adreno_dev, drawctxt); 4373: if (ret) 4374: goto done; 4375: 4376: ret = send_context_unregister_hfi(adreno_dev, context, 4377: drawctxt->internal_timestamp); 4378: if (ret) 4379: goto done; 4380: 4381: kgsl_sharedmem_writel(device->memstore, 4382: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 4383: drawctxt->timestamp); 4384: 4385: kgsl_sharedmem_writel(device->memstore, 4386: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 4387: drawctxt->timestamp); 4388: 4389: adreno_profile_process_results(adreno_dev); 4390: 4391: context->gmu_registered = false; 4392: } 4393: 4394: /* 4395: * At this point it is safe to assume that we recovered. Setting 4396: * this field allows us to take a new snapshot for the next failure 4397: * if we are prioritizing the first unrecoverable snapshot. 4398: */ 4399: if (device->snapshot) 4400: device->snapshot->recovered = true; 4401: 4402: device->reset_counter++; 4403: done: 4404: if (ret) 4405: dev_err(device->dev, "GPU soft reset failed: %d\n", ret); 4406: 4407: return ret; 4408: } 4409: 4410: u32 gen8_hwsched_preempt_count_get(struct adreno_device *adreno_dev) 4411: { MATCH LINES: 4434, 4435, 4438, 4440, 4445, 4458, 4461, 4469 4422: 4423: return gen8_hwsched_hfi_get_value(adreno_dev, HFI_VALUE_PREEMPT_COUNT, 0); 4424: } 4425: 4426: void gen8_hwsched_context_destroy(struct adreno_device *adreno_dev, 4427: struct adreno_context *drawctxt) 4428: { 4429: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 4430: 4431: if (drawctxt->gmu_context_queue.gmuaddr) 4432: gmu_core_free_block(device, &drawctxt->gmu_context_queue); 4433: 4434: if (drawctxt->gmu_hw_fence_queue.gmuaddr) 4435: gmu_core_free_block(device, &drawctxt->gmu_hw_fence_queue); 4436: } 4437: 4438: int gen8_hwsched_disable_hw_fence_throttle(struct adreno_device *adreno_dev) 4439: { 4440: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 4441: struct adreno_context *drawctxt = NULL; 4442: u32 ts = 0; 4443: int ret = 0; 4444: 4445: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags)) 4446: return 0; 4447: 4448: spin_lock(&hwf->lock); 4449: 4450: drawctxt = hwf->defer_drawctxt; 4451: ts = hwf->defer_ts; 4452: 4453: spin_unlock(&hwf->lock); 4454: 4455: if (!drawctxt) 4456: goto done; 4457: 4458: ret = process_hw_fence_deferred_ctxt(adreno_dev, drawctxt, ts); 4459: if (ret) { 4460: /* the deferred drawctxt will be handled post fault recovery */ 4461: gen8_hwsched_fault(adreno_dev, GMU_FAULT_HW_FENCE); 4462: return ret; 4463: } 4464: 4465: kgsl_context_put(&drawctxt->base); 4466: adreno_active_count_put(adreno_dev); 4467: 4468: done: 4469: _disable_hw_fence_throttle(adreno_dev, true); 4470: 4471: return ret; 4472: } 4473: 4474: int gen8_hwsched_set_dcvs_profile(struct adreno_device *adreno_dev, 4475: struct kgsl_process_private *proc_priv) 4476: { 4477: struct hfi_profile_register cmd = {0}; 4478: struct hfi_msg_platform msg = {0}; 4479: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 4480: struct kgsl_memdesc md = proc_priv->profile.md; 4481: int ret; 4482: 4483: /* Only send HFI if device is not in SLUMBER */ 4484: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 4485: return 0; 4486: 4487: msg.sub_type = H2F_ST_MSG_PROFILE_REGISTER; 4488: CMD_MSG_HDR(msg, H2F_MSG_PLATFORM_LA); 4489: cmd.header = msg; 4490: cmd.version = 2; 4491: cmd.gmu_addr = GMU_BUF_ADDR(md); 4492: cmd.attrs_addr = md.gmuaddr; 4493: --- FILE: \adreno_gen8_hwsched_hfi.h | HITS: 43 --- MATCH LINES: 16, 18, 22, 25, 26, 27, 28, 29, 30, 31, 34, 37, 40 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #ifndef _ADRENO_GEN8_HWSCHED_HFI_H_ 8: #define _ADRENO_GEN8_HWSCHED_HFI_H_ 9: 10: /* Maximum number of IBs in a submission */ 11: #define HWSCHED_MAX_NUMIBS \ 12: ((HFI_MAX_MSG_SIZE - offsetof(struct hfi_issue_cmd_cmd, ibs)) \ 13: / sizeof(struct hfi_issue_ib)) 14: 15: /* 16: * This is used to put userspace threads to sleep when hardware fence unack count reaches a 17: * threshold. This bit is cleared in two scenarios: 18: * 1. If the hardware fence unack count drops to a desired threshold. 19: * 2. If there is a GMU/GPU fault. Because we don't want the threads to keep sleeping through fault 20: * recovery, which can easily take 100s of milliseconds to complete. 21: */ 22: #define GEN8_HWSCHED_HW_FENCE_SLEEP_BIT 0x0 23: 24: /* 25: * This is used to avoid creating any more hardware fences until the hardware fence unack count 26: * drops to a desired threshold. This bit is required in cases where GEN8_HWSCHED_HW_FENCE_SLEEP_BIT 27: * will be cleared, but we still want to avoid creating any more hardware fences. For example, if 28: * hardware fence unack count reaches a maximum threshold, both GEN8_HWSCHED_HW_FENCE_SLEEP_BIT and 29: * GEN8_HWSCHED_HW_FENCE_MAX_BIT will be set. Say, a GMU/GPU fault happens and 30: * GEN8_HWSCHED_HW_FENCE_SLEEP_BIT will be cleared to wake up any sleeping threads. But, 31: * GEN8_HWSCHED_HW_FENCE_MAX_BIT will remain set to avoid creating any new hardware fences until 32: * recovery is complete and deferred drawctxt (if any) is handled. 33: */ 34: #define GEN8_HWSCHED_HW_FENCE_MAX_BIT 0x1 35: 36: /* 37: * This is used to avoid creating any more hardware fences until concurrent reset/recovery completes 38: * or when soccp vote fails 39: */ 40: #define GEN8_HWSCHED_HW_FENCE_ABORT_BIT 0x2 41: 42: #define MAX_THROTTLE_LVLS 3 43: struct hfi_tsens_cfg { 44: /** @limit_u: deci-C value for upper trigger point */ 45: u32 limit_u; 46: /** @limit_l: deci-C value for lower trigger point */ 47: u32 limit_l; 48: /** @margin_u: deci-C value for upper trigger intercept margin */ 49: u32 margin_u; 50: /** @margin_l: deci-C value for lower trigger intercept margin */ 51: u32 margin_l; 52: } __packed; 53: 54: struct hfi_tsens_throttle_param { 55: /** @throttle_hyst: Microsecond wait between each throttle level */ 56: u32 throttle_hyst; 57: /** @num_throttle_cnt: Number of entries in throttle_levels */ 58: u32 num_throttle_cnt; 59: /** @throttle_lvls: Percent of original clock to throttle per level */ 60: u32 throttle_lvls[MAX_THROTTLE_LVLS]; 61: } __packed; 62: 63: struct hfi_therm_profile_ctrl { 64: /** @feature_en: Feature enable status */ MATCH LINES: 112, 115, 117, 119, 120, 121, 122, 123 100: struct list_head msglist; 101: /** @f2h_task: Task for processing gmu fw to host packets */ 102: struct task_struct *f2h_task; 103: /** @f2h_wq: Waitqueue for the f2h_task */ 104: wait_queue_head_t f2h_wq; 105: /** @big_ib: GMU buffer to hold big IBs */ 106: struct kgsl_memdesc *big_ib; 107: /** @big_ib_recurring: GMU buffer to hold big recurring IBs */ 108: struct kgsl_memdesc *big_ib_recurring; 109: /** @msg_mutex: Mutex for accessing the msgq */ 110: struct mutex msgq_mutex; 111: /** 112: * @hw_fence_timer: Timer to trigger fault if unack'd hardware fence count does'nt drop 113: * to a desired threshold in given amount of time 114: */ 115: struct timer_list hw_fence_timer; 116: /** 117: * @hw_fence_ws: Work struct that gets scheduled when hw_fence_timer expires 118: */ 119: struct work_struct hw_fence_ws; 120: /** @detached_hw_fences_list: List of hardware fences belonging to detached contexts */ 121: struct list_head detached_hw_fence_list; 122: /** @defer_hw_fence_work: The work structure to send deferred hardware fences to GMU */ 123: struct kthread_work defer_hw_fence_work; 124: }; 125: 126: struct kgsl_drawobj_cmd; 127: 128: /** 129: * gen8_hwsched_hfi_probe - Probe hwsched hfi resources 130: * @adreno_dev: Pointer to adreno device structure 131: * 132: * Return: 0 on success and negative error on failure. 133: */ 134: int gen8_hwsched_hfi_probe(struct adreno_device *adreno_dev); 135: 136: /** 137: * gen8_hwsched_hfi_remove - Release hwsched hfi resources 138: * @adreno_dev: Pointer to adreno device structure 139: */ 140: void gen8_hwsched_hfi_remove(struct adreno_device *adreno_dev); 141: 142: /** 143: * gen8_hwsched_hfi_init - Initialize hfi resources 144: * @adreno_dev: Pointer to adreno device structure 145: * 146: * This function is used to initialize hfi resources 147: * once before the very first gmu boot MATCH LINES: 297, 299, 300, 302, 306, 307, 310, 312, 314, 316, 317, 320, 321, 322, 328, 331, 336, 341, 345, 348, 349, 353 285: * @adreno_dev: Pointer to adreno device 286: * @type: Type of the property to set 287: * @subtype: Sub type of the property to set 288: * @data: Value to be set to the property 289: * 290: * This functions sends SET_VALUE HFI packet to set value of a property 291: * 292: * Return: On success, return 0. On failure, return error code 293: */ 294: int gen8_hwsched_hfi_set_value(struct adreno_device *adreno_dev, u32 type, u32 subtype, u32 data); 295: 296: /** 297: * gen8_send_hw_fence_hfi_wait_ack - Send hardware fence info to GMU 298: * @adreno_dev: Pointer to adreno device 299: * @entry: Pointer to the adreno hardware fence entry 300: * @flags: Flags for this hardware fence 301: * 302: * Send the hardware fence info to the GMU and wait for the ack 303: * 304: * Return: 0 on success or negative error on failure 305: */ 306: int gen8_send_hw_fence_hfi_wait_ack(struct adreno_device *adreno_dev, 307: struct adreno_hw_fence_entry *entry, u64 flags); 308: 309: /** 310: * gen8_hwsched_create_hw_fence - Create a hardware fence 311: * @adreno_dev: Pointer to adreno device 312: * @kfence: Pointer to the kgsl fence 313: * 314: * Create a hardware fence, set up hardware fence info and send it to GMU if required 315: */ 316: void gen8_hwsched_create_hw_fence(struct adreno_device *adreno_dev, 317: struct kgsl_sync_fence *kfence); 318: 319: /** 320: * gen8_hwsched_process_detached_hw_fences - Send fences that couldn't be sent to GMU when a context 321: * got detached. We must wait for ack when sending each of these fences to GMU so as to avoid 322: * sending a large number of hardware fences in a short span of time. 323: * @adreno_dev: Pointer to adreno device 324: * 325: * Return: Zero on success or negative error on failure 326: * 327: */ 328: int gen8_hwsched_process_detached_hw_fences(struct adreno_device *adreno_dev); 329: 330: /** 331: * gen8_hwsched_check_context_inflight_hw_fences - Check whether all hardware fences 332: * from a context have been sent to the TxQueue or not 333: * @adreno_dev: Pointer to adreno device 334: * @drawctxt: Pointer to the adreno context which is to be flushed 335: * 336: * Check if all hardware fences from this context have been sent to the 337: * TxQueue. If not, log an error and return error code. 338: * 339: * Return: Zero on success or negative error on failure 340: */ 341: int gen8_hwsched_check_context_inflight_hw_fences(struct adreno_device *adreno_dev, 342: struct adreno_context *drawctxt); 343: 344: /** 345: * gen8_hwsched_disable_hw_fence_throttle - Disable hardware fence throttling after reset 346: * @adreno_dev: pointer to the adreno device 347: * 348: * After device reset, clear hardware fence related data structures and send any hardware fences 349: * that got deferred (prior to reset) and re-open the gates for hardware fence creation 350: * 351: * Return: Zero on success or negative error on failure 352: */ 353: int gen8_hwsched_disable_hw_fence_throttle(struct adreno_device *adreno_dev); 354: 355: /** 356: * gen8_hwsched_process_msgq - Process msgq 357: * @adreno_dev: pointer to the adreno device 358: * 359: * This function grabs the msgq mutex and processes msgq for any outstanding hfi packets 360: */ 361: void gen8_hwsched_process_msgq(struct adreno_device *adreno_dev); 362: 363: /** 364: * gen8_hwsched_boot_gpu - Send the command to boot GPU 365: * @adreno_dev: Pointer to adreno device 366: * 367: * Send the hfi to boot GPU, and check the ack, incase of a failure 368: * get a snapshot and capture registers of interest. 369: * 370: * Return: Zero on success or negative error on failure 371: */ 372: int gen8_hwsched_boot_gpu(struct adreno_device *adreno_dev); 373: 374: /** 375: * gen8_hwsched_set_gmu_based_dcvs_value - Set value for GMU based DCVS 376: * @adreno_dev: pointer to the adreno device 377: * @type: Type of HFI for set value --- FILE: \adreno_gen8_preempt.c | HITS: 21 --- MATCH LINES: 36, 38 24: unsigned long flags; 25: int ret = 0; 26: 27: spin_lock_irqsave(&rb->preempt_lock, flags); 28: 29: if (!atomic) { 30: /* 31: * We might have skipped updating the wptr in case we are in 32: * dispatcher context. Do it now. 33: */ 34: if (rb->skip_inline_wptr) { 35: 36: ret = gen8_fenced_write(adreno_dev, 37: GEN8_CP_RB_WPTR_GC, rb->wptr, 38: FENCE_STATUS_WRITEDROPPED0_MASK); 39: 40: reset_timer = true; 41: rb->skip_inline_wptr = false; 42: } 43: } else { 44: u32 wptr; 45: 46: kgsl_regread(device, GEN8_CP_RB_WPTR_GC, &wptr); 47: if (wptr != rb->wptr) { 48: kgsl_regwrite(device, GEN8_CP_RB_WPTR_GC, rb->wptr); 49: reset_timer = true; 50: } 51: } 52: 53: if (reset_timer) 54: rb->dispatch_q.expires = jiffies + 55: msecs_to_jiffies(adreno_drawobj_timeout); 56: 57: spin_unlock_irqrestore(&rb->preempt_lock, flags); 58: 59: if (!atomic) { 60: /* If WPTR update fails, set the fault and trigger recovery */ 61: if (ret) { 62: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); MATCH LINES: 285, 286, 293, 296, 299, 303, 314, 317, 321, 324, 327, 330, 334, 337, 340, 343, 373, 374, 382 273: 274: kgsl_sharedmem_readq(preempt->scratch, &gpuaddr, 275: next->id * sizeof(u64)); 276: 277: /* 278: * Set a keepalive bit before the first preemption register write. 279: * This is required since while each individual write to the context 280: * switch registers will wake the GPU from collapse, it will not in 281: * itself cause GPU activity. Thus, the GPU could technically be 282: * re-collapsed between subsequent register writes leading to a 283: * prolonged preemption sequence. The keepalive bit prevents any 284: * further power collapse while it is set. 285: * It is more efficient to use a keepalive+wake-on-fence approach here 286: * rather than an OOB. Both keepalive and the fence are effectively 287: * free when the GPU is already powered on, whereas an OOB requires an 288: * unconditional handshake with the GMU. 289: */ 290: _power_collapse_set(adreno_dev, true); 291: 292: /* 293: * Fenced writes on this path will make sure the GPU is woken up 294: * in case it was power collapsed by the GMU. 295: */ 296: if (gen8_fenced_write(adreno_dev, 297: GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_LO, 298: lower_32_bits(next->preemption_desc->gpuaddr), 299: FENCE_STATUS_WRITEDROPPED1_MASK)) 300: goto err; 301: 302: /* 303: * Above fence writes will make sure GMU comes out of 304: * IFPC state if its was in IFPC state but it doesn't 305: * guarantee that GMU FW actually moved to ACTIVE state 306: * i.e. wake-up from IFPC is complete. 307: * Wait for GMU to move to ACTIVE state before triggering 308: * preemption. This is require to make sure CP doesn't 309: * interrupt GMU during wake-up from IFPC. 310: */ 311: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 312: goto err; 313: 314: if (gen8_fenced_write(adreno_dev, 315: GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_HI, 316: upper_32_bits(next->preemption_desc->gpuaddr), 317: FENCE_STATUS_WRITEDROPPED1_MASK)) 318: goto err; 319: 320: if (kgsl_mmu_is_secured(&device->mmu)) { 321: if (gen8_fenced_write(adreno_dev, 322: GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_LO, 323: lower_32_bits(next->secure_preemption_desc->gpuaddr), 324: FENCE_STATUS_WRITEDROPPED1_MASK)) 325: goto err; 326: 327: if (gen8_fenced_write(adreno_dev, 328: GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_HI, 329: upper_32_bits(next->secure_preemption_desc->gpuaddr), 330: FENCE_STATUS_WRITEDROPPED1_MASK)) 331: goto err; 332: } 333: 334: if (gen8_fenced_write(adreno_dev, 335: GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_LO, 336: lower_32_bits(gpuaddr), 337: FENCE_STATUS_WRITEDROPPED1_MASK)) 338: goto err; 339: 340: if (gen8_fenced_write(adreno_dev, 341: GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_HI, 342: upper_32_bits(gpuaddr), 343: FENCE_STATUS_WRITEDROPPED1_MASK)) 344: goto err; 345: 346: adreno_dev->next_rb = next; 347: 348: /* Start the timer to detect a stuck preemption */ 349: mod_timer(&adreno_dev->preempt.timer, 350: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 351: 352: cntl = (preempt->preempt_level << 6) | 0x01; 353: 354: /* Skip save/restore during L1 preemption */ 355: if (preempt->skipsaverestore) 356: cntl |= (1 << 9); 357: 358: /* Enable GMEM save/restore across preemption */ 359: if (preempt->usesgmem) 360: cntl |= (1 << 8); 361: 362: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 363: cntl, 0); 364: 365: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 366: 367: if (gen8_core->qos_value) 368: kgsl_sharedmem_writel(preempt->scratch, 369: PREEMPT_SCRATCH_OFFSET(QOS_VALUE_IDX), 370: gen8_core->qos_value[next->id]); 371: 372: /* Trigger the preemption */ 373: if (gen8_fenced_write(adreno_dev, GEN8_CP_CONTEXT_SWITCH_CNTL, cntl, 374: FENCE_STATUS_WRITEDROPPED1_MASK)) { 375: adreno_dev->next_rb = NULL; 376: kgsl_delete_timer(&adreno_dev->preempt.timer); 377: goto err; 378: } 379: 380: return; 381: err: 382: /* If fenced write fails, take inline snapshot and trigger recovery */ 383: if (!in_interrupt()) { 384: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 385: adreno_scheduler_fault(adreno_dev, 386: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 387: } else { 388: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 389: } 390: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 391: /* Clear the keep alive */ 392: _power_collapse_set(adreno_dev, false); 393: 394: } 395: 396: void gen8_preemption_callback(struct adreno_device *adreno_dev, int bit) 397: { 398: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 399: u32 status; 400: 401: if (!adreno_move_preempt_state(adreno_dev, 402: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 403: return; 404: 405: kgsl_regread(device, GEN8_CP_CONTEXT_SWITCH_CNTL, &status); 406: --- FILE: \adreno_gen8_ringbuffer.c | HITS: 38 --- MATCH LINES: 166, 167, 168, 169, 171, 172, 173, 174, 190, 192 154: u64 gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 155: 156: cmds[count++] = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 3); 157: cmds[count++] = SET_PSEUDO_NON_PRIV_SAVE_ADDR; 158: cmds[count++] = lower_32_bits(gpuaddr); 159: cmds[count++] = upper_32_bits(gpuaddr); 160: } 161: 162: return gen8_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED, 163: cmds, count, 0, NULL); 164: } 165: 166: #define RB_SOPTIMESTAMP(device, rb) \ 167: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 168: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 169: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 170: 171: #define RB_EOPTIMESTAMP(device, rb) \ 172: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 173: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 174: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 175: 176: int gen8_ringbuffer_submit(struct adreno_ringbuffer *rb, 177: struct adreno_submit_time *time) 178: { 179: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 180: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 181: int ret = 0; 182: unsigned long flags; 183: 184: adreno_get_submit_time(adreno_dev, rb, time); 185: adreno_profile_submit_time(time); 186: 187: spin_lock_irqsave(&rb->preempt_lock, flags); 188: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) { 189: if (adreno_dev->cur_rb == rb) { 190: ret = gen8_fenced_write(adreno_dev, 191: GEN8_CP_RB_WPTR_GC, rb->_wptr, 192: FENCE_STATUS_WRITEDROPPED0_MASK); 193: rb->skip_inline_wptr = false; 194: } 195: } else { 196: if (adreno_dev->cur_rb == rb) 197: rb->skip_inline_wptr = true; 198: } 199: 200: rb->wptr = rb->_wptr; 201: spin_unlock_irqrestore(&rb->preempt_lock, flags); 202: 203: if (ret) { 204: /* 205: * If WPTR update fails, take inline snapshot and trigger 206: * recovery. 207: */ 208: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 209: adreno_scheduler_fault(adreno_dev, 210: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 211: } 212: 213: return ret; 214: } 215: 216: int gen8_ringbuffer_init(struct adreno_device *adreno_dev) MATCH LINES: 254, 269, 272 242: if (ret) 243: return ret; 244: } 245: 246: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 247: return 0; 248: } 249: 250: #define GEN8_SUBMIT_MAX 104 251: 252: int gen8_ringbuffer_addcmds(struct adreno_device *adreno_dev, 253: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 254: u32 flags, u32 *in, u32 dwords, u32 timestamp, 255: struct adreno_submit_time *time) 256: { 257: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 258: u32 size = GEN8_SUBMIT_MAX + dwords; 259: u32 *cmds, index = 0; 260: u64 profile_gpuaddr; 261: u32 profile_dwords; 262: 263: if (adreno_drawctxt_detached(drawctxt)) 264: return -ENOENT; 265: 266: if (adreno_gpu_fault(adreno_dev) != 0) 267: return -EPROTO; 268: 269: rb->timestamp++; 270: 271: if (drawctxt) 272: drawctxt->internal_timestamp = rb->timestamp; 273: 274: /* All submissions are run with protected mode off due to APRIV */ 275: flags &= ~F_NOTPROTECTED; 276: 277: cmds = adreno_ringbuffer_allocspace(rb, size); 278: if (IS_ERR(cmds)) 279: return PTR_ERR(cmds); 280: 281: /* Identify the start of a command */ 282: cmds[index++] = cp_type7_packet(CP_NOP, 1); 283: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 284: 285: /* This is 25 dwords when drawctxt is not NULL and perfcounter needs to be zapped*/ 286: index += gen8_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 287: &cmds[index]); 288: 289: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 290: cmds[index++] = CP_SET_THREAD_BOTH; 291: 292: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 293: cmds[index++] = 0x101; /* IFPC disable */ 294: 295: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 296: cmds[index++] = CP_SET_THREAD_BR; MATCH LINES: 320, 322, 324, 328, 329, 330, 363, 370, 377, 380, 384, 388, 394, 395, 396, 400, 402, 404, 408, 409, 410 308: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 309: drawctxt, &profile_dwords); 310: 311: if (profile_gpuaddr) { 312: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 313: cmds[index++] = lower_32_bits(profile_gpuaddr); 314: cmds[index++] = upper_32_bits(profile_gpuaddr); 315: cmds[index++] = profile_dwords; 316: } 317: 318: if (drawctxt) { 319: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 320: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 321: drawctxt)); 322: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 323: drawctxt)); 324: cmds[index++] = timestamp; 325: } 326: 327: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 328: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 329: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); 330: cmds[index++] = rb->timestamp; 331: 332: if (IS_SECURE(flags)) { 333: /* Sync BV and BR if entering secure mode */ 334: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 335: cmds[index++] = CP_SYNC_THREADS | CP_CONCURRENT_BIN_DISABLE; 336: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 337: cmds[index++] = 1; 338: } 339: 340: memcpy(&cmds[index], in, dwords << 2); 341: index += dwords; 342: 343: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev, 344: drawctxt, &dwords); 345: 346: if (profile_gpuaddr) { 347: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 348: cmds[index++] = lower_32_bits(profile_gpuaddr); 349: cmds[index++] = upper_32_bits(profile_gpuaddr); 350: cmds[index++] = profile_dwords; 351: } 352: 353: if (test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &device->mmu.pfpolicy)) 354: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0); 355: 356: if (is_concurrent_binning(drawctxt)) { 357: u64 addr = SCRATCH_RB_GPU_ADDR(device, rb->id, bv_ts); 358: 359: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 360: cmds[index++] = CP_SET_THREAD_BV; 361: 362: /* 363: * Make sure the timestamp is committed once BV pipe is 364: * completely done with this submission. 365: */ 366: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 367: cmds[index++] = CACHE_CLEAN | BIT(27); 368: cmds[index++] = lower_32_bits(addr); 369: cmds[index++] = upper_32_bits(addr); 370: cmds[index++] = rb->timestamp; 371: 372: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 373: cmds[index++] = CP_SET_THREAD_BR; 374: 375: /* 376: * This makes sure that BR doesn't race ahead and commit 377: * timestamp to memstore while BV is still processing 378: * this submission. 379: */ 380: cmds[index++] = cp_type7_packet(CP_WAIT_TIMESTAMP, 4); 381: cmds[index++] = 0; 382: cmds[index++] = lower_32_bits(addr); 383: cmds[index++] = upper_32_bits(addr); 384: cmds[index++] = rb->timestamp; 385: } 386: 387: /* 388: * If this is an internal command, just write the ringbuffer timestamp, 389: * otherwise, write both 390: */ 391: if (!drawctxt) { 392: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 393: cmds[index++] = CACHE_CLEAN | BIT(31) | BIT(27); 394: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 395: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 396: cmds[index++] = rb->timestamp; 397: } else { 398: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 399: cmds[index++] = CACHE_CLEAN | BIT(31) | BIT(27); 400: cmds[index++] = lower_32_bits(CTXT_EOPTIMESTAMP(device, 401: drawctxt)); 402: cmds[index++] = upper_32_bits(CTXT_EOPTIMESTAMP(device, 403: drawctxt)); 404: cmds[index++] = timestamp; 405: 406: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 407: cmds[index++] = CACHE_CLEAN | BIT(27); 408: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 409: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 410: cmds[index++] = rb->timestamp; 411: } 412: 413: if (IS_WFI(flags)) 414: cmds[index++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 415: 416: if (IS_SECURE(flags)) { 417: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 418: cmds[index++] = CP_CONCURRENT_BIN_DISABLE; 419: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 420: cmds[index++] = 0; 421: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 422: cmds[index++] = CP_SYNC_THREADS; 423: } 424: 425: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 426: cmds[index++] = CP_SET_THREAD_BOTH; 427: 428: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 429: cmds[index++] = 0x100; /* IFPC enable */ 430: 431: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 432: cmds[index++] = CP_SET_THREAD_BR; 433: 434: /* 10 dwords */ MATCH LINES: 514, 515 502: if (!_kgsl_context_get(&drawctxt->base)) 503: return -ENOENT; 504: 505: ret = gen8_rb_context_switch(adreno_dev, rb, drawctxt); 506: if (ret) { 507: kgsl_context_put(&drawctxt->base); 508: return ret; 509: } 510: 511: trace_adreno_drawctxt_switch(rb, drawctxt); 512: 513: /* Release the current drawctxt as soon as the new one is switched */ 514: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active, 515: rb, rb->timestamp); 516: 517: rb->drawctxt_active = drawctxt; 518: return 0; 519: } 520: 521: 522: #define GEN8_USER_PROFILE_IB(rb, cmdobj, cmds, field) \ 523: gen8_get_user_profiling_ib((rb), (cmdobj), \ 524: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 525: (cmds)) 526: 527: #define GEN8_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 528: gen8_get_alwayson_counter((cmds), \ 529: (dev)->profile_buffer->gpuaddr + \ 530: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 531: field)) 532: 533: #define GEN8_KERNEL_PROFILE_CONTEXT(dev, cmdobj, cmds, field) \ 534: gen8_get_alwayson_context((cmds), \ 535: (dev)->profile_buffer->gpuaddr + \ 536: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 537: field)) 538: 539: #define GEN8_COMMAND_DWORDS 63 MATCH LINES: 662, 666 650: if (ret != -ENOSPC && ret != -ENOENT) 651: dev_err(device->dev, 652: "Unable to switch draw context: %d\n", ret); 653: goto done; 654: } 655: 656: adreno_drawobj_set_constraint(device, drawobj); 657: 658: if (drawobj->flags & KGSL_DRAWOBJ_USES_MALU) 659: flags |= F_MALU; 660: 661: ret = gen8_ringbuffer_addcmds(adreno_dev, drawctxt->rb, drawctxt, 662: flags, cmds, index, drawobj->timestamp, time); 663: 664: done: 665: trace_kgsl_issueibcmds(device, drawctxt->base.id, numibs, 666: drawobj->timestamp, drawobj->flags, ret, drawctxt->type); 667: 668: kvfree(cmds); 669: return ret; 670: } --- FILE: \adreno_hfi.h | HITS: 49 --- MATCH LINES: 11 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: #ifndef __ADRENO_HFI_H 7: #define __ADRENO_HFI_H 8: 9: #include "kgsl_util.h" 10: 11: #define HW_FENCE_QUEUE_SIZE SZ_4K 12: #define HFI_QUEUE_SIZE SZ_4K /* bytes, must be base 4dw */ 13: #define MAX_RCVD_PAYLOAD_SIZE 32 /* dwords */ 14: #define MAX_RCVD_SIZE (MAX_RCVD_PAYLOAD_SIZE + 3) /* dwords */ 15: #define HFI_MAX_MSG_SIZE (SZ_1K) 16: 17: #define HFI_CMD_ID 0 18: #define HFI_MSG_ID 1 19: #define HFI_DBG_ID 2 20: #define HFI_DSP_ID_0 3 21: 22: #define HFI_CMD_IDX 0 23: #define HFI_MSG_IDX 1 24: #define HFI_DBG_IDX 2 25: #define HFI_DSP_IDX_BASE 3 26: #define HFI_DSP_IDX_0 3 27: 28: #define HFI_CMD_IDX_LEGACY 0 29: #define HFI_DSP_IDX_0_LEGACY 1 30: #define HFI_MSG_IDX_LEGACY 4 31: #define HFI_DBG_IDX_LEGACY 5 32: 33: #define HFI_QUEUE_STATUS_DISABLED 0 34: #define HFI_QUEUE_STATUS_ENABLED 1 35: MATCH LINES: 77 65: #define HFI_FEATURE_ACD 12 66: #define HFI_FEATURE_DIDT 13 67: #define HFI_FEATURE_DEPRECATED 14 68: #define HFI_FEATURE_CB 15 69: #define HFI_FEATURE_KPROF 16 70: #define HFI_FEATURE_BAIL_OUT_TIMER 17 71: #define HFI_FEATURE_GMU_STATS 18 72: #define HFI_FEATURE_DBQ 19 73: #define HFI_FEATURE_MINBW 20 74: #define HFI_FEATURE_CLX 21 75: #define HFI_FEATURE_LSR 23 76: #define HFI_FEATURE_LPAC 24 77: #define HFI_FEATURE_HW_FENCE 25 78: #define HFI_FEATURE_PERF_NORETAIN 26 79: #define HFI_FEATURE_DMS 27 80: #define HFI_FEATURE_THERMAL 28 81: #define HFI_FEATURE_AQE 29 82: #define HFI_FEATURE_TDCVS 30 83: #define HFI_FEATURE_DCE 31 84: #define HFI_FEATURE_IFF_PCLX 32 85: #define HFI_FEATURE_SOFT_RESET 0x10000001 86: #define HFI_FEATURE_DCVS_PROFILE 0x10000002 87: #define HFI_FEATURE_FAST_CONTEXT_DESTROY 0x10000003 88: 89: /* 90: * MINBW_HYST_MASK = 0xffff 91: * (7680 xo ticks which is 400us) 92: */ 93: #define DEFAULT_MINBW_HYST 0x1e00 94: 95: /* MINBW_IDX_MASK = 0xff0000*/ 96: #define DEFAULT_MINBW_IDX 0x1 97: 98: #define HFI_MINBW_DEFAULT (DEFAULT_MINBW_HYST | (DEFAULT_MINBW_IDX << 16)) 99: 100: /* Types to be used with H2F_MSG_TABLE */ 101: enum hfi_table_type { MATCH LINES: 258, 260, 261, 269, 270 246: /** 247: *@MEMKIND_MMIO_IPC_CORE: Used for IPC_core region mapping to GMU space 248: * for EVA to GPU communication. 249: */ 250: HFI_MEMKIND_MMIO_IPC_CORE, 251: /** @HFIMEMKIND_MMIO_IPCC_AOSS: Used for IPCC AOSS, second memory region */ 252: HFI_MEMKIND_MMIO_IPCC_AOSS, 253: /** 254: * @MEMKIND_CSW_LPAC_PRIV_NON_SECURE: Used for privileged nonsecure 255: * memory for LPAC context record 256: */ 257: HFI_MEMKIND_CSW_LPAC_PRIV_NON_SECURE, 258: /** @HFI_MEMKIND_MEMSTORE: Buffer used to query a context's GPU sop/eop timestamps */ 259: HFI_MEMKIND_MEMSTORE, 260: /** @HFI_MEMKIND_HW_FENCE: Hardware fence Tx/Rx headers and queues */ 261: HFI_MEMKIND_HW_FENCE, 262: /** @HFI_MEMKIND_PREEMPT_SCRATCH: Used for Preemption scratch memory */ 263: HFI_MEMKIND_PREEMPT_SCRATCH, 264: /** 265: * @HFI_MEMKIND_AQE_BUFFER: Sandbox memory used by AQE to switch 266: * between LPAC and GC 267: */ 268: HFI_MEMKIND_AQE_BUFFER, 269: /** @HFI_MEMKIND_HW_FENCE_SHADOW: Shadow memory used for caching external input fences */ 270: HFI_MEMKIND_HW_FENCE_SHADOW, 271: /** 272: * @HFI_MEMKIND_FREQMGR_SCRATCH: Scratch memory for FreqMgr task to retain information 273: * related to GMU based DCVS. 274: */ 275: HFI_MEMKIND_FREQMGR_SCRATCH, 276: /** 277: * @HFI_MEMKIND_DUMMY_CSW_PRIV_NON_SECURE: Used for requesting privileged non 278: * secure preemption records for the internal dummy buffer 279: */ 280: HFI_MEMKIND_DUMMY_CSW_PRIV_NON_SECURE, 281: /** 282: * @HFI_MEMKIND_DUMMY_CSW_COUNTER: Used for requesting preemption performance 283: * counter save/restore buffer for the internal dummy buffer 284: */ 285: HFI_MEMKIND_DUMMY_CSW_COUNTER, 286: HFI_MEMKIND_MAX, 287: }; 288: 289: static const char * const hfi_memkind_strings[] = { 290: [HFI_MEMKIND_GENERIC] = "GMU GENERIC", 291: [HFI_MEMKIND_RB] = "GMU RB", 292: [HFI_MEMKIND_SCRATCH] = "GMU SCRATCH", 293: [HFI_MEMKIND_CSW_SMMU_INFO] = "GMU SMMU INFO", 294: [HFI_MEMKIND_CSW_PRIV_NON_SECURE] = "GMU CSW PRIV NON SECURE", MATCH LINES: 313, 316 301: [HFI_MEMKIND_MMIO_DPU] = "GMU MMIO DPU", 302: [HFI_MEMKIND_MMIO_TCSR] = "GMU MMIO TCSR", 303: [HFI_MEMKIND_MMIO_QDSS_STM] = "GMU MMIO QDSS STM", 304: [HFI_MEMKIND_PROFILE] = "GMU KERNEL PROFILING", 305: [HFI_MEMKIND_USER_PROFILE_IBS] = "GMU USER PROFILING", 306: [HFI_MEMKIND_CMD_BUFFER] = "GMU CMD BUFFER", 307: [HFI_MEMKIND_GPU_BUSY_DATA_BUFFER] = "GMU BUSY DATA BUFFER", 308: [HFI_MEMKIND_GPU_BUSY_CMD_BUFFER] = "GMU BUSY CMD BUFFER", 309: [HFI_MEMKIND_MMIO_IPC_CORE] = "GMU MMIO IPC", 310: [HFI_MEMKIND_MMIO_IPCC_AOSS] = "GMU MMIO IPCC AOSS", 311: [HFI_MEMKIND_CSW_LPAC_PRIV_NON_SECURE] = "GMU CSW LPAC PRIV NON SECURE", 312: [HFI_MEMKIND_MEMSTORE] = "GMU MEMSTORE", 313: [HFI_MEMKIND_HW_FENCE] = "GMU HW FENCE", 314: [HFI_MEMKIND_PREEMPT_SCRATCH] = "GMU PREEMPTION", 315: [HFI_MEMKIND_AQE_BUFFER] = "GMU AQE BUFFER", 316: [HFI_MEMKIND_HW_FENCE_SHADOW] = "GMU HW FENCE SHADOW", 317: [HFI_MEMKIND_FREQMGR_SCRATCH] = "GMU FREQMGR SCRATCH", 318: [HFI_MEMKIND_DUMMY_CSW_PRIV_NON_SECURE] = "GMU DUMMY CSW PRIV NON SECURE", 319: [HFI_MEMKIND_DUMMY_CSW_COUNTER] = "GMU DUMMY CSW COUNTER", 320: [HFI_MEMKIND_MAX] = "GMU UNKNOWN", 321: }; 322: 323: /* CP/GFX pipeline can access */ 324: #define HFI_MEMFLAG_GFX_ACC BIT(0) 325: 326: /* Buffer has APRIV protection in GFX PTEs */ 327: #define HFI_MEMFLAG_GFX_PRIV BIT(1) 328: 329: /* Buffer is read-write for GFX PTEs. A 0 indicates read-only */ 330: #define HFI_MEMFLAG_GFX_WRITEABLE BIT(2) 331: 332: /* GMU can access */ 333: #define HFI_MEMFLAG_GMU_ACC BIT(3) 334: 335: /* Buffer has APRIV protection in GMU PTEs */ 336: #define HFI_MEMFLAG_GMU_PRIV BIT(4) 337: 338: /* Buffer is read-write for GMU PTEs. A 0 indicates read-only */ 339: #define HFI_MEMFLAG_GMU_WRITEABLE BIT(5) 340: MATCH LINES: 384, 385, 386, 393, 396, 398, 401 372: } __packed; 373: 374: /** 375: * struct gmu_context_queue_header - GMU context queue header structure 376: */ 377: struct gmu_context_queue_header { 378: /** @version: Version of the header */ 379: u32 version; 380: /** @start_addr: GMU VA of start of the queue */ 381: u32 start_addr; 382: /** @queue_size: queue size in dwords */ 383: u32 queue_size; 384: /** @out_fence_ts: Timestamp of last hardware fence sent to Tx Queue */ 385: volatile u32 out_fence_ts; 386: /** @sync_obj_ts: Timestamp of last sync object that GMU has digested */ 387: volatile u32 sync_obj_ts; 388: /** @read_index: Read index of the queue */ 389: volatile u32 read_index; 390: /** @write_index: Write index of the queue */ 391: volatile u32 write_index; 392: /** 393: * @hw_fence_buffer_va: GMU VA of the buffer to store output hardware fences for this 394: * context 395: */ 396: u32 hw_fence_buffer_va; 397: /** 398: * @hw_fence_buffer_size: Size of the buffer to store output hardware fences for this 399: * context 400: */ 401: u32 hw_fence_buffer_size; 402: u32 unused1; 403: u32 unused2; 404: u32 unused3; 405: } __packed; 406: 407: /** 408: * struct hfi_queue_header - HFI queue header structure 409: * @status: active: 1; inactive: 0 410: * @start_addr: starting address of the queue in GMU VA space 411: * @type: queue type encoded the priority, ID and send/recevie types 412: * @queue_size: size of the queue 413: * @msg_size: size of the message if each message has fixed size. 414: * Otherwise, 0 means variable size of message in the queue. 415: * @read_index: read index of the queue 416: * @write_index: write index of the queue 417: */ 418: struct hfi_queue_header { 419: u32 status; 420: u32 start_addr; 421: u32 type; 422: u32 queue_size; 423: u32 msg_size; 424: u32 unused0; 425: u32 unused1; MATCH LINES: 534 522: H2F_MSG_ACK = 127, /* Deprecated for v2.0*/ 523: H2F_MSG_REGISTER_CONTEXT = 128, 524: H2F_MSG_UNREGISTER_CONTEXT = 129, 525: H2F_MSG_ISSUE_CMD = 130, 526: H2F_MSG_ISSUE_CMD_RAW = 131, 527: H2F_MSG_TS_NOTIFY = 132, 528: F2H_MSG_TS_RETIRE = 133, 529: H2F_MSG_CONTEXT_POINTERS = 134, 530: H2F_MSG_ISSUE_LPAC_CMD_RAW = 135, 531: H2F_MSG_CONTEXT_RULE = 140, /* AKA constraint */ 532: H2F_MSG_ISSUE_RECURRING_CMD = 141, 533: F2H_MSG_CONTEXT_BAD = 150, 534: H2F_MSG_HW_FENCE_INFO = 151, 535: H2F_MSG_ISSUE_SYNCOBJ = 152, 536: F2H_MSG_SYNCOBJ_QUERY = 153, 537: H2F_MSG_WARMBOOT_CMD = 154, 538: F2H_MSG_PROCESS_TRACE = 155, 539: F2H_MSG_PLATFORM_LA = 200, 540: H2F_MSG_PLATFORM_LA = 201, 541: F2H_MSG_PLATFORM_WIN = 202, /* Reserved */ 542: H2F_MSG_PLATFORM_WIN = 203, /* Reserved */ 543: HFI_MAX_ID, 544: }; 545: 546: enum gmu_ret_type { 547: GMU_SUCCESS = 0, 548: GMU_ERROR_FATAL, 549: GMU_ERROR_MEM_FAIL, 550: GMU_ERROR_INVAL_PARAM, 551: GMU_ERROR_NULL_PTR, 552: GMU_ERROR_OUT_OF_BOUNDS, 553: GMU_ERROR_TIMEOUT, 554: GMU_ERROR_NOT_SUPPORTED, 555: GMU_ERROR_NO_ENTRY, 556: }; 557: 558: /* Platform specific F2H subtype message for GMU */ MATCH LINES: 866 854: 855: /* F2H */ 856: struct hfi_err_cmd { 857: u32 hdr; 858: u32 error_code; 859: u32 data[16]; 860: } __packed; 861: 862: /* F2H */ 863: struct hfi_debug_cmd { 864: u32 hdr; 865: u32 type; 866: u32 timestamp; 867: u32 data; 868: } __packed; 869: 870: /* F2H */ 871: struct hfi_trace_cmd { 872: u32 hdr; 873: u32 version; 874: u64 identifier; 875: } __packed; 876: 877: /* Trace packet definition */ 878: struct gmu_trace_packet { 879: u32 hdr; 880: u32 trace_id; 881: u64 ticks; 882: u32 payload[]; 883: } __packed; 884: 885: /* F2H */ 886: struct hfi_gmu_cntr_register_cmd { 887: u32 hdr; 888: u32 group_id; 889: u32 countable; 890: } __packed; MATCH LINES: 966, 967, 978 954: #define CMDBATCH_RETIRED 1 955: #define CMDBATCH_ERROR 2 956: #define CMDBATCH_SKIP 3 957: 958: #define CMDBATCH_PROFILING BIT(4) 959: #define CMDBATCH_EOF BIT(8) 960: #define CMDBATCH_INDIRECT BIT(9) 961: #define CMDBATCH_RECURRING_START BIT(18) 962: #define CMDBATCH_RECURRING_STOP BIT(19) 963: #define CMDBATCH_NOP_SUBMISSION BIT(20) 964: #define CMDBATCH_USES_MALU BIT(21) 965: 966: /* This indicates that the SYNCOBJ is kgsl output fence */ 967: #define GMU_SYNCOBJ_FLAG_KGSL_FENCE_BIT 0 968: /* This indicates that the SYNCOBJ is signaled */ 969: #define GMU_SYNCOBJ_FLAG_SIGNALED_BIT 1 970: /* This indicates that the SYNCOBJ's software status is queried */ 971: #define GMU_SYNCOBJ_FLAG_QUERY_SW_STATUS_BIT 2 972: /* This indicates that the SYNCOBJ's software status is signaled */ 973: #define GMU_SYNCOBJ_FLAG_SW_STATUS_SIGNALED_BIT 3 974: /* This indicates that the SYNCOBJ's software status is pending */ 975: #define GMU_SYNCOBJ_FLAG_SW_STATUS_PENDING_BIT 4 976: 977: #define GMU_SYNCOBJ_FLAGS \ 978: { BIT(GMU_SYNCOBJ_FLAG_KGSL_FENCE_BIT), "KGSL"}, \ 979: { BIT(GMU_SYNCOBJ_FLAG_SIGNALED_BIT), "SIGNALED"}, \ 980: { BIT(GMU_SYNCOBJ_FLAG_QUERY_SW_STATUS_BIT), "QUERIED"}, \ 981: { BIT(GMU_SYNCOBJ_FLAG_SW_STATUS_SIGNALED_BIT), "SW_SIGNALED"}, \ 982: { BIT(GMU_SYNCOBJ_FLAG_SW_STATUS_PENDING_BIT), "SW_PENDING"} 983: 984: /* F2H */ 985: struct hfi_ts_retire_cmd { 986: u32 hdr; 987: u32 ctxt_id; 988: u32 ts; 989: u32 type; 990: u64 submitted_to_rb; 991: u64 sop; 992: u64 eop; 993: u64 retired_on_gmu; 994: u64 active; 995: u32 version; 996: } __packed; 997: 998: /* H2F */ 999: struct hfi_context_pointers_cmd { 1000: u32 hdr; 1001: u32 ctxt_id; 1002: u64 sop_addr; MATCH LINES: 1063, 1065, 1067, 1069, 1079, 1081, 1083, 1085, 1093, 1097, 1101, 1131, 1132, 1134, 1135, 1137, 1139, 1141, 1143, 1145, 1149, 1153, 1154, 1155, 1156, 1172, 1174, 1178 1051: /* H2F */ 1052: struct hfi_submit_cmd { 1053: u32 hdr; 1054: u32 ctxt_id; 1055: u32 flags; 1056: u32 ts; 1057: u32 profile_gpuaddr_lo; 1058: u32 profile_gpuaddr_hi; 1059: u32 numibs; 1060: u32 big_ib_gmu_va; 1061: } __packed; 1062: 1063: /* This structure is only used for hw fence feature on gen7 hwsched targets */ 1064: struct hfi_syncobj_legacy { 1065: /** @ctxt_id: dma fence context id for external fence and gmu context id for kgsl fence */ 1066: u64 ctxt_id; 1067: /** @seq_no: Sequence number (or timestamp) of this fence */ 1068: u64 seq_no; 1069: /** @flags: Flags for this fence */ 1070: u64 flags; 1071: } __packed; 1072: 1073: struct hfi_syncobj { 1074: /** 1075: * @header: bits[0:15]: size of this packet in dwords, bits[15:23]: version, 1076: * bits[24:31] unused 1077: */ 1078: u32 header; 1079: /** @hash_index: hash index of external input fence */ 1080: u32 hash_index; 1081: /** @ctxt_id: dma fence context id for external fence and gmu context id for kgsl fence */ 1082: u64 ctxt_id; 1083: /** @seq_no: Sequence number (or timestamp) of this fence */ 1084: u64 seq_no; 1085: /** @flags: Flags for this fence */ 1086: u64 flags; 1087: } __packed; 1088: 1089: struct hfi_submit_syncobj { 1090: u32 hdr; 1091: u32 version; 1092: u32 flags; 1093: u32 timestamp; 1094: u32 num_syncobj; 1095: } __packed; 1096: 1097: #define HFI_SYNCOBJ_LEGACY_HW_FENCE_MAX \ 1098: ((HFI_MAX_MSG_SIZE - sizeof(struct hfi_submit_syncobj)) \ 1099: / sizeof(struct hfi_syncobj_legacy)) 1100: 1101: #define HFI_SYNCOBJ_HW_FENCE_MAX \ 1102: ((HFI_MAX_MSG_SIZE - sizeof(struct hfi_submit_syncobj)) \ 1103: / sizeof(struct hfi_syncobj)) 1104: 1105: struct hfi_log_block { 1106: u32 hdr; 1107: u32 version; 1108: u32 start_index; 1109: u32 stop_index; 1110: } __packed; 1111: 1112: enum hfi_warmboot_cmd_type { 1113: HFI_WARMBOOT_SET_SCRATCH = 0, 1114: HFI_WARMBOOT_EXEC_SCRATCH, 1115: HFI_WARMBOOT_QUERY_SCRATCH, 1116: }; 1117: 1118: struct hfi_warmboot_scratch_cmd { 1119: /** @hdr: Header for the scratch command packet */ 1120: u32 hdr; 1121: /** @version: Version of the scratch command packet */ 1122: u32 version; 1123: /** @flags: Set, Execute or Query scratch flag */ 1124: u32 flags; 1125: /** @scratch_addr: Address of the scratch */ 1126: u32 scratch_addr; 1127: /** @scratch_size: Size of the scratch in bytes*/ 1128: u32 scratch_size; 1129: } __packed; 1130: 1131: /* Request GMU to add this fence to TxQueue without checking whether this is retired or not */ 1132: #define HW_FENCE_FLAG_SKIP_MEMSTORE 0x1 1133: 1134: struct hfi_hw_fence_info { 1135: /** @hdr: Header for the fence info packet */ 1136: u32 hdr; 1137: /** @version: Version of the fence info packet */ 1138: u32 version; 1139: /** @gmu_ctxt_id: GMU Context id to which this fence belongs */ 1140: u32 gmu_ctxt_id; 1141: /** @error: Any error code associated with this fence */ 1142: u32 error; 1143: /** @ctxt_id: Context id for which hw fence is to be triggered */ 1144: u64 ctxt_id; 1145: /** @ts: Timestamp for which hw fence is to be triggered */ 1146: u64 ts; 1147: /** @flags: Flags on how to handle this hfi packet */ 1148: u64 flags; 1149: /** @hash_index: Index of the hw fence in hw fence table */ 1150: u64 hash_index; 1151: } __packed; 1152: 1153: /* The software fence corresponding to the queried hardware fence has not signaled */ 1154: #define ADRENO_HW_FENCE_SW_STATUS_PENDING BIT(0) 1155: /* The software fence corresponding to the queried hardware fence has signaled */ 1156: #define ADRENO_HW_FENCE_SW_STATUS_SIGNALED BIT(1) 1157: 1158: struct hfi_syncobj_query { 1159: /** 1160: * @query_bitmask: Bitmask representing the sync object descriptors to be queried. For 1161: * example, to query the second sync object descriptor(index=1) in a sync object, 1162: * bit(1) should be set in this bitmask. 1163: */ 1164: u32 query_bitmask; 1165: } __packed; 1166: 1167: #define MAX_SYNCOBJ_QUERY_BITS 128 1168: #define BITS_PER_SYNCOBJ_QUERY 32 1169: #define MAX_SYNCOBJ_QUERY_DWORDS (MAX_SYNCOBJ_QUERY_BITS / BITS_PER_SYNCOBJ_QUERY) 1170: 1171: struct hfi_syncobj_query_cmd { 1172: /** @hdr: Header for the fence info packet */ 1173: u32 hdr; 1174: /** @version: Version of the fence info packet */ 1175: u32 version; 1176: /** @gmu_ctxt_id: GMU Context id to which this SYNC object belongs */ 1177: u32 gmu_ctxt_id; 1178: /** @sync_obj_ts: Timestamp of this SYNC object */ 1179: u32 sync_obj_ts; 1180: /** @queries: Array of query bitmasks */ 1181: struct hfi_syncobj_query queries[MAX_SYNCOBJ_QUERY_DWORDS]; 1182: } __packed; 1183: 1184: /** 1185: * struct pending_cmd - data structure to track outstanding HFI 1186: * command messages 1187: */ 1188: struct pending_cmd { 1189: /** @sent_hdr: Header of the un-ack'd hfi packet */ 1190: u32 sent_hdr; 1191: /** @results: Array to store the ack packet */ 1192: u32 results[MAX_RCVD_SIZE]; 1193: /** @complete: Completion to signal hfi ack has been received */ 1194: struct completion complete; 1195: /** @node: to add it to the list of hfi packets waiting for ack */ 1196: struct list_head node; 1197: }; 1198: 1199: struct hfi_msg_platform { 1200: /** @hdr: Header for the platform specific msg */ 1201: u32 hdr; 1202: /** @sub_type: Sub type for the platform msg */ --- FILE: \adreno_hwsched.c | HITS: 180 --- MATCH LINES: 240, 266, 270, 271 228: return ERR_PTR(-ENOMEM); 229: } 230: 231: entry = &hwsched->mem_alloc_table[hwsched->mem_alloc_entries]; 232: 233: memcpy(&entry->desc, desc, sizeof(*desc)); 234: 235: entry->desc.host_mem_handle = desc->gmu_mem_handle; 236: 237: setup_gfx_flags_priv(desc->flags, &flags, &priv); 238: 239: if (!(desc->flags & HFI_MEMFLAG_GFX_ACC) && 240: (desc->mem_kind != HFI_MEMKIND_HW_FENCE)) { 241: if (desc->mem_kind == HFI_MEMKIND_MMIO_IPC_CORE) 242: entry->md = gmu_core_reserve_kernel_block_fixed(device, 0, 243: desc->size, 244: get_gmu_vma_id(desc->flags), 245: "qcom,ipc-core", gmu_core_get_attrs(desc->flags), 246: desc->align); 247: else 248: entry->md = gmu_core_reserve_kernel_block(device, 0, 249: desc->size, 250: get_gmu_vma_id(desc->flags), 251: desc->align); 252: 253: if (IS_ERR(entry->md)) { 254: ret = PTR_ERR(entry->md); 255: 256: memset(entry, 0, sizeof(*entry)); 257: return ERR_PTR(ret); 258: } 259: entry->desc.size = entry->md->size; 260: entry->desc.gmu_addr = entry->md->gmuaddr; 261: 262: goto done; 263: } 264: 265: /* 266: * Use pre-allocated memory descriptors to map the HFI_MEMKIND_HW_FENCE and 267: * HFI_MEMKIND_MEMSTORE 268: */ 269: switch (desc->mem_kind) { 270: case HFI_MEMKIND_HW_FENCE: 271: entry->md = &adreno_dev->hwsched.hw_fence.md; 272: break; 273: case HFI_MEMKIND_MEMSTORE: 274: entry->md = device->memstore; 275: break; 276: case HFI_MEMKIND_CSW_PRIV_NON_SECURE: 277: case HFI_MEMKIND_CSW_PRIV_SECURE: 278: /* 279: * Standard kernel does not support secure SIDs. But GMU FW 280: * always requests a secure preempt buffer regardless. Back it 281: * with a PAGE_SIZE non-secure dummy buffer to give CP a valid 282: * GPU VA to write to. 283: */ 284: if (desc->mem_kind == HFI_MEMKIND_CSW_PRIV_SECURE && 285: !kgsl_mmu_is_secured(&device->mmu)) { 286: entry->desc.flags &= ~HFI_MEMFLAG_GFX_SECURE; 287: flags &= ~KGSL_MEMFLAGS_SECURE; 288: entry->desc.size = PAGE_SIZE; 289: } 290: if (ADRENO_FEATURE(adreno_dev, ADRENO_DEFER_GMEM_ALLOC)) { 291: ret = process_preempt_record_mem_alloc(adreno_dev, entry); 292: if (ret) 293: return ERR_PTR(ret); 294: 295: entry->desc.size = entry->md->size; MATCH LINES: 509, 512, 533, 534, 537, 538, 544, 548, 549, 552, 553, 557, 569, 571, 584, 586, 588, 589, 593, 602, 604, 625, 648 497: static int _retire_syncobj(struct adreno_device *adreno_dev, 498: struct kgsl_drawobj_sync *syncobj, struct adreno_context *drawctxt) 499: { 500: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 501: 502: if (!kgsl_drawobj_events_pending(syncobj)) { 503: _pop_drawobj(drawctxt); 504: kgsl_drawobj_destroy(DRAWOBJ(syncobj)); 505: return 0; 506: } 507: 508: /* 509: * If hardware fences are enabled, and this SYNCOBJ is backed by hardware fences, 510: * send it to the GMU 511: */ 512: if (test_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags) && 513: test_bit(KGSL_SYNCOBJ_HW, &syncobj->flags)) 514: return 1; 515: 516: /* 517: * If we got here, there are pending events for sync object. 518: * Start the canary timer if it hasnt been started already. 519: */ 520: if (!syncobj->timeout_jiffies) { 521: syncobj->timeout_jiffies = jiffies + msecs_to_jiffies(5000); 522: mod_timer(&syncobj->timer, syncobj->timeout_jiffies); 523: } 524: 525: return -EAGAIN; 526: } 527: 528: static bool _marker_expired(struct kgsl_drawobj_cmd *markerobj) 529: { 530: struct kgsl_drawobj *drawobj = DRAWOBJ(markerobj); 531: 532: return (drawobj->flags & KGSL_DRAWOBJ_MARKER) && 533: kgsl_check_timestamp(drawobj->device, drawobj->context, 534: markerobj->marker_timestamp); 535: } 536: 537: /* Only retire the timestamp. The drawobj will be destroyed later */ 538: static void _retire_timestamp_only(struct kgsl_drawobj *drawobj) 539: { 540: struct kgsl_context *context = drawobj->context; 541: struct kgsl_device *device = context->device; 542: 543: /* 544: * Write the start and end timestamp to the memstore to keep the 545: * accounting sane 546: */ 547: kgsl_sharedmem_writel(device->memstore, 548: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 549: drawobj->timestamp); 550: 551: kgsl_sharedmem_writel(device->memstore, 552: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 553: drawobj->timestamp); 554: 555: msm_perf_events_update(MSM_PERF_GFX, MSM_PERF_RETIRED, 556: pid_nr(context->proc_priv->pid), 557: context->id, drawobj->timestamp, 558: !!(drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME)); 559: 560: if (drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME) { 561: atomic64_inc(&drawobj->context->proc_priv->frame_count); 562: atomic_inc(&drawobj->context->proc_priv->period->frames); 563: } 564: 565: /* Retire pending GPU events for the object */ 566: kgsl_process_event_group(device, &context->events); 567: } 568: 569: static void _retire_timestamp(struct kgsl_drawobj *drawobj) 570: { 571: _retire_timestamp_only(drawobj); 572: 573: kgsl_drawobj_destroy(drawobj); 574: } 575: 576: static int _retire_markerobj(struct adreno_device *adreno_dev, struct kgsl_drawobj_cmd *cmdobj, 577: struct adreno_context *drawctxt) 578: { 579: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 580: 581: if (_marker_expired(cmdobj)) { 582: set_bit(CMDOBJ_MARKER_EXPIRED, &cmdobj->priv); 583: /* 584: * There may be pending hardware fences that need to be signaled upon retiring 585: * this MARKER object. Hence, send it to the target specific layers to trigger 586: * the hardware fences. 587: */ 588: if (test_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags)) { 589: _retire_timestamp_only(DRAWOBJ(cmdobj)); 590: return 1; 591: } 592: _pop_drawobj(drawctxt); 593: _retire_timestamp(DRAWOBJ(cmdobj)); 594: return 0; 595: } 596: 597: /* 598: * If the marker isn't expired but the SKIP bit 599: * is set then there are real commands following 600: * this one in the queue. This means that we 601: * need to dispatch the command so that we can 602: * keep the timestamp accounting correct. If 603: * skip isn't set then we block this queue 604: * until the dependent timestamp expires 605: */ 606: 607: return test_bit(CMDOBJ_SKIP, &cmdobj->priv) ? 1 : -EAGAIN; 608: } 609: 610: static int _retire_timelineobj(struct kgsl_drawobj *drawobj, 611: struct adreno_context *drawctxt) 612: { 613: _pop_drawobj(drawctxt); 614: kgsl_drawobj_destroy(drawobj); 615: return 0; 616: } 617: 618: static int drawqueue_retire_bindobj(struct kgsl_drawobj *drawobj, 619: struct adreno_context *drawctxt) 620: { 621: struct kgsl_drawobj_bind *bindobj = BINDOBJ(drawobj); 622: 623: if (test_bit(KGSL_BINDOBJ_STATE_DONE, &bindobj->state)) { 624: _pop_drawobj(drawctxt); 625: _retire_timestamp(drawobj); 626: return 0; 627: } 628: 629: if (!test_and_set_bit(KGSL_BINDOBJ_STATE_START, &bindobj->state)) { 630: /* 631: * Take a reference to the drawobj and the context because both 632: * get referenced in the bind callback 633: */ 634: _kgsl_context_get(&drawctxt->base); 635: kref_get(&drawobj->refcount); 636: 637: kgsl_sharedmem_bind_ranges(bindobj->bind); 638: } 639: 640: return -EAGAIN; 641: } 642: 643: /* 644: * Retires all expired marker and sync objs from the context 645: * queue and returns one of the below 646: * a) next drawobj that needs to be sent to ringbuffer 647: * b) -EAGAIN for syncobj with syncpoints pending. 648: * c) -EAGAIN for markerobj whose marker timestamp has not expired yet. 649: * c) NULL for no commands remaining in drawqueue. 650: */ 651: static struct kgsl_drawobj *_process_drawqueue_get_next_drawobj( 652: struct adreno_device *adreno_dev, struct adreno_context *drawctxt) 653: { 654: struct kgsl_drawobj *drawobj; 655: unsigned int i = drawctxt->drawqueue_head; 656: struct kgsl_drawobj_cmd *cmdobj; 657: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 658: int ret = 0; 659: 660: if (drawctxt->drawqueue_head == drawctxt->drawqueue_tail) 661: return NULL; 662: 663: for (i = drawctxt->drawqueue_head; i != drawctxt->drawqueue_tail; 664: i = DRAWQUEUE_NEXT(i, ADRENO_CONTEXT_DRAWQUEUE_SIZE)) { 665: 666: drawobj = drawctxt->drawqueue[i]; 667: 668: if (!drawobj) 669: return NULL; 670: 671: switch (drawobj->type) { 672: case CMDOBJ_TYPE: MATCH LINES: 965, 994 953: if (IS_ERR(drawobj)) 954: ret = PTR_ERR(drawobj); 955: spin_unlock(&drawctxt->lock); 956: break; 957: } 958: _pop_drawobj(drawctxt); 959: spin_unlock(&drawctxt->lock); 960: 961: if (is_cmdobj(drawobj) || is_marker_skip(drawobj)) { 962: cmdobj = CMDOBJ(drawobj); 963: context = drawobj->context; 964: trace_adreno_cmdbatch_ready(context->id, 965: context->priority, drawobj->timestamp, 966: cmdobj->requeue_cnt); 967: } 968: ret = hwsched_sendcmd(adreno_dev, drawobj); 969: 970: /* 971: * On error from hwsched_sendcmd() try to requeue the cmdobj 972: * unless we got back -ENOENT which means that the context has 973: * been detached and there will be no more deliveries from here 974: */ 975: if (ret != 0) { 976: /* Destroy the cmdobj on -ENOENT */ 977: if (ret == -ENOENT) 978: kgsl_drawobj_destroy(drawobj); 979: else { 980: /* 981: * If we couldn't put it on dispatch queue 982: * then return it to the context queue 983: */ 984: int r = hwsched_dispatcher_requeue_drawobj( 985: drawctxt, drawobj); 986: if (r) 987: ret = r; 988: } 989: 990: break; 991: } 992: 993: if (cmdobj) 994: drawctxt->submitted_timestamp = drawobj->timestamp; 995: 996: count++; 997: } 998: 999: /* 1000: * Wake up any snoozing threads if we have consumed any real commands 1001: * or marker commands and we have room in the context queue. 1002: */ 1003: 1004: if (_check_context_queue(drawctxt, 0)) 1005: wake_up_all(&drawctxt->wq); 1006: 1007: if (!ret) 1008: ret = count; 1009: 1010: /* Return error or the number of commands queued */ 1011: return ret; 1012: } 1013: 1014: static void hwsched_handle_jobs_list(struct adreno_device *adreno_dev, 1015: int id, unsigned long *map, struct llist_node *list) 1016: { 1017: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1018: struct adreno_dispatch_job *job, *next; MATCH LINES: 1157, 1160, 1161, 1163, 1166, 1167, 1173, 1174, 1176, 1179, 1181, 1183, 1184 1145: kgsl_mutex_unlock(&device->mutex); 1146: } 1147: 1148: mutex_unlock(&hwsched->mutex); 1149: _decrement_submit_now(device); 1150: return; 1151: 1152: done: 1153: adreno_scheduler_queue(adreno_dev); 1154: } 1155: 1156: /** 1157: * get_timestamp() - Return the next timestamp for the context 1158: * @drawctxt - Pointer to an adreno draw context struct 1159: * @drawobj - Pointer to a drawobj 1160: * @timestamp - Pointer to a timestamp value possibly passed from the user 1161: * @user_ts - user generated timestamp 1162: * 1163: * Assign a timestamp based on the settings of the draw context and the command 1164: * batch. 1165: */ 1166: static int get_timestamp(struct adreno_context *drawctxt, 1167: struct kgsl_drawobj *drawobj, unsigned int *timestamp, 1168: unsigned int user_ts) 1169: { 1170: 1171: if (drawctxt->base.flags & KGSL_CONTEXT_USER_GENERATED_TS) { 1172: /* 1173: * User specified timestamps need to be greater than the last 1174: * issued timestamp in the context 1175: */ 1176: if (timestamp_cmp(drawctxt->timestamp, user_ts) >= 0) 1177: return -ERANGE; 1178: 1179: drawctxt->timestamp = user_ts; 1180: } else 1181: drawctxt->timestamp++; 1182: 1183: *timestamp = drawctxt->timestamp; 1184: drawobj->timestamp = *timestamp; 1185: return 0; 1186: } 1187: 1188: static inline int _wait_for_room_in_context_queue( 1189: struct adreno_context *drawctxt, u32 count) 1190: { 1191: int ret = 0; 1192: 1193: /* 1194: * There is always a possibility that dispatcher may end up pushing 1195: * the last popped draw object back to the context drawqueue. Hence, 1196: * we can only queue up to _context_drawqueue_size - 1 here to make 1197: * sure we never let drawqueue->queued exceed _context_drawqueue_size. 1198: */ 1199: if ((drawctxt->queued + count) > (_context_drawqueue_size - 1)) { 1200: trace_adreno_drawctxt_sleep(drawctxt); 1201: spin_unlock(&drawctxt->lock); 1202: 1203: ret = wait_event_interruptible_timeout(drawctxt->wq, 1204: _check_context_queue(drawctxt, count), 1205: msecs_to_jiffies(_context_queue_wait)); 1206: 1207: spin_lock(&drawctxt->lock); 1208: trace_adreno_drawctxt_wake(drawctxt); MATCH LINES: 1246, 1253, 1259, 1281, 1289, 1293, 1294, 1301, 1306, 1314, 1315, 1316, 1321, 1322, 1325, 1326, 1334, 1338, 1342, 1352, 1353, 1356, 1363 1234: static void _queue_drawobj(struct adreno_context *drawctxt, 1235: struct kgsl_drawobj *drawobj) 1236: { 1237: struct kgsl_context *context = drawobj->context; 1238: 1239: /* Put the command into the queue */ 1240: drawctxt->drawqueue[drawctxt->drawqueue_tail] = drawobj; 1241: drawctxt->drawqueue_tail = (drawctxt->drawqueue_tail + 1) % 1242: ADRENO_CONTEXT_DRAWQUEUE_SIZE; 1243: drawctxt->queued++; 1244: msm_perf_events_update(MSM_PERF_GFX, MSM_PERF_QUEUE, 1245: pid_nr(context->proc_priv->pid), 1246: context->id, drawobj->timestamp, 1247: !!(drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME)); 1248: trace_adreno_cmdbatch_queued(drawobj, drawctxt->queued); 1249: } 1250: 1251: static int _queue_cmdobj(struct adreno_device *adreno_dev, 1252: struct adreno_context *drawctxt, struct kgsl_drawobj_cmd *cmdobj, 1253: uint32_t *timestamp, unsigned int user_ts) 1254: { 1255: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 1256: u32 j; 1257: int ret; 1258: 1259: ret = get_timestamp(drawctxt, drawobj, timestamp, user_ts); 1260: if (ret) 1261: return ret; 1262: 1263: /* 1264: * If this is a real command then we need to force any markers 1265: * queued before it to dispatch to keep time linear - set the 1266: * skip bit so the commands get NOPed. 1267: */ 1268: j = drawctxt->drawqueue_head; 1269: 1270: while (j != drawctxt->drawqueue_tail) { 1271: if (drawctxt->drawqueue[j]->type == MARKEROBJ_TYPE) { 1272: struct kgsl_drawobj_cmd *markerobj = 1273: CMDOBJ(drawctxt->drawqueue[j]); 1274: 1275: set_bit(CMDOBJ_SKIP, &markerobj->priv); 1276: } 1277: 1278: j = DRAWQUEUE_NEXT(j, ADRENO_CONTEXT_DRAWQUEUE_SIZE); 1279: } 1280: 1281: drawctxt->queued_timestamp = *timestamp; 1282: 1283: _queue_drawobj(drawctxt, drawobj); 1284: 1285: return 0; 1286: } 1287: 1288: static void _queue_syncobj(struct adreno_context *drawctxt, 1289: struct kgsl_drawobj_sync *syncobj, uint32_t *timestamp) 1290: { 1291: struct kgsl_drawobj *drawobj = DRAWOBJ(syncobj); 1292: 1293: *timestamp = 0; 1294: drawobj->timestamp = 0; 1295: 1296: _queue_drawobj(drawctxt, drawobj); 1297: } 1298: 1299: static int _queue_markerobj(struct adreno_device *adreno_dev, 1300: struct adreno_context *drawctxt, struct kgsl_drawobj_cmd *markerobj, 1301: u32 *timestamp, u32 user_ts) 1302: { 1303: struct kgsl_drawobj *drawobj = DRAWOBJ(markerobj); 1304: int ret; 1305: 1306: ret = get_timestamp(drawctxt, drawobj, timestamp, user_ts); 1307: if (ret) 1308: return ret; 1309: 1310: /* 1311: * See if we can fastpath this thing - if nothing is queued 1312: * and nothing is inflight retire without bothering the GPU 1313: */ 1314: if (!drawctxt->queued && kgsl_check_timestamp(drawobj->device, 1315: drawobj->context, drawctxt->queued_timestamp)) { 1316: _retire_timestamp(drawobj); 1317: return 1; 1318: } 1319: 1320: /* 1321: * Remember the last queued timestamp - the marker will block 1322: * until that timestamp is expired (unless another command 1323: * comes along and forces the marker to execute) 1324: */ 1325: markerobj->marker_timestamp = drawctxt->queued_timestamp; 1326: drawctxt->queued_timestamp = *timestamp; 1327: 1328: _queue_drawobj(drawctxt, drawobj); 1329: 1330: return 0; 1331: } 1332: 1333: static int _queue_bindobj(struct adreno_context *drawctxt, 1334: struct kgsl_drawobj *drawobj, u32 *timestamp, u32 user_ts) 1335: { 1336: int ret; 1337: 1338: ret = get_timestamp(drawctxt, drawobj, timestamp, user_ts); 1339: if (ret) 1340: return ret; 1341: 1342: drawctxt->queued_timestamp = *timestamp; 1343: _queue_drawobj(drawctxt, drawobj); 1344: 1345: return 0; 1346: } 1347: 1348: static void _queue_timelineobj(struct adreno_context *drawctxt, 1349: struct kgsl_drawobj *drawobj) 1350: { 1351: /* 1352: * This drawobj is not submitted to the GPU so use a timestamp of 0. 1353: * Update the timestamp through a subsequent marker to keep userspace 1354: * happy. 1355: */ 1356: drawobj->timestamp = 0; 1357: 1358: _queue_drawobj(drawctxt, drawobj); 1359: } 1360: 1361: static int adreno_hwsched_queue_cmds(struct kgsl_device_private *dev_priv, 1362: struct kgsl_context *context, struct kgsl_drawobj *drawobj[], 1363: u32 count, u32 *timestamp) 1364: 1365: { 1366: struct kgsl_device *device = dev_priv->device; 1367: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1368: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 1369: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1370: struct adreno_dispatch_job *job; 1371: int ret; 1372: unsigned int i, user_ts; 1373: 1374: /* 1375: * There is always a possibility that dispatcher may end up pushing 1376: * the last popped draw object back to the context drawqueue. Hence, 1377: * we can only queue up to _context_drawqueue_size - 1 here to make 1378: * sure we never let drawqueue->queued exceed _context_drawqueue_size. 1379: */ 1380: if (!count || count > _context_drawqueue_size - 1) 1381: return -EINVAL; 1382: 1383: for (i = 0; i < count; i++) { 1384: struct kgsl_drawobj_cmd *cmdobj; 1385: struct kgsl_memobj_node *ib; 1386: 1387: if (!is_cmdobj(drawobj[i])) MATCH LINES: 1425, 1434, 1435, 1437, 1450, 1464, 1473, 1476 1413: 1414: job->drawctxt = drawctxt; 1415: 1416: spin_lock(&drawctxt->lock); 1417: 1418: ret = _check_context_state_to_queue_cmds(drawctxt, count); 1419: if (ret) { 1420: spin_unlock(&drawctxt->lock); 1421: kmem_cache_free(jobs_cache, job); 1422: return ret; 1423: } 1424: 1425: user_ts = *timestamp; 1426: 1427: /* 1428: * If there is only one drawobj in the array and it is of 1429: * type SYNCOBJ_TYPE, skip comparing user_ts as it can be 0 1430: */ 1431: if (!(count == 1 && drawobj[0]->type == SYNCOBJ_TYPE) && 1432: (drawctxt->base.flags & KGSL_CONTEXT_USER_GENERATED_TS)) { 1433: /* 1434: * User specified timestamps need to be greater than the last 1435: * issued timestamp in the context 1436: */ 1437: if (timestamp_cmp(drawctxt->timestamp, user_ts) >= 0) { 1438: spin_unlock(&drawctxt->lock); 1439: kmem_cache_free(jobs_cache, job); 1440: return -ERANGE; 1441: } 1442: } 1443: 1444: for (i = 0; i < count; i++) { 1445: 1446: switch (drawobj[i]->type) { 1447: case MARKEROBJ_TYPE: 1448: ret = _queue_markerobj(adreno_dev, drawctxt, 1449: CMDOBJ(drawobj[i]), 1450: timestamp, user_ts); 1451: if (ret == 1) { 1452: spin_unlock(&drawctxt->lock); 1453: kmem_cache_free(jobs_cache, job); 1454: return 0; 1455: } else if (ret) { 1456: spin_unlock(&drawctxt->lock); 1457: kmem_cache_free(jobs_cache, job); 1458: return ret; 1459: } 1460: break; 1461: case CMDOBJ_TYPE: 1462: ret = _queue_cmdobj(adreno_dev, drawctxt, 1463: CMDOBJ(drawobj[i]), 1464: timestamp, user_ts); 1465: if (ret) { 1466: spin_unlock(&drawctxt->lock); 1467: kmem_cache_free(jobs_cache, job); 1468: return ret; 1469: } 1470: break; 1471: case SYNCOBJ_TYPE: 1472: _queue_syncobj(drawctxt, SYNCOBJ(drawobj[i]), 1473: timestamp); 1474: break; 1475: case BINDOBJ_TYPE: 1476: ret = _queue_bindobj(drawctxt, drawobj[i], timestamp, 1477: user_ts); 1478: if (ret) { 1479: spin_unlock(&drawctxt->lock); 1480: kmem_cache_free(jobs_cache, job); 1481: return ret; 1482: } 1483: break; 1484: case TIMELINEOBJ_TYPE: 1485: _queue_timelineobj(drawctxt, drawobj[i]); 1486: break; 1487: default: 1488: spin_unlock(&drawctxt->lock); 1489: kmem_cache_free(jobs_cache, job); 1490: return -EINVAL; 1491: } 1492: 1493: } 1494: 1495: adreno_track_context(adreno_dev, NULL, drawctxt); 1496: 1497: spin_unlock(&drawctxt->lock); 1498: 1499: /* Add the context to the dispatcher pending list */ 1500: if (_kgsl_context_get(&drawctxt->base)) { MATCH LINES: 1522, 1531, 1541, 1545, 1546, 1547, 1558, 1561, 1575, 1579, 1588, 1612, 1613 1510: 1511: return 0; 1512: } 1513: 1514: void adreno_hwsched_retire_cmdobj(struct adreno_hwsched *hwsched, 1515: struct kgsl_drawobj_cmd *cmdobj) 1516: { 1517: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 1518: struct kgsl_context *context = drawobj->context; 1519: 1520: msm_perf_events_update(MSM_PERF_GFX, MSM_PERF_RETIRED, 1521: pid_nr(context->proc_priv->pid), 1522: context->id, drawobj->timestamp, 1523: !!(drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME)); 1524: 1525: if (drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME) { 1526: atomic64_inc(&drawobj->context->proc_priv->frame_count); 1527: atomic_inc(&drawobj->context->proc_priv->period->frames); 1528: } 1529: 1530: trace_adreno_cmdbatch_done(drawobj->context->id, 1531: drawobj->context->priority, drawobj->timestamp); 1532: 1533: if (hwsched->big_cmdobj == cmdobj) { 1534: hwsched->big_cmdobj = NULL; 1535: kgsl_drawobj_put(drawobj); 1536: } 1537: 1538: kgsl_drawobj_destroy(drawobj); 1539: } 1540: 1541: void adreno_hwsched_syncobj_kfence_put(struct kgsl_drawobj_sync *syncobj) 1542: { 1543: int i; 1544: 1545: for (i = 0; i < syncobj->num_hw_fence; i++) { 1546: kgsl_context_put(syncobj->hw_fences[i].context); 1547: syncobj->hw_fences[i].context = NULL; 1548: } 1549: } 1550: 1551: static void adreno_hwsched_hw_syncobj_cancel_callbacks(struct kgsl_drawobj_sync *syncobj) 1552: { 1553: u32 i; 1554: 1555: for (i = 0; i < syncobj->numsyncs; i++) { 1556: struct kgsl_drawobj_sync_event *event = &syncobj->synclist[i]; 1557: 1558: if (event->type != KGSL_CMD_SYNCPOINT_TYPE_FENCE) 1559: continue; 1560: 1561: kgsl_sync_fence_async_cancel(event->handle); 1562: 1563: /* 1564: * Now that we know the callback is removed, we can safely put back the 1565: * refcount if it isn't already put back 1566: */ 1567: if (test_and_clear_bit(i, &syncobj->pending)) 1568: kgsl_drawobj_put(DRAWOBJ(syncobj)); 1569: } 1570: } 1571: 1572: static void adreno_hwsched_hw_syncobj_destroy(struct kgsl_drawobj *drawobj) 1573: { 1574: /* 1575: * It is still possible that the dma fence callbacks may not yet have 1576: * been invoked. Make sure we cancel the callbacks before we destroy the sync object 1577: */ 1578: adreno_hwsched_hw_syncobj_cancel_callbacks(SYNCOBJ(drawobj)); 1579: adreno_hwsched_syncobj_kfence_put(SYNCOBJ(drawobj)); 1580: kgsl_drawobj_destroy(drawobj); 1581: } 1582: 1583: static bool adreno_hwsched_hw_syncobj_retired(struct kgsl_drawobj *drawobj) 1584: { 1585: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 1586: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 1587: 1588: if (timestamp_cmp(drawobj->timestamp, hdr->sync_obj_ts) > 0) 1589: return false; 1590: 1591: return true; 1592: } 1593: 1594: static bool drawobj_retired(struct adreno_device *adreno_dev, 1595: struct kgsl_drawobj *drawobj) 1596: { 1597: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1598: struct kgsl_drawobj_cmd *cmdobj; 1599: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1600: 1601: if ((drawobj->type & SYNCOBJ_TYPE) != 0) { 1602: if (adreno_hwsched_hw_syncobj_retired(drawobj)) { 1603: adreno_hwsched_hw_syncobj_destroy(drawobj); 1604: return true; 1605: } 1606: 1607: return false; 1608: } 1609: 1610: cmdobj = CMDOBJ(drawobj); 1611: 1612: if (!kgsl_check_timestamp(device, drawobj->context, 1613: drawobj->timestamp)) 1614: return false; 1615: 1616: adreno_hwsched_retire_cmdobj(hwsched, cmdobj); 1617: return true; 1618: } 1619: 1620: static void retire_drawobj_list(struct adreno_device *adreno_dev) 1621: { 1622: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1623: struct cmd_list_obj *obj, *tmp; 1624: 1625: list_for_each_entry_safe(obj, tmp, &hwsched->cmd_list, node) { 1626: struct kgsl_drawobj *drawobj = obj->drawobj; 1627: 1628: if (!drawobj_retired(adreno_dev, drawobj)) 1629: continue; 1630: 1631: list_del_init(&obj->node); 1632: 1633: kmem_cache_free(obj_cache, obj); 1634: 1635: hwsched->inflight--; 1636: } 1637: } MATCH LINES: 1746, 1750, 1753, 1755, 1756, 1758, 1760, 1762, 1782, 1791, 1804, 1805, 1808, 1809, 1832, 1833 1734: static ADRENO_SYSFS_BOOL(preemption); 1735: static ADRENO_SYSFS_RO_U32(preempt_count); 1736: static ADRENO_SYSFS_BOOL(ft_long_ib_detect); 1737: 1738: static const struct attribute *_hwsched_attr_list[] = { 1739: &adreno_attr_preemption.attr.attr, 1740: &adreno_attr_preempt_count.attr.attr, 1741: &adreno_attr_preempt_info.attr, 1742: &adreno_attr_ft_long_ib_detect.attr.attr, 1743: NULL, 1744: }; 1745: 1746: void adreno_hwsched_deregister_hw_fence(struct adreno_device *adreno_dev) 1747: { 1748: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1749: 1750: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags)) 1751: return; 1752: 1753: kgsl_hw_fence_close(KGSL_DEVICE(adreno_dev)); 1754: 1755: if (hwsched->hw_fence.md.sgt) 1756: sg_free_table(hwsched->hw_fence.md.sgt); 1757: 1758: memset(&hwsched->hw_fence.md, 0x0, sizeof(hwsched->hw_fence.md)); 1759: 1760: kmem_cache_destroy(hwsched->hw_fence_cache); 1761: 1762: clear_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags); 1763: } 1764: 1765: static void adreno_hwsched_dispatcher_close(struct adreno_device *adreno_dev) 1766: { 1767: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1768: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1769: 1770: if (!IS_ERR_OR_NULL(adreno_dev->scheduler_worker)) 1771: kthread_destroy_worker(adreno_dev->scheduler_worker); 1772: 1773: adreno_set_dispatch_ops(adreno_dev, NULL); 1774: 1775: kmem_cache_destroy(jobs_cache); 1776: kmem_cache_destroy(obj_cache); 1777: 1778: sysfs_remove_files(&device->dev->kobj, _hwsched_attr_list); 1779: 1780: kfree(hwsched->ctxt_bad); 1781: 1782: adreno_hwsched_deregister_hw_fence(adreno_dev); 1783: 1784: if (hwsched->global_ctxtq.hostptr) 1785: kgsl_sharedmem_free(&hwsched->global_ctxtq); 1786: 1787: kobject_put(&hwsched->dcvs_kobj); 1788: kobject_put(&hwsched->tunables_kobj); 1789: } 1790: 1791: static void force_retire_timestamp(struct kgsl_device *device, 1792: struct kgsl_drawobj *drawobj) 1793: { 1794: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1795: 1796: if (test_bit(ADRENO_HWSCHED_FORCE_RETIRE_GMU, &adreno_dev->hwsched.flags)) { 1797: struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj); 1798: 1799: set_bit(CMDOBJ_NOP_SUBMISSION, &cmdobj->priv); 1800: return; 1801: } 1802: 1803: kgsl_sharedmem_writel(device->memstore, 1804: KGSL_MEMSTORE_OFFSET(drawobj->context->id, soptimestamp), 1805: drawobj->timestamp); 1806: 1807: kgsl_sharedmem_writel(device->memstore, 1808: KGSL_MEMSTORE_OFFSET(drawobj->context->id, eoptimestamp), 1809: drawobj->timestamp); 1810: } 1811: 1812: /* Return true if drawobj needs to replayed, false otherwise */ 1813: bool adreno_hwsched_drawobj_replay(struct adreno_device *adreno_dev, 1814: struct kgsl_drawobj *drawobj) 1815: { 1816: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1817: struct kgsl_drawobj_cmd *cmdobj; 1818: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1819: 1820: if ((drawobj->type & SYNCOBJ_TYPE) != 0) { 1821: if (kgsl_context_is_bad(drawobj->context) || 1822: adreno_hwsched_hw_syncobj_retired(drawobj)) { 1823: adreno_hwsched_hw_syncobj_destroy(drawobj); 1824: return false; 1825: } 1826: 1827: return true; 1828: } 1829: 1830: cmdobj = CMDOBJ(drawobj); 1831: 1832: if (kgsl_check_timestamp(device, drawobj->context, 1833: drawobj->timestamp) || kgsl_context_is_bad(drawobj->context)) { 1834: adreno_hwsched_retire_cmdobj(hwsched, cmdobj); 1835: return false; 1836: } 1837: 1838: return true; 1839: } 1840: 1841: void adreno_hwsched_replay(struct adreno_device *adreno_dev) 1842: { 1843: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1844: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1845: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1846: struct cmd_list_obj *obj, *tmp; 1847: u32 retired = 0; 1848: 1849: list_for_each_entry_safe(obj, tmp, &hwsched->cmd_list, node) { 1850: struct kgsl_drawobj *drawobj = obj->drawobj; 1851: 1852: /* 1853: * Get rid of retired objects or objects that belong to detached 1854: * or invalidated contexts 1855: */ 1856: if (adreno_hwsched_drawobj_replay(adreno_dev, drawobj)) { 1857: hwsched->hwsched_ops->submit_drawobj(adreno_dev, drawobj); MATCH LINES: 1884 1872: &hwsched->recurring_cmdobj->priv); 1873: set_bit(CMDOBJ_RECURRING_STOP, 1874: &hwsched->recurring_cmdobj->priv); 1875: event = GPU_SSR_FATAL; 1876: } else { 1877: event = GPU_SSR_END; 1878: } 1879: gpudev->send_recurring_cmdobj(adreno_dev, 1880: hwsched->recurring_cmdobj); 1881: srcu_notifier_call_chain(&device->nh, event, NULL); 1882: } 1883: 1884: /* Signal fences */ 1885: if (retired) 1886: kgsl_process_event_groups(device); 1887: } 1888: 1889: static void do_fault_header(struct adreno_device *adreno_dev, 1890: struct kgsl_drawobj *drawobj, int fault) 1891: { 1892: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1893: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1894: struct adreno_context *drawctxt; 1895: u32 status = 0, rptr = 0, wptr = 0, ib1sz = 0, ib2sz = 0; 1896: u64 ib1base = 0, ib2base = 0; 1897: bool gx_on = adreno_gx_is_on(adreno_dev); 1898: u32 ctxt_id = 0, ts = 0; 1899: int rb_id = -1; 1900: 1901: dev_err(device->dev, "Fault id:%d and GX is %s with Curr GPU freq:%ld\n", 1902: fault, gx_on ? "ON" : "OFF", kgsl_pwrctrl_active_freq(&device->pwrctrl)); 1903: 1904: if (!gx_on && !drawobj) 1905: return; 1906: 1907: if (gpudev->fault_header) 1908: return gpudev->fault_header(adreno_dev, drawobj); MATCH LINES: 1928, 1931, 1937, 1963, 1964, 1965, 1966 1916: adreno_readreg(adreno_dev, ADRENO_REG_CP_IB1_BUFSZ, &ib1sz); 1917: adreno_readreg64(adreno_dev, ADRENO_REG_CP_IB2_BASE, 1918: ADRENO_REG_CP_IB2_BASE_HI, &ib2base); 1919: adreno_readreg(adreno_dev, ADRENO_REG_CP_IB2_BUFSZ, &ib2sz); 1920: 1921: dev_err(device->dev, 1922: "status %8.8X rb %4.4x/%4.4x ib1 %16.16llX/%4.4x ib2 %16.16llX/%4.4x\n", 1923: status, rptr, wptr, ib1base, ib1sz, ib2base, ib2sz); 1924: } 1925: 1926: if (drawobj) { 1927: drawctxt = ADRENO_CONTEXT(drawobj->context); 1928: drawobj->context->last_faulted_cmd_ts = drawobj->timestamp; 1929: drawobj->context->total_fault_count++; 1930: ctxt_id = drawobj->context->id; 1931: ts = drawobj->timestamp; 1932: rb_id = adreno_get_level(drawobj->context); 1933: 1934: pr_context(device, drawobj->context, 1935: "ctx %u ctx_type %s ts %u policy %lX dispatch_queue=%d\n", 1936: drawobj->context->id, kgsl_context_type(drawctxt->type), 1937: drawobj->timestamp, CMDOBJ(drawobj)->fault_recovery, 1938: drawobj->context->gmu_dispatch_queue); 1939: 1940: pr_context(device, drawobj->context, 1941: "cmdline: %s\n", drawctxt->base.proc_priv->cmdline); 1942: } 1943: 1944: trace_adreno_gpu_fault(ctxt_id, ts, status, rptr, wptr, ib1base, ib1sz, 1945: ib2base, ib2sz, rb_id); 1946: } 1947: 1948: static struct cmd_list_obj *get_active_cmdobj_lpac( 1949: struct adreno_device *adreno_dev) 1950: { 1951: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1952: struct cmd_list_obj *obj, *tmp, *active_obj = NULL; 1953: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1954: u32 consumed = 0, retired = 0; 1955: struct kgsl_drawobj *drawobj = NULL; 1956: 1957: list_for_each_entry_safe(obj, tmp, &hwsched->cmd_list, node) { 1958: drawobj = obj->drawobj; 1959: 1960: if (!is_cmdobj(drawobj) || !kgsl_context_is_lpac(drawobj->context)) 1961: continue; 1962: 1963: kgsl_readtimestamp(device, drawobj->context, 1964: KGSL_TIMESTAMP_CONSUMED, &consumed); 1965: kgsl_readtimestamp(device, drawobj->context, 1966: KGSL_TIMESTAMP_RETIRED, &retired); 1967: 1968: if (!consumed) 1969: continue; 1970: 1971: if (consumed == retired) 1972: continue; 1973: 1974: /* 1975: * Find the first submission that started but didn't finish 1976: * We only care about one ringbuffer for LPAC so just look for the 1977: * first unfinished submission 1978: */ 1979: if (!active_obj) 1980: active_obj = obj; 1981: } 1982: 1983: if (active_obj) { 1984: drawobj = active_obj->drawobj; 1985: 1986: if (kref_get_unless_zero(&drawobj->refcount)) { 1987: struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj); 1988: 1989: set_bit(CMDOBJ_FAULT, &cmdobj->priv); 1990: return active_obj; MATCH LINES: 2013, 2014, 2015, 2016 2001: struct cmd_list_obj *obj, *tmp, *active_obj = NULL; 2002: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2003: u32 consumed = 0, retired = 0, prio = UINT_MAX; 2004: struct kgsl_drawobj *drawobj = NULL; 2005: 2006: list_for_each_entry_safe(obj, tmp, &hwsched->cmd_list, node) { 2007: drawobj = obj->drawobj; 2008: 2009: /* We track LPAC separately */ 2010: if (!is_cmdobj(drawobj) || kgsl_context_is_lpac(drawobj->context)) 2011: continue; 2012: 2013: kgsl_readtimestamp(device, drawobj->context, 2014: KGSL_TIMESTAMP_CONSUMED, &consumed); 2015: kgsl_readtimestamp(device, drawobj->context, 2016: KGSL_TIMESTAMP_RETIRED, &retired); 2017: 2018: if (!consumed) 2019: continue; 2020: 2021: if (consumed == retired) 2022: continue; 2023: 2024: /* Find the first submission that started but didn't finish */ 2025: if (!active_obj) { 2026: active_obj = obj; 2027: prio = adreno_get_level(drawobj->context); 2028: continue; 2029: } 2030: 2031: /* Find the highest priority active submission */ 2032: if (adreno_get_level(drawobj->context) < prio) { 2033: active_obj = obj; 2034: prio = adreno_get_level(drawobj->context); 2035: } 2036: } 2037: 2038: if (active_obj) { 2039: struct kgsl_drawobj_cmd *cmdobj; 2040: MATCH LINES: 2066 2054: u32 ctxt_id, u32 ts) 2055: { 2056: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 2057: struct cmd_list_obj *obj, *tmp; 2058: 2059: list_for_each_entry_safe(obj, tmp, &hwsched->cmd_list, node) { 2060: struct kgsl_drawobj *drawobj = obj->drawobj; 2061: 2062: if (!is_cmdobj(drawobj)) 2063: continue; 2064: 2065: if ((ctxt_id == drawobj->context->id) && 2066: (ts == drawobj->timestamp)) { 2067: if (kref_get_unless_zero(&drawobj->refcount)) { 2068: struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj); 2069: 2070: set_bit(CMDOBJ_FAULT, &cmdobj->priv); 2071: return obj; 2072: } 2073: } 2074: } 2075: 2076: return NULL; 2077: } 2078: 2079: static bool context_is_throttled(struct kgsl_device *device, 2080: struct kgsl_context *context) 2081: { 2082: if (ktime_ms_delta(ktime_get(), context->fault_time) > 2083: _fault_throttle_time) { 2084: context->fault_time = ktime_get(); 2085: context->fault_count = 1; 2086: return false; 2087: } 2088: 2089: context->fault_count++; 2090: MATCH LINES: 2107, 2108, 2109, 2110, 2113, 2116, 2117, 2133 2095: return true; 2096: } 2097: 2098: return false; 2099: } 2100: 2101: static void _print_syncobj(struct adreno_device *adreno_dev, struct kgsl_drawobj *drawobj) 2102: { 2103: int i; 2104: struct kgsl_drawobj_sync *syncobj = SYNCOBJ(drawobj); 2105: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2106: 2107: for (i = 0; i < syncobj->num_hw_fence; i++) { 2108: struct dma_fence *fence = syncobj->hw_fences[i].fence; 2109: bool kgsl = is_kgsl_fence(fence); 2110: bool signaled = test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags); 2111: char value[32] = "unknown"; 2112: 2113: kgsl_fence_timeline_value_str(fence, value, sizeof(value)); 2114: 2115: dev_err(device->dev, 2116: "dma fence[%d] signaled:%d kgsl:%d ctx:%llu seqno:%llu value:%s\n", 2117: i, signaled, kgsl, fence->context, fence->seqno, value); 2118: } 2119: 2120: } 2121: 2122: static void print_fault_syncobj(struct adreno_device *adreno_dev, 2123: u32 ctxt_id, u32 ts) 2124: { 2125: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 2126: struct cmd_list_obj *obj; 2127: 2128: list_for_each_entry(obj, &hwsched->cmd_list, node) { 2129: struct kgsl_drawobj *drawobj = obj->drawobj; 2130: 2131: if (drawobj->type == SYNCOBJ_TYPE) { 2132: if ((ctxt_id == drawobj->context->id) && 2133: (ts == drawobj->timestamp)) 2134: _print_syncobj(adreno_dev, drawobj); 2135: } 2136: } 2137: } 2138: 2139: static void adreno_hwsched_snapshot_legacy(struct adreno_device *adreno_dev, int fault) 2140: { 2141: struct kgsl_drawobj *drawobj = NULL; 2142: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2143: struct kgsl_context *context = NULL; 2144: struct cmd_list_obj *obj; 2145: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 2146: struct hfi_context_bad_cmd_legacy *cmd = hwsched->ctxt_bad; 2147: 2148: if (hwsched->recurring_cmdobj) 2149: srcu_notifier_call_chain(&device->nh, GPU_SSR_BEGIN, NULL); 2150: 2151: if (cmd->error == GMU_SYNCOBJ_TIMEOUT_ERROR) { 2152: print_fault_syncobj(adreno_dev, cmd->ctxt_id, cmd->ts); 2153: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 2154: return; 2155: } 2156: 2157: /* MATCH LINES: 2198 2186: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 2187: else 2188: kgsl_device_snapshot(device, NULL, NULL, false); 2189: return; 2190: } 2191: 2192: context = drawobj->context; 2193: 2194: do_fault_header(adreno_dev, drawobj, fault); 2195: 2196: kgsl_device_snapshot(device, context, NULL, false); 2197: 2198: force_retire_timestamp(device, drawobj); 2199: 2200: if ((context->flags & KGSL_CONTEXT_INVALIDATE_ON_FAULT) || 2201: (context->flags & KGSL_CONTEXT_NO_FAULT_TOLERANCE) || 2202: (cmd->error == GMU_GPU_SW_HANG) || 2203: (cmd->error == GMU_GPU_SW_FUSE_VIOLATION) || 2204: context_is_throttled(device, context)) { 2205: adreno_drawctxt_set_guilty(device, context); 2206: } 2207: 2208: /* 2209: * Put back the reference which we incremented while trying to find 2210: * faulted command object 2211: */ 2212: kgsl_drawobj_put(drawobj); 2213: } 2214: 2215: static int adreno_hwsched_snapshot_and_soft_reset(struct adreno_device *adreno_dev, int fault) 2216: { 2217: struct kgsl_drawobj *drawobj = NULL; 2218: struct kgsl_drawobj *drawobj_lpac = NULL; 2219: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2220: struct kgsl_context *context = NULL; 2221: struct kgsl_context *context_lpac = NULL; 2222: struct cmd_list_obj *obj; MATCH LINES: 2307, 2330 2295: context_lpac = drawobj_lpac->context; 2296: if (gpudev->lpac_fault_header) 2297: gpudev->lpac_fault_header(adreno_dev, drawobj_lpac); 2298: } 2299: 2300: if (drawobj_lpac && drawobj_lpac->context) 2301: set_bit(ADRENO_CONTEXT_FAULT, &drawobj_lpac->context->priv); 2302: 2303: kgsl_device_snapshot(device, context, context_lpac, false); 2304: adreno_gpufault_stats(adreno_dev, drawobj, drawobj_lpac, fault); 2305: 2306: if (drawobj) { 2307: force_retire_timestamp(device, drawobj); 2308: if (context && ((context->flags & KGSL_CONTEXT_INVALIDATE_ON_FAULT) || 2309: (context->flags & KGSL_CONTEXT_NO_FAULT_TOLERANCE) || 2310: (cmd->error == GMU_GPU_SW_HANG) || 2311: (cmd->error == GMU_GPU_SW_FUSE_VIOLATION) || 2312: context_is_throttled(device, context))) { 2313: ctx_guilty = true; 2314: } 2315: 2316: if (gpudev->soft_reset) 2317: ret = gpudev->soft_reset(adreno_dev, context, ctx_guilty); 2318: 2319: if (ctx_guilty) 2320: adreno_drawctxt_set_guilty(device, context); 2321: /* 2322: * Put back the reference which we incremented while trying to find 2323: * faulted command object 2324: */ 2325: kgsl_drawobj_put(drawobj); 2326: } 2327: 2328: if (drawobj_lpac) { 2329: ctx_guilty = false; 2330: force_retire_timestamp(device, drawobj_lpac); 2331: if (context_lpac && ((context_lpac->flags & KGSL_CONTEXT_INVALIDATE_ON_FAULT) || 2332: (context_lpac->flags & KGSL_CONTEXT_NO_FAULT_TOLERANCE) || 2333: (cmd->error == GMU_GPU_SW_HANG) || 2334: (cmd->error == GMU_GPU_SW_FUSE_VIOLATION) || 2335: context_is_throttled(device, context_lpac))) { 2336: ctx_guilty = true; 2337: } 2338: 2339: if (gpudev->soft_reset) 2340: ret = gpudev->soft_reset(adreno_dev, context_lpac, ctx_guilty); 2341: 2342: if (ctx_guilty) 2343: adreno_drawctxt_set_guilty(device, context_lpac); 2344: /* 2345: * Put back the reference which we incremented while trying to find 2346: * faulted command object 2347: */ 2348: kgsl_drawobj_put(drawobj_lpac); 2349: } 2350: done: 2351: if (gpudev->soft_reset && !drawobj && !drawobj_lpac) 2352: ret = gpudev->soft_reset(adreno_dev, NULL, ctx_guilty); 2353: 2354: memset(hwsched->ctxt_bad, 0x0, HFI_MAX_MSG_SIZE); MATCH LINES: 2439, 2457, 2458, 2460, 2465, 2468, 2472, 2485, 2518 2427: 2428: if (adreno_hwsched_do_fault(adreno_dev)) { 2429: mutex_unlock(&hwsched->mutex); 2430: return; 2431: } 2432: 2433: /* 2434: * As long as there are inflight commands, process retired comamnds from 2435: * all drawqueues 2436: */ 2437: retire_drawobj_list(adreno_dev); 2438: 2439: /* Signal fences */ 2440: kgsl_process_event_groups(device); 2441: 2442: /* Run the scheduler for to dispatch new commands */ 2443: hwsched_issuecmds(adreno_dev); 2444: 2445: if (hwsched->inflight == 0) { 2446: hwsched_power_down(adreno_dev); 2447: } else { 2448: kgsl_mutex_lock(&device->mutex); 2449: kgsl_pwrscale_update(device); 2450: kgsl_start_idle_timer(device); 2451: kgsl_mutex_unlock(&device->mutex); 2452: } 2453: 2454: mutex_unlock(&hwsched->mutex); 2455: } 2456: 2457: static void adreno_hwsched_create_hw_fence(struct adreno_device *adreno_dev, 2458: struct kgsl_sync_fence *kfence) 2459: { 2460: struct kgsl_sync_timeline *ktimeline = kfence->parent; 2461: struct kgsl_context *context = ktimeline->context; 2462: const struct adreno_hwsched_ops *hwsched_ops = 2463: adreno_dev->hwsched.hwsched_ops; 2464: 2465: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags)) 2466: return; 2467: 2468: /* Do not create a hardware backed fence, if this context is bad or going away */ 2469: if (kgsl_context_is_bad(context)) 2470: return; 2471: 2472: hwsched_ops->create_hw_fence(adreno_dev, kfence); 2473: } 2474: 2475: static int adreno_hwsched_setup_context(struct adreno_device *adreno_dev, 2476: struct adreno_context *drawctxt) 2477: { 2478: return adreno_hwsched_alloc_preempt_record_gmem(adreno_dev, drawctxt); 2479: } 2480: 2481: static const struct adreno_dispatch_ops hwsched_ops = { 2482: .close = adreno_hwsched_dispatcher_close, 2483: .queue_cmds = adreno_hwsched_queue_cmds, 2484: .queue_context = adreno_hwsched_queue_context, 2485: .create_hw_fence = adreno_hwsched_create_hw_fence, 2486: .setup_context = adreno_hwsched_setup_context, 2487: }; 2488: 2489: static void hwsched_lsr_check(struct work_struct *work) 2490: { 2491: struct adreno_hwsched *hwsched = container_of(work, 2492: struct adreno_hwsched, lsr_check_ws); 2493: struct adreno_device *adreno_dev = container_of(hwsched, 2494: struct adreno_device, hwsched); 2495: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2496: 2497: kgsl_mutex_lock(&device->mutex); 2498: kgsl_pwrscale_update_stats(device); 2499: kgsl_pwrscale_update(device); 2500: kgsl_mutex_unlock(&device->mutex); 2501: 2502: mod_timer(&hwsched->lsr_timer, jiffies + msecs_to_jiffies(10)); 2503: } 2504: 2505: static void hwsched_lsr_timer(struct timer_list *t) 2506: { 2507: struct adreno_hwsched *hwsched = container_of(t, struct adreno_hwsched, 2508: lsr_timer); 2509: 2510: kgsl_schedule_work(&hwsched->lsr_check_ws); 2511: } 2512: 2513: int adreno_hwsched_init(struct adreno_device *adreno_dev, 2514: const struct adreno_hwsched_ops *target_hwsched_ops) 2515: { 2516: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2517: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 2518: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 2519: int i; 2520: 2521: memset(hwsched, 0, sizeof(*hwsched)); 2522: 2523: hwsched->ctxt_bad = kzalloc(HFI_MAX_MSG_SIZE, GFP_KERNEL); 2524: if (!hwsched->ctxt_bad) 2525: return -ENOMEM; 2526: 2527: adreno_dev->scheduler_worker = kgsl_kthread_run_worker(0, "kgsl_hwsched"); 2528: if (IS_ERR(adreno_dev->scheduler_worker)) { 2529: kfree(hwsched->ctxt_bad); 2530: return PTR_ERR(adreno_dev->scheduler_worker); 2531: } 2532: 2533: mutex_init(&hwsched->mutex); 2534: 2535: kthread_init_work(&adreno_dev->scheduler_work, adreno_hwsched_work); 2536: 2537: jobs_cache = KMEM_CACHE(adreno_dispatch_job, 0); 2538: obj_cache = KMEM_CACHE(cmd_list_obj, 0); 2539: 2540: INIT_LIST_HEAD(&hwsched->cmd_list); 2541: 2542: for (i = 0; i < ARRAY_SIZE(hwsched->jobs); i++) { MATCH LINES: 2630, 2631, 2633, 2635, 2636, 2639 2618: } 2619: 2620: /* 2621: * We don't need to send the unregister hfi packet because 2622: * we are anyway going to lose the gmu state of registered 2623: * contexts. So just reset the flag so that the context 2624: * registers with gmu on its first submission post slumber. 2625: */ 2626: context->gmu_registered = false; 2627: 2628: /* 2629: * Consider the scenario where non-recurring submissions were made 2630: * by a context. Here internal_timestamp of context would be non 2631: * zero. After slumber, last retired timestamp is not held by GMU. 2632: * If this context submits a recurring workload, the context is 2633: * registered again, but the internal timestamp is not updated. When 2634: * the context is unregistered in send_context_unregister_hfi(), 2635: * we could be waiting on old internal_timestamp which is not held by 2636: * GMU. This can result in GMU errors. Hence set internal_timestamp 2637: * to zero when entering slumber. 2638: */ 2639: drawctxt->internal_timestamp = 0; 2640: 2641: return 0; 2642: } 2643: 2644: void adreno_hwsched_unregister_contexts(struct adreno_device *adreno_dev) 2645: { 2646: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2647: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 2648: 2649: read_lock(&device->context_lock); 2650: idr_for_each(&device->context_idr, unregister_context, NULL); 2651: read_unlock(&device->context_lock); 2652: 2653: if (hwsched->global_ctxtq.hostptr) { 2654: struct gmu_context_queue_header *header = hwsched->global_ctxtq.hostptr; 2655: 2656: header->read_index = header->write_index; 2657: /* This is to make sure GMU sees the correct indices after recovery */ 2658: mb(); 2659: } 2660: 2661: hwsched->global_ctxt_gmu_registered = false; 2662: } 2663: MATCH LINES: 2772, 2778, 2781, 2784, 2791, 2792, 2794, 2795, 2797, 2799, 2800, 2804, 2806 2760: * without checking if the gpu is idle. check one last time before we 2761: * return failure. 2762: */ 2763: if (adreno_gpu_fault(adreno_dev)) 2764: return -EDEADLK; 2765: 2766: if (gpudev->hw_isidle(adreno_dev)) 2767: return 0; 2768: 2769: return -ETIMEDOUT; 2770: } 2771: 2772: void adreno_hwsched_register_hw_fence(struct adreno_device *adreno_dev) 2773: { 2774: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 2775: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2776: int ret; 2777: 2778: if (!ADRENO_FEATURE(adreno_dev, ADRENO_HW_FENCE)) 2779: return; 2780: 2781: if (test_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags)) 2782: return; 2783: 2784: if (kgsl_hw_fence_init(device)) 2785: return; 2786: 2787: /* 2788: * We need to set up the memory descriptor with the physical address of the Tx/Rx Queues so 2789: * that these buffers can be imported in to GMU VA space 2790: */ 2791: kgsl_memdesc_init(device, &hwsched->hw_fence.md, 0); 2792: kgsl_hw_fence_populate_md(device, &hwsched->hw_fence.md); 2793: 2794: ret = kgsl_memdesc_sg_dma(&hwsched->hw_fence.md, hwsched->hw_fence.md.physaddr, 2795: hwsched->hw_fence.md.size); 2796: if (ret) { 2797: dev_err(device->dev, "Failed to setup HW fences memdesc: %d\n", 2798: ret); 2799: kgsl_hw_fence_close(device); 2800: memset(&hwsched->hw_fence.md, 0x0, sizeof(hwsched->hw_fence.md)); 2801: return; 2802: } 2803: 2804: hwsched->hw_fence_cache = KMEM_CACHE(adreno_hw_fence_entry, 0); 2805: 2806: set_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags); 2807: } 2808: 2809: int adreno_hwsched_wait_ack_completion(struct adreno_device *adreno_dev, 2810: struct device *dev, struct pending_cmd *ack, 2811: void (*process_msgq)(struct adreno_device *adreno_dev)) 2812: { 2813: int rc; 2814: /* Only allow a single log in a second */ 2815: static DEFINE_RATELIMIT_STATE(_rs, HZ, 1); 2816: static u32 unprocessed, processed; 2817: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 2818: u64 start, end; 2819: 2820: start = gpudev->read_alwayson(adreno_dev); 2821: rc = wait_for_completion_timeout(&ack->complete, 2822: msecs_to_jiffies(HFI_RSP_TIMEOUT)); 2823: /* 2824: * A non-zero return value means the completion is complete, whereas zero indicates 2825: * timeout 2826: */ 2827: if (rc) { 2828: /* 2829: * If an ack goes unprocessed, keep track of processed and unprocessed acks 2830: * because we may not log each unprocessed ack due to ratelimiting MATCH LINES: 2983, 2987, 2988, 2999, 3003, 3013 2971: u32 id = adreno_hwsched_parse_payload(payload, KEY_RB_ID); 2972: 2973: if (id == rb_id) 2974: return adreno_hwsched_parse_payload(payload, key); 2975: } 2976: 2977: i += struct_size(payload, data, payload->dwords); 2978: } 2979: 2980: return 0; 2981: } 2982: 2983: void adreno_hwsched_log_remove_pending_hw_fences(struct adreno_device *adreno_dev, 2984: struct device *dev) 2985: { 2986: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2987: struct adreno_hw_fence_entry entries[5]; 2988: struct adreno_hw_fence_entry *entry, *next; 2989: struct kgsl_context *context; 2990: int id, i; 2991: u32 count = 0; 2992: 2993: read_lock(&device->context_lock); 2994: idr_for_each_entry(&device->context_idr, context, id) { 2995: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 2996: 2997: spin_lock(&drawctxt->lock); 2998: 2999: list_for_each_entry_safe(entry, next, &drawctxt->hw_fence_list, node) { 3000: if (count < ARRAY_SIZE(entries)) 3001: memcpy(&entries[count], entry, sizeof(*entry)); 3002: count++; 3003: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 3004: } 3005: 3006: spin_unlock(&drawctxt->lock); 3007: } 3008: read_unlock(&device->context_lock); 3009: 3010: if (!count) 3011: return; 3012: 3013: dev_err(dev, "%d hw fences may not be signaled. %s are:\n", count, 3014: count > 5 ? "First 5" : "They"); 3015: 3016: for (i = 0; (i < count) && (i < ARRAY_SIZE(entries)); i++) 3017: dev_err(dev, "%d: ctx=%llu seqno=%llu\n", i, entries[i].cmd.ctxt_id, 3018: entries[i].cmd.ts); 3019: } 3020: 3021: static void adreno_hwsched_lookup_key_value(struct adreno_device *adreno_dev, 3022: u32 type, u32 key, u32 *ptr, u32 num_values) 3023: { 3024: struct hfi_context_bad_cmd *cmd = adreno_dev->hwsched.ctxt_bad; 3025: u32 i = 0, payload_bytes; 3026: void *start; 3027: 3028: if (!cmd->hdr) 3029: return; 3030: 3031: payload_bytes = (MSG_HDR_GET_SIZE(cmd->hdr) << 2) - 3032: offsetof(struct hfi_context_bad_cmd, payload); 3033: 3034: start = &cmd->payload[0]; 3035: 3036: while (i < payload_bytes) { 3037: struct payload_section *payload = start + i; MATCH LINES: 3130, 3131, 3135, 3140, 3142, 3144, 3180, 3202, 3207 3118: 3119: done: 3120: /* 3121: * This is to ensure that the queue is not read speculatively before the 3122: * polling condition is evaluated. 3123: */ 3124: rmb(); 3125: 3126: return 0; 3127: } 3128: 3129: /* This function can be called while holding the drawctxt spinlock */ 3130: void adreno_hwsched_remove_hw_fence_entry(struct adreno_device *adreno_dev, 3131: struct adreno_hw_fence_entry *entry) 3132: { 3133: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3134: struct adreno_context *drawctxt = entry->drawctxt; 3135: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3136: 3137: spin_lock(&hwf->lock); 3138: hwf->pending_count--; 3139: spin_unlock(&hwf->lock); 3140: drawctxt->hw_fence_count--; 3141: 3142: dma_fence_put(&entry->kfence->fence); 3143: list_del_init(&entry->node); 3144: kmem_cache_free(hwsched->hw_fence_cache, entry); 3145: kgsl_context_put_deferred(&drawctxt->base); 3146: } 3147: 3148: void adreno_hwsched_add_profile_events(struct adreno_device *adreno_dev, 3149: struct kgsl_drawobj_cmd *cmdobj, struct adreno_submit_time *time) 3150: { 3151: unsigned long flags; 3152: u64 time_in_s; 3153: unsigned long time_in_ns; 3154: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 3155: struct kgsl_context *context = drawobj->context; 3156: struct submission_info info = {0}; 3157: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3158: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 3159: 3160: if (!time) 3161: return; 3162: 3163: /* 3164: * Here we are attempting to create a mapping between the 3165: * GPU time domain (alwayson counter) and the CPU time domain 3166: * (local_clock) by sampling both values as close together as 3167: * possible. This is useful for many types of debugging and 3168: * profiling. In order to make this mapping as accurate as 3169: * possible, we must turn off interrupts to avoid running 3170: * interrupt handlers between the two samples. 3171: */ 3172: 3173: local_irq_save(flags); 3174: 3175: /* Read always on registers */ 3176: time->ticks = gpudev->read_alwayson(adreno_dev); 3177: 3178: /* Trace the GPU time to create a mapping to ftrace time */ 3179: trace_adreno_cmdbatch_sync(context->id, context->priority, 3180: drawobj->timestamp, time->ticks); 3181: 3182: /* Get the kernel clock for time since boot */ 3183: time->ktime = local_clock(); 3184: 3185: /* Get the timeofday for the wall time (for the user) */ 3186: ktime_get_real_ts64(&time->utime); 3187: 3188: local_irq_restore(flags); 3189: 3190: /* Return kernel clock time to the client if requested */ 3191: time_in_s = time->ktime; 3192: time_in_ns = do_div(time_in_s, 1000000000); 3193: 3194: info.inflight = hwsched->inflight; 3195: info.rb_id = adreno_get_level(context); 3196: info.gmu_dispatch_queue = context->gmu_dispatch_queue; 3197: 3198: cmdobj->submit_ticks = time->ticks; 3199: 3200: msm_perf_events_update(MSM_PERF_GFX, MSM_PERF_SUBMIT, 3201: pid_nr(context->proc_priv->pid), 3202: context->id, drawobj->timestamp, 3203: !!(drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME)); 3204: trace_adreno_cmdbatch_submitted(drawobj, &info, time->ticks, 3205: (unsigned long) time_in_s, time_in_ns / 1000, 0); 3206: 3207: log_kgsl_cmdbatch_submitted_event(context->id, drawobj->timestamp, 3208: context->priority, drawobj->flags); 3209: } 3210: 3211: int adreno_gmu_context_queue_write(struct adreno_device *adreno_dev, 3212: struct kgsl_memdesc *gmu_context_queue, u32 *msg, u32 size_bytes, 3213: struct kgsl_drawobj *drawobj, struct adreno_submit_time *time) 3214: { 3215: struct gmu_context_queue_header *hdr = gmu_context_queue->hostptr; 3216: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 3217: u32 *queue = gmu_context_queue->hostptr + sizeof(*hdr); 3218: u32 i, empty_space, write_idx = hdr->write_index, read_idx = hdr->read_index; 3219: u32 size_dwords = size_bytes >> 2; 3220: u32 align_size = ALIGN(size_dwords, SZ_4); 3221: u32 id = MSG_HDR_GET_ID(*msg); 3222: struct kgsl_drawobj_cmd *cmdobj = NULL; 3223: 3224: empty_space = (write_idx >= read_idx) ? 3225: (hdr->queue_size - (write_idx - read_idx)) 3226: : (read_idx - write_idx); 3227: 3228: if (empty_space <= align_size) 3229: return -ENOSPC; 3230: 3231: if (!IS_ALIGNED(size_bytes, sizeof(u32))) MATCH LINES: 3254, 3255, 3291, 3295, 3297, 3302, 3306, 3309, 3312, 3328, 3350 3242: write_idx = (write_idx + 1) % hdr->queue_size; 3243: } 3244: 3245: /* Ensure packet is written out before proceeding */ 3246: wmb(); 3247: 3248: if (!drawobj) 3249: goto done; 3250: 3251: if (drawobj->type & SYNCOBJ_TYPE) { 3252: struct kgsl_drawobj_sync *syncobj = SYNCOBJ(drawobj); 3253: 3254: trace_adreno_syncobj_submitted(drawobj->context->id, drawobj->timestamp, 3255: syncobj->num_hw_fence, gpudev->read_alwayson(adreno_dev)); 3256: goto done; 3257: } 3258: 3259: cmdobj = CMDOBJ(drawobj); 3260: 3261: adreno_hwsched_add_profile_events(adreno_dev, cmdobj, time); 3262: 3263: /* 3264: * Put the profiling information in the user profiling buffer. 3265: * The hfi_update_write_idx below has a wmb() before the actual 3266: * write index update to ensure that the GMU does not see the 3267: * packet before the profile data is written out. 3268: */ 3269: adreno_profile_submit_time(time); 3270: 3271: done: 3272: trace_kgsl_hfi_send(id, size_dwords, MSG_HDR_GET_SEQNUM(*msg)); 3273: 3274: hfi_update_write_idx(&hdr->write_index, write_idx); 3275: 3276: return 0; 3277: } 3278: 3279: int adreno_hwsched_drain_and_idle(struct adreno_device *adreno_dev) 3280: { 3281: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3282: int ret = adreno_drain(device, msecs_to_jiffies(100)); 3283: 3284: /* Make sure the dispatcher and hardware are idle */ 3285: if (!ret) 3286: ret = adreno_hwsched_idle(adreno_dev); 3287: 3288: return ret; 3289: } 3290: 3291: static void _retire_inflight_hw_fences(struct adreno_device *adreno_dev, 3292: struct kgsl_context *context) 3293: { 3294: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 3295: struct adreno_hw_fence_entry *entry, *tmp; 3296: 3297: if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags)) 3298: return; 3299: 3300: spin_lock(&drawctxt->lock); 3301: 3302: list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) { 3303: struct gmu_context_queue_header *hdr = drawctxt->gmu_context_queue.hostptr; 3304: 3305: /* 3306: * Since this list is sorted by timestamp, abort on the first fence that hasn't 3307: * yet been sent to TxQueue 3308: */ 3309: if (timestamp_cmp((u32)entry->cmd.ts, hdr->out_fence_ts) > 0) 3310: break; 3311: 3312: adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry); 3313: } 3314: spin_unlock(&drawctxt->lock); 3315: } 3316: 3317: void adreno_hwsched_log_profiling_info(struct adreno_device *adreno_dev, u32 *rcvd) 3318: { 3319: struct hfi_ts_retire_cmd *cmd = (struct hfi_ts_retire_cmd *)rcvd; 3320: struct kgsl_context *context; 3321: struct retire_info info = {0}; 3322: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3323: 3324: context = kgsl_context_get(device, cmd->ctxt_id); 3325: if (context == NULL) 3326: return; 3327: 3328: info.timestamp = cmd->ts; 3329: info.rb_id = adreno_get_level(context); 3330: info.gmu_dispatch_queue = context->gmu_dispatch_queue; 3331: info.submitted_to_rb = cmd->submitted_to_rb; 3332: info.sop = cmd->sop; 3333: info.eop = cmd->eop; 3334: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 4) 3335: info.active = cmd->eop - cmd->sop; 3336: else 3337: info.active = cmd->active; 3338: info.retired_on_gmu = cmd->retired_on_gmu; 3339: 3340: /* protected GPU work must not be reported */ 3341: if (!(context->flags & KGSL_CONTEXT_SECURE)) 3342: kgsl_work_period_update(device, context->proc_priv->period, 3343: info.active); 3344: 3345: trace_adreno_cmdbatch_retired(context, &info, 0, 0, 0); 3346: 3347: log_kgsl_cmdbatch_retired_event(context->id, cmd->ts, 3348: context->priority, 0, cmd->sop, cmd->eop); 3349: 3350: _retire_inflight_hw_fences(adreno_dev, context); 3351: 3352: kgsl_context_put(context); 3353: } 3354: 3355: void *adreno_hwsched_get_rb_hostptr(struct adreno_device *adreno_dev, 3356: u64 gpuaddr, u32 size) 3357: { 3358: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3359: u64 offset; 3360: u32 i; 3361: 3362: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 3363: struct kgsl_memdesc *md = hwsched->mem_alloc_table[i].md; 3364: 3365: if (kgsl_gpuaddr_in_memdesc(md, gpuaddr, size)) { 3366: offset = gpuaddr - md->gpuaddr; 3367: return md->hostptr + offset; 3368: } 3369: } 3370: 3371: return NULL; 3372: } 3373: 3374: void adreno_hwsched_reset_hfi_mem(struct adreno_device *adreno_dev) --- FILE: \adreno_hwsched.h | HITS: 43 --- MATCH LINES: 21, 22, 25, 30, 35, 36, 40, 44, 47, 51, 53, 58, 60, 61, 62, 63, 64, 69, 92, 94, 95 9: 10: #include "adreno_hfi.h" 11: #include "kgsl_sync.h" 12: 13: /* This structure represents inflight command object */ 14: struct cmd_list_obj { 15: /** @drawobj: Handle to the draw object */ 16: struct kgsl_drawobj *drawobj; 17: /** @node: List node to put it in the list of inflight commands */ 18: struct list_head node; 19: }; 20: 21: struct adreno_hwsched_hw_fence { 22: /** @lock: Spinlock for managing hardware fences */ 23: spinlock_t lock; 24: /** 25: * @unack_count: Number of hardware fences sent to GMU but haven't yet been ack'd 26: * by GMU 27: */ 28: u32 unack_count; 29: /** 30: * @unack_wq: Waitqueue to wait on till number of unacked hardware fences drops to 31: * a desired threshold 32: */ 33: wait_queue_head_t unack_wq; 34: /** 35: * @defer_drawctxt: Drawctxt to send hardware fences from as soon as unacked 36: * hardware fences drops to a desired threshold 37: */ 38: struct adreno_context *defer_drawctxt; 39: /** 40: * @defer_ts: The timestamp of the hardware fence which got deferred 41: */ 42: u32 defer_ts; 43: /** 44: * @flags: Flags to control the creation of new hardware fences 45: */ 46: unsigned long flags; 47: /** @seqnum: Sequence number for hardware fence packet header */ 48: atomic_t seqnum; 49: /** @soccp_rproc: rproc handle for soccp */ 50: struct rproc *soccp_rproc; 51: /** @hw_fence_md: Kgsl memory descriptor for hardware fences queue */ 52: struct kgsl_memdesc md; 53: /** @pending_count: Number of hardware fences that haven't yet been sent to Tx Queue */ 54: u32 pending_count; 55: }; 56: 57: /** 58: * struct adreno_hw_fence_entry - A structure to store hardware fence and the context 59: */ 60: struct adreno_hw_fence_entry { 61: /** @cmd: H2F_MSG_HW_FENCE_INFO packet for this hardware fence */ 62: struct hfi_hw_fence_info cmd; 63: /** @kfence: Pointer to the kgsl fence */ 64: struct kgsl_sync_fence *kfence; 65: /** @drawctxt: Pointer to the context */ 66: struct adreno_context *drawctxt; 67: /** @node: list node to add it to a list */ 68: struct list_head node; 69: /** @reset_node: list node to add it to post reset list of hardware fences */ 70: struct list_head reset_node; 71: }; 72: 73: /** 74: * struct adreno_hwsched_ops - Function table to hook hwscheduler things 75: * to target specific routines 76: */ 77: struct adreno_hwsched_ops { 78: /** 79: * @submit_drawobj - Target specific function to submit IBs to hardware 80: */ 81: int (*submit_drawobj)(struct adreno_device *adreno_dev, 82: struct kgsl_drawobj *drawobj); 83: /** 84: * @preempt_count - Target specific function to get preemption count 85: */ 86: u32 (*preempt_count)(struct adreno_device *adreno_dev); 87: /** 88: * @preempt_info - Target specific function to get preemption information 89: */ 90: ssize_t (*preempt_info)(struct adreno_device *adreno_dev, char *buf); 91: /** 92: * @create_hw_fence - Target specific function to create a hardware fence 93: */ 94: void (*create_hw_fence)(struct adreno_device *adreno_dev, 95: struct kgsl_sync_fence *kfence); 96: /** 97: * @set_dcvs_profile - Set dcvs profile for a process 98: */ 99: int (*set_dcvs_profile)(struct adreno_device *adreno_dev, 100: struct kgsl_process_private *proc_priv); 101: }; 102: 103: enum gpu_reset_type { 104: GMU_GPU_RESET_NONE, 105: GMU_GPU_SOFT_RESET, 106: GMU_GPU_HARD_RESET, 107: }; 108: 109: struct adreno_dcvs_tunable { 110: /** @value: Stores the requested value for the tunable **/ 111: u32 value; 112: /** @update: True if this value needs to be sent to GMU at slumber exit **/ 113: bool update; 114: }; 115: 116: /** 117: * struct adreno_hwsched - Container for the hardware scheduler 118: */ 119: struct adreno_hwsched { MATCH LINES: 150, 151, 161, 162 138: /** @ctxt_bad: Container for the context bad hfi packet */ 139: void *ctxt_bad; 140: /** @idle_gate: Gate to wait on for hwscheduler to idle */ 141: struct completion idle_gate; 142: /** @big_cmdobj = Points to the big IB that is inflight */ 143: struct kgsl_drawobj_cmd *big_cmdobj; 144: /** @recurring_cmdobj: Recurring commmand object sent to GMU */ 145: struct kgsl_drawobj_cmd *recurring_cmdobj; 146: /** @lsr_timer: Timer struct to schedule lsr work */ 147: struct timer_list lsr_timer; 148: /** @lsr_check_ws: Lsr work to update power stats */ 149: struct work_struct lsr_check_ws; 150: /** @hw_fence: Container for the hw fences instance */ 151: struct kmem_cache *hw_fence_cache; 152: /** 153: * @submission_seqnum: Sequence number for sending submissions to GMU context queues or 154: * dispatch queues 155: */ 156: atomic_t submission_seqnum; 157: /** @global_ctxtq: Memory descriptor for global context queue */ 158: struct kgsl_memdesc global_ctxtq; 159: /** @global_ctxt_gmu_registered: Whether global context is registered with gmu */ 160: bool global_ctxt_gmu_registered; 161: /** @hw_fence: Container for hw fence related structures */ 162: struct adreno_hwsched_hw_fence hw_fence; 163: /** @reset_type: GPU fault reset (hard/soft) type */ 164: enum gpu_reset_type reset_type; 165: /** @preempt_rec: Memory descriptors for non-gmem part of preemption records */ 166: struct kgsl_memdesc *preempt_rec[KGSL_PRIORITY_MAX_RB_LEVELS]; 167: /** 168: * @preempt_rec_gmem: Memory descriptors for gmem part of preemption 169: * records. No gmem buffer needed for rb0 preemption record. 170: */ 171: struct kgsl_memdesc *preempt_rec_gmem[KGSL_PRIORITY_MAX_RB_LEVELS - 1]; 172: /** 173: * @secure_preempt_rec: Memory descriptors for non-gmem part of secure 174: * preemption records 175: */ 176: struct kgsl_memdesc *secure_preempt_rec[KGSL_PRIORITY_MAX_RB_LEVELS]; 177: /** 178: * @secure_preempt_rec_gmem: Memory descriptors for gmem part of secure 179: * preemption records. No gmem buffer needed for rb0 preemption record. 180: */ 181: struct kgsl_memdesc *secure_preempt_rec_gmem[KGSL_PRIORITY_MAX_RB_LEVELS - 1]; 182: /** @dcvs_param_update: True if dcvs params have to be sent to GMU at slumber exit */ 183: bool dcvs_param_update; 184: /** @tunables_kobj: Kobj for dcvs tunables **/ 185: struct kobject tunables_kobj; 186: /** @dcvs_kobj: Kobj for dcvs params **/ MATCH LINES: 205 193: 194: /* 195: * This value is based on maximum number of IBs that can fit 196: * in the ringbuffer. 197: */ 198: #define HWSCHED_MAX_IBS 2000 199: 200: enum adreno_hwsched_flags { 201: ADRENO_HWSCHED_POWER = 0, 202: ADRENO_HWSCHED_ACTIVE, 203: ADRENO_HWSCHED_CTX_BAD_LEGACY, 204: ADRENO_HWSCHED_CONTEXT_QUEUE, 205: ADRENO_HWSCHED_HW_FENCE, 206: ADRENO_HWSCHED_FORCE_RETIRE_GMU, 207: ADRENO_HWSCHED_GPU_SOFT_RESET, 208: }; 209: 210: /** 211: * adreno_hwsched_process_mem_alloc - Process memory allocation for hwsched 212: * @adreno_dev: Pointer to the adreno device 213: * @mad: Pointer to the HFI memory allocation descriptor 214: * 215: * This function processes the memory allocation request for the hwsched. 216: * It retrieves or allocates the necessary memory based on the provided 217: * descriptor and updates the descriptor with the allocated memory addresses. 218: * 219: * Return: 0 on success, or a negative error code on failure. 220: */ 221: int adreno_hwsched_process_mem_alloc(struct adreno_device *adreno_dev, 222: struct hfi_mem_alloc_desc *mad); 223: 224: /** 225: * adreno_hwsched_start() - activate the hwsched dispatcher 226: * @adreno_dev: pointer to the adreno device 227: * 228: * Enable dispatcher thread to execute 229: */ MATCH LINES: 277, 280, 281, 284, 287, 290, 291, 293 265: * @adreno_dev: A handle to adreno device 266: * 267: * Return: 0 on success or negative error on failure 268: */ 269: int adreno_hwsched_drain_and_idle(struct adreno_device *adreno_dev); 270: 271: void adreno_hwsched_retire_cmdobj(struct adreno_hwsched *hwsched, 272: struct kgsl_drawobj_cmd *cmdobj); 273: 274: bool adreno_hwsched_context_queue_enabled(struct adreno_device *adreno_dev); 275: 276: /** 277: * adreno_hwsched_register_hw_fence - Register GPU as a hardware fence client 278: * @adreno_dev: pointer to the adreno device 279: * 280: * Register with the hardware fence driver to be able to trigger and wait 281: * for hardware fences. Also, set up the memory descriptor for mapping the 282: * client queue to the GMU. 283: */ 284: void adreno_hwsched_register_hw_fence(struct adreno_device *adreno_dev); 285: 286: /** 287: * adreno_hwsched_deregister_hw_fence - Deregister GPU as a hardware fence client 288: * @adreno_dev: pointer to the adreno device 289: * 290: * Deregister with the hardware fence driver and free up any resources allocated 291: * as part of registering with the hardware fence driver 292: */ 293: void adreno_hwsched_deregister_hw_fence(struct adreno_device *adreno_dev); 294: 295: /** 296: * adreno_hwsched_replay - Resubmit inflight cmdbatches after gpu reset 297: * @adreno_dev: pointer to the adreno device 298: * 299: * Resubmit all cmdbatches to GMU after device reset 300: */ 301: void adreno_hwsched_replay(struct adreno_device *adreno_dev); 302: 303: /** 304: * adreno_hwsched_parse_payload - Parse payload to look up a key 305: * @payload: Pointer to a payload section 306: * @key: The key who's value is to be looked up 307: * 308: * This function parses the payload data which is a sequence 309: * of key-value pairs. 310: * 311: * Return: The value of the key or 0 if key is not found 312: */ 313: u32 adreno_hwsched_parse_payload(struct payload_section *payload, u32 key); 314: 315: /** 316: * adreno_hwsched_get_payload_rb_key - Retrieve the payload based on ring buffer key 317: * @adreno_dev: Pointer to the adreno device MATCH LINES: 345, 350, 354, 358, 382, 384, 386, 387 333: */ 334: u32 adreno_hwsched_get_payload_rb_key_legacy(struct adreno_device *adreno_dev, u32 rb_id, u32 key); 335: 336: /** 337: * adreno_hwsched_gpu_fault - Gets hwsched gpu fault info 338: * @adreno_dev: pointer to the adreno device 339: * 340: * Returns zero for hwsched fault else non zero value 341: */ 342: u32 adreno_hwsched_gpu_fault(struct adreno_device *adreno_dev); 343: 344: /** 345: * adreno_hwsched_log_remove_pending_fences - Log and remove any pending hardware fences if soccp 346: * vote failed 347: * @adreno_dev: pointer to the adreno device 348: * @dev: Pointer to the gmu pdev device 349: */ 350: void adreno_hwsched_log_remove_pending_hw_fences(struct adreno_device *adreno_dev, 351: struct device *dev); 352: 353: /** 354: * adreno_hwsched_syncobj_kfence_put - Put back kfence context refcounts for this sync object 355: * @syncobj: Pointer to the sync object 356: * 357: */ 358: void adreno_hwsched_syncobj_kfence_put(struct kgsl_drawobj_sync *syncobj); 359: 360: /** 361: * adreno_hwsched_log_nonfatal_gpu_fault - Logs non fatal GPU error from context bad hfi packet 362: * @adreno_dev: pointer to the adreno device 363: * @dev: Pointer to the struct device for the GMU platform device 364: * @error: Types of error that triggered from context bad HFI 365: * 366: * This function parses context bad hfi packet and logs error information. 367: * 368: * Return: True for non fatal error code else false. 369: */ 370: bool adreno_hwsched_log_nonfatal_gpu_fault(struct adreno_device *adreno_dev, 371: struct device *dev, u32 error); 372: 373: /** 374: * adreno_hwsched_poll_msg_queue_write_index - Poll on write index of HFI message queue 375: * @hfi_mem: Memory descriptor for HFI queue table 376: * 377: * Returns zero if write index advances or ETIMEDOUT if timed out polling 378: */ 379: int adreno_hwsched_poll_msg_queue_write_index(struct kgsl_memdesc *hfi_mem); 380: 381: /** 382: * adreno_hwsched_remove_hw_fence_entry - Remove hardware fence entry 383: * @adreno_dev: pointer to the adreno device 384: * @entry: Pointer to the hardware fence entry 385: */ 386: void adreno_hwsched_remove_hw_fence_entry(struct adreno_device *adreno_dev, 387: struct adreno_hw_fence_entry *entry); 388: 389: /** 390: * adreno_gmu_context_queue_read - Read data from context queue 391: * @drawctxt: Pointer to the adreno draw context 392: * @output: Pointer to read the data into 393: * @read_idx: Index to read the data from 394: * @size: Number of dwords to read from the context queue 395: * 396: * Return: 0 on success or negative error on failure 397: */ 398: int adreno_gmu_context_queue_read(struct adreno_context *drawctxt, u32 *output, 399: u32 read_idx, u32 size); 400: 401: /** 402: * adreno_gmu_context_queue_write - Write data to context queue 403: * 404: * @adreno_dev: Pointer to adreno device structure 405: * @gmu_context_queue: Pointer to the memory descriptor for context queue 406: * @msg: Pointer to the message data to be written 407: * @size_bytes: Size of the message data in bytes 408: * @drawobj: Pointer to the draw object 409: * @time: Pointer to the submission time information 410: * 411: * Return: 0 on success or negative error on failure MATCH LINES: 431 419: * 420: * @adreno_dev: Pointer to the adreno device structure 421: * @cmdobj: Pointer to the command object 422: * @time: Pointer to the submission time information 423: */ 424: void adreno_hwsched_add_profile_events(struct adreno_device *adreno_dev, 425: struct kgsl_drawobj_cmd *cmdobj, struct adreno_submit_time *time); 426: 427: /** 428: * adreno_hwsched_log_profiling_info - Log profiling information for a retired 429: * command batch 430: * @adreno_dev: Pointer to the adreno device structure 431: * @rcvd: Pointer to the received HFI timestamp retire command 432: */ 433: void adreno_hwsched_log_profiling_info(struct adreno_device *adreno_dev, u32 *rcvd); 434: 435: /** 436: * adreno_hwsched_drawobj_replay - Check drawobj need to be replayed or not 437: * @adreno_dev: Pointer to the adreno device structure 438: * @drawobj: Pointer to the draw object 439: * 440: * Return true if drawobj needs to replayed, false otherwise 441: */ 442: bool adreno_hwsched_drawobj_replay(struct adreno_device *adreno_dev, 443: struct kgsl_drawobj *drawobj); 444: 445: /** 446: * adreno_hwsched_get_rb_hostptr - Get the host pointer for a given GPU address 447: * @adreno_dev: Pointer to the adreno device 448: * @gpuaddr: GPU address to look up 449: * @size: Size of the memory region 450: * 451: * This function retrieves the host pointer corresponding to a given GPU address. 452: * It searches through the memory allocation table to find the matching memory 453: * descriptor and calculates the host pointer offset. 454: * 455: * Return: Host pointer if found, or NULL if the GPU address is not found in the --- FILE: \adreno_hwsched_snapshot.c | HITS: 4 --- MATCH LINES: 27, 28 15: struct kgsl_memdesc *rb = (struct kgsl_memdesc *)priv; 16: 17: if (remain < rb->size + sizeof(*header)) { 18: SNAPSHOT_ERR_NOMEM(device, "RB"); 19: return 0; 20: } 21: 22: header->start = 0; 23: header->end = rb->size >> 2; 24: header->rptr = 0; 25: header->rbsize = rb->size >> 2; 26: header->count = rb->size >> 2; 27: header->timestamp_queued = 0; 28: header->timestamp_retired = 0; 29: header->gpuaddr = rb->gpuaddr; 30: header->id = 0; 31: 32: memcpy(data, rb->hostptr, rb->size); 33: 34: return rb->size + sizeof(*header); 35: } 36: 37: static u32 copy_gpu_global(void *out, void *in, u32 size) 38: { 39: if (out && in) { 40: memcpy(out, in, size); 41: return size; 42: } 43: 44: return 0; 45: } 46: 47: static void adreno_hwsched_snapshot_rb_payload(struct adreno_device *adreno_dev, 48: struct kgsl_snapshot *snapshot, struct payload_section *payload) 49: { 50: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 51: struct kgsl_snapshot_section_header *section_header = 52: (struct kgsl_snapshot_section_header *)snapshot->ptr; MATCH LINES: 99, 101 87: 88: /* Parse all IBs from current RB */ 89: if ((rbaddr == gpuaddr) || (lpac_rbaddr == gpuaddr)) 90: adreno_snapshot_dump_all_ibs(device, rb_hostptr, snapshot); 91: } 92: 93: header->start = 0; 94: header->end = size >> 2; 95: header->rptr = adreno_hwsched_parse_payload(payload, KEY_RB_RPTR); 96: header->wptr = adreno_hwsched_parse_payload(payload, KEY_RB_WPTR); 97: header->rbsize = size >> 2; 98: header->count = size >> 2; 99: header->timestamp_queued = adreno_hwsched_parse_payload(payload, 100: KEY_RB_QUEUED_TS); 101: header->timestamp_retired = adreno_hwsched_parse_payload(payload, 102: KEY_RB_RETIRED_TS); 103: header->gpuaddr = gpuaddr; 104: header->id = adreno_hwsched_parse_payload(payload, KEY_RB_ID); 105: 106: section_header->magic = SNAPSHOT_SECTION_MAGIC; 107: section_header->id = KGSL_SNAPSHOT_SECTION_RB_V2; 108: section_header->size = size + sizeof(*header) + sizeof(*section_header); 109: 110: snapshot->ptr += section_header->size; 111: snapshot->remain -= section_header->size; 112: snapshot->size += section_header->size; 113: 114: return; 115: err: 116: snprintf(str, sizeof(str), "RB addr:0x%llx", gpuaddr); 117: SNAPSHOT_ERR_NOMEM(device, str); 118: } 119: 120: bool adreno_hwsched_parse_payload_rb_legacy(struct adreno_device *adreno_dev, 121: struct kgsl_snapshot *snapshot) 122: { 123: struct hfi_context_bad_cmd_legacy *cmd = adreno_dev->hwsched.ctxt_bad; 124: u32 i = 0, payload_bytes; 125: void *start; --- FILE: \adreno_ioctl.c | HITS: 5 --- MATCH LINES: 186, 195, 199 174: return -EFAULT; 175: 176: read->max_priority_level = levels_to_copy; 177: read->size_priority_level = size_level; 178: 179: return 0; 180: } 181: 182: static long adreno_ioctl_read_calibrated_ts(struct kgsl_device_private *dev_priv, 183: unsigned int cmd, void *data) 184: { 185: struct adreno_device *adreno_dev = ADRENO_DEVICE(dev_priv->device); 186: struct kgsl_read_calibrated_timestamps *reads = data; 187: unsigned long flags; 188: u32 *sources = NULL; 189: u64 *ts = NULL; 190: u64 start; 191: u64 samples[KGSL_CALIBRATED_TIME_DOMAIN_MAX] = {0}; 192: u32 i; 193: int ret = 0; 194: 195: /* Reading calibrated timestamps requires the CX timer be initialized */ 196: if (!test_bit(ADRENO_DEVICE_CX_TIMER_INITIALIZED, &adreno_dev->priv)) 197: return -EOPNOTSUPP; 198: 199: /* Check that the number of timestamps is reasonable */ 200: if (!reads->count || 201: (reads->count > (2 * KGSL_CALIBRATED_TIME_DOMAIN_MAX))) 202: return -EINVAL; 203: 204: sources = kvcalloc(reads->count, sizeof(*sources), GFP_KERNEL); 205: if (!sources) 206: return -ENOMEM; 207: 208: if (copy_from_user(sources, u64_to_user_ptr(reads->sources), 209: reads->count * sizeof(*sources))) { 210: ret = -EFAULT; 211: goto done; 212: } 213: 214: for (i = 0; i < reads->count; i++) { 215: if (sources[i] >= KGSL_CALIBRATED_TIME_DOMAIN_MAX) { 216: ret = -EINVAL; 217: goto done; 218: } 219: } 220: 221: ts = kvcalloc(reads->count, sizeof(*ts), GFP_KERNEL); 222: if (!ts) { 223: ret = -ENOMEM; MATCH LINES: 240 228: local_irq_save(flags); 229: 230: /* Sample the MONOTONIC_RAW domain for use in calculating deviation */ 231: start = (u64)ktime_to_ns(ktime_get_raw()); 232: 233: samples[KGSL_CALIBRATED_TIME_DOMAIN_DEVICE] = 234: adreno_read_cx_timer(adreno_dev); 235: samples[KGSL_CALIBRATED_TIME_DOMAIN_MONOTONIC] = 236: (u64)ktime_to_ns(ktime_get()); 237: samples[KGSL_CALIBRATED_TIME_DOMAIN_MONOTONIC_RAW] = 238: (u64)ktime_to_ns(ktime_get_raw()); 239: 240: /* Done collecting timestamps. Re-enable irqs */ 241: local_irq_restore(flags); 242: 243: /* Calculate deviation in reads based on the MONOTONIC_RAW samples */ 244: reads->deviation = samples[KGSL_CALIBRATED_TIME_DOMAIN_MONOTONIC_RAW] - start; 245: 246: for (i = 0; i < reads->count; i++) 247: ts[i] = samples[sources[i]]; 248: 249: if (copy_to_user(u64_to_user_ptr(reads->ts), ts, reads->count * sizeof(*ts))) 250: ret = -EFAULT; 251: 252: done: 253: kvfree(ts); 254: kvfree(sources); 255: return ret; 256: } 257: 258: long adreno_ioctl_helper(struct kgsl_device_private *dev_priv, 259: unsigned int cmd, unsigned long arg, 260: const struct kgsl_ioctl *cmds, int len) 261: { 262: unsigned char data[128] = { 0 }; 263: long ret; 264: int i; MATCH LINES: 305 293: ret = kgsl_ioctl_copy_out(cmds[i].cmd, cmd, arg, data); 294: 295: return ret; 296: } 297: 298: static struct kgsl_ioctl adreno_ioctl_funcs[] = { 299: { IOCTL_KGSL_PERFCOUNTER_GET, adreno_ioctl_perfcounter_get }, 300: { IOCTL_KGSL_PERFCOUNTER_PUT, adreno_ioctl_perfcounter_put }, 301: { IOCTL_KGSL_PERFCOUNTER_QUERY, adreno_ioctl_perfcounter_query }, 302: { IOCTL_KGSL_PERFCOUNTER_READ, adreno_ioctl_perfcounter_read }, 303: { IOCTL_KGSL_PREEMPTIONCOUNTER_QUERY, 304: adreno_ioctl_preemption_counters_query }, 305: { IOCTL_KGSL_READ_CALIBRATED_TIMESTAMPS, adreno_ioctl_read_calibrated_ts }, 306: }; 307: 308: long adreno_ioctl(struct kgsl_device_private *dev_priv, 309: unsigned int cmd, unsigned long arg) 310: { 311: return adreno_ioctl_helper(dev_priv, cmd, arg, 312: adreno_ioctl_funcs, ARRAY_SIZE(adreno_ioctl_funcs)); 313: } --- FILE: \adreno_pm4types.h | HITS: 2 --- MATCH LINES: 133, 140 121: 122: /* (A4x) save PM4 stream pointers to execute upon a visible draw */ 123: #define CP_SET_DRAW_STATE 0x43 124: 125: #define CP_LOADSTATE_DSTOFFSET_SHIFT 0x00000000 126: #define CP_LOADSTATE_STATESRC_SHIFT 0x00000010 127: #define CP_LOADSTATE_STATEBLOCKID_SHIFT 0x00000013 128: #define CP_LOADSTATE_NUMOFUNITS_SHIFT 0x00000016 129: #define CP_LOADSTATE_STATETYPE_SHIFT 0x00000000 130: #define CP_LOADSTATE_EXTSRCADDR_SHIFT 0x00000002 131: 132: /* This is a commonly used CP_EVENT_WRITE */ 133: #define CACHE_FLUSH_TS 4 134: #define CACHE_CLEAN 0x31 135: #define LRZ_CACHE_FLUSH 0x26 136: 137: /* Controls which threads execute the PM4 commands the follow this packet */ 138: #define CP_THREAD_CONTROL 0x17 139: 140: #define CP_WAIT_TIMESTAMP 0x14 141: 142: #define CP_SET_THREAD_BR FIELD_PREP(GENMASK(1, 0), 1) 143: #define CP_SET_THREAD_BV FIELD_PREP(GENMASK(1, 0), 2) 144: #define CP_SET_THREAD_BOTH FIELD_PREP(GENMASK(1, 0), 3) 145: #define CP_SYNC_THREADS BIT(31) 146: #define CP_CONCURRENT_BIN_DISABLE BIT(27) 147: 148: #define CP_RESET_CONTEXT_STATE 0x1F 149: 150: #define CP_RESET_GLOBAL_LOCAL_TS BIT(3) 151: #define CP_CLEAR_BV_BR_COUNTER BIT(2) 152: #define CP_CLEAR_RESOURCE_TABLE BIT(1) 153: #define CP_CLEAR_ON_CHIP_TS BIT(0) 154: 155: /* Used to define amble type in SET_AMBLE packet to execute during preemption */ 156: #define CP_KMD_AMBLE_TYPE 3 157: 158: static inline uint pm4_calc_odd_parity_bit(uint val) 159: { 160: return (0x9669 >> (0xf & ((val) ^ 161: ((val) >> 4) ^ ((val) >> 8) ^ ((val) >> 12) ^ 162: ((val) >> 16) ^ ((val) >> 20) ^ ((val) >> 24) ^ 163: ((val) >> 28)))) & 1; 164: } --- FILE: \adreno_profile.c | HITS: 13 --- MATCH LINES: 22, 34 10: #include 11: 12: #include "adreno.h" 13: #include "adreno_hwsched.h" 14: #include "adreno_profile.h" 15: #include "adreno_pm4types.h" 16: #include "adreno_ringbuffer.h" 17: 18: #define ASSIGNS_STR_FORMAT "%.8s:%u " 19: 20: /* 21: * Raw Data for processing later: 22: * : 3 - timestamp, count, context id 23: * [per counter] - data for each counter 24: * : 1 - Register offset 25: * : 2 - Pre IB register hi/lo value 26: * : 2 - Post IB register hi/lo value 27: * [per counter end] 28: */ 29: #define SIZE_DATA(cnt) (6 + (cnt) * 5) 30: 31: /* 32: * Pre-IB command size (in dwords): 33: * : 2 - NOP start identifier 34: * : 4 - timestamp 35: * : 4 - count 36: * : 4 - context id 37: * : 4 - pid 38: * : 4 - tid 39: * : 4 - type 40: * [loop count start] - for each counter to watch 41: * : 4 - Register offset 42: * : 4 - Register read lo 43: * : 4 - Register read high 44: * [loop end] 45: * : 2 - NOP end identifier 46: */ 47: #define SIZE_PREIB(cnt) (28 + (cnt) * 12) 48: 49: /* 50: * Post-IB command size (in dwords): 51: * : 2 - NOP start identifier 52: * [loop count start] - for each counter to watch 53: * : 4 - Register read lo 54: * : 4 - Register read high 55: * [loop end] 56: * : 2 - NOP end identifier 57: */ 58: #define SIZE_POSTIB(cnt) (4 + (cnt) * 8) MATCH LINES: 99, 117, 120 87: unsigned int *start = cmds; 88: 89: *cmds++ = cp_mem_packet(adreno_dev, CP_REG_TO_MEM, 2, 1); 90: *cmds++ = val; 91: cmds += cp_gpuaddr(adreno_dev, cmds, gpuaddr); 92: 93: *off += sizeof(unsigned int); 94: return cmds - start; 95: } 96: 97: static u64 _build_pre_ib_cmds(struct adreno_device *adreno_dev, 98: struct adreno_profile *profile, 99: unsigned int head, unsigned int timestamp, 100: struct adreno_context *drawctxt, 101: u32 *dwords) 102: { 103: struct adreno_profile_assigns_list *entry; 104: unsigned int *start, *ibcmds; 105: unsigned int count = profile->assignment_count; 106: uint64_t gpuaddr = profile->shared_buffer->gpuaddr; 107: unsigned int ib_offset = head + SIZE_DATA(count); 108: unsigned int data_offset = head * sizeof(unsigned int); 109: 110: ibcmds = ib_offset + ((unsigned int *) profile->shared_buffer->hostptr); 111: start = ibcmds; 112: 113: ibcmds += cp_identifier(adreno_dev, ibcmds, START_PROFILE_IDENTIFIER); 114: 115: /* 116: * Write ringbuffer commands to save the following to memory: 117: * timestamp, count, context_id, pid, tid, context type 118: */ 119: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 120: timestamp, &data_offset); 121: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 122: profile->assignment_count, &data_offset); 123: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 124: drawctxt->base.id, &data_offset); 125: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 126: pid_nr(drawctxt->base.proc_priv->pid), &data_offset); 127: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 128: drawctxt->base.tid, &data_offset); 129: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 130: drawctxt->type, &data_offset); 131: 132: /* loop for each countable assigned */ 133: list_for_each_entry(entry, &profile->assignments_list, list) { 134: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, 135: gpuaddr + data_offset, entry->offset, 136: &data_offset); 137: ibcmds += _ib_cmd_reg_to_mem(adreno_dev, ibcmds, 138: gpuaddr + data_offset, entry->offset, 139: &data_offset); 140: ibcmds += _ib_cmd_reg_to_mem(adreno_dev, ibcmds, 141: gpuaddr + data_offset, entry->offset_hi, 142: &data_offset); 143: 144: /* skip over post_ib counter data */ MATCH LINES: 321, 322, 328, 330, 338 309: struct adreno_profile *profile, unsigned int *shared_buf_tail) 310: { 311: unsigned int global_eop; 312: unsigned int off = profile->shared_tail; 313: unsigned int *shared_ptr; 314: unsigned int ts, cnt; 315: int ts_cmp; 316: 317: if (IS_ERR(profile->shared_buffer)) 318: return false; 319: 320: /* 321: * If shared_buffer empty or Memstore EOP timestamp is less than 322: * outstanding counter buffer timestamps then no results available 323: */ 324: if (shared_buf_empty(profile)) 325: return false; 326: 327: shared_ptr = (unsigned int *)profile->shared_buffer->hostptr; 328: if (adreno_rb_readtimestamp(adreno_dev, 329: adreno_dev->cur_rb, 330: KGSL_TIMESTAMP_RETIRED, &global_eop)) 331: return false; 332: do { 333: cnt = *(shared_ptr + off + 1); 334: if (cnt == 0) 335: return false; 336: 337: ts = *(shared_ptr + off); 338: ts_cmp = timestamp_cmp(ts, global_eop); 339: if (ts_cmp >= 0) { 340: *shared_buf_tail = off; 341: if (off == profile->shared_tail) 342: return false; 343: else 344: return true; 345: } 346: shared_buf_inc(profile->shared_size, &off, 347: SIZE_SHARED_ENTRY(cnt)); 348: } while (off != profile->shared_head); 349: 350: *shared_buf_tail = profile->shared_head; 351: 352: return true; 353: } 354: 355: static void transfer_results(struct adreno_profile *profile, 356: unsigned int shared_buf_tail) 357: { 358: unsigned int buf_off; 359: unsigned int ts, cnt, ctxt_id, pid, tid, client_type; 360: unsigned int *ptr = (unsigned int *) profile->shared_buffer->hostptr; 361: unsigned int *log_ptr, *log_base; 362: struct adreno_profile_assigns_list *assigns_list; MATCH LINES: 379 367: if (log_ptr == NULL) 368: return; 369: 370: /* 371: * go through counter buffers and format for write into log_buffer 372: * if log buffer doesn't have space just overwrite it circularly 373: * shared_buf is guaranteed to not wrap within an entry so can use 374: * ptr increment 375: */ 376: while (profile->shared_tail != shared_buf_tail) { 377: buf_off = profile->shared_tail; 378: /* 379: * format: timestamp, count, context_id 380: * count entries: pc_off, pc_start, pc_end 381: */ 382: ts = *(ptr + buf_off++); 383: cnt = *(ptr + buf_off++); 384: ctxt_id = *(ptr + buf_off++); 385: pid = *(ptr + buf_off++); 386: tid = *(ptr + buf_off++); 387: client_type = *(ptr + buf_off++); 388: 389: /* 390: * if entry overwrites the tail of log_buffer then adjust tail 391: * ptr to make room for the new entry, discarding old entry 392: */ 393: while (log_buf_available(profile, log_ptr) <= 394: SIZE_LOG_ENTRY(cnt)) { 395: unsigned int size_tail; 396: uintptr_t boff; 397: 398: size_tail = SIZE_LOG_ENTRY(0xffff & 399: *(profile->log_tail)); 400: boff = ((uintptr_t) profile->log_tail - 401: (uintptr_t) log_base) / sizeof(uintptr_t); 402: log_buf_wrapcnt(size_tail, &boff); 403: profile->log_tail = log_base + boff; MATCH LINES: 907 895: { 896: struct kgsl_device *device = (struct kgsl_device *) filep->private_data; 897: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 898: struct adreno_profile *profile = &adreno_dev->profile; 899: char __user *usr_buf = ubuf; 900: int status = 0; 901: 902: /* 903: * this file not seekable since it only supports streaming, ignore 904: * ppos <> 0 905: */ 906: /* 907: * format 908: * for each perf counter 909: */ 910: 911: kgsl_mutex_lock(&device->mutex); 912: 913: while (1) { 914: /* process any results that are available into the log_buffer */ 915: status = adreno_profile_process_results(adreno_dev); 916: if (status > 0) { 917: /* if we have results, print them and exit */ 918: status = _pipe_print_results(adreno_dev, usr_buf, max); 919: break; 920: } 921: 922: /* there are no unread results, act accordingly */ 923: if (filep->f_flags & O_NONBLOCK) { 924: if (profile->shared_tail != profile->shared_head) { 925: status = _pipe_print_pending(usr_buf, max); 926: break; 927: } 928: 929: status = 0; 930: break; 931: } MATCH LINES: 1132 1120: 1121: /* zero out the counter area of shared_buffer entry_head */ 1122: shared_ptr = entry_head + ((unsigned int *) 1123: profile->shared_buffer->hostptr); 1124: memset(shared_ptr, 0, SIZE_SHARED_ENTRY(count) * sizeof(unsigned int)); 1125: 1126: /* reserve space for the pre ib shared buffer */ 1127: shared_buf_inc(profile->shared_size, &profile->shared_head, 1128: SIZE_SHARED_ENTRY(count)); 1129: 1130: /* create the shared ibdesc */ 1131: return _build_pre_ib_cmds(adreno_dev, profile, entry_head, 1132: rb->timestamp + 1, drawctxt, dwords); 1133: } 1134: 1135: u64 adreno_profile_postib_processing(struct adreno_device *adreno_dev, 1136: struct adreno_context *drawctxt, u32 *dwords) 1137: { 1138: struct adreno_profile *profile = &adreno_dev->profile; 1139: int count = profile->assignment_count; 1140: unsigned int entry_head = profile->shared_head - 1141: SIZE_SHARED_ENTRY(count); 1142: 1143: if (adreno_dev->hwsched_enabled) 1144: return 0; 1145: 1146: if (!drawctxt || !adreno_profile_assignments_ready(profile)) 1147: return 0; 1148: 1149: /* create the shared ibdesc */ 1150: return _build_post_ib_cmds(adreno_dev, profile, entry_head, dwords); 1151: } --- FILE: \adreno_ringbuffer.c | HITS: 27 --- MATCH LINES: 55 43: * possible. This is useful for many types of debugging and 44: * profiling. In order to make this mapping as accurate as 45: * possible, we must turn off interrupts to avoid running 46: * interrupt handlers between the two samples. 47: */ 48: 49: local_irq_save(flags); 50: 51: time->ticks = gpudev->read_alwayson(adreno_dev); 52: 53: /* Trace the GPU time to create a mapping to ftrace time */ 54: trace_adreno_cmdbatch_sync(context->id, context->priority, 55: drawctxt->timestamp, time->ticks); 56: 57: /* Get the kernel clock for time since boot */ 58: time->ktime = local_clock(); 59: 60: /* Get the timeofday for the wall time (for the user) */ 61: ktime_get_real_ts64(&time->utime); 62: 63: local_irq_restore(flags); 64: } 65: 66: unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb, 67: unsigned int dwords) 68: { 69: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 70: unsigned int rptr = adreno_get_rptr(rb); 71: unsigned int ret; 72: 73: if (rptr <= rb->_wptr) { 74: unsigned int *cmds; 75: 76: if (rb->_wptr + dwords <= (KGSL_RB_DWORDS - 2)) { 77: ret = rb->_wptr; 78: rb->_wptr = (rb->_wptr + dwords) % KGSL_RB_DWORDS; 79: return RB_HOSTPTR(rb, ret); MATCH LINES: 114, 115, 116, 118, 119, 145, 148, 186 102: return ERR_PTR(-ENOSPC); 103: } 104: 105: void adreno_ringbuffer_stop(struct adreno_device *adreno_dev) 106: { 107: struct adreno_ringbuffer *rb; 108: int i; 109: 110: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) 111: kgsl_cancel_events(KGSL_DEVICE(adreno_dev), &(rb->events)); 112: } 113: 114: static int _rb_readtimestamp(struct kgsl_device *device, 115: void *priv, enum kgsl_timestamp_type type, 116: unsigned int *timestamp) 117: { 118: return adreno_rb_readtimestamp(ADRENO_DEVICE(device), priv, type, 119: timestamp); 120: } 121: 122: int adreno_ringbuffer_setup(struct adreno_device *adreno_dev, 123: struct adreno_ringbuffer *rb, int id) 124: { 125: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 126: unsigned int priv = 0; 127: int ret; 128: 129: /* allocate a chunk of memory to create user profiling IB1s */ 130: adreno_allocate_global(device, &rb->profile_desc, PAGE_SIZE, 131: 0, KGSL_MEMFLAGS_GPUREADONLY, 0, "profile_desc"); 132: 133: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 134: priv |= KGSL_MEMDESC_PRIVILEGED; 135: 136: ret = adreno_allocate_global(device, &rb->buffer_desc, KGSL_RB_SIZE, 137: SZ_4K, KGSL_MEMFLAGS_GPUREADONLY, priv, "ringbuffer"); 138: if (ret) 139: return ret; 140: 141: if (!list_empty(&rb->events.group)) 142: return 0; 143: 144: rb->id = id; 145: kgsl_add_event_group(device, &rb->events, NULL, _rb_readtimestamp, rb, 146: "rb_events-%d", id); 147: 148: rb->timestamp = 0; 149: init_waitqueue_head(&rb->ts_expire_waitq); 150: 151: spin_lock_init(&rb->preempt_lock); 152: 153: return 0; 154: } 155: 156: void adreno_preemption_timer(struct timer_list *t) 157: { 158: struct adreno_preemption *preempt = kgsl_timer_container_of(preempt, t, timer); 159: struct adreno_device *adreno_dev = container_of(preempt, 160: struct adreno_device, preempt); 161: 162: /* We should only be here from a triggered state */ 163: if (!adreno_move_preempt_state(adreno_dev, 164: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_FAULTED)) 165: return; 166: 167: /* Schedule the worker to take care of the details */ 168: queue_work(system_unbound_wq, &adreno_dev->preempt.work); 169: } 170: 171: void adreno_drawobj_set_constraint(struct kgsl_device *device, 172: struct kgsl_drawobj *drawobj) 173: { 174: struct kgsl_context *context = drawobj->context; 175: unsigned long flags = drawobj->flags; 176: 177: /* 178: * Check if the context has a constraint and constraint flags are 179: * set. 180: */ 181: if (device->host_based_dcvs && 182: context->pwr_constraint.type && 183: ((context->flags & KGSL_CONTEXT_PWR_CONSTRAINT) || 184: (drawobj->flags & KGSL_CONTEXT_PWR_CONSTRAINT))) 185: kgsl_pwrctrl_set_constraint(device, &context->pwr_constraint, 186: context->id, drawobj->timestamp); 187: 188: if (context->l3_pwr_constraint.type && 189: ((context->flags & KGSL_CONTEXT_PWR_CONSTRAINT) || 190: (flags & KGSL_CONTEXT_PWR_CONSTRAINT))) { 191: 192: if (!device->num_l3_pwrlevels) { 193: dev_err_once(device->dev, 194: "l3 voting not available\n"); 195: return; 196: } 197: 198: switch (context->l3_pwr_constraint.type) { 199: case KGSL_CONSTRAINT_L3_PWRLEVEL: { 200: unsigned int sub_type; 201: unsigned int new_l3; 202: int ret = 0; 203: struct dcvs_freq freq = {0}; 204: 205: if (!device->l3_vote) 206: return; 207: 208: sub_type = context->l3_pwr_constraint.sub_type; 209: 210: /* MATCH LINES: 345, 353, 368, 369, 371, 376, 377, 382, 384, 387, 388, 398, 399, 401, 410, 417, 420, 421 333: /* Check to see the submission should be secure */ 334: if (drawobj->context->flags & KGSL_CONTEXT_SECURE) 335: flags |= F_SECURE; 336: 337: /* process any profiling results that are available into the log_buf */ 338: adreno_profile_process_results(adreno_dev); 339: 340: ret = gpudev->ringbuffer_submitcmd(adreno_dev, cmdobj, 341: flags, time); 342: 343: if (!ret) { 344: set_bit(KGSL_CONTEXT_PRIV_SUBMITTED, &drawobj->context->priv); 345: cmdobj->global_ts = drawctxt->internal_timestamp; 346: } 347: 348: return ret; 349: } 350: 351: /** 352: * adreno_ringbuffer_wait_callback() - Callback function for event registered 353: * on a ringbuffer timestamp 354: * @device: Device for which the callback is valid 355: * @context: The context of the event 356: * @priv: The private parameter of the event 357: * @result: Result of the event trigger 358: */ 359: static void adreno_ringbuffer_wait_callback(struct kgsl_device *device, 360: struct kgsl_event_group *group, 361: void *priv, int result) 362: { 363: struct adreno_ringbuffer *rb = group->priv; 364: 365: wake_up_all(&rb->ts_expire_waitq); 366: } 367: 368: /* check if timestamp is greater than the current rb timestamp */ 369: static inline int adreno_ringbuffer_check_timestamp( 370: struct adreno_ringbuffer *rb, 371: unsigned int timestamp, int type) 372: { 373: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 374: unsigned int ts; 375: 376: adreno_rb_readtimestamp(adreno_dev, rb, type, &ts); 377: return (timestamp_cmp(ts, timestamp) >= 0); 378: } 379: 380: 381: /** 382: * adreno_ringbuffer_waittimestamp() - Wait for a RB timestamp 383: * @rb: The ringbuffer to wait on 384: * @timestamp: The timestamp to wait for 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 | HITS: 10 --- MATCH LINES: 72, 73, 85, 86, 103 60: */ 61: #define ADRENO_RB_SET_PSEUDO_DONE 0 62: 63: /** 64: * struct adreno_ringbuffer - Definition for an adreno ringbuffer object 65: * @flags: Internal control flags for the ringbuffer 66: * @buffer_desc: Pointer to the ringbuffer memory descriptor 67: * @_wptr: The next value of wptr to be written to the hardware on submit 68: * @wptr: Local copy of the wptr offset last written to hardware 69: * @last_wptr: offset of the last wptr that was written to CFF 70: * @rb_ctx: The context that represents a ringbuffer 71: * @id: Priority level of the ringbuffer, also used as an ID 72: * @fault_detect_ts: The last retired global timestamp read during fault detect 73: * @timestamp: The RB's global timestamp 74: * @events: A kgsl_event_group for this context - contains the list of GPU 75: * events 76: * @drawctxt_active: The last pagetable that this ringbuffer is set to 77: * @preemption_desc: The memory descriptor containing 78: * preemption info written/read by CP 79: * @secure_preemption_desc: The memory descriptor containing 80: * preemption info written/read by CP for secure contexts 81: * @perfcounter_save_restore_desc: Used by CP to save/restore the perfcounter 82: * values across preemption 83: * and the commands to switch pagetable on the RB 84: * @dispatch_q: The dispatcher side queue for this ringbuffer 85: * @ts_expire_waitq: Wait queue to wait for rb timestamp to expire 86: * @ts_expire_waitq: Wait q to wait for rb timestamp to expire 87: * @wptr_preempt_end: Used during preemption to check that preemption occurred 88: * at the right rptr 89: * @gpr11: The gpr11 value of this RB 90: * @preempted_midway: Indicates that the RB was preempted before rptr = wptr 91: * @preempt_lock: Lock to protect the wptr pointer while it is being updated 92: * @skip_inline_wptr: Used during preemption to make sure wptr is updated in 93: * hardware 94: */ 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; MATCH LINES: 155, 156, 159, 160, 161 143: struct adreno_ringbuffer *rb, int id); 144: 145: int adreno_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 146: struct kgsl_drawobj_cmd *cmdobj, 147: struct adreno_submit_time *time); 148: 149: 150: void adreno_ringbuffer_stop(struct adreno_device *adreno_dev); 151: 152: unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb, 153: unsigned int numcmds); 154: 155: int adreno_ringbuffer_waittimestamp(struct adreno_ringbuffer *rb, 156: unsigned int timestamp, 157: unsigned int msecs); 158: 159: int adreno_rb_readtimestamp(struct adreno_device *adreno_dev, 160: void *priv, enum kgsl_timestamp_type type, 161: unsigned int *timestamp); 162: 163: static inline int adreno_ringbuffer_count(struct adreno_ringbuffer *rb, 164: unsigned int rptr) 165: { 166: if (rb->wptr >= rptr) 167: return rb->wptr - rptr; 168: return rb->wptr + KGSL_RB_DWORDS - rptr; 169: } 170: 171: /* Increment a value by 4 bytes with wrap-around based on size */ 172: static inline unsigned int adreno_ringbuffer_inc_wrapped(unsigned int val, 173: unsigned int size) 174: { 175: return (val + sizeof(unsigned int)) % size; 176: } 177: 178: /* Decrement a value by 4 bytes with wrap-around based on size */ 179: static inline unsigned int adreno_ringbuffer_dec_wrapped(unsigned int val, 180: unsigned int size) 181: { 182: return (val + size - sizeof(unsigned int)) % size; 183: } 184: 185: void adreno_get_submit_time(struct adreno_device *adreno_dev, --- FILE: \adreno_snapshot.c | HITS: 12 --- MATCH LINES: 508, 509, 510, 511 496: dev_err(device->dev, 497: "snapshot: Not enough memory for the rb section\n"); 498: return 0; 499: } 500: 501: /* Write the sub-header for the section */ 502: header->start = 0; 503: header->end = KGSL_RB_DWORDS; 504: header->wptr = rb->wptr; 505: header->rptr = adreno_get_rptr(rb); 506: header->rbsize = KGSL_RB_DWORDS; 507: header->count = KGSL_RB_DWORDS; 508: adreno_rb_readtimestamp(adreno_dev, rb, KGSL_TIMESTAMP_QUEUED, 509: &header->timestamp_queued); 510: adreno_rb_readtimestamp(adreno_dev, rb, KGSL_TIMESTAMP_RETIRED, 511: &header->timestamp_retired); 512: header->gpuaddr = rb->buffer_desc->gpuaddr; 513: header->id = rb->id; 514: 515: if (rb == adreno_dev->cur_rb) 516: snapshot_rb_ibs(device, rb, snapshot); 517: 518: /* Just copy the ringbuffer, there are no active IBs */ 519: memcpy(data, rb->buffer_desc->hostptr, KGSL_RB_SIZE); 520: 521: /* Return the size of the section */ 522: return KGSL_RB_SIZE + sizeof(*header); 523: } 524: 525: static int _count_mem_entries(int id, void *ptr, void *data) 526: { 527: int *count = data; 528: *count = *count + 1; 529: return 0; 530: } 531: 532: struct mem_entry { 533: uint64_t gpuaddr; 534: uint64_t size; 535: unsigned int type; MATCH LINES: 993, 994, 996, 997, 999, 1000 981: } 982: 983: remain = snapshot->remain - sizeof(*sect) + sizeof(*header); 984: mem = snapshot->ptr + sizeof(*sect) + sizeof(*header); 985: 986: read_lock(&device->context_lock); 987: idr_for_each_entry(&device->context_idr, context, id) { 988: struct kgsl_snapshot_linux_context_v2 *c = mem; 989: 990: if (remain < sizeof(*c)) 991: break; 992: 993: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_QUEUED, 994: &c->timestamp_queued); 995: 996: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_CONSUMED, 997: &c->timestamp_consumed); 998: 999: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, 1000: &c->timestamp_retired); 1001: 1002: header->ctxtcount++; 1003: 1004: mem += sizeof(*c); 1005: remain -= sizeof(*c); 1006: } 1007: read_unlock(&device->context_lock); 1008: 1009: sect->magic = SNAPSHOT_SECTION_MAGIC; 1010: sect->id = KGSL_SNAPSHOT_SECTION_OS; 1011: sect->size = sizeof(*sect) + sizeof(*header) + 1012: header->ctxtcount * sizeof(struct kgsl_snapshot_linux_context_v2); 1013: 1014: snapshot->ptr += sect->size; 1015: snapshot->remain -= sect->size; 1016: snapshot->size += sect->size; 1017: } 1018: 1019: static void adreno_static_ib_dump(struct kgsl_device *device, 1020: struct kgsl_process_private *process, u64 ib1base, 1021: u32 ib1size, u64 ib2base, u32 ib2size, 1022: u64 ib3base, u32 ib3size) 1023: { 1024: if (process == NULL) MATCH LINES: 1416, 1417 1404: if (remain < desc->memdesc->size + sizeof(*mem_hdr)) { 1405: dev_err(device->dev, 1406: "snapshot: Not enough memory for the gmu section %d\n", 1407: desc->type); 1408: return 0; 1409: } 1410: 1411: mem_hdr->type = desc->type; 1412: mem_hdr->hostaddr = 0; 1413: mem_hdr->gmuaddr = desc->memdesc->gmuaddr; 1414: mem_hdr->gpuaddr = 0; 1415: 1416: /* The hw fence queues are mapped as iomem in the kernel */ 1417: if (desc->type == SNAPSHOT_GMU_MEM_HW_FENCE) 1418: memcpy_fromio(data, desc->memdesc->hostptr, desc->memdesc->size); 1419: else 1420: memcpy(data, desc->memdesc->hostptr, desc->memdesc->size); 1421: 1422: return desc->memdesc->size + sizeof(*mem_hdr); 1423: } 1424: 1425: /* Snapshot the preemption related buffers */ 1426: static size_t snapshot_preemption_record(struct kgsl_device *device, 1427: u8 *buf, size_t remain, void *priv) 1428: { 1429: struct kgsl_memdesc *memdesc = priv; 1430: struct kgsl_snapshot_gpu_object_v2 *header = 1431: (struct kgsl_snapshot_gpu_object_v2 *)buf; 1432: u8 *ptr = buf + sizeof(*header); 1433: u64 ctxt_record_size = min_t(u64, device->snapshot_ctxt_record_size, memdesc->size); 1434: 1435: if (remain < (ctxt_record_size + sizeof(*header))) { 1436: SNAPSHOT_ERR_NOMEM(device, "PREEMPTION RECORD"); 1437: return 0; 1438: } 1439: 1440: header->size = ctxt_record_size >> 2; 1441: header->gpuaddr = memdesc->gpuaddr; --- FILE: \adreno_trace.c | HITS: 13 --- MATCH LINES: 16, 17, 20, 21, 23, 24, 27, 32, 34, 37, 40, 41, 42 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include 8: #include 9: #include 10: #include "adreno.h" 11: 12: /* Instantiate tracepoints */ 13: #define CREATE_TRACE_POINTS 14: #include "adreno_trace.h" 15: 16: #ifdef CONFIG_QCOM_KGSL_FENCE_TRACE 17: static const char * const kgsl_fence_trace_events[] = { 18: "adreno_cmdbatch_submitted", 19: "adreno_cmdbatch_retired", 20: "syncpoint_fence", 21: "syncpoint_fence_expire", 22: "kgsl_fire_event", 23: "kgsl_timeline_fence_alloc", 24: "kgsl_timeline_fence_release", 25: }; 26: 27: void adreno_fence_trace_array_init(struct kgsl_device *device) 28: { 29: int i; 30: 31: #if (KERNEL_VERSION(6, 7, 0) >= LINUX_VERSION_CODE) 32: device->fence_trace_array = trace_array_get_by_name("kgsl-fence"); 33: #else 34: device->fence_trace_array = trace_array_get_by_name("kgsl-fence", NULL); 35: #endif 36: 37: if (!device->fence_trace_array) 38: return; 39: 40: for (i = 0; i < ARRAY_SIZE(kgsl_fence_trace_events); i++) 41: trace_array_set_clr_event(device->fence_trace_array, 42: "kgsl", kgsl_fence_trace_events[i], true); 43: 44: } 45: #endif --- FILE: \adreno_trace.h | HITS: 63 --- MATCH LINES: 44, 51, 59, 65, 72, 79, 86, 87, 88, 92, 100, 107, 114, 118, 119, 122, 127, 132, 136, 137, 140, 145, 150, 154, 156, 159, 165, 171, 175, 176, 179, 184, 188, 198, 213, 228, 245, 264, 283 32: { BIT(KGSL_FT_SKIPIB), "skipib" }, \ 33: { BIT(KGSL_FT_SKIPFRAME), "skipframe" }, \ 34: { BIT(KGSL_FT_DISABLE), "disable" }, \ 35: { BIT(KGSL_FT_TEMP_DISABLE), "temp" }, \ 36: { BIT(KGSL_FT_THROTTLE), "throttle"}, \ 37: { BIT(KGSL_FT_SKIPCMD), "skipcmd" } 38: 39: TRACE_EVENT(adreno_cmdbatch_queued, 40: TP_PROTO(struct kgsl_drawobj *drawobj, unsigned int queued), 41: TP_ARGS(drawobj, queued), 42: TP_STRUCT__entry( 43: __field(unsigned int, id) 44: __field(unsigned int, timestamp) 45: __field(unsigned int, queued) 46: __field(unsigned int, flags) 47: __field(unsigned int, prio) 48: ), 49: TP_fast_assign( 50: __entry->id = drawobj->context->id; 51: __entry->timestamp = drawobj->timestamp; 52: __entry->queued = queued; 53: __entry->flags = drawobj->flags; 54: __entry->prio = drawobj->context->priority; 55: ), 56: TP_printk( 57: "ctx=%u ctx_prio=%u ts=%u queued=%u flags=%s", 58: __entry->id, __entry->prio, 59: __entry->timestamp, __entry->queued, 60: __entry->flags ? __print_flags(__entry->flags, "|", 61: KGSL_DRAWOBJ_FLAGS) : "none" 62: ) 63: ); 64: 65: TRACE_EVENT(adreno_hw_fence_query, 66: TP_PROTO(u64 context, u64 seqno, u32 flags, const char *name, const char *val), 67: TP_ARGS(context, seqno, flags, name, val), 68: TP_STRUCT__entry( 69: __field(u64, context) 70: __field(u64, seqno) 71: __field(u32, flags) 72: __string(fence_name, name) 73: __string(val, val) 74: ), 75: TP_fast_assign( 76: __entry->context = context; 77: __entry->seqno = seqno; 78: __entry->flags = flags; 79: adreno_assign_str(fence_name, name); 80: adreno_assign_str(val, val); 81: ), 82: TP_printk( 83: "id=%lld seqno=%lld sw_status=%s name=%s val=%s", 84: __entry->context, __entry->seqno, 85: __entry->flags ? __print_flags(__entry->flags, "|", 86: { ADRENO_HW_FENCE_SW_STATUS_PENDING, "PENDING" }, 87: { ADRENO_HW_FENCE_SW_STATUS_SIGNALED, "SIGNALED" }) : "none", 88: __get_str(fence_name), 89: __get_str(val)) 90: ); 91: 92: TRACE_EVENT(adreno_input_hw_fence, 93: TP_PROTO(u32 id, u64 context, u64 seqno, u64 flags, const char *name), 94: TP_ARGS(id, context, seqno, flags, name), 95: TP_STRUCT__entry( 96: __field(u32, id) 97: __field(u64, context) 98: __field(u64, seqno) 99: __field(u64, flags) 100: __string(fence_name, name) 101: ), 102: TP_fast_assign( 103: __entry->id = id; 104: __entry->context = context; 105: __entry->seqno = seqno; 106: __entry->flags = flags; 107: adreno_assign_str(fence_name, name); 108: ), 109: TP_printk( 110: "ctx=%u id=%lld seqno=%lld flags=%s name=%s", 111: __entry->id, __entry->context, __entry->seqno, 112: __entry->flags ? __print_flags(__entry->flags, "|", 113: GMU_SYNCOBJ_FLAGS) : "none", 114: __get_str(fence_name)) 115: ); 116: 117: TRACE_EVENT(adreno_syncobj_query_reply, 118: TP_PROTO(u32 id, u32 timestamp, uint64_t ticks), 119: TP_ARGS(id, timestamp, ticks), 120: TP_STRUCT__entry( 121: __field(u32, id) 122: __field(u32, timestamp) 123: __field(uint64_t, ticks) 124: ), 125: TP_fast_assign( 126: __entry->id = id; 127: __entry->timestamp = timestamp; 128: __entry->ticks = ticks; 129: ), 130: TP_printk( 131: "ctx=%u ts=%u ticks=%lld", 132: __entry->id, __entry->timestamp, __entry->ticks) 133: ); 134: 135: TRACE_EVENT(adreno_syncobj_query, 136: TP_PROTO(u32 id, u32 timestamp, uint64_t ticks), 137: TP_ARGS(id, timestamp, ticks), 138: TP_STRUCT__entry( 139: __field(u32, id) 140: __field(u32, timestamp) 141: __field(uint64_t, ticks) 142: ), 143: TP_fast_assign( 144: __entry->id = id; 145: __entry->timestamp = timestamp; 146: __entry->ticks = ticks; 147: ), 148: TP_printk( 149: "ctx=%u ts=%u ticks=%lld", 150: __entry->id, __entry->timestamp, __entry->ticks) 151: ); 152: 153: TRACE_EVENT(adreno_syncobj_submitted, 154: TP_PROTO(u32 id, u32 timestamp, u32 num_syncobj, 155: uint64_t ticks), 156: TP_ARGS(id, timestamp, num_syncobj, ticks), 157: TP_STRUCT__entry( 158: __field(u32, id) 159: __field(u32, timestamp) 160: __field(u32, num_syncobj) 161: __field(uint64_t, ticks) 162: ), 163: TP_fast_assign( 164: __entry->id = id; 165: __entry->timestamp = timestamp; 166: __entry->num_syncobj = num_syncobj; 167: __entry->ticks = ticks; 168: ), 169: TP_printk( 170: "ctx=%u ts=%u num_sync=%u ticks=%lld", 171: __entry->id, __entry->timestamp, __entry->num_syncobj, __entry->ticks) 172: ); 173: 174: TRACE_EVENT(adreno_syncobj_retired, 175: TP_PROTO(u32 id, u32 timestamp, u64 ticks), 176: TP_ARGS(id, timestamp, ticks), 177: TP_STRUCT__entry( 178: __field(u32, id) 179: __field(u32, timestamp) 180: __field(u64, ticks) 181: ), 182: TP_fast_assign( 183: __entry->id = id; 184: __entry->timestamp = timestamp; 185: __entry->ticks = ticks; 186: ), 187: TP_printk( 188: "ctx=%u ts=%u ticks=%llu", __entry->id, __entry->timestamp, __entry->ticks) 189: ); 190: 191: TRACE_EVENT(adreno_cmdbatch_submitted, 192: TP_PROTO(struct kgsl_drawobj *drawobj, struct submission_info *info, 193: uint64_t ticks, unsigned long secs, unsigned long usecs, 194: int q_inflight), 195: TP_ARGS(drawobj, info, ticks, secs, usecs, q_inflight), 196: TP_STRUCT__entry( 197: __field(unsigned int, id) 198: __field(unsigned int, timestamp) 199: __field(int, inflight) 200: __field(unsigned int, flags) 201: __field(uint64_t, ticks) 202: __field(unsigned long, secs) 203: __field(unsigned long, usecs) 204: __field(int, prio) 205: __field(int, rb_id) 206: __field(unsigned int, rptr) 207: __field(unsigned int, wptr) 208: __field(int, q_inflight) 209: __field(int, dispatch_queue) 210: ), 211: TP_fast_assign( 212: __entry->id = drawobj->context->id; 213: __entry->timestamp = drawobj->timestamp; 214: __entry->inflight = info->inflight; 215: __entry->flags = drawobj->flags; 216: __entry->ticks = ticks; 217: __entry->secs = secs; 218: __entry->usecs = usecs; 219: __entry->prio = drawobj->context->priority; 220: __entry->rb_id = info->rb_id; 221: __entry->rptr = info->rptr; 222: __entry->wptr = info->wptr; 223: __entry->q_inflight = q_inflight; 224: __entry->dispatch_queue = info->gmu_dispatch_queue; 225: ), 226: TP_printk( 227: "ctx=%u ctx_prio=%d ts=%u inflight=%d flags=%s ticks=%lld time=%lu.%0lu rb_id=%d r/w=%x/%x, q_inflight=%d dq_id=%d", 228: __entry->id, __entry->prio, __entry->timestamp, 229: __entry->inflight, 230: __entry->flags ? __print_flags(__entry->flags, "|", 231: KGSL_DRAWOBJ_FLAGS) : "none", 232: __entry->ticks, __entry->secs, __entry->usecs, 233: __entry->rb_id, __entry->rptr, __entry->wptr, 234: __entry->q_inflight, __entry->dispatch_queue 235: ) 236: ); 237: 238: TRACE_EVENT(adreno_cmdbatch_retired, 239: TP_PROTO(struct kgsl_context *context, struct retire_info *info, 240: unsigned int flags, int q_inflight, 241: unsigned long fault_recovery), 242: TP_ARGS(context, info, flags, q_inflight, fault_recovery), 243: TP_STRUCT__entry( 244: __field(unsigned int, id) 245: __field(unsigned int, timestamp) 246: __field(int, inflight) 247: __field(unsigned int, recovery) 248: __field(unsigned int, flags) 249: __field(uint64_t, start) 250: __field(uint64_t, retire) 251: __field(int, prio) 252: __field(int, rb_id) 253: __field(unsigned int, rptr) 254: __field(unsigned int, wptr) 255: __field(int, q_inflight) 256: __field(unsigned long, fault_recovery) 257: __field(unsigned int, dispatch_queue) 258: __field(uint64_t, submitted_to_rb) 259: __field(uint64_t, retired_on_gmu) 260: __field(uint64_t, active) 261: ), 262: TP_fast_assign( 263: __entry->id = context->id; 264: __entry->timestamp = info->timestamp; 265: __entry->inflight = info->inflight; 266: __entry->recovery = fault_recovery; 267: __entry->flags = flags; 268: __entry->start = info->sop; 269: __entry->retire = info->eop; 270: __entry->prio = context->priority; 271: __entry->rb_id = info->rb_id; 272: __entry->rptr = info->rptr; 273: __entry->wptr = info->wptr; 274: __entry->q_inflight = q_inflight; 275: __entry->dispatch_queue = info->gmu_dispatch_queue; 276: __entry->submitted_to_rb = info->submitted_to_rb; 277: __entry->retired_on_gmu = info->retired_on_gmu; 278: __entry->active = info->active; 279: ), 280: 281: TP_printk( 282: "ctx=%u ctx_prio=%d ts=%u inflight=%d recovery=%s flags=%s start=%llu retire=%llu rb_id=%d, r/w=%x/%x, q_inflight=%d, dq_id=%u, submitted_to_rb=%llu retired_on_gmu=%llu active=%llu", 283: __entry->id, __entry->prio, __entry->timestamp, 284: __entry->inflight, 285: __entry->recovery ? 286: __print_flags(__entry->fault_recovery, "|", 287: ADRENO_FT_TYPES) : "none", 288: __entry->flags ? __print_flags(__entry->flags, "|", 289: KGSL_DRAWOBJ_FLAGS) : "none", 290: __entry->start, 291: __entry->retire, 292: __entry->rb_id, __entry->rptr, __entry->wptr, 293: __entry->q_inflight, 294: __entry->dispatch_queue, 295: __entry->submitted_to_rb, __entry->retired_on_gmu, 296: __entry->active 297: ) 298: ); 299: 300: TRACE_EVENT(gmu_ao_sync, 301: TP_PROTO(u64 ticks), 302: TP_ARGS(ticks), 303: TP_STRUCT__entry( 304: __field(u64, ticks) 305: ), 306: TP_fast_assign( 307: __entry->ticks = ticks; MATCH LINES: 337, 338, 341, 347, 353, 360, 361, 365, 371, 376, 383, 384, 388, 393, 397, 406, 411, 416, 430, 435, 440 325: __entry->ticks = event_info[1]; 326: __entry->data1 = event_info[2]; 327: __entry->data2 = event_info[3]; 328: ), 329: TP_printk( 330: "event=%08u ticks=%08u data1=0x%08x data2=0x%08x", 331: __entry->event, __entry->ticks, __entry->data1, __entry->data2 332: ) 333: ); 334: 335: TRACE_EVENT(adreno_cmdbatch_sync, 336: TP_PROTO(unsigned int ctx_id, unsigned int ctx_prio, 337: unsigned int timestamp, uint64_t ticks), 338: TP_ARGS(ctx_id, ctx_prio, timestamp, ticks), 339: TP_STRUCT__entry( 340: __field(unsigned int, id) 341: __field(unsigned int, timestamp) 342: __field(uint64_t, ticks) 343: __field(int, prio) 344: ), 345: TP_fast_assign( 346: __entry->id = ctx_id; 347: __entry->timestamp = timestamp; 348: __entry->ticks = ticks; 349: __entry->prio = ctx_prio; 350: ), 351: TP_printk( 352: "ctx=%u ctx_prio=%d ts=%u ticks=%lld", 353: __entry->id, __entry->prio, __entry->timestamp, 354: __entry->ticks 355: ) 356: ); 357: 358: TRACE_EVENT(adreno_cmdbatch_ready, 359: TP_PROTO(unsigned int ctx_id, unsigned int ctx_prio, 360: unsigned int timestamp, unsigned int requeue_cnt), 361: TP_ARGS(ctx_id, ctx_prio, timestamp, requeue_cnt), 362: TP_STRUCT__entry( 363: __field(unsigned int, id) 364: __field(int, prio) 365: __field(unsigned int, timestamp) 366: __field(unsigned int, requeue_cnt) 367: ), 368: TP_fast_assign( 369: __entry->id = ctx_id; 370: __entry->prio = ctx_prio; 371: __entry->timestamp = timestamp; 372: __entry->requeue_cnt = requeue_cnt; 373: ), 374: TP_printk( 375: "ctx=%u ctx_prio=%d ts=%u requeue_cnt=%u", 376: __entry->id, __entry->prio, __entry->timestamp, 377: __entry->requeue_cnt 378: ) 379: ); 380: 381: TRACE_EVENT(adreno_cmdbatch_done, 382: TP_PROTO(unsigned int ctx_id, unsigned int ctx_prio, 383: unsigned int timestamp), 384: TP_ARGS(ctx_id, ctx_prio, timestamp), 385: TP_STRUCT__entry( 386: __field(unsigned int, id) 387: __field(unsigned int, prio) 388: __field(unsigned int, timestamp) 389: ), 390: TP_fast_assign( 391: __entry->id = ctx_id; 392: __entry->prio = ctx_prio; 393: __entry->timestamp = timestamp; 394: ), 395: TP_printk( 396: "ctx=%u ctx_prio=%u ts=%u", 397: __entry->id, __entry->prio, __entry->timestamp 398: ) 399: ); 400: 401: TRACE_EVENT(adreno_cmdbatch_fault, 402: TP_PROTO(struct kgsl_drawobj_cmd *cmdobj, unsigned int fault), 403: TP_ARGS(cmdobj, fault), 404: TP_STRUCT__entry( 405: __field(unsigned int, id) 406: __field(unsigned int, timestamp) 407: __field(unsigned int, fault) 408: ), 409: TP_fast_assign( 410: __entry->id = cmdobj->base.context->id; 411: __entry->timestamp = cmdobj->base.timestamp; 412: __entry->fault = fault; 413: ), 414: TP_printk( 415: "ctx=%u ts=%u type=%s", 416: __entry->id, __entry->timestamp, 417: __print_symbolic(__entry->fault, 418: { 0, "none" }, 419: { ADRENO_SOFT_FAULT, "soft" }, 420: { ADRENO_HARD_FAULT, "hard" }, 421: { ADRENO_TIMEOUT_FAULT, "timeout" }) 422: ) 423: ); 424: 425: TRACE_EVENT(adreno_cmdbatch_recovery, 426: TP_PROTO(struct kgsl_drawobj_cmd *cmdobj, unsigned int action), 427: TP_ARGS(cmdobj, action), 428: TP_STRUCT__entry( 429: __field(unsigned int, id) 430: __field(unsigned int, timestamp) 431: __field(unsigned int, action) 432: ), 433: TP_fast_assign( 434: __entry->id = cmdobj->base.context->id; 435: __entry->timestamp = cmdobj->base.timestamp; 436: __entry->action = action; 437: ), 438: TP_printk( 439: "ctx=%u ts=%u action=%s", 440: __entry->id, __entry->timestamp, 441: __print_symbolic(__entry->action, ADRENO_FT_TYPES) 442: ) 443: ); 444: 445: DECLARE_EVENT_CLASS(adreno_drawctxt_template, 446: TP_PROTO(struct adreno_context *drawctxt), 447: TP_ARGS(drawctxt), 448: TP_STRUCT__entry( 449: __field(unsigned int, id) 450: __field(unsigned int, priority) 451: ), 452: TP_fast_assign( 453: __entry->id = drawctxt->base.id; 454: __entry->priority = drawctxt->base.priority; 455: ), 456: TP_printk("ctx=%u priority=%u", __entry->id, __entry->priority) 457: ); 458: 459: DEFINE_EVENT(adreno_drawctxt_template, adreno_drawctxt_sleep, 460: TP_PROTO(struct adreno_context *drawctxt), 461: TP_ARGS(drawctxt) 462: ); 463: 464: DEFINE_EVENT(adreno_drawctxt_template, adreno_drawctxt_wake, MATCH LINES: 650, 651 638: "CP_CCU_FLUSH_DEPTH_TS" }, 639: { BIT(A5XX_INT_CP_CCU_FLUSH_COLOR_TS), 640: "CP_CCU_FLUSH_COLOR_TS" }, 641: { BIT(A5XX_INT_CP_CCU_RESOLVE_TS), 642: "CP_CCU_RESOLVE_TS" }, 643: { BIT(A5XX_INT_CP_IB2), "CP_IB2_INT" }, 644: { BIT(A5XX_INT_CP_IB1), "CP_IB1_INT" }, 645: { BIT(A5XX_INT_CP_RB), "CP_RB_INT" }, 646: { BIT(A5XX_INT_CP_UNUSED_1), "CP_UNUSED_1" }, 647: { BIT(A5XX_INT_CP_RB_DONE_TS), "CP_RB_DONE_TS" }, 648: { BIT(A5XX_INT_CP_WT_DONE_TS), "CP_WT_DONE_TS" }, 649: { BIT(A5XX_INT_UNKNOWN_1), "UNKNOWN_1" }, 650: { BIT(A5XX_INT_CP_CACHE_FLUSH_TS), 651: "CP_CACHE_FLUSH_TS" }, 652: { BIT(A5XX_INT_UNUSED_2), "UNUSED_2" }, 653: { BIT(A5XX_INT_RBBM_ATB_BUS_OVERFLOW), 654: "RBBM_ATB_BUS_OVERFLOW" }, 655: { BIT(A5XX_INT_MISC_HANG_DETECT), "MISC_HANG_DETECT" }, 656: { BIT(A5XX_INT_UCHE_OOB_ACCESS), "UCHE_OOB_ACCESS" }, 657: { BIT(A5XX_INT_UCHE_TRAP_INTR), "UCHE_TRAP_INTR" }, 658: { BIT(A5XX_INT_DEBBUS_INTR_0), "DEBBUS_INTR_0" }, 659: { BIT(A5XX_INT_DEBBUS_INTR_1), "DEBBUS_INTR_1" }, 660: { BIT(A5XX_INT_GPMU_VOLTAGE_DROOP), 661: "GPMU_VOLTAGE_DROOP" }, 662: { BIT(A5XX_INT_GPMU_FIRMWARE), "GPMU_FIRMWARE" }, 663: { BIT(A5XX_INT_ISDB_CPU_IRQ), "ISDB_CPU_IRQ" }, 664: { BIT(A5XX_INT_ISDB_UNDER_DEBUG), "ISDB_UNDER_DEBUG" }) 665: : "None" 666: ) 667: ); 668: 669: /* 670: * Tracepoint for gen7 irq. Includes status info 671: */ 672: TRACE_EVENT(kgsl_gen7_irq_status, 673: 674: TP_PROTO(struct adreno_device *adreno_dev, unsigned int status), 675: MATCH LINES: 962 950: ), 951: TP_fast_assign( 952: __entry->cur = cur_rb_id; 953: __entry->next = next_rb_id; 954: __entry->level = level; 955: __entry->ticks = gmu_ticks; 956: ), 957: TP_printk("done switch to id=%d from id=%d level=%x ticks=%llu", 958: __entry->next, __entry->cur, __entry->level, __entry->ticks 959: ) 960: ); 961: 962: TRACE_EVENT(adreno_ext_hw_fence_signal, 963: TP_PROTO(u64 context, u64 seq_no, u32 flags, u64 gmu_ticks), 964: TP_ARGS(context, seq_no, flags, gmu_ticks), 965: TP_STRUCT__entry( 966: __field(u64, context) 967: __field(u64, seq_no) 968: __field(u32, flags) 969: __field(u64, ticks) 970: ), 971: TP_fast_assign( 972: __entry->context = context; 973: __entry->seq_no = seq_no; 974: __entry->flags = flags; 975: __entry->ticks = gmu_ticks; 976: ), 977: TP_printk("id=%llu seqno=%llu flags=0x%x ticks=%llu", 978: __entry->context, __entry->seq_no, __entry->flags, __entry->ticks 979: ) 980: ); 981: 982: TRACE_EVENT(adreno_ifpc_count, 983: TP_PROTO(unsigned int ifpc_count), 984: TP_ARGS(ifpc_count), 985: TP_STRUCT__entry( 986: __field(unsigned int, ifpc_count) --- FILE: \Android.mk | HITS: 3 --- MATCH LINES: 36, 53, 54 24: ifneq ($(findstring vendor,$(LOCAL_PATH)),) 25: 26: ifeq ($(BOARD_COMMON_DIR),) 27: BOARD_COMMON_DIR := device/qcom/common 28: endif 29: 30: DLKM_DIR := $(BOARD_COMMON_DIR)/dlkm 31: 32: KBUILD_OPTIONS += BOARD_PLATFORM=$(TARGET_BOARD_PLATFORM) 33: KBUILD_OPTIONS += $(KGSL_SELECT) 34: KBUILD_OPTIONS += MODNAME=msm_kgsl 35: ifeq ($(TARGET_BOARD_PLATFORM), pineapple) 36: KBUILD_OPTIONS += KBUILD_EXTRA_SYMBOLS+=$(PWD)/$(call intermediates-dir-for,DLKM,hw-fence-module-symvers)/Module.symvers 37: endif 38: 39: ifneq ($(filter sun niobe, $(TARGET_BOARD_PLATFORM)),) 40: KBUILD_OPTIONS += KBUILD_EXTRA_SYMBOLS+=$(PWD)/$(call intermediates-dir-for,DLKM,synx-driver-symvers)/synx-driver-symvers 41: endif 42: 43: include $(CLEAR_VARS) 44: # For incremental compilation 45: LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/**/*) $(wildcard $(LOCAL_PATH)/*) 46: LOCAL_MODULE := msm_kgsl.ko 47: LOCAL_MODULE_KBUILD_NAME := msm_kgsl.ko 48: LOCAL_MODULE_TAGS := optional 49: LOCAL_MODULE_DEBUG_ENABLE := true 50: LOCAL_MODULE_PATH := $(KERNEL_MODULES_OUT) 51: 52: ifeq ($(TARGET_BOARD_PLATFORM), pineapple) 53: LOCAL_REQUIRED_MODULES := hw-fence-module-symvers 54: LOCAL_ADDITIONAL_DEPENDENCIES := $(call intermediates-dir-for,DLKM,hw-fence-module-symvers)/Module.symvers 55: endif 56: # Include msm_kgsl.ko in the /vendor/lib/modules (vendor.img) 57: BOARD_VENDOR_KERNEL_MODULES += $(LOCAL_MODULE_PATH)/$(LOCAL_MODULE) 58: include $(DLKM_DIR)/Build_external_kernelmodule.mk 59: 60: endif # DLKM check 61: endif # KGSL_ENABLED --- FILE: \gen7_reg.h | HITS: 9 --- MATCH LINES: 1258, 1259, 1260, 1268, 1269, 1289, 1290, 1291, 1292 1246: #define GEN7_GPU_GMU_CX_PMIC_PAYLOAD_1 0x20005 1247: 1248: #define GEN7_GMU_AO_INTERRUPT_EN 0x23b03 1249: #define GEN7_GMU_AO_HOST_INTERRUPT_CLR 0x23b04 1250: #define GEN7_GMU_AO_HOST_INTERRUPT_STATUS 0x23b05 1251: #define GEN7_GMU_AO_HOST_INTERRUPT_MASK 0x23b06 1252: #define GEN7_GPU_GMU_AO_GMU_CGC_MODE_CNTL 0x23b09 1253: #define GEN7_GPU_GMU_AO_GMU_CGC_DELAY_CNTL 0x23b0a 1254: #define GEN7_GPU_GMU_AO_GMU_CGC_HYST_CNTL 0x23b0b 1255: #define GEN7_GPU_GMU_AO_GPU_CX_BUSY_STATUS 0x23b0c 1256: #define GEN7_GPU_GMU_AO_GPU_CX_BUSY_STATUS2 0x23b0d 1257: #define GEN7_GPU_GMU_AO_GPU_CX_BUSY_MASK 0x23b0e 1258: #define GEN7_GMU_AO_AHB_FENCE_CTRL 0x23b10 1259: #define GEN7_GMU_AHB_FENCE_STATUS 0x23b13 1260: #define GEN7_GMU_AHB_FENCE_STATUS_CLR 0x23b14 1261: #define GEN7_GMU_RBBM_INT_UNMASKED_STATUS 0x23b15 1262: #define GEN7_GPU_GMU_AO_GPU_LPAC_BUSY_STATUS 0x23b30 1263: 1264: /* GMU RSC control registers */ 1265: #define GEN7_GMU_RSCC_CONTROL_REQ 0x23b07 1266: #define GEN7_GMU_RSCC_CONTROL_ACK 0x23b08 1267: 1268: /* FENCE control registers */ 1269: #define GEN7_GMU_AHB_FENCE_RANGE_0 0x23b11 1270: 1271: /* GMU countables */ 1272: #define GEN7_GMU_CM3_BUSY_CYCLES 0 1273: 1274: /* GPUCC registers */ 1275: #define GEN7_11_0_GPU_CC_CX_CFG_GDSCR 0x26424 1276: #define GEN7_13_0_GPU_CC_CX_CFG_GDSCR 0x2643b 1277: #define GEN7_GPU_CC_CX_CFG_GDSCR 0x26443 1278: #define GEN7_17_0_GPU_CC_CX_CFG_GDSCR 0x26445 1279: #define GEN7_GPU_CC_GX_DOMAIN_MISC3 0x26541 1280: 1281: /* GPU RSC sequencer registers */ 1282: #define GEN7_GPU_RSCC_RSC_STATUS0_DRV0 0x00004 1283: #define GEN7_RSCC_PDC_SEQ_START_ADDR 0x00008 1284: #define GEN7_RSCC_PDC_MATCH_VALUE_LO 0x00009 1285: #define GEN7_RSCC_PDC_MATCH_VALUE_HI 0x0000a 1286: #define GEN7_RSCC_PDC_SLAVE_ID_DRV0 0x0000b 1287: #define GEN7_RSCC_HIDDEN_TCS_CMD0_ADDR 0x0000d 1288: #define GEN7_RSCC_HIDDEN_TCS_CMD0_DATA 0x0000e 1289: #define GEN7_RSCC_TIMESTAMP_UNIT0_TIMESTAMP_L_DRV0 0x00082 1290: #define GEN7_RSCC_TIMESTAMP_UNIT0_TIMESTAMP_H_DRV0 0x00083 1291: #define GEN7_RSCC_TIMESTAMP_UNIT1_EN_DRV0 0x00089 1292: #define GEN7_RSCC_TIMESTAMP_UNIT1_OUTPUT_DRV0 0x0008c 1293: #define GEN7_RSCC_OVERRIDE_START_ADDR 0x00100 1294: #define GEN7_RSCC_SEQ_BUSY_DRV0 0x00101 1295: #define GEN7_RSCC_SEQ_MEM_0_DRV0 0x00180 1296: #define GEN7_RSCC_TCS0_DRV0_STATUS 0x00346 1297: #define GEN7_RSCC_TCS1_DRV0_STATUS 0x003ee 1298: #define GEN7_RSCC_TCS2_DRV0_STATUS 0x00496 1299: #define GEN7_RSCC_TCS3_DRV0_STATUS 0x0053e 1300: #define GEN7_RSCC_TCS4_DRV0_STATUS 0x005e6 1301: #define GEN7_RSCC_TCS5_DRV0_STATUS 0x0068e 1302: #define GEN7_RSCC_TCS6_DRV0_STATUS 0x00736 1303: #define GEN7_RSCC_TCS7_DRV0_STATUS 0x007de 1304: #define GEN7_RSCC_TCS8_DRV0_STATUS 0x00886 1305: #define GEN7_RSCC_TCS9_DRV0_STATUS 0x0092e 1306: 1307: /* Device-specific RSCC registers */ 1308: #define GEN7_2_0_RSCC_SEQ_MEM_0_DRV0 0x00154 1309: #define GEN7_2_0_RSCC_TCS0_DRV0_STATUS 0x0034a 1310: #define GEN7_2_0_RSCC_TCS1_DRV0_STATUS 0x003f2 1311: #define GEN7_2_0_RSCC_TCS2_DRV0_STATUS 0x0049a 1312: #define GEN7_2_0_RSCC_TCS3_DRV0_STATUS 0x00542 1313: #define GEN7_2_0_RSCC_TCS4_DRV0_STATUS 0x005ea 1314: #define GEN7_2_0_RSCC_TCS5_DRV0_STATUS 0x00692 1315: #define GEN7_2_0_RSCC_TCS6_DRV0_STATUS 0x0073a 1316: #define GEN7_2_0_RSCC_TCS7_DRV0_STATUS 0x007e2 --- FILE: \gen8_reg.h | HITS: 13 --- MATCH LINES: 594, 595 582: #define GEN8_DBGC_CFG_DBGBUS_TRACE_ADDR 0x62d 583: #define GEN8_DBGC_CFG_DBGBUS_TRACE_BUF0 0x62e 584: #define GEN8_DBGC_CFG_DBGBUS_TRACE_BUF1 0x62f 585: #define GEN8_DBGC_CFG_DBGBUS_TRACE_BUF2 0x630 586: #define GEN8_DBGC_CFG_DBGBUS_TRACE_BUF3 0x631 587: #define GEN8_DBGC_CFG_DBGBUS_TRACE_BUF4 0x632 588: #define GEN8_DBGC_CFG_DBGBUS_MISR0 0x633 589: #define GEN8_DBGC_CFG_DBGBUS_MISR1 0x634 590: #define GEN8_DBGC_EVT_CFG 0x635 591: #define GEN8_DBGC_EVT_INTF_SEL_0 0x636 /* Indexed Register */ 592: #define GEN8_DBGC_EVT_INTF_SEL_1 0x637 /* Indexed Register */ 593: #define GEN8_DBGC_EVT_SLICE_CFG 0x638 594: #define GEN8_DBGC_QDSS_TIMESTAMP_0 0x639 /* Indexed Register */ 595: #define GEN8_DBGC_QDSS_TIMESTAMP_1 0x63a /* Indexed Register */ 596: #define GEN8_DBGC_ECO_CNTL 0x63b 597: #define GEN8_DBGC_AHB_DBG_CNTL 0x63c 598: #define GEN8_DBGC_EVT_INTF_SEL_2 0x63d 599: #define GEN8_DBGC_CFG_DBGBUS_PONG_SEL_A 0x640 600: #define GEN8_DBGC_CFG_DBGBUS_PONG_SEL_B 0x641 601: #define GEN8_DBGC_CFG_DBGBUS_PONG_SEL_C 0x642 602: #define GEN8_DBGC_CFG_DBGBUS_PONG_SEL_D 0x643 603: #define GEN8_DBGC_CFG_DBGBUS_MISC_MODE 0x644 604: #define GEN8_DBGC_EVT_INTF_SEL_3_0 0x650 /* Indexed Register */ 605: #define GEN8_DBGC_EVT_INTF_SEL_3_1 0x651 /* Indexed Register */ 606: #define GEN8_DBGC_EVT_INTF_SEL_3_2 0x652 /* Indexed Register */ 607: #define GEN8_DBGC_EVT_INTF_SEL_3_3 0x653 /* Indexed Register */ 608: #define GEN8_DBGC_EVT_INTF_SEL_3_4 0x654 /* Indexed Register */ 609: #define GEN8_DBGC_EVT_INTF_SEL_3_5 0x655 /* Indexed Register */ 610: #define GEN8_DBGC_TRACE_BUFFER_STATUS 0x660 611: #define GEN8_DBGC_TRACE_BUFFER_CMD 0x661 612: #define GEN8_DBGC_DBG_TRACE_BUFFER_RD_ADDR 0x662 613: #define GEN8_DBGC_DBG_TRACE_BUFFER_RD_DATA 0x663 614: #define GEN8_DBGC_TRACE_BUFFER_ATB_RD_STATUS 0x664 615: #define GEN8_DBGC_SMMU_FAULT_BLOCK_HALT_CFG 0x665 616: #define GEN8_DBGC_DBG_LOPC_SB_RD_ADDR 0x666 617: #define GEN8_DBGC_DBG_LOPC_SB_RD_DATA 0x667 618: #define GEN8_DBGC_DBG_LOPC_SB_WR_ADDR 0x668 619: #define GEN8_DBGC_DBG_LOPC_SB_WR_DATA 0x669 MATCH LINES: 653, 654, 682 641: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_VPC_US_1 0x714 642: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_SP_VS_US 0x715 643: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_SP_PS_US 0x716 644: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_NONE_US 0x720 645: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_NONE_US_1 0x721 646: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_FE_US 0x722 647: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_FE_US_1 0x723 648: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_FE_US_2 0x724 649: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_VPC_US 0x730 650: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_VPC_US_1 0x731 651: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_SP_VS_US 0x732 652: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_NONE_US 0x740 653: #define GEN8_DBGC_CFG_PERF_TIMESTAMP_TRIG_SEL_US 0x742 654: #define GEN8_DBGC_CFG_BV_PERF_TIMESTAMP_TRIG_SEL_US 0x743 655: #define GEN8_DBGC_CFG_GBIF_BR_PERF_CNTR_BASE_LO 0x744 656: #define GEN8_DBGC_CFG_GBIF_BR_PERF_CNTR_BASE_HI 0x745 657: #define GEN8_DBGC_CFG_GBIF_BR_BUFFER_SIZE 0x746 658: #define GEN8_DBGC_CFG_GBIF_BV_PERF_CNTR_BASE_LO 0x747 659: #define GEN8_DBGC_CFG_GBIF_BV_PERF_CNTR_BASE_HI 0x748 660: #define GEN8_DBGC_CFG_GBIF_BV_BUFFER_SIZE 0x749 661: #define GEN8_DBGC_CFG_GBIF_QOS_CTRL 0x74a 662: #define GEN8_DBGC_GBIF_BR_PERF_CNTR_WRITE_POINTER 0x750 663: #define GEN8_DBGC_GBIF_BV_PERF_CNTR_WRITE_POINTER 0x751 664: #define GEN8_DBGC_PERF_COUNTER_FE_LOCAL_BATCH_ID 0x752 665: #define GEN8_DBGC_CFG_PERF_WAIT_IDLE_CLOCKS_CNTL 0x753 666: #define GEN8_DBGC_PERF_COUNTER_SCOPING_CMD_US 0x754 667: #define GEN8_DBGC_PERF_SKEW_BUFFER_INIT_CMD 0x755 668: #define GEN8_DBGC_LOPC_INTERRUPT_STATUS 0x759 669: #define GEN8_DBGC_LOPC_BUFFER_PTR_STATUS 0x75a 670: #define GEN8_DBGC_PERF_SCOPING_STATUS 0x75b 671: #define GEN8_DBGC_PERF_COUNTER_PKT_STATUS 0x75c 672: #define GEN8_DBGC_GC_LIVE_MBX_PKT_STATUS 0x760 673: #define GEN8_DBGC_GC_ALW_MBX_PKT_STATUS 0x761 674: #define GEN8_DBGC_AO_CNTR_LO_STATUS 0x762 675: #define GEN8_DBGC_AO_CNTR_HI_STATUS 0x763 676: #define GEN8_DBGC_LOPC_GC_SB_DEPTH_STATUS 0x770 677: #define GEN8_DBGC_LPAC_SCOPE_PERF_COUNTER_CFG_US 0x780 678: #define GEN8_DBGC_CFG_PERF_TRIG_LPAC_US 0x781 679: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_LPAC_US 0x782 680: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_LPAC_US_1 0x783 681: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_LPAC_US_2 0x784 682: #define GEN8_DBGC_CFG_PERF_TIMESTAMP_TRIG_SEL_LPAC_US 0x785 683: #define GEN8_DBGC_CFG_GBIF_LPAC_PERF_CNTR_BASE_LO 0x786 684: #define GEN8_DBGC_CFG_GBIF_LPAC_PERF_CNTR_BASE_HI 0x787 685: #define GEN8_DBGC_CFG_GBIF_LPAC_BUFFER_SIZE 0x788 686: #define GEN8_DBGC_GBIF_LPAC_PERF_CNTR_WRITE_POINTER 0x789 687: #define GEN8_DBGC_CFG_LPAC_PERF_WAIT_IDLE_CLOCKS_CNTL 0x78a 688: #define GEN8_DBGC_LPAC_PERF_COUNTER_SCOPING_CMD_US 0x78b 689: #define GEN8_DBGC_LPAC_MBX_PKT_STATUS 0x78c 690: #define GEN8_DBGC_LPAC_PERF_SCOPING_STATUS 0x78d 691: #define GEN8_DBGC_LOPC_LPAC_SB_DEPTH_STATUS 0x790 692: #define GEN8_DBGC_SCOPE_PERF_COUNTER_CFG_S 0x7a0 693: #define GEN8_DBGC_CFG_PERF_TRIG_CLUSTER_FE_S 0x7a1 694: #define GEN8_DBGC_CFG_PERF_TRIG_CLUSTER_SP_VS 0x7a2 695: #define GEN8_DBGC_CFG_PERF_TRIG_CLUSTER_VPC_VS 0x7a3 696: #define GEN8_DBGC_CFG_PERF_TRIG_CLUSTER_GRAS 0x7a4 697: #define GEN8_DBGC_CFG_PERF_TRIG_CLUSTER_SP_PS 0x7a5 698: #define GEN8_DBGC_CFG_PERF_TRIG_CLUSTER_VPC_PS 0x7a6 699: #define GEN8_DBGC_CFG_PERF_TRIG_CLUSTER_PS 0x7a7 700: #define GEN8_DBGC_CFG_BV_PERF_TRIG_CLUSTER_FE_S 0x7a8 701: #define GEN8_DBGC_CFG_BV_PERF_TRIG_CLUSTER_SP_VS 0x7a9 702: #define GEN8_DBGC_CFG_BV_PERF_TRIG_CLUSTER_VPC_VS 0x7aa 703: #define GEN8_DBGC_CFG_BV_PERF_TRIG_CLUSTER_GRAS 0x7ab 704: #define GEN8_DBGC_CFG_BV_PERF_TRIG_CLUSTER_VPC_PS 0x7ac 705: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_FE_S 0x7ad 706: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_FE_S_1 0x7ae MATCH LINES: 728, 744, 751 716: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_GRAS_1 0x7b8 717: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_GRAS_2 0x7b9 718: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_SP_PS 0x7ba 719: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_SP_PS_1 0x7bb 720: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_SP_PS_2 0x7bc 721: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_SP_PS_3 0x7bd 722: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_VPC_PS 0x7be 723: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_VPC_PS_1 0x7bf 724: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_PS 0x7c0 725: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_PS_1 0x7c1 726: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_PS_2 0x7c2 727: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_PS_3 0x7c3 728: #define GEN8_DBGC_CFG_PERF_TIMESTAMP_TRIG_SEL_S 0x7c4 729: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_FE_S 0x7c5 730: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_FE_S_1 0x7c6 731: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_FE_S_2 0x7c7 732: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_FE_S_3 0x7c8 733: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_SP_VS 0x7c9 734: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_SP_VS_1 0x7ca 735: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_SP_VS_2 0x7cb 736: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_SP_VS_3 0x7cc 737: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_VPC_VS 0x7cd 738: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_VPC_VS_1 0x7ce 739: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_GRAS 0x7cf 740: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_GRAS_1 0x7d0 741: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_GRAS_2 0x7d1 742: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_VPC_PS 0x7d2 743: #define GEN8_DBGC_CFG_BV_PERF_COUNTER_SEL_VPC_PS_1 0x7d3 744: #define GEN8_DBGC_CFG_BV_PERF_TIMESTAMP_TRIG_SEL_S 0x7d4 745: #define GEN8_DBGC_PERF_COUNTER_SCOPING_CMD_S 0x7d5 746: #define GEN8_DBGC_LPAC_SCOPE_PERF_COUNTER_CFG_S 0x7e0 747: #define GEN8_DBGC_CFG_PERF_TRIG_LPAC_S 0x7e1 748: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_LPAC_S 0x7e2 749: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_LPAC_S_1 0x7e3 750: #define GEN8_DBGC_CFG_PERF_COUNTER_SEL_LPAC_S_2 0x7e4 751: #define GEN8_DBGC_CFG_PERF_TIMESTAMP_TRIG_SEL_LPAC_S 0x7e5 752: #define GEN8_DBGC_LPAC_PERF_COUNTER_SCOPING_CMD_S 0x7e6 753: 754: /* VSC registers */ 755: #define GEN8_VSC_PERFCTR_VSC_SEL_0 0xcd8 756: #define GEN8_VSC_PERFCTR_VSC_SEL_1 0xcd9 757: #define GEN8_VSC_KMD_DBG_ECO_CNTL 0xdf0 758: #define GEN8_VSC_VISIBILITY_FLUSH_CNTL 0xdf8 759: 760: /* CP registers */ 761: #define GEN8_CP_RB_BASE_LO_GC 0x800 762: #define GEN8_CP_RB_BASE_HI_GC 0x801 763: #define GEN8_CP_RB_CNTL_GC 0x802 764: #define GEN8_CP_RB_RPTR_WR_GC 0x803 765: #define GEN8_CP_RB_RPTR_ADDR_LO_BR 0x804 766: #define GEN8_CP_RB_RPTR_ADDR_HI_BR 0x805 767: #define GEN8_CP_RB_RPTR_BR 0x806 768: #define GEN8_CP_RB_WPTR_GC 0x807 769: #define GEN8_CP_RB_RPTR_ADDR_LO_BV 0x808 770: #define GEN8_CP_RB_RPTR_ADDR_HI_BV 0x809 771: #define GEN8_CP_RB_RPTR_BV 0x80a 772: #define GEN8_CP_RB_BASE_LO_LPAC 0x80b 773: #define GEN8_CP_RB_BASE_HI_LPAC 0x80c 774: #define GEN8_CP_RB_CNTL_LPAC 0x80d 775: #define GEN8_CP_RB_RPTR_WR_LPAC 0x80e MATCH LINES: 1634, 1635, 1636, 1637, 1638 1622: 1623: /* GMU RSC control registers */ 1624: #define GEN8_GMUAO_RSCC_CONTROL_REQ 0x23b07 1625: #define GEN8_GMUAO_RSCC_CONTROL_ACK 0x23b08 1626: 1627: #define GEN8_GMUAO_CGC_MODE_CNTL 0x23b09 1628: #define GEN8_GMUAO_CGC_DELAY_CNTL 0x23b0a 1629: #define GEN8_GMUAO_CGC_HYST_CNTL 0x23b0b 1630: #define GEN8_GMUAO_GPU_CX_BUSY_STATUS 0x23b0c 1631: #define GEN8_GMUAO_GPU_CX_BUSY_STATUS2 0x23b0d 1632: #define GEN8_GMUAO_GPU_CX_BUSY_MASK 0x23b0e 1633: 1634: /* FENCE control registers */ 1635: #define GEN8_GMUAO_AHB_FENCE_CTRL 0x23b10 1636: #define GEN8_GMUAO_AHB_FENCE_RANGE_0 0x23b11 1637: #define GEN8_GMUAO_AHB_FENCE_STATUS 0x23b13 1638: #define GEN8_GMUAO_AHB_FENCE_STATUS_CLR 0x23b14 1639: #define GEN8_GMUAO_RBBM_INT_UNMASKED_STATUS_SHADOW 0x23b15 1640: #define GEN8_GMUAO_LPAC_BUSY_STATUS 0x23b30 1641: 1642: /* GMU countables */ 1643: #define GEN8_GMU_CM3_BUSY_CYCLES 0 1644: 1645: /* GPUCC registers */ 1646: #define GEN8_GPU_CC_CX_CFG_GDSCR 0x26421 1647: #define GEN8_GPU_CC_GX_DOMAIN_MISC3 0x26541 1648: 1649: /* GPU RSC sequencer registers */ 1650: #define GEN8_GPU_RSCC_RSC_STATUS0_DRV0 0x00004 1651: #define GEN8_RSCC_SEQ_BUSY_DRV0 0x00101 1652: #define GEN8_RSCC_TCS0_DRV0_STATUS 0x0034a 1653: #define GEN8_RSCC_TCS1_DRV0_STATUS 0x003f2 1654: #define GEN8_RSCC_TCS2_DRV0_STATUS 0x0049a 1655: #define GEN8_RSCC_TCS3_DRV0_STATUS 0x00542 1656: #define GEN8_RSCC_TCS4_DRV0_STATUS 0x005ea 1657: #define GEN8_RSCC_TCS5_DRV0_STATUS 0x00692 1658: #define GEN8_RSCC_TCS6_DRV0_STATUS 0x0073a 1659: #define GEN8_RSCC_TCS7_DRV0_STATUS 0x007e2 1660: #define GEN8_RSCC_TCS8_DRV0_STATUS 0x0088a 1661: #define GEN8_RSCC_TCS9_DRV0_STATUS 0x00932 1662: --- FILE: \Kconfig | HITS: 8 --- MATCH LINES: 15, 16, 19, 20 3: tristate "Qualcomm Technologies, Inc. 3D Graphics driver" 4: depends on ARCH_QCOM 5: depends on NVMEM_QCOM_QFPROM || QCOM_QFPROM 6: select QCOM_MDT_LOADER 7: select INTERVAL_TREE 8: select TRACE_GPU_MEM 9: help 10: 3D graphics driver for the Adreno family of GPUs from QTI. 11: Required to use hardware accelerated OpenGL, compute and Vulkan 12: on QTI targets. This includes power management, memory management, 13: and scheduling for the Adreno GPUs. 14: 15: config QCOM_KGSL_FENCE_TRACE 16: bool "Enable built-in tracing for adreno fence timeouts" 17: help 18: A boolean flag used to create a KGSL-specific tracing instance 19: under /tracing/instances/kgsl-fence that can be used 20: for debugging timeouts for fences between KGSL-contexts and 21: sync-point blocks. If unsure, say 'N' here. 22: 23: config QCOM_ADRENO_DEFAULT_GOVERNOR 24: string "devfreq governor for the adreno core" 25: default "msm-adreno-tz" 26: 27: config QCOM_KGSL_CORESIGHT 28: bool "Enable coresight support for the Adreno GPU" 29: depends on CORESIGHT 30: default y 31: help 32: When enabled, the Adreno GPU is available as a source for Coresight 33: data. On a6xx targets there are two sources available for the GX and 34: CX domains respectively. Debug kernels should say 'Y' here. 35: 36: config QCOM_KGSL_IOCOHERENCY_DEFAULT 37: bool "Enable I/O coherency on cached GPU memory by default" 38: default y if ARCH_LAHAINA 39: help 40: Say 'Y' here to enable I/O cache coherency by default on targets that 41: support hardware I/O coherency. If enabled all cached GPU memory 42: will use I/O coherency regardless of the user flags. If not enabled 43: the user can still selectively enable I/O coherency with a flag. 44: MATCH LINES: 105, 108, 109, 110 93: process. Based on this kgsl can unpin given number of pages from 94: background processes and make them available to the shrinker. 95: 96: config QCOM_KGSL_HIBERNATION 97: bool "Enable Hibernation support in KGSL" 98: depends on HIBERNATION 99: help 100: Say 'Y' to enable hibernation support in kgsl. If enabled, kgsl 101: will register necessary power manager callbacks to support 102: hibernation. 103: 104: config QCOM_KGSL_SYNX 105: bool "Use synx APIs in KGSL for HW fences" 106: help 107: Say 'Y' to enable synx API in kgsl. If enabled, kgsl will use 108: synx API for HW fence feature. This allows hardware fence inter-op 109: between HW fence clients and SYNX clients. If not enabled, then 110: kgsl will use msm_hw_fence APIs for hardware fence feature. 111: 112: config QCOM_KGSL_RT_MUTEX 113: bool "Use RT-mutex in KGSL" 114: depends on RT_MUTEXES 115: help 116: Say 'Y' to use RT-mutex instead of mutex in KGSL driver. If 117: enabled, KGSL will use RT-mutex instead of mutex to prevent 118: priority inversion. RT-mutexes extend the semantics of simple 119: mutexes by the priority inheritance protocol. 120: 121: config QCOM_KGSL_DEVCOREDUMP 122: bool "Use devcoredump for KGSL snapshots" 123: depends on DEV_COREDUMP 124: help 125: Say 'Y' to use devcoredump framework for GPU snapshot dumps 126: instead of the custom sysfs interface. Snapshot data will be 127: accessible through /sys/class/devcoredump/ interface. If enabled, 128: the snapshot/dump sysfs node will not be set up. 129: 130: config QCOM_KGSL_UPSTREAM 131: bool "Enable KGSL compilation with upstream kernel" 132: help 133: Say 'Y' to enable kgsl compilation with upstream kernel. If enabled, 134: all downstream dependencies are stubbed out. --- FILE: \kgsl.c | HITS: 80 --- MATCH LINES: 253, 254, 257, 258 241: entry->gpuaddr = gpuaddr; 242: entry->size = size; 243: entry->flags = flags; 244: 245: memfree.head = (memfree.head + 1) % MEMFREE_ENTRIES; 246: 247: if (memfree.head == memfree.tail) 248: memfree.tail = (memfree.tail + 1) % MEMFREE_ENTRIES; 249: 250: spin_unlock(&memfree_lock); 251: } 252: 253: int kgsl_readtimestamp(struct kgsl_device *device, void *priv, 254: enum kgsl_timestamp_type type, unsigned int *timestamp) 255: { 256: if (device) 257: return device->ftbl->readtimestamp(device, priv, type, 258: timestamp); 259: return -EINVAL; 260: 261: } 262: 263: const char *kgsl_context_type(int type) 264: { 265: if (type == KGSL_CONTEXT_TYPE_GL) 266: return "GL"; 267: else if (type == KGSL_CONTEXT_TYPE_CL) 268: return "CL"; 269: else if (type == KGSL_CONTEXT_TYPE_C2D) 270: return "C2D"; 271: else if (type == KGSL_CONTEXT_TYPE_RS) 272: return "RS"; 273: else if (type == KGSL_CONTEXT_TYPE_VK) 274: return "VK"; 275: 276: return "ANY"; 277: } 278: 279: static struct kgsl_mem_entry *kgsl_mem_entry_create(void) 280: { 281: struct kgsl_mem_entry *entry = kzalloc(sizeof(*entry), GFP_KERNEL); 282: MATCH LINES: 661 649: #else 650: static void kgsl_context_debug_info(struct kgsl_device *device) 651: { 652: } 653: #endif 654: 655: /** 656: * kgsl_context_dump() - dump information about a draw context 657: * @device: KGSL device that owns the context 658: * @context: KGSL context to dump information about 659: * 660: * Dump specific information about the context to the kernel log. Used for 661: * fence timeout callbacks 662: */ 663: void kgsl_context_dump(struct kgsl_context *context) 664: { 665: struct kgsl_device *device; 666: 667: if (_kgsl_context_get(context) == 0) 668: return; 669: 670: device = context->device; 671: 672: if (kgsl_context_detached(context)) { 673: dev_err(device->dev, " context[%u]: context detached\n", 674: context->id); 675: } else if (device->ftbl->drawctxt_dump != NULL) 676: device->ftbl->drawctxt_dump(device, context); 677: 678: kgsl_context_put(context); 679: } 680: 681: /* Allocate a new context ID */ 682: static int _kgsl_get_context_id(struct kgsl_device *device) 683: { 684: int id; 685: MATCH LINES: 784 772: context->device = device; 773: context->dev_priv = dev_priv; 774: context->proc_priv = proc_priv; 775: context->tid = task_pid_nr(current); 776: 777: ret = kgsl_sync_timeline_create(context); 778: if (ret) { 779: kgsl_process_private_put(proc_priv); 780: goto out; 781: } 782: 783: kgsl_add_event_group(device, &context->events, context, 784: kgsl_readtimestamp, context, "context-%d", id); 785: 786: out: 787: if (ret) { 788: atomic_dec(&proc_priv->ctxt_count); 789: write_lock(&device->context_lock); 790: idr_remove(&device->context_idr, id); 791: write_unlock(&device->context_lock); 792: } 793: 794: return ret; 795: } 796: 797: void kgsl_free_faults(struct kgsl_context *context) 798: { 799: struct kgsl_fault_node *p, *tmp; 800: 801: if (!(context->flags & KGSL_CONTEXT_FAULT_INFO)) 802: return; 803: 804: list_for_each_entry_safe(p, tmp, &context->faults, node) { 805: list_del(&p->node); 806: kfree(p->priv); 807: kfree(p); 808: } MATCH LINES: 879, 881, 883 867: /* 868: * It's not safe to destroy the context if it's not detached as GPU 869: * may still be executing commands 870: */ 871: BUG_ON(!kgsl_context_detached(context)); 872: 873: kgsl_free_faults(context); 874: kgsl_sync_timeline_put(context->ktimeline); 875: 876: write_lock(&device->context_lock); 877: if (context->id != KGSL_CONTEXT_INVALID) { 878: 879: /* Clear the timestamps in the memstore during destroy */ 880: kgsl_sharedmem_writel(device->memstore, 881: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 0); 882: kgsl_sharedmem_writel(device->memstore, 883: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 0); 884: 885: /* clear device power constraint */ 886: if (context->id == device->pwrctrl.constraint.owner_id) { 887: trace_kgsl_constraint(device, 888: device->pwrctrl.constraint.type, 889: device->pwrctrl.active_pwrlevel, 890: 0, 0); 891: device->pwrctrl.constraint.type = KGSL_CONSTRAINT_NONE; 892: } 893: 894: atomic_dec(&context->proc_priv->ctxt_count); 895: idr_remove(&device->context_idr, context->id); 896: context->id = KGSL_CONTEXT_INVALID; 897: } 898: write_unlock(&device->context_lock); 899: kgsl_process_private_put(context->proc_priv); 900: 901: device->ftbl->drawctxt_destroy(context); 902: } 903: 904: struct kgsl_device *kgsl_get_device(int dev_idx) 905: { 906: int i; 907: struct kgsl_device *ret = NULL; MATCH LINES: 937, 939, 940, 942, 943, 947, 950 925: 926: if (minor < 0 || minor >= ARRAY_SIZE(kgsl_driver.devp)) 927: return NULL; 928: 929: mutex_lock(&kgsl_driver.devlock); 930: ret = kgsl_driver.devp[minor]; 931: mutex_unlock(&kgsl_driver.devlock); 932: 933: return ret; 934: } 935: 936: /** 937: * kgsl_check_timestamp() - return true if the specified timestamp is retired 938: * @device: Pointer to the KGSL device to check 939: * @context: Pointer to the context for the timestamp 940: * @timestamp: The timestamp to compare 941: */ 942: bool kgsl_check_timestamp(struct kgsl_device *device, 943: struct kgsl_context *context, unsigned int timestamp) 944: { 945: unsigned int ts_processed; 946: 947: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, 948: &ts_processed); 949: 950: return (timestamp_cmp(ts_processed, timestamp) >= 0); 951: } 952: 953: static void kgsl_work_period_release(struct kref *kref) 954: { 955: struct gpu_work_period *wp = container_of(kref, 956: struct gpu_work_period, refcount); 957: 958: spin_lock(&kgsl_driver.wp_list_lock); 959: if (!list_empty(&wp->list)) 960: list_del_init(&wp->list); 961: spin_unlock(&kgsl_driver.wp_list_lock); 962: 963: kfree(wp); 964: } 965: 966: static void kgsl_put_work_period(struct gpu_work_period *wp) 967: { 968: if (!IS_ERR_OR_NULL(wp)) 969: kref_put(&wp->refcount, kgsl_work_period_release); 970: } 971: 972: /** 973: * kgsl_destroy_process_private() - Cleanup function to free process private 974: * @kref: - Pointer to object being destroyed's kref struct MATCH LINES: 1664, 1700 1652: spin_lock(&entry->priv->mem_lock); 1653: entry->pending_free = 0; 1654: spin_unlock(&entry->priv->mem_lock); 1655: } 1656: 1657: /** 1658: * kgsl_mem_entry_set_pend() - Set the pending free flag of a memory entry 1659: * @entry - The memory entry 1660: * 1661: * @returns - true if pending flag was 0 else false 1662: * 1663: * This function will set the pending free flag if it is previously unset. Used 1664: * to prevent race condition between ioctls calling free/freememontimestamp 1665: * on the same entry. Whichever thread set's the flag first will do the free. 1666: */ 1667: static inline bool kgsl_mem_entry_set_pend(struct kgsl_mem_entry *entry) 1668: { 1669: bool ret = false; 1670: 1671: if (entry == NULL) 1672: return false; 1673: 1674: spin_lock(&entry->priv->mem_lock); 1675: if (!entry->pending_free) { 1676: entry->pending_free = 1; 1677: ret = true; 1678: } 1679: spin_unlock(&entry->priv->mem_lock); 1680: return ret; 1681: } 1682: 1683: static int kgsl_get_ctxt_fault_stats(struct kgsl_context *context, 1684: struct kgsl_context_property *ctxt_property) 1685: { 1686: struct kgsl_context_property_fault fault_stats; 1687: size_t copy; 1688: 1689: /* Return the size of the subtype struct */ 1690: if (ctxt_property->size == 0) { 1691: ctxt_property->size = sizeof(fault_stats); 1692: return 0; 1693: } 1694: 1695: memset(&fault_stats, 0, sizeof(fault_stats)); 1696: 1697: copy = min_t(size_t, ctxt_property->size, sizeof(fault_stats)); 1698: 1699: fault_stats.faults = context->total_fault_count; 1700: fault_stats.timestamp = context->last_faulted_cmd_ts; 1701: 1702: /* 1703: * Copy the context fault stats to data which also serves as 1704: * the out parameter. 1705: */ 1706: if (copy_to_user(u64_to_user_ptr(ctxt_property->data), 1707: &fault_stats, copy)) 1708: return -EFAULT; 1709: 1710: return 0; 1711: } 1712: 1713: static long kgsl_get_ctxt_properties(struct kgsl_device_private *dev_priv, 1714: struct kgsl_device_getproperty *param) 1715: { 1716: /* Return fault stats of given context */ 1717: struct kgsl_context_property ctxt_property; 1718: struct kgsl_context *context; 1719: size_t copy; 1720: long ret; 1721: 1722: /* 1723: * If sizebytes is zero, tell the user how big the 1724: * ctxt_property struct should be. MATCH LINES: 2063, 2067, 2077, 2080, 2081, 2083, 2086, 2088 2051: if (is_compat_task()) 2052: result = dev_priv->device->ftbl->setproperty_compat( 2053: dev_priv, param->type, param->value, 2054: param->sizebytes); 2055: else if (dev_priv->device->ftbl->setproperty) 2056: result = dev_priv->device->ftbl->setproperty( 2057: dev_priv, param->type, param->value, 2058: param->sizebytes); 2059: 2060: return result; 2061: } 2062: 2063: long kgsl_ioctl_device_waittimestamp_ctxtid( 2064: struct kgsl_device_private *dev_priv, unsigned int cmd, 2065: void *data) 2066: { 2067: struct kgsl_device_waittimestamp_ctxtid *param = data; 2068: struct kgsl_device *device = dev_priv->device; 2069: long result = -EINVAL; 2070: unsigned int temp_cur_ts = 0; 2071: struct kgsl_context *context; 2072: 2073: context = kgsl_context_get_owner(dev_priv, param->context_id); 2074: if (context == NULL) 2075: return result; 2076: 2077: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, 2078: &temp_cur_ts); 2079: 2080: trace_kgsl_waittimestamp_entry(device, context->id, temp_cur_ts, 2081: param->timestamp, param->timeout); 2082: 2083: result = device->ftbl->waittimestamp(device, context, param->timestamp, 2084: param->timeout); 2085: 2086: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, 2087: &temp_cur_ts); 2088: trace_kgsl_waittimestamp_exit(device, temp_cur_ts, result); 2089: 2090: kgsl_context_put(context); 2091: 2092: return result; 2093: } 2094: 2095: long kgsl_ioctl_rb_issueibcmds(struct kgsl_device_private *dev_priv, 2096: unsigned int cmd, void *data) 2097: { 2098: struct kgsl_ringbuffer_issueibcmds *param = data; 2099: struct kgsl_device *device = dev_priv->device; 2100: struct kgsl_context *context; 2101: struct kgsl_drawobj *drawobj; 2102: struct kgsl_drawobj_cmd *cmdobj; 2103: long result = -EINVAL; 2104: 2105: /* The legacy functions don't support synchronization commands */ 2106: if ((param->flags & (KGSL_DRAWOBJ_SYNC | KGSL_DRAWOBJ_MARKER))) 2107: return -EINVAL; 2108: 2109: /* Sanity check the number of IBs */ 2110: if (param->flags & KGSL_DRAWOBJ_SUBMIT_IB_LIST && 2111: (param->numibs == 0 || param->numibs > KGSL_MAX_NUMIBS)) 2112: return -EINVAL; MATCH LINES: 2148 2136: ibdesc.gpuaddr = param->ibdesc_addr; 2137: ibdesc.sizedwords = param->numibs; 2138: ibdesc.ctrl = 0; 2139: 2140: result = kgsl_drawobj_cmd_add_ibdesc(device, cmdobj, &ibdesc); 2141: } 2142: 2143: if (result == 0) 2144: result = kgsl_reclaim_to_pinned_state(dev_priv->process_priv); 2145: 2146: if (result == 0) 2147: result = device->ftbl->queue_cmds(dev_priv, context, 2148: &drawobj, 1, ¶m->timestamp); 2149: 2150: /* 2151: * -EPROTO is a "success" error - it just tells the user that the 2152: * context had previously faulted 2153: */ 2154: if (result && result != -EPROTO) 2155: kgsl_drawobj_destroy(drawobj); 2156: 2157: kgsl_context_put(context); 2158: return result; 2159: } 2160: 2161: /* Returns 0 on failure. Returns command type(s) on success */ 2162: static unsigned int _process_command_input(struct kgsl_device *device, 2163: unsigned int flags, unsigned int numcmds, 2164: unsigned int numobjs, unsigned int numsyncs) 2165: { 2166: if (numcmds > KGSL_MAX_NUMIBS || 2167: numobjs > KGSL_MAX_NUMIBS || 2168: numsyncs > KGSL_MAX_SYNCPOINTS) 2169: return 0; 2170: 2171: /* 2172: * The SYNC bit is supposed to identify a dummy sync object MATCH LINES: 2266 2254: DRAWOBJ(cmdobj)->flags &= 2255: ~(unsigned long)KGSL_DRAWOBJ_PROFILING; 2256: 2257: if (type & CMDOBJ_TYPE) { 2258: result = kgsl_reclaim_to_pinned_state( 2259: dev_priv->process_priv); 2260: if (result) 2261: goto done; 2262: } 2263: } 2264: 2265: result = device->ftbl->queue_cmds(dev_priv, context, drawobj, 2266: i, ¶m->timestamp); 2267: 2268: done: 2269: /* 2270: * -EPROTO is a "success" error - it just tells the user that the 2271: * context had previously faulted 2272: */ 2273: if (result && result != -EPROTO) 2274: while (i--) 2275: kgsl_drawobj_destroy(drawobj[i]); 2276: 2277: 2278: kgsl_context_put(context); 2279: return result; 2280: } 2281: 2282: long kgsl_ioctl_gpu_command(struct kgsl_device_private *dev_priv, 2283: unsigned int cmd, void *data) 2284: { 2285: struct kgsl_gpu_command *param = data; 2286: struct kgsl_device *device = dev_priv->device; 2287: struct kgsl_context *context; 2288: struct kgsl_drawobj *drawobj[2]; 2289: unsigned int type; 2290: long result; MATCH LINES: 2361 2349: DRAWOBJ(cmdobj)->flags &= 2350: ~(unsigned long)KGSL_DRAWOBJ_PROFILING; 2351: 2352: if (type & CMDOBJ_TYPE) { 2353: result = kgsl_reclaim_to_pinned_state( 2354: dev_priv->process_priv); 2355: if (result) 2356: goto done; 2357: } 2358: } 2359: 2360: result = device->ftbl->queue_cmds(dev_priv, context, drawobj, 2361: i, ¶m->timestamp); 2362: 2363: done: 2364: /* 2365: * -EPROTO is a "success" error - it just tells the user that the 2366: * context had previously faulted 2367: */ 2368: if (result && result != -EPROTO) 2369: while (i--) 2370: kgsl_drawobj_destroy(drawobj[i]); 2371: 2372: kgsl_context_put(context); 2373: return result; 2374: } 2375: 2376: long kgsl_ioctl_gpu_aux_command(struct kgsl_device_private *dev_priv, 2377: unsigned int cmd, void *data) 2378: { 2379: struct kgsl_gpu_aux_command *param = data; 2380: struct kgsl_device *device = dev_priv->device; 2381: struct kgsl_context *context; 2382: struct kgsl_drawobj **drawobjs; 2383: void __user *cmdlist; 2384: u32 count; 2385: int i, index = 0; MATCH LINES: 2407, 2409, 2422, 2459, 2462, 2465 2395: return -EINVAL; 2396: 2397: if ((param->flags & KGSL_GPU_AUX_COMMAND_SYNC) && 2398: (param->numsyncs > KGSL_MAX_SYNCPOINTS)) 2399: return -EINVAL; 2400: 2401: context = kgsl_context_get_owner(dev_priv, param->context_id); 2402: if (!context) 2403: return -EINVAL; 2404: 2405: /* 2406: * param->numcmds is always one and we have one additional drawobj 2407: * for the timestamp sync if KGSL_GPU_AUX_COMMAND_SYNC flag is passed. 2408: * On top of that we make an implicit sync object for the last queued 2409: * timestamp on this context. 2410: */ 2411: count = (param->flags & KGSL_GPU_AUX_COMMAND_SYNC) ? 3 : 2; 2412: 2413: drawobjs = kvcalloc(count, sizeof(*drawobjs), 2414: GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN); 2415: 2416: if (!drawobjs) { 2417: kgsl_context_put(context); 2418: return -ENOMEM; 2419: } 2420: 2421: trace_kgsl_aux_command(context->id, param->numcmds, param->flags, 2422: param->timestamp); 2423: 2424: if (param->flags & KGSL_GPU_AUX_COMMAND_SYNC) { 2425: struct kgsl_drawobj_sync *syncobj = 2426: kgsl_drawobj_sync_create(device, context); 2427: 2428: if (IS_ERR(syncobj)) { 2429: ret = PTR_ERR(syncobj); 2430: goto err; 2431: } 2432: 2433: drawobjs[index++] = DRAWOBJ(syncobj); 2434: 2435: ret = kgsl_drawobj_sync_add_synclist(device, syncobj, 2436: u64_to_user_ptr(param->synclist), 2437: param->syncsize, param->numsyncs); 2438: if (ret) 2439: goto err; 2440: } 2441: 2442: cmdlist = u64_to_user_ptr(param->cmdlist); 2443: 2444: /* 2445: * Create a draw object for KGSL_GPU_AUX_COMMAND_BIND or 2446: * KGSL_GPU_AUX_COMMAND_TIMELINE. 2447: */ 2448: if (copy_struct_from_user(&generic, sizeof(generic), 2449: cmdlist, param->cmdsize)) { 2450: ret = -EFAULT; 2451: goto err; 2452: } 2453: 2454: if (generic.type == KGSL_GPU_AUX_COMMAND_BIND) { 2455: struct kgsl_drawobj_sync *tsobj; 2456: struct kgsl_drawobj_bind *bindobj; 2457: u32 queued; 2458: 2459: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_QUEUED, 2460: &queued); 2461: /* 2462: * Make an implicit sync object for the last queued timestamp 2463: * on this context 2464: */ 2465: tsobj = kgsl_drawobj_create_timestamp_syncobj(device, 2466: context, queued); 2467: 2468: if (IS_ERR(tsobj)) { 2469: ret = PTR_ERR(tsobj); 2470: goto err; 2471: } 2472: 2473: drawobjs[index++] = DRAWOBJ(tsobj); 2474: 2475: bindobj = kgsl_drawobj_bind_create(device, context); 2476: 2477: if (IS_ERR(bindobj)) { 2478: ret = PTR_ERR(bindobj); 2479: goto err; 2480: } 2481: 2482: drawobjs[index++] = DRAWOBJ(bindobj); 2483: 2484: ret = kgsl_drawobj_add_bind(dev_priv, bindobj, 2485: cmdlist, param->cmdsize); 2486: if (ret) 2487: goto err; 2488: } else if (generic.type == KGSL_GPU_AUX_COMMAND_TIMELINE) { 2489: struct kgsl_drawobj_timeline *timelineobj; MATCH LINES: 2508, 2509, 2527 2496: ret = PTR_ERR(timelineobj); 2497: goto err; 2498: } 2499: 2500: drawobjs[index++] = DRAWOBJ(timelineobj); 2501: 2502: ret = kgsl_drawobj_add_timeline(dev_priv, timelineobj, 2503: cmdlist, param->cmdsize); 2504: if (ret) 2505: goto err; 2506: 2507: /* 2508: * Userspace needs a timestamp to associate with this 2509: * submisssion. Use a marker to keep the timestamp 2510: * bookkeeping correct. 2511: */ 2512: markerobj = kgsl_drawobj_cmd_create(device, context, 2513: KGSL_DRAWOBJ_MARKER, MARKEROBJ_TYPE); 2514: 2515: if (IS_ERR(markerobj)) { 2516: ret = PTR_ERR(markerobj); 2517: goto err; 2518: } 2519: 2520: drawobjs[index++] = DRAWOBJ(markerobj); 2521: } else { 2522: ret = -EINVAL; 2523: goto err; 2524: } 2525: 2526: ret = device->ftbl->queue_cmds(dev_priv, context, 2527: drawobjs, index, ¶m->timestamp); 2528: 2529: err: 2530: kgsl_context_put(context); 2531: 2532: if (ret && ret != -EPROTO) { 2533: for (i = 0; i < count; i++) 2534: kgsl_drawobj_destroy(drawobjs[i]); 2535: } 2536: 2537: kvfree(drawobjs); 2538: return ret; 2539: } 2540: 2541: /* Returns 0 on failure. Returns command type(s) on success */ 2542: static unsigned int _process_recurring_input(struct kgsl_device *device, 2543: unsigned int flags, unsigned int numcmds, 2544: unsigned int numobjs) 2545: { 2546: if (numcmds > KGSL_MAX_NUMIBS || 2547: numobjs > KGSL_MAX_NUMIBS) 2548: return 0; 2549: 2550: /* SYNC and MARKER object is not allowed through recurring command */ 2551: if ((flags & KGSL_DRAWOBJ_MARKER) || (flags & KGSL_DRAWOBJ_SYNC)) MATCH LINES: 2630, 2634, 2642, 2643, 2645, 2646 2618: /* 2619: * -EPROTO is a "success" error - it just tells the user that the 2620: * context had previously faulted 2621: */ 2622: if (result && result != -EPROTO) 2623: kgsl_drawobj_destroy(drawobj); 2624: 2625: kgsl_context_put(context); 2626: 2627: return result; 2628: } 2629: 2630: long kgsl_ioctl_cmdstream_readtimestamp_ctxtid(struct kgsl_device_private 2631: *dev_priv, unsigned int cmd, 2632: void *data) 2633: { 2634: struct kgsl_cmdstream_readtimestamp_ctxtid *param = data; 2635: struct kgsl_device *device = dev_priv->device; 2636: struct kgsl_context *context; 2637: long result = -EINVAL; 2638: 2639: context = kgsl_context_get_owner(dev_priv, param->context_id); 2640: 2641: if (context) { 2642: result = kgsl_readtimestamp(device, context, 2643: param->type, ¶m->timestamp); 2644: 2645: trace_kgsl_readtimestamp(device, context->id, 2646: param->type, param->timestamp); 2647: } 2648: 2649: kgsl_context_put(context); 2650: return result; 2651: } 2652: 2653: long kgsl_ioctl_drawctxt_create(struct kgsl_device_private *dev_priv, 2654: unsigned int cmd, void *data) 2655: { 2656: int result = 0; 2657: struct kgsl_drawctxt_create *param = data; 2658: struct kgsl_context *context = NULL; 2659: struct kgsl_device *device = dev_priv->device; 2660: 2661: context = device->ftbl->drawctxt_create(dev_priv, ¶m->flags); 2662: if (IS_ERR(context)) { 2663: result = PTR_ERR(context); 2664: goto done; 2665: } 2666: trace_kgsl_context_create(device, context, param->flags); 2667: 2668: /* Commit the pointer to the context in context_idr */ 2669: write_lock(&device->context_lock); 2670: idr_replace(&device->context_idr, context, context->id); MATCH LINES: 2716, 2718, 2721, 2722, 2732, 2734, 2742, 2743, 2744, 2746 2704: entry->memdesc.flags); 2705: 2706: kgsl_mem_entry_put(entry); 2707: 2708: return 0; 2709: } 2710: 2711: static void gpumem_free_func(struct kgsl_device *device, 2712: struct kgsl_event_group *group, void *priv, int ret) 2713: { 2714: struct kgsl_context *context = group->context; 2715: struct kgsl_mem_entry *entry = priv; 2716: unsigned int timestamp; 2717: 2718: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, ×tamp); 2719: 2720: /* Free the memory for all event types */ 2721: trace_kgsl_mem_timestamp_free(device, entry, KGSL_CONTEXT_ID(context), 2722: timestamp, 0); 2723: kgsl_memfree_add(pid_nr(entry->priv->pid), 2724: entry->memdesc.pagetable ? 2725: entry->memdesc.pagetable->name : 0, 2726: entry->memdesc.gpuaddr, entry->memdesc.size, 2727: entry->memdesc.flags); 2728: 2729: kgsl_mem_entry_put_deferred(entry); 2730: } 2731: 2732: static long gpumem_free_entry_on_timestamp(struct kgsl_device *device, 2733: struct kgsl_mem_entry *entry, 2734: struct kgsl_context *context, unsigned int timestamp) 2735: { 2736: int ret; 2737: unsigned int temp; 2738: 2739: if (!kgsl_mem_entry_set_pend(entry)) 2740: return -EBUSY; 2741: 2742: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, &temp); 2743: trace_kgsl_mem_timestamp_queue(device, entry, context->id, temp, 2744: timestamp); 2745: ret = kgsl_add_event(device, &context->events, 2746: timestamp, gpumem_free_func, entry); 2747: 2748: if (ret) 2749: kgsl_mem_entry_unset_pend(entry); 2750: 2751: return ret; 2752: } 2753: 2754: long kgsl_ioctl_sharedmem_free(struct kgsl_device_private *dev_priv, 2755: unsigned int cmd, void *data) 2756: { 2757: struct kgsl_sharedmem_free *param = data; 2758: struct kgsl_process_private *private = dev_priv->process_priv; 2759: struct kgsl_mem_entry *entry; 2760: long ret; 2761: 2762: entry = kgsl_sharedmem_find(private, (uint64_t) param->gpuaddr); 2763: if (entry == NULL) 2764: return -EINVAL; 2765: 2766: ret = gpumem_free_entry(entry); 2767: kgsl_mem_entry_put(entry); 2768: 2769: return ret; 2770: } MATCH LINES: 2790, 2793, 2808, 2809, 2815, 2830, 2833, 2834, 2850, 2857, 2859, 2879, 2880, 2881, 2882, 2890, 2894, 2899, 2913, 2914 2778: long ret; 2779: 2780: entry = kgsl_sharedmem_find_id(private, param->id); 2781: if (entry == NULL) 2782: return -EINVAL; 2783: 2784: ret = gpumem_free_entry(entry); 2785: kgsl_mem_entry_put(entry); 2786: 2787: return ret; 2788: } 2789: 2790: static long gpuobj_free_on_timestamp(struct kgsl_device_private *dev_priv, 2791: struct kgsl_mem_entry *entry, struct kgsl_gpuobj_free *param) 2792: { 2793: struct kgsl_gpu_event_timestamp event; 2794: struct kgsl_context *context; 2795: long ret; 2796: 2797: if (copy_struct_from_user(&event, sizeof(event), 2798: u64_to_user_ptr(param->priv), param->len)) 2799: return -EFAULT; 2800: 2801: if (event.context_id == 0) 2802: return -EINVAL; 2803: 2804: context = kgsl_context_get_owner(dev_priv, event.context_id); 2805: if (context == NULL) 2806: return -EINVAL; 2807: 2808: ret = gpumem_free_entry_on_timestamp(dev_priv->device, entry, context, 2809: event.timestamp); 2810: 2811: kgsl_context_put(context); 2812: return ret; 2813: } 2814: 2815: static bool gpuobj_free_fence_func(void *priv) 2816: { 2817: struct kgsl_mem_entry *entry = priv; 2818: 2819: trace_kgsl_mem_free(entry); 2820: kgsl_memfree_add(pid_nr(entry->priv->pid), 2821: entry->memdesc.pagetable ? 2822: entry->memdesc.pagetable->name : 0, 2823: entry->memdesc.gpuaddr, entry->memdesc.size, 2824: entry->memdesc.flags); 2825: 2826: kgsl_mem_entry_put_deferred(entry); 2827: return true; 2828: } 2829: 2830: static long gpuobj_free_on_fence(struct kgsl_device_private *dev_priv, 2831: struct kgsl_mem_entry *entry, struct kgsl_gpuobj_free *param) 2832: { 2833: struct kgsl_sync_fence_cb *handle; 2834: struct kgsl_gpu_event_fence event; 2835: 2836: if (!kgsl_mem_entry_set_pend(entry)) 2837: return -EBUSY; 2838: 2839: if (copy_struct_from_user(&event, sizeof(event), 2840: u64_to_user_ptr(param->priv), param->len)) { 2841: kgsl_mem_entry_unset_pend(entry); 2842: return -EFAULT; 2843: } 2844: 2845: if (event.fd < 0) { 2846: kgsl_mem_entry_unset_pend(entry); 2847: return -EINVAL; 2848: } 2849: 2850: handle = kgsl_sync_fence_async_wait(event.fd, gpuobj_free_fence_func, entry); 2851: 2852: if (IS_ERR(handle)) { 2853: kgsl_mem_entry_unset_pend(entry); 2854: return PTR_ERR(handle); 2855: } 2856: 2857: /* if handle is NULL the fence has already signaled */ 2858: if (handle == NULL) 2859: gpuobj_free_fence_func(entry); 2860: 2861: return 0; 2862: } 2863: 2864: long kgsl_ioctl_gpuobj_free(struct kgsl_device_private *dev_priv, 2865: unsigned int cmd, void *data) 2866: { 2867: struct kgsl_gpuobj_free *param = data; 2868: struct kgsl_process_private *private = dev_priv->process_priv; 2869: struct kgsl_mem_entry *entry; 2870: long ret; 2871: 2872: entry = kgsl_sharedmem_find_id(private, param->id); 2873: if (entry == NULL) 2874: return -EINVAL; 2875: 2876: /* If no event is specified then free immediately */ 2877: if (!(param->flags & KGSL_GPUOBJ_FREE_ON_EVENT)) 2878: ret = gpumem_free_entry(entry); 2879: else if (param->type == KGSL_GPU_EVENT_TIMESTAMP) 2880: ret = gpuobj_free_on_timestamp(dev_priv, entry, param); 2881: else if (param->type == KGSL_GPU_EVENT_FENCE) 2882: ret = gpuobj_free_on_fence(dev_priv, entry, param); 2883: else 2884: ret = -EINVAL; 2885: 2886: kgsl_mem_entry_put(entry); 2887: return ret; 2888: } 2889: 2890: long kgsl_ioctl_cmdstream_freememontimestamp_ctxtid( 2891: struct kgsl_device_private *dev_priv, 2892: unsigned int cmd, void *data) 2893: { 2894: struct kgsl_cmdstream_freememontimestamp_ctxtid *param = data; 2895: struct kgsl_context *context = NULL; 2896: struct kgsl_mem_entry *entry; 2897: long ret = -EINVAL; 2898: 2899: if (param->type != KGSL_TIMESTAMP_RETIRED) 2900: return -EINVAL; 2901: 2902: context = kgsl_context_get_owner(dev_priv, param->context_id); 2903: if (context == NULL) 2904: return -EINVAL; 2905: 2906: entry = kgsl_sharedmem_find(dev_priv->process_priv, 2907: (uint64_t) param->gpuaddr); 2908: if (entry == NULL) { 2909: kgsl_context_put(context); 2910: return -EINVAL; 2911: } 2912: 2913: ret = gpumem_free_entry_on_timestamp(dev_priv->device, entry, 2914: context, param->timestamp); 2915: 2916: kgsl_mem_entry_put(entry); 2917: kgsl_context_put(context); 2918: 2919: return ret; 2920: } 2921: 2922: static bool _vma_is_cached(struct vm_area_struct *vma) 2923: { 2924: pteval_t pgprot_val = pgprot_val(vma->vm_page_prot); 2925: 2926: /* 2927: * An uncached cpu mapping can either be marked as writecombine or noncached. If it isn't 2928: * either, then it means it is cached. 2929: */ 2930: if ((pgprot_val != pgprot_val(pgprot_writecombine((vma->vm_page_prot)))) && 2931: (pgprot_val != pgprot_val(pgprot_noncached(vma->vm_page_prot)))) 2932: return true; 2933: 2934: return false; 2935: } 2936: 2937: static bool check_vma(struct kgsl_device *device, struct kgsl_memdesc *memdesc, 2938: unsigned long hostptr) MATCH LINES: 4572, 4579, 4582, 4586, 4587, 4588 4560: entry->memdesc.flags &= ~((uint64_t) KGSL_MEMTYPE_MASK); 4561: entry->memdesc.flags |= 4562: FIELD_PREP(KGSL_MEMTYPE_MASK, param->type); 4563: } else 4564: ret = -EINVAL; 4565: } 4566: 4567: kgsl_mem_entry_put(entry); 4568: return ret; 4569: } 4570: 4571: /** 4572: * kgsl_ioctl_timestamp_event - Register a new timestamp event from userspace 4573: * @dev_priv - pointer to the private device structure 4574: * @cmd - the ioctl cmd passed from kgsl_ioctl 4575: * @data - the user data buffer from kgsl_ioctl 4576: * @returns 0 on success or error code on failure 4577: */ 4578: 4579: long kgsl_ioctl_timestamp_event(struct kgsl_device_private *dev_priv, 4580: unsigned int cmd, void *data) 4581: { 4582: struct kgsl_timestamp_event *param = data; 4583: int ret; 4584: 4585: switch (param->type) { 4586: case KGSL_TIMESTAMP_EVENT_FENCE: 4587: ret = kgsl_add_fence_event(dev_priv->device, 4588: param->context_id, param->timestamp, param->priv, 4589: param->len, dev_priv); 4590: break; 4591: default: 4592: ret = -EINVAL; 4593: } 4594: 4595: return ret; 4596: } 4597: 4598: static vm_fault_t 4599: kgsl_memstore_vm_fault(struct vm_fault *vmf) 4600: { 4601: struct kgsl_memdesc *memdesc = vmf->vma->vm_private_data; 4602: 4603: return memdesc->ops->vmfault(memdesc, vmf->vma, vmf); 4604: } 4605: 4606: static const struct vm_operations_struct kgsl_memstore_vm_ops = { 4607: .fault = kgsl_memstore_vm_fault, 4608: }; 4609: 4610: static inline void kgsl_vm_flags_clear(struct vm_area_struct *vma, vm_flags_t flags) 4611: { 4612: #if (KERNEL_VERSION(6, 1, 25) <= LINUX_VERSION_CODE) --- FILE: \kgsl.h | HITS: 24 --- MATCH LINES: 92 80: * SCRATCH MEMORY: The scratch memory is one page worth of data that 81: * is mapped into the GPU. This allows for some 'shared' data between 82: * the GPU and CPU. For example, it will be used by the GPU to write 83: * each updated RPTR for each RB. 84: */ 85: 86: /* Shadow global helpers */ 87: struct adreno_rb_shadow { 88: /** @rptr: per ringbuffer address where GPU writes the rptr */ 89: u32 rptr; 90: /** @bv_rptr: per ringbuffer address where GPU writes BV rptr */ 91: u32 bv_rptr; 92: /** @bv_ts: per ringbuffer address where BV ringbuffer timestamp is written to */ 93: u32 bv_ts; 94: /** @current_rb_ptname: The current pagetable active on the given RB */ 95: u32 current_rb_ptname; 96: /** @ttbr0: value to program into TTBR0 during pagetable switch */ 97: u64 ttbr0; 98: /** @contextidr: value to program into CONTEXTIDR during pagetable switch */ 99: u32 contextidr; 100: }; 101: 102: /** 103: * struct gpu_work_period - App specific GPU work period stats 104: */ 105: struct gpu_work_period { 106: struct kref refcount; 107: struct list_head list; 108: /** @uid: application unique identifier */ 109: uid_t uid; 110: /** @active: Total amount of time the GPU spent running work */ 111: u64 active; 112: /** @cmds: Total number of commands completed within work period */ 113: u32 cmds; 114: /** @frames: Total number of frames completed within work period */ 115: atomic_t frames; 116: /** @flags: Flags to accumulate GPU busy stats */ MATCH LINES: 134, 135 122: }; 123: 124: #define SCRATCH_RB_OFFSET(id, _field) ((id * sizeof(struct adreno_rb_shadow)) + \ 125: offsetof(struct adreno_rb_shadow, _field)) 126: #define SCRATCH_RB_GPU_ADDR(dev, id, _field) \ 127: ((dev)->scratch->gpuaddr + SCRATCH_RB_OFFSET(id, _field)) 128: 129: /* OFFSET to KMD postamble packets in scratch buffer */ 130: #define SCRATCH_POSTAMBLE_OFFSET (100 * sizeof(u64)) 131: #define SCRATCH_POSTAMBLE_ADDR(dev) \ 132: ((dev)->scratch->gpuaddr + SCRATCH_POSTAMBLE_OFFSET) 133: 134: /* Timestamp window used to detect rollovers (half of integer range) */ 135: #define KGSL_TIMESTAMP_WINDOW 0x80000000 136: 137: /* 138: * A macro for memory statistics - add the new size to the stat and if 139: * the statisic is greater then _max, set _max 140: */ 141: static inline void KGSL_STATS_ADD(uint64_t size, atomic_long_t *stat, 142: atomic_long_t *max) 143: { 144: uint64_t ret = atomic_long_add_return(size, stat); 145: 146: if (ret > atomic_long_read(max)) 147: atomic_long_set(max, ret); 148: } 149: 150: #define KGSL_MAX_NUMIBS 2000 151: #define KGSL_MAX_SYNCPOINTS 32 152: 153: struct kgsl_device; 154: struct kgsl_context; 155: 156: /** 157: * struct kgsl_driver - main container for global KGSL things 158: * @cdev: Character device struct 159: * @major: Major ID for the KGSL device MATCH LINES: 241, 244, 256, 266, 267, 275, 277, 278, 287, 314, 327, 339, 345, 348, 374, 400 229: /* For application specific GPU work period stats */ 230: #define KGSL_WORK_PERIOD 0 231: /* GPU work period time in msec to emulate application work stats */ 232: #define KGSL_WORK_PERIOD_MS 900 233: 234: struct kgsl_device_private; 235: struct kgsl_event_group; 236: 237: typedef void (*kgsl_event_func)(struct kgsl_device *, struct kgsl_event_group *, 238: void *, int); 239: 240: /** 241: * struct kgsl_event - KGSL GPU timestamp event 242: * @device: Pointer to the KGSL device that owns the event 243: * @context: Pointer to the context that owns the event 244: * @timestamp: Timestamp for the event to expire 245: * @func: Callback function for the event when it expires 246: * @priv: Private data passed to the callback function 247: * @node: List node for the kgsl_event_group list 248: * @created: Jiffies when the event was created 249: * @work: kthread_work struct for dispatching the callback 250: * @result: KGSL event result type to pass to the callback 251: * group: The event group this event belongs to 252: */ 253: struct kgsl_event { 254: struct kgsl_device *device; 255: struct kgsl_context *context; 256: unsigned int timestamp; 257: kgsl_event_func func; 258: void *priv; 259: struct list_head node; 260: unsigned int created; 261: struct kthread_work work; 262: int result; 263: struct kgsl_event_group *group; 264: }; 265: 266: typedef int (*readtimestamp_func)(struct kgsl_device *, void *, 267: enum kgsl_timestamp_type, unsigned int *); 268: 269: /** 270: * struct event_group - A list of GPU events 271: * @context: Pointer to the active context for the events 272: * @lock: Spinlock for protecting the list 273: * @events: List of active GPU events 274: * @group: Node for the master group list 275: * @processed: Last processed timestamp 276: * @name: String name for the group (for the debugfs file) 277: * @readtimestamp: Function pointer to read a timestamp 278: * @priv: Priv member to pass to the readtimestamp function 279: */ 280: struct kgsl_event_group { 281: struct kgsl_context *context; 282: spinlock_t lock; 283: struct list_head events; 284: struct list_head group; 285: unsigned int processed; 286: char name[64]; 287: readtimestamp_func readtimestamp; 288: void *priv; 289: }; 290: 291: /** 292: * struct submission_info - Container for submission statistics 293: * @inflight: Number of commands that are inflight 294: * @rb_id: id of the ringbuffer to which this submission is made 295: * @rptr: Read pointer of the ringbuffer 296: * @wptr: Write pointer of the ringbuffer 297: * @gmu_dispatch_queue: GMU dispach queue to which this submission is made 298: */ 299: struct submission_info { 300: int inflight; 301: u32 rb_id; 302: u32 rptr; 303: u32 wptr; 304: u32 gmu_dispatch_queue; 305: }; 306: 307: /** 308: * struct retire_info - Container for retire statistics 309: * @inflight: NUmber of commands that are inflight 310: * @rb_id: id of the ringbuffer to which this submission is made 311: * @rptr: Read pointer of the ringbuffer 312: * @wptr: Write pointer of the ringbuffer 313: * @gmu_dispatch_queue: GMU dispach queue to which this submission is made 314: * @timestamp: Timestamp of submission that retired 315: * @submitted_to_rb: AO ticks when GMU put this submission on ringbuffer 316: * @sop: AO ticks when GPU started procssing this submission 317: * @eop: AO ticks when GPU finished this submission 318: * @retired_on_gmu: AO ticks when GMU retired this submission 319: * @active: Number AO of ticks taken by GPU to complete the command 320: */ 321: struct retire_info { 322: int inflight; 323: int rb_id; 324: u32 rptr; 325: u32 wptr; 326: u32 gmu_dispatch_queue; 327: u32 timestamp; 328: u64 submitted_to_rb; 329: u64 sop; 330: u64 eop; 331: u64 retired_on_gmu; 332: u64 active; 333: }; 334: 335: long kgsl_ioctl_device_getproperty(struct kgsl_device_private *dev_priv, 336: unsigned int cmd, void *data); 337: long kgsl_ioctl_device_setproperty(struct kgsl_device_private *dev_priv, 338: unsigned int cmd, void *data); 339: long kgsl_ioctl_device_waittimestamp_ctxtid(struct kgsl_device_private 340: *dev_priv, unsigned int cmd, void *data); 341: long kgsl_ioctl_rb_issueibcmds(struct kgsl_device_private *dev_priv, 342: unsigned int cmd, void *data); 343: long kgsl_ioctl_submit_commands(struct kgsl_device_private *dev_priv, 344: unsigned int cmd, void *data); 345: long kgsl_ioctl_cmdstream_readtimestamp_ctxtid(struct kgsl_device_private 346: *dev_priv, unsigned int cmd, 347: void *data); 348: long kgsl_ioctl_cmdstream_freememontimestamp_ctxtid( 349: struct kgsl_device_private 350: *dev_priv, unsigned int cmd, 351: void *data); 352: long kgsl_ioctl_drawctxt_create(struct kgsl_device_private *dev_priv, 353: unsigned int cmd, void *data); 354: long kgsl_ioctl_drawctxt_destroy(struct kgsl_device_private *dev_priv, 355: unsigned int cmd, void *data); 356: long kgsl_ioctl_sharedmem_free(struct kgsl_device_private *dev_priv, 357: unsigned int cmd, void *data); 358: long kgsl_ioctl_gpumem_free_id(struct kgsl_device_private *dev_priv, 359: unsigned int cmd, void *data); 360: long kgsl_ioctl_map_user_mem(struct kgsl_device_private *dev_priv, 361: unsigned int cmd, void *data); 362: long kgsl_ioctl_gpumem_sync_cache(struct kgsl_device_private *dev_priv, 363: unsigned int cmd, void *data); 364: long kgsl_ioctl_gpumem_sync_cache_bulk(struct kgsl_device_private *dev_priv, 365: unsigned int cmd, void *data); 366: long kgsl_ioctl_sharedmem_flush_cache(struct kgsl_device_private *dev_priv, 367: unsigned int cmd, void *data); 368: long kgsl_ioctl_gpumem_alloc(struct kgsl_device_private *dev_priv, 369: unsigned int cmd, void *data); 370: long kgsl_ioctl_gpumem_alloc_id(struct kgsl_device_private *dev_priv, 371: unsigned int cmd, void *data); 372: long kgsl_ioctl_gpumem_get_info(struct kgsl_device_private *dev_priv, 373: unsigned int cmd, void *data); 374: long kgsl_ioctl_timestamp_event(struct kgsl_device_private *dev_priv, 375: unsigned int cmd, void *data); 376: long kgsl_ioctl_gpuobj_alloc(struct kgsl_device_private *dev_priv, 377: unsigned int cmd, void *data); 378: long kgsl_ioctl_gpuobj_free(struct kgsl_device_private *dev_priv, 379: unsigned int cmd, void *data); 380: long kgsl_ioctl_gpuobj_info(struct kgsl_device_private *dev_priv, 381: unsigned int cmd, void *data); 382: long kgsl_ioctl_gpuobj_import(struct kgsl_device_private *dev_priv, 383: unsigned int cmd, void *data); 384: long kgsl_ioctl_gpuobj_sync(struct kgsl_device_private *dev_priv, 385: unsigned int cmd, void *data); 386: long kgsl_ioctl_gpu_command(struct kgsl_device_private *dev_priv, 387: unsigned int cmd, void *data); 388: long kgsl_ioctl_gpuobj_set_info(struct kgsl_device_private *dev_priv, 389: unsigned int cmd, void *data); 390: long kgsl_ioctl_gpumem_bind_ranges(struct kgsl_device_private *dev_priv, 391: unsigned int cmd, void *data); 392: long kgsl_ioctl_gpu_aux_command(struct kgsl_device_private *dev_priv, 393: unsigned int cmd, void *data); 394: long kgsl_ioctl_timeline_create(struct kgsl_device_private *dev_priv, 395: unsigned int cmd, void *data); 396: long kgsl_ioctl_timeline_wait(struct kgsl_device_private *dev_priv, 397: unsigned int cmd, void *data); 398: long kgsl_ioctl_timeline_query(struct kgsl_device_private *dev_priv, 399: unsigned int cmd, void *data); 400: long kgsl_ioctl_timeline_fence_get(struct kgsl_device_private *dev_priv, 401: unsigned int cmd, void *data); 402: long kgsl_ioctl_timeline_signal(struct kgsl_device_private *dev_priv, 403: unsigned int cmd, void *data); 404: long kgsl_ioctl_timeline_destroy(struct kgsl_device_private *dev_priv, 405: unsigned int cmd, void *data); 406: long kgsl_ioctl_get_fault_report(struct kgsl_device_private *dev_priv, 407: unsigned int cmd, void *data); 408: long kgsl_ioctl_recurring_command(struct kgsl_device_private *dev_priv, 409: unsigned int cmd, void *data); 410: 411: void kgsl_mem_entry_destroy(struct kref *kref); 412: void kgsl_mem_entry_destroy_deferred(struct kref *kref); 413: 414: void kgsl_get_egl_counts(struct kgsl_mem_entry *entry, 415: int *egl_surface_count, int *egl_image_count); 416: 417: unsigned long kgsl_get_dmabuf_inode_number(struct kgsl_mem_entry *entry); 418: 419: struct kgsl_mem_entry * __must_check 420: kgsl_sharedmem_find(struct kgsl_process_private *private, uint64_t gpuaddr); 421: 422: struct kgsl_mem_entry * __must_check 423: kgsl_sharedmem_find_id(struct kgsl_process_private *process, unsigned int id); 424: MATCH LINES: 443, 450, 458, 459, 460 431: /* Helper functions */ 432: unsigned long kgsl_get_align(struct kgsl_memdesc *memdesc); 433: 434: int kgsl_request_irq(struct platform_device *pdev, const char *name, 435: const char *alt_name, int index, irq_handler_t handler, void *data); 436: 437: int kgsl_request_irq_optional(struct platform_device *pdev, const char *name, 438: irq_handler_t handler, void *data); 439: 440: int __init kgsl_core_init(void); 441: void kgsl_core_exit(void); 442: 443: static inline int timestamp_cmp(unsigned int a, unsigned int b) 444: { 445: /* check for equal */ 446: if (a == b) 447: return 0; 448: 449: /* check for greater-than for non-rollover case */ 450: if ((a > b) && (a - b < KGSL_TIMESTAMP_WINDOW)) 451: return 1; 452: 453: /* check for greater-than for rollover case 454: * note that <= is required to ensure that consistent 455: * results are returned for values whose difference is 456: * equal to the window size 457: */ 458: a += KGSL_TIMESTAMP_WINDOW; 459: b += KGSL_TIMESTAMP_WINDOW; 460: return ((a > b) && (a - b <= KGSL_TIMESTAMP_WINDOW)) ? 1 : -1; 461: } 462: 463: /** 464: * kgsl_schedule_work() - Schedule a work item on the KGSL workqueue 465: * @work: work item to schedule 466: */ 467: static inline void kgsl_schedule_work(struct work_struct *work) 468: { 469: queue_work(kgsl_driver.workqueue, work); 470: } 471: 472: static inline struct kgsl_mem_entry * 473: kgsl_mem_entry_get(struct kgsl_mem_entry *entry) 474: { 475: if (!IS_ERR_OR_NULL(entry) && kref_get_unless_zero(&entry->refcount)) 476: return entry; 477: 478: return NULL; 479: } 480: 481: static inline void 482: kgsl_mem_entry_put(struct kgsl_mem_entry *entry) 483: { 484: if (!IS_ERR_OR_NULL(entry)) --- FILE: \kgsl_compat.c | HITS: 31 --- MATCH LINES: 53, 57, 74, 78, 83, 88, 89, 94, 96 41: unsigned int cmd, void *data) 42: { 43: int result; 44: struct kgsl_submit_commands_compat *param32 = data; 45: struct kgsl_submit_commands param; 46: 47: param.context_id = param32->context_id; 48: param.flags = param32->flags; 49: param.cmdlist = compat_ptr(param32->cmdlist); 50: param.numcmds = param32->numcmds; 51: param.synclist = compat_ptr(param32->synclist); 52: param.numsyncs = param32->numsyncs; 53: param.timestamp = param32->timestamp; 54: 55: result = kgsl_ioctl_submit_commands(dev_priv, cmd, ¶m); 56: 57: param32->timestamp = param.timestamp; 58: 59: return result; 60: } 61: 62: static long 63: kgsl_ioctl_rb_issueibcmds_compat(struct kgsl_device_private *dev_priv, 64: unsigned int cmd, void *data) 65: { 66: int result; 67: struct kgsl_ringbuffer_issueibcmds_compat *param32 = data; 68: struct kgsl_ringbuffer_issueibcmds param; 69: 70: param.drawctxt_id = param32->drawctxt_id; 71: param.flags = param32->flags; 72: param.ibdesc_addr = (unsigned long)param32->ibdesc_addr; 73: param.numibs = param32->numibs; 74: param.timestamp = param32->timestamp; 75: 76: result = kgsl_ioctl_rb_issueibcmds(dev_priv, cmd, ¶m); 77: 78: param32->timestamp = param.timestamp; 79: 80: return result; 81: } 82: 83: static long kgsl_ioctl_cmdstream_freememontimestamp_ctxtid_compat( 84: struct kgsl_device_private 85: *dev_priv, unsigned int cmd, 86: void *data) 87: { 88: struct kgsl_cmdstream_freememontimestamp_ctxtid_compat *param32 = data; 89: struct kgsl_cmdstream_freememontimestamp_ctxtid param; 90: 91: param.context_id = param32->context_id; 92: param.gpuaddr = (unsigned long)param32->gpuaddr; 93: param.type = param32->type; 94: param.timestamp = param32->timestamp; 95: 96: return kgsl_ioctl_cmdstream_freememontimestamp_ctxtid(dev_priv, cmd, 97: ¶m); 98: } 99: 100: static long kgsl_ioctl_sharedmem_free_compat(struct kgsl_device_private 101: *dev_priv, unsigned int cmd, 102: void *data) 103: { 104: struct kgsl_sharedmem_free_compat *param32 = data; 105: struct kgsl_sharedmem_free param; 106: 107: param.gpuaddr = (unsigned long)param32->gpuaddr; 108: 109: return kgsl_ioctl_sharedmem_free(dev_priv, cmd, ¶m); 110: } 111: 112: static long kgsl_ioctl_map_user_mem_compat(struct kgsl_device_private 113: *dev_priv, unsigned int cmd, 114: void *data) 115: { 116: int result = 0; 117: struct kgsl_map_user_mem_compat *param32 = data; 118: struct kgsl_map_user_mem param; 119: 120: param.fd = param32->fd; MATCH LINES: 264, 267, 268, 271, 276, 283, 284, 285, 290, 291, 292, 293, 294, 295, 308, 309, 326, 327, 328, 329, 364, 365 252: result = kgsl_ioctl_gpumem_get_info(dev_priv, cmd, ¶m); 253: 254: param32->gpuaddr = gpuaddr_to_compat(param.gpuaddr); 255: param32->id = param.id; 256: param32->flags = param.flags; 257: param32->size = sizet_to_compat(param.size); 258: param32->mmapsize = sizet_to_compat(param.mmapsize); 259: param32->useraddr = (compat_ulong_t)param.useraddr; 260: 261: return result; 262: } 263: 264: static long kgsl_ioctl_timestamp_event_compat(struct kgsl_device_private 265: *dev_priv, unsigned int cmd, void *data) 266: { 267: struct kgsl_timestamp_event_compat *param32 = data; 268: struct kgsl_timestamp_event param; 269: 270: param.type = param32->type; 271: param.timestamp = param32->timestamp; 272: param.context_id = param32->context_id; 273: param.priv = compat_ptr(param32->priv); 274: param.len = (size_t)param32->len; 275: 276: return kgsl_ioctl_timestamp_event(dev_priv, cmd, ¶m); 277: } 278: 279: 280: static const struct kgsl_ioctl kgsl_compat_ioctl_funcs[] = { 281: KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_GETPROPERTY_COMPAT, 282: kgsl_ioctl_device_getproperty_compat), 283: /* IOCTL_KGSL_DEVICE_WAITTIMESTAMP is no longer supported */ 284: KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID, 285: kgsl_ioctl_device_waittimestamp_ctxtid), 286: KGSL_IOCTL_FUNC(IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS_COMPAT, 287: kgsl_ioctl_rb_issueibcmds_compat), 288: KGSL_IOCTL_FUNC(IOCTL_KGSL_SUBMIT_COMMANDS_COMPAT, 289: kgsl_ioctl_submit_commands_compat), 290: /* IOCTL_KGSL_CMDSTREAM_READTIMESTAMP is no longer supported */ 291: KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID, 292: kgsl_ioctl_cmdstream_readtimestamp_ctxtid), 293: /* IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP is no longer supported */ 294: KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID_COMPAT, 295: kgsl_ioctl_cmdstream_freememontimestamp_ctxtid_compat), 296: KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_CREATE, 297: kgsl_ioctl_drawctxt_create), 298: KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_DESTROY, 299: kgsl_ioctl_drawctxt_destroy), 300: KGSL_IOCTL_FUNC(IOCTL_KGSL_MAP_USER_MEM_COMPAT, 301: kgsl_ioctl_map_user_mem_compat), 302: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FREE_COMPAT, 303: kgsl_ioctl_sharedmem_free_compat), 304: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE_COMPAT, 305: kgsl_ioctl_sharedmem_flush_cache_compat), 306: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_ALLOC_COMPAT, 307: kgsl_ioctl_gpumem_alloc_compat), 308: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMESTAMP_EVENT_COMPAT, 309: kgsl_ioctl_timestamp_event_compat), 310: KGSL_IOCTL_FUNC(IOCTL_KGSL_SETPROPERTY_COMPAT, 311: kgsl_ioctl_device_setproperty_compat), 312: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_ALLOC_ID_COMPAT, 313: kgsl_ioctl_gpumem_alloc_id_compat), 314: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_FREE_ID, 315: kgsl_ioctl_gpumem_free_id), 316: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_GET_INFO_COMPAT, 317: kgsl_ioctl_gpumem_get_info_compat), 318: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_SYNC_CACHE_COMPAT, 319: kgsl_ioctl_gpumem_sync_cache_compat), 320: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_SYNC_CACHE_BULK_COMPAT, 321: kgsl_ioctl_gpumem_sync_cache_bulk_compat), 322: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_CREATE, 323: kgsl_ioctl_syncsource_create), 324: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_DESTROY, 325: kgsl_ioctl_syncsource_destroy), 326: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_CREATE_FENCE, 327: kgsl_ioctl_syncsource_create_fence), 328: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_SIGNAL_FENCE, 329: kgsl_ioctl_syncsource_signal_fence), 330: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUOBJ_ALLOC, 331: kgsl_ioctl_gpuobj_alloc), 332: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUOBJ_FREE, 333: kgsl_ioctl_gpuobj_free), 334: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUOBJ_INFO, 335: kgsl_ioctl_gpuobj_info), 336: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUOBJ_IMPORT, 337: kgsl_ioctl_gpuobj_import), 338: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUOBJ_SYNC, 339: kgsl_ioctl_gpuobj_sync), 340: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPU_COMMAND, 341: kgsl_ioctl_gpu_command), 342: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUOBJ_SET_INFO, 343: NULL), 344: KGSL_IOCTL_FUNC(IOCTL_KGSL_SPARSE_PHYS_ALLOC, 345: NULL), 346: KGSL_IOCTL_FUNC(IOCTL_KGSL_SPARSE_PHYS_FREE, 347: NULL), 348: KGSL_IOCTL_FUNC(IOCTL_KGSL_SPARSE_VIRT_ALLOC, 349: NULL), 350: KGSL_IOCTL_FUNC(IOCTL_KGSL_SPARSE_VIRT_FREE, 351: NULL), 352: KGSL_IOCTL_FUNC(IOCTL_KGSL_SPARSE_BIND, 353: NULL), 354: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPU_SPARSE_COMMAND, 355: NULL), 356: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_BIND_RANGES, 357: kgsl_ioctl_gpumem_bind_ranges), 358: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPU_AUX_COMMAND, 359: kgsl_ioctl_gpu_aux_command), 360: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMELINE_CREATE, 361: kgsl_ioctl_timeline_create), 362: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMELINE_WAIT, 363: kgsl_ioctl_timeline_wait), 364: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMELINE_FENCE_GET, 365: kgsl_ioctl_timeline_fence_get), 366: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMELINE_QUERY, 367: kgsl_ioctl_timeline_query), 368: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMELINE_SIGNAL, 369: kgsl_ioctl_timeline_signal), 370: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMELINE_DESTROY, 371: kgsl_ioctl_timeline_destroy), 372: KGSL_IOCTL_FUNC(IOCTL_KGSL_GET_FAULT_REPORT, 373: kgsl_ioctl_get_fault_report), 374: KGSL_IOCTL_FUNC(IOCTL_KGSL_RECURRING_COMMAND, 375: kgsl_ioctl_recurring_command), 376: }; 377: 378: long kgsl_compat_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) 379: { 380: struct kgsl_device_private *dev_priv = filep->private_data; 381: struct kgsl_device *device = dev_priv->device; 382: 383: long ret = kgsl_ioctl_helper(filep, cmd, arg, kgsl_compat_ioctl_funcs, 384: ARRAY_SIZE(kgsl_compat_ioctl_funcs)); 385: 386: /* 387: * If the command was unrecognized in the generic core, try the device 388: * specific function 389: */ --- FILE: \kgsl_compat.h | HITS: 11 --- MATCH LINES: 69, 81, 88, 92, 95, 97, 131, 133, 134, 139, 140 57: 58: #define IOCTL_KGSL_SETPROPERTY_COMPAT \ 59: _IOW(KGSL_IOC_TYPE, 0x32, struct kgsl_device_getproperty_compat) 60: 61: 62: struct kgsl_submit_commands_compat { 63: unsigned int context_id; 64: unsigned int flags; 65: compat_uptr_t cmdlist; 66: unsigned int numcmds; 67: compat_uptr_t synclist; 68: unsigned int numsyncs; 69: unsigned int timestamp; 70: /* private: reserved for future use */ 71: unsigned int __pad[4]; 72: }; 73: 74: #define IOCTL_KGSL_SUBMIT_COMMANDS_COMPAT \ 75: _IOWR(KGSL_IOC_TYPE, 0x3D, struct kgsl_submit_commands_compat) 76: 77: struct kgsl_ringbuffer_issueibcmds_compat { 78: unsigned int drawctxt_id; 79: compat_ulong_t ibdesc_addr; 80: unsigned int numibs; 81: unsigned int timestamp; /* output param */ 82: unsigned int flags; 83: }; 84: 85: #define IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS_COMPAT \ 86: _IOWR(KGSL_IOC_TYPE, 0x10, struct kgsl_ringbuffer_issueibcmds_compat) 87: 88: struct kgsl_cmdstream_freememontimestamp_ctxtid_compat { 89: unsigned int context_id; 90: compat_ulong_t gpuaddr; 91: unsigned int type; 92: unsigned int timestamp; 93: }; 94: 95: #define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID_COMPAT \ 96: _IOW(KGSL_IOC_TYPE, 0x17, \ 97: struct kgsl_cmdstream_freememontimestamp_ctxtid_compat) 98: 99: struct kgsl_map_user_mem_compat { 100: int fd; 101: compat_ulong_t gpuaddr; 102: compat_size_t len; 103: compat_size_t offset; 104: compat_ulong_t hostptr; 105: enum kgsl_user_mem_type memtype; 106: unsigned int flags; 107: }; 108: 109: #define IOCTL_KGSL_MAP_USER_MEM_COMPAT \ 110: _IOWR(KGSL_IOC_TYPE, 0x15, struct kgsl_map_user_mem_compat) 111: 112: struct kgsl_sharedmem_free_compat { 113: compat_ulong_t gpuaddr; 114: }; 115: 116: #define IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE_COMPAT \ 117: _IOW(KGSL_IOC_TYPE, 0x24, struct kgsl_sharedmem_free_compat) 118: 119: #define IOCTL_KGSL_SHAREDMEM_FREE_COMPAT \ 120: _IOW(KGSL_IOC_TYPE, 0x21, struct kgsl_sharedmem_free_compat) 121: 122: struct kgsl_gpumem_alloc_compat { 123: compat_ulong_t gpuaddr; /* output param */ 124: compat_size_t size; 125: unsigned int flags; 126: }; 127: 128: #define IOCTL_KGSL_GPUMEM_ALLOC_COMPAT \ 129: _IOWR(KGSL_IOC_TYPE, 0x2f, struct kgsl_gpumem_alloc_compat) 130: 131: struct kgsl_timestamp_event_compat { 132: int type; /* Type of event (see list below) */ 133: unsigned int timestamp; /* Timestamp to trigger event on */ 134: unsigned int context_id; /* Context for the timestamp */ 135: compat_uptr_t priv; /* Pointer to the event specific blob */ 136: compat_size_t len; /* Size of the event specific blob */ 137: }; 138: 139: #define IOCTL_KGSL_TIMESTAMP_EVENT_COMPAT \ 140: _IOWR(KGSL_IOC_TYPE, 0x33, struct kgsl_timestamp_event_compat) 141: 142: struct kgsl_gpumem_alloc_id_compat { 143: unsigned int id; 144: unsigned int flags; 145: compat_size_t size; 146: compat_size_t mmapsize; 147: compat_ulong_t gpuaddr; 148: /* private: reserved for future use*/ 149: unsigned int __pad[2]; 150: }; 151: 152: #define IOCTL_KGSL_GPUMEM_ALLOC_ID_COMPAT \ 153: _IOWR(KGSL_IOC_TYPE, 0x34, struct kgsl_gpumem_alloc_id_compat) 154: 155: struct kgsl_gpumem_get_info_compat { 156: compat_ulong_t gpuaddr; 157: unsigned int id; 158: unsigned int flags; 159: compat_size_t size; 160: compat_size_t mmapsize; 161: compat_ulong_t useraddr; 162: /* private: reserved for future use*/ 163: unsigned int __pad[4]; 164: }; --- FILE: \kgsl_device.h | HITS: 33 --- MATCH LINES: 69 57: #define KGSL_STATE_NONE 0x00000000 58: #define KGSL_STATE_INIT 0x00000001 59: #define KGSL_STATE_ACTIVE 0x00000002 60: #define KGSL_STATE_NAP 0x00000004 /* Not Used */ 61: #define KGSL_STATE_SUSPEND 0x00000010 62: #define KGSL_STATE_AWARE 0x00000020 63: #define KGSL_STATE_SLUMBER 0x00000080 64: #define KGSL_STATE_MINBW 0x00000100 /* Not Used */ 65: 66: /** 67: * enum kgsl_event_results - result codes passed to an event callback when the 68: * event is retired or cancelled 69: * @KGSL_EVENT_RETIRED: The timestamp associated with the event retired 70: * successflly 71: * @KGSL_EVENT_CANCELLED: The event was cancelled before the event was fired 72: */ 73: enum kgsl_event_results { 74: KGSL_EVENT_RETIRED = 1, 75: KGSL_EVENT_CANCELLED = 2, 76: }; 77: 78: /* 79: * "list" of event types for ftrace symbolic magic 80: */ 81: 82: #define KGSL_CONTEXT_FLAGS \ 83: { KGSL_CONTEXT_NO_GMEM_ALLOC, "NO_GMEM_ALLOC" }, \ 84: { KGSL_CONTEXT_PREAMBLE, "PREAMBLE" }, \ 85: { KGSL_CONTEXT_TRASH_STATE, "TRASH_STATE" }, \ 86: { KGSL_CONTEXT_CTX_SWITCH, "CTX_SWITCH" }, \ 87: { KGSL_CONTEXT_PER_CONTEXT_TS, "PER_CONTEXT_TS" }, \ 88: { KGSL_CONTEXT_USER_GENERATED_TS, "USER_TS" }, \ 89: { KGSL_CONTEXT_NO_FAULT_TOLERANCE, "NO_FT" }, \ 90: { KGSL_CONTEXT_INVALIDATE_ON_FAULT, "INVALIDATE_ON_FAULT" }, \ 91: { KGSL_CONTEXT_PWR_CONSTRAINT, "PWR" }, \ 92: { KGSL_CONTEXT_SAVE_GMEM, "SAVE_GMEM" }, \ 93: { KGSL_CONTEXT_IFH_NOP, "IFH_NOP" }, \ MATCH LINES: 118, 134, 135, 137, 138, 141 106: GPU_PWRLEVEL_OP_PERF_HINT, /* Mutex grabbed in the ops function */ 107: GPU_PWRLEVEL_OP_DCVS_ENABLE, 108: GPU_PWRLEVEL_OP_TUNING_ATTR, 109: }; 110: 111: struct kgsl_device; 112: struct platform_device; 113: struct kgsl_device_private; 114: struct kgsl_context; 115: struct kgsl_power_stats; 116: struct kgsl_event; 117: struct kgsl_snapshot; 118: struct kgsl_sync_fence; 119: 120: struct kgsl_functable { 121: /* Mandatory functions - these functions must be implemented 122: * by the client device. The driver will not check for a NULL 123: * pointer before calling the hook. 124: */ 125: void (*check_idle)(struct kgsl_device *device); 126: int (*first_open)(struct kgsl_device *device); 127: int (*last_close)(struct kgsl_device *device); 128: int (*start)(struct kgsl_device *device, int priority); 129: int (*stop)(struct kgsl_device *device); 130: int (*getproperty)(struct kgsl_device *device, 131: struct kgsl_device_getproperty *param); 132: int (*getproperty_compat)(struct kgsl_device *device, 133: struct kgsl_device_getproperty *param); 134: int (*waittimestamp)(struct kgsl_device *device, 135: struct kgsl_context *context, unsigned int timestamp, 136: unsigned int msecs); 137: int (*readtimestamp)(struct kgsl_device *device, void *priv, 138: enum kgsl_timestamp_type type, unsigned int *timestamp); 139: int (*queue_cmds)(struct kgsl_device_private *dev_priv, 140: struct kgsl_context *context, struct kgsl_drawobj *drawobj[], 141: uint32_t count, uint32_t *timestamp); 142: void (*power_stats)(struct kgsl_device *device, 143: struct kgsl_power_stats *stats); 144: void (*snapshot)(struct kgsl_device *device, 145: struct kgsl_snapshot *snapshot, struct kgsl_context *context, 146: struct kgsl_context *context_lpac); 147: /** @drain_and_idle: Drain the GPU and wait for it to idle */ 148: int (*drain_and_idle)(struct kgsl_device *device); 149: struct kgsl_device_private * (*device_private_create)(void); 150: void (*device_private_destroy)(struct kgsl_device_private *dev_priv); 151: /* 152: * Optional functions - these functions are not mandatory. The 153: * driver will check that the function pointer is not NULL before 154: * calling the hook 155: */ 156: struct kgsl_context *(*drawctxt_create) 157: (struct kgsl_device_private *dev_priv, 158: uint32_t *flags); 159: void (*drawctxt_detach)(struct kgsl_context *context); 160: void (*drawctxt_destroy)(struct kgsl_context *context); 161: void (*drawctxt_dump)(struct kgsl_device *device, 162: struct kgsl_context *context); 163: long (*ioctl)(struct kgsl_device_private *dev_priv, 164: unsigned int cmd, unsigned long arg); 165: long (*compat_ioctl)(struct kgsl_device_private *dev_priv, MATCH LINES: 203, 204 191: int (*gpu_clock_set)(struct kgsl_device *device, u32 pwrlevel); 192: /** @gpu_bus_set: Target specific function to set gpu bandwidth */ 193: int (*gpu_bus_set)(struct kgsl_device *device, int bus_level, u32 ab); 194: void (*deassert_gbif_halt)(struct kgsl_device *device); 195: /** @queue_recurring_cmd: Queue recurring commands to GMU */ 196: int (*queue_recurring_cmd)(struct kgsl_device_private *dev_priv, 197: struct kgsl_context *context, struct kgsl_drawobj *drawobj); 198: /** @dequeue_recurring_cmd: Dequeue recurring commands from GMU */ 199: int (*dequeue_recurring_cmd)(struct kgsl_device *device, 200: struct kgsl_context *context); 201: /** set_isdb_breakpoint_registers: Program isdb registers to issue break command */ 202: void (*set_isdb_breakpoint_registers)(struct kgsl_device *device); 203: /** @create_hw_fence: Create a hardware fence */ 204: void (*create_hw_fence)(struct kgsl_device *device, struct kgsl_sync_fence *kfence); 205: /** @gmu_based_dcvs_pwr_ops: Function ops for GMU based DCVS power operations */ 206: int (*gmu_based_dcvs_pwr_ops)(struct kgsl_device *device, u32 arg, 207: enum gpu_pwrlevel_op op); 208: /** @set_thermal_index: Target specific function to send thermal constraint to GMU */ 209: void (*set_thermal_index)(struct kgsl_device *device); 210: /** @alloc_dcvs_profile_memory: Function ops for GMU based DCVS profile operations */ 211: void (*alloc_dcvs_profile_memory)(struct kgsl_device *device, 212: struct kgsl_process_private *proc_priv); 213: /** @is_first_boot_done: Check if the ADRENO device first boot is done */ 214: bool (*is_first_boot_done)(struct kgsl_device *device); 215: /** @set_smmu_aperture: Target specific function to program the SMMU aperture registers */ 216: int (*set_smmu_aperture)(struct kgsl_device *device); 217: }; 218: 219: struct kgsl_ioctl { 220: unsigned int cmd; 221: long (*func)(struct kgsl_device_private *dev_priv, 222: unsigned int cmd, void *data); 223: }; 224: 225: long kgsl_ioctl_helper(struct file *filep, unsigned int cmd, unsigned long arg, 226: const struct kgsl_ioctl *cmds, int len); 227: 228: /* Flag to mark that the memobj_node should not go to the hadrware */ MATCH LINES: 391, 392, 424, 427, 447, 448, 456, 493, 494, 504 379: /** @debug_bus_bin: Debug bus bin for the GPU device if applicable */ 380: u32 debug_bus_bin; 381: /** @soc_code: Identifier containing product and feature code */ 382: u32 soc_code; 383: /** @gmu_fault: Set when a gmu or rgmu fault is encountered */ 384: bool gmu_fault; 385: /** @regmap: GPU register map */ 386: struct kgsl_regmap regmap; 387: /** @timelines: Iterator for assigning IDs to timelines */ 388: struct idr timelines; 389: /** @timelines_lock: Spinlock to protect the timelines idr */ 390: spinlock_t timelines_lock; 391: /** @fence_trace_array: A local trace array for fence debugging */ 392: struct trace_array *fence_trace_array; 393: /** @l3_vote: Enable/Disable l3 voting */ 394: bool l3_vote; 395: /** @pdev_loaded: Flag to test if platform driver is probed */ 396: bool pdev_loaded; 397: /** @nh: Pointer to head of the SRCU notifier chain */ 398: struct srcu_notifier_head nh; 399: /** @bcl_data_kobj: Kobj for bcl_data sysfs node */ 400: struct kobject bcl_data_kobj; 401: /** @work_period_timer: Timer to capture application GPU work stats */ 402: struct timer_list work_period_timer; 403: /** @work_period_lock: Lock to protect application GPU work periods */ 404: spinlock_t work_period_lock; 405: /** @work_period_ws: Work struct to emulate application GPU work events */ 406: struct work_struct work_period_ws; 407: /** @flags: Flags for gpu_period stats */ 408: unsigned long flags; 409: struct { 410: u64 begin; 411: u64 end; 412: } gpu_period; 413: /** @idle_jiffies: Latest idle jiffies */ 414: unsigned long idle_jiffies; 415: /** @dump_all_ibs: Whether to dump all ibs in snapshot */ 416: bool dump_all_ibs; 417: /** @freq_limiter_irq_clear: reset controller to clear freq limiter irq */ 418: struct reset_control *freq_limiter_irq_clear; 419: /** @freq_limiter_intr_num: The interrupt number for freq limiter */ 420: int freq_limiter_intr_num; 421: /** @cx_host_irq_num: Interrupt number for cx_host_irq */ 422: int cx_host_irq_num; 423: /** 424: * @max_syncobj_hw_fence_count: Maximum number of hardware fences that are allowed in a sync 425: * object 426: */ 427: u32 max_syncobj_hw_fence_count; 428: /** @file_mutex: Mutex to protect device open and close operations */ 429: struct mutex file_mutex; 430: /** @host_based_dcvs: Set when KGSL is in charge of DCVS */ 431: bool host_based_dcvs; 432: }; 433: 434: #define KGSL_MMU_DEVICE(_mmu) \ 435: container_of((_mmu), struct kgsl_device, mmu) 436: 437: /** 438: * enum bits for struct kgsl_context.priv 439: * @KGSL_CONTEXT_PRIV_SUBMITTED - The context has submitted commands to gpu. 440: * @KGSL_CONTEXT_PRIV_DETACHED - The context has been destroyed by userspace 441: * and is no longer using the gpu. 442: * @KGSL_CONTEXT_PRIV_INVALID - The context has been destroyed by the kernel 443: * because it caused a GPU fault. 444: * @KGSL_CONTEXT_PRIV_PAGEFAULT - The context has caused a page fault. 445: * @KGSL_CONTEXT_PRIV_DEVICE_SPECIFIC - this value and higher values are 446: * reserved for devices specific use. 447: * @KGSL_CONTEXT_PRIV_INVALID_DRAIN_HW_FENCE - this context got invalidated 448: * and needs its hardware fences drained after device reset 449: */ 450: enum kgsl_context_priv { 451: KGSL_CONTEXT_PRIV_SUBMITTED = 0, 452: KGSL_CONTEXT_PRIV_DETACHED, 453: KGSL_CONTEXT_PRIV_INVALID, 454: KGSL_CONTEXT_PRIV_PAGEFAULT, 455: KGSL_CONTEXT_PRIV_DEVICE_SPECIFIC = 16, 456: KGSL_CONTEXT_PRIV_INVALID_DRAIN_HW_FENCE, 457: }; 458: 459: struct kgsl_process_private; 460: 461: #define KGSL_MAX_FAULT_ENTRIES 40 462: 463: /* Maintain faults observed within threshold time (in milliseconds) */ 464: #define KGSL_MAX_FAULT_TIME_THRESHOLD 5000 465: 466: /** 467: * struct kgsl_fault_node - GPU fault descriptor 468: * @node: List node for list of faults 469: * @type: Type of fault 470: * @priv: Pointer to type specific fault 471: * @time: Time when fault was observed 472: */ 473: struct kgsl_fault_node { 474: struct list_head node; 475: u32 type; 476: void *priv; 477: ktime_t time; 478: }; 479: 480: /** 481: * struct kgsl_context - The context fields that are valid for a user defined 482: * context 483: * @refcount: kref object for reference counting the context 484: * @id: integer identifier for the context 485: * @priority; The context's priority to submit commands to GPU 486: * @tid: task that created this context. 487: * @dev_priv: pointer to the owning device instance 488: * @proc_priv: pointer to process private, the process that allocated the 489: * context 490: * @priv: in-kernel context flags, use KGSL_CONTEXT_* values 491: * @reset_status: status indication whether a gpu reset occurred and whether 492: * this context was responsible for causing it 493: * @timeline: sync timeline used to create fences that can be signaled when a 494: * sync_pt timestamp expires 495: * @events: A kgsl_event_group for this context - contains the list of GPU 496: * events 497: * @flags: flags from userspace controlling the behavior of this context 498: * @pwr_constraint: power constraint from userspace for this context 499: * @fault_count: number of times gpu hanged in last _context_throttle_time ms 500: * @fault_time: time of the first gpu hang in last _context_throttle_time ms 501: * @user_ctxt_record: memory descriptor used by CP to save/restore VPC data 502: * across preemption 503: * @total_fault_count: number of times gpu faulted in this context 504: * @last_faulted_cmd_ts: last faulted command batch timestamp 505: * @gmu_registered: whether context is registered with gmu or not 506: */ 507: struct kgsl_context { 508: struct kref refcount; 509: uint32_t id; 510: uint32_t priority; 511: pid_t tid; 512: struct kgsl_device_private *dev_priv; 513: struct kgsl_process_private *proc_priv; 514: unsigned long priv; 515: struct kgsl_device *device; 516: unsigned int reset_status; 517: struct kgsl_sync_timeline *ktimeline; 518: struct kgsl_event_group events; 519: unsigned int flags; 520: struct kgsl_pwr_constraint pwr_constraint; 521: struct kgsl_pwr_constraint l3_pwr_constraint; 522: unsigned int fault_count; 523: ktime_t fault_time; 524: struct kgsl_mem_entry *user_ctxt_record; 525: unsigned int total_fault_count; 526: unsigned int last_faulted_cmd_ts; 527: bool gmu_registered; 528: /** MATCH LINES: 678, 709 666: * @ib1base: Active IB1 base address at the time of fault 667: * @ib2base: Active IB2 base address at the time of fault 668: * @ib3base: Active IB3 base address at the time of fault 669: * @ib1size: Number of DWORDS pending in IB1 at the time of fault 670: * @ib2size: Number of DWORDS pending in IB2 at the time of fault 671: * @ib3size: Number of DWORDS pending in IB3 at the time of fault 672: * @ib1dumped: Active IB1 dump status to sansphot binary 673: * @ib2dumped: Active IB2 dump status to sansphot binary 674: * @start: Pointer to the start of the static snapshot region 675: * @size: Size of the current snapshot instance 676: * @ptr: Pointer to the next block of memory to write to during snapshotting 677: * @remain: Bytes left in the snapshot region 678: * @timestamp: Timestamp of the snapshot instance (in seconds since boot) 679: * @mempool: Pointer to the memory pool for storing memory objects 680: * @mempool_size: Size of the memory pool 681: * @obj_list: List of frozen GPU buffers that are waiting to be dumped. 682: * @cp_list: List of IB's to be dumped. 683: * @work: worker to dump the frozen memory 684: * @dump_gate: completion gate signaled by worker when it is finished. 685: * @process: the process that caused the hang, if known. 686: * @sysfs_read: Count of current reads via sysfs 687: * @first_read: True until the snapshot read is started 688: * @recovered: True if GPU was recovered after previous snapshot 689: */ 690: struct kgsl_snapshot { 691: u64 ib1base; 692: u64 ib2base; 693: u64 ib3base; 694: u32 ib1size; 695: u32 ib2size; 696: u32 ib3size; 697: bool ib1dumped; 698: bool ib2dumped; 699: u64 ib1base_lpac; 700: u64 ib2base_lpac; 701: u32 ib1size_lpac; 702: u32 ib2size_lpac; 703: bool ib1dumped_lpac; 704: bool ib2dumped_lpac; 705: u8 *start; 706: size_t size; 707: u8 *ptr; 708: size_t remain; 709: unsigned long timestamp; 710: u8 *mempool; 711: size_t mempool_size; 712: struct list_head obj_list; 713: struct list_head cp_list; 714: struct work_struct work; 715: struct completion dump_gate; 716: struct kgsl_process_private *process; 717: struct kgsl_process_private *process_lpac; 718: unsigned int sysfs_read; 719: bool first_read; 720: bool recovered; 721: struct kgsl_device *device; 722: }; 723: 724: /** 725: * struct kgsl_snapshot_object - GPU memory in the snapshot 726: * @gpuaddr: The GPU address identified during snapshot 727: * @size: The buffer size identified during snapshot 728: * @offset: offset from start of the allocated kgsl_mem_entry 729: * @type: SNAPSHOT_OBJ_TYPE_* identifier. 730: * @entry: the reference counted memory entry for this buffer 731: * @node: node for kgsl_snapshot.obj_list 732: */ 733: struct kgsl_snapshot_object { MATCH LINES: 796, 797, 799, 800 784: * kgsl_start_idle_timer - Start the idle timer 785: * @device: A KGSL device handle 786: * 787: * Start the idle timer to expire in 'interval_timeout' milliseconds 788: */ 789: static inline void kgsl_start_idle_timer(struct kgsl_device *device) 790: { 791: device->idle_jiffies = jiffies + 792: msecs_to_jiffies(atomic64_read(&device->pwrctrl.interval_timeout)); 793: mod_timer(&device->idle_timer, device->idle_jiffies); 794: } 795: 796: int kgsl_readtimestamp(struct kgsl_device *device, void *priv, 797: enum kgsl_timestamp_type type, unsigned int *timestamp); 798: 799: bool kgsl_check_timestamp(struct kgsl_device *device, 800: struct kgsl_context *context, unsigned int timestamp); 801: 802: int kgsl_device_platform_probe(struct kgsl_device *device); 803: 804: void kgsl_device_platform_remove(struct kgsl_device *device); 805: 806: const char *kgsl_pwrstate_to_str(unsigned int state); 807: 808: /** 809: * kgsl_device_snapshot_probe - add resources for the device GPU snapshot 810: * @device: The device to initialize 811: * @size: The size of the static region to allocate 812: * 813: * Allocate memory for a GPU snapshot for the specified device, 814: * and create the sysfs files to manage it 815: */ 816: void kgsl_device_snapshot_probe(struct kgsl_device *device, u32 size); 817: 818: void kgsl_device_snapshot(struct kgsl_device *device, 819: struct kgsl_context *context, struct kgsl_context *context_lpac, 820: bool gmu_fault); 821: void kgsl_device_snapshot_close(struct kgsl_device *device); 822: 823: void kgsl_events_init(void); 824: void kgsl_events_exit(void); MATCH LINES: 860, 862, 868, 871, 872, 876, 879, 882 848: * @group: Event group to be removed 849: * 850: * Remove the specified group from the list of event groups on @device. 851: */ 852: void kgsl_del_event_group(struct kgsl_device *device, 853: struct kgsl_event_group *group); 854: 855: /** 856: * kgsl_add_event_group - Add a new GPU event group 857: * @device: A KGSL GPU device handle 858: * @group: Pointer to the new group to add to the list 859: * @context: Context that owns the group (or NULL for global) 860: * @readtimestamp: Function pointer to the readtimestamp function to call when 861: * processing events 862: * @priv: Priv member to pass to the readtimestamp function 863: * @fmt: The format string to use to build the event name 864: * @...: Arguments for the format string 865: */ 866: void kgsl_add_event_group(struct kgsl_device *device, 867: struct kgsl_event_group *group, 868: struct kgsl_context *context, readtimestamp_func readtimestamp, 869: void *priv, const char *fmt, ...); 870: 871: void kgsl_cancel_events_timestamp(struct kgsl_device *device, 872: struct kgsl_event_group *group, unsigned int timestamp); 873: void kgsl_cancel_events(struct kgsl_device *device, 874: struct kgsl_event_group *group); 875: void kgsl_cancel_event(struct kgsl_device *device, 876: struct kgsl_event_group *group, unsigned int timestamp, 877: kgsl_event_func func, void *priv); 878: bool kgsl_event_pending(struct kgsl_device *device, 879: struct kgsl_event_group *group, unsigned int timestamp, 880: kgsl_event_func func, void *priv); 881: int kgsl_add_event(struct kgsl_device *device, struct kgsl_event_group *group, 882: unsigned int timestamp, kgsl_event_func func, void *priv); 883: void kgsl_process_event_group(struct kgsl_device *device, 884: struct kgsl_event_group *group); 885: void kgsl_flush_event_group(struct kgsl_device *device, 886: struct kgsl_event_group *group); 887: void kgsl_process_event_groups(struct kgsl_device *device); 888: 889: void kgsl_context_destroy(struct kref *kref); 890: 891: int kgsl_context_init(struct kgsl_device_private *dev_priv, 892: struct kgsl_context *context); 893: 894: void kgsl_context_dump(struct kgsl_context *context); 895: 896: int kgsl_memfree_find_entry(pid_t ptname, uint64_t *gpuaddr, 897: uint64_t *size, uint64_t *flags, pid_t *pid); 898: 899: long kgsl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); 900: 901: long kgsl_ioctl_copy_in(unsigned int kernel_cmd, unsigned int user_cmd, 902: unsigned long arg, unsigned char *ptr); 903: 904: long kgsl_ioctl_copy_out(unsigned int kernel_cmd, unsigned int user_cmd, 905: unsigned long arg, unsigned char *ptr); 906: --- FILE: \kgsl_drawobj.c | HITS: 141 --- MATCH LINES: 23, 49, 50, 53, 58, 60, 69 11: * sync points. 12: * 13: * Sync points are events that need to expire before the 14: * drawobj can be queued to the hardware. All synpoints are contained in an 15: * array of kgsl_drawobj_sync_event structs in the drawobj. There can be 16: * multiple types of events both internal ones (GPU events) and external 17: * triggers. As the events expire bits are cleared in a pending bitmap stored 18: * in the drawobj. The GPU will submit the command as soon as the bitmap 19: * goes to zero indicating no more pending events. 20: */ 21: 22: #include 23: #include 24: 25: #include "adreno_drawctxt.h" 26: #include "kgsl_compat.h" 27: #include "kgsl_device.h" 28: #include "kgsl_drawobj.h" 29: #include "kgsl_eventlog.h" 30: #include "kgsl_sync.h" 31: #include "kgsl_timeline.h" 32: #include "kgsl_trace.h" 33: #include "kgsl_util.h" 34: 35: /* 36: * Define an kmem cache for the memobj structures since we 37: * allocate and free them so frequently 38: */ 39: static struct kmem_cache *memobjs_cache; 40: 41: static void syncobj_destroy_object(struct kgsl_drawobj *drawobj) 42: { 43: struct kgsl_drawobj_sync *syncobj = SYNCOBJ(drawobj); 44: int i; 45: 46: for (i = 0; i < syncobj->numsyncs; i++) { 47: struct kgsl_drawobj_sync_event *event = &syncobj->synclist[i]; 48: 49: if (event->type == KGSL_CMD_SYNCPOINT_TYPE_FENCE) { 50: struct event_fence_info *priv = event->priv; 51: 52: if (priv) { 53: kfree(priv->fences); 54: kfree(priv); 55: } 56: 57: if (event->handle) { 58: struct kgsl_sync_fence_cb *kcb = event->handle; 59: 60: dma_fence_put(kcb->fence); 61: kfree(kcb); 62: } 63: 64: } else if (event->type == KGSL_CMD_SYNCPOINT_TYPE_TIMELINE) { 65: kfree(event->priv); 66: } 67: } 68: 69: kfree(syncobj->hw_fences); 70: kfree(syncobj->synclist); 71: kfree(syncobj); 72: } 73: 74: static void cmdobj_destroy_object(struct kgsl_drawobj *drawobj) 75: { 76: kfree(CMDOBJ(drawobj)); 77: } 78: 79: static void bindobj_destroy_object(struct kgsl_drawobj *drawobj) 80: { 81: kfree(BINDOBJ(drawobj)); 82: } 83: 84: static void timelineobj_destroy_object(struct kgsl_drawobj *drawobj) 85: { 86: kfree(TIMELINEOBJ(drawobj)); 87: } 88: 89: void kgsl_drawobj_destroy_object(struct kref *kref) 90: { 91: struct kgsl_drawobj *drawobj = container_of(kref, 92: struct kgsl_drawobj, refcount); 93: MATCH LINES: 111, 114, 115, 119, 120, 124, 126, 128, 129, 130 99: struct kgsl_drawobj_sync *syncobj) 100: { 101: struct kgsl_drawobj_sync_event *event; 102: unsigned int i; 103: 104: for (i = 0; i < syncobj->numsyncs; i++) { 105: event = &syncobj->synclist[i]; 106: 107: if (!kgsl_drawobj_event_pending(syncobj, i)) 108: continue; 109: 110: switch (event->type) { 111: case KGSL_CMD_SYNCPOINT_TYPE_TIMESTAMP: { 112: unsigned int retired; 113: 114: kgsl_readtimestamp(event->device, 115: event->context, KGSL_TIMESTAMP_RETIRED, 116: &retired); 117: 118: dev_err(device->dev, 119: " [timestamp] context %u timestamp %u (retired %u)\n", 120: event->context->id, event->timestamp, 121: retired); 122: break; 123: } 124: case KGSL_CMD_SYNCPOINT_TYPE_FENCE: { 125: int j; 126: struct event_fence_info *info = event->priv; 127: 128: for (j = 0; info && j < info->num_fences; j++) 129: dev_err(device->dev, "[%d] fence: %s\n", 130: i, info->fences[j].name); 131: break; 132: } 133: case KGSL_CMD_SYNCPOINT_TYPE_TIMELINE: { 134: int j; 135: struct event_timeline_info *info = event->priv; 136: 137: for (j = 0; info && info[j].timeline; j++) 138: dev_err(device->dev, "[%d] timeline: %d seqno %lld\n", 139: i, info[j].timeline, info[j].seqno); 140: break; 141: } 142: } 143: } 144: } 145: 146: static void syncobj_timer(struct timer_list *t) 147: { 148: struct kgsl_device *device; 149: struct kgsl_drawobj_sync *syncobj = kgsl_timer_container_of(syncobj, t, timer); 150: struct kgsl_drawobj *drawobj; 151: struct kgsl_drawobj_sync_event *event; 152: unsigned int i; 153: 154: if (syncobj == NULL) MATCH LINES: 170, 171, 173, 175, 186, 187, 188, 190, 192, 194, 195, 196, 202, 204, 205, 208, 217 158: 159: if (!kref_get_unless_zero(&drawobj->refcount)) 160: return; 161: 162: if (drawobj->context == NULL) { 163: kgsl_drawobj_put(drawobj); 164: return; 165: } 166: 167: device = drawobj->context->device; 168: 169: dev_err(device->dev, 170: "kgsl: possible gpu syncpoint deadlock for context %u timestamp %u\n", 171: drawobj->context->id, drawobj->timestamp); 172: 173: set_bit(ADRENO_CONTEXT_FENCE_LOG, &drawobj->context->priv); 174: kgsl_context_dump(drawobj->context); 175: clear_bit(ADRENO_CONTEXT_FENCE_LOG, &drawobj->context->priv); 176: 177: dev_err(device->dev, " pending events:\n"); 178: 179: for (i = 0; i < syncobj->numsyncs; i++) { 180: event = &syncobj->synclist[i]; 181: 182: if (!kgsl_drawobj_event_pending(syncobj, i)) 183: continue; 184: 185: switch (event->type) { 186: case KGSL_CMD_SYNCPOINT_TYPE_TIMESTAMP: 187: dev_err(device->dev, " [%u] TIMESTAMP %u:%u\n", 188: i, event->context->id, event->timestamp); 189: break; 190: case KGSL_CMD_SYNCPOINT_TYPE_FENCE: { 191: int j; 192: struct event_fence_info *info = event->priv; 193: 194: for (j = 0; info && j < info->num_fences; j++) 195: dev_err(device->dev, " [%u] FENCE %s\n", 196: i, info->fences[j].name); 197: break; 198: } 199: case KGSL_CMD_SYNCPOINT_TYPE_TIMELINE: { 200: int j; 201: struct event_timeline_info *info = event->priv; 202: struct dma_fence *fence = event->fence; 203: bool retired = false; 204: bool signaled = test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, 205: &fence->flags); 206: const char *str = NULL; 207: 208: if (fence->ops->signaled && fence->ops->signaled(fence)) 209: retired = true; 210: 211: if (!retired) 212: str = "not retired"; 213: else if (retired && signaled) 214: str = "signaled"; 215: else if (retired && !signaled) 216: str = "retired but not signaled"; 217: dev_err(device->dev, " [%u] FENCE %s\n", 218: i, str); 219: for (j = 0; info && info[j].timeline; j++) 220: dev_err(device->dev, " TIMELINE %d SEQNO %lld\n", 221: info[j].timeline, info[j].seqno); 222: break; 223: } 224: } 225: } 226: 227: kgsl_drawobj_put(drawobj); 228: dev_err(device->dev, "--gpu syncpoint deadlock print end--\n"); 229: } 230: 231: /* 232: * a generic function to retire a pending sync event and (possibly) kick the 233: * dispatcher. 234: * Returns false if the event was already marked for cancellation in another 235: * thread. This function should return true if this thread is responsible for 236: * freeing up the memory, and the event will not be cancelled. 237: */ 238: static bool drawobj_sync_expire(struct kgsl_device *device, 239: struct kgsl_drawobj_sync_event *event) 240: { 241: struct kgsl_drawobj_sync *syncobj = event->syncobj; MATCH LINES: 264, 272, 273, 285, 290, 294, 295, 297, 298, 299, 303, 304, 307, 308, 310, 311, 312, 314, 315, 316, 318, 319, 320, 325, 326, 331, 335, 365, 367, 375, 376, 380, 381 252: */ 253: if (!kgsl_drawobj_events_pending(event->syncobj)) { 254: kgsl_delete_timer(&syncobj->timer); 255: 256: if (device->ftbl->drawctxt_sched) 257: device->ftbl->drawctxt_sched(device, 258: event->syncobj->base.context); 259: } 260: return true; 261: } 262: 263: /* 264: * This function is called by the GPU event when the sync event timestamp 265: * expires 266: */ 267: static void drawobj_sync_func(struct kgsl_device *device, 268: struct kgsl_event_group *group, void *priv, int result) 269: { 270: struct kgsl_drawobj_sync_event *event = priv; 271: 272: trace_syncpoint_timestamp_expire(event->syncobj, 273: event->context, event->timestamp); 274: 275: /* 276: * Put down the context ref count only if 277: * this thread successfully clears the pending bit mask. 278: */ 279: if (drawobj_sync_expire(device, event)) 280: kgsl_context_put(event->context); 281: 282: kgsl_drawobj_put(&event->syncobj->base); 283: } 284: 285: static void drawobj_sync_timeline_fence_work(struct work_struct *work) 286: { 287: struct kgsl_drawobj_sync_event *event = container_of(work, 288: struct kgsl_drawobj_sync_event, work); 289: 290: dma_fence_put(event->fence); 291: kgsl_drawobj_put(&event->syncobj->base); 292: } 293: 294: static void trace_syncpoint_timeline_fence(struct kgsl_drawobj_sync *syncobj, 295: struct dma_fence *f, bool expire) 296: { 297: struct dma_fence_array *array = to_dma_fence_array(f); 298: struct dma_fence **fences = &f; 299: u32 num_fences = 1; 300: int i; 301: 302: if (array) { 303: num_fences = array->num_fences; 304: fences = array->fences; 305: } 306: 307: for (i = 0; i < num_fences; i++) { 308: char fence_name[KGSL_FENCE_NAME_LEN]; 309: 310: snprintf(fence_name, sizeof(fence_name), "%s:%llu", 311: fences[i]->ops->get_timeline_name(fences[i]), 312: fences[i]->seqno); 313: if (expire) { 314: trace_syncpoint_fence_expire(syncobj, fence_name); 315: log_kgsl_syncpoint_fence_expire_event( 316: syncobj->base.context->id, fence_name); 317: } else { 318: trace_syncpoint_fence(syncobj, fence_name); 319: log_kgsl_syncpoint_fence_event( 320: syncobj->base.context->id, fence_name); 321: } 322: } 323: } 324: 325: static void drawobj_sync_timeline_fence_callback(struct dma_fence *f, 326: struct dma_fence_cb *cb) 327: { 328: struct kgsl_drawobj_sync_event *event = container_of(cb, 329: struct kgsl_drawobj_sync_event, cb); 330: 331: trace_syncpoint_timeline_fence(event->syncobj, f, true); 332: 333: /* 334: * Mark the event as synced and then fire off a worker to handle 335: * removing the fence 336: */ 337: if (drawobj_sync_expire(event->device, event)) 338: queue_work(kgsl_driver.lockless_workqueue, &event->work); 339: } 340: 341: static void syncobj_destroy(struct kgsl_drawobj *drawobj) 342: { 343: struct kgsl_drawobj_sync *syncobj = SYNCOBJ(drawobj); 344: unsigned int i; 345: 346: /* Zap the canary timer */ 347: kgsl_delete_timer_sync(&syncobj->timer); 348: 349: /* 350: * Clear all pending events - this will render any subsequent async 351: * callbacks harmless 352: */ 353: for (i = 0; i < syncobj->numsyncs; i++) { 354: struct kgsl_drawobj_sync_event *event = &syncobj->synclist[i]; 355: 356: /* 357: * Don't do anything if the event has already expired. 358: * If this thread clears the pending bit mask then it is 359: * responsible for doing context put. 360: */ 361: if (!test_and_clear_bit(i, &syncobj->pending)) 362: continue; 363: 364: switch (event->type) { 365: case KGSL_CMD_SYNCPOINT_TYPE_TIMESTAMP: 366: kgsl_cancel_event(drawobj->device, 367: &event->context->events, event->timestamp, 368: drawobj_sync_func, event); 369: /* 370: * Do context put here to make sure the context is alive 371: * till this thread cancels kgsl event. 372: */ 373: kgsl_context_put(event->context); 374: break; 375: case KGSL_CMD_SYNCPOINT_TYPE_FENCE: 376: kgsl_sync_fence_async_cancel(event->handle); 377: kgsl_drawobj_put(drawobj); 378: break; 379: case KGSL_CMD_SYNCPOINT_TYPE_TIMELINE: 380: dma_fence_remove_callback(event->fence, &event->cb); 381: dma_fence_put(event->fence); 382: kgsl_drawobj_put(drawobj); 383: break; 384: } 385: } 386: 387: /* 388: * If we cancelled an event, there's a good chance that the context is 389: * on a dispatcher queue, so schedule to get it removed. 390: */ 391: if (!bitmap_empty(&syncobj->pending, KGSL_MAX_SYNCPOINTS) && 392: drawobj->device->ftbl->drawctxt_sched) 393: drawobj->device->ftbl->drawctxt_sched(drawobj->device, 394: drawobj->context); 395: 396: } 397: 398: static void _drawobj_timelineobj_retire(struct kref *kref) 399: { 400: int i; 401: struct kgsl_drawobj_timeline *timelineobj = container_of(kref, 402: struct kgsl_drawobj_timeline, sig_refcount); 403: 404: for (i = 0; i < timelineobj->count; i++) { 405: kgsl_timeline_signal(timelineobj->timelines[i].timeline, MATCH LINES: 429, 431 417: static void kgsl_timelineobj_signal(struct kgsl_drawobj_timeline *timelineobj) 418: { 419: kref_put(&timelineobj->sig_refcount, _drawobj_timelineobj_retire); 420: } 421: 422: static void timelineobj_destroy(struct kgsl_drawobj *drawobj) 423: { 424: struct kgsl_drawobj_timeline *timelineobj = TIMELINEOBJ(drawobj); 425: int i; 426: 427: /* 428: * At this point any syncobjs blocking this timelinobj have been 429: * signaled. The timelineobj now only needs all preceding timestamps to 430: * retire before signaling the timelines. Notify timelines to keep them 431: * in sync with the timestamps as they retire. 432: */ 433: for (i = 0; i < timelineobj->count; i++) 434: kgsl_timeline_add_signal(&timelineobj->timelines[i]); 435: 436: /* 437: * The scheduler is done with the timelineobj. Put the initial 438: * sig_refcount to continue with the signaling process. 439: */ 440: kgsl_timelineobj_signal(timelineobj); 441: } 442: 443: static void bindobj_destroy(struct kgsl_drawobj *drawobj) 444: { 445: struct kgsl_drawobj_bind *bindobj = BINDOBJ(drawobj); 446: 447: kgsl_sharedmem_put_bind_op(bindobj->bind); 448: } 449: 450: static void cmdobj_destroy(struct kgsl_drawobj *drawobj) 451: { 452: struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj); 453: struct kgsl_memobj_node *mem, *tmpmem; 454: 455: /* MATCH LINES: 498, 501, 504, 505, 506, 507, 508 486: * kgsl_drawobj_destroy has returned. 487: */ 488: void kgsl_drawobj_destroy(struct kgsl_drawobj *drawobj) 489: { 490: if (IS_ERR_OR_NULL(drawobj)) 491: return; 492: 493: drawobj->destroy(drawobj); 494: 495: kgsl_drawobj_put(drawobj); 496: } 497: 498: static bool drawobj_sync_fence_func(void *priv) 499: { 500: struct kgsl_drawobj_sync_event *event = priv; 501: struct event_fence_info *info = event->priv; 502: int i; 503: 504: for (i = 0; info && i < info->num_fences; i++) { 505: trace_syncpoint_fence_expire(event->syncobj, 506: info->fences[i].name); 507: log_kgsl_syncpoint_fence_expire_event( 508: event->syncobj->base.context->id, info->fences[i].name); 509: } 510: 511: /* 512: * Only call kgsl_drawobj_put() if it's not marked for cancellation 513: * in another thread. 514: */ 515: if (drawobj_sync_expire(event->device, event)) { 516: kgsl_drawobj_put(&event->syncobj->base); 517: return true; 518: } 519: return false; 520: } 521: 522: static struct event_timeline_info * 523: drawobj_get_sync_timeline_priv(void __user *uptr, u64 usize, u32 count) 524: { 525: int i; 526: struct event_timeline_info *priv; 527: 528: /* Make sure we don't accidently overflow count */ 529: if (count == UINT_MAX) 530: return NULL; 531: 532: priv = kcalloc(count + 1, sizeof(*priv), GFP_KERNEL); MATCH LINES: 558, 565, 567, 568, 581, 582, 593, 594, 595, 596, 601, 602, 603, 605, 609, 610, 615, 617, 618, 622, 626, 629, 642, 651, 664, 668, 669, 676, 678, 679, 680, 681, 687, 692, 694, 696, 701, 713, 719, 722, 724, 725, 737, 740, 745, 752, 753, 763, 767, 769, 773, 792, 795, 796, 798, 799 546: priv[i].timeline = 0; 547: return priv; 548: } 549: 550: static int drawobj_add_sync_timeline(struct kgsl_device *device, 551: 552: struct kgsl_drawobj_sync *syncobj, void __user *uptr, 553: u64 usize) 554: { 555: struct kgsl_drawobj *drawobj = DRAWOBJ(syncobj); 556: struct kgsl_cmd_syncpoint_timeline sync; 557: struct kgsl_drawobj_sync_event *event; 558: struct dma_fence *fence; 559: unsigned int id; 560: int ret; 561: 562: if (copy_struct_from_user(&sync, sizeof(sync), uptr, usize)) 563: return -EFAULT; 564: 565: fence = kgsl_timelines_to_fence_array(device, sync.timelines, 566: sync.count, sync.timelines_size); 567: if (IS_ERR(fence)) 568: return PTR_ERR(fence); 569: 570: kref_get(&drawobj->refcount); 571: 572: id = syncobj->numsyncs++; 573: 574: event = &syncobj->synclist[id]; 575: 576: event->id = id; 577: event->type = KGSL_CMD_SYNCPOINT_TYPE_TIMELINE; 578: event->syncobj = syncobj; 579: event->device = device; 580: event->context = NULL; 581: event->fence = fence; 582: INIT_WORK(&event->work, drawobj_sync_timeline_fence_work); 583: 584: INIT_LIST_HEAD(&event->cb.node); 585: 586: event->priv = 587: drawobj_get_sync_timeline_priv(u64_to_user_ptr(sync.timelines), 588: sync.timelines_size, sync.count); 589: 590: /* Set pending flag before adding callback to avoid race */ 591: set_bit(event->id, &syncobj->pending); 592: 593: /* Get a dma_fence refcount to hand over to the callback */ 594: dma_fence_get(event->fence); 595: ret = dma_fence_add_callback(event->fence, 596: &event->cb, drawobj_sync_timeline_fence_callback); 597: 598: if (ret) { 599: clear_bit(event->id, &syncobj->pending); 600: 601: if (dma_fence_is_signaled(event->fence)) { 602: trace_syncpoint_fence_expire(syncobj, "signaled"); 603: log_kgsl_syncpoint_fence_expire_event( 604: syncobj->base.context->id, "signaled"); 605: dma_fence_put(event->fence); 606: ret = 0; 607: } 608: 609: /* Put the refcount from fence creation */ 610: dma_fence_put(event->fence); 611: kgsl_drawobj_put(drawobj); 612: return ret; 613: } 614: 615: trace_syncpoint_timeline_fence(event->syncobj, event->fence, false); 616: 617: /* Put the refcount from fence creation */ 618: dma_fence_put(event->fence); 619: return 0; 620: } 621: 622: static int drawobj_add_sync_fence(struct kgsl_device *device, 623: struct kgsl_drawobj_sync *syncobj, void __user *data, 624: u64 datasize) 625: { 626: struct kgsl_cmd_syncpoint_fence sync; 627: struct kgsl_drawobj *drawobj = DRAWOBJ(syncobj); 628: struct kgsl_drawobj_sync_event *event; 629: struct event_fence_info *priv; 630: unsigned int id, i; 631: 632: if (copy_struct_from_user(&sync, sizeof(sync), data, datasize)) 633: return -EFAULT; 634: 635: kref_get(&drawobj->refcount); 636: 637: id = syncobj->numsyncs++; 638: 639: event = &syncobj->synclist[id]; 640: 641: event->id = id; 642: event->type = KGSL_CMD_SYNCPOINT_TYPE_FENCE; 643: event->syncobj = syncobj; 644: event->device = device; 645: event->context = NULL; 646: 647: priv = kzalloc(sizeof(*priv), GFP_KERNEL); 648: 649: set_bit(event->id, &syncobj->pending); 650: 651: event->handle = kgsl_sync_fence_async_wait(sync.fd, drawobj_sync_fence_func, event); 652: 653: event->priv = priv; 654: 655: if (IS_ERR_OR_NULL(event->handle)) { 656: int ret = PTR_ERR(event->handle); 657: 658: clear_bit(event->id, &syncobj->pending); 659: event->handle = NULL; 660: 661: kgsl_drawobj_put(drawobj); 662: 663: /* 664: * If ret == 0 the fence was already signaled - print a trace 665: * message so we can track that 666: */ 667: if (ret == 0) { 668: trace_syncpoint_fence_expire(syncobj, "signaled"); 669: log_kgsl_syncpoint_fence_expire_event( 670: syncobj->base.context->id, "signaled"); 671: } 672: 673: return ret; 674: } 675: 676: kgsl_get_fence_info(event); 677: 678: for (i = 0; priv && i < priv->num_fences; i++) { 679: trace_syncpoint_fence(syncobj, priv->fences[i].name); 680: log_kgsl_syncpoint_fence_event(syncobj->base.context->id, 681: priv->fences[i].name); 682: } 683: 684: return 0; 685: } 686: 687: /* drawobj_add_sync_timestamp() - Add a new sync point for a sync obj 688: * @device: KGSL device 689: * @syncobj: KGSL sync obj to add the sync point to 690: * @priv: Private structure passed by the user 691: * 692: * Add a new sync point timestamp event to the sync obj. 693: */ 694: static int drawobj_add_sync_timestamp(struct kgsl_device *device, 695: struct kgsl_drawobj_sync *syncobj, 696: struct kgsl_cmd_syncpoint_timestamp *timestamp) 697: 698: { 699: struct kgsl_drawobj *drawobj = DRAWOBJ(syncobj); 700: struct kgsl_context *context = kgsl_context_get(device, 701: timestamp->context_id); 702: struct kgsl_drawobj_sync_event *event; 703: int ret = -EINVAL; 704: unsigned int id; 705: 706: if (context == NULL) 707: return -EINVAL; 708: 709: /* 710: * We allow somebody to create a sync point on their own context. 711: * This has the effect of delaying a command from submitting until the 712: * dependent command has cleared. That said we obviously can't let them 713: * create a sync point on a future timestamp. 714: */ 715: 716: if (context == drawobj->context) { 717: unsigned int queued; 718: 719: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_QUEUED, 720: &queued); 721: 722: if (timestamp_cmp(timestamp->timestamp, queued) > 0) { 723: dev_err(device->dev, 724: "Cannot create syncpoint for future timestamp %d (current %d)\n", 725: timestamp->timestamp, queued); 726: goto done; 727: } 728: } 729: 730: kref_get(&drawobj->refcount); 731: 732: id = syncobj->numsyncs++; 733: 734: event = &syncobj->synclist[id]; 735: event->id = id; 736: 737: event->type = KGSL_CMD_SYNCPOINT_TYPE_TIMESTAMP; 738: event->syncobj = syncobj; 739: event->context = context; 740: event->timestamp = timestamp->timestamp; 741: event->device = device; 742: 743: set_bit(event->id, &syncobj->pending); 744: 745: ret = kgsl_add_event(device, &context->events, timestamp->timestamp, 746: drawobj_sync_func, event); 747: 748: if (ret) { 749: clear_bit(event->id, &syncobj->pending); 750: kgsl_drawobj_put(drawobj); 751: } else { 752: trace_syncpoint_timestamp(syncobj, context, 753: timestamp->timestamp); 754: } 755: 756: done: 757: if (ret) 758: kgsl_context_put(context); 759: 760: return ret; 761: } 762: 763: static int drawobj_add_sync_timestamp_from_user(struct kgsl_device *device, 764: struct kgsl_drawobj_sync *syncobj, void __user *data, 765: u64 datasize) 766: { 767: struct kgsl_cmd_syncpoint_timestamp timestamp; 768: 769: if (copy_struct_from_user(×tamp, sizeof(timestamp), 770: data, datasize)) 771: return -EFAULT; 772: 773: return drawobj_add_sync_timestamp(device, syncobj, ×tamp); 774: } 775: 776: /** 777: * kgsl_drawobj_sync_add_sync() - Add a sync point to a command 778: * batch 779: * @device: Pointer to the KGSL device struct for the GPU 780: * @syncobj: Pointer to the sync obj 781: * @sync: Pointer to the user-specified struct defining the syncpoint 782: * 783: * Create a new sync point in the sync obj based on the 784: * user specified parameters 785: */ 786: int kgsl_drawobj_sync_add_sync(struct kgsl_device *device, 787: struct kgsl_drawobj_sync *syncobj, 788: struct kgsl_cmd_syncpoint *sync) 789: { 790: struct kgsl_drawobj *drawobj = DRAWOBJ(syncobj); 791: 792: if (sync->type != KGSL_CMD_SYNCPOINT_TYPE_FENCE) 793: set_bit(KGSL_SYNCOBJ_SW, &syncobj->flags); 794: 795: if (sync->type == KGSL_CMD_SYNCPOINT_TYPE_TIMESTAMP) 796: return drawobj_add_sync_timestamp_from_user(device, 797: syncobj, sync->priv, sync->size); 798: else if (sync->type == KGSL_CMD_SYNCPOINT_TYPE_FENCE) 799: return drawobj_add_sync_fence(device, 800: syncobj, sync->priv, sync->size); 801: else if (sync->type == KGSL_CMD_SYNCPOINT_TYPE_TIMELINE) 802: return drawobj_add_sync_timeline(device, 803: syncobj, sync->priv, sync->size); 804: 805: dev_err(device->dev, "bad syncpoint type %d for ctxt %u\n", 806: sync->type, drawobj->context->id); 807: 808: return -EINVAL; 809: } 810: 811: static void add_profiling_buffer(struct kgsl_device *device, 812: struct kgsl_drawobj_cmd *cmdobj, 813: uint64_t gpuaddr, uint64_t size, 814: unsigned int id, uint64_t offset) 815: { 816: struct kgsl_mem_entry *entry; 817: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 818: u64 start; 819: 820: if (!(drawobj->flags & KGSL_DRAWOBJ_PROFILING)) 821: return; 822: 823: /* Only the first buffer entry counts - ignore the rest */ MATCH LINES: 1036, 1037, 1073, 1081 1024: 1025: if (!cmd.count) 1026: return -EINVAL; 1027: 1028: timelineobj->timelines = kvcalloc(cmd.count, 1029: sizeof(*timelineobj->timelines), 1030: GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN); 1031: if (!timelineobj->timelines) 1032: return -ENOMEM; 1033: 1034: src = u64_to_user_ptr(cmd.timelines); 1035: 1036: /* Get the last queued timestamp on the drawobj context */ 1037: ret = kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_QUEUED, &queued); 1038: if (ret) 1039: return ret; 1040: 1041: for (i = 0; i < cmd.count; i++) { 1042: struct kgsl_timeline_val val; 1043: 1044: if (copy_struct_from_user(&val, sizeof(val), src, 1045: cmd.timelines_size)) { 1046: ret = -EFAULT; 1047: goto err; 1048: } 1049: 1050: if (val.padding) { 1051: ret = -EINVAL; 1052: goto err; 1053: } 1054: 1055: timelineobj->timelines[i].timeline = 1056: kgsl_timeline_by_id(dev_priv->device, 1057: val.timeline); 1058: 1059: if (!timelineobj->timelines[i].timeline) { 1060: ret = -ENODEV; 1061: goto err; 1062: } 1063: 1064: /* Get a context refcount so we can use the context pointer */ 1065: if (!_kgsl_context_get(context)) { 1066: ret = -ENODEV; 1067: goto err; 1068: } 1069: 1070: trace_kgsl_drawobj_timeline(val.timeline, val.seqno); 1071: timelineobj->timelines[i].seqno = val.seqno; 1072: timelineobj->timelines[i].context = context; 1073: timelineobj->timelines[i].timestamp = queued; 1074: 1075: src += cmd.timelines_size; 1076: } 1077: 1078: timelineobj->count = cmd.count; 1079: 1080: /* 1081: * Register a kgsl_event to notify us when the last queued timestamp 1082: * retires. Take a refcount on the drawobj to keep it valid for the 1083: * callback, and take the sig_refcount to synchronize with the 1084: * timelineobj retire. Both these refcounts are put in the callback. 1085: */ 1086: kref_get(&drawobj->refcount); 1087: kref_get(&timelineobj->sig_refcount); 1088: ret = kgsl_add_event(device, &context->events, queued, 1089: _timeline_signaled, timelineobj); 1090: 1091: if (ret) 1092: goto event_err; 1093: 1094: return 0; 1095: 1096: event_err: 1097: /* 1098: * If there was an error, put back sig_refcount and drawobj refcounts. 1099: * The caller still holds initial refcounts on both and puts them in 1100: * kgsl_drawobj_destroy(). Clean up the timelinelines array since we 1101: * do not want to signal anything now. 1102: */ 1103: kgsl_timelineobj_signal(timelineobj); 1104: kgsl_drawobj_put(drawobj); 1105: err: MATCH LINES: 1554, 1555, 1558, 1571, 1574 1542: &obj); 1543: if (ret) 1544: return ret; 1545: } 1546: 1547: ptr += sizeof(obj); 1548: } 1549: 1550: return 0; 1551: } 1552: 1553: struct kgsl_drawobj_sync * 1554: kgsl_drawobj_create_timestamp_syncobj(struct kgsl_device *device, 1555: struct kgsl_context *context, unsigned int timestamp) 1556: { 1557: struct kgsl_drawobj_sync *syncobj; 1558: struct kgsl_cmd_syncpoint_timestamp priv; 1559: int ret; 1560: 1561: syncobj = kgsl_drawobj_sync_create(device, context); 1562: if (IS_ERR(syncobj)) 1563: return syncobj; 1564: 1565: syncobj->synclist = kzalloc(sizeof(*syncobj->synclist), GFP_KERNEL); 1566: if (!syncobj->synclist) { 1567: kgsl_drawobj_destroy(DRAWOBJ(syncobj)); 1568: return ERR_PTR(-ENOMEM); 1569: } 1570: 1571: priv.timestamp = timestamp; 1572: priv.context_id = context->id; 1573: 1574: ret = drawobj_add_sync_timestamp(device, syncobj, &priv); 1575: if (ret) { 1576: kgsl_drawobj_destroy(DRAWOBJ(syncobj)); 1577: return ERR_PTR(ret); 1578: } 1579: 1580: return syncobj; 1581: } 1582: 1583: int kgsl_drawobj_sync_add_synclist(struct kgsl_device *device, 1584: struct kgsl_drawobj_sync *syncobj, void __user *ptr, 1585: unsigned int size, unsigned int count) 1586: { 1587: struct kgsl_command_syncpoint syncpoint; 1588: struct kgsl_cmd_syncpoint sync; 1589: int i, ret; 1590: 1591: /* If creating a sync and the data is not there or wrong then error */ 1592: ret = _verify_input_list(count, ptr, size); 1593: if (ret <= 0) 1594: return -EINVAL; 1595: 1596: syncobj->synclist = kcalloc(count, 1597: sizeof(struct kgsl_drawobj_sync_event), GFP_KERNEL); 1598: --- FILE: \kgsl_drawobj.h | HITS: 35 --- MATCH LINES: 10, 30, 38, 53, 62, 81, 96, 99, 100, 101, 103, 111, 128, 129, 131, 133 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #ifndef __KGSL_DRAWOBJ_H 8: #define __KGSL_DRAWOBJ_H 9: 10: #include 11: #include 12: 13: #define DRAWOBJ(obj) (&obj->base) 14: #define SYNCOBJ(obj) \ 15: container_of(obj, struct kgsl_drawobj_sync, base) 16: #define CMDOBJ(obj) \ 17: container_of(obj, struct kgsl_drawobj_cmd, base) 18: 19: #define CMDOBJ_TYPE BIT(0) 20: #define MARKEROBJ_TYPE BIT(1) 21: #define SYNCOBJ_TYPE BIT(2) 22: #define BINDOBJ_TYPE BIT(3) 23: #define TIMELINEOBJ_TYPE BIT(4) 24: 25: /** 26: * struct kgsl_drawobj - KGSL drawobj descriptor 27: * @device: KGSL GPU device that the command was created for 28: * @context: KGSL context that created the command 29: * @type: Object type 30: * @timestamp: Timestamp assigned to the command 31: * @flags: flags 32: * @refcount: kref structure to maintain the reference count 33: */ 34: struct kgsl_drawobj { 35: struct kgsl_device *device; 36: struct kgsl_context *context; 37: uint32_t type; 38: uint32_t timestamp; 39: unsigned long flags; 40: struct kref refcount; 41: /** @destroy: Callbak function to take down the object */ 42: void (*destroy)(struct kgsl_drawobj *drawobj); 43: /** @destroy_object: Callback function to free the object memory */ 44: void (*destroy_object)(struct kgsl_drawobj *drawobj); 45: }; 46: 47: /** 48: * struct kgsl_drawobj_cmd - KGSL command obj, This covers marker 49: * cmds also since markers are special form of cmds that do not 50: * need their cmds to be executed. 51: * @base: Base kgsl_drawobj, this needs to be the first entry 52: * @priv: Internal flags 53: * @global_ts: The ringbuffer timestamp corresponding to this 54: * command obj 55: * @fault_policy: Internal policy describing how to handle this command in case 56: * of a fault 57: * @fault_recovery: recovery actions actually tried for this batch 58: * be hung 59: * @refcount: kref structure to maintain the reference count 60: * @cmdlist: List of IBs to issue 61: * @memlist: List of all memory used in this command batch 62: * @marker_timestamp: For markers, the timestamp of the last "real" command that 63: * was queued 64: * @profiling_buf_entry: Mem entry containing the profiling buffer 65: * @profiling_buffer_gpuaddr: GPU virt address of the profile buffer added here 66: * for easy access 67: * @profile_index: Index to store the start/stop ticks in the kernel profiling 68: * buffer 69: * @submit_ticks: Variable to hold ticks at the time of 70: * command obj submit. 71: 72: */ 73: struct kgsl_drawobj_cmd { 74: struct kgsl_drawobj base; 75: unsigned long priv; 76: unsigned int global_ts; 77: unsigned long fault_policy; 78: unsigned long fault_recovery; 79: struct list_head cmdlist; 80: struct list_head memlist; 81: unsigned int marker_timestamp; 82: struct kgsl_mem_entry *profiling_buf_entry; 83: uint64_t profiling_buffer_gpuaddr; 84: unsigned int profile_index; 85: uint64_t submit_ticks; 86: /* @numibs: Number of ibs in this cmdobj */ 87: u32 numibs; 88: /* @requeue_cnt: Number of times cmdobj was requeued before submission to dq succeeded */ 89: u32 requeue_cnt; 90: }; 91: 92: /* This sync object cannot be sent to hardware */ 93: #define KGSL_SYNCOBJ_SW 0 94: /* This sync object can be sent to hardware */ 95: #define KGSL_SYNCOBJ_HW 1 96: /* This hw sync object has been assigned a timestamp */ 97: #define KGSL_SYNCOBJ_HW_TS 2 98: 99: struct kgsl_drawobj_sync_hw_fence { 100: /** @fence: Pointer to hardware fence */ 101: struct dma_fence *fence; 102: /** 103: * context: Pointer to kgsl context if this hardware fence is owned by a kgsl context 104: */ 105: struct kgsl_context *context; 106: }; 107: 108: /** 109: * struct kgsl_drawobj_sync - KGSL sync object 110: * @base: Base kgsl_drawobj, this needs to be the first entry 111: * @synclist: Array of context/timestamp tuples to wait for before issuing 112: * @numsyncs: Number of sync entries in the array 113: * @pending: Bitmask of sync events that are active 114: * @timer: a timer used to track possible sync timeouts for this 115: * sync obj 116: * @timeout_jiffies: For a sync obj the jiffies at 117: * which the timer will expire 118: */ 119: struct kgsl_drawobj_sync { 120: struct kgsl_drawobj base; 121: struct kgsl_drawobj_sync_event *synclist; 122: unsigned int numsyncs; 123: unsigned long pending; 124: struct timer_list timer; 125: unsigned long timeout_jiffies; 126: /** @flags: sync object internal flags */ 127: unsigned long flags; 128: /** @num_hw_fence: number of hw fences in this syncobj */ 129: u32 num_hw_fence; 130: /** 131: * @hw_fences: Array to hold information regarding hardware fences that are in this syncobj 132: */ 133: struct kgsl_drawobj_sync_hw_fence *hw_fences; 134: }; 135: 136: #define KGSL_BINDOBJ_STATE_START 0 137: #define KGSL_BINDOBJ_STATE_DONE 1 138: 139: /** 140: * struct kgsl_drawobj_bind - KGSL virtual buffer object bind operation 141: * @base: &struct kgsl_drawobj container 142: * @state: Current state of the draw operation 143: * @bind: Pointer to the VBO bind operation struct 144: */ 145: struct kgsl_drawobj_bind { 146: struct kgsl_drawobj base; 147: unsigned long state; 148: struct kgsl_sharedmem_bind_op *bind; 149: }; 150: 151: static inline struct kgsl_drawobj_bind *BINDOBJ(struct kgsl_drawobj *obj) 152: { 153: return container_of(obj, struct kgsl_drawobj_bind, base); 154: } 155: 156: /** 157: * struct kgsl_drawobj_timeline - KGSL timeline signal operation MATCH LINES: 176, 178, 179, 182, 183, 184, 197, 199, 200, 208, 209, 214, 217, 219 164: /* @timelines: Array of timeline events to signal */ 165: struct kgsl_timeline_event *timelines; 166: /** @count: Number of items in timelines */ 167: u32 count; 168: }; 169: 170: static inline struct kgsl_drawobj_timeline * 171: TIMELINEOBJ(struct kgsl_drawobj *obj) 172: { 173: return container_of(obj, struct kgsl_drawobj_timeline, base); 174: } 175: 176: #define KGSL_FENCE_NAME_LEN 74 177: 178: struct fence_info { 179: char name[KGSL_FENCE_NAME_LEN]; 180: }; 181: 182: struct event_fence_info { 183: struct fence_info *fences; 184: int num_fences; 185: }; 186: 187: struct event_timeline_info { 188: u64 seqno; 189: u32 timeline; 190: }; 191: 192: /** 193: * struct kgsl_drawobj_sync_event 194: * @id: identifer (positiion within the pending bitmap) 195: * @type: Syncpoint type 196: * @syncobj: Pointer to the syncobj that owns the sync event 197: * @context: KGSL context for whose timestamp we want to 198: * register this event 199: * @timestamp: Pending timestamp for the event 200: * @handle: Pointer to a sync fence handle 201: * @device: Pointer to the KGSL device 202: */ 203: struct kgsl_drawobj_sync_event { 204: unsigned int id; 205: int type; 206: struct kgsl_drawobj_sync *syncobj; 207: struct kgsl_context *context; 208: unsigned int timestamp; 209: struct kgsl_sync_fence_cb *handle; 210: struct kgsl_device *device; 211: /** @priv: Type specific private information */ 212: void *priv; 213: /** 214: * @fence: Pointer to a dma fence for KGSL_CMD_SYNCPOINT_TYPE_TIMELINE 215: * events 216: */ 217: struct dma_fence *fence; 218: /** @cb: Callback struct for KGSL_CMD_SYNCPOINT_TYPE_TIMELINE */ 219: struct dma_fence_cb cb; 220: /** @work : work_struct for KGSL_CMD_SYNCPOINT_TYPE_TIMELINE */ 221: struct work_struct work; 222: }; 223: 224: #define KGSL_DRAWOBJ_FLAGS \ 225: { KGSL_DRAWOBJ_MARKER, "MARKER" }, \ 226: { KGSL_DRAWOBJ_CTX_SWITCH, "CTX_SWITCH" }, \ 227: { KGSL_DRAWOBJ_SYNC, "SYNC" }, \ 228: { KGSL_DRAWOBJ_END_OF_FRAME, "EOF" }, \ 229: { KGSL_DRAWOBJ_PWR_CONSTRAINT, "PWR_CONSTRAINT" }, \ 230: { KGSL_DRAWOBJ_SUBMIT_IB_LIST, "IB_LIST" }, \ 231: { KGSL_DRAWOBJ_USES_MALU, "MALU" } 232: 233: /** 234: * enum kgsl_drawobj_cmd_priv - Internal command obj flags 235: * @CMDOBJ_SKIP - skip the entire command obj 236: * @CMDOBJ_FORCE_PREAMBLE - Force the preamble on for 237: * command obj 238: * @CMDOBJ_WFI - Force wait-for-idle for the submission 239: * @CMDOBJ_PROFILE - store the start / retire ticks for 240: * @CMDOBJ_FAULT - Mark the command object as faulted 241: * the command obj in the profiling buffer 242: * @CMDOBJ_RECURRING_START: To track recurring command object at GMU 243: * @CMDOBJ_RECURRING_STOP: To untrack recurring command object from GMU MATCH LINES: 320, 323, 325, 329, 330 308: return false; 309: 310: return test_bit(bit, &syncobj->pending); 311: } 312: 313: static inline void kgsl_drawobj_put(struct kgsl_drawobj *drawobj) 314: { 315: if (drawobj) 316: kref_put(&drawobj->refcount, kgsl_drawobj_destroy_object); 317: } 318: 319: /** 320: * kgsl_drawobj_create_timestamp_syncobj - Create a syncobj for a timestamp 321: * @device: A GPU device handle 322: * @context: Draw context for the syncobj 323: * @timestamp: Timestamp to sync on 324: * 325: * Create a sync object for @timestamp on @context. 326: * Return: A pointer to the sync object 327: */ 328: struct kgsl_drawobj_sync * 329: kgsl_drawobj_create_timestamp_syncobj(struct kgsl_device *device, 330: struct kgsl_context *context, unsigned int timestamp); 331: 332: struct kgsl_drawobj_bind *kgsl_drawobj_bind_create(struct kgsl_device *device, 333: struct kgsl_context *context); 334: 335: int kgsl_drawobj_add_bind(struct kgsl_device_private *dev_priv, 336: struct kgsl_drawobj_bind *bindobj, 337: void __user *src, u64 cmdsize); 338: 339: /** 340: * kgsl_drawobj_timeline_create - Create a timeline draw object 341: * @device: A GPU device handle 342: * @context: Draw context for the drawobj 343: * 344: * Create a timeline draw object on @context. 345: * Return: A pointer to the draw object 346: */ 347: struct kgsl_drawobj_timeline * 348: kgsl_drawobj_timeline_create(struct kgsl_device *device, 349: struct kgsl_context *context); 350: 351: /** 352: * kgsl_drwobj_add_timeline - Add a timeline to a timeline drawobj 353: * @dev_priv: Pointer to the process private data 354: * @timelineobj: Pointer to a timeline drawobject --- FILE: \kgsl_eventlog.c | HITS: 17 --- MATCH LINES: 19, 33, 34, 35, 36 7: #include 8: #include 9: #include 10: #include 11: 12: #include "kgsl_device.h" 13: #include "kgsl_eventlog.h" 14: #include "kgsl_snapshot.h" 15: #include "kgsl_util.h" 16: 17: #define EVENTLOG_SIZE (SZ_64K + SZ_32K) 18: #define MAGIC 0xabbaabba 19: #define LOG_FENCE_NAME_LEN 74 20: 21: #define KGSL_SNAPSHOT_EVENTLOG_TYPE 0x1 22: #define KGSL_SNAPSHOT_EVENTLOG_VERSION 0x0 23: 24: /* 25: * This an internal event used to skip empty space at the bottom of the 26: * ringbuffer 27: */ 28: 29: #define LOG_SKIP 1 30: #define LOG_FIRE_EVENT 2 31: #define LOG_CMDBATCH_SUBMITTED_EVENT 3 32: #define LOG_CMDBATCH_RETIRED_EVENT 4 33: #define LOG_SYNCPOINT_FENCE_EVENT 5 34: #define LOG_SYNCPOINT_FENCE_EXPIRE_EVENT 6 35: #define LOG_TIMELINE_FENCE_ALLOC_EVENT 7 36: #define LOG_TIMELINE_FENCE_RELEASE_EVENT 8 37: #define LOG_CX_WAIT_TIMEOUT_EVENT 9 38: 39: static spinlock_t lock; 40: static void *kgsl_eventlog; 41: static int eventlog_wptr; 42: 43: struct kgsl_log_header { 44: /** @magic: Magic value to identify header */ 45: u32 magic; 46: /** @pid: : PID of the process */ 47: int pid; 48: /** @time: System time in nanoseconds */ 49: u64 time; 50: /** @event: bits[0:15] specify the event ID. bits[16:31] specify event version */ 51: u32 event; 52: /** @size: Size of the event data in bytes */ 53: u32 size; 54: } __packed; 55: 56: /* Add a marker to skip the rest of the eventlog and start over fresh */ 57: static void add_skip_header(u32 offset) 58: { 59: struct kgsl_log_header *header = kgsl_eventlog + offset; 60: MATCH LINES: 183, 187, 190, 196, 199, 203, 206, 212, 215, 222, 230, 237 171: entry = kgsl_eventlog_alloc(LOG_CMDBATCH_RETIRED_EVENT, sizeof(*entry)); 172: if (!entry) 173: return; 174: 175: entry->id = id; 176: entry->ts = ts; 177: entry->prio = prio; 178: entry->flags = flags; 179: entry->start = start; 180: entry->retire = retire; 181: } 182: 183: void log_kgsl_syncpoint_fence_event(u32 id, char *fence_name) 184: { 185: struct __packed { 186: u32 id; 187: char name[LOG_FENCE_NAME_LEN]; 188: } *entry; 189: 190: entry = kgsl_eventlog_alloc(LOG_SYNCPOINT_FENCE_EVENT, sizeof(*entry)); 191: if (!entry) 192: return; 193: 194: entry->id = id; 195: memset(entry->name, 0, sizeof(entry->name)); 196: strscpy(entry->name, fence_name, sizeof(entry->name)); 197: } 198: 199: void log_kgsl_syncpoint_fence_expire_event(u32 id, char *fence_name) 200: { 201: struct __packed { 202: u32 id; 203: char name[LOG_FENCE_NAME_LEN]; 204: } *entry; 205: 206: entry = kgsl_eventlog_alloc(LOG_SYNCPOINT_FENCE_EXPIRE_EVENT, sizeof(*entry)); 207: if (!entry) 208: return; 209: 210: entry->id = id; 211: memset(entry->name, 0, sizeof(entry->name)); 212: strscpy(entry->name, fence_name, sizeof(entry->name)); 213: } 214: 215: void log_kgsl_timeline_fence_alloc_event(u32 id, u64 seqno) 216: { 217: struct __packed { 218: u32 id; 219: u64 seqno; 220: } *entry; 221: 222: entry = kgsl_eventlog_alloc(LOG_TIMELINE_FENCE_ALLOC_EVENT, sizeof(*entry)); 223: if (!entry) 224: return; 225: 226: entry->id = id; 227: entry->seqno = seqno; 228: } 229: 230: void log_kgsl_timeline_fence_release_event(u32 id, u64 seqno) 231: { 232: struct __packed { 233: u32 id; 234: u64 seqno; 235: } *entry; 236: 237: entry = kgsl_eventlog_alloc(LOG_TIMELINE_FENCE_RELEASE_EVENT, sizeof(*entry)); 238: if (!entry) 239: return; 240: 241: entry->id = id; 242: entry->seqno = seqno; 243: } 244: 245: void log_kgsl_cx_wait_timeout_event(u32 timeout_vote) 246: { 247: struct __packed { 248: u32 timeout_vote; 249: } *entry; 250: 251: entry = kgsl_eventlog_alloc(LOG_CX_WAIT_TIMEOUT_EVENT, sizeof(*entry)); 252: if (!entry) 253: return; 254: 255: entry->timeout_vote = timeout_vote; 256: } 257: 258: size_t kgsl_snapshot_eventlog_buffer(struct kgsl_device *device, 259: u8 *buf, size_t remain, void *priv) 260: { 261: struct kgsl_snapshot_eventlog *hdr = --- FILE: \kgsl_eventlog.h | HITS: 4 --- MATCH LINES: 20, 21, 22, 23 8: #define _KGSL_EVENTLOG_H 9: 10: #define HLOS_CX_WAIT_TIMEOUT 0 11: #define NONHLOS_CX_WAIT_TIMEOUT 1 12: 13: void kgsl_eventlog_init(void); 14: void kgsl_eventlog_exit(void); 15: 16: void log_kgsl_fire_event(u32 id, u32 ts, u32 type, u32 age); 17: void log_kgsl_cmdbatch_submitted_event(u32 id, u32 ts, u32 prio, u64 flags); 18: void log_kgsl_cmdbatch_retired_event(u32 id, u32 ts, u32 prio, u64 flags, 19: u64 start, u64 retire); 20: void log_kgsl_syncpoint_fence_event(u32 id, char *fence_name); 21: void log_kgsl_syncpoint_fence_expire_event(u32 id, char *fence_name); 22: void log_kgsl_timeline_fence_alloc_event(u32 id, u64 seqno); 23: void log_kgsl_timeline_fence_release_event(u32 id, u64 seqno); 24: void log_kgsl_cx_wait_timeout_event(u32 timeout_vote); 25: size_t kgsl_snapshot_eventlog_buffer(struct kgsl_device *device, 26: u8 *buf, size_t remain, void *priv); 27: #endif --- FILE: \kgsl_events.c | HITS: 38 --- MATCH LINES: 41, 44, 60, 64, 74, 91, 92, 94, 98, 105, 137, 140, 142, 143, 150, 179, 184, 192, 206, 212, 219, 232, 237, 248, 249, 253, 256, 272, 280, 285, 288, 291 29: /** 30: * _kgsl_event_worker() - Work handler for processing GPU event callbacks 31: * @work: Pointer to the kthread_work for the event 32: * 33: * Each event callback has its own kthread_work struct and is run on a event specific 34: * worker thread. This is the worker that queues up the event callback function. 35: */ 36: static void _kgsl_event_worker(struct kthread_work *work) 37: { 38: struct kgsl_event *event = container_of(work, struct kgsl_event, work); 39: int id = KGSL_CONTEXT_ID(event->context); 40: 41: trace_kgsl_fire_event(id, event->timestamp, event->result, 42: jiffies - event->created, event->func); 43: 44: log_kgsl_fire_event(id, event->timestamp, event->result, 45: jiffies - event->created); 46: 47: event->func(event->device, event->group, event->priv, event->result); 48: 49: kgsl_context_put(event->context); 50: kmem_cache_free(events_cache, event); 51: } 52: 53: /* return true if the group needs to be processed */ 54: static bool _do_process_group(unsigned int processed, unsigned int cur) 55: { 56: if (processed == cur) 57: return false; 58: 59: /* 60: * This ensures that the timestamp didn't slip back accidently, maybe 61: * due to a memory barrier issue. This is highly unlikely but we've 62: * been burned here in the past. 63: */ 64: if ((cur < processed) && ((processed - cur) < KGSL_TIMESTAMP_WINDOW)) 65: return false; 66: 67: return true; 68: } 69: 70: static void _process_event_group(struct kgsl_device *device, 71: struct kgsl_event_group *group, bool flush) 72: { 73: struct kgsl_event *event, *tmp; 74: unsigned int timestamp; 75: struct kgsl_context *context; 76: 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: ×tamp); 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) 151: signal_event(device, event, KGSL_EVENT_CANCELLED); 152: } 153: 154: spin_unlock(&group->lock); 155: } 156: 157: /** 158: * kgsl_cancel_events() - Cancel all pending events in the group 159: * @device: Pointer to a KGSL device 160: * @group: Pointer to a kgsl_events_group 161: */ 162: void kgsl_cancel_events(struct kgsl_device *device, 163: struct kgsl_event_group *group) 164: { 165: struct kgsl_event *event, *tmp; 166: 167: spin_lock(&group->lock); 168: 169: list_for_each_entry_safe(event, tmp, &group->events, node) 170: signal_event(device, event, KGSL_EVENT_CANCELLED); 171: 172: spin_unlock(&group->lock); 173: } 174: 175: /** 176: * kgsl_cancel_event() - Cancel a specific event from a group 177: * @device: Pointer to a KGSL device 178: * @group: Pointer to the group that contains the events 179: * @timestamp: Registered expiry timestamp for the event 180: * @func: Registered callback for the function 181: * @priv: Registered priv data for the function 182: */ 183: void kgsl_cancel_event(struct kgsl_device *device, 184: struct kgsl_event_group *group, unsigned int timestamp, 185: kgsl_event_func func, void *priv) 186: { 187: struct kgsl_event *event, *tmp; 188: 189: spin_lock(&group->lock); 190: 191: list_for_each_entry_safe(event, tmp, &group->events, node) { 192: if (timestamp == event->timestamp && func == event->func && 193: event->priv == priv) { 194: signal_event(device, event, KGSL_EVENT_CANCELLED); 195: break; 196: } 197: } 198: 199: spin_unlock(&group->lock); 200: } 201: 202: /** 203: * kgsl_event_pending() - Searches for an event in an event group 204: * @device: Pointer to a KGSL device 205: * @group: Pointer to the group that contains the events 206: * @timestamp: Registered expiry timestamp for the event 207: * @func: Registered callback for the function 208: * @priv: Registered priv data for the function 209: */ 210: bool kgsl_event_pending(struct kgsl_device *device, 211: struct kgsl_event_group *group, 212: unsigned int timestamp, kgsl_event_func func, void *priv) 213: { 214: struct kgsl_event *event; 215: bool result = false; 216: 217: spin_lock(&group->lock); 218: list_for_each_entry(event, &group->events, node) { 219: if (timestamp == event->timestamp && func == event->func && 220: event->priv == priv) { 221: result = true; 222: break; 223: } 224: } 225: spin_unlock(&group->lock); 226: return result; 227: } 228: /** 229: * kgsl_add_event() - Add a new GPU event to a group 230: * @device: Pointer to a KGSL device 231: * @group: Pointer to the group to add the event to 232: * @timestamp: Timestamp that the event will expire on 233: * @func: Callback function for the event 234: * @priv: Private data to send to the callback function 235: */ 236: int kgsl_add_event(struct kgsl_device *device, struct kgsl_event_group *group, 237: unsigned int timestamp, kgsl_event_func func, void *priv) 238: { 239: unsigned int queued; 240: struct kgsl_context *context = group->context; 241: struct kgsl_event *event; 242: unsigned int retired; 243: 244: if (!func) 245: return -EINVAL; 246: 247: /* 248: * If the caller is creating their own timestamps, let them schedule 249: * events in the future. Otherwise only allow timestamps that have been 250: * queued. 251: */ 252: if (!context || !(context->flags & KGSL_CONTEXT_USER_GENERATED_TS)) { 253: group->readtimestamp(device, group->priv, KGSL_TIMESTAMP_QUEUED, 254: &queued); 255: 256: if (timestamp_cmp(timestamp, queued) > 0) 257: return -EINVAL; 258: } 259: 260: event = kmem_cache_alloc(events_cache, GFP_KERNEL); 261: if (event == NULL) 262: return -ENOMEM; 263: 264: /* Get a reference to the context while the event is active */ 265: if (context != NULL && !_kgsl_context_get(context)) { 266: kmem_cache_free(events_cache, event); 267: return -ENOENT; 268: } 269: 270: event->device = device; 271: event->context = context; 272: event->timestamp = timestamp; 273: event->priv = priv; 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: MATCH LINES: 333, 338, 344, 370, 371, 376 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); 339: 340: spin_lock_init(&group->lock); 341: INIT_LIST_HEAD(&group->events); 342: 343: group->context = context; 344: group->readtimestamp = readtimestamp; 345: group->priv = priv; 346: 347: if (fmt) { 348: va_start(args, fmt); 349: vsnprintf(group->name, sizeof(group->name), fmt, args); 350: va_end(args); 351: } 352: 353: write_lock(&device->event_groups_lock); 354: list_add_tail(&group->group, &device->event_groups); 355: write_unlock(&device->event_groups_lock); 356: } 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); --- FILE: \kgsl_gmu_core.c | HITS: 8 --- MATCH LINES: 524 512: 513: int gmu_core_import_buffer(struct kgsl_device *device, struct hfi_mem_alloc_entry *entry) 514: { 515: struct hfi_mem_alloc_desc *desc = &entry->desc; 516: u32 attrs = gmu_core_get_attrs(desc->flags); 517: u32 vma_id = (desc->flags & HFI_MEMFLAG_GMU_CACHEABLE) ? GMU_CACHE : GMU_NONCACHED_KERNEL; 518: 519: /* 520: * GMU Tx/Rx queues are mapped as I/O-coherent on both SOCCP and CPU, 521: * mark the buffer I/O-coherent on GMU side as well to prevent stale 522: * data and immediate updates in DDR. 523: */ 524: if (desc->mem_kind == HFI_MEMKIND_HW_FENCE && 525: kgsl_mmu_has_feature(device, KGSL_MMU_IO_COHERENT)) { 526: entry->md->flags |= KGSL_MEMFLAGS_IOCOHERENT; 527: attrs |= IOMMU_CACHE; 528: } 529: 530: return gmu_core_map_gmu(device, entry->md, 0, vma_id, attrs, desc->align); 531: } 532: 533: struct kgsl_memdesc *gmu_core_reserve_kernel_block(struct kgsl_device *device, 534: u32 addr, u32 size, u32 vma_id, u32 align) 535: { 536: int ret; 537: u64 memflags = 0; 538: struct kgsl_memdesc *md; 539: struct gmu_core_device *gmu = &device->gmu_core; 540: int attrs = IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV; 541: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 542: 543: if (gmu->global_entries == ARRAY_SIZE(gmu->gmu_globals)) 544: return ERR_PTR(-ENOMEM); 545: 546: md = &gmu->gmu_globals[gmu->global_entries]; 547: 548: /* MATCH LINES: 892, 893, 894, 896, 904 880: trace_adreno_preempt_trigger(data->cur_rb, data->next_rb, 881: data->ctx_switch_cntl, pkt->ticks); 882: break; 883: } 884: case GMU_TRACE_PREEMPT_DONE: { 885: struct trace_preempt_done *data = 886: (struct trace_preempt_done *)pkt->payload; 887: 888: trace_adreno_preempt_done(data->prev_rb, data->next_rb, 889: data->ctx_switch_cntl, pkt->ticks); 890: break; 891: } 892: case GMU_TRACE_EXTERNAL_HW_FENCE_SIGNAL: { 893: struct trace_ext_hw_fence_signal *data = 894: (struct trace_ext_hw_fence_signal *)pkt->payload; 895: 896: trace_adreno_ext_hw_fence_signal(data->context, data->seq_no, 897: data->flags, pkt->ticks); 898: break; 899: } 900: case GMU_TRACE_SYNCOBJ_RETIRE: { 901: struct trace_syncobj_retire *data = 902: (struct trace_syncobj_retire *)pkt->payload; 903: 904: trace_adreno_syncobj_retired(data->gmu_ctxt_id, data->timestamp, pkt->ticks); 905: break; 906: } 907: case GMU_TRACE_DCVS_PWRLVL: { 908: _gmu_trace_dcvs_pwrlevel(device, pkt); 909: break; 910: } 911: case GMU_TRACE_DCVS_BUSLVL: { 912: _gmu_trace_dcvs_buslevel(device, pkt); 913: break; 914: } 915: case GMU_TRACE_DCVS_PWRSTATS: { 916: _gmu_trace_dcvs_pwrstats(device, pkt); 917: break; 918: } 919: case GMU_TRACE_PWR_CONSTRAINT: { 920: struct trace_pwr_constraint *data = 921: (struct trace_pwr_constraint *)pkt->payload; 922: 923: trace_kgsl_constraint(device, data->type, data->value, data->status, pkt->ticks); 924: break; 925: } 926: case GMU_TRACE_DCVS_PROFILE: { 927: struct trace_dcvs_profile *data = 928: (struct trace_dcvs_profile *)pkt->payload; MATCH LINES: 1059, 1065 1047: trace->seq_num = 0; 1048: gmu_core_trace_header_init(trace); 1049: trace->reset_hdr = false; 1050: } 1051: 1052: int gmu_core_soccp_vote(struct kgsl_device *device, bool pwr_on) 1053: { 1054: int ret; 1055: 1056: if (!(test_bit(GMU_SOCCP_VOTE_ON, &device->gmu_core.flags) ^ pwr_on)) 1057: return 0; 1058: 1059: ret = kgsl_hw_fence_soccp_vote(pwr_on); 1060: if (!ret) { 1061: change_bit(GMU_SOCCP_VOTE_ON, &device->gmu_core.flags); 1062: return 0; 1063: } 1064: 1065: dev_err(GMU_PDEV_DEV(device), "soccp power %s failed: %d. Disabling hw fences\n", 1066: pwr_on ? "on" : "off", ret); 1067: 1068: return ret; 1069: } 1070: 1071: bool gmu_core_capabilities_enabled(struct firmware_capabilities *caps, u32 field) 1072: { 1073: if (!caps->length || !caps->data) 1074: return false; 1075: 1076: /* Capabilities payload data stored in 1 byte */ 1077: if (caps->data[field / BITS_PER_BYTE] & BIT(field % BITS_PER_BYTE)) 1078: return true; 1079: 1080: return false; 1081: } 1082: 1083: void gmu_core_mark_for_coldboot(struct kgsl_device *device) 1084: { 1085: struct gmu_core_device *gmu_core = &device->gmu_core; 1086: 1087: if (!gmu_core->warmboot_enabled) 1088: return; 1089: --- FILE: \kgsl_gmu_core.h | HITS: 11 --- MATCH LINES: 46 34: #define INVALID_BW_VOTE (INVALID_DCVS_IDX | \ 35: (FIELD_PREP(GENMASK(31, 16), INVALID_AB_VALUE))) 36: #if MAX_CNOC_LEVELS > MAX_GX_LEVELS 37: #error "CNOC levels cannot exceed GX levels" 38: #endif 39: 40: enum gmu_common_capabilities { 41: FCC_VERSION_INFO = 0, 42: }; 43: 44: enum gmu_platform_capabilities { 45: FAC_TRACE_BUFFER = 0, 46: FAC_VRB_HW_FENCE_SHADOW_NUM_ENTRIES = 1, 47: FAC_VRB_CL_NO_FT_TIMEOUT = 2, 48: FAC_VRB_PREEMPT_COUNT = 3, 49: FAC_RBBM_INTERRUPTS_HANDLE_ALL = 4, 50: FAC_FORCE_RETIRE_COMMAND = 5, 51: FAC_SOFT_RESET = 6, 52: FAC_FAST_CONTEXT_DESTROY = 7, 53: FAC_POWER_CONTROL_WA = 8, 54: }; 55: 56: /* 57: * These are the different ways the GMU can boot. GMU_WARM_BOOT is waking up 58: * from slumber. GMU_COLD_BOOT is booting for the first time. GMU_RESET 59: * is a soft reset of the GMU. 60: */ 61: enum gmu_core_boot { 62: GMU_WARM_BOOT = 0, 63: GMU_COLD_BOOT = 1, 64: GMU_RESET = 2 65: }; 66: 67: /* Bits for the flags field in the gmu structure */ 68: enum gmu_core_flags { 69: GMU_BOOT_INIT_DONE = 0, 70: GMU_HFI_ON, MATCH LINES: 118, 119, 134, 139 106: */ 107: #define GMU_CORE_WAKEUP_DELAY_US 10 108: 109: /* Max amount of tries to wake up the GMU. The short retry 110: * limit is half of the long retry limit. After the short 111: * number of retries, we print an informational message to say 112: * exiting IFPC is taking longer than expected. We continue 113: * to retry after this until the long retry limit. 114: */ 115: #define GMU_CORE_SHORT_WAKEUP_RETRY_LIMIT 100 116: #define GMU_CORE_LONG_WAKEUP_RETRY_LIMIT 200 117: 118: #define FENCE_STATUS_WRITEDROPPED0_MASK 0x1 119: #define FENCE_STATUS_WRITEDROPPED1_MASK 0x2 120: 121: #define HFI_VERSION(major, minor, step) \ 122: (FIELD_PREP(GENMASK(31, 28), major) | \ 123: FIELD_PREP(GENMASK(27, 16), minor) | \ 124: FIELD_PREP(GENMASK(15, 0), step)) 125: 126: #define GMU_VER_MAJOR(ver) (((ver) >> 28) & 0xF) 127: #define GMU_VER_MINOR(ver) (((ver) >> 16) & 0xFFF) 128: #define GMU_VER_STEP(ver) ((ver) & 0xFFFF) 129: #define GMU_VERSION(major, minor, step) \ 130: ((((major) & 0xF) << 28) | (((minor) & 0xFFF) << 16) | ((step) & 0xFFFF)) 131: 132: #define GMU_INT_WDOG_BITE BIT(0) 133: #define GMU_INT_RSCC_COMP BIT(1) 134: #define GMU_INT_FENCE_ERR BIT(3) 135: #define GMU_INT_DBD_WAKEUP BIT(4) 136: #define GMU_INT_HOST_AHB_BUS_ERR BIT(5) 137: #define GMU_AO_INT_MASK \ 138: (GMU_INT_WDOG_BITE | \ 139: GMU_INT_FENCE_ERR | \ 140: GMU_INT_HOST_AHB_BUS_ERR) 141: 142: /* Bitmask for GPU low power mode enabling and hysterisis*/ 143: #define SPTP_ENABLE_MASK (BIT(2) | BIT(0)) 144: #define IFPC_ENABLE_MASK (BIT(1) | BIT(0)) 145: 146: /* Bitmask for RPMH capability enabling */ 147: #define RPMH_INTERFACE_ENABLE BIT(0) 148: #define LLC_VOTE_ENABLE BIT(4) 149: #define DDR_VOTE_ENABLE BIT(8) 150: #define MX_VOTE_ENABLE BIT(9) 151: #define CX_VOTE_ENABLE BIT(10) 152: #define GFX_VOTE_ENABLE BIT(11) 153: #define RPMH_ENABLE_MASK (RPMH_INTERFACE_ENABLE | \ 154: LLC_VOTE_ENABLE | \ 155: DDR_VOTE_ENABLE | \ 156: MX_VOTE_ENABLE | \ 157: CX_VOTE_ENABLE | \ 158: GFX_VOTE_ENABLE) 159: 160: /* Constants for GMU OOBs */ 161: #define OOB_BOOT_OPTION 0 162: #define OOB_SLUMBER_OPTION 1 163: MATCH LINES: 215, 216 203: 204: /* 205: * GMU Virtual Register Definitions 206: * These values are dword offsets into the GMU Virtual Register Bank 207: */ 208: enum gmu_vrb_idx { 209: /* Number of dwords supported by VRB */ 210: VRB_SIZE_IDX = 0, 211: /* Contains the address of warmboot scratch buffer */ 212: VRB_WARMBOOT_SCRATCH_IDX = 1, 213: /* Contains the address of GMU trace buffer */ 214: VRB_TRACE_BUFFER_ADDR_IDX = 2, 215: /* Contains the number of hw fence shadow table entries */ 216: VRB_HW_FENCE_SHADOW_NUM_ENTRIES = 3, 217: /* Contains OpenCL no fault tolerance timeout in ms */ 218: VRB_CL_NO_FT_TIMEOUT = 4, 219: /* Contains the total number of GPU preemptions */ 220: VRB_PREEMPT_COUNT_TOTAL = 5, 221: /* Contains the number of L0 GPU preemptions */ 222: VRB_PREEMPT_COUNT_L0 = 6, 223: /* Contains the number of L1A GPU preemptions */ 224: VRB_PREEMPT_COUNT_L1A = 7, 225: /* Contains the number of L1B GPU preemptions */ 226: VRB_PREEMPT_COUNT_L1B = 8, 227: /* Contains the GMU VA for power limits trace buffer */ 228: VRB_PWR_LIMITS_TRACE_BUF = 9, 229: /* Contains the total size of context record in KB */ 230: VRB_CTXRECORD_TOTAL_SZ = 10, 231: /* Contains the size of AQE context record in KB */ 232: VRB_CTXRECORD_AQE_SZ = 11, 233: /* Contains the size of GMEM inside context record in KB */ 234: VRB_CTXRECORD_GMEM_SZ = 12, 235: /* Contains whether to enable fault on DBGC interrupts */ 236: VRB_DBGC_FAULT_ENABLE = 17, 237: }; 238: 239: /* For GMU Trace */ 240: #define GMU_TRACE_SIZE SZ_16K MATCH LINES: 328, 350, 358 316: * timeout: GMU Trace Timer value in msec - zero to disable trace timer else 317: * value for GMU trace timerhandler to send HFI msg. 318: */ 319: u32 timeout; 320: /** @log_type: To decode the trace buffer data */ 321: u32 log_type; 322: } __packed; 323: 324: /* Trace ID definition */ 325: enum gmu_trace_id { 326: GMU_TRACE_PREEMPT_TRIGGER = 1, 327: GMU_TRACE_PREEMPT_DONE = 2, 328: GMU_TRACE_EXTERNAL_HW_FENCE_SIGNAL = 3, 329: GMU_TRACE_SYNCOBJ_RETIRE = 4, 330: GMU_TRACE_DCVS_PWRLVL = 5, 331: GMU_TRACE_DCVS_BUSLVL = 6, 332: GMU_TRACE_DCVS_PWRSTATS = 7, 333: GMU_TRACE_PWR_CONSTRAINT = 8, 334: GMU_TRACE_DCVS_PROFILE = 9, 335: GMU_TRACE_MAX, 336: }; 337: 338: struct trace_preempt_trigger { 339: u32 cur_rb; 340: u32 next_rb; 341: u32 ctx_switch_cntl; 342: } __packed; 343: 344: struct trace_preempt_done { 345: u32 prev_rb; 346: u32 next_rb; 347: u32 ctx_switch_cntl; 348: } __packed; 349: 350: struct trace_ext_hw_fence_signal { 351: u64 context; 352: u64 seq_no; 353: u32 flags; 354: } __packed; 355: 356: struct trace_syncobj_retire { 357: u32 gmu_ctxt_id; 358: u32 timestamp; 359: } __packed; 360: 361: #define TRACE_FLAG_BIT_DCVS_VOTE 0 362: #define TRACE_FLAG_BIT_STRICT_FRAME 1 363: #define TRACE_FLAG_BIT_NON_LINEAR_UP 2 364: #define TRACE_FLAG_BIT_NON_LINEAR_DOWN 3 365: 366: struct trace_dcvs_pwrlvl { 367: u32 new_pwrlvl; 368: u32 prev_pwrlvl; 369: u32 flag; 370: u16 penalty_up; 371: u16 penalty_down; 372: u16 first_step_down_count; 373: u16 subsequent_step_down_count; 374: u16 min_freq; 375: u16 max_freq; 376: u16 num_samples_up; 377: u16 num_samples_down; 378: u16 target_fps; 379: u16 mod_percent; 380: u16 avg_busy; 381: u16 padding; 382: } __packed; MATCH LINES: 510 498: GMU_FAULT_HFI_INIT, 499: GMU_FAULT_OOB_SET, 500: GMU_FAULT_HFI_RECIVE_ACK, 501: GMU_FAULT_SEND_CMD_WAIT_INLINE, 502: GMU_FAULT_HFI_SEND_GENERIC_REQ, 503: GMU_FAULT_F2H_MSG_ERR, 504: GMU_FAULT_H2F_MSG_START, 505: GMU_FAULT_WAIT_ACK_COMPLETION, 506: GMU_FAULT_HFI_ACK, 507: GMU_FAULT_CTX_UNREGISTER, 508: GMU_FAULT_WAIT_FOR_LOWEST_IDLE, 509: GMU_FAULT_WAIT_FOR_IDLE, 510: GMU_FAULT_HW_FENCE, 511: GMU_FAULT_WAIT_FOR_CX, 512: GMU_FAULT_CX_WAIT_TIMEOUT, 513: GMU_FAULT_CM3, 514: GMU_FAULT_MAX, 515: }; 516: 517: #define KGSL_GMU_CORE_FORCE_PANIC(gf_panic, pdev, ticks, policy) do { \ 518: if (gf_panic & BIT(policy)) { \ 519: dev_err(&pdev->dev, \ 520: "GMU always on ticks: %llx gf_policy: 0x%x gf_trigger: 0x%lx\n", \ 521: ticks, gf_panic, BIT(policy));\ 522: BUG();\ 523: } \ 524: } while (0) 525: 526: struct gmu_dev_ops { 527: int (*oob_set)(struct kgsl_device *device, enum oob_request req); 528: void (*oob_clear)(struct kgsl_device *device, enum oob_request req); 529: int (*ifpc_store)(struct kgsl_device *device, unsigned int val); 530: unsigned int (*ifpc_isenabled)(struct kgsl_device *device); 531: void (*cooperative_reset)(struct kgsl_device *device); 532: int (*wait_for_active_transition)(struct kgsl_device *device); 533: bool (*scales_bandwidth)(struct kgsl_device *device); 534: int (*acd_set)(struct kgsl_device *device, bool val); --- FILE: \kgsl_ioctl.c | HITS: 17 --- MATCH LINES: 13, 14, 15, 20, 21, 22, 23, 24, 25, 40, 41, 58, 59, 60, 61, 96, 97 1: // SPDX-License-Identifier: GPL-2.0-only 2: /* 3: * Copyright (c) 2008-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 5: */ 6: 7: #include "kgsl_device.h" 8: #include "kgsl_sync.h" 9: 10: static const struct kgsl_ioctl kgsl_ioctl_funcs[] = { 11: KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_GETPROPERTY, 12: kgsl_ioctl_device_getproperty), 13: /* IOCTL_KGSL_DEVICE_WAITTIMESTAMP is no longer supported */ 14: KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID, 15: kgsl_ioctl_device_waittimestamp_ctxtid), 16: KGSL_IOCTL_FUNC(IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS, 17: kgsl_ioctl_rb_issueibcmds), 18: KGSL_IOCTL_FUNC(IOCTL_KGSL_SUBMIT_COMMANDS, 19: kgsl_ioctl_submit_commands), 20: /* IOCTL_KGSL_CMDSTREAM_READTIMESTAMP is no longer supported */ 21: KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID, 22: kgsl_ioctl_cmdstream_readtimestamp_ctxtid), 23: /* IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP is no longer supported */ 24: KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID, 25: kgsl_ioctl_cmdstream_freememontimestamp_ctxtid), 26: KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_CREATE, 27: kgsl_ioctl_drawctxt_create), 28: KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_DESTROY, 29: kgsl_ioctl_drawctxt_destroy), 30: KGSL_IOCTL_FUNC(IOCTL_KGSL_MAP_USER_MEM, 31: kgsl_ioctl_map_user_mem), 32: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FROM_PMEM, 33: kgsl_ioctl_map_user_mem), 34: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FREE, 35: kgsl_ioctl_sharedmem_free), 36: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE, 37: kgsl_ioctl_sharedmem_flush_cache), 38: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_ALLOC, 39: kgsl_ioctl_gpumem_alloc), 40: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMESTAMP_EVENT, 41: kgsl_ioctl_timestamp_event), 42: KGSL_IOCTL_FUNC(IOCTL_KGSL_SETPROPERTY, 43: kgsl_ioctl_device_setproperty), 44: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_ALLOC_ID, 45: kgsl_ioctl_gpumem_alloc_id), 46: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_FREE_ID, 47: kgsl_ioctl_gpumem_free_id), 48: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_GET_INFO, 49: kgsl_ioctl_gpumem_get_info), 50: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_SYNC_CACHE, 51: kgsl_ioctl_gpumem_sync_cache), 52: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_SYNC_CACHE_BULK, 53: kgsl_ioctl_gpumem_sync_cache_bulk), 54: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_CREATE, 55: kgsl_ioctl_syncsource_create), 56: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_DESTROY, 57: kgsl_ioctl_syncsource_destroy), 58: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_CREATE_FENCE, 59: kgsl_ioctl_syncsource_create_fence), 60: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_SIGNAL_FENCE, 61: kgsl_ioctl_syncsource_signal_fence), 62: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUOBJ_ALLOC, 63: kgsl_ioctl_gpuobj_alloc), 64: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUOBJ_FREE, 65: kgsl_ioctl_gpuobj_free), 66: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUOBJ_INFO, 67: kgsl_ioctl_gpuobj_info), 68: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUOBJ_IMPORT, 69: kgsl_ioctl_gpuobj_import), 70: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUOBJ_SYNC, 71: kgsl_ioctl_gpuobj_sync), 72: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPU_COMMAND, 73: kgsl_ioctl_gpu_command), 74: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUOBJ_SET_INFO, 75: kgsl_ioctl_gpuobj_set_info), 76: KGSL_IOCTL_FUNC(IOCTL_KGSL_SPARSE_PHYS_ALLOC, 77: NULL), 78: KGSL_IOCTL_FUNC(IOCTL_KGSL_SPARSE_PHYS_FREE, 79: NULL), 80: KGSL_IOCTL_FUNC(IOCTL_KGSL_SPARSE_VIRT_ALLOC, 81: NULL), 82: KGSL_IOCTL_FUNC(IOCTL_KGSL_SPARSE_VIRT_FREE, 83: NULL), 84: KGSL_IOCTL_FUNC(IOCTL_KGSL_SPARSE_BIND, 85: NULL), 86: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPU_SPARSE_COMMAND, 87: NULL), 88: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_BIND_RANGES, 89: kgsl_ioctl_gpumem_bind_ranges), 90: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPU_AUX_COMMAND, 91: kgsl_ioctl_gpu_aux_command), 92: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMELINE_CREATE, 93: kgsl_ioctl_timeline_create), 94: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMELINE_WAIT, 95: kgsl_ioctl_timeline_wait), 96: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMELINE_FENCE_GET, 97: kgsl_ioctl_timeline_fence_get), 98: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMELINE_QUERY, 99: kgsl_ioctl_timeline_query), 100: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMELINE_SIGNAL, 101: kgsl_ioctl_timeline_signal), 102: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMELINE_DESTROY, 103: kgsl_ioctl_timeline_destroy), 104: KGSL_IOCTL_FUNC(IOCTL_KGSL_GET_FAULT_REPORT, 105: kgsl_ioctl_get_fault_report), 106: KGSL_IOCTL_FUNC(IOCTL_KGSL_RECURRING_COMMAND, 107: kgsl_ioctl_recurring_command), 108: }; 109: 110: long kgsl_ioctl_copy_in(unsigned int kernel_cmd, unsigned int user_cmd, 111: unsigned long arg, unsigned char *ptr) 112: { 113: unsigned int usize = _IOC_SIZE(user_cmd); 114: unsigned int ksize = _IOC_SIZE(kernel_cmd); 115: unsigned int copy = ksize < usize ? ksize : usize; 116: 117: if ((kernel_cmd & IOC_IN) && (user_cmd & IOC_IN)) { 118: if (copy > 0 && copy_from_user(ptr, (void __user *) arg, copy)) 119: return -EFAULT; 120: } 121: --- FILE: \kgsl_pwrctrl.c | HITS: 7 --- MATCH LINES: 162, 165, 166, 174 150: (time_after(jiffies, pwr->constraint.expires))) { 151: 152: struct kgsl_context *context = kgsl_context_get(device, 153: pwr->constraint.owner_id); 154: 155: /* We couldn't get a reference, clear the constraint */ 156: if (!context) { 157: reset = true; 158: goto done; 159: } 160: 161: /* 162: * If the last timestamp that set the constraint has retired, 163: * clear the constraint 164: */ 165: if (kgsl_check_timestamp(device, context, 166: pwr->constraint.owner_timestamp)) { 167: reset = true; 168: kgsl_context_put(context); 169: goto done; 170: } 171: 172: /* 173: * Increase the timeout to keep the constraint at least till 174: * the timestamp retires 175: */ 176: pwr->constraint.expires = jiffies + 177: msecs_to_jiffies(atomic64_read(&device->pwrctrl.interval_timeout)); 178: 179: kgsl_context_put(context); 180: } 181: 182: done: 183: if (reset) { 184: /* Trace the constraint being un-set by the driver */ 185: trace_kgsl_constraint(device, pwr->constraint.type, 186: old_level, 0, 0); 187: /*Invalidate the constraint set */ 188: pwr->constraint.expires = 0; 189: pwr->constraint.type = KGSL_CONSTRAINT_NONE; 190: } 191: 192: /* 193: * Adjust the power level if required by thermal, max/min, 194: * constraints, etc 195: */ 196: return _adjust_pwrlevel(pwr, new_level, &pwr->constraint); 197: } 198: MATCH LINES: 300, 310, 316 288: unsigned int constraint; 289: struct kgsl_pwr_constraint *pwrc_old; 290: 291: if (device == NULL || pwrc == NULL) 292: return; 293: constraint = _adjust_pwrlevel(&device->pwrctrl, 294: device->pwrctrl.active_pwrlevel, pwrc); 295: pwrc_old = &device->pwrctrl.constraint; 296: 297: /* 298: * If a constraint is already set, set a new constraint only 299: * if it is faster. If the requested constraint is the same 300: * as the current one, update ownership and timestamp. 301: */ 302: if ((pwrc_old->type == KGSL_CONSTRAINT_NONE) || 303: (pwrc_old->sub_type == KGSL_CONSTRAINT_PWR_MIN && 304: pwrc->sub_type == KGSL_CONSTRAINT_PWR_MAX)) { 305: pwrc_old->type = pwrc->type; 306: pwrc_old->sub_type = pwrc->sub_type; 307: pwrc_old->owner_id = id; 308: pwrc_old->expires = jiffies + 309: msecs_to_jiffies(atomic64_read(&device->pwrctrl.interval_timeout)); 310: pwrc_old->owner_timestamp = ts; 311: kgsl_pwrctrl_pwrlevel_change(device, constraint); 312: /* Trace the constraint being set by the driver */ 313: trace_kgsl_constraint(device, pwrc_old->type, constraint, 1, 0); 314: } else if ((pwrc_old->type == pwrc->type) && (pwrc_old->sub_type == pwrc->sub_type)) { 315: pwrc_old->owner_id = id; 316: pwrc_old->owner_timestamp = ts; 317: pwrc_old->expires = jiffies + 318: msecs_to_jiffies(atomic64_read(&device->pwrctrl.interval_timeout)); 319: } 320: } 321: 322: static int kgsl_pwrctrl_set_thermal_limit(struct kgsl_device *device, 323: u32 level) 324: { 325: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 326: int ret = -EINVAL; 327: 328: if (level >= pwr->num_pwrlevels) 329: level = pwr->num_pwrlevels - 1; 330: 331: if (dev_pm_qos_request_active(&pwr->sysfs_thermal_req)) 332: ret = dev_pm_qos_update_request(&pwr->sysfs_thermal_req, 333: (pwr->pwrlevels[level].gpu_freq / 1000)); 334: 335: return (ret < 0) ? ret : 0; 336: } 337: 338: static ssize_t thermal_pwrlevel_store(struct device *dev, 339: struct device_attribute *attr, 340: const char *buf, size_t count) --- FILE: \kgsl_pwrctrl.h | HITS: 3 --- MATCH LINES: 55 43: struct kgsl_clk_stats { 44: unsigned int busy; 45: unsigned int total; 46: unsigned int busy_old; 47: unsigned int total_old; 48: }; 49: 50: struct kgsl_pwr_constraint { 51: unsigned int type; 52: unsigned int sub_type; 53: unsigned long expires; 54: uint32_t owner_id; 55: u32 owner_timestamp; 56: }; 57: 58: /** 59: * struct kgsl_pwrlevel - Struct holding different pwrlevel info obtained 60: * from dtsi file 61: * @gpu_freq: GPU frequency vote in Hz 62: * @bus_freq: Bus bandwidth vote index 63: * @bus_min: Min bus index @gpu_freq 64: * @bus_max: Max bus index @gpu_freq 65: */ 66: struct kgsl_pwrlevel { 67: unsigned int gpu_freq; 68: unsigned int bus_freq; 69: unsigned int bus_min; 70: unsigned int bus_max; 71: unsigned int acd_level; 72: /** @cx_level: CX vote */ 73: u32 cx_level; 74: /** @voltage_level: Voltage level used by the GMU to vote RPMh */ 75: u32 voltage_level; 76: /** @opp: OPP node corresponding to GPU OPP table */ 77: struct dev_pm_opp *opp; 78: }; 79: MATCH LINES: 262, 266 250: * 251: * Block until the active_cnt value hits the desired value 252: */ 253: int kgsl_active_count_wait(struct kgsl_device *device, int count, 254: unsigned long wait_jiffies); 255: void kgsl_pwrctrl_busy_time(struct kgsl_device *device, u64 time, u64 busy, u64 ticks); 256: 257: /** 258: * kgsl_pwrctrl_set_constraint() - Validate and change enforced constraint 259: * @device: Pointer to the kgsl_device struct 260: * @pwrc: Pointer to requested constraint 261: * @id: Context id which owns the constraint 262: * @ts: The timestamp for which this constraint is enforced 263: * 264: * Accept the new constraint if no previous constraint existed or if the 265: * new constraint is faster than the previous one. If the new and previous 266: * constraints are equal, update the timestamp and ownership to make sure 267: * the constraint expires at the correct time. 268: */ 269: void kgsl_pwrctrl_set_constraint(struct kgsl_device *device, 270: struct kgsl_pwr_constraint *pwrc, u32 id, u32 ts); 271: 272: /** 273: * kgsl_pwrctrl_request_state - Request a specific power state 274: * @device: Pointer to the kgsl device 275: * @state: Power state requested 276: */ 277: void kgsl_pwrctrl_request_state(struct kgsl_device *device, u32 state); 278: 279: /** 280: * kgsl_pwrctrl_set_state - Set a specific power state 281: * @device: Pointer to the kgsl device 282: * @state: Power state requested 283: */ 284: void kgsl_pwrctrl_set_state(struct kgsl_device *device, u32 state); 285: 286: /** 287: * kgsl_pwrctrl_axi - Propagate bus votes during slumber entry and exit 288: * @device: Pointer to the kgsl device 289: * @state: Whether we are going to slumber or coming out of slumber 290: * --- FILE: \kgsl_pwrscale.h | HITS: 2 --- MATCH LINES: 31, 35 19: u64 ram_wait; 20: }; 21: 22: /** 23: * struct kgsl_pwrscale - Power scaling settings for a KGSL device 24: * @devfreqptr - Pointer to the devfreq device 25: * @gpu_ro_df - Pointer to the msm-adreno-ro devfreq device 26: * @gpu_profile - GPU profile data for the devfreq device 27: * @bus_profile - Bus specific data for the bus devfreq device 28: * @freq_table - GPU frequencies for the DCVS algorithm 29: * @accum_stats - Accumulated statistics for various frequency calculations 30: * @enabled - Whether or not power scaling is enabled 31: * @time - Last submitted sample timestamp 32: * @devfreq_wq - Main devfreq workqueue 33: * @devfreq_suspend_ws - Pass device suspension to devfreq 34: * @devfreq_resume_ws - Pass device resume to devfreq 35: * @next_governor_call - Timestamp after which the governor may be notified of 36: * a new sample 37: * @ctxt_aware_enable - Whether or not ctxt aware DCVS feature is enabled 38: * @ctxt_aware_busy_penalty - The time in microseconds required to trigger 39: * ctxt aware power level jump 40: * @ctxt_aware_target_pwrlevel - pwrlevel to jump on in case of ctxt aware 41: * power level jump 42: */ 43: struct kgsl_pwrscale { 44: struct devfreq *devfreqptr; 45: struct devfreq *gpu_ro_df; 46: struct msm_adreno_extended_profile gpu_profile; 47: struct msm_busmon_extended_profile bus_profile; 48: unsigned long freq_table[KGSL_MAX_PWRLEVELS]; 49: struct kgsl_power_stats accum_stats; 50: bool enabled; 51: ktime_t time; 52: struct workqueue_struct *devfreq_wq; 53: struct work_struct devfreq_suspend_ws; 54: struct work_struct devfreq_resume_ws; 55: /** @devfreq_notify_worker: kthread worker to handle devfreq notify event */ 56: struct kthread_worker *devfreq_notify_worker; 57: /** @devfreq_notify_work: work struct to update devfreq as per request */ 58: struct kthread_work devfreq_notify_work; 59: ktime_t next_governor_call; --- FILE: \kgsl_snapshot.c | HITS: 12 --- MATCH LINES: 609, 613 597: /* 598: * Trigger both GPU and GMU snapshot. GPU specific code 599: * will take care of whether to dumps full state or only 600: * GMU state based on current GPU power state. 601: */ 602: if (device->ftbl->snapshot) 603: device->ftbl->snapshot(device, snapshot, NULL, NULL); 604: 605: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_EVENTLOG, 606: snapshot, kgsl_snapshot_eventlog_buffer, NULL); 607: 608: /* 609: * The timestamp is the seconds since boot so it is easier to match to 610: * the kernel log 611: */ 612: getboottime64(&boot); 613: snapshot->timestamp = ktime_get_real_seconds() - boot.tv_sec; 614: 615: kgsl_add_to_minidump("ATOMIC_GPU_SNAPSHOT", (u64) device->snapshot_memory_atomic.ptr, 616: atomic_snapshot_phy_addr(device), device->snapshot_memory_atomic.size); 617: 618: /* log buffer info to aid in ramdump fault tolerance */ 619: dev_err(device->dev, "Atomic GPU snapshot created at pa %llx++0x%zx\n", 620: atomic_snapshot_phy_addr(device), snapshot->size); 621: } 622: 623: /** 624: * kgsl_device_snapshot() - construct a device snapshot 625: * @device: device to snapshot 626: * @context: the context that is hung, might be NULL if unknown. 627: * @context_lpac: the lpac context that is hung, might be NULL if unknown. 628: * @gmu_fault: whether this snapshot is triggered by a GMU fault. 629: * 630: * Given a device, construct a binary snapshot dump of the current device state 631: * and store it in the device snapshot memory. 632: */ 633: void kgsl_device_snapshot(struct kgsl_device *device, 634: struct kgsl_context *context, struct kgsl_context *context_lpac, 635: bool gmu_fault) 636: { 637: struct kgsl_snapshot *snapshot; MATCH LINES: 705, 710, 727 693: snapshot->ptr = device->snapshot_memory.ptr; 694: snapshot->remain = device->snapshot_memory.size; 695: snapshot->recovered = false; 696: snapshot->first_read = true; 697: snapshot->sysfs_read = 0; 698: 699: device->ftbl->snapshot(device, snapshot, context, context_lpac); 700: 701: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_EVENTLOG, 702: snapshot, kgsl_snapshot_eventlog_buffer, NULL); 703: 704: /* 705: * The timestamp is the seconds since boot so it is easier to match to 706: * the kernel log 707: */ 708: 709: getboottime64(&boot); 710: snapshot->timestamp = ktime_get_real_seconds() - boot.tv_sec; 711: 712: /* Store the instance in the device until it gets dumped */ 713: device->snapshot = snapshot; 714: snapshot->device = device; 715: 716: /* log buffer info to aid in ramdump fault tolerance */ 717: dev_err(device->dev, "%s snapshot created at pa %llx++0x%zx\n", 718: gmu_fault ? "GMU" : "GPU", snapshot_phy_addr(device), 719: snapshot->size); 720: 721: kgsl_add_to_minidump("GPU_SNAPSHOT", (u64) device->snapshot_memory.ptr, 722: snapshot_phy_addr(device), device->snapshot_memory.size); 723: 724: if (device->skip_ib_capture) 725: BUG_ON(device->force_panic); 726: 727: sysfs_notify(&device->snapshot_kobj, NULL, "timestamp"); 728: 729: /* 730: * Queue a work item that will save the IB data in snapshot into 731: * static memory to prevent loss of data due to overwriting of 732: * memory. If force panic is enabled, there is no need to move 733: * ahead and IB data can be dumped inline. 734: */ 735: if (device->force_panic) 736: kgsl_snapshot_save_frozen_objs(&snapshot->work); 737: else 738: kgsl_schedule_work(&snapshot->work); 739: } 740: 741: /* An attribute for showing snapshot details */ 742: struct kgsl_snapshot_attribute { 743: struct attribute attr; 744: ssize_t (*show)(struct kgsl_device *device, char *buf); 745: ssize_t (*store)(struct kgsl_device *device, const char *buf, 746: size_t count); 747: }; 748: 749: /** 750: * kgsl_snapshot_process_ib_obj_list() - Go through the list of IB's which need 751: * to be dumped for snapshot and move them to the global snapshot list so MATCH LINES: 1000, 1001, 1003, 1006, 1008, 1039 988: 989: 990: /* Store the value to snapshot_crashdumper*/ 991: static ssize_t snapshot_crashdumper_store(struct kgsl_device *device, 992: const char *buf, size_t count) 993: { 994: int ret; 995: 996: ret = kstrtobool(buf, &device->snapshot_crashdumper); 997: return ret ? ret : count; 998: } 999: 1000: /* Show the timestamp of the last collected snapshot */ 1001: static ssize_t timestamp_show(struct kgsl_device *device, char *buf) 1002: { 1003: unsigned long timestamp; 1004: 1005: kgsl_mutex_lock(&device->mutex); 1006: timestamp = device->snapshot ? device->snapshot->timestamp : 0; 1007: kgsl_mutex_unlock(&device->mutex); 1008: return scnprintf(buf, PAGE_SIZE, "%lu\n", timestamp); 1009: } 1010: 1011: static ssize_t snapshot_legacy_show(struct kgsl_device *device, char *buf) 1012: { 1013: return scnprintf(buf, PAGE_SIZE, "%d\n", device->snapshot_legacy); 1014: } 1015: 1016: static ssize_t snapshot_legacy_store(struct kgsl_device *device, 1017: const char *buf, size_t count) 1018: { 1019: int ret; 1020: 1021: ret = kstrtobool(buf, &device->snapshot_legacy); 1022: return ret ? ret : count; 1023: } 1024: 1025: static struct bin_attribute snapshot_attr = { 1026: .attr.name = "dump", 1027: .attr.mode = 0444, 1028: .size = 0, 1029: .read = snapshot_show 1030: }; 1031: 1032: #define SNAPSHOT_ATTR(_name, _mode, _show, _store) \ 1033: struct kgsl_snapshot_attribute attr_##_name = { \ 1034: .attr = { .name = __stringify(_name), .mode = _mode }, \ 1035: .show = _show, \ 1036: .store = _store, \ 1037: } 1038: 1039: static SNAPSHOT_ATTR(timestamp, 0444, timestamp_show, NULL); 1040: static SNAPSHOT_ATTR(faultcount, 0644, faultcount_show, faultcount_store); 1041: static SNAPSHOT_ATTR(force_panic, 0644, force_panic_show, force_panic_store); 1042: static SNAPSHOT_ATTR(prioritize_unrecoverable, 0644, 1043: prioritize_unrecoverable_show, prioritize_unrecoverable_store); 1044: static SNAPSHOT_ATTR(snapshot_crashdumper, 0644, snapshot_crashdumper_show, 1045: snapshot_crashdumper_store); 1046: static SNAPSHOT_ATTR(snapshot_legacy, 0644, snapshot_legacy_show, 1047: snapshot_legacy_store); 1048: static SNAPSHOT_ATTR(skip_ib_capture, 0644, skip_ib_capture_show, 1049: skip_ib_capture_store); 1050: 1051: static ssize_t snapshot_sysfs_show(struct kobject *kobj, 1052: struct attribute *attr, char *buf) 1053: { 1054: struct kgsl_snapshot_attribute *pattr = to_snapshot_attr(attr); 1055: struct kgsl_device *device = kobj_to_device(kobj); 1056: ssize_t ret; 1057: 1058: if (device && pattr->show) 1059: ret = pattr->show(device, buf); 1060: else 1061: ret = -EIO; 1062: 1063: return ret; MATCH LINES: 1089 1077: } 1078: 1079: static const struct sysfs_ops snapshot_sysfs_ops = { 1080: .show = snapshot_sysfs_show, 1081: .store = snapshot_sysfs_store, 1082: }; 1083: 1084: static struct kobj_type ktype_snapshot = { 1085: .sysfs_ops = &snapshot_sysfs_ops, 1086: }; 1087: 1088: static const struct attribute *snapshot_attrs[] = { 1089: &attr_timestamp.attr, 1090: &attr_faultcount.attr, 1091: &attr_force_panic.attr, 1092: &attr_prioritize_unrecoverable.attr, 1093: &attr_snapshot_crashdumper.attr, 1094: &attr_snapshot_legacy.attr, 1095: &attr_skip_ib_capture.attr, 1096: NULL, 1097: }; 1098: 1099: static int kgsl_panic_notifier_callback(struct notifier_block *nb, 1100: unsigned long action, void *unused) 1101: { 1102: struct kgsl_device *device = container_of(nb, struct kgsl_device, 1103: panic_nb); 1104: 1105: /* To send NMI to GMU */ 1106: device->gmu_fault = gmu_core_isenabled(device); 1107: 1108: kgsl_device_snapshot_atomic(device); 1109: 1110: return NOTIFY_OK; 1111: } 1112: 1113: static ssize_t kgsl_devcoredump_read(char *buf, loff_t off, --- FILE: \kgsl_snapshot.h | HITS: 7 --- MATCH LINES: 73, 99, 100, 101, 112, 113, 144 61: #define KGSL_SNAPSHOT_SECTION_SIDE_DEBUGBUS 0x1801 62: #define KGSL_SNAPSHOT_SECTION_TRACE_BUFFER 0x1901 63: #define KGSL_SNAPSHOT_SECTION_EVENTLOG 0x1A01 64: 65: #define KGSL_SNAPSHOT_SECTION_END 0xFFFF 66: 67: /* OS sub-section header */ 68: #define KGSL_SNAPSHOT_OS_LINUX_V4 0x00000203 69: 70: /* Linux OS specific information */ 71: struct kgsl_snapshot_linux_v4 { 72: int osid; /* subsection OS identifier */ 73: __u32 seconds; /* Unix timestamp for the snapshot */ 74: __u32 power_flags; /* Current power flags */ 75: __u32 power_level; /* Current power level */ 76: __u32 power_interval_timeout; /* Power interval timeout */ 77: __u32 grpclk; /* Current GP clock value */ 78: __u32 busclk; /* Current busclk value */ 79: __u64 ptbase; /* Current ptbase */ 80: __u64 ptbase_lpac; /* Current LPAC ptbase */ 81: __u32 pid; /* PID of the process that owns the PT */ 82: __u32 pid_lpac; /* PID of the LPAC process that owns the PT */ 83: __u32 current_context; /* ID of the current context */ 84: __u32 current_context_lpac; /* ID of the current LPAC context */ 85: __u32 ctxtcount; /* Number of contexts appended to section */ 86: unsigned char release[32]; /* kernel release */ 87: unsigned char version[32]; /* kernel version */ 88: unsigned char comm[16]; /* Name of the process that owns the PT */ 89: unsigned char comm_lpac[16]; /* Name of the LPAC process that owns the PT */ 90: } __packed; 91: 92: /* 93: * This structure contains a record of an active context. 94: * These are appended one after another in the OS section below 95: * the header above 96: */ 97: struct kgsl_snapshot_linux_context_v2 { 98: __u32 id; /* The context ID */ 99: __u32 timestamp_queued; /* The last queued timestamp */ 100: __u32 timestamp_consumed; /* The last timestamp consumed by HW */ 101: __u32 timestamp_retired; /* The last timestamp retired by HW */ 102: }; 103: 104: /* Ringbuffer sub-section header */ 105: struct kgsl_snapshot_rb_v2 { 106: int start; /* dword at the start of the dump */ 107: int end; /* dword at the end of the dump */ 108: int rbsize; /* Size (in dwords) of the ringbuffer */ 109: int wptr; /* Current index of the CPU write pointer */ 110: int rptr; /* Current index of the GPU read pointer */ 111: int count; /* Number of dwords in the dump */ 112: __u32 timestamp_queued; /* The last queued timestamp */ 113: __u32 timestamp_retired; /* The last timestamp retired by HW */ 114: __u64 gpuaddr; /* The GPU address of the ringbuffer */ 115: __u32 id; /* Ringbuffer identifier */ 116: } __packed; 117: 118: /* Replay or Memory list section, both sections have same header */ 119: struct kgsl_snapshot_mem_list_v2 { 120: /* 121: * Number of IBs to replay for replay section or 122: * number of memory list entries for mem list section 123: */ 124: int num_entries; 125: /* Pagetable base to which the replay IBs or memory entries belong */ 126: __u64 ptbase; 127: } __packed; 128: 129: /* Indirect buffer sub-section header (v2) */ 130: struct kgsl_snapshot_ib_v2 { 131: __u64 gpuaddr; /* GPU address of the IB */ 132: __u64 ptbase; /* Base for the pagetable the GPU address is valid in */ 133: __u64 size; /* Size of the IB */ 134: } __packed; 135: 136: /* GMU memory ID's */ 137: #define SNAPSHOT_GMU_MEM_UNKNOWN 0x00 138: #define SNAPSHOT_GMU_MEM_HFI 0x01 139: #define SNAPSHOT_GMU_MEM_LOG 0x02 140: #define SNAPSHOT_GMU_MEM_BWTABLE 0x03 141: #define SNAPSHOT_GMU_MEM_DEBUG 0x04 142: #define SNAPSHOT_GMU_MEM_BIN_BLOCK 0x05 143: #define SNAPSHOT_GMU_MEM_CONTEXT_QUEUE 0x06 144: #define SNAPSHOT_GMU_MEM_HW_FENCE 0x07 145: #define SNAPSHOT_GMU_MEM_WARMBOOT 0x08 146: #define SNAPSHOT_GMU_MEM_VRB 0x09 147: #define SNAPSHOT_GMU_MEM_TRACE 0x0a 148: 149: /* GMU memory section data */ 150: struct kgsl_snapshot_gmu_mem { 151: int type; 152: uint64_t hostaddr; 153: uint64_t gmuaddr; 154: uint64_t gpuaddr; 155: } __packed; 156: 157: /* Register sub-section header */ 158: struct kgsl_snapshot_regs { 159: __u32 count; /* Number of register pairs in the section */ 160: } __packed; 161: 162: /* Indexed register sub-section header */ 163: struct kgsl_snapshot_indexed_regs { 164: __u32 index_reg; /* Offset of the index register for this section */ 165: __u32 data_reg; /* Offset of the data register for this section */ 166: int start; /* Starting index */ 167: int count; /* Number of dwords in the data */ 168: } __packed; --- FILE: \kgsl_sync.c | HITS: 365 --- MATCH LINES: 16, 17, 22, 23, 24, 25, 27, 28, 30, 32, 33, 34, 42, 43, 45, 49, 51, 54, 58, 63, 69, 70, 75, 77, 82, 89, 94, 95, 96, 100, 105, 106, 111, 117, 120, 125, 126, 134, 135, 144, 147, 148, 165, 171, 173, 176, 177, 179, 182, 186, 188, 191, 193, 196, 198, 199, 202, 204, 210, 212, 215, 216, 218, 219, 220, 222, 227, 229, 230, 232, 233, 234, 235, 239, 240, 245, 247, 249, 252, 254, 255, 256, 259, 261, 264, 265, 267, 270, 271, 275, 280, 283, 288, 289, 298, 300, 301, 302, 319, 325, 327, 331, 333, 337, 338, 342, 346, 348, 351, 353, 356, 358, 363, 365, 367, 375, 376, 381, 382, 383, 385, 386, 389, 390, 392, 394, 397, 402, 405, 408, 410, 412, 413, 415, 416, 420, 422, 423, 424, 426, 429, 431, 434, 436, 440, 441, 446, 449, 452, 454, 459, 460, 462, 479, 481, 482, 493, 495, 496, 497, 498, 500, 504, 506, 507, 508, 512, 513, 516, 517, 520, 522, 527, 540, 541, 546, 547, 550, 551, 556, 557, 558, 561, 563, 569, 580, 582, 587, 588, 590, 591, 594, 596, 602, 604, 605, 610, 611, 613, 626, 627, 628, 630, 631, 633, 634, 640, 641, 647, 650, 652, 655, 660, 662, 663, 689, 690, 707, 710, 716, 717, 719, 721, 722, 723, 757, 758, 761, 762, 763, 766, 771, 772, 774, 779, 781, 787, 789, 791, 792, 793, 796, 799, 801, 803, 805, 806, 807, 810, 813, 816, 821, 823, 824, 826, 831, 832, 833, 839, 840, 845, 848, 851, 855, 859, 862, 864, 870, 874, 877, 879, 882, 884, 891, 896, 900, 902, 903, 904, 905, 908, 910, 912, 913, 915, 916, 922, 924, 927, 929, 930, 931, 933, 935, 940, 941, 944, 947, 948, 951, 952, 958, 962, 967, 968, 972, 976, 983, 985, 990, 1002, 1003 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include 8: #include 9: #include 10: #include 11: 12: #include "kgsl_device.h" 13: #include "kgsl_gmu_core.h" 14: #include "kgsl_sync.h" 15: 16: const struct dma_fence_ops kgsl_sync_fence_ops; 17: static const struct dma_fence_ops kgsl_syncsource_fence_ops; 18: 19: /* Only allow a single log in a second */ 20: static DEFINE_RATELIMIT_STATE(_rs, HZ, 1); 21: 22: /* List of hardware fences that haven't been destroyed */ 23: struct list_head hw_fence_list; 24: /* Spinlock to protect access to hw_fence_list */ 25: spinlock_t hw_fence_list_lock; 26: 27: static void destroy_all_hw_fences(void); 28: static void _hw_fence_destroy(struct kgsl_sync_fence *kfence); 29: 30: static inline void add_hw_fence(struct kgsl_sync_fence *kfence) 31: { 32: spin_lock(&hw_fence_list_lock); 33: list_add_tail(&kfence->hw_fence_list, &hw_fence_list); 34: spin_unlock(&hw_fence_list_lock); 35: } 36: 37: #ifdef CONFIG_QCOM_KGSL_SYNX 38: 39: #include 40: #include 41: 42: static struct synx_hw_fence_descriptor { 43: /** @handle: Handle for hardware fences */ 44: struct synx_session *handle; 45: /** @descriptor: Memory descriptor for hardware fences */ 46: struct synx_queue_desc mem_descriptor; 47: } kgsl_synx; 48: 49: int kgsl_hw_fence_soccp_vote(bool pwr_on) 50: { 51: return synx_enable_resources(SYNX_CLIENT_HW_FENCE_GFX_CTX0, SYNX_RESOURCE_SOCCP, pwr_on); 52: } 53: 54: int kgsl_hw_fence_init(struct kgsl_device *device) 55: { 56: struct synx_initialization_params params; 57: 58: params.id = (enum synx_client_id)SYNX_CLIENT_HW_FENCE_GFX_CTX0; 59: params.ptr = &kgsl_synx.mem_descriptor; 60: kgsl_synx.handle = synx_initialize(¶ms); 61: 62: if (IS_ERR_OR_NULL(kgsl_synx.handle)) { 63: dev_err(device->dev, "HW fences not supported: %d\n", 64: PTR_ERR_OR_ZERO(kgsl_synx.handle)); 65: kgsl_synx.handle = NULL; 66: return -EINVAL; 67: } 68: 69: INIT_LIST_HEAD(&hw_fence_list); 70: spin_lock_init(&hw_fence_list_lock); 71: 72: return 0; 73: } 74: 75: void kgsl_hw_fence_close(struct kgsl_device *device) 76: { 77: destroy_all_hw_fences(); 78: 79: synx_uninitialize(kgsl_synx.handle); 80: } 81: 82: void kgsl_hw_fence_populate_md(struct kgsl_device *device, struct kgsl_memdesc *md) 83: { 84: md->physaddr = kgsl_synx.mem_descriptor.dev_addr; 85: md->size = kgsl_synx.mem_descriptor.size; 86: md->hostptr = kgsl_synx.mem_descriptor.vaddr; 87: } 88: 89: int kgsl_hw_fence_create(struct kgsl_device *device, struct kgsl_sync_fence *kfence) 90: { 91: struct synx_create_params params = {0}; 92: int ret; 93: 94: params.fence = &kfence->fence; 95: params.h_synx = (u32 *)&kfence->hw_fence_index; 96: params.flags = SYNX_CREATE_DMA_FENCE; 97: 98: ret = synx_create(kgsl_synx.handle, ¶ms); 99: if (!ret) { 100: add_hw_fence(kfence); 101: return 0; 102: } 103: 104: if (__ratelimit(&_rs)) 105: dev_err(device->dev, "Failed to create ctx:%d ts:%d hardware fence:%d\n", 106: kfence->context_id, kfence->timestamp, ret); 107: 108: return -EINVAL; 109: } 110: 111: int kgsl_hw_fence_add_waiter(struct kgsl_device *device, struct dma_fence *fence, u32 *hash_index) 112: { 113: struct synx_import_params params; 114: u32 handle = 0; 115: int ret; 116: 117: params.indv.fence = fence; 118: params.type = SYNX_IMPORT_INDV_PARAMS; 119: params.indv.new_h_synx = &handle; 120: params.indv.flags = SYNX_IMPORT_DMA_FENCE; 121: 122: ret = synx_import(kgsl_synx.handle, ¶ms); 123: if (ret) { 124: dev_err_ratelimited(device->dev, 125: "Failed to add GMU as waiter ret:%d fence ctx:%llu ts:%llu\n", 126: ret, fence->context, fence->seqno); 127: return ret; 128: } 129: 130: /* release reference held by synx_import */ 131: ret = synx_release(kgsl_synx.handle, handle); 132: if (ret) { 133: dev_err_ratelimited(device->dev, 134: "Failed to release wait fences ret:%d fence ctx:%llu ts:%llu\n", 135: ret, fence->context, fence->seqno); 136: } else { 137: if (hash_index) 138: *hash_index = handle; 139: } 140: 141: return ret; 142: } 143: 144: bool kgsl_hw_fence_tx_slot_available(struct kgsl_device *device, u32 pending_hw_fence_count) 145: { 146: void *ptr = kgsl_synx.mem_descriptor.vaddr; 147: struct synx_hw_fence_hfi_queue_header *hdr = (struct synx_hw_fence_hfi_queue_header *) 148: (ptr + sizeof(struct synx_hw_fence_hfi_queue_table_header)); 149: u32 queue_size_dwords = hdr->queue_size / sizeof(u32); 150: u32 payload_size_dwords = hdr->pkt_size / sizeof(u32); 151: u32 free_entries, write_idx = hdr->write_index, read_idx = hdr->read_index; 152: 153: free_entries = read_idx <= write_idx ? 154: queue_size_dwords - (write_idx - read_idx) : 155: read_idx - write_idx; 156: 157: free_entries /= payload_size_dwords; 158: 159: /* Ensure free_entries does not become negative */ 160: if (free_entries == 0) 161: return false; 162: 163: free_entries -= 1; 164: 165: if (free_entries > pending_hw_fence_count) 166: return true; 167: 168: return false; 169: } 170: 171: void _hw_fence_destroy(struct kgsl_sync_fence *kfence) 172: { 173: synx_release(kgsl_synx.handle, kfence->hw_fence_index); 174: 175: /* 176: * synx_release() doesn't have a way to get to the dma fence. Hence, the client must clear 177: * this bit from the dma fence flags. 178: */ 179: clear_bit(SYNX_HW_FENCE_FLAG_ENABLED_BIT, &kfence->fence.flags); 180: } 181: 182: void kgsl_hw_fence_trigger_cpu(struct kgsl_device *device, struct kgsl_sync_fence *kfence) 183: { 184: /* soccp should be powered on */ 185: WARN_RATELIMIT(!test_bit(GMU_SOCCP_VOTE_ON, &device->gmu_core.flags), 186: "signaling hw fence via cpu without soccp powered up\n"); 187: 188: synx_signal(kgsl_synx.handle, (u32)kfence->hw_fence_index, SYNX_STATE_SIGNALED_SUCCESS); 189: } 190: 191: bool kgsl_hw_fence_signaled(struct dma_fence *fence) 192: { 193: return test_bit(SYNX_HW_FENCE_FLAG_SIGNALED_BIT, &fence->flags); 194: } 195: 196: static bool kgsl_is_input_hw_fence(struct dma_fence *fence) 197: { 198: return test_bit(SYNX_HW_FENCE_FLAG_ENABLED_BIT, &fence->flags) || 199: test_bit(SYNX_NATIVE_FENCE_FLAG_ENABLED_BIT, &fence->flags) || is_kgsl_fence(fence); 200: } 201: 202: static bool kgsl_is_output_hw_fence(struct dma_fence *fence) 203: { 204: return test_bit(SYNX_HW_FENCE_FLAG_ENABLED_BIT, &fence->flags); 205: } 206: 207: #else 208: 209: #if (KERNEL_VERSION(6, 3, 0) <= LINUX_VERSION_CODE) 210: #include 211: #else 212: #include 213: #endif 214: 215: static struct msm_hw_fence_descriptor { 216: /** @handle: Handle for hardware fences */ 217: void *handle; 218: /** @descriptor: Memory descriptor for hardware fences */ 219: struct msm_hw_fence_mem_addr mem_descriptor; 220: } kgsl_msm_hw_fence; 221: 222: int kgsl_hw_fence_soccp_vote(bool pwr_on) 223: { 224: return -EINVAL; 225: } 226: 227: int kgsl_hw_fence_init(struct kgsl_device *device) 228: { 229: kgsl_msm_hw_fence.handle = msm_hw_fence_register(HW_FENCE_CLIENT_ID_CTX0, 230: &kgsl_msm_hw_fence.mem_descriptor); 231: 232: if (IS_ERR_OR_NULL(kgsl_msm_hw_fence.handle)) { 233: dev_err(device->dev, "HW fences not supported: %d\n", 234: PTR_ERR_OR_ZERO(kgsl_msm_hw_fence.handle)); 235: kgsl_msm_hw_fence.handle = NULL; 236: return -EINVAL; 237: } 238: 239: INIT_LIST_HEAD(&hw_fence_list); 240: spin_lock_init(&hw_fence_list_lock); 241: 242: return 0; 243: } 244: 245: void kgsl_hw_fence_close(struct kgsl_device *device) 246: { 247: destroy_all_hw_fences(); 248: 249: msm_hw_fence_deregister(kgsl_msm_hw_fence.handle); 250: } 251: 252: void kgsl_hw_fence_populate_md(struct kgsl_device *device, struct kgsl_memdesc *md) 253: { 254: md->physaddr = kgsl_msm_hw_fence.mem_descriptor.device_addr; 255: md->size = kgsl_msm_hw_fence.mem_descriptor.size; 256: md->hostptr = kgsl_msm_hw_fence.mem_descriptor.virtual_addr; 257: } 258: 259: int kgsl_hw_fence_create(struct kgsl_device *device, struct kgsl_sync_fence *kfence) 260: { 261: struct msm_hw_fence_create_params params = {0}; 262: int ret; 263: 264: params.fence = &kfence->fence; 265: params.handle = &kfence->hw_fence_index; 266: 267: ret = msm_hw_fence_create(kgsl_msm_hw_fence.handle, ¶ms); 268: if ((ret || IS_ERR_OR_NULL(params.handle))) { 269: if (__ratelimit(&_rs)) 270: dev_err(device->dev, "Failed to create ctx:%d ts:%d hardware fence:%d\n", 271: kfence->context_id, kfence->timestamp, ret); 272: return -EINVAL; 273: } 274: 275: add_hw_fence(kfence); 276: 277: return 0; 278: } 279: 280: int kgsl_hw_fence_add_waiter(struct kgsl_device *device, struct dma_fence *fence, u32 *hash_index) 281: { 282: u64 handle = 0; 283: int ret = msm_hw_fence_wait_update_v2(kgsl_msm_hw_fence.handle, &fence, &handle, NULL, 1, 284: true); 285: 286: if (ret) 287: dev_err_ratelimited(device->dev, 288: "Failed to add GMU as waiter ret:%d fence ctx:%llu ts:%llu\n", 289: ret, fence->context, fence->seqno); 290: else { 291: if (hash_index) 292: *hash_index = (u32)handle; 293: } 294: 295: return ret; 296: } 297: 298: bool kgsl_hw_fence_tx_slot_available(struct kgsl_device *device, u32 pending_hw_fence_count) 299: { 300: void *ptr = kgsl_msm_hw_fence.mem_descriptor.virtual_addr; 301: struct msm_hw_fence_hfi_queue_header *hdr = (struct msm_hw_fence_hfi_queue_header *) 302: (ptr + sizeof(struct msm_hw_fence_hfi_queue_table_header)); 303: u32 queue_size_dwords = hdr->queue_size / sizeof(u32); 304: u32 payload_size_dwords = hdr->pkt_size / sizeof(u32); 305: u32 free_entries, write_idx = hdr->write_index, read_idx = hdr->read_index; 306: 307: free_entries = read_idx <= write_idx ? 308: queue_size_dwords - (write_idx - read_idx) : 309: read_idx - write_idx; 310: 311: free_entries /= payload_size_dwords; 312: 313: /* Ensure free_entries does not become negative */ 314: if (free_entries == 0) 315: return false; 316: 317: free_entries -= 1; 318: 319: if (free_entries > pending_hw_fence_count) 320: return true; 321: 322: return false; 323: } 324: 325: void _hw_fence_destroy(struct kgsl_sync_fence *kfence) 326: { 327: msm_hw_fence_destroy(kgsl_msm_hw_fence.handle, &kfence->fence); 328: } 329: 330: #define IPCC_GPU_PHYS_ID 4 331: void kgsl_hw_fence_trigger_cpu(struct kgsl_device *device, struct kgsl_sync_fence *kfence) 332: { 333: int ret = msm_hw_fence_update_txq(kgsl_msm_hw_fence.handle, kfence->hw_fence_index, 334: 0, 0); 335: if (ret) { 336: dev_err_ratelimited(device->dev, 337: "Failed to trigger hw fence via cpu: ctx:%d ts:%d ret:%d\n", 338: kfence->context_id, kfence->timestamp, ret); 339: return; 340: } 341: 342: msm_hw_fence_trigger_signal(kgsl_msm_hw_fence.handle, IPCC_GPU_PHYS_ID, 343: IPCC_CLIENT_APSS, 0); 344: } 345: 346: bool kgsl_hw_fence_signaled(struct dma_fence *fence) 347: { 348: return test_bit(MSM_HW_FENCE_FLAG_SIGNALED_BIT, &fence->flags); 349: } 350: 351: static bool kgsl_is_output_hw_fence(struct dma_fence *fence) 352: { 353: return test_bit(MSM_HW_FENCE_FLAG_ENABLED_BIT, &fence->flags); 354: } 355: 356: static bool kgsl_is_input_hw_fence(struct dma_fence *fence) 357: { 358: return test_bit(MSM_HW_FENCE_FLAG_ENABLED_BIT, &fence->flags); 359: } 360: 361: #endif 362: 363: static struct kgsl_sync_fence *kgsl_sync_fence_create( 364: struct kgsl_context *context, 365: unsigned int timestamp) 366: { 367: struct kgsl_sync_fence *kfence; 368: struct kgsl_sync_timeline *ktimeline = context->ktimeline; 369: unsigned long flags; 370: 371: /* Get a refcount to the timeline. Put when released */ 372: if (!kref_get_unless_zero(&ktimeline->kref)) 373: return NULL; 374: 375: kfence = kzalloc(sizeof(*kfence), GFP_KERNEL); 376: if (kfence == NULL) { 377: kgsl_sync_timeline_put(ktimeline); 378: return NULL; 379: } 380: 381: kfence->parent = ktimeline; 382: kfence->context_id = context->id; 383: kfence->timestamp = timestamp; 384: 385: dma_fence_init(&kfence->fence, &kgsl_sync_fence_ops, &ktimeline->lock, 386: ktimeline->fence_context, timestamp); 387: 388: /* 389: * sync_file_create() takes a refcount to the fence. This refcount is 390: * put when the fence is signaled. 391: */ 392: kfence->sync_file = sync_file_create(&kfence->fence); 393: 394: if (kfence->sync_file == NULL) { 395: kgsl_sync_timeline_put(ktimeline); 396: dev_err(context->device->dev, "Create sync_file failed\n"); 397: kfree(kfence); 398: return NULL; 399: } 400: 401: spin_lock_irqsave(&ktimeline->lock, flags); 402: list_add_tail(&kfence->child_list, &ktimeline->child_list_head); 403: spin_unlock_irqrestore(&ktimeline->lock, flags); 404: 405: return kfence; 406: } 407: 408: static void kgsl_sync_fence_release(struct dma_fence *fence) 409: { 410: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)fence; 411: 412: if (kgsl_is_output_hw_fence(fence)) 413: kgsl_hw_fence_destroy(kfence); 414: 415: kgsl_sync_timeline_put(kfence->parent); 416: kfree(kfence); 417: } 418: 419: /* Called with ktimeline->lock held */ 420: static bool kgsl_sync_fence_has_signaled(struct dma_fence *fence) 421: { 422: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)fence; 423: struct kgsl_sync_timeline *ktimeline = kfence->parent; 424: unsigned int ts = kfence->timestamp; 425: 426: return (timestamp_cmp(ktimeline->last_timestamp, ts) >= 0); 427: } 428: 429: static bool kgsl_enable_signaling(struct dma_fence *fence) 430: { 431: return !kgsl_sync_fence_has_signaled(fence); 432: } 433: 434: struct kgsl_sync_fence_event_priv { 435: struct kgsl_context *context; 436: unsigned int timestamp; 437: }; 438: 439: /** 440: * kgsl_sync_fence_event_cb - Event callback for a fence timestamp event 441: * @device - The KGSL device that expired the timestamp 442: * @context- Pointer to the context that owns the event 443: * @priv: Private data for the callback 444: * @result - Result of the event (retired or canceled) 445: * 446: * Signal a fence following the expiration of a timestamp 447: */ 448: 449: static void kgsl_sync_fence_event_cb(struct kgsl_device *device, 450: struct kgsl_event_group *group, void *priv, int result) 451: { 452: struct kgsl_sync_fence_event_priv *ev = priv; 453: 454: kgsl_sync_timeline_signal(ev->context->ktimeline, ev->timestamp); 455: kgsl_context_put(ev->context); 456: kfree(ev); 457: } 458: 459: static int _add_fence_event(struct kgsl_device *device, 460: struct kgsl_context *context, unsigned int timestamp) 461: { 462: struct kgsl_sync_fence_event_priv *event; 463: int ret; 464: 465: event = kmalloc(sizeof(*event), GFP_KERNEL); 466: if (event == NULL) 467: return -ENOMEM; 468: 469: /* 470: * Increase the refcount for the context to keep it through the 471: * callback 472: */ 473: if (!_kgsl_context_get(context)) { 474: kfree(event); 475: return -ENOENT; 476: } 477: 478: event->context = context; 479: event->timestamp = timestamp; 480: 481: ret = kgsl_add_event(device, &context->events, timestamp, 482: kgsl_sync_fence_event_cb, event); 483: 484: if (ret) { 485: kgsl_context_put(context); 486: kfree(event); 487: } 488: 489: return ret; 490: } 491: 492: /* Only to be used if creating a related event failed */ 493: static void kgsl_sync_cancel(struct kgsl_sync_fence *kfence) 494: { 495: spin_lock(&kfence->parent->lock); 496: if (!list_empty(&kfence->child_list)) { 497: list_del_init(&kfence->child_list); 498: dma_fence_put(&kfence->fence); 499: } 500: spin_unlock(&kfence->parent->lock); 501: } 502: 503: /** 504: * kgsl_add_fence_event - Create a new fence event 505: * @device - KGSL device to create the event on 506: * @timestamp - Timestamp to trigger the event 507: * @data - Return fence fd stored in struct kgsl_timestamp_event_fence 508: * @len - length of the fence event 509: * @owner - driver instance that owns this event 510: * @returns 0 on success or error code on error 511: * 512: * Create a fence and register an event to signal the fence when 513: * the timestamp expires 514: */ 515: 516: int kgsl_add_fence_event(struct kgsl_device *device, 517: u32 context_id, u32 timestamp, void __user *data, int len, 518: struct kgsl_device_private *owner) 519: { 520: struct kgsl_timestamp_event_fence priv; 521: struct kgsl_context *context; 522: struct kgsl_sync_fence *kfence = NULL; 523: int ret = -EINVAL; 524: unsigned int cur; 525: bool retired = false; 526: 527: priv.fence_fd = -1; 528: 529: if (len != sizeof(priv)) 530: return -EINVAL; 531: 532: context = kgsl_context_get_owner(owner, context_id); 533: 534: if (context == NULL) 535: return -EINVAL; 536: 537: if (test_bit(KGSL_CONTEXT_PRIV_INVALID, &context->priv)) 538: goto out; 539: 540: kfence = kgsl_sync_fence_create(context, timestamp); 541: if (kfence == NULL) { 542: ret = -ENOMEM; 543: goto out; 544: } 545: 546: priv.fence_fd = get_unused_fd_flags(0); 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 594: * kfence->fence as well. 595: */ 596: fput(kfence->sync_file->file); 597: } 598: } 599: return ret; 600: } 601: 602: void kgsl_sync_timeline_value_str(struct dma_fence *fence, char *str, int size) 603: { 604: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)fence; 605: struct kgsl_sync_timeline *ktimeline = kfence->parent; 606: struct kgsl_context *context = NULL; 607: unsigned long flags; 608: int ret = 0; 609: 610: unsigned int timestamp_retired; 611: unsigned int timestamp_queued; 612: 613: if (fence->ops != &kgsl_sync_fence_ops) 614: return; 615: 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, ×tamp_retired); 632: 633: kgsl_readtimestamp(ktimeline->device, context, 634: KGSL_TIMESTAMP_QUEUED, ×tamp_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; 666: } 667: 668: int kgsl_sync_timeline_create(struct kgsl_context *context) 669: { 670: struct kgsl_sync_timeline *ktimeline; 671: 672: /* Put context at detach time */ 673: if (!_kgsl_context_get(context)) 674: return -ENOENT; 675: 676: ktimeline = kzalloc(sizeof(*ktimeline), GFP_KERNEL); 677: if (ktimeline == NULL) { 678: kgsl_context_put(context); 679: return -ENOMEM; 680: } 681: 682: kref_init(&ktimeline->kref); 683: snprintf(ktimeline->name, sizeof(ktimeline->name), 684: "%s_%u-%.15s(%d)-%.15s(%d)", 685: context->device->name, context->id, 686: current->group_leader->comm, current->group_leader->pid, 687: current->comm, current->pid); 688: 689: ktimeline->fence_context = dma_fence_context_alloc(1); 690: ktimeline->last_timestamp = 0; 691: INIT_LIST_HEAD(&ktimeline->child_list_head); 692: spin_lock_init(&ktimeline->lock); 693: ktimeline->device = context->device; 694: 695: /* 696: * The context pointer is valid till detach time, where we put the 697: * refcount on the context 698: */ 699: ktimeline->context = context; 700: 701: context->ktimeline = ktimeline; 702: 703: return 0; 704: } 705: 706: void kgsl_sync_timeline_signal(struct kgsl_sync_timeline *ktimeline, 707: unsigned int timestamp) 708: { 709: unsigned long flags; 710: struct kgsl_sync_fence *kfence, *next; 711: 712: if (!kref_get_unless_zero(&ktimeline->kref)) 713: return; 714: 715: spin_lock_irqsave(&ktimeline->lock, flags); 716: if (timestamp_cmp(timestamp, ktimeline->last_timestamp) > 0) 717: ktimeline->last_timestamp = timestamp; 718: 719: list_for_each_entry_safe(kfence, next, &ktimeline->child_list_head, 720: child_list) { 721: if (dma_fence_is_signaled_locked(&kfence->fence)) { 722: list_del_init(&kfence->child_list); 723: dma_fence_put(&kfence->fence); 724: } 725: } 726: 727: spin_unlock_irqrestore(&ktimeline->lock, flags); 728: kgsl_sync_timeline_put(ktimeline); 729: } 730: 731: void kgsl_sync_timeline_detach(struct kgsl_sync_timeline *ktimeline) 732: { 733: unsigned long flags; 734: struct kgsl_context *context = ktimeline->context; 735: 736: /* Set context pointer to NULL and drop our refcount on the context */ 737: spin_lock_irqsave(&ktimeline->lock, flags); 738: ktimeline->context = NULL; 739: spin_unlock_irqrestore(&ktimeline->lock, flags); 740: kgsl_context_put(context); 741: } 742: 743: static void kgsl_sync_timeline_destroy(struct kref *kref) 744: { 745: struct kgsl_sync_timeline *ktimeline = 746: container_of(kref, struct kgsl_sync_timeline, kref); 747: 748: kfree(ktimeline); 749: } 750: 751: void kgsl_sync_timeline_put(struct kgsl_sync_timeline *ktimeline) 752: { 753: if (ktimeline) 754: kref_put(&ktimeline->kref, kgsl_sync_timeline_destroy); 755: } 756: 757: const struct dma_fence_ops kgsl_sync_fence_ops = { 758: .get_driver_name = kgsl_sync_fence_driver_name, 759: .get_timeline_name = kgsl_sync_timeline_name, 760: .enable_signaling = kgsl_enable_signaling, 761: .signaled = kgsl_sync_fence_has_signaled, 762: .wait = dma_fence_default_wait, 763: .release = kgsl_sync_fence_release, 764: 765: #if (KERNEL_VERSION(6, 16, 0) > LINUX_VERSION_CODE) 766: .fence_value_str = kgsl_sync_fence_value_str, 767: .timeline_value_str = kgsl_sync_timeline_value_str, 768: #endif 769: }; 770: 771: static void kgsl_sync_fence_callback(struct dma_fence *fence, 772: struct dma_fence_cb *cb) 773: { 774: struct kgsl_sync_fence_cb *kcb = (struct kgsl_sync_fence_cb *)cb; 775: 776: kcb->func(kcb->priv); 777: } 778: 779: bool is_kgsl_fence(struct dma_fence *f) 780: { 781: if (f->ops == &kgsl_sync_fence_ops) 782: return true; 783: 784: return false; 785: } 786: 787: void kgsl_hw_fence_destroy(struct kgsl_sync_fence *kfence) 788: { 789: spin_lock(&hw_fence_list_lock); 790: 791: if (!list_empty(&kfence->hw_fence_list)) { 792: _hw_fence_destroy(kfence); 793: list_del_init(&kfence->hw_fence_list); 794: } 795: 796: spin_unlock(&hw_fence_list_lock); 797: } 798: 799: static void destroy_all_hw_fences(void) 800: { 801: struct kgsl_sync_fence *kfence, *next; 802: 803: spin_lock(&hw_fence_list_lock); 804: 805: list_for_each_entry_safe(kfence, next, &hw_fence_list, hw_fence_list) { 806: _hw_fence_destroy(kfence); 807: list_del_init(&kfence->hw_fence_list); 808: } 809: 810: spin_unlock(&hw_fence_list_lock); 811: } 812: 813: static void kgsl_count_hw_fences(struct kgsl_drawobj_sync_event *event, struct dma_fence *fence) 814: { 815: struct kgsl_drawobj_sync *syncobj = event->syncobj; 816: u32 max_hw_fence = event->device->max_syncobj_hw_fence_count; 817: 818: if (test_bit(KGSL_SYNCOBJ_SW, &syncobj->flags)) 819: return; 820: 821: if (!kgsl_is_input_hw_fence(fence)) { 822: /* 823: * Ignore software fences that are already signaled. Even one unsignaled sw-only 824: * fence in this sync object means we can't send this sync object to the hardware 825: */ 826: if (!dma_fence_is_signaled(fence)) 827: set_bit(KGSL_SYNCOBJ_SW, &syncobj->flags); 828: return; 829: } 830: 831: if (!syncobj->hw_fences) { 832: syncobj->hw_fences = kcalloc(max_hw_fence, sizeof(*syncobj->hw_fences), GFP_KERNEL); 833: if (!syncobj->hw_fences) { 834: set_bit(KGSL_SYNCOBJ_SW, &syncobj->flags); 835: return; 836: } 837: } 838: 839: if (syncobj->num_hw_fence < max_hw_fence) 840: syncobj->hw_fences[syncobj->num_hw_fence++].fence = fence; 841: else 842: set_bit(KGSL_SYNCOBJ_SW, &syncobj->flags); 843: } 844: 845: static void kgsl_syncsource_fence_value_str(struct dma_fence *fence, char *str, int size) 846: { 847: /* 848: * Each fence is independent of the others on the same timeline. 849: * We use a different context for each of them. 850: */ 851: snprintf(str, size, "%llu", fence->context); 852: } 853: 854: #if (KERNEL_VERSION(6, 16, 0) > LINUX_VERSION_CODE) 855: static int kgsl_get_fence_value_str(struct dma_fence *fence, char *buf, size_t size) 856: { 857: int len = 0; 858: 859: if (!fence || !fence->ops || !buf) 860: return 0; 861: 862: if (fence->ops->fence_value_str) { 863: len += scnprintf(buf + len, size - len, ": "); 864: fence->ops->fence_value_str(fence, buf + len, size - len); 865: } 866: 867: return len; 868: } 869: #else 870: static int kgsl_get_fence_value_str(struct dma_fence *fence, char *buf, size_t size) 871: { 872: int len = 0; 873: 874: if (!fence || !fence->ops || !buf) 875: return 0; 876: 877: if (fence->ops == &kgsl_sync_fence_ops) { 878: len += scnprintf(buf + len, size - len, ": "); 879: kgsl_sync_fence_value_str(fence, buf + len, size - len); 880: } 881: 882: if (fence->ops == &kgsl_syncsource_fence_ops) { 883: len += scnprintf(buf + len, size - len, ": "); 884: kgsl_syncsource_fence_value_str(fence, buf + len, size - len); 885: } 886: 887: return len; 888: } 889: #endif 890: 891: void kgsl_get_fence_name(struct dma_fence *f, char *name, u32 max_size) 892: { 893: int len = scnprintf(name, max_size, "%s %s", f->ops->get_driver_name(f), 894: f->ops->get_timeline_name(f)); 895: 896: len += kgsl_get_fence_value_str(f, name + len, max_size - len); 897: 898: } 899: 900: void kgsl_get_fence_info(struct kgsl_drawobj_sync_event *event) 901: { 902: unsigned int num_fences; 903: struct dma_fence *fence, **fences; 904: struct dma_fence_array *array; 905: struct event_fence_info *info_ptr = event->priv; 906: int i; 907: 908: fence = event->handle->fence; 909: 910: array = to_dma_fence_array(fence); 911: if (array != NULL) { 912: num_fences = array->num_fences; 913: fences = array->fences; 914: } else { 915: num_fences = 1; 916: fences = &fence; 917: } 918: 919: if (!info_ptr) 920: goto count; 921: 922: info_ptr->fences = kcalloc(num_fences, sizeof(struct fence_info), 923: GFP_KERNEL); 924: if (info_ptr->fences == NULL) 925: goto count; 926: 927: info_ptr->num_fences = num_fences; 928: 929: for (i = 0; i < num_fences; i++) { 930: struct dma_fence *f = fences[i]; 931: struct fence_info *fi = &info_ptr->fences[i]; 932: 933: kgsl_get_fence_name(f, fi->name, sizeof(fi->name)); 934: 935: kgsl_count_hw_fences(event, f); 936: } 937: 938: return; 939: count: 940: for (i = 0; i < num_fences; i++) 941: kgsl_count_hw_fences(event, fences[i]); 942: } 943: 944: struct kgsl_sync_fence_cb *kgsl_sync_fence_async_wait(int fd, 945: bool (*func)(void *priv), void *priv) 946: { 947: struct kgsl_sync_fence_cb *kcb; 948: struct dma_fence *fence; 949: int status; 950: 951: fence = sync_file_get_fence(fd); 952: if (fence == NULL) 953: return ERR_PTR(-EINVAL); 954: 955: /* create the callback */ 956: kcb = kzalloc(sizeof(*kcb), GFP_KERNEL); 957: if (kcb == NULL) { 958: dma_fence_put(fence); 959: return ERR_PTR(-ENOMEM); 960: } 961: 962: kcb->fence = fence; 963: kcb->priv = priv; 964: kcb->func = func; 965: 966: /* if status then error or signaled */ 967: status = dma_fence_add_callback(fence, &kcb->fence_cb, 968: kgsl_sync_fence_callback); 969: 970: if (status) { 971: kfree(kcb); 972: if (!dma_fence_is_signaled(fence)) 973: kcb = ERR_PTR(status); 974: else 975: kcb = NULL; 976: dma_fence_put(fence); 977: } 978: 979: return kcb; 980: } 981: 982: /* 983: * Cancel the fence async callback. 984: */ 985: void kgsl_sync_fence_async_cancel(struct kgsl_sync_fence_cb *kcb) 986: { 987: if (kcb == NULL) 988: return; 989: 990: dma_fence_remove_callback(kcb->fence, &kcb->fence_cb); 991: } 992: 993: struct kgsl_syncsource { 994: struct kref refcount; 995: char name[32]; 996: int id; 997: struct kgsl_process_private *private; 998: struct list_head child_list_head; 999: spinlock_t lock; 1000: }; 1001: 1002: struct kgsl_syncsource_fence { 1003: struct dma_fence fence; 1004: struct kgsl_syncsource *parent; 1005: struct list_head child_list; 1006: }; 1007: 1008: long kgsl_ioctl_syncsource_create(struct kgsl_device_private *dev_priv, 1009: unsigned int cmd, void *data) 1010: { 1011: struct kgsl_syncsource *syncsource = NULL; 1012: struct kgsl_syncsource_create *param = data; 1013: int ret = -EINVAL; 1014: int id = 0; 1015: struct kgsl_process_private *private = dev_priv->process_priv; 1016: 1017: if (!kgsl_process_private_get(private)) 1018: return ret; 1019: 1020: syncsource = kzalloc(sizeof(*syncsource), GFP_KERNEL); 1021: if (syncsource == NULL) { 1022: ret = -ENOMEM; 1023: goto out; 1024: } 1025: 1026: kref_init(&syncsource->refcount); 1027: snprintf(syncsource->name, sizeof(syncsource->name), MATCH LINES: 1096, 1099, 1102, 1104, 1105, 1139, 1142, 1145, 1151, 1152, 1159, 1160, 1164, 1166, 1167, 1168, 1170, 1188, 1191, 1195, 1200, 1205, 1206, 1215, 1217, 1223, 1225, 1226, 1227, 1239, 1243, 1245, 1252, 1253, 1258, 1260, 1261, 1267, 1269, 1270, 1273, 1276, 1278, 1307, 1309, 1310, 1311, 1316, 1321, 1326, 1330, 1331, 1334 1084: kfree(syncsource); 1085: } 1086: 1087: void kgsl_syncsource_put(struct kgsl_syncsource *syncsource) 1088: { 1089: if (syncsource) 1090: kref_put(&syncsource->refcount, kgsl_syncsource_destroy); 1091: } 1092: 1093: static void kgsl_syncsource_cleanup(struct kgsl_process_private *private, 1094: struct kgsl_syncsource *syncsource) 1095: { 1096: struct kgsl_syncsource_fence *sfence, *next; 1097: unsigned long flags; 1098: 1099: /* Signal all fences to release any callbacks */ 1100: spin_lock_irqsave(&syncsource->lock, flags); 1101: 1102: list_for_each_entry_safe(sfence, next, &syncsource->child_list_head, 1103: child_list) { 1104: dma_fence_signal_locked(&sfence->fence); 1105: list_del_init(&sfence->child_list); 1106: } 1107: 1108: spin_unlock_irqrestore(&syncsource->lock, flags); 1109: 1110: /* put reference from syncsource creation */ 1111: kgsl_syncsource_put(syncsource); 1112: } 1113: 1114: long kgsl_ioctl_syncsource_destroy(struct kgsl_device_private *dev_priv, 1115: unsigned int cmd, void *data) 1116: { 1117: struct kgsl_syncsource_destroy *param = data; 1118: struct kgsl_syncsource *syncsource = NULL; 1119: struct kgsl_process_private *private = dev_priv->process_priv; 1120: 1121: spin_lock(&private->syncsource_lock); 1122: syncsource = idr_find(&private->syncsource_idr, param->id); 1123: 1124: if (syncsource == NULL) { 1125: spin_unlock(&private->syncsource_lock); 1126: return -EINVAL; 1127: } 1128: 1129: if (syncsource->id != 0) { 1130: idr_remove(&private->syncsource_idr, syncsource->id); 1131: syncsource->id = 0; 1132: } 1133: spin_unlock(&private->syncsource_lock); 1134: 1135: kgsl_syncsource_cleanup(private, syncsource); 1136: return 0; 1137: } 1138: 1139: long kgsl_ioctl_syncsource_create_fence(struct kgsl_device_private *dev_priv, 1140: unsigned int cmd, void *data) 1141: { 1142: struct kgsl_syncsource_create_fence *param = data; 1143: struct kgsl_syncsource *syncsource = NULL; 1144: int ret = -EINVAL; 1145: struct kgsl_syncsource_fence *sfence = NULL; 1146: struct sync_file *sync_file = NULL; 1147: int fd = -1; 1148: unsigned long flags; 1149: 1150: /* 1151: * Take a refcount that is released when the fence is released 1152: * (or if fence can't be added to the syncsource). 1153: */ 1154: syncsource = kgsl_syncsource_get(dev_priv->process_priv, 1155: param->id); 1156: if (syncsource == NULL) 1157: goto out; 1158: 1159: sfence = kzalloc(sizeof(*sfence), GFP_KERNEL); 1160: if (sfence == NULL) { 1161: ret = -ENOMEM; 1162: goto out; 1163: } 1164: sfence->parent = syncsource; 1165: 1166: /* Use a new fence context for each fence */ 1167: dma_fence_init(&sfence->fence, &kgsl_syncsource_fence_ops, 1168: &syncsource->lock, dma_fence_context_alloc(1), 1); 1169: 1170: sync_file = sync_file_create(&sfence->fence); 1171: 1172: if (sync_file == NULL) { 1173: dev_err(dev_priv->device->dev, 1174: "Create sync_file failed\n"); 1175: ret = -ENOMEM; 1176: goto out; 1177: } 1178: 1179: fd = get_unused_fd_flags(0); 1180: if (fd < 0) { 1181: ret = -EBADF; 1182: goto out; 1183: } 1184: ret = 0; 1185: 1186: fd_install(fd, sync_file->file); 1187: 1188: param->fence_fd = fd; 1189: 1190: spin_lock_irqsave(&syncsource->lock, flags); 1191: list_add_tail(&sfence->child_list, &syncsource->child_list_head); 1192: spin_unlock_irqrestore(&syncsource->lock, flags); 1193: out: 1194: /* 1195: * We're transferring ownership of the fence to the sync file. 1196: * The sync file takes an extra refcount when it is created, so put 1197: * our refcount. 1198: */ 1199: if (sync_file) 1200: dma_fence_put(&sfence->fence); 1201: 1202: if (ret) { 1203: if (sync_file) 1204: fput(sync_file->file); 1205: else if (sfence) 1206: dma_fence_put(&sfence->fence); 1207: else 1208: kgsl_syncsource_put(syncsource); 1209: } 1210: 1211: return ret; 1212: } 1213: 1214: static int kgsl_syncsource_signal(struct kgsl_syncsource *syncsource, 1215: struct dma_fence *fence) 1216: { 1217: struct kgsl_syncsource_fence *sfence, *next; 1218: int ret = -EINVAL; 1219: unsigned long flags; 1220: 1221: spin_lock_irqsave(&syncsource->lock, flags); 1222: 1223: list_for_each_entry_safe(sfence, next, &syncsource->child_list_head, 1224: child_list) { 1225: if (fence == &sfence->fence) { 1226: dma_fence_signal_locked(fence); 1227: list_del_init(&sfence->child_list); 1228: 1229: ret = 0; 1230: break; 1231: } 1232: } 1233: 1234: spin_unlock_irqrestore(&syncsource->lock, flags); 1235: 1236: return ret; 1237: } 1238: 1239: long kgsl_ioctl_syncsource_signal_fence(struct kgsl_device_private *dev_priv, 1240: unsigned int cmd, void *data) 1241: { 1242: int ret = -EINVAL; 1243: struct kgsl_syncsource_signal_fence *param = data; 1244: struct kgsl_syncsource *syncsource = NULL; 1245: struct dma_fence *fence = NULL; 1246: 1247: syncsource = kgsl_syncsource_get(dev_priv->process_priv, 1248: param->id); 1249: if (syncsource == NULL) 1250: goto out; 1251: 1252: fence = sync_file_get_fence(param->fence_fd); 1253: if (fence == NULL) { 1254: ret = -EBADF; 1255: goto out; 1256: } 1257: 1258: ret = kgsl_syncsource_signal(syncsource, fence); 1259: out: 1260: if (fence) 1261: dma_fence_put(fence); 1262: if (syncsource) 1263: kgsl_syncsource_put(syncsource); 1264: return ret; 1265: } 1266: 1267: static void kgsl_syncsource_fence_release(struct dma_fence *fence) 1268: { 1269: struct kgsl_syncsource_fence *sfence = 1270: (struct kgsl_syncsource_fence *)fence; 1271: 1272: /* Signal if it's not signaled yet */ 1273: kgsl_syncsource_signal(sfence->parent, fence); 1274: 1275: /* Release the refcount on the syncsource */ 1276: kgsl_syncsource_put(sfence->parent); 1277: 1278: kfree(sfence); 1279: } 1280: 1281: void kgsl_syncsource_process_release_syncsources( 1282: struct kgsl_process_private *private) 1283: { 1284: struct kgsl_syncsource *syncsource; 1285: int next = 0; 1286: 1287: while (1) { 1288: spin_lock(&private->syncsource_lock); 1289: syncsource = idr_get_next(&private->syncsource_idr, &next); 1290: 1291: if (syncsource == NULL) { 1292: spin_unlock(&private->syncsource_lock); 1293: break; 1294: } 1295: 1296: if (syncsource->id != 0) { 1297: idr_remove(&private->syncsource_idr, syncsource->id); 1298: syncsource->id = 0; 1299: } 1300: spin_unlock(&private->syncsource_lock); 1301: 1302: kgsl_syncsource_cleanup(private, syncsource); 1303: next = next + 1; 1304: } 1305: } 1306: 1307: static const char *kgsl_syncsource_get_timeline_name(struct dma_fence *fence) 1308: { 1309: struct kgsl_syncsource_fence *sfence = 1310: (struct kgsl_syncsource_fence *)fence; 1311: struct kgsl_syncsource *syncsource = sfence->parent; 1312: 1313: return syncsource->name; 1314: } 1315: 1316: static bool kgsl_syncsource_enable_signaling(struct dma_fence *fence) 1317: { 1318: return true; 1319: } 1320: 1321: static const char *kgsl_syncsource_driver_name(struct dma_fence *fence) 1322: { 1323: return "kgsl-syncsource-timeline"; 1324: } 1325: 1326: static const struct dma_fence_ops kgsl_syncsource_fence_ops = { 1327: .get_driver_name = kgsl_syncsource_driver_name, 1328: .get_timeline_name = kgsl_syncsource_get_timeline_name, 1329: .enable_signaling = kgsl_syncsource_enable_signaling, 1330: .wait = dma_fence_default_wait, 1331: .release = kgsl_syncsource_fence_release, 1332: 1333: #if (KERNEL_VERSION(6, 16, 0) > LINUX_VERSION_CODE) 1334: .fence_value_str = kgsl_syncsource_fence_value_str, 1335: #endif 1336: }; 1337: --- FILE: \kgsl_sync.h | HITS: 67 --- MATCH LINES: 9, 13, 16, 18, 20, 28, 33, 39, 41, 43, 44, 46, 48, 49, 54, 55, 56, 57, 58, 62, 63, 64, 69, 70, 71, 78, 83, 84, 93, 95, 97, 99, 105, 107, 115, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 143, 144, 165, 169, 176, 195, 202, 219, 225, 230, 235, 240, 245, 250, 255, 260, 265, 270, 275, 280 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2012-2014,2018-2019, 2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: #ifndef __KGSL_SYNC_H 7: #define __KGSL_SYNC_H 8: 9: #include 10: 11: /** 12: * struct kgsl_sync_timeline - A sync timeline associated with a kgsl context 13: * @kref: Refcount to keep the struct alive until all its fences are signaled, 14: and as long as the context exists 15: * @name: String to describe this timeline 16: * @fence_context: Used by the fence driver to identify fences belonging to 17: * this context 18: * @child_list_head: List head for all fences on this timeline 19: * @lock: Spinlock to protect this timeline 20: * @last_timestamp: Last timestamp when signaling fences 21: * @device: kgsl device 22: * @context: kgsl context 23: */ 24: struct kgsl_sync_timeline { 25: struct kref kref; 26: char name[32]; 27: 28: u64 fence_context; 29: 30: struct list_head child_list_head; 31: 32: spinlock_t lock; 33: unsigned int last_timestamp; 34: struct kgsl_device *device; 35: struct kgsl_context *context; 36: }; 37: 38: /** 39: * struct kgsl_sync_fence - A struct containing a fence and other data 40: * associated with it 41: * @fence: The fence struct 42: * @sync_file: Pointer to the sync file 43: * @parent: Pointer to the kgsl sync timeline this fence is on 44: * @child_list: List of fences on the same timeline 45: * @context_id: kgsl context id 46: * @timestamp: Context timestamp that this fence is associated with 47: */ 48: struct kgsl_sync_fence { 49: struct dma_fence fence; 50: struct sync_file *sync_file; 51: struct kgsl_sync_timeline *parent; 52: struct list_head child_list; 53: u32 context_id; 54: unsigned int timestamp; 55: /** @hw_fence_index: Index of hw fence in hw fence table */ 56: u64 hw_fence_index; 57: /** @hw_fence_list: Global list of hw fences */ 58: struct list_head hw_fence_list; 59: }; 60: 61: /** 62: * struct kgsl_sync_fence_cb - Used for fence callbacks 63: * fence_cb: Fence callback struct 64: * fence: Pointer to the fence for which the callback is done 65: * priv: Private data for the callback 66: * func: Pointer to the kgsl function to call. This function should return 67: * false if the sync callback is marked for cancellation in a separate thread. 68: */ 69: struct kgsl_sync_fence_cb { 70: struct dma_fence_cb fence_cb; 71: struct dma_fence *fence; 72: void *priv; 73: bool (*func)(void *priv); 74: }; 75: 76: struct kgsl_device_private; 77: struct kgsl_drawobj_sync_event; 78: struct event_fence_info; 79: struct kgsl_process_private; 80: struct kgsl_syncsource; 81: 82: #if defined(CONFIG_SYNC_FILE) 83: int kgsl_add_fence_event(struct kgsl_device *device, 84: u32 context_id, u32 timestamp, void __user *data, int len, 85: struct kgsl_device_private *owner); 86: 87: int kgsl_sync_timeline_create(struct kgsl_context *context); 88: 89: void kgsl_sync_timeline_detach(struct kgsl_sync_timeline *ktimeline); 90: 91: void kgsl_sync_timeline_put(struct kgsl_sync_timeline *ktimeline); 92: 93: void kgsl_sync_timeline_value_str(struct dma_fence *fence, char *str, int size); 94: 95: struct kgsl_sync_fence_cb *kgsl_sync_fence_async_wait(int fd, bool (*func)(void *priv), void *priv); 96: 97: void kgsl_get_fence_info(struct kgsl_drawobj_sync_event *event); 98: 99: void kgsl_sync_fence_async_cancel(struct kgsl_sync_fence_cb *kcb); 100: 101: long kgsl_ioctl_syncsource_create(struct kgsl_device_private *dev_priv, 102: unsigned int cmd, void *data); 103: long kgsl_ioctl_syncsource_destroy(struct kgsl_device_private *dev_priv, 104: unsigned int cmd, void *data); 105: long kgsl_ioctl_syncsource_create_fence(struct kgsl_device_private *dev_priv, 106: unsigned int cmd, void *data); 107: long kgsl_ioctl_syncsource_signal_fence(struct kgsl_device_private *dev_priv, 108: unsigned int cmd, void *data); 109: 110: void kgsl_syncsource_put(struct kgsl_syncsource *syncsource); 111: 112: void kgsl_syncsource_process_release_syncsources( 113: struct kgsl_process_private *private); 114: 115: bool is_kgsl_fence(struct dma_fence *f); 116: 117: void kgsl_sync_timeline_signal(struct kgsl_sync_timeline *ktimeline, 118: u32 timestamp); 119: 120: int kgsl_hw_fence_init(struct kgsl_device *device); 121: 122: void kgsl_hw_fence_close(struct kgsl_device *device); 123: 124: void kgsl_hw_fence_populate_md(struct kgsl_device *device, struct kgsl_memdesc *md); 125: 126: int kgsl_hw_fence_create(struct kgsl_device *device, struct kgsl_sync_fence *kfence); 127: 128: int kgsl_hw_fence_add_waiter(struct kgsl_device *device, struct dma_fence *fence, u32 *hash_index); 129: 130: bool kgsl_hw_fence_tx_slot_available(struct kgsl_device *device, u32 pending_hw_fence_count); 131: 132: void kgsl_hw_fence_destroy(struct kgsl_sync_fence *kfence); 133: 134: void kgsl_hw_fence_trigger_cpu(struct kgsl_device *device, struct kgsl_sync_fence *kfence); 135: 136: bool kgsl_hw_fence_signaled(struct dma_fence *fence); 137: 138: void kgsl_get_fence_name(struct dma_fence *f, char *name, u32 max_size); 139: 140: int kgsl_hw_fence_soccp_vote(bool pwr_on); 141: 142: #else 143: static inline int kgsl_add_fence_event(struct kgsl_device *device, 144: u32 context_id, u32 timestamp, void __user *data, int len, 145: struct kgsl_device_private *owner) 146: { 147: return -EINVAL; 148: } 149: 150: static inline int kgsl_sync_timeline_create(struct kgsl_context *context) 151: { 152: context->ktimeline = NULL; 153: return 0; 154: } 155: 156: static inline void kgsl_sync_timeline_detach(struct kgsl_sync_timeline *ktimeline) 157: { 158: } 159: 160: static inline void kgsl_sync_timeline_put(struct kgsl_sync_timeline *ktimeline) 161: { 162: } 163: 164: 165: static inline void kgsl_get_fence_info(struct kgsl_drawobj_sync_event *event) 166: { 167: } 168: 169: static inline struct kgsl_sync_fence_cb *kgsl_sync_fence_async_wait(int fd, 170: bool (*func)(void *priv), void *priv) 171: { 172: return NULL; 173: } 174: 175: static inline void 176: kgsl_sync_fence_async_cancel(struct kgsl_sync_fence_cb *kcb) 177: { 178: } 179: 180: static inline long 181: kgsl_ioctl_syncsource_create(struct kgsl_device_private *dev_priv, 182: unsigned int cmd, void *data) 183: { 184: return -ENOIOCTLCMD; 185: } 186: 187: static inline long 188: kgsl_ioctl_syncsource_destroy(struct kgsl_device_private *dev_priv, 189: unsigned int cmd, void *data) 190: { 191: return -ENOIOCTLCMD; 192: } 193: 194: static inline long 195: kgsl_ioctl_syncsource_create_fence(struct kgsl_device_private *dev_priv, 196: unsigned int cmd, void *data) 197: { 198: return -ENOIOCTLCMD; 199: } 200: 201: static inline long 202: kgsl_ioctl_syncsource_signal_fence(struct kgsl_device_private *dev_priv, 203: unsigned int cmd, void *data) 204: { 205: return -ENOIOCTLCMD; 206: } 207: 208: static inline void kgsl_syncsource_put(struct kgsl_syncsource *syncsource) 209: { 210: 211: } 212: 213: static inline void kgsl_syncsource_process_release_syncsources( 214: struct kgsl_process_private *private) 215: { 216: 217: } 218: 219: bool is_kgsl_fence(struct dma_fence *f) 220: { 221: return false; 222: } 223: 224: void kgsl_sync_timeline_signal(struct kgsl_sync_timeline *ktimeline, 225: u32 timestamp) 226: { 227: 228: } 229: 230: int kgsl_hw_fence_soccp_vote(bool pwr_on) 231: { 232: return -EINVAL; 233: } 234: 235: int kgsl_hw_fence_init(struct kgsl_device *device) 236: { 237: return -EINVAL; 238: } 239: 240: void kgsl_hw_fence_close(struct kgsl_device *device) 241: { 242: 243: } 244: 245: void kgsl_hw_fence_populate_md(struct kgsl_device *device, struct kgsl_memdesc *md) 246: { 247: 248: } 249: 250: int kgsl_hw_fence_create(struct kgsl_device *device, struct kgsl_sync_fence *kfence) 251: { 252: return -EINVAL; 253: } 254: 255: int kgsl_hw_fence_add_waiter(struct kgsl_device *device, struct dma_fence *fence, u32 *hash_index) 256: { 257: return -EINVAL; 258: } 259: 260: bool kgsl_hw_fence_tx_slot_available(struct kgsl_device *device, u32 pending_hw_fence_count) 261: { 262: return false; 263: } 264: 265: void kgsl_hw_fence_destroy(struct kgsl_sync_fence *kfence) 266: { 267: 268: } 269: 270: void kgsl_hw_fence_trigger_cpu(struct kgsl_device *device, struct kgsl_sync_fence *kfence) 271: { 272: 273: } 274: 275: bool kgsl_hw_fence_signaled(struct dma_fence *fence) 276: { 277: return false; 278: } 279: 280: void kgsl_get_fence_name(struct dma_fence *f, char *name, u32 max_size) 281: { 282: 283: } 284: 285: #endif /* CONFIG_SYNC_FILE */ 286: 287: #endif /* __KGSL_SYNC_H */ --- FILE: \kgsl_timeline.c | HITS: 156 --- MATCH LINES: 7, 21, 22, 28, 34, 36, 41, 47, 50, 73, 76, 77, 84, 87, 88, 91, 96, 97, 99, 100, 103, 104, 106, 107, 111, 114, 115, 118, 119, 120, 123, 125, 126, 129, 135, 137, 146 1: // SPDX-License-Identifier: GPL-2.0-only 2: /* 3: * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include 8: #include 9: #include 10: #include 11: #include 12: #include 13: 14: #include "kgsl_device.h" 15: #include "kgsl_eventlog.h" 16: #include "kgsl_sharedmem.h" 17: #include "kgsl_sync.h" 18: #include "kgsl_timeline.h" 19: #include "kgsl_trace.h" 20: 21: struct kgsl_timeline_fence { 22: struct dma_fence base; 23: struct kgsl_timeline *timeline; 24: struct list_head node; 25: }; 26: 27: /* 28: * kgsl_timelines_collect_fences - Collect timeline fences from userspace 29: * @device: A KGSL device handle 30: * @timelines: Userspace pointer to an array of &struct kgsl_timeline_val 31: * @count: Number of entries in @timelines 32: * @usize: Size of each entry in @timelines 33: * 34: * Returns an array of dma_fence pointers on success, or ERR_PTR on failure. 35: */ 36: static struct dma_fence **kgsl_timelines_collect_fences( 37: struct kgsl_device *device, u64 timelines, u32 count, 38: u64 usize) 39: { 40: void __user *uptr = u64_to_user_ptr(timelines); 41: struct dma_fence **fences; 42: int i, ret = 0; 43: 44: if (!count || count > INT_MAX) 45: return ERR_PTR(-EINVAL); 46: 47: fences = kcalloc(count, sizeof(*fences), 48: GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN); 49: 50: if (!fences) 51: return ERR_PTR(-ENOMEM); 52: 53: for (i = 0; i < count; i++) { 54: struct kgsl_timeline_val val; 55: struct kgsl_timeline *timeline; 56: 57: if (copy_struct_from_user(&val, sizeof(val), uptr, usize)) { 58: ret = -EFAULT; 59: goto err; 60: } 61: 62: if (val.padding) { 63: ret = -EINVAL; 64: goto err; 65: } 66: 67: timeline = kgsl_timeline_by_id(device, val.timeline); 68: if (!timeline) { 69: ret = -ENOENT; 70: goto err; 71: } 72: 73: fences[i] = kgsl_timeline_fence_alloc(timeline, val.seqno); 74: kgsl_timeline_put(timeline); 75: 76: if (IS_ERR(fences[i])) { 77: ret = PTR_ERR(fences[i]); 78: goto err; 79: } 80: 81: uptr += usize; 82: } 83: 84: return fences; 85: err: 86: for (i = 0; i < count; i++) { 87: if (!IS_ERR_OR_NULL(fences[i])) 88: dma_fence_put(fences[i]); 89: } 90: 91: kfree(fences); 92: return ERR_PTR(ret); 93: } 94: 95: #if (KERNEL_VERSION(7, 2, 0) <= LINUX_VERSION_CODE) 96: static struct dma_fence_array *kgsl_dma_fence_array_create(int count, 97: struct dma_fence **fences) 98: { 99: return dma_fence_array_create(count, fences, 100: dma_fence_context_alloc(1), 0); 101: } 102: #else 103: static struct dma_fence_array *kgsl_dma_fence_array_create(int count, 104: struct dma_fence **fences) 105: { 106: return dma_fence_array_create(count, fences, 107: dma_fence_context_alloc(1), 0, false); 108: } 109: #endif 110: 111: struct dma_fence *kgsl_timelines_to_fence_array(struct kgsl_device *device, 112: u64 timelines, u32 count, u64 usize) 113: { 114: struct dma_fence_array *array; 115: struct dma_fence **fences; 116: int i; 117: 118: fences = kgsl_timelines_collect_fences(device, timelines, count, usize); 119: if (IS_ERR(fences)) 120: return ERR_CAST(fences); 121: 122: if (count == 1) { 123: struct dma_fence *fence = fences[0]; 124: 125: kfree(fences); 126: return fence; 127: } 128: 129: array = kgsl_dma_fence_array_create(count, fences); 130: 131: if (array) 132: return &array->base; 133: 134: for (i = 0; i < count; i++) 135: dma_fence_put(fences[i]); 136: 137: kfree(fences); 138: return ERR_PTR(-ENOMEM); 139: } 140: 141: void kgsl_timeline_destroy(struct kref *kref) 142: { 143: struct kgsl_timeline *timeline = container_of(kref, 144: struct kgsl_timeline, ref); 145: 146: WARN_ON(!list_empty(&timeline->fences)); 147: WARN_ON(!list_empty(&timeline->events)); 148: 149: trace_kgsl_timeline_destroy(timeline->id); 150: 151: kfree(timeline); 152: } 153: 154: struct kgsl_timeline *kgsl_timeline_get(struct kgsl_timeline *timeline) 155: { 156: if (timeline) { 157: if (!kref_get_unless_zero(&timeline->ref)) 158: return NULL; 159: } 160: 161: return timeline; 162: } 163: 164: static struct kgsl_timeline *kgsl_timeline_alloc(struct kgsl_device_private *dev_priv, 165: u64 initial) 166: { 167: struct kgsl_device *device = dev_priv->device; 168: struct kgsl_timeline *timeline; 169: int id; 170: MATCH LINES: 187, 189, 200, 207, 209, 212, 214, 216, 219, 221, 222, 229, 230, 231, 234, 238, 240, 242, 245, 247, 249, 250, 254, 257, 258, 261, 264, 269, 271, 276, 279, 284, 287, 288, 289, 302, 304, 307, 308, 312, 314, 317, 318, 320, 324, 325, 327, 330, 331, 332, 333, 334, 339, 340, 367, 390, 391, 392, 393, 394, 395, 397, 398, 399, 407, 408, 410, 413, 414, 416, 420, 423, 425, 426, 429, 430, 431, 435, 438, 441, 446, 447, 449, 452, 454 175: idr_preload(GFP_KERNEL); 176: spin_lock(&device->timelines_lock); 177: /* Allocate the ID but don't attach the pointer just yet */ 178: id = idr_alloc(&device->timelines, NULL, 1, 0, GFP_NOWAIT); 179: spin_unlock(&device->timelines_lock); 180: idr_preload_end(); 181: 182: if (id < 0) { 183: kfree(timeline); 184: return ERR_PTR(id); 185: } 186: 187: timeline->context = dma_fence_context_alloc(1); 188: timeline->id = id; 189: INIT_LIST_HEAD(&timeline->fences); 190: INIT_LIST_HEAD(&timeline->events); 191: timeline->value = initial; 192: timeline->dev_priv = dev_priv; 193: 194: snprintf((char *) timeline->name, sizeof(timeline->name), 195: "kgsl-sw-timeline-%d", id); 196: 197: trace_kgsl_timeline_alloc(id, initial); 198: 199: spin_lock_init(&timeline->lock); 200: spin_lock_init(&timeline->fence_lock); 201: 202: kref_init(&timeline->ref); 203: 204: return timeline; 205: } 206: 207: static struct kgsl_timeline_fence *to_timeline_fence(struct dma_fence *fence) 208: { 209: return container_of(fence, struct kgsl_timeline_fence, base); 210: } 211: 212: static void timeline_fence_release(struct dma_fence *fence) 213: { 214: struct kgsl_timeline_fence *f = to_timeline_fence(fence); 215: struct kgsl_timeline *timeline = f->timeline; 216: struct kgsl_timeline_fence *cur, *temp; 217: unsigned long flags; 218: 219: spin_lock_irqsave(&timeline->fence_lock, flags); 220: 221: /* If the fence is still on the active list, remove it */ 222: list_for_each_entry_safe(cur, temp, &timeline->fences, node) { 223: if (f != cur) 224: continue; 225: 226: list_del_init(&f->node); 227: break; 228: } 229: spin_unlock_irqrestore(&timeline->fence_lock, flags); 230: trace_kgsl_timeline_fence_release(f->timeline->id, fence->seqno); 231: log_kgsl_timeline_fence_release_event(f->timeline->id, fence->seqno); 232: 233: kgsl_timeline_put(f->timeline); 234: dma_fence_free(fence); 235: } 236: 237: #if (KERNEL_VERSION(6, 17, 0) <= LINUX_VERSION_CODE) 238: static bool timeline_fence_signaled(struct dma_fence *fence) 239: { 240: struct kgsl_timeline_fence *f = to_timeline_fence(fence); 241: 242: return !__dma_fence_is_later(fence, fence->seqno, f->timeline->value); 243: } 244: #else 245: static bool timeline_fence_signaled(struct dma_fence *fence) 246: { 247: struct kgsl_timeline_fence *f = to_timeline_fence(fence); 248: 249: return !__dma_fence_is_later(fence->seqno, f->timeline->value, 250: fence->ops); 251: } 252: #endif 253: 254: static bool timeline_fence_enable_signaling(struct dma_fence *fence) 255: { 256: /* 257: * Return value of false indicates the fence already passed. 258: * When fence is not passed we return true indicating successful 259: * enabling. 260: */ 261: return !timeline_fence_signaled(fence); 262: } 263: 264: static const char *timeline_get_driver_name(struct dma_fence *fence) 265: { 266: return "kgsl-sw-timeline"; 267: } 268: 269: static const char *timeline_get_timeline_name(struct dma_fence *fence) 270: { 271: struct kgsl_timeline_fence *f = to_timeline_fence(fence); 272: 273: return f->timeline->name; 274: } 275: 276: static void timeline_get_value_str(struct dma_fence *fence, 277: char *str, int size) 278: { 279: struct kgsl_timeline_fence *f = to_timeline_fence(fence); 280: 281: snprintf(str, size, "%lld", f->timeline->value); 282: } 283: 284: static const struct dma_fence_ops timeline_fence_ops = { 285: .get_driver_name = timeline_get_driver_name, 286: .get_timeline_name = timeline_get_timeline_name, 287: .signaled = timeline_fence_signaled, 288: .release = timeline_fence_release, 289: .enable_signaling = timeline_fence_enable_signaling, 290: 291: #if (KERNEL_VERSION(6, 16, 0) > LINUX_VERSION_CODE) 292: .timeline_value_str = timeline_get_value_str, 293: #endif 294: 295: #if (KERNEL_VERSION(6, 17, 0) > LINUX_VERSION_CODE) 296: .use_64bit_seqno = true, 297: #endif 298: 299: }; 300: 301: #if (KERNEL_VERSION(6, 16, 0) > LINUX_VERSION_CODE) 302: void kgsl_fence_timeline_value_str(struct dma_fence *fence, char *value, size_t size) 303: { 304: if (!fence || !fence->ops || !value || !size) 305: return; 306: 307: if (fence->ops->timeline_value_str) 308: fence->ops->timeline_value_str(fence, value, size); 309: 310: } 311: #else 312: void kgsl_fence_timeline_value_str(struct dma_fence *fence, char *value, size_t size) 313: { 314: if (!fence || !fence->ops || !value || !size) 315: return; 316: 317: if (fence->ops == &timeline_fence_ops) 318: timeline_get_value_str(fence, value, size); 319: else 320: kgsl_sync_timeline_value_str(fence, value, size); 321: } 322: #endif 323: 324: static void kgsl_timeline_add_fence(struct kgsl_timeline *timeline, 325: struct kgsl_timeline_fence *fence) 326: { 327: struct kgsl_timeline_fence *entry; 328: unsigned long flags; 329: 330: spin_lock_irqsave(&timeline->fence_lock, flags); 331: list_for_each_entry(entry, &timeline->fences, node) { 332: if (fence->base.seqno < entry->base.seqno) { 333: list_add_tail(&fence->node, &entry->node); 334: spin_unlock_irqrestore(&timeline->fence_lock, flags); 335: return; 336: } 337: } 338: 339: list_add_tail(&fence->node, &timeline->fences); 340: spin_unlock_irqrestore(&timeline->fence_lock, flags); 341: } 342: 343: void kgsl_timeline_add_signal(struct kgsl_timeline_event *signal) 344: { 345: struct kgsl_timeline *timeline = signal->timeline; 346: struct kgsl_timeline_event *event; 347: unsigned long flags; 348: 349: spin_lock_irqsave(&timeline->lock, flags); 350: 351: /* If we already signaled this seqno don't add it to the list */ 352: if (timeline->value >= signal->seqno) 353: goto done; 354: 355: /* Keep the list sorted by seqno */ 356: list_for_each_entry_reverse(event, &timeline->events, node) { 357: if (event->seqno <= signal->seqno) 358: break; 359: } 360: list_add(&signal->node, &event->node); 361: done: 362: spin_unlock_irqrestore(&timeline->lock, flags); 363: } 364: 365: void kgsl_timeline_signal(struct kgsl_timeline *timeline, u64 seqno) 366: { 367: struct kgsl_timeline_fence *fence, *tmp; 368: struct kgsl_timeline_event *event, *tmp_event; 369: struct list_head temp; 370: 371: INIT_LIST_HEAD(&temp); 372: 373: spin_lock_irq(&timeline->lock); 374: 375: if (seqno < timeline->value) 376: goto unlock; 377: 378: trace_kgsl_timeline_signal(timeline->id, seqno); 379: 380: timeline->value = seqno; 381: list_for_each_entry_safe(event, tmp_event, &timeline->events, node) { 382: /* List is sorted by seqno */ 383: if (event->seqno > seqno) 384: break; 385: 386: /* Remove retired nodes */ 387: list_del(&event->node); 388: } 389: 390: spin_lock(&timeline->fence_lock); 391: list_for_each_entry_safe(fence, tmp, &timeline->fences, node) 392: if (timeline_fence_signaled(&fence->base) && 393: kref_get_unless_zero(&fence->base.refcount)) 394: list_move(&fence->node, &temp); 395: spin_unlock(&timeline->fence_lock); 396: 397: list_for_each_entry_safe(fence, tmp, &temp, node) { 398: dma_fence_signal_locked(&fence->base); 399: dma_fence_put(&fence->base); 400: } 401: 402: unlock: 403: spin_unlock_irq(&timeline->lock); 404: } 405: 406: #if KERNEL_VERSION(6, 17, 0) <= LINUX_VERSION_CODE 407: static inline void kgsl_timeline_dma_fence_init(struct dma_fence *fence, 408: const struct dma_fence_ops *ops, spinlock_t *lock, u64 context, u64 seqno) 409: { 410: dma_fence_init64(fence, ops, lock, context, seqno); 411: } 412: #else 413: static inline void kgsl_timeline_dma_fence_init(struct dma_fence *fence, 414: const struct dma_fence_ops *ops, spinlock_t *lock, u64 context, u64 seqno) 415: { 416: dma_fence_init(fence, ops, lock, context, seqno); 417: } 418: #endif 419: 420: struct dma_fence *kgsl_timeline_fence_alloc(struct kgsl_timeline *timeline, 421: u64 seqno) 422: { 423: struct kgsl_timeline_fence *fence; 424: 425: fence = kzalloc(sizeof(*fence), GFP_KERNEL); 426: if (!fence) 427: return ERR_PTR(-ENOMEM); 428: 429: fence->timeline = kgsl_timeline_get(timeline); 430: if (!fence->timeline) { 431: kfree(fence); 432: return ERR_PTR(-ENOENT); 433: } 434: 435: kgsl_timeline_dma_fence_init(&fence->base, &timeline_fence_ops, &timeline->lock, 436: timeline->context, seqno); 437: 438: INIT_LIST_HEAD(&fence->node); 439: 440: /* 441: * Once fence is checked as not signaled, allow it to be added 442: * in the list before other thread such as kgsl_timeline_signal 443: * can get chance to signal. 444: */ 445: spin_lock_irq(&timeline->lock); 446: if (!dma_fence_is_signaled_locked(&fence->base)) 447: kgsl_timeline_add_fence(timeline, fence); 448: 449: trace_kgsl_timeline_fence_alloc(timeline->id, seqno); 450: spin_unlock_irq(&timeline->lock); 451: 452: log_kgsl_timeline_fence_alloc_event(timeline->id, seqno); 453: 454: return &fence->base; 455: } 456: 457: long kgsl_ioctl_timeline_create(struct kgsl_device_private *dev_priv, 458: unsigned int cmd, void *data) 459: { 460: struct kgsl_device *device = dev_priv->device; 461: struct kgsl_timeline_create *param = data; 462: struct kgsl_timeline *timeline; 463: 464: timeline = kgsl_timeline_alloc(dev_priv, param->seqno); 465: if (IS_ERR(timeline)) 466: return PTR_ERR(timeline); 467: 468: /* Commit the pointer to the timeline in timeline idr */ 469: spin_lock(&device->timelines_lock); 470: idr_replace(&device->timelines, timeline, timeline->id); 471: param->id = timeline->id; 472: spin_unlock(&device->timelines_lock); 473: return 0; 474: } 475: 476: struct kgsl_timeline *kgsl_timeline_by_id(struct kgsl_device *device, 477: u32 id) 478: { MATCH LINES: 497, 498, 510, 513, 514, 527, 531, 532, 534, 537, 538, 542, 543, 578, 579, 592, 596, 599, 606, 608, 610, 619, 629 485: if (timeline) 486: ret = kref_get_unless_zero(&timeline->ref); 487: spin_unlock(&device->timelines_lock); 488: 489: return ret ? timeline : NULL; 490: } 491: 492: long kgsl_ioctl_timeline_wait(struct kgsl_device_private *dev_priv, 493: unsigned int cmd, void *data) 494: { 495: struct kgsl_device *device = dev_priv->device; 496: struct kgsl_timeline_wait *param = data; 497: struct dma_fence_array *array; 498: struct dma_fence **fences; 499: unsigned long timeout; 500: signed long ret; 501: int i; 502: 503: if (param->flags != KGSL_TIMELINE_WAIT_ANY && 504: param->flags != KGSL_TIMELINE_WAIT_ALL) 505: return -EINVAL; 506: 507: if (param->padding) 508: return -EINVAL; 509: 510: fences = kgsl_timelines_collect_fences(device, param->timelines, 511: param->count, param->timelines_size); 512: 513: if (IS_ERR(fences)) 514: return PTR_ERR(fences); 515: 516: if (param->tv_sec >= KTIME_SEC_MAX) 517: timeout = MAX_SCHEDULE_TIMEOUT; 518: else { 519: ktime_t time = ktime_set(param->tv_sec, param->tv_nsec); 520: 521: timeout = msecs_to_jiffies(ktime_to_ms(time)); 522: } 523: 524: trace_kgsl_timeline_wait(param->flags, param->tv_sec, param->tv_nsec); 525: 526: if (param->flags == KGSL_TIMELINE_WAIT_ANY) { 527: ret = dma_fence_wait_any_timeout(fences, param->count, 528: true, timeout, NULL); 529: 530: for (i = 0; i < param->count; i++) 531: dma_fence_put(fences[i]); 532: kfree(fences); 533: } else { 534: array = kgsl_dma_fence_array_create(param->count, fences); 535: if (!array) { 536: for (i = 0; i < param->count; i++) 537: dma_fence_put(fences[i]); 538: kfree(fences); 539: return -ENOMEM; 540: } 541: 542: ret = dma_fence_wait_timeout(&array->base, true, timeout); 543: dma_fence_put(&array->base); 544: } 545: 546: if (!ret) 547: ret = (!timeout) ? -EBUSY : -ETIMEDOUT; 548: else if (ret > 0) 549: ret = 0; 550: 551: return ret; 552: } 553: 554: long kgsl_ioctl_timeline_query(struct kgsl_device_private *dev_priv, 555: unsigned int cmd, void *data) 556: { 557: struct kgsl_timeline_val *param = data; 558: struct kgsl_timeline *timeline; 559: struct kgsl_timeline_event *event; 560: u64 seqno; 561: 562: if (param->padding) 563: return -EINVAL; 564: 565: timeline = kgsl_timeline_by_id(dev_priv->device, param->timeline); 566: if (!timeline) 567: return -ENODEV; 568: 569: /* 570: * Start from the end of the list to find the last retired signal event 571: * that was not yet processed. Leave the entry in the list until the 572: * timeline signal actually advances the timeline's value. This ensures 573: * subsequent query ioctls return a monotonically increasing seqno. 574: */ 575: spin_lock_irq(&timeline->lock); 576: seqno = timeline->value; 577: list_for_each_entry_reverse(event, &timeline->events, node) { 578: if (kgsl_check_timestamp(event->context->device, 579: event->context, event->timestamp)) { 580: seqno = event->seqno; 581: break; 582: } 583: } 584: spin_unlock_irq(&timeline->lock); 585: 586: param->seqno = seqno; 587: kgsl_timeline_put(timeline); 588: 589: return 0; 590: } 591: 592: long kgsl_ioctl_timeline_fence_get(struct kgsl_device_private *dev_priv, 593: unsigned int cmd, void *data) 594: { 595: struct kgsl_device *device = dev_priv->device; 596: struct kgsl_timeline_fence_get *param = data; 597: struct kgsl_timeline *timeline; 598: struct sync_file *sync_file; 599: struct dma_fence *fence; 600: int ret = 0, fd; 601: 602: timeline = kgsl_timeline_by_id(device, param->timeline); 603: if (!timeline) 604: return -ENODEV; 605: 606: fence = kgsl_timeline_fence_alloc(timeline, param->seqno); 607: 608: if (IS_ERR(fence)) { 609: kgsl_timeline_put(timeline); 610: return PTR_ERR(fence); 611: } 612: 613: fd = get_unused_fd_flags(O_CLOEXEC); 614: if (fd < 0) { 615: ret = fd; 616: goto out; 617: } 618: 619: sync_file = sync_file_create(fence); 620: if (sync_file) { 621: fd_install(fd, sync_file->file); 622: param->handle = fd; 623: } else { 624: put_unused_fd(fd); 625: ret = -ENOMEM; 626: } 627: 628: out: 629: dma_fence_put(fence); 630: kgsl_timeline_put(timeline); 631: 632: return ret; 633: } 634: 635: long kgsl_ioctl_timeline_signal(struct kgsl_device_private *dev_priv, 636: unsigned int cmd, void *data) 637: { 638: struct kgsl_device *device = dev_priv->device; 639: struct kgsl_timeline_signal *param = data; 640: u64 timelines; 641: int i; 642: 643: if (!param->timelines_size) { 644: param->timelines_size = sizeof(struct kgsl_timeline_val); 645: return -EAGAIN; 646: } 647: 648: if (!param->count) 649: return -EINVAL; 650: 651: timelines = param->timelines; 652: 653: for (i = 0; i < param->count; i++) { MATCH LINES: 682, 712, 713, 714, 715, 716, 717, 720, 721, 722, 723 670: kgsl_timeline_put(timeline); 671: 672: timelines += param->timelines_size; 673: } 674: 675: return 0; 676: } 677: 678: long kgsl_ioctl_timeline_destroy(struct kgsl_device_private *dev_priv, 679: unsigned int cmd, void *data) 680: { 681: struct kgsl_device *device = dev_priv->device; 682: struct kgsl_timeline_fence *fence, *tmp; 683: struct kgsl_timeline *timeline; 684: struct list_head temp; 685: u32 *param = data; 686: 687: if (*param == 0) 688: return -ENODEV; 689: 690: spin_lock(&device->timelines_lock); 691: timeline = idr_find(&device->timelines, *param); 692: 693: if (timeline == NULL) { 694: spin_unlock(&device->timelines_lock); 695: return -ENODEV; 696: } 697: 698: /* 699: * Validate that the id given is owned by the dev_priv 700: * instance that is passed in. If not, abort. 701: */ 702: if (timeline->dev_priv != dev_priv) { 703: spin_unlock(&device->timelines_lock); 704: return -EINVAL; 705: } 706: 707: idr_remove(&device->timelines, timeline->id); 708: spin_unlock(&device->timelines_lock); 709: 710: INIT_LIST_HEAD(&temp); 711: 712: spin_lock(&timeline->fence_lock); 713: list_for_each_entry_safe(fence, tmp, &timeline->fences, node) 714: if (!kref_get_unless_zero(&fence->base.refcount)) 715: list_del_init(&fence->node); 716: list_replace_init(&timeline->fences, &temp); 717: spin_unlock(&timeline->fence_lock); 718: 719: spin_lock_irq(&timeline->lock); 720: list_for_each_entry_safe(fence, tmp, &temp, node) { 721: dma_fence_set_error(&fence->base, -ENOENT); 722: dma_fence_signal_locked(&fence->base); 723: dma_fence_put(&fence->base); 724: } 725: spin_unlock_irq(&timeline->lock); 726: 727: kgsl_timeline_put(timeline); 728: 729: return 0; 730: } --- FILE: \kgsl_timeline.h | HITS: 25 --- MATCH LINES: 14, 20, 21, 22, 26, 27, 46, 47, 53, 54, 58, 61, 63, 66, 82, 97, 99, 101, 103, 105, 142, 148, 149, 150, 152 2: /* 3: * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #ifndef __KGSL_TIMELINE_H 8: #define __KGSL_TIMELINE_H 9: 10: /** 11: * struct kgsl_timeline - Container for a timeline object 12: */ 13: struct kgsl_timeline { 14: /** @context: dma-fence timeline context */ 15: u64 context; 16: /** @id: Timeline identifier */ 17: int id; 18: /** @value: Current value of the timeline */ 19: u64 value; 20: /** @fence_lock: Lock to protect @fences */ 21: spinlock_t fence_lock; 22: /** @lock: Lock to use for locking each fence in @fences */ 23: spinlock_t lock; 24: /** @ref: Reference count for the struct */ 25: struct kref ref; 26: /** @fences: sorted list of active fences */ 27: struct list_head fences; 28: /** @events: sorted list of events to be retired */ 29: struct list_head events; 30: /** @name: Name of the timeline for debugging */ 31: const char name[32]; 32: /** @dev_priv: pointer to the owning device instance */ 33: struct kgsl_device_private *dev_priv; 34: }; 35: 36: /** 37: * struct kgsl_timeline_event - Contains data to signal a timeline 38: */ 39: struct kgsl_timeline_event { 40: /** @timeline: Pointer to the timeline to signal */ 41: struct kgsl_timeline *timeline; 42: /** @seqno: seqno of the timeline to signal */ 43: u64 seqno; 44: /** @context: context this event is waiting for */ 45: struct kgsl_context *context; 46: /** @timestamp: context timestamp this event is waiting for */ 47: unsigned int timestamp; 48: /** @node: list node */ 49: struct list_head node; 50: }; 51: 52: /** 53: * kgsl_fence_timeline_value_str - Get the timeline value as a string 54: * @fence: Pointer to the dma_fence object 55: * @value: Pointer to the character buffer to store the value string 56: * @size: Size of the character buffer 57: * 58: * This function retrieves the timeline value from a DMA fence as a string and 59: * copies at most @size characters into @value. 60: * It delegates to the appropriate timeline_value_str implementation based on 61: * the fence operations. 62: * 63: * If either the fence, fence operations, or value pointer is NULL, the function 64: * returns without doing anything. 65: */ 66: void kgsl_fence_timeline_value_str(struct dma_fence *fence, char *value, 67: size_t size); 68: 69: /** 70: * kgsl_timeline_add_signal - Notify a timeline of an upcoming signal 71: * @signal: Pointer to a kgsl_timeline_event 72: * 73: * Notify the timeline that a GPU AUX command is expected to signal. 74: */ 75: void kgsl_timeline_add_signal(struct kgsl_timeline_event *signal); 76: 77: /** 78: * kgsl_timeline_signal - Signal the timeline 79: * @timeline: Pointer to a timeline container 80: * @seqno: Seqeuence number to signal 81: * 82: * Advance @timeline to sequence number @seqno and signal any fences that might 83: * have expired. 84: */ 85: void kgsl_timeline_signal(struct kgsl_timeline *timeline, u64 seqno); 86: 87: /** 88: * kgsl_timeline_destroy - Timeline destroy callback 89: * @kref: Refcount pointer for the timeline 90: * 91: * Reference count callback for the timeline called when the all the object 92: * references have been released. 93: */ 94: void kgsl_timeline_destroy(struct kref *kref); 95: 96: /** 97: * kgsl_timeline_fence_alloc - Allocate a new fence on a timeline 98: * @timeline: Pointer to a timeline container 99: * @seqno: Sequence number for the new fence to wait for 100: * 101: * Create and return a new fence on the timeline that will expire when the 102: * timeline value is greater or equal to @seqno. 103: * Return: A pointer to the newly created fence 104: */ 105: struct dma_fence *kgsl_timeline_fence_alloc(struct kgsl_timeline *timeline, 106: u64 seqno); 107: 108: /** 109: * kgsl_timeline_by_id - Look up a timeline by an id 110: * @device: A KGSL device handle 111: * @id: Lookup identifier 112: * 113: * Find and return the timeline associated with identifer @id. 114: * Return: A pointer to a timeline or PTR_ERR() encoded error on failure. 115: */ 116: struct kgsl_timeline *kgsl_timeline_by_id(struct kgsl_device *device, 117: u32 id); 118: 119: /** 120: * kgsl_timeline_get - Get a reference to an existing timeline 121: * @timeline: Pointer to a timeline container 122: * 123: * Get a new reference to the timeline and return the pointer back to the user. 124: * Return: The pointer to the timeline or PTR_ERR encoded error on failure 125: */ 126: struct kgsl_timeline *kgsl_timeline_get(struct kgsl_timeline *timeline); 127: 128: /** 129: * kgsl_timeline_put - Release a reference to a timeline 130: * @timeline: Pointer to a timeline container 131: * 132: * Release a reference to a timeline and destroy it if there are no other 133: * references 134: */ 135: static inline void kgsl_timeline_put(struct kgsl_timeline *timeline) 136: { 137: if (!IS_ERR_OR_NULL(timeline)) 138: kref_put(&timeline->ref, kgsl_timeline_destroy); 139: } 140: 141: /** 142: * kgsl_timelines_to_fence_array - Return a dma-fence array of timeline fences 143: * @device: A KGSL device handle 144: * @timelines: Userspace pointer to an array of &struct kgsl_timeline_val 145: * @count: Number of entries in @timelines 146: * @usize: Size of each entry in @timelines 147: * 148: * Given a list of &struct kgsl_timeline_val entries, create a dma-fence-array 149: * containing fences for each timeline/seqno pair. The fence will wait for ALL 150: * of the encapsulated timeline fences to expire. 151: */ 152: struct dma_fence *kgsl_timelines_to_fence_array(struct kgsl_device *device, 153: u64 timelines, u32 count, u64 usize); 154: 155: #endif --- FILE: \kgsl_trace.h | HITS: 52 --- MATCH LINES: 49, 59, 64, 71, 81, 92, 101, 103, 108, 110, 116, 123, 131, 136, 138, 175, 177 37: { KGSL_MEM_ENTRY_KERNEL, "gpumem" }, \ 38: { KGSL_MEM_ENTRY_USER, "usermem" }, \ 39: { KGSL_MEM_ENTRY_ION, "ion" }) 40: 41: #define show_constraint(type) \ 42: __print_symbolic(type, \ 43: { KGSL_CONSTRAINT_NONE, "None" }, \ 44: { KGSL_CONSTRAINT_PWRLEVEL, "Pwrlevel" }, \ 45: { KGSL_CONSTRAINT_L3_NONE, "L3_none" }, \ 46: { KGSL_CONSTRAINT_L3_PWRLEVEL, "L3_pwrlevel" }) 47: 48: struct kgsl_ringbuffer_issueibcmds; 49: struct kgsl_device_waittimestamp; 50: 51: /* 52: * Tracepoint for kgsl issue ib commands 53: */ 54: TRACE_EVENT(kgsl_issueibcmds, 55: 56: TP_PROTO(struct kgsl_device *device, 57: int drawctxt_id, 58: unsigned int numibs, 59: int timestamp, 60: int flags, 61: int result, 62: unsigned int type), 63: 64: TP_ARGS(device, drawctxt_id, numibs, timestamp, 65: flags, result, type), 66: 67: TP_STRUCT__entry( 68: __string(device_name, device->name) 69: __field(unsigned int, drawctxt_id) 70: __field(unsigned int, numibs) 71: __field(unsigned int, timestamp) 72: __field(unsigned int, flags) 73: __field(int, result) 74: __field(unsigned int, drawctxt_type) 75: ), 76: 77: TP_fast_assign( 78: kgsl_assign_str(device_name, device->name); 79: __entry->drawctxt_id = drawctxt_id; 80: __entry->numibs = numibs; 81: __entry->timestamp = timestamp; 82: __entry->flags = flags; 83: __entry->result = result; 84: __entry->drawctxt_type = type; 85: ), 86: 87: TP_printk( 88: "d_name=%s ctx=%u ib=0x0 numibs=%u ts=%u flags=%s result=%d type=%s", 89: __get_str(device_name), 90: __entry->drawctxt_id, 91: __entry->numibs, 92: __entry->timestamp, 93: __entry->flags ? __print_flags(__entry->flags, "|", 94: KGSL_DRAWOBJ_FLAGS) : "None", 95: __entry->result, 96: kgsl_context_type(__entry->drawctxt_type) 97: ) 98: ); 99: 100: /* 101: * Tracepoint for kgsl readtimestamp 102: */ 103: TRACE_EVENT(kgsl_readtimestamp, 104: 105: TP_PROTO(struct kgsl_device *device, 106: unsigned int context_id, 107: unsigned int type, 108: unsigned int timestamp), 109: 110: TP_ARGS(device, context_id, type, timestamp), 111: 112: TP_STRUCT__entry( 113: __string(device_name, device->name) 114: __field(unsigned int, context_id) 115: __field(unsigned int, type) 116: __field(unsigned int, timestamp) 117: ), 118: 119: TP_fast_assign( 120: kgsl_assign_str(device_name, device->name); 121: __entry->context_id = context_id; 122: __entry->type = type; 123: __entry->timestamp = timestamp; 124: ), 125: 126: TP_printk( 127: "d_name=%s context_id=%u type=%u ts=%u", 128: __get_str(device_name), 129: __entry->context_id, 130: __entry->type, 131: __entry->timestamp 132: ) 133: ); 134: 135: /* 136: * Tracepoint for kgsl waittimestamp entry 137: */ 138: TRACE_EVENT(kgsl_waittimestamp_entry, 139: 140: TP_PROTO(struct kgsl_device *device, 141: unsigned int context_id, 142: unsigned int curr_ts, 143: unsigned int wait_ts, 144: unsigned int timeout), 145: 146: TP_ARGS(device, context_id, curr_ts, wait_ts, timeout), 147: 148: TP_STRUCT__entry( 149: __string(device_name, device->name) 150: __field(unsigned int, context_id) 151: __field(unsigned int, curr_ts) 152: __field(unsigned int, wait_ts) 153: __field(unsigned int, timeout) 154: ), 155: 156: TP_fast_assign( 157: kgsl_assign_str(device_name, device->name); 158: __entry->context_id = context_id; 159: __entry->curr_ts = curr_ts; 160: __entry->wait_ts = wait_ts; 161: __entry->timeout = timeout; 162: ), 163: 164: TP_printk( 165: "d_name=%s ctx=%u curr_ts=%u ts=%u timeout=%u", 166: __get_str(device_name), 167: __entry->context_id, 168: __entry->curr_ts, 169: __entry->wait_ts, 170: __entry->timeout 171: ) 172: ); 173: 174: /* 175: * Tracepoint for kgsl waittimestamp exit 176: */ 177: TRACE_EVENT(kgsl_waittimestamp_exit, 178: 179: TP_PROTO(struct kgsl_device *device, unsigned int curr_ts, 180: int result), 181: 182: TP_ARGS(device, curr_ts, result), 183: 184: TP_STRUCT__entry( 185: __string(device_name, device->name) 186: __field(unsigned int, curr_ts) 187: __field(int, result) 188: ), 189: 190: TP_fast_assign( 191: kgsl_assign_str(device_name, device->name); 192: __entry->curr_ts = curr_ts; 193: __entry->result = result; 194: ), 195: 196: TP_printk( 197: "d_name=%s curr_ts=%u result=%d", 198: __get_str(device_name), 199: __entry->curr_ts, 200: __entry->result 201: ) MATCH LINES: 761 749: 750: TP_fast_assign( 751: __entry->num_bufs = num_bufs; 752: __entry->bulk_size = bulk_size; 753: ), 754: 755: TP_printk( 756: "num_bufs=%u bulk_size=%llu op=ci", 757: __entry->num_bufs, __entry->bulk_size 758: ) 759: ); 760: 761: DECLARE_EVENT_CLASS(kgsl_mem_timestamp_template, 762: 763: TP_PROTO(struct kgsl_device *device, struct kgsl_mem_entry *mem_entry, 764: unsigned int id, unsigned int curr_ts, unsigned int free_ts), 765: 766: TP_ARGS(device, mem_entry, id, curr_ts, free_ts), 767: 768: TP_STRUCT__entry( 769: __string(device_name, device->name) 770: __field(uint64_t, gpuaddr) 771: __field(uint64_t, size) 772: __field(int, type) 773: __array(char, usage, 16) 774: __field(unsigned int, id) 775: __field(unsigned int, drawctxt_id) 776: __field(unsigned int, curr_ts) 777: __field(unsigned int, free_ts) 778: ), 779: 780: TP_fast_assign( 781: kgsl_assign_str(device_name, device->name); 782: __entry->gpuaddr = mem_entry->memdesc.gpuaddr; 783: __entry->size = mem_entry->memdesc.size; 784: kgsl_get_memory_usage(__entry->usage, sizeof(__entry->usage), 785: mem_entry->memdesc.flags); MATCH LINES: 807, 813 795: __get_str(device_name), 796: __entry->gpuaddr, 797: __entry->size, 798: show_memtype(__entry->type), 799: __entry->usage, 800: __entry->id, 801: __entry->drawctxt_id, 802: __entry->curr_ts, 803: __entry->free_ts 804: ) 805: ); 806: 807: DEFINE_EVENT(kgsl_mem_timestamp_template, kgsl_mem_timestamp_queue, 808: TP_PROTO(struct kgsl_device *device, struct kgsl_mem_entry *mem_entry, 809: unsigned int id, unsigned int curr_ts, unsigned int free_ts), 810: TP_ARGS(device, mem_entry, id, curr_ts, free_ts) 811: ); 812: 813: DEFINE_EVENT(kgsl_mem_timestamp_template, kgsl_mem_timestamp_free, 814: TP_PROTO(struct kgsl_device *device, struct kgsl_mem_entry *mem_entry, 815: unsigned int id, unsigned int curr_ts, unsigned int free_ts), 816: TP_ARGS(device, mem_entry, id, curr_ts, free_ts) 817: ); 818: 819: TRACE_EVENT(kgsl_context_create, 820: 821: TP_PROTO(struct kgsl_device *device, struct kgsl_context *context, 822: unsigned int flags), 823: 824: TP_ARGS(device, context, flags), 825: 826: TP_STRUCT__entry( 827: __string(device_name, device->name) 828: __field(unsigned int, id) 829: __field(unsigned int, flags) 830: __field(unsigned int, priority) 831: __field(unsigned int, type) 832: ), 833: 834: TP_fast_assign( 835: kgsl_assign_str(device_name, device->name); 836: __entry->id = context->id; 837: __entry->flags = flags & ~(KGSL_CONTEXT_PRIORITY_MASK | MATCH LINES: 1020, 1021, 1024, 1029, 1034 1008: kgsl_assign_str(device_name, "kgsl-3d0"); 1009: __entry->offset = offset; 1010: __entry->value = value; 1011: ), 1012: 1013: TP_printk( 1014: "d_name=%s reg=0x%x value=0x%x", 1015: __get_str(device_name), __entry->offset, __entry->value 1016: ) 1017: ); 1018: 1019: TRACE_EVENT(kgsl_register_event, 1020: TP_PROTO(unsigned int id, unsigned int timestamp, void *func), 1021: TP_ARGS(id, timestamp, func), 1022: TP_STRUCT__entry( 1023: __field(unsigned int, id) 1024: __field(unsigned int, timestamp) 1025: __field(void *, func) 1026: ), 1027: TP_fast_assign( 1028: __entry->id = id; 1029: __entry->timestamp = timestamp; 1030: __entry->func = func; 1031: ), 1032: TP_printk( 1033: "ctx=%u ts=%u cb=%pS", 1034: __entry->id, __entry->timestamp, __entry->func) 1035: ); 1036: 1037: TRACE_EVENT(kgsl_fire_event, 1038: TP_PROTO(unsigned int id, unsigned int ts, 1039: unsigned int type, unsigned int age, void *func), 1040: TP_ARGS(id, ts, type, age, func), 1041: TP_STRUCT__entry( 1042: __field(unsigned int, id) 1043: __field(unsigned int, ts) 1044: __field(unsigned int, type) 1045: __field(unsigned int, age) 1046: __field(void *, func) 1047: ), 1048: TP_fast_assign( 1049: __entry->id = id; 1050: __entry->ts = ts; 1051: __entry->type = type; 1052: __entry->age = age; 1053: __entry->func = func; 1054: ), 1055: TP_printk( 1056: "ctx=%u ts=%u type=%s age=%u cb=%pS", 1057: __entry->id, __entry->ts, 1058: __print_symbolic(__entry->type, MATCH LINES: 1102, 1105, 1106, 1110, 1115, 1119, 1122, 1125, 1126, 1129, 1132, 1133, 1136, 1140, 1145, 1147, 1148, 1151, 1156 1090: TP_ARGS(ptbase, name), 1091: TP_STRUCT__entry( 1092: __field(u64, ptbase) 1093: __field(unsigned int, name) 1094: ), 1095: TP_fast_assign( 1096: __entry->ptbase = ptbase; 1097: __entry->name = name; 1098: ), 1099: TP_printk("ptbase=%llx name=%u", __entry->ptbase, __entry->name) 1100: ); 1101: 1102: DECLARE_EVENT_CLASS(syncpoint_timestamp_template, 1103: TP_PROTO(struct kgsl_drawobj_sync *syncobj, 1104: struct kgsl_context *context, 1105: unsigned int timestamp), 1106: TP_ARGS(syncobj, context, timestamp), 1107: TP_STRUCT__entry( 1108: __field(unsigned int, syncobj_context_id) 1109: __field(unsigned int, context_id) 1110: __field(unsigned int, timestamp) 1111: ), 1112: TP_fast_assign( 1113: __entry->syncobj_context_id = syncobj->base.context->id; 1114: __entry->context_id = context->id; 1115: __entry->timestamp = timestamp; 1116: ), 1117: TP_printk("ctx=%u sync ctx=%u ts=%u", 1118: __entry->syncobj_context_id, __entry->context_id, 1119: __entry->timestamp) 1120: ); 1121: 1122: DEFINE_EVENT(syncpoint_timestamp_template, syncpoint_timestamp, 1123: TP_PROTO(struct kgsl_drawobj_sync *syncobj, 1124: struct kgsl_context *context, 1125: unsigned int timestamp), 1126: TP_ARGS(syncobj, context, timestamp) 1127: ); 1128: 1129: DEFINE_EVENT(syncpoint_timestamp_template, syncpoint_timestamp_expire, 1130: TP_PROTO(struct kgsl_drawobj_sync *syncobj, 1131: struct kgsl_context *context, 1132: unsigned int timestamp), 1133: TP_ARGS(syncobj, context, timestamp) 1134: ); 1135: 1136: DECLARE_EVENT_CLASS(syncpoint_fence_template, 1137: TP_PROTO(struct kgsl_drawobj_sync *syncobj, char *name), 1138: TP_ARGS(syncobj, name), 1139: TP_STRUCT__entry( 1140: __string(fence_name, name) 1141: __field(unsigned int, syncobj_context_id) 1142: ), 1143: TP_fast_assign( 1144: __entry->syncobj_context_id = syncobj->base.context->id; 1145: kgsl_assign_str(fence_name, name); 1146: ), 1147: TP_printk("ctx=%u fence=%s", 1148: __entry->syncobj_context_id, __get_str(fence_name)) 1149: ); 1150: 1151: DEFINE_EVENT(syncpoint_fence_template, syncpoint_fence, 1152: TP_PROTO(struct kgsl_drawobj_sync *syncobj, char *name), 1153: TP_ARGS(syncobj, name) 1154: ); 1155: 1156: DEFINE_EVENT(syncpoint_fence_template, syncpoint_fence_expire, 1157: TP_PROTO(struct kgsl_drawobj_sync *syncobj, char *name), 1158: TP_ARGS(syncobj, name) 1159: ); 1160: 1161: TRACE_EVENT(kgsl_msg, 1162: TP_PROTO(const char *msg), 1163: TP_ARGS(msg), 1164: TP_STRUCT__entry( 1165: __string(msg, msg) 1166: ), 1167: TP_fast_assign( 1168: kgsl_assign_str(msg, msg); 1169: ), 1170: TP_printk( 1171: "%s", __get_str(msg) 1172: ) 1173: ); 1174: 1175: TRACE_EVENT(kgsl_clock_throttling, 1176: TP_PROTO( 1177: int idle_10pct, 1178: int crc_50pct, 1179: int crc_more50pct, 1180: int crc_less50pct, MATCH LINES: 1349, 1371 1337: __field(u32, id) 1338: __field(u64, seqno) 1339: ), 1340: TP_fast_assign( 1341: __entry->id = id; 1342: __entry->seqno = seqno; 1343: ), 1344: TP_printk("id=%u seqno=%llu", 1345: __entry->id, __entry->seqno 1346: ) 1347: ); 1348: 1349: TRACE_EVENT(kgsl_timeline_fence_alloc, 1350: TP_PROTO( 1351: u32 timeline, 1352: u64 seqno 1353: ), 1354: TP_ARGS( 1355: timeline, 1356: seqno 1357: ), 1358: TP_STRUCT__entry( 1359: __field(u32, timeline) 1360: __field(u64, seqno) 1361: ), 1362: TP_fast_assign( 1363: __entry->timeline = timeline; 1364: __entry->seqno = seqno; 1365: ), 1366: TP_printk("timeline=%u seqno=%llu", 1367: __entry->timeline, __entry->seqno 1368: ) 1369: ); 1370: 1371: TRACE_EVENT(kgsl_timeline_fence_release, 1372: TP_PROTO( 1373: u32 timeline, 1374: u64 seqno 1375: ), 1376: TP_ARGS( 1377: timeline, 1378: seqno 1379: ), 1380: TP_STRUCT__entry( 1381: __field(u32, timeline) 1382: __field(u64, seqno) 1383: ), 1384: TP_fast_assign( 1385: __entry->timeline = timeline; 1386: __entry->seqno = seqno; 1387: ), 1388: TP_printk("timeline=%u seqno=%llu", 1389: __entry->timeline, __entry->seqno 1390: ) 1391: ); 1392: 1393: 1394: TRACE_EVENT(kgsl_timeline_wait, 1395: TP_PROTO( MATCH LINES: 1422, 1424, 1430, 1436, 1438, 1440 1410: TP_fast_assign( 1411: __entry->flags = flags; 1412: __entry->tv_sec = tv_sec; 1413: __entry->tv_nsec = tv_nsec; 1414: ), 1415: TP_printk("flags=0x%x tv_sec=%llu tv_nsec=%llu", 1416: __entry->flags, __entry->tv_sec, __entry->tv_nsec 1417: 1418: ) 1419: ); 1420: 1421: TRACE_EVENT(kgsl_aux_command, 1422: TP_PROTO(u32 drawctxt_id, u32 numcmds, u32 flags, u32 timestamp 1423: ), 1424: TP_ARGS(drawctxt_id, numcmds, flags, timestamp 1425: ), 1426: TP_STRUCT__entry( 1427: __field(u32, drawctxt_id) 1428: __field(u32, numcmds) 1429: __field(u32, flags) 1430: __field(u32, timestamp) 1431: ), 1432: TP_fast_assign( 1433: __entry->drawctxt_id = drawctxt_id; 1434: __entry->numcmds = numcmds; 1435: __entry->flags = flags; 1436: __entry->timestamp = timestamp; 1437: ), 1438: TP_printk("context=%u numcmds=%u flags=0x%x timestamp=%u", 1439: __entry->drawctxt_id, __entry->numcmds, __entry->flags, 1440: __entry->timestamp 1441: ) 1442: ); 1443: 1444: TRACE_EVENT(kgsl_drawobj_timeline, 1445: TP_PROTO(u32 timeline, u64 seqno 1446: ), 1447: TP_ARGS(timeline, seqno 1448: ), 1449: TP_STRUCT__entry( 1450: __field(u32, timeline) 1451: __field(u64, seqno) 1452: ), 1453: TP_fast_assign( 1454: __entry->timeline = timeline; 1455: __entry->seqno = seqno; 1456: ), 1457: TP_printk("timeline=%u seqno=%llu", 1458: __entry->timeline, __entry->seqno 1459: ) 1460: ); 1461: 1462: TRACE_EVENT(kgsl_thermal_constraint, 1463: TP_PROTO( 1464: s32 max_freq --- FILE: \kgsl_util.c | HITS: 4 --- MATCH LINES: 362, 371, 372, 375 350: return 0; 351: } 352: #endif 353: 354: #ifdef CONFIG_SYNC_FILE 355: static int kgsl_add_sync_timeline_info_to_va_minidump(struct kgsl_device *device) 356: { 357: int ret, id; 358: struct kgsl_context *context; 359: 360: idr_for_each_entry(&device->context_idr, context, id) { 361: char name[MAX_VA_MINIDUMP_STR_LEN]; 362: struct kgsl_sync_fence *kfence, *next; 363: struct kgsl_sync_timeline *ktimeline = context->ktimeline; 364: 365: snprintf(name, sizeof(name), KGSL_SYNC_TIMELINE_ENTRY "_ctxt:%d", context->id); 366: ret = kgsl_add_va_to_minidump(device->dev, name, 367: (void *)(ktimeline), sizeof(*ktimeline)); 368: if (ret) 369: return ret; 370: 371: list_for_each_entry_safe(kfence, next, &ktimeline->child_list_head, child_list) { 372: snprintf(name, sizeof(name), KGSL_SYNC_FENCE_ENTRY "_ctxt:%d", 373: context->id); 374: ret = kgsl_add_va_to_minidump(device->dev, name, 375: (void *)(kfence), sizeof(*kfence)); 376: if (ret) 377: return ret; 378: } 379: } 380: 381: return 0; 382: } 383: #else 384: static int kgsl_add_sync_timeline_info_to_va_minidump(struct kgsl_device *device) 385: { 386: return 0; 387: } 388: #endif 389: 390: static int kgsl_add_driver_data_to_va_minidump(struct kgsl_device *device) 391: { 392: int ret; 393: char name[MAX_VA_MINIDUMP_STR_LEN]; 394: struct kgsl_pagetable *pt; 395: struct adreno_context *ctxt; 396: struct kgsl_process_private *p; 397: struct kgsl_global_memdesc *md; 398: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 399: --- FILE: \kgsl_util.h | HITS: 1 --- MATCH LINES: 35 23: #define KGSL_HFIMEM_ENTRY "kgsl_hfi_mem" 24: #define KGSL_GMU_DUMPMEM_ENTRY "kgsl_gmu_dump_mem" 25: #define KGSL_GMU_RB_ENTRY "gmu_rb" 26: #define KGSL_GMU_KERNEL_PROF_ENTRY "gmu_kernel_profiling" 27: #define KGSL_GMU_USER_PROF_ENTRY "gmu_user_profiling" 28: #define KGSL_GMU_CMD_BUFFER_ENTRY "gmu_cmd_buffer" 29: #define KGSL_HFI_BIG_IB_ENTRY "kgsl_hfi_big_ib" 30: #define KGSL_HFI_BIG_IB_REC_ENTRY "kgsl_hfi_big_ib_rec" 31: #define KGSL_ADRENO_CTX_ENTRY "kgsl_adreno_ctx" 32: #define KGSL_PROC_PRIV_ENTRY "kgsl_proc_priv" 33: #define KGSL_PGTABLE_ENTRY "kgsl_pgtable" 34: #define KGSL_GMU_VRB_ENTRY "kgsl_gmu_vrb" 35: #define KGSL_SYNC_FENCE_ENTRY "kgsl_sync_fence" 36: #define KGSL_SYNC_TIMELINE_ENTRY "kgsl_sync_timeline" 37: #define KGSL_PAGE_POOL_ENTRY "kgsl_page_pool" 38: #define KGSL_ADRENO_TZ_DATA_ENTRY "kgsl_adreno_tz_data" 39: #define KGSL_NC_OVERRIDES_ENTRY "kgsl_nc_overrides" 40: 41: #define MAX_VA_MINIDUMP_STR_LEN 48 42: 43: 44: /** 45: * Request TZ to program set of access controlled registers that KGSL needs 46: * irrespective of any features 47: */ 48: #define GPU_ALWAYS_EN_REQ BIT(0) 49: /** 50: * Request TZ to program BCL id to access controlled register when BCL is 51: * enabled 52: */ 53: #define GPU_BCL_EN_REQ BIT(1) 54: /** 55: * Request TZ to program set of access controlled register for CLX feature 56: * when enabled 57: */ 58: #define GPU_CLX_EN_REQ BIT(2) 59: /** --- FILE: \kgsl_vbo.c | HITS: 42 --- MATCH LINES: 602, 603, 609, 614, 619, 621, 622, 624, 625, 629, 631, 633, 634, 637, 638, 639, 640, 643, 644, 646, 650, 651, 654, 656, 657, 661, 665, 668, 674, 675, 677, 694, 695, 706, 708, 709, 711, 713, 716, 717, 718, 723 590: kgsl_sharedmem_put_bind_op(op); 591: } 592: 593: void kgsl_sharedmem_bind_ranges(struct kgsl_sharedmem_bind_op *op) 594: { 595: /* Take a reference to the operation while it is scheduled */ 596: kref_get(&op->ref); 597: 598: INIT_WORK(&op->work, kgsl_sharedmem_bind_worker); 599: schedule_work(&op->work); 600: } 601: 602: struct kgsl_sharedmem_bind_fence { 603: struct dma_fence base; 604: spinlock_t lock; 605: int fd; 606: struct kgsl_sharedmem_bind_op *op; 607: }; 608: 609: static const char *bind_fence_get_driver_name(struct dma_fence *fence) 610: { 611: return "kgsl_sharedmem_bind"; 612: } 613: 614: static const char *bind_fence_get_timeline_name(struct dma_fence *fence) 615: { 616: return "(unbound)"; 617: } 618: 619: static void bind_fence_release(struct dma_fence *fence) 620: { 621: struct kgsl_sharedmem_bind_fence *bind_fence = container_of(fence, 622: struct kgsl_sharedmem_bind_fence, base); 623: 624: kgsl_sharedmem_put_bind_op(bind_fence->op); 625: kfree(bind_fence); 626: } 627: 628: static void 629: kgsl_sharedmem_bind_fence_callback(struct kgsl_sharedmem_bind_op *op) 630: { 631: struct kgsl_sharedmem_bind_fence *bind_fence = op->data; 632: 633: dma_fence_signal(&bind_fence->base); 634: dma_fence_put(&bind_fence->base); 635: } 636: 637: static const struct dma_fence_ops kgsl_sharedmem_bind_fence_ops = { 638: .get_driver_name = bind_fence_get_driver_name, 639: .get_timeline_name = bind_fence_get_timeline_name, 640: .release = bind_fence_release, 641: }; 642: 643: static struct kgsl_sharedmem_bind_fence * 644: kgsl_sharedmem_bind_fence(struct kgsl_sharedmem_bind_op *op) 645: { 646: struct kgsl_sharedmem_bind_fence *fence; 647: struct sync_file *sync_file; 648: int fd; 649: 650: fence = kzalloc(sizeof(*fence), GFP_KERNEL); 651: if (!fence) 652: return ERR_PTR(-ENOMEM); 653: 654: spin_lock_init(&fence->lock); 655: 656: dma_fence_init(&fence->base, &kgsl_sharedmem_bind_fence_ops, 657: &fence->lock, dma_fence_context_alloc(1), 0); 658: 659: fd = get_unused_fd_flags(O_CLOEXEC); 660: if (fd < 0) { 661: kfree(fence); 662: return ERR_PTR(fd); 663: } 664: 665: sync_file = sync_file_create(&fence->base); 666: if (!sync_file) { 667: put_unused_fd(fd); 668: kfree(fence); 669: return ERR_PTR(-ENOMEM); 670: } 671: 672: fd_install(fd, sync_file->file); 673: 674: fence->fd = fd; 675: fence->op = op; 676: 677: return fence; 678: } 679: 680: long kgsl_ioctl_gpumem_bind_ranges(struct kgsl_device_private *dev_priv, 681: unsigned int cmd, void *data) 682: { 683: struct kgsl_process_private *private = dev_priv->process_priv; 684: struct kgsl_gpumem_bind_ranges *param = data; 685: struct kgsl_sharedmem_bind_op *op; 686: int ret; 687: 688: /* If ranges_size isn't set, return the expected size to the user */ 689: if (!param->ranges_size) { 690: param->ranges_size = sizeof(struct kgsl_gpumem_bind_range); 691: return 0; 692: } 693: 694: /* FENCE_OUT only makes sense with ASYNC */ 695: if ((param->flags & KGSL_GPUMEM_BIND_FENCE_OUT) && 696: !(param->flags & KGSL_GPUMEM_BIND_ASYNC)) 697: return -EINVAL; 698: 699: op = kgsl_sharedmem_create_bind_op(private, param->id, 700: u64_to_user_ptr(param->ranges), param->ranges_nents, 701: param->ranges_size); 702: if (IS_ERR(op)) 703: return PTR_ERR(op); 704: 705: if (param->flags & KGSL_GPUMEM_BIND_ASYNC) { 706: struct kgsl_sharedmem_bind_fence *fence; 707: 708: if (param->flags & KGSL_GPUMEM_BIND_FENCE_OUT) { 709: fence = kgsl_sharedmem_bind_fence(op); 710: 711: if (IS_ERR(fence)) { 712: kgsl_sharedmem_put_bind_op(op); 713: return PTR_ERR(fence); 714: } 715: 716: op->data = fence; 717: op->callback = kgsl_sharedmem_bind_fence_callback; 718: param->fence_id = fence->fd; 719: } 720: 721: kgsl_sharedmem_bind_ranges(op); 722: 723: if (!(param->flags & KGSL_GPUMEM_BIND_FENCE_OUT)) 724: kgsl_sharedmem_put_bind_op(op); 725: 726: return 0; 727: } 728: 729: /* 730: * Schedule the work. All the resources will be released after 731: * the bind operation is done 732: */ 733: kgsl_sharedmem_bind_ranges(op); 734: 735: ret = wait_for_completion_interruptible(&op->comp); 736: kgsl_sharedmem_put_bind_op(op); 737: 738: return ret; 739: } --- FILE: \config\gki_niobe.conf | HITS: 1 --- MATCH LINES: 20 8: CONFIG_QCOM_ADRENO_DEFAULT_GOVERNOR = \"msm-adreno-tz\" 9: CONFIG_QCOM_KGSL_SYNX=y 10: 11: ifneq ($(CONFIG_CORESIGHT),) 12: CONFIG_QCOM_KGSL_CORESIGHT = y 13: endif 14: 15: ccflags-y += -DCONFIG_QCOM_KGSL_IDLE_TIMEOUT=80 \ 16: -DCONFIG_QCOM_KGSL_SORT_POOL=1 \ 17: -DCONFIG_QCOM_KGSL_CONTEXT_DEBUG=1 \ 18: -DCONFIG_QCOM_KGSL_IOCOHERENCY_DEFAULT=1 \ 19: -DCONFIG_QCOM_ADRENO_DEFAULT_GOVERNOR=\"msm-adreno-tz\" \ 20: -DCONFIG_QCOM_KGSL_SYNX=1 # This is needed to enable the hw-fence driver APIs in kernel headers 21: 22: ifneq ($(CONFIG_CORESIGHT),) 23: ccflags-y += -DCONFIG_QCOM_KGSL_CORESIGHT=1 24: endif --- FILE: \config\gki_pineapple.conf | HITS: 2 --- MATCH LINES: 6, 17 1: CONFIG_QCOM_KGSL_IDLE_TIMEOUT = 80 2: CONFIG_QCOM_KGSL_SORT_POOL = y 3: CONFIG_QCOM_KGSL_CONTEXT_DEBUG = y 4: CONFIG_QCOM_KGSL_IOCOHERENCY_DEFAULT = y 5: CONFIG_QCOM_ADRENO_DEFAULT_GOVERNOR = \"msm-adreno-tz\" 6: CONFIG_QTI_HW_FENCE=y 7: 8: ifneq ($(CONFIG_CORESIGHT),) 9: CONFIG_QCOM_KGSL_CORESIGHT = y 10: endif 11: 12: ccflags-y += -DCONFIG_QCOM_KGSL_IDLE_TIMEOUT=80 \ 13: -DCONFIG_QCOM_KGSL_SORT_POOL=1 \ 14: -DCONFIG_QCOM_KGSL_CONTEXT_DEBUG=1 \ 15: -DCONFIG_QCOM_KGSL_IOCOHERENCY_DEFAULT=1 \ 16: -DCONFIG_QCOM_ADRENO_DEFAULT_GOVERNOR=\"msm-adreno-tz\" \ 17: -DCONFIG_QTI_HW_FENCE=1 # This is needed to enable the hw-fence driver APIs in kernel headers 18: 19: ifneq ($(CONFIG_CORESIGHT),) 20: ccflags-y += -DCONFIG_QCOM_KGSL_CORESIGHT=1 21: endif --- FILE: \downstream_dependencies\msm_hw_fence.h | HITS: 90 --- MATCH LINES: 7, 8, 11, 14, 16, 17, 19, 22, 24, 25, 26, 28, 31, 33, 36, 40, 41, 44, 47, 52, 60, 70, 90, 108, 109, 116, 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, 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, 180, 181, 186, 191, 192, 197, 202, 203, 208, 213, 219, 220 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2020, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #ifndef __MSM_HW_FENCE_H 8: #define __MSM_HW_FENCE_H 9: 10: #include 11: #include 12: 13: /** 14: * MSM_HW_FENCE_FLAG_ENABLED_BIT - Hw-fence is enabled for the dma_fence. 15: * 16: * Drivers set this flag in the dma_fence 'flags' to fences that 17: * are backed up by a hw-fence. 18: */ 19: #define MSM_HW_FENCE_FLAG_ENABLED_BIT 31 20: 21: /** 22: * MSM_HW_FENCE_FLAG_SIGNALED_BIT - Hw-fence is signaled for the dma_fence. 23: * 24: * This flag is set by hw-fence driver when a client wants to add itself as 25: * a waiter for this hw-fence. The client uses this flag to avoid adding itself 26: * as a waiter for a fence that is already retired. 27: */ 28: #define MSM_HW_FENCE_FLAG_SIGNALED_BIT 30 29: 30: /** 31: * MSM_HW_FENCE_MAX_SIGNAL_PER_CLIENT - Maximum number of signals per client 32: */ 33: #define MSM_HW_FENCE_MAX_SIGNAL_PER_CLIENT 64 34: 35: /** 36: * struct msm_hw_fence_create_params - Creation parameters. 37: * 38: * @name : Optional parameter associating a name with the object for debug purposes. 39: * Only first 64 bytes are accepted, rest will be ignored. 40: * @handle : Pointer to fence hash (filled by function). 41: * @fence : Pointer to fence. 42: * @flags : flags for customization. 43: */ 44: struct msm_hw_fence_create_params { 45: const char *name; 46: u64 *handle; 47: void *fence; 48: u32 flags; 49: }; 50: 51: /** 52: * struct msm_hw_fence_hfi_queue_table_header - HFI queue table structure. 53: * @version: HFI protocol version. 54: * @size: Queue table size in dwords. 55: * @qhdr0_offset: First queue header offset (dwords) in this table. 56: * @qhdr_size: Queue header size. 57: * @num_q: Number of queues defined in this table. 58: * @num_active_q: Number of active queues. 59: */ 60: struct msm_hw_fence_hfi_queue_table_header { 61: u32 version; 62: u32 size; 63: u32 qhdr0_offset; 64: u32 qhdr_size; 65: u32 num_q; 66: u32 num_active_q; 67: }; 68: 69: /** 70: * struct msm_hw_fence_hfi_queue_header - HFI queue header structure. 71: * @status: Active = 1, Inactive = 0. 72: * @start_addr: Starting address of the queue. 73: * @type: Queue type (rx/tx). 74: * @queue_size: Size of the queue. 75: * @pkt_size: Size of the queue packet entries, 76: * 0 - means variable size of message in the queue, 77: * non-zero - size of the packet, fixed. 78: * @pkt_drop_cnt: Number of packets drop by sender. 79: * @rx_wm: Receiver watermark, applicable in event driven mode. 80: * @tx_wm: Sender watermark, applicable in event driven mode. 81: * @rx_req: Receiver sets this bit if queue is empty. 82: * @tx_req: Sender sets this bit if queue is full. 83: * @rx_irq_status: Receiver sets this bit and triggers an interrupt to the 84: * sender after packets are dequeued. Sender clears this bit. 85: * @tx_irq_status: Sender sets this bit and triggers an interrupt to the 86: * receiver after packets are queued. Receiver clears this bit. 87: * @read_index: read index of the queue. 88: * @write_index: write index of the queue. 89: */ 90: struct msm_hw_fence_hfi_queue_header { 91: u32 status; 92: u32 start_addr; 93: u32 type; 94: u32 queue_size; 95: u32 pkt_size; 96: u32 pkt_drop_cnt; 97: u32 rx_wm; 98: u32 tx_wm; 99: u32 rx_req; 100: u32 tx_req; 101: u32 rx_irq_status; 102: u32 tx_irq_status; 103: u32 read_index; 104: u32 write_index; 105: }; 106: 107: /** 108: * struct msm_hw_fence_mem_addr - Memory descriptor of the queue allocated by 109: * the fence driver for each client during 110: * register. 111: * @virtual_addr: Kernel virtual address of the queue. 112: * @device_addr: Physical address of the memory object. 113: * @size: Size of the memory. 114: * @mem_data: Internal pointer with the attributes of the allocation. 115: */ 116: struct msm_hw_fence_mem_addr { 117: void *virtual_addr; 118: phys_addr_t device_addr; 119: u64 size; 120: void *mem_data; 121: }; 122: 123: /** 124: * enum hw_fence_client_id - Unique identifier of the supported clients. 125: * @HW_FENCE_CLIENT_ID_CTX0: GFX Client. 126: * @HW_FENCE_CLIENT_ID_CTL0: DPU Client 0. 127: * @HW_FENCE_CLIENT_ID_CTL1: DPU Client 1. 128: * @HW_FENCE_CLIENT_ID_CTL2: DPU Client 2. 129: * @HW_FENCE_CLIENT_ID_CTL3: DPU Client 3. 130: * @HW_FENCE_CLIENT_ID_CTL4: DPU Client 4. 131: * @HW_FENCE_CLIENT_ID_CTL5: DPU Client 5. 132: * @HW_FENCE_CLIENT_ID_VAL0: debug Validation client 0. 133: * @HW_FENCE_CLIENT_ID_VAL1: debug Validation client 1. 134: * @HW_FENCE_CLIENT_ID_VAL2: debug Validation client 2. 135: * @HW_FENCE_CLIENT_ID_VAL3: debug Validation client 3. 136: * @HW_FENCE_CLIENT_ID_VAL4: debug Validation client 4. 137: * @HW_FENCE_CLIENT_ID_VAL5: debug Validation client 5. 138: * @HW_FENCE_CLIENT_ID_VAL6: debug Validation client 6. 139: * @HW_FENCE_CLIENT_ID_IPE: IPE Client. 140: * @HW_FENCE_CLIENT_ID_VPU: VPU Client. 141: * @HW_FENCE_CLIENT_ID_IFE0: IFE0 Client 0. 142: * @HW_FENCE_CLIENT_ID_IFE1: IFE1 Client 0. 143: * @HW_FENCE_CLIENT_ID_IFE2: IFE2 Client 0. 144: * @HW_FENCE_CLIENT_ID_IFE3: IFE3 Client 0. 145: * @HW_FENCE_CLIENT_ID_IFE4: IFE4 Client 0. 146: * @HW_FENCE_CLIENT_ID_IFE5: IFE5 Client 0. 147: * @HW_FENCE_CLIENT_ID_IFE6: IFE6 Client 0. 148: * @HW_FENCE_CLIENT_ID_IFE7: IFE7 Client 0. 149: * @HW_FENCE_CLIENT_MAX: Max number of clients, any client must be added 150: * before this enum. 151: */ 152: enum hw_fence_client_id { 153: HW_FENCE_CLIENT_ID_CTX0 = 0x1, 154: HW_FENCE_CLIENT_ID_CTL0, 155: HW_FENCE_CLIENT_ID_CTL1, 156: HW_FENCE_CLIENT_ID_CTL2, 157: HW_FENCE_CLIENT_ID_CTL3, 158: HW_FENCE_CLIENT_ID_CTL4, 159: HW_FENCE_CLIENT_ID_CTL5, 160: HW_FENCE_CLIENT_ID_VAL0, 161: HW_FENCE_CLIENT_ID_VAL1, 162: HW_FENCE_CLIENT_ID_VAL2, 163: HW_FENCE_CLIENT_ID_VAL3, 164: HW_FENCE_CLIENT_ID_VAL4, 165: HW_FENCE_CLIENT_ID_VAL5, 166: HW_FENCE_CLIENT_ID_VAL6, 167: HW_FENCE_CLIENT_ID_IPE, 168: HW_FENCE_CLIENT_ID_VPU, 169: HW_FENCE_CLIENT_ID_IFE0, 170: HW_FENCE_CLIENT_ID_IFE1 = HW_FENCE_CLIENT_ID_IFE0 + MSM_HW_FENCE_MAX_SIGNAL_PER_CLIENT, 171: HW_FENCE_CLIENT_ID_IFE2 = HW_FENCE_CLIENT_ID_IFE1 + MSM_HW_FENCE_MAX_SIGNAL_PER_CLIENT, 172: HW_FENCE_CLIENT_ID_IFE3 = HW_FENCE_CLIENT_ID_IFE2 + MSM_HW_FENCE_MAX_SIGNAL_PER_CLIENT, 173: HW_FENCE_CLIENT_ID_IFE4 = HW_FENCE_CLIENT_ID_IFE3 + MSM_HW_FENCE_MAX_SIGNAL_PER_CLIENT, 174: HW_FENCE_CLIENT_ID_IFE5 = HW_FENCE_CLIENT_ID_IFE4 + MSM_HW_FENCE_MAX_SIGNAL_PER_CLIENT, 175: HW_FENCE_CLIENT_ID_IFE6 = HW_FENCE_CLIENT_ID_IFE5 + MSM_HW_FENCE_MAX_SIGNAL_PER_CLIENT, 176: HW_FENCE_CLIENT_ID_IFE7 = HW_FENCE_CLIENT_ID_IFE6 + MSM_HW_FENCE_MAX_SIGNAL_PER_CLIENT, 177: HW_FENCE_CLIENT_MAX = HW_FENCE_CLIENT_ID_IFE7 + MSM_HW_FENCE_MAX_SIGNAL_PER_CLIENT 178: }; 179: 180: static inline void *msm_hw_fence_register(enum hw_fence_client_id client_id, 181: struct msm_hw_fence_mem_addr *mem_descriptor) 182: { 183: return NULL; 184: } 185: 186: static inline int msm_hw_fence_deregister(void *client_handle) 187: { 188: return -EINVAL; 189: } 190: 191: static inline int msm_hw_fence_create(void *client_handle, 192: struct msm_hw_fence_create_params *params) 193: { 194: return -EINVAL; 195: } 196: 197: static inline int msm_hw_fence_destroy(void *client_handle, struct dma_fence *fence) 198: { 199: return -EINVAL; 200: } 201: 202: static inline int msm_hw_fence_wait_update(void *client_handle, 203: struct dma_fence **fences, u32 num_fences, bool reg) 204: { 205: return -EINVAL; 206: } 207: 208: static inline int msm_hw_fence_update_txq(void *client_handle, u64 handle, u64 flags, u32 error) 209: { 210: return -EINVAL; 211: } 212: 213: static inline int msm_hw_fence_trigger_signal(void *client_handle, u32 tx_client_id, 214: u32 rx_client_id, u32 signal_id) 215: { 216: return -EINVAL; 217: } 218: 219: static inline int msm_hw_fence_wait_update_v2(void *client_handle, 220: struct dma_fence **fences, u64 *handles, u64 *client_data_list, u32 num_fences, bool reg) 221: { 222: return -EINVAL; 223: } 224: #endif --- FILE: \downstream_dependencies\soc\qcom\msm_performance.h | HITS: 1 --- MATCH LINES: 23 11: MSM_PERF_INVAL, 12: MSM_PERF_QUEUE, 13: MSM_PERF_SUBMIT, 14: MSM_PERF_RETIRED 15: }; 16: 17: enum evt_update_t { 18: MSM_PERF_GFX, 19: }; 20: 21: static inline void msm_perf_events_update(enum evt_update_t update_typ, 22: enum gfx_evt_t evt_typ, pid_t pid, 23: uint32_t ctx_id, uint32_t timestamp, bool end_of_frame) 24: { 25: } 26: #endif --- FILE: \include\uapi\linux\msm_kgsl.h | HITS: 137 --- MATCH LINES: 130, 131 118: */ 119: 120: /* Flags for GPU command objects */ 121: #define KGSL_CMDLIST_IB 0x00000001U 122: #define KGSL_CMDLIST_CTXTSWITCH_PREAMBLE 0x00000002U 123: #define KGSL_CMDLIST_IB_PREAMBLE 0x00000004U 124: 125: /* Flags for GPU command memory objects */ 126: #define KGSL_OBJLIST_MEMOBJ 0x00000008U 127: #define KGSL_OBJLIST_PROFILE 0x00000010U 128: 129: /* Flags for GPU command sync points */ 130: #define KGSL_CMD_SYNCPOINT_TYPE_TIMESTAMP 0 131: #define KGSL_CMD_SYNCPOINT_TYPE_FENCE 1 132: #define KGSL_CMD_SYNCPOINT_TYPE_TIMELINE 2 133: 134: /* --- Memory allocation flags --- */ 135: 136: /* General allocation hints */ 137: #define KGSL_MEMFLAGS_SECURE (1ULL << 3) 138: #define KGSL_MEMFLAGS_GPUREADONLY (1ULL << 24) 139: #define KGSL_MEMFLAGS_GPUWRITEONLY (1ULL << 25) 140: #define KGSL_MEMFLAGS_FORCE_32BIT (1ULL << 32) 141: 142: /* Flag for binding all the virt range to single phys data */ 143: #define KGSL_SPARSE_BIND_MULTIPLE_TO_PHYS 0x400000000ULL 144: #define KGSL_SPARSE_BIND 0x1ULL 145: #define KGSL_SPARSE_UNBIND 0x2ULL 146: 147: /* Memory caching hints */ 148: #define KGSL_CACHEMODE_MASK 0x0C000000U 149: #define KGSL_CACHEMODE_SHIFT 26 150: 151: #define KGSL_CACHEMODE_WRITECOMBINE 0 152: #define KGSL_CACHEMODE_UNCACHED 1 153: #define KGSL_CACHEMODE_WRITETHROUGH 2 154: #define KGSL_CACHEMODE_WRITEBACK 3 155: MATCH LINES: 240 228: /* --- generic KGSL flag values --- */ 229: 230: #define KGSL_FLAGS_NORMALMODE 0x00000000 231: #define KGSL_FLAGS_SAFEMODE 0x00000001 232: #define KGSL_FLAGS_INITIALIZED0 0x00000002 233: #define KGSL_FLAGS_INITIALIZED 0x00000004 234: #define KGSL_FLAGS_STARTED 0x00000008 235: #define KGSL_FLAGS_ACTIVE 0x00000010 236: #define KGSL_FLAGS_RESERVED0 0x00000020 237: #define KGSL_FLAGS_RESERVED1 0x00000040 238: #define KGSL_FLAGS_RESERVED2 0x00000080 239: #define KGSL_FLAGS_SOFT_RESET 0x00000100 240: #define KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS 0x00000200 241: 242: /* Server Side Sync Timeout in milliseconds */ 243: #define KGSL_SYNCOBJ_SERVER_TIMEOUT 2000 244: 245: /* UBWC Modes */ 246: #define KGSL_UBWC_NONE 0 247: #define KGSL_UBWC_1_0 1 248: #define KGSL_UBWC_2_0 2 249: #define KGSL_UBWC_3_0 3 250: #define KGSL_UBWC_4_0 4 251: #define KGSL_UBWC_5_0 5 252: #define KGSL_UBWC_6_0 6 253: 254: /* 255: * Reset status values for context 256: */ 257: enum kgsl_ctx_reset_stat { 258: KGSL_CTX_STAT_NO_ERROR = 0x00000000, 259: KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT = 0x00000001, 260: KGSL_CTX_STAT_INNOCENT_CONTEXT_RESET_EXT = 0x00000002, 261: KGSL_CTX_STAT_UNKNOWN_CONTEXT_RESET_EXT = 0x00000003 262: }; 263: 264: #define KGSL_CONVERT_TO_MBPS(val) \ MATCH LINES: 287, 289, 292, 297, 303, 305, 319, 320, 321, 322, 323 275: unsigned int mmu_enabled; 276: unsigned long gmem_gpubaseaddr; 277: /* 278: * This field contains the adreno revision 279: * number 200, 205, 220, etc... 280: */ 281: unsigned int gpu_id; 282: __kernel_size_t gmem_sizebytes; 283: }; 284: 285: /* 286: * struct kgsl_devmemstore - this structure defines the region of memory 287: * that can be mmap()ed from this driver. The timestamp fields are volatile 288: * because they are written by the GPU 289: * @soptimestamp: Start of pipeline timestamp written by GPU before the 290: * commands in concern are processed 291: * @sbz: Unused, kept for 8 byte alignment 292: * @eoptimestamp: End of pipeline timestamp written by GPU after the 293: * commands in concern are processed 294: * @sbz2: Unused, kept for 8 byte alignment 295: * @preempted: Indicates if the context was preempted 296: * @sbz3: Unused, kept for 8 byte alignment 297: * @ref_wait_ts: Timestamp on which to generate interrupt, unused now. 298: * @sbz4: Unused, kept for 8 byte alignment 299: * @current_context: The current context the GPU is working on 300: * @sbz5: Unused, kept for 8 byte alignment 301: */ 302: struct kgsl_devmemstore { 303: volatile unsigned int soptimestamp; 304: unsigned int sbz; 305: volatile unsigned int eoptimestamp; 306: unsigned int sbz2; 307: volatile unsigned int preempted; 308: unsigned int sbz3; 309: volatile unsigned int ref_wait_ts; 310: unsigned int sbz4; 311: unsigned int current_context; 312: unsigned int sbz5; 313: }; 314: 315: #define KGSL_MEMSTORE_OFFSET(ctxt_id, field) \ 316: ((ctxt_id)*sizeof(struct kgsl_devmemstore) + \ 317: offsetof(struct kgsl_devmemstore, field)) 318: 319: /* timestamp id*/ 320: enum kgsl_timestamp_type { 321: KGSL_TIMESTAMP_CONSUMED = 0x00000001, /* start-of-pipeline timestamp */ 322: KGSL_TIMESTAMP_RETIRED = 0x00000002, /* end-of-pipeline timestamp*/ 323: KGSL_TIMESTAMP_QUEUED = 0x00000003, 324: }; 325: 326: /* property types - used with kgsl_device_getproperty */ 327: #define KGSL_PROP_DEVICE_INFO 0x1 328: #define KGSL_PROP_DEVICE_SHADOW 0x2 329: #define KGSL_PROP_DEVICE_POWER 0x3 330: #define KGSL_PROP_SHMEM 0x4 331: #define KGSL_PROP_SHMEM_APERTURES 0x5 332: #define KGSL_PROP_MMU_ENABLE 0x6 333: #define KGSL_PROP_INTERRUPT_WAITS 0x7 334: #define KGSL_PROP_VERSION 0x8 335: #define KGSL_PROP_GPU_RESET_STAT 0x9 336: #define KGSL_PROP_PWRCTRL 0xE 337: #define KGSL_PROP_PWR_CONSTRAINT 0x12 338: #define KGSL_PROP_UCHE_GMEM_VADDR 0x13 339: #define KGSL_PROP_SP_GENERIC_MEM 0x14 340: #define KGSL_PROP_UCODE_VERSION 0x15 341: #define KGSL_PROP_GPMU_VERSION 0x16 342: #define KGSL_PROP_HIGHEST_BANK_BIT 0x17 343: #define KGSL_PROP_DEVICE_BITNESS 0x18 344: #define KGSL_PROP_DEVICE_QDSS_STM 0x19 345: #define KGSL_PROP_MIN_ACCESS_LENGTH 0x1A 346: #define KGSL_PROP_UBWC_MODE 0x1B 347: #define KGSL_PROP_DEVICE_QTIMER 0x20 MATCH LINES: 449 437: unsigned int features; 438: }; 439: 440: struct kgsl_context_property { 441: __u64 data; 442: __u32 size; 443: __u32 type; 444: __u32 contextid; 445: }; 446: 447: struct kgsl_context_property_fault { 448: __s32 faults; 449: __u32 timestamp; 450: }; 451: 452: struct kgsl_gpu_model { 453: char gpu_model[32]; 454: }; 455: 456: /* Context property sub types */ 457: #define KGSL_CONTEXT_PROP_FAULTS 1 458: 459: /* Performance counter groups */ 460: 461: #define KGSL_PERFCOUNTER_GROUP_CP 0x0 462: #define KGSL_PERFCOUNTER_GROUP_RBBM 0x1 463: #define KGSL_PERFCOUNTER_GROUP_PC 0x2 464: #define KGSL_PERFCOUNTER_GROUP_VFD 0x3 465: #define KGSL_PERFCOUNTER_GROUP_HLSQ 0x4 466: #define KGSL_PERFCOUNTER_GROUP_VPC 0x5 467: #define KGSL_PERFCOUNTER_GROUP_TSE 0x6 468: #define KGSL_PERFCOUNTER_GROUP_RAS 0x7 469: #define KGSL_PERFCOUNTER_GROUP_UCHE 0x8 470: #define KGSL_PERFCOUNTER_GROUP_TP 0x9 471: #define KGSL_PERFCOUNTER_GROUP_SP 0xA 472: #define KGSL_PERFCOUNTER_GROUP_RB 0xB 473: #define KGSL_PERFCOUNTER_GROUP_PWR 0xC MATCH LINES: 580, 583, 584, 588, 589, 591, 593, 597, 598, 605, 616, 623, 624, 626, 628, 631, 632, 634, 635, 637, 640, 642, 645, 648, 649, 653, 658, 659, 697, 700, 703, 704, 706, 710, 713, 715 568: struct kgsl_device_getproperty { 569: unsigned int type; 570: void __user *value; 571: __kernel_size_t sizebytes; 572: }; 573: 574: #define IOCTL_KGSL_DEVICE_GETPROPERTY \ 575: _IOWR(KGSL_IOC_TYPE, 0x2, struct kgsl_device_getproperty) 576: 577: /* IOCTL_KGSL_DEVICE_READ (0x3) - removed 03/2012 578: */ 579: 580: /* block until the GPU has executed past a given timestamp 581: * timeout is in milliseconds. 582: */ 583: struct kgsl_device_waittimestamp { 584: unsigned int timestamp; 585: unsigned int timeout; 586: }; 587: 588: #define IOCTL_KGSL_DEVICE_WAITTIMESTAMP \ 589: _IOW(KGSL_IOC_TYPE, 0x6, struct kgsl_device_waittimestamp) 590: 591: struct kgsl_device_waittimestamp_ctxtid { 592: unsigned int context_id; 593: unsigned int timestamp; 594: unsigned int timeout; 595: }; 596: 597: #define IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID \ 598: _IOW(KGSL_IOC_TYPE, 0x7, struct kgsl_device_waittimestamp_ctxtid) 599: 600: /* DEPRECATED: issue indirect commands to the GPU. 601: * drawctxt_id must have been created with IOCTL_KGSL_DRAWCTXT_CREATE 602: * ibaddr and sizedwords must specify a subset of a buffer created 603: * with IOCTL_KGSL_SHAREDMEM_FROM_PMEM 604: * flags may be a mask of KGSL_CONTEXT_ values 605: * timestamp is a returned counter value which can be passed to 606: * other ioctls to determine when the commands have been executed by 607: * the GPU. 608: * 609: * This function is deprecated - consider using IOCTL_KGSL_SUBMIT_COMMANDS 610: * instead 611: */ 612: struct kgsl_ringbuffer_issueibcmds { 613: unsigned int drawctxt_id; 614: unsigned long ibdesc_addr; 615: unsigned int numibs; 616: unsigned int timestamp; /*output param */ 617: unsigned int flags; 618: }; 619: 620: #define IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS \ 621: _IOWR(KGSL_IOC_TYPE, 0x10, struct kgsl_ringbuffer_issueibcmds) 622: 623: /* read the most recently executed timestamp value 624: * type should be a value from enum kgsl_timestamp_type 625: */ 626: struct kgsl_cmdstream_readtimestamp { 627: unsigned int type; 628: unsigned int timestamp; /*output param */ 629: }; 630: 631: #define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_OLD \ 632: _IOR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp) 633: 634: #define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP \ 635: _IOWR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp) 636: 637: /* free memory when the GPU reaches a given timestamp. 638: * gpuaddr specify a memory region created by a 639: * IOCTL_KGSL_SHAREDMEM_FROM_PMEM call 640: * type should be a value from enum kgsl_timestamp_type 641: */ 642: struct kgsl_cmdstream_freememontimestamp { 643: unsigned long gpuaddr; 644: unsigned int type; 645: unsigned int timestamp; 646: }; 647: 648: #define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP \ 649: _IOW(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp) 650: 651: /* 652: * Previous versions of this header had incorrectly defined 653: * IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP as a read-only ioctl instead 654: * of a write only ioctl. To ensure binary compatibility, the following 655: * #define will be used to intercept the incorrect ioctl 656: */ 657: 658: #define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_OLD \ 659: _IOR(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp) 660: 661: /* create a draw context, which is used to preserve GPU state. 662: * The flags field may contain a mask KGSL_CONTEXT_* values 663: */ 664: struct kgsl_drawctxt_create { 665: unsigned int flags; 666: unsigned int drawctxt_id; /*output param */ 667: }; 668: 669: #define IOCTL_KGSL_DRAWCTXT_CREATE \ 670: _IOWR(KGSL_IOC_TYPE, 0x13, struct kgsl_drawctxt_create) 671: 672: /* destroy a draw context */ 673: struct kgsl_drawctxt_destroy { 674: unsigned int drawctxt_id; 675: }; 676: 677: #define IOCTL_KGSL_DRAWCTXT_DESTROY \ 678: _IOW(KGSL_IOC_TYPE, 0x14, struct kgsl_drawctxt_destroy) 679: 680: /* 681: * add a block of pmem, fb, ashmem or user allocated address 682: * into the GPU address space 683: */ 684: struct kgsl_map_user_mem { 685: int fd; 686: unsigned long gpuaddr; /*output param */ 687: __kernel_size_t len; 688: __kernel_size_t offset; 689: unsigned long hostptr; /*input param */ 690: enum kgsl_user_mem_type memtype; 691: unsigned int flags; 692: }; 693: 694: #define IOCTL_KGSL_MAP_USER_MEM \ 695: _IOWR(KGSL_IOC_TYPE, 0x15, struct kgsl_map_user_mem) 696: 697: struct kgsl_cmdstream_readtimestamp_ctxtid { 698: unsigned int context_id; 699: unsigned int type; 700: unsigned int timestamp; /*output param */ 701: }; 702: 703: #define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID \ 704: _IOWR(KGSL_IOC_TYPE, 0x16, struct kgsl_cmdstream_readtimestamp_ctxtid) 705: 706: struct kgsl_cmdstream_freememontimestamp_ctxtid { 707: unsigned int context_id; 708: unsigned long gpuaddr; 709: unsigned int type; 710: unsigned int timestamp; 711: }; 712: 713: #define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID \ 714: _IOW(KGSL_IOC_TYPE, 0x17, \ 715: struct kgsl_cmdstream_freememontimestamp_ctxtid) 716: 717: /* add a block of pmem or fb into the GPU address space */ 718: struct kgsl_sharedmem_from_pmem { 719: int pmem_fd; 720: unsigned long gpuaddr; /*output param */ 721: unsigned int len; 722: unsigned int offset; 723: }; 724: 725: #define IOCTL_KGSL_SHAREDMEM_FROM_PMEM \ 726: _IOWR(KGSL_IOC_TYPE, 0x20, struct kgsl_sharedmem_from_pmem) 727: 728: /* remove memory from the GPU's address space */ 729: struct kgsl_sharedmem_free { 730: unsigned long gpuaddr; 731: }; 732: 733: #define IOCTL_KGSL_SHAREDMEM_FREE \ 734: _IOW(KGSL_IOC_TYPE, 0x21, struct kgsl_sharedmem_free) 735: 736: struct kgsl_cff_user_event { 737: unsigned char cff_opcode; 738: unsigned int op1; 739: unsigned int op2; MATCH LINES: 851, 852, 853, 856, 858, 859, 864, 865, 867, 869, 871, 875, 877, 879, 880, 891, 892 839: _IOWR(KGSL_IOC_TYPE, 0x2f, struct kgsl_gpumem_alloc) 840: 841: struct kgsl_cff_syncmem { 842: unsigned long gpuaddr; 843: __kernel_size_t len; 844: unsigned int __pad[2]; /* For future binary compatibility */ 845: }; 846: 847: #define IOCTL_KGSL_CFF_SYNCMEM \ 848: _IOW(KGSL_IOC_TYPE, 0x30, struct kgsl_cff_syncmem) 849: 850: /* 851: * A timestamp event allows the user space to register an action following an 852: * expired timestamp. Note IOCTL_KGSL_TIMESTAMP_EVENT has been redefined to 853: * _IOWR to support fences which need to return a fd for the priv parameter. 854: */ 855: 856: struct kgsl_timestamp_event { 857: int type; /* Type of event (see list below) */ 858: unsigned int timestamp; /* Timestamp to trigger event on */ 859: unsigned int context_id; /* Context for the timestamp */ 860: void __user *priv; /* Pointer to the event specific blob */ 861: __kernel_size_t len; /* Size of the event specific blob */ 862: }; 863: 864: #define IOCTL_KGSL_TIMESTAMP_EVENT_OLD \ 865: _IOW(KGSL_IOC_TYPE, 0x31, struct kgsl_timestamp_event) 866: 867: /* A genlock timestamp event releases an existing lock on timestamp expire */ 868: 869: #define KGSL_TIMESTAMP_EVENT_GENLOCK 1 870: 871: struct kgsl_timestamp_event_genlock { 872: int handle; /* Handle of the genlock lock to release */ 873: }; 874: 875: /* A fence timestamp event releases an existing lock on timestamp expire */ 876: 877: #define KGSL_TIMESTAMP_EVENT_FENCE 2 878: 879: struct kgsl_timestamp_event_fence { 880: int fence_fd; /* Fence to signal */ 881: }; 882: 883: /* 884: * Set a property within the kernel. Uses the same structure as 885: * IOCTL_KGSL_GETPROPERTY 886: */ 887: 888: #define IOCTL_KGSL_SETPROPERTY \ 889: _IOW(KGSL_IOC_TYPE, 0x32, struct kgsl_device_getproperty) 890: 891: #define IOCTL_KGSL_TIMESTAMP_EVENT \ 892: _IOWR(KGSL_IOC_TYPE, 0x33, struct kgsl_timestamp_event) 893: 894: /** 895: * struct kgsl_gpumem_alloc_id - argument to IOCTL_KGSL_GPUMEM_ALLOC_ID 896: * @id: returned id value for this allocation. 897: * @flags: mask of KGSL_MEM* values requested and actual flags on return. 898: * @size: requested size of the allocation and actual size on return. 899: * @mmapsize: returned size to pass to mmap() which may be larger than 'size' 900: * @gpuaddr: returned GPU address for the allocation 901: * 902: * Allocate memory for access by the GPU. The flags and size fields are echoed 903: * back by the kernel, so that the caller can know if the request was 904: * adjusted. 905: * 906: * Supported flags: 907: * KGSL_MEMFLAGS_GPUREADONLY: the GPU will be unable to write to the buffer 908: * KGSL_MEMTYPE*: usage hint for debugging aid 909: * KGSL_MEMALIGN*: alignment hint, may be ignored or adjusted by the kernel. 910: * KGSL_MEMFLAGS_USE_CPU_MAP: If set on call and return, the returned GPU 911: * address will be 0. Calling mmap() will set the GPU address. 912: */ 913: struct kgsl_gpumem_alloc_id { 914: unsigned int id; 915: unsigned int flags; 916: __kernel_size_t size; MATCH LINES: 1136, 1138, 1140, 1145, 1147, 1150 1124: struct kgsl_gpumem_sync_cache_bulk { 1125: unsigned int __user *id_list; 1126: unsigned int count; 1127: unsigned int op; 1128: /* private: reserved for future use */ 1129: unsigned int __pad[2]; /* For future binary compatibility */ 1130: }; 1131: 1132: #define IOCTL_KGSL_GPUMEM_SYNC_CACHE_BULK \ 1133: _IOWR(KGSL_IOC_TYPE, 0x3C, struct kgsl_gpumem_sync_cache_bulk) 1134: 1135: /* 1136: * struct kgsl_cmd_syncpoint_timestamp 1137: * @context_id: ID of a KGSL context 1138: * @timestamp: GPU timestamp 1139: * 1140: * This structure defines a syncpoint comprising a context/timestamp pair. A 1141: * list of these may be passed by IOCTL_KGSL_SUBMIT_COMMANDS to define 1142: * dependencies that must be met before the command can be submitted to the 1143: * hardware 1144: */ 1145: struct kgsl_cmd_syncpoint_timestamp { 1146: unsigned int context_id; 1147: unsigned int timestamp; 1148: }; 1149: 1150: struct kgsl_cmd_syncpoint_fence { 1151: int fd; 1152: }; 1153: 1154: /* 1155: * struct kgsl_cmd_syncpoint_timeline 1156: * @timelines: Address of an array of &struct kgsl_timeline_val 1157: * @count: Number of entries in @timelines 1158: * @timelines_size: Size of each entry in @timelines 1159: * 1160: * Define a syncpoint for a number of timelines. This syncpoint will 1161: * be satisfied when all of the specified timelines are signaled. 1162: */ 1163: struct kgsl_cmd_syncpoint_timeline { 1164: __u64 timelines; 1165: __u32 count; 1166: __u32 timelines_size; 1167: }; 1168: 1169: /** 1170: * struct kgsl_cmd_syncpoint - Define a sync point for a command batch 1171: * @type: type of sync point defined here 1172: * @priv: Pointer to the type specific buffer 1173: * @size: Size of the type specific buffer 1174: * MATCH LINES: 1198, 1216 1186: 1187: /* Flag to point out the cmdbatch profiling buffer in the memlist */ 1188: #define KGSL_IBDESC_PROFILING_BUFFER 0x2 1189: 1190: /** 1191: * struct kgsl_submit_commands - Argument to IOCTL_KGSL_SUBMIT_COMMANDS 1192: * @context_id: KGSL context ID that owns the commands 1193: * @flags: 1194: * @cmdlist: User pointer to a list of kgsl_ibdesc structures 1195: * @numcmds: Number of commands listed in cmdlist 1196: * @synclist: User pointer to a list of kgsl_cmd_syncpoint structures 1197: * @numsyncs: Number of sync points listed in synclist 1198: * @timestamp: On entry the a user defined timestamp, on exist the timestamp 1199: * assigned to the command batch 1200: * 1201: * This structure specifies a command to send to the GPU hardware. This is 1202: * similar to kgsl_issueibcmds expect that it doesn't support the legacy way to 1203: * submit IB lists and it adds sync points to block the IB until the 1204: * dependencies are satisified. This entry point is the new and preferred way 1205: * to submit commands to the GPU. The memory list can be used to specify all 1206: * memory that is referrenced in the current set of commands. 1207: */ 1208: 1209: struct kgsl_submit_commands { 1210: unsigned int context_id; 1211: unsigned int flags; 1212: struct kgsl_ibdesc __user *cmdlist; 1213: unsigned int numcmds; 1214: struct kgsl_cmd_syncpoint __user *synclist; 1215: unsigned int numsyncs; 1216: unsigned int timestamp; 1217: /* private: reserved for future use */ 1218: unsigned int __pad[4]; 1219: }; 1220: 1221: #define IOCTL_KGSL_SUBMIT_COMMANDS \ 1222: _IOWR(KGSL_IOC_TYPE, 0x3D, struct kgsl_submit_commands) 1223: 1224: /** 1225: * struct kgsl_device_constraint - device constraint argument 1226: * @context_id: KGSL context ID 1227: * @type: type of constraint i.e pwrlevel/none 1228: * @data: constraint data 1229: * @size: size of the constraint data 1230: */ 1231: struct kgsl_device_constraint { 1232: unsigned int type; 1233: unsigned int context_id; 1234: void __user *data; 1235: __kernel_size_t size; 1236: }; 1237: 1238: /* Constraint Type*/ 1239: #define KGSL_CONSTRAINT_NONE 0 1240: #define KGSL_CONSTRAINT_PWRLEVEL 1 MATCH LINES: 1296, 1297, 1299, 1301, 1302, 1303, 1305, 1307, 1313, 1314, 1316, 1318, 1319, 1321, 1323, 1324, 1326, 1328, 1333, 1334 1284: */ 1285: 1286: struct kgsl_syncsource_destroy { 1287: unsigned int id; 1288: /* private: reserved for future use */ 1289: unsigned int __pad[3]; 1290: }; 1291: 1292: #define IOCTL_KGSL_SYNCSOURCE_DESTROY \ 1293: _IOWR(KGSL_IOC_TYPE, 0x41, struct kgsl_syncsource_destroy) 1294: 1295: /** 1296: * struct kgsl_syncsource_create_fence - Argument to 1297: * IOCTL_KGSL_SYNCSOURCE_CREATE_FENCE 1298: * @id: syncsource id 1299: * @fence_fd: returned sync_fence fd 1300: * 1301: * Create a fence that may be signaled by userspace by calling 1302: * IOCTL_KGSL_SYNCSOURCE_SIGNAL_FENCE. There are no order dependencies between 1303: * these fences. 1304: */ 1305: struct kgsl_syncsource_create_fence { 1306: unsigned int id; 1307: int fence_fd; 1308: /* private: reserved for future use */ 1309: unsigned int __pad[4]; 1310: }; 1311: 1312: /** 1313: * struct kgsl_syncsource_signal_fence - Argument to 1314: * IOCTL_KGSL_SYNCSOURCE_SIGNAL_FENCE 1315: * @id: syncsource id 1316: * @fence_fd: sync_fence fd to signal 1317: * 1318: * Signal a fence that was created by a IOCTL_KGSL_SYNCSOURCE_CREATE_FENCE 1319: * call using the same syncsource id. This allows a fence to be shared 1320: * to other processes but only signaled by the process owning the fd 1321: * used to create the fence. 1322: */ 1323: #define IOCTL_KGSL_SYNCSOURCE_CREATE_FENCE \ 1324: _IOWR(KGSL_IOC_TYPE, 0x42, struct kgsl_syncsource_create_fence) 1325: 1326: struct kgsl_syncsource_signal_fence { 1327: unsigned int id; 1328: int fence_fd; 1329: /* private: reserved for future use */ 1330: unsigned int __pad[4]; 1331: }; 1332: 1333: #define IOCTL_KGSL_SYNCSOURCE_SIGNAL_FENCE \ 1334: _IOWR(KGSL_IOC_TYPE, 0x43, struct kgsl_syncsource_signal_fence) 1335: 1336: /** 1337: * struct kgsl_cff_sync_gpuobj - Argument to IOCTL_KGSL_CFF_SYNC_GPUOBJ 1338: * @offset: Offset into the GPU object to sync 1339: * @length: Number of bytes to sync 1340: * @id: ID of the GPU object to sync 1341: */ 1342: struct kgsl_cff_sync_gpuobj { 1343: __u64 offset; 1344: __u64 length; 1345: unsigned int id; 1346: }; 1347: 1348: #define IOCTL_KGSL_CFF_SYNC_GPUOBJ \ 1349: _IOW(KGSL_IOC_TYPE, 0x44, struct kgsl_cff_sync_gpuobj) 1350: 1351: /** 1352: * struct kgsl_gpuobj_alloc - Argument to IOCTL_KGSL_GPUOBJ_ALLOC 1353: * @size: Size in bytes of the object to allocate 1354: * @flags: mask of KGSL_MEMFLAG_* bits 1355: * @va_len: Size in bytes of the virtual region to allocate 1356: * @mmapsize: Returns the mmap() size of the object 1357: * @id: Returns the GPU object ID of the new object 1358: * @metadata_len: Length of the metdata to copy from the user MATCH LINES: 1402, 1403, 1406, 1408, 1409, 1411, 1413, 1417, 1418, 1420 1390: * @len: Length of the data passed in priv 1391: */ 1392: struct kgsl_gpuobj_free { 1393: __u64 flags; 1394: __u64 __user priv; 1395: unsigned int id; 1396: unsigned int type; 1397: unsigned int len; 1398: }; 1399: 1400: #define KGSL_GPUOBJ_FREE_ON_EVENT 1 1401: 1402: #define KGSL_GPU_EVENT_TIMESTAMP 1 1403: #define KGSL_GPU_EVENT_FENCE 2 1404: 1405: /** 1406: * struct kgsl_gpu_event_timestamp - Specifies a timestamp event to free a GPU 1407: * object on 1408: * @context_id: ID of the timestamp event to wait for 1409: * @timestamp: Timestamp of the timestamp event to wait for 1410: */ 1411: struct kgsl_gpu_event_timestamp { 1412: unsigned int context_id; 1413: unsigned int timestamp; 1414: }; 1415: 1416: /** 1417: * struct kgsl_gpu_event_fence - Specifies a fence ID to free a GPU object on 1418: * @fd: File descriptor for the fence 1419: */ 1420: struct kgsl_gpu_event_fence { 1421: int fd; 1422: }; 1423: 1424: #define IOCTL_KGSL_GPUOBJ_FREE \ 1425: _IOW(KGSL_IOC_TYPE, 0x46, struct kgsl_gpuobj_free) 1426: 1427: /** 1428: * struct kgsl_gpuobj_info - argument to IOCTL_KGSL_GPUOBJ_INFO 1429: * @gpuaddr: GPU address of the object 1430: * @flags: Current flags for the object 1431: * @size: Size of the object 1432: * @va_len: VA size of the object 1433: * @va_addr: Virtual address of the object (if it is mapped) 1434: * id - GPU object ID of the object to query 1435: */ 1436: struct kgsl_gpuobj_info { 1437: __u64 gpuaddr; 1438: __u64 flags; 1439: __u64 size; 1440: __u64 va_len; 1441: __u64 va_addr; 1442: unsigned int id; 1443: }; 1444: MATCH LINES: 1555, 1569 1543: * struct kgsl_gpu_command - Argument for IOCTL_KGSL_GPU_COMMAND 1544: * @flags: Current flags for the object 1545: * @cmdlist: List of kgsl_command_objects for submission 1546: * @cmdsize: Size of kgsl_command_objects structure 1547: * @numcmds: Number of kgsl_command_objects in command list 1548: * @objlist: List of kgsl_command_objects for tracking 1549: * @objsize: Size of kgsl_command_objects structure 1550: * @numobjs: Number of kgsl_command_objects in object list 1551: * @synclist: List of kgsl_command_syncpoints 1552: * @syncsize: Size of kgsl_command_syncpoint structure 1553: * @numsyncs: Number of kgsl_command_syncpoints in syncpoint list 1554: * @context_id: Context ID submitting the kgsl_gpu_command 1555: * @timestamp: Timestamp for the submitted commands 1556: */ 1557: struct kgsl_gpu_command { 1558: __u64 flags; 1559: __u64 __user cmdlist; 1560: unsigned int cmdsize; 1561: unsigned int numcmds; 1562: __u64 __user objlist; 1563: unsigned int objsize; 1564: unsigned int numobjs; 1565: __u64 __user synclist; 1566: unsigned int syncsize; 1567: unsigned int numsyncs; 1568: unsigned int context_id; 1569: unsigned int timestamp; 1570: }; 1571: 1572: #define IOCTL_KGSL_GPU_COMMAND \ 1573: _IOWR(KGSL_IOC_TYPE, 0x4A, struct kgsl_gpu_command) 1574: 1575: /** 1576: * struct kgsl_preemption_counters_query - argument to 1577: * IOCTL_KGSL_PREEMPTIONCOUNTER_QUERY 1578: * @counters: Return preemption counters array 1579: * @size_user: Size allocated by userspace 1580: * @size_priority_level: Size of preemption counters for each 1581: * priority level 1582: * @max_priority_level: Return max number of priority levels 1583: * 1584: * Query the available preemption counters. The array counters 1585: * is used to return preemption counters. The size of the array 1586: * is passed in so the kernel will only write at most size_user 1587: * or max available preemption counters. The total number of 1588: * preemption counters is returned in max_priority_level. If the 1589: * array or size passed in are invalid, then an error is 1590: * returned back. 1591: */ 1592: struct kgsl_preemption_counters_query { 1593: __u64 __user counters; MATCH LINES: 1730, 1742 1718: 1719: /** 1720: * struct kgsl_gpu_sparse_command - Argument for 1721: * IOCTL_KGSL_GPU_SPARSE_COMMAND 1722: * @flags: Current flags for the object 1723: * @sparselist: List of kgsl_sparse_binding_object to bind/unbind 1724: * @synclist: List of kgsl_command_syncpoints 1725: * @sparsesize: Size of kgsl_sparse_binding_object 1726: * @numsparse: Number of elements in list 1727: * @sync_size: Size of kgsl_command_syncpoint structure 1728: * @numsyncs: Number of kgsl_command_syncpoints in syncpoint list 1729: * @context_id: Context ID submitting the kgsl_gpu_command 1730: * @timestamp: Timestamp for the submitted commands 1731: * @id: Virtual ID to bind/unbind 1732: */ 1733: struct kgsl_gpu_sparse_command { 1734: __u64 flags; 1735: __u64 __user sparselist; 1736: __u64 __user synclist; 1737: unsigned int sparsesize; 1738: unsigned int numsparse; 1739: unsigned int syncsize; 1740: unsigned int numsyncs; 1741: unsigned int context_id; 1742: unsigned int timestamp; 1743: unsigned int id; 1744: }; 1745: 1746: #define IOCTL_KGSL_GPU_SPARSE_COMMAND \ 1747: _IOWR(KGSL_IOC_TYPE, 0x55, struct kgsl_gpu_sparse_command) 1748: 1749: #define KGSL_GPUMEM_RANGE_OP_BIND 1 1750: #define KGSL_GPUMEM_RANGE_OP_UNBIND 2 1751: 1752: /** 1753: * struct kgsl_gpumem_bind_range - specifies a bind operation for a virtual 1754: * buffer object 1755: * @child_offset: Offset to the start of memory within the child buffer object 1756: * (not used for KGSL_GPUMEM_RANGE_OP_UNBIND operations) 1757: * @target_offset: GPU address offset within the target VBO 1758: * @length: Amount of memory to map/unmap (in bytes) 1759: * @child_id: The GPU buffer ID for the child object to map/unmap in the VBO 1760: * @op: One of KGSL_GPUMEM_RANGE_OP_BIND or KGSL_GPUMEM_RANGE_OP_UNBIND 1761: * 1762: * This defines a specific bind operation to a virtual buffer object specified 1763: * in &struct kgsl_gpumem_bind_ranges. When @op is KGSL_GPUMEM_RANGE_OP_BIND the 1764: * physical memory starting at @child_offset in the memory object identified by 1765: * @child_id will be mapped into the target virtual buffer object starting at 1766: * @offset for @length bytes. MATCH LINES: 1781, 1791, 1792, 1793, 1805, 1806, 1815 1769: * buffer object between @offset and @length that belong to @child_id will be 1770: * removed. 1771: */ 1772: struct kgsl_gpumem_bind_range { 1773: __u64 child_offset; 1774: __u64 target_offset; 1775: __u64 length; 1776: __u32 child_id; 1777: __u32 op; 1778: }; 1779: 1780: #define KGSL_GPUMEM_BIND_ASYNC (1UL << 0) 1781: #define KGSL_GPUMEM_BIND_FENCE_OUT (1UL << 1) 1782: 1783: /** 1784: * struct kgsl_gpumem_bind_ranges - Argument to IOCTL_KGSL_GPUMEM_BIND_RANGES to 1785: * either map or unmap a child buffer object into a virtual buffer object. 1786: * @ranges: User memory pointer to an array of range operations of type &struct 1787: * kgsl_gpumem_bind_range 1788: * @ranges_nents: Number of entries in @ranges 1789: * @ranges_size: Size of each entry in @ranges in bytes 1790: * @id: GPU buffer object identifier for the target virtual buffer object 1791: * @flags: Bitmap of KGSL_GPUMEM_BIND_ASYNC and KGSL_GPUMEM_BIND_FENCE_OUT 1792: * @fence_id: If KGSL_GPUMEM_BIND_FENCE_OUT is set in @flags contains the 1793: * identifier for the sync fence that will be signaled after the operation 1794: * completes 1795: * 1796: * Describes a number of range operations to perform on a virtual buffer object 1797: * identified by @id. Ranges should be a __u64 representation of an array of 1798: * &struct kgsl_gpumem_bind_range entries. @ranges_nents will contain the number 1799: * of entries in the array, and @ranges_size will contain the size of each entry 1800: * in the array. If KGSL_GPUMEM_BIND_ASYNC is set the operation will be 1801: * performed asynchronously and the operation will immediately return to the 1802: * user. Otherwise the calling context will block until the operation has 1803: * completed. 1804: * 1805: * If KGSL_GPUMEM_BIND_ASYNC and KGSL_GPUMEM_BIND_FENCE_OUT are both set a sync 1806: * fence will be created and returned in @fence_id. The fence will be signaled 1807: * when the bind operation has completed. 1808: */ 1809: struct kgsl_gpumem_bind_ranges { 1810: __u64 ranges; 1811: __u32 ranges_nents; 1812: __u32 ranges_size; 1813: __u32 id; 1814: __u32 flags; 1815: int fence_id; 1816: /* private: 64 bit compatibility */ 1817: __u32 padding; 1818: }; 1819: 1820: #define IOCTL_KGSL_GPUMEM_BIND_RANGES \ 1821: _IOWR(KGSL_IOC_TYPE, 0x56, struct kgsl_gpumem_bind_ranges) 1822: 1823: #define KGSL_GPU_AUX_COMMAND_BIND (1 << 0) 1824: #define KGSL_GPU_AUX_COMMAND_TIMELINE (1 << 1) 1825: /* Reuse the same flag that GPU COMMAND uses */ 1826: #define KGSL_GPU_AUX_COMMAND_SYNC KGSL_CMDBATCH_SYNC 1827: 1828: /** 1829: * struct kgsl_gpu_aux_command_bind - Descriptor for a GPU AUX bind command 1830: * @rangeslist: Pointer to a list of &struct kgsl_gpumem_bind_range items 1831: * @numranges Number of entries in @rangeslist 1832: * @rangesize: Size of each entry in @rangeslist 1833: * @target: The GPU memory ID for the target virtual buffer object 1834: * 1835: * Describe a GPU AUX command to bind ranges in a virtual buffer object. 1836: * @rangeslist points to a &struct kgsl_gpumem_bind_ranges which is the same 1837: * struct that is used by IOCTl_KGSL_GPUMEM_BIND_RANGES. @numrages is the size 1838: * of the array in @rangeslist and @rangesize is the size of each entity in 1839: * @rangeslist. @target points to the GPU ID for the target VBO object. MATCH LINES: 1877, 1881, 1897, 1898, 1909 1865: }; 1866: 1867: /** 1868: * struct kgsl_gpu_aux_command - Argument for IOCTL_KGSL_GPU_AUX_COMMAND 1869: * @flags: flags for the object 1870: * @cmdlist: List of &struct kgsl_gpu_aux_command_generic objects 1871: * @cmd_size: Size of each entry in @cmdlist 1872: * @numcmds: Number of entries in @cmdlist 1873: * @synclist: List of &struct kgsl_command_syncpoint objects 1874: * @syncsize: Size of each entry in @synclist 1875: * @numsyncs: Number of entries in @synclist 1876: * @context_id: ID of the context submitting the aux command 1877: * @timestamp: Timestamp for the command submission 1878: * 1879: * Describe a GPU auxiliary command. Auxiliary commands are tasks that are not 1880: * performed on hardware but can be queued like normal GPU commands. Like GPU 1881: * commands AUX commands are assigned a timestamp and processed in order in the 1882: * queue. They can also have standard sync objects attached. The only 1883: * difference is that AUX commands usually perform some sort of administrative 1884: * task in the CPU and are retired in the dispatcher. 1885: * 1886: * For bind operations flags must have one of the KGSL_GPU_AUX_COMMAND_* flags 1887: * set. If sync objects are attached KGSL_GPU_AUX_COMMAND_SYNC must be set. 1888: * @cmdlist points to an array of &struct kgsl_gpu_aux_command_generic structs 1889: * which in turn will have a pointer to a specific command type. 1890: * @numcmds is the number of commands in the list and @cmdsize is the size 1891: * of each entity in @cmdlist. 1892: * 1893: * If KGSL_GPU_AUX_COMMAND_SYNC is specified @synclist will point to an array of 1894: * &struct kgsl_command_syncpoint items in the same fashion as a GPU hardware 1895: * command. @numsyncs and @syncsize describe the list. 1896: * 1897: * @context_id is the context that is submitting the command and @timestamp 1898: * contains the timestamp for the operation. 1899: */ 1900: struct kgsl_gpu_aux_command { 1901: __u64 flags; 1902: __u64 cmdlist; 1903: __u32 cmdsize; 1904: __u32 numcmds; 1905: __u64 synclist; 1906: __u32 syncsize; 1907: __u32 numsyncs; 1908: __u32 context_id; 1909: __u32 timestamp; 1910: }; 1911: 1912: #define IOCTL_KGSL_GPU_AUX_COMMAND \ 1913: _IOWR(KGSL_IOC_TYPE, 0x57, struct kgsl_gpu_aux_command) 1914: 1915: /** 1916: * struct kgsl_timeline_create - Argument for IOCTL_KGSL_TIMELINE_CREATE 1917: * @seqno: Initial sequence number for the timeline 1918: * @id: Timeline identifier [out] 1919: * 1920: * Create a new semaphore timeline and return the identifier in @id. 1921: * The identifier is global for the device and can be used to 1922: * identify the timeline in all subsequent commands. 1923: */ 1924: struct kgsl_timeline_create { 1925: __u64 seqno; 1926: __u32 id; 1927: /* private: padding for 64 bit compatibility */ 1928: __u32 padding; 1929: }; 1930: 1931: #define IOCTL_KGSL_TIMELINE_CREATE \ 1932: _IOWR(KGSL_IOC_TYPE, 0x58, struct kgsl_timeline_create) 1933: MATCH LINES: 2003, 2004, 2005, 2006, 2011, 2017, 2018 1991: * Signal an array of timelines of type @struct kgsl_timeline_val. 1992: */ 1993: struct kgsl_timeline_signal { 1994: __u64 timelines; 1995: __u32 count; 1996: __u32 timelines_size; 1997: }; 1998: 1999: #define IOCTL_KGSL_TIMELINE_SIGNAL \ 2000: _IOW(KGSL_IOC_TYPE, 0x5B, struct kgsl_timeline_signal) 2001: 2002: /** 2003: * struct kgsl_timeline_fence_get - argument for IOCTL_KGSL_TIMELINE_FENCE_GET 2004: * @seqno: Sequence number for the fence 2005: * @timeline: Timeline to create the fence on 2006: * @handle: Contains the fence fd for a successful operation [out] 2007: * 2008: * Create a sync file descriptor for the seqnum on the timeline and return it in 2009: * @handle. Can be polled and queried just like any other sync file descriptor 2010: */ 2011: struct kgsl_timeline_fence_get { 2012: __u64 seqno; 2013: __u32 timeline; 2014: int handle; 2015: }; 2016: 2017: #define IOCTL_KGSL_TIMELINE_FENCE_GET \ 2018: _IOWR(KGSL_IOC_TYPE, 0x5C, struct kgsl_timeline_fence_get) 2019: /** 2020: * IOCTL_KGSL_TIMELINE_DESTROY takes a u32 identifier for the timeline to 2021: * destroy 2022: */ 2023: #define IOCTL_KGSL_TIMELINE_DESTROY _IOW(KGSL_IOC_TYPE, 0x5D, __u32) 2024: 2025: /** 2026: * struct kgsl_gpu_aux_command_timeline - An aux command for timeline signals 2027: * @timelines: An array of &struct kgsl_timeline_val elements 2028: * @count: The number of entries in @timelines 2029: * @timelines_size: The size of each element in @timelines 2030: * 2031: * An aux command for timeline signals that can be pointed to by 2032: * &struct kgsl_gpu_aux_command_generic when the type is 2033: * KGSL_GPU_AUX_COMMAND_TIMELINE. 2034: */ 2035: struct kgsl_gpu_aux_command_timeline { 2036: __u64 timelines; 2037: __u32 count; 2038: __u32 timelines_size; 2039: }; 2040: 2041: /* Macros for fault type used in kgsl_fault structure */ 2042: #define KGSL_FAULT_TYPE_NO_FAULT 0 MATCH LINES: 2160, 2162, 2163, 2164, 2166, 2169, 2178, 2179 2148: 2149: #define IOCTL_KGSL_RECURRING_COMMAND \ 2150: _IOWR(KGSL_IOC_TYPE, 0x5F, struct kgsl_recurring_command) 2151: 2152: enum kgsl_calibrated_time_domain { 2153: KGSL_CALIBRATED_TIME_DOMAIN_DEVICE = 0, 2154: KGSL_CALIBRATED_TIME_DOMAIN_MONOTONIC = 1, 2155: KGSL_CALIBRATED_TIME_DOMAIN_MONOTONIC_RAW = 2, 2156: KGSL_CALIBRATED_TIME_DOMAIN_MAX, 2157: }; 2158: 2159: /** 2160: * struct kgsl_read_calibrated_timestamps - Argument for IOCTL_KGSL_READ_CALIBRATED_TIMESTAMPS 2161: * @sources: List of time domains of type enum kgsl_calibrated_time_domain 2162: * @ts: List of calibrated timestamps 2163: * @deviation: Deviation between timestamp samples in nsecs 2164: * @count: Number of timestamps to read 2165: * 2166: * Returns a list of calibrated timestamps corresponding to an input list of time domains to 2167: * query. 2168: */ 2169: struct kgsl_read_calibrated_timestamps { 2170: __u64 __user sources; 2171: __u64 __user ts; 2172: __u64 deviation; 2173: __u32 count; 2174: /* private: Padding for 64 bit compatibility */ 2175: __u32 padding; 2176: }; 2177: 2178: #define IOCTL_KGSL_READ_CALIBRATED_TIMESTAMPS \ 2179: _IOWR(KGSL_IOC_TYPE, 0x60, struct kgsl_read_calibrated_timestamps) 2180: 2181: /* Macro for unused field in kgsl_dcvs_attrs structure */ 2182: #define KGSL_DCVS_ATTR_UNUSED 0xFFFFFFFF 2183: 2184: /** 2185: * struct kgsl_dcvs_attrs - Descriptor for DCVS profile attributes 2186: * @min_gpu_freq: Minimum GPU frequency in MHz 2187: * Requested frequency is floor GPU frequency clamped to the supported range 2188: * and rounded down to a supported frequency level 2189: * @max_gpu_freq: Maximum GPU frequency in MHz 2190: * Requested frequency is ceil GPU frequency clamped to the supported range 2191: * and rounded down to a supported frequency level 2192: * @target_fps: Target frame rate input to DCVS algorithm 2193: * @penalty_up: Average gpu busy% threshold to step up one level 2194: * @penalty_down: Average gpu busy% threshold to step down one level 2195: * @first_step_down_count: Number of consecutive down recommendations before first step down 2196: * @subsequent_step_down_count: Number of consecutive down recommendations for subsequent step down 2197: * after first step down 2198: * @num_samples_up: Moving average window size used for vote up decision 2199: * @num_samples_down: Moving average window size used for vote down decision 2200: * @strict_frame: Flag used to enable/disable vote up decision if the average gpu busy% over some 2201: * consecutive samples is very high. This node takes effect only when target_fps is configured 2202: * @non_linear_ramp_up: Flag used to enable/disable non-linear ramp up which supports a larger 2203: * stride jump if the gpu busy% is very high TOTAL MATCHES: 3635 ========================================================================================== SUBSYSTEM: MEMORY_AND_GEM ========================================================================================== --- FILE: \adreno.c | HITS: 66 --- MATCH LINES: 51, 52, 53 39: #include "adreno_pm4types.h" 40: #include "adreno_trace.h" 41: #include "kgsl_bus.h" 42: #include "kgsl_gmu_core.h" 43: #include "kgsl_power_trace.h" 44: #include "kgsl_reclaim.h" 45: #include "kgsl_trace.h" 46: #include "kgsl_util.h" 47: 48: /* Include the master list of GPU cores that are supported */ 49: #include "adreno-gpulist.h" 50: 51: #define HOSTADDR_IN_MEMDESC(_addr, _memdesc) \ 52: (((_addr) >= (_memdesc)->hostptr) && \ 53: ((_addr) < ((_memdesc)->hostptr + (_memdesc)->size))) 54: 55: /* Indicates that the context record table is present in CP ucode */ 56: #define CTXT_RECORD_TBL_MAGIC 0xADDED 57: #define CTXT_RECORD_MAGIC_OFFSET 5 58: #define CTXT_TBL_OFFSET 6 59: /* Mask for extracting the instruction payload from ucode instructions */ 60: #define CTXT_RECORD_PAYLOAD_MASK GENMASK(23, 0) 61: 62: /** 63: * struct gpu_ctxt_record - Information about GPU context record, defined per GPU. 64: * If a ucode is shared by multiple targets, there will be multiple instances 65: * of this structure embedded in the ucode. Instances of this structure will be 66: * present immediately after ctxt_record_info. 67: */ 68: struct gpu_ctxt_record { 69: /** 70: * @hw_version: GPU hardware version 71: * [15:0]: Step, should be 0. 72: * [27:16]: Minor 73: * [31:28]: Major 74: */ 75: u32 hw_version; 76: /** @ctxt_record_size: Size of preemption record in KB */ 77: u32 ctxt_record_size; MATCH LINES: 132, 137, 140, 157, 158 120: 121: version = data[1]; 122: 123: if ((version & 0xf) != 0xa) 124: return version; 125: 126: version &= ~0xfff; 127: return version | ((data[3] & 0xfff000) >> 12); 128: } 129: 130: int adreno_populate_ctxt_record_size(struct adreno_device *adreno_dev) 131: { 132: struct kgsl_memdesc *memdesc = ADRENO_FW(adreno_dev, ADRENO_FW_SQE)->memdesc; 133: struct ctxt_record_info *info; 134: u32 *hostptr; 135: int i; 136: 137: if (!memdesc) 138: return -ENODEV; 139: 140: hostptr = (u32 *)memdesc->hostptr; 141: 142: /* 143: * SQE firmware inserts context record magic at offset 5. 144: * The pointer to context record table is stored at offset 6. 145: * The values are stored at [23:0]. 146: */ 147: if ((hostptr[CTXT_RECORD_MAGIC_OFFSET] & 148: CTXT_RECORD_PAYLOAD_MASK) != CTXT_RECORD_TBL_MAGIC) 149: return -ENODEV; 150: 151: /* Calculate the address of the context record table */ 152: hostptr += (hostptr[CTXT_TBL_OFFSET] & CTXT_RECORD_PAYLOAD_MASK); 153: info = (struct ctxt_record_info *) hostptr; 154: hostptr += (sizeof(*info) >> 2); 155: 156: /* Validate that the entire context record table is within mapped range */ 157: if (!HOSTADDR_IN_MEMDESC((void *)(hostptr + 158: ((u64) info->num_gpus * (u64) info->dwords_per_gpu)), memdesc)) 159: return -EACCES; 160: 161: for (i = 0; i < info->num_gpus; i++) { 162: struct gpu_ctxt_record *record = (struct gpu_ctxt_record *) hostptr; 163: u32 major, minor; 164: 165: /* Compare the GPU revision to determine context record size */ 166: major = FIELD_GET(GENMASK(31, 28), record->hw_version); 167: minor = FIELD_GET(GENMASK(27, 16), record->hw_version); 168: 169: if ((ADRENO_REV_MAJOR(ADRENO_GPUREV(adreno_dev)) == major) && 170: (ADRENO_REV_MINOR(ADRENO_GPUREV(adreno_dev)) == minor)) { 171: adreno_dev->total_ctxt_record_sz = record->ctxt_record_size * SZ_1K; 172: 173: /* From v0.2, GMEM size is not exposed through ucode binary */ 174: if ((info->version & GENMASK(11, 0)) >= 2) 175: adreno_dev->total_ctxt_record_sz += adreno_gmem_size(adreno_dev); 176: 177: adreno_dev->aqe_ctxt_record_sz = record->aqe_size * SZ_1K; 178: return 0; 179: } 180: 181: hostptr += info->dwords_per_gpu; 182: } MATCH LINES: 260, 268, 269, 272, 274 248: destroy_work_on_stack(&work.work); 249: 250: return ret; 251: } 252: 253: int adreno_get_firmware(struct adreno_device *adreno_dev, 254: const char *fwfile, struct adreno_firmware *firmware) 255: { 256: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 257: const struct firmware *fw = NULL; 258: int ret; 259: 260: if (!IS_ERR_OR_NULL(firmware->memdesc)) 261: return 0; 262: 263: ret = adreno_request_firmware(&fw, fwfile, &device->pdev->dev, true); 264: 265: if (ret) 266: return ret; 267: 268: firmware->memdesc = kgsl_allocate_global(device, fw->size - 4, 0, 269: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_UCODE, 270: "ucode"); 271: 272: ret = PTR_ERR_OR_ZERO(firmware->memdesc); 273: if (!ret) { 274: memcpy(firmware->memdesc->hostptr, &fw->data[4], fw->size - 4); 275: firmware->size = (fw->size - 4) / sizeof(u32); 276: firmware->version = get_ucode_version((u32 *)fw->data); 277: } 278: 279: release_firmware(fw); 280: return ret; 281: } 282: 283: /* 284: * The PASID has stayed consistent across all targets thus far so we are 285: * cautiously optimistic that we can hard code it 286: */ 287: #define GPU_PASID 13 288: 289: /* True when zap-shader is present */ 290: static bool adreno_check_zap_enabled(struct kgsl_device *device) 291: { 292: struct device_node *np = of_get_child_by_name(device->pdev->dev.of_node, 293: "zap-shader"); 294: bool present = of_device_is_available(np); 295: 296: of_node_put(np); 297: return present; 298: } MATCH LINES: 452 440: /** 441: * adreno_get_rptr() - Get the current ringbuffer read pointer 442: * @rb: Pointer the ringbuffer to query 443: * 444: * Get the latest rptr 445: */ 446: unsigned int adreno_get_rptr(struct adreno_ringbuffer *rb) 447: { 448: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 449: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 450: u32 rptr = 0; 451: 452: kgsl_sharedmem_readl(device->scratch, &rptr, 453: SCRATCH_RB_OFFSET(rb->id, rptr)); 454: 455: return rptr; 456: } 457: 458: static void adreno_touch_wakeup(struct adreno_device *adreno_dev) 459: { 460: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 461: 462: /* 463: * Don't schedule adreno_start in a high priority workqueue, we are 464: * already in a workqueue which should be sufficient 465: */ 466: kgsl_pwrctrl_change_state(device, KGSL_STATE_ACTIVE); 467: 468: /* 469: * When waking up from a touch event we want to stay active long enough 470: * for the user to send a draw command. The default idle timer timeout 471: * is shorter than we want so go ahead and push the idle timer out 472: * further for this special case 473: */ 474: mod_timer(&device->idle_timer, 475: jiffies + msecs_to_jiffies(adreno_wake_timeout)); 476: MATCH LINES: 2252, 2255 2240: 2241: res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "aperture"); 2242: if (res) { 2243: device->smmu_aperture_virt = devm_ioremap(dev, res->start, 2244: resource_size(res)); 2245: if (!device->smmu_aperture_virt) 2246: dev_warn(dev, "aperture ioremap failed\n"); 2247: } 2248: 2249: if (kgsl_regmap_add_region(&device->regmap, pdev, "isense_cntl", -EINVAL, NULL, NULL) == 0) 2250: adreno_dev->isense_reg_mapped = true; 2251: 2252: /* Allocate the memstore for storing timestamps and other useful info */ 2253: 2254: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 2255: priv |= KGSL_MEMDESC_PRIVILEGED; 2256: 2257: kgsl_mutex_lock(&device->mutex); 2258: device->memstore = kgsl_allocate_global(device, 2259: KGSL_MEMSTORE_SIZE, 0, 0, priv, "memstore"); 2260: adreno_profile_init(adreno_dev); 2261: kgsl_mutex_unlock(&device->mutex); 2262: 2263: status = PTR_ERR_OR_ZERO(device->memstore); 2264: if (status) { 2265: trace_array_put(device->fence_trace_array); 2266: kgsl_device_platform_remove(device); 2267: goto err_unbind; 2268: } 2269: 2270: /* Initialize UBWC mode and HBB */ 2271: status = adreno_init_ubwc(adreno_dev); 2272: if (status) { 2273: trace_array_put(device->fence_trace_array); 2274: kgsl_device_platform_remove(device); 2275: goto err_unbind; 2276: } 2277: 2278: /* Initialize the snapshot engine */ 2279: size = adreno_dev->gpucore->snapshot_size; MATCH LINES: 2561 2549: kthread_flush_worker(device->events_worker); 2550: flush_workqueue(kgsl_driver.lockless_workqueue); 2551: 2552: return status; 2553: } 2554: 2555: void adreno_create_profile_buffer(struct adreno_device *adreno_dev) 2556: { 2557: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2558: unsigned int priv = 0; 2559: 2560: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 2561: priv = KGSL_MEMDESC_PRIVILEGED; 2562: 2563: adreno_allocate_global(device, &adreno_dev->profile_buffer, 2564: PAGE_SIZE, 0, 0, priv, "alwayson"); 2565: 2566: adreno_dev->profile_index = 0; 2567: 2568: if (!IS_ERR(adreno_dev->profile_buffer)) 2569: set_bit(ADRENO_DEVICE_DRAWOBJ_PROFILE, 2570: &adreno_dev->priv); 2571: } 2572: 2573: static int adreno_init(struct kgsl_device *device) 2574: { 2575: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 2576: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 2577: int ret; 2578: 2579: ret = kgsl_pwrctrl_change_state(device, KGSL_STATE_INIT); 2580: if (ret) 2581: return ret; 2582: 2583: /* 2584: * initialization only needs to be done once initially until 2585: * device is shutdown MATCH LINES: 2632 2620: 2621: void adreno_set_active_ctxs_null(struct adreno_device *adreno_dev) 2622: { 2623: int i; 2624: struct adreno_ringbuffer *rb; 2625: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2626: 2627: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2628: if (rb->drawctxt_active) 2629: kgsl_context_put(&(rb->drawctxt_active->base)); 2630: rb->drawctxt_active = NULL; 2631: 2632: kgsl_sharedmem_writel(device->scratch, 2633: SCRATCH_RB_OFFSET(rb->id, current_rb_ptname), 2634: 0); 2635: } 2636: } 2637: 2638: static int adreno_open(struct adreno_device *adreno_dev) 2639: { 2640: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2641: int ret; 2642: 2643: /* 2644: * active_cnt special case: we are starting up for the first 2645: * time, so use this sequence instead of the kgsl_pwrctrl_wake() 2646: * which will be called by adreno_active_count_get(). 2647: */ 2648: atomic_inc(&device->active_cnt); 2649: 2650: memset(device->memstore->hostptr, 0, device->memstore->size); 2651: 2652: ret = adreno_init(device); 2653: if (ret) 2654: goto err; 2655: 2656: ret = adreno_start(device, 0); MATCH LINES: 3124, 3140, 3153 3112: sizeof(model.gpu_model)); 3113: 3114: return copy_prop(param, &model, sizeof(model)); 3115: } 3116: 3117: static int adreno_prop_device_shadow(struct kgsl_device *device, 3118: struct kgsl_device_getproperty *param) 3119: { 3120: struct kgsl_shadowprop shadowprop = { 0 }; 3121: 3122: if (device->memstore->hostptr) { 3123: /* Pass a dummy address to identify memstore */ 3124: shadowprop.gpuaddr = KGSL_MEMSTORE_TOKEN_ADDRESS; 3125: shadowprop.size = device->memstore->size; 3126: 3127: shadowprop.flags = KGSL_FLAGS_INITIALIZED | 3128: KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS; 3129: } 3130: 3131: return copy_prop(param, &shadowprop, sizeof(shadowprop)); 3132: } 3133: 3134: static int adreno_prop_device_qdss_stm(struct kgsl_device *device, 3135: struct kgsl_device_getproperty *param) 3136: { 3137: struct kgsl_qdss_stm_prop qdssprop = {0}; 3138: 3139: if (!IS_ERR_OR_NULL(device->qdss_desc)) { 3140: qdssprop.gpuaddr = device->qdss_desc->gpuaddr; 3141: qdssprop.size = device->qdss_desc->size; 3142: } 3143: 3144: return copy_prop(param, &qdssprop, sizeof(qdssprop)); 3145: } 3146: 3147: static int adreno_prop_device_qtimer(struct kgsl_device *device, 3148: struct kgsl_device_getproperty *param) 3149: { 3150: struct kgsl_qtimer_prop qtimerprop = {0}; 3151: 3152: if (!IS_ERR_OR_NULL(device->qtimer_desc)) { 3153: qtimerprop.gpuaddr = device->qtimer_desc->gpuaddr; 3154: qtimerprop.size = device->qtimer_desc->size; 3155: } 3156: 3157: return copy_prop(param, &qtimerprop, sizeof(qtimerprop)); 3158: } 3159: 3160: static int adreno_prop_s32(struct kgsl_device *device, 3161: struct kgsl_device_getproperty *param) 3162: { 3163: int val = 0; 3164: 3165: if (param->type == KGSL_PROP_MMU_ENABLE) 3166: val = kgsl_mmu_has_feature(device, KGSL_MMU_PAGED); 3167: else if (param->type == KGSL_PROP_INTERRUPT_WAITS) 3168: val = 1; 3169: 3170: return copy_prop(param, &val, sizeof(val)); 3171: } 3172: 3173: static int adreno_prop_uche_gmem_addr(struct kgsl_device *device, 3174: struct kgsl_device_getproperty *param) 3175: { 3176: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 3177: MATCH LINES: 3508, 3512, 3539, 3555 3496: } else { 3497: device->ftbl->gmu_based_dcvs_pwr_ops(device, enable, 3498: GPU_PWRLEVEL_OP_DCVS_ENABLE); 3499: device->ftbl->gmu_based_dcvs_pwr_ops(device, 0, GPU_PWRLEVEL_OP_GPUCLK); 3500: } 3501: } 3502: 3503: kgsl_mutex_unlock(&device->mutex); 3504: 3505: return 0; 3506: } 3507: 3508: static void adreno_alloc_dcvs_profile_memory(struct kgsl_device *device, 3509: struct kgsl_process_private *proc_priv) 3510: { 3511: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 3512: struct kgsl_memdesc *md = &proc_priv->profile.md; 3513: u32 sizebytes; 3514: 3515: if (!ADRENO_FEATURE(adreno_dev, ADRENO_DCVS_PROFILE)) 3516: return; 3517: 3518: if (!gmu_core_alloc_kernel_block(device, md, 3519: SZ_4K, GMU_NONCACHED_KERNEL, 3520: IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV)) { 3521: /* KMD need to initialize KGSL region to KGSL_DCVS_ATTR_UNUSED for 3522: * torn state handling as per design and second half region to 0 so that 3523: * if there is no profile ever registered for a process, GMU can skip 3524: * tracking for this profile. 3525: */ 3526: sizebytes = md->size >> 1; 3527: memset(md->hostptr, KGSL_DCVS_ATTR_UNUSED, sizebytes); 3528: memset(md->hostptr + sizebytes, 0, sizebytes); 3529: } 3530: } 3531: 3532: static int adreno_set_dcvs_profile(struct kgsl_device_private *dev_priv, 3533: void __user *data, u32 sizebytes) 3534: { 3535: struct kgsl_device *device = dev_priv->device; 3536: struct kgsl_process_private *proc_priv = dev_priv->process_priv; 3537: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 3538: const struct adreno_hwsched_ops *hwsched_ops = adreno_dev->hwsched.hwsched_ops; 3539: struct kgsl_memdesc *md = &proc_priv->profile.md; 3540: struct kgsl_dcvs_profile param = {0}; 3541: struct kgsl_dcvs_attrs attrs; 3542: u32 size; 3543: int ret = 0; 3544: 3545: if (!ADRENO_FEATURE(adreno_dev, ADRENO_DCVS_PROFILE)) 3546: return -EOPNOTSUPP; 3547: 3548: /* Restrict to one profile per process */ 3549: mutex_lock(&proc_priv->profile.profile_mutex); 3550: if (proc_priv->profile.user_profile_registered) { 3551: ret = -EINVAL; 3552: goto done; 3553: } 3554: 3555: /* Not enough allocated GMU memory */ 3556: if ((!md->hostptr) || (sizeof(attrs) > (md->size >> 1))) { 3557: ret = -ENOMEM; 3558: goto done; 3559: } 3560: 3561: size = min_t(u32, sizeof(param), sizebytes); 3562: if (copy_from_user(¶m, data, size)) { 3563: ret = -EFAULT; 3564: goto done; 3565: } 3566: 3567: /* 3568: * Divide shared buffer into two equal parts and first part addresses 3569: * should be reserved for KGSL to copy profile buffer and second 3570: * part addresses for GMU Internal usage. 3571: */ 3572: size = min_t(u32, sizeof(attrs), param.attrs_size); 3573: 3574: if (copy_from_user(md->hostptr, u64_to_user_ptr(param.attrs), size)) { 3575: memset(md->hostptr, KGSL_DCVS_ATTR_UNUSED, size); 3576: ret = -EFAULT; 3577: goto done; 3578: } 3579: MATCH LINES: 3880, 3881, 3900 3868: if (!time) 3869: return; 3870: 3871: drawobj = time->drawobj; 3872: if (drawobj == NULL) 3873: return; 3874: 3875: cmdobj = CMDOBJ(drawobj); 3876: entry = cmdobj->profiling_buf_entry; 3877: if (!entry) 3878: return; 3879: 3880: profile_buffer = kgsl_gpuaddr_to_vaddr(&entry->memdesc, 3881: cmdobj->profiling_buffer_gpuaddr); 3882: 3883: if (profile_buffer == NULL) 3884: return; 3885: 3886: /* Return kernel clock time to the client if requested */ 3887: if (drawobj->flags & KGSL_DRAWOBJ_PROFILING_KTIME) { 3888: u64 secs = time->ktime; 3889: 3890: profile_buffer->wall_clock_ns = 3891: do_div(secs, NSEC_PER_SEC); 3892: profile_buffer->wall_clock_s = secs; 3893: } else { 3894: profile_buffer->wall_clock_s = time->utime.tv_sec; 3895: profile_buffer->wall_clock_ns = time->utime.tv_nsec; 3896: } 3897: 3898: profile_buffer->gpu_ticks_queued = time->ticks; 3899: 3900: kgsl_memdesc_unmap(&entry->memdesc); 3901: } 3902: 3903: /** 3904: * adreno_waittimestamp - sleep while waiting for the specified timestamp 3905: * @device - pointer to a KGSL device structure 3906: * @context - pointer to the active kgsl context 3907: * @timestamp - GPU timestamp to wait for 3908: * @msecs - amount of time to wait (in milliseconds) 3909: * 3910: * Wait up to 'msecs' milliseconds for the specified timestamp to expire. 3911: */ 3912: static int adreno_waittimestamp(struct kgsl_device *device, 3913: struct kgsl_context *context, 3914: unsigned int timestamp, 3915: unsigned int msecs) 3916: { 3917: int ret; 3918: 3919: if (context == NULL) { 3920: /* If they are doing then complain once */ 3921: dev_WARN_ONCE(device->dev, 1, 3922: "IOCTL_KGSL_DEVICE_WAITTIMESTAMP is deprecated\n"); 3923: return -ENOTTY; 3924: } MATCH LINES: 3964, 3968 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. MATCH LINES: 4180, 4181, 4182, 4183 4168: { 4169: struct kgsl_device *device = dev_priv->device; 4170: struct kgsl_process_private *private = dev_priv->process_priv; 4171: 4172: /* The maximum allowable size for an IB in the CP is 0xFFFFF dwords */ 4173: if (ib->size == 0 || ((ib->size >> 2) > 0xFFFFF)) { 4174: pr_context(device, context, "ctxt %u invalid ib size %lld\n", 4175: context->id, ib->size); 4176: return false; 4177: } 4178: 4179: /* Make sure that the address is in range and dword aligned */ 4180: if (!kgsl_mmu_gpuaddr_in_range(private->pagetable, ib->gpuaddr, 4181: ib->size) || !IS_ALIGNED(ib->gpuaddr, 4)) { 4182: pr_context(device, context, "ctxt %u invalid ib gpuaddr %llX\n", 4183: context->id, ib->gpuaddr); 4184: return false; 4185: } 4186: 4187: return true; 4188: } 4189: 4190: int adreno_verify_cmdobj(struct kgsl_device_private *dev_priv, 4191: struct kgsl_context *context, struct kgsl_drawobj *drawobj[], 4192: uint32_t count) 4193: { 4194: struct kgsl_device *device = dev_priv->device; 4195: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4196: struct kgsl_memobj_node *ib; 4197: unsigned int i; 4198: 4199: for (i = 0; i < count; i++) { 4200: /* Verify the IBs before they get queued */ 4201: if (drawobj[i]->type == CMDOBJ_TYPE) { 4202: struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj[i]); 4203: 4204: /* Only allow mALU submissions if hardware supports mALU */ 4205: if ((drawobj[i]->flags & KGSL_DRAWOBJ_USES_MALU) && 4206: !adreno_dev->malu_enabled) { 4207: dev_err_once(device->dev, "mALU workload isn't supported\n"); MATCH LINES: 4754 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, 4771: }; 4772: 4773: static int _compare_of(struct device *dev, void *data) 4774: { 4775: return (dev->of_node == data); 4776: } 4777: 4778: static void _release_of(struct device *dev, void *data) MATCH LINES: 4868, 4869, 4875, 4876, 4877, 4878, 4883, 4886, 4894, 4895, 4896, 4897, 4902, 4910, 4911, 4912, 4913, 4914, 4926, 4927, 4931, 4932, 4933, 4934, 4939, 4946, 4947, 4948, 4949, 4954, 4959 4856: 4857: #if IS_ENABLED(CONFIG_QCOM_KGSL_HIBERNATION) 4858: #if IS_ENABLED(CONFIG_QCOM_SECURE_BUFFER) 4859: /* 4860: * Issue hyp_assign call to assign non-used internal/userspace secure 4861: * buffers to kernel. 4862: */ 4863: static int adreno_secure_pt_hibernate(struct adreno_device *adreno_dev) 4864: { 4865: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 4866: struct kgsl_process_private *process; 4867: struct kgsl_mem_entry *entry; 4868: struct kgsl_global_memdesc *md; 4869: struct kgsl_memdesc *memdesc; 4870: int ret, id; 4871: 4872: read_lock(&kgsl_driver.proclist_lock); 4873: list_for_each_entry(process, &kgsl_driver.process_list, list) { 4874: idr_for_each_entry(&process->mem_idr, entry, id) { 4875: memdesc = &entry->memdesc; 4876: if (!kgsl_memdesc_is_secured(memdesc) || 4877: (memdesc->flags & KGSL_MEMFLAGS_USERMEM_ION) || 4878: (TEST_FLAG(KGSL_MEMDESC_HYPASSIGNED_HLOS, &memdesc->priv))) 4879: continue; 4880: 4881: read_unlock(&kgsl_driver.proclist_lock); 4882: 4883: if (kgsl_unlock_sgt(memdesc->sgt)) 4884: dev_err(device->dev, "kgsl_unlock_sgt failed\n"); 4885: 4886: SET_FLAG(KGSL_MEMDESC_HYPASSIGNED_HLOS, &memdesc->priv); 4887: 4888: read_lock(&kgsl_driver.proclist_lock); 4889: } 4890: } 4891: read_unlock(&kgsl_driver.proclist_lock); 4892: 4893: list_for_each_entry(md, &device->globals, node) { 4894: memdesc = &md->memdesc; 4895: if (kgsl_memdesc_is_secured(memdesc) && 4896: !(TEST_FLAG(KGSL_MEMDESC_HYPASSIGNED_HLOS, &memdesc->priv))) { 4897: ret = kgsl_unlock_sgt(memdesc->sgt); 4898: if (ret) { 4899: dev_err(device->dev, "kgsl_unlock_sgt failed ret %d\n", ret); 4900: goto fail; 4901: } 4902: SET_FLAG(KGSL_MEMDESC_HYPASSIGNED_HLOS, &memdesc->priv); 4903: } 4904: } 4905: 4906: return 0; 4907: 4908: fail: 4909: list_for_each_entry(md, &device->globals, node) { 4910: memdesc = &md->memdesc; 4911: if (kgsl_memdesc_is_secured(memdesc) && 4912: (TEST_FLAG(KGSL_MEMDESC_HYPASSIGNED_HLOS, &memdesc->priv))) { 4913: kgsl_lock_sgt(memdesc->sgt, memdesc->size); 4914: CLEAR_FLAG(KGSL_MEMDESC_HYPASSIGNED_HLOS, &memdesc->priv); 4915: } 4916: } 4917: 4918: return -EBUSY; 4919: } 4920: 4921: static int adreno_secure_pt_restore(struct adreno_device *adreno_dev) 4922: { 4923: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 4924: struct kgsl_process_private *process; 4925: struct kgsl_mem_entry *entry; 4926: struct kgsl_memdesc *memdesc; 4927: struct kgsl_global_memdesc *md; 4928: int ret, id; 4929: 4930: list_for_each_entry(md, &device->globals, node) { 4931: memdesc = &md->memdesc; 4932: if (kgsl_memdesc_is_secured(memdesc) && 4933: (TEST_FLAG(KGSL_MEMDESC_HYPASSIGNED_HLOS, &memdesc->priv))) { 4934: ret = kgsl_lock_sgt(memdesc->sgt, memdesc->size); 4935: if (ret) { 4936: dev_err(device->dev, "kgsl_lock_sgt failed ret %d\n", ret); 4937: return ret; 4938: } 4939: CLEAR_FLAG(KGSL_MEMDESC_HYPASSIGNED_HLOS, &memdesc->priv); 4940: } 4941: } 4942: 4943: read_lock(&kgsl_driver.proclist_lock); 4944: list_for_each_entry(process, &kgsl_driver.process_list, list) { 4945: idr_for_each_entry(&process->mem_idr, entry, id) { 4946: memdesc = &entry->memdesc; 4947: if (!kgsl_memdesc_is_secured(memdesc) || 4948: (memdesc->flags & KGSL_MEMFLAGS_USERMEM_ION) || 4949: !(TEST_FLAG(KGSL_MEMDESC_HYPASSIGNED_HLOS, &memdesc->priv))) 4950: continue; 4951: 4952: read_unlock(&kgsl_driver.proclist_lock); 4953: 4954: ret = kgsl_lock_sgt(memdesc->sgt, memdesc->size); 4955: if (ret) { 4956: dev_err(device->dev, "kgsl_lock_sgt failed ret %d\n", ret); 4957: return ret; 4958: } 4959: CLEAR_FLAG(KGSL_MEMDESC_HYPASSIGNED_HLOS, &memdesc->priv); 4960: 4961: read_lock(&kgsl_driver.proclist_lock); 4962: } 4963: } 4964: read_unlock(&kgsl_driver.proclist_lock); 4965: 4966: return 0; 4967: } 4968: #else 4969: static int adreno_secure_pt_hibernate(struct adreno_device *adreno_dev) 4970: { 4971: return 0; 4972: } 4973: 4974: static int adreno_secure_pt_restore(struct adreno_device *adreno_dev) 4975: { 4976: return 0; 4977: } 4978: #endif /* IS_ENABLED(CONFIG_QCOM_SECURE_BUFFER) */ 4979: 4980: static int adreno_hibernation_suspend(struct device *dev) 4981: { 4982: struct kgsl_device *device = dev_get_drvdata(dev); 4983: struct adreno_device *adreno_dev; --- FILE: \adreno.h | HITS: 23 --- MATCH LINES: 20 8: 9: #include 10: #include 11: #include 12: #include 13: #include "adreno_coresight.h" 14: #include "adreno_dispatch.h" 15: #include "adreno_drawctxt.h" 16: #include "adreno_hwsched.h" 17: #include "adreno_perfcounter.h" 18: #include "adreno_profile.h" 19: #include "adreno_ringbuffer.h" 20: #include "kgsl_sharedmem.h" 21: 22: /* Used to point CP to the SMMU record during preemption */ 23: #define SET_PSEUDO_SMMU_INFO 0 24: /* Used to inform CP where to save preemption data at the time of switch out */ 25: #define SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR 1 26: /* Used to inform CP where to save secure preemption data at the time of switch out */ 27: #define SET_PSEUDO_PRIV_SECURE_SAVE_ADDR 2 28: /* Used to inform CP where to save per context non-secure data at the time of switch out */ 29: #define SET_PSEUDO_NON_PRIV_SAVE_ADDR 3 30: /* Used to inform CP where to save preemption counter data at the time of switch out */ 31: #define SET_PSEUDO_COUNTER 4 32: 33: /* Index to preemption scratch buffer to store current QOS value */ 34: #define QOS_VALUE_IDX KGSL_PRIORITY_MAX_RB_LEVELS 35: 36: /* Size of the user context record block (in bytes) */ 37: #define ADRENO_CP_CTXRECORD_USER_RESTORE_SIZE (192 * SZ_1K) 38: 39: /* ADRENO_DEVICE - Given a kgsl_device return the adreno device struct */ 40: #define ADRENO_DEVICE(device) \ 41: container_of(device, struct adreno_device, dev) 42: 43: /* KGSL_DEVICE - given an adreno_device, return the KGSL device struct */ 44: #define KGSL_DEVICE(_dev) (&((_dev)->dev)) MATCH LINES: 187 175: /* AQE supported on this target */ 176: #define ADRENO_AQE BIT(18) 177: /* Warm Boot supported on this target */ 178: #define ADRENO_GMU_WARMBOOT BIT(19) 179: /* The GPU supports CLX */ 180: #define ADRENO_CLX BIT(20) 181: /* Enable GMU support for GMU based thermal mitigation */ 182: #define ADRENO_GMU_THERMAL_MITIGATION BIT(21) 183: /* GMU Based DCVS */ 184: #define ADRENO_GMU_BASED_DCVS BIT(22) 185: /* RT hint feature for RB0 workloads */ 186: #define ADRENO_RT_HINT BIT(23) 187: /* Defer allocation of preemption record gmem memory when needed */ 188: #define ADRENO_DEFER_GMEM_ALLOC BIT(24) 189: /* The GMU supports MINBW voting */ 190: #define ADRENO_GMU_MINBW BIT(25) 191: /* Enable GMU Based DCVS profile */ 192: #define ADRENO_DCVS_PROFILE BIT(26) 193: /* Enable TSENSE power savings during sleep */ 194: #define ADRENO_TSENSE_DYNAMIC_PERIOD BIT(27) 195: /* Enable GMU Based AB voting */ 196: #define ADRENO_GMU_AB BIT(28) 197: /* Enable GMU Fast Context Destroy optimization */ 198: #define ADRENO_GMU_FAST_CONTEXT_DESTROY BIT(29) 199: /* 200: * The target uses the GPU_CX_MISC_SW_FUSE_FREQ_LIMIT_STATUS register to 201: * get combined (HW + SW) speedbin when no nvmem speed_bin cell exists. 202: */ 203: #define ADRENO_SOFTFUSE BIT_ULL(32) 204: /* 205: * Adreno GPU quirks - control bits for various workarounds 206: */ 207: 208: /* Set TWOPASSUSEWFI in PC_DBG_ECO_CNTL (5XX/6XX) */ 209: #define ADRENO_QUIRK_TWO_PASS_USE_WFI BIT(0) 210: /* Submit critical packets at GPU wake up */ 211: #define ADRENO_QUIRK_CRITICAL_PACKETS BIT(1) MATCH LINES: 378 366: 367: /* number of throttle counters for DCVS adjustment */ 368: #define ADRENO_GPMU_THROTTLE_COUNTERS 4 369: 370: struct adreno_gpudev; 371: 372: /* Time to allow preemption to complete (in ms) */ 373: #define ADRENO_PREEMPT_TIMEOUT 10000 374: 375: #define PREEMPT_SCRATCH_OFFSET(id) (id * sizeof(u64)) 376: 377: #define PREEMPT_SCRATCH_ADDR(dev, id) \ 378: ((dev)->preempt.scratch->gpuaddr + PREEMPT_SCRATCH_OFFSET(id)) 379: 380: /** 381: * enum adreno_preempt_states 382: * ADRENO_PREEMPT_NONE: No preemption is scheduled 383: * ADRENO_PREEMPT_START: The S/W has started 384: * ADRENO_PREEMPT_TRIGGERED: A preeempt has been triggered in the HW 385: * ADRENO_PREEMPT_FAULTED: The preempt timer has fired 386: * ADRENO_PREEMPT_PENDING: The H/W has signaled preemption complete 387: * ADRENO_PREEMPT_COMPLETE: Preemption could not be finished in the IRQ handler, 388: * worker has been scheduled 389: */ 390: enum adreno_preempt_states { 391: ADRENO_PREEMPT_NONE = 0, 392: ADRENO_PREEMPT_START, 393: ADRENO_PREEMPT_TRIGGERED, 394: ADRENO_PREEMPT_FAULTED, 395: ADRENO_PREEMPT_PENDING, 396: ADRENO_PREEMPT_COMPLETE, 397: }; 398: 399: /** 400: * struct adreno_protected_regs - container for a protect register span 401: */ 402: struct adreno_protected_regs { MATCH LINES: 432, 467, 473 420: * struct adreno_preemption 421: * @state: The current state of preemption 422: * @scratch: Per-target scratch memory for implementation specific functionality 423: * @timer: A timer to make sure preemption doesn't stall 424: * @work: A work struct for the preemption worker (for 5XX) 425: * preempt_level: The level of preemption (for 6XX) 426: * skipsaverestore: To skip saverestore during L1 preemption (for 6XX) 427: * usesgmem: enable GMEM save/restore across preemption (for 6XX) 428: * count: Track the number of preemptions triggered 429: */ 430: struct adreno_preemption { 431: atomic_t state; 432: struct kgsl_memdesc *scratch; 433: struct timer_list timer; 434: struct work_struct work; 435: unsigned int preempt_level; 436: bool skipsaverestore; 437: bool usesgmem; 438: unsigned int count; 439: /* @postamble_len: Number of dwords in KMD postamble pm4 packet */ 440: u32 postamble_len; 441: /* 442: * @postamble_bootup_len: Number of dwords in KMD postamble pm4 packet 443: * that needs to be sent before first submission to GPU. 444: * Note: Postambles are not preserved across slumber. 445: */ 446: u32 postamble_bootup_len; 447: }; 448: 449: struct adreno_busy_data { 450: unsigned int gpu_busy; 451: unsigned int bif_ram_cycles; 452: unsigned int bif_ram_cycles_read_ch1; 453: unsigned int bif_ram_cycles_write_ch0; 454: unsigned int bif_ram_cycles_write_ch1; 455: unsigned int bif_starved_ram; 456: unsigned int bif_starved_ram_ch1; 457: unsigned int num_ifpc; 458: unsigned int throttle_cycles[ADRENO_GPMU_THROTTLE_COUNTERS]; 459: u32 bcl_throttle; 460: }; 461: 462: /** 463: * struct adreno_firmware - Struct holding fw details 464: * @fwvirt: Buffer which holds the ucode 465: * @size: Size of ucode buffer 466: * @version: Version of ucode 467: * @memdesc: Memory descriptor which holds ucode buffer info 468: */ 469: struct adreno_firmware { 470: unsigned int *fwvirt; 471: size_t size; 472: unsigned int version; 473: struct kgsl_memdesc *memdesc; 474: }; 475: 476: /** 477: * struct adreno_perfcounter_list_node - struct to store perfcounters 478: * allocated by a process on a kgsl fd. 479: * @groupid: groupid of the allocated perfcounter 480: * @countable: countable assigned to the allocated perfcounter 481: * @node: list node for perfcounter_list of a process 482: */ 483: struct adreno_perfcounter_list_node { 484: unsigned int groupid; 485: unsigned int countable; 486: struct list_head node; 487: }; 488: 489: /** 490: * struct adreno_device_private - Adreno private structure per fd 491: * @dev_priv: the kgsl device private structure 492: * @perfcounter_list: list of perfcounters used by the process 493: */ 494: struct adreno_device_private { 495: struct kgsl_device_private dev_priv; 496: struct list_head perfcounter_list; 497: }; MATCH LINES: 696, 699 684: * @ram_cycles_lo_ch1_read: Number of DDR channel 1 Read clock cycles for 685: * the monitor session 686: * @ram_cycles_lo_ch0_write: Number of DDR channel 0 Write clock cycles for 687: * the monitor session 688: * @ram_cycles_lo_ch1_write: Number of DDR channel 0 Write clock cycles for 689: * the monitor session 690: * @starved_ram_lo: Number of cycles VBIF/GBIF is stalled by DDR (Only channel 0 691: * stall cycles in case of GBIF) 692: * @starved_ram_lo_ch1: Number of cycles GBIF is stalled by DDR channel 1 693: * @halt: Atomic variable to check whether the GPU is currently halted 694: * @pending_irq_refcnt: Atomic variable to keep track of running IRQ handlers 695: * @ctx_d_debugfs: Context debugfs node 696: * @profile_buffer: Memdesc holding the drawobj profiling buffer 697: * @profile_index: Index to store the start/stop ticks in the profiling 698: * buffer 699: * @pwrup_reglist: Memdesc holding the power up register list 700: * which is used by CP during preemption and IFPC 701: * @lm_sequence: Pointer to the start of the register write sequence for LM 702: * @lm_size: The dword size of the LM sequence 703: * @lm_limit: limiting value for LM 704: * @lm_threshold_count: register value for counter for lm threshold breakin 705: * @lm_threshold_cross: number of current peaks exceeding threshold 706: * @ifpc_count: Number of times the GPU went into IFPC 707: * @highest_bank_bit: Value of the highest bank bit 708: * @gpmu_throttle_counters - counters for number of throttled clocks 709: * @irq_storm_work: Worker to handle possible interrupt storms 710: * @active_list: List to track active contexts 711: * @active_list_lock: Lock to protect active_list 712: * @gpu_llc_slice: GPU system cache slice descriptor 713: * @gpu_llc_slice_enable: To enable the GPU system cache slice or not 714: * @gpuhtw_llc_slice: GPU pagetables system cache slice descriptor 715: * @gpuhtw_llc_slice_enable: To enable the GPUHTW system cache slice or not 716: * @gpumv_llc_slice: GPU MV buffer system cache slice descriptor 717: * @gpumv_llc_slice_enable: To enable GPUMV buffer system cache slice or not 718: * @zap_loaded: Used to track if zap was successfully loaded or not 719: */ 720: struct adreno_device { 721: struct kgsl_device dev; /* Must be first field in this struct */ 722: unsigned long priv; 723: unsigned int chipid; MATCH LINES: 740 728: size_t gpmu_cmds_size; 729: unsigned int *gpmu_cmds; 730: struct adreno_ringbuffer ringbuffers[KGSL_PRIORITY_MAX_RB_LEVELS]; 731: int num_ringbuffers; 732: struct adreno_ringbuffer *cur_rb; 733: struct adreno_ringbuffer *next_rb; 734: struct adreno_ringbuffer *prev_rb; 735: unsigned long ft_policy; 736: bool long_ib_detect; 737: bool cooperative_reset; 738: struct adreno_profile profile; 739: struct adreno_dispatcher dispatcher; 740: struct kgsl_memdesc *pwron_fixup; 741: unsigned int pwron_fixup_dwords; 742: struct work_struct input_work; 743: struct adreno_busy_data busy_data; 744: unsigned int ram_cycles_lo; 745: unsigned int ram_cycles_lo_ch1_read; 746: unsigned int ram_cycles_lo_ch0_write; 747: unsigned int ram_cycles_lo_ch1_write; 748: unsigned int starved_ram_lo; 749: unsigned int starved_ram_lo_ch1; 750: atomic_t halt; 751: atomic_t pending_irq_refcnt; 752: struct dentry *ctx_d_debugfs; 753: /** @lm_enabled: True if limits management is enabled for this target */ 754: bool lm_enabled; 755: /** @acd_enabled: True if acd is enabled for this target */ 756: bool acd_enabled; 757: /** @hwcg_enabled: True if hardware clock gating is enabled */ 758: bool hwcg_enabled; 759: /** @throttling_enabled: True if LM throttling is enabled on a5xx */ 760: bool throttling_enabled; 761: /** @sptp_pc_enabled: True if SPTP power collapse is enabled on a5xx */ 762: bool sptp_pc_enabled; 763: /** @bcl_enabled: True if BCL is enabled */ 764: bool bcl_enabled; MATCH LINES: 779, 781 767: /** @isense_reg_mapped: True if isense registers are mapped to regmap */ 768: bool isense_reg_mapped; 769: /** @lpac_enabled: True if LPAC is enabled */ 770: bool lpac_enabled; 771: /** @dms_enabled: True if DMS is enabled */ 772: bool dms_enabled; 773: /** @minbw_enabled: True if minbw vote is enabled */ 774: bool minbw_enabled; 775: /** @malu_enabled: True if mALU is enabled */ 776: bool malu_enabled; 777: /** @preempt_override: True if command line param enables preemption */ 778: bool preempt_override; 779: struct kgsl_memdesc *profile_buffer; 780: unsigned int profile_index; 781: struct kgsl_memdesc *pwrup_reglist; 782: uint32_t *lm_sequence; 783: uint32_t lm_size; 784: struct adreno_preemption preempt; 785: struct work_struct gpmu_work; 786: uint32_t lm_leakage; 787: uint32_t lm_limit; 788: uint32_t lm_threshold_count; 789: uint32_t lm_threshold_cross; 790: uint32_t ifpc_count; 791: 792: unsigned int highest_bank_bit; 793: /** @ubwc_mode: Supported UBWC mode */ 794: u32 ubwc_mode; 795: /** @mal: Minimum access length */ 796: u32 mal; 797: unsigned int quirks; 798: 799: #ifdef CONFIG_QCOM_KGSL_CORESIGHT 800: /** @gx_coresight: A coresight instance for GX */ 801: struct adreno_coresight_device gx_coresight; 802: /** @gx_coresight: A coresight instance for CX */ 803: struct adreno_coresight_device cx_coresight; 804: /** @funnel_gfx: A coresight instance for gfx funnel */ 805: struct adreno_funnel_device funnel_gfx; MATCH LINES: 832, 836 820: void *gpu_llc_slice; 821: bool gpu_llc_slice_enable; 822: void *gpuhtw_llc_slice; 823: bool gpuhtw_llc_slice_enable; 824: void *gpumv_llc_slice; 825: bool gpumv_llc_slice_enable; 826: unsigned int zap_loaded; 827: /** @zap_enabled: True when zap-shader is present */ 828: bool zap_enabled; 829: /** 830: * @critpkts: Memory descriptor for 5xx critical packets if applicable 831: */ 832: struct kgsl_memdesc *critpkts; 833: /** 834: * @critpkts: Memory descriptor for 5xx secure critical packets 835: */ 836: struct kgsl_memdesc *critpkts_secure; 837: /** @irq_mask: The current interrupt mask for the GPU device */ 838: u32 irq_mask; 839: /* @dispatch_ops: A pointer to a set of adreno dispatch ops */ 840: const struct adreno_dispatch_ops *dispatch_ops; 841: /** @hwsched: Container for the hardware dispatcher */ 842: struct adreno_hwsched hwsched; 843: /* 844: * @perfcounter: Flag to clear perfcounters across contexts and 845: * controls perfcounter ioctl read 846: */ 847: bool perfcounter; 848: /** @gmu_hub_clk_freq: Gmu hub interface clock frequency */ 849: u64 gmu_hub_clk_freq; 850: /* @patch_reglist: If false power up register list needs to be patched */ 851: bool patch_reglist; 852: /* 853: * @uche_client_pf: uche_client_pf client register configuration 854: * for pf debugging 855: */ 856: u32 uche_client_pf; 857: /** 858: * @bcl_data: bit 0 contains response type for bcl alarms and bits 1:24 controls 859: * throttle level for bcl alarm levels 0-2. If not set, gmu fw sets default throttle levels. 860: */ MATCH LINES: 1957, 1960, 1964 1945: * unsigned long is big enough for our purposes. 1946: */ 1947: return (BITS_PER_LONG > 32 && ADRENO_GPUREV(adreno_dev) >= 500); 1948: } 1949: 1950: static inline void adreno_ringbuffer_set_pagetable(struct kgsl_device *device, 1951: struct adreno_ringbuffer *rb, struct kgsl_pagetable *pt) 1952: { 1953: unsigned long flags; 1954: 1955: spin_lock_irqsave(&rb->preempt_lock, flags); 1956: 1957: kgsl_sharedmem_writel(device->scratch, 1958: SCRATCH_RB_OFFSET(rb->id, current_rb_ptname), pt->name); 1959: 1960: kgsl_sharedmem_writeq(device->scratch, 1961: SCRATCH_RB_OFFSET(rb->id, ttbr0), 1962: kgsl_mmu_pagetable_get_ttbr0(pt)); 1963: 1964: kgsl_sharedmem_writel(device->scratch, 1965: SCRATCH_RB_OFFSET(rb->id, contextidr), 0); 1966: 1967: spin_unlock_irqrestore(&rb->preempt_lock, flags); 1968: } 1969: 1970: static inline u32 counter_delta(struct kgsl_device *device, 1971: unsigned int reg, unsigned int *counter) 1972: { 1973: u32 val, ret = 0; 1974: 1975: if (!reg) 1976: return 0; 1977: 1978: kgsl_regread(device, reg, &val); 1979: 1980: if (*counter) { 1981: if (val >= *counter) 1982: ret = val - *counter; 1983: else 1984: ret = (UINT_MAX - *counter) + val; 1985: } 1986: 1987: *counter = val; 1988: return ret; MATCH LINES: 2106 2094: * 2095: * Return: 0 on success or negative on failure 2096: */ 2097: int adreno_request_firmware(const struct firmware **fw, 2098: const char *name, struct device *device, bool log_error); 2099: 2100: /** 2101: * adreno_get_firwmare - Load firmware into a adreno_firmware struct 2102: * @adreno_dev: An Adreno GPU device handle 2103: * @fwfile: Firmware file to load 2104: * @firmware: A &struct adreno_firmware container for the firmware. 2105: * 2106: * Load the specified firmware file into the memdesc in &struct adreno_firmware 2107: * and get the size and version from the data. 2108: * 2109: * Return: 0 on success or negative on failure 2110: */ 2111: int adreno_get_firmware(struct adreno_device *adreno_dev, 2112: const char *fwfile, struct adreno_firmware *firmware); 2113: /** 2114: * adreno_zap_shader_load - Helper function for loading the zap shader 2115: * adreno_dev: A handle to an Adreno GPU device 2116: * name: Name of the zap shader to load 2117: * 2118: * A target indepedent helper function for loading the zap shader. 2119: * 2120: * Return: 0 on success or negative on failure. 2121: */ 2122: int adreno_zap_shader_load(struct adreno_device *adreno_dev, 2123: const char *name); 2124: 2125: /** 2126: * adreno_irq_callbacks - Helper function to handle IRQ callbacks 2127: * @adreno_dev: Adreno GPU device handle 2128: * @funcs: List of callback functions 2129: * @status: Interrupt status 2130: * MATCH LINES: 2262, 2270, 2274, 2277, 2280, 2281 2250: 2251: /** 2252: * adreno_isidle - return true if the hardware is idle 2253: * @adreno_dev: Adreno GPU device handle 2254: * 2255: * Return: True if the hardware is idle 2256: */ 2257: bool adreno_isidle(struct adreno_device *adreno_dev); 2258: 2259: /** 2260: * adreno_allocate_global - Helper function to allocate a global GPU object 2261: * @device: A GPU device handle 2262: * @memdesc: Pointer to a &struct kgsl_memdesc pointer 2263: * @size: Size of the allocation in bytes 2264: * @padding: Amount of extra adding to add to the VA allocation 2265: * @flags: Control flags for the allocation 2266: * @priv: Internal flags for the allocation 2267: * @name: Name of the allocation (for the debugfs file) 2268: * 2269: * Allocate a global object if it hasn't already been alllocated and put it in 2270: * the pointer pointed to by @memdesc. 2271: * Return: 0 on success or negative on error 2272: */ 2273: static inline int adreno_allocate_global(struct kgsl_device *device, 2274: struct kgsl_memdesc **memdesc, u64 size, u32 padding, u64 flags, 2275: u32 priv, const char *name) 2276: { 2277: if (!IS_ERR_OR_NULL(*memdesc)) 2278: return 0; 2279: 2280: *memdesc = kgsl_allocate_global(device, size, padding, flags, priv, name); 2281: return PTR_ERR_OR_ZERO(*memdesc); 2282: } 2283: 2284: static inline void adreno_set_dispatch_ops(struct adreno_device *adreno_dev, 2285: const struct adreno_dispatch_ops *ops) 2286: { 2287: adreno_dev->dispatch_ops = ops; 2288: } 2289: 2290: #ifdef CONFIG_QCOM_KGSL_FENCE_TRACE 2291: /** 2292: * adreno_fence_trace_array_init - Initialize an always on trace array 2293: * @device: A GPU device handle 2294: * 2295: * Register an always-on trace array to for fence timeout debugging 2296: */ 2297: void adreno_fence_trace_array_init(struct kgsl_device *device); 2298: #else 2299: static inline void adreno_fence_trace_array_init(struct kgsl_device *device) {} 2300: #endif 2301: 2302: /* 2303: * adreno_drawobj_set_constraint - Set a power constraint 2304: * @device: Pointer to a KGSL device structure 2305: * @drawobj: Draw object for which constraint is to be set --- FILE: \adreno_a5xx.c | HITS: 26 --- MATCH LINES: 117, 123, 127, 135, 149, 150, 151, 152, 159, 174 105: adreno_dev->irq_mask = A5XX_INT_MASK; 106: 107: ret = adreno_device_probe(pdev, adreno_dev); 108: if (ret) 109: return ret; 110: 111: a5xx_coresight_init(adreno_dev); 112: 113: return adreno_dispatcher_init(adreno_dev); 114: } 115: 116: static void _do_fixup(const struct adreno_critical_fixup *fixups, int count, 117: uint64_t *gpuaddrs, unsigned int *buffer) 118: { 119: int i; 120: 121: for (i = 0; i < count; i++) { 122: buffer[fixups[i].lo_offset] = 123: lower_32_bits(gpuaddrs[fixups[i].buffer]) | 124: fixups[i].mem_offset; 125: 126: buffer[fixups[i].hi_offset] = 127: upper_32_bits(gpuaddrs[fixups[i].buffer]); 128: } 129: } 130: 131: static int a5xx_critical_packet_construct(struct adreno_device *adreno_dev) 132: { 133: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 134: unsigned int *cmds; 135: uint64_t gpuaddrs[4]; 136: 137: adreno_dev->critpkts = kgsl_allocate_global(device, 138: PAGE_SIZE * 4, 0, 0, 0, "crit_pkts"); 139: if (IS_ERR(adreno_dev->critpkts)) 140: return PTR_ERR(adreno_dev->critpkts); 141: 142: adreno_dev->critpkts_secure = kgsl_allocate_global(device, 143: PAGE_SIZE, 0, KGSL_MEMFLAGS_SECURE, 0, "crit_pkts_secure"); 144: if (IS_ERR(adreno_dev->critpkts_secure)) 145: return PTR_ERR(adreno_dev->critpkts_secure); 146: 147: cmds = adreno_dev->critpkts->hostptr; 148: 149: gpuaddrs[0] = adreno_dev->critpkts_secure->gpuaddr; 150: gpuaddrs[1] = adreno_dev->critpkts->gpuaddr + PAGE_SIZE; 151: gpuaddrs[2] = adreno_dev->critpkts->gpuaddr + (PAGE_SIZE * 2); 152: gpuaddrs[3] = adreno_dev->critpkts->gpuaddr + (PAGE_SIZE * 3); 153: 154: crit_pkts_dwords = ARRAY_SIZE(_a5xx_critical_pkts); 155: 156: memcpy(cmds, _a5xx_critical_pkts, crit_pkts_dwords << 2); 157: 158: _do_fixup(critical_pkt_fixups, ARRAY_SIZE(critical_pkt_fixups), 159: gpuaddrs, cmds); 160: 161: cmds = adreno_dev->critpkts->hostptr + PAGE_SIZE; 162: memcpy(cmds, _a5xx_critical_pkts_mem01, 163: ARRAY_SIZE(_a5xx_critical_pkts_mem01) << 2); 164: 165: cmds = adreno_dev->critpkts->hostptr + (PAGE_SIZE * 2); 166: memcpy(cmds, _a5xx_critical_pkts_mem02, 167: ARRAY_SIZE(_a5xx_critical_pkts_mem02) << 2); 168: 169: cmds = adreno_dev->critpkts->hostptr + (PAGE_SIZE * 3); 170: memcpy(cmds, _a5xx_critical_pkts_mem03, 171: ARRAY_SIZE(_a5xx_critical_pkts_mem03) << 2); 172: 173: _do_fixup(critical_pkt_mem03_fixups, 174: ARRAY_SIZE(critical_pkt_mem03_fixups), gpuaddrs, cmds); 175: 176: critical_packet_constructed = 1; 177: 178: return 0; 179: } 180: 181: static int a5xx_microcode_read(struct adreno_device *adreno_dev); 182: 183: static int a5xx_init(struct adreno_device *adreno_dev) 184: { 185: int ret; 186: 187: ret = a5xx_ringbuffer_init(adreno_dev); 188: if (ret) 189: return ret; 190: 191: ret = a5xx_microcode_read(adreno_dev); 192: if (ret) 193: return ret; 194: 195: if (a5xx_has_gpmu(adreno_dev)) 196: INIT_WORK(&adreno_dev->gpmu_work, a5xx_gpmu_reset); 197: 198: INIT_WORK(&adreno_dev->irq_storm_work, a5xx_irq_storm_worker); MATCH LINES: 1522, 1531, 1533, 1549 1510: } 1511: 1512: /* 1513: * Follow the ME_INIT sequence with a preemption yield to allow the GPU to move 1514: * to a different ringbuffer, if desired 1515: */ 1516: static int _preemption_init( 1517: struct adreno_device *adreno_dev, 1518: struct adreno_ringbuffer *rb, unsigned int *cmds, 1519: struct kgsl_context *context) 1520: { 1521: unsigned int *cmds_orig = cmds; 1522: uint64_t gpuaddr = rb->preemption_desc->gpuaddr; 1523: 1524: /* Turn CP protection OFF */ 1525: cmds += cp_protected_mode(adreno_dev, cmds, 0); 1526: /* 1527: * CP during context switch will save context switch info to 1528: * a5xx_cp_preemption_record pointed by CONTEXT_SWITCH_SAVE_ADDR 1529: */ 1530: *cmds++ = cp_type4_packet(A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_LO, 1); 1531: *cmds++ = lower_32_bits(gpuaddr); 1532: *cmds++ = cp_type4_packet(A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_HI, 1); 1533: *cmds++ = upper_32_bits(gpuaddr); 1534: 1535: /* Turn CP protection ON */ 1536: cmds += cp_protected_mode(adreno_dev, cmds, 1); 1537: 1538: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_GLOBAL, 1); 1539: *cmds++ = 0; 1540: 1541: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_LOCAL, 1); 1542: *cmds++ = 1; 1543: 1544: /* Enable yield in RB only */ 1545: *cmds++ = cp_type7_packet(CP_YIELD_ENABLE, 1); 1546: *cmds++ = 1; 1547: 1548: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1549: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 1550: *cmds++ = 0; 1551: /* generate interrupt on preemption completion */ 1552: *cmds++ = 1; 1553: 1554: return cmds - cmds_orig; 1555: } 1556: 1557: static int a5xx_post_start(struct adreno_device *adreno_dev) 1558: { 1559: int ret; 1560: unsigned int *cmds, *start; 1561: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1562: 1563: if (!adreno_is_a530(adreno_dev) && 1564: !adreno_is_preemption_enabled(adreno_dev)) 1565: return 0; 1566: 1567: cmds = adreno_ringbuffer_allocspace(rb, 42); 1568: if (IS_ERR(cmds)) { 1569: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1570: 1571: dev_err(device->dev, 1572: "error allocating preemtion init cmds\n"); 1573: return PTR_ERR(cmds); MATCH LINES: 1645, 1647, 1649, 1651, 1653, 1655, 1657 1633: } 1634: 1635: /* 1636: * a5xx_microcode_load() - Load microcode 1637: * @adreno_dev: Pointer to adreno device 1638: */ 1639: static int a5xx_microcode_load(struct adreno_device *adreno_dev) 1640: { 1641: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1642: struct adreno_firmware *pm4_fw = ADRENO_FW(adreno_dev, ADRENO_FW_PM4); 1643: struct adreno_firmware *pfp_fw = ADRENO_FW(adreno_dev, ADRENO_FW_PFP); 1644: const struct adreno_a5xx_core *a5xx_core = to_a5xx_core(adreno_dev); 1645: uint64_t gpuaddr; 1646: 1647: gpuaddr = pm4_fw->memdesc->gpuaddr; 1648: kgsl_regwrite(device, A5XX_CP_PM4_INSTR_BASE_LO, 1649: lower_32_bits(gpuaddr)); 1650: kgsl_regwrite(device, A5XX_CP_PM4_INSTR_BASE_HI, 1651: upper_32_bits(gpuaddr)); 1652: 1653: gpuaddr = pfp_fw->memdesc->gpuaddr; 1654: kgsl_regwrite(device, A5XX_CP_PFP_INSTR_BASE_LO, 1655: lower_32_bits(gpuaddr)); 1656: kgsl_regwrite(device, A5XX_CP_PFP_INSTR_BASE_HI, 1657: upper_32_bits(gpuaddr)); 1658: 1659: /* 1660: * Do not invoke to load zap shader if MMU does 1661: * not support secure mode. 1662: */ 1663: if (!device->mmu.secured) 1664: return 0; 1665: 1666: if (adreno_dev->zap_loaded && !(ADRENO_FEATURE(adreno_dev, 1667: ADRENO_CPZ_RETENTION))) 1668: return a5xx_zap_shader_resume(device); 1669: 1670: return adreno_zap_shader_load(adreno_dev, a5xx_core->zap_name); 1671: } 1672: 1673: static int _me_init_ucode_workarounds(struct adreno_device *adreno_dev) 1674: { 1675: switch (ADRENO_GPUREV(adreno_dev)) { 1676: case ADRENO_REV_A510: 1677: return 0x00000001; /* Ucode workaround for token end syncs */ 1678: case ADRENO_REV_A505: 1679: case ADRENO_REV_A506: 1680: case ADRENO_REV_A530: 1681: /* MATCH LINES: 1733 1721: { 1722: unsigned int *cmds; 1723: int ret; 1724: 1725: if (!critical_packet_constructed) 1726: return 0; 1727: 1728: cmds = adreno_ringbuffer_allocspace(rb, 4); 1729: if (IS_ERR(cmds)) 1730: return PTR_ERR(cmds); 1731: 1732: *cmds++ = cp_mem_packet(adreno_dev, CP_INDIRECT_BUFFER_PFE, 2, 1); 1733: cmds += cp_gpuaddr(adreno_dev, cmds, adreno_dev->critpkts->gpuaddr); 1734: *cmds++ = crit_pkts_dwords; 1735: 1736: ret = a5xx_ringbuffer_submit(rb, NULL, true); 1737: if (!ret) { 1738: ret = adreno_spin_idle(adreno_dev, 20); 1739: if (ret) 1740: a5xx_spin_idle_debug(adreno_dev, 1741: "Critical packet submission failed to idle\n"); 1742: } 1743: 1744: return ret; 1745: } 1746: 1747: /* 1748: * a5xx_send_me_init() - Initialize ringbuffer 1749: * @adreno_dev: Pointer to adreno device 1750: * @rb: Pointer to the ringbuffer of device 1751: * 1752: * Submit commands for ME initialization, 1753: */ 1754: static int a5xx_send_me_init(struct adreno_device *adreno_dev, 1755: struct adreno_ringbuffer *rb) 1756: { 1757: unsigned int *cmds; MATCH LINES: 1818, 1844, 1846 1806: */ 1807: static int a5xx_rb_start(struct adreno_device *adreno_dev) 1808: { 1809: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1810: struct adreno_ringbuffer *rb; 1811: uint64_t addr; 1812: unsigned int *cmds; 1813: int ret, i; 1814: 1815: /* Clear all the ringbuffers */ 1816: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1817: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 1818: kgsl_sharedmem_writel(device->scratch, 1819: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1820: 1821: rb->wptr = 0; 1822: rb->_wptr = 0; 1823: rb->wptr_preempt_end = ~0; 1824: } 1825: 1826: /* Set up the current ringbuffer */ 1827: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 1828: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 1829: 1830: kgsl_regwrite(device, A5XX_CP_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1831: kgsl_regwrite(device, A5XX_CP_RB_RPTR_ADDR_HI, upper_32_bits(addr)); 1832: 1833: /* 1834: * The size of the ringbuffer in the hardware is the log2 1835: * representation of the size in quadwords (sizedwords / 2). 1836: * Also disable the host RPTR shadow register as it might be unreliable 1837: * in certain circumstances. 1838: */ 1839: 1840: kgsl_regwrite(device, A5XX_CP_RB_CNTL, 1841: A5XX_CP_RB_CNTL_DEFAULT); 1842: 1843: kgsl_regwrite(device, A5XX_CP_RB_BASE, 1844: lower_32_bits(rb->buffer_desc->gpuaddr)); 1845: kgsl_regwrite(device, A5XX_CP_RB_BASE_HI, 1846: upper_32_bits(rb->buffer_desc->gpuaddr)); 1847: 1848: ret = a5xx_microcode_load(adreno_dev); 1849: if (ret) 1850: return ret; 1851: 1852: /* clear ME_HALT to start micro engine */ 1853: 1854: kgsl_regwrite(device, A5XX_CP_ME_CNTL, 0); 1855: 1856: ret = a5xx_send_me_init(adreno_dev, rb); 1857: if (ret) 1858: return ret; 1859: 1860: /* Run the critical packets if we need to */ 1861: if (ADRENO_QUIRK(adreno_dev, ADRENO_QUIRK_CRITICAL_PACKETS)) { 1862: ret = a5xx_critical_packet_submit(adreno_dev, rb); 1863: if (ret) 1864: return ret; 1865: } 1866: 1867: /* 1868: * Try to execute the zap shader if it exists, otherwise just try 1869: * directly writing to the control register 1870: */ MATCH LINES: 2104 2092: } 2093: 2094: static void a5xx_cp_callback(struct adreno_device *adreno_dev, int bit) 2095: { 2096: struct kgsl_device *device = &adreno_dev->dev; 2097: unsigned int cur; 2098: static unsigned int count; 2099: static unsigned int prev; 2100: 2101: if (test_bit(ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED, &adreno_dev->priv)) 2102: return; 2103: 2104: kgsl_sharedmem_readl(device->memstore, &cur, 2105: KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, 2106: ref_wait_ts)); 2107: 2108: /* 2109: * prev holds a previously read value 2110: * from memory. It should be changed by the GPU with every 2111: * interrupt. If the value we know about and the value we just 2112: * read are the same, then we are likely in a storm. 2113: * If this happens twice, disable the interrupt in the mask 2114: * so the dispatcher can take care of the issue. It is then 2115: * up to the dispatcher to re-enable the mask once all work 2116: * is done and the storm has ended. 2117: */ 2118: if (prev == cur) { 2119: count++; 2120: if (count == 2) { 2121: /* disable interrupt from the mask */ 2122: set_bit(ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED, 2123: &adreno_dev->priv); 2124: 2125: adreno_dev->irq_mask &= 2126: ~BIT(A5XX_INT_CP_CACHE_FLUSH_TS); 2127: 2128: kgsl_regwrite(device, A5XX_RBBM_INT_0_MASK, --- FILE: \adreno_a5xx_preempt.c | HITS: 36 --- MATCH LINES: 218, 220, 223, 230, 232, 237, 239 206: 207: /* Turn off the dispatcher timer */ 208: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 209: 210: /* 211: * This is the most critical section - we need to take care not to race 212: * until we have programmed the CP for the switch 213: */ 214: 215: spin_lock_irqsave(&next->preempt_lock, flags); 216: 217: /* Get the pagetable from the pagetable info. */ 218: kgsl_sharedmem_readq(device->scratch, &ttbr0, 219: SCRATCH_RB_OFFSET(next->id, ttbr0)); 220: kgsl_sharedmem_readl(device->scratch, &contextidr, 221: SCRATCH_RB_OFFSET(next->id, contextidr)); 222: 223: kgsl_sharedmem_writel(next->preemption_desc, 224: PREEMPT_RECORD(wptr), next->wptr); 225: 226: spin_unlock_irqrestore(&next->preempt_lock, flags); 227: 228: /* And write it to the smmu info */ 229: if (kgsl_mmu_is_perprocess(&device->mmu)) { 230: kgsl_sharedmem_writeq(iommu->smmu_info, 231: PREEMPT_SMMU_RECORD(ttbr0), ttbr0); 232: kgsl_sharedmem_writel(iommu->smmu_info, 233: PREEMPT_SMMU_RECORD(context_idr), contextidr); 234: } 235: 236: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_LO, 237: lower_32_bits(next->preemption_desc->gpuaddr)); 238: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_HI, 239: upper_32_bits(next->preemption_desc->gpuaddr)); 240: 241: adreno_dev->next_rb = next; 242: 243: /* Start the timer to detect a stuck preemption */ 244: mod_timer(&adreno_dev->preempt.timer, 245: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 246: 247: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 248: 1, 0); 249: 250: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 251: 252: /* Trigger the preemption */ 253: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_CNTL, 1); 254: } 255: 256: void a5xx_preempt_callback(struct adreno_device *adreno_dev, int bit) 257: { 258: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 259: unsigned int status; 260: 261: if (!adreno_move_preempt_state(adreno_dev, 262: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING)) 263: return; MATCH LINES: 325 313: _a5xx_preemption_done(adreno_dev); 314: 315: a5xx_preemption_trigger(adreno_dev); 316: 317: kgsl_mutex_unlock(&device->mutex); 318: } 319: 320: u32 a5xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 321: struct adreno_ringbuffer *rb, 322: struct adreno_context *drawctxt, u32 *cmds) 323: { 324: unsigned int *cmds_orig = cmds; 325: uint64_t gpuaddr = rb->preemption_desc->gpuaddr; 326: unsigned int preempt_style = 0; 327: 328: if (!adreno_is_preemption_enabled(adreno_dev)) 329: return 0; 330: 331: if (drawctxt) { 332: /* 333: * Preemption from secure to unsecure needs Zap shader to be 334: * run to clear all secure content. CP does not know during 335: * preemption if it is switching between secure and unsecure 336: * contexts so restrict Secure contexts to be preempted at 337: * ringbuffer level. 338: */ 339: if (drawctxt->base.flags & KGSL_CONTEXT_SECURE) 340: preempt_style = KGSL_CONTEXT_PREEMPT_STYLE_RINGBUFFER; 341: else 342: preempt_style = FIELD_GET(KGSL_CONTEXT_PREEMPT_STYLE_MASK, 343: drawctxt->base.flags); 344: } 345: 346: /* 347: * CP_PREEMPT_ENABLE_GLOBAL(global preemption) can only be set by KMD 348: * in ringbuffer. 349: * 1) set global preemption to 0x0 to disable global preemption. MATCH LINES: 369, 371, 405, 430, 432, 436, 438, 442, 445, 451, 453, 455, 472, 477, 479, 481, 483, 485, 487, 489, 492, 493, 494, 516, 527, 529, 538, 541 357: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_GLOBAL, 1); 358: *cmds++ = ((preempt_style == KGSL_CONTEXT_PREEMPT_STYLE_FINEGRAIN) 359: ? 2 : 0); 360: 361: /* Turn CP protection OFF */ 362: cmds += cp_protected_mode(adreno_dev, cmds, 0); 363: 364: /* 365: * CP during context switch will save context switch info to 366: * a5xx_cp_preemption_record pointed by CONTEXT_SWITCH_SAVE_ADDR 367: */ 368: *cmds++ = cp_type4_packet(A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_LO, 1); 369: *cmds++ = lower_32_bits(gpuaddr); 370: *cmds++ = cp_type4_packet(A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_HI, 1); 371: *cmds++ = upper_32_bits(gpuaddr); 372: 373: /* Turn CP protection ON */ 374: cmds += cp_protected_mode(adreno_dev, cmds, 1); 375: 376: /* 377: * Enable local preemption for finegrain preemption in case of 378: * a misbehaving IB 379: */ 380: if (preempt_style == KGSL_CONTEXT_PREEMPT_STYLE_FINEGRAIN) { 381: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_LOCAL, 1); 382: *cmds++ = 1; 383: } else { 384: *cmds++ = cp_type7_packet(CP_PREEMPT_ENABLE_LOCAL, 1); 385: *cmds++ = 0; 386: } 387: 388: /* Enable CP_CONTEXT_SWITCH_YIELD packets in the IB2s */ 389: *cmds++ = cp_type7_packet(CP_YIELD_ENABLE, 1); 390: *cmds++ = 2; 391: 392: return (unsigned int) (cmds - cmds_orig); 393: } 394: 395: unsigned int a5xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 396: unsigned int *cmds) 397: { 398: int dwords = 0; 399: 400: if (!adreno_is_preemption_enabled(adreno_dev)) 401: return 0; 402: 403: cmds[dwords++] = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 404: /* Write NULL to the address to skip the data write */ 405: dwords += cp_gpuaddr(adreno_dev, &cmds[dwords], 0x0); 406: cmds[dwords++] = 1; 407: /* generate interrupt on preemption completion */ 408: cmds[dwords++] = 1; 409: 410: return dwords; 411: } 412: 413: void a5xx_preemption_start(struct adreno_device *adreno_dev) 414: { 415: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 416: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 417: struct adreno_ringbuffer *rb; 418: unsigned int i; 419: 420: if (!adreno_is_preemption_enabled(adreno_dev)) 421: return; 422: 423: /* Force the state to be clear */ 424: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 425: 426: /* Only set up smmu info when per-process pagetables are enabled */ 427: 428: if (kgsl_mmu_is_perprocess(&device->mmu)) { 429: /* smmu_info is allocated and mapped in a5xx_preemption_iommu_init */ 430: kgsl_sharedmem_writel(iommu->smmu_info, 431: PREEMPT_SMMU_RECORD(magic), A5XX_CP_SMMU_INFO_MAGIC_REF); 432: kgsl_sharedmem_writeq(iommu->smmu_info, 433: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 434: 435: /* The CP doesn't use the asid record, so poison it */ 436: kgsl_sharedmem_writel(iommu->smmu_info, 437: PREEMPT_SMMU_RECORD(asid), 0xDECAFBAD); 438: kgsl_sharedmem_writel(iommu->smmu_info, 439: PREEMPT_SMMU_RECORD(context_idr), 0); 440: 441: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 442: lower_32_bits(iommu->smmu_info->gpuaddr)); 443: 444: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 445: upper_32_bits(iommu->smmu_info->gpuaddr)); 446: } 447: 448: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 449: /* 450: * preemption_desc is allocated and mapped at init time, 451: * so no need to check sharedmem_writel return value 452: */ 453: kgsl_sharedmem_writel(rb->preemption_desc, 454: PREEMPT_RECORD(rptr), 0); 455: kgsl_sharedmem_writel(rb->preemption_desc, 456: PREEMPT_RECORD(wptr), 0); 457: 458: adreno_ringbuffer_set_pagetable(device, rb, 459: device->mmu.defaultpagetable); 460: } 461: 462: } 463: 464: static int a5xx_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 465: struct adreno_ringbuffer *rb, uint64_t counteraddr) 466: { 467: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 468: 469: if (IS_ERR_OR_NULL(rb->preemption_desc)) 470: rb->preemption_desc = kgsl_allocate_global(device, 471: A5XX_CP_CTXRECORD_SIZE_IN_BYTES, SZ_16K, 0, 472: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 473: 474: if (IS_ERR(rb->preemption_desc)) 475: return PTR_ERR(rb->preemption_desc); 476: 477: kgsl_sharedmem_writel(rb->preemption_desc, 478: PREEMPT_RECORD(magic), A5XX_CP_CTXRECORD_MAGIC_REF); 479: kgsl_sharedmem_writel(rb->preemption_desc, 480: PREEMPT_RECORD(info), 0); 481: kgsl_sharedmem_writel(rb->preemption_desc, 482: PREEMPT_RECORD(data), 0); 483: kgsl_sharedmem_writel(rb->preemption_desc, 484: PREEMPT_RECORD(cntl), A5XX_CP_RB_CNTL_DEFAULT); 485: kgsl_sharedmem_writel(rb->preemption_desc, 486: PREEMPT_RECORD(rptr), 0); 487: kgsl_sharedmem_writel(rb->preemption_desc, 488: PREEMPT_RECORD(wptr), 0); 489: kgsl_sharedmem_writeq(rb->preemption_desc, 490: PREEMPT_RECORD(rptr_addr), SCRATCH_RB_GPU_ADDR(device, 491: rb->id, rptr)); 492: kgsl_sharedmem_writeq(rb->preemption_desc, 493: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 494: kgsl_sharedmem_writeq(rb->preemption_desc, 495: PREEMPT_RECORD(counter), counteraddr); 496: 497: return 0; 498: } 499: 500: int a5xx_preemption_init(struct adreno_device *adreno_dev) 501: { 502: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 503: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 504: struct adreno_preemption *preempt = &adreno_dev->preempt; 505: struct adreno_ringbuffer *rb; 506: int ret; 507: unsigned int i; 508: uint64_t addr; 509: 510: /* We are dependent on IOMMU to make preemption go on the CP side */ 511: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) 512: return -ENODEV; 513: 514: INIT_WORK(&preempt->work, _a5xx_preemption_worker); 515: 516: /* Allocate mem for storing preemption counters */ 517: if (IS_ERR_OR_NULL(preempt->scratch)) 518: preempt->scratch = kgsl_allocate_global(device, 519: adreno_dev->num_ringbuffers * 520: A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE, 0, 0, 0, 521: "preemption_counters"); 522: 523: ret = PTR_ERR_OR_ZERO(preempt->scratch); 524: if (ret) 525: return ret; 526: 527: addr = preempt->scratch->gpuaddr; 528: 529: /* Allocate mem for storing preemption switch record */ 530: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 531: ret = a5xx_preemption_ringbuffer_init(adreno_dev, rb, addr); 532: if (ret) 533: return ret; 534: 535: addr += A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE; 536: } 537: 538: /* Allocate mem for storing preemption smmu record */ 539: if (kgsl_mmu_is_perprocess(&device->mmu) && IS_ERR_OR_NULL(iommu->smmu_info)) 540: iommu->smmu_info = kgsl_allocate_global(device, PAGE_SIZE, 0, 541: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 542: "smmu_info"); 543: 544: if (IS_ERR(iommu->smmu_info)) 545: return PTR_ERR(iommu->smmu_info); 546: 547: set_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 548: return 0; 549: } --- FILE: \adreno_a5xx_ringbuffer.c | HITS: 21 --- MATCH LINES: 104 92: spin_unlock_irqrestore(&rb->preempt_lock, flags); 93: 94: return 0; 95: } 96: 97: int a5xx_ringbuffer_init(struct adreno_device *adreno_dev) 98: { 99: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 100: int i; 101: 102: if (IS_ERR_OR_NULL(device->scratch)) 103: device->scratch = kgsl_allocate_global(device, PAGE_SIZE, 104: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED, 105: "scratch"); 106: 107: if (IS_ERR(device->scratch)) 108: return PTR_ERR(device->scratch); 109: 110: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]); 111: 112: if (!adreno_preemption_feature_set(adreno_dev)) { 113: adreno_dev->num_ringbuffers = 1; 114: return adreno_ringbuffer_setup(adreno_dev, 115: &adreno_dev->ringbuffers[0], 0); 116: } 117: 118: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers); 119: 120: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 121: int ret; 122: 123: ret = adreno_ringbuffer_setup(adreno_dev, 124: &adreno_dev->ringbuffers[i], i); 125: if (ret) 126: return ret; 127: } 128: MATCH LINES: 145, 171, 174, 176, 177, 214, 217, 219, 220 133: 134: #define A5XX_SUBMIT_MAX 64 135: 136: int a5xx_ringbuffer_addcmds(struct adreno_device *adreno_dev, 137: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 138: u32 flags, u32 *in, u32 dwords, u32 timestamp, 139: struct adreno_submit_time *time) 140: { 141: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 142: static u32 sequence; 143: u32 size = A5XX_SUBMIT_MAX + dwords; 144: u32 *cmds, index = 0; 145: u64 profile_gpuaddr; 146: u32 profile_dwords; 147: 148: if (adreno_drawctxt_detached(drawctxt)) 149: return -ENOENT; 150: 151: if (adreno_gpu_fault(adreno_dev) != 0) 152: return -EPROTO; 153: 154: rb->timestamp++; 155: 156: if (drawctxt) 157: drawctxt->internal_timestamp = rb->timestamp; 158: 159: cmds = adreno_ringbuffer_allocspace(rb, size); 160: if (IS_ERR(cmds)) 161: return PTR_ERR(cmds); 162: 163: /* Identify the start of a command */ 164: cmds[index++] = cp_type7_packet(CP_NOP, 1); 165: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 166: 167: /* 14 dwords */ 168: index += a5xx_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 169: &cmds[index]); 170: 171: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 172: drawctxt, &profile_dwords); 173: 174: if (profile_gpuaddr) { 175: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 176: cmds[index++] = lower_32_bits(profile_gpuaddr); 177: cmds[index++] = upper_32_bits(profile_gpuaddr); 178: cmds[index++] = profile_dwords; 179: } 180: 181: if (drawctxt) { 182: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 183: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 184: drawctxt)); 185: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 186: drawctxt)); 187: cmds[index++] = timestamp; 188: } 189: 190: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 191: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 192: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); 193: cmds[index++] = rb->timestamp; 194: 195: if (IS_SECURE(flags)) { 196: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 197: cmds[index++] = 1; 198: } 199: 200: if (IS_NOTPROTECTED(flags)) { 201: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1); 202: cmds[index++] = 0; 203: } 204: 205: memcpy(&cmds[index], in, dwords << 2); 206: index += dwords; 207: 208: if (IS_NOTPROTECTED(flags)) { 209: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1); 210: cmds[index++] = 1; 211: } 212: 213: /* 4 dwords */ 214: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev, 215: drawctxt, &profile_dwords); 216: 217: if (profile_gpuaddr) { 218: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 219: cmds[index++] = lower_32_bits(profile_gpuaddr); 220: cmds[index++] = upper_32_bits(profile_gpuaddr); 221: cmds[index++] = profile_dwords; 222: } 223: 224: if (!adreno_is_a510(adreno_dev) && 225: test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, 226: &device->mmu.pfpolicy)) 227: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0); 228: 229: /* 230: * Do a unique memory write from the GPU to assist in early detection of 231: * interrupt storms 232: */ 233: 234: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 235: cmds[index++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 236: KGSL_MEMSTORE_GLOBAL, ref_wait_ts)); 237: cmds[index++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 238: KGSL_MEMSTORE_GLOBAL, ref_wait_ts)); 239: cmds[index++] = ++sequence; 240: 241: /* 242: * If this is an internal command, just write the ringbuffer timestamp, 243: * otherwise, write both 244: */ MATCH LINES: 288, 297, 298, 312, 319, 321, 324, 325 276: index += a5xx_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 277: 278: /* Adjust the thing for the number of bytes we actually wrote */ 279: rb->_wptr -= (size - index); 280: 281: a5xx_ringbuffer_submit(rb, time, 282: !adreno_is_preemption_enabled(adreno_dev)); 283: 284: return 0; 285: } 286: 287: static u32 a5xx_get_alwayson_counter(struct adreno_device *adreno_dev, 288: u32 *cmds, u64 gpuaddr) 289: { 290: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 291: cmds[1] = A5XX_RBBM_ALWAYSON_COUNTER_LO; 292: 293: /* On some targets the upper 32 bits are not reliable */ 294: if (ADRENO_GPUREV(adreno_dev) > ADRENO_REV_A530) 295: cmds[1] |= (1 << 30) | (2 << 18); 296: 297: cmds[2] = lower_32_bits(gpuaddr); 298: cmds[3] = upper_32_bits(gpuaddr); 299: 300: return 4; 301: } 302: 303: /* This is the maximum possible size for 64 bit targets */ 304: #define PROFILE_IB_DWORDS 4 305: #define PROFILE_IB_SLOTS (PAGE_SIZE / (PROFILE_IB_DWORDS << 2)) 306: 307: static u64 a5xx_get_user_profiling_ib(struct adreno_device *adreno_dev, 308: struct adreno_ringbuffer *rb, struct kgsl_drawobj_cmd *cmdobj, 309: u32 target_offset, u32 *cmds) 310: { 311: u32 offset, *ib, dwords; 312: u64 gpuaddr; 313: 314: if (IS_ERR(rb->profile_desc)) 315: return 0; 316: 317: offset = rb->profile_index * (PROFILE_IB_DWORDS << 2); 318: ib = rb->profile_desc->hostptr + offset; 319: gpuaddr = rb->profile_desc->gpuaddr + offset; 320: dwords = a5xx_get_alwayson_counter(adreno_dev, ib, 321: cmdobj->profiling_buffer_gpuaddr + target_offset); 322: 323: cmds[0] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 324: cmds[1] = lower_32_bits(gpuaddr); 325: cmds[2] = upper_32_bits(gpuaddr); 326: cmds[3] = dwords; 327: 328: rb->profile_index = (rb->profile_index + 1) % PROFILE_IB_SLOTS; 329: 330: return 4; 331: } 332: 333: static int a5xx_rb_context_switch(struct adreno_device *adreno_dev, 334: struct adreno_ringbuffer *rb, 335: struct adreno_context *drawctxt) 336: { 337: struct kgsl_pagetable *pagetable = 338: adreno_drawctxt_get_pagetable(drawctxt); 339: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 340: int count = 0; 341: u32 cmds[32]; 342: 343: if (adreno_drawctxt_get_pagetable(rb->drawctxt_active) != pagetable) 344: count += a5xx_rb_pagetable_switch(device, drawctxt, 345: rb, pagetable, cmds); 346: 347: cmds[count++] = cp_type7_packet(CP_NOP, 1); 348: cmds[count++] = CONTEXT_TO_MEM_IDENTIFIER; 349: MATCH LINES: 406 394: rb->drawctxt_active = drawctxt; 395: return 0; 396: } 397: 398: 399: #define A5XX_USER_PROFILE_IB(dev, rb, cmdobj, cmds, field) \ 400: a5xx_get_user_profiling_ib((dev), (rb), (cmdobj), \ 401: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 402: (cmds)) 403: 404: #define A5XX_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 405: a5xx_get_alwayson_counter((dev), (cmds), \ 406: (dev)->profile_buffer->gpuaddr + \ 407: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 408: field)) 409: 410: #define A5XX_COMMAND_DWORDS 32 411: 412: int a5xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 413: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 414: struct adreno_submit_time *time) 415: { 416: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 417: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 418: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 419: struct adreno_ringbuffer *rb = drawctxt->rb; 420: int ret = 0, numibs = 0, index = 0; 421: u32 *cmds; 422: 423: /* Count the number of IBs (if we are not skipping) */ 424: if (!IS_SKIP(flags)) { 425: struct list_head *tmp; 426: 427: list_for_each(tmp, &cmdobj->cmdlist) 428: numibs++; 429: } 430: MATCH LINES: 461, 462 449: 450: if (numibs) { 451: struct kgsl_memobj_node *ib; 452: 453: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 454: if (ib->priv & MEMOBJ_SKIP || 455: (ib->flags & KGSL_CMDLIST_CTXTSWITCH_PREAMBLE 456: && !IS_PREAMBLE(flags))) 457: cmds[index++] = cp_type7_packet(CP_NOP, 4); 458: 459: cmds[index++] = 460: cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 461: cmds[index++] = lower_32_bits(ib->gpuaddr); 462: cmds[index++] = upper_32_bits(ib->gpuaddr); 463: 464: /* Double check that IB_PRIV is never set */ 465: cmds[index++] = (ib->size >> 2) & 0xfffff; 466: } 467: } 468: 469: /* 470: * SRM -- set render mode (ex binning, direct render etc) 471: * SRM is set by UMD usually at start of IB to tell CP the type of 472: * preemption. 473: * KMD needs to set SRM to NULL to indicate CP that rendering is 474: * done by IB. 475: */ 476: cmds[index++] = cp_type7_packet(CP_SET_RENDER_MODE, 5); 477: cmds[index++] = 0; 478: cmds[index++] = 0; 479: cmds[index++] = 0; 480: cmds[index++] = 0; 481: cmds[index++] = 0; 482: 483: cmds[index++] = cp_type7_packet(CP_YIELD_ENABLE, 1); 484: cmds[index++] = 1; 485: 486: /* 4 dwords */ --- FILE: \adreno_a5xx_snapshot.c | HITS: 12 --- MATCH LINES: 141, 164 129: unsigned int *data = (unsigned int *)(buf + sizeof(*header)); 130: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_PM4); 131: size_t size = fw->size; 132: 133: if (remain < DEBUG_SECTION_SZ(size)) { 134: SNAPSHOT_ERR_NOMEM(device, "CP PM4 RAM DEBUG"); 135: return 0; 136: } 137: 138: header->type = SNAPSHOT_DEBUG_CP_PM4_RAM; 139: header->size = size; 140: 141: memcpy(data, fw->memdesc->hostptr, size * sizeof(uint32_t)); 142: 143: return DEBUG_SECTION_SZ(size); 144: } 145: 146: /* a5xx_snapshot_cp_pfp() - Dump the PFP data on snapshot */ 147: static size_t a5xx_snapshot_cp_pfp(struct kgsl_device *device, u8 *buf, 148: size_t remain, void *priv) 149: { 150: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 151: struct kgsl_snapshot_debug *header = (struct kgsl_snapshot_debug *)buf; 152: unsigned int *data = (unsigned int *)(buf + sizeof(*header)); 153: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_PFP); 154: int size = fw->size; 155: 156: if (remain < DEBUG_SECTION_SZ(size)) { 157: SNAPSHOT_ERR_NOMEM(device, "CP PFP RAM DEBUG"); 158: return 0; 159: } 160: 161: header->type = SNAPSHOT_DEBUG_CP_PFP_RAM; 162: header->size = size; 163: 164: memcpy(data, fw->memdesc->hostptr, size * sizeof(uint32_t)); 165: 166: return DEBUG_SECTION_SZ(size); 167: } 168: 169: /* a5xx_rbbm_debug_bus_read() - Read data from trace bus */ 170: static void a5xx_rbbm_debug_bus_read(struct kgsl_device *device, 171: unsigned int block_id, unsigned int index, unsigned int *val) 172: { 173: unsigned int reg; 174: 175: reg = (block_id << A5XX_RBBM_CFG_DBGBUS_SEL_PING_BLK_SEL_SHIFT) | 176: (index << A5XX_RBBM_CFG_DBGBUS_SEL_PING_INDEX_SHIFT); 177: kgsl_regwrite(device, A5XX_RBBM_CFG_DBGBUS_SEL_A, reg); 178: kgsl_regwrite(device, A5XX_RBBM_CFG_DBGBUS_SEL_B, reg); 179: kgsl_regwrite(device, A5XX_RBBM_CFG_DBGBUS_SEL_C, reg); 180: kgsl_regwrite(device, A5XX_RBBM_CFG_DBGBUS_SEL_D, reg); 181: 182: kgsl_regread(device, A5XX_RBBM_CFG_DBGBUS_TRACE_BUF2, val); 183: val++; 184: kgsl_regread(device, A5XX_RBBM_CFG_DBGBUS_TRACE_BUF1, val); 185: 186: } 187: 188: /* a5xx_snapshot_vbif_debugbus() - Dump the VBIF debug data */ MATCH LINES: 593, 594 581: {A5XX_SP_S_3D_INSTR_DIRTY, 0x1}, 582: {A5XX_SP_S_3D_CB_BASE_DIRTY, 0x5}, 583: {A5XX_SP_S_3D_UAV_BASE_DIRTY, 0x2}, 584: {A5XX_SP_S_CS_INSTR_DIRTY, 0x1}, 585: {A5XX_SP_S_CS_CB_BASE_DIRTY, 0x1}, 586: {A5XX_SP_S_CS_UAV_BASE_DIRTY, 0x2}, 587: {A5XX_HLSQ_ICB, 0x200}, 588: {A5XX_HLSQ_ICB_CB_BASE_DIRTY, 0x4}, 589: {A5XX_SP_POWER_RESTORE_RAM, 0x140}, 590: {A5XX_TP_POWER_RESTORE_RAM, 0x40}, 591: }; 592: 593: static struct kgsl_memdesc *capturescript; 594: static struct kgsl_memdesc *registers; 595: static bool crash_dump_valid; 596: 597: static size_t a5xx_snapshot_shader_memory(struct kgsl_device *device, 598: u8 *buf, size_t remain, void *priv) 599: { 600: struct kgsl_snapshot_shader *header = 601: (struct kgsl_snapshot_shader *) buf; 602: struct a5xx_shader_block_info *info = 603: (struct a5xx_shader_block_info *) priv; 604: struct a5xx_shader_block *block = info->block; 605: unsigned int *data = (unsigned int *) (buf + sizeof(*header)); 606: 607: if (remain < SHADER_SECTION_SZ(block->sz)) { 608: SNAPSHOT_ERR_NOMEM(device, "SHADER MEMORY"); 609: return 0; 610: } 611: 612: header->type = block->statetype; 613: header->index = info->bank; 614: header->size = block->sz; 615: 616: memcpy(data, registers->hostptr + info->offset, 617: block->sz * sizeof(unsigned int)); 618: MATCH LINES: 745, 747 733: 734: if (IS_ERR_OR_NULL(capturescript) || IS_ERR_OR_NULL(registers)) 735: return; 736: 737: /* IF the SMMU is stalled we cannot do a crash dump */ 738: if (adreno_smmu_is_stalled(ADRENO_DEVICE(device))) 739: return; 740: 741: /* Turn on APRIV so we can access the buffers */ 742: kgsl_regwrite(device, A5XX_CP_CNTL, 1); 743: 744: kgsl_regwrite(device, A5XX_CP_CRASH_SCRIPT_BASE_LO, 745: lower_32_bits(capturescript->gpuaddr)); 746: kgsl_regwrite(device, A5XX_CP_CRASH_SCRIPT_BASE_HI, 747: upper_32_bits(capturescript->gpuaddr)); 748: kgsl_regwrite(device, A5XX_CP_CRASH_DUMP_CNTL, 1); 749: 750: wait_time = jiffies + msecs_to_jiffies(CP_CRASH_DUMPER_TIMEOUT); 751: while (!time_after(jiffies, wait_time)) { 752: kgsl_regread(device, A5XX_CP_CRASH_DUMP_CNTL, ®); 753: if (reg & 0x4) 754: break; 755: cpu_relax(); 756: } 757: 758: kgsl_regwrite(device, A5XX_CP_CNTL, 0); 759: 760: if (!(reg & 0x4)) { 761: dev_err(device->dev, "Crash dump timed out: 0x%X\n", reg); 762: return; 763: } 764: 765: crash_dump_valid = true; 766: } 767: 768: static int get_hlsq_registers(struct kgsl_device *device, 769: const struct a5xx_hlsq_sp_tp_regs *regs, unsigned int *data) 770: { 771: unsigned int i; MATCH LINES: 1029, 1056 1017: int qwords = 0; 1018: unsigned int j; 1019: 1020: /* Capture each bank in the block */ 1021: for (j = 0; j < A5XX_NUM_SHADER_BANKS; j++) { 1022: /* Program the aperture */ 1023: ptr[qwords++] = 1024: (block->statetype << A5XX_SHADER_STATETYPE_SHIFT) | j; 1025: ptr[qwords++] = (((uint64_t) A5XX_HLSQ_DBG_READ_SEL << 44)) | 1026: (1 << 21) | 1; 1027: 1028: /* Read all the data in one chunk */ 1029: ptr[qwords++] = registers->gpuaddr + *offset; 1030: ptr[qwords++] = 1031: (((uint64_t) A5XX_HLSQ_DBG_AHB_READ_APERTURE << 44)) | 1032: block->sz; 1033: 1034: /* Remember the offset of the first bank for easy access */ 1035: if (j == 0) 1036: block->offset = *offset; 1037: 1038: *offset += block->sz * sizeof(unsigned int); 1039: } 1040: 1041: return qwords; 1042: } 1043: 1044: static int _a5xx_crashdump_init_hlsq(struct a5xx_hlsq_sp_tp_regs *regs, 1045: uint64_t *ptr, uint64_t *offset) 1046: { 1047: int qwords = 0; 1048: 1049: /* Program the aperture */ 1050: ptr[qwords++] = 1051: (regs->statetype << A5XX_SHADER_STATETYPE_SHIFT); 1052: ptr[qwords++] = (((uint64_t) A5XX_HLSQ_DBG_READ_SEL << 44)) | 1053: (1 << 21) | 1; 1054: 1055: /* Read all the data in one chunk */ 1056: ptr[qwords++] = registers->gpuaddr + *offset; 1057: ptr[qwords++] = 1058: (((uint64_t) A5XX_HLSQ_DBG_AHB_READ_APERTURE << 44)) | 1059: regs->size; 1060: 1061: /* Remember the offset of the first bank for easy access */ 1062: regs->offset = *offset; 1063: 1064: *offset += regs->size * sizeof(unsigned int); 1065: 1066: return qwords; 1067: } 1068: 1069: void a5xx_crashdump_init(struct adreno_device *adreno_dev) 1070: { 1071: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1072: unsigned int script_size = 0; 1073: unsigned int data_size = 0; 1074: unsigned int i, j; 1075: uint64_t *ptr; 1076: uint64_t offset = 0; 1077: 1078: if (!IS_ERR_OR_NULL(capturescript) && !IS_ERR_OR_NULL(registers)) 1079: return; 1080: MATCH LINES: 1133, 1140, 1153, 1162 1121: for (i = 0; i < ARRAY_SIZE(a5xx_hlsq_sp_tp_registers); i++) { 1122: script_size += 32; 1123: data_size += 1124: a5xx_hlsq_sp_tp_registers[i].size * sizeof(unsigned int); 1125: } 1126: 1127: /* Now allocate the script and data buffers */ 1128: 1129: /* The script buffers needs 2 extra qwords on the end */ 1130: if (!IS_ERR_OR_NULL(capturescript)) 1131: capturescript = kgsl_allocate_global(device, 1132: script_size + 16, 0, KGSL_MEMFLAGS_GPUREADONLY, 1133: KGSL_MEMDESC_PRIVILEGED, "capturescript"); 1134: 1135: if (IS_ERR(capturescript)) 1136: return; 1137: 1138: if (!IS_ERR_OR_NULL(registers)) 1139: registers = kgsl_allocate_global(device, data_size, 0, 0, 1140: KGSL_MEMDESC_PRIVILEGED, "capturescript_regs"); 1141: 1142: if (IS_ERR(registers)) 1143: return; 1144: 1145: /* Build the crash script */ 1146: 1147: ptr = (uint64_t *) capturescript->hostptr; 1148: 1149: /* For the registers, program a read command for each pair */ 1150: 1151: for (j = 0; j < ARRAY_SIZE(a5xx_registers) / 2; j++) { 1152: unsigned int r = REG_PAIR_COUNT(a5xx_registers, j); 1153: *ptr++ = registers->gpuaddr + offset; 1154: *ptr++ = (((uint64_t) a5xx_registers[2 * j]) << 44) 1155: | r; 1156: offset += r * sizeof(unsigned int); 1157: } 1158: 1159: if (a5xx_has_gpmu(adreno_dev)) { 1160: for (j = 0; j < ARRAY_SIZE(a5xx_gpmu_registers) / 2; j++) { 1161: unsigned int r = REG_PAIR_COUNT(a5xx_gpmu_registers, j); 1162: *ptr++ = registers->gpuaddr + offset; 1163: *ptr++ = (((uint64_t) a5xx_gpmu_registers[2 * j]) << 44) 1164: | r; 1165: offset += r * sizeof(unsigned int); 1166: } 1167: } 1168: 1169: /* Program each shader block */ 1170: for (i = 0; i < ARRAY_SIZE(a5xx_shader_blocks); i++) { 1171: ptr += _a5xx_crashdump_init_shader(&a5xx_shader_blocks[i], ptr, 1172: &offset); 1173: } 1174: /* Program the hlsq sp tp register sets */ 1175: for (i = 0; i < ARRAY_SIZE(a5xx_hlsq_sp_tp_registers); i++) 1176: ptr += _a5xx_crashdump_init_hlsq(&a5xx_hlsq_sp_tp_registers[i], 1177: ptr, &offset); 1178: 1179: *ptr++ = 0; 1180: *ptr++ = 0; 1181: } --- FILE: \adreno_a6xx.c | HITS: 16 --- MATCH LINES: 266 254: 255: int a6xx_init(struct adreno_device *adreno_dev) 256: { 257: adreno_dev->cooperative_reset = ADRENO_FEATURE(adreno_dev, 258: ADRENO_COOP_RESET); 259: 260: a6xx_calc_ubwc_config(adreno_dev); 261: 262: a6xx_crashdump_init(adreno_dev); 263: 264: return adreno_allocate_global(KGSL_DEVICE(adreno_dev), 265: &adreno_dev->pwrup_reglist, 266: PAGE_SIZE, 0, 0, KGSL_MEMDESC_PRIVILEGED, 267: "powerup_register_list"); 268: } 269: 270: static int a6xx_nogmu_init(struct adreno_device *adreno_dev) 271: { 272: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 273: int ret; 274: 275: ret = a6xx_ringbuffer_init(adreno_dev); 276: if (ret) 277: return ret; 278: 279: ret = a6xx_microcode_read(adreno_dev); 280: if (ret) 281: return ret; 282: 283: /* Try to map the GMU wrapper region if applicable */ 284: ret = kgsl_regmap_add_region(&device->regmap, device->pdev, 285: "gmu_wrapper", -EINVAL, NULL, NULL); 286: if (ret && ret != -ENODEV) 287: dev_err(device->dev, "Couldn't map the GMU wrapper registers\n"); 288: 289: adreno_create_profile_buffer(adreno_dev); 290: MATCH LINES: 883 871: /* 872: * Enable hardware clock gating here to prevent any register access 873: * issue due to internal clock gating. 874: */ 875: a6xx_hwcg_set(adreno_dev, true); 876: 877: /* 878: * All registers must be written before this point so that we don't 879: * miss any register programming when we patch the power up register 880: * list. 881: */ 882: if (!adreno_dev->patch_reglist && 883: (adreno_dev->pwrup_reglist->gpuaddr != 0)) { 884: a6xx_patch_pwrup_reglist(adreno_dev); 885: adreno_dev->patch_reglist = true; 886: } 887: 888: /* 889: * During adreno_stop, GBIF halt is asserted to ensure 890: * no further transaction can go through GPU before GPU 891: * headswitch is turned off. 892: * 893: * This halt is deasserted once headswitch goes off but 894: * incase headswitch doesn't goes off clear GBIF halt 895: * here to ensure GPU wake-up doesn't fail because of 896: * halted GPU transactions. 897: */ 898: a6xx_deassert_gbif_halt(adreno_dev); 899: 900: } 901: 902: /* This is the start point for non GMU/RGMU targets */ 903: static int a6xx_nogmu_start(struct adreno_device *adreno_dev) 904: { 905: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 906: int ret; 907: MATCH LINES: 1002, 1004, 1005 990: cmds[i++] = 0x00000000; 991: /* Header dump enable and dump size */ 992: cmds[i++] = 0x00000000; 993: } 994: 995: if (CP_INIT_MASK & CP_INIT_UCODE_WORKAROUND_MASK) 996: cmds[i++] = 0x00000000; 997: 998: if (CP_INIT_MASK & CP_INIT_OPERATION_MODE_MASK) 999: cmds[i++] = 0x00000002; 1000: 1001: if (CP_INIT_MASK & CP_INIT_REGISTER_INIT_LIST_WITH_SPINLOCK) { 1002: uint64_t gpuaddr = adreno_dev->pwrup_reglist->gpuaddr; 1003: 1004: cmds[i++] = lower_32_bits(gpuaddr); 1005: cmds[i++] = upper_32_bits(gpuaddr); 1006: cmds[i++] = 0; 1007: } 1008: } 1009: 1010: void a6xx_spin_idle_debug(struct adreno_device *adreno_dev, 1011: const char *str) 1012: { 1013: struct kgsl_device *device = &adreno_dev->dev; 1014: unsigned int rptr, wptr; 1015: unsigned int status, status3, intstatus; 1016: unsigned int hwfault; 1017: 1018: dev_err(device->dev, str); 1019: 1020: kgsl_regread(device, A6XX_CP_RB_RPTR, &rptr); 1021: kgsl_regread(device, A6XX_CP_RB_WPTR, &wptr); 1022: 1023: kgsl_regread(device, A6XX_RBBM_STATUS, &status); 1024: kgsl_regread(device, A6XX_RBBM_STATUS3, &status3); 1025: kgsl_regread(device, A6XX_RBBM_INT_0_STATUS, &intstatus); 1026: kgsl_regread(device, A6XX_CP_HW_FAULT, &hwfault); 1027: 1028: 1029: dev_err(device->dev, MATCH LINES: 1067, 1095, 1096, 1100, 1101, 1109 1055: if (IS_ERR(cmds)) 1056: return PTR_ERR(cmds); 1057: 1058: a6xx_cp_init_cmds(adreno_dev, cmds); 1059: 1060: ret = a6xx_ringbuffer_submit(rb, NULL, true); 1061: if (!ret) { 1062: ret = adreno_spin_idle(adreno_dev, 2000); 1063: if (ret) { 1064: a6xx_spin_idle_debug(adreno_dev, 1065: "CP initialization failed to idle\n"); 1066: 1067: kgsl_sharedmem_writel(device->scratch, 1068: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1069: rb->wptr = 0; 1070: rb->_wptr = 0; 1071: } 1072: } 1073: 1074: return ret; 1075: } 1076: 1077: /* 1078: * Follow the ME_INIT sequence with a preemption yield to allow the GPU to move 1079: * to a different ringbuffer, if desired 1080: */ 1081: static int _preemption_init(struct adreno_device *adreno_dev, 1082: struct adreno_ringbuffer *rb, unsigned int *cmds, 1083: struct kgsl_context *context) 1084: { 1085: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1086: unsigned int *cmds_orig = cmds; 1087: 1088: /* Turn CP protection OFF on legacy targets */ 1089: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 1090: cmds += cp_protected_mode(adreno_dev, cmds, 0); 1091: 1092: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 1093: kgsl_mmu_is_secured(&device->mmu) ? 6 : 3); 1094: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 1095: cmds += cp_gpuaddr(adreno_dev, cmds, 1096: rb->preemption_desc->gpuaddr); 1097: 1098: if (kgsl_mmu_is_secured(&device->mmu)) { 1099: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 1100: cmds += cp_gpuaddr(adreno_dev, cmds, 1101: rb->secure_preemption_desc->gpuaddr); 1102: } 1103: 1104: /* Turn CP protection back ON */ 1105: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 1106: cmds += cp_protected_mode(adreno_dev, cmds, 1); 1107: 1108: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1109: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 1110: *cmds++ = 0; 1111: /* generate interrupt on preemption completion */ 1112: *cmds++ = 0; 1113: 1114: return cmds - cmds_orig; 1115: } 1116: 1117: static int a6xx_post_start(struct adreno_device *adreno_dev) 1118: { 1119: int ret; 1120: unsigned int *cmds, *start; 1121: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 1122: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1123: 1124: if (!adreno_is_preemption_enabled(adreno_dev)) 1125: return 0; 1126: 1127: cmds = adreno_ringbuffer_allocspace(rb, 42); 1128: if (IS_ERR(cmds)) { 1129: dev_err(device->dev, 1130: "error allocating preemption init cmds\n"); 1131: return PTR_ERR(cmds); 1132: } 1133: start = cmds; MATCH LINES: 1165, 1189, 1192, 1196, 1198 1153: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1154: u32 cp_rb_cntl = A6XX_CP_RB_CNTL_DEFAULT | 1155: (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? 0 : (1 << 27)); 1156: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 1157: struct adreno_ringbuffer *rb; 1158: uint64_t addr; 1159: int ret, i; 1160: unsigned int *cmds; 1161: 1162: /* Clear all the ringbuffers */ 1163: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1164: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 1165: kgsl_sharedmem_writel(device->scratch, 1166: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1167: 1168: rb->wptr = 0; 1169: rb->_wptr = 0; 1170: rb->wptr_preempt_end = ~0; 1171: } 1172: 1173: a6xx_preemption_start(adreno_dev); 1174: 1175: /* Set up the current ringbuffer */ 1176: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 1177: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 1178: 1179: kgsl_regwrite(device, A6XX_CP_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1180: kgsl_regwrite(device, A6XX_CP_RB_RPTR_ADDR_HI, upper_32_bits(addr)); 1181: 1182: /* 1183: * The size of the ringbuffer in the hardware is the log2 1184: * representation of the size in quadwords (sizedwords / 2). 1185: */ 1186: kgsl_regwrite(device, A6XX_CP_RB_CNTL, cp_rb_cntl); 1187: 1188: kgsl_regwrite(device, A6XX_CP_RB_BASE, 1189: lower_32_bits(rb->buffer_desc->gpuaddr)); 1190: 1191: kgsl_regwrite(device, A6XX_CP_RB_BASE_HI, 1192: upper_32_bits(rb->buffer_desc->gpuaddr)); 1193: 1194: /* Program the ucode base for CP */ 1195: kgsl_regwrite(device, A6XX_CP_SQE_INSTR_BASE_LO, 1196: lower_32_bits(fw->memdesc->gpuaddr)); 1197: kgsl_regwrite(device, A6XX_CP_SQE_INSTR_BASE_HI, 1198: upper_32_bits(fw->memdesc->gpuaddr)); 1199: 1200: /* Clear the SQE_HALT to start the CP engine */ 1201: kgsl_regwrite(device, A6XX_CP_SQE_CNTL, 1); 1202: 1203: ret = a6xx_send_cp_init(adreno_dev, rb); 1204: if (ret) 1205: return ret; 1206: 1207: ret = adreno_zap_shader_load(adreno_dev, a6xx_core->zap_name); 1208: if (ret) 1209: return ret; 1210: 1211: /* 1212: * Take the GPU out of secure mode. Try the zap shader if it is loaded, 1213: * otherwise just try to write directly to the secure control register 1214: */ 1215: if (!adreno_dev->zap_loaded) 1216: kgsl_regwrite(device, A6XX_RBBM_SECVID_TRUST_CNTL, 0); 1217: else { 1218: cmds = adreno_ringbuffer_allocspace(rb, 2); 1219: if (IS_ERR(cmds)) 1220: return PTR_ERR(cmds); 1221: 1222: *cmds++ = cp_packet(adreno_dev, CP_SET_SECURE_MODE, 1); --- FILE: \adreno_a6xx_gmu.c | HITS: 9 --- MATCH LINES: 858, 859 846: return -EINVAL; 847: } 848: 849: if (id == GMU_ITCM) { 850: load_tcm(adreno_dev, fw, 851: A6XX_GMU_CM3_ITCM_START, 852: device->gmu_core.vma[GMU_ITCM].start, blk); 853: } else if (id == GMU_DTCM) { 854: load_tcm(adreno_dev, fw, 855: A6XX_GMU_CM3_DTCM_START, 856: device->gmu_core.vma[GMU_DTCM].start, blk); 857: } else { 858: struct kgsl_memdesc *md = 859: gmu_core_find_memdesc(device, blk->addr, blk->size); 860: 861: if (!md) { 862: dev_err(GMU_PDEV_DEV(device), 863: "No backing memory for GMU FW block addr:0x%x size:0x%x\n", 864: blk->addr, blk->size); 865: return -EINVAL; 866: } 867: 868: memcpy(md->hostptr + (blk->addr - md->gmuaddr), fw, 869: blk->size); 870: } 871: 872: fw += blk->size; 873: } 874: 875: /* Proceed only after the FW is written */ 876: wmb(); 877: return 0; 878: } 879: 880: static const char *oob_to_str(enum oob_request req) 881: { 882: if (req == oob_gpu) 883: return "oob_gpu"; MATCH LINES: 1594, 1598, 1610, 1613, 1641, 1657 1582: ((GMU_LOG_SIZE/SZ_4K - 1) & 0xFF); 1583: gmu_core_regwrite(device, A6XX_GPU_GMU_CX_GMU_PWR_COL_CP_MSG, 1584: gmu_log_info); 1585: 1586: /* Configure power control and bring the GMU out of reset */ 1587: a6xx_gmu_power_config(adreno_dev); 1588: 1589: a6xx_gmu_enable_throttle_counters(adreno_dev); 1590: } 1591: 1592: static int reserve_entire_vma(struct a6xx_gmu_device *gmu, u32 vma_id) 1593: { 1594: struct kgsl_memdesc *md; 1595: struct kgsl_device *device = KGSL_DEVICE(a6xx_gmu_to_adreno(gmu)); 1596: u32 start = device->gmu_core.vma[vma_id].start, size = device->gmu_core.vma[vma_id].size; 1597: 1598: md = gmu_core_find_memdesc(device, start, size); 1599: if (md) 1600: return 0; 1601: 1602: md = gmu_core_reserve_kernel_block(device, start, size, vma_id, 0); 1603: 1604: return PTR_ERR_OR_ZERO(md); 1605: } 1606: 1607: static int a6xx_gmu_cache_finalize(struct adreno_device *adreno_dev) 1608: { 1609: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 1610: struct kgsl_memdesc *md; 1611: int ret; 1612: 1613: /* Preallocations were made so no need to request all this memory */ 1614: if (gmu->preallocations) 1615: return 0; 1616: 1617: ret = reserve_entire_vma(gmu, GMU_ICACHE); 1618: if (ret) 1619: return ret; 1620: 1621: if (!adreno_is_a650_family(adreno_dev)) { 1622: ret = reserve_entire_vma(gmu, GMU_DCACHE); 1623: if (ret) 1624: return ret; 1625: } 1626: 1627: md = gmu_core_reserve_kernel_block(KGSL_DEVICE(adreno_dev), 0, SZ_4K, 1628: GMU_NONCACHED_KERNEL, 0); 1629: if (IS_ERR(md)) 1630: return PTR_ERR(md); 1631: 1632: gmu->preallocations = true; 1633: 1634: return 0; 1635: } 1636: 1637: static int a6xx_gmu_process_prealloc(struct a6xx_gmu_device *gmu, 1638: struct gmu_block_header *blk) 1639: { 1640: struct kgsl_device *device = KGSL_DEVICE(a6xx_gmu_to_adreno(gmu)); 1641: struct kgsl_memdesc *md; 1642: 1643: int id = gmu_core_find_vma_block(device, blk->addr, blk->value); 1644: 1645: if (id < 0) { 1646: dev_err(GMU_PDEV_DEV(device), 1647: "Invalid prealloc block addr: 0x%x value:%d\n", 1648: blk->addr, blk->value); 1649: return id; 1650: } 1651: 1652: /* Nothing to do for TCM blocks or user uncached */ 1653: if (id == GMU_ITCM || id == GMU_DTCM || id == GMU_NONCACHED_USER) 1654: return 0; 1655: 1656: /* Check if the block is already allocated */ 1657: md = gmu_core_find_memdesc(device, blk->addr, blk->value); 1658: if (md != NULL) 1659: return 0; 1660: 1661: md = gmu_core_reserve_kernel_block(device, blk->addr, blk->value, id, 0); 1662: if (IS_ERR(md)) 1663: return PTR_ERR(md); 1664: 1665: gmu->preallocations = true; 1666: 1667: return 0; 1668: } 1669: 1670: int a6xx_gmu_parse_fw(struct adreno_device *adreno_dev) 1671: { 1672: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 1673: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev); 1674: struct device *gmu_pdev_dev = GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)); 1675: struct gmu_block_header *blk; 1676: int ret, offset = 0; 1677: 1678: /* GMU fw already saved and verified so do nothing new */ 1679: if (!gmu->fw_image) { 1680: 1681: if (a6xx_core->gmufw_name == NULL) MATCH LINES: 1726 1714: return ret; 1715: } 1716: } 1717: 1718: return 0; 1719: } 1720: 1721: int a6xx_gmu_memory_init(struct adreno_device *adreno_dev) 1722: { 1723: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 1724: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1725: 1726: /* Allocates & maps GMU crash dump memory */ 1727: if (adreno_is_a630(adreno_dev) || adreno_is_a615_family(adreno_dev)) { 1728: if (IS_ERR_OR_NULL(gmu->dump_mem)) 1729: gmu->dump_mem = gmu_core_reserve_kernel_block(device, 0, 1730: SZ_16K, GMU_NONCACHED_KERNEL, 0); 1731: if (IS_ERR(gmu->dump_mem)) 1732: return PTR_ERR(gmu->dump_mem); 1733: } 1734: 1735: /* GMU master log */ 1736: if (IS_ERR_OR_NULL(gmu->gmu_log)) 1737: gmu->gmu_log = gmu_core_reserve_kernel_block(device, 0, GMU_LOG_SIZE, 1738: GMU_NONCACHED_KERNEL, 0); 1739: 1740: return PTR_ERR_OR_ZERO(gmu->gmu_log); 1741: } 1742: 1743: static int a6xx_gmu_init(struct adreno_device *adreno_dev) 1744: { 1745: int ret; 1746: 1747: ret = a6xx_gmu_parse_fw(adreno_dev); 1748: if (ret) 1749: return ret; 1750: --- FILE: \adreno_a6xx_gmu.h | HITS: 3 --- MATCH LINES: 29, 30 17: * @irq: GMU interrupt number 18: * @fw_image: GMU FW image 19: * @dump_mem: pointer to GMU debug dump memory 20: * @gmu_log: gmu event log memory 21: * @hfi: HFI controller 22: * @idle_level: Minimal GPU idle power level 23: * @mailbox: Messages to AOP for ACD enable/disable go through this 24: * @log_wptr_retention: Store the log wptr offset on slumber 25: */ 26: struct a6xx_gmu_device { 27: int irq; 28: const struct firmware *fw_image; 29: struct kgsl_memdesc *dump_mem; 30: struct kgsl_memdesc *gmu_log; 31: struct a6xx_hfi hfi; 32: unsigned int idle_level; 33: /** @qmp: Pointer to qmp struct used for AOP messages*/ 34: struct qmp *qmp; 35: struct kgsl_mailbox mailbox; 36: bool preallocations; 37: unsigned int log_wptr_retention; 38: /** @cm3_fault: whether gmu received a cm3 fault interrupt */ 39: atomic_t cm3_fault; 40: /** 41: * @itcm_shadow: Copy of the itcm block in firmware binary used for 42: * snapshot 43: */ 44: void *itcm_shadow; 45: /** @flags: Internal gmu flags */ 46: unsigned long flags; 47: /** @rscc_virt: Pointer where RSCC block is mapped */ 48: void __iomem *rscc_virt; 49: /** @log_stream_enable: GMU log streaming enable. Disabled by default */ 50: bool log_stream_enable; 51: /** @log_group_mask: Allows overriding default GMU log group mask */ 52: u32 log_group_mask; 53: struct kobject log_kobj; 54: /** @num_oob_perfcntr: Number of active oob_perfcntr requests */ MATCH LINES: 169 157: int a6xx_gmu_probe(struct kgsl_device *device, 158: struct platform_device *pdev); 159: 160: /** 161: * a6xx_gmu_parse_fw - Parse the gmu fw binary 162: * @adreno_dev: Pointer to the adreno device 163: * 164: * Return: 0 on success or negative error on failure 165: */ 166: int a6xx_gmu_parse_fw(struct adreno_device *adreno_dev); 167: 168: /** 169: * a6xx_gmu_memory_init - Allocate gmu memory 170: * @adreno_dev: Pointer to the adreno device 171: * 172: * Allocates the gmu log buffer and others if ndeeded. 173: * 174: * Return: 0 on success or negative error on failure 175: */ 176: int a6xx_gmu_memory_init(struct adreno_device *adreno_dev); 177: 178: /** 179: * a6xx_gmu_aop_send_acd_state - Enable or disable acd feature in aop 180: * @gmu: Pointer to the a6xx gmu device 181: * @flag: Boolean to enable or disable acd in aop 182: * 183: * This function enables or disables gpu acd feature using mailbox or qmp 184: */ 185: void a6xx_gmu_aop_send_acd_state(struct a6xx_gmu_device *gmu, bool flag); 186: 187: /** 188: * a6xx_gmu_disable_gdsc - Disable gmu gdsc 189: * @adreno_dev: Pointer to the adreno device 190: */ 191: void a6xx_gmu_disable_gdsc(struct adreno_device *adreno_dev); 192: 193: /** --- FILE: \adreno_a6xx_gmu_snapshot.c | HITS: 4 --- MATCH LINES: 175, 206, 217, 227 163: (struct kgsl_snapshot_gmu_mem *)buf; 164: u32 *data = (u32 *)(buf + sizeof(*mem_hdr)); 165: u32 i; 166: 167: if (remain < gmu_core->vma[GMU_DTCM].size + sizeof(*mem_hdr)) { 168: SNAPSHOT_ERR_NOMEM(device, "GMU DTCM Memory"); 169: return 0; 170: } 171: 172: mem_hdr->type = SNAPSHOT_GMU_MEM_BIN_BLOCK; 173: mem_hdr->hostaddr = 0; 174: mem_hdr->gmuaddr = gmu_core->vma[GMU_DTCM].start; 175: mem_hdr->gpuaddr = 0; 176: 177: /* FIXME: use a bulk read? */ 178: for (i = 0; i < (gmu_core->vma[GMU_DTCM].size >> 2); i++) 179: gmu_core_regread(device, A6XX_GMU_CM3_DTCM_START + i, data++); 180: 181: return gmu_core->vma[GMU_DTCM].size + sizeof(*mem_hdr); 182: } 183: 184: static size_t a6xx_gmu_snapshot_itcm(struct kgsl_device *device, 185: u8 *buf, size_t remain, void *priv) 186: { 187: struct gmu_core_device *gmu_core = &device->gmu_core; 188: struct kgsl_snapshot_gmu_mem *mem_hdr = 189: (struct kgsl_snapshot_gmu_mem *)buf; 190: void *dest = buf + sizeof(*mem_hdr); 191: struct a6xx_gmu_device *gmu = (struct a6xx_gmu_device *)priv; 192: 193: if (!gmu->itcm_shadow) { 194: dev_err(GMU_PDEV_DEV(device), "ITCM not captured\n"); 195: return 0; 196: } 197: 198: if (remain < gmu_core->vma[GMU_ITCM].size + sizeof(*mem_hdr)) { 199: SNAPSHOT_ERR_NOMEM(device, "GMU ITCM Memory"); 200: return 0; 201: } 202: 203: mem_hdr->type = SNAPSHOT_GMU_MEM_BIN_BLOCK; 204: mem_hdr->hostaddr = 0; 205: mem_hdr->gmuaddr = gmu_core->vma[GMU_ITCM].start; 206: mem_hdr->gpuaddr = 0; 207: 208: memcpy(dest, gmu->itcm_shadow, gmu_core->vma[GMU_ITCM].size); 209: 210: return gmu_core->vma[GMU_ITCM].size + sizeof(*mem_hdr); 211: } 212: 213: static void a6xx_gmu_snapshot_memories(struct kgsl_device *device, 214: struct a6xx_gmu_device *gmu, struct kgsl_snapshot *snapshot) 215: { 216: struct gmu_mem_type_desc desc; 217: struct kgsl_memdesc *md; 218: struct gmu_core_device *gmu_core = &device->gmu_core; 219: int i; 220: 221: for (i = 0; i < ARRAY_SIZE(gmu_core->gmu_globals); i++) { 222: 223: md = &gmu_core->gmu_globals[i]; 224: if (!md->size) 225: continue; 226: 227: desc.memdesc = md; 228: if (md == gmu->hfi.hfi_mem) 229: desc.type = SNAPSHOT_GMU_MEM_HFI; 230: else if (md == gmu->gmu_log) 231: desc.type = SNAPSHOT_GMU_MEM_LOG; 232: else if (md == gmu->dump_mem) 233: desc.type = SNAPSHOT_GMU_MEM_DEBUG; 234: else if (md == gmu_core->vrb) 235: desc.type = SNAPSHOT_GMU_MEM_VRB; 236: else if (md == gmu_core->trace.md) 237: desc.type = SNAPSHOT_GMU_MEM_TRACE; 238: else 239: desc.type = SNAPSHOT_GMU_MEM_BIN_BLOCK; 240: 241: kgsl_snapshot_add_section(device, 242: KGSL_SNAPSHOT_SECTION_GMU_MEMORY, 243: snapshot, adreno_snapshot_gmu_mem, &desc); 244: } 245: } 246: 247: #define RSCC_OFFSET_DWORDS 0x38000 248: 249: static size_t a6xx_snapshot_rscc_registers(struct kgsl_device *device, u8 *buf, 250: size_t remain, void *priv) 251: { --- FILE: \adreno_a6xx_hfi.c | HITS: 4 --- MATCH LINES: 35 23: struct a6xx_hfi *to_a6xx_hfi(struct adreno_device *adreno_dev) 24: { 25: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 26: 27: return &gmu->hfi; 28: } 29: 30: /* Size in below functions are in unit of dwords */ 31: int a6xx_hfi_queue_read(struct a6xx_gmu_device *gmu, uint32_t queue_idx, 32: unsigned int *output, unsigned int max_size) 33: { 34: struct kgsl_device *device = KGSL_DEVICE(a6xx_gmu_to_adreno(gmu)); 35: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 36: struct hfi_queue_table *tbl = mem_addr->hostptr; 37: struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx]; 38: uint32_t *queue; 39: uint32_t msg_hdr; 40: uint32_t i, read; 41: uint32_t size; 42: int result = 0; 43: 44: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 45: return -EINVAL; 46: 47: if (hdr->read_index == hdr->write_index) 48: return -ENODATA; 49: 50: /* Clear the output data before populating */ 51: memset(output, 0, max_size); 52: 53: queue = HOST_QUEUE_START_ADDR(mem_addr, queue_idx); 54: msg_hdr = queue[hdr->read_index]; 55: size = MSG_HDR_GET_SIZE(msg_hdr); 56: 57: if (size > (max_size >> 2)) { 58: dev_err(GMU_PDEV_DEV(device), 59: "HFI message too big: hdr:0x%x rd idx=%d\n", MATCH LINES: 173 161: if (!ret) 162: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), 163: A6XX_GMU_HOST2GMU_INTR_SET, 164: 0x1); 165: 166: return ret; 167: } 168: 169: /* Sizes of the queue and message are in unit of dwords */ 170: static void init_queues(struct adreno_device *adreno_dev) 171: { 172: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 173: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 174: int i; 175: struct hfi_queue_table *tbl; 176: struct hfi_queue_header *hdr; 177: struct { 178: unsigned int idx; 179: unsigned int pri; 180: unsigned int status; 181: } queue[HFI_QUEUE_MAX] = { 182: { HFI_CMD_IDX, HFI_CMD_PRI, HFI_QUEUE_STATUS_ENABLED }, 183: { HFI_MSG_IDX, HFI_MSG_PRI, HFI_QUEUE_STATUS_ENABLED }, 184: { HFI_DBG_IDX, HFI_DBG_PRI, HFI_QUEUE_STATUS_ENABLED }, 185: }; 186: 187: /* 188: * Overwrite the queue IDs for A630, A615 and A616 as they use 189: * legacy firmware. Legacy firmware has different queue IDs for 190: * message, debug and dispatch queues (dispatch queues aren't used 191: * on these targets so the queue idx value update is not needed). 192: */ 193: if (adreno_is_a630(adreno_dev) || adreno_is_a615_family(adreno_dev)) { 194: queue[HFI_MSG_ID].idx = HFI_MSG_IDX_LEGACY; 195: queue[HFI_DBG_ID].idx = HFI_DBG_IDX_LEGACY; 196: } 197: MATCH LINES: 224 212: hdr->start_addr = GMU_QUEUE_START_ADDR(mem_addr->gmuaddr, i); 213: hdr->type = QUEUE_HDR_TYPE(queue[i].idx, queue[i].pri, 0, 0); 214: hdr->status = queue[i].status; 215: hdr->queue_size = HFI_QUEUE_SIZE >> 2; /* convert to dwords */ 216: } 217: } 218: 219: int a6xx_hfi_init(struct adreno_device *adreno_dev) 220: { 221: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 222: struct a6xx_hfi *hfi = &gmu->hfi; 223: 224: /* Allocates & maps memory for HFI */ 225: if (IS_ERR_OR_NULL(hfi->hfi_mem)) { 226: hfi->hfi_mem = gmu_core_reserve_kernel_block(KGSL_DEVICE(adreno_dev), 0, 227: HFIMEM_SIZE, GMU_NONCACHED_KERNEL, 0); 228: if (!IS_ERR(hfi->hfi_mem)) 229: init_queues(adreno_dev); 230: } 231: 232: return PTR_ERR_OR_ZERO(hfi->hfi_mem); 233: } 234: 235: int a6xx_receive_ack_cmd(struct a6xx_gmu_device *gmu, void *rcvd, 236: struct pending_cmd *ret_cmd) 237: { 238: struct adreno_device *adreno_dev = a6xx_gmu_to_adreno(gmu); 239: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 240: uint32_t *ack = rcvd; 241: uint32_t hdr = ack[0]; 242: uint32_t req_hdr = ack[1]; 243: 244: if (ret_cmd == NULL) 245: return -EINVAL; 246: 247: if (CMP_HFI_ACK_HDR(ret_cmd->sent_hdr, req_hdr)) { 248: memcpy(&ret_cmd->results, ack, MSG_HDR_GET_SIZE(hdr) << 2); MATCH LINES: 666 654: &gmu->hfi.acd_table, sizeof(gmu->hfi.acd_table)); 655: if (!ret) 656: ret = a6xx_hfi_send_feature_ctrl(adreno_dev, 657: HFI_FEATURE_ACD, 1, 0); 658: } 659: 660: return ret; 661: } 662: 663: static void reset_hfi_queues(struct adreno_device *adreno_dev) 664: { 665: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 666: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 667: struct hfi_queue_table *tbl = mem_addr->hostptr; 668: struct hfi_queue_header *hdr; 669: unsigned int i; 670: 671: /* Flush HFI queues */ 672: for (i = 0; i < HFI_QUEUE_MAX; i++) { 673: hdr = &tbl->qhdr[i]; 674: 675: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 676: continue; 677: 678: hdr->read_index = hdr->write_index; 679: } 680: } 681: 682: int a6xx_hfi_start(struct adreno_device *adreno_dev) 683: { 684: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 685: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 686: int result; 687: 688: reset_hfi_queues(adreno_dev); 689: 690: /* This is legacy HFI message for A630 and A615 family firmware */ --- FILE: \adreno_a6xx_hfi.h | HITS: 1 --- MATCH LINES: 23 11: /** 12: * struct a6xx_hfi - HFI control structure 13: * @seqnum: atomic counter that is incremented for each message sent. The 14: * value of the counter is used as sequence number for HFI message 15: * @bw_table: HFI BW table buffer 16: * @acd_table: HFI table for ACD data 17: */ 18: struct a6xx_hfi { 19: /** @irq: HFI interrupt line */ 20: int irq; 21: atomic_t seqnum; 22: /** @hfi_mem: Memory descriptor for the hfi memory */ 23: struct kgsl_memdesc *hfi_mem; 24: struct hfi_bwtable_cmd bw_table; 25: struct hfi_acd_table_cmd acd_table; 26: /** @dcvs_table: HFI table for gpu dcvs levels */ 27: struct hfi_dcvstable_cmd dcvs_table; 28: }; 29: 30: struct a6xx_gmu_device; 31: 32: /* a6xx_hfi_irq_handler - IRQ handler for HFI interripts */ 33: irqreturn_t a6xx_hfi_irq_handler(int irq, void *data); 34: 35: /** 36: * a6xx_hfi_start - Send the various HFIs during device boot up 37: * @adreno_dev: Pointer to the adreno device 38: * 39: * Return: 0 on success or negative error on failure 40: */ 41: int a6xx_hfi_start(struct adreno_device *adreno_dev); 42: 43: /** 44: * a6xx_hfi_start - Send the various HFIs during device boot up 45: * @adreno_dev: Pointer to the adreno device 46: * 47: * Return: 0 on success or negative error on failure --- FILE: \adreno_a6xx_hwsched.c | HITS: 2 --- MATCH LINES: 48 36: * payloads are not present, fall back to dumping ringbuffers 37: * based on MEMKIND_RB 38: */ 39: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2) 40: parse_payload = adreno_hwsched_parse_payload_rb_legacy(adreno_dev, snapshot); 41: else 42: parse_payload = adreno_hwsched_parse_payload_rb(adreno_dev, snapshot); 43: 44: if (parse_payload) 45: skip_memkind_rb = true; 46: 47: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 48: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 49: 50: if (entry->desc.mem_kind == HFI_MEMKIND_RB && !skip_memkind_rb) 51: kgsl_snapshot_add_section(device, 52: KGSL_SNAPSHOT_SECTION_RB_V2, 53: snapshot, adreno_hwsched_snapshot_rb, 54: entry->md); 55: 56: if (entry->desc.mem_kind == HFI_MEMKIND_SCRATCH) 57: kgsl_snapshot_add_section(device, 58: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 59: snapshot, adreno_snapshot_global, 60: entry->md); 61: 62: if (entry->desc.mem_kind == HFI_MEMKIND_PROFILE) 63: kgsl_snapshot_add_section(device, 64: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 65: snapshot, adreno_snapshot_global, 66: entry->md); 67: 68: if (entry->desc.mem_kind == HFI_MEMKIND_CSW_SMMU_INFO) 69: kgsl_snapshot_add_section(device, 70: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 71: snapshot, adreno_snapshot_global, 72: entry->md); MATCH LINES: 1081 1069: 1070: if (!IS_ERR_OR_NULL(gmu_core->trace.md)) { 1071: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, 1072: KGSL_GMU_TRACE_ENTRY, 1073: gmu_core->trace.md->hostptr, 1074: gmu_core->trace.md->size); 1075: if (ret) 1076: return ret; 1077: } 1078: 1079: /* Dump HFI hwsched global mem alloc entries */ 1080: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 1081: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 1082: char hfi_minidump_str[MAX_VA_MINIDUMP_STR_LEN] = {0}; 1083: char name[MAX_VA_MINIDUMP_STR_LEN]; 1084: u32 rb_id = 0; 1085: 1086: if (!hfi_get_minidump_string(entry->desc.mem_kind, 1087: &hfi_minidump_str[0], 1088: sizeof(hfi_minidump_str), &rb_id)) { 1089: snprintf(name, sizeof(name), "kgsl_global_%s", hfi_minidump_str); 1090: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, 1091: name, 1092: entry->md->hostptr, 1093: entry->md->size); 1094: if (ret) 1095: return ret; 1096: } 1097: } 1098: 1099: if (!IS_ERR_OR_NULL(hw_hfi->big_ib)) { 1100: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, 1101: KGSL_HFI_BIG_IB_ENTRY, 1102: hw_hfi->big_ib->hostptr, 1103: hw_hfi->big_ib->size); 1104: if (ret) 1105: return ret; --- FILE: \adreno_a6xx_hwsched_hfi.c | HITS: 16 --- MATCH LINES: 345 333: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 334: 335: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2) 336: log_gpu_fault_legacy(adreno_dev); 337: else 338: log_gpu_fault(adreno_dev); 339: 340: adreno_scheduler_fault(adreno_dev, ADRENO_HARD_FAULT); 341: } 342: 343: static u32 peek_next_header(struct a6xx_gmu_device *gmu, uint32_t queue_idx) 344: { 345: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 346: struct hfi_queue_table *tbl = mem_addr->hostptr; 347: struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx]; 348: u32 *queue; 349: 350: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 351: return 0; 352: 353: if (hdr->read_index == hdr->write_index) 354: return 0; 355: 356: queue = HOST_QUEUE_START_ADDR(mem_addr, queue_idx); 357: 358: return queue[hdr->read_index]; 359: } 360: 361: static void a6xx_hwsched_process_msgq(struct adreno_device *adreno_dev) 362: { 363: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 364: struct a6xx_hwsched_hfi *hw_hfi = to_a6xx_hwsched_hfi(adreno_dev); 365: u32 rcvd[MAX_RCVD_SIZE], next_hdr; 366: 367: if (!(hw_hfi->irq_mask & HFI_IRQ_MSGQ_MASK)) 368: return; 369: MATCH LINES: 1041, 1043 1029: "Switch to unsecure failed to idle\n"); 1030: } 1031: 1032: int a6xx_hwsched_cp_init(struct adreno_device *adreno_dev) 1033: { 1034: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev); 1035: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 1036: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1037: int ret; 1038: 1039: /* Program the ucode base for CP */ 1040: kgsl_regwrite(device, A6XX_CP_SQE_INSTR_BASE_LO, 1041: lower_32_bits(fw->memdesc->gpuaddr)); 1042: kgsl_regwrite(device, A6XX_CP_SQE_INSTR_BASE_HI, 1043: upper_32_bits(fw->memdesc->gpuaddr)); 1044: 1045: ret = cp_init(adreno_dev); 1046: if (ret) 1047: return ret; 1048: 1049: ret = adreno_zap_shader_load(adreno_dev, a6xx_core->zap_name); 1050: if (ret) 1051: return ret; 1052: 1053: if (!adreno_dev->zap_loaded) 1054: kgsl_regwrite(KGSL_DEVICE(adreno_dev), 1055: A6XX_RBBM_SECVID_TRUST_CNTL, 0x0); 1056: else 1057: ret = send_switch_to_unsecure(adreno_dev); 1058: 1059: return ret; 1060: } 1061: 1062: static int register_global_ctxt(struct adreno_device *adreno_dev) 1063: { 1064: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1065: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1066: struct hfi_register_ctxt_cmd rcmd = {0}; 1067: struct hfi_context_pointers_cmd pcmd = {0}; MATCH LINES: 1103, 1118 1091: 1092: ret = a6xx_hfi_send_cmd_async(adreno_dev, &pcmd, sizeof(pcmd)); 1093: if (!ret) 1094: hwsched->global_ctxt_gmu_registered = true; 1095: 1096: return ret; 1097: } 1098: 1099: #define HFI_DSP_IRQ_BASE 2 1100: 1101: #define DISPQ_IRQ_BIT(_idx) BIT((_idx) + HFI_DSP_IRQ_BASE) 1102: 1103: static int submit_global_ctxt_cmd(struct adreno_device *adreno_dev, u64 gpuaddr, u32 size) 1104: { 1105: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1106: struct { 1107: struct hfi_submit_cmd submit_cmd; 1108: struct hfi_issue_ib issue_ib; 1109: } cmd = {0}; 1110: u32 seqnum, cmd_size = sizeof(cmd); 1111: static u32 ts; 1112: int ret = 0; 1113: 1114: cmd.submit_cmd.ctxt_id = KGSL_GLOBAL_CTXT_ID; 1115: cmd.submit_cmd.ts = ++ts; 1116: cmd.submit_cmd.numibs = 1; 1117: 1118: cmd.issue_ib.addr = gpuaddr; 1119: cmd.issue_ib.size = size; 1120: 1121: seqnum = atomic_inc_return(&adreno_dev->hwsched.submission_seqnum); 1122: cmd.submit_cmd.hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_CMD, HFI_MSG_CMD); 1123: cmd.submit_cmd.hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd.submit_cmd.hdr, seqnum, cmd_size >> 2); 1124: 1125: ret = a6xx_hfi_dispatch_queue_write(adreno_dev, HFI_DSP_ID_0, 1126: (u32 *)&cmd, cmd_size, NULL, NULL); 1127: /* Send interrupt to GMU to receive the message */ 1128: if (!ret) 1129: gmu_core_regwrite(device, A6XX_GMU_HOST2GMU_INTR_SET, DISPQ_IRQ_BIT(0)); 1130: 1131: return ret; 1132: } 1133: 1134: int a6xx_hwsched_counter_inline_enable(struct adreno_device *adreno_dev, 1135: const struct adreno_perfcount_group *group, 1136: u32 counter, u32 countable) 1137: { 1138: struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev); 1139: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1140: struct adreno_perfcount_register *reg = &group->regs[counter]; 1141: u32 val, *cmds, count = 0; 1142: int ret; MATCH LINES: 1162, 1183 1150: if (ret) 1151: goto err; 1152: 1153: if (group->flags & ADRENO_PERFCOUNTER_GROUP_RESTORE) 1154: a6xx_perfcounter_update(adreno_dev, reg, false); 1155: 1156: cmds = hfi->perfctr_scratch->hostptr; 1157: 1158: cmds[count++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 1159: cmds[count++] = cp_type4_packet(reg->select, 1); 1160: cmds[count++] = countable; 1161: 1162: ret = submit_global_ctxt_cmd(adreno_dev, hfi->perfctr_scratch->gpuaddr, count << 2); 1163: if (ret) 1164: goto err; 1165: 1166: /* Wait till the register is programmed with the countable */ 1167: ret = kgsl_regmap_read_poll_timeout(&device->regmap, reg->select, val, 1168: val == countable, 100, ADRENO_IDLE_TIMEOUT * USEC_PER_MSEC); 1169: if (!ret) { 1170: reg->value = 0; 1171: return ret; 1172: } 1173: 1174: err: 1175: dev_err(device->dev, "Perfcounter %s/%u/%u start via commands failed\n", 1176: group->name, counter, countable); 1177: return ret; 1178: } 1179: 1180: static bool is_queue_empty(struct adreno_device *adreno_dev, u32 queue_idx) 1181: { 1182: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 1183: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 1184: struct hfi_queue_table *tbl = mem_addr->hostptr; 1185: struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx]; 1186: 1187: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 1188: return true; 1189: 1190: if (hdr->read_index == hdr->write_index) 1191: return true; 1192: 1193: return false; 1194: } 1195: 1196: static int hfi_f2h_main(void *arg) 1197: { 1198: struct adreno_device *adreno_dev = arg; 1199: struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev); 1200: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1201: 1202: while (!kthread_should_stop()) { 1203: wait_event_interruptible(hfi->f2h_wq, kthread_should_stop() || 1204: /* If msgq irq is enabled and msgq has messages to process */ 1205: (((hfi->irq_mask & HFI_IRQ_MSGQ_MASK) && 1206: !is_queue_empty(adreno_dev, HFI_MSG_ID)) || 1207: /* Trace buffer has messages to process */ MATCH LINES: 1322 1310: struct hfi_context_pointers_cmd cmd = {0}; 1311: int ret; 1312: 1313: ret = CMD_MSG_HDR(cmd, H2F_MSG_CONTEXT_POINTERS); 1314: if (ret) 1315: return ret; 1316: 1317: cmd.ctxt_id = context->id; 1318: cmd.sop_addr = MEMSTORE_ID_GPU_ADDR(device, context->id, soptimestamp); 1319: cmd.eop_addr = MEMSTORE_ID_GPU_ADDR(device, context->id, eoptimestamp); 1320: if (context->user_ctxt_record) 1321: cmd.user_ctxt_record_addr = 1322: context->user_ctxt_record->memdesc.gpuaddr; 1323: 1324: return a6xx_hfi_send_cmd_async(adreno_dev, &cmd, sizeof(cmd)); 1325: } 1326: 1327: static int hfi_context_register(struct adreno_device *adreno_dev, 1328: struct kgsl_context *context) 1329: { 1330: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1331: int ret; 1332: 1333: if (context->gmu_registered) 1334: return 0; 1335: 1336: ret = send_context_register(adreno_dev, context); 1337: if (ret) { 1338: dev_err(GMU_PDEV_DEV(device), 1339: "Unable to register context %u: %d\n", 1340: context->id, ret); 1341: 1342: if (device->gmu_fault) 1343: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 1344: 1345: return ret; 1346: } MATCH LINES: 1374, 1391 1362: 1363: return 0; 1364: } 1365: 1366: static void populate_ibs(struct adreno_device *adreno_dev, 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: 1414: if (hdr->status == HFI_QUEUE_STATUS_DISABLED || !IS_ALIGNED(size_bytes, sizeof(u32))) 1415: return -EINVAL; MATCH LINES: 1521, 1522, 1523, 1524 1509: cmd->ts = drawobj->timestamp; 1510: 1511: if (test_bit(CMDOBJ_SKIP, &cmdobj->priv)) 1512: goto skipib; 1513: 1514: populate_ibs(adreno_dev, cmd, cmdobj); 1515: 1516: if ((drawobj->flags & KGSL_DRAWOBJ_PROFILING) && 1517: cmdobj->profiling_buf_entry) { 1518: 1519: time.drawobj = drawobj; 1520: 1521: cmd->profile_gpuaddr_lo = 1522: lower_32_bits(cmdobj->profiling_buffer_gpuaddr); 1523: cmd->profile_gpuaddr_hi = 1524: upper_32_bits(cmdobj->profiling_buffer_gpuaddr); 1525: 1526: /* Indicate to GMU to do user profiling for this submission */ 1527: cmd->flags |= CMDBATCH_PROFILING; 1528: } 1529: 1530: skipib: 1531: adreno_drawobj_set_constraint(KGSL_DEVICE(adreno_dev), drawobj); 1532: 1533: seqnum = atomic_inc_return(&adreno_dev->hwsched.submission_seqnum); 1534: cmd->hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_CMD, HFI_MSG_CMD); 1535: cmd->hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd->hdr, seqnum, cmd_sizebytes >> 2); 1536: 1537: ret = a6xx_hfi_dispatch_queue_write(adreno_dev, 1538: HFI_DSP_ID_0 + drawobj->context->gmu_dispatch_queue, 1539: (u32 *)cmd, cmd_sizebytes, cmdobj, &time); 1540: if (ret) 1541: return ret; 1542: 1543: /* Send interrupt to GMU to receive the message */ 1544: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), A6XX_GMU_HOST2GMU_INTR_SET, 1545: DISPQ_IRQ_BIT(drawobj->context->gmu_dispatch_queue)); 1546: 1547: drawctxt->internal_timestamp = drawobj->timestamp; 1548: MATCH LINES: 1733, 1736 1721: struct kgsl_device *device = context->device; 1722: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1723: int ret = 0; 1724: 1725: kgsl_mutex_lock(&device->mutex); 1726: 1727: ret = send_context_unregister_hfi(adreno_dev, context, 1728: drawctxt->internal_timestamp); 1729: 1730: if (ret) 1731: goto out; 1732: 1733: kgsl_sharedmem_writel(device->memstore, 1734: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), drawctxt->timestamp); 1735: 1736: kgsl_sharedmem_writel(device->memstore, 1737: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), drawctxt->timestamp); 1738: 1739: adreno_profile_process_results(adreno_dev); 1740: context->gmu_registered = false; 1741: 1742: out: 1743: kgsl_mutex_unlock(&device->mutex); 1744: } 1745: 1746: u32 a6xx_hwsched_preempt_count_get(struct adreno_device *adreno_dev) 1747: { 1748: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1749: struct hfi_get_value_cmd cmd; 1750: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 1751: struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev); 1752: struct pending_cmd pending_ack; 1753: int rc; 1754: u32 seqnum; 1755: 1756: if (device->state != KGSL_STATE_ACTIVE) 1757: return 0; 1758: 1759: rc = CMD_MSG_HDR(cmd, H2F_MSG_GET_VALUE); 1760: if (rc) --- FILE: \adreno_a6xx_hwsched_hfi.h | HITS: 3 --- MATCH LINES: 22, 24, 26 10: struct a6xx_hwsched_hfi { 11: /** @irq_mask: Store the hfi interrupt mask */ 12: u32 irq_mask; 13: /** @msglock: To protect the list of un-ACKed hfi packets */ 14: rwlock_t msglock; 15: /** @msglist: List of un-ACKed hfi packets */ 16: struct list_head msglist; 17: /** @f2h_task: Task for processing gmu fw to host packets */ 18: struct task_struct *f2h_task; 19: /** @f2h_wq: Waitqueue for the f2h_task */ 20: wait_queue_head_t f2h_wq; 21: /** @big_ib: GMU buffer to hold big IBs */ 22: struct kgsl_memdesc *big_ib; 23: /** @big_ib_recurring: GMU buffer to hold big recurring IBs */ 24: struct kgsl_memdesc *big_ib_recurring; 25: /** @perfctr_scratch: Buffer to hold perfcounter PM4 commands */ 26: struct kgsl_memdesc *perfctr_scratch; 27: /** @msg_mutex: Mutex for accessing the msgq */ 28: struct mutex msgq_mutex; 29: }; 30: 31: struct kgsl_drawobj_cmd; 32: 33: /** 34: * a6xx_hwsched_hfi_probe - Probe hwsched hfi resources 35: * @adreno_dev: Pointer to adreno device structure 36: * 37: * Return: 0 on success and negative error on failure. 38: */ 39: int a6xx_hwsched_hfi_probe(struct adreno_device *adreno_dev); 40: 41: /** 42: * a6xx_hwsched_hfi_remove - Release hwsched hfi resources 43: * @adreno_dev: Pointer to adreno device structure 44: */ 45: void a6xx_hwsched_hfi_remove(struct adreno_device *adreno_dev); 46: 47: /** 48: * a6xx_hwsched_hfi_init - Initialize hfi resources 49: * @adreno_dev: Pointer to adreno device structure 50: * --- FILE: \adreno_a6xx_preempt.c | HITS: 44 --- MATCH LINES: 239 227: if (!empty) 228: return rb; 229: } 230: 231: return NULL; 232: } 233: 234: void a6xx_preemption_trigger(struct adreno_device *adreno_dev, bool atomic) 235: { 236: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 237: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 238: struct adreno_ringbuffer *next; 239: uint64_t ttbr0, gpuaddr; 240: unsigned int contextidr, cntl; 241: unsigned long flags; 242: struct adreno_preemption *preempt = &adreno_dev->preempt; 243: 244: /* Put ourselves into a possible trigger state */ 245: if (!adreno_move_preempt_state(adreno_dev, 246: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START)) 247: return; 248: 249: /* Get the next ringbuffer to preempt in */ 250: next = a6xx_next_ringbuffer(adreno_dev); 251: 252: /* 253: * Nothing to do if every ringbuffer is empty or if the current 254: * ringbuffer is the only active one 255: */ 256: if (next == NULL || next == adreno_dev->cur_rb) { 257: /* 258: * Update any critical things that might have been skipped while 259: * we were looking for a new ringbuffer 260: */ 261: 262: if (next != NULL) { 263: _update_wptr(adreno_dev, false, atomic); MATCH LINES: 284, 286, 289, 297, 299, 303, 327, 345, 352, 358, 365, 371 272: 273: /* Turn off the dispatcher timer */ 274: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 275: 276: /* 277: * This is the most critical section - we need to take care not to race 278: * until we have programmed the CP for the switch 279: */ 280: 281: spin_lock_irqsave(&next->preempt_lock, flags); 282: 283: /* Get the pagetable from the pagetable info. */ 284: kgsl_sharedmem_readq(device->scratch, &ttbr0, 285: SCRATCH_RB_OFFSET(next->id, ttbr0)); 286: kgsl_sharedmem_readl(device->scratch, &contextidr, 287: SCRATCH_RB_OFFSET(next->id, contextidr)); 288: 289: kgsl_sharedmem_writel(next->preemption_desc, 290: PREEMPT_RECORD(wptr), next->wptr); 291: 292: spin_unlock_irqrestore(&next->preempt_lock, flags); 293: 294: /* And write it to the smmu info */ 295: 296: if (kgsl_mmu_is_perprocess(&device->mmu)) { 297: kgsl_sharedmem_writeq(iommu->smmu_info, 298: PREEMPT_SMMU_RECORD(ttbr0), ttbr0); 299: kgsl_sharedmem_writel(iommu->smmu_info, 300: PREEMPT_SMMU_RECORD(context_idr), contextidr); 301: } 302: 303: kgsl_sharedmem_readq(preempt->scratch, &gpuaddr, 304: next->id * sizeof(u64)); 305: 306: /* 307: * Set a keepalive bit before the first preemption register write. 308: * This is required since while each individual write to the context 309: * switch registers will wake the GPU from collapse, it will not in 310: * itself cause GPU activity. Thus, the GPU could technically be 311: * re-collapsed between subsequent register writes leading to a 312: * prolonged preemption sequence. The keepalive bit prevents any 313: * further power collapse while it is set. 314: * It is more efficient to use a keepalive+wake-on-fence approach here 315: * rather than an OOB. Both keepalive and the fence are effectively 316: * free when the GPU is already powered on, whereas an OOB requires an 317: * unconditional handshake with the GMU. 318: */ 319: _power_collapse_set(adreno_dev, true); 320: 321: /* 322: * Fenced writes on this path will make sure the GPU is woken up 323: * in case it was power collapsed by the GMU. 324: */ 325: if (a6xx_fenced_write(adreno_dev, 326: A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO, 327: lower_32_bits(next->preemption_desc->gpuaddr), 328: FENCE_STATUS_WRITEDROPPED1_MASK)) 329: goto err; 330: 331: /* 332: * Above fence writes will make sure GMU comes out of 333: * IFPC state if its was in IFPC state but it doesn't 334: * guarantee that GMU FW actually moved to ACTIVE state 335: * i.e. wake-up from IFPC is complete. 336: * Wait for GMU to move to ACTIVE state before triggering 337: * preemption. This is require to make sure CP doesn't 338: * interrupt GMU during wake-up from IFPC. 339: */ 340: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 341: goto err; 342: 343: if (a6xx_fenced_write(adreno_dev, 344: A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI, 345: upper_32_bits(next->preemption_desc->gpuaddr), 346: FENCE_STATUS_WRITEDROPPED1_MASK)) 347: goto err; 348: 349: if (kgsl_mmu_is_secured(&device->mmu)) { 350: if (a6xx_fenced_write(adreno_dev, 351: A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO, 352: lower_32_bits(next->secure_preemption_desc->gpuaddr), 353: FENCE_STATUS_WRITEDROPPED1_MASK)) 354: goto err; 355: 356: if (a6xx_fenced_write(adreno_dev, 357: A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI, 358: upper_32_bits(next->secure_preemption_desc->gpuaddr), 359: FENCE_STATUS_WRITEDROPPED1_MASK)) 360: goto err; 361: } 362: 363: if (a6xx_fenced_write(adreno_dev, 364: A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO, 365: lower_32_bits(gpuaddr), 366: FENCE_STATUS_WRITEDROPPED1_MASK)) 367: goto err; 368: 369: if (a6xx_fenced_write(adreno_dev, 370: A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI, 371: upper_32_bits(gpuaddr), 372: FENCE_STATUS_WRITEDROPPED1_MASK)) 373: goto err; 374: 375: adreno_dev->next_rb = next; 376: 377: /* Start the timer to detect a stuck preemption */ 378: mod_timer(&adreno_dev->preempt.timer, 379: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 380: 381: cntl = (preempt->preempt_level << 6) | 0x01; 382: 383: /* Skip save/restore during L1 preemption */ 384: if (preempt->skipsaverestore) 385: cntl |= (1 << 9); 386: 387: /* Enable GMEM save/restore across preemption */ 388: if (preempt->usesgmem) 389: cntl |= (1 << 8); 390: 391: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 392: cntl, 0); 393: 394: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 395: MATCH LINES: 502, 508, 510, 516, 519, 523, 524, 527, 529, 540, 541 490: a6xx_preemption_trigger(adreno_dev, false); 491: 492: kgsl_mutex_unlock(&device->mutex); 493: } 494: 495: u32 a6xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev, 496: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 497: u32 *cmds) 498: { 499: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 500: u32 count = kgsl_mmu_is_secured(&device->mmu) ? 12 : 9; 501: unsigned int *cmds_orig = cmds; 502: uint64_t gpuaddr = 0; 503: 504: if (!adreno_is_preemption_enabled(adreno_dev)) 505: return 0; 506: 507: if (drawctxt && drawctxt->base.user_ctxt_record) 508: gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 509: 510: if (gpuaddr) 511: count += 3; 512: 513: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, count); 514: /* NULL SMMU_INFO buffer - we track in KMD */ 515: *cmds++ = SET_PSEUDO_SMMU_INFO; 516: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 517: 518: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 519: cmds += cp_gpuaddr(adreno_dev, cmds, rb->preemption_desc->gpuaddr); 520: 521: if (kgsl_mmu_is_secured(&device->mmu)) { 522: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 523: cmds += cp_gpuaddr(adreno_dev, cmds, 524: rb->secure_preemption_desc->gpuaddr); 525: } 526: 527: if (gpuaddr) { 528: *cmds++ = SET_PSEUDO_NON_PRIV_SAVE_ADDR; 529: cmds += cp_gpuaddr(adreno_dev, cmds, gpuaddr); 530: } 531: 532: /* 533: * There is no need to specify this address when we are about to 534: * trigger preemption. This is because CP internally stores this 535: * address specified here in the CP_SET_PSEUDO_REGISTER payload to 536: * the context record and thus knows from where to restore 537: * the saved perfcounters for the new ringbuffer. 538: */ 539: *cmds++ = SET_PSEUDO_COUNTER; 540: cmds += cp_gpuaddr(adreno_dev, cmds, 541: rb->perfcounter_save_restore_desc->gpuaddr); 542: 543: if (!drawctxt) 544: goto done; 545: 546: cmds += adreno_prepare_preib_preempt_scratch(adreno_dev, drawctxt, cmds); 547: 548: /* Add a KMD post amble to clear the perf counters during preemption */ 549: if (!adreno_dev->perfcounter) 550: cmds += adreno_prepare_preib_postamble_scratch(adreno_dev, cmds); 551: 552: done: 553: return (u32) (cmds - cmds_orig); 554: } 555: 556: u32 a6xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 557: u32 *cmds) 558: { 559: u32 index = 0; 560: 561: if (!adreno_is_preemption_enabled(adreno_dev)) 562: return 0; 563: 564: if (adreno_dev->cur_rb) { 565: u64 dest = PREEMPT_SCRATCH_ADDR(adreno_dev, adreno_dev->cur_rb->id); MATCH LINES: 598, 600, 604, 606, 610, 613, 617, 619, 635, 637, 639, 642, 643, 671, 679, 686, 698, 712, 724, 727 586: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 587: struct adreno_ringbuffer *rb; 588: unsigned int i; 589: 590: if (!adreno_is_preemption_enabled(adreno_dev)) 591: return; 592: 593: /* Force the state to be clear */ 594: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 595: 596: if (kgsl_mmu_is_perprocess(&device->mmu)) { 597: /* smmu_info is allocated and mapped in a6xx_preemption_iommu_init */ 598: kgsl_sharedmem_writel(iommu->smmu_info, 599: PREEMPT_SMMU_RECORD(magic), A6XX_CP_SMMU_INFO_MAGIC_REF); 600: kgsl_sharedmem_writeq(iommu->smmu_info, 601: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 602: 603: /* The CP doesn't use the asid record, so poison it */ 604: kgsl_sharedmem_writel(iommu->smmu_info, 605: PREEMPT_SMMU_RECORD(asid), 0xDECAFBAD); 606: kgsl_sharedmem_writel(iommu->smmu_info, 607: PREEMPT_SMMU_RECORD(context_idr), 0); 608: 609: kgsl_regwrite(device, A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 610: lower_32_bits(iommu->smmu_info->gpuaddr)); 611: 612: kgsl_regwrite(device, A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 613: upper_32_bits(iommu->smmu_info->gpuaddr)); 614: } 615: 616: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 617: kgsl_sharedmem_writel(rb->preemption_desc, 618: PREEMPT_RECORD(rptr), 0); 619: kgsl_sharedmem_writel(rb->preemption_desc, 620: PREEMPT_RECORD(wptr), 0); 621: 622: adreno_ringbuffer_set_pagetable(device, rb, 623: device->mmu.defaultpagetable); 624: } 625: } 626: 627: static void reset_rb_preempt_record(struct adreno_device *adreno_dev, 628: struct adreno_ringbuffer *rb) 629: { 630: u32 cp_rb_cntl = A6XX_CP_RB_CNTL_DEFAULT | 631: (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? 0 : (1 << 27)); 632: 633: memset(rb->preemption_desc->hostptr, 0x0, rb->preemption_desc->size); 634: 635: kgsl_sharedmem_writel(rb->preemption_desc, 636: PREEMPT_RECORD(magic), A6XX_CP_CTXRECORD_MAGIC_REF); 637: kgsl_sharedmem_writel(rb->preemption_desc, 638: PREEMPT_RECORD(cntl), cp_rb_cntl); 639: kgsl_sharedmem_writeq(rb->preemption_desc, 640: PREEMPT_RECORD(rptr_addr), SCRATCH_RB_GPU_ADDR( 641: KGSL_DEVICE(adreno_dev), rb->id, rptr)); 642: kgsl_sharedmem_writeq(rb->preemption_desc, 643: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 644: } 645: 646: void a6xx_reset_preempt_records(struct adreno_device *adreno_dev) 647: { 648: int i; 649: struct adreno_ringbuffer *rb; 650: 651: if (!adreno_is_preemption_enabled(adreno_dev)) 652: return; 653: 654: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 655: reset_rb_preempt_record(adreno_dev, rb); 656: } 657: } 658: 659: static int a6xx_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 660: struct adreno_ringbuffer *rb) 661: { 662: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 663: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev); 664: u64 ctxt_record_size = A6XX_CP_CTXRECORD_SIZE_IN_BYTES; 665: int ret; 666: 667: if (a6xx_core->ctxt_record_size) 668: ctxt_record_size = a6xx_core->ctxt_record_size; 669: 670: ret = adreno_allocate_global(device, &rb->preemption_desc, 671: ctxt_record_size, SZ_16K, 0, KGSL_MEMDESC_PRIVILEGED, 672: "preemption_desc"); 673: if (ret) 674: return ret; 675: 676: if (kgsl_mmu_is_secured(&device->mmu)) { 677: ret = adreno_allocate_global(device, &rb->secure_preemption_desc, 678: ctxt_record_size, 0, KGSL_MEMFLAGS_SECURE, 679: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 680: if (ret) 681: return ret; 682: } 683: 684: ret = adreno_allocate_global(device, &rb->perfcounter_save_restore_desc, 685: A6XX_CP_PERFCOUNTER_SAVE_RESTORE_SIZE, 0, 0, 686: KGSL_MEMDESC_PRIVILEGED, 687: "perfcounter_save_restore_desc"); 688: if (ret) 689: return ret; 690: 691: reset_rb_preempt_record(adreno_dev, rb); 692: 693: return 0; 694: } 695: 696: int a6xx_preemption_init(struct adreno_device *adreno_dev) 697: { 698: u32 flags = ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? KGSL_MEMDESC_PRIVILEGED : 0; 699: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 700: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 701: struct adreno_preemption *preempt = &adreno_dev->preempt; 702: struct adreno_ringbuffer *rb; 703: int ret; 704: unsigned int i; 705: 706: /* We are dependent on IOMMU to make preemption go on the CP side */ 707: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) 708: return -ENODEV; 709: 710: INIT_WORK(&preempt->work, _a6xx_preemption_worker); 711: 712: /* Allocate mem for storing preemption switch record */ 713: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 714: ret = a6xx_preemption_ringbuffer_init(adreno_dev, rb); 715: if (ret) 716: return ret; 717: } 718: 719: ret = adreno_allocate_global(device, &preempt->scratch, 720: PAGE_SIZE, 0, 0, flags, "preempt_scratch"); 721: if (ret) 722: return ret; 723: 724: /* Allocate mem for storing preemption smmu record */ 725: if (kgsl_mmu_is_perprocess(&device->mmu)) { 726: ret = adreno_allocate_global(device, &iommu->smmu_info, PAGE_SIZE, 0, 727: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 728: "smmu_info"); 729: if (ret) 730: return ret; 731: } 732: 733: /* 734: * First 28 dwords of the device scratch buffer are used to store shadow rb data. 735: * Insert PM4 packets in device scratch buffer to clear perfcounters. This should 736: * be in *device->scratch* so that userspace cannot access it. 737: */ 738: if (!adreno_dev->perfcounter) { 739: u32 *postamble = device->scratch->hostptr + SCRATCH_POSTAMBLE_OFFSET; 740: u32 count = 0; 741: 742: postamble[count++] = cp_type4_packet(A6XX_RBBM_PERFCTR_SRAM_INIT_CMD, 1); 743: postamble[count++] = 0x1; 744: 745: postamble[count++] = cp_type7_packet(CP_WAIT_REG_MEM, 6); 746: postamble[count++] = 0x3; 747: postamble[count++] = A6XX_RBBM_PERFCTR_SRAM_INIT_STATUS; 748: postamble[count++] = 0x0; 749: postamble[count++] = 0x1; 750: postamble[count++] = 0x1; 751: postamble[count++] = 0x0; --- FILE: \adreno_a6xx_ringbuffer.c | HITS: 25 --- MATCH LINES: 183 171: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 172: } 173: 174: return ret; 175: } 176: 177: int a6xx_ringbuffer_init(struct adreno_device *adreno_dev) 178: { 179: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 180: int i, ret; 181: 182: ret = adreno_allocate_global(device, &device->scratch, PAGE_SIZE, 183: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED, 184: "scratch"); 185: if (ret) 186: return ret; 187: 188: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]); 189: 190: if (!adreno_preemption_feature_set(adreno_dev)) { 191: adreno_dev->num_ringbuffers = 1; 192: return adreno_ringbuffer_setup(adreno_dev, 193: &adreno_dev->ringbuffers[0], 0); 194: } 195: 196: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers); 197: 198: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 199: int ret; 200: 201: ret = adreno_ringbuffer_setup(adreno_dev, 202: &adreno_dev->ringbuffers[i], i); 203: if (ret) 204: return ret; 205: } 206: 207: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); MATCH LINES: 222, 258, 261, 263, 264, 300, 303, 305, 306 210: } 211: 212: #define A6XX_SUBMIT_MAX 79 213: 214: int a6xx_ringbuffer_addcmds(struct adreno_device *adreno_dev, 215: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 216: u32 flags, u32 *in, u32 dwords, u32 timestamp, 217: struct adreno_submit_time *time) 218: { 219: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 220: u32 size = A6XX_SUBMIT_MAX + dwords; 221: u32 *cmds, index = 0; 222: u64 profile_gpuaddr; 223: u32 profile_dwords; 224: 225: if (adreno_drawctxt_detached(drawctxt)) 226: return -ENOENT; 227: 228: if (adreno_gpu_fault(adreno_dev) != 0) 229: return -EPROTO; 230: 231: rb->timestamp++; 232: 233: if (drawctxt) 234: drawctxt->internal_timestamp = rb->timestamp; 235: 236: /* 237: * if APRIV is enabled we assume all submissions are run with protected 238: * mode off 239: */ 240: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 241: flags &= ~F_NOTPROTECTED; 242: 243: cmds = adreno_ringbuffer_allocspace(rb, size); 244: if (IS_ERR(cmds)) 245: return PTR_ERR(cmds); 246: 247: /* Identify the start of a command */ 248: cmds[index++] = cp_type7_packet(CP_NOP, 1); 249: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 250: 251: /* This is 25 dwords when drawctxt is not NULL and perfcounter needs to be zapped */ 252: index += a6xx_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 253: &cmds[index]); 254: 255: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 256: cmds[index++] = 0x101; /* IFPC disable */ 257: 258: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 259: drawctxt, &profile_dwords); 260: 261: if (profile_gpuaddr) { 262: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 263: cmds[index++] = lower_32_bits(profile_gpuaddr); 264: cmds[index++] = upper_32_bits(profile_gpuaddr); 265: cmds[index++] = profile_dwords; 266: } 267: 268: if (drawctxt) { 269: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 270: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 271: drawctxt)); 272: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 273: drawctxt)); 274: cmds[index++] = timestamp; 275: } 276: 277: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 278: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 279: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); 280: cmds[index++] = rb->timestamp; 281: 282: if (IS_SECURE(flags)) { 283: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 284: cmds[index++] = 1; 285: } 286: 287: if (IS_NOTPROTECTED(flags)) { 288: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1); 289: cmds[index++] = 0; 290: } 291: 292: memcpy(&cmds[index], in, dwords << 2); 293: index += dwords; 294: 295: if (IS_NOTPROTECTED(flags)) { 296: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1); 297: cmds[index++] = 1; 298: } 299: 300: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev, 301: drawctxt, &dwords); 302: 303: if (profile_gpuaddr) { 304: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 305: cmds[index++] = lower_32_bits(profile_gpuaddr); 306: cmds[index++] = upper_32_bits(profile_gpuaddr); 307: cmds[index++] = profile_dwords; 308: } 309: 310: if (test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &device->mmu.pfpolicy)) 311: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0); 312: 313: /* 314: * If this is an internal command, just write the ringbuffer timestamp, 315: * otherwise, write both 316: */ 317: if (!drawctxt) { 318: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 319: cmds[index++] = CACHE_FLUSH_TS | (1 << 31); 320: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb)); 321: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb)); 322: cmds[index++] = rb->timestamp; 323: } else { 324: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 325: cmds[index++] = CACHE_FLUSH_TS | (1 << 31); 326: cmds[index++] = lower_32_bits(CTXT_EOPTIMESTAMP(device, 327: drawctxt)); 328: cmds[index++] = upper_32_bits(CTXT_EOPTIMESTAMP(device, 329: drawctxt)); 330: cmds[index++] = timestamp; MATCH LINES: 360, 364, 365, 370, 374, 375, 387, 394, 396, 399, 400 348: } 349: 350: /* 10 dwords */ 351: index += a6xx_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 352: 353: /* Adjust the thing for the number of dwords we actually wrote */ 354: rb->_wptr -= (size - index); 355: 356: return a6xx_ringbuffer_submit(rb, time, 357: !adreno_is_preemption_enabled(adreno_dev)); 358: } 359: 360: static u32 a6xx_get_alwayson_counter(u32 *cmds, u64 gpuaddr) 361: { 362: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 363: cmds[1] = A6XX_CP_ALWAYS_ON_COUNTER_LO | (1 << 30) | (2 << 18); 364: cmds[2] = lower_32_bits(gpuaddr); 365: cmds[3] = upper_32_bits(gpuaddr); 366: 367: return 4; 368: } 369: 370: static u32 a6xx_get_alwayson_context(u32 *cmds, u64 gpuaddr) 371: { 372: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 373: cmds[1] = A6XX_CP_ALWAYS_ON_CONTEXT_LO | (1 << 30) | (2 << 18); 374: cmds[2] = lower_32_bits(gpuaddr); 375: cmds[3] = upper_32_bits(gpuaddr); 376: 377: return 4; 378: } 379: 380: #define PROFILE_IB_DWORDS 4 381: #define PROFILE_IB_SLOTS (PAGE_SIZE / (PROFILE_IB_DWORDS << 2)) 382: 383: static u64 a6xx_get_user_profiling_ib(struct adreno_ringbuffer *rb, 384: struct kgsl_drawobj_cmd *cmdobj, u32 target_offset, u32 *cmds) 385: { 386: u32 offset, *ib, dwords; 387: u64 gpuaddr; 388: 389: if (IS_ERR(rb->profile_desc)) 390: return 0; 391: 392: offset = rb->profile_index * (PROFILE_IB_DWORDS << 2); 393: ib = rb->profile_desc->hostptr + offset; 394: gpuaddr = rb->profile_desc->gpuaddr + offset; 395: dwords = a6xx_get_alwayson_counter(ib, 396: cmdobj->profiling_buffer_gpuaddr + target_offset); 397: 398: cmds[0] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 399: cmds[1] = lower_32_bits(gpuaddr); 400: cmds[2] = upper_32_bits(gpuaddr); 401: cmds[3] = dwords; 402: 403: rb->profile_index = (rb->profile_index + 1) % PROFILE_IB_SLOTS; 404: 405: return 4; 406: } 407: 408: static int a6xx_drawctxt_switch(struct adreno_device *adreno_dev, 409: struct adreno_ringbuffer *rb, 410: struct adreno_context *drawctxt) 411: { 412: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 413: int ret; 414: 415: if (rb->drawctxt_active == drawctxt) 416: return 0; 417: 418: if (kgsl_context_detached(&drawctxt->base)) 419: return -ENOENT; 420: 421: if (!_kgsl_context_get(&drawctxt->base)) 422: return -ENOENT; 423: 424: ret = a6xx_rb_context_switch(adreno_dev, rb, drawctxt); MATCH LINES: 447, 453 435: 436: rb->drawctxt_active = drawctxt; 437: return 0; 438: } 439: 440: #define A6XX_USER_PROFILE_IB(rb, cmdobj, cmds, field) \ 441: a6xx_get_user_profiling_ib((rb), (cmdobj), \ 442: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 443: (cmds)) 444: 445: #define A6XX_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 446: a6xx_get_alwayson_counter((cmds), \ 447: (dev)->profile_buffer->gpuaddr + \ 448: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 449: field)) 450: 451: #define A6XX_KERNEL_PROFILE_CONTEXT(dev, cmdobj, cmds, field) \ 452: a6xx_get_alwayson_context((cmds), \ 453: (dev)->profile_buffer->gpuaddr + \ 454: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 455: field)) 456: 457: #define A6XX_COMMAND_DWORDS 40 458: 459: int a6xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 460: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 461: struct adreno_submit_time *time) 462: { 463: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 464: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 465: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 466: struct adreno_ringbuffer *rb = drawctxt->rb; 467: int ret = 0, numibs = 0, index = 0; 468: u32 *cmds; 469: 470: /* Count the number of IBs (if we are not skipping) */ 471: if (!IS_SKIP(flags)) { 472: struct list_head *tmp; 473: 474: list_for_each(tmp, &cmdobj->cmdlist) 475: numibs++; 476: } 477: MATCH LINES: 514, 515 502: 503: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 504: cmds[index++] = 0x00d; /* IB1LIST start */ 505: 506: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 507: if (ib->priv & MEMOBJ_SKIP || 508: (ib->flags & KGSL_CMDLIST_CTXTSWITCH_PREAMBLE 509: && !IS_PREAMBLE(flags))) 510: cmds[index++] = cp_type7_packet(CP_NOP, 4); 511: 512: cmds[index++] = 513: cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 514: cmds[index++] = lower_32_bits(ib->gpuaddr); 515: cmds[index++] = upper_32_bits(ib->gpuaddr); 516: 517: /* Double check that IB_PRIV is never set */ 518: cmds[index++] = (ib->size >> 2) & 0xfffff; 519: } 520: 521: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 522: cmds[index++] = 0x00e; /* IB1LIST end */ 523: } 524: 525: /* CCU invalidate */ 526: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1); 527: cmds[index++] = 24; 528: 529: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1); 530: cmds[index++] = 25; 531: 532: /* 8 dwords */ 533: if (IS_KERNEL_PROFILE(flags)) { 534: index += A6XX_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index], 535: retired); 536: index += A6XX_KERNEL_PROFILE_CONTEXT(adreno_dev, cmdobj, &cmds[index], 537: ctx_end); 538: } 539: --- FILE: \adreno_a6xx_snapshot.c | HITS: 12 --- MATCH LINES: 574, 575 562: {A6XX_HLSQ_GFX_CVS_CONST_RAM_TAG, 0xC,}, 563: {A6XX_HLSQ_GFX_CPS_CONST_RAM_TAG, 0x10}, 564: {A6XX_HLSQ_PWR_REST_RAM, 0x28}, 565: {A6XX_HLSQ_PWR_REST_TAG, 0x14}, 566: {A6XX_HLSQ_DATAPATH_META, 0x40,}, 567: {A6XX_HLSQ_FRONTEND_META, 0x40}, 568: {A6XX_HLSQ_INDIRECT_META, 0x40,}, 569: {A6XX_SP_LB_6_DATA, 0x200}, 570: {A6XX_SP_LB_7_DATA, 0x200}, 571: {A6XX_HLSQ_INST_RAM_1, 0x200}, 572: }; 573: 574: static struct kgsl_memdesc *a6xx_capturescript; 575: static struct kgsl_memdesc *a6xx_crashdump_registers; 576: static bool crash_dump_valid; 577: static u32 *a6xx_cd_reg_end; 578: 579: static struct reg_list { 580: const unsigned int *regs; 581: unsigned int count; 582: const struct sel_reg *sel; 583: uint64_t offset; 584: } a6xx_reg_list[] = { 585: { a6xx_registers, ARRAY_SIZE(a6xx_registers) / 2, NULL }, 586: { a660_registers, ARRAY_SIZE(a660_registers) / 2, NULL }, 587: { a6xx_rb_rac_registers, ARRAY_SIZE(a6xx_rb_rac_registers) / 2, 588: &_a6xx_rb_rac_aperture }, 589: { a6xx_rb_rbp_registers, ARRAY_SIZE(a6xx_rb_rbp_registers) / 2, 590: &_a6xx_rb_rbp_aperture }, 591: }; 592: 593: #define REG_PAIR_COUNT(_a, _i) \ 594: (((_a)[(2 * (_i)) + 1] - (_a)[2 * (_i)]) + 1) 595: 596: static size_t a6xx_legacy_snapshot_registers(struct kgsl_device *device, 597: u8 *buf, size_t remain, struct reg_list *regs) 598: { 599: struct kgsl_snapshot_registers snapshot_regs = { MATCH LINES: 1583, 1585 1571: IS_ERR_OR_NULL(a6xx_crashdump_registers)) 1572: return; 1573: 1574: /* IF the SMMU is stalled we cannot do a crash dump */ 1575: if (adreno_smmu_is_stalled(ADRENO_DEVICE(device))) 1576: return; 1577: 1578: /* Turn on APRIV for legacy targets so we can access the buffers */ 1579: if (!ADRENO_FEATURE(ADRENO_DEVICE(device), ADRENO_APRIV)) 1580: kgsl_regwrite(device, A6XX_CP_MISC_CNTL, 1); 1581: 1582: kgsl_regwrite(device, A6XX_CP_CRASH_SCRIPT_BASE_LO, 1583: lower_32_bits(a6xx_capturescript->gpuaddr)); 1584: kgsl_regwrite(device, A6XX_CP_CRASH_SCRIPT_BASE_HI, 1585: upper_32_bits(a6xx_capturescript->gpuaddr)); 1586: kgsl_regwrite(device, A6XX_CP_CRASH_DUMP_CNTL, 1); 1587: 1588: timeout = ktime_add_ms(ktime_get(), CP_CRASH_DUMPER_TIMEOUT); 1589: 1590: if (!device->snapshot_atomic) 1591: might_sleep(); 1592: 1593: for (;;) { 1594: /* make sure we're reading the latest value */ 1595: rmb(); 1596: if ((*a6xx_cd_reg_end) != 0xaaaaaaaa) 1597: break; 1598: 1599: if (ktime_compare(ktime_get(), timeout) > 0) 1600: break; 1601: 1602: /* Wait 1msec to avoid unnecessary looping */ 1603: if (!device->snapshot_atomic) 1604: usleep_range(100, 1000); 1605: } 1606: 1607: kgsl_regread(device, A6XX_CP_CRASH_DUMP_STATUS, &val); 1608: 1609: if (!ADRENO_FEATURE(ADRENO_DEVICE(device), ADRENO_APRIV)) MATCH LINES: 1878, 1906 1866: 1867: if (j == 1) 1868: cluster->offset1 = *offset; 1869: 1870: ptr[qwords++] = (cluster->id << 8) | (j << 4) | j; 1871: ptr[qwords++] = 1872: ((uint64_t)A6XX_CP_APERTURE_CNTL_CD << 44) | 1873: (1 << 21) | 1; 1874: 1875: for (k = 0; k < cluster->num_sets; k++) { 1876: count = REG_PAIR_COUNT(cluster->regs, k); 1877: ptr[qwords++] = 1878: a6xx_crashdump_registers->gpuaddr + *offset; 1879: ptr[qwords++] = 1880: (((uint64_t)cluster->regs[2 * k]) << 44) | 1881: count; 1882: 1883: *offset += count * sizeof(unsigned int); 1884: } 1885: } 1886: } 1887: 1888: return qwords; 1889: } 1890: 1891: static int _a6xx_crashdump_init_shader(struct a6xx_shader_block *block, 1892: uint64_t *ptr, uint64_t *offset) 1893: { 1894: int qwords = 0; 1895: unsigned int j; 1896: 1897: /* Capture each bank in the block */ 1898: for (j = 0; j < A6XX_NUM_SHADER_BANKS; j++) { 1899: /* Program the aperture */ 1900: ptr[qwords++] = 1901: (block->statetype << A6XX_SHADER_STATETYPE_SHIFT) | j; 1902: ptr[qwords++] = (((uint64_t) A6XX_HLSQ_DBG_READ_SEL << 44)) | 1903: (1 << 21) | 1; 1904: 1905: /* Read all the data in one chunk */ 1906: ptr[qwords++] = a6xx_crashdump_registers->gpuaddr + *offset; 1907: ptr[qwords++] = 1908: (((uint64_t) A6XX_HLSQ_DBG_AHB_READ_APERTURE << 44)) | 1909: block->sz; 1910: 1911: /* Remember the offset of the first bank for easy access */ 1912: if (j == 0) 1913: block->offset = *offset; 1914: 1915: *offset += block->sz * sizeof(unsigned int); 1916: } 1917: 1918: return qwords; 1919: } 1920: 1921: static int _a6xx_crashdump_init_ctx_dbgahb(uint64_t *ptr, uint64_t *offset) 1922: { 1923: int qwords = 0; 1924: unsigned int i, j, k; 1925: unsigned int count; 1926: 1927: for (i = 0; i < ARRAY_SIZE(a6xx_dbgahb_ctx_clusters); i++) { 1928: struct a6xx_cluster_dbgahb_registers *cluster = 1929: &a6xx_dbgahb_ctx_clusters[i]; 1930: MATCH LINES: 1949, 1984 1937: /* Program the aperture */ 1938: ptr[qwords++] = 1939: ((cluster->statetype + j * 2) & 0xff) << 8; 1940: ptr[qwords++] = 1941: (((uint64_t)A6XX_HLSQ_DBG_READ_SEL << 44)) | 1942: (1 << 21) | 1; 1943: 1944: for (k = 0; k < cluster->num_sets; k++) { 1945: unsigned int start = cluster->regs[2 * k]; 1946: 1947: count = REG_PAIR_COUNT(cluster->regs, k); 1948: ptr[qwords++] = 1949: a6xx_crashdump_registers->gpuaddr + *offset; 1950: ptr[qwords++] = 1951: (((uint64_t)(A6XX_HLSQ_DBG_AHB_READ_APERTURE + 1952: start - cluster->regbase / 4) << 44)) | 1953: count; 1954: 1955: *offset += count * sizeof(unsigned int); 1956: } 1957: } 1958: } 1959: return qwords; 1960: } 1961: 1962: static int _a6xx_crashdump_init_non_ctx_dbgahb(uint64_t *ptr, uint64_t *offset) 1963: { 1964: int qwords = 0; 1965: unsigned int i, k; 1966: unsigned int count; 1967: 1968: for (i = 0; i < ARRAY_SIZE(a6xx_non_ctx_dbgahb); i++) { 1969: struct a6xx_non_ctx_dbgahb_registers *regs = 1970: &a6xx_non_ctx_dbgahb[i]; 1971: 1972: regs->offset = *offset; 1973: 1974: /* Program the aperture */ 1975: ptr[qwords++] = (regs->statetype & 0xff) << 8; 1976: ptr[qwords++] = (((uint64_t)A6XX_HLSQ_DBG_READ_SEL << 44)) | 1977: (1 << 21) | 1; 1978: 1979: for (k = 0; k < regs->num_sets; k++) { 1980: unsigned int start = regs->regs[2 * k]; 1981: 1982: count = REG_PAIR_COUNT(regs->regs, k); 1983: ptr[qwords++] = 1984: a6xx_crashdump_registers->gpuaddr + *offset; 1985: ptr[qwords++] = 1986: (((uint64_t)(A6XX_HLSQ_DBG_AHB_READ_APERTURE + 1987: start - regs->regbase / 4) << 44)) | 1988: count; 1989: 1990: *offset += count * sizeof(unsigned int); 1991: } 1992: } 1993: return qwords; 1994: } 1995: 1996: void a6xx_crashdump_init(struct adreno_device *adreno_dev) 1997: { 1998: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1999: unsigned int script_size = 0; 2000: unsigned int data_size = 0; 2001: unsigned int i, j, k, ret; 2002: uint64_t *ptr; 2003: uint64_t offset = 0; 2004: 2005: if (!IS_ERR_OR_NULL(a6xx_capturescript) && 2006: !IS_ERR_OR_NULL(a6xx_crashdump_registers)) 2007: return; 2008: MATCH LINES: 2131, 2136, 2165, 2193 2119: } 2120: 2121: /* 16 bytes (2 qwords) for last entry in CD script */ 2122: script_size += 16; 2123: /* Increment data size to store last entry in CD */ 2124: data_size += sizeof(unsigned int); 2125: 2126: /* Now allocate the script and data buffers */ 2127: 2128: /* The script buffers needs 2 extra qwords on the end */ 2129: ret = adreno_allocate_global(device, &a6xx_capturescript, 2130: script_size + 16, 0, KGSL_MEMFLAGS_GPUREADONLY, 2131: KGSL_MEMDESC_PRIVILEGED, "capturescript"); 2132: if (ret) 2133: return; 2134: 2135: ret = adreno_allocate_global(device, &a6xx_crashdump_registers, 2136: data_size, 0, 0, KGSL_MEMDESC_PRIVILEGED, 2137: "capturescript_regs"); 2138: if (ret) 2139: return; 2140: 2141: /* Build the crash script */ 2142: 2143: ptr = (uint64_t *)a6xx_capturescript->hostptr; 2144: 2145: /* For the registers, program a read command for each pair */ 2146: for (i = 0; i < ARRAY_SIZE(a6xx_reg_list); i++) { 2147: struct reg_list *regs = &a6xx_reg_list[i]; 2148: 2149: /* Skip registers that dont exists on targets other than A660 */ 2150: if (!adreno_is_a660(adreno_dev) && 2151: (regs->regs == a660_registers)) 2152: continue; 2153: 2154: regs->offset = offset; 2155: 2156: /* Program the SEL_CNTL_CD register appropriately */ 2157: if (regs->sel) { 2158: *ptr++ = regs->sel->val; 2159: *ptr++ = (((uint64_t)regs->sel->cd_reg << 44)) | 2160: (1 << 21) | 1; 2161: } 2162: 2163: for (j = 0; j < regs->count; j++) { 2164: unsigned int r = REG_PAIR_COUNT(regs->regs, j); 2165: *ptr++ = a6xx_crashdump_registers->gpuaddr + offset; 2166: *ptr++ = (((uint64_t) regs->regs[2 * j]) << 44) | r; 2167: offset += r * sizeof(unsigned int); 2168: } 2169: } 2170: 2171: /* Program each shader block */ 2172: for (i = 0; i < ARRAY_SIZE(a6xx_shader_blocks); i++) { 2173: ptr += _a6xx_crashdump_init_shader(&a6xx_shader_blocks[i], ptr, 2174: &offset); 2175: } 2176: 2177: /* Program the capturescript for the MVC regsiters */ 2178: ptr += _a6xx_crashdump_init_mvc(adreno_dev, ptr, &offset); 2179: 2180: if (!adreno_is_a663(adreno_dev)) { 2181: ptr += _a6xx_crashdump_init_ctx_dbgahb(ptr, &offset); 2182: 2183: ptr += _a6xx_crashdump_init_non_ctx_dbgahb(ptr, &offset); 2184: } 2185: 2186: /* Save CD register end pointer to check CD status completion */ 2187: a6xx_cd_reg_end = a6xx_crashdump_registers->hostptr + offset; 2188: 2189: memset(a6xx_crashdump_registers->hostptr, 0xaa, 2190: a6xx_crashdump_registers->size); 2191: 2192: /* Program the capturescript to read the last register entry */ 2193: *ptr++ = a6xx_crashdump_registers->gpuaddr + offset; 2194: *ptr++ = (((uint64_t) A6XX_CP_CRASH_DUMP_STATUS) << 44) | (uint64_t) 1; 2195: 2196: *ptr++ = 0; 2197: *ptr++ = 0; 2198: } --- FILE: \adreno_compat.c | HITS: 1 --- MATCH LINES: 55 43: break; 44: case KGSL_PROP_DEVICE_SHADOW: 45: { 46: struct kgsl_shadowprop_compat shadowprop; 47: 48: if (param->sizebytes != sizeof(shadowprop)) { 49: status = -EINVAL; 50: break; 51: } 52: memset(&shadowprop, 0, sizeof(shadowprop)); 53: if (device->memstore->hostptr) { 54: /* Give a token address to identify memstore */ 55: shadowprop.gpuaddr = (unsigned int) 56: KGSL_MEMSTORE_TOKEN_ADDRESS; 57: shadowprop.size = 58: (unsigned int) device->memstore->size; 59: /* 60: * GSL needs this to be set, even if it 61: * appears to be meaningless 62: */ 63: shadowprop.flags = KGSL_FLAGS_INITIALIZED | 64: KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS; 65: } 66: if (copy_to_user(param->value, &shadowprop, 67: sizeof(shadowprop))) { 68: status = -EFAULT; 69: break; 70: } 71: status = 0; 72: } 73: break; 74: default: 75: status = device->ftbl->getproperty(device, param); 76: } 77: 78: return status; 79: } --- FILE: \adreno_cp_parser.c | HITS: 52 --- MATCH LINES: 38, 52, 56, 58, 59, 61, 62, 64, 66, 71, 79, 89, 90, 98, 99, 104, 111, 121, 124, 130, 131, 133, 135, 138, 141, 142 26: }; 27: 28: /* List of variables used when parsing an IB */ 29: struct ib_parser_variables { 30: /* List of registers containing addresses and their sizes */ 31: unsigned int cp_addr_regs[ADRENO_CP_ADDR_MAX]; 32: /* 32 groups of command streams in set draw state packets */ 33: struct set_draw_state set_draw_groups[NUM_SET_DRAW_GROUPS]; 34: }; 35: 36: static int adreno_ib_find_objs(struct kgsl_device *device, 37: struct kgsl_process_private *process, 38: uint64_t gpuaddr, uint64_t dwords, 39: uint64_t ib2base, int obj_type, 40: struct adreno_ib_object_list *ib_obj_list, 41: int ib_level); 42: 43: static int ib_parse_type7_set_draw_state(struct kgsl_device *device, 44: unsigned int *ptr, int size, 45: struct kgsl_process_private *process, 46: struct adreno_ib_object_list *ib_obj_list); 47: 48: /* 49: * adreno_ib_merge_range() - Increases the address range tracked by an ib 50: * object 51: * @ib_obj: The ib object 52: * @gpuaddr: The start address which is to be merged 53: * @size: Size of the merging address 54: */ 55: static void adreno_ib_merge_range(struct adreno_ib_object *ib_obj, 56: uint64_t gpuaddr, uint64_t size) 57: { 58: uint64_t addr_end1 = ib_obj->gpuaddr + ib_obj->size; 59: uint64_t addr_end2 = gpuaddr + size; 60: 61: if (gpuaddr < ib_obj->gpuaddr) 62: ib_obj->gpuaddr = gpuaddr; 63: if (addr_end2 > addr_end1) 64: ib_obj->size = addr_end2 - ib_obj->gpuaddr; 65: else 66: ib_obj->size = addr_end1 - ib_obj->gpuaddr; 67: } 68: 69: /* 70: * adreno_ib_check_overlap() - Checks if an address range overlap 71: * @gpuaddr: The start address range to check for overlap 72: * @size: Size of the address range 73: * @type: The type of address range 74: * @ib_obj_list: The list of address ranges to check for overlap 75: * 76: * Checks if an address range overlaps with a list of address ranges 77: * Returns the entry from list which overlaps else NULL 78: */ 79: static struct adreno_ib_object *adreno_ib_check_overlap(uint64_t gpuaddr, 80: uint64_t size, int type, 81: struct adreno_ib_object_list *ib_obj_list) 82: { 83: struct adreno_ib_object *ib_obj; 84: int i; 85: 86: for (i = 0; i < ib_obj_list->num_objs; i++) { 87: ib_obj = &(ib_obj_list->obj_list[i]); 88: if ((type == ib_obj->snapshot_obj_type) && 89: kgsl_addr_range_overlap(ib_obj->gpuaddr, ib_obj->size, 90: gpuaddr, size)) 91: /* regions overlap */ 92: return ib_obj; 93: } 94: return NULL; 95: } 96: 97: /* 98: * adreno_ib_add() - Add a gpuaddress range to list 99: * @process: Process in which the gpuaddress is mapped 100: * @type: The type of address range 101: * @ib_obj_list: List of the address ranges in which the given range is to be 102: * added 103: * 104: * Add a gpuaddress range as an ib object to a given list after checking if it 105: * overlaps with another entry on the list. If it conflicts then change the 106: * existing entry to incorporate this range 107: * 108: * Returns 0 on success else error code 109: */ 110: static int adreno_ib_add(struct kgsl_process_private *process, 111: uint64_t gpuaddr, int type, 112: struct adreno_ib_object_list *ib_obj_list) 113: { 114: uint64_t size; 115: struct adreno_ib_object *ib_obj; 116: struct kgsl_mem_entry *entry; 117: 118: if (ib_obj_list->num_objs >= MAX_IB_OBJS) 119: return -E2BIG; 120: 121: entry = kgsl_sharedmem_find(process, gpuaddr); 122: if (!entry) 123: /* 124: * Do not fail if gpuaddr not found, we can continue 125: * to search for other objects even if few objects are 126: * not found 127: */ 128: return 0; 129: 130: size = entry->memdesc.size; 131: gpuaddr = entry->memdesc.gpuaddr; 132: 133: ib_obj = adreno_ib_check_overlap(gpuaddr, size, type, ib_obj_list); 134: if (ib_obj) { 135: adreno_ib_merge_range(ib_obj, gpuaddr, size); 136: kgsl_mem_entry_put(entry); 137: } else { 138: adreno_ib_init_ib_obj(gpuaddr, size, type, entry, 139: &(ib_obj_list->obj_list[ib_obj_list->num_objs])); 140: ib_obj_list->num_objs++; 141: /* Skip reclaim for the memdesc until it is dumped */ 142: SET_FLAG(KGSL_MEMDESC_SKIP_RECLAIM, &entry->memdesc.priv); 143: } 144: return 0; 145: } 146: 147: /* 148: * ib_add_type0_entries() - Add memory objects to list 149: * @device: The device on which the IB will execute 150: * @process: The process in which IB is mapped 151: * @ib_obj_list: The list of gpu objects 152: * @ib_parse_vars: addresses ranges found in type0 packets 153: * 154: * Add memory objects to given list that are found in type0 packets 155: * Returns 0 on success else 0 156: */ 157: static int ib_add_type0_entries(struct kgsl_device *device, 158: struct kgsl_process_private *process, 159: struct adreno_ib_object_list *ib_obj_list, 160: struct ib_parser_variables *ib_parse_vars) 161: { 162: int ret = 0; 163: int i; 164: int vfd_end; 165: unsigned int mask; 166: /* First up the visiblity stream buffer */ MATCH LINES: 289, 291, 293, 307, 318, 332, 333, 342, 343, 344, 348, 378, 391, 409, 410, 411, 415, 419, 424, 432, 459, 465, 491, 501, 515, 538 277: cmd_stream_addr = cmd_stream_addr << 32 | ptr[i + 1]; 278: if (cmd_stream_dwords) 279: ret = adreno_ib_find_objs(device, process, 280: cmd_stream_addr, cmd_stream_dwords, 281: 0, SNAPSHOT_GPU_OBJECT_DRAW, 282: ib_obj_list, IB_LEVEL_2); 283: if (ret) 284: break; 285: continue; 286: } 287: /* load immediate */ 288: if (flags & 0x8) { 289: uint64_t gpuaddr = ptr[i + 2]; 290: 291: gpuaddr = gpuaddr << 32 | ptr[i + 1]; 292: ret = adreno_ib_find_objs(device, process, 293: gpuaddr, (ptr[i] & 0x0000FFFF), 294: 0, SNAPSHOT_GPU_OBJECT_IB, 295: ib_obj_list, IB_LEVEL_2); 296: if (ret) 297: break; 298: } 299: } 300: return ret; 301: } 302: 303: /* 304: * adreno_cp_parse_ibn() - Wrapper function around IBn parsing 305: * @device: Device pointer 306: * @process: Process in which the IB is allocated 307: * @gpuaddr: IB gpuaddr 308: * @dwords: IB size in dwords 309: * @ibbase: Base address of active IB 310: * @ib_obj_list: List of objects found in IB 311: * @ib_level: The level from which function is called from IBn-1 312: * 313: * Function does some checks to ensure that IBn parsing is called from IBn-1 314: * and then calls the function to find objects in IBn. 315: */ 316: static int adreno_cp_parse_ibn(struct kgsl_device *device, 317: struct kgsl_process_private *process, 318: u64 gpuaddr, u64 dwords, u64 ibbase, 319: struct adreno_ib_object_list *ib_obj_list, 320: int ib_level) 321: { 322: int i; 323: 324: /* 325: * We can only expect an IBn in IBn-1, if we are 326: * already processing an IBn then return error 327: */ 328: if (ib_level >= IB_LEVEL_3) 329: return -EINVAL; 330: 331: /* Save current IBn statically */ 332: if (ibbase == gpuaddr) 333: kgsl_snapshot_push_object(device, process, gpuaddr, dwords); 334: /* 335: * Only try to find sub objects if this IBn has 336: * not been processed already 337: */ 338: for (i = 0; i < ib_obj_list->num_objs; i++) { 339: struct adreno_ib_object *ib_obj = &(ib_obj_list->obj_list[i]); 340: 341: if ((ib_obj->snapshot_obj_type == SNAPSHOT_GPU_OBJECT_IB) && 342: (gpuaddr >= ib_obj->gpuaddr) && 343: (gpuaddr + dwords * sizeof(unsigned int) <= 344: ib_obj->gpuaddr + ib_obj->size)) 345: return 0; 346: } 347: 348: return adreno_ib_find_objs(device, process, gpuaddr, dwords, ibbase, 349: SNAPSHOT_GPU_OBJECT_IB, ib_obj_list, ib_level + 1); 350: } 351: 352: static s64 get_ib_base(struct adreno_device *adreno_dev, int ib_level) 353: { 354: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 355: s64 ibbase = 0; 356: 357: switch (ib_level) { 358: case IB_LEVEL_2: 359: ibbase = metadata.ib2base; 360: break; 361: case IB_LEVEL_3: 362: if (!adreno_is_a5xx(adreno_dev) && !adreno_is_a6xx(adreno_dev)) 363: ibbase = metadata.ib3base; 364: break; 365: default: 366: /* Invalid IB level */ 367: dev_err(device->dev, "Invalid IB level %d\n", ib_level); 368: return -EINVAL; 369: } 370: 371: return ibbase; 372: } 373: 374: /* 375: * adreno_ib_find_objs() - Find all IB objects in a given IB 376: * @device: The device pointer on which the IB executes 377: * @process: The process in which the IB and all contained objects are mapped. 378: * @gpuaddr: The gpu address of the IB 379: * @ib2base: IB2 base address 380: * @dwords: Size of ib in dwords 381: * @obj_type: The object type can be either an IB or a draw state sequence 382: * @ib_obj_list: The list in which the IB and the objects in it are added. 383: * @ib_level: Indicates if IB1 or IB2 is being processed 384: * 385: * Finds all IB objects in a given IB and puts then in a list. Can be called 386: * recursively for the IBn in the IBn-1 387: * Returns 0 on success else error code 388: */ 389: static int adreno_ib_find_objs(struct kgsl_device *device, 390: struct kgsl_process_private *process, 391: uint64_t gpuaddr, uint64_t dwords, 392: uint64_t ib2base, int obj_type, 393: struct adreno_ib_object_list *ib_obj_list, 394: int ib_level) 395: { 396: int ret = 0; 397: uint64_t rem = dwords; 398: int i; 399: struct ib_parser_variables ib_parse_vars; 400: unsigned int *src; 401: struct adreno_ib_object *ib_obj; 402: struct kgsl_mem_entry *entry; 403: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 404: 405: /* check that this IB is not already on list */ 406: for (i = 0; i < ib_obj_list->num_objs; i++) { 407: ib_obj = &(ib_obj_list->obj_list[i]); 408: if ((obj_type == ib_obj->snapshot_obj_type) && 409: (ib_obj->gpuaddr <= gpuaddr) && 410: ((ib_obj->gpuaddr + ib_obj->size) >= 411: (gpuaddr + (dwords << 2)))) 412: return 0; 413: } 414: 415: entry = kgsl_sharedmem_find(process, gpuaddr); 416: if (!entry) 417: return -EINVAL; 418: 419: if (!kgsl_gpuaddr_in_memdesc(&entry->memdesc, gpuaddr, (dwords << 2))) { 420: kgsl_mem_entry_put(entry); 421: return -EINVAL; 422: } 423: 424: src = kgsl_gpuaddr_to_vaddr(&entry->memdesc, gpuaddr); 425: if (!src) { 426: kgsl_mem_entry_put(entry); 427: return -EINVAL; 428: } 429: 430: memset(&ib_parse_vars, 0, sizeof(struct ib_parser_variables)); 431: 432: ret = adreno_ib_add(process, gpuaddr, obj_type, ib_obj_list); 433: if (ret) 434: goto done; 435: 436: for (i = 0; rem > 0; rem--, i++) { 437: int pktsize; 438: unsigned int hdr = src[i]; 439: 440: if (pkt_is_type4(hdr)) 441: pktsize = type4_pkt_size(hdr); 442: else if (pkt_is_type7(hdr)) 443: pktsize = type7_pkt_size(hdr); 444: 445: /* 446: * If the packet isn't a type 1, type 3, type 4 or type 7 then 447: * don't bother parsing it - it is likely corrupted 448: */ 449: else 450: break; 451: 452: /* Check if rem is less than pktsize before decrementing */ 453: if (rem < pktsize) 454: break; 455: 456: if (pkt_is_type7(hdr)) { 457: if (adreno_cmd_is_ib(adreno_dev, hdr)) { 458: u64 size = src[i + 3]; 459: u64 gpuaddribn = ((u64)(src[i + 2]) << 32) | src[i + 1]; 460: s64 next_ibbase = get_ib_base(adreno_dev, ib_level + IB_LEVEL_1); 461: 462: if (next_ibbase == -EINVAL) 463: goto done; 464: ret = adreno_cp_parse_ibn(device, process, 465: gpuaddribn, size, (u64)next_ibbase, ib_obj_list, ib_level); 466: if (ret) 467: goto done; 468: } else { 469: ret = ib_parse_type7(device, &src[i], pktsize, 470: process, ib_obj_list, 471: &ib_parse_vars); 472: if (ret) 473: goto done; 474: } 475: } 476: 477: i += pktsize; 478: rem -= pktsize; 479: } 480: 481: done: 482: /* 483: * For set draw objects there may not be a draw_indx packet at its end 484: * to signal that we need to save the found objects in it, so just save 485: * it here. 486: */ 487: if (!ret && SNAPSHOT_GPU_OBJECT_DRAW == obj_type) 488: ret = ib_add_type0_entries(device, process, ib_obj_list, 489: &ib_parse_vars); 490: 491: kgsl_memdesc_unmap(&entry->memdesc); 492: kgsl_mem_entry_put(entry); 493: return ret; 494: } 495: 496: 497: /* 498: * adreno_ib_create_object_list() - Find all the memory objects in IB 499: * @device: The device pointer on which the IB executes 500: * @process: The process in which the IB and all contained objects are mapped 501: * @gpuaddr: The gpu address of the IB 502: * @dwords: Size of ib in dwords 503: * @ib2base: Base address of active IB2 504: * @ib_obj_list: The list in which the IB and the objects in it are added. 505: * 506: * Find all the memory objects that an IB needs for execution and place 507: * them in a list including the IB. 508: * Returns the ib object list. On success 0 is returned, on failure error 509: * code is returned along with number of objects that was saved before 510: * error occurred. If no objects found then the list pointer is set to 511: * NULL. 512: */ 513: int adreno_ib_create_object_list(struct kgsl_device *device, 514: struct kgsl_process_private *process, 515: uint64_t gpuaddr, uint64_t dwords, uint64_t ib2base, 516: struct adreno_ib_object_list **out_ib_obj_list) 517: { 518: int ret = 0; 519: struct adreno_ib_object_list *ib_obj_list; 520: 521: if (!out_ib_obj_list) 522: return -EINVAL; 523: 524: *out_ib_obj_list = NULL; 525: 526: ib_obj_list = kzalloc(sizeof(*ib_obj_list), GFP_KERNEL); 527: if (!ib_obj_list) 528: return -ENOMEM; 529: 530: ib_obj_list->obj_list = vmalloc(MAX_IB_OBJS * 531: sizeof(struct adreno_ib_object)); 532: 533: if (!ib_obj_list->obj_list) { 534: kfree(ib_obj_list); 535: return -ENOMEM; 536: } 537: 538: ret = adreno_ib_find_objs(device, process, gpuaddr, dwords, ib2base, 539: SNAPSHOT_GPU_OBJECT_IB, ib_obj_list, IB_LEVEL_1); 540: 541: /* Even if there was an error return the remaining objects found */ 542: if (ib_obj_list->num_objs) 543: *out_ib_obj_list = ib_obj_list; 544: 545: return ret; 546: } 547: 548: /* 549: * adreno_ib_destroy_obj_list() - Destroy an ib object list 550: * @ib_obj_list: List to destroy 551: * 552: * Free up all resources used by an ib_obj_list 553: */ 554: void adreno_ib_destroy_obj_list(struct adreno_ib_object_list *ib_obj_list) 555: { 556: int i; 557: 558: if (!ib_obj_list) 559: return; 560: 561: for (i = 0; i < ib_obj_list->num_objs; i++) { 562: if (ib_obj_list->obj_list[i].entry) --- FILE: \adreno_cp_parser.h | HITS: 7 --- MATCH LINES: 15, 21 3: * Copyright (c) 2013-2014, 2017, 2019, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #ifndef __ADRENO_IB_PARSER__ 8: #define __ADRENO_IB_PARSER__ 9: 10: #include "adreno.h" 11: 12: /* 13: * struct adreno_ib_object - Structure containing information about an 14: * address range found in an IB 15: * @gpuaddr: The starting gpuaddress of the range 16: * @size: Size of the range 17: * @snapshot_obj_type - Type of range used in snapshot 18: * @entry: The memory entry in which this range is found 19: */ 20: struct adreno_ib_object { 21: uint64_t gpuaddr; 22: uint64_t size; 23: int snapshot_obj_type; 24: struct kgsl_mem_entry *entry; 25: }; 26: 27: /* 28: * struct adreno_ib_object_list - List of address ranges found in IB 29: * @obj_list: The address range list 30: * @num_objs: Number of objects in list 31: */ 32: struct adreno_ib_object_list { 33: struct adreno_ib_object *obj_list; 34: int num_objs; 35: }; 36: 37: /* 38: * adreno registers used during IB parsing, there contain addresses 39: * and sizes of the addresses that present in an IB 40: */ 41: enum adreno_cp_addr_regs { 42: ADRENO_CP_ADDR_VSC_PIPE_DATA_ADDRESS_0 = 0, 43: ADRENO_CP_ADDR_VSC_PIPE_DATA_LENGTH_0, 44: ADRENO_CP_ADDR_VSC_PIPE_DATA_ADDRESS_1, 45: ADRENO_CP_ADDR_VSC_PIPE_DATA_LENGTH_1, MATCH LINES: 100, 101, 107, 112, 121 88: ADRENO_CP_ADDR_VFD_FETCH_INSTR_1_30, 89: ADRENO_CP_ADDR_VFD_FETCH_INSTR_1_31, 90: ADRENO_CP_ADDR_VSC_SIZE_ADDRESS, 91: ADRENO_CP_ADDR_SP_VS_PVT_MEM_ADDR, 92: ADRENO_CP_ADDR_SP_FS_PVT_MEM_ADDR, 93: ADRENO_CP_ADDR_SP_VS_OBJ_START_REG, 94: ADRENO_CP_ADDR_SP_FS_OBJ_START_REG, 95: ADRENO_CP_ADDR_MAX, 96: }; 97: 98: /* 99: * adreno_ib_init_ib_obj() - Create an ib object structure and initialize it 100: * with gpuaddress and size 101: * @gpuaddr: gpuaddr with which to initialize the object with 102: * @size: Size in bytes with which the object is initialized 103: * @ib_type: The IB type used by snapshot 104: * 105: * Returns the object pointer on success else error code in the pointer 106: */ 107: static inline void adreno_ib_init_ib_obj(uint64_t gpuaddr, 108: uint64_t size, int obj_type, 109: struct kgsl_mem_entry *entry, 110: struct adreno_ib_object *ib_obj) 111: { 112: ib_obj->gpuaddr = gpuaddr; 113: ib_obj->size = size; 114: ib_obj->snapshot_obj_type = obj_type; 115: ib_obj->entry = entry; 116: } 117: 118: int adreno_ib_create_object_list( 119: struct kgsl_device *device, 120: struct kgsl_process_private *process, 121: uint64_t gpuaddr, uint64_t dwords, uint64_t ib2base, 122: struct adreno_ib_object_list **out_ib_obj_list); 123: 124: void adreno_ib_destroy_obj_list(struct adreno_ib_object_list *ib_obj_list); 125: 126: #endif --- FILE: \adreno_debugfs.c | HITS: 8 --- MATCH LINES: 173, 179, 207, 216, 224, 225 161: 162: static int _gpu_client_pf_get(void *data, u64 *val) 163: { 164: struct kgsl_device *device = data; 165: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 166: 167: *val = (u64) adreno_dev->uche_client_pf; 168: return 0; 169: } 170: DEFINE_DEBUGFS_ATTRIBUTE(_gpu_client_pf_fops, _gpu_client_pf_get, 171: _gpu_client_pf_set, "%llu\n"); 172: 173: static int _prealloc_atomic_snap_mem_set(void *data, u64 val) 174: { 175: struct kgsl_device *device = data; 176: 177: kgsl_mutex_lock(&device->mutex); 178: 179: /* Allocate atomic snapshot memory if it's not allocated yet */ 180: if (!val || device->snapshot_memory_atomic.ptr) { 181: kgsl_mutex_unlock(&device->mutex); 182: return 0; 183: } 184: 185: device->snapshot_memory_atomic.size = device->snapshot_memory.size; 186: 187: /* Ensure size is visible to other threads before setting address */ 188: smp_wmb(); 189: 190: device->snapshot_memory_atomic.ptr = dma_alloc_coherent(&device->pdev->dev, 191: device->snapshot_memory_atomic.size, &device->snapshot_memory_atomic.dma_handle, 192: GFP_KERNEL); 193: 194: if (WARN_ON((!device->snapshot_memory_atomic.ptr))) { 195: /* Fallback to slab allocator if DMA allocation fails */ 196: device->snapshot_memory_atomic.size = (SZ_2M + SZ_1M); 197: 198: /* Ensure size is visible to other threads before setting address */ 199: smp_wmb(); 200: 201: device->snapshot_memory_atomic.ptr = devm_kzalloc(&device->pdev->dev, 202: device->snapshot_memory_atomic.size, GFP_KERNEL); 203: } 204: 205: if (!device->snapshot_memory_atomic.ptr) { 206: kgsl_mutex_unlock(&device->mutex); 207: dev_err(device->dev, "Failed to allocate memory for atomic snapshot\n"); 208: return -ENOMEM; 209: } 210: 211: kgsl_mutex_unlock(&device->mutex); 212: 213: return 0; 214: } 215: 216: static int _prealloc_atomic_snap_mem_get(void *data, u64 *val) 217: { 218: struct kgsl_device *device = data; 219: 220: *val = device->snapshot_memory_atomic.ptr ? 1 : 0; 221: return 0; 222: } 223: 224: DEFINE_DEBUGFS_ATTRIBUTE(_prealloc_atomic_snapshot_mem_fops, _prealloc_atomic_snap_mem_get, 225: _prealloc_atomic_snap_mem_set, "%llu\n"); 226: 227: typedef void (*reg_read_init_t)(struct kgsl_device *device); 228: typedef void (*reg_read_fill_t)(struct kgsl_device *device, int i, 229: unsigned int *vals, int linec); 230: 231: 232: static void sync_event_print(struct seq_file *s, 233: struct kgsl_drawobj_sync_event *sync_event) 234: { 235: switch (sync_event->type) { 236: case KGSL_CMD_SYNCPOINT_TYPE_TIMESTAMP: { 237: seq_printf(s, "sync: ctx: %u ts: %u", 238: sync_event->context->id, sync_event->timestamp); 239: break; 240: } 241: case KGSL_CMD_SYNCPOINT_TYPE_FENCE: { 242: int i; 243: struct event_fence_info *info = sync_event->priv; 244: 245: for (i = 0; info && i < info->num_fences; i++) 246: seq_printf(s, "sync: %s", 247: info->fences[i].name); 248: break; 249: } MATCH LINES: 850, 851 838: } 839: 840: if (ADRENO_FEATURE(adreno_dev, ADRENO_GMU_WARMBOOT)) 841: debugfs_create_file("warmboot", 0644, device->d_debugfs, 842: device, &warmboot_fops); 843: 844: debugfs_create_file("ctxt_record_size", 0644, snapshot_dir, 845: device, &_ctxt_record_size_fops); 846: debugfs_create_file("gpu_client_pf", 0644, snapshot_dir, 847: device, &_gpu_client_pf_fops); 848: debugfs_create_bool("dump_all_ibs", 0644, snapshot_dir, 849: &device->dump_all_ibs); 850: debugfs_create_file("prealloc_atomic_snapshot_mem", 0644, snapshot_dir, 851: device, &_prealloc_atomic_snapshot_mem_fops); 852: 853: adreno_dev->bcl_debugfs_dir = debugfs_create_dir("bcl", device->d_debugfs); 854: if (!IS_ERR_OR_NULL(adreno_dev->bcl_debugfs_dir)) { 855: debugfs_create_file("sid0", 0644, adreno_dev->bcl_debugfs_dir, device, &_sid0_fops); 856: debugfs_create_file("sid1", 0644, adreno_dev->bcl_debugfs_dir, device, &_sid1_fops); 857: debugfs_create_file("sid2", 0644, adreno_dev->bcl_debugfs_dir, device, &_sid2_fops); 858: debugfs_create_file("bcl_throttle_time_us", 0444, adreno_dev->bcl_debugfs_dir, 859: device, &_bcl_throttle_fops); 860: } 861: 862: adreno_dev->preemption_debugfs_dir = debugfs_create_dir("preemption", device->d_debugfs); 863: if (!IS_ERR_OR_NULL(adreno_dev->preemption_debugfs_dir)) { 864: debugfs_create_file("preempt_level", 0644, adreno_dev->preemption_debugfs_dir, 865: device, &preempt_level_fops); 866: debugfs_create_file("usesgmem", 0644, adreno_dev->preemption_debugfs_dir, device, 867: &usesgmem_fops); 868: debugfs_create_file("skipsaverestore", 0644, adreno_dev->preemption_debugfs_dir, 869: device, &skipsaverestore_fops); 870: } 871: 872: if (ADRENO_FEATURE(adreno_dev, ADRENO_GMU_BASED_DCVS)) 873: debugfs_create_file("host_based_dcvs", 0644, device->d_debugfs, 874: device, &host_based_dcvs_fops); 875: } --- FILE: \adreno_dispatch.c | HITS: 9 --- MATCH LINES: 119, 123 107: static void _retire_timestamp(struct kgsl_drawobj *drawobj) 108: { 109: struct kgsl_context *context = drawobj->context; 110: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 111: struct kgsl_device *device = context->device; 112: struct adreno_ringbuffer *rb = drawctxt->rb; 113: struct retire_info info = {0}; 114: 115: /* 116: * Write the start and end timestamp to the memstore to keep the 117: * accounting sane 118: */ 119: kgsl_sharedmem_writel(device->memstore, 120: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 121: drawobj->timestamp); 122: 123: kgsl_sharedmem_writel(device->memstore, 124: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 125: drawobj->timestamp); 126: 127: drawctxt->submitted_timestamp = drawobj->timestamp; 128: 129: /* Retire pending GPU events for the object */ 130: kgsl_process_event_group(device, &context->events); 131: 132: info.inflight = -1; 133: info.rb_id = rb->id; 134: info.wptr = rb->wptr; 135: info.timestamp = drawobj->timestamp; 136: 137: msm_perf_events_update(MSM_PERF_GFX, MSM_PERF_RETIRED, 138: pid_nr(context->proc_priv->pid), 139: context->id, drawobj->timestamp, 140: !!(drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME)); 141: 142: if (drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME) { 143: atomic64_inc(&context->proc_priv->frame_count); 144: atomic_inc(&context->proc_priv->period->frames); 145: } 146: 147: info.rptr = adreno_get_rptr(rb); MATCH LINES: 272 260: _retire_timestamp(drawobj); 261: return 0; 262: } 263: 264: if (!test_and_set_bit(KGSL_BINDOBJ_STATE_START, &bindobj->state)) { 265: /* 266: * Take a referencre to the drawobj and the context because both 267: * get referenced in the bind callback 268: */ 269: _kgsl_context_get(&drawctxt->base); 270: kref_get(&drawobj->refcount); 271: 272: kgsl_sharedmem_bind_ranges(bindobj->bind); 273: } 274: 275: return -EAGAIN; 276: } 277: 278: /* 279: * Retires all expired marker and sync objs from the context 280: * queue and returns one of the below 281: * a) next drawobj that needs to be sent to ringbuffer 282: * b) -EAGAIN for syncobj with syncpoints pending. 283: * c) -EAGAIN for markerobj whose marker timestamp has not expired yet. 284: * c) NULL for no commands remaining in drawqueue. 285: */ 286: static struct kgsl_drawobj *_process_drawqueue_get_next_drawobj( 287: struct adreno_context *drawctxt) 288: { 289: struct kgsl_drawobj *drawobj; 290: unsigned int i = drawctxt->drawqueue_head; 291: 292: if (drawctxt->drawqueue_head == drawctxt->drawqueue_tail) 293: return NULL; 294: 295: for (i = drawctxt->drawqueue_head; i != drawctxt->drawqueue_tail; 296: i = DRAWQUEUE_NEXT(i, ADRENO_CONTEXT_DRAWQUEUE_SIZE)) { MATCH LINES: 1324, 1333 1312: */ 1313: 1314: if (dispatch_q->inflight < _context_drawobj_burst) 1315: adreno_dispatcher_issuecmds(adreno_dev); 1316: done: 1317: if (test_and_clear_bit(ADRENO_CONTEXT_FAULT, &context->priv)) 1318: return -EPROTO; 1319: 1320: return 0; 1321: } 1322: 1323: /* 1324: * If an IB inside of the drawobj has a gpuaddr that matches the base 1325: * passed in then zero the size which effectively skips it when it is submitted 1326: * in the ringbuffer. 1327: */ 1328: static void _skip_ib(struct kgsl_drawobj_cmd *cmdobj, uint64_t base) 1329: { 1330: struct kgsl_memobj_node *ib; 1331: 1332: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 1333: if (ib->gpuaddr == base) { 1334: ib->priv |= MEMOBJ_SKIP; 1335: if (base) 1336: return; 1337: } 1338: } 1339: } 1340: 1341: static void _skip_cmd(struct kgsl_drawobj_cmd *cmdobj, 1342: struct kgsl_drawobj_cmd **replay, int count) 1343: { 1344: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 1345: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 1346: int i; 1347: 1348: /* 1349: * SKIPCMD policy: next IB issued for this context is tentative 1350: * if it fails we assume that GFT failed and if it succeeds 1351: * we mark GFT as a success. 1352: * 1353: * Find next commandbatch for the faulting context 1354: * If commandbatch is found 1355: * a) store the current commandbatch fault_policy in context's next 1356: * commandbatch fault_policy 1357: * b) force preamble for next commandbatch MATCH LINES: 1752 1740: static void recover_dispatch_q(struct kgsl_device *device, 1741: struct adreno_dispatcher_drawqueue *dispatch_q, 1742: int fault, 1743: unsigned int base) 1744: { 1745: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1746: struct kgsl_drawobj_cmd **replay; 1747: unsigned int ptr; 1748: int first = 0; 1749: int count = 0; 1750: int i; 1751: 1752: /* Allocate memory to store the inflight commands */ 1753: replay = kcalloc(dispatch_q->inflight, sizeof(*replay), GFP_KERNEL); 1754: 1755: if (replay == NULL) { 1756: unsigned int ptr = dispatch_q->head; 1757: 1758: /* Recovery failed - mark everybody on this q guilty */ 1759: while (ptr != dispatch_q->tail) { 1760: struct kgsl_drawobj_cmd *cmdobj = 1761: dispatch_q->cmd_q[ptr]; 1762: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 1763: 1764: adreno_drawctxt_set_guilty(device, drawobj->context); 1765: kgsl_drawobj_destroy(drawobj); 1766: 1767: ptr = DRAWQUEUE_NEXT(ptr, 1768: ADRENO_DISPATCH_DRAWQUEUE_SIZE); 1769: } 1770: 1771: /* 1772: * Set the replay count to zero - this will ensure that the 1773: * hardware gets reset but nothing else gets played 1774: */ 1775: 1776: count = 0; MATCH LINES: 1987 1975: else 1976: reg = 0x0; 1977: 1978: adreno_writereg(adreno_dev, ADRENO_REG_CP_ME_CNTL, reg); 1979: } 1980: /* 1981: * retire cmdobj's from all the dispatch_q's before starting recovery 1982: */ 1983: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1984: adreno_dispatch_retire_drawqueue(adreno_dev, 1985: &(rb->dispatch_q)); 1986: /* Select the active dispatch_q */ 1987: if (base == rb->buffer_desc->gpuaddr) { 1988: dispatch_q = &(rb->dispatch_q); 1989: hung_rb = rb; 1990: if (adreno_dev->cur_rb != hung_rb) { 1991: adreno_dev->prev_rb = adreno_dev->cur_rb; 1992: adreno_dev->cur_rb = hung_rb; 1993: } 1994: } 1995: } 1996: 1997: if (dispatch_q && !adreno_drawqueue_is_empty(dispatch_q)) { 1998: cmdobj = dispatch_q->cmd_q[dispatch_q->head]; 1999: trace_adreno_cmdbatch_fault(cmdobj, fault); 2000: } 2001: 2002: if (gx_on) 2003: adreno_readreg64(adreno_dev, ADRENO_REG_CP_IB1_BASE, 2004: ADRENO_REG_CP_IB1_BASE_HI, &base); 2005: 2006: if (!test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &device->mmu.pfpolicy) 2007: && adreno_dev->cooperative_reset) 2008: gmu_core_dev_cooperative_reset(device); 2009: 2010: if (!(fault & ADRENO_GMU_FAULT_SKIP_SNAPSHOT)) 2011: do_header_and_snapshot(device, fault, hung_rb, cmdobj); MATCH LINES: 2040, 2044 2028: 2029: /* Reset the GPU and make sure halt is not set during recovery */ 2030: halt = adreno_gpu_halt(adreno_dev); 2031: adreno_clear_gpu_halt(adreno_dev); 2032: 2033: /* 2034: * If there is a stall in the ringbuffer after all commands have been 2035: * retired then we could hit problems if contexts are waiting for 2036: * internal timestamps that will never retire 2037: */ 2038: 2039: if (hung_rb != NULL) { 2040: kgsl_sharedmem_writel(device->memstore, 2041: MEMSTORE_RB_OFFSET(hung_rb, soptimestamp), 2042: hung_rb->timestamp); 2043: 2044: kgsl_sharedmem_writel(device->memstore, 2045: MEMSTORE_RB_OFFSET(hung_rb, eoptimestamp), 2046: hung_rb->timestamp); 2047: 2048: /* Schedule any pending events to be run */ 2049: kgsl_process_event_group(device, &hung_rb->events); 2050: } 2051: 2052: ret = adreno_reset(device, fault); 2053: 2054: /* If adreno_reset() fails then what hope do we have for the future? */ 2055: BUG_ON(ret); 2056: 2057: /* if any other fault got in until reset then ignore */ 2058: adreno_clear_gpu_fault(adreno_dev); 2059: 2060: kgsl_mutex_unlock(&device->mutex); 2061: 2062: mutex_unlock(&adreno_dev->fault_recovery_mutex); 2063: 2064: /* recover all the dispatch_q's starting with the one that hung */ 2065: if (dispatch_q) 2066: recover_dispatch_q(device, dispatch_q, fault, base); 2067: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2068: dispatch_q_temp = &(rb->dispatch_q); --- FILE: \adreno_drawctxt.c | HITS: 11 --- MATCH LINES: 276, 280 264: trace_adreno_drawctxt_invalidate(drawctxt); 265: 266: spin_lock(&drawctxt->lock); 267: set_bit(KGSL_CONTEXT_PRIV_INVALID, &context->priv); 268: 269: if (!list_empty(&drawctxt->hw_fence_list)) 270: set_bit(KGSL_CONTEXT_PRIV_INVALID_DRAIN_HW_FENCE, &context->priv); 271: 272: /* 273: * set the timestamp to the last value since the context is invalidated 274: * and we want the pending events for this context to go away 275: */ 276: kgsl_sharedmem_writel(device->memstore, 277: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 278: drawctxt->timestamp); 279: 280: kgsl_sharedmem_writel(device->memstore, 281: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 282: drawctxt->timestamp); 283: 284: /* Get rid of commands still waiting in the queue */ 285: count = drawctxt_detach_drawobjs(drawctxt, list); 286: spin_unlock(&drawctxt->lock); 287: 288: for (i = 0; i < count; i++) { 289: kgsl_cancel_events_timestamp(device, &context->events, 290: list[i]->timestamp); 291: kgsl_drawobj_destroy(list[i]); 292: } 293: 294: /* Make sure all pending events are processed or cancelled */ 295: kgsl_flush_event_group(device, &context->events); 296: 297: /* Give the bad news to everybody waiting around */ 298: wake_up_all(&drawctxt->waiting); 299: wake_up_all(&drawctxt->wq); 300: wake_up_all(&drawctxt->timeout); 301: } 302: 303: void adreno_drawctxt_set_guilty(struct kgsl_device *device, 304: struct kgsl_context *context) MATCH LINES: 319, 325, 328, 329, 330 307: return; 308: 309: context->reset_status = KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT; 310: 311: adreno_drawctxt_invalidate(device, context); 312: } 313: 314: u32 adreno_prepare_preib_preempt_scratch(struct adreno_device *adreno_dev, 315: struct adreno_context *drawctxt, u32 *cmds) 316: { 317: struct adreno_ringbuffer *rb = drawctxt->rb; 318: u32 *cmds_orig = cmds; 319: u64 gpuaddr, dest; 320: 321: if (!drawctxt->base.user_ctxt_record) 322: return 0; 323: 324: dest = PREEMPT_SCRATCH_ADDR(adreno_dev, rb->id); 325: gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 326: 327: *cmds++ = cp_mem_packet(adreno_dev, CP_MEM_WRITE, 2, 2); 328: cmds += cp_gpuaddr(adreno_dev, cmds, dest); 329: *cmds++ = lower_32_bits(gpuaddr); 330: *cmds++ = upper_32_bits(gpuaddr); 331: 332: return (u32) (cmds - cmds_orig); 333: } 334: 335: u32 adreno_prepare_preib_postamble_scratch(struct adreno_device *adreno_dev, u32 *cmds) 336: { 337: u32 *cmds_orig = cmds; 338: u64 kmd_postamble_addr; 339: 340: if (!adreno_dev->preempt.postamble_len) 341: return 0; 342: 343: kmd_postamble_addr = SCRATCH_POSTAMBLE_ADDR(KGSL_DEVICE(adreno_dev)); 344: 345: *cmds++ = cp_type7_packet(CP_SET_AMBLE, 3); 346: *cmds++ = lower_32_bits(kmd_postamble_addr); 347: *cmds++ = upper_32_bits(kmd_postamble_addr); 348: *cmds++ = FIELD_PREP(GENMASK(22, 20), CP_KMD_AMBLE_TYPE) 349: | (FIELD_PREP(GENMASK(19, 0), adreno_dev->preempt.postamble_len)); 350: 351: return (u32) (cmds - cmds_orig); 352: } 353: 354: static int drawctxt_preemption_init(struct kgsl_context *context) MATCH LINES: 500, 503 488: /* 489: * Now initialize the common part of the context. This allocates the 490: * context id, and then possibly another thread could look it up. 491: * So we want all of our initializtion that doesn't require the context 492: * id to be done before this call. 493: */ 494: ret = kgsl_context_init(dev_priv, &drawctxt->base); 495: if (ret != 0) { 496: kfree(drawctxt); 497: return ERR_PTR(ret); 498: } 499: 500: kgsl_sharedmem_writel(device->memstore, 501: KGSL_MEMSTORE_OFFSET(drawctxt->base.id, soptimestamp), 502: 0); 503: kgsl_sharedmem_writel(device->memstore, 504: KGSL_MEMSTORE_OFFSET(drawctxt->base.id, eoptimestamp), 505: 0); 506: 507: adreno_context_debugfs_init(ADRENO_DEVICE(device), drawctxt); 508: 509: INIT_LIST_HEAD(&drawctxt->active_node); 510: INIT_LIST_HEAD(&drawctxt->hw_fence_list); 511: INIT_LIST_HEAD(&drawctxt->hw_fence_inflight_list); 512: 513: if (adreno_dev->dispatch_ops && adreno_dev->dispatch_ops->setup_context) { 514: ret = adreno_dev->dispatch_ops->setup_context(adreno_dev, drawctxt); 515: if (ret) { 516: dev_err_ratelimited(device->dev, 517: "Context initialization failed ret:%d\n", ret); 518: kgsl_context_detach(&drawctxt->base); 519: return ERR_PTR(ret); 520: } 521: } 522: 523: ret = drawctxt_preemption_init(&drawctxt->base); 524: if (ret) { 525: kgsl_context_detach(&drawctxt->base); 526: return ERR_PTR(ret); 527: } MATCH LINES: 587, 591 575: kgsl_mutex_unlock(&device->mutex); 576: 577: /* Schedule dispatcher to kick in recovery */ 578: adreno_scheduler_queue(adreno_dev); 579: 580: /* Wait for context to be invalidated and release context */ 581: wait_event_interruptible_timeout(drawctxt->timeout, 582: kgsl_context_invalid(&drawctxt->base), 583: msecs_to_jiffies(5000)); 584: return; 585: } 586: 587: kgsl_sharedmem_writel(device->memstore, 588: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 589: drawctxt->timestamp); 590: 591: kgsl_sharedmem_writel(device->memstore, 592: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 593: drawctxt->timestamp); 594: 595: adreno_profile_process_results(adreno_dev); 596: 597: kgsl_mutex_unlock(&device->mutex); 598: } 599: 600: void adreno_drawctxt_detach(struct kgsl_context *context) 601: { 602: struct kgsl_device *device; 603: struct adreno_device *adreno_dev; 604: const struct adreno_gpudev *gpudev; 605: struct adreno_context *drawctxt; 606: int count, i; 607: struct kgsl_drawobj *list[ADRENO_CONTEXT_DRAWQUEUE_SIZE]; 608: 609: if (context == NULL) 610: return; 611: 612: device = context->device; 613: adreno_dev = ADRENO_DEVICE(device); 614: gpudev = ADRENO_GPU_DEVICE(adreno_dev); 615: drawctxt = ADRENO_CONTEXT(context); --- FILE: \adreno_drawctxt.h | HITS: 2 --- MATCH LINES: 80, 82 68: int queued; 69: unsigned int fault_policy; 70: struct dentry *debug_root; 71: unsigned int queued_timestamp; 72: struct adreno_ringbuffer *rb; 73: unsigned int submitted_timestamp; 74: uint64_t submit_retire_ticks[SUBMIT_RETIRE_TICKS_SIZE]; 75: int ticks_index; 76: 77: struct list_head active_node; 78: unsigned long active_time; 79: /** @gmu_context_queue: Queue to dispatch submissions to GMU */ 80: struct kgsl_memdesc gmu_context_queue; 81: /** @gmu_hw_fence_queue: Queue for GMU to store hardware fences for this context */ 82: struct kgsl_memdesc gmu_hw_fence_queue; 83: /** @hw_fence_list: List of hardware fences(sorted by timestamp) not yet submitted to GMU */ 84: struct list_head hw_fence_list; 85: /** @hw_fence_inflight_list: List of hardware fences submitted to GMU */ 86: struct list_head hw_fence_inflight_list; 87: /** @hw_fence_count: Number of hardware fences not yet sent to Tx Queue */ 88: u32 hw_fence_count; 89: /** @syncobj_timestamp: Timestamp to check whether GMU has consumed a syncobj */ 90: u32 syncobj_timestamp; 91: /** 92: * @gmu_hw_fence_ready_ts: This timestamp is used to figure out whether a hardware fence 93: * is ready to be submitted to GMU at the time of its creation or not. This timestamp 94: * tracks the timestamp of the most recently submitted cmdbatch submission to the GMU 95: * context queue for this context. This is different from the internal_timestamp (which gets 96: * reset to 0 in some cases). 97: */ 98: u32 gmu_hw_fence_ready_ts; 99: /** 100: * @hw_fence_last_ts: This tracks the latest timestamp for which a hw fence was created. 101: * This is used to figure out if a new fence has an out-of-order timestamp. 102: */ 103: u32 hw_fence_last_ts; 104: }; 105: 106: /* Flag definitions for flag field in adreno_context */ --- FILE: \adreno_gen7.c | HITS: 14 --- MATCH LINES: 286, 287 274: if (!adreno_dev->dms_enabled) 275: mask |= BIT(11); 276: 277: cmds[i++] = cp_type7_packet(CP_ME_INIT, 7); 278: 279: /* Enabled ordinal mask */ 280: cmds[i++] = mask; 281: cmds[i++] = 0x00000003; /* Set number of HW contexts */ 282: cmds[i++] = 0x20000000; /* Enable error detection */ 283: cmds[i++] = 0x00000002; /* Operation mode mask */ 284: 285: /* Register initialization list with spinlock */ 286: cmds[i++] = lower_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 287: cmds[i++] = upper_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 288: /* 289: * Gen7 targets with concurrent binning are expected to have a dynamic 290: * power up list with triplets which contains the pipe id in it. 291: * Bit 31 of POWER_UP_REGISTER_LIST_LENGTH is reused here to let CP 292: * know if the power up contains the triplets. If 293: * REGISTER_INIT_LIST_WITH_SPINLOCK is set and bit 31 below is set, 294: * CP expects a dynamic list with triplets. 295: */ 296: cmds[i++] = BIT(31); 297: } 298: 299: int gen7_fenced_write(struct adreno_device *adreno_dev, u32 offset, 300: u32 value, u32 mask) 301: { 302: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 303: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 304: unsigned int status, i; 305: u64 ts1, ts2; 306: 307: kgsl_regwrite(device, offset, value); 308: ts1 = gpudev->read_alwayson(adreno_dev); 309: for (i = 0; i < GMU_CORE_LONG_WAKEUP_RETRY_LIMIT; i++) { 310: /* 311: * Make sure the previous register write is posted before MATCH LINES: 393 381: adreno_dev->ahb_timeout_val = adreno_get_ahb_timeout_val(adreno_dev, 382: gen7_core->noc_timeout_us); 383: adreno_dev->bcl_data = gen7_core->bcl_data; 384: 385: adreno_dev->cooperative_reset = ADRENO_FEATURE(adreno_dev, 386: ADRENO_COOP_RESET); 387: 388: gen7_calc_ubwc_config(adreno_dev); 389: 390: gen7_crashdump_init(adreno_dev); 391: 392: return adreno_allocate_global(device, &adreno_dev->pwrup_reglist, 393: PAGE_SIZE, 0, 0, KGSL_MEMDESC_PRIVILEGED, 394: "powerup_register_list"); 395: } 396: 397: #define CX_TIMER_INIT_SAMPLES 16 398: void gen7_cx_timer_init(struct adreno_device *adreno_dev) 399: { 400: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 401: u64 seed_val, tmr, skew = 0; 402: int i; 403: unsigned long flags; 404: 405: /* 406: * Only gen7_9_x has the CX timer. Set it up during first boot or 407: * after suspend resume. 408: */ 409: if (!adreno_is_gen7_9_x(adreno_dev) || 410: test_bit(ADRENO_DEVICE_CX_TIMER_INITIALIZED, &adreno_dev->priv)) 411: return; 412: 413: /* Disable irqs to get accurate timings */ 414: local_irq_save(flags); 415: 416: /* Calculate the overhead of timer reads and register writes */ 417: for (i = 0; i < CX_TIMER_INIT_SAMPLES; i++) { MATCH LINES: 1088 1076: /* 1077: * Enable hardware clock gating here to prevent any register access 1078: * issue due to internal clock gating. 1079: */ 1080: gen7_hwcg_set(adreno_dev, true); 1081: 1082: /* 1083: * All registers must be written before this point so that we don't 1084: * miss any register programming when we patch the power up register 1085: * list. 1086: */ 1087: if (!adreno_dev->patch_reglist && 1088: (adreno_dev->pwrup_reglist->gpuaddr != 0)) { 1089: gen7_patch_pwrup_reglist(adreno_dev); 1090: adreno_dev->patch_reglist = true; 1091: } 1092: 1093: return 0; 1094: } 1095: 1096: int gen7_scm_gpu_init_cx_regs(struct adreno_device *adreno_dev) 1097: { 1098: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1099: u32 gpu_req = GPU_ALWAYS_EN_REQ; 1100: int ret; 1101: 1102: if (ADRENO_FEATURE(adreno_dev, ADRENO_BCL)) 1103: gpu_req |= GPU_BCL_EN_REQ; 1104: 1105: if (ADRENO_FEATURE(adreno_dev, ADRENO_CLX)) 1106: gpu_req |= GPU_CLX_EN_REQ; 1107: 1108: if (adreno_is_gen7_9_x(adreno_dev)) 1109: gpu_req |= GPU_TSENSE_EN_REQ; 1110: 1111: ret = kgsl_scm_gpu_init_regs(&device->pdev->dev, gpu_req, 1112: adreno_dev->zap_enabled); MATCH LINES: 1223, 1224, 1228, 1229 1211: count += 3; 1212: 1213: if (preempt->postamble_bootup_len) 1214: count += 4; 1215: 1216: cmds = adreno_ringbuffer_allocspace(rb, count); 1217: if (IS_ERR(cmds)) 1218: return PTR_ERR(cmds); 1219: 1220: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 1221: kgsl_mmu_is_secured(&device->mmu) ? 6 : 3); 1222: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 1223: *cmds++ = lower_32_bits(rb->preemption_desc->gpuaddr); 1224: *cmds++ = upper_32_bits(rb->preemption_desc->gpuaddr); 1225: 1226: if (kgsl_mmu_is_secured(&device->mmu)) { 1227: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 1228: *cmds++ = lower_32_bits(rb->secure_preemption_desc->gpuaddr); 1229: *cmds++ = upper_32_bits(rb->secure_preemption_desc->gpuaddr); 1230: } 1231: 1232: if (preempt->postamble_bootup_len) { 1233: *cmds++ = cp_type7_packet(CP_SET_AMBLE, 3); 1234: *cmds++ = lower_32_bits(kmd_postamble_addr); 1235: *cmds++ = upper_32_bits(kmd_postamble_addr); 1236: *cmds++ = FIELD_PREP(GENMASK(22, 20), CP_KMD_AMBLE_TYPE) 1237: | (FIELD_PREP(GENMASK(19, 0), adreno_dev->preempt.postamble_bootup_len)); 1238: } 1239: 1240: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 1241: *cmds++ = 0; 1242: *cmds++ = 0; 1243: *cmds++ = 0; 1244: /* generate interrupt on preemption completion */ 1245: *cmds++ = 0; 1246: 1247: ret = gen7_ringbuffer_submit(rb, NULL); 1248: if (!ret) { 1249: ret = adreno_spin_idle(adreno_dev, 2000); 1250: if (ret) 1251: gen7_spin_idle_debug(adreno_dev, 1252: "hw preemption initialization failed to idle\n"); 1253: } MATCH LINES: 1271, 1273, 1300, 1302, 1306, 1308 1259: { 1260: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 1261: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 1262: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1263: struct adreno_ringbuffer *rb; 1264: u64 addr; 1265: int ret, i; 1266: unsigned int *cmds; 1267: 1268: /* Clear all the ringbuffers */ 1269: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1270: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 1271: kgsl_sharedmem_writel(device->scratch, 1272: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 1273: kgsl_sharedmem_writel(device->scratch, 1274: SCRATCH_RB_OFFSET(rb->id, bv_rptr), 0); 1275: 1276: rb->wptr = 0; 1277: rb->_wptr = 0; 1278: rb->wptr_preempt_end = UINT_MAX; 1279: } 1280: 1281: gen7_preemption_start(adreno_dev); 1282: 1283: /* Set up the current ringbuffer */ 1284: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 1285: 1286: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 1287: kgsl_regwrite(device, GEN7_CP_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1288: kgsl_regwrite(device, GEN7_CP_RB_RPTR_ADDR_HI, upper_32_bits(addr)); 1289: 1290: /* Skip this regwrite for Gen7 targets that do not have BV */ 1291: if (!adreno_is_gen7_no_cb_family(adreno_dev)) { 1292: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, bv_rptr); 1293: kgsl_regwrite(device, GEN7_CP_BV_RB_RPTR_ADDR_LO, lower_32_bits(addr)); 1294: kgsl_regwrite(device, GEN7_CP_BV_RB_RPTR_ADDR_HI, upper_32_bits(addr)); 1295: } 1296: 1297: kgsl_regwrite(device, GEN7_CP_RB_CNTL, GEN7_CP_RB_CNTL_DEFAULT); 1298: 1299: kgsl_regwrite(device, GEN7_CP_RB_BASE, 1300: lower_32_bits(rb->buffer_desc->gpuaddr)); 1301: kgsl_regwrite(device, GEN7_CP_RB_BASE_HI, 1302: upper_32_bits(rb->buffer_desc->gpuaddr)); 1303: 1304: /* Program the ucode base for CP */ 1305: kgsl_regwrite(device, GEN7_CP_SQE_INSTR_BASE_LO, 1306: lower_32_bits(fw->memdesc->gpuaddr)); 1307: kgsl_regwrite(device, GEN7_CP_SQE_INSTR_BASE_HI, 1308: upper_32_bits(fw->memdesc->gpuaddr)); 1309: 1310: /* Clear the SQE_HALT to start the CP engine */ 1311: kgsl_regwrite(device, GEN7_CP_SQE_CNTL, 1); 1312: 1313: ret = gen7_send_cp_init(adreno_dev, rb); 1314: if (ret) 1315: return ret; 1316: 1317: ret = adreno_zap_shader_load(adreno_dev, gen7_core->zap_name); 1318: if (ret) 1319: return ret; 1320: 1321: /* 1322: * Take the GPU out of secure mode. Try the zap shader if it is loaded, 1323: * otherwise just try to write directly to the secure control register 1324: */ 1325: if (!adreno_dev->zap_loaded) 1326: kgsl_regwrite(device, GEN7_RBBM_SECVID_TRUST_CNTL, 0); 1327: else { 1328: cmds = adreno_ringbuffer_allocspace(rb, 2); 1329: if (IS_ERR(cmds)) 1330: return PTR_ERR(cmds); 1331: 1332: *cmds++ = cp_type7_packet(CP_SET_SECURE_MODE, 1); --- FILE: \adreno_gen7_gmu.c | HITS: 2 --- MATCH LINES: 527, 528 515: 516: if (id == GMU_ITCM) { 517: load_tcm(adreno_dev, fw, 518: GEN7_GMU_CM3_ITCM_START, 519: device->gmu_core.vma[GMU_ITCM].start, blk); 520: } else if (id == GMU_DTCM) { 521: load_tcm(adreno_dev, fw, 522: GEN7_GMU_CM3_DTCM_START, 523: device->gmu_core.vma[GMU_DTCM].start, blk); 524: } else { 525: /* The firmware block for memory needs to be copied on first boot only */ 526: if (!test_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags)) { 527: struct kgsl_memdesc *md = 528: gmu_core_find_memdesc(device, blk->addr, blk->size); 529: 530: if (!md) { 531: dev_err(GMU_PDEV_DEV(device), 532: "No backing memory for GMU FW block addr:0x%x size:0x%x\n", 533: blk->addr, blk->size); 534: return -EINVAL; 535: } 536: 537: memcpy(md->hostptr + (blk->addr - md->gmuaddr), fw, 538: blk->size); 539: } 540: } 541: 542: fw += blk->size; 543: } 544: 545: /* Proceed only after the FW is written */ 546: wmb(); 547: return 0; 548: } 549: 550: static const char *oob_to_str(enum oob_request req) 551: { 552: switch (req) { --- FILE: \adreno_gen7_gmu.h | HITS: 4 --- MATCH LINES: 36, 38, 40 24: * @ver: GMU Version information 25: * @irq: GMU interrupt number 26: * @fw_image: GMU FW image 27: * @gmu_log: gmu event log memory 28: * @hfi: HFI controller 29: * @idle_level: Minimal GPU idle power level 30: * @mailbox: Messages to AOP for ACD enable/disable go through this 31: * @log_wptr_retention: Store the log wptr offset on slumber 32: */ 33: struct gen7_gmu_device { 34: int irq; 35: const struct firmware *fw_image; 36: struct kgsl_memdesc *gmu_log; 37: /** @gmu_init_scratch: Memory to store the initial HFI messages */ 38: struct kgsl_memdesc *gmu_init_scratch; 39: /** @gpu_boot_scratch: Memory to store the bootup HFI messages */ 40: struct kgsl_memdesc *gpu_boot_scratch; 41: struct gen7_hfi hfi; 42: unsigned int idle_level; 43: /** @qmp: Pointer to qmp struct used for AOP messages*/ 44: struct qmp *qmp; 45: struct kgsl_mailbox mailbox; 46: unsigned int log_wptr_retention; 47: /** @cm3_fault: whether gmu received a cm3 fault interrupt */ 48: atomic_t cm3_fault; 49: /** 50: * @itcm_shadow: Copy of the itcm block in firmware binary used for 51: * snapshot 52: */ 53: void *itcm_shadow; 54: /** @flags: Internal gmu flags */ 55: unsigned long flags; 56: /** @rscc_virt: Pointer where RSCC block is mapped */ 57: void __iomem *rscc_virt; 58: /** @log_stream_enable: GMU log streaming enable. Disabled by default */ 59: bool log_stream_enable; 60: /** @log_group_mask: Allows overriding default GMU log group mask */ 61: u32 log_group_mask; 62: struct kobject log_kobj; 63: /** @pdc_cfg_base: Base address of PDC cfg registers */ 64: void __iomem *pdc_cfg_base; MATCH LINES: 173 161: int gen7_gmu_probe(struct kgsl_device *device, 162: struct platform_device *pdev); 163: 164: /** 165: * gen7_gmu_parse_fw - Parse the gmu fw binary 166: * @adreno_dev: Pointer to the adreno device 167: * 168: * Return: 0 on success or negative error on failure 169: */ 170: int gen7_gmu_parse_fw(struct adreno_device *adreno_dev); 171: 172: /** 173: * gen7_gmu_memory_init - Allocate gmu memory 174: * @adreno_dev: Pointer to the adreno device 175: * 176: * Allocates the gmu log buffer and others if ndeeded. 177: * 178: * Return: 0 on success or negative error on failure 179: */ 180: int gen7_gmu_memory_init(struct adreno_device *adreno_dev); 181: 182: /** 183: * gen7_gmu_aop_send_acd_state - Enable or disable acd feature in aop 184: * @gmu: Pointer to the gen7 gmu device 185: * @flag: Boolean to enable or disable acd in aop 186: * 187: * This function enables or disables gpu acd feature using mailbox or qmp 188: */ 189: void gen7_gmu_aop_send_acd_state(struct gen7_gmu_device *gmu, bool flag); 190: 191: /** 192: * gen7_gmu_load_fw - Load gmu firmware 193: * @adreno_dev: Pointer to the adreno device 194: * 195: * Loads the gmu firmware binary into TCMs and memory 196: * 197: * Return: 0 on success or negative error on failure --- FILE: \adreno_gen7_gmu_snapshot.c | HITS: 4 --- MATCH LINES: 36 24: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 25: u32 *data = (u32 *)(buf + sizeof(*mem_hdr)); 26: u32 i; 27: 28: if (remain < gmu_core->vma[GMU_DTCM].size + sizeof(*mem_hdr)) { 29: SNAPSHOT_ERR_NOMEM(device, "GMU DTCM Memory"); 30: return 0; 31: } 32: 33: mem_hdr->type = SNAPSHOT_GMU_MEM_BIN_BLOCK; 34: mem_hdr->hostaddr = 0; 35: mem_hdr->gmuaddr = gmu_core->vma[GMU_DTCM].start; 36: mem_hdr->gpuaddr = 0; 37: 38: /* 39: * Read of GMU TCMs over side-band debug controller interface is 40: * supported on gen7_2_x family 41: */ 42: if (adreno_is_gen7_2_x_family(adreno_dev)) { 43: /* 44: * region [20]: Dump ITCM/DTCM. Select 1 for DTCM. 45: * autoInc [31]: Autoincrement the address field after each 46: * access to TCM_DBG_DATA 47: */ 48: kgsl_regwrite(device, GEN7_CX_DBGC_TCM_DBG_ADDR, BIT(20) | BIT(31)); 49: 50: for (i = 0; i < (gmu_core->vma[GMU_DTCM].size >> 2); i++) 51: kgsl_regread(device, GEN7_CX_DBGC_TCM_DBG_DATA, data++); 52: } else { 53: for (i = 0; i < (gmu_core->vma[GMU_DTCM].size >> 2); i++) 54: gmu_core_regread(device, GEN7_GMU_CM3_DTCM_START + i, data++); 55: } 56: 57: return gmu_core->vma[GMU_DTCM].size + sizeof(*mem_hdr); 58: } 59: 60: static size_t gen7_gmu_snapshot_itcm(struct kgsl_device *device, MATCH LINES: 83, 94, 104 71: "No memory allocated for ITCM shadow capture\n"); 72: return 0; 73: } 74: 75: if (remain < gmu_core->vma[GMU_ITCM].size + sizeof(*mem_hdr)) { 76: SNAPSHOT_ERR_NOMEM(device, "GMU ITCM Memory"); 77: return 0; 78: } 79: 80: mem_hdr->type = SNAPSHOT_GMU_MEM_BIN_BLOCK; 81: mem_hdr->hostaddr = 0; 82: mem_hdr->gmuaddr = gmu_core->vma[GMU_ITCM].start; 83: mem_hdr->gpuaddr = 0; 84: 85: memcpy(dest, gmu->itcm_shadow, gmu_core->vma[GMU_ITCM].size); 86: 87: return gmu_core->vma[GMU_ITCM].size + sizeof(*mem_hdr); 88: } 89: 90: static void gen7_gmu_snapshot_memories(struct kgsl_device *device, 91: struct gen7_gmu_device *gmu, struct kgsl_snapshot *snapshot) 92: { 93: struct gmu_mem_type_desc desc; 94: struct kgsl_memdesc *md; 95: struct gmu_core_device *gmu_core = &device->gmu_core; 96: int i; 97: 98: for (i = 0; i < ARRAY_SIZE(gmu_core->gmu_globals); i++) { 99: 100: md = &gmu_core->gmu_globals[i]; 101: if (!md->size) 102: continue; 103: 104: desc.memdesc = md; 105: if (md == gmu->hfi.hfi_mem) 106: desc.type = SNAPSHOT_GMU_MEM_HFI; 107: else if (md == gmu->gmu_log) 108: desc.type = SNAPSHOT_GMU_MEM_LOG; 109: else if ((md == gmu->gmu_init_scratch) || (md == gmu->gpu_boot_scratch)) 110: desc.type = SNAPSHOT_GMU_MEM_WARMBOOT; 111: else if (md == gmu_core->vrb) 112: desc.type = SNAPSHOT_GMU_MEM_VRB; 113: else if (md == gmu_core->trace.md) 114: desc.type = SNAPSHOT_GMU_MEM_TRACE; 115: else 116: desc.type = SNAPSHOT_GMU_MEM_BIN_BLOCK; 117: 118: kgsl_snapshot_add_section(device, 119: KGSL_SNAPSHOT_SECTION_GMU_MEMORY, 120: snapshot, adreno_snapshot_gmu_mem, &desc); 121: } 122: } 123: 124: #define RSCC_OFFSET_DWORDS 0x14000 125: 126: static size_t gen7_snapshot_rscc_registers(struct kgsl_device *device, u8 *buf, 127: size_t remain, void *priv) 128: { --- FILE: \adreno_gen7_hfi.c | HITS: 4 --- MATCH LINES: 39 27: struct gen7_hfi *to_gen7_hfi(struct adreno_device *adreno_dev) 28: { 29: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 30: 31: return &gmu->hfi; 32: } 33: 34: /* Size in below functions are in unit of dwords */ 35: int gen7_hfi_queue_read(struct gen7_gmu_device *gmu, u32 queue_idx, 36: unsigned int *output, unsigned int max_size) 37: { 38: struct kgsl_device *device = KGSL_DEVICE(gen7_gmu_to_adreno(gmu)); 39: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 40: struct hfi_queue_table *tbl = mem_addr->hostptr; 41: struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx]; 42: u32 *queue; 43: u32 msg_hdr; 44: u32 i, read; 45: u32 size; 46: int result = 0; 47: 48: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 49: return -EINVAL; 50: 51: if (hdr->read_index == hdr->write_index) 52: return -ENODATA; 53: 54: /* Clear the output data before populating */ 55: memset(output, 0, max_size); 56: 57: queue = HOST_QUEUE_START_ADDR(mem_addr, queue_idx); 58: msg_hdr = queue[hdr->read_index]; 59: size = MSG_HDR_GET_SIZE(msg_hdr); 60: 61: if (size > (max_size >> 2)) { 62: dev_err(GMU_PDEV_DEV(device), 63: "HFI message too big: hdr:0x%x rd idx=%d\n", MATCH LINES: 186 174: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), 175: GEN7_GMU_HOST2GMU_INTR_SET, 0x1); 176: 177: spin_unlock(&hfi->cmdq_lock); 178: 179: return ret; 180: } 181: 182: /* Sizes of the queue and message are in unit of dwords */ 183: static void init_queues(struct adreno_device *adreno_dev) 184: { 185: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 186: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 187: int i; 188: struct hfi_queue_table *tbl; 189: struct hfi_queue_header *hdr; 190: struct { 191: unsigned int idx; 192: unsigned int pri; 193: unsigned int status; 194: } queue[HFI_QUEUE_MAX] = { 195: { HFI_CMD_ID, HFI_CMD_PRI, HFI_QUEUE_STATUS_ENABLED }, 196: { HFI_MSG_ID, HFI_MSG_PRI, HFI_QUEUE_STATUS_ENABLED }, 197: { HFI_DBG_ID, HFI_DBG_PRI, HFI_QUEUE_STATUS_ENABLED }, 198: }; 199: 200: /* Fill Table Header */ 201: tbl = mem_addr->hostptr; 202: tbl->qtbl_hdr.version = 0; 203: tbl->qtbl_hdr.size = sizeof(struct hfi_queue_table) >> 2; 204: tbl->qtbl_hdr.qhdr0_offset = sizeof(struct hfi_queue_table_header) >> 2; 205: tbl->qtbl_hdr.qhdr_size = sizeof(struct hfi_queue_header) >> 2; 206: tbl->qtbl_hdr.num_q = HFI_QUEUE_MAX; 207: tbl->qtbl_hdr.num_active_q = HFI_QUEUE_MAX; 208: 209: memset(&tbl->qhdr[0], 0, sizeof(tbl->qhdr)); 210: MATCH LINES: 227 215: hdr->type = QUEUE_HDR_TYPE(queue[i].idx, queue[i].pri, 0, 0); 216: hdr->status = queue[i].status; 217: hdr->queue_size = HFI_QUEUE_SIZE >> 2; /* convert to dwords */ 218: } 219: } 220: 221: int gen7_hfi_init(struct adreno_device *adreno_dev) 222: { 223: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 224: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 225: struct gen7_hfi *hfi = &gmu->hfi; 226: 227: /* Allocates & maps memory for HFI */ 228: if (IS_ERR_OR_NULL(hfi->hfi_mem)) { 229: hfi->hfi_mem = gmu_core_reserve_kernel_block(device, 0, 230: HFIMEM_SIZE, GMU_NONCACHED_KERNEL, 0); 231: if (!IS_ERR(hfi->hfi_mem)) 232: init_queues(adreno_dev); 233: } 234: 235: return PTR_ERR_OR_ZERO(hfi->hfi_mem); 236: } 237: 238: int gen7_receive_ack_cmd(struct gen7_gmu_device *gmu, void *rcvd, 239: struct pending_cmd *ret_cmd) 240: { 241: struct adreno_device *adreno_dev = gen7_gmu_to_adreno(gmu); 242: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 243: u32 *ack = rcvd; 244: u32 hdr = ack[0]; 245: u32 req_hdr = ack[1]; 246: 247: if (ret_cmd == NULL) 248: return -EINVAL; 249: 250: if (CMP_HFI_ACK_HDR(ret_cmd->sent_hdr, req_hdr)) { 251: memcpy(&ret_cmd->results, ack, MSG_HDR_GET_SIZE(hdr) << 2); MATCH LINES: 639 627: { 628: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 629: 630: if (gmu->idle_level == GPU_HW_IFPC) 631: return gen7_hfi_send_feature_ctrl(adreno_dev, 632: HFI_FEATURE_IFPC, 1, adreno_dev->ifpc_hyst); 633: return 0; 634: } 635: 636: static void reset_hfi_queues(struct adreno_device *adreno_dev) 637: { 638: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 639: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 640: struct hfi_queue_table *tbl = mem_addr->hostptr; 641: struct hfi_queue_header *hdr; 642: unsigned int i; 643: 644: /* Flush HFI queues */ 645: for (i = 0; i < HFI_QUEUE_MAX; i++) { 646: hdr = &tbl->qhdr[i]; 647: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 648: continue; 649: 650: hdr->read_index = hdr->write_index; 651: } 652: } 653: 654: /* Fill the entry and return the dword count written */ 655: static u32 _fill_table_entry(struct hfi_table_entry *entry, u32 count, 656: u32 stride_bytes, u32 *data) 657: { 658: entry->count = count; 659: entry->stride = stride_bytes >> 2; /* entry->stride is in dwords */ 660: memcpy(entry->data, data, stride_bytes * count); 661: 662: /* Return total dword count of entry + data */ 663: return (sizeof(*entry) >> 2) + (entry->count * entry->stride); --- FILE: \adreno_gen7_hfi.h | HITS: 1 --- MATCH LINES: 22 10: 11: /** 12: * struct gen7_hfi - HFI control structure 13: */ 14: struct gen7_hfi { 15: /** @irq: HFI interrupt line */ 16: int irq; 17: /** @seqnum: atomic counter that is incremented for each message sent. 18: * The value of the counter is used as sequence number for HFI message. 19: */ 20: atomic_t seqnum; 21: /** @hfi_mem: Memory descriptor for the hfi memory */ 22: struct kgsl_memdesc *hfi_mem; 23: /** @bw_table: HFI BW table buffer */ 24: struct hfi_bwtable_cmd bw_table; 25: /** @acd_table: HFI table for ACD data */ 26: struct hfi_acd_table_cmd acd_table; 27: /** @cmdq_lock: Spinlock for accessing the cmdq */ 28: spinlock_t cmdq_lock; 29: /** 30: * @wb_set_record_bitmask: Bitmask to enable or disable the recording 31: * of messages in the GMU scratch. 32: */ 33: unsigned long wb_set_record_bitmask[BITS_TO_LONGS(HFI_MAX_ID)]; 34: }; 35: 36: struct gen7_gmu_device; 37: 38: /* gen7_hfi_irq_handler - IRQ handler for HFI interripts */ 39: irqreturn_t gen7_hfi_irq_handler(int irq, void *data); 40: 41: /** 42: * gen7_hfi_start - Send the various HFIs during device boot up 43: * @adreno_dev: Pointer to the adreno device 44: * 45: * Return: 0 on success or negative error on failure 46: */ --- FILE: \adreno_gen7_hwsched.c | HITS: 9 --- MATCH LINES: 93 81: * payloads are not present, fall back to dumping ringbuffers 82: * based on MEMKIND_RB 83: */ 84: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2) 85: parse_payload = adreno_hwsched_parse_payload_rb_legacy(adreno_dev, snapshot); 86: else 87: parse_payload = adreno_hwsched_parse_payload_rb(adreno_dev, snapshot); 88: 89: if (parse_payload) 90: skip_memkind_rb = true; 91: 92: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 93: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 94: 95: if (entry->desc.mem_kind == HFI_MEMKIND_RB && !skip_memkind_rb) 96: kgsl_snapshot_add_section(device, 97: KGSL_SNAPSHOT_SECTION_RB_V2, 98: snapshot, adreno_hwsched_snapshot_rb, 99: entry->md); 100: 101: if (entry->desc.mem_kind == HFI_MEMKIND_SCRATCH) 102: kgsl_snapshot_add_section(device, 103: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 104: snapshot, adreno_snapshot_global, 105: entry->md); 106: 107: if (entry->desc.mem_kind == HFI_MEMKIND_PROFILE) 108: kgsl_snapshot_add_section(device, 109: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 110: snapshot, adreno_snapshot_global, 111: entry->md); 112: 113: if (entry->desc.mem_kind == HFI_MEMKIND_CSW_SMMU_INFO) 114: kgsl_snapshot_add_section(device, 115: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 116: snapshot, adreno_snapshot_global, 117: entry->md); MATCH LINES: 138 126: snapshot, adreno_snapshot_global, 127: entry->md); 128: 129: if (entry->desc.mem_kind == HFI_MEMKIND_AQE_BUFFER) 130: kgsl_snapshot_add_section(device, 131: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 132: snapshot, adreno_hwsched_snapshot_aqe_buffer, 133: entry->md); 134: 135: if (entry->desc.mem_kind == HFI_MEMKIND_HW_FENCE) { 136: struct gmu_mem_type_desc desc; 137: 138: desc.memdesc = entry->md; 139: desc.type = SNAPSHOT_GMU_MEM_HW_FENCE; 140: 141: kgsl_snapshot_add_section(device, 142: KGSL_SNAPSHOT_SECTION_GMU_MEMORY, 143: snapshot, adreno_snapshot_gmu_mem, &desc); 144: } 145: 146: } 147: 148: if (adreno_hwsched_context_queue_enabled(adreno_dev)) 149: adreno_hwsched_snapshot_context_queue(device, snapshot); 150: } 151: 152: static void gen7_hwsched_gmu_suspend(struct adreno_device *adreno_dev, bool force) 153: { 154: gen7_gmu_suspend(adreno_dev, force); 155: adreno_hwsched_reset_hfi_mem(adreno_dev); 156: } 157: 158: static int gen7_hwsched_gmu_first_boot(struct adreno_device *adreno_dev) 159: { 160: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 161: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 162: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); MATCH LINES: 459, 461, 468, 470, 475, 477 447: gen7_hwsched_gmu_suspend(adreno_dev, false); 448: 449: return ret; 450: } 451: 452: static void gen7_hwsched_init_ucode_regs(struct adreno_device *adreno_dev) 453: { 454: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 455: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 456: 457: /* Program the ucode base for CP */ 458: kgsl_regwrite(device, GEN7_CP_SQE_INSTR_BASE_LO, 459: lower_32_bits(fw->memdesc->gpuaddr)); 460: kgsl_regwrite(device, GEN7_CP_SQE_INSTR_BASE_HI, 461: upper_32_bits(fw->memdesc->gpuaddr)); 462: 463: if (ADRENO_FEATURE(adreno_dev, ADRENO_AQE)) { 464: fw = ADRENO_FW(adreno_dev, ADRENO_FW_AQE); 465: 466: /* Program the ucode base for AQE0 (BV coprocessor) */ 467: kgsl_regwrite(device, GEN7_CP_AQE_INSTR_BASE_LO_0, 468: lower_32_bits(fw->memdesc->gpuaddr)); 469: kgsl_regwrite(device, GEN7_CP_AQE_INSTR_BASE_HI_0, 470: upper_32_bits(fw->memdesc->gpuaddr)); 471: 472: /* Program the ucode base for AQE1 (LPAC coprocessor) */ 473: if (adreno_dev->lpac_enabled) { 474: kgsl_regwrite(device, GEN7_CP_AQE_INSTR_BASE_LO_1, 475: lower_32_bits(fw->memdesc->gpuaddr)); 476: kgsl_regwrite(device, GEN7_CP_AQE_INSTR_BASE_HI_1, 477: upper_32_bits(fw->memdesc->gpuaddr)); 478: } 479: } 480: } 481: 482: static int gen7_hwsched_gpu_boot(struct adreno_device *adreno_dev) 483: { 484: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 485: int ret; 486: 487: ret = kgsl_mmu_start(device); 488: if (ret) 489: goto err; 490: 491: ret = gen7_gmu_oob_set(device, oob_gpu); 492: if (ret) 493: goto err; 494: 495: /* Clear the busy_data stats - we're starting over from scratch */ 496: memset(&adreno_dev->busy_data, 0, sizeof(adreno_dev->busy_data)); 497: 498: gen7_start(adreno_dev); 499: 500: /* Re-initialize the coresight registers if applicable */ 501: adreno_coresight_start(adreno_dev); MATCH LINES: 1659 1647: 1648: if (!IS_ERR_OR_NULL(gmu_core->trace.md)) { 1649: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, 1650: KGSL_GMU_TRACE_ENTRY, 1651: gmu_core->trace.md->hostptr, 1652: gmu_core->trace.md->size); 1653: if (ret) 1654: return ret; 1655: } 1656: 1657: /* Dump HFI hwsched global mem alloc entries */ 1658: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 1659: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 1660: char hfi_minidump_str[MAX_VA_MINIDUMP_STR_LEN] = {0}; 1661: char name[MAX_VA_MINIDUMP_STR_LEN]; 1662: u32 rb_id = 0; 1663: 1664: if (!hfi_get_minidump_string(entry->desc.mem_kind, 1665: &hfi_minidump_str[0], 1666: sizeof(hfi_minidump_str), &rb_id)) { 1667: snprintf(name, sizeof(name), "kgsl_global_%s", hfi_minidump_str); 1668: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, 1669: name, 1670: entry->md->hostptr, 1671: entry->md->size); 1672: if (ret) 1673: return ret; 1674: } 1675: } 1676: 1677: if (!IS_ERR_OR_NULL(hw_hfi->big_ib)) { 1678: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, 1679: KGSL_HFI_BIG_IB_ENTRY, 1680: hw_hfi->big_ib->hostptr, 1681: hw_hfi->big_ib->size); 1682: if (ret) 1683: return ret; --- FILE: \adreno_gen7_hwsched_hfi.c | HITS: 16 --- MATCH LINES: 626, 648 614: dev_crit_ratelimited(gmu_pdev_dev, "Unknown GPU fault: %u\n", 615: cmd->error); 616: break; 617: } 618: 619: /* Return true for fatal errors to perform recovery sequence */ 620: return true; 621: } 622: 623: static bool is_queue_empty(struct adreno_device *adreno_dev, u32 queue_idx) 624: { 625: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 626: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 627: struct hfi_queue_table *tbl = mem_addr->hostptr; 628: struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx]; 629: 630: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 631: return true; 632: 633: if (hdr->read_index == hdr->write_index) 634: return true; 635: 636: /* 637: * This is to ensure that the queue is not read speculatively before the queue empty 638: * condition is evaluated 639: */ 640: rmb(); 641: 642: return false; 643: } 644: 645: static u32 peek_next_header(struct adreno_device *adreno_dev, struct gen7_gmu_device *gmu, 646: u32 queue_idx) 647: { 648: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 649: struct hfi_queue_table *tbl = mem_addr->hostptr; 650: struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx]; 651: u32 *queue; 652: 653: if (is_queue_empty(adreno_dev, queue_idx)) 654: return 0; 655: 656: queue = HOST_QUEUE_START_ADDR(mem_addr, queue_idx); 657: 658: return queue[hdr->read_index]; 659: } 660: 661: static void process_ctx_bad(struct adreno_device *adreno_dev) 662: { 663: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 664: 665: if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2) { 666: log_gpu_fault_legacy(adreno_dev); 667: goto done; 668: } 669: 670: /* Non fatal RBBM error interrupts don't go through reset and recovery */ 671: if (!log_gpu_fault(adreno_dev)) { 672: memset(adreno_dev->hwsched.ctxt_bad, 0x0, HFI_MAX_MSG_SIZE); MATCH LINES: 1918 1906: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1907: struct gmu_core_device *gmu_core = &device->gmu_core; 1908: 1909: if (gmu_core->warmboot_enabled && test_bit(GMU_PRIV_WARMBOOT_GMU_INIT_DONE, &gmu->flags) 1910: && test_bit(GMU_PRIV_WARMBOOT_GPU_BOOT_DONE, &gmu->flags) && 1911: !test_bit(GMU_FORCE_COLDBOOT, &device->gmu_core.flags)) 1912: return true; 1913: 1914: return false; 1915: } 1916: 1917: static int gen7_hwsched_hfi_send_warmboot_cmd(struct adreno_device *adreno_dev, 1918: struct kgsl_memdesc *desc, u32 flag, bool async, struct pending_cmd *ack) 1919: { 1920: struct hfi_warmboot_scratch_cmd cmd = {0}; 1921: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1922: struct gmu_core_device *gmu_core = &device->gmu_core; 1923: int ret; 1924: 1925: if (!gmu_core->warmboot_enabled) 1926: return 0; 1927: 1928: cmd.scratch_addr = desc->gmuaddr; 1929: cmd.scratch_size = desc->size; 1930: cmd.flags = flag; 1931: 1932: ret = CMD_MSG_HDR(cmd, H2F_MSG_WARMBOOT_CMD); 1933: if (ret) 1934: return ret; 1935: 1936: if (async) 1937: return gen7_hfi_send_cmd_async(adreno_dev, &cmd, sizeof(cmd)); 1938: 1939: return gen7_hfi_send_generic_req_v5(adreno_dev, &cmd, ack, sizeof(cmd)); 1940: } 1941: 1942: static int gen7_hwsched_hfi_warmboot_gpu_cmd(struct adreno_device *adreno_dev, MATCH LINES: 2504 2492: } 2493: 2494: void gen7_hwsched_hfi_remove(struct adreno_device *adreno_dev) 2495: { 2496: struct gen7_hwsched_hfi *hw_hfi = to_gen7_hwsched_hfi(adreno_dev); 2497: 2498: if (hw_hfi->f2h_task) 2499: kthread_stop(hw_hfi->f2h_task); 2500: } 2501: 2502: static void init_gmu_context_queue(struct adreno_context *drawctxt) 2503: { 2504: struct kgsl_memdesc *md = &drawctxt->gmu_context_queue; 2505: struct gmu_context_queue_header *hdr = md->hostptr; 2506: 2507: hdr->start_addr = md->gmuaddr + sizeof(*hdr); 2508: hdr->queue_size = (md->size - sizeof(*hdr)) >> 2; 2509: hdr->hw_fence_buffer_va = drawctxt->gmu_hw_fence_queue.gmuaddr; 2510: hdr->hw_fence_buffer_size = drawctxt->gmu_hw_fence_queue.size; 2511: } 2512: 2513: static u32 get_dq_id(struct adreno_device *adreno_dev, struct kgsl_context *context) 2514: { 2515: struct dq_info *info; 2516: u32 next; 2517: u32 priority = adreno_get_level(context); 2518: 2519: if (adreno_dev->lpac_enabled) 2520: info = &gen7_hfi_dqs_lpac[priority]; 2521: else 2522: info = &gen7_hfi_dqs[priority]; 2523: 2524: next = info->base_dq_id + info->offset; 2525: 2526: info->offset = (info->offset + 1) % info->max_dq; 2527: 2528: return next; MATCH LINES: 2621 2609: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 2610: int ret; 2611: 2612: ret = CMD_MSG_HDR(cmd, H2F_MSG_CONTEXT_POINTERS); 2613: if (ret) 2614: return ret; 2615: 2616: cmd.ctxt_id = context->id; 2617: cmd.sop_addr = MEMSTORE_ID_GPU_ADDR(device, context->id, soptimestamp); 2618: cmd.eop_addr = MEMSTORE_ID_GPU_ADDR(device, context->id, eoptimestamp); 2619: if (context->user_ctxt_record) 2620: cmd.user_ctxt_record_addr = 2621: context->user_ctxt_record->memdesc.gpuaddr; 2622: 2623: if (adreno_hwsched_context_queue_enabled(adreno_dev)) 2624: cmd.gmu_context_queue_addr = drawctxt->gmu_context_queue.gmuaddr; 2625: 2626: return gen7_hfi_send_cmd_async(adreno_dev, &cmd, sizeof(cmd)); 2627: } 2628: 2629: static int hfi_context_register(struct adreno_device *adreno_dev, 2630: struct kgsl_context *context) 2631: { 2632: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2633: int ret; 2634: 2635: if (context->gmu_registered) 2636: return 0; 2637: 2638: ret = send_context_register(adreno_dev, context); 2639: if (ret) { 2640: dev_err(GMU_PDEV_DEV(device), 2641: "Unable to register context %u: %d\n", 2642: context->id, ret); 2643: 2644: if (device->gmu_fault) 2645: gen7_hwsched_fault(adreno_dev, ADRENO_GMU_FAULT); MATCH LINES: 2679, 2696 2667: 2668: return 0; 2669: } 2670: 2671: static void populate_ibs(struct adreno_device *adreno_dev, 2672: struct hfi_submit_cmd *cmd, struct kgsl_drawobj_cmd *cmdobj) 2673: { 2674: struct hfi_issue_ib *issue_ib; 2675: struct kgsl_memobj_node *ib; 2676: 2677: if (cmdobj->numibs > HWSCHED_MAX_DISPATCH_NUMIBS) { 2678: struct gen7_hwsched_hfi *hfi = to_gen7_hwsched_hfi(adreno_dev); 2679: struct kgsl_memdesc *big_ib; 2680: 2681: if (test_bit(CMDOBJ_RECURRING_START, &cmdobj->priv)) 2682: big_ib = hfi->big_ib_recurring; 2683: else 2684: big_ib = hfi->big_ib; 2685: /* 2686: * The dispatcher ensures that there is only one big IB inflight 2687: */ 2688: cmd->big_ib_gmu_va = big_ib->gmuaddr; 2689: cmd->flags |= CMDBATCH_INDIRECT; 2690: issue_ib = big_ib->hostptr; 2691: } else { 2692: issue_ib = (struct hfi_issue_ib *)&cmd[1]; 2693: } 2694: 2695: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 2696: issue_ib->addr = ib->gpuaddr; 2697: issue_ib->size = ib->size; 2698: issue_ib++; 2699: } 2700: 2701: cmd->numibs = cmdobj->numibs; 2702: } 2703: 2704: #define HFI_DSP_IRQ_BASE 2 2705: 2706: #define DISPQ_IRQ_BIT(_idx) BIT((_idx) + HFI_DSP_IRQ_BASE) 2707: #define DISPQ_SYNC_IRQ_BIT(_idx) ((DISPQ_IRQ_BIT(_idx) << (KGSL_PRIORITY_MAX_RB_LEVELS + 1))) 2708: 2709: static u32 get_irq_bit(struct adreno_device *adreno_dev, struct kgsl_drawobj *drawobj) 2710: { 2711: if (!adreno_hwsched_context_queue_enabled(adreno_dev)) 2712: return drawobj->context->gmu_dispatch_queue; 2713: 2714: if (adreno_is_preemption_enabled(adreno_dev)) 2715: return adreno_get_level(drawobj->context); 2716: 2717: if (kgsl_context_is_lpac(drawobj->context)) 2718: return 1; 2719: 2720: return 0; MATCH LINES: 3459, 3460, 3461, 3462 3447: cmd->ts = drawobj->timestamp; 3448: 3449: if (test_bit(CMDOBJ_SKIP, &cmdobj->priv)) 3450: goto skipib; 3451: 3452: populate_ibs(adreno_dev, cmd, cmdobj); 3453: 3454: if ((drawobj->flags & KGSL_DRAWOBJ_PROFILING) && 3455: cmdobj->profiling_buf_entry) { 3456: 3457: time.drawobj = drawobj; 3458: 3459: cmd->profile_gpuaddr_lo = 3460: lower_32_bits(cmdobj->profiling_buffer_gpuaddr); 3461: cmd->profile_gpuaddr_hi = 3462: upper_32_bits(cmdobj->profiling_buffer_gpuaddr); 3463: 3464: /* Indicate to GMU to do user profiling for this submission */ 3465: cmd->flags |= CMDBATCH_PROFILING; 3466: } 3467: 3468: if (test_and_clear_bit(CMDOBJ_NOP_SUBMISSION, &cmdobj->priv)) 3469: cmd->flags |= CMDBATCH_NOP_SUBMISSION; 3470: 3471: skipib: 3472: adreno_drawobj_set_constraint(KGSL_DEVICE(adreno_dev), drawobj); 3473: 3474: seqnum = atomic_inc_return(&adreno_dev->hwsched.submission_seqnum); 3475: cmd->hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_CMD, HFI_MSG_CMD); 3476: cmd->hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd->hdr, seqnum, cmd_sizebytes >> 2); 3477: 3478: if (adreno_hwsched_context_queue_enabled(adreno_dev)) 3479: ret = adreno_gmu_context_queue_write(adreno_dev, 3480: &drawctxt->gmu_context_queue, (u32 *)cmd, cmd_sizebytes, drawobj, &time); 3481: else 3482: ret = gen7_hfi_dispatch_queue_write(adreno_dev, 3483: HFI_DSP_ID_0 + drawobj->context->gmu_dispatch_queue, 3484: (u32 *)cmd, cmd_sizebytes, cmdobj, &time); 3485: if (ret) 3486: return ret; MATCH LINES: 3747, 3750 3735: struct kgsl_device *device = context->device; 3736: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 3737: int ret = 0; 3738: 3739: kgsl_mutex_lock(&device->mutex); 3740: 3741: ret = send_context_unregister_hfi(adreno_dev, context, 3742: drawctxt->internal_timestamp); 3743: 3744: if (ret) 3745: goto out; 3746: 3747: kgsl_sharedmem_writel(device->memstore, 3748: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), drawctxt->timestamp); 3749: 3750: kgsl_sharedmem_writel(device->memstore, 3751: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), drawctxt->timestamp); 3752: 3753: adreno_profile_process_results(adreno_dev); 3754: context->gmu_registered = false; 3755: 3756: out: 3757: WARN_RATELIMIT(!list_empty(&drawctxt->hw_fence_list) || 3758: !list_empty(&drawctxt->hw_fence_inflight_list), 3759: "detached ctx:%u has active hw fences\n", 3760: context->id); 3761: 3762: kgsl_mutex_unlock(&device->mutex); 3763: } 3764: 3765: u32 gen7_hwsched_preempt_count_get(struct adreno_device *adreno_dev) 3766: { 3767: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3768: 3769: if (device->state != KGSL_STATE_ACTIVE) 3770: return 0; 3771: 3772: return gen7_hwsched_hfi_get_value(adreno_dev, HFI_VALUE_PREEMPT_COUNT); 3773: } 3774: MATCH LINES: 3845, 3861 3833: pcmd.eop_addr = MEMSTORE_ID_GPU_ADDR(device, KGSL_GLOBAL_CTXT_ID, eoptimestamp); 3834: 3835: if (adreno_hwsched_context_queue_enabled(adreno_dev)) 3836: pcmd.gmu_context_queue_addr = hwsched->global_ctxtq.gmuaddr; 3837: 3838: ret = gen7_hfi_send_cmd_async(adreno_dev, &pcmd, sizeof(pcmd)); 3839: if (!ret) 3840: hwsched->global_ctxt_gmu_registered = true; 3841: 3842: return ret; 3843: } 3844: 3845: static int submit_global_ctxt_cmd(struct adreno_device *adreno_dev, u64 gpuaddr, u32 size) 3846: { 3847: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3848: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3849: struct { 3850: struct hfi_submit_cmd submit_cmd; 3851: struct hfi_issue_ib issue_ib; 3852: } cmd = {0}; 3853: u32 seqnum, cmd_size = sizeof(cmd); 3854: static u32 ts; 3855: int ret; 3856: 3857: cmd.submit_cmd.ctxt_id = KGSL_GLOBAL_CTXT_ID; 3858: cmd.submit_cmd.ts = ++ts; 3859: cmd.submit_cmd.numibs = 1; 3860: 3861: cmd.issue_ib.addr = gpuaddr; 3862: cmd.issue_ib.size = size; 3863: 3864: seqnum = atomic_inc_return(&hwsched->submission_seqnum); 3865: cmd.submit_cmd.hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_CMD, HFI_MSG_CMD); 3866: cmd.submit_cmd.hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd.submit_cmd.hdr, seqnum, cmd_size >> 2); 3867: 3868: if (adreno_hwsched_context_queue_enabled(adreno_dev)) 3869: ret = adreno_gmu_context_queue_write(adreno_dev, 3870: &hwsched->global_ctxtq, (u32 *)&cmd, cmd_size, NULL, NULL); 3871: else 3872: ret = gen7_hfi_dispatch_queue_write(adreno_dev, HFI_DSP_ID_0, 3873: (u32 *)&cmd, cmd_size, NULL, NULL); 3874: 3875: /* Send interrupt to GMU to receive the message */ 3876: if (!ret) 3877: gmu_core_regwrite(device, GEN7_GMU_HOST2GMU_INTR_SET, DISPQ_IRQ_BIT(0)); 3878: 3879: return ret; 3880: } 3881: 3882: int gen7_hwsched_counter_inline_enable(struct adreno_device *adreno_dev, 3883: const struct adreno_perfcount_group *group, 3884: u32 counter, u32 countable) 3885: { MATCH LINES: 3911 3899: goto err; 3900: 3901: if (group->flags & ADRENO_PERFCOUNTER_GROUP_RESTORE) 3902: gen7_perfcounter_update(adreno_dev, reg, false, 3903: FIELD_PREP(GENMASK(13, 12), PIPE_NONE), group->flags); 3904: 3905: cmds = hfi->perfctr_scratch->hostptr; 3906: 3907: cmds[count++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 3908: cmds[count++] = cp_type4_packet(reg->select, 1); 3909: cmds[count++] = countable; 3910: 3911: ret = submit_global_ctxt_cmd(adreno_dev, hfi->perfctr_scratch->gpuaddr, count << 2); 3912: if (ret) 3913: goto err; 3914: 3915: /* Wait till the register is programmed with the countable */ 3916: ret = kgsl_regmap_read_poll_timeout(&device->regmap, reg->select, val, 3917: val == countable, 100, ADRENO_IDLE_TIMEOUT * USEC_PER_MSEC); 3918: if (!ret) { 3919: reg->value = 0; 3920: return ret; 3921: } 3922: 3923: err: 3924: dev_err(device->dev, "Perfcounter %s/%u/%u start via commands failed\n", 3925: group->name, counter, countable); 3926: 3927: return ret; 3928: } 3929: 3930: int gen7_hwsched_disable_hw_fence_throttle(struct adreno_device *adreno_dev) 3931: { 3932: struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence; 3933: struct adreno_context *drawctxt = NULL; 3934: u32 ts = 0; 3935: int ret = 0; --- FILE: \adreno_gen7_hwsched_hfi.h | HITS: 3 --- MATCH LINES: 53, 55, 57 41: struct gen7_hwsched_hfi { 42: /** @irq_mask: Store the hfi interrupt mask */ 43: u32 irq_mask; 44: /** @msglock: To protect the list of un-ACKed hfi packets */ 45: rwlock_t msglock; 46: /** @msglist: List of un-ACKed hfi packets */ 47: struct list_head msglist; 48: /** @f2h_task: Task for processing gmu fw to host packets */ 49: struct task_struct *f2h_task; 50: /** @f2h_wq: Waitqueue for the f2h_task */ 51: wait_queue_head_t f2h_wq; 52: /** @big_ib: GMU buffer to hold big IBs */ 53: struct kgsl_memdesc *big_ib; 54: /** @big_ib_recurring: GMU buffer to hold big recurring IBs */ 55: struct kgsl_memdesc *big_ib_recurring; 56: /** @perfctr_scratch: Buffer to hold perfcounter PM4 commands */ 57: struct kgsl_memdesc *perfctr_scratch; 58: /** @msg_mutex: Mutex for accessing the msgq */ 59: struct mutex msgq_mutex; 60: /** 61: * @hw_fence_timer: Timer to trigger fault if unack'd hardware fence count does'nt drop 62: * to a desired threshold in given amount of time 63: */ 64: struct timer_list hw_fence_timer; 65: /** 66: * @hw_fence_ws: Work struct that gets scheduled when hw_fence_timer expires 67: */ 68: struct work_struct hw_fence_ws; 69: /** @detached_hw_fences_list: List of hardware fences belonging to detached contexts */ 70: struct list_head detached_hw_fence_list; 71: /** @defer_hw_fence_work: The work structure to send deferred hardware fences to GMU */ 72: struct kthread_work defer_hw_fence_work; 73: }; 74: 75: struct kgsl_drawobj_cmd; 76: 77: /** 78: * gen7_hwsched_hfi_probe - Probe hwsched hfi resources 79: * @adreno_dev: Pointer to adreno device structure 80: * 81: * Return: 0 on success and negative error on failure. --- FILE: \adreno_gen7_preempt.c | HITS: 41 --- MATCH LINES: 211 199: return rb; 200: } 201: 202: return NULL; 203: } 204: 205: void gen7_preemption_trigger(struct adreno_device *adreno_dev, bool atomic) 206: { 207: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 208: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 209: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 210: struct adreno_ringbuffer *next; 211: u64 ttbr0, gpuaddr; 212: u32 contextidr, cntl; 213: unsigned long flags; 214: struct adreno_preemption *preempt = &adreno_dev->preempt; 215: 216: /* Put ourselves into a possible trigger state */ 217: if (!adreno_move_preempt_state(adreno_dev, 218: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START)) 219: return; 220: 221: /* Get the next ringbuffer to preempt in */ 222: next = gen7_next_ringbuffer(adreno_dev); 223: 224: /* 225: * Nothing to do if every ringbuffer is empty or if the current 226: * ringbuffer is the only active one 227: */ 228: if (next == NULL || next == adreno_dev->cur_rb) { 229: /* 230: * Update any critical things that might have been skipped while 231: * we were looking for a new ringbuffer 232: */ 233: 234: if (next != NULL) { 235: _update_wptr(adreno_dev, false, atomic); MATCH LINES: 256, 258, 261, 268, 270, 274, 298, 316, 323, 329, 336, 342, 368 244: 245: /* Turn off the dispatcher timer */ 246: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 247: 248: /* 249: * This is the most critical section - we need to take care not to race 250: * until we have programmed the CP for the switch 251: */ 252: 253: spin_lock_irqsave(&next->preempt_lock, flags); 254: 255: /* Get the pagetable from the pagetable info. */ 256: kgsl_sharedmem_readq(device->scratch, &ttbr0, 257: SCRATCH_RB_OFFSET(next->id, ttbr0)); 258: kgsl_sharedmem_readl(device->scratch, &contextidr, 259: SCRATCH_RB_OFFSET(next->id, contextidr)); 260: 261: kgsl_sharedmem_writel(next->preemption_desc, 262: PREEMPT_RECORD(wptr), next->wptr); 263: 264: spin_unlock_irqrestore(&next->preempt_lock, flags); 265: 266: /* And write it to the smmu info */ 267: if (kgsl_mmu_is_perprocess(&device->mmu)) { 268: kgsl_sharedmem_writeq(iommu->smmu_info, 269: PREEMPT_SMMU_RECORD(ttbr0), ttbr0); 270: kgsl_sharedmem_writel(iommu->smmu_info, 271: PREEMPT_SMMU_RECORD(context_idr), contextidr); 272: } 273: 274: kgsl_sharedmem_readq(preempt->scratch, &gpuaddr, 275: next->id * sizeof(u64)); 276: 277: /* 278: * Set a keepalive bit before the first preemption register write. 279: * This is required since while each individual write to the context 280: * switch registers will wake the GPU from collapse, it will not in 281: * itself cause GPU activity. Thus, the GPU could technically be 282: * re-collapsed between subsequent register writes leading to a 283: * prolonged preemption sequence. The keepalive bit prevents any 284: * further power collapse while it is set. 285: * It is more efficient to use a keepalive+wake-on-fence approach here 286: * rather than an OOB. Both keepalive and the fence are effectively 287: * free when the GPU is already powered on, whereas an OOB requires an 288: * unconditional handshake with the GMU. 289: */ 290: _power_collapse_set(adreno_dev, true); 291: 292: /* 293: * Fenced writes on this path will make sure the GPU is woken up 294: * in case it was power collapsed by the GMU. 295: */ 296: if (gen7_fenced_write(adreno_dev, 297: GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO, 298: lower_32_bits(next->preemption_desc->gpuaddr), 299: FENCE_STATUS_WRITEDROPPED1_MASK)) 300: goto err; 301: 302: /* 303: * Above fence writes will make sure GMU comes out of 304: * IFPC state if its was in IFPC state but it doesn't 305: * guarantee that GMU FW actually moved to ACTIVE state 306: * i.e. wake-up from IFPC is complete. 307: * Wait for GMU to move to ACTIVE state before triggering 308: * preemption. This is require to make sure CP doesn't 309: * interrupt GMU during wake-up from IFPC. 310: */ 311: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 312: goto err; 313: 314: if (gen7_fenced_write(adreno_dev, 315: GEN7_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI, 316: upper_32_bits(next->preemption_desc->gpuaddr), 317: FENCE_STATUS_WRITEDROPPED1_MASK)) 318: goto err; 319: 320: if (kgsl_mmu_is_secured(&device->mmu)) { 321: if (gen7_fenced_write(adreno_dev, 322: GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO, 323: lower_32_bits(next->secure_preemption_desc->gpuaddr), 324: FENCE_STATUS_WRITEDROPPED1_MASK)) 325: goto err; 326: 327: if (gen7_fenced_write(adreno_dev, 328: GEN7_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI, 329: upper_32_bits(next->secure_preemption_desc->gpuaddr), 330: FENCE_STATUS_WRITEDROPPED1_MASK)) 331: goto err; 332: } 333: 334: if (gen7_fenced_write(adreno_dev, 335: GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO, 336: lower_32_bits(gpuaddr), 337: FENCE_STATUS_WRITEDROPPED1_MASK)) 338: goto err; 339: 340: if (gen7_fenced_write(adreno_dev, 341: GEN7_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI, 342: upper_32_bits(gpuaddr), 343: FENCE_STATUS_WRITEDROPPED1_MASK)) 344: goto err; 345: 346: adreno_dev->next_rb = next; 347: 348: /* Start the timer to detect a stuck preemption */ 349: mod_timer(&adreno_dev->preempt.timer, 350: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 351: 352: cntl = (preempt->preempt_level << 6) | 0x01; 353: 354: /* Skip save/restore during L1 preemption */ 355: if (preempt->skipsaverestore) 356: cntl |= (1 << 9); 357: 358: /* Enable GMEM save/restore across preemption */ 359: if (preempt->usesgmem) 360: cntl |= (1 << 8); 361: 362: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 363: cntl, 0); 364: 365: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 366: 367: if (gen7_core->qos_value) 368: kgsl_sharedmem_writel(preempt->scratch, 369: PREEMPT_SCRATCH_OFFSET(QOS_VALUE_IDX), 370: gen7_core->qos_value[next->id]); 371: 372: /* Trigger the preemption */ 373: if (gen7_fenced_write(adreno_dev, GEN7_CP_CONTEXT_SWITCH_CNTL, cntl, 374: FENCE_STATUS_WRITEDROPPED1_MASK)) { 375: adreno_dev->next_rb = NULL; 376: kgsl_delete_timer(&adreno_dev->preempt.timer); 377: goto err; 378: } 379: 380: return; 381: err: 382: /* If fenced write fails, take inline snapshot and trigger recovery */ 383: if (!in_interrupt()) { 384: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 385: adreno_scheduler_fault(adreno_dev, 386: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 387: } else { 388: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 389: } 390: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 391: /* Clear the keep alive */ 392: _power_collapse_set(adreno_dev, false); MATCH LINES: 543, 546, 550, 551, 562, 563 531: return 0; 532: 533: if (test_and_set_bit(ADRENO_RB_SET_PSEUDO_DONE, &rb->flags)) 534: goto done; 535: 536: *cmds++ = cp_type7_packet(CP_THREAD_CONTROL, 1); 537: *cmds++ = CP_SET_THREAD_BR; 538: 539: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, count); 540: 541: /* NULL SMMU_INFO buffer - we track in KMD */ 542: *cmds++ = SET_PSEUDO_SMMU_INFO; 543: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 544: 545: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 546: cmds += cp_gpuaddr(adreno_dev, cmds, rb->preemption_desc->gpuaddr); 547: 548: if (kgsl_mmu_is_secured(&device->mmu)) { 549: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 550: cmds += cp_gpuaddr(adreno_dev, cmds, 551: rb->secure_preemption_desc->gpuaddr); 552: } 553: 554: /* 555: * There is no need to specify this address when we are about to 556: * trigger preemption. This is because CP internally stores this 557: * address specified here in the CP_SET_PSEUDO_REGISTER payload to 558: * the context record and thus knows from where to restore 559: * the saved perfcounters for the new ringbuffer. 560: */ 561: *cmds++ = SET_PSEUDO_COUNTER; 562: cmds += cp_gpuaddr(adreno_dev, cmds, 563: rb->perfcounter_save_restore_desc->gpuaddr); 564: 565: done: 566: if (drawctxt) { 567: cmds += adreno_prepare_preib_preempt_scratch(adreno_dev, drawctxt, cmds); 568: cmds += adreno_prepare_preib_postamble_scratch(adreno_dev, cmds); 569: } 570: 571: return (u32) (cmds - cmds_orig); 572: } 573: 574: u32 gen7_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 575: u32 *cmds) 576: { 577: u32 index = 0; 578: 579: if (!adreno_is_preemption_enabled(adreno_dev)) 580: return 0; 581: 582: if (adreno_dev->cur_rb) { 583: u64 dest = PREEMPT_SCRATCH_ADDR(adreno_dev, adreno_dev->cur_rb->id); 584: 585: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 4); 586: cmds[index++] = lower_32_bits(dest); 587: cmds[index++] = upper_32_bits(dest); MATCH LINES: 618, 620, 624, 626, 630, 633, 637, 639, 654, 656, 658, 661, 662, 663, 694, 701, 709, 721, 737, 749, 752 606: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 607: struct adreno_ringbuffer *rb; 608: unsigned int i; 609: 610: if (!adreno_is_preemption_enabled(adreno_dev)) 611: return; 612: 613: /* Force the state to be clear */ 614: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 615: 616: if (kgsl_mmu_is_perprocess(&device->mmu)) { 617: /* smmu_info is allocated and mapped in gen7_preemption_iommu_init */ 618: kgsl_sharedmem_writel(iommu->smmu_info, 619: PREEMPT_SMMU_RECORD(magic), GEN7_CP_SMMU_INFO_MAGIC_REF); 620: kgsl_sharedmem_writeq(iommu->smmu_info, 621: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 622: 623: /* The CP doesn't use the asid record, so poison it */ 624: kgsl_sharedmem_writel(iommu->smmu_info, 625: PREEMPT_SMMU_RECORD(asid), 0xdecafbad); 626: kgsl_sharedmem_writel(iommu->smmu_info, 627: PREEMPT_SMMU_RECORD(context_idr), 0); 628: 629: kgsl_regwrite(device, GEN7_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 630: lower_32_bits(iommu->smmu_info->gpuaddr)); 631: 632: kgsl_regwrite(device, GEN7_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 633: upper_32_bits(iommu->smmu_info->gpuaddr)); 634: } 635: 636: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 637: kgsl_sharedmem_writel(rb->preemption_desc, 638: PREEMPT_RECORD(rptr), 0); 639: kgsl_sharedmem_writel(rb->preemption_desc, 640: PREEMPT_RECORD(wptr), 0); 641: 642: adreno_ringbuffer_set_pagetable(device, rb, 643: device->mmu.defaultpagetable); 644: 645: clear_bit(ADRENO_RB_SET_PSEUDO_DONE, &rb->flags); 646: } 647: } 648: 649: static void reset_rb_preempt_record(struct adreno_device *adreno_dev, 650: struct adreno_ringbuffer *rb) 651: { 652: memset(rb->preemption_desc->hostptr, 0x0, rb->preemption_desc->size); 653: 654: kgsl_sharedmem_writel(rb->preemption_desc, 655: PREEMPT_RECORD(magic), GEN7_CP_CTXRECORD_MAGIC_REF); 656: kgsl_sharedmem_writel(rb->preemption_desc, 657: PREEMPT_RECORD(cntl), GEN7_CP_RB_CNTL_DEFAULT); 658: kgsl_sharedmem_writeq(rb->preemption_desc, 659: PREEMPT_RECORD(rptr_addr), SCRATCH_RB_GPU_ADDR( 660: KGSL_DEVICE(adreno_dev), rb->id, rptr)); 661: kgsl_sharedmem_writeq(rb->preemption_desc, 662: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 663: kgsl_sharedmem_writeq(rb->preemption_desc, 664: PREEMPT_RECORD(bv_rptr_addr), SCRATCH_RB_GPU_ADDR( 665: KGSL_DEVICE(adreno_dev), rb->id, bv_rptr)); 666: } 667: 668: void gen7_reset_preempt_records(struct adreno_device *adreno_dev) 669: { 670: int i; 671: struct adreno_ringbuffer *rb; 672: 673: if (!adreno_is_preemption_enabled(adreno_dev)) 674: return; 675: 676: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 677: reset_rb_preempt_record(adreno_dev, rb); 678: } 679: } 680: 681: static int gen7_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 682: struct adreno_ringbuffer *rb) 683: { 684: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 685: const struct adreno_gen7_core *gen7_core = to_gen7_core(adreno_dev); 686: u64 ctxt_record_size = GEN7_CP_CTXRECORD_SIZE_IN_BYTES; 687: int ret; 688: 689: if (gen7_core->ctxt_record_size) 690: ctxt_record_size = gen7_core->ctxt_record_size; 691: 692: ret = adreno_allocate_global(device, &rb->preemption_desc, 693: ctxt_record_size, SZ_16K, 0, 694: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 695: if (ret) 696: return ret; 697: 698: if (kgsl_mmu_is_secured(&device->mmu)) { 699: ret = adreno_allocate_global(device, &rb->secure_preemption_desc, 700: ctxt_record_size, 0, 701: KGSL_MEMFLAGS_SECURE, KGSL_MEMDESC_PRIVILEGED, 702: "secure_preemption_desc"); 703: if (ret) 704: return ret; 705: } 706: 707: ret = adreno_allocate_global(device, &rb->perfcounter_save_restore_desc, 708: GEN7_CP_PERFCOUNTER_SAVE_RESTORE_SIZE, 0, 0, 709: KGSL_MEMDESC_PRIVILEGED, 710: "perfcounter_save_restore_desc"); 711: if (ret) 712: return ret; 713: 714: reset_rb_preempt_record(adreno_dev, rb); 715: 716: return 0; 717: } 718: 719: int gen7_preemption_init(struct adreno_device *adreno_dev) 720: { 721: u32 flags = ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? KGSL_MEMDESC_PRIVILEGED : 0; 722: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 723: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 724: struct adreno_preemption *preempt = &adreno_dev->preempt; 725: struct adreno_ringbuffer *rb; 726: int ret; 727: unsigned int i; 728: 729: /* We are dependent on IOMMU to make preemption go on the CP side */ 730: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) { 731: ret = -ENODEV; 732: goto done; 733: } 734: 735: INIT_WORK(&preempt->work, _gen7_preemption_worker); 736: 737: /* Allocate mem for storing preemption switch record */ 738: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 739: ret = gen7_preemption_ringbuffer_init(adreno_dev, rb); 740: if (ret) 741: goto done; 742: } 743: 744: ret = adreno_allocate_global(device, &preempt->scratch, PAGE_SIZE, 745: 0, 0, flags, "preempt_scratch"); 746: if (ret) 747: goto done; 748: 749: /* Allocate mem for storing preemption smmu record */ 750: if (kgsl_mmu_is_perprocess(&device->mmu)) { 751: ret = adreno_allocate_global(device, &iommu->smmu_info, PAGE_SIZE, 0, 752: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 753: "smmu_info"); 754: if (ret) 755: goto done; 756: } 757: 758: return 0; 759: done: 760: clear_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 761: return ret; 762: } --- FILE: \adreno_gen7_ringbuffer.c | HITS: 26 --- MATCH LINES: 152, 156, 157 140: 141: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 142: cmds[count++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 143: KGSL_MEMSTORE_GLOBAL, current_context)); 144: cmds[count++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 145: KGSL_MEMSTORE_GLOBAL, current_context)); 146: cmds[count++] = drawctxt->base.id; 147: 148: cmds[count++] = cp_type7_packet(CP_EVENT_WRITE, 1); 149: cmds[count++] = 0x31; 150: 151: if (adreno_is_preemption_enabled(adreno_dev) && drawctxt->base.user_ctxt_record) { 152: u64 gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 153: 154: cmds[count++] = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 3); 155: cmds[count++] = SET_PSEUDO_NON_PRIV_SAVE_ADDR; 156: cmds[count++] = lower_32_bits(gpuaddr); 157: cmds[count++] = upper_32_bits(gpuaddr); 158: } 159: 160: return gen7_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED, 161: cmds, count, 0, NULL); 162: } 163: 164: #define RB_SOPTIMESTAMP(device, rb) \ 165: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 166: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 167: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 168: 169: #define RB_EOPTIMESTAMP(device, rb) \ 170: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 171: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 172: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 173: 174: int gen7_ringbuffer_submit(struct adreno_ringbuffer *rb, 175: struct adreno_submit_time *time) 176: { 177: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 178: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 179: int ret = 0; 180: unsigned long flags; 181: MATCH LINES: 220 208: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 209: } 210: 211: return ret; 212: } 213: 214: int gen7_ringbuffer_init(struct adreno_device *adreno_dev) 215: { 216: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 217: int i, ret; 218: 219: ret = adreno_allocate_global(device, &device->scratch, PAGE_SIZE, 220: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED, 221: "scratch"); 222: if (ret) 223: return ret; 224: 225: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]); 226: 227: if (!adreno_preemption_feature_set(adreno_dev)) { 228: adreno_dev->num_ringbuffers = 1; 229: return adreno_ringbuffer_setup(adreno_dev, 230: &adreno_dev->ringbuffers[0], 0); 231: } 232: 233: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers); 234: 235: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 236: int ret; 237: 238: ret = adreno_ringbuffer_setup(adreno_dev, 239: &adreno_dev->ringbuffers[i], i); 240: if (ret) 241: return ret; 242: } 243: 244: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); MATCH LINES: 259, 297, 300, 302, 303, 332, 335, 337, 338 247: } 248: 249: #define GEN7_SUBMIT_MAX 104 250: 251: int gen7_ringbuffer_addcmds(struct adreno_device *adreno_dev, 252: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 253: u32 flags, u32 *in, u32 dwords, u32 timestamp, 254: struct adreno_submit_time *time) 255: { 256: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 257: u32 size = GEN7_SUBMIT_MAX + dwords; 258: u32 *cmds, index = 0; 259: u64 profile_gpuaddr; 260: u32 profile_dwords; 261: 262: if (adreno_drawctxt_detached(drawctxt)) 263: return -ENOENT; 264: 265: if (adreno_gpu_fault(adreno_dev) != 0) 266: return -EPROTO; 267: 268: rb->timestamp++; 269: 270: if (drawctxt) 271: drawctxt->internal_timestamp = rb->timestamp; 272: 273: /* All submissions are run with protected mode off due to APRIV */ 274: flags &= ~F_NOTPROTECTED; 275: 276: cmds = adreno_ringbuffer_allocspace(rb, size); 277: if (IS_ERR(cmds)) 278: return PTR_ERR(cmds); 279: 280: /* Identify the start of a command */ 281: cmds[index++] = cp_type7_packet(CP_NOP, 1); 282: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 283: 284: /* This is 25 dwords when drawctxt is not NULL and perfcounter needs to be zapped*/ 285: index += gen7_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt, 286: &cmds[index]); 287: 288: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 289: cmds[index++] = CP_SET_THREAD_BOTH; 290: 291: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 292: cmds[index++] = 0x101; /* IFPC disable */ 293: 294: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 295: cmds[index++] = CP_SET_THREAD_BR; 296: 297: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 298: drawctxt, &profile_dwords); 299: 300: if (profile_gpuaddr) { 301: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 302: cmds[index++] = lower_32_bits(profile_gpuaddr); 303: cmds[index++] = upper_32_bits(profile_gpuaddr); 304: cmds[index++] = profile_dwords; 305: } 306: 307: if (drawctxt) { 308: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 309: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 310: drawctxt)); 311: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 312: drawctxt)); 313: cmds[index++] = timestamp; 314: } 315: 316: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 317: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 318: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); 319: cmds[index++] = rb->timestamp; 320: 321: if (IS_SECURE(flags)) { 322: /* Sync BV and BR if entering secure mode */ 323: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 324: cmds[index++] = CP_SYNC_THREADS | CP_CONCURRENT_BIN_DISABLE; 325: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 326: cmds[index++] = 1; 327: } 328: 329: memcpy(&cmds[index], in, dwords << 2); 330: index += dwords; 331: 332: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev, 333: drawctxt, &dwords); 334: 335: if (profile_gpuaddr) { 336: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 337: cmds[index++] = lower_32_bits(profile_gpuaddr); 338: cmds[index++] = upper_32_bits(profile_gpuaddr); 339: cmds[index++] = profile_dwords; 340: } 341: 342: if (test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &device->mmu.pfpolicy)) 343: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0); 344: 345: if (is_concurrent_binning(drawctxt)) { 346: u64 addr = SCRATCH_RB_GPU_ADDR(device, rb->id, bv_ts); 347: 348: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 349: cmds[index++] = CP_SET_THREAD_BV; 350: 351: /* 352: * Make sure the timestamp is committed once BV pipe is 353: * completely done with this submission. 354: */ 355: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 356: cmds[index++] = CACHE_CLEAN | BIT(27); 357: cmds[index++] = lower_32_bits(addr); 358: cmds[index++] = upper_32_bits(addr); 359: cmds[index++] = rb->timestamp; 360: 361: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 362: cmds[index++] = CP_SET_THREAD_BR; MATCH LINES: 432, 436, 437, 442, 446, 447, 466, 469, 470 420: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 421: cmds[index++] = CP_SET_THREAD_BR; 422: 423: /* 10 dwords */ 424: index += gen7_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 425: 426: /* Adjust the thing for the number of bytes we actually wrote */ 427: rb->_wptr -= (size - index); 428: 429: return gen7_ringbuffer_submit(rb, time); 430: } 431: 432: static u32 gen7_get_alwayson_counter(u32 *cmds, u64 gpuaddr) 433: { 434: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 435: cmds[1] = GEN7_CP_ALWAYS_ON_COUNTER_LO | (1 << 30) | (2 << 18); 436: cmds[2] = lower_32_bits(gpuaddr); 437: cmds[3] = upper_32_bits(gpuaddr); 438: 439: return 4; 440: } 441: 442: static u32 gen7_get_alwayson_context(u32 *cmds, u64 gpuaddr) 443: { 444: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 445: cmds[1] = GEN7_CP_ALWAYS_ON_CONTEXT_LO | (1 << 30) | (2 << 18); 446: cmds[2] = lower_32_bits(gpuaddr); 447: cmds[3] = upper_32_bits(gpuaddr); 448: 449: return 4; 450: } 451: 452: #define PROFILE_IB_DWORDS 4 453: #define PROFILE_IB_SLOTS (PAGE_SIZE / (PROFILE_IB_DWORDS << 2)) 454: 455: static u64 gen7_get_user_profiling_ib(struct adreno_ringbuffer *rb, 456: struct kgsl_drawobj_cmd *cmdobj, u32 target_offset, u32 *cmds) 457: { 458: u32 offset, *ib, dwords; 459: 460: if (IS_ERR(rb->profile_desc)) 461: return 0; 462: 463: offset = rb->profile_index * (PROFILE_IB_DWORDS << 2); 464: ib = rb->profile_desc->hostptr + offset; 465: dwords = gen7_get_alwayson_counter(ib, 466: cmdobj->profiling_buffer_gpuaddr + target_offset); 467: 468: cmds[0] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 469: cmds[1] = lower_32_bits(rb->profile_desc->gpuaddr + offset); 470: cmds[2] = upper_32_bits(rb->profile_desc->gpuaddr + offset); 471: cmds[3] = dwords; 472: 473: rb->profile_index = (rb->profile_index + 1) % PROFILE_IB_SLOTS; 474: 475: return 4; 476: } 477: 478: static int gen7_drawctxt_switch(struct adreno_device *adreno_dev, 479: struct adreno_ringbuffer *rb, 480: struct adreno_context *drawctxt) 481: { 482: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 483: int ret; 484: 485: if (rb->drawctxt_active == drawctxt) 486: return 0; 487: 488: if (kgsl_context_detached(&drawctxt->base)) 489: return -ENOENT; 490: 491: if (!_kgsl_context_get(&drawctxt->base)) 492: return -ENOENT; 493: 494: ret = gen7_rb_context_switch(adreno_dev, rb, drawctxt); MATCH LINES: 518, 524 506: rb->drawctxt_active = drawctxt; 507: return 0; 508: } 509: 510: 511: #define GEN7_USER_PROFILE_IB(rb, cmdobj, cmds, field) \ 512: gen7_get_user_profiling_ib((rb), (cmdobj), \ 513: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 514: (cmds)) 515: 516: #define GEN7_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 517: gen7_get_alwayson_counter((cmds), \ 518: (dev)->profile_buffer->gpuaddr + \ 519: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 520: field)) 521: 522: #define GEN7_KERNEL_PROFILE_CONTEXT(dev, cmdobj, cmds, field) \ 523: gen7_get_alwayson_context((cmds), \ 524: (dev)->profile_buffer->gpuaddr + \ 525: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 526: field)) 527: 528: #define GEN7_COMMAND_DWORDS 60 529: 530: int gen7_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 531: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 532: struct adreno_submit_time *time) 533: { 534: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 535: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 536: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 537: struct adreno_ringbuffer *rb = drawctxt->rb; 538: int ret = 0, numibs = 0, index = 0; 539: u32 *cmds; 540: 541: /* Count the number of IBs (if we are not skipping) */ 542: if (!IS_SKIP(flags)) { 543: struct list_head *tmp; 544: 545: list_for_each(tmp, &cmdobj->cmdlist) 546: numibs++; 547: } 548: MATCH LINES: 589, 590 577: 578: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 579: cmds[index++] = 0x00d; /* IB1LIST start */ 580: 581: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 582: if (ib->priv & MEMOBJ_SKIP || 583: (ib->flags & KGSL_CMDLIST_CTXTSWITCH_PREAMBLE && 584: !IS_PREAMBLE(flags))) 585: cmds[index++] = cp_type7_packet(CP_NOP, 4); 586: 587: cmds[index++] = 588: cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 589: cmds[index++] = lower_32_bits(ib->gpuaddr); 590: cmds[index++] = upper_32_bits(ib->gpuaddr); 591: 592: /* Double check that IB_PRIV is never set */ 593: cmds[index++] = (ib->size >> 2) & 0xfffff; 594: } 595: 596: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 597: cmds[index++] = 0x00e; /* IB1LIST end */ 598: } 599: 600: if (is_concurrent_binning(drawctxt)) { 601: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 602: cmds[index++] = CP_SET_THREAD_BR; 603: } 604: /* CCU invalidate depth */ 605: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1); 606: cmds[index++] = 24; 607: 608: /* CCU invalidate color */ 609: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1); 610: cmds[index++] = 25; 611: 612: /* 8 dwords */ 613: if (IS_KERNEL_PROFILE(flags)) { 614: index += GEN7_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index], --- FILE: \adreno_gen7_snapshot.c | HITS: 12 --- MATCH LINES: 20, 21 8: #include "adreno_snapshot.h" 9: #include "adreno_gen7_0_0_snapshot.h" 10: #include "adreno_gen7_2_0_snapshot.h" 11: #include "adreno_gen7_3_0_snapshot.h" 12: #include "adreno_gen7_5_0_snapshot.h" 13: #include "adreno_gen7_6_0_snapshot.h" 14: #include "adreno_gen7_9_0_snapshot.h" 15: #include "adreno_gen7_11_0_snapshot.h" 16: #include "adreno_gen7_14_0_snapshot.h" 17: #include "adreno_gen7_15_0_snapshot.h" 18: #include "adreno_gen7_17_0_snapshot.h" 19: 20: static struct kgsl_memdesc *gen7_capturescript; 21: static struct kgsl_memdesc *gen7_crashdump_registers; 22: static u32 *gen7_cd_reg_end; 23: static const struct gen7_snapshot_block_list *gen7_snapshot_block_list; 24: static bool gen7_crashdump_timedout; 25: 26: /* Starting kernel virtual address for QDSS TMC register block */ 27: static void __iomem *tmc_virt; 28: 29: const struct gen7_snapshot_block_list gen7_0_0_snapshot_block_list = { 30: .pre_crashdumper_regs = gen7_0_0_pre_crashdumper_gpu_registers, 31: .debugbus_blocks = gen7_0_0_debugbus_blocks, 32: .debugbus_blocks_len = ARRAY_SIZE(gen7_0_0_debugbus_blocks), 33: .gbif_debugbus_blocks = gen7_gbif_debugbus_blocks, 34: .gbif_debugbus_blocks_len = ARRAY_SIZE(gen7_gbif_debugbus_blocks), 35: .cx_debugbus_blocks = gen7_cx_dbgc_debugbus_blocks, 36: .cx_debugbus_blocks_len = ARRAY_SIZE(gen7_cx_dbgc_debugbus_blocks), 37: .external_core_regs = gen7_0_0_external_core_regs, 38: .num_external_core_regs = ARRAY_SIZE(gen7_0_0_external_core_regs), 39: .gmu_regs = gen7_0_0_gmu_registers, 40: .gmu_gx_regs = gen7_0_0_gmugx_registers, 41: .rscc_regs = gen7_0_0_rscc_registers, 42: .reg_list = gen7_0_0_reg_list, 43: .cx_misc_regs = gen7_0_0_cx_misc_registers, 44: .shader_blocks = gen7_0_0_shader_blocks, 45: .num_shader_blocks = ARRAY_SIZE(gen7_0_0_shader_blocks), MATCH LINES: 354, 377, 379 342: static int CD_READ(u64 *ptr, u32 offset, u32 size, u64 target) 343: { 344: ptr[0] = target; 345: ptr[1] = FIELD_PREP(GENMASK(63, 44), offset) | size; 346: 347: return 2; 348: } 349: 350: static void CD_FINISH(u64 *ptr, u32 offset) 351: { 352: gen7_cd_reg_end = gen7_crashdump_registers->hostptr + offset; 353: *gen7_cd_reg_end = CD_REG_END; 354: ptr[0] = gen7_crashdump_registers->gpuaddr + offset; 355: ptr[1] = FIELD_PREP(GENMASK(63, 44), GEN7_CP_CRASH_DUMP_STATUS) | BIT(0); 356: ptr[2] = 0; 357: ptr[3] = 0; 358: } 359: 360: static bool CD_SCRIPT_CHECK(struct kgsl_device *device) 361: { 362: return (adreno_smmu_is_stalled(ADRENO_DEVICE(device)) || (!device->snapshot_crashdumper) || 363: IS_ERR_OR_NULL(gen7_capturescript) || 364: IS_ERR_OR_NULL(gen7_crashdump_registers) || 365: gen7_crashdump_timedout); 366: } 367: 368: static bool _gen7_do_crashdump(struct kgsl_device *device) 369: { 370: unsigned int reg = 0; 371: ktime_t timeout; 372: 373: if (CD_SCRIPT_CHECK(device)) 374: return false; 375: 376: kgsl_regwrite(device, GEN7_CP_CRASH_SCRIPT_BASE_LO, 377: lower_32_bits(gen7_capturescript->gpuaddr)); 378: kgsl_regwrite(device, GEN7_CP_CRASH_SCRIPT_BASE_HI, 379: upper_32_bits(gen7_capturescript->gpuaddr)); 380: kgsl_regwrite(device, GEN7_CP_CRASH_DUMP_CNTL, 1); 381: 382: timeout = ktime_add_ms(ktime_get(), CP_CRASH_DUMPER_TIMEOUT); 383: 384: if (!device->snapshot_atomic) 385: might_sleep(); 386: for (;;) { 387: /* make sure we're reading the latest value */ 388: rmb(); 389: if ((*gen7_cd_reg_end) != CD_REG_END) 390: break; 391: if (ktime_compare(ktime_get(), timeout) > 0) 392: break; 393: /* Wait 50us to avoid unnecessary looping */ 394: if (!device->snapshot_atomic) 395: usleep_range(5, 50); 396: } 397: 398: kgsl_regread(device, GEN7_CP_CRASH_DUMP_STATUS, ®); 399: 400: /* 401: * Writing to the GEN7_CP_CRASH_DUMP_CNTL also resets the 402: * GEN7_CP_CRASH_DUMP_STATUS. Make sure the read above is 403: * complete before we change the value MATCH LINES: 869 857: ptr = gen7_capturescript->hostptr; 858: offset = 0; 859: 860: for (sp = 0; sp < block->num_sps; sp++) { 861: for (usptp = 0; usptp < block->num_usptps; usptp++) { 862: /* Program the aperture */ 863: ptr += CD_WRITE(ptr, GEN7_SP_READ_SEL, 864: GEN7_SP_READ_SEL_VAL(block->location, block->pipeid, 865: block->statetype, usptp, sp)); 866: 867: /* Read all the data in one chunk */ 868: ptr += CD_READ(ptr, GEN7_SP_AHB_READ_APERTURE, block->size, 869: gen7_crashdump_registers->gpuaddr + offset); 870: offset += block->size << 2; 871: } 872: } 873: /* Marker for end of script */ 874: CD_FINISH(ptr, offset); 875: 876: /* Try to run the crash dumper */ 877: func = gen7_legacy_snapshot_shader; 878: if (_gen7_do_crashdump(device)) 879: func = gen7_snapshot_shader_memory; 880: 881: offset = 0; 882: for (sp = 0; sp < block->num_sps; sp++) { 883: for (usptp = 0; usptp < block->num_usptps; usptp++) { 884: info.block = block; 885: info.sp_id = sp; 886: info.usptp = usptp; 887: info.offset = offset; 888: offset += block->size << 2; 889: 890: /* Shader working/shadow memory */ 891: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_SHADER_V2, 892: snapshot, func, &info); 893: } MATCH LINES: 1059 1047: const u32 *regs = cluster->regs; 1048: 1049: cluster->offset = offset; 1050: 1051: /* Program the aperture */ 1052: ptr += CD_WRITE(ptr, GEN7_SP_READ_SEL, GEN7_SP_READ_SEL_VAL 1053: (cluster->location_id, cluster->pipe_id, cluster->statetype, 0, 0)); 1054: 1055: for (; regs[0] != UINT_MAX; regs += 2) { 1056: count = REG_COUNT(regs); 1057: ptr += CD_READ(ptr, (GEN7_SP_AHB_READ_APERTURE + 1058: regs[0] - cluster->regbase), count, 1059: (gen7_crashdump_registers->gpuaddr + offset)); 1060: 1061: offset += count * sizeof(unsigned int); 1062: } 1063: } 1064: /* Marker for end of script */ 1065: CD_FINISH(ptr, offset); 1066: 1067: /* Try to run the crash dumper */ 1068: if (_gen7_do_crashdump(device)) 1069: func = gen7_snapshot_cluster_dbgahb; 1070: 1071: /* Capture the registers in snapshot */ 1072: for (i = 0; i < num_sptp_clusters; i++) 1073: kgsl_snapshot_add_section(device, 1074: KGSL_SNAPSHOT_SECTION_MVC_V2, snapshot, func, &sptp_clusters[i]); 1075: } 1076: 1077: static size_t gen7_legacy_snapshot_mvc(struct kgsl_device *device, u8 *buf, 1078: size_t remain, void *priv) 1079: { 1080: struct kgsl_snapshot_mvc_regs_v2 *header = 1081: (struct kgsl_snapshot_mvc_regs_v2 *)buf; 1082: unsigned int *data = (unsigned int *)(buf + sizeof(*header)); 1083: struct gen7_cluster_registers *cluster = MATCH LINES: 1206 1194: 1195: cluster->offset = offset; 1196: ptr += CD_WRITE(ptr, GEN7_CP_APERTURE_CNTL_CD, GEN7_CP_APERTURE_REG_VAL 1197: (cluster->pipe_id, cluster->cluster_id, cluster->context_id)); 1198: 1199: if (cluster->sel) 1200: ptr += CD_WRITE(ptr, cluster->sel->cd_reg, cluster->sel->val); 1201: 1202: for (; regs[0] != UINT_MAX; regs += 2) { 1203: count = REG_COUNT(regs); 1204: 1205: ptr += CD_READ(ptr, regs[0], 1206: count, (gen7_crashdump_registers->gpuaddr + offset)); 1207: 1208: offset += count * sizeof(unsigned int); 1209: } 1210: } 1211: 1212: /* Marker for end of script */ 1213: CD_FINISH(ptr, offset); 1214: 1215: /* Try to run the crash dumper */ 1216: if (_gen7_do_crashdump(device)) 1217: func = gen7_snapshot_mvc; 1218: 1219: for (i = 0; i < num_clusters; i++) 1220: kgsl_snapshot_add_section(device, 1221: KGSL_SNAPSHOT_SECTION_MVC_V2, snapshot, func, &clusters[i]); 1222: } 1223: 1224: /* gen7_dbgc_debug_bus_read() - Read data from trace bus */ 1225: static void gen7_dbgc_debug_bus_read(struct kgsl_device *device, 1226: unsigned int block_id, unsigned int index, unsigned int *val) 1227: { 1228: unsigned int reg; 1229: 1230: reg = FIELD_PREP(GENMASK(7, 0), index) | MATCH LINES: 1574 1562: struct gen7_reg_list *regs = ®_list[i]; 1563: const u32 *regs_ptr = regs->regs; 1564: 1565: regs->offset = offset; 1566: 1567: /* Program the SEL_CNTL_CD register appropriately */ 1568: if (regs->sel) 1569: ptr += CD_WRITE(ptr, regs->sel->cd_reg, regs->sel->val); 1570: 1571: for (; regs_ptr[0] != UINT_MAX; regs_ptr += 2) { 1572: r = REG_COUNT(regs_ptr); 1573: ptr += CD_READ(ptr, regs_ptr[0], r, 1574: (gen7_crashdump_registers->gpuaddr + offset)); 1575: offset += r * sizeof(u32); 1576: } 1577: } 1578: 1579: /* Marker for end of script */ 1580: CD_FINISH(ptr, offset); 1581: 1582: /* Try to run the crash dumper */ 1583: if (_gen7_do_crashdump(device)) 1584: func = gen7_snapshot_registers; 1585: 1586: for (i = 0; reg_list[i].regs; i++) 1587: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS_V2, 1588: snapshot, func, ®_list[i]); 1589: } 1590: 1591: static size_t gen7_snapshot_cx_misc_registers(struct kgsl_device *device, u8 *buf, 1592: size_t remain, void *priv) 1593: { 1594: const u32 *ptr = (u32 *)priv; 1595: u32 *src, *data = (unsigned int *)buf; 1596: size_t size = adreno_snapshot_regs_count(ptr) * sizeof(u32); 1597: 1598: if (remain < size) { MATCH LINES: 1639 1627: const u32 *regs_ptr = (const u32 *)gen7_snapshot_block_list->cx_misc_regs; 1628: 1629: if (CD_SCRIPT_CHECK(device) || !adreno_gx_is_on(ADRENO_DEVICE(device))) 1630: goto done; 1631: 1632: /* Build the crash script */ 1633: ptr = (u64 *)gen7_capturescript->hostptr; 1634: 1635: for (; regs_ptr[0] != UINT_MAX; regs_ptr += 2) { 1636: u32 r = REG_COUNT(regs_ptr); 1637: 1638: ptr += CD_READ(ptr, regs_ptr[0], r, 1639: (gen7_crashdump_registers->gpuaddr + offset)); 1640: offset += r * sizeof(u32); 1641: } 1642: 1643: /* Marker for end of script */ 1644: CD_FINISH(ptr, offset); 1645: 1646: /* Try to run the crash dumper */ 1647: if (_gen7_do_crashdump(device)) { 1648: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS_V2, 1649: snapshot, gen7_snapshot_cx_misc_registers, 1650: (void *)gen7_snapshot_block_list->cx_misc_regs); 1651: return; 1652: } 1653: 1654: done: 1655: regs_ptr = (const u32 *)gen7_snapshot_block_list->cx_misc_regs; 1656: 1657: if (!kgsl_regmap_valid_offset(&device->regmap, regs_ptr[0])) { 1658: WARN_ONCE(1, "cx_misc registers are not defined in device tree"); 1659: return; 1660: } 1661: 1662: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS_V2, 1663: snapshot, adreno_snapshot_registers_v2, (void *)regs_ptr); MATCH LINES: 1909, 1916 1897: 1898: if (is_current_rt) 1899: sched_set_fifo(current); 1900: } 1901: 1902: void gen7_crashdump_init(struct adreno_device *adreno_dev) 1903: { 1904: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1905: 1906: if (IS_ERR_OR_NULL(gen7_capturescript)) 1907: gen7_capturescript = kgsl_allocate_global(device, 1908: 3 * PAGE_SIZE, 0, KGSL_MEMFLAGS_GPUREADONLY, 1909: KGSL_MEMDESC_PRIVILEGED, "capturescript"); 1910: 1911: if (IS_ERR(gen7_capturescript)) 1912: return; 1913: 1914: if (IS_ERR_OR_NULL(gen7_crashdump_registers)) 1915: gen7_crashdump_registers = kgsl_allocate_global(device, 1916: 25 * PAGE_SIZE, 0, 0, KGSL_MEMDESC_PRIVILEGED, 1917: "capturescript_regs"); 1918: 1919: if (IS_ERR(gen7_crashdump_registers)) 1920: return; 1921: } --- FILE: \adreno_gen8.c | HITS: 14 --- MATCH LINES: 1137, 1138 1125: /* Enable the register init list with the spinlock */ 1126: mask |= BIT(8); 1127: 1128: cmds[i++] = cp_type7_packet(CP_ME_INIT, 7); 1129: 1130: /* Enabled ordinal mask */ 1131: cmds[i++] = mask; 1132: cmds[i++] = 0x00000003; /* Set number of HW contexts */ 1133: cmds[i++] = 0x20000000; /* Enable error detection */ 1134: cmds[i++] = 0x00000002; /* Operation mode mask */ 1135: 1136: /* Register initialization list with spinlock */ 1137: cmds[i++] = lower_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 1138: cmds[i++] = upper_32_bits(adreno_dev->pwrup_reglist->gpuaddr); 1139: /* 1140: * Gen8 targets with concurrent binning are expected to have a dynamic 1141: * power up list with triplets which contains the pipe id in it. 1142: * Bit 31 of POWER_UP_REGISTER_LIST_LENGTH is reused here to let CP 1143: * know if the power up contains the triplets. If 1144: * REGISTER_INIT_LIST_WITH_SPINLOCK is set and bit 31 below is set, 1145: * CP expects a dynamic list with triplets. 1146: */ 1147: cmds[i++] = BIT(31); 1148: } 1149: 1150: int gen8_fenced_write(struct adreno_device *adreno_dev, u32 offset, 1151: u32 value, u32 mask) 1152: { 1153: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1154: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 1155: u32 status, i; 1156: u64 ts1, ts2; 1157: 1158: kgsl_regwrite(device, offset, value); 1159: ts1 = gpudev->read_alwayson(adreno_dev); 1160: for (i = 0; i < GMU_CORE_LONG_WAKEUP_RETRY_LIMIT; i++) { 1161: /* 1162: * Make sure the previous register write is posted before MATCH LINES: 1300 1288: 1289: gen8_crashdump_init(adreno_dev); 1290: 1291: gen8_dev->nc_overrides = gen8_nc_overrides; 1292: mutex_init(&gen8_dev->nc_mutex); 1293: 1294: /* Debugfs node for noncontext registers override */ 1295: if (!debugfs_lookup("nc_override", device->d_debugfs)) 1296: debugfs_create_file("nc_override", 0644, 1297: device->d_debugfs, device, &nc_override_fops); 1298: 1299: return adreno_allocate_global(device, &adreno_dev->pwrup_reglist, 1300: PAGE_SIZE, 0, 0, KGSL_MEMDESC_PRIVILEGED, 1301: "powerup_register_list"); 1302: } 1303: 1304: #define CX_TIMER_INIT_SAMPLES 16 1305: void gen8_cx_timer_init(struct adreno_device *adreno_dev) 1306: { 1307: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1308: u64 seed_val, tmr, skew = 0; 1309: int i; 1310: unsigned long flags; 1311: 1312: /* Set it up during first boot or after suspend resume */ 1313: if (test_bit(ADRENO_DEVICE_CX_TIMER_INITIALIZED, &adreno_dev->priv)) 1314: return; 1315: 1316: /* Disable irqs to get accurate timings */ 1317: local_irq_save(flags); 1318: 1319: /* Calculate the overhead of timer reads and register writes */ 1320: for (i = 0; i < CX_TIMER_INIT_SAMPLES; i++) { 1321: u64 tmr1, tmr2, tmr3; 1322: 1323: /* Measure time for two reads of the CPU timer */ 1324: tmr1 = arch_timer_read_counter(); MATCH LINES: 2418, 2419, 2423, 2424 2406: 2407: if (preempt->postamble_bootup_len) 2408: count += 4; 2409: 2410: cmds = adreno_ringbuffer_allocspace(rb, count); 2411: if (IS_ERR(cmds)) 2412: return PTR_ERR(cmds); 2413: 2414: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 2415: kgsl_mmu_is_secured(&device->mmu) ? 6 : 3); 2416: 2417: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 2418: *cmds++ = lower_32_bits(rb->preemption_desc->gpuaddr); 2419: *cmds++ = upper_32_bits(rb->preemption_desc->gpuaddr); 2420: 2421: if (kgsl_mmu_is_secured(&device->mmu)) { 2422: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 2423: *cmds++ = lower_32_bits(rb->secure_preemption_desc->gpuaddr); 2424: *cmds++ = upper_32_bits(rb->secure_preemption_desc->gpuaddr); 2425: } 2426: 2427: if (preempt->postamble_bootup_len) { 2428: *cmds++ = cp_type7_packet(CP_SET_AMBLE, 3); 2429: *cmds++ = lower_32_bits(kmd_postamble_addr); 2430: *cmds++ = upper_32_bits(kmd_postamble_addr); 2431: *cmds++ = FIELD_PREP(GENMASK(22, 20), CP_KMD_AMBLE_TYPE) 2432: | (FIELD_PREP(GENMASK(19, 0), 2433: adreno_dev->preempt.postamble_bootup_len)); 2434: } 2435: 2436: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4); 2437: *cmds++ = 0; 2438: *cmds++ = 0; 2439: *cmds++ = 0; 2440: /* generate interrupt on preemption completion */ 2441: *cmds++ = 0; 2442: 2443: ret = gen8_ringbuffer_submit(rb, NULL); 2444: if (!ret) { 2445: ret = adreno_spin_idle(adreno_dev, 2000); 2446: if (ret) 2447: gen8_spin_idle_debug(adreno_dev, 2448: "hw preemption initialization failed to idle\n"); MATCH LINES: 2467, 2469, 2493, 2495, 2499, 2501 2455: { 2456: const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev); 2457: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 2458: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2459: struct adreno_ringbuffer *rb; 2460: u64 addr; 2461: int ret, i; 2462: u32 *cmds; 2463: 2464: /* Clear all the ringbuffers */ 2465: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 2466: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE); 2467: kgsl_sharedmem_writel(device->scratch, 2468: SCRATCH_RB_OFFSET(rb->id, rptr), 0); 2469: kgsl_sharedmem_writel(device->scratch, 2470: SCRATCH_RB_OFFSET(rb->id, bv_rptr), 0); 2471: 2472: rb->wptr = 0; 2473: rb->_wptr = 0; 2474: rb->wptr_preempt_end = UINT_MAX; 2475: } 2476: 2477: gen8_preemption_start(adreno_dev); 2478: 2479: /* Set up the current ringbuffer */ 2480: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev); 2481: 2482: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr); 2483: kgsl_regwrite(device, GEN8_CP_RB_RPTR_ADDR_LO_BR, lower_32_bits(addr)); 2484: kgsl_regwrite(device, GEN8_CP_RB_RPTR_ADDR_HI_BR, upper_32_bits(addr)); 2485: 2486: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, bv_rptr); 2487: kgsl_regwrite(device, GEN8_CP_RB_RPTR_ADDR_LO_BV, lower_32_bits(addr)); 2488: kgsl_regwrite(device, GEN8_CP_RB_RPTR_ADDR_HI_BV, upper_32_bits(addr)); 2489: 2490: kgsl_regwrite(device, GEN8_CP_RB_CNTL_GC, GEN8_CP_RB_CNTL_DEFAULT); 2491: 2492: kgsl_regwrite(device, GEN8_CP_RB_BASE_LO_GC, 2493: lower_32_bits(rb->buffer_desc->gpuaddr)); 2494: kgsl_regwrite(device, GEN8_CP_RB_BASE_HI_GC, 2495: upper_32_bits(rb->buffer_desc->gpuaddr)); 2496: 2497: /* Program the ucode base for CP */ 2498: kgsl_regwrite(device, GEN8_CP_SQE_INSTR_BASE_LO, 2499: lower_32_bits(fw->memdesc->gpuaddr)); 2500: kgsl_regwrite(device, GEN8_CP_SQE_INSTR_BASE_HI, 2501: upper_32_bits(fw->memdesc->gpuaddr)); 2502: 2503: /* Clear the SQE_HALT to start the CP engine */ 2504: kgsl_regwrite(device, GEN8_CP_SQE_CNTL, 1); 2505: 2506: ret = gen8_send_cp_init(adreno_dev, rb); 2507: if (ret) 2508: return ret; 2509: 2510: ret = adreno_zap_shader_load(adreno_dev, gen8_core->zap_name); 2511: if (ret) 2512: return ret; 2513: 2514: /* 2515: * Take the GPU out of secure mode. Try the zap shader if it is loaded, 2516: * otherwise just try to write directly to the secure control register 2517: */ 2518: if (!adreno_dev->zap_loaded) 2519: kgsl_regwrite(device, GEN8_RBBM_SECVID_TRUST_CNTL, 0); 2520: else { 2521: cmds = adreno_ringbuffer_allocspace(rb, 2); 2522: if (IS_ERR(cmds)) 2523: return PTR_ERR(cmds); 2524: 2525: *cmds++ = cp_type7_packet(CP_SET_SECURE_MODE, 1); MATCH LINES: 2552 2540: * When the GPU is in secure mode, any writes to the RB_GC_GMEM_PROTECT 2541: * register are ignored. At this point, the GPU should be in unsecure 2542: * mode, so program the RB_GC_GMEM_PROTECT register. 2543: */ 2544: gen8_set_gmem_protect(adreno_dev); 2545: 2546: /* 2547: * All registers must be written before this point so that we don't 2548: * miss any register programming when we patch the power up register 2549: * list. 2550: */ 2551: if (!adreno_dev->patch_reglist && 2552: (adreno_dev->pwrup_reglist->gpuaddr != 0)) { 2553: gen8_patch_pwrup_reglist(adreno_dev); 2554: adreno_dev->patch_reglist = true; 2555: } 2556: 2557: ret = gen8_post_start(adreno_dev); 2558: if (!ret && (adreno_is_gen8_2_x(adreno_dev) || adreno_is_gen8_1_0(adreno_dev) || 2559: adreno_is_gen8_10_0(adreno_dev))) 2560: gen8_hwcg_set(adreno_dev, true); 2561: 2562: return ret; 2563: } 2564: 2565: /* 2566: * gen8_gpu_keepalive() - GMU reg write to request GPU stays on 2567: * @adreno_dev: Pointer to the adreno device that has the GMU 2568: * @state: State to set: true is ON, false is OFF 2569: */ 2570: static void gen8_gpu_keepalive(struct adreno_device *adreno_dev, 2571: bool state) 2572: { 2573: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), 2574: GEN8_GMUCX_PWR_COL_KEEPALIVE, state); 2575: } 2576: --- FILE: \adreno_gen8_gmu.c | HITS: 2 --- MATCH LINES: 436, 437 424: return -EINVAL; 425: } 426: 427: if (id == GMU_ITCM) { 428: load_tcm(adreno_dev, fw, 429: GEN8_GMU_CM3_ITCM_START, 430: device->gmu_core.vma[GMU_ITCM].start, blk); 431: } else if (id == GMU_DTCM) { 432: load_tcm(adreno_dev, fw, 433: GEN8_GMU_CM3_DTCM_START, 434: device->gmu_core.vma[GMU_DTCM].start, blk); 435: } else { 436: struct kgsl_memdesc *md = 437: gmu_core_find_memdesc(device, blk->addr, blk->size); 438: 439: if (!md) { 440: dev_err(gmu_pdev_dev, 441: "No backing memory for GMU FW block addr:0x%x size:0x%x\n", 442: blk->addr, blk->size); 443: return -EINVAL; 444: } 445: 446: memcpy(md->hostptr + (blk->addr - md->gmuaddr), fw, 447: blk->size); 448: } 449: 450: fw += blk->size; 451: } 452: 453: /* Proceed only after the FW is written */ 454: wmb(); 455: return 0; 456: } 457: 458: static const char *oob_to_str(enum oob_request req) 459: { 460: switch (req) { 461: case oob_gpu: --- FILE: \adreno_gen8_gmu.h | HITS: 4 --- MATCH LINES: 35, 37, 39 23: * struct gen8_gmu_device - GMU device structure 24: * @ver: GMU Version information 25: * @irq: GMU interrupt number 26: * @fw_image: GMU FW image 27: * @gmu_log: gmu event log memory 28: * @hfi: HFI controller 29: * @idle_level: Minimal GPU idle power level 30: * @log_wptr_retention: Store the log wptr offset on slumber 31: */ 32: struct gen8_gmu_device { 33: int irq; 34: const struct firmware *fw_image; 35: struct kgsl_memdesc *gmu_log; 36: /** @gmu_init_scratch: Memory to store the initial HFI messages */ 37: struct kgsl_memdesc *gmu_init_scratch; 38: /** @gpu_boot_scratch: Memory to store the bootup HFI messages */ 39: struct kgsl_memdesc *gpu_boot_scratch; 40: struct gen8_hfi hfi; 41: u32 idle_level; 42: /** @qmp: aoss_qmp handle */ 43: struct qmp *qmp; 44: u32 log_wptr_retention; 45: /** @cm3_fault: whether gmu received a cm3 fault interrupt */ 46: atomic_t cm3_fault; 47: /** 48: * @itcm_shadow: Copy of the itcm block in firmware binary used for 49: * snapshot 50: */ 51: void *itcm_shadow; 52: /** @flags: Internal gmu flags */ 53: unsigned long flags; 54: /** @rscc_virt: Pointer where RSCC block is mapped */ 55: void __iomem *rscc_virt; 56: /** @log_stream_enable: GMU log streaming enable. Disabled by default */ 57: bool log_stream_enable; 58: /** @log_group_mask: Allows overriding default GMU log group mask */ 59: u32 log_group_mask; 60: struct kobject log_kobj; 61: /** @num_oob_perfcntr: Number of active oob_perfcntr requests */ 62: u32 num_oob_perfcntr; 63: /** @acd_debug_val: DVM value to calibrate ACD for a level */ MATCH LINES: 173 161: int gen8_gmu_probe(struct kgsl_device *device, 162: struct platform_device *pdev); 163: 164: /** 165: * gen8_gmu_parse_fw - Parse the gmu fw binary 166: * @adreno_dev: Pointer to the adreno device 167: * 168: * Return: 0 on success or negative error on failure 169: */ 170: int gen8_gmu_parse_fw(struct adreno_device *adreno_dev); 171: 172: /** 173: * gen8_gmu_memory_init - Allocate gmu memory 174: * @adreno_dev: Pointer to the adreno device 175: * 176: * Allocates the gmu log buffer and others if ndeeded. 177: * 178: * Return: 0 on success or negative error on failure 179: */ 180: int gen8_gmu_memory_init(struct adreno_device *adreno_dev); 181: 182: /** 183: * gen8_gmu_aop_send_acd_state - Enable or disable acd feature in aop 184: * @gmu: Pointer to the gen8 gmu device 185: * @flag: Boolean to enable or disable acd in aop 186: * 187: * This function enables or disables gpu acd feature using qmp 188: */ 189: void gen8_gmu_aop_send_acd_state(struct gen8_gmu_device *gmu, bool flag); 190: 191: /** 192: * gen8_gmu_load_fw - Load gmu firmware 193: * @adreno_dev: Pointer to the adreno device 194: * 195: * Loads the gmu firmware binary into TCMs and memory 196: * 197: * Return: 0 on success or negative error on failure --- FILE: \adreno_gen8_gmu_snapshot.c | HITS: 4 --- MATCH LINES: 33 21: (struct kgsl_snapshot_gmu_mem *)buf; 22: u32 *data = (u32 *)(buf + sizeof(*mem_hdr)); 23: u32 i; 24: 25: if (remain < gmu_core->vma[GMU_DTCM].size + sizeof(*mem_hdr)) { 26: SNAPSHOT_ERR_NOMEM(device, "GMU DTCM Memory"); 27: return 0; 28: } 29: 30: mem_hdr->type = SNAPSHOT_GMU_MEM_BIN_BLOCK; 31: mem_hdr->hostaddr = 0; 32: mem_hdr->gmuaddr = gmu_core->vma[GMU_DTCM].start; 33: mem_hdr->gpuaddr = 0; 34: 35: /* 36: * Read of GMU TCMs over side-band debug controller interface is 37: * supported on gen8 family 38: * region [20]: Dump ITCM/DTCM. Select 1 for DTCM. 39: * autoInc [31]: Autoincrement the address field after each 40: * access to TCM_DBG_DATA 41: */ 42: kgsl_regwrite(device, GEN8_CX_DBGC_TCM_DBG_ADDR, BIT(20) | BIT(31)); 43: 44: for (i = 0; i < (gmu_core->vma[GMU_DTCM].size >> 2); i++) 45: kgsl_regread(device, GEN8_CX_DBGC_TCM_DBG_DATA, data++); 46: 47: return gmu_core->vma[GMU_DTCM].size + sizeof(*mem_hdr); 48: } 49: 50: static size_t gen8_gmu_snapshot_itcm(struct kgsl_device *device, 51: u8 *buf, size_t remain, void *priv) 52: { 53: struct gmu_core_device *gmu_core = &device->gmu_core; 54: struct kgsl_snapshot_gmu_mem *mem_hdr = 55: (struct kgsl_snapshot_gmu_mem *)buf; 56: void *dest = buf + sizeof(*mem_hdr); 57: struct gen8_gmu_device *gmu = (struct gen8_gmu_device *)priv; MATCH LINES: 73, 84, 94 61: "No memory allocated for ITCM shadow capture\n"); 62: return 0; 63: } 64: 65: if (remain < gmu_core->vma[GMU_ITCM].size + sizeof(*mem_hdr)) { 66: SNAPSHOT_ERR_NOMEM(device, "GMU ITCM Memory"); 67: return 0; 68: } 69: 70: mem_hdr->type = SNAPSHOT_GMU_MEM_BIN_BLOCK; 71: mem_hdr->hostaddr = 0; 72: mem_hdr->gmuaddr = gmu_core->vma[GMU_ITCM].start; 73: mem_hdr->gpuaddr = 0; 74: 75: memcpy(dest, gmu->itcm_shadow, gmu_core->vma[GMU_ITCM].size); 76: 77: return gmu_core->vma[GMU_ITCM].size + sizeof(*mem_hdr); 78: } 79: 80: static void gen8_gmu_snapshot_memories(struct kgsl_device *device, 81: struct gen8_gmu_device *gmu, struct kgsl_snapshot *snapshot) 82: { 83: struct gmu_mem_type_desc desc; 84: struct kgsl_memdesc *md; 85: struct gmu_core_device *gmu_core = &device->gmu_core; 86: int i; 87: 88: for (i = 0; i < ARRAY_SIZE(gmu_core->gmu_globals); i++) { 89: 90: md = &gmu_core->gmu_globals[i]; 91: if (!md->size) 92: continue; 93: 94: desc.memdesc = md; 95: if (md == gmu->hfi.hfi_mem) 96: desc.type = SNAPSHOT_GMU_MEM_HFI; 97: else if (md == gmu->gmu_log) 98: desc.type = SNAPSHOT_GMU_MEM_LOG; 99: else if ((md == gmu->gmu_init_scratch) || (md == gmu->gpu_boot_scratch)) 100: desc.type = SNAPSHOT_GMU_MEM_WARMBOOT; 101: else if (md == gmu_core->vrb) 102: desc.type = SNAPSHOT_GMU_MEM_VRB; 103: else if (md == gmu_core->trace.md) 104: desc.type = SNAPSHOT_GMU_MEM_TRACE; 105: else 106: desc.type = SNAPSHOT_GMU_MEM_BIN_BLOCK; 107: 108: kgsl_snapshot_add_section(device, 109: KGSL_SNAPSHOT_SECTION_GMU_MEMORY, 110: snapshot, adreno_snapshot_gmu_mem, &desc); 111: } 112: } 113: 114: #define RSCC_OFFSET_DWORDS 0x14000 115: 116: static size_t gen8_snapshot_rscc_registers(struct kgsl_device *device, u8 *buf, 117: size_t remain, void *priv) 118: { --- FILE: \adreno_gen8_hfi.c | HITS: 4 --- MATCH LINES: 40 28: struct gen8_hfi *to_gen8_hfi(struct adreno_device *adreno_dev) 29: { 30: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 31: 32: return &gmu->hfi; 33: } 34: 35: /* Size in below functions are in unit of dwords */ 36: int gen8_hfi_queue_read(struct gen8_gmu_device *gmu, u32 queue_idx, 37: u32 *output, u32 max_size) 38: { 39: struct kgsl_device *device = KGSL_DEVICE(gen8_gmu_to_adreno(gmu)); 40: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 41: struct hfi_queue_table *tbl = mem_addr->hostptr; 42: struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx]; 43: u32 *queue; 44: u32 msg_hdr; 45: u32 i, read; 46: u32 size; 47: int result = 0; 48: 49: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 50: return -EINVAL; 51: 52: if (hdr->read_index == hdr->write_index) 53: return -ENODATA; 54: 55: /* Clear the output data before populating */ 56: memset(output, 0, max_size); 57: 58: queue = HOST_QUEUE_START_ADDR(mem_addr, queue_idx); 59: msg_hdr = queue[hdr->read_index]; 60: size = MSG_HDR_GET_SIZE(msg_hdr); 61: 62: if (size > (max_size >> 2)) { 63: dev_err(GMU_PDEV_DEV(device), 64: "HFI message too big: hdr:0x%x rd idx=%d\n", MATCH LINES: 187 175: gmu_core_regwrite(KGSL_DEVICE(adreno_dev), 176: GEN8_GMUCX_HOST2GMU_INTR_SET, 0x1); 177: 178: spin_unlock(&hfi->cmdq_lock); 179: 180: return ret; 181: } 182: 183: /* Sizes of the queue and message are in unit of dwords */ 184: static void init_queues(struct adreno_device *adreno_dev) 185: { 186: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 187: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 188: int i; 189: struct hfi_queue_table *tbl; 190: struct hfi_queue_header *hdr; 191: struct { 192: u32 idx; 193: u32 pri; 194: u32 status; 195: } queue[HFI_QUEUE_MAX] = { 196: { HFI_CMD_ID, HFI_CMD_PRI, HFI_QUEUE_STATUS_ENABLED }, 197: { HFI_MSG_ID, HFI_MSG_PRI, HFI_QUEUE_STATUS_ENABLED }, 198: { HFI_DBG_ID, HFI_DBG_PRI, HFI_QUEUE_STATUS_ENABLED }, 199: }; 200: 201: /* Fill Table Header */ 202: tbl = mem_addr->hostptr; 203: tbl->qtbl_hdr.version = 0; 204: tbl->qtbl_hdr.size = sizeof(struct hfi_queue_table) >> 2; 205: tbl->qtbl_hdr.qhdr0_offset = sizeof(struct hfi_queue_table_header) >> 2; 206: tbl->qtbl_hdr.qhdr_size = sizeof(struct hfi_queue_header) >> 2; 207: tbl->qtbl_hdr.num_q = HFI_QUEUE_MAX; 208: tbl->qtbl_hdr.num_active_q = HFI_QUEUE_MAX; 209: 210: memset(&tbl->qhdr[0], 0, sizeof(tbl->qhdr)); 211: MATCH LINES: 228 216: hdr->type = QUEUE_HDR_TYPE(queue[i].idx, queue[i].pri, 0, 0); 217: hdr->status = queue[i].status; 218: hdr->queue_size = HFI_QUEUE_SIZE >> 2; /* convert to dwords */ 219: } 220: } 221: 222: int gen8_hfi_init(struct adreno_device *adreno_dev) 223: { 224: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 225: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 226: struct gen8_hfi *hfi = &gmu->hfi; 227: 228: /* Allocates & maps memory for HFI */ 229: if (IS_ERR_OR_NULL(hfi->hfi_mem)) { 230: hfi->hfi_mem = gmu_core_reserve_kernel_block(device, 0, 231: HFIMEM_SIZE, GMU_NONCACHED_KERNEL, 0); 232: if (!IS_ERR(hfi->hfi_mem)) 233: init_queues(adreno_dev); 234: } 235: 236: return PTR_ERR_OR_ZERO(hfi->hfi_mem); 237: } 238: 239: int gen8_receive_ack_cmd(struct gen8_gmu_device *gmu, void *rcvd, 240: struct pending_cmd *ret_cmd) 241: { 242: struct adreno_device *adreno_dev = gen8_gmu_to_adreno(gmu); 243: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 244: u32 *ack = rcvd; 245: u32 hdr = ack[0]; 246: u32 req_hdr = ack[1]; 247: 248: if (ret_cmd == NULL) 249: return -EINVAL; 250: 251: if (CMP_HFI_ACK_HDR(ret_cmd->sent_hdr, req_hdr)) { 252: memcpy(&ret_cmd->results, ack, MSG_HDR_GET_SIZE(hdr) << 2); MATCH LINES: 723 711: { 712: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 713: 714: if ((gmu->idle_level == GPU_HW_MINBW) || (gmu->idle_level == GPU_HW_IFPC)) 715: return gen8_hfi_send_feature_ctrl(adreno_dev, 716: HFI_FEATURE_IFPC, 1, adreno_dev->ifpc_hyst); 717: return 0; 718: } 719: 720: static void reset_hfi_queues(struct adreno_device *adreno_dev) 721: { 722: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 723: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 724: struct hfi_queue_table *tbl = mem_addr->hostptr; 725: struct hfi_queue_header *hdr; 726: u32 i; 727: 728: /* Flush HFI queues */ 729: for (i = 0; i < HFI_QUEUE_MAX; i++) { 730: hdr = &tbl->qhdr[i]; 731: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 732: continue; 733: 734: hdr->read_index = hdr->write_index; 735: } 736: } 737: 738: /* Fill the entry and return the dword count written */ 739: static u32 _fill_table_entry(struct hfi_table_entry *entry, u32 count, 740: u32 stride_bytes, u32 *data) 741: { 742: entry->count = count; 743: entry->stride = stride_bytes >> 2; /* entry->stride is in dwords */ 744: memcpy(entry->data, data, stride_bytes * count); 745: 746: /* Return total dword count of entry + data */ 747: return (sizeof(*entry) >> 2) + (entry->count * entry->stride); --- FILE: \adreno_gen8_hfi.h | HITS: 1 --- MATCH LINES: 23 11: 12: /** 13: * struct gen8_hfi - HFI control structure 14: */ 15: struct gen8_hfi { 16: /** @irq: HFI interrupt line */ 17: int irq; 18: /** @seqnum: atomic counter that is incremented for each message sent. 19: * The value of the counter is used as sequence number for HFI message. 20: */ 21: atomic_t seqnum; 22: /** @hfi_mem: Memory descriptor for the hfi memory */ 23: struct kgsl_memdesc *hfi_mem; 24: /** @bw_table: HFI BW table buffer */ 25: struct hfi_bwtable_cmd bw_table; 26: /** @acd_table: HFI table for ACD data */ 27: struct hfi_acd_table_cmd acd_table; 28: /** @cmdq_lock: Spinlock for accessing the cmdq */ 29: spinlock_t cmdq_lock; 30: /** 31: * @wb_set_record_bitmask: Bitmask to enable or disable the recording 32: * of messages in the GMU scratch. 33: */ 34: unsigned long wb_set_record_bitmask[BITS_TO_LONGS(HFI_MAX_ID)]; 35: }; 36: 37: struct gen8_gmu_device; 38: 39: /* gen8_hfi_irq_handler - IRQ handler for HFI interripts */ 40: irqreturn_t gen8_hfi_irq_handler(int irq, void *data); 41: 42: /** 43: * gen8_hfi_start - Send the various HFIs during device boot up 44: * @adreno_dev: Pointer to the adreno device 45: * 46: * Return: 0 on success or negative error on failure 47: */ --- FILE: \adreno_gen8_hwsched.c | HITS: 9 --- MATCH LINES: 91 79: /* 80: * First try to dump ringbuffers using context bad HFI payloads 81: * because they have all the ringbuffer parameters. If ringbuffer 82: * payloads are not present, fall back to dumping ringbuffers 83: * based on MEMKIND_RB 84: */ 85: parse_payload = adreno_hwsched_parse_payload_rb(adreno_dev, snapshot); 86: 87: if (parse_payload) 88: skip_memkind_rb = true; 89: 90: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 91: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 92: 93: if (entry->desc.mem_kind == HFI_MEMKIND_RB && !skip_memkind_rb) 94: kgsl_snapshot_add_section(device, 95: KGSL_SNAPSHOT_SECTION_RB_V2, 96: snapshot, adreno_hwsched_snapshot_rb, 97: entry->md); 98: 99: if (entry->desc.mem_kind == HFI_MEMKIND_SCRATCH) 100: kgsl_snapshot_add_section(device, 101: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 102: snapshot, adreno_snapshot_global, 103: entry->md); 104: 105: if (entry->desc.mem_kind == HFI_MEMKIND_PROFILE) 106: kgsl_snapshot_add_section(device, 107: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 108: snapshot, adreno_snapshot_global, 109: entry->md); 110: 111: if (entry->desc.mem_kind == HFI_MEMKIND_CSW_SMMU_INFO) 112: kgsl_snapshot_add_section(device, 113: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 114: snapshot, adreno_snapshot_global, 115: entry->md); MATCH LINES: 136 124: snapshot, adreno_snapshot_global, 125: entry->md); 126: 127: if (entry->desc.mem_kind == HFI_MEMKIND_AQE_BUFFER) 128: kgsl_snapshot_add_section(device, 129: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 130: snapshot, adreno_hwsched_snapshot_aqe_buffer, 131: entry->md); 132: 133: if (entry->desc.mem_kind == HFI_MEMKIND_HW_FENCE) { 134: struct gmu_mem_type_desc desc; 135: 136: desc.memdesc = entry->md; 137: desc.type = SNAPSHOT_GMU_MEM_HW_FENCE; 138: kgsl_snapshot_add_section(device, 139: KGSL_SNAPSHOT_SECTION_GMU_MEMORY, 140: snapshot, adreno_snapshot_gmu_mem, &desc); 141: } 142: 143: } 144: 145: adreno_hwsched_snapshot_context_queue(device, snapshot); 146: } 147: 148: static void _get_hw_fence_entries(struct adreno_device *adreno_dev) 149: { 150: struct device_node *node = NULL; 151: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 152: u32 shadow_num_entries = 0; 153: 154: if (!ADRENO_FEATURE(adreno_dev, ADRENO_HW_FENCE)) 155: return; 156: 157: node = of_find_node_by_name(NULL, "qcom,hw-fence"); 158: if (!node) 159: return; 160: MATCH LINES: 611, 613, 620, 622, 627, 629 599: gen8_hwsched_gmu_suspend(adreno_dev, false); 600: 601: return ret; 602: } 603: 604: void gen8_hwsched_init_ucode_regs(struct adreno_device *adreno_dev) 605: { 606: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 607: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 608: 609: /* Program the ucode base for CP */ 610: kgsl_regwrite(device, GEN8_CP_SQE_INSTR_BASE_LO, 611: lower_32_bits(fw->memdesc->gpuaddr)); 612: kgsl_regwrite(device, GEN8_CP_SQE_INSTR_BASE_HI, 613: upper_32_bits(fw->memdesc->gpuaddr)); 614: 615: if (ADRENO_FEATURE(adreno_dev, ADRENO_AQE)) { 616: fw = ADRENO_FW(adreno_dev, ADRENO_FW_AQE); 617: 618: /* Program the ucode base for AQE0 (BV coprocessor) */ 619: kgsl_regwrite(device, GEN8_CP_AQE_INSTR_BASE_LO_0, 620: lower_32_bits(fw->memdesc->gpuaddr)); 621: kgsl_regwrite(device, GEN8_CP_AQE_INSTR_BASE_HI_0, 622: upper_32_bits(fw->memdesc->gpuaddr)); 623: 624: /* Program the ucode base for AQE1 (LPAC coprocessor) */ 625: if (adreno_dev->lpac_enabled) { 626: kgsl_regwrite(device, GEN8_CP_AQE_INSTR_BASE_LO_1, 627: lower_32_bits(fw->memdesc->gpuaddr)); 628: kgsl_regwrite(device, GEN8_CP_AQE_INSTR_BASE_HI_1, 629: upper_32_bits(fw->memdesc->gpuaddr)); 630: } 631: } 632: } 633: 634: static int gen8_hwsched_gpu_boot(struct adreno_device *adreno_dev) 635: { 636: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 637: int ret; 638: 639: ret = kgsl_mmu_start(device); 640: if (ret) 641: goto err; 642: 643: ret = gen8_gmu_oob_set(device, oob_gpu); 644: if (ret) 645: goto err; 646: 647: /* Clear the busy_data stats - we're starting over from scratch */ 648: memset(&adreno_dev->busy_data, 0, sizeof(adreno_dev->busy_data)); 649: 650: gen8_start(adreno_dev); 651: 652: /* Re-initialize the coresight registers if applicable */ 653: adreno_coresight_start(adreno_dev); MATCH LINES: 2219 2207: 2208: if (!IS_ERR_OR_NULL(gmu_core->trace.md)) { 2209: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, 2210: KGSL_GMU_TRACE_ENTRY, 2211: gmu_core->trace.md->hostptr, 2212: gmu_core->trace.md->size); 2213: if (ret) 2214: return ret; 2215: } 2216: 2217: /* Dump HFI hwsched global mem alloc entries */ 2218: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 2219: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 2220: char hfi_minidump_str[MAX_VA_MINIDUMP_STR_LEN] = {0}; 2221: char name[MAX_VA_MINIDUMP_STR_LEN]; 2222: u32 rb_id = 0; 2223: 2224: if (!hfi_get_minidump_string(entry->desc.mem_kind, 2225: &hfi_minidump_str[0], 2226: sizeof(hfi_minidump_str), &rb_id)) { 2227: snprintf(name, sizeof(name), "kgsl_global_%s", hfi_minidump_str); 2228: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, 2229: name, 2230: entry->md->hostptr, 2231: entry->md->size); 2232: if (ret) 2233: return ret; 2234: } 2235: } 2236: 2237: if (!IS_ERR_OR_NULL(hw_hfi->big_ib)) { 2238: ret = kgsl_add_va_to_minidump(adreno_dev->dev.dev, 2239: KGSL_HFI_BIG_IB_ENTRY, 2240: hw_hfi->big_ib->hostptr, 2241: hw_hfi->big_ib->size); 2242: if (ret) 2243: return ret; --- FILE: \adreno_gen8_hwsched_hfi.c | HITS: 18 --- MATCH LINES: 551, 573 539: dev_crit_ratelimited(gmu_pdev_dev, "Unknown GPU fault: %u\n", 540: cmd->error); 541: break; 542: } 543: 544: /* Return true for fatal errors to perform recovery sequence */ 545: return true; 546: } 547: 548: static bool is_queue_empty(struct adreno_device *adreno_dev, u32 queue_idx) 549: { 550: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 551: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 552: struct hfi_queue_table *tbl = mem_addr->hostptr; 553: struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx]; 554: 555: if (hdr->status == HFI_QUEUE_STATUS_DISABLED) 556: return true; 557: 558: if (hdr->read_index == hdr->write_index) 559: return true; 560: 561: /* 562: * This is to ensure that the queue is not read speculatively before the queue empty 563: * condition is evaluated 564: */ 565: rmb(); 566: 567: return false; 568: } 569: 570: static u32 peek_next_header(struct adreno_device *adreno_dev, struct gen8_gmu_device *gmu, 571: u32 queue_idx) 572: { 573: struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem; 574: struct hfi_queue_table *tbl = mem_addr->hostptr; 575: struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx]; 576: u32 *queue; 577: 578: if (is_queue_empty(adreno_dev, queue_idx)) 579: return 0; 580: 581: queue = HOST_QUEUE_START_ADDR(mem_addr, queue_idx); 582: 583: return queue[hdr->read_index]; 584: } 585: 586: static void process_ctx_bad(struct adreno_device *adreno_dev) 587: { 588: /* Non fatal RBBM error interrupts don't go through reset and recovery */ 589: if (!log_gpu_fault(adreno_dev)) { 590: memset(adreno_dev->hwsched.ctxt_bad, 0x0, HFI_MAX_MSG_SIZE); 591: return; 592: } 593: 594: adreno_dev->hwsched.reset_type = gen8_hwsched_lookup_key_value(adreno_dev, 595: PAYLOAD_FAULT_RESET_POLICY, KEY_GPU_RESET_POLICY); 596: 597: gen8_hwsched_fault(adreno_dev, ADRENO_HARD_FAULT); MATCH LINES: 1826 1814: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1815: struct gmu_core_device *gmu_core = &device->gmu_core; 1816: 1817: if (gmu_core->warmboot_enabled && test_bit(GMU_PRIV_WARMBOOT_GMU_INIT_DONE, &gmu->flags) 1818: && test_bit(GMU_PRIV_WARMBOOT_GPU_BOOT_DONE, &gmu->flags) && 1819: !test_bit(GMU_FORCE_COLDBOOT, &device->gmu_core.flags)) 1820: return true; 1821: 1822: return false; 1823: } 1824: 1825: static int gen8_hwsched_hfi_send_warmboot_cmd(struct adreno_device *adreno_dev, 1826: struct kgsl_memdesc *desc, u32 flag, bool async, struct pending_cmd *ack) 1827: { 1828: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1829: struct gmu_core_device *gmu_core = &device->gmu_core; 1830: struct hfi_warmboot_scratch_cmd cmd = {0}; 1831: int ret; 1832: 1833: if (!gmu_core->warmboot_enabled) 1834: return 0; 1835: 1836: cmd.scratch_addr = desc->gmuaddr; 1837: cmd.scratch_size = desc->size; 1838: cmd.flags = flag; 1839: 1840: ret = CMD_MSG_HDR(cmd, H2F_MSG_WARMBOOT_CMD); 1841: if (ret) 1842: return ret; 1843: 1844: if (async) 1845: return gen8_hfi_send_cmd_async(adreno_dev, &cmd, sizeof(cmd)); 1846: 1847: return gen8_hfi_send_generic_req_v5(adreno_dev, &cmd, ack, sizeof(cmd)); 1848: } 1849: 1850: static int gen8_hwsched_hfi_warmboot_gpu_cmd(struct adreno_device *adreno_dev, MATCH LINES: 2021 2009: * register are ignored. At this point, the GPU should be in unsecure 2010: * mode, so program the RB_GC_GMEM_PROTECT register. 2011: */ 2012: if (!ret) 2013: gen8_set_gmem_protect(adreno_dev); 2014: 2015: /* 2016: * All registers must be written before this point so that we don't 2017: * miss any register programming when we patch the power up register 2018: * list. 2019: */ 2020: if (!adreno_dev->patch_reglist && 2021: (adreno_dev->pwrup_reglist->gpuaddr != 0)) { 2022: gen8_patch_pwrup_reglist(adreno_dev); 2023: adreno_dev->patch_reglist = true; 2024: } 2025: 2026: return ret; 2027: } 2028: 2029: static int gen8_hwsched_hfi_set_tunables(struct adreno_device *adreno_dev, u32 type, u32 subtype, 2030: u32 val, u32 *ret) 2031: { 2032: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 2033: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2034: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 2035: struct pending_cmd pending_ack; 2036: int rc; 2037: u32 seqnum; 2038: struct hfi_set_value_cmd cmd = { 2039: .type = type, 2040: .subtype = subtype, 2041: .data = val, 2042: }; 2043: 2044: rc = CMD_MSG_HDR(cmd, H2F_MSG_SET_VALUE); 2045: if (rc) MATCH LINES: 2993 2981: } 2982: 2983: void gen8_hwsched_hfi_remove(struct adreno_device *adreno_dev) 2984: { 2985: struct gen8_hwsched_hfi *hw_hfi = to_gen8_hwsched_hfi(adreno_dev); 2986: 2987: if (hw_hfi->f2h_task) 2988: kthread_stop(hw_hfi->f2h_task); 2989: } 2990: 2991: static void init_gmu_context_queue(struct adreno_context *drawctxt) 2992: { 2993: struct kgsl_memdesc *md = &drawctxt->gmu_context_queue; 2994: struct gmu_context_queue_header *hdr = md->hostptr; 2995: 2996: hdr->start_addr = md->gmuaddr + sizeof(*hdr); 2997: hdr->queue_size = (md->size - sizeof(*hdr)) >> 2; 2998: hdr->hw_fence_buffer_va = drawctxt->gmu_hw_fence_queue.gmuaddr; 2999: hdr->hw_fence_buffer_size = drawctxt->gmu_hw_fence_queue.size; 3000: } 3001: 3002: static int allocate_context_queues(struct adreno_device *adreno_dev, 3003: struct adreno_context *drawctxt) 3004: { 3005: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3006: int ret = 0; 3007: 3008: if (test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags) && 3009: !drawctxt->gmu_hw_fence_queue.gmuaddr) { 3010: ret = gmu_core_alloc_kernel_block( 3011: device, &drawctxt->gmu_hw_fence_queue, 3012: HW_FENCE_QUEUE_SIZE, GMU_NONCACHED_KERNEL, 3013: IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV); 3014: if (ret) { 3015: memset(&drawctxt->gmu_hw_fence_queue, 0x0, 3016: sizeof(drawctxt->gmu_hw_fence_queue)); 3017: return ret; MATCH LINES: 3079, 3093 3067: cmd.ctxt_bank = kgsl_mmu_pagetable_get_context_bank(pt, context); 3068: 3069: return gen8_hfi_send_cmd_async(adreno_dev, &cmd, sizeof(cmd)); 3070: } 3071: 3072: static int send_context_pointers(struct adreno_device *adreno_dev, 3073: struct kgsl_context *context) 3074: { 3075: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3076: struct hfi_context_pointers_cmd cmd = {0}; 3077: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 3078: struct kgsl_process_private *proc_priv = drawctxt->base.proc_priv; 3079: struct kgsl_memdesc md = proc_priv->profile.md; 3080: int ret; 3081: 3082: ret = CMD_MSG_HDR(cmd, H2F_MSG_CONTEXT_POINTERS); 3083: if (ret) 3084: return ret; 3085: 3086: cmd.ctxt_id = context->id; 3087: cmd.sop_addr = MEMSTORE_ID_GPU_ADDR(device, context->id, soptimestamp); 3088: cmd.eop_addr = MEMSTORE_ID_GPU_ADDR(device, context->id, eoptimestamp); 3089: cmd.version = 1; 3090: cmd.dcvs_profile_addr = GMU_BUF_ADDR(md); 3091: if (context->user_ctxt_record) 3092: cmd.user_ctxt_record_addr = 3093: context->user_ctxt_record->memdesc.gpuaddr; 3094: 3095: cmd.gmu_context_queue_addr = drawctxt->gmu_context_queue.gmuaddr; 3096: 3097: return gen8_hfi_send_cmd_async(adreno_dev, &cmd, sizeof(cmd)); 3098: } 3099: 3100: static int hfi_context_register(struct adreno_device *adreno_dev, 3101: struct kgsl_context *context) 3102: { 3103: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 3104: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 3105: struct kgsl_process_private *proc_priv = drawctxt->base.proc_priv; 3106: int ret; 3107: 3108: if (context->gmu_registered) 3109: return 0; 3110: 3111: ret = send_context_register(adreno_dev, context); 3112: if (ret) { 3113: dev_err(GMU_PDEV_DEV(device), 3114: "Unable to register context %u: %d\n", 3115: context->id, ret); 3116: 3117: if (device->gmu_fault) MATCH LINES: 3160, 3177 3148: 3149: return 0; 3150: } 3151: 3152: static void populate_ibs(struct adreno_device *adreno_dev, 3153: struct hfi_submit_cmd *cmd, struct kgsl_drawobj_cmd *cmdobj) 3154: { 3155: struct hfi_issue_ib *issue_ib; 3156: struct kgsl_memobj_node *ib; 3157: 3158: if (cmdobj->numibs > HWSCHED_MAX_DISPATCH_NUMIBS) { 3159: struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev); 3160: struct kgsl_memdesc *big_ib; 3161: 3162: if (test_bit(CMDOBJ_RECURRING_START, &cmdobj->priv)) 3163: big_ib = hfi->big_ib_recurring; 3164: else 3165: big_ib = hfi->big_ib; 3166: /* 3167: * The dispatcher ensures that there is only one big IB inflight 3168: */ 3169: cmd->big_ib_gmu_va = big_ib->gmuaddr; 3170: cmd->flags |= CMDBATCH_INDIRECT; 3171: issue_ib = big_ib->hostptr; 3172: } else { 3173: issue_ib = (struct hfi_issue_ib *)&cmd[1]; 3174: } 3175: 3176: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 3177: issue_ib->addr = ib->gpuaddr; 3178: issue_ib->size = ib->size; 3179: issue_ib++; 3180: } 3181: 3182: cmd->numibs = cmdobj->numibs; 3183: } 3184: 3185: #define HFI_DSP_IRQ_BASE 2 3186: 3187: #define DISPQ_IRQ_BIT(_idx) BIT((_idx) + HFI_DSP_IRQ_BASE) 3188: #define DISPQ_SYNC_IRQ_BIT(_idx) ((DISPQ_IRQ_BIT(_idx) << (KGSL_PRIORITY_MAX_RB_LEVELS + 1))) 3189: 3190: 3191: static u32 get_irq_bit(struct adreno_device *adreno_dev, struct kgsl_context *context) 3192: { 3193: if (adreno_is_preemption_enabled(adreno_dev)) 3194: return adreno_get_level(context); 3195: 3196: if (kgsl_context_is_lpac(context)) 3197: return 1; 3198: 3199: return 0; 3200: } 3201: MATCH LINES: 3878, 3879, 3880, 3881 3866: cmd->ts = drawobj->timestamp; 3867: 3868: if (test_bit(CMDOBJ_SKIP, &cmdobj->priv)) 3869: goto skipib; 3870: 3871: populate_ibs(adreno_dev, cmd, cmdobj); 3872: 3873: if ((drawobj->flags & KGSL_DRAWOBJ_PROFILING) && 3874: cmdobj->profiling_buf_entry) { 3875: 3876: time.drawobj = drawobj; 3877: 3878: cmd->profile_gpuaddr_lo = 3879: lower_32_bits(cmdobj->profiling_buffer_gpuaddr); 3880: cmd->profile_gpuaddr_hi = 3881: upper_32_bits(cmdobj->profiling_buffer_gpuaddr); 3882: 3883: /* Indicate to GMU to do user profiling for this submission */ 3884: cmd->flags |= CMDBATCH_PROFILING; 3885: } 3886: 3887: if (test_and_clear_bit(CMDOBJ_NOP_SUBMISSION, &cmdobj->priv)) 3888: cmd->flags |= CMDBATCH_NOP_SUBMISSION; 3889: 3890: if (drawobj->flags & KGSL_DRAWOBJ_USES_MALU) 3891: cmd->flags |= CMDBATCH_USES_MALU; 3892: skipib: 3893: adreno_drawobj_set_constraint(KGSL_DEVICE(adreno_dev), drawobj); 3894: 3895: cmd->hdr = CREATE_MSG_HDR(H2F_MSG_ISSUE_CMD, HFI_MSG_CMD); 3896: seqnum = atomic_inc_return(&adreno_dev->hwsched.submission_seqnum); 3897: cmd->hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd->hdr, seqnum, cmd_sizebytes >> 2); 3898: 3899: ret = adreno_gmu_context_queue_write(adreno_dev, &drawctxt->gmu_context_queue, 3900: (u32 *)cmd, cmd_sizebytes, drawobj, &time); 3901: if (ret) 3902: return ret; 3903: 3904: hdr = drawctxt->gmu_context_queue.hostptr; 3905: /* The last sync object has been retired by the GMU */ MATCH LINES: 4203, 4206 4191: struct kgsl_device *device = context->device; 4192: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4193: int ret = 0; 4194: 4195: kgsl_mutex_lock(&device->mutex); 4196: 4197: ret = send_context_unregister_hfi(adreno_dev, context, 4198: drawctxt->internal_timestamp); 4199: 4200: if (ret) 4201: goto out; 4202: 4203: kgsl_sharedmem_writel(device->memstore, 4204: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), drawctxt->timestamp); 4205: 4206: kgsl_sharedmem_writel(device->memstore, 4207: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), drawctxt->timestamp); 4208: 4209: adreno_profile_process_results(adreno_dev); 4210: context->gmu_registered = false; 4211: 4212: out: 4213: WARN_RATELIMIT(!list_empty(&drawctxt->hw_fence_list) || 4214: !list_empty(&drawctxt->hw_fence_inflight_list), 4215: "detached ctx:%u has active hw fences\n", 4216: context->id); 4217: 4218: kgsl_mutex_unlock(&device->mutex); 4219: } 4220: 4221: static int handle_hw_fences_after_soft_reset(struct adreno_device *adreno_dev, 4222: struct adreno_context *drawctxt) 4223: { 4224: int ret = 0; 4225: 4226: if (!drawctxt) 4227: return ret; 4228: 4229: ret = gen8_hwsched_process_detached_hw_fences(adreno_dev); 4230: if (ret) MATCH LINES: 4381, 4385 4369: if (ctx_guilty) { 4370: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 4371: 4372: ret = handle_hw_fences_after_soft_reset(adreno_dev, drawctxt); 4373: if (ret) 4374: goto done; 4375: 4376: ret = send_context_unregister_hfi(adreno_dev, context, 4377: drawctxt->internal_timestamp); 4378: if (ret) 4379: goto done; 4380: 4381: kgsl_sharedmem_writel(device->memstore, 4382: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 4383: drawctxt->timestamp); 4384: 4385: kgsl_sharedmem_writel(device->memstore, 4386: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 4387: drawctxt->timestamp); 4388: 4389: adreno_profile_process_results(adreno_dev); 4390: 4391: context->gmu_registered = false; 4392: } 4393: 4394: /* 4395: * At this point it is safe to assume that we recovered. Setting 4396: * this field allows us to take a new snapshot for the next failure 4397: * if we are prioritizing the first unrecoverable snapshot. 4398: */ 4399: if (device->snapshot) 4400: device->snapshot->recovered = true; 4401: 4402: device->reset_counter++; 4403: done: 4404: if (ret) 4405: dev_err(device->dev, "GPU soft reset failed: %d\n", ret); 4406: 4407: return ret; 4408: } 4409: MATCH LINES: 4480 4468: done: 4469: _disable_hw_fence_throttle(adreno_dev, true); 4470: 4471: return ret; 4472: } 4473: 4474: int gen8_hwsched_set_dcvs_profile(struct adreno_device *adreno_dev, 4475: struct kgsl_process_private *proc_priv) 4476: { 4477: struct hfi_profile_register cmd = {0}; 4478: struct hfi_msg_platform msg = {0}; 4479: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); 4480: struct kgsl_memdesc md = proc_priv->profile.md; 4481: int ret; 4482: 4483: /* Only send HFI if device is not in SLUMBER */ 4484: if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags)) 4485: return 0; 4486: 4487: msg.sub_type = H2F_ST_MSG_PROFILE_REGISTER; 4488: CMD_MSG_HDR(msg, H2F_MSG_PLATFORM_LA); 4489: cmd.header = msg; 4490: cmd.version = 2; 4491: cmd.gmu_addr = GMU_BUF_ADDR(md); 4492: cmd.attrs_addr = md.gmuaddr; 4493: 4494: ret = gen8_hfi_send_cmd_async(adreno_dev, &cmd, sizeof(cmd)); 4495: if (!ret) { 4496: proc_priv->profile.gmu_registered = true; 4497: proc_priv->profile.user_profile_registered = true; 4498: } 4499: 4500: return ret; 4501: } --- FILE: \adreno_gen8_hwsched_hfi.h | HITS: 2 --- MATCH LINES: 106, 108 94: struct gen8_hwsched_hfi { 95: /** @irq_mask: Store the hfi interrupt mask */ 96: u32 irq_mask; 97: /** @msglock: To protect the list of un-ACKed hfi packets */ 98: rwlock_t msglock; 99: /** @msglist: List of un-ACKed hfi packets */ 100: struct list_head msglist; 101: /** @f2h_task: Task for processing gmu fw to host packets */ 102: struct task_struct *f2h_task; 103: /** @f2h_wq: Waitqueue for the f2h_task */ 104: wait_queue_head_t f2h_wq; 105: /** @big_ib: GMU buffer to hold big IBs */ 106: struct kgsl_memdesc *big_ib; 107: /** @big_ib_recurring: GMU buffer to hold big recurring IBs */ 108: struct kgsl_memdesc *big_ib_recurring; 109: /** @msg_mutex: Mutex for accessing the msgq */ 110: struct mutex msgq_mutex; 111: /** 112: * @hw_fence_timer: Timer to trigger fault if unack'd hardware fence count does'nt drop 113: * to a desired threshold in given amount of time 114: */ 115: struct timer_list hw_fence_timer; 116: /** 117: * @hw_fence_ws: Work struct that gets scheduled when hw_fence_timer expires 118: */ 119: struct work_struct hw_fence_ws; 120: /** @detached_hw_fences_list: List of hardware fences belonging to detached contexts */ 121: struct list_head detached_hw_fence_list; 122: /** @defer_hw_fence_work: The work structure to send deferred hardware fences to GMU */ 123: struct kthread_work defer_hw_fence_work; 124: }; 125: 126: struct kgsl_drawobj_cmd; 127: 128: /** 129: * gen8_hwsched_hfi_probe - Probe hwsched hfi resources 130: * @adreno_dev: Pointer to adreno device structure 131: * 132: * Return: 0 on success and negative error on failure. --- FILE: \adreno_gen8_preempt.c | HITS: 41 --- MATCH LINES: 211 199: return rb; 200: } 201: 202: return NULL; 203: } 204: 205: void gen8_preemption_trigger(struct adreno_device *adreno_dev, bool atomic) 206: { 207: const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev); 208: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 209: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 210: struct adreno_ringbuffer *next; 211: u64 ttbr0, gpuaddr; 212: u32 contextidr, cntl; 213: unsigned long flags; 214: struct adreno_preemption *preempt = &adreno_dev->preempt; 215: 216: /* Put ourselves into a possible trigger state */ 217: if (!adreno_move_preempt_state(adreno_dev, 218: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START)) 219: return; 220: 221: /* Get the next ringbuffer to preempt in */ 222: next = gen8_next_ringbuffer(adreno_dev); 223: 224: /* 225: * Nothing to do if every ringbuffer is empty or if the current 226: * ringbuffer is the only active one 227: */ 228: if (next == NULL || next == adreno_dev->cur_rb) { 229: /* 230: * Update any critical things that might have been skipped while 231: * we were looking for a new ringbuffer 232: */ 233: 234: if (next != NULL) { 235: _update_wptr(adreno_dev, false, atomic); MATCH LINES: 256, 258, 261, 268, 270, 274, 298, 316, 323, 329, 336, 342, 368 244: 245: /* Turn off the dispatcher timer */ 246: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 247: 248: /* 249: * This is the most critical section - we need to take care not to race 250: * until we have programmed the CP for the switch 251: */ 252: 253: spin_lock_irqsave(&next->preempt_lock, flags); 254: 255: /* Get the pagetable from the pagetable info. */ 256: kgsl_sharedmem_readq(device->scratch, &ttbr0, 257: SCRATCH_RB_OFFSET(next->id, ttbr0)); 258: kgsl_sharedmem_readl(device->scratch, &contextidr, 259: SCRATCH_RB_OFFSET(next->id, contextidr)); 260: 261: kgsl_sharedmem_writel(next->preemption_desc, 262: PREEMPT_RECORD(wptr), next->wptr); 263: 264: spin_unlock_irqrestore(&next->preempt_lock, flags); 265: 266: /* And write it to the smmu info */ 267: if (kgsl_mmu_is_perprocess(&device->mmu)) { 268: kgsl_sharedmem_writeq(iommu->smmu_info, 269: PREEMPT_SMMU_RECORD(ttbr0), ttbr0); 270: kgsl_sharedmem_writel(iommu->smmu_info, 271: PREEMPT_SMMU_RECORD(context_idr), contextidr); 272: } 273: 274: kgsl_sharedmem_readq(preempt->scratch, &gpuaddr, 275: next->id * sizeof(u64)); 276: 277: /* 278: * Set a keepalive bit before the first preemption register write. 279: * This is required since while each individual write to the context 280: * switch registers will wake the GPU from collapse, it will not in 281: * itself cause GPU activity. Thus, the GPU could technically be 282: * re-collapsed between subsequent register writes leading to a 283: * prolonged preemption sequence. The keepalive bit prevents any 284: * further power collapse while it is set. 285: * It is more efficient to use a keepalive+wake-on-fence approach here 286: * rather than an OOB. Both keepalive and the fence are effectively 287: * free when the GPU is already powered on, whereas an OOB requires an 288: * unconditional handshake with the GMU. 289: */ 290: _power_collapse_set(adreno_dev, true); 291: 292: /* 293: * Fenced writes on this path will make sure the GPU is woken up 294: * in case it was power collapsed by the GMU. 295: */ 296: if (gen8_fenced_write(adreno_dev, 297: GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_LO, 298: lower_32_bits(next->preemption_desc->gpuaddr), 299: FENCE_STATUS_WRITEDROPPED1_MASK)) 300: goto err; 301: 302: /* 303: * Above fence writes will make sure GMU comes out of 304: * IFPC state if its was in IFPC state but it doesn't 305: * guarantee that GMU FW actually moved to ACTIVE state 306: * i.e. wake-up from IFPC is complete. 307: * Wait for GMU to move to ACTIVE state before triggering 308: * preemption. This is require to make sure CP doesn't 309: * interrupt GMU during wake-up from IFPC. 310: */ 311: if (!atomic && gmu_core_dev_wait_for_active_transition(device)) 312: goto err; 313: 314: if (gen8_fenced_write(adreno_dev, 315: GEN8_CP_CONTEXT_SWITCH_PNSR_ADDR_HI, 316: upper_32_bits(next->preemption_desc->gpuaddr), 317: FENCE_STATUS_WRITEDROPPED1_MASK)) 318: goto err; 319: 320: if (kgsl_mmu_is_secured(&device->mmu)) { 321: if (gen8_fenced_write(adreno_dev, 322: GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_LO, 323: lower_32_bits(next->secure_preemption_desc->gpuaddr), 324: FENCE_STATUS_WRITEDROPPED1_MASK)) 325: goto err; 326: 327: if (gen8_fenced_write(adreno_dev, 328: GEN8_CP_CONTEXT_SWITCH_PSR_ADDR_HI, 329: upper_32_bits(next->secure_preemption_desc->gpuaddr), 330: FENCE_STATUS_WRITEDROPPED1_MASK)) 331: goto err; 332: } 333: 334: if (gen8_fenced_write(adreno_dev, 335: GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_LO, 336: lower_32_bits(gpuaddr), 337: FENCE_STATUS_WRITEDROPPED1_MASK)) 338: goto err; 339: 340: if (gen8_fenced_write(adreno_dev, 341: GEN8_CP_CONTEXT_SWITCH_NPR_ADDR_HI, 342: upper_32_bits(gpuaddr), 343: FENCE_STATUS_WRITEDROPPED1_MASK)) 344: goto err; 345: 346: adreno_dev->next_rb = next; 347: 348: /* Start the timer to detect a stuck preemption */ 349: mod_timer(&adreno_dev->preempt.timer, 350: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 351: 352: cntl = (preempt->preempt_level << 6) | 0x01; 353: 354: /* Skip save/restore during L1 preemption */ 355: if (preempt->skipsaverestore) 356: cntl |= (1 << 9); 357: 358: /* Enable GMEM save/restore across preemption */ 359: if (preempt->usesgmem) 360: cntl |= (1 << 8); 361: 362: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 363: cntl, 0); 364: 365: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 366: 367: if (gen8_core->qos_value) 368: kgsl_sharedmem_writel(preempt->scratch, 369: PREEMPT_SCRATCH_OFFSET(QOS_VALUE_IDX), 370: gen8_core->qos_value[next->id]); 371: 372: /* Trigger the preemption */ 373: if (gen8_fenced_write(adreno_dev, GEN8_CP_CONTEXT_SWITCH_CNTL, cntl, 374: FENCE_STATUS_WRITEDROPPED1_MASK)) { 375: adreno_dev->next_rb = NULL; 376: kgsl_delete_timer(&adreno_dev->preempt.timer); 377: goto err; 378: } 379: 380: return; 381: err: 382: /* If fenced write fails, take inline snapshot and trigger recovery */ 383: if (!in_interrupt()) { 384: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE); 385: adreno_scheduler_fault(adreno_dev, 386: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 387: } else { 388: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT); 389: } 390: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 391: /* Clear the keep alive */ 392: _power_collapse_set(adreno_dev, false); MATCH LINES: 545, 548, 552, 553, 564, 565 533: return 0; 534: 535: if (test_and_set_bit(ADRENO_RB_SET_PSEUDO_DONE, &rb->flags)) 536: goto done; 537: 538: *cmds++ = cp_type7_packet(CP_THREAD_CONTROL, 1); 539: *cmds++ = CP_SET_THREAD_BR; 540: 541: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, count); 542: 543: /* NULL SMMU_INFO buffer - we track in KMD */ 544: *cmds++ = SET_PSEUDO_SMMU_INFO; 545: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0); 546: 547: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR; 548: cmds += cp_gpuaddr(adreno_dev, cmds, rb->preemption_desc->gpuaddr); 549: 550: if (kgsl_mmu_is_secured(&device->mmu)) { 551: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR; 552: cmds += cp_gpuaddr(adreno_dev, cmds, 553: rb->secure_preemption_desc->gpuaddr); 554: } 555: 556: /* 557: * There is no need to specify this address when we are about to 558: * trigger preemption. This is because CP internally stores this 559: * address specified here in the CP_SET_PSEUDO_REGISTER payload to 560: * the context record and thus knows from where to restore 561: * the saved perfcounters for the new ringbuffer. 562: */ 563: *cmds++ = SET_PSEUDO_COUNTER; 564: cmds += cp_gpuaddr(adreno_dev, cmds, 565: rb->perfcounter_save_restore_desc->gpuaddr); 566: 567: done: 568: if (drawctxt) { 569: cmds += adreno_prepare_preib_preempt_scratch(adreno_dev, drawctxt, cmds); 570: cmds += adreno_prepare_preib_postamble_scratch(adreno_dev, cmds); 571: } 572: 573: return (u32) (cmds - cmds_orig); 574: } 575: 576: u32 gen8_preemption_post_ibsubmit(struct adreno_device *adreno_dev, 577: u32 *cmds) 578: { 579: u32 index = 0; 580: 581: if (!adreno_is_preemption_enabled(adreno_dev)) 582: return 0; 583: 584: if (adreno_dev->cur_rb) { 585: u64 dest = PREEMPT_SCRATCH_ADDR(adreno_dev, adreno_dev->cur_rb->id); 586: 587: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 4); 588: cmds[index++] = lower_32_bits(dest); 589: cmds[index++] = upper_32_bits(dest); MATCH LINES: 620, 622, 626, 628, 632, 635, 639, 641, 656, 658, 660, 663, 664, 665, 700, 707, 715, 727, 743, 755, 758 608: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 609: struct adreno_ringbuffer *rb; 610: u32 i; 611: 612: if (!adreno_is_preemption_enabled(adreno_dev)) 613: return; 614: 615: /* Force the state to be clear */ 616: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 617: 618: if (kgsl_mmu_is_perprocess(&device->mmu)) { 619: /* smmu_info is allocated and mapped in gen8_preemption_iommu_init */ 620: kgsl_sharedmem_writel(iommu->smmu_info, 621: PREEMPT_SMMU_RECORD(magic), GEN8_CP_SMMU_INFO_MAGIC_REF); 622: kgsl_sharedmem_writeq(iommu->smmu_info, 623: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 624: 625: /* The CP doesn't use the asid record, so poison it */ 626: kgsl_sharedmem_writel(iommu->smmu_info, 627: PREEMPT_SMMU_RECORD(asid), 0xdecafbad); 628: kgsl_sharedmem_writel(iommu->smmu_info, 629: PREEMPT_SMMU_RECORD(context_idr), 0); 630: 631: kgsl_regwrite(device, GEN8_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 632: lower_32_bits(iommu->smmu_info->gpuaddr)); 633: 634: kgsl_regwrite(device, GEN8_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 635: upper_32_bits(iommu->smmu_info->gpuaddr)); 636: } 637: 638: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 639: kgsl_sharedmem_writel(rb->preemption_desc, 640: PREEMPT_RECORD(rptr), 0); 641: kgsl_sharedmem_writel(rb->preemption_desc, 642: PREEMPT_RECORD(wptr), 0); 643: 644: adreno_ringbuffer_set_pagetable(device, rb, 645: device->mmu.defaultpagetable); 646: 647: clear_bit(ADRENO_RB_SET_PSEUDO_DONE, &rb->flags); 648: } 649: } 650: 651: static void reset_rb_preempt_record(struct adreno_device *adreno_dev, 652: struct adreno_ringbuffer *rb) 653: { 654: memset(rb->preemption_desc->hostptr, 0x0, rb->preemption_desc->size); 655: 656: kgsl_sharedmem_writel(rb->preemption_desc, 657: PREEMPT_RECORD(magic), GEN8_CP_CTXRECORD_MAGIC_REF); 658: kgsl_sharedmem_writel(rb->preemption_desc, 659: PREEMPT_RECORD(cntl), GEN8_CP_RB_CNTL_DEFAULT); 660: kgsl_sharedmem_writeq(rb->preemption_desc, 661: PREEMPT_RECORD(rptr_addr), SCRATCH_RB_GPU_ADDR( 662: KGSL_DEVICE(adreno_dev), rb->id, rptr)); 663: kgsl_sharedmem_writeq(rb->preemption_desc, 664: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 665: kgsl_sharedmem_writeq(rb->preemption_desc, 666: PREEMPT_RECORD(bv_rptr_addr), SCRATCH_RB_GPU_ADDR( 667: KGSL_DEVICE(adreno_dev), rb->id, bv_rptr)); 668: } 669: 670: void gen8_reset_preempt_records(struct adreno_device *adreno_dev) 671: { 672: int i; 673: struct adreno_ringbuffer *rb; 674: 675: if (!adreno_is_preemption_enabled(adreno_dev)) 676: return; 677: 678: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 679: reset_rb_preempt_record(adreno_dev, rb); 680: } 681: } 682: 683: static int gen8_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 684: struct adreno_ringbuffer *rb) 685: { 686: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 687: u64 ctxt_record_size = adreno_dev->total_ctxt_record_sz; 688: u64 curr_gmem_size = adreno_gmem_size(adreno_dev); 689: int ret; 690: 691: /* 692: * Since RB0 always runs to completion, there is no need to 693: * save/restore GMEM data for RB0. 694: */ 695: if (rb->id == 0) 696: ctxt_record_size -= curr_gmem_size; 697: 698: ret = adreno_allocate_global(device, &rb->preemption_desc, 699: ctxt_record_size, SZ_16K, 0, 700: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 701: if (ret) 702: return ret; 703: 704: if (kgsl_mmu_is_secured(&device->mmu)) { 705: ret = adreno_allocate_global(device, &rb->secure_preemption_desc, 706: ctxt_record_size, 0, 707: KGSL_MEMFLAGS_SECURE, KGSL_MEMDESC_PRIVILEGED, 708: "secure_preemption_desc"); 709: if (ret) 710: return ret; 711: } 712: 713: ret = adreno_allocate_global(device, &rb->perfcounter_save_restore_desc, 714: GEN8_CP_PERFCOUNTER_SAVE_RESTORE_SIZE, 0, 0, 715: KGSL_MEMDESC_PRIVILEGED, 716: "perfcounter_save_restore_desc"); 717: if (ret) 718: return ret; 719: 720: reset_rb_preempt_record(adreno_dev, rb); 721: 722: return 0; 723: } 724: 725: int gen8_preemption_init(struct adreno_device *adreno_dev) 726: { 727: u32 flags = ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? KGSL_MEMDESC_PRIVILEGED : 0; 728: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 729: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 730: struct adreno_preemption *preempt = &adreno_dev->preempt; 731: struct adreno_ringbuffer *rb; 732: int ret; 733: u32 i; 734: 735: /* We are dependent on IOMMU to make preemption go on the CP side */ 736: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) { 737: ret = -ENODEV; 738: goto done; 739: } 740: 741: INIT_WORK(&preempt->work, _gen8_preemption_worker); 742: 743: /* Allocate mem for storing preemption switch record */ 744: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 745: ret = gen8_preemption_ringbuffer_init(adreno_dev, rb); 746: if (ret) 747: goto done; 748: } 749: 750: ret = adreno_allocate_global(device, &preempt->scratch, PAGE_SIZE, 751: 0, 0, flags, "preempt_scratch"); 752: if (ret) 753: goto done; 754: 755: /* Allocate mem for storing preemption smmu record */ 756: if (kgsl_mmu_is_perprocess(&device->mmu)) { 757: ret = adreno_allocate_global(device, &iommu->smmu_info, PAGE_SIZE, 0, 758: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 759: "smmu_info"); 760: if (ret) 761: goto done; 762: } 763: 764: return 0; 765: done: 766: clear_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 767: return ret; 768: } --- FILE: \adreno_gen8_ringbuffer.c | HITS: 26 --- MATCH LINES: 154, 158, 159 142: 143: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 144: cmds[count++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 145: KGSL_MEMSTORE_GLOBAL, current_context)); 146: cmds[count++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 147: KGSL_MEMSTORE_GLOBAL, current_context)); 148: cmds[count++] = drawctxt->base.id; 149: 150: cmds[count++] = cp_type7_packet(CP_EVENT_WRITE, 1); 151: cmds[count++] = 0x31; 152: 153: if (adreno_is_preemption_enabled(adreno_dev) && drawctxt->base.user_ctxt_record) { 154: u64 gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr; 155: 156: cmds[count++] = cp_type7_packet(CP_SET_PSEUDO_REGISTER, 3); 157: cmds[count++] = SET_PSEUDO_NON_PRIV_SAVE_ADDR; 158: cmds[count++] = lower_32_bits(gpuaddr); 159: cmds[count++] = upper_32_bits(gpuaddr); 160: } 161: 162: return gen8_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED, 163: cmds, count, 0, NULL); 164: } 165: 166: #define RB_SOPTIMESTAMP(device, rb) \ 167: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 168: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 169: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 170: 171: #define RB_EOPTIMESTAMP(device, rb) \ 172: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 173: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 174: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 175: 176: int gen8_ringbuffer_submit(struct adreno_ringbuffer *rb, 177: struct adreno_submit_time *time) 178: { 179: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 180: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 181: int ret = 0; 182: unsigned long flags; 183: MATCH LINES: 222, 260 210: ADRENO_GMU_FAULT_SKIP_SNAPSHOT); 211: } 212: 213: return ret; 214: } 215: 216: int gen8_ringbuffer_init(struct adreno_device *adreno_dev) 217: { 218: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 219: int i, ret; 220: 221: ret = adreno_allocate_global(device, &device->scratch, PAGE_SIZE, 222: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED, 223: "scratch"); 224: if (ret) 225: return ret; 226: 227: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]); 228: 229: if (!adreno_preemption_feature_set(adreno_dev)) { 230: adreno_dev->num_ringbuffers = 1; 231: return adreno_ringbuffer_setup(adreno_dev, 232: &adreno_dev->ringbuffers[0], 0); 233: } 234: 235: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers); 236: 237: for (i = 0; i < adreno_dev->num_ringbuffers; i++) { 238: int ret; 239: 240: ret = adreno_ringbuffer_setup(adreno_dev, 241: &adreno_dev->ringbuffers[i], i); 242: if (ret) 243: return ret; 244: } 245: 246: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0); 247: return 0; 248: } 249: 250: #define GEN8_SUBMIT_MAX 104 251: 252: int gen8_ringbuffer_addcmds(struct adreno_device *adreno_dev, 253: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt, 254: u32 flags, u32 *in, u32 dwords, u32 timestamp, 255: struct adreno_submit_time *time) 256: { 257: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 258: u32 size = GEN8_SUBMIT_MAX + dwords; 259: u32 *cmds, index = 0; 260: u64 profile_gpuaddr; 261: u32 profile_dwords; 262: 263: if (adreno_drawctxt_detached(drawctxt)) 264: return -ENOENT; 265: 266: if (adreno_gpu_fault(adreno_dev) != 0) 267: return -EPROTO; 268: 269: rb->timestamp++; 270: 271: if (drawctxt) 272: drawctxt->internal_timestamp = rb->timestamp; 273: 274: /* All submissions are run with protected mode off due to APRIV */ 275: flags &= ~F_NOTPROTECTED; 276: 277: cmds = adreno_ringbuffer_allocspace(rb, size); 278: if (IS_ERR(cmds)) 279: return PTR_ERR(cmds); 280: 281: /* Identify the start of a command */ 282: cmds[index++] = cp_type7_packet(CP_NOP, 1); 283: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER; 284: MATCH LINES: 308, 311, 313, 314, 343, 346, 348, 349 296: cmds[index++] = CP_SET_THREAD_BR; 297: 298: /* 299: * The POWER_CONTROL packet should always be after IFPC disable MARKER 300: * to avoid opcode errors 301: */ 302: if (flags & F_MALU) { 303: cmds[index++] = cp_type7_packet(CP_POWER_CONTROL, 2); 304: cmds[index++] = 1; /* Control mALU power */ 305: cmds[index++] = 1; /* Turn on mALU */ 306: } 307: 308: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev, 309: drawctxt, &profile_dwords); 310: 311: if (profile_gpuaddr) { 312: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 313: cmds[index++] = lower_32_bits(profile_gpuaddr); 314: cmds[index++] = upper_32_bits(profile_gpuaddr); 315: cmds[index++] = profile_dwords; 316: } 317: 318: if (drawctxt) { 319: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 320: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device, 321: drawctxt)); 322: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device, 323: drawctxt)); 324: cmds[index++] = timestamp; 325: } 326: 327: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3); 328: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb)); 329: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb)); 330: cmds[index++] = rb->timestamp; 331: 332: if (IS_SECURE(flags)) { 333: /* Sync BV and BR if entering secure mode */ 334: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 335: cmds[index++] = CP_SYNC_THREADS | CP_CONCURRENT_BIN_DISABLE; 336: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1); 337: cmds[index++] = 1; 338: } 339: 340: memcpy(&cmds[index], in, dwords << 2); 341: index += dwords; 342: 343: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev, 344: drawctxt, &dwords); 345: 346: if (profile_gpuaddr) { 347: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 348: cmds[index++] = lower_32_bits(profile_gpuaddr); 349: cmds[index++] = upper_32_bits(profile_gpuaddr); 350: cmds[index++] = profile_dwords; 351: } 352: 353: if (test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &device->mmu.pfpolicy)) 354: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0); 355: 356: if (is_concurrent_binning(drawctxt)) { 357: u64 addr = SCRATCH_RB_GPU_ADDR(device, rb->id, bv_ts); 358: 359: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 360: cmds[index++] = CP_SET_THREAD_BV; 361: 362: /* 363: * Make sure the timestamp is committed once BV pipe is 364: * completely done with this submission. 365: */ 366: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4); 367: cmds[index++] = CACHE_CLEAN | BIT(27); 368: cmds[index++] = lower_32_bits(addr); 369: cmds[index++] = upper_32_bits(addr); 370: cmds[index++] = rb->timestamp; 371: 372: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 373: cmds[index++] = CP_SET_THREAD_BR; MATCH LINES: 443, 447, 448, 453, 457, 458, 477, 480, 481 431: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 432: cmds[index++] = CP_SET_THREAD_BR; 433: 434: /* 10 dwords */ 435: index += gen8_preemption_post_ibsubmit(adreno_dev, &cmds[index]); 436: 437: /* Adjust the thing for the number of bytes we actually wrote */ 438: rb->_wptr -= (size - index); 439: 440: return gen8_ringbuffer_submit(rb, time); 441: } 442: 443: static u32 gen8_get_alwayson_counter(u32 *cmds, u64 gpuaddr) 444: { 445: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 446: cmds[1] = GEN8_CP_ALWAYS_ON_COUNTER_LO | (1 << 30) | (2 << 18); 447: cmds[2] = lower_32_bits(gpuaddr); 448: cmds[3] = upper_32_bits(gpuaddr); 449: 450: return 4; 451: } 452: 453: static u32 gen8_get_alwayson_context(u32 *cmds, u64 gpuaddr) 454: { 455: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3); 456: cmds[1] = GEN8_CP_ALWAYS_ON_CONTEXT_LO | (1 << 30) | (2 << 18); 457: cmds[2] = lower_32_bits(gpuaddr); 458: cmds[3] = upper_32_bits(gpuaddr); 459: 460: return 4; 461: } 462: 463: #define PROFILE_IB_DWORDS 4 464: #define PROFILE_IB_SLOTS (PAGE_SIZE / (PROFILE_IB_DWORDS << 2)) 465: 466: static u64 gen8_get_user_profiling_ib(struct adreno_ringbuffer *rb, 467: struct kgsl_drawobj_cmd *cmdobj, u32 target_offset, u32 *cmds) 468: { 469: u32 offset, *ib, dwords; 470: 471: if (IS_ERR(rb->profile_desc)) 472: return 0; 473: 474: offset = rb->profile_index * (PROFILE_IB_DWORDS << 2); 475: ib = rb->profile_desc->hostptr + offset; 476: dwords = gen8_get_alwayson_counter(ib, 477: cmdobj->profiling_buffer_gpuaddr + target_offset); 478: 479: cmds[0] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 480: cmds[1] = lower_32_bits(rb->profile_desc->gpuaddr + offset); 481: cmds[2] = upper_32_bits(rb->profile_desc->gpuaddr + offset); 482: cmds[3] = dwords; 483: 484: rb->profile_index = (rb->profile_index + 1) % PROFILE_IB_SLOTS; 485: 486: return 4; 487: } 488: 489: static int gen8_drawctxt_switch(struct adreno_device *adreno_dev, 490: struct adreno_ringbuffer *rb, 491: struct adreno_context *drawctxt) 492: { 493: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 494: int ret; 495: 496: if (rb->drawctxt_active == drawctxt) 497: return 0; 498: 499: if (kgsl_context_detached(&drawctxt->base)) 500: return -ENOENT; 501: 502: if (!_kgsl_context_get(&drawctxt->base)) 503: return -ENOENT; 504: 505: ret = gen8_rb_context_switch(adreno_dev, rb, drawctxt); MATCH LINES: 529, 535 517: rb->drawctxt_active = drawctxt; 518: return 0; 519: } 520: 521: 522: #define GEN8_USER_PROFILE_IB(rb, cmdobj, cmds, field) \ 523: gen8_get_user_profiling_ib((rb), (cmdobj), \ 524: offsetof(struct kgsl_drawobj_profiling_buffer, field), \ 525: (cmds)) 526: 527: #define GEN8_KERNEL_PROFILE(dev, cmdobj, cmds, field) \ 528: gen8_get_alwayson_counter((cmds), \ 529: (dev)->profile_buffer->gpuaddr + \ 530: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 531: field)) 532: 533: #define GEN8_KERNEL_PROFILE_CONTEXT(dev, cmdobj, cmds, field) \ 534: gen8_get_alwayson_context((cmds), \ 535: (dev)->profile_buffer->gpuaddr + \ 536: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \ 537: field)) 538: 539: #define GEN8_COMMAND_DWORDS 63 540: 541: int gen8_ringbuffer_submitcmd(struct adreno_device *adreno_dev, 542: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 543: struct adreno_submit_time *time) 544: { 545: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 546: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 547: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context); 548: struct adreno_ringbuffer *rb = drawctxt->rb; 549: int ret = 0, numibs = 0, index = 0; 550: u32 *cmds; 551: 552: /* Count the number of IBs (if we are not skipping) */ 553: if (!IS_SKIP(flags)) { 554: struct list_head *tmp; 555: 556: list_for_each(tmp, &cmdobj->cmdlist) 557: numibs++; 558: } 559: MATCH LINES: 600, 601 588: 589: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 590: cmds[index++] = 0x00d; /* IB1LIST start */ 591: 592: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 593: if (ib->priv & MEMOBJ_SKIP || 594: (ib->flags & KGSL_CMDLIST_CTXTSWITCH_PREAMBLE && 595: !IS_PREAMBLE(flags))) 596: cmds[index++] = cp_type7_packet(CP_NOP, 4); 597: 598: cmds[index++] = 599: cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3); 600: cmds[index++] = lower_32_bits(ib->gpuaddr); 601: cmds[index++] = upper_32_bits(ib->gpuaddr); 602: 603: /* Double check that IB_PRIV is never set */ 604: cmds[index++] = (ib->size >> 2) & 0xfffff; 605: } 606: 607: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1); 608: cmds[index++] = 0x00e; /* IB1LIST end */ 609: } 610: 611: if (is_concurrent_binning(drawctxt)) { 612: cmds[index++] = cp_type7_packet(CP_THREAD_CONTROL, 1); 613: cmds[index++] = CP_SET_THREAD_BR; 614: } 615: /* CCU invalidate depth */ 616: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1); 617: cmds[index++] = 24; 618: 619: /* CCU invalidate color */ 620: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1); 621: cmds[index++] = 25; 622: 623: /* 8 dwords */ 624: if (IS_KERNEL_PROFILE(flags)) { 625: index += GEN8_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index], --- FILE: \adreno_gen8_snapshot.c | HITS: 13 --- MATCH LINES: 18, 19 6: 7: #include "adreno.h" 8: #include "adreno_gen8_0_0_snapshot.h" 9: #include "adreno_gen8_1_0_snapshot.h" 10: #include "adreno_gen8_10_0_snapshot.h" 11: #include "adreno_gen8_2_0_snapshot.h" 12: #include "adreno_gen8_3_0_snapshot.h" 13: #include "adreno_gen8_6_0_snapshot.h" 14: #include "adreno_gen8_9_0_snapshot.h" 15: #include "adreno_gen8_11_0_snapshot.h" 16: #include "adreno_snapshot.h" 17: 18: static struct kgsl_memdesc *gen8_capturescript; 19: static struct kgsl_memdesc *gen8_crashdump_registers; 20: static u32 *gen8_cd_reg_end; 21: static const struct gen8_snapshot_block_list *gen8_snapshot_block_list; 22: static bool gen8_crashdump_timedout; 23: 24: /* Starting kernel virtual address for QDSS TMC register block */ 25: static void __iomem *tmc_virt; 26: 27: const struct gen8_snapshot_block_list gen8_0_0_snapshot_block_list = { 28: .pre_crashdumper_regs = gen8_0_0_ahb_registers, 29: .num_pre_crashdumper_regs = ARRAY_SIZE(gen8_0_0_ahb_registers), 30: .debugbus_blocks = gen8_debugbus_blocks, 31: .debugbus_blocks_len = ARRAY_SIZE(gen8_debugbus_blocks), 32: .gbif_debugbus_blocks = gen8_gbif_debugbus_blocks, 33: .gbif_debugbus_blocks_len = ARRAY_SIZE(gen8_gbif_debugbus_blocks), 34: .cx_debugbus_blocks = gen8_cx_debugbus_blocks, 35: .cx_debugbus_blocks_len = ARRAY_SIZE(gen8_cx_debugbus_blocks), 36: .external_core_regs = gen8_0_0_external_core_regs, 37: .num_external_core_regs = ARRAY_SIZE(gen8_0_0_external_core_regs), 38: .gmu_cx_unsliced_regs = gen8_0_0_gmu_registers, 39: .gmu_gx_regs = gen8_gmu_gx_registers, 40: .num_gmu_gx_regs = ARRAY_SIZE(gen8_gmu_gx_registers), 41: .rscc_regs = gen8_0_0_rscc_rsc_registers, 42: .reg_list = gen8_0_0_reg_list, 43: .cx_misc_regs = gen8_0_0_cx_misc_registers, MATCH LINES: 323, 348, 350 311: static u32 CD_READ(u64 *ptr, u32 offset, u32 size, u64 target) 312: { 313: ptr[0] = target; 314: ptr[1] = FIELD_PREP(GENMASK(63, 44), offset) | size; 315: 316: return 2; 317: } 318: 319: static void CD_FINISH(u64 *ptr, u32 offset) 320: { 321: gen8_cd_reg_end = gen8_crashdump_registers->hostptr + offset; 322: *gen8_cd_reg_end = CD_REG_END; 323: ptr[0] = gen8_crashdump_registers->gpuaddr + offset; 324: ptr[1] = FIELD_PREP(GENMASK(63, 44), GEN8_CP_CRASH_DUMP_STATUS) | BIT(0); 325: ptr[2] = 0; 326: ptr[3] = 0; 327: } 328: 329: static bool CD_SCRIPT_CHECK(struct kgsl_device *device) 330: { 331: return (adreno_smmu_is_stalled(ADRENO_DEVICE(device)) || 332: (kgsl_mmu_ctx_terminated_on_fault(&device->mmu)) || 333: (!device->snapshot_crashdumper) || 334: IS_ERR_OR_NULL(gen8_capturescript) || 335: IS_ERR_OR_NULL(gen8_crashdump_registers) || 336: gen8_crashdump_timedout); 337: } 338: 339: static bool _gen8_do_crashdump(struct kgsl_device *device) 340: { 341: u32 reg = 0; 342: ktime_t timeout; 343: 344: if (CD_SCRIPT_CHECK(device)) 345: return false; 346: 347: kgsl_regwrite(device, GEN8_CP_CRASH_DUMP_SCRIPT_BASE_LO, 348: lower_32_bits(gen8_capturescript->gpuaddr)); 349: kgsl_regwrite(device, GEN8_CP_CRASH_DUMP_SCRIPT_BASE_HI, 350: upper_32_bits(gen8_capturescript->gpuaddr)); 351: kgsl_regwrite(device, GEN8_CP_CRASH_DUMP_CNTL, 1); 352: 353: timeout = ktime_add_ms(ktime_get(), CP_CRASH_DUMPER_TIMEOUT); 354: 355: if (!device->snapshot_atomic) 356: might_sleep(); 357: for (;;) { 358: /* make sure we're reading the latest value */ 359: rmb(); 360: if ((*gen8_cd_reg_end) != CD_REG_END) 361: break; 362: if (ktime_compare(ktime_get(), timeout) > 0) 363: break; 364: /* Wait 50us to avoid unnecessary looping */ 365: if (!device->snapshot_atomic) 366: usleep_range(5, 50); 367: } 368: 369: kgsl_regread(device, GEN8_CP_CRASH_DUMP_STATUS, ®); 370: 371: /* 372: * Writing to the GEN8_CP_CRASH_DUMP_CNTL also resets the 373: * GEN8_CP_CRASH_DUMP_STATUS. Make sure the read above is 374: * complete before we change the value MATCH LINES: 630 618: 619: /* Build the crash script */ 620: ptr = gen8_capturescript->hostptr; 621: 622: ptr += CD_WRITE(ptr, GEN8_CP_APERTURE_CNTL_CD, GEN8_CP_APERTURE_REG_VAL 623: ((iregs->slice_id == UINT_MAX) ? 0 : iregs->slice_id, iregs->pipe_id, 624: 0, 0)); 625: 626: for (i = 0; i < num_cd_regs; i++) { 627: /* Write the address register */ 628: ptr += CD_WRITE(ptr, iregs->index, start + i); 629: ptr += CD_READ(ptr, iregs->data, 1, 630: (gen8_crashdump_registers->gpuaddr + offset)); 631: offset += sizeof(u32); 632: } 633: 634: /* Marker for end of script */ 635: CD_FINISH(ptr, offset); 636: 637: /* 638: * Attempt to execute the CD. If it times out, update the header 639: * and return the number of bytes written so far to account for 640: * partial data. 641: */ 642: if (!_gen8_do_crashdump(device)) { 643: header->count = iregs->count - count; 644: return ((u8 *)dest - buf); 645: } 646: 647: memcpy(dest, gen8_crashdump_registers->hostptr, offset); 648: 649: count -= num_cd_regs; 650: start += num_cd_regs; 651: dest = (u32 *)((u8 *)dest + offset); 652: } 653: 654: return (iregs->count * 4) + sizeof(*header); MATCH LINES: 1039 1027: FOR_EACH_SLICE(slice, block->slice_region, slice_mask) { 1028: for (sp = 0; sp < block->num_sps; sp++) { 1029: for (ctxt = 0; ctxt < block->num_ctx; ctxt++) { 1030: /* Program the aperture */ 1031: ptr += CD_WRITE(ptr, GEN8_SP_READ_SEL, 1032: GEN8_SP_READ_SEL_VAL(ctxt, slice, 1033: block->location, block->pipeid, 1034: block->statetype, block->usptp_id, sp)); 1035: 1036: /* Read all the data in one chunk */ 1037: ptr += CD_READ(ptr, GEN8_SP_AHB_READ_APERTURE, 1038: block->size, 1039: gen8_crashdump_registers->gpuaddr + offset); 1040: offset += block->size << 2; 1041: } 1042: } 1043: } 1044: /* Marker for end of script */ 1045: CD_FINISH(ptr, offset); 1046: 1047: /* Try to run the crash dumper and bail if it times out */ 1048: if (!_gen8_do_crashdump(device)) 1049: return false; 1050: 1051: offset = 0; 1052: FOR_EACH_SLICE(slice, block->slice_region, slice_mask) { 1053: for (sp = 0; sp < block->num_sps; sp++) { 1054: for (ctxt = 0; ctxt < block->num_ctx; ctxt++) { 1055: info.block = block; 1056: info.sp_id = sp; 1057: info.usptp = block->usptp_id; 1058: info.slice_id = slice; 1059: info.offset = offset; 1060: info.context_id = ctxt; 1061: offset += block->size << 2; 1062: 1063: /* Shader working/shadow memory */ MATCH LINES: 1301 1289: /* Build the crash script */ 1290: ptr = gen8_capturescript->hostptr; 1291: 1292: /* Program the aperture */ 1293: ptr += CD_WRITE(ptr, GEN8_SP_READ_SEL, GEN8_SP_READ_SEL_VAL 1294: (0, j, cluster->location_id, cluster->pipe_id, 1295: cluster->statetype, usptp, sp)); 1296: 1297: for (; regs[0] != UINT_MAX; regs += 2) { 1298: count = REG_COUNT(regs); 1299: ptr += CD_READ(ptr, (GEN8_SP_AHB_READ_APERTURE + 1300: regs[0] - cluster->regbase), count, 1301: (gen8_crashdump_registers->gpuaddr + 1302: offset)); 1303: 1304: offset += count * sizeof(u32); 1305: } 1306: /* Marker for end of script */ 1307: CD_FINISH(ptr, offset); 1308: 1309: /* Try to run the crash dumper and bail if it times out */ 1310: if (!_gen8_do_crashdump(device)) 1311: return false; 1312: 1313: kgsl_snapshot_add_section(device, 1314: KGSL_SNAPSHOT_SECTION_MVC_V3, snapshot, 1315: gen8_snapshot_cluster_dbgahb, &info); 1316: } 1317: } 1318: } 1319: } 1320: return true; 1321: } 1322: 1323: static size_t gen8_legacy_snapshot_mvc(struct kgsl_device *device, u8 *buf, 1324: size_t remain, void *priv) 1325: { MATCH LINES: 1479 1467: ptr = gen8_capturescript->hostptr; 1468: 1469: ptr += CD_WRITE(ptr, GEN8_CP_APERTURE_CNTL_CD, GEN8_CP_APERTURE_REG_VAL 1470: (j, cluster->pipe_id, cluster->cluster_id, cluster->context_id)); 1471: 1472: if (cluster->sel) 1473: ptr += CD_WRITE(ptr, cluster->sel->cd_reg, cluster->sel->val); 1474: 1475: for (; regs[0] != UINT_MAX; regs += 2) { 1476: count = REG_COUNT(regs); 1477: 1478: ptr += CD_READ(ptr, regs[0], 1479: count, (gen8_crashdump_registers->gpuaddr + offset)); 1480: 1481: offset += count * sizeof(u32); 1482: } 1483: 1484: /* Marker for end of script */ 1485: CD_FINISH(ptr, offset); 1486: 1487: /* Try to run the crash dumper and bail if it times out */ 1488: if (!_gen8_do_crashdump(device)) 1489: return false; 1490: 1491: kgsl_snapshot_add_section(device, 1492: KGSL_SNAPSHOT_SECTION_MVC_V3, snapshot, gen8_snapshot_mvc, &info); 1493: } 1494: } 1495: return true; 1496: } 1497: 1498: static void gen8_debugbus_internal_read_setup(struct kgsl_device *device) 1499: { 1500: /* Clear the DBGC logic/events */ 1501: kgsl_regwrite(device, GEN8_CX_DBGC_CFG_DBGBUS_CNTLM, 0x70000000); 1502: 1503: /* Enable the internal buffer mode and program to tail mode */ MATCH LINES: 1932 1920: ptr += CD_WRITE(ptr, GEN8_CP_APERTURE_CNTL_CD, GEN8_CP_APERTURE_REG_VAL 1921: (j, 0, 0, 0)); 1922: /* Program the SEL_CNTL_CD register appropriately */ 1923: if (regs->sel) 1924: ptr += CD_WRITE(ptr, regs->sel->cd_reg, regs->sel->val); 1925: info.regs = regs; 1926: info.slice_id = SLICE_ID(regs->slice_region, j); 1927: info.offset = offset; 1928: 1929: for (; regs_ptr[0] != UINT_MAX; regs_ptr += 2) { 1930: r = REG_COUNT(regs_ptr); 1931: ptr += CD_READ(ptr, regs_ptr[0], r, 1932: (gen8_crashdump_registers->gpuaddr + offset)); 1933: offset += r * sizeof(u32); 1934: } 1935: 1936: /* Marker for end of script */ 1937: CD_FINISH(ptr, offset); 1938: 1939: /* Try to run the crash dumper and bail if it times out */ 1940: if (!_gen8_do_crashdump(device)) 1941: return false; 1942: 1943: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_MVC_V3, 1944: snapshot, gen8_snapshot_registers, &info); 1945: } 1946: } 1947: 1948: return true; 1949: } 1950: 1951: static size_t gen8_snapshot_cx_misc_registers(struct kgsl_device *device, u8 *buf, 1952: size_t remain, void *priv) 1953: { 1954: const u32 *ptr = (u32 *)priv; 1955: u32 *src, *data = (unsigned int *)buf; 1956: size_t size = adreno_snapshot_regs_count(ptr) * sizeof(u32); MATCH LINES: 2000 1988: 1989: if (CD_SCRIPT_CHECK(device) || !gen8_gmu_rpmh_pwr_state_is_active(device) 1990: || !gen8_gmu_gx_is_on(ADRENO_DEVICE(device))) 1991: goto legacy_snapshot; 1992: 1993: /* Build the crash script */ 1994: ptr = (u64 *)gen8_capturescript->hostptr; 1995: 1996: for (; regs_ptr[0] != UINT_MAX; regs_ptr += 2) { 1997: u32 r = REG_COUNT(regs_ptr); 1998: 1999: ptr += CD_READ(ptr, regs_ptr[0], r, 2000: (gen8_crashdump_registers->gpuaddr + offset)); 2001: offset += r * sizeof(u32); 2002: } 2003: 2004: /* Marker for end of script */ 2005: CD_FINISH(ptr, offset); 2006: 2007: /* Try to run the crash dumper if it fails return */ 2008: if (_gen8_do_crashdump(device)) { 2009: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS_V2, 2010: snapshot, gen8_snapshot_cx_misc_registers, 2011: (void *)gen8_snapshot_block_list->cx_misc_regs); 2012: return true; 2013: } else 2014: return false; 2015: 2016: legacy_snapshot: 2017: regs_ptr = (const u32 *)gen8_snapshot_block_list->cx_misc_regs; 2018: 2019: if (!kgsl_regmap_valid_offset(&device->regmap, regs_ptr[0])) { 2020: WARN_ONCE(1, "cx_misc registers are not defined in device tree"); 2021: return true; 2022: } 2023: 2024: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS_V2, MATCH LINES: 2263, 2268 2251: 2252: void gen8_crashdump_init(struct adreno_device *adreno_dev) 2253: { 2254: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2255: int ret; 2256: u64 capturescript_regs_pages = 2257: ((adreno_is_gen8_2_x(adreno_dev) || 2258: adreno_is_gen8_1_0(adreno_dev) || 2259: adreno_is_gen8_11_x(adreno_dev)) ? 400 : 200); 2260: 2261: ret = adreno_allocate_global(device, &gen8_capturescript, 2262: 50 * PAGE_SIZE, 0, KGSL_MEMFLAGS_GPUREADONLY, 2263: KGSL_MEMDESC_PRIVILEGED, "capturescript"); 2264: 2265: if (!ret) 2266: ret = adreno_allocate_global(device, &gen8_crashdump_registers, 2267: capturescript_regs_pages * PAGE_SIZE, 0, 0, 2268: KGSL_MEMDESC_PRIVILEGED, "capturescript_regs"); 2269: 2270: if (ret) 2271: dev_err(device->dev, "Failed to init crashdumper err = %d\n", ret); 2272: } --- FILE: \adreno_hfi.h | HITS: 9 --- MATCH LINES: 811 799: u32 gmu_addr; 800: u32 size; /* Bytes */ 801: /** 802: * @align: bits[0:7] specify alignment requirement of the GMU VA specified as a power of 803: * two. bits[8:15] specify alignment requirement for the size of the GMU mapping. For 804: * example, a decimal value of 20 = (1 << 20) = 1 MB alignment 805: */ 806: u32 align; 807: } __packed; 808: 809: struct hfi_mem_alloc_entry { 810: struct hfi_mem_alloc_desc desc; 811: struct kgsl_memdesc *md; 812: }; 813: 814: /* F2H */ 815: struct hfi_mem_alloc_cmd_legacy { 816: u32 hdr; 817: u32 reserved; /* Padding to ensure alignment of 'desc' below */ 818: struct hfi_mem_alloc_desc_legacy desc; 819: } __packed; 820: 821: struct hfi_mem_alloc_cmd { 822: u32 hdr; 823: u32 version; 824: struct hfi_mem_alloc_desc desc; 825: } __packed; 826: 827: /* H2F */ 828: struct hfi_mem_alloc_reply_cmd { 829: u32 hdr; 830: u32 req_hdr; 831: struct hfi_mem_alloc_desc desc; 832: } __packed; 833: 834: /* H2F */ 835: struct hfi_gx_bw_perf_vote_cmd { MATCH LINES: 1057, 1058 1045: struct hfi_msg_ret_cmd { 1046: u32 hdr; 1047: u32 req_hdr; 1048: u32 error; 1049: } __packed; 1050: 1051: /* H2F */ 1052: struct hfi_submit_cmd { 1053: u32 hdr; 1054: u32 ctxt_id; 1055: u32 flags; 1056: u32 ts; 1057: u32 profile_gpuaddr_lo; 1058: u32 profile_gpuaddr_hi; 1059: u32 numibs; 1060: u32 big_ib_gmu_va; 1061: } __packed; 1062: 1063: /* This structure is only used for hw fence feature on gen7 hwsched targets */ 1064: struct hfi_syncobj_legacy { 1065: /** @ctxt_id: dma fence context id for external fence and gmu context id for kgsl fence */ 1066: u64 ctxt_id; 1067: /** @seq_no: Sequence number (or timestamp) of this fence */ 1068: u64 seq_no; 1069: /** @flags: Flags for this fence */ 1070: u64 flags; 1071: } __packed; 1072: 1073: struct hfi_syncobj { 1074: /** 1075: * @header: bits[0:15]: size of this packet in dwords, bits[15:23]: version, 1076: * bits[24:31] unused 1077: */ 1078: u32 header; 1079: /** @hash_index: hash index of external input fence */ 1080: u32 hash_index; 1081: /** @ctxt_id: dma fence context id for external fence and gmu context id for kgsl fence */ 1082: u64 ctxt_id; MATCH LINES: 1319, 1320 1307: #define KEY_CP_DDEBV_HW_FAULT 28 1308: #define KEY_CP_DDEBV_SW_FAULT 29 1309: #define KEY_CP_AHB_ERROR 30 1310: #define KEY_TSB_WRITE_ERROR 31 1311: 1312: /* Keys for PAYLOAD_RB type payload */ 1313: #define KEY_RB_ID 1 1314: #define KEY_RB_RPTR 2 1315: #define KEY_RB_WPTR 3 1316: #define KEY_RB_SIZEDWORDS 4 1317: #define KEY_RB_QUEUED_TS 5 1318: #define KEY_RB_RETIRED_TS 6 1319: #define KEY_RB_GPUADDR_LO 7 1320: #define KEY_RB_GPUADDR_HI 8 1321: 1322: /* Keys for PAYLOAD_PREEMPT_TIMEOUT type payload */ 1323: #define KEY_PREEMPT_TIMEOUT_CUR_RB_ID 1 1324: #define KEY_PREEMPT_TIMEOUT_NEXT_RB_ID 2 1325: 1326: /* Keys for PAYLOAD_FAULT_RESET_POLICY type payload */ 1327: #define KEY_GPU_RESET_POLICY 1 1328: 1329: /* Types of errors that trigger context bad HFI */ 1330: 1331: /* GPU encountered a CP HW error */ 1332: #define GMU_CP_HW_ERROR 600 1333: /* GPU encountered a GPU Hang interrupt */ 1334: #define GMU_GPU_HW_HANG 601 1335: /* Preemption didn't complete in given time */ 1336: #define GMU_GPU_PREEMPT_TIMEOUT 602 1337: /* Fault due to Long IB timeout */ 1338: #define GMU_GPU_SW_HANG 603 1339: /* GPU encountered a bad opcode */ 1340: #define GMU_CP_OPCODE_ERROR 604 1341: /* GPU encountered protected mode error */ 1342: #define GMU_CP_PROTECTED_ERROR 605 1343: /* GPU encountered an illegal instruction */ 1344: #define GMU_CP_ILLEGAL_INST_ERROR 606 MATCH LINES: 1506, 1513, 1515, 1516 1494: wmb(); 1495: 1496: *write_idx = index; 1497: 1498: /* 1499: * Memory barrier to make sure write index is written before an 1500: * interrupt is raised 1501: */ 1502: wmb(); 1503: } 1504: 1505: /** 1506: * hfi_get_mem_alloc_desc - Get the descriptor from F2H_MSG_MEM_ALLOC packet 1507: * rcvd: Pointer to the F2H_MSG_MEM_ALLOC packet 1508: * out: Pointer to copy the descriptor data to 1509: * 1510: * This function checks for the F2H_MSG_MEM_ALLOC packet version and based on that gets the 1511: * descriptor data from the packet. 1512: */ 1513: static inline void hfi_get_mem_alloc_desc(void *rcvd, struct hfi_mem_alloc_desc *out) 1514: { 1515: struct hfi_mem_alloc_cmd_legacy *in_legacy = (struct hfi_mem_alloc_cmd_legacy *)rcvd; 1516: struct hfi_mem_alloc_cmd *in = (struct hfi_mem_alloc_cmd *)rcvd; 1517: 1518: if (in->version > 0) 1519: memcpy(out, &in->desc, sizeof(in->desc)); 1520: else 1521: memcpy(out, &in_legacy->desc, sizeof(in_legacy->desc)); 1522: } 1523: 1524: /** 1525: * hfi_get_gmu_va_alignment - Get the alignment (in bytes) for a GMU VA 1526: * align: Alignment specified as a power of two (2^n) in bits[0:7] 1527: * 1528: * This function derives the GMU VA alignment in bytes from bits[0:7] in the passed in value, which 1529: * is specified in terms of power of two (2^n). For example, va_align = 20 means (1 << 20) = 1MB 1530: * alignment. The minimum alignment (in bytes) is SZ_4K i.e. anything less than (or equal to) a 1531: * va_align value of ilog2(SZ_4K) will default to SZ_4K alignment. 1532: */ 1533: static inline u32 hfi_get_gmu_va_alignment(u32 align) 1534: { 1535: u32 va_align = FIELD_GET(GENMASK(7, 0), align); 1536: 1537: return (va_align > ilog2(SZ_4K)) ? (1 << va_align) : SZ_4K; 1538: } 1539: 1540: /** --- FILE: \adreno_hwsched.c | HITS: 48 --- MATCH LINES: 61, 77, 78, 95, 110, 132, 147, 185, 188, 195, 205, 211, 226, 231, 266, 296, 316, 328, 329, 361, 383, 392, 399, 412, 440, 441, 449, 455 49: { 50: return test_bit(ADRENO_HWSCHED_CONTEXT_QUEUE, &adreno_dev->hwsched.flags); 51: } 52: 53: static inline u32 get_gmu_vma_id(u32 flags) 54: { 55: return (flags & HFI_MEMFLAG_GMU_CACHEABLE) ? GMU_CACHE : GMU_NONCACHED_KERNEL; 56: } 57: 58: static void setup_gfx_flags_priv(u32 desc_flags, u64 *flags, u32 *priv) 59: { 60: if (desc_flags & HFI_MEMFLAG_GFX_PRIV) 61: *priv |= KGSL_MEMDESC_PRIVILEGED; 62: 63: if (!(desc_flags & HFI_MEMFLAG_GFX_WRITEABLE)) 64: *flags |= KGSL_MEMFLAGS_GPUREADONLY; 65: 66: if (desc_flags & HFI_MEMFLAG_GFX_SECURE) 67: *flags |= KGSL_MEMFLAGS_SECURE; 68: } 69: 70: static int reserve_preempt_record_va(struct adreno_device *adreno_dev, 71: struct hfi_mem_alloc_entry *entry, u64 flags, u32 priv) 72: { 73: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 74: struct hfi_mem_alloc_desc *desc = &entry->desc; 75: int ret = 0; 76: 77: if (!entry->md->gpuaddr) { 78: ret = kgsl_get_global_gpuaddr(device, entry->md, 79: desc->size, flags, priv); 80: if (ret) 81: return ret; 82: } 83: 84: if (!(entry->desc.flags & HFI_MEMFLAG_GMU_ACC)) 85: return ret; 86: 87: if (!entry->md->gmuaddr) 88: ret = gmu_core_reserve_gmuaddr(device, entry->md, 89: get_gmu_vma_id(desc->flags), desc->align); 90: 91: return ret; 92: } 93: 94: static int alloc_map_preempt_record(struct adreno_device *adreno_dev, 95: struct kgsl_memdesc **md, struct hfi_mem_alloc_entry *entry, u64 offset, 96: u64 flags, u32 priv) 97: { 98: u64 ctxt_record_size = adreno_dev->total_ctxt_record_sz; 99: u64 curr_gmem_size = adreno_gmem_size(adreno_dev); 100: u64 md_size = ctxt_record_size - curr_gmem_size; 101: struct hfi_mem_alloc_desc *desc = &entry->desc; 102: 103: if (*md) 104: return 0; 105: 106: if (offset >= (entry->md->size)) 107: return -ENOSPC; 108: 109: *md = kgsl_alloc_map_gpu_global(KGSL_DEVICE(adreno_dev), 110: entry->md->gpuaddr + offset, md_size, 0, flags, priv, 111: (entry->desc.mem_kind == HFI_MEMKIND_CSW_PRIV_SECURE) ? 112: "sec_preempt_record_non_gmem" : "preempt_record_non_gmem"); 113: if (IS_ERR(*md)) { 114: int ret = PTR_ERR(*md); 115: 116: *md = NULL; 117: return ret; 118: } 119: 120: if (!(desc->flags & HFI_MEMFLAG_GMU_ACC)) 121: return 0; 122: 123: if ((*md)->gmuaddr) 124: return 0; 125: 126: return gmu_core_map_gmu(KGSL_DEVICE(adreno_dev), *md, 127: entry->md->gmuaddr + offset, 128: get_gmu_vma_id(desc->flags), 129: gmu_core_get_attrs(desc->flags), desc->align); 130: } 131: 132: static int alloc_map_non_gmem(struct adreno_device *adreno_dev, 133: struct hfi_mem_alloc_entry *entry, u64 flags, u32 priv) 134: { 135: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 136: u64 ctxt_record_sz = adreno_dev->total_ctxt_record_sz, offset = 0; 137: u64 curr_gmem_size = adreno_gmem_size(adreno_dev); 138: bool no_rb0_gmem = false; 139: int i; 140: 141: /* Check whether GMU has removed GMEM size from RB0 context record */ 142: if (entry->desc.size == ((ctxt_record_sz * KGSL_PRIORITY_MAX_RB_LEVELS) - 143: curr_gmem_size)) 144: no_rb0_gmem = true; 145: 146: for (i = 0; i < KGSL_PRIORITY_MAX_RB_LEVELS; i++) { 147: struct kgsl_memdesc **md = (entry->desc.mem_kind == HFI_MEMKIND_CSW_PRIV_SECURE) ? 148: &hwsched->secure_preempt_rec[i] : &hwsched->preempt_rec[i]; 149: int ret = alloc_map_preempt_record(adreno_dev, md, entry, offset, flags, priv); 150: 151: if (ret) 152: return ret; 153: 154: offset += ctxt_record_sz; 155: if ((i == 0) && no_rb0_gmem) 156: offset -= curr_gmem_size; 157: } 158: 159: return 0; 160: } 161: 162: static int process_preempt_record_mem_alloc(struct adreno_device *adreno_dev, 163: struct hfi_mem_alloc_entry *entry) 164: { 165: u64 flags = 0; 166: u32 priv = 0; 167: int ret; 168: 169: if (!entry->md) { 170: struct gmu_core_device *gmu = &KGSL_DEVICE(adreno_dev)->gmu_core; 171: 172: if (gmu->global_entries == ARRAY_SIZE(gmu->gmu_globals)) 173: return -ENOMEM; 174: 175: entry->md = &gmu->gmu_globals[gmu->global_entries]; 176: gmu->global_entries++; 177: } 178: 179: setup_gfx_flags_priv(entry->desc.flags, &flags, &priv); 180: 181: ret = reserve_preempt_record_va(adreno_dev, entry, flags, priv); 182: if (ret) 183: return ret; 184: 185: return alloc_map_non_gmem(adreno_dev, entry, flags, priv); 186: } 187: 188: static struct hfi_mem_alloc_entry *lookup_mem_alloc_table( 189: struct adreno_device *adreno_dev, struct hfi_mem_alloc_desc *desc) 190: { 191: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 192: int i; 193: 194: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 195: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 196: 197: if ((entry->desc.mem_kind == desc->mem_kind) && 198: (entry->desc.gmu_mem_handle == desc->gmu_mem_handle)) 199: return entry; 200: } 201: 202: return NULL; 203: } 204: 205: static struct hfi_mem_alloc_entry *get_mem_alloc_entry( 206: struct adreno_device *adreno_dev, struct hfi_mem_alloc_desc *desc) 207: { 208: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 209: struct device *gmu_pdev_dev = GMU_PDEV_DEV(device); 210: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 211: struct hfi_mem_alloc_entry *entry = lookup_mem_alloc_table(adreno_dev, desc); 212: u64 flags = 0; 213: u32 priv = 0; 214: int ret; 215: const char *memkind_string = desc->mem_kind < HFI_MEMKIND_MAX ? 216: hfi_memkind_strings[desc->mem_kind] : "UNKNOWN"; 217: 218: if (entry) 219: return entry; 220: 221: if (desc->mem_kind >= HFI_MEMKIND_MAX) { 222: dev_err(gmu_pdev_dev, "Invalid mem kind: %d\n", desc->mem_kind); 223: return ERR_PTR(-EINVAL); 224: } 225: 226: if (hwsched->mem_alloc_entries == ARRAY_SIZE(hwsched->mem_alloc_table)) { 227: dev_err(gmu_pdev_dev, "Reached max mem alloc entries\n"); 228: return ERR_PTR(-ENOMEM); 229: } 230: 231: entry = &hwsched->mem_alloc_table[hwsched->mem_alloc_entries]; 232: 233: memcpy(&entry->desc, desc, sizeof(*desc)); 234: 235: entry->desc.host_mem_handle = desc->gmu_mem_handle; 236: 237: setup_gfx_flags_priv(desc->flags, &flags, &priv); 238: 239: if (!(desc->flags & HFI_MEMFLAG_GFX_ACC) && 240: (desc->mem_kind != HFI_MEMKIND_HW_FENCE)) { 241: if (desc->mem_kind == HFI_MEMKIND_MMIO_IPC_CORE) 242: entry->md = gmu_core_reserve_kernel_block_fixed(device, 0, 243: desc->size, 244: get_gmu_vma_id(desc->flags), 245: "qcom,ipc-core", gmu_core_get_attrs(desc->flags), 246: desc->align); 247: else 248: entry->md = gmu_core_reserve_kernel_block(device, 0, 249: desc->size, 250: get_gmu_vma_id(desc->flags), 251: desc->align); 252: 253: if (IS_ERR(entry->md)) { 254: ret = PTR_ERR(entry->md); 255: 256: memset(entry, 0, sizeof(*entry)); 257: return ERR_PTR(ret); 258: } 259: entry->desc.size = entry->md->size; 260: entry->desc.gmu_addr = entry->md->gmuaddr; 261: 262: goto done; 263: } 264: 265: /* 266: * Use pre-allocated memory descriptors to map the HFI_MEMKIND_HW_FENCE and 267: * HFI_MEMKIND_MEMSTORE 268: */ 269: switch (desc->mem_kind) { 270: case HFI_MEMKIND_HW_FENCE: 271: entry->md = &adreno_dev->hwsched.hw_fence.md; 272: break; 273: case HFI_MEMKIND_MEMSTORE: 274: entry->md = device->memstore; 275: break; 276: case HFI_MEMKIND_CSW_PRIV_NON_SECURE: 277: case HFI_MEMKIND_CSW_PRIV_SECURE: 278: /* 279: * Standard kernel does not support secure SIDs. But GMU FW 280: * always requests a secure preempt buffer regardless. Back it 281: * with a PAGE_SIZE non-secure dummy buffer to give CP a valid 282: * GPU VA to write to. 283: */ 284: if (desc->mem_kind == HFI_MEMKIND_CSW_PRIV_SECURE && 285: !kgsl_mmu_is_secured(&device->mmu)) { 286: entry->desc.flags &= ~HFI_MEMFLAG_GFX_SECURE; 287: flags &= ~KGSL_MEMFLAGS_SECURE; 288: entry->desc.size = PAGE_SIZE; 289: } 290: if (ADRENO_FEATURE(adreno_dev, ADRENO_DEFER_GMEM_ALLOC)) { 291: ret = process_preempt_record_mem_alloc(adreno_dev, entry); 292: if (ret) 293: return ERR_PTR(ret); 294: 295: entry->desc.size = entry->md->size; 296: entry->desc.gpu_addr = entry->md->gpuaddr; 297: entry->desc.gmu_addr = entry->md->gmuaddr; 298: 299: goto done; 300: } 301: /* Allocate global through legacy approach */ 302: fallthrough; 303: default: 304: entry->md = kgsl_allocate_global(device, entry->desc.size, 0, flags, 305: priv, memkind_string); 306: break; 307: } 308: if (IS_ERR(entry->md)) { 309: ret = PTR_ERR(entry->md); 310: 311: memset(entry, 0, sizeof(*entry)); 312: return ERR_PTR(ret); 313: } 314: 315: entry->desc.size = entry->md->size; 316: entry->desc.gpu_addr = entry->md->gpuaddr; 317: 318: if (!(desc->flags & HFI_MEMFLAG_GMU_ACC)) 319: goto done; 320: 321: /* 322: * If gmu mapping fails, then we have to live with 323: * leaking the gpu global buffer allocated above. 324: */ 325: ret = gmu_core_import_buffer(device, entry); 326: if (ret) { 327: dev_err(gmu_pdev_dev, 328: "gpuaddr: 0x%llx size: %lld bytes lost\n", 329: entry->md->gpuaddr, entry->md->size); 330: memset(entry, 0, sizeof(*entry)); 331: return ERR_PTR(ret); 332: } 333: 334: entry->desc.gmu_addr = entry->md->gmuaddr; 335: done: 336: hwsched->mem_alloc_entries++; 337: 338: return entry; 339: } 340: 341: void adreno_hwsched_retire_cmdlist_obj(struct adreno_device *adreno_dev, 342: struct cmd_list_obj *obj) 343: { 344: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 345: 346: list_del_init(&obj->node); 347: kmem_cache_free(obj_cache, obj); 348: hwsched->inflight--; 349: } 350: 351: int adreno_hwsched_process_mem_alloc(struct adreno_device *adreno_dev, 352: struct hfi_mem_alloc_desc *mad) 353: { 354: struct hfi_mem_alloc_entry *entry; 355: 356: entry = get_mem_alloc_entry(adreno_dev, mad); 357: if (IS_ERR(entry)) 358: return PTR_ERR(entry); 359: 360: if (entry->md) { 361: mad->gpu_addr = entry->md->gpuaddr; 362: mad->gmu_addr = entry->md->gmuaddr; 363: } 364: 365: /* 366: * GMU uses the host_mem_handle to check if this memalloc was 367: * successful 368: */ 369: mad->host_mem_handle = mad->gmu_mem_handle; 370: 371: return 0; 372: } 373: 374: static struct hfi_mem_alloc_entry *get_preempt_record_entry(struct adreno_device *adreno_dev, 375: unsigned long flags) 376: { 377: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 378: u32 mem_kind = flags & KGSL_CONTEXT_SECURE ? 379: HFI_MEMKIND_CSW_PRIV_SECURE : HFI_MEMKIND_CSW_PRIV_NON_SECURE; 380: u32 i; 381: 382: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 383: struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i]; 384: 385: if (entry->desc.mem_kind == mem_kind) 386: return entry; 387: } 388: 389: return NULL; 390: } 391: 392: static int adreno_hwsched_alloc_preempt_record_gmem(struct adreno_device *adreno_dev, 393: struct adreno_context *drawctxt) 394: { 395: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 396: struct kgsl_context *context = &drawctxt->base; 397: struct kgsl_device *device = context->device; 398: struct hfi_mem_alloc_entry *entry = NULL; 399: struct kgsl_memdesc *pr_md, **md = NULL; 400: u32 priv = 0, level = adreno_get_level(context); 401: u64 curr_gmem_size = adreno_gmem_size(adreno_dev); 402: u64 flags = 0; 403: int ret = 0; 404: 405: if (context->flags & KGSL_CONTEXT_LPAC) 406: return 0; 407: 408: if (!ADRENO_FEATURE(adreno_dev, ADRENO_PREEMPTION) || 409: !ADRENO_FEATURE(adreno_dev, ADRENO_DEFER_GMEM_ALLOC)) 410: return 0; 411: 412: /* No need to allocate gmem for RB0 preemption record */ 413: if (!level) 414: return 0; 415: 416: md = context->flags & KGSL_CONTEXT_SECURE ? 417: &hwsched->secure_preempt_rec_gmem[level - 1] : 418: &hwsched->preempt_rec_gmem[level - 1]; 419: 420: /* Avoid device mutex if buffer is already allocated */ 421: if (*md) 422: return 0; 423: 424: kgsl_mutex_lock(&device->mutex); 425: 426: if (*md) 427: goto unlock; 428: 429: entry = get_preempt_record_entry(adreno_dev, context->flags); 430: if (!entry) { 431: dev_err_ratelimited(GMU_PDEV_DEV(device), 432: "preempt record entry not found\n"); 433: ret = -EINVAL; 434: goto unlock; 435: } 436: 437: pr_md = context->flags & KGSL_CONTEXT_SECURE ? 438: hwsched->secure_preempt_rec[level] : hwsched->preempt_rec[level]; 439: 440: if ((pr_md->gpuaddr + pr_md->size + curr_gmem_size) > 441: (entry->md->gpuaddr + entry->md->size)) { 442: ret = -ENOSPC; 443: goto unlock; 444: } 445: 446: setup_gfx_flags_priv(entry->desc.flags, &flags, &priv); 447: 448: /* gmem section only needs to be mapped to gpu */ 449: *md = kgsl_alloc_map_gpu_global(device, pr_md->gpuaddr + pr_md->size, 450: curr_gmem_size, 0, flags, priv, 451: (entry->desc.mem_kind == HFI_MEMKIND_CSW_PRIV_SECURE) ? 452: "sec_preempt_record_gmem" : "preempt_record_gmem"); 453: if (!*md) { 454: dev_err_ratelimited(GMU_PDEV_DEV(device), 455: "Failed to allocate gmem preempt record for rb:%d\n", level); 456: ret = PTR_ERR(*md); 457: kfree(*md); 458: } 459: unlock: 460: kgsl_mutex_unlock(&device->mutex); 461: return ret; 462: } 463: 464: static bool is_cmdobj(struct kgsl_drawobj *drawobj) 465: { 466: return (drawobj->type & CMDOBJ_TYPE); 467: } 468: 469: static bool _check_context_queue(struct adreno_context *drawctxt, u32 count) 470: { 471: bool ret; 472: 473: spin_lock(&drawctxt->lock); 474: 475: /* 476: * Wake up if there is room in the context or if the whole thing got 477: * invalidated while we were asleep 478: */ 479: MATCH LINES: 547, 551 535: } 536: 537: /* Only retire the timestamp. The drawobj will be destroyed later */ 538: static void _retire_timestamp_only(struct kgsl_drawobj *drawobj) 539: { 540: struct kgsl_context *context = drawobj->context; 541: struct kgsl_device *device = context->device; 542: 543: /* 544: * Write the start and end timestamp to the memstore to keep the 545: * accounting sane 546: */ 547: kgsl_sharedmem_writel(device->memstore, 548: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 549: drawobj->timestamp); 550: 551: kgsl_sharedmem_writel(device->memstore, 552: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 553: drawobj->timestamp); 554: 555: msm_perf_events_update(MSM_PERF_GFX, MSM_PERF_RETIRED, 556: pid_nr(context->proc_priv->pid), 557: context->id, drawobj->timestamp, 558: !!(drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME)); 559: 560: if (drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME) { 561: atomic64_inc(&drawobj->context->proc_priv->frame_count); 562: atomic_inc(&drawobj->context->proc_priv->period->frames); 563: } 564: 565: /* Retire pending GPU events for the object */ 566: kgsl_process_event_group(device, &context->events); 567: } 568: 569: static void _retire_timestamp(struct kgsl_drawobj *drawobj) 570: { 571: _retire_timestamp_only(drawobj); 572: 573: kgsl_drawobj_destroy(drawobj); 574: } 575: MATCH LINES: 637 625: _retire_timestamp(drawobj); 626: return 0; 627: } 628: 629: if (!test_and_set_bit(KGSL_BINDOBJ_STATE_START, &bindobj->state)) { 630: /* 631: * Take a reference to the drawobj and the context because both 632: * get referenced in the bind callback 633: */ 634: _kgsl_context_get(&drawctxt->base); 635: kref_get(&drawobj->refcount); 636: 637: kgsl_sharedmem_bind_ranges(bindobj->bind); 638: } 639: 640: return -EAGAIN; 641: } 642: 643: /* 644: * Retires all expired marker and sync objs from the context 645: * queue and returns one of the below 646: * a) next drawobj that needs to be sent to ringbuffer 647: * b) -EAGAIN for syncobj with syncpoints pending. 648: * c) -EAGAIN for markerobj whose marker timestamp has not expired yet. 649: * c) NULL for no commands remaining in drawqueue. 650: */ 651: static struct kgsl_drawobj *_process_drawqueue_get_next_drawobj( 652: struct adreno_device *adreno_dev, struct adreno_context *drawctxt) 653: { 654: struct kgsl_drawobj *drawobj; 655: unsigned int i = drawctxt->drawqueue_head; 656: struct kgsl_drawobj_cmd *cmdobj; 657: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 658: int ret = 0; 659: 660: if (drawctxt->drawqueue_head == drawctxt->drawqueue_tail) 661: return NULL; MATCH LINES: 1785, 1803, 1807 1773: adreno_set_dispatch_ops(adreno_dev, NULL); 1774: 1775: kmem_cache_destroy(jobs_cache); 1776: kmem_cache_destroy(obj_cache); 1777: 1778: sysfs_remove_files(&device->dev->kobj, _hwsched_attr_list); 1779: 1780: kfree(hwsched->ctxt_bad); 1781: 1782: adreno_hwsched_deregister_hw_fence(adreno_dev); 1783: 1784: if (hwsched->global_ctxtq.hostptr) 1785: kgsl_sharedmem_free(&hwsched->global_ctxtq); 1786: 1787: kobject_put(&hwsched->dcvs_kobj); 1788: kobject_put(&hwsched->tunables_kobj); 1789: } 1790: 1791: static void force_retire_timestamp(struct kgsl_device *device, 1792: struct kgsl_drawobj *drawobj) 1793: { 1794: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1795: 1796: if (test_bit(ADRENO_HWSCHED_FORCE_RETIRE_GMU, &adreno_dev->hwsched.flags)) { 1797: struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj); 1798: 1799: set_bit(CMDOBJ_NOP_SUBMISSION, &cmdobj->priv); 1800: return; 1801: } 1802: 1803: kgsl_sharedmem_writel(device->memstore, 1804: KGSL_MEMSTORE_OFFSET(drawobj->context->id, soptimestamp), 1805: drawobj->timestamp); 1806: 1807: kgsl_sharedmem_writel(device->memstore, 1808: KGSL_MEMSTORE_OFFSET(drawobj->context->id, eoptimestamp), 1809: drawobj->timestamp); 1810: } 1811: 1812: /* Return true if drawobj needs to replayed, false otherwise */ 1813: bool adreno_hwsched_drawobj_replay(struct adreno_device *adreno_dev, 1814: struct kgsl_drawobj *drawobj) 1815: { 1816: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1817: struct kgsl_drawobj_cmd *cmdobj; 1818: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 1819: 1820: if ((drawobj->type & SYNCOBJ_TYPE) != 0) { 1821: if (kgsl_context_is_bad(drawobj->context) || 1822: adreno_hwsched_hw_syncobj_retired(drawobj)) { 1823: adreno_hwsched_hw_syncobj_destroy(drawobj); 1824: return false; 1825: } 1826: 1827: return true; 1828: } 1829: 1830: cmdobj = CMDOBJ(drawobj); 1831: MATCH LINES: 2478 2466: return; 2467: 2468: /* Do not create a hardware backed fence, if this context is bad or going away */ 2469: if (kgsl_context_is_bad(context)) 2470: return; 2471: 2472: hwsched_ops->create_hw_fence(adreno_dev, kfence); 2473: } 2474: 2475: static int adreno_hwsched_setup_context(struct adreno_device *adreno_dev, 2476: struct adreno_context *drawctxt) 2477: { 2478: return adreno_hwsched_alloc_preempt_record_gmem(adreno_dev, drawctxt); 2479: } 2480: 2481: static const struct adreno_dispatch_ops hwsched_ops = { 2482: .close = adreno_hwsched_dispatcher_close, 2483: .queue_cmds = adreno_hwsched_queue_cmds, 2484: .queue_context = adreno_hwsched_queue_context, 2485: .create_hw_fence = adreno_hwsched_create_hw_fence, 2486: .setup_context = adreno_hwsched_setup_context, 2487: }; 2488: 2489: static void hwsched_lsr_check(struct work_struct *work) 2490: { 2491: struct adreno_hwsched *hwsched = container_of(work, 2492: struct adreno_hwsched, lsr_check_ws); 2493: struct adreno_device *adreno_dev = container_of(hwsched, 2494: struct adreno_device, hwsched); 2495: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2496: 2497: kgsl_mutex_lock(&device->mutex); 2498: kgsl_pwrscale_update_stats(device); 2499: kgsl_pwrscale_update(device); 2500: kgsl_mutex_unlock(&device->mutex); 2501: 2502: mod_timer(&hwsched->lsr_timer, jiffies + msecs_to_jiffies(10)); MATCH LINES: 2596, 2600 2584: if (!is_cmdobj(drawobj)) 2585: continue; 2586: 2587: cmdobj = CMDOBJ(drawobj); 2588: 2589: if (test_bit(CMDOBJ_FAULT, &cmdobj->priv)) { 2590: struct kgsl_memobj_node *ib; 2591: 2592: list_for_each_entry(ib, &cmdobj->cmdlist, node) { 2593: if (drawobj->context->flags & KGSL_CONTEXT_LPAC) 2594: adreno_parse_ib_lpac(KGSL_DEVICE(adreno_dev), 2595: snapshot, snapshot->process_lpac, 2596: ib->gpuaddr, ib->size >> 2); 2597: else 2598: adreno_parse_ib(KGSL_DEVICE(adreno_dev), 2599: snapshot, snapshot->process, 2600: ib->gpuaddr, ib->size >> 2); 2601: } 2602: clear_bit(CMDOBJ_FAULT, &cmdobj->priv); 2603: } 2604: } 2605: } 2606: 2607: static int unregister_context(int id, void *ptr, void *data) 2608: { 2609: struct kgsl_context *context = ptr; 2610: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 2611: 2612: if (drawctxt->gmu_context_queue.gmuaddr != 0) { 2613: struct gmu_context_queue_header *header = drawctxt->gmu_context_queue.hostptr; 2614: 2615: header->read_index = header->write_index; 2616: /* This is to make sure GMU sees the correct indices after recovery */ 2617: mb(); 2618: } 2619: 2620: /* 2621: * We don't need to send the unregister hfi packet because 2622: * we are anyway going to lose the gmu state of registered 2623: * contexts. So just reset the flag so that the context 2624: * registers with gmu on its first submission post slumber. MATCH LINES: 2791, 2794, 2797 2779: return; 2780: 2781: if (test_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags)) 2782: return; 2783: 2784: if (kgsl_hw_fence_init(device)) 2785: return; 2786: 2787: /* 2788: * We need to set up the memory descriptor with the physical address of the Tx/Rx Queues so 2789: * that these buffers can be imported in to GMU VA space 2790: */ 2791: kgsl_memdesc_init(device, &hwsched->hw_fence.md, 0); 2792: kgsl_hw_fence_populate_md(device, &hwsched->hw_fence.md); 2793: 2794: ret = kgsl_memdesc_sg_dma(&hwsched->hw_fence.md, hwsched->hw_fence.md.physaddr, 2795: hwsched->hw_fence.md.size); 2796: if (ret) { 2797: dev_err(device->dev, "Failed to setup HW fences memdesc: %d\n", 2798: ret); 2799: kgsl_hw_fence_close(device); 2800: memset(&hwsched->hw_fence.md, 0x0, sizeof(hwsched->hw_fence.md)); 2801: return; 2802: } 2803: 2804: hwsched->hw_fence_cache = KMEM_CACHE(adreno_hw_fence_entry, 0); 2805: 2806: set_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags); 2807: } 2808: 2809: int adreno_hwsched_wait_ack_completion(struct adreno_device *adreno_dev, 2810: struct device *dev, struct pending_cmd *ack, 2811: void (*process_msgq)(struct adreno_device *adreno_dev)) 2812: { 2813: int rc; 2814: /* Only allow a single log in a second */ 2815: static DEFINE_RATELIMIT_STATE(_rs, HZ, 1); 2816: static u32 unprocessed, processed; 2817: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 2818: u64 start, end; 2819: 2820: start = gpudev->read_alwayson(adreno_dev); 2821: rc = wait_for_completion_timeout(&ack->complete, MATCH LINES: 3100 3088: FIELD_GET(GENMASK(16, 0), addr[1]) << 32 | addr[0], 3089: FIELD_GET(GENMASK(31, 23), addr[1])); 3090: break; 3091: } 3092: default: 3093: non_fatal = false; 3094: break; 3095: } 3096: 3097: return non_fatal; 3098: } 3099: 3100: int adreno_hwsched_poll_msg_queue_write_index(struct kgsl_memdesc *hfi_mem) 3101: { 3102: struct hfi_queue_table *tbl = hfi_mem->hostptr; 3103: struct hfi_queue_header *hdr = &tbl->qhdr[HFI_MSG_ID]; 3104: unsigned long timeout = jiffies + msecs_to_jiffies(HFI_RSP_TIMEOUT); 3105: 3106: while (time_before(jiffies, timeout)) { 3107: if (hdr->write_index != hdr->read_index) 3108: goto done; 3109: 3110: /* Wait for up to 100 us before trying again */ 3111: usleep_range((POLL_SLEEP_US >> 2) + 1, POLL_SLEEP_US); 3112: cpu_relax(); 3113: } 3114: 3115: /* Check if the write index has advanced */ 3116: if (hdr->write_index == hdr->read_index) 3117: return -ETIMEDOUT; 3118: 3119: done: 3120: /* 3121: * This is to ensure that the queue is not read speculatively before the 3122: * polling condition is evaluated. 3123: */ 3124: rmb(); MATCH LINES: 3212 3200: msm_perf_events_update(MSM_PERF_GFX, MSM_PERF_SUBMIT, 3201: pid_nr(context->proc_priv->pid), 3202: context->id, drawobj->timestamp, 3203: !!(drawobj->flags & KGSL_DRAWOBJ_END_OF_FRAME)); 3204: trace_adreno_cmdbatch_submitted(drawobj, &info, time->ticks, 3205: (unsigned long) time_in_s, time_in_ns / 1000, 0); 3206: 3207: log_kgsl_cmdbatch_submitted_event(context->id, drawobj->timestamp, 3208: context->priority, drawobj->flags); 3209: } 3210: 3211: int adreno_gmu_context_queue_write(struct adreno_device *adreno_dev, 3212: struct kgsl_memdesc *gmu_context_queue, u32 *msg, u32 size_bytes, 3213: struct kgsl_drawobj *drawobj, struct adreno_submit_time *time) 3214: { 3215: struct gmu_context_queue_header *hdr = gmu_context_queue->hostptr; 3216: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 3217: u32 *queue = gmu_context_queue->hostptr + sizeof(*hdr); 3218: u32 i, empty_space, write_idx = hdr->write_index, read_idx = hdr->read_index; 3219: u32 size_dwords = size_bytes >> 2; 3220: u32 align_size = ALIGN(size_dwords, SZ_4); 3221: u32 id = MSG_HDR_GET_ID(*msg); 3222: struct kgsl_drawobj_cmd *cmdobj = NULL; 3223: 3224: empty_space = (write_idx >= read_idx) ? 3225: (hdr->queue_size - (write_idx - read_idx)) 3226: : (read_idx - write_idx); 3227: 3228: if (empty_space <= align_size) 3229: return -ENOSPC; 3230: 3231: if (!IS_ALIGNED(size_bytes, sizeof(u32))) 3232: return -EINVAL; 3233: 3234: for (i = 0; i < size_dwords; i++) { 3235: queue[write_idx] = msg[i]; 3236: write_idx = (write_idx + 1) % hdr->queue_size; MATCH LINES: 3356, 3363, 3365, 3366, 3377, 3381 3344: 3345: trace_adreno_cmdbatch_retired(context, &info, 0, 0, 0); 3346: 3347: log_kgsl_cmdbatch_retired_event(context->id, cmd->ts, 3348: context->priority, 0, cmd->sop, cmd->eop); 3349: 3350: _retire_inflight_hw_fences(adreno_dev, context); 3351: 3352: kgsl_context_put(context); 3353: } 3354: 3355: void *adreno_hwsched_get_rb_hostptr(struct adreno_device *adreno_dev, 3356: u64 gpuaddr, u32 size) 3357: { 3358: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3359: u64 offset; 3360: u32 i; 3361: 3362: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 3363: struct kgsl_memdesc *md = hwsched->mem_alloc_table[i].md; 3364: 3365: if (kgsl_gpuaddr_in_memdesc(md, gpuaddr, size)) { 3366: offset = gpuaddr - md->gpuaddr; 3367: return md->hostptr + offset; 3368: } 3369: } 3370: 3371: return NULL; 3372: } 3373: 3374: void adreno_hwsched_reset_hfi_mem(struct adreno_device *adreno_dev) 3375: { 3376: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 3377: struct kgsl_memdesc *md = NULL; 3378: u32 i; 3379: 3380: for (i = 0; i < hwsched->mem_alloc_entries; i++) { 3381: struct hfi_mem_alloc_desc *desc = &hwsched->mem_alloc_table[i].desc; 3382: 3383: if (desc->flags & HFI_MEMFLAG_HOST_INIT) { 3384: md = hwsched->mem_alloc_table[i].md; 3385: if (md->hostptr) 3386: memset(md->hostptr, 0x0, md->size); 3387: } 3388: } 3389: 3390: if (!(adreno_is_preemption_enabled(adreno_dev) && 3391: ADRENO_FEATURE(adreno_dev, ADRENO_DEFER_GMEM_ALLOC))) 3392: return; 3393: 3394: /* No need to reset gmem portion of the preemption records */ 3395: for (i = 0; i < KGSL_PRIORITY_MAX_RB_LEVELS; i++) { 3396: md = hwsched->preempt_rec[i]; 3397: if (md && md->hostptr) 3398: memset(md->hostptr, 0x0, md->size); 3399: } 3400: } --- FILE: \adreno_hwsched.h | HITS: 17 --- MATCH LINES: 52 40: * @defer_ts: The timestamp of the hardware fence which got deferred 41: */ 42: u32 defer_ts; 43: /** 44: * @flags: Flags to control the creation of new hardware fences 45: */ 46: unsigned long flags; 47: /** @seqnum: Sequence number for hardware fence packet header */ 48: atomic_t seqnum; 49: /** @soccp_rproc: rproc handle for soccp */ 50: struct rproc *soccp_rproc; 51: /** @hw_fence_md: Kgsl memory descriptor for hardware fences queue */ 52: struct kgsl_memdesc md; 53: /** @pending_count: Number of hardware fences that haven't yet been sent to Tx Queue */ 54: u32 pending_count; 55: }; 56: 57: /** 58: * struct adreno_hw_fence_entry - A structure to store hardware fence and the context 59: */ 60: struct adreno_hw_fence_entry { 61: /** @cmd: H2F_MSG_HW_FENCE_INFO packet for this hardware fence */ 62: struct hfi_hw_fence_info cmd; 63: /** @kfence: Pointer to the kgsl fence */ 64: struct kgsl_sync_fence *kfence; 65: /** @drawctxt: Pointer to the context */ 66: struct adreno_context *drawctxt; 67: /** @node: list node to add it to a list */ 68: struct list_head node; 69: /** @reset_node: list node to add it to post reset list of hardware fences */ 70: struct list_head reset_node; 71: }; 72: 73: /** 74: * struct adreno_hwsched_ops - Function table to hook hwscheduler things 75: * to target specific routines 76: */ MATCH LINES: 120, 121, 122, 158, 166, 171, 176, 181, 211, 216, 217 108: 109: struct adreno_dcvs_tunable { 110: /** @value: Stores the requested value for the tunable **/ 111: u32 value; 112: /** @update: True if this value needs to be sent to GMU at slumber exit **/ 113: bool update; 114: }; 115: 116: /** 117: * struct adreno_hwsched - Container for the hardware scheduler 118: */ 119: struct adreno_hwsched { 120: /** @mem_alloc_table: Array of HFI memory allocation entries */ 121: struct hfi_mem_alloc_entry mem_alloc_table[32]; 122: /** @mem_alloc_entries: Number of entries in the memory allocation table */ 123: u32 mem_alloc_entries; 124: /** @mutex: Mutex needed to run dispatcher function */ 125: struct mutex mutex; 126: /** @flags: Container for the dispatcher internal flags */ 127: unsigned long flags; 128: /** @inflight: Number of active submissions to the dispatch queues */ 129: u32 inflight; 130: /** @jobs - Array of dispatch job lists for each priority level */ 131: struct llist_head jobs[16]; 132: /** @requeue - Array of lists for dispatch jobs that got requeued */ 133: struct llist_head requeue[16]; 134: /** @cmd_list: List of objects submitted to dispatch queues */ 135: struct list_head cmd_list; 136: /** @hwsched_ops: Container for target specific hwscheduler ops */ 137: const struct adreno_hwsched_ops *hwsched_ops; 138: /** @ctxt_bad: Container for the context bad hfi packet */ 139: void *ctxt_bad; 140: /** @idle_gate: Gate to wait on for hwscheduler to idle */ 141: struct completion idle_gate; 142: /** @big_cmdobj = Points to the big IB that is inflight */ 143: struct kgsl_drawobj_cmd *big_cmdobj; 144: /** @recurring_cmdobj: Recurring commmand object sent to GMU */ 145: struct kgsl_drawobj_cmd *recurring_cmdobj; 146: /** @lsr_timer: Timer struct to schedule lsr work */ 147: struct timer_list lsr_timer; 148: /** @lsr_check_ws: Lsr work to update power stats */ 149: struct work_struct lsr_check_ws; 150: /** @hw_fence: Container for the hw fences instance */ 151: struct kmem_cache *hw_fence_cache; 152: /** 153: * @submission_seqnum: Sequence number for sending submissions to GMU context queues or 154: * dispatch queues 155: */ 156: atomic_t submission_seqnum; 157: /** @global_ctxtq: Memory descriptor for global context queue */ 158: struct kgsl_memdesc global_ctxtq; 159: /** @global_ctxt_gmu_registered: Whether global context is registered with gmu */ 160: bool global_ctxt_gmu_registered; 161: /** @hw_fence: Container for hw fence related structures */ 162: struct adreno_hwsched_hw_fence hw_fence; 163: /** @reset_type: GPU fault reset (hard/soft) type */ 164: enum gpu_reset_type reset_type; 165: /** @preempt_rec: Memory descriptors for non-gmem part of preemption records */ 166: struct kgsl_memdesc *preempt_rec[KGSL_PRIORITY_MAX_RB_LEVELS]; 167: /** 168: * @preempt_rec_gmem: Memory descriptors for gmem part of preemption 169: * records. No gmem buffer needed for rb0 preemption record. 170: */ 171: struct kgsl_memdesc *preempt_rec_gmem[KGSL_PRIORITY_MAX_RB_LEVELS - 1]; 172: /** 173: * @secure_preempt_rec: Memory descriptors for non-gmem part of secure 174: * preemption records 175: */ 176: struct kgsl_memdesc *secure_preempt_rec[KGSL_PRIORITY_MAX_RB_LEVELS]; 177: /** 178: * @secure_preempt_rec_gmem: Memory descriptors for gmem part of secure 179: * preemption records. No gmem buffer needed for rb0 preemption record. 180: */ 181: struct kgsl_memdesc *secure_preempt_rec_gmem[KGSL_PRIORITY_MAX_RB_LEVELS - 1]; 182: /** @dcvs_param_update: True if dcvs params have to be sent to GMU at slumber exit */ 183: bool dcvs_param_update; 184: /** @tunables_kobj: Kobj for dcvs tunables **/ 185: struct kobject tunables_kobj; 186: /** @dcvs_kobj: Kobj for dcvs params **/ 187: struct kobject dcvs_kobj; 188: /** @sysfs_dcvs_tunables : Tuning parameters for GMU based DCVS **/ 189: struct adreno_dcvs_tunable sysfs_dcvs_tunables[GPU_TUNING_KEY_MAX]; 190: /** @default_dcvs_tunables: Default value of GMU based DCVS tunables **/ 191: u32 default_dcvs_tunables[GPU_TUNING_KEY_MAX]; 192: }; 193: 194: /* 195: * This value is based on maximum number of IBs that can fit 196: * in the ringbuffer. 197: */ 198: #define HWSCHED_MAX_IBS 2000 199: 200: enum adreno_hwsched_flags { 201: ADRENO_HWSCHED_POWER = 0, 202: ADRENO_HWSCHED_ACTIVE, 203: ADRENO_HWSCHED_CTX_BAD_LEGACY, 204: ADRENO_HWSCHED_CONTEXT_QUEUE, 205: ADRENO_HWSCHED_HW_FENCE, 206: ADRENO_HWSCHED_FORCE_RETIRE_GMU, 207: ADRENO_HWSCHED_GPU_SOFT_RESET, 208: }; 209: 210: /** 211: * adreno_hwsched_process_mem_alloc - Process memory allocation for hwsched 212: * @adreno_dev: Pointer to the adreno device 213: * @mad: Pointer to the HFI memory allocation descriptor 214: * 215: * This function processes the memory allocation request for the hwsched. 216: * It retrieves or allocates the necessary memory based on the provided 217: * descriptor and updates the descriptor with the allocated memory addresses. 218: * 219: * Return: 0 on success, or a negative error code on failure. 220: */ 221: int adreno_hwsched_process_mem_alloc(struct adreno_device *adreno_dev, 222: struct hfi_mem_alloc_desc *mad); 223: 224: /** 225: * adreno_hwsched_start() - activate the hwsched dispatcher 226: * @adreno_dev: pointer to the adreno device 227: * 228: * Enable dispatcher thread to execute 229: */ 230: void adreno_hwsched_start(struct adreno_device *adreno_dev); 231: /** 232: * adreno_hwsched_init() - Initialize the hwsched 233: * @adreno_dev: pointer to the adreno device 234: * @hwsched_ops: Pointer to target specific hwsched ops 235: * 236: * Set up the hwsched resources. 237: * Return: 0 on success or negative on failure. 238: */ 239: int adreno_hwsched_init(struct adreno_device *adreno_dev, 240: const struct adreno_hwsched_ops *hwsched_ops); 241: MATCH LINES: 379, 414, 448, 452, 459 367: * 368: * Return: True for non fatal error code else false. 369: */ 370: bool adreno_hwsched_log_nonfatal_gpu_fault(struct adreno_device *adreno_dev, 371: struct device *dev, u32 error); 372: 373: /** 374: * adreno_hwsched_poll_msg_queue_write_index - Poll on write index of HFI message queue 375: * @hfi_mem: Memory descriptor for HFI queue table 376: * 377: * Returns zero if write index advances or ETIMEDOUT if timed out polling 378: */ 379: int adreno_hwsched_poll_msg_queue_write_index(struct kgsl_memdesc *hfi_mem); 380: 381: /** 382: * adreno_hwsched_remove_hw_fence_entry - Remove hardware fence entry 383: * @adreno_dev: pointer to the adreno device 384: * @entry: Pointer to the hardware fence entry 385: */ 386: void adreno_hwsched_remove_hw_fence_entry(struct adreno_device *adreno_dev, 387: struct adreno_hw_fence_entry *entry); 388: 389: /** 390: * adreno_gmu_context_queue_read - Read data from context queue 391: * @drawctxt: Pointer to the adreno draw context 392: * @output: Pointer to read the data into 393: * @read_idx: Index to read the data from 394: * @size: Number of dwords to read from the context queue 395: * 396: * Return: 0 on success or negative error on failure 397: */ 398: int adreno_gmu_context_queue_read(struct adreno_context *drawctxt, u32 *output, 399: u32 read_idx, u32 size); 400: 401: /** 402: * adreno_gmu_context_queue_write - Write data to context queue 403: * 404: * @adreno_dev: Pointer to adreno device structure 405: * @gmu_context_queue: Pointer to the memory descriptor for context queue 406: * @msg: Pointer to the message data to be written 407: * @size_bytes: Size of the message data in bytes 408: * @drawobj: Pointer to the draw object 409: * @time: Pointer to the submission time information 410: * 411: * Return: 0 on success or negative error on failure 412: */ 413: int adreno_gmu_context_queue_write(struct adreno_device *adreno_dev, 414: struct kgsl_memdesc *gmu_context_queue, u32 *msg, u32 size_bytes, 415: struct kgsl_drawobj *drawobj, struct adreno_submit_time *time); 416: 417: /** 418: * adreno_hwsched_add_profile_events - Add profiling events 419: * 420: * @adreno_dev: Pointer to the adreno device structure 421: * @cmdobj: Pointer to the command object 422: * @time: Pointer to the submission time information 423: */ 424: void adreno_hwsched_add_profile_events(struct adreno_device *adreno_dev, 425: struct kgsl_drawobj_cmd *cmdobj, struct adreno_submit_time *time); 426: 427: /** 428: * adreno_hwsched_log_profiling_info - Log profiling information for a retired 429: * command batch 430: * @adreno_dev: Pointer to the adreno device structure 431: * @rcvd: Pointer to the received HFI timestamp retire command 432: */ 433: void adreno_hwsched_log_profiling_info(struct adreno_device *adreno_dev, u32 *rcvd); 434: 435: /** 436: * adreno_hwsched_drawobj_replay - Check drawobj need to be replayed or not 437: * @adreno_dev: Pointer to the adreno device structure 438: * @drawobj: Pointer to the draw object 439: * 440: * Return true if drawobj needs to replayed, false otherwise 441: */ 442: bool adreno_hwsched_drawobj_replay(struct adreno_device *adreno_dev, 443: struct kgsl_drawobj *drawobj); 444: 445: /** 446: * adreno_hwsched_get_rb_hostptr - Get the host pointer for a given GPU address 447: * @adreno_dev: Pointer to the adreno device 448: * @gpuaddr: GPU address to look up 449: * @size: Size of the memory region 450: * 451: * This function retrieves the host pointer corresponding to a given GPU address. 452: * It searches through the memory allocation table to find the matching memory 453: * descriptor and calculates the host pointer offset. 454: * 455: * Return: Host pointer if found, or NULL if the GPU address is not found in the 456: * memory allocation table. 457: */ 458: void *adreno_hwsched_get_rb_hostptr(struct adreno_device *adreno_dev, 459: u64 gpuaddr, u32 size); 460: 461: /** 462: * adreno_hwsched_reset_hfi_mem - Reset HFI memory records 463: * @adreno_dev: Pointer to the adreno device 464: * 465: * GMU expects hfi memory records to be clear during bootup. This function 466: * iterates through the memory allocation table and resets entries with 467: * HFI_MEMFLAG_HOST_INIT set. 468: */ 469: void adreno_hwsched_reset_hfi_mem(struct adreno_device *adreno_dev); 470: 471: /** 472: * adreno_hwsched_context_init - Function for context creation 473: * @drawctxt: Pointer to the adreno context 474: * 475: * Allocate resources at the time of context creation 476: * 477: * Return: Zero on success or negative error on failure 478: */ 479: int adreno_hwsched_context_init(struct adreno_context *drawctxt); 480: 481: /* 482: * adreno_hwsched_retire_cmdlist_obj - helper function for cleaning up cmd_list_obj 483: * @adreno_dev: Pointer to the adreno device --- FILE: \adreno_hwsched_snapshot.c | HITS: 22 --- MATCH LINES: 15, 29, 57, 61, 62, 63, 69, 74, 89, 103, 116 3: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 4: */ 5: 6: #include "adreno.h" 7: #include "adreno_hwsched_snapshot.h" 8: #include "adreno_snapshot.h" 9: 10: size_t adreno_hwsched_snapshot_rb(struct kgsl_device *device, u8 *buf, 11: size_t remain, void *priv) 12: { 13: struct kgsl_snapshot_rb_v2 *header = (struct kgsl_snapshot_rb_v2 *)buf; 14: u32 *data = (u32 *)(buf + sizeof(*header)); 15: struct kgsl_memdesc *rb = (struct kgsl_memdesc *)priv; 16: 17: if (remain < rb->size + sizeof(*header)) { 18: SNAPSHOT_ERR_NOMEM(device, "RB"); 19: return 0; 20: } 21: 22: header->start = 0; 23: header->end = rb->size >> 2; 24: header->rptr = 0; 25: header->rbsize = rb->size >> 2; 26: header->count = rb->size >> 2; 27: header->timestamp_queued = 0; 28: header->timestamp_retired = 0; 29: header->gpuaddr = rb->gpuaddr; 30: header->id = 0; 31: 32: memcpy(data, rb->hostptr, rb->size); 33: 34: return rb->size + sizeof(*header); 35: } 36: 37: static u32 copy_gpu_global(void *out, void *in, u32 size) 38: { 39: if (out && in) { 40: memcpy(out, in, size); 41: return size; 42: } 43: 44: return 0; 45: } 46: 47: static void adreno_hwsched_snapshot_rb_payload(struct adreno_device *adreno_dev, 48: struct kgsl_snapshot *snapshot, struct payload_section *payload) 49: { 50: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 51: struct kgsl_snapshot_section_header *section_header = 52: (struct kgsl_snapshot_section_header *)snapshot->ptr; 53: u8 *buf = snapshot->ptr + sizeof(*section_header); 54: struct kgsl_snapshot_rb_v2 *header = (struct kgsl_snapshot_rb_v2 *)buf; 55: u32 *data = (u32 *)(buf + sizeof(*header)); 56: u32 size = adreno_hwsched_parse_payload(payload, KEY_RB_SIZEDWORDS) << 2; 57: u64 lo, hi, gpuaddr; 58: void *rb_hostptr = NULL; 59: char str[16]; 60: 61: lo = adreno_hwsched_parse_payload(payload, KEY_RB_GPUADDR_LO); 62: hi = adreno_hwsched_parse_payload(payload, KEY_RB_GPUADDR_HI); 63: gpuaddr = hi << 32 | lo; 64: 65: /* Sanity check to make sure there is enough for the header */ 66: if (snapshot->remain < sizeof(*section_header)) 67: goto err; 68: 69: rb_hostptr = adreno_hwsched_get_rb_hostptr(adreno_dev, gpuaddr, size); 70: 71: if (rb_hostptr == NULL) 72: goto err; 73: 74: /* If the gpuaddress and size don't match any allocation, then abort */ 75: if (((snapshot->remain - sizeof(*section_header)) < (size + sizeof(*header))) || 76: !copy_gpu_global(data, rb_hostptr, size)) 77: goto err; 78: 79: if (device->dump_all_ibs) { 80: u64 rbaddr, lpac_rbaddr; 81: 82: adreno_readreg64(adreno_dev, ADRENO_REG_CP_RB_BASE, 83: ADRENO_REG_CP_RB_BASE_HI, &rbaddr); 84: 85: adreno_readreg64(adreno_dev, ADRENO_REG_CP_LPAC_RB_BASE, 86: ADRENO_REG_CP_LPAC_RB_BASE_HI, &lpac_rbaddr); 87: 88: /* Parse all IBs from current RB */ 89: if ((rbaddr == gpuaddr) || (lpac_rbaddr == gpuaddr)) 90: adreno_snapshot_dump_all_ibs(device, rb_hostptr, snapshot); 91: } 92: 93: header->start = 0; 94: header->end = size >> 2; 95: header->rptr = adreno_hwsched_parse_payload(payload, KEY_RB_RPTR); 96: header->wptr = adreno_hwsched_parse_payload(payload, KEY_RB_WPTR); 97: header->rbsize = size >> 2; 98: header->count = size >> 2; 99: header->timestamp_queued = adreno_hwsched_parse_payload(payload, 100: KEY_RB_QUEUED_TS); 101: header->timestamp_retired = adreno_hwsched_parse_payload(payload, 102: KEY_RB_RETIRED_TS); 103: header->gpuaddr = gpuaddr; 104: header->id = adreno_hwsched_parse_payload(payload, KEY_RB_ID); 105: 106: section_header->magic = SNAPSHOT_SECTION_MAGIC; 107: section_header->id = KGSL_SNAPSHOT_SECTION_RB_V2; 108: section_header->size = size + sizeof(*header) + sizeof(*section_header); 109: 110: snapshot->ptr += section_header->size; 111: snapshot->remain -= section_header->size; 112: snapshot->size += section_header->size; 113: 114: return; 115: err: 116: snprintf(str, sizeof(str), "RB addr:0x%llx", gpuaddr); 117: SNAPSHOT_ERR_NOMEM(device, str); 118: } 119: 120: bool adreno_hwsched_parse_payload_rb_legacy(struct adreno_device *adreno_dev, 121: struct kgsl_snapshot *snapshot) 122: { 123: struct hfi_context_bad_cmd_legacy *cmd = adreno_dev->hwsched.ctxt_bad; 124: u32 i = 0, payload_bytes; 125: void *start; 126: bool ret = false; 127: 128: /* Skip if we didn't receive a context bad HFI */ 129: if (!cmd->hdr) 130: return false; 131: 132: payload_bytes = (MSG_HDR_GET_SIZE(cmd->hdr) << 2) - 133: offsetof(struct hfi_context_bad_cmd_legacy, payload); 134: 135: start = &cmd->payload[0]; 136: 137: while (i < payload_bytes) { 138: struct payload_section *payload = start + i; 139: 140: if (payload->type == PAYLOAD_RB) { MATCH LINES: 186, 193, 196, 201, 202, 206, 208, 221, 242, 269, 284 174: ret = true; 175: } 176: 177: i += sizeof(*payload) + (payload->dwords << 2); 178: } 179: 180: return ret; 181: } 182: 183: size_t adreno_hwsched_snapshot_aqe_buffer(struct kgsl_device *device, u8 *buf, 184: size_t remain, void *priv) 185: { 186: struct kgsl_memdesc *memdesc = priv; 187: 188: struct kgsl_snapshot_gpu_object_v2 *header = 189: (struct kgsl_snapshot_gpu_object_v2 *)buf; 190: 191: u8 *ptr = buf + sizeof(*header); 192: 193: if (IS_ERR_OR_NULL(memdesc) || memdesc->size == 0) 194: return 0; 195: 196: if (remain < (memdesc->size + sizeof(*header))) { 197: SNAPSHOT_ERR_NOMEM(device, "AQE BUFFER"); 198: return 0; 199: } 200: 201: header->size = memdesc->size >> 2; 202: header->gpuaddr = memdesc->gpuaddr; 203: header->ptbase = MMU_DEFAULT_TTBR0(device); 204: header->type = SNAPSHOT_GPU_OBJECT_GLOBAL; 205: 206: memcpy(ptr, memdesc->hostptr, memdesc->size); 207: 208: return memdesc->size + sizeof(*header); 209: } 210: 211: static int snapshot_context_queue(int id, void *ptr, void *data) 212: { 213: struct kgsl_snapshot *snapshot = data; 214: struct kgsl_context *context = ptr; 215: struct adreno_context *drawctxt = ADRENO_CONTEXT(context); 216: struct gmu_mem_type_desc desc; 217: 218: if (!context->gmu_registered) 219: return 0; 220: 221: desc.memdesc = &drawctxt->gmu_context_queue; 222: desc.type = SNAPSHOT_GMU_MEM_CONTEXT_QUEUE; 223: kgsl_snapshot_add_section(context->device, 224: KGSL_SNAPSHOT_SECTION_GMU_MEMORY, 225: snapshot, adreno_snapshot_gmu_mem, &desc); 226: 227: return 0; 228: } 229: 230: void adreno_hwsched_snapshot_context_queue(struct kgsl_device *device, 231: struct kgsl_snapshot *snapshot) 232: { 233: if (!adreno_hwsched_context_queue_enabled(ADRENO_DEVICE(device))) 234: return; 235: 236: read_lock(&device->context_lock); 237: idr_for_each(&device->context_idr, snapshot_context_queue, snapshot); 238: read_unlock(&device->context_lock); 239: } 240: 241: static void snapshot_preemption_record(struct kgsl_device *device, 242: struct kgsl_snapshot *snapshot, struct kgsl_memdesc *md, u64 offset, u64 size) 243: { 244: struct kgsl_snapshot_section_header *section_header = 245: (struct kgsl_snapshot_section_header *)snapshot->ptr; 246: u8 *dest = snapshot->ptr + sizeof(*section_header); 247: struct kgsl_snapshot_gpu_object_v2 *header = 248: (struct kgsl_snapshot_gpu_object_v2 *)dest; 249: u64 ctxt_record_size = min_t(u64, device->snapshot_ctxt_record_size, size); 250: size_t section_size; 251: 252: if (WARN_RATELIMIT((ctxt_record_size > md->size) || 253: (offset > (md->size - ctxt_record_size)), 254: "Invalid preemption context record size: md_size: 0x%llx, ctxt_record_size: 0x%llx\n", 255: md->size, ctxt_record_size)) 256: return; 257: 258: section_size = sizeof(*section_header) + sizeof(*header) + ctxt_record_size; 259: if (snapshot->remain < section_size) { 260: SNAPSHOT_ERR_NOMEM(device, "PREEMPTION RECORD"); 261: return; 262: } 263: 264: section_header->magic = SNAPSHOT_SECTION_MAGIC; 265: section_header->id = KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2; 266: section_header->size = section_size; 267: 268: header->size = ctxt_record_size >> 2; 269: header->gpuaddr = md->gpuaddr + offset; 270: header->ptbase = 271: kgsl_mmu_pagetable_get_ttbr0(device->mmu.defaultpagetable); 272: header->type = SNAPSHOT_GPU_OBJECT_GLOBAL; 273: 274: dest += sizeof(*header); 275: 276: memcpy(dest, md->hostptr + offset, ctxt_record_size); 277: 278: snapshot->ptr += section_header->size; 279: snapshot->remain -= section_header->size; 280: snapshot->size += section_header->size; 281: } 282: 283: void adreno_hwsched_snapshot_preemption_records(struct kgsl_device *device, 284: struct kgsl_snapshot *snapshot, struct kgsl_memdesc *md) 285: { 286: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 287: u64 offset = 0, ctxt_record_size = md->size; 288: u64 rb0_ctxt_record_size = PAGE_ALIGN(adreno_dev->total_ctxt_record_sz); 289: u64 curr_gmem_size = adreno_gmem_size(adreno_dev); 290: int i; 291: 292: if (ADRENO_FEATURE(adreno_dev, ADRENO_DEFER_GMEM_ALLOC)) { 293: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 294: 295: for (i = 0; i < KGSL_PRIORITY_MAX_RB_LEVELS; i++) 296: snapshot_preemption_record(device, snapshot, 297: hwsched->preempt_rec[i], 0, hwsched->preempt_rec[i]->size); 298: return; 299: } 300: 301: /* Check whether GMU has removed GMEM size from RB0 context record */ 302: if (md->size == (rb0_ctxt_record_size * KGSL_PRIORITY_MAX_RB_LEVELS)) { 303: do_div(ctxt_record_size, KGSL_PRIORITY_MAX_RB_LEVELS); 304: } else { 305: rb0_ctxt_record_size -= PAGE_ALIGN(curr_gmem_size); 306: ctxt_record_size -= rb0_ctxt_record_size; 307: do_div(ctxt_record_size, KGSL_PRIORITY_MAX_RB_LEVELS - 1); 308: } --- FILE: \adreno_hwsched_snapshot.h | HITS: 1 --- MATCH LINES: 25 13: struct kgsl_snapshot *snapshot); 14: 15: size_t adreno_hwsched_snapshot_rb(struct kgsl_device *device, u8 *buf, 16: size_t remain, void *priv); 17: 18: size_t adreno_hwsched_snapshot_aqe_buffer(struct kgsl_device *device, u8 *buf, 19: size_t remain, void *priv); 20: 21: void adreno_hwsched_snapshot_context_queue(struct kgsl_device *device, 22: struct kgsl_snapshot *snapshot); 23: 24: void adreno_hwsched_snapshot_preemption_records(struct kgsl_device *device, 25: struct kgsl_snapshot *snapshot, struct kgsl_memdesc *md); 26: 27: #endif --- FILE: \adreno_pm4types.h | HITS: 9 --- MATCH LINES: 252, 255, 256, 258, 259, 263, 264, 284, 298 240: { 241: return cmd == cp_mem_packet(adreno_dev, 242: CP_INDIRECT_BUFFER_PFE, 2, 1) || 243: cmd == cp_mem_packet(adreno_dev, 244: CP_INDIRECT_BUFFER_PFD, 2, 1) || 245: cmd == cp_mem_packet(adreno_dev, 246: CP_COND_INDIRECT_BUFFER_PFE, 2, 1) || 247: cmd == cp_mem_packet(adreno_dev, 248: CP_COND_INDIRECT_BUFFER_PFD, 2, 1); 249: } 250: 251: /** 252: * cp_gpuaddr - Generic function to add 64bit and 32bit gpuaddr 253: * to pm4 commands 254: * @adreno_dev: The adreno device 255: * @cmds: command pointer to add gpuaddr 256: * @gpuaddr: gpuaddr to add 257: */ 258: static inline uint cp_gpuaddr(struct adreno_device *adreno_dev, 259: uint *cmds, uint64_t gpuaddr) 260: { 261: uint *start = cmds; 262: 263: *cmds++ = lower_32_bits(gpuaddr); 264: *cmds++ = upper_32_bits(gpuaddr); 265: 266: return cmds - start; 267: } 268: 269: /** 270: * cp_register - Generic function for gpu register operation 271: * @adreno_dev: The adreno device 272: * @reg: GPU register 273: * @size: count for PM4 operation 274: */ 275: static inline uint cp_register(struct adreno_device *adreno_dev, 276: unsigned int reg, unsigned int size) 277: { 278: return cp_type4_packet(reg, size); 279: } 280: 281: /** 282: * cp_wait_for_me - common function for WAIT_FOR_ME 283: * @adreno_dev: The adreno device 284: * @cmds: command pointer to add gpuaddr 285: */ 286: static inline uint cp_wait_for_me(struct adreno_device *adreno_dev, 287: uint *cmds) 288: { 289: uint *start = cmds; 290: 291: *cmds++ = cp_type7_packet(CP_WAIT_FOR_ME, 0); 292: return cmds - start; 293: } 294: 295: /** 296: * cp_wait_for_idle - common function for WAIT_FOR_IDLE 297: * @adreno_dev: The adreno device 298: * @cmds: command pointer to add gpuaddr 299: */ 300: static inline uint cp_wait_for_idle(struct adreno_device *adreno_dev, 301: uint *cmds) 302: { 303: uint *start = cmds; 304: 305: *cmds++ = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 306: return cmds - start; 307: } 308: 309: static inline u32 cp_protected_mode(struct adreno_device *adreno_dev, 310: u32 *cmds, int on) 311: { 312: cmds[0] = cp_packet(adreno_dev, CP_SET_PROTECTED_MODE, 1); 313: cmds[1] = on; 314: 315: return 2; 316: } 317: 318: static inline u32 cp_identifier(struct adreno_device *adreno_dev, 319: u32 *cmds, u32 id) 320: { 321: cmds[0] = cp_packet(adreno_dev, CP_NOP, 1); 322: cmds[1] = id; --- FILE: \adreno_profile.c | HITS: 20 --- MATCH LINES: 72, 77, 85, 91, 106, 119, 121, 123, 125, 127, 129, 135, 138, 141, 152, 162, 180, 183, 191 60: /* Counter data + Pre size + post size = total size */ 61: #define SIZE_SHARED_ENTRY(cnt) (SIZE_DATA(cnt) + SIZE_PREIB(cnt) \ 62: + SIZE_POSTIB(cnt)) 63: 64: /* 65: * Space for following string :"%u %u %u %.5s %u " 66: * [count iterations]: "%.8s:%u %llu %llu%c" 67: */ 68: #define SIZE_PIPE_ENTRY(cnt) (50 + (cnt) * 62) 69: #define SIZE_LOG_ENTRY(cnt) (6 + (cnt) * 5) 70: 71: static inline uint _ib_cmd_mem_write(struct adreno_device *adreno_dev, 72: uint *cmds, uint64_t gpuaddr, uint val, uint *off) 73: { 74: unsigned int *start = cmds; 75: 76: *cmds++ = cp_mem_packet(adreno_dev, CP_MEM_WRITE, 2, 1); 77: cmds += cp_gpuaddr(adreno_dev, cmds, gpuaddr); 78: *cmds++ = val; 79: 80: *off += sizeof(unsigned int); 81: return cmds - start; 82: } 83: 84: static inline uint _ib_cmd_reg_to_mem(struct adreno_device *adreno_dev, 85: uint *cmds, uint64_t gpuaddr, uint val, uint *off) 86: { 87: unsigned int *start = cmds; 88: 89: *cmds++ = cp_mem_packet(adreno_dev, CP_REG_TO_MEM, 2, 1); 90: *cmds++ = val; 91: cmds += cp_gpuaddr(adreno_dev, cmds, gpuaddr); 92: 93: *off += sizeof(unsigned int); 94: return cmds - start; 95: } 96: 97: static u64 _build_pre_ib_cmds(struct adreno_device *adreno_dev, 98: struct adreno_profile *profile, 99: unsigned int head, unsigned int timestamp, 100: struct adreno_context *drawctxt, 101: u32 *dwords) 102: { 103: struct adreno_profile_assigns_list *entry; 104: unsigned int *start, *ibcmds; 105: unsigned int count = profile->assignment_count; 106: uint64_t gpuaddr = profile->shared_buffer->gpuaddr; 107: unsigned int ib_offset = head + SIZE_DATA(count); 108: unsigned int data_offset = head * sizeof(unsigned int); 109: 110: ibcmds = ib_offset + ((unsigned int *) profile->shared_buffer->hostptr); 111: start = ibcmds; 112: 113: ibcmds += cp_identifier(adreno_dev, ibcmds, START_PROFILE_IDENTIFIER); 114: 115: /* 116: * Write ringbuffer commands to save the following to memory: 117: * timestamp, count, context_id, pid, tid, context type 118: */ 119: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 120: timestamp, &data_offset); 121: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 122: profile->assignment_count, &data_offset); 123: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 124: drawctxt->base.id, &data_offset); 125: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 126: pid_nr(drawctxt->base.proc_priv->pid), &data_offset); 127: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 128: drawctxt->base.tid, &data_offset); 129: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, gpuaddr + data_offset, 130: drawctxt->type, &data_offset); 131: 132: /* loop for each countable assigned */ 133: list_for_each_entry(entry, &profile->assignments_list, list) { 134: ibcmds += _ib_cmd_mem_write(adreno_dev, ibcmds, 135: gpuaddr + data_offset, entry->offset, 136: &data_offset); 137: ibcmds += _ib_cmd_reg_to_mem(adreno_dev, ibcmds, 138: gpuaddr + data_offset, entry->offset, 139: &data_offset); 140: ibcmds += _ib_cmd_reg_to_mem(adreno_dev, ibcmds, 141: gpuaddr + data_offset, entry->offset_hi, 142: &data_offset); 143: 144: /* skip over post_ib counter data */ 145: data_offset += sizeof(unsigned int) * 2; 146: } 147: 148: 149: ibcmds += cp_identifier(adreno_dev, ibcmds, END_PROFILE_IDENTIFIER); 150: 151: *dwords = (ibcmds - start); 152: return profile->shared_buffer->gpuaddr + (ib_offset * sizeof(u32)); 153: } 154: 155: static u64 _build_post_ib_cmds(struct adreno_device *adreno_dev, 156: struct adreno_profile *profile, unsigned int head, 157: u32 *dwords) 158: { 159: struct adreno_profile_assigns_list *entry; 160: unsigned int *start, *ibcmds; 161: unsigned int count = profile->assignment_count; 162: uint64_t gpuaddr = profile->shared_buffer->gpuaddr; 163: unsigned int ib_offset = head + SIZE_DATA(count) + SIZE_PREIB(count); 164: unsigned int data_offset = head * sizeof(unsigned int); 165: 166: ibcmds = ib_offset + ((unsigned int *) profile->shared_buffer->hostptr); 167: start = ibcmds; 168: 169: /* start of profile identifier */ 170: ibcmds += cp_identifier(adreno_dev, ibcmds, START_PROFILE_IDENTIFIER); 171: 172: /* skip over pre_ib preamble */ 173: data_offset += sizeof(unsigned int) * 6; 174: 175: /* loop for each countable assigned */ 176: list_for_each_entry(entry, &profile->assignments_list, list) { 177: /* skip over pre_ib counter data */ 178: data_offset += sizeof(unsigned int) * 3; 179: ibcmds += _ib_cmd_reg_to_mem(adreno_dev, ibcmds, 180: gpuaddr + data_offset, entry->offset, 181: &data_offset); 182: ibcmds += _ib_cmd_reg_to_mem(adreno_dev, ibcmds, 183: gpuaddr + data_offset, entry->offset_hi, 184: &data_offset); 185: } 186: 187: /* end of profile identifier */ 188: ibcmds += cp_identifier(adreno_dev, ibcmds, END_PROFILE_IDENTIFIER); 189: 190: *dwords = (ibcmds - start); 191: return profile->shared_buffer->gpuaddr + (ib_offset * sizeof(u32)); 192: } 193: 194: static bool shared_buf_empty(struct adreno_profile *profile) 195: { 196: if (profile->shared_buffer->hostptr == NULL || 197: profile->shared_buffer->size == 0) 198: return true; 199: 200: if (profile->shared_head == profile->shared_tail) 201: return true; 202: 203: return false; 204: } 205: 206: static inline void shared_buf_inc(unsigned int max_size, 207: unsigned int *offset, size_t inc) 208: { 209: *offset = (*offset + inc) % max_size; 210: } 211: 212: static inline void log_buf_wrapcnt(unsigned int cnt, uintptr_t *off) 213: { 214: *off = (*off + cnt) % ADRENO_PROFILE_LOG_BUF_SIZE_DWORDS; 215: } MATCH LINES: 289 277: return true; 278: } 279: 280: return false; 281: } 282: 283: static bool _add_to_assignments_list(struct adreno_profile *profile, 284: const char *str, unsigned int groupid, unsigned int countable, 285: unsigned int offset, unsigned int offset_hi) 286: { 287: struct adreno_profile_assigns_list *entry; 288: 289: /* first make sure we can alloc memory */ 290: entry = kmalloc(sizeof(struct adreno_profile_assigns_list), GFP_KERNEL); 291: if (!entry) 292: return false; 293: 294: list_add_tail(&entry->list, &profile->assignments_list); 295: 296: entry->countable = countable; 297: entry->groupid = groupid; 298: entry->offset = offset; 299: entry->offset_hi = offset_hi; 300: 301: strscpy(entry->name, str, sizeof(entry->name)); 302: 303: profile->assignment_count++; 304: 305: return true; 306: } 307: 308: static bool results_available(struct adreno_device *adreno_dev, 309: struct adreno_profile *profile, unsigned int *shared_buf_tail) 310: { 311: unsigned int global_eop; 312: unsigned int off = profile->shared_tail; 313: unsigned int *shared_ptr; --- FILE: \adreno_profile.h | HITS: 1 --- MATCH LINES: 43 31: unsigned int *log_tail; 32: bool enabled; 33: /* counter, pre_ib, and post_ib held in one large circular buffer 34: * shared between kgsl and GPU 35: * counter entry 0 36: * pre_ib entry 0 37: * post_ib entry 0 38: * ... 39: * counter entry N 40: * pre_ib entry N 41: * post_ib entry N 42: */ 43: struct kgsl_memdesc *shared_buffer; 44: unsigned int shared_head; 45: unsigned int shared_tail; 46: unsigned int shared_size; 47: }; 48: 49: #define ADRENO_PROFILE_SHARED_BUF_SIZE_DWORDS (48 * 4096 / sizeof(uint)) 50: /* sized @ 48 pages should allow for over 50 outstanding IBs minimum, 1755 max*/ 51: 52: #define ADRENO_PROFILE_LOG_BUF_SIZE (1024 * 920) 53: /* sized for 1024 entries of fully assigned 45 cnters in log buffer, 230 pages*/ 54: #define ADRENO_PROFILE_LOG_BUF_SIZE_DWORDS (ADRENO_PROFILE_LOG_BUF_SIZE / \ 55: sizeof(unsigned int)) 56: 57: #ifdef CONFIG_DEBUG_FS 58: void adreno_profile_init(struct adreno_device *adreno_dev); 59: void adreno_profile_close(struct adreno_device *adreno_dev); 60: int adreno_profile_process_results(struct adreno_device *adreno_dev); 61: u64 adreno_profile_preib_processing(struct adreno_device *adreno_dev, 62: struct adreno_context *drawctxt, u32 *dwords); 63: u64 adreno_profile_postib_processing(struct adreno_device *adreno_dev, 64: struct adreno_context *drawctxt, u32 *dwords); 65: #else 66: static inline void adreno_profile_init(struct adreno_device *adreno_dev) { } 67: static inline void adreno_profile_close(struct adreno_device *adreno_dev) { } --- FILE: \adreno_ringbuffer.c | HITS: 4 --- MATCH LINES: 24, 25 12: #include "adreno.h" 13: #include "adreno_pm4types.h" 14: #include "adreno_ringbuffer.h" 15: #include "adreno_trace.h" 16: #include "kgsl_trace.h" 17: #include "kgsl_util.h" 18: 19: 20: #define RB_HOSTPTR(_rb, _pos) \ 21: ((unsigned int *) ((_rb)->buffer_desc->hostptr + \ 22: ((_pos) * sizeof(unsigned int)))) 23: 24: #define RB_GPUADDR(_rb, _pos) \ 25: ((_rb)->buffer_desc->gpuaddr + ((_pos) * sizeof(unsigned int))) 26: 27: void adreno_get_submit_time(struct adreno_device *adreno_dev, 28: struct adreno_ringbuffer *rb, 29: struct adreno_submit_time *time) 30: { 31: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 32: unsigned long flags; 33: struct adreno_context *drawctxt = rb->drawctxt_active; 34: struct kgsl_context *context = &drawctxt->base; 35: 36: if (!time) 37: return; 38: 39: /* 40: * Here we are attempting to create a mapping between the 41: * GPU time domain (alwayson counter) and the CPU time domain 42: * (local_clock) by sampling both values as close together as 43: * possible. This is useful for many types of debugging and 44: * profiling. In order to make this mapping as accurate as 45: * possible, we must turn off interrupts to avoid running 46: * interrupt handlers between the two samples. 47: */ 48: 49: local_irq_save(flags); MATCH LINES: 129, 134 117: { 118: return adreno_rb_readtimestamp(ADRENO_DEVICE(device), priv, type, 119: timestamp); 120: } 121: 122: int adreno_ringbuffer_setup(struct adreno_device *adreno_dev, 123: struct adreno_ringbuffer *rb, int id) 124: { 125: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 126: unsigned int priv = 0; 127: int ret; 128: 129: /* allocate a chunk of memory to create user profiling IB1s */ 130: adreno_allocate_global(device, &rb->profile_desc, PAGE_SIZE, 131: 0, KGSL_MEMFLAGS_GPUREADONLY, 0, "profile_desc"); 132: 133: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 134: priv |= KGSL_MEMDESC_PRIVILEGED; 135: 136: ret = adreno_allocate_global(device, &rb->buffer_desc, KGSL_RB_SIZE, 137: SZ_4K, KGSL_MEMFLAGS_GPUREADONLY, priv, "ringbuffer"); 138: if (ret) 139: return ret; 140: 141: if (!list_empty(&rb->events.group)) 142: return 0; 143: 144: rb->id = id; 145: kgsl_add_event_group(device, &rb->events, NULL, _rb_readtimestamp, rb, 146: "rb_events-%d", id); 147: 148: rb->timestamp = 0; 149: init_waitqueue_head(&rb->ts_expire_waitq); 150: 151: spin_lock_init(&rb->preempt_lock); 152: 153: return 0; 154: } 155: 156: void adreno_preemption_timer(struct timer_list *t) 157: { 158: struct adreno_preemption *preempt = kgsl_timer_container_of(preempt, t, timer); --- FILE: \adreno_ringbuffer.h | HITS: 5 --- MATCH LINES: 97, 106, 107, 108, 120 85: * @ts_expire_waitq: Wait queue to wait for rb timestamp to expire 86: * @ts_expire_waitq: Wait q to wait for rb timestamp to expire 87: * @wptr_preempt_end: Used during preemption to check that preemption occurred 88: * at the right rptr 89: * @gpr11: The gpr11 value of this RB 90: * @preempted_midway: Indicates that the RB was preempted before rptr = wptr 91: * @preempt_lock: Lock to protect the wptr pointer while it is being updated 92: * @skip_inline_wptr: Used during preemption to make sure wptr is updated in 93: * hardware 94: */ 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: */ 142: int adreno_ringbuffer_setup(struct adreno_device *adreno_dev, 143: struct adreno_ringbuffer *rb, int id); 144: --- FILE: \adreno_rpmh.h | HITS: 1 --- MATCH LINES: 83 71: * @votes: Pointer to an array to store the resulting ARC votes 72: * @pri_rail: Pointer to the primary rail ARC values 73: * @sec_rail: Pointer to the secondary rail ARC values 74: * @vlvl: Array of voltage levels corresponding to each frequency corner 75: * @num_entries: Number of entries in the voltage dependency table 76: * 77: * Return: 0 on success or negative error on failure 78: */ 79: int adreno_rpmh_setup_volt_dependency_tbl(u32 *votes, struct rpmh_arc_vals *pri_rail, 80: struct rpmh_arc_vals *sec_rail, u16 *vlvl, u32 num_entries); 81: 82: /** 83: * adreno_rpmh_free_bw_votes - Free memory associated with RPMh bandwidth votes 84: * @votes: Pointer to the rpmh_bw_votes structure 85: */ 86: void adreno_rpmh_free_bw_votes(struct rpmh_bw_votes *votes); 87: 88: /** 89: * adreno_rpmh_build_bw_votes - Build the votes table from the specified 90: * bandwidth levels 91: * @bcms: Array of BCM structures representing BCMs 92: * @bcm_count: Number of BCMs in the array 93: * @levels: Array of performance levels 94: * @levels_count: Number of performance levels 95: * @perfmode_vote: Performance mode vote 96: * @perfmode_lvl: Initial performance level for performance mode vote 97: * @gmu_ab: Indicate if GMU supports AB vote 98: * 99: * Return: Pointer to the rpmh_bw_votes structure on success, or an error pointer failure 100: */ 101: struct rpmh_bw_votes *adreno_rpmh_build_bw_votes(struct bcm *bcms, int bcm_count, 102: u32 *levels, int levels_count, u32 perfmode_vote, u32 perfmode_lvl, bool gmu_ab); 103: 104: /** 105: * adreno_rpmh_to_cx_hlvl - Convert RPMh VLVL to CX HLVL level 106: * @cx_rail: Pointer to the RPMh ARC values for the CX rail 107: * @vlvl: Voltage level to convert --- FILE: \adreno_snapshot.c | HITS: 105 --- MATCH LINES: 44, 49, 60, 67, 68, 69, 71, 72, 88, 91, 98, 100, 101, 103, 106, 112, 122, 127, 159, 160, 162, 165, 166, 173, 187, 191, 194, 200, 209, 215, 217, 222, 226, 238, 247, 253, 255, 260, 264, 292, 296 32: static unsigned int objbufptr; 33: 34: static inline int adreno_rb_ctxtswitch(struct adreno_device *adreno_dev, 35: unsigned int *cmd) 36: { 37: return cmd[0] == cp_packet(adreno_dev, CP_NOP, 1) && 38: cmd[1] == CONTEXT_TO_MEM_IDENTIFIER; 39: } 40: 41: /* Push a new buffer object onto the list */ 42: void kgsl_snapshot_push_object(struct kgsl_device *device, 43: struct kgsl_process_private *process, 44: uint64_t gpuaddr, uint64_t dwords) 45: { 46: int index; 47: struct kgsl_mem_entry *entry; 48: 49: if (process == NULL || gpuaddr == 0) 50: return; 51: 52: /* 53: * Sometimes IBs can be reused in the same dump. Because we parse from 54: * oldest to newest, if we come across an IB that has already been used, 55: * assume that it has been reused and update the list with the newest 56: * size. 57: */ 58: 59: for (index = 0; index < objbufptr; index++) { 60: if (objbuf[index].gpuaddr == gpuaddr && 61: objbuf[index].entry->priv == process) { 62: /* 63: * Check if newly requested size is within the 64: * allocated range or not, otherwise continue 65: * with previous size. 66: */ 67: if (!kgsl_gpuaddr_in_memdesc( 68: &objbuf[index].entry->memdesc, 69: gpuaddr, dwords << 2)) { 70: dev_err(device->dev, 71: "snapshot: gpuaddr 0x%016llX size is less than requested\n", 72: gpuaddr); 73: return; 74: } 75: 76: objbuf[index].size = max_t(uint64_t, 77: objbuf[index].size, 78: dwords << 2); 79: return; 80: } 81: } 82: 83: if (objbufptr == SNAPSHOT_OBJ_BUFSIZE) { 84: dev_err(device->dev, "snapshot: too many snapshot objects\n"); 85: return; 86: } 87: 88: entry = kgsl_sharedmem_find(process, gpuaddr); 89: if (entry == NULL) { 90: dev_err(device->dev, 91: "snapshot: Can't find entry for 0x%016llX\n", gpuaddr); 92: return; 93: } 94: 95: /* 96: * In some gpu fault scenarios incorrect dword size resulting to return 97: * without putting IB addrs into the list. Hence update IB dword size 98: * within memdesc size to have IB dump in snapshot. 99: */ 100: if ((gpuaddr + (dwords << 2)) > (entry->memdesc.gpuaddr + entry->memdesc.size)) 101: dwords = (entry->memdesc.size - (gpuaddr - entry->memdesc.gpuaddr)) >> 2; 102: 103: if (!kgsl_gpuaddr_in_memdesc(&entry->memdesc, gpuaddr, dwords << 2)) { 104: dev_err(device->dev, 105: "snapshot: Mem entry 0x%016llX is too small\n", 106: gpuaddr); 107: kgsl_mem_entry_put(entry); 108: return; 109: } 110: 111: /* Put it on the list of things to parse */ 112: objbuf[objbufptr].gpuaddr = gpuaddr; 113: objbuf[objbufptr].size = dwords << 2; 114: objbuf[objbufptr++].entry = entry; 115: } 116: 117: /* 118: * Returns index of the specified object is already on the list of buffers 119: * to be dumped 120: */ 121: 122: static int find_object(uint64_t gpuaddr, struct kgsl_process_private *process) 123: { 124: int index; 125: 126: for (index = 0; index < objbufptr; index++) { 127: if (objbuf[index].gpuaddr == gpuaddr && 128: objbuf[index].entry->priv == process) 129: return index; 130: } 131: return -ENOENT; 132: } 133: 134: /* 135: * snapshot_freeze_obj_list() - Take a list of ib objects and freeze their 136: * memory for snapshot 137: * @snapshot: The snapshot data. 138: * @process: The process to which the IB belongs 139: * @ib_obj_list: List of the IB objects 140: * 141: * Returns 0 on success else error code 142: */ 143: static int snapshot_freeze_obj_list(struct kgsl_snapshot *snapshot, 144: struct kgsl_process_private *process, 145: struct adreno_ib_object_list *ib_obj_list) 146: { 147: int ret = 0; 148: struct adreno_ib_object *ib_objs; 149: int i; 150: 151: for (i = 0; i < ib_obj_list->num_objs; i++) { 152: int temp_ret; 153: int index; 154: int freeze = 1; 155: 156: ib_objs = &(ib_obj_list->obj_list[i]); 157: /* Make sure this object is not going to be saved statically */ 158: for (index = 0; index < objbufptr; index++) { 159: if ((objbuf[index].gpuaddr <= ib_objs->gpuaddr) && 160: ((objbuf[index].gpuaddr + 161: (objbuf[index].size)) >= 162: (ib_objs->gpuaddr + ib_objs->size)) && 163: (objbuf[index].entry->priv == process)) { 164: freeze = 0; 165: CLEAR_FLAG(KGSL_MEMDESC_SKIP_RECLAIM, 166: &(objbuf[index].entry->memdesc.priv)); 167: break; 168: } 169: } 170: 171: if (freeze) { 172: temp_ret = kgsl_snapshot_get_object(snapshot, 173: process, ib_objs->gpuaddr, 174: ib_objs->size, 175: ib_objs->snapshot_obj_type); 176: if (temp_ret < 0) { 177: if (ret >= 0) 178: ret = temp_ret; 179: } else { 180: snapshot_frozen_objsize += temp_ret; 181: } 182: } 183: } 184: return ret; 185: } 186: 187: static inline bool adreno_ib_addr_overlap(u64 ibaddr, u64 gpuaddr, u64 dwords) 188: { 189: u64 size = dwords << 2; 190: 191: if (size > (U64_MAX - gpuaddr)) 192: return false; 193: 194: return (ibaddr >= gpuaddr && ibaddr < (gpuaddr + size)); 195: } 196: 197: void adreno_parse_ib(struct kgsl_device *device, 198: struct kgsl_snapshot *snapshot, 199: struct kgsl_process_private *process, 200: uint64_t gpuaddr, uint64_t dwords) 201: { 202: struct adreno_ib_object_list *ib_obj_list; 203: 204: /* 205: * Check the IB address - if it is either the last executed IB1 206: * then push it into the static blob otherwise put it in the dynamic 207: * list 208: */ 209: if (adreno_ib_addr_overlap(snapshot->ib1base, gpuaddr, dwords)) { 210: /* 211: * During restore after preemption, ib1base in the register 212: * can be updated by CP. In such scenarios, to dump complete 213: * IB1 in snapshot, we should consider ib1base from ringbuffer. 214: */ 215: snapshot->ib1base = gpuaddr; 216: snapshot->ib1size = dwords; 217: kgsl_snapshot_push_object(device, process, gpuaddr, dwords); 218: return; 219: } 220: 221: if (kgsl_snapshot_have_object(snapshot, process, 222: gpuaddr, dwords << 2)) 223: return; 224: 225: if (-E2BIG == adreno_ib_create_object_list(device, process, 226: gpuaddr, dwords, snapshot->ib2base, 227: &ib_obj_list)) 228: ib_max_objs = 1; 229: 230: if (ib_obj_list) 231: kgsl_snapshot_add_ib_obj_list(snapshot, ib_obj_list); 232: 233: } 234: 235: void adreno_parse_ib_lpac(struct kgsl_device *device, 236: struct kgsl_snapshot *snapshot, 237: struct kgsl_process_private *process, 238: u64 gpuaddr, u64 dwords) 239: { 240: struct adreno_ib_object_list *ib_obj_list; 241: 242: /* 243: * Check the IB address - if it is either the last executed IB1 244: * then push it into the static blob otherwise put it in the dynamic 245: * list 246: */ 247: if (adreno_ib_addr_overlap(snapshot->ib1base_lpac, gpuaddr, dwords)) { 248: /* 249: * During restore after preemption, ib1base in the register 250: * can be updated by CP. In such scenarios, to dump complete 251: * IB1 in snapshot, we should consider ib1base from ringbuffer. 252: */ 253: snapshot->ib1base_lpac = gpuaddr; 254: snapshot->ib1size_lpac = dwords; 255: kgsl_snapshot_push_object(device, process, gpuaddr, dwords); 256: return; 257: } 258: 259: if (kgsl_snapshot_have_object(snapshot, process, 260: gpuaddr, dwords << 2)) 261: return; 262: 263: if (-E2BIG == adreno_ib_create_object_list(device, process, 264: gpuaddr, dwords, snapshot->ib2base_lpac, 265: &ib_obj_list)) 266: ib_max_objs = 1; 267: 268: if (ib_obj_list) 269: kgsl_snapshot_add_ib_obj_list(snapshot, ib_obj_list); 270: 271: } 272: 273: void adreno_snapshot_dump_all_ibs(struct kgsl_device *device, 274: unsigned int *rbptr, struct kgsl_snapshot *snapshot) 275: { 276: int index = 0; 277: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 278: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 279: 280: for (index = 0; index < KGSL_RB_DWORDS;) { 281: 282: if (adreno_cmd_is_ib(adreno_dev, rbptr[index])) { 283: uint64_t ibaddr; 284: uint64_t ibsize; 285: 286: ibaddr = rbptr[(index + 2) % KGSL_RB_DWORDS]; 287: ibaddr = ibaddr << 32 | rbptr[(index + 1) % KGSL_RB_DWORDS]; 288: ibsize = rbptr[(index + 3) % KGSL_RB_DWORDS]; 289: index += 4; 290: 291: /* Don't parse known global IBs */ 292: if (kgsl_gpuaddr_in_memdesc(iommu->setstate, 293: ibaddr, ibsize)) 294: continue; 295: 296: if (kgsl_gpuaddr_in_memdesc(adreno_dev->pwron_fixup, 297: ibaddr, ibsize)) 298: continue; 299: 300: adreno_parse_ib(device, snapshot, snapshot->process, 301: ibaddr, ibsize); 302: } else 303: index = index + 1; 304: } 305: } 306: 307: /** 308: * snapshot_rb_ibs() - Dump rb data and capture the IB's in the RB as well 309: * @device: Pointer to a KGSL device 310: * @rb: The RB to dump 311: * @data: Pointer to memory where the RB data is to be dumped 312: * @snapshot: Pointer to information about the current snapshot being taken 313: */ 314: static void snapshot_rb_ibs(struct kgsl_device *device, 315: struct adreno_ringbuffer *rb, 316: struct kgsl_snapshot *snapshot) 317: { 318: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 319: unsigned int *rbptr, rptr = adreno_get_rptr(rb); 320: int index, i; MATCH LINES: 463, 467 451: if (parse_ibs && adreno_cmd_is_ib(adreno_dev, rbptr[index])) { 452: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 453: uint64_t ibaddr; 454: uint64_t ibsize; 455: 456: ibaddr = rbptr[index + 2]; 457: ibaddr = ibaddr << 32 | rbptr[index + 1]; 458: ibsize = rbptr[index + 3]; 459: 460: index = (index + 1) % KGSL_RB_DWORDS; 461: 462: /* Don't parse known global IBs */ 463: if (kgsl_gpuaddr_in_memdesc(iommu->setstate, 464: ibaddr, ibsize)) 465: continue; 466: 467: if (kgsl_gpuaddr_in_memdesc(adreno_dev->pwron_fixup, 468: ibaddr, ibsize)) 469: continue; 470: 471: adreno_parse_ib(device, snapshot, snapshot->process, 472: ibaddr, ibsize); 473: } else 474: index = (index + 1) % KGSL_RB_DWORDS; 475: } 476: 477: } 478: 479: /* Snapshot the ringbuffer memory */ 480: static size_t snapshot_rb(struct kgsl_device *device, u8 *buf, 481: size_t remain, void *priv) 482: { 483: struct kgsl_snapshot_rb_v2 *header = (struct kgsl_snapshot_rb_v2 *)buf; 484: unsigned int *data = (unsigned int *)(buf + sizeof(*header)); 485: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 486: struct snapshot_rb_params *snap_rb_params = priv; 487: struct kgsl_snapshot *snapshot = snap_rb_params->snapshot; 488: struct adreno_ringbuffer *rb = snap_rb_params->rb; 489: 490: /* 491: * Dump the entire ringbuffer - the parser can choose how much of it to MATCH LINES: 512, 533, 571, 574, 575, 576, 597, 600, 633, 636, 660, 667, 671, 673, 674, 676, 693, 701, 705, 712, 716, 721, 723, 727, 741, 742, 745, 747, 751, 764, 765, 769, 801 500: 501: /* Write the sub-header for the section */ 502: header->start = 0; 503: header->end = KGSL_RB_DWORDS; 504: header->wptr = rb->wptr; 505: header->rptr = adreno_get_rptr(rb); 506: header->rbsize = KGSL_RB_DWORDS; 507: header->count = KGSL_RB_DWORDS; 508: adreno_rb_readtimestamp(adreno_dev, rb, KGSL_TIMESTAMP_QUEUED, 509: &header->timestamp_queued); 510: adreno_rb_readtimestamp(adreno_dev, rb, KGSL_TIMESTAMP_RETIRED, 511: &header->timestamp_retired); 512: header->gpuaddr = rb->buffer_desc->gpuaddr; 513: header->id = rb->id; 514: 515: if (rb == adreno_dev->cur_rb) 516: snapshot_rb_ibs(device, rb, snapshot); 517: 518: /* Just copy the ringbuffer, there are no active IBs */ 519: memcpy(data, rb->buffer_desc->hostptr, KGSL_RB_SIZE); 520: 521: /* Return the size of the section */ 522: return KGSL_RB_SIZE + sizeof(*header); 523: } 524: 525: static int _count_mem_entries(int id, void *ptr, void *data) 526: { 527: int *count = data; 528: *count = *count + 1; 529: return 0; 530: } 531: 532: struct mem_entry { 533: uint64_t gpuaddr; 534: uint64_t size; 535: unsigned int type; 536: } __packed; 537: 538: static size_t snapshot_capture_mem_list(struct kgsl_device *device, 539: u8 *buf, size_t remain, void *priv) 540: { 541: struct kgsl_snapshot_mem_list_v2 *header = 542: (struct kgsl_snapshot_mem_list_v2 *)buf; 543: int id, index = 0, ret = 0, num_mem = 0; 544: struct kgsl_process_private *process = priv; 545: struct mem_entry *m = (struct mem_entry *)(buf + sizeof(*header)); 546: struct kgsl_mem_entry *entry; 547: 548: /* we need a process to search! */ 549: if (process == NULL) 550: return 0; 551: 552: spin_lock(&process->mem_lock); 553: 554: /* We need to know the number of memory objects that the process has */ 555: idr_for_each(&process->mem_idr, _count_mem_entries, &num_mem); 556: 557: if (num_mem == 0) 558: goto out; 559: 560: if (remain < ((num_mem * sizeof(struct mem_entry)) + sizeof(*header))) { 561: dev_err(device->dev, 562: "snapshot: Not enough memory for the mem list\n"); 563: goto out; 564: } 565: 566: header->num_entries = num_mem; 567: header->ptbase = kgsl_mmu_pagetable_get_ttbr0(process->pagetable); 568: 569: /* 570: * Walk through the memory list and store the 571: * tuples(gpuaddr, size, memtype) in snapshot 572: */ 573: idr_for_each_entry(&process->mem_idr, entry, id) { 574: m[index].gpuaddr = entry->memdesc.gpuaddr; 575: m[index].size = entry->memdesc.size; 576: m[index].type = kgsl_memdesc_get_memtype(&entry->memdesc); 577: index++; 578: } 579: 580: ret = sizeof(*header) + (num_mem * sizeof(struct mem_entry)); 581: out: 582: spin_unlock(&process->mem_lock); 583: return ret; 584: } 585: 586: static void kgsl_snapshot_add_active_ib_obj_list(struct kgsl_device *device, 587: struct kgsl_snapshot *snapshot) 588: { 589: struct adreno_ib_object_list *ib_obj_list; 590: int index = -ENOENT; 591: 592: if (!snapshot->ib1dumped) 593: index = find_object(snapshot->ib1base, snapshot->process); 594: 595: /* only do this for IB1 because the IB2's are part of IB1 objects */ 596: if ((index != -ENOENT) && 597: (snapshot->ib1base == objbuf[index].gpuaddr)) { 598: if (-E2BIG == adreno_ib_create_object_list(device, 599: objbuf[index].entry->priv, 600: objbuf[index].gpuaddr, 601: objbuf[index].size >> 2, 602: snapshot->ib2base, 603: &ib_obj_list)) 604: ib_max_objs = 1; 605: if (ib_obj_list) { 606: /* freeze the IB objects in the IB */ 607: snapshot_freeze_obj_list(snapshot, 608: objbuf[index].entry->priv, 609: ib_obj_list); 610: adreno_ib_destroy_obj_list(ib_obj_list); 611: } 612: } else { 613: /* Get the IB2 index from parsed object */ 614: index = find_object(snapshot->ib2base, snapshot->process); 615: 616: if (index != -ENOENT) 617: adreno_parse_ib(device, snapshot, snapshot->process, 618: snapshot->ib2base, objbuf[index].size >> 2); 619: } 620: } 621: 622: static void kgsl_snapshot_add_active_lpac_ib_obj_list(struct kgsl_device *device, 623: struct kgsl_snapshot *snapshot) 624: { 625: struct adreno_ib_object_list *ib_obj_list; 626: int index = -ENOENT; 627: 628: if (!snapshot->ib1dumped_lpac) 629: index = find_object(snapshot->ib1base_lpac, snapshot->process_lpac); 630: 631: /* only do this for IB1 because the IB2's are part of IB1 objects */ 632: if ((index != -ENOENT) && 633: (snapshot->ib1base_lpac == objbuf[index].gpuaddr)) { 634: if (-E2BIG == adreno_ib_create_object_list(device, 635: objbuf[index].entry->priv, 636: objbuf[index].gpuaddr, 637: objbuf[index].size >> 2, 638: snapshot->ib2base_lpac, 639: &ib_obj_list)) 640: ib_max_objs = 1; 641: if (ib_obj_list) { 642: /* freeze the IB objects in the IB */ 643: snapshot_freeze_obj_list(snapshot, 644: objbuf[index].entry->priv, 645: ib_obj_list); 646: adreno_ib_destroy_obj_list(ib_obj_list); 647: } 648: } else { 649: /* Get the IB2 index from parsed object */ 650: index = find_object(snapshot->ib2base_lpac, snapshot->process_lpac); 651: 652: if (index != -ENOENT) 653: adreno_parse_ib_lpac(device, snapshot, snapshot->process_lpac, 654: snapshot->ib2base_lpac, objbuf[index].size >> 2); 655: } 656: } 657: 658: /* 659: * active_ib_is_parsed() - Checks if active ib is already parsed 660: * @gpuaddr: Active IB base address at the time of fault 661: * @size: Active IB size 662: * @process: The process to which the IB belongs 663: * 664: * Function returns true if the active is already is parsed 665: * else false 666: */ 667: static bool active_ib_is_parsed(uint64_t gpuaddr, uint64_t size, 668: struct kgsl_process_private *process) 669: { 670: int index; 671: /* go through the static list for gpuaddr is in list or not */ 672: for (index = 0; index < objbufptr; index++) { 673: if ((objbuf[index].gpuaddr <= gpuaddr) && 674: ((objbuf[index].gpuaddr + 675: (objbuf[index].size)) >= 676: (gpuaddr + size)) && 677: (objbuf[index].entry->priv == process)) 678: return true; 679: } 680: return false; 681: } 682: /* Snapshot the memory for an indirect buffer */ 683: static size_t snapshot_ib(struct kgsl_device *device, u8 *buf, 684: size_t remain, void *priv) 685: { 686: struct kgsl_snapshot_ib_v2 *header = (struct kgsl_snapshot_ib_v2 *)buf; 687: struct snapshot_ib_meta *metadata = priv; 688: unsigned int *src; 689: unsigned int *dst = (unsigned int *)(buf + sizeof(*header)); 690: struct adreno_ib_object_list *ib_obj_list; 691: struct kgsl_snapshot *snapshot; 692: struct kgsl_snapshot_object *obj; 693: struct kgsl_memdesc *memdesc; 694: 695: if (metadata == NULL || metadata->snapshot == NULL || metadata->obj == NULL) { 696: dev_err(device->dev, "snapshot: bad metadata\n"); 697: return 0; 698: } 699: snapshot = metadata->snapshot; 700: obj = metadata->obj; 701: memdesc = &obj->entry->memdesc; 702: 703: /* If size is zero get it from the medesc size */ 704: if (!obj->size) 705: obj->size = (memdesc->size - (obj->gpuaddr - memdesc->gpuaddr)); 706: 707: if (remain < (obj->size + sizeof(*header))) { 708: dev_err(device->dev, "snapshot: Not enough memory for the ib\n"); 709: return 0; 710: } 711: 712: src = kgsl_gpuaddr_to_vaddr(memdesc, obj->gpuaddr); 713: if (src == NULL) { 714: dev_err(device->dev, 715: "snapshot: Unable to map GPU memory object 0x%016llX into the kernel\n", 716: obj->gpuaddr); 717: return 0; 718: } 719: 720: /* only do this for IB1 because the IB2's are part of IB1 objects */ 721: if (metadata->ib1base == obj->gpuaddr) { 722: 723: snapshot->ib1dumped = active_ib_is_parsed(obj->gpuaddr, 724: obj->size, obj->entry->priv); 725: if (-E2BIG == adreno_ib_create_object_list(device, 726: obj->entry->priv, 727: obj->gpuaddr, obj->size >> 2, 728: snapshot->ib2base, 729: &ib_obj_list)) 730: ib_max_objs = 1; 731: if (ib_obj_list) { 732: /* freeze the IB objects in the IB */ 733: snapshot_freeze_obj_list(snapshot, 734: obj->entry->priv, 735: ib_obj_list); 736: adreno_ib_destroy_obj_list(ib_obj_list); 737: } 738: } 739: 740: 741: if (metadata->ib2base == obj->gpuaddr) 742: snapshot->ib2dumped = active_ib_is_parsed(obj->gpuaddr, 743: obj->size, obj->entry->priv); 744: 745: if (metadata->ib1base_lpac == obj->gpuaddr) { 746: 747: snapshot->ib1dumped_lpac = active_ib_is_parsed(obj->gpuaddr, 748: obj->size, obj->entry->priv); 749: if (-E2BIG == adreno_ib_create_object_list(device, 750: obj->entry->priv, 751: obj->gpuaddr, obj->size >> 2, 752: snapshot->ib2base_lpac, 753: &ib_obj_list)) 754: ib_max_objs = 1; 755: if (ib_obj_list) { 756: /* freeze the IB objects in the IB */ 757: snapshot_freeze_obj_list(snapshot, 758: obj->entry->priv, 759: ib_obj_list); 760: adreno_ib_destroy_obj_list(ib_obj_list); 761: } 762: } 763: 764: if (metadata->ib2base_lpac == obj->gpuaddr) 765: snapshot->ib2dumped_lpac = active_ib_is_parsed(obj->gpuaddr, 766: obj->size, obj->entry->priv); 767: 768: /* Write the sub-header for the section */ 769: header->gpuaddr = obj->gpuaddr; 770: header->ptbase = 771: kgsl_mmu_pagetable_get_ttbr0(obj->entry->priv->pagetable); 772: header->size = obj->size >> 2; 773: 774: /* Write the contents of the ib */ 775: memcpy((void *)dst, (void *)src, (size_t) obj->size); 776: /* Write the contents of the ib */ 777: 778: return obj->size + sizeof(*header); 779: } 780: 781: /* Dump another item on the current pending list */ 782: static void dump_object(struct kgsl_device *device, int obj, 783: struct kgsl_snapshot *snapshot) 784: { 785: metadata.snapshot = snapshot; 786: metadata.obj = &objbuf[obj]; 787: metadata.ib1base = snapshot->ib1base; 788: metadata.ib1size = snapshot->ib1size; 789: metadata.ib2base = snapshot->ib2base; 790: metadata.ib2size = snapshot->ib2size; 791: metadata.ib3base = snapshot->ib3base; 792: metadata.ib3size = snapshot->ib3size; 793: metadata.ib1base_lpac = snapshot->ib1base_lpac; 794: metadata.ib1size_lpac = snapshot->ib1size_lpac; 795: metadata.ib2base_lpac = snapshot->ib2base_lpac; 796: metadata.ib2size_lpac = snapshot->ib2size_lpac; 797: 798: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_IB_V2, 799: snapshot, snapshot_ib, &metadata); 800: if (objbuf[obj].entry) { 801: kgsl_memdesc_unmap(&(objbuf[obj].entry->memdesc)); 802: kgsl_mem_entry_put(objbuf[obj].entry); 803: } 804: } 805: 806: /* setup_fault process - Find kgsl_process_private struct that caused the fault 807: * 808: * Find the faulting process based what the dispatcher thinks happened and 809: * what the hardware is using for the current pagetable. The process struct 810: * will be used to look up GPU addresses that are encountered while parsing 811: * the GPU state. 812: */ 813: static struct kgsl_process_private *setup_fault_process(struct kgsl_device *device, 814: struct kgsl_snapshot *snapshot, 815: struct kgsl_context *context) 816: { 817: u64 hw_ptbase, proc_ptbase; 818: struct kgsl_process_private *process = context ? context->proc_priv : NULL; 819: 820: if (process != NULL && !kgsl_process_private_get(process)) 821: process = NULL; 822: 823: /* Get the physical address of the MMU pagetable */ 824: hw_ptbase = kgsl_mmu_get_current_ttbr0(&device->mmu, context); 825: MATCH LINES: 870, 877, 880, 882, 886, 889, 893, 894, 898, 900 858: } 859: } 860: read_unlock(&kgsl_driver.proclist_lock); 861: } 862: done: 863: return process; 864: } 865: 866: /* Snapshot a global memory buffer */ 867: size_t adreno_snapshot_global(struct kgsl_device *device, u8 *buf, 868: size_t remain, void *priv) 869: { 870: struct kgsl_memdesc *memdesc = priv; 871: 872: struct kgsl_snapshot_gpu_object_v2 *header = 873: (struct kgsl_snapshot_gpu_object_v2 *)buf; 874: 875: u8 *ptr = buf + sizeof(*header); 876: 877: if (IS_ERR_OR_NULL(memdesc) || memdesc->size == 0) 878: return 0; 879: 880: if (remain < (memdesc->size + sizeof(*header))) { 881: dev_err(device->dev, 882: "snapshot: Not enough memory for the memdesc\n"); 883: return 0; 884: } 885: 886: if (memdesc->hostptr == NULL) { 887: dev_err(device->dev, 888: "snapshot: no kernel mapping for global object 0x%016llX\n", 889: memdesc->gpuaddr); 890: return 0; 891: } 892: 893: header->size = memdesc->size >> 2; 894: header->gpuaddr = memdesc->gpuaddr; 895: header->ptbase = MMU_DEFAULT_TTBR0(device); 896: header->type = SNAPSHOT_GPU_OBJECT_GLOBAL; 897: 898: memcpy(ptr, memdesc->hostptr, memdesc->size); 899: 900: return memdesc->size + sizeof(*header); 901: } 902: 903: /* Snapshot IOMMU specific buffers */ 904: static void adreno_snapshot_iommu(struct kgsl_device *device, 905: struct kgsl_snapshot *snapshot) 906: { 907: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 908: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 909: 910: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 911: snapshot, adreno_snapshot_global, iommu->setstate); 912: 913: if (adreno_is_preemption_enabled(adreno_dev)) 914: kgsl_snapshot_add_section(device, 915: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 916: snapshot, adreno_snapshot_global, iommu->smmu_info); 917: } 918: 919: static void adreno_snapshot_ringbuffer(struct kgsl_device *device, 920: struct kgsl_snapshot *snapshot, struct adreno_ringbuffer *rb) 921: { 922: struct snapshot_rb_params params = { 923: .snapshot = snapshot, 924: .rb = rb, MATCH LINES: 1035, 1044, 1050, 1051 1023: { 1024: if (process == NULL) 1025: return; 1026: 1027: /* Make sure that the last IB1 that was being executed is dumped. 1028: * Since this was the last IB1 that was processed, we should have 1029: * already added it to the list during the ringbuffer parse but we 1030: * want to be double plus sure. 1031: * The problem is that IB size from the register is the unprocessed size 1032: * of the buffer not the original size, so if we didn't catch this 1033: * buffer being directly used in the RB, then we might not be able to 1034: * dump the whole thing. Try to dump the maximum possible size from the 1035: * IB1 base address till the end of memdesc size so that we dont miss 1036: * what we are interested in. Print a warning message so we can try to 1037: * figure how often this really happens. 1038: */ 1039: 1040: if (ib1base && (-ENOENT == find_object(ib1base, process))) { 1041: struct kgsl_mem_entry *entry; 1042: u64 ibsize; 1043: 1044: entry = kgsl_sharedmem_find(process, ib1base); 1045: if (entry == NULL) { 1046: dev_err(device->dev, 1047: "Can't find a memory entry containing IB1BASE %16llx\n", 1048: ib1base); 1049: } else { 1050: ibsize = entry->memdesc.size - 1051: (ib1base - entry->memdesc.gpuaddr); 1052: kgsl_mem_entry_put(entry); 1053: 1054: kgsl_snapshot_push_object(device, process, 1055: ib1base, ibsize >> 2); 1056: dev_err(device->dev, 1057: "CP_IB1_BASE %16llx is not found in the ringbuffer. Dumping %llx dwords of the buffer\n", 1058: ib1base, ibsize >> 2); 1059: } 1060: } 1061: 1062: /* 1063: * Add the last parsed IB2 and IB3 to the list. These should be found as we 1064: * parse the objects below, but we try to add them to the list first, so 1065: * they too can be parsed. Don't print an error message in this case - if 1066: * the IB2 and IB3 are found during parsing, the list will be updated with 1067: * the correct size. 1068: */ 1069: if (ib2base && (-ENOENT == find_object(ib2base, process))) 1070: kgsl_snapshot_push_object(device, process, ib2base, ib2size); 1071: 1072: if (ib3base && (-ENOENT == find_object(ib3base, process))) 1073: kgsl_snapshot_push_object(device, process, ib3base, ib3size); 1074: } 1075: MATCH LINES: 1101, 1120, 1131 1089: struct kgsl_snapshot_debug *header = (struct kgsl_snapshot_debug *)buf; 1090: void *data = buf + sizeof(*header); 1091: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE); 1092: 1093: if (remain < DEBUG_SECTION_SZ(SQE_FW_SNAPSHOT_DWORDS)) { 1094: SNAPSHOT_ERR_NOMEM(device, "SQE VERSION DEBUG"); 1095: return 0; 1096: } 1097: 1098: /* Dump the SQE firmware version and few dwords */ 1099: header->type = SNAPSHOT_DEBUG_SQE_VERSION; 1100: header->size = SQE_FW_SNAPSHOT_DWORDS; 1101: memcpy(data, fw->memdesc->hostptr, (SQE_FW_SNAPSHOT_DWORDS * sizeof(u32))); 1102: 1103: return DEBUG_SECTION_SZ(SQE_FW_SNAPSHOT_DWORDS); 1104: } 1105: 1106: /* adreno_snapshot_aqe() - Dump AQE data in snapshot */ 1107: static size_t adreno_snapshot_aqe(struct kgsl_device *device, u8 *buf, 1108: size_t remain, void *priv) 1109: { 1110: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1111: struct kgsl_snapshot_debug *header = (struct kgsl_snapshot_debug *)buf; 1112: u32 *data = (u32 *)(buf + sizeof(*header)); 1113: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_AQE); 1114: 1115: /* 1116: * AQE firmware memory is allocated in the hwsched path. 1117: * In swsched path, the address is NULL, so add a check 1118: * to avoid NULL pointer dereference. 1119: */ 1120: if ((!ADRENO_FEATURE(adreno_dev, ADRENO_AQE)) || (fw->memdesc == NULL)) 1121: return 0; 1122: 1123: if (remain < DEBUG_SECTION_SZ(AQE_FW_SNAPSHOT_DWORDS)) { 1124: SNAPSHOT_ERR_NOMEM(device, "AQE VERSION DEBUG"); 1125: return 0; 1126: } 1127: 1128: /* Dump the AQE firmware version and few dwords */ 1129: header->type = SNAPSHOT_DEBUG_AQE_VERSION; 1130: header->size = AQE_FW_SNAPSHOT_DWORDS; 1131: memcpy(data, fw->memdesc->hostptr, AQE_FW_SNAPSHOT_DWORDS * sizeof(u32)); 1132: 1133: return DEBUG_SECTION_SZ(AQE_FW_SNAPSHOT_DWORDS); 1134: } 1135: 1136: static void adreno_snapshot_firmware(struct kgsl_device *device, 1137: struct kgsl_snapshot *snapshot) 1138: { 1139: 1140: /* Dump SQE firmware version and few dwords */ 1141: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, 1142: snapshot, adreno_snapshot_sqe, NULL); 1143: 1144: /* Dump AQE firmware version */ 1145: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, 1146: snapshot, adreno_snapshot_aqe, NULL); 1147: } 1148: 1149: /* adreno_snapshot - Snapshot the Adreno GPU state 1150: * @device - KGSL device to snapshot 1151: * @snapshot - Pointer to the snapshot instance 1152: * @context - context that caused the fault, if known by the driver 1153: * This is a hook function called by kgsl_snapshot to snapshot the 1154: * Adreno specific information for the GPU snapshot. In turn, this function 1155: * calls the GPU specific snapshot function to get core specific information. MATCH LINES: 1235 1223: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 1224: snapshot, adreno_snapshot_global, 1225: adreno_dev->pwron_fixup); 1226: 1227: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 1228: snapshot, adreno_snapshot_global, 1229: adreno_dev->profile_buffer); 1230: 1231: if (kgsl_mmu_get_mmutype(device) == KGSL_MMU_TYPE_IOMMU) 1232: adreno_snapshot_iommu(device, snapshot); 1233: 1234: /* 1235: * Add a section that lists (gpuaddr, size, memtype) tuples of the 1236: * hanging process 1237: */ 1238: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_MEMLIST_V2, 1239: snapshot, snapshot_capture_mem_list, snapshot->process); 1240: 1241: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_MEMLIST_V2, 1242: snapshot, snapshot_capture_mem_list, snapshot->process_lpac); 1243: 1244: adreno_static_ib_dump(device, snapshot->process, 1245: snapshot->ib1base, snapshot->ib1size, snapshot->ib2base, snapshot->ib2size, 1246: snapshot->ib3base, snapshot->ib3size); 1247: 1248: adreno_static_ib_dump(device, snapshot->process_lpac, 1249: snapshot->ib1base_lpac, snapshot->ib1size_lpac, 1250: snapshot->ib2base_lpac, snapshot->ib2size_lpac, 0, 0); 1251: /* 1252: * Go through the list of found objects and dump each one. As the IBs 1253: * are parsed, more objects might be found, and objbufptr will increase 1254: */ 1255: for (i = 0; i < objbufptr; i++) 1256: dump_object(device, i, snapshot); 1257: 1258: /* 1259: * Incase snapshot static blob is running out of memory, Add Active IB1 MATCH LINES: 1401, 1404, 1413, 1414, 1418, 1420, 1422, 1429, 1433, 1441, 1446 1389: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, 1390: snapshot, snapshot_gmu_version, &gmu_vers[i]); 1391: } 1392: 1393: size_t adreno_snapshot_gmu_mem(struct kgsl_device *device, 1394: u8 *buf, size_t remain, void *priv) 1395: { 1396: struct kgsl_snapshot_gmu_mem *mem_hdr = 1397: (struct kgsl_snapshot_gmu_mem *)buf; 1398: void *data = buf + sizeof(*mem_hdr); 1399: struct gmu_mem_type_desc *desc = priv; 1400: 1401: if (priv == NULL || desc->memdesc->hostptr == NULL) 1402: return 0; 1403: 1404: if (remain < desc->memdesc->size + sizeof(*mem_hdr)) { 1405: dev_err(device->dev, 1406: "snapshot: Not enough memory for the gmu section %d\n", 1407: desc->type); 1408: return 0; 1409: } 1410: 1411: mem_hdr->type = desc->type; 1412: mem_hdr->hostaddr = 0; 1413: mem_hdr->gmuaddr = desc->memdesc->gmuaddr; 1414: mem_hdr->gpuaddr = 0; 1415: 1416: /* The hw fence queues are mapped as iomem in the kernel */ 1417: if (desc->type == SNAPSHOT_GMU_MEM_HW_FENCE) 1418: memcpy_fromio(data, desc->memdesc->hostptr, desc->memdesc->size); 1419: else 1420: memcpy(data, desc->memdesc->hostptr, desc->memdesc->size); 1421: 1422: return desc->memdesc->size + sizeof(*mem_hdr); 1423: } 1424: 1425: /* Snapshot the preemption related buffers */ 1426: static size_t snapshot_preemption_record(struct kgsl_device *device, 1427: u8 *buf, size_t remain, void *priv) 1428: { 1429: struct kgsl_memdesc *memdesc = priv; 1430: struct kgsl_snapshot_gpu_object_v2 *header = 1431: (struct kgsl_snapshot_gpu_object_v2 *)buf; 1432: u8 *ptr = buf + sizeof(*header); 1433: u64 ctxt_record_size = min_t(u64, device->snapshot_ctxt_record_size, memdesc->size); 1434: 1435: if (remain < (ctxt_record_size + sizeof(*header))) { 1436: SNAPSHOT_ERR_NOMEM(device, "PREEMPTION RECORD"); 1437: return 0; 1438: } 1439: 1440: header->size = ctxt_record_size >> 2; 1441: header->gpuaddr = memdesc->gpuaddr; 1442: header->ptbase = 1443: kgsl_mmu_pagetable_get_ttbr0(device->mmu.defaultpagetable); 1444: header->type = SNAPSHOT_GPU_OBJECT_GLOBAL; 1445: 1446: memcpy(ptr, memdesc->hostptr, ctxt_record_size); 1447: 1448: return ctxt_record_size + sizeof(*header); 1449: } 1450: 1451: void adreno_snapshot_preemption_record(struct kgsl_device *device, 1452: struct kgsl_snapshot *snapshot) 1453: { 1454: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 1455: struct adreno_ringbuffer *rb; 1456: u32 i; 1457: 1458: if (adreno_is_preemption_enabled(adreno_dev)) { 1459: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 1460: kgsl_snapshot_add_section(device, 1461: KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2, 1462: snapshot, snapshot_preemption_record, 1463: rb->preemption_desc); 1464: } 1465: } 1466: } --- FILE: \adreno_snapshot.h | HITS: 4 --- MATCH LINES: 99, 110, 117, 128 87: * This function dumps the CX_MISC registers in a way that we need to 88: * only dump the start address and count for each pair of register 89: * in the array. This helps us save some memory in snapshot. 90: */ 91: size_t adreno_snapshot_cx_misc_registers(struct kgsl_device *device, 92: u8 *buf, size_t remain, void *priv); 93: 94: /** 95: * adreno_parse_ib - Parse the given IB 96: * @device: Pointer to the kgsl device 97: * @snapshot: Pointer to the snapshot structure 98: * @process: Process to which this IB belongs 99: * @gpuaddr: Gpu address of the IB 100: * @dwords: Size in dwords of the IB 101: * 102: * We want to store the last executed IB1 and IB2 in the static region to ensure 103: * that we get at least some information out of the snapshot even if we can't 104: * access the dynamic data from the sysfs file. Push all other IBs on the 105: * dynamic list 106: */ 107: void adreno_parse_ib(struct kgsl_device *device, 108: struct kgsl_snapshot *snapshot, 109: struct kgsl_process_private *process, 110: u64 gpuaddr, u64 dwords); 111: 112: /** 113: * adreno_parse_ib_lpac - Parse the given LPAC IB 114: * @device: Pointer to the kgsl device 115: * @snapshot: Pointer to the snapshot structure 116: * @process: Process to which this LPAC IB belongs 117: * @gpuaddr: Gpu address of the LPAC IB 118: * @dwords: Size in dwords of the LPAC IB 119: * 120: * We want to store the last executed LPAC IB1 and IB2 in the static region to ensure 121: * that we get at least some information out of the snapshot even if we can't 122: * access the dynamic data from the sysfs file. Push all other IBs on the 123: * dynamic list 124: */ 125: void adreno_parse_ib_lpac(struct kgsl_device *device, 126: struct kgsl_snapshot *snapshot, 127: struct kgsl_process_private *process, 128: u64 gpuaddr, u64 dwords); 129: 130: /** 131: * adreno_snapshot_global - Add global buffer to snapshot 132: * @device: Pointer to the kgsl device 133: * @buf: Where the global buffer section is to be written 134: * @remain: Remaining bytes in snapshot buffer 135: * @priv: Opaque data 136: * 137: * Return: Number of bytes written to the snapshot buffer 138: */ 139: size_t adreno_snapshot_global(struct kgsl_device *device, u8 *buf, 140: size_t remain, void *priv); 141: 142: /** 143: * adreno_snapshot_dump_all_ibs - To dump all ibs from ringbuffer 144: * @device: Pointer to the kgsl device 145: * @rbptr: Ringbuffer host pointer 146: * @snapshot: Pointer to the snapshot structure 147: * 148: * Parse all IBs from the ringbuffer and add to IB dump list. 149: */ 150: void adreno_snapshot_dump_all_ibs(struct kgsl_device *device, 151: unsigned int *rbptr, 152: struct kgsl_snapshot *snapshot); --- FILE: \adreno_trace.h | HITS: 6 --- MATCH LINES: 818, 819 806: __field(unsigned int, new_rptr) 807: __field(unsigned int, cur_wptr) 808: __field(unsigned int, new_wptr) 809: __field(unsigned int, cur_rbbase) 810: __field(unsigned int, new_rbbase) 811: ), 812: TP_fast_assign(__entry->cur_level = cur_rb->id; 813: __entry->new_level = new_rb->id; 814: __entry->cur_rptr = cur_rptr; 815: __entry->new_rptr = new_rptr; 816: __entry->cur_wptr = cur_rb->wptr; 817: __entry->new_wptr = new_rb->wptr; 818: __entry->cur_rbbase = cur_rb->buffer_desc->gpuaddr; 819: __entry->new_rbbase = new_rb->buffer_desc->gpuaddr; 820: ), 821: TP_printk( 822: "cur_rb_lvl=%d rptr=%x wptr=%x rbbase=%x new_rb_lvl=%d rptr=%x wptr=%x rbbase=%x", 823: __entry->cur_level, __entry->cur_rptr, 824: __entry->cur_wptr, __entry->cur_rbbase, 825: __entry->new_level, __entry->new_rptr, 826: __entry->new_wptr, __entry->new_rbbase 827: ) 828: ); 829: 830: DEFINE_EVENT(adreno_hw_preempt_template, adreno_hw_preempt_clear_to_trig, 831: TP_PROTO(struct adreno_ringbuffer *cur_rb, 832: struct adreno_ringbuffer *new_rb, 833: unsigned int cur_rptr, unsigned int new_rptr), 834: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr) 835: ); 836: 837: DEFINE_EVENT(adreno_hw_preempt_template, adreno_hw_preempt_trig_to_comp, 838: TP_PROTO(struct adreno_ringbuffer *cur_rb, 839: struct adreno_ringbuffer *new_rb, 840: unsigned int cur_rptr, unsigned int new_rptr), 841: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr) 842: ); 843: MATCH LINES: 873, 874, 907, 908 861: __field(unsigned int, new_wptr_end) 862: __field(unsigned int, new_wptr) 863: __field(unsigned int, cur_rbbase) 864: __field(unsigned int, new_rbbase) 865: ), 866: TP_fast_assign(__entry->cur_level = cur_rb->id; 867: __entry->new_level = new_rb->id; 868: __entry->cur_rptr = cur_rptr; 869: __entry->new_rptr = new_rptr; 870: __entry->cur_wptr = cur_rb->wptr; 871: __entry->new_wptr_end = new_rb->wptr_preempt_end; 872: __entry->new_wptr = new_rb->wptr; 873: __entry->cur_rbbase = cur_rb->buffer_desc->gpuaddr; 874: __entry->new_rbbase = new_rb->buffer_desc->gpuaddr; 875: ), 876: TP_printk( 877: "cur_rb_lvl=%d rptr=%x wptr=%x rbbase=%x prev_rb_lvl=%d rptr=%x wptr_preempt_end=%x wptr=%x rbbase=%x", 878: __entry->cur_level, __entry->cur_rptr, 879: __entry->cur_wptr, __entry->cur_rbbase, 880: __entry->new_level, __entry->new_rptr, 881: __entry->new_wptr_end, __entry->new_wptr, __entry->new_rbbase 882: ) 883: ); 884: 885: TRACE_EVENT(adreno_hw_preempt_token_submit, 886: TP_PROTO(struct adreno_ringbuffer *cur_rb, 887: struct adreno_ringbuffer *new_rb, 888: unsigned int cur_rptr, unsigned int new_rptr), 889: TP_ARGS(cur_rb, new_rb, cur_rptr, new_rptr), 890: TP_STRUCT__entry(__field(int, cur_level) 891: __field(int, new_level) 892: __field(unsigned int, cur_rptr) 893: __field(unsigned int, new_rptr) 894: __field(unsigned int, cur_wptr) 895: __field(unsigned int, cur_wptr_end) 896: __field(unsigned int, new_wptr) 897: __field(unsigned int, cur_rbbase) 898: __field(unsigned int, new_rbbase) 899: ), 900: TP_fast_assign(__entry->cur_level = cur_rb->id; 901: __entry->new_level = new_rb->id; 902: __entry->cur_rptr = cur_rptr; 903: __entry->new_rptr = new_rptr; 904: __entry->cur_wptr = cur_rb->wptr; 905: __entry->cur_wptr_end = cur_rb->wptr_preempt_end; 906: __entry->new_wptr = new_rb->wptr; 907: __entry->cur_rbbase = cur_rb->buffer_desc->gpuaddr; 908: __entry->new_rbbase = new_rb->buffer_desc->gpuaddr; 909: ), 910: TP_printk( 911: "cur_rb_lvl=%d rptr=%x wptr_preempt_end=%x wptr=%x rbbase=%x new_rb_lvl=%d rptr=%x wptr=%x rbbase=%x", 912: __entry->cur_level, __entry->cur_rptr, 913: __entry->cur_wptr_end, __entry->cur_wptr, 914: __entry->cur_rbbase, 915: __entry->new_level, __entry->new_rptr, 916: __entry->new_wptr, __entry->new_rbbase 917: ) 918: ); 919: 920: TRACE_EVENT(adreno_preempt_trigger, 921: TP_PROTO(u32 cur_rb_id, u32 next_rb_id, 922: u32 cntl, u64 gmu_ticks), 923: TP_ARGS(cur_rb_id, next_rb_id, cntl, gmu_ticks), 924: TP_STRUCT__entry( 925: __field(u32, cur) 926: __field(u32, next) 927: __field(u32, cntl) 928: __field(u64, ticks) 929: ), 930: TP_fast_assign( 931: __entry->cur = cur_rb_id; 932: __entry->next = next_rb_id; --- FILE: \governor_msm_adreno_tz.c | HITS: 8 --- MATCH LINES: 264, 268, 280, 290, 295, 311, 313, 314 252: 253: memset(&pool_config, 0, sizeof(pool_config)); 254: pool_config.initial_size = PAGE_ALIGN(size_pwrlevels); 255: pool_config.policy = QCOM_TZMEM_POLICY_STATIC; 256: pool_config.max_size = PAGE_ALIGN(size_pwrlevels); 257: 258: tzmem_pool = qcom_tzmem_pool_new(&pool_config); 259: if (IS_ERR(tzmem_pool)) { 260: pr_err(TAG "tz: Failed to create qcom_tzmem_pool %pe\n", tzmem_pool); 261: return PTR_ERR(tzmem_pool); 262: } 263: 264: void *tzmem = qcom_tzmem_alloc(tzmem_pool, 265: PAGE_ALIGN(size_pwrlevels), GFP_KERNEL); 266: if (!tzmem) { 267: ret = -ENOMEM; 268: goto free_tzmem; 269: } 270: 271: paddr = qcom_tzmem_to_phys(tzmem); 272: 273: memcpy(tzmem, tz_pwrlevels, size_pwrlevels); 274: /* Ensure memcpy completes execution */ 275: mb(); 276: 277: ret = qcom_scm_dcvs_init_v2(paddr, size_pwrlevels, version); 278: 279: if (ret) 280: goto free_tzmem; 281: 282: priv->is_64 = true; 283: 284: /* 285: * Initialize context aware feature, if enabled. If context 286: * aware initialization fails, just print an error message 287: * and return success as normal DCVS will still work. 288: */ 289: if (!priv->ctxt_aware_enable) 290: goto free_tzmem; 291: 292: if (!qcom_scm_dcvs_ca_available()) { 293: pr_warn(TAG "tz: context aware DCVS not supported\n"); 294: priv->ctxt_aware_enable = false; 295: goto free_tzmem; 296: } 297: 298: ((unsigned int*)tzmem)[0] = priv->bin.ctxt_aware_target_pwrlevel; 299: ((unsigned int*)tzmem)[1] = priv->bin.ctxt_aware_busy_penalty; 300: /* Ensure writes are completed */ 301: mb(); 302: 303: ret = qcom_scm_dcvs_init_ca_v2(paddr, 2 * sizeof(unsigned int)); 304: 305: if (ret) { 306: pr_err(TAG "tz: context aware DCVS init failed %d\n", ret); 307: priv->ctxt_aware_enable = false; 308: ret = 0; 309: } 310: 311: free_tzmem: 312: if (tzmem) 313: qcom_tzmem_free(tzmem); 314: qcom_tzmem_pool_free(tzmem_pool); 315: 316: return ret; 317: } 318: 319: #else 320: static int tz_init_ca(struct device *dev, 321: struct devfreq_msm_adreno_tz_data *priv) 322: { 323: unsigned int tz_ca_data[2]; 324: phys_addr_t paddr; 325: u8 *tz_buf; 326: int ret; 327: struct qtee_shm shm; 328: 329: /* Set data for TZ */ 330: tz_ca_data[0] = priv->bin.ctxt_aware_target_pwrlevel; 331: tz_ca_data[1] = priv->bin.ctxt_aware_busy_penalty; 332: 333: if (!qtee_shmbridge_is_enabled()) { 334: tz_buf = kzalloc(PAGE_ALIGN(sizeof(tz_ca_data)), GFP_KERNEL); 335: if (!tz_buf) 336: return -ENOMEM; 337: paddr = virt_to_phys(tz_buf); 338: } else { --- FILE: \kgsl.c | HITS: 298 --- MATCH LINES: 85, 89, 123, 134, 146, 147, 151, 152, 154, 170, 172, 173, 193, 204, 209, 210, 212, 213, 214, 215, 217, 218, 226, 237, 241, 245, 247, 248 73: struct list_head dmabuf_list; 74: }; 75: 76: struct kgsl_dma_buf_meta { 77: struct kgsl_mem_entry *entry; 78: struct dma_buf_attachment *attach; 79: struct dma_buf *dmabuf; 80: struct sg_table *table; 81: struct dmabuf_list_entry *dle; 82: struct list_head node; 83: }; 84: 85: static inline struct kgsl_pagetable *_get_memdesc_pagetable( 86: struct kgsl_pagetable *pt, struct kgsl_mem_entry *entry) 87: { 88: /* if a secured buffer, map it to secure global pagetable */ 89: if (kgsl_memdesc_is_secured(&entry->memdesc)) 90: return pt->mmu->securepagetable; 91: 92: return pt; 93: } 94: 95: static void kgsl_mem_entry_detach_process(struct kgsl_mem_entry *entry); 96: 97: static const struct vm_operations_struct kgsl_gpumem_vm_ops; 98: 99: #if (KERNEL_VERSION(6, 10, 0) > LINUX_VERSION_CODE) 100: static unsigned long kgsl_mm_get_unmapped_area(struct mm_struct *mm, struct file *file, 101: unsigned long addr, unsigned long len, 102: unsigned long pgoff, unsigned long flags) 103: { 104: return mm->get_unmapped_area(file, addr, len, pgoff, flags); 105: } 106: #elif (KERNEL_VERSION(6, 19, 0) > LINUX_VERSION_CODE) 107: static unsigned long kgsl_mm_get_unmapped_area(struct mm_struct *mm, struct file *file, 108: unsigned long addr, unsigned long len, 109: unsigned long pgoff, unsigned long flags) 110: { 111: return mm_get_unmapped_area(mm, file, addr, len, pgoff, flags); 112: } 113: #else 114: static unsigned long kgsl_mm_get_unmapped_area(struct mm_struct *mm, struct file *file, 115: unsigned long addr, unsigned long len, 116: unsigned long pgoff, unsigned long flags) 117: { 118: return mm_get_unmapped_area(file, addr, len, pgoff, flags); 119: } 120: #endif 121: 122: /* 123: * The memfree list contains the last N blocks of memory that have been freed. 124: * On a GPU fault we walk the list to see if the faulting address had been 125: * recently freed and print out a message to that effect 126: */ 127: 128: #define MEMFREE_ENTRIES 512 129: 130: static DEFINE_SPINLOCK(memfree_lock); 131: 132: struct memfree_entry { 133: pid_t ptname; 134: uint64_t gpuaddr; 135: uint64_t size; 136: pid_t pid; 137: uint64_t flags; 138: }; 139: 140: static struct { 141: struct memfree_entry *list; 142: int head; 143: int tail; 144: } memfree; 145: 146: static inline bool match_memfree_addr(struct memfree_entry *entry, 147: pid_t ptname, uint64_t gpuaddr) 148: { 149: return ((entry->ptname == ptname) && 150: (entry->size > 0) && 151: (gpuaddr >= entry->gpuaddr && 152: gpuaddr < (entry->gpuaddr + entry->size))); 153: } 154: int kgsl_memfree_find_entry(pid_t ptname, uint64_t *gpuaddr, 155: uint64_t *size, uint64_t *flags, pid_t *pid) 156: { 157: int ptr; 158: 159: if (memfree.list == NULL) 160: return 0; 161: 162: spin_lock(&memfree_lock); 163: 164: ptr = memfree.head - 1; 165: if (ptr < 0) 166: ptr = MEMFREE_ENTRIES - 1; 167: 168: /* Walk backwards through the list looking for the last match */ 169: while (ptr != memfree.tail) { 170: struct memfree_entry *entry = &memfree.list[ptr]; 171: 172: if (match_memfree_addr(entry, ptname, *gpuaddr)) { 173: *gpuaddr = entry->gpuaddr; 174: *flags = entry->flags; 175: *size = entry->size; 176: *pid = entry->pid; 177: 178: spin_unlock(&memfree_lock); 179: return 1; 180: } 181: 182: ptr = ptr - 1; 183: 184: if (ptr < 0) 185: ptr = MEMFREE_ENTRIES - 1; 186: } 187: 188: spin_unlock(&memfree_lock); 189: return 0; 190: } 191: 192: static void kgsl_memfree_purge(struct kgsl_pagetable *pagetable, 193: uint64_t gpuaddr, uint64_t size) 194: { 195: pid_t ptname = pagetable ? pagetable->name : 0; 196: int i; 197: 198: if (memfree.list == NULL) 199: return; 200: 201: spin_lock(&memfree_lock); 202: 203: for (i = 0; i < MEMFREE_ENTRIES; i++) { 204: struct memfree_entry *entry = &memfree.list[i]; 205: 206: if (entry->ptname != ptname || entry->size == 0) 207: continue; 208: 209: if (gpuaddr > entry->gpuaddr && 210: gpuaddr < entry->gpuaddr + entry->size) { 211: /* truncate the end of the entry */ 212: entry->size = gpuaddr - entry->gpuaddr; 213: } else if (gpuaddr <= entry->gpuaddr) { 214: if (gpuaddr + size > entry->gpuaddr && 215: gpuaddr + size < entry->gpuaddr + entry->size) 216: /* Truncate the beginning of the entry */ 217: entry->gpuaddr = gpuaddr + size; 218: else if (gpuaddr + size >= entry->gpuaddr + entry->size) 219: /* Remove the entire entry */ 220: entry->size = 0; 221: } 222: } 223: spin_unlock(&memfree_lock); 224: } 225: 226: static void kgsl_memfree_add(pid_t pid, pid_t ptname, uint64_t gpuaddr, 227: uint64_t size, uint64_t flags) 228: 229: { 230: struct memfree_entry *entry; 231: 232: if (memfree.list == NULL) 233: return; 234: 235: spin_lock(&memfree_lock); 236: 237: entry = &memfree.list[memfree.head]; 238: 239: entry->pid = pid; 240: entry->ptname = ptname; 241: entry->gpuaddr = gpuaddr; 242: entry->size = size; 243: entry->flags = flags; 244: 245: memfree.head = (memfree.head + 1) % MEMFREE_ENTRIES; 246: 247: if (memfree.head == memfree.tail) 248: memfree.tail = (memfree.tail + 1) % MEMFREE_ENTRIES; 249: 250: spin_unlock(&memfree_lock); 251: } 252: 253: int kgsl_readtimestamp(struct kgsl_device *device, void *priv, 254: enum kgsl_timestamp_type type, unsigned int *timestamp) 255: { 256: if (device) 257: return device->ftbl->readtimestamp(device, priv, type, 258: timestamp); 259: return -EINVAL; 260: 261: } 262: 263: const char *kgsl_context_type(int type) 264: { 265: if (type == KGSL_CONTEXT_TYPE_GL) 266: return "GL"; 267: else if (type == KGSL_CONTEXT_TYPE_CL) 268: return "CL"; 269: else if (type == KGSL_CONTEXT_TYPE_C2D) 270: return "C2D"; 271: else if (type == KGSL_CONTEXT_TYPE_RS) 272: return "RS"; MATCH LINES: 329, 348, 354, 356, 357, 360, 366, 369, 376, 380, 382, 386, 392, 395, 403, 408, 414, 415, 416, 431, 434, 436, 438, 439, 445, 448 317: } 318: } 319: 320: /* This is a new buffer. Add a new entry for it */ 321: dle = kzalloc(sizeof(*dle), GFP_ATOMIC); 322: if (dle) { 323: dle->firstpage = page; 324: INIT_LIST_HEAD(&dle->dmabuf_list); 325: list_add(&dle->node, &kgsl_dmabuf_list); 326: metadata->dle = dle; 327: list_add(&metadata->node, &dle->dmabuf_list); 328: kgsl_trace_gpu_mem_total(device, 329: metadata->entry->memdesc.size); 330: } 331: spin_unlock(&kgsl_dmabuf_lock); 332: } 333: 334: static void remove_dmabuf_list(struct kgsl_dma_buf_meta *metadata) 335: { 336: struct kgsl_device *device = dev_get_drvdata(metadata->attach->dev); 337: struct dmabuf_list_entry *dle = metadata->dle; 338: 339: if (!dle) 340: return; 341: 342: spin_lock(&kgsl_dmabuf_lock); 343: list_del(&metadata->node); 344: if (list_empty(&dle->dmabuf_list)) { 345: list_del(&dle->node); 346: kfree(dle); 347: kgsl_trace_gpu_mem_total(device, 348: -(metadata->entry->memdesc.size)); 349: } 350: spin_unlock(&kgsl_dmabuf_lock); 351: } 352: 353: #ifdef CONFIG_DMA_SHARED_BUFFER 354: static void kgsl_destroy_ion(struct kgsl_memdesc *memdesc) 355: { 356: struct kgsl_mem_entry *entry = container_of(memdesc, 357: struct kgsl_mem_entry, memdesc); 358: struct kgsl_dma_buf_meta *metadata = entry->priv_data; 359: 360: if (TEST_FLAG(KGSL_MEMDESC_MAPPED, &memdesc->priv)) 361: return; 362: 363: if (metadata != NULL) { 364: remove_dmabuf_list(metadata); 365: #if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) 366: dma_buf_unmap_attachment_unlocked(metadata->attach, memdesc->sgt, 367: DMA_BIDIRECTIONAL); 368: #else 369: dma_buf_unmap_attachment(metadata->attach, memdesc->sgt, DMA_BIDIRECTIONAL); 370: #endif 371: dma_buf_detach(metadata->dmabuf, metadata->attach); 372: dma_buf_put(metadata->dmabuf); 373: kfree(metadata); 374: } 375: 376: memdesc->sgt = NULL; 377: entry->priv_data = NULL; 378: } 379: 380: static const struct kgsl_memdesc_ops kgsl_dmabuf_ops = { 381: .free = kgsl_destroy_ion, 382: .put_gpuaddr = kgsl_unmap_and_put_gpuaddr, 383: }; 384: #endif 385: 386: static void kgsl_destroy_anon(struct kgsl_memdesc *memdesc) 387: { 388: int i = 0, j; 389: struct scatterlist *sg; 390: struct page *page; 391: 392: if (TEST_FLAG(KGSL_MEMDESC_MAPPED, &memdesc->priv)) 393: return; 394: 395: for_each_sg(memdesc->sgt->sgl, sg, memdesc->sgt->nents, i) { 396: page = sg_page(sg); 397: for (j = 0; j < (sg->length >> PAGE_SHIFT); j++) { 398: 399: /* 400: * Mark the page in the scatterlist as dirty if they 401: * were writable by the GPU. 402: */ 403: if (!(memdesc->flags & KGSL_MEMFLAGS_GPUREADONLY)) 404: set_page_dirty_lock(kgsl_nth_page(page, j)); 405: 406: /* 407: * Put the page reference taken using get_user_pages 408: * during memdesc_sg_virt. 409: */ 410: put_page(kgsl_nth_page(page, j)); 411: } 412: } 413: 414: sg_free_table(memdesc->sgt); 415: kfree(memdesc->sgt); 416: memdesc->sgt = NULL; 417: } 418: 419: void 420: kgsl_mem_entry_destroy(struct kref *kref) 421: { 422: struct kgsl_mem_entry *entry = container_of(kref, 423: struct kgsl_mem_entry, 424: refcount); 425: unsigned int memtype; 426: 427: if (entry == NULL) 428: return; 429: 430: /* pull out the memtype before the flags get cleared */ 431: memtype = kgsl_memdesc_usermem_type(&entry->memdesc); 432: 433: /* 434: * VBO allocations at gpumem_alloc_vbo_entry are not added into stats 435: * (using kgsl_process_add_stats) so do not subtract here. For all other 436: * allocations subtract before freeing memdesc 437: */ 438: if (!(entry->memdesc.flags & KGSL_MEMFLAGS_VBO)) 439: atomic64_sub(entry->memdesc.size, &entry->priv->stats[memtype].cur); 440: 441: /* Detach from process list */ 442: kgsl_mem_entry_detach_process(entry); 443: 444: if (memtype != KGSL_MEM_ENTRY_KERNEL) 445: atomic_long_sub(entry->memdesc.size, 446: &kgsl_driver.stats.mapped); 447: 448: kgsl_sharedmem_free(&entry->memdesc); 449: 450: kfree(entry); 451: } 452: 453: /* Scheduled by kgsl_mem_entry_destroy_deferred() */ 454: static void _deferred_destroy(struct work_struct *work) 455: { 456: struct kgsl_mem_entry *entry = 457: container_of(work, struct kgsl_mem_entry, work); 458: 459: kgsl_mem_entry_destroy(&entry->refcount); 460: } 461: 462: void kgsl_mem_entry_destroy_deferred(struct kref *kref) 463: { 464: struct kgsl_mem_entry *entry = 465: container_of(kref, struct kgsl_mem_entry, refcount); 466: 467: INIT_WORK(&entry->work, _deferred_destroy); 468: queue_work(kgsl_driver.lockless_workqueue, &entry->work); 469: } 470: 471: /* Scheduled by kgsl_context_destroy_deferred() */ 472: static void _deferred_context_destroy(struct work_struct *work) MATCH LINES: 504, 512, 516, 519, 529, 534, 535, 554, 561, 567, 575, 576, 598, 600, 601 492: if (!entry) 493: return; 494: 495: spin_lock(&entry->priv->mem_lock); 496: idr_replace(&entry->priv->mem_idr, entry, entry->id); 497: spin_unlock(&entry->priv->mem_lock); 498: } 499: 500: static int kgsl_mem_entry_attach_to_process(struct kgsl_device *device, 501: struct kgsl_process_private *process, 502: struct kgsl_mem_entry *entry) 503: { 504: struct kgsl_memdesc *memdesc = &entry->memdesc; 505: int ret, id; 506: 507: ret = kgsl_process_private_get(process); 508: if (!ret) 509: return -EBADF; 510: 511: /* Assign a gpu address */ 512: if (!kgsl_memdesc_use_cpu_map(memdesc) && 513: kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_NONE) { 514: struct kgsl_pagetable *pagetable; 515: 516: pagetable = kgsl_memdesc_is_secured(memdesc) ? 517: device->mmu.securepagetable : process->pagetable; 518: 519: ret = kgsl_mmu_get_gpuaddr(pagetable, memdesc); 520: if (ret) { 521: kgsl_process_private_put(process); 522: return ret; 523: } 524: } 525: 526: idr_preload(GFP_KERNEL); 527: spin_lock(&process->mem_lock); 528: /* Allocate the ID but don't attach the pointer just yet */ 529: id = idr_alloc(&process->mem_idr, NULL, 1, 0, GFP_NOWAIT); 530: spin_unlock(&process->mem_lock); 531: idr_preload_end(); 532: 533: if (id < 0) { 534: if (!kgsl_memdesc_use_cpu_map(memdesc)) 535: kgsl_mmu_put_gpuaddr(memdesc->pagetable, memdesc); 536: kgsl_process_private_put(process); 537: return id; 538: } 539: 540: entry->id = id; 541: entry->priv = process; 542: 543: return 0; 544: } 545: 546: /* 547: * Attach the memory object to a process by (possibly) getting a GPU address and 548: * (possibly) mapping it 549: */ 550: static int kgsl_mem_entry_attach_and_map(struct kgsl_device *device, 551: struct kgsl_process_private *process, 552: struct kgsl_mem_entry *entry) 553: { 554: struct kgsl_memdesc *memdesc = &entry->memdesc; 555: int ret; 556: 557: ret = kgsl_mem_entry_attach_to_process(device, process, entry); 558: if (ret) 559: return ret; 560: 561: if (memdesc->gpuaddr) { 562: /* 563: * Map the memory if a GPU address is already assigned, either 564: * through kgsl_mem_entry_attach_to_process() or via some other 565: * SVM process 566: */ 567: ret = kgsl_mmu_map(memdesc->pagetable, memdesc); 568: 569: if (ret) { 570: kgsl_mem_entry_detach_process(entry); 571: return ret; 572: } 573: } 574: 575: kgsl_memfree_purge(memdesc->pagetable, memdesc->gpuaddr, 576: memdesc->size); 577: 578: return ret; 579: } 580: 581: /* Detach a memory entry from a process and unmap it from the MMU */ 582: static void kgsl_mem_entry_detach_process(struct kgsl_mem_entry *entry) 583: { 584: if (entry == NULL) 585: return; 586: 587: /* 588: * First remove the entry from mem_idr list 589: * so that no one can operate on obsolete values 590: */ 591: spin_lock(&entry->priv->mem_lock); 592: if (entry->id != 0) 593: idr_remove(&entry->priv->mem_idr, entry->id); 594: entry->id = 0; 595: 596: spin_unlock(&entry->priv->mem_lock); 597: 598: kgsl_sharedmem_put_gpuaddr(&entry->memdesc); 599: 600: if (TEST_FLAG(KGSL_MEMDESC_RECLAIMED, &entry->memdesc.priv)) 601: atomic_sub(entry->memdesc.page_count, 602: &entry->priv->unpinned_page_count); 603: 604: kgsl_process_private_put(entry->priv); 605: 606: entry->priv = NULL; 607: } 608: 609: #ifdef CONFIG_QCOM_KGSL_CONTEXT_DEBUG 610: static void kgsl_context_debug_info(struct kgsl_device *device) 611: { 612: struct kgsl_context *context; 613: struct kgsl_process_private *p; 614: int next; 615: /* 616: * Keep an interval between consecutive logging to avoid 617: * flooding the kernel log 618: */ 619: static DEFINE_RATELIMIT_STATE(_rs, 10 * HZ, 1); 620: 621: if (!__ratelimit(&_rs)) 622: return; 623: 624: dev_info(device->dev, "KGSL active contexts:\n"); 625: dev_info(device->dev, "pid process total attached detached\n"); MATCH LINES: 846, 880, 882 834: * the context before it gets fully removed, and to make sure 835: * we don't try to detach twice. 836: */ 837: if (test_and_set_bit(KGSL_CONTEXT_PRIV_DETACHED, &context->priv)) 838: return; 839: 840: trace_kgsl_context_detach(device, context); 841: 842: context->device->ftbl->drawctxt_detach(context); 843: 844: /* 845: * Cancel all pending events after the device-specific context is 846: * detached, to avoid possibly freeing memory while it is still 847: * in use by the GPU. 848: */ 849: kgsl_cancel_events(device, &context->events); 850: 851: /* Remove the event group from the list */ 852: kgsl_del_event_group(device, &context->events); 853: 854: kgsl_sync_timeline_detach(context->ktimeline); 855: kgsl_context_put(context); 856: } 857: 858: void 859: kgsl_context_destroy(struct kref *kref) 860: { 861: struct kgsl_context *context = container_of(kref, struct kgsl_context, 862: refcount); 863: struct kgsl_device *device = context->device; 864: 865: trace_kgsl_context_destroy(device, context); 866: 867: /* 868: * It's not safe to destroy the context if it's not detached as GPU 869: * may still be executing commands 870: */ 871: BUG_ON(!kgsl_context_detached(context)); 872: 873: kgsl_free_faults(context); 874: kgsl_sync_timeline_put(context->ktimeline); 875: 876: write_lock(&device->context_lock); 877: if (context->id != KGSL_CONTEXT_INVALID) { 878: 879: /* Clear the timestamps in the memstore during destroy */ 880: kgsl_sharedmem_writel(device->memstore, 881: KGSL_MEMSTORE_OFFSET(context->id, soptimestamp), 0); 882: kgsl_sharedmem_writel(device->memstore, 883: KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp), 0); 884: 885: /* clear device power constraint */ 886: if (context->id == device->pwrctrl.constraint.owner_id) { 887: trace_kgsl_constraint(device, 888: device->pwrctrl.constraint.type, 889: device->pwrctrl.active_pwrlevel, 890: 0, 0); 891: device->pwrctrl.constraint.type = KGSL_CONSTRAINT_NONE; 892: } 893: 894: atomic_dec(&context->proc_priv->ctxt_count); 895: idr_remove(&device->context_idr, context->id); 896: context->id = KGSL_CONTEXT_INVALID; 897: } 898: write_unlock(&device->context_lock); 899: kgsl_process_private_put(context->proc_priv); 900: 901: device->ftbl->drawctxt_destroy(context); 902: } 903: 904: struct kgsl_device *kgsl_get_device(int dev_idx) 905: { 906: int i; MATCH LINES: 1270, 1271 1258: 1259: kgsl_put_work_period(private->period); 1260: idr_destroy(&private->mem_idr); 1261: idr_destroy(&private->syncsource_idr); 1262: put_pid(private->pid); 1263: mmdrop(private->mm); 1264: 1265: kfree(private); 1266: private = ERR_PTR(err); 1267: return private; 1268: } 1269: 1270: /* Allocate profile memory for gmu based DCVS targets */ 1271: device->ftbl->alloc_dcvs_profile_memory(device, private); 1272: mutex_init(&private->profile.profile_mutex); 1273: kgsl_process_init_sysfs(device, private); 1274: kgsl_process_init_debugfs(private); 1275: write_lock(&kgsl_driver.proclist_lock); 1276: list_add(&private->list, &kgsl_driver.process_list); 1277: write_unlock(&kgsl_driver.proclist_lock); 1278: 1279: return private; 1280: } 1281: 1282: static void process_release_memory(struct kgsl_process_private *private) 1283: { 1284: struct kgsl_mem_entry *entry; 1285: int next = 0; 1286: 1287: while (1) { 1288: spin_lock(&private->mem_lock); 1289: entry = idr_get_next(&private->mem_idr, &next); 1290: if (entry == NULL) { 1291: spin_unlock(&private->mem_lock); 1292: break; 1293: } 1294: /* 1295: * If the free pending flag is not set it means that user space MATCH LINES: 1571, 1572, 1573, 1576, 1579, 1581, 1585, 1593, 1594, 1595, 1600, 1612, 1621, 1629, 1639, 1641, 1658, 1664 1559: goto err; 1560: } 1561: 1562: err: 1563: if (result) { 1564: filep->private_data = NULL; 1565: kfree(dev_priv); 1566: pm_runtime_put(&device->pdev->dev); 1567: } 1568: return result; 1569: } 1570: 1571: #define GPUADDR_IN_MEMDESC(_val, _memdesc) \ 1572: (((_val) >= (_memdesc)->gpuaddr) && \ 1573: ((_val) < ((_memdesc)->gpuaddr + (_memdesc)->size))) 1574: 1575: /** 1576: * kgsl_sharedmem_find() - Find a gpu memory allocation 1577: * 1578: * @private: private data for the process to check. 1579: * @gpuaddr: start address of the region 1580: * 1581: * Find a gpu allocation. Caller must kgsl_mem_entry_put() 1582: * the returned entry when finished using it. 1583: */ 1584: struct kgsl_mem_entry * __must_check 1585: kgsl_sharedmem_find(struct kgsl_process_private *private, uint64_t gpuaddr) 1586: { 1587: int id; 1588: struct kgsl_mem_entry *entry, *ret = NULL; 1589: 1590: if (!private) 1591: return NULL; 1592: 1593: if (!kgsl_mmu_gpuaddr_in_range(private->pagetable, gpuaddr, 0) && 1594: !kgsl_mmu_gpuaddr_in_range( 1595: private->pagetable->mmu->securepagetable, gpuaddr, 0)) 1596: return NULL; 1597: 1598: spin_lock(&private->mem_lock); 1599: idr_for_each_entry(&private->mem_idr, entry, id) { 1600: if (GPUADDR_IN_MEMDESC(gpuaddr, &entry->memdesc)) { 1601: if (!entry->pending_free) 1602: ret = kgsl_mem_entry_get(entry); 1603: break; 1604: } 1605: } 1606: spin_unlock(&private->mem_lock); 1607: 1608: return ret; 1609: } 1610: 1611: static struct kgsl_mem_entry * __must_check 1612: kgsl_sharedmem_find_id_flags(struct kgsl_process_private *process, 1613: unsigned int id, uint64_t flags) 1614: { 1615: struct kgsl_mem_entry *entry, *ret = NULL; 1616: 1617: spin_lock(&process->mem_lock); 1618: entry = idr_find(&process->mem_idr, id); 1619: if (entry) 1620: if (!entry->pending_free && 1621: (flags & entry->memdesc.flags) == flags) 1622: ret = kgsl_mem_entry_get(entry); 1623: spin_unlock(&process->mem_lock); 1624: 1625: return ret; 1626: } 1627: 1628: /** 1629: * kgsl_sharedmem_find_id() - find a memory entry by id 1630: * @process: the owning process 1631: * @id: id to find 1632: * 1633: * @returns - the mem_entry or NULL 1634: * 1635: * Caller must kgsl_mem_entry_put() the returned entry, when finished using 1636: * it. 1637: */ 1638: struct kgsl_mem_entry * __must_check 1639: kgsl_sharedmem_find_id(struct kgsl_process_private *process, unsigned int id) 1640: { 1641: return kgsl_sharedmem_find_id_flags(process, id, 0); 1642: } 1643: 1644: /** 1645: * kgsl_mem_entry_unset_pend() - Unset the pending free flag of an entry 1646: * @entry - The memory entry 1647: */ 1648: static inline void kgsl_mem_entry_unset_pend(struct kgsl_mem_entry *entry) 1649: { 1650: if (entry == NULL) 1651: return; 1652: spin_lock(&entry->priv->mem_lock); 1653: entry->pending_free = 0; 1654: spin_unlock(&entry->priv->mem_lock); 1655: } 1656: 1657: /** 1658: * kgsl_mem_entry_set_pend() - Set the pending free flag of a memory entry 1659: * @entry - The memory entry 1660: * 1661: * @returns - true if pending flag was 0 else false 1662: * 1663: * This function will set the pending free flag if it is previously unset. Used 1664: * to prevent race condition between ioctls calling free/freememontimestamp 1665: * on the same entry. Whichever thread set's the flag first will do the free. 1666: */ 1667: static inline bool kgsl_mem_entry_set_pend(struct kgsl_mem_entry *entry) 1668: { 1669: bool ret = false; 1670: 1671: if (entry == NULL) 1672: return false; 1673: 1674: spin_lock(&entry->priv->mem_lock); 1675: if (!entry->pending_free) { 1676: entry->pending_free = 1; 1677: ret = true; 1678: } 1679: spin_unlock(&entry->priv->mem_lock); 1680: return ret; 1681: } 1682: 1683: static int kgsl_get_ctxt_fault_stats(struct kgsl_context *context, 1684: struct kgsl_context_property *ctxt_property) 1685: { 1686: struct kgsl_context_property_fault fault_stats; 1687: size_t copy; 1688: MATCH LINES: 2136 2124: } 2125: 2126: drawobj = DRAWOBJ(cmdobj); 2127: 2128: if (param->flags & KGSL_DRAWOBJ_SUBMIT_IB_LIST) 2129: result = kgsl_drawobj_cmd_add_ibdesc_list(device, cmdobj, 2130: (void __user *) param->ibdesc_addr, 2131: param->numibs); 2132: else { 2133: struct kgsl_ibdesc ibdesc; 2134: /* Ultra legacy path */ 2135: 2136: ibdesc.gpuaddr = param->ibdesc_addr; 2137: ibdesc.sizedwords = param->numibs; 2138: ibdesc.ctrl = 0; 2139: 2140: result = kgsl_drawobj_cmd_add_ibdesc(device, cmdobj, &ibdesc); 2141: } 2142: 2143: if (result == 0) 2144: result = kgsl_reclaim_to_pinned_state(dev_priv->process_priv); 2145: 2146: if (result == 0) 2147: result = device->ftbl->queue_cmds(dev_priv, context, 2148: &drawobj, 1, ¶m->timestamp); 2149: 2150: /* 2151: * -EPROTO is a "success" error - it just tells the user that the 2152: * context had previously faulted 2153: */ 2154: if (result && result != -EPROTO) 2155: kgsl_drawobj_destroy(drawobj); 2156: 2157: kgsl_context_put(context); 2158: return result; 2159: } 2160: MATCH LINES: 2694, 2701, 2702, 2703, 2704, 2720, 2724, 2725, 2726, 2727, 2754, 2757, 2762, 2780 2682: struct kgsl_context *context; 2683: 2684: context = kgsl_context_get_owner(dev_priv, param->drawctxt_id); 2685: if (context == NULL) 2686: return -EINVAL; 2687: 2688: kgsl_context_detach(context); 2689: kgsl_context_put(context); 2690: 2691: return 0; 2692: } 2693: 2694: long gpumem_free_entry(struct kgsl_mem_entry *entry) 2695: { 2696: if (!kgsl_mem_entry_set_pend(entry)) 2697: return -EBUSY; 2698: 2699: trace_kgsl_mem_free(entry); 2700: kgsl_memfree_add(pid_nr(entry->priv->pid), 2701: entry->memdesc.pagetable ? 2702: entry->memdesc.pagetable->name : 0, 2703: entry->memdesc.gpuaddr, entry->memdesc.size, 2704: entry->memdesc.flags); 2705: 2706: kgsl_mem_entry_put(entry); 2707: 2708: return 0; 2709: } 2710: 2711: static void gpumem_free_func(struct kgsl_device *device, 2712: struct kgsl_event_group *group, void *priv, int ret) 2713: { 2714: struct kgsl_context *context = group->context; 2715: struct kgsl_mem_entry *entry = priv; 2716: unsigned int timestamp; 2717: 2718: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, ×tamp); 2719: 2720: /* Free the memory for all event types */ 2721: trace_kgsl_mem_timestamp_free(device, entry, KGSL_CONTEXT_ID(context), 2722: timestamp, 0); 2723: kgsl_memfree_add(pid_nr(entry->priv->pid), 2724: entry->memdesc.pagetable ? 2725: entry->memdesc.pagetable->name : 0, 2726: entry->memdesc.gpuaddr, entry->memdesc.size, 2727: entry->memdesc.flags); 2728: 2729: kgsl_mem_entry_put_deferred(entry); 2730: } 2731: 2732: static long gpumem_free_entry_on_timestamp(struct kgsl_device *device, 2733: struct kgsl_mem_entry *entry, 2734: struct kgsl_context *context, unsigned int timestamp) 2735: { 2736: int ret; 2737: unsigned int temp; 2738: 2739: if (!kgsl_mem_entry_set_pend(entry)) 2740: return -EBUSY; 2741: 2742: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, &temp); 2743: trace_kgsl_mem_timestamp_queue(device, entry, context->id, temp, 2744: timestamp); 2745: ret = kgsl_add_event(device, &context->events, 2746: timestamp, gpumem_free_func, entry); 2747: 2748: if (ret) 2749: kgsl_mem_entry_unset_pend(entry); 2750: 2751: return ret; 2752: } 2753: 2754: long kgsl_ioctl_sharedmem_free(struct kgsl_device_private *dev_priv, 2755: unsigned int cmd, void *data) 2756: { 2757: struct kgsl_sharedmem_free *param = data; 2758: struct kgsl_process_private *private = dev_priv->process_priv; 2759: struct kgsl_mem_entry *entry; 2760: long ret; 2761: 2762: entry = kgsl_sharedmem_find(private, (uint64_t) param->gpuaddr); 2763: if (entry == NULL) 2764: return -EINVAL; 2765: 2766: ret = gpumem_free_entry(entry); 2767: kgsl_mem_entry_put(entry); 2768: 2769: return ret; 2770: } 2771: 2772: long kgsl_ioctl_gpumem_free_id(struct kgsl_device_private *dev_priv, 2773: unsigned int cmd, void *data) 2774: { 2775: struct kgsl_gpumem_free_id *param = data; 2776: struct kgsl_process_private *private = dev_priv->process_priv; 2777: struct kgsl_mem_entry *entry; 2778: long ret; 2779: 2780: entry = kgsl_sharedmem_find_id(private, param->id); 2781: if (entry == NULL) 2782: return -EINVAL; 2783: 2784: ret = gpumem_free_entry(entry); 2785: kgsl_mem_entry_put(entry); 2786: 2787: return ret; 2788: } 2789: 2790: static long gpuobj_free_on_timestamp(struct kgsl_device_private *dev_priv, 2791: struct kgsl_mem_entry *entry, struct kgsl_gpuobj_free *param) 2792: { 2793: struct kgsl_gpu_event_timestamp event; 2794: struct kgsl_context *context; 2795: long ret; 2796: 2797: if (copy_struct_from_user(&event, sizeof(event), 2798: u64_to_user_ptr(param->priv), param->len)) 2799: return -EFAULT; 2800: 2801: if (event.context_id == 0) 2802: return -EINVAL; 2803: 2804: context = kgsl_context_get_owner(dev_priv, event.context_id); MATCH LINES: 2821, 2822, 2823, 2824 2809: event.timestamp); 2810: 2811: kgsl_context_put(context); 2812: return ret; 2813: } 2814: 2815: static bool gpuobj_free_fence_func(void *priv) 2816: { 2817: struct kgsl_mem_entry *entry = priv; 2818: 2819: trace_kgsl_mem_free(entry); 2820: kgsl_memfree_add(pid_nr(entry->priv->pid), 2821: entry->memdesc.pagetable ? 2822: entry->memdesc.pagetable->name : 0, 2823: entry->memdesc.gpuaddr, entry->memdesc.size, 2824: entry->memdesc.flags); 2825: 2826: kgsl_mem_entry_put_deferred(entry); 2827: return true; 2828: } 2829: 2830: static long gpuobj_free_on_fence(struct kgsl_device_private *dev_priv, 2831: struct kgsl_mem_entry *entry, struct kgsl_gpuobj_free *param) 2832: { 2833: struct kgsl_sync_fence_cb *handle; 2834: struct kgsl_gpu_event_fence event; 2835: 2836: if (!kgsl_mem_entry_set_pend(entry)) 2837: return -EBUSY; 2838: 2839: if (copy_struct_from_user(&event, sizeof(event), 2840: u64_to_user_ptr(param->priv), param->len)) { 2841: kgsl_mem_entry_unset_pend(entry); 2842: return -EFAULT; 2843: } 2844: 2845: if (event.fd < 0) { 2846: kgsl_mem_entry_unset_pend(entry); 2847: return -EINVAL; 2848: } MATCH LINES: 2872, 2890, 2894, 2906, 2907, 2937, 2956, 2966, 2981, 2986, 2991, 2993, 3003, 3004, 3010, 3033, 3034, 3039, 3043, 3049, 3050, 3056, 3058, 3072, 3073, 3074, 3075, 3077, 3093, 3096, 3098, 3099, 3134 2860: 2861: return 0; 2862: } 2863: 2864: long kgsl_ioctl_gpuobj_free(struct kgsl_device_private *dev_priv, 2865: unsigned int cmd, void *data) 2866: { 2867: struct kgsl_gpuobj_free *param = data; 2868: struct kgsl_process_private *private = dev_priv->process_priv; 2869: struct kgsl_mem_entry *entry; 2870: long ret; 2871: 2872: entry = kgsl_sharedmem_find_id(private, param->id); 2873: if (entry == NULL) 2874: return -EINVAL; 2875: 2876: /* If no event is specified then free immediately */ 2877: if (!(param->flags & KGSL_GPUOBJ_FREE_ON_EVENT)) 2878: ret = gpumem_free_entry(entry); 2879: else if (param->type == KGSL_GPU_EVENT_TIMESTAMP) 2880: ret = gpuobj_free_on_timestamp(dev_priv, entry, param); 2881: else if (param->type == KGSL_GPU_EVENT_FENCE) 2882: ret = gpuobj_free_on_fence(dev_priv, entry, param); 2883: else 2884: ret = -EINVAL; 2885: 2886: kgsl_mem_entry_put(entry); 2887: return ret; 2888: } 2889: 2890: long kgsl_ioctl_cmdstream_freememontimestamp_ctxtid( 2891: struct kgsl_device_private *dev_priv, 2892: unsigned int cmd, void *data) 2893: { 2894: struct kgsl_cmdstream_freememontimestamp_ctxtid *param = data; 2895: struct kgsl_context *context = NULL; 2896: struct kgsl_mem_entry *entry; 2897: long ret = -EINVAL; 2898: 2899: if (param->type != KGSL_TIMESTAMP_RETIRED) 2900: return -EINVAL; 2901: 2902: context = kgsl_context_get_owner(dev_priv, param->context_id); 2903: if (context == NULL) 2904: return -EINVAL; 2905: 2906: entry = kgsl_sharedmem_find(dev_priv->process_priv, 2907: (uint64_t) param->gpuaddr); 2908: if (entry == NULL) { 2909: kgsl_context_put(context); 2910: return -EINVAL; 2911: } 2912: 2913: ret = gpumem_free_entry_on_timestamp(dev_priv->device, entry, 2914: context, param->timestamp); 2915: 2916: kgsl_mem_entry_put(entry); 2917: kgsl_context_put(context); 2918: 2919: return ret; 2920: } 2921: 2922: static bool _vma_is_cached(struct vm_area_struct *vma) 2923: { 2924: pteval_t pgprot_val = pgprot_val(vma->vm_page_prot); 2925: 2926: /* 2927: * An uncached cpu mapping can either be marked as writecombine or noncached. If it isn't 2928: * either, then it means it is cached. 2929: */ 2930: if ((pgprot_val != pgprot_val(pgprot_writecombine((vma->vm_page_prot)))) && 2931: (pgprot_val != pgprot_val(pgprot_noncached(vma->vm_page_prot)))) 2932: return true; 2933: 2934: return false; 2935: } 2936: 2937: static bool check_vma(struct kgsl_device *device, struct kgsl_memdesc *memdesc, 2938: unsigned long hostptr) 2939: { 2940: struct vm_area_struct *vma; 2941: unsigned long cur = hostptr; 2942: bool cached; 2943: 2944: vma = find_vma(current->mm, hostptr); 2945: if (!vma) 2946: return false; 2947: 2948: /* Don't remap memory that we already own */ 2949: if (vma->vm_file && (vma->vm_ops == &kgsl_gpumem_vm_ops)) 2950: return false; 2951: 2952: cached = _vma_is_cached(vma); 2953: 2954: cur = vma->vm_end; 2955: 2956: while (cur < (hostptr + memdesc->size)) { 2957: vma = find_vma(current->mm, cur); 2958: if (!vma) 2959: return false; 2960: 2961: /* Don't remap memory that we already own */ 2962: if (vma->vm_file && (vma->vm_ops == &kgsl_gpumem_vm_ops)) 2963: return false; 2964: 2965: /* 2966: * Make sure the entire memdesc is either cached or noncached. Bail out if there is 2967: * a mismatch as it can lead to coherency issues. 2968: */ 2969: if (cached != _vma_is_cached(vma)) 2970: return false; 2971: 2972: cur = vma->vm_end; 2973: } 2974: 2975: /* 2976: * If cpu side mapping is cached (and io-coherency is enabled), the gpu mapping should be 2977: * marked io-coherent to avoid coherency issues. 2978: */ 2979: if (cached && kgsl_mmu_has_feature(device, KGSL_MMU_IO_COHERENT) && 2980: IS_ENABLED(CONFIG_QCOM_KGSL_IOCOHERENCY_DEFAULT)) 2981: memdesc->flags |= KGSL_MEMFLAGS_IOCOHERENT; 2982: 2983: return true; 2984: } 2985: 2986: static int memdesc_sg_virt(struct kgsl_device *device, struct kgsl_memdesc *memdesc, 2987: unsigned long useraddr) 2988: { 2989: int ret = 0; 2990: long npages = 0, i; 2991: size_t sglen = (size_t) (memdesc->size / PAGE_SIZE); 2992: struct page **pages = NULL; 2993: int write = ((memdesc->flags & KGSL_MEMFLAGS_GPUREADONLY) ? 0 : 2994: FOLL_WRITE); 2995: 2996: if (sglen == 0 || sglen >= LONG_MAX) 2997: return -EINVAL; 2998: 2999: pages = kvcalloc(sglen, sizeof(*pages), GFP_KERNEL); 3000: if (pages == NULL) 3001: return -ENOMEM; 3002: 3003: memdesc->sgt = kmalloc(sizeof(*memdesc->sgt), GFP_KERNEL); 3004: if (memdesc->sgt == NULL) { 3005: ret = -ENOMEM; 3006: goto out; 3007: } 3008: 3009: mmap_read_lock(current->mm); 3010: if (!check_vma(device, memdesc, useraddr)) { 3011: mmap_read_unlock(current->mm); 3012: ret = -EFAULT; 3013: goto out; 3014: } 3015: 3016: #if (KERNEL_VERSION(6, 4, 0) <= LINUX_VERSION_CODE) 3017: npages = get_user_pages(useraddr, sglen, write, pages); 3018: #else 3019: npages = get_user_pages(useraddr, sglen, write, pages, NULL); 3020: #endif 3021: 3022: mmap_read_unlock(current->mm); 3023: 3024: ret = (npages < 0) ? (int)npages : 0; 3025: if (ret) 3026: goto out; 3027: 3028: if ((unsigned long) npages != sglen) { 3029: ret = -EINVAL; 3030: goto out; 3031: } 3032: 3033: ret = sg_alloc_table_from_pages(memdesc->sgt, pages, npages, 3034: 0, memdesc->size, GFP_KERNEL); 3035: 3036: if (ret) 3037: goto out; 3038: 3039: ret = kgsl_cache_range_op(memdesc, 0, memdesc->size, 3040: KGSL_CACHE_OP_FLUSH); 3041: 3042: if (ret) 3043: sg_free_table(memdesc->sgt); 3044: out: 3045: if (ret) { 3046: for (i = 0; i < npages; i++) 3047: put_page(pages[i]); 3048: 3049: kfree(memdesc->sgt); 3050: memdesc->sgt = NULL; 3051: } 3052: kvfree(pages); 3053: return ret; 3054: } 3055: 3056: static const struct kgsl_memdesc_ops kgsl_usermem_ops = { 3057: .free = kgsl_destroy_anon, 3058: .put_gpuaddr = kgsl_unmap_and_put_gpuaddr, 3059: }; 3060: 3061: static int kgsl_setup_anon_useraddr(struct kgsl_device *device, struct kgsl_pagetable *pagetable, 3062: struct kgsl_mem_entry *entry, unsigned long hostptr, size_t offset, size_t size) 3063: { 3064: /* Map an anonymous memory chunk */ 3065: 3066: int ret; 3067: 3068: if (size == 0 || offset != 0 || 3069: !IS_ALIGNED(size, PAGE_SIZE)) 3070: return -EINVAL; 3071: 3072: entry->memdesc.pagetable = pagetable; 3073: entry->memdesc.size = (uint64_t) size; 3074: entry->memdesc.flags |= (uint64_t)KGSL_MEMFLAGS_USERMEM_ADDR; 3075: entry->memdesc.ops = &kgsl_usermem_ops; 3076: 3077: if (kgsl_memdesc_use_cpu_map(&entry->memdesc)) { 3078: 3079: /* Register the address in the database */ 3080: ret = kgsl_mmu_set_svm_region(pagetable, 3081: (uint64_t) hostptr, (uint64_t) size); 3082: 3083: /* if OOM, retry once after flushing lockless_workqueue */ 3084: if (ret == -ENOMEM) { 3085: flush_workqueue(kgsl_driver.lockless_workqueue); 3086: ret = kgsl_mmu_set_svm_region(pagetable, 3087: (uint64_t) hostptr, (uint64_t) size); 3088: } 3089: 3090: if (ret) 3091: return ret; 3092: 3093: entry->memdesc.gpuaddr = (uint64_t) hostptr; 3094: } 3095: 3096: ret = memdesc_sg_virt(device, &entry->memdesc, hostptr); 3097: 3098: if (ret && kgsl_memdesc_use_cpu_map(&entry->memdesc)) 3099: kgsl_mmu_put_gpuaddr(pagetable, &entry->memdesc); 3100: 3101: return ret; 3102: } 3103: 3104: static int kgsl_setup_useraddr(struct kgsl_device *device, 3105: struct kgsl_pagetable *pagetable, 3106: struct kgsl_mem_entry *entry, 3107: unsigned long hostptr, size_t offset, size_t size) 3108: { 3109: if (hostptr == 0 || !IS_ALIGNED(hostptr, PAGE_SIZE)) 3110: return -EINVAL; 3111: 3112: return kgsl_setup_anon_useraddr(device, pagetable, entry, 3113: hostptr, offset, size); 3114: } 3115: 3116: static long _gpuobj_map_useraddr(struct kgsl_device *device, 3117: struct kgsl_pagetable *pagetable, 3118: struct kgsl_mem_entry *entry, 3119: struct kgsl_gpuobj_import *param) 3120: { 3121: struct kgsl_gpuobj_import_useraddr useraddr; 3122: 3123: param->flags &= KGSL_MEMFLAGS_GPUREADONLY 3124: | KGSL_CACHEMODE_MASK 3125: | KGSL_MEMFLAGS_USE_CPU_MAP 3126: | KGSL_MEMTYPE_MASK 3127: | KGSL_MEMFLAGS_FORCE_32BIT 3128: | KGSL_MEMFLAGS_IOCOHERENT; 3129: 3130: /* Specifying SECURE is an explicit error */ 3131: if (param->flags & KGSL_MEMFLAGS_SECURE) 3132: return -ENOTSUPP; 3133: 3134: kgsl_memdesc_init(device, &entry->memdesc, param->flags); 3135: 3136: if (copy_from_user(&useraddr, 3137: u64_to_user_ptr(param->priv), sizeof(useraddr))) 3138: return -EINVAL; 3139: 3140: /* Verify that the virtaddr and len are within bounds */ 3141: if (useraddr.virtaddr > ULONG_MAX) 3142: return -EINVAL; 3143: 3144: return kgsl_setup_useraddr(device, pagetable, entry, 3145: (unsigned long) useraddr.virtaddr, 0, param->priv_len); 3146: } 3147: 3148: static bool check_and_warn_secured(struct kgsl_device *device) 3149: { 3150: if (kgsl_mmu_is_secured(&device->mmu)) 3151: return true; 3152: 3153: dev_WARN_ONCE(device->dev, 1, "Secure buffers are not supported\n"); 3154: return false; 3155: } 3156: 3157: #ifdef CONFIG_DMA_SHARED_BUFFER 3158: static int kgsl_setup_dma_buf(struct kgsl_device *device, MATCH LINES: 3181, 3187, 3191, 3209, 3211, 3221 3169: bool iocoherent = (param->flags & KGSL_MEMFLAGS_IOCOHERENT); 3170: struct kgsl_gpuobj_import_dma_buf buf; 3171: struct dma_buf *dmabuf; 3172: int ret; 3173: 3174: param->flags &= KGSL_MEMFLAGS_GPUREADONLY | 3175: KGSL_MEMTYPE_MASK | 3176: KGSL_MEMALIGN_MASK | 3177: KGSL_MEMFLAGS_SECURE | 3178: KGSL_MEMFLAGS_FORCE_32BIT | 3179: KGSL_MEMFLAGS_GUARD_PAGE; 3180: 3181: kgsl_memdesc_init(device, &entry->memdesc, param->flags); 3182: 3183: /* 3184: * If content protection is not enabled and secure buffer 3185: * is requested to be mapped return error. 3186: */ 3187: if (entry->memdesc.flags & KGSL_MEMFLAGS_SECURE) { 3188: if (!check_and_warn_secured(device)) 3189: return -ENOTSUPP; 3190: 3191: SET_FLAG(KGSL_MEMDESC_SECURE, &entry->memdesc.priv); 3192: } 3193: 3194: if (copy_struct_from_user(&buf, sizeof(buf), 3195: u64_to_user_ptr(param->priv), param->priv_len)) 3196: return -EFAULT; 3197: 3198: if (buf.fd < 0) 3199: return -EINVAL; 3200: 3201: *fd = buf.fd; 3202: dmabuf = dma_buf_get(buf.fd); 3203: 3204: if (IS_ERR(dmabuf)) 3205: return PTR_ERR(dmabuf); 3206: 3207: /* 3208: * DMA BUFS are always cached so make sure that is reflected in 3209: * the memdesc. 3210: */ 3211: entry->memdesc.flags |= 3212: FIELD_PREP(KGSL_CACHEMODE_MASK, KGSL_CACHEMODE_WRITEBACK); 3213: 3214: /* 3215: * Enable I/O coherency if it is 1) a thing, and either 3216: * 2) enabled by default or 3) enabled by the caller 3217: */ 3218: if (kgsl_mmu_has_feature(device, KGSL_MMU_IO_COHERENT) && 3219: (IS_ENABLED(CONFIG_QCOM_KGSL_IOCOHERENCY_DEFAULT) || 3220: iocoherent)) 3221: entry->memdesc.flags |= KGSL_MEMFLAGS_IOCOHERENT; 3222: 3223: ret = kgsl_setup_dma_buf(device, pagetable, entry, dmabuf); 3224: if (ret) 3225: dma_buf_put(dmabuf); 3226: 3227: return ret; 3228: } 3229: #else 3230: static long _gpuobj_map_dma_buf(struct kgsl_device *device, 3231: struct kgsl_pagetable *pagetable, 3232: struct kgsl_mem_entry *entry, 3233: struct kgsl_gpuobj_import *param, 3234: int *fd) 3235: { 3236: return -EINVAL; 3237: } 3238: #endif 3239: 3240: static void kgsl_process_add_stats(struct kgsl_process_private *priv, 3241: unsigned int type, uint64_t size) 3242: { 3243: u64 ret = atomic64_add_return(size, &priv->stats[type].cur); 3244: 3245: if (ret > priv->stats[type].max) MATCH LINES: 3298, 3299, 3300, 3301, 3303, 3311, 3315, 3316, 3328, 3343, 3364, 3368, 3395 3286: return -ENOMEM; 3287: 3288: if (param->type == KGSL_USER_MEM_TYPE_ADDR) 3289: ret = _gpuobj_map_useraddr(device, private->pagetable, 3290: entry, param); 3291: else 3292: ret = _gpuobj_map_dma_buf(device, private->pagetable, 3293: entry, param, &fd); 3294: 3295: if (ret) 3296: goto out; 3297: 3298: if (entry->memdesc.size >= SZ_1M) 3299: kgsl_memdesc_set_align(&entry->memdesc, ilog2(SZ_1M)); 3300: else if (entry->memdesc.size >= SZ_64K) 3301: kgsl_memdesc_set_align(&entry->memdesc, ilog2(SZ_64K)); 3302: 3303: param->flags = entry->memdesc.flags; 3304: 3305: ret = kgsl_mem_entry_attach_and_map(device, private, entry); 3306: if (ret) 3307: goto unmap; 3308: 3309: param->id = entry->id; 3310: 3311: KGSL_STATS_ADD(entry->memdesc.size, &kgsl_driver.stats.mapped, 3312: &kgsl_driver.stats.mapped_max); 3313: 3314: kgsl_process_add_stats(private, 3315: kgsl_memdesc_usermem_type(&entry->memdesc), 3316: entry->memdesc.size); 3317: 3318: trace_kgsl_mem_map(entry, fd); 3319: 3320: kgsl_mem_entry_commit_process(entry); 3321: 3322: /* Put the extra ref from kgsl_mem_entry_create() */ 3323: kgsl_mem_entry_put(entry); 3324: 3325: return 0; 3326: 3327: unmap: 3328: kgsl_sharedmem_free(&entry->memdesc); 3329: 3330: out: 3331: kfree(entry); 3332: return ret; 3333: } 3334: 3335: static long _map_usermem_addr(struct kgsl_device *device, 3336: struct kgsl_pagetable *pagetable, struct kgsl_mem_entry *entry, 3337: unsigned long hostptr, size_t offset, size_t size) 3338: { 3339: if (!kgsl_mmu_has_feature(device, KGSL_MMU_PAGED)) 3340: return -EINVAL; 3341: 3342: /* No CPU mapped buffer could ever be secure */ 3343: if (entry->memdesc.flags & KGSL_MEMFLAGS_SECURE) 3344: return -EINVAL; 3345: 3346: return kgsl_setup_useraddr(device, pagetable, entry, hostptr, 3347: offset, size); 3348: } 3349: 3350: #ifdef CONFIG_DMA_SHARED_BUFFER 3351: static int _map_usermem_dma_buf(struct kgsl_device *device, 3352: struct kgsl_pagetable *pagetable, 3353: struct kgsl_mem_entry *entry, 3354: unsigned int fd) 3355: { 3356: int ret; 3357: struct dma_buf *dmabuf; 3358: 3359: /* 3360: * If content protection is not enabled and secure buffer 3361: * is requested to be mapped return error. 3362: */ 3363: 3364: if (entry->memdesc.flags & KGSL_MEMFLAGS_SECURE) { 3365: if (!check_and_warn_secured(device)) 3366: return -EOPNOTSUPP; 3367: 3368: SET_FLAG(KGSL_MEMDESC_SECURE, &entry->memdesc.priv); 3369: } 3370: 3371: dmabuf = dma_buf_get(fd); 3372: if (IS_ERR_OR_NULL(dmabuf)) { 3373: ret = PTR_ERR(dmabuf); 3374: return ret ? ret : -EINVAL; 3375: } 3376: ret = kgsl_setup_dma_buf(device, pagetable, entry, dmabuf); 3377: if (ret) 3378: dma_buf_put(dmabuf); 3379: return ret; 3380: } 3381: #else 3382: static int _map_usermem_dma_buf(struct kgsl_device *device, 3383: struct kgsl_pagetable *pagetable, 3384: struct kgsl_mem_entry *entry, 3385: unsigned int fd) 3386: { 3387: return -EINVAL; 3388: } 3389: #endif 3390: 3391: #ifdef CONFIG_DMA_SHARED_BUFFER 3392: static int verify_secure_access(struct kgsl_device *device, 3393: struct kgsl_mem_entry *entry, struct dma_buf *dmabuf) 3394: { 3395: bool secure = TEST_FLAG(KGSL_MEMDESC_SECURE, &entry->memdesc.priv); 3396: uint32_t *vmid_list = NULL, *perms_list = NULL; 3397: uint32_t nelems = 0; 3398: int i; 3399: 3400: if (mem_buf_dma_buf_copy_vmperm(dmabuf, (int **)&vmid_list, 3401: (int **)&perms_list, (int *)&nelems)) { 3402: dev_dbg(device->dev, "Skipped access check\n"); 3403: return 0; 3404: } 3405: 3406: /* Check if secure buffer is accessible to CP_PIXEL */ 3407: for (i = 0; i < nelems; i++) { 3408: if (vmid_list[i] == VMID_CP_PIXEL) 3409: break; 3410: } 3411: 3412: kfree(vmid_list); 3413: kfree(perms_list); 3414: 3415: /* 3416: * Do not import a buffer if it is accessible to CP_PIXEL but is being imported as 3417: * a buffer accessible to non-secure GPU. Also, make sure if buffer is to be made 3418: * accessible to secure GPU, it must be accessible to CP_PIXEL 3419: */ MATCH LINES: 3457, 3466, 3467, 3468, 3470, 3471, 3485, 3491, 3492, 3493, 3495, 3501, 3538 3445: 3446: if (IS_ERR(attach)) { 3447: ret = PTR_ERR(attach); 3448: goto out; 3449: } 3450: 3451: #ifndef CONFIG_QCOM_KGSL_UPSTREAM 3452: /* 3453: * If dma buffer is marked IO coherent, skip sync at attach, 3454: * which involves flushing the buffer on CPU. 3455: * HW manages coherency for IO coherent buffers. 3456: */ 3457: if (entry->memdesc.flags & KGSL_MEMFLAGS_IOCOHERENT) 3458: attach->dma_map_attrs |= DMA_ATTR_SKIP_CPU_SYNC; 3459: #endif 3460: 3461: metadata->dmabuf = dmabuf; 3462: metadata->attach = attach; 3463: metadata->entry = entry; 3464: 3465: entry->priv_data = metadata; 3466: entry->memdesc.pagetable = pagetable; 3467: entry->memdesc.size = 0; 3468: entry->memdesc.ops = &kgsl_dmabuf_ops; 3469: /* USE_CPU_MAP is not impemented for ION. */ 3470: entry->memdesc.flags &= ~((uint64_t) KGSL_MEMFLAGS_USE_CPU_MAP); 3471: entry->memdesc.flags |= (uint64_t)KGSL_MEMFLAGS_USERMEM_ION; 3472: 3473: #if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) 3474: sg_table = dma_buf_map_attachment_unlocked(attach, DMA_BIDIRECTIONAL); 3475: #else 3476: sg_table = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL); 3477: #endif 3478: if (IS_ERR_OR_NULL(sg_table)) { 3479: ret = PTR_ERR(sg_table); 3480: goto out; 3481: } 3482: 3483: metadata->table = sg_table; 3484: entry->priv_data = metadata; 3485: entry->memdesc.sgt = sg_table; 3486: 3487: ret = verify_secure_access(device, entry, dmabuf); 3488: if (ret) 3489: goto out; 3490: 3491: /* Calculate the size of the memdesc from the sglist */ 3492: for (s = entry->memdesc.sgt->sgl; s != NULL; s = sg_next(s)) 3493: entry->memdesc.size += (uint64_t) s->length; 3494: 3495: if (!entry->memdesc.size) { 3496: ret = -EINVAL; 3497: goto out; 3498: } 3499: 3500: add_dmabuf_list(metadata); 3501: entry->memdesc.size = PAGE_ALIGN(entry->memdesc.size); 3502: 3503: out: 3504: if (ret) { 3505: if (!IS_ERR_OR_NULL(sg_table)) 3506: #if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) 3507: dma_buf_unmap_attachment_unlocked(attach, sg_table, DMA_BIDIRECTIONAL); 3508: #else 3509: dma_buf_unmap_attachment(attach, sg_table, DMA_BIDIRECTIONAL); 3510: #endif 3511: 3512: if (!IS_ERR_OR_NULL(attach)) 3513: dma_buf_detach(dmabuf, attach); 3514: 3515: kfree(metadata); 3516: } 3517: 3518: return ret; 3519: } 3520: #endif 3521: 3522: #ifdef CONFIG_DMA_SHARED_BUFFER 3523: void kgsl_get_egl_counts(struct kgsl_mem_entry *entry, 3524: int *egl_surface_count, int *egl_image_count) 3525: { 3526: struct kgsl_dma_buf_meta *metadata = entry->priv_data; 3527: struct dmabuf_list_entry *dle = metadata->dle; 3528: struct kgsl_dma_buf_meta *scan_meta; 3529: struct kgsl_mem_entry *scan_mem_entry; 3530: 3531: if (!dle) 3532: return; 3533: 3534: spin_lock(&kgsl_dmabuf_lock); 3535: list_for_each_entry(scan_meta, &dle->dmabuf_list, node) { 3536: scan_mem_entry = scan_meta->entry; 3537: 3538: switch (kgsl_memdesc_get_memtype(&scan_mem_entry->memdesc)) { 3539: case KGSL_MEMTYPE_EGL_SURFACE: 3540: case KGSL_MEMTYPE_SURFACE: 3541: (*egl_surface_count)++; 3542: break; 3543: case KGSL_MEMTYPE_EGL_IMAGE: 3544: (*egl_image_count)++; 3545: break; 3546: } 3547: } 3548: spin_unlock(&kgsl_dmabuf_lock); 3549: } 3550: 3551: unsigned long kgsl_get_dmabuf_inode_number(struct kgsl_mem_entry *entry) 3552: { 3553: struct kgsl_dma_buf_meta *metadata = entry->priv_data; 3554: 3555: return metadata ? file_inode(metadata->dmabuf->file)->i_ino : 0; 3556: } 3557: #else 3558: void kgsl_get_egl_counts(struct kgsl_mem_entry *entry, 3559: int *egl_surface_count, int *egl_image_count) 3560: { 3561: } 3562: MATCH LINES: 3620, 3642, 3643, 3644, 3645, 3646, 3647, 3650, 3658, 3659, 3665, 3677, 3679, 3680, 3696, 3718, 3721, 3723, 3742, 3743, 3744 3608: * determined by type of allocation being mapped. 3609: */ 3610: flags = param->flags & (KGSL_MEMFLAGS_GPUREADONLY 3611: | KGSL_MEMTYPE_MASK 3612: | KGSL_MEMALIGN_MASK 3613: | KGSL_MEMFLAGS_USE_CPU_MAP 3614: | KGSL_MEMFLAGS_SECURE 3615: | KGSL_MEMFLAGS_IOCOHERENT); 3616: 3617: if (is_compat_task()) 3618: flags |= KGSL_MEMFLAGS_FORCE_32BIT; 3619: 3620: kgsl_memdesc_init(device, &entry->memdesc, flags); 3621: 3622: switch (memtype) { 3623: case KGSL_MEM_ENTRY_USER: 3624: result = _map_usermem_addr(device, private->pagetable, 3625: entry, param->hostptr, param->offset, param->len); 3626: break; 3627: case KGSL_MEM_ENTRY_ION: 3628: if (param->offset != 0) 3629: result = -EINVAL; 3630: else 3631: result = _map_usermem_dma_buf(device, 3632: private->pagetable, entry, param->fd); 3633: break; 3634: default: 3635: result = -EOPNOTSUPP; 3636: break; 3637: } 3638: 3639: if (result) 3640: goto error; 3641: 3642: if (entry->memdesc.size >= SZ_2M) 3643: kgsl_memdesc_set_align(&entry->memdesc, ilog2(SZ_2M)); 3644: else if (entry->memdesc.size >= SZ_1M) 3645: kgsl_memdesc_set_align(&entry->memdesc, ilog2(SZ_1M)); 3646: else if (entry->memdesc.size >= SZ_64K) 3647: kgsl_memdesc_set_align(&entry->memdesc, ilog2(SZ_64)); 3648: 3649: /* echo back flags */ 3650: param->flags = (unsigned int) entry->memdesc.flags; 3651: 3652: result = kgsl_mem_entry_attach_and_map(device, private, 3653: entry); 3654: if (result) 3655: goto error_attach; 3656: 3657: /* Adjust the returned value for a non 4k aligned offset */ 3658: param->gpuaddr = (unsigned long) 3659: entry->memdesc.gpuaddr + (param->offset & PAGE_MASK); 3660: 3661: KGSL_STATS_ADD(param->len, &kgsl_driver.stats.mapped, 3662: &kgsl_driver.stats.mapped_max); 3663: 3664: kgsl_process_add_stats(private, 3665: kgsl_memdesc_usermem_type(&entry->memdesc), param->len); 3666: 3667: trace_kgsl_mem_map(entry, param->fd); 3668: 3669: kgsl_mem_entry_commit_process(entry); 3670: 3671: /* Put the extra ref from kgsl_mem_entry_create() */ 3672: kgsl_mem_entry_put(entry); 3673: 3674: return result; 3675: 3676: error_attach: 3677: kgsl_sharedmem_free(&entry->memdesc); 3678: error: 3679: /* Clear gpuaddr here so userspace doesn't get any wrong ideas */ 3680: param->gpuaddr = 0; 3681: 3682: kfree(entry); 3683: return result; 3684: } 3685: 3686: static int _kgsl_gpumem_sync_cache(struct kgsl_mem_entry *entry, 3687: uint64_t offset, uint64_t length, unsigned int op) 3688: { 3689: int ret = 0; 3690: int cacheop; 3691: 3692: if (!entry) 3693: return 0; 3694: 3695: /* Cache ops are not allowed on secure memory */ 3696: if (entry->memdesc.flags & KGSL_MEMFLAGS_SECURE) 3697: return 0; 3698: 3699: /* 3700: * Flush is defined as (clean | invalidate). If both bits are set, then 3701: * do a flush, otherwise check for the individual bits and clean or inv 3702: * as requested 3703: */ 3704: 3705: if ((op & KGSL_GPUMEM_CACHE_FLUSH) == KGSL_GPUMEM_CACHE_FLUSH) 3706: cacheop = KGSL_CACHE_OP_FLUSH; 3707: else if (op & KGSL_GPUMEM_CACHE_CLEAN) 3708: cacheop = KGSL_CACHE_OP_CLEAN; 3709: else if (op & KGSL_GPUMEM_CACHE_INV) 3710: cacheop = KGSL_CACHE_OP_INV; 3711: else { 3712: ret = -EINVAL; 3713: goto done; 3714: } 3715: 3716: if (!(op & KGSL_GPUMEM_CACHE_RANGE)) { 3717: offset = 0; 3718: length = entry->memdesc.size; 3719: } 3720: 3721: if (kgsl_cachemode_is_cached(entry->memdesc.flags)) { 3722: trace_kgsl_mem_sync_cache(entry, offset, length, op); 3723: ret = kgsl_cache_range_op(&entry->memdesc, offset, 3724: length, cacheop); 3725: } 3726: 3727: done: 3728: return ret; 3729: } 3730: 3731: /* New cache sync function - supports both directions (clean and invalidate) */ 3732: 3733: long kgsl_ioctl_gpumem_sync_cache(struct kgsl_device_private *dev_priv, 3734: unsigned int cmd, void *data) 3735: { 3736: struct kgsl_gpumem_sync_cache *param = data; 3737: struct kgsl_process_private *private = dev_priv->process_priv; 3738: struct kgsl_mem_entry *entry = NULL; 3739: long ret; 3740: 3741: if (param->id != 0) 3742: entry = kgsl_sharedmem_find_id(private, param->id); 3743: else if (param->gpuaddr != 0) 3744: entry = kgsl_sharedmem_find(private, (uint64_t) param->gpuaddr); 3745: 3746: if (entry == NULL) 3747: return -EINVAL; 3748: 3749: ret = _kgsl_gpumem_sync_cache(entry, (uint64_t) param->offset, 3750: (uint64_t) param->length, param->op); 3751: kgsl_mem_entry_put(entry); 3752: return ret; 3753: } 3754: 3755: static int mem_id_cmp(const void *_a, const void *_b) 3756: { 3757: const unsigned int *a = _a, *b = _b; 3758: 3759: if (*a == *b) 3760: return 0; 3761: return (*a > *b) ? 1 : -1; 3762: } 3763: 3764: #ifdef CONFIG_ARM64 3765: /* Do not support full flush on ARM64 targets */ 3766: static inline bool check_full_flush(size_t size, int op) 3767: { 3768: return false; MATCH LINES: 3827, 3832, 3839, 3856, 3868, 3871, 3876, 3880 3815: /* sort the ids so we can weed out duplicates */ 3816: sort(id_list, param->count, sizeof(*id_list), mem_id_cmp, NULL); 3817: 3818: for (i = 0; i < param->count; i++) { 3819: unsigned int cachemode; 3820: struct kgsl_mem_entry *entry = NULL; 3821: 3822: id = id_list[i]; 3823: /* skip 0 ids or duplicates */ 3824: if (id == last_id) 3825: continue; 3826: 3827: entry = kgsl_sharedmem_find_id(private, id); 3828: if (entry == NULL) 3829: continue; 3830: 3831: /* skip uncached memory */ 3832: cachemode = kgsl_memdesc_get_cachemode(&entry->memdesc); 3833: if (cachemode != KGSL_CACHEMODE_WRITETHROUGH && 3834: cachemode != KGSL_CACHEMODE_WRITEBACK) { 3835: kgsl_mem_entry_put(entry); 3836: continue; 3837: } 3838: 3839: op_size += entry->memdesc.size; 3840: entries[actual_count++] = entry; 3841: 3842: full_flush = check_full_flush(op_size, param->op); 3843: if (full_flush) { 3844: trace_kgsl_mem_sync_full_cache(actual_count, op_size); 3845: break; 3846: } 3847: 3848: last_id = id; 3849: } 3850: 3851: param->op &= ~KGSL_GPUMEM_CACHE_RANGE; 3852: 3853: for (i = 0; i < actual_count; i++) { 3854: if (!full_flush) 3855: _kgsl_gpumem_sync_cache(entries[i], 0, 3856: entries[i]->memdesc.size, 3857: param->op); 3858: kgsl_mem_entry_put(entries[i]); 3859: } 3860: end: 3861: kfree(entries); 3862: kfree(id_list); 3863: return ret; 3864: } 3865: 3866: /* Legacy cache function, does a flush (clean + invalidate) */ 3867: 3868: long kgsl_ioctl_sharedmem_flush_cache(struct kgsl_device_private *dev_priv, 3869: unsigned int cmd, void *data) 3870: { 3871: struct kgsl_sharedmem_free *param = data; 3872: struct kgsl_process_private *private = dev_priv->process_priv; 3873: struct kgsl_mem_entry *entry = NULL; 3874: long ret; 3875: 3876: entry = kgsl_sharedmem_find(private, (uint64_t) param->gpuaddr); 3877: if (entry == NULL) 3878: return -EINVAL; 3879: 3880: ret = _kgsl_gpumem_sync_cache(entry, 0, entry->memdesc.size, 3881: KGSL_GPUMEM_CACHE_FLUSH); 3882: kgsl_mem_entry_put(entry); 3883: return ret; 3884: } 3885: 3886: long kgsl_ioctl_gpuobj_sync(struct kgsl_device_private *dev_priv, 3887: unsigned int cmd, void *data) 3888: { 3889: struct kgsl_process_private *private = dev_priv->process_priv; 3890: struct kgsl_gpuobj_sync *param = data; 3891: struct kgsl_gpuobj_sync_obj *objs; 3892: struct kgsl_mem_entry **entries; 3893: long ret = 0; 3894: uint64_t size = 0; 3895: int i; 3896: void __user *ptr; 3897: 3898: if (param->count == 0 || param->count > 128) 3899: return -EINVAL; 3900: 3901: objs = kcalloc(param->count, sizeof(*objs), GFP_KERNEL); 3902: if (objs == NULL) 3903: return -ENOMEM; 3904: MATCH LINES: 3919, 3926, 3927, 3928 3907: kfree(objs); 3908: return -ENOMEM; 3909: } 3910: 3911: ptr = u64_to_user_ptr(param->objs); 3912: 3913: for (i = 0; i < param->count; i++) { 3914: ret = copy_struct_from_user(&objs[i], sizeof(*objs), ptr, 3915: param->obj_len); 3916: if (ret) 3917: goto out; 3918: 3919: entries[i] = kgsl_sharedmem_find_id(private, objs[i].id); 3920: 3921: /* Not finding the ID is not a fatal failure - just skip it */ 3922: if (entries[i] == NULL) 3923: continue; 3924: 3925: if (!(objs[i].op & KGSL_GPUMEM_CACHE_RANGE)) 3926: size += entries[i]->memdesc.size; 3927: else if (objs[i].offset < entries[i]->memdesc.size) 3928: size += (entries[i]->memdesc.size - objs[i].offset); 3929: 3930: if (check_full_flush(size, objs[i].op)) { 3931: trace_kgsl_mem_sync_full_cache(i, size); 3932: goto out; 3933: } 3934: 3935: ptr += sizeof(*objs); 3936: } 3937: 3938: for (i = 0; !ret && i < param->count; i++) 3939: ret = _kgsl_gpumem_sync_cache(entries[i], 3940: objs[i].offset, objs[i].length, objs[i].op); 3941: 3942: out: 3943: for (i = 0; i < param->count; i++) 3944: kgsl_mem_entry_put(entries[i]); 3945: 3946: kfree(entries); 3947: kfree(objs); 3948: 3949: return ret; 3950: } 3951: 3952: static int kgsl_update_fault_details(struct kgsl_context *context, MATCH LINES: 4202, 4237, 4239, 4246, 4254, 4255, 4264 4190: if (flags & KGSL_MEMFLAGS_FORCE_32BIT) 4191: return pt->compat_va_end - pt->compat_va_start; 4192: 4193: return pt->va_end - pt->va_start; 4194: } 4195: 4196: static struct kgsl_mem_entry * 4197: gpumem_alloc_vbo_entry(struct kgsl_device_private *dev_priv, 4198: u64 size, u64 flags) 4199: { 4200: struct kgsl_process_private *private = dev_priv->process_priv; 4201: struct kgsl_device *device = dev_priv->device; 4202: struct kgsl_memdesc *memdesc; 4203: struct kgsl_mem_entry *entry; 4204: struct kgsl_pagetable *pt; 4205: int ret; 4206: 4207: /* Disallow specific flags */ 4208: if (flags & (KGSL_MEMFLAGS_GPUREADONLY | KGSL_CACHEMODE_MASK)) 4209: return ERR_PTR(-EINVAL); 4210: 4211: if (flags & (KGSL_MEMFLAGS_USE_CPU_MAP | KGSL_MEMFLAGS_IOCOHERENT)) 4212: return ERR_PTR(-EINVAL); 4213: 4214: /* Quietly ignore the other flags that aren't this list */ 4215: flags &= KGSL_MEMFLAGS_SECURE | 4216: KGSL_MEMFLAGS_VBO | 4217: KGSL_MEMFLAGS_VBO_NO_MAP_ZERO | 4218: KGSL_MEMTYPE_MASK | 4219: KGSL_MEMALIGN_MASK | 4220: KGSL_MEMFLAGS_FORCE_32BIT; 4221: 4222: if ((flags & KGSL_MEMFLAGS_SECURE) && !check_and_warn_secured(device)) 4223: return ERR_PTR(-EOPNOTSUPP); 4224: 4225: pt = (flags & KGSL_MEMFLAGS_SECURE) ? 4226: device->mmu.securepagetable : private->pagetable; 4227: 4228: if (!size || (size > gpumem_max_va_size(pt, flags))) 4229: return ERR_PTR(-EINVAL); 4230: 4231: flags = cap_alignment(device, flags); 4232: 4233: entry = kgsl_mem_entry_create(); 4234: if (!entry) 4235: return ERR_PTR(-ENOMEM); 4236: 4237: memdesc = &entry->memdesc; 4238: 4239: ret = kgsl_sharedmem_allocate_vbo(device, memdesc, size, flags); 4240: if (ret) { 4241: kfree(entry); 4242: return ERR_PTR(ret); 4243: } 4244: 4245: if (flags & KGSL_MEMFLAGS_SECURE) 4246: SET_FLAG(KGSL_MEMDESC_SECURE, &entry->memdesc.priv); 4247: 4248: ret = kgsl_mem_entry_attach_to_process(device, private, entry); 4249: if (ret) 4250: goto out; 4251: 4252: /* Map the zero page unless explicitly asked not to */ 4253: if (!(flags & KGSL_MEMFLAGS_VBO_NO_MAP_ZERO)) 4254: ret = kgsl_mmu_map_zero_page_to_range(memdesc->pagetable, 4255: memdesc, 0, memdesc->size); 4256: 4257: if (!ret) { 4258: trace_kgsl_mem_alloc(entry); 4259: kgsl_mem_entry_commit_process(entry); 4260: return entry; 4261: } 4262: 4263: out: 4264: kgsl_sharedmem_free(memdesc); 4265: kfree(entry); 4266: return ERR_PTR(ret); 4267: } 4268: 4269: struct kgsl_mem_entry *gpumem_alloc_entry( 4270: struct kgsl_device_private *dev_priv, 4271: uint64_t size, uint64_t flags) 4272: { 4273: int ret; 4274: struct kgsl_process_private *private = dev_priv->process_priv; 4275: struct kgsl_mem_entry *entry; 4276: struct kgsl_device *device = dev_priv->device; 4277: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4278: u32 cachemode; 4279: 4280: /* For 32-bit kernel world nothing to do with this flag */ 4281: if (BITS_PER_LONG == 32) 4282: flags &= ~((uint64_t) KGSL_MEMFLAGS_FORCE_32BIT); 4283: 4284: if (flags & KGSL_MEMFLAGS_VBO) 4285: return gpumem_alloc_vbo_entry(dev_priv, size, flags); 4286: 4287: flags &= KGSL_MEMFLAGS_GPUREADONLY 4288: | KGSL_CACHEMODE_MASK MATCH LINES: 4325, 4332, 4336, 4349, 4352, 4353 4313: flags |= FIELD_PREP(KGSL_CACHEMODE_MASK, KGSL_CACHEMODE_WRITEBACK); 4314: 4315: flags = kgsl_filter_cachemode(flags); 4316: 4317: entry = kgsl_mem_entry_create(); 4318: if (entry == NULL) 4319: return ERR_PTR(-ENOMEM); 4320: 4321: if (IS_ENABLED(CONFIG_QCOM_KGSL_IOCOHERENCY_DEFAULT) && 4322: kgsl_cachemode_is_cached(flags)) 4323: flags |= KGSL_MEMFLAGS_IOCOHERENT; 4324: 4325: ret = kgsl_allocate_user(device, &entry->memdesc, 4326: size, flags, 0); 4327: if (ret != 0) 4328: goto err; 4329: 4330: ret = kgsl_mem_entry_attach_and_map(device, private, entry); 4331: if (ret != 0) { 4332: kgsl_sharedmem_free(&entry->memdesc); 4333: goto err; 4334: } 4335: 4336: cachemode = kgsl_memdesc_get_cachemode(&entry->memdesc); 4337: /* 4338: * Secure buffers cannot be reclaimed. For IO-COHERENT devices cached 4339: * buffers can safely reclaimed. But avoid reclaim cached buffers of 4340: * non IO-COHERENT devices as we could get request for cache operations 4341: * on these buffers when they are reclaimed. 4342: */ 4343: if (!(flags & KGSL_MEMFLAGS_SECURE) && 4344: (((flags & KGSL_MEMFLAGS_IOCOHERENT) && 4345: !(cachemode == KGSL_CACHEMODE_WRITETHROUGH)) || 4346: (!(flags & KGSL_MEMFLAGS_IOCOHERENT) && 4347: !(cachemode == KGSL_CACHEMODE_WRITEBACK) && 4348: !(cachemode == KGSL_CACHEMODE_WRITETHROUGH)))) 4349: SET_FLAG(KGSL_MEMDESC_CAN_RECLAIM, &entry->memdesc.priv); 4350: 4351: kgsl_process_add_stats(private, 4352: kgsl_memdesc_usermem_type(&entry->memdesc), 4353: entry->memdesc.size); 4354: trace_kgsl_mem_alloc(entry); 4355: 4356: kgsl_mem_entry_commit_process(entry); 4357: return entry; 4358: err: 4359: kfree(entry); 4360: return ERR_PTR(ret); 4361: } 4362: 4363: static void copy_metadata(struct kgsl_mem_entry *entry, uint64_t metadata, 4364: unsigned int len) 4365: { 4366: unsigned int i, size; 4367: 4368: if (len == 0) 4369: return; 4370: 4371: size = min_t(unsigned int, len, sizeof(entry->metadata) - 1); 4372: 4373: if (copy_from_user(entry->metadata, u64_to_user_ptr(metadata), size)) { 4374: memset(entry->metadata, 0, sizeof(entry->metadata)); 4375: return; 4376: } 4377: MATCH LINES: 4398, 4399, 4400, 4427, 4428, 4429, 4453, 4454, 4455, 4456, 4473, 4474, 4475, 4485, 4488, 4490, 4491, 4492, 4514, 4519, 4520, 4521, 4524, 4527, 4551, 4560, 4561 4386: unsigned int cmd, void *data) 4387: { 4388: struct kgsl_gpuobj_alloc *param = data; 4389: struct kgsl_mem_entry *entry; 4390: 4391: entry = gpumem_alloc_entry(dev_priv, param->size, param->flags); 4392: 4393: if (IS_ERR(entry)) 4394: return PTR_ERR(entry); 4395: 4396: copy_metadata(entry, param->metadata, param->metadata_len); 4397: 4398: param->size = entry->memdesc.size; 4399: param->flags = entry->memdesc.flags; 4400: param->mmapsize = kgsl_memdesc_footprint(&entry->memdesc); 4401: param->id = entry->id; 4402: 4403: /* Put the extra ref from kgsl_mem_entry_create() */ 4404: kgsl_mem_entry_put(entry); 4405: 4406: return 0; 4407: } 4408: 4409: long kgsl_ioctl_gpumem_alloc(struct kgsl_device_private *dev_priv, 4410: unsigned int cmd, void *data) 4411: { 4412: struct kgsl_gpumem_alloc *param = data; 4413: struct kgsl_mem_entry *entry; 4414: uint64_t flags = param->flags; 4415: 4416: /* Legacy functions doesn't support these advanced features */ 4417: flags &= ~((uint64_t) KGSL_MEMFLAGS_USE_CPU_MAP); 4418: 4419: if (is_compat_task()) 4420: flags |= KGSL_MEMFLAGS_FORCE_32BIT; 4421: 4422: entry = gpumem_alloc_entry(dev_priv, (uint64_t) param->size, flags); 4423: 4424: if (IS_ERR(entry)) 4425: return PTR_ERR(entry); 4426: 4427: param->gpuaddr = (unsigned long) entry->memdesc.gpuaddr; 4428: param->size = (size_t) entry->memdesc.size; 4429: param->flags = (unsigned int) entry->memdesc.flags; 4430: 4431: /* Put the extra ref from kgsl_mem_entry_create() */ 4432: kgsl_mem_entry_put(entry); 4433: 4434: return 0; 4435: } 4436: 4437: long kgsl_ioctl_gpumem_alloc_id(struct kgsl_device_private *dev_priv, 4438: unsigned int cmd, void *data) 4439: { 4440: struct kgsl_gpumem_alloc_id *param = data; 4441: struct kgsl_mem_entry *entry; 4442: uint64_t flags = param->flags; 4443: 4444: if (is_compat_task()) 4445: flags |= KGSL_MEMFLAGS_FORCE_32BIT; 4446: 4447: entry = gpumem_alloc_entry(dev_priv, (uint64_t) param->size, flags); 4448: 4449: if (IS_ERR(entry)) 4450: return PTR_ERR(entry); 4451: 4452: param->id = entry->id; 4453: param->flags = (unsigned int) entry->memdesc.flags; 4454: param->size = (size_t) entry->memdesc.size; 4455: param->mmapsize = (size_t) kgsl_memdesc_footprint(&entry->memdesc); 4456: param->gpuaddr = (unsigned long) entry->memdesc.gpuaddr; 4457: 4458: /* Put the extra ref from kgsl_mem_entry_create() */ 4459: kgsl_mem_entry_put(entry); 4460: 4461: return 0; 4462: } 4463: 4464: long kgsl_ioctl_gpumem_get_info(struct kgsl_device_private *dev_priv, 4465: unsigned int cmd, void *data) 4466: { 4467: struct kgsl_process_private *private = dev_priv->process_priv; 4468: struct kgsl_gpumem_get_info *param = data; 4469: struct kgsl_mem_entry *entry = NULL; 4470: int result = 0; 4471: 4472: if (param->id != 0) 4473: entry = kgsl_sharedmem_find_id(private, param->id); 4474: else if (param->gpuaddr != 0) 4475: entry = kgsl_sharedmem_find(private, (uint64_t) param->gpuaddr); 4476: 4477: if (entry == NULL) 4478: return -EINVAL; 4479: 4480: /* 4481: * If any of the 64 bit address / sizes would end up being 4482: * truncated, return -ERANGE. That will signal the user that they 4483: * should use a more modern API 4484: */ 4485: if (entry->memdesc.gpuaddr > ULONG_MAX) 4486: result = -ERANGE; 4487: 4488: param->gpuaddr = (unsigned long) entry->memdesc.gpuaddr; 4489: param->id = entry->id; 4490: param->flags = (unsigned int) entry->memdesc.flags; 4491: param->size = (size_t) entry->memdesc.size; 4492: param->mmapsize = (size_t) kgsl_memdesc_footprint(&entry->memdesc); 4493: /* 4494: * Entries can have multiple user mappings so thre isn't any one address 4495: * we can report. Plus, the user should already know their mappings, so 4496: * there isn't any value in reporting it back to them. 4497: */ 4498: param->useraddr = 0; 4499: 4500: kgsl_mem_entry_put(entry); 4501: return result; 4502: } 4503: 4504: long kgsl_ioctl_gpuobj_info(struct kgsl_device_private *dev_priv, 4505: unsigned int cmd, void *data) 4506: { 4507: struct kgsl_process_private *private = dev_priv->process_priv; 4508: struct kgsl_gpuobj_info *param = data; 4509: struct kgsl_mem_entry *entry; 4510: 4511: if (param->id == 0) 4512: return -EINVAL; 4513: 4514: entry = kgsl_sharedmem_find_id(private, param->id); 4515: if (entry == NULL) 4516: return -EINVAL; 4517: 4518: param->id = entry->id; 4519: param->gpuaddr = entry->memdesc.gpuaddr; 4520: param->flags = entry->memdesc.flags; 4521: param->size = entry->memdesc.size; 4522: 4523: /* VBOs cannot be mapped, so don't report a va_len */ 4524: if (entry->memdesc.flags & KGSL_MEMFLAGS_VBO) 4525: param->va_len = 0; 4526: else 4527: param->va_len = kgsl_memdesc_footprint(&entry->memdesc); 4528: 4529: /* 4530: * Entries can have multiple user mappings so thre isn't any one address 4531: * we can report. Plus, the user should already know their mappings, so 4532: * there isn't any value in reporting it back to them. 4533: */ 4534: param->va_addr = 0; 4535: 4536: kgsl_mem_entry_put(entry); 4537: return 0; 4538: } 4539: 4540: long kgsl_ioctl_gpuobj_set_info(struct kgsl_device_private *dev_priv, 4541: unsigned int cmd, void *data) 4542: { 4543: struct kgsl_process_private *private = dev_priv->process_priv; 4544: struct kgsl_gpuobj_set_info *param = data; 4545: struct kgsl_mem_entry *entry; 4546: int ret = 0; 4547: 4548: if (param->id == 0) 4549: return -EINVAL; 4550: 4551: entry = kgsl_sharedmem_find_id(private, param->id); 4552: if (entry == NULL) 4553: return -EINVAL; 4554: 4555: if (param->flags & KGSL_GPUOBJ_SET_INFO_METADATA) 4556: copy_metadata(entry, param->metadata, param->metadata_len); 4557: 4558: if (param->flags & KGSL_GPUOBJ_SET_INFO_TYPE) { 4559: if (FIELD_FIT(KGSL_MEMTYPE_MASK, param->type)) { 4560: entry->memdesc.flags &= ~((uint64_t) KGSL_MEMTYPE_MASK); 4561: entry->memdesc.flags |= 4562: FIELD_PREP(KGSL_MEMTYPE_MASK, param->type); 4563: } else 4564: ret = -EINVAL; 4565: } 4566: 4567: kgsl_mem_entry_put(entry); 4568: return ret; 4569: } 4570: 4571: /** 4572: * kgsl_ioctl_timestamp_event - Register a new timestamp event from userspace 4573: * @dev_priv - pointer to the private device structure 4574: * @cmd - the ioctl cmd passed from kgsl_ioctl 4575: * @data - the user data buffer from kgsl_ioctl 4576: * @returns 0 on success or error code on failure 4577: */ 4578: 4579: long kgsl_ioctl_timestamp_event(struct kgsl_device_private *dev_priv, 4580: unsigned int cmd, void *data) 4581: { 4582: struct kgsl_timestamp_event *param = data; 4583: int ret; 4584: 4585: switch (param->type) { MATCH LINES: 4601, 4603, 4632, 4642, 4648, 4649, 4680, 4683, 4695, 4699, 4718, 4720, 4725, 4726, 4727, 4733, 4738, 4739, 4743, 4744, 4767, 4770, 4772, 4773, 4781, 4785, 4786, 4788, 4790, 4792, 4796, 4797, 4802, 4804 4589: param->len, dev_priv); 4590: break; 4591: default: 4592: ret = -EINVAL; 4593: } 4594: 4595: return ret; 4596: } 4597: 4598: static vm_fault_t 4599: kgsl_memstore_vm_fault(struct vm_fault *vmf) 4600: { 4601: struct kgsl_memdesc *memdesc = vmf->vma->vm_private_data; 4602: 4603: return memdesc->ops->vmfault(memdesc, vmf->vma, vmf); 4604: } 4605: 4606: static const struct vm_operations_struct kgsl_memstore_vm_ops = { 4607: .fault = kgsl_memstore_vm_fault, 4608: }; 4609: 4610: static inline void kgsl_vm_flags_clear(struct vm_area_struct *vma, vm_flags_t flags) 4611: { 4612: #if (KERNEL_VERSION(6, 1, 25) <= LINUX_VERSION_CODE) 4613: vm_flags_clear(vma, flags); 4614: #else 4615: vma->vm_flags &= ~flags; 4616: #endif 4617: } 4618: 4619: static inline void kgsl_vm_flags_set(struct vm_area_struct *vma, vm_flags_t flags) 4620: { 4621: #if (KERNEL_VERSION(6, 1, 25) <= LINUX_VERSION_CODE) 4622: vm_flags_set(vma, flags); 4623: #else 4624: vma->vm_flags |= flags; 4625: #endif 4626: } 4627: 4628: static int 4629: kgsl_mmap_memstore(struct file *file, struct kgsl_device *device, 4630: struct vm_area_struct *vma) 4631: { 4632: struct kgsl_memdesc *memdesc = device->memstore; 4633: unsigned int vma_size = vma->vm_end - vma->vm_start; 4634: 4635: /* The memstore can only be mapped as read only */ 4636: 4637: if (vma->vm_flags & VM_WRITE) 4638: return -EPERM; 4639: 4640: kgsl_vm_flags_clear(vma, VM_MAYWRITE); 4641: 4642: if (memdesc->size != vma_size) { 4643: dev_err(device->dev, "Cannot partially map the memstore\n"); 4644: return -EINVAL; 4645: } 4646: 4647: vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); 4648: vma->vm_private_data = memdesc; 4649: kgsl_vm_flags_set(vma, memdesc->ops->vmflags); 4650: vma->vm_ops = &kgsl_memstore_vm_ops; 4651: vma->vm_file = file; 4652: 4653: return 0; 4654: } 4655: 4656: /* 4657: * kgsl_gpumem_vm_open is called whenever a vma region is copied or split. 4658: * Increase the refcount to make sure that the accounting stays correct 4659: */ 4660: 4661: static void kgsl_gpumem_vm_open(struct vm_area_struct *vma) 4662: { 4663: struct kgsl_mem_entry *entry = vma->vm_private_data; 4664: 4665: if (!kgsl_mem_entry_get(entry)) { 4666: vma->vm_private_data = NULL; 4667: return; 4668: } 4669: 4670: atomic_inc(&entry->map_count); 4671: } 4672: 4673: static vm_fault_t 4674: kgsl_gpumem_vm_fault(struct vm_fault *vmf) 4675: { 4676: struct kgsl_mem_entry *entry = vmf->vma->vm_private_data; 4677: 4678: if (!entry) 4679: return VM_FAULT_SIGBUS; 4680: if (!entry->memdesc.ops || !entry->memdesc.ops->vmfault) 4681: return VM_FAULT_SIGBUS; 4682: 4683: return entry->memdesc.ops->vmfault(&entry->memdesc, vmf->vma, vmf); 4684: } 4685: 4686: static void 4687: kgsl_gpumem_vm_close(struct vm_area_struct *vma) 4688: { 4689: struct kgsl_mem_entry *entry = vma->vm_private_data; 4690: 4691: if (!entry) 4692: return; 4693: 4694: /* 4695: * Remove the memdesc from the mapped stat once all the mappings have 4696: * gone away 4697: */ 4698: if (!atomic_dec_return(&entry->map_count)) 4699: atomic64_sub(entry->memdesc.size, &entry->priv->gpumem_mapped); 4700: 4701: kgsl_mem_entry_put(entry); 4702: } 4703: 4704: static const struct vm_operations_struct kgsl_gpumem_vm_ops = { 4705: .open = kgsl_gpumem_vm_open, 4706: .fault = kgsl_gpumem_vm_fault, 4707: .close = kgsl_gpumem_vm_close, 4708: }; 4709: 4710: static int 4711: get_mmap_entry(struct kgsl_process_private *private, 4712: struct kgsl_mem_entry **out_entry, unsigned long pgoff, 4713: unsigned long len) 4714: { 4715: int ret = 0; 4716: struct kgsl_mem_entry *entry; 4717: 4718: entry = kgsl_sharedmem_find_id(private, pgoff); 4719: if (entry == NULL) 4720: entry = kgsl_sharedmem_find(private, pgoff << PAGE_SHIFT); 4721: 4722: if (!entry) 4723: return -EINVAL; 4724: 4725: if (!entry->memdesc.ops || 4726: !entry->memdesc.ops->vmflags || 4727: !entry->memdesc.ops->vmfault) { 4728: ret = -EINVAL; 4729: goto err_put; 4730: } 4731: 4732: /* Don't allow ourselves to remap user memory */ 4733: if (entry->memdesc.flags & KGSL_MEMFLAGS_USERMEM_ADDR) { 4734: ret = -EBUSY; 4735: goto err_put; 4736: } 4737: 4738: if (kgsl_memdesc_use_cpu_map(&entry->memdesc)) { 4739: if (len != kgsl_memdesc_footprint(&entry->memdesc)) { 4740: ret = -ERANGE; 4741: goto err_put; 4742: } 4743: } else if (len != kgsl_memdesc_footprint(&entry->memdesc) && 4744: len != entry->memdesc.size) { 4745: /* 4746: * If cpu_map != gpumap then user can map either the 4747: * footprint or the entry size 4748: */ 4749: ret = -ERANGE; 4750: goto err_put; 4751: } 4752: 4753: *out_entry = entry; 4754: return 0; 4755: err_put: 4756: kgsl_mem_entry_put(entry); 4757: return ret; 4758: } 4759: 4760: static unsigned long _gpu_set_svm_region(struct kgsl_process_private *private, 4761: struct kgsl_mem_entry *entry, unsigned long addr, 4762: unsigned long size) 4763: { 4764: int ret; 4765: 4766: /* 4767: * Protect access to the gpuaddr here to prevent multiple vmas from 4768: * trying to map a SVM region at the same time 4769: */ 4770: spin_lock(&entry->memdesc.lock); 4771: 4772: if (entry->memdesc.gpuaddr) { 4773: spin_unlock(&entry->memdesc.lock); 4774: return (unsigned long) -EBUSY; 4775: } 4776: 4777: ret = kgsl_mmu_set_svm_region(private->pagetable, (uint64_t) addr, 4778: (uint64_t) size); 4779: 4780: if (ret != 0) { 4781: spin_unlock(&entry->memdesc.lock); 4782: return (unsigned long) ret; 4783: } 4784: 4785: entry->memdesc.gpuaddr = (uint64_t) addr; 4786: spin_unlock(&entry->memdesc.lock); 4787: 4788: entry->memdesc.pagetable = private->pagetable; 4789: 4790: ret = kgsl_mmu_map(private->pagetable, &entry->memdesc); 4791: if (ret) { 4792: kgsl_mmu_put_gpuaddr(private->pagetable, &entry->memdesc); 4793: return (unsigned long) ret; 4794: } 4795: 4796: kgsl_memfree_purge(private->pagetable, entry->memdesc.gpuaddr, 4797: entry->memdesc.size); 4798: 4799: return addr; 4800: } 4801: 4802: unsigned long kgsl_get_align(struct kgsl_memdesc *memdesc) 4803: { 4804: u32 bit = kgsl_memdesc_get_align(memdesc); 4805: 4806: if (bit >= ilog2(SZ_2M)) 4807: return SZ_2M; 4808: else if (bit >= ilog2(SZ_1M)) 4809: return SZ_1M; 4810: else if (bit >= ilog2(SZ_64K)) 4811: return SZ_64K; 4812: 4813: return PAGE_SIZE; 4814: } 4815: 4816: static unsigned long set_svm_area(struct file *file, 4817: struct kgsl_mem_entry *entry, 4818: unsigned long addr, unsigned long len, 4819: unsigned long flags) 4820: { 4821: struct kgsl_device_private *dev_priv = file->private_data; 4822: struct kgsl_process_private *private = dev_priv->process_priv; 4823: unsigned long ret; 4824: 4825: /* 4826: * Do additoinal constraints checking on the address. Passing MAP_FIXED 4827: * ensures that the address we want gets checked 4828: */ MATCH LINES: 4845, 4869 4833: return _gpu_set_svm_region(private, entry, addr, len); 4834: 4835: return ret; 4836: } 4837: 4838: static unsigned long get_svm_unmapped_area(struct file *file, 4839: struct kgsl_mem_entry *entry, 4840: unsigned long addr, unsigned long len, 4841: unsigned long flags) 4842: { 4843: struct kgsl_device_private *dev_priv = file->private_data; 4844: struct kgsl_process_private *private = dev_priv->process_priv; 4845: unsigned long align = kgsl_get_align(&entry->memdesc); 4846: unsigned long ret, iova; 4847: u64 start = 0, end = 0; 4848: struct vm_area_struct *vma; 4849: 4850: if (flags & MAP_FIXED) { 4851: /* Even fixed addresses need to obey alignment */ 4852: if (!IS_ALIGNED(addr, align)) 4853: return -EINVAL; 4854: 4855: return set_svm_area(file, entry, addr, len, flags); 4856: } 4857: 4858: /* If a hint was provided, try to use that first */ 4859: if (addr) { 4860: if (IS_ALIGNED(addr, align)) { 4861: ret = set_svm_area(file, entry, addr, len, flags); 4862: if (!IS_ERR_VALUE(ret)) 4863: return ret; 4864: } 4865: } 4866: 4867: /* Get the SVM range for the current process */ 4868: if (kgsl_mmu_svm_range(private->pagetable, &start, &end, 4869: entry->memdesc.flags)) 4870: return -ERANGE; 4871: 4872: /* Find the first gap in the iova map */ 4873: iova = kgsl_mmu_find_svm_region(private->pagetable, start, end, 4874: len, align); 4875: 4876: while (!IS_ERR_VALUE(iova)) { 4877: vma = find_vma_intersection(current->mm, iova, iova + len - 1); 4878: if (vma) { 4879: iova = vma->vm_start; 4880: } else { 4881: ret = set_svm_area(file, entry, iova, len, flags); 4882: if (!IS_ERR_VALUE(ret)) 4883: return ret; 4884: 4885: /* 4886: * set_svm_area will return -EBUSY if we tried to set up 4887: * SVM on an object that already has a GPU address. If 4888: * that happens don't bother walking the rest of the 4889: * region 4890: */ 4891: if ((long) ret == -EBUSY) 4892: return -EBUSY; 4893: MATCH LINES: 4923, 4928 4911: struct kgsl_process_private *private = dev_priv->process_priv; 4912: struct kgsl_device *device = dev_priv->device; 4913: struct kgsl_mem_entry *entry = NULL; 4914: 4915: if (vma_offset == (unsigned long) KGSL_MEMSTORE_TOKEN_ADDRESS) 4916: return kgsl_mm_get_unmapped_area(current->mm, NULL, addr, len, pgoff, flags); 4917: 4918: val = get_mmap_entry(private, &entry, pgoff, len); 4919: if (val) 4920: return val; 4921: 4922: /* Do not allow CPU mappings for secure buffers */ 4923: if (kgsl_memdesc_is_secured(&entry->memdesc)) { 4924: kgsl_mem_entry_put(entry); 4925: return (unsigned long) -EPERM; 4926: } 4927: 4928: if (!kgsl_memdesc_use_cpu_map(&entry->memdesc)) { 4929: val = kgsl_mm_get_unmapped_area(current->mm, file, addr, len, 0, flags); 4930: if (IS_ERR_VALUE(val)) 4931: dev_err_ratelimited(device->dev, 4932: "get_unmapped_area: pid %d addr %lx pgoff %lx len %ld failed error %d\n", 4933: pid_nr(private->pid), addr, pgoff, len, 4934: (int) val); 4935: } else { 4936: val = get_svm_unmapped_area(file, entry, addr, len, flags); 4937: /* if OOM, retry once after flushing lockless_workqueue */ 4938: if (val == -ENOMEM) { 4939: flush_workqueue(kgsl_driver.lockless_workqueue); 4940: val = get_svm_unmapped_area(file, entry, addr, len, flags); 4941: } 4942: if (IS_ERR_VALUE(val)) 4943: dev_err_ratelimited(device->dev, 4944: "_get_svm_area: pid %d addr %lx pgoff %lx len %ld failed error %d\n", 4945: pid_nr(private->pid), addr, pgoff, len, 4946: (int) val); 4947: } 4948: 4949: kgsl_mem_entry_put(entry); 4950: return val; 4951: } 4952: MATCH LINES: 4981, 4987, 5008, 5015, 5025, 5027, 5040 4969: if (vma_offset == (unsigned long) KGSL_MEMSTORE_TOKEN_ADDRESS) 4970: return kgsl_mmap_memstore(file, device, vma); 4971: 4972: /* 4973: * The reference count on the entry that we get from 4974: * get_mmap_entry() will be held until kgsl_gpumem_vm_close(). 4975: */ 4976: ret = get_mmap_entry(private, &entry, vma->vm_pgoff, 4977: vma->vm_end - vma->vm_start); 4978: if (ret) 4979: return ret; 4980: 4981: kgsl_vm_flags_set(vma, entry->memdesc.ops->vmflags); 4982: 4983: vma->vm_private_data = entry; 4984: 4985: /* Determine user-side caching policy */ 4986: 4987: cache = kgsl_memdesc_get_cachemode(&entry->memdesc); 4988: 4989: switch (cache) { 4990: case KGSL_CACHEMODE_WRITETHROUGH: 4991: vma->vm_page_prot = pgprot_writethroughcache(vma->vm_page_prot); 4992: if (pgprot_val(vma->vm_page_prot) == 4993: pgprot_val(pgprot_writebackcache(vma->vm_page_prot))) 4994: WARN_ONCE(1, "WRITETHROUGH is deprecated for arm64"); 4995: break; 4996: case KGSL_CACHEMODE_WRITEBACK: 4997: vma->vm_page_prot = pgprot_writebackcache(vma->vm_page_prot); 4998: break; 4999: case KGSL_CACHEMODE_UNCACHED: 5000: case KGSL_CACHEMODE_WRITECOMBINE: 5001: default: 5002: vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); 5003: break; 5004: } 5005: 5006: vma->vm_ops = &kgsl_gpumem_vm_ops; 5007: 5008: flags = entry->memdesc.flags; 5009: 5010: if (!(flags & KGSL_MEMFLAGS_IOCOHERENT) && 5011: (cache == KGSL_CACHEMODE_WRITEBACK || 5012: cache == KGSL_CACHEMODE_WRITETHROUGH)) { 5013: int i; 5014: unsigned long addr = vma->vm_start; 5015: struct kgsl_memdesc *m = &entry->memdesc; 5016: 5017: for (i = 0; i < m->page_count; i++) { 5018: struct page *page = m->pages[i]; 5019: 5020: vm_insert_page(vma, addr, page); 5021: addr += PAGE_SIZE; 5022: } 5023: } 5024: 5025: if (entry->memdesc.shmem_filp) { 5026: fput(vma->vm_file); 5027: vma->vm_file = get_file(entry->memdesc.shmem_filp); 5028: } 5029: 5030: /* 5031: * kgsl gets the entry id or the gpu address through vm_pgoff. 5032: * It is used during mmap and never needed again. But this vm_pgoff 5033: * has different meaning at other parts of kernel. Not setting to 5034: * zero will let way for wrong assumption when tried to unmap a page 5035: * from this vma. 5036: */ 5037: vma->vm_pgoff = 0; 5038: 5039: if (atomic_inc_return(&entry->map_count) == 1) 5040: atomic64_add(entry->memdesc.size, &entry->priv->gpumem_mapped); 5041: 5042: trace_kgsl_mem_mmap(entry, vma->vm_start); 5043: return 0; 5044: } 5045: 5046: #define KGSL_READ_MESSAGE "OH HAI GPU\n" 5047: 5048: static ssize_t kgsl_read(struct file *filep, char __user *buf, size_t count, 5049: loff_t *pos) 5050: { 5051: return simple_read_from_buffer(buf, count, pos, 5052: KGSL_READ_MESSAGE, strlen(KGSL_READ_MESSAGE) + 1); 5053: } 5054: 5055: static const struct file_operations kgsl_fops = { 5056: .owner = THIS_MODULE, 5057: .release = kgsl_release, 5058: .open = kgsl_open, 5059: .mmap = kgsl_mmap, 5060: .read = kgsl_read, 5061: .get_unmapped_area = kgsl_get_unmapped_area, 5062: .unlocked_ioctl = kgsl_ioctl, 5063: .compat_ioctl = kgsl_compat_ioctl, 5064: }; MATCH LINES: 5444, 5445 5432: * see if it is not NULL (and thus, has been populated). 5433: */ 5434: if (kgsl_driver.virtdev.class) 5435: device_unregister(&kgsl_driver.virtdev); 5436: 5437: if (kgsl_driver.class) { 5438: class_destroy(kgsl_driver.class); 5439: kgsl_driver.class = NULL; 5440: } 5441: 5442: kgsl_drawobjs_cache_exit(); 5443: 5444: kfree(memfree.list); 5445: memset(&memfree, 0, sizeof(memfree)); 5446: 5447: unregister_chrdev_region(kgsl_driver.major, 5448: ARRAY_SIZE(kgsl_driver.devp)); 5449: 5450: sysstats_unregister_kgsl_stats_cb(); 5451: } 5452: 5453: int __init kgsl_core_init(void) 5454: { 5455: static u64 dma_mask = (u64)DMA_BIT_MASK(64); 5456: static struct device_dma_parameters dma_parms; 5457: int result = 0; 5458: 5459: KGSL_BOOT_MARKER("KGSL Init"); 5460: 5461: /* alloc major and minor device numbers */ 5462: result = alloc_chrdev_region(&kgsl_driver.major, 0, 5463: ARRAY_SIZE(kgsl_driver.devp), "kgsl"); 5464: 5465: if (result < 0) { 5466: 5467: pr_err("kgsl: alloc_chrdev_region failed err = %d\n", result); 5468: goto err; 5469: } MATCH LINES: 5526 5514: /* Make kobjects in the virtual device for storing statistics */ 5515: 5516: kgsl_driver.ptkobj = 5517: kobject_create_and_add("pagetables", 5518: &kgsl_driver.virtdev.kobj); 5519: 5520: kgsl_driver.prockobj = 5521: kobject_create_and_add("proc", 5522: &kgsl_driver.virtdev.kobj); 5523: 5524: kgsl_core_debugfs_init(); 5525: 5526: kgsl_sharedmem_init_sysfs(); 5527: 5528: /* Initialize the memory pools */ 5529: kgsl_probe_page_pools(); 5530: 5531: kgsl_register_shmem_callback(); 5532: 5533: INIT_LIST_HEAD(&kgsl_driver.process_list); 5534: 5535: INIT_LIST_HEAD(&kgsl_driver.pagetable_list); 5536: 5537: INIT_LIST_HEAD(&kgsl_driver.wp_list); 5538: 5539: kgsl_driver.workqueue = alloc_workqueue("kgsl-workqueue", 5540: WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_SYSFS, 0); 5541: 5542: if (!kgsl_driver.workqueue) { 5543: pr_err("kgsl: Failed to allocate kgsl workqueue\n"); 5544: result = -ENOMEM; 5545: goto err; 5546: } 5547: 5548: /* 5549: * The lockless workqueue is used to perform work which doesn't need to 5550: * take the device mutex MATCH LINES: 5569 5557: result = -ENOMEM; 5558: goto err; 5559: } 5560: 5561: kgsl_eventlog_init(); 5562: 5563: kgsl_events_init(); 5564: 5565: result = kgsl_drawobjs_cache_init(); 5566: if (result) 5567: goto err; 5568: 5569: memfree.list = kcalloc(MEMFREE_ENTRIES, sizeof(struct memfree_entry), 5570: GFP_KERNEL); 5571: 5572: sysstats_register_kgsl_stats_cb(kgsl_get_stats); 5573: 5574: KGSL_BOOT_MARKER("KGSL Ready"); 5575: 5576: return 0; 5577: 5578: err: 5579: kgsl_core_exit(); 5580: return result; 5581: } --- FILE: \kgsl.h | HITS: 20 --- MATCH LINES: 20 8: 9: #include 10: #include 11: #include 12: #include 13: #include 14: #include 15: #include 16: #include 17: 18: #include "kgsl_gmu_core.h" 19: #include "kgsl_pwrscale.h" 20: #include "kgsl_sharedmem.h" 21: 22: #define KGSL_L3_DEVICE "kgsl-l3" 23: 24: #if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)) 25: #include 26: #define KGSL_BOOT_MARKER(str) place_marker("M - DRIVER " str) 27: #else 28: #define KGSL_BOOT_MARKER(str) pr_info("boot_kpi: M - DRIVER " str) 29: #endif 30: 31: /* 32: * --- kgsl drawobj flags --- 33: * These flags are same as --- drawobj flags --- 34: * but renamed to reflect that cmdbatch is renamed to drawobj. 35: */ 36: #define KGSL_DRAWOBJ_MEMLIST KGSL_CMDBATCH_MEMLIST 37: #define KGSL_DRAWOBJ_MARKER KGSL_CMDBATCH_MARKER 38: #define KGSL_DRAWOBJ_SUBMIT_IB_LIST KGSL_CMDBATCH_SUBMIT_IB_LIST 39: #define KGSL_DRAWOBJ_CTX_SWITCH KGSL_CMDBATCH_CTX_SWITCH 40: #define KGSL_DRAWOBJ_PROFILING KGSL_CMDBATCH_PROFILING 41: #define KGSL_DRAWOBJ_PROFILING_KTIME KGSL_CMDBATCH_PROFILING_KTIME 42: #define KGSL_DRAWOBJ_END_OF_FRAME KGSL_CMDBATCH_END_OF_FRAME 43: #define KGSL_DRAWOBJ_SYNC KGSL_CMDBATCH_SYNC 44: #define KGSL_DRAWOBJ_PWR_CONSTRAINT KGSL_CMDBATCH_PWR_CONSTRAINT MATCH LINES: 69, 72 57: #define KGSL_MEMSTORE_GLOBAL (0) 58: #define KGSL_PRIORITY_MAX_RB_LEVELS 4 59: #define KGSL_LPAC_RB_ID KGSL_PRIORITY_MAX_RB_LEVELS 60: /* Subtract one for LPAC */ 61: #define KGSL_MEMSTORE_MAX (KGSL_MEMSTORE_SIZE / \ 62: sizeof(struct kgsl_devmemstore) - 2 - KGSL_PRIORITY_MAX_RB_LEVELS) 63: #define KGSL_MAX_CONTEXTS_PER_PROC 200 64: 65: #define MEMSTORE_RB_OFFSET(rb, field) \ 66: KGSL_MEMSTORE_OFFSET(((rb)->id + KGSL_MEMSTORE_MAX), field) 67: 68: #define MEMSTORE_ID_GPU_ADDR(dev, iter, field) \ 69: ((dev)->memstore->gpuaddr + KGSL_MEMSTORE_OFFSET(iter, field)) 70: 71: #define MEMSTORE_RB_GPU_ADDR(dev, rb, field) \ 72: ((dev)->memstore->gpuaddr + \ 73: KGSL_MEMSTORE_OFFSET(((rb)->id + KGSL_MEMSTORE_MAX), field)) 74: 75: #define KGSL_CONTEXT_PRIORITY_HIGH 0 76: /* Last context id is reserved for global context */ 77: #define KGSL_GLOBAL_CTXT_ID (KGSL_MEMSTORE_MAX - 1) 78: 79: /* 80: * SCRATCH MEMORY: The scratch memory is one page worth of data that 81: * is mapped into the GPU. This allows for some 'shared' data between 82: * the GPU and CPU. For example, it will be used by the GPU to write 83: * each updated RPTR for each RB. 84: */ 85: 86: /* Shadow global helpers */ 87: struct adreno_rb_shadow { 88: /** @rptr: per ringbuffer address where GPU writes the rptr */ 89: u32 rptr; 90: /** @bv_rptr: per ringbuffer address where GPU writes BV rptr */ 91: u32 bv_rptr; 92: /** @bv_ts: per ringbuffer address where BV ringbuffer timestamp is written to */ 93: u32 bv_ts; 94: /** @current_rb_ptname: The current pagetable active on the given RB */ 95: u32 current_rb_ptname; 96: /** @ttbr0: value to program into TTBR0 during pagetable switch */ MATCH LINES: 127, 132 115: atomic_t frames; 116: /** @flags: Flags to accumulate GPU busy stats */ 117: unsigned long flags; 118: /** @active_cmds: The number of active cmds from application */ 119: atomic_t active_cmds; 120: /** @defer_ws: Work struct to clear gpu work period */ 121: struct work_struct defer_ws; 122: }; 123: 124: #define SCRATCH_RB_OFFSET(id, _field) ((id * sizeof(struct adreno_rb_shadow)) + \ 125: offsetof(struct adreno_rb_shadow, _field)) 126: #define SCRATCH_RB_GPU_ADDR(dev, id, _field) \ 127: ((dev)->scratch->gpuaddr + SCRATCH_RB_OFFSET(id, _field)) 128: 129: /* OFFSET to KMD postamble packets in scratch buffer */ 130: #define SCRATCH_POSTAMBLE_OFFSET (100 * sizeof(u64)) 131: #define SCRATCH_POSTAMBLE_ADDR(dev) \ 132: ((dev)->scratch->gpuaddr + SCRATCH_POSTAMBLE_OFFSET) 133: 134: /* Timestamp window used to detect rollovers (half of integer range) */ 135: #define KGSL_TIMESTAMP_WINDOW 0x80000000 136: 137: /* 138: * A macro for memory statistics - add the new size to the stat and if 139: * the statisic is greater then _max, set _max 140: */ 141: static inline void KGSL_STATS_ADD(uint64_t size, atomic_long_t *stat, 142: atomic_long_t *max) 143: { 144: uint64_t ret = atomic_long_add_return(size, stat); 145: 146: if (ret > atomic_long_read(max)) 147: atomic_long_set(max, ret); 148: } 149: 150: #define KGSL_MAX_NUMIBS 2000 151: #define KGSL_MAX_SYNCPOINTS 32 152: 153: struct kgsl_device; 154: struct kgsl_context; 155: 156: /** MATCH LINES: 221 209: /** @pool_shrinker: Pointer to a shrinker that resizes the kgsl page pools */ 210: struct shrinker *pool_shrinker; 211: /** @reclaim_shrinker: Pointer to a shrinker that reclaims kgsl memory */ 212: struct shrinker *reclaim_shrinker; 213: }; 214: 215: extern struct kgsl_driver kgsl_driver; 216: 217: struct kgsl_pagetable; 218: 219: /* 220: * List of different memory entry types. The usermem enum 221: * starts at 0, which we use for allocated memory, so 1 is 222: * added to the enum values. 223: */ 224: #define KGSL_MEM_ENTRY_KERNEL 0 225: #define KGSL_MEM_ENTRY_USER (KGSL_USER_MEM_TYPE_ADDR + 1) 226: #define KGSL_MEM_ENTRY_ION (KGSL_USER_MEM_TYPE_ION + 1) 227: #define KGSL_MEM_ENTRY_MAX (KGSL_USER_MEM_TYPE_MAX + 1) 228: 229: /* For application specific GPU work period stats */ 230: #define KGSL_WORK_PERIOD 0 231: /* GPU work period time in msec to emulate application work stats */ 232: #define KGSL_WORK_PERIOD_MS 900 233: 234: struct kgsl_device_private; 235: struct kgsl_event_group; 236: 237: typedef void (*kgsl_event_func)(struct kgsl_device *, struct kgsl_event_group *, 238: void *, int); 239: 240: /** 241: * struct kgsl_event - KGSL GPU timestamp event 242: * @device: Pointer to the KGSL device that owns the event 243: * @context: Pointer to the context that owns the event 244: * @timestamp: Timestamp for the event to expire 245: * @func: Callback function for the event when it expires MATCH LINES: 348, 356, 366 336: unsigned int cmd, void *data); 337: long kgsl_ioctl_device_setproperty(struct kgsl_device_private *dev_priv, 338: unsigned int cmd, void *data); 339: long kgsl_ioctl_device_waittimestamp_ctxtid(struct kgsl_device_private 340: *dev_priv, unsigned int cmd, void *data); 341: long kgsl_ioctl_rb_issueibcmds(struct kgsl_device_private *dev_priv, 342: unsigned int cmd, void *data); 343: long kgsl_ioctl_submit_commands(struct kgsl_device_private *dev_priv, 344: unsigned int cmd, void *data); 345: long kgsl_ioctl_cmdstream_readtimestamp_ctxtid(struct kgsl_device_private 346: *dev_priv, unsigned int cmd, 347: void *data); 348: long kgsl_ioctl_cmdstream_freememontimestamp_ctxtid( 349: struct kgsl_device_private 350: *dev_priv, unsigned int cmd, 351: void *data); 352: long kgsl_ioctl_drawctxt_create(struct kgsl_device_private *dev_priv, 353: unsigned int cmd, void *data); 354: long kgsl_ioctl_drawctxt_destroy(struct kgsl_device_private *dev_priv, 355: unsigned int cmd, void *data); 356: long kgsl_ioctl_sharedmem_free(struct kgsl_device_private *dev_priv, 357: unsigned int cmd, void *data); 358: long kgsl_ioctl_gpumem_free_id(struct kgsl_device_private *dev_priv, 359: unsigned int cmd, void *data); 360: long kgsl_ioctl_map_user_mem(struct kgsl_device_private *dev_priv, 361: unsigned int cmd, void *data); 362: long kgsl_ioctl_gpumem_sync_cache(struct kgsl_device_private *dev_priv, 363: unsigned int cmd, void *data); 364: long kgsl_ioctl_gpumem_sync_cache_bulk(struct kgsl_device_private *dev_priv, 365: unsigned int cmd, void *data); 366: long kgsl_ioctl_sharedmem_flush_cache(struct kgsl_device_private *dev_priv, 367: unsigned int cmd, void *data); 368: long kgsl_ioctl_gpumem_alloc(struct kgsl_device_private *dev_priv, 369: unsigned int cmd, void *data); 370: long kgsl_ioctl_gpumem_alloc_id(struct kgsl_device_private *dev_priv, 371: unsigned int cmd, void *data); 372: long kgsl_ioctl_gpumem_get_info(struct kgsl_device_private *dev_priv, 373: unsigned int cmd, void *data); 374: long kgsl_ioctl_timestamp_event(struct kgsl_device_private *dev_priv, 375: unsigned int cmd, void *data); 376: long kgsl_ioctl_gpuobj_alloc(struct kgsl_device_private *dev_priv, 377: unsigned int cmd, void *data); 378: long kgsl_ioctl_gpuobj_free(struct kgsl_device_private *dev_priv, 379: unsigned int cmd, void *data); 380: long kgsl_ioctl_gpuobj_info(struct kgsl_device_private *dev_priv, 381: unsigned int cmd, void *data); 382: long kgsl_ioctl_gpuobj_import(struct kgsl_device_private *dev_priv, 383: unsigned int cmd, void *data); 384: long kgsl_ioctl_gpuobj_sync(struct kgsl_device_private *dev_priv, 385: unsigned int cmd, void *data); 386: long kgsl_ioctl_gpu_command(struct kgsl_device_private *dev_priv, 387: unsigned int cmd, void *data); 388: long kgsl_ioctl_gpuobj_set_info(struct kgsl_device_private *dev_priv, 389: unsigned int cmd, void *data); 390: long kgsl_ioctl_gpumem_bind_ranges(struct kgsl_device_private *dev_priv, MATCH LINES: 420, 423, 427, 432 408: long kgsl_ioctl_recurring_command(struct kgsl_device_private *dev_priv, 409: unsigned int cmd, void *data); 410: 411: void kgsl_mem_entry_destroy(struct kref *kref); 412: void kgsl_mem_entry_destroy_deferred(struct kref *kref); 413: 414: void kgsl_get_egl_counts(struct kgsl_mem_entry *entry, 415: int *egl_surface_count, int *egl_image_count); 416: 417: unsigned long kgsl_get_dmabuf_inode_number(struct kgsl_mem_entry *entry); 418: 419: struct kgsl_mem_entry * __must_check 420: kgsl_sharedmem_find(struct kgsl_process_private *private, uint64_t gpuaddr); 421: 422: struct kgsl_mem_entry * __must_check 423: kgsl_sharedmem_find_id(struct kgsl_process_private *process, unsigned int id); 424: 425: struct kgsl_mem_entry *gpumem_alloc_entry(struct kgsl_device_private *dev_priv, 426: uint64_t size, uint64_t flags); 427: long gpumem_free_entry(struct kgsl_mem_entry *entry); 428: 429: enum kgsl_mmutype kgsl_mmu_get_mmutype(struct kgsl_device *device); 430: 431: /* Helper functions */ 432: unsigned long kgsl_get_align(struct kgsl_memdesc *memdesc); 433: 434: int kgsl_request_irq(struct platform_device *pdev, const char *name, 435: const char *alt_name, int index, irq_handler_t handler, void *data); 436: 437: int kgsl_request_irq_optional(struct platform_device *pdev, const char *name, 438: irq_handler_t handler, void *data); 439: 440: int __init kgsl_core_init(void); 441: void kgsl_core_exit(void); 442: 443: static inline int timestamp_cmp(unsigned int a, unsigned int b) 444: { 445: /* check for equal */ 446: if (a == b) 447: return 0; 448: 449: /* check for greater-than for non-rollover case */ 450: if ((a > b) && (a - b < KGSL_TIMESTAMP_WINDOW)) 451: return 1; 452: 453: /* check for greater-than for rollover case 454: * note that <= is required to ensure that consistent 455: * results are returned for values whose difference is 456: * equal to the window size MATCH LINES: 504, 506, 512, 513, 515, 517, 518 492: * 493: * Use this to put a memory entry when we don't want to block 494: * the caller while destroying memory entry. 495: */ 496: static inline void kgsl_mem_entry_put_deferred(struct kgsl_mem_entry *entry) 497: { 498: if (entry) 499: kref_put(&entry->refcount, kgsl_mem_entry_destroy_deferred); 500: } 501: 502: /* 503: * kgsl_addr_range_overlap() - Checks if 2 ranges overlap 504: * @gpuaddr1: Start of first address range 505: * @size1: Size of first address range 506: * @gpuaddr2: Start of second address range 507: * @size2: Size of second address range 508: * 509: * Function returns true if the 2 given address ranges overlap 510: * else false 511: */ 512: static inline bool kgsl_addr_range_overlap(uint64_t gpuaddr1, 513: uint64_t size1, uint64_t gpuaddr2, uint64_t size2) 514: { 515: if ((size1 > (U64_MAX - gpuaddr1)) || (size2 > (U64_MAX - gpuaddr2))) 516: return false; 517: return !(((gpuaddr1 + size1) <= gpuaddr2) || 518: (gpuaddr1 >= (gpuaddr2 + size2))); 519: } 520: 521: /** 522: * kgsl_work_period_update() - To update application work period stats 523: * @device: Pointer to the KGSL device 524: * @period: GPU work period stats 525: * @active: Command active time 526: */ 527: void kgsl_work_period_update(struct kgsl_device *device, 528: struct gpu_work_period *period, u64 active); 529: 530: /** 531: * kgsl_context_destroy_deferred() - Destroy context in a deferred manner 532: * @kref: Pointer to context refcount 533: */ 534: void kgsl_context_destroy_deferred(struct kref *kref); 535: 536: u64 kgsl_get_stats(pid_t pid); 537: #endif /* __KGSL_H */ --- FILE: \kgsl_compat.c | HITS: 31 --- MATCH LINES: 83, 88, 89, 92, 96, 100, 104, 105, 107, 109, 121, 130, 142, 166, 169, 170, 172, 174, 185, 198, 217, 232, 245, 254 71: param.flags = param32->flags; 72: param.ibdesc_addr = (unsigned long)param32->ibdesc_addr; 73: param.numibs = param32->numibs; 74: param.timestamp = param32->timestamp; 75: 76: result = kgsl_ioctl_rb_issueibcmds(dev_priv, cmd, ¶m); 77: 78: param32->timestamp = param.timestamp; 79: 80: return result; 81: } 82: 83: static long kgsl_ioctl_cmdstream_freememontimestamp_ctxtid_compat( 84: struct kgsl_device_private 85: *dev_priv, unsigned int cmd, 86: void *data) 87: { 88: struct kgsl_cmdstream_freememontimestamp_ctxtid_compat *param32 = data; 89: struct kgsl_cmdstream_freememontimestamp_ctxtid param; 90: 91: param.context_id = param32->context_id; 92: param.gpuaddr = (unsigned long)param32->gpuaddr; 93: param.type = param32->type; 94: param.timestamp = param32->timestamp; 95: 96: return kgsl_ioctl_cmdstream_freememontimestamp_ctxtid(dev_priv, cmd, 97: ¶m); 98: } 99: 100: static long kgsl_ioctl_sharedmem_free_compat(struct kgsl_device_private 101: *dev_priv, unsigned int cmd, 102: void *data) 103: { 104: struct kgsl_sharedmem_free_compat *param32 = data; 105: struct kgsl_sharedmem_free param; 106: 107: param.gpuaddr = (unsigned long)param32->gpuaddr; 108: 109: return kgsl_ioctl_sharedmem_free(dev_priv, cmd, ¶m); 110: } 111: 112: static long kgsl_ioctl_map_user_mem_compat(struct kgsl_device_private 113: *dev_priv, unsigned int cmd, 114: void *data) 115: { 116: int result = 0; 117: struct kgsl_map_user_mem_compat *param32 = data; 118: struct kgsl_map_user_mem param; 119: 120: param.fd = param32->fd; 121: param.gpuaddr = (unsigned long)param32->gpuaddr; 122: param.len = (size_t)param32->len; 123: param.offset = (size_t)param32->offset; 124: param.hostptr = (unsigned long)param32->hostptr; 125: param.memtype = param32->memtype; 126: param.flags = param32->flags; 127: 128: result = kgsl_ioctl_map_user_mem(dev_priv, cmd, ¶m); 129: 130: param32->gpuaddr = gpuaddr_to_compat(param.gpuaddr); 131: param32->flags = param.flags; 132: return result; 133: } 134: 135: static long 136: kgsl_ioctl_gpumem_sync_cache_compat(struct kgsl_device_private *dev_priv, 137: unsigned int cmd, void *data) 138: { 139: struct kgsl_gpumem_sync_cache_compat *param32 = data; 140: struct kgsl_gpumem_sync_cache param; 141: 142: param.gpuaddr = (unsigned long)param32->gpuaddr; 143: param.id = param32->id; 144: param.op = param32->op; 145: param.offset = (size_t)param32->offset; 146: param.length = (size_t)param32->length; 147: 148: return kgsl_ioctl_gpumem_sync_cache(dev_priv, cmd, ¶m); 149: } 150: 151: static long 152: kgsl_ioctl_gpumem_sync_cache_bulk_compat(struct kgsl_device_private *dev_priv, 153: unsigned int cmd, void *data) 154: { 155: struct kgsl_gpumem_sync_cache_bulk_compat *param32 = data; 156: struct kgsl_gpumem_sync_cache_bulk param; 157: 158: param.id_list = compat_ptr(param32->id_list); 159: param.count = param32->count; 160: param.op = param32->op; 161: 162: return kgsl_ioctl_gpumem_sync_cache_bulk(dev_priv, cmd, ¶m); 163: } 164: 165: static long 166: kgsl_ioctl_sharedmem_flush_cache_compat(struct kgsl_device_private *dev_priv, 167: unsigned int cmd, void *data) 168: { 169: struct kgsl_sharedmem_free_compat *param32 = data; 170: struct kgsl_sharedmem_free param; 171: 172: param.gpuaddr = (unsigned long)param32->gpuaddr; 173: 174: return kgsl_ioctl_sharedmem_flush_cache(dev_priv, cmd, ¶m); 175: } 176: 177: static long 178: kgsl_ioctl_gpumem_alloc_compat(struct kgsl_device_private *dev_priv, 179: unsigned int cmd, void *data) 180: { 181: int result = 0; 182: struct kgsl_gpumem_alloc_compat *param32 = data; 183: struct kgsl_gpumem_alloc param; 184: 185: param.gpuaddr = (unsigned long)param32->gpuaddr; 186: param.size = (size_t)param32->size; 187: param.flags = param32->flags; 188: 189: /* 190: * Since this is a 32 bit application the page aligned size is expected 191: * to fit inside of 32 bits - check for overflow and return error if so 192: */ 193: if (PAGE_ALIGN(param.size) >= UINT_MAX) 194: return -EINVAL; 195: 196: result = kgsl_ioctl_gpumem_alloc(dev_priv, cmd, ¶m); 197: 198: param32->gpuaddr = gpuaddr_to_compat(param.gpuaddr); 199: param32->size = sizet_to_compat(param.size); 200: param32->flags = param.flags; 201: 202: return result; 203: } 204: 205: static long 206: kgsl_ioctl_gpumem_alloc_id_compat(struct kgsl_device_private *dev_priv, 207: unsigned int cmd, void *data) 208: { 209: int result = 0; 210: struct kgsl_gpumem_alloc_id_compat *param32 = data; 211: struct kgsl_gpumem_alloc_id param; 212: 213: param.id = param32->id; 214: param.flags = param32->flags; 215: param.size = (size_t)param32->size; 216: param.mmapsize = (size_t)param32->mmapsize; 217: param.gpuaddr = (unsigned long)param32->gpuaddr; 218: 219: /* 220: * Since this is a 32 bit application the page aligned size is expected 221: * to fit inside of 32 bits - check for overflow and return error if so 222: */ 223: if (PAGE_ALIGN(param.size) >= UINT_MAX) 224: return -EINVAL; 225: 226: result = kgsl_ioctl_gpumem_alloc_id(dev_priv, cmd, ¶m); 227: 228: param32->id = param.id; 229: param32->flags = param.flags; 230: param32->size = sizet_to_compat(param.size); 231: param32->mmapsize = sizet_to_compat(param.mmapsize); 232: param32->gpuaddr = gpuaddr_to_compat(param.gpuaddr); 233: 234: return result; 235: } 236: 237: static long 238: kgsl_ioctl_gpumem_get_info_compat(struct kgsl_device_private *dev_priv, 239: unsigned int cmd, void *data) 240: { 241: int result = 0; 242: struct kgsl_gpumem_get_info_compat *param32 = data; 243: struct kgsl_gpumem_get_info param; 244: 245: param.gpuaddr = (unsigned long)param32->gpuaddr; 246: param.id = param32->id; 247: param.flags = param32->flags; 248: param.size = (size_t)param32->size; 249: param.mmapsize = (size_t)param32->mmapsize; 250: param.useraddr = (unsigned long)param32->useraddr; 251: 252: result = kgsl_ioctl_gpumem_get_info(dev_priv, cmd, ¶m); 253: 254: param32->gpuaddr = gpuaddr_to_compat(param.gpuaddr); 255: param32->id = param.id; 256: param32->flags = param.flags; 257: param32->size = sizet_to_compat(param.size); 258: param32->mmapsize = sizet_to_compat(param.mmapsize); 259: param32->useraddr = (compat_ulong_t)param.useraddr; 260: 261: return result; 262: } 263: 264: static long kgsl_ioctl_timestamp_event_compat(struct kgsl_device_private 265: *dev_priv, unsigned int cmd, void *data) 266: { 267: struct kgsl_timestamp_event_compat *param32 = data; 268: struct kgsl_timestamp_event param; 269: 270: param.type = param32->type; 271: param.timestamp = param32->timestamp; 272: param.context_id = param32->context_id; 273: param.priv = compat_ptr(param32->priv); 274: param.len = (size_t)param32->len; 275: 276: return kgsl_ioctl_timestamp_event(dev_priv, cmd, ¶m); 277: } 278: MATCH LINES: 293, 294, 295, 302, 303, 304, 305 281: KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_GETPROPERTY_COMPAT, 282: kgsl_ioctl_device_getproperty_compat), 283: /* IOCTL_KGSL_DEVICE_WAITTIMESTAMP is no longer supported */ 284: KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID, 285: kgsl_ioctl_device_waittimestamp_ctxtid), 286: KGSL_IOCTL_FUNC(IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS_COMPAT, 287: kgsl_ioctl_rb_issueibcmds_compat), 288: KGSL_IOCTL_FUNC(IOCTL_KGSL_SUBMIT_COMMANDS_COMPAT, 289: kgsl_ioctl_submit_commands_compat), 290: /* IOCTL_KGSL_CMDSTREAM_READTIMESTAMP is no longer supported */ 291: KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID, 292: kgsl_ioctl_cmdstream_readtimestamp_ctxtid), 293: /* IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP is no longer supported */ 294: KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID_COMPAT, 295: kgsl_ioctl_cmdstream_freememontimestamp_ctxtid_compat), 296: KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_CREATE, 297: kgsl_ioctl_drawctxt_create), 298: KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_DESTROY, 299: kgsl_ioctl_drawctxt_destroy), 300: KGSL_IOCTL_FUNC(IOCTL_KGSL_MAP_USER_MEM_COMPAT, 301: kgsl_ioctl_map_user_mem_compat), 302: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FREE_COMPAT, 303: kgsl_ioctl_sharedmem_free_compat), 304: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE_COMPAT, 305: kgsl_ioctl_sharedmem_flush_cache_compat), 306: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_ALLOC_COMPAT, 307: kgsl_ioctl_gpumem_alloc_compat), 308: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMESTAMP_EVENT_COMPAT, 309: kgsl_ioctl_timestamp_event_compat), 310: KGSL_IOCTL_FUNC(IOCTL_KGSL_SETPROPERTY_COMPAT, 311: kgsl_ioctl_device_setproperty_compat), 312: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_ALLOC_ID_COMPAT, 313: kgsl_ioctl_gpumem_alloc_id_compat), 314: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_FREE_ID, 315: kgsl_ioctl_gpumem_free_id), 316: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_GET_INFO_COMPAT, 317: kgsl_ioctl_gpumem_get_info_compat), 318: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_SYNC_CACHE_COMPAT, 319: kgsl_ioctl_gpumem_sync_cache_compat), 320: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_SYNC_CACHE_BULK_COMPAT, 321: kgsl_ioctl_gpumem_sync_cache_bulk_compat), 322: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_CREATE, 323: kgsl_ioctl_syncsource_create), 324: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_DESTROY, 325: kgsl_ioctl_syncsource_destroy), 326: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_CREATE_FENCE, 327: kgsl_ioctl_syncsource_create_fence), 328: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_SIGNAL_FENCE, 329: kgsl_ioctl_syncsource_signal_fence), --- FILE: \kgsl_compat.h | HITS: 20 --- MATCH LINES: 15, 37 3: * Copyright (c) 2013-2017,2019,2021 The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: #ifndef __KGSL_COMPAT_H 7: #define __KGSL_COMPAT_H 8: 9: #include 10: #include 11: 12: #ifdef CONFIG_COMPAT 13: 14: struct kgsl_ibdesc_compat { 15: compat_ulong_t gpuaddr; 16: unsigned int __pad; 17: compat_size_t sizedwords; 18: unsigned int ctrl; 19: }; 20: 21: struct kgsl_cmd_syncpoint_compat { 22: int type; 23: compat_uptr_t priv; 24: compat_size_t size; 25: }; 26: 27: struct kgsl_devinfo_compat { 28: unsigned int device_id; 29: unsigned int chip_id; 30: unsigned int mmu_enabled; 31: compat_ulong_t gmem_gpubaseaddr; 32: unsigned int gpu_id; 33: compat_size_t gmem_sizebytes; 34: }; 35: 36: struct kgsl_shadowprop_compat { 37: compat_ulong_t gpuaddr; 38: compat_size_t size; 39: unsigned int flags; 40: }; 41: 42: struct kgsl_device_constraint_compat { 43: unsigned int type; 44: unsigned int context_id; 45: compat_uptr_t data; 46: compat_size_t size; 47: }; 48: 49: struct kgsl_device_getproperty_compat { 50: unsigned int type; 51: compat_uptr_t value; 52: compat_size_t sizebytes; 53: }; 54: 55: #define IOCTL_KGSL_DEVICE_GETPROPERTY_COMPAT \ 56: _IOWR(KGSL_IOC_TYPE, 0x2, struct kgsl_device_getproperty_compat) 57: 58: #define IOCTL_KGSL_SETPROPERTY_COMPAT \ 59: _IOW(KGSL_IOC_TYPE, 0x32, struct kgsl_device_getproperty_compat) 60: 61: MATCH LINES: 88, 90, 95, 97, 101, 112, 113, 116, 117, 119, 120, 123, 147, 156, 170 76: 77: struct kgsl_ringbuffer_issueibcmds_compat { 78: unsigned int drawctxt_id; 79: compat_ulong_t ibdesc_addr; 80: unsigned int numibs; 81: unsigned int timestamp; /* output param */ 82: unsigned int flags; 83: }; 84: 85: #define IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS_COMPAT \ 86: _IOWR(KGSL_IOC_TYPE, 0x10, struct kgsl_ringbuffer_issueibcmds_compat) 87: 88: struct kgsl_cmdstream_freememontimestamp_ctxtid_compat { 89: unsigned int context_id; 90: compat_ulong_t gpuaddr; 91: unsigned int type; 92: unsigned int timestamp; 93: }; 94: 95: #define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID_COMPAT \ 96: _IOW(KGSL_IOC_TYPE, 0x17, \ 97: struct kgsl_cmdstream_freememontimestamp_ctxtid_compat) 98: 99: struct kgsl_map_user_mem_compat { 100: int fd; 101: compat_ulong_t gpuaddr; 102: compat_size_t len; 103: compat_size_t offset; 104: compat_ulong_t hostptr; 105: enum kgsl_user_mem_type memtype; 106: unsigned int flags; 107: }; 108: 109: #define IOCTL_KGSL_MAP_USER_MEM_COMPAT \ 110: _IOWR(KGSL_IOC_TYPE, 0x15, struct kgsl_map_user_mem_compat) 111: 112: struct kgsl_sharedmem_free_compat { 113: compat_ulong_t gpuaddr; 114: }; 115: 116: #define IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE_COMPAT \ 117: _IOW(KGSL_IOC_TYPE, 0x24, struct kgsl_sharedmem_free_compat) 118: 119: #define IOCTL_KGSL_SHAREDMEM_FREE_COMPAT \ 120: _IOW(KGSL_IOC_TYPE, 0x21, struct kgsl_sharedmem_free_compat) 121: 122: struct kgsl_gpumem_alloc_compat { 123: compat_ulong_t gpuaddr; /* output param */ 124: compat_size_t size; 125: unsigned int flags; 126: }; 127: 128: #define IOCTL_KGSL_GPUMEM_ALLOC_COMPAT \ 129: _IOWR(KGSL_IOC_TYPE, 0x2f, struct kgsl_gpumem_alloc_compat) 130: 131: struct kgsl_timestamp_event_compat { 132: int type; /* Type of event (see list below) */ 133: unsigned int timestamp; /* Timestamp to trigger event on */ 134: unsigned int context_id; /* Context for the timestamp */ 135: compat_uptr_t priv; /* Pointer to the event specific blob */ 136: compat_size_t len; /* Size of the event specific blob */ 137: }; 138: 139: #define IOCTL_KGSL_TIMESTAMP_EVENT_COMPAT \ 140: _IOWR(KGSL_IOC_TYPE, 0x33, struct kgsl_timestamp_event_compat) 141: 142: struct kgsl_gpumem_alloc_id_compat { 143: unsigned int id; 144: unsigned int flags; 145: compat_size_t size; 146: compat_size_t mmapsize; 147: compat_ulong_t gpuaddr; 148: /* private: reserved for future use*/ 149: unsigned int __pad[2]; 150: }; 151: 152: #define IOCTL_KGSL_GPUMEM_ALLOC_ID_COMPAT \ 153: _IOWR(KGSL_IOC_TYPE, 0x34, struct kgsl_gpumem_alloc_id_compat) 154: 155: struct kgsl_gpumem_get_info_compat { 156: compat_ulong_t gpuaddr; 157: unsigned int id; 158: unsigned int flags; 159: compat_size_t size; 160: compat_size_t mmapsize; 161: compat_ulong_t useraddr; 162: /* private: reserved for future use*/ 163: unsigned int __pad[4]; 164: }; 165: 166: #define IOCTL_KGSL_GPUMEM_GET_INFO_COMPAT \ 167: _IOWR(KGSL_IOC_TYPE, 0x36, struct kgsl_gpumem_get_info_compat) 168: 169: struct kgsl_gpumem_sync_cache_compat { 170: compat_ulong_t gpuaddr; 171: unsigned int id; 172: unsigned int op; 173: compat_size_t offset; 174: compat_size_t length; 175: }; 176: 177: #define IOCTL_KGSL_GPUMEM_SYNC_CACHE_COMPAT \ 178: _IOW(KGSL_IOC_TYPE, 0x37, struct kgsl_gpumem_sync_cache_compat) 179: 180: struct kgsl_gpumem_sync_cache_bulk_compat { 181: compat_uptr_t id_list; 182: unsigned int count; 183: unsigned int op; 184: /* private: reserved for future use */ 185: unsigned int __pad[2]; /* For future binary compatibility */ 186: }; 187: 188: #define IOCTL_KGSL_GPUMEM_SYNC_CACHE_BULK_COMPAT \ 189: _IOWR(KGSL_IOC_TYPE, 0x3C, struct kgsl_gpumem_sync_cache_bulk_compat) 190: 191: struct kgsl_perfcounter_query_compat { 192: unsigned int groupid; 193: compat_uptr_t countables; 194: unsigned int count; MATCH LINES: 211, 213, 214 199: #define IOCTL_KGSL_PERFCOUNTER_QUERY_COMPAT \ 200: _IOWR(KGSL_IOC_TYPE, 0x3A, struct kgsl_perfcounter_query_compat) 201: 202: struct kgsl_perfcounter_read_compat { 203: compat_uptr_t reads; 204: unsigned int count; 205: unsigned int __pad[2]; 206: }; 207: 208: #define IOCTL_KGSL_PERFCOUNTER_READ_COMPAT \ 209: _IOWR(KGSL_IOC_TYPE, 0x3B, struct kgsl_perfcounter_read_compat) 210: 211: static inline compat_ulong_t gpuaddr_to_compat(unsigned long gpuaddr) 212: { 213: WARN(gpuaddr >> 32, "Top 32 bits of gpuaddr have been set\n"); 214: return (compat_ulong_t)gpuaddr; 215: } 216: 217: static inline compat_size_t sizet_to_compat(size_t size) 218: { 219: WARN(size >> 32, "Size greater than 4G\n"); 220: return (compat_size_t)size; 221: } 222: 223: long kgsl_compat_ioctl(struct file *filep, unsigned int cmd, 224: unsigned long arg); 225: 226: #else 227: 228: static inline long kgsl_compat_ioctl(struct file *filep, unsigned int cmd, 229: unsigned long arg) 230: { 231: return -EINVAL; 232: } 233: 234: #endif /* CONFIG_COMPAT */ 235: #endif /* __KGSL_COMPAT_H */ --- FILE: \kgsl_debugfs.c | HITS: 24 --- MATCH LINES: 13 1: // SPDX-License-Identifier: GPL-2.0-only 2: /* 3: * Copyright (c) 2002,2008-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include 8: #include 9: 10: #include "kgsl_debugfs.h" 11: #include "kgsl_device.h" 12: #include "kgsl_pool.h" 13: #include "kgsl_sharedmem.h" 14: 15: struct dentry *kgsl_debugfs_dir, *mempools_debugfs; 16: static struct dentry *proc_d_debugfs; 17: 18: static void kgsl_qdss_gfx_register_probe(struct kgsl_device *device) 19: { 20: struct resource *res; 21: 22: res = platform_get_resource_byname(device->pdev, IORESOURCE_MEM, 23: "qdss_gfx"); 24: 25: if (res == NULL) 26: return; 27: 28: device->qdss_gfx_virt = devm_ioremap(&device->pdev->dev, res->start, 29: resource_size(res)); 30: 31: if (device->qdss_gfx_virt == NULL) 32: dev_warn(device->dev, "qdss_gfx ioremap failed\n"); 33: } 34: 35: static int _isdb_set(void *data, u64 val) 36: { 37: struct kgsl_device *device = data; MATCH LINES: 59, 62, 65, 66, 67, 68, 69, 73, 74, 75 47: { 48: struct kgsl_device *device = data; 49: 50: *val = device->set_isdb_breakpoint ? 1 : 0; 51: return 0; 52: } 53: 54: DEFINE_DEBUGFS_ATTRIBUTE(_isdb_fops, _isdb_get, _isdb_set, "%llu\n"); 55: 56: static int globals_show(struct seq_file *s, void *unused) 57: { 58: struct kgsl_device *device = s->private; 59: struct kgsl_global_memdesc *md; 60: 61: list_for_each_entry(md, &device->globals, node) { 62: struct kgsl_memdesc *memdesc = &md->memdesc; 63: char flags[6]; 64: 65: flags[0] = TEST_FLAG(KGSL_MEMDESC_PRIVILEGED, &memdesc->priv) ? 'p' : '-'; 66: flags[1] = !(TEST_FLAG(KGSL_MEMFLAGS_GPUREADONLY, &memdesc->priv)) ? 'w' : '-'; 67: flags[2] = kgsl_memdesc_is_secured(memdesc) ? 's' : '-'; 68: flags[3] = TEST_FLAG(KGSL_MEMDESC_RANDOM, &memdesc->priv) ? 'r' : '-'; 69: flags[4] = TEST_FLAG(KGSL_MEMDESC_UCODE, &memdesc->priv) ? 'u' : '-'; 70: flags[5] = '\0'; 71: 72: seq_printf(s, "0x%pK-0x%pK %16llu %5s %s\n", 73: (u64 *)(uintptr_t) memdesc->gpuaddr, 74: (u64 *)(uintptr_t) (memdesc->gpuaddr + 75: memdesc->size - 1), memdesc->size, flags, 76: md->name); 77: } 78: 79: return 0; 80: } 81: 82: DEFINE_SHOW_ATTRIBUTE(globals); 83: 84: static int _pool_size_get(void *data, u64 *val) 85: { 86: *val = (u64) kgsl_pool_size_total(); 87: return 0; 88: } 89: 90: DEFINE_DEBUGFS_ATTRIBUTE(_pool_size_fops, _pool_size_get, NULL, "%llu\n"); 91: 92: DEFINE_DEBUGFS_ATTRIBUTE(_reserved_fops, 93: kgsl_pool_reserved_get, NULL, "%llu\n"); 94: DEFINE_DEBUGFS_ATTRIBUTE(_page_count_fops, 95: kgsl_pool_page_count_get, NULL, "%llu\n"); 96: 97: void kgsl_pool_init_debugfs(struct dentry *pool_debugfs, 98: char *name, void *pool) 99: { MATCH LINES: 159, 161, 170, 179, 189, 190, 195, 200, 203, 217 147: static const char *memtype_str(int memtype) 148: { 149: if (memtype == KGSL_MEM_ENTRY_KERNEL) 150: return "gpumem"; 151: else if (memtype == KGSL_MEM_ENTRY_USER) 152: return "usermem"; 153: else if (memtype == KGSL_MEM_ENTRY_ION) 154: return "ion"; 155: 156: return "unknown"; 157: } 158: 159: static char get_alignflag(const struct kgsl_memdesc *m) 160: { 161: u32 align = kgsl_memdesc_get_align(m); 162: 163: if (align >= ilog2(SZ_1M)) 164: return 'L'; 165: else if (align >= ilog2(SZ_64K)) 166: return 'l'; 167: return '-'; 168: } 169: 170: static char get_cacheflag(const struct kgsl_memdesc *m) 171: { 172: static const char table[] = { 173: [KGSL_CACHEMODE_WRITECOMBINE] = '-', 174: [KGSL_CACHEMODE_UNCACHED] = 'u', 175: [KGSL_CACHEMODE_WRITEBACK] = 'b', 176: [KGSL_CACHEMODE_WRITETHROUGH] = 't', 177: }; 178: 179: return table[kgsl_memdesc_get_cachemode(m)]; 180: } 181: 182: 183: static int print_mem_entry(void *data, void *ptr) 184: { 185: struct seq_file *s = data; 186: struct kgsl_mem_entry *entry = ptr; 187: char flags[11]; 188: char usage[16]; 189: struct kgsl_memdesc *m = &entry->memdesc; 190: unsigned int usermem_type = kgsl_memdesc_usermem_type(m); 191: int egl_surface_count = 0, egl_image_count = 0; 192: unsigned long inode_number = 0; 193: u32 map_count = atomic_read(&entry->map_count); 194: 195: flags[0] = kgsl_memdesc_is_global(m) ? 'g' : '-'; 196: flags[1] = '-'; 197: flags[2] = !(m->flags & KGSL_MEMFLAGS_GPUREADONLY) ? 'w' : '-'; 198: flags[3] = get_alignflag(m); 199: flags[4] = get_cacheflag(m); 200: flags[5] = kgsl_memdesc_use_cpu_map(m) ? 'p' : '-'; 201: /* Show Y if at least one vma has this entry mapped (could be multiple) */ 202: flags[6] = map_count ? 'Y' : 'N'; 203: flags[7] = kgsl_memdesc_is_secured(m) ? 's' : '-'; 204: flags[8] = '-'; 205: flags[9] = m->flags & KGSL_MEMFLAGS_VBO ? 'v' : '-'; 206: flags[10] = '\0'; 207: 208: kgsl_get_memory_usage(usage, sizeof(usage), m->flags); 209: 210: if (usermem_type == KGSL_MEM_ENTRY_ION) { 211: kgsl_get_egl_counts(entry, &egl_surface_count, 212: &egl_image_count); 213: inode_number = kgsl_get_dmabuf_inode_number(entry); 214: } 215: 216: seq_printf(s, "%pK %pK %16llu %5d %10s %10s %16s %5d %10d %6d %6d %10lu", 217: (uint64_t *)(uintptr_t) m->gpuaddr, 218: /* 219: * Show zero for the useraddr - we can't reliably track 220: * that value for multiple vmas anyway 221: */ 222: NULL, m->size, entry->id, flags, 223: memtype_str(usermem_type), 224: usage, (m->sgt ? m->sgt->nents : 0), map_count, 225: egl_surface_count, egl_image_count, inode_number); 226: 227: if (entry->metadata[0] != 0) 228: seq_printf(s, " %s", entry->metadata); 229: 230: seq_putc(s, '\n'); 231: 232: return 0; 233: } 234: 235: static struct kgsl_mem_entry *process_mem_seq_find(struct seq_file *s, 236: void *ptr, loff_t pos) 237: { 238: struct kgsl_mem_entry *entry = ptr; 239: struct kgsl_process_private *private = s->private; 240: int id = 0; 241: MATCH LINES: 294 282: 283: static void *process_mem_seq_next(struct seq_file *s, void *ptr, 284: loff_t *pos) 285: { 286: ++*pos; 287: return process_mem_seq_find(s, ptr, 1); 288: } 289: 290: static int process_mem_seq_show(struct seq_file *s, void *ptr) 291: { 292: if (ptr == SEQ_START_TOKEN) { 293: seq_printf(s, "%16s %16s %16s %5s %10s %10s %16s %5s %10s %6s %6s %10s\n", 294: "gpuaddr", "useraddr", "size", "id", "flags", "type", 295: "usage", "sglen", "mapcnt", "eglsrf", "eglimg", "inode"); 296: return 0; 297: } else 298: return print_mem_entry(s, ptr); 299: } 300: 301: static const struct seq_operations process_mem_seq_fops = { 302: .start = process_mem_seq_start, 303: .stop = process_mem_seq_stop, 304: .next = process_mem_seq_next, 305: .show = process_mem_seq_show, 306: }; 307: 308: static int process_mem_open(struct inode *inode, struct file *file) 309: { 310: int ret; 311: pid_t pid = (pid_t) (unsigned long) inode->i_private; 312: struct seq_file *s = NULL; 313: struct kgsl_process_private *private = NULL; 314: 315: private = kgsl_process_private_find(pid); 316: 317: if (!private) 318: return -ENODEV; MATCH LINES: 352 340: } 341: 342: static const struct file_operations process_mem_fops = { 343: .open = process_mem_open, 344: .read = seq_read, 345: .llseek = seq_lseek, 346: .release = process_mem_release, 347: }; 348: 349: 350: static int print_vbo_ranges(int id, void *ptr, void *data) 351: { 352: kgsl_memdesc_print_vbo_ranges(ptr, data); 353: return 0; 354: } 355: 356: static int vbo_print(struct seq_file *s, void *unused) 357: { 358: struct kgsl_process_private *private = s->private; 359: 360: seq_puts(s, "id child range\n"); 361: 362: spin_lock(&private->mem_lock); 363: idr_for_each(&private->mem_idr, print_vbo_ranges, s); 364: spin_unlock(&private->mem_lock); 365: 366: return 0; 367: } 368: 369: static int vbo_open(struct inode *inode, struct file *file) 370: { 371: pid_t pid = (pid_t) (unsigned long) inode->i_private; 372: struct kgsl_process_private *private; 373: int ret; 374: 375: private = kgsl_process_private_find(pid); 376: MATCH LINES: 442 430: { 431: struct dentry *debug_dir, *dentry; 432: 433: kgsl_debugfs_dir = debugfs_create_dir("kgsl", NULL); 434: if (IS_ERR_OR_NULL(kgsl_debugfs_dir)) 435: return; 436: 437: debug_dir = debugfs_create_dir("debug", kgsl_debugfs_dir); 438: 439: proc_d_debugfs = debugfs_create_dir("proc", kgsl_debugfs_dir); 440: 441: debugfs_create_bool("strict_memory", 0644, debug_dir, 442: &kgsl_sharedmem_noretry_flag); 443: 444: mempools_debugfs = debugfs_create_dir("mempools", kgsl_debugfs_dir); 445: 446: if (IS_ERR_OR_NULL(mempools_debugfs)) 447: return; 448: 449: dentry = debugfs_create_file("pool_size", 0444, 450: mempools_debugfs, NULL, &_pool_size_fops); 451: 452: WARN((IS_ERR_OR_NULL(dentry)), 453: "Unable to create 'pool_size' file for mempools\n"); 454: } 455: 456: void kgsl_core_debugfs_close(void) 457: { 458: debugfs_remove_recursive(kgsl_debugfs_dir); 459: } --- FILE: \kgsl_device.h | HITS: 17 --- MATCH LINES: 83 71: * @KGSL_EVENT_CANCELLED: The event was cancelled before the event was fired 72: */ 73: enum kgsl_event_results { 74: KGSL_EVENT_RETIRED = 1, 75: KGSL_EVENT_CANCELLED = 2, 76: }; 77: 78: /* 79: * "list" of event types for ftrace symbolic magic 80: */ 81: 82: #define KGSL_CONTEXT_FLAGS \ 83: { KGSL_CONTEXT_NO_GMEM_ALLOC, "NO_GMEM_ALLOC" }, \ 84: { KGSL_CONTEXT_PREAMBLE, "PREAMBLE" }, \ 85: { KGSL_CONTEXT_TRASH_STATE, "TRASH_STATE" }, \ 86: { KGSL_CONTEXT_CTX_SWITCH, "CTX_SWITCH" }, \ 87: { KGSL_CONTEXT_PER_CONTEXT_TS, "PER_CONTEXT_TS" }, \ 88: { KGSL_CONTEXT_USER_GENERATED_TS, "USER_TS" }, \ 89: { KGSL_CONTEXT_NO_FAULT_TOLERANCE, "NO_FT" }, \ 90: { KGSL_CONTEXT_INVALIDATE_ON_FAULT, "INVALIDATE_ON_FAULT" }, \ 91: { KGSL_CONTEXT_PWR_CONSTRAINT, "PWR" }, \ 92: { KGSL_CONTEXT_SAVE_GMEM, "SAVE_GMEM" }, \ 93: { KGSL_CONTEXT_IFH_NOP, "IFH_NOP" }, \ 94: { KGSL_CONTEXT_SECURE, "SECURE" }, \ 95: { KGSL_CONTEXT_LPAC, "LPAC" }, \ 96: { KGSL_CONTEXT_NO_SNAPSHOT, "NO_SNAPSHOT" } 97: 98: #define KGSL_CONTEXT_ID(_context) \ 99: ((_context != NULL) ? (_context)->id : KGSL_MEMSTORE_GLOBAL) 100: 101: enum gpu_pwrlevel_op { 102: GPU_PWRLEVEL_OP_THERMAL, 103: GPU_PWRLEVEL_OP_MIN_PWRLEVEL, 104: GPU_PWRLEVEL_OP_MAX_PWRLEVEL, 105: GPU_PWRLEVEL_OP_GPUCLK, 106: GPU_PWRLEVEL_OP_PERF_HINT, /* Mutex grabbed in the ops function */ 107: GPU_PWRLEVEL_OP_DCVS_ENABLE, MATCH LINES: 210, 211, 236, 244 198: /** @dequeue_recurring_cmd: Dequeue recurring commands from GMU */ 199: int (*dequeue_recurring_cmd)(struct kgsl_device *device, 200: struct kgsl_context *context); 201: /** set_isdb_breakpoint_registers: Program isdb registers to issue break command */ 202: void (*set_isdb_breakpoint_registers)(struct kgsl_device *device); 203: /** @create_hw_fence: Create a hardware fence */ 204: void (*create_hw_fence)(struct kgsl_device *device, struct kgsl_sync_fence *kfence); 205: /** @gmu_based_dcvs_pwr_ops: Function ops for GMU based DCVS power operations */ 206: int (*gmu_based_dcvs_pwr_ops)(struct kgsl_device *device, u32 arg, 207: enum gpu_pwrlevel_op op); 208: /** @set_thermal_index: Target specific function to send thermal constraint to GMU */ 209: void (*set_thermal_index)(struct kgsl_device *device); 210: /** @alloc_dcvs_profile_memory: Function ops for GMU based DCVS profile operations */ 211: void (*alloc_dcvs_profile_memory)(struct kgsl_device *device, 212: struct kgsl_process_private *proc_priv); 213: /** @is_first_boot_done: Check if the ADRENO device first boot is done */ 214: bool (*is_first_boot_done)(struct kgsl_device *device); 215: /** @set_smmu_aperture: Target specific function to program the SMMU aperture registers */ 216: int (*set_smmu_aperture)(struct kgsl_device *device); 217: }; 218: 219: struct kgsl_ioctl { 220: unsigned int cmd; 221: long (*func)(struct kgsl_device_private *dev_priv, 222: unsigned int cmd, void *data); 223: }; 224: 225: long kgsl_ioctl_helper(struct file *filep, unsigned int cmd, unsigned long arg, 226: const struct kgsl_ioctl *cmds, int len); 227: 228: /* Flag to mark that the memobj_node should not go to the hadrware */ 229: #define MEMOBJ_SKIP BIT(1) 230: 231: /** 232: * struct kgsl_memobj_node - Memory object descriptor 233: * @node: Local list node for the object 234: * @id: GPU memory ID for the object 235: * offset: Offset within the object 236: * @gpuaddr: GPU address for the object 237: * @flags: External flags passed by the user 238: * @priv: Internal flags set by the driver 239: */ 240: struct kgsl_memobj_node { 241: struct list_head node; 242: unsigned int id; 243: uint64_t offset; 244: uint64_t gpuaddr; 245: uint64_t size; 246: unsigned long flags; 247: unsigned long priv; 248: }; 249: 250: struct kgsl_speedbin { 251: u16 fuse; 252: u16 speedbin; 253: }; 254: 255: /* 256: * Helper to build a speedbin table, i.e. the table: 257: * fuse | speedbin 258: * -----+--------- 259: * 0 | 0 260: * 169 | 1 261: * 174 | 2 262: * 263: * would be declared as: 264: * .speedbins = KGSL_SPEEDBINS( 265: * { 0, 0 }, 266: * { 169, 1 }, 267: * { 174, 2 }, 268: * ), MATCH LINES: 286, 287 274: const char *name; 275: u32 id; 276: 277: /* Kernel virtual address for GPU shader memory */ 278: void __iomem *shader_mem_virt; 279: 280: /* Starting kernel virtual address for QDSS GFX DBG register block */ 281: void __iomem *qdss_gfx_virt; 282: 283: /* Kernel virtual address for CX SMMU aperture register block */ 284: void __iomem *smmu_aperture_virt; 285: 286: struct kgsl_memdesc *memstore; 287: struct kgsl_memdesc *scratch; 288: 289: struct kgsl_mmu mmu; 290: struct gmu_core_device gmu_core; 291: struct completion hwaccess_gate; 292: struct completion halt_gate; 293: const struct kgsl_functable *ftbl; 294: struct work_struct idle_check_ws; 295: struct timer_list idle_timer; 296: struct kgsl_pwrctrl pwrctrl; 297: int open_count; 298: 299: /* For GPU inline submission */ 300: uint32_t submit_now; 301: spinlock_t submit_lock; 302: /** @skip_inline_submit: Track if user threads should make an inline submission or not */ 303: bool skip_inline_submit; 304: 305: #if IS_ENABLED(CONFIG_QCOM_KGSL_RT_MUTEX) 306: struct rt_mutex mutex; 307: #else 308: struct mutex mutex; 309: #endif 310: uint32_t state; 311: uint32_t requested_state; MATCH LINES: 370, 372 358: /* Number of active contexts seen globally for this device */ 359: int active_context_count; 360: struct kobject gpu_sysfs_kobj; 361: unsigned int l3_freq[3]; 362: unsigned int num_l3_pwrlevels; 363: /* store current L3 vote to determine if we should change our vote */ 364: unsigned int cur_l3_pwrlevel; 365: /** @globals: List of global memory objects */ 366: struct list_head globals; 367: /** @globlal_map: bitmap for global memory allocations */ 368: unsigned long *global_map; 369: /* @qdss_desc: Memory descriptor for the QDSS region if applicable */ 370: struct kgsl_memdesc *qdss_desc; 371: /* @qtimer_desc: Memory descriptor for the QDSS region if applicable */ 372: struct kgsl_memdesc *qtimer_desc; 373: /** @event_groups: List of event groups for this device */ 374: struct list_head event_groups; 375: /** @event_groups_lock: A R/W lock for the events group list */ 376: rwlock_t event_groups_lock; 377: /** @speed_bin: Speed bin for the GPU device if applicable */ 378: u32 speed_bin; 379: /** @debug_bus_bin: Debug bus bin for the GPU device if applicable */ 380: u32 debug_bus_bin; 381: /** @soc_code: Identifier containing product and feature code */ 382: u32 soc_code; 383: /** @gmu_fault: Set when a gmu or rgmu fault is encountered */ 384: bool gmu_fault; 385: /** @regmap: GPU register map */ 386: struct kgsl_regmap regmap; 387: /** @timelines: Iterator for assigning IDs to timelines */ 388: struct idr timelines; 389: /** @timelines_lock: Spinlock to protect the timelines idr */ 390: spinlock_t timelines_lock; 391: /** @fence_trace_array: A local trace array for fence debugging */ 392: struct trace_array *fence_trace_array; 393: /** @l3_vote: Enable/Disable l3 voting */ 394: bool l3_vote; 395: /** @pdev_loaded: Flag to test if platform driver is probed */ 396: bool pdev_loaded; MATCH LINES: 564 552: pid_nr((_c)->proc_priv->pid), ##args) 553: 554: /** 555: * struct kgsl_dcvs_profile_private - Private structure for a KGSL DCVS profile 556: * @gmu_registered: True if DCVS profile is registered with GMU 557: * @user_profile_registered: True if user DCVS IOCTL profile is received 558: * @md: Memory descriptor for the DCVS profile region 559: * @profile_mutex: Mutex lock to protect kgsl_dcvs_profile_private 560: */ 561: struct kgsl_dcvs_profile_private { 562: bool gmu_registered; 563: bool user_profile_registered; 564: struct kgsl_memdesc md; 565: struct mutex profile_mutex; 566: }; 567: 568: /** 569: * struct kgsl_process_private - Private structure for a KGSL process (across 570: * all devices) 571: * @priv: Internal flags, use KGSL_PROCESS_* values 572: * @pid: Identification structure for the task owner of the process 573: * @comm: task name of the process 574: * @mm: mm_struct of the opening process, used to prevent other mm mmap 575: * @mem_lock: Spinlock to protect the process memory lists 576: * @refcount: kref object for reference counting the process 577: * @idr: Iterator for assigning IDs to memory allocations 578: * @pagetable: Pointer to the pagetable owned by this process 579: * @kobj: Pointer to a kobj for the sysfs directory for this process 580: * @debug_root: Pointer to the debugfs root for this process 581: * @stats: Memory allocation statistics for this process 582: * @gpumem_mapped: KGSL memory mapped in the process address space 583: * @syncsource_idr: sync sources created by this process 584: * @syncsource_lock: Spinlock to protect the syncsource idr 585: * @fd_count: Counter for the number of FDs for this process 586: * @ctxt_count: Count for the number of contexts for this process 587: * @ctxt_count_lock: Spinlock to protect ctxt_count 588: * @frame_count: Count for the number of frames processed MATCH LINES: 726, 728, 734 714: struct work_struct work; 715: struct completion dump_gate; 716: struct kgsl_process_private *process; 717: struct kgsl_process_private *process_lpac; 718: unsigned int sysfs_read; 719: bool first_read; 720: bool recovered; 721: struct kgsl_device *device; 722: }; 723: 724: /** 725: * struct kgsl_snapshot_object - GPU memory in the snapshot 726: * @gpuaddr: The GPU address identified during snapshot 727: * @size: The buffer size identified during snapshot 728: * @offset: offset from start of the allocated kgsl_mem_entry 729: * @type: SNAPSHOT_OBJ_TYPE_* identifier. 730: * @entry: the reference counted memory entry for this buffer 731: * @node: node for kgsl_snapshot.obj_list 732: */ 733: struct kgsl_snapshot_object { 734: uint64_t gpuaddr; 735: uint64_t size; 736: uint64_t offset; 737: int type; 738: struct kgsl_mem_entry *entry; 739: struct list_head node; 740: }; 741: 742: struct kgsl_device *kgsl_get_device(int dev_idx); 743: 744: static inline void kgsl_regread(struct kgsl_device *device, 745: unsigned int offsetwords, 746: unsigned int *value) 747: { 748: *value = kgsl_regmap_read(&device->regmap, offsetwords); 749: } 750: 751: static inline void kgsl_regread64(struct kgsl_device *device, 752: u32 offsetwords_lo, u32 offsetwords_hi, 753: u64 *value) 754: { 755: u32 val_lo = 0, val_hi = 0; 756: 757: val_lo = kgsl_regmap_read(&device->regmap, offsetwords_lo); 758: val_hi = kgsl_regmap_read(&device->regmap, offsetwords_hi); MATCH LINES: 813 801: 802: int kgsl_device_platform_probe(struct kgsl_device *device); 803: 804: void kgsl_device_platform_remove(struct kgsl_device *device); 805: 806: const char *kgsl_pwrstate_to_str(unsigned int state); 807: 808: /** 809: * kgsl_device_snapshot_probe - add resources for the device GPU snapshot 810: * @device: The device to initialize 811: * @size: The size of the static region to allocate 812: * 813: * Allocate memory for a GPU snapshot for the specified device, 814: * and create the sysfs files to manage it 815: */ 816: void kgsl_device_snapshot_probe(struct kgsl_device *device, u32 size); 817: 818: void kgsl_device_snapshot(struct kgsl_device *device, 819: struct kgsl_context *context, struct kgsl_context *context_lpac, 820: bool gmu_fault); 821: void kgsl_device_snapshot_close(struct kgsl_device *device); 822: 823: void kgsl_events_init(void); 824: void kgsl_events_exit(void); 825: 826: /** 827: * kgsl_device_events_probe - Set up events for the KGSL device 828: * @device: A KGSL GPU device handle 829: * 830: * Set up the list and lock for GPU events for this device 831: */ 832: void kgsl_device_events_probe(struct kgsl_device *device); 833: 834: /** 835: * kgsl_device_events_remove - Remove all event groups from the KGSL device 836: * @device: A KGSL GPU device handle 837: * MATCH LINES: 896 884: struct kgsl_event_group *group); 885: void kgsl_flush_event_group(struct kgsl_device *device, 886: struct kgsl_event_group *group); 887: void kgsl_process_event_groups(struct kgsl_device *device); 888: 889: void kgsl_context_destroy(struct kref *kref); 890: 891: int kgsl_context_init(struct kgsl_device_private *dev_priv, 892: struct kgsl_context *context); 893: 894: void kgsl_context_dump(struct kgsl_context *context); 895: 896: int kgsl_memfree_find_entry(pid_t ptname, uint64_t *gpuaddr, 897: uint64_t *size, uint64_t *flags, pid_t *pid); 898: 899: long kgsl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); 900: 901: long kgsl_ioctl_copy_in(unsigned int kernel_cmd, unsigned int user_cmd, 902: unsigned long arg, unsigned char *ptr); 903: 904: long kgsl_ioctl_copy_out(unsigned int kernel_cmd, unsigned int user_cmd, 905: unsigned long arg, unsigned char *ptr); 906: 907: /** 908: * kgsl_context_type - Return a symbolic string for the context type 909: * @type: Context type 910: * 911: * Return: Symbolic string representing the context type 912: */ 913: const char *kgsl_context_type(int type); 914: 915: /** 916: * kgsl_context_put() - Release context reference count 917: * @context: Pointer to the KGSL context to be released 918: * 919: * Reduce the reference count on a KGSL context and destroy it if it is no 920: * longer needed MATCH LINES: 1141, 1146 1129: * @start: Index to start reading 1130: * @count: Number of entries to read 1131: * @pipe_id: Pipe ID to be dumped 1132: * @slice_id: Slice ID to be dumped 1133: * 1134: * Dump the values from an indexed register group into the snapshot 1135: */ 1136: void kgsl_snapshot_indexed_registers_v2(struct kgsl_device *device, 1137: struct kgsl_snapshot *snapshot, u32 index, u32 data, 1138: u32 start, u32 count, u32 pipe_id, u32 slice_id); 1139: 1140: int kgsl_snapshot_get_object(struct kgsl_snapshot *snapshot, 1141: struct kgsl_process_private *process, uint64_t gpuaddr, 1142: uint64_t size, unsigned int type); 1143: 1144: int kgsl_snapshot_have_object(struct kgsl_snapshot *snapshot, 1145: struct kgsl_process_private *process, 1146: uint64_t gpuaddr, uint64_t size); 1147: 1148: struct adreno_ib_object_list; 1149: 1150: int kgsl_snapshot_add_ib_obj_list(struct kgsl_snapshot *snapshot, 1151: struct adreno_ib_object_list *ib_obj_list); 1152: 1153: void kgsl_snapshot_add_section(struct kgsl_device *device, u16 id, 1154: struct kgsl_snapshot *snapshot, 1155: size_t (*func)(struct kgsl_device *, u8 *, size_t, void *), 1156: void *priv); 1157: 1158: /** 1159: * kgsl_of_property_read_ddrtype - Get property from devicetree based on 1160: * the type of DDR. 1161: * @node: Devicetree node 1162: * @base: prefix string of the property 1163: * @ptr: Pointer to store the value of the property 1164: * 1165: * First look up the devicetree property based on the prefix string and DDR 1166: * type. If property is not specified per DDR type, then look for the property 1167: * based on prefix string only. 1168: * 1169: * Return: 0 on success or error code on failure. 1170: */ --- FILE: \kgsl_drawobj.c | HITS: 27 --- MATCH LINES: 236 224: } 225: } 226: 227: kgsl_drawobj_put(drawobj); 228: dev_err(device->dev, "--gpu syncpoint deadlock print end--\n"); 229: } 230: 231: /* 232: * a generic function to retire a pending sync event and (possibly) kick the 233: * dispatcher. 234: * Returns false if the event was already marked for cancellation in another 235: * thread. This function should return true if this thread is responsible for 236: * freeing up the memory, and the event will not be cancelled. 237: */ 238: static bool drawobj_sync_expire(struct kgsl_device *device, 239: struct kgsl_drawobj_sync_event *event) 240: { 241: struct kgsl_drawobj_sync *syncobj = event->syncobj; 242: /* 243: * Clear the event from the pending mask - if it is already clear, then 244: * leave without doing anything useful 245: */ 246: if (!test_and_clear_bit(event->id, &syncobj->pending)) 247: return false; 248: 249: /* 250: * If no more pending events, delete the timer and schedule the command 251: * for dispatch 252: */ 253: if (!kgsl_drawobj_events_pending(event->syncobj)) { 254: kgsl_delete_timer(&syncobj->timer); 255: 256: if (device->ftbl->drawctxt_sched) 257: device->ftbl->drawctxt_sched(device, 258: event->syncobj->base.context); 259: } 260: return true; MATCH LINES: 447, 465, 471 435: 436: /* 437: * The scheduler is done with the timelineobj. Put the initial 438: * sig_refcount to continue with the signaling process. 439: */ 440: kgsl_timelineobj_signal(timelineobj); 441: } 442: 443: static void bindobj_destroy(struct kgsl_drawobj *drawobj) 444: { 445: struct kgsl_drawobj_bind *bindobj = BINDOBJ(drawobj); 446: 447: kgsl_sharedmem_put_bind_op(bindobj->bind); 448: } 449: 450: static void cmdobj_destroy(struct kgsl_drawobj *drawobj) 451: { 452: struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj); 453: struct kgsl_memobj_node *mem, *tmpmem; 454: 455: /* 456: * Release the refcount on the mem entry associated with the 457: * ib profiling buffer 458: */ 459: if (cmdobj->base.flags & KGSL_DRAWOBJ_PROFILING) 460: kgsl_mem_entry_put(cmdobj->profiling_buf_entry); 461: 462: /* Destroy the command list */ 463: list_for_each_entry_safe(mem, tmpmem, &cmdobj->cmdlist, node) { 464: list_del_init(&mem->node); 465: kmem_cache_free(memobjs_cache, mem); 466: } 467: 468: /* Destroy the memory list */ 469: list_for_each_entry_safe(mem, tmpmem, &cmdobj->memlist, node) { 470: list_del_init(&mem->node); 471: kmem_cache_free(memobjs_cache, mem); 472: } 473: 474: if (drawobj->type & CMDOBJ_TYPE) { 475: atomic_dec(&drawobj->context->proc_priv->cmd_count); 476: atomic_dec(&drawobj->context->proc_priv->period->active_cmds); 477: } 478: } 479: 480: /** 481: * kgsl_drawobj_destroy() - Destroy a kgsl object structure 482: * @obj: Pointer to the kgsl object to destroy 483: * 484: * Start the process of destroying a command batch. Cancel any pending events 485: * and decrement the refcount. Asynchronous events can still signal after 486: * kgsl_drawobj_destroy has returned. 487: */ 488: void kgsl_drawobj_destroy(struct kgsl_drawobj *drawobj) 489: { 490: if (IS_ERR_OR_NULL(drawobj)) 491: return; 492: 493: drawobj->destroy(drawobj); 494: 495: kgsl_drawobj_put(drawobj); MATCH LINES: 813, 828, 831, 832, 835, 840, 841, 850, 851, 855, 871, 883, 892, 896 801: else if (sync->type == KGSL_CMD_SYNCPOINT_TYPE_TIMELINE) 802: return drawobj_add_sync_timeline(device, 803: syncobj, sync->priv, sync->size); 804: 805: dev_err(device->dev, "bad syncpoint type %d for ctxt %u\n", 806: sync->type, drawobj->context->id); 807: 808: return -EINVAL; 809: } 810: 811: static void add_profiling_buffer(struct kgsl_device *device, 812: struct kgsl_drawobj_cmd *cmdobj, 813: uint64_t gpuaddr, uint64_t size, 814: unsigned int id, uint64_t offset) 815: { 816: struct kgsl_mem_entry *entry; 817: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 818: u64 start; 819: 820: if (!(drawobj->flags & KGSL_DRAWOBJ_PROFILING)) 821: return; 822: 823: /* Only the first buffer entry counts - ignore the rest */ 824: if (cmdobj->profiling_buf_entry != NULL) 825: return; 826: 827: if (id != 0) 828: entry = kgsl_sharedmem_find_id(drawobj->context->proc_priv, 829: id); 830: else 831: entry = kgsl_sharedmem_find(drawobj->context->proc_priv, 832: gpuaddr); 833: 834: if (entry != NULL) { 835: start = id ? (entry->memdesc.gpuaddr + offset) : gpuaddr; 836: /* 837: * Make sure there is enough room in the object to store the 838: * entire profiling buffer object 839: */ 840: if (!kgsl_gpuaddr_in_memdesc(&entry->memdesc, gpuaddr, size) || 841: !kgsl_gpuaddr_in_memdesc(&entry->memdesc, start, 842: sizeof(struct kgsl_drawobj_profiling_buffer))) { 843: kgsl_mem_entry_put(entry); 844: entry = NULL; 845: } 846: } 847: 848: if (entry == NULL) { 849: dev_err(device->dev, 850: "ignore bad profile buffer ctxt %u id %d offset %lld gpuaddr %llx size %lld\n", 851: drawobj->context->id, id, offset, gpuaddr, size); 852: return; 853: } 854: 855: cmdobj->profiling_buffer_gpuaddr = start; 856: cmdobj->profiling_buf_entry = entry; 857: } 858: 859: /** 860: * kgsl_drawobj_cmd_add_ibdesc() - Add a legacy ibdesc to a command 861: * batch 862: * @cmdobj: Pointer to the ib 863: * @ibdesc: Pointer to the user-specified struct defining the memory or IB 864: * 865: * Create a new memory entry in the ib based on the 866: * user specified parameters 867: */ 868: int kgsl_drawobj_cmd_add_ibdesc(struct kgsl_device *device, 869: struct kgsl_drawobj_cmd *cmdobj, struct kgsl_ibdesc *ibdesc) 870: { 871: uint64_t gpuaddr = (uint64_t) ibdesc->gpuaddr; 872: uint64_t size = (uint64_t) ibdesc->sizedwords << 2; 873: struct kgsl_memobj_node *mem; 874: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj); 875: 876: /* sanitize the ibdesc ctrl flags */ 877: ibdesc->ctrl &= KGSL_IBDESC_MEMLIST | KGSL_IBDESC_PROFILING_BUFFER; 878: 879: if (drawobj->flags & KGSL_DRAWOBJ_MEMLIST && 880: ibdesc->ctrl & KGSL_IBDESC_MEMLIST) { 881: if (ibdesc->ctrl & KGSL_IBDESC_PROFILING_BUFFER) { 882: add_profiling_buffer(device, cmdobj, 883: gpuaddr, size, 0, 0); 884: return 0; 885: } 886: } 887: 888: /* Ignore if SYNC or MARKER is specified */ 889: if (drawobj->type & (SYNCOBJ_TYPE | MARKEROBJ_TYPE)) 890: return 0; 891: 892: mem = kmem_cache_alloc(memobjs_cache, GFP_KERNEL); 893: if (mem == NULL) 894: return -ENOMEM; 895: 896: mem->gpuaddr = gpuaddr; 897: mem->size = size; 898: mem->priv = 0; 899: mem->id = 0; 900: mem->offset = 0; 901: mem->flags = 0; 902: 903: if (drawobj->flags & KGSL_DRAWOBJ_MEMLIST && 904: ibdesc->ctrl & KGSL_IBDESC_MEMLIST) 905: /* add to the memlist */ 906: list_add_tail(&mem->node, &cmdobj->memlist); 907: else { 908: /* set the preamble flag if directed to */ 909: if (drawobj->context->flags & KGSL_CONTEXT_PREAMBLE && 910: list_empty(&cmdobj->cmdlist)) 911: mem->flags = KGSL_CMDLIST_CTXTSWITCH_PREAMBLE; 912: 913: /* add to the cmd list */ 914: list_add_tail(&mem->node, &cmdobj->cmdlist); 915: } 916: 917: return 0; 918: } 919: 920: static int drawobj_init(struct kgsl_device *device, MATCH LINES: 1117, 1141, 1149 1105: err: 1106: for (i = 0; i < cmd.count; i++) { 1107: kgsl_timeline_put(timelineobj->timelines[i].timeline); 1108: kgsl_context_put(timelineobj->timelines[i].context); 1109: } 1110: 1111: kvfree(timelineobj->timelines); 1112: timelineobj->timelines = NULL; 1113: timelineobj->count = 0; 1114: return ret; 1115: } 1116: 1117: static void kgsl_drawobj_bind_callback(struct kgsl_sharedmem_bind_op *op) 1118: { 1119: struct kgsl_drawobj_bind *bindobj = op->data; 1120: struct kgsl_drawobj *drawobj = DRAWOBJ(bindobj); 1121: struct kgsl_device *device = drawobj->device; 1122: 1123: set_bit(KGSL_BINDOBJ_STATE_DONE, &bindobj->state); 1124: 1125: /* Re-schedule the context */ 1126: if (device->ftbl->drawctxt_sched) 1127: device->ftbl->drawctxt_sched(device, 1128: drawobj->context); 1129: 1130: /* Put back the reference we took when we started the operation */ 1131: kgsl_context_put(drawobj->context); 1132: kgsl_drawobj_put(drawobj); 1133: } 1134: 1135: int kgsl_drawobj_add_bind(struct kgsl_device_private *dev_priv, 1136: struct kgsl_drawobj_bind *bindobj, 1137: void __user *src, u64 cmdsize) 1138: { 1139: struct kgsl_gpu_aux_command_bind cmd; 1140: struct kgsl_process_private *private = dev_priv->process_priv; 1141: struct kgsl_sharedmem_bind_op *op; 1142: int ret; 1143: 1144: ret = get_aux_command(src, cmdsize, 1145: KGSL_GPU_AUX_COMMAND_BIND, &cmd, sizeof(cmd)); 1146: if (ret) 1147: return ret; 1148: 1149: op = kgsl_sharedmem_create_bind_op(private, cmd.target, 1150: u64_to_user_ptr(cmd.rangeslist), cmd.numranges, 1151: cmd.rangesize); 1152: 1153: if (IS_ERR(op)) 1154: return PTR_ERR(op); 1155: 1156: op->callback = kgsl_drawobj_bind_callback; 1157: op->data = bindobj; 1158: 1159: bindobj->bind = op; 1160: return 0; 1161: } 1162: 1163: struct kgsl_drawobj_bind *kgsl_drawobj_bind_create(struct kgsl_device *device, 1164: struct kgsl_context *context) 1165: { 1166: int ret; 1167: struct kgsl_drawobj_bind *bindobj = 1168: kzalloc(sizeof(*bindobj), GFP_KERNEL); 1169: 1170: if (!bindobj) 1171: return ERR_PTR(-ENOMEM); 1172: 1173: ret = drawobj_init(device, context, &bindobj->base, BINDOBJ_TYPE); MATCH LINES: 1300 1288: int i, ret = 0; 1289: struct kgsl_ibdesc_compat ibdesc32; 1290: struct kgsl_ibdesc ibdesc; 1291: 1292: for (i = 0; i < count; i++) { 1293: memset(&ibdesc32, 0, sizeof(ibdesc32)); 1294: 1295: if (copy_from_user(&ibdesc32, ptr, sizeof(ibdesc32))) { 1296: ret = -EFAULT; 1297: break; 1298: } 1299: 1300: ibdesc.gpuaddr = (unsigned long) ibdesc32.gpuaddr; 1301: ibdesc.sizedwords = (size_t) ibdesc32.sizedwords; 1302: ibdesc.ctrl = (unsigned int) ibdesc32.ctrl; 1303: 1304: ret = kgsl_drawobj_cmd_add_ibdesc(device, cmdobj, &ibdesc); 1305: if (ret) 1306: break; 1307: 1308: ptr += sizeof(ibdesc32); 1309: } 1310: 1311: return ret; 1312: } 1313: 1314: static int add_syncpoints_compat(struct kgsl_device *device, 1315: struct kgsl_drawobj_sync *syncobj, void __user *ptr, int count) 1316: { 1317: struct kgsl_cmd_syncpoint_compat sync32; 1318: struct kgsl_cmd_syncpoint sync; 1319: int i, ret = 0; 1320: 1321: for (i = 0; i < count; i++) { 1322: memset(&sync32, 0, sizeof(sync32)); 1323: 1324: if (copy_from_user(&sync32, ptr, sizeof(sync32))) { MATCH LINES: 1448, 1452 1436: 1437: ptr += sizeof(sync); 1438: } 1439: 1440: return 0; 1441: } 1442: 1443: static int kgsl_drawobj_add_memobject(struct list_head *head, 1444: struct kgsl_command_object *obj) 1445: { 1446: struct kgsl_memobj_node *mem; 1447: 1448: mem = kmem_cache_alloc(memobjs_cache, GFP_KERNEL); 1449: if (mem == NULL) 1450: return -ENOMEM; 1451: 1452: mem->gpuaddr = obj->gpuaddr; 1453: mem->size = obj->size; 1454: mem->id = obj->id; 1455: mem->offset = obj->offset; 1456: mem->flags = obj->flags; 1457: mem->priv = 0; 1458: 1459: list_add_tail(&mem->node, head); 1460: return 0; 1461: } 1462: 1463: #define CMDLIST_FLAGS \ 1464: (KGSL_CMDLIST_IB | \ 1465: KGSL_CMDLIST_CTXTSWITCH_PREAMBLE | \ 1466: KGSL_CMDLIST_IB_PREAMBLE) 1467: 1468: /* This can only accept MARKEROBJ_TYPE and CMDOBJ_TYPE */ 1469: int kgsl_drawobj_cmd_add_cmdlist(struct kgsl_device *device, 1470: struct kgsl_drawobj_cmd *cmdobj, void __user *ptr, 1471: unsigned int size, unsigned int count) 1472: { 1473: struct kgsl_command_object obj; 1474: struct kgsl_drawobj *baseobj = DRAWOBJ(cmdobj); 1475: int i, ret; 1476: MATCH LINES: 1494, 1532, 1538 1482: if (ret <= 0) 1483: return ret; 1484: 1485: for (i = 0; i < count; i++) { 1486: if (copy_struct_from_user(&obj, sizeof(obj), ptr, size)) 1487: return -EFAULT; 1488: 1489: /* Sanity check the flags */ 1490: if (!(obj.flags & CMDLIST_FLAGS)) { 1491: dev_err(device->dev, 1492: "invalid cmdobj ctxt %u flags %d id %d offset %llu addr %llx size %llu\n", 1493: baseobj->context->id, obj.flags, obj.id, 1494: obj.offset, obj.gpuaddr, obj.size); 1495: return -EINVAL; 1496: } 1497: 1498: ret = kgsl_drawobj_add_memobject(&cmdobj->cmdlist, &obj); 1499: if (ret) 1500: return ret; 1501: 1502: ptr += sizeof(obj); 1503: } 1504: 1505: return 0; 1506: } 1507: 1508: int kgsl_drawobj_cmd_add_memlist(struct kgsl_device *device, 1509: struct kgsl_drawobj_cmd *cmdobj, void __user *ptr, 1510: unsigned int size, unsigned int count) 1511: { 1512: struct kgsl_command_object obj; 1513: struct kgsl_drawobj *baseobj = DRAWOBJ(cmdobj); 1514: int i, ret; 1515: 1516: /* Ignore everything if this is a MARKER */ 1517: if (baseobj->type & MARKEROBJ_TYPE) 1518: return 0; 1519: 1520: ret = _verify_input_list(count, ptr, size); 1521: if (ret <= 0) 1522: return ret; 1523: 1524: for (i = 0; i < count; i++) { 1525: if (copy_struct_from_user(&obj, sizeof(obj), ptr, size)) 1526: return -EFAULT; 1527: 1528: if (!(obj.flags & KGSL_OBJLIST_MEMOBJ)) { 1529: dev_err(device->dev, 1530: "invalid memobj ctxt %u flags %d id %d offset %lld addr %lld size %lld\n", 1531: DRAWOBJ(cmdobj)->context->id, obj.flags, 1532: obj.id, obj.offset, obj.gpuaddr, 1533: obj.size); 1534: return -EINVAL; 1535: } 1536: 1537: if (obj.flags & KGSL_OBJLIST_PROFILE) 1538: add_profiling_buffer(device, cmdobj, obj.gpuaddr, 1539: obj.size, obj.id, obj.offset); 1540: else { 1541: ret = kgsl_drawobj_add_memobject(&cmdobj->memlist, 1542: &obj); 1543: if (ret) 1544: return ret; 1545: } 1546: 1547: ptr += sizeof(obj); 1548: } 1549: 1550: return 0; 1551: } 1552: 1553: struct kgsl_drawobj_sync * 1554: kgsl_drawobj_create_timestamp_syncobj(struct kgsl_device *device, 1555: struct kgsl_context *context, unsigned int timestamp) 1556: { 1557: struct kgsl_drawobj_sync *syncobj; 1558: struct kgsl_cmd_syncpoint_timestamp priv; 1559: int ret; 1560: 1561: syncobj = kgsl_drawobj_sync_create(device, context); 1562: if (IS_ERR(syncobj)) --- FILE: \kgsl_drawobj.h | HITS: 4 --- MATCH LINES: 43, 65, 83 31: * @flags: flags 32: * @refcount: kref structure to maintain the reference count 33: */ 34: struct kgsl_drawobj { 35: struct kgsl_device *device; 36: struct kgsl_context *context; 37: uint32_t type; 38: uint32_t timestamp; 39: unsigned long flags; 40: struct kref refcount; 41: /** @destroy: Callbak function to take down the object */ 42: void (*destroy)(struct kgsl_drawobj *drawobj); 43: /** @destroy_object: Callback function to free the object memory */ 44: void (*destroy_object)(struct kgsl_drawobj *drawobj); 45: }; 46: 47: /** 48: * struct kgsl_drawobj_cmd - KGSL command obj, This covers marker 49: * cmds also since markers are special form of cmds that do not 50: * need their cmds to be executed. 51: * @base: Base kgsl_drawobj, this needs to be the first entry 52: * @priv: Internal flags 53: * @global_ts: The ringbuffer timestamp corresponding to this 54: * command obj 55: * @fault_policy: Internal policy describing how to handle this command in case 56: * of a fault 57: * @fault_recovery: recovery actions actually tried for this batch 58: * be hung 59: * @refcount: kref structure to maintain the reference count 60: * @cmdlist: List of IBs to issue 61: * @memlist: List of all memory used in this command batch 62: * @marker_timestamp: For markers, the timestamp of the last "real" command that 63: * was queued 64: * @profiling_buf_entry: Mem entry containing the profiling buffer 65: * @profiling_buffer_gpuaddr: GPU virt address of the profile buffer added here 66: * for easy access 67: * @profile_index: Index to store the start/stop ticks in the kernel profiling 68: * buffer 69: * @submit_ticks: Variable to hold ticks at the time of 70: * command obj submit. 71: 72: */ 73: struct kgsl_drawobj_cmd { 74: struct kgsl_drawobj base; 75: unsigned long priv; 76: unsigned int global_ts; 77: unsigned long fault_policy; 78: unsigned long fault_recovery; 79: struct list_head cmdlist; 80: struct list_head memlist; 81: unsigned int marker_timestamp; 82: struct kgsl_mem_entry *profiling_buf_entry; 83: uint64_t profiling_buffer_gpuaddr; 84: unsigned int profile_index; 85: uint64_t submit_ticks; 86: /* @numibs: Number of ibs in this cmdobj */ 87: u32 numibs; 88: /* @requeue_cnt: Number of times cmdobj was requeued before submission to dq succeeded */ 89: u32 requeue_cnt; 90: }; 91: 92: /* This sync object cannot be sent to hardware */ 93: #define KGSL_SYNCOBJ_SW 0 94: /* This sync object can be sent to hardware */ 95: #define KGSL_SYNCOBJ_HW 1 96: /* This hw sync object has been assigned a timestamp */ 97: #define KGSL_SYNCOBJ_HW_TS 2 98: 99: struct kgsl_drawobj_sync_hw_fence { 100: /** @fence: Pointer to hardware fence */ 101: struct dma_fence *fence; 102: /** 103: * context: Pointer to kgsl context if this hardware fence is owned by a kgsl context 104: */ 105: struct kgsl_context *context; 106: }; 107: MATCH LINES: 148 136: #define KGSL_BINDOBJ_STATE_START 0 137: #define KGSL_BINDOBJ_STATE_DONE 1 138: 139: /** 140: * struct kgsl_drawobj_bind - KGSL virtual buffer object bind operation 141: * @base: &struct kgsl_drawobj container 142: * @state: Current state of the draw operation 143: * @bind: Pointer to the VBO bind operation struct 144: */ 145: struct kgsl_drawobj_bind { 146: struct kgsl_drawobj base; 147: unsigned long state; 148: struct kgsl_sharedmem_bind_op *bind; 149: }; 150: 151: static inline struct kgsl_drawobj_bind *BINDOBJ(struct kgsl_drawobj *obj) 152: { 153: return container_of(obj, struct kgsl_drawobj_bind, base); 154: } 155: 156: /** 157: * struct kgsl_drawobj_timeline - KGSL timeline signal operation 158: */ 159: struct kgsl_drawobj_timeline { 160: /** @base: &struct kgsl_drawobj container */ 161: struct kgsl_drawobj base; 162: /** @sig_refcount: Refcount to trigger timeline signaling */ 163: struct kref sig_refcount; 164: /* @timelines: Array of timeline events to signal */ 165: struct kgsl_timeline_event *timelines; 166: /** @count: Number of items in timelines */ 167: u32 count; 168: }; 169: 170: static inline struct kgsl_drawobj_timeline * 171: TIMELINEOBJ(struct kgsl_drawobj *obj) 172: { --- FILE: \kgsl_gmu_core.c | HITS: 33 --- MATCH LINES: 208, 213, 214, 215, 220, 221, 236, 242, 274, 281, 282 196: } 197: 198: int gmu_core_timed_poll_check(struct kgsl_device *device, 199: unsigned int offset, unsigned int expected_ret, 200: unsigned int timeout_ms, unsigned int mask) 201: { 202: u32 val; 203: 204: return kgsl_regmap_read_poll_timeout(&device->regmap, offset, 205: val, (val & mask) == expected_ret, 100, timeout_ms * 1000); 206: } 207: 208: int gmu_core_map_memdesc(struct iommu_domain *domain, struct kgsl_memdesc *memdesc, 209: u64 gmuaddr, int attrs) 210: { 211: ssize_t mapped; 212: 213: if (!memdesc->pages) { 214: mapped = kgsl_mmu_map_sg(domain, gmuaddr, memdesc->sgt->sgl, 215: memdesc->sgt->nents, attrs); 216: } else { 217: struct sg_table sgt = { 0 }; 218: int ret; 219: 220: ret = sg_alloc_table_from_pages(&sgt, memdesc->pages, 221: memdesc->page_count, 0, memdesc->size, GFP_KERNEL); 222: 223: if (ret) 224: return ret; 225: 226: mapped = kgsl_mmu_map_sg(domain, gmuaddr, sgt.sgl, sgt.nents, attrs); 227: sg_free_table(&sgt); 228: } 229: 230: if (!mapped) 231: mapped = -ENOMEM; 232: 233: return (mapped < 0) ? mapped : 0; 234: } 235: 236: struct kgsl_memdesc *gmu_core_find_memdesc(struct kgsl_device *device, u32 addr, u32 size) 237: { 238: struct gmu_core_device *gmu = &device->gmu_core; 239: int i; 240: 241: for (i = 0; i < gmu->global_entries; i++) { 242: struct kgsl_memdesc *md = &gmu->gmu_globals[i]; 243: 244: if ((addr >= md->gmuaddr) && 245: (((addr + size) <= (md->gmuaddr + md->size)))) 246: return md; 247: } 248: 249: return NULL; 250: } 251: 252: int gmu_core_find_vma_block(struct kgsl_device *device, u32 addr, u32 size) 253: { 254: struct gmu_core_device *gmu = &device->gmu_core; 255: int i; 256: 257: for (i = 0; i < gmu->num_vmas; i++) { 258: struct gmu_vma_entry *vma = &gmu->vma[i]; 259: 260: if ((addr >= vma->start) && 261: ((addr + size) <= (vma->start + vma->size))) 262: return i; 263: } 264: 265: return -ENOENT; 266: } 267: 268: void gmu_core_free_globals(struct kgsl_device *device) 269: { 270: struct gmu_core_device *gmu = &device->gmu_core; 271: int i; 272: 273: for (i = 0; i < gmu->global_entries && i < ARRAY_SIZE(gmu->gmu_globals); i++) { 274: struct kgsl_memdesc *md = &gmu->gmu_globals[i]; 275: 276: if (!md->gmuaddr) 277: continue; 278: 279: iommu_unmap(gmu->domain, md->gmuaddr, md->size); 280: 281: if (TEST_FLAG(KGSL_MEMDESC_SYSMEM, &md->priv)) 282: kgsl_sharedmem_free(md); 283: 284: memset(md, 0, sizeof(*md)); 285: } 286: 287: if (gmu->domain) { 288: kgsl_detach_iommu_group(gmu->domain, gmu->group); 289: iommu_domain_free(gmu->domain); 290: gmu->domain = NULL; 291: } 292: 293: gmu->global_entries = 0; 294: } 295: 296: static struct gmu_vma_node *find_va(struct gmu_vma_entry *vma, u32 addr, u32 size) 297: { 298: struct rb_node *node = vma->vma_root.rb_node; 299: 300: while (node != NULL) { 301: struct gmu_vma_node *data = rb_entry(node, struct gmu_vma_node, node); 302: 303: if (addr + size <= data->va) 304: node = node->rb_left; 305: else if (addr >= data->va + data->size) 306: node = node->rb_right; MATCH LINES: 381, 414, 435, 446, 462, 492 369: } 370: 371: cur = ALIGN(data->va + data->size, va_align); 372: node = rb_next(node); 373: } 374: 375: /* Do we have space after the last node? */ 376: if (!found && (cur + size <= vma->start + vma->size)) 377: found = true; 378: return found ? cur : 0; 379: } 380: 381: static int _map_gmu_dynamic(struct kgsl_device *device, struct kgsl_memdesc *md, 382: u32 addr, u32 vma_id, int attrs, u32 align) 383: { 384: struct gmu_core_device *gmu = &device->gmu_core; 385: struct device *gmu_pdev_dev = GMU_PDEV_DEV(device); 386: struct gmu_vma_entry *vma = &gmu->vma[vma_id]; 387: struct gmu_vma_node *vma_node = NULL; 388: int ret; 389: u32 size = ALIGN(md->size, hfi_get_gmu_sz_alignment(align)); 390: 391: spin_lock(&vma->lock); 392: if (!addr) { 393: /* 394: * We will end up with a hole (GMU VA range not backed by physical mapping) if 395: * the aligned size is greater than the size of the physical mapping 396: */ 397: addr = find_unmapped_va(vma, size, hfi_get_gmu_va_alignment(align)); 398: if (addr == 0) { 399: spin_unlock(&vma->lock); 400: dev_err(gmu_pdev_dev, 401: "Insufficient VA space size: %x\n", size); 402: return -ENOMEM; 403: } 404: } 405: 406: ret = insert_va(vma, addr, size); 407: spin_unlock(&vma->lock); 408: if (ret < 0) { 409: dev_err(gmu_pdev_dev, 410: "Could not insert va: %x size %x\n", addr, size); 411: return ret; 412: } 413: 414: ret = gmu_core_map_memdesc(gmu->domain, md, addr, attrs); 415: if (!ret) { 416: md->gmuaddr = addr; 417: return 0; 418: } 419: 420: /* Failed to map to GMU */ 421: dev_err(gmu_pdev_dev, 422: "Unable to map GMU kernel block: addr:0x%08x size:0x%llx :%d\n", 423: addr, md->size, ret); 424: 425: spin_lock(&vma->lock); 426: vma_node = find_va(vma, md->gmuaddr, size); 427: if (vma_node) 428: rb_erase(&vma_node->node, &vma->vma_root); 429: spin_unlock(&vma->lock); 430: kfree(vma_node); 431: 432: return ret; 433: } 434: 435: static int _map_gmu_static(struct kgsl_device *device, struct kgsl_memdesc *md, 436: u32 addr, u32 vma_id, int attrs, u32 align) 437: { 438: struct gmu_core_device *gmu = &device->gmu_core; 439: struct gmu_vma_entry *vma = &gmu->vma[vma_id]; 440: int ret; 441: u32 size = ALIGN(md->size, hfi_get_gmu_sz_alignment(align)); 442: 443: if (!addr) 444: addr = ALIGN(vma->next_va, hfi_get_gmu_va_alignment(align)); 445: 446: ret = gmu_core_map_memdesc(device->gmu_core.domain, md, addr, attrs); 447: if (ret) { 448: dev_err(GMU_PDEV_DEV(device), 449: "Unable to map GMU kernel block: addr:0x%08x size:0x%llx :%d\n", 450: addr, md->size, ret); 451: return ret; 452: } 453: md->gmuaddr = addr; 454: /* 455: * We will end up with a hole (GMU VA range not backed by physical mapping) if the aligned 456: * size is greater than the size of the physical mapping 457: */ 458: vma->next_va = md->gmuaddr + size; 459: return 0; 460: } 461: 462: int gmu_core_reserve_gmuaddr(struct kgsl_device *device, struct kgsl_memdesc *md, u32 vma_id, 463: u32 align) 464: { 465: struct gmu_core_device *gmu = &device->gmu_core; 466: struct gmu_vma_entry *vma = &gmu->vma[vma_id]; 467: u32 addr, size = ALIGN(md->size, hfi_get_gmu_sz_alignment(align)); 468: 469: if (vma_is_dynamic(device, vma_id)) { 470: spin_lock(&vma->lock); 471: addr = find_unmapped_va(vma, size, hfi_get_gmu_va_alignment(align)); 472: spin_unlock(&vma->lock); 473: if (addr == 0) 474: goto error; 475: } else { 476: addr = ALIGN(vma->next_va, hfi_get_gmu_va_alignment(align)); 477: if ((addr + size) >= (vma->start + vma->size)) 478: goto error; 479: vma->next_va = addr + size; 480: } 481: 482: md->gmuaddr = addr; 483: 484: return 0; 485: 486: error: 487: dev_err_ratelimited(GMU_PDEV_DEV(device), 488: "Insufficient VA space size: %x in vma:%u\n", size, vma_id); 489: return -ENOMEM; 490: } 491: 492: int gmu_core_map_gmu(struct kgsl_device *device, struct kgsl_memdesc *md, 493: u32 addr, u32 vma_id, int attrs, u32 align) 494: { 495: return vma_is_dynamic(device, vma_id) ? 496: _map_gmu_dynamic(device, md, addr, vma_id, attrs, align) : 497: _map_gmu_static(device, md, addr, vma_id, attrs, align); 498: } 499: 500: int gmu_core_get_attrs(u32 flags) 501: { 502: int attrs = IOMMU_READ; 503: 504: if (flags & HFI_MEMFLAG_GMU_PRIV) 505: attrs |= IOMMU_PRIV; 506: 507: if (flags & HFI_MEMFLAG_GMU_WRITEABLE) 508: attrs |= IOMMU_WRITE; 509: 510: return attrs; 511: } 512: 513: int gmu_core_import_buffer(struct kgsl_device *device, struct hfi_mem_alloc_entry *entry) 514: { 515: struct hfi_mem_alloc_desc *desc = &entry->desc; 516: u32 attrs = gmu_core_get_attrs(desc->flags); MATCH LINES: 533, 538, 556, 564, 574, 578, 586, 609, 613, 619, 624, 650, 655, 670 521: * mark the buffer I/O-coherent on GMU side as well to prevent stale 522: * data and immediate updates in DDR. 523: */ 524: if (desc->mem_kind == HFI_MEMKIND_HW_FENCE && 525: kgsl_mmu_has_feature(device, KGSL_MMU_IO_COHERENT)) { 526: entry->md->flags |= KGSL_MEMFLAGS_IOCOHERENT; 527: attrs |= IOMMU_CACHE; 528: } 529: 530: return gmu_core_map_gmu(device, entry->md, 0, vma_id, attrs, desc->align); 531: } 532: 533: struct kgsl_memdesc *gmu_core_reserve_kernel_block(struct kgsl_device *device, 534: u32 addr, u32 size, u32 vma_id, u32 align) 535: { 536: int ret; 537: u64 memflags = 0; 538: struct kgsl_memdesc *md; 539: struct gmu_core_device *gmu = &device->gmu_core; 540: int attrs = IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV; 541: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 542: 543: if (gmu->global_entries == ARRAY_SIZE(gmu->gmu_globals)) 544: return ERR_PTR(-ENOMEM); 545: 546: md = &gmu->gmu_globals[gmu->global_entries]; 547: 548: /* 549: * Apply WB cache policy to fetch GMU FW successfully for A622. 550: * A622 has specific cache coherency requirements that can lead to data 551: * inconsistency if not using writeback cache policy. 552: */ 553: if (adreno_is_a622(adreno_dev)) 554: memflags = FIELD_PREP(KGSL_CACHEMODE_MASK, KGSL_CACHEMODE_WRITEBACK); 555: 556: ret = kgsl_allocate_kernel(device, md, size, memflags, KGSL_MEMDESC_SYSMEM); 557: if (ret) { 558: memset(md, 0x0, sizeof(*md)); 559: return ERR_PTR(-ENOMEM); 560: } 561: 562: ret = gmu_core_map_gmu(device, md, addr, vma_id, attrs, align); 563: if (ret) { 564: kgsl_sharedmem_free(md); 565: memset(md, 0x0, sizeof(*md)); 566: return ERR_PTR(ret); 567: } 568: 569: gmu->global_entries++; 570: 571: return md; 572: } 573: 574: struct kgsl_memdesc *gmu_core_reserve_kernel_block_fixed(struct kgsl_device *device, 575: u32 addr, u32 size, u32 vma_id, const char *resource, int attrs, u32 align) 576: { 577: int ret; 578: struct kgsl_memdesc *md; 579: struct gmu_core_device *gmu = &device->gmu_core; 580: 581: if (gmu->global_entries == ARRAY_SIZE(gmu->gmu_globals)) 582: return ERR_PTR(-ENOMEM); 583: 584: md = &gmu->gmu_globals[gmu->global_entries]; 585: 586: ret = kgsl_memdesc_init_fixed(device, GMU_PDEV(device), resource, md); 587: if (ret) 588: return ERR_PTR(ret); 589: 590: ret = gmu_core_map_gmu(device, md, addr, vma_id, attrs, align); 591: 592: sg_free_table(md->sgt); 593: kfree(md->sgt); 594: md->sgt = NULL; 595: 596: if (!ret) { 597: gmu->global_entries++; 598: } else { 599: dev_err(GMU_PDEV_DEV(device), 600: "Unable to map GMU kernel block: addr:0x%08x size:0x%llx :%d\n", 601: addr, md->size, ret); 602: memset(md, 0x0, sizeof(*md)); 603: md = ERR_PTR(ret); 604: } 605: return md; 606: } 607: 608: int gmu_core_alloc_kernel_block(struct kgsl_device *device, 609: struct kgsl_memdesc *md, u32 size, u32 vma_id, int attrs) 610: { 611: int ret; 612: 613: ret = kgsl_allocate_kernel(device, md, size, 0, KGSL_MEMDESC_SYSMEM); 614: if (ret) 615: return ret; 616: 617: ret = gmu_core_map_gmu(device, md, 0, vma_id, attrs, 0); 618: if (ret) 619: kgsl_sharedmem_free(md); 620: 621: return ret; 622: } 623: 624: void gmu_core_free_block(struct kgsl_device *device, struct kgsl_memdesc *md) 625: { 626: struct gmu_core_device *gmu = &device->gmu_core; 627: int vma_id = gmu_core_find_vma_block(device, md->gmuaddr, md->size); 628: struct gmu_vma_entry *vma; 629: struct gmu_vma_node *vma_node; 630: 631: if ((vma_id < 0) || !vma_is_dynamic(device, vma_id)) 632: return; 633: 634: vma = &gmu->vma[vma_id]; 635: 636: /* 637: * Do not remove the vma node if we failed to unmap the entire buffer. This is because the 638: * iommu driver considers remapping an already mapped iova as fatal. 639: */ 640: if (md->size != iommu_unmap(device->gmu_core.domain, md->gmuaddr, md->size)) 641: goto free; 642: 643: spin_lock(&vma->lock); 644: vma_node = find_va(vma, md->gmuaddr, md->size); 645: if (vma_node) 646: rb_erase(&vma_node->node, &vma->vma_root); 647: spin_unlock(&vma->lock); 648: kfree(vma_node); 649: free: 650: kgsl_sharedmem_free(md); 651: } 652: 653: int gmu_core_process_prealloc(struct kgsl_device *device, struct gmu_block_header *blk) 654: { 655: struct kgsl_memdesc *md; 656: int id = gmu_core_find_vma_block(device, blk->addr, blk->value); 657: 658: if (id < 0) { 659: dev_err(GMU_PDEV_DEV(device), 660: "Invalid prealloc block addr: 0x%x value:%d\n", 661: blk->addr, blk->value); 662: return id; 663: } 664: 665: /* Nothing to do for TCM blocks or user uncached */ 666: if (id == GMU_ITCM || id == GMU_DTCM || id == GMU_NONCACHED_USER) 667: return 0; 668: 669: /* Check if the block is already allocated */ 670: md = gmu_core_find_memdesc(device, blk->addr, blk->value); 671: if (md != NULL) 672: return 0; 673: 674: md = gmu_core_reserve_kernel_block(device, blk->addr, blk->value, id, 0); 675: 676: return PTR_ERR_OR_ZERO(md); 677: } 678: 679: static int gmu_core_iommu_fault_handler(struct iommu_domain *domain, 680: struct device *dev, unsigned long addr, int flags, void *token) 681: { 682: char *fault_type = "unknown"; 683: 684: if (flags & IOMMU_FAULT_TRANSLATION) 685: fault_type = "translation"; 686: else if (flags & IOMMU_FAULT_PERMISSION) 687: fault_type = "permission"; 688: else if (flags & IOMMU_FAULT_EXTERNAL) 689: fault_type = "external"; 690: else if (flags & IOMMU_FAULT_TRANSACTION_STALLED) 691: fault_type = "transaction stalled"; 692: 693: dev_err(dev, "GMU fault addr = %lX, context=kernel (%s %s fault)\n", 694: addr, (flags & IOMMU_FAULT_WRITE) ? "write" : "read", fault_type); MATCH LINES: 755, 776 743: 744: return ret; 745: } 746: 747: void gmu_core_dev_force_first_boot(struct kgsl_device *device) 748: { 749: const struct gmu_dev_ops *ops = GMU_DEVICE_OPS(device); 750: 751: if (ops && ops->force_first_boot) 752: return ops->force_first_boot(device); 753: } 754: 755: int gmu_core_set_vrb_register(struct kgsl_memdesc *vrb, u32 index, u32 val) 756: { 757: u32 *vrb_buf; 758: 759: if (WARN_ON(IS_ERR_OR_NULL(vrb))) 760: return -ENODEV; 761: 762: if (WARN_ON(index >= (vrb->size >> 2))) { 763: pr_err("kgsl: Unable to set VRB register for index %u\n", index); 764: return -EINVAL; 765: } 766: 767: vrb_buf = vrb->hostptr; 768: vrb_buf[index] = val; 769: 770: /* Make sure the vrb write is posted before moving ahead */ 771: wmb(); 772: 773: return 0; 774: } 775: 776: int gmu_core_get_vrb_register(struct kgsl_memdesc *vrb, u32 index, u32 *val) 777: { 778: u32 *vrb_buf; 779: 780: if (IS_ERR_OR_NULL(vrb)) 781: return -ENODEV; 782: 783: if (WARN_ON(index >= (vrb->size >> 2))) { 784: pr_err("kgsl: Unable to get VRB register for index %u\n", index); 785: return -EINVAL; 786: } 787: 788: vrb_buf = vrb->hostptr; 789: *val = vrb_buf[index]; 790: 791: return 0; 792: } 793: 794: static void _gmu_trace_dcvs_pwrlevel(struct kgsl_device *device, struct gmu_trace_packet *pkt) 795: { 796: struct trace_dcvs_pwrlvl *data = (struct trace_dcvs_pwrlvl *)pkt->payload; 797: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 798: 799: /* 800: * After a slumber, gmu will have the previous power level as num_pwrlevels. --- FILE: \kgsl_gmu_core.h | HITS: 33 --- MATCH LINES: 12 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: #ifndef __KGSL_GMU_CORE_H 7: #define __KGSL_GMU_CORE_H 8: 9: #include 10: #include 11: 12: #include "kgsl_sharedmem.h" 13: 14: /* GMU_DEVICE - Given an KGSL device return the GMU specific struct */ 15: #define GMU_DEVICE_OPS(_a) ((_a)->gmu_core.dev_ops) 16: 17: /* GMU_PDEV - Given a KGSL device return the GMU platform device struct */ 18: #define GMU_PDEV(device) ((device)->gmu_core.pdev) 19: 20: /* GMU_PDEV_DEV - Given a KGSL device return pointer to struct dev for GMU platform device */ 21: #define GMU_PDEV_DEV(device) (&((GMU_PDEV(device))->dev)) 22: 23: #define MAX_GX_LEVELS 32 24: #define MAX_GX_LEVELS_LEGACY 16 25: #define MAX_CX_LEVELS 16 26: #define MAX_CX_LEVELS_LEGACY 4 27: #define MAX_BW_LEVELS 16 28: #define MAX_CNOC_LEVELS 2 29: #define MAX_CNOC_CMDS 6 30: #define MAX_BW_CMDS 8 31: #define INVALID_DCVS_IDX 0xFF 32: #define INVALID_AB_VALUE 0xFFFF 33: #define MAX_AB_VALUE (0xFFFF - 1) 34: #define INVALID_BW_VOTE (INVALID_DCVS_IDX | \ 35: (FIELD_PREP(GENMASK(31, 16), INVALID_AB_VALUE))) 36: #if MAX_CNOC_LEVELS > MAX_GX_LEVELS MATCH LINES: 416, 423, 439, 445 404: 405: struct trace_dcvs_profile { 406: u32 action; 407: u32 profile; 408: struct kgsl_dcvs_attrs attrs; 409: } __packed; 410: 411: /** 412: * struct kgsl_gmu_trace - wrapper for gmu trace memory object 413: */ 414: struct kgsl_gmu_trace { 415: /** @md: gmu trace memory descriptor */ 416: struct kgsl_memdesc *md; 417: /* @seq_num: GMU trace packet sequence number to detect drop packet count */ 418: u16 seq_num; 419: /* @reset_hdr: To reset trace buffer header incase of invalid packet */ 420: bool reset_hdr; 421: }; 422: 423: /* GMU memdesc entries */ 424: #define GMU_KERNEL_ENTRIES 32 425: 426: enum gmu_mem_type { 427: GMU_ITCM = 0, 428: GMU_ICACHE, 429: GMU_CACHE = GMU_ICACHE, 430: GMU_DTCM, 431: GMU_DCACHE, 432: GMU_NONCACHED_KERNEL, /* GMU VBIF3 uncached VA range: 0x60000000 - 0x7fffffff */ 433: GMU_NONCACHED_KERNEL_EXTENDED, /* GMU VBIF3 uncached VA range: 0xc0000000 - 0xdfffffff */ 434: GMU_NONCACHED_USER, 435: GMU_MEM_TYPE_MAX, 436: }; 437: 438: /** 439: * struct gmu_memdesc - Gmu shared memory object descriptor 440: * @hostptr: Kernel virtual address 441: * @gmuaddr: GPU virtual address 442: * @physaddr: Physical address of the memory object 443: * @size: Size of the memory object 444: */ 445: struct gmu_memdesc { 446: void *hostptr; 447: u32 gmuaddr; 448: phys_addr_t physaddr; 449: u32 size; 450: }; 451: 452: struct kgsl_mailbox { 453: struct mbox_client client; 454: struct mbox_chan *channel; 455: }; 456: 457: struct icc_path; 458: 459: struct gmu_vma_node { 460: struct rb_node node; 461: u32 va; 462: u32 size; 463: }; 464: 465: struct gmu_vma_entry { 466: /** @start: Starting virtual address of the vma */ 467: u32 start; 468: /** @size: Size of this vma */ 469: u32 size; MATCH LINES: 567 555: void *ptr; 556: const struct gmu_dev_ops *dev_ops; 557: unsigned long flags; 558: /** @gf_panic: GMU fault panic policy */ 559: enum gmu_fault_panic_policy gf_panic; 560: /** @pdev: platform device for the gmu */ 561: struct platform_device *pdev; 562: /** @domain: IOMMU domain for the gmu context */ 563: struct iommu_domain *domain; 564: /** @group: IOMMU group for the gmu context */ 565: struct iommu_group *group; 566: /** @gmu_globals: Array to store gmu global buffers */ 567: struct kgsl_memdesc gmu_globals[GMU_KERNEL_ENTRIES]; 568: /** @global_entries: To keep track of number of gmu buffers */ 569: u32 global_entries; 570: /** @vma: VMA entry for GMU */ 571: struct gmu_vma_entry *vma; 572: /** @num_vmas: Number of entries in the @vma array */ 573: u32 num_vmas; 574: /** @common_caps: GMU firmware common capabilities */ 575: struct firmware_capabilities common_caps; 576: /** @platform_caps: GMU firmware platform capabilities */ 577: struct firmware_capabilities platform_caps; 578: /* @ver: GMU Version information */ 579: struct { 580: u32 core; 581: u32 core_dev; 582: u32 pwr; 583: u32 pwr_dev; 584: u32 hfi; 585: } ver; 586: /** @warmboot_enabled: True if warmboot is enabled */ 587: bool warmboot_enabled; 588: /** @rdpm_cx_virt: Pointer where the RDPM CX block is mapped */ 589: void __iomem *rdpm_cx_virt; 590: /** @rdpm_mx_virt: Pointer where the RDPM MX block is mapped */ 591: void __iomem *rdpm_mx_virt; MATCH LINES: 624 612: u32 cur_level; 613: /** @hub_freqs: Array of GMU hub frequencies */ 614: u32 hub_freqs[MAX_CX_LEVELS]; 615: /** @hub_vlvls: Array of GMU hub voltage levels */ 616: u32 hub_vlvls[MAX_CX_LEVELS]; 617: /** @num_hub_freqs: Number of entries in the @hub_freqs array */ 618: int num_hub_freqs; 619: /** @cur_hub_level: Tracks current frequency level for hub clock */ 620: u32 cur_hub_level; 621: /** @gpu_pwrscale_enable: Flag to toggle GMU based DCVS pwrscale */ 622: bool gpu_pwrscale_enable; 623: /** @vrb: GMU virtual register bank memory */ 624: struct kgsl_memdesc *vrb; 625: /** @trace: gmu trace container */ 626: struct kgsl_gmu_trace trace; 627: }; 628: 629: extern struct platform_driver a6xx_gmu_driver; 630: extern struct platform_driver a6xx_rgmu_driver; 631: extern struct platform_driver gen7_gmu_driver; 632: extern struct platform_driver gen8_gmu_driver; 633: 634: /* GMU core functions */ 635: 636: void __init gmu_core_register(void); 637: void gmu_core_unregister(void); 638: 639: bool gmu_core_gpmu_isenabled(struct kgsl_device *device); 640: bool gmu_core_scales_bandwidth(struct kgsl_device *device); 641: bool gmu_core_isenabled(struct kgsl_device *device); 642: int gmu_core_dev_acd_set(struct kgsl_device *device, bool val); 643: void gmu_core_regread(struct kgsl_device *device, unsigned int offsetwords, 644: unsigned int *value); 645: void gmu_core_regwrite(struct kgsl_device *device, unsigned int offsetwords, 646: unsigned int value); 647: 648: /** MATCH LINES: 697, 702, 703, 709, 711, 717, 721, 723, 724, 725, 727, 731, 735, 740, 742, 755, 790, 807, 813, 823, 828, 830, 859, 869 685: * as expected. 686: * 687: * @device: Pointer to KGSL device 688: * @offset: Register offset in dwords 689: * @expected_ret: expected register value that stops polling 690: * @timeout_ms: time in milliseconds to poll the register 691: * @mask: bitmask to filter register value to match expected_ret 692: */ 693: int gmu_core_timed_poll_check(struct kgsl_device *device, 694: unsigned int offset, unsigned int expected_ret, 695: unsigned int timeout_ms, unsigned int mask); 696: 697: struct kgsl_memdesc; 698: struct iommu_domain; 699: struct hfi_mem_alloc_entry; 700: 701: struct gmu_mem_type_desc { 702: /** @memdesc: Pointer to the memory descriptor */ 703: struct kgsl_memdesc *memdesc; 704: /** @type: Type of the memory descriptor */ 705: u32 type; 706: }; 707: 708: /** 709: * gmu_core_map_memdesc - Map the memdesc into the GMU IOMMU domain 710: * @domain: Domain to map the memory into 711: * @memdesc: Memory descriptor to map 712: * @gmuaddr: Virtual GMU address to map the memory into 713: * @attrs: Attributes for the mapping 714: * 715: * Return: 0 on success or -ENOMEM on failure 716: */ 717: int gmu_core_map_memdesc(struct iommu_domain *domain, struct kgsl_memdesc *memdesc, 718: u64 gmuaddr, int attrs); 719: 720: /** 721: * gmu_core_map_gmu - Map a kgsl memdesc to GMU 722: * @device: Pointer to kgsl device 723: * @md: Pointer to the kgsl memdesc 724: * @addr: Address where to map this memdesc 725: * @vma_id: VMA id to which this memdesc needs to be mapped 726: * @attrs: mapping attributes 727: * @align: Alignment request for this memdesc 728: 729: * Return: Zero on success or negative error on failure. 730: */ 731: int gmu_core_map_gmu(struct kgsl_device *device, struct kgsl_memdesc *md, 732: u32 addr, u32 vma_id, int attrs, u32 align); 733: 734: /** 735: * gmu_core_find_memdesc - Find the GMU memory descriptor for a given address and size 736: * @device: Pointer to KGSL device 737: * @addr: Address of the memory region 738: * @size: Size of the memory region 739: * 740: * Return: Pointer to the matching kgsl_memdesc structure if found, NULL otherwise. 741: */ 742: struct kgsl_memdesc *gmu_core_find_memdesc(struct kgsl_device *device, u32 addr, u32 size); 743: 744: /** 745: * gmu_core_find_vma_block - Find the VMA block for a given address and size 746: * @device: Pointer to KGSL device 747: * @addr: Address of the memory region 748: * @size: Size of the memory region 749: * 750: * Return: The index of the matching VMA entry if found, -ENOENT otherwise. 751: */ 752: int gmu_core_find_vma_block(struct kgsl_device *device, u32 addr, u32 size); 753: 754: /** 755: * gmu_core_free_globals - Free the GMU global memory descriptors 756: * @device: Pointer to KGSL device 757: */ 758: void gmu_core_free_globals(struct kgsl_device *device); 759: 760: /** 761: * gmu_core_get_attrs - Get the IOMMU attributes based on flags 762: * @flags: The memory flags indicating the attributes 763: * 764: * Return: IOMMU attributes. 765: */ 766: int gmu_core_get_attrs(u32 flags); 767: 768: /** 769: * gmu_core_import_buffer - Import a gmu buffer 770: * @device: Pointer to KGSL device 771: * @entry: GMU memory entry 772: * This function imports and maps a buffer to a gmu vma 773: * 774: * Return: 0 on success or error code on failure 775: */ 776: int gmu_core_import_buffer(struct kgsl_device *device, struct hfi_mem_alloc_entry *entry); 777: 778: /** 779: * gmu_core_reserve_kernel_block - Allocate a gmu buffer 780: * @device: Pointer to KGSL device 781: * @addr: Desired gmu virtual address 782: * @size: Size of the buffer in bytes 783: * @vma_id: Target gmu vma where this buffer should be mapped 784: * @align: Alignment as a power of two(2^n) bytes for the GMU VA 785: * 786: * This function allocates a buffer and maps it in the desired gmu vma 787: * 788: * Return: Pointer to the memory descriptor or error pointer on failure 789: */ 790: struct kgsl_memdesc *gmu_core_reserve_kernel_block(struct kgsl_device *device, 791: u32 addr, u32 size, u32 vma_id, u32 align); 792: 793: /** 794: * gmu_core_reserve_kernel_block_fixed - Maps phyical resource address to gmu 795: * @device: Pointer to KGSL device 796: * @addr: Desired gmu virtual address 797: * @size: Size of the buffer in bytes 798: * @vma_id: Target gmu vma where this buffer should be mapped 799: * @resource: Name of the resource to get the size and address to allocate 800: * @attrs: Attributes for the mapping 801: * @align: Alignment as a power of two(2^n) bytes for the GMU VA 802: * 803: * This function maps the physcial resource address to desired gmu vma 804: * 805: * Return: Pointer to the memory descriptor or error pointer on failure 806: */ 807: struct kgsl_memdesc *gmu_core_reserve_kernel_block_fixed(struct kgsl_device *device, 808: u32 addr, u32 size, u32 vma_id, const char *resource, int attrs, u32 align); 809: 810: /** 811: * gmu_core_alloc_kernel_block - Allocate a gmu buffer 812: * @device: Pointer to KGSL device 813: * @md: Pointer to the memdesc 814: * @size: Size of the buffer in bytes 815: * @vma_id: Target gmu vma where this buffer should be mapped 816: * @attrs: Attributes for the mapping 817: * 818: * This function allocates a buffer and maps it in the desired gmu vma 819: * 820: * Return: 0 on success or error code on failure 821: */ 822: int gmu_core_alloc_kernel_block(struct kgsl_device *device, 823: struct kgsl_memdesc *md, u32 size, u32 vma_id, int attrs); 824: 825: /** 826: * gmu_core_free_block - Free a gmu buffer 827: * @device: Pointer to KGSL device 828: * @md: Pointer to the memdesc that is to be freed 829: */ 830: void gmu_core_free_block(struct kgsl_device *device, struct kgsl_memdesc *md); 831: 832: /** 833: * gmu_core_process_prealloc - Process preallocate GMU blocks 834: * @device: Pointer to the KGSL device structure 835: * @blk: Pointer to the GMU block header structure 836: * 837: * Return: 0 on success, negative error code on failure. 838: */ 839: int gmu_core_process_prealloc(struct kgsl_device *device, struct gmu_block_header *blk); 840: 841: /** 842: * gmu_core_iommu_init - Set up GMU IOMMU and shared memory with GMU 843: * @device: Pointer to KGSL device 844: * 845: * Return: 0 on success or error value on failure 846: */ 847: int gmu_core_iommu_init(struct kgsl_device *device); 848: 849: void gmu_core_dev_force_first_boot(struct kgsl_device *device); 850: 851: /** 852: * gmu_core_set_vrb_register - set vrb register value at specified index 853: * @vrb: GMU virtual register bank memory 854: * @index: vrb index to write the value 855: * @val: value to be writen into vrb 856: * 857: * Return: Negative error on failure and zero on success. 858: */ 859: int gmu_core_set_vrb_register(struct kgsl_memdesc *vrb, u32 index, u32 val); 860: 861: /** 862: * gmu_core_get_vrb_register - get vrb register value at specified index 863: * @vrb: GMU virtual register bank memory 864: * @index: vrb index to write the value 865: * @val: Pointer to update the data after reading from vrb 866: * 867: * Return: Negative error on failure and zero on success. 868: */ 869: int gmu_core_get_vrb_register(struct kgsl_memdesc *vrb, u32 index, u32 *val); 870: 871: /** 872: * gmu_core_process_trace_data - Process gmu trace buffer data writes to default linux trace buffer 873: * @device: Pointer to KGSL device 874: * @dev: GMU device instance 875: * @trace: GMU trace memory pointer 876: */ 877: void gmu_core_process_trace_data(struct kgsl_device *device, 878: struct device *dev, struct kgsl_gmu_trace *trace); 879: 880: /** 881: * gmu_core_is_trace_empty - Check for trace buffer empty/full status 882: * @hdr: Pointer to gmu trace header 883: * 884: * Return: true if readidex equl to writeindex else false 885: */ 886: bool gmu_core_is_trace_empty(struct gmu_trace_header *hdr); 887: 888: /** 889: * gmu_core_trace_header_init - Initialize the GMU trace buffer header 890: * @trace: Pointer to kgsl gmu trace 891: */ 892: void gmu_core_trace_header_init(struct kgsl_gmu_trace *trace); 893: MATCH LINES: 928, 936 916: bool gmu_core_capabilities_enabled(struct firmware_capabilities *caps, u32 field); 917: 918: /** 919: * gmu_core_mark_for_coldboot - Set a flag to coldboot gpu in the slumber exit 920: * @device: Pointer to KGSL device 921: * 922: */ 923: void gmu_core_mark_for_coldboot(struct kgsl_device *device); 924: 925: /** 926: * gmu_core_reserve_gmuaddr() - Reserve a gmuaddr in the GMU VA space 927: * @device: Pointer to the kgsl device 928: * @md: Pointer to the memdesc 929: * @vma_id: Target gmu vma where this buffer should be mapped 930: * @align: Alignment for the GMU VA and GMU mapping size 931: * 932: * This function reserves a gmu address based on the input parameters 933: * 934: * Return: 0 on success or negative error on failure 935: */ 936: int gmu_core_reserve_gmuaddr(struct kgsl_device *device, struct kgsl_memdesc *md, 937: u32 vma_id, u32 align); 938: 939: /** 940: * gmu_core_rdpm_probe - Probe GMU RDPM resources 941: * @device: Pointer to KGSL device 942: */ 943: void gmu_core_rdpm_probe(struct kgsl_device *device); 944: 945: /** 946: * gmu_core_rdpm_mx_freq_update - Update the mx frequency 947: * @device: Pointer to KGSL device 948: * @freq: Frequency in KHz 949: * 950: * This function communicates GPU mx frequency(in Mhz) changes to rdpm. 951: */ 952: void gmu_core_rdpm_mx_freq_update(struct kgsl_device *device, u32 freq); 953: 954: /** 955: * gmu_core_rdpm_cx_freq_update - Update the cx frequency 956: * @device: Pointer to KGSL device 957: * @freq: Frequency in KHz 958: * 959: * This function communicates GPU cx frequency(in Mhz) changes to rdpm. 960: */ --- FILE: \kgsl_ioctl.c | HITS: 8 --- MATCH LINES: 23, 24, 25, 32, 34, 35, 36, 37 11: KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_GETPROPERTY, 12: kgsl_ioctl_device_getproperty), 13: /* IOCTL_KGSL_DEVICE_WAITTIMESTAMP is no longer supported */ 14: KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID, 15: kgsl_ioctl_device_waittimestamp_ctxtid), 16: KGSL_IOCTL_FUNC(IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS, 17: kgsl_ioctl_rb_issueibcmds), 18: KGSL_IOCTL_FUNC(IOCTL_KGSL_SUBMIT_COMMANDS, 19: kgsl_ioctl_submit_commands), 20: /* IOCTL_KGSL_CMDSTREAM_READTIMESTAMP is no longer supported */ 21: KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID, 22: kgsl_ioctl_cmdstream_readtimestamp_ctxtid), 23: /* IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP is no longer supported */ 24: KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID, 25: kgsl_ioctl_cmdstream_freememontimestamp_ctxtid), 26: KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_CREATE, 27: kgsl_ioctl_drawctxt_create), 28: KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_DESTROY, 29: kgsl_ioctl_drawctxt_destroy), 30: KGSL_IOCTL_FUNC(IOCTL_KGSL_MAP_USER_MEM, 31: kgsl_ioctl_map_user_mem), 32: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FROM_PMEM, 33: kgsl_ioctl_map_user_mem), 34: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FREE, 35: kgsl_ioctl_sharedmem_free), 36: KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE, 37: kgsl_ioctl_sharedmem_flush_cache), 38: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_ALLOC, 39: kgsl_ioctl_gpumem_alloc), 40: KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMESTAMP_EVENT, 41: kgsl_ioctl_timestamp_event), 42: KGSL_IOCTL_FUNC(IOCTL_KGSL_SETPROPERTY, 43: kgsl_ioctl_device_setproperty), 44: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_ALLOC_ID, 45: kgsl_ioctl_gpumem_alloc_id), 46: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_FREE_ID, 47: kgsl_ioctl_gpumem_free_id), 48: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_GET_INFO, 49: kgsl_ioctl_gpumem_get_info), 50: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_SYNC_CACHE, 51: kgsl_ioctl_gpumem_sync_cache), 52: KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_SYNC_CACHE_BULK, 53: kgsl_ioctl_gpumem_sync_cache_bulk), 54: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_CREATE, 55: kgsl_ioctl_syncsource_create), 56: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_DESTROY, 57: kgsl_ioctl_syncsource_destroy), 58: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_CREATE_FENCE, 59: kgsl_ioctl_syncsource_create_fence), 60: KGSL_IOCTL_FUNC(IOCTL_KGSL_SYNCSOURCE_SIGNAL_FENCE, 61: kgsl_ioctl_syncsource_signal_fence), --- FILE: \kgsl_iommu.c | HITS: 184 --- MATCH LINES: 37 25: #if IS_ENABLED(CONFIG_QCOM_SCM_ADDON) 26: #include 27: #endif 28: #include 29: #include 30: #include 31: 32: #include "adreno.h" 33: #include "kgsl_device.h" 34: #include "kgsl_iommu.h" 35: #include "kgsl_mmu.h" 36: #include "kgsl_pwrctrl.h" 37: #include "kgsl_sharedmem.h" 38: #include "kgsl_trace.h" 39: 40: #define KGSL_IOMMU_SPLIT_TABLE_BASE 0x0001ff8000000000ULL 41: 42: #define KGSL_IOMMU_IDR1_OFFSET 0x24 43: #define IDR1_NUMPAGENDXB GENMASK(30, 28) 44: #define IDR1_PAGESIZE BIT(31) 45: 46: static const struct kgsl_mmu_pt_ops secure_pt_ops; 47: static const struct kgsl_mmu_pt_ops default_pt_ops; 48: static const struct kgsl_mmu_pt_ops iopgtbl_pt_ops; 49: 50: /* Zero page for non-secure VBOs */ 51: static struct page *kgsl_vbo_zero_page; 52: 53: /* 54: * struct kgsl_iommu_addr_entry - entry in the kgsl_pagetable rbtree. 55: * @base: starting virtual address of the entry 56: * @size: size of the entry 57: * @node: the rbtree node 58: */ 59: struct kgsl_iommu_addr_entry { 60: uint64_t base; 61: uint64_t size; MATCH LINES: 116, 122, 125, 128, 131, 137, 138 104: if (!test_bit(KGSL_MMU_LLCC_ENABLE, &mmu->features)) 105: return 0; 106: 107: /* Return no-write-allocate if mmu feature for no-write-allocate is set */ 108: if (test_bit(KGSL_MMU_FORCE_LLCC_NWA, &mmu->features)) 109: return IOMMU_SYS_CACHE_NWA; 110: 111: /* Return 0 as default llcc allocation policy */ 112: return 0; 113: } 114: 115: static int _iommu_get_protection_flags(struct kgsl_mmu *mmu, 116: struct kgsl_memdesc *memdesc) 117: { 118: int flags = IOMMU_READ | IOMMU_WRITE | IOMMU_NOEXEC; 119: 120: flags |= get_llcc_flags(mmu); 121: 122: if (memdesc->flags & KGSL_MEMFLAGS_GPUREADONLY) 123: flags &= ~IOMMU_WRITE; 124: 125: if (TEST_FLAG(KGSL_MEMDESC_PRIVILEGED, &memdesc->priv)) 126: flags |= IOMMU_PRIV; 127: 128: if (memdesc->flags & KGSL_MEMFLAGS_IOCOHERENT) 129: flags |= IOMMU_CACHE; 130: 131: if (TEST_FLAG(KGSL_MEMDESC_UCODE, &memdesc->priv)) 132: flags &= ~IOMMU_NOEXEC; 133: 134: return flags; 135: } 136: 137: /* Get a scattterlist for the subrange in the child memdesc */ 138: static int get_sg_from_child(struct sg_table *sgt, struct kgsl_memdesc *child, 139: u64 offset, u64 length) 140: { 141: int npages = (length >> PAGE_SHIFT); 142: int pgoffset = (offset >> PAGE_SHIFT); 143: struct scatterlist *target_sg; 144: struct sg_page_iter iter; 145: int i = 0, ret; 146: 147: if (child->pages) 148: return sg_alloc_table_from_pages(sgt, 149: child->pages + pgoffset, npages, 0, 150: length, GFP_KERNEL); 151: 152: ret = sg_alloc_table(sgt, npages, GFP_KERNEL); 153: if (ret) 154: return ret; 155: 156: target_sg = sgt->sgl; 157: 158: for_each_sgtable_page(child->sgt, &iter, pgoffset) { 159: sg_set_page(target_sg, sg_page_iter_page(&iter), PAGE_SIZE, 0); 160: target_sg = sg_next(target_sg); 161: 162: if (++i == npages) MATCH LINES: 186, 188 174: static struct kgsl_iommu *to_kgsl_iommu(struct kgsl_pagetable *pt) 175: { 176: return &pt->mmu->iommu; 177: } 178: 179: /* 180: * One page allocation for a guard region to protect against over-zealous 181: * GPU pre-fetch 182: */ 183: static struct page *kgsl_guard_page; 184: static struct page *kgsl_secure_guard_page; 185: 186: static struct page *iommu_get_guard_page(struct kgsl_memdesc *memdesc) 187: { 188: if (kgsl_memdesc_is_secured(memdesc)) { 189: if (!kgsl_secure_guard_page) 190: kgsl_secure_guard_page = kgsl_alloc_secure_page(); 191: 192: return kgsl_secure_guard_page; 193: } 194: 195: if (!kgsl_guard_page) 196: kgsl_guard_page = alloc_page(GFP_KERNEL | __GFP_ZERO | 197: __GFP_NORETRY | __GFP_HIGHMEM); 198: 199: return kgsl_guard_page; 200: } 201: 202: static size_t iommu_pgsize(unsigned long pgsize_bitmap, unsigned long iova, 203: phys_addr_t paddr, size_t size, size_t *count) 204: { 205: unsigned int pgsize_idx, pgsize_idx_next; 206: unsigned long pgsizes; 207: size_t offset, pgsize, pgsize_next; 208: unsigned long addr_merge = paddr | iova; 209: 210: /* Page sizes supported by the hardware and small enough for @size */ 211: pgsizes = pgsize_bitmap & GENMASK(__fls(size), 0); 212: MATCH LINES: 273, 283, 287, 293, 304, 309, 316, 325, 331, 349 261: 262: iommu_flush_iotlb_all(to_iommu_domain(&iommu->user_context)); 263: 264: /* As LPAC is optional, check LPAC domain is present before flush */ 265: if (iommu->lpac_context.domain) 266: iommu_flush_iotlb_all(to_iommu_domain(&iommu->lpac_context)); 267: 268: /* Flush iotbl for GMU domian */ 269: if (device->gmu_core.domain) 270: iommu_flush_iotlb_all(device->gmu_core.domain); 271: } 272: 273: static int _iopgtbl_unmap(struct kgsl_iommu_pt *pt, u64 gpuaddr, size_t size) 274: { 275: struct io_pgtable_ops *ops = pt->pgtbl_ops; 276: size_t unmapped = 0; 277: 278: while (unmapped < size) { 279: size_t ret, size_to_unmap, remaining, pgcount; 280: 281: remaining = (size - unmapped); 282: size_to_unmap = iommu_pgsize(pt->cfg.pgsize_bitmap, 283: gpuaddr, gpuaddr, remaining, &pgcount); 284: if (size_to_unmap == 0) 285: break; 286: 287: ret = ops->unmap_pages(ops, gpuaddr, size_to_unmap, 288: pgcount, NULL); 289: 290: if (ret == 0) 291: break; 292: 293: gpuaddr += ret; 294: unmapped += ret; 295: } 296: 297: if (unmapped != size) 298: return -EINVAL; 299: 300: kgsl_iommu_flush_tlb(pt->base.mmu); 301: return 0; 302: } 303: 304: static size_t _iopgtbl_map_pages(struct kgsl_iommu_pt *pt, u64 gpuaddr, 305: struct page **pages, int npages, int prot) 306: { 307: struct io_pgtable_ops *ops = pt->pgtbl_ops; 308: size_t mapped = 0; 309: u64 addr = gpuaddr; 310: int ret, i; 311: 312: for (i = 0; i < npages; i++) { 313: ret = ops->map_pages(ops, addr, page_to_phys(pages[i]), PAGE_SIZE, 1, 314: prot, GFP_KERNEL, &mapped); 315: if (ret) { 316: _iopgtbl_unmap(pt, gpuaddr, mapped); 317: return 0; 318: } 319: addr += PAGE_SIZE; 320: } 321: 322: return mapped; 323: } 324: 325: static size_t _iopgtbl_map_sg(struct kgsl_iommu_pt *pt, u64 gpuaddr, 326: struct sg_table *sgt, int prot) 327: { 328: struct io_pgtable_ops *ops = pt->pgtbl_ops; 329: struct scatterlist *sg; 330: size_t mapped = 0; 331: u64 addr = gpuaddr; 332: int ret, i; 333: 334: for_each_sg(sgt->sgl, sg, sgt->nents, i) { 335: size_t size = sg->length; 336: phys_addr_t phys = sg_phys(sg); 337: 338: while (size) { 339: size_t count, map_size = 0; 340: size_t pgsize = iommu_pgsize(pt->cfg.pgsize_bitmap, 341: addr, phys, size, &count); 342: 343: ret = ops->map_pages(ops, addr, phys, pgsize, count, 344: prot, GFP_KERNEL, &map_size); 345: 346: mapped += map_size; 347: 348: if (ret) { 349: _iopgtbl_unmap(pt, gpuaddr, mapped); 350: return 0; 351: } 352: 353: addr += map_size; 354: phys += map_size; 355: size -= map_size; 356: } 357: 358: } 359: 360: return mapped; 361: } 362: 363: static void kgsl_iommu_send_tlb_hint(struct kgsl_mmu *mmu, bool hint) 364: { 365: struct kgsl_device *device = KGSL_MMU_DEVICE(mmu); 366: struct kgsl_iommu *iommu = &mmu->iommu; 367: 368: /* 369: * Send skip TLB hints for user context, LPAC context, and GMU domains 370: * to the SMMU driver to skip TLB operations during slumber. This will 371: * help avoid unnecessary CX GDSC toggling. 372: */ 373: qcom_skip_tlb_management(&iommu->user_context.pdev->dev, hint); MATCH LINES: 388, 389, 404, 413, 416, 417, 420, 425, 429, 436, 448, 464, 465, 468, 476, 483, 485, 486, 487, 489, 490, 495, 498, 503, 507, 516, 518, 519, 540, 543, 549, 550, 562, 574, 578, 579, 581, 586, 588, 594, 595, 598, 599, 600, 604, 605, 609, 617, 620, 625, 628, 637, 642, 656, 658, 661, 662, 667, 674, 675, 680, 686, 690, 698, 702, 706, 710, 716, 719, 720, 723, 726 376: if (device->gmu_core.domain) 377: qcom_skip_tlb_management(&device->gmu_core.pdev->dev, hint); 378: /* 379: * TLB operations are skipped during slumber. Incase CX doesn't 380: * go down, it can result in incorrect translations due to stale 381: * TLB entries. Flush TLB before boot up to ensure fresh start. 382: */ 383: if (!hint) 384: kgsl_iommu_flush_tlb(mmu); 385: } 386: 387: static int 388: kgsl_iopgtbl_map_child(struct kgsl_pagetable *pt, struct kgsl_memdesc *memdesc, 389: u64 offset, struct kgsl_memdesc *child, u64 child_offset, u64 length) 390: { 391: struct kgsl_iommu_pt *iommu_pt = to_iommu_pt(pt); 392: struct sg_table sgt; 393: u32 flags; 394: size_t mapped; 395: int ret; 396: 397: ret = get_sg_from_child(&sgt, child, child_offset, length); 398: if (ret) 399: return ret; 400: 401: /* Inherit the flags from the child for this mapping */ 402: flags = _iommu_get_protection_flags(pt->mmu, child); 403: 404: mapped = _iopgtbl_map_sg(iommu_pt, memdesc->gpuaddr + offset, &sgt, flags); 405: 406: sg_free_table(&sgt); 407: 408: return mapped ? 0 : -ENOMEM; 409: } 410: 411: 412: static int 413: kgsl_iopgtbl_unmap_range(struct kgsl_pagetable *pt, struct kgsl_memdesc *memdesc, 414: u64 offset, u64 length) 415: { 416: if (WARN_ON(offset >= memdesc->size || 417: (offset + length) > memdesc->size)) 418: return -ERANGE; 419: 420: return _iopgtbl_unmap(to_iommu_pt(pt), memdesc->gpuaddr + offset, 421: length); 422: } 423: 424: static size_t _iopgtbl_map_page_to_range(struct kgsl_iommu_pt *pt, 425: struct page *page, u64 gpuaddr, size_t range, int prot) 426: { 427: struct io_pgtable_ops *ops = pt->pgtbl_ops; 428: size_t mapped = 0; 429: u64 addr = gpuaddr; 430: int ret; 431: 432: while (range) { 433: ret = ops->map_pages(ops, addr, page_to_phys(page), PAGE_SIZE, 434: 1, prot, GFP_KERNEL, &mapped); 435: if (ret) { 436: _iopgtbl_unmap(pt, gpuaddr, mapped); 437: return 0; 438: } 439: 440: addr += PAGE_SIZE; 441: range -= PAGE_SIZE; 442: } 443: 444: return mapped; 445: } 446: 447: static int kgsl_iopgtbl_map_zero_page_to_range(struct kgsl_pagetable *pt, 448: struct kgsl_memdesc *memdesc, u64 offset, u64 length) 449: { 450: /* 451: * The SMMU only does the PRT compare at the bottom level of the page table, because 452: * there is not an easy way for the hardware to perform this check at earlier levels. 453: * Mark this page writable to avoid page faults while writing to it. Since the address 454: * of this zero page is programmed in PRR register, MMU will intercept any accesses to 455: * the page before they go to DDR and will terminate the transaction. 456: */ 457: u32 flags = IOMMU_READ | IOMMU_WRITE | IOMMU_NOEXEC | get_llcc_flags(pt->mmu); 458: struct kgsl_iommu_pt *iommu_pt = to_iommu_pt(pt); 459: struct page *page = kgsl_vbo_zero_page; 460: 461: if (WARN_ON(!page)) 462: return -ENODEV; 463: 464: if (WARN_ON((offset >= memdesc->size) || 465: (offset + length) > memdesc->size)) 466: return -ERANGE; 467: 468: if (!_iopgtbl_map_page_to_range(iommu_pt, page, memdesc->gpuaddr + offset, 469: length, flags)) 470: return -ENOMEM; 471: 472: return 0; 473: } 474: 475: static int kgsl_iopgtbl_map(struct kgsl_pagetable *pagetable, 476: struct kgsl_memdesc *memdesc) 477: { 478: struct kgsl_iommu_pt *pt = to_iommu_pt(pagetable); 479: size_t mapped, padding; 480: int prot; 481: 482: /* Get the protection flags for the user context */ 483: prot = _iommu_get_protection_flags(pagetable->mmu, memdesc); 484: 485: if (memdesc->sgt) 486: mapped = _iopgtbl_map_sg(pt, memdesc->gpuaddr, 487: memdesc->sgt, prot); 488: else 489: mapped = _iopgtbl_map_pages(pt, memdesc->gpuaddr, 490: memdesc->pages, memdesc->page_count, prot); 491: 492: if (mapped == 0) 493: return -ENOMEM; 494: 495: padding = kgsl_memdesc_footprint(memdesc) - mapped; 496: 497: if (padding) { 498: struct page *page = iommu_get_guard_page(memdesc); 499: size_t ret; 500: 501: if (page) 502: ret = _iopgtbl_map_page_to_range(pt, page, 503: memdesc->gpuaddr + mapped, padding, 504: prot & ~IOMMU_WRITE); 505: 506: if (!page || !ret) { 507: _iopgtbl_unmap(pt, memdesc->gpuaddr, mapped); 508: return -ENOMEM; 509: } 510: } 511: 512: return 0; 513: } 514: 515: static int kgsl_iopgtbl_unmap(struct kgsl_pagetable *pagetable, 516: struct kgsl_memdesc *memdesc) 517: { 518: return _iopgtbl_unmap(to_iommu_pt(pagetable), memdesc->gpuaddr, 519: kgsl_memdesc_footprint(memdesc)); 520: } 521: 522: static int _iommu_unmap(struct iommu_domain *domain, u64 addr, size_t size) 523: { 524: size_t unmapped = 0; 525: 526: if (!domain) 527: return 0; 528: 529: /* Sign extend TTBR1 addresses all the way to avoid warning */ 530: if (addr & (1ULL << 48)) 531: addr |= 0xffff000000000000; 532: 533: unmapped = iommu_unmap(domain, addr, size); 534: 535: return (unmapped == size) ? 0 : -ENOMEM; 536: } 537: 538: 539: static size_t _iommu_map_page_to_range(struct iommu_domain *domain, 540: struct page *page, u64 gpuaddr, size_t range, int prot) 541: { 542: size_t mapped = 0; 543: u64 addr = gpuaddr; 544: 545: if (!page) 546: return 0; 547: 548: /* Sign extend TTBR1 addresses all the way to avoid warning */ 549: if (gpuaddr & (1ULL << 48)) 550: gpuaddr |= 0xffff000000000000; 551: 552: 553: while (range) { 554: #if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) 555: int ret = iommu_map(domain, addr, page_to_phys(page), 556: PAGE_SIZE, prot, GFP_KERNEL); 557: #else 558: int ret = iommu_map(domain, addr, page_to_phys(page), 559: PAGE_SIZE, prot); 560: #endif 561: if (ret) { 562: iommu_unmap(domain, gpuaddr, mapped); 563: return 0; 564: } 565: 566: addr += PAGE_SIZE; 567: mapped += PAGE_SIZE; 568: range -= PAGE_SIZE; 569: } 570: 571: return mapped; 572: } 573: 574: static ssize_t _iommu_map_sg(struct iommu_domain *domain, u64 gpuaddr, 575: struct sg_table *sgt, int prot) 576: { 577: /* Sign extend TTBR1 addresses all the way to avoid warning */ 578: if (gpuaddr & (1ULL << 48)) 579: gpuaddr |= 0xffff000000000000; 580: 581: return kgsl_mmu_map_sg(domain, gpuaddr, sgt->sgl, sgt->orig_nents, prot); 582: } 583: 584: static int 585: _kgsl_iommu_map(struct kgsl_mmu *mmu, struct iommu_domain *domain, 586: struct kgsl_memdesc *memdesc) 587: { 588: int prot = _iommu_get_protection_flags(mmu, memdesc); 589: ssize_t mapped; 590: size_t padding; 591: int ret = 0; 592: 593: /* 594: * For paged memory allocated through kgsl, memdesc->pages is not NULL. 595: * Allocate sgt here just for its map operation. Contiguous memory 596: * already has its sgt, so no need to allocate it here. 597: */ 598: if (!memdesc->pages) { 599: mapped = _iommu_map_sg(domain, memdesc->gpuaddr, 600: memdesc->sgt, prot); 601: } else { 602: struct sg_table sgt; 603: 604: ret = sg_alloc_table_from_pages(&sgt, memdesc->pages, 605: memdesc->page_count, 0, memdesc->size, GFP_KERNEL); 606: if (ret) 607: return ret; 608: 609: mapped = _iommu_map_sg(domain, memdesc->gpuaddr, &sgt, prot); 610: sg_free_table(&sgt); 611: } 612: 613: /* Check for errors or no pages mapped */ 614: if (mapped <= 0) 615: return mapped ? mapped : -ENOMEM; 616: 617: padding = kgsl_memdesc_footprint(memdesc) - mapped; 618: 619: if (padding) { 620: struct page *page = iommu_get_guard_page(memdesc); 621: size_t guard_mapped; 622: 623: if (page) 624: guard_mapped = _iommu_map_page_to_range(domain, page, 625: memdesc->gpuaddr + mapped, padding, prot & ~IOMMU_WRITE); 626: 627: if (!page || !guard_mapped) { 628: _iommu_unmap(domain, memdesc->gpuaddr, mapped); 629: ret = -ENOMEM; 630: } 631: } 632: 633: return ret; 634: } 635: 636: static int kgsl_iommu_secure_map(struct kgsl_pagetable *pagetable, 637: struct kgsl_memdesc *memdesc) 638: { 639: struct kgsl_iommu *iommu = &pagetable->mmu->iommu; 640: struct iommu_domain *domain = to_iommu_domain(&iommu->secure_context); 641: 642: return _kgsl_iommu_map(pagetable->mmu, domain, memdesc); 643: } 644: 645: /* 646: * Return true if the address is in the TTBR0 region. This is used for cases 647: * when the "default" pagetable is used for both TTBR0 and TTBR1 648: */ 649: static bool is_lower_address(struct kgsl_mmu *mmu, u64 addr) 650: { 651: return (test_bit(KGSL_MMU_IOPGTABLE, &mmu->features) && 652: addr < KGSL_IOMMU_SPLIT_TABLE_BASE); 653: } 654: 655: static int _kgsl_iommu_unmap(struct iommu_domain *domain, 656: struct kgsl_memdesc *memdesc) 657: { 658: if (memdesc->size == 0 || memdesc->gpuaddr == 0) 659: return -EINVAL; 660: 661: return _iommu_unmap(domain, memdesc->gpuaddr, 662: kgsl_memdesc_footprint(memdesc)); 663: } 664: 665: /* Map on the default pagetable and the LPAC pagetable if it exists */ 666: static int kgsl_iommu_default_map(struct kgsl_pagetable *pagetable, 667: struct kgsl_memdesc *memdesc) 668: { 669: struct kgsl_mmu *mmu = pagetable->mmu; 670: struct kgsl_iommu *iommu = &mmu->iommu; 671: struct iommu_domain *domain, *lpac; 672: int ret; 673: 674: if (is_lower_address(mmu, memdesc->gpuaddr)) 675: return kgsl_iopgtbl_map(pagetable, memdesc); 676: 677: domain = to_iommu_domain(&iommu->user_context); 678: 679: /* Map the object to the default GPU domain */ 680: ret = _kgsl_iommu_map(mmu, domain, memdesc); 681: 682: /* Also map the object to the LPAC domain if it exists */ 683: lpac = to_iommu_domain(&iommu->lpac_context); 684: 685: if (!ret && lpac) { 686: ret = _kgsl_iommu_map(mmu, lpac, memdesc); 687: 688: /* On failure, also unmap from the default domain */ 689: if (ret) 690: _kgsl_iommu_unmap(domain, memdesc); 691: 692: } 693: 694: return ret; 695: } 696: 697: static int kgsl_iommu_secure_unmap(struct kgsl_pagetable *pagetable, 698: struct kgsl_memdesc *memdesc) 699: { 700: struct kgsl_iommu *iommu = &pagetable->mmu->iommu; 701: 702: if (memdesc->size == 0 || memdesc->gpuaddr == 0) 703: return -EINVAL; 704: 705: return _kgsl_iommu_unmap(to_iommu_domain(&iommu->secure_context), 706: memdesc); 707: } 708: 709: static int kgsl_iommu_default_unmap(struct kgsl_pagetable *pagetable, 710: struct kgsl_memdesc *memdesc) 711: { 712: struct kgsl_mmu *mmu = pagetable->mmu; 713: struct kgsl_iommu *iommu = &mmu->iommu; 714: int ret; 715: 716: if (memdesc->size == 0 || memdesc->gpuaddr == 0) 717: return -EINVAL; 718: 719: if (is_lower_address(mmu, memdesc->gpuaddr)) 720: return kgsl_iopgtbl_unmap(pagetable, memdesc); 721: 722: /* Unmap from the default domain */ 723: ret = _kgsl_iommu_unmap(to_iommu_domain(&iommu->user_context), memdesc); 724: 725: /* Unmap from the LPAC domain if it exists */ 726: ret |= _kgsl_iommu_unmap(to_iommu_domain(&iommu->lpac_context), memdesc); 727: return ret; 728: } 729: 730: static bool kgsl_iommu_addr_is_global(struct kgsl_mmu *mmu, u64 addr) 731: { 732: if (test_bit(KGSL_MMU_IOPGTABLE, &mmu->features)) 733: return (addr >= KGSL_IOMMU_SPLIT_TABLE_BASE); 734: 735: return ((addr >= KGSL_IOMMU_GLOBAL_MEM_BASE(mmu)) && 736: (addr < KGSL_IOMMU_GLOBAL_MEM_BASE(mmu) + 737: KGSL_IOMMU_GLOBAL_MEM_SIZE)); 738: } 739: 740: static void __iomem *kgsl_iommu_reg(struct kgsl_iommu_context *ctx, 741: u32 offset) 742: { 743: struct kgsl_iommu *iommu = KGSL_IOMMU(ctx->kgsldev); 744: 745: if (!iommu->cb0_offset) { 746: u32 reg = 747: readl_relaxed(iommu->regbase + KGSL_IOMMU_IDR1_OFFSET); 748: 749: iommu->pagesize = 750: FIELD_GET(IDR1_PAGESIZE, reg) ? SZ_64K : SZ_4K; MATCH LINES: 786, 787, 798, 804, 832, 833, 838, 841, 842, 849, 854, 860, 862, 863, 867, 868, 870, 884, 887, 888, 889, 894, 898, 904, 911 774: void __iomem *addr = kgsl_iommu_reg(ctx, offset); 775: 776: writel_relaxed(val, addr); 777: } 778: 779: static u32 KGSL_IOMMU_GET_CTX_REG(struct kgsl_iommu_context *ctx, u32 offset) 780: { 781: void __iomem *addr = kgsl_iommu_reg(ctx, offset); 782: 783: return readl_relaxed(addr); 784: } 785: 786: static int kgsl_iommu_get_gpuaddr(struct kgsl_pagetable *pagetable, 787: struct kgsl_memdesc *memdesc); 788: 789: #define KGSL_GLOBAL_MEM_PAGES (KGSL_IOMMU_GLOBAL_MEM_SIZE >> PAGE_SHIFT) 790: 791: static u64 global_get_offset(struct kgsl_device *device, u64 size, 792: atomic_t *priv) 793: { 794: int start = 0, bit; 795: 796: if (!device->global_map) { 797: device->global_map = 798: kcalloc(BITS_TO_LONGS(KGSL_GLOBAL_MEM_PAGES), 799: sizeof(unsigned long), GFP_KERNEL); 800: if (!device->global_map) 801: return (unsigned long) -ENOMEM; 802: } 803: 804: if (TEST_FLAG(KGSL_MEMDESC_RANDOM, priv)) { 805: u32 offset = KGSL_GLOBAL_MEM_PAGES - (size >> PAGE_SHIFT); 806: 807: start = get_random_u32() % offset; 808: } 809: 810: while (start >= 0) { 811: bit = bitmap_find_next_zero_area(device->global_map, 812: KGSL_GLOBAL_MEM_PAGES, start, size >> PAGE_SHIFT, 0); 813: 814: if (bit < KGSL_GLOBAL_MEM_PAGES) 815: break; 816: 817: /* 818: * Later implementations might want to randomize this to reduce 819: * predictability 820: */ 821: start--; 822: } 823: 824: if (WARN_ON(start < 0)) 825: return (unsigned long) -ENOMEM; 826: 827: bitmap_set(device->global_map, bit, size >> PAGE_SHIFT); 828: 829: return bit << PAGE_SHIFT; 830: } 831: 832: static int kgsl_iommu_reserve_global_gpuaddr(struct kgsl_mmu *mmu, 833: struct kgsl_memdesc *memdesc, u32 padding) 834: { 835: struct kgsl_device *device = KGSL_MMU_DEVICE(mmu); 836: u64 offset; 837: 838: if (memdesc->gpuaddr) 839: return -EINVAL; 840: 841: if (memdesc->flags & KGSL_MEMFLAGS_SECURE) { 842: int ret = kgsl_iommu_get_gpuaddr(mmu->securepagetable, memdesc); 843: 844: WARN_ON(ret); 845: 846: return ret; 847: } 848: 849: offset = global_get_offset(device, memdesc->size + padding, &memdesc->priv); 850: 851: if (IS_ERR_VALUE(offset)) 852: return -ENOSPC; 853: 854: memdesc->gpuaddr = mmu->defaultpagetable->global_base + offset; 855: 856: return 0; 857: } 858: 859: static void kgsl_iommu_map_global(struct kgsl_mmu *mmu, 860: struct kgsl_memdesc *memdesc, u32 padding) 861: { 862: if (!memdesc->gpuaddr) { 863: if (kgsl_iommu_reserve_global_gpuaddr(mmu, memdesc, padding)) 864: return; 865: } 866: 867: if (memdesc->flags & KGSL_MEMFLAGS_SECURE) 868: kgsl_iommu_secure_map(mmu->securepagetable, memdesc); 869: else 870: kgsl_iommu_default_map(mmu->defaultpagetable, memdesc); 871: } 872: 873: /* Print the mem entry for the pagefault debugging */ 874: static void print_entry(struct device *dev, struct kgsl_mem_entry *entry, 875: pid_t pid) 876: { 877: char name[32]; 878: 879: if (!entry) { 880: dev_crit(dev, "**EMPTY**\n"); 881: return; 882: } 883: 884: kgsl_get_memory_usage(name, sizeof(name), entry->memdesc.flags); 885: 886: dev_err(dev, "[%016llX - %016llX] %s %s (pid = %d) (%s)\n", 887: entry->memdesc.gpuaddr, 888: entry->memdesc.gpuaddr + entry->memdesc.size - 1, 889: TEST_FLAG(KGSL_MEMDESC_GUARD_PAGE, &entry->memdesc.priv) ? "(+guard)" : "", 890: entry->pending_free ? "(pending free)" : "", 891: pid, name); 892: } 893: 894: /* Check if the address in the list of recently freed memory */ 895: static void kgsl_iommu_check_if_freed(struct device *dev, 896: struct kgsl_iommu_context *context, u64 addr, u32 ptname) 897: { 898: uint64_t gpuaddr = addr; 899: uint64_t size = 0; 900: uint64_t flags = 0; 901: char name[32]; 902: pid_t pid; 903: 904: if (!kgsl_memfree_find_entry(ptname, &gpuaddr, &size, &flags, &pid)) 905: return; 906: 907: kgsl_get_memory_usage(name, sizeof(name), flags); 908: 909: dev_err(dev, "---- premature free ----\n"); 910: dev_err(dev, "[%8.8llX-%8.8llX] (%s) was already freed by pid %d\n", 911: gpuaddr, gpuaddr + size, name, pid); 912: } 913: 914: static struct kgsl_process_private *kgsl_iommu_get_process(u64 ptbase) 915: { 916: struct kgsl_process_private *p; 917: struct kgsl_iommu_pt *iommu_pt; 918: 919: read_lock(&kgsl_driver.proclist_lock); 920: 921: list_for_each_entry(p, &kgsl_driver.process_list, list) { 922: iommu_pt = to_iommu_pt(p->pagetable); 923: if (iommu_pt->ttbr0 == MMU_SW_PT_BASE(ptbase)) { 924: if (!kgsl_process_private_get(p)) 925: p = NULL; 926: 927: read_unlock(&kgsl_driver.proclist_lock); 928: return p; 929: } 930: } 931: 932: read_unlock(&kgsl_driver.proclist_lock); 933: 934: return NULL; 935: } MATCH LINES: 1142, 1145, 1150 1130: if (kgsl_iommu_addr_is_global(mmu, addr)) { 1131: dev_crit(device->dev, "Fault in global memory\n"); 1132: return; 1133: } 1134: 1135: if (!private) 1136: return; 1137: 1138: dev_crit(device->dev, "---- nearby memory ----\n"); 1139: 1140: spin_lock(&private->mem_lock); 1141: idr_for_each_entry(&private->mem_idr, entry, id) { 1142: u64 cur = entry->memdesc.gpuaddr; 1143: 1144: if (cur < addr) { 1145: if (!prev || prev->memdesc.gpuaddr < cur) 1146: prev = entry; 1147: } 1148: 1149: if (cur > addr) { 1150: if (!next || next->memdesc.gpuaddr > cur) 1151: next = entry; 1152: } 1153: } 1154: 1155: print_entry(device->dev, prev, pid_nr(private->pid)); 1156: dev_crit(device->dev, "<- fault @ %16.16lx\n", addr); 1157: print_entry(device->dev, next, pid_nr(private->pid)); 1158: 1159: spin_unlock(&private->mem_lock); 1160: } 1161: 1162: /* 1163: * Return true if the IOMMU should stall and trigger a snapshot on a pagefault 1164: */ 1165: static bool kgsl_iommu_check_stall_on_fault(struct kgsl_iommu_context *ctx, 1166: struct kgsl_mmu *mmu, int flags) 1167: { 1168: struct kgsl_device *device = KGSL_MMU_DEVICE(mmu); 1169: 1170: if (!(flags & IOMMU_FAULT_TRANSACTION_STALLED)) 1171: return false; 1172: 1173: if (!test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &mmu->pfpolicy)) 1174: return false; MATCH LINES: 1413, 1416, 1419 1401: if (kgsl_context_is_lpac(context)) 1402: domain = to_iommu_domain(&iommu->lpac_context); 1403: else 1404: domain = to_iommu_domain(&iommu->user_context); 1405: 1406: return qcom_iommu_get_asid_nr(domain); 1407: } 1408: 1409: static void kgsl_iommu_destroy_default_pagetable(struct kgsl_pagetable *pagetable) 1410: { 1411: struct kgsl_device *device = KGSL_MMU_DEVICE(pagetable->mmu); 1412: struct kgsl_iommu_pt *pt = to_iommu_pt(pagetable); 1413: struct kgsl_global_memdesc *md; 1414: 1415: list_for_each_entry(md, &device->globals, node) { 1416: if (md->memdesc.flags & KGSL_MEMFLAGS_SECURE) 1417: continue; 1418: 1419: kgsl_iommu_default_unmap(pagetable, &md->memdesc); 1420: } 1421: 1422: kfree(pt); 1423: } 1424: 1425: static void kgsl_iommu_destroy_pagetable(struct kgsl_pagetable *pagetable) 1426: { 1427: struct kgsl_iommu_pt *pt = to_iommu_pt(pagetable); 1428: 1429: free_io_pgtable_ops(pt->pgtbl_ops); 1430: kfree(pt); 1431: } 1432: 1433: static void _enable_gpuhtw_llc(struct kgsl_mmu *mmu, struct iommu_domain *domain) 1434: { 1435: if (!test_bit(KGSL_MMU_LLCC_ENABLE, &mmu->features)) 1436: return; 1437: 1438: if (mmu->subtype == KGSL_IOMMU_SMMU_V500) { 1439: if (!test_bit(KGSL_MMU_IO_COHERENT, &mmu->features)) 1440: iommu_set_pgtable_quirks(domain, 1441: IO_PGTABLE_QUIRK_QCOM_USE_LLC_NWA); 1442: } else 1443: iommu_set_pgtable_quirks(domain, IO_PGTABLE_QUIRK_ARM_OUTER_WBWA); MATCH LINES: 2160, 2161, 2169, 2171, 2180, 2181, 2185, 2187, 2210, 2211, 2220, 2237, 2268, 2285 2148: unsigned long pf_policy) 2149: { 2150: struct kgsl_iommu *iommu = &mmu->iommu; 2151: 2152: kgsl_iommu_set_pf_policy_ctxt(mmu, pf_policy, &iommu->user_context); 2153: 2154: if (iommu->lpac_context.domain) 2155: kgsl_iommu_set_pf_policy_ctxt(mmu, pf_policy, &iommu->lpac_context); 2156: 2157: return 0; 2158: } 2159: 2160: static struct kgsl_iommu_addr_entry *_find_gpuaddr( 2161: struct kgsl_pagetable *pagetable, uint64_t gpuaddr) 2162: { 2163: struct rb_node *node = pagetable->rbtree.rb_node; 2164: 2165: while (node != NULL) { 2166: struct kgsl_iommu_addr_entry *entry = rb_entry(node, 2167: struct kgsl_iommu_addr_entry, node); 2168: 2169: if (gpuaddr < entry->base) 2170: node = node->rb_left; 2171: else if (gpuaddr > entry->base) 2172: node = node->rb_right; 2173: else 2174: return entry; 2175: } 2176: 2177: return NULL; 2178: } 2179: 2180: static int _remove_gpuaddr(struct kgsl_pagetable *pagetable, 2181: uint64_t gpuaddr) 2182: { 2183: struct kgsl_iommu_addr_entry *entry; 2184: 2185: entry = _find_gpuaddr(pagetable, gpuaddr); 2186: 2187: if (WARN(!entry, "GPU address %llx doesn't exist\n", gpuaddr)) 2188: return -ENOMEM; 2189: 2190: /* 2191: * If the hint was based on this entry, adjust it to the end of the 2192: * previous entry. 2193: */ 2194: if (pagetable->va_hint == (entry->base + entry->size)) { 2195: struct kgsl_iommu_addr_entry *prev = 2196: rb_entry_safe(rb_prev(&entry->node), 2197: struct kgsl_iommu_addr_entry, node); 2198: 2199: pagetable->va_hint = pagetable->va_start; 2200: if (prev) 2201: pagetable->va_hint = max_t(u64, prev->base + prev->size, 2202: pagetable->va_start); 2203: } 2204: 2205: rb_erase(&entry->node, &pagetable->rbtree); 2206: kmem_cache_free(addr_entry_cache, entry); 2207: return 0; 2208: } 2209: 2210: static int _insert_gpuaddr(struct kgsl_pagetable *pagetable, 2211: uint64_t gpuaddr, uint64_t size) 2212: { 2213: struct rb_node **node, *parent = NULL; 2214: struct kgsl_iommu_addr_entry *new = 2215: kmem_cache_alloc(addr_entry_cache, GFP_ATOMIC); 2216: 2217: if (new == NULL) 2218: return -ENOMEM; 2219: 2220: new->base = gpuaddr; 2221: new->size = size; 2222: 2223: node = &pagetable->rbtree.rb_node; 2224: 2225: while (*node != NULL) { 2226: struct kgsl_iommu_addr_entry *this; 2227: 2228: parent = *node; 2229: this = rb_entry(parent, struct kgsl_iommu_addr_entry, node); 2230: 2231: if (new->base < this->base) 2232: node = &parent->rb_left; 2233: else if (new->base > this->base) 2234: node = &parent->rb_right; 2235: else { 2236: /* Duplicate entry */ 2237: WARN_RATELIMIT(1, "duplicate gpuaddr: 0x%llx\n", gpuaddr); 2238: kmem_cache_free(addr_entry_cache, new); 2239: return -EEXIST; 2240: } 2241: } 2242: 2243: rb_link_node(&new->node, parent, node); 2244: rb_insert_color(&new->node, &pagetable->rbtree); 2245: 2246: return 0; 2247: } 2248: 2249: static u64 _get_unmapped_area_hint(struct kgsl_pagetable *pagetable, 2250: u64 bottom, u64 top, u64 size, u64 align) 2251: { 2252: u64 hint; 2253: 2254: /* 2255: * VA fragmentation can be a problem on global and secure pagetables 2256: * that are common to all processes, or if we're constrained to a 32-bit 2257: * range. Don't use the va_hint in these cases. 2258: */ 2259: if (!pagetable->va_hint || !upper_32_bits(top)) 2260: return (u64) -EINVAL; 2261: 2262: /* Satisfy requested alignment */ 2263: hint = ALIGN(pagetable->va_hint, align); 2264: 2265: /* 2266: * The va_hint is the highest VA that was allocated in the non-SVM 2267: * region. The 64-bit SVM and non-SVM regions do not overlap. So, we 2268: * know there is no VA allocated at this gpuaddr. Therefore, we only 2269: * need to check whether we have enough space for this allocation. 2270: */ 2271: if ((hint + size) > top) 2272: return (u64) -ENOMEM; 2273: 2274: pagetable->va_hint = hint + size; 2275: return hint; 2276: } 2277: 2278: static uint64_t _get_unmapped_area(struct kgsl_pagetable *pagetable, 2279: uint64_t bottom, uint64_t top, uint64_t size, 2280: uint64_t align) 2281: { 2282: struct rb_node *node; 2283: uint64_t start; 2284: 2285: /* Check if we can assign a gpuaddr based on the last allocation */ 2286: start = _get_unmapped_area_hint(pagetable, bottom, top, size, align); 2287: if (!IS_ERR_VALUE(start)) 2288: return start; 2289: 2290: /* Fall back to searching through the range. */ 2291: node = rb_first(&pagetable->rbtree); 2292: bottom = ALIGN(bottom, align); 2293: start = bottom; 2294: 2295: while (node != NULL) { 2296: uint64_t gap; 2297: struct kgsl_iommu_addr_entry *entry = rb_entry(node, 2298: struct kgsl_iommu_addr_entry, node); 2299: 2300: /* 2301: * Skip any entries that are outside of the range, but make sure 2302: * to account for some that might straddle the lower bound 2303: */ 2304: if (entry->base < bottom) { 2305: if (entry->base + entry->size > bottom) 2306: start = ALIGN(entry->base + entry->size, align); 2307: node = rb_next(node); 2308: continue; 2309: } MATCH LINES: 2374 2362: uint64_t offset; 2363: 2364: entry = rb_entry(node, struct kgsl_iommu_addr_entry, node); 2365: 2366: /* If the entire entry is below the range the search is over */ 2367: if ((entry->base + entry->size) < bottom) 2368: break; 2369: 2370: /* Get the top of the entry properly aligned */ 2371: offset = ALIGN(entry->base + entry->size, align); 2372: 2373: /* 2374: * Try to allocate the memory from the top of the gap, 2375: * making sure that it fits between the top of this entry and 2376: * the bottom of the previous one 2377: */ 2378: 2379: if ((end > size) && (offset < end)) { 2380: uint64_t chunk = (end - size) & mask; 2381: 2382: if (chunk >= offset) 2383: return chunk; 2384: } 2385: 2386: /* 2387: * If we get here and the current entry is outside of the range 2388: * then we are officially out of room 2389: */ 2390: 2391: if (entry->base < bottom) 2392: return (uint64_t) -ENOMEM; 2393: 2394: /* Set the top of the gap to the current entry->base */ 2395: end = entry->base; 2396: 2397: /* And move on to the next lower entry */ 2398: node = rb_prev(node); MATCH LINES: 2426, 2428, 2431, 2434, 2439, 2448, 2454, 2468, 2470, 2476, 2482, 2483, 2496, 2500, 2501, 2507, 2508, 2513, 2516, 2520, 2522, 2524, 2532, 2536, 2542, 2544, 2547, 2549, 2551, 2568, 2570, 2573, 2576, 2579, 2583 2414: /* Avoid black holes */ 2415: if (WARN(end <= start, "Bad search range: 0x%llx-0x%llx", start, end)) 2416: return (uint64_t) -EINVAL; 2417: 2418: spin_lock(&pagetable->lock); 2419: addr = _get_unmapped_area_topdown(pagetable, 2420: start, end, size, alignment); 2421: spin_unlock(&pagetable->lock); 2422: return addr; 2423: } 2424: 2425: static bool iommu_addr_in_svm_ranges(struct kgsl_pagetable *pagetable, 2426: u64 gpuaddr, u64 size) 2427: { 2428: u64 end = gpuaddr + size; 2429: 2430: /* Make sure size is not zero and we don't wrap around */ 2431: if (end <= gpuaddr) 2432: return false; 2433: 2434: if ((gpuaddr >= pagetable->compat_va_start && gpuaddr < pagetable->compat_va_end) && 2435: (end > pagetable->compat_va_start && 2436: end <= pagetable->compat_va_end)) 2437: return true; 2438: 2439: if ((gpuaddr >= pagetable->svm_start && gpuaddr < pagetable->svm_end) && 2440: (end > pagetable->svm_start && 2441: end <= pagetable->svm_end)) 2442: return true; 2443: 2444: return false; 2445: } 2446: 2447: static int kgsl_iommu_set_svm_region(struct kgsl_pagetable *pagetable, 2448: uint64_t gpuaddr, uint64_t size) 2449: { 2450: int ret = -ENOMEM; 2451: struct rb_node *node; 2452: 2453: /* Make sure the requested address doesn't fall out of SVM range */ 2454: if (!iommu_addr_in_svm_ranges(pagetable, gpuaddr, size)) 2455: return -ENOMEM; 2456: 2457: spin_lock(&pagetable->lock); 2458: node = pagetable->rbtree.rb_node; 2459: 2460: while (node != NULL) { 2461: uint64_t start, end; 2462: struct kgsl_iommu_addr_entry *entry = rb_entry(node, 2463: struct kgsl_iommu_addr_entry, node); 2464: 2465: start = entry->base; 2466: end = entry->base + entry->size; 2467: 2468: if (gpuaddr + size <= start) 2469: node = node->rb_left; 2470: else if (end <= gpuaddr) 2471: node = node->rb_right; 2472: else 2473: goto out; 2474: } 2475: 2476: ret = _insert_gpuaddr(pagetable, gpuaddr, size); 2477: out: 2478: spin_unlock(&pagetable->lock); 2479: return ret; 2480: } 2481: 2482: static int get_gpuaddr(struct kgsl_pagetable *pagetable, 2483: struct kgsl_memdesc *memdesc, u64 start, u64 end, 2484: u64 size, u64 align) 2485: { 2486: u64 addr; 2487: int ret; 2488: 2489: spin_lock(&pagetable->lock); 2490: addr = _get_unmapped_area(pagetable, start, end, size, align); 2491: if (addr == (u64) -ENOMEM) { 2492: spin_unlock(&pagetable->lock); 2493: return -ENOMEM; 2494: } 2495: 2496: ret = _insert_gpuaddr(pagetable, addr, size); 2497: spin_unlock(&pagetable->lock); 2498: 2499: if (ret == 0) { 2500: memdesc->gpuaddr = addr; 2501: memdesc->pagetable = pagetable; 2502: } 2503: 2504: return ret; 2505: } 2506: 2507: static int kgsl_iommu_get_gpuaddr(struct kgsl_pagetable *pagetable, 2508: struct kgsl_memdesc *memdesc) 2509: { 2510: int ret = 0; 2511: u64 start, end, size, align; 2512: 2513: if (WARN_ON(kgsl_memdesc_use_cpu_map(memdesc))) 2514: return -EINVAL; 2515: 2516: if (memdesc->flags & KGSL_MEMFLAGS_SECURE && 2517: pagetable->name != KGSL_MMU_SECURE_PT) 2518: return -EINVAL; 2519: 2520: size = kgsl_memdesc_footprint(memdesc); 2521: 2522: align = kgsl_get_align(memdesc); 2523: 2524: if (memdesc->flags & KGSL_MEMFLAGS_FORCE_32BIT) { 2525: start = pagetable->compat_va_start; 2526: end = pagetable->compat_va_end; 2527: } else { 2528: start = pagetable->va_start; 2529: end = pagetable->va_end; 2530: } 2531: 2532: ret = get_gpuaddr(pagetable, memdesc, start, end, size, align); 2533: /* if OOM, retry once after flushing lockless_workqueue */ 2534: if (ret == -ENOMEM) { 2535: flush_workqueue(kgsl_driver.lockless_workqueue); 2536: ret = get_gpuaddr(pagetable, memdesc, start, end, size, align); 2537: } 2538: 2539: return ret; 2540: } 2541: 2542: static void kgsl_iommu_put_gpuaddr(struct kgsl_memdesc *memdesc) 2543: { 2544: if (memdesc->pagetable == NULL) 2545: return; 2546: 2547: spin_lock(&memdesc->pagetable->lock); 2548: 2549: _remove_gpuaddr(memdesc->pagetable, memdesc->gpuaddr); 2550: 2551: spin_unlock(&memdesc->pagetable->lock); 2552: } 2553: 2554: static int kgsl_iommu_svm_range(struct kgsl_pagetable *pagetable, 2555: uint64_t *lo, uint64_t *hi, uint64_t memflags) 2556: { 2557: bool gpu_compat = (memflags & KGSL_MEMFLAGS_FORCE_32BIT) != 0; 2558: 2559: if (lo != NULL) 2560: *lo = gpu_compat ? pagetable->compat_va_start : pagetable->svm_start; 2561: if (hi != NULL) 2562: *hi = gpu_compat ? pagetable->compat_va_end : pagetable->svm_end; 2563: 2564: return 0; 2565: } 2566: 2567: static bool kgsl_iommu_addr_in_range(struct kgsl_pagetable *pagetable, 2568: uint64_t gpuaddr, uint64_t size) 2569: { 2570: u64 end = gpuaddr + size; 2571: 2572: /* Make sure we don't wrap around */ 2573: if (gpuaddr == 0 || end < gpuaddr) 2574: return false; 2575: 2576: if (gpuaddr >= pagetable->va_start && end <= pagetable->va_end) 2577: return true; 2578: 2579: if (gpuaddr >= pagetable->compat_va_start && 2580: end <= pagetable->compat_va_end) 2581: return true; 2582: 2583: if (gpuaddr >= pagetable->svm_start && end <= pagetable->svm_end) 2584: return true; 2585: 2586: return false; 2587: } 2588: 2589: #if (KERNEL_VERSION(6, 13, 0) <= LINUX_VERSION_CODE) 2590: static struct iommu_domain *kgsl_iommu_domain_alloc(struct device *dev) 2591: { 2592: return iommu_paging_domain_alloc(dev); 2593: } 2594: #else 2595: static struct iommu_domain *kgsl_iommu_domain_alloc(struct device *dev) 2596: { 2597: return iommu_domain_alloc(&platform_bus_type); 2598: } 2599: #endif 2600: 2601: static int kgsl_iommu_setup_context_common(struct kgsl_mmu *mmu, 2602: struct platform_device *pdev, struct device_node *node, 2603: struct kgsl_iommu_context *context, const char *name, 2604: iommu_fault_handler_t handler, bool restore_drvdata) 2605: { 2606: struct kgsl_device *device = KGSL_MMU_DEVICE(mmu); 2607: void *kgsl_drvdata = NULL; MATCH LINES: 2925, 2928, 2933, 2936 2913: * should intercept accesses to the page before they go to DDR 2914: * so this should be mostly just a placeholder 2915: */ 2916: kgsl_vbo_zero_page = alloc_page(GFP_KERNEL | __GFP_ZERO | 2917: __GFP_NORETRY | __GFP_HIGHMEM); 2918: } 2919: if (!kgsl_vbo_zero_page) 2920: clear_bit(KGSL_MMU_SUPPORT_VBO, &mmu->features); 2921: } 2922: 2923: static void kgsl_iommu_map_globals(struct kgsl_device *device, struct kgsl_mmu *mmu) 2924: { 2925: struct kgsl_global_memdesc *md; 2926: 2927: list_for_each_entry(md, &device->globals, node) { 2928: if (md->memdesc.flags & KGSL_MEMFLAGS_SECURE) { 2929: if (IS_ERR_OR_NULL(mmu->securepagetable)) 2930: continue; 2931: 2932: kgsl_iommu_secure_map(mmu->securepagetable, 2933: &md->memdesc); 2934: } else 2935: kgsl_iommu_default_map(mmu->defaultpagetable, 2936: &md->memdesc); 2937: } 2938: } 2939: 2940: static int kgsl_iommu_setup_context_standard(struct kgsl_mmu *mmu, 2941: struct device_node *node, 2942: struct kgsl_iommu_context *context, const char *name, 2943: iommu_fault_handler_t handler) 2944: { 2945: struct platform_device *pdev; 2946: int ret; 2947: 2948: pdev = of_find_device_by_node(node); 2949: if (!pdev) { 2950: ret = -ENODEV; 2951: goto err_node_put; 2952: } 2953: 2954: ret = of_dma_configure(&pdev->dev, node, true); 2955: if (ret) 2956: goto err_device_put; 2957: 2958: return kgsl_iommu_setup_context_common(mmu, pdev, node, context, name, handler, true); 2959: 2960: err_device_put: MATCH LINES: 3382, 3397, 3398, 3411, 3412, 3423, 3424 3370: static const struct kgsl_mmu_ops kgsl_iommu_ops = { 3371: .mmu_close = kgsl_iommu_close, 3372: .mmu_start = kgsl_iommu_start, 3373: .mmu_ctx_terminated_on_fault = kgsl_iommu_ctx_terminated_on_fault, 3374: .mmu_clear_fsr = kgsl_iommu_clear_fsr, 3375: .mmu_get_current_ttbr0 = kgsl_iommu_get_current_ttbr0, 3376: .mmu_enable_clk = kgsl_iommu_enable_clk, 3377: .mmu_disable_clk = kgsl_iommu_disable_clk, 3378: .mmu_set_pf_policy = kgsl_iommu_set_pf_policy, 3379: .mmu_pagefault_resume = kgsl_iommu_pagefault_resume, 3380: .mmu_getpagetable = kgsl_iommu_getpagetable, 3381: .mmu_map_global = kgsl_iommu_map_global, 3382: .mmu_reserve_global_gpuaddr = kgsl_iommu_reserve_global_gpuaddr, 3383: .mmu_send_tlb_hint = kgsl_iommu_send_tlb_hint, 3384: .mmu_sysfs_init = kgsl_iommu_sysfs_init, 3385: }; 3386: 3387: static const struct kgsl_mmu_pt_ops iopgtbl_pt_ops = { 3388: .mmu_map = kgsl_iopgtbl_map, 3389: .mmu_map_child = kgsl_iopgtbl_map_child, 3390: .mmu_map_zero_page_to_range = kgsl_iopgtbl_map_zero_page_to_range, 3391: .mmu_unmap = kgsl_iopgtbl_unmap, 3392: .mmu_unmap_range = kgsl_iopgtbl_unmap_range, 3393: .mmu_destroy_pagetable = kgsl_iommu_destroy_pagetable, 3394: .get_ttbr0 = kgsl_iommu_get_ttbr0, 3395: .get_context_bank = kgsl_iommu_get_context_bank, 3396: .get_asid = kgsl_iommu_get_asid, 3397: .get_gpuaddr = kgsl_iommu_get_gpuaddr, 3398: .put_gpuaddr = kgsl_iommu_put_gpuaddr, 3399: .set_svm_region = kgsl_iommu_set_svm_region, 3400: .find_svm_region = kgsl_iommu_find_svm_region, 3401: .svm_range = kgsl_iommu_svm_range, 3402: .addr_in_range = kgsl_iommu_addr_in_range, 3403: }; 3404: 3405: static const struct kgsl_mmu_pt_ops secure_pt_ops = { 3406: .mmu_map = kgsl_iommu_secure_map, 3407: .mmu_unmap = kgsl_iommu_secure_unmap, 3408: .mmu_destroy_pagetable = kgsl_iommu_destroy_pagetable, 3409: .get_context_bank = kgsl_iommu_get_context_bank, 3410: .get_asid = kgsl_iommu_get_asid, 3411: .get_gpuaddr = kgsl_iommu_get_gpuaddr, 3412: .put_gpuaddr = kgsl_iommu_put_gpuaddr, 3413: .addr_in_range = kgsl_iommu_addr_in_range, 3414: }; 3415: 3416: static const struct kgsl_mmu_pt_ops default_pt_ops = { 3417: .mmu_map = kgsl_iommu_default_map, 3418: .mmu_unmap = kgsl_iommu_default_unmap, 3419: .mmu_destroy_pagetable = kgsl_iommu_destroy_default_pagetable, 3420: .get_ttbr0 = kgsl_iommu_get_ttbr0, 3421: .get_context_bank = kgsl_iommu_get_context_bank, 3422: .get_asid = kgsl_iommu_get_asid, 3423: .get_gpuaddr = kgsl_iommu_get_gpuaddr, 3424: .put_gpuaddr = kgsl_iommu_put_gpuaddr, 3425: .addr_in_range = kgsl_iommu_addr_in_range, 3426: }; --- FILE: \kgsl_iommu.h | HITS: 2 --- MATCH LINES: 184, 188 172: * @clk_enable_count: The ref count of clock enable calls 173: * @clks: Array of pointers to IOMMU clocks 174: * @smmu_info: smmu info used in a5xx preemption 175: */ 176: struct kgsl_iommu { 177: /** @user_context: Container for the user iommu context */ 178: struct kgsl_iommu_context user_context; 179: /** @secure_context: Container for the secure iommu context */ 180: struct kgsl_iommu_context secure_context; 181: /** @lpac_context: Container for the LPAC iommu context */ 182: struct kgsl_iommu_context lpac_context; 183: void __iomem *regbase; 184: struct kgsl_memdesc *setstate; 185: atomic_t clk_enable_count; 186: struct clk_bulk_data *clks; 187: int num_clks; 188: struct kgsl_memdesc *smmu_info; 189: /** @pdev: Pointer to the platform device for the IOMMU device */ 190: struct platform_device *pdev; 191: /** 192: * @ppt_active: Set when the first per process pagetable is created. 193: * This is used to warn when global buffers are created that might not 194: * be mapped in all contexts 195: */ 196: bool ppt_active; 197: /** 198: * @smmu_aperture_set: Set once the SMMU aperture is programmed. Cleared 199: * when the aperture is lost so that the next MMU start programs it again. 200: */ 201: bool smmu_aperture_set; 202: /** @cb0_offset: Offset of context bank 0 from iommu register base */ 203: u32 cb0_offset; 204: /** @pagesize: Size of each context bank register space */ 205: u32 pagesize; 206: /** @cx_regulator: CX regulator handle in case the IOMMU needs it */ 207: struct regulator *cx_regulator; 208: /** @pf_type_counts: Keep track of pagefaults */ 209: u32 pf_type_counts[KGSL_IOMMU_PAGEFAULT_TYPES]; 210: /** 211: * @pf_procs: Array to keep track of per process pagefault count sorted by the number 212: * of pagefaults --- FILE: \kgsl_mmu.c | HITS: 58 --- MATCH LINES: 14 2: /* 3: * Copyright (c) 2002,2007-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include 8: #include 9: #include 10: #include 11: 12: #include "kgsl_device.h" 13: #include "kgsl_mmu.h" 14: #include "kgsl_sharedmem.h" 15: 16: static void pagetable_remove_sysfs_objects(struct kgsl_pagetable *pagetable); 17: 18: static void _deferred_destroy(struct work_struct *ws) 19: { 20: struct kgsl_pagetable *pagetable = container_of(ws, 21: struct kgsl_pagetable, destroy_ws); 22: 23: WARN_ON(!list_empty(&pagetable->list)); 24: 25: pagetable->pt_ops->mmu_destroy_pagetable(pagetable); 26: } 27: 28: static void kgsl_destroy_pagetable(struct kref *kref) 29: { 30: struct kgsl_pagetable *pagetable = container_of(kref, 31: struct kgsl_pagetable, refcount); 32: 33: kgsl_mmu_detach_pagetable(pagetable); 34: 35: kgsl_schedule_work(&pagetable->destroy_ws); 36: } 37: 38: struct kgsl_pagetable * MATCH LINES: 315, 318, 322, 329, 334, 337, 338, 341, 344, 349, 358, 359, 363, 370, 371, 375, 378, 384, 397, 402, 405, 410, 440, 445, 448, 452, 458, 460, 468, 469, 470, 480, 485, 489, 499, 500, 504, 505, 511, 516, 542, 543, 546, 557, 558, 560, 563, 564, 566, 570, 572, 573, 586, 587, 596, 609, 610 303: uint64_t start, uint64_t end, uint64_t size, 304: uint64_t align) 305: { 306: if (PT_OP_VALID(pagetable, find_svm_region)) 307: return pagetable->pt_ops->find_svm_region(pagetable, start, 308: end, size, align); 309: return -ENOMEM; 310: } 311: 312: /** 313: * kgsl_mmu_set_svm_region() - Check if a region is empty and reserve it if so 314: * @pagetable: KGSL pagetable to search 315: * @gpuaddr: GPU address to check/reserve 316: * @size: Size of the region to check/reserve 317: */ 318: int kgsl_mmu_set_svm_region(struct kgsl_pagetable *pagetable, uint64_t gpuaddr, 319: uint64_t size) 320: { 321: if (PT_OP_VALID(pagetable, set_svm_region)) 322: return pagetable->pt_ops->set_svm_region(pagetable, gpuaddr, 323: size); 324: return -ENOMEM; 325: } 326: 327: int 328: kgsl_mmu_map(struct kgsl_pagetable *pagetable, 329: struct kgsl_memdesc *memdesc) 330: { 331: int size; 332: struct kgsl_device *device = KGSL_MMU_DEVICE(pagetable->mmu); 333: 334: if (!memdesc->gpuaddr) 335: return -EINVAL; 336: /* Only global mappings should be mapped multiple times */ 337: if (!kgsl_memdesc_is_global(memdesc) && 338: (TEST_FLAG(KGSL_MEMDESC_MAPPED, &memdesc->priv))) 339: return -EINVAL; 340: 341: if (memdesc->flags & KGSL_MEMFLAGS_VBO) 342: return -EINVAL; 343: 344: size = kgsl_memdesc_footprint(memdesc); 345: 346: if (PT_OP_VALID(pagetable, mmu_map)) { 347: int ret; 348: 349: ret = pagetable->pt_ops->mmu_map(pagetable, memdesc); 350: if (ret) 351: return ret; 352: 353: atomic_inc(&pagetable->stats.entries); 354: KGSL_STATS_ADD(size, &pagetable->stats.mapped, 355: &pagetable->stats.max_mapped); 356: kgsl_mmu_trace_gpu_mem_pagetable(pagetable); 357: 358: if (!kgsl_memdesc_is_global(memdesc) 359: && !(memdesc->flags & KGSL_MEMFLAGS_USERMEM_ION)) { 360: kgsl_trace_gpu_mem_total(device, size); 361: } 362: 363: SET_FLAG(KGSL_MEMDESC_MAPPED, &memdesc->priv); 364: } 365: 366: return 0; 367: } 368: 369: int kgsl_mmu_map_child(struct kgsl_pagetable *pt, 370: struct kgsl_memdesc *memdesc, u64 offset, 371: struct kgsl_memdesc *child, u64 child_offset, 372: u64 length) 373: { 374: /* This only makes sense for virtual buffer objects */ 375: if (!(memdesc->flags & KGSL_MEMFLAGS_VBO)) 376: return -EINVAL; 377: 378: if (!memdesc->gpuaddr) 379: return -EINVAL; 380: 381: if (PT_OP_VALID(pt, mmu_map_child)) { 382: int ret; 383: 384: ret = pt->pt_ops->mmu_map_child(pt, memdesc, 385: offset, child, child_offset, length); 386: if (ret) 387: return ret; 388: 389: KGSL_STATS_ADD(length, &pt->stats.mapped, 390: &pt->stats.max_mapped); 391: } 392: 393: return 0; 394: } 395: 396: int kgsl_mmu_map_zero_page_to_range(struct kgsl_pagetable *pt, 397: struct kgsl_memdesc *memdesc, u64 start, u64 length) 398: { 399: int ret = -EINVAL; 400: 401: /* This only makes sense for virtual buffer objects */ 402: if (!(memdesc->flags & KGSL_MEMFLAGS_VBO)) 403: return -EINVAL; 404: 405: if (!memdesc->gpuaddr) 406: return -EINVAL; 407: 408: if (PT_OP_VALID(pt, mmu_map_zero_page_to_range)) { 409: ret = pt->pt_ops->mmu_map_zero_page_to_range(pt, 410: memdesc, start, length); 411: if (ret) 412: return ret; 413: 414: KGSL_STATS_ADD(length, &pt->stats.mapped, 415: &pt->stats.max_mapped); 416: } 417: 418: return 0; 419: } 420: 421: /** 422: * kgsl_mmu_svm_range() - Return the range for SVM (if applicable) 423: * @pagetable: Pagetable to query the range from 424: * @lo: Pointer to store the start of the SVM range 425: * @hi: Pointer to store the end of the SVM range 426: * @memflags: Flags from the buffer we are mapping 427: */ 428: int kgsl_mmu_svm_range(struct kgsl_pagetable *pagetable, 429: uint64_t *lo, uint64_t *hi, uint64_t memflags) 430: { 431: if (PT_OP_VALID(pagetable, svm_range)) 432: return pagetable->pt_ops->svm_range(pagetable, lo, hi, 433: memflags); 434: 435: return -ENODEV; 436: } 437: 438: int 439: kgsl_mmu_unmap(struct kgsl_pagetable *pagetable, 440: struct kgsl_memdesc *memdesc) 441: { 442: int ret = 0; 443: struct kgsl_device *device = KGSL_MMU_DEVICE(pagetable->mmu); 444: 445: if (memdesc->size == 0) 446: return -EINVAL; 447: 448: if ((memdesc->flags & KGSL_MEMFLAGS_VBO)) 449: return -EINVAL; 450: 451: /* Only global mappings should be mapped multiple times */ 452: if (!(TEST_FLAG(KGSL_MEMDESC_MAPPED, &memdesc->priv))) 453: return -EINVAL; 454: 455: if (PT_OP_VALID(pagetable, mmu_unmap)) { 456: uint64_t size; 457: 458: size = kgsl_memdesc_footprint(memdesc); 459: 460: ret = pagetable->pt_ops->mmu_unmap(pagetable, memdesc); 461: if (ret) 462: return ret; 463: 464: atomic_dec(&pagetable->stats.entries); 465: atomic_long_sub(size, &pagetable->stats.mapped); 466: kgsl_mmu_trace_gpu_mem_pagetable(pagetable); 467: 468: if (!kgsl_memdesc_is_global(memdesc)) { 469: CLEAR_FLAG(KGSL_MEMDESC_MAPPED, &memdesc->priv); 470: if (!(memdesc->flags & KGSL_MEMFLAGS_USERMEM_ION)) 471: kgsl_trace_gpu_mem_total(device, -(size)); 472: } 473: } 474: 475: return ret; 476: } 477: 478: int 479: kgsl_mmu_unmap_range(struct kgsl_pagetable *pagetable, 480: struct kgsl_memdesc *memdesc, u64 offset, u64 length) 481: { 482: int ret = 0; 483: 484: /* Only allow virtual buffer objects to use this function */ 485: if (!(memdesc->flags & KGSL_MEMFLAGS_VBO)) 486: return -EINVAL; 487: 488: if (PT_OP_VALID(pagetable, mmu_unmap_range)) { 489: ret = pagetable->pt_ops->mmu_unmap_range(pagetable, memdesc, 490: offset, length); 491: 492: if (!ret) 493: atomic_long_sub(length, &pagetable->stats.mapped); 494: } 495: 496: return ret; 497: } 498: 499: int kgsl_mmu_reserve_global_gpuaddr(struct kgsl_device *device, 500: struct kgsl_memdesc *memdesc) 501: { 502: struct kgsl_mmu *mmu = &(device->mmu); 503: 504: if (MMU_OP_VALID(mmu, mmu_reserve_global_gpuaddr)) 505: return mmu->mmu_ops->mmu_reserve_global_gpuaddr(mmu, memdesc, 0); 506: 507: return -EINVAL; 508: } 509: 510: void kgsl_mmu_map_global(struct kgsl_device *device, 511: struct kgsl_memdesc *memdesc, u32 padding) 512: { 513: struct kgsl_mmu *mmu = &(device->mmu); 514: 515: if (MMU_OP_VALID(mmu, mmu_map_global)) 516: mmu->mmu_ops->mmu_map_global(mmu, memdesc, padding); 517: } 518: 519: int kgsl_mmu_pagetable_get_context_bank(struct kgsl_pagetable *pagetable, 520: struct kgsl_context *context) 521: { 522: if (PT_OP_VALID(pagetable, get_context_bank)) 523: return pagetable->pt_ops->get_context_bank(pagetable, context); 524: 525: return -ENOENT; 526: } 527: 528: int kgsl_mmu_pagetable_get_asid(struct kgsl_pagetable *pagetable, 529: struct kgsl_context *context) 530: { 531: if (PT_OP_VALID(pagetable, get_asid)) 532: return pagetable->pt_ops->get_asid(pagetable, context); 533: 534: return -ENOENT; 535: } 536: 537: enum kgsl_mmutype kgsl_mmu_get_mmutype(struct kgsl_device *device) 538: { 539: return device ? device->mmu.type : KGSL_MMU_TYPE_NONE; 540: } 541: 542: bool kgsl_mmu_gpuaddr_in_range(struct kgsl_pagetable *pagetable, 543: uint64_t gpuaddr, uint64_t size) 544: { 545: if (PT_OP_VALID(pagetable, addr_in_range)) 546: return pagetable->pt_ops->addr_in_range(pagetable, gpuaddr, size); 547: 548: return false; 549: } 550: 551: /* 552: * NOMMU definitions - NOMMU really just means that the MMU is kept in pass 553: * through and the GPU directly accesses physical memory. Used in debug mode 554: * and when a real MMU isn't up and running yet. 555: */ 556: 557: static bool nommu_gpuaddr_in_range(struct kgsl_pagetable *pagetable, 558: uint64_t gpuaddr, uint64_t size) 559: { 560: return (gpuaddr != 0) ? true : false; 561: } 562: 563: static int nommu_get_gpuaddr(struct kgsl_pagetable *pagetable, 564: struct kgsl_memdesc *memdesc) 565: { 566: if (WARN_ONCE(memdesc->sgt->nents > 1, 567: "Attempt to map non-contiguous memory with NOMMU\n")) 568: return -EINVAL; 569: 570: memdesc->gpuaddr = (uint64_t) sg_phys(memdesc->sgt->sgl); 571: 572: if (memdesc->gpuaddr) { 573: memdesc->pagetable = pagetable; 574: return 0; 575: } 576: 577: return -ENOMEM; 578: } 579: 580: static void nommu_destroy_pagetable(struct kgsl_pagetable *pt) 581: { 582: kfree(pt); 583: } 584: 585: static const struct kgsl_mmu_pt_ops nommu_pt_ops = { 586: .get_gpuaddr = nommu_get_gpuaddr, 587: .addr_in_range = nommu_gpuaddr_in_range, 588: .mmu_destroy_pagetable = nommu_destroy_pagetable, 589: }; 590: 591: static struct kgsl_pagetable *nommu_getpagetable(struct kgsl_mmu *mmu, 592: unsigned long name) 593: { 594: struct kgsl_device *device = KGSL_MMU_DEVICE(mmu); 595: struct kgsl_pagetable *pagetable; 596: struct kgsl_global_memdesc *md; 597: 598: pagetable = kgsl_get_pagetable(KGSL_MMU_GLOBAL_PT); 599: 600: if (pagetable == NULL) { 601: pagetable = kzalloc(sizeof(*pagetable), GFP_KERNEL); 602: if (!pagetable) 603: return ERR_PTR(-ENOMEM); 604: 605: kgsl_mmu_pagetable_init(mmu, pagetable, KGSL_MMU_GLOBAL_PT); 606: pagetable->pt_ops = &nommu_pt_ops; 607: 608: list_for_each_entry(md, &device->globals, node) 609: md->memdesc.gpuaddr = 610: (uint64_t) sg_phys(md->memdesc.sgt->sgl); 611: 612: kgsl_mmu_pagetable_add(mmu, pagetable); 613: } 614: 615: return pagetable; 616: } 617: 618: static struct kgsl_mmu_ops kgsl_nommu_ops = { 619: .mmu_getpagetable = nommu_getpagetable, 620: }; 621: 622: ssize_t kgsl_mmu_map_sg(struct iommu_domain *domain, 623: unsigned long iova, struct scatterlist *sg, 624: unsigned int nents, int prot) 625: { 626: #if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) 627: return iommu_map_sg(domain, iova, sg, nents, prot, GFP_KERNEL); 628: #else 629: return iommu_map_sg(domain, iova, sg, nents, prot); 630: #endif 631: } 632: 633: static int kgsl_mmu_cb_bind(struct device *dev, struct device *master, void *data) 634: { --- FILE: \kgsl_mmu.h | HITS: 41 --- MATCH LINES: 74 62: unsigned int name; 63: struct kobject *kobj; 64: struct work_struct destroy_ws; 65: 66: struct { 67: atomic_t entries; 68: atomic_long_t mapped; 69: atomic_long_t max_mapped; 70: } stats; 71: const struct kgsl_mmu_pt_ops *pt_ops; 72: uint64_t fault_addr; 73: struct kgsl_mmu *mmu; 74: /** @rbtree: all buffers mapped into the pagetable, indexed by gpuaddr */ 75: struct rb_root rbtree; 76: /** @va_start: Start of virtual range used in this pagetable */ 77: u64 va_start; 78: /** @va_end: End of virtual range */ 79: u64 va_end; 80: /** 81: * @svm_start: Start of shared virtual memory range. Addresses in this 82: * range are also valid in the process's CPU address space. 83: */ 84: u64 svm_start; 85: /** @svm_end: end of 32 bit compatible range */ 86: u64 svm_end; 87: /** 88: * @compat_va_start - Start of the "compat" virtual address range for 89: * forced 32 bit allocations 90: */ 91: u64 compat_va_start; 92: /** 93: * @compat_va_end - End of the "compat" virtual address range for 94: * forced 32 bit allocations 95: */ 96: u64 compat_va_end; 97: /** @va_hint: Virtual address hint for 64-bit non-SVM allocations */ 98: u64 va_hint; MATCH LINES: 118, 119, 127, 129, 130, 133, 135, 137, 142, 143, 144, 148, 152 106: int (*mmu_start)(struct kgsl_mmu *mmu); 107: bool (*mmu_ctx_terminated_on_fault)(struct kgsl_mmu *mmu); 108: uint64_t (*mmu_get_current_ttbr0)(struct kgsl_mmu *mmu, struct kgsl_context *context); 109: void (*mmu_pagefault_resume)(struct kgsl_mmu *mmu, bool terminate); 110: void (*mmu_clear_fsr)(struct kgsl_mmu *mmu); 111: void (*mmu_enable_clk)(struct kgsl_mmu *mmu); 112: void (*mmu_disable_clk)(struct kgsl_mmu *mmu); 113: int (*mmu_set_pf_policy)(struct kgsl_mmu *mmu, unsigned long pf_policy); 114: int (*mmu_init_pt)(struct kgsl_mmu *mmu, struct kgsl_pagetable *pt); 115: struct kgsl_pagetable * (*mmu_getpagetable)(struct kgsl_mmu *mmu, 116: unsigned long name); 117: void (*mmu_map_global)(struct kgsl_mmu *mmu, 118: struct kgsl_memdesc *memdesc, u32 padding); 119: int (*mmu_reserve_global_gpuaddr)(struct kgsl_mmu *mmu, struct kgsl_memdesc *memdesc, 120: u32 padding); 121: void (*mmu_send_tlb_hint)(struct kgsl_mmu *mmu, bool hint); 122: void (*mmu_sysfs_init)(struct kgsl_mmu *mmu); 123: }; 124: 125: struct kgsl_mmu_pt_ops { 126: int (*mmu_map)(struct kgsl_pagetable *pt, 127: struct kgsl_memdesc *memdesc); 128: int (*mmu_map_child)(struct kgsl_pagetable *pt, 129: struct kgsl_memdesc *memdesc, u64 offset, 130: struct kgsl_memdesc *child, u64 child_offset, 131: u64 length); 132: int (*mmu_map_zero_page_to_range)(struct kgsl_pagetable *pt, 133: struct kgsl_memdesc *memdesc, u64 start, u64 length); 134: int (*mmu_unmap)(struct kgsl_pagetable *pt, 135: struct kgsl_memdesc *memdesc); 136: int (*mmu_unmap_range)(struct kgsl_pagetable *pt, 137: struct kgsl_memdesc *memdesc, u64 offset, u64 length); 138: void (*mmu_destroy_pagetable)(struct kgsl_pagetable *pt); 139: u64 (*get_ttbr0)(struct kgsl_pagetable *pt); 140: int (*get_context_bank)(struct kgsl_pagetable *pt, struct kgsl_context *context); 141: int (*get_asid)(struct kgsl_pagetable *pt, struct kgsl_context *context); 142: int (*get_gpuaddr)(struct kgsl_pagetable *pt, 143: struct kgsl_memdesc *memdesc); 144: void (*put_gpuaddr)(struct kgsl_memdesc *memdesc); 145: uint64_t (*find_svm_region)(struct kgsl_pagetable *pt, uint64_t start, 146: uint64_t end, uint64_t size, uint64_t align); 147: int (*set_svm_region)(struct kgsl_pagetable *pt, 148: uint64_t gpuaddr, uint64_t size); 149: int (*svm_range)(struct kgsl_pagetable *pt, uint64_t *lo, uint64_t *hi, 150: uint64_t memflags); 151: bool (*addr_in_range)(struct kgsl_pagetable *pagetable, 152: uint64_t gpuaddr, uint64_t size); 153: }; 154: 155: enum kgsl_mmu_feature { 156: /* @KGSL_MMU_64BIT: Use 64 bit virtual address space */ 157: KGSL_MMU_64BIT, 158: /* @KGSL_MMU_PAGED: Support paged memory */ 159: KGSL_MMU_PAGED, 160: /* 161: * @KGSL_MMU_NEED_GUARD_PAGE: Set if a guard page is needed for each 162: * mapped region 163: */ 164: KGSL_MMU_NEED_GUARD_PAGE, 165: /** @KGSL_MMU_IO_COHERENT: Set if a device supports I/O coherency */ 166: KGSL_MMU_IO_COHERENT, 167: /** @KGSL_MMU_LLC_ENABLE: Set if LLC is activated for the target */ 168: KGSL_MMU_LLCC_ENABLE, 169: /** @KGSL_MMU_SMMU_APERTURE: Set the SMMU aperture */ 170: KGSL_MMU_SMMU_APERTURE, 171: /** 172: * @KGSL_MMU_IOPGTABLE: Set if the qcom,adreno-smmu implementation is 173: * available. Implies split address space and per-process pagetables 174: */ 175: KGSL_MMU_IOPGTABLE, 176: /** @KGSL_MMU_SUPPORT_VBO: Non-secure VBOs are supported */ MATCH LINES: 222, 224, 225, 228, 230, 232, 235, 242, 269, 271, 275, 276, 278, 279, 285, 287, 291, 292, 294, 295 210: }; 211: 212: #define KGSL_IOMMU(d) (&((d)->mmu.iommu)) 213: 214: int __init kgsl_mmu_init(void); 215: void kgsl_mmu_exit(void); 216: 217: int kgsl_mmu_start(struct kgsl_device *device); 218: 219: void kgsl_mmu_putpagetable(struct kgsl_pagetable *pagetable); 220: 221: int kgsl_mmu_map(struct kgsl_pagetable *pagetable, 222: struct kgsl_memdesc *memdesc); 223: int kgsl_mmu_map_child(struct kgsl_pagetable *pt, 224: struct kgsl_memdesc *memdesc, u64 offset, 225: struct kgsl_memdesc *child, u64 child_offset, 226: u64 length); 227: int kgsl_mmu_map_zero_page_to_range(struct kgsl_pagetable *pt, 228: struct kgsl_memdesc *memdesc, u64 start, u64 length); 229: int kgsl_mmu_unmap(struct kgsl_pagetable *pagetable, 230: struct kgsl_memdesc *memdesc); 231: int kgsl_mmu_unmap_range(struct kgsl_pagetable *pt, 232: struct kgsl_memdesc *memdesc, u64 offset, u64 length); 233: unsigned int kgsl_mmu_log_fault_addr(struct kgsl_mmu *mmu, 234: u64 ttbr0, uint64_t addr); 235: bool kgsl_mmu_gpuaddr_in_range(struct kgsl_pagetable *pt, uint64_t gpuaddr, 236: uint64_t size); 237: 238: uint64_t kgsl_mmu_find_svm_region(struct kgsl_pagetable *pagetable, 239: uint64_t start, uint64_t end, uint64_t size, 240: uint64_t alignment); 241: 242: int kgsl_mmu_set_svm_region(struct kgsl_pagetable *pagetable, uint64_t gpuaddr, 243: uint64_t size); 244: 245: void kgsl_mmu_detach_pagetable(struct kgsl_pagetable *pagetable); 246: 247: int kgsl_mmu_svm_range(struct kgsl_pagetable *pagetable, 248: uint64_t *lo, uint64_t *hi, uint64_t memflags); 249: 250: struct kgsl_pagetable *kgsl_get_pagetable(unsigned long name); 251: 252: /* 253: * Static inline functions of MMU that simply call the SMMU specific 254: * function using a function pointer. These functions can be thought 255: * of as wrappers around the actual function 256: */ 257: 258: #define MMU_OP_VALID(_mmu, _field) \ 259: (((_mmu) != NULL) && \ 260: ((_mmu)->mmu_ops != NULL) && \ 261: ((_mmu)->mmu_ops->_field != NULL)) 262: 263: #define PT_OP_VALID(_pt, _field) \ 264: (((_pt) != NULL) && \ 265: ((_pt)->pt_ops != NULL) && \ 266: ((_pt)->pt_ops->_field != NULL)) 267: 268: /** 269: * kgsl_mmu_get_gpuaddr - Assign a GPU address to the memdesc 270: * @pagetable: GPU pagetable to assign the address in 271: * @memdesc: mem descriptor to assign the memory to 272: * 273: * Return: 0 on success or negative on failure 274: */ 275: static inline int kgsl_mmu_get_gpuaddr(struct kgsl_pagetable *pagetable, 276: struct kgsl_memdesc *memdesc) 277: { 278: if (PT_OP_VALID(pagetable, get_gpuaddr)) 279: return pagetable->pt_ops->get_gpuaddr(pagetable, memdesc); 280: 281: return -ENOMEM; 282: } 283: 284: /** 285: * kgsl_mmu_put_gpuaddr - Remove a GPU address from a pagetable 286: * @pagetable: Pagetable to release the memory from 287: * @memdesc: Memory descriptor containing the GPU address to free 288: * 289: * Release a GPU address in the MMU virtual address space. 290: */ 291: static inline void kgsl_mmu_put_gpuaddr(struct kgsl_pagetable *pagetable, 292: struct kgsl_memdesc *memdesc) 293: { 294: if (PT_OP_VALID(pagetable, put_gpuaddr)) 295: pagetable->pt_ops->put_gpuaddr(memdesc); 296: } 297: 298: static inline bool kgsl_mmu_ctx_terminated_on_fault(struct kgsl_mmu *mmu) 299: { 300: if (MMU_OP_VALID(mmu, mmu_ctx_terminated_on_fault)) 301: return mmu->mmu_ops->mmu_ctx_terminated_on_fault(mmu); 302: 303: return false; 304: } 305: 306: static inline u64 kgsl_mmu_get_current_ttbr0(struct kgsl_mmu *mmu, struct kgsl_context *context) 307: { 308: if (MMU_OP_VALID(mmu, mmu_get_current_ttbr0)) 309: return mmu->mmu_ops->mmu_get_current_ttbr0(mmu, context); 310: 311: return 0; 312: } 313: 314: static inline struct kgsl_pagetable *kgsl_mmu_getpagetable(struct kgsl_mmu *mmu, 315: unsigned long name) 316: { 317: if (MMU_OP_VALID(mmu, mmu_getpagetable)) 318: return mmu->mmu_ops->mmu_getpagetable(mmu, name); 319: MATCH LINES: 383, 385, 391, 392, 395, 397, 403 371: return pagetable->pt_ops->get_ttbr0(pagetable); 372: 373: return 0; 374: } 375: 376: static inline void kgsl_mmu_send_tlb_hint(struct kgsl_mmu *mmu, bool hint) 377: { 378: if (MMU_OP_VALID(mmu, mmu_send_tlb_hint)) 379: return mmu->mmu_ops->mmu_send_tlb_hint(mmu, hint); 380: } 381: 382: /** 383: * kgsl_mmu_reserve_global_gpuaddr - Reserve VA in the global VA space 384: * @device: A KGSL GPU device handle 385: * @memdesc: Pointer to a GPU memory descriptor 386: * 387: * Reserve VA in the global pagetable without mapping anything to this VA 388: * 389: * Return: 0 on success and negative error on failure 390: */ 391: int kgsl_mmu_reserve_global_gpuaddr(struct kgsl_device *device, 392: struct kgsl_memdesc *memdesc); 393: 394: /** 395: * kgsl_mmu_map_global - Map a memdesc as a global buffer 396: * @device: A KGSL GPU device handle 397: * @memdesc: Pointer to a GPU memory descriptor 398: * @padding: Any padding to add to the end of the VA allotment (in bytes) 399: * 400: * Map a buffer as globally accessible in all pagetable contexts 401: */ 402: void kgsl_mmu_map_global(struct kgsl_device *device, 403: struct kgsl_memdesc *memdesc, u32 padding); 404: 405: /** 406: * kgsl_mmu_pagetable_get_context_bank - Return the context bank number 407: * @pagetable: A handle to a given pagetable 408: * @context : LPAC or User context 409: * 410: * This function will find the context number of the given pagetable 411: 412: * Return: The context bank number the pagetable is attached to or 413: * negative error on failure. 414: */ 415: int kgsl_mmu_pagetable_get_context_bank(struct kgsl_pagetable *pagetable, 416: struct kgsl_context *context); 417: 418: 419: /** 420: * kgsl_mmu_pagetable_get_asid - Return the ASID number 421: * @pagetable: A handle to a given pagetable 422: * @context: LPAC or GC context 423: * 424: * This function will find the ASID number of the given pagetable 425: 426: * Return: The ASID number the pagetable is attached to or 427: * negative error on failure. --- FILE: \kgsl_pool.c | HITS: 3 --- MATCH LINES: 17, 48 5: */ 6: 7: #include 8: #include 9: #include 10: #include 11: #include 12: #include 13: 14: #include "kgsl_debugfs.h" 15: #include "kgsl_device.h" 16: #include "kgsl_pool.h" 17: #include "kgsl_sharedmem.h" 18: #include "kgsl_trace.h" 19: #include "kgsl_util.h" 20: 21: #ifdef CONFIG_QCOM_KGSL_SORT_POOL 22: 23: struct kgsl_pool_page_entry { 24: phys_addr_t physaddr; 25: struct page *page; 26: struct rb_node node; 27: }; 28: 29: static struct kmem_cache *addr_page_cache; 30: 31: static void *_pool_entry_alloc(gfp_t gfp_mask, void *arg) 32: { 33: return kmem_cache_alloc(addr_page_cache, gfp_mask); 34: } 35: 36: static void _pool_entry_free(void *element, void *arg) 37: { 38: return kmem_cache_free(addr_page_cache, element); 39: } 40: 41: static int 42: __kgsl_pool_add_page(struct kgsl_page_pool *pool, struct page *p) 43: { 44: struct rb_node **node, *parent = NULL; 45: struct kgsl_pool_page_entry *new_page, *entry; 46: 47: spin_lock(&pool->list_lock); 48: new_page = pool->mempool ? mempool_alloc(pool->mempool, GFP_ATOMIC) : 49: kmem_cache_alloc(addr_page_cache, GFP_ATOMIC); 50: if (new_page == NULL) { 51: spin_unlock(&pool->list_lock); 52: return -ENOMEM; 53: } 54: 55: node = &pool->pool_rbtree.rb_node; 56: new_page->physaddr = page_to_phys(p); 57: new_page->page = p; 58: 59: while (*node != NULL) { 60: parent = *node; 61: entry = rb_entry(parent, struct kgsl_pool_page_entry, node); 62: 63: if (new_page->physaddr < entry->physaddr) 64: node = &parent->rb_left; 65: else 66: node = &parent->rb_right; 67: } 68: 69: rb_link_node(&new_page->node, parent, node); 70: rb_insert_color(&new_page->node, &pool->pool_rbtree); 71: 72: /* MATCH LINES: 98 86: struct rb_node *node; 87: struct kgsl_pool_page_entry *entry; 88: struct page *p; 89: 90: node = rb_first(&pool->pool_rbtree); 91: if (!node) 92: return NULL; 93: 94: entry = rb_entry(node, struct kgsl_pool_page_entry, node); 95: p = entry->page; 96: rb_erase(&entry->node, &pool->pool_rbtree); 97: if (pool->mempool) 98: mempool_free(entry, pool->mempool); 99: else 100: kmem_cache_free(addr_page_cache, entry); 101: 102: /* 103: * page_count may be read without the list_lock held. Use WRITE_ONCE 104: * to avoid compiler optimizations that may break consistency. 105: */ 106: ASSERT_EXCLUSIVE_WRITER(pool->page_count); 107: WRITE_ONCE(pool->page_count, pool->page_count - 1); 108: return p; 109: } 110: 111: static void kgsl_pool_list_init(struct kgsl_page_pool *pool) 112: { 113: pool->pool_rbtree = RB_ROOT; 114: } 115: 116: static void kgsl_pool_cache_init(void) 117: { 118: addr_page_cache = KMEM_CACHE(kgsl_pool_page_entry, 0); 119: } 120: 121: static void kgsl_pool_cache_destroy(void) 122: { --- FILE: \kgsl_pool.h | HITS: 2 --- MATCH LINES: 93 81: u32 reserved_pages; 82: spinlock_t list_lock; 83: struct list_head page_list; 84: struct dentry *debug_root; 85: u32 max_pages; 86: }; 87: #endif 88: 89: extern struct kgsl_page_pool kgsl_pools[6]; 90: extern int kgsl_num_pools; 91: 92: /** 93: * kgsl_pool_free_page - Frees the page and adds it back to pool/system memory 94: * @page: Pointer to page struct that needs to be freed 95: */ 96: void kgsl_pool_free_page(struct page *page); 97: 98: /** 99: * kgsl_get_page_size - Get supported pagesize 100: * @size: Size of the page 101: * @align: Desired alignment of the size 102: * 103: * Return largest available page size from pools that can be used to meet 104: * given size and alignment requirements 105: */ 106: u32 kgsl_get_page_size(size_t size, unsigned int align); 107: 108: /** 109: * kgsl_pool_alloc_page - Allocate a page of requested size 110: * @page_size: Size of the page to be allocated 111: * @pages: pointer to hold list of pages, should be big enough to hold 112: * requested page 113: * @len: Length of array pages 114: * 115: * Return total page count on success and negative value on failure 116: */ 117: int kgsl_pool_alloc_page(int *page_size, struct page **pages, MATCH LINES: 147 135: 136: /** 137: * kgsl_pool_size_total - Return the number of pages in all kgsl page pools 138: */ 139: int kgsl_pool_size_total(void); 140: 141: /** 142: * kgsl_probe_page_pools - Initialize the memory pools 143: */ 144: void kgsl_probe_page_pools(void); 145: 146: /** 147: * kgsl_exit_page_pools - Free outstanding pooled memory 148: */ 149: void kgsl_exit_page_pools(void); 150: 151: #endif 152: #endif /* __KGSL_POOL_H */ 153: --- FILE: \kgsl_reclaim.c | HITS: 89 --- MATCH LINES: 15, 35, 36, 51, 53, 54, 55, 56, 57, 59, 72, 74, 85, 86, 101, 103, 104, 105, 106, 107, 109, 122, 124, 130, 132, 136, 137, 138, 141, 142, 146, 152, 153, 154, 158, 160, 162, 166, 168, 195, 200, 227, 240, 245, 260, 261, 265, 269, 273, 274, 275, 278, 284, 285, 300, 305, 310, 315, 318, 325, 326, 327, 328, 329, 330, 332, 336, 340, 347, 348, 356 3: * Copyright (c) 2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include 8: #include 9: #include 10: #include 11: #include 12: #include 13: 14: #include "kgsl_reclaim.h" 15: #include "kgsl_sharedmem.h" 16: #include "kgsl_trace.h" 17: 18: /* 19: * Reclaiming excessive number of pages from a process will impact launch 20: * latency for the subsequent launch of the process. After measuring the 21: * launch latencies by having various maximum limits, it has been decided 22: * that allowing 30MB (7680 pages) of relcaim per process will have little 23: * impact and the latency will be within acceptable limit. 24: */ 25: static u32 kgsl_reclaim_max_page_limit = 7680; 26: 27: /* Setting this to 0 means we reclaim pages as specified in shrinker call */ 28: static u32 kgsl_nr_to_scan; 29: 30: struct work_struct reclaim_work; 31: 32: static atomic_t kgsl_nr_to_reclaim; 33: 34: #if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) 35: static void kgsl_memdesc_clear_unevictable(struct kgsl_process_private *process, 36: struct kgsl_memdesc *memdesc) 37: { 38: struct folio_batch fbatch; 39: int i; 40: 41: /* 42: * Pages that are first allocated are by default added to 43: * unevictable list. To reclaim them, we first clear the 44: * AS_UNEVICTABLE flag of the shmem file address space thus 45: * check_move_unevictable_folios() places them on the 46: * evictable list. 47: * 48: * Once reclaim is done, hint that further shmem allocations 49: * will have to be on the unevictable list. 50: */ 51: mapping_clear_unevictable(memdesc->shmem_filp->f_mapping); 52: folio_batch_init(&fbatch); 53: for (i = 0; i < memdesc->page_count; i++) { 54: set_page_dirty_lock(memdesc->pages[i]); 55: spin_lock(&memdesc->lock); 56: folio_batch_add(&fbatch, page_folio(memdesc->pages[i])); 57: memdesc->pages[i] = NULL; 58: atomic_inc(&process->unpinned_page_count); 59: spin_unlock(&memdesc->lock); 60: if (folio_batch_count(&fbatch) == PAGEVEC_SIZE) { 61: check_move_unevictable_folios(&fbatch); 62: __folio_batch_release(&fbatch); 63: } 64: } 65: 66: if (folio_batch_count(&fbatch)) { 67: check_move_unevictable_folios(&fbatch); 68: __folio_batch_release(&fbatch); 69: } 70: } 71: 72: static int kgsl_read_mapping(struct kgsl_memdesc *memdesc, struct page **page, int i) 73: { 74: struct folio *folio = shmem_read_folio_gfp(memdesc->shmem_filp->f_mapping, 75: i, kgsl_gfp_mask(0)); 76: 77: if (!IS_ERR(folio)) { 78: *page = folio_page(folio, 0); 79: return 0; 80: } 81: 82: return PTR_ERR(folio); 83: } 84: #else 85: static void kgsl_memdesc_clear_unevictable(struct kgsl_process_private *process, 86: struct kgsl_memdesc *memdesc) 87: { 88: struct pagevec pvec; 89: int i; 90: 91: /* 92: * Pages that are first allocated are by default added to 93: * unevictable list. To reclaim them, we first clear the 94: * AS_UNEVICTABLE flag of the shmem file address space thus 95: * check_move_unevictable_pages() places them on the 96: * evictable list. 97: * 98: * Once reclaim is done, hint that further shmem allocations 99: * will have to be on the unevictable list. 100: */ 101: mapping_clear_unevictable(memdesc->shmem_filp->f_mapping); 102: pagevec_init(&pvec); 103: for (i = 0; i < memdesc->page_count; i++) { 104: set_page_dirty_lock(memdesc->pages[i]); 105: spin_lock(&memdesc->lock); 106: pagevec_add(&pvec, memdesc->pages[i]); 107: memdesc->pages[i] = NULL; 108: atomic_inc(&process->unpinned_page_count); 109: spin_unlock(&memdesc->lock); 110: if (pagevec_count(&pvec) == PAGEVEC_SIZE) { 111: check_move_unevictable_pages(&pvec); 112: __pagevec_release(&pvec); 113: } 114: } 115: 116: if (pagevec_count(&pvec)) { 117: check_move_unevictable_pages(&pvec); 118: __pagevec_release(&pvec); 119: } 120: } 121: 122: static int kgsl_read_mapping(struct kgsl_memdesc *memdesc, struct page **page, int i) 123: { 124: *page = shmem_read_mapping_page_gfp(memdesc->shmem_filp->f_mapping, 125: i, kgsl_gfp_mask(0)); 126: return PTR_ERR_OR_ZERO(*page); 127: } 128: #endif 129: 130: static int kgsl_memdesc_get_reclaimed_pages(struct kgsl_mem_entry *entry) 131: { 132: struct kgsl_memdesc *memdesc = &entry->memdesc; 133: int i, ret; 134: struct page *page = NULL; 135: 136: spin_lock(&memdesc->lock); 137: for (i = 0; i < memdesc->page_count; i++) { 138: if (memdesc->pages[i]) 139: continue; 140: 141: spin_unlock(&memdesc->lock); 142: ret = kgsl_read_mapping(memdesc, &page, i); 143: if (ret) 144: return ret; 145: 146: kgsl_page_sync(memdesc->dev, page, PAGE_SIZE, DMA_BIDIRECTIONAL); 147: 148: /* 149: * Update the pages array only if vmfault has not 150: * updated it meanwhile 151: */ 152: spin_lock(&memdesc->lock); 153: if (!memdesc->pages[i]) { 154: memdesc->pages[i] = page; 155: atomic_dec(&entry->priv->unpinned_page_count); 156: } else 157: put_page(page); 158: spin_unlock(&memdesc->lock); 159: } 160: spin_unlock(&memdesc->lock); 161: 162: ret = kgsl_mmu_map(memdesc->pagetable, memdesc); 163: if (ret) 164: return ret; 165: 166: trace_kgsl_reclaim_memdesc(entry, false); 167: 168: CLEAR_FLAG(KGSL_MEMDESC_RECLAIMED | KGSL_MEMDESC_SKIP_RECLAIM, &memdesc->priv); 169: 170: return 0; 171: } 172: 173: int kgsl_reclaim_to_pinned_state( 174: struct kgsl_process_private *process) 175: { 176: struct kgsl_mem_entry *entry, *valid_entry; 177: int next = 0, ret = 0, count; 178: 179: mutex_lock(&process->reclaim_lock); 180: 181: if (test_bit(KGSL_PROC_PINNED_STATE, &process->state)) 182: goto done; 183: 184: count = atomic_read(&process->unpinned_page_count); 185: 186: for ( ; ; ) { 187: valid_entry = NULL; 188: spin_lock(&process->mem_lock); 189: entry = idr_get_next(&process->mem_idr, &next); 190: if (entry == NULL) { 191: spin_unlock(&process->mem_lock); 192: break; 193: } 194: 195: if (TEST_FLAG(KGSL_MEMDESC_RECLAIMED, &entry->memdesc.priv)) 196: valid_entry = kgsl_mem_entry_get(entry); 197: spin_unlock(&process->mem_lock); 198: 199: if (valid_entry) { 200: ret = kgsl_memdesc_get_reclaimed_pages(entry); 201: kgsl_mem_entry_put(entry); 202: if (ret) 203: goto done; 204: } 205: 206: next++; 207: } 208: 209: trace_kgsl_reclaim_process(process, count, false); 210: set_bit(KGSL_PROC_PINNED_STATE, &process->state); 211: done: 212: mutex_unlock(&process->reclaim_lock); 213: return ret; 214: } 215: 216: static void kgsl_reclaim_foreground_work(struct work_struct *work) 217: { 218: struct kgsl_process_private *process = 219: container_of(work, struct kgsl_process_private, fg_work); 220: 221: if (test_bit(KGSL_PROC_STATE, &process->state)) 222: kgsl_reclaim_to_pinned_state(process); 223: kgsl_process_private_put(process); 224: } 225: 226: #ifdef CONFIG_QCOM_KGSL_HYBRID_ALLOCATION 227: static void _copy_page(struct kgsl_memdesc *memdesc, struct page *dest, struct page *src) 228: { 229: void *src_ptr, *dest_ptr; 230: 231: set_page_dirty_lock(src); 232: 233: src_ptr = kmap_local_page(src); 234: dest_ptr = kmap_local_page(dest); 235: 236: memcpy(dest_ptr, src_ptr, PAGE_SIZE); 237: kunmap_local(src_ptr); 238: kunmap_local(dest_ptr); 239: 240: kgsl_page_sync(memdesc->dev, dest, PAGE_SIZE, DMA_BIDIRECTIONAL); 241: } 242: 243: static u32 kgsl_shmem_mem_entry_migrate(struct mm_struct *mm, struct kgsl_mem_entry *entry) 244: { 245: struct kgsl_memdesc *memdesc = &entry->memdesc; 246: u32 page_count = 0; 247: struct page **pages = NULL; 248: struct file *shmem_filp = NULL; 249: int i = 0; 250: int ret = 1; 251: int vidx; 252: struct vm_area_struct *vma; 253: int page_size = PAGE_SIZE; 254: struct page **old_pages; 255: 256: /* Skip mem entries that are mapped into a VBO */ 257: if (atomic_read(&entry->vbo_count)) 258: return 0; 259: 260: /* Check if migrating this memdesc will put us over the limit */ 261: if ((atomic_read(&entry->priv->migrated_page_count) + memdesc->page_count) > 262: kgsl_reclaim_max_page_limit) 263: return 0; 264: 265: pages = kvcalloc(memdesc->page_count, sizeof(*pages), GFP_KERNEL); 266: if (!pages) 267: return 0; 268: 269: shmem_filp = kgsl_memdesc_file_setup(memdesc); 270: if (IS_ERR_OR_NULL(shmem_filp)) 271: goto cleanup_pages; 272: 273: /* Allocate replacement shmem pages */ 274: for (i = 0; i < memdesc->page_count; i++) { 275: ret = kgsl_alloc_shmem_page(memdesc, shmem_filp, &page_size, &pages[i], NULL, i); 276: if (ret <= 0) { 277: pr_err_ratelimited( 278: "kgsl: Failed to alloc shmem page process %d entry %d offset %d\n", 279: pid_nr(entry->priv->pid), entry->id, i); 280: goto cleanup_shmem; 281: } 282: } 283: 284: /* Unmap the memdesc from the mmu */ 285: ret = kgsl_mmu_unmap(memdesc->pagetable, memdesc); 286: if (ret) { 287: pr_err_ratelimited("kgsl: Failed to unmap process %d entry %d\n", 288: pid_nr(entry->priv->pid), entry->id); 289: kill_pid(entry->priv->pid, SIGKILL, 1); 290: goto cleanup_shmem; 291: } 292: 293: /* Take the mmap write lock to prevent concurrent entry mmaps and vm_faults */ 294: mmap_write_lock(mm); 295: 296: /* 297: * Zap ptes to force a vm_fault on the next userspace access. 298: * vma_idr is protected by the mmap lock 299: */ 300: idr_for_each_entry(&memdesc->vma_idr, vma, vidx) { 301: zap_page_range_single(vma, vma->vm_start, 302: vma->vm_end - vma->vm_start, NULL); 303: } 304: 305: for (i = 0; i < memdesc->page_count; ) { 306: struct page *p; 307: int n; 308: int count; 309: 310: p = memdesc->pages[i]; 311: count = 1 << compound_order(p); 312: 313: /* Copy over existing data */ 314: for (n = 0; n < count; n++) { 315: struct page *page = memdesc->pages[i + n]; 316: struct page *new_page = pages[i + n]; 317: 318: _copy_page(memdesc, new_page, page); 319: page_count++; 320: } 321: 322: i += count; 323: } 324: 325: old_pages = memdesc->pages; 326: spin_lock(&memdesc->lock); 327: memdesc->pages = pages; 328: memdesc->shmem_filp = shmem_filp; 329: SET_FLAG(KGSL_MEMDESC_MIGRATED, &memdesc->priv); 330: spin_unlock(&memdesc->lock); 331: 332: /* Re-enable mmaps and vm_faults on the entry memdesc */ 333: mmap_write_unlock(mm); 334: 335: /* Free the old pages back into the pool */ 336: kgsl_pool_free_pages(old_pages, memdesc->page_count); 337: kvfree(old_pages); 338: 339: /* Map the new pages to the mmu */ 340: ret = kgsl_mmu_map(memdesc->pagetable, memdesc); 341: if (ret) { 342: pr_err_ratelimited("kgsl: Failed to map process %d entry %d\n", 343: pid_nr(entry->priv->pid), entry->id); 344: kill_pid(entry->priv->pid, SIGKILL, 1); 345: } 346: 347: atomic_add(memdesc->page_count, &entry->priv->migrated_page_count); 348: trace_kgsl_migrate_memdesc(entry); 349: 350: return page_count; 351: 352: cleanup_shmem: 353: for (i--; i >= 0; i--) 354: put_page(pages[i]); 355: 356: kgsl_memdesc_pagelist_cleanup(shmem_filp, memdesc); 357: SHMEM_I(shmem_filp->f_mapping->host)->android_vendor_data1 = 0; 358: fput(shmem_filp); 359: 360: cleanup_pages: 361: kvfree(pages); 362: 363: return 0; 364: } 365: 366: static void kgsl_shmem_migrate(struct kgsl_process_private *process) 367: { 368: u32 migrate_count = 0; 369: struct kgsl_mem_entry *entry; 370: struct task_struct *task; 371: struct mm_struct *mm; 372: u32 next = 0; 373: 374: /* Skip migration if we're already over the limit for the process */ 375: if (atomic_read(&process->migrated_page_count) >= kgsl_reclaim_max_page_limit) 376: return; 377: 378: if (!mutex_trylock(&process->reclaim_lock)) 379: return; 380: MATCH LINES: 411, 412, 413 399: 400: spin_lock(&process->mem_lock); 401: entry = idr_get_next(&process->mem_idr, &next); 402: if (entry == NULL) { 403: spin_unlock(&process->mem_lock); 404: break; 405: } 406: 407: /* 408: * Skip entries that are pending free or are already migrated or 409: * cannot be reclaimed 410: */ 411: priv = atomic_read(&entry->memdesc.priv); 412: if (!(entry->pending_free || (priv & KGSL_MEMDESC_MIGRATED) || 413: !(priv & KGSL_MEMDESC_CAN_RECLAIM))) 414: valid_entry = kgsl_mem_entry_get(entry); 415: 416: spin_unlock(&process->mem_lock); 417: 418: next++; 419: if (!valid_entry) 420: continue; 421: 422: migrate_count += kgsl_shmem_mem_entry_migrate(mm, valid_entry); 423: kgsl_mem_entry_put(valid_entry); 424: } 425: 426: clear_bit(KGSL_PROC_CAN_MIGRATE, &process->state); 427: abort: 428: trace_kgsl_migrate_process(process, migrate_count); 429: mmput(mm); 430: put_task: 431: put_task_struct(task); 432: done: 433: mutex_unlock(&process->reclaim_lock); 434: } 435: 436: static void kgsl_background_work(struct work_struct *work) 437: { MATCH LINES: 538, 572, 573, 575, 576, 577, 594, 600, 606, 607, 608, 609, 610, 611, 612 526: return ret ? ret : count; 527: } 528: 529: ssize_t kgsl_nr_to_scan_show(struct device *dev, 530: struct device_attribute *attr, char *buf) 531: { 532: return scnprintf(buf, PAGE_SIZE, "%d\n", kgsl_nr_to_scan); 533: } 534: 535: static u32 kgsl_reclaim_process(struct kgsl_process_private *process, 536: u32 pages_to_reclaim) 537: { 538: struct kgsl_memdesc *memdesc; 539: struct kgsl_mem_entry *entry, *valid_entry; 540: u32 next = 0, remaining = pages_to_reclaim, priv = 0; 541: 542: /* 543: * If we do not get the lock here, it means that the buffers are 544: * being pinned back. So do not keep waiting here as we would anyway 545: * return empty handed once the lock is acquired. 546: */ 547: if (!mutex_trylock(&process->reclaim_lock)) 548: return 0; 549: 550: while (remaining) { 551: 552: if (atomic_read(&process->unpinned_page_count) >= 553: kgsl_reclaim_max_page_limit) 554: break; 555: 556: /* Abort reclaim if process submitted work. */ 557: if (atomic_read(&process->cmd_count)) 558: break; 559: 560: /* Abort reclaim if process foreground hint is received. */ 561: if (test_bit(KGSL_PROC_STATE, &process->state)) 562: break; 563: 564: valid_entry = NULL; 565: spin_lock(&process->mem_lock); 566: entry = idr_get_next(&process->mem_idr, &next); 567: if (entry == NULL) { 568: spin_unlock(&process->mem_lock); 569: break; 570: } 571: 572: memdesc = &entry->memdesc; 573: priv = atomic_read(&memdesc->priv); 574: if (!entry->pending_free && 575: (priv & KGSL_MEMDESC_CAN_RECLAIM) && 576: !(priv & KGSL_MEMDESC_RECLAIMED) && 577: !(priv & KGSL_MEMDESC_SKIP_RECLAIM)) 578: valid_entry = kgsl_mem_entry_get(entry); 579: spin_unlock(&process->mem_lock); 580: 581: if (!valid_entry) { 582: next++; 583: continue; 584: } 585: 586: /* Do not reclaim pages mapped into a VBO */ 587: if (atomic_read(&valid_entry->vbo_count)) { 588: kgsl_mem_entry_put(entry); 589: next++; 590: continue; 591: } 592: 593: if ((atomic_read(&process->unpinned_page_count) + 594: memdesc->page_count) > kgsl_reclaim_max_page_limit) { 595: kgsl_mem_entry_put(entry); 596: next++; 597: continue; 598: } 599: 600: if (memdesc->page_count > remaining) { 601: kgsl_mem_entry_put(entry); 602: next++; 603: continue; 604: } 605: 606: if (!kgsl_mmu_unmap(memdesc->pagetable, memdesc)) { 607: kgsl_memdesc_clear_unevictable(process, memdesc); 608: remaining -= memdesc->page_count; 609: reclaim_shmem_address_space(memdesc->shmem_filp->f_mapping); 610: mapping_set_unevictable(memdesc->shmem_filp->f_mapping); 611: SET_FLAG(KGSL_MEMDESC_RECLAIMED, &memdesc->priv); 612: trace_kgsl_reclaim_memdesc(entry, true); 613: } 614: 615: kgsl_mem_entry_put(entry); 616: next++; 617: } 618: 619: if (next) 620: clear_bit(KGSL_PROC_PINNED_STATE, &process->state); 621: 622: trace_kgsl_reclaim_process(process, pages_to_reclaim - remaining, true); 623: mutex_unlock(&process->reclaim_lock); 624: 625: return (pages_to_reclaim - remaining); 626: } 627: 628: static void kgsl_reclaim_background_work(struct work_struct *work) 629: { 630: u32 bg_proc = 0, nr_pages = atomic_read(&kgsl_nr_to_reclaim); 631: u64 pp_nr_pages; 632: struct list_head kgsl_reclaim_process_list; 633: struct kgsl_process_private *process, *next; 634: 635: INIT_LIST_HEAD(&kgsl_reclaim_process_list); 636: read_lock(&kgsl_driver.proclist_lock); --- FILE: \kgsl_reclaim.h | HITS: 1 --- MATCH LINES: 14 2: /* 3: * Copyright (c) 2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved. 5: */ 6: #ifndef __KGSL_RECLAIM_H 7: #define __KGSL_RECLAIM_H 8: 9: 10: #include "kgsl_device.h" 11: 12: #ifdef CONFIG_QCOM_KGSL_PROCESS_RECLAIM 13: 14: /* Set if all the memdescs of this process are pinned */ 15: #define KGSL_PROC_PINNED_STATE 0 16: /* Process foreground/background state. Set if process is in foreground */ 17: #define KGSL_PROC_STATE 1 18: 19: int kgsl_reclaim_start(void); 20: int kgsl_reclaim_init(void); 21: void kgsl_reclaim_close(void); 22: int kgsl_reclaim_to_pinned_state(struct kgsl_process_private *priv); 23: void kgsl_reclaim_proc_sysfs_init(struct kgsl_process_private *process); 24: void kgsl_reclaim_proc_private_init(struct kgsl_process_private *process); 25: ssize_t kgsl_proc_max_reclaim_limit_store(struct device *dev, 26: struct device_attribute *attr, const char *buf, size_t count); 27: ssize_t kgsl_proc_max_reclaim_limit_show(struct device *dev, 28: struct device_attribute *attr, char *buf); 29: ssize_t kgsl_nr_to_scan_store(struct device *dev, 30: struct device_attribute *attr, const char *buf, size_t count); 31: ssize_t kgsl_nr_to_scan_show(struct device *dev, 32: struct device_attribute *attr, char *buf); 33: #else 34: static inline int kgsl_reclaim_start(void) 35: { 36: return 0; 37: } 38: --- FILE: \kgsl_sharedmem.c | HITS: 338 --- MATCH LINES: 20, 30 8: #include 9: #include 10: #include 11: #include 12: #include 13: #include 14: #include 15: #include 16: 17: #include "kgsl_device.h" 18: #include "kgsl_pool.h" 19: #include "kgsl_reclaim.h" 20: #include "kgsl_sharedmem.h" 21: #include "kgsl_util.h" 22: 23: /* 24: * The user can set this from debugfs to force failed memory allocations to 25: * fail without trying OOM first. This is a debug setting useful for 26: * stress applications that want to test failure cases without pushing the 27: * system into unrecoverable OOM panics 28: */ 29: 30: bool kgsl_sharedmem_noretry_flag; 31: 32: static DEFINE_MUTEX(kernel_map_global_lock); 33: 34: #define MEMTYPE(_type, _name) \ 35: static struct kgsl_memtype memtype_##_name = { \ 36: .type = _type, \ 37: .attr = { .name = __stringify(_name), .mode = 0444 } \ 38: } 39: 40: struct kgsl_memtype { 41: unsigned int type; 42: struct attribute attr; 43: }; 44: 45: /* We can not use macro MEMTYPE for "any(0)" because of special characters */ 46: static struct kgsl_memtype memtype_any0 = { 47: .type = KGSL_MEMTYPE_OBJECTANY, 48: .attr = { .name = "any(0)", .mode = 0444 }, 49: }; 50: 51: MEMTYPE(KGSL_MEMTYPE_FRAMEBUFFER, framebuffer); 52: MEMTYPE(KGSL_MEMTYPE_RENDERBUFFER, renderbuffer); 53: MEMTYPE(KGSL_MEMTYPE_ARRAYBUFFER, arraybuffer); 54: MEMTYPE(KGSL_MEMTYPE_ELEMENTARRAYBUFFER, elementarraybuffer); MATCH LINES: 188, 195, 196, 199 176: */ 177: if (!kgsl_process_private_get(priv)) { 178: kfree(work); 179: return -ENOENT; 180: } 181: 182: work->private = priv; 183: INIT_WORK(&work->work, process_private_deferred_put); 184: 185: spin_lock(&priv->mem_lock); 186: for (entry = idr_get_next(&priv->mem_idr, &id); entry; 187: id++, entry = idr_get_next(&priv->mem_idr, &id)) { 188: struct kgsl_memdesc *memdesc; 189: unsigned int type; 190: 191: if (!kgsl_mem_entry_get(entry)) 192: continue; 193: spin_unlock(&priv->mem_lock); 194: 195: memdesc = &entry->memdesc; 196: type = kgsl_memdesc_get_memtype(memdesc); 197: 198: if (type == memtype->type) 199: size += memdesc->size; 200: 201: kgsl_mem_entry_put(entry); 202: spin_lock(&priv->mem_lock); 203: } 204: spin_unlock(&priv->mem_lock); 205: 206: queue_work(kgsl_driver.lockless_workqueue, &work->work); 207: 208: return scnprintf(buf, PAGE_SIZE, "%llu\n", size); 209: } 210: 211: static const struct sysfs_ops memtype_sysfs_ops = { 212: .show = memtype_sysfs_show, 213: }; 214: 215: static struct kobj_type ktype_memtype = { 216: .sysfs_ops = &memtype_sysfs_ops, 217: .default_groups = memtype_groups, 218: }; 219: 220: static ssize_t 221: imported_mem_show(struct kgsl_process_private *priv, 222: int type, char *buf) 223: { MATCH LINES: 253, 259, 260 241: kfree(work); 242: return -ENOENT; 243: } 244: 245: work->private = priv; 246: INIT_WORK(&work->work, process_private_deferred_put); 247: 248: spin_lock(&priv->mem_lock); 249: for (entry = idr_get_next(&priv->mem_idr, &id); entry; 250: id++, entry = idr_get_next(&priv->mem_idr, &id)) { 251: 252: int egl_surface_count = 0, egl_image_count = 0; 253: struct kgsl_memdesc *m; 254: 255: if (!kgsl_mem_entry_get(entry)) 256: continue; 257: spin_unlock(&priv->mem_lock); 258: 259: m = &entry->memdesc; 260: if (kgsl_memdesc_usermem_type(m) == KGSL_MEM_ENTRY_ION) { 261: u64 size = m->size; 262: int total_egl_count; 263: 264: kgsl_get_egl_counts(entry, &egl_surface_count, 265: &egl_image_count); 266: total_egl_count = egl_surface_count + egl_image_count; 267: 268: /* 269: * Divide the total buffer size uniformly across all the 270: * processes that imported the buffer. 271: */ 272: do_div(size, (total_egl_count ? total_egl_count : 1)); 273: imported_mem += size; 274: } 275: 276: kgsl_mem_entry_put(entry); 277: spin_lock(&priv->mem_lock); 278: } 279: spin_unlock(&priv->mem_lock); 280: 281: queue_work(kgsl_driver.lockless_workqueue, &work->work); 282: 283: return scnprintf(buf, PAGE_SIZE, "%llu\n", imported_mem); 284: } MATCH LINES: 308, 319 296: { 297: u64 gpumem_total = atomic64_read(&priv->stats[type].cur); 298: u64 gpumem_mapped = atomic64_read(&priv->gpumem_mapped); 299: 300: if (gpumem_mapped > gpumem_total) 301: return -EIO; 302: 303: return scnprintf(buf, PAGE_SIZE, "%llu\n", 304: gpumem_total - gpumem_mapped); 305: } 306: 307: /** 308: * Show the current amount of memory allocated for the given memtype 309: */ 310: 311: static ssize_t 312: mem_entry_show(struct kgsl_process_private *priv, int type, char *buf) 313: { 314: return scnprintf(buf, PAGE_SIZE, "%lld\n", 315: atomic64_read(&priv->stats[type].cur)); 316: } 317: 318: /** 319: * Show the maximum memory allocated for the given memtype through the life of 320: * the process 321: */ 322: 323: static ssize_t 324: mem_entry_max_show(struct kgsl_process_private *priv, int type, char *buf) 325: { 326: return scnprintf(buf, PAGE_SIZE, "%llu\n", priv->stats[type].max); 327: } 328: 329: static ssize_t process_sysfs_show(struct kobject *kobj, 330: struct attribute *attr, char *buf) 331: { 332: struct kgsl_process_attribute *pattr = to_process_attr(attr); 333: 334: return pattr->show(kobj, pattr, buf); 335: } 336: 337: static ssize_t process_sysfs_store(struct kobject *kobj, 338: struct attribute *attr, const char *buf, size_t count) 339: { 340: struct kgsl_process_attribute *pattr = to_process_attr(attr); 341: 342: if (pattr->store) 343: return pattr->store(kobj, pattr, buf, count); MATCH LINES: 485, 486, 487, 488, 517, 522, 530, 535, 536, 537, 544, 545, 548, 552, 558, 559, 560, 565, 572, 575, 577, 580, 581, 583, 585, 586 473: kgsl_driver.full_cache_threshold = thresh; 474: return count; 475: } 476: 477: static ssize_t full_cache_threshold_show(struct device *dev, 478: struct device_attribute *attr, 479: char *buf) 480: { 481: return scnprintf(buf, PAGE_SIZE, "%d\n", 482: kgsl_driver.full_cache_threshold); 483: } 484: 485: static DEVICE_ATTR(vmalloc, 0444, memstat_show, NULL); 486: static DEVICE_ATTR(vmalloc_max, 0444, memstat_show, NULL); 487: static DEVICE_ATTR(page_alloc, 0444, memstat_show, NULL); 488: static DEVICE_ATTR(page_alloc_max, 0444, memstat_show, NULL); 489: static DEVICE_ATTR(coherent, 0444, memstat_show, NULL); 490: static DEVICE_ATTR(coherent_max, 0444, memstat_show, NULL); 491: static DEVICE_ATTR(secure, 0444, memstat_show, NULL); 492: static DEVICE_ATTR(secure_max, 0444, memstat_show, NULL); 493: static DEVICE_ATTR(mapped, 0444, memstat_show, NULL); 494: static DEVICE_ATTR(mapped_max, 0444, memstat_show, NULL); 495: static DEVICE_ATTR_RW(full_cache_threshold); 496: 497: static const struct attribute *drv_attr_list[] = { 498: &dev_attr_vmalloc.attr, 499: &dev_attr_vmalloc_max.attr, 500: &dev_attr_page_alloc.attr, 501: &dev_attr_page_alloc_max.attr, 502: &dev_attr_coherent.attr, 503: &dev_attr_coherent_max.attr, 504: &dev_attr_secure.attr, 505: &dev_attr_secure_max.attr, 506: &dev_attr_mapped.attr, 507: &dev_attr_mapped_max.attr, 508: &dev_attr_full_cache_threshold.attr, 509: #ifdef CONFIG_QCOM_KGSL_PROCESS_RECLAIM 510: &dev_attr_max_reclaim_limit.attr, 511: &dev_attr_page_reclaim_per_call.attr, 512: #endif 513: NULL, 514: }; 515: 516: int 517: kgsl_sharedmem_init_sysfs(void) 518: { 519: return sysfs_create_files(&kgsl_driver.virtdev.kobj, drv_attr_list); 520: } 521: 522: static vm_fault_t kgsl_paged_vmfault(struct kgsl_memdesc *memdesc, 523: struct vm_area_struct *vma, 524: struct vm_fault *vmf) 525: { 526: int pgoff, ret; 527: struct page *page; 528: unsigned int offset = vmf->address - vma->vm_start; 529: 530: if (offset >= memdesc->size) 531: return VM_FAULT_SIGBUS; 532: 533: pgoff = offset >> PAGE_SHIFT; 534: 535: spin_lock(&memdesc->lock); 536: if (memdesc->pages[pgoff]) { 537: page = memdesc->pages[pgoff]; 538: get_page(page); 539: } else { 540: struct kgsl_process_private *priv = 541: ((struct kgsl_mem_entry *)vma->vm_private_data)->priv; 542: 543: /* We are here because page was reclaimed */ 544: SET_FLAG(KGSL_MEMDESC_SKIP_RECLAIM, &memdesc->priv); 545: spin_unlock(&memdesc->lock); 546: 547: page = shmem_read_mapping_page_gfp( 548: memdesc->shmem_filp->f_mapping, pgoff, 549: kgsl_gfp_mask(0)); 550: if (IS_ERR(page)) 551: return VM_FAULT_SIGBUS; 552: kgsl_page_sync(memdesc->dev, page, PAGE_SIZE, DMA_BIDIRECTIONAL); 553: 554: /* 555: * Update the pages array only if the page was 556: * not already brought back. 557: */ 558: spin_lock(&memdesc->lock); 559: if (!memdesc->pages[pgoff]) { 560: memdesc->pages[pgoff] = page; 561: atomic_dec(&priv->unpinned_page_count); 562: get_page(page); 563: } 564: } 565: spin_unlock(&memdesc->lock); 566: 567: ret = vmf_insert_page(vma, vmf->address, page); 568: put_page(page); 569: return ret; 570: } 571: 572: static void kgsl_paged_unmap_kernel(struct kgsl_memdesc *memdesc) 573: { 574: mutex_lock(&kernel_map_global_lock); 575: if (!memdesc->hostptr) { 576: /* If already unmapped the refcount should be 0 */ 577: WARN_ON(memdesc->hostptr_count); 578: goto done; 579: } 580: memdesc->hostptr_count--; 581: if (memdesc->hostptr_count) 582: goto done; 583: vunmap(memdesc->hostptr); 584: 585: atomic_long_sub(memdesc->size, &kgsl_driver.stats.vmalloc); 586: memdesc->hostptr = NULL; 587: done: 588: mutex_unlock(&kernel_map_global_lock); 589: } 590: 591: #if IS_ENABLED(CONFIG_QCOM_SECURE_BUFFER) 592: 593: #include 594: 595: int kgsl_lock_sgt(struct sg_table *sgt, u64 size) 596: { 597: int dest_perms = PERM_READ | PERM_WRITE; 598: int source_vm = VMID_HLOS; 599: int dest_vm = VMID_CP_PIXEL; 600: int ret; 601: 602: do { 603: ret = hyp_assign_table(sgt, &source_vm, 1, &dest_vm, 604: &dest_perms, 1); 605: } while (ret == -EAGAIN); 606: 607: if (ret) { 608: /* 609: * If returned error code is EADDRNOTAVAIL, then this 610: * memory may no longer be in a usable state as security MATCH LINES: 644, 649, 653, 658, 674, 676, 677, 683, 684, 691, 700 632: do { 633: ret = hyp_assign_table(sgt, &source_vm, 1, &dest_vm, 634: &dest_perms, 1); 635: } while (ret == -EAGAIN); 636: 637: if (ret) 638: return ret; 639: 640: return 0; 641: } 642: #endif 643: 644: static int kgsl_paged_map_kernel(struct kgsl_memdesc *memdesc) 645: { 646: int ret = 0; 647: 648: /* Sanity check - don't map more than we could possibly chew */ 649: if (memdesc->size > ULONG_MAX) 650: return -ENOMEM; 651: 652: mutex_lock(&kernel_map_global_lock); 653: if ((!memdesc->hostptr) && (memdesc->pages != NULL)) { 654: pgprot_t page_prot; 655: u64 cache; 656: 657: /* Determine user-side caching policy */ 658: cache = kgsl_memdesc_get_cachemode(memdesc); 659: switch (cache) { 660: case KGSL_CACHEMODE_WRITETHROUGH: 661: page_prot = PAGE_KERNEL; 662: WARN_ONCE(1, "WRITETHROUGH is deprecated for arm64"); 663: break; 664: case KGSL_CACHEMODE_WRITEBACK: 665: page_prot = PAGE_KERNEL; 666: break; 667: case KGSL_CACHEMODE_UNCACHED: 668: case KGSL_CACHEMODE_WRITECOMBINE: 669: default: 670: page_prot = pgprot_writecombine(PAGE_KERNEL); 671: break; 672: } 673: 674: memdesc->hostptr = vmap(memdesc->pages, memdesc->page_count, 675: VM_IOREMAP, page_prot); 676: if (memdesc->hostptr) 677: KGSL_STATS_ADD(memdesc->size, 678: &kgsl_driver.stats.vmalloc, 679: &kgsl_driver.stats.vmalloc_max); 680: else 681: ret = -ENOMEM; 682: } 683: if (memdesc->hostptr) 684: memdesc->hostptr_count++; 685: 686: mutex_unlock(&kernel_map_global_lock); 687: 688: return ret; 689: } 690: 691: static vm_fault_t kgsl_contiguous_vmfault(struct kgsl_memdesc *memdesc, 692: struct vm_area_struct *vma, 693: struct vm_fault *vmf) 694: { 695: unsigned long offset, pfn; 696: 697: offset = ((unsigned long) vmf->address - vma->vm_start) >> 698: PAGE_SHIFT; 699: 700: pfn = (memdesc->physaddr >> PAGE_SHIFT) + offset; 701: return vmf_insert_pfn(vma, vmf->address, pfn); 702: } 703: 704: static void _dma_cache_op(struct device *dev, struct page *page, 705: unsigned int op) 706: { 707: struct scatterlist sgl; 708: 709: /* Skip cache maintenance for the shared zero page. */ 710: if (is_zero_page(page)) 711: return; 712: 713: sg_init_table(&sgl, 1); 714: sg_set_page(&sgl, page, PAGE_SIZE, 0); 715: sg_dma_address(&sgl) = page_to_phys(page); 716: 717: /* 718: * APIs for Cache Maintenance Operations are updated in kernel 719: * version 6.1. Prior to 6.1, dma_sync_sg_for_device() with 720: * DMA_FROM_DEVICE as direction triggers cache invalidate and 721: * clean whereas in kernel version 6.1, it triggers only cache 722: * clean. Hence use dma_sync_sg_for_cpu() for cache invalidate 723: * for kernel version 6.1 and above. 724: */ MATCH LINES: 747, 752, 762, 763, 770, 773, 775, 780, 786, 792, 793, 798, 827, 830, 832, 835, 839, 842, 843, 845, 848, 850, 854, 857, 858, 860, 861, 865, 871, 879, 880, 888, 894, 898, 899, 905, 908, 915, 921, 929, 930, 938, 944, 948, 949, 955, 958, 981, 987, 988, 991, 993, 994, 998, 1002, 1004, 1005, 1006, 1008, 1009, 1011, 1014, 1016, 1019, 1022, 1024, 1031, 1057, 1063, 1067, 1068, 1070, 1080, 1105, 1107, 1110, 1111, 1117, 1124, 1126, 1129, 1130, 1136 735: case KGSL_CACHE_OP_CLEAN: 736: dma_sync_sg_for_device(dev, &sgl, 1, DMA_TO_DEVICE); 737: break; 738: case KGSL_CACHE_OP_INV: 739: dma_sync_sg_for_device(dev, &sgl, 1, DMA_FROM_DEVICE); 740: #if (KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE) 741: dma_sync_sg_for_cpu(dev, &sgl, 1, DMA_FROM_DEVICE); 742: #endif 743: break; 744: } 745: } 746: 747: int kgsl_cache_range_op(struct kgsl_memdesc *memdesc, uint64_t offset, 748: uint64_t size, unsigned int op) 749: { 750: int i; 751: 752: if (memdesc->flags & KGSL_MEMFLAGS_IOCOHERENT) 753: return 0; 754: 755: if (size == 0 || size > UINT_MAX) 756: return -EINVAL; 757: 758: /* Make sure that the offset + size does not overflow */ 759: if ((offset + size < offset) || (offset + size < size)) 760: return -ERANGE; 761: 762: /* Check that offset+length does not exceed memdesc->size */ 763: if (offset + size > memdesc->size) 764: return -ERANGE; 765: 766: size += offset & PAGE_MASK; 767: offset &= ~PAGE_MASK; 768: 769: /* If there is a sgt, use for_each_sg_page to walk it */ 770: if (memdesc->sgt) { 771: struct sg_page_iter sg_iter; 772: 773: for_each_sg_page(memdesc->sgt->sgl, &sg_iter, 774: PAGE_ALIGN(size) >> PAGE_SHIFT, offset >> PAGE_SHIFT) 775: _dma_cache_op(memdesc->dev, sg_page_iter_page(&sg_iter), op); 776: return 0; 777: } 778: 779: /* Otherwise just walk through the list of pages */ 780: for (i = 0; i < memdesc->page_count; i++) { 781: u64 cur = (i << PAGE_SHIFT); 782: 783: if ((cur < offset) || (cur >= (offset + size))) 784: continue; 785: 786: _dma_cache_op(memdesc->dev, memdesc->pages[i], op); 787: } 788: 789: return 0; 790: } 791: 792: void kgsl_memdesc_init(struct kgsl_device *device, 793: struct kgsl_memdesc *memdesc, uint64_t flags) 794: { 795: struct kgsl_mmu *mmu = &device->mmu; 796: unsigned int align; 797: 798: memset(memdesc, 0, sizeof(*memdesc)); 799: /* Turn off SVM if the system doesn't support it */ 800: if (!kgsl_mmu_is_perprocess(mmu)) 801: flags &= ~((uint64_t) KGSL_MEMFLAGS_USE_CPU_MAP); 802: 803: /* Secure memory disables advanced addressing modes */ 804: if (flags & KGSL_MEMFLAGS_SECURE) 805: flags &= ~((uint64_t) KGSL_MEMFLAGS_USE_CPU_MAP); 806: 807: /* Disable IO coherence if it is not supported on the chip */ 808: if (!kgsl_mmu_has_feature(device, KGSL_MMU_IO_COHERENT)) { 809: flags &= ~((uint64_t) KGSL_MEMFLAGS_IOCOHERENT); 810: 811: WARN_ONCE(IS_ENABLED(CONFIG_QCOM_KGSL_IOCOHERENCY_DEFAULT), 812: "I/O coherency is not supported on this target\n"); 813: } else if (IS_ENABLED(CONFIG_QCOM_KGSL_IOCOHERENCY_DEFAULT)) 814: flags |= KGSL_MEMFLAGS_IOCOHERENT; 815: 816: /* 817: * We can't enable I/O coherency on uncached surfaces because of 818: * situations where hardware might snoop the cpu caches which can 819: * have stale data. This happens primarily due to the limitations 820: * of dma caching APIs available on arm64 821: */ 822: if (!kgsl_cachemode_is_cached(flags)) 823: flags &= ~((u64) KGSL_MEMFLAGS_IOCOHERENT); 824: 825: if (kgsl_mmu_has_feature(device, KGSL_MMU_NEED_GUARD_PAGE) || 826: (flags & KGSL_MEMFLAGS_GUARD_PAGE)) 827: SET_FLAG(KGSL_MEMDESC_GUARD_PAGE, &memdesc->priv); 828: 829: if (flags & KGSL_MEMFLAGS_SECURE) 830: SET_FLAG(KGSL_MEMDESC_SECURE, &memdesc->priv); 831: 832: memdesc->flags = flags; 833: 834: /* 835: * For io-coherent buffers don't set memdesc->dev, so that we skip DMA 836: * cache operations at allocation time 837: */ 838: if (!(flags & KGSL_MEMFLAGS_IOCOHERENT)) 839: memdesc->dev = &kgsl_driver.virtdev; 840: 841: align = max_t(unsigned int, 842: kgsl_memdesc_get_align(memdesc), ilog2(PAGE_SIZE)); 843: kgsl_memdesc_set_align(memdesc, align); 844: 845: spin_lock_init(&memdesc->lock); 846: } 847: 848: void kgsl_sharedmem_free(struct kgsl_memdesc *memdesc) 849: { 850: if (!memdesc || !memdesc->size) 851: return; 852: 853: /* Assume if no operations were specified something went bad early */ 854: if (!memdesc->ops) 855: return; 856: 857: if (memdesc->ops->put_gpuaddr) 858: memdesc->ops->put_gpuaddr(memdesc); 859: 860: if (memdesc->ops->free) 861: memdesc->ops->free(memdesc); 862: } 863: 864: int 865: kgsl_sharedmem_readl(const struct kgsl_memdesc *memdesc, 866: uint32_t *dst, 867: uint64_t offsetbytes) 868: { 869: uint32_t *src; 870: 871: if (WARN_ON(memdesc == NULL || memdesc->hostptr == NULL || 872: dst == NULL)) 873: return -EINVAL; 874: 875: WARN_ON(offsetbytes % sizeof(uint32_t) != 0); 876: if (offsetbytes % sizeof(uint32_t) != 0) 877: return -EINVAL; 878: 879: WARN_ON(offsetbytes > (memdesc->size - sizeof(uint32_t))); 880: if (offsetbytes > (memdesc->size - sizeof(uint32_t))) 881: return -ERANGE; 882: 883: /* 884: * We are reading shared memory between CPU and GPU. 885: * Make sure reads before this are complete 886: */ 887: rmb(); 888: src = (uint32_t *)(memdesc->hostptr + offsetbytes); 889: *dst = *src; 890: return 0; 891: } 892: 893: void 894: kgsl_sharedmem_writel(const struct kgsl_memdesc *memdesc, 895: uint64_t offsetbytes, 896: uint32_t src) 897: { 898: /* Quietly return if the memdesc isn't valid */ 899: if (IS_ERR_OR_NULL(memdesc) || WARN_ON(!memdesc->hostptr)) 900: return; 901: 902: if (WARN_ON(!IS_ALIGNED(offsetbytes, sizeof(u32)))) 903: return; 904: 905: if (WARN_ON(offsetbytes > (memdesc->size - sizeof(u32)))) 906: return; 907: 908: *((u32 *) (memdesc->hostptr + offsetbytes)) = src; 909: 910: /* Make sure the write is posted before continuing */ 911: wmb(); 912: } 913: 914: int 915: kgsl_sharedmem_readq(const struct kgsl_memdesc *memdesc, 916: uint64_t *dst, 917: uint64_t offsetbytes) 918: { 919: uint64_t *src; 920: 921: if (WARN_ON(memdesc == NULL || memdesc->hostptr == NULL || 922: dst == NULL)) 923: return -EINVAL; 924: 925: WARN_ON(offsetbytes % sizeof(uint32_t) != 0); 926: if (offsetbytes % sizeof(uint32_t) != 0) 927: return -EINVAL; 928: 929: WARN_ON(offsetbytes > (memdesc->size - sizeof(uint32_t))); 930: if (offsetbytes > (memdesc->size - sizeof(uint32_t))) 931: return -ERANGE; 932: 933: /* 934: * We are reading shared memory between CPU and GPU. 935: * Make sure reads before this are complete 936: */ 937: rmb(); 938: src = (uint64_t *)(memdesc->hostptr + offsetbytes); 939: *dst = *src; 940: return 0; 941: } 942: 943: void 944: kgsl_sharedmem_writeq(const struct kgsl_memdesc *memdesc, 945: uint64_t offsetbytes, 946: uint64_t src) 947: { 948: /* Quietly return if the memdesc isn't valid */ 949: if (IS_ERR_OR_NULL(memdesc) || WARN_ON(!memdesc->hostptr)) 950: return; 951: 952: if (WARN_ON(!IS_ALIGNED(offsetbytes, sizeof(u64)))) 953: return; 954: 955: if (WARN_ON(offsetbytes > (memdesc->size - sizeof(u64)))) 956: return; 957: 958: *((u64 *) (memdesc->hostptr + offsetbytes)) = src; 959: 960: /* Make sure the write is posted before continuing */ 961: wmb(); 962: } 963: 964: void kgsl_get_memory_usage(char *name, size_t name_size, uint64_t memflags) 965: { 966: unsigned int type = FIELD_GET(KGSL_MEMTYPE_MASK, memflags); 967: struct kgsl_memtype *memtype; 968: int i; 969: 970: for (i = 0; memtype_attrs[i]; i++) { 971: memtype = container_of(memtype_attrs[i], struct kgsl_memtype, attr); 972: if (memtype->type == type) { 973: strscpy(name, memtype->attr.name, name_size); 974: return; 975: } 976: } 977: 978: snprintf(name, name_size, "VK/others(%3d)", type); 979: } 980: 981: int kgsl_memdesc_sg_dma(struct kgsl_memdesc *memdesc, 982: phys_addr_t addr, u64 size) 983: { 984: int ret; 985: struct page *page = phys_to_page(addr); 986: 987: memdesc->sgt = kmalloc(sizeof(*memdesc->sgt), GFP_KERNEL); 988: if (memdesc->sgt == NULL) 989: return -ENOMEM; 990: 991: ret = sg_alloc_table(memdesc->sgt, 1, GFP_KERNEL); 992: if (ret) { 993: kfree(memdesc->sgt); 994: memdesc->sgt = NULL; 995: return ret; 996: } 997: 998: sg_set_page(memdesc->sgt->sgl, page, (size_t) size, 0); 999: return 0; 1000: } 1001: 1002: static void _kgsl_contiguous_free(struct kgsl_memdesc *memdesc) 1003: { 1004: dma_free_attrs(memdesc->dev, memdesc->size, 1005: memdesc->hostptr, memdesc->physaddr, 1006: memdesc->attrs); 1007: 1008: sg_free_table(memdesc->sgt); 1009: kfree(memdesc->sgt); 1010: 1011: memdesc->sgt = NULL; 1012: } 1013: 1014: static void kgsl_contiguous_free(struct kgsl_memdesc *memdesc) 1015: { 1016: if (!memdesc->hostptr) 1017: return; 1018: 1019: if (TEST_FLAG(KGSL_MEMDESC_MAPPED, &memdesc->priv)) 1020: return; 1021: 1022: atomic_long_sub(memdesc->size, &kgsl_driver.stats.coherent); 1023: 1024: _kgsl_contiguous_free(memdesc); 1025: } 1026: 1027: #ifdef CONFIG_QCOM_KGSL_USE_SHMEM 1028: #include 1029: #include 1030: 1031: static int _kgsl_shmem_alloc_page(struct kgsl_memdesc *memdesc, u32 order) 1032: { 1033: int pcount; 1034: struct page *page; 1035: gfp_t gfp_mask = kgsl_gfp_mask(order); 1036: 1037: if (fatal_signal_pending(current)) 1038: return -EINTR; 1039: 1040: /* Allocate non compound page to split 4K page chunks */ 1041: gfp_mask &= ~__GFP_COMP; 1042: 1043: page = alloc_pages(gfp_mask, order); 1044: if (page == NULL) { 1045: /* Retry with lower order pages */ 1046: if (order > 1) 1047: return -EAGAIN; 1048: else 1049: return -ENOMEM; 1050: } 1051: 1052: /* Split non-compound higher-order pages to 4k pages */ 1053: split_page(page, order); 1054: 1055: for (pcount = 0; pcount < (1 << order); pcount++) { 1056: clear_highpage(&page[pcount]); 1057: list_add_tail(&page[pcount].lru, &memdesc->shmem_page_list); 1058: } 1059: 1060: return pcount; 1061: } 1062: 1063: static int kgsl_shmem_alloc_pages(struct kgsl_memdesc *memdesc) 1064: { 1065: int ret, count = 0; 1066: u32 size, align, order; 1067: /* Length of remaining unallocated memdesc pages */ 1068: u64 len = memdesc->size - ((u64)memdesc->page_count << PAGE_SHIFT); 1069: 1070: /* 4k allocation managed by the SHMEM */ 1071: if (len == PAGE_SIZE) 1072: return 0; 1073: 1074: /* Start with 1MB alignment to get the biggest page we can */ 1075: align = ilog2(SZ_1M); 1076: size = kgsl_get_page_size(len, align); 1077: order = get_order(size); 1078: 1079: while (len) { 1080: ret = _kgsl_shmem_alloc_page(memdesc, order); 1081: 1082: if (ret == -EAGAIN) { 1083: size = PAGE_SIZE << --order; 1084: size = kgsl_get_page_size(size, ilog2(size)); 1085: align = ilog2(size); 1086: continue; 1087: } else if (ret <= 0) { 1088: return -ENOMEM; 1089: } 1090: 1091: count += ret; 1092: len -= size; 1093: size = kgsl_get_page_size(len, align); 1094: align = ilog2(size); 1095: order = get_order(size); 1096: } 1097: return count; 1098: } 1099: 1100: #if ((KERNEL_VERSION(6, 12, 18) <= LINUX_VERSION_CODE) && \ 1101: (KERNEL_VERSION(6, 13, 0) > LINUX_VERSION_CODE)) 1102: static void kgsl_shmem_fill_page(void *ptr, 1103: struct shmem_inode_info *inode, struct folio **folio, int order) 1104: { 1105: struct kgsl_memdesc *memdesc = (struct kgsl_memdesc *)inode->android_vendor_data1; 1106: 1107: if (IS_ERR_OR_NULL(memdesc) || order) 1108: return; 1109: 1110: if (list_empty(&memdesc->shmem_page_list)) { 1111: int ret = kgsl_shmem_alloc_pages(memdesc); 1112: 1113: if (ret <= 0) 1114: return; 1115: } 1116: 1117: *folio = list_first_entry(&memdesc->shmem_page_list, struct folio, lru); 1118: list_del(&(*folio)->lru); 1119: } 1120: #else 1121: static void kgsl_shmem_fill_page(void *ptr, 1122: struct shmem_inode_info *inode, struct folio **folio) 1123: { 1124: struct kgsl_memdesc *memdesc = (struct kgsl_memdesc *)inode->android_vendor_data1; 1125: 1126: if (IS_ERR_OR_NULL(memdesc)) 1127: return; 1128: 1129: if (list_empty(&memdesc->shmem_page_list)) { 1130: int ret = kgsl_shmem_alloc_pages(memdesc); 1131: 1132: if (ret <= 0) 1133: return; 1134: } 1135: 1136: *folio = list_first_entry(&memdesc->shmem_page_list, struct folio, lru); 1137: list_del(&(*folio)->lru); 1138: } 1139: #endif 1140: 1141: void kgsl_register_shmem_callback(void) 1142: { 1143: register_trace_android_rvh_shmem_get_folio(kgsl_shmem_fill_page, NULL); 1144: } 1145: 1146: static int kgsl_alloc_secure(int *page_size, struct page **pages, 1147: u32 *align, struct device *dev) 1148: { 1149: int order = get_order(*page_size); 1150: gfp_t gfp_mask = kgsl_gfp_mask(order); 1151: struct page *page = NULL; 1152: int j, pcount = 0; 1153: size_t size = 0; 1154: 1155: page = alloc_pages(gfp_mask, order); 1156: if (!page) { 1157: /* Retry with lower order pages */ 1158: if (order > 0) { 1159: size = PAGE_SIZE << --order; 1160: goto eagain; MATCH LINES: 1185, 1190, 1198, 1199, 1201, 1207, 1208, 1211, 1219, 1225, 1226, 1229, 1232, 1234, 1235, 1236, 1240, 1241, 1242, 1247, 1249, 1255, 1257, 1260, 1261, 1264, 1268, 1272, 1275, 1276, 1277, 1281, 1282, 1284, 1286, 1289, 1292, 1293, 1299, 1307, 1310, 1315, 1319, 1324, 1326, 1328, 1329, 1331 1173: 1174: eagain: 1175: *page_size = kgsl_get_page_size(size, ilog2(size)); 1176: *align = ilog2(*page_size); 1177: return -EAGAIN; 1178: } 1179: 1180: static void kgsl_free_secure(struct page *p) 1181: { 1182: __free_pages(p, compound_order(p)); 1183: } 1184: 1185: static int kgsl_alloc_page(struct kgsl_memdesc *memdesc, int *page_size, 1186: struct page **pages, unsigned int pages_len, 1187: unsigned int *align, unsigned int page_off) 1188: { 1189: struct page *page; 1190: u32 pcount = (memdesc->size >> PAGE_SHIFT) - memdesc->page_count; 1191: 1192: if (pages == NULL) 1193: return -EINVAL; 1194: 1195: if (fatal_signal_pending(current)) 1196: return -EINTR; 1197: 1198: if (!memdesc->shmem_filp) 1199: return kgsl_alloc_secure(page_size, pages, align, memdesc->dev); 1200: 1201: page = shmem_read_mapping_page_gfp(memdesc->shmem_filp->f_mapping, page_off, 1202: kgsl_gfp_mask(0)); 1203: if (IS_ERR(page)) 1204: return PTR_ERR(page); 1205: 1206: /* Clear only shmem driver allocated pages */ 1207: if ((memdesc->size == PAGE_SIZE) || 1208: (list_empty(&memdesc->shmem_page_list) && (pcount > 1))) 1209: clear_highpage(page); 1210: 1211: kgsl_page_sync(memdesc->dev, page, PAGE_SIZE, DMA_TO_DEVICE); 1212: 1213: *page_size = PAGE_SIZE; 1214: *pages = page; 1215: 1216: return 1; 1217: } 1218: 1219: static int kgsl_memdesc_file_setup(struct kgsl_memdesc *memdesc) 1220: { 1221: int ret; 1222: 1223: /* 1224: * SHMEM pages are allocated in 4K chunks, which introduces higher 1225: * allocation latency. Since secure memory is non-reclaimable, 1226: * allocating it via SHMEM is inefficient. Use system memory directly 1227: * to reduce allocation latency for secure buffers. 1228: */ 1229: if (kgsl_memdesc_is_secured(memdesc)) 1230: return 0; 1231: 1232: memdesc->shmem_filp = shmem_file_setup("kgsl-3d0", memdesc->size, 1233: VM_NORESERVE); 1234: if (IS_ERR(memdesc->shmem_filp)) { 1235: ret = PTR_ERR(memdesc->shmem_filp); 1236: memdesc->shmem_filp = NULL; 1237: return ret; 1238: } 1239: 1240: INIT_LIST_HEAD(&memdesc->shmem_page_list); 1241: SHMEM_I(memdesc->shmem_filp->f_mapping->host)->android_vendor_data1 = (u64)memdesc; 1242: mapping_set_unevictable(memdesc->shmem_filp->f_mapping); 1243: 1244: return 0; 1245: } 1246: 1247: static void kgsl_free_page(struct kgsl_memdesc *memdesc, struct page *p) 1248: { 1249: if (!memdesc->shmem_filp) 1250: return kgsl_free_secure(p); 1251: 1252: put_page(p); 1253: } 1254: 1255: static void kgsl_memdesc_pagelist_cleanup(struct kgsl_memdesc *memdesc) 1256: { 1257: if (!memdesc->shmem_filp) 1258: return; 1259: 1260: while (!list_empty(&memdesc->shmem_page_list)) { 1261: struct page *page = list_first_entry(&memdesc->shmem_page_list, struct page, lru); 1262: 1263: list_del(&page->lru); 1264: kgsl_free_page(memdesc, page); 1265: } 1266: } 1267: 1268: static void _kgsl_free_pages(struct kgsl_memdesc *memdesc) 1269: { 1270: u32 i, n = 1; 1271: 1272: for (i = 0; i < memdesc->page_count; i += n) { 1273: n = 1; 1274: 1275: if (memdesc->pages[i]) { 1276: n = 1 << compound_order(memdesc->pages[i]); 1277: put_page(memdesc->pages[i]); 1278: } 1279: } 1280: 1281: memdesc->page_count = 0; 1282: kvfree(memdesc->pages); 1283: 1284: memdesc->pages = NULL; 1285: 1286: if (!memdesc->shmem_filp) 1287: return; 1288: 1289: WARN(!list_empty(&memdesc->shmem_page_list), 1290: "KGSL shmem page list is not empty\n"); 1291: 1292: SHMEM_I(memdesc->shmem_filp->f_mapping->host)->android_vendor_data1 = 0; 1293: fput(memdesc->shmem_filp); 1294: } 1295: 1296: #else 1297: void kgsl_register_shmem_callback(void) { } 1298: 1299: static int kgsl_alloc_page(struct kgsl_memdesc *memdesc, int *page_size, 1300: struct page **pages, unsigned int pages_len, 1301: unsigned int *align, unsigned int page_off) 1302: { 1303: if (fatal_signal_pending(current)) 1304: return -EINTR; 1305: 1306: return kgsl_pool_alloc_page(page_size, pages, 1307: pages_len, align, memdesc->dev); 1308: } 1309: 1310: static int kgsl_memdesc_file_setup(struct kgsl_memdesc *memdesc) 1311: { 1312: return 0; 1313: } 1314: 1315: static void kgsl_memdesc_pagelist_cleanup(struct kgsl_memdesc *memdesc) 1316: { 1317: } 1318: 1319: static void kgsl_free_page(struct kgsl_memdesc *memdesc, struct page *p) 1320: { 1321: kgsl_pool_free_page(p); 1322: } 1323: 1324: static void _kgsl_free_pages(struct kgsl_memdesc *memdesc) 1325: { 1326: kgsl_pool_free_pages(memdesc->pages, memdesc->page_count); 1327: 1328: memdesc->page_count = 0; 1329: kvfree(memdesc->pages); 1330: 1331: memdesc->pages = NULL; 1332: } 1333: 1334: #endif 1335: 1336: void kgsl_page_sync(struct device *dev, struct page *page, 1337: size_t size, enum dma_data_direction dir) 1338: { 1339: struct scatterlist sg; 1340: 1341: /* The caller may choose not to specify a device on purpose */ 1342: if (!dev) 1343: return; 1344: 1345: sg_init_table(&sg, 1); 1346: sg_set_page(&sg, page, size, 0); 1347: sg_dma_address(&sg) = page_to_phys(page); 1348: 1349: /* 1350: * APIs for Cache Maintenance Operations are updated in kernel 1351: * version 6.1. Prior to 6.1, dma_sync_sg_for_device() with 1352: * DMA_BIDIRECTIONAL as direction triggers cache invalidate and 1353: * clean whereas in kernel version 6.1, it triggers only cache 1354: * clean. Hence use dma_sync_sg_for_cpu() for cache invalidate 1355: * for kernel version 6.1 and above. MATCH LINES: 1390, 1396, 1400, 1403, 1409, 1421, 1439, 1444, 1446, 1448, 1449, 1456, 1466, 1470, 1472, 1473, 1475, 1478, 1480, 1484, 1488, 1489, 1491, 1494, 1496, 1497, 1499, 1500, 1501, 1504, 1506, 1509, 1517, 1518, 1521, 1523, 1524, 1527, 1531, 1535, 1540, 1543, 1558, 1565, 1566, 1569, 1575, 1578, 1587, 1588, 1592, 1594, 1600, 1601, 1603, 1606, 1610, 1613, 1621, 1622, 1626, 1628, 1630, 1631, 1633 1378: } 1379: 1380: gfp_t kgsl_gfp_mask(int page_order) 1381: { 1382: gfp_t gfp_mask = __GFP_HIGHMEM; 1383: 1384: if (page_order > 0) { 1385: gfp_mask |= __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN; 1386: gfp_mask &= ~__GFP_RECLAIM; 1387: } else 1388: gfp_mask |= GFP_KERNEL; 1389: 1390: if (kgsl_sharedmem_noretry_flag) 1391: gfp_mask |= __GFP_NORETRY | __GFP_NOWARN; 1392: 1393: return gfp_mask; 1394: } 1395: 1396: static int _kgsl_alloc_pages(struct kgsl_memdesc *memdesc, 1397: struct page ***pages) 1398: { 1399: int count = 0; 1400: int npages = memdesc->size >> PAGE_SHIFT; 1401: struct page **local = kvcalloc(npages, sizeof(*local), GFP_KERNEL); 1402: u32 page_size, align; 1403: u64 len = memdesc->size; 1404: bool memwq_flush_done = false; 1405: 1406: if (!local) 1407: return -ENOMEM; 1408: 1409: count = kgsl_memdesc_file_setup(memdesc); 1410: if (count) { 1411: kvfree(local); 1412: return count; 1413: } 1414: 1415: /* Start with 1MB alignment to get the biggest page we can */ 1416: align = ilog2(SZ_1M); 1417: 1418: page_size = kgsl_get_page_size(len, align); 1419: 1420: while (len) { 1421: int ret = kgsl_alloc_page(memdesc, &page_size, &local[count], 1422: npages, &align, count); 1423: 1424: if (ret == -EAGAIN) 1425: continue; 1426: else if (ret <= 0) { 1427: int i; 1428: 1429: /* if OOM, retry once after flushing lockless_workqueue */ 1430: if (ret == -ENOMEM && !memwq_flush_done) { 1431: flush_workqueue(kgsl_driver.lockless_workqueue); 1432: memwq_flush_done = true; 1433: continue; 1434: } 1435: 1436: for (i = 0; i < count; ) { 1437: int n = 1 << compound_order(local[i]); 1438: 1439: kgsl_free_page(memdesc, local[i]); 1440: i += n; 1441: } 1442: kvfree(local); 1443: 1444: if (!kgsl_sharedmem_noretry_flag) 1445: pr_err_ratelimited("kgsl: out of memory: only allocated %lldKb of %lldKb requested\n", 1446: (memdesc->size - len) >> 10, memdesc->size >> 10); 1447: 1448: if (memdesc->shmem_filp) 1449: fput(memdesc->shmem_filp); 1450: 1451: count = -ENOMEM; 1452: goto done; 1453: } 1454: 1455: count += ret; 1456: memdesc->page_count += ret; 1457: npages -= ret; 1458: len -= page_size; 1459: 1460: page_size = kgsl_get_page_size(len, align); 1461: } 1462: 1463: *pages = local; 1464: 1465: done: 1466: kgsl_memdesc_pagelist_cleanup(memdesc); 1467: return count; 1468: } 1469: 1470: static void kgsl_free_pages(struct kgsl_memdesc *memdesc) 1471: { 1472: kgsl_paged_unmap_kernel(memdesc); 1473: WARN_ON(memdesc->hostptr); 1474: 1475: if (TEST_FLAG(KGSL_MEMDESC_MAPPED, &memdesc->priv)) 1476: return; 1477: 1478: atomic_long_sub(memdesc->size, &kgsl_driver.stats.page_alloc); 1479: 1480: _kgsl_free_pages(memdesc); 1481: 1482: } 1483: 1484: static void kgsl_free_system_pages(struct kgsl_memdesc *memdesc) 1485: { 1486: int i; 1487: 1488: kgsl_paged_unmap_kernel(memdesc); 1489: WARN_ON(memdesc->hostptr); 1490: 1491: if (TEST_FLAG(KGSL_MEMDESC_MAPPED, &memdesc->priv)) 1492: return; 1493: 1494: atomic_long_sub(memdesc->size, &kgsl_driver.stats.page_alloc); 1495: 1496: for (i = 0; i < memdesc->page_count; i++) 1497: __free_pages(memdesc->pages[i], get_order(PAGE_SIZE)); 1498: 1499: memdesc->page_count = 0; 1500: kvfree(memdesc->pages); 1501: memdesc->pages = NULL; 1502: } 1503: 1504: void kgsl_unmap_and_put_gpuaddr(struct kgsl_memdesc *memdesc) 1505: { 1506: if (!memdesc->size || !memdesc->gpuaddr) 1507: return; 1508: 1509: if (WARN_ON(kgsl_memdesc_is_global(memdesc))) 1510: return; 1511: 1512: /* 1513: * Don't release the GPU address if the memory fails to unmap because 1514: * the IOMMU driver will BUG later if we reallocated the address and 1515: * tried to map it 1516: */ 1517: if (!kgsl_memdesc_is_reclaimed(memdesc) && 1518: kgsl_mmu_unmap(memdesc->pagetable, memdesc)) 1519: return; 1520: 1521: kgsl_mmu_put_gpuaddr(memdesc->pagetable, memdesc); 1522: 1523: memdesc->gpuaddr = 0; 1524: memdesc->pagetable = NULL; 1525: } 1526: 1527: static const struct kgsl_memdesc_ops kgsl_contiguous_ops = { 1528: .free = kgsl_contiguous_free, 1529: .vmflags = VM_DONTDUMP | VM_PFNMAP | VM_DONTEXPAND | VM_DONTCOPY, 1530: .vmfault = kgsl_contiguous_vmfault, 1531: .put_gpuaddr = kgsl_unmap_and_put_gpuaddr, 1532: }; 1533: 1534: #if IS_ENABLED(CONFIG_QCOM_SECURE_BUFFER) 1535: static void kgsl_free_pages_from_sgt(struct kgsl_memdesc *memdesc) 1536: { 1537: int i; 1538: struct scatterlist *sg; 1539: 1540: if (WARN_ON(!memdesc->sgt)) 1541: return; 1542: 1543: for_each_sg(memdesc->sgt->sgl, sg, memdesc->sgt->nents, i) { 1544: /* 1545: * sg_alloc_table_from_pages() will collapse any physically 1546: * adjacent pages into a single scatterlist entry. We cannot 1547: * just call __free_pages() on the entire set since we cannot 1548: * ensure that the size is a whole order. Instead, free each 1549: * page or compound page group individually. 1550: */ 1551: struct page *p = sg_page(sg), *next; 1552: unsigned int count; 1553: unsigned int j = 0; 1554: 1555: while (j < (sg->length/PAGE_SIZE)) { 1556: count = 1 << compound_order(p); 1557: next = kgsl_nth_page(p, count); 1558: kgsl_free_page(memdesc, p); 1559: 1560: p = next; 1561: j += count; 1562: } 1563: } 1564: 1565: if (memdesc->shmem_filp) 1566: fput(memdesc->shmem_filp); 1567: } 1568: 1569: static void kgsl_free_secure_system_pages(struct kgsl_memdesc *memdesc) 1570: { 1571: int i; 1572: struct scatterlist *sg; 1573: int ret; 1574: 1575: if (TEST_FLAG(KGSL_MEMDESC_MAPPED, &memdesc->priv)) 1576: return; 1577: 1578: ret = kgsl_unlock_sgt(memdesc->sgt); 1579: 1580: if (ret) { 1581: /* 1582: * Unlock of the secure buffer failed. This buffer will 1583: * be stuck in secure side forever and is unrecoverable. 1584: * Give up on the buffer and don't return it to the 1585: * pool. 1586: */ 1587: pr_err("kgsl: secure buf unlock failed: gpuaddr: %llx size: %llx ret: %d\n", 1588: memdesc->gpuaddr, memdesc->size, ret); 1589: return; 1590: } 1591: 1592: atomic_long_sub(memdesc->size, &kgsl_driver.stats.secure); 1593: 1594: for_each_sg(memdesc->sgt->sgl, sg, memdesc->sgt->nents, i) { 1595: struct page *page = sg_page(sg); 1596: 1597: __free_pages(page, get_order(PAGE_SIZE)); 1598: } 1599: 1600: sg_free_table(memdesc->sgt); 1601: kfree(memdesc->sgt); 1602: 1603: memdesc->sgt = NULL; 1604: } 1605: 1606: static void kgsl_free_secure_pages(struct kgsl_memdesc *memdesc) 1607: { 1608: int ret; 1609: 1610: if (TEST_FLAG(KGSL_MEMDESC_MAPPED, &memdesc->priv)) 1611: return; 1612: 1613: ret = kgsl_unlock_sgt(memdesc->sgt); 1614: if (ret) { 1615: /* 1616: * Unlock of the secure buffer failed. This buffer will 1617: * be stuck in secure side forever and is unrecoverable. 1618: * Give up on the buffer and don't return it to the 1619: * pool. 1620: */ 1621: pr_err("kgsl: secure buf unlock failed: gpuaddr: %llx size: %llx ret: %d\n", 1622: memdesc->gpuaddr, memdesc->size, ret); 1623: return; 1624: } 1625: 1626: atomic_long_sub(memdesc->size, &kgsl_driver.stats.secure); 1627: 1628: kgsl_free_pages_from_sgt(memdesc); 1629: 1630: sg_free_table(memdesc->sgt); 1631: kfree(memdesc->sgt); 1632: 1633: memdesc->sgt = NULL; 1634: } 1635: 1636: void kgsl_free_secure_page(struct page *page) 1637: { 1638: struct sg_table sgt; 1639: struct scatterlist sgl; 1640: int ret; 1641: 1642: if (!page) 1643: return; 1644: 1645: sgt.sgl = &sgl; 1646: sgt.nents = 1; 1647: sgt.orig_nents = 1; 1648: sg_init_table(&sgl, 1); 1649: sg_set_page(&sgl, page, PAGE_SIZE, 0); 1650: 1651: ret = kgsl_unlock_sgt(&sgt); 1652: if (ret) 1653: /* 1654: * Unlock of the secure page failed. This page will be 1655: * stuck in secure side forever and is unrecoverable. 1656: * Give up on this page and don't free it. 1657: */ MATCH LINES: 1692, 1697, 1700, 1713, 1719, 1722, 1730, 1733, 1755, 1759, 1765, 1777, 1778, 1779, 1781, 1782, 1783, 1785, 1786, 1794, 1795, 1802, 1803, 1810, 1815, 1818, 1829, 1831, 1835, 1842, 1852, 1853, 1854, 1856, 1857, 1858, 1860, 1861, 1867, 1876, 1887, 1888, 1889, 1890, 1891, 1892, 1894, 1902, 1911, 1912, 1914, 1915, 1924, 1928, 1931, 1933, 1937, 1941, 1945, 1946, 1948, 1956, 1958, 1980, 1981, 1982, 1984, 1987, 1990, 1996, 1997, 2003, 2011, 2013, 2016, 2017, 2020, 2033, 2036, 2038, 2045, 2046, 2056, 2057, 2059, 2062, 2071, 2075, 2077, 2078, 2080, 2083, 2091, 2094 1680: 1681: status = kgsl_lock_sgt(&sgt, PAGE_SIZE); 1682: if (status) { 1683: if (status == -EADDRNOTAVAIL) 1684: return NULL; 1685: 1686: __free_page(page); 1687: return NULL; 1688: } 1689: return page; 1690: } 1691: 1692: static const struct kgsl_memdesc_ops kgsl_secure_system_ops = { 1693: .free = kgsl_free_secure_system_pages, 1694: /* FIXME: Make sure vmflags / vmfault does the right thing here */ 1695: }; 1696: 1697: static const struct kgsl_memdesc_ops kgsl_secure_page_ops = { 1698: .free = kgsl_free_secure_pages, 1699: /* FIXME: Make sure vmflags / vmfault does the right thing here */ 1700: .put_gpuaddr = kgsl_unmap_and_put_gpuaddr, 1701: }; 1702: #else 1703: void kgsl_free_secure_page(struct page *page) 1704: { 1705: } 1706: 1707: struct page *kgsl_alloc_secure_page(void) 1708: { 1709: return NULL; 1710: } 1711: #endif 1712: 1713: static const struct kgsl_memdesc_ops kgsl_page_ops = { 1714: .free = kgsl_free_pages, 1715: .vmflags = VM_DONTDUMP | VM_DONTEXPAND | VM_DONTCOPY | VM_MIXEDMAP, 1716: .vmfault = kgsl_paged_vmfault, 1717: .map_kernel = kgsl_paged_map_kernel, 1718: .unmap_kernel = kgsl_paged_unmap_kernel, 1719: .put_gpuaddr = kgsl_unmap_and_put_gpuaddr, 1720: }; 1721: 1722: static const struct kgsl_memdesc_ops kgsl_system_ops = { 1723: .free = kgsl_free_system_pages, 1724: .vmflags = VM_DONTDUMP | VM_DONTEXPAND | VM_DONTCOPY | VM_MIXEDMAP, 1725: .vmfault = kgsl_paged_vmfault, 1726: .map_kernel = kgsl_paged_map_kernel, 1727: .unmap_kernel = kgsl_paged_unmap_kernel, 1728: }; 1729: 1730: static int kgsl_system_alloc_pages(struct kgsl_memdesc *memdesc, struct page ***pages) 1731: { 1732: struct page **local; 1733: int i, npages = memdesc->size >> PAGE_SHIFT; 1734: 1735: local = kvcalloc(npages, sizeof(*pages), GFP_KERNEL); 1736: if (!local) 1737: return -ENOMEM; 1738: 1739: for (i = 0; i < npages; i++) { 1740: gfp_t gfp = __GFP_ZERO | __GFP_HIGHMEM | GFP_KERNEL; 1741: 1742: if (!fatal_signal_pending(current)) 1743: local[i] = alloc_pages(gfp, get_order(PAGE_SIZE)); 1744: else 1745: local[i] = NULL; 1746: 1747: if (!local[i]) { 1748: for (i = i - 1; i >= 0; i--) 1749: __free_pages(local[i], get_order(PAGE_SIZE)); 1750: kvfree(local); 1751: return -ENOMEM; 1752: } 1753: 1754: /* Make sure the cache is clean */ 1755: kgsl_page_sync(memdesc->dev, local[i], PAGE_SIZE, DMA_TO_DEVICE); 1756: } 1757: 1758: *pages = local; 1759: memdesc->page_count = npages; 1760: return npages; 1761: } 1762: 1763: #if IS_ENABLED(CONFIG_QCOM_SECURE_BUFFER) 1764: static int kgsl_alloc_secure_pages(struct kgsl_device *device, 1765: struct kgsl_memdesc *memdesc, u64 size, u64 flags, u32 priv) 1766: { 1767: struct page **pages; 1768: int count; 1769: struct sg_table *sgt; 1770: int ret; 1771: 1772: size = PAGE_ALIGN(size); 1773: 1774: if (!size || size > UINT_MAX) 1775: return -EINVAL; 1776: 1777: kgsl_memdesc_init(device, memdesc, flags); 1778: atomic_or(priv, &memdesc->priv); 1779: memdesc->size = size; 1780: 1781: if (priv & KGSL_MEMDESC_SYSMEM) { 1782: memdesc->ops = &kgsl_secure_system_ops; 1783: count = kgsl_system_alloc_pages(memdesc, &pages); 1784: } else { 1785: memdesc->ops = &kgsl_secure_page_ops; 1786: count = _kgsl_alloc_pages(memdesc, &pages); 1787: } 1788: 1789: if (count < 0) 1790: return count; 1791: 1792: sgt = kzalloc(sizeof(*sgt), GFP_KERNEL); 1793: if (!sgt) { 1794: memdesc->pages = pages; 1795: _kgsl_free_pages(memdesc); 1796: return -ENOMEM; 1797: } 1798: 1799: ret = sg_alloc_table_from_pages(sgt, pages, count, 0, size, GFP_KERNEL); 1800: if (ret) { 1801: kfree(sgt); 1802: memdesc->pages = pages; 1803: _kgsl_free_pages(memdesc); 1804: return ret; 1805: } 1806: 1807: /* Now that we've moved to a sg table don't need the pages anymore */ 1808: kvfree(pages); 1809: 1810: memdesc->sgt = sgt; 1811: 1812: ret = kgsl_lock_sgt(sgt, size); 1813: if (ret) { 1814: if (ret != -EADDRNOTAVAIL) 1815: kgsl_free_pages_from_sgt(memdesc); 1816: sg_free_table(sgt); 1817: kfree(sgt); 1818: memdesc->sgt = NULL; 1819: return ret; 1820: } 1821: 1822: KGSL_STATS_ADD(size, &kgsl_driver.stats.secure, 1823: &kgsl_driver.stats.secure_max); 1824: 1825: return 0; 1826: } 1827: 1828: static int kgsl_allocate_secure(struct kgsl_device *device, 1829: struct kgsl_memdesc *memdesc, u64 size, u64 flags, u32 priv) 1830: { 1831: return kgsl_alloc_secure_pages(device, memdesc, size, flags, priv); 1832: } 1833: #else 1834: static int kgsl_allocate_secure(struct kgsl_device *device, 1835: struct kgsl_memdesc *memdesc, u64 size, u64 flags, u32 priv) 1836: { 1837: return -ENODEV; 1838: } 1839: #endif 1840: 1841: static int kgsl_alloc_pages(struct kgsl_device *device, 1842: struct kgsl_memdesc *memdesc, u64 size, u64 flags, u32 priv) 1843: { 1844: struct page **pages; 1845: int count; 1846: 1847: size = PAGE_ALIGN(size); 1848: 1849: if (!size || size > UINT_MAX) 1850: return -EINVAL; 1851: 1852: kgsl_memdesc_init(device, memdesc, flags); 1853: atomic_or(priv, &memdesc->priv); 1854: memdesc->size = size; 1855: 1856: if (priv & KGSL_MEMDESC_SYSMEM) { 1857: memdesc->ops = &kgsl_system_ops; 1858: count = kgsl_system_alloc_pages(memdesc, &pages); 1859: } else { 1860: memdesc->ops = &kgsl_page_ops; 1861: count = _kgsl_alloc_pages(memdesc, &pages); 1862: } 1863: 1864: if (count < 0) 1865: return count; 1866: 1867: memdesc->pages = pages; 1868: 1869: KGSL_STATS_ADD(size, &kgsl_driver.stats.page_alloc, 1870: &kgsl_driver.stats.page_alloc_max); 1871: 1872: return 0; 1873: } 1874: 1875: static int _kgsl_alloc_contiguous(struct device *dev, 1876: struct kgsl_memdesc *memdesc, u64 size, unsigned long attrs) 1877: { 1878: int ret; 1879: phys_addr_t phys; 1880: void *ptr; 1881: 1882: ptr = dma_alloc_attrs(dev, (size_t) size, &phys, 1883: GFP_KERNEL, attrs); 1884: if (!ptr) 1885: return -ENOMEM; 1886: 1887: memdesc->size = size; 1888: memdesc->dev = dev; 1889: memdesc->hostptr = ptr; 1890: memdesc->physaddr = phys; 1891: memdesc->gpuaddr = phys; 1892: memdesc->attrs = attrs; 1893: 1894: ret = kgsl_memdesc_sg_dma(memdesc, phys, size); 1895: if (ret) 1896: dma_free_attrs(dev, (size_t) size, ptr, phys, attrs); 1897: 1898: return ret; 1899: } 1900: 1901: static int kgsl_alloc_contiguous(struct kgsl_device *device, 1902: struct kgsl_memdesc *memdesc, u64 size, u64 flags, u32 priv) 1903: { 1904: int ret; 1905: 1906: size = PAGE_ALIGN(size); 1907: 1908: if (!size || size > UINT_MAX) 1909: return -EINVAL; 1910: 1911: kgsl_memdesc_init(device, memdesc, flags); 1912: atomic_or(priv, &memdesc->priv); 1913: 1914: memdesc->ops = &kgsl_contiguous_ops; 1915: ret = _kgsl_alloc_contiguous(&device->pdev->dev, memdesc, size, 0); 1916: 1917: if (!ret) 1918: KGSL_STATS_ADD(size, &kgsl_driver.stats.coherent, 1919: &kgsl_driver.stats.coherent_max); 1920: 1921: return ret; 1922: } 1923: 1924: int kgsl_allocate_user(struct kgsl_device *device, struct kgsl_memdesc *memdesc, 1925: u64 size, u64 flags, u32 priv) 1926: { 1927: if (device->mmu.type == KGSL_MMU_TYPE_NONE) 1928: return kgsl_alloc_contiguous(device, memdesc, size, flags, 1929: priv); 1930: else if (flags & KGSL_MEMFLAGS_SECURE) 1931: return kgsl_allocate_secure(device, memdesc, size, flags, priv); 1932: 1933: return kgsl_alloc_pages(device, memdesc, size, flags, priv); 1934: } 1935: 1936: int kgsl_allocate_kernel(struct kgsl_device *device, 1937: struct kgsl_memdesc *memdesc, u64 size, u64 flags, u32 priv) 1938: { 1939: int ret; 1940: 1941: ret = kgsl_allocate_user(device, memdesc, size, flags, priv); 1942: if (ret) 1943: return ret; 1944: 1945: if (memdesc->ops->map_kernel) { 1946: ret = memdesc->ops->map_kernel(memdesc); 1947: if (ret) { 1948: kgsl_sharedmem_free(memdesc); 1949: return ret; 1950: } 1951: } 1952: 1953: return 0; 1954: } 1955: 1956: int kgsl_memdesc_init_fixed(struct kgsl_device *device, 1957: struct platform_device *pdev, const char *resource, 1958: struct kgsl_memdesc *memdesc) 1959: { 1960: const __be32 *prop; 1961: phys_addr_t physaddr; 1962: u64 size; 1963: int len; 1964: int addr_cells = of_n_addr_cells(pdev->dev.of_node); 1965: int size_cells = of_n_size_cells(pdev->dev.of_node); 1966: 1967: prop = of_get_property(pdev->dev.of_node, resource, &len); 1968: if (!prop) 1969: return -ENODEV; 1970: 1971: if (len != ((addr_cells + size_cells) * sizeof(__be32))) { 1972: dev_err_ratelimited(device->dev, "of property %s has len %d expected %lu\n", 1973: resource, len, (addr_cells + size_cells) * sizeof(__be32)); 1974: return -E2BIG; 1975: } 1976: 1977: physaddr = of_read_number(prop, addr_cells); 1978: size = of_read_number(prop + addr_cells, size_cells); 1979: 1980: kgsl_memdesc_init(device, memdesc, 0); 1981: memdesc->physaddr = physaddr; 1982: memdesc->size = size; 1983: 1984: return kgsl_memdesc_sg_dma(memdesc, physaddr, size); 1985: } 1986: 1987: struct kgsl_memdesc *kgsl_allocate_global_fixed(struct kgsl_device *device, 1988: const char *resource, const char *name) 1989: { 1990: struct kgsl_global_memdesc *gmd = kzalloc(sizeof(*gmd), GFP_KERNEL); 1991: int ret; 1992: 1993: if (!gmd) 1994: return ERR_PTR(-ENOMEM); 1995: 1996: ret = kgsl_memdesc_init_fixed(device, device->pdev, resource, 1997: &gmd->memdesc); 1998: if (ret) { 1999: kfree(gmd); 2000: return ERR_PTR(ret); 2001: } 2002: 2003: atomic_set(&gmd->memdesc.priv, KGSL_MEMDESC_GLOBAL); 2004: gmd->name = name; 2005: 2006: /* 2007: * No lock here, because this function is only called during probe/init 2008: * while the caller is holding the mutex 2009: */ 2010: list_add_tail(&gmd->node, &device->globals); 2011: kgsl_mmu_map_global(device, &gmd->memdesc, 0); 2012: 2013: return &gmd->memdesc; 2014: } 2015: 2016: struct kgsl_memdesc *kgsl_alloc_map_gpu_global(struct kgsl_device *device, 2017: u64 gpuaddr, u64 size, u32 padding, u64 flags, u32 priv, const char *name) 2018: { 2019: int ret; 2020: struct kgsl_global_memdesc *md; 2021: 2022: if (WARN_ON(!kgsl_mutex_is_locked(&device->mutex))) 2023: return ERR_PTR(-EINVAL); 2024: 2025: md = kzalloc(sizeof(*md), GFP_KERNEL); 2026: if (!md) 2027: return ERR_PTR(-ENOMEM); 2028: 2029: /* 2030: * Make sure that we get global memory from system memory to keep from 2031: * taking up pool memory for the life of the driver 2032: */ 2033: priv |= KGSL_MEMDESC_GLOBAL | KGSL_MEMDESC_SYSMEM; 2034: 2035: if (flags & KGSL_MEMFLAGS_SECURE) 2036: ret = kgsl_allocate_secure(device, &md->memdesc, size, flags, priv); 2037: else 2038: ret = kgsl_allocate_kernel(device, &md->memdesc, size, flags, priv); 2039: 2040: if (ret) { 2041: kfree(md); 2042: return ERR_PTR(ret); 2043: } 2044: 2045: if (gpuaddr) 2046: md->memdesc.gpuaddr = gpuaddr; 2047: 2048: md->name = name; 2049: 2050: /* 2051: * No lock here, because this function is only called during probe/init 2052: * while the caller is holding the mute 2053: */ 2054: list_add_tail(&md->node, &device->globals); 2055: 2056: kgsl_mmu_map_global(device, &md->memdesc, padding); 2057: kgsl_trace_gpu_mem_total(device, md->memdesc.size); 2058: 2059: return &md->memdesc; 2060: } 2061: 2062: int kgsl_get_global_gpuaddr(struct kgsl_device *device, struct kgsl_memdesc *memdesc, 2063: u64 size, u64 flags, u32 priv) 2064: { 2065: if (WARN_ON(!kgsl_mutex_is_locked(&device->mutex))) 2066: return -EINVAL; 2067: 2068: if (!size || size > UINT_MAX) 2069: return -EINVAL; 2070: 2071: priv |= KGSL_MEMDESC_GLOBAL; 2072: 2073: size = PAGE_ALIGN(size); 2074: 2075: kgsl_memdesc_init(device, memdesc, flags); 2076: 2077: atomic_or(priv, &memdesc->priv); 2078: memdesc->size = size; 2079: 2080: return kgsl_mmu_reserve_global_gpuaddr(device, memdesc); 2081: } 2082: 2083: struct kgsl_memdesc *kgsl_allocate_global(struct kgsl_device *device, 2084: u64 size, u32 padding, u64 flags, u32 priv, const char *name) 2085: { 2086: return kgsl_alloc_map_gpu_global(device, 0, size, padding, flags, priv, name); 2087: } 2088: 2089: void kgsl_free_globals(struct kgsl_device *device) 2090: { 2091: struct kgsl_global_memdesc *md, *tmp; 2092: 2093: list_for_each_entry_safe(md, tmp, &device->globals, node) { 2094: kgsl_sharedmem_free(&md->memdesc); 2095: list_del(&md->node); 2096: kfree(md); 2097: } 2098: } --- FILE: \kgsl_sharedmem.h | HITS: 191 --- MATCH LINES: 6, 7, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 49, 51, 53, 55, 56, 57, 59, 62, 66, 70, 75, 82, 86, 91, 98, 102, 118, 124, 132, 150, 152, 153, 154, 161, 167, 169, 174, 175, 176, 179, 181, 185, 190, 191, 192, 195, 197, 201, 205, 206, 211, 248, 250, 255, 258, 262, 264, 269, 274, 277, 279, 289, 293, 295, 306, 307, 310, 324, 328, 342, 345, 350, 356, 358, 380, 381, 386, 388, 392, 393, 398, 400, 404, 406, 409, 410, 414, 419, 420, 425, 426, 433, 435, 439, 440, 448, 452, 453, 457, 459, 463, 464, 468, 470, 474, 475, 477, 479, 481, 485, 486, 488, 491, 493, 497, 498, 500, 506, 508, 509, 511, 515, 516, 518, 519, 521, 523, 524, 530, 542, 543, 545, 553, 556, 557, 560, 562, 563, 565, 568, 570, 571, 574, 578, 579, 580, 582, 586, 587, 588, 591, 593, 614, 622, 624, 626, 634, 636, 644, 645, 648, 654, 658, 668, 672, 673, 678, 683, 686, 687, 691, 694, 697, 699, 702, 710 1: /* SPDX-License-Identifier: GPL-2.0-only */ 2: /* 3: * Copyright (c) 2002,2007-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: #ifndef __KGSL_SHAREDMEM_H 7: #define __KGSL_SHAREDMEM_H 8: 9: #include 10: #include 11: #include 12: #include 13: #include 14: 15: struct kgsl_device; 16: struct kgsl_process_private; 17: 18: /* Internal definitions for memdesc->priv */ 19: #define KGSL_MEMDESC_GUARD_PAGE BIT(0) 20: /* Set if the memdesc is mapped into all pagetables */ 21: #define KGSL_MEMDESC_GLOBAL BIT(1) 22: /* The memdesc is frozen during a snapshot */ 23: #define KGSL_MEMDESC_FROZEN BIT(2) 24: /* The memdesc is mapped into a pagetable */ 25: #define KGSL_MEMDESC_MAPPED BIT(3) 26: /* The memdesc is secured for content protection */ 27: #define KGSL_MEMDESC_SECURE BIT(4) 28: /* Memory is accessible in privileged mode */ 29: #define KGSL_MEMDESC_PRIVILEGED BIT(6) 30: /* This is an instruction buffer */ 31: #define KGSL_MEMDESC_UCODE BIT(7) 32: /* For global buffers, randomly assign an address from the region */ 33: #define KGSL_MEMDESC_RANDOM BIT(8) 34: /* Allocate memory from the system instead of the pools */ 35: #define KGSL_MEMDESC_SYSMEM BIT(9) 36: /* The memdesc pages can be reclaimed */ 37: #define KGSL_MEMDESC_CAN_RECLAIM BIT(10) 38: /* The memdesc pages were reclaimed */ 39: #define KGSL_MEMDESC_RECLAIMED BIT(11) 40: /* Skip reclaim of the memdesc pages */ 41: #define KGSL_MEMDESC_SKIP_RECLAIM BIT(12) 42: /* The memdesc is hypassigned to HLOS*/ 43: #define KGSL_MEMDESC_HYPASSIGNED_HLOS BIT(13) 44: 45: #define TEST_FLAG(_bit, _val) ((atomic_read(_val) & (_bit)) != 0) 46: #define SET_FLAG(_bit, _val) atomic_or((int)(_bit), (_val)) 47: #define CLEAR_FLAG(_bit, _val) atomic_and(~(int)(_bit), (_val)) 48: 49: struct kgsl_memdesc; 50: 51: struct kgsl_memdesc_ops { 52: u32 vmflags; 53: vm_fault_t (*vmfault)(struct kgsl_memdesc *memdesc, 54: struct vm_area_struct *vma, struct vm_fault *vmf); 55: void (*free)(struct kgsl_memdesc *memdesc); 56: int (*map_kernel)(struct kgsl_memdesc *memdesc); 57: void (*unmap_kernel)(struct kgsl_memdesc *memdesc); 58: /** 59: * @put_gpuaddr: Put away the GPU address and unmap the memory 60: * descriptor 61: */ 62: void (*put_gpuaddr)(struct kgsl_memdesc *memdesc); 63: }; 64: 65: /** 66: * struct kgsl_memdesc - GPU memory object descriptor 67: * @pagetable: Pointer to the pagetable that the object is mapped in 68: * @hostptr: Kernel virtual address 69: * @hostptr_count: Number of threads using hostptr 70: * @gpuaddr: GPU virtual address 71: * @physaddr: Physical address of the memory object 72: * @size: Size of the memory object 73: * @priv: Internal flags and settings 74: * @sgt: Scatter gather table for allocated pages 75: * @ops: Function hooks for the memdesc memory type 76: * @flags: Flags set from userspace 77: * @dev: Pointer to the struct device that owns this memory 78: * @attrs: dma attributes for this memory 79: * @pages: An array of pointers to allocated pages 80: * @page_count: Total number of pages allocated 81: */ 82: struct kgsl_memdesc { 83: struct kgsl_pagetable *pagetable; 84: void *hostptr; 85: u32 hostptr_count; 86: u64 gpuaddr; 87: phys_addr_t physaddr; 88: u64 size; 89: atomic_t priv; 90: struct sg_table *sgt; 91: const struct kgsl_memdesc_ops *ops; 92: u64 flags; 93: struct device *dev; 94: unsigned long attrs; 95: struct page **pages; 96: u32 page_count; 97: /** 98: * @lock: Spinlock to protect the gpuaddr from being accessed by 99: * multiple entities trying to map the same SVM region at once 100: */ 101: spinlock_t lock; 102: /** @shmem_filp: Pointer to the shmem file backing this memdesc */ 103: struct file *shmem_filp; 104: /** @ranges: rbtree base for the interval list of vbo ranges */ 105: struct rb_root_cached ranges; 106: /** @ranges_lock: Mutex to protect the range database */ 107: struct mutex ranges_lock; 108: /** @gmuaddr: GMU VA if this is mapped in GMU */ 109: u32 gmuaddr; 110: /*@shmem_page_list: shmem pages list */ 111: struct list_head shmem_page_list; 112: }; 113: 114: /* 115: * struct kgsl_mem_entry - a userspace memory allocation 116: * @refcount: reference count. Currently userspace can only 117: * hold a single reference count, but the kernel may hold more. 118: * @memdesc: description of the memory 119: * @priv_data: type-specific data, such as the dma-buf attachment pointer. 120: * @node: rb_node for the gpu address lookup rb tree 121: * @id: idr index for this entry, can be used to find memory that does not have 122: * a valid GPU address. 123: * @priv: back pointer to the process that owns this memory 124: * @pending_free: if !0, userspace requested that his memory be freed, but there 125: * are still references to it. 126: * @dev_priv: back pointer to the device file that created this entry. 127: * @metadata: String containing user specified metadata for the entry 128: * @work: Work struct used to schedule kgsl_mem_entry_destroy() 129: */ 130: struct kgsl_mem_entry { 131: struct kref refcount; 132: struct kgsl_memdesc memdesc; 133: void *priv_data; 134: struct rb_node node; 135: u32 id; 136: struct kgsl_process_private *priv; 137: int pending_free; 138: char metadata[KGSL_GPUOBJ_ALLOC_METADATA_MAX + 1]; 139: struct work_struct work; 140: /** 141: * @map_count: Count how many vmas this object is mapped in - used for 142: * debugfs accounting 143: */ 144: atomic_t map_count; 145: /** @vbo_count: Count how many VBO ranges this entry is mapped in */ 146: atomic_t vbo_count; 147: }; 148: 149: /** 150: * struct kgsl_global_memdesc - wrapper for global memory objects 151: */ 152: struct kgsl_global_memdesc { 153: /** @memdesc: Container for the GPU memory descriptor for the object */ 154: struct kgsl_memdesc memdesc; 155: /** @name: Name of the object for the debugfs list */ 156: const char *name; 157: /** @node: List node for the list of global objects */ 158: struct list_head node; 159: }; 160: 161: extern bool kgsl_sharedmem_noretry_flag; 162: 163: #define KGSL_CACHE_OP_INV 0x01 164: #define KGSL_CACHE_OP_FLUSH 0x02 165: #define KGSL_CACHE_OP_CLEAN 0x03 166: 167: void kgsl_sharedmem_free(struct kgsl_memdesc *memdesc); 168: 169: int kgsl_sharedmem_readl(const struct kgsl_memdesc *memdesc, 170: uint32_t *dst, 171: uint64_t offsetbytes); 172: 173: /** 174: * kgsl_sharedmem_writel - write a 32 bit value to a shared memory object 175: * @memdesc: Pointer to a GPU memory object 176: * @offsetbytes: Offset inside of @memdesc to write to 177: * @src: Value to write 178: * 179: * Write @src to @offsetbytes from the start of @memdesc 180: */ 181: void kgsl_sharedmem_writel(const struct kgsl_memdesc *memdesc, 182: uint64_t offsetbytes, 183: uint32_t src); 184: 185: int kgsl_sharedmem_readq(const struct kgsl_memdesc *memdesc, 186: uint64_t *dst, 187: uint64_t offsetbytes); 188: 189: /** 190: * kgsl_sharedmem_writeq - write a 64 bit value to a shared memory object 191: * @memdesc: Pointer to a GPU memory object 192: * @offsetbytes: Offset inside of @memdesc to write to 193: * @src: Value to write 194: * 195: * Write @src to @offsetbytes from the start of @memdesc 196: */ 197: void kgsl_sharedmem_writeq(const struct kgsl_memdesc *memdesc, 198: uint64_t offsetbytes, 199: uint64_t src); 200: 201: int kgsl_cache_range_op(struct kgsl_memdesc *memdesc, 202: uint64_t offset, uint64_t size, 203: unsigned int op); 204: 205: void kgsl_memdesc_init(struct kgsl_device *device, 206: struct kgsl_memdesc *memdesc, uint64_t flags); 207: 208: void kgsl_process_init_sysfs(struct kgsl_device *device, 209: struct kgsl_process_private *private); 210: 211: int kgsl_sharedmem_init_sysfs(void); 212: 213: void kgsl_get_memory_usage(char *str, size_t len, uint64_t memflags); 214: 215: void kgsl_free_secure_page(struct page *page); 216: 217: struct page *kgsl_alloc_secure_page(void); 218: 219: #if IS_ENABLED(CONFIG_QCOM_SECURE_BUFFER) 220: int kgsl_lock_sgt(struct sg_table *sgt, u64 size); 221: 222: int kgsl_unlock_sgt(struct sg_table *sgt); 223: #endif 224: 225: /** 226: * kgsl_zero_page() - zero out a page 227: * @p: pointer to the struct page 228: * @order: order of the page 229: * @dev: A &struct device pointer 230: * 231: * Map a page into kernel and zero it out 232: */ 233: void kgsl_zero_page(struct page *p, unsigned int order, 234: struct device *dev); 235: 236: /** 237: * kgsl_gfp_mask() - get gfp_mask to be used 238: * @page_order: order of the page 239: * 240: * Get the gfp_mask to be used for page allocation 241: * based on the order of the page 242: * 243: * Return appropriate gfp_mask 244: */ 245: gfp_t kgsl_gfp_mask(int page_order); 246: 247: /** 248: * kgsl_allocate_user - Allocate user visible GPU memory 249: * @device: A GPU device handle 250: * @memdesc: Memory descriptor for the object 251: * @size: Size of the allocation in bytes 252: * @flags: Control flags for the allocation 253: * @priv: Internal flags for the allocation 254: * 255: * Allocate GPU memory on behalf of the user. 256: * Return: 0 on success or negative on failure. 257: */ 258: int kgsl_allocate_user(struct kgsl_device *device, struct kgsl_memdesc *memdesc, 259: u64 size, u64 flags, u32 priv); 260: 261: /** 262: * kgsl_allocate_kernel - Allocate kernel visible GPU memory 263: * @device: A GPU device handle 264: * @memdesc: Memory descriptor for the object 265: * @size: Size of the allocation in bytes 266: * @flags: Control flags for the allocation 267: * @priv: Internal flags for the allocation 268: * 269: * Allocate GPU memory on for use by the kernel. Kernel objects are 270: * automatically mapped into the kernel address space (except for secure). 271: * Return: 0 on success or negative on failure. 272: */ 273: int kgsl_allocate_kernel(struct kgsl_device *device, 274: struct kgsl_memdesc *memdesc, u64 size, u64 flags, u32 priv); 275: 276: /** 277: * kgsl_get_global_gpuaddr - Get global gpu address based on input parameters 278: * @device: A GPU device handle 279: * @memdesc: Pointer to memory descriptor 280: * @size: Size of the allocation in bytes 281: * @flags: Control flags for the allocation 282: * @priv: Internal flags for the allocation 283: * 284: * Get a gpu address in the global VA range based on the input parameters 285: * without allocating and mapping any physical pages. 286: * 287: * Return: 0 on success and negative error on failure 288: */ 289: int kgsl_get_global_gpuaddr(struct kgsl_device *device, struct kgsl_memdesc *memdesc, 290: u64 size, u64 flags, u32 priv); 291: 292: /** 293: * kgsl_alloc_map_gpu_global - Allocate and map a global GPU memory object 294: * @device: A GPU device handle 295: * @gpuaddr: pre-allocated GPU VA for this memory object 296: * @size: Size of the allocation in bytes 297: * @padding: Amount of extra adding to add to the VA allocation 298: * @flags: Control flags for the allocation 299: * @priv: Internal flags for the allocation 300: * @name: Name of the allocation (for the debugfs file) 301: * 302: * Allocate a global GPU object that is mapped into the default pagetables only. 303: * 304: * Return: 0 on success or negative error on failure 305: */ 306: struct kgsl_memdesc *kgsl_alloc_map_gpu_global(struct kgsl_device *device, 307: u64 gpuaddr, u64 size, u32 padding, u64 flags, u32 priv, const char *name); 308: 309: /** 310: * kgsl_allocate_global - Allocate a global GPU memory object 311: * @device: A GPU device handle 312: * @size: Size of the allocation in bytes 313: * @padding: Amount of extra adding to add to the VA allocation 314: * @flags: Control flags for the allocation 315: * @priv: Internal flags for the allocation 316: * @name: Name of the allocation (for the debugfs file) 317: * 318: * Allocate a global GPU object for use by all processes. The buffer is 319: * automatically mapped into the kernel address space and added to the list of 320: * global buffers that get mapped into each newly created pagetable. 321: * Return: The memory descriptor on success or a ERR_PTR encoded error on 322: * failure. 323: */ 324: struct kgsl_memdesc *kgsl_allocate_global(struct kgsl_device *device, 325: u64 size, u32 padding, u64 flags, u32 priv, const char *name); 326: 327: /** 328: * kgsl_allocate_global_fixed - Allocate a global GPU memory object from a fixed 329: * region defined in the device tree 330: * @device: A GPU device handle 331: * @size: Size of the allocation in bytes 332: * @flags: Control flags for the allocation 333: * @priv: Internal flags for the allocation 334: * 335: * Allocate a global GPU object for use by all processes. The buffer is 336: * added to the list of global buffers that get mapped into each newly created 337: * pagetable. 338: * 339: * Return: The memory descriptor on success or a ERR_PTR encoded error on 340: * failure. 341: */ 342: struct kgsl_memdesc *kgsl_allocate_global_fixed(struct kgsl_device *device, 343: const char *resource, const char *name); 344: /** 345: * kgsl_memdesc_init_fixed - Intializes a memory object from a fixed 346: * region defined in the device tree 347: * @device: A GPU device handle 348: * @pdev: Pointer to the platform device 349: * @resource: Name of the resource to get the size and address to allocate 350: * @memdesc: Memory descriptor for the object 351: * 352: * Intializes a memory object for a fixed I/O region defined in device tree. 353: * 354: * Return: 0 on success or negative on failure. 355: */ 356: int kgsl_memdesc_init_fixed(struct kgsl_device *device, 357: struct platform_device *pdev, const char *resource, 358: struct kgsl_memdesc *memdesc); 359: 360: /** 361: * kgsl_free_globals - Free all global objects 362: * @device: A GPU device handle 363: * 364: * Free all the global buffer objects. Should only be called during shutdown 365: * after the pagetables have been freed 366: */ 367: void kgsl_free_globals(struct kgsl_device *device); 368: 369: /** 370: * kgsl_page_sync_for_device - Initialize SG table with page & sync to/from device 371: * @dev: A GPU device handle 372: * @page: Pointer to the struct page 373: * @size: Size of the page 374: * @dir: DMA direction flag 375: */ 376: void kgsl_page_sync(struct device *dev, struct page *page, 377: size_t size, enum dma_data_direction dir); 378: 379: /* 380: * kgsl_memdesc_get_align - Get alignment flags from a memdesc 381: * @memdesc - the memdesc 382: * 383: * Returns the alignment requested, as power of 2 exponent. 384: */ 385: static inline u32 386: kgsl_memdesc_get_align(const struct kgsl_memdesc *memdesc) 387: { 388: return FIELD_GET(KGSL_MEMALIGN_MASK, memdesc->flags); 389: } 390: 391: /* 392: * kgsl_memdesc_get_cachemode - Get cache mode of a memdesc 393: * @memdesc: the memdesc 394: * 395: * Returns a KGSL_CACHEMODE* value. 396: */ 397: static inline int 398: kgsl_memdesc_get_cachemode(const struct kgsl_memdesc *memdesc) 399: { 400: return FIELD_GET(KGSL_CACHEMODE_MASK, memdesc->flags); 401: } 402: 403: static inline unsigned int 404: kgsl_memdesc_get_memtype(const struct kgsl_memdesc *memdesc) 405: { 406: return FIELD_GET(KGSL_MEMTYPE_MASK, memdesc->flags); 407: } 408: /* 409: * kgsl_memdesc_set_align - Set alignment flags of a memdesc 410: * @memdesc - the memdesc 411: * @align - alignment requested, as a power of 2 exponent. 412: */ 413: static inline int 414: kgsl_memdesc_set_align(struct kgsl_memdesc *memdesc, unsigned int align) 415: { 416: if (align > 32) 417: align = 32; 418: 419: memdesc->flags &= ~(uint64_t)KGSL_MEMALIGN_MASK; 420: memdesc->flags |= FIELD_PREP(KGSL_MEMALIGN_MASK, align); 421: return 0; 422: } 423: 424: /** 425: * kgsl_memdesc_usermem_type - return buffer type 426: * @memdesc - the memdesc 427: * 428: * Returns a KGSL_MEM_ENTRY_* value for this buffer, which 429: * identifies if was allocated by us, or imported from 430: * another allocator. 431: */ 432: static inline unsigned int 433: kgsl_memdesc_usermem_type(const struct kgsl_memdesc *memdesc) 434: { 435: return FIELD_GET(KGSL_MEMFLAGS_USERMEM_MASK, memdesc->flags); 436: } 437: 438: /** 439: * kgsl_memdesc_sg_dma - Turn a dma_addr (from CMA) into a sg table 440: * @memdesc: Pointer to a memory descriptor 441: * @addr: Physical address from the dma_alloc function 442: * @size: Size of the chunk 443: * 444: * Create a sg table for the contiguous chunk specified by addr and size. 445: * 446: * Return: 0 on success or negative on failure. 447: */ 448: int kgsl_memdesc_sg_dma(struct kgsl_memdesc *memdesc, 449: phys_addr_t addr, u64 size); 450: 451: /* 452: * kgsl_memdesc_is_global - is this a globally mapped buffer? 453: * @memdesc: the memdesc 454: * 455: * Return: True if this is a global mapping 456: */ 457: static inline bool kgsl_memdesc_is_global(const struct kgsl_memdesc *memdesc) 458: { 459: return memdesc && (TEST_FLAG(KGSL_MEMDESC_GLOBAL, &memdesc->priv)); 460: } 461: 462: /* 463: * kgsl_memdesc_is_secured - is this a secure buffer? 464: * @memdesc: the memdesc 465: * 466: * Returns true if this is a secure mapping, false otherwise 467: */ 468: static inline bool kgsl_memdesc_is_secured(const struct kgsl_memdesc *memdesc) 469: { 470: return memdesc && (TEST_FLAG(KGSL_MEMDESC_SECURE, &memdesc->priv)); 471: } 472: 473: /* 474: * kgsl_memdesc_is_reclaimed - check if a buffer is reclaimed 475: * @memdesc: the memdesc 476: * 477: * Return: true if the memdesc pages were reclaimed, false otherwise 478: */ 479: static inline bool kgsl_memdesc_is_reclaimed(const struct kgsl_memdesc *memdesc) 480: { 481: return memdesc && (TEST_FLAG(KGSL_MEMDESC_RECLAIMED, &memdesc->priv)); 482: } 483: 484: /* 485: * kgsl_memdesc_use_cpu_map - use the same virtual mapping on CPU and GPU? 486: * @memdesc: the memdesc 487: * 488: * Return: true if the memdesc is using SVM mapping 489: */ 490: static inline bool 491: kgsl_memdesc_use_cpu_map(const struct kgsl_memdesc *memdesc) 492: { 493: return memdesc && (memdesc->flags & KGSL_MEMFLAGS_USE_CPU_MAP); 494: } 495: 496: /* 497: * kgsl_memdesc_footprint - get the size of the mmap region 498: * @memdesc - the memdesc 499: * 500: * The entire memdesc must be mapped. Additionally if the 501: * CPU mapping is going to be mirrored, there must be room 502: * for the guard page to be mapped so that the address spaces 503: * match up. 504: */ 505: static inline uint64_t 506: kgsl_memdesc_footprint(const struct kgsl_memdesc *memdesc) 507: { 508: if (!(TEST_FLAG(KGSL_MEMDESC_GUARD_PAGE, &memdesc->priv))) 509: return memdesc->size; 510: 511: return PAGE_ALIGN(memdesc->size + PAGE_SIZE); 512: } 513: 514: /** 515: * kgsl_memdesc_put_gpuaddr - Release the gpuaddr assigned to a memdesc 516: * @memdesc: Pointer to a GPU memory object 517: * 518: * Call the memdesc specific function to release the GPU address assigned to the 519: * memdesc and unmap the memory 520: */ 521: static inline void kgsl_sharedmem_put_gpuaddr(struct kgsl_memdesc *memdesc) 522: { 523: if (memdesc && memdesc->ops->put_gpuaddr) 524: memdesc->ops->put_gpuaddr(memdesc); 525: } 526: 527: /** 528: * kgsl_cachemode_is_cached - Return true if the passed flags indicate a cached 529: * buffer 530: * @flags: A bitmask of KGSL_MEMDESC_ flags 531: * 532: * Return: true if the flags indicate a cached buffer 533: */ 534: static inline bool kgsl_cachemode_is_cached(u64 flags) 535: { 536: u64 mode = FIELD_GET(KGSL_CACHEMODE_MASK, flags); 537: 538: return (mode != KGSL_CACHEMODE_UNCACHED && 539: mode != KGSL_CACHEMODE_WRITECOMBINE); 540: } 541: 542: static inline bool kgsl_gpuaddr_in_memdesc(const struct kgsl_memdesc *memdesc, 543: u64 gpuaddr, u64 size) 544: { 545: if (IS_ERR_OR_NULL(memdesc)) 546: return false; 547: 548: /* set a minimum size to search for */ 549: if (!size) 550: size = 1; 551: 552: /* don't overflow */ 553: if (size > U64_MAX - gpuaddr) 554: return false; 555: 556: return (gpuaddr >= memdesc->gpuaddr && 557: ((gpuaddr + size) <= (memdesc->gpuaddr + memdesc->size))); 558: } 559: 560: static inline void *kgsl_memdesc_map(struct kgsl_memdesc *memdesc) 561: { 562: if (memdesc->ops && memdesc->ops->map_kernel) 563: memdesc->ops->map_kernel(memdesc); 564: 565: return memdesc->hostptr; 566: } 567: 568: static inline void kgsl_memdesc_unmap(struct kgsl_memdesc *memdesc) 569: { 570: if (memdesc->ops && memdesc->ops->unmap_kernel) 571: memdesc->ops->unmap_kernel(memdesc); 572: } 573: 574: static inline void *kgsl_gpuaddr_to_vaddr(struct kgsl_memdesc *memdesc, u64 gpuaddr) 575: { 576: void *hostptr = NULL; 577: 578: if ((gpuaddr >= memdesc->gpuaddr) && 579: (gpuaddr < (memdesc->gpuaddr + memdesc->size))) 580: hostptr = kgsl_memdesc_map(memdesc); 581: 582: return hostptr != NULL ? hostptr + (gpuaddr - memdesc->gpuaddr) : NULL; 583: } 584: 585: /** 586: * kgsl_unmap_and_put_gpuaddr - Unmap the memory and release the gpuaddr 587: * assigned to a memdesc 588: * @memdesc: Pointer to a GPU memory object 589: * 590: * Remove the mapping from pagetable and release the GPU address assigned 591: * to the memdesc 592: */ 593: void kgsl_unmap_and_put_gpuaddr(struct kgsl_memdesc *memdesc); 594: 595: /** 596: * struct kgsl_process_attribute - basic attribute for a process 597: * @attr: Underlying struct attribute 598: * @show: Attribute show function 599: * @store: Attribute store function 600: */ 601: struct kgsl_process_attribute { 602: struct attribute attr; 603: ssize_t (*show)(struct kobject *kobj, 604: struct kgsl_process_attribute *attr, char *buf); 605: ssize_t (*store)(struct kobject *kobj, 606: struct kgsl_process_attribute *attr, const char *buf, 607: ssize_t count); 608: }; 609: 610: #define PROCESS_ATTR(_name, _mode, _show, _store) \ 611: static struct kgsl_process_attribute attr_##_name = \ 612: __ATTR(_name, _mode, _show, _store) 613: 614: struct kgsl_sharedmem_bind_op_range { 615: u64 start; 616: u64 last; 617: u32 child_offset; 618: u32 op; 619: struct kgsl_mem_entry *entry; 620: }; 621: 622: struct kgsl_sharedmem_bind_op { 623: struct kgsl_mem_entry *target; 624: struct kgsl_sharedmem_bind_op_range *ops; 625: int nr_ops; 626: void (*callback)(struct kgsl_sharedmem_bind_op *op); 627: void *data; 628: struct work_struct work; 629: struct completion comp; 630: struct kref ref; 631: }; 632: 633: /** 634: * kgsl_sharedmem_allocate_vbo - Allocate a new virtual buffer object 635: * @device: A KGSL GPU handle 636: * @memdesc: Memory descriptor container to initialize 637: * @size: Size of the VBO 638: * @flags: Bitmask of KGSL_MEMFLAGS_* 639: * 640: * Initialize a new virtual buffer object memory descriptor 641: * 642: * Return: 0 on success or negative on failure. 643: */ 644: int kgsl_sharedmem_allocate_vbo(struct kgsl_device *device, 645: struct kgsl_memdesc *memdesc, u64 size, u64 flags); 646: 647: /** 648: * kgsl_memdesc_print_vbo_ranges - Print a new virtual buffer object 649: * @entry: A KGSL memory entry 650: * @s: seq_file pointer 651: * 652: * Print virtual buffer object memory ranges 653: */ 654: void kgsl_memdesc_print_vbo_ranges(struct kgsl_mem_entry *entry, 655: struct seq_file *s); 656: 657: /** 658: * kgsl_sharedmem_create_bind_op - Create a new bind op 659: * @private: A KGSL process private 660: * @target_id: Target virtual buffer object id 661: * @ranges: User memory pointer to an array of range operations of type &struct 662: * kgsl_gpumem_bind_range 663: * @ranges_nents: Number of entries in @ranges 664: * @ranges_size: Size of each entry in @ranges in bytes 665: * 666: * Create a new bind op to be used to map ranges 667: * 668: * Return: On success return kgsl_sharedmem_bind_op pointer or negative 669: * on failure 670: * 671: */ 672: struct kgsl_sharedmem_bind_op * 673: kgsl_sharedmem_create_bind_op(struct kgsl_process_private *private, 674: u32 target_id, void __user *ranges, u32 ranges_nents, 675: u64 ranges_size); 676: 677: /** 678: * kgsl_sharedmem_bind_ranges - Bind ranges to virtual buffer object 679: * @op: One of KGSL_GPUMEM_RANGE_OP_BIND or KGSL_GPUMEM_RANGE_OP_UNBIND 680: * 681: * Add or remove a range from kgsl memory descriptor 682: */ 683: void kgsl_sharedmem_bind_ranges(struct kgsl_sharedmem_bind_op *op); 684: 685: /** 686: * kgsl_sharedmem_bind_range_destroy - Bind ranges to virtual buffer object 687: * @kref: kref to bind kgsl_sharedmem_bind_op 688: * 689: * Destroy bind ranges object 690: */ 691: void kgsl_sharedmem_bind_range_destroy(struct kref *kref); 692: 693: /** 694: * kgsl_sharedmem_put_bind_op - Bind ranges to virtual buffer object 695: * @op: One of KGSL_GPUMEM_RANGE_OP_BIND or KGSL_GPUMEM_RANGE_OP_UNBIND 696: * 697: * Put kgsl_sharedmem_bind_range_destroy to free resources 698: */ 699: static inline void kgsl_sharedmem_put_bind_op(struct kgsl_sharedmem_bind_op *op) 700: { 701: if (!IS_ERR_OR_NULL(op)) 702: kref_put(&op->ref, kgsl_sharedmem_bind_range_destroy); 703: } 704: 705: /** 706: * kgsl_register_shmem_callback - Register vendor hook callback with SHMEM 707: * driver 708: */ 709: void kgsl_register_shmem_callback(void); 710: #endif /* __KGSL_SHAREDMEM_H */ --- FILE: \kgsl_snapshot.c | HITS: 51 --- MATCH LINES: 17 5: */ 6: 7: #include 8: #include 9: #include 10: #include 11: #include 12: #include 13: 14: #include "adreno_cp_parser.h" 15: #include "kgsl_device.h" 16: #include "kgsl_eventlog.h" 17: #include "kgsl_sharedmem.h" 18: #include "kgsl_snapshot.h" 19: #include "kgsl_util.h" 20: 21: static void kgsl_snapshot_save_frozen_objs(struct work_struct *work); 22: 23: /* Placeholder for list of ib objects that contain all objects in that IB */ 24: 25: struct kgsl_snapshot_cp_obj { 26: struct adreno_ib_object_list *ib_obj_list; 27: struct list_head node; 28: }; 29: 30: struct snapshot_obj_itr { 31: u8 *buf; /* Buffer pointer to write to */ 32: int pos; /* Current position in the sequence */ 33: loff_t offset; /* file offset to start writing from */ 34: size_t remain; /* Bytes remaining in buffer */ 35: size_t write; /* Bytes written so far */ 36: }; 37: 38: static inline u64 snapshot_phy_addr(struct kgsl_device *device) 39: { 40: return device->snapshot_memory.dma_handle ? 41: device->snapshot_memory.dma_handle : __pa(device->snapshot_memory.ptr); MATCH LINES: 100, 110, 119, 138, 139, 140, 149, 150, 161, 170, 179, 182, 187, 188, 195, 212, 215, 216, 218, 221, 224, 232, 233, 234, 235, 237, 238, 240, 242, 243, 256, 270, 271, 273, 277 88: itr->write += size; 89: itr->remain -= size; 90: 91: done: 92: itr->pos += size; 93: return size; 94: } 95: 96: static void kgsl_snapshot_put_object(struct kgsl_snapshot_object *obj) 97: { 98: list_del(&obj->node); 99: 100: CLEAR_FLAG(KGSL_MEMDESC_FROZEN | KGSL_MEMDESC_SKIP_RECLAIM, &obj->entry->memdesc.priv); 101: kgsl_mem_entry_put(obj->entry); 102: 103: kfree(obj); 104: } 105: 106: /** 107: * kgsl_snapshot_have_object() - return 1 if the object has been processed 108: * @snapshot: the snapshot data 109: * @process: The process that owns the object to freeze 110: * @gpuaddr: The gpu address of the object to freeze 111: * @size: the size of the object (may not always be the size of the region) 112: * 113: * Return 1 if the object is already in the list - this can save us from 114: * having to parse the same thing over again. There are 2 lists that are 115: * tracking objects so check for the object in both lists 116: */ 117: int kgsl_snapshot_have_object(struct kgsl_snapshot *snapshot, 118: struct kgsl_process_private *process, 119: uint64_t gpuaddr, uint64_t size) 120: { 121: struct kgsl_snapshot_object *obj; 122: struct kgsl_snapshot_cp_obj *obj_cp; 123: struct adreno_ib_object *ib_obj; 124: int i; 125: 126: /* Check whether the object is tracked already in ib list */ 127: list_for_each_entry(obj_cp, &snapshot->cp_list, node) { 128: if (obj_cp->ib_obj_list == NULL 129: || obj_cp->ib_obj_list->num_objs == 0) 130: continue; 131: 132: ib_obj = &(obj_cp->ib_obj_list->obj_list[0]); 133: if (ib_obj->entry == NULL || ib_obj->entry->priv != process) 134: continue; 135: 136: for (i = 0; i < obj_cp->ib_obj_list->num_objs; i++) { 137: ib_obj = &(obj_cp->ib_obj_list->obj_list[i]); 138: if ((gpuaddr >= ib_obj->gpuaddr) && 139: ((gpuaddr + size) <= 140: (ib_obj->gpuaddr + ib_obj->size))) 141: return 1; 142: } 143: } 144: 145: list_for_each_entry(obj, &snapshot->obj_list, node) { 146: if (obj->entry == NULL || obj->entry->priv != process) 147: continue; 148: 149: if ((gpuaddr >= obj->gpuaddr) && 150: ((gpuaddr + size) <= (obj->gpuaddr + obj->size))) 151: return 1; 152: } 153: 154: return 0; 155: } 156: 157: /** 158: * kgsl_snapshot_get_object() - Mark a GPU buffer to be frozen 159: * @snapshot: The snapshot data 160: * @process: The process that owns the object we want to freeze 161: * @gpuaddr: The gpu address of the object to freeze 162: * @size: the size of the object (may not always be the size of the region) 163: * @type: the type of object being saved (shader, vbo, etc) 164: * 165: * Mark and freeze a GPU buffer object. This will prevent it from being 166: * freed until it can be copied out as part of the snapshot dump. Returns the 167: * size of the object being frozen 168: */ 169: int kgsl_snapshot_get_object(struct kgsl_snapshot *snapshot, 170: struct kgsl_process_private *process, uint64_t gpuaddr, 171: uint64_t size, u32 type) 172: { 173: struct kgsl_mem_entry *entry; 174: struct kgsl_snapshot_object *obj; 175: uint64_t offset; 176: int ret = -EINVAL; 177: u32 mem_type; 178: 179: if (!gpuaddr) 180: return 0; 181: 182: entry = kgsl_sharedmem_find(process, gpuaddr); 183: 184: if (entry == NULL) 185: return -EINVAL; 186: 187: /* We can't freeze external memory, because we don't own it */ 188: if (entry->memdesc.flags & KGSL_MEMFLAGS_USERMEM_MASK) 189: goto err_put; 190: /* 191: * Do not save texture and render targets in snapshot, 192: * they can be just too big 193: */ 194: 195: mem_type = kgsl_memdesc_get_memtype(&entry->memdesc); 196: if (mem_type == KGSL_MEMTYPE_TEXTURE || 197: mem_type == KGSL_MEMTYPE_EGL_SURFACE || 198: mem_type == KGSL_MEMTYPE_SURFACE || 199: mem_type == KGSL_MEMTYPE_EGL_IMAGE) { 200: ret = 0; 201: goto err_put; 202: } 203: 204: /* 205: * size indicates the number of bytes in the region to save. This might 206: * not always be the entire size of the region because some buffers are 207: * sub-allocated from a larger region. However, if size 0 was passed 208: * thats a flag that the caller wants to capture the entire buffer 209: */ 210: 211: if (size == 0) { 212: size = entry->memdesc.size; 213: offset = 0; 214: 215: /* Adjust the gpuaddr to the start of the object */ 216: gpuaddr = entry->memdesc.gpuaddr; 217: } else { 218: offset = gpuaddr - entry->memdesc.gpuaddr; 219: } 220: 221: if (size + offset > entry->memdesc.size) { 222: dev_err(snapshot->device->dev, 223: "snapshot: invalid size for GPU buffer 0x%016llx\n", 224: gpuaddr); 225: goto err_put; 226: } 227: 228: /* If the buffer is already on the list, skip it */ 229: list_for_each_entry(obj, &snapshot->obj_list, node) { 230: /* combine the range with existing object if they overlap */ 231: if (obj->entry->priv == process && obj->type == type && 232: kgsl_addr_range_overlap(obj->gpuaddr, obj->size, 233: gpuaddr, size)) { 234: uint64_t end1 = obj->gpuaddr + obj->size; 235: uint64_t end2 = gpuaddr + size; 236: 237: if (obj->gpuaddr > gpuaddr) 238: obj->gpuaddr = gpuaddr; 239: if (end1 > end2) 240: obj->size = end1 - obj->gpuaddr; 241: else 242: obj->size = end2 - obj->gpuaddr; 243: obj->offset = obj->gpuaddr - entry->memdesc.gpuaddr; 244: ret = 0; 245: goto err_put; 246: } 247: } 248: 249: obj = kzalloc(sizeof(*obj), GFP_KERNEL); 250: 251: if (obj == NULL) 252: goto err_put; 253: 254: obj->type = type; 255: obj->entry = entry; 256: obj->gpuaddr = gpuaddr; 257: obj->size = size; 258: obj->offset = offset; 259: 260: list_add(&obj->node, &snapshot->obj_list); 261: 262: /* 263: * Return the size of the entire mem entry that was frozen - this gets 264: * used for tracking how much memory is frozen for a hang. Also, mark 265: * the memory entry as frozen. If the entry was already marked as 266: * frozen, then another buffer already got to it. In that case, return 267: * 0 so it doesn't get counted twice 268: */ 269: 270: ret = (TEST_FLAG(KGSL_MEMDESC_FROZEN, &entry->memdesc.priv)) ? 0 271: : entry->memdesc.size; 272: 273: SET_FLAG(KGSL_MEMDESC_FROZEN, &entry->memdesc.priv); 274: 275: return ret; 276: err_put: 277: CLEAR_FLAG(KGSL_MEMDESC_SKIP_RECLAIM, &entry->memdesc.priv); 278: kgsl_mem_entry_put(entry); 279: return ret; 280: } 281: 282: /** 283: * kgsl_snapshot_dump_registers - helper function to dump device registers 284: * @device - the device to dump registers from 285: * @snapshot - pointer to the start of the region of memory for the snapshot 286: * @remain - a pointer to the number of bytes remaining in the snapshot 287: * @priv - A pointer to the kgsl_snapshot_registers data 288: * 289: * Given an array of register ranges pairs (start,end [inclusive]), dump the 290: * registers into a snapshot register section. The snapshot region stores a 291: * part of dwords for each register - the word address of the register, and 292: * the value. 293: */ 294: size_t kgsl_snapshot_dump_registers(struct kgsl_device *device, u8 *buf, 295: size_t remain, void *priv) 296: { 297: struct kgsl_snapshot_regs *header = (struct kgsl_snapshot_regs *)buf; 298: struct kgsl_snapshot_registers *regs = priv; 299: u32 *data = (u32 *)(buf + sizeof(*header)); 300: int count = 0, j, k; 301: MATCH LINES: 505 493: static void kgsl_free_snapshot(struct kgsl_snapshot *snapshot) 494: { 495: struct kgsl_snapshot_object *obj, *tmp; 496: struct kgsl_device *device = snapshot->device; 497: 498: wait_for_completion(&snapshot->dump_gate); 499: 500: list_for_each_entry_safe(obj, tmp, 501: &snapshot->obj_list, node) 502: kgsl_snapshot_put_object(obj); 503: 504: if (snapshot->mempool) 505: vfree(snapshot->mempool); 506: 507: kfree(snapshot); 508: dev_err(device->dev, "snapshot: objects released\n"); 509: } 510: 511: #define SP0_ISDB_ISDB_BRKPT_CFG 0x40014 512: #define SP0_ISDB_ISDB_EN 0x40004 513: #define SP0_ISDB_ISDB_CMD 0x4000C 514: 515: void isdb_write(void __iomem *base, u32 offset) 516: { 517: /* To set the SCHBREAKTYPE bit */ 518: __raw_writel(0x801, base + SP0_ISDB_ISDB_BRKPT_CFG + offset); 519: 520: /* 521: * ensure the configurations are set before 522: * enabling ISDB 523: */ 524: wmb(); 525: /* To set the ISDBCLKON and ISDB_EN bits*/ 526: __raw_writel(0x03, base + SP0_ISDB_ISDB_EN + offset); 527: 528: /* 529: * ensure previous write to enable isdb posts MATCH LINES: 574, 580 562: device->snapshot_memory_atomic.size, GFP_ATOMIC); 563: 564: /* If we fail to allocate more than 1MB fall back to 1MB */ 565: if (WARN_ON((!device->snapshot_memory_atomic.ptr) && 566: device->snapshot_memory_atomic.size > SZ_1M)) { 567: device->snapshot_memory_atomic.size = SZ_1M; 568: device->snapshot_memory_atomic.ptr = devm_kzalloc(&device->pdev->dev, 569: device->snapshot_memory_atomic.size, GFP_ATOMIC); 570: } 571: 572: if (!device->snapshot_memory_atomic.ptr) { 573: dev_err(device->dev, 574: "Failed to allocate memory for atomic snapshot\n"); 575: return; 576: } 577: } 578: 579: snapshot: 580: /* Allocate memory for the snapshot instance */ 581: snapshot = kzalloc(sizeof(*snapshot), GFP_ATOMIC); 582: if (snapshot == NULL) 583: return; 584: 585: device->snapshot_atomic = true; 586: INIT_LIST_HEAD(&snapshot->obj_list); 587: INIT_LIST_HEAD(&snapshot->cp_list); 588: 589: snapshot->start = device->snapshot_memory_atomic.ptr; 590: snapshot->ptr = device->snapshot_memory_atomic.ptr; 591: 592: /* Ensure size is read after reading address */ 593: smp_rmb(); 594: 595: snapshot->remain = device->snapshot_memory_atomic.size; 596: 597: /* 598: * Trigger both GPU and GMU snapshot. GPU specific code 599: * will take care of whether to dumps full state or only 600: * GMU state based on current GPU power state. 601: */ 602: if (device->ftbl->snapshot) 603: device->ftbl->snapshot(device, snapshot, NULL, NULL); 604: MATCH LINES: 682 670: !device->snapshot->recovered || !gmu_fault) 671: return; 672: 673: /* 674: * If another thread is currently reading it, that thread 675: * will free it, otherwise free it now. 676: */ 677: if (!device->snapshot->sysfs_read) 678: kgsl_free_snapshot(device->snapshot); 679: device->snapshot = NULL; 680: } 681: 682: /* Allocate memory for the snapshot instance */ 683: snapshot = kzalloc(sizeof(*snapshot), GFP_KERNEL); 684: if (snapshot == NULL) 685: return; 686: 687: init_completion(&snapshot->dump_gate); 688: INIT_LIST_HEAD(&snapshot->obj_list); 689: INIT_LIST_HEAD(&snapshot->cp_list); 690: INIT_WORK(&snapshot->work, kgsl_snapshot_save_frozen_objs); 691: 692: snapshot->start = device->snapshot_memory.ptr; 693: snapshot->ptr = device->snapshot_memory.ptr; 694: snapshot->remain = device->snapshot_memory.size; 695: snapshot->recovered = false; 696: snapshot->first_read = true; 697: snapshot->sysfs_read = 0; 698: 699: device->ftbl->snapshot(device, snapshot, context, context_lpac); 700: 701: kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_EVENTLOG, 702: snapshot, kgsl_snapshot_eventlog_buffer, NULL); 703: 704: /* 705: * The timestamp is the seconds since boot so it is easier to match to 706: * the kernel log MATCH LINES: 766 754: */ 755: static void kgsl_snapshot_process_ib_obj_list(struct kgsl_snapshot *snapshot) 756: { 757: struct kgsl_snapshot_cp_obj *obj, *obj_temp; 758: struct adreno_ib_object *ib_obj; 759: int i; 760: 761: list_for_each_entry_safe(obj, obj_temp, &snapshot->cp_list, 762: node) { 763: for (i = 0; i < obj->ib_obj_list->num_objs; i++) { 764: ib_obj = &(obj->ib_obj_list->obj_list[i]); 765: kgsl_snapshot_get_object(snapshot, ib_obj->entry->priv, 766: ib_obj->gpuaddr, ib_obj->size, 767: ib_obj->snapshot_obj_type); 768: } 769: list_del(&obj->node); 770: adreno_ib_destroy_obj_list(obj->ib_obj_list); 771: kfree(obj); 772: } 773: } 774: 775: #define to_snapshot_attr(a) \ 776: container_of(a, struct kgsl_snapshot_attribute, attr) 777: 778: #define kobj_to_device(a) \ 779: container_of(a, struct kgsl_device, snapshot_kobj) 780: 781: static int snapshot_release(struct kgsl_device *device, 782: struct kgsl_snapshot *snapshot) 783: { 784: bool snapshot_free = false; 785: int ret = 0; 786: 787: kgsl_mutex_lock(&device->mutex); 788: snapshot->sysfs_read--; 789: 790: /* MATCH LINES: 1172 1160: /* 1161: * If we fail to allocate more than 1MB for snapshot fall back 1162: * to 1MB 1163: */ 1164: if (WARN_ON((!device->snapshot_memory.ptr) && size > SZ_1M)) { 1165: device->snapshot_memory.size = SZ_1M; 1166: device->snapshot_memory.ptr = devm_kzalloc(&device->pdev->dev, 1167: device->snapshot_memory.size, GFP_KERNEL); 1168: } 1169: 1170: if (!device->snapshot_memory.ptr) { 1171: dev_err(device->dev, 1172: "KGSL failed to allocate memory for snapshot\n"); 1173: return; 1174: } 1175: 1176: device->snapshot = NULL; 1177: device->snapshot_faultcount = 0; 1178: device->force_panic = false; 1179: device->snapshot_crashdumper = true; 1180: device->snapshot_legacy = false; 1181: 1182: device->snapshot_atomic = false; 1183: device->panic_nb.notifier_call = kgsl_panic_notifier_callback; 1184: device->panic_nb.priority = 1; 1185: device->snapshot_ctxt_record_size = 64 * 1024; 1186: 1187: /* 1188: * Set this to false so that we only ever keep the first snapshot around 1189: * If we want to over-write with a gmu snapshot, then set it to true 1190: * via sysfs 1191: */ 1192: device->prioritize_unrecoverable = false; 1193: 1194: if (kobject_init_and_add(&device->snapshot_kobj, &ktype_snapshot, 1195: &device->dev->kobj, "snapshot")) 1196: return; MATCH LINES: 1215, 1237, 1241 1203: if (!IS_ENABLED(CONFIG_QCOM_KGSL_DEVCOREDUMP)) 1204: WARN_ON(sysfs_create_bin_file(&device->snapshot_kobj, &snapshot_attr)); 1205: 1206: WARN_ON(sysfs_create_files(&device->snapshot_kobj, snapshot_attrs)); 1207: atomic_notifier_chain_register(&panic_notifier_list, 1208: &device->panic_nb); 1209: } 1210: 1211: /** 1212: * kgsl_device_snapshot_close() - take down snapshot memory for a device 1213: * @device: Pointer to the kgsl_device 1214: * 1215: * Remove the sysfs files and free the memory allocated for the GPU 1216: * snapshot 1217: */ 1218: void kgsl_device_snapshot_close(struct kgsl_device *device) 1219: { 1220: if (device->snapshot_memory.ptr == NULL) 1221: return; 1222: 1223: kgsl_remove_from_minidump("GPU_SNAPSHOT", (u64) device->snapshot_memory.ptr, 1224: snapshot_phy_addr(device), device->snapshot_memory.size); 1225: 1226: atomic_notifier_chain_unregister(&panic_notifier_list, 1227: &device->panic_nb); 1228: 1229: if (!IS_ENABLED(CONFIG_QCOM_KGSL_DEVCOREDUMP)) 1230: sysfs_remove_bin_file(&device->snapshot_kobj, &snapshot_attr); 1231: 1232: sysfs_remove_files(&device->snapshot_kobj, snapshot_attrs); 1233: 1234: kobject_put(&device->snapshot_kobj); 1235: 1236: if (device->snapshot_memory.dma_handle) 1237: dma_free_coherent(&device->pdev->dev, device->snapshot_memory.size, 1238: device->snapshot_memory.ptr, device->snapshot_memory.dma_handle); 1239: 1240: if (device->snapshot_memory_atomic.dma_handle) 1241: dma_free_coherent(&device->pdev->dev, device->snapshot_memory_atomic.size, 1242: device->snapshot_memory_atomic.ptr, 1243: device->snapshot_memory_atomic.dma_handle); 1244: } 1245: 1246: /** 1247: * kgsl_snapshot_add_ib_obj_list() - Add a IB object list to the snapshot 1248: * object list 1249: * @device: the device that is being snapshotted 1250: * @ib_obj_list: The IB list that has objects required to execute an IB 1251: * @num_objs: Number of IB objects 1252: * @ptbase: The pagetable base in which the IB is mapped 1253: * 1254: * Adds a new IB to the list of IB objects maintained when getting snapshot 1255: * Returns 0 on success else -ENOMEM on error 1256: */ 1257: int kgsl_snapshot_add_ib_obj_list(struct kgsl_snapshot *snapshot, 1258: struct adreno_ib_object_list *ib_obj_list) 1259: { 1260: struct kgsl_snapshot_cp_obj *obj; 1261: 1262: obj = kzalloc(sizeof(*obj), GFP_KERNEL); 1263: if (!obj) 1264: return -ENOMEM; 1265: obj->ib_obj_list = ib_obj_list; MATCH LINES: 1282, 1293, 1298, 1302, 1306, 1307 1270: static size_t _mempool_add_object(struct kgsl_snapshot *snapshot, u8 *data, 1271: struct kgsl_snapshot_object *obj) 1272: { 1273: struct kgsl_snapshot_section_header *section = 1274: (struct kgsl_snapshot_section_header *)data; 1275: struct kgsl_snapshot_gpu_object_v2 *header = 1276: (struct kgsl_snapshot_gpu_object_v2 *)(data + sizeof(*section)); 1277: u8 *dest = data + sizeof(*section) + sizeof(*header); 1278: uint64_t size; 1279: 1280: size = obj->size; 1281: 1282: if (!kgsl_memdesc_map(&obj->entry->memdesc)) { 1283: dev_err(snapshot->device->dev, 1284: "snapshot: failed to map GPU object\n"); 1285: return 0; 1286: } 1287: 1288: section->magic = SNAPSHOT_SECTION_MAGIC; 1289: section->id = KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2; 1290: section->size = size + sizeof(*header) + sizeof(*section); 1291: 1292: header->size = size >> 2; 1293: header->gpuaddr = obj->gpuaddr; 1294: header->ptbase = 1295: kgsl_mmu_pagetable_get_ttbr0(obj->entry->priv->pagetable); 1296: header->type = obj->type; 1297: 1298: if (kgsl_addr_range_overlap(obj->gpuaddr, obj->size, 1299: snapshot->ib1base, snapshot->ib1size)) 1300: snapshot->ib1dumped = true; 1301: 1302: if (kgsl_addr_range_overlap(obj->gpuaddr, obj->size, 1303: snapshot->ib2base, snapshot->ib2size)) 1304: snapshot->ib2dumped = true; 1305: 1306: memcpy(dest, obj->entry->memdesc.hostptr + obj->offset, size); 1307: kgsl_memdesc_unmap(&obj->entry->memdesc); 1308: 1309: return section->size; 1310: } 1311: 1312: /** 1313: * kgsl_snapshot_save_frozen_objs() - Save the objects frozen in snapshot into 1314: * memory so that the data reported in these objects is correct when snapshot 1315: * is taken 1316: * @work: The work item that scheduled this work 1317: */ 1318: static void kgsl_snapshot_save_frozen_objs(struct work_struct *work) 1319: { 1320: struct kgsl_snapshot *snapshot = container_of(work, 1321: struct kgsl_snapshot, work); 1322: struct kgsl_snapshot_object *obj, *tmp; 1323: size_t size = 0; 1324: void *ptr; 1325: 1326: if (snapshot->device->gmu_fault) 1327: goto gmu_only; 1328: 1329: kgsl_snapshot_process_ib_obj_list(snapshot); 1330: 1331: list_for_each_entry(obj, &snapshot->obj_list, node) { --- FILE: \kgsl_snapshot.h | HITS: 5 --- MATCH LINES: 114, 131, 154 102: }; 103: 104: /* Ringbuffer sub-section header */ 105: struct kgsl_snapshot_rb_v2 { 106: int start; /* dword at the start of the dump */ 107: int end; /* dword at the end of the dump */ 108: int rbsize; /* Size (in dwords) of the ringbuffer */ 109: int wptr; /* Current index of the CPU write pointer */ 110: int rptr; /* Current index of the GPU read pointer */ 111: int count; /* Number of dwords in the dump */ 112: __u32 timestamp_queued; /* The last queued timestamp */ 113: __u32 timestamp_retired; /* The last timestamp retired by HW */ 114: __u64 gpuaddr; /* The GPU address of the ringbuffer */ 115: __u32 id; /* Ringbuffer identifier */ 116: } __packed; 117: 118: /* Replay or Memory list section, both sections have same header */ 119: struct kgsl_snapshot_mem_list_v2 { 120: /* 121: * Number of IBs to replay for replay section or 122: * number of memory list entries for mem list section 123: */ 124: int num_entries; 125: /* Pagetable base to which the replay IBs or memory entries belong */ 126: __u64 ptbase; 127: } __packed; 128: 129: /* Indirect buffer sub-section header (v2) */ 130: struct kgsl_snapshot_ib_v2 { 131: __u64 gpuaddr; /* GPU address of the IB */ 132: __u64 ptbase; /* Base for the pagetable the GPU address is valid in */ 133: __u64 size; /* Size of the IB */ 134: } __packed; 135: 136: /* GMU memory ID's */ 137: #define SNAPSHOT_GMU_MEM_UNKNOWN 0x00 138: #define SNAPSHOT_GMU_MEM_HFI 0x01 139: #define SNAPSHOT_GMU_MEM_LOG 0x02 140: #define SNAPSHOT_GMU_MEM_BWTABLE 0x03 141: #define SNAPSHOT_GMU_MEM_DEBUG 0x04 142: #define SNAPSHOT_GMU_MEM_BIN_BLOCK 0x05 143: #define SNAPSHOT_GMU_MEM_CONTEXT_QUEUE 0x06 144: #define SNAPSHOT_GMU_MEM_HW_FENCE 0x07 145: #define SNAPSHOT_GMU_MEM_WARMBOOT 0x08 146: #define SNAPSHOT_GMU_MEM_VRB 0x09 147: #define SNAPSHOT_GMU_MEM_TRACE 0x0a 148: 149: /* GMU memory section data */ 150: struct kgsl_snapshot_gmu_mem { 151: int type; 152: uint64_t hostaddr; 153: uint64_t gmuaddr; 154: uint64_t gpuaddr; 155: } __packed; 156: 157: /* Register sub-section header */ 158: struct kgsl_snapshot_regs { 159: __u32 count; /* Number of register pairs in the section */ 160: } __packed; 161: 162: /* Indexed register sub-section header */ 163: struct kgsl_snapshot_indexed_regs { 164: __u32 index_reg; /* Offset of the index register for this section */ 165: __u32 data_reg; /* Offset of the data register for this section */ 166: int start; /* Starting index */ 167: int count; /* Number of dwords in the data */ 168: } __packed; 169: 170: struct kgsl_snapshot_indexed_regs_v2 { 171: u32 index_reg; /* Offset of the index register for this section */ 172: u32 data_reg; /* Offset of the data register for this section */ 173: u32 start; /* Starting index */ 174: u32 count; /* Number of dwords in the data */ 175: u32 pipe_id; /* Id of pipe, BV, Br etc */ 176: u32 slice_id; /* Slice ID to be dumped */ 177: } __packed; 178: MATCH LINES: 310, 345 298: /** @size: Number of bytes in the dump */ 299: __u32 size; 300: } __packed; 301: 302: #define SNAPSHOT_GPU_OBJECT_SHADER 1 303: #define SNAPSHOT_GPU_OBJECT_IB 2 304: #define SNAPSHOT_GPU_OBJECT_GENERIC 3 305: #define SNAPSHOT_GPU_OBJECT_DRAW 4 306: #define SNAPSHOT_GPU_OBJECT_GLOBAL 5 307: 308: struct kgsl_snapshot_gpu_object_v2 { 309: int type; /* Type of GPU object */ 310: __u64 gpuaddr; /* GPU address of the object */ 311: __u64 ptbase; /* Base for the pagetable the GPU address is valid in */ 312: __u64 size; /* Size of the object (in dwords) */ 313: } __packed; 314: 315: struct kgsl_snapshot_eventlog { 316: /** @type: Type of the event log buffer */ 317: __u16 type; 318: /** @version: Version of the event log buffer */ 319: __u16 version; 320: /** @size: Size of the eventlog buffer in bytes */ 321: u32 size; 322: } __packed; 323: 324: struct kgsl_snapshot_gmu_version { 325: /** @type: Type of the GMU version buffer */ 326: u32 type; 327: /** @value: GMU FW version value */ 328: u32 value; 329: } __packed; 330: 331: struct kgsl_snapshot_indexed_registers_v2 { 332: u32 index; 333: u32 data; 334: u32 start; 335: u32 count; 336: u32 pipe_id; 337: u32 slice_id; 338: }; 339: 340: struct kgsl_device; 341: struct kgsl_process_private; 342: 343: void kgsl_snapshot_push_object(struct kgsl_device *device, 344: struct kgsl_process_private *process, 345: uint64_t gpuaddr, uint64_t dwords); 346: #endif --- FILE: \kgsl_sync.c | HITS: 2 --- MATCH LINES: 82 70: spin_lock_init(&hw_fence_list_lock); 71: 72: return 0; 73: } 74: 75: void kgsl_hw_fence_close(struct kgsl_device *device) 76: { 77: destroy_all_hw_fences(); 78: 79: synx_uninitialize(kgsl_synx.handle); 80: } 81: 82: void kgsl_hw_fence_populate_md(struct kgsl_device *device, struct kgsl_memdesc *md) 83: { 84: md->physaddr = kgsl_synx.mem_descriptor.dev_addr; 85: md->size = kgsl_synx.mem_descriptor.size; 86: md->hostptr = kgsl_synx.mem_descriptor.vaddr; 87: } 88: 89: int kgsl_hw_fence_create(struct kgsl_device *device, struct kgsl_sync_fence *kfence) 90: { 91: struct synx_create_params params = {0}; 92: int ret; 93: 94: params.fence = &kfence->fence; 95: params.h_synx = (u32 *)&kfence->hw_fence_index; 96: params.flags = SYNX_CREATE_DMA_FENCE; 97: 98: ret = synx_create(kgsl_synx.handle, ¶ms); 99: if (!ret) { 100: add_hw_fence(kfence); 101: return 0; 102: } 103: 104: if (__ratelimit(&_rs)) 105: dev_err(device->dev, "Failed to create ctx:%d ts:%d hardware fence:%d\n", 106: kfence->context_id, kfence->timestamp, ret); MATCH LINES: 252 240: spin_lock_init(&hw_fence_list_lock); 241: 242: return 0; 243: } 244: 245: void kgsl_hw_fence_close(struct kgsl_device *device) 246: { 247: destroy_all_hw_fences(); 248: 249: msm_hw_fence_deregister(kgsl_msm_hw_fence.handle); 250: } 251: 252: void kgsl_hw_fence_populate_md(struct kgsl_device *device, struct kgsl_memdesc *md) 253: { 254: md->physaddr = kgsl_msm_hw_fence.mem_descriptor.device_addr; 255: md->size = kgsl_msm_hw_fence.mem_descriptor.size; 256: md->hostptr = kgsl_msm_hw_fence.mem_descriptor.virtual_addr; 257: } 258: 259: int kgsl_hw_fence_create(struct kgsl_device *device, struct kgsl_sync_fence *kfence) 260: { 261: struct msm_hw_fence_create_params params = {0}; 262: int ret; 263: 264: params.fence = &kfence->fence; 265: params.handle = &kfence->hw_fence_index; 266: 267: ret = msm_hw_fence_create(kgsl_msm_hw_fence.handle, ¶ms); 268: if ((ret || IS_ERR_OR_NULL(params.handle))) { 269: if (__ratelimit(&_rs)) 270: dev_err(device->dev, "Failed to create ctx:%d ts:%d hardware fence:%d\n", 271: kfence->context_id, kfence->timestamp, ret); 272: return -EINVAL; 273: } 274: 275: add_hw_fence(kfence); 276: --- FILE: \kgsl_sync.h | HITS: 2 --- MATCH LINES: 124 112: void kgsl_syncsource_process_release_syncsources( 113: struct kgsl_process_private *private); 114: 115: bool is_kgsl_fence(struct dma_fence *f); 116: 117: void kgsl_sync_timeline_signal(struct kgsl_sync_timeline *ktimeline, 118: u32 timestamp); 119: 120: int kgsl_hw_fence_init(struct kgsl_device *device); 121: 122: void kgsl_hw_fence_close(struct kgsl_device *device); 123: 124: void kgsl_hw_fence_populate_md(struct kgsl_device *device, struct kgsl_memdesc *md); 125: 126: int kgsl_hw_fence_create(struct kgsl_device *device, struct kgsl_sync_fence *kfence); 127: 128: int kgsl_hw_fence_add_waiter(struct kgsl_device *device, struct dma_fence *fence, u32 *hash_index); 129: 130: bool kgsl_hw_fence_tx_slot_available(struct kgsl_device *device, u32 pending_hw_fence_count); 131: 132: void kgsl_hw_fence_destroy(struct kgsl_sync_fence *kfence); 133: 134: void kgsl_hw_fence_trigger_cpu(struct kgsl_device *device, struct kgsl_sync_fence *kfence); 135: 136: bool kgsl_hw_fence_signaled(struct dma_fence *fence); 137: 138: void kgsl_get_fence_name(struct dma_fence *f, char *name, u32 max_size); 139: 140: int kgsl_hw_fence_soccp_vote(bool pwr_on); 141: 142: #else 143: static inline int kgsl_add_fence_event(struct kgsl_device *device, 144: u32 context_id, u32 timestamp, void __user *data, int len, 145: struct kgsl_device_private *owner) 146: { 147: return -EINVAL; 148: } MATCH LINES: 245 233: } 234: 235: int kgsl_hw_fence_init(struct kgsl_device *device) 236: { 237: return -EINVAL; 238: } 239: 240: void kgsl_hw_fence_close(struct kgsl_device *device) 241: { 242: 243: } 244: 245: void kgsl_hw_fence_populate_md(struct kgsl_device *device, struct kgsl_memdesc *md) 246: { 247: 248: } 249: 250: int kgsl_hw_fence_create(struct kgsl_device *device, struct kgsl_sync_fence *kfence) 251: { 252: return -EINVAL; 253: } 254: 255: int kgsl_hw_fence_add_waiter(struct kgsl_device *device, struct dma_fence *fence, u32 *hash_index) 256: { 257: return -EINVAL; 258: } 259: 260: bool kgsl_hw_fence_tx_slot_available(struct kgsl_device *device, u32 pending_hw_fence_count) 261: { 262: return false; 263: } 264: 265: void kgsl_hw_fence_destroy(struct kgsl_sync_fence *kfence) 266: { 267: 268: } 269: --- FILE: \kgsl_timeline.c | HITS: 1 --- MATCH LINES: 16 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include 8: #include 9: #include 10: #include 11: #include 12: #include 13: 14: #include "kgsl_device.h" 15: #include "kgsl_eventlog.h" 16: #include "kgsl_sharedmem.h" 17: #include "kgsl_sync.h" 18: #include "kgsl_timeline.h" 19: #include "kgsl_trace.h" 20: 21: struct kgsl_timeline_fence { 22: struct dma_fence base; 23: struct kgsl_timeline *timeline; 24: struct list_head node; 25: }; 26: 27: /* 28: * kgsl_timelines_collect_fences - Collect timeline fences from userspace 29: * @device: A KGSL device handle 30: * @timelines: Userspace pointer to an array of &struct kgsl_timeline_val 31: * @count: Number of entries in @timelines 32: * @usize: Size of each entry in @timelines 33: * 34: * Returns an array of dma_fence pointers on success, or ERR_PTR on failure. 35: */ 36: static struct dma_fence **kgsl_timelines_collect_fences( 37: struct kgsl_device *device, u64 timelines, u32 count, 38: u64 usize) 39: { 40: void __user *uptr = u64_to_user_ptr(timelines); --- FILE: \kgsl_trace.h | HITS: 58 --- MATCH LINES: 21 9: 10: #undef TRACE_SYSTEM 11: #define TRACE_SYSTEM kgsl 12: #undef TRACE_INCLUDE_PATH 13: #define TRACE_INCLUDE_PATH . 14: #undef TRACE_INCLUDE_FILE 15: #define TRACE_INCLUDE_FILE kgsl_trace 16: 17: #include 18: 19: #include "kgsl.h" 20: #include "kgsl_drawobj.h" 21: #include "kgsl_sharedmem.h" 22: 23: #if (KERNEL_VERSION(6, 10, 0) > LINUX_VERSION_CODE) 24: #define kgsl_assign_str(dst, src) __assign_str(dst, src) 25: #else 26: #define kgsl_assign_str(dst, src) __assign_str(dst) 27: #endif 28: 29: #define KGSL_TRACE_GPU_FREQ(freq, gpu_id, ticks) \ 30: do { \ 31: trace_gpu_frequency(freq, gpu_id); \ 32: trace_kgsl_gpu_frequency(freq, gpu_id, ticks); \ 33: } while (0) 34: 35: #define show_memtype(type) \ 36: __print_symbolic(type, \ 37: { KGSL_MEM_ENTRY_KERNEL, "gpumem" }, \ 38: { KGSL_MEM_ENTRY_USER, "usermem" }, \ 39: { KGSL_MEM_ENTRY_ION, "ion" }) 40: 41: #define show_constraint(type) \ 42: __print_symbolic(type, \ 43: { KGSL_CONSTRAINT_NONE, "None" }, \ 44: { KGSL_CONSTRAINT_PWRLEVEL, "Pwrlevel" }, \ 45: { KGSL_CONSTRAINT_L3_NONE, "L3_none" }, \ MATCH LINES: 490, 499, 500, 503, 505, 509, 510, 523, 532, 533, 535, 537, 541, 542, 580, 590, 591, 593, 596, 601, 602, 616, 626, 627, 628, 631, 636, 637, 651, 661, 663, 669, 673, 674, 689, 697, 705, 706, 718, 726, 734, 735, 770, 782, 783, 785, 788, 794, 796 478: DEFINE_EVENT(kgsl_pwrstate_template, kgsl_pwr_request_state, 479: TP_PROTO(struct kgsl_device *device, unsigned int state), 480: TP_ARGS(device, state) 481: ); 482: 483: TRACE_EVENT(kgsl_mem_alloc, 484: 485: TP_PROTO(struct kgsl_mem_entry *mem_entry), 486: 487: TP_ARGS(mem_entry), 488: 489: TP_STRUCT__entry( 490: __field(uint64_t, gpuaddr) 491: __field(uint64_t, size) 492: __field(unsigned int, tgid) 493: __array(char, usage, 16) 494: __field(unsigned int, id) 495: __field(uint64_t, flags) 496: ), 497: 498: TP_fast_assign( 499: __entry->gpuaddr = mem_entry->memdesc.gpuaddr; 500: __entry->size = mem_entry->memdesc.size; 501: __entry->tgid = pid_nr(mem_entry->priv->pid); 502: kgsl_get_memory_usage(__entry->usage, sizeof(__entry->usage), 503: mem_entry->memdesc.flags); 504: __entry->id = mem_entry->id; 505: __entry->flags = mem_entry->memdesc.flags; 506: ), 507: 508: TP_printk( 509: "gpuaddr=0x%llx size=%llu tgid=%u usage=%s id=%u flags=0x%llx", 510: __entry->gpuaddr, __entry->size, __entry->tgid, 511: __entry->usage, __entry->id, __entry->flags 512: ) 513: ); 514: 515: TRACE_EVENT(kgsl_mem_mmap, 516: 517: TP_PROTO(struct kgsl_mem_entry *mem_entry, unsigned long useraddr), 518: 519: TP_ARGS(mem_entry, useraddr), 520: 521: TP_STRUCT__entry( 522: __field(unsigned long, useraddr) 523: __field(uint64_t, gpuaddr) 524: __field(uint64_t, size) 525: __array(char, usage, 16) 526: __field(unsigned int, id) 527: __field(uint64_t, flags) 528: ), 529: 530: TP_fast_assign( 531: __entry->useraddr = useraddr; 532: __entry->gpuaddr = mem_entry->memdesc.gpuaddr; 533: __entry->size = mem_entry->memdesc.size; 534: kgsl_get_memory_usage(__entry->usage, sizeof(__entry->usage), 535: mem_entry->memdesc.flags); 536: __entry->id = mem_entry->id; 537: __entry->flags = mem_entry->memdesc.flags; 538: ), 539: 540: TP_printk( 541: "useraddr=0x%lx gpuaddr=0x%llx size=%llu usage=%s id=%u flags=0x%llx", 542: __entry->useraddr, __entry->gpuaddr, __entry->size, 543: __entry->usage, __entry->id, __entry->flags 544: ) 545: ); 546: 547: TRACE_EVENT(kgsl_mem_unmapped_area_collision, 548: 549: TP_PROTO(struct kgsl_mem_entry *mem_entry, 550: unsigned long addr, 551: unsigned long len), 552: 553: TP_ARGS(mem_entry, addr, len), 554: 555: TP_STRUCT__entry( 556: __field(unsigned int, id) 557: __field(unsigned long, addr) 558: __field(unsigned long, len) 559: ), 560: 561: TP_fast_assign( 562: __entry->id = mem_entry->id; 563: __entry->len = len; 564: __entry->addr = addr; 565: ), 566: 567: TP_printk( 568: "id=%u len=%lu addr=0x%lx", 569: __entry->id, __entry->len, __entry->addr 570: ) 571: ); 572: 573: TRACE_EVENT(kgsl_mem_map, 574: 575: TP_PROTO(struct kgsl_mem_entry *mem_entry, int fd), 576: 577: TP_ARGS(mem_entry, fd), 578: 579: TP_STRUCT__entry( 580: __field(uint64_t, gpuaddr) 581: __field(uint64_t, size) 582: __field(int, fd) 583: __field(int, type) 584: __field(unsigned int, tgid) 585: __array(char, usage, 16) 586: __field(unsigned int, id) 587: ), 588: 589: TP_fast_assign( 590: __entry->gpuaddr = mem_entry->memdesc.gpuaddr; 591: __entry->size = mem_entry->memdesc.size; 592: __entry->fd = fd; 593: __entry->type = kgsl_memdesc_usermem_type(&mem_entry->memdesc); 594: __entry->tgid = pid_nr(mem_entry->priv->pid); 595: kgsl_get_memory_usage(__entry->usage, sizeof(__entry->usage), 596: mem_entry->memdesc.flags); 597: __entry->id = mem_entry->id; 598: ), 599: 600: TP_printk( 601: "gpuaddr=0x%llx size=%llu type=%s fd=%d tgid=%u usage=%s id=%u", 602: __entry->gpuaddr, __entry->size, 603: show_memtype(__entry->type), 604: __entry->fd, __entry->tgid, 605: __entry->usage, __entry->id 606: ) 607: ); 608: 609: TRACE_EVENT(kgsl_mem_free, 610: 611: TP_PROTO(struct kgsl_mem_entry *mem_entry), 612: 613: TP_ARGS(mem_entry), 614: 615: TP_STRUCT__entry( 616: __field(uint64_t, gpuaddr) 617: __field(uint64_t, size) 618: __field(int, type) 619: __field(int, fd) 620: __field(unsigned int, tgid) 621: __array(char, usage, 16) 622: __field(unsigned int, id) 623: ), 624: 625: TP_fast_assign( 626: __entry->gpuaddr = mem_entry->memdesc.gpuaddr; 627: __entry->size = mem_entry->memdesc.size; 628: __entry->type = kgsl_memdesc_usermem_type(&mem_entry->memdesc); 629: __entry->tgid = pid_nr(mem_entry->priv->pid); 630: kgsl_get_memory_usage(__entry->usage, sizeof(__entry->usage), 631: mem_entry->memdesc.flags); 632: __entry->id = mem_entry->id; 633: ), 634: 635: TP_printk( 636: "gpuaddr=0x%llx size=%llu type=%s tgid=%u usage=%s id=%u", 637: __entry->gpuaddr, __entry->size, 638: show_memtype(__entry->type), 639: __entry->tgid, __entry->usage, __entry->id 640: ) 641: ); 642: 643: TRACE_EVENT(kgsl_mem_sync_cache, 644: 645: TP_PROTO(struct kgsl_mem_entry *mem_entry, uint64_t offset, 646: uint64_t length, unsigned int op), 647: 648: TP_ARGS(mem_entry, offset, length, op), 649: 650: TP_STRUCT__entry( 651: __field(uint64_t, gpuaddr) 652: __array(char, usage, 16) 653: __field(unsigned int, tgid) 654: __field(unsigned int, id) 655: __field(unsigned int, op) 656: __field(uint64_t, offset) 657: __field(uint64_t, length) 658: ), 659: 660: TP_fast_assign( 661: __entry->gpuaddr = mem_entry->memdesc.gpuaddr; 662: kgsl_get_memory_usage(__entry->usage, sizeof(__entry->usage), 663: mem_entry->memdesc.flags); 664: __entry->tgid = pid_nr(mem_entry->priv->pid); 665: __entry->id = mem_entry->id; 666: __entry->op = op; 667: __entry->offset = offset; 668: __entry->length = (length == 0) ? 669: mem_entry->memdesc.size : length; 670: ), 671: 672: TP_printk( 673: "gpuaddr=0x%llx size=%llu tgid=%u usage=%s id=%u op=%c%c offset=%llu", 674: __entry->gpuaddr, __entry->length, 675: __entry->tgid, __entry->usage, __entry->id, 676: (__entry->op & KGSL_GPUMEM_CACHE_CLEAN) ? 'c' : '.', 677: (__entry->op & KGSL_GPUMEM_CACHE_INV) ? 'i' : '.', 678: __entry->offset 679: ) 680: ); 681: 682: TRACE_EVENT(kgsl_mem_add_bind_range, 683: TP_PROTO(struct kgsl_mem_entry *target, u64 offset, 684: struct kgsl_mem_entry *child, u64 length), 685: 686: TP_ARGS(target, offset, child, length), 687: 688: TP_STRUCT__entry( 689: __field(u64, gpuaddr) 690: __field(u32, target) 691: __field(u32, tgid) 692: __field(u32, child) 693: __field(u64, length) 694: ), 695: 696: TP_fast_assign( 697: __entry->gpuaddr = target->memdesc.gpuaddr + offset; 698: __entry->tgid = pid_nr(target->priv->pid); 699: __entry->target = target->id; 700: __entry->child = child->id; 701: __entry->length = length; 702: ), 703: 704: TP_printk( 705: "tgid=%u target=%d gpuaddr=%llx length %llu child=%d", 706: __entry->tgid, __entry->target, __entry->gpuaddr, 707: __entry->length, __entry->child 708: ) 709: ); 710: 711: TRACE_EVENT(kgsl_mem_remove_bind_range, 712: TP_PROTO(struct kgsl_mem_entry *target, u64 offset, 713: struct kgsl_mem_entry *child, u64 length), 714: 715: TP_ARGS(target, offset, child, length), 716: 717: TP_STRUCT__entry( 718: __field(u64, gpuaddr) 719: __field(u32, target) 720: __field(u32, tgid) 721: __field(u32, child) 722: __field(u64, length) 723: ), 724: 725: TP_fast_assign( 726: __entry->gpuaddr = target->memdesc.gpuaddr + offset; 727: __entry->tgid = pid_nr(target->priv->pid); 728: __entry->target = target->id; 729: __entry->child = child->id; 730: __entry->length = length; 731: ), 732: 733: TP_printk( 734: "tgid=%u target=%d gpuaddr=%llx length %llu child=%d", 735: __entry->tgid, __entry->target, __entry->gpuaddr, 736: __entry->length, __entry->child 737: ) 738: ); 739: 740: TRACE_EVENT(kgsl_mem_sync_full_cache, 741: 742: TP_PROTO(unsigned int num_bufs, uint64_t bulk_size), 743: TP_ARGS(num_bufs, bulk_size), 744: 745: TP_STRUCT__entry( 746: __field(unsigned int, num_bufs) 747: __field(uint64_t, bulk_size) 748: ), 749: 750: TP_fast_assign( 751: __entry->num_bufs = num_bufs; 752: __entry->bulk_size = bulk_size; 753: ), 754: 755: TP_printk( 756: "num_bufs=%u bulk_size=%llu op=ci", 757: __entry->num_bufs, __entry->bulk_size 758: ) 759: ); 760: 761: DECLARE_EVENT_CLASS(kgsl_mem_timestamp_template, 762: 763: TP_PROTO(struct kgsl_device *device, struct kgsl_mem_entry *mem_entry, 764: unsigned int id, unsigned int curr_ts, unsigned int free_ts), 765: 766: TP_ARGS(device, mem_entry, id, curr_ts, free_ts), 767: 768: TP_STRUCT__entry( 769: __string(device_name, device->name) 770: __field(uint64_t, gpuaddr) 771: __field(uint64_t, size) 772: __field(int, type) 773: __array(char, usage, 16) 774: __field(unsigned int, id) 775: __field(unsigned int, drawctxt_id) 776: __field(unsigned int, curr_ts) 777: __field(unsigned int, free_ts) 778: ), 779: 780: TP_fast_assign( 781: kgsl_assign_str(device_name, device->name); 782: __entry->gpuaddr = mem_entry->memdesc.gpuaddr; 783: __entry->size = mem_entry->memdesc.size; 784: kgsl_get_memory_usage(__entry->usage, sizeof(__entry->usage), 785: mem_entry->memdesc.flags); 786: __entry->id = mem_entry->id; 787: __entry->drawctxt_id = id; 788: __entry->type = kgsl_memdesc_usermem_type(&mem_entry->memdesc); 789: __entry->curr_ts = curr_ts; 790: __entry->free_ts = free_ts; 791: ), 792: 793: TP_printk( 794: "d_name=%s gpuaddr=0x%llx size=%llu type=%s usage=%s id=%u ctx=%u curr_ts=%u free_ts=%u", 795: __get_str(device_name), 796: __entry->gpuaddr, 797: __entry->size, 798: show_memtype(__entry->type), 799: __entry->usage, 800: __entry->id, 801: __entry->drawctxt_id, 802: __entry->curr_ts, 803: __entry->free_ts 804: ) 805: ); 806: 807: DEFINE_EVENT(kgsl_mem_timestamp_template, kgsl_mem_timestamp_queue, 808: TP_PROTO(struct kgsl_device *device, struct kgsl_mem_entry *mem_entry, 809: unsigned int id, unsigned int curr_ts, unsigned int free_ts), 810: TP_ARGS(device, mem_entry, id, curr_ts, free_ts) 811: ); 812: 813: DEFINE_EVENT(kgsl_mem_timestamp_template, kgsl_mem_timestamp_free, 814: TP_PROTO(struct kgsl_device *device, struct kgsl_mem_entry *mem_entry, 815: unsigned int id, unsigned int curr_ts, unsigned int free_ts), 816: TP_ARGS(device, mem_entry, id, curr_ts, free_ts) 817: ); 818: 819: TRACE_EVENT(kgsl_context_create, 820: MATCH LINES: 1554, 1564, 1574, 1575, 1576, 1579, 1584, 1585 1542: TP_ARGS(order), 1543: TP_STRUCT__entry( 1544: __field(int, order) 1545: ), 1546: TP_fast_assign( 1547: __entry->order = order; 1548: ), 1549: TP_printk("order=%d", 1550: __entry->order 1551: ) 1552: ); 1553: 1554: TRACE_EVENT(kgsl_reclaim_memdesc, 1555: TP_PROTO( 1556: struct kgsl_mem_entry *mem_entry, 1557: bool swapout 1558: ), 1559: 1560: TP_ARGS(mem_entry, swapout 1561: ), 1562: 1563: TP_STRUCT__entry( 1564: __field(uint64_t, gpuaddr) 1565: __field(uint64_t, size) 1566: __field(unsigned int, page_count) 1567: __field(unsigned int, tgid) 1568: __field(unsigned int, id) 1569: __field(uint64_t, flags) 1570: __field(bool, swapout) 1571: ), 1572: 1573: TP_fast_assign( 1574: __entry->gpuaddr = mem_entry->memdesc.gpuaddr; 1575: __entry->size = mem_entry->memdesc.size; 1576: __entry->page_count = mem_entry->memdesc.page_count; 1577: __entry->tgid = pid_nr(mem_entry->priv->pid); 1578: __entry->id = mem_entry->id; 1579: __entry->flags = mem_entry->memdesc.flags; 1580: __entry->swapout = swapout; 1581: ), 1582: 1583: TP_printk( 1584: "gpuaddr=0x%llx size=%llu page_count=%u tgid=%u id=%u flags=0x%llx swap=%s", 1585: __entry->gpuaddr, __entry->size, __entry->page_count, __entry->tgid, 1586: __entry->id, __entry->flags, __entry->swapout ? "out" : "in" 1587: ) 1588: ); 1589: 1590: TRACE_EVENT(kgsl_reclaim_process, 1591: TP_PROTO( 1592: struct kgsl_process_private *process, 1593: u32 swap_count, 1594: bool swapout 1595: ), 1596: 1597: TP_ARGS(process, swap_count, swapout 1598: ), 1599: 1600: TP_STRUCT__entry( 1601: __field(unsigned int, pid) 1602: __field(u32, swap_count) 1603: __field(u32, unpinned_page_count) 1604: __field(bool, swapout) 1605: ), 1606: TP_fast_assign( 1607: __entry->pid = pid_nr(process->pid); 1608: __entry->swap_count = swap_count; 1609: __entry->unpinned_page_count = atomic_read(&process->unpinned_page_count); --- FILE: \kgsl_util.c | HITS: 3 --- MATCH LINES: 319 307: 308: scnprintf(entry.owner, sizeof(entry.owner), name); 309: entry.vaddr = (u64)(ptr); 310: entry.size = size; 311: ret = qcom_va_md_add_region(&entry); 312: if (ret < 0) 313: dev_err(dev, "Failed to register %s with va_minidump: %d\n", name, 314: ret); 315: 316: return ret; 317: } 318: 319: static bool include_global_in_minidump(struct kgsl_global_memdesc *md) 320: { 321: static const char * const globals[] = {"ringbuffer", "memstore", "scratch", 322: "profile", "profile_desc", "alwayson"}; 323: int i; 324: 325: for (i = 0; i < ARRAY_SIZE(globals); i++) { 326: if (!strcmp(md->name, globals[i])) 327: return true; 328: } 329: 330: return false; 331: } 332: 333: #ifdef CONFIG_QCOM_KGSL_USE_SHMEM 334: static int kgsl_add_page_pools_to_va_minidump(struct kgsl_device *device) 335: { 336: return 0; 337: } 338: #else 339: static int kgsl_add_page_pools_to_va_minidump(struct kgsl_device *device) 340: { 341: int i, ret; 342: 343: for (i = 0; i < kgsl_num_pools; i++) { MATCH LINES: 397 385: { 386: return 0; 387: } 388: #endif 389: 390: static int kgsl_add_driver_data_to_va_minidump(struct kgsl_device *device) 391: { 392: int ret; 393: char name[MAX_VA_MINIDUMP_STR_LEN]; 394: struct kgsl_pagetable *pt; 395: struct adreno_context *ctxt; 396: struct kgsl_process_private *p; 397: struct kgsl_global_memdesc *md; 398: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 399: 400: ret = kgsl_add_va_to_minidump(device->dev, KGSL_DRIVER, 401: (void *)(&kgsl_driver), sizeof(struct kgsl_driver)); 402: if (ret) 403: return ret; 404: 405: if (!ADRENO_FEATURE(adreno_dev, ADRENO_GMU_BASED_DCVS) && 406: device->pwrscale.enabled) { 407: struct msm_busmon_extended_profile bus_profile = device->pwrscale.bus_profile; 408: 409: ret = kgsl_add_va_to_minidump(device->dev, KGSL_ADRENO_TZ_DATA_ENTRY, 410: (void *)bus_profile.private_data, 411: sizeof(*bus_profile.private_data)); 412: if (ret) 413: return ret; 414: } 415: 416: ret = kgsl_add_page_pools_to_va_minidump(device); 417: if (ret) 418: return ret; 419: 420: list_for_each_entry(ctxt, &adreno_dev->active_list, active_node) { 421: snprintf(name, sizeof(name), KGSL_ADRENO_CTX_ENTRY"_%d", ctxt->base.id); MATCH LINES: 457 445: if (ret) 446: return ret; 447: 448: /* 449: * Global buffers for HWSCHED are dumped in target-specific code. Therefore, 450: * only dump the required globals for SWSCHED here. 451: */ 452: if (!adreno_dev->hwsched_enabled) { 453: list_for_each_entry(md, &device->globals, node) { 454: if (include_global_in_minidump(md)) { 455: snprintf(name, sizeof(name), "kgsl_global_%s", md->name); 456: ret = kgsl_add_va_to_minidump(device->dev, name, 457: md->memdesc.hostptr, md->memdesc.size); 458: if (ret) 459: break; 460: } 461: } 462: } 463: 464: return ret; 465: } 466: 467: static int kgsl_va_minidump_callback(struct notifier_block *nb, 468: unsigned long action, void *unused) 469: { 470: struct adreno_device *adreno_dev = ADRENO_DEVICE(kgsl_driver.devp[0]); 471: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev); 472: 473: if (kgsl_add_driver_data_to_va_minidump(kgsl_driver.devp[0])) 474: return NOTIFY_BAD; 475: 476: if (gpudev->add_to_va_minidump(adreno_dev)) 477: return NOTIFY_BAD; 478: 479: return NOTIFY_OK; 480: } 481: --- FILE: \kgsl_vbo.c | HITS: 127 --- MATCH LINES: 16, 19, 24, 26, 29, 32, 51, 60, 65, 69, 71, 78, 81, 83, 92, 95, 99, 100, 102, 104, 115, 116, 119, 124, 125, 126, 132, 135, 139, 140, 147, 154, 155, 161, 164, 173, 178, 179, 183, 193, 194, 198, 206, 212, 224, 232, 233, 237, 243, 250, 251, 256, 260, 266, 270, 273, 281, 282, 283, 293, 300, 303, 304, 321, 323, 324, 327, 328, 331, 332, 341, 342, 344, 345, 348, 349, 354, 357, 359, 362, 385, 386, 390, 399, 403 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include 8: #include 9: #include 10: #include 11: #include 12: 13: #include "kgsl_device.h" 14: #include "kgsl_mmu.h" 15: #include "kgsl_reclaim.h" 16: #include "kgsl_sharedmem.h" 17: #include "kgsl_trace.h" 18: 19: struct kgsl_memdesc_bind_range { 20: struct kgsl_mem_entry *entry; 21: struct interval_tree_node range; 22: }; 23: 24: static struct kgsl_memdesc_bind_range *bind_to_range(struct interval_tree_node *node) 25: { 26: return container_of(node, struct kgsl_memdesc_bind_range, range); 27: } 28: 29: static struct kgsl_memdesc_bind_range *bind_range_create(u64 start, u64 last, 30: struct kgsl_mem_entry *entry) 31: { 32: struct kgsl_memdesc_bind_range *range = 33: kzalloc(sizeof(*range), GFP_KERNEL); 34: 35: if (!range) 36: return ERR_PTR(-ENOMEM); 37: 38: range->range.start = start; 39: range->range.last = last; 40: range->entry = kgsl_mem_entry_get(entry); 41: 42: if (!range->entry) { 43: kfree(range); 44: return ERR_PTR(-EINVAL); 45: } 46: 47: atomic_inc(&entry->vbo_count); 48: return range; 49: } 50: 51: static void bind_range_destroy(struct kgsl_memdesc_bind_range *range) 52: { 53: struct kgsl_mem_entry *entry = range->entry; 54: 55: atomic_dec(&entry->vbo_count); 56: kgsl_mem_entry_put(entry); 57: kfree(range); 58: } 59: 60: static u64 bind_range_len(struct kgsl_memdesc_bind_range *range) 61: { 62: return (range->range.last - range->range.start) + 1; 63: } 64: 65: void kgsl_memdesc_print_vbo_ranges(struct kgsl_mem_entry *entry, 66: struct seq_file *s) 67: { 68: struct interval_tree_node *next; 69: struct kgsl_memdesc *memdesc = &entry->memdesc; 70: 71: if (!(memdesc->flags & KGSL_MEMFLAGS_VBO)) 72: return; 73: 74: /* 75: * We are called in an atomic context so try to get the mutex but if we 76: * don't then skip this item 77: */ 78: if (!mutex_trylock(&memdesc->ranges_lock)) 79: return; 80: 81: next = interval_tree_iter_first(&memdesc->ranges, 0, ~0UL); 82: while (next) { 83: struct kgsl_memdesc_bind_range *range = bind_to_range(next); 84: 85: seq_printf(s, "%5d %5d 0x%16.16lx-0x%16.16lx\n", 86: entry->id, range->entry->id, range->range.start, 87: range->range.last); 88: 89: next = interval_tree_iter_next(next, 0, ~0UL); 90: } 91: 92: mutex_unlock(&memdesc->ranges_lock); 93: } 94: 95: static void kgsl_memdesc_remove_range(struct kgsl_mem_entry *target, 96: u64 start, u64 last, struct kgsl_mem_entry *entry) 97: { 98: struct interval_tree_node *node, *next; 99: struct kgsl_memdesc_bind_range *range; 100: struct kgsl_memdesc *memdesc = &target->memdesc; 101: 102: mutex_lock(&memdesc->ranges_lock); 103: 104: next = interval_tree_iter_first(&memdesc->ranges, start, last); 105: while (next) { 106: node = next; 107: range = bind_to_range(node); 108: next = interval_tree_iter_next(node, start, last); 109: 110: /* 111: * If entry is null, consider it as a special request. Unbind 112: * the entire range between start and last in this case. 113: */ 114: if (!entry || range->entry->id == entry->id) { 115: if (kgsl_mmu_unmap_range(memdesc->pagetable, 116: memdesc, range->range.start, bind_range_len(range))) 117: continue; 118: 119: interval_tree_remove(node, &memdesc->ranges); 120: trace_kgsl_mem_remove_bind_range(target, 121: range->range.start, range->entry, 122: bind_range_len(range)); 123: 124: if (!(memdesc->flags & KGSL_MEMFLAGS_VBO_NO_MAP_ZERO)) 125: kgsl_mmu_map_zero_page_to_range(memdesc->pagetable, 126: memdesc, range->range.start, bind_range_len(range)); 127: 128: bind_range_destroy(range); 129: } 130: } 131: 132: mutex_unlock(&memdesc->ranges_lock); 133: } 134: 135: static int kgsl_memdesc_add_range(struct kgsl_mem_entry *target, 136: u64 start, u64 last, struct kgsl_mem_entry *entry, u64 offset) 137: { 138: struct interval_tree_node *node, *next; 139: struct kgsl_memdesc *memdesc = &target->memdesc; 140: struct kgsl_memdesc_bind_range *range = 141: bind_range_create(start, last, entry); 142: int ret = 0; 143: 144: if (IS_ERR(range)) 145: return PTR_ERR(range); 146: 147: mutex_lock(&memdesc->ranges_lock); 148: 149: /* 150: * If the VBO maps the zero page, then we can unmap the requested range 151: * in one call. Otherwise we have to figure out what ranges to unmap 152: * while walking the interval tree. 153: */ 154: if (!(memdesc->flags & KGSL_MEMFLAGS_VBO_NO_MAP_ZERO)) { 155: ret = kgsl_mmu_unmap_range(memdesc->pagetable, memdesc, start, 156: last - start + 1); 157: if (ret) 158: goto error; 159: } 160: 161: next = interval_tree_iter_first(&memdesc->ranges, start, last); 162: 163: while (next) { 164: struct kgsl_memdesc_bind_range *cur; 165: 166: node = next; 167: cur = bind_to_range(node); 168: next = interval_tree_iter_next(node, start, last); 169: 170: trace_kgsl_mem_remove_bind_range(target, cur->range.start, 171: cur->entry, bind_range_len(cur)); 172: 173: interval_tree_remove(node, &memdesc->ranges); 174: 175: if (start <= cur->range.start) { 176: if (last >= cur->range.last) { 177: /* Unmap the entire cur range */ 178: if (memdesc->flags & KGSL_MEMFLAGS_VBO_NO_MAP_ZERO) { 179: ret = kgsl_mmu_unmap_range(memdesc->pagetable, memdesc, 180: cur->range.start, 181: cur->range.last - cur->range.start + 1); 182: if (ret) { 183: interval_tree_insert(node, &memdesc->ranges); 184: goto error; 185: } 186: } 187: 188: bind_range_destroy(cur); 189: continue; 190: } 191: 192: /* Unmap the range overlapping cur */ 193: if (memdesc->flags & KGSL_MEMFLAGS_VBO_NO_MAP_ZERO) { 194: ret = kgsl_mmu_unmap_range(memdesc->pagetable, memdesc, 195: cur->range.start, 196: last - cur->range.start + 1); 197: if (ret) { 198: interval_tree_insert(node, &memdesc->ranges); 199: goto error; 200: } 201: } 202: 203: /* Adjust the start of the mapping */ 204: cur->range.start = last + 1; 205: /* And put it back into the tree */ 206: interval_tree_insert(node, &memdesc->ranges); 207: 208: trace_kgsl_mem_add_bind_range(target, 209: cur->range.start, cur->entry, bind_range_len(cur)); 210: } else { 211: if (last < cur->range.last) { 212: struct kgsl_memdesc_bind_range *temp; 213: 214: /* 215: * The range is split into two so make a new 216: * entry for the far side 217: */ 218: temp = bind_range_create(last + 1, cur->range.last, 219: cur->entry); 220: /* FIXME: Uhoh, this would be bad */ 221: BUG_ON(IS_ERR(temp)); 222: 223: interval_tree_insert(&temp->range, 224: &memdesc->ranges); 225: 226: trace_kgsl_mem_add_bind_range(target, 227: temp->range.start, 228: temp->entry, bind_range_len(temp)); 229: } 230: 231: /* Unmap the range overlapping cur */ 232: if (memdesc->flags & KGSL_MEMFLAGS_VBO_NO_MAP_ZERO) { 233: ret = kgsl_mmu_unmap_range(memdesc->pagetable, memdesc, 234: start, 235: min_t(u64, cur->range.last, last) - start + 1); 236: if (ret) { 237: interval_tree_insert(node, &memdesc->ranges); 238: goto error; 239: } 240: } 241: 242: cur->range.last = start - 1; 243: interval_tree_insert(node, &memdesc->ranges); 244: 245: trace_kgsl_mem_add_bind_range(target, cur->range.start, 246: cur->entry, bind_range_len(cur)); 247: } 248: } 249: 250: ret = kgsl_mmu_map_child(memdesc->pagetable, memdesc, start, 251: &entry->memdesc, offset, last - start + 1); 252: if (ret) 253: goto error; 254: 255: /* Add the new range */ 256: interval_tree_insert(&range->range, &memdesc->ranges); 257: 258: trace_kgsl_mem_add_bind_range(target, range->range.start, 259: range->entry, bind_range_len(range)); 260: mutex_unlock(&memdesc->ranges_lock); 261: 262: return ret; 263: 264: error: 265: bind_range_destroy(range); 266: mutex_unlock(&memdesc->ranges_lock); 267: return ret; 268: } 269: 270: static void kgsl_sharedmem_vbo_put_gpuaddr(struct kgsl_memdesc *memdesc) 271: { 272: struct interval_tree_node *node, *next; 273: struct kgsl_memdesc_bind_range *range; 274: int ret = 0; 275: bool unmap_fail; 276: 277: /* 278: * If the VBO maps the zero range then we can unmap the entire 279: * pagetable region in one call. 280: */ 281: if (!(memdesc->flags & KGSL_MEMFLAGS_VBO_NO_MAP_ZERO)) 282: ret = kgsl_mmu_unmap_range(memdesc->pagetable, memdesc, 283: 0, memdesc->size); 284: 285: unmap_fail = ret; 286: 287: /* 288: * FIXME: do we have a use after free potential here? We might need to 289: * lock this and set a "do not update" bit 290: */ 291: 292: /* Now delete each range and release the mem entries */ 293: next = interval_tree_iter_first(&memdesc->ranges, 0, ~0UL); 294: 295: while (next) { 296: node = next; 297: range = bind_to_range(node); 298: next = interval_tree_iter_next(node, 0, ~0UL); 299: 300: interval_tree_remove(node, &memdesc->ranges); 301: 302: /* Unmap this range */ 303: if (memdesc->flags & KGSL_MEMFLAGS_VBO_NO_MAP_ZERO) 304: ret = kgsl_mmu_unmap_range(memdesc->pagetable, memdesc, 305: range->range.start, 306: range->range.last - range->range.start + 1); 307: 308: /* Put the child's refcount if unmap succeeds */ 309: if (!ret) 310: bind_range_destroy(range); 311: else 312: kfree(range); 313: 314: unmap_fail = unmap_fail || ret; 315: } 316: 317: if (unmap_fail) 318: return; 319: 320: /* Put back the GPU address */ 321: kgsl_mmu_put_gpuaddr(memdesc->pagetable, memdesc); 322: 323: memdesc->gpuaddr = 0; 324: memdesc->pagetable = NULL; 325: } 326: 327: static struct kgsl_memdesc_ops kgsl_vbo_ops = { 328: .put_gpuaddr = kgsl_sharedmem_vbo_put_gpuaddr, 329: }; 330: 331: int kgsl_sharedmem_allocate_vbo(struct kgsl_device *device, 332: struct kgsl_memdesc *memdesc, u64 size, u64 flags) 333: { 334: size = PAGE_ALIGN(size); 335: 336: /* Make sure that VBOs are supported by the MMU */ 337: if (WARN_ON_ONCE(!kgsl_mmu_has_feature(device, 338: KGSL_MMU_SUPPORT_VBO))) 339: return -EOPNOTSUPP; 340: 341: kgsl_memdesc_init(device, memdesc, flags); 342: atomic_set(&memdesc->priv, 0); 343: 344: memdesc->ops = &kgsl_vbo_ops; 345: memdesc->size = size; 346: 347: /* Set up the interval tree and lock */ 348: memdesc->ranges = RB_ROOT_CACHED; 349: mutex_init(&memdesc->ranges_lock); 350: 351: return 0; 352: } 353: 354: static bool kgsl_memdesc_check_range(struct kgsl_memdesc *memdesc, 355: u64 offset, u64 length) 356: { 357: return ((offset < memdesc->size) && 358: (offset + length > offset) && 359: (offset + length) <= memdesc->size); 360: } 361: 362: static void kgsl_sharedmem_free_bind_op(struct kgsl_sharedmem_bind_op *op) 363: { 364: int i; 365: 366: if (IS_ERR_OR_NULL(op)) 367: return; 368: 369: for (i = 0; i < op->nr_ops; i++) { 370: /* Decrement the vbo_count we added when creating the bind_op */ 371: if (op->ops[i].entry) 372: atomic_dec(&op->ops[i].entry->vbo_count); 373: 374: /* Release the reference on the child entry */ 375: kgsl_mem_entry_put_deferred(op->ops[i].entry); 376: } 377: 378: /* Release the reference on the target entry */ 379: kgsl_mem_entry_put_deferred(op->target); 380: 381: kvfree(op->ops); 382: kfree(op); 383: } 384: 385: struct kgsl_sharedmem_bind_op * 386: kgsl_sharedmem_create_bind_op(struct kgsl_process_private *private, 387: u32 target_id, void __user *ranges, u32 ranges_nents, 388: u64 ranges_size) 389: { 390: struct kgsl_sharedmem_bind_op *op; 391: struct kgsl_mem_entry *target; 392: int ret, i; 393: 394: /* There must be at least one defined operation */ 395: if (!ranges_nents) 396: return ERR_PTR(-EINVAL); 397: 398: /* Find the target memory entry */ 399: target = kgsl_sharedmem_find_id(private, target_id); 400: if (!target) 401: return ERR_PTR(-ENOENT); 402: 403: if (!(target->memdesc.flags & KGSL_MEMFLAGS_VBO)) { 404: kgsl_mem_entry_put(target); 405: return ERR_PTR(-EINVAL); 406: } 407: 408: /* Make a container for the bind operations */ 409: op = kzalloc(sizeof(*op), GFP_KERNEL); 410: if (!op) { 411: kgsl_mem_entry_put(target); 412: return ERR_PTR(-ENOMEM); 413: } 414: 415: /* 416: * Make an array for the individual operations. Use __GFP_NOWARN and 417: * __GFP_NORETRY to make sure a very large request quietly fails 418: */ 419: op->ops = kvcalloc(ranges_nents, sizeof(*op->ops), 420: GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY); 421: if (!op->ops) { 422: kfree(op); 423: kgsl_mem_entry_put(target); 424: return ERR_PTR(-ENOMEM); 425: } 426: 427: op->nr_ops = ranges_nents; MATCH LINES: 459, 481, 493, 502, 503, 518, 544, 548, 550, 551, 553, 556, 558, 559, 570, 576, 590, 593, 598, 602, 606, 611, 621, 622, 624, 629, 631, 637, 643, 644, 646, 656, 685, 699, 706, 709, 712, 717, 721, 724, 733, 736 447: goto err; 448: } 449: 450: /* The offset must be page aligned */ 451: if (!PAGE_ALIGNED(range.target_offset)) 452: goto err; 453: 454: /* The length of the operation must be aligned and non zero */ 455: if (!range.length || !PAGE_ALIGNED(range.length)) 456: goto err; 457: 458: /* Make sure the range fits in the target */ 459: if (!kgsl_memdesc_check_range(&target->memdesc, 460: range.target_offset, range.length)) 461: goto err; 462: 463: /* 464: * Special case: Consider child id 0 as a special request incase of 465: * unbind. This helps to unbind the specified range (could span multiple 466: * child buffers) without supplying backing physical buffer information. 467: */ 468: if (range.child_id == 0 && range.op == KGSL_GPUMEM_RANGE_OP_UNBIND) { 469: op->ops[i].entry = NULL; 470: op->ops[i].start = range.target_offset; 471: op->ops[i].last = range.target_offset + range.length - 1; 472: /* Child offset doesn't matter for unbind. set it to 0 */ 473: op->ops[i].child_offset = 0; 474: op->ops[i].op = range.op; 475: 476: ranges += ranges_size; 477: continue; 478: } 479: 480: /* Get the child object */ 481: op->ops[i].entry = kgsl_sharedmem_find_id(private, 482: range.child_id); 483: entry = op->ops[i].entry; 484: if (!entry) { 485: ret = -ENOENT; 486: goto err; 487: } 488: 489: /* Keep the child pinned in memory */ 490: atomic_inc(&entry->vbo_count); 491: 492: /* Make sure the child is not a VBO */ 493: if ((entry->memdesc.flags & KGSL_MEMFLAGS_VBO)) { 494: ret = -EINVAL; 495: goto err; 496: } 497: 498: /* 499: * Make sure that only secure children are mapped in secure VBOs 500: * and vice versa 501: */ 502: if ((target->memdesc.flags & KGSL_MEMFLAGS_SECURE) != 503: (entry->memdesc.flags & KGSL_MEMFLAGS_SECURE)) { 504: ret = -EPERM; 505: goto err; 506: } 507: 508: /* Make sure the range operation is valid */ 509: if (range.op != KGSL_GPUMEM_RANGE_OP_BIND && 510: range.op != KGSL_GPUMEM_RANGE_OP_UNBIND) 511: goto err; 512: 513: if (range.op == KGSL_GPUMEM_RANGE_OP_BIND) { 514: if (!PAGE_ALIGNED(range.child_offset)) 515: goto err; 516: 517: /* Make sure the range fits in the child */ 518: if (!kgsl_memdesc_check_range(&entry->memdesc, 519: range.child_offset, range.length)) 520: goto err; 521: } else { 522: /* For unop operations the child offset must be 0 */ 523: if (range.child_offset) 524: goto err; 525: } 526: 527: op->ops[i].entry = entry; 528: op->ops[i].start = range.target_offset; 529: op->ops[i].last = range.target_offset + range.length - 1; 530: op->ops[i].child_offset = range.child_offset; 531: op->ops[i].op = range.op; 532: 533: ranges += ranges_size; 534: } 535: 536: atomic_dec(&private->cmd_count); 537: init_completion(&op->comp); 538: kref_init(&op->ref); 539: 540: return op; 541: 542: err: 543: atomic_dec(&private->cmd_count); 544: kgsl_sharedmem_free_bind_op(op); 545: return ERR_PTR(ret); 546: } 547: 548: void kgsl_sharedmem_bind_range_destroy(struct kref *kref) 549: { 550: struct kgsl_sharedmem_bind_op *op = container_of(kref, 551: struct kgsl_sharedmem_bind_op, ref); 552: 553: kgsl_sharedmem_free_bind_op(op); 554: } 555: 556: static void kgsl_sharedmem_bind_worker(struct work_struct *work) 557: { 558: struct kgsl_sharedmem_bind_op *op = container_of(work, 559: struct kgsl_sharedmem_bind_op, work); 560: int i; 561: 562: for (i = 0; i < op->nr_ops; i++) { 563: if (op->ops[i].op == KGSL_GPUMEM_RANGE_OP_BIND) { 564: spin_lock(&op->ops[i].entry->priv->mem_lock); 565: if (op->ops[i].entry->pending_free) { 566: spin_unlock(&op->ops[i].entry->priv->mem_lock); 567: continue; 568: } 569: spin_unlock(&op->ops[i].entry->priv->mem_lock); 570: kgsl_memdesc_add_range(op->target, 571: op->ops[i].start, 572: op->ops[i].last, 573: op->ops[i].entry, 574: op->ops[i].child_offset); 575: } else { 576: kgsl_memdesc_remove_range(op->target, 577: op->ops[i].start, 578: op->ops[i].last, 579: op->ops[i].entry); 580: } 581: } 582: 583: /* Wake up any threads waiting for the bind operation */ 584: complete_all(&op->comp); 585: 586: if (op->callback) 587: op->callback(op); 588: 589: /* Put the refcount we took when scheduling the worker */ 590: kgsl_sharedmem_put_bind_op(op); 591: } 592: 593: void kgsl_sharedmem_bind_ranges(struct kgsl_sharedmem_bind_op *op) 594: { 595: /* Take a reference to the operation while it is scheduled */ 596: kref_get(&op->ref); 597: 598: INIT_WORK(&op->work, kgsl_sharedmem_bind_worker); 599: schedule_work(&op->work); 600: } 601: 602: struct kgsl_sharedmem_bind_fence { 603: struct dma_fence base; 604: spinlock_t lock; 605: int fd; 606: struct kgsl_sharedmem_bind_op *op; 607: }; 608: 609: static const char *bind_fence_get_driver_name(struct dma_fence *fence) 610: { 611: return "kgsl_sharedmem_bind"; 612: } 613: 614: static const char *bind_fence_get_timeline_name(struct dma_fence *fence) 615: { 616: return "(unbound)"; 617: } 618: 619: static void bind_fence_release(struct dma_fence *fence) 620: { 621: struct kgsl_sharedmem_bind_fence *bind_fence = container_of(fence, 622: struct kgsl_sharedmem_bind_fence, base); 623: 624: kgsl_sharedmem_put_bind_op(bind_fence->op); 625: kfree(bind_fence); 626: } 627: 628: static void 629: kgsl_sharedmem_bind_fence_callback(struct kgsl_sharedmem_bind_op *op) 630: { 631: struct kgsl_sharedmem_bind_fence *bind_fence = op->data; 632: 633: dma_fence_signal(&bind_fence->base); 634: dma_fence_put(&bind_fence->base); 635: } 636: 637: static const struct dma_fence_ops kgsl_sharedmem_bind_fence_ops = { 638: .get_driver_name = bind_fence_get_driver_name, 639: .get_timeline_name = bind_fence_get_timeline_name, 640: .release = bind_fence_release, 641: }; 642: 643: static struct kgsl_sharedmem_bind_fence * 644: kgsl_sharedmem_bind_fence(struct kgsl_sharedmem_bind_op *op) 645: { 646: struct kgsl_sharedmem_bind_fence *fence; 647: struct sync_file *sync_file; 648: int fd; 649: 650: fence = kzalloc(sizeof(*fence), GFP_KERNEL); 651: if (!fence) 652: return ERR_PTR(-ENOMEM); 653: 654: spin_lock_init(&fence->lock); 655: 656: dma_fence_init(&fence->base, &kgsl_sharedmem_bind_fence_ops, 657: &fence->lock, dma_fence_context_alloc(1), 0); 658: 659: fd = get_unused_fd_flags(O_CLOEXEC); 660: if (fd < 0) { 661: kfree(fence); 662: return ERR_PTR(fd); 663: } 664: 665: sync_file = sync_file_create(&fence->base); 666: if (!sync_file) { 667: put_unused_fd(fd); 668: kfree(fence); 669: return ERR_PTR(-ENOMEM); 670: } 671: 672: fd_install(fd, sync_file->file); 673: 674: fence->fd = fd; 675: fence->op = op; 676: 677: return fence; 678: } 679: 680: long kgsl_ioctl_gpumem_bind_ranges(struct kgsl_device_private *dev_priv, 681: unsigned int cmd, void *data) 682: { 683: struct kgsl_process_private *private = dev_priv->process_priv; 684: struct kgsl_gpumem_bind_ranges *param = data; 685: struct kgsl_sharedmem_bind_op *op; 686: int ret; 687: 688: /* If ranges_size isn't set, return the expected size to the user */ 689: if (!param->ranges_size) { 690: param->ranges_size = sizeof(struct kgsl_gpumem_bind_range); 691: return 0; 692: } 693: 694: /* FENCE_OUT only makes sense with ASYNC */ 695: if ((param->flags & KGSL_GPUMEM_BIND_FENCE_OUT) && 696: !(param->flags & KGSL_GPUMEM_BIND_ASYNC)) 697: return -EINVAL; 698: 699: op = kgsl_sharedmem_create_bind_op(private, param->id, 700: u64_to_user_ptr(param->ranges), param->ranges_nents, 701: param->ranges_size); 702: if (IS_ERR(op)) 703: return PTR_ERR(op); 704: 705: if (param->flags & KGSL_GPUMEM_BIND_ASYNC) { 706: struct kgsl_sharedmem_bind_fence *fence; 707: 708: if (param->flags & KGSL_GPUMEM_BIND_FENCE_OUT) { 709: fence = kgsl_sharedmem_bind_fence(op); 710: 711: if (IS_ERR(fence)) { 712: kgsl_sharedmem_put_bind_op(op); 713: return PTR_ERR(fence); 714: } 715: 716: op->data = fence; 717: op->callback = kgsl_sharedmem_bind_fence_callback; 718: param->fence_id = fence->fd; 719: } 720: 721: kgsl_sharedmem_bind_ranges(op); 722: 723: if (!(param->flags & KGSL_GPUMEM_BIND_FENCE_OUT)) 724: kgsl_sharedmem_put_bind_op(op); 725: 726: return 0; 727: } 728: 729: /* 730: * Schedule the work. All the resources will be released after 731: * the bind operation is done 732: */ 733: kgsl_sharedmem_bind_ranges(op); 734: 735: ret = wait_for_completion_interruptible(&op->comp); 736: kgsl_sharedmem_put_bind_op(op); 737: 738: return ret; 739: } --- FILE: \include\uapi\linux\msm_kgsl.h | HITS: 58 --- MATCH LINES: 215, 216 203: /* 204: * ION type is retained for backward compatibility but ION buffers are 205: * dma-bufs so try to use that naming if we can 206: */ 207: KGSL_USER_MEM_TYPE_DMABUF = 0x00000003, 208: KGSL_USER_MEM_TYPE_MAX = 0x00000007, 209: }; 210: #define KGSL_MEMFLAGS_USERMEM_MASK 0x000000e0 211: #define KGSL_MEMFLAGS_USERMEM_SHIFT 5 212: 213: /* 214: * Unfortunately, enum kgsl_user_mem_type starts at 0 which does not 215: * leave a good value for allocated memory. In the flags we use 216: * 0 to indicate allocated memory and thus need to add 1 to the enum 217: * values. 218: */ 219: #define KGSL_USERMEM_FLAG(x) (((x) + 1) << KGSL_MEMFLAGS_USERMEM_SHIFT) 220: 221: #define KGSL_MEMFLAGS_NOT_USERMEM 0 222: #define KGSL_MEMFLAGS_USERMEM_PMEM KGSL_USERMEM_FLAG(KGSL_USER_MEM_TYPE_PMEM) 223: #define KGSL_MEMFLAGS_USERMEM_ASHMEM \ 224: KGSL_USERMEM_FLAG(KGSL_USER_MEM_TYPE_ASHMEM) 225: #define KGSL_MEMFLAGS_USERMEM_ADDR KGSL_USERMEM_FLAG(KGSL_USER_MEM_TYPE_ADDR) 226: #define KGSL_MEMFLAGS_USERMEM_ION KGSL_USERMEM_FLAG(KGSL_USER_MEM_TYPE_ION) 227: 228: /* --- generic KGSL flag values --- */ 229: 230: #define KGSL_FLAGS_NORMALMODE 0x00000000 231: #define KGSL_FLAGS_SAFEMODE 0x00000001 232: #define KGSL_FLAGS_INITIALIZED0 0x00000002 233: #define KGSL_FLAGS_INITIALIZED 0x00000004 234: #define KGSL_FLAGS_STARTED 0x00000008 235: #define KGSL_FLAGS_ACTIVE 0x00000010 236: #define KGSL_FLAGS_RESERVED0 0x00000020 237: #define KGSL_FLAGS_RESERVED1 0x00000040 238: #define KGSL_FLAGS_RESERVED2 0x00000080 239: #define KGSL_FLAGS_SOFT_RESET 0x00000100 240: #define KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS 0x00000200 MATCH LINES: 402, 408, 413 390: * kgsl_capabilities allows the user to query kernel capabilities. The 'data' 391: * type should be set appropriately for the querytype (see above). Pass 0 to 392: * 'size' and the kernel will set it to the expected size of 'data' that is 393: * appropriate for querytype (in bytes). 394: */ 395: struct kgsl_capabilities { 396: __u64 data; 397: __u64 size; 398: __u32 querytype; 399: }; 400: 401: struct kgsl_shadowprop { 402: unsigned long gpuaddr; 403: __kernel_size_t size; 404: unsigned int flags; /* contains KGSL_FLAGS_ values */ 405: }; 406: 407: struct kgsl_qdss_stm_prop { 408: __u64 gpuaddr; 409: __u64 size; 410: }; 411: 412: struct kgsl_qtimer_prop { 413: __u64 gpuaddr; 414: __u64 size; 415: }; 416: 417: struct kgsl_version { 418: unsigned int drv_major; 419: unsigned int drv_minor; 420: unsigned int dev_major; 421: unsigned int dev_minor; 422: }; 423: 424: struct kgsl_sp_generic_mem { 425: __u64 local; 426: __u64 pvt; 427: }; 428: 429: struct kgsl_ucode_version { 430: unsigned int pfp; 431: unsigned int pm4; 432: }; 433: 434: struct kgsl_gpmu_version { 435: unsigned int major; 436: unsigned int minor; 437: unsigned int features; MATCH LINES: 525 513: #define KGSL_PERFCOUNTER_GROUP_BV_RAS 0x34 514: #define KGSL_PERFCOUNTER_GROUP_BV_LRZ 0x35 515: #define KGSL_PERFCOUNTER_GROUP_BV_HLSQ 0x36 516: #define KGSL_PERFCOUNTER_GROUP_BV_CCU 0x37 517: #define KGSL_PERFCOUNTER_GROUP_BV_RB 0x38 518: #define KGSL_PERFCOUNTER_GROUP_MAX 0x39 519: 520: #define KGSL_PERFCOUNTER_NOT_USED 0xFFFFFFFF 521: #define KGSL_PERFCOUNTER_BROKEN 0xFFFFFFFE 522: 523: /* structure holds list of ibs */ 524: struct kgsl_ibdesc { 525: unsigned long gpuaddr; 526: unsigned long __pad; 527: __kernel_size_t sizedwords; 528: unsigned int ctrl; 529: }; 530: 531: /** 532: * struct kgsl_cmdbatch_profiling_buffer 533: * @wall_clock_s: Ringbuffer submission time (seconds). 534: * If KGSL_CMDBATCH_PROFILING_KTIME is set, time is provided 535: * in kernel clocks, otherwise wall clock time is used. 536: * @wall_clock_ns: Ringbuffer submission time (nanoseconds). 537: * If KGSL_CMDBATCH_PROFILING_KTIME is set time is provided 538: * in kernel clocks, otherwise wall clock time is used. 539: * @gpu_ticks_queued: GPU ticks at ringbuffer submission 540: * @gpu_ticks_submitted: GPU ticks when starting cmdbatch execution 541: * @gpu_ticks_retired: GPU ticks when finishing cmdbatch execution 542: * 543: * This structure defines the profiling buffer used to measure cmdbatch 544: * execution time 545: */ 546: struct kgsl_cmdbatch_profiling_buffer { 547: __u64 wall_clock_s; 548: __u64 wall_clock_ns; 549: __u64 gpu_ticks_queued; MATCH LINES: 603, 637, 638, 639, 642, 643, 648, 649, 653, 658, 659, 686, 706, 708, 713, 715, 718, 720, 725, 726, 729, 730, 733, 734, 759, 781, 785, 786, 791, 792, 802, 803, 833, 842 591: struct kgsl_device_waittimestamp_ctxtid { 592: unsigned int context_id; 593: unsigned int timestamp; 594: unsigned int timeout; 595: }; 596: 597: #define IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID \ 598: _IOW(KGSL_IOC_TYPE, 0x7, struct kgsl_device_waittimestamp_ctxtid) 599: 600: /* DEPRECATED: issue indirect commands to the GPU. 601: * drawctxt_id must have been created with IOCTL_KGSL_DRAWCTXT_CREATE 602: * ibaddr and sizedwords must specify a subset of a buffer created 603: * with IOCTL_KGSL_SHAREDMEM_FROM_PMEM 604: * flags may be a mask of KGSL_CONTEXT_ values 605: * timestamp is a returned counter value which can be passed to 606: * other ioctls to determine when the commands have been executed by 607: * the GPU. 608: * 609: * This function is deprecated - consider using IOCTL_KGSL_SUBMIT_COMMANDS 610: * instead 611: */ 612: struct kgsl_ringbuffer_issueibcmds { 613: unsigned int drawctxt_id; 614: unsigned long ibdesc_addr; 615: unsigned int numibs; 616: unsigned int timestamp; /*output param */ 617: unsigned int flags; 618: }; 619: 620: #define IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS \ 621: _IOWR(KGSL_IOC_TYPE, 0x10, struct kgsl_ringbuffer_issueibcmds) 622: 623: /* read the most recently executed timestamp value 624: * type should be a value from enum kgsl_timestamp_type 625: */ 626: struct kgsl_cmdstream_readtimestamp { 627: unsigned int type; 628: unsigned int timestamp; /*output param */ 629: }; 630: 631: #define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_OLD \ 632: _IOR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp) 633: 634: #define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP \ 635: _IOWR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp) 636: 637: /* free memory when the GPU reaches a given timestamp. 638: * gpuaddr specify a memory region created by a 639: * IOCTL_KGSL_SHAREDMEM_FROM_PMEM call 640: * type should be a value from enum kgsl_timestamp_type 641: */ 642: struct kgsl_cmdstream_freememontimestamp { 643: unsigned long gpuaddr; 644: unsigned int type; 645: unsigned int timestamp; 646: }; 647: 648: #define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP \ 649: _IOW(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp) 650: 651: /* 652: * Previous versions of this header had incorrectly defined 653: * IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP as a read-only ioctl instead 654: * of a write only ioctl. To ensure binary compatibility, the following 655: * #define will be used to intercept the incorrect ioctl 656: */ 657: 658: #define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_OLD \ 659: _IOR(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp) 660: 661: /* create a draw context, which is used to preserve GPU state. 662: * The flags field may contain a mask KGSL_CONTEXT_* values 663: */ 664: struct kgsl_drawctxt_create { 665: unsigned int flags; 666: unsigned int drawctxt_id; /*output param */ 667: }; 668: 669: #define IOCTL_KGSL_DRAWCTXT_CREATE \ 670: _IOWR(KGSL_IOC_TYPE, 0x13, struct kgsl_drawctxt_create) 671: 672: /* destroy a draw context */ 673: struct kgsl_drawctxt_destroy { 674: unsigned int drawctxt_id; 675: }; 676: 677: #define IOCTL_KGSL_DRAWCTXT_DESTROY \ 678: _IOW(KGSL_IOC_TYPE, 0x14, struct kgsl_drawctxt_destroy) 679: 680: /* 681: * add a block of pmem, fb, ashmem or user allocated address 682: * into the GPU address space 683: */ 684: struct kgsl_map_user_mem { 685: int fd; 686: unsigned long gpuaddr; /*output param */ 687: __kernel_size_t len; 688: __kernel_size_t offset; 689: unsigned long hostptr; /*input param */ 690: enum kgsl_user_mem_type memtype; 691: unsigned int flags; 692: }; 693: 694: #define IOCTL_KGSL_MAP_USER_MEM \ 695: _IOWR(KGSL_IOC_TYPE, 0x15, struct kgsl_map_user_mem) 696: 697: struct kgsl_cmdstream_readtimestamp_ctxtid { 698: unsigned int context_id; 699: unsigned int type; 700: unsigned int timestamp; /*output param */ 701: }; 702: 703: #define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID \ 704: _IOWR(KGSL_IOC_TYPE, 0x16, struct kgsl_cmdstream_readtimestamp_ctxtid) 705: 706: struct kgsl_cmdstream_freememontimestamp_ctxtid { 707: unsigned int context_id; 708: unsigned long gpuaddr; 709: unsigned int type; 710: unsigned int timestamp; 711: }; 712: 713: #define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID \ 714: _IOW(KGSL_IOC_TYPE, 0x17, \ 715: struct kgsl_cmdstream_freememontimestamp_ctxtid) 716: 717: /* add a block of pmem or fb into the GPU address space */ 718: struct kgsl_sharedmem_from_pmem { 719: int pmem_fd; 720: unsigned long gpuaddr; /*output param */ 721: unsigned int len; 722: unsigned int offset; 723: }; 724: 725: #define IOCTL_KGSL_SHAREDMEM_FROM_PMEM \ 726: _IOWR(KGSL_IOC_TYPE, 0x20, struct kgsl_sharedmem_from_pmem) 727: 728: /* remove memory from the GPU's address space */ 729: struct kgsl_sharedmem_free { 730: unsigned long gpuaddr; 731: }; 732: 733: #define IOCTL_KGSL_SHAREDMEM_FREE \ 734: _IOW(KGSL_IOC_TYPE, 0x21, struct kgsl_sharedmem_free) 735: 736: struct kgsl_cff_user_event { 737: unsigned char cff_opcode; 738: unsigned int op1; 739: unsigned int op2; 740: unsigned int op3; 741: unsigned int op4; 742: unsigned int op5; 743: unsigned int __pad[2]; 744: }; 745: 746: #define IOCTL_KGSL_CFF_USER_EVENT \ 747: _IOW(KGSL_IOC_TYPE, 0x31, struct kgsl_cff_user_event) 748: 749: struct kgsl_gmem_desc { 750: unsigned int x; 751: unsigned int y; 752: unsigned int width; 753: unsigned int height; 754: unsigned int pitch; 755: }; 756: 757: struct kgsl_buffer_desc { 758: void *hostptr; 759: unsigned long gpuaddr; 760: int size; 761: unsigned int format; 762: unsigned int pitch; 763: unsigned int enabled; 764: }; 765: 766: struct kgsl_bind_gmem_shadow { 767: unsigned int drawctxt_id; 768: struct kgsl_gmem_desc gmem_desc; 769: unsigned int shadow_x; 770: unsigned int shadow_y; 771: struct kgsl_buffer_desc shadow_buffer; 772: unsigned int buffer_id; 773: }; 774: 775: #define IOCTL_KGSL_DRAWCTXT_BIND_GMEM_SHADOW \ 776: _IOW(KGSL_IOC_TYPE, 0x22, struct kgsl_bind_gmem_shadow) 777: 778: /* add a block of memory into the GPU address space */ 779: 780: /* 781: * IOCTL_KGSL_SHAREDMEM_FROM_VMALLOC deprecated 09/2012 782: * use IOCTL_KGSL_GPUMEM_ALLOC instead 783: */ 784: 785: struct kgsl_sharedmem_from_vmalloc { 786: unsigned long gpuaddr; /*output param */ 787: unsigned int hostptr; 788: unsigned int flags; 789: }; 790: 791: #define IOCTL_KGSL_SHAREDMEM_FROM_VMALLOC \ 792: _IOWR(KGSL_IOC_TYPE, 0x23, struct kgsl_sharedmem_from_vmalloc) 793: 794: /* 795: * This is being deprecated in favor of IOCTL_KGSL_GPUMEM_CACHE_SYNC which 796: * supports both directions (flush and invalidate). This code will still 797: * work, but by definition it will do a flush of the cache which might not be 798: * what you want to have happen on a buffer following a GPU operation. It is 799: * safer to go with IOCTL_KGSL_GPUMEM_CACHE_SYNC 800: */ 801: 802: #define IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE \ 803: _IOW(KGSL_IOC_TYPE, 0x24, struct kgsl_sharedmem_free) 804: 805: struct kgsl_drawctxt_set_bin_base_offset { 806: unsigned int drawctxt_id; 807: unsigned int offset; 808: }; 809: 810: #define IOCTL_KGSL_DRAWCTXT_SET_BIN_BASE_OFFSET \ 811: _IOW(KGSL_IOC_TYPE, 0x25, struct kgsl_drawctxt_set_bin_base_offset) 812: 813: enum kgsl_cmdwindow_type { 814: KGSL_CMDWINDOW_MIN = 0x00000000, 815: KGSL_CMDWINDOW_2D = 0x00000000, 816: KGSL_CMDWINDOW_3D = 0x00000001, /* legacy */ 817: KGSL_CMDWINDOW_MMU = 0x00000002, 818: KGSL_CMDWINDOW_ARBITER = 0x000000FF, 819: KGSL_CMDWINDOW_MAX = 0x000000FF, 820: }; 821: 822: /* write to the command window */ 823: struct kgsl_cmdwindow_write { 824: enum kgsl_cmdwindow_type target; 825: unsigned int addr; 826: unsigned int data; 827: }; 828: 829: #define IOCTL_KGSL_CMDWINDOW_WRITE \ 830: _IOW(KGSL_IOC_TYPE, 0x2e, struct kgsl_cmdwindow_write) 831: 832: struct kgsl_gpumem_alloc { 833: unsigned long gpuaddr; /* output param */ 834: __kernel_size_t size; 835: unsigned int flags; 836: }; 837: 838: #define IOCTL_KGSL_GPUMEM_ALLOC \ 839: _IOWR(KGSL_IOC_TYPE, 0x2f, struct kgsl_gpumem_alloc) 840: 841: struct kgsl_cff_syncmem { 842: unsigned long gpuaddr; 843: __kernel_size_t len; 844: unsigned int __pad[2]; /* For future binary compatibility */ 845: }; 846: 847: #define IOCTL_KGSL_CFF_SYNCMEM \ 848: _IOW(KGSL_IOC_TYPE, 0x30, struct kgsl_cff_syncmem) 849: 850: /* 851: * A timestamp event allows the user space to register an action following an 852: * expired timestamp. Note IOCTL_KGSL_TIMESTAMP_EVENT has been redefined to 853: * _IOWR to support fences which need to return a fd for the priv parameter. 854: */ 855: 856: struct kgsl_timestamp_event { 857: int type; /* Type of event (see list below) */ 858: unsigned int timestamp; /* Timestamp to trigger event on */ 859: unsigned int context_id; /* Context for the timestamp */ 860: void __user *priv; /* Pointer to the event specific blob */ 861: __kernel_size_t len; /* Size of the event specific blob */ 862: }; 863: 864: #define IOCTL_KGSL_TIMESTAMP_EVENT_OLD \ 865: _IOW(KGSL_IOC_TYPE, 0x31, struct kgsl_timestamp_event) 866: MATCH LINES: 895, 900, 902, 918, 927, 932, 945, 959, 974, 975, 982, 987 883: /* 884: * Set a property within the kernel. Uses the same structure as 885: * IOCTL_KGSL_GETPROPERTY 886: */ 887: 888: #define IOCTL_KGSL_SETPROPERTY \ 889: _IOW(KGSL_IOC_TYPE, 0x32, struct kgsl_device_getproperty) 890: 891: #define IOCTL_KGSL_TIMESTAMP_EVENT \ 892: _IOWR(KGSL_IOC_TYPE, 0x33, struct kgsl_timestamp_event) 893: 894: /** 895: * struct kgsl_gpumem_alloc_id - argument to IOCTL_KGSL_GPUMEM_ALLOC_ID 896: * @id: returned id value for this allocation. 897: * @flags: mask of KGSL_MEM* values requested and actual flags on return. 898: * @size: requested size of the allocation and actual size on return. 899: * @mmapsize: returned size to pass to mmap() which may be larger than 'size' 900: * @gpuaddr: returned GPU address for the allocation 901: * 902: * Allocate memory for access by the GPU. The flags and size fields are echoed 903: * back by the kernel, so that the caller can know if the request was 904: * adjusted. 905: * 906: * Supported flags: 907: * KGSL_MEMFLAGS_GPUREADONLY: the GPU will be unable to write to the buffer 908: * KGSL_MEMTYPE*: usage hint for debugging aid 909: * KGSL_MEMALIGN*: alignment hint, may be ignored or adjusted by the kernel. 910: * KGSL_MEMFLAGS_USE_CPU_MAP: If set on call and return, the returned GPU 911: * address will be 0. Calling mmap() will set the GPU address. 912: */ 913: struct kgsl_gpumem_alloc_id { 914: unsigned int id; 915: unsigned int flags; 916: __kernel_size_t size; 917: __kernel_size_t mmapsize; 918: unsigned long gpuaddr; 919: /* private: reserved for future use*/ 920: unsigned long __pad[2]; 921: }; 922: 923: #define IOCTL_KGSL_GPUMEM_ALLOC_ID \ 924: _IOWR(KGSL_IOC_TYPE, 0x34, struct kgsl_gpumem_alloc_id) 925: 926: /** 927: * struct kgsl_gpumem_free_id - argument to IOCTL_KGSL_GPUMEM_FREE_ID 928: * @id: GPU allocation id to free 929: * 930: * Free an allocation by id, in case a GPU address has not been assigned or 931: * is unknown. Freeing an allocation by id with this ioctl or by GPU address 932: * with IOCTL_KGSL_SHAREDMEM_FREE are equivalent. 933: */ 934: struct kgsl_gpumem_free_id { 935: unsigned int id; 936: /* private: reserved for future use*/ 937: unsigned int __pad; 938: }; 939: 940: #define IOCTL_KGSL_GPUMEM_FREE_ID \ 941: _IOWR(KGSL_IOC_TYPE, 0x35, struct kgsl_gpumem_free_id) 942: 943: /** 944: * struct kgsl_gpumem_get_info - argument to IOCTL_KGSL_GPUMEM_GET_INFO 945: * @gpuaddr: GPU address to query. Also set on return. 946: * @id: GPU allocation id to query. Also set on return. 947: * @flags: returned mask of KGSL_MEM* values. 948: * @size: returned size of the allocation. 949: * @mmapsize: returned size to pass mmap(), which may be larger than 'size' 950: * @useraddr: returned address of the userspace mapping for this buffer 951: * 952: * This ioctl allows querying of all user visible attributes of an existing 953: * allocation, by either the GPU address or the id returned by a previous 954: * call to IOCTL_KGSL_GPUMEM_ALLOC_ID. Legacy allocation ioctls may not 955: * return all attributes so this ioctl can be used to look them up if needed. 956: * 957: */ 958: struct kgsl_gpumem_get_info { 959: unsigned long gpuaddr; 960: unsigned int id; 961: unsigned int flags; 962: __kernel_size_t size; 963: __kernel_size_t mmapsize; 964: unsigned long useraddr; 965: /* private: reserved for future use*/ 966: unsigned long __pad[4]; 967: }; 968: 969: #define IOCTL_KGSL_GPUMEM_GET_INFO\ 970: _IOWR(KGSL_IOC_TYPE, 0x36, struct kgsl_gpumem_get_info) 971: 972: /** 973: * struct kgsl_gpumem_sync_cache - argument to IOCTL_KGSL_GPUMEM_SYNC_CACHE 974: * @gpuaddr: GPU address of the buffer to sync. 975: * @id: id of the buffer to sync. Either gpuaddr or id is sufficient. 976: * @op: a mask of KGSL_GPUMEM_CACHE_* values 977: * @offset: offset into the buffer 978: * @length: number of bytes starting from offset to perform 979: * the cache operation on 980: * 981: * Sync the L2 cache for memory headed to and from the GPU - this replaces 982: * KGSL_SHAREDMEM_FLUSH_CACHE since it can handle cache management for both 983: * directions 984: * 985: */ 986: struct kgsl_gpumem_sync_cache { 987: unsigned long gpuaddr; 988: unsigned int id; 989: unsigned int op; 990: __kernel_size_t offset; 991: __kernel_size_t length; 992: }; 993: 994: #define KGSL_GPUMEM_CACHE_CLEAN (1 << 0) 995: #define KGSL_GPUMEM_CACHE_TO_GPU KGSL_GPUMEM_CACHE_CLEAN 996: 997: #define KGSL_GPUMEM_CACHE_INV (1 << 1) 998: #define KGSL_GPUMEM_CACHE_FROM_GPU KGSL_GPUMEM_CACHE_INV 999: 1000: #define KGSL_GPUMEM_CACHE_FLUSH \ 1001: (KGSL_GPUMEM_CACHE_CLEAN | KGSL_GPUMEM_CACHE_INV) 1002: 1003: /* Flag to ensure backward compatibility of kgsl_gpumem_sync_cache struct */ 1004: #define KGSL_GPUMEM_CACHE_RANGE (1 << 31U) 1005: 1006: #define IOCTL_KGSL_GPUMEM_SYNC_CACHE \ 1007: _IOW(KGSL_IOC_TYPE, 0x37, struct kgsl_gpumem_sync_cache) 1008: 1009: /** 1010: * struct kgsl_perfcounter_get - argument to IOCTL_KGSL_PERFCOUNTER_GET 1011: * @groupid: Performance counter group ID MATCH LINES: 1429, 1437 1417: * struct kgsl_gpu_event_fence - Specifies a fence ID to free a GPU object on 1418: * @fd: File descriptor for the fence 1419: */ 1420: struct kgsl_gpu_event_fence { 1421: int fd; 1422: }; 1423: 1424: #define IOCTL_KGSL_GPUOBJ_FREE \ 1425: _IOW(KGSL_IOC_TYPE, 0x46, struct kgsl_gpuobj_free) 1426: 1427: /** 1428: * struct kgsl_gpuobj_info - argument to IOCTL_KGSL_GPUOBJ_INFO 1429: * @gpuaddr: GPU address of the object 1430: * @flags: Current flags for the object 1431: * @size: Size of the object 1432: * @va_len: VA size of the object 1433: * @va_addr: Virtual address of the object (if it is mapped) 1434: * id - GPU object ID of the object to query 1435: */ 1436: struct kgsl_gpuobj_info { 1437: __u64 gpuaddr; 1438: __u64 flags; 1439: __u64 size; 1440: __u64 va_len; 1441: __u64 va_addr; 1442: unsigned int id; 1443: }; 1444: 1445: #define IOCTL_KGSL_GPUOBJ_INFO \ 1446: _IOWR(KGSL_IOC_TYPE, 0x47, struct kgsl_gpuobj_info) 1447: 1448: /** 1449: * struct kgsl_gpuobj_import - argument to IOCTL_KGSL_GPUOBJ_IMPORT 1450: * @priv: Pointer to the private data for the import type 1451: * @priv_len: Length of the private data 1452: * @flags: Mask of KGSL_MEMFLAG_ flags 1453: * @type: Type of the import (KGSL_USER_MEM_TYPE_*) 1454: * @id: Returns the ID of the new GPU object 1455: */ 1456: struct kgsl_gpuobj_import { 1457: __u64 __user priv; 1458: __u64 priv_len; 1459: __u64 flags; 1460: unsigned int type; 1461: unsigned int id; MATCH LINES: 1517, 1524 1505: struct kgsl_gpuobj_sync { 1506: __u64 __user objs; 1507: unsigned int obj_len; 1508: unsigned int count; 1509: }; 1510: 1511: #define IOCTL_KGSL_GPUOBJ_SYNC \ 1512: _IOW(KGSL_IOC_TYPE, 0x49, struct kgsl_gpuobj_sync) 1513: 1514: /** 1515: * struct kgsl_command_object - GPU command object 1516: * @offset: GPU address offset of the object 1517: * @gpuaddr: GPU address of the object 1518: * @size: Size of the object 1519: * @flags: Current flags for the object 1520: * @id - GPU command object ID 1521: */ 1522: struct kgsl_command_object { 1523: __u64 offset; 1524: __u64 gpuaddr; 1525: __u64 size; 1526: unsigned int flags; 1527: unsigned int id; 1528: }; 1529: 1530: /** 1531: * struct kgsl_command_syncpoint - GPU syncpoint object 1532: * @priv: Pointer to the type specific buffer 1533: * @size: Size of the type specific buffer 1534: * @type: type of sync point defined here 1535: */ 1536: struct kgsl_command_syncpoint { 1537: __u64 __user priv; 1538: __u64 size; 1539: unsigned int type; 1540: }; 1541: 1542: /** 1543: * struct kgsl_gpu_command - Argument for IOCTL_KGSL_GPU_COMMAND 1544: * @flags: Current flags for the object 1545: * @cmdlist: List of kgsl_command_objects for submission 1546: * @cmdsize: Size of kgsl_command_objects structure 1547: * @numcmds: Number of kgsl_command_objects in command list 1548: * @objlist: List of kgsl_command_objects for tracking MATCH LINES: 1661, 1667 1649: unsigned int id; 1650: }; 1651: 1652: #define IOCTL_KGSL_SPARSE_PHYS_FREE \ 1653: _IOW(KGSL_IOC_TYPE, 0x51, struct kgsl_sparse_phys_free) 1654: 1655: /** 1656: * struct kgsl_sparse_virt_alloc - Argument for IOCTL_KGSL_SPARSE_VIRT_ALLOC 1657: * @size: Size in bytes to reserve 1658: * @pagesize: Pagesize alignment required 1659: * @flags: Flags for this allocation 1660: * @id: Returned ID for this allocation 1661: * @gpuaddr: Returned GPU address for this allocation 1662: */ 1663: struct kgsl_sparse_virt_alloc { 1664: __u64 size; 1665: __u64 pagesize; 1666: __u64 flags; 1667: __u64 gpuaddr; 1668: unsigned int id; 1669: }; 1670: 1671: #define IOCTL_KGSL_SPARSE_VIRT_ALLOC \ 1672: _IOWR(KGSL_IOC_TYPE, 0x52, struct kgsl_sparse_virt_alloc) 1673: 1674: /** 1675: * struct kgsl_sparse_virt_free - Argument for IOCTL_KGSL_SPARSE_VIRT_FREE 1676: * @id: ID to free 1677: */ 1678: struct kgsl_sparse_virt_free { 1679: unsigned int id; 1680: }; 1681: 1682: #define IOCTL_KGSL_SPARSE_VIRT_FREE \ 1683: _IOW(KGSL_IOC_TYPE, 0x53, struct kgsl_sparse_virt_free) 1684: 1685: /** 1686: * struct kgsl_sparse_binding_object - Argument for kgsl_sparse_bind 1687: * @virtoffset: Offset into the virtual ID 1688: * @physoffset: Offset into the physical ID (bind only) 1689: * @size: Size in bytes to reserve 1690: * @flags: Flags for this kgsl_sparse_binding_object 1691: * @id: Physical ID to bind (bind only) TOTAL MATCHES: 2678 ========================================================================================== SUBSYSTEM: MMU_AND_IOMMU ========================================================================================== --- FILE: \a5xx_reg.h | HITS: 2 --- MATCH LINES: 95, 96 83: #define A5XX_CP_CNTL 0x831 84: #define A5XX_CP_ME_CNTL 0x832 85: #define A5XX_CP_CHICKEN_DBG 0x833 86: #define A5XX_CP_PFP_INSTR_BASE_LO 0x835 87: #define A5XX_CP_PFP_INSTR_BASE_HI 0x836 88: #define A5XX_CP_PM4_INSTR_BASE_LO 0x838 89: #define A5XX_CP_PM4_INSTR_BASE_HI 0x839 90: #define A5XX_CP_CONTEXT_SWITCH_CNTL 0x83B 91: #define A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_LO 0x83C 92: #define A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_HI 0x83D 93: #define A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_LO 0x83E 94: #define A5XX_CP_CONTEXT_SWITCH_SAVE_ADDR_HI 0x83F 95: #define A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x840 96: #define A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x841 97: #define A5XX_CP_ADDR_MODE_CNTL 0x860 98: #define A5XX_CP_ME_STAT_DATA 0xB14 99: #define A5XX_CP_WFI_PEND_CTR 0xB15 100: #define A5XX_CP_INTERRUPT_STATUS 0xB18 101: #define A5XX_CP_HW_FAULT 0xB1A 102: #define A5XX_CP_PROTECT_STATUS 0xB1C 103: #define A5XX_CP_IB1_BASE 0xB1F 104: #define A5XX_CP_IB1_BASE_HI 0xB20 105: #define A5XX_CP_IB1_BUFSZ 0xB21 106: #define A5XX_CP_IB2_BASE 0xB22 107: #define A5XX_CP_IB2_BASE_HI 0xB23 108: #define A5XX_CP_IB2_BUFSZ 0xB24 109: #define A5XX_CP_PROTECT_REG_0 0x880 110: #define A5XX_CP_PROTECT_CNTL 0x8A0 111: #define A5XX_CP_AHB_FAULT 0xB1B 112: #define A5XX_CP_PERFCTR_CP_SEL_0 0xBB0 113: #define A5XX_CP_PERFCTR_CP_SEL_1 0xBB1 114: #define A5XX_CP_PERFCTR_CP_SEL_2 0xBB2 115: #define A5XX_CP_PERFCTR_CP_SEL_3 0xBB3 116: #define A5XX_CP_PERFCTR_CP_SEL_4 0xBB4 117: #define A5XX_CP_PERFCTR_CP_SEL_5 0xBB5 118: #define A5XX_CP_PERFCTR_CP_SEL_6 0xBB6 119: #define A5XX_CP_PERFCTR_CP_SEL_7 0xBB7 120: --- FILE: \a6xx_reg.h | HITS: 2 --- MATCH LINES: 72, 73 60: #define A6XX_CP_SQE_INSTR_BASE_HI 0x831 61: #define A6XX_CP_MISC_CNTL 0x840 62: #define A6XX_CP_APRIV_CNTL 0X844 63: #define A6XX_CP_ROQ_THRESHOLDS_1 0x8C1 64: #define A6XX_CP_ROQ_THRESHOLDS_2 0x8C2 65: #define A6XX_CP_MEM_POOL_SIZE 0x8C3 66: #define A6XX_CP_CHICKEN_DBG 0x841 67: #define A6XX_CP_ADDR_MODE_CNTL 0x842 68: #define A6XX_CP_DBG_ECO_CNTL 0x843 69: #define A6XX_CP_PROTECT_CNTL 0x84F 70: #define A6XX_CP_PROTECT_REG 0x850 71: #define A6XX_CP_CONTEXT_SWITCH_CNTL 0x8A0 72: #define A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO 0x8A1 73: #define A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI 0x8A2 74: #define A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO 0x8A3 75: #define A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI 0x8A4 76: #define A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO 0x8A5 77: #define A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI 0x8A6 78: #define A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO 0x8A7 79: #define A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI 0x8A8 80: #define A6XX_CP_CONTEXT_SWITCH_LEVEL_STATUS 0x8AB 81: #define A6XX_CP_PERFCTR_CP_SEL_0 0x8D0 82: #define A6XX_CP_PERFCTR_CP_SEL_1 0x8D1 83: #define A6XX_CP_PERFCTR_CP_SEL_2 0x8D2 84: #define A6XX_CP_PERFCTR_CP_SEL_3 0x8D3 85: #define A6XX_CP_PERFCTR_CP_SEL_4 0x8D4 86: #define A6XX_CP_PERFCTR_CP_SEL_5 0x8D5 87: #define A6XX_CP_PERFCTR_CP_SEL_6 0x8D6 88: #define A6XX_CP_PERFCTR_CP_SEL_7 0x8D7 89: #define A6XX_CP_PERFCTR_CP_SEL_8 0x8D8 90: #define A6XX_CP_PERFCTR_CP_SEL_9 0x8D9 91: #define A6XX_CP_PERFCTR_CP_SEL_10 0x8DA 92: #define A6XX_CP_PERFCTR_CP_SEL_11 0x8DB 93: #define A6XX_CP_PERFCTR_CP_SEL_12 0x8DC 94: #define A6XX_CP_PERFCTR_CP_SEL_13 0x8DD 95: #define A6XX_CP_CRASH_SCRIPT_BASE_LO 0x900 96: #define A6XX_CP_CRASH_SCRIPT_BASE_HI 0x901 97: #define A6XX_CP_CRASH_DUMP_CNTL 0x902 --- FILE: \adreno-gpulist.h | HITS: 18 --- MATCH LINES: 2007, 2008, 2028, 2029 1995: }, 1996: .prim_fifo_threshold = 0x0000c000, 1997: .sqefw_name = "a702_sqe.fw", 1998: .zap_name = "a702_zap.mdt", 1999: .hwcg = a702_hwcg_regs, 2000: .hwcg_count = ARRAY_SIZE(a702_hwcg_regs), 2001: .vbif = a640_vbif_regs, 2002: .vbif_count = ARRAY_SIZE(a640_vbif_regs), 2003: .hang_detect_cycles = 0x3ffff, 2004: .protected_regs = a620_protected_regs, 2005: }; 2006: 2007: /* SMMU aperture registers: GC to context bank 0, LPAC disabled */ 2008: static const struct kgsl_regmap_list a704_smmu_aperture_regs[] = { 2009: { 0x0, 0x000a8000 }, /* GC: CB0 */ 2010: { 0x2, 0x00000000 }, /* CTRL: GC only */ 2011: }; 2012: 2013: static const struct adreno_a6xx_core adreno_gpu_core_a704 = { 2014: .base = { 2015: DEFINE_ADRENO_REV(ADRENO_REV_A704, 7, 0, 4, ANY_ID), 2016: .features = ADRENO_CONTENT_PROTECTION | 2017: ADRENO_APRIV | ADRENO_PREEMPTION, 2018: .gpudev = &adreno_a6xx_gpudev, 2019: .perfcounters = &adreno_a6xx_legacy_perfcounters, 2020: .gmem_size = SZ_128K, 2021: .bus_width = 16, 2022: .snapshot_size = SZ_1M, 2023: .highest_bank_bit = 14, 2024: .chipid = 0x07000400, 2025: .ubwc_mode = 2, 2026: .mal = 32, 2027: .gpu_model = "Adreno704v1", 2028: .smmu_aperture = a704_smmu_aperture_regs, 2029: .smmu_aperture_count = ARRAY_SIZE(a704_smmu_aperture_regs), 2030: }, 2031: .prim_fifo_threshold = 0x0000c000, 2032: .sqefw_name = "a702_sqe.fw", 2033: .zap_name = "a704_zap.mbn", 2034: .hwcg = a702_hwcg_regs, 2035: .hwcg_count = ARRAY_SIZE(a702_hwcg_regs), 2036: .vbif = a640_vbif_regs, 2037: .vbif_count = ARRAY_SIZE(a640_vbif_regs), 2038: .hang_detect_cycles = 0x3ffff, 2039: .protected_regs = a620_protected_regs, 2040: }; 2041: 2042: static const struct kgsl_regmap_list gen7_0_0_hwcg_regs[] = { 2043: { GEN7_RBBM_CLOCK_CNTL_SP0, 0x02222222 }, 2044: { GEN7_RBBM_CLOCK_CNTL2_SP0, 0x02022222 }, 2045: { GEN7_RBBM_CLOCK_HYST_SP0, 0x0000f3cf }, 2046: { GEN7_RBBM_CLOCK_DELAY_SP0, 0x00000080 }, 2047: { GEN7_RBBM_CLOCK_CNTL_TP0, 0x22222220 }, 2048: { GEN7_RBBM_CLOCK_CNTL2_TP0, 0x22222222 }, 2049: { GEN7_RBBM_CLOCK_CNTL3_TP0, 0x22220222 }, 2050: { GEN7_RBBM_CLOCK_CNTL4_TP0, 0x00222222 }, 2051: { GEN7_RBBM_CLOCK_HYST_TP0, 0x77777777 }, 2052: { GEN7_RBBM_CLOCK_HYST2_TP0, 0x77777777 }, 2053: { GEN7_RBBM_CLOCK_HYST3_TP0, 0x77777777 }, MATCH LINES: 2780, 2781, 2801, 2802 2768: .gmu_hub_clk_freq = 200000000, 2769: .gen7_snapshot_block_list = &gen7_9_0_snapshot_block_list, 2770: .bcl_data = 1, 2771: .acv_perfmode_vote = BIT(2), 2772: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 2773: .ctxt_record_size = (4208 * SZ_1K), 2774: .preempt_level = 1, 2775: .fast_bus_hint = true, 2776: }; 2777: 2778: extern const struct gen7_snapshot_block_list gen7_13_0_snapshot_block_list; 2779: 2780: /* SMMU aperture registers: GC to context bank 0, LPAC to context bank 1 */ 2781: static const struct kgsl_regmap_list gen7_13_0_smmu_aperture_regs[] = { 2782: { 0x0, 0x000c0000 }, /* GC: CB0 */ 2783: { 0x1, 0x000c1000 }, /* LPAC: CB1 */ 2784: { 0x2, 0x00000002 }, /* CTRL: GC + LPAC */ 2785: }; 2786: 2787: static const struct adreno_gen7_core adreno_gpu_core_gen7_13_0 = { 2788: .base = { 2789: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_13_0, 2790: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2791: .features = ADRENO_APRIV | ADRENO_IOCOHERENT, 2792: .gpudev = &adreno_gen7_gmu_gpudev.base, 2793: .perfcounters = &adreno_gen7_9_0_perfcounters, 2794: .uche_gmem_alignment = SZ_16M, 2795: .gmem_size = 3 * SZ_1M, 2796: .bus_width = 32, 2797: .snapshot_size = SZ_8M, 2798: .num_ddr_channels = 4, 2799: .highest_bank_bit = 16, 2800: .chipid = 0x43051701, 2801: .smmu_aperture = gen7_13_0_smmu_aperture_regs, 2802: .smmu_aperture_count = ARRAY_SIZE(gen7_13_0_smmu_aperture_regs), 2803: }, 2804: .sqefw_name = "gen71300_sqe.fw", 2805: .gmufw_name = "gen71300_gmu.bin", 2806: .zap_name = "gen71300_zap.mbn", 2807: .gmu_chipid = 0x70D0000, 2808: .ao_hwcg = gen7_9_0_ao_hwcg_regs, 2809: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs), 2810: .gbif = gen7_2_0_gbif_cx_regs, 2811: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs), 2812: .hang_detect_cycles = 0xcfffff, 2813: .protected_regs = gen7_9_0_protected_regs, 2814: .gmu_hub_clk_freq = 200000000, 2815: .gen7_snapshot_block_list = &gen7_13_0_snapshot_block_list, 2816: .ctxt_record_size = (4208 * SZ_1K), 2817: .preempt_level = 1, 2818: }; 2819: 2820: extern const struct gen7_snapshot_block_list gen7_14_0_snapshot_block_list; 2821: 2822: static const struct adreno_gen7_core adreno_gpu_core_gen7_14_0 = { 2823: .base = { 2824: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_14_0, 2825: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID), 2826: .compatible = "qcom,adreno-gpu-gen7-14-0", MATCH LINES: 3081 3069: 3070: static const struct kgsl_regmap_list gen8_0_0_gbif_cx_regs[] = { 3071: { GEN8_GBIF_QSB_SIDE0, 0x00071e20 }, 3072: { GEN8_GBIF_QSB_SIDE1, 0x00071e20 }, 3073: { GEN8_GBIF_QSB_SIDE2, 0x00071e20 }, 3074: { GEN8_GBIF_QSB_SIDE3, 0x00071e20 }, 3075: { GEN8_GBIF_CX_CONFIG, 0x20023000 }, 3076: { GEN8_GMUCX_MRC_GBIF_QOS_CTRL, 0x33 }, 3077: }; 3078: 3079: /* GEN8_0_0 noncontext register list */ 3080: static const struct gen8_nonctxt_regs gen8_0_0_nonctxt_regs[] = { 3081: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 3082: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3083: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3084: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3085: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3086: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3087: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3088: /* Disable BR throttling */ 3089: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3090: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3091: /* Configure GBIF GX registers */ 3092: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) }, 3093: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) }, 3094: /* Enable full concurrent resolve and unresolves */ 3095: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 3096: { GEN8_RB_GC_GMEM_PROTECT, 0x0c000000, BIT(PIPE_BR) }, 3097: /* Configure number of outstanding transactions to 32 */ 3098: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 3099: /* Configure UCHE request time out to 16 cycles for CCU/UCHE arbitration */ 3100: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 3101: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3102: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3103: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 3104: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 3105: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, MATCH LINES: 3516 3504: { GEN8_CP_PROTECT_REG_GLOBAL + 47, 0x1f878, 0x1fd7f, 0 }, 3505: { GEN8_CP_PROTECT_REG_GLOBAL + 48, 0x1f930, 0x1fc59, 1 }, 3506: { GEN8_CP_PROTECT_REG_GLOBAL + 49, 0x1fd80, 0x21d7f, 1 }, 3507: { GEN8_CP_PROTECT_REG_GLOBAL + 50, 0x27800, 0x2787f, 1 }, 3508: { GEN8_CP_PROTECT_REG_GLOBAL + 51, 0x27880, 0x27c05, 0 }, 3509: { GEN8_CP_PROTECT_REG_GLOBAL + 52, 0x27882, 0x2788b, 1 }, 3510: { GEN8_CP_PROTECT_REG_GLOBAL + 63, 0x27c06, 0x27c06, 1 }, 3511: { 0 }, 3512: }; 3513: 3514: /* GEN8_2_0 noncontext register list */ 3515: static const struct gen8_nonctxt_regs gen8_2_0_nonctxt_regs[] = { 3516: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 3517: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3518: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3519: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3520: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3521: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3522: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3523: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3524: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3525: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3526: /* Disable Dead Draw Merge scheme on RB-HLSQ */ 3527: { GEN8_RB_RBP_CNTL, BIT(5), BIT(PIPE_BV) | BIT(PIPE_BR) }, 3528: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 3529: /* Partially enable perf clear, Disable DINT to c/z be data forwarding */ 3530: { GEN8_RB_CCU_DBG_ECO_CNTL, 0x00002200, BIT(PIPE_BR) }, 3531: { GEN8_RB_GC_GMEM_PROTECT, 0x12000000, BIT(PIPE_BR) }, 3532: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 3533: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 3534: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3535: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3536: { GEN8_RBBM_POWER_UP_RESET_SW_OVERRIDE, 0x70809060, BIT(PIPE_NONE) }, 3537: { GEN8_RBBM_POWER_UP_RESET_SW_BV_OVERRIDE, 0x30000000, BIT(PIPE_NONE) }, 3538: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 3539: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 3540: { GEN8_RBBM_INTERFACE_HANG_INT_CNTL, 0x0fffffff, BIT(PIPE_NONE) }, MATCH LINES: 3716 3704: .bcl_data = GEN8_2_X_BCL_DATA, 3705: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 3706: .noc_timeout_us = 3410, /* 3.41 msec */ 3707: .cl_no_ft_timeout_ms = 6500, 3708: .ctxt_record_size = (19708 * SZ_1K), 3709: .therm_cfg = &therm_mit_cfg_8_2_0, 3710: .limits_mit_cfg = &gen8_2_0_limits_mit_cfg, 3711: .preempt_level = 1, 3712: .clx_tbl = &gen8_2_0_clx_table, 3713: }; 3714: 3715: static const struct gen8_nonctxt_regs gen8_1_0_nonctxt_regs[] = { 3716: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 3717: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3718: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3719: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3720: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3721: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3722: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3723: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3724: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3725: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) }, 3726: { GEN8_RB_GC_GMEM_PROTECT, 0x15000000, BIT(PIPE_BR) }, 3727: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 3728: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 3729: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3730: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3731: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 3732: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 3733: { GEN8_RBBM_INTERFACE_HANG_INT_CNTL, 0x0fffffff, BIT(PIPE_NONE) }, 3734: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) }, 3735: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, 3736: { GEN8_SP_CHICKEN_BITS_2, 0x00820800, BIT(PIPE_NONE) }, 3737: { GEN8_SP_CHICKEN_BITS_3, 0x00300000, BIT(PIPE_NONE) }, 3738: { GEN8_SP_PERFCTR_SHADER_MASK, 0x0000003f, BIT(PIPE_NONE) }, 3739: /* Disable CS dead batch merge */ 3740: { GEN8_SP_HLSQ_DBG_ECO_CNTL_2, BIT(31), BIT(PIPE_NONE) }, MATCH LINES: 3917 3905: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4), 3906: .noc_timeout_us = 3410, /* 3.41 msec */ 3907: .cl_no_ft_timeout_ms = 6500, 3908: .ctxt_record_size = (19708 * SZ_1K), 3909: .therm_cfg = &therm_mit_cfg_8_2_0, 3910: .limits_mit_cfg = &gen8_2_0_limits_mit_cfg, 3911: .preempt_level = 1, 3912: .clx_tbl = &gen8_2_0_clx_table, 3913: }; 3914: 3915: /* GEN8_4_0 noncontext register list */ 3916: static const struct gen8_nonctxt_regs gen8_4_0_nonctxt_regs[] = { 3917: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 3918: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3919: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3920: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3921: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3922: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3923: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3924: /* Disable BR throttling */ 3925: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3926: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) }, 3927: /* Configure GBIF GX registers */ 3928: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) }, 3929: /* Reset value of RBBM_GBIF_CLIENT_QOS_CNTL is 0. So, no need to program explicitly. */ 3930: /* Enable full concurrent resolve and unresolves */ 3931: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 3932: { GEN8_RB_GC_GMEM_PROTECT, 0x0c000000, BIT(PIPE_BR) }, 3933: /* Configure number of outstanding transactions to 32 */ 3934: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 3935: /* Configure UCHE request time out to 16 cycles for CCU/UCHE arbitration */ 3936: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 3937: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3938: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 3939: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 3940: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 3941: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, MATCH LINES: 4045 4033: }; 4034: 4035: static const struct kgsl_regmap_list gen8_8_0_gbif_cx_regs[] = { 4036: { GEN8_GBIF_QSB_SIDE0, 0x00071e20 }, 4037: { GEN8_GBIF_QSB_SIDE1, 0x00071e20 }, 4038: { GEN8_GBIF_QSB_SIDE2, 0x00071e20 }, 4039: { GEN8_GBIF_QSB_SIDE3, 0x00071e20 }, 4040: { GEN8_GBIF_CX_CONFIG, 0x40023000 }, 4041: }; 4042: 4043: /* GEN8_3_0 noncontext register list */ 4044: static const struct gen8_nonctxt_regs gen8_3_0_nonctxt_regs[] = { 4045: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 4046: { GEN8_GRAS_DBG_ECO_CNTL, 0x00f80800, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4047: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4048: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4049: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4050: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) }, 4051: { GEN8_PC_CHICKEN_BITS_1, 0x00000023, BIT(PIPE_BV) }, /* Avoid partial waves at VFD */ 4052: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4053: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4054: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4055: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 4056: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 4057: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 4058: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4059: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4060: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 4061: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 4062: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) }, 4063: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) }, 4064: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, 4065: { GEN8_SP_CHICKEN_BITS_2, BIT(22) | BIT(23), BIT(PIPE_NONE) }, 4066: { GEN8_SP_CHICKEN_BITS_3, 0x00300000, BIT(PIPE_NONE) }, 4067: { GEN8_SP_PERFCTR_SHADER_MASK, 0x0000003f, BIT(PIPE_NONE) }, 4068: { GEN8_SP_HLSQ_TIMEOUT_THRESHOLD_DP, 0x00000080, BIT(PIPE_NONE) }, 4069: { GEN8_TPL1_DBG_ECO_CNTL, 0x10000000, BIT(PIPE_NONE) }, MATCH LINES: 4123 4111: .gbif_count = ARRAY_SIZE(gen8_3_0_gbif_cx_regs), 4112: .hang_detect_cycles = 0xcfffff, 4113: .protected_regs = gen8_0_0_protected_regs, /* Reuse the protected regs list from Gen8_0_0 */ 4114: .nonctxt_regs = gen8_3_0_nonctxt_regs, 4115: .gmu_hub_clk_freq = 200000000, 4116: .gen8_snapshot_block_list = &gen8_3_0_snapshot_block_list, 4117: .ctxt_record_size = (4558 * SZ_1K), 4118: .preempt_level = 1, 4119: }; 4120: 4121: /* GEN8_6_0 noncontext register list */ 4122: static const struct gen8_nonctxt_regs gen8_6_0_nonctxt_regs[] = { 4123: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 4124: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4125: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4126: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4127: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4128: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4129: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4130: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4131: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4132: /* Configure GBIF GX registers */ 4133: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) }, 4134: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) }, 4135: /* Enable full concurrent resolve and unresolves */ 4136: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 4137: { GEN8_RB_GC_GMEM_PROTECT, 0x02600000, BIT(PIPE_BR) }, 4138: /* Configure number of outstanding transactions to 32 */ 4139: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 4140: /* Configure UCHE request time out to 16 cycles for CCU/UCHE arbitration */ 4141: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 4142: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4143: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4144: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) }, 4145: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) }, 4146: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, 4147: /* Enable contribution of all shader stages to SP perfcounters */ MATCH LINES: 4279 4267: { GEN8_RBBM_INTERFACE_HANG_INT_CNTL, 0x0fffffff, BIT(PIPE_NONE) }, 4268: { GEN8_RBBM_POWER_UP_RESET_SW_OVERRIDE, 0x70809060, BIT(PIPE_NONE) }, 4269: { GEN8_RBBM_POWER_UP_RESET_SW_BV_OVERRIDE, 0x30000000, BIT(PIPE_NONE) }, 4270: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) }, 4271: /* Disable mode_switch optimization in UMAS */ 4272: { GEN8_SP_CHICKEN_BITS, BIT(26), BIT(PIPE_NONE) }, 4273: /* Disable LPAC large-LM mode */ 4274: { GEN8_SP_SS_CHICKEN_BITS_0, BIT(3), BIT(PIPE_NONE) }, 4275: /* Disable PS out of order retire */ 4276: { GEN8_SP_CHICKEN_BITS_2, 0xc21800, BIT(PIPE_NONE) }, 4277: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4278: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4279: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 4280: { GEN8_UCHE_MODE_CNTL, 0x80080000, BIT(PIPE_NONE) }, 4281: { GEN8_UCHE_VARB_IDLE_TIMEOUT, 0x00000020, BIT(PIPE_NONE) }, 4282: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) }, 4283: { GEN8_UCHE_CCHE_MODE_CNTL, 0x00001000, BIT(PIPE_NONE) }, 4284: { GEN8_UCHE_CCHE_CACHE_WAYS, 0x00000800, BIT(PIPE_NONE) }, 4285: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4286: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4287: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 4288: { GEN8_RB_CCU_DBG_ECO_CNTL, 0x00002200, BIT(PIPE_BR) }, 4289: { GEN8_RB_GC_GMEM_PROTECT, 0x02600000, BIT(PIPE_BR) }, 4290: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) }, 4291: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) }, 4292: { GEN8_VPC_FLATSHADE_MODE_CNTL, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4293: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4294: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4295: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4296: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4297: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4298: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4299: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4300: { GEN8_VFD_DBG_ECO_CNTL, 0x00008000, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4301: { GEN8_VFD_CB_BV_THRESHOLD, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4302: { GEN8_VFD_CB_BR_THRESHOLD, 0x00600060, BIT(PIPE_BR) | BIT(PIPE_BV) }, 4303: { GEN8_VFD_CB_BUSY_REQ_CNT, 0x00200020, BIT(PIPE_BR) | BIT(PIPE_BV) }, MATCH LINES: 4632 4620: { GEN8_CP_PROTECT_REG_GLOBAL + 50, 0x1f878, 0x1fd7f, 0 }, 4621: { GEN8_CP_PROTECT_REG_GLOBAL + 51, 0x1f930, 0x1fc59, 1 }, 4622: { GEN8_CP_PROTECT_REG_GLOBAL + 52, 0x1fd80, 0x21d7f, 1 }, 4623: { GEN8_CP_PROTECT_REG_GLOBAL + 53, 0x27800, 0x2787f, 1 }, 4624: { GEN8_CP_PROTECT_REG_GLOBAL + 54, 0x27880, 0x27c05, 0 }, 4625: { GEN8_CP_PROTECT_REG_GLOBAL + 55, 0x27882, 0x278b7, 1 }, 4626: { GEN8_CP_PROTECT_REG_GLOBAL + 63, 0x27c06, 0x27c06, 1 }, 4627: { 0 }, 4628: }; 4629: 4630: /* GEN8_11_0 noncontext register list */ 4631: static const struct gen8_nonctxt_regs gen8_11_0_nonctxt_regs[] = { 4632: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 4633: { GEN8_CP_MULTIDRAW_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4634: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4635: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4636: { GEN8_GRAS_NC_MODE_CNTL, 0x00000220, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4637: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4638: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4639: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4640: /* BIT(11): Disable skipIdx to avoid PDMA hang with restart-index draws */ 4641: { GEN8_PC_CHICKEN_BITS_1, 0x00000803, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4642: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4643: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4644: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4645: /* 4646: * BIT(28): Disable GS Quad primitive 4647: * BIT(30): Disable skipIdx to avoid PDMA hang with restart-index draws 4648: */ 4649: { GEN8_PC_CHICKEN_BITS_5, BIT(28) | BIT(30), BIT(PIPE_BV) | BIT(PIPE_BR) }, 4650: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 4651: /* 4652: * BIT(10): Disable sysmem nonfclear feature 4653: * BIT(9): Disable DINT to c/z be data forwarding 4654: */ 4655: { GEN8_RB_CCU_DBG_ECO_CNTL, BIT(10) | BIT(9), BIT(PIPE_BR) }, 4656: { GEN8_RB_CCU_NC_MODE_CNTL, 0x00000002, BIT(PIPE_BR) }, MATCH LINES: 4771 4759: .cl_no_ft_timeout_ms = 6500, 4760: .ctxt_record_size = (19708 * SZ_1K), 4761: .limits_mit_cfg = &gen8_11_0_limits_mit_cfg, 4762: .preempt_level = 1, 4763: .gmu_mx_gdsc = true, 4764: .three_rail_memory = true, 4765: .malu = true, 4766: .clx_tbl = &gen8_11_0_clx_table, 4767: }; 4768: 4769: /* GEN8_11_1 noncontext register list */ 4770: static const struct gen8_nonctxt_regs gen8_11_1_nonctxt_regs[] = { 4771: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 4772: { GEN8_CP_MULTIDRAW_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4773: /* Keep the raster direction as topleft */ 4774: { GEN8_GRAS_DBG_ECO_CNTL, 0x01000800, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4775: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4776: /* GEN8_GRAS_NC_MODE_CNTL explicitly set elsewhere */ 4777: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4778: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4779: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4780: /* BIT(11): Disable skipIdx to avoid PDMA hang with restart-index draws */ 4781: { GEN8_PC_CHICKEN_BITS_1, 0x00000803, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4782: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4783: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4784: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4785: /* 4786: * BIT(28): Disable GS Quad primitive 4787: * BIT(30): Disable skipIdx to avoid PDMA hang with restart-index draws 4788: */ 4789: { GEN8_PC_CHICKEN_BITS_5, BIT(28) | BIT(30), BIT(PIPE_BV) | BIT(PIPE_BR) }, 4790: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 4791: /* 4792: * BIT(10): Disable sysmem nonfclear feature 4793: * BIT(9): Disable DINT to c/z be data forwarding 4794: */ 4795: { GEN8_RB_CCU_DBG_ECO_CNTL, BIT(10) | BIT(9), BIT(PIPE_BR) }, MATCH LINES: 4917 4905: .noc_timeout_us = 3410, /* 3.41 msec */ 4906: .cl_no_ft_timeout_ms = 6500, 4907: .ctxt_record_size = (19708 * SZ_1K), 4908: .limits_mit_cfg = &gen8_11_0_limits_mit_cfg, 4909: .preempt_level = 1, 4910: .gmu_mx_gdsc = true, 4911: .three_rail_memory = true, 4912: .malu = true, 4913: .clx_tbl = &gen8_11_0_clx_table, 4914: }; 4915: 4916: static const struct gen8_nonctxt_regs gen8_14_0_nonctxt_regs[] = { 4917: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) }, 4918: { GEN8_CP_MULTIDRAW_CNTL, 0x00000001, BIT(PIPE_NONE) }, 4919: /* Keep the raster direction as topleft */ 4920: { GEN8_GRAS_DBG_ECO_CNTL, 0x01000800, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4921: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4922: /* GEN8_GRAS_NC_MODE_CNTL explicitly set elsewhere */ 4923: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4924: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4925: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4926: /* BIT(11): Disable skipIdx to avoid PDMA hang with restart-index draws */ 4927: { GEN8_PC_CHICKEN_BITS_1, 0x00000803, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4928: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4929: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4930: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) }, 4931: /* 4932: * BIT(28): Disable GS Quad primitive 4933: * BIT(30): Disable skipIdx to avoid PDMA hang with restart-index draws 4934: */ 4935: { GEN8_PC_CHICKEN_BITS_5, BIT(28) | BIT(30), BIT(PIPE_BV) | BIT(PIPE_BR) }, 4936: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) }, 4937: /* 4938: * BIT(10): Disable sysmem nonfclear feature 4939: * BIT(9): Disable DINT to c/z be data forwarding 4940: */ 4941: { GEN8_RB_CCU_DBG_ECO_CNTL, BIT(10) | BIT(9), BIT(PIPE_BR) }, --- FILE: \adreno.c | HITS: 30 --- MATCH LINES: 1704 1692: 1693: if (ret) { 1694: /* Propagate EPROBE_DEFER back to the probe function */ 1695: if (ret == -EPROBE_DEFER) 1696: return ret; 1697: 1698: if (ret != -ENOENT) 1699: dev_warn(&pdev->dev, 1700: "Unable to get the GPU LLC slice: %d\n", ret); 1701: } else 1702: adreno_dev->gpu_llc_slice_enable = true; 1703: 1704: /* Get the system cache slice descriptor for GPU pagetables */ 1705: adreno_dev->gpuhtw_llc_slice = llcc_slice_getd(LLCC_GPUHTW); 1706: ret = PTR_ERR_OR_ZERO(adreno_dev->gpuhtw_llc_slice); 1707: if (ret) { 1708: if (ret == -EPROBE_DEFER) { 1709: llcc_slice_putd(adreno_dev->gpu_llc_slice); 1710: return ret; 1711: } 1712: 1713: if (ret != -ENOENT) 1714: dev_warn(&pdev->dev, 1715: "Unable to get GPU HTW LLC slice: %d\n", ret); 1716: } else 1717: adreno_dev->gpuhtw_llc_slice_enable = true; 1718: 1719: #if (KERNEL_VERSION(6, 1, 0) == LINUX_VERSION_CODE) 1720: if (adreno_is_a621(adreno_dev)) { 1721: /* Get the system cache slice descriptor for GPU MV grid buffer */ 1722: adreno_dev->gpumv_llc_slice = llcc_slice_getd(LLCC_GPUMV); 1723: ret = PTR_ERR_OR_ZERO(adreno_dev->gpumv_llc_slice); 1724: if (ret) { 1725: if (ret == -EPROBE_DEFER) { 1726: llcc_slice_putd(adreno_dev->gpu_llc_slice); 1727: llcc_slice_putd(adreno_dev->gpuhtw_llc_slice); 1728: return ret; MATCH LINES: 1871, 1872, 1873 1859: 1860: static const struct of_device_id adreno_component_match[] = { 1861: { .compatible = "qcom,adreno-gmu" }, 1862: { .compatible = "qcom,adreno-rgmu" }, 1863: {}, 1864: }; 1865: 1866: static const struct of_device_id adreno_component_match_legacy[] = { 1867: { .compatible = "qcom,gen8-gmu" }, 1868: { .compatible = "qcom,gen7-gmu" }, 1869: { .compatible = "qcom,gpu-gmu" }, 1870: { .compatible = "qcom,gpu-rgmu" }, 1871: /* Legacy components for kgsl-smmu */ 1872: { .compatible = "qcom,kgsl-smmu-v2" }, 1873: { .compatible = "qcom,smmu-kgsl-cb" }, 1874: {}, 1875: }; 1876: 1877: static int adreno_irq_setup(struct platform_device *pdev, 1878: struct adreno_device *adreno_dev) 1879: { 1880: if (!adreno_dev->irq_mask) 1881: return 0; 1882: 1883: /* 1884: * Try to get the irq based on gpu irq name (i.e. "kgsl_3d0_irq") else fall back 1885: * to requesting it by index. 1886: * Note: kgsl_3d0_irq should always be the first in the gpu irq list. 1887: */ 1888: return kgsl_request_irq(pdev, "kgsl_3d0_irq", NULL, 0, adreno_irq_handler, 1889: KGSL_DEVICE(adreno_dev)); 1890: } 1891: 1892: static int adreno_pm_notifier(struct notifier_block *nb, unsigned long event, void *unused) 1893: { 1894: struct adreno_device *adreno_dev = container_of(nb, struct adreno_device, pm_nb); 1895: struct kgsl_pwrctrl *pwr = &adreno_dev->dev.pwrctrl; 1896: struct generic_pm_domain *pd = NULL; 1897: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); MATCH LINES: 2161, 2169, 2170, 2173 2149: 2150: status = kgsl_bus_init(device, pdev); 2151: if (status) 2152: goto err; 2153: 2154: status = adreno_of_get_power(adreno_dev, pdev); 2155: if (status) 2156: goto err; 2157: 2158: validate_pwrlevels(device); 2159: 2160: /* 2161: * The SMMU APIs use unsigned long for virtual addresses which means 2162: * that we cannot use 64 bit virtual addresses on a 32 bit kernel even 2163: * though the hardware and the rest of the KGSL driver supports it. 2164: */ 2165: if (adreno_support_64bit(adreno_dev)) 2166: kgsl_mmu_set_feature(device, KGSL_MMU_64BIT); 2167: 2168: /* 2169: * Set the SMMU aperture on A6XX/Gen7 targets to use per-process 2170: * pagetables. 2171: */ 2172: if (ADRENO_GPUREV(adreno_dev) >= 600) 2173: kgsl_mmu_set_feature(device, KGSL_MMU_SMMU_APERTURE); 2174: 2175: if (ADRENO_FEATURE(adreno_dev, ADRENO_IOCOHERENT)) 2176: kgsl_mmu_set_feature(device, KGSL_MMU_IO_COHERENT); 2177: 2178: /* 2179: * Support VBOs on hardware where HLOS has access to PRR registers 2180: * configuration. 2181: */ 2182: if (!adreno_is_a650(adreno_dev)) 2183: kgsl_mmu_set_feature(device, KGSL_MMU_SUPPORT_VBO); 2184: 2185: if (adreno_preemption_enable) 2186: adreno_dev->preempt_override = true; 2187: 2188: device->pwrctrl.bus_width = adreno_dev->gpucore->bus_width; 2189: 2190: device->mmu.secured = (IS_ENABLED(CONFIG_QCOM_SECURE_BUFFER) && 2191: ADRENO_FEATURE(adreno_dev, ADRENO_CONTENT_PROTECTION) && 2192: adreno_dev->zap_enabled); 2193: 2194: /* Probe the LLCC - this could return -EPROBE_DEFER */ 2195: status = adreno_probe_llcc(adreno_dev, pdev); 2196: if (status) 2197: goto err_bus_close; MATCH LINES: 2243, 2245 2231: 2232: status = kgsl_device_platform_probe(device); 2233: if (status) 2234: goto err_unbind; 2235: 2236: adreno_fence_trace_array_init(device); 2237: 2238: /* Add CX_DBGC block to the regmap*/ 2239: kgsl_regmap_add_region(&device->regmap, pdev, "cx_dbgc", -EINVAL, NULL, NULL); 2240: 2241: res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "aperture"); 2242: if (res) { 2243: device->smmu_aperture_virt = devm_ioremap(dev, res->start, 2244: resource_size(res)); 2245: if (!device->smmu_aperture_virt) 2246: dev_warn(dev, "aperture ioremap failed\n"); 2247: } 2248: 2249: if (kgsl_regmap_add_region(&device->regmap, pdev, "isense_cntl", -EINVAL, NULL, NULL) == 0) 2250: adreno_dev->isense_reg_mapped = true; 2251: 2252: /* Allocate the memstore for storing timestamps and other useful info */ 2253: 2254: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) 2255: priv |= KGSL_MEMDESC_PRIVILEGED; 2256: 2257: kgsl_mutex_lock(&device->mutex); 2258: device->memstore = kgsl_allocate_global(device, 2259: KGSL_MEMSTORE_SIZE, 0, 0, priv, "memstore"); 2260: adreno_profile_init(adreno_dev); 2261: kgsl_mutex_unlock(&device->mutex); 2262: 2263: status = PTR_ERR_OR_ZERO(device->memstore); 2264: if (status) { 2265: trace_array_put(device->fence_trace_array); 2266: kgsl_device_platform_remove(device); 2267: goto err_unbind; 2268: } 2269: MATCH LINES: 2491 2479: struct adreno_device *adreno_dev; 2480: const struct adreno_power_ops *ops; 2481: 2482: if (!device) 2483: return 0; 2484: 2485: adreno_dev = ADRENO_DEVICE(device); 2486: ops = ADRENO_POWER_OPS(adreno_dev); 2487: 2488: kgsl_mutex_lock(&device->mutex); 2489: #if IS_ENABLED(CONFIG_DEEPSLEEP) 2490: if (pm_suspend_via_firmware()) 2491: device->mmu.iommu.smmu_aperture_set = false; 2492: #endif 2493: ops->pm_resume(adreno_dev); 2494: kgsl_mutex_unlock(&device->mutex); 2495: 2496: kgsl_reclaim_start(); 2497: return 0; 2498: } 2499: 2500: static int adreno_suspend(struct adreno_device *adreno_dev) 2501: { 2502: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2503: int status = kgsl_pwrctrl_change_state(device, KGSL_STATE_SUSPEND); 2504: 2505: if (!status && device->state == KGSL_STATE_SUSPEND) 2506: adreno_get_gpu_halt(adreno_dev); 2507: 2508: return status; 2509: } 2510: 2511: static int adreno_pm_suspend(struct device *dev) 2512: { 2513: struct kgsl_device *device = dev_get_drvdata(dev); 2514: struct adreno_device *adreno_dev; 2515: const struct adreno_power_ops *ops; MATCH LINES: 3041, 3042, 3045 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: /* 3041: * Try soft reset first Do not do soft reset for a IOMMU fault (because 3042: * the IOMMU hardware needs a reset too) 3043: */ 3044: 3045: if (!(fault & ADRENO_IOMMU_STALL_ON_PAGE_FAULT)) 3046: ret = adreno_soft_reset(device); 3047: 3048: if (ret) { 3049: /* If soft reset failed/skipped, then pull the power */ 3050: kgsl_pwrctrl_change_state(device, KGSL_STATE_INIT); 3051: /* since device is officially off now clear start bit */ 3052: clear_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv); 3053: 3054: /* Try to reset the device */ 3055: ret = adreno_start(device, 0); 3056: 3057: for (i = 0; ret && i < 4; i++) { 3058: msleep(20); 3059: ret = adreno_start(device, 0); 3060: } 3061: 3062: if (ret) 3063: return ret; 3064: 3065: if (i != 0) 3066: dev_warn(device->dev, 3067: "Device hard reset tried %d tries\n", i); 3068: } 3069: MATCH LINES: 3520 3508: static void adreno_alloc_dcvs_profile_memory(struct kgsl_device *device, 3509: struct kgsl_process_private *proc_priv) 3510: { 3511: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 3512: struct kgsl_memdesc *md = &proc_priv->profile.md; 3513: u32 sizebytes; 3514: 3515: if (!ADRENO_FEATURE(adreno_dev, ADRENO_DCVS_PROFILE)) 3516: return; 3517: 3518: if (!gmu_core_alloc_kernel_block(device, md, 3519: SZ_4K, GMU_NONCACHED_KERNEL, 3520: IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV)) { 3521: /* KMD need to initialize KGSL region to KGSL_DCVS_ATTR_UNUSED for 3522: * torn state handling as per design and second half region to 0 so that 3523: * if there is no profile ever registered for a process, GMU can skip 3524: * tracking for this profile. 3525: */ 3526: sizebytes = md->size >> 1; 3527: memset(md->hostptr, KGSL_DCVS_ATTR_UNUSED, sizebytes); 3528: memset(md->hostptr + sizebytes, 0, sizebytes); 3529: } 3530: } 3531: 3532: static int adreno_set_dcvs_profile(struct kgsl_device_private *dev_priv, 3533: void __user *data, u32 sizebytes) 3534: { 3535: struct kgsl_device *device = dev_priv->device; 3536: struct kgsl_process_private *proc_priv = dev_priv->process_priv; 3537: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 3538: const struct adreno_hwsched_ops *hwsched_ops = adreno_dev->hwsched.hwsched_ops; 3539: struct kgsl_memdesc *md = &proc_priv->profile.md; 3540: struct kgsl_dcvs_profile param = {0}; 3541: struct kgsl_dcvs_attrs attrs; 3542: u32 size; 3543: int ret = 0; 3544: MATCH LINES: 4180 4168: { 4169: struct kgsl_device *device = dev_priv->device; 4170: struct kgsl_process_private *private = dev_priv->process_priv; 4171: 4172: /* The maximum allowable size for an IB in the CP is 0xFFFFF dwords */ 4173: if (ib->size == 0 || ((ib->size >> 2) > 0xFFFFF)) { 4174: pr_context(device, context, "ctxt %u invalid ib size %lld\n", 4175: context->id, ib->size); 4176: return false; 4177: } 4178: 4179: /* Make sure that the address is in range and dword aligned */ 4180: if (!kgsl_mmu_gpuaddr_in_range(private->pagetable, ib->gpuaddr, 4181: ib->size) || !IS_ALIGNED(ib->gpuaddr, 4)) { 4182: pr_context(device, context, "ctxt %u invalid ib gpuaddr %llX\n", 4183: context->id, ib->gpuaddr); 4184: return false; 4185: } 4186: 4187: return true; 4188: } 4189: 4190: int adreno_verify_cmdobj(struct kgsl_device_private *dev_priv, 4191: struct kgsl_context *context, struct kgsl_drawobj *drawobj[], 4192: uint32_t count) 4193: { 4194: struct kgsl_device *device = dev_priv->device; 4195: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4196: struct kgsl_memobj_node *ib; 4197: unsigned int i; 4198: 4199: for (i = 0; i < count; i++) { 4200: /* Verify the IBs before they get queued */ 4201: if (drawobj[i]->type == CMDOBJ_TYPE) { 4202: struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj[i]); 4203: 4204: /* Only allow mALU submissions if hardware supports mALU */ MATCH LINES: 4344, 4349, 4360 4332: static void adreno_drawctxt_sched(struct kgsl_device *device, 4333: struct kgsl_context *context) 4334: { 4335: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4336: 4337: if (WARN_ON(!adreno_dev->dispatch_ops || !adreno_dev->dispatch_ops->queue_context)) 4338: return; 4339: 4340: adreno_dev->dispatch_ops->queue_context(adreno_dev, 4341: ADRENO_CONTEXT(context)); 4342: } 4343: 4344: bool adreno_smmu_is_stalled(struct adreno_device *adreno_dev) 4345: { 4346: u32 fault, val; 4347: 4348: /* 4349: * RBBM_STATUS3:SMMU_STALLED_ON_FAULT (BIT 24) to tells if GPU 4350: * encountered a pagefault. Gen8 page fault status checked from 4351: * the software condition as RBBM_STATUS3 is not available. 4352: */ 4353: if (ADRENO_GPUREV(adreno_dev) < ADRENO_REV_GEN8_0_0) { 4354: adreno_readreg(adreno_dev, ADRENO_REG_RBBM_STATUS3, &val); 4355: return (val & BIT(24)); 4356: } 4357: 4358: fault = adreno_gpu_fault(adreno_dev); 4359: 4360: return (fault & ADRENO_IOMMU_STALL_ON_PAGE_FAULT) ? true : false; 4361: } 4362: 4363: int adreno_power_cycle(struct adreno_device *adreno_dev, 4364: void (*callback)(struct adreno_device *adreno_dev, void *priv), 4365: void *priv) 4366: { 4367: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 4368: const struct adreno_power_ops *ops = ADRENO_POWER_OPS(adreno_dev); 4369: int ret; 4370: 4371: kgsl_mutex_lock(&device->mutex); 4372: ret = ops->pm_suspend(adreno_dev); 4373: 4374: if (!ret) { 4375: callback(adreno_dev, priv); 4376: gmu_core_mark_for_coldboot(device); 4377: ops->pm_resume(adreno_dev); 4378: } 4379: 4380: kgsl_mutex_unlock(&device->mutex); 4381: 4382: return ret; 4383: } 4384: MATCH LINES: 4685, 4691, 4694, 4695, 4696 4673: } 4674: } 4675: 4676: static void adreno_set_thermal_index(struct kgsl_device *device) 4677: { 4678: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4679: const struct adreno_power_ops *ops = ADRENO_POWER_OPS(adreno_dev); 4680: 4681: if (ops->set_thermal_index) 4682: ops->set_thermal_index(adreno_dev); 4683: } 4684: 4685: static int adreno_set_smmu_aperture(struct kgsl_device *device) 4686: { 4687: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4688: const struct adreno_gpu_core *gpucore = adreno_dev->gpucore; 4689: int i; 4690: 4691: if (!gpucore->smmu_aperture_count || !device->smmu_aperture_virt) 4692: return -ENODEV; 4693: 4694: for (i = 0; i < gpucore->smmu_aperture_count; i++) 4695: writel_relaxed(gpucore->smmu_aperture[i].val, device->smmu_aperture_virt + 4696: (gpucore->smmu_aperture[i].offset << 2)); 4697: 4698: /* Make sure all of the preceding writes have posted */ 4699: wmb(); 4700: 4701: return 0; 4702: } 4703: 4704: static bool adreno_is_first_boot_done(struct kgsl_device *device) 4705: { 4706: struct adreno_device *adreno_dev = ADRENO_DEVICE(device); 4707: 4708: return test_bit(ADRENO_DEVICE_FIRST_BOOT_DONE, &adreno_dev->priv); 4709: } 4710: 4711: static const struct kgsl_functable adreno_functable = { 4712: /* Mandatory functions */ 4713: .check_idle = adreno_check_idle, 4714: .first_open = adreno_first_open, 4715: .start = adreno_start, 4716: .stop = adreno_stop, 4717: .last_close = adreno_last_close, 4718: .getproperty = adreno_getproperty, 4719: .getproperty_compat = adreno_getproperty_compat, 4720: .waittimestamp = adreno_waittimestamp, MATCH LINES: 4756, 4789 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, 4771: }; 4772: 4773: static int _compare_of(struct device *dev, void *data) 4774: { 4775: return (dev->of_node == data); 4776: } 4777: 4778: static void _release_of(struct device *dev, void *data) 4779: { 4780: of_node_put(data); 4781: } 4782: 4783: static void adreno_add_components(struct device *dev, 4784: struct component_match **match, const struct of_device_id *matches) 4785: { 4786: struct device_node *node; 4787: 4788: /* 4789: * Add kgsl-smmu, context banks and gmu as components, if supported. 4790: * Master bind (adreno_bind) will be called only once all added 4791: * components are available. 4792: */ 4793: for_each_matching_node(node, matches) { 4794: if (!of_device_is_available(node)) 4795: continue; 4796: 4797: component_match_add_release(dev, match, _release_of, _compare_of, node); 4798: } 4799: } 4800: 4801: static int adreno_probe(struct platform_device *pdev) 4802: { 4803: struct component_match *match = NULL; 4804: const struct of_device_id *matches = adreno_component_match_legacy; 4805: 4806: /* 4807: * Let us say there are two devices. One with "qcom,adreno" compatible 4808: * and one with "qcom,kgsl-3d0" or "qcom,kgsl" compatible. In this case 4809: * probe only the device with legacy compatible strings and return 4810: * error for the device with "qcom,adreno". Also choose the match table 4811: * accordingly. 4812: */ 4813: if (of_device_is_compatible(pdev->dev.of_node, "qcom,adreno")) { MATCH LINES: 5030, 5039, 5050 5018: 5019: static int governor_reinit(struct devfreq *devfreq, const char *governor) 5020: { 5021: if (governor && !strcmp(governor, "msm-adreno-tz")) 5022: return msm_adreno_tz_reinit(devfreq); 5023: 5024: return 0; 5025: } 5026: 5027: static int adreno_hibernation_resume(struct device *dev) 5028: { 5029: struct kgsl_device *device = dev_get_drvdata(dev); 5030: struct kgsl_iommu *iommu; 5031: struct kgsl_pwrscale *pwrscale; 5032: struct adreno_device *adreno_dev; 5033: const struct adreno_power_ops *ops; 5034: int ret; 5035: 5036: if (!device) 5037: return 0; 5038: 5039: iommu = &device->mmu.iommu; 5040: pwrscale = &device->pwrscale; 5041: adreno_dev = ADRENO_DEVICE(device); 5042: ops = ADRENO_POWER_OPS(adreno_dev); 5043: 5044: kgsl_mutex_lock(&device->mutex); 5045: 5046: ret = adreno_secure_pt_restore(adreno_dev); 5047: if (ret) 5048: goto err; 5049: 5050: iommu->smmu_aperture_set = false; 5051: 5052: gmu_core_dev_force_first_boot(device); 5053: 5054: governor_reinit(pwrscale->devfreqptr, CONFIG_QCOM_ADRENO_DEFAULT_GOVERNOR); 5055: 5056: ops->pm_resume(adreno_dev); 5057: 5058: err: 5059: kgsl_mutex_unlock(&device->mutex); 5060: return ret; 5061: } 5062: 5063: static const struct dev_pm_ops adreno_pm_ops = { 5064: .suspend = adreno_pm_suspend, 5065: .resume = adreno_pm_resume, 5066: .freeze = adreno_hibernation_suspend, 5067: .thaw = adreno_hibernation_resume, 5068: .poweroff = adreno_hibernation_suspend, 5069: .restore = adreno_hibernation_resume, 5070: }; 5071: #else 5072: static const struct dev_pm_ops adreno_pm_ops = { 5073: SET_SYSTEM_SLEEP_PM_OPS(adreno_pm_suspend, adreno_pm_resume) 5074: }; MATCH LINES: 5137 5125: 5126: module_param_named(gpu_speed_bin_override, kgsl_gpu_speed_bin_override, uint, 0600); 5127: MODULE_PARM_DESC(gpu_speed_bin_override, "Override GPU speed bin"); 5128: 5129: module_param_named(slice_mask_override, adreno_slice_mask_override, uint, 0600); 5130: MODULE_PARM_DESC(slice_mask_override, "Override GPU slice mask"); 5131: 5132: module_init(kgsl_3d_init); 5133: module_exit(kgsl_3d_exit); 5134: 5135: MODULE_DESCRIPTION("3D Graphics driver"); 5136: MODULE_LICENSE("GPL v2"); 5137: MODULE_SOFTDEP("pre: arm_smmu nvmem_qfprom socinfo governor_msm_adreno_tz governor_gpubw_mon governor_msm_adreno_ro"); 5138: #if (KERNEL_VERSION(6, 13, 0) <= LINUX_VERSION_CODE) 5139: MODULE_IMPORT_NS("DMA_BUF"); 5140: #elif (KERNEL_VERSION(5, 18, 0) <= LINUX_VERSION_CODE) 5141: MODULE_IMPORT_NS(DMA_BUF); 5142: #endif --- FILE: \adreno.h | HITS: 19 --- MATCH LINES: 22, 23 10: #include 11: #include 12: #include 13: #include "adreno_coresight.h" 14: #include "adreno_dispatch.h" 15: #include "adreno_drawctxt.h" 16: #include "adreno_hwsched.h" 17: #include "adreno_perfcounter.h" 18: #include "adreno_profile.h" 19: #include "adreno_ringbuffer.h" 20: #include "kgsl_sharedmem.h" 21: 22: /* Used to point CP to the SMMU record during preemption */ 23: #define SET_PSEUDO_SMMU_INFO 0 24: /* Used to inform CP where to save preemption data at the time of switch out */ 25: #define SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR 1 26: /* Used to inform CP where to save secure preemption data at the time of switch out */ 27: #define SET_PSEUDO_PRIV_SECURE_SAVE_ADDR 2 28: /* Used to inform CP where to save per context non-secure data at the time of switch out */ 29: #define SET_PSEUDO_NON_PRIV_SAVE_ADDR 3 30: /* Used to inform CP where to save preemption counter data at the time of switch out */ 31: #define SET_PSEUDO_COUNTER 4 32: 33: /* Index to preemption scratch buffer to store current QOS value */ 34: #define QOS_VALUE_IDX KGSL_PRIORITY_MAX_RB_LEVELS 35: 36: /* Size of the user context record block (in bytes) */ 37: #define ADRENO_CP_CTXRECORD_USER_RESTORE_SIZE (192 * SZ_1K) 38: 39: /* ADRENO_DEVICE - Given a kgsl_device return the adreno device struct */ 40: #define ADRENO_DEVICE(device) \ 41: container_of(device, struct adreno_device, dev) 42: 43: /* KGSL_DEVICE - given an adreno_device, return the KGSL device struct */ 44: #define KGSL_DEVICE(_dev) (&((_dev)->dev)) 45: 46: /* ADRENO_CONTEXT - Given a context return the adreno context struct */ 47: #define ADRENO_CONTEXT(context) \ MATCH LINES: 225 213: #define ADRENO_QUIRK_FAULT_DETECT_MASK BIT(2) 214: /* Disable RB sampler datapath clock gating optimization */ 215: #define ADRENO_QUIRK_DISABLE_RB_DP2CLOCKGATING BIT(3) 216: /* Disable local memory(LM) feature to avoid corner case error */ 217: #define ADRENO_QUIRK_DISABLE_LMLOADKILL BIT(4) 218: /* Allow HFI to use registers to send message to GMU */ 219: #define ADRENO_QUIRK_HFI_USE_REG BIT(5) 220: /* Only set protected SECVID registers once */ 221: #define ADRENO_QUIRK_SECVID_SET_ONCE BIT(6) 222: /* 223: * Limit number of read and write transactions from 224: * UCHE block to GBIF to avoid possible deadlock 225: * between GBIF, SMMU and MEMNOC. 226: */ 227: #define ADRENO_QUIRK_LIMIT_UCHE_GBIF_RW BIT(8) 228: /* Do explicit mode control of cx gdsc */ 229: #define ADRENO_QUIRK_CX_GDSC BIT(9) 230: 231: /* Command identifiers */ 232: #define CONTEXT_TO_MEM_IDENTIFIER 0x2EADBEEF 233: #define CMD_IDENTIFIER 0x2EEDFACE 234: #define CMD_INTERNAL_IDENTIFIER 0x2EEDD00D 235: #define START_IB_IDENTIFIER 0x2EADEABE 236: #define END_IB_IDENTIFIER 0x2ABEDEAD 237: #define START_PROFILE_IDENTIFIER 0x2DEFADE1 238: #define END_PROFILE_IDENTIFIER 0x2DEFADE2 239: #define PWRON_FIXUP_IDENTIFIER 0x2AFAFAFA 240: 241: /* One cannot wait forever for the core to idle, so set an upper limit to the 242: * amount of time to wait for the core to go idle 243: */ 244: #define ADRENO_IDLE_TIMEOUT (20 * 1000) 245: 246: #define ADRENO_FW_PFP 0 247: #define ADRENO_FW_SQE 0 248: #define ADRENO_FW_PM4 1 249: #define ADRENO_FW_AQE 1 MATCH LINES: 340 328: ADRENO_REV_GEN8_6_0 = ADRENO_GPUREV_VALUE(8, 6, 0), 329: ADRENO_REV_GEN8_8_0 = ADRENO_GPUREV_VALUE(8, 8, 0), 330: ADRENO_REV_GEN8_9_0 = ADRENO_GPUREV_VALUE(8, 9, 0), 331: ADRENO_REV_GEN8_10_0 = ADRENO_GPUREV_VALUE(8, 10, 0), 332: ADRENO_REV_GEN8_11_0 = ADRENO_GPUREV_VALUE(8, 11, 0), 333: ADRENO_REV_GEN8_11_1 = ADRENO_GPUREV_VALUE(8, 11, 1), 334: ADRENO_REV_GEN8_14_0 = ADRENO_GPUREV_VALUE(8, 14, 0), 335: }; 336: 337: #define ADRENO_SOFT_FAULT BIT(0) 338: #define ADRENO_HARD_FAULT BIT(1) 339: #define ADRENO_TIMEOUT_FAULT BIT(2) 340: #define ADRENO_IOMMU_STALL_ON_PAGE_FAULT BIT(3) 341: #define ADRENO_PREEMPT_FAULT BIT(4) 342: #define ADRENO_GMU_FAULT BIT(5) 343: #define ADRENO_CTX_DETATCH_TIMEOUT_FAULT BIT(6) 344: #define ADRENO_GMU_FAULT_SKIP_SNAPSHOT BIT(7) 345: #define ADRENO_FAULT_TYPES 8 346: 347: /** 348: * Bit fields for GPU_CX_MISC_CX_AHB_*_CNTL registers 349: * AHB_TXFRTIMEOUTRELEASE [8:8] 350: * AHB_TXFRTIMEOUTENABLE [9:9] 351: * AHB_RESPONDERROR [11:11] 352: * AHB_ERRORSTATUSENABLE [12:12] 353: */ 354: #define ADRENO_AHB_CNTL_DEFAULT (BIT(12) | BIT(11) | BIT(9) | BIT(8)) 355: 356: enum adreno_pipe_type { 357: PIPE_NONE = 0, 358: PIPE_BR = 1, 359: PIPE_BV = 2, 360: PIPE_LPAC = 3, 361: PIPE_AQE0 = 4, 362: PIPE_AQE1 = 5, 363: PIPE_DDE_BR = 6, 364: PIPE_DDE_BV = 7, MATCH LINES: 622, 623, 624, 625 610: * Consists of pairs of fuse, index mappings, terminated with 611: * {SHRT_MAX, 0} sentinel. 612: */ 613: struct kgsl_speedbin *speedbins; 614: /** @ubwc_mode: Supported UBWC mode */ 615: u32 ubwc_mode; 616: /** @mal: Minimum access length */ 617: u32 mal; 618: /** @highest_bank_bit: The bit of the highest DDR bank */ 619: u32 highest_bank_bit; 620: /** @gpu_model: Gpu model name */ 621: const char *gpu_model; 622: /** @smmu_aperture: List of registers and values to write for SMMU aperture */ 623: const struct kgsl_regmap_list *smmu_aperture; 624: /** @smmu_aperture_count: Number of registers in @smmu_aperture */ 625: u32 smmu_aperture_count; 626: }; 627: 628: /** 629: * struct adreno_dispatch_ops - Common functions for dispatcher operations 630: */ 631: struct adreno_dispatch_ops { 632: /* @close: Shut down the dispatcher */ 633: void (*close)(struct adreno_device *adreno_dev); 634: /* @queue_cmds: Queue a command on the context */ 635: int (*queue_cmds)(struct kgsl_device_private *dev_priv, 636: struct kgsl_context *context, struct kgsl_drawobj *drawobj[], 637: u32 count, u32 *timestamp); 638: /* @queue_context: Queue a context to be dispatched */ 639: void (*queue_context)(struct adreno_device *adreno_dev, 640: struct adreno_context *drawctxt); 641: int (*setup_context)(struct adreno_device *adreno_dev, 642: struct adreno_context *drawctxt); 643: /* @create_hw_fence: Create a hardware fence */ 644: void (*create_hw_fence)(struct adreno_device *adreno_dev, struct kgsl_sync_fence *kfence); 645: }; 646: 647: /** 648: * struct adreno_fault_proc - Structure to hold data on faulting processes 649: */ MATCH LINES: 714 702: * @lm_size: The dword size of the LM sequence 703: * @lm_limit: limiting value for LM 704: * @lm_threshold_count: register value for counter for lm threshold breakin 705: * @lm_threshold_cross: number of current peaks exceeding threshold 706: * @ifpc_count: Number of times the GPU went into IFPC 707: * @highest_bank_bit: Value of the highest bank bit 708: * @gpmu_throttle_counters - counters for number of throttled clocks 709: * @irq_storm_work: Worker to handle possible interrupt storms 710: * @active_list: List to track active contexts 711: * @active_list_lock: Lock to protect active_list 712: * @gpu_llc_slice: GPU system cache slice descriptor 713: * @gpu_llc_slice_enable: To enable the GPU system cache slice or not 714: * @gpuhtw_llc_slice: GPU pagetables system cache slice descriptor 715: * @gpuhtw_llc_slice_enable: To enable the GPUHTW system cache slice or not 716: * @gpumv_llc_slice: GPU MV buffer system cache slice descriptor 717: * @gpumv_llc_slice_enable: To enable GPUMV buffer system cache slice or not 718: * @zap_loaded: Used to track if zap was successfully loaded or not 719: */ 720: struct adreno_device { 721: struct kgsl_device dev; /* Must be first field in this struct */ 722: unsigned long priv; 723: unsigned int chipid; 724: /** @uche_gmem_base: Base address of GMEM for UCHE access */ 725: u64 uche_gmem_base; 726: const struct adreno_gpu_core *gpucore; 727: struct adreno_firmware fw[2]; 728: size_t gpmu_cmds_size; 729: unsigned int *gpmu_cmds; 730: struct adreno_ringbuffer ringbuffers[KGSL_PRIORITY_MAX_RB_LEVELS]; 731: int num_ringbuffers; 732: struct adreno_ringbuffer *cur_rb; 733: struct adreno_ringbuffer *next_rb; 734: struct adreno_ringbuffer *prev_rb; 735: unsigned long ft_policy; 736: bool long_ib_detect; 737: bool cooperative_reset; 738: struct adreno_profile profile; MATCH LINES: 1108 1096: int (*start)(struct adreno_device *adreno_dev); 1097: int (*regulator_enable)(struct adreno_device *adreno_dev); 1098: void (*regulator_disable)(struct adreno_device *adreno_dev); 1099: void (*pwrlevel_change_settings)(struct adreno_device *adreno_dev, 1100: unsigned int prelevel, unsigned int postlevel, 1101: bool post); 1102: void (*preemption_schedule)(struct adreno_device *adreno_dev); 1103: void (*context_detach)(struct adreno_context *drawctxt); 1104: void (*pre_reset)(struct adreno_device *adreno_dev); 1105: void (*gpu_keepalive)(struct adreno_device *adreno_dev, 1106: bool state); 1107: bool (*hw_isidle)(struct adreno_device *adreno_dev); 1108: const char *(*iommu_fault_block)(struct kgsl_device *device, 1109: unsigned int fsynr1); 1110: int (*reset)(struct adreno_device *adreno_dev); 1111: /** @soft_reset: Soft reset GPU on fault recovery */ 1112: int (*soft_reset)(struct adreno_device *adreno_dev, 1113: struct kgsl_context *context, bool ctx_guilty); 1114: /** @read_alwayson: Return the current value of the alwayson counter */ 1115: u64 (*read_alwayson)(struct adreno_device *adreno_dev); 1116: /** 1117: * @power_ops: Target specific function pointers to power up/down the 1118: * gpu 1119: */ 1120: const struct adreno_power_ops *power_ops; 1121: int (*clear_pending_transactions)(struct adreno_device *adreno_dev); 1122: void (*deassert_gbif_halt)(struct adreno_device *adreno_dev); 1123: int (*ringbuffer_submitcmd)(struct adreno_device *adreno_dev, 1124: struct kgsl_drawobj_cmd *cmdobj, u32 flags, 1125: struct adreno_submit_time *time); 1126: /** 1127: * @is_hw_collapsible: Return true if the hardware can be collapsed. 1128: * Only used by non GMU/RGMU targets 1129: */ 1130: bool (*is_hw_collapsible)(struct adreno_device *adreno_dev); 1131: /** 1132: * @power_stats - Return the perfcounter statistics for DCVS MATCH LINES: 1942, 1950, 1951, 1961, 1962, 1965 1930: !test_bit(ADRENO_DEVICE_ISDB_ENABLED, &adreno_dev->priv); 1931: } 1932: 1933: /** 1934: * adreno_support_64bit - Return true if the GPU supports 64 bit addressing 1935: * @adreno_dev: An Adreno GPU device handle 1936: * 1937: * Return: True if the device supports 64 bit addressing 1938: */ 1939: static inline bool adreno_support_64bit(struct adreno_device *adreno_dev) 1940: { 1941: /* 1942: * The IOMMU API takes a unsigned long for the iova so we can't support 1943: * 64 bit addresses when the kernel is in 32 bit mode even if we wanted 1944: * so we need to check that we are using a5xx or newer and that the 1945: * unsigned long is big enough for our purposes. 1946: */ 1947: return (BITS_PER_LONG > 32 && ADRENO_GPUREV(adreno_dev) >= 500); 1948: } 1949: 1950: static inline void adreno_ringbuffer_set_pagetable(struct kgsl_device *device, 1951: struct adreno_ringbuffer *rb, struct kgsl_pagetable *pt) 1952: { 1953: unsigned long flags; 1954: 1955: spin_lock_irqsave(&rb->preempt_lock, flags); 1956: 1957: kgsl_sharedmem_writel(device->scratch, 1958: SCRATCH_RB_OFFSET(rb->id, current_rb_ptname), pt->name); 1959: 1960: kgsl_sharedmem_writeq(device->scratch, 1961: SCRATCH_RB_OFFSET(rb->id, ttbr0), 1962: kgsl_mmu_pagetable_get_ttbr0(pt)); 1963: 1964: kgsl_sharedmem_writel(device->scratch, 1965: SCRATCH_RB_OFFSET(rb->id, contextidr), 0); 1966: 1967: spin_unlock_irqrestore(&rb->preempt_lock, flags); 1968: } 1969: 1970: static inline u32 counter_delta(struct kgsl_device *device, 1971: unsigned int reg, unsigned int *counter) 1972: { 1973: u32 val, ret = 0; 1974: 1975: if (!reg) 1976: return 0; 1977: 1978: kgsl_regread(device, reg, &val); 1979: 1980: if (*counter) { 1981: if (val >= *counter) 1982: ret = val - *counter; 1983: else 1984: ret = (UINT_MAX - *counter) + val; 1985: } 1986: 1987: *counter = val; 1988: return ret; 1989: } MATCH LINES: 2325, 2328, 2330 2313: * adreno_get_gpu_model - Gets gpu model name from device tree (or) chipid 2314: * @device: A GPU device handle 2315: * 2316: * Return: GPU model name string 2317: */ 2318: const char *adreno_get_gpu_model(struct kgsl_device *device); 2319: 2320: int adreno_verify_cmdobj(struct kgsl_device_private *dev_priv, 2321: struct kgsl_context *context, struct kgsl_drawobj *drawobj[], 2322: uint32_t count); 2323: 2324: /** 2325: * adreno_smmu_is_stalled() - Check whether smmu is stalled or not 2326: * @device: Pointer to adreno device 2327: * 2328: * Return - True if smmu is stalled or false otherwise 2329: */ 2330: bool adreno_smmu_is_stalled(struct adreno_device *adreno_dev); 2331: 2332: /** 2333: * adreno_get_ahb_timeout_val() - Get the ahb_timeout value 2334: * @adreno_dev: Adreno device handle 2335: * @noc_timeout_us: GPU config NOC timeout value in usec 2336: * 2337: * Return - AHB timeout value to be programmed in AHB CNTL registers 2338: */ 2339: u32 adreno_get_ahb_timeout_val(struct adreno_device *adreno_dev, u32 noc_timeout_us); 2340: 2341: /** 2342: * adreno_llcc_slice_deactivate - Deactivate GPU and GPUHTW llcc slices 2343: * @adreno_dev: Adreno device handle 2344: */ 2345: static inline void adreno_llcc_slice_deactivate(struct adreno_device *adreno_dev) 2346: { 2347: if (adreno_dev->gpu_llc_slice_enable && !IS_ERR_OR_NULL(adreno_dev->gpu_llc_slice)) 2348: llcc_slice_deactivate(adreno_dev->gpu_llc_slice); 2349: 2350: if (adreno_dev->gpuhtw_llc_slice_enable && !IS_ERR_OR_NULL(adreno_dev->gpuhtw_llc_slice)) 2351: llcc_slice_deactivate(adreno_dev->gpuhtw_llc_slice); 2352: 2353: if (adreno_dev->gpumv_llc_slice_enable && !IS_ERR_OR_NULL(adreno_dev->gpumv_llc_slice)) 2354: llcc_slice_deactivate(adreno_dev->gpumv_llc_slice); --- FILE: \adreno_a5xx.c | HITS: 5 --- MATCH LINES: 237, 264 225: { A5XX_CP_PROTECT_REG_0 + 8, 0x800, 6 }, 226: { A5XX_CP_PROTECT_REG_0 + 9, 0x840, 3 }, 227: { A5XX_CP_PROTECT_REG_0 + 10, 0x880, 5 }, 228: { A5XX_CP_PROTECT_REG_0 + 11, 0xaa0, 0 }, 229: /* RB */ 230: { A5XX_CP_PROTECT_REG_0 + 12, 0xcc0, 0 }, 231: { A5XX_CP_PROTECT_REG_0 + 13, 0xcf0, 1 }, 232: /* VPC */ 233: { A5XX_CP_PROTECT_REG_0 + 14, 0xe68, 3 }, 234: { A5XX_CP_PROTECT_REG_0 + 15, 0xe70, 4 }, 235: /* UCHE */ 236: { A5XX_CP_PROTECT_REG_0 + 16, 0xe80, 4 }, 237: /* A5XX_CP_PROTECT_REG_17 will be used for SMMU */ 238: /* A5XX_CP_PROTECT_REG_18 - A5XX_CP_PROTECT_REG_31 are available */ 239: }; 240: 241: static void _setprotectreg(struct kgsl_device *device, u32 offset, 242: u32 base, u32 count) 243: { 244: kgsl_regwrite(device, offset, 0x60000000 | (count << 24) | (base << 2)); 245: } 246: 247: static void a5xx_protect_init(struct adreno_device *adreno_dev) 248: { 249: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 250: u32 reg; 251: int i; 252: 253: /* enable access protection to privileged registers */ 254: kgsl_regwrite(device, A5XX_CP_PROTECT_CNTL, 0x00000007); 255: 256: for (i = 0; i < ARRAY_SIZE(a5xx_protected_blocks); i++) { 257: reg = a5xx_protected_blocks[i].reg; 258: 259: _setprotectreg(device, reg, a5xx_protected_blocks[i].base, 260: a5xx_protected_blocks[i].count); 261: } 262: 263: /* 264: * For a530 and a540 the SMMU region is 0x20000 bytes long and 0x10000 265: * bytes on all other targets. The base offset for both is 0x40000. 266: * Write it to the next available slot 267: */ 268: if (adreno_is_a530(adreno_dev) || adreno_is_a540(adreno_dev)) 269: _setprotectreg(device, reg + 1, 0x40000, ilog2(0x20000)); 270: else 271: _setprotectreg(device, reg + 1, 0x40000, ilog2(0x10000)); 272: } 273: 274: /* 275: * _poll_gdsc_status() - Poll the GDSC status register 276: * @adreno_dev: The adreno device pointer 277: * @status_reg: Offset of the status register 278: * @status_value: The expected bit value 279: * 280: * Poll the status register till the power-on bit is equal to the 281: * expected value or the max retries are exceeded. 282: */ 283: static int _poll_gdsc_status(struct adreno_device *adreno_dev, 284: unsigned int status_reg, 285: unsigned int status_value) 286: { 287: unsigned int reg, retry = PWR_RETRY; 288: MATCH LINES: 1498, 1500, 1503 1486: * VPC corner case with local memory load kill leads to corrupt 1487: * internal state. Normal Disable does not work for all a5x chips. 1488: * So do the following setting to disable it. 1489: */ 1490: if (ADRENO_QUIRK(adreno_dev, ADRENO_QUIRK_DISABLE_LMLOADKILL)) { 1491: kgsl_regrmw(device, A5XX_VPC_DBG_ECO_CNTL, 0, 0x1 << 23); 1492: kgsl_regrmw(device, A5XX_HLSQ_DBG_ECO_CNTL, 0x1 << 18, 0); 1493: } 1494: 1495: if (device->mmu.secured) { 1496: kgsl_regwrite(device, A5XX_RBBM_SECVID_TSB_CNTL, 0x0); 1497: kgsl_regwrite(device, A5XX_RBBM_SECVID_TSB_TRUSTED_BASE_LO, 1498: lower_32_bits(KGSL_IOMMU_SECURE_BASE32)); 1499: kgsl_regwrite(device, A5XX_RBBM_SECVID_TSB_TRUSTED_BASE_HI, 1500: upper_32_bits(KGSL_IOMMU_SECURE_BASE32)); 1501: kgsl_regwrite(device, A5XX_RBBM_SECVID_TSB_TRUSTED_SIZE, 1502: FIELD_PREP(GENMASK(31, 12), 1503: (KGSL_IOMMU_SECURE_SIZE(&device->mmu) / SZ_4K))); 1504: } 1505: 1506: a5xx_preemption_start(adreno_dev); 1507: a5xx_protect_init(adreno_dev); 1508: 1509: return 0; 1510: } 1511: 1512: /* 1513: * Follow the ME_INIT sequence with a preemption yield to allow the GPU to move 1514: * to a different ringbuffer, if desired 1515: */ 1516: static int _preemption_init( 1517: struct adreno_device *adreno_dev, 1518: struct adreno_ringbuffer *rb, unsigned int *cmds, 1519: struct kgsl_context *context) 1520: { 1521: unsigned int *cmds_orig = cmds; 1522: uint64_t gpuaddr = rb->preemption_desc->gpuaddr; 1523: 1524: /* Turn CP protection OFF */ 1525: cmds += cp_protected_mode(adreno_dev, cmds, 0); 1526: /* 1527: * CP during context switch will save context switch info to --- FILE: \adreno_a5xx.h | HITS: 6 --- MATCH LINES: 80, 83, 85, 87, 91, 94 68: struct a5xx_cp_preemption_record { 69: uint32_t magic; 70: uint32_t info; 71: uint32_t data; 72: uint32_t cntl; 73: uint32_t rptr; 74: uint32_t wptr; 75: uint64_t rptr_addr; 76: uint64_t rbase; 77: uint64_t counter; 78: }; 79: 80: #define A5XX_CP_SMMU_INFO_MAGIC_REF 0x3618CDA3UL 81: 82: /** 83: * struct a5xx_cp_smmu_info - CP preemption SMMU info. 84: * @magic: (00) The value at this offset must be equal to 85: * A5XX_CP_SMMU_INFO_MAGIC_REF. 86: * @_pad4: (04) Reserved/padding 87: * @ttbr0: (08) Base address of the page table for the 88: * incoming context. 89: * @context_idr: (16) Context Identification Register value. 90: */ 91: struct a5xx_cp_smmu_info { 92: uint32_t magic; 93: uint32_t _pad4; 94: uint64_t ttbr0; 95: uint32_t asid; 96: uint32_t context_idr; 97: }; 98: 99: void a5xx_snapshot(struct adreno_device *adreno_dev, 100: struct kgsl_snapshot *snapshot); 101: unsigned int a5xx_num_registers(void); 102: 103: void a5xx_crashdump_init(struct adreno_device *adreno_dev); 104: 105: void a5xx_hwcg_set(struct adreno_device *adreno_dev, bool on); 106: 107: #define A5XX_CP_RB_CNTL_DEFAULT ((1 << 27) | ((ilog2(4) << 8) & 0x1F00) | \ 108: (ilog2(KGSL_RB_DWORDS >> 1) & 0x3F)) 109: /* GPMU interrupt multiplexor */ 110: #define FW_INTR_INFO (0) 111: #define LLM_ACK_ERR_INTR (1) 112: #define ISENS_TRIM_ERR_INTR (2) 113: #define ISENS_ERR_INTR (3) 114: #define ISENS_IDLE_ERR_INTR (4) 115: #define ISENS_PWR_ON_ERR_INTR (5) 116: #define WDOG_EXPITED (31) 117: 118: #define VALID_GPMU_IRQ (\ --- FILE: \adreno_a5xx_preempt.c | HITS: 41 --- MATCH LINES: 16, 17 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include "adreno.h" 8: #include "adreno_a5xx.h" 9: #include "adreno_pm4types.h" 10: #include "adreno_trace.h" 11: #include "kgsl_util.h" 12: 13: #define PREEMPT_RECORD(_field) \ 14: offsetof(struct a5xx_cp_preemption_record, _field) 15: 16: #define PREEMPT_SMMU_RECORD(_field) \ 17: offsetof(struct a5xx_cp_smmu_info, _field) 18: 19: static void _update_wptr(struct adreno_device *adreno_dev, bool reset_timer) 20: { 21: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 22: struct adreno_ringbuffer *rb = adreno_dev->cur_rb; 23: unsigned int wptr; 24: unsigned long flags; 25: 26: spin_lock_irqsave(&rb->preempt_lock, flags); 27: 28: kgsl_regread(device, A5XX_CP_RB_WPTR, &wptr); 29: 30: if (wptr != rb->wptr) { 31: kgsl_regwrite(device, A5XX_CP_RB_WPTR, rb->wptr); 32: /* 33: * In case something got submitted while preemption was on 34: * going, reset the timer. 35: */ 36: reset_timer = true; 37: } 38: 39: if (reset_timer) 40: rb->dispatch_q.expires = jiffies + 41: msecs_to_jiffies(adreno_drawobj_timeout); MATCH LINES: 172, 174, 175 160: spin_unlock_irqrestore(&rb->preempt_lock, flags); 161: 162: if (!empty) 163: return rb; 164: } 165: 166: return NULL; 167: } 168: 169: void a5xx_preemption_trigger(struct adreno_device *adreno_dev) 170: { 171: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 172: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 173: struct adreno_ringbuffer *next; 174: uint64_t ttbr0; 175: unsigned int contextidr; 176: unsigned long flags; 177: 178: /* Put ourselves into a possible trigger state */ 179: if (!adreno_move_preempt_state(adreno_dev, 180: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START)) 181: return; 182: 183: /* Get the next ringbuffer to preempt in */ 184: next = a5xx_next_ringbuffer(adreno_dev); 185: 186: /* 187: * Nothing to do if every ringbuffer is empty or if the current 188: * ringbuffer is the only active one 189: */ 190: if (next == NULL || next == adreno_dev->cur_rb) { 191: /* 192: * Update any critical things that might have been skipped while 193: * we were looking for a new ringbuffer 194: */ 195: 196: if (next != NULL) { 197: _update_wptr(adreno_dev, false); 198: 199: mod_timer(&adreno_dev->dispatcher.timer, MATCH LINES: 217, 218, 219, 220, 221, 228, 230, 231, 232, 233 205: } 206: 207: /* Turn off the dispatcher timer */ 208: kgsl_delete_timer(&adreno_dev->dispatcher.timer); 209: 210: /* 211: * This is the most critical section - we need to take care not to race 212: * until we have programmed the CP for the switch 213: */ 214: 215: spin_lock_irqsave(&next->preempt_lock, flags); 216: 217: /* Get the pagetable from the pagetable info. */ 218: kgsl_sharedmem_readq(device->scratch, &ttbr0, 219: SCRATCH_RB_OFFSET(next->id, ttbr0)); 220: kgsl_sharedmem_readl(device->scratch, &contextidr, 221: SCRATCH_RB_OFFSET(next->id, contextidr)); 222: 223: kgsl_sharedmem_writel(next->preemption_desc, 224: PREEMPT_RECORD(wptr), next->wptr); 225: 226: spin_unlock_irqrestore(&next->preempt_lock, flags); 227: 228: /* And write it to the smmu info */ 229: if (kgsl_mmu_is_perprocess(&device->mmu)) { 230: kgsl_sharedmem_writeq(iommu->smmu_info, 231: PREEMPT_SMMU_RECORD(ttbr0), ttbr0); 232: kgsl_sharedmem_writel(iommu->smmu_info, 233: PREEMPT_SMMU_RECORD(context_idr), contextidr); 234: } 235: 236: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_LO, 237: lower_32_bits(next->preemption_desc->gpuaddr)); 238: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_RESTORE_ADDR_HI, 239: upper_32_bits(next->preemption_desc->gpuaddr)); 240: 241: adreno_dev->next_rb = next; 242: 243: /* Start the timer to detect a stuck preemption */ 244: mod_timer(&adreno_dev->preempt.timer, 245: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT)); 246: 247: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id, 248: 1, 0); 249: 250: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED); 251: 252: /* Trigger the preemption */ 253: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_CNTL, 1); 254: } 255: 256: void a5xx_preempt_callback(struct adreno_device *adreno_dev, int bit) 257: { MATCH LINES: 416, 426, 429, 430, 431, 432, 433, 436, 437, 438, 439, 441, 442, 444, 445, 458, 459 404: /* Write NULL to the address to skip the data write */ 405: dwords += cp_gpuaddr(adreno_dev, &cmds[dwords], 0x0); 406: cmds[dwords++] = 1; 407: /* generate interrupt on preemption completion */ 408: cmds[dwords++] = 1; 409: 410: return dwords; 411: } 412: 413: void a5xx_preemption_start(struct adreno_device *adreno_dev) 414: { 415: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 416: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 417: struct adreno_ringbuffer *rb; 418: unsigned int i; 419: 420: if (!adreno_is_preemption_enabled(adreno_dev)) 421: return; 422: 423: /* Force the state to be clear */ 424: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE); 425: 426: /* Only set up smmu info when per-process pagetables are enabled */ 427: 428: if (kgsl_mmu_is_perprocess(&device->mmu)) { 429: /* smmu_info is allocated and mapped in a5xx_preemption_iommu_init */ 430: kgsl_sharedmem_writel(iommu->smmu_info, 431: PREEMPT_SMMU_RECORD(magic), A5XX_CP_SMMU_INFO_MAGIC_REF); 432: kgsl_sharedmem_writeq(iommu->smmu_info, 433: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device)); 434: 435: /* The CP doesn't use the asid record, so poison it */ 436: kgsl_sharedmem_writel(iommu->smmu_info, 437: PREEMPT_SMMU_RECORD(asid), 0xDECAFBAD); 438: kgsl_sharedmem_writel(iommu->smmu_info, 439: PREEMPT_SMMU_RECORD(context_idr), 0); 440: 441: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO, 442: lower_32_bits(iommu->smmu_info->gpuaddr)); 443: 444: kgsl_regwrite(device, A5XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI, 445: upper_32_bits(iommu->smmu_info->gpuaddr)); 446: } 447: 448: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 449: /* 450: * preemption_desc is allocated and mapped at init time, 451: * so no need to check sharedmem_writel return value 452: */ 453: kgsl_sharedmem_writel(rb->preemption_desc, 454: PREEMPT_RECORD(rptr), 0); 455: kgsl_sharedmem_writel(rb->preemption_desc, 456: PREEMPT_RECORD(wptr), 0); 457: 458: adreno_ringbuffer_set_pagetable(device, rb, 459: device->mmu.defaultpagetable); 460: } 461: 462: } 463: 464: static int a5xx_preemption_ringbuffer_init(struct adreno_device *adreno_dev, 465: struct adreno_ringbuffer *rb, uint64_t counteraddr) 466: { 467: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 468: 469: if (IS_ERR_OR_NULL(rb->preemption_desc)) 470: rb->preemption_desc = kgsl_allocate_global(device, 471: A5XX_CP_CTXRECORD_SIZE_IN_BYTES, SZ_16K, 0, 472: KGSL_MEMDESC_PRIVILEGED, "preemption_desc"); 473: 474: if (IS_ERR(rb->preemption_desc)) 475: return PTR_ERR(rb->preemption_desc); 476: 477: kgsl_sharedmem_writel(rb->preemption_desc, 478: PREEMPT_RECORD(magic), A5XX_CP_CTXRECORD_MAGIC_REF); 479: kgsl_sharedmem_writel(rb->preemption_desc, 480: PREEMPT_RECORD(info), 0); 481: kgsl_sharedmem_writel(rb->preemption_desc, 482: PREEMPT_RECORD(data), 0); 483: kgsl_sharedmem_writel(rb->preemption_desc, MATCH LINES: 503, 510, 511, 538, 539, 540, 542, 544, 545 491: rb->id, rptr)); 492: kgsl_sharedmem_writeq(rb->preemption_desc, 493: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr); 494: kgsl_sharedmem_writeq(rb->preemption_desc, 495: PREEMPT_RECORD(counter), counteraddr); 496: 497: return 0; 498: } 499: 500: int a5xx_preemption_init(struct adreno_device *adreno_dev) 501: { 502: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 503: struct kgsl_iommu *iommu = KGSL_IOMMU(device); 504: struct adreno_preemption *preempt = &adreno_dev->preempt; 505: struct adreno_ringbuffer *rb; 506: int ret; 507: unsigned int i; 508: uint64_t addr; 509: 510: /* We are dependent on IOMMU to make preemption go on the CP side */ 511: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU) 512: return -ENODEV; 513: 514: INIT_WORK(&preempt->work, _a5xx_preemption_worker); 515: 516: /* Allocate mem for storing preemption counters */ 517: if (IS_ERR_OR_NULL(preempt->scratch)) 518: preempt->scratch = kgsl_allocate_global(device, 519: adreno_dev->num_ringbuffers * 520: A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE, 0, 0, 0, 521: "preemption_counters"); 522: 523: ret = PTR_ERR_OR_ZERO(preempt->scratch); 524: if (ret) 525: return ret; 526: 527: addr = preempt->scratch->gpuaddr; 528: 529: /* Allocate mem for storing preemption switch record */ 530: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) { 531: ret = a5xx_preemption_ringbuffer_init(adreno_dev, rb, addr); 532: if (ret) 533: return ret; 534: 535: addr += A5XX_CP_CTXRECORD_PREEMPTION_COUNTER_SIZE; 536: } 537: 538: /* Allocate mem for storing preemption smmu record */ 539: if (kgsl_mmu_is_perprocess(&device->mmu) && IS_ERR_OR_NULL(iommu->smmu_info)) 540: iommu->smmu_info = kgsl_allocate_global(device, PAGE_SIZE, 0, 541: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED, 542: "smmu_info"); 543: 544: if (IS_ERR(iommu->smmu_info)) 545: return PTR_ERR(iommu->smmu_info); 546: 547: set_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv); 548: return 0; 549: } --- FILE: \adreno_a5xx_ringbuffer.c | HITS: 16 --- MATCH LINES: 14, 17, 19, 22, 25, 26, 27, 37, 39, 40, 41 2: /* 3: * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. 4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. 5: */ 6: 7: #include "adreno.h" 8: #include "adreno_a5xx.h" 9: #include "adreno_pm4types.h" 10: #include "adreno_ringbuffer.h" 11: #include "adreno_trace.h" 12: #include "kgsl_trace.h" 13: 14: static int a5xx_rb_pagetable_switch(struct kgsl_device *device, 15: struct adreno_context *drawctxt, 16: struct adreno_ringbuffer *rb, 17: struct kgsl_pagetable *pagetable, u32 *cmds) 18: { 19: u64 ttbr0 = kgsl_mmu_pagetable_get_ttbr0(pagetable); 20: u32 id = drawctxt ? drawctxt->base.id : 0; 21: 22: if (pagetable == device->mmu.defaultpagetable) 23: return 0; 24: 25: cmds[0] = cp_type7_packet(CP_SMMU_TABLE_UPDATE, 3); 26: cmds[1] = lower_32_bits(ttbr0); 27: cmds[2] = upper_32_bits(ttbr0); 28: cmds[3] = id; 29: 30: cmds[4] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 31: cmds[5] = cp_type7_packet(CP_WAIT_FOR_ME, 0); 32: cmds[6] = cp_type4_packet(A5XX_CP_CNTL, 1); 33: cmds[7] = 1; 34: 35: cmds[8] = cp_type7_packet(CP_MEM_WRITE, 5); 36: cmds[9] = lower_32_bits(SCRATCH_RB_GPU_ADDR(device, 37: rb->id, ttbr0)); 38: cmds[10] = upper_32_bits(SCRATCH_RB_GPU_ADDR(device, 39: rb->id, ttbr0)); 40: cmds[11] = lower_32_bits(ttbr0); 41: cmds[12] = upper_32_bits(ttbr0); 42: cmds[13] = id; 43: 44: cmds[14] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0); 45: cmds[15] = cp_type7_packet(CP_WAIT_FOR_ME, 0); 46: cmds[16] = cp_type4_packet(A5XX_CP_CNTL, 1); 47: cmds[17] = 0; 48: 49: return 18; 50: } 51: 52: #define RB_SOPTIMESTAMP(device, rb) \ 53: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp) 54: #define CTXT_SOPTIMESTAMP(device, drawctxt) \ 55: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp) 56: 57: #define RB_EOPTIMESTAMP(device, rb) \ 58: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp) 59: #define CTXT_EOPTIMESTAMP(device, drawctxt) \ 60: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp) 61: 62: int a5xx_ringbuffer_submit(struct adreno_ringbuffer *rb, 63: struct adreno_submit_time *time, bool sync) 64: { 65: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); MATCH LINES: 337, 338, 343, 344, 345 325: cmds[2] = upper_32_bits(gpuaddr); 326: cmds[3] = dwords; 327: 328: rb->profile_index = (rb->profile_index + 1) % PROFILE_IB_SLOTS; 329: 330: return 4; 331: } 332: 333: static int a5xx_rb_context_switch(struct adreno_device *adreno_dev, 334: struct adreno_ringbuffer *rb, 335: struct adreno_context *drawctxt) 336: { 337: struct kgsl_pagetable *pagetable = 338: adreno_drawctxt_get_pagetable(drawctxt); 339: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 340: int count = 0; 341: u32 cmds[32]; 342: 343: if (adreno_drawctxt_get_pagetable(rb->drawctxt_active) != pagetable) 344: count += a5xx_rb_pagetable_switch(device, drawctxt, 345: rb, pagetable, cmds); 346: 347: cmds[count++] = cp_type7_packet(CP_NOP, 1); 348: cmds[count++] = CONTEXT_TO_MEM_IDENTIFIER; 349: 350: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 351: cmds[count++] = lower_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb, 352: current_context)); 353: cmds[count++] = upper_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb, 354: current_context)); 355: cmds[count++] = drawctxt->base.id; 356: 357: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3); 358: cmds[count++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device, 359: KGSL_MEMSTORE_GLOBAL, current_context)); 360: cmds[count++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device, 361: KGSL_MEMSTORE_GLOBAL, current_context)); 362: cmds[count++] = drawctxt->base.id; 363: 364: cmds[count++] = cp_type4_packet(A5XX_UCHE_INVALIDATE0, 1); 365: cmds[count++] = 0x12; 366: 367: return a5xx_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED, 368: cmds, count, 0, NULL); 369: } --- FILE: \adreno_a5xx_snapshot.c | HITS: 2 --- MATCH LINES: 737, 738 725: { 726: unsigned long wait_time; 727: unsigned int reg = 0; 728: 729: crash_dump_valid = false; 730: 731: if (!device->snapshot_crashdumper) 732: return; 733: 734: if (IS_ERR_OR_NULL(capturescript) || IS_ERR_OR_NULL(registers)) 735: return; 736: 737: /* IF the SMMU is stalled we cannot do a crash dump */ 738: if (adreno_smmu_is_stalled(ADRENO_DEVICE(device))) 739: return; 740: 741: /* Turn on APRIV so we can access the buffers */ 742: kgsl_regwrite(device, A5XX_CP_CNTL, 1); 743: 744: kgsl_regwrite(device, A5XX_CP_CRASH_SCRIPT_BASE_LO, 745: lower_32_bits(capturescript->gpuaddr)); 746: kgsl_regwrite(device, A5XX_CP_CRASH_SCRIPT_BASE_HI, 747: upper_32_bits(capturescript->gpuaddr)); 748: kgsl_regwrite(device, A5XX_CP_CRASH_DUMP_CNTL, 1); 749: 750: wait_time = jiffies + msecs_to_jiffies(CP_CRASH_DUMPER_TIMEOUT); 751: while (!time_after(jiffies, wait_time)) { 752: kgsl_regread(device, A5XX_CP_CRASH_DUMP_CNTL, ®); 753: if (reg & 0x4) 754: break; 755: cpu_relax(); 756: } 757: 758: kgsl_regwrite(device, A5XX_CP_CNTL, 0); 759: 760: if (!(reg & 0x4)) { 761: dev_err(device->dev, "Crash dump timed out: 0x%X\n", reg); 762: return; --- FILE: \adreno_a6xx.c | HITS: 18 --- MATCH LINES: 580, 582, 585 568: static void a6xx_llc_configure_gpumv_scid(struct adreno_device *adreno_dev); 569: static void a6xx_llc_enable_overrides(struct adreno_device *adreno_dev); 570: 571: static void a6xx_set_secvid(struct kgsl_device *device) 572: { 573: static bool set; 574: 575: if (set || !device->mmu.secured) 576: return; 577: 578: kgsl_regwrite(device, A6XX_RBBM_SECVID_TSB_CNTL, 0x0); 579: kgsl_regwrite(device, A6XX_RBBM_SECVID_TSB_TRUSTED_BASE_LO, 580: lower_32_bits(KGSL_IOMMU_SECURE_BASE32)); 581: kgsl_regwrite(device, A6XX_RBBM_SECVID_TSB_TRUSTED_BASE_HI, 582: upper_32_bits(KGSL_IOMMU_SECURE_BASE32)); 583: kgsl_regwrite(device, A6XX_RBBM_SECVID_TSB_TRUSTED_SIZE, 584: FIELD_PREP(GENMASK(31, 12), 585: (KGSL_IOMMU_SECURE_SIZE(&device->mmu) / SZ_4K))); 586: 587: if (ADRENO_QUIRK(ADRENO_DEVICE(device), ADRENO_QUIRK_SECVID_SET_ONCE)) 588: set = true; 589: } 590: 591: static void a6xx_deassert_gbif_halt(struct adreno_device *adreno_dev) 592: { 593: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 594: 595: kgsl_regwrite(device, A6XX_GBIF_HALT, 0x0); 596: 597: if (adreno_is_a619_holi(adreno_dev)) 598: kgsl_regwrite(device, A6XX_RBBM_GPR0_CNTL, 0x0); 599: else 600: kgsl_regwrite(device, A6XX_RBBM_GBIF_HALT, 0x0); 601: } 602: 603: bool a6xx_gx_is_on(struct adreno_device *adreno_dev) 604: { 605: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 606: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 607: bool gdsc_on, clk_on; 608: 609: clk_on = __clk_is_enabled(pwr->grp_clks[0]); MATCH LINES: 1612, 1632, 1649, 1652, 1673, 1695, 1697, 1731 1600: if (IS_ERR_OR_NULL(adreno_dev->gpu_llc_slice) || 1601: !adreno_dev->gpu_llc_slice_enable) 1602: return; 1603: 1604: if (llcc_slice_activate(adreno_dev->gpu_llc_slice)) 1605: return; 1606: 1607: gpu_scid = llcc_get_slice_id(adreno_dev->gpu_llc_slice); 1608: for (i = 0; i < A6XX_LLC_NUM_GPU_SCIDS; i++) 1609: gpu_cntl1_val = (gpu_cntl1_val << A6XX_GPU_LLC_SCID_NUM_BITS) 1610: | gpu_scid; 1611: 1612: if (mmu->subtype == KGSL_IOMMU_SMMU_V500) 1613: kgsl_regrmw(device, A6XX_GBIF_SCACHE_CNTL1, 1614: A6XX_GPU_LLC_SCID_MASK, gpu_cntl1_val); 1615: else 1616: kgsl_regrmw(device, A6XX_GPU_CX_MISC_SYSTEM_CACHE_CNTL_1, 1617: A6XX_GPU_LLC_SCID_MASK, gpu_cntl1_val); 1618: 1619: /* 1620: * On A660, the SCID programming for UCHE traffic is done in 1621: * A6XX_GBIF_SCACHE_CNTL0[14:10] 1622: * GFO ENABLE BIT(8) : LLC uses a 64 byte cache line size enabling 1623: * GFO allows it allocate partial cache lines 1624: */ 1625: if (adreno_is_a660(adreno_dev) || 1626: adreno_is_a663(adreno_dev)) 1627: kgsl_regrmw(device, A6XX_GBIF_SCACHE_CNTL0, (0x1f << 10) | 1628: BIT(8), (gpu_scid << 10) | BIT(8)); 1629: } 1630: 1631: /* 1632: * a6xx_llc_configure_gpuhtw_scid() - Program the SCID for GPU pagetables 1633: * @adreno_dev: The adreno device pointer 1634: */ 1635: static void a6xx_llc_configure_gpuhtw_scid(struct adreno_device *adreno_dev) 1636: { 1637: uint32_t gpuhtw_scid; 1638: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1639: struct kgsl_mmu *mmu = &device->mmu; 1640: 1641: if (IS_ERR_OR_NULL(adreno_dev->gpuhtw_llc_slice) || 1642: !adreno_dev->gpuhtw_llc_slice_enable) 1643: return; 1644: 1645: if (llcc_slice_activate(adreno_dev->gpuhtw_llc_slice)) 1646: return; 1647: 1648: /* 1649: * On SMMU-v500, the GPUHTW SCID is configured via a NoC override in 1650: * the XBL image. 1651: */ 1652: if (mmu->subtype == KGSL_IOMMU_SMMU_V500) 1653: return; 1654: 1655: gpuhtw_scid = llcc_get_slice_id(adreno_dev->gpuhtw_llc_slice); 1656: 1657: kgsl_regrmw(device, A6XX_GPU_CX_MISC_SYSTEM_CACHE_CNTL_1, 1658: A6XX_GPUHTW_LLC_SCID_MASK, gpuhtw_scid << A6XX_GPUHTW_LLC_SCID_SHIFT); 1659: } 1660: 1661: /* 1662: * a6xx_llc_configure_gpumv_scid() - Program the sub-cache ID for CCU block 1663: * @adreno_dev: The adreno device pointer 1664: */ 1665: static void a6xx_llc_configure_gpumv_scid(struct adreno_device *adreno_dev) 1666: { 1667: u32 gpumv_scid = 0; 1668: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1669: struct kgsl_mmu *mmu = &device->mmu; 1670: 1671: if (IS_ERR_OR_NULL(adreno_dev->gpumv_llc_slice) || 1672: !adreno_dev->gpumv_llc_slice_enable || 1673: mmu->subtype != KGSL_IOMMU_SMMU_V500) 1674: return; 1675: 1676: if (llcc_slice_activate(adreno_dev->gpumv_llc_slice)) 1677: return; 1678: 1679: gpumv_scid = llcc_get_slice_id(adreno_dev->gpumv_llc_slice); 1680: kgsl_regrmw(device, A6XX_GBIF_SCACHE_CNTL1, 1681: A6XX_GPUMV_LLC_SCID_MASK, FIELD_PREP(GENMASK(19, 15), gpumv_scid)); 1682: } 1683: 1684: /* 1685: * a6xx_llc_enable_overrides() - Override the page attributes 1686: * @adreno_dev: The adreno device pointer 1687: */ 1688: static void a6xx_llc_enable_overrides(struct adreno_device *adreno_dev) 1689: { 1690: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1691: struct kgsl_mmu *mmu = &device->mmu; 1692: 1693: /* 1694: * Attributes override through GBIF is not supported with MMU-500. 1695: * Attributes are used as configured through SMMU pagetable entries. 1696: */ 1697: if (mmu->subtype == KGSL_IOMMU_SMMU_V500) 1698: return; 1699: 1700: /* 1701: * 0x3: readnoallocoverrideen=0 1702: * read-no-alloc=0 - Allocate lines on read miss 1703: * writenoallocoverrideen=1 1704: * write-no-alloc=1 - Do not allocates lines on write miss 1705: */ 1706: kgsl_regwrite(device, A6XX_GPU_CX_MISC_SYSTEM_CACHE_CNTL_0, 0x3); 1707: } 1708: 1709: static const char *uche_client[7][3] = { 1710: {"SP | VSC | VPC | HLSQ | PC | LRZ", "TP", "VFD"}, 1711: {"VSC | VPC | HLSQ | PC | LRZ", "TP | VFD", "SP"}, 1712: {"SP | VPC | HLSQ | PC | LRZ", "TP | VFD", "VSC"}, 1713: {"SP | VSC | HLSQ | PC | LRZ", "TP | VFD", "VPC"}, 1714: {"SP | VSC | VPC | PC | LRZ", "TP | VFD", "HLSQ"}, 1715: {"SP | VSC | VPC | HLSQ | LRZ", "TP | VFD", "PC"}, 1716: {"SP | VSC | VPC | HLSQ | PC", "TP | VFD", "LRZ"}, 1717: }; 1718: 1719: static const char *const uche_client_a660[] = { "VFD", "SP", "VSC", "VPC", 1720: "HLSQ", "PC", "LRZ", "TP" }; 1721: 1722: #define SCOOBYDOO 0x5c00bd00 1723: 1724: static const char *a6xx_fault_block_uche(struct kgsl_device *device, 1725: unsigned int mid) 1726: { 1727: unsigned int uche_client_id = 0; 1728: static char str[40]; 1729: 1730: /* 1731: * Smmu driver takes a vote on CX gdsc before calling the kgsl 1732: * pagefault handler. If there is contention for device mutex in this 1733: * path and the dispatcher fault handler is holding this lock, trying 1734: * to turn off CX gdsc will fail during the reset. So to avoid blocking 1735: * here, try to lock device mutex and return if it fails. 1736: */ 1737: if (!kgsl_mutex_trylock(&device->mutex)) 1738: return "UCHE: unknown"; 1739: 1740: if (!kgsl_state_is_awake(device)) { 1741: kgsl_mutex_unlock(&device->mutex); 1742: return "UCHE: unknown"; 1743: } 1744: 1745: kgsl_regread(device, A6XX_UCHE_CLIENT_PF, &uche_client_id); 1746: kgsl_mutex_unlock(&device->mutex); 1747: 1748: /* Ignore the value if the gpu is in IFPC */ 1749: if (uche_client_id == SCOOBYDOO) 1750: return "UCHE: unknown"; 1751: 1752: if (adreno_is_a660(ADRENO_DEVICE(device))) { 1753: 1754: /* Mask is 7 bits for A660 */ 1755: uche_client_id &= 0x7F; MATCH LINES: 1778 1766: } else { 1767: uche_client_id &= A6XX_UCHE_CLIENT_PF_CLIENT_ID_MASK; 1768: if (uche_client_id >= ARRAY_SIZE(uche_client)) 1769: return "UCHE: Unknown"; 1770: 1771: snprintf(str, sizeof(str), "UCHE: %s", 1772: uche_client[uche_client_id][mid - 1]); 1773: } 1774: 1775: return str; 1776: } 1777: 1778: static const char *a6xx_iommu_fault_block(struct kgsl_device *device, 1779: unsigned int fsynr1) 1780: { 1781: unsigned int mid = fsynr1 & 0xff; 1782: 1783: switch (mid) { 1784: case 0: 1785: return "CP"; 1786: case 1: 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: { MATCH LINES: 2395, 2416, 2444, 2470, 2495, 2521 2383: /* This is a non GMU/RGMU part */ 2384: const struct adreno_gpudev adreno_a6xx_gpudev = { 2385: .reg_offsets = a6xx_register_offsets, 2386: .probe = a6xx_probe, 2387: .start = a6xx_nogmu_start, 2388: .snapshot = a6xx_snapshot, 2389: .init = a6xx_nogmu_init, 2390: .irq_handler = a6xx_irq_handler, 2391: .rb_start = a6xx_rb_start, 2392: .regulator_disable = a6xx_prepare_for_regulator_disable, 2393: .gpu_keepalive = a6xx_gpu_keepalive, 2394: .hw_isidle = a6xx_hw_isidle, 2395: .iommu_fault_block = a6xx_iommu_fault_block, 2396: .reset = a6xx_reset, 2397: .preemption_schedule = a6xx_preemption_schedule, 2398: .read_alwayson = a6xx_read_alwayson, 2399: .power_ops = &adreno_power_operations, 2400: .clear_pending_transactions = a6xx_clear_pending_transactions, 2401: .deassert_gbif_halt = a6xx_deassert_gbif_halt, 2402: .remove = a6xx_remove, 2403: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2404: .is_hw_collapsible = adreno_isidle, 2405: .power_stats = a6xx_power_stats, 2406: .add_to_va_minidump = a6xx_dev_add_to_minidump, 2407: .gx_is_on = a6xx_gx_is_on, 2408: }; 2409: 2410: const struct a6xx_gpudev adreno_a6xx_hwsched_gpudev = { 2411: .base = { 2412: .reg_offsets = a6xx_register_offsets, 2413: .probe = a6xx_hwsched_probe, 2414: .snapshot = a6xx_hwsched_snapshot, 2415: .irq_handler = a6xx_hwsched_irq_handler, 2416: .iommu_fault_block = a6xx_iommu_fault_block, 2417: .context_detach = a6xx_hwsched_context_detach, 2418: .read_alwayson = a6xx_read_alwayson, 2419: .reset = a6xx_hwsched_reset_replay, 2420: .power_ops = &a6xx_hwsched_power_ops, 2421: .power_stats = a6xx_power_stats, 2422: .hw_isidle = a6xx_hw_isidle, 2423: .add_to_va_minidump = a6xx_hwsched_add_to_minidump, 2424: .gx_is_on = a6xx_gmu_gx_is_on, 2425: .send_recurring_cmdobj = a6xx_hwsched_send_recurring_cmdobj, 2426: .set_isdb_breakpoint_registers = a6xx_set_isdb_breakpoint_registers, 2427: }, 2428: .hfi_probe = a6xx_hwsched_hfi_probe, 2429: .hfi_remove = a6xx_hwsched_hfi_remove, 2430: .handle_watchdog = a6xx_hwsched_handle_watchdog, 2431: }; 2432: 2433: const struct a6xx_gpudev adreno_a6xx_gmu_gpudev = { 2434: .base = { 2435: .reg_offsets = a6xx_register_offsets, 2436: .probe = a6xx_gmu_device_probe, 2437: .snapshot = a6xx_gmu_snapshot, 2438: .irq_handler = a6xx_irq_handler, 2439: .rb_start = a6xx_rb_start, 2440: .regulator_enable = a6xx_sptprac_enable, 2441: .regulator_disable = a6xx_sptprac_disable, 2442: .gpu_keepalive = a6xx_gpu_keepalive, 2443: .hw_isidle = a6xx_hw_isidle, 2444: .iommu_fault_block = a6xx_iommu_fault_block, 2445: .reset = a6xx_gmu_reset, 2446: .preemption_schedule = a6xx_preemption_schedule, 2447: .read_alwayson = a6xx_read_alwayson, 2448: .power_ops = &a6xx_gmu_power_ops, 2449: .remove = a6xx_remove, 2450: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2451: .power_stats = a6xx_power_stats, 2452: .add_to_va_minidump = a6xx_gmu_add_to_minidump, 2453: .gx_is_on = a6xx_gmu_gx_is_on, 2454: .set_isdb_breakpoint_registers = a6xx_set_isdb_breakpoint_registers, 2455: }, 2456: .hfi_probe = a6xx_gmu_hfi_probe, 2457: .handle_watchdog = a6xx_gmu_handle_watchdog, 2458: }; 2459: 2460: const struct adreno_gpudev adreno_a6xx_rgmu_gpudev = { 2461: .reg_offsets = a6xx_register_offsets, 2462: .probe = a6xx_rgmu_device_probe, 2463: .snapshot = a6xx_rgmu_snapshot, 2464: .irq_handler = a6xx_irq_handler, 2465: .rb_start = a6xx_rb_start, 2466: .regulator_enable = a6xx_sptprac_enable, 2467: .regulator_disable = a6xx_sptprac_disable, 2468: .gpu_keepalive = a6xx_gpu_keepalive, 2469: .hw_isidle = a6xx_hw_isidle, 2470: .iommu_fault_block = a6xx_iommu_fault_block, 2471: .reset = a6xx_rgmu_reset, 2472: .preemption_schedule = a6xx_preemption_schedule, 2473: .read_alwayson = a6xx_read_alwayson, 2474: .power_ops = &a6xx_rgmu_power_ops, 2475: .remove = a6xx_remove, 2476: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2477: .power_stats = a6xx_power_stats, 2478: .add_to_va_minidump = a6xx_rgmu_add_to_minidump, 2479: .gx_is_on = a6xx_rgmu_gx_is_on, 2480: }; 2481: 2482: /* This is a non GMU/RGMU part */ 2483: const struct adreno_gpudev adreno_a619_holi_gpudev = { 2484: .reg_offsets = a6xx_register_offsets, 2485: .probe = a6xx_probe, 2486: .start = a6xx_nogmu_start, 2487: .snapshot = a6xx_snapshot, 2488: .init = a6xx_nogmu_init, 2489: .irq_handler = a6xx_irq_handler, 2490: .rb_start = a6xx_rb_start, 2491: .regulator_enable = a619_holi_sptprac_enable, 2492: .regulator_disable = a619_holi_sptprac_disable, 2493: .gpu_keepalive = a6xx_gpu_keepalive, 2494: .hw_isidle = a619_holi_hw_isidle, 2495: .iommu_fault_block = a6xx_iommu_fault_block, 2496: .reset = a6xx_reset, 2497: .preemption_schedule = a6xx_preemption_schedule, 2498: .read_alwayson = a6xx_read_alwayson, 2499: .power_ops = &adreno_power_operations, 2500: .clear_pending_transactions = a6xx_clear_pending_transactions, 2501: .deassert_gbif_halt = a6xx_deassert_gbif_halt, 2502: .remove = a6xx_remove, 2503: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2504: .is_hw_collapsible = adreno_isidle, 2505: .power_stats = a6xx_power_stats, 2506: .add_to_va_minidump = a6xx_dev_add_to_minidump, 2507: .gx_is_on = a619_holi_gx_is_on, 2508: }; 2509: 2510: const struct a6xx_gpudev adreno_a630_gpudev = { 2511: .base = { 2512: .reg_offsets = a6xx_register_offsets, 2513: .probe = a6xx_gmu_device_probe, 2514: .snapshot = a6xx_gmu_snapshot, 2515: .irq_handler = a6xx_irq_handler, 2516: .rb_start = a6xx_rb_start, 2517: .regulator_enable = a6xx_sptprac_enable, 2518: .regulator_disable = a6xx_sptprac_disable, 2519: .gpu_keepalive = a6xx_gpu_keepalive, 2520: .hw_isidle = a6xx_hw_isidle, 2521: .iommu_fault_block = a6xx_iommu_fault_block, 2522: .reset = a6xx_gmu_reset, 2523: .preemption_schedule = a6xx_preemption_schedule, 2524: .read_alwayson = a6xx_read_alwayson, 2525: .power_ops = &a630_gmu_power_ops, 2526: .remove = a6xx_remove, 2527: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd, 2528: .power_stats = a6xx_power_stats, 2529: .add_to_va_minidump = a6xx_gmu_add_to_minidump, 2530: .gx_is_on = a6xx_gmu_gx_is_on, 2531: }, 2532: .hfi_probe = a6xx_gmu_hfi_probe, 2533: .handle_watchdog = a6xx_gmu_handle_watchdog, 2534: }; --- FILE: \adreno_a6xx.h | HITS: 6 --- MATCH LINES: 139, 141, 143, 147, 150, 155 127: uint32_t errno; 128: uint32_t data; 129: uint32_t cntl; 130: uint32_t rptr; 131: uint32_t wptr; 132: uint32_t _pad28; 133: uint64_t rptr_addr; 134: uint64_t rbase; 135: uint64_t counter; 136: }; 137: 138: /** 139: * struct a6xx_cp_smmu_info - CP preemption SMMU info. 140: * @magic: (00) The value at this offset must be equal to 141: * A6XX_CP_SMMU_INFO_MAGIC_REF. 142: * @_pad4: (04) Reserved/padding 143: * @ttbr0: (08) Base address of the page table for the 144: * incoming context. 145: * @context_idr: (16) Context Identification Register value. 146: */ 147: struct a6xx_cp