Commit 2408c2e5 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'qxl-fixes' of git://people.freedesktop.org/~airlied/linux

Pull qxl drm fixes from Dave Airlie:
 "Okay as I warned, the qxl driver was running a bit free and loose with
  its ttm object reservations and the new lockdep enabled reservation
  tracking shone a bright light into it, it also with the new
  reservations mutexes hits a possible deadlock during boot.

  The first patch is a real fix to render the console correctly as the
  driver used to just drop irq renderering as too hard, this also fixes
  a sleeping while atomic warning.

  The other two patches are the big ugly ones that redo how the driver
  allocates objects and reserves them and makes things all work
  properly, I've tested this in a VM, and compared to the current code
  which hits a lockdep warning and the sleep while atomic warning before
  failing.

  So sorry this is coming in late, I should have tested qxl before
  merging the mutex code, but I'd rather just fix qxl with this than
  revert the reservations code at this point"

* 'qxl-fixes' of git://people.freedesktop.org/~airlied/linux:
  qxl: convert qxl driver to proper use for reservations
  qxl: allow creation of pre-pinned objects and use for releases.
  drm/qxl: add delayed fb operations
parents 0f746650 8002db63
...@@ -179,9 +179,10 @@ qxl_push_command_ring_release(struct qxl_device *qdev, struct qxl_release *relea ...@@ -179,9 +179,10 @@ qxl_push_command_ring_release(struct qxl_device *qdev, struct qxl_release *relea
uint32_t type, bool interruptible) uint32_t type, bool interruptible)
{ {
struct qxl_command cmd; struct qxl_command cmd;
struct qxl_bo_list *entry = list_first_entry(&release->bos, struct qxl_bo_list, tv.head);
cmd.type = type; cmd.type = type;
cmd.data = qxl_bo_physical_address(qdev, release->bos[0], release->release_offset); cmd.data = qxl_bo_physical_address(qdev, to_qxl_bo(entry->tv.bo), release->release_offset);
return qxl_ring_push(qdev->command_ring, &cmd, interruptible); return qxl_ring_push(qdev->command_ring, &cmd, interruptible);
} }
...@@ -191,9 +192,10 @@ qxl_push_cursor_ring_release(struct qxl_device *qdev, struct qxl_release *releas ...@@ -191,9 +192,10 @@ qxl_push_cursor_ring_release(struct qxl_device *qdev, struct qxl_release *releas
uint32_t type, bool interruptible) uint32_t type, bool interruptible)
{ {
struct qxl_command cmd; struct qxl_command cmd;
struct qxl_bo_list *entry = list_first_entry(&release->bos, struct qxl_bo_list, tv.head);
cmd.type = type; cmd.type = type;
cmd.data = qxl_bo_physical_address(qdev, release->bos[0], release->release_offset); cmd.data = qxl_bo_physical_address(qdev, to_qxl_bo(entry->tv.bo), release->release_offset);
return qxl_ring_push(qdev->cursor_ring, &cmd, interruptible); return qxl_ring_push(qdev->cursor_ring, &cmd, interruptible);
} }
...@@ -214,7 +216,6 @@ int qxl_garbage_collect(struct qxl_device *qdev) ...@@ -214,7 +216,6 @@ int qxl_garbage_collect(struct qxl_device *qdev)
struct qxl_release *release; struct qxl_release *release;
uint64_t id, next_id; uint64_t id, next_id;
int i = 0; int i = 0;
int ret;
union qxl_release_info *info; union qxl_release_info *info;
while (qxl_ring_pop(qdev->release_ring, &id)) { while (qxl_ring_pop(qdev->release_ring, &id)) {
...@@ -224,17 +225,10 @@ int qxl_garbage_collect(struct qxl_device *qdev) ...@@ -224,17 +225,10 @@ int qxl_garbage_collect(struct qxl_device *qdev)
if (release == NULL) if (release == NULL)
break; break;
ret = qxl_release_reserve(qdev, release, false);
if (ret) {
qxl_io_log(qdev, "failed to reserve release on garbage collect %lld\n", id);
DRM_ERROR("failed to reserve release %lld\n", id);
}
info = qxl_release_map(qdev, release); info = qxl_release_map(qdev, release);
next_id = info->next; next_id = info->next;
qxl_release_unmap(qdev, release, info); qxl_release_unmap(qdev, release, info);
qxl_release_unreserve(qdev, release);
QXL_INFO(qdev, "popped %lld, next %lld\n", id, QXL_INFO(qdev, "popped %lld, next %lld\n", id,
next_id); next_id);
...@@ -259,27 +253,29 @@ int qxl_garbage_collect(struct qxl_device *qdev) ...@@ -259,27 +253,29 @@ int qxl_garbage_collect(struct qxl_device *qdev)
return i; return i;
} }
int qxl_alloc_bo_reserved(struct qxl_device *qdev, unsigned long size, int qxl_alloc_bo_reserved(struct qxl_device *qdev,
struct qxl_release *release,
unsigned long size,
struct qxl_bo **_bo) struct qxl_bo **_bo)
{ {
struct qxl_bo *bo; struct qxl_bo *bo;
int ret; int ret;
ret = qxl_bo_create(qdev, size, false /* not kernel - device */, ret = qxl_bo_create(qdev, size, false /* not kernel - device */,
QXL_GEM_DOMAIN_VRAM, NULL, &bo); false, QXL_GEM_DOMAIN_VRAM, NULL, &bo);
if (ret) { if (ret) {
DRM_ERROR("failed to allocate VRAM BO\n"); DRM_ERROR("failed to allocate VRAM BO\n");
return ret; return ret;
} }
ret = qxl_bo_reserve(bo, false); ret = qxl_release_list_add(release, bo);
if (unlikely(ret != 0)) if (ret)
goto out_unref; goto out_unref;
*_bo = bo; *_bo = bo;
return 0; return 0;
out_unref: out_unref:
qxl_bo_unref(&bo); qxl_bo_unref(&bo);
return 0; return ret;
} }
static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port, bool intr) static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port, bool intr)
...@@ -503,6 +499,10 @@ int qxl_hw_surface_alloc(struct qxl_device *qdev, ...@@ -503,6 +499,10 @@ int qxl_hw_surface_alloc(struct qxl_device *qdev,
if (ret) if (ret)
return ret; return ret;
ret = qxl_release_reserve_list(release, true);
if (ret)
return ret;
cmd = (struct qxl_surface_cmd *)qxl_release_map(qdev, release); cmd = (struct qxl_surface_cmd *)qxl_release_map(qdev, release);
cmd->type = QXL_SURFACE_CMD_CREATE; cmd->type = QXL_SURFACE_CMD_CREATE;
cmd->u.surface_create.format = surf->surf.format; cmd->u.surface_create.format = surf->surf.format;
...@@ -524,14 +524,11 @@ int qxl_hw_surface_alloc(struct qxl_device *qdev, ...@@ -524,14 +524,11 @@ int qxl_hw_surface_alloc(struct qxl_device *qdev,
surf->surf_create = release; surf->surf_create = release;
/* no need to add a release to the fence for this bo, /* no need to add a release to the fence for this surface bo,
since it is only released when we ask to destroy the surface since it is only released when we ask to destroy the surface
and it would never signal otherwise */ and it would never signal otherwise */
qxl_fence_releaseable(qdev, release);
qxl_push_command_ring_release(qdev, release, QXL_CMD_SURFACE, false); qxl_push_command_ring_release(qdev, release, QXL_CMD_SURFACE, false);
qxl_release_fence_buffer_objects(release);
qxl_release_unreserve(qdev, release);
surf->hw_surf_alloc = true; surf->hw_surf_alloc = true;
spin_lock(&qdev->surf_id_idr_lock); spin_lock(&qdev->surf_id_idr_lock);
...@@ -573,12 +570,9 @@ int qxl_hw_surface_dealloc(struct qxl_device *qdev, ...@@ -573,12 +570,9 @@ int qxl_hw_surface_dealloc(struct qxl_device *qdev,
cmd->surface_id = id; cmd->surface_id = id;
qxl_release_unmap(qdev, release, &cmd->release_info); qxl_release_unmap(qdev, release, &cmd->release_info);
qxl_fence_releaseable(qdev, release);
qxl_push_command_ring_release(qdev, release, QXL_CMD_SURFACE, false); qxl_push_command_ring_release(qdev, release, QXL_CMD_SURFACE, false);
qxl_release_unreserve(qdev, release); qxl_release_fence_buffer_objects(release);
return 0; return 0;
} }
......
...@@ -179,7 +179,7 @@ static void qxl_crtc_destroy(struct drm_crtc *crtc) ...@@ -179,7 +179,7 @@ static void qxl_crtc_destroy(struct drm_crtc *crtc)
kfree(qxl_crtc); kfree(qxl_crtc);
} }
static void static int
qxl_hide_cursor(struct qxl_device *qdev) qxl_hide_cursor(struct qxl_device *qdev)
{ {
struct qxl_release *release; struct qxl_release *release;
...@@ -188,14 +188,22 @@ qxl_hide_cursor(struct qxl_device *qdev) ...@@ -188,14 +188,22 @@ qxl_hide_cursor(struct qxl_device *qdev)
ret = qxl_alloc_release_reserved(qdev, sizeof(*cmd), QXL_RELEASE_CURSOR_CMD, ret = qxl_alloc_release_reserved(qdev, sizeof(*cmd), QXL_RELEASE_CURSOR_CMD,
&release, NULL); &release, NULL);
if (ret)
return ret;
ret = qxl_release_reserve_list(release, true);
if (ret) {
qxl_release_free(qdev, release);
return ret;
}
cmd = (struct qxl_cursor_cmd *)qxl_release_map(qdev, release); cmd = (struct qxl_cursor_cmd *)qxl_release_map(qdev, release);
cmd->type = QXL_CURSOR_HIDE; cmd->type = QXL_CURSOR_HIDE;
qxl_release_unmap(qdev, release, &cmd->release_info); qxl_release_unmap(qdev, release, &cmd->release_info);
qxl_fence_releaseable(qdev, release);
qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false); qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false);
qxl_release_unreserve(qdev, release); qxl_release_fence_buffer_objects(release);
return 0;
} }
static int qxl_crtc_cursor_set2(struct drm_crtc *crtc, static int qxl_crtc_cursor_set2(struct drm_crtc *crtc,
...@@ -216,10 +224,8 @@ static int qxl_crtc_cursor_set2(struct drm_crtc *crtc, ...@@ -216,10 +224,8 @@ static int qxl_crtc_cursor_set2(struct drm_crtc *crtc,
int size = 64*64*4; int size = 64*64*4;
int ret = 0; int ret = 0;
if (!handle) { if (!handle)
qxl_hide_cursor(qdev); return qxl_hide_cursor(qdev);
return 0;
}
obj = drm_gem_object_lookup(crtc->dev, file_priv, handle); obj = drm_gem_object_lookup(crtc->dev, file_priv, handle);
if (!obj) { if (!obj) {
...@@ -234,8 +240,9 @@ static int qxl_crtc_cursor_set2(struct drm_crtc *crtc, ...@@ -234,8 +240,9 @@ static int qxl_crtc_cursor_set2(struct drm_crtc *crtc,
goto out_unref; goto out_unref;
ret = qxl_bo_pin(user_bo, QXL_GEM_DOMAIN_CPU, NULL); ret = qxl_bo_pin(user_bo, QXL_GEM_DOMAIN_CPU, NULL);
qxl_bo_unreserve(user_bo);
if (ret) if (ret)
goto out_unreserve; goto out_unref;
ret = qxl_bo_kmap(user_bo, &user_ptr); ret = qxl_bo_kmap(user_bo, &user_ptr);
if (ret) if (ret)
...@@ -246,14 +253,20 @@ static int qxl_crtc_cursor_set2(struct drm_crtc *crtc, ...@@ -246,14 +253,20 @@ static int qxl_crtc_cursor_set2(struct drm_crtc *crtc,
&release, NULL); &release, NULL);
if (ret) if (ret)
goto out_kunmap; goto out_kunmap;
ret = qxl_alloc_bo_reserved(qdev, sizeof(struct qxl_cursor) + size,
&cursor_bo); ret = qxl_alloc_bo_reserved(qdev, release, sizeof(struct qxl_cursor) + size,
&cursor_bo);
if (ret) if (ret)
goto out_free_release; goto out_free_release;
ret = qxl_bo_kmap(cursor_bo, (void **)&cursor);
ret = qxl_release_reserve_list(release, false);
if (ret) if (ret)
goto out_free_bo; goto out_free_bo;
ret = qxl_bo_kmap(cursor_bo, (void **)&cursor);
if (ret)
goto out_backoff;
cursor->header.unique = 0; cursor->header.unique = 0;
cursor->header.type = SPICE_CURSOR_TYPE_ALPHA; cursor->header.type = SPICE_CURSOR_TYPE_ALPHA;
cursor->header.width = 64; cursor->header.width = 64;
...@@ -269,11 +282,7 @@ static int qxl_crtc_cursor_set2(struct drm_crtc *crtc, ...@@ -269,11 +282,7 @@ static int qxl_crtc_cursor_set2(struct drm_crtc *crtc,
qxl_bo_kunmap(cursor_bo); qxl_bo_kunmap(cursor_bo);
/* finish with the userspace bo */
qxl_bo_kunmap(user_bo); qxl_bo_kunmap(user_bo);
qxl_bo_unpin(user_bo);
qxl_bo_unreserve(user_bo);
drm_gem_object_unreference_unlocked(obj);
cmd = (struct qxl_cursor_cmd *)qxl_release_map(qdev, release); cmd = (struct qxl_cursor_cmd *)qxl_release_map(qdev, release);
cmd->type = QXL_CURSOR_SET; cmd->type = QXL_CURSOR_SET;
...@@ -281,30 +290,35 @@ static int qxl_crtc_cursor_set2(struct drm_crtc *crtc, ...@@ -281,30 +290,35 @@ static int qxl_crtc_cursor_set2(struct drm_crtc *crtc,
cmd->u.set.position.y = qcrtc->cur_y; cmd->u.set.position.y = qcrtc->cur_y;
cmd->u.set.shape = qxl_bo_physical_address(qdev, cursor_bo, 0); cmd->u.set.shape = qxl_bo_physical_address(qdev, cursor_bo, 0);
qxl_release_add_res(qdev, release, cursor_bo);
cmd->u.set.visible = 1; cmd->u.set.visible = 1;
qxl_release_unmap(qdev, release, &cmd->release_info); qxl_release_unmap(qdev, release, &cmd->release_info);
qxl_fence_releaseable(qdev, release);
qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false); qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false);
qxl_release_unreserve(qdev, release); qxl_release_fence_buffer_objects(release);
/* finish with the userspace bo */
ret = qxl_bo_reserve(user_bo, false);
if (!ret) {
qxl_bo_unpin(user_bo);
qxl_bo_unreserve(user_bo);
}
drm_gem_object_unreference_unlocked(obj);
qxl_bo_unreserve(cursor_bo);
qxl_bo_unref(&cursor_bo); qxl_bo_unref(&cursor_bo);
return ret; return ret;
out_backoff:
qxl_release_backoff_reserve_list(release);
out_free_bo: out_free_bo:
qxl_bo_unref(&cursor_bo); qxl_bo_unref(&cursor_bo);
out_free_release: out_free_release:
qxl_release_unreserve(qdev, release);
qxl_release_free(qdev, release); qxl_release_free(qdev, release);
out_kunmap: out_kunmap:
qxl_bo_kunmap(user_bo); qxl_bo_kunmap(user_bo);
out_unpin: out_unpin:
qxl_bo_unpin(user_bo); qxl_bo_unpin(user_bo);
out_unreserve:
qxl_bo_unreserve(user_bo);
out_unref: out_unref:
drm_gem_object_unreference_unlocked(obj); drm_gem_object_unreference_unlocked(obj);
return ret; return ret;
...@@ -322,6 +336,14 @@ static int qxl_crtc_cursor_move(struct drm_crtc *crtc, ...@@ -322,6 +336,14 @@ static int qxl_crtc_cursor_move(struct drm_crtc *crtc,
ret = qxl_alloc_release_reserved(qdev, sizeof(*cmd), QXL_RELEASE_CURSOR_CMD, ret = qxl_alloc_release_reserved(qdev, sizeof(*cmd), QXL_RELEASE_CURSOR_CMD,
&release, NULL); &release, NULL);
if (ret)
return ret;
ret = qxl_release_reserve_list(release, true);
if (ret) {
qxl_release_free(qdev, release);
return ret;
}
qcrtc->cur_x = x; qcrtc->cur_x = x;
qcrtc->cur_y = y; qcrtc->cur_y = y;
...@@ -332,9 +354,9 @@ static int qxl_crtc_cursor_move(struct drm_crtc *crtc, ...@@ -332,9 +354,9 @@ static int qxl_crtc_cursor_move(struct drm_crtc *crtc,
cmd->u.position.y = qcrtc->cur_y; cmd->u.position.y = qcrtc->cur_y;
qxl_release_unmap(qdev, release, &cmd->release_info); qxl_release_unmap(qdev, release, &cmd->release_info);
qxl_fence_releaseable(qdev, release);
qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false); qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false);
qxl_release_unreserve(qdev, release); qxl_release_fence_buffer_objects(release);
return 0; return 0;
} }
......
This diff is collapsed.
...@@ -42,6 +42,9 @@ ...@@ -42,6 +42,9 @@
#include <ttm/ttm_placement.h> #include <ttm/ttm_placement.h>
#include <ttm/ttm_module.h> #include <ttm/ttm_module.h>
/* just for ttm_validate_buffer */
#include <ttm/ttm_execbuf_util.h>
#include <drm/qxl_drm.h> #include <drm/qxl_drm.h>
#include "qxl_dev.h" #include "qxl_dev.h"
...@@ -118,9 +121,9 @@ struct qxl_bo { ...@@ -118,9 +121,9 @@ struct qxl_bo {
uint32_t surface_id; uint32_t surface_id;
struct qxl_fence fence; /* per bo fence - list of releases */ struct qxl_fence fence; /* per bo fence - list of releases */
struct qxl_release *surf_create; struct qxl_release *surf_create;
atomic_t reserve_count;
}; };
#define gem_to_qxl_bo(gobj) container_of((gobj), struct qxl_bo, gem_base) #define gem_to_qxl_bo(gobj) container_of((gobj), struct qxl_bo, gem_base)
#define to_qxl_bo(tobj) container_of((tobj), struct qxl_bo, tbo)
struct qxl_gem { struct qxl_gem {
struct mutex mutex; struct mutex mutex;
...@@ -128,12 +131,7 @@ struct qxl_gem { ...@@ -128,12 +131,7 @@ struct qxl_gem {
}; };
struct qxl_bo_list { struct qxl_bo_list {
struct list_head lhead; struct ttm_validate_buffer tv;
struct qxl_bo *bo;
};
struct qxl_reloc_list {
struct list_head bos;
}; };
struct qxl_crtc { struct qxl_crtc {
...@@ -195,10 +193,20 @@ enum { ...@@ -195,10 +193,20 @@ enum {
struct qxl_release { struct qxl_release {
int id; int id;
int type; int type;
int bo_count;
uint32_t release_offset; uint32_t release_offset;
uint32_t surface_release_id; uint32_t surface_release_id;
struct qxl_bo *bos[QXL_MAX_RES]; struct ww_acquire_ctx ticket;
struct list_head bos;
};
struct qxl_drm_chunk {
struct list_head head;
struct qxl_bo *bo;
};
struct qxl_drm_image {
struct qxl_bo *bo;
struct list_head chunk_list;
}; };
struct qxl_fb_image { struct qxl_fb_image {
...@@ -314,6 +322,7 @@ struct qxl_device { ...@@ -314,6 +322,7 @@ struct qxl_device {
struct workqueue_struct *gc_queue; struct workqueue_struct *gc_queue;
struct work_struct gc_work; struct work_struct gc_work;
struct work_struct fb_work;
}; };
/* forward declaration for QXL_INFO_IO */ /* forward declaration for QXL_INFO_IO */
...@@ -433,12 +442,19 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma); ...@@ -433,12 +442,19 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma);
/* qxl image */ /* qxl image */
int qxl_image_create(struct qxl_device *qdev, int qxl_image_init(struct qxl_device *qdev,
struct qxl_release *release, struct qxl_release *release,
struct qxl_bo **image_bo, struct qxl_drm_image *dimage,
const uint8_t *data, const uint8_t *data,
int x, int y, int width, int height, int x, int y, int width, int height,
int depth, int stride); int depth, int stride);
int
qxl_image_alloc_objects(struct qxl_device *qdev,
struct qxl_release *release,
struct qxl_drm_image **image_ptr,
int height, int stride);
void qxl_image_free_objects(struct qxl_device *qdev, struct qxl_drm_image *dimage);
void qxl_update_screen(struct qxl_device *qxl); void qxl_update_screen(struct qxl_device *qxl);
/* qxl io operations (qxl_cmd.c) */ /* qxl io operations (qxl_cmd.c) */
...@@ -459,20 +475,15 @@ int qxl_ring_push(struct qxl_ring *ring, const void *new_elt, bool interruptible ...@@ -459,20 +475,15 @@ int qxl_ring_push(struct qxl_ring *ring, const void *new_elt, bool interruptible
void qxl_io_flush_release(struct qxl_device *qdev); void qxl_io_flush_release(struct qxl_device *qdev);
void qxl_io_flush_surfaces(struct qxl_device *qdev); void qxl_io_flush_surfaces(struct qxl_device *qdev);
int qxl_release_reserve(struct qxl_device *qdev,
struct qxl_release *release, bool no_wait);
void qxl_release_unreserve(struct qxl_device *qdev,
struct qxl_release *release);
union qxl_release_info *qxl_release_map(struct qxl_device *qdev, union qxl_release_info *qxl_release_map(struct qxl_device *qdev,
struct qxl_release *release); struct qxl_release *release);
void qxl_release_unmap(struct qxl_device *qdev, void qxl_release_unmap(struct qxl_device *qdev,
struct qxl_release *release, struct qxl_release *release,
union qxl_release_info *info); union qxl_release_info *info);
/* int qxl_release_list_add(struct qxl_release *release, struct qxl_bo *bo);
* qxl_bo_add_resource. int qxl_release_reserve_list(struct qxl_release *release, bool no_intr);
* void qxl_release_backoff_reserve_list(struct qxl_release *release);
*/ void qxl_release_fence_buffer_objects(struct qxl_release *release);
void qxl_bo_add_resource(struct qxl_bo *main_bo, struct qxl_bo *resource);
int qxl_alloc_surface_release_reserved(struct qxl_device *qdev, int qxl_alloc_surface_release_reserved(struct qxl_device *qdev,
enum qxl_surface_cmd_type surface_cmd_type, enum qxl_surface_cmd_type surface_cmd_type,
...@@ -481,15 +492,16 @@ int qxl_alloc_surface_release_reserved(struct qxl_device *qdev, ...@@ -481,15 +492,16 @@ int qxl_alloc_surface_release_reserved(struct qxl_device *qdev,
int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size, int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size,
int type, struct qxl_release **release, int type, struct qxl_release **release,
struct qxl_bo **rbo); struct qxl_bo **rbo);
int qxl_fence_releaseable(struct qxl_device *qdev,
struct qxl_release *release);
int int
qxl_push_command_ring_release(struct qxl_device *qdev, struct qxl_release *release, qxl_push_command_ring_release(struct qxl_device *qdev, struct qxl_release *release,
uint32_t type, bool interruptible); uint32_t type, bool interruptible);
int int
qxl_push_cursor_ring_release(struct qxl_device *qdev, struct qxl_release *release, qxl_push_cursor_ring_release(struct qxl_device *qdev, struct qxl_release *release,
uint32_t type, bool interruptible); uint32_t type, bool interruptible);
int qxl_alloc_bo_reserved(struct qxl_device *qdev, unsigned long size, int qxl_alloc_bo_reserved(struct qxl_device *qdev,
struct qxl_release *release,
unsigned long size,
struct qxl_bo **_bo); struct qxl_bo **_bo);
/* qxl drawing commands */ /* qxl drawing commands */
...@@ -510,15 +522,9 @@ void qxl_draw_copyarea(struct qxl_device *qdev, ...@@ -510,15 +522,9 @@ void qxl_draw_copyarea(struct qxl_device *qdev,
u32 sx, u32 sy, u32 sx, u32 sy,
u32 dx, u32 dy); u32 dx, u32 dy);
uint64_t
qxl_release_alloc(struct qxl_device *qdev, int type,
struct qxl_release **ret);
void qxl_release_free(struct qxl_device *qdev, void qxl_release_free(struct qxl_device *qdev,
struct qxl_release *release); struct qxl_release *release);
void qxl_release_add_res(struct qxl_device *qdev,
struct qxl_release *release,
struct qxl_bo *bo);
/* used by qxl_debugfs_release */ /* used by qxl_debugfs_release */
struct qxl_release *qxl_release_from_id_locked(struct qxl_device *qdev, struct qxl_release *qxl_release_from_id_locked(struct qxl_device *qdev,
uint64_t id); uint64_t id);
...@@ -561,7 +567,7 @@ void qxl_surface_evict(struct qxl_device *qdev, struct qxl_bo *surf, bool freein ...@@ -561,7 +567,7 @@ void qxl_surface_evict(struct qxl_device *qdev, struct qxl_bo *surf, bool freein
int qxl_update_surface(struct qxl_device *qdev, struct qxl_bo *surf); int qxl_update_surface(struct qxl_device *qdev, struct qxl_bo *surf);
/* qxl_fence.c */ /* qxl_fence.c */
int qxl_fence_add_release(struct qxl_fence *qfence, uint32_t rel_id); void qxl_fence_add_release_locked(struct qxl_fence *qfence, uint32_t rel_id);
int qxl_fence_remove_release(struct qxl_fence *qfence, uint32_t rel_id); int qxl_fence_remove_release(struct qxl_fence *qfence, uint32_t rel_id);
int qxl_fence_init(struct qxl_device *qdev, struct qxl_fence *qfence); int qxl_fence_init(struct qxl_device *qdev, struct qxl_fence *qfence);
void qxl_fence_fini(struct qxl_fence *qfence); void qxl_fence_fini(struct qxl_fence *qfence);
......
...@@ -37,12 +37,29 @@ ...@@ -37,12 +37,29 @@
#define QXL_DIRTY_DELAY (HZ / 30) #define QXL_DIRTY_DELAY (HZ / 30)
#define QXL_FB_OP_FILLRECT 1
#define QXL_FB_OP_COPYAREA 2
#define QXL_FB_OP_IMAGEBLIT 3
struct qxl_fb_op {
struct list_head head;
int op_type;
union {
struct fb_fillrect fr;
struct fb_copyarea ca;
struct fb_image ib;
} op;
void *img_data;
};
struct qxl_fbdev { struct qxl_fbdev {
struct drm_fb_helper helper; struct drm_fb_helper helper;
struct qxl_framebuffer qfb; struct qxl_framebuffer qfb;
struct list_head fbdev_list; struct list_head fbdev_list;
struct qxl_device *qdev; struct qxl_device *qdev;
spinlock_t delayed_ops_lock;
struct list_head delayed_ops;
void *shadow; void *shadow;
int size; int size;
...@@ -164,8 +181,69 @@ static struct fb_deferred_io qxl_defio = { ...@@ -164,8 +181,69 @@ static struct fb_deferred_io qxl_defio = {
.deferred_io = qxl_deferred_io, .deferred_io = qxl_deferred_io,
}; };
static void qxl_fb_fillrect(struct fb_info *info, static void qxl_fb_delayed_fillrect(struct qxl_fbdev *qfbdev,
const struct fb_fillrect *fb_rect) const struct fb_fillrect *fb_rect)
{
struct qxl_fb_op *op;
unsigned long flags;
op = kmalloc(sizeof(struct qxl_fb_op), GFP_ATOMIC | __GFP_NOWARN);
if (!op)
return;
op->op.fr = *fb_rect;
op->img_data = NULL;
op->op_type = QXL_FB_OP_FILLRECT;
spin_lock_irqsave(&qfbdev->delayed_ops_lock, flags);
list_add_tail(&op->head, &qfbdev->delayed_ops);
spin_unlock_irqrestore(&qfbdev->delayed_ops_lock, flags);
}
static void qxl_fb_delayed_copyarea(struct qxl_fbdev *qfbdev,
const struct fb_copyarea *fb_copy)
{
struct qxl_fb_op *op;
unsigned long flags;
op = kmalloc(sizeof(struct qxl_fb_op), GFP_ATOMIC | __GFP_NOWARN);
if (!op)
return;
op->op.ca = *fb_copy;
op->img_data = NULL;
op->op_type = QXL_FB_OP_COPYAREA;
spin_lock_irqsave(&qfbdev->delayed_ops_lock, flags);
list_add_tail(&op->head, &qfbdev->delayed_ops);
spin_unlock_irqrestore(&qfbdev->delayed_ops_lock, flags);
}
static void qxl_fb_delayed_imageblit(struct qxl_fbdev *qfbdev,
const struct fb_image *fb_image)
{
struct qxl_fb_op *op;
unsigned long flags;
uint32_t size = fb_image->width * fb_image->height * (fb_image->depth >= 8 ? fb_image->depth / 8 : 1);
op = kmalloc(sizeof(struct qxl_fb_op) + size, GFP_ATOMIC | __GFP_NOWARN);
if (!op)
return;
op->op.ib = *fb_image;
op->img_data = (void *)(op + 1);
op->op_type = QXL_FB_OP_IMAGEBLIT;
memcpy(op->img_data, fb_image->data, size);
op->op.ib.data = op->img_data;
spin_lock_irqsave(&qfbdev->delayed_ops_lock, flags);
list_add_tail(&op->head, &qfbdev->delayed_ops);
spin_unlock_irqrestore(&qfbdev->delayed_ops_lock, flags);
}
static void qxl_fb_fillrect_internal(struct fb_info *info,
const struct fb_fillrect *fb_rect)
{ {
struct qxl_fbdev *qfbdev = info->par; struct qxl_fbdev *qfbdev = info->par;
struct qxl_device *qdev = qfbdev->qdev; struct qxl_device *qdev = qfbdev->qdev;
...@@ -203,17 +281,28 @@ static void qxl_fb_fillrect(struct fb_info *info, ...@@ -203,17 +281,28 @@ static void qxl_fb_fillrect(struct fb_info *info,
qxl_draw_fill_rec.rect = rect; qxl_draw_fill_rec.rect = rect;
qxl_draw_fill_rec.color = color; qxl_draw_fill_rec.color = color;
qxl_draw_fill_rec.rop = rop; qxl_draw_fill_rec.rop = rop;
qxl_draw_fill(&qxl_draw_fill_rec);
}
static void qxl_fb_fillrect(struct fb_info *info,
const struct fb_fillrect *fb_rect)
{
struct qxl_fbdev *qfbdev = info->par;
struct qxl_device *qdev = qfbdev->qdev;
if (!drm_can_sleep()) { if (!drm_can_sleep()) {
qxl_io_log(qdev, qxl_fb_delayed_fillrect(qfbdev, fb_rect);
"%s: TODO use RCU, mysterious locks with spin_lock\n", schedule_work(&qdev->fb_work);
__func__);
return; return;
} }
qxl_draw_fill(&qxl_draw_fill_rec); /* make sure any previous work is done */
flush_work(&qdev->fb_work);
qxl_fb_fillrect_internal(info, fb_rect);
} }
static void qxl_fb_copyarea(struct fb_info *info, static void qxl_fb_copyarea_internal(struct fb_info *info,
const struct fb_copyarea *region) const struct fb_copyarea *region)
{ {
struct qxl_fbdev *qfbdev = info->par; struct qxl_fbdev *qfbdev = info->par;
...@@ -223,37 +312,89 @@ static void qxl_fb_copyarea(struct fb_info *info, ...@@ -223,37 +312,89 @@ static void qxl_fb_copyarea(struct fb_info *info,
region->dx, region->dy); region->dx, region->dy);
} }
static void qxl_fb_copyarea(struct fb_info *info,
const struct fb_copyarea *region)
{
struct qxl_fbdev *qfbdev = info->par;
struct qxl_device *qdev = qfbdev->qdev;
if (!drm_can_sleep()) {
qxl_fb_delayed_copyarea(qfbdev, region);
schedule_work(&qdev->fb_work);
return;
}
/* make sure any previous work is done */
flush_work(&qdev->fb_work);
qxl_fb_copyarea_internal(info, region);
}
static void qxl_fb_imageblit_safe(struct qxl_fb_image *qxl_fb_image) static void qxl_fb_imageblit_safe(struct qxl_fb_image *qxl_fb_image)
{ {
qxl_draw_opaque_fb(qxl_fb_image, 0); qxl_draw_opaque_fb(qxl_fb_image, 0);
} }
static void qxl_fb_imageblit_internal(struct fb_info *info,
const struct fb_image *image)
{
struct qxl_fbdev *qfbdev = info->par;
struct qxl_fb_image qxl_fb_image;
/* ensure proper order rendering operations - TODO: must do this
* for everything. */
qxl_fb_image_init(&qxl_fb_image, qfbdev->qdev, info, image);
qxl_fb_imageblit_safe(&qxl_fb_image);
}
static void qxl_fb_imageblit(struct fb_info *info, static void qxl_fb_imageblit(struct fb_info *info,
const struct fb_image *image) const struct fb_image *image)
{ {
struct qxl_fbdev *qfbdev = info->par; struct qxl_fbdev *qfbdev = info->par;
struct qxl_device *qdev = qfbdev->qdev; struct qxl_device *qdev = qfbdev->qdev;
struct qxl_fb_image qxl_fb_image;
if (!drm_can_sleep()) { if (!drm_can_sleep()) {
/* we cannot do any ttm_bo allocation since that will fail on qxl_fb_delayed_imageblit(qfbdev, image);
* ioremap_wc..__get_vm_area_node, so queue the work item schedule_work(&qdev->fb_work);
* instead This can happen from printk inside an interrupt
* context, i.e.: smp_apic_timer_interrupt..check_cpu_stall */
qxl_io_log(qdev,
"%s: TODO use RCU, mysterious locks with spin_lock\n",
__func__);
return; return;
} }
/* make sure any previous work is done */
flush_work(&qdev->fb_work);
qxl_fb_imageblit_internal(info, image);
}
/* ensure proper order of rendering operations - TODO: must do this static void qxl_fb_work(struct work_struct *work)
* for everything. */ {
qxl_fb_image_init(&qxl_fb_image, qfbdev->qdev, info, image); struct qxl_device *qdev = container_of(work, struct qxl_device, fb_work);
qxl_fb_imageblit_safe(&qxl_fb_image); unsigned long flags;
struct qxl_fb_op *entry, *tmp;
struct qxl_fbdev *qfbdev = qdev->mode_info.qfbdev;
/* since the irq context just adds entries to the end of the
list dropping the lock should be fine, as entry isn't modified
in the operation code */
spin_lock_irqsave(&qfbdev->delayed_ops_lock, flags);
list_for_each_entry_safe(entry, tmp, &qfbdev->delayed_ops, head) {
spin_unlock_irqrestore(&qfbdev->delayed_ops_lock, flags);
switch (entry->op_type) {
case QXL_FB_OP_FILLRECT:
qxl_fb_fillrect_internal(qfbdev->helper.fbdev, &entry->op.fr);
break;
case QXL_FB_OP_COPYAREA:
qxl_fb_copyarea_internal(qfbdev->helper.fbdev, &entry->op.ca);
break;
case QXL_FB_OP_IMAGEBLIT:
qxl_fb_imageblit_internal(qfbdev->helper.fbdev, &entry->op.ib);
break;
}
spin_lock_irqsave(&qfbdev->delayed_ops_lock, flags);
list_del(&entry->head);
kfree(entry);
}
spin_unlock_irqrestore(&qfbdev->delayed_ops_lock, flags);
} }
int qxl_fb_init(struct qxl_device *qdev) int qxl_fb_init(struct qxl_device *qdev)
{ {
INIT_WORK(&qdev->fb_work, qxl_fb_work);
return 0; return 0;
} }
...@@ -536,7 +677,8 @@ int qxl_fbdev_init(struct qxl_device *qdev) ...@@ -536,7 +677,8 @@ int qxl_fbdev_init(struct qxl_device *qdev)
qfbdev->qdev = qdev; qfbdev->qdev = qdev;
qdev->mode_info.qfbdev = qfbdev; qdev->mode_info.qfbdev = qfbdev;
qfbdev->helper.funcs = &qxl_fb_helper_funcs; qfbdev->helper.funcs = &qxl_fb_helper_funcs;
spin_lock_init(&qfbdev->delayed_ops_lock);
INIT_LIST_HEAD(&qfbdev->delayed_ops);
ret = drm_fb_helper_init(qdev->ddev, &qfbdev->helper, ret = drm_fb_helper_init(qdev->ddev, &qfbdev->helper,
qxl_num_crtc /* num_crtc - QXL supports just 1 */, qxl_num_crtc /* num_crtc - QXL supports just 1 */,
QXLFB_CONN_LIMIT); QXLFB_CONN_LIMIT);
......
...@@ -49,17 +49,11 @@ ...@@ -49,17 +49,11 @@
For some reason every so often qxl hw fails to release, things go wrong. For some reason every so often qxl hw fails to release, things go wrong.
*/ */
/* must be called with the fence lock held */
void qxl_fence_add_release_locked(struct qxl_fence *qfence, uint32_t rel_id)
int qxl_fence_add_release(struct qxl_fence *qfence, uint32_t rel_id)
{ {
struct qxl_bo *bo = container_of(qfence, struct qxl_bo, fence);
spin_lock(&bo->tbo.bdev->fence_lock);
radix_tree_insert(&qfence->tree, rel_id, qfence); radix_tree_insert(&qfence->tree, rel_id, qfence);
qfence->num_active_releases++; qfence->num_active_releases++;
spin_unlock(&bo->tbo.bdev->fence_lock);
return 0;
} }
int qxl_fence_remove_release(struct qxl_fence *qfence, uint32_t rel_id) int qxl_fence_remove_release(struct qxl_fence *qfence, uint32_t rel_id)
......
...@@ -55,7 +55,7 @@ int qxl_gem_object_create(struct qxl_device *qdev, int size, ...@@ -55,7 +55,7 @@ int qxl_gem_object_create(struct qxl_device *qdev, int size,
/* At least align on page size */ /* At least align on page size */
if (alignment < PAGE_SIZE) if (alignment < PAGE_SIZE)
alignment = PAGE_SIZE; alignment = PAGE_SIZE;
r = qxl_bo_create(qdev, size, kernel, initial_domain, surf, &qbo); r = qxl_bo_create(qdev, size, kernel, false, initial_domain, surf, &qbo);
if (r) { if (r) {
if (r != -ERESTARTSYS) if (r != -ERESTARTSYS)
DRM_ERROR( DRM_ERROR(
......
...@@ -30,31 +30,100 @@ ...@@ -30,31 +30,100 @@
#include "qxl_object.h" #include "qxl_object.h"
static int static int
qxl_image_create_helper(struct qxl_device *qdev, qxl_allocate_chunk(struct qxl_device *qdev,
struct qxl_release *release,
struct qxl_drm_image *image,
unsigned int chunk_size)
{
struct qxl_drm_chunk *chunk;
int ret;
chunk = kmalloc(sizeof(struct qxl_drm_chunk), GFP_KERNEL);
if (!chunk)
return -ENOMEM;
ret = qxl_alloc_bo_reserved(qdev, release, chunk_size, &chunk->bo);
if (ret) {
kfree(chunk);
return ret;
}
list_add_tail(&chunk->head, &image->chunk_list);
return 0;
}
int
qxl_image_alloc_objects(struct qxl_device *qdev,
struct qxl_release *release, struct qxl_release *release,
struct qxl_bo **image_bo, struct qxl_drm_image **image_ptr,
const uint8_t *data, int height, int stride)
int width, int height, {
int depth, unsigned int hash, struct qxl_drm_image *image;
int stride) int ret;
image = kmalloc(sizeof(struct qxl_drm_image), GFP_KERNEL);
if (!image)
return -ENOMEM;
INIT_LIST_HEAD(&image->chunk_list);
ret = qxl_alloc_bo_reserved(qdev, release, sizeof(struct qxl_image), &image->bo);
if (ret) {
kfree(image);
return ret;
}
ret = qxl_allocate_chunk(qdev, release, image, sizeof(struct qxl_data_chunk) + stride * height);
if (ret) {
qxl_bo_unref(&image->bo);
kfree(image);
return ret;
}
*image_ptr = image;
return 0;
}
void qxl_image_free_objects(struct qxl_device *qdev, struct qxl_drm_image *dimage)
{ {
struct qxl_drm_chunk *chunk, *tmp;
list_for_each_entry_safe(chunk, tmp, &dimage->chunk_list, head) {
qxl_bo_unref(&chunk->bo);
kfree(chunk);
}
qxl_bo_unref(&dimage->bo);
kfree(dimage);
}
static int
qxl_image_init_helper(struct qxl_device *qdev,
struct qxl_release *release,
struct qxl_drm_image *dimage,
const uint8_t *data,
int width, int height,
int depth, unsigned int hash,
int stride)
{
struct qxl_drm_chunk *drv_chunk;
struct qxl_image *image; struct qxl_image *image;
struct qxl_data_chunk *chunk; struct qxl_data_chunk *chunk;
int i; int i;
int chunk_stride; int chunk_stride;
int linesize = width * depth / 8; int linesize = width * depth / 8;
struct qxl_bo *chunk_bo; struct qxl_bo *chunk_bo, *image_bo;
int ret;
void *ptr; void *ptr;
/* Chunk */ /* Chunk */
/* FIXME: Check integer overflow */ /* FIXME: Check integer overflow */
/* TODO: variable number of chunks */ /* TODO: variable number of chunks */
drv_chunk = list_first_entry(&dimage->chunk_list, struct qxl_drm_chunk, head);
chunk_bo = drv_chunk->bo;
chunk_stride = stride; /* TODO: should use linesize, but it renders chunk_stride = stride; /* TODO: should use linesize, but it renders
wrong (check the bitmaps are sent correctly wrong (check the bitmaps are sent correctly
first) */ first) */
ret = qxl_alloc_bo_reserved(qdev, sizeof(*chunk) + height * chunk_stride,
&chunk_bo);
ptr = qxl_bo_kmap_atomic_page(qdev, chunk_bo, 0); ptr = qxl_bo_kmap_atomic_page(qdev, chunk_bo, 0);
chunk = ptr; chunk = ptr;
chunk->data_size = height * chunk_stride; chunk->data_size = height * chunk_stride;
...@@ -102,7 +171,6 @@ qxl_image_create_helper(struct qxl_device *qdev, ...@@ -102,7 +171,6 @@ qxl_image_create_helper(struct qxl_device *qdev,
while (remain > 0) { while (remain > 0) {
page_base = out_offset & PAGE_MASK; page_base = out_offset & PAGE_MASK;
page_offset = offset_in_page(out_offset); page_offset = offset_in_page(out_offset);
size = min((int)(PAGE_SIZE - page_offset), remain); size = min((int)(PAGE_SIZE - page_offset), remain);
ptr = qxl_bo_kmap_atomic_page(qdev, chunk_bo, page_base); ptr = qxl_bo_kmap_atomic_page(qdev, chunk_bo, page_base);
...@@ -116,14 +184,10 @@ qxl_image_create_helper(struct qxl_device *qdev, ...@@ -116,14 +184,10 @@ qxl_image_create_helper(struct qxl_device *qdev,
} }
} }
} }
qxl_bo_kunmap(chunk_bo); qxl_bo_kunmap(chunk_bo);
/* Image */ image_bo = dimage->bo;
ret = qxl_alloc_bo_reserved(qdev, sizeof(*image), image_bo); ptr = qxl_bo_kmap_atomic_page(qdev, image_bo, 0);
ptr = qxl_bo_kmap_atomic_page(qdev, *image_bo, 0);
image = ptr; image = ptr;
image->descriptor.id = 0; image->descriptor.id = 0;
...@@ -154,23 +218,20 @@ qxl_image_create_helper(struct qxl_device *qdev, ...@@ -154,23 +218,20 @@ qxl_image_create_helper(struct qxl_device *qdev,
image->u.bitmap.stride = chunk_stride; image->u.bitmap.stride = chunk_stride;
image->u.bitmap.palette = 0; image->u.bitmap.palette = 0;
image->u.bitmap.data = qxl_bo_physical_address(qdev, chunk_bo, 0); image->u.bitmap.data = qxl_bo_physical_address(qdev, chunk_bo, 0);
qxl_release_add_res(qdev, release, chunk_bo);
qxl_bo_unreserve(chunk_bo);
qxl_bo_unref(&chunk_bo);
qxl_bo_kunmap_atomic_page(qdev, *image_bo, ptr); qxl_bo_kunmap_atomic_page(qdev, image_bo, ptr);
return 0; return 0;
} }
int qxl_image_create(struct qxl_device *qdev, int qxl_image_init(struct qxl_device *qdev,
struct qxl_release *release, struct qxl_release *release,
struct qxl_bo **image_bo, struct qxl_drm_image *dimage,
const uint8_t *data, const uint8_t *data,
int x, int y, int width, int height, int x, int y, int width, int height,
int depth, int stride) int depth, int stride)
{ {
data += y * stride + x * (depth / 8); data += y * stride + x * (depth / 8);
return qxl_image_create_helper(qdev, release, image_bo, data, return qxl_image_init_helper(qdev, release, dimage, data,
width, height, depth, 0, stride); width, height, depth, 0, stride);
} }
This diff is collapsed.
...@@ -51,20 +51,21 @@ bool qxl_ttm_bo_is_qxl_bo(struct ttm_buffer_object *bo) ...@@ -51,20 +51,21 @@ bool qxl_ttm_bo_is_qxl_bo(struct ttm_buffer_object *bo)
return false; return false;
} }
void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain) void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain, bool pinned)
{ {
u32 c = 0; u32 c = 0;
u32 pflag = pinned ? TTM_PL_FLAG_NO_EVICT : 0;
qbo->placement.fpfn = 0; qbo->placement.fpfn = 0;
qbo->placement.lpfn = 0; qbo->placement.lpfn = 0;
qbo->placement.placement = qbo->placements; qbo->placement.placement = qbo->placements;
qbo->placement.busy_placement = qbo->placements; qbo->placement.busy_placement = qbo->placements;
if (domain == QXL_GEM_DOMAIN_VRAM) if (domain == QXL_GEM_DOMAIN_VRAM)
qbo->placements[c++] = TTM_PL_FLAG_CACHED | TTM_PL_FLAG_VRAM; qbo->placements[c++] = TTM_PL_FLAG_CACHED | TTM_PL_FLAG_VRAM | pflag;
if (domain == QXL_GEM_DOMAIN_SURFACE) if (domain == QXL_GEM_DOMAIN_SURFACE)
qbo->placements[c++] = TTM_PL_FLAG_CACHED | TTM_PL_FLAG_PRIV0; qbo->placements[c++] = TTM_PL_FLAG_CACHED | TTM_PL_FLAG_PRIV0 | pflag;
if (domain == QXL_GEM_DOMAIN_CPU) if (domain == QXL_GEM_DOMAIN_CPU)
qbo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM; qbo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM | pflag;
if (!c) if (!c)
qbo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM; qbo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
qbo->placement.num_placement = c; qbo->placement.num_placement = c;
...@@ -73,7 +74,7 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain) ...@@ -73,7 +74,7 @@ void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain)
int qxl_bo_create(struct qxl_device *qdev, int qxl_bo_create(struct qxl_device *qdev,
unsigned long size, bool kernel, u32 domain, unsigned long size, bool kernel, bool pinned, u32 domain,
struct qxl_surface *surf, struct qxl_surface *surf,
struct qxl_bo **bo_ptr) struct qxl_bo **bo_ptr)
{ {
...@@ -99,15 +100,15 @@ int qxl_bo_create(struct qxl_device *qdev, ...@@ -99,15 +100,15 @@ int qxl_bo_create(struct qxl_device *qdev,
} }
bo->gem_base.driver_private = NULL; bo->gem_base.driver_private = NULL;
bo->type = domain; bo->type = domain;
bo->pin_count = 0; bo->pin_count = pinned ? 1 : 0;
bo->surface_id = 0; bo->surface_id = 0;
qxl_fence_init(qdev, &bo->fence); qxl_fence_init(qdev, &bo->fence);
INIT_LIST_HEAD(&bo->list); INIT_LIST_HEAD(&bo->list);
atomic_set(&bo->reserve_count, 0);
if (surf) if (surf)
bo->surf = *surf; bo->surf = *surf;
qxl_ttm_placement_from_domain(bo, domain); qxl_ttm_placement_from_domain(bo, domain, pinned);
r = ttm_bo_init(&qdev->mman.bdev, &bo->tbo, size, type, r = ttm_bo_init(&qdev->mman.bdev, &bo->tbo, size, type,
&bo->placement, 0, !kernel, NULL, size, &bo->placement, 0, !kernel, NULL, size,
...@@ -228,7 +229,7 @@ struct qxl_bo *qxl_bo_ref(struct qxl_bo *bo) ...@@ -228,7 +229,7 @@ struct qxl_bo *qxl_bo_ref(struct qxl_bo *bo)
int qxl_bo_pin(struct qxl_bo *bo, u32 domain, u64 *gpu_addr) int qxl_bo_pin(struct qxl_bo *bo, u32 domain, u64 *gpu_addr)
{ {
struct qxl_device *qdev = (struct qxl_device *)bo->gem_base.dev->dev_private; struct qxl_device *qdev = (struct qxl_device *)bo->gem_base.dev->dev_private;
int r, i; int r;
if (bo->pin_count) { if (bo->pin_count) {
bo->pin_count++; bo->pin_count++;
...@@ -236,9 +237,7 @@ int qxl_bo_pin(struct qxl_bo *bo, u32 domain, u64 *gpu_addr) ...@@ -236,9 +237,7 @@ int qxl_bo_pin(struct qxl_bo *bo, u32 domain, u64 *gpu_addr)
*gpu_addr = qxl_bo_gpu_offset(bo); *gpu_addr = qxl_bo_gpu_offset(bo);
return 0; return 0;
} }
qxl_ttm_placement_from_domain(bo, domain); qxl_ttm_placement_from_domain(bo, domain, true);
for (i = 0; i < bo->placement.num_placement; i++)
bo->placements[i] |= TTM_PL_FLAG_NO_EVICT;
r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
if (likely(r == 0)) { if (likely(r == 0)) {
bo->pin_count = 1; bo->pin_count = 1;
...@@ -317,53 +316,6 @@ int qxl_bo_check_id(struct qxl_device *qdev, struct qxl_bo *bo) ...@@ -317,53 +316,6 @@ int qxl_bo_check_id(struct qxl_device *qdev, struct qxl_bo *bo)
return 0; return 0;
} }
void qxl_bo_list_unreserve(struct qxl_reloc_list *reloc_list, bool failed)
{
struct qxl_bo_list *entry, *sf;
list_for_each_entry_safe(entry, sf, &reloc_list->bos, lhead) {
qxl_bo_unreserve(entry->bo);
list_del(&entry->lhead);
kfree(entry);
}
}
int qxl_bo_list_add(struct qxl_reloc_list *reloc_list, struct qxl_bo *bo)
{
struct qxl_bo_list *entry;
int ret;
list_for_each_entry(entry, &reloc_list->bos, lhead) {
if (entry->bo == bo)
return 0;
}
entry = kmalloc(sizeof(struct qxl_bo_list), GFP_KERNEL);
if (!entry)
return -ENOMEM;
entry->bo = bo;
list_add(&entry->lhead, &reloc_list->bos);
ret = qxl_bo_reserve(bo, false);
if (ret)
return ret;
if (!bo->pin_count) {
qxl_ttm_placement_from_domain(bo, bo->type);
ret = ttm_bo_validate(&bo->tbo, &bo->placement,
true, false);
if (ret)
return ret;
}
/* allocate a surface for reserved + validated buffers */
ret = qxl_bo_check_id(bo->gem_base.dev->dev_private, bo);
if (ret)
return ret;
return 0;
}
int qxl_surf_evict(struct qxl_device *qdev) int qxl_surf_evict(struct qxl_device *qdev)
{ {
return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_PRIV0); return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_PRIV0);
......
...@@ -88,7 +88,7 @@ static inline int qxl_bo_wait(struct qxl_bo *bo, u32 *mem_type, ...@@ -88,7 +88,7 @@ static inline int qxl_bo_wait(struct qxl_bo *bo, u32 *mem_type,
extern int qxl_bo_create(struct qxl_device *qdev, extern int qxl_bo_create(struct qxl_device *qdev,
unsigned long size, unsigned long size,
bool kernel, u32 domain, bool kernel, bool pinned, u32 domain,
struct qxl_surface *surf, struct qxl_surface *surf,
struct qxl_bo **bo_ptr); struct qxl_bo **bo_ptr);
extern int qxl_bo_kmap(struct qxl_bo *bo, void **ptr); extern int qxl_bo_kmap(struct qxl_bo *bo, void **ptr);
...@@ -99,9 +99,7 @@ extern struct qxl_bo *qxl_bo_ref(struct qxl_bo *bo); ...@@ -99,9 +99,7 @@ extern struct qxl_bo *qxl_bo_ref(struct qxl_bo *bo);
extern void qxl_bo_unref(struct qxl_bo **bo); extern void qxl_bo_unref(struct qxl_bo **bo);
extern int qxl_bo_pin(struct qxl_bo *bo, u32 domain, u64 *gpu_addr); extern int qxl_bo_pin(struct qxl_bo *bo, u32 domain, u64 *gpu_addr);
extern int qxl_bo_unpin(struct qxl_bo *bo); extern int qxl_bo_unpin(struct qxl_bo *bo);
extern void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain); extern void qxl_ttm_placement_from_domain(struct qxl_bo *qbo, u32 domain, bool pinned);
extern bool qxl_ttm_bo_is_qxl_bo(struct ttm_buffer_object *bo); extern bool qxl_ttm_bo_is_qxl_bo(struct ttm_buffer_object *bo);
extern int qxl_bo_list_add(struct qxl_reloc_list *reloc_list, struct qxl_bo *bo);
extern void qxl_bo_list_unreserve(struct qxl_reloc_list *reloc_list, bool failed);
#endif #endif
...@@ -38,7 +38,8 @@ ...@@ -38,7 +38,8 @@
static const int release_size_per_bo[] = { RELEASE_SIZE, SURFACE_RELEASE_SIZE, RELEASE_SIZE }; static const int release_size_per_bo[] = { RELEASE_SIZE, SURFACE_RELEASE_SIZE, RELEASE_SIZE };
static const int releases_per_bo[] = { RELEASES_PER_BO, SURFACE_RELEASES_PER_BO, RELEASES_PER_BO }; static const int releases_per_bo[] = { RELEASES_PER_BO, SURFACE_RELEASES_PER_BO, RELEASES_PER_BO };
uint64_t
static uint64_t
qxl_release_alloc(struct qxl_device *qdev, int type, qxl_release_alloc(struct qxl_device *qdev, int type,
struct qxl_release **ret) struct qxl_release **ret)
{ {
...@@ -53,9 +54,9 @@ qxl_release_alloc(struct qxl_device *qdev, int type, ...@@ -53,9 +54,9 @@ qxl_release_alloc(struct qxl_device *qdev, int type,
return 0; return 0;
} }
release->type = type; release->type = type;
release->bo_count = 0;
release->release_offset = 0; release->release_offset = 0;
release->surface_release_id = 0; release->surface_release_id = 0;
INIT_LIST_HEAD(&release->bos);
idr_preload(GFP_KERNEL); idr_preload(GFP_KERNEL);
spin_lock(&qdev->release_idr_lock); spin_lock(&qdev->release_idr_lock);
...@@ -77,20 +78,20 @@ void ...@@ -77,20 +78,20 @@ void
qxl_release_free(struct qxl_device *qdev, qxl_release_free(struct qxl_device *qdev,
struct qxl_release *release) struct qxl_release *release)
{ {
int i; struct qxl_bo_list *entry, *tmp;
QXL_INFO(qdev, "release %d, type %d\n", release->id,
QXL_INFO(qdev, "release %d, type %d, %d bos\n", release->id, release->type);
release->type, release->bo_count);
if (release->surface_release_id) if (release->surface_release_id)
qxl_surface_id_dealloc(qdev, release->surface_release_id); qxl_surface_id_dealloc(qdev, release->surface_release_id);
for (i = 0 ; i < release->bo_count; ++i) { list_for_each_entry_safe(entry, tmp, &release->bos, tv.head) {
struct qxl_bo *bo = to_qxl_bo(entry->tv.bo);
QXL_INFO(qdev, "release %llx\n", QXL_INFO(qdev, "release %llx\n",
release->bos[i]->tbo.addr_space_offset entry->tv.bo->addr_space_offset
- DRM_FILE_OFFSET); - DRM_FILE_OFFSET);
qxl_fence_remove_release(&release->bos[i]->fence, release->id); qxl_fence_remove_release(&bo->fence, release->id);
qxl_bo_unref(&release->bos[i]); qxl_bo_unref(&bo);
} }
spin_lock(&qdev->release_idr_lock); spin_lock(&qdev->release_idr_lock);
idr_remove(&qdev->release_idr, release->id); idr_remove(&qdev->release_idr, release->id);
...@@ -98,83 +99,117 @@ qxl_release_free(struct qxl_device *qdev, ...@@ -98,83 +99,117 @@ qxl_release_free(struct qxl_device *qdev,
kfree(release); kfree(release);
} }
void
qxl_release_add_res(struct qxl_device *qdev, struct qxl_release *release,
struct qxl_bo *bo)
{
int i;
for (i = 0; i < release->bo_count; i++)
if (release->bos[i] == bo)
return;
if (release->bo_count >= QXL_MAX_RES) {
DRM_ERROR("exceeded max resource on a qxl_release item\n");
return;
}
release->bos[release->bo_count++] = qxl_bo_ref(bo);
}
static int qxl_release_bo_alloc(struct qxl_device *qdev, static int qxl_release_bo_alloc(struct qxl_device *qdev,
struct qxl_bo **bo) struct qxl_bo **bo)
{ {
int ret; int ret;
ret = qxl_bo_create(qdev, PAGE_SIZE, false, QXL_GEM_DOMAIN_VRAM, NULL, /* pin releases bo's they are too messy to evict */
ret = qxl_bo_create(qdev, PAGE_SIZE, false, true,
QXL_GEM_DOMAIN_VRAM, NULL,
bo); bo);
return ret; return ret;
} }
int qxl_release_reserve(struct qxl_device *qdev, int qxl_release_list_add(struct qxl_release *release, struct qxl_bo *bo)
struct qxl_release *release, bool no_wait) {
struct qxl_bo_list *entry;
list_for_each_entry(entry, &release->bos, tv.head) {
if (entry->tv.bo == &bo->tbo)
return 0;
}
entry = kmalloc(sizeof(struct qxl_bo_list), GFP_KERNEL);
if (!entry)
return -ENOMEM;
qxl_bo_ref(bo);
entry->tv.bo = &bo->tbo;
list_add_tail(&entry->tv.head, &release->bos);
return 0;
}
static int qxl_release_validate_bo(struct qxl_bo *bo)
{ {
int ret; int ret;
if (atomic_inc_return(&release->bos[0]->reserve_count) == 1) {
ret = qxl_bo_reserve(release->bos[0], no_wait); if (!bo->pin_count) {
qxl_ttm_placement_from_domain(bo, bo->type, false);
ret = ttm_bo_validate(&bo->tbo, &bo->placement,
true, false);
if (ret) if (ret)
return ret; return ret;
} }
/* allocate a surface for reserved + validated buffers */
ret = qxl_bo_check_id(bo->gem_base.dev->dev_private, bo);
if (ret)
return ret;
return 0;
}
int qxl_release_reserve_list(struct qxl_release *release, bool no_intr)
{
int ret;
struct qxl_bo_list *entry;
/* if only one object on the release its the release itself
since these objects are pinned no need to reserve */
if (list_is_singular(&release->bos))
return 0;
ret = ttm_eu_reserve_buffers(&release->ticket, &release->bos);
if (ret)
return ret;
list_for_each_entry(entry, &release->bos, tv.head) {
struct qxl_bo *bo = to_qxl_bo(entry->tv.bo);
ret = qxl_release_validate_bo(bo);
if (ret) {
ttm_eu_backoff_reservation(&release->ticket, &release->bos);
return ret;
}
}
return 0; return 0;
} }
void qxl_release_unreserve(struct qxl_device *qdev, void qxl_release_backoff_reserve_list(struct qxl_release *release)
struct qxl_release *release)
{ {
if (atomic_dec_and_test(&release->bos[0]->reserve_count)) /* if only one object on the release its the release itself
qxl_bo_unreserve(release->bos[0]); since these objects are pinned no need to reserve */
if (list_is_singular(&release->bos))
return;
ttm_eu_backoff_reservation(&release->ticket, &release->bos);
} }
int qxl_alloc_surface_release_reserved(struct qxl_device *qdev, int qxl_alloc_surface_release_reserved(struct qxl_device *qdev,
enum qxl_surface_cmd_type surface_cmd_type, enum qxl_surface_cmd_type surface_cmd_type,
struct qxl_release *create_rel, struct qxl_release *create_rel,
struct qxl_release **release) struct qxl_release **release)
{ {
int ret;
if (surface_cmd_type == QXL_SURFACE_CMD_DESTROY && create_rel) { if (surface_cmd_type == QXL_SURFACE_CMD_DESTROY && create_rel) {
int idr_ret; int idr_ret;
struct qxl_bo_list *entry = list_first_entry(&create_rel->bos, struct qxl_bo_list, tv.head);
struct qxl_bo *bo; struct qxl_bo *bo;
union qxl_release_info *info; union qxl_release_info *info;
/* stash the release after the create command */ /* stash the release after the create command */
idr_ret = qxl_release_alloc(qdev, QXL_RELEASE_SURFACE_CMD, release); idr_ret = qxl_release_alloc(qdev, QXL_RELEASE_SURFACE_CMD, release);
bo = qxl_bo_ref(create_rel->bos[0]); bo = qxl_bo_ref(to_qxl_bo(entry->tv.bo));
(*release)->release_offset = create_rel->release_offset + 64; (*release)->release_offset = create_rel->release_offset + 64;
qxl_release_add_res(qdev, *release, bo); qxl_release_list_add(*release, bo);
ret = qxl_release_reserve(qdev, *release, false);
if (ret) {
DRM_ERROR("release reserve failed\n");
goto out_unref;
}
info = qxl_release_map(qdev, *release); info = qxl_release_map(qdev, *release);
info->id = idr_ret; info->id = idr_ret;
qxl_release_unmap(qdev, *release, info); qxl_release_unmap(qdev, *release, info);
out_unref:
qxl_bo_unref(&bo); qxl_bo_unref(&bo);
return ret; return 0;
} }
return qxl_alloc_release_reserved(qdev, sizeof(struct qxl_surface_cmd), return qxl_alloc_release_reserved(qdev, sizeof(struct qxl_surface_cmd),
...@@ -187,7 +222,7 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size, ...@@ -187,7 +222,7 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size,
{ {
struct qxl_bo *bo; struct qxl_bo *bo;
int idr_ret; int idr_ret;
int ret; int ret = 0;
union qxl_release_info *info; union qxl_release_info *info;
int cur_idx; int cur_idx;
...@@ -216,11 +251,6 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size, ...@@ -216,11 +251,6 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size,
mutex_unlock(&qdev->release_mutex); mutex_unlock(&qdev->release_mutex);
return ret; return ret;
} }
/* pin releases bo's they are too messy to evict */
ret = qxl_bo_reserve(qdev->current_release_bo[cur_idx], false);
qxl_bo_pin(qdev->current_release_bo[cur_idx], QXL_GEM_DOMAIN_VRAM, NULL);
qxl_bo_unreserve(qdev->current_release_bo[cur_idx]);
} }
bo = qxl_bo_ref(qdev->current_release_bo[cur_idx]); bo = qxl_bo_ref(qdev->current_release_bo[cur_idx]);
...@@ -231,36 +261,18 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size, ...@@ -231,36 +261,18 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size,
if (rbo) if (rbo)
*rbo = bo; *rbo = bo;
qxl_release_add_res(qdev, *release, bo);
ret = qxl_release_reserve(qdev, *release, false);
mutex_unlock(&qdev->release_mutex); mutex_unlock(&qdev->release_mutex);
if (ret)
goto out_unref; qxl_release_list_add(*release, bo);
info = qxl_release_map(qdev, *release); info = qxl_release_map(qdev, *release);
info->id = idr_ret; info->id = idr_ret;
qxl_release_unmap(qdev, *release, info); qxl_release_unmap(qdev, *release, info);
out_unref:
qxl_bo_unref(&bo); qxl_bo_unref(&bo);
return ret; return ret;
} }
int qxl_fence_releaseable(struct qxl_device *qdev,
struct qxl_release *release)
{
int i, ret;
for (i = 0; i < release->bo_count; i++) {
if (!release->bos[i]->tbo.sync_obj)
release->bos[i]->tbo.sync_obj = &release->bos[i]->fence;
ret = qxl_fence_add_release(&release->bos[i]->fence, release->id);
if (ret)
return ret;
}
return 0;
}
struct qxl_release *qxl_release_from_id_locked(struct qxl_device *qdev, struct qxl_release *qxl_release_from_id_locked(struct qxl_device *qdev,
uint64_t id) uint64_t id)
{ {
...@@ -273,10 +285,7 @@ struct qxl_release *qxl_release_from_id_locked(struct qxl_device *qdev, ...@@ -273,10 +285,7 @@ struct qxl_release *qxl_release_from_id_locked(struct qxl_device *qdev,
DRM_ERROR("failed to find id in release_idr\n"); DRM_ERROR("failed to find id in release_idr\n");
return NULL; return NULL;
} }
if (release->bo_count < 1) {
DRM_ERROR("read a released resource with 0 bos\n");
return NULL;
}
return release; return release;
} }
...@@ -285,9 +294,12 @@ union qxl_release_info *qxl_release_map(struct qxl_device *qdev, ...@@ -285,9 +294,12 @@ union qxl_release_info *qxl_release_map(struct qxl_device *qdev,
{ {
void *ptr; void *ptr;
union qxl_release_info *info; union qxl_release_info *info;
struct qxl_bo *bo = release->bos[0]; struct qxl_bo_list *entry = list_first_entry(&release->bos, struct qxl_bo_list, tv.head);
struct qxl_bo *bo = to_qxl_bo(entry->tv.bo);
ptr = qxl_bo_kmap_atomic_page(qdev, bo, release->release_offset & PAGE_SIZE); ptr = qxl_bo_kmap_atomic_page(qdev, bo, release->release_offset & PAGE_SIZE);
if (!ptr)
return NULL;
info = ptr + (release->release_offset & ~PAGE_SIZE); info = ptr + (release->release_offset & ~PAGE_SIZE);
return info; return info;
} }
...@@ -296,9 +308,51 @@ void qxl_release_unmap(struct qxl_device *qdev, ...@@ -296,9 +308,51 @@ void qxl_release_unmap(struct qxl_device *qdev,
struct qxl_release *release, struct qxl_release *release,
union qxl_release_info *info) union qxl_release_info *info)
{ {
struct qxl_bo *bo = release->bos[0]; struct qxl_bo_list *entry = list_first_entry(&release->bos, struct qxl_bo_list, tv.head);
struct qxl_bo *bo = to_qxl_bo(entry->tv.bo);
void *ptr; void *ptr;
ptr = ((void *)info) - (release->release_offset & ~PAGE_SIZE); ptr = ((void *)info) - (release->release_offset & ~PAGE_SIZE);
qxl_bo_kunmap_atomic_page(qdev, bo, ptr); qxl_bo_kunmap_atomic_page(qdev, bo, ptr);
} }
void qxl_release_fence_buffer_objects(struct qxl_release *release)
{
struct ttm_validate_buffer *entry;
struct ttm_buffer_object *bo;
struct ttm_bo_global *glob;
struct ttm_bo_device *bdev;
struct ttm_bo_driver *driver;
struct qxl_bo *qbo;
/* if only one object on the release its the release itself
since these objects are pinned no need to reserve */
if (list_is_singular(&release->bos))
return;
bo = list_first_entry(&release->bos, struct ttm_validate_buffer, head)->bo;
bdev = bo->bdev;
driver = bdev->driver;
glob = bo->glob;
spin_lock(&glob->lru_lock);
spin_lock(&bdev->fence_lock);
list_for_each_entry(entry, &release->bos, head) {
bo = entry->bo;
qbo = to_qxl_bo(bo);
if (!entry->bo->sync_obj)
entry->bo->sync_obj = &qbo->fence;
qxl_fence_add_release_locked(&qbo->fence, release->id);
ttm_bo_add_to_lru(bo);
ww_mutex_unlock(&bo->resv->lock);
entry->reserved = false;
}
spin_unlock(&bdev->fence_lock);
spin_unlock(&glob->lru_lock);
ww_acquire_fini(&release->ticket);
}
...@@ -206,7 +206,7 @@ static void qxl_evict_flags(struct ttm_buffer_object *bo, ...@@ -206,7 +206,7 @@ static void qxl_evict_flags(struct ttm_buffer_object *bo,
return; return;
} }
qbo = container_of(bo, struct qxl_bo, tbo); qbo = container_of(bo, struct qxl_bo, tbo);
qxl_ttm_placement_from_domain(qbo, QXL_GEM_DOMAIN_CPU); qxl_ttm_placement_from_domain(qbo, QXL_GEM_DOMAIN_CPU, false);
*placement = qbo->placement; *placement = qbo->placement;
} }
......
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