diff options
author | Hans de Goede <hdegoede@redhat.com> | 2018-09-18 19:44:37 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-09-20 12:32:05 +0200 |
commit | cfc1fc63be447737639dbf90610e7af58d7bd437 (patch) | |
tree | 9e00eb16271b0da605cae5110bd2465deafa5533 /drivers/staging/vboxvideo | |
parent | 114094c83ed334524ee1a50bd8c08425f361148b (diff) | |
download | linux-cfc1fc63be447737639dbf90610e7af58d7bd437.tar.bz2 |
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: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/vboxvideo')
-rw-r--r-- | drivers/staging/vboxvideo/vbox_drv.h | 2 | ||||
-rw-r--r-- | drivers/staging/vboxvideo/vbox_fb.c | 27 | ||||
-rw-r--r-- | drivers/staging/vboxvideo/vbox_mode.c | 54 | ||||
-rw-r--r-- | drivers/staging/vboxvideo/vbox_ttm.c | 32 |
4 files changed, 42 insertions, 73 deletions
diff --git a/drivers/staging/vboxvideo/vbox_drv.h b/drivers/staging/vboxvideo/vbox_drv.h index 6a4d3b382e79..fffde1713101 100644 --- a/drivers/staging/vboxvideo/vbox_drv.h +++ b/drivers/staging/vboxvideo/vbox_drv.h @@ -245,7 +245,7 @@ int vbox_bo_create(struct vbox_private *vbox, int size, int align, int vbox_gem_create(struct vbox_private *vbox, 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); static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait) diff --git a/drivers/staging/vboxvideo/vbox_fb.c b/drivers/staging/vboxvideo/vbox_fb.c index 0e5550fa7c57..bdc87d02ecc5 100644 --- a/drivers/staging/vboxvideo/vbox_fb.c +++ b/drivers/staging/vboxvideo/vbox_fb.c @@ -104,18 +104,11 @@ static int vboxfb_create(struct drm_fb_helper *helper, bo = gem_to_vbox_bo(gobj); - ret = vbox_bo_reserve(bo, false); + ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM); if (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); - vbox_bo_unreserve(bo); if (ret) { DRM_ERROR("failed to kmap fbcon\n"); return ret; @@ -153,6 +146,7 @@ static int vboxfb_create(struct drm_fb_helper *helper, drm_fb_helper_fill_var(info, &fbdev->helper, sizes->fb_width, sizes->fb_height); + gpu_addr = vbox_bo_gpu_offset(bo); info->fix.smem_start = info->apertures->ranges[0].base + gpu_addr; info->fix.smem_len = vbox->available_vram_size - gpu_addr; @@ -190,17 +184,12 @@ void vbox_fbdev_fini(struct vbox_private *vbox) if (afb->obj) { struct vbox_bo *bo = gem_to_vbox_bo(afb->obj); - if (!vbox_bo_reserve(bo, false)) { - if (bo->kmap.virtual) - ttm_bo_kunmap(&bo->kmap); - /* - * QXL does this, but is it really needed before - * freeing? - */ - if (bo->pin_count) - vbox_bo_unpin(bo); - vbox_bo_unreserve(bo); - } + if (bo->kmap.virtual) + ttm_bo_kunmap(&bo->kmap); + + if (bo->pin_count) + vbox_bo_unpin(bo); + drm_gem_object_put_unlocked(afb->obj); afb->obj = NULL; } diff --git a/drivers/staging/vboxvideo/vbox_mode.c b/drivers/staging/vboxvideo/vbox_mode.c index 910ea19931c9..bef99664d030 100644 --- a/drivers/staging/vboxvideo/vbox_mode.c +++ b/drivers/staging/vboxvideo/vbox_mode.c @@ -221,40 +221,6 @@ static bool vbox_set_up_input_mapping(struct vbox_private *vbox) 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, struct drm_framebuffer *fb, struct drm_display_mode *mode, @@ -296,17 +262,22 @@ static int vbox_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *adjusted_mode, 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; - ret = vbox_fb_pin(CRTC_FB(crtc), TTM_PL_FLAG_VRAM, NULL); + ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM); if (ret) { DRM_WARN("Error %d pinning new fb, out of video mem?\n", 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; } @@ -317,10 +288,12 @@ static int vbox_crtc_page_flip(struct drm_crtc *crtc, uint32_t page_flip_flags, 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; int rc; - rc = vbox_fb_pin(fb, TTM_PL_FLAG_VRAM, NULL); + rc = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM); if (rc) { DRM_WARN("Error %d pinning new fb, out of video mem?\n", rc); return rc; @@ -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_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); diff --git a/drivers/staging/vboxvideo/vbox_ttm.c b/drivers/staging/vboxvideo/vbox_ttm.c index 0e14556dcd6b..bd0a1603764e 100644 --- a/drivers/staging/vboxvideo/vbox_ttm.c +++ b/drivers/staging/vboxvideo/vbox_ttm.c @@ -343,34 +343,32 @@ err_free_vboxbo: 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 }; int i, ret; if (bo->pin_count) { bo->pin_count++; - if (gpu_addr) - *gpu_addr = vbox_bo_gpu_offset(bo); - return 0; } + ret = vbox_bo_reserve(bo, false); + if (ret) + return ret; + vbox_ttm_placement(bo, pl_flag); for (i = 0; i < bo->placement.num_placement; i++) bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT; ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx); - if (ret) - return ret; - - bo->pin_count = 1; + if (ret == 0) + bo->pin_count = 1; - if (gpu_addr) - *gpu_addr = vbox_bo_gpu_offset(bo); + vbox_bo_unreserve(bo); - return 0; + return ret; } int vbox_bo_unpin(struct vbox_bo *bo) @@ -386,14 +384,20 @@ int vbox_bo_unpin(struct vbox_bo *bo) if (bo->pin_count) 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++) bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT; ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx); - if (ret) - return ret; - return 0; + vbox_bo_unreserve(bo); + + return ret; } /* |