adreno_device.c 17.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 13 14
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);

15 16 17 18
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);

19 20 21 22
bool allow_vram_carveout = false;
MODULE_PARM_DESC(allow_vram_carveout, "Allow using VRAM Carveout, in place of IOMMU");
module_param_named(allow_vram_carveout, allow_vram_carveout, bool, 0600);

23 24
static const struct adreno_info gpulist[] = {
	{
J
Jonathan Marek 已提交
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 56 57
		.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,
	}, {
58 59 60
		.rev   = ADRENO_REV(3, 0, 5, ANY_ID),
		.revn  = 305,
		.name  = "A305",
61 62 63 64
		.fw = {
			[ADRENO_FW_PM4] = "a300_pm4.fw",
			[ADRENO_FW_PFP] = "a300_pfp.fw",
		},
65
		.gmem  = SZ_256K,
66
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
67
		.init  = a3xx_gpu_init,
R
Rob Clark 已提交
68 69 70 71
	}, {
		.rev   = ADRENO_REV(3, 0, 6, 0),
		.revn  = 307,        /* because a305c is revn==306 */
		.name  = "A306",
72 73 74 75
		.fw = {
			[ADRENO_FW_PM4] = "a300_pm4.fw",
			[ADRENO_FW_PFP] = "a300_pfp.fw",
		},
R
Rob Clark 已提交
76
		.gmem  = SZ_128K,
77
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
R
Rob Clark 已提交
78
		.init  = a3xx_gpu_init,
79 80 81 82
	}, {
		.rev   = ADRENO_REV(3, 2, ANY_ID, ANY_ID),
		.revn  = 320,
		.name  = "A320",
83 84 85 86
		.fw = {
			[ADRENO_FW_PM4] = "a300_pm4.fw",
			[ADRENO_FW_PFP] = "a300_pfp.fw",
		},
87
		.gmem  = SZ_512K,
88
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
89 90 91 92 93
		.init  = a3xx_gpu_init,
	}, {
		.rev   = ADRENO_REV(3, 3, 0, ANY_ID),
		.revn  = 330,
		.name  = "A330",
94 95 96 97
		.fw = {
			[ADRENO_FW_PM4] = "a330_pm4.fw",
			[ADRENO_FW_PFP] = "a330_pfp.fw",
		},
98
		.gmem  = SZ_1M,
99
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
100
		.init  = a3xx_gpu_init,
101 102 103 104 105 106 107 108 109 110 111
	}, {
		.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,
112 113 114 115
	}, {
		.rev   = ADRENO_REV(4, 2, 0, ANY_ID),
		.revn  = 420,
		.name  = "A420",
116 117 118 119
		.fw = {
			[ADRENO_FW_PM4] = "a420_pm4.fw",
			[ADRENO_FW_PFP] = "a420_pfp.fw",
		},
120
		.gmem  = (SZ_1M + SZ_512K),
121
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
122
		.init  = a4xx_gpu_init,
123 124 125 126
	}, {
		.rev   = ADRENO_REV(4, 3, 0, ANY_ID),
		.revn  = 430,
		.name  = "A430",
127 128 129 130
		.fw = {
			[ADRENO_FW_PM4] = "a420_pm4.fw",
			[ADRENO_FW_PFP] = "a420_pfp.fw",
		},
131
		.gmem  = (SZ_1M + SZ_512K),
132
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
133
		.init  = a4xx_gpu_init,
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
	}, {
		.rev   = ADRENO_REV(5, 0, 6, ANY_ID),
		.revn = 506,
		.name = "A506",
		.fw = {
			[ADRENO_FW_PM4] = "a530_pm4.fw",
			[ADRENO_FW_PFP] = "a530_pfp.fw",
		},
		.gmem = (SZ_128K + SZ_8K),
		/*
		 * Increase inactive period to 250 to avoid bouncing
		 * the GDSC which appears to make it grumpy
		 */
		.inactive_period = 250,
		.quirks = ADRENO_QUIRK_TWO_PASS_USE_WFI |
			  ADRENO_QUIRK_LMLOADKILL_DISABLE,
		.init = a5xx_gpu_init,
		.zapfw = "a506_zap.mdt",
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
	}, {
		.rev   = ADRENO_REV(5, 0, 8, ANY_ID),
		.revn = 508,
		.name = "A508",
		.fw = {
			[ADRENO_FW_PM4] = "a530_pm4.fw",
			[ADRENO_FW_PFP] = "a530_pfp.fw",
		},
		.gmem = (SZ_128K + SZ_8K),
		/*
		 * 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 = "a508_zap.mdt",
	}, {
		.rev   = ADRENO_REV(5, 0, 9, ANY_ID),
		.revn = 509,
		.name = "A509",
		.fw = {
			[ADRENO_FW_PM4] = "a530_pm4.fw",
			[ADRENO_FW_PFP] = "a530_pfp.fw",
		},
		.gmem = (SZ_256K + SZ_16K),
		/*
		 * 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,
		/* Adreno 509 uses the same ZAP as 512 */
		.zapfw = "a512_zap.mdt",
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
	}, {
		.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,
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
	}, {
		.rev   = ADRENO_REV(5, 1, 2, ANY_ID),
		.revn = 512,
		.name = "A512",
		.fw = {
			[ADRENO_FW_PM4] = "a530_pm4.fw",
			[ADRENO_FW_PFP] = "a530_pfp.fw",
		},
		.gmem = (SZ_256K + SZ_16K),
		/*
		 * 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 = "a512_zap.mdt",
219
	}, {
R
Rob Clark 已提交
220
		.rev = ADRENO_REV(5, 3, 0, 2),
221 222
		.revn = 530,
		.name = "A530",
223 224 225 226 227
		.fw = {
			[ADRENO_FW_PM4] = "a530_pm4.fw",
			[ADRENO_FW_PFP] = "a530_pfp.fw",
			[ADRENO_FW_GPMU] = "a530v3_gpmu.fw2",
		},
228
		.gmem = SZ_1M,
229 230 231 232 233
		/*
		 * Increase inactive period to 250 to avoid bouncing
		 * the GDSC which appears to make it grumpy
		 */
		.inactive_period = 250,
R
Rob Clark 已提交
234 235
		.quirks = ADRENO_QUIRK_TWO_PASS_USE_WFI |
			ADRENO_QUIRK_FAULT_DETECT_MASK,
236
		.init = a5xx_gpu_init,
237
		.zapfw = "a530_zap.mdt",
J
Jeffrey Hugo 已提交
238
	}, {
239
		.rev = ADRENO_REV(5, 4, 0, ANY_ID),
J
Jeffrey Hugo 已提交
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
		.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",
256 257 258 259 260 261 262 263 264 265 266
	}, {
		.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,
K
Konrad Dybcio 已提交
267 268 269 270 271 272 273 274 275 276 277 278 279
	}, {
		.rev = ADRENO_REV(6, 1, 9, ANY_ID),
		.revn = 619,
		.name = "A619",
		.fw = {
			[ADRENO_FW_SQE] = "a630_sqe.fw",
			[ADRENO_FW_GMU] = "a619_gmu.bin",
		},
		.gmem = SZ_512K,
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
		.init = a6xx_gpu_init,
		.zapfw = "a615_zap.mdt",
		.hwcg = a615_hwcg,
J
Jordan Crouse 已提交
280 281 282 283 284 285 286 287 288
	}, {
		.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,
289
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
J
Jordan Crouse 已提交
290
		.init = a6xx_gpu_init,
291
		.zapfw = "a630_zap.mdt",
292
		.hwcg = a630_hwcg,
293 294 295 296 297 298 299 300 301 302 303 304
	}, {
		.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",
305
		.hwcg = a640_hwcg,
306 307 308 309 310 311 312 313 314 315 316 317
	}, {
		.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",
318
		.hwcg = a650_hwcg,
319
		.address_space_size = SZ_16G,
320 321 322 323 324 325 326 327 328 329 330 331 332
	}, {
		.rev = ADRENO_REV(6, 6, 0, ANY_ID),
		.revn = 660,
		.name = "A660",
		.fw = {
			[ADRENO_FW_SQE] = "a660_sqe.fw",
			[ADRENO_FW_GMU] = "a660_gmu.bin",
		},
		.gmem = SZ_1M + SZ_512K,
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
		.init = a6xx_gpu_init,
		.zapfw = "a660_zap.mdt",
		.hwcg = a660_hwcg,
333
		.address_space_size = SZ_16G,
334 335 336 337 338 339 340 341 342 343
	}, {
		.rev = ADRENO_REV(6, 3, 5, ANY_ID),
		.fw = {
			[ADRENO_FW_SQE] = "a660_sqe.fw",
			[ADRENO_FW_GMU] = "a660_gmu.bin",
		},
		.gmem = SZ_512K,
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
		.init = a6xx_gpu_init,
		.hwcg = a660_hwcg,
344
		.address_space_size = SZ_16G,
345 346 347 348 349 350 351 352 353 354 355 356 357
	}, {
		.rev = ADRENO_REV(6, 8, 0, ANY_ID),
		.revn = 680,
		.name = "A680",
		.fw = {
			[ADRENO_FW_SQE] = "a630_sqe.fw",
			[ADRENO_FW_GMU] = "a640_gmu.bin",
		},
		.gmem = SZ_2M,
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
		.init = a6xx_gpu_init,
		.zapfw = "a640_zap.mdt",
		.hwcg = a640_hwcg,
358 359 360
	},
};

