Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6295 → Rev 6296

/drivers/video/drm/vmwgfx/vmwgfx_dmabuf.c
1,6 → 1,6
/**************************************************************************
*
* Copyright © 2011 VMware, Inc., Palo Alto, CA., USA
* Copyright © 2011-2015 VMware, Inc., Palo Alto, CA., USA
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
32,22 → 32,17
 
 
/**
* vmw_dmabuf_to_placement - Validate a buffer to placement.
* vmw_dmabuf_pin_in_placement - Validate a buffer to placement.
*
* @dev_priv: Driver private.
* @buf: DMA buffer to move.
* @pin: Pin buffer if true.
* @placement: The placement to pin it.
* @interruptible: Use interruptible wait.
*
* May only be called by the current master since it assumes that the
* master lock is the current master's lock.
* This function takes the master's lock in write mode.
* Flushes and unpins the query bo to avoid failures.
*
* Returns
* -ERESTARTSYS if interrupted by a signal.
*/
int vmw_dmabuf_to_placement(struct vmw_private *dev_priv,
int vmw_dmabuf_pin_in_placement(struct vmw_private *dev_priv,
struct vmw_dma_buffer *buf,
struct ttm_placement *placement,
bool interruptible)
55,9 → 50,9
struct ttm_buffer_object *bo = &buf->base;
int ret;
 
// ret = ttm_write_lock(&vmaster->lock, interruptible);
// if (unlikely(ret != 0))
// return ret;
ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible);
if (unlikely(ret != 0))
return ret;
 
vmw_execbuf_release_pinned_bo(dev_priv);
 
66,21 → 61,21
goto err;
 
ret = ttm_bo_validate(bo, placement, interruptible, false);
if (!ret)
vmw_bo_pin_reserved(buf, true);
 
ttm_bo_unreserve(bo);
 
err:
// ttm_write_unlock(&vmaster->lock);
ttm_write_unlock(&dev_priv->reservation_sem);
return ret;
}
 
/**
* vmw_dmabuf_to_vram_or_gmr - Move a buffer to vram or gmr.
* vmw_dmabuf_pin_in_vram_or_gmr - Move a buffer to vram or gmr.
*
* May only be called by the current master since it assumes that the
* master lock is the current master's lock.
* This function takes the master's lock in write mode.
* Flushes and unpins the query bo if @pin == true to avoid failures.
* This function takes the reservation_sem in write mode.
* Flushes and unpins the query bo to avoid failures.
*
* @dev_priv: Driver private.
* @buf: DMA buffer to move.
90,19 → 85,17
* Returns
* -ERESTARTSYS if interrupted by a signal.
*/
int vmw_dmabuf_to_vram_or_gmr(struct vmw_private *dev_priv,
int vmw_dmabuf_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
struct vmw_dma_buffer *buf,
bool pin, bool interruptible)
bool interruptible)
{
struct ttm_buffer_object *bo = &buf->base;
struct ttm_placement *placement;
int ret;
 
// ret = ttm_write_lock(&vmaster->lock, interruptible);
// if (unlikely(ret != 0))
// return ret;
ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible);
if (unlikely(ret != 0))
return ret;
 
if (pin)
vmw_execbuf_release_pinned_bo(dev_priv);
 
ret = ttm_bo_reserve(bo, interruptible, false, false, NULL);
109,114 → 102,87
if (unlikely(ret != 0))
goto err;
 
/**
* Put BO in VRAM if there is space, otherwise as a GMR.
* If there is no space in VRAM and GMR ids are all used up,
* start evicting GMRs to make room. If the DMA buffer can't be
* used as a GMR, this will return -ENOMEM.
*/
 
if (pin)
placement = &vmw_vram_gmr_ne_placement;
else
placement = &vmw_vram_gmr_placement;
 
ret = ttm_bo_validate(bo, placement, interruptible, false);
ret = ttm_bo_validate(bo, &vmw_vram_gmr_placement, interruptible,
false);
if (likely(ret == 0) || ret == -ERESTARTSYS)
goto err_unreserve;
goto out_unreserve;
 
