vc4_v3d.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * Copyright (c) 2014 The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <robdclark@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "linux/component.h"
  19. #include "linux/pm_runtime.h"
  20. #include "vc4_drv.h"
  21. #include "vc4_regs.h"
  22. #ifdef CONFIG_DEBUG_FS
  23. #define REGDEF(reg) { reg, #reg }
  24. static const struct {
  25. uint32_t reg;
  26. const char *name;
  27. } vc4_reg_defs[] = {
  28. REGDEF(V3D_IDENT0),
  29. REGDEF(V3D_IDENT1),
  30. REGDEF(V3D_IDENT2),
  31. REGDEF(V3D_SCRATCH),
  32. REGDEF(V3D_L2CACTL),
  33. REGDEF(V3D_SLCACTL),
  34. REGDEF(V3D_INTCTL),
  35. REGDEF(V3D_INTENA),
  36. REGDEF(V3D_INTDIS),
  37. REGDEF(V3D_CT0CS),
  38. REGDEF(V3D_CT1CS),
  39. REGDEF(V3D_CT0EA),
  40. REGDEF(V3D_CT1EA),
  41. REGDEF(V3D_CT0CA),
  42. REGDEF(V3D_CT1CA),
  43. REGDEF(V3D_CT00RA0),
  44. REGDEF(V3D_CT01RA0),
  45. REGDEF(V3D_CT0LC),
  46. REGDEF(V3D_CT1LC),
  47. REGDEF(V3D_CT0PC),
  48. REGDEF(V3D_CT1PC),
  49. REGDEF(V3D_PCS),
  50. REGDEF(V3D_BFC),
  51. REGDEF(V3D_RFC),
  52. REGDEF(V3D_BPCA),
  53. REGDEF(V3D_BPCS),
  54. REGDEF(V3D_BPOA),
  55. REGDEF(V3D_BPOS),
  56. REGDEF(V3D_BXCF),
  57. REGDEF(V3D_SQRSV0),
  58. REGDEF(V3D_SQRSV1),
  59. REGDEF(V3D_SQCNTL),
  60. REGDEF(V3D_SRQPC),
  61. REGDEF(V3D_SRQUA),
  62. REGDEF(V3D_SRQUL),
  63. REGDEF(V3D_SRQCS),
  64. REGDEF(V3D_VPACNTL),
  65. REGDEF(V3D_VPMBASE),
  66. REGDEF(V3D_PCTRC),
  67. REGDEF(V3D_PCTRE),
  68. REGDEF(V3D_PCTR0),
  69. REGDEF(V3D_PCTRS0),
  70. REGDEF(V3D_PCTR1),
  71. REGDEF(V3D_PCTRS1),
  72. REGDEF(V3D_PCTR2),
  73. REGDEF(V3D_PCTRS2),
  74. REGDEF(V3D_PCTR3),
  75. REGDEF(V3D_PCTRS3),
  76. REGDEF(V3D_PCTR4),
  77. REGDEF(V3D_PCTRS4),
  78. REGDEF(V3D_PCTR5),
  79. REGDEF(V3D_PCTRS5),
  80. REGDEF(V3D_PCTR6),
  81. REGDEF(V3D_PCTRS6),
  82. REGDEF(V3D_PCTR7),
  83. REGDEF(V3D_PCTRS7),
  84. REGDEF(V3D_PCTR8),
  85. REGDEF(V3D_PCTRS8),
  86. REGDEF(V3D_PCTR9),
  87. REGDEF(V3D_PCTRS9),
  88. REGDEF(V3D_PCTR10),
  89. REGDEF(V3D_PCTRS10),
  90. REGDEF(V3D_PCTR11),
  91. REGDEF(V3D_PCTRS11),
  92. REGDEF(V3D_PCTR12),
  93. REGDEF(V3D_PCTRS12),
  94. REGDEF(V3D_PCTR13),
  95. REGDEF(V3D_PCTRS13),
  96. REGDEF(V3D_PCTR14),
  97. REGDEF(V3D_PCTRS14),
  98. REGDEF(V3D_PCTR15),
  99. REGDEF(V3D_PCTRS15),
  100. REGDEF(V3D_DBGE),
  101. REGDEF(V3D_FDBGO),
  102. REGDEF(V3D_FDBGB),
  103. REGDEF(V3D_FDBGR),
  104. REGDEF(V3D_FDBGS),
  105. REGDEF(V3D_ERRSTAT),
  106. };
  107. int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused)
  108. {
  109. struct drm_info_node *node = (struct drm_info_node *)m->private;
  110. struct drm_device *dev = node->minor->dev;
  111. struct vc4_dev *vc4 = to_vc4_dev(dev);
  112. int i;
  113. for (i = 0; i < ARRAY_SIZE(vc4_reg_defs); i++) {
  114. seq_printf(m, "%s (0x%04x): 0x%08x\n",
  115. vc4_reg_defs[i].name, vc4_reg_defs[i].reg,
  116. V3D_READ(vc4_reg_defs[i].reg));
  117. }
  118. return 0;
  119. }
  120. int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
  121. {
  122. struct drm_info_node *node = (struct drm_info_node *)m->private;
  123. struct drm_device *dev = node->minor->dev;
  124. struct vc4_dev *vc4 = to_vc4_dev(dev);
  125. uint32_t ident1 = V3D_READ(V3D_IDENT1);
  126. uint32_t nslc = VC4_GET_FIELD(ident1, V3D_IDENT1_NSLC);
  127. uint32_t tups = VC4_GET_FIELD(ident1, V3D_IDENT1_TUPS);
  128. uint32_t qups = VC4_GET_FIELD(ident1, V3D_IDENT1_QUPS);
  129. seq_printf(m, "Revision: %d\n",
  130. VC4_GET_FIELD(ident1, V3D_IDENT1_REV));
  131. seq_printf(m, "Slices: %d\n", nslc);
  132. seq_printf(m, "TMUs: %d\n", nslc * tups);
  133. seq_printf(m, "QPUs: %d\n", nslc * qups);
  134. seq_printf(m, "Semaphores: %d\n",
  135. VC4_GET_FIELD(ident1, V3D_IDENT1_NSEM));
  136. return 0;
  137. }
  138. #endif /* CONFIG_DEBUG_FS */
  139. static void vc4_v3d_init_hw(struct drm_device *dev)
  140. {
  141. struct vc4_dev *vc4 = to_vc4_dev(dev);
  142. /* Take all the memory that would have been reserved for user
  143. * QPU programs, since we don't have an interface for running
  144. * them, anyway.
  145. */
  146. V3D_WRITE(V3D_VPMBASE, 0);
  147. }
  148. #ifdef CONFIG_PM
  149. static int vc4_v3d_runtime_suspend(struct device *dev)
  150. {
  151. struct vc4_v3d *v3d = dev_get_drvdata(dev);
  152. struct vc4_dev *vc4 = v3d->vc4;
  153. vc4_irq_uninstall(vc4->dev);
  154. return 0;
  155. }
  156. static int vc4_v3d_runtime_resume(struct device *dev)
  157. {
  158. struct vc4_v3d *v3d = dev_get_drvdata(dev);
  159. struct vc4_dev *vc4 = v3d->vc4;
  160. vc4_v3d_init_hw(vc4->dev);
  161. /* We disabled the IRQ as part of vc4_irq_uninstall in suspend. */
  162. enable_irq(vc4->dev->irq);
  163. vc4_irq_postinstall(vc4->dev);
  164. return 0;
  165. }
  166. #endif
  167. static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
  168. {
  169. struct platform_device *pdev = to_platform_device(dev);
  170. struct drm_device *drm = dev_get_drvdata(master);
  171. struct vc4_dev *vc4 = to_vc4_dev(drm);
  172. struct vc4_v3d *v3d = NULL;
  173. int ret;
  174. v3d = devm_kzalloc(&pdev->dev, sizeof(*v3d), GFP_KERNEL);
  175. if (!v3d)
  176. return -ENOMEM;
  177. dev_set_drvdata(dev, v3d);
  178. v3d->pdev = pdev;
  179. v3d->regs = vc4_ioremap_regs(pdev, 0);
  180. if (IS_ERR(v3d->regs))
  181. return PTR_ERR(v3d->regs);
  182. vc4->v3d = v3d;
  183. v3d->vc4 = vc4;
  184. if (V3D_READ(V3D_IDENT0) != V3D_EXPECTED_IDENT0) {
  185. DRM_ERROR("V3D_IDENT0 read 0x%08x instead of 0x%08x\n",
  186. V3D_READ(V3D_IDENT0), V3D_EXPECTED_IDENT0);
  187. return -EINVAL;
  188. }
  189. /* Reset the binner overflow address/size at setup, to be sure
  190. * we don't reuse an old one.
  191. */
  192. V3D_WRITE(V3D_BPOA, 0);
  193. V3D_WRITE(V3D_BPOS, 0);
  194. vc4_v3d_init_hw(drm);
  195. ret = drm_irq_install(drm, platform_get_irq(pdev, 0));
  196. if (ret) {
  197. DRM_ERROR("Failed to install IRQ handler\n");
  198. return ret;
  199. }
  200. pm_runtime_use_autosuspend(dev);
  201. pm_runtime_set_autosuspend_delay(dev, 40); /* a little over 2 frames. */
  202. pm_runtime_enable(dev);
  203. return 0;
  204. }
  205. static void vc4_v3d_unbind(struct device *dev, struct device *master,
  206. void *data)
  207. {
  208. struct drm_device *drm = dev_get_drvdata(master);
  209. struct vc4_dev *vc4 = to_vc4_dev(drm);
  210. pm_runtime_disable(dev);
  211. drm_irq_uninstall(drm);
  212. /* Disable the binner's overflow memory address, so the next
  213. * driver probe (if any) doesn't try to reuse our old
  214. * allocation.
  215. */
  216. V3D_WRITE(V3D_BPOA, 0);
  217. V3D_WRITE(V3D_BPOS, 0);
  218. vc4->v3d = NULL;
  219. }
  220. static const struct dev_pm_ops vc4_v3d_pm_ops = {
  221. SET_RUNTIME_PM_OPS(vc4_v3d_runtime_suspend, vc4_v3d_runtime_resume, NULL)
  222. };
  223. static const struct component_ops vc4_v3d_ops = {
  224. .bind = vc4_v3d_bind,
  225. .unbind = vc4_v3d_unbind,
  226. };
  227. static int vc4_v3d_dev_probe(struct platform_device *pdev)
  228. {
  229. return component_add(&pdev->dev, &vc4_v3d_ops);
  230. }
  231. static int vc4_v3d_dev_remove(struct platform_device *pdev)
  232. {
  233. component_del(&pdev->dev, &vc4_v3d_ops);
  234. return 0;
  235. }
  236. static const struct of_device_id vc4_v3d_dt_match[] = {
  237. { .compatible = "brcm,bcm2835-v3d" },
  238. { .compatible = "brcm,vc4-v3d" },
  239. {}
  240. };
  241. struct platform_driver vc4_v3d_driver = {
  242. .probe = vc4_v3d_dev_probe,
  243. .remove = vc4_v3d_dev_remove,
  244. .driver = {
  245. .name = "vc4_v3d",
  246. .of_match_table = vc4_v3d_dt_match,
  247. .pm = &vc4_v3d_pm_ops,
  248. },
  249. };