Commit Graph

64 Commits

Author SHA1 Message Date
Ben Hoff
18c0350721 fix[drm]: Call drop master by default
drop master by default to avoid becoming the drm master

Signed-off-by: http://benhoff.net/
Change-Id: Idf850f4ae7c5a0177e058bc2f1d2acc2df70408d
2024-12-10 09:47:45 +08:00
Herman Chen
9c92ab9e20 fix[drm]: Fix permission check issue on GKI kernel
The GKI kernel does not allow non-render thread to open /dev/dri/card0
and alloc drm buffer from it. So we need to use /dev/dri/renderD128
instead.

Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Change-Id: I0fad306c6eeadd8da5507883f4f4915c11946761
2024-06-07 14:48:51 +08:00
Yanjun Liao
423ebb1da1 fix[ext_dma]: fix mmap permission error
Change-Id: Ic7ae7c8de978752f8437f2d0b700014ea6817c56
Signed-off-by: Yanjun Liao <yanjun.liao@rock-chips.com>
2024-03-18 18:05:13 +08:00
Herman Chen
8db63d761a fix[common]: Add mpp_dup function
mpp_dup function use fnctl F_DUPFD_CLOEXEC for fd dup with CLOEXEC flag.

Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Change-Id: Idd82eb935b06d2885685aeb696b95e910981539d
2024-01-10 18:15:45 +08:00
Herman Chen
6ce3007994 refactor[allocator]: Refactor allocator flow
1. Allocator api is determined by buffer type.
2. Allocator ctx is determined by both buffer type and buffer flags.
3. All allocator dma_heap / drm / ion / ext_dma should support different
buffer flags.
4. The buffer flag supports cacheable / 32-bit / contig options.
5. Add flags update flow on allocator create process.
6. Add mpp_dmabuf_has_partial_ops to disable dmabuf partial ops when the
kernel driver has bug.

Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Change-Id: If36a05c6704112cad3ab46861023597ff02bf14c
2023-11-29 09:54:36 +08:00
Yandong Lin
e155a7eac7 fix[dma_heap]: add dma heap uncached node checking
Currently only support uncached dma heap node access,
because of the cache processing is not yet complete.

So if there are no uncached node in /dev/dma_heap/ path,
mpp will not use dma_heap allocator.

Signed-off-by: Yandong Lin <yandong.lin@rock-chips.com>
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Change-Id: Ic33fca9c445c7668a86454f01f9d7577668de32b
2023-11-29 09:54:36 +08:00
Herman Chen
feab136f1a [allocator_dma_heap]: Add error log
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Change-Id: I06af727713e1c096eada8a40795f42668fdaff6d
2023-06-06 15:48:43 +08:00
xueman.ruan
c794d353c5 [allocator_dma_heap]: add file permission check.
Change-Id: Icfffaf3594f029b87e3a87f17de408a681c49dfb
Signed-off-by: xueman.ruan <xueman.ruan@rock-chips.com>
2023-05-04 08:57:02 +08:00
xueman.ruan
f387c6dac2 [mpp_allocator]: disable std allocator.
Signed-off-by: xueman.ruan <xueman.ruan@rock-chips.com>
Change-Id: I27441d49c2072176b848b5d80d408ebcb50926df
2023-04-07 09:06:37 +08:00
xueman.ruan
062c175265 [hal_jpege]: Add dma heap options for JPEG encode.
use cachable dma buffer to reduce copy time.

Signed-off-by: xueman.ruan <xueman.ruan@rock-chips.com>
Change-Id: I7fcc0fa5942ea5aa4e247b5f10677843d006ff28
2023-02-21 20:57:26 +08:00
Herman Chen
8828359534 [misc]: chmod all code file to 644
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Change-Id: I2225d7508a7f8bf5693077d20f48065e8324b318
2022-11-02 11:10:49 +08:00
Rimon Xu
1cc1af1b08 [osal]: reorder dma heap type select priority
Change-Id: Ifd2286ecf97fb4477693c24cdaec10c1df15eacf
Signed-off-by: Rimon Xu <rimon.xu@rock-chips.com>
2022-10-28 10:06:22 +08:00
Yandong Lin
d1fbc475fa [allocator_dma_heap]: fix compile err for linux/aarch64
Err notes:
    mpp/osal/allocator/allocator_dma_heap.c:26:27: fatal error:linux/dma-buf.h: No such file or directory

Signed-off-by: Yandong Lin <yandong.lin@rock-chips.com>
Change-Id: Ib5f0aa77f36adfd3bea98ff16de8000a82f49720
2022-07-01 08:57:18 +08:00
Herman Chen
60f5fc234a [allocator]: Add dma_heap allocator
The dma_heap is introduced in kernel 5.10.