ret = ttm_bo_validate(bo, &vmw_vram_placement, interruptible, false);
 
/**
* If that failed, try VRAM again, this time evicting
* previous contents.
*/
out_unreserve:
if (!ret)
vmw_bo_pin_reserved(buf, true);
 
if (pin)
placement = &vmw_vram_ne_placement;
else
placement = &vmw_vram_placement;
 
ret = ttm_bo_validate(bo, placement, interruptible, false);
 
err_unreserve:
ttm_bo_unreserve(bo);
err:
// ttm_write_unlock(&vmaster->lock);
ttm_write_unlock(&dev_priv->reservation_sem);
return ret;
}
 
/**
* vmw_dmabuf_to_vram - Move a buffer to vram.
* vmw_dmabuf_pin_in_vram - Move a buffer to vram.
*
* May only be called by the current master since it assumes that the
* master lock is the current master's lock.
* This function takes the master's lock in write mode.
* This function takes the reservation_sem in write mode.
* Flushes and unpins the query bo to avoid failures.
*
* @dev_priv: Driver private.
* @buf: DMA buffer to move.
* @pin: Pin buffer in vram if true.
* @interruptible: Use interruptible wait.
*
* Returns
* -ERESTARTSYS if interrupted by a signal.
*/
int vmw_dmabuf_to_vram(struct vmw_private *dev_priv,
int vmw_dmabuf_pin_in_vram(struct vmw_private *dev_priv,
struct vmw_dma_buffer *buf,
bool pin, bool interruptible)
bool interruptible)
{
struct ttm_placement *placement;
 
if (pin)
placement = &vmw_vram_ne_placement;
else
placement = &vmw_vram_placement;
 
return vmw_dmabuf_to_placement(dev_priv, buf,
placement,
return vmw_dmabuf_pin_in_placement(dev_priv, buf, &vmw_vram_placement,
interruptible);
}
 
/**
* vmw_dmabuf_to_start_of_vram - Move a buffer to start of vram.
* vmw_dmabuf_pin_in_start_of_vram - Move a buffer to start of vram.
*
* May only be called by the current master since it assumes that the
* master lock is the current master's lock.
* This function takes the master's lock in write mode.
* Flushes and unpins the query bo if @pin == true to avoid failures.
* This function takes the reservation_sem in write mode.
* Flushes and unpins the query bo to avoid failures.
*
* @dev_priv: Driver private.
* @buf: DMA buffer to move.
* @pin: Pin buffer in vram if true.
* @buf: DMA buffer to pin.
* @interruptible: Use interruptible wait.
*
* Returns
* -ERESTARTSYS if interrupted by a signal.
*/
int vmw_dmabuf_to_start_of_vram(struct vmw_private *dev_priv,
int vmw_dmabuf_pin_in_start_of_vram(struct vmw_private *dev_priv,
struct vmw_dma_buffer *buf,
bool pin, bool interruptible)
bool interruptible)
{
struct ttm_buffer_object *bo = &buf->base;
struct ttm_placement placement;
struct ttm_place place;
int ret = 0;
 
if (pin)
placement = vmw_vram_ne_placement;
else
placement = vmw_vram_placement;
placement.lpfn = bo->num_pages;
place = vmw_vram_placement.placement[0];
place.lpfn = bo->num_pages;
placement.num_placement = 1;
placement.placement = &place;
placement.num_busy_placement = 1;
placement.busy_placement = &place;
 
// ret = ttm_write_lock(&vmaster->lock, interruptible);
// if (unlikely(ret != 0))
// return ret;
ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible);
if (unlikely(ret != 0))
return ret;
 
if (pin)
vmw_execbuf_release_pinned_bo(dev_priv);
ret = ttm_bo_reserve(bo, interruptible, false, false, NULL);
if (unlikely(ret != 0))
goto err_unlock;
 
/* Is this buffer already in vram but not at the start of it? */
/*
* Is this buffer already in vram but not at the start of it?
* In that case, evict it first because TTM isn't good at handling
* that situation.
*/
if (bo->mem.mem_type == TTM_PL_VRAM &&
bo->mem.start < bo->num_pages &&
bo->mem.start > 0)
224,23 → 190,22
 
ret = ttm_bo_validate(bo, &placement, interruptible, false);
 
/* For some reason we didn't up at the start of vram */
/* For some reason we didn't end up at the start of vram */
WARN_ON(ret == 0 && bo->offset != 0);
if (!ret)
vmw_bo_pin_reserved(buf, true);
 
ttm_bo_unreserve(bo);
err_unlock:
// ttm_write_unlock(&vmaster->lock);
ttm_write_unlock(&dev_priv->reservation_sem);
 
return ret;
}
 
 
/**
* vmw_dmabuf_upin - Unpin the buffer given buffer, does not move the buffer.
* vmw_dmabuf_unpin - Unpin the buffer given buffer, does not move the buffer.
*
* May only be called by the current master since it assumes that the
* master lock is the current master's lock.
* This function takes the master's lock in write mode.
* This function takes the reservation_sem in write mode.
*
* @dev_priv: Driver private.
* @buf: DMA buffer to unpin.
253,17 → 218,26
struct vmw_dma_buffer *buf,
bool interruptible)
{
/*
* We could in theory early out if the buffer is
* unpinned but we need to lock and reserve the buffer
* anyways so we don't gain much by that.
*/
return vmw_dmabuf_to_placement(dev_priv, buf,
&vmw_evictable_placement,
interruptible);
struct ttm_buffer_object *bo = &buf->base;
int ret;
 
