video: tegra: nvmap: wrap fast_cache_maint_outer inside its CONFIG

Use CONFIG_NVMAP_OUTER_CACHE_MAINT_BY_SET_WAYS to define
fast_cache_maint_outer().

Change-Id: I374598e3d1c10aaac3910d5477e32759cab1c7a8
Signed-off-by: Varun Wadekar <vwadekar@nvidia.com>
video: tegra: nvmap: Add config to fill page pools at init.

This config option allows disabling page pool fill during page pool init
and avoids increase in boottime.

Change-Id: Icdffd5c3e7114d9c368c8900c53adf72be2f3462
Signed-off-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-on: http://git-master/r/123545
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>
video: tegra: nvmap: Fix debugfs file permissions.

Change-Id: I3f2d0e2bff35ed868267fd85b5bf7d83d3317bf4
Signed-off-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-on: http://git-master/r/131226
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Alex Waterman <alexw@nvidia.com>
video: tegra: nvmap: Validate handle in nvmap_pin.

Change-Id: Idb4290cb47cc64c525ca9087c8c9e4239baefa6a
Signed-off-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-on: http://git-master/r/131229
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: Vandana Salve <vsalve@nvidia.com>
video: tegra: nvmap: Validate page pool entries.

Change-Id: I519c66e553f6b188446a2d771bffa9a45ef51201
Signed-off-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-on: http://git-master/r/131230
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Alex Waterman <alexw@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Vandana Salve <vsalve@nvidia.com>
video: tegra: nvmap: Introduce dma-buf exporter

Based on Terje's host nvmap exporter.

Change-Id: I9627ac9c4fc838f2e2c5c95b6972aa6185be7d6b
Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
Cc: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-on: http://git-master/r/133500
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
video: tegra: nvmap: fix cache_maint leak

Under certain error conditions, nvmap's cache_maint would do an early
return while holding an incremented refcount and an allocated pte,
causing leaks.

Bug 1042888

Change-Id: Ie6d557f5678e7475cf46c1524a43ed464502e94c
Signed-off-by: Tuomas Tynkkynen <ttynkkynen@nvidia.com>
Reviewed-on: http://git-master/r/131887
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
video: tegra: nvmap: fix pinning unalloc'd handles

nvmap_pin_ids takes a list of handles to pin from userspace.
Unfortunately, it does not check that the handles are actually
allocated, which will trigger a BUG_ON later in pin_locked().

Bug 1023954

Change-Id: Iba4c53bc0a6c47b7f4f740a93e59b613dc3b95f6
Signed-off-by: Tuomas Tynkkynen <ttynkkynen@nvidia.com>
Reviewed-on: http://git-master/r/131888
Reviewed-by: Mrutyunjay Sawant <msawant@nvidia.com>
Tested-by: Mrutyunjay Sawant <msawant@nvidia.com>
video: tegra: nvmap: Add pin, unpin trace events

Change-Id: I62deda9d607476e3dc82428b872ad1a3e396e37e
Signed-off-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-on: http://git-master/r/143421
Reviewed-by: Mrutyunjay Sawant <msawant@nvidia.com>
Tested-by: Mrutyunjay Sawant <msawant@nvidia.com>
video: tegra: nvmap: Add support for nvmap_kmap

Add support for mapping a single page from a buffer to kernel address
space.

Bug 1158533

Change-Id: Ie331e787663d98b644aa2e7f220020982f15fd9d
Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com>
Signed-off-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-on: http://git-master/r/145503
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Ken Adams <kadams@nvidia.com>
Reviewed-by: Juha Tukkinen <jtukkinen@nvidia.com>
video: tegra: nvmap: implement fast api functions

Implement optimized nvmap_pin_array() for fast pinning
of array of nvmap_handles.

Implement fast nvmap functions which skip slow validation
step if it is possible:

_nvmap_duplicate_handle_id()
_nvmap_free()
_nvmap_pin()