361 362 363 364 365 366
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");
367
MODULE_FIRMWARE("qcom/a530_pm4.fw");
368
MODULE_FIRMWARE("qcom/a530_pfp.fw");
369 370 371 372 373
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");
K
Konrad Dybcio 已提交
374
MODULE_FIRMWARE("qcom/a619_gmu.bin");
J
Jordan Crouse 已提交
375 376
MODULE_FIRMWARE("qcom/a630_sqe.fw");
MODULE_FIRMWARE("qcom/a630_gmu.bin");
377
MODULE_FIRMWARE("qcom/a630_zap.mbn");
378 379 380 381 382 383

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

384 385 386 387 388 389 390 391 392
bool adreno_cmp_rev(struct adreno_rev rev1, struct adreno_rev rev2)
{

	return _rev_match(rev1.core, rev2.core) &&
		_rev_match(rev1.major, rev2.major) &&
		_rev_match(rev1.minor, rev2.minor) &&
		_rev_match(rev1.patchid, rev2.patchid);
}

393 394 395 396 397 398 399
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];
400
		if (adreno_cmp_rev(info->rev, rev))
401 402 403 404 405 406 407 408 409 410
			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;
411
	struct msm_gpu *gpu = NULL;
412
	struct adreno_gpu *adreno_gpu;
