Skip to content

Commit

Permalink
drm/qxl: implement prime kmap/kunmap
Browse files Browse the repository at this point in the history
Generic fbdev emulation needs this.  Also: We must keep track of the
number of mappings now, so we don't unmap early in case two users want a
kmap of the same bo.  Add a sanity check to destroy callback to make
sure kmap/kunmap is balanced.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Noralf Trønnes <noralf@tronnes.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20190118122020.27596-17-kraxel@redhat.com
  • Loading branch information
Gerd Hoffmann committed Jan 28, 2019
1 parent 21c76bd commit 9b36911
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions drivers/gpu/drm/qxl/qxl_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct qxl_bo {
struct ttm_bo_kmap_obj kmap;
unsigned int pin_count;
void *kptr;
unsigned int map_count;
int type;

/* Constant after initialization */
Expand Down
6 changes: 6 additions & 0 deletions drivers/gpu/drm/qxl/qxl_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static void qxl_ttm_bo_destroy(struct ttm_buffer_object *tbo)
qdev = (struct qxl_device *)bo->gem_base.dev->dev_private;

qxl_surface_evict(qdev, bo, false);
WARN_ON_ONCE(bo->map_count > 0);
mutex_lock(&qdev->gem.mutex);
list_del_init(&bo->list);
mutex_unlock(&qdev->gem.mutex);
Expand Down Expand Up @@ -131,6 +132,7 @@ int qxl_bo_kmap(struct qxl_bo *bo, void **ptr)
if (bo->kptr) {
if (ptr)
*ptr = bo->kptr;
bo->map_count++;
return 0;
}
r = ttm_bo_kmap(&bo->tbo, 0, bo->tbo.num_pages, &bo->kmap);
Expand All @@ -139,6 +141,7 @@ int qxl_bo_kmap(struct qxl_bo *bo, void **ptr)
bo->kptr = ttm_kmap_obj_virtual(&bo->kmap, &is_iomem);
if (ptr)
*ptr = bo->kptr;
bo->map_count = 1;
return 0;
}

Expand Down Expand Up @@ -180,6 +183,9 @@ void qxl_bo_kunmap(struct qxl_bo *bo)
{
if (bo->kptr == NULL)
return;
bo->map_count--;
if (bo->map_count > 0)
return;
bo->kptr = NULL;
ttm_bo_kunmap(&bo->kmap);
}
Expand Down
17 changes: 13 additions & 4 deletions drivers/gpu/drm/qxl/qxl_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Authors: Andreas Pokorny
*/

#include "qxl_drv.h"
#include "qxl_object.h"

/* Empty Implementations as there should not be any other driver for a virtual
* device that might share buffers with qxl */
Expand Down Expand Up @@ -54,13 +54,22 @@ struct drm_gem_object *qxl_gem_prime_import_sg_table(

void *qxl_gem_prime_vmap(struct drm_gem_object *obj)
{
WARN_ONCE(1, "not implemented");
return ERR_PTR(-ENOSYS);
struct qxl_bo *bo = gem_to_qxl_bo(obj);
void *ptr;
int ret;

ret = qxl_bo_kmap(bo, &ptr);
if (ret < 0)
return ERR_PTR(ret);

return ptr;
}

void qxl_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
{
WARN_ONCE(1, "not implemented");
struct qxl_bo *bo = gem_to_qxl_bo(obj);

qxl_bo_kunmap(bo);
}

int qxl_gem_prime_mmap(struct drm_gem_object *obj,
Expand Down

0 comments on commit 9b36911

Please sign in to comment.