cma: Change to reserve-contiguous-region

Currently, devices are associated with CMA regions via phandle to the
CMA region. The phandle name 'linux,contiguous-region' is the same as
that which is used to designate a CMA region. This can lead to issues
of trying to treat a device only using a CMA region as an actual CMA
region. Rather than continuing to rely on this handle and the depth
to differentiate CMA regions, just create separate DT binding
linux,reserve-contiguous-region to indicate that the node is
an actual CMA node for reserving rather than a client referencing
via phandle.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
ARM: dts: msm: Move audio heaps over to use reserved CMA
 regions

Carveout regions are being deprecated. Convert the audio heaps over
to use a reserved CMA region instead of a carveout. At a later time,
the audio regions may be converted over to a fully functional CMA region.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
[neo: Use increased ion heap size for better 5.1 AAC playback]
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
ARM: dts: msm: Migrate 8x74 memory regions to CMA

CMA now fully supports removing regions from memory. Since CMA
is the preferred method for tracking these regions as well, migrate
all removed regions over to use CMA and CMA derivatives.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
[neo: This patch is modified to skip external_image_mem
 region which I am really not sure where it is used.]
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: Remove memory hole scanning

The memory hole is now accounted for by using CMA/reserved regions.
Remove the custom memory hole scanning and cruft.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
cma: Delay non-placed memblocks until after all allocations

CMA is now responsible for almost all memory reservation/removal.
Some regions are at fixed locations, some are placed dynamically.
We need to place all fixed regions first before trying to place
dynamic regions to avoid overlap. Additionally, allow an
architectural callback after all removals/fixed location has
happened to potentially update any relevant limits.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
cma: Call dma_contiguous_early_fixup after allocation

Commit (cma: Delay non-placed memblocks until after all allocations)
delayed calling memblock_alloc until later but didn't move the
fixup. Make sure to call the fixup after allocation of the
memblock.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
cma: Add support for different size_cells and address_cells

Currently, the CMA flat device tree code does not take into account
targets that may specify size_cells and address_cells > 1. This will
lead to unsuccessful parsing. Add support for taking into account
nodes that may specify size_cells and address_cells explicitly.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
drivers: dma-contiguous: Don't redefine SZ_1M

Use the definition from linux/sizes.h instead.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
cma: Add support for status in DT nodes

CMA scans the flattened devicetree to reserve memory early. Check
for the status of a DT node to possibly skip initialization.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
cma: use be32_to_cpup for devicetree conversion

The value returned by of_get_flat_dt_prop is a pointer. Use
be32_to_cpup which properly type checks against pointers.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
cma: Cleanup code style

* Sync with msm-3.10

Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: Backport memory allocation from msm-3.10

ion: remove ion_cp_heap

The CP heap has been replaced by CMA-based heaps. Remove it.

Change-Id: I6b5e81d701e730584a456c7d9c3ff71397a12c0f
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

msm: Remove references to SMI

SMI memory is no longer supported on current targets. Remove
all references to it.

Change-Id: Ifbdf6247cc4b13c1d0173f1c998e07c702c06408
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

gpu: ion: get rid of adjacent heap code

The targets that require adjacent heaps are no longer present. Get
rid of the complicated crufty code.

Change-Id: Ic46cd16d36b812b19a7dc88202264cf137aebdd1
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

gpu: ion: Remove mach/ion.h

This file is now mostly useless. Move the remaining defintions elsewhere
and cleanup the cruft.

Change-Id: Icc19f9138a0d9d24a466511d69bc0eed45789fb9
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

gpu: ion: Remove allocate_contiguous_ebi call for carveouts

The allocate_contiguous_ebi APIs are being deprecated in favor
of the standard dma_alloc_coherent APIs. The carveout heap
does not currently support the dma_alloc_coherent APIs so just
give a note that clients should switch over to a heap type that
does support dma_alloc_coherent for non-fixed addresses. Remove
some crufty stuff related to allocate_contiguous_ebi memory types
as well.

Change-Id: I96fd43eb59d4cde4cdfd5c8d414885467ff423db
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

x9007: Remove references to SMI memory

Change-Id: I1b22e2d09c830be47e8100f1fbe9cf084fd0be31

gpu: ion: change pr_err to pr_debug for secure buffer failure

