Commit Graph

43 Commits

Author SHA1 Message Date
Olav Haugan
eeab21e633 gpu: ion: Add dump of memory map
Add dump of physical memory map, showing allocated and
free areas, to debugfs interface for heaps with carveout memory.

Change-Id: I9bda9f3e555e55570c95e652616ca1fcc25eb0ab
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:44:15 -08:00
Olav Haugan
4f3cadaf47 gpu: ion: Add lock around debug routine
Access to rb tree of user and kernel ION clients
must be protected by a mutex.

Change-Id: Ie27eba65f8cab3a7c20c041eb46429ba62c5c00f
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:44:15 -08:00
Olav Haugan
772ffb6355 gpu: ion: Add more debug info to client debugfs IF
Add logging of buffer physical address (if allocation
is from physically contiguous heap) and iommu mapping
information to the ion client debug interface.

Change-Id: Id3a77c1b5e3c5d15b11b3612f07d10092922cdff
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:44:13 -08:00
Olav Haugan
87d9a20aa2 gpu: ion: Check for null name argument
Add check for null argument to avoid dereferencing
a null-pointer.

Change-Id: Icb452d0764e375bf2684e013c51d260de98e8583
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:44:13 -08:00
Olav Haugan
8876e13360 gpu: ion: IOCTL return success when error occurs
ION_IOC_MAP, ION_IOC_SHARE, and ION_IOC_IMPORT may return
success when an error occurs.

Add correct error handling to ION_IOC_MAP, ION_IOC_SHARE, and
ION_IOC_IMPORT.

Change-Id: Idb7e58c94dab53fd82dd49150af9eaec78430c40
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:44:12 -08:00
Olav Haugan
14a31da90d gpu: ion: Ensure ioctl return correct error codes
Under certain error conditions the following ION ioctl's would return
success even when the operation failed:

-ION_IOC_CLEAN_CACHES
-ION_IOC_INV_CACHES
-ION_IOC_CLEAN_INV_CACHES

Add return of correct error codes when an error occurs.

Change-Id: Ie8824bfecbb423c23d32c6a3d7058f06d8322906
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:44:11 -08:00
Olav Haugan
6147670108 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>
2013-02-07 17:44:09 -08:00
Olav Haugan
e65d394b58 gpu: ion: Add missing argument to WARN call
The condition argument to the WARN call in ion_free is missing. Add the
argument to allow correct printing of warning message.

Change-Id: I158e1a583b7242b2c3209d6ce64dc0b771efeffe
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:44:06 -08:00
Olav Haugan
be9ab94f9f gpu: ion: Delay unmapping from IOMMU.
Due to limitations in the multimedia architecure
clients might not know when a buffer can be unmapped
from the IOMMU. In addition, the multimedia architecture
causes unnecessary mappings/unmappings for the same buffers
which reduces framerates.

Add logic to delay unmapping from the IOMMU
until buffer memory is freed and unmap any outstanding
mappings to avoid virtual memory address space leak.

Change-Id: Idaeae269d9ba623e25a0cb087a89b4cbb63915af
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:44:02 -08:00
Olav Haugan
9c3801b1e3 gpu: ion: Add API to do cache operations
Clients need to be able to do cache operations
on ION buffers in the kernel. Add API to
flush, invalidate, or invalidate and flush the
cache of an ION buffer.

Change-Id: I2b676dbe32372b3c17e4aaf39f51878b105a699c
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:43:59 -08:00
Olav Haugan
b6ecf576cd gpu: ion: Do not allow cached IOMMU mappings.
Cached IOMMU mapping is not supported.

Add check for clients trying to map buffers
into IOMMU as cached and return error.

Change-Id: Ic63a24bf651d613933633cd81143701f66df566c
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:43:58 -08:00
Laura Abbott
74e13249b9 gpu: ion: Fix race condition with import
Consider two threads. Thread 1 has an fd linked to an ion buffer
and Thread 2 has a handle to the same buffer. The two came from
the same client

Thread 1                    Thread 2
-----------------------------------------
ion_import_fd
ion_import
mutex_lock(&client->lock)
                            ion_free
                            ion_handle_put
                            ion_handle_destroy
                            mutex_lock(&client->lock) <--- currently locked
