Init basesystem source codes.
[staging/basesystem.git] / stub / memory_gpio_access_library / client / include / stub / el_mem.h
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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 /**
18  * @file el_mem.h
19  * @brief el_mem function header file
20  */
21
22 #ifndef MEMORY_GPIO_ACCESS_LIBRARY_CLIENT_INCLUDE_NATIVE_SERVICE_EL_MEM_H_
23 #define MEMORY_GPIO_ACCESS_LIBRARY_CLIENT_INCLUDE_NATIVE_SERVICE_EL_MEM_H_
24
25 /** @addtogroup BaseSystem
26  *  @{
27  */
28 /** @addtogroup native_service
29  *  @ingroup BaseSystem
30  *  @{
31  */
32 /** @addtogroup memory_gpio_access_library
33  *  @ingroup native_service
34  *  @{
35  */
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 #include <stdbool.h>
41 #include <sys/types.h>
42
43 /**
44 * \~english Definitions of the Parametar of type
45 */
46 enum {
47   EL_MEM_TYPE_REGION_SYS,            //!< \~english SYS region
48   EL_MEM_TYPE_REGION_LOG,            //!< \~english LOG region
49   EL_MEM_TYPE_REGION_COM,            //!< \~english COMMUNICATION region
50   EL_MEM_TYPE_REGION_NAVI,           //!< \~english NAVI region
51   EL_MEM_TYPE_REGION_SH4A,           //!< \~english SH4A region
52   EL_MEM_TYPE_REGION_PRAMFS,         //!< \~english PRAMFS region
53   EL_MEM_TYPE_REGION_STARTUPBGM,     //!< \~english STARTUPBGM region
54   EL_MEM_TYPE_REGION_NAVI_IR,        //!< \~english NAVI picture recognition region
55   EL_MEM_TYPE_REGION_MAX             //!< \~english (internal use)
56 };
57
58 /**
59 * \~english Definitions of the Parametar of memory id
60 */
61 enum {
62   // SYS region
63   EL_MEM_ID_SYS_ALL   = 0x0001,          //!< \~english all SYS region
64   EL_MEM_ID_SYS_BOOT,                    //!< \~english particular: BOOT region
65
66   // LOG region
67   EL_MEM_ID_LOG_ALL = 0x1001,            //!< \~english all LOG region
68
69   // COM region
70   EL_MEM_ID_COM_ALL = 0x2001,            //!< \~english all COMMUNICATION region
71   EL_MEM_ID_COM_SH4A,            //!< \~english particular: SH4A abnornal observation
72
73   // NAVI region
74   EL_MEM_ID_NAVI_ALL  = 0x3001,          //!< \~english NAVI region
75   EL_MEM_ID_NAVI_LOG,                //!< \~english particular: NAVI(AW) LOG region
76
77   // SH4A region
78   EL_MEM_ID_SH4A_ALL  = 0x4001,          //!< \~english SH4A region
79   EL_MEM_ID_SH4A_SHM,   //!< \~english particular: SH4A SH share memory region
80
81   // PRAMFS region NOTE:Can be used only when ROM operation
82   EL_MEM_ID_PRAMFS_ALL = 0x5001,         //!< \~english all PRAMFS region
83
84   // STARTUPBGM region
85   EL_MEM_ID_STARTUPBGM_ALL = 0x6001,     //!< \~english all STARTUPBGM region
86
87   // NAVI region (Picture Recognition: For Image Recognition)
88   EL_MEM_ID_NAVI_IR_ALL = 0x7001,  //!< \~english all NAVI picture recognition region
89 };
90
91 /**
92  * \~english Valid cache_flag
93  */
94 #define EL_MEM_CACHE_VALID      1
95
96 /**
97  * \~english Invalid cache_flag
98  */
99 #define EL_MEM_CACHE_INVALID    0
100
101 /**\ingroup EL_mem_getOffset
102 * \~english @par Brief
103 *        Get offset of function region according to mem_id.
104 * \~english @param [in] mem_id
105 *        int   - memory id
106 * \~english @par
107 *        Defined memory id as follows.
108 * \~english @code
109 *        enum {
110 *                   // SYS
111 *                   EL_MEM_ID_SYS_ALL   = 0x0001,          // all SYS region
112 *                   EL_MEM_ID_SYS_BOOT,                    // particular: BOOT region
113 *                   // COM
114 *                   EL_MEM_ID_COM_ALL = 0x2001,            // all COMMUNICATION region
115 *                   EL_MEM_ID_COM_SH4A,                    // particular: SH4A abnornal observation
116 *                   // NAVI
117 *                   EL_MEM_ID_NAVI_ALL  = 0x3001,          // NAVI region
118 *                   EL_MEM_ID_NAVI_LOG,                    // particular: NAVI(AW) LOG region
119 *                   // SH4A
120 *                   EL_MEM_ID_SH4A_ALL  = 0x4001,          // SH4A region
121 *                   EL_MEM_ID_SH4A_SHM,                    // particular: SH4A SH share memory region
122 *                   // PRAMFS NOTE:ROM only
123 *                   EL_MEM_ID_PRAMFS_ALL = 0x5001,         // all PRAMFS region
124 *                   // STARTUPBGM
125 *                   EL_MEM_ID_STARTUPBGM_ALL = 0x6001,     // all STARTUPBGM region
126 *                   // NAVI (Image Recognition)
127 *                   EL_MEM_ID_NAVI_IR_ALL = 0x7001,        // all NAVI picture recognition region
128 *        };
129 *            @endcode
130 * \~english @retval offset Success
131 * \~english @retval -1 Error
132 * \~english @par Prerequisite
133 *        - None.
134 * \~english @par Change of internal state
135 *        - Change of internal state according to the API does not occur.
136 * \~english @par Conditions of processing failure
137 *        - Parameter mem_id is not defined.[-1]
138 * \~english @par Detail
139 *        - Get offset of function region according to mem_id.
140 * \~english @par Classification
141 *        Public
142 * \~english @par Type
143 *        Sync
144 * \~english @see none
145 */
146 off_t EL_mem_getOffset(int mem_id);  // NOLINT [readability/naming]
147
148 /**\ingroup EL_mem_getLength
149 * \~english @par Brief
150 *        Get length of function region according to mem_id.
151 * \~english @param [in] mem_id
152 *        int   - memory id
153 * \~english @par
154 *        Defined memory id as follows.
155 * \~english @code
156 *        enum {
157 *                   // SYS
158 *                   EL_MEM_ID_SYS_ALL   = 0x0001,          // all SYS region
159 *                   EL_MEM_ID_SYS_BOOT,                    // particular: BOOT region
160 *                   // COM
161 *                   EL_MEM_ID_COM_ALL = 0x2001,            // all COMMUNICATION region
162 *                   EL_MEM_ID_COM_SH4A,                    // particular: SH4A abnornal observation
163 *                   // NAVI
164 *                   EL_MEM_ID_NAVI_ALL  = 0x3001,          // NAVI region
165 *                   EL_MEM_ID_NAVI_LOG,                    // particular: NAVI(AW) LOG region
166 *                   // SH4A
167 *                   EL_MEM_ID_SH4A_ALL  = 0x4001,          // SH4A region
168 *                   EL_MEM_ID_SH4A_SHM,                    // particular: SH4A SH share memory region
169 *                   // PRAMFS NOTE:ROM only
170 *                   EL_MEM_ID_PRAMFS_ALL = 0x5001,         // all PRAMFS region
171 *                   // STARTUPBGM
172 *                   EL_MEM_ID_STARTUPBGM_ALL = 0x6001,     // all STARTUPBGM region
173 *                   // NAVI (Image Recognition)
174 *                   EL_MEM_ID_NAVI_IR_ALL = 0x7001,        // all NAVI picture recognition region
175 *        };
176 *            @endcode
177 * \~english @retval length Success
178 * \~english @retval 0 Error
179 * \~english @par Prerequisite
180 *        - None.
181 * \~english @par Change of internal state
182 *        - Change of internal state according to the API does not occur.
183 * \~english @par Conditions of processing failure
184 *        - Parameter mem_id is not defined.[0]
185 *        - syscall error(open(), ioctl()).[0]
186 * \~english @par Detail
187 *        - Get length of function region according to mem_id.
188 * \~english @par Classification
189 *        Public
190 * \~english @par Type
191 *        Sync
192 * \~english @see none
193 */
194 size_t EL_mem_getLength(int mem_id);  // NOLINT [readability/naming]
195
196 /**\ingroup EL_mem_exram_mmap_simple
197 * \~english @par Brief
198 *        Map device file to memory.(simple)
199 * \~english @param [in] mem_id
200 *        int   - memory id
201 * \~english @param [in] prot
202 *        int   - Linux standard (same to mmap() of /dev/mem)
203 * \~english @param [in] flags
204 *        int   - Linux standard (same to mmap() of /dev/mem)
205 * \~english @param [in] cache_flag
206 *        int   - cache flag valid/invalid
207 * \~english @par
208 *        Defined memory id as follows.
209 * \~english @code
210 *        enum {
211 *                   // SYS
212 *                   EL_MEM_ID_SYS_ALL   = 0x0001,          // all SYS region
213 *                   EL_MEM_ID_SYS_BOOT,                    // particular: BOOT region
214 *                   // COM
215 *                   EL_MEM_ID_COM_ALL = 0x2001,            // all COMMUNICATION region
216 *                   EL_MEM_ID_COM_SH4A,                    // particular: SH4A abnornal observation
217 *                   // NAVI
218 *                   EL_MEM_ID_NAVI_ALL  = 0x3001,          // NAVI region
219 *                   EL_MEM_ID_NAVI_LOG,                    // particular: NAVI(AW) LOG region
220 *                   // SH4A
221 *                   EL_MEM_ID_SH4A_ALL  = 0x4001,          // SH4A region
222 *                   EL_MEM_ID_SH4A_SHM,                    // particular: SH4A SH share memory region
223 *                   // PRAMFS NOTE:ROM only
224 *                   EL_MEM_ID_PRAMFS_ALL = 0x5001,         // all PRAMFS region
225 *                   // STARTUPBGM
226 *                   EL_MEM_ID_STARTUPBGM_ALL = 0x6001,     // all STARTUPBGM region
227 *                   // NAVI (Image Recognition)
228 *                   EL_MEM_ID_NAVI_IR_ALL = 0x7001,        // all NAVI picture recognition region
229 *        };
230 *            @endcode
231 * \~english @par
232 *        Cache flag as follows.
233 * \~english @code
234 *                 #define EL_MEM_CACHE_VALID      1   // valid cache
235 *                 #define EL_MEM_CACHE_INVALID    0   // invalid cache
236 *            @endcode
237 * \~english @retval address Success
238 * \~english @retval -1 Error
239 * \~english @par Prerequisite
240 *        - None.
241 * \~english @par Change of internal state
242 *        - Change of internal state according to the API does not occur.
243 * \~english @par Conditions of processing failure
244 *        - Parameter mem_id is not defined.[-1]
245 *        - Open device file failed.[-1]
246 *        - Map device file to memory error.[-1]
247 * \~english @par Detail
248 *        - Get type, offset and length from internal table specified by mem_id, then\n
249 *        call \ref EL_mem_exram_mmap.
250 * \~english @par Classification
251 *        Public
252 * \~english @par Type
253 *        Sync
254 * \~english @see EL_mem_getLength, EL_mem_exram_mmap, EL_mem_exram_munmap
255 */
256 void *EL_mem_exram_mmap_simple(int mem_id , int prot, int flags , int cache_flag);  // NOLINT [readability/naming]
257
258 /**\ingroup EL_mem_exram_mmap
259 * \~english @par Brief
260 *        Map device file to memory.
261 * \~english @param [in] type
262 *        int   - memory type
263 * \~english @param [in] offset
264 *        off_t   - offset(From 0\ref EL_mem_getOffset)
265 * \~english @param [in] length
266 *        size_t   - length(From 1\ref EL_mem_getLength)
267 * \~english @param [in] prot
268 *        int   - Linux standard (same to mmap() of /dev/mem)
269 * \~english @param [in] flags
270 *        int   - Linux standard (same to mmap() of /dev/mem)
271 * \~english @param [in] cache_flag
272 *        int   - cache flag valid/invalid
273 * \~english @par
274 *        Defined memory type as follows.
275 * \~english @code
276 *        enum {
277 *                   EL_MEM_TYPE_REGION_SYS,            // SYS
278 *                   EL_MEM_TYPE_REGION_COM,            // COMMUNICATION
279 *                   EL_MEM_TYPE_REGION_NAVI,           // NAVI
280 *                   EL_MEM_TYPE_REGION_SH4A,           // SH4A
281 *                   EL_MEM_TYPE_REGION_PRAMFS,         // PRAMFS
282 *                   EL_MEM_TYPE_REGION_STARTUPBGM,     // STARTUPBGM
283 *                   EL_MEM_TYPE_REGION_NAVI_IR,        // NAVI IMAGE
284 *        };
285 *            @endcode
286 * \~english @par
287 *        Cache flag as follows.
288 * \~english @code
289 *                 #define EL_MEM_CACHE_VALID      1   // valid cache
290 *                 #define EL_MEM_CACHE_INVALID    0   // invalid cache
291 *            @endcode
292 * \~english @retval address Success
293 * \~english @retval -1 Error
294 * \~english @par Prerequisite
295 *        - None.
296 * \~english @par Change of internal state
297 *        - Change of internal state according to the API does not occur.
298 * \~english @par Conditions of processing failure
299 *        - Open device file failed.[-1]
300 *        - Map device file to memory error.[-1]
301 * \~english @par Detail
302 *        - Access device file specified by memory type, map function region to user space.
303 * \~english @par Classification
304 *        Public
305 * \~english @par Type
306 *        Sync
307 * \~english @see EL_mem_exram_munmap
308 */
309 void *EL_mem_exram_mmap(int type, off_t offset , size_t length , int prot, int flags , int cache_flag);  // NOLINT [readability/naming]
310
311 /**\ingroup EL_mem_exram_munmap
312 * \~english @par Brief
313 *        Unmap device file from memory.
314 * \~english @param [in] addr
315 *        void *   - address
316 * \~english @param [in] length
317 *        size_t   - size (1 ~ \ref EL_mem_getLength)
318 * \~english @retval 0 Success
319 * \~english @retval -1 Error:Set errno according to error type when error occurs.
320 * \~english @par Prerequisite
321 *        - Map device file to memory(\ref EL_mem_exram_mmap,
322 *          \ref EL_mem_exram_mmap_simple).
323 * \~english @par Change of internal state
324 *        - Change of internal state according to the API does not occur.
325 * \~english @par Conditions of processing failure
326 *        - Unmap device file from memory error.[-1]
327 * \~english @par Detail
328 *        - Unmap specified address.Error occurs when refer to this memory after unmap.
329 *        - Automatic unmap when process ends.
330 *        - The memory will not be unmap even the file descriptor is closed.
331 * \~english @par Classification
332 *        Public
333 * \~english @par Type
334 *        Sync
335 * \~english @see EL_mem_exram_mmap, EL_mem_exram_mmap_simple
336 */
337 int EL_mem_exram_munmap(void *addr, size_t length);  // NOLINT [readability/naming]
338
339 /**\ingroup EL_mem_getPhysicalAddress
340 * \~english @par Brief
341 *        Get physical address.
342 * \~english @param [in] mem_id
343 *        int   - memory id
344 * \~english @par
345 *        Defined memory id as follows.
346 * \~english @code
347 *        enum {
348 *                   // SYS
349 *                   EL_MEM_ID_SYS_ALL   = 0x0001,          // all SYS region
350 *                   EL_MEM_ID_SYS_BOOT,                    // particular: BOOT region
351 *                   // COM
352 *                   EL_MEM_ID_COM_ALL = 0x2001,            // all COMMUNICATION region
353 *                   EL_MEM_ID_COM_SH4A,                    // particular: SH4A abnornal observation
354 *                   // NAVI
355 *                   EL_MEM_ID_NAVI_ALL  = 0x3001,          // NAVI region
356 *                   EL_MEM_ID_NAVI_LOG,                    // particular: NAVI(AW) LOG region
357 *                   // SH4A
358 *                   EL_MEM_ID_SH4A_ALL  = 0x4001,          // SH4A region
359 *                   EL_MEM_ID_SH4A_SHM,                    // particular: SH4A SH share memory region
360 *                   // PRAMFS NOTE:ROM only
361 *                   EL_MEM_ID_PRAMFS_ALL = 0x5001,         // all PRAMFS region
362 *                   // STARTUPBGM
363 *                   EL_MEM_ID_STARTUPBGM_ALL = 0x6001,     // all STARTUPBGM region
364 *                   // NAVI (Image Recognition)
365 *                   EL_MEM_ID_NAVI_IR_ALL = 0x7001,        // all NAVI picture recognition region
366 *        };
367 *            @endcode
368 * \~english @retval physical address Success
369 * \~english @retval 0 Error: Failed to open device file or get physical address(ioctl)
370 * \~english @retval -1 Error: Parameter mem_id is not defined.
371 * \~english @par Prerequisite
372 *        - None.
373 * \~english @par Change of internal state
374 *        - Change of internal state according to the API does not occur.
375 * \~english @par Conditions of processing failure
376 *        - Parameter mem_id is not defined.[-1]
377 *        - Get physical address error.[0]
378 * \~english @par Detail
379 *        - Get physical address from dummy-memory driver according to device file specified by mem_id.
380 *        - Return the sum value of physical address and offset specified by mem_id.
381 * \~english @par Classification
382 *        Public
383 * \~english @par Type
384 *        Sync
385 * \~english @see none
386 */
387 u_int64_t EL_mem_getPhysicalAddress(int mem_id);  // NOLINT [readability/naming]
388
389 #ifdef __cplusplus
390 }
391 #endif  // __cplusplus
392
393 /** @}*/  // end of memory_gpio_access_library
394 /** @}*/  // end of native_service
395 /** @}*/  // end of BaseSystem
396 #endif  // MEMORY_GPIO_ACCESS_LIBRARY_CLIENT_INCLUDE_NATIVE_SERVICE_EL_MEM_H_