adreno_device.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 <linux/pm_opp.h>
  20. #include "adreno_gpu.h"
  21. #define ANY_ID 0xff
  22. bool hang_debug = false;
  23. MODULE_PARM_DESC(hang_debug, "Dump registers when hang is detected (can be slow!)");
  24. module_param_named(hang_debug, hang_debug, bool, 0600);
  25. static const struct adreno_info gpulist[] = {
  26. {
  27. .rev = ADRENO_REV(3, 0, 5, ANY_ID),
  28. .revn = 305,
  29. .name = "A305",
  30. .pm4fw = "a300_pm4.fw",
  31. .pfpfw = "a300_pfp.fw",
  32. .gmem = SZ_256K,
  33. .init = a3xx_gpu_init,
  34. }, {
  35. .rev = ADRENO_REV(3, 0, 6, 0),
  36. .revn = 307, /* because a305c is revn==306 */
  37. .name = "A306",
  38. .pm4fw = "a300_pm4.fw",
  39. .pfpfw = "a300_pfp.fw",
  40. .gmem = SZ_128K,
  41. .init = a3xx_gpu_init,
  42. }, {
  43. .rev = ADRENO_REV(3, 2, ANY_ID, ANY_ID),
  44. .revn = 320,
  45. .name = "A320",
  46. .pm4fw = "a300_pm4.fw",
  47. .pfpfw = "a300_pfp.fw",
  48. .gmem = SZ_512K,
  49. .init = a3xx_gpu_init,
  50. }, {
  51. .rev = ADRENO_REV(3, 3, 0, ANY_ID),
  52. .revn = 330,
  53. .name = "A330",
  54. .pm4fw = "a330_pm4.fw",
  55. .pfpfw = "a330_pfp.fw",
  56. .gmem = SZ_1M,
  57. .init = a3xx_gpu_init,
  58. }, {
  59. .rev = ADRENO_REV(4, 2, 0, ANY_ID),
  60. .revn = 420,
  61. .name = "A420",
  62. .pm4fw = "a420_pm4.fw",
  63. .pfpfw = "a420_pfp.fw",
  64. .gmem = (SZ_1M + SZ_512K),
  65. .init = a4xx_gpu_init,
  66. }, {
  67. .rev = ADRENO_REV(4, 3, 0, ANY_ID),
  68. .revn = 430,
  69. .name = "A430",
  70. .pm4fw = "a420_pm4.fw",
  71. .pfpfw = "a420_pfp.fw",
  72. .gmem = (SZ_1M + SZ_512K),
  73. .init = a4xx_gpu_init,
  74. }, {
  75. .rev = ADRENO_REV(5, 3, 0, 2),
  76. .revn = 530,
  77. .name = "A530",
  78. .pm4fw = "a530_pm4.fw",
  79. .pfpfw = "a530_pfp.fw",
  80. .gmem = SZ_1M,
  81. .quirks = ADRENO_QUIRK_TWO_PASS_USE_WFI |
  82. ADRENO_QUIRK_FAULT_DETECT_MASK,
  83. .init = a5xx_gpu_init,
  84. .gpmufw = "a530v3_gpmu.fw2",
  85. },
  86. };
  87. MODULE_FIRMWARE("a300_pm4.fw");
  88. MODULE_FIRMWARE("a300_pfp.fw");
  89. MODULE_FIRMWARE("a330_pm4.fw");
  90. MODULE_FIRMWARE("a330_pfp.fw");
  91. MODULE_FIRMWARE("a420_pm4.fw");
  92. MODULE_FIRMWARE("a420_pfp.fw");
  93. MODULE_FIRMWARE("a530_fm4.fw");
  94. MODULE_FIRMWARE("a530_pfp.fw");
  95. static inline bool _rev_match(uint8_t entry, uint8_t id)
  96. {
  97. return (entry == ANY_ID) || (entry == id);
  98. }
  99. const struct adreno_info *adreno_info(struct adreno_rev rev)
  100. {
  101. int i;
  102. /* identify gpu: */
  103. for (i = 0; i < ARRAY_SIZE(gpulist); i++) {
  104. const struct adreno_info *info = &gpulist[i];
  105. if (_rev_match(info->rev.core, rev.core) &&
  106. _rev_match(info->rev.major, rev.major) &&
  107. _rev_match(info->rev.minor, rev.minor) &&
  108. _rev_match(info->rev.patchid, rev.patchid))
  109. return info;
  110. }
  111. return NULL;
  112. }
  113. struct msm_gpu *adreno_load_gpu(struct drm_device *dev)
  114. {
  115. struct msm_drm_private *priv = dev->dev_private;
  116. struct platform_device *pdev = priv->gpu_pdev;
  117. struct adreno_platform_config *config;
  118. struct adreno_rev rev;
  119. const struct adreno_info *info;
  120. struct msm_gpu *gpu = NULL;
  121. if (!pdev) {
  122. dev_err(dev->dev, "no adreno device\n");
  123. return NULL;
  124. }
  125. config = pdev->dev.platform_data;
  126. rev = config->rev;
  127. info = adreno_info(config->rev);
  128. if (!info) {
  129. dev_warn(dev->dev, "Unknown GPU revision: %u.%u.%u.%u\n",
  130. rev.core, rev.major, rev.minor, rev.patchid);
  131. return NULL;
  132. }
  133. DBG("Found GPU: %u.%u.%u.%u", rev.core, rev.major,
  134. rev.minor, rev.patchid);
  135. gpu = info->init(dev);
  136. if (IS_ERR(gpu)) {
  137. dev_warn(dev->dev, "failed to load adreno gpu\n");
  138. gpu = NULL;
  139. /* not fatal */
  140. }
  141. if (gpu) {
  142. int ret;
  143. pm_runtime_get_sync(&pdev->dev);
  144. ret = msm_gpu_hw_init(gpu);
  145. pm_runtime_put_sync(&pdev->dev);
  146. if (ret) {
  147. dev_err(dev->dev, "gpu hw init failed: %d\n", ret);
  148. gpu->funcs->destroy(gpu);
  149. gpu = NULL;
  150. }
  151. }
  152. return gpu;
  153. }
  154. static void set_gpu_pdev(struct drm_device *dev,
  155. struct platform_device *pdev)
  156. {
  157. struct msm_drm_private *priv = dev->dev_private;
  158. priv->gpu_pdev = pdev;
  159. }
  160. static int find_chipid(struct device *dev, u32 *chipid)
  161. {
  162. struct device_node *node = dev->of_node;
  163. const char *compat;
  164. int ret;
  165. /* first search the compat strings for qcom,adreno-XYZ.W: */
  166. ret = of_property_read_string_index(node, "compatible", 0, &compat);
  167. if (ret == 0) {
  168. unsigned rev, patch;
  169. if (sscanf(compat, "qcom,adreno-%u.%u", &rev, &patch) == 2) {
  170. *chipid = 0;
  171. *chipid |= (rev / 100) << 24; /* core */
  172. rev %= 100;
  173. *chipid |= (rev / 10) << 16; /* major */
  174. rev %= 10;
  175. *chipid |= rev << 8; /* minor */
  176. *chipid |= patch;
  177. return 0;
  178. }
  179. }
  180. /* and if that fails, fall back to legacy "qcom,chipid" property: */
  181. ret = of_property_read_u32(node, "qcom,chipid", chipid);
  182. if (ret)
  183. return ret;
  184. dev_warn(dev, "Using legacy qcom,chipid binding!\n");
  185. dev_warn(dev, "Use compatible qcom,adreno-%u%u%u.%u instead.\n",
  186. (*chipid >> 24) & 0xff, (*chipid >> 16) & 0xff,
  187. (*chipid >> 8) & 0xff, *chipid & 0xff);
  188. return 0;
  189. }
  190. /* Get legacy powerlevels from qcom,gpu-pwrlevels and populate the opp table */
  191. static int adreno_get_legacy_pwrlevels(struct device *dev)
  192. {
  193. struct device_node *child, *node;
  194. int ret;
  195. node = of_find_compatible_node(dev->of_node, NULL,
  196. "qcom,gpu-pwrlevels");
  197. if (!node) {
  198. dev_err(dev, "Could not find the GPU powerlevels\n");
  199. return -ENXIO;
  200. }
  201. for_each_child_of_node(node, child) {
  202. unsigned int val;
  203. ret = of_property_read_u32(child, "qcom,gpu-freq", &val);
  204. if (ret)
  205. continue;
  206. /*
  207. * Skip the intentionally bogus clock value found at the bottom
  208. * of most legacy frequency tables
  209. */
  210. if (val != 27000000)
  211. dev_pm_opp_add(dev, val, 0);
  212. }
  213. return 0;
  214. }
  215. static int adreno_get_pwrlevels(struct device *dev,
  216. struct adreno_platform_config *config)
  217. {
  218. unsigned long freq = ULONG_MAX;
  219. struct dev_pm_opp *opp;
  220. int ret;
  221. /* You down with OPP? */
  222. if (!of_find_property(dev->of_node, "operating-points-v2", NULL))
  223. ret = adreno_get_legacy_pwrlevels(dev);
  224. else
  225. ret = dev_pm_opp_of_add_table(dev);
  226. if (ret)
  227. return ret;
  228. /* Find the fastest defined rate */
  229. opp = dev_pm_opp_find_freq_floor(dev, &freq);
  230. if (!IS_ERR(opp))
  231. config->fast_rate = dev_pm_opp_get_freq(opp);
  232. if (!config->fast_rate) {
  233. DRM_DEV_INFO(dev,
  234. "Could not find clock rate. Using default\n");
  235. /* Pick a suitably safe clock speed for any target */
  236. config->fast_rate = 200000000;
  237. }
  238. return 0;
  239. }
  240. static int adreno_bind(struct device *dev, struct device *master, void *data)
  241. {
  242. static struct adreno_platform_config config = {};
  243. u32 val;
  244. int ret;
  245. ret = find_chipid(dev, &val);
  246. if (ret) {
  247. dev_err(dev, "could not find chipid: %d\n", ret);
  248. return ret;
  249. }
  250. config.rev = ADRENO_REV((val >> 24) & 0xff,
  251. (val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff);
  252. /* find clock rates: */
  253. config.fast_rate = 0;
  254. ret = adreno_get_pwrlevels(dev, &config);
  255. if (ret)
  256. return ret;
  257. dev->platform_data = &config;
  258. set_gpu_pdev(dev_get_drvdata(master), to_platform_device(dev));
  259. return 0;
  260. }
  261. static void adreno_unbind(struct device *dev, struct device *master,
  262. void *data)
  263. {
  264. set_gpu_pdev(dev_get_drvdata(master), NULL);
  265. }
  266. static const struct component_ops a3xx_ops = {
  267. .bind = adreno_bind,
  268. .unbind = adreno_unbind,
  269. };
  270. static int adreno_probe(struct platform_device *pdev)
  271. {
  272. return component_add(&pdev->dev, &a3xx_ops);
  273. }
  274. static int adreno_remove(struct platform_device *pdev)
  275. {
  276. component_del(&pdev->dev, &a3xx_ops);
  277. return 0;
  278. }
  279. static const struct of_device_id dt_match[] = {
  280. { .compatible = "qcom,adreno" },
  281. { .compatible = "qcom,adreno-3xx" },
  282. /* for backwards compat w/ downstream kgsl DT files: */
  283. { .compatible = "qcom,kgsl-3d0" },
  284. {}
  285. };
  286. #ifdef CONFIG_PM
  287. static int adreno_resume(struct device *dev)
  288. {
  289. struct platform_device *pdev = to_platform_device(dev);
  290. struct msm_gpu *gpu = platform_get_drvdata(pdev);
  291. return gpu->funcs->pm_resume(gpu);
  292. }
  293. static int adreno_suspend(struct device *dev)
  294. {
  295. struct platform_device *pdev = to_platform_device(dev);
  296. struct msm_gpu *gpu = platform_get_drvdata(pdev);
  297. return gpu->funcs->pm_suspend(gpu);
  298. }
  299. #endif
  300. static const struct dev_pm_ops adreno_pm_ops = {
  301. SET_RUNTIME_PM_OPS(adreno_suspend, adreno_resume, NULL)
  302. };
  303. static struct platform_driver adreno_driver = {
  304. .probe = adreno_probe,
  305. .remove = adreno_remove,
  306. .driver = {
  307. .name = "adreno",
  308. .of_match_table = dt_match,
  309. .pm = &adreno_pm_ops,
  310. },
  311. };
  312. void __init adreno_register(void)
  313. {
  314. platform_driver_register(&adreno_driver);
  315. }
  316. void __exit adreno_unregister(void)
  317. {
  318. platform_driver_unregister(&adreno_driver);
  319. }