1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
32 33 34 35
36
37 package ti.sdo.ipc;
38
39 import xdc.runtime.Error;
40 import xdc.runtime.Assert;
41 import xdc.runtime.IGateProvider;
42 import xdc.runtime.Log;
43 import xdc.runtime.Diags;
44
45 import ti.sdo.utils.NameServer;
46 import ti.sdo.ipc.interfaces.IGateMPSupport;
47
48 /*!
49 * ======== GateMP ========
50 * Multiple processor gate that provides local and remote context protection.
51 *
52 * @p(html)
53 * This module has a common header that can be found in the {@link ti.ipc}
54 * package. Application code should include the common header file (not the
55 * RTSC-generated one):
56 *
57 * <PRE>#include <ti/ipc/GateMP.h></PRE>
58 *
59 * The RTSC module must be used in the application's RTSC configuration file
60 * (.cfg) if runtime APIs will be used in the application:
61 *
62 * <PRE>GateMP = xdc.useModule('ti.sdo.ipc.GateMP');</PRE>
63 *
64 * Documentation for all runtime APIs, instance configuration parameters,
65 * error codes macros and type definitions available to the application
66 * integrator can be found in the
67 * <A HREF="../../../../doxygen/html/files.html">Doxygen documenation</A>
68 * for the IPC product. However, the documentation presented on this page
69 * should be referred to for information specific to the RTSC module, such as
70 * module configuration, Errors, and Asserts.
71 * @p
72 */
73
74 @InstanceInitError
75 @InstanceFinalize
76
77 module GateMP
78 {
79 /*!
80 * ======== BasicView ========
81 * @_nodoc
82 */
83 metaonly struct BasicView {
84 String name;
85 String remoteProtect;
86 String remoteStatus;
87 String localProtect;
88 UInt numOpens;
89 Bits32 resourceId;
90 UInt creatorProcId;
91 String objType;
92 }
93
94 /*!
95 * ======== ModuleView ========
96 * @_nodoc
97 */
98 metaonly struct ModuleView {
99 UInt numGatesSystem;
100 UInt numUsedSystem;
101 UInt numGatesCustom1;
102 UInt numUsedCustom1;
103 UInt numGatesCustom2;
104 UInt numUsedCustom2;
105 }
106
107 /*!
108 * ======== rovViewInfo ========
109 * @_nodoc
110 */
111 @Facet
112 metaonly config xdc.rov.ViewInfo.Instance rovViewInfo =
113 xdc.rov.ViewInfo.create({
114 viewMap: [
115 ['Basic',
116 {
117 type: xdc.rov.ViewInfo.INSTANCE,
118 viewInitFxn: 'viewInitBasic',
119 structName: 'BasicView'
120 }
121 ],
122 ['Gate Resources',
123 {
124 type: xdc.rov.ViewInfo.MODULE,
125 viewInitFxn: 'viewInitModule',
126 structName: 'ModuleView'
127 }
128 ]
129 ]
130 });
131
132 /*!
133 * ======== Reserved space at the top of SharedRegion0 ========
134 */
135 struct Reserved {
136 Bits32 version;
137 };
138
139 /*!
140 * ======== E_gateUnavailable ========
141 * Error raised no gates of the requested type are available
142 */
143 config Error.Id E_gateUnavailable = {
144 msg: "E_gateUnavailable: No gates of requested type are available"
145 };
146
147 /*!
148 * ======== E_localGate ========
149 * Error raised when remote side tried to open local gate
150 */
151 config Error.Id E_localGate = {
152 msg: "E_localGate: Only creator can open local Gate"
153 };
154
155 /*!
156 * Assert raised when calling GateMP_close with the wrong handle
157 */
158 config Assert.Id A_invalidClose = {
159 msg: "A_invalidContext: Calling GateMP_close with the wrong handle"
160 };
161
162 /*!
163 * Assert raised when calling GateMP_delete incorrectly
164 */
165 config Assert.Id A_invalidDelete = {
166 msg: "A_invalidDelete: Calling GateMP_delete incorrectly"
167 };
168
169 /*!
170 * ======== LM_enter ========
171 * Logged on gate enter
172 */
173 config Log.Event LM_enter = {
174 mask: Diags.USER1,
175 msg: "LM_enter: Gate (remoteGate = %d, resourceId = %d) entered, returning key = %d"
176 };
177
178 /*!
179 * ======== LM_leave ========
180 * Logged on gate leave
181 */
182 config Log.Event LM_leave = {
183 mask: Diags.USER1,
184 msg: "LM_leave: Gate (remoteGate = %d, resourceId = %d) left using key = %d"
185 };
186
187 /*!
188 * ======== LM_create ========
189 * Logged on gate create
190 */
191 config Log.Event LM_create = {
192 mask: Diags.USER1,
193 msg: "LM_create: Gate (remoteGate = %d, resourceId = %d) created"
194 };
195
196 /*!
197 * ======== LM_open ========
198 * Logged on gate open
199 */
200 config Log.Event LM_open = {
201 mask: Diags.USER1,
202 msg: "LM_open: Remote gate (remoteGate = %d, resourceId = %d) opened"
203 };
204
205 /*!
206 * ======== LM_delete ========
207 * Logged on gate deletion
208 */
209 config Log.Event LM_delete = {
210 mask: Diags.USER1,
211 msg: "LM_delete: Gate (remoteGate = %d, resourceId = %d) deleted"
212 };
213
214 /*!
215 * ======== LM_close ========
216 * Logged on gate close
217 */
218 config Log.Event LM_close = {
219 mask: Diags.USER1,
220 msg: "LM_close: Gate (remoteGate = %d, resourceId = %d) closed"
221 };
222
223 /*!
224 * A set of local context protection levels
225 *
226 * Each member corresponds to a specific local processor gates used for
227 * local protection.
228 *
229 * For SYS/BIOS users, the following are the mappings for the constants
230 * @p(blist)
231 * -INTERRUPT -> GateAll: disables interrupts
232 * -TASKLET -> GateSwi: disables Swis (software interrupts)
233 * -THREAD -> GateMutexPri: based on Semaphores
234 * -PROCESS -> GateMutexPri: based on Semaphores
235 * @p
236 */
237 enum LocalProtect {
238 LocalProtect_NONE = 0,
239 LocalProtect_INTERRUPT = 1,
240 LocalProtect_TASKLET = 2,
241 LocalProtect_THREAD = 3,
242 LocalProtect_PROCESS = 4
243 };
244
245 /*!
246 * Type of remote Gate
247 *
248 * Each member corresponds to a specific type of remote gate.
249 * Each enum value corresponds to the following remote protection levels:
250 * @p(blist)
251 * -NONE -> No remote protection (the GateMP instance will exclusively
252 * offer local protection configured in {@link #localProtect})
253 * -SYSTEM -> Use the SYSTEM remote protection level (default for remote
254 * protection
255 * -CUSTOM1 -> Use the CUSTOM1 remote protection level
256 * -CUSTOM2 -> Use the CUSTOM2 remote protection level
257 * @p
258 */
259 enum RemoteProtect {
260 RemoteProtect_NONE = 0,
261 RemoteProtect_SYSTEM = 1,
262 RemoteProtect_CUSTOM1 = 2,
263 RemoteProtect_CUSTOM2 = 3
264 };
265
266 /*!
267 * ======== maxRuntimeEntries ========
268 * Maximum runtime entries
269 *
270 * Maximum number of GateMP's that can be dynamically created and
271 * added to the NameServer.
272 *
273 * To minimize the amount of runtime allocation, this parameter allows
274 * the pre-allocation of memory for the GateMP's NameServer table.
275 * The default is to allow growth (i.e. memory allocation when
276 * creating a new instance).
277 */
278 metaonly config UInt maxRuntimeEntries = NameServer.ALLOWGROWTH;
279
280 /*!
281 * ======== maxNameLen ========
282 * Maximum length for names
283 */
284 config UInt maxNameLen = 32;
285
286 /*!
287 * ======== tableSection ========
288 * Section name is used to place the names table
289 */
290 metaonly config String tableSection = null;
291
292 /*!
293 * ======== remoteSystemProxy ========
294 * System remote gate proxy
295 *
296 * By default, GateMP instances use the 'System' proxy for locking between
297 * multiple processors by setting the 'localProtect' setting to . This
298 * remote gate proxy defaults to a device-specific remote GateMP delegate
299 * and typically should not be modified.
300 */
301 proxy RemoteSystemProxy inherits IGateMPSupport;
302
303 /*!
304 * ======== remoteCustom1Proxy ========
305 * Custom1 remote gate proxy
306 *
307 * GateMP instances may use the 'Custom1' proxy for locking between
308 * multiple processors. This proxy defaults to
309 * {@link ti.sdo.ipc.gates.GatePeterson}.
310 */
311 proxy RemoteCustom1Proxy inherits IGateMPSupport;
312
313 /*!
314 * ======== remoteCustom2Proxy ========
315 * Custom2 remote gate proxy
316 *
317 * GateMP instances may use the 'Custom2' proxy for locking between
318 * multiple processors. This proxy defaults to
319 * {@link ti.sdo.ipc.gates.GateMPSupportNull}.
320 */
321 proxy RemoteCustom2Proxy inherits IGateMPSupport;
322
323 /*!
324 * ======== createLocal ========
325 * @_nodoc
326 * Get a local IGateProvider instance
327 *
328 * This function is designed to be used by the IGateMPSupport modules
329 * to get a local Gate easily.
330 */
331 IGateProvider.Handle createLocal(LocalProtect localProtect);
332
333 /*! @_nodoc
334 * ======== attach ========
335 */
336 Int attach(UInt16 remoteProcId, Ptr sharedAddr);
337
338 /*! @_nodoc
339 * ======== detach ========
340 */
341 Int detach(UInt16 remoteProcId);
342
343 /*!
344 * ======== getRegion0ReservedSize ========
345 * @_nodoc
346 * Amount of shared memory to be reserved for GateMP in region 0.
347 */
348 SizeT getRegion0ReservedSize();
349
350 /*!
351 * ======== setRegion0Reserved ========
352 * @_nodoc
353 * Set and initialize GateMP reserved memory in Region 0.
354 */
355 Void setRegion0Reserved(Ptr sharedAddr);
356
357 /*!
358 * ======== openRegion0Reserved ========
359 * @_nodoc
360 * Open shared memory reserved for GateP in region 0.
361 */
362 Void openRegion0Reserved(Ptr sharedAddr);
363
364 /*!
365 * ======== setDefaultRemote ========
366 * @_nodoc
367 * Set the default Remote Gate. Called by SharedRegion_start().
368 */
369 Void setDefaultRemote(Handle handle);
370
371 /*! @_nodoc
372 * ======== start ========
373 */
374 Int start(Ptr sharedAddr);
375
376 /*! @_nodoc
377 * ======== stop ========
378 */
379 Int stop();
380
381 instance:
382
383 /*!
384 * ======== name ========
385 * Name of the instance
386 *
387 * Name needs to be unique. Used only if {@link #useNameServer}
388 * is set to TRUE.
389 */
390 config String name = null;
391
392 /*! @_nodoc
393 * Set to true by the open() call. No one else should touch this!
394 */
395 config Bool openFlag = false;
396
397 /*! @_nodoc
398 * Set by the open() call. No one else should touch this!
399 */
400 config Bits32 resourceId = 0;
401
402 /*!
403 * Shared Region Id
404 *
405 * The ID corresponding to the shared region in which this shared instance
406 * is to be placed.
407 */
408 config UInt16 regionId = 0;
409
410 /*!
411 * ======== sharedAddr ========
412 * Physical address of the shared memory
413 *
414 * The creator must supply the shared memory that will be used
415 * for maintaining shared state information. This parameter is used
416 * only when {@link #Type} is set to {@link #Type_SHARED}
417 */
418 config Ptr sharedAddr = null;
419
420 /*!
421 * ======== localProtect ========
422 */
423 config LocalProtect localProtect = LocalProtect_THREAD;
424
425 /*!
426 * ======== localProtect ========
427 */
428 config RemoteProtect remoteProtect = RemoteProtect_SYSTEM;
429
430 /*!
431 * ======== getSharedAddr ========
432 * @_nodoc
433 * Return the SRPtr that points to a GateMP instance's shared memory
434 *
435 * getSharedAddr is typically used internally by other IPC modules to save
436 * the shared address to a GateMP instance in the other modules' shared
437 * state. This allows the other module's open() call to open the GateMP
438 * instance by address.
439 */
440 SharedRegion.SRPtr getSharedAddr();
441
442 internal:
443 const UInt32 VERSION = 1;
444 const UInt32 CREATED = 0x11202009;
445
446 const Int ProxyOrder_SYSTEM = 0;
447 const Int ProxyOrder_CUSTOM1 = 1;
448 const Int ProxyOrder_CUSTOM2 = 2;
449 const Int ProxyOrder_NUM = 3;
450
451 /*!
452 * ======== nameSrvPrms ========
453 * This Params object is used for temporary storage of the
454 * module wide parameters that are for setting the NameServer instance.
455 */
456 metaonly config NameServer.Params nameSrvPrms;
457
458 UInt getFreeResource(UInt8 *inUse, Int num, Error.Block *eb);
459
460 struct LocalGate {
461 IGateProvider.Handle localGate;
462 Int refCount;
463 }
464
465
466 struct Attrs {
467 Bits16 mask;
468 Bits16 creatorProcId;
469 Bits32 arg;
470 Bits32 status;
471 };
472
473 struct Instance_State {
474 RemoteProtect remoteProtect;
475 LocalProtect localProtect;
476 Ptr nsKey;
477 Int numOpens;
478 Bool cacheEnabled;
479 Attrs *attrs;
480 UInt16 regionId;
481 SizeT allocSize;
482 Ipc.ObjType objType;
483 Ptr proxyAttrs;
484 UInt resourceId;
485 IGateProvider.Handle gateHandle;
486 };
487
488 struct Module_State {
489 NameServer.Handle nameServer;
490 Int numRemoteSystem;
491 Int numRemoteCustom1;
492 Int numRemoteCustom2;
493 UInt8 remoteSystemInUse[];
494 UInt8 remoteCustom1InUse[];
495 UInt8 remoteCustom2InUse[];
496 Handle remoteSystemGates[];
497 Handle remoteCustom1Gates[];
498 Handle remoteCustom2Gates[];
499 IGateProvider.Handle gateAll;
500 IGateProvider.Handle gateSwi;
501 IGateProvider.Handle gateMutexPri;
502 IGateProvider.Handle gateNull;
503 Handle defaultGate;
504 Int proxyMap[ProxyOrder_NUM];
505 };
506 }
507 508 509 510
511