413
	int ret;
414

415
	if (pdev)
R
Rob Clark 已提交
416
		gpu = dev_to_gpu(&pdev->dev);
417

418
	if (!gpu) {
419
		dev_err_once(dev->dev, "no GPU device was found\n");
420 421 422
		return NULL;
	}

423 424 425 426 427 428 429 430 431 432 433 434
	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;

435 436 437 438 439 440
	/*
	 * Now that we have firmware loaded, and are ready to begin
	 * booting the gpu, go ahead and enable runpm:
	 */
	pm_runtime_enable(&pdev->dev);

441 442 443 444 445
	/* 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) {
446
		pm_runtime_put_sync(&pdev->dev);
447
		DRM_DEV_ERROR(dev->dev, "Couldn't power up the GPU: %d\n", ret);
448 449 450
		return NULL;
	}

R
Rob Clark 已提交
451
	mutex_lock(&gpu->lock);
452
	ret = msm_gpu_hw_init(gpu);
R
Rob Clark 已提交
453
	mutex_unlock(&gpu->lock);
454
	pm_runtime_put_autosuspend(&pdev->dev);
455
	if (ret) {
456
		DRM_DEV_ERROR(dev->dev, "gpu hw init failed: %d\n", ret);
457 458 459
		return NULL;
	}

460
#ifdef CONFIG_DEBUG_FS
R
Rob Clark 已提交
461 462 463 464
	if (gpu->funcs->debugfs_init) {
		gpu->funcs->debugfs_init(gpu, dev->primary);
		gpu->funcs->debugfs_init(gpu, dev->render);
	}
465
#endif
R
Rob Clark 已提交
466

467 468 469
	return gpu;
}

470
static int find_chipid(struct device *dev, struct adreno_rev *rev)
R
Rob Clark 已提交
471 472 473 474
{
	struct device_node *node = dev->of_node;
	const char *compat;
	int ret;
475
	u32 chipid;
R
Rob Clark 已提交
476 477 478 479

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

482 483
		if (sscanf(compat, "qcom,adreno-%u.%u", &r, &patch) == 2 ||
		    sscanf(compat, "amd,imageon-%u.%u", &r, &patch) == 2) {
484 485 486 487 488 489
			rev->core = r / 100;
			r %= 100;
			rev->major = r / 10;
			r %= 10;
			rev->minor = r;
			rev->patchid = patch;
R
Rob Clark 已提交
490 491 492 493 494 495

			return 0;
		}
	}

	/* and if that fails, fall back to legacy "qcom,chipid" property: */
