adreno_device.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*
  2. * Copyright (C) 2013-2014 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * Copyright (c) 2014,2017 The Linux Foundation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "adreno_gpu.h"
  20. #define ANY_ID 0xff
  21. bool hang_debug = false;
  22. MODULE_PARM_DESC(hang_debug, "Dump registers when hang is detected (can be slow!)");
  23. module_param_named(hang_debug, hang_debug, bool, 0600);
  24. static const struct adreno_info gpulist[] = {
  25. {
  26. .rev = ADRENO_REV(3, 0, 5, ANY_ID),
  27. .revn = 305,
  28. .name = "A305",
  29. .fw = {
  30. [ADRENO_FW_PM4] = "a300_pm4.fw",
  31. [ADRENO_FW_PFP] = "a300_pfp.fw",
  32. },
  33. .gmem = SZ_256K,
  34. .init = a3xx_gpu_init,
  35. }, {
  36. .rev = ADRENO_REV(3, 0, 6, 0),
  37. .revn = 307, /* because a305c is revn==306 */
  38. .name = "A306",
  39. .fw = {
  40. [ADRENO_FW_PM4] = "a300_pm4.fw",
  41. [ADRENO_FW_PFP] = "a300_pfp.fw",
  42. },
  43. .gmem = SZ_128K,
  44. .init = a3xx_gpu_init,
  45. }, {
  46. .rev = ADRENO_REV(3, 2, ANY_ID, ANY_ID),
  47. .revn = 320,
  48. .name = "A320",
  49. .fw = {
  50. [ADRENO_FW_PM4] = "a300_pm4.fw",
  51. [ADRENO_FW_PFP] = "a300_pfp.fw",
  52. },
  53. .gmem = SZ_512K,
  54. .init = a3xx_gpu_init,
  55. }, {
  56. .rev = ADRENO_REV(3, 3, 0, ANY_ID),
  57. .revn = 330,
  58. .name = "A330",
  59. .fw = {
  60. [ADRENO_FW_PM4] = "a330_pm4.fw",
  61. [ADRENO_FW_PFP] = "a330_pfp.fw",
  62. },
  63. .gmem = SZ_1M,
  64. .init = a3xx_gpu_init,
  65. }, {
  66. .rev = ADRENO_REV(4, 2, 0, ANY_ID),
  67. .revn = 420,
  68. .name = "A420",
  69. .fw = {
  70. [ADRENO_FW_PM4] = "a420_pm4.fw",
  71. [ADRENO_FW_PFP] = "a420_pfp.fw",
  72. },
  73. .gmem = (SZ_1M + SZ_512K),
  74. .init = a4xx_gpu_init,
  75. }, {
  76. .rev = ADRENO_REV(4, 3, 0, ANY_ID),
  77. .revn = 430,
  78. .name = "A430",
  79. .fw = {
  80. [ADRENO_FW_PM4] = "a420_pm4.fw",
  81. [ADRENO_FW_PFP] = "a420_pfp.fw",
  82. },
  83. .gmem = (SZ_1M + SZ_512K),
  84. .init = a4xx_gpu_init,
  85. }, {
  86. .rev = ADRENO_REV(5, 3, 0, 2),
  87. .revn = 530,
  88. .name = "A530",
  89. .fw = {
  90. [ADRENO_FW_PM4] = "a530_pm4.fw",
  91. [ADRENO_FW_PFP] = "a530_pfp.fw",
  92. [ADRENO_FW_GPMU] = "a530v3_gpmu.fw2",
  93. },
  94. .gmem = SZ_1M,
  95. .quirks = ADRENO_QUIRK_TWO_PASS_USE_WFI |
  96. ADRENO_QUIRK_FAULT_DETECT_MASK,
  97. .init = a5xx_gpu_init,
  98. .zapfw = "a530_zap.mdt",
  99. },
  100. };
  101. MODULE_FIRMWARE("qcom/a300_pm4.fw");
  102. MODULE_FIRMWARE("qcom/a300_pfp.fw");
  103. MODULE_FIRMWARE("qcom/a330_pm4.fw");
  104. MODULE_FIRMWARE("qcom/a330_pfp.fw");
  105. MODULE_FIRMWARE("qcom/a420_pm4.fw");
  106. MODULE_FIRMWARE("qcom/a420_pfp.fw");
  107. MODULE_FIRMWARE("qcom/a530_pm4.fw");
  108. MODULE_FIRMWARE("qcom/a530_pfp.fw");
  109. MODULE_FIRMWARE("qcom/a530v3_gpmu.fw2");
  110. MODULE_FIRMWARE("qcom/a530_zap.mdt");
  111. MODULE_FIRMWARE("qcom/a530_zap.b00");
  112. MODULE_FIRMWARE("qcom/a530_zap.b01");
  113. MODULE_FIRMWARE("qcom/a530_zap.b02");
  114. static inline bool _rev_match(uint8_t entry, uint8_t id)
  115. {
  116. return (entry == ANY_ID) || (entry == id);
  117. }
  118. const struct adreno_info *adreno_info(struct adreno_rev rev)
  119. {
  120. int i;
  121. /* identify gpu: */
  122. for (i = 0; i < ARRAY_SIZE(gpulist); i++) {
  123. const struct adreno_info *info = &gpulist[i];
  124. if (_rev_match(info->rev.core, rev.core) &&
  125. _rev_match(info->rev.major, rev.major) &&
  126. _rev_match(info->rev.minor, rev.minor) &&
  127. _rev_match(info->rev.patchid, rev.patchid))
  128. return info;
  129. }
  130. return NULL;
  131. }
  132. struct msm_gpu *adreno_load_gpu(struct drm_device *dev)
  133. {
  134. struct msm_drm_private *priv = dev->dev_private;
  135. struct platform_device *pdev = priv->gpu_pdev;
  136. struct msm_gpu *gpu = NULL;
  137. int ret;
  138. if (pdev)
  139. gpu = platform_get_drvdata(pdev);
  140. if (!gpu) {
  141. dev_err_once(dev->dev, "no GPU device was found\n");
  142. return NULL;
  143. }
  144. pm_runtime_get_sync(&pdev->dev);
  145. mutex_lock(&dev->struct_mutex);
  146. ret = msm_gpu_hw_init(gpu);
  147. mutex_unlock(&dev->struct_mutex);
  148. pm_runtime_put_sync(&pdev->dev);
  149. if (ret) {
  150. dev_err(dev->dev, "gpu hw init failed: %d\n", ret);
  151. return NULL;
  152. }
  153. #ifdef CONFIG_DEBUG_FS
  154. if (gpu->funcs->debugfs_init) {
  155. gpu->funcs->debugfs_init(gpu, dev->primary);
  156. gpu->funcs->debugfs_init(gpu, dev->render);
  157. gpu->funcs->debugfs_init(gpu, dev->control);
  158. }
  159. #endif
  160. return gpu;
  161. }
  162. static void set_gpu_pdev(struct drm_device *dev,
  163. struct platform_device *pdev)
  164. {
  165. struct msm_drm_private *priv = dev->dev_private;
  166. priv->gpu_pdev = pdev;
  167. }
  168. static int find_chipid(struct device *dev, struct adreno_rev *rev)
  169. {
  170. struct device_node *node = dev->of_node;
  171. const char *compat;
  172. int ret;
  173. u32 chipid;
  174. /* first search the compat strings for qcom,adreno-XYZ.W: */
  175. ret = of_property_read_string_index(node, "compatible", 0, &compat);
  176. if (ret == 0) {
  177. unsigned int r, patch;
  178. if (sscanf(compat, "qcom,adreno-%u.%u", &r, &patch) == 2) {
  179. rev->core = r / 100;
  180. r %= 100;
  181. rev->major = r / 10;
  182. r %= 10;
  183. rev->minor = r;
  184. rev->patchid = patch;
  185. return 0;
  186. }
  187. }
  188. /* and if that fails, fall back to legacy "qcom,chipid" property: */
  189. ret = of_property_read_u32(node, "qcom,chipid", &chipid);
  190. if (ret) {
  191. dev_err(dev, "could not parse qcom,chipid: %d\n", ret);
  192. return ret;
  193. }
  194. rev->core = (chipid >> 24) & 0xff;
  195. rev->major = (chipid >> 16) & 0xff;
  196. rev->minor = (chipid >> 8) & 0xff;
  197. rev->patchid = (chipid & 0xff);
  198. dev_warn(dev, "Using legacy qcom,chipid binding!\n");
  199. dev_warn(dev, "Use compatible qcom,adreno-%u%u%u.%u instead.\n",
  200. rev->core, rev->major, rev->minor, rev->patchid);
  201. return 0;
  202. }
  203. static int adreno_bind(struct device *dev, struct device *master, void *data)
  204. {
  205. static struct adreno_platform_config config = {};
  206. const struct adreno_info *info;
  207. struct drm_device *drm = dev_get_drvdata(master);
  208. struct msm_gpu *gpu;
  209. int ret;
  210. ret = find_chipid(dev, &config.rev);
  211. if (ret)
  212. return ret;
  213. dev->platform_data = &config;
  214. set_gpu_pdev(drm, to_platform_device(dev));
  215. info = adreno_info(config.rev);
  216. if (!info) {
  217. dev_warn(drm->dev, "Unknown GPU revision: %u.%u.%u.%u\n",
  218. config.rev.core, config.rev.major,
  219. config.rev.minor, config.rev.patchid);
  220. return -ENXIO;
  221. }
  222. DBG("Found GPU: %u.%u.%u.%u", config.rev.core, config.rev.major,
  223. config.rev.minor, config.rev.patchid);
  224. gpu = info->init(drm);
  225. if (IS_ERR(gpu)) {
  226. dev_warn(drm->dev, "failed to load adreno gpu\n");
  227. return PTR_ERR(gpu);
  228. }
  229. dev_set_drvdata(dev, gpu);
  230. return 0;
  231. }
  232. static void adreno_unbind(struct device *dev, struct device *master,
  233. void *data)
  234. {
  235. struct msm_gpu *gpu = dev_get_drvdata(dev);
  236. gpu->funcs->pm_suspend(gpu);
  237. gpu->funcs->destroy(gpu);
  238. set_gpu_pdev(dev_get_drvdata(master), NULL);
  239. }
  240. static const struct component_ops a3xx_ops = {
  241. .bind = adreno_bind,
  242. .unbind = adreno_unbind,
  243. };
  244. static int adreno_probe(struct platform_device *pdev)
  245. {
  246. return component_add(&pdev->dev, &a3xx_ops);
  247. }
  248. static int adreno_remove(struct platform_device *pdev)
  249. {
  250. component_del(&pdev->dev, &a3xx_ops);
  251. return 0;
  252. }
  253. static const struct of_device_id dt_match[] = {
  254. { .compatible = "qcom,adreno" },
  255. { .compatible = "qcom,adreno-3xx" },
  256. /* for backwards compat w/ downstream kgsl DT files: */
  257. { .compatible = "qcom,kgsl-3d0" },
  258. {}
  259. };
  260. #ifdef CONFIG_PM
  261. static int adreno_resume(struct device *dev)
  262. {
  263. struct platform_device *pdev = to_platform_device(dev);
  264. struct msm_gpu *gpu = platform_get_drvdata(pdev);
  265. return gpu->funcs->pm_resume(gpu);
  266. }
  267. static int adreno_suspend(struct device *dev)
  268. {
  269. struct platform_device *pdev = to_platform_device(dev);
  270. struct msm_gpu *gpu = platform_get_drvdata(pdev);
  271. return gpu->funcs->pm_suspend(gpu);
  272. }
  273. #endif
  274. static const struct dev_pm_ops adreno_pm_ops = {
  275. SET_RUNTIME_PM_OPS(adreno_suspend, adreno_resume, NULL)
  276. };
  277. static struct platform_driver adreno_driver = {
  278. .probe = adreno_probe,
  279. .remove = adreno_remove,
  280. .driver = {
  281. .name = "adreno",
  282. .of_match_table = dt_match,
  283. .pm = &adreno_pm_ops,
  284. },
  285. };
  286. void __init adreno_register(void)
  287. {
  288. platform_driver_register(&adreno_driver);
  289. }
  290. void __exit adreno_unregister(void)
  291. {
  292. platform_driver_unregister(&adreno_driver);
  293. }