drm/radeon/kms: wait on correct fence in wait_fb callback

wait_fb callback is used to wait for push operation to finish.
We have the right fences to wait on (it's in the radeon_crtc
structure) so there is no need to wait for all existing
fences.

This patch also plugs a memory leak that was caused by waiting
in frame N on a fence from frame N-1. On detach, there was a
possiblity that the very last fence was never unreferenced.
With this patch, if there is an outstanding last fence, we
will unreference it on detach.

Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com>
vcrtcm: mark a function static

Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com>
v4l2pim: call wait_fb in detach, not destroy

Calling wait_fb function in destroy_pcon has little value
because by that time all transmission is gone, all push buffers
freed and and PCON is detached. So there is nothing to wait on.
The correct place to wait is the detach function: after we
have stopped the vblank thread and no new pushes are being
scheduled, we still have to wait for the last outstanding
one (which could be in the GPU's queue) to finish.

Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com>
udlpim: call wait_fb in detach, not destroy

Calling wait_fb function in destroy_pcon has little value
because by that time all transmission is gone, all push buffers
freed and and PCON is detached. So there is nothing to wait on.
The correct place to wait is the detach function: after we
have stopped the vblank thread and no new pushes are being
scheduled, we still have to wait for the last outstanding
one (which could be in the GPU's queue) to finish.

Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com>
udlpim: do not keep stale pointer to mapping

When buffer is unmapped, we need to set the mapping
pointer in pcon structure to NULL. Otherwise,
the realloc function may think that we have a mapping
in place when we don't.

Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com>
v4l2pim: do not keep stale pointer to mapping

When buffer is unmapped, we need to set the mapping
pointer in pcon structure to NULL. Otherwise,
the realloc function may think that we have a mapping
in place when we don't.

Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com>
v4l2pim: fix an error message

Error should not be info and it should be terminated with
a newline character.

Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com>
vcrtcm: narrow range of spin lock

The alloc spin lock was being held during the calls to vcrtcm_get_pim
and vcrtcm_get_pcon, both of which lock a mutex.  Attempting to lock
a mutex while holding a spin lock is against the rules.  This commit
narrows the range of the spin lock, while still preserving the
protection of the critical section.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
vcrtcm: eliminate no-longer-accurate comments

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
vcrtcm: remove all use of pcon spin lock

The pcon locking scheme is being rearchitected.  This is the
first commit in a series of commits that implement the new scheme.
This first commit removes all use of the per-pcon spin lock.
The system after this commit still works well enough to pass
simple tests, but it temporarily has even more race conditions
than it already had.  Those race conditions will be gradually
removed over the course of the following commits.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
vcrtcm: remove pcon mutexing from internal functions

The pcon locking scheme is being rearchitected.  This commit
removes the use of the per-pcon mutex from two internal functions
in which use of the mutex no longer belongs.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
vcrtcm: vcrtcm_dealloc_pcon no longer frees pcon

The caller of vcrtcm_dealloc_pcon is now responsible for calling
vcrtcm_kfree() on the pcon.  This is to permit the caller to release
the pcon's mutex and spin lock before freeing the struct.  This
change is inelegant and will be removed in a much later commit.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
vcrtcm: vcrtcm_destroy_pcon no longer frees pcon

The caller of vcrtcm_destroy_pcon is now responsible for calling
vcrtcm_kfree() on the pcon.  This is to permit the caller to release
the pcon's mutex and spin lock before freeing the struct.  This
change is inelegant and will be removed in a much later commit.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
vcrtcm: fix pcon mutexing in ioctl entry points

The pcon locking scheme is being rearchitected.  This commit
fixes the use of the per-pcon mutex in vcrtcm's ioctl entry points.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
vcrtcm: add lock-pcon and unlock-pcon functions to API

The pcon locking scheme is being rearchitected.  The new scheme
requires that the GPU driver and the PIMs be able to lock and
unlock the pcon.  The GPU driver and the PIMs will be modified
to use these functions in future commits.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
vcrtcm: eliminate void return type on pim-related API functions

The pim-related API functions that used to return void now
return an error code, which is set to nonzero if, for example,
the specified pimid is invalid.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
vcrtcm: eliminate void return type on pcon-related API functions

The pcon-related API functions that used to return void now
return an error code, which is set to nonzero if, for example,
the specified pconid is invalid.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
vcrtcm: eliminate void return type on gpu-related API functions

The gpu-related API functions that used to return void now
return an error code.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
vcrtcm: move vblank worker to separate file

This worker belongs in its own file.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>
vcrtcm: fix function names

The implementation of two functions in the api were misnamed.
This mistake was never noticed because these functions are not
currently called by anyone.

Signed-off-by: Martin Carroll <martin.carroll@alcatel-lucent.com>