adreno_device.c 12.5 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-only
2 3 4 5
/*
 * Copyright (C) 2013-2014 Red Hat
 * Author: Rob Clark <robdclark@gmail.com>
 *
6
 * Copyright (c) 2014,2017 The Linux Foundation. All rights reserved.
7 8 9 10
 */

#include "adreno_gpu.h"

11 12
#define ANY_ID 0xff

13 14 15 16
bool hang_debug = false;
MODULE_PARM_DESC(hang_debug, "Dump registers when hang is detected (can be slow!)");
module_param_named(hang_debug, hang_debug, bool, 0600);

17 18 19 20
bool snapshot_debugbus = false;
MODULE_PARM_DESC(snapshot_debugbus, "Include debugbus sections in GPU devcoredump (if not fused off)");
module_param_named(snapshot_debugbus, snapshot_debugbus, bool, 0600);

21 22
static const struct adreno_info gpulist[] = {
	{
J
Jonathan Marek 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
		.rev   = ADRENO_REV(2, 0, 0, 0),
		.revn  = 200,
		.name  = "A200",
		.fw = {
			[ADRENO_FW_PM4] = "yamato_pm4.fw",
			[ADRENO_FW_PFP] = "yamato_pfp.fw",
		},
		.gmem  = SZ_256K,
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
		.init  = a2xx_gpu_init,
	}, { /* a200 on i.mx51 has only 128kib gmem */
		.rev   = ADRENO_REV(2, 0, 0, 1),
		.revn  = 201,
		.name  = "A200",
		.fw = {
			[ADRENO_FW_PM4] = "yamato_pm4.fw",
			[ADRENO_FW_PFP] = "yamato_pfp.fw",
		},
		.gmem  = SZ_128K,
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
		.init  = a2xx_gpu_init,
	}, {
		.rev   = ADRENO_REV(2, 2, 0, ANY_ID),
		.revn  = 220,
		.name  = "A220",
		.fw = {
			[ADRENO_FW_PM4] = "leia_pm4_470.fw",
			[ADRENO_FW_PFP] = "leia_pfp_470.fw",
		},
		.gmem  = SZ_512K,
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
		.init  = a2xx_gpu_init,
	}, {
56 57 58
		.rev   = ADRENO_REV(3, 0, 5, ANY_ID),
		.revn  = 305,
		.name  = "A305",
59 60 61 62
		.fw = {
			[ADRENO_FW_PM4] = "a300_pm4.fw",
			[ADRENO_FW_PFP] = "a300_pfp.fw",
		},
63
		.gmem  = SZ_256K,
64
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
65
		.init  = a3xx_gpu_init,
R
Rob Clark 已提交
66 67 68 69
	}, {
		.rev   = ADRENO_REV(3, 0, 6, 0),
		.revn  = 307,        /* because a305c is revn==306 */
		.name  = "A306",
70 71 72 73
		.fw = {
			[ADRENO_FW_PM4] = "a300_pm4.fw",
			[ADRENO_FW_PFP] = "a300_pfp.fw",
		},
R
Rob Clark 已提交
74
		.gmem  = SZ_128K,
75
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
R
Rob Clark 已提交
76
		.init  = a3xx_gpu_init,
77 78 79 80
	}, {
		.rev   = ADRENO_REV(3, 2, ANY_ID, ANY_ID),
		.revn  = 320,
		.name  = "A320",
81 82 83 84
		.fw = {
			[ADRENO_FW_PM4] = "a300_pm4.fw",
			[ADRENO_FW_PFP] = "a300_pfp.fw",
		},
85
		.gmem  = SZ_512K,
86
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
87 88 89 90 91
		.init  = a3xx_gpu_init,
	}, {
		.rev   = ADRENO_REV(3, 3, 0, ANY_ID),
		.revn  = 330,
		.name  = "A330",
92 93 94 95
		.fw = {
			[ADRENO_FW_PM4] = "a330_pm4.fw",
			[ADRENO_FW_PFP] = "a330_pfp.fw",
		},
96
		.gmem  = SZ_1M,
97
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
98
		.init  = a3xx_gpu_init,
99 100 101 102 103 104 105 106 107 108 109
	}, {
		.rev   = ADRENO_REV(4, 0, 5, ANY_ID),
		.revn  = 405,
		.name  = "A405",
		.fw = {
			[ADRENO_FW_PM4] = "a420_pm4.fw",
			[ADRENO_FW_PFP] = "a420_pfp.fw",
		},
		.gmem  = SZ_256K,
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
		.init  = a4xx_gpu_init,
110 111 112 113
	}, {
		.rev   = ADRENO_REV(4, 2, 0, ANY_ID),
		.revn  = 420,
		.name  = "A420",
114 115 116 117
		.fw = {
			[ADRENO_FW_PM4] = "a420_pm4.fw",
			[ADRENO_FW_PFP] = "a420_pfp.fw",
		},
118
		.gmem  = (SZ_1M + SZ_512K),
119
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
120
		.init  = a4xx_gpu_init,
121 122 123 124
	}, {
		.rev   = ADRENO_REV(4, 3, 0, ANY_ID),
		.revn  = 430,
		.name  = "A430",
125 126 127 128
		.fw = {
			[ADRENO_FW_PM4] = "a420_pm4.fw",
			[ADRENO_FW_PFP] = "a420_pfp.fw",
		},
129
		.gmem  = (SZ_1M + SZ_512K),
130
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
131
		.init  = a4xx_gpu_init,
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
	}, {
		.rev   = ADRENO_REV(5, 1, 0, ANY_ID),
		.revn = 510,
		.name = "A510",
		.fw = {
			[ADRENO_FW_PM4] = "a530_pm4.fw",
			[ADRENO_FW_PFP] = "a530_pfp.fw",
		},
		.gmem = SZ_256K,
		/*
		 * Increase inactive period to 250 to avoid bouncing
		 * the GDSC which appears to make it grumpy
		 */
		.inactive_period = 250,
		.init = a5xx_gpu_init,
147
	}, {
R
Rob Clark 已提交
148
		.rev = ADRENO_REV(5, 3, 0, 2),
149 150
		.revn = 530,
		.name = "A530",
151 152 153 154 155
		.fw = {
			[ADRENO_FW_PM4] = "a530_pm4.fw",
			[ADRENO_FW_PFP] = "a530_pfp.fw",
			[ADRENO_FW_GPMU] = "a530v3_gpmu.fw2",
		},
156
		.gmem = SZ_1M,
157 158 159 160 161
		/*
		 * Increase inactive period to 250 to avoid bouncing
		 * the GDSC which appears to make it grumpy
		 */
		.inactive_period = 250,
R
Rob Clark 已提交
162 163
		.quirks = ADRENO_QUIRK_TWO_PASS_USE_WFI |
			ADRENO_QUIRK_FAULT_DETECT_MASK,
164
		.init = a5xx_gpu_init,
165
		.zapfw = "a530_zap.mdt",
J
Jeffrey Hugo 已提交
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
	}, {
		.rev = ADRENO_REV(5, 4, 0, 2),
		.revn = 540,
		.name = "A540",
		.fw = {
			[ADRENO_FW_PM4] = "a530_pm4.fw",
			[ADRENO_FW_PFP] = "a530_pfp.fw",
			[ADRENO_FW_GPMU] = "a540_gpmu.fw2",
		},
		.gmem = SZ_1M,
		/*
		 * Increase inactive period to 250 to avoid bouncing
		 * the GDSC which appears to make it grumpy
		 */
		.inactive_period = 250,
		.quirks = ADRENO_QUIRK_LMLOADKILL_DISABLE,
		.init = a5xx_gpu_init,
		.zapfw = "a540_zap.mdt",
184 185 186 187 188 189 190 191 192 193 194
	}, {
		.rev = ADRENO_REV(6, 1, 8, ANY_ID),
		.revn = 618,
		.name = "A618",
		.fw = {
			[ADRENO_FW_SQE] = "a630_sqe.fw",
			[ADRENO_FW_GMU] = "a630_gmu.bin",
		},
		.gmem = SZ_512K,
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
		.init = a6xx_gpu_init,
J
Jordan Crouse 已提交
195 196 197 198 199 200 201 202 203
	}, {
		.rev = ADRENO_REV(6, 3, 0, ANY_ID),
		.revn = 630,
		.name = "A630",
		.fw = {
			[ADRENO_FW_SQE] = "a630_sqe.fw",
			[ADRENO_FW_GMU] = "a630_gmu.bin",
		},
		.gmem = SZ_1M,
204
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
J
Jordan Crouse 已提交
205
		.init = a6xx_gpu_init,
206
		.zapfw = "a630_zap.mdt",
207
		.hwcg = a630_hwcg,
208 209 210 211 212 213 214 215 216 217 218 219
	}, {
		.rev = ADRENO_REV(6, 4, 0, ANY_ID),
		.revn = 640,
		.name = "A640",
		.fw = {
			[ADRENO_FW_SQE] = "a630_sqe.fw",
			[ADRENO_FW_GMU] = "a640_gmu.bin",
		},
		.gmem = SZ_1M,
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
		.init = a6xx_gpu_init,
		.zapfw = "a640_zap.mdt",
220
		.hwcg = a640_hwcg,
221 222 223 224 225 226 227 228 229 230 231 232
	}, {
		.rev = ADRENO_REV(6, 5, 0, ANY_ID),
		.revn = 650,
		.name = "A650",
		.fw = {
			[ADRENO_FW_SQE] = "a650_sqe.fw",
			[ADRENO_FW_GMU] = "a650_gmu.bin",
		},
		.gmem = SZ_1M + SZ_128K,
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
		.init = a6xx_gpu_init,
		.zapfw = "a650_zap.mdt",
233
		.hwcg = a650_hwcg,
234 235 236
	},
};

