Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 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 | |
| 29 | #include "drmP.h" |
| 30 | #include "drm_crtc.h" |
| 31 | #include "drm_crtc_helper.h" |
Seung-Woo Kim | 7db3eba | 2011-10-18 16:58:05 +0900 | [diff] [blame] | 32 | #include "drm_fb_helper.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 33 | |
Seung-Woo Kim | 7db3eba | 2011-10-18 16:58:05 +0900 | [diff] [blame] | 34 | #include "exynos_drm_drv.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 35 | #include "exynos_drm_fb.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 36 | #include "exynos_drm_gem.h" |
| 37 | |
| 38 | #define to_exynos_fb(x) container_of(x, struct exynos_drm_fb, fb) |
| 39 | |
| 40 | /* |
| 41 | * exynos specific framebuffer structure. |
| 42 | * |
| 43 | * @fb: drm framebuffer obejct. |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame^] | 44 | * @exynos_gem_obj: array of exynos specific gem object containing a gem object. |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 45 | */ |
| 46 | struct exynos_drm_fb { |
| 47 | struct drm_framebuffer fb; |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame^] | 48 | struct exynos_drm_gem_obj *exynos_gem_obj[MAX_FB_BUFFER]; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | static void exynos_drm_fb_destroy(struct drm_framebuffer *fb) |
| 52 | { |
| 53 | struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb); |
| 54 | |
| 55 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 56 | |
| 57 | drm_framebuffer_cleanup(fb); |
| 58 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 59 | kfree(exynos_fb); |
| 60 | exynos_fb = NULL; |
| 61 | } |
| 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 | |
| 69 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 70 | |
| 71 | return drm_gem_handle_create(file_priv, |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame^] | 72 | &exynos_fb->exynos_gem_obj[0]->base, handle); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static int exynos_drm_fb_dirty(struct drm_framebuffer *fb, |
| 76 | struct drm_file *file_priv, unsigned flags, |
| 77 | unsigned color, struct drm_clip_rect *clips, |
| 78 | unsigned num_clips) |
| 79 | { |
| 80 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 81 | |
| 82 | /* TODO */ |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static struct drm_framebuffer_funcs exynos_drm_fb_funcs = { |
| 88 | .destroy = exynos_drm_fb_destroy, |
| 89 | .create_handle = exynos_drm_fb_create_handle, |
| 90 | .dirty = exynos_drm_fb_dirty, |
| 91 | }; |
| 92 | |
Joonyoung Shim | e1533c0 | 2011-12-13 14:46:57 +0900 | [diff] [blame] | 93 | struct drm_framebuffer * |
| 94 | exynos_drm_framebuffer_init(struct drm_device *dev, |
| 95 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 96 | struct drm_gem_object *obj) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 97 | { |
| 98 | struct exynos_drm_fb *exynos_fb; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 99 | int ret; |
| 100 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 101 | exynos_fb = kzalloc(sizeof(*exynos_fb), GFP_KERNEL); |
| 102 | if (!exynos_fb) { |
Joonyoung Shim | e1533c0 | 2011-12-13 14:46:57 +0900 | [diff] [blame] | 103 | DRM_ERROR("failed to allocate exynos drm framebuffer\n"); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 104 | return ERR_PTR(-ENOMEM); |
| 105 | } |
| 106 | |
Joonyoung Shim | e1533c0 | 2011-12-13 14:46:57 +0900 | [diff] [blame] | 107 | ret = drm_framebuffer_init(dev, &exynos_fb->fb, &exynos_drm_fb_funcs); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 108 | if (ret) { |
Joonyoung Shim | e1533c0 | 2011-12-13 14:46:57 +0900 | [diff] [blame] | 109 | DRM_ERROR("failed to initialize framebuffer\n"); |
| 110 | return ERR_PTR(ret); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 111 | } |
| 112 | |
Joonyoung Shim | e1533c0 | 2011-12-13 14:46:57 +0900 | [diff] [blame] | 113 | drm_helper_mode_fill_fb_struct(&exynos_fb->fb, mode_cmd); |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame^] | 114 | exynos_fb->exynos_gem_obj[0] = to_exynos_gem_obj(obj); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 115 | |
Joonyoung Shim | e1533c0 | 2011-12-13 14:46:57 +0900 | [diff] [blame] | 116 | return &exynos_fb->fb; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 117 | } |
| 118 | |
Joonyoung Shim | e1533c0 | 2011-12-13 14:46:57 +0900 | [diff] [blame] | 119 | static struct drm_framebuffer * |
| 120 | exynos_user_fb_create(struct drm_device *dev, struct drm_file *file_priv, |
| 121 | struct drm_mode_fb_cmd2 *mode_cmd) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 122 | { |
Joonyoung Shim | e1533c0 | 2011-12-13 14:46:57 +0900 | [diff] [blame] | 123 | struct drm_gem_object *obj; |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame^] | 124 | struct drm_framebuffer *fb; |
| 125 | struct exynos_drm_fb *exynos_fb; |
| 126 | int nr; |
| 127 | int i; |
Joonyoung Shim | e1533c0 | 2011-12-13 14:46:57 +0900 | [diff] [blame] | 128 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 129 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 130 | |
Joonyoung Shim | e1533c0 | 2011-12-13 14:46:57 +0900 | [diff] [blame] | 131 | obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]); |
| 132 | if (!obj) { |
| 133 | DRM_ERROR("failed to lookup gem object\n"); |
| 134 | return ERR_PTR(-ENOENT); |
| 135 | } |
| 136 | |
| 137 | drm_gem_object_unreference_unlocked(obj); |
| 138 | |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame^] | 139 | fb = exynos_drm_framebuffer_init(dev, mode_cmd, obj); |
| 140 | if (IS_ERR(fb)) |
| 141 | return fb; |
| 142 | |
| 143 | exynos_fb = to_exynos_fb(fb); |
| 144 | nr = exynos_drm_format_num_buffers(fb->pixel_format); |
| 145 | |
| 146 | for (i = 1; i < nr; i++) { |
| 147 | obj = drm_gem_object_lookup(dev, file_priv, |
| 148 | mode_cmd->handles[i]); |
| 149 | if (!obj) { |
| 150 | DRM_ERROR("failed to lookup gem object\n"); |
| 151 | exynos_drm_fb_destroy(fb); |
| 152 | return ERR_PTR(-ENOENT); |
| 153 | } |
| 154 | |
| 155 | drm_gem_object_unreference_unlocked(obj); |
| 156 | |
| 157 | exynos_fb->exynos_gem_obj[i] = to_exynos_gem_obj(obj); |
| 158 | } |
| 159 | |
| 160 | return fb; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 161 | } |
| 162 | |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame^] | 163 | struct exynos_drm_gem_buf *exynos_drm_fb_buffer(struct drm_framebuffer *fb, |
| 164 | int index) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 165 | { |
| 166 | struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb); |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 167 | struct exynos_drm_gem_buf *buffer; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 168 | |
| 169 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 170 | |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame^] | 171 | if (index >= MAX_FB_BUFFER) |
| 172 | return NULL; |
| 173 | |
| 174 | buffer = exynos_fb->exynos_gem_obj[index]->buffer; |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 175 | if (!buffer) |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 176 | return NULL; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 177 | |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 178 | DRM_DEBUG_KMS("vaddr = 0x%lx, dma_addr = 0x%lx\n", |
| 179 | (unsigned long)buffer->kvaddr, |
| 180 | (unsigned long)buffer->dma_addr); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 181 | |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 182 | return buffer; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 183 | } |
| 184 | |
Seung-Woo Kim | 7db3eba | 2011-10-18 16:58:05 +0900 | [diff] [blame] | 185 | static void exynos_drm_output_poll_changed(struct drm_device *dev) |
| 186 | { |
| 187 | struct exynos_drm_private *private = dev->dev_private; |
| 188 | struct drm_fb_helper *fb_helper = private->fb_helper; |
| 189 | |
| 190 | if (fb_helper) |
| 191 | drm_fb_helper_hotplug_event(fb_helper); |
| 192 | } |
| 193 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 194 | static struct drm_mode_config_funcs exynos_drm_mode_config_funcs = { |
Joonyoung Shim | e1533c0 | 2011-12-13 14:46:57 +0900 | [diff] [blame] | 195 | .fb_create = exynos_user_fb_create, |
Seung-Woo Kim | 7db3eba | 2011-10-18 16:58:05 +0900 | [diff] [blame] | 196 | .output_poll_changed = exynos_drm_output_poll_changed, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | void exynos_drm_mode_config_init(struct drm_device *dev) |
| 200 | { |
| 201 | dev->mode_config.min_width = 0; |
| 202 | dev->mode_config.min_height = 0; |
| 203 | |
| 204 | /* |
| 205 | * set max width and height as default value(4096x4096). |
| 206 | * this value would be used to check framebuffer size limitation |
| 207 | * at drm_mode_addfb(). |
| 208 | */ |
| 209 | dev->mode_config.max_width = 4096; |
| 210 | dev->mode_config.max_height = 4096; |
| 211 | |
| 212 | dev->mode_config.funcs = &exynos_drm_mode_config_funcs; |
| 213 | } |
| 214 | |
| 215 | MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>"); |
| 216 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
| 217 | MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>"); |
| 218 | MODULE_DESCRIPTION("Samsung SoC DRM FB Driver"); |
| 219 | MODULE_LICENSE("GPL"); |