gpu: ion: Map a range into the IOMMU

Instead of mapping 1 4K page at a time into the IOMMU create a
scatterlist and map everything at once. This will be more efficient.

(cherry picked from commit 16cdb41acb58dc352994e9b27a9344b1337b0c46)

Change-Id: I8488cc8e6d013d1e62c6ea5fcfc2425384daefe9
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 8ddf658dc1a93a91eacf8d47779710ff860337aa)
iommu: Fix flags passed to iommu map functions.

iommu map functions requires clients to specify whether
the mappings should be read only or read-write (write only
is not supported). Ensure clients specify the appropriate
flags when calling map functions.

Change-Id: If42b4b0367b4311aa36d3063979ef04af3a43fc6
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit bcf5ae04a9bf744a7a3d119c93d439a682404877)
gpu: ion: Remove extra iova free call

IOMMU virtual address (iova) is allocated locally in IOMMU mapping
functions per heap type. When an error happens the iova's are
freed in the same function as it was allocated. However, there
is an extra free call in the ion wrapper function that calls
these IOMMU mapping functions.

Remove the extra iova free call which can cause kernel panic.

Change-Id: Ic8978cf05202b29a42da7374e2c8c1e590b2d2a8
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit b343e0593e5f574cd1483497807a6cf10b7aee8e)
gpu: ion: Map everything into IOMMU with 64K pages.

Due to performance issues with 4K pages and the IOMMU we should use
64K pages. However, minimum allocation from ION is 4K so instead of
mapping on demand we need to map the full heap into the IOMMU when
the first request for mapping comes. Only unmap everything from the
IOMMU when the last buffer is freed.

CRs-fixed: 348606
Change-Id: Ic1793f5caaff2f69bf1fb7e8c8b3bd03378131b8
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 5027688e1d4cf244f84b525c76a000b9408c62a5)

Conflicts:

	arch/arm/mach-msm/board-msm8x60.c
gpu: ion: Fix incorrect argument to map call

An incorrect argument is passed to a local ion heap
function call. This is causing incorrect flags to be
passed to iommu map call. The side effect is that the
flags passed to the iommu map call is defaulted to
read-write and uncached.

Change-Id: Ia2a7e64818dc8f251dadfb545f9b218a5e3cfc42
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 3d79eec14b8fdb99832a907a0ae29042eaba7f07)
msm_fb: display: Add IOMMU support to MDP and rotator driver

Add IOMMU support to MDP and rotator driver for operating with
virtual addresses instead of physical addresses

Change-Id: Ia5afcf33220e0e75e92948649c2bd4d7ef32917d
Signed-off-by: Ravishangar Kalyanam <rkalya@codeaurora.org>
msm: display: Attach MDP IOMMU during first update after boot

For continuous splash support to work properly, attach the MDP IOMMU
device at a later point during boot to allow display use the
splash image from bootloader

Signed-off-by: Ravishangar Kalyanam <rkalya@codeaurora.org>
Change-Id: Ife9a2afae1e9b9140ee74af0cc7dcf7ad945d4de
msm_fb: display: Unstage video from primary mixer H/W on unset

Resolve video playback suspend/resume IOMMU page fault by
unstaging video layer on VG pipes from primary mixer H/W during
overlay_unset calls immediately at the next vsync boundary

CRs-Fixed: 350371
CRs-Fixed: 354236
Signed-off-by: Ravishangar Kalyanam <rkalya@codeaurora.org>
Change-Id: I7fe10989a7bc3d7f379adfd18010c5e8cd655368
msm_fb: Correct mdp_iommu array size to avoid scribbling

The mdp_iommu array was undersized. This resulted in scribbling of
nearby data structures which, through a long series of events,
lead to invalid pointer dereferences in the workqueue framework's
process_one_work() function on (at least) the 8930 SoC.

CRs-Fixed: 357011
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
Change-Id: Idb360e687c4cf050b6e73e575a13eba4b9d3c150
msm_fb: display: Flush pipe registers before staging the pipe

Flush pipe registers before staging the pipe for the Mixer with
pull mode panel interfaces. This fixes the IOMMU page fault/underrun
caused by pipe fetching previously unmapped buffers due to missing flush
calls

CRs-Fixed: 356484
Change-Id: I6bc2e49746a7c3773708796bc1709c75a8afaa4b
Signed-off-by: Ravishangar Kalyanam <rkalya@codeaurora.org>
msm: Make IOMMU domains unique

4 domains have been defined for the IOMMU. However, they are all
aliased to each other.

Change so that the domains have unique value for video, camera,
display, and rotator.

Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/include/mach/iommu_domains.h