Change-Id: Id3c116d996da461467fe380a79434ba5ea875033
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2022-06-24 15:52:06 +08:00
Herman Chen
e2072abcb8 [drm]: Remove drm_fd_to_handle on import
Remove drm handle to reduce iova usage.

Change-Id: Ie5000cb594806c9c7cc97f8ff7e25a4ba61f721a
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2022-06-23 09:25:16 +08:00
Herman Chen
2b35cee0ce [mpp_log]: Add more log helper function
1. Move mpp_log.h to inc for external user.
2. Add mpp_debug.h for mpp internal logging.
3. Fix some warning.
4. Add log level setup function.
5. Check env log_level value in mpp_get_log_level call.

NOTE:
1. mpp internal module should use mpp_debug.h and mpp external user
should use mpp_log.h
2. Use mpp_get_log_level to update mpp_log_level when the env changed.

Change-Id: I90a55a02a72db177533013280dfe111ca3479229
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2022-05-20 11:42:10 +08:00
Jeffy Chen
49f29006a3 [drm]: Add mmap flag detection
Change-Id: I1099248e40e507d67cf82a5c5dca89ba7c706d52
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
2021-08-04 09:43:19 +08:00
Jeffy Chen
b212aa4d08 [drm]: stop using drm_mmap and drm_munmap
That is no longer needed.

Change-Id: I6ee1efce4be88572200f10bc469904248e799bdc
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
2021-07-29 10:32:53 +08:00
Herman Chen
82aeaebe34 [drm]: Add DRM_CLOEXEC|DRM_RDWR flag on fd import
1. Add drm fd open flag.
2. Remove unused handle process on mmap.

Change-Id: Id0b29b8914c1e8e8ae6af40877df21f73b46346e
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
2021-07-15 17:15:21 +08:00
Herman Chen
5b05a3c5e9 [misc]: Add O_CLOEXEC flag on file open
When /dev/mpp_service is opened and be forked to another thread the
leaked fd will increase file refcnt in kernel.
Then the codec kernel session will be leaked on mpp_destroy.

Change-Id: I5bb682792c8e58591ec3a21af36e3f8a967f77fb
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2021-06-25 10:32:04 +08:00
aaron.sun
a748e54e88 [drm]: Fix drm handle issue
There is a bug when using single drm allocator device for all buffers:

Sample:
1. external fd a is import to mpp_buffer and get handle B / fd b.
2. external fd a is import to mpp_buffer again and get handle B / fd c.
   NOTE: The handle is the same in mpp for drm allocator is the same
   and the handle ref_count is not increased.
4. release fd b and handle B. (NOTE: The handle B is released in kernel)
5. mmap fd c by handle B. (Crash on getting handle B in kernel)

So we should reacquire handle for fd c when it need mmap or free.

Change-Id: Ide0591f97be5e00ca71f6a16e0ff676c4ed206a5
Signed-off-by: aaron.sun <aaron.sun@rockchips-com>
2021-06-25 08:58:10 +08:00
Johnson Ding
643d2116f8 [build]: support NDK-17 and above
Change-Id: I59bb0a1ad06a3e6d2a2b51610c528ade61e9c5d3
Signed-off-by: Johnson Ding <johnson.ding@rock-chips.com>
2021-01-13 11:23:55 +08:00
Shunqian Zheng
9464af395b [misc]: Terminate soc_name to fix out of bounds
1. Terminate soc_name string to fix memory out of bounds
2. Fix all snprintf/strnlen warning

Change-Id: I4525c6e289a00d1509bc30ee69545d92f2f4b9cb
Signed-off-by: Shunqian Zheng <zhengsq@rock-chips.com>
2020-04-29 16:06:47 +08:00
Herman Chen
11ac01351a [misc]: Fix compile warning on NDK r16b
Change-Id: I1c1f1137fbbb7875d48cee1b6c17aa1d4c6f0863
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2019-07-03 15:50:35 +08:00
Rimon Xu
a3116b8ce4 [ion]: scandir operation need to be protected by lock.
When multi thread calls scandir, crash may occur, so
the operation needs to be synchronized.

Change-Id: Idbdf539208259313d36c4acd17934af0e4dcf911
Signed-off-by: Rimon Xu <rimon.xu@rock-chips.com>
2019-04-23 15:10:24 +08:00
Herman Chen
033b2e9b22 [drm]: allocator drm code clean up
Add more log to allocator drm.

Change-Id: I3c6ec13ee6045fa06eec682b8e9cc933f8a03fe0
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2018-08-21 11:00:31 +08:00
Rimon Xu
fb73f23f53 [alloctor]: add flags for alloctor
Each of the different alloctor has different alloctor modes,
such as allocating physical continuous memory, secure memory,
etc.

