Commit Graph

78 Commits

Author SHA1 Message Date
Olav Haugan
16cdb41acb gpu: ion: Map a range into the IOMMU
Instead of mapping 1 4K page at a time into the IOMMU create a
scatterlist and map everything at once. This will be more efficient.

Change-Id: I8e83066869dd6f7a479bad22a66e4c70cc5973b5
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-03-29 17:02:06 -07:00
Jeremy Gebben
d01042d080 gpu: ion: set dma_address for contiguous heaps in ion_map_dma()
Ion carveout and content protect heap buffers do not
have a struct page associated with them. Thus
sg_phys() will not work reliably on these buffers,
so set dma_address on their scatterlists.

CRs-Fixed: 345257
Change-Id: Ifdad5ce497de170f47b4ee2f7a93563a5cbe1a96
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
2012-03-25 13:39:39 -07:00
Olav Haugan
b36765960a 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>
2012-03-09 09:49:47 -08:00
Olav Haugan
ab804b883a gpu: ion: Add map_dma support in IOMMU heap
IOMMU is missing support for ion_map_dma.
ION clients need support for this api.

Add functions to implement ion_map_dma and
ion_unmap_dma in the IOMMU heap.

Change-Id: If5723f0d7ec1145e9c9d8b88a42b57ab0f2c2da7
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-03-09 09:49:28 -08:00
Olav Haugan
ef0107124e gpu: ion: Add cache operations to IOMMU heap
The IOMMU heap must support cache operations so that clients
can do cached allocations from the heap.

Add function to perform cache operations on memory
allocated from IOMMU heap.

Change-Id: I49a84dca613b7c209dde03b67b2fc1b2c9d844dd
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-03-09 09:49:22 -08:00
Olav Haugan
dbec7db15d gpu: ion: Allow smaller mappings
Clients using ION must be able to mmap a smaller
set of pages than what was allocated from the
IOMMU heap.

Add check that we don't try to map a page passed
the end of the vma.

Change-Id: I1241f952359f6bb1d5bb0deb11cc0f44d94a3404
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-03-09 09:49:00 -08:00
Olav Haugan
41f8579a79 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>
2012-03-02 17:33:19 -08:00
Olav Haugan
79e9ffa55a 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>
2012-03-02 17:33:19 -08:00
Olav Haugan
de074a7d5b gpu: ion: Change from uncached to buffered mapping
PMEM uses buffered mappings when PMEM device is
opened with O_SYNC flag. ION should have the same
behavior as PMEM.

Change ION to provide buffered mappings instead
of uncached when the O_DSYNC flag is used when
opening the ION device.

CRs-fixed: 335827
Change-Id: I369a35a2ff68adc8339380dfbb7721e3d361ee69
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-02-23 13:48:18 -08:00
Olav Haugan
f6dc774968 gpu: ion: Move MFC heap to different address
Video hardware has the following requirements for
ION heaps:

1. MM heap must be at a higher address than FW heap.
2. MFC heap must at a higher address than FW
3. MM heap must be adjacent to FW heap.
   (There cannot be another heap between FW and MM heap)
4. MM and MFC heap cannot be more than 256MB away
   from the base address of the FW heap.

MM heap is configured as a reusable heap (FMEM heap) and FMEM
is carved out at a much higher address than the other heaps breaking
the above requirements. To support the above requirements the
MFC heap together with the FW heap must be carved out at the same
location as MM heap.

Change-Id: Ie0acb4b267d4307190ea3cd9ff23c710ffa1a538
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-02-19 20:26:15 -07:00
Olav Haugan
1c94f7be2d gpu: ion: Add support for IOMMU in CP heap
ION clients allocating from a content protection
heap (cp heap) must be able to map the memory to
an IOMMU when IOMMU are being used.

Add callbacks to CP heap to support IOMMU mapping.

Change-Id: I5dd70096edcab4866a436ae4447f9a6e00e2f0ec
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-02-08 09:49:09 -08:00
Laura Abbott
caafeea7ce gpu: ion: Add ION support for fmem
FMEM allows ION to release memory for other
purposes when ION clients are not using the
memory.

Add new heap type for fmem that make calls
into fmem API to transition memory from T to
C state and vice versa. Add support for
fmem to content protection heap.

Change-Id: I95f949b57c99949e6eafe6a6f5fd147bdaa264f6
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2012-02-03 15:21:49 -08:00
Olav Haugan
2a5404bfd9 gpu: ion: Add check for cached kernel mappings
An ION content protection heap should not allow
cached kernel space mapping for a heap that is
protected. Also, ION should not allow a heap that
has outstanding cached kernel space mappings to
be protected. These checks will ensure that the kernel
doesn't try to access memory that is locked down and
it cannot access.

