GitHub/LineageOS/android_kernel_motorola_exynos9610.git
6 years ago[COMMON] mm: hpa: fix using invalid array index
Cho KyongHo [Wed, 19 Apr 2017 14:27:03 +0000 (23:27 +0900)]
[COMMON] mm: hpa: fix using invalid array index

Change-Id: I433e9f33ae3931319b52cb977bbf178a74287fe4
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years ago[COMMON] mm: hpa/cma: introduce alloc_contig_range_fast()
Cho KyongHo [Wed, 19 Apr 2017 14:57:19 +0000 (23:57 +0900)]
[COMMON] mm: hpa/cma: introduce alloc_contig_range_fast()

HPA allocates lots of order-4 pages from alloc_contig_range(). But it
consumes the most of time to flush per-cpu LRU and per-cpu free pages
that is not required for HPA.
alloc_contig_range_fast() does not flush the per-cpu pages. Therefore
it may fail to reclaim the given range of pages. The users that need
guarantee of success of reclamation of the given range of pages, they
can call alloc_contig_range() as they did. Its behavior is unchanged.

Change-Id: Ie9d545132c7450713ff7724099d24a2ffd766cb1
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years ago[COMMON] mm: hpa: avoid selecting a victim that was a victim
Cho KyongHo [Fri, 3 Feb 2017 12:35:39 +0000 (21:35 +0900)]
[COMMON] mm: hpa: avoid selecting a victim that was a victim

Totally the same logic with the following patch:
0f7b387 [COMMON] lowmemorykiller: when killing timeout, choose other process

HPA eventually invokes its internal task killer, HPA Killer that
selects a victim task with the highest oom_adj and the largest rss. It
signals SIGKILL the victim task and expects the victim task to be soon
died.
HPA Killer skips selecting another task on the next invocation until
the victim task is finally died during a second unless it finds
another victim task that is more proper to kill. If the task is not
died in a second, HPA killer is to select the same task as a victim
because of the victim selection logic.
If the victim task is in disk sleep state and it waits for a resource
that is occupied by the task that invoking HPA Killer, HPA Killer will
be never finished until another larger task with higher oom_adj is
appeared.
To end ths dead-lock condition, HPA Killer should select next proper
victim task even though the current victim task is not died.

Change-Id: I73afdce457976c9a8f60e92d8d96e792ea854c7c
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years ago[COMMON] mm: hpa: prevent allocating cma pages from HPA
Cho KyongHo [Thu, 2 Feb 2017 15:07:24 +0000 (00:07 +0900)]
[COMMON] mm: hpa: prevent allocating cma pages from HPA

HPA turns movable pages into the unmovable for playing DRM contents.
But CMA pages should be always ready for reclamation. Therefore, they
should not be unmovable at all time.

Change-Id: I4dbdd7bc065c1c40f7c6bd80fa55c49a46711482
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years ago[COMMON] mm: hpa: initialize local variable
Sunyoung Kang [Fri, 2 Sep 2016 02:47:26 +0000 (11:47 +0900)]
[COMMON] mm: hpa: initialize local variable

Fix Svace: 64228

Change-Id: Ic29475767bd4cbd8043677abf435c4ab478dd2b7
Signed-off-by: Sunyoung Kang <sy0816.kang@samsung.com>
6 years ago[COMMON] mm: introduce High-order Pages Allocator
Sunyoung Kang [Mon, 4 Jul 2016 06:50:57 +0000 (15:50 +0900)]
[COMMON] mm: introduce High-order Pages Allocator

The high-order pages allocator (aka. HPA) has been introduced to ensure
successful allocation of high-order pages always with given order and size.
The HPA tries to allocate pages from buddy and then if any pages are in use,
tries to reclaim and migrate pages.

Change-Id: I61a7fe76d4a1c6a1058d2fe731bbfef8d3e6959a
Signed-off-by: Jinsung Yang <jsgood.yang@samsung.com>
Signed-off-by: Sunyoung Kang <sy0816.kang@samsung.com>
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: fix missing debug info of cma heap
Cho KyongHo [Tue, 6 Mar 2018 12:19:30 +0000 (21:19 +0900)]
android: ion: fix missing debug info of cma heap

cma heaps shows the list of allocated buffers from their heap. But
cma heaps do not show the list when cma fails to allocate, actually.

Change-Id: I4b2264bd213d77d7c4276a45b560e6611b4c3b93
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add dmabuf cpu access ops for exynos
Cho KyongHo [Fri, 2 Mar 2018 14:03:48 +0000 (23:03 +0900)]
android: ion: add dmabuf cpu access ops for exynos

.begin_cpu_access and .end_cpu_access of dmabuf ops provided by ION
needs scatter-gather list because they rely on dma-mapping api.

After 'commit 8dbbf7b ("android: ion: do not map in dma_map_attach()
for Exynos")', ion_dma_buf_begin_cpu_access() and
ion_dma_buf_end_cpu_access() loose scatter-gather list stored in
the dma-buf attachment that is eliminated by the above commit.

Instead, dma-mapping api can be used with ion_buffer.sg_table and the
miscdevice of ion_device because they are initialized at buffer
allocation and ION initialization, respectively since 'commit 10a41c2
("android: ion: add fixups to ion exynos extension")'.

Uncached buffers are not required to maintain CPU caches for CPU
accesses because dma_buf_kmap() returns the kernel address with the
cacheability attribute of the buffer.

Change-Id: I6656f22b696ae96de9f2766751970b25f17572f6
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: fix compile error
Janghyuck Kim [Tue, 6 Mar 2018 02:03:28 +0000 (11:03 +0900)]
android: ion: fix compile error

This patch fixed below compile error when CONFIG_ION_EXYNOS is not
defined.

