Commit 4b9e45e6 authored by Thomas Hellstrom's avatar Thomas Hellstrom

drm/vmwgfx: Ditch the vmw_dummy_query_bo_prepare function

Combine it with vmw_dummy_query_bo_create, and also make sure
we use tryreserve when reserving the bo to avoid any lockdep warnings
We are sure the tryreserve will always succeed since we are
the only users at that point.
In addition, allow the vmw_bo_pin function to pin/unpin system memory.
Signed-off-by: default avatarThomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: default avatarJakob Bornecrantz <jakob@vmware.com>
parent 173fb7d4
...@@ -290,8 +290,7 @@ void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *bo, ...@@ -290,8 +290,7 @@ void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *bo,
/** /**
* vmw_bo_pin - Pin or unpin a buffer object without moving it. * vmw_bo_pin - Pin or unpin a buffer object without moving it.
* *
* @bo: The buffer object. Must be reserved, and present either in VRAM * @bo: The buffer object. Must be reserved.
* or GMR memory.
* @pin: Whether to pin or unpin. * @pin: Whether to pin or unpin.
* *
*/ */
...@@ -303,12 +302,9 @@ void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin) ...@@ -303,12 +302,9 @@ void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin)
int ret; int ret;
lockdep_assert_held(&bo->resv->lock.base); lockdep_assert_held(&bo->resv->lock.base);
BUG_ON(old_mem_type != TTM_PL_VRAM &&
old_mem_type != VMW_PL_GMR &&
old_mem_type != VMW_PL_MOB);
pl_flags = TTM_PL_FLAG_VRAM | VMW_PL_FLAG_GMR | VMW_PL_FLAG_MOB pl_flags = TTM_PL_FLAG_VRAM | VMW_PL_FLAG_GMR | VMW_PL_FLAG_MOB
| TTM_PL_FLAG_CACHED; | TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED;
if (pin) if (pin)
pl_flags |= TTM_PL_FLAG_NO_EVICT; pl_flags |= TTM_PL_FLAG_NO_EVICT;
......
...@@ -281,36 +281,44 @@ static void vmw_print_capabilities(uint32_t capabilities) ...@@ -281,36 +281,44 @@ static void vmw_print_capabilities(uint32_t capabilities)
DRM_INFO(" Guest Backed Resources.\n"); DRM_INFO(" Guest Backed Resources.\n");
} }
/** /**
* vmw_execbuf_prepare_dummy_query - Initialize a query result structure at * vmw_dummy_query_bo_create - create a bo to hold a dummy query result
* the start of a buffer object.
* *
* @dev_priv: The device private structure. * @dev_priv: A device private structure.
* *
* This function will idle the buffer using an uninterruptible wait, then * This function creates a small buffer object that holds the query
* map the first page and initialize a pending occlusion query result structure, * result for dummy queries emitted as query barriers.
* Finally it will unmap the buffer. * The function will then map the first page and initialize a pending
* occlusion query result structure, Finally it will unmap the buffer.
* No interruptible waits are done within this function.
* *
* TODO: Since we're only mapping a single page, we should optimize the map * Returns an error if bo creation or initialization fails.
* to use kmap_atomic / iomap_atomic.
*/ */
static void vmw_dummy_query_bo_prepare(struct vmw_private *dev_priv) static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv)
{ {
int ret;
struct ttm_buffer_object *bo;
struct ttm_bo_kmap_obj map; struct ttm_bo_kmap_obj map;
volatile SVGA3dQueryResult *result; volatile SVGA3dQueryResult *result;
bool dummy; bool dummy;
int ret;
struct ttm_bo_device *bdev = &dev_priv->bdev;
struct ttm_buffer_object *bo = dev_priv->dummy_query_bo;
ttm_bo_reserve(bo, false, false, false, 0); /*
spin_lock(&bdev->fence_lock); * Create the bo as pinned, so that a tryreserve will
ret = ttm_bo_wait(bo, false, false, false); * immediately succeed. This is because we're the only
spin_unlock(&bdev->fence_lock); * user of the bo currently.
*/
ret = ttm_bo_create(&dev_priv->bdev,
PAGE_SIZE,
ttm_bo_type_device,
&vmw_sys_ne_placement,
0, false, NULL,
&bo);
if (unlikely(ret != 0)) if (unlikely(ret != 0))
(void) vmw_fallback_wait(dev_priv, false, true, 0, false, return ret;
10*HZ);
ret = ttm_bo_reserve(bo, false, true, false, 0);
BUG_ON(ret != 0);
ret = ttm_bo_kmap(bo, 0, 1, &map); ret = ttm_bo_kmap(bo, 0, 1, &map);
if (likely(ret == 0)) { if (likely(ret == 0)) {
...@@ -319,34 +327,19 @@ static void vmw_dummy_query_bo_prepare(struct vmw_private *dev_priv) ...@@ -319,34 +327,19 @@ static void vmw_dummy_query_bo_prepare(struct vmw_private *dev_priv)
result->state = SVGA3D_QUERYSTATE_PENDING; result->state = SVGA3D_QUERYSTATE_PENDING;
result->result32 = 0xff; result->result32 = 0xff;
ttm_bo_kunmap(&map); ttm_bo_kunmap(&map);
} else }
DRM_ERROR("Dummy query buffer map failed.\n"); vmw_bo_pin(bo, false);
ttm_bo_unreserve(bo); ttm_bo_unreserve(bo);
}
if (unlikely(ret != 0)) {
DRM_ERROR("Dummy query buffer map failed.\n");
ttm_bo_unref(&bo);
} else
dev_priv->dummy_query_bo = bo;
/** return ret;
* vmw_dummy_query_bo_create - create a bo to hold a dummy query result
*
* @dev_priv: A device private structure.
*
* This function creates a small buffer object that holds the query
* result for dummy queries emitted as query barriers.
* No interruptible waits are done within this function.
*
* Returns an error if bo creation fails.
*/
static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv)
{
return ttm_bo_create(&dev_priv->bdev,
PAGE_SIZE,
ttm_bo_type_device,
&vmw_vram_sys_placement,
0, false, NULL,
&dev_priv->dummy_query_bo);
} }
static int vmw_request_device(struct vmw_private *dev_priv) static int vmw_request_device(struct vmw_private *dev_priv)
{ {
int ret; int ret;
...@@ -368,7 +361,6 @@ static int vmw_request_device(struct vmw_private *dev_priv) ...@@ -368,7 +361,6 @@ static int vmw_request_device(struct vmw_private *dev_priv)
ret = vmw_dummy_query_bo_create(dev_priv); ret = vmw_dummy_query_bo_create(dev_priv);
if (unlikely(ret != 0)) if (unlikely(ret != 0))
goto out_no_query_bo; goto out_no_query_bo;
vmw_dummy_query_bo_prepare(dev_priv);
return 0; return 0;
......
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