Change-Id: I1f4a392d94ae8ae59c52978cfd0890e1a13fd39a
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-02-03 08:58:45 -08:00
Olav Haugan
ea66e7aa4b gpu: ion: Remove protection of heap on first alloc
ION protects the heap when the first secure allocation
is done while unprotecting when the last secure allocation
is freed. In addition ION provides a separate API for protecting
and unprotecting a heap allowing users to better time the
protection of a heap.

The protection/unprotection done during first allocation and
last free is not needed anymore. Clients need better control
and thus use the separate API.

Remove protection of heap that is occuring when the
first secure allocation is done. Remove unprotecting of
the heap when the last secure allocation is freed.

Change-Id: I80254c3a79399cd4900a389dcb535d843d6dfa80
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-02-03 08:58:44 -08:00
Laura Abbott
ec149ff980 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>
2012-01-30 01:04:11 -07:00
Olav Haugan
0fa9b60cc8 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>
2012-01-28 17:05:16 -08:00
Olav Haugan
bd2b6925de 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>
2012-01-26 09:18:18 -08:00
Olav Haugan
6625c7d1f8 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>
2012-01-24 14:26:04 -08:00
Laura Abbott
e8bc7aaf98 gpu: ion: Increment the ref count in mmap
The refcount increment actually needs to happen in mmap.
Otherwise it doesn't actually happen.

Change-Id: I1043453c2c828b8658a28acea57181759b2b21f0
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2012-01-19 11:06:59 -08:00
Olav Haugan
3d4fe1ac86 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>
2012-01-18 16:41:56 -08:00
Olav Haugan
35e2f2f14b 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>
2012-01-18 16:41:47 -08:00
Olav Haugan
63e5f3bc5a 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>
2012-01-18 16:41:26 -08:00
Olav Haugan
cb9ad9ead5 gpu: ion: Add decrement of mapping count
Add decrement of mapping count when mapping fails
and corresponding SMI release region call.

Change-Id: I81fb7eeee9973c770a65f02236c5358ce313e3a0
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-18 16:41:15 -08:00
Olav Haugan
9b2d1c2f8c gpu: ion: Clean up logging messages
Remove duplicate logging message for failure to create
a heap. Add logging message with name, base address, and
size of each heap created.

Change-Id: Id3a3706d914ffa72b0ecd84eb98785a678ceda9a
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-18 16:41:04 -08:00
Olav Haugan
41cf3e3363 gpu: ion: Fix SCM call message size
The SCM call message size used to protect and
unprotect memory is incorrect. The interface expects
13 bytes but 16 bytes is sent due to padding of the
message struct.

Pack the message structure to force the size of the
structure to 13 bytes.

Change-Id: Iecb7b40aa7e94454620c19cd70c3106392d2d311
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-18 16:40:53 -08:00
Olav Haugan
42ebe71efc gpu: ion: Add support for adjacent heaps
ION has to guarantee that two of the heaps are
adjacent to each other. This is due to a limitation
in the hardware. Add code to ensure these heaps
are adjacent.

Change-Id: Icc18437a50e1d872112468d02b61ab47fd70acc9
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-18 16:40:39 -08:00
Olav Haugan
0703dbf608 gpu: ion: Refactor platform data
Refactor platform data to allow for better
expansion in the future. Add void * for
elements unique to each heap type.

Change-Id: I435679819c67ce917b5798009eff7e71047fd2ea
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-15 09:30:35 -08:00
Olav Haugan
b06ee07711 gpu: ion: Change ION_IOC_ALLOC ioctl return value
ION_IOC_ALLOC may incorrectly return an error pointer
which could be 0 when an allocation fails. The ioctl call from user
space expects that the function succeeded when ioctl returns 0.
Change ION_IOC_ALLOC return value to -ENOMEM when the requested
buffer could not be allocated.

Change-Id: Id9d49ffa0eb8af5defc9635f40b45351b9dd8999
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-15 09:30:31 -08:00
Olav Haugan
e1f5d838d1 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>
2012-01-15 09:30:28 -08:00
Olav Haugan
5e56021d35 gpu: ion: Add missing iommu heap destroy call
When a heap is destroyed a heap type specific
function is called to release memory that the heap
structures used. A case statement handling destroying
the iommu heap is missing. Add missing case statement.

Change-Id: I1aa54209a55db06becc570f65ecf0f740d2e9545
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-15 09:30:25 -08:00
Olav Haugan
0a85251cd8 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>
2012-01-14 22:18:45 -07:00
Olav Haugan
7fba5cf795 gpu: ion: Add missing gen_pool_destroy call
If the carveout heap fails to be created the pool needs to
be destroyed.