In file included from drivers/staging/android/ion/ion.c:42:0:
drivers/staging/android/ion/ion_exynos.h:102:25: error:
'ion_exynos_map_dma_buf' defined but not used [-Werror=unused-function]
 static struct sg_table *ion_exynos_map_dma_buf(struct
dma_buf_attachment *att,

Change-Id: I22b9d0e87856bff9a9e307e49698fa9fa3677a3b
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years agoandroid: ion: add checking of returned page
Janghyuck Kim [Wed, 28 Feb 2018 08:11:52 +0000 (17:11 +0900)]
android: ion: add checking of returned page

This patch added checking code to avoid invalid address access for cache
operation.
ion_page_pool_alloc_pages() might return NULL when alloc_pages() could
not get enough pages as requested order, especially in high-order case.

Change-Id: I7aa2bb08f32f523f5b76930b46c0f47d3457895b
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years agoandroid: ion: free iova at buffer destruction time
Janghyuck Kim [Tue, 27 Feb 2018 09:24:10 +0000 (18:24 +0900)]
android: ion: free iova at buffer destruction time

In order to optimize the performance of ion_iovmm_unmap(), the actual
unmapping of the device virtual address is deferred. It is expected to
work at buffer destruction time, but this is missing. So unmapping code
is added to work properly.

Change-Id: Ie2dffa58df5125baf4a4e9723db241846e860443
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years agoarm64: dts: add reserve mem for exynos9610 of 4.14
hyesoo.yu [Fri, 11 May 2018 07:06:00 +0000 (16:06 +0900)]
arm64: dts: add reserve mem for exynos9610 of 4.14

Change-Id: I4d304c4c8010febf5ffa25f660215a6020e0616e
Signed-off-by: hyesoo.yu <hyesoo.yu@samsung.com>
6 years agoarm64: erd9610_defconfig: enable the new ION
hyesoo.yu [Fri, 11 May 2018 06:54:56 +0000 (15:54 +0900)]
arm64: erd9610_defconfig: enable the new ION

Change-Id: I51e5aa321ffea0ad8147a5f3c3e4fc47eade0380
Signed-off-by: hyesoo.yu <hyesoo.yu@samsung.com>
6 years agoandroid: ion: add show all buffers of contig heaps
Cho KyongHo [Wed, 21 Feb 2018 09:28:52 +0000 (18:28 +0900)]
android: ion: add show all buffers of contig heaps

ION heaps of physically contiguous memory pool is vulnerable to memory
external fragmentations. If an allocation from such heaps has failed,
ION just returns 'out of memory' error. But users need to know if the
error is caused by insufficient free space or fragmentations. Their
actions to the error should be different according to the reason.
Therefore ION ought to tell the users the list of allocated buffers
from the physically contiguous heaps.

Change-Id: I0ea0dd81cfac8f8b019a763480f5c7af22b8eac0
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add kernel log on errors
Cho KyongHo [Thu, 22 Feb 2018 11:55:24 +0000 (20:55 +0900)]
android: ion: add kernel log on errors

It is very important to know the reason of an exception. It is too
difficult to know the details about the exception with an error
number returned by ION.

Change-Id: I51f92bb1cc1c1eee2e0a1a17803d4f5bb0720433
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: do not map in dma_map_attach() for Exynos
Cho KyongHo [Thu, 22 Feb 2018 06:40:48 +0000 (15:40 +0900)]
android: ion: do not map in dma_map_attach() for Exynos

dma_buf ops of ION does two unneccessary works. One is duplicating
sg_table in dma_map_attach() and the other is dma_map_sg() call in
dma_buf_map_attachment(). The duplication of sg_table is neccessary
in fact because dma_map_sg() updates dma_address fields of scatter-
gather list in sg_table with the DMA address of the given device.
It is true with the devices with IOMMU that provides dma-mapping ops.
But our IOMMU, System MMU driver does not provide dma-mapping ops.
Therefor, DMA addresses of the same physical memory location are not
different between devices in Exynos SoCs.

ion_buffer_create() calls dma_map_sg() to initialize dma_address
fields sg_table from the following commit:
'commit 8215d29 ("android: ion: add fixups to ion exynos extension")'

Now we can use the sg_table in ion_buffer for all devices. We can
avoid duplicating sg_table on every dma_buf_attach() call. We can
replace dma_map_sg() with dma_sync_sg_for_device() in
dma_buf_map_attachment().
ion_dma_buf_attach() and ion_dma_buf_detach() are no more required.
it does nothing after sg_table duplication is removed.

For the maintenance reason, we do not remove the unused dma_buf ops
of ION in ion.c. Instead we adds our implementation of map_dma_buf()
and unmap_dma_buf() ops to dma_buf ops of ION if CONFIG_ION_EXYNOS
is configured.

Change-Id: I1764a7eb62e948f074b596e316fe3f48ed3f8662
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add fixups to ion exynos extension
Cho KyongHo [Wed, 21 Feb 2018 12:42:47 +0000 (21:42 +0900)]
android: ion: add fixups to ion exynos extension

The purpose of the exynos extension is to attach addtional
improvements to ION. The first improvment is the elimination of
dma-mapping overhead.
dma_map_sg() and dma_unmap_sg() maps the given memory to the address
space of the given device. The mapping can be translation table update
if the device has iommu. It may allocate swiotlb buffer if the device
does not have iommu and the address space of the device is smaller
than the physical address space. dma_map_sg() and dma_unmap_sg() also
maintain CPU caches to ensure memory coherency.
The purpose of calls to dma_map_sg() and dma_unmap_sg() in
ion_map_dma_buf() and ion_unmap_dma_buf(), respectively is just
ensuring cache coherency in Exynos SoCs. We have another approach to
map the physical memory to the device address space, ion_iovmm_map().
But replacing dma_map_sg() with dma_sync_sg_for_device() does not work
because dma_sync_sg_for_device() needs dma_address fields to be
initialized by dma_map_sg().
This is the first step to replacing dma_map_sg() with
dma_sync_sg_for_device() in ion_map_dma_buf().
Buffer allocation now involves dma_map_sg() to assign dma_address
fields of ion_buffer.sg_table. dma_unmap_sg() is called by
ion_buffer_destroy().
Then we can finally use dma_sync_sg_for_device() in ion_map_dma_buf().

Change-Id: I8b439eddc0b3722a297ea395aa7e6f3ebc00b294
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: do not cache flush for uncached buffers
Cho KyongHo [Thu, 22 Feb 2018 06:52:48 +0000 (15:52 +0900)]
android: ion: do not cache flush for uncached buffers

Uncached buffers are touched by CPU with uncached addresses. Cache
maintenance on the uncached buffers is just redundant, no effect.

Change-Id: I04283f55760845834c1d12102669caa6ccc4f45a
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: remove redundant statements
Cho KyongHo [Wed, 21 Feb 2018 12:55:22 +0000 (21:55 +0900)]
android: ion: remove redundant statements

Change-Id: Ibaef184155aaef44c6d471e3a1d567c21d3f9115
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add ION_FLAG_MAY_HWRENDER
Cho KyongHo [Mon, 12 Feb 2018 05:48:49 +0000 (14:48 +0900)]
android: ion: add ION_FLAG_MAY_HWRENDER

Clients of ION in userland can specify if the allocated buffer is
written by H/W like GPU before S/W initializes it. If the cache
maintenance is fully supported by all H/Ws that touch the buffer or
all H/Ws touching the buffer are in the same cache coherency domain,
everything goes right. But the problem occurs due to the drivers that
does not perform cache maintenance due to the performance reason.
For the the different H/Ws that touch the same buffer in the different
cache coherency domain, the drivers should care when creating IO
memory mapping. ION_FLAG_MAY_HWRENDER and ion_hwrender_dmabuf() helper
give information to such drivers if the buffer is initialized by H/W.
ION_FLAG_MAY_HWRENDER effects nonthing in ION. Just documentation
purpose.

Change-Id: Iab6293f2c5d6017cf67378356721de4256f049b9
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add ion_cached_dmabuf()
Cho KyongHo [Mon, 12 Feb 2018 05:35:24 +0000 (14:35 +0900)]
android: ion: add ion_cached_dmabuf()

Some kernel clients of ION need to know if an ION buffer is cached.

Change-Id: I8a179e2ba4476408732e2d32441268883c9dc2c6
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add ion_iovmm_[un]map()
Cho KyongHo [Mon, 12 Feb 2018 02:19:32 +0000 (11:19 +0900)]
android: ion: add ion_iovmm_[un]map()

iovmm_map() provided by exynos-iovmm is time-consuming. If the same
buffer is iovm mapped to a device, iovmm_map() does the same thing
with much time. iovmm_map() is not able to avoid this repeat because
it has no information to identify a buffer. Thus, ION provides the
avoidance of repeating mapping the same buffer.

Change-Id: I4c62f615dca6dfb5f8d2fe366ccc0a89af1d485e
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: make dma_buf_ops of ION global
Cho KyongHo [Mon, 12 Feb 2018 01:34:16 +0000 (10:34 +0900)]
android: ion: make dma_buf_ops of ION global

It is the only way to verify if the given dma-buf is exported by ION.

Change-Id: I7925e9f88e34f6ecd123a4178531fd237b807ffa
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: remove the list of attachments
Cho KyongHo [Mon, 12 Feb 2018 00:45:03 +0000 (09:45 +0900)]
android: ion: remove the list of attachments

dma_buf also has the list of attachments. ion_buffer.attachments is
redundant. So, let's remove it.
dma_buf.attachment should be accessed with dma_buf.lock held. Holding
dma_buf.lock in begin_cpu_access() and end_cpu_access() is okay. But
it should be handled with care to prevent possible deadlock.

Change-Id: I6a4a5c74c1030874fc08684c6c84485373b47919
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add ion_alloc_dmabuf()
Cho KyongHo [Sun, 11 Feb 2018 11:37:11 +0000 (20:37 +0900)]
android: ion: add ion_alloc_dmabuf()

ION does not provide API to the kernel drivers.
Thus, ion_alloc_dmabuf() is introduced. To allocate a buffer from a
specific heap of ION, the client should query heaps to search proper
heap then allocate buffers with heap mask of the found heap. This
is tedious and error-prone task for drivers.
Let's allow drivers select a heap with heap name. The Exynos extension
to ION will find the heap with the given name and select the heap for
buffer allocation.
ion_alloc_dmabuf() returns dma_buf instead of fd. To deliver the
allocated dma_buf from ion_alloc_dmabuf() to the userspace, the client
driver should assign it to an unused fd by itself.

Change-Id: Iedc0f970fcc2ddcf4739a5d8c3ecec3cd137e280
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add properties to ion_heap_data
Cho KyongHo [Sun, 11 Feb 2018 08:34:49 +0000 (17:34 +0900)]
android: ion: add properties to ion_heap_data

ion_heap_data is lack of heap properties that is critical to users.
Users may want to know the total size of the cma/carved out memory
pools served by cma heap and carveout heap, respectively. They also
need to know if a heap provides buffer protection for DRM video
streams or allocated buffer from a heap can be accessed.

Change-Id: I3c3a6b9a41d32398ddfe1b1c21b3977e790e5c25
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add buffer protection
Cho KyongHo [Sun, 11 Feb 2018 08:08:35 +0000 (17:08 +0900)]
android: ion: add buffer protection

DRM video contents need protection of the decrypted video stream from
copying to insecure buffer. For the protection from copying, Exynos
SoC provides H/W based protection. Since H/W has limitation of
resources, the H/W needs the types of buffer protection, some special
limitation to alignments and limits to the memory pool to serve buffer
protection.
Every memory pool needs buffer protection should be specified in the
flattened device tree under 'reserved-memory' node like cma heaps and
carveout heaps. The heaps needs protection should have 'ion,secure'
boolean property that specifies buffers from the heap may needs buffer
protection. They also need 'ion,protection_id' which specifies the
types of buffer protection.
Buffers from the secure heaps are not protected unless users gives ION
ION_FLAG_PROTECTED flag. non-secure heaps just ignore the flag.

Change-Id: Ibef18c3fde7d628c2298abb95e71379c67cf7471
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add nozero and sync_force flags
Cho KyongHo [Fri, 9 Feb 2018 07:18:43 +0000 (16:18 +0900)]
android: ion: add nozero and sync_force flags

Allocation with ION_FLAG_NOZERED returns buffers without clearing data
written by previous users. ION should not allow userspace accessing
the buffer due to the security reason.
ION_FLAG_SYNC_FORCE is also introduced for some users that want to
decide the point of cache maintenance by itself. With the flag, ION
performs cache flush to the allocated even for cached buffers. those
users want this redundant cache flush to prevent buffer corruption by
victim dirty cache lines about the buffer after DMA write without
proper cache maintenance.

Change-Id: Ib3c4f9c93a6cd0240ae12b8c061142355e2b1605
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: initialize cma heap from device tree
Cho KyongHo [Thu, 8 Feb 2018 08:05:11 +0000 (17:05 +0900)]
android: ion: initialize cma heap from device tree

ION creates cma heaps for all cma region but a lot of cma regions are
not needed to be serviced by ION. If cma heap is required, some users
of ION needs physically contiguous memory for graphics and multimedia.
Exynos SoCs traditionally defines such cma regions in the flattened
device tree node under 'reserved-memory' node.
Since the cma regions may have additional properties which are not
identified by of_reserved_mem.c, the cma region definitions should be
handled by ION.

Change-Id: Ia23fd12f9422f1d9e3a86e5b1d403caa12a29867
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add fdt handling for carveout_heap
Cho KyongHo [Wed, 7 Feb 2018 11:36:08 +0000 (20:36 +0900)]
android: ion: add fdt handling for carveout_heap

Carveout heap provides buffer management for a reserved pool of
physical memory which is carved out by an early allocator like
memblock. Current ION is lack of how to initialize carveout heap.
We have decided to define the reserved memory pool in
"reserved-memory" device tree node with "exynos9820-ion" compatible
string.
The node may have the following properties in addition to the properties
of the child nodes of "reserved-memory" node:
- ion,untouchable: the buffer from the heap should not creates a
              mapping in the kernel and userland.
- ion,heapname: The name of the heap.
- ion,alignment: The alignment of buffers from the heap.

Change-Id: I41cdc72078a88795c8d6aca6af2c40e910330894
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add properties to carveout_heap
Cho KyongHo [Wed, 7 Feb 2018 08:01:10 +0000 (17:01 +0900)]
android: ion: add properties to carveout_heap

Added size, alloc_align, and untouchable properties to carveout heaps.
size property is used for debugging purpose. carvedout heaps are
suffering from the external fragmentations and out of memory when
users do not carefully handle the heaps. When allocation from a carved
out heap happens, the base and the size of the heap is very useful for
debugging.

Some heaps should have restriction of alignment of allocated buffers
to be larger than PAGE_SIZE. alloc_align property specifies this
restriction.

Some special heap has strange property, untouchable. If it is
specified, buffers from the heap should not be accessed from both of
userland and the kernel.

Change-Id: Ib4fd2a4af2e6307bf67aa28d06bbcbca393d4475
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: give name to carveout_heap
Cho KyongHo [Wed, 7 Feb 2018 07:38:09 +0000 (16:38 +0900)]
android: ion: give name to carveout_heap

Heap name is required by ion_query_heaps() because we cannot identify
a specific heap without name.

Change-Id: I39d886255c8381d11f067ec6f19a105e7269010c
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: fix missing error number in cma heap
Cho KyongHo [Thu, 22 Feb 2018 12:05:28 +0000 (21:05 +0900)]
android: ion: fix missing error number in cma heap

Change-Id: Ib08aa1eefbeb954327ce8052471c621fb1a91063
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: fix missing buffer initialization
Cho KyongHo [Fri, 9 Feb 2018 06:11:15 +0000 (15:11 +0900)]
android: ion: fix missing buffer initialization

Every buffer allocated to userspace should be initialized to a
specific pattern to remove data written by previous users of the
memory in the buffer. The initialization should include elimination
of dirty cache lines allocated for a uncached buffer to prevent write
back from dirty cache lines after uncached data write to the buffer.
This write-back corrupts the buffer with the stale data in the cache.

Cache flush on allocation uses __flush_dcache_area() that is not a
kernel API function allowed for the drivers. But we have no chice than
that because dma-mapping API needs a device descriptor configured for
DMA. Instead modifying pseudo device descriptor, ion_device, we have
decided to use ARM64 specific function __funsh_dcache_area() for
convenient maintenance.

Change-Id: I6d6dda56a5ac4f8cf9dc796b3eddb7ba40e337d9
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: do not defer free for carveout heap
Cho KyongHo [Wed, 7 Feb 2018 05:46:49 +0000 (14:46 +0900)]
android: ion: do not defer free for carveout heap

Carved out heaps allocate buffers from a memory pool of with a limited
size. If it frees buffers in deferred manner, the heap may not be
available in a rare condition by unexpected external fragmentations.
Let's think about the following scenario in a 10MB carveout pool:
  1. allocated 4MB @ +0MB
  2. allocated 2MB @ +4MB
  3. freed 1 but defferred
  4. freed 2 but defferred
  5. allocated 3MB @ +6MB
  6. returned buffer 1 and 2 to the heap.
  7. allocated 4MB @ +0MB
  8. allocation of 3MB failed due to the fragmentation.

Any defferred behavior to the very limited resources is harmful.

Change-Id: I0a64fdec56f0ec1992c20f8ccd50d5c7fbfa8d40
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years ago[COMMON] android: ion: fix overwriting gfp flags
Cho KyongHo [Thu, 22 Feb 2018 14:22:24 +0000 (23:22 +0900)]
[COMMON] android: ion: fix overwriting gfp flags

The following commit by Chen Feng introduces cached page pools to
improve the allocation perfromance of system heap types.
'commit e7f63771b60e ("ION: Sys_heap: Add cached pool to spead up
 cached buffer alloc")'

But it has a logical problem assigning gfp mask for page allocation
from the kernel page allocator. low_order_gfp_flags should be applied
to the low order page allocations but is is actually not because
high_order_gfp_flags overwrites the gfp_flags at the first iteration
of page pool creation and there is no chance to get back to
low_order_gfp_flags.

Change-Id: I4fb10bfc9f517e660e2f78661d67146380441ecb
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion-test: set correct dma configurations
Cho KyongHo [Tue, 6 Feb 2018 16:26:32 +0000 (01:26 +0900)]
android: ion-test: set correct dma configurations

ion-test does not need swiotlb buffer because it temporarily creates
writecombine mappings for test. Therefore it should have full dma
mask. Moreover, without correct dma_ops, dma_buf_map_attachment()
always fails. Let's configure dma_ops with arch_setup_dma_ops().

Change-Id: Iccdd0f7f593af42d7e708877723aae273bd4acf1
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion-test: addr error message about dmabuf
Cho KyongHo [Tue, 6 Feb 2018 16:21:23 +0000 (01:21 +0900)]
android: ion-test: addr error message about dmabuf

It is useful to distinguish where the error is returned.

Change-Id: I32a3ea5a81f7599fadf1d282fd2776305a0f749d
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion-test: change vmap() to map_vm_ram()
Cho KyongHo [Tue, 6 Feb 2018 16:17:40 +0000 (01:17 +0900)]
android: ion-test: change vmap() to map_vm_ram()

map_vm_ram() is faster than vmap() and is safe for short lived
mappings.

Change-Id: Iec262ade2ebf232b7cd4719e1ddf21f23c5474ae
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years ago[COMMON] android: ion: ion_test add ION_IOC_TEST_PHYS
Cho KyongHo [Tue, 30 May 2017 15:00:57 +0000 (00:00 +0900)]
[COMMON] android: ion: ion_test add ION_IOC_TEST_PHYS

ION_IOC_TEST_PHYS tests various aspects of the buffers from ION.

Change-Id: I67ac43837eca444ebd4c7b6e838b96532e6d3c9e
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years ago[COMMON] staging: android: ion_test: fix copying incorrect size to userspace
Cho KyongHo [Fri, 9 Jun 2017 13:53:47 +0000 (22:53 +0900)]
[COMMON] staging: android: ion_test: fix copying incorrect size to userspace

ion_test_ioctl() copies the data to userspace if ioctl command
includes read property. But it copies incorrect number of bytes
because 'data' in sizeof(data) is union of various length data
structures.

Change-Id: I3bcafa6823a38b8ce949f90086dbc9f4c5d3e8c3
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: revive ion-test device
Cho KyongHo [Tue, 6 Feb 2018 10:59:06 +0000 (19:59 +0900)]
android: ion: revive ion-test device

ion-test is the only tool for regression test for ION itself.
Let's restore ion-test device. The restored ion-test device is based
on the following commit:
'commit 4485842493fe ("Staging: android: ion: ion_test.c: fix
 parenthesis alignment")'

Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
Change-Id: I0dc3ee70656926e52c6d21afcc31a46215a3928b

6 years agoandroid: ion: kill system_contig heap
Cho KyongHo [Fri, 2 Feb 2018 13:56:04 +0000 (22:56 +0900)]
android: ion: kill system_contig heap

system_contig heap is very restrictive to be used by graphic/multimedia
use. Since it relies on the page allocator even for the large
physically contiguous buffers.
Let's kill system_contig heap to prevent users from confusion.

Change-Id: Id5bcca56d2139b95c706c5068d797f77904d4888
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: promote heap add priority
Cho KyongHo [Fri, 2 Feb 2018 14:01:10 +0000 (23:01 +0900)]
android: ion: promote heap add priority

Changed heap registration priority to subsys_initcall_sync() because
some drivers calls ion_alloc() in probe() that is called in
device_initcall() priority.

Change-Id: Ib1a06d147c75b0601c4807cea82dfcaca4cb526a
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years agoandroid: ion: add vmap/vunmap ops to dma-buf
Cho KyongHo [Fri, 2 Feb 2018 13:47:34 +0000 (22:47 +0900)]
android: ion: add vmap/vunmap ops to dma-buf

Kernel drivers that allocate buffers from ION sometimes requires
kernel address of the buffers. The drivers tend to access the whole
buffer instead of accessing several pages from the large buffers in
megabytes. Therefore dma_buf_vmap() is proper for the drivers than
dma_buf_kmap().

Change-Id: Ie5edf4c325a34c8ed419291b4490b917b755b551
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years ago[9610] arm64: configs: enable SysMMU
Janghyuck Kim [Fri, 11 May 2018 02:23:48 +0000 (11:23 +0900)]
[9610] arm64: configs: enable SysMMU

Change-Id: Icde7bb364dafb57cbbf128ff1052174020729cc9
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[9610] dtsi: fix TLB mask of sysmmu cam & isp0
Janghyuck Kim [Fri, 1 Dec 2017 06:52:08 +0000 (15:52 +0900)]
[9610] dtsi: fix TLB mask of sysmmu cam & isp0

Change-Id: I0f81a2ccc08c4ef9c3783895c6500bd85d180980
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[9610] dtsi: add no-rpm-control for sysmmu abox
Janghyuck Kim [Mon, 23 Oct 2017 11:49:11 +0000 (20:49 +0900)]
[9610] dtsi: add no-rpm-control for sysmmu abox

Change-Id: I0e0c293de0f49b93191af2eaa4d25594c3e383aa
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[9610] dtsi: add sysmmu properties
Janghyuck Kim [Mon, 25 Sep 2017 12:39:07 +0000 (21:39 +0900)]
[9610] dtsi: add sysmmu properties

Change-Id: Ie855f0baa5cfec54c5950203398d010be7613fdc
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[9610] dtsi: add no suspend property for abox sysmmu
Janghyuck Kim [Tue, 19 Sep 2017 11:54:19 +0000 (20:54 +0900)]
[9610] dtsi: add no suspend property for abox sysmmu

Change-Id: I8d8bc6f010e02561f624ac893ac663aea1a9389e
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[9610] arm64: dts: add System MMU device nodes to 9610
Cho KyongHo [Fri, 15 Sep 2017 11:14:16 +0000 (20:14 +0900)]
[9610] arm64: dts: add System MMU device nodes to 9610

Change-Id: I910fd34892a22d0c06407c17fe23b3f805a5fe6f
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu: fix detach_device() condition
Janghyuck Kim [Fri, 27 May 2016 01:14:35 +0000 (10:14 +0900)]
[COMMON] iommu: fix detach_device() condition

attach_device() was fixed not to care group condition. So
detach_device() should be changed as same condition.

Change-Id: I300cf0927588dba4d79502e7a5beb07b479396fd
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu: fix condition for exynos-iommu
Janghyuck Kim [Tue, 26 Apr 2016 05:03:18 +0000 (14:03 +0900)]
[COMMON] iommu: fix condition for exynos-iommu

Fix up condition of iommu framework to operate exynos-iommu.
exynos-iommu doesn't use dma-iommu for virtual address management.
And it doesn't need to care about group status in attach_device.

Change-Id: Ie9cbb7f2a4963fb279356d54be36c71b7ffd293d
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[HACK] iommu/exynos: fix compile error
Janghyuck Kim [Tue, 9 Jan 2018 04:23:45 +0000 (13:23 +0900)]
[HACK] iommu/exynos: fix compile error

Change-Id: Iff1e5c745b0065e7a2bff2c29f5dd3fffd69485e
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: fix prevent issue
Janghyuck Kim [Thu, 23 Nov 2017 08:10:50 +0000 (17:10 +0900)]
[COMMON] iommu/exynos: fix prevent issue

This patch fixed below prevent issue which are other violation types.

CID 201989,201988,201971,201965,201958,201937,201925,201912,200894

Change-Id: Ic43a796b3f159a8f6cd36756b5e7b42df97a1ec2
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: separate register access file
Janghyuck Kim [Fri, 21 Jul 2017 08:03:45 +0000 (17:03 +0900)]
[COMMON] iommu/exynos: separate register access file

H/W access codes are separated into exynos-iommu-reg.h.

Change-Id: Ifcb239ba84f2545ae9174adc531248843265e56f
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add sysmmu operation logging
Janghyuck Kim [Wed, 19 Jul 2017 09:58:40 +0000 (18:58 +0900)]
[COMMON] iommu/exynos: add sysmmu operation logging

Sysmmu operation logging is added that would be useful for unexpected
situation.

Change-Id: I3d8381cdb8eb1a80f9e52c685affa885c613a73e
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add slot property setting
Janghyuck Kim [Mon, 2 Jan 2017 11:41:27 +0000 (20:41 +0900)]
[COMMON] iommu/exynos: add slot property setting

This patch added parsing DT about slot properties, and parsed
information is used at the beginning of sysmmu.

Change-Id: I1148177911eff50ee71282c4bba508368b1a4a0b
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add TLB port setting
Janghyuck Kim [Tue, 8 Nov 2016 11:34:41 +0000 (20:34 +0900)]
[COMMON] iommu/exynos: add TLB port setting

To support TLB port setting, parsing device tree and setting code are
added.

Change-Id: I63f5854d4d23f2aabb4fe9a4a68a35b8902ab6fd
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add TLB match type flags
Janghyuck Kim [Mon, 31 Oct 2016 08:03:09 +0000 (17:03 +0900)]
[COMMON] iommu/exynos: add TLB match type flags

TLB match type can be different by the supported version.
This patch reads supported feature from H/W, and calls handling function
for each type.

Change-Id: Id674fa9687c4a3839c2dcfa04061c2c8386a4c34
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: remove __initconst for sysmmu_of_match table
Janghyuck Kim [Wed, 22 Feb 2017 07:24:21 +0000 (16:24 +0900)]
[COMMON] iommu/exynos: remove __initconst for sysmmu_of_match table

KASAN reported use-after-free case like below.
To avoid this case, __instconst is removed.

BUG: KASAN: use-after-free in __of_match_node+0xb0/0x104 at addr
ffffffc002653338
Read of size 1 by task kworker/u16:0/6
page:ffffffbdc00994c0 count:0 mapcount:0 mapping:          (null)
index:0x1
flags: 0x0()
page dumped because: kasan: bad access detected

.. < skip > ..

Workqueue: deferwq deferred_probe_work_func
Call trace:
[<ffffffc0000e7140>] dump_backtrace+0x0/0x21c
[<ffffffc0000e7370>] show_stack+0x14/0x1c
[<ffffffc0007a4dc8>] dump_stack+0xa8/0xe8
[<ffffffc000393e04>] kasan_report+0x468/0x484
[<ffffffc000393e38>] __asan_report_load1_noabort+0x18/0x20
[<ffffffc00125f65c>] __of_match_node+0xb0/0x104
[<ffffffc00125f6e8>] of_match_node+0x38/0x5c
[<ffffffc00125ff3c>] of_match_device+0x50/0x5c
[<ffffffc000b0fa5c>] platform_match+0x9c/0x1c4
[<ffffffc000b0be84>] __device_attach_driver+0x100/0x180
[<ffffffc000b08bb0>] bus_for_each_drv+0x15c/0x164
[<ffffffc000b0b584>] __device_attach+0x198/0x208
[<ffffffc000b0c180>] device_initial_probe+0x10/0x18
[<ffffffc000b09020>] bus_probe_device+0x98/0x190
[<ffffffc000b0ac78>] deferred_probe_work_func+0xd4/0xec
[<ffffffc000145428>] process_one_work+0x978/0x1208
[<ffffffc00014636c>] worker_thread+0x654/0x824
[<ffffffc0001524fc>] kthread+0x240/0x250
[<ffffffc0000dde30>] ret_from_fork+0x10/0x20
Memory state around the buggy address:

Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
Change-Id: Ibc46808a38b0db3f9cc62a1e106022fa9383dd20

6 years ago[COMMON] iommu/exynos: display sysmmu name when fault occurred
Janghyuck Kim [Wed, 1 Feb 2017 08:24:20 +0000 (17:24 +0900)]
[COMMON] iommu/exynos: display sysmmu name when fault occurred

In case of sysmmu page fault, it was difficult to distinguish the owner
of invalid request. This patch displays sysmmu name to improve
readability.

Change-Id: I2a11a503c4ad64eaa819e8f76640c3dffc999d00
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: alloc page table entry with gfp mask
Janghyuck Kim [Sat, 7 Jan 2017 05:53:35 +0000 (14:53 +0900)]
[COMMON] iommu/exynos: alloc page table entry with gfp mask

Page table entry can be allocated with GFP_KERNEL if mapping request is
passed by iommu_map(), because it is outside of spinlock boundary.

Change-Id: I59fc5666597ee41f060bccfe91772c603acf9a12
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: force non-shareable for non-cached buffers
Cho KyongHo [Wed, 4 Jan 2017 08:23:19 +0000 (17:23 +0900)]
[COMMON] iommu/exynos: force non-shareable for non-cached buffers

exynos_iovmm_map_userptr() migrates the given userspace mapping to the
device virtual address space. If the given mapping is uncached or
writecombine, cache lines that are allocated to some part of the given
range can be stale. Therefore the mapping is not cached, the mapping
to the System MMU page table should also be non-shareable.

Change-Id: I748ae92525c916d580cb55f9deeb9c43f03a6386
Signe-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years ago[COMMON] iommu/exynos: fix possible NULL pointer dereference
Cho KyongHo [Thu, 5 Jan 2017 13:59:33 +0000 (22:59 +0900)]
[COMMON] iommu/exynos: fix possible NULL pointer dereference

find_vma() may return NULL. It should be checked even though
exynos_iovmm_map_userptr() requires the callers to acquire mmap_sem.

SVACE WGID 87553

Change-Id: Ice3239234dc46177bce5963444f0c4cbc094fe40
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
6 years ago[COMMON] iommu/exynos: implement API to show status
Janghyuck Kim [Thu, 8 Dec 2016 02:23:31 +0000 (11:23 +0900)]
[COMMON] iommu/exynos: implement API to show status

exynos_sysmmu_show_status() provides information of sysmmu status.

Change-Id: Ia448f085acd3b7d605941481f7799899940420f3
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: support no-suspend feature
Janghyuck Kim [Tue, 25 Oct 2016 10:29:53 +0000 (19:29 +0900)]
[COMMON] iommu/exynos: support no-suspend feature

This patch supports no-suspend mode that not to disable sysmmu when it
is going to suspend state. It is necessary for the master driver like
abox that should operate in suspend mode.

Change-Id: I1ff1ccd83997f3852d5b962767c43bc0d6cd6819
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: check condition before pointer access
Janghyuck Kim [Mon, 5 Sep 2016 03:21:20 +0000 (12:21 +0900)]
[COMMON] iommu/exynos: check condition before pointer access

Fix Svace : 64214, 64219

Change-Id: I5ab4d2e84d4a510693978b6aac97ebf8c037119e
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add shareablity setting in iommu_map
Janghyuck Kim [Thu, 11 Aug 2016 04:23:33 +0000 (13:23 +0900)]
[COMMON] iommu/exynos: add shareablity setting in iommu_map

Current exynos iommu driver supports shareability setting by userptr
case only, and prot was ignored in case of iommu_map().
This patch enables shareability setting for iommu_map().

Change-Id: I5431a029746b5d9b89ceb8d4b0a6b2190e8d43e6
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: support secure sysmmu interrupt
Janghyuck Kim [Sat, 6 Aug 2016 07:20:47 +0000 (16:20 +0900)]
[COMMON] iommu/exynos: support secure sysmmu interrupt

Abnormal situation like page fault can be happened when sysmmu is
operating in secure context. To ease debugging with maintaining secure
state, secure interrupt handler is added. In this handler, useful
information of sysmmu status can be obtained through exynos_smc().

Change-Id: I066f70f655e41eda9ba5d7f2d8dd83f1cea94176
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: fix overflow check condition
Janghyuck Kim [Thu, 7 Jul 2016 14:01:16 +0000 (23:01 +0900)]
[COMMON] iommu/exynos: fix overflow check condition

Considering 32bit dma address, overflow checking condition is fixed.

Change-Id: I98066be8a219f9a26e076b2f64285455f48d057d
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] include: add definition for prefetch read/write
Janghyuck Kim [Mon, 1 May 2017 08:28:04 +0000 (17:28 +0900)]
[COMMON] include: add definition for prefetch read/write

