Skip to content

Commit c394c2b

Browse files
mattropedanvet
authored andcommitted
drm: Refactor framebuffer creation to allow internal use (v2)
Refactor DRM framebuffer creation into a new function that returns a struct drm_framebuffer directly. The upcoming universal cursor support will want to create framebuffers internally to wrap cursor buffers, so we want to be able to share that framebuffer creation with the drm_mode_addfb2 ioctl handler. v2: Take struct drm_mode_fb_cmd2 parameter directly rather than void* Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Matt Roper <matthew.d.roper@intel.com> Reviewed-by: Pallavi G<pallavi.g@intel.com> Acked-by: Dave Airlie <airlied@linux.ie> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent 7405f42 commit c394c2b

1 file changed

Lines changed: 42 additions & 27 deletions

File tree

‎drivers/gpu/drm/drm_crtc.c‎

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141

4242
#include "drm_crtc_internal.h"
4343

44+
static struct drm_framebuffer *add_framebuffer_internal(struct drm_device *dev,
45+
struct drm_mode_fb_cmd2 *r,
46+
struct drm_file *file_priv);
47+
4448
/**
4549
* drm_modeset_lock_all - take all modeset locks
4650
* @dev: drm device
@@ -2827,56 +2831,38 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
28272831
return 0;
28282832
}
28292833

2830-
/**
2831-
* drm_mode_addfb2 - add an FB to the graphics configuration
2832-
* @dev: drm device for the ioctl
2833-
* @data: data pointer for the ioctl
2834-
* @file_priv: drm file for the ioctl call
2835-
*
2836-
* Add a new FB to the specified CRTC, given a user request with format. This is
2837-
* the 2nd version of the addfb ioctl, which supports multi-planar framebuffers
2838-
* and uses fourcc codes as pixel format specifiers.
2839-
*
2840-
* Called by the user via ioctl.
2841-
*
2842-
* Returns:
2843-
* Zero on success, errno on failure.
2844-
*/
2845-
int drm_mode_addfb2(struct drm_device *dev,
2846-
void *data, struct drm_file *file_priv)
2834+
static struct drm_framebuffer *add_framebuffer_internal(struct drm_device *dev,
2835+
struct drm_mode_fb_cmd2 *r,
2836+
struct drm_file *file_priv)
28472837
{
2848-
struct drm_mode_fb_cmd2 *r = data;
28492838
struct drm_mode_config *config = &dev->mode_config;
28502839
struct drm_framebuffer *fb;
28512840
int ret;
28522841

2853-
if (!drm_core_check_feature(dev, DRIVER_MODESET))
2854-
return -EINVAL;
2855-
28562842
if (r->flags & ~DRM_MODE_FB_INTERLACED) {
28572843
DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags);
2858-
return -EINVAL;
2844+
return ERR_PTR(-EINVAL);
28592845
}
28602846

28612847
if ((config->min_width > r->width) || (r->width > config->max_width)) {
28622848
DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
28632849
r->width, config->min_width, config->max_width);
2864-
return -EINVAL;
2850+
return ERR_PTR(-EINVAL);
28652851
}
28662852
if ((config->min_height > r->height) || (r->height > config->max_height)) {
28672853
DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
28682854
r->height, config->min_height, config->max_height);
2869-
return -EINVAL;
2855+
return ERR_PTR(-EINVAL);
28702856
}
28712857

28722858
ret = framebuffer_check(r);
28732859
if (ret)
2874-
return ret;
2860+
return ERR_PTR(ret);
28752861

28762862
fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
28772863
if (IS_ERR(fb)) {
28782864
DRM_DEBUG_KMS("could not create framebuffer\n");
2879-
return PTR_ERR(fb);
2865+
return fb;
28802866
}
28812867

28822868
mutex_lock(&file_priv->fbs_lock);
@@ -2885,8 +2871,37 @@ int drm_mode_addfb2(struct drm_device *dev,
28852871
DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
28862872
mutex_unlock(&file_priv->fbs_lock);
28872873

2874+
return fb;
2875+
}
28882876

2889-
return ret;
2877+
/**
2878+
* drm_mode_addfb2 - add an FB to the graphics configuration
2879+
* @dev: drm device for the ioctl
2880+
* @data: data pointer for the ioctl
2881+
* @file_priv: drm file for the ioctl call
2882+
*
2883+
* Add a new FB to the specified CRTC, given a user request with format. This is
2884+
* the 2nd version of the addfb ioctl, which supports multi-planar framebuffers
2885+
* and uses fourcc codes as pixel format specifiers.
2886+
*
2887+
* Called by the user via ioctl.
2888+
*
2889+
* Returns:
2890+
* Zero on success, errno on failure.
2891+
*/
2892+
int drm_mode_addfb2(struct drm_device *dev,
2893+
void *data, struct drm_file *file_priv)
2894+
{
2895+
struct drm_framebuffer *fb;
2896+
2897+
if (!drm_core_check_feature(dev, DRIVER_MODESET))
2898+
return -EINVAL;
2899+
2900+
fb = add_framebuffer_internal(dev, data, file_priv);
2901+
if (IS_ERR(fb))
2902+
return PTR_ERR(fb);
2903+
2904+
return 0;
28902905
}
28912906

28922907
/**

0 commit comments

Comments
 (0)