msm: iommu: Switch to the new clock APIs

Change-Id: I26521f28bc0217eaf394ff4c133bb3266b7582b5
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
msm: iommu: Convert spinlocks to mutexes

Use a mutex to protect the IOMMU data structures to allow
use of the new clock APIs from within lock-protected
regions.

Change-Id: I89a932d42e37d7860485add1b857288fd5947aea
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
msm: iommu: Support IOMMU page fault reporting

Provide the ability to report IOMMU fault events through
the IOMMU API. The driver will fall back on the previous
behavior of printing the fault information registers if no
domain fault handler is registered, or if the handler
returns -ENOSYS.

Change-Id: I9144e9b4bba117b67c7d81609e986ea716b34882
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
iommu/core: Add fault reporting mechanism

Add iommu fault report mechanism to the IOMMU API, so implementations
could report about mmu faults (translation errors, hardware errors,
etc..).

Fault reports can be used in several ways:
- mere logging
- reset the device that accessed the faulting address (may be necessary
  in case the device is a remote processor for example)
- implement dynamic PTE/TLB loading

A dedicated iommu_set_fault_handler() API has been added to allow
users, who are interested to receive such reports, to provide
their handler.

Change-Id: Id049671b7a0df27476c3cad451c2505e9b260ab6
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
iommu/core: let drivers know if an iommu fault handler isn't installed

Make report_iommu_fault() return -ENOSYS whenever an iommu fault
handler isn't installed, so IOMMU drivers can then do their own
platform-specific default behavior if they wanted.

Fault handlers can still return -ENOSYS in case they want to elicit the
default behavior of the IOMMU drivers.

Change-Id: I4cb7d6566f9d0f4329c37e890fee6c113edeb981
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
iommu: Initialize domain->handler in iommu_domain_alloc()

Since it is not guaranteed that an iommu driver initializes in its
domain_init() function, it must be initialized with NULL to prevent
calling a function in an arbitrary location when iommu fault occurred.

Change-Id: I1001bc6382cfe1e6cf8f311a822380f4151f8391
Signed-off-by: KyongHo Cho <pullip.cho@samsung.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
[stepanm@codeaurora.org: rebased to before the file moved]
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
msm: kgsl: Upgrade Adreno driver

 * Matches CAF ics_strawberry at commit b53d895b55dfcbc77a6308c7cfb423e98e53599b

Change-Id: I05e75c05c3782d9edacc47834c485b699f96c23e
msm: kgsl: Program both IOMMUs at our disposal on 8064

APQ8064 has two AXI ports attached to the GPU with an IOMMU on both.
The VBIF can be programmed to use a round-robin arbitration to access
the ports equally, so we need to program both IOMMUs with the same
pagetable to make sure that the GPU can get where it needs to go.
All this involves a board file infrastructure change that affects 8960
too, but no functional changes are happening for that platform.

Change-Id: Ic0dedbad5198ed9c453711e58a3f1220ef5d5b4e
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/board-8064-gpu.c
	drivers/gpu/msm/kgsl_iommu.c
	include/linux/msm_kgsl.h
msm: kgsl: fix 8960 2d1 iommu name

The correct name is gfx2d1_2d1.

Change-Id: I7e988c0ac88fb4006096b210f829e7ad80e73c12
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
msm: kgsl: Add a pwrscale policy to interact with msm_dcvs

This pwrscale policy provides per-core idle information to the
msm_dcvs driver.  It accepts frequency updates from the msm_dcvs
driver and updates the core frequency as needed.

Change-Id: I201cfcb6ceedc19c27f7848781813d9c477f9f83
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/board-8064-gpu.c
	arch/arm/mach-msm/devices-8960.c
	drivers/gpu/msm/kgsl_pwrscale_msm.c
msm: kgsl: Allow SLEEP/SLUMBER/SUSPEND states to wake to nominal voltage

Waking in turbo drains power while the high nominal frequency of 300MHz is
generally enough to handle rapid requests.

