[S390] Remove error checking from copy_oldmem_page()
[linux/fpc-iii.git] / drivers / gpu / drm / exynos / exynos_drm_fb.c
blob48d29cfd5240197f645c6732a9360bb255656f97
1 /* exynos_drm_fb.c
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>
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:
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.
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.
29 #include "drmP.h"
30 #include "drm_crtc.h"
31 #include "drm_crtc_helper.h"
33 #include "exynos_drm_fb.h"
34 #include "exynos_drm_buf.h"
35 #include "exynos_drm_gem.h"
37 #define to_exynos_fb(x) container_of(x, struct exynos_drm_fb, fb)
40 * exynos specific framebuffer structure.
42 * @fb: drm framebuffer obejct.
43 * @exynos_gem_obj: exynos specific gem object containing a gem object.
44 * @entry: pointer to exynos drm buffer entry object.
45 * - containing only the information to physically continuous memory
46 * region allocated at default framebuffer creation.
48 struct exynos_drm_fb {
49 struct drm_framebuffer fb;
50 struct exynos_drm_gem_obj *exynos_gem_obj;
51 struct exynos_drm_buf_entry *entry;
54 static void exynos_drm_fb_destroy(struct drm_framebuffer *fb)
56 struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
58 DRM_DEBUG_KMS("%s\n", __FILE__);
60 drm_framebuffer_cleanup(fb);
63 * default framebuffer has no gem object so
64 * a buffer of the default framebuffer should be released at here.
66 if (!exynos_fb->exynos_gem_obj && exynos_fb->entry)
67 exynos_drm_buf_destroy(fb->dev, exynos_fb->entry);
69 kfree(exynos_fb);
70 exynos_fb = NULL;
73 static int exynos_drm_fb_create_handle(struct drm_framebuffer *fb,
74 struct drm_file *file_priv,
75 unsigned int *handle)
77 struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
79 DRM_DEBUG_KMS("%s\n", __FILE__);
81 return drm_gem_handle_create(file_priv,
82 &exynos_fb->exynos_gem_obj->base, handle);
85 static int exynos_drm_fb_dirty(struct drm_framebuffer *fb,
86 struct drm_file *file_priv, unsigned flags,
87 unsigned color, struct drm_clip_rect *clips,
88 unsigned num_clips)
90 DRM_DEBUG_KMS("%s\n", __FILE__);
92 /* TODO */
94 return 0;
97 static struct drm_framebuffer_funcs exynos_drm_fb_funcs = {
98 .destroy = exynos_drm_fb_destroy,
99 .create_handle = exynos_drm_fb_create_handle,
100 .dirty = exynos_drm_fb_dirty,
103 static struct drm_framebuffer *
104 exynos_drm_fb_init(struct drm_file *file_priv, struct drm_device *dev,
105 struct drm_mode_fb_cmd *mode_cmd)
107 struct exynos_drm_fb *exynos_fb;
108 struct drm_framebuffer *fb;
109 struct exynos_drm_gem_obj *exynos_gem_obj = NULL;
110 struct drm_gem_object *obj;
111 unsigned int size;
112 int ret;
114 DRM_DEBUG_KMS("%s\n", __FILE__);
116 mode_cmd->pitch = max(mode_cmd->pitch,
117 mode_cmd->width * (mode_cmd->bpp >> 3));
119 DRM_LOG_KMS("drm fb create(%dx%d)\n",
120 mode_cmd->width, mode_cmd->height);
122 exynos_fb = kzalloc(sizeof(*exynos_fb), GFP_KERNEL);
123 if (!exynos_fb) {
124 DRM_ERROR("failed to allocate exynos drm framebuffer.\n");
125 return ERR_PTR(-ENOMEM);
128 fb = &exynos_fb->fb;
129 ret = drm_framebuffer_init(dev, fb, &exynos_drm_fb_funcs);
130 if (ret) {
131 DRM_ERROR("failed to initialize framebuffer.\n");
132 goto err_init;
135 DRM_LOG_KMS("create: fb id: %d\n", fb->base.id);
137 size = mode_cmd->pitch * mode_cmd->height;
140 * mode_cmd->handle could be NULL at booting time or
141 * with user request. if NULL, a new buffer or a gem object
142 * would be allocated.
144 if (!mode_cmd->handle) {
145 if (!file_priv) {
146 struct exynos_drm_buf_entry *entry;
149 * in case that file_priv is NULL, it allocates
150 * only buffer and this buffer would be used
151 * for default framebuffer.
153 entry = exynos_drm_buf_create(dev, size);
154 if (IS_ERR(entry)) {
155 ret = PTR_ERR(entry);
156 goto err_buffer;
159 exynos_fb->entry = entry;
161 DRM_LOG_KMS("default fb: paddr = 0x%lx, size = 0x%x\n",
162 (unsigned long)entry->paddr, size);
164 goto out;
165 } else {
166 exynos_gem_obj = exynos_drm_gem_create(file_priv, dev,
167 size,
168 &mode_cmd->handle);
169 if (IS_ERR(exynos_gem_obj)) {
170 ret = PTR_ERR(exynos_gem_obj);
171 goto err_buffer;
174 } else {
175 obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle);
176 if (!obj) {
177 DRM_ERROR("failed to lookup gem object.\n");
178 goto err_buffer;
181 exynos_gem_obj = to_exynos_gem_obj(obj);
183 drm_gem_object_unreference_unlocked(obj);
187 * if got a exynos_gem_obj from either a handle or
188 * a new creation then exynos_fb->exynos_gem_obj is NULL
189 * so that default framebuffer has no its own gem object,
190 * only its own buffer object.
192 exynos_fb->entry = exynos_gem_obj->entry;
194 DRM_LOG_KMS("paddr = 0x%lx, size = 0x%x, gem object = 0x%x\n",
195 (unsigned long)exynos_fb->entry->paddr, size,
196 (unsigned int)&exynos_gem_obj->base);
198 out:
199 exynos_fb->exynos_gem_obj = exynos_gem_obj;
201 drm_helper_mode_fill_fb_struct(fb, mode_cmd);
203 return fb;
205 err_buffer:
206 drm_framebuffer_cleanup(fb);
208 err_init:
209 kfree(exynos_fb);
211 return ERR_PTR(ret);
214 struct drm_framebuffer *exynos_drm_fb_create(struct drm_device *dev,
215 struct drm_file *file_priv,
216 struct drm_mode_fb_cmd *mode_cmd)
218 DRM_DEBUG_KMS("%s\n", __FILE__);
220 return exynos_drm_fb_init(file_priv, dev, mode_cmd);
223 struct exynos_drm_buf_entry *exynos_drm_fb_get_buf(struct drm_framebuffer *fb)
225 struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
226 struct exynos_drm_buf_entry *entry;
228 DRM_DEBUG_KMS("%s\n", __FILE__);
230 entry = exynos_fb->entry;
231 if (!entry)
232 return NULL;
234 DRM_DEBUG_KMS("vaddr = 0x%lx, paddr = 0x%lx\n",
235 (unsigned long)entry->vaddr,
236 (unsigned long)entry->paddr);
238 return entry;
241 static struct drm_mode_config_funcs exynos_drm_mode_config_funcs = {
242 .fb_create = exynos_drm_fb_create,
245 void exynos_drm_mode_config_init(struct drm_device *dev)
247 dev->mode_config.min_width = 0;
248 dev->mode_config.min_height = 0;
251 * set max width and height as default value(4096x4096).
252 * this value would be used to check framebuffer size limitation
253 * at drm_mode_addfb().
255 dev->mode_config.max_width = 4096;
256 dev->mode_config.max_height = 4096;
258 dev->mode_config.funcs = &exynos_drm_mode_config_funcs;
261 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
262 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
263 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
264 MODULE_DESCRIPTION("Samsung SoC DRM FB Driver");
265 MODULE_LICENSE("GPL");