237 238 239 240 241 242
MODULE_FIRMWARE("qcom/a300_pm4.fw");
MODULE_FIRMWARE("qcom/a300_pfp.fw");
MODULE_FIRMWARE("qcom/a330_pm4.fw");
MODULE_FIRMWARE("qcom/a330_pfp.fw");
MODULE_FIRMWARE("qcom/a420_pm4.fw");
MODULE_FIRMWARE("qcom/a420_pfp.fw");
243
MODULE_FIRMWARE("qcom/a530_pm4.fw");
244
MODULE_FIRMWARE("qcom/a530_pfp.fw");
245 246 247 248 249
MODULE_FIRMWARE("qcom/a530v3_gpmu.fw2");
MODULE_FIRMWARE("qcom/a530_zap.mdt");
MODULE_FIRMWARE("qcom/a530_zap.b00");
MODULE_FIRMWARE("qcom/a530_zap.b01");
MODULE_FIRMWARE("qcom/a530_zap.b02");
J
Jordan Crouse 已提交
250 251
MODULE_FIRMWARE("qcom/a630_sqe.fw");
MODULE_FIRMWARE("qcom/a630_gmu.bin");
252
MODULE_FIRMWARE("qcom/a630_zap.mbn");
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279

static inline bool _rev_match(uint8_t entry, uint8_t id)
{
	return (entry == ANY_ID) || (entry == id);
}