Change-Id: I01a8261b6431556b483e59d1c2ae539ff094c751
Signed-off-by: Lucille Sylvester <lsylvest@codeaurora.org>
msm: kgsl: Change iommu structure to better represent the hardware

Change the iommu structures to properly represent the iommu hardware
which makes the code more readable.

Change-Id: I61cf988998da3fc4f62ca020e4240cf50ddd20f0
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/board-8064-gpu.c
	arch/arm/mach-msm/board-8930-gpu.c
	drivers/gpu/msm/kgsl_iommu.c
	drivers/gpu/msm/kgsl_iommu.h
msm_fb: display: add iommu mapping for mdp cursor buffer address

The mdp h/w cursor buffer physical address needs to be mapped to an
iommu virtual address when iommu domain is enabled.

Change-Id: I73b4492fc4d63632117074136e4d908f5089eb93
Signed-off-by: Huaibin Yang <huaibiny@codeaurora.org>
msm_fb: display: enable sending uevent as default

Enable sending vsync uevent as default so that uevent will
be sent to usersapce frame work when first request recevied

Change-Id: If72248007d68cba8fc814d449b46a58d842544ba
Signed-off-by: Kuogee Hsieh <khsieh@codeaurora.org>
msm_fb: display: vsync support for HDMI as primary

When HDMI is primary, dtv is associated with node 0. In this case,
DTV vsync and ctrl need to be called for node 0.

CRs-Fixed: 383877
Change-Id: I425cddf453dd159259883e71f92c32918ca8e6c7
Signed-off-by: Ajay Singh Parmar <aparmar@codeaurora.org>
video: msm: Add DMA busy wait to Samsung MIPI driver

 * Fixes lockups on resume

Change-Id: I42c460f4fc0130714c74606b2512507e0d96b2b0
msm: rotator: Add secure session flag to rotator start data

Add flag for handling secure session to rotator data passed during
start ioctl call.

Signed-off-by: Ravishangar Kalyanam <rkalya@codeaurora.org>
(cherry picked from commit 1eca352482747613e90cbd6f2eeaa91e21351de6)

Change-Id: I155a794329d2f104d493bae5f8a8037e8520b287
Signed-off-by: Dhivya Subramanian <dthiru@codeaurora.org>
msm_fb: display: Increase MDP IOMMU buffer mapping size

Double the MDP IOMMU buffer mapping size to allow overfetching
by hardware for boundary conditions and avoid system crashes
due to page faults.

CRs-Fixed: 378108
CRs-Fixed: 364478
Signed-off-by: Ravishangar Kalyanam <rkalya@codeaurora.org>
Change-Id: Ib19af6b06ab06455acaffcca33830e0487bb0836
(cherry picked from commit 1ed0dae869f6384d23322b78691852d70c573174)

Conflicts:

	drivers/video/msm/mdp4_overlay.c

Signed-off-by: Dhivya Subramanian <dthiru@codeaurora.org>

Conflicts:

	drivers/video/msm/mdp4_overlay.c
msm: camera: Squashed set of bugfixes from CAF

Change-Id: I7e50e0799351468a06ef92d1cb07772c9213322c

msm: camera: Not allocate memory for the buffer done event.

Unnecessary code cleaned.

Change-Id: I9ffd389156a971a867475ff9ea6d4a7f8ca70cab
Signed-off-by: Mingcheng Zhu <mingchen@codeaurora.org>

Conflicts:

	drivers/media/video/msm/msm_vfe31_v4l2.c
	drivers/media/video/msm/msm_vfe32.c
	drivers/media/video/msm/msm_vfe7x27a_v4l2.c

msm: Camera: clear control queue

Clear control queue everytime before entering wait in msm_control as
there might be invalid payloads in the queue and this can lead to
not waiting at all and exit before the valid command completes.

