2019-05-27 06:55:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-11-16 12:52:37 +00:00
|
|
|
/* Hisilicon Hibmc SoC drm driver
|
|
|
|
*
|
|
|
|
* Based on the bochs drm driver.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Huawei Limited.
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Rongrong Zou <zourongrong@huawei.com>
|
|
|
|
* Rongrong Zou <zourongrong@gmail.com>
|
|
|
|
* Jianhua Li <lijianhua@huawei.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <drm/drm_crtc.h>
|
|
|
|
#include <drm/drm_fb_helper.h>
|
2019-06-30 06:19:22 +00:00
|
|
|
#include <drm/drm_fourcc.h>
|
|
|
|
#include <drm/drm_gem_vram_helper.h>
|
2019-01-17 21:03:34 +00:00
|
|
|
#include <drm/drm_probe_helper.h>
|
2016-11-16 12:52:37 +00:00
|
|
|
|
|
|
|
#include "hibmc_drm_drv.h"
|
|
|
|
|
|
|
|
static int hibmcfb_create_object(
|
|
|
|
struct hibmc_drm_private *priv,
|
|
|
|
const struct drm_mode_fb_cmd2 *mode_cmd,
|
|
|
|
struct drm_gem_object **gobj_p)
|
|
|
|
{
|
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
struct drm_device *dev = priv->dev;
|
|
|
|
u32 size;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
size = mode_cmd->pitches[0] * mode_cmd->height;
|
|
|
|
ret = hibmc_gem_create(dev, size, true, &gobj);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
*gobj_p = gobj;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct fb_ops hibmc_drm_fb_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.fb_check_var = drm_fb_helper_check_var,
|
|
|
|
.fb_set_par = drm_fb_helper_set_par,
|
|
|
|
.fb_fillrect = drm_fb_helper_sys_fillrect,
|
|
|
|
.fb_copyarea = drm_fb_helper_sys_copyarea,
|
|
|
|
.fb_imageblit = drm_fb_helper_sys_imageblit,
|
|
|
|
.fb_pan_display = drm_fb_helper_pan_display,
|
|
|
|
.fb_blank = drm_fb_helper_blank,
|
|
|
|
.fb_setcmap = drm_fb_helper_setcmap,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int hibmc_drm_fb_create(struct drm_fb_helper *helper,
|
|
|
|
struct drm_fb_helper_surface_size *sizes)
|
|
|
|
{
|
|
|
|
struct hibmc_fbdev *hi_fbdev =
|
|
|
|
container_of(helper, struct hibmc_fbdev, helper);
|
|
|
|
struct hibmc_drm_private *priv = helper->dev->dev_private;
|
|
|
|
struct fb_info *info;
|
|
|
|
struct drm_mode_fb_cmd2 mode_cmd;
|
|
|
|
struct drm_gem_object *gobj = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
size_t size;
|
|
|
|
unsigned int bytes_per_pixel;
|
2019-05-08 08:26:29 +00:00
|
|
|
struct drm_gem_vram_object *gbo = NULL;
|
|
|
|
void *base;
|
2016-11-16 12:52:37 +00:00
|
|
|
|
|
|
|
DRM_DEBUG_DRIVER("surface width(%d), height(%d) and bpp(%d)\n",
|
|
|
|
sizes->surface_width, sizes->surface_height,
|
|
|
|
sizes->surface_bpp);
|
|
|
|
|
|
|
|
bytes_per_pixel = DIV_ROUND_UP(sizes->surface_bpp, 8);
|
|
|
|
|
|
|
|
mode_cmd.width = sizes->surface_width;
|
|
|
|
mode_cmd.height = sizes->surface_height;
|
|
|
|
mode_cmd.pitches[0] = mode_cmd.width * bytes_per_pixel;
|
|
|
|
mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
|
|
|
|
sizes->surface_depth);
|
|
|
|
|
|
|
|
size = PAGE_ALIGN(mode_cmd.pitches[0] * mode_cmd.height);
|
|
|
|
|
|
|
|
ret = hibmcfb_create_object(priv, &mode_cmd, &gobj);
|
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("failed to create fbcon backing object: %d\n", ret);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2019-05-08 08:26:29 +00:00
|
|
|
gbo = drm_gem_vram_of_gem(gobj);
|
2016-11-16 12:52:37 +00:00
|
|
|
|
2019-05-08 08:26:29 +00:00
|
|
|
ret = drm_gem_vram_pin(gbo, DRM_GEM_VRAM_PL_FLAG_VRAM);
|
2016-11-16 12:52:37 +00:00
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("failed to pin fbcon: %d\n", ret);
|
2019-05-16 16:27:46 +00:00
|
|
|
goto out_unref_gem;
|
2016-11-16 12:52:37 +00:00
|
|
|
}
|
|
|
|
|
2019-05-08 08:26:29 +00:00
|
|
|
base = drm_gem_vram_kmap(gbo, true, NULL);
|
|
|
|
if (IS_ERR(base)) {
|
|
|
|
ret = PTR_ERR(base);
|
2016-11-16 12:52:37 +00:00
|
|
|
DRM_ERROR("failed to kmap fbcon: %d\n", ret);
|
|
|
|
goto out_unpin_bo;
|
|
|
|
}
|
|
|
|
|
|
|
|
info = drm_fb_helper_alloc_fbi(helper);
|
|
|
|
if (IS_ERR(info)) {
|
|
|
|
ret = PTR_ERR(info);
|
|
|
|
DRM_ERROR("failed to allocate fbi: %d\n", ret);
|
|
|
|
goto out_release_fbi;
|
|
|
|
}
|
|
|
|
|
|
|
|
hi_fbdev->fb = hibmc_framebuffer_init(priv->dev, &mode_cmd, gobj);
|
|
|
|
if (IS_ERR(hi_fbdev->fb)) {
|
2017-01-12 15:19:21 +00:00
|
|
|
ret = PTR_ERR(hi_fbdev->fb);
|
drm/hisilicon: hibmc: Do not carry error code in HiBMC framebuffer pointer
In hibmc_drm_fb_create(), when the call to hibmc_framebuffer_init() fails
with error, do not store the error code in the HiBMC device frame-buffer
pointer, as this will be later checked for non-zero value in
hibmc_fbdev_destroy() when our intention is to check for a valid function
pointer.
This fixes the following crash:
[ 9.699791] Unable to handle kernel NULL pointer dereference at virtual address 000000000000001a
[ 9.708672] Mem abort info:
[ 9.711489] ESR = 0x96000004
[ 9.714570] Exception class = DABT (current EL), IL = 32 bits
[ 9.720551] SET = 0, FnV = 0
[ 9.723631] EA = 0, S1PTW = 0
[ 9.726799] Data abort info:
[ 9.729702] ISV = 0, ISS = 0x00000004
[ 9.733573] CM = 0, WnR = 0
[ 9.736566] [000000000000001a] user address but active_mm is swapper
[ 9.742987] Internal error: Oops: 96000004 [#1] PREEMPT SMP
[ 9.748614] Modules linked in:
[ 9.751694] CPU: 16 PID: 293 Comm: kworker/16:1 Tainted: G W 4.19.0-rc4-next-20180920-00001-g9b0012c #322
[ 9.762681] Hardware name: Huawei Taishan 2280 /D05, BIOS Hisilicon D05 IT21 Nemo 2.0 RC0 04/18/2018
[ 9.771915] Workqueue: events work_for_cpu_fn
[ 9.776312] pstate: 60000005 (nZCv daif -PAN -UAO)
[ 9.781150] pc : drm_mode_object_put+0x0/0x20
[ 9.785547] lr : hibmc_fbdev_fini+0x40/0x58
[ 9.789767] sp : ffff00000af1bcf0
[ 9.793108] x29: ffff00000af1bcf0 x28: 0000000000000000
[ 9.798473] x27: 0000000000000000 x26: ffff000008f66630
[ 9.803838] x25: 0000000000000000 x24: ffff0000095abb98
[ 9.809203] x23: ffff8017db92fe00 x22: ffff8017d2b13000
[ 9.814568] x21: ffffffffffffffea x20: ffff8017d2f80018
[ 9.819933] x19: ffff8017d28a0018 x18: ffffffffffffffff
[ 9.825297] x17: 0000000000000000 x16: 0000000000000000
[ 9.830662] x15: ffff0000092296c8 x14: ffff00008939970f
[ 9.836026] x13: ffff00000939971d x12: ffff000009229940
[ 9.841391] x11: ffff0000085f8fc0 x10: ffff00000af1b9a0
[ 9.846756] x9 : 000000000000000d x8 : 6620657a696c6169
[ 9.852121] x7 : ffff8017d3340580 x6 : ffff8017d4168000
[ 9.857486] x5 : 0000000000000000 x4 : ffff8017db92fb20
[ 9.862850] x3 : 0000000000002690 x2 : ffff8017d3340480
[ 9.868214] x1 : 0000000000000028 x0 : 0000000000000002
[ 9.873580] Process kworker/16:1 (pid: 293, stack limit = 0x(____ptrval____))
[ 9.880788] Call trace:
[ 9.883252] drm_mode_object_put+0x0/0x20
[ 9.887297] hibmc_unload+0x1c/0x80
[ 9.890815] hibmc_pci_probe+0x170/0x3c8
[ 9.894773] local_pci_probe+0x3c/0xb0
[ 9.898555] work_for_cpu_fn+0x18/0x28
[ 9.902337] process_one_work+0x1e0/0x318
[ 9.906382] worker_thread+0x228/0x450
[ 9.910164] kthread+0x128/0x130
[ 9.913418] ret_from_fork+0x10/0x18
[ 9.917024] Code: a94153f3 a8c27bfd d65f03c0 d503201f (f9400c01)
[ 9.923180] ---[ end trace 2695ffa0af5be375 ]---
Fixes: d1667b86795a ("drm/hisilicon/hibmc: Add support for frame buffer")
Signed-off-by: John Garry <john.garry@huawei.com>
Reviewed-by: Xinliang Liu <z.liuxinliang@hisilicon.com>
Signed-off-by: Xinliang Liu <z.liuxinliang@hisilicon.com>
2018-09-21 17:25:25 +00:00
|
|
|
hi_fbdev->fb = NULL;
|
2016-11-16 12:52:37 +00:00
|
|
|
DRM_ERROR("failed to initialize framebuffer: %d\n", ret);
|
|
|
|
goto out_release_fbi;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->fbdev->size = size;
|
|
|
|
hi_fbdev->helper.fb = &hi_fbdev->fb->fb;
|
|
|
|
|
|
|
|
info->fbops = &hibmc_drm_fb_ops;
|
|
|
|
|
2019-03-26 13:19:57 +00:00
|
|
|
drm_fb_helper_fill_info(info, &priv->fbdev->helper, sizes);
|
2016-11-16 12:52:37 +00:00
|
|
|
|
2019-05-08 08:26:29 +00:00
|
|
|
info->screen_base = base;
|
2016-11-16 12:52:37 +00:00
|
|
|
info->screen_size = size;
|
|
|
|
|
2019-05-08 08:26:29 +00:00
|
|
|
info->fix.smem_start = gbo->bo.mem.bus.offset + gbo->bo.mem.bus.base;
|
2016-11-16 12:52:37 +00:00
|
|
|
info->fix.smem_len = size;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_release_fbi:
|
2019-05-08 08:26:29 +00:00
|
|
|
drm_gem_vram_kunmap(gbo);
|
2016-11-16 12:52:37 +00:00
|
|
|
out_unpin_bo:
|
2019-05-08 08:26:29 +00:00
|
|
|
drm_gem_vram_unpin(gbo);
|
2016-11-16 12:52:37 +00:00
|
|
|
out_unref_gem:
|
2017-08-11 12:32:56 +00:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2016-11-16 12:52:37 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hibmc_fbdev_destroy(struct hibmc_fbdev *fbdev)
|
|
|
|
{
|
|
|
|
struct hibmc_framebuffer *gfb = fbdev->fb;
|
|
|
|
struct drm_fb_helper *fbh = &fbdev->helper;
|
|
|
|
|
|
|
|
drm_fb_helper_unregister_fbi(fbh);
|
|
|
|
|
|
|
|
drm_fb_helper_fini(fbh);
|
|
|
|
|
|
|
|
if (gfb)
|
2017-08-11 12:32:56 +00:00
|
|
|
drm_framebuffer_put(&gfb->fb);
|
2016-11-16 12:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_fb_helper_funcs hibmc_fbdev_helper_funcs = {
|
|
|
|
.fb_probe = hibmc_drm_fb_create,
|
|
|
|
};
|
|
|
|
|
|
|
|
int hibmc_fbdev_init(struct hibmc_drm_private *priv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct fb_var_screeninfo *var;
|
|
|
|
struct fb_fix_screeninfo *fix;
|
|
|
|
struct hibmc_fbdev *hifbdev;
|
|
|
|
|
|
|
|
hifbdev = devm_kzalloc(priv->dev->dev, sizeof(*hifbdev), GFP_KERNEL);
|
|
|
|
if (!hifbdev) {
|
|
|
|
DRM_ERROR("failed to allocate hibmc_fbdev\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->fbdev = hifbdev;
|
|
|
|
drm_fb_helper_prepare(priv->dev, &hifbdev->helper,
|
|
|
|
&hibmc_fbdev_helper_funcs);
|
|
|
|
|
|
|
|
/* Now just one crtc and one channel */
|
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 16:26:40 +00:00
|
|
|
ret = drm_fb_helper_init(priv->dev, &hifbdev->helper, 1);
|
2016-11-16 12:52:37 +00:00
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("failed to initialize fb helper: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_fb_helper_single_add_all_connectors(&hifbdev->helper);
|
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("failed to add all connectors: %d\n", ret);
|
|
|
|
goto fini;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_fb_helper_initial_config(&hifbdev->helper, 16);
|
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("failed to setup initial conn config: %d\n", ret);
|
|
|
|
goto fini;
|
|
|
|
}
|
|
|
|
|
|
|
|
var = &hifbdev->helper.fbdev->var;
|
|
|
|
fix = &hifbdev->helper.fbdev->fix;
|
|
|
|
|
|
|
|
DRM_DEBUG_DRIVER("Member of info->var is :\n"
|
|
|
|
"xres=%d\n"
|
|
|
|
"yres=%d\n"
|
|
|
|
"xres_virtual=%d\n"
|
|
|
|
"yres_virtual=%d\n"
|
|
|
|
"xoffset=%d\n"
|
|
|
|
"yoffset=%d\n"
|
|
|
|
"bits_per_pixel=%d\n"
|
|
|
|
"...\n", var->xres, var->yres, var->xres_virtual,
|
|
|
|
var->yres_virtual, var->xoffset, var->yoffset,
|
|
|
|
var->bits_per_pixel);
|
|
|
|
DRM_DEBUG_DRIVER("Member of info->fix is :\n"
|
|
|
|
"smem_start=%lx\n"
|
|
|
|
"smem_len=%d\n"
|
|
|
|
"type=%d\n"
|
|
|
|
"type_aux=%d\n"
|
|
|
|
"visual=%d\n"
|
|
|
|
"xpanstep=%d\n"
|
|
|
|
"ypanstep=%d\n"
|
|
|
|
"ywrapstep=%d\n"
|
|
|
|
"line_length=%d\n"
|
|
|
|
"accel=%d\n"
|
|
|
|
"capabilities=%d\n"
|
|
|
|
"...\n", fix->smem_start, fix->smem_len, fix->type,
|
|
|
|
fix->type_aux, fix->visual, fix->xpanstep,
|
|
|
|
fix->ypanstep, fix->ywrapstep, fix->line_length,
|
|
|
|
fix->accel, fix->capabilities);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fini:
|
|
|
|
drm_fb_helper_fini(&hifbdev->helper);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hibmc_fbdev_fini(struct hibmc_drm_private *priv)
|
|
|
|
{
|
|
|
|
if (!priv->fbdev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hibmc_fbdev_destroy(priv->fbdev);
|
|
|
|
priv->fbdev = NULL;
|
|
|
|
}
|