const struct adreno_info *adreno_info(struct adreno_rev rev)
{
	int i;

	/* identify gpu: */
	for (i = 0; i < ARRAY_SIZE(gpulist); i++) {
		const struct adreno_info *info = &gpulist[i];
		if (_rev_match(info->rev.core, rev.core) &&
				_rev_match(info->rev.major, rev.major) &&
				_rev_match(info->rev.minor, rev.minor) &&
				_rev_match(info->rev.patchid, rev.patchid))
			return info;
	}

	return NULL;
}

struct msm_gpu *adreno_load_gpu(struct drm_device *dev)
{
	struct msm_drm_private *priv = dev->dev_private;
	struct platform_device *pdev = priv->gpu_pdev;
280
	struct msm_gpu *gpu = NULL;
281
	struct adreno_gpu *adreno_gpu;
282
	int ret;
283

284
	if (pdev)
R
Rob Clark 已提交
285
		gpu = dev_to_gpu(&pdev->dev);
286

287
	if (!gpu) {
288
		dev_err_once(dev->dev, "no GPU device was found\n");
289 290 291
		return NULL;
	}

292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
	adreno_gpu = to_adreno_gpu(gpu);

	/*
	 * The number one reason for HW init to fail is if the firmware isn't
	 * loaded yet. Try that first and don't bother continuing on
	 * otherwise
	 */

	ret = adreno_load_fw(adreno_gpu);
	if (ret)
		return NULL;

