mxc: gpu_viv: Fixup interrupt initialization

There is no reason to tear down and setup the interrupt constantly.
This breaks the routines up to  Setup/Remove and Enable/Disable,
it also consolidates the code to take Core as a parameter so
there aren't similar functions for the various Core types.
mxc: gpu_viv: Start with interrupts disabled.

Make sure interrupts are disabled so we don't get an unbalanced
irq later on.
mxc: gpu_viv: Wrap interrupt handling in a spinlock

Make sure that multiple threads are enabling/disabling irq's
when we are trying to read events pending.
mxc: gpu_viv: Don't try to Idle GPU after event submission

This code is attempting to IDLE the gpu after an event is
submitted, however this is generally followed by an interrupt
at the end of which the code attempts to idle the GPU.  This
generally causes Mutex contention with both threads trying
to do the same thing, set the powerstate to IDLE, or SUSPEND
depending on the driver preferences.
mxc: gpu_viv: Don't do an identity check for every commit

Everytime the GPU is woken up to process something an Identity
check is done to verify the GPU is present and active.  This is
really heavy handed and definitely causes excessive latency in
the kernel driver that is not needed.

FIXME: Find a better way to verify the GPU is ready to process
commands.
mxc: gpu_viv: Optimize PM routine

We are trying to manage multiple threads and a time trying to
put the GPU in the proper powerstate.  It is possible that while
the hardware is trying to power on the GPU the idle timer will
kick off and first suspend the chip only to wake it back up. This
commit does two things

1)  If the chip is already in the state we are trying to achieve
bail out and do nothing.
2)  If we are powering the chip on or off kill the IDLE timer
right away as we know we don't care about the suspend state because
we are already processing a different state command that is not
suspend.
GALCORE: fix race in _GetEvent()

Two _GetEvent()s can race, as it finds an event with a NULL head, and
then drops the lock:

Thread 0                        Thread 1
Calls _GetEvent
                                Calls _GetEvent
Acquires mutexQueue
Searches for a free entry
 by way of NULL queues[n].head
Finds entry N
Sets the stamp and source
Drops mutexQueue lock
returns event id N
                                Acquires MutexQueue
                                Searches for a free entry
                                 by way of NULL queues[n].head
                                Finds entry N
                                Sets the stamp and source
                                Drops mutexQueue lock
                                returns event id N
Sets the Event->queues[N].head
                                Sets Event->queues[N].head

This allows another thread to come in and also pick the same event.
Plug this race by holding the list lock over the call to _GetEvent,
and assign the head within _GetEvent().

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

Adapted to the V4 codebase

Signed-off-by: Jon Nettleton <jon.nettleton@gmail.com>
GALCORE: fix race in gckEvent_Notify()

This function can race with the setup of a new event queue.

Thread 0                        Thread 1
                                write Event->queues[i].head
read Event->queues[i].head
read Event->queues[i].stamp
                                write Event->queues[i].stamp
                                  with current stamp

Here, thread 0 has read a non-NULL head, but a old value for the stamp.
This leads gckEvent_Notify() to believe that this is an old event which
was not signalled by the GPU.  With some of the errors enabled, galcore
will issue a warning: Event N lost (stamp X)

More worrying is that it will immediately execute the attached event
list, and mark this event as completed - even though it's still being
setup.  This can result in problems such as GPU stalls being completed
early and command buffers being marked as completed (and hence re-used)
while the GPU is still reading commands from them.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

Adapted to the V4 codebase

Signed-off-by: Jon Nettleton <jon.nettleton@gmail.com>
GALCORE: fix race in _IsEmpty()

The following race is possible:

Thread 0                        Thread 1
Read Event->queues[0].head
Finds that it's NULL
                                Acquires Event->mutexQueue
                                Sets Event->queues[0].head
                                Releases Event->mutexQueue
Acquires Event->mutexQueue
Releases Event->mutexQueue
IsEmpty = True

Therefore, it is possible that this function returns with IsEmpty=TRUE
even though the event queues may not be empty.  The converse is also
possible:

Thread 0                        Thread 1 (event thread)
Read Event->queues[0].head
Finds that it's non-NULL
                                Receives interrupt
                                Acquires Event->mutexQueue
                                Clears Event->queues[0].head
                                Releases Event->mutexQueue
Acquires Event->mutexQueue
Releases Event->mutexQueue
IsEmpty = False

Here, the queues are empty, but we've returned that they not empty.

Fix this by reading the Event queue pointers beneath the lock.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

Adapted to the V4 codebase

Signed-off-by: Jon Nettleton <jon.nettleton@gmail.com>
GALCORE: fix LINK fetch size

The size of the destination command buffer was being padded to 64
bytes, whereas only 64 bits is required (as is the case for every
other LINK command.)  Make this consistent.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

Updated to the V4 codebase

Signed-off-by: Jon Nettleton <jon.nettleton@gmail.com>
cpufreq: cpufreq-imx6: Fix mutex init.

Use DECLARE_MUTEX to properly initialize the mutex.
debugfs: add get/set for atomic types

debugfs currently lack the ability to create attributes
that set/get atomic_t values.

This patch adds support for this through a new
debugfs_create_atomic_t() function.

Signed-off-by: Seth Jennings <sjenning <at> linux.vnet.ibm.com>
Acked-by: Greg Kroah-Hartman <gregkh <at> linuxfoundation.org>
Acked-by: Mel Gorman <mgorman <at> suse.de>
zbud: add to mm/

zbud is an special purpose allocator for storing compressed pages. It is
designed to store up to two compressed pages per physical page.  While this
design limits storage density, it has simple and deterministic reclaim
properties that make it preferable to a higher density approach when reclaim
will be used.

zbud works by storing compressed pages, or "zpages", together in pairs in a
single memory page called a "zbud page".  The first buddy is "left
justifed" at the beginning of the zbud page, and the last buddy is "right
justified" at the end of the zbud page.  The benefit is that if either
buddy is freed, the freed buddy space, coalesced with whatever slack space
that existed between the buddies, results in the largest possible free region
within the zbud page.

zbud also provides an attractive lower bound on density. The ratio of zpages
to zbud pages can not be less than 1.  This ensures that zbud can never "do
harm" by using more pages to store zpages than the uncompressed zpages would
have used on their own.

This patch adds zbud to mm/ for later use by zswap.

Signed-off-by: Seth Jennings <sjenning <at> linux.vnet.ibm.com>
zswap: add to mm/

zswap is a thin compression backend for frontswap. It receives pages from
frontswap and attempts to store them in a compressed memory pool, resulting in
an effective partial memory reclaim and dramatically reduced swap device I/O.

Additionally, in most cases, pages can be retrieved from this compressed store
much more quickly than reading from tradition swap devices resulting in faster
performance for many workloads.

It also has support for evicting swap pages that are currently compressed in
zswap to the swap device on an LRU(ish) basis. This functionality is very
important and make zswap a true cache in that, once the cache is full or can't
grow due to memory pressure, the oldest pages can be moved out of zswap to the
swap device so newer pages can be compressed and stored in zswap.

This patch adds the zswap driver to mm/

Signed-off-by: Seth Jennings <sjenning <at> linux.vnet.ibm.com>
zswap: add documentation

This patch adds the documentation file for the zswap functionality

Signed-off-by: Seth Jennings <sjenning <at> linux.vnet.ibm.com>