bug 1158533

Signed-off-by: Kirill Artamonov <kartamonov@nvidia.com>
Change-Id: I4639973bf9cf507ed68a03087ec6a91449f8453e
Reviewed-on: http://git-master/r/147505
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
video: tegra: nvmap: Clean up fast_cache_maint()

Get rid of ifdef in a function for readability.

Bug 1158336

Change-Id: I31e9521f97dda91fecf523bcd49ff5b34db86e45
Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
Reviewed-on: http://git-master/r/161207
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Alex Waterman <alexw@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
video: tegra: nvmap: Configurable cache_maint_{inner,outer}_threshold

Introduce configurable cache_maint_{inner,outer}_threshold via debugfs.

Bug 1158336

Change-Id: I0b20d44ddf1e8e88954ac8fac7750b4e31959564
Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
Reviewed-on: http://git-master/r/161208
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
video: tegra: nvmap: Set cache_maint_inner_threshold 2MB for T11x

Equal to the size of L2 cache on T114.

Bug 1158336

Change-Id: Ib3dfb4d26ccd36a63a8336f60ecf679105a1a44a
Signed-off-by: Hiroshi Doyu <hdoyu@nvidia.com>
Reviewed-on: http://git-master/r/161231
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
video: tegra: nvmap: Return error for re-allocation request.

Bug 898294

Change-Id: I176918d07d0f622db36b9be18ac726c06dc59432
Signed-off-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-on: http://git-master/r/161826
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Alex Waterman <alexw@nvidia.com>
video: tegra: nvmap: Fix heap compactor under OOM

The carveout heap compactor wasn't really prepared for running out of
memory, and would trigger a BUG_ON instead.

Bug 1024556

Change-Id: I661942d787a1fe59ab35e035d124e4cfaeed69b3
Signed-off-by: Tuomas Tynkkynen <ttynkkynen@nvidia.com>
Reviewed-on: http://git-master/r/131889
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
video: tegra: nvmap: expose a few nvmap interfaces for RM

Bug 979808

Change-Id: I06c11409f7cb300f2a8040a0623577c3db91c79f
Signed-off-by: Jin Qian <jqian@nvidia.com>
Reviewed-on: http://git-master/r/135142
Reviewed-by: Automatic_Commit_Validation_User
Tested-by: Antoine Chauveau <achauveau@nvidia.com>
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
video: tegra: nvmap: use phys_addr_t to hold phys addr

Bug 1182878

Change-Id: I1f4888bf049ec362388c8db07ee0b0b43a375e46
Signed-off-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-on: http://git-master/r/167111
Reviewed-by: Mrutyunjay Sawant <msawant@nvidia.com>
Tested-by: Mrutyunjay Sawant <msawant@nvidia.com>
nvmap: implement deferred cache maintenance

Defer maintenance till pin or unmap. Handle multiple deferred
operations in batches to flush faster. Enable full L1/L2 flush
if batch is big enough.

bug 983964
bug 994226

Reviewed-on: http://git-master/r/138931
(cherry picked from commit 01d0145ea95c7f98aa4bea3f71962872ba70bdfc)
Change-Id: I29bc82ded1fd7282426e8f161cc55e17f67fc649
Signed-off-by: Kirill Artamonov <kartamonov@nvidia.com>
Reviewed-on: http://git-master/r/171176
Reviewed-by: Riham Haidar <rhaidar@nvidia.com>
Tested-by: Riham Haidar <rhaidar@nvidia.com>
nvmap: expose refs, dupes, pins in debugfs

Expose data needed for debugging memory leaks in nvmap.

Change-Id: I7011ea63eceb6a2de9cd8363c78555dee680ae04
Signed-off-by: Kirill Artamonov <kartamonov@nvidia.com>
Reviewed-on: http://git-master/r/171178
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Antoine Chauveau <achauveau@nvidia.com>
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>