Change-Id: I73f768d79a11aacd2161b079db9621264d14d2ad
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-10 16:45:32 -08:00
Olav Haugan
ee0f780d78 board: 8660: Add callbacks to request_region
Callbacks to request_region, release_region,
setup_region is missing from ION platform data for
SMI heap.

Change-Id: Ida603d4ac7c3246c0deedb9b80dc0c1ea64638eb
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2011-12-21 16:32:08 -08:00
Laura Abbott
0f2175b51f gpu: ion: Take handle reference in ion_vma_open
When ion_vma_open is called, a reference to the handle in
the vma must be taken. Otherwise, if forking occurs,
ion_vma_close will be called twice which will leave one of
the calls with an invalid reference.

Change-Id: I9ab6e68ab6b1d2ac4bed4f45045b4b2ee39995e8
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-12-09 14:26:07 -08:00
Linux Build Service Account
13605e484b Merge "gpu: ion: Check for release/request functions before calling" into msm-3.0 2011-12-08 14:54:13 -08:00
Laura Abbott
eed86035d5 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>
2011-12-08 08:39:38 -07:00
Laura Abbott
a683509211 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>
2011-12-07 15:07:01 -08:00
Laura Abbott
7716850941 gpu: ion: Incrememnt user refcount during vma_open/vma_close
Ion allows multiple mmaps of the same buffers. This means that
incrementing the usermap count in mmap and decrementing it in
release is not sufficient as release will only ever be called
once. Fix this by only doing the reference count change in the
vma_open and close which are called whenever mmap is called.

Change-Id: I6d17c0f563d0b90481d8e092c1e206f2b33c8e00
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-12-07 15:07:00 -08:00
Laura Abbott
b866d75946 gpu: ion: Check for release/request functions before calling
Not all heaps will implement the release/request callbacks. Check those
function pointers are valid before calling.

Change-Id: I848e31495e45c7eaa4497b82be590d291d77980a
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-12-07 10:48:17 -08:00
Laura Abbott
8c0173668e 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>
2011-12-05 10:36:11 -08:00
Laura Abbott
ceee3d25d5 gpu: ion: Map only the vma size given
When mapping carveout buffers into userspace, only map
the size of the vma given, not the full size of the buffer
since clients may map less than the buffer size.

Change-Id: Idf1d1ee5850c0f7045c0f78bfd5841a76db90a34
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-12-03 05:44:33 -07:00
Alex Bird
8a3ede3801 gpu: ion: Add callbacks to enable SMI voting in ION.
This change is part of the move from PMEM to ION. ION needs an SMI
voting interface smiliar to PMEM's.

Change-Id: I18888f46198848694fb7e1e0d2671074bf51d7c9
Signed-off-by: Alex Bird <alexbird@codeaurora.org>
2011-12-01 17:45:22 -08:00
Laura Abbott
e80ea017f1 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>
2011-11-21 12:27:52 -08:00
Laura Abbott
e1b9ce5c22 gpu: ion: Return negative value from ioctl on allocation failure
If the ion allocation fails, return a negative value to the
ioctl. This is easier for userspace to deal with than
checking if the handle is valid.

Change-Id: I1c785b1b1e71d2bd45c6f7be78ea15e4a08cd6e5
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-11-16 07:22:40 -08:00
Laura Abbott
9fa29e8889 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>
2011-11-16 07:22:40 -08:00
Olav Haugan
1a304b5ad6 gpu: ion: Make ion heap error handling consistent
If an error occurs during heap creation the behavior is different
depending on the error condition. If memory cannot be allocated
for the heap the rest of the heaps will be created. However, if
the ion heap cannot be created heap creation stops and all the heaps
are destroyed. Make the error handling consistent for both error
conditions by logging an error message and continuing creation
of the rest of the heaps.

General cleanup: Change global variables to be local to this
translation unit.

Change-Id: Ia8d2fb2f3257b91d6423b6722e12e9b3d7792e86
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2011-11-03 10:35:28 -07:00
Jordan Crouse
0a1195ece6 gpu: ion: Add map/unmap DMA ops for carveout heap
Change-Id: Ic0dedbad2a092c6b9dc9778d26f6315054520a63
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
2011-11-02 00:50:08 -06:00
Laura Abbott
404f824466 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>
2011-10-31 22:37:18 -07:00
Laura Abbott
8747bbe3e9 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>
2011-10-31 22:37:17 -07:00
Laura Abbott
3647ac3c7e 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>
2011-10-31 22:37:17 -07:00