]>
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 | * | |
d81aecb5 ID |
9 | * This program is free software; you can redistribute it and/or modify it |
10 | * under the terms of the GNU General Public License as published by the | |
11 | * Free Software Foundation; either version 2 of the License, or (at your | |
12 | * option) any later version. | |
1c248b7d ID |
13 | */ |
14 | ||
760285e7 DH |
15 | #include <drm/drmP.h> |
16 | #include <drm/drm_crtc.h> | |
17 | #include <drm/drm_crtc_helper.h> | |
18 | #include <drm/drm_fb_helper.h> | |
d6562a29 | 19 | #include <drm/drm_atomic.h> |
910874a8 | 20 | #include <drm/drm_atomic_helper.h> |
0519f9a1 | 21 | #include <uapi/drm/exynos_drm.h> |
1c248b7d | 22 | |
7db3eba6 | 23 | #include "exynos_drm_drv.h" |
1c248b7d | 24 | #include "exynos_drm_fb.h" |
25928a39 | 25 | #include "exynos_drm_fbdev.h" |
0519f9a1 | 26 | #include "exynos_drm_iommu.h" |
080be03d | 27 | #include "exynos_drm_crtc.h" |
1c248b7d ID |
28 | |
29 | #define to_exynos_fb(x) container_of(x, struct exynos_drm_fb, fb) | |
30 | ||
31 | /* | |
32 | * exynos specific framebuffer structure. | |
33 | * | |
34 | * @fb: drm framebuffer obejct. | |
813fd67b | 35 | * @exynos_gem: array of exynos specific gem object containing a gem object. |
1c248b7d ID |
36 | */ |
37 | struct exynos_drm_fb { | |
813fd67b JS |
38 | struct drm_framebuffer fb; |
39 | struct exynos_drm_gem *exynos_gem[MAX_FB_BUFFER]; | |
1c248b7d ID |
40 | }; |
41 | ||
0519f9a1 | 42 | static int check_fb_gem_memory_type(struct drm_device *drm_dev, |
813fd67b | 43 | struct exynos_drm_gem *exynos_gem) |
0519f9a1 ID |
44 | { |
45 | unsigned int flags; | |
46 | ||
47 | /* | |
48 | * if exynos drm driver supports iommu then framebuffer can use | |
49 | * all the buffer types. | |
50 | */ | |
51 | if (is_drm_iommu_supported(drm_dev)) | |
52 | return 0; | |
53 | ||
813fd67b | 54 | flags = exynos_gem->flags; |
0519f9a1 ID |
55 | |
56 | /* | |
57 | * without iommu support, not support physically non-continuous memory | |
58 | * for framebuffer. | |
59 | */ | |
60 | if (IS_NONCONTIG_BUFFER(flags)) { | |
61 | DRM_ERROR("cannot use this gem memory type for fb.\n"); | |
62 | return -EINVAL; | |
63 | } | |
64 | ||
65 | return 0; | |
66 | } | |
67 | ||
1c248b7d ID |
68 | static void exynos_drm_fb_destroy(struct drm_framebuffer *fb) |
69 | { | |
70 | struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb); | |
07b6835f | 71 | unsigned int i; |
1c248b7d | 72 | |
1daa892c | 73 | /* make sure that overlay data are updated before relesing fb. */ |
080be03d | 74 | exynos_drm_crtc_complete_scanout(fb); |
1daa892c | 75 | |
1c248b7d ID |
76 | drm_framebuffer_cleanup(fb); |
77 | ||
813fd67b | 78 | for (i = 0; i < ARRAY_SIZE(exynos_fb->exynos_gem); i++) { |
07b6835f LP |
79 | struct drm_gem_object *obj; |
80 | ||
813fd67b | 81 | if (exynos_fb->exynos_gem[i] == NULL) |
07b6835f LP |
82 | continue; |
83 | ||
813fd67b | 84 | obj = &exynos_fb->exynos_gem[i]->base; |
07b6835f LP |
85 | drm_gem_object_unreference_unlocked(obj); |
86 | } | |
87 | ||
1c248b7d ID |
88 | kfree(exynos_fb); |
89 | exynos_fb = NULL; | |
90 | } | |
91 | ||
92 | static int exynos_drm_fb_create_handle(struct drm_framebuffer *fb, | |
93 | struct drm_file *file_priv, | |
94 | unsigned int *handle) | |
95 | { | |
96 | struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb); | |
97 | ||
1c248b7d | 98 | return drm_gem_handle_create(file_priv, |
813fd67b | 99 | &exynos_fb->exynos_gem[0]->base, handle); |
1c248b7d ID |
100 | } |
101 | ||
102 | static int exynos_drm_fb_dirty(struct drm_framebuffer *fb, | |
103 | struct drm_file *file_priv, unsigned flags, | |
104 | unsigned color, struct drm_clip_rect *clips, | |
105 | unsigned num_clips) | |
106 | { | |
1c248b7d ID |
107 | /* TODO */ |
108 | ||
109 | return 0; | |
110 | } | |
111 | ||
112 | static struct drm_framebuffer_funcs exynos_drm_fb_funcs = { | |
113 | .destroy = exynos_drm_fb_destroy, | |
114 | .create_handle = exynos_drm_fb_create_handle, | |
115 | .dirty = exynos_drm_fb_dirty, | |
116 | }; | |
117 | ||
e1533c08 JS |
118 | struct drm_framebuffer * |
119 | exynos_drm_framebuffer_init(struct drm_device *dev, | |
120 | struct drm_mode_fb_cmd2 *mode_cmd, | |
813fd67b | 121 | struct exynos_drm_gem **exynos_gem, |
d56125af | 122 | int count) |
1c248b7d ID |
123 | { |
124 | struct exynos_drm_fb *exynos_fb; | |
d56125af | 125 | int i; |
1c248b7d ID |
126 | int ret; |
127 | ||
1c248b7d | 128 | exynos_fb = kzalloc(sizeof(*exynos_fb), GFP_KERNEL); |
38bb5253 | 129 | if (!exynos_fb) |
1c248b7d | 130 | return ERR_PTR(-ENOMEM); |
1c248b7d | 131 | |
d56125af | 132 | for (i = 0; i < count; i++) { |
813fd67b | 133 | ret = check_fb_gem_memory_type(dev, exynos_gem[i]); |
d56125af JS |
134 | if (ret < 0) |
135 | goto err; | |
136 | ||
813fd67b | 137 | exynos_fb->exynos_gem[i] = exynos_gem[i]; |
d56125af JS |
138 | } |
139 | ||
140 | drm_helper_mode_fill_fb_struct(&exynos_fb->fb, mode_cmd); | |
94e30d93 | 141 | |
e1533c08 | 142 | ret = drm_framebuffer_init(dev, &exynos_fb->fb, &exynos_drm_fb_funcs); |
d56125af | 143 | if (ret < 0) { |
e1533c08 | 144 | DRM_ERROR("failed to initialize framebuffer\n"); |
d56125af | 145 | goto err; |
1c248b7d ID |
146 | } |
147 | ||
e1533c08 | 148 | return &exynos_fb->fb; |
d56125af JS |
149 | |
150 | err: | |
151 | kfree(exynos_fb); | |
152 | return ERR_PTR(ret); | |
1c248b7d ID |
153 | } |
154 | ||
e1533c08 JS |
155 | static struct drm_framebuffer * |
156 | exynos_user_fb_create(struct drm_device *dev, struct drm_file *file_priv, | |
157 | struct drm_mode_fb_cmd2 *mode_cmd) | |
1c248b7d | 158 | { |
813fd67b | 159 | struct exynos_drm_gem *exynos_gem[MAX_FB_BUFFER]; |
e1533c08 | 160 | struct drm_gem_object *obj; |
8d31758e JS |
161 | struct drm_framebuffer *fb; |
162 | int i; | |
163 | int ret; | |
229d3534 | 164 | |
8d31758e | 165 | for (i = 0; i < drm_format_num_planes(mode_cmd->pixel_format); i++) { |
229d3534 | 166 | obj = drm_gem_object_lookup(dev, file_priv, |
8d31758e | 167 | mode_cmd->handles[i]); |
229d3534 SWK |
168 | if (!obj) { |
169 | DRM_ERROR("failed to lookup gem object\n"); | |
979c0c7e | 170 | ret = -ENOENT; |
dcbb85a1 | 171 | goto err; |
229d3534 SWK |
172 | } |
173 | ||
813fd67b | 174 | exynos_gem[i] = to_exynos_gem(obj); |
229d3534 SWK |
175 | } |
176 | ||
813fd67b | 177 | fb = exynos_drm_framebuffer_init(dev, mode_cmd, exynos_gem, i); |
8d31758e JS |
178 | if (IS_ERR(fb)) { |
179 | ret = PTR_ERR(fb); | |
dcbb85a1 | 180 | goto err; |
f2c0095a DV |
181 | } |
182 | ||
8d31758e | 183 | return fb; |
979c0c7e | 184 | |
dcbb85a1 | 185 | err: |
8d31758e | 186 | while (i--) |
813fd67b | 187 | drm_gem_object_unreference_unlocked(&exynos_gem[i]->base); |
979c0c7e | 188 | |
979c0c7e | 189 | return ERR_PTR(ret); |
1c248b7d ID |
190 | } |
191 | ||
813fd67b | 192 | struct exynos_drm_gem *exynos_drm_fb_gem(struct drm_framebuffer *fb, int index) |
1c248b7d ID |
193 | { |
194 | struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb); | |
813fd67b | 195 | struct exynos_drm_gem *exynos_gem; |
1c248b7d | 196 | |
229d3534 SWK |
197 | if (index >= MAX_FB_BUFFER) |
198 | return NULL; | |
199 | ||
813fd67b JS |
200 | exynos_gem = exynos_fb->exynos_gem[index]; |
201 | if (!exynos_gem) | |
19c8b834 | 202 | return NULL; |
1c248b7d | 203 | |
813fd67b | 204 | DRM_DEBUG_KMS("dma_addr: 0x%lx\n", (unsigned long)exynos_gem->dma_addr); |
1c248b7d | 205 | |
813fd67b | 206 | return exynos_gem; |
1c248b7d ID |
207 | } |
208 | ||
7db3eba6 SWK |
209 | static void exynos_drm_output_poll_changed(struct drm_device *dev) |
210 | { | |
211 | struct exynos_drm_private *private = dev->dev_private; | |
212 | struct drm_fb_helper *fb_helper = private->fb_helper; | |
213 | ||
214 | if (fb_helper) | |
215 | drm_fb_helper_hotplug_event(fb_helper); | |
25928a39 AH |
216 | else |
217 | exynos_drm_fbdev_init(dev); | |
7db3eba6 SWK |
218 | } |
219 | ||
e6ecefaa | 220 | static const struct drm_mode_config_funcs exynos_drm_mode_config_funcs = { |
e1533c08 | 221 | .fb_create = exynos_user_fb_create, |
7db3eba6 | 222 | .output_poll_changed = exynos_drm_output_poll_changed, |
910874a8 | 223 | .atomic_check = drm_atomic_helper_check, |
9d5ab6a0 | 224 | .atomic_commit = exynos_atomic_commit, |
1c248b7d ID |
225 | }; |
226 | ||
227 | void exynos_drm_mode_config_init(struct drm_device *dev) | |
228 | { | |
229 | dev->mode_config.min_width = 0; | |
230 | dev->mode_config.min_height = 0; | |
231 | ||
232 | /* | |
233 | * set max width and height as default value(4096x4096). | |
234 | * this value would be used to check framebuffer size limitation | |
235 | * at drm_mode_addfb(). | |
236 | */ | |
237 | dev->mode_config.max_width = 4096; | |
238 | dev->mode_config.max_height = 4096; | |
239 | ||
240 | dev->mode_config.funcs = &exynos_drm_mode_config_funcs; | |
241 | } |