4fa13dbe8c
In the same spirit of the fix for QXL in commit 861078381b
("drm: qxl:
Don't alloc fbdev if emulation is not supported"), prevent the Oops in
the unbind path of Bochs if fbdev emulation is disabled.
[ 112.176009] Oops: 0002 [#1] SMP
[ 112.176009] Modules linked in: bochs_drm
[ 112.176009] CPU: 0 PID: 3002 Comm: bash Not tainted 4.11.0-rc1+ #111
[ 112.176009] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.3-20161025_171302-gandalf 04/01/2014
[ 112.176009] task: ffff8800743bbac0 task.stack: ffffc90000b5c000
[ 112.176009] RIP: 0010:mutex_lock+0x18/0x30
[ 112.176009] RSP: 0018:ffffc90000b5fc78 EFLAGS: 00010246
[ 112.176009] RAX: 0000000000000000 RBX: 0000000000000260 RCX: 0000000000000000
[ 112.176009] RDX: ffff8800743bbac0 RSI: ffff8800787176e0 RDI: 0000000000000260
[ 112.176009] RBP: ffffc90000b5fc80 R08: ffffffff00000000 R09: 00000000ffffffff
[ 112.176009] R10: ffff88007b463650 R11: 0000000000000000 R12: 0000000000000260
[ 112.176009] R13: ffff8800787176e0 R14: ffffffffa0003068 R15: 0000000000000060
[ 112.176009] FS: 00007f20564c7b40(0000) GS:ffff88007ce00000(0000) knlGS:0000000000000000
[ 112.176009] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 112.176009] CR2: 0000000000000260 CR3: 000000006b89c000 CR4: 00000000000006f0
[ 112.176009] Call Trace:
[ 112.176009] drm_mode_object_unregister+0x1e/0x50
[ 112.176009] drm_framebuffer_unregister_private+0x15/0x20
[ 112.176009] bochs_fbdev_fini+0x57/0x70 [bochs_drm]
[ 112.176009] bochs_unload+0x16/0x50 [bochs_drm]
[ 112.176009] drm_dev_unregister+0x37/0xd0
[ 112.176009] drm_put_dev+0x31/0x60
[ 112.176009] bochs_pci_remove+0x10/0x20 [bochs_drm]
[ 112.176009] pci_device_remove+0x34/0xb0
[ 112.176009] device_release_driver_internal+0x150/0x200
[ 112.176009] device_release_driver+0xd/0x10
[ 112.176009] unbind_store+0x108/0x150
[ 112.176009] drv_attr_store+0x20/0x30
[ 112.176009] sysfs_kf_write+0x32/0x40
[ 112.176009] kernfs_fop_write+0x10b/0x190
[ 112.176009] __vfs_write+0x23/0x120
[ 112.176009] ? security_file_permission+0x36/0xb0
[ 112.176009] ? rw_verify_area+0x49/0xb0
[ 112.176009] vfs_write+0xb0/0x190
[ 112.176009] SyS_write+0x41/0xa0
[ 112.176009] entry_SYSCALL_64_fastpath+0x1a/0xa9
[ 112.176009] RIP: 0033:0x7f2055bd5620
[ 112.176009] RSP: 002b:00007ffed2f487d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
[ 112.176009] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f2055bd5620
[ 112.176009] RDX: 000000000000000d RSI: 0000000000ee0008 RDI: 0000000000000001
[ 112.176009] RBP: 0000000000000001 R08: 00007f2055e94760 R09: 00007f20564c7b40
[ 112.176009] R10: 0000000000000073 R11: 0000000000000246 R12: 0000000000000000
[ 112.176009] R13: 00007ffed2f48d70 R14: 0000000000000000 R15: 0000000000000000
[ 112.176009] Code: 00 00 00 55 be 02 00 00 00 48 89 e5 e8 62 fb ff ff 5d c3 55 48 89 e5 53 48 89 fb e8 53 e9 ff ff 65 48 8b 14 25 40 c4 00 00 31 c0 <f0> 48 0f b1 13 48 85 c0 74 08 48 89 df e8c6 ff ff ff 5b 5d c3
[ 112.176009] RIP: mutex_lock+0x18/0x30 RSP: ffffc90000b5fc78
[ 112.176009] CR2: 0000000000000260
[ 112.205622] ---[ end trace 76189cd7a9bdd155 ]---
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
Link: http://patchwork.freedesktop.org/patch/msgid/20170317181409.4183-1-krisman@collabora.co.uk
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
198 lines
4.6 KiB
C
198 lines
4.6 KiB
C
/*
|
|
* 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 "bochs.h"
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
static int bochsfb_mmap(struct fb_info *info,
|
|
struct vm_area_struct *vma)
|
|
{
|
|
struct drm_fb_helper *fb_helper = info->par;
|
|
struct bochs_device *bochs =
|
|
container_of(fb_helper, struct bochs_device, fb.helper);
|
|
struct bochs_bo *bo = gem_to_bochs_bo(bochs->fb.gfb.obj);
|
|
|
|
return ttm_fbdev_mmap(vma, &bo->bo);
|
|
}
|
|
|
|
static struct fb_ops bochsfb_ops = {
|
|
.owner = THIS_MODULE,
|
|
DRM_FB_HELPER_DEFAULT_OPS,
|
|
.fb_fillrect = drm_fb_helper_sys_fillrect,
|
|
.fb_copyarea = drm_fb_helper_sys_copyarea,
|
|
.fb_imageblit = drm_fb_helper_sys_imageblit,
|
|
.fb_mmap = bochsfb_mmap,
|
|
};
|
|
|
|
static int bochsfb_create_object(struct bochs_device *bochs,
|
|
const struct drm_mode_fb_cmd2 *mode_cmd,
|
|
struct drm_gem_object **gobj_p)
|
|
{
|
|
struct drm_device *dev = bochs->dev;
|
|
struct drm_gem_object *gobj;
|
|
u32 size;
|
|
int ret = 0;
|
|
|
|
size = mode_cmd->pitches[0] * mode_cmd->height;
|
|
ret = bochs_gem_create(dev, size, true, &gobj);
|
|
if (ret)
|
|
return ret;
|
|
|
|
*gobj_p = gobj;
|
|
return ret;
|
|
}
|
|
|
|
static int bochsfb_create(struct drm_fb_helper *helper,
|
|
struct drm_fb_helper_surface_size *sizes)
|
|
{
|
|
struct bochs_device *bochs =
|
|
container_of(helper, struct bochs_device, fb.helper);
|
|
struct fb_info *info;
|
|
struct drm_framebuffer *fb;
|
|
struct drm_mode_fb_cmd2 mode_cmd;
|
|
struct drm_gem_object *gobj = NULL;
|
|
struct bochs_bo *bo = NULL;
|
|
int size, ret;
|
|
|
|
if (sizes->surface_bpp != 32)
|
|
return -EINVAL;
|
|
|
|
mode_cmd.width = sizes->surface_width;
|
|
mode_cmd.height = sizes->surface_height;
|
|
mode_cmd.pitches[0] = mode_cmd.width * ((sizes->surface_bpp + 7) / 8);
|
|
mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
|
|
sizes->surface_depth);
|
|
size = mode_cmd.pitches[0] * mode_cmd.height;
|
|
|
|
/* alloc, pin & map bo */
|
|
ret = bochsfb_create_object(bochs, &mode_cmd, &gobj);
|
|
if (ret) {
|
|
DRM_ERROR("failed to create fbcon backing object %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
bo = gem_to_bochs_bo(gobj);
|
|
|
|
ret = ttm_bo_reserve(&bo->bo, true, false, NULL);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = bochs_bo_pin(bo, TTM_PL_FLAG_VRAM, NULL);
|
|
if (ret) {
|
|
DRM_ERROR("failed to pin fbcon\n");
|
|
ttm_bo_unreserve(&bo->bo);
|
|
return ret;
|
|
}
|
|
|
|
ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages,
|
|
&bo->kmap);
|
|
if (ret) {
|
|
DRM_ERROR("failed to kmap fbcon\n");
|
|
ttm_bo_unreserve(&bo->bo);
|
|
return ret;
|
|
}
|
|
|
|
ttm_bo_unreserve(&bo->bo);
|
|
|
|
/* init fb device */
|
|
info = drm_fb_helper_alloc_fbi(helper);
|
|
if (IS_ERR(info))
|
|
return PTR_ERR(info);
|
|
|
|
info->par = &bochs->fb.helper;
|
|
|
|
ret = bochs_framebuffer_init(bochs->dev, &bochs->fb.gfb, &mode_cmd, gobj);
|
|
if (ret)
|
|
return ret;
|
|
|
|
bochs->fb.size = size;
|
|
|
|
/* setup helper */
|
|
fb = &bochs->fb.gfb.base;
|
|
bochs->fb.helper.fb = fb;
|
|
|
|
strcpy(info->fix.id, "bochsdrmfb");
|
|
|
|
info->flags = FBINFO_DEFAULT;
|
|
info->fbops = &bochsfb_ops;
|
|
|
|
drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth);
|
|
drm_fb_helper_fill_var(info, &bochs->fb.helper, sizes->fb_width,
|
|
sizes->fb_height);
|
|
|
|
info->screen_base = bo->kmap.virtual;
|
|
info->screen_size = size;
|
|
|
|
drm_vma_offset_remove(&bo->bo.bdev->vma_manager, &bo->bo.vma_node);
|
|
info->fix.smem_start = 0;
|
|
info->fix.smem_len = size;
|
|
|
|
bochs->fb.initialized = true;
|
|
return 0;
|
|
}
|
|
|
|
static int bochs_fbdev_destroy(struct bochs_device *bochs)
|
|
{
|
|
struct bochs_framebuffer *gfb = &bochs->fb.gfb;
|
|
|
|
DRM_DEBUG_DRIVER("\n");
|
|
|
|
drm_fb_helper_unregister_fbi(&bochs->fb.helper);
|
|
|
|
if (gfb->obj) {
|
|
drm_gem_object_unreference_unlocked(gfb->obj);
|
|
gfb->obj = NULL;
|
|
}
|
|
|
|
drm_framebuffer_unregister_private(&gfb->base);
|
|
drm_framebuffer_cleanup(&gfb->base);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct drm_fb_helper_funcs bochs_fb_helper_funcs = {
|
|
.fb_probe = bochsfb_create,
|
|
};
|
|
|
|
int bochs_fbdev_init(struct bochs_device *bochs)
|
|
{
|
|
int ret;
|
|
|
|
drm_fb_helper_prepare(bochs->dev, &bochs->fb.helper,
|
|
&bochs_fb_helper_funcs);
|
|
|
|
ret = drm_fb_helper_init(bochs->dev, &bochs->fb.helper, 1);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = drm_fb_helper_single_add_all_connectors(&bochs->fb.helper);
|
|
if (ret)
|
|
goto fini;
|
|
|
|
drm_helper_disable_unused_functions(bochs->dev);
|
|
|
|
ret = drm_fb_helper_initial_config(&bochs->fb.helper, 32);
|
|
if (ret)
|
|
goto fini;
|
|
|
|
return 0;
|
|
|
|
fini:
|
|
drm_fb_helper_fini(&bochs->fb.helper);
|
|
return ret;
|
|
}
|
|
|
|
void bochs_fbdev_fini(struct bochs_device *bochs)
|
|
{
|
|
if (bochs->fb.initialized)
|
|
bochs_fbdev_destroy(bochs);
|
|
|
|
drm_fb_helper_fini(&bochs->fb.helper);
|
|
bochs->fb.initialized = false;
|
|
}
|