New architecture requirements for secure buffers mean that a
secure buffer failure may happen during normal playback. There's
no need to print an error message every time during normal use
cases so change the pr_err to pr_debug.

Change-Id: Ic05d0e95e2542dec9661e990cbfefd50274abc9e
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

gpu: ion: Pull secure buffers out of Ion

Securing individual buffers does not belong in the Ion framework.
Pull the code out of the framework and into a file which can be
managed separately. The file can be moved elsewhere at a later
date.

Change-Id: Ifaec740abcd78ee1bc3769a6c73014e4309c82be
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

gpu: ion: Skip wrong usage check for secure buffers

With the change to secure buffers at allocation time, it is
no longer possible to correctly validate if the memory is
re-secured with a different usage hint. Considering the usage
hint is being deprecated anyway, drop the redundant check. If
a client tries to re-secure with the wrong usage hint, failures
will occur elsewhere to indicate the problem.

Change-Id: If8487c431eb4555927cd06c6cc5edcb1a66002f1
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

gpu: ion: only secure buffers when supported

There are some targets where securing Ion buffers is not supported
through the TZ API used in the MSM secure buffer code. Currently, we
simply try the allocation and if it fails we let the clients secure it
themselves through some other means. However, due to a recent change to
the TZ error logging in the kernel, the current "ask for forgiveness"
approach results in logspam. Fix this by moving to an "ask for
permission" approach: if the TZ API to secure the buffers is not
available, don't attempt to use it.

Change-Id: Ie003d5139a0622ce9c18719ca2697525e23e7733
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: fix print statements

Use %zx, %zu for printing size_t and %p for printing
pointers (rather than casting them as integers and using %x).

Change-Id: I86bc2b10283b640f51a861adde6b8181bdbbcb29
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>

msm: Remove lib/memory_alloc.c and related files

The memory pools are gone for good. Remove memory_alloc.c and the
associated header file from clients.

Change-Id: I8d303c72fa03cdca7eee34b39d57d5cbb5df920d
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

msm: Remove memory reservation code

The memory reservation API used for allocate_contiguous_ebi is now
deprecated in favor of using standard kernel APIs such as
dma_alloc_coherent and CMA for reserving/allocating memory. Remove
lots of code.

Change-Id: I5a7c22cce6b4b772dc67d18029e40b4509d3ba40
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

msm: Remove ugly header include fixme

Long ago, some targets needed ugly hacks to work around buggy
hardware. These targets have fortunately been deprecated.
Remove the ugly header include remnants.

Change-Id: Ia7eef2f8f625775e40c1a73f5c2095560618cada
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

msm: Remove store_ttbr0

This was used for debugging a while back but isn't even called
anymore. Remove it.

Change-Id: Ia5e9c609508a80ae471b9ff448b92fe193e2d2b1
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

msm: clean up memory.c

This file contained support and workarounds for platforms that are
no longer supported on 3.10 -- remove this code.

Change-Id: I841a04c34c5fbe36a40b5ee49e3ac8608c963808
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>

msm: clean up memory.h

Remove various defines and comments which were only
relevant to platforms or features not supported any more.

Change-Id: I3eade953577079878375c87e35c842090c35f55d
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>

msm: remove allocate_contiguous_ebi APIs

The allocate_contiguous_ebi APIs are now deprecated. Remove them.

Change-Id: Icb83230e5b4b2eca135e8a27f6d5e73a0b9b3bb9
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

msm: Remove DONT_MAP_HOLE_AFTER_MEMBANK0

The DONT_MAP_HOLE_AFTER_MEMBANK0 feature is now deprecated. Remove
the code associated with it.

Change-Id: I729b9574a7655e97c8e7abc68797b874e90dcac2
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

ASoC: msm: qdsp6v2: Migrate away from allocate_contiguous_ebi APIs

The allocate_contiguous_ebi APIs are being deprecated in favor of
the standard dma_alloc_coherent APIs. Migrate accordingly.

Change-Id: I01dece36f7aaae192afa689daf0b51de4c1ec592
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

msm: kgsl: Remove reference to memory_alloc.h

Change-Id: I11a86f6f3254c8f150b7287d729540ef5db71ea1

msm: rtb: Convert away from allocate_contiguous_ebi APIs

The allocate_contiguous_ebi APIs are now deprecated. Move
to using dma_alloc_coherent for the RTB buffer. Because we
aren't using allocate_contiguous_ebi for allocation, change
the devicetree bindings as well to support using CMA or just
a regular size from the generic region.

