• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2019, The Linux Foundation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *    * Redistributions of source code must retain the above copyright
8  *      notice, this list of conditions and the following disclaimer.
9  *    * Redistributions in binary form must reproduce the above
10  *      copyright notice, this list of conditions and the following
11  *      disclaimer in the documentation and/or other materials provided
12  *      with the distribution.
13  *    * Neither the name of The Linux Foundation nor the names of its
14  *      contributors may be used to endorse or promote products derived
15  *      from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef RPCMEM_H
31 #define RPCMEM_H
32 
33 #include "AEEStdDef.h"
34 
35 /**
36  * RPCMEM_DEFAULT_HEAP
37  * Dynamicaly select the heap to use.  This should be ok for most usecases.
38  */
39 #define RPCMEM_DEFAULT_HEAP -1
40 
41 
42 /**
43  * RPCMEM_DEFAULT_FLAGS should allocate memory with the same properties
44  * as the ION_FLAG_CACHED flag
45  */
46 #ifdef ION_FLAG_CACHED
47 #define RPCMEM_DEFAULT_FLAGS ION_FLAG_CACHED
48 #else
49 #define RPCMEM_DEFAULT_FLAGS 1
50 #endif
51 
52 /**
53  * RPCMEM_FLAG_UNCACHED
54  * ION_FLAG_CACHED should be defined as 1
55  */
56 #define RPCMEM_FLAG_UNCACHED 0
57 #define RPCMEM_FLAG_CACHED RPCMEM_DEFAULT_FLAGS
58 
59 /**
60  * examples:
61  *
62  * heap 22, uncached, 1kb
63  *    rpcmem_alloc(22, 0, 1024);
64  *    rpcmem_alloc(22, RPCMEM_FLAG_UNCACHED, 1024);
65  *
66  * heap 21, cached, 2kb
67  *    rpcmem_alloc(21, RPCMEM_FLAG_CACHED, 2048);
68  *    #include <ion.h>
69  *    rpcmem_alloc(21, ION_FLAG_CACHED, 2048);
70  *
71  * just give me the defaults, 2kb
72  *    rpcmem_alloc(RPCMEM_DEFAULT_HEAP, RPCMEM_DEFAULT_FLAGS, 2048);
73  *    rpcmem_alloc_def(2048);
74  *
75  * give me the default flags, but from heap 18, 4kb
76  *    rpcmem_alloc(18, RPCMEM_DEFAULT_FLAGS, 4096);
77  *
78  */
79 #define ION_SECURE_FLAGS    ((1 << 31) | (1 << 19))
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
84 /**
85  * call once to initialize the library
86  * Note: should not call this if rpcmem is linked from libadsprpc.so
87  * /libcdsprpc.so/libmdsprpc.so/libsdsprpc.so
88  */
89 void rpcmem_init(void);
90 /**
91  * call once for cleanup
92  * Note: should not call this if rpcmem is linked from libadsprpc.so
93  * /libcdsprpc.so/libmdsprpc.so/libsdsprpc.so
94  */
95 void rpcmem_deinit(void);
96 
97 /**
98  * Allocate via ION a buffer of size
99  * @heapid, the heap id to use
100  * @flags, ion flags to use to when allocating
101  * @size, the buffer size to allocate
102  * @retval, 0 on failure, pointer to buffer on success
103  *
104  * For example:
105  *    buf = rpcmem_alloc(RPCMEM_DEFAULT_HEAP, RPCMEM_DEFAULT_FLAGS, size);
106  */
107 
108 void* rpcmem_alloc(int heapid, uint32 flags, int size);
109 
110 /**
111  * allocate with default settings
112  */
113  #if !defined(WINNT) && !defined (_WIN32_WINNT)
114 __attribute__((unused))
115 #endif
rpcmem_alloc_def(int size)116 static __inline void* rpcmem_alloc_def(int size) {
117    return rpcmem_alloc(RPCMEM_DEFAULT_HEAP, RPCMEM_DEFAULT_FLAGS, size);
118 }
119 
120 /**
121  * free buffer, ignores invalid buffers
122  */
123 void rpcmem_free(void* po);
124 
125 /**
126  * returns associated fd
127  */
128 int rpcmem_to_fd(void* po);
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #define RPCMEM_HEAP_DEFAULT     0x80000000
135 #define RPCMEM_HEAP_NOREG       0x40000000
136 #define RPCMEM_HEAP_UNCACHED    0x20000000
137 #define RPCMEM_HEAP_NOVA        0x10000000
138 #define RPCMEM_HEAP_NONCOHERENT 0x08000000
139 
140 #endif //RPCMEM_H
141