adreno_device.c 9.3 KB
Newer Older
1 2 3 4
/*
 * Copyright (C) 2013-2014 Red Hat
 * Author: Rob Clark <robdclark@gmail.com>
 *
5
 * Copyright (c) 2014,2017 The Linux Foundation. All rights reserved.
6
 *
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "adreno_gpu.h"

22 23
#define ANY_ID 0xff

24 25 26 27
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);

28 29 30 31 32
static const struct adreno_info gpulist[] = {
	{
		.rev   = ADRENO_REV(3, 0, 5, ANY_ID),
		.revn  = 305,
		.name  = "A305",
33 34 35 36
		.fw = {
			[ADRENO_FW_PM4] = "a300_pm4.fw",
			[ADRENO_FW_PFP] = "a300_pfp.fw",
		},
37
		.gmem  = SZ_256K,
38
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
39
		.init  = a3xx_gpu_init,
R
Rob Clark 已提交
40 41 42 43
	}, {
		.rev   = ADRENO_REV(3, 0, 6, 0),
		.revn  = 307,        /* because a305c is revn==306 */
		.name  = "A306",
44 45 46 47
		.fw = {
			[ADRENO_FW_PM4] = "a300_pm4.fw",
			[ADRENO_FW_PFP] = "a300_pfp.fw",
		},
R
Rob Clark 已提交
48
		.gmem  = SZ_128K,
49
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
R
Rob Clark 已提交
50
		.init  = a3xx_gpu_init,
51 52 53 54
	}, {
		.rev   = ADRENO_REV(3, 2, ANY_ID, ANY_ID),
		.revn  = 320,
		.name  = "A320",
55 56 57 58
		.fw = {
			[ADRENO_FW_PM4] = "a300_pm4.fw",
			[ADRENO_FW_PFP] = "a300_pfp.fw",
		},
59
		.gmem  = SZ_512K,
60
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
61 62 63 64 65
		.init  = a3xx_gpu_init,
	}, {
		.rev   = ADRENO_REV(3, 3, 0, ANY_ID),
		.revn  = 330,
		.name  = "A330",
66 67 68 69
		.fw = {
			[ADRENO_FW_PM4] = "a330_pm4.fw",
			[ADRENO_FW_PFP] = "a330_pfp.fw",
		},
70
		.gmem  = SZ_1M,
71
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
72
		.init  = a3xx_gpu_init,
73 74 75 76
	}, {
		.rev   = ADRENO_REV(4, 2, 0, ANY_ID),
		.revn  = 420,
		.name  = "A420",
77 78 79 80
		.fw = {
			[ADRENO_FW_PM4] = "a420_pm4.fw",
			[ADRENO_FW_PFP] = "a420_pfp.fw",
		},
81
		.gmem  = (SZ_1M + SZ_512K),
82
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
83
		.init  = a4xx_gpu_init,
84 85 86 87
	}, {
		.rev   = ADRENO_REV(4, 3, 0, ANY_ID),
		.revn  = 430,
		.name  = "A430",
88 89 90 91
		.fw = {
			[ADRENO_FW_PM4] = "a420_pm4.fw",
			[ADRENO_FW_PFP] = "a420_pfp.fw",
		},
92
		.gmem  = (SZ_1M + SZ_512K),
93
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
94
		.init  = a4xx_gpu_init,
95
	}, {
R
Rob Clark 已提交
96
		.rev = ADRENO_REV(5, 3, 0, 2),
97 98
		.revn = 530,
		.name = "A530",
99 100 101 102 103
		.fw = {
			[ADRENO_FW_PM4] = "a530_pm4.fw",
			[ADRENO_FW_PFP] = "a530_pfp.fw",
			[ADRENO_FW_GPMU] = "a530v3_gpmu.fw2",
		},
104
		.gmem = SZ_1M,
105 106 107 108 109
		/*
		 * Increase inactive period to 250 to avoid bouncing
		 * the GDSC which appears to make it grumpy
		 */
		.inactive_period = 250,
R
Rob Clark 已提交
110 111
		.quirks = ADRENO_QUIRK_TWO_PASS_USE_WFI |
			ADRENO_QUIRK_FAULT_DETECT_MASK,
112
		.init = a5xx_gpu_init,
113
		.zapfw = "a530_zap.mdt",
J
Jordan Crouse 已提交
114 115 116 117 118 119 120 121 122
	}, {
		.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,
123
		.inactive_period = DRM_MSM_INACTIVE_PERIOD,
J
Jordan Crouse 已提交
124
		.init = a6xx_gpu_init,
125 126 127
	},
};

128 129 130 131 132 133
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");
134
MODULE_FIRMWARE("qcom/a530_pm4.fw");
135
MODULE_FIRMWARE("qcom/a530_pfp.fw");
136 137 138 139 140
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 已提交
141 142
MODULE_FIRMWARE("qcom/a630_sqe.fw");
MODULE_FIRMWARE("qcom/a630_gmu.bin");
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

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;
170
	struct msm_gpu *gpu = NULL;