496 497
	ret = of_property_read_u32(node, "qcom,chipid", &chipid);
	if (ret) {
498
		DRM_DEV_ERROR(dev, "could not parse qcom,chipid: %d\n", ret);
R
Rob Clark 已提交
499
		return ret;
500 501 502 503 504 505
	}

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

	dev_warn(dev, "Using legacy qcom,chipid binding!\n");
	dev_warn(dev, "Use compatible qcom,adreno-%u%u%u.%u instead.\n",
509
		rev->core, rev->major, rev->minor, rev->patchid);
R
Rob Clark 已提交
510 511 512 513

	return 0;
}

514 515 516
static int adreno_bind(struct device *dev, struct device *master, void *data)
{
	static struct adreno_platform_config config = {};
517
	const struct adreno_info *info;
518 519
	struct msm_drm_private *priv = dev_get_drvdata(master);
	struct drm_device *drm = priv->dev;
520
	struct msm_gpu *gpu;
R
Rob Clark 已提交
521
	int ret;
522

523 524
	ret = find_chipid(dev, &config.rev);
	if (ret)
525 526 527
		return ret;

	dev->platform_data = &config;
528
	priv->gpu_pdev = to_platform_device(dev);
529 530 531 532 533 534 535 536 537 538 539 540 541

	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 已提交
542
	priv->is_a2xx = config.rev.core == 2;
543
	priv->has_cached_coherent = config.rev.core >= 6;
J
Jonathan Marek 已提交
544

545 546 547 548 549 550
	gpu = info->init(drm);
	if (IS_ERR(gpu)) {
		dev_warn(drm->dev, "failed to load adreno gpu\n");
		return PTR_ERR(gpu);
	}

551 552 553 554 555 556
	return 0;
}

static void adreno_unbind(struct device *dev, struct device *master,
		void *data)
{
557
	struct msm_drm_private *priv = dev_get_drvdata(master);
R
Rob Clark 已提交
558
	struct msm_gpu *gpu = dev_to_gpu(dev);
559

560
	pm_runtime_force_suspend(dev);
561 562
	gpu->funcs->destroy(gpu);

563
	priv->gpu_pdev = NULL;
564 565 566 567 568 569 570
}

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

571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
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);
}

589 590
static int adreno_probe(struct platform_device *pdev)
{
591 592 593 594 595 596 597 598 599 600 601

	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;
602 603 604 605 606 607 608 609
}

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

610 611 612 613 614
static void adreno_shutdown(struct platform_device *pdev)
{
	pm_runtime_force_suspend(&pdev->dev);
}

