exynos_drm_drv.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /*
  2. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  3. * Authors:
  4. * Inki Dae <inki.dae@samsung.com>
  5. * Joonyoung Shim <jy0922.shim@samsung.com>
  6. * Seung-Woo Kim <sw0312.kim@samsung.com>
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the next
  16. * paragraph) shall be included in all copies or substantial portions of the
  17. * Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  23. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  24. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. * OTHER DEALINGS IN THE SOFTWARE.
  26. */
  27. #include <drm/drmP.h>
  28. #include <drm/drm_crtc_helper.h>
  29. #include <drm/exynos_drm.h>
  30. #include "exynos_drm_drv.h"
  31. #include "exynos_drm_crtc.h"
  32. #include "exynos_drm_encoder.h"
  33. #include "exynos_drm_fbdev.h"
  34. #include "exynos_drm_fb.h"
  35. #include "exynos_drm_gem.h"
  36. #include "exynos_drm_plane.h"
  37. #include "exynos_drm_vidi.h"
  38. #include "exynos_drm_dmabuf.h"
  39. #include "exynos_drm_g2d.h"
  40. #include "exynos_drm_iommu.h"
  41. #define DRIVER_NAME "exynos"
  42. #define DRIVER_DESC "Samsung SoC DRM"
  43. #define DRIVER_DATE "20110530"
  44. #define DRIVER_MAJOR 1
  45. #define DRIVER_MINOR 0
  46. #define VBLANK_OFF_DELAY 50000
  47. /* platform device pointer for eynos drm device. */
  48. static struct platform_device *exynos_drm_pdev;
  49. static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
  50. {
  51. struct exynos_drm_private *private;
  52. int ret;
  53. int nr;
  54. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  55. private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
  56. if (!private) {
  57. DRM_ERROR("failed to allocate private\n");
  58. return -ENOMEM;
  59. }
  60. INIT_LIST_HEAD(&private->pageflip_event_list);
  61. dev->dev_private = (void *)private;
  62. /*
  63. * create mapping to manage iommu table and set a pointer to iommu
  64. * mapping structure to iommu_mapping of private data.
  65. * also this iommu_mapping can be used to check if iommu is supported
  66. * or not.
  67. */
  68. ret = drm_create_iommu_mapping(dev);
  69. if (ret < 0) {
  70. DRM_ERROR("failed to create iommu mapping.\n");
  71. goto err_crtc;
  72. }
  73. drm_mode_config_init(dev);
  74. /* init kms poll for handling hpd */
  75. drm_kms_helper_poll_init(dev);
  76. exynos_drm_mode_config_init(dev);
  77. /*
  78. * EXYNOS4 is enough to have two CRTCs and each crtc would be used
  79. * without dependency of hardware.
  80. */
  81. for (nr = 0; nr < MAX_CRTC; nr++) {
  82. ret = exynos_drm_crtc_create(dev, nr);
  83. if (ret)
  84. goto err_release_iommu_mapping;
  85. }
  86. for (nr = 0; nr < MAX_PLANE; nr++) {
  87. struct drm_plane *plane;
  88. unsigned int possible_crtcs = (1 << MAX_CRTC) - 1;
  89. plane = exynos_plane_init(dev, possible_crtcs, false);
  90. if (!plane)
  91. goto err_release_iommu_mapping;
  92. }
  93. ret = drm_vblank_init(dev, MAX_CRTC);
  94. if (ret)
  95. goto err_release_iommu_mapping;
  96. /*
  97. * probe sub drivers such as display controller and hdmi driver,
  98. * that were registered at probe() of platform driver
  99. * to the sub driver and create encoder and connector for them.
  100. */
  101. ret = exynos_drm_device_register(dev);
  102. if (ret)
  103. goto err_vblank;
  104. /* setup possible_clones. */
  105. exynos_drm_encoder_setup(dev);
  106. /*
  107. * create and configure fb helper and also exynos specific
  108. * fbdev object.
  109. */
  110. ret = exynos_drm_fbdev_init(dev);
  111. if (ret) {
  112. DRM_ERROR("failed to initialize drm fbdev\n");
  113. goto err_drm_device;
  114. }
  115. drm_vblank_offdelay = VBLANK_OFF_DELAY;
  116. return 0;
  117. err_drm_device:
  118. exynos_drm_device_unregister(dev);
  119. err_vblank:
  120. drm_vblank_cleanup(dev);
  121. err_release_iommu_mapping:
  122. drm_release_iommu_mapping(dev);
  123. err_crtc:
  124. drm_mode_config_cleanup(dev);
  125. kfree(private);
  126. return ret;
  127. }
  128. static int exynos_drm_unload(struct drm_device *dev)
  129. {
  130. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  131. exynos_drm_fbdev_fini(dev);
  132. exynos_drm_device_unregister(dev);
  133. drm_vblank_cleanup(dev);
  134. drm_kms_helper_poll_fini(dev);
  135. drm_mode_config_cleanup(dev);
  136. drm_release_iommu_mapping(dev);
  137. kfree(dev->dev_private);
  138. dev->dev_private = NULL;
  139. return 0;
  140. }
  141. static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
  142. {
  143. struct drm_exynos_file_private *file_priv;
  144. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  145. file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
  146. if (!file_priv)
  147. return -ENOMEM;
  148. file->driver_priv = file_priv;
  149. return exynos_drm_subdrv_open(dev, file);
  150. }
  151. static void exynos_drm_preclose(struct drm_device *dev,
  152. struct drm_file *file)
  153. {
  154. struct exynos_drm_private *private = dev->dev_private;
  155. struct drm_pending_vblank_event *e, *t;
  156. unsigned long flags;
  157. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  158. /* release events of current file */
  159. spin_lock_irqsave(&dev->event_lock, flags);
  160. list_for_each_entry_safe(e, t, &private->pageflip_event_list,
  161. base.link) {
  162. if (e->base.file_priv == file) {
  163. list_del(&e->base.link);
  164. e->base.destroy(&e->base);
  165. }
  166. }
  167. spin_unlock_irqrestore(&dev->event_lock, flags);
  168. exynos_drm_subdrv_close(dev, file);
  169. }
  170. static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
  171. {
  172. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  173. if (!file->driver_priv)
  174. return;
  175. kfree(file->driver_priv);
  176. file->driver_priv = NULL;
  177. }
  178. static void exynos_drm_lastclose(struct drm_device *dev)
  179. {
  180. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  181. exynos_drm_fbdev_restore_mode(dev);
  182. }
  183. static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
  184. .fault = exynos_drm_gem_fault,
  185. .open = drm_gem_vm_open,
  186. .close = drm_gem_vm_close,
  187. };
  188. static struct drm_ioctl_desc exynos_ioctls[] = {
  189. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
  190. DRM_UNLOCKED | DRM_AUTH),
  191. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
  192. exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
  193. DRM_AUTH),
  194. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
  195. exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
  196. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET,
  197. exynos_drm_gem_get_ioctl, DRM_UNLOCKED),
  198. DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION,
  199. vidi_connection_ioctl, DRM_UNLOCKED | DRM_AUTH),
  200. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER,
  201. exynos_g2d_get_ver_ioctl, DRM_UNLOCKED | DRM_AUTH),
  202. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST,
  203. exynos_g2d_set_cmdlist_ioctl, DRM_UNLOCKED | DRM_AUTH),
  204. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC,
  205. exynos_g2d_exec_ioctl, DRM_UNLOCKED | DRM_AUTH),
  206. };
  207. static const struct file_operations exynos_drm_driver_fops = {
  208. .owner = THIS_MODULE,
  209. .open = drm_open,
  210. .mmap = exynos_drm_gem_mmap,
  211. .poll = drm_poll,
  212. .read = drm_read,
  213. .unlocked_ioctl = drm_ioctl,
  214. #ifdef CONFIG_COMPAT
  215. .compat_ioctl = drm_compat_ioctl,
  216. #endif
  217. .release = drm_release,
  218. };
  219. static struct drm_driver exynos_drm_driver = {
  220. .driver_features = DRIVER_HAVE_IRQ | DRIVER_MODESET |
  221. DRIVER_GEM | DRIVER_PRIME,
  222. .load = exynos_drm_load,
  223. .unload = exynos_drm_unload,
  224. .open = exynos_drm_open,
  225. .preclose = exynos_drm_preclose,
  226. .lastclose = exynos_drm_lastclose,
  227. .postclose = exynos_drm_postclose,
  228. .get_vblank_counter = drm_vblank_count,
  229. .enable_vblank = exynos_drm_crtc_enable_vblank,
  230. .disable_vblank = exynos_drm_crtc_disable_vblank,
  231. .gem_init_object = exynos_drm_gem_init_object,
  232. .gem_free_object = exynos_drm_gem_free_object,
  233. .gem_vm_ops = &exynos_drm_gem_vm_ops,
  234. .dumb_create = exynos_drm_gem_dumb_create,
  235. .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
  236. .dumb_destroy = exynos_drm_gem_dumb_destroy,
  237. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  238. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  239. .gem_prime_export = exynos_dmabuf_prime_export,
  240. .gem_prime_import = exynos_dmabuf_prime_import,
  241. .ioctls = exynos_ioctls,
  242. .fops = &exynos_drm_driver_fops,
  243. .name = DRIVER_NAME,
  244. .desc = DRIVER_DESC,
  245. .date = DRIVER_DATE,
  246. .major = DRIVER_MAJOR,
  247. .minor = DRIVER_MINOR,
  248. };
  249. static int exynos_drm_platform_probe(struct platform_device *pdev)
  250. {
  251. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  252. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  253. exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
  254. return drm_platform_init(&exynos_drm_driver, pdev);
  255. }
  256. static int exynos_drm_platform_remove(struct platform_device *pdev)
  257. {
  258. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  259. drm_platform_exit(&exynos_drm_driver, pdev);
  260. return 0;
  261. }
  262. static struct platform_driver exynos_drm_platform_driver = {
  263. .probe = exynos_drm_platform_probe,
  264. .remove = __devexit_p(exynos_drm_platform_remove),
  265. .driver = {
  266. .owner = THIS_MODULE,
  267. .name = "exynos-drm",
  268. },
  269. };
  270. static int __init exynos_drm_init(void)
  271. {
  272. int ret;
  273. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  274. #ifdef CONFIG_DRM_EXYNOS_FIMD
  275. ret = platform_driver_register(&fimd_driver);
  276. if (ret < 0)
  277. goto out_fimd;
  278. #endif
  279. #ifdef CONFIG_DRM_EXYNOS_HDMI
  280. ret = platform_driver_register(&hdmi_driver);
  281. if (ret < 0)
  282. goto out_hdmi;
  283. ret = platform_driver_register(&mixer_driver);
  284. if (ret < 0)
  285. goto out_mixer;
  286. ret = platform_driver_register(&exynos_drm_common_hdmi_driver);
  287. if (ret < 0)
  288. goto out_common_hdmi;
  289. ret = exynos_platform_device_hdmi_register();
  290. if (ret < 0)
  291. goto out_common_hdmi_dev;
  292. #endif
  293. #ifdef CONFIG_DRM_EXYNOS_VIDI
  294. ret = platform_driver_register(&vidi_driver);
  295. if (ret < 0)
  296. goto out_vidi;
  297. #endif
  298. #ifdef CONFIG_DRM_EXYNOS_G2D
  299. ret = platform_driver_register(&g2d_driver);
  300. if (ret < 0)
  301. goto out_g2d;
  302. #endif
  303. ret = platform_driver_register(&exynos_drm_platform_driver);
  304. if (ret < 0)
  305. goto out_drm;
  306. exynos_drm_pdev = platform_device_register_simple("exynos-drm", -1,
  307. NULL, 0);
  308. if (IS_ERR_OR_NULL(exynos_drm_pdev)) {
  309. ret = PTR_ERR(exynos_drm_pdev);
  310. goto out;
  311. }
  312. return 0;
  313. out:
  314. platform_driver_unregister(&exynos_drm_platform_driver);
  315. out_drm:
  316. #ifdef CONFIG_DRM_EXYNOS_G2D
  317. platform_driver_unregister(&g2d_driver);
  318. out_g2d:
  319. #endif
  320. #ifdef CONFIG_DRM_EXYNOS_VIDI
  321. platform_driver_unregister(&vidi_driver);
  322. out_vidi:
  323. #endif
  324. #ifdef CONFIG_DRM_EXYNOS_HDMI
  325. exynos_platform_device_hdmi_unregister();
  326. out_common_hdmi_dev:
  327. platform_driver_unregister(&exynos_drm_common_hdmi_driver);
  328. out_common_hdmi:
  329. platform_driver_unregister(&mixer_driver);
  330. out_mixer:
  331. platform_driver_unregister(&hdmi_driver);
  332. out_hdmi:
  333. #endif
  334. #ifdef CONFIG_DRM_EXYNOS_FIMD
  335. platform_driver_unregister(&fimd_driver);
  336. out_fimd:
  337. #endif
  338. return ret;
  339. }
  340. static void __exit exynos_drm_exit(void)
  341. {
  342. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  343. platform_device_unregister(exynos_drm_pdev);
  344. platform_driver_unregister(&exynos_drm_platform_driver);
  345. #ifdef CONFIG_DRM_EXYNOS_G2D
  346. platform_driver_unregister(&g2d_driver);
  347. #endif
  348. #ifdef CONFIG_DRM_EXYNOS_HDMI
  349. exynos_platform_device_hdmi_unregister();
  350. platform_driver_unregister(&exynos_drm_common_hdmi_driver);
  351. platform_driver_unregister(&mixer_driver);
  352. platform_driver_unregister(&hdmi_driver);
  353. #endif
  354. #ifdef CONFIG_DRM_EXYNOS_VIDI
  355. platform_driver_unregister(&vidi_driver);
  356. #endif
  357. #ifdef CONFIG_DRM_EXYNOS_FIMD
  358. platform_driver_unregister(&fimd_driver);
  359. #endif
  360. }
  361. module_init(exynos_drm_init);
  362. module_exit(exynos_drm_exit);
  363. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  364. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  365. MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
  366. MODULE_DESCRIPTION("Samsung SoC DRM Driver");
  367. MODULE_LICENSE("GPL");