ret = ttm_read_lock(&dev_priv->reservation_sem, interruptible);
if (unlikely(ret != 0))
return ret;
 
ret = ttm_bo_reserve(bo, interruptible, false, false, NULL);
if (unlikely(ret != 0))
goto err;
 
vmw_bo_pin_reserved(buf, false);
 
ttm_bo_unreserve(bo);
 
err:
ttm_read_unlock(&dev_priv->reservation_sem);
return ret;
}
 
 
/**
* vmw_bo_get_guest_ptr - Get the guest ptr representing the current placement
* of a buffer.
285,29 → 259,41
 
 
/**
* vmw_bo_pin - Pin or unpin a buffer object without moving it.
* vmw_bo_pin_reserved - Pin or unpin a buffer object without moving it.
*
* @bo: The buffer object. Must be reserved.
* @vbo: The buffer object. Must be reserved.
* @pin: Whether to pin or unpin.
*
*/
void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin)
void vmw_bo_pin_reserved(struct vmw_dma_buffer *vbo, bool pin)
{
uint32_t pl_flags;
struct ttm_place pl;
struct ttm_placement placement;
struct ttm_buffer_object *bo = &vbo->base;
uint32_t old_mem_type = bo->mem.mem_type;
int ret;
 
lockdep_assert_held(&bo->resv->lock.base);
 
pl_flags = TTM_PL_FLAG_VRAM | VMW_PL_FLAG_GMR | VMW_PL_FLAG_MOB
if (pin) {
if (vbo->pin_count++ > 0)
return;
} else {
WARN_ON(vbo->pin_count <= 0);
if (--vbo->pin_count > 0)
return;
}
 
pl.fpfn = 0;
pl.lpfn = 0;
pl.flags = TTM_PL_FLAG_VRAM | VMW_PL_FLAG_GMR | VMW_PL_FLAG_MOB
| TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED;
if (pin)
pl_flags |= TTM_PL_FLAG_NO_EVICT;
pl.flags |= TTM_PL_FLAG_NO_EVICT;
 
memset(&placement, 0, sizeof(placement));
placement.num_placement = 1;
placement.placement = &pl_flags;
placement.placement = &pl;
 
ret = ttm_bo_validate(bo, &placement, false, true);