2017-08-13 21:31:44 +08:00
|
|
|
/*
|
|
|
|
* drm gem framebuffer helper functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Noralf Trønnes
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/dma-buf.h>
|
|
|
|
#include <linux/dma-fence.h>
|
|
|
|
#include <linux/reservation.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
#include <drm/drm_atomic.h>
|
2018-09-05 21:57:11 +08:00
|
|
|
#include <drm/drm_atomic_uapi.h>
|
2019-01-15 12:36:39 +08:00
|
|
|
#include <drm/drm_damage_helper.h>
|
2017-08-13 21:31:44 +08:00
|
|
|
#include <drm/drm_fb_helper.h>
|
|
|
|
#include <drm/drm_fourcc.h>
|
|
|
|
#include <drm/drm_framebuffer.h>
|
|
|
|
#include <drm/drm_gem.h>
|
|
|
|
#include <drm/drm_gem_framebuffer_helper.h>
|
|
|
|
#include <drm/drm_modeset_helper.h>
|
2018-04-05 23:44:42 +08:00
|
|
|
#include <drm/drm_simple_kms_helper.h>
|
2017-08-13 21:31:44 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DOC: overview
|
|
|
|
*
|
|
|
|
* This library provides helpers for drivers that don't subclass
|
2017-09-22 23:47:44 +08:00
|
|
|
* &drm_framebuffer and use &drm_gem_object for their backing storage.
|
2017-08-13 21:31:44 +08:00
|
|
|
*
|
|
|
|
* Drivers without additional needs to validate framebuffers can simply use
|
2017-09-22 23:47:44 +08:00
|
|
|
* drm_gem_fb_create() and everything is wired up automatically. Other drivers
|
|
|
|
* can use all parts independently.
|
2017-08-13 21:31:44 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-09-22 23:47:44 +08:00
|
|
|
* drm_gem_fb_get_obj() - Get GEM object backing the framebuffer
|
|
|
|
* @fb: Framebuffer
|
|
|
|
* @plane: Plane index
|
2017-08-13 21:31:44 +08:00
|
|
|
*
|
2017-09-22 23:47:44 +08:00
|
|
|
* No additional reference is taken beyond the one that the &drm_frambuffer
|
|
|
|
* already holds.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Pointer to &drm_gem_object for the given framebuffer and plane index or NULL
|
|
|
|
* if it does not exist.
|
2017-08-13 21:31:44 +08:00
|
|
|
*/
|
|
|
|
struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
|
|
|
|
unsigned int plane)
|
|
|
|
{
|
|
|
|
if (plane >= 4)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return fb->obj[plane];
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(drm_gem_fb_get_obj);
|
|
|
|
|
|
|
|
static struct drm_framebuffer *
|
|
|
|
drm_gem_fb_alloc(struct drm_device *dev,
|
|
|
|
const struct drm_mode_fb_cmd2 *mode_cmd,
|
|
|
|
struct drm_gem_object **obj, unsigned int num_planes,
|
|
|
|
const struct drm_framebuffer_funcs *funcs)
|
|
|
|
{
|
|
|
|
struct drm_framebuffer *fb;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
fb = kzalloc(sizeof(*fb), GFP_KERNEL);
|
|
|
|
if (!fb)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
|
|
|
|
|
|
|
|
for (i = 0; i < num_planes; i++)
|
|
|
|
fb->obj[i] = obj[i];
|
|
|
|
|
|
|
|
ret = drm_framebuffer_init(dev, fb, funcs);
|
|
|
|
if (ret) {
|
|
|
|
DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n",
|
|
|
|
ret);
|
|
|
|
kfree(fb);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_gem_fb_destroy - Free GEM backed framebuffer
|
2017-09-22 23:47:44 +08:00
|
|
|
* @fb: Framebuffer
|
2017-08-13 21:31:44 +08:00
|
|
|
*
|
|
|
|
* Frees a GEM backed framebuffer with its backing buffer(s) and the structure
|
|
|
|
* itself. Drivers can use this as their &drm_framebuffer_funcs->destroy
|
|
|
|
* callback.
|
|
|
|
*/
|
|
|
|
void drm_gem_fb_destroy(struct drm_framebuffer *fb)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
drm_gem_object_put_unlocked(fb->obj[i]);
|
|
|
|
|
|
|
|
drm_framebuffer_cleanup(fb);
|
|
|
|
kfree(fb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_gem_fb_destroy);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_gem_fb_create_handle - Create handle for GEM backed framebuffer
|
2017-09-22 23:47:44 +08:00
|
|
|
* @fb: Framebuffer
|
|
|
|
* @file: DRM file to register the handle for
|
|
|
|
* @handle: Pointer to return the created handle
|
2017-08-13 21:31:44 +08:00
|
|
|
*
|
2017-09-22 23:47:44 +08:00
|
|
|
* This function creates a handle for the GEM object backing the framebuffer.
|
2017-08-13 21:31:44 +08:00
|
|
|
* Drivers can use this as their &drm_framebuffer_funcs->create_handle
|
2017-09-22 23:47:44 +08:00
|
|
|
* callback. The GETFB IOCTL calls into this callback.
|
2017-08-13 21:31:44 +08:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 on success or a negative error code on failure.
|
|
|
|
*/
|
|
|
|
int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,
|
|
|
|
unsigned int *handle)
|
|
|
|
{
|
|
|
|
return drm_gem_handle_create(file, fb->obj[0], handle);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_gem_fb_create_handle);
|
|
|
|
|
|
|
|
/**
|
2017-09-22 23:47:44 +08:00
|
|
|
* drm_gem_fb_create_with_funcs() - Helper function for the
|
2017-08-13 21:31:44 +08:00
|
|
|
* &drm_mode_config_funcs.fb_create
|
|
|
|
* callback
|
|
|
|
* @dev: DRM device
|
2017-09-22 23:47:44 +08:00
|
|
|
* @file: DRM file that holds the GEM handle(s) backing the framebuffer
|
|
|
|
* @mode_cmd: Metadata from the userspace framebuffer creation request
|
2017-08-13 21:31:44 +08:00
|
|
|
* @funcs: vtable to be used for the new framebuffer object
|
|
|
|
*
|
2019-01-15 12:36:39 +08:00
|
|
|
* This function can be used to set &drm_framebuffer_funcs for drivers that need
|
|
|
|
* custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to
|
|
|
|
* change &drm_framebuffer_funcs. The function does buffer size validation.
|
2017-09-22 23:47:44 +08:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Pointer to a &drm_framebuffer on success or an error pointer on failure.
|
2017-08-13 21:31:44 +08:00
|
|
|
*/
|
|
|
|
struct drm_framebuffer *
|
|
|
|
drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
|
|
|
|
const struct drm_mode_fb_cmd2 *mode_cmd,
|
|
|
|
const struct drm_framebuffer_funcs *funcs)
|
|
|
|
{
|
|
|
|
const struct drm_format_info *info;
|
|
|
|
struct drm_gem_object *objs[4];
|
|
|
|
struct drm_framebuffer *fb;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
info = drm_get_format_info(dev, mode_cmd);
|
|
|
|
if (!info)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
for (i = 0; i < info->num_planes; i++) {
|
|
|
|
unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
|
|
|
|
unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
|
|
|
|
unsigned int min_size;
|
|
|
|
|
|
|
|
objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]);
|
|
|
|
if (!objs[i]) {
|
2017-09-12 00:37:45 +08:00
|
|
|
DRM_DEBUG_KMS("Failed to lookup GEM object\n");
|
2017-08-13 21:31:44 +08:00
|
|
|
ret = -ENOENT;
|
|
|
|
goto err_gem_object_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
min_size = (height - 1) * mode_cmd->pitches[i]
|
drm/fourcc: Add char_per_block, block_w and block_h in drm_format_info
For some pixel formats .cpp structure in drm_format info it's not
enough to describe the peculiarities of the pixel layout, for example
tiled formats or packed formats at bit level.
What's implemented here is to add three new members to drm_format_info
that could describe such formats:
- char_per_block[3]
- block_w[3]
- block_h[3]
char_per_block will be put in a union alongside cpp, for transparent
compatibility with the existing format descriptions.
Regarding, block_w and block_h they are intended to be used through
their equivalent getters drm_format_info_block_width /
drm_format_info_block_height, the reason of the getters is to abstract
the fact that for normal formats block_w and block_h will be unset/0,
but the methods will be returning 1.
Additionally, convenience function drm_format_info_min_pitch had been
added that computes the minimum required pitch for a given pixel
format and buffer width.
Using that the following drm core functions had been updated to
generically handle both block and non-block formats:
- drm_fb_cma_get_gem_addr: for block formats it will just return the
beginning of the block.
- framebuffer_check: Use the newly added drm_format_info_min_pitch.
- drm_gem_fb_create_with_funcs: Use the newly added
drm_format_info_min_pitch.
- In places where is not expecting to handle block formats, like fbdev
helpers I just added some warnings in case the block width/height
are greater than 1.
Changes since v3:
- Add helper function for computing the minimum required pitch.
- Improve/cleanup documentation
Changes since v8:
- Fixed build on 32bits arm architectures, with:
- return DIV_ROUND_UP((u64)buffer_width * info->char_per_block[plane],
+ return DIV_ROUND_UP_ULL((u64)buffer_width * info->char_per_block[plane],
Reviewed-by: Brian Starkey <brian.starkey@arm.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Alexandru Gheorghe <alexandru-cosmin.gheorghe@arm.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20181101170055.5433-1-alexandru-cosmin.gheorghe@arm.com
2018-11-02 01:02:05 +08:00
|
|
|
+ drm_format_info_min_pitch(info, i, width)
|
2017-08-13 21:31:44 +08:00
|
|
|
+ mode_cmd->offsets[i];
|
|
|
|
|
|
|
|
if (objs[i]->size < min_size) {
|
|
|
|
drm_gem_object_put_unlocked(objs[i]);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err_gem_object_put;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fb = drm_gem_fb_alloc(dev, mode_cmd, objs, i, funcs);
|
|
|
|
if (IS_ERR(fb)) {
|
|
|
|
ret = PTR_ERR(fb);
|
|
|
|
goto err_gem_object_put;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fb;
|
|
|
|
|
|
|
|
err_gem_object_put:
|
|
|
|
for (i--; i >= 0; i--)
|
|
|
|
drm_gem_object_put_unlocked(objs[i]);
|
|
|
|
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_funcs);
|
|
|
|
|
|
|
|
static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
|
|
|
|
.destroy = drm_gem_fb_destroy,
|
|
|
|
.create_handle = drm_gem_fb_create_handle,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-09-22 23:47:44 +08:00
|
|
|
* drm_gem_fb_create() - Helper function for the
|
|
|
|
* &drm_mode_config_funcs.fb_create callback
|
2017-08-13 21:31:44 +08:00
|
|
|
* @dev: DRM device
|
2017-09-22 23:47:44 +08:00
|
|
|
* @file: DRM file that holds the GEM handle(s) backing the framebuffer
|
|
|
|
* @mode_cmd: Metadata from the userspace framebuffer creation request
|
|
|
|
*
|
|
|
|
* This function creates a new framebuffer object described by
|
|
|
|
* &drm_mode_fb_cmd2. This description includes handles for the buffer(s)
|
|
|
|
* backing the framebuffer.
|
2017-08-13 21:31:44 +08:00
|
|
|
*
|
|
|
|
* If your hardware has special alignment or pitch requirements these should be
|
|
|
|
* checked before calling this function. The function does buffer size
|
2019-01-15 12:36:39 +08:00
|
|
|
* validation. Use drm_gem_fb_create_with_dirty() if you need framebuffer
|
|
|
|
* flushing.
|
2017-09-22 23:47:44 +08:00
|
|
|
*
|
|
|
|
* Drivers can use this as their &drm_mode_config_funcs.fb_create callback.
|
|
|
|
* The ADDFB2 IOCTL calls into this callback.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Pointer to a &drm_framebuffer on success or an error pointer on failure.
|
2017-08-13 21:31:44 +08:00
|
|
|
*/
|
|
|
|
struct drm_framebuffer *
|
|
|
|
drm_gem_fb_create(struct drm_device *dev, struct drm_file *file,
|
|
|
|
const struct drm_mode_fb_cmd2 *mode_cmd)
|
|
|
|
{
|
|
|
|
return drm_gem_fb_create_with_funcs(dev, file, mode_cmd,
|
|
|
|
&drm_gem_fb_funcs);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(drm_gem_fb_create);
|
|
|
|
|
2019-01-15 12:36:39 +08:00
|
|
|
static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = {
|
|
|
|
.destroy = drm_gem_fb_destroy,
|
|
|
|
.create_handle = drm_gem_fb_create_handle,
|
|
|
|
.dirty = drm_atomic_helper_dirtyfb,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_gem_fb_create_with_dirty() - Helper function for the
|
|
|
|
* &drm_mode_config_funcs.fb_create callback
|
|
|
|
* @dev: DRM device
|
|
|
|
* @file: DRM file that holds the GEM handle(s) backing the framebuffer
|
|
|
|
* @mode_cmd: Metadata from the userspace framebuffer creation request
|
|
|
|
*
|
|
|
|
* This function creates a new framebuffer object described by
|
|
|
|
* &drm_mode_fb_cmd2. This description includes handles for the buffer(s)
|
|
|
|
* backing the framebuffer. drm_atomic_helper_dirtyfb() is used for the dirty
|
|
|
|
* callback giving framebuffer flushing through the atomic machinery. Use
|
|
|
|
* drm_gem_fb_create() if you don't need the dirty callback.
|
|
|
|
* The function does buffer size validation.
|
|
|
|
*
|
|
|
|
* Drivers should also call drm_plane_enable_fb_damage_clips() on all planes
|
|
|
|
* to enable userspace to use damage clips also with the ATOMIC IOCTL.
|
|
|
|
*
|
|
|
|
* Drivers can use this as their &drm_mode_config_funcs.fb_create callback.
|
|
|
|
* The ADDFB2 IOCTL calls into this callback.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Pointer to a &drm_framebuffer on success or an error pointer on failure.
|
|
|
|
*/
|
|
|
|
struct drm_framebuffer *
|
|
|
|
drm_gem_fb_create_with_dirty(struct drm_device *dev, struct drm_file *file,
|
|
|
|
const struct drm_mode_fb_cmd2 *mode_cmd)
|
|
|
|
{
|
|
|
|
return drm_gem_fb_create_with_funcs(dev, file, mode_cmd,
|
|
|
|
&drm_gem_fb_funcs_dirtyfb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_dirty);
|
|
|
|
|
2017-08-13 21:31:44 +08:00
|
|
|
/**
|
2017-09-22 23:47:44 +08:00
|
|
|
* drm_gem_fb_prepare_fb() - Prepare a GEM backed framebuffer
|
|
|
|
* @plane: Plane
|
|
|
|
* @state: Plane state the fence will be attached to
|
2017-08-13 21:31:44 +08:00
|
|
|
*
|
2017-09-22 23:47:44 +08:00
|
|
|
* This function prepares a GEM backed framebuffer for scanout by checking if
|
|
|
|
* the plane framebuffer has a DMA-BUF attached. If it does, it extracts the
|
|
|
|
* exclusive fence and attaches it to the plane state for the atomic helper to
|
|
|
|
* wait on. This function can be used as the &drm_plane_helper_funcs.prepare_fb
|
|
|
|
* callback.
|
2017-08-13 21:31:44 +08:00
|
|
|
*
|
|
|
|
* There is no need for &drm_plane_helper_funcs.cleanup_fb hook for simple
|
|
|
|
* gem based framebuffer drivers which have their buffers always pinned in
|
|
|
|
* memory.
|
2019-06-03 22:28:48 +08:00
|
|
|
*
|
|
|
|
* See drm_atomic_set_fence_for_plane() for a discussion of implicit and
|
|
|
|
* explicit fencing in atomic modeset updates.
|
2017-08-13 21:31:44 +08:00
|
|
|
*/
|
|
|
|
int drm_gem_fb_prepare_fb(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *state)
|
|
|
|
{
|
|
|
|
struct dma_buf *dma_buf;
|
|
|
|
struct dma_fence *fence;
|
|
|
|
|
drm/gem-fb-helper: Always do implicit sync
I've done a lot of history digging. The first signs of this
optimization was introduced in i915:
commit 25067bfc060d1a481584dcb51ef4b5680176ecb6
Author: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Date: Wed Sep 10 12:03:17 2014 -0300
drm/i915: pin sprite fb only if it changed
without much justification. Pinning already pinned stuff is real cheap
(it's just obj->pin_count++ really), and the missing implicit sync was
entirely forgotten about it seems. It's at least not mentioned
anywhere it the commit message.
It was also promptly removed shortly afterwards in
commit ea2c67bb4affa84080c616920f3899f123786e56
Author: Matt Roper <matthew.d.roper@intel.com>
Date: Tue Dec 23 10:41:52 2014 -0800
drm/i915: Move to atomic plane helpers (v9)
again without really mentioning the side-effect that plane updates
with the same fb now again obey implicit syncing.
Note that this only ever applied to the plane_update hook, all other
legacy entry points (set_base, page_flip) always obeyed implicit sync
in the drm/i915 driver.
The real source of this code here seems to be msm, copied to vc4, then
copied to tinydrm. I've also tried to dig around in all available msm
sources, but the corresponding check for fb != old_fb is present ever
since the initial merge in
commit cf3a7e4ce08e6876cdcb80390876647f28a7cf8f
Author: Rob Clark <robdclark@gmail.com>
Date: Sat Nov 8 13:21:06 2014 -0500
drm/msm: atomic core bits
The only older version I've found of msm atomic code predates the
atomic helpers, and so didn't even use any of this. It also does not
have a corresponding check (because it simply did no implicit sync at
all).
I've chatted with Rob on irc, and he didn't remember the reason for
this either.
Note we had epic amounts of fun with too much syncing against
_vblank_, especially around cursor updates. But I don't ever
discussing a need for less syncing against implicit fences.
Also note that explicit fencing allows you to sidetrack all of this,
at least for all the drivers correctly implemented using
drm_atomic_set_fence_for_plane().
Given that it seems to be an accident of history, and that big drivers
like i915 (and also nouveau it seems, I didn't follow the
amdgpu/radeon sync code to figure this out properly there) never have
done it, let's remove this.
Cc: Rob Clark <robdclark@gmail.com>
Cc: Matt Roper <matthew.d.roper@intel.com>
Cc: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Sean Paul <seanpaul@chromium.org>
Cc: David Airlie <airlied@linux.ie>
Cc: "Noralf Trønnes" <noralf@tronnes.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180405154449.23038-8-daniel.vetter@ffwll.ch
2018-04-05 23:44:47 +08:00
|
|
|
if (!state->fb)
|
2017-08-13 21:31:44 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
dma_buf = drm_gem_fb_get_obj(state->fb, 0)->dma_buf;
|
|
|
|
if (dma_buf) {
|
|
|
|
fence = reservation_object_get_excl_rcu(dma_buf->resv);
|
|
|
|
drm_atomic_set_fence_for_plane(state, fence);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(drm_gem_fb_prepare_fb);
|
|
|
|
|
2018-04-05 23:44:42 +08:00
|
|
|
/**
|
|
|
|
* drm_gem_fb_simple_display_pipe_prepare_fb - prepare_fb helper for
|
|
|
|
* &drm_simple_display_pipe
|
|
|
|
* @pipe: Simple display pipe
|
|
|
|
* @plane_state: Plane state
|
|
|
|
*
|
|
|
|
* This function uses drm_gem_fb_prepare_fb() to check if the plane FB has a
|
|
|
|
* &dma_buf attached, extracts the exclusive fence and attaches it to plane
|
|
|
|
* state for the atomic helper to wait on. Drivers can use this as their
|
|
|
|
* &drm_simple_display_pipe_funcs.prepare_fb callback.
|
2019-06-03 22:28:48 +08:00
|
|
|
*
|
|
|
|
* See drm_atomic_set_fence_for_plane() for a discussion of implicit and
|
|
|
|
* explicit fencing in atomic modeset updates.
|
2018-04-05 23:44:42 +08:00
|
|
|
*/
|
|
|
|
int drm_gem_fb_simple_display_pipe_prepare_fb(struct drm_simple_display_pipe *pipe,
|
|
|
|
struct drm_plane_state *plane_state)
|
|
|
|
{
|
|
|
|
return drm_gem_fb_prepare_fb(&pipe->plane, plane_state);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_gem_fb_simple_display_pipe_prepare_fb);
|
|
|
|
|
2017-08-13 21:31:44 +08:00
|
|
|
/**
|
2017-09-22 23:47:44 +08:00
|
|
|
* drm_gem_fbdev_fb_create - Create a GEM backed &drm_framebuffer for fbdev
|
|
|
|
* emulation
|
2017-08-13 21:31:44 +08:00
|
|
|
* @dev: DRM device
|
|
|
|
* @sizes: fbdev size description
|
2017-09-22 23:47:44 +08:00
|
|
|
* @pitch_align: Optional pitch alignment
|
2017-08-13 21:31:44 +08:00
|
|
|
* @obj: GEM object backing the framebuffer
|
2017-11-15 22:19:40 +08:00
|
|
|
* @funcs: Optional vtable to be used for the new framebuffer object when the
|
|
|
|
* dirty callback is needed.
|
2017-08-13 21:31:44 +08:00
|
|
|
*
|
2017-09-22 23:47:44 +08:00
|
|
|
* This function creates a framebuffer from a &drm_fb_helper_surface_size
|
|
|
|
* description for use in the &drm_fb_helper_funcs.fb_probe callback.
|
2017-08-13 21:31:44 +08:00
|
|
|
*
|
|
|
|
* Returns:
|
2017-09-22 23:47:44 +08:00
|
|
|
* Pointer to a &drm_framebuffer on success or an error pointer on failure.
|
2017-08-13 21:31:44 +08:00
|
|
|
*/
|
|
|
|
struct drm_framebuffer *
|
|
|
|
drm_gem_fbdev_fb_create(struct drm_device *dev,
|
|
|
|
struct drm_fb_helper_surface_size *sizes,
|
|
|
|
unsigned int pitch_align, struct drm_gem_object *obj,
|
|
|
|
const struct drm_framebuffer_funcs *funcs)
|
|
|
|
{
|
|
|
|
struct drm_mode_fb_cmd2 mode_cmd = { 0 };
|
|
|
|
|
|
|
|
mode_cmd.width = sizes->surface_width;
|
|
|
|
mode_cmd.height = sizes->surface_height;
|
|
|
|
mode_cmd.pitches[0] = sizes->surface_width *
|
|
|
|
DIV_ROUND_UP(sizes->surface_bpp, 8);
|
|
|
|
if (pitch_align)
|
|
|
|
mode_cmd.pitches[0] = roundup(mode_cmd.pitches[0],
|
|
|
|
pitch_align);
|
2018-09-21 21:47:00 +08:00
|
|
|
mode_cmd.pixel_format = drm_driver_legacy_fb_format(dev, sizes->surface_bpp,
|
|
|
|
sizes->surface_depth);
|
2017-08-13 21:31:44 +08:00
|
|
|
if (obj->size < mode_cmd.pitches[0] * mode_cmd.height)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2017-11-15 22:19:40 +08:00
|
|
|
if (!funcs)
|
|
|
|
funcs = &drm_gem_fb_funcs;
|
|
|
|
|
2017-08-13 21:31:44 +08:00
|
|
|
return drm_gem_fb_alloc(dev, &mode_cmd, &obj, 1, funcs);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_gem_fbdev_fb_create);
|