Change-Id: Ibac9935d7ed568bcc62845643e7fb00af003f926
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] include: add definition for TLB port setting
Janghyuck Kim [Tue, 8 Nov 2016 11:33:51 +0000 (20:33 +0900)]
[COMMON] include: add definition for TLB port setting

Change-Id: I49560e481edc20b8134861f9314cbda19cb48925
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: parsing DT for sysmmu properties
Janghyuck Kim [Mon, 16 May 2016 12:19:54 +0000 (21:19 +0900)]
[COMMON] iommu/exynos: parsing DT for sysmmu properties

Sysmmu properties that read from DT are parsed and stored into driver
data.

1) QoS property is defined like below in DT.
sysmmu_node:
qos = <4>;

2) TLB properties are defined like below in DT.
sysmmu_node:
sysmmu,tlb_property =
<PRIV_WAY_CFG ID SYSMMU_ID(X)>,
<PRIV_WAY_CFG ID SYSMMU_ID(X)>,
<PUBLIC_WAY_CFG SYSMMU_NOID>;
Refer to include/dt-bindings/sysmmu/sysmmu.h for detailed definitions.

Change-Id: Ibdca6081351e997ba3a01f0173c751d30bb69a1d
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add dma-window property parsing
Janghyuck Kim [Wed, 11 May 2016 02:25:18 +0000 (11:25 +0900)]
[COMMON] iommu/exynos: add dma-window property parsing