171
	struct adreno_gpu *adreno_gpu;
172
	int ret;
173

174 175 176
	if (pdev)
		gpu = platform_get_drvdata(pdev);

177
	if (!gpu) {
178
		dev_err_once(dev->dev, "no GPU device was found\n");
179 180 181
		return NULL;
	}

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
	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) {
199
		DRM_DEV_ERROR(dev->dev, "Couldn't power up the GPU: %d\n", ret);
200 201 202
		return NULL;
	}

203 204 205
	mutex_lock(&dev->struct_mutex);
	ret = msm_gpu_hw_init(gpu);
	mutex_unlock(&dev->struct_mutex);
206
	pm_runtime_put_autosuspend(&pdev->dev);
207
	if (ret) {
208
		DRM_DEV_ERROR(dev->dev, "gpu hw init failed: %d\n", ret);
209 210 211
		return NULL;
	}

212
#ifdef CONFIG_DEBUG_FS
R
Rob Clark 已提交
213 214 215 216
	if (gpu->funcs->debugfs_init) {
		gpu->funcs->debugfs_init(gpu, dev->primary);
		gpu->funcs->debugfs_init(gpu, dev->render);
	}
217
#endif
R
Rob Clark 已提交
218

219 220 221
	return gpu;
}

222 223 224 225 226 227 228
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;
}

229
static int find_chipid(struct device *dev, struct adreno_rev *rev)
R
Rob Clark 已提交
230 231 232 233
{
	struct device_node *node = dev->of_node;
	const char *compat;
	int ret;
234
	u32 chipid;
R
Rob Clark 已提交
235 236 237 238

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

241 242 243 244 245 246 247
		if (sscanf(compat, "qcom,adreno-%u.%u", &r, &patch) == 2) {
			rev->core = r / 100;
			r %= 100;
			rev->major = r / 10;
			r %= 10;
			rev->minor = r;
			rev->patchid = patch;
R
Rob Clark 已提交
248 249 250 251 252 253

			return 0;
		}
	}

	/* and if that fails, fall back to legacy "qcom,chipid" property: */
254 255
	ret = of_property_read_u32(node, "qcom,chipid", &chipid);
	if (ret) {
256
		DRM_DEV_ERROR(dev, "could not parse qcom,chipid: %d\n", ret);
R
Rob Clark 已提交
257
		return ret;
258 259 260 261 262 263
	}

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

	dev_warn(dev, "Using legacy qcom,chipid binding!\n");
	dev_warn(dev, "Use compatible qcom,adreno-%u%u%u.%u instead.\n",
267
		rev->core, rev->major, rev->minor, rev->patchid);
R
Rob Clark 已提交
268 269 270 271

	return 0;
}

272 273 274
static int adreno_bind(struct device *dev, struct device *master, void *data)
{
	static struct adreno_platform_config config = {};
275 276 277
	const struct adreno_info *info;
	struct drm_device *drm = dev_get_drvdata(master);
	struct msm_gpu *gpu;
R
Rob Clark 已提交
278
	int ret;
279

280 281
	ret = find_chipid(dev, &config.rev);
	if (ret)
282 283 284
		return ret;

	dev->platform_data = &config;
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
	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);

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

	dev_set_drvdata(dev, gpu);

307 308 309 310 311 312
	return 0;
}

static void adreno_unbind(struct device *dev, struct device *master,
		void *data)
{
313 314 315 316 317
	struct msm_gpu *gpu = dev_get_drvdata(dev);

	gpu->funcs->pm_suspend(gpu);
	gpu->funcs->destroy(gpu);

318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
	set_gpu_pdev(dev_get_drvdata(master), NULL);
}

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

static int adreno_probe(struct platform_device *pdev)
{
	return component_add(&pdev->dev, &a3xx_ops);
}

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

static const struct of_device_id dt_match[] = {
R
Rob Clark 已提交
338
	{ .compatible = "qcom,adreno" },
339 340 341 342 343 344
	{ .compatible = "qcom,adreno-3xx" },
	/* for backwards compat w/ downstream kgsl DT files: */
	{ .compatible = "qcom,kgsl-3d0" },
	{}
};

R
Rob Clark 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
#ifdef CONFIG_PM
static int adreno_resume(struct device *dev)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct msm_gpu *gpu = platform_get_drvdata(pdev);

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

static int adreno_suspend(struct device *dev)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct msm_gpu *gpu = platform_get_drvdata(pdev);

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

static const struct dev_pm_ops adreno_pm_ops = {
364
	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
R
Rob Clark 已提交
365 366 367
	SET_RUNTIME_PM_OPS(adreno_suspend, adreno_resume, NULL)
};

368 369 370 371 372 373
static struct platform_driver adreno_driver = {
	.probe = adreno_probe,
	.remove = adreno_remove,
	.driver = {
		.name = "adreno",
		.of_match_table = dt_match,
R
Rob Clark 已提交
374
		.pm = &adreno_pm_ops,
375 376 377 378 379 380 381 382 383 384 385 386
	},
};

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

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