2019-06-04 11:11:33 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-11-16 01:28:22 +04:00
|
|
|
/*
|
2013-03-22 18:34:08 +04:00
|
|
|
* Copyright (C) 2012-2013 Avionic Design GmbH
|
2012-11-16 01:28:22 +04:00
|
|
|
* Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
|
|
|
|
*
|
2013-03-22 18:34:08 +04:00
|
|
|
* Based on the KMS/FB CMA helpers
|
|
|
|
* Copyright (C) 2012 Analog Device Inc.
|
2012-11-16 01:28:22 +04:00
|
|
|
*/
|
|
|
|
|
2015-08-11 14:11:49 +03:00
|
|
|
#include <linux/console.h>
|
|
|
|
|
2012-11-16 01:28:22 +04:00
|
|
|
#include "drm.h"
|
2013-03-22 18:34:08 +04:00
|
|
|
#include "gem.h"
|
2018-03-30 17:11:26 +03:00
|
|
|
#include <drm/drm_gem_framebuffer_helper.h>
|
2019-01-18 00:03:34 +03:00
|
|
|
#include <drm/drm_modeset_helper.h>
|
2013-03-22 18:34:08 +04:00
|
|
|
|
2015-10-27 11:10:59 +03:00
|
|
|
#ifdef CONFIG_DRM_FBDEV_EMULATION
|
2013-03-22 18:34:08 +04:00
|
|
|
static inline struct tegra_fbdev *to_tegra_fbdev(struct drm_fb_helper *helper)
|
|
|
|
{
|
|
|
|
return container_of(helper, struct tegra_fbdev, base);
|
|
|
|
}
|
2013-10-31 16:28:50 +04:00
|
|
|
#endif
|
2013-03-22 18:34:08 +04:00
|
|
|
|
|
|
|
struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
|
|
|
|
unsigned int index)
|
|
|
|
{
|
2018-03-30 17:11:26 +03:00
|
|
|
return to_tegra_bo(drm_gem_fb_get_obj(framebuffer, index));
|
2013-03-22 18:34:08 +04:00
|
|
|
}
|
|
|
|
|
2013-10-07 11:47:58 +04:00
|
|
|
bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer)
|
|
|
|
{
|
2018-03-30 17:11:26 +03:00
|
|
|
struct tegra_bo *bo = tegra_fb_get_plane(framebuffer, 0);
|
2013-10-07 11:47:58 +04:00
|
|
|
|
2018-03-30 17:11:26 +03:00
|
|
|
if (bo->flags & TEGRA_BO_BOTTOM_UP)
|
2013-10-07 11:47:58 +04:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-03 16:48:12 +04:00
|
|
|
int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
|
|
|
|
struct tegra_bo_tiling *tiling)
|
2013-10-05 00:34:01 +04:00
|
|
|
{
|
2018-03-30 17:11:26 +03:00
|
|
|
uint64_t modifier = framebuffer->modifier;
|
2016-11-08 10:50:42 +03:00
|
|
|
|
drm/tegra: Sanitize format modifiers
The existing format modifier definitions were merged prematurely, and
recent work has unveiled that the definitions are suboptimal in several
ways:
- The format specifiers, except for one, are not Tegra specific, but
the names don't reflect that.
- The number space is split into two, reserving 32 bits for some
"parameter" which most of the modifiers are not going to have.
- Symbolic names for the modifiers are not using the standard
DRM_FORMAT_MOD_* prefix, which makes them awkward to use.
- The vendor prefix NV is somewhat ambiguous.
Fortunately, nobody's started using these modifiers, so we can still fix
the above issues. Do so by using the standard prefix. Also, remove TEGRA
from the name of those modifiers that exist on NVIDIA GPUs as well. In
case of the block linear modifiers, make the "parameter" smaller (4
bits, though only 6 values are valid) and don't let that leak into any
of the other modifiers.
Finally, also use the more canonical NVIDIA instead of the ambiguous NV
prefix.
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Thierry Reding <treding@nvidia.com>
2017-10-12 17:39:20 +03:00
|
|
|
switch (modifier) {
|
2018-03-15 18:45:45 +03:00
|
|
|
case DRM_FORMAT_MOD_LINEAR:
|
|
|
|
tiling->mode = TEGRA_BO_TILING_MODE_PITCH;
|
|
|
|
tiling->value = 0;
|
|
|
|
break;
|
|
|
|
|
drm/tegra: Sanitize format modifiers
The existing format modifier definitions were merged prematurely, and
recent work has unveiled that the definitions are suboptimal in several
ways:
- The format specifiers, except for one, are not Tegra specific, but
the names don't reflect that.
- The number space is split into two, reserving 32 bits for some
"parameter" which most of the modifiers are not going to have.
- Symbolic names for the modifiers are not using the standard
DRM_FORMAT_MOD_* prefix, which makes them awkward to use.
- The vendor prefix NV is somewhat ambiguous.
Fortunately, nobody's started using these modifiers, so we can still fix
the above issues. Do so by using the standard prefix. Also, remove TEGRA
from the name of those modifiers that exist on NVIDIA GPUs as well. In
case of the block linear modifiers, make the "parameter" smaller (4
bits, though only 6 values are valid) and don't let that leak into any
of the other modifiers.
Finally, also use the more canonical NVIDIA instead of the ambiguous NV
prefix.
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Thierry Reding <treding@nvidia.com>
2017-10-12 17:39:20 +03:00
|
|
|
case DRM_FORMAT_MOD_NVIDIA_TEGRA_TILED:
|
2016-11-08 10:50:42 +03:00
|
|
|
tiling->mode = TEGRA_BO_TILING_MODE_TILED;
|
|
|
|
tiling->value = 0;
|
|
|
|
break;
|
|
|
|
|
drm/tegra: Sanitize format modifiers
The existing format modifier definitions were merged prematurely, and
recent work has unveiled that the definitions are suboptimal in several
ways:
- The format specifiers, except for one, are not Tegra specific, but
the names don't reflect that.
- The number space is split into two, reserving 32 bits for some
"parameter" which most of the modifiers are not going to have.
- Symbolic names for the modifiers are not using the standard
DRM_FORMAT_MOD_* prefix, which makes them awkward to use.
- The vendor prefix NV is somewhat ambiguous.
Fortunately, nobody's started using these modifiers, so we can still fix
the above issues. Do so by using the standard prefix. Also, remove TEGRA
from the name of those modifiers that exist on NVIDIA GPUs as well. In
case of the block linear modifiers, make the "parameter" smaller (4
bits, though only 6 values are valid) and don't let that leak into any
of the other modifiers.
Finally, also use the more canonical NVIDIA instead of the ambiguous NV
prefix.
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Thierry Reding <treding@nvidia.com>
2017-10-12 17:39:20 +03:00
|
|
|
case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(0):
|
2016-11-08 10:50:42 +03:00
|
|
|
tiling->mode = TEGRA_BO_TILING_MODE_BLOCK;
|
drm/tegra: Sanitize format modifiers
The existing format modifier definitions were merged prematurely, and
recent work has unveiled that the definitions are suboptimal in several
ways:
- The format specifiers, except for one, are not Tegra specific, but
the names don't reflect that.
- The number space is split into two, reserving 32 bits for some
"parameter" which most of the modifiers are not going to have.
- Symbolic names for the modifiers are not using the standard
DRM_FORMAT_MOD_* prefix, which makes them awkward to use.
- The vendor prefix NV is somewhat ambiguous.
Fortunately, nobody's started using these modifiers, so we can still fix
the above issues. Do so by using the standard prefix. Also, remove TEGRA
from the name of those modifiers that exist on NVIDIA GPUs as well. In
case of the block linear modifiers, make the "parameter" smaller (4
bits, though only 6 values are valid) and don't let that leak into any
of the other modifiers.
Finally, also use the more canonical NVIDIA instead of the ambiguous NV
prefix.
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Thierry Reding <treding@nvidia.com>
2017-10-12 17:39:20 +03:00
|
|
|
tiling->value = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(1):
|
|
|
|
tiling->mode = TEGRA_BO_TILING_MODE_BLOCK;
|
|
|
|
tiling->value = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(2):
|
|
|
|
tiling->mode = TEGRA_BO_TILING_MODE_BLOCK;
|
|
|
|
tiling->value = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(3):
|
|
|
|
tiling->mode = TEGRA_BO_TILING_MODE_BLOCK;
|
|
|
|
tiling->value = 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(4):
|
|
|
|
tiling->mode = TEGRA_BO_TILING_MODE_BLOCK;
|
|
|
|
tiling->value = 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRM_FORMAT_MOD_NVIDIA_16BX2_BLOCK(5):
|
|
|
|
tiling->mode = TEGRA_BO_TILING_MODE_BLOCK;
|
|
|
|
tiling->value = 5;
|
2016-11-08 10:50:42 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-03-15 18:45:45 +03:00
|
|
|
return -EINVAL;
|
2016-11-08 10:50:42 +03:00
|
|
|
}
|
2013-10-05 00:34:01 +04:00
|
|
|
|
2014-06-03 16:48:12 +04:00
|
|
|
return 0;
|
2013-10-05 00:34:01 +04:00
|
|
|
}
|
|
|
|
|
2015-12-15 14:21:13 +03:00
|
|
|
static const struct drm_framebuffer_funcs tegra_fb_funcs = {
|
2018-03-30 17:11:29 +03:00
|
|
|
.destroy = drm_gem_fb_destroy,
|
2018-03-30 17:11:26 +03:00
|
|
|
.create_handle = drm_gem_fb_create_handle,
|
2013-03-22 18:34:08 +04:00
|
|
|
};
|
|
|
|
|
2018-03-30 17:11:27 +03:00
|
|
|
static struct drm_framebuffer *tegra_fb_alloc(struct drm_device *drm,
|
|
|
|
const struct drm_mode_fb_cmd2 *mode_cmd,
|
|
|
|
struct tegra_bo **planes,
|
|
|
|
unsigned int num_planes)
|
2013-03-22 18:34:08 +04:00
|
|
|
{
|
2018-03-30 17:11:27 +03:00
|
|
|
struct drm_framebuffer *fb;
|
2013-03-22 18:34:08 +04:00
|
|
|
unsigned int i;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
fb = kzalloc(sizeof(*fb), GFP_KERNEL);
|
|
|
|
if (!fb)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2018-03-30 17:11:27 +03:00
|
|
|
drm_helper_mode_fill_fb_struct(drm, fb, mode_cmd);
|
2013-03-22 18:34:08 +04:00
|
|
|
|
2018-03-30 17:11:27 +03:00
|
|
|
for (i = 0; i < fb->format->num_planes; i++)
|
|
|
|
fb->obj[i] = &planes[i]->gem;
|
2013-03-22 18:34:08 +04:00
|
|
|
|
2018-03-30 17:11:27 +03:00
|
|
|
err = drm_framebuffer_init(drm, fb, &tegra_fb_funcs);
|
2013-03-22 18:34:08 +04:00
|
|
|
if (err < 0) {
|
|
|
|
dev_err(drm->dev, "failed to initialize framebuffer: %d\n",
|
|
|
|
err);
|
|
|
|
kfree(fb);
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fb;
|
|
|
|
}
|
|
|
|
|
2014-11-26 15:03:57 +03:00
|
|
|
struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
|
|
|
|
struct drm_file *file,
|
2015-11-11 20:11:29 +03:00
|
|
|
const struct drm_mode_fb_cmd2 *cmd)
|
2013-03-22 18:34:08 +04:00
|
|
|
{
|
2019-05-16 13:31:47 +03:00
|
|
|
const struct drm_format_info *info = drm_get_format_info(drm, cmd);
|
2013-03-22 18:34:08 +04:00
|
|
|
struct tegra_bo *planes[4];
|
|
|
|
struct drm_gem_object *gem;
|
2018-03-30 17:11:27 +03:00
|
|
|
struct drm_framebuffer *fb;
|
2019-05-16 13:31:48 +03:00
|
|
|
unsigned int i;
|
2013-03-22 18:34:08 +04:00
|
|
|
int err;
|
|
|
|
|
2019-05-16 13:31:47 +03:00
|
|
|
for (i = 0; i < info->num_planes; i++) {
|
2019-05-16 13:31:48 +03:00
|
|
|
unsigned int width = cmd->width / (i ? info->hsub : 1);
|
|
|
|
unsigned int height = cmd->height / (i ? info->vsub : 1);
|
2013-03-22 18:34:08 +04:00
|
|
|
unsigned int size, bpp;
|
|
|
|
|
2016-05-09 13:04:54 +03:00
|
|
|
gem = drm_gem_object_lookup(file, cmd->handles[i]);
|
2013-03-22 18:34:08 +04:00
|
|
|
if (!gem) {
|
|
|
|
err = -ENXIO;
|
|
|
|
goto unreference;
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:31:52 +03:00
|
|
|
bpp = info->cpp[i];
|
2013-03-22 18:34:08 +04:00
|
|
|
|
|
|
|
size = (height - 1) * cmd->pitches[i] +
|
|
|
|
width * bpp + cmd->offsets[i];
|
|
|
|
|
|
|
|
if (gem->size < size) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto unreference;
|
|
|
|
}
|
|
|
|
|
|
|
|
planes[i] = to_tegra_bo(gem);
|
|
|
|
}
|
|
|
|
|
|
|
|
fb = tegra_fb_alloc(drm, cmd, planes, i);
|
|
|
|
if (IS_ERR(fb)) {
|
|
|
|
err = PTR_ERR(fb);
|
|
|
|
goto unreference;
|
|
|
|
}
|
|
|
|
|
2018-03-30 17:11:27 +03:00
|
|
|
return fb;
|
2013-03-22 18:34:08 +04:00
|
|
|
|
|
|
|
unreference:
|
|
|
|
while (i--)
|
2017-08-11 15:33:07 +03:00
|
|
|
drm_gem_object_put_unlocked(&planes[i]->gem);
|
2012-11-16 01:28:22 +04:00
|
|
|
|
2013-03-22 18:34:08 +04:00
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
2015-10-27 11:10:59 +03:00
|
|
|
#ifdef CONFIG_DRM_FBDEV_EMULATION
|
2018-02-07 20:45:56 +03:00
|
|
|
static int tegra_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct drm_fb_helper *helper = info->par;
|
|
|
|
struct tegra_bo *bo;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
bo = tegra_fb_get_plane(helper->fb, 0);
|
|
|
|
|
|
|
|
err = drm_gem_mmap_obj(&bo->gem, bo->gem.size, vma);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return __tegra_gem_mmap(&bo->gem, vma);
|
|
|
|
}
|
|
|
|
|
2013-03-22 18:34:08 +04:00
|
|
|
static struct fb_ops tegra_fb_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
2016-11-14 02:03:22 +03:00
|
|
|
DRM_FB_HELPER_DEFAULT_OPS,
|
2015-07-22 12:28:07 +03:00
|
|
|
.fb_fillrect = drm_fb_helper_sys_fillrect,
|
|
|
|
.fb_copyarea = drm_fb_helper_sys_copyarea,
|
|
|
|
.fb_imageblit = drm_fb_helper_sys_imageblit,
|
2018-02-07 20:45:56 +03:00
|
|
|
.fb_mmap = tegra_fb_mmap,
|
2013-03-22 18:34:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static int tegra_fbdev_probe(struct drm_fb_helper *helper,
|
|
|
|
struct drm_fb_helper_surface_size *sizes)
|
|
|
|
{
|
|
|
|
struct tegra_fbdev *fbdev = to_tegra_fbdev(helper);
|
2014-07-11 10:29:14 +04:00
|
|
|
struct tegra_drm *tegra = helper->dev->dev_private;
|
2013-03-22 18:34:08 +04:00
|
|
|
struct drm_device *drm = helper->dev;
|
|
|
|
struct drm_mode_fb_cmd2 cmd = { 0 };
|
|
|
|
unsigned int bytes_per_pixel;
|
|
|
|
struct drm_framebuffer *fb;
|
|
|
|
unsigned long offset;
|
|
|
|
struct fb_info *info;
|
|
|
|
struct tegra_bo *bo;
|
|
|
|
size_t size;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
bytes_per_pixel = DIV_ROUND_UP(sizes->surface_bpp, 8);
|
|
|
|
|
|
|
|
cmd.width = sizes->surface_width;
|
|
|
|
cmd.height = sizes->surface_height;
|
2014-07-11 10:29:14 +04:00
|
|
|
cmd.pitches[0] = round_up(sizes->surface_width * bytes_per_pixel,
|
|
|
|
tegra->pitch_align);
|
2017-11-14 18:09:30 +03:00
|
|
|
|
2013-03-22 18:34:08 +04:00
|
|
|
cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
|
|
|
|
sizes->surface_depth);
|
|
|
|
|
|
|
|
size = cmd.pitches[0] * cmd.height;
|
|
|
|
|
2013-10-05 00:34:01 +04:00
|
|
|
bo = tegra_bo_create(drm, size, 0);
|
2013-03-22 18:34:08 +04:00
|
|
|
if (IS_ERR(bo))
|
|
|
|
return PTR_ERR(bo);
|
|
|
|
|
2015-07-22 12:28:07 +03:00
|
|
|
info = drm_fb_helper_alloc_fbi(helper);
|
|
|
|
if (IS_ERR(info)) {
|
2013-03-22 18:34:08 +04:00
|
|
|
dev_err(drm->dev, "failed to allocate framebuffer info\n");
|
2017-08-11 15:33:07 +03:00
|
|
|
drm_gem_object_put_unlocked(&bo->gem);
|
2015-07-22 12:28:07 +03:00
|
|
|
return PTR_ERR(info);
|
2013-03-22 18:34:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
fbdev->fb = tegra_fb_alloc(drm, &cmd, &bo, 1);
|
|
|
|
if (IS_ERR(fbdev->fb)) {
|
|
|
|
err = PTR_ERR(fbdev->fb);
|
2014-11-06 16:36:19 +03:00
|
|
|
dev_err(drm->dev, "failed to allocate DRM framebuffer: %d\n",
|
|
|
|
err);
|
2017-08-11 15:33:07 +03:00
|
|
|
drm_gem_object_put_unlocked(&bo->gem);
|
2017-02-07 19:16:03 +03:00
|
|
|
return PTR_ERR(fbdev->fb);
|
2013-03-22 18:34:08 +04:00
|
|
|
}
|
|
|
|
|
2018-03-30 17:11:27 +03:00
|
|
|
fb = fbdev->fb;
|
2013-03-22 18:34:08 +04:00
|
|
|
helper->fb = fb;
|
|
|
|
helper->fbdev = info;
|
|
|
|
|
|
|
|
info->fbops = &tegra_fb_ops;
|
|
|
|
|
2019-03-26 16:20:05 +03:00
|
|
|
drm_fb_helper_fill_info(info, helper, sizes);
|
2013-03-22 18:34:08 +04:00
|
|
|
|
|
|
|
offset = info->var.xoffset * bytes_per_pixel +
|
|
|
|
info->var.yoffset * fb->pitches[0];
|
|
|
|
|
2014-06-26 23:41:53 +04:00
|
|
|
if (bo->pages) {
|
|
|
|
bo->vaddr = vmap(bo->pages, bo->num_pages, VM_MAP,
|
|
|
|
pgprot_writecombine(PAGE_KERNEL));
|
|
|
|
if (!bo->vaddr) {
|
|
|
|
dev_err(drm->dev, "failed to vmap() framebuffer\n");
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 18:34:08 +04:00
|
|
|
drm->mode_config.fb_base = (resource_size_t)bo->paddr;
|
2013-11-08 16:18:14 +04:00
|
|
|
info->screen_base = (void __iomem *)bo->vaddr + offset;
|
2013-03-22 18:34:08 +04:00
|
|
|
info->screen_size = size;
|
|
|
|
info->fix.smem_start = (unsigned long)(bo->paddr + offset);
|
|
|
|
info->fix.smem_len = size;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
destroy:
|
2016-12-27 13:49:25 +03:00
|
|
|
drm_framebuffer_remove(fb);
|
2013-03-22 18:34:08 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-06-27 19:19:23 +04:00
|
|
|
static const struct drm_fb_helper_funcs tegra_fb_helper_funcs = {
|
2013-03-22 18:34:08 +04:00
|
|
|
.fb_probe = tegra_fbdev_probe,
|
|
|
|
};
|
|
|
|
|
2014-06-27 19:19:25 +04:00
|
|
|
static struct tegra_fbdev *tegra_fbdev_create(struct drm_device *drm)
|
2013-03-22 18:34:08 +04:00
|
|
|
{
|
|
|
|
struct tegra_fbdev *fbdev;
|
|
|
|
|
|
|
|
fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL);
|
|
|
|
if (!fbdev) {
|
|
|
|
dev_err(drm->dev, "failed to allocate DRM fbdev\n");
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
}
|
|
|
|
|
2014-06-27 19:19:24 +04:00
|
|
|
drm_fb_helper_prepare(drm, &fbdev->base, &tegra_fb_helper_funcs);
|
2013-03-22 18:34:08 +04:00
|
|
|
|
2014-06-27 19:19:25 +04:00
|
|
|
return fbdev;
|
|
|
|
}
|
|
|
|
|
2014-11-06 16:12:08 +03:00
|
|
|
static void tegra_fbdev_free(struct tegra_fbdev *fbdev)
|
|
|
|
{
|
|
|
|
kfree(fbdev);
|
|
|
|
}
|
|
|
|
|
2014-06-27 19:19:25 +04:00
|
|
|
static int tegra_fbdev_init(struct tegra_fbdev *fbdev,
|
|
|
|
unsigned int preferred_bpp,
|
|
|
|
unsigned int num_crtc,
|
|
|
|
unsigned int max_connectors)
|
|
|
|
{
|
|
|
|
struct drm_device *drm = fbdev->base.dev;
|
|
|
|
int err;
|
|
|
|
|
drm: Rely on mode_config data for fb_helper initialization
Instead of receiving the num_crts as a parameter, we can read it
directly from the mode_config structure. I audited the drivers that
invoke this helper and I believe all of them initialize the mode_config
struct accordingly, prior to calling the fb_helper.
I used the following coccinelle hack to make this transformation, except
for the function headers and comment updates. The first and second
rules are split because I couldn't find a way to remove the unused
temporary variables at the same time I removed the parameter.
// <smpl>
@r@
expression A,B,D,E;
identifier C;
@@
(
- drm_fb_helper_init(A,B,C,D)
+ drm_fb_helper_init(A,B,D)
|
- drm_fbdev_cma_init_with_funcs(A,B,C,D,E)
+ drm_fbdev_cma_init_with_funcs(A,B,D,E)
|
- drm_fbdev_cma_init(A,B,C,D)
+ drm_fbdev_cma_init(A,B,D)
)
@@
expression A,B,C,D,E;
@@
(
- drm_fb_helper_init(A,B,C,D)
+ drm_fb_helper_init(A,B,D)
|
- drm_fbdev_cma_init_with_funcs(A,B,C,D,E)
+ drm_fbdev_cma_init_with_funcs(A,B,D,E)
|
- drm_fbdev_cma_init(A,B,C,D)
+ drm_fbdev_cma_init(A,B,D)
)
@@
identifier r.C;
type T;
expression V;
@@
- T C;
<...
when != C
- C = V;
...>
// </smpl>
Changes since v1:
- Rebased on top of the tip of drm-misc-next.
- Remove mention to sti since a proper fix got merged.
Suggested-by: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20170202162640.27261-1-krisman@collabora.co.uk
2017-02-02 19:26:40 +03:00
|
|
|
err = drm_fb_helper_init(drm, &fbdev->base, max_connectors);
|
2013-03-22 18:34:08 +04:00
|
|
|
if (err < 0) {
|
2014-11-06 16:36:19 +03:00
|
|
|
dev_err(drm->dev, "failed to initialize DRM FB helper: %d\n",
|
|
|
|
err);
|
2014-06-27 19:19:25 +04:00
|
|
|
return err;
|
2013-03-22 18:34:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
err = drm_fb_helper_single_add_all_connectors(&fbdev->base);
|
|
|
|
if (err < 0) {
|
2014-11-06 16:36:19 +03:00
|
|
|
dev_err(drm->dev, "failed to add connectors: %d\n", err);
|
2013-03-22 18:34:08 +04:00
|
|
|
goto fini;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = drm_fb_helper_initial_config(&fbdev->base, preferred_bpp);
|
|
|
|
if (err < 0) {
|
2014-11-06 16:36:19 +03:00
|
|
|
dev_err(drm->dev, "failed to set initial configuration: %d\n",
|
|
|
|
err);
|
2013-03-22 18:34:08 +04:00
|
|
|
goto fini;
|
|
|
|
}
|
|
|
|
|
2014-06-27 19:19:25 +04:00
|
|
|
return 0;
|
2013-03-22 18:34:08 +04:00
|
|
|
|
|
|
|
fini:
|
|
|
|
drm_fb_helper_fini(&fbdev->base);
|
2014-06-27 19:19:25 +04:00
|
|
|
return err;
|
2013-03-22 18:34:08 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 16:12:08 +03:00
|
|
|
static void tegra_fbdev_exit(struct tegra_fbdev *fbdev)
|
2013-03-22 18:34:08 +04:00
|
|
|
{
|
2015-07-22 12:28:07 +03:00
|
|
|
drm_fb_helper_unregister_fbi(&fbdev->base);
|
2013-03-22 18:34:08 +04:00
|
|
|
|
2018-03-30 17:11:28 +03:00
|
|
|
if (fbdev->fb) {
|
|
|
|
struct tegra_bo *bo = tegra_fb_get_plane(fbdev->fb, 0);
|
|
|
|
|
|
|
|
/* Undo the special mapping we made in fbdev probe. */
|
|
|
|
if (bo && bo->pages) {
|
|
|
|
vunmap(bo->vaddr);
|
2018-07-31 23:07:05 +03:00
|
|
|
bo->vaddr = NULL;
|
2018-03-30 17:11:28 +03:00
|
|
|
}
|
|
|
|
|
2018-03-30 17:11:27 +03:00
|
|
|
drm_framebuffer_remove(fbdev->fb);
|
2018-03-30 17:11:28 +03:00
|
|
|
}
|
2013-03-22 18:34:08 +04:00
|
|
|
|
|
|
|
drm_fb_helper_fini(&fbdev->base);
|
2014-11-06 16:12:08 +03:00
|
|
|
tegra_fbdev_free(fbdev);
|
2013-03-22 18:34:08 +04:00
|
|
|
}
|
2013-10-31 16:28:50 +04:00
|
|
|
#endif
|
2012-11-16 01:28:22 +04:00
|
|
|
|
2014-06-27 19:19:25 +04:00
|
|
|
int tegra_drm_fb_prepare(struct drm_device *drm)
|
2012-11-16 01:28:22 +04:00
|
|
|
{
|
2015-10-27 11:10:59 +03:00
|
|
|
#ifdef CONFIG_DRM_FBDEV_EMULATION
|
2013-09-24 15:22:17 +04:00
|
|
|
struct tegra_drm *tegra = drm->dev_private;
|
2012-11-16 01:28:22 +04:00
|
|
|
|
2014-06-27 19:19:25 +04:00
|
|
|
tegra->fbdev = tegra_fbdev_create(drm);
|
2013-10-31 16:28:50 +04:00
|
|
|
if (IS_ERR(tegra->fbdev))
|
|
|
|
return PTR_ERR(tegra->fbdev);
|
|
|
|
#endif
|
2012-11-16 01:28:22 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-06 16:12:08 +03:00
|
|
|
void tegra_drm_fb_free(struct drm_device *drm)
|
|
|
|
{
|
2015-10-27 11:10:59 +03:00
|
|
|
#ifdef CONFIG_DRM_FBDEV_EMULATION
|
2014-11-06 16:12:08 +03:00
|
|
|
struct tegra_drm *tegra = drm->dev_private;
|
|
|
|
|
|
|
|
tegra_fbdev_free(tegra->fbdev);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-06-27 19:19:25 +04:00
|
|
|
int tegra_drm_fb_init(struct drm_device *drm)
|
|
|
|
{
|
2015-10-27 11:10:59 +03:00
|
|
|
#ifdef CONFIG_DRM_FBDEV_EMULATION
|
2014-06-27 19:19:25 +04:00
|
|
|
struct tegra_drm *tegra = drm->dev_private;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = tegra_fbdev_init(tegra->fbdev, 32, drm->mode_config.num_crtc,
|
|
|
|
drm->mode_config.num_connector);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-16 01:28:22 +04:00
|
|
|
void tegra_drm_fb_exit(struct drm_device *drm)
|
|
|
|
{
|
2015-10-27 11:10:59 +03:00
|
|
|
#ifdef CONFIG_DRM_FBDEV_EMULATION
|
2013-09-24 15:22:17 +04:00
|
|
|
struct tegra_drm *tegra = drm->dev_private;
|
2012-11-16 01:28:22 +04:00
|
|
|
|
2014-11-06 16:12:08 +03:00
|
|
|
tegra_fbdev_exit(tegra->fbdev);
|
2013-10-31 16:28:50 +04:00
|
|
|
#endif
|
2012-11-16 01:28:22 +04:00
|
|
|
}
|