staging: etnaviv: fix oops on unbind

The oops below was found when unbinding the etnaviv drm driver.  This is
caused by using drm_gem_object_unreference() in a region which is not
protected by drm_dev->struct_mutex.  Fix this by using
drm_gem_object_unreference_unlocked() instead.

Kernel BUG at c026cab8 [verbose debug info unavailable]
Internal error: Oops - BUG: 0 [#1] PREEMPT ARM
Modules linked in: etnaviv(C-) ...
task: d41dda80 ti: d63f2000 task.ti: d63f2000
PC is at drm_gem_object_free+0x34/0x38
LR is at etnaviv_gpu_unbind+0x7c/0xb0 [etnaviv]
pc : [<c026cab8>]    lr : [<bf1067a8>]    psr: 600d0013
sp : d63f3da0  ip : d63f3db0  fp : d63f3dac
r10: 00020000  r9 : d63f2000  r8 : c000ece8
r7 : d4386c34  r6 : d4386c00  r5 : d42c4d80  r4 : d621ac10
r3 : d4386c00  r2 : 00000001  r1 : d608c410  r0 : d59da580
Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
Control: 10c5387d  Table: 14234019  DAC: 00000015
Process rmmod (pid: 1633, stack limit = 0xd63f2250)
[<c026ca84>] (drm_gem_object_free) from [<bf1067a8>] (etnaviv_gpu_unbind+0x7c/0xb0 [etnaviv])
[<bf10672c>] (etnaviv_gpu_unbind [etnaviv]) from [<c028a47c>] (component_unbind+0x38/0x70)
[<c028a444>] (component_unbind) from [<c028a52c>] (component_unbind_all+0x78/0xac)
[<c028a4b4>] (component_unbind_all) from [<bf104560>] (etnaviv_unload+0x68/0x7c [etnaviv])
[<bf1044f8>] (etnaviv_unload [etnaviv]) from [<c0270498>] (drm_dev_unregister+0x2c/0xa0)
[<c0270c90>] (drm_put_dev) from [<bf104058>] (etnaviv_unbind+0x14/0x18 [etnaviv])
[<bf104044>] (etnaviv_unbind [etnaviv]) from [<c028a2a4>] (take_down_master+0x2c/0x4c)
...

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
staging: etnaviv: fix oops in timer subsystem caused by hangcheck timer

We must delete the hangcheck timer before freeing its memory, otherwise
we oops the kernel in the timer code when the memory is overwritten.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
staging: etnaviv: fix etnaviv_add_components()

There are a couple of issues with etnaviv_add_components():
1. it releases each child node as it parses, which is unnecessary
   Fix this by using the for_each_available_child_of_node() helper
   rather than open-coding this.
2. it fails to check the return value from component_master_add_child().
   In this case, we must drop the child reference before breaking out
   of the loop.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
staging: etnaviv: fix etnaviv_hw_reset()

Ensure that we reset the GPU with the clocks on, and restore the clock
state after GPU reset has completed.  Without this, register accesses
can fail:

Unhandled fault: external abort on non-linefetch (0x1828) at 0xfe640418
Internal error: : 1828 [#1] PREEMPT ARM
Modules linked in: etnaviv(C+) ...
CPU: 0 PID: 1617 Comm: modprobe Tainted: G C    3.16.0+ #1010
task: d6210140 ti: d4102000 task.ti: d4102000
PC is at etnaviv_writel+0x2c/0x38 [etnaviv]
LR is at etnaviv_gpu_init+0x304/0x5cc [etnaviv]
pc : [<bf104960>]    lr : [<bf107228>]    psr: 600f0013
sp : d4103ba8  ip : d4103bc0  fp : d4103bbc
r10: 00000000  r9 : 00000000  r8 : cd45b034
r7 : d43ee480  r6 : d5ab1c10  r5 : 00000000  r4 : fe640418
r3 : 00000000  r2 : 00000000  r1 : fe640418  r0 : 00000000
Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
Control: 10c5387d  Table: 143d4019  DAC: 00000015
Process modprobe (pid: 1617, stack limit = 0xd4102250)
Backtrace:
[<bf104934>] (etnaviv_writel [etnaviv]) from [<bf107228>] (etnaviv_gpu_init+0x304/0x5cc [etnaviv])
[<bf106f24>] (etnaviv_gpu_init [etnaviv]) from [<bf10481c>] (etnaviv_load+0xbc/0x128 [etnaviv])
[<bf104760>] (etnaviv_load [etnaviv]) from [<c0270a8c>] (drm_dev_register+0xa8/0x108)
[<c02709e4>] (drm_dev_register) from [<c027238c>] (drm_platform_init+0x50/0xe8)
...

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
staging: etnaviv: fix etnaviv gpu debugfs output

"0x08%x" is a confusing format.  It prints values prefixed with 0x08
irrespective of their values, which leads you to think that 0x08fe
really is 0x08fe.  Fix the format string to place the % correctly.

Reverse the 64-bit values - even though the GPU wants 64-bit alignment
in the command stream, and sees the stream as 64-bit values, it's more
humanly understandable to print them as separate 32-bit values in
"lo hi" format - the order that they appear in the command stream.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
staging: etnaviv: fix fence implementation

The fence implementation relied upon incrementing a 32-bit number,
and using unsigned comparisons.  This is a limited number space,
which, when exhausted will lead to unpredictable behaviour.  Turn
this into a circular namespace, and use signed difference comparisons.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
staging: etnaviv: fix buffer dumping code

The buffer dumping code tries to dereference obj->gpu.  However, for
submitted command buffers, obj->gpu is only set after the buffer has
been submitted to the GPU.  Explicitly pass in the etnaviv_gpu struct.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
staging: etnaviv: fix ring buffer overflow check

The ring buffer offset is an index into an array of uint32_t, whereas
obj->base.size is measured in bytes.  Comparing these two is nonsense.
Convert the index into a byte offset first.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
staging: etnaviv: fix cleanup of imported dmabufs

We need to call drm_prime_gem_destroy() to properly clean up imported
dmabufs when their associated GEM object is deleted, otherwise we drop
a refcount on them, preventing them from being cleaned up.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
staging: etnaviv: fix printk formats

Use %p for pointers rather than casting to u32 and using 0x%08x.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>