Each domain may need different dma ranges for client device's
requirement. 'dma-window' property specifies dma ranges
for each domain.

This property is optional, so if it doesn't exist,
default dma ranges from 0x10000000 to 0xD0000000 are used.

If this property is used, address and size cells should be described.
Below is an example.

iommu-domain_something {
compatible = "samsung,exynos-iommu-bus";

#dma-address-cells = <1>;
#dma-size-cells = <1>;
/* start address, size */
dma-window = <0x10000000 0xC0000000>;

domain-clients = <&something>;
};

Change-Id: I2765f8a4a6b142475c5de80aa73234bef0bd3248
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add dump of TLB status
Janghyuck Kim [Thu, 16 Jun 2016 08:12:46 +0000 (17:12 +0900)]
[COMMON] iommu/exynos: add dump of TLB status

Dumping TLB status and TLB set/way information are added to provide
useful information in sysmmu status dumping

Change-Id: I37bfdfbd1baa2c6f10275c93f3d43b055ad0b6e7
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: support fault handler for v7
Janghyuck Kim [Wed, 1 Jun 2016 05:10:39 +0000 (14:10 +0900)]
[COMMON] iommu/exynos: support fault handler for v7

Reading interrupt status and displaying information are changed to
support sysmmu v7.

Change-Id: I29acc8fd8427933a58a2330526f74f283a0d2d01
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: fix return value in attach_dev
Janghyuck Kim [Wed, 1 Jun 2016 05:13:13 +0000 (14:13 +0900)]
[COMMON] iommu/exynos: fix return value in attach_dev

