Commit 382d62e5 authored by Marcin Slusarz's avatar Marcin Slusarz Committed by Ben Skeggs

drm/nouveau: fix annoying nouveau_fence type issue

nouveau_fence_* functions are not type safe, which could lead to bugs.
Additionally every use of nouveau_fence_unref had to cast struct
nouveau_fence to void **.
Fix it by renaming old functions and creating static inline functions with
new prototypes. We still need old functions, because we pass function
pointers to ttm.
As we are wrapping functions, drop unused "void *arg" parameter where possible.
Signed-off-by: default avatarMarcin Slusarz <marcin.slusarz@gmail.com>
Signed-off-by: default avatarFrancisco Jerez <currojerez@riseup.net>
Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 5f80198e
...@@ -487,7 +487,7 @@ nouveau_bo_move_accel_cleanup(struct nouveau_channel *chan, ...@@ -487,7 +487,7 @@ nouveau_bo_move_accel_cleanup(struct nouveau_channel *chan,
ret = ttm_bo_move_accel_cleanup(&nvbo->bo, fence, NULL, evict, ret = ttm_bo_move_accel_cleanup(&nvbo->bo, fence, NULL, evict,
no_wait_reserve, no_wait_gpu, new_mem); no_wait_reserve, no_wait_gpu, new_mem);
nouveau_fence_unref((void *)&fence); nouveau_fence_unref(&fence);
return ret; return ret;
} }
...@@ -949,11 +949,11 @@ struct ttm_bo_driver nouveau_bo_driver = { ...@@ -949,11 +949,11 @@ struct ttm_bo_driver nouveau_bo_driver = {
.evict_flags = nouveau_bo_evict_flags, .evict_flags = nouveau_bo_evict_flags,
.move = nouveau_bo_move, .move = nouveau_bo_move,
.verify_access = nouveau_bo_verify_access, .verify_access = nouveau_bo_verify_access,
.sync_obj_signaled = nouveau_fence_signalled, .sync_obj_signaled = __nouveau_fence_signalled,
.sync_obj_wait = nouveau_fence_wait, .sync_obj_wait = __nouveau_fence_wait,
.sync_obj_flush = nouveau_fence_flush, .sync_obj_flush = __nouveau_fence_flush,
.sync_obj_unref = nouveau_fence_unref, .sync_obj_unref = __nouveau_fence_unref,
.sync_obj_ref = nouveau_fence_ref, .sync_obj_ref = __nouveau_fence_ref,
.fault_reserve_notify = &nouveau_ttm_fault_reserve_notify, .fault_reserve_notify = &nouveau_ttm_fault_reserve_notify,
.io_mem_reserve = &nouveau_ttm_io_mem_reserve, .io_mem_reserve = &nouveau_ttm_io_mem_reserve,
.io_mem_free = &nouveau_ttm_io_mem_free, .io_mem_free = &nouveau_ttm_io_mem_free,
......
...@@ -303,8 +303,8 @@ nouveau_channel_put_unlocked(struct nouveau_channel **pchan) ...@@ -303,8 +303,8 @@ nouveau_channel_put_unlocked(struct nouveau_channel **pchan)
ret = nouveau_fence_new(chan, &fence, true); ret = nouveau_fence_new(chan, &fence, true);
if (ret == 0) { if (ret == 0) {
ret = nouveau_fence_wait(fence, NULL, false, false); ret = nouveau_fence_wait(fence, false, false);
nouveau_fence_unref((void *)&fence); nouveau_fence_unref(&fence);
} }
if (ret) if (ret)
......
...@@ -205,8 +205,8 @@ nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state) ...@@ -205,8 +205,8 @@ nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state)
ret = nouveau_fence_new(chan, &fence, true); ret = nouveau_fence_new(chan, &fence, true);
if (ret == 0) { if (ret == 0) {
ret = nouveau_fence_wait(fence, NULL, false, false); ret = nouveau_fence_wait(fence, false, false);
nouveau_fence_unref((void *)&fence); nouveau_fence_unref(&fence);
} }
if (ret) { if (ret) {
......
...@@ -1264,12 +1264,35 @@ extern void nouveau_fence_work(struct nouveau_fence *fence, ...@@ -1264,12 +1264,35 @@ extern void nouveau_fence_work(struct nouveau_fence *fence,
void (*work)(void *priv, bool signalled), void (*work)(void *priv, bool signalled),
void *priv); void *priv);
struct nouveau_channel *nouveau_fence_channel(struct nouveau_fence *); struct nouveau_channel *nouveau_fence_channel(struct nouveau_fence *);
extern bool nouveau_fence_signalled(void *obj, void *arg);
extern int nouveau_fence_wait(void *obj, void *arg, bool lazy, bool intr); extern bool __nouveau_fence_signalled(void *obj, void *arg);
extern int __nouveau_fence_wait(void *obj, void *arg, bool lazy, bool intr);
extern int __nouveau_fence_flush(void *obj, void *arg);
extern void __nouveau_fence_unref(void **obj);
extern void *__nouveau_fence_ref(void *obj);
static inline bool nouveau_fence_signalled(struct nouveau_fence *obj)
{
return __nouveau_fence_signalled(obj, NULL);
}
static inline int
nouveau_fence_wait(struct nouveau_fence *obj, bool lazy, bool intr)
{
return __nouveau_fence_wait(obj, NULL, lazy, intr);
}
extern int nouveau_fence_sync(struct nouveau_fence *, struct nouveau_channel *); extern int nouveau_fence_sync(struct nouveau_fence *, struct nouveau_channel *);
extern int nouveau_fence_flush(void *obj, void *arg); static inline int nouveau_fence_flush(struct nouveau_fence *obj)
extern void nouveau_fence_unref(void **obj); {
extern void *nouveau_fence_ref(void *obj); return __nouveau_fence_flush(obj, NULL);
}
static inline void nouveau_fence_unref(struct nouveau_fence **obj)
{
__nouveau_fence_unref((void **)obj);
}
static inline struct nouveau_fence *nouveau_fence_ref(struct nouveau_fence *obj)
{
return __nouveau_fence_ref(obj);
}
/* nouveau_gem.c */ /* nouveau_gem.c */
extern int nouveau_gem_new(struct drm_device *, struct nouveau_channel *, extern int nouveau_gem_new(struct drm_device *, struct nouveau_channel *,
......
...@@ -120,7 +120,7 @@ nouveau_fence_new(struct nouveau_channel *chan, struct nouveau_fence **pfence, ...@@ -120,7 +120,7 @@ nouveau_fence_new(struct nouveau_channel *chan, struct nouveau_fence **pfence,
ret = nouveau_fence_emit(fence); ret = nouveau_fence_emit(fence);
if (ret) if (ret)
nouveau_fence_unref((void *)&fence); nouveau_fence_unref(&fence);
*pfence = fence; *pfence = fence;
return ret; return ret;
} }
...@@ -183,7 +183,7 @@ nouveau_fence_work(struct nouveau_fence *fence, ...@@ -183,7 +183,7 @@ nouveau_fence_work(struct nouveau_fence *fence,
} }
void void
nouveau_fence_unref(void **sync_obj) __nouveau_fence_unref(void **sync_obj)
{ {
struct nouveau_fence *fence = nouveau_fence(*sync_obj); struct nouveau_fence *fence = nouveau_fence(*sync_obj);
...@@ -193,7 +193,7 @@ nouveau_fence_unref(void **sync_obj) ...@@ -193,7 +193,7 @@ nouveau_fence_unref(void **sync_obj)
} }
void * void *
nouveau_fence_ref(void *sync_obj) __nouveau_fence_ref(void *sync_obj)
{ {
struct nouveau_fence *fence = nouveau_fence(sync_obj); struct nouveau_fence *fence = nouveau_fence(sync_obj);
...@@ -202,7 +202,7 @@ nouveau_fence_ref(void *sync_obj) ...@@ -202,7 +202,7 @@ nouveau_fence_ref(void *sync_obj)
} }
bool bool
nouveau_fence_signalled(void *sync_obj, void *sync_arg) __nouveau_fence_signalled(void *sync_obj, void *sync_arg)
{ {
struct nouveau_fence *fence = nouveau_fence(sync_obj); struct nouveau_fence *fence = nouveau_fence(sync_obj);
struct nouveau_channel *chan = fence->channel; struct nouveau_channel *chan = fence->channel;
...@@ -215,13 +215,13 @@ nouveau_fence_signalled(void *sync_obj, void *sync_arg) ...@@ -215,13 +215,13 @@ nouveau_fence_signalled(void *sync_obj, void *sync_arg)
} }
int int
nouveau_fence_wait(void *sync_obj, void *sync_arg, bool lazy, bool intr) __nouveau_fence_wait(void *sync_obj, void *sync_arg, bool lazy, bool intr)
{ {
unsigned long timeout = jiffies + (3 * DRM_HZ); unsigned long timeout = jiffies + (3 * DRM_HZ);
int ret = 0; int ret = 0;
while (1) { while (1) {
if (nouveau_fence_signalled(sync_obj, sync_arg)) if (__nouveau_fence_signalled(sync_obj, sync_arg))
break; break;
if (time_after_eq(jiffies, timeout)) { if (time_after_eq(jiffies, timeout)) {
...@@ -369,7 +369,7 @@ emit_semaphore(struct nouveau_channel *chan, int method, ...@@ -369,7 +369,7 @@ emit_semaphore(struct nouveau_channel *chan, int method,
kref_get(&sema->ref); kref_get(&sema->ref);
nouveau_fence_work(fence, semaphore_work, sema); nouveau_fence_work(fence, semaphore_work, sema);
nouveau_fence_unref((void *)&fence); nouveau_fence_unref(&fence);
return 0; return 0;
} }
...@@ -384,14 +384,14 @@ nouveau_fence_sync(struct nouveau_fence *fence, ...@@ -384,14 +384,14 @@ nouveau_fence_sync(struct nouveau_fence *fence,
int ret = 0; int ret = 0;
if (likely(!chan || chan == wchan || if (likely(!chan || chan == wchan ||
nouveau_fence_signalled(fence, NULL))) nouveau_fence_signalled(fence)))
goto out; goto out;
sema = alloc_semaphore(dev); sema = alloc_semaphore(dev);
if (!sema) { if (!sema) {
/* Early card or broken userspace, fall back to /* Early card or broken userspace, fall back to
* software sync. */ * software sync. */
ret = nouveau_fence_wait(fence, NULL, true, false); ret = nouveau_fence_wait(fence, true, false);
goto out; goto out;
} }
...@@ -400,7 +400,7 @@ nouveau_fence_sync(struct nouveau_fence *fence, ...@@ -400,7 +400,7 @@ nouveau_fence_sync(struct nouveau_fence *fence,
* order issues * order issues
*/ */
if (!mutex_trylock(&chan->mutex)) { if (!mutex_trylock(&chan->mutex)) {
ret = nouveau_fence_wait(fence, NULL, true, false); ret = nouveau_fence_wait(fence, true, false);
goto out_unref; goto out_unref;
} }
...@@ -423,7 +423,7 @@ nouveau_fence_sync(struct nouveau_fence *fence, ...@@ -423,7 +423,7 @@ nouveau_fence_sync(struct nouveau_fence *fence,
} }
int int
nouveau_fence_flush(void *sync_obj, void *sync_arg) __nouveau_fence_flush(void *sync_obj, void *sync_arg)
{ {
return 0; return 0;
} }
......
...@@ -238,7 +238,7 @@ validate_fini_list(struct list_head *list, struct nouveau_fence *fence) ...@@ -238,7 +238,7 @@ validate_fini_list(struct list_head *list, struct nouveau_fence *fence)
prev_fence = nvbo->bo.sync_obj; prev_fence = nvbo->bo.sync_obj;
nvbo->bo.sync_obj = nouveau_fence_ref(fence); nvbo->bo.sync_obj = nouveau_fence_ref(fence);
spin_unlock(&nvbo->bo.bdev->fence_lock); spin_unlock(&nvbo->bo.bdev->fence_lock);
nouveau_fence_unref((void *)&prev_fence); nouveau_fence_unref(&prev_fence);
} }
if (unlikely(nvbo->validate_mapped)) { if (unlikely(nvbo->validate_mapped)) {
...@@ -728,7 +728,7 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data, ...@@ -728,7 +728,7 @@ nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
out: out:
validate_fini(&op, fence); validate_fini(&op, fence);
nouveau_fence_unref((void**)&fence); nouveau_fence_unref(&fence);
kfree(bo); kfree(bo);
kfree(push); kfree(push);
......
...@@ -54,7 +54,7 @@ nv10_mem_set_region_tiling(struct drm_device *dev, int i, uint32_t addr, ...@@ -54,7 +54,7 @@ nv10_mem_set_region_tiling(struct drm_device *dev, int i, uint32_t addr,
tile->addr = addr; tile->addr = addr;
tile->size = size; tile->size = size;
tile->used = !!pitch; tile->used = !!pitch;
nouveau_fence_unref((void **)&tile->fence); nouveau_fence_unref(&tile->fence);
pfifo->reassign(dev, false); pfifo->reassign(dev, false);
pfifo->cache_pull(dev, false); pfifo->cache_pull(dev, false);
...@@ -87,7 +87,7 @@ nv10_mem_set_tiling(struct drm_device *dev, uint32_t addr, uint32_t size, ...@@ -87,7 +87,7 @@ nv10_mem_set_tiling(struct drm_device *dev, uint32_t addr, uint32_t size,
continue; continue;
if (tile->fence && if (tile->fence &&
!nouveau_fence_signalled(tile->fence, NULL)) !nouveau_fence_signalled(tile->fence))
/* Pending tile region. */ /* Pending tile region. */
continue; continue;
......
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