615
static const struct of_device_id dt_match[] = {
R
Rob Clark 已提交
616
	{ .compatible = "qcom,adreno" },
617
	{ .compatible = "qcom,adreno-3xx" },
618 619
	/* for compatibility with imx5 gpu: */
	{ .compatible = "amd,imageon" },
620 621 622 623 624
	/* for backwards compat w/ downstream kgsl DT files: */
	{ .compatible = "qcom,kgsl-3d0" },
	{}
};

625
static int adreno_runtime_resume(struct device *dev)
R
Rob Clark 已提交
626
{
R
Rob Clark 已提交
627
	struct msm_gpu *gpu = dev_to_gpu(dev);
R
Rob Clark 已提交
628 629 630 631

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

632
static int adreno_runtime_suspend(struct device *dev)
R
Rob Clark 已提交
633
{
R
Rob Clark 已提交
634
	struct msm_gpu *gpu = dev_to_gpu(dev);
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682

	/*
	 * We should be holding a runpm ref, which will prevent
	 * runtime suspend.  In the system suspend path, we've
	 * already waited for active jobs to complete.
	 */
	WARN_ON_ONCE(gpu->active_submits);

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

static void suspend_scheduler(struct msm_gpu *gpu)
{
	int i;

	/*
	 * Shut down the scheduler before we force suspend, so that
	 * suspend isn't racing with scheduler kthread feeding us
	 * more work.
	 *
	 * Note, we just want to park the thread, and let any jobs
	 * that are already on the hw queue complete normally, as
	 * opposed to the drm_sched_stop() path used for handling
	 * faulting/timed-out jobs.  We can't really cancel any jobs
	 * already on the hw queue without racing with the GPU.
	 */
	for (i = 0; i < gpu->nr_rings; i++) {
		struct drm_gpu_scheduler *sched = &gpu->rb[i]->sched;
		kthread_park(sched->thread);
	}
}

static void resume_scheduler(struct msm_gpu *gpu)
{
	int i;

	for (i = 0; i < gpu->nr_rings; i++) {
		struct drm_gpu_scheduler *sched = &gpu->rb[i]->sched;
		kthread_unpark(sched->thread);
	}
}

static int adreno_system_suspend(struct device *dev)
{
	struct msm_gpu *gpu = dev_to_gpu(dev);
	int remaining, ret;

	suspend_scheduler(gpu);
683 684

	remaining = wait_event_timeout(gpu->retire_event,
685
				       gpu->active_submits == 0,
686 687 688
				       msecs_to_jiffies(1000));
	if (remaining == 0) {
		dev_err(dev, "Timeout waiting for GPU to suspend\n");
689 690
		ret = -EBUSY;
		goto out;
691
	}
R
Rob Clark 已提交
692

693 694 695 696 697 698
	ret = pm_runtime_force_suspend(dev);
out:
	if (ret)
		resume_scheduler(gpu);

	return ret;
R
Rob Clark 已提交
699
}
700 701 702 703 704 705 706

static int adreno_system_resume(struct device *dev)
{
	resume_scheduler(dev_to_gpu(dev));
	return pm_runtime_force_resume(dev);
}

R
Rob Clark 已提交
707
static const struct dev_pm_ops adreno_pm_ops = {
708 709
	SYSTEM_SLEEP_PM_OPS(adreno_system_suspend, adreno_system_resume)
	RUNTIME_PM_OPS(adreno_runtime_suspend, adreno_runtime_resume, NULL)
R
Rob Clark 已提交
710 711
};

712 713 714
static struct platform_driver adreno_driver = {
	.probe = adreno_probe,
	.remove = adreno_remove,
715
	.shutdown = adreno_shutdown,
716 717 718
	.driver = {
		.name = "adreno",
		.of_match_table = dt_match,
R
Rob Clark 已提交
719
		.pm = &adreno_pm_ops,
720 721 722 723 724 725 726 727 728 729 730 731
	},
};

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

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