IOMMU framework considers error if attach_dev returns non-zero value.
If sysmmu is already enabled by other master device, return value can be
one, which means already enabled. It is normal situation, so return
value is changed to zero in this case.

Change-Id: I4a344cedc2d3729de3b46c9c1cf0f6e44072d2a5
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] exynos/iommu: add suspended state
Janghyuck Kim [Fri, 27 May 2016 01:23:56 +0000 (10:23 +0900)]
[COMMON] exynos/iommu: add suspended state

This patch added suspended state that becomes true when sysmmu goes to
suspend state. No SFR access is allowed if sysmmu is in suspended.

Without suspended state, some operation involving SFR access like tlb
invalidation would make external abort because it only checks internal
reference count before SFR access, and internal reference count is
remained after sysmmu becomes suspend state.

Change-Id: I7460e8b0b96de5f46584cc299dc2e659fc34da44
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add fault handler API
Janghyuck Kim [Mon, 9 May 2016 06:16:24 +0000 (15:16 +0900)]
[COMMON] iommu/exynos: add fault handler API

By fault handler API, master driver can register their own fault handler
that would be called when related sysmmu fault occurred.
In fault handler, master driver can print out their useful information
like SFR for debugging.

Change-Id: Ica6b7df8108d3165a7e1a3632aba027f328d1ecf
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add iova_to_phys
Janghyuck Kim [Sat, 7 May 2016 06:45:32 +0000 (15:45 +0900)]
[COMMON] iommu/exynos: add iova_to_phys

