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