adreno_device.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * Copyright (C) 2013-2014 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * Copyright (c) 2014 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. .pm4fw = "a300_pm4.fw",
  30. .pfpfw = "a300_pfp.fw",
  31. .gmem = SZ_256K,
  32. .init = a3xx_gpu_init,
  33. }, {
  34. .rev = ADRENO_REV(3, 0, 6, 0),
  35. .revn = 307, /* because a305c is revn==306 */
  36. .name = "A306",
  37. .pm4fw = "a300_pm4.fw",
  38. .pfpfw = "a300_pfp.fw",
  39. .gmem = SZ_128K,
  40. .init = a3xx_gpu_init,
  41. }, {
  42. .rev = ADRENO_REV(3, 2, ANY_ID, ANY_ID),
  43. .revn = 320,
  44. .name = "A320",
  45. .pm4fw = "a300_pm4.fw",
  46. .pfpfw = "a300_pfp.fw",
  47. .gmem = SZ_512K,
  48. .init = a3xx_gpu_init,
  49. }, {
  50. .rev = ADRENO_REV(3, 3, 0, ANY_ID),
  51. .revn = 330,
  52. .name = "A330",
  53. .pm4fw = "a330_pm4.fw",
  54. .pfpfw = "a330_pfp.fw",
  55. .gmem = SZ_1M,
  56. .init = a3xx_gpu_init,
  57. }, {
  58. .rev = ADRENO_REV(4, 2, 0, ANY_ID),
  59. .revn = 420,
  60. .name = "A420",
  61. .pm4fw = "a420_pm4.fw",
  62. .pfpfw = "a420_pfp.fw",
  63. .gmem = (SZ_1M + SZ_512K),
  64. .init = a4xx_gpu_init,
  65. }, {
  66. .rev = ADRENO_REV(4, 3, 0, ANY_ID),
  67. .revn = 430,
  68. .name = "A430",
  69. .pm4fw = "a420_pm4.fw",
  70. .pfpfw = "a420_pfp.fw",
  71. .gmem = (SZ_1M + SZ_512K),
  72. .init = a4xx_gpu_init,
  73. }, {
  74. .rev = ADRENO_REV(5, 3, 0, ANY_ID),
  75. .revn = 530,
  76. .name = "A530",
  77. .pm4fw = "a530_pm4.fw",
  78. .pfpfw = "a530_pfp.fw",
  79. .gmem = SZ_1M,
  80. .init = a5xx_gpu_init,
  81. .gpmufw = "a530v3_gpmu.fw2",
  82. },
  83. };
  84. MODULE_FIRMWARE("a300_pm4.fw");
  85. MODULE_FIRMWARE("a300_pfp.fw");
  86. MODULE_FIRMWARE("a330_pm4.fw");
  87. MODULE_FIRMWARE("a330_pfp.fw");
  88. MODULE_FIRMWARE("a420_pm4.fw");
  89. MODULE_FIRMWARE("a420_pfp.fw");
  90. MODULE_FIRMWARE("a530_fm4.fw");
  91. MODULE_FIRMWARE("a530_pfp.fw");
  92. static inline bool _rev_match(uint8_t entry, uint8_t id)
  93. {
  94. return (entry == ANY_ID) || (entry == id);
  95. }
  96. const struct adreno_info *adreno_info(struct adreno_rev rev)
  97. {
  98. int i;
  99. /* identify gpu: */
  100. for (i = 0; i < ARRAY_SIZE(gpulist); i++) {
  101. const struct adreno_info *info = &gpulist[i];
  102. if (_rev_match(info->rev.core, rev.core) &&
  103. _rev_match(info->rev.major, rev.major) &&
  104. _rev_match(info->rev.minor, rev.minor) &&
  105. _rev_match(info->rev.patchid, rev.patchid))
  106. return info;
  107. }
  108. return NULL;
  109. }
  110. struct msm_gpu *adreno_load_gpu(struct drm_device *dev)
  111. {
  112. struct msm_drm_private *priv = dev->dev_private;
  113. struct platform_device *pdev = priv->gpu_pdev;
  114. struct adreno_platform_config *config;
  115. struct adreno_rev rev;
  116. const struct adreno_info *info;
  117. struct msm_gpu *gpu = NULL;
  118. if (!pdev) {
  119. dev_err(dev->dev, "no adreno device\n");
  120. return NULL;
  121. }
  122. config = pdev->dev.platform_data;
  123. rev = config->rev;
  124. info = adreno_info(config->rev);
  125. if (!info) {
  126. dev_warn(dev->dev, "Unknown GPU revision: %u.%u.%u.%u\n",
  127. rev.core, rev.major, rev.minor, rev.patchid);
  128. return NULL;
  129. }
  130. DBG("Found GPU: %u.%u.%u.%u", rev.core, rev.major,
  131. rev.minor, rev.patchid);
  132. gpu = info->init(dev);
  133. if (IS_ERR(gpu)) {
  134. dev_warn(dev->dev, "failed to load adreno gpu\n");
  135. gpu = NULL;
  136. /* not fatal */
  137. }
  138. if (gpu) {
  139. int ret;
  140. mutex_lock(&dev->struct_mutex);
  141. gpu->funcs->pm_resume(gpu);
  142. mutex_unlock(&dev->struct_mutex);
  143. disable_irq(gpu->irq);
  144. ret = gpu->funcs->hw_init(gpu);
  145. if (ret) {
  146. dev_err(dev->dev, "gpu hw init failed: %d\n", ret);
  147. gpu->funcs->destroy(gpu);
  148. gpu = NULL;
  149. } else {
  150. enable_irq(gpu->irq);
  151. /* give inactive pm a chance to kick in: */
  152. msm_gpu_retire(gpu);
  153. }
  154. }
  155. return gpu;
  156. }
  157. static void set_gpu_pdev(struct drm_device *dev,
  158. struct platform_device *pdev)
  159. {
  160. struct msm_drm_private *priv = dev->dev_private;
  161. priv->gpu_pdev = pdev;
  162. }
  163. static const struct {
  164. const char *str;
  165. uint32_t flag;
  166. } quirks[] = {
  167. { "qcom,gpu-quirk-two-pass-use-wfi", ADRENO_QUIRK_TWO_PASS_USE_WFI },
  168. { "qcom,gpu-quirk-fault-detect-mask", ADRENO_QUIRK_FAULT_DETECT_MASK },
  169. };
  170. static int adreno_bind(struct device *dev, struct device *master, void *data)
  171. {
  172. static struct adreno_platform_config config = {};
  173. struct device_node *child, *node = dev->of_node;
  174. u32 val;
  175. int ret, i;
  176. ret = of_property_read_u32(node, "qcom,chipid", &val);
  177. if (ret) {
  178. dev_err(dev, "could not find chipid: %d\n", ret);
  179. return ret;
  180. }
  181. config.rev = ADRENO_REV((val >> 24) & 0xff,
  182. (val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff);
  183. /* find clock rates: */
  184. config.fast_rate = 0;
  185. config.slow_rate = ~0;
  186. for_each_child_of_node(node, child) {
  187. if (of_device_is_compatible(child, "qcom,gpu-pwrlevels")) {
  188. struct device_node *pwrlvl;
  189. for_each_child_of_node(child, pwrlvl) {
  190. ret = of_property_read_u32(pwrlvl, "qcom,gpu-freq", &val);
  191. if (ret) {
  192. dev_err(dev, "could not find gpu-freq: %d\n", ret);
  193. return ret;
  194. }
  195. config.fast_rate = max(config.fast_rate, val);
  196. config.slow_rate = min(config.slow_rate, val);
  197. }
  198. }
  199. }
  200. if (!config.fast_rate) {
  201. dev_err(dev, "could not find clk rates\n");
  202. return -ENXIO;
  203. }
  204. for (i = 0; i < ARRAY_SIZE(quirks); i++)
  205. if (of_property_read_bool(node, quirks[i].str))
  206. config.quirks |= quirks[i].flag;
  207. dev->platform_data = &config;
  208. set_gpu_pdev(dev_get_drvdata(master), to_platform_device(dev));
  209. return 0;
  210. }
  211. static void adreno_unbind(struct device *dev, struct device *master,
  212. void *data)
  213. {
  214. set_gpu_pdev(dev_get_drvdata(master), NULL);
  215. }
  216. static const struct component_ops a3xx_ops = {
  217. .bind = adreno_bind,
  218. .unbind = adreno_unbind,
  219. };
  220. static int adreno_probe(struct platform_device *pdev)
  221. {
  222. return component_add(&pdev->dev, &a3xx_ops);
  223. }
  224. static int adreno_remove(struct platform_device *pdev)
  225. {
  226. component_del(&pdev->dev, &a3xx_ops);
  227. return 0;
  228. }
  229. static const struct of_device_id dt_match[] = {
  230. { .compatible = "qcom,adreno-3xx" },
  231. /* for backwards compat w/ downstream kgsl DT files: */
  232. { .compatible = "qcom,kgsl-3d0" },
  233. {}
  234. };
  235. static struct platform_driver adreno_driver = {
  236. .probe = adreno_probe,
  237. .remove = adreno_remove,
  238. .driver = {
  239. .name = "adreno",
  240. .of_match_table = dt_match,
  241. },
  242. };
  243. void __init adreno_register(void)
  244. {
  245. platform_driver_register(&adreno_driver);
  246. }
  247. void __exit adreno_unregister(void)
  248. {
  249. platform_driver_unregister(&adreno_driver);
  250. }