A618 IRQ TO COMPLETION PATH Generated: 2026-11-26T19:56:29 Repository: C:\Users\qwertyhorik\Desktop\GPU_TRANSFER_2026-11-26\external\qualcomm-kgsl ========== FILE: \a6xx_reg.h ========== --- LINES 8-50 --- 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 ========== FILE: \adreno.c ========== --- LINES 657-738 --- 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); --- LINES 1876-1913 --- 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: 1913: if (pwr->gmu_cx_pd) { --- LINES 1921-1978 --- 1921: } 1922: } 1923: 1924: if (event == PM_SUSPEND_PREPARE) { 1925: /* 1926: * In presence of a hardware fault, cancel system suspend (by returning NOTIFY_BAD) 1927: * here to make sure system suspend doesn't increment the pd prepared_count. This 1928: * ensures that cx and gx gdscs can be toggled successfully during fault recovery. 1929: */ 1930: if (adreno_gpu_fault(adreno_dev)) { 1931: dev_err_ratelimited(device->dev, "cancelling suspend because of fault\n"); 1932: complete_all(&adreno_dev->suspend_recovery_gate); 1933: adreno_scheduler_queue(adreno_dev); 1934: return NOTIFY_BAD; 1935: } 1936: 1937: reinit_completion(&adreno_dev->suspend_recovery_gate); 1938: return NOTIFY_DONE; 1939: } 1940: 1941: /* 1942: * We get PM_POST_SUSPEND if we failed kgsl suspend in the presence of a hardware fault, 1943: * or when system resume finishes. In either case, this means the system has come out of 1944: * suspend and has put back the power domain prepared_count. This means we are safe to 1945: * perform fault recovery. 1946: */ 1947: if (event == PM_POST_SUSPEND) { 1948: complete_all(&adreno_dev->suspend_recovery_gate); 1949: /* 1950: * Queue the gpu scheduler to proceed with fault recovery in case there was a 1951: * fault 1952: */ 1953: adreno_scheduler_queue(adreno_dev); 1954: } 1955: 1956: return NOTIFY_DONE; 1957: } 1958: 1959: static void validate_pwrlevels(struct kgsl_device *device) 1960: { 1961: struct kgsl_pwrctrl *pwr = &device->pwrctrl; 1962: int i, count = pwr->ddr_table_count; 1963: 1964: for (i = 0; i < pwr->num_pwrlevels - 1; i++) { 1965: struct kgsl_pwrlevel *pwrlevel = &pwr->pwrlevels[i]; 1966: 1967: if (pwrlevel->bus_freq >= count) { 1968: dev_err(device->dev, "Bus setting for GPU freq %d is out of bounds\n", 1969: pwrlevel->gpu_freq); 1970: pwrlevel->bus_freq = count - 1; 1971: } 1972: 1973: if (pwrlevel->bus_max >= count) { 1974: dev_err(device->dev, "Bus max for GPU freq %d is out of bounds\n", 1975: pwrlevel->gpu_freq); 1976: pwrlevel->bus_max = count - 1; 1977: } 1978: --- LINES 2214-2251 --- 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: --- LINES 3938-4062 --- 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: */ --- LINES 4709-4746 --- 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, ========== FILE: \adreno.h ========== --- LINES 1111-1148 --- 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 1148: */ --- LINES 1259-1296 --- 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: 1270: void adreno_hang_int_callback(struct adreno_device *adreno_dev, int bit); 1271: void adreno_cp_callback(struct adreno_device *adreno_dev, int bit); 1272: 1273: int adreno_sysfs_init(struct adreno_device *adreno_dev); 1274: 1275: void adreno_irqctrl(struct adreno_device *adreno_dev, int state); 1276: 1277: long adreno_ioctl_perfcounter_get(struct kgsl_device_private *dev_priv, 1278: unsigned int cmd, void *data); 1279: 1280: long adreno_ioctl_perfcounter_put(struct kgsl_device_private *dev_priv, 1281: unsigned int cmd, void *data); 1282: 1283: bool adreno_gx_is_on(struct adreno_device *adreno_dev); 1284: 1285: u64 adreno_read_cx_timer(struct adreno_device *adreno_dev); 1286: 1287: /** 1288: * adreno_active_count_get - Wrapper for target specific active count get 1289: * @adreno_dev: pointer to the adreno device 1290: * 1291: * Increase the active count for the KGSL device and execute slumber exit 1292: * sequence if this is the first reference. Code paths that need to touch the 1293: * hardware or wait for the hardware to complete an operation must hold an 1294: * active count reference until they are finished. The device mutex must be held 1295: * while calling this function. 1296: * --- LINES 1716-1770 --- 1716: * 1717: * Clear the GPU fault status for the adreno device 1718: */ 1719: static inline void adreno_clear_gpu_fault(struct adreno_device *adreno_dev) 1720: { 1721: atomic_set(&adreno_dev->scheduler_fault, 0); 1722: 1723: /* make sure other CPUs see the update */ 1724: smp_wmb(); 1725: } 1726: 1727: /** 1728: * adreno_scheduler_queue - Queue the scheduler kthread 1729: * @adreno_dev: Adreno device handle 1730: */ 1731: static inline void adreno_scheduler_queue(struct adreno_device *adreno_dev) 1732: { 1733: kthread_queue_work(adreno_dev->scheduler_worker, &adreno_dev->scheduler_work); 1734: } 1735: 1736: /** 1737: * adreno_scheduler_fault() - Set GPU fault and trigger fault recovery 1738: * @adreno_dev: A pointer to an adreno_device structure 1739: * @fault: Type of fault 1740: */ 1741: static inline void adreno_scheduler_fault(struct adreno_device *adreno_dev, 1742: u32 fault) 1743: { 1744: adreno_set_gpu_fault(adreno_dev, fault); 1745: adreno_scheduler_queue(adreno_dev); 1746: } 1747: 1748: /** 1749: * adreno_gpu_halt() - Return the GPU halt refcount 1750: * @adreno_dev: A pointer to the adreno_device 1751: */ 1752: static inline int adreno_gpu_halt(struct adreno_device *adreno_dev) 1753: { 1754: /* make sure we're reading the latest value */ 1755: smp_rmb(); 1756: return atomic_read(&adreno_dev->halt); 1757: } 1758: 1759: 1760: /** 1761: * adreno_clear_gpu_halt() - Clear the GPU halt refcount 1762: * @adreno_dev: A pointer to the adreno_device 1763: */ 1764: static inline void adreno_clear_gpu_halt(struct adreno_device *adreno_dev) 1765: { 1766: atomic_set(&adreno_dev->halt, 0); 1767: 1768: /* make sure other CPUs see the update */ 1769: smp_wmb(); 1770: } --- LINES 2114-2159 --- 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: * 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 2159: * the device, executes the callback, and resumes the device. ========== FILE: \adreno_a5xx.c ========== --- LINES 2079-2116 --- 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. --- LINES 2129-2166 --- 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); 2165: } 2166: --- LINES 2284-2321 --- 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: --- LINES 2422-2448 --- 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 ========== --- LINES 277-315 --- 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 ========== --- LINES 83-120 --- 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: ========== FILE: \adreno_a5xx_preempt.c ========== --- LINES 101-138 --- 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 */ --- LINES 267-304 --- 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: { ========== FILE: \adreno_a5xx_ringbuffer.c ========== --- LINES 45-85 --- 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); --- LINES 236-288 --- 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) --- LINES 400-437 --- 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); ========== FILE: \adreno_a6xx.c ========== --- LINES 1794-1873 --- 1794: case 7: 1795: return "GPMU"; 1796: } 1797: 1798: return "Unknown"; 1799: } 1800: 1801: static void a6xx_cp_callback(struct adreno_device *adreno_dev, int bit) 1802: { 1803: if (adreno_is_preemption_enabled(adreno_dev)) 1804: a6xx_preemption_trigger(adreno_dev, true); 1805: 1806: adreno_scheduler_queue(adreno_dev); 1807: } 1808: 1809: /* 1810: * a6xx_gpc_err_int_callback() - Isr for GPC error interrupts 1811: * @adreno_dev: Pointer to device 1812: * @bit: Interrupt bit 1813: */ 1814: static void a6xx_gpc_err_int_callback(struct adreno_device *adreno_dev, int bit) 1815: { 1816: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1817: 1818: /* 1819: * GPC error is typically the result of mistake SW programming. 1820: * Force GPU fault for this interrupt so that we can debug it 1821: * with help of register dump. 1822: */ 1823: 1824: dev_crit(device->dev, "RBBM: GPC error\n"); 1825: adreno_irqctrl(adreno_dev, 0); 1826: 1827: /* Trigger a fault in the dispatcher - this will effect a restart */ 1828: adreno_scheduler_fault(adreno_dev, ADRENO_SOFT_FAULT); 1829: } 1830: 1831: static const struct adreno_irq_funcs a6xx_irq_funcs[32] = { 1832: ADRENO_IRQ_CALLBACK(NULL), /* 0 - RBBM_GPU_IDLE */ 1833: ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 1 - RBBM_AHB_ERROR */ 1834: ADRENO_IRQ_CALLBACK(NULL), /* 2 - UNUSED */ 1835: ADRENO_IRQ_CALLBACK(NULL), /* 3 - UNUSED */ 1836: ADRENO_IRQ_CALLBACK(NULL), /* 4 - UNUSED */ 1837: ADRENO_IRQ_CALLBACK(NULL), /* 5 - UNUSED */ 1838: /* 6 - RBBM_ATB_ASYNC_OVERFLOW */ 1839: ADRENO_IRQ_CALLBACK(a6xx_err_callback), 1840: ADRENO_IRQ_CALLBACK(a6xx_gpc_err_int_callback), /* 7 - GPC_ERR */ 1841: ADRENO_IRQ_CALLBACK(a6xx_preemption_callback),/* 8 - CP_SW */ 1842: ADRENO_IRQ_CALLBACK(a6xx_cp_hw_err_callback), /* 9 - CP_HW_ERROR */ 1843: ADRENO_IRQ_CALLBACK(NULL), /* 10 - CP_CCU_FLUSH_DEPTH_TS */ 1844: ADRENO_IRQ_CALLBACK(NULL), /* 11 - CP_CCU_FLUSH_COLOR_TS */ 1845: ADRENO_IRQ_CALLBACK(NULL), /* 12 - CP_CCU_RESOLVE_TS */ 1846: ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 13 - CP_IB2_INT */ 1847: ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 14 - CP_IB1_INT */ 1848: ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 15 - CP_RB_INT */ 1849: ADRENO_IRQ_CALLBACK(NULL), /* 16 - UNUSED */ 1850: ADRENO_IRQ_CALLBACK(NULL), /* 17 - CP_RB_DONE_TS */ 1851: ADRENO_IRQ_CALLBACK(NULL), /* 18 - CP_WT_DONE_TS */ 1852: ADRENO_IRQ_CALLBACK(NULL), /* 19 - UNUSED */ 1853: ADRENO_IRQ_CALLBACK(a6xx_cp_callback), /* 20 - CP_CACHE_FLUSH_TS */ 1854: ADRENO_IRQ_CALLBACK(NULL), /* 21 - UNUSED */ 1855: ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 22 - RBBM_ATB_BUS_OVERFLOW */ 1856: /* 23 - MISC_HANG_DETECT */ 1857: ADRENO_IRQ_CALLBACK(adreno_hang_int_callback), 1858: ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 24 - UCHE_OOB_ACCESS */ 1859: ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 25 - UCHE_TRAP_INTR */ 1860: ADRENO_IRQ_CALLBACK(NULL), /* 26 - DEBBUS_INTR_0 */ 1861: ADRENO_IRQ_CALLBACK(NULL), /* 27 - DEBBUS_INTR_1 */ 1862: ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 28 - TSBWRITEERROR */ 1863: ADRENO_IRQ_CALLBACK(NULL), /* 29 - UNUSED */ 1864: ADRENO_IRQ_CALLBACK(NULL), /* 30 - ISDB_CPU_IRQ */ 1865: ADRENO_IRQ_CALLBACK(NULL), /* 31 - ISDB_UNDER_DEBUG */ 1866: }; 1867: 1868: /* 1869: * If the AHB fence is not in ALLOW mode when we receive an RBBM 1870: * interrupt, something went wrong. This means that we cannot proceed 1871: * since the IRQ status and clear registers are not accessible. 1872: * This is usually harmless because the GMU will abort power collapse 1873: * and change the fence back to ALLOW. Poll so that this can happen. --- LINES 1919-1989 --- 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; 1985: adreno_dev->chipid = chipid; 1986: 1987: adreno_reg_offset_init(gpudev->reg_offsets); 1988: 1989: if (gmu_core_isenabled(device) && (gpudev != &adreno_a6xx_rgmu_gpudev)) { --- LINES 2378-2534 --- 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.h ========== --- LINES 163-203 --- 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) | \ 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: { 203: const struct adreno_gpu_core *core = adreno_dev->gpucore; --- LINES 354-399 --- 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 ========== FILE: \adreno_a6xx_gmu.c ========== --- LINES 2788-2825 --- 2788: gmu->stats_interval = HFI_FEATURE_GMU_STATS_INTERVAL; 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, --- LINES 3495-3532 --- 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: { 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_hwsched_hfi.c ========== --- LINES 384-421 --- 384: } 385: 386: a6xx_hfi_queue_read(gmu, HFI_MSG_ID, rcvd, sizeof(rcvd)); 387: 388: /* 389: * We are assuming that there is only one outstanding ack 390: * because hfi sending thread waits for completion while 391: * holding the device mutex 392: */ 393: if (MSG_HDR_GET_TYPE(rcvd[0]) == HFI_MSG_ACK) { 394: a6xx_receive_ack_async(adreno_dev, rcvd); 395: } else if (MSG_HDR_GET_ID(rcvd[0]) == F2H_MSG_TS_RETIRE) { 396: adreno_scheduler_queue(adreno_dev); 397: adreno_hwsched_log_profiling_info(adreno_dev, rcvd); 398: } else if (MSG_HDR_GET_ID(rcvd[0]) == F2H_MSG_GMU_CNTR_RELEASE) { 399: struct hfi_gmu_cntr_release_cmd *cmd = 400: (struct hfi_gmu_cntr_release_cmd *) rcvd; 401: 402: adreno_perfcounter_put(adreno_dev, 403: cmd->group_id, cmd->countable, PERFCOUNTER_FLAG_KERNEL); 404: } 405: } 406: mutex_unlock(&hw_hfi->msgq_mutex); 407: } 408: 409: static void process_log_block(struct adreno_device *adreno_dev, void *data) 410: { 411: struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev); 412: struct hfi_log_block *cmd = data; 413: u32 *log_event = gmu->gmu_log->hostptr; 414: u32 start, end; 415: 416: start = cmd->start_index; 417: end = cmd->stop_index; 418: 419: log_event += start * 4; 420: while (start != end) { 421: trace_gmu_event(log_event); --- LINES 472-509 --- 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) --- LINES 1078-1115 --- 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; 1115: cmd.submit_cmd.ts = ++ts; --- LINES 1219-1256 --- 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); 1228: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 1229: 1230: /* Try with "hfi" irq first. Use Fallback legacy name "kgsl_hfi_irq" if not found. */ 1231: gmu->hfi.irq = kgsl_request_irq(GMU_PDEV(device), "hfi", "kgsl_hfi_irq", -EINVAL, 1232: a6xx_hwsched_hfi_handler, adreno_dev); 1233: 1234: if (gmu->hfi.irq < 0) 1235: return gmu->hfi.irq; 1236: 1237: hw_hfi->irq_mask = HFI_IRQ_MASK; 1238: 1239: rwlock_init(&hw_hfi->msglock); 1240: 1241: INIT_LIST_HEAD(&hw_hfi->msglist); 1242: 1243: init_waitqueue_head(&hw_hfi->f2h_wq); 1244: 1245: mutex_init(&hw_hfi->msgq_mutex); 1246: 1247: return 0; 1248: } 1249: 1250: void a6xx_hwsched_hfi_remove(struct adreno_device *adreno_dev) 1251: { 1252: struct a6xx_hwsched_hfi *hw_hfi = to_a6xx_hwsched_hfi(adreno_dev); 1253: 1254: if (hw_hfi->f2h_task) 1255: kthread_stop(hw_hfi->f2h_task); 1256: } --- LINES 1307-1344 --- 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); 1344: --- LINES 1725-1762 --- 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; 1762: ========== FILE: \adreno_a6xx_perfcounter.c ========== --- LINES 110-147 --- 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: ========== FILE: \adreno_a6xx_preempt.c ========== --- LINES 166-203 --- 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 */ --- LINES 431-468 --- 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: ========== FILE: \adreno_a6xx_rgmu.c ========== --- LINES 1235-1281 --- 1235: .oob_clear = a6xx_rgmu_oob_clear, 1236: .ifpc_store = a6xx_rgmu_ifpc_store, 1237: .ifpc_isenabled = a6xx_rgmu_ifpc_isenabled, 1238: .send_nmi = a6xx_rgmu_halt_execution, 1239: }; 1240: 1241: static int a6xx_rgmu_irq_probe(struct kgsl_device *device) 1242: { 1243: struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(ADRENO_DEVICE(device)); 1244: int ret; 1245: 1246: /* Try with "oob" irq first. Use Fallback legacy name "kgsl_oob" if not found. */ 1247: ret = kgsl_request_irq(rgmu->pdev, "oob", "kgsl_oob", -EINVAL, 1248: a6xx_oob_irq_handler, device); 1249: 1250: if (ret < 0) 1251: return ret; 1252: 1253: rgmu->oob_interrupt_num = ret; 1254: 1255: /* Try with "gmu" irq first. Use Fallback legacy name "kgsl_rgmu" if not found. */ 1256: ret = kgsl_request_irq(rgmu->pdev, "gmu", "kgsl_rgmu", -EINVAL, 1257: a6xx_rgmu_irq_handler, device); 1258: 1259: if (ret < 0) 1260: return ret; 1261: 1262: rgmu->rgmu_interrupt_num = ret; 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. ========== FILE: \adreno_a6xx_ringbuffer.c ========== --- LINES 107-147 --- 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: --- LINES 308-360 --- 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) --- LINES 447-484 --- 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); ========== FILE: \adreno_debugfs.c ========== --- LINES 374-416 --- 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: { ========== FILE: \adreno_dispatch.c ========== --- LINES 112-155 --- 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); --- LINES 490-527 --- 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: /* --- LINES 876-913 --- 876: goto done; 877: } 878: 879: _adreno_dispatcher_issuecmds(adreno_dev); 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: --- LINES 1899-1936 --- 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, 1909: msecs_to_jiffies(ADRENO_SUSPEND_RECOVERY_GATE_TIMEOUT_MS))) { 1910: dev_err(device->dev, "suspend recovery gate timeout\n"); 1911: adreno_scheduler_queue(adreno_dev); 1912: mutex_unlock(&adreno_dev->fault_recovery_mutex); 1913: return 1; 1914: } 1915: 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: } --- LINES 2033-2074 --- 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: --- LINES 2331-2431 --- 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: /* 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) 2378: { 2379: dispatcher_queue_context(adreno_dev, drawctxt); 2380: adreno_scheduler_queue(adreno_dev); 2381: } 2382: 2383: /* 2384: * This is called when the timer expires - it either means the GPU is hung or 2385: * the IB is taking too long to execute 2386: */ 2387: static void adreno_dispatcher_timer(struct timer_list *t) 2388: { 2389: struct adreno_dispatcher *dispatcher = kgsl_timer_container_of(dispatcher, t, timer); 2390: struct adreno_device *adreno_dev = container_of(dispatcher, 2391: struct adreno_device, dispatcher); 2392: 2393: adreno_scheduler_queue(adreno_dev); 2394: } 2395: 2396: /** 2397: * adreno_dispatcher_start() - activate the dispatcher 2398: * @adreno_dev: pointer to the adreno device structure 2399: * 2400: */ 2401: void adreno_dispatcher_start(struct kgsl_device *device) 2402: { 2403: complete_all(&device->halt_gate); 2404: 2405: /* Schedule the work loop to get things going */ 2406: adreno_scheduler_queue(ADRENO_DEVICE(device)); 2407: } 2408: 2409: /** 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: --- LINES 2473-2510 --- 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: { --- LINES 2800-2825 --- 2800: } 2801: 2802: if (adreno_gpu_fault(adreno_dev) != 0) 2803: ret = -EDEADLK; 2804: } 2805: 2806: kgsl_mutex_lock(&device->mutex); 2807: adreno_put_gpu_halt(adreno_dev); 2808: /* 2809: * requeue dispatcher work to resubmit pending commands 2810: * that may have been blocked due to this idling request 2811: */ 2812: adreno_scheduler_queue(adreno_dev); 2813: return ret; 2814: } 2815: 2816: int adreno_drain_and_idle(struct kgsl_device *device) 2817: { 2818: int ret = adreno_drain(device, HZ); 2819: 2820: /* Make sure the dispatcher and hardware are idle */ 2821: if (!ret) 2822: ret = adreno_wait_idle(device); 2823: 2824: return ret; 2825: } ========== FILE: \adreno_drawctxt.c ========== --- LINES 36-75 --- 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); --- LINES 145-182 --- 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 */ --- LINES 269-306 --- 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) --- LINES 492-529 --- 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 */ --- LINES 566-617 --- 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); --- LINES 681-718 --- 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) 718: { ========== FILE: \adreno_gen7.c ========== --- LINES 1622-1659 --- 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); 1657: } 1658: 1659: /* --- LINES 1700-1737 --- 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: }; 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: */ --- LINES 1780-1850 --- 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); 1846: int ret; 1847: 1848: adreno_dev->gpucore = gpucore; 1849: adreno_dev->chipid = chipid; 1850: --- LINES 2493-2592 --- 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 ========== --- LINES 391-436 --- 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: ========== FILE: \adreno_gen7_gmu.c ========== --- LINES 2172-2209 --- 2172: 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, --- LINES 2846-2883 --- 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, 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_hwsched_hfi.c ========== --- LINES 995-1032 --- 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); --- LINES 1165-1202 --- 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: 1189: gmu_core_mark_for_coldboot(KGSL_DEVICE(adreno_dev)); 1190: } 1191: break; 1192: } 1193: } 1194: mutex_unlock(&hw_hfi->msgq_mutex); 1195: } 1196: 1197: static void process_log_block(struct adreno_device *adreno_dev, void *data) 1198: { 1199: struct gen7_gmu_device *gmu = to_gen7_gmu(adreno_dev); 1200: struct hfi_log_block *cmd = data; 1201: u32 *log_event = gmu->gmu_log->hostptr; 1202: u32 start, end; --- LINES 1260-1297 --- 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) --- LINES 2458-2495 --- 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: { --- LINES 2606-2643 --- 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); 2643: --- LINES 3209-3246 --- 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); --- LINES 3739-3776 --- 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) --- LINES 3821-3858 --- 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; 3858: cmd.submit_cmd.ts = ++ts; ========== FILE: \adreno_gen7_perfcounter.c ========== --- LINES 85-122 --- 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: ========== FILE: \adreno_gen7_preempt.c ========== --- LINES 137-174 --- 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 */ --- LINES 407-444 --- 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: ========== FILE: \adreno_gen7_ringbuffer.c ========== --- LINES 157-197 --- 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: --- LINES 371-423 --- 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 */ --- LINES 518-555 --- 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); ========== FILE: \adreno_gen8.c ========== --- LINES 2892-2929 --- 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); 2927: } 2928: 2929: /* --- LINES 2988-3025 --- 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: }; 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: */ --- LINES 3068-3138 --- 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); --- LINES 3154-3191 --- 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; --- LINES 3839-3912 --- 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, 3911: .handle_watchdog = gen8_gmu_handle_watchdog, 3912: }; ========== FILE: \adreno_gen8.h ========== --- LINES 497-542 --- 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: ========== FILE: \adreno_gen8_gmu.c ========== --- LINES 2197-2234 --- 2197: 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, --- LINES 2850-2887 --- 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, 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_hwsched_hfi.c ========== --- LINES 912-949 --- 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); --- LINES 1099-1136 --- 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: 1123: gmu_core_mark_for_coldboot(KGSL_DEVICE(adreno_dev)); 1124: } 1125: break; 1126: case F2H_MSG_PLATFORM_LA: 1127: gen8_hwsched_process_f2h_platform_msg(adreno_dev, rcvd); 1128: break; 1129: } 1130: } 1131: mutex_unlock(&hw_hfi->msgq_mutex); 1132: } 1133: 1134: static void process_log_block(struct adreno_device *adreno_dev, void *data) 1135: { 1136: struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev); --- LINES 1199-1236 --- 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; --- LINES 2944-2981 --- 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: } --- LINES 3076-3113 --- 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), --- LINES 3689-3726 --- 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", --- LINES 4195-4232 --- 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: --- LINES 4374-4411 --- 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: { ========== FILE: \adreno_gen8_preempt.c ========== --- LINES 137-174 --- 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 */ --- LINES 407-444 --- 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: ========== FILE: \adreno_gen8_ringbuffer.c ========== --- LINES 159-199 --- 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: --- LINES 382-434 --- 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 */ --- LINES 529-566 --- 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); ========== FILE: \adreno_hwsched.c ========== --- LINES 540-591 --- 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: } --- LINES 1141-1178 --- 1141: if (hwsched->inflight > 0) { 1142: kgsl_mutex_lock(&device->mutex); 1143: kgsl_pwrscale_update(device); 1144: kgsl_start_idle_timer(device); 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: --- LINES 1650-1696 --- 1650: if (test_bit(ADRENO_HWSCHED_POWER, &hwsched->flags)) { 1651: adreno_active_count_put(adreno_dev); 1652: clear_bit(ADRENO_HWSCHED_POWER, &hwsched->flags); 1653: } 1654: 1655: kgsl_mutex_unlock(&device->mutex); 1656: } 1657: 1658: static void adreno_hwsched_queue_context(struct adreno_device *adreno_dev, 1659: struct adreno_context *drawctxt) 1660: { 1661: hwsched_queue_context(adreno_dev, drawctxt); 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; --- LINES 1796-1833 --- 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)) { --- LINES 1874-1911 --- 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); 1909: 1910: if (gx_on) { 1911: adreno_readreg(adreno_dev, ADRENO_REG_RBBM_STATUS, &status); --- LINES 1951-1991 --- 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; 1991: } --- LINES 2001-2041 --- 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: 2041: drawobj = active_obj->drawobj; --- LINES 2372-2465 --- 2372: * out in the presence of this hwsched fault and requeue the dispatcher to handle this fault 2373: */ 2374: if (!mutex_trylock(&adreno_dev->fault_recovery_mutex)) 2375: return true; 2376: 2377: /* 2378: * Wait long enough to allow the system to come out of suspend completely, which can take 2379: * variable amount of time especially if it has to rewind suspend processes and devices. 2380: */ 2381: if (!wait_for_completion_timeout(&adreno_dev->suspend_recovery_gate, 2382: msecs_to_jiffies(ADRENO_SUSPEND_RECOVERY_GATE_TIMEOUT_MS))) { 2383: dev_err(device->dev, "suspend recovery gate timeout\n"); 2384: adreno_scheduler_queue(adreno_dev); 2385: mutex_unlock(&adreno_dev->fault_recovery_mutex); 2386: return true; 2387: } 2388: 2389: kgsl_mutex_lock(&device->mutex); 2390: 2391: if (device->state == KGSL_STATE_ACTIVE) { 2392: /* 2393: * Halt CP for page faults here. CP is halted from GMU when required, 2394: * for other faults. 2395: */ 2396: if ((fault & ADRENO_IOMMU_STALL_ON_PAGE_FAULT) && adreno_gx_is_on(adreno_dev)) 2397: adreno_writereg(adreno_dev, ADRENO_REG_CP_ME_CNTL, 0); 2398: 2399: if (test_bit(ADRENO_HWSCHED_CTX_BAD_LEGACY, &hwsched->flags)) { 2400: adreno_hwsched_snapshot_legacy(adreno_dev, fault); 2401: memset(hwsched->ctxt_bad, 0x0, HFI_MAX_MSG_SIZE); 2402: adreno_gpudev_reset(adreno_dev); 2403: } else { 2404: int ret = adreno_hwsched_snapshot_and_soft_reset(adreno_dev, fault); 2405: 2406: if (ret) 2407: adreno_gpudev_reset(adreno_dev); 2408: } 2409: } 2410: 2411: adreno_scheduler_queue(adreno_dev); 2412: 2413: kgsl_mutex_unlock(&device->mutex); 2414: mutex_unlock(&adreno_dev->fault_recovery_mutex); 2415: 2416: return true; 2417: } 2418: 2419: static void adreno_hwsched_work(struct kthread_work *work) 2420: { 2421: struct adreno_device *adreno_dev = container_of(work, 2422: struct adreno_device, scheduler_work); 2423: struct adreno_hwsched *hwsched = &adreno_dev->hwsched; 2424: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 2425: 2426: mutex_lock(&hwsched->mutex); 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)) ========== FILE: \adreno_profile.c ========== --- LINES 318-355 --- 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, ========== FILE: \adreno_ringbuffer.c ========== --- LINES 133-170 --- 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: --- LINES 229-266 --- 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); --- LINES 328-365 --- 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); --- LINES 387-426 --- 387: int adreno_ringbuffer_waittimestamp(struct adreno_ringbuffer *rb, 388: unsigned int timestamp, 389: unsigned int msecs) 390: { 391: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb); 392: struct kgsl_device *device = KGSL_DEVICE(adreno_dev); 393: int ret; 394: unsigned long wait_time; 395: 396: /* check immediately if timeout is 0 */ 397: if (msecs == 0) 398: return adreno_ringbuffer_check_timestamp(rb, 399: timestamp, KGSL_TIMESTAMP_RETIRED) ? 0 : -EBUSY; 400: 401: ret = kgsl_add_event(device, &rb->events, timestamp, 402: adreno_ringbuffer_wait_callback, NULL); 403: if (ret) 404: return ret; 405: 406: kgsl_mutex_unlock(&device->mutex); 407: 408: wait_time = msecs_to_jiffies(msecs); 409: if (wait_event_timeout(rb->ts_expire_waitq, 410: !kgsl_event_pending(device, &rb->events, timestamp, 411: adreno_ringbuffer_wait_callback, NULL), 412: wait_time) == 0) 413: ret = -ETIMEDOUT; 414: 415: kgsl_mutex_lock(&device->mutex); 416: /* 417: * after wake up make sure that expected timestamp has retired 418: * because the wakeup could have happened due to a cancel event 419: */ 420: if (!ret && !adreno_ringbuffer_check_timestamp(rb, 421: timestamp, KGSL_TIMESTAMP_RETIRED)) { 422: ret = -EAGAIN; 423: } 424: 425: return ret; 426: } ========== FILE: \adreno_ringbuffer.h ========== --- LINES 133-170 --- 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: ========== FILE: \adreno_snapshot.c ========== --- LINES 498-535 --- 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; --- LINES 981-1024 --- 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) ========== FILE: \kgsl.c ========== --- LINES 241-278 --- 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: --- LINES 771-809 --- 771: 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: } 809: } --- LINES 871-908 --- 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; 908: --- LINES 935-972 --- 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: /** --- LINES 2065-2111 --- 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)) --- LINES 2447-2484 --- 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, --- LINES 2630-2670 --- 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); --- LINES 2706-2770 --- 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: } --- LINES 2887-2924 --- 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); --- LINES 5214-5251 --- 5214: kgsl_dev_set_dma_coherent(device->dev); 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: } --- LINES 5261-5298 --- 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(); ========== FILE: \kgsl.h ========== --- LINES 422-462 --- 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 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 ========== --- LINES 784-821 --- 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); --- LINES 844-912 --- 844: 845: /** 846: * kgsl_del_event_group - Remove a GPU event group from a device 847: * @device: A KGSL GPU device handle 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: 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: */ ========== FILE: \kgsl_drawobj.c ========== --- LINES 102-140 --- 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; --- LINES 707-770 --- 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)) --- LINES 1025-1062 --- 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: } --- LINES 1076-1113 --- 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: 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; ========== FILE: \kgsl_events.c ========== --- LINES 79-143 --- 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) --- LINES 217-261 --- 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) --- LINES 276-396 --- 276: event->group = group; 277: 278: kthread_init_work(&event->work, _kgsl_event_worker); 279: 280: trace_kgsl_register_event(KGSL_CONTEXT_ID(context), timestamp, func); 281: 282: spin_lock(&group->lock); 283: 284: /* 285: * Check to see if the requested timestamp has already retired. If so, 286: * schedule the callback right away 287: */ 288: group->readtimestamp(device, group->priv, KGSL_TIMESTAMP_RETIRED, 289: &retired); 290: 291: if (timestamp_cmp(retired, timestamp) >= 0) { 292: event->result = KGSL_EVENT_RETIRED; 293: kthread_queue_work(device->events_worker, &event->work); 294: spin_unlock(&group->lock); 295: return 0; 296: } 297: 298: /* Add the event to the group list */ 299: list_add_tail(&event->node, &group->events); 300: 301: spin_unlock(&group->lock); 302: 303: return 0; 304: } 305: 306: void kgsl_process_event_groups(struct kgsl_device *device) 307: { 308: struct kgsl_event_group *group; 309: 310: read_lock(&device->event_groups_lock); 311: list_for_each_entry(group, &device->event_groups, group) 312: _process_event_group(device, group, false); 313: read_unlock(&device->event_groups_lock); 314: } 315: 316: void kgsl_del_event_group(struct kgsl_device *device, 317: struct kgsl_event_group *group) 318: { 319: /* Check if the group is uninintalized */ 320: if (!group->context) 321: return; 322: 323: /* Make sure that all the events have been deleted from the list */ 324: WARN_ON(!list_empty(&group->events)); 325: 326: write_lock(&device->event_groups_lock); 327: list_del(&group->group); 328: write_unlock(&device->event_groups_lock); 329: } 330: 331: void kgsl_add_event_group(struct kgsl_device *device, 332: struct kgsl_event_group *group, struct kgsl_context *context, 333: readtimestamp_func readtimestamp, 334: void *priv, const char *fmt, ...) 335: { 336: va_list args; 337: 338: WARN_ON(readtimestamp == NULL); 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: ========== FILE: \kgsl_sync.c ========== --- LINES 469-506 --- 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 --- LINES 549-586 --- 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) { --- LINES 618-658 --- 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: } ========== FILE: \kgsl_trace.h ========== --- LINES 91-128 --- 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), ========== FILE: \include\uapi\linux\msm_kgsl.h ========== --- LINES 280-347 --- 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