	/* Make sure pm runtime is active and reset any previous errors */
	pm_runtime_set_active(&pdev->dev);

	ret = pm_runtime_get_sync(&pdev->dev);
	if (ret < 0) {
309
		pm_runtime_put_sync(&pdev->dev);
310
		DRM_DEV_ERROR(dev->dev, "Couldn't power up the GPU: %d\n", ret);
311 312 313
		return NULL;
	}

314 315 316
	mutex_lock(&dev->struct_mutex);
	ret = msm_gpu_hw_init(gpu);
	mutex_unlock(&dev->struct_mutex);
317
	pm_runtime_put_autosuspend(&pdev->dev);
318
	if (ret) {
319
		DRM_DEV_ERROR(dev->dev, "gpu hw init failed: %d\n", ret);
320 321 322
		return NULL;
	}

323
#ifdef CONFIG_DEBUG_FS
R
Rob Clark 已提交
324 325 326 327
	if (gpu->funcs->debugfs_init) {
		gpu->funcs->debugfs_init(gpu, dev->primary);
		gpu->funcs->debugfs_init(gpu, dev->render);
	}
328
#endif
R
Rob Clark 已提交
329

330 331 332
	return gpu;
}

333 334 335 336 337 338 339
static void set_gpu_pdev(struct drm_device *dev,
		struct platform_device *pdev)
{
	struct msm_drm_private *priv = dev->dev_private;
	priv->gpu_pdev = pdev;
}

340
static int find_chipid(struct device *dev, struct adreno_rev *rev)
R
Rob Clark 已提交
341 342 343 344
{
	struct device_node *node = dev->of_node;
	const char *compat;
	int ret;
345
	u32 chipid;
R
Rob Clark 已提交
346 347 348 349

	/* first search the compat strings for qcom,adreno-XYZ.W: */
	ret = of_property_read_string_index(node, "compatible", 0, &compat);
	if (ret == 0) {
350
		unsigned int r, patch;
R
Rob Clark 已提交
351

352 353
		if (sscanf(compat, "qcom,adreno-%u.%u", &r, &patch) == 2 ||
		    sscanf(compat, "amd,imageon-%u.%u", &r, &patch) == 2) {
354 355 356 357 358 359
			rev->core = r / 100;
			r %= 100;
			rev->major = r / 10;
			r %= 10;
			rev->minor = r;
			rev->patchid = patch;
R
Rob Clark 已提交
360 361 362 363 364 365

			return 0;
		}
	}

	/* and if that fails, fall back to legacy "qcom,chipid" property: */
366 367
	ret = of_property_read_u32(node, "qcom,chipid", &chipid);
	if (ret) {
368
		DRM_DEV_ERROR(dev, "could not parse qcom,chipid: %d\n", ret);
R
Rob Clark 已提交
369
		return ret;
370 371 372 373 374 375
	}

	rev->core = (chipid >> 24) & 0xff;
	rev->major = (chipid >> 16) & 0xff;
	rev->minor = (chipid >> 8) & 0xff;
	rev->patchid = (chipid & 0xff);
R
Rob Clark 已提交
376 377 378

	dev_warn(dev, "Using legacy qcom,chipid binding!\n");
	dev_warn(dev, "Use compatible qcom,adreno-%u%u%u.%u instead.\n",
379
		rev->core, rev->major, rev->minor, rev->patchid);
R
Rob Clark 已提交
380 381 382 383

	return 0;
}

384 385 386
static int adreno_bind(struct device *dev, struct device *master, void *data)
{
	static struct adreno_platform_config config = {};
387 388
	const struct adreno_info *info;
	struct drm_device *drm = dev_get_drvdata(master);
J
Jonathan Marek 已提交
389
	struct msm_drm_private *priv = drm->dev_private;
390
	struct msm_gpu *gpu;
R
Rob Clark 已提交
391
	int ret;
392

393 394
	ret = find_chipid(dev, &config.rev);
	if (ret)
395 396 397
		return ret;

	dev->platform_data = &config;
398 399 400 401 402 403 404 405 406 407 408 409 410 411
	set_gpu_pdev(drm, to_platform_device(dev));

	info = adreno_info(config.rev);

	if (!info) {
		dev_warn(drm->dev, "Unknown GPU revision: %u.%u.%u.%u\n",
			config.rev.core, config.rev.major,
			config.rev.minor, config.rev.patchid);
		return -ENXIO;
	}

	DBG("Found GPU: %u.%u.%u.%u", config.rev.core, config.rev.major,
		config.rev.minor, config.rev.patchid);

J
Jonathan Marek 已提交
412 413
	priv->is_a2xx = config.rev.core == 2;

414 415 416 417 418 419
	gpu = info->init(drm);
	if (IS_ERR(gpu)) {
		dev_warn(drm->dev, "failed to load adreno gpu\n");
		return PTR_ERR(gpu);
	}

420 421 422 423 424 425
	return 0;
}