Change-Id: Ib032689f0cfd36b494843dcc176a22c6c9587b6a
Signed-off-by: Rimon Xu <rimon.xu@rock-chips.com>
2018-05-07 17:34:34 +08:00
Randy Li
a78598dab5 [osal]: add new buffer type for DMA import buffer
This buffer type is used for the buffer coming from the
application, the application should make sure those
buffers are the dma buffer.

Change-Id: I2c8491f4dea77e5d7ae8d9157b0a1eda204f4bd6
Signed-off-by: Randy Li <randy.li@rock-chips.com>
2018-04-27 17:20:32 +08:00
Randy Li
86c5f925cd [alloactor]: fix some minior errors
1. fix the header protection
2. the incorrect offset in ion memory mapping
3. the commentment of the buffer type in a header file

Change-Id: If9d1db90d41131750a341ab6177f947f7b966317
Signed-off-by: Randy Li <randy.li@rock-chips.com>
2018-04-27 17:20:32 +08:00
Chengmc
e648d65af8 [allocator] lock ion heap detection operation
When in multi-codecs cases, the check_sysfs_iommu function reenters
with high probability, so some codec instances may fail to obtain
the correct memory type.

The root cause is scandir call in find_dir_in_path function. For
efficiency consideration it is better to lock ion_heap_id value.

Change-Id: I60a0eb27c3ac35bc022aa00b2cffc4e26e54bf24
Signed-off-by: Chengmc <Martin.Cheng@rock-chips.com>
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2018-03-22 17:00:49 +08:00
Randy Li
c56a9365f6 [ion]: file descriptor for the external buffer
The imported buffer may be released from its origin allocator,
I would suggest to use the new file descriptor from new ion
handle.

The ion only has map_user() to export buffer to userspace,
There is no unmap_user() because the mapping is represented as
a file descriptor in user space. The closing of that file
descriptor will cause the memory to be unmapped from
the calling process.

Change-Id: Ief855aab11793238b40b73da92af853ca3b58349
Signed-off-by: Randy Li <randy.li@rock-chips.com>
Signed-off-by: ayaka <ayaka@soulik.info>
2017-11-02 17:55:23 +08:00
Herman Chen
ba4b1db7ce [ioctl]: Add compatible patch for different kernel
New kernel use u32 as a fix length ioctl parameter then mpp should keep
compatible to all kernel driver case.

Change-Id: I73afe00971d7b73d6c4695254bc5fdf82422b1f5
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2017-11-01 17:23:13 +08:00
Randy Li
e0a1d6579d [drm]: use mmap() in native way for GNU Linux target
The "[drm]: fix runtime error for 32bit library" is hack way,
it won't work at GNU Linux platform. Also you need to check
_FILE_OFFSET_BITS and _LARGEFILE64_SOURCE before use the
mmap64().

For the normal mmap() with glibc, we only request to
check offset is aligned with page size but not the lenght.
But that doesn't apply for the memory from the drm device,
also the android use a different rule.

I decide not to map all the buffer to cpu at beginning
since most of them won't be access by the cpu.

Change-Id: I74ac7b5b63d45029cae076985a3d0b4526c62bbc
Signed-off-by: Randy Li <randy.li@rock-chips.com>
2017-10-27 10:06:20 +08:00
Randy Li
8083d5ca60 [drm]: fix a various of bugs in drm allocator
1. The wrong size information;
2. Release the drm buffer when the life of the buffer is ended.

Change-Id: I8a17bf807609dfa940545f2391a62bd0a4f51670
Signed-off-by: Randy Li <randy.li@rock-chips.com>
2017-10-27 10:05:55 +08:00
Randy Li
19c0237886 [ion]: file descriptor for the external buffer
The imported buffer may be released from its origin allocator,
I would suggest to use the new file descriptor from new ion
handle.

NOTE: User may use file descriptor outside mpp as buffer index.
If mpp chooses new map fd as its output user may lost the
connection between user external buffer and mpp output buffer.

