adreno_device.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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, 2),
  75. .revn = 530,
  76. .name = "A530",
  77. .pm4fw = "a530_pm4.fw",
  78. .pfpfw = "a530_pfp.fw",
  79. .gmem = SZ_1M,
  80. .quirks = ADRENO_QUIRK_TWO_PASS_USE_WFI |
  81. ADRENO_QUIRK_FAULT_DETECT_MASK,
  82. .init = a5xx_gpu_init,
  83. .gpmufw = "a530v3_gpmu.fw2",
  84. },
  85. };
  86. MODULE_FIRMWARE("a300_pm4.fw");
  87. MODULE_FIRMWARE("a300_pfp.fw");
  88. MODULE_FIRMWARE("a330_pm4.fw");
  89. MODULE_FIRMWARE("a330_pfp.fw");
  90. MODULE_FIRMWARE("a420_pm4.fw");
  91. MODULE_FIRMWARE("a420_pfp.fw");
  92. MODULE_FIRMWARE("a530_fm4.fw");
  93. MODULE_FIRMWARE("a530_pfp.fw");
  94. static inline bool _rev_match(uint8_t entry, uint8_t id)
  95. {
  96. return (entry == ANY_ID) || (entry == id);
  97. }
  98. const struct adreno_info *adreno_info(struct adreno_rev rev)
  99. {
  100. int i;
  101. /* identify gpu: */
  102. for (i = 0; i < ARRAY_SIZE(gpulist); i++) {
  103. const struct adreno_info *info = &gpulist[i];
  104. if (_rev_match(info->rev.core, rev.core) &&
  105. _rev_match(info->rev.major, rev.major) &&
  106. _rev_match(info->rev.minor, rev.minor) &&
  107. _rev_match(info->rev.patchid, rev.patchid))
  108. return info;
  109. }
  110. return NULL;
  111. }
  112. struct msm_gpu *adreno_load_gpu(struct drm_device *dev)
  113. {
  114. struct msm_drm_private *priv = dev->dev_private;
  115. struct platform_device *pdev = priv->gpu_pdev;
  116. struct adreno_platform_config *config;
  117. struct adreno_rev rev;
  118. const struct adreno_info *info;
  119. struct msm_gpu *gpu = NULL;
  120. if (!pdev) {
  121. dev_err(dev->dev, "no adreno device\n");
  122. return NULL;
  123. }
  124. config = pdev->dev.platform_data;
  125. rev = config->rev;
  126. info = adreno_info(config->rev);
  127. if (!info) {
  128. dev_warn(dev->dev, "Unknown GPU revision: %u.%u.%u.%u\n",
  129. rev.core, rev.major, rev.minor, rev.patchid);
  130. return NULL;
  131. }
  132. DBG("Found GPU: %u.%u.%u.%u", rev.core, rev.major,
  133. rev.minor, rev.patchid);
  134. gpu = info->init(dev);
  135. if (IS_ERR(gpu)) {
  136. dev_warn(dev->dev, "failed to load adreno gpu\n");
  137. gpu = NULL;
  138. /* not fatal */
  139. }
  140. if (gpu) {
  141. int ret;
  142. mutex_lock(&dev->struct_mutex);
  143. gpu->funcs->pm_resume(gpu);
  144. mutex_unlock(&dev->struct_mutex);
  145. disable_irq(gpu->irq);
  146. ret = gpu->funcs->hw_init(gpu);
  147. if (ret) {
  148. dev_err(dev->dev, "gpu hw init failed: %d\n", ret);
  149. gpu->funcs->destroy(gpu);
  150. gpu = NULL;
  151. } else {
  152. enable_irq(gpu->irq);
  153. /* give inactive pm a chance to kick in: */
  154. msm_gpu_retire(gpu);
  155. }
  156. }
  157. return gpu;
  158. }
  159. static void set_gpu_pdev(struct drm_device *dev,
  160. struct platform_device *pdev)
  161. {
  162. struct msm_drm_private *priv = dev->dev_private;
  163. priv->gpu_pdev = pdev;
  164. }
  165. static int find_chipid(struct device *dev, u32 *chipid)
  166. {
  167. struct device_node *node = dev->of_node;
  168. const char *compat;
  169. int ret;
  170. /* first search the compat strings for qcom,adreno-XYZ.W: */
  171. ret = of_property_read_string_index(node, "compatible", 0, &compat);
  172. if (ret == 0) {
  173. unsigned rev, patch;
  174. if (sscanf(compat, "qcom,adreno-%u.%u", &rev, &patch) == 2) {
  175. *chipid = 0;
  176. *chipid |= (rev / 100) << 24; /* core */
  177. rev %= 100;
  178. *chipid |= (rev / 10) << 16; /* major */
  179. rev %= 10;
  180. *chipid |= rev << 8; /* minor */
  181. *chipid |= patch;
  182. return 0;
  183. }
  184. }
  185. /* and if that fails, fall back to legacy "qcom,chipid" property: */
  186. ret = of_property_read_u32(node, "qcom,chipid", chipid);
  187. if (ret)
  188. return ret;
  189. dev_warn(dev, "Using legacy qcom,chipid binding!\n");
  190. dev_warn(dev, "Use compatible qcom,adreno-%u%u%u.%u instead.\n",
  191. (*chipid >> 24) & 0xff, (*chipid >> 16) & 0xff,
  192. (*chipid >> 8) & 0xff, *chipid & 0xff);
  193. return 0;
  194. }
  195. static int adreno_bind(struct device *dev, struct device *master, void *data)
  196. {
  197. static struct adreno_platform_config config = {};
  198. struct device_node *child, *node = dev->of_node;
  199. u32 val;
  200. int ret;
  201. ret = find_chipid(dev, &val);
  202. if (ret) {
  203. dev_err(dev, "could not find chipid: %d\n", ret);
  204. return ret;
  205. }
  206. config.rev = ADRENO_REV((val >> 24) & 0xff,
  207. (val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff);
  208. /* find clock rates: */
  209. config.fast_rate = 0;
  210. config.slow_rate = ~0;
  211. for_each_child_of_node(node, child) {
  212. if (of_device_is_compatible(child, "qcom,gpu-pwrlevels")) {
  213. struct device_node *pwrlvl;
  214. for_each_child_of_node(child, pwrlvl) {
  215. ret = of_property_read_u32(pwrlvl, "qcom,gpu-freq", &val);
  216. if (ret) {
  217. dev_err(dev, "could not find gpu-freq: %d\n", ret);
  218. return ret;
  219. }
  220. config.fast_rate = max(config.fast_rate, val);
  221. config.slow_rate = min(config.slow_rate, val);
  222. }
  223. }
  224. }
  225. if (!config.fast_rate) {
  226. dev_warn(dev, "could not find clk rates\n");
  227. /* This is a safe low speed for all devices: */
  228. config.fast_rate = 200000000;
  229. config.slow_rate = 27000000;
  230. }
  231. dev->platform_data = &config;
  232. set_gpu_pdev(dev_get_drvdata(master), to_platform_device(dev));
  233. return 0;
  234. }
  235. static void adreno_unbind(struct device *dev, struct device *master,
  236. void *data)
  237. {
  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. static struct platform_driver adreno_driver = {
  261. .probe = adreno_probe,
  262. .remove = adreno_remove,
  263. .driver = {
  264. .name = "adreno",
  265. .of_match_table = dt_match,
  266. },
  267. };
  268. void __init adreno_register(void)
  269. {
  270. platform_driver_register(&adreno_driver);
  271. }
  272. void __exit adreno_unregister(void)
  273. {
  274. platform_driver_unregister(&adreno_driver);
  275. }