Change-Id: Iee83bc51e0c3568f73c1f900d72df41c63a3ace6
Signed-off-by: Manogna Reddy Alle <cmalle@codeaurora.org>
(cherry picked from commit 008ccc5b4e2b7e05d1dd4d6054c31828ef29d17f)
Signed-off-by: Gopal G Goberu <ggober@codeaurora.org>

msm: camera: Fix the VPE state machine to avoid multiple VPE disable.

Patch to ensure VPE state machine is handled properly in case of
monkey runs. This is a corner case where vpe disable got triggered
twice.

(cherry picked from commit 257b4192a9e73f55457cd56c890ba2d8de3c8f3f)

Change-Id: I21282a0adcdf978f1b65c81d07b15702a0ab7061
CRs-Fixed: 330166
Signed-off-by: Azam Sadiq Pasha Kapatrala Syed <akapatra@codeaurora.org>

Camera : Change to retreive system time from Kernel

This timestamp is needed in the userspace to flush old
video frames.

Change-Id: I432e5f5d35581b10857b41930d7751500ea131dc
Signed-off-by: Guruprasad Gaonkar <ggaonk@codeaurora.org>

Conflicts:

	include/media/msm_camera.h

msm: camera: Add plane's data offset in address calculation.

When a frame is diverted for postprocessing, and returned
back to kernel, the address of plane 0 is used to find
the buffer in the queue. Use the data offset field of
plane 0 in the address calculation, otherwise we will
not be able to find the buffer.

Change-Id: I91b1c61e4fe04a44f5d76457ab91aaba3e815ad3
CRs-Fixed: 324846, 323332
Signed-off-by: Kiran Kumar H N <hurlisal@codeaurora.org>

msm: v4l2: fix support for test app.

This commit fixes bug in query-cap ioctl and
adds ION support for case where buffers are
allocated in the kernel with mmap. This change
is required to fix the V4L2 command line test app.

Signed-off-by: Ankit Premrajka <ankitp@codeaurora.org>
(cherry picked from commit d814743600bf0b5c26ec4a532d47fce828c18d6f)

Change-Id: I3293252424ba419ff1cfa375e658ec4ff53986b1
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>

Conflicts:

	drivers/media/video/videobuf2-msm-mem.c
	include/media/videobuf2-msm-mem.h

msm: Camera: Reset base csi address to NULL

Reset base csi address to NULL after unmapping the memory region
to make sure that the csi hardware registers are not programmed until
base address is mapped to fix the data abort in kernel which occurred
randomly during a stability test.

CRs-fixed: 332716
Signed-off-by: Manogna Reddy Alle <cmalle@codeaurora.org>
(cherry picked from commit 966020a3e78a70ba8d7c86c5a721715fc56c6eb8)

Change-Id: I3144733066955034628e45c120e0d42cf253541d
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>

msm: camera: send error to HAL if daemon crashed.

When camera userspace daemon crashes, the server fd
will be close, which trigger the msm_server_close
function, we will check if there is an active camera
session. If camera is active, we will send a v4l2
event to HAL layer to signal an error. Application
will exit gracefully and close other open fds and
exit camera session.

Change-Id: I14ebc864d6cace7ca6f4dbfb935623a76eeccaa8
Signed-off-by: Kevin Chan <ktchan@codeaurora.org>

Conflicts:

	drivers/media/video/msm/msm.c
	drivers/media/video/msm/msm.h
	drivers/media/video/msm/msm_mctl.c

msm: camera: Fix crash issue while enabling regular stats

Update the AEC, AWB, AF, HIST and RS/CS buffers and fds
before passing the stats message to the upper layer

Change-Id: I98b03638ea27669263cd11798ca2af8dda6a98df
Signed-off-by: Sunid Wilson <sunidw@codeaurora.org>
(cherry picked from commit d803a63cbc771e1685f976e2964a16a0468c8bb0)

msm: camera: Assign Null to unmapped addresses

Observed unhandled virtual addresses with all the camera drivers
while performing reads and writes to the ioremap addresses in different
scenarios, Hence assigining NULL to all the hardware remapped addresses
immediately after the iounmap calls

