gpu: pvr: Add PVR GPU driver

Patch-Mainline: not sure
Add the SGX PVR driver.

Signed-off-by: Imre Deak <imre.deak@nokia.com>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: Topi Pohjolainen <topi.pohjolainen@nokia.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@nokia.com>
Signed-off-by: Mark Underwood <mark.underwood@imgtec.com>
Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@nokia.com>
Signed-off-by: Sami Kyöstilä <sami.kyostila@nokia.com>
Signed-off-by: Mark Riding <mark.riding@imgtec.com>
Signed-off-by: Janusz Sobczak <janusz.sobczak@imgtec.com>
Signed-off-by: Roger Quadros <roger.quadros@nokia.com>
gpu: pvr: compilation fixes for kernel > 2.6.33

Signed-off-by: Ameya Palande <ameya.palande@nokia.com>
gpu: pvr: move device registration into board file

Needed by an upcoming patch adding board specific device parameters.

Signed-off-by: Imre Deak <imre.deak@nokia.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@nokia.com>

Adapt for Nokia N900 MeeGo kernel

Signed-off-by: Carsten Munk <carsten@maemo.org>
gpu: pvr: add support to set board specific max SGX functional clk rate

Signed-off-by: Imre Deak <imre.deak@nokia.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@nokia.com>
gpu: pvr: add pvr_lock/remove unneeded lock headers

- Add a public interface for accessing this lock. It has been used
  as a public interface anyway and an upcoming patch needs to access
  it as well.

- Remove headers becoming unnecessary by this refactoring.

Note:
  Currently this lock provides for a course level locking protecting
  all HW and SW state tracking objects. We'll need to revise the use
  of the following additional locks in the driver. Their existance
  might not be justified, in which case we could just substitute
  them with pvr_lock:

  PVRSRVDvfsLock
  PVRSRVPowerLock

Signed-off-by: Imre Deak <imre.deak@nokia.com>
gpu: pvr: bail out from SGXOSTimer if it's been canceled

At the moment cancelling the timer is done in a synchronous way, so
we don't need to have the extra check. But a later patch will add
additional locking around the HW interrupt from where the timer can
be cancelled as well. Because of lock dependency issues described
in that patch we have to switch to an asynchronous way of cancelling
this timer and it means we need to have the extra check.

Also reset the flag indicating that the timer is cancelled when
destroying it. Currently we are both cancelling and destroying the
timer, but we really should just require calling the destroy function.

Signed-off-by: Imre Deak <imre.deak@nokia.com>
gpu: pvr: fix locking on the HW interrupt path

- take pvr_lock in the interrupt handling work (MISR) thread, as from
  there we can call functions accessing HW and SW state tracking objects.
  An example is the SGX HW recovery function.

- make SGXOSTimerCancel asynchronous. This is safe now as a previous
  patch made sure that the timer will not run after cancelled. We can't
  do synchronous cancellation, because there would be an ABBA lockdep
  problem involving the SGXOSTimer's mutex and pvr_lock:

  MISR / IOCTL thread:
    1. pvr_lock in PVRSRV_BridgeDispatchKM
    2. timer's lock through SGXPrePowerState -> SGXOSTimerCancel

  SGXOSTimer's thread:
    1. timer's lock already taken when SGXOSTimer is called
    2. pvr_lock in SGXOSTimer

Signed-off-by: Imre Deak <imre.deak@nokia.com>
gpu: pvr: acquire the pvr lock on the SGX HW recovery path

We need to take the lock protecting all SW and HW state tracking
objects on the recovery reset path, since we are accessing objects
like the SGX command queue, or the per process memory and resource
management contexts.

Signed-off-by: Imre Deak <imre.deak@nokia.com>
gpu: pvr: fix locking in pvr_dbg_reset

HWRecoverResetSGX needs to be called with the pvr_lock held.

Signed-off-by: Imre Deak <imre.deak@nokia.com>
gpu: pvr: BUG if pvr_lock is not held in HWRecoveryResetSGX

Adding the check only to this one place, more can be added later.

Signed-off-by: Imre Deak <imre.deak@nokia.com>
gpu: pvr: fix indent error