Change-Id: I5b09c1d98e04c63c718bbbf0a0dd2e3d1cc21c25
Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
gpu: ion: Use standard cache routines

Instead of using custom routines for cache operations use the
standard operations for cache flush, cache clean, and cache
invalidate. In addition only call outer cache routines if
outer cache is available.

Change-Id: Idb51bf7348fd526ebdea1e6ff2e366b8a3b4de33
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 85c95406680ce1a959a9b8cdb5aff7afcd699038)

Conflicts:

	drivers/gpu/ion/ion_system_heap.c

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm: memory: Use standard cache routines

Convert custom clean, flush, and invalidate cache routines to use
standard ARM cache routines.

Change-Id: Ida0c539b89e1b6c98542221f847a9bcd7fc32a2e
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 29bb4d5fa7a285c8fb5d5db55225dab700b80419)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm: vidc: Downloads firmware using pil_get.

Downloads video codec firmware using pil_get
for secure sessions only. Firmware is not
downloaded using pil_get for non-secure
sessions.

Conflicts:

	drivers/video/msm/vidc/1080p/resource_tracker/vcd_res_tracker.c

Change-Id: I84b7a1d70ed1f505838930a192e5d1afdbfc54c1
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm: Enable all IOMMU's

Enable video, camera, display, and rotator IOMMU's so
that virtual contigious memory can be used by these
devices. Physical contigious carveout regions can
be reduced so that more memory is available to the
rest of the system when not in use by multimedia.

Change-Id: Ibfad7d6a55e04490be9e39a5539780657f6727e0
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm: 8960: Add correct PASR mask support

The current system does not use the correct PASR masks for turning
off sections of memory. It will also crash if the SPARSEMEM section_size
is changed to smaller values.

This fix calculates the correct masks and removes the dependency on
the SPARSEMEM section_size. It will accurately calculate the mask
regardless of memory size and configuration.

MAX_NR_REGIONS has been increased to 32 to account for the largest
system containing four memory banks, each divided into 8 sections.

Change-Id: Idaf05a06c1430e6d353fddafa305b57e400dfb8c
CRs-fixed: 329575
Signed-off-by: Jack Cheung <jackc@codeaurora.org>
(cherry picked from commit d01fd83bf9182b0a37abb3c4a2b9cd5e8ced4bd5)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
vidc: Adjust core timeout based on current core frequency.

Core timeout value is calculated based on the current core
clock rate during video play back.

Change-Id: I52f38560eda71dd0eaf208da68b4c3f74955661b
CRs-fixed: 354069
Signed-off-by: Mohan Kumar Gubbihalli Lachma Naik <mgubbi@codeaurora.org>

Conflicts:

	drivers/video/msm/vidc/1080p/resource_tracker/vcd_res_tracker_api.h

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>

Conflicts:

	drivers/video/msm/vidc/1080p/ddl/vcd_ddl_shared_mem.c
	drivers/video/msm/vidc/1080p/ddl/vcd_ddl_shared_mem.h
vidc:1080p: Set video core timeout value for Thumbnail mode

Video core timeout value is set only for thumbnail mode.
For normal playback senario default value is set.

CRs-fixed: 367222
Signed-off-by: Mohan Kumar Gubbihalli Lachma Naik <mgubbi@codeaurora.org>
(cherry picked from commit 740d5ad28484b42ae675721a66a1bd93081712c8)
Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>

Change-Id: I32ee573b21fd79d44d578a773294ba9973f1c00d
Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm_fb: display: remove mixer1 waiting4vsync when staging down the pipe

dtv_pipe is the base layer pipe for mixer1. Waiting for vsync when
staging down this pipe (it happens when we unplug HDMI cable) causes
mixer1 under run because at the vsync moment dtv_pipe is disconnected
to mixer1.

CRs-fixed: 349765, 355110
Signed-off-by: Huaibin Yang <huaibiny@codeaurora.org>
(cherry picked from commit b2bdae8ee4262a4e1d8e8e7f9c91b80790bdff27)

Change-Id: Ifcc38e5c954c4e58a9328ea3c85a5a1baa5ad826
Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit 8ff14bda4a8de3ab4c567c06d9eb283a996bb686)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm: kgsl: Write the retired timestamp on resume

Write the retired timestamp into the expected location. This fixes
userspace crashes after resume when the retired timestamp is read
as 0 instead of the expected last timestamp.

CRs-Fixed: 350556
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
(cherry picked from commit 68dba7b544a9f2351d61dff7f7c47aaff96d0413)

Change-Id: Ib44eb3c48f642d3b3b219f3ce666175472f03196
Signed-off-by: Zhoulu <zluo@codeaurora.org>