1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2013-2014 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
6 * Copyright (c) 2014,2017 The Linux Foundation. All rights reserved.
9 #include "adreno_gpu.h"
11 bool hang_debug = false;
12 MODULE_PARM_DESC(hang_debug, "Dump registers when hang is detected (can be slow!)");
13 module_param_named(hang_debug, hang_debug, bool, 0600);
15 bool snapshot_debugbus = false;
16 MODULE_PARM_DESC(snapshot_debugbus, "Include debugbus sections in GPU devcoredump (if not fused off)");
17 module_param_named(snapshot_debugbus, snapshot_debugbus, bool, 0600);
19 bool allow_vram_carveout = false;
20 MODULE_PARM_DESC(allow_vram_carveout, "Allow using VRAM Carveout, in place of IOMMU");
21 module_param_named(allow_vram_carveout, allow_vram_carveout, bool, 0600);
23 static const struct adreno_info gpulist[] = {
25 .rev = ADRENO_REV(2, 0, 0, 0),
29 [ADRENO_FW_PM4] = "yamato_pm4.fw",
30 [ADRENO_FW_PFP] = "yamato_pfp.fw",
33 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
34 .init = a2xx_gpu_init,
35 }, { /* a200 on i.mx51 has only 128kib gmem */
36 .rev = ADRENO_REV(2, 0, 0, 1),
40 [ADRENO_FW_PM4] = "yamato_pm4.fw",
41 [ADRENO_FW_PFP] = "yamato_pfp.fw",
44 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
45 .init = a2xx_gpu_init,
47 .rev = ADRENO_REV(2, 2, 0, ANY_ID),
51 [ADRENO_FW_PM4] = "leia_pm4_470.fw",
52 [ADRENO_FW_PFP] = "leia_pfp_470.fw",
55 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
56 .init = a2xx_gpu_init,
58 .rev = ADRENO_REV(3, 0, 5, ANY_ID),
62 [ADRENO_FW_PM4] = "a300_pm4.fw",
63 [ADRENO_FW_PFP] = "a300_pfp.fw",
66 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
67 .init = a3xx_gpu_init,
69 .rev = ADRENO_REV(3, 0, 6, 0),
70 .revn = 307, /* because a305c is revn==306 */
73 [ADRENO_FW_PM4] = "a300_pm4.fw",
74 [ADRENO_FW_PFP] = "a300_pfp.fw",
77 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
78 .init = a3xx_gpu_init,
80 .rev = ADRENO_REV(3, 2, ANY_ID, ANY_ID),
84 [ADRENO_FW_PM4] = "a300_pm4.fw",
85 [ADRENO_FW_PFP] = "a300_pfp.fw",
88 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
89 .init = a3xx_gpu_init,
91 .rev = ADRENO_REV(3, 3, 0, ANY_ID),
95 [ADRENO_FW_PM4] = "a330_pm4.fw",
96 [ADRENO_FW_PFP] = "a330_pfp.fw",
99 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
100 .init = a3xx_gpu_init,
102 .rev = ADRENO_REV(4, 0, 5, ANY_ID),
106 [ADRENO_FW_PM4] = "a420_pm4.fw",
107 [ADRENO_FW_PFP] = "a420_pfp.fw",
110 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
111 .init = a4xx_gpu_init,
113 .rev = ADRENO_REV(4, 2, 0, ANY_ID),
117 [ADRENO_FW_PM4] = "a420_pm4.fw",
118 [ADRENO_FW_PFP] = "a420_pfp.fw",
120 .gmem = (SZ_1M + SZ_512K),
121 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
122 .init = a4xx_gpu_init,
124 .rev = ADRENO_REV(4, 3, 0, ANY_ID),
128 [ADRENO_FW_PM4] = "a420_pm4.fw",
129 [ADRENO_FW_PFP] = "a420_pfp.fw",
131 .gmem = (SZ_1M + SZ_512K),
132 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
133 .init = a4xx_gpu_init,
135 .rev = ADRENO_REV(5, 0, 6, ANY_ID),
139 [ADRENO_FW_PM4] = "a530_pm4.fw",
140 [ADRENO_FW_PFP] = "a530_pfp.fw",
142 .gmem = (SZ_128K + SZ_8K),
144 * Increase inactive period to 250 to avoid bouncing
145 * the GDSC which appears to make it grumpy
147 .inactive_period = 250,
148 .quirks = ADRENO_QUIRK_TWO_PASS_USE_WFI |
149 ADRENO_QUIRK_LMLOADKILL_DISABLE,
150 .init = a5xx_gpu_init,
151 .zapfw = "a506_zap.mdt",
153 .rev = ADRENO_REV(5, 0, 8, ANY_ID),
157 [ADRENO_FW_PM4] = "a530_pm4.fw",
158 [ADRENO_FW_PFP] = "a530_pfp.fw",
160 .gmem = (SZ_128K + SZ_8K),
162 * Increase inactive period to 250 to avoid bouncing
163 * the GDSC which appears to make it grumpy
165 .inactive_period = 250,
166 .quirks = ADRENO_QUIRK_LMLOADKILL_DISABLE,
167 .init = a5xx_gpu_init,
168 .zapfw = "a508_zap.mdt",
170 .rev = ADRENO_REV(5, 0, 9, ANY_ID),
174 [ADRENO_FW_PM4] = "a530_pm4.fw",
175 [ADRENO_FW_PFP] = "a530_pfp.fw",
177 .gmem = (SZ_256K + SZ_16K),
179 * Increase inactive period to 250 to avoid bouncing
180 * the GDSC which appears to make it grumpy
182 .inactive_period = 250,
183 .quirks = ADRENO_QUIRK_LMLOADKILL_DISABLE,
184 .init = a5xx_gpu_init,
185 /* Adreno 509 uses the same ZAP as 512 */
186 .zapfw = "a512_zap.mdt",
188 .rev = ADRENO_REV(5, 1, 0, ANY_ID),
192 [ADRENO_FW_PM4] = "a530_pm4.fw",
193 [ADRENO_FW_PFP] = "a530_pfp.fw",
197 * Increase inactive period to 250 to avoid bouncing
198 * the GDSC which appears to make it grumpy
200 .inactive_period = 250,
201 .init = a5xx_gpu_init,
203 .rev = ADRENO_REV(5, 1, 2, ANY_ID),
207 [ADRENO_FW_PM4] = "a530_pm4.fw",
208 [ADRENO_FW_PFP] = "a530_pfp.fw",
210 .gmem = (SZ_256K + SZ_16K),
212 * Increase inactive period to 250 to avoid bouncing
213 * the GDSC which appears to make it grumpy
215 .inactive_period = 250,
216 .quirks = ADRENO_QUIRK_LMLOADKILL_DISABLE,
217 .init = a5xx_gpu_init,
218 .zapfw = "a512_zap.mdt",
220 .rev = ADRENO_REV(5, 3, 0, 2),
224 [ADRENO_FW_PM4] = "a530_pm4.fw",
225 [ADRENO_FW_PFP] = "a530_pfp.fw",
226 [ADRENO_FW_GPMU] = "a530v3_gpmu.fw2",
230 * Increase inactive period to 250 to avoid bouncing
231 * the GDSC which appears to make it grumpy
233 .inactive_period = 250,
234 .quirks = ADRENO_QUIRK_TWO_PASS_USE_WFI |
235 ADRENO_QUIRK_FAULT_DETECT_MASK,
236 .init = a5xx_gpu_init,
237 .zapfw = "a530_zap.mdt",
239 .rev = ADRENO_REV(5, 4, 0, ANY_ID),
243 [ADRENO_FW_PM4] = "a530_pm4.fw",
244 [ADRENO_FW_PFP] = "a530_pfp.fw",
245 [ADRENO_FW_GPMU] = "a540_gpmu.fw2",
249 * Increase inactive period to 250 to avoid bouncing
250 * the GDSC which appears to make it grumpy
252 .inactive_period = 250,
253 .quirks = ADRENO_QUIRK_LMLOADKILL_DISABLE,
254 .init = a5xx_gpu_init,
255 .zapfw = "a540_zap.mdt",
257 .rev = ADRENO_REV(6, 1, 8, ANY_ID),
261 [ADRENO_FW_SQE] = "a630_sqe.fw",
262 [ADRENO_FW_GMU] = "a630_gmu.bin",
265 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
266 .init = a6xx_gpu_init,
268 .rev = ADRENO_REV(6, 3, 0, ANY_ID),
272 [ADRENO_FW_SQE] = "a630_sqe.fw",
273 [ADRENO_FW_GMU] = "a630_gmu.bin",
276 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
277 .init = a6xx_gpu_init,
278 .zapfw = "a630_zap.mdt",
281 .rev = ADRENO_REV(6, 4, 0, ANY_ID),
285 [ADRENO_FW_SQE] = "a630_sqe.fw",
286 [ADRENO_FW_GMU] = "a640_gmu.bin",
289 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
290 .init = a6xx_gpu_init,
291 .zapfw = "a640_zap.mdt",
294 .rev = ADRENO_REV(6, 5, 0, ANY_ID),
298 [ADRENO_FW_SQE] = "a650_sqe.fw",
299 [ADRENO_FW_GMU] = "a650_gmu.bin",
301 .gmem = SZ_1M + SZ_128K,
302 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
303 .init = a6xx_gpu_init,
304 .zapfw = "a650_zap.mdt",
307 .rev = ADRENO_REV(6, 6, 0, ANY_ID),
311 [ADRENO_FW_SQE] = "a660_sqe.fw",
312 [ADRENO_FW_GMU] = "a660_gmu.bin",
314 .gmem = SZ_1M + SZ_512K,
315 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
316 .init = a6xx_gpu_init,
317 .zapfw = "a660_zap.mdt",
320 .rev = ADRENO_REV(6, 3, 5, ANY_ID),
322 [ADRENO_FW_SQE] = "a660_sqe.fw",
323 [ADRENO_FW_GMU] = "a660_gmu.bin",
326 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
327 .init = a6xx_gpu_init,
330 .rev = ADRENO_REV(6, 8, 0, ANY_ID),
334 [ADRENO_FW_SQE] = "a630_sqe.fw",
335 [ADRENO_FW_GMU] = "a640_gmu.bin",
338 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
339 .init = a6xx_gpu_init,
340 .zapfw = "a640_zap.mdt",
345 MODULE_FIRMWARE("qcom/a300_pm4.fw");
346 MODULE_FIRMWARE("qcom/a300_pfp.fw");
347 MODULE_FIRMWARE("qcom/a330_pm4.fw");
348 MODULE_FIRMWARE("qcom/a330_pfp.fw");
349 MODULE_FIRMWARE("qcom/a420_pm4.fw");
350 MODULE_FIRMWARE("qcom/a420_pfp.fw");
351 MODULE_FIRMWARE("qcom/a530_pm4.fw");
352 MODULE_FIRMWARE("qcom/a530_pfp.fw");
353 MODULE_FIRMWARE("qcom/a530v3_gpmu.fw2");
354 MODULE_FIRMWARE("qcom/a530_zap.mdt");
355 MODULE_FIRMWARE("qcom/a530_zap.b00");
356 MODULE_FIRMWARE("qcom/a530_zap.b01");
357 MODULE_FIRMWARE("qcom/a530_zap.b02");
358 MODULE_FIRMWARE("qcom/a630_sqe.fw");
359 MODULE_FIRMWARE("qcom/a630_gmu.bin");
360 MODULE_FIRMWARE("qcom/a630_zap.mbn");
362 static inline bool _rev_match(uint8_t entry, uint8_t id)
364 return (entry == ANY_ID) || (entry == id);
367 bool adreno_cmp_rev(struct adreno_rev rev1, struct adreno_rev rev2)
370 return _rev_match(rev1.core, rev2.core) &&
371 _rev_match(rev1.major, rev2.major) &&
372 _rev_match(rev1.minor, rev2.minor) &&
373 _rev_match(rev1.patchid, rev2.patchid);
376 const struct adreno_info *adreno_info(struct adreno_rev rev)
381 for (i = 0; i < ARRAY_SIZE(gpulist); i++) {
382 const struct adreno_info *info = &gpulist[i];
383 if (adreno_cmp_rev(info->rev, rev))
390 struct msm_gpu *adreno_load_gpu(struct drm_device *dev)
392 struct msm_drm_private *priv = dev->dev_private;
393 struct platform_device *pdev = priv->gpu_pdev;
394 struct msm_gpu *gpu = NULL;
395 struct adreno_gpu *adreno_gpu;
399 gpu = dev_to_gpu(&pdev->dev);
402 dev_err_once(dev->dev, "no GPU device was found\n");
406 adreno_gpu = to_adreno_gpu(gpu);
409 * The number one reason for HW init to fail is if the firmware isn't
410 * loaded yet. Try that first and don't bother continuing on
414 ret = adreno_load_fw(adreno_gpu);
418 /* Make sure pm runtime is active and reset any previous errors */
419 pm_runtime_set_active(&pdev->dev);
421 ret = pm_runtime_get_sync(&pdev->dev);
423 pm_runtime_put_sync(&pdev->dev);
424 DRM_DEV_ERROR(dev->dev, "Couldn't power up the GPU: %d\n", ret);
428 mutex_lock(&gpu->lock);
429 ret = msm_gpu_hw_init(gpu);
430 mutex_unlock(&gpu->lock);
431 pm_runtime_put_autosuspend(&pdev->dev);
433 DRM_DEV_ERROR(dev->dev, "gpu hw init failed: %d\n", ret);
437 #ifdef CONFIG_DEBUG_FS
438 if (gpu->funcs->debugfs_init) {
439 gpu->funcs->debugfs_init(gpu, dev->primary);
440 gpu->funcs->debugfs_init(gpu, dev->render);
447 static int find_chipid(struct device *dev, struct adreno_rev *rev)
449 struct device_node *node = dev->of_node;
454 /* first search the compat strings for qcom,adreno-XYZ.W: */
455 ret = of_property_read_string_index(node, "compatible", 0, &compat);
457 unsigned int r, patch;
459 if (sscanf(compat, "qcom,adreno-%u.%u", &r, &patch) == 2 ||
460 sscanf(compat, "amd,imageon-%u.%u", &r, &patch) == 2) {
466 rev->patchid = patch;
472 /* and if that fails, fall back to legacy "qcom,chipid" property: */
473 ret = of_property_read_u32(node, "qcom,chipid", &chipid);
475 DRM_DEV_ERROR(dev, "could not parse qcom,chipid: %d\n", ret);
479 rev->core = (chipid >> 24) & 0xff;
480 rev->major = (chipid >> 16) & 0xff;
481 rev->minor = (chipid >> 8) & 0xff;
482 rev->patchid = (chipid & 0xff);
484 dev_warn(dev, "Using legacy qcom,chipid binding!\n");
485 dev_warn(dev, "Use compatible qcom,adreno-%u%u%u.%u instead.\n",
486 rev->core, rev->major, rev->minor, rev->patchid);
491 static int adreno_bind(struct device *dev, struct device *master, void *data)
493 static struct adreno_platform_config config = {};
494 const struct adreno_info *info;
495 struct msm_drm_private *priv = dev_get_drvdata(master);
496 struct drm_device *drm = priv->dev;
500 ret = find_chipid(dev, &config.rev);
504 dev->platform_data = &config;
505 priv->gpu_pdev = to_platform_device(dev);
507 info = adreno_info(config.rev);
510 dev_warn(drm->dev, "Unknown GPU revision: %u.%u.%u.%u\n",
511 config.rev.core, config.rev.major,
512 config.rev.minor, config.rev.patchid);
516 DBG("Found GPU: %u.%u.%u.%u", config.rev.core, config.rev.major,
517 config.rev.minor, config.rev.patchid);
519 priv->is_a2xx = config.rev.core == 2;
520 priv->has_cached_coherent = config.rev.core >= 6;
522 gpu = info->init(drm);
524 dev_warn(drm->dev, "failed to load adreno gpu\n");
531 static void adreno_unbind(struct device *dev, struct device *master,
534 struct msm_drm_private *priv = dev_get_drvdata(master);
535 struct msm_gpu *gpu = dev_to_gpu(dev);
537 pm_runtime_force_suspend(dev);
538 gpu->funcs->destroy(gpu);
540 priv->gpu_pdev = NULL;
543 static const struct component_ops a3xx_ops = {
545 .unbind = adreno_unbind,
548 static void adreno_device_register_headless(void)
550 /* on imx5, we don't have a top-level mdp/dpu node
551 * this creates a dummy node for the driver for that case
553 struct platform_device_info dummy_info = {
563 platform_device_register_full(&dummy_info);
566 static int adreno_probe(struct platform_device *pdev)
571 ret = component_add(&pdev->dev, &a3xx_ops);
575 if (of_device_is_compatible(pdev->dev.of_node, "amd,imageon"))
576 adreno_device_register_headless();
581 static int adreno_remove(struct platform_device *pdev)
583 component_del(&pdev->dev, &a3xx_ops);
587 static void adreno_shutdown(struct platform_device *pdev)
589 pm_runtime_force_suspend(&pdev->dev);
592 static const struct of_device_id dt_match[] = {
593 { .compatible = "qcom,adreno" },
594 { .compatible = "qcom,adreno-3xx" },
595 /* for compatibility with imx5 gpu: */
596 { .compatible = "amd,imageon" },
597 /* for backwards compat w/ downstream kgsl DT files: */
598 { .compatible = "qcom,kgsl-3d0" },
603 static int adreno_resume(struct device *dev)
605 struct msm_gpu *gpu = dev_to_gpu(dev);
607 return gpu->funcs->pm_resume(gpu);
610 static int active_submits(struct msm_gpu *gpu)
613 mutex_lock(&gpu->active_lock);
614 active_submits = gpu->active_submits;
615 mutex_unlock(&gpu->active_lock);
616 return active_submits;
619 static int adreno_suspend(struct device *dev)
621 struct msm_gpu *gpu = dev_to_gpu(dev);
624 remaining = wait_event_timeout(gpu->retire_event,
625 active_submits(gpu) == 0,
626 msecs_to_jiffies(1000));
627 if (remaining == 0) {
628 dev_err(dev, "Timeout waiting for GPU to suspend\n");
632 return gpu->funcs->pm_suspend(gpu);
636 static const struct dev_pm_ops adreno_pm_ops = {
637 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
638 SET_RUNTIME_PM_OPS(adreno_suspend, adreno_resume, NULL)
641 static struct platform_driver adreno_driver = {
642 .probe = adreno_probe,
643 .remove = adreno_remove,
644 .shutdown = adreno_shutdown,
647 .of_match_table = dt_match,
648 .pm = &adreno_pm_ops,
652 void __init adreno_register(void)
654 platform_driver_register(&adreno_driver);
657 void __exit adreno_unregister(void)
659 platform_driver_unregister(&adreno_driver);