blob: 8f36ae5e5d715c2a5f830416b57a5d59c48025cf [file] [log] [blame]
Inki Dae1c248b72011-10-04 19:19:01 +09001/* 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 Kim7db3eba2011-10-18 16:58:05 +090032#include "drm_fb_helper.h"
Inki Dae1c248b72011-10-04 19:19:01 +090033
Seung-Woo Kim7db3eba2011-10-18 16:58:05 +090034#include "exynos_drm_drv.h"
Inki Dae1c248b72011-10-04 19:19:01 +090035#include "exynos_drm_fb.h"
36#include "exynos_drm_buf.h"
37#include "exynos_drm_gem.h"
38
39#define to_exynos_fb(x) container_of(x, struct exynos_drm_fb, fb)
40
41/*
42 * exynos specific framebuffer structure.
43 *
44 * @fb: drm framebuffer obejct.
45 * @exynos_gem_obj: exynos specific gem object containing a gem object.
Inki Dae1c248b72011-10-04 19:19:01 +090046 */
47struct exynos_drm_fb {
48 struct drm_framebuffer fb;
49 struct exynos_drm_gem_obj *exynos_gem_obj;
Inki Dae1c248b72011-10-04 19:19:01 +090050};
51
52static void exynos_drm_fb_destroy(struct drm_framebuffer *fb)
53{
54 struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
55
56 DRM_DEBUG_KMS("%s\n", __FILE__);
57
58 drm_framebuffer_cleanup(fb);
59
Inki Dae1c248b72011-10-04 19:19:01 +090060 kfree(exynos_fb);
61 exynos_fb = NULL;
62}
63
64static int exynos_drm_fb_create_handle(struct drm_framebuffer *fb,
65 struct drm_file *file_priv,
66 unsigned int *handle)
67{
68 struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
69
70 DRM_DEBUG_KMS("%s\n", __FILE__);
71
72 return drm_gem_handle_create(file_priv,
73 &exynos_fb->exynos_gem_obj->base, handle);
74}
75
76static int exynos_drm_fb_dirty(struct drm_framebuffer *fb,
77 struct drm_file *file_priv, unsigned flags,
78 unsigned color, struct drm_clip_rect *clips,
79 unsigned num_clips)
80{
81 DRM_DEBUG_KMS("%s\n", __FILE__);
82
83 /* TODO */
84
85 return 0;
86}
87
88static struct drm_framebuffer_funcs exynos_drm_fb_funcs = {
89 .destroy = exynos_drm_fb_destroy,
90 .create_handle = exynos_drm_fb_create_handle,
91 .dirty = exynos_drm_fb_dirty,
92};
93
Joonyoung Shime1533c02011-12-13 14:46:57 +090094struct drm_framebuffer *
95exynos_drm_framebuffer_init(struct drm_device *dev,
96 struct drm_mode_fb_cmd2 *mode_cmd,
97 struct drm_gem_object *obj)
Inki Dae1c248b72011-10-04 19:19:01 +090098{
99 struct exynos_drm_fb *exynos_fb;
Inki Dae1c248b72011-10-04 19:19:01 +0900100 int ret;
101
Inki Dae1c248b72011-10-04 19:19:01 +0900102 exynos_fb = kzalloc(sizeof(*exynos_fb), GFP_KERNEL);
103 if (!exynos_fb) {
Joonyoung Shime1533c02011-12-13 14:46:57 +0900104 DRM_ERROR("failed to allocate exynos drm framebuffer\n");
Inki Dae1c248b72011-10-04 19:19:01 +0900105 return ERR_PTR(-ENOMEM);
106 }
107
Joonyoung Shime1533c02011-12-13 14:46:57 +0900108 ret = drm_framebuffer_init(dev, &exynos_fb->fb, &exynos_drm_fb_funcs);
Inki Dae1c248b72011-10-04 19:19:01 +0900109 if (ret) {
Joonyoung Shime1533c02011-12-13 14:46:57 +0900110 DRM_ERROR("failed to initialize framebuffer\n");
111 return ERR_PTR(ret);
Inki Dae1c248b72011-10-04 19:19:01 +0900112 }
113
Joonyoung Shime1533c02011-12-13 14:46:57 +0900114 drm_helper_mode_fill_fb_struct(&exynos_fb->fb, mode_cmd);
115 exynos_fb->exynos_gem_obj = to_exynos_gem_obj(obj);
Inki Dae1c248b72011-10-04 19:19:01 +0900116
Joonyoung Shime1533c02011-12-13 14:46:57 +0900117 return &exynos_fb->fb;
Inki Dae1c248b72011-10-04 19:19:01 +0900118}
119
Joonyoung Shime1533c02011-12-13 14:46:57 +0900120static struct drm_framebuffer *
121exynos_user_fb_create(struct drm_device *dev, struct drm_file *file_priv,
122 struct drm_mode_fb_cmd2 *mode_cmd)
Inki Dae1c248b72011-10-04 19:19:01 +0900123{
Joonyoung Shime1533c02011-12-13 14:46:57 +0900124 struct drm_gem_object *obj;
125
Inki Dae1c248b72011-10-04 19:19:01 +0900126 DRM_DEBUG_KMS("%s\n", __FILE__);
127
Joonyoung Shime1533c02011-12-13 14:46:57 +0900128 obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]);
129 if (!obj) {
130 DRM_ERROR("failed to lookup gem object\n");
131 return ERR_PTR(-ENOENT);
132 }
133
134 drm_gem_object_unreference_unlocked(obj);
135
136 return exynos_drm_framebuffer_init(dev, mode_cmd, obj);
Inki Dae1c248b72011-10-04 19:19:01 +0900137}
138
Inki Dae2c871122011-11-12 15:23:32 +0900139struct exynos_drm_gem_buf *exynos_drm_fb_get_buf(struct drm_framebuffer *fb)
Inki Dae1c248b72011-10-04 19:19:01 +0900140{
141 struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
Inki Dae2c871122011-11-12 15:23:32 +0900142 struct exynos_drm_gem_buf *buffer;
Inki Dae1c248b72011-10-04 19:19:01 +0900143
144 DRM_DEBUG_KMS("%s\n", __FILE__);
145
Joonyoung Shime1533c02011-12-13 14:46:57 +0900146 buffer = exynos_fb->exynos_gem_obj->buffer;
Inki Dae2c871122011-11-12 15:23:32 +0900147 if (!buffer)
Inki Dae19c8b832011-10-14 13:29:46 +0900148 return NULL;
Inki Dae1c248b72011-10-04 19:19:01 +0900149
Inki Dae2c871122011-11-12 15:23:32 +0900150 DRM_DEBUG_KMS("vaddr = 0x%lx, dma_addr = 0x%lx\n",
151 (unsigned long)buffer->kvaddr,
152 (unsigned long)buffer->dma_addr);
Inki Dae1c248b72011-10-04 19:19:01 +0900153
Inki Dae2c871122011-11-12 15:23:32 +0900154 return buffer;
Inki Dae1c248b72011-10-04 19:19:01 +0900155}
156
Seung-Woo Kim7db3eba2011-10-18 16:58:05 +0900157static void exynos_drm_output_poll_changed(struct drm_device *dev)
158{
159 struct exynos_drm_private *private = dev->dev_private;
160 struct drm_fb_helper *fb_helper = private->fb_helper;
161
162 if (fb_helper)
163 drm_fb_helper_hotplug_event(fb_helper);
164}
165
Inki Dae1c248b72011-10-04 19:19:01 +0900166static struct drm_mode_config_funcs exynos_drm_mode_config_funcs = {
Joonyoung Shime1533c02011-12-13 14:46:57 +0900167 .fb_create = exynos_user_fb_create,
Seung-Woo Kim7db3eba2011-10-18 16:58:05 +0900168 .output_poll_changed = exynos_drm_output_poll_changed,
Inki Dae1c248b72011-10-04 19:19:01 +0900169};
170
171void exynos_drm_mode_config_init(struct drm_device *dev)
172{
173 dev->mode_config.min_width = 0;
174 dev->mode_config.min_height = 0;
175
176 /*
177 * set max width and height as default value(4096x4096).
178 * this value would be used to check framebuffer size limitation
179 * at drm_mode_addfb().
180 */
181 dev->mode_config.max_width = 4096;
182 dev->mode_config.max_height = 4096;
183
184 dev->mode_config.funcs = &exynos_drm_mode_config_funcs;
185}
186
187MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
188MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
189MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
190MODULE_DESCRIPTION("Samsung SoC DRM FB Driver");
191MODULE_LICENSE("GPL");