Change-Id: I8ab0b7336924a78b40c68af3f215d7bfd2fba33c
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

msm: pm-boot: Remove boot remapping support

All devices that used the boot remapping code are no longer supported.
Remove the code that sets this up.

Change-Id: I85eb4e9f01664c855b0f96c34daca4c2a16ce896
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

msm: pm-boot: clean up non TZ support code

Modern ARM processors supporting TZ environment by
default. Currently, cores warmboot starts from TZ when
there is a TZ support. This patch removes the non TZ
supported code.

Change-Id: Ifa5df40bd649e4860a2660132f3fc30fa7937358
Signed-off-by: Murali Nalajala <mnalajal@codeaurora.org>

msm: pm-boot: flush msm_pm_boot_vector to main memory

msm_pm_boot_vector array stores cores warmboot entry before
cores enter into LPM mode. These warm boot entries must be
visible to core when it comes out of LPM mode. To ensure
this variable to appear in main memory use flush APIs to
flush out of caches. Use a different API to do this on
latest ARM based targets.

Change-Id: I870b68e4f6f6b116e93deffe59edff9094db0fa8
Signed-off-by: Murali Nalajala <mnalajal@codeaurora.org>

msm: buspm: Remove allocate_contiguous_ebi calls

allocate_contiguous_ebi is being deprecated in favor of the standard
dma_alloc_coherent APIs. Move accordingly.

Change-Id: I3746e5ac047b1a6ee570aaf96ffbe305e3b6a49f
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

msm: kgsl: Add CMA memory feature to support NOMMU for GPU

Reserves CMA memory for kgsl driver early during bootup and then
uses dma_alloc_coherent() to allocate physically contiguous memory
instead of using the MMU

Change-Id: Ica9b244fe9b9d8a902d670293a0bec2edf81bd5d
Signed-off-by: Shrenuj Bansal <shrenujb@codeaurora.org>

media: Remove videobuf2-msm-mem.c

This file is no longer needed by any frameworks. Remove it.

Change-Id: I66f01ab9ba273ba15b1966ad040d1d3d172d33bf
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
random: convert use of typedef ctl_table to struct ctl_table

This typedef is unnecessary and should just be removed.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
random: fix nasty entropy accounting bug

Commit 0fb7a01af5b0 "random: simplify accounting code", introduced in
v3.15, has a very nasty accounting problem when the entropy pool has
has fewer bytes of entropy than the number of requested reserved
bytes.  In that case, "have_bytes - reserved" goes negative, and since
size_t is unsigned, the expression:

       ibytes = min_t(size_t, ibytes, have_bytes - reserved);

... does not do the right thing.  This is rather bad, because it
defeats the catastrophic reseeding feature in the
xfer_secondary_pool() path.

It also can cause the "BUG: spinlock trylock failure on UP" for some
kernel configurations when prandom_reseed() calls get_random_bytes()
in the early init, since when the entropy count gets corrupted,
credit_entropy_bits() erroneously believes that the nonblocking pool
has been fully initialized (when in fact it is not), and so it calls
prandom_reseed(true) recursively leading to the spinlock BUG.

The logic is *not* the same it was originally, but in the cases where
it matters, the behavior is the same, and the resulting code is
hopefully easier to read and understand.

Fixes: "random: simplify accounting code"
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: Greg Price <price@mit.edu>
Cc: stable@vger.kernel.org  #v3.15
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
random: check for increase of entropy_count because of signed conversion

The expression entropy_count -= ibytes << (ENTROPY_SHIFT + 3) could
actually increase entropy_count if during assignment of the unsigned
expression on the RHS (mind the -=) we reduce the value modulo
2^width(int) and assign it to entropy_count. Trinity found this.

[ Commit modified by tytso to add an additional safety check for a
  negative entropy_count -- which should never happen, and to also add
  an additional paranoia check to prevent overly large count values to
  be passed into urandom_read().  ]

Reported-by: Dave Jones <davej@redhat.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
ion: remove use of qcom,msm-ion-reserve

The device tree string "qcom,msm-ion-reserve" is no
longer needed since we don't support carveout heaps any more.

Signed-off-by: Larry Bassel <lbassel@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
ion: chunk_heap: fix leak in allocated counter