Signed-off-by: Imre Deak <imre.deak@nokia.com>
gpu: pvr: remove unused per device variable

Signed-off-by: Imre Deak <imre.deak@nokia.com>
gpu: pvr: make sure the device is powered on in SGX_MISRHandler

While SGX_MISRHandler is scheduled another code path of the driver
(IOCTL, SGXOSTimer) can race with it and turn the power off before
it starts to execute.

When this happens we get the following oops backtrace:

 HWRecoveryResetSGX: SGX Hardware Recovery triggered
 Unhandled fault: external abort on non-linefetch (0x1008)
 PC is at HWRecoveryResetSGX+0x74/0x1b8 [pvrsrvkm]
 LR is at preempt_schedule+0x44/0x54
 (HWRecoveryResetSGX+0x0/0x1b8) from (SGX_MISRHandler+0x5c/0x60)
 (SGX_MISRHandler+0x0/0x60) from (PVRSRVMISR+0x44/0xa0)
  r5:bf0a29cc r4:dfbbbcc0
 (PVRSRVMISR+0x0/0xa0) from (MISRWrapper+0x14/0x18)
  r5:00000002 r4:00000000
 (MISRWrapper+0x0/0x18) from (worker_thread+0x1d0/0x2cc)
 (worker_thread+0x0/0x2cc) from (kthread+0x88/0x90)
 (kthread+0x0/0x90) from (do_exit+0x0/0x680)

Signed-off-by: Imre Deak <imre.deak@nokia.com>
gpu: pvr: add support for finding the BM context from the DL

This allows us to find the BM context from the value of the directory list.
This is required for the next patch.

Signed-off-by: Mark Underwood <mark.underwood@imgtec.com>
Signed-off-by: Imre Deak <imre.deak@nokia.com>
gpu: pvr: clean up FreeResourceByCriteria

Signed-off-by: Imre Deak <imre.deak@nokia.com>
gpu: pvr: add helpers to look up resource context and proc info

These are needed by an upcoming patch showing process info.

Signed-off-by: Imre Deak <imre.deak@nokia.com>
gpu: pvr: dump process info at HW recovery reset

Print process ID and command name during HW recovery reset.

Based on a patch from Mark Underwood <mark.underwood@imgtec.com>.

Forward port to 2.6.35

Signed-off-by: Imre Deak <imre.deak@nokia.com>
Signed-off-by: Carsten Munk <carsten@maemo.org>
gpu: pvr: add option for extra debugging information

This is basically a sed -i 's/\<DEBUG\>/CONFIG_PVR_DEBUG_EXTRA' *.[ch] .

Currently a driver built in debug mode will only work together with the
relevant PVR/OGLES user space libraries being built in debug mode too.
This is becuase the ABI is different in debug and release build.

This is not very flexible when one wants to only debug the kernel driver
and not care about the user space part, let alone figuring out where to
get the sources for that and rebuild it in debug mode too.

Mark the current user space dependent debug code parts with a new
CONFIG_PVR_DEBUG_EXTRA option instead of DEBUG, so that later we can
selectively add back basic debugging facilities like debug traces and
mark them with CONFIG_PVR_DEBUG.

Signed-off-by: Imre Deak <imre.deak@nokia.com>
CC: Mark Underwood <mark.underwood@imgtec.com>
CC: Mark Riding <mark.riding@imgtec.com>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@nokia.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@nokia.com>
gpu: pvr: enable debug trace for basic debug build

Enable debug messages for basic debug type builds.

Signed-off-by: Imre Deak <imre.deak@nokia.com>
CC: Mark Underwood <mark.underwood@imgtec.com>
CC: Mark Riding <mark.riding@imgtec.com>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@nokia.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@nokia.com>
gpu: pvr: fix locking on SGX load calculating thread

psDeviceNodeList et al is protected by pvr_lock, so we need to
acquire it here.

Signed-off-by: Imre Deak <imre.deak@nokia.com>
CC: Mark Underwood <mark.underwood@imgtec.com>
CC: Mark Riding <mark.riding@imgtec.com>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@nokia.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@nokia.com>