gpu: ion: system_heap: add support for 2MB allocations

Enable 2MB (order 9) allocations from the system heap. This improves the
performance of some heavyweight use cases. The benefit is especially
large for use cases where the buffer is mapped into an IOMMU since we
can leverage the 2MB IOMMU page table mappings.

Change-Id: I869733089b9ccba8090bbca80aac7b5f248b335e
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
ion: use iounmap instead of __arm_iounmap

The API iounmap() is more generic and portable
than __arm_iounmap().

Change-Id: If9601e9266bec56442686d3f2bdb1d475cd7bead
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>
ion: use PAGE_KERNEL instead of pgprot_kernel

The ion code uses PAGE_KERNEL (which is more generic than
pgprot_kernel) everywhere except in one place (so fix it).

Change-Id: I38fa1c682a3e04e9c8cb3cd25678094862fe8c9c
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>
ion: remove unused function

Somehow, during [83c50939e88d0 gpu: ion: optimize zero'ing of pages] we
retained some cruft. Remove it.

Change-Id: I38f2ef5d6cd1baa3fe8a758a0bf8164695e2b657
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
gpu: ion: fix use-after-free in ion_heap_freelist_drain

The `buffer' variable is being used after being freed. Fix this.

Change-Id: Iea3471fa7dc7535bbf0620c1639fea2008d7cf19
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
ion: system_heap: only use low gfp flags for order-0 pages

By trying a little harder to get high-order pages (by virtue of the
liberal gfp flags used for high-order allocations) we can actually
optimize performance since high-order pages seem to help a lot. Only use
the low-order flags as a last resort, when trying to allocate an order-0
page.

Change-Id: If8d8f4b1b4503b0c7546cf5a4bcdcaecd2bb5905
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
ion: invalidate buffers before zero'ing

Currently, we invalidate the cache for buffers being zero'd *after* we
zero them. However, this is racey since a dirty cache line from an
earlier mapping could be written out to memory between the zero'ing and
the invalidation. Fix this by invalidating the cache *before* zero'ing
the buffer.

Before this change, I was seeing corruption with:

    $ cat <<EOF | ./memory_prof -e -i -
    simple_alloc,1,ION_SYSTEM_HEAP_ID,ION_FLAG_CACHED,0x100000,1MB
    simple_basic_sanity,1
    simple_profile,1
    simple_free,1
    EOF

After this change, no corruption.

CRs-Fixed: 585524
Change-Id: I1f2603604efc9be4ebf9112b06728e0aeca60ea0
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
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>
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.

Change-Id: Icb24d86fff9b478504d17518fda4c2e7b04833b8
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>
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.

Change-Id: I288ffc1221ce96cfe2591468502ac3279065bde4
Signed-off-by: Colin Cross <ccross@android.com>
Git-commit: f526a55b400d166dafc6062e5818a2410555ef39
Git-repo: https://android.googlesource.com/kernel/common/
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
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>
cma: Allow option to use strict memblock_reserved memory

Despite all the performance optimizations, some clients are
still unable to use CMA because of the allocation latency.
Rather than make those clients use a separate set of APIs,
extend the CMA code to allow clients to keep the memory out of
the buddy allocator. Since the pages never actually go to the
buddy allocator, allocation and freeing is only based on the bitmap
allocator to find the appropriate region.

Change-Id: Ia31bb1212fd7b19280361128453c8d25369ce592
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
cma: Remove potential deadlock situation

A report was given of a deadlock situation on the cma_mutex:

mutex_lock(cma_mutex)   (*2)
dma_release_from_contiguous
ion_secure_cma_free_chunk
ion_secure_cma_shrinker
shrink_slab
try_to_free_pages
migrate_pages
alloc_contig_range
mutex_lock(cma_mutex)  (*1)
dma_alloc_from_contiguous
ion_alloc

We may need to free CMA allocations while a current CMA allocation is in
progress if CMA is freed from a shrinker. cma_mutex currently protects
two things: the bitmap indicating which pages are allocated/free and
serialization of isolation/migration calls on allocation. There is
no need to take the mutex on free calls though as the pages are
freed back into the system via the regular __free_page call. Move
the free_contig_range call outside the cma_mutex to break the
chain dependency. We can safely free the pages back into the system
before changing the bitmap without any risk of races.

Change-Id: I4989eb2891e502b08db8117a51bd86652e902778
CRs-Fixed: 619644
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
cma: Increase the default number of regions

The total number of CMA regions that can be created is statically
decided at compile time via a config option. Incoming memory map
changes increase the number of CMA regions significantly across
almost all targets. Rather than make every target set the CONFIG,
just increase the default number. The additional overhead is very
small.

Change-Id: I2f60ee56b43c256f3bfa4d1e3ab95a8f378568ab
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
drivers: cma: Fix wrong CMA selected region size default value

Kconfig lists CMA_SIZE_SEL_ABSOLUTE as the default value fo the CMA
selected region size, but that option isn't available in the defined
choices. Set the default to CMA_SIZE_SEL_MBYTES instead.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
drivers: Add option to reserve default CMA region

CMA provides good utilization of memory but for some use cases, the
allocation time is too costly. Add a Kconfig option to allow the
default region to be permanently set aside for contiguous use cases.

Change-Id: I1eef508d37cf6ae3b7b7a652fc59391b186fc122
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
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.

Change-Id: I9ea63b8c34e903b186c29ec6555dd7a5c317c602
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
cma: Add support for memory limits

Currently, when dynamically placing regions CMA will allow the memory
to be placed anywhere, including highmem. Due to system restrictions,
regions may need to be placed in a smaller range. Add support to
devicetree to allow these regions to have an upper bound on where they
will be placed.

Change-Id: Ib4ae194cbb6389e1091e7e04cfd331e9ab67ad05
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
cma: print physical addresses correctly

Physical addresses can be greater than an unsigned long on
systems with LPAE. Print these addresses properly with %pa

Change-Id: If9f1572bb9dadcb14f2834647a4421509e90096a
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
cma: Make the default CMA region not reserved by default

Due to a bug in code logic, the default CMA region is
reserved when CONFIG_CMA_RESERVE_DEFAULT_AREA is NOT set
instead of when it is set. Fix this logic.

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