From: Hans de Goede <hdegoede@redhat.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: devel@driverdev.osuosl.org, Hans de Goede <hdegoede@redhat.com>,
Michael Thayer <michael.thayer@oracle.com>,
dri-devel@lists.freedesktop.org
Subject: [PATCH 12/12] staging: vboxvideo: Add vbox_bo_k[un]map helper functions
Date: Tue, 18 Sep 2018 19:44:38 +0200 [thread overview]
Message-ID: <20180918174438.19780-13-hdegoede@redhat.com> (raw)
In-Reply-To: <20180918174438.19780-1-hdegoede@redhat.com>
Add vbox_bo_k[un]map helper functions instead of having code directly
poking struct vbox_bo internals.
While touch neighboring code anyways also fix a return -PTR_ERR(info),
which should be return PTR_ERR(info).
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/staging/vboxvideo/vbox_drv.h | 2 ++
drivers/staging/vboxvideo/vbox_fb.c | 19 +++++++------------
drivers/staging/vboxvideo/vbox_ttm.c | 28 +++++++++++++++++++++++++++-
3 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/drivers/staging/vboxvideo/vbox_drv.h b/drivers/staging/vboxvideo/vbox_drv.h
index fffde1713101..6c52cbd9e91e 100644
--- a/drivers/staging/vboxvideo/vbox_drv.h
+++ b/drivers/staging/vboxvideo/vbox_drv.h
@@ -269,6 +269,8 @@ static inline void vbox_bo_unreserve(struct vbox_bo *bo)
void vbox_ttm_placement(struct vbox_bo *bo, int domain);
int vbox_bo_push_sysram(struct vbox_bo *bo);
int vbox_mmap(struct file *filp, struct vm_area_struct *vma);
+void *vbox_bo_kmap(struct vbox_bo *bo);
+void vbox_bo_kunmap(struct vbox_bo *bo);
/* vbox_prime.c */
int vbox_gem_prime_pin(struct drm_gem_object *obj);
diff --git a/drivers/staging/vboxvideo/vbox_fb.c b/drivers/staging/vboxvideo/vbox_fb.c
index bdc87d02ecc5..b8b42f9aafae 100644
--- a/drivers/staging/vboxvideo/vbox_fb.c
+++ b/drivers/staging/vboxvideo/vbox_fb.c
@@ -108,15 +108,14 @@ static int vboxfb_create(struct drm_fb_helper *helper,
if (ret)
return ret;
- ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
- if (ret) {
- DRM_ERROR("failed to kmap fbcon\n");
- return ret;
- }
-
info = drm_fb_helper_alloc_fbi(helper);
if (IS_ERR(info))
- return -PTR_ERR(info);
+ return PTR_ERR(info);
+
+ info->screen_size = size;
+ info->screen_base = (char __iomem *)vbox_bo_kmap(bo);
+ if (IS_ERR(info->screen_base))
+ return PTR_ERR(info->screen_base);
info->par = fbdev;
@@ -150,9 +149,6 @@ static int vboxfb_create(struct drm_fb_helper *helper,
info->fix.smem_start = info->apertures->ranges[0].base + gpu_addr;
info->fix.smem_len = vbox->available_vram_size - gpu_addr;
- info->screen_base = (char __iomem *)bo->kmap.virtual;
- info->screen_size = size;
-
#ifdef CONFIG_DRM_KMS_FB_HELPER
info->fbdefio = &vbox_defio;
fb_deferred_io_init(info);
@@ -184,8 +180,7 @@ void vbox_fbdev_fini(struct vbox_private *vbox)
if (afb->obj) {
struct vbox_bo *bo = gem_to_vbox_bo(afb->obj);
- if (bo->kmap.virtual)
- ttm_bo_kunmap(&bo->kmap);
+ vbox_bo_kunmap(bo);
if (bo->pin_count)
vbox_bo_unpin(bo);
diff --git a/drivers/staging/vboxvideo/vbox_ttm.c b/drivers/staging/vboxvideo/vbox_ttm.c
index bd0a1603764e..5ecfa7629173 100644
--- a/drivers/staging/vboxvideo/vbox_ttm.c
+++ b/drivers/staging/vboxvideo/vbox_ttm.c
@@ -418,8 +418,10 @@ int vbox_bo_push_sysram(struct vbox_bo *bo)
if (bo->pin_count)
return 0;
- if (bo->kmap.virtual)
+ if (bo->kmap.virtual) {
ttm_bo_kunmap(&bo->kmap);
+ bo->kmap.virtual = NULL;
+ }
vbox_ttm_placement(bo, TTM_PL_FLAG_SYSTEM);
@@ -448,3 +450,27 @@ int vbox_mmap(struct file *filp, struct vm_area_struct *vma)
return ttm_bo_mmap(filp, vma, &vbox->ttm.bdev);
}
+
+void *vbox_bo_kmap(struct vbox_bo *bo)
+{
+ int ret;
+
+ if (bo->kmap.virtual)
+ return bo->kmap.virtual;
+
+ ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
+ if (ret) {
+ DRM_ERROR("Error kmapping bo: %d\n", ret);
+ return NULL;
+ }
+
+ return bo->kmap.virtual;
+}
+
+void vbox_bo_kunmap(struct vbox_bo *bo)
+{
+ if (bo->kmap.virtual) {
+ ttm_bo_kunmap(&bo->kmap);
+ bo->kmap.virtual = NULL;
+ }
+}
--
2.19.0.rc1
next prev parent reply other threads:[~2018-09-18 17:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-18 17:44 [PATCH 00/12] staging: vboxvideo: Preparation work for moving to atomic modesetting Hans de Goede
2018-09-18 17:44 ` [PATCH 01/12] staging: vboxvideo: Let DRM core handle connector registering Hans de Goede
2018-09-18 17:44 ` [PATCH 02/12] staging: vboxvideo: Move setup of modesetting from driver_load to mode_init Hans de Goede
2018-09-18 17:44 ` [PATCH 03/12] staging: vboxvideo: Fold driver_load/unload into probe/remove functions Hans de Goede
2018-09-18 17:44 ` [PATCH 04/12] staging: vboxvideo: Embed drm_device into driver structure Hans de Goede
2018-09-18 17:44 ` [PATCH 05/12] staging: vboxvideo: Fold vbox_drm_resume() into vbox_pm_resume() Hans de Goede
2018-09-18 17:44 ` [PATCH 06/12] staging: vboxvideo: Add fl_flag argument to vbox_fb_pin() helper Hans de Goede
2018-09-18 17:44 ` [PATCH 07/12] staging: vboxvideo: Expose creation of universal primary plane Hans de Goede
2018-09-18 17:44 ` [PATCH 08/12] staging: vboxvideo: Init fb_info.fix.smem once from fbdev_create Hans de Goede
2018-09-18 17:44 ` [PATCH 09/12] staging: vboxvideo: Move pin / unpin of fb out of vbox_crtc_set_base_and_mode Hans de Goede
2018-09-18 17:44 ` [PATCH 10/12] staging: vboxvideo: Fix NULL ptr deref in vbox_set_up_input_mapping() Hans de Goede
2018-09-18 17:44 ` [PATCH 11/12] staging: vboxvideo: Move bo_[un]resere calls into vbox_bo_[un]pin Hans de Goede
2018-09-18 17:44 ` Hans de Goede [this message]
2018-09-20 10:32 ` [PATCH 00/12] staging: vboxvideo: Preparation work for moving to atomic modesetting Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180918174438.19780-13-hdegoede@redhat.com \
--to=hdegoede@redhat.com \
--cc=devel@driverdev.osuosl.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=michael.thayer@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).