comparison src/cs/riviera/rvf/rvf_i.h @ 0:4e78acac3d88

src/{condat,cs,gpf,nucleus}: import from Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:23:26 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4e78acac3d88
1 /****************************************************************************/
2 /* */
3 /* Name rvf_i.h */
4 /* */
5 /* Function this file contains rvf private definitions */
6 /* */
7 /* Version 0.4 */
8 /* */
9 /* Date Modification */
10 /* ------------------------------------ */
11 /* 3/12/99 Create */
12 /* 30/11/99 compliant to RV coding guidelines */
13 /* 12/23/1999 change buffer structures, add memory bank related structures*/
14 /* 02/21/2000 change memory bank implementation. */
15 /* 12/07/2000 implement dynamic memory allocation. */
16 /* */
17 /* Author David Lamy-Charrier (dlamy@tif.ti.com) */
18 /* */
19 /* (C) Copyright 1999 by Texas Instruments Incorporated, All Rights Reserved*/
20 /****************************************************************************/
21
22
23 #ifndef _RVF_I_H
24 #define _RVF_I_H
25
26
27 #include "rv/general.h"
28 #include "rvf/rvf_api.h"
29 #include "nucleus.h" /* A-M-E-N-D-E-D! */
30 #include "rvm/rvm_i.h"
31
32 /********************************************************************/
33 /** Buffer Management Data Structures **/
34 /********************************************************************/
35 #define MAX_RVF_G_ADDR_ID 200
36
37
38 /* define the OVERHEAD per buffer */
39 #if RVF_ENABLE_BUF_CORRUPTION_CHECK
40 #define RVF_CORRUPT_OVERHEAD (sizeof(UINT32))
41 BOOLEAN _rvf_chk_buf_damage(void *bptr);
42 #else
43 #define RVF_CORRUPT_OVERHEAD 0
44 #endif
45 /* calculate the size required in bytes, add the overhead for buffer corruption and round up to a multiple of 4 */
46 #define REQ2SIZE(size) ( ((size) + 3 + RVF_CORRUPT_OVERHEAD) & ~0x00000003)
47
48
49 #define RVF_MIN_USABLE_SIZE ( sizeof(T_RVF_INTERNAL_BUF) + sizeof(UINT32) )
50
51 /* macros to get the internal header from the user pointer and vice-versa */
52 #define USER2MEM(buf) ( (T_RVF_INTERNAL_BUF*)(((UINT8*)(buf)) - sizeof(T_RVF_INTERNAL_BUF) ) )
53 #define MEM2USER(buf) ( ((UINT8*)(buf)) + sizeof(T_RVF_INTERNAL_BUF) )
54
55
56 /* NOTE: since buffer size is always a multiple of 4, the last 2 bits may be used for flags */
57
58 #define GETSIZE(hdr) ((UINT32)(hdr->buf_size & ~0x03) )
59
60 /* macros to manage if buffers are linked or not */
61 #define RVF_BUF_IS_LINKED(hdr) (0x00000001 & hdr->buf_size)
62 #define RVF_SET_BUF_LINKED(hdr) ( (hdr)->buf_size |= 0x00000001)
63
64 #define RVF_BUF_IS_UNLINKED(hdr) (!(RVF_BUF_IS_LINKED(hdr)) )
65 #define RVF_SET_BUF_UNLINKED(hdr) ( (hdr)->buf_size &= ~0x00000001)
66
67
68 /* macros to set and check the usage of the previous buffer */
69 #define RVF_IS_PREV_IN_USE(hdr) (0x00000002 & hdr->buf_size)
70 #define RVF_SET_PREV_IN_USE(hdr) ( (hdr)->buf_size |= 0x00000002)
71
72 #define RVF_IS_PREV_FREE(hdr) (!(RVF_IS_PREV_IN_USE(hdr)) )
73 #define RVF_SET_PREV_FREE(hdr) ( (hdr)->buf_size &= ~0x00000002)
74
75
76 #define SETSIZE(hdr, size) { (hdr)->buf_size &= 0x03;\
77 (hdr)->buf_size |= (size); }
78
79
80
81 #define NEXTCHUNK(hdr) ( (T_RVF_INTERNAL_BUF *)( (UINT8*)hdr + GETSIZE(hdr) + sizeof(T_RVF_INTERNAL_BUF) ) )
82
83 #define ENDSIZE(hdr) ( ((T_RVF_INTERNAL_BUF*)( (UINT8*)hdr + GETSIZE(hdr) + sizeof(T_RVF_INTERNAL_BUF) - sizeof(UINT32) ))->buf_size )
84
85
86 #define RVF_NB_FREE_LISTS 32
87 /* macro used to get the list index from the buffer size */
88 /* 32 lists : 8 lists for buffer < 256 all spaced 32 bytes apart,
89 8 lists for buffer < 1280 all spaced 128 bytes apart,
90 8 lists for buffer < 5376 all spaced 512 bytes apart,
91 8 lists for buffer > 5376 all spaced 16384 bytes apart.*/
92
93 #define RVF_BUF_LIST_INDEX(size) ( ((size) < 256 ) ? ( (UINT8)((size)>>5) ) :\
94 ( ((size) < 1280 ) ? ((UINT8)(8 + ((size-256)>>7) ) ) :\
95 ( ((size) < 5376) ? ((UINT8)(16 + ((size-1280)>>9) ) ) :\
96 ( ((size) < 136448)? ((UINT8)(24 + ((size-5376)>>14) ) ): (UINT8)(31) ) ) ) )
97
98 /* internal buffer structure */
99 typedef struct _t_internal_buf
100 { UINT32 buf_size; /* size of the user buffer */
101 struct _t_internal_buf * p_next; /* pointer to the next buffer in the queue */
102
103 union header
104 { struct external
105 { UINT16 mb_id; /* id of the memory bank which owns the buffer */
106 UINT16 mb_expected; /* id of the memory bank on which the buffer want to be counted */
107 }external;
108
109 struct _t_internal_buf * p_prev; /* pointer to the previous buffer in the queue */
110 }header;
111
112
113 } T_RVF_INTERNAL_BUF;
114
115
116
117
118
119 /* RVF will managed at most 2 pools of memory for dynamic allocation */
120 /* buffer pool structure*/
121 typedef struct _t_rvf_pool
122 {
123 void * start_address; /* address of the beginnig of the pool */
124 UINT32 pool_size; /* total size of the pool */
125 } T_RVF_POOL;
126
127
128
129
130 /* memory bank structure */
131 typedef struct _t_rvf_mb
132 { UINT32 cur_memory_used; /* size of current memory usage */
133 UINT32 watermark; /* watermark */
134 UINT32 max; /* max size */
135 MB_CALLBACK_FUNC func; /* function to call when mb_state switch to GREEN */
136 BOOLEAN returned_red; /* flag indicating that this memory bank returned a RED value, */
137 /* its callback function has to be called and/or buffer are waiting */
138 UINT16 first_buffer_index; /* index of the first waiting buffer in the array */
139 UINT16 last_buffer_index; /* index of the last waiting buffer in the array */
140 #if RVF_ENABLE_STATS
141 UINT32 max_reached; /* maximum memory usage reached */
142 UINT32 required_size; /* total size in byte required by the rvf_get_buf function */
143 UINT32 num_buf; /* total number of buffer allocated by rvf_get_buf function */
144 #endif
145
146 } T_RVF_MB;
147
148
149 /* structure which associates mb name and mb id */
150 typedef struct _t_rvf_mb_name_id
151 { char mb_name[RVF_MAX_MB_LEN]; /* name of the memory bank */
152 UINT16 mb_id; /* id of the memory bank */
153 T_RVF_MB_PARAM mb_params; /* parameters of the memory bank */
154 } T_RVF_MB_NAME_ID;
155
156
157 /* note:
158 * - hosting_list overhead is reduced with an 8 bit addr id
159 * - is hosting_list needed? would known_swe struct be enough to derive all info? */
160 typedef struct _rvf_rt_addr_id_data { /* A-M-E-N-D-E-D! */
161 UINT8 type_code; /* poss. derived? */
162 UINT8 priority;
163 T_RVF_G_ADDR_ID host_addr_id; /* Poss. union: JavaRef-32b or addrId-16 */
164 UINT8 hosting_count;
165 T_RVF_G_ADDR_ID parasites[MAX_PARASITES];
166 UINT8 swe_db_index;
167 char* symbolic_name;
168 NU_TASK* pOSTCB;
169 NU_EVENT_GROUP* pOSEvtGrp;
170 UINT8* p_os_stack;
171 UINT16 os_stack_size;
172 T_RVF_G_ADDR_ID virtualContext;
173 UINT8 gdHost;
174 T_RVF_INTERNAL_BUF* OSTaskQFirst[RVF_NUM_TASK_MBOX];
175 T_RVF_INTERNAL_BUF* OSTaskQLast [RVF_NUM_TASK_MBOX];
176 T_RV_RET (* handle_message) (T_RV_HDR * msg); // note: T_RV_RETURN and not T_RVM...
177 T_RV_RET (* handle_timer) (T_RV_HDR * msg);
178 } T_RVF_RT_ADDR_ID_DATA;
179
180 typedef struct _rvf_tm_attrib {
181 T_RVF_G_ADDR_ID host_addr_id;
182 UINT8 legacyFlag;
183 void* action;
184 } T_RVF_TM_ATTRIB;
185
186 typedef NU_TIMER T_RV_TM;
187
188 typedef union _rvf_tm_ublk {
189 T_RV_TM* ptr;
190 UINT32 id;
191
192 } T_RVF_TM_UBLK;
193
194 typedef union _rvf_tm_attib {
195 char str[8];
196 T_RVF_TM_ATTRIB attrib;
197 } T_RVF_TM_ATTRIB_UBLK;
198
199 typedef union _rvf_tm_action {
200 UINT32 action_id;
201 void* p_action;
202 } T_RVF_TM_ACTION_UBLK;
203
204 #ifdef __cplusplus
205 extern "C" {
206 #endif
207
208 T_RVF_RET rvf_send_priority_msg (T_RVF_G_ADDR_ID addr_id, void *msg) ;
209 T_RVF_RET rvf_adapt_send_msg (T_RVF_G_ADDR_ID addr_id, void *msg, UINT8 mbox) ;
210
211 void rvf_yield();
212
213 void rvf_mbox_buffer_init(T_RVF_RT_ADDR_ID_DATA* pRtAddrIdElement);
214 void _rvf_buffer_init (void);
215 void _rvf_timers_init(void);
216 T_RVF_RET rvf_get_available_mem( UINT32 * total_size, UINT32 * used_size );
217 T_RV_RET _rvf_empty_mailboxes (T_RVF_G_ADDR_ID task_id);
218
219 void _rvf_init_mem_pool(void);
220 void _rvf_init_free_queue (UINT8 id, UINT32 size, void *p_mem);
221 UINT16 _rvf_get_mem_usage_ratio(void);
222 UINT16 _rvf_get_number_of_pool(void);
223 #ifdef _WINDOWS
224 void _rvf_window_dump_mem(void *m);
225 #endif
226
227
228 T_RVF_RET rvf_free_sys_resources(T_RVF_G_ADDR_ID gid, UINT8 rm);
229 T_RVF_G_ADDR_ID rvf_allocate_task_id(UINT8 isRealTask) ; /* return should be changed to 16 or 32 bit val */
230 T_RVF_RET rvf_setRtAddrSweIndex(T_RVF_G_ADDR_ID id, UINT8 sweIndex);
231 T_RVF_G_ADDR_ID resolveHostAddrId(T_RVF_G_ADDR_ID id) ;
232 T_RVF_RET rvf_create_virtual_task(T_RV_RET (* handle_message)(T_RV_HDR * msg),
233 T_RV_RET (* handle_timer)(T_RV_HDR * msg),
234 T_RVF_G_ADDR_ID task_id, T_RVF_G_ADDR_ID host_task_id, char *taskname, UINT8 priority, UINT8 tcode) ;
235 T_RVF_RET rvf_register_t3_handlers (T_RVF_G_ADDR_ID task_id,
236 T_RV_RET (* handle_message)(T_RV_HDR * msg),
237 T_RV_RET (* handle_timer)(T_RV_HDR * msg) ) ;
238 T_RVF_RET rvf_create_host_task (T_RV_RET (* proxy)(void), T_RVF_G_ADDR_ID task_id, char *taskname, UINT8 *stack, UINT16 stacksize,\
239 UINT8 priority, UINT8 tcode, UINT8 time_slicing, T_RVF_TASK_STATE suspend);
240 T_RVF_RET rvf_registerToHost(T_RVF_G_ADDR_ID host_id, T_RVF_G_ADDR_ID eid) ;
241 T_RVF_RET rvf_unregisterFromHost(T_RVF_G_ADDR_ID host_id, T_RVF_G_ADDR_ID pid) ;
242 T_RVF_RET rvf_setHostTaskStackPtr(T_RVF_G_ADDR_ID id, UINT8* pStack) ;
243
244 T_RVF_G_ADDR_ID rvf_resolveHostingAddrId(T_RVM_GROUP_DIRECTIVE gd);
245 T_RVF_RET rvf_associateGrpToHost(T_RVF_G_ADDR_ID host_id, T_RVF_GD_ID gd_id);
246 T_RVF_RET rvf_isHostingTaskIdle(T_RVF_G_ADDR_ID id, UINT8* status);
247 void rvf_setRDV(T_RVF_G_ADDR_ID tid,T_RVF_G_ADDR_ID vid);
248
249 /* Internal RVF data structures*/
250
251 extern T_RVF_INTERNAL_BUF *OSTaskQFirst[1][1]; //MAX_RVF_TASKS][RVF_NUM_TASK_MBOX];
252 extern T_RVF_INTERNAL_BUF *OSTaskQLast[1][1]; //[MAX_RVF_TASKS][RVF_NUM_TASK_MBOX];
253
254 extern T_RVF_RT_ADDR_ID_DATA* pRtAddrIdTable[MAX_RVF_G_ADDR_ID];
255
256
257
258 #ifdef __cplusplus
259 }
260 #endif
261
262 #endif /* _RVF_I_H */