]>
Commit | Line | Data |
---|---|---|
1c248b7d ID |
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" | |
7db3eba6 | 32 | #include "drm_fb_helper.h" |
1c248b7d | 33 | |
7db3eba6 | 34 | #include "exynos_drm_drv.h" |
1c248b7d ID |
35 | #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. | |
46 | * @entry: pointer to exynos drm buffer entry object. | |
47 | * - containing only the information to physically continuous memory | |
48 | * region allocated at default framebuffer creation. | |
49 | */ | |
50 | struct exynos_drm_fb { | |
51 | struct drm_framebuffer fb; | |
52 | struct exynos_drm_gem_obj *exynos_gem_obj; | |
53 | struct exynos_drm_buf_entry *entry; | |
54 | }; | |
55 | ||
56 | static void exynos_drm_fb_destroy(struct drm_framebuffer *fb) | |
57 | { | |
58 | struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb); | |
59 | ||
60 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
61 | ||
62 | drm_framebuffer_cleanup(fb); | |
63 | ||
64 | /* | |
65 | * default framebuffer has no gem object so | |
66 | * a buffer of the default framebuffer should be released at here. | |
67 | */ | |
68 | if (!exynos_fb->exynos_gem_obj && exynos_fb->entry) | |
69 | exynos_drm_buf_destroy(fb->dev, exynos_fb->entry); | |
70 | ||
71 | kfree(exynos_fb); | |
72 | exynos_fb = NULL; | |
73 | } | |
74 | ||
75 | static int exynos_drm_fb_create_handle(struct drm_framebuffer *fb, | |
76 | struct drm_file *file_priv, | |
77 | unsigned int *handle) | |
78 | { | |
79 | struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb); | |
80 | ||
81 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
82 | ||
83 | return drm_gem_handle_create(file_priv, | |
84 | &exynos_fb->exynos_gem_obj->base, handle); | |
85 | } | |
86 | ||
87 | static int exynos_drm_fb_dirty(struct drm_framebuffer *fb, | |
88 | struct drm_file *file_priv, unsigned flags, | |
89 | unsigned color, struct drm_clip_rect *clips, | |
90 | unsigned num_clips) | |
91 | { | |
92 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
93 | ||
94 | /* TODO */ | |
95 | ||
96 | return 0; | |
97 | } | |
98 | ||
99 | static struct drm_framebuffer_funcs exynos_drm_fb_funcs = { | |
100 | .destroy = exynos_drm_fb_destroy, | |
101 | .create_handle = exynos_drm_fb_create_handle, | |
102 | .dirty = exynos_drm_fb_dirty, | |
103 | }; | |
104 | ||
105 | static struct drm_framebuffer * | |
106 | exynos_drm_fb_init(struct drm_file *file_priv, struct drm_device *dev, | |
107 | struct drm_mode_fb_cmd *mode_cmd) | |
108 | { | |
109 | struct exynos_drm_fb *exynos_fb; | |
110 | struct drm_framebuffer *fb; | |
111 | struct exynos_drm_gem_obj *exynos_gem_obj = NULL; | |
112 | struct drm_gem_object *obj; | |
113 | unsigned int size; | |
114 | int ret; | |
115 | ||
116 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
117 | ||
118 | mode_cmd->pitch = max(mode_cmd->pitch, | |
119 | mode_cmd->width * (mode_cmd->bpp >> 3)); | |
120 | ||
121 | DRM_LOG_KMS("drm fb create(%dx%d)\n", | |
122 | mode_cmd->width, mode_cmd->height); | |
123 | ||
124 | exynos_fb = kzalloc(sizeof(*exynos_fb), GFP_KERNEL); | |
125 | if (!exynos_fb) { | |
126 | DRM_ERROR("failed to allocate exynos drm framebuffer.\n"); | |
127 | return ERR_PTR(-ENOMEM); | |
128 | } | |
129 | ||
130 | fb = &exynos_fb->fb; | |
131 | ret = drm_framebuffer_init(dev, fb, &exynos_drm_fb_funcs); | |
132 | if (ret) { | |
133 | DRM_ERROR("failed to initialize framebuffer.\n"); | |
134 | goto err_init; | |
135 | } | |
136 | ||
137 | DRM_LOG_KMS("create: fb id: %d\n", fb->base.id); | |
138 | ||
139 | size = mode_cmd->pitch * mode_cmd->height; | |
140 | ||
141 | /* | |
142 | * mode_cmd->handle could be NULL at booting time or | |
143 | * with user request. if NULL, a new buffer or a gem object | |
144 | * would be allocated. | |
145 | */ | |
146 | if (!mode_cmd->handle) { | |
147 | if (!file_priv) { | |
148 | struct exynos_drm_buf_entry *entry; | |
149 | ||
150 | /* | |
151 | * in case that file_priv is NULL, it allocates | |
152 | * only buffer and this buffer would be used | |
153 | * for default framebuffer. | |
154 | */ | |
155 | entry = exynos_drm_buf_create(dev, size); | |
156 | if (IS_ERR(entry)) { | |
157 | ret = PTR_ERR(entry); | |
158 | goto err_buffer; | |
159 | } | |
160 | ||
161 | exynos_fb->entry = entry; | |
162 | ||
163 | DRM_LOG_KMS("default fb: paddr = 0x%lx, size = 0x%x\n", | |
164 | (unsigned long)entry->paddr, size); | |
165 | ||
166 | goto out; | |
167 | } else { | |
f088d5a9 ID |
168 | exynos_gem_obj = exynos_drm_gem_create(dev, file_priv, |
169 | &mode_cmd->handle, | |
170 | size); | |
1c248b7d ID |
171 | if (IS_ERR(exynos_gem_obj)) { |
172 | ret = PTR_ERR(exynos_gem_obj); | |
173 | goto err_buffer; | |
174 | } | |
175 | } | |
176 | } else { | |
177 | obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle); | |
178 | if (!obj) { | |
179 | DRM_ERROR("failed to lookup gem object.\n"); | |
180 | goto err_buffer; | |
181 | } | |
182 | ||
183 | exynos_gem_obj = to_exynos_gem_obj(obj); | |
184 | ||
185 | drm_gem_object_unreference_unlocked(obj); | |
186 | } | |
187 | ||
188 | /* | |
189 | * if got a exynos_gem_obj from either a handle or | |
190 | * a new creation then exynos_fb->exynos_gem_obj is NULL | |
191 | * so that default framebuffer has no its own gem object, | |
192 | * only its own buffer object. | |
193 | */ | |
194 | exynos_fb->entry = exynos_gem_obj->entry; | |
195 | ||
196 | DRM_LOG_KMS("paddr = 0x%lx, size = 0x%x, gem object = 0x%x\n", | |
197 | (unsigned long)exynos_fb->entry->paddr, size, | |
198 | (unsigned int)&exynos_gem_obj->base); | |
199 | ||
200 | out: | |
201 | exynos_fb->exynos_gem_obj = exynos_gem_obj; | |
202 | ||
203 | drm_helper_mode_fill_fb_struct(fb, mode_cmd); | |
204 | ||
205 | return fb; | |
206 | ||
207 | err_buffer: | |
208 | drm_framebuffer_cleanup(fb); | |
209 | ||
210 | err_init: | |
211 | kfree(exynos_fb); | |
212 | ||
213 | return ERR_PTR(ret); | |
214 | } | |
215 | ||
216 | struct drm_framebuffer *exynos_drm_fb_create(struct drm_device *dev, | |
217 | struct drm_file *file_priv, | |
218 | struct drm_mode_fb_cmd *mode_cmd) | |
219 | { | |
220 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
221 | ||
222 | return exynos_drm_fb_init(file_priv, dev, mode_cmd); | |
223 | } | |
224 | ||
19c8b834 | 225 | struct exynos_drm_buf_entry *exynos_drm_fb_get_buf(struct drm_framebuffer *fb) |
1c248b7d ID |
226 | { |
227 | struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb); | |
228 | struct exynos_drm_buf_entry *entry; | |
1c248b7d ID |
229 | |
230 | DRM_DEBUG_KMS("%s\n", __FILE__); | |
231 | ||
1c248b7d | 232 | entry = exynos_fb->entry; |
19c8b834 ID |
233 | if (!entry) |
234 | return NULL; | |
1c248b7d | 235 | |
19c8b834 ID |
236 | DRM_DEBUG_KMS("vaddr = 0x%lx, paddr = 0x%lx\n", |
237 | (unsigned long)entry->vaddr, | |
238 | (unsigned long)entry->paddr); | |
1c248b7d | 239 | |
19c8b834 | 240 | return entry; |
1c248b7d ID |
241 | } |
242 | ||
7db3eba6 SWK |
243 | static void exynos_drm_output_poll_changed(struct drm_device *dev) |
244 | { | |
245 | struct exynos_drm_private *private = dev->dev_private; | |
246 | struct drm_fb_helper *fb_helper = private->fb_helper; | |
247 | ||
248 | if (fb_helper) | |
249 | drm_fb_helper_hotplug_event(fb_helper); | |
250 | } | |
251 | ||
1c248b7d ID |
252 | static struct drm_mode_config_funcs exynos_drm_mode_config_funcs = { |
253 | .fb_create = exynos_drm_fb_create, | |
7db3eba6 | 254 | .output_poll_changed = exynos_drm_output_poll_changed, |
1c248b7d ID |
255 | }; |
256 | ||
257 | void exynos_drm_mode_config_init(struct drm_device *dev) | |
258 | { | |
259 | dev->mode_config.min_width = 0; | |
260 | dev->mode_config.min_height = 0; | |
261 | ||
262 | /* | |
263 | * set max width and height as default value(4096x4096). | |
264 | * this value would be used to check framebuffer size limitation | |
265 | * at drm_mode_addfb(). | |
266 | */ | |
267 | dev->mode_config.max_width = 4096; | |
268 | dev->mode_config.max_height = 4096; | |
269 | ||
270 | dev->mode_config.funcs = &exynos_drm_mode_config_funcs; | |
271 | } | |
272 | ||
273 | MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>"); | |
274 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); | |
275 | MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>"); | |
276 | MODULE_DESCRIPTION("Samsung SoC DRM FB Driver"); | |
277 | MODULE_LICENSE("GPL"); |