buffer->size is controlled by the outer ion layer, don't modify it
inside the heap.  Instead, compute the rounded up allocated size
on demand.

Signed-off-by: Colin Cross <ccross@android.com>
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
ion: Squashed commit of upstream updates

ion: Add missing unlock on error path

A mutex_unlock was missing for the alloc_lock on an error
path. Add it.

Change-Id: If88b72fbc2fd18504347b784d5daa2bc9170c55f
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

ion: fix crash when alloc len is -1

If userspace passes a length between -4095 and -1 to allocate it
will pass the len != 0 check, but when len is page aligned it will
be 0.  Check len after page aligning.

Drop the warning as well, userspace shouldn't be able to trigger
a warning in the kernel.

Change-Id: I96c7142637638991f3a9af9be7cfbb50f79f3803
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: 49bdc418a3c1129d49fe92d89cf77111584fb51f
Git-repo: http://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: fix dma APIs

__dma_page_cpu_to_dev is a private ARM api that is not available
on 3.10 and was never available on other architectures.  We can
get the same behavior by calling dma_sync_sg_for_device with a
scatterlist containing a single page.  It's still not quite a
kosher use of the dma apis, we still conflate physical addresses
with bus addresses, but it should at least compile on all
platforms, and work on any platform that doesn't have a physical
to bus address translation.

Change-Id: I8451c2dae4bf85841015c016640684ac28430a5a
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: 51e3580bf9da57da9c860330293b73b0dbb296e0
Git-repo: http://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: conflicts due to different cache APIs being
 used. Earlier we changed __dma_page_cpu_to_dev to
 arm_dma_ops.sync_single_for_device so there was a conflict at that call
 site.]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

gpu: ion: Fix performance issue in faulting code

Previously the code to fault ion buffers in one page at a time had a
performance problem caused by the requirement to traverse the sg list
looking for the right page to load in (a result of the fact that the items in
the list may not be of uniform size).  To fix the problem, for buffers
that will be faulted in, also keep a flat array of all the pages in the buffer
to use from the fault handler.  To recover some of the additional memory
footprint this creates per buffer, dirty bits used to indicate which
pages have been faulted in to the cpu are now stored in the low bit of each
page struct pointer in the page array.

Change-Id: I891b077dc0c88ed6d416b256626d8778fd67be84
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
Git-commit: bbf5538ee0e4c30ba9b4556f9699ed5f31df67da
Git-repo: https://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: conflicts due to msm modifications. Changed a
 private dma API (__dma_page_cpu_to_dev) to public (ARM-specific)
 wrapper (arm_dma_ops.sync_single_for_device).]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: convert sg_dma_len(sg) to sg->length

ion is always dealing with the allocation and not the mapping,
so it should always be using sg->length and not sg->dma_length.

Change-Id: Id9b07f1196b2bafe04636fa1aa46dfc84d003cf0
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: c1d3cea1d0b985a78a87675a07c2dab865a416f1
Git-repo: http://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: check invalid values in ion_system_heap

ion_system_heap can only satisfy page alignment, and
ion_system_contig_heap can only satisify alignment to the
allocation size.  Neither can support faulting user mappings
because they use slab pages.

Change-Id: I895c2d4184c672f647f83a17aeb862985dc92f2c
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: e8f7f42cdcbe3ae4c4bf719847369ddac44219a9
Git-repo: http://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: some context due to msm fixes]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: add test device for unit tests to interact with dma_bufs

Add a /dev/ion-test device that will be created if CONFIG_ION_TEST
is set.  The device accepts a dma_buf fd and allows reading and
writing to the backing memory using DMA-like apis or kernel mapping
apis.  Can be used to test the dma_buf mapping ops, including
the ion implementations, from userspace.

Change-Id: I30703ba69cd75bdfe7767ac642e5f0cacd8d0478
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: 5c31b87cef4e03eea5b417a6e3f7c9b781aacf96
Git-repo: http://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

gpu: ion: ion_chunk_heap: Zero chunk heap memory at creation time

Allocations from the ion heap need to be zeroed to protect userspace
from seeing memory belonging to other processes.  First allocations
from this heap were not zero'd allowing users to see memory from other
processes on a warm reset.

Change-Id: I524a7b79cb76c390c870fcf8b30d213185fc85a0
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
Git-commit: 34e159dd120ce57b9dbfdaecb5904c2be3000a26
Git-repo: http://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: don't use phys_to_page or __phys_to_pfn