Signed-off-by: Lakshmi Narayana Kalavala <lkalaval@codeaurora.org>
(cherry picked from commit 72ee044121488cc9f4cde91c5e3a2b820d7a0fad)

Change-Id: Ia0a74ca35e8575b18da8350cb6de83752ee0b11b
Signed-off-by: Shruthi Krishna <skrish@codeaurora.org>

Conflicts:

	drivers/media/video/msm/csi/msm_csic.c

msm: camera: handle mediaserver crash elegantly.

This change stops the VFE first, before unmapping the buffers
registered in the kernel in the scenario of a mediaserver
crash.

(cherry picked from commit f3ae3699dd3140c857835901b68d293fb0629f85)

Change-Id: I38a4e62b3adf12582b07084056975f74db56086b
Signed-off-by: Ankit Premrajka <ankitp@codeaurora.org>
(cherry picked from commit a7c397f44e5c28ae9c0fed21771acc12837ee1d4)
(cherry picked from commit 01e1261625181f00e42335ccc16942f6b3928b87)

msm: camera: Flush event queue during close.

Event queue needs to be drained to avoid picking any
stale entries in the future iterations

CRs-Fixed: 360672

Signed-off-by: Azam Sadiq Pasha Kapatrala Syed <akapatra@codeaurora.org>
(cherry picked from commit 34fc95b423796e7b1d474171af67784a5678cfd2)

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

msm: camera: allocate memory properly to avoid passing local variable as reference.

1. allocate memory in msm_server_control to avoid passing local variable as
   reference to event queue
2. Safe coding: Set pointer to NULL in some kfree
3. only dqbuf when streamon
4. Add per instance lock to serialize stream operation

Change-Id: I6e87faa1bd05ada9dc94510cb6414c2a670dae63
Signed-off-by: Mingcheng Zhu <mingchen@codeaurora.org>
Signed-off-by: Peter Liu <pingchie@codeaurora.org>
(cherry picked from commit 49253c236c00ffa5d83e809a7d6f68db28aa3852)

Conflicts:

	drivers/media/video/msm/actuators/msm_actuator.c

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

Conflicts:

	drivers/media/video/msm/msm.c
	drivers/media/video/msm/msm_vfe32.c

msm: camera: Fix camera devices disable sequence

Ensure clocks are turned off after tasklet is kill
and device is not in active state. This is to
prevent bus lockdown if the device is accessing
the bus and clock is turn off
Also ensure clocks are on, when accessing hardware
registers.

(cherry picked from commit 57701f7109efafa8d38b69808e307fbda2e90224)

Change-Id: I0f9fb6d4b60eba5afb47814315f07e0efa15251c
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>

Conflicts:

	drivers/media/video/msm/csi/msm_csid.c
	drivers/media/video/msm/csi/msm_ispif.c
	drivers/media/video/msm/msm_vfe32.c
	drivers/media/video/msm/msm_vpe.c

msm: camera: Correct the reserve buffer logic in mctl_pp.

When the daemon asks to reserve a free buffer, get the
correct address by using the image mode to get to the
correct camera instance and populating the buffer address.

Signed-off-by: Kevin Chan <ktchan@codeaurora.org>
Signed-off-by: Kiran Kumar H N <hurlisal@codeaurora.org>
Signed-off-by: Ujwal Patel <ujwalp@codeaurora.org>
(cherry picked from commit 318d7cbd8eaaced74293b90bec8533a280d41bdc)

Change-Id: I21f329a52bfe51501f1a87bb8a62c51213e5d1bb
Signed-off-by: Yen-Pin Hsiao <yphsiao@codeaurora.org>
msm: camera: Fix IRQ handling in vfe32

 * Only request during probe, enable and disable in correct place
 * Properly initialize the tasklet

Change-Id: Ie1fabea93ef0d0eff4aaa0cd29fae47b81dbc6ed