iova_to_phys() is implemented to return physical address from iova.

Change-Id: I0e0d0f91231889efadb10a18b1e07d60b01ce1dc
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: remove rpm-enabled check in suspend/resume
Janghyuck Kim [Thu, 19 May 2016 11:22:08 +0000 (20:22 +0900)]
[COMMON] iommu/exynos: remove rpm-enabled check in suspend/resume

After removing CONFIG_PM_RUNTIME, pm_runtime_enabled() always returns
zero because sysmmu driver calls pm_runtime_enable() at probe time.
It results SFR access in suspend/resume callback even though power block
is off. To avoid SFR access, condition checking by pm_runtime_enabled()
is removed by this patch.

Change-Id: I2afea1ad4b3bdc57cb50d71423e44358b3023696
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add userptr map/unmap
Janghyuck Kim [Tue, 3 May 2016 11:52:34 +0000 (20:52 +0900)]
[COMMON] iommu/exynos: add userptr map/unmap

user virtual address mapping/unmapping should be supported.

Change-Id: Iff0398588a1d295d86ea9285303a558453f0baba
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add sysmmu irq handler
Janghyuck Kim [Tue, 3 May 2016 11:55:58 +0000 (20:55 +0900)]
[COMMON] iommu/exynos: add sysmmu irq handler