phys_to_page and __phys_to_pfn don't exist on all platforms.
Use a combination of pfn_to_page, PFN_DOWN, page_to_pfn, and
virt_to_page to get the same results.

Change-Id: I53cef26059800bc8b7fb85ae458741574c97c257
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: f26a6f2aa0beea7eeb0a2f69d44a5975ef8c887e
Git-repo: http://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: we weren't using the APIs in question in the
 same locations. Also applied the change to some other locations]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: add free list size to heap debug files

Change-Id: I3c6309afdbd661a2f870fd1ba3fea9543e229882
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: a3041cac9fc117df010e66ce40091fa2c4f646f8
Git-repo: https://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: fix printk warnings

Use %z for size_t and %pa for dma_addr_t to avoid warnings in printks.

Change-Id: I2c72874acd0b69cb35fca691928783817deb9394
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: 21e08b49ac311e3d1e9c7168de1bd42868176398
Git-repo: http://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: we already had most of these right, so this
 turned out to be pretty minimal compared to the original patch.]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: Fix two small issues in system_heap allocation

In testing ion system heap allocations, I ran across two issues:

1) Not k*z*allocing the sg table. This can cause trouble if
we end up trying call sg_alloc_table() with too many entries,
then sg_alloc_table() internally fails and tries to free what it
thinks is internal table structure, which causes bad pointer
traversals.

2) The second list_for_each_entry probably should be _safe,
since I was seeing  strange lock warnings and oopses on occasion.
This seems to resolve it, but could use some extra checking.

Change-Id: I59d4c90104a8cf23dc4ae814d0b17348f1b68ac0
Signed-off-by: John Stultz <john.stultz@linaro.org>
Git-commit: 818017a0caa6b7b3bb6e96697a2c35806e08f6a4
Git-repo: http://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: we already had list_for_each_entry_safe from
the commit (fb98460facd6: "gpu: ion: Use list_for_each_safe on error
path")]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: free low memory from page pools first

When the shrinkers are called with GFP_HIGH free low memory first,
it is more important to have free than high memory.

Change-Id: I7ad8a9c133830f04d429c3d87b781b3e862ccedb
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: b928ad649cd32b4ca5ba7429bfe897433d37dfea
Git-repo: http://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: check return value from remap_pfn_range

Check the return value of remap_pfn_range and return an error if
it fails.

Change-Id: I206cf95a24607ebe1c80274e3ed15cc7c076d007
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: 3b8da00c6c5e42af7b532dbf51b2d5007095d844
Git-repo: http://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: use vm_insert_pfn for faulted pages

Most ion userspace mappings are created with remap_pfn_range.  Use
vm_insert_pfn instead of vm_insert_page to make faulted cached
mappings look more like uncached mappings.

Change-Id: I9ec5cad3fef54f3b80be8b306d7ff2f1fe3f0e66
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: ed6cfafce575cc6baa099212c69b56c0132f598d
Git-repo: http://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: remove ion_heap_alloc_pages

Now that ion_vm_fault doesn't need a struct page with a nonzero
refcount, there is no need allocate heap memory for cached pages using
split_page.  Remove the ion_heap_alloc_pages and ion_heap_free_pages
helpers in favor of direct calls to alloc_pages and __free_pages,
and remove the special handling in the system heap.

Change-Id: I5966a798f48df2d56642e662a69c1495944f6509
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: d671290eae60f4a77ab2aef79cfaed008ee0716d
Git-repo: http://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: conflicts since we have page pooling for both
 cached and uncached]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: allow cached mappings of chunk and system heap buffers

Now that ion_vm_fault uses vm_insert_pfn instead of vm_insert_page
cached buffers can be supported in any heap.  Remove the checks
in the chunk and system heaps.

Change-Id: I371a44c400ed8a342c3b0eed90d0fb7060537697
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: 1f67f7520303192e46e1621639097007ab076b90
Git-repo: http://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: context differences due to prior msm related
 to flushing the cache at allocation time. The prior msm fixes are now
 no longer relevant so an additional structure was removed.]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: fix sparse warnings

Fix sparse warnings in ion.