Change-Id: Ie0f42cd3268dfd08ddcbd5148a68406ff4b66b7a
Signed-off-by: Randy Li <randy.li@rock-chips.com>
Signed-off-by: ayaka <ayaka@soulik.info>
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2017-06-14 11:38:32 +08:00
Randy Li
42fc9843bc [alloactor]: fix the compiler warnings in drm
Change-Id: I17fd18b6c6be4fb4855e35e5aea0b656e5aeb2d9
Signed-off-by: Randy Li <randy.li@rock-chips.com>
2017-03-24 14:03:21 +08:00
Randy Li
e709b1b621 [alloactor]: fix the compiler warnings in ion
Change-Id: I73a7d4dae08f18aa2c61d1b3766ea94b7d9eea21
Signed-off-by: Randy Li <randy.li@rock-chips.com>
2017-03-24 14:03:21 +08:00
Randy Li
d0b76f9703 [alloactor]: fix the compiler warnings in std
Change-Id: I6613d51cae9633f4048d65de9d23a295e70f5626
Signed-off-by: Randy Li <randy.li@rock-chips.com>
2017-03-24 14:03:20 +08:00
Herman Chen
1bbd1dcce6 [ion]: Ion buffer mmap optimization
1. Do not do map when MppBuffer alloc or import. Only map when user requires a
user pointer. This will save a lot of vma resource especially when buffer is
very large.
2. Fix error in mpp_dec thread which use info.ptr directly.
3. Use external fd on import (have risk of external user close fd on hw work)

Change-Id: I28225f6ba28afa3e9475e605bf971348dcef185a
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2017-01-04 15:01:09 +08:00
Herman Chen
e2f0da0a89 [allocator]: Transform allocator normal to std
1. Use allocator std to replace default normal allocator on all OS.
2. Use wrapper to simplify mpp_allocator.

Change-Id: I13314a9eec3c5b39bc5ad8ddb3033ac2da79ba8f
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2016-12-15 17:20:14 +08:00
Alpha Lin
f98c06f233 [osal]: add new dts node for iommu determination
Add new dts node 'vpu_combo' for rk312x,rk3368 video codec devices
compatibility.

Change-Id: I81326d478788ddddfb42e9fe0f4596ab84183934
Signed-off-by: Alpha Lin <alpha.lin@rock-chips.com>
2016-12-02 14:28:40 +08:00
Jung Zhao
4273a46252 [drm]: add drm_debug environment support
Change-Id: If31a5ede4460f2147eba126301be39e28e3c0626
Signed-off-by: Jung Zhao <jung.zhao@rock-chips.com>
2016-11-30 17:52:08 +08:00
hh
824c04836e [ion]: fix ion handle check error
Ion file handle can have a fd_flag equal to 0. So we need to remove the
condition fd_flag == 0 in funciton os_allocator_ion_import.

Change-Id: I0393cf1f69d358308903fc7461efc36158f42358
Signed-off-by: hh <hh@rock-chips.com>
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2016-11-29 10:34:12 +08:00
Lin Kesheng
89e11ed9c7 [ion]: dup new fd while get fd 0 after importing
1. check input fd is valid
2. dup new fd while imported fd is 0

Change-Id: Ic20d070d1a29e7d37c4f1e75cbef89263c5bc3a9
Signed-off-by: Lin Kesheng <lks@rock-chips.com>
2016-11-25 14:55:32 +08:00
Herman Chen
3bd7a6e027 [drm]: fix runtime error for 32bit library
1. When run the 32bit library without mmap64 it will fail due to lack of mmap64
symbol. So we do a runtime detection.
2. Fix runtime error of missing getpagesize. Use sysconf(_SC_PAGESIZE) instead.

Change-Id: I6dbeb6d55175a1ebb48d314f3dc691cd029710d1
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2016-11-16 14:28:21 +08:00
Herman Chen
80140b3966 [ion]: use mpp_log to print scan info
In order to avoid misunderstanding change mpp_err to mpp_log

Change-Id: Id4a0591a0eeb7975fcdf1979b9d45c9b8d076370
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2016-10-11 10:06:33 +08:00
Jung Zhao
deb649610c [drm]: add macro control in os_allocator.c
1. fix compiling error of previous commit
2. can enable drm on x86 pc linux platform

Change-Id: I06271fe0efcaa7de2531c7fb3e21bf9c75781beb
Signed-off-by: Jung Zhao <jung.zhao@rock-chips.com>
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2016-10-07 17:37:05 +08:00
Lin Kesheng
60373a6973 [all]: format code
use fromdos to change file type, remove ^M in code.

Change-Id: I000202dc51fcff57cc0771455baebea595115b1d
Signed-off-by: Lin Kesheng <lks@rock-chips.com>
2016-09-08 15:21:02 +08:00
Jung Zhao
70e2ebdb2b [drm]: add android drm allocator support
1. enable drm allocator in android
2. modify size calculating when alloc

Todo: wait for new interface of kernel to decide
use whether drm or ion as allocator

Change-Id: Ia6791d91d113b238be77088ae747012fb786d683
Signed-off-by: Jung Zhao <jung.zhao@rock-chips.com>
2016-08-29 14:26:49 +08:00
Herman Chen
43bfdc6bdf [format]: format coding style
Change-Id: I3d0e081f6636ca8162df4bda68618ec0ba37e7ae
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
2016-08-23 09:16:22 +08:00