xref: /OK3568_Linux_fs/external/mpp/osal/linux/os_allocator.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright 2015 Rockchip Electronics Co. LTD
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Licensed under the Apache License, Version 2.0 (the "License");
5*4882a593Smuzhiyun  * you may not use this file except in compliance with the License.
6*4882a593Smuzhiyun  * You may obtain a copy of the License at
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *      http://www.apache.org/licenses/LICENSE-2.0
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * Unless required by applicable law or agreed to in writing, software
11*4882a593Smuzhiyun  * distributed under the License is distributed on an "AS IS" BASIS,
12*4882a593Smuzhiyun  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*4882a593Smuzhiyun  * See the License for the specific language governing permissions and
14*4882a593Smuzhiyun  * limitations under the License.
15*4882a593Smuzhiyun  */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #if defined(linux) && !defined(__ANDROID__)
18*4882a593Smuzhiyun #include "mpp_log.h"
19*4882a593Smuzhiyun #include "mpp_runtime.h"
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #include "allocator_dma_heap.h"
22*4882a593Smuzhiyun #include "allocator_drm.h"
23*4882a593Smuzhiyun #include "allocator_ext_dma.h"
24*4882a593Smuzhiyun #include "allocator_ion.h"
25*4882a593Smuzhiyun #include "allocator_std.h"
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun /*
28*4882a593Smuzhiyun  * Linux only support MPP_BUFFER_TYPE_NORMAL so far
29*4882a593Smuzhiyun  * we can support MPP_BUFFER_TYPE_V4L2 later
30*4882a593Smuzhiyun  */
31*4882a593Smuzhiyun 
os_allocator_get(os_allocator * api,MppBufferType type)32*4882a593Smuzhiyun MPP_RET os_allocator_get(os_allocator *api, MppBufferType type)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun     MPP_RET ret = MPP_OK;
35*4882a593Smuzhiyun     switch (type) {
36*4882a593Smuzhiyun     case MPP_BUFFER_TYPE_NORMAL : {
37*4882a593Smuzhiyun         *api = allocator_std;
38*4882a593Smuzhiyun     } break;
39*4882a593Smuzhiyun     case MPP_BUFFER_TYPE_ION : {
40*4882a593Smuzhiyun         *api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION)) ? allocator_ion :
41*4882a593Smuzhiyun                (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap :
42*4882a593Smuzhiyun #if HAVE_DRM
43*4882a593Smuzhiyun                (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM)) ? allocator_drm :
44*4882a593Smuzhiyun #endif
45*4882a593Smuzhiyun                allocator_std;
46*4882a593Smuzhiyun     } break;
47*4882a593Smuzhiyun     case MPP_BUFFER_TYPE_EXT_DMA: {
48*4882a593Smuzhiyun         *api = allocator_ext_dma;
49*4882a593Smuzhiyun     } break;
50*4882a593Smuzhiyun     case MPP_BUFFER_TYPE_DRM : {
51*4882a593Smuzhiyun         *api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap :
52*4882a593Smuzhiyun #if HAVE_DRM
53*4882a593Smuzhiyun                (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DRM)) ? allocator_drm :
54*4882a593Smuzhiyun #endif
55*4882a593Smuzhiyun                (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_ION)) ? allocator_ion :
56*4882a593Smuzhiyun                allocator_std;
57*4882a593Smuzhiyun     } break;
58*4882a593Smuzhiyun     case MPP_BUFFER_TYPE_DMA_HEAP: {
59*4882a593Smuzhiyun         *api = (mpp_rt_allcator_is_valid(MPP_BUFFER_TYPE_DMA_HEAP)) ? allocator_dma_heap :
60*4882a593Smuzhiyun                allocator_std;
61*4882a593Smuzhiyun     } break;
62*4882a593Smuzhiyun     default : {
63*4882a593Smuzhiyun         ret = MPP_NOK;
64*4882a593Smuzhiyun     } break;
65*4882a593Smuzhiyun     }
66*4882a593Smuzhiyun     return ret;
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun #endif
70