Change-Id: Icbadf2ca53bea20914f608f619568629c178eae3
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: 6db8a1c0c9817d6ebd61c47110554aa34729e9a7
Git-repo: http://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: conflicts since we have page pooling for both
 cached and uncached as well as some gfp flag differences]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: add alignment check to chunk heap

Change-Id: I4be12b9545a81f9b46339a905f00e1e64896b3ed
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: 1b1cbed2f4cd92b9ccfd28b985983e2d217ecd2e
Git-repo: http://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: Cleanup whitespace issues and other checkpatch problems

Just some simple cleanups to address whitespace issues and
other issues found w/ checkpatch.

Change-Id: I181444505627894b8f3bbf59192703b0f65736ee
Signed-off-by: John Stultz <john.stultz@linaro.org>
Git-commit: 0f9ae3f7fc853efb3f36e44b1c24ca15490e54f0
Git-repo: http://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: remove support for securing entire heaps

Securing an entire heap is no longer required or implemented by any
heaps. Remove the (now unused) upper-level hooks for securing heaps.

Change-Id: I624a050c30c89522e8794768681ea39ff29bc215
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: remove obsolete stub

ion_mark_dangling_buffers_locked is no longer used anywhere. The main
implementation of the function was removed but the stub wasn't. Remove
the stub.

Change-Id: I8488c5dfdd93827c31ae41be849dfe0999a965d1
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: remove calls to outer cache routines

There aren't any platforms supported on 3.10 which
have outer caches.

Change-Id: Ia624de9835dd372dcd403fa321e21fc8272cb4bd
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>

gpu: ion: Add trace events for secure cma

Secure CMA allocates and stores memory differently than regular
heaps. This means the regular trace events for tracking allocation
time may not tell the whole story. Add secure CMA specific trace
events for events such as prefetching and shrinking to better collect
data.

Change-Id: I58ce8eb9e94ea380bece6bd75c7ba899a3ebc781
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>

ion: index client->handles rbtree by buffer

The only remaining users of the client->handles rbtree are
iterating through it like a list.  Keep the rbtree, but change
its index to be the buffer address instead of the handle address,
which makes ion_handle_lookup a fast rbtree search.

Change-Id: Ie7d974b3a5d9831c0d664de85ddae8db3c3abdf9
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: 002119eeb221cf1efd7afda836da768ff1cd0ad9
Git-repo: http://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: do not use sg_dma_len() macro

Use of sg_dma_len() is not portable to 64 bit and is not used any more
by ion or iommu. Replace the usages by direct access of the length
structure member.

Change-Id: I6c18b2a77e288be312448c36f8ed3ad6db90ac0f
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>

ion: convert map_kernel to return ERR_PTR

ion is going to stop accepting NULL as an error value, use ERR_PTR.

Change-Id: I030e8b72138904e38a4a5d225beaaa98427651fb
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: d37aa151f874563a35d49a0ff0a129ef332c5e9e
Git-repo: http://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: conflicts due to msm changes]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

gpu: ion: delete ion_system_mapper.c

The mapper abstraction layer was removed before the initial ion
commit, but a stray ion_system_mapper.c file was left in.  Delete
it.

Change-Id: I0001d1ea1b866ebd7ec1306e94472c67a094855f
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: 3922298f52d193d5e014bf4d28e423cf7bd0b50e
Git-repo: http://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>

ion: change ion_user_handle_t definition to int

Turn ion_user_handle_t to int. This change reflects the underlying type
returned by the ion driver.

Change-Id: I40390dae8138327769510525bf62e55877a4b37d
Signed-off-by: Rom Lemarchand <romlem@google.com>
Git-commit: dcd2da8015c7ac2da6f57fc0d8c15b80e44c4aed
Git-repo: http://android.googlesource.com/kernel/common/
[mitchelh@codeaurora.org: made changes to file in different location
 since we've already done the uapi split. Also, one function name was
 different due to some necessary patch re-ordering.]
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
ion: secure_buffer: fix iteration of sg_table

We're currently re-using the `i' loop counter to iterate over the chunk
list within our iteration of the secure sg_table. This causes the
iteration of the sg_table to get all messed up and results in crashes
when we walk off the end of the list. Fix it.

Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
ion: fix remaining instances of sg_dma_len

Recently, ["ion: convert sg_dma_len(sg) to sg->length"]
moved Ion away from using sg_dma_len. However, a few instances were left
over from MSM-specific code. Fix these instances so that we're using
sg->length everywhere.

Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>