ion_handle_lookup
<return reference to same handle>
mutex_unlock(&client->lock)
                            acquire client lock
                            free(handle)

Thread 1 is now holding a reference to an already freed handle.
The issue arises because thread 2 is attempting to destroy the
handle but the handle still exists on the clients list of handles.
This needs to be atomic. Fix this by taking the client lock
around ion_handle_put.

CRs-Fixed: 328348
Change-Id: I3ff5e6c50b5268fd42092bc1f2b99403e5fcd3cd
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:52 -08:00
Olav Haugan
9938af95ab gpu: ion: Limit scope of local functions
Several functions that should not be used outside of
the ion.c file does not have static keyword. In
addition two of the functions should not be exported.

Add static keyword to functions that are local to the
translation unit and remove EXPORT_SYMBOL declarations
that are not needed.

Change-Id: Ia1ef54e3670d361c9a6d684f789be2129facb04d
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:43:51 -08:00
Olav Haugan
d4c5c5d2fc gpu: ion: Add EXPORT_SYMBOL to functions
Several functions in the ion interface is missing
EXPORT_SYMBOL. This is needed to allow clients to
use these functions from kernel modules.

Add EXPORT_SYMBOL to functions that are supposed
to be exposed.

Change-Id: Ieb2810d85205a7492b8fe28536fb20ea090e830f
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:43:50 -08:00
Olav Haugan
bae1129b0c gpu: ion: Replace strncpy with strlcpy
strncpy is unsafe because it does not guarantee
that the resultant string is NULL-terminated.

Replace strncpy with strlcpy and remove explicit
NULL-termination. Also correct allocation of
string buffer.

Change-Id: Id5075ef7b04f80e2bf828f52def329b926e9ec3f
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:43:50 -08:00
Olav Haugan
46533157db gpu: ion: Refactor debugfs printing
Printing to debugfs is done from a centralized location for
all the heaps managed by ion. This architecture is not
sustainable in the long run since different heaps have different
requirements for what should be printed.

Refactor the debugfs printing for ion so that each heap is
responsible for printing its information.

Change-Id: I1dbe13432a4ab07f27ea4756c3be7fa01ad1df92
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:43:49 -08:00
Olav Haugan
0a0df35f5b gpu: ion: Add error message when allocation fails
Add error message when allocation from ion fails.

Change-Id: If2efa95c563c9f076b85958a70ea66afa3983325
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:43:48 -08:00
Olav Haugan
167e3462da gpu: ion: Fix ion client name allocation
The ion client name used for debugging were being
allocated on the stack for user space clients. This
causes the name to be garbled when later printed.

Instead, allocate the name from the heap.

Change-Id: Id299d224192f127197bef2eeb22d881b3a31795c
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:43:47 -08:00
Olav Haugan
900908129a gpu: ion: Add more debug info
Add more debug information to ion_debug_heap_show:
-Get number of allocations from heap
-Get number of user space mappings.
-Get number of kernel space mappings.
-Get indicator whether heaps has been secured or not.

Change-Id: I05491b3dd8caccfc3bbe5a9e55642e5e2cd431c4
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-02-07 17:43:44 -08:00
Olav Haugan
b6a020a45b gpu: ion: Add support for secure buffers
Secure buffers provides a way to allow premium encrypted
multimedia content to be decrypted in a secured
memory area that does not allow for interception of the
decrypted content.

Add support for heap type that allow heap to be
used for content protection. Introduce new content
protection heap type and id's.

Change-Id: Idd56aa8805b5b74d1b9ab3fe8964aacc218668c1
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
[sboyd: drop board file and scm.h changes]
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
2013-02-07 17:43:43 -08:00
Laura Abbott
3f40f8db92 gpu: ion: Fix debugfs handling of multiple kernel clients
Currently, Ion registers all debugfs entries for clients
via pid. If there are multiple kernel clients, this means
the debugfs entry only gets created for the first one. Fix
this by creating debugfs entries by name always. When
creating user clients, specify the name via the pid.