Sysmmu interrupt occurred when sysmmu detected illegal request.
Sysmu irq handler displays detected fault type and related information.

Change-Id: Ie12909182f722f85480a285fc05573ad5af7759a
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add cache sync operation
Janghyuck Kim [Thu, 28 Apr 2016 06:49:40 +0000 (15:49 +0900)]
[COMMON] iommu/exynos: add cache sync operation

Cache sync operation for device and cpu is added.

Change-Id: I6167a51997d50978e1bc22bbe2c1c33a18cf0666
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add temporal function for master driver
Janghyuck Kim [Tue, 26 Apr 2016 07:09:29 +0000 (16:09 +0900)]
[COMMON] iommu/exynos: add temporal function for master driver

Frequently used function for master driver is added temporally to avoid
compile error.

Change-Id: Ieb3986467e9fadcc77aee01f40bb5e9e7d7c04c8
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add iommu group for each domain
Janghyuck Kim [Tue, 26 Apr 2016 05:00:47 +0000 (14:00 +0900)]
[COMMON] iommu/exynos: add iommu group for each domain

iommu group is not important for exynos iommu driver, however, without
iommu group, getting domain from master device is failed.
This patch added one to one relationship for iommu group and domain.

Change-Id: Ia31bd028226e228c14091cd8ec5ee0412155228d
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add suspend/resume callback
Janghyuck Kim [Mon, 25 Apr 2016 09:30:17 +0000 (18:30 +0900)]
[COMMON] iommu/exynos: add suspend/resume callback

