exynos_drm_fb.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /* exynos_drm_fb.c
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  4. * Authors:
  5. * Inki Dae <inki.dae@samsung.com>
  6. * Joonyoung Shim <jy0922.shim@samsung.com>
  7. * Seung-Woo Kim <sw0312.kim@samsung.com>
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a
  10. * copy of this software and associated documentation files (the "Software"),
  11. * to deal in the Software without restriction, including without limitation
  12. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. * and/or sell copies of the Software, and to permit persons to whom the
  14. * Software is furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice (including the next
  17. * paragraph) shall be included in all copies or substantial portions of the
  18. * Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  23. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  24. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  25. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  26. * OTHER DEALINGS IN THE SOFTWARE.
  27. */
  28. #include "drmP.h"
  29. #include "drm_crtc.h"
  30. #include "drm_crtc_helper.h"
  31. #include "exynos_drm_fb.h"
  32. #include "exynos_drm_buf.h"
  33. #include "exynos_drm_gem.h"
  34. #define to_exynos_fb(x) container_of(x, struct exynos_drm_fb, fb)
  35. /*
  36. * exynos specific framebuffer structure.
  37. *
  38. * @fb: drm framebuffer obejct.
  39. * @exynos_gem_obj: exynos specific gem object containing a gem object.
  40. * @entry: pointer to exynos drm buffer entry object.
  41. * - containing only the information to physically continuous memory
  42. * region allocated at default framebuffer creation.
  43. */
  44. struct exynos_drm_fb {
  45. struct drm_framebuffer fb;
  46. struct exynos_drm_gem_obj *exynos_gem_obj;
  47. struct exynos_drm_buf_entry *entry;
  48. };
  49. static void exynos_drm_fb_destroy(struct drm_framebuffer *fb)
  50. {
  51. struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
  52. DRM_DEBUG_KMS("%s\n", __FILE__);
  53. drm_framebuffer_cleanup(fb);
  54. /*
  55. * default framebuffer has no gem object so
  56. * a buffer of the default framebuffer should be released at here.
  57. */
  58. if (!exynos_fb->exynos_gem_obj && exynos_fb->entry)
  59. exynos_drm_buf_destroy(fb->dev, exynos_fb->entry);
  60. kfree(exynos_fb);
  61. exynos_fb = NULL;
  62. }
  63. static int exynos_drm_fb_create_handle(struct drm_framebuffer *fb,
  64. struct drm_file *file_priv,
  65. unsigned int *handle)
  66. {
  67. struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
  68. DRM_DEBUG_KMS("%s\n", __FILE__);
  69. return drm_gem_handle_create(file_priv,
  70. &exynos_fb->exynos_gem_obj->base, handle);
  71. }
  72. static int exynos_drm_fb_dirty(struct drm_framebuffer *fb,
  73. struct drm_file *file_priv, unsigned flags,
  74. unsigned color, struct drm_clip_rect *clips,
  75. unsigned num_clips)
  76. {
  77. DRM_DEBUG_KMS("%s\n", __FILE__);
  78. /* TODO */
  79. return 0;
  80. }
  81. static struct drm_framebuffer_funcs exynos_drm_fb_funcs = {
  82. .destroy = exynos_drm_fb_destroy,
  83. .create_handle = exynos_drm_fb_create_handle,
  84. .dirty = exynos_drm_fb_dirty,
  85. };
  86. static struct drm_framebuffer *
  87. exynos_drm_fb_init(struct drm_file *file_priv, struct drm_device *dev,
  88. struct drm_mode_fb_cmd *mode_cmd)
  89. {
  90. struct exynos_drm_fb *exynos_fb;
  91. struct drm_framebuffer *fb;
  92. struct exynos_drm_gem_obj *exynos_gem_obj = NULL;
  93. struct drm_gem_object *obj;
  94. unsigned int size;
  95. int ret;
  96. DRM_DEBUG_KMS("%s\n", __FILE__);
  97. mode_cmd->pitch = max(mode_cmd->pitch,
  98. mode_cmd->width * (mode_cmd->bpp >> 3));
  99. DRM_LOG_KMS("drm fb create(%dx%d)\n",
  100. mode_cmd->width, mode_cmd->height);
  101. exynos_fb = kzalloc(sizeof(*exynos_fb), GFP_KERNEL);
  102. if (!exynos_fb) {
  103. DRM_ERROR("failed to allocate exynos drm framebuffer.\n");
  104. return ERR_PTR(-ENOMEM);
  105. }
  106. fb = &exynos_fb->fb;
  107. ret = drm_framebuffer_init(dev, fb, &exynos_drm_fb_funcs);
  108. if (ret) {
  109. DRM_ERROR("failed to initialize framebuffer.\n");
  110. goto err_init;
  111. }
  112. DRM_LOG_KMS("create: fb id: %d\n", fb->base.id);
  113. size = mode_cmd->pitch * mode_cmd->height;
  114. /*
  115. * mode_cmd->handle could be NULL at booting time or
  116. * with user request. if NULL, a new buffer or a gem object
  117. * would be allocated.
  118. */
  119. if (!mode_cmd->handle) {
  120. if (!file_priv) {
  121. struct exynos_drm_buf_entry *entry;
  122. /*
  123. * in case that file_priv is NULL, it allocates
  124. * only buffer and this buffer would be used
  125. * for default framebuffer.
  126. */
  127. entry = exynos_drm_buf_create(dev, size);
  128. if (IS_ERR(entry)) {
  129. ret = PTR_ERR(entry);
  130. goto err_buffer;
  131. }
  132. exynos_fb->entry = entry;
  133. DRM_LOG_KMS("default fb: paddr = 0x%lx, size = 0x%x\n",
  134. (unsigned long)entry->paddr, size);
  135. goto out;
  136. } else {
  137. exynos_gem_obj = exynos_drm_gem_create(file_priv, dev,
  138. size,
  139. &mode_cmd->handle);
  140. if (IS_ERR(exynos_gem_obj)) {
  141. ret = PTR_ERR(exynos_gem_obj);
  142. goto err_buffer;
  143. }
  144. }
  145. } else {
  146. obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle);
  147. if (!obj) {
  148. DRM_ERROR("failed to lookup gem object.\n");
  149. goto err_buffer;
  150. }
  151. exynos_gem_obj = to_exynos_gem_obj(obj);
  152. drm_gem_object_unreference_unlocked(obj);
  153. }
  154. /*
  155. * if got a exynos_gem_obj from either a handle or
  156. * a new creation then exynos_fb->exynos_gem_obj is NULL
  157. * so that default framebuffer has no its own gem object,
  158. * only its own buffer object.
  159. */
  160. exynos_fb->entry = exynos_gem_obj->entry;
  161. DRM_LOG_KMS("paddr = 0x%lx, size = 0x%x, gem object = 0x%x\n",
  162. (unsigned long)exynos_fb->entry->paddr, size,
  163. (unsigned int)&exynos_gem_obj->base);
  164. out:
  165. exynos_fb->exynos_gem_obj = exynos_gem_obj;
  166. drm_helper_mode_fill_fb_struct(fb, mode_cmd);
  167. return fb;
  168. err_buffer:
  169. drm_framebuffer_cleanup(fb);
  170. err_init:
  171. kfree(exynos_fb);
  172. return ERR_PTR(ret);
  173. }
  174. struct drm_framebuffer *exynos_drm_fb_create(struct drm_device *dev,
  175. struct drm_file *file_priv,
  176. struct drm_mode_fb_cmd *mode_cmd)
  177. {
  178. DRM_DEBUG_KMS("%s\n", __FILE__);
  179. return exynos_drm_fb_init(file_priv, dev, mode_cmd);
  180. }
  181. struct exynos_drm_buf_entry *exynos_drm_fb_get_buf(struct drm_framebuffer *fb)
  182. {
  183. struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
  184. struct exynos_drm_buf_entry *entry;
  185. DRM_DEBUG_KMS("%s\n", __FILE__);
  186. entry = exynos_fb->entry;
  187. if (!entry)
  188. return NULL;
  189. DRM_DEBUG_KMS("vaddr = 0x%lx, paddr = 0x%lx\n",
  190. (unsigned long)entry->vaddr,
  191. (unsigned long)entry->paddr);
  192. return entry;
  193. }
  194. static struct drm_mode_config_funcs exynos_drm_mode_config_funcs = {
  195. .fb_create = exynos_drm_fb_create,
  196. };
  197. void exynos_drm_mode_config_init(struct drm_device *dev)
  198. {
  199. dev->mode_config.min_width = 0;
  200. dev->mode_config.min_height = 0;
  201. /*
  202. * set max width and height as default value(4096x4096).
  203. * this value would be used to check framebuffer size limitation
  204. * at drm_mode_addfb().
  205. */
  206. dev->mode_config.max_width = 4096;
  207. dev->mode_config.max_height = 4096;
  208. dev->mode_config.funcs = &exynos_drm_mode_config_funcs;
  209. }
  210. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  211. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  212. MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
  213. MODULE_DESCRIPTION("Samsung SoC DRM FB Driver");
  214. MODULE_LICENSE("GPL");