Change-Id: I00cbb284d1c53b3362bb7be9c0275620a9fac167
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:40 -08:00
Laura Abbott
2d5e460bb6 gpu: ion: Add call back for unmapping user mappings
When mmap is called to remove a mapping, the mmap code
takes care of removing all the entries so it isn't
necessary to call unmap versions. However, there may be
cases where heaps need to do other buffer clean up when
a userspace buffer is unmapped. Add an unmap_user function
to the ion heap ops. This callback needs to happen in
vma_close, so move the decrementing of the overall user map
call back as well.

Change-Id: I8e5716774dd973828f76e03ec43e8e8ecf8c7936
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:39 -08:00
Laura Abbott
0a06f5ac59 gpu: ion: Add support for iommus
Add infrastructure to support mapping allocations
into iommus.

Change-Id: Ia5eafebee408e297013bf55284abf67d9eb8d78b
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
[sboyd: drop board file changes]
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
2013-02-07 17:43:39 -08:00
Laura Abbott
5769ad8032 gpu: ion: Add support for flushing via fd
Userspace clients pass fds around, not handles. Support flushing
via fd.

Change-Id: Ic22d9327e9fa72cb604c3010a2a6f798be8dfdb1
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:36 -08:00
Laura Abbott
878705f82d gpu: ion: Prevent deadlock with cache flushing
Cache flushing takes the mmap semaphore to validate the
address range. This can cause a deadlock in the following
scenario with two threads in the same client:

Thread 1			Thread 2
(cache operation)		(mmap)
-----------------------------------------
lock(client_lock)
				down_write(mmap_semaphore)
down_read(mmap_semaphore)
				lock(client_lock)

Fix this by doing the check for the address range before
taking the client lock. This is independent of Ion so there
is no need to have this lock locked.

Change-Id: Ibe372cf232fbad7e031ab2d38cf3a34823f43bf9
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:36 -08:00
Laura Abbott
c1cc4dbfdf gpu: ion: Add scan for leaked userspace fds
The ION_IOC_MAP/ION_IOC_SHARE ioctls take a reference to
an ion buffer. If the fd generated by the ioctl is never
closed, the buffer will never be freed. This is a pain to
track down in userspace. Add a debugfs entry to do a scan
of all the buffers and check which ones have no handle
associated with them. If a buffer has no handle associated
with it, that means the last reference is an fd. There
isn't a good way to directly associate an fd with a buffer,
but this can at least be a starting point for tracking down
leaks.

Change-Id: I64eedd6a30d8298b2aa75532c7fad506542910f6
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:31 -08:00
Laura Abbott
e9bda2ef0e gpu: ion: Print debug information in hex
For consistency sake, print out debug information in hex.

Change-Id: Iccf27eca1b994bff547c812387ed756a07e9cd7b
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:31 -08:00
Laura Abbott
0552ef6bd3 gpu: ion: Add debug information for individual heaps
Currently, the debugfs information provides aggregated data
for all carveout heaps. This isn't particularly helpful for
determining allocation problems with individual carveout heaps.
Fix this to give data for individual carveout heaps.

Change-Id: I60a10851052412e20c40f1862d6dcc22093fd982
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:30 -08:00
Laura Abbott
323102293b gpu: ion: Add API to get the buffer flags
Clients may want to know what the existing flags are on a
handle for mapping, cache flushing or other purposes. Add
an API to get those flags.

Change-Id: I2d8c93194d1fc940042529b8851ebecf35d6e3de
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:27 -08:00
Laura Abbott
d302d3e849 gpu: ion: Add better debugfs information
In debugfs, clients now show individual allocations.
Carveout heaps now give the number of bytes currently
allocated out of total possible bytes. The system heaps
just show the number of bytes currently allocated.

Change-Id: I4acfcdc1089c73c28041e09cb6b5a03b956e936a
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:26 -08:00
Laura Abbott
18593f5f2e gpu: ion: Do the cache op when the buffer is cached
Only do the cache operation when the buffer is cached.
If the buffer is uncached, just return. Fixes a bug
where the cache was only being flushed when the buffer
was uncached instead of cached.

Change-Id: Ib1fa01168de79d5627b11d07c5313d19b3049145
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:26 -08:00
Laura Abbott
767d0d5934 gpu: ion: Add cache flushing APIs
Add ioctl to support flushing the caches of ion
buffers from userspace.

