26 #include <linux/module.h>
53 for (i = 0; i < 4; i++) {
55 drm_gem_object_unreference_unlocked(&fb_cma->
obj[i]->base);
63 struct drm_file *file_priv,
unsigned int *
handle)
68 &fb_cma->
obj[0]->base, handle);
72 .destroy = drm_fb_cma_destroy,
73 .create_handle = drm_fb_cma_create_handle,
90 dev_err(dev->dev,
"Failed to initalize framebuffer: %d\n", ret);
98 fb_cma->
obj[i] = obj[i];
114 struct drm_gem_object *obj;
124 unsigned int width = mode_cmd->
width / (i ? hsub : 1);
125 unsigned int height = mode_cmd->
height / (i ? vsub : 1);
126 unsigned int min_size;
130 dev_err(dev->dev,
"Failed to lookup GEM object\n");
132 goto err_gem_object_unreference;
135 min_size = (height - 1) * mode_cmd->
pitches[i]
139 if (obj->size < min_size) {
140 drm_gem_object_unreference_unlocked(obj);
142 goto err_gem_object_unreference;
144 objs[
i] = to_drm_gem_cma_obj(obj);
147 fb_cma = drm_fb_cma_alloc(dev, mode_cmd, objs, i);
148 if (IS_ERR(fb_cma)) {
149 ret = PTR_ERR(fb_cma);
150 goto err_gem_object_unreference;
155 err_gem_object_unreference:
156 for (i--; i >= 0; i--)
157 drm_gem_object_unreference_unlocked(&objs[i]->
base);
183 static struct fb_ops drm_fbdev_cma_ops = {
195 static int drm_fbdev_cma_create(
struct drm_fb_helper *helper,
203 unsigned int bytes_per_pixel;
209 DRM_DEBUG_KMS(
"surface width(%d), height(%d) and bpp(%d)\n",
228 dev_err(dev->dev,
"Failed to allocate framebuffer info.\n");
230 goto err_drm_gem_cma_free_object;
233 fbdev_cma->
fb = drm_fb_cma_alloc(dev, &mode_cmd, &obj, 1);
234 if (IS_ERR(fbdev_cma->
fb)) {
235 dev_err(dev->dev,
"Failed to allocate DRM framebuffer.\n");
236 ret = PTR_ERR(fbdev_cma->
fb);
237 goto err_framebuffer_release;
240 fb = &fbdev_cma->
fb->fb;
246 fbi->
fbops = &drm_fbdev_cma_ops;
250 dev_err(dev->dev,
"Failed to allocate color map.\n");
251 goto err_drm_fb_cma_destroy;
257 offset = fbi->
var.xoffset * bytes_per_pixel;
268 err_drm_fb_cma_destroy:
269 drm_fb_cma_destroy(fb);
270 err_framebuffer_release:
272 err_drm_gem_cma_free_object:
283 ret = drm_fbdev_cma_create(helper, sizes);
293 .fb_probe = drm_fbdev_cma_probe,
306 unsigned int preferred_bpp,
unsigned int num_crtc,
307 unsigned int max_conn_count)
313 fbdev_cma = kzalloc(
sizeof(*fbdev_cma),
GFP_KERNEL);
315 dev_err(dev->dev,
"Failed to allocate drm fbdev.\n");
319 fbdev_cma->
fb_helper.funcs = &drm_fb_cma_helper_funcs;
324 dev_err(dev->dev,
"Failed to initialize drm fb helper.\n");
330 dev_err(dev->dev,
"Failed to add connectors.\n");
331 goto err_drm_fb_helper_fini;
337 dev_err(dev->dev,
"Failed to set inital hw configuration.\n");
338 goto err_drm_fb_helper_fini;
343 err_drm_fb_helper_fini:
365 DRM_DEBUG_KMS(
"failed unregister_framebuffer()\n");
374 drm_fb_cma_destroy(&fbdev_cma->
fb->fb);