mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-29 23:53:32 +00:00
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>
This commit is contained in:
parent
7405f42c79
commit
c394c2b08e
1 changed files with 50 additions and 35 deletions
|
@ -41,6 +41,10 @@
|
||||||
|
|
||||||
#include "drm_crtc_internal.h"
|
#include "drm_crtc_internal.h"
|
||||||
|
|
||||||
|
static struct drm_framebuffer *add_framebuffer_internal(struct drm_device *dev,
|
||||||
|
struct drm_mode_fb_cmd2 *r,
|
||||||
|
struct drm_file *file_priv);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* drm_modeset_lock_all - take all modeset locks
|
* drm_modeset_lock_all - take all modeset locks
|
||||||
* @dev: drm device
|
* @dev: drm device
|
||||||
|
@ -2827,6 +2831,49 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct drm_framebuffer *add_framebuffer_internal(struct drm_device *dev,
|
||||||
|
struct drm_mode_fb_cmd2 *r,
|
||||||
|
struct drm_file *file_priv)
|
||||||
|
{
|
||||||
|
struct drm_mode_config *config = &dev->mode_config;
|
||||||
|
struct drm_framebuffer *fb;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (r->flags & ~DRM_MODE_FB_INTERLACED) {
|
||||||
|
DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags);
|
||||||
|
return ERR_PTR(-EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((config->min_width > r->width) || (r->width > config->max_width)) {
|
||||||
|
DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
|
||||||
|
r->width, config->min_width, config->max_width);
|
||||||
|
return ERR_PTR(-EINVAL);
|
||||||
|
}
|
||||||
|
if ((config->min_height > r->height) || (r->height > config->max_height)) {
|
||||||
|
DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
|
||||||
|
r->height, config->min_height, config->max_height);
|
||||||
|
return ERR_PTR(-EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = framebuffer_check(r);
|
||||||
|
if (ret)
|
||||||
|
return ERR_PTR(ret);
|
||||||
|
|
||||||
|
fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
|
||||||
|
if (IS_ERR(fb)) {
|
||||||
|
DRM_DEBUG_KMS("could not create framebuffer\n");
|
||||||
|
return fb;
|
||||||
|
}
|
||||||
|
|
||||||
|
mutex_lock(&file_priv->fbs_lock);
|
||||||
|
r->fb_id = fb->base.id;
|
||||||
|
list_add(&fb->filp_head, &file_priv->fbs);
|
||||||
|
DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
|
||||||
|
mutex_unlock(&file_priv->fbs_lock);
|
||||||
|
|
||||||
|
return fb;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* drm_mode_addfb2 - add an FB to the graphics configuration
|
* drm_mode_addfb2 - add an FB to the graphics configuration
|
||||||
* @dev: drm device for the ioctl
|
* @dev: drm device for the ioctl
|
||||||
|
@ -2845,48 +2892,16 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
|
||||||
int drm_mode_addfb2(struct drm_device *dev,
|
int drm_mode_addfb2(struct drm_device *dev,
|
||||||
void *data, struct drm_file *file_priv)
|
void *data, struct drm_file *file_priv)
|
||||||
{
|
{
|
||||||
struct drm_mode_fb_cmd2 *r = data;
|
|
||||||
struct drm_mode_config *config = &dev->mode_config;
|
|
||||||
struct drm_framebuffer *fb;
|
struct drm_framebuffer *fb;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!drm_core_check_feature(dev, DRIVER_MODESET))
|
if (!drm_core_check_feature(dev, DRIVER_MODESET))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (r->flags & ~DRM_MODE_FB_INTERLACED) {
|
fb = add_framebuffer_internal(dev, data, file_priv);
|
||||||
DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags);
|
if (IS_ERR(fb))
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((config->min_width > r->width) || (r->width > config->max_width)) {
|
|
||||||
DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
|
|
||||||
r->width, config->min_width, config->max_width);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
if ((config->min_height > r->height) || (r->height > config->max_height)) {
|
|
||||||
DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
|
|
||||||
r->height, config->min_height, config->max_height);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = framebuffer_check(r);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
|
|
||||||
if (IS_ERR(fb)) {
|
|
||||||
DRM_DEBUG_KMS("could not create framebuffer\n");
|
|
||||||
return PTR_ERR(fb);
|
return PTR_ERR(fb);
|
||||||
}
|
|
||||||
|
|
||||||
mutex_lock(&file_priv->fbs_lock);
|
return 0;
|
||||||
r->fb_id = fb->base.id;
|
|
||||||
list_add(&fb->filp_head, &file_priv->fbs);
|
|
||||||
DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
|
|
||||||
mutex_unlock(&file_priv->fbs_lock);
|
|
||||||
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue