Commit cfc1fc63 authored by Hans de Goede's avatar Hans de Goede Committed by Greg Kroah-Hartman

staging: vboxvideo: Move bo_[un]resere calls into vbox_bo_[un]pin

We always need to reserve the bo around a pin / unpin, so move the
reservation there.

This allows removing the vbox_fb_[un]pin helpers.

Note this means that we now no longer hold the bo reserved while
k[un]mapping it in vbox_fb.c this is fine as it is not necessary
to hold it reserved for this.
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 114094c8
...@@ -245,7 +245,7 @@ int vbox_bo_create(struct vbox_private *vbox, int size, int align, ...@@ -245,7 +245,7 @@ int vbox_bo_create(struct vbox_private *vbox, int size, int align,
int vbox_gem_create(struct vbox_private *vbox, int vbox_gem_create(struct vbox_private *vbox,
u32 size, bool iskernel, struct drm_gem_object **obj); u32 size, bool iskernel, struct drm_gem_object **obj);
int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr); int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag);
int vbox_bo_unpin(struct vbox_bo *bo); int vbox_bo_unpin(struct vbox_bo *bo);
static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait) static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait)
......
...@@ -104,18 +104,11 @@ static int vboxfb_create(struct drm_fb_helper *helper, ...@@ -104,18 +104,11 @@ static int vboxfb_create(struct drm_fb_helper *helper,
bo = gem_to_vbox_bo(gobj); bo = gem_to_vbox_bo(gobj);
ret = vbox_bo_reserve(bo, false); ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM);
if (ret) if (ret)
return ret; return ret;
ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
if (ret) {
vbox_bo_unreserve(bo);
return ret;
}
ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap); ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
vbox_bo_unreserve(bo);
if (ret) { if (ret) {
DRM_ERROR("failed to kmap fbcon\n"); DRM_ERROR("failed to kmap fbcon\n");
return ret; return ret;
...@@ -153,6 +146,7 @@ static int vboxfb_create(struct drm_fb_helper *helper, ...@@ -153,6 +146,7 @@ static int vboxfb_create(struct drm_fb_helper *helper,
drm_fb_helper_fill_var(info, &fbdev->helper, sizes->fb_width, drm_fb_helper_fill_var(info, &fbdev->helper, sizes->fb_width,
sizes->fb_height); sizes->fb_height);
gpu_addr = vbox_bo_gpu_offset(bo);
info->fix.smem_start = info->apertures->ranges[0].base + gpu_addr; info->fix.smem_start = info->apertures->ranges[0].base + gpu_addr;
info->fix.smem_len = vbox->available_vram_size - gpu_addr; info->fix.smem_len = vbox->available_vram_size - gpu_addr;
...@@ -190,17 +184,12 @@ void vbox_fbdev_fini(struct vbox_private *vbox) ...@@ -190,17 +184,12 @@ void vbox_fbdev_fini(struct vbox_private *vbox)
if (afb->obj) { if (afb->obj) {
struct vbox_bo *bo = gem_to_vbox_bo(afb->obj); struct vbox_bo *bo = gem_to_vbox_bo(afb->obj);
if (!vbox_bo_reserve(bo, false)) { if (bo->kmap.virtual)
if (bo->kmap.virtual) ttm_bo_kunmap(&bo->kmap);
ttm_bo_kunmap(&bo->kmap);
/* if (bo->pin_count)
* QXL does this, but is it really needed before vbox_bo_unpin(bo);
* freeing?
*/
if (bo->pin_count)
vbox_bo_unpin(bo);
vbox_bo_unreserve(bo);
}
drm_gem_object_put_unlocked(afb->obj); drm_gem_object_put_unlocked(afb->obj);
afb->obj = NULL; afb->obj = NULL;
} }
......
...@@ -221,40 +221,6 @@ static bool vbox_set_up_input_mapping(struct vbox_private *vbox) ...@@ -221,40 +221,6 @@ static bool vbox_set_up_input_mapping(struct vbox_private *vbox)
return old_single_framebuffer != vbox->single_framebuffer; return old_single_framebuffer != vbox->single_framebuffer;
} }
static int vbox_fb_pin(struct drm_framebuffer *fb, u32 pl_flag, u64 *addr)
{
struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(fb)->obj);
int ret;
ret = vbox_bo_reserve(bo, false);
if (ret)
return ret;
ret = vbox_bo_pin(bo, pl_flag, addr);
vbox_bo_unreserve(bo);
return ret;
}
static void vbox_fb_unpin(struct drm_framebuffer *fb)
{
struct vbox_bo *bo;
int ret;
if (!fb)
return;
bo = gem_to_vbox_bo(to_vbox_framebuffer(fb)->obj);
ret = vbox_bo_reserve(bo, false);
if (ret) {
DRM_ERROR("Error %d reserving fb bo, leaving it pinned\n", ret);
return;
}
vbox_bo_unpin(bo);
vbox_bo_unreserve(bo);
}
static void vbox_crtc_set_base_and_mode(struct drm_crtc *crtc, static void vbox_crtc_set_base_and_mode(struct drm_crtc *crtc,
struct drm_framebuffer *fb, struct drm_framebuffer *fb,
struct drm_display_mode *mode, struct drm_display_mode *mode,
...@@ -296,17 +262,22 @@ static int vbox_crtc_mode_set(struct drm_crtc *crtc, ...@@ -296,17 +262,22 @@ static int vbox_crtc_mode_set(struct drm_crtc *crtc,
struct drm_display_mode *adjusted_mode, struct drm_display_mode *adjusted_mode,
int x, int y, struct drm_framebuffer *old_fb) int x, int y, struct drm_framebuffer *old_fb)
{ {
struct drm_framebuffer *new_fb = CRTC_FB(crtc);
struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(new_fb)->obj);
int ret; int ret;
ret = vbox_fb_pin(CRTC_FB(crtc), TTM_PL_FLAG_VRAM, NULL); ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM);
if (ret) { if (ret) {
DRM_WARN("Error %d pinning new fb, out of video mem?\n", ret); DRM_WARN("Error %d pinning new fb, out of video mem?\n", ret);
return ret; return ret;
} }
vbox_crtc_set_base_and_mode(crtc, CRTC_FB(crtc), mode, x, y); vbox_crtc_set_base_and_mode(crtc, new_fb, mode, x, y);
vbox_fb_unpin(old_fb); if (old_fb) {
bo = gem_to_vbox_bo(to_vbox_framebuffer(old_fb)->obj);
vbox_bo_unpin(bo);
}
return 0; return 0;
} }
...@@ -317,10 +288,12 @@ static int vbox_crtc_page_flip(struct drm_crtc *crtc, ...@@ -317,10 +288,12 @@ static int vbox_crtc_page_flip(struct drm_crtc *crtc,
uint32_t page_flip_flags, uint32_t page_flip_flags,
struct drm_modeset_acquire_ctx *ctx) struct drm_modeset_acquire_ctx *ctx)
{ {
struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(fb)->obj);
struct drm_framebuffer *old_fb = CRTC_FB(crtc);
unsigned long flags; unsigned long flags;
int rc; int rc;
rc = vbox_fb_pin(fb, TTM_PL_FLAG_VRAM, NULL); rc = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM);
if (rc) { if (rc) {
DRM_WARN("Error %d pinning new fb, out of video mem?\n", rc); DRM_WARN("Error %d pinning new fb, out of video mem?\n", rc);
return rc; return rc;
...@@ -328,7 +301,10 @@ static int vbox_crtc_page_flip(struct drm_crtc *crtc, ...@@ -328,7 +301,10 @@ static int vbox_crtc_page_flip(struct drm_crtc *crtc,
vbox_crtc_set_base_and_mode(crtc, fb, NULL, 0, 0); vbox_crtc_set_base_and_mode(crtc, fb, NULL, 0, 0);
vbox_fb_unpin(CRTC_FB(crtc)); if (old_fb) {
bo = gem_to_vbox_bo(to_vbox_framebuffer(old_fb)->obj);
vbox_bo_unpin(bo);
}
spin_lock_irqsave(&crtc->dev->event_lock, flags); spin_lock_irqsave(&crtc->dev->event_lock, flags);
......
...@@ -343,34 +343,32 @@ int vbox_bo_create(struct vbox_private *vbox, int size, int align, ...@@ -343,34 +343,32 @@ int vbox_bo_create(struct vbox_private *vbox, int size, int align,
return ret; return ret;
} }
int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr) int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag)
{ {
struct ttm_operation_ctx ctx = { false, false }; struct ttm_operation_ctx ctx = { false, false };
int i, ret; int i, ret;
if (bo->pin_count) { if (bo->pin_count) {
bo->pin_count++; bo->pin_count++;
if (gpu_addr)
*gpu_addr = vbox_bo_gpu_offset(bo);
return 0; return 0;
} }
ret = vbox_bo_reserve(bo, false);
if (ret)
return ret;
vbox_ttm_placement(bo, pl_flag); vbox_ttm_placement(bo, pl_flag);
for (i = 0; i < bo->placement.num_placement; i++) for (i = 0; i < bo->placement.num_placement; i++)
bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT; bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx); ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
if (ret) if (ret == 0)
return ret; bo->pin_count = 1;
bo->pin_count = 1;
if (gpu_addr) vbox_bo_unreserve(bo);
*gpu_addr = vbox_bo_gpu_offset(bo);
return 0; return ret;
} }
int vbox_bo_unpin(struct vbox_bo *bo) int vbox_bo_unpin(struct vbox_bo *bo)
...@@ -386,14 +384,20 @@ int vbox_bo_unpin(struct vbox_bo *bo) ...@@ -386,14 +384,20 @@ int vbox_bo_unpin(struct vbox_bo *bo)
if (bo->pin_count) if (bo->pin_count)
return 0; return 0;
ret = vbox_bo_reserve(bo, false);
if (ret) {
DRM_ERROR("Error %d reserving bo, leaving it pinned\n", ret);
return ret;
}
for (i = 0; i < bo->placement.num_placement; i++) for (i = 0; i < bo->placement.num_placement; i++)
bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT; bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx); ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
if (ret)
return ret;
return 0; vbox_bo_unreserve(bo);
return ret;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment