• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2010 Rockchip Electronics S.LSI Co. LTD
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 /*
18    * File:
19    * vpu_mem.h
20    * Description:
21    *
22    * Author:
23    *     Chm
24    * Date:
25    *    2010-11-23
26  */
27 
28 
29 #ifndef __VPU_MEM_H__
30 #define __VPU_MEM_H__
31 
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36 
37 #include "vpu_type.h"
38 #include "vpu_api.h"
39 /* Linear memory area descriptor */
40 
41 #define VPU_MEM_IS_NULL(p)          ((p)->offset < 0)
42 
43 /* SW/HW shared memory */
44 RK_S32 VPUMallocLinear(VPUMemLinear_t *p, RK_U32 size);
45 RK_S32 VPUFreeLinear(VPUMemLinear_t *p);
46 RK_S32 VPUMemDuplicate(VPUMemLinear_t *dst, VPUMemLinear_t *src);
47 RK_S32 VPUMemLink(VPUMemLinear_t *p);
48 RK_S32 VPUMemFlush(VPUMemLinear_t *p);
49 RK_S32 VPUMemClean(VPUMemLinear_t *p);
50 RK_S32 VPUMemInvalidate(VPUMemLinear_t *p);
51 RK_U32 *VPUMemVirtual(VPUMemLinear_t *p);
52 RK_S32 VPUMemPoolSet(RK_U32 size, RK_U32 count);
53 RK_S32 VPUMemPoolUnset(RK_U32 size, RK_U32 count);
54 RK_S32 VPUMemGetFreeSize();
55 RK_S32 VPUMallocLinearFromRender(VPUMemLinear_t *p, RK_U32 size, void *ctx);
56 RK_S32 VPUMemGetFD(VPUMemLinear_t *p);
57 RK_S32 VPUMemGetREF(VPUMemLinear_t *p);
58 RK_S32 VPUMemJudgeIommu();
59 RK_S32 VPUMemImport_phyaddr(int share_fd, RK_U32 *phy_addr);
60 
61 // new malloc interface by with allocator for memory management
62 typedef void*   RK_HANDLE;
63 typedef struct {
64     RK_U32      phy_addr;
65     RK_U32     *vir_addr;
66     int         fd;
67     RK_HANDLE   handle;
68 } VPUMemHnd;
69 
70 typedef enum {
71     VPU_CACHE_FLUSH,
72     VPU_CACHE_CLEAN,
73     VPU_CACHE_INVALID,
74     VPU_CACHE_OP_NUM,
75 } VPUCacheOp_E;
76 
77 typedef enum {
78     INVALID_NULL_PTR = 0x8000000,
79     INVALID_ALLOCATOR,
80     INVALID_MEM_HND,
81     INVALID_CACHE_OP,
82 } VPUMemError;
83 
84 // maxSize equal to zero means no limit
85 RK_HANDLE VPUMemAllocatorCreate(RK_U32 maxSize);
86 RK_S32 VPUMemMalloc(RK_HANDLE allocator, RK_U32 size, RK_S32 timeout, VPUMemHnd **p);
87 RK_S32 VPUMemImport(RK_HANDLE allocator, RK_S32 mem_fd, VPUMemHnd **p);
88 RK_S32 VPUMemFree(VPUMemHnd *p);
89 RK_S32 VPUMemShare(VPUMemHnd *p, RK_S32 *mem_fd);
90 RK_S32 VPUMemCache(VPUMemHnd *p, VPUCacheOp_E cmd);
91 void VPUMemAllocatorDestory(RK_HANDLE allocator);
92 
93 #ifdef __cplusplus
94 }
95 
96 #endif
97 
98 #endif /* __VPU_MEM_H__ */
99 
100