static void adreno_unbind(struct device *dev, struct device *master,
		void *data)
{
R
Rob Clark 已提交
426
	struct msm_gpu *gpu = dev_to_gpu(dev);
427

428
	pm_runtime_force_suspend(dev);
429 430
	gpu->funcs->destroy(gpu);

431 432 433 434 435 436 437 438
	set_gpu_pdev(dev_get_drvdata(master), NULL);
}

static const struct component_ops a3xx_ops = {
		.bind   = adreno_bind,
		.unbind = adreno_unbind,
};

439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
static void adreno_device_register_headless(void)
{
	/* on imx5, we don't have a top-level mdp/dpu node
	 * this creates a dummy node for the driver for that case
	 */
	struct platform_device_info dummy_info = {
		.parent = NULL,
		.name = "msm",
		.id = -1,
		.res = NULL,
		.num_res = 0,
		.data = NULL,
		.size_data = 0,
		.dma_mask = ~0,
	};
	platform_device_register_full(&dummy_info);
}

457 458
static int adreno_probe(struct platform_device *pdev)
{
459 460 461 462 463 464 465 466 467 468 469

	int ret;

	ret = component_add(&pdev->dev, &a3xx_ops);
	if (ret)
		return ret;

	if (of_device_is_compatible(pdev->dev.of_node, "amd,imageon"))
		adreno_device_register_headless();

	return 0;
470 471 472 473 474 475 476 477
}

static int adreno_remove(struct platform_device *pdev)
{
	component_del(&pdev->dev, &a3xx_ops);
	return 0;
}

478 479 480 481 482
static void adreno_shutdown(struct platform_device *pdev)
{
	pm_runtime_force_suspend(&pdev->dev);
}

483
static const struct of_device_id dt_match[] = {
R
Rob Clark 已提交
484
	{ .compatible = "qcom,adreno" },
485
	{ .compatible = "qcom,adreno-3xx" },
486 487
	/* for compatibility with imx5 gpu: */
	{ .compatible = "amd,imageon" },
488 489 490 491 492
	/* for backwards compat w/ downstream kgsl DT files: */
	{ .compatible = "qcom,kgsl-3d0" },
	{}
};

R
Rob Clark 已提交
493 494 495
#ifdef CONFIG_PM
static int adreno_resume(struct device *dev)
{
R
Rob Clark 已提交
496
	struct msm_gpu *gpu = dev_to_gpu(dev);
R
Rob Clark 已提交
497 498 499 500 501 502

	return gpu->funcs->pm_resume(gpu);
}

static int adreno_suspend(struct device *dev)
{
R
Rob Clark 已提交
503
	struct msm_gpu *gpu = dev_to_gpu(dev);
R
Rob Clark 已提交
504 505 506 507 508 509

	return gpu->funcs->pm_suspend(gpu);
}
#endif

static const struct dev_pm_ops adreno_pm_ops = {
510
	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
R
Rob Clark 已提交
511 512 513
	SET_RUNTIME_PM_OPS(adreno_suspend, adreno_resume, NULL)
};

514 515 516
static struct platform_driver adreno_driver = {
	.probe = adreno_probe,
	.remove = adreno_remove,
517
	.shutdown = adreno_shutdown,
518 519 520
	.driver = {
		.name = "adreno",
		.of_match_table = dt_match,
R
Rob Clark 已提交
521
		.pm = &adreno_pm_ops,
522 523 524 525 526 527 528 529 530 531 532 533
	},
};

void __init adreno_register(void)
{
	platform_driver_register(&adreno_driver);
}

void __exit adreno_unregister(void)
{
	platform_driver_unregister(&adreno_driver);
}