To support suspend and resume of APM, suspend and resume callback is
added to disable and enable sysmmu properly.

Change-Id: Ie2cf804b50219c1c820de794fe2e6aad68ae3d94
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: runtime suspend/resume callback
Janghyuck Kim [Mon, 25 Apr 2016 09:27:20 +0000 (18:27 +0900)]
[COMMON] iommu/exynos: runtime suspend/resume callback

Sysmmu operation is implicitly enabled and disabled when master device
turned on the power and off the power.

This patch replaces runtime pm suspend/resume callback of platform bus
with exynos_iommu_runtime_suspend/resume that added sysmmu handling.

Change-Id: I5e5e1f5fb485a9943c84c0e6a379b8720de57094
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add tlb invalidation
Janghyuck Kim [Mon, 25 Apr 2016 05:20:05 +0000 (14:20 +0900)]
[COMMON] iommu/exynos: add tlb invalidation

TLB invalidation is mandatory when page table entry is added or removed.
Without this, sysmmu might translate wrong address results.

Change-Id: I3fe24d211256b8f503d1fbabc78dc3f6790faf4e
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add map/unmap
Janghyuck Kim [Mon, 25 Apr 2016 02:28:06 +0000 (11:28 +0900)]
[COMMON] iommu/exynos: add map/unmap

mapping makes page table entry to translate virtual address to physical
address. unmapping removes page table entry.

Change-Id: I82c053b40868deba948c60affd96074661987f15
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add sysmmu enable/disable
Janghyuck Kim [Sat, 23 Apr 2016 10:26:37 +0000 (19:26 +0900)]
[COMMON] iommu/exynos: add sysmmu enable/disable

Sysmmu checks activation status and runtime activation by master
driver to control properly.
At enabling time, sysmmu configuration and page table are set.
At disabling time, sysmmu is blocked and disabled.

Change-Id: Ia8cfee103bdb259d295c18edb7d3b033f85c2662
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add attach/detach device
Janghyuck Kim [Sat, 23 Apr 2016 07:51:50 +0000 (16:51 +0900)]
[COMMON] iommu/exynos: add attach/detach device

Client device is attached to domain by attach_device.
It enables sysmmu for all clients that attached to domain.
Client device is detached from domain by detach_device.
All enabled sysmmus for clients are disabled.

Change-Id: Ib261369344516ee034a3fae0498137f983ca5bd6
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add domain alloc/free
Janghyuck Kim [Sat, 23 Apr 2016 07:00:10 +0000 (16:00 +0900)]
[COMMON] iommu/exynos: add domain alloc/free

iommu domain represents virtual address spaces for client device.
domain_alloc creates page table for each domain and initialize domain
related data structures.
domain_free cleans up attached client list and releases domain related
information.

Change-Id: I61d6621c5598be459e963ecdb58711fc76d083ed
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: of_xlate for master and sysmmu
Janghyuck Kim [Fri, 22 Apr 2016 11:13:54 +0000 (20:13 +0900)]
[COMMON] iommu/exynos: of_xlate for master and sysmmu

of_xlate is called when master device is added.
Purpose of of_xlate is making relationship between master and sysmmu
devices. Domain and client relationship is also created at this time.

Change-Id: I4b7f5a2d9d1237b61beee1a6f216ef39c60df722
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add probe function
Janghyuck Kim [Fri, 22 Apr 2016 12:03:30 +0000 (21:03 +0900)]
[COMMON] iommu/exynos: add probe function

resources like SFR and IRQ are registered and main structure for sysmmu
is created in probe function.

Change-Id: I3266acf9b97bea4395804a5bf1f814c7b0f4815f
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: creating iommu domain
Janghyuck Kim [Fri, 22 Apr 2016 06:13:15 +0000 (15:13 +0900)]
[COMMON] iommu/exynos: creating iommu domain

iommu domain is created at booting time and it parses device tree with
"samsung,exynos-iommu-bus" to clarify relationship between domain and
client devices. At this time, client device is not added yet, so parsed
informations are stored into exynos_client_list for later.

Change-Id: I7928fbdf0898fef2b9e9004e3b45c3520c2c1c18
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: enable IOVMM
Janghyuck Kim [Fri, 22 Apr 2016 05:21:02 +0000 (14:21 +0900)]
[COMMON] iommu/exynos: enable IOVMM

IOVMM is Exynos I/O Virtual Memory Manager.
It manages device virtual address region like allocation and free.
IOVMM is connected with exynos iommu domain.

Some dummy function is added in exynos-iommu to avoid compilie error.

Change-Id: Icdd0fe1acc81240b97361ae495276d920c129ad9
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add initialization
Janghyuck Kim [Thu, 21 Apr 2016 10:19:53 +0000 (19:19 +0900)]
[COMMON] iommu/exynos: add initialization

This is the starting point for exynos iommu driver.
It registers sysmmu driver and iommu api to platform_bus_type.

Change-Id: Iae165ce448ab4334ca956c5c2aaaa6bbe4997d7a
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>
6 years ago[COMMON] iommu/exynos: add skeleton exynos iommu driver
Janghyuck Kim [Tue, 19 Apr 2016 05:28:16 +0000 (14:28 +0900)]
[COMMON] iommu/exynos: add skeleton exynos iommu driver

Basic structures for domain, master and sysmmu are defined.
Skeleton functions of iommu_ops are added.

Change-Id: I501f6a82357a1e37e3d14bbb0f2c7ad4c516090f
Signed-off-by: Janghyuck Kim <janghyuck.kim@samsung.com>