Change-Id: I60f1daf0eef09e1307242bb3fd0ce4aef374a111
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:23 -08:00
Laura Abbott
1d94d6cd3f gpu: ion: Add support for cached and uncached mappings
Add explicit support for cached and uncached mappings. Functions
now describe whether mappings will be cached or uncached.

Change-Id: I3f0540c0486b134d7bc610480a3f72350337e5b1
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:21 -08:00
Stephen Boyd
a505cfb76e ion: mysterious movement of two assignments
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
2013-02-07 17:43:15 -08:00
Laura Abbott
c08951f5f5 gpu: ion: Loop on the handle count when destroying
When destroying a handle, all kernel mappings to that handle
should be destroyed. Other handles may still have references
and valid mappings to the buffer underneath which should not
be destroyed. Loop on the handle reference count, not the buffer
reference count to get rid of all kernel mappings for the handle.

Change-Id: I7dc5d6a86513fc5fa4e21110ceab434714ea2493
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-02-07 17:43:14 -08:00
Rebecca Schultz Zavin
903f6c716d gpu: ion: Get an sg_table from an ion handle
This patch adds an interface to return and sg_table given a
valid ion handle.

Change-Id: Icd948c60c1af0a4279f337bcd591cd39b46325e8
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2012-05-23 13:20:25 -07:00
Rebecca Schultz Zavin
46d71337f9 gpu: ion: Allocate the sg_table at creation time rather than dynamically
Rather than calling map_dma on the allocations dynamically, this patch
switches to creating the sg_table at the time the buffer is created.
This is necessary because in future updates the sg_table will be used
for cache maintenance.

Change-Id: I49aac7c6d3a5afc440d18b917ae0e73be5d3f56d
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2012-05-22 14:01:07 -07:00
Rebecca Schultz Zavin
be4a1ee79a gpu: ion: support begin/end and kmap/kunmap dma_buf ops
These ops were added in the 3.4 kernel.  This patch adds support
for them to ion.  Previous ion_map/unmap_kernel api is also
retained in addition to this new api.

Change-Id: I6d2db284dce12c2d8cc4e540865beee2da43bd0c
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2012-05-22 14:01:07 -07:00
Rebecca Schultz Zavin
043a61468f ion: Switch ion to use dma-buf
Ion now uses dma-buf file descriptors to share
buffers with userspace.  Ion becomes a dma-buf
exporter and any driver that can import dma-bufs
can now import ion file descriptors.

Change-Id: Ia04d6d72fb301dc088eb8db6576822e9260ff332
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2012-05-22 14:01:06 -07:00
KyongHo Cho
9ae7e01de1 gpu: ion: several bugfixes and enhancements of ION
1. Verifying if the size of memory allocation in ion_alloc() is aligned
by PAGE_SIZE at least. If it is not, this change makes the size to be
aligned by PAGE_SIZE.

2. Unmaps all mappings to the kernel and DMA address spaces when
destroying ion_buffer in ion_buffer_destroy(). This prevents leaks in
those virtual address spaces.

3. Makes the return value of ion_alloc() to be explicit Linux error code
when it fails to allocate a buffer.

4. Makes ion_alloc() implementation simpler. Removes 'goto' statement and
relavant call to ion_buffer_put().

5. Checks if the task is valid before calling put_task_struct() due
to failure on creating a ion client in ion_client_create().

6. Returns error when buffer allocation requested by userspace is failed.

Change-Id: I4fa9859f4a0b665fcb44e5c0da43c569732e93ae
Signed-off-by: KyongHo Cho <pullip.cho@samsung.com>
2012-05-22 14:01:05 -07:00
Rebecca Schultz Zavin
6f9e56945d ion: Add reserve function to ion
Rather than requiring each platform call memblock_remove or reserve
from the board file, add this to ion

Change-Id: Ie418a692c13e9e0cfe93ecc83d253d3ce860fc83
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2012-05-22 14:01:05 -07:00
Rebecca Schultz Zavin
7191e9ba25 ion: Switch map/unmap dma api to sg_tables
Switch these api's from scatterlists to sg_tables

Change-Id: I8b99e39633df009d472ce24704fa26af7bb50fa2
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2012-05-22 14:01:05 -07:00
Rebecca Schultz Zavin
0c38bfd0ed gpu: ion: Add ION Memory Manager
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2012-04-09 13:57:56 -07:00