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"
13 bool hang_debug = false;
14 MODULE_PARM_DESC(hang_debug, "Dump registers when hang is detected (can be slow!)");
15 module_param_named(hang_debug, hang_debug, bool, 0600);
17 bool snapshot_debugbus = false;
18 MODULE_PARM_DESC(snapshot_debugbus, "Include debugbus sections in GPU devcoredump (if not fused off)");
19 module_param_named(snapshot_debugbus, snapshot_debugbus, bool, 0600);
21 static const struct adreno_info gpulist[] = {
23 .rev = ADRENO_REV(2, 0, 0, 0),
27 [ADRENO_FW_PM4] = "yamato_pm4.fw",
28 [ADRENO_FW_PFP] = "yamato_pfp.fw",
31 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
32 .init = a2xx_gpu_init,
33 }, { /* a200 on i.mx51 has only 128kib gmem */
34 .rev = ADRENO_REV(2, 0, 0, 1),
38 [ADRENO_FW_PM4] = "yamato_pm4.fw",
39 [ADRENO_FW_PFP] = "yamato_pfp.fw",
42 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
43 .init = a2xx_gpu_init,
45 .rev = ADRENO_REV(2, 2, 0, ANY_ID),
49 [ADRENO_FW_PM4] = "leia_pm4_470.fw",
50 [ADRENO_FW_PFP] = "leia_pfp_470.fw",
53 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
54 .init = a2xx_gpu_init,
56 .rev = ADRENO_REV(3, 0, 5, ANY_ID),
60 [ADRENO_FW_PM4] = "a300_pm4.fw",
61 [ADRENO_FW_PFP] = "a300_pfp.fw",
64 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
65 .init = a3xx_gpu_init,
67 .rev = ADRENO_REV(3, 0, 6, 0),
68 .revn = 307, /* because a305c is revn==306 */
71 [ADRENO_FW_PM4] = "a300_pm4.fw",
72 [ADRENO_FW_PFP] = "a300_pfp.fw",
75 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
76 .init = a3xx_gpu_init,
78 .rev = ADRENO_REV(3, 2, ANY_ID, ANY_ID),
82 [ADRENO_FW_PM4] = "a300_pm4.fw",
83 [ADRENO_FW_PFP] = "a300_pfp.fw",
86 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
87 .init = a3xx_gpu_init,
89 .rev = ADRENO_REV(3, 3, 0, ANY_ID),
93 [ADRENO_FW_PM4] = "a330_pm4.fw",
94 [ADRENO_FW_PFP] = "a330_pfp.fw",
97 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
98 .init = a3xx_gpu_init,
100 .rev = ADRENO_REV(4, 0, 5, ANY_ID),
104 [ADRENO_FW_PM4] = "a420_pm4.fw",
105 [ADRENO_FW_PFP] = "a420_pfp.fw",
108 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
109 .init = a4xx_gpu_init,
111 .rev = ADRENO_REV(4, 2, 0, ANY_ID),
115 [ADRENO_FW_PM4] = "a420_pm4.fw",
116 [ADRENO_FW_PFP] = "a420_pfp.fw",
118 .gmem = (SZ_1M + SZ_512K),
119 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
120 .init = a4xx_gpu_init,
122 .rev = ADRENO_REV(4, 3, 0, ANY_ID),
126 [ADRENO_FW_PM4] = "a420_pm4.fw",
127 [ADRENO_FW_PFP] = "a420_pfp.fw",
129 .gmem = (SZ_1M + SZ_512K),
130 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
131 .init = a4xx_gpu_init,
133 .rev = ADRENO_REV(5, 1, 0, ANY_ID),
137 [ADRENO_FW_PM4] = "a530_pm4.fw",
138 [ADRENO_FW_PFP] = "a530_pfp.fw",
142 * Increase inactive period to 250 to avoid bouncing
143 * the GDSC which appears to make it grumpy
145 .inactive_period = 250,
146 .init = a5xx_gpu_init,
148 .rev = ADRENO_REV(5, 3, 0, 2),
152 [ADRENO_FW_PM4] = "a530_pm4.fw",
153 [ADRENO_FW_PFP] = "a530_pfp.fw",
154 [ADRENO_FW_GPMU] = "a530v3_gpmu.fw2",
158 * Increase inactive period to 250 to avoid bouncing
159 * the GDSC which appears to make it grumpy
161 .inactive_period = 250,
162 .quirks = ADRENO_QUIRK_TWO_PASS_USE_WFI |
163 ADRENO_QUIRK_FAULT_DETECT_MASK,
164 .init = a5xx_gpu_init,
165 .zapfw = "a530_zap.mdt",
167 .rev = ADRENO_REV(5, 4, 0, 2),
171 [ADRENO_FW_PM4] = "a530_pm4.fw",
172 [ADRENO_FW_PFP] = "a530_pfp.fw",
173 [ADRENO_FW_GPMU] = "a540_gpmu.fw2",
177 * Increase inactive period to 250 to avoid bouncing
178 * the GDSC which appears to make it grumpy
180 .inactive_period = 250,
181 .quirks = ADRENO_QUIRK_LMLOADKILL_DISABLE,
182 .init = a5xx_gpu_init,
183 .zapfw = "a540_zap.mdt",
185 .rev = ADRENO_REV(6, 1, 8, ANY_ID),
189 [ADRENO_FW_SQE] = "a630_sqe.fw",
190 [ADRENO_FW_GMU] = "a630_gmu.bin",
193 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
194 .init = a6xx_gpu_init,
196 .rev = ADRENO_REV(6, 3, 0, ANY_ID),
200 [ADRENO_FW_SQE] = "a630_sqe.fw",
201 [ADRENO_FW_GMU] = "a630_gmu.bin",
204 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
205 .init = a6xx_gpu_init,
206 .zapfw = "a630_zap.mdt",
209 .rev = ADRENO_REV(6, 4, 0, ANY_ID),
213 [ADRENO_FW_SQE] = "a630_sqe.fw",
214 [ADRENO_FW_GMU] = "a640_gmu.bin",
217 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
218 .init = a6xx_gpu_init,
219 .zapfw = "a640_zap.mdt",
222 .rev = ADRENO_REV(6, 5, 0, ANY_ID),
226 [ADRENO_FW_SQE] = "a650_sqe.fw",
227 [ADRENO_FW_GMU] = "a650_gmu.bin",
229 .gmem = SZ_1M + SZ_128K,
230 .inactive_period = DRM_MSM_INACTIVE_PERIOD,
231 .init = a6xx_gpu_init,
232 .zapfw = "a650_zap.mdt",
237 MODULE_FIRMWARE("qcom/a300_pm4.fw");
238 MODULE_FIRMWARE("qcom/a300_pfp.fw");
239 MODULE_FIRMWARE("qcom/a330_pm4.fw");
240 MODULE_FIRMWARE("qcom/a330_pfp.fw");
241 MODULE_FIRMWARE("qcom/a420_pm4.fw");
242 MODULE_FIRMWARE("qcom/a420_pfp.fw");
243 MODULE_FIRMWARE("qcom/a530_pm4.fw");
244 MODULE_FIRMWARE("qcom/a530_pfp.fw");
245 MODULE_FIRMWARE("qcom/a530v3_gpmu.fw2");
246 MODULE_FIRMWARE("qcom/a530_zap.mdt");
247 MODULE_FIRMWARE("qcom/a530_zap.b00");
248 MODULE_FIRMWARE("qcom/a530_zap.b01");
249 MODULE_FIRMWARE("qcom/a530_zap.b02");
250 MODULE_FIRMWARE("qcom/a630_sqe.fw");
251 MODULE_FIRMWARE("qcom/a630_gmu.bin");
252 MODULE_FIRMWARE("qcom/a630_zap.mbn");
254 static inline bool _rev_match(uint8_t entry, uint8_t id)
256 return (entry == ANY_ID) || (entry == id);
259 const struct adreno_info *adreno_info(struct adreno_rev rev)
264 for (i = 0; i < ARRAY_SIZE(gpulist); i++) {
265 const struct adreno_info *info = &gpulist[i];
266 if (_rev_match(info->rev.core, rev.core) &&
267 _rev_match(info->rev.major, rev.major) &&
268 _rev_match(info->rev.minor, rev.minor) &&
269 _rev_match(info->rev.patchid, rev.patchid))
276 struct msm_gpu *adreno_load_gpu(struct drm_device *dev)
278 struct msm_drm_private *priv = dev->dev_private;
279 struct platform_device *pdev = priv->gpu_pdev;
280 struct msm_gpu *gpu = NULL;
281 struct adreno_gpu *adreno_gpu;
285 gpu = platform_get_drvdata(pdev);
288 dev_err_once(dev->dev, "no GPU device was found\n");
292 adreno_gpu = to_adreno_gpu(gpu);
295 * The number one reason for HW init to fail is if the firmware isn't
296 * loaded yet. Try that first and don't bother continuing on
300 ret = adreno_load_fw(adreno_gpu);
304 /* Make sure pm runtime is active and reset any previous errors */
305 pm_runtime_set_active(&pdev->dev);
307 ret = pm_runtime_get_sync(&pdev->dev);
309 pm_runtime_put_sync(&pdev->dev);
310 DRM_DEV_ERROR(dev->dev, "Couldn't power up the GPU: %d\n", ret);
314 mutex_lock(&dev->struct_mutex);
315 ret = msm_gpu_hw_init(gpu);
316 mutex_unlock(&dev->struct_mutex);
317 pm_runtime_put_autosuspend(&pdev->dev);
319 DRM_DEV_ERROR(dev->dev, "gpu hw init failed: %d\n", ret);
323 #ifdef CONFIG_DEBUG_FS
324 if (gpu->funcs->debugfs_init) {
325 gpu->funcs->debugfs_init(gpu, dev->primary);
326 gpu->funcs->debugfs_init(gpu, dev->render);
333 static void set_gpu_pdev(struct drm_device *dev,
334 struct platform_device *pdev)
336 struct msm_drm_private *priv = dev->dev_private;
337 priv->gpu_pdev = pdev;
340 static int find_chipid(struct device *dev, struct adreno_rev *rev)
342 struct device_node *node = dev->of_node;
347 /* first search the compat strings for qcom,adreno-XYZ.W: */
348 ret = of_property_read_string_index(node, "compatible", 0, &compat);
350 unsigned int r, patch;
352 if (sscanf(compat, "qcom,adreno-%u.%u", &r, &patch) == 2 ||
353 sscanf(compat, "amd,imageon-%u.%u", &r, &patch) == 2) {
359 rev->patchid = patch;
365 /* and if that fails, fall back to legacy "qcom,chipid" property: */
366 ret = of_property_read_u32(node, "qcom,chipid", &chipid);
368 DRM_DEV_ERROR(dev, "could not parse qcom,chipid: %d\n", ret);
372 rev->core = (chipid >> 24) & 0xff;
373 rev->major = (chipid >> 16) & 0xff;
374 rev->minor = (chipid >> 8) & 0xff;
375 rev->patchid = (chipid & 0xff);
377 dev_warn(dev, "Using legacy qcom,chipid binding!\n");
378 dev_warn(dev, "Use compatible qcom,adreno-%u%u%u.%u instead.\n",
379 rev->core, rev->major, rev->minor, rev->patchid);
384 static int adreno_bind(struct device *dev, struct device *master, void *data)
386 static struct adreno_platform_config config = {};
387 const struct adreno_info *info;
388 struct drm_device *drm = dev_get_drvdata(master);
389 struct msm_drm_private *priv = drm->dev_private;
393 ret = find_chipid(dev, &config.rev);
397 dev->platform_data = &config;
398 set_gpu_pdev(drm, to_platform_device(dev));
400 info = adreno_info(config.rev);
403 dev_warn(drm->dev, "Unknown GPU revision: %u.%u.%u.%u\n",
404 config.rev.core, config.rev.major,
405 config.rev.minor, config.rev.patchid);
409 DBG("Found GPU: %u.%u.%u.%u", config.rev.core, config.rev.major,
410 config.rev.minor, config.rev.patchid);
412 priv->is_a2xx = config.rev.core == 2;
414 gpu = info->init(drm);
416 dev_warn(drm->dev, "failed to load adreno gpu\n");
420 dev_set_drvdata(dev, gpu);
425 static void adreno_unbind(struct device *dev, struct device *master,
428 struct msm_gpu *gpu = dev_get_drvdata(dev);
430 pm_runtime_force_suspend(dev);
431 gpu->funcs->destroy(gpu);
433 set_gpu_pdev(dev_get_drvdata(master), NULL);
436 static const struct component_ops a3xx_ops = {
438 .unbind = adreno_unbind,
441 static void adreno_device_register_headless(void)
443 /* on imx5, we don't have a top-level mdp/dpu node
444 * this creates a dummy node for the driver for that case
446 struct platform_device_info dummy_info = {
456 platform_device_register_full(&dummy_info);
459 static int adreno_probe(struct platform_device *pdev)
464 ret = component_add(&pdev->dev, &a3xx_ops);
468 if (of_device_is_compatible(pdev->dev.of_node, "amd,imageon"))
469 adreno_device_register_headless();
474 static int adreno_remove(struct platform_device *pdev)
476 component_del(&pdev->dev, &a3xx_ops);
480 static const struct of_device_id dt_match[] = {
481 { .compatible = "qcom,adreno" },
482 { .compatible = "qcom,adreno-3xx" },
483 /* for compatibility with imx5 gpu: */
484 { .compatible = "amd,imageon" },
485 /* for backwards compat w/ downstream kgsl DT files: */
486 { .compatible = "qcom,kgsl-3d0" },
491 static int adreno_resume(struct device *dev)
493 struct platform_device *pdev = to_platform_device(dev);
494 struct msm_gpu *gpu = platform_get_drvdata(pdev);
496 return gpu->funcs->pm_resume(gpu);
499 static int adreno_suspend(struct device *dev)
501 struct platform_device *pdev = to_platform_device(dev);
502 struct msm_gpu *gpu = platform_get_drvdata(pdev);
504 return gpu->funcs->pm_suspend(gpu);
508 static const struct dev_pm_ops adreno_pm_ops = {
509 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
510 SET_RUNTIME_PM_OPS(adreno_suspend, adreno_resume, NULL)
513 static struct platform_driver adreno_driver = {
514 .probe = adreno_probe,
515 .remove = adreno_remove,
518 .of_match_table = dt_match,
519 .pm = &adreno_pm_ops,
523 void __init adreno_register(void)
525 platform_driver_register(&adreno_driver);
528 void __exit adreno_unregister(void)
530 platform_driver_unregister(&adreno_driver);