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
38 package ti.sysbios.family.c66.tci66xx;
39
40 import xdc.runtime.Error;
41
42 /*!
43 * ======== CpIntc ========
44 * Common Platform Interrupt Controller Manager
45 *
46 * This module manages the CP_INTC hardware. This module supports enabling
47 * and disabling of both system and host interrupts. This module also
48 * supports mapping system interrupts to host interrupts and host interrupts
49 * to Hwis or to the EventCombiner. These functionality are supported
50 * statically and during runtime for CP_INTCs connected to the GEM interrupt
51 * controller but only during runtime for other CP_INTCs. There is a dispatch
52 * function for handling GEM hardware interrupts triggered by a system
53 * interrupt. The Global Enable Register is enabled by default in the module
54 * startup function.
55 *
56 * System interrupts are those interrupts generated by a hardware module
57 * in the system. These interrupts are inputs into CP_INTC.
58 * Host interrupts are the output interrupts of CP_INTC.
59 * There is a one-to-one mapping between channels and host interrupts
60 * therefore, the term "host interrupt" is also used for channels.
61 *
62 * This modules does not support prioritization, nesting, and vectorization.
63 *
64 * An example of using CpIntc during runtime to plug the ISR handler for
65 * System interrupt 15 mapped to Host interrupt 8 on Hwi 7.
66 *
67 * @p(code)
68 *
69 * Int eventId;
70 * Hwi_Params params;
71 * Error_Block eb;
72 *
73 * // Initialize the error block
74 * Error_init(&eb);
75 *
76 * // Map system interrupt 15 to host interrupt 8 on Intc 0
77 * CpIntc_mapSysIntToHostInt(0, 15, 8);
78 *
79 * // Plug the function and argument for System interrupt 15 then enable it
80 * CpIntc_dispatchPlug(15, &myEvent15Fxn, 15, TRUE);
81 *
82 * // Enable Host interrupt 8 on Intc 0
83 * CpIntc_enableHostInt(0, 8);
84 *
85 * // Get the eventId associated with Host interrupt 8
86 * eventId = CpIntc_getEventId(8);
87 *
88 * // Initialize the Hwi parameters
89 * Hwi_Params_init(¶ms);
90 *
91 * // Set the eventId associated with the Host Interrupt
92 * params.eventId = eventId;
93 *
94 * // The arg must be set to the Host interrupt
95 * params.arg = 8;
96 *
97 * // Enable the interrupt vector
98 * params.enableInt = TRUE;
99 *
100 * // Create the Hwi on interrupt 7 then specify 'CpIntc_dispatch'
101 * // as the function.
102 * Hwi_create(7, &CpIntc_dispatch, ¶ms, &eb);
103 *
104 * @p
105 *
106 * An example of using CpIntc during runtime to plug the ISR handlers for
107 * System interrupts 33-35 mapped to Host interrupt 1 on Hwi 9
108 * using the EventCombiner.
109 *
110 * @p(code)
111 *
112 * Int i;
113 * Int eventId;
114 * Hwi_Params hwiParams;
115 * Int hostInt, sysInt;
116 * Error_Block eb;
117 *
118 * // Initialize the error block
119 * Error_init(&eb);
120 *
121 * // Map 3 System interrupts (33-35) to a single Host interrupt (1).
122 * sysInt = 33;
123 * hostInt = 1;
124 * for (i = 0; i < 3; i++) {
125 * // Map System interrupts to the Host interrupt on Intc 0
126 * CpIntc_mapSysIntToHostInt(0, sysInt + i, hostInt);
127 *
128 * // Plug and enable the function and argument for System interrupts
129 * CpIntc_dispatchPlug(sysInt + i, myIsr, sysInt + i, TRUE);
130 * }
131 *
132 * // Enable the Host interrupt on Intc 0
133 * CpIntc_enableHostInt(0, hostInt);
134 *
135 * // Get the eventId associated with the Host interrupt
136 * eventId = CpIntc_getEventId(hostInt);
137 *
138 * // Plug the event associated with Host Interrupt.
139 * // The function must be 'CpIntc_dispatch' and argument 'hostInt'.
140 * EventCombiner_dispatchPlug(eventId, &CpIntc_dispatch, hostInt, TRUE);
141 *
142 * // Initialize the Hwi parameters
143 * Hwi_Params_init(&hwiParams);
144 *
145 * // The eventId must be set to the combined event
146 * hwiParams.eventId = (eventId / 32);
147 *
148 * // The arg must be set to hwiParams.eventId
149 * hwiParams.arg = hwiParams.eventId;
150 *
151 * // Enable the interrupt.
152 * hwiParams.enableInt = TRUE;
153 *
154 * // Create the Hwi on interrupt 9 then specify 'EventCombiner_dispatch'
155 * // as the function.
156 * Hwi_create(9, &EventCombiner_dispatch, &hwiParams, NULL);
157 *
158 * @p
159 *
160 * An example of using CpIntc during static config to plug the ISR handlers
161 * System interrupts 15,16 mapped to Host interrupt 2 on Hwi 4.
162 *
163 * @p(code)
164 *
165 * var CpIntc = xdc.useModule('ti.sysbios.family.c66.tci66xx.CpIntc');
166 * var Hwi = xdc.useModule('ti.sysbios.family.c64p.Hwi');
167 *
168 * CpIntc.sysInts[15].fxn = '&event15Fxn';
169 * CpIntc.sysInts[15].arg = 15;
170 * CpIntc.sysInts[15].hostInt = 2;
171 * CpIntc.sysInts[15].enable = true;
172 *
173 * CpIntc.sysInts[16].fxn = '&event16Fxn';
174 * CpIntc.sysInts[16].arg = 16;
175 * CpIntc.sysInts[16].hostInt = 2;
176 * CpIntc.sysInts[16].enable = true;
177 *
178 * var eventId = CpIntc.getEventIdMeta(2);
179 * params = new Hwi.Params;
180 * params.arg = 2;
181 * params.eventId = eventId;
182 * params.enableInt = 1;
183 * Hwi.create(4, CpIntc.dispatch, params);
184 *
185 * @p
186 *
187 * @p(html)
188 * <h3> Calling Context </h3>
189 * <table border="1" cellpadding="3">
190 * <colgroup span="1"></colgroup> <colgroup span="5" align="center"></colgroup>
191 *
192 * <tr><th> Function </th><th> Hwi </th><th> Swi </th><th> Task </th><th> Main </th><th> Startup </th></tr>
193 * <!-- -->
194 * <tr><td> {@link #clearSysInt} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
195 * <tr><td> {@link #disableAllHostInts} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
196 * <tr><td> {@link #disableHostInt} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
197 * <tr><td> {@link #dispatch} </td><td> Y </td><td> N </td><td> N </td><td> N </td><td> N </td></tr>
198 * <tr><td> {@link #disableHostInt} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
199 * <tr><td> {@link #dispatchPlug} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
200 * <tr><td> {@link #enableAllHostInts} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
201 * <tr><td> {@link #enableHostInt} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
202 * <tr><td> {@link #enableSysInt} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
203 * <tr><td> {@link #getEventId} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
204 * <tr><td> {@link #getHostInt} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
205 * <tr><td> {@link #mapSysIntToHostInt} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
206 * <tr><td> {@link #postSysInt} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
207 * <tr><td colspan="6"> Definitions: <br />
208 * <ul>
209 * <li> <b>Hwi</b>: API is callable from a Hwi thread. </li>
210 * <li> <b>Swi</b>: API is callable from a Swi thread. </li>
211 * <li> <b>Task</b>: API is callable from a Task thread. </li>
212 * <li> <b>Main</b>: API is callable during any of these phases: </li>
213 * <ul>
214 * <li> In your module startup after this module is started (e.g. CpIntc_Module_startupDone() returns TRUE). </li>
215 * <li> During xdc.runtime.Startup.lastFxns. </li>
216 * <li> During main().</li>
217 * <li> During BIOS.startupFxns.</li>
218 * </ul>
219 * <li> <b>Startup</b>: API is callable during any of these phases:</li>
220 * <ul>
221 * <li> During xdc.runtime.Startup.firstFxns.</li>
222 * <li> In your module startup before this module is started (e.g. CpIntc_Module_startupDone() returns FALSE).</li>
223 * </ul>
224 * </ul>
225 * </td></tr>
226 *
227 * </table>
228 * @p
229 */
230
231 @DirectCall
232 @ModuleStartup
233
234 module CpIntc
235 {
236 /*!
237 * ======== SysIntsView ========
238 * @_nodoc
239 */
240 metaonly struct SysIntsView {
241 UInt systemInt ;
242 UInt8 hostInt;
243 String fxn;
244 String arg;
245 Bool enabled;
246 };
247
248 /*!
249 * ======== rovViewInfo ========
250 * @_nodoc
251 */
252 @Facet
253 metaonly config xdc.rov.ViewInfo.Instance rovViewInfo =
254 xdc.rov.ViewInfo.create({
255 viewMap: [
256 ['SysInts',
257 {
258 type: xdc.rov.ViewInfo.MODULE_DATA,
259 viewInitFxn: 'viewInitSystemInts',
260 structName: 'SysIntsView'
261 }
262 ]
263 ]
264 });
265
266 /*! CpIntc dispatcher function type definition. */
267 typedef Void (*FuncPtr)(UArg);
268
269 /*!
270 * Common Platform Interrupt Controller.
271 */
272 struct RegisterMap {
273 UInt32 REV; /*! 0x00 Revision Register */
274 UInt32 CR; /*! 0x04 Control Register */
275 UInt32 RES_08; /*! 0x08 reserved */
276 UInt32 HCR; /*! 0x0C Host Control Register */
277 UInt32 GER; /*! 0x10 Global Enable Register */
278 UInt32 RES_14; /*! 0x14 reserved */
279 UInt32 RES_18; /*! 0x18 reserved */
280 UInt32 GNLR; /*! 0x1C Global Nesting Level Register */
281 UInt32 SISR; /*! 0x20 Status Index Set Register */
282 UInt32 SICR; /*! 0x24 Status Index Clear Register */
283 UInt32 EISR; /*! 0x28 Enable Index Set Register */
284 UInt32 EICR; /*! 0x2C Enable Index Clear Register */
285 UInt32 GWER; /*! 0x30 Global Wakeup Enable Register */
286 UInt32 HIEISR; /*! 0x34 Host Int Enable Index Set Register */
287 UInt32 HIDISR; /*! 0x38 Host Int Disable Index Set Register */
288 UInt32 RES_3C; /*! 0x3C reserved */
289 UInt32 PPR; /*! 0x40 Pacer Prescale Register */
290 UInt32 RES_44; /*! 0x44 reserved */
291 UInt32 RES_48; /*! 0x48 reserved */
292 UInt32 RES_4C; /*! 0x4C reserved */
293 Ptr *VBR; /*! 0x50 Vector Base Register */
294 UInt32 VSR; /*! 0x54 Vector Size Register */
295 Ptr VNR; /*! 0x58 Vector Null Register */
296 UInt32 RES_5C[9]; /*! 0x5C-0x7C reserved */
297 Int32 GPIR; /*! 0x80 Global Prioritized Index Register */
298 Ptr *GPVR; /*! 0x84 Global Prioritized Vector Register */
299 UInt32 RES_88; /*! 0x88 reserved */
300 UInt32 RES_8C; /*! 0x8C reserved */
301 UInt32 GSIER; /*! 0x90 Global Secure Interrupt Enable Register */
302 UInt32 SPIR; /*! 0x94 Secure Prioritized Index Register */
303 UInt32 RES_98[26]; /*! 0x98-0xFC reserved */
304 UInt32 PPMR[64]; /*! 0x100-0x1FC Pacer Parameter/Map Registers */
305 UInt32 SRSR[32]; /*! 0x200-0x27C Status Raw/Set Registers */
306 UInt32 SECR[32]; /*! 0x280-0x2FC Status Enabled/Clear Registers */
307 UInt32 ESR[32]; /*! 0x300-0x37C Enable Set Registers */
308 UInt32 ECR[32]; /*! 0x380-0x3FC Enable Clear Registers */
309 UInt8 CMR[1024]; /*! 0x400-0x7FC Channel Map Registers */
310 UInt8 HIMR[256]; /*! 0x800-0x8FC Host Interrupt Map Registers */
311 UInt32 HIPIR[256]; /*! 0x900-0xCFC Host Interrupt Pri Index Registers */
312 UInt32 PR[32]; /*! 0xD00-0xD7C Polarity Registers */
313 UInt32 TR[32]; /*! 0xD80-0xDFC Type Registers */
314 UInt32 WER[64]; /*! 0xE00-0xEFC Wakeup Enable Registers */
315 UInt32 DSR[64]; /*! 0xF00-0xFFC Debug Select Registers */
316 UInt32 SER[32]; /*! 0x1000-0x107C Secure Enable Registers */
317 UInt32 SDR[32]; /*! 0x1080-0x10FC Secure Disable Registers */
318 UInt32 HINLR[256]; /*! 0x1100-0x14FC Host Interrupt Nesting Level Registers */
319 UInt32 HIER[8]; /*! 0x1500-0x151F Host Interrupt Enable Registers */
320 UInt32 RES1520[56]; /*! 0x1520-0x15FC Reserved */
321 Ptr *HIPVR[256]; /*! 0x1600-0x19FC Host Interrupt Prioritized Vector */
322 UInt32 RES1A00[384];/*! 0x1A00-0x1FFC Reserved */
323 };
324
325 /*!
326 * System Interrupt Object.
327 */
328 metaonly struct SysIntObj {
329 FuncPtr fxn;
330 UArg arg;
331 UInt8 hostInt;
332 Bool enable;
333 };
334
335 /*!
336 * Error raised when an unplug system interrupt is executed.
337 */
338 config Error.Id E_unpluggedSysInt = {
339 msg: "E_unpluggedSysInt: System Interrupt# %d is unplugged"
340 };
341
342 /*!
343 * ======== sysInts ========
344 * Use for configuring the system interrupts.
345 *
346 * During static configuration this array can be used to configure
347 * the function to execute when a system interrupt is triggered,
348 * the arg to the function, the host interrupt to which the system
349 * interrupt is mapped too, and whether to enable the system interrupt.
350 */
351 metaonly config SysIntObj sysInts[];
352
353 /*!
354 * ======== getEventIdMeta ========
355 * Returns the GEM event id associated with the host interrupt
356 *
357 * If no event id is associated with the host interrupt, the value
358 * -1 will be returned.
359 *
360 * @param(hostInt) host interrupt number
361 */
362 metaonly Int getEventIdMeta(UInt hostInt);
363
364 /*!
365 * ======== mapHostIntToEventCombinerMeta ========
366 * Maps the host interrupt to the Event Combiner.
367 *
368 * The GEM event corresponding to the 'hostInt' in the Event Combiner
369 * will be unmask but the event group will not be dispatched.
370 * The Event Combiner function for this event will be set to the
371 * dispatch function and argument set to 'hostInt'.
372 * The event group must be dispatched from the Event Combiner Module.
373 *
374 * @param(hostInt) host interrupt number
375 */
376 metaonly Void mapHostIntToEventCombinerMeta(UInt hostInt);
377
378 /*!
379 * ======== mapHostIntToHwiMeta ========
380 * Maps the host interrupt to a Hwi.
381 *
382 * A Hwi object will be created with the 'hwiNum', the function
383 * set as the dispatch function and argument set to 'hostInt'.
384 *
385 * @param(hostInt) host interrupt number
386 * @param(hwiNum) Hwi number
387 */
388 metaonly Void mapHostIntToHwiMeta(UInt hostInt, UInt hwiNum);
389
390 /*!
391 * ======== clearSystInt ========
392 * Clears the system interrupt.
393 *
394 * Writes the system interrupt number to the System Interrupt
395 * Status Indexed Clear Register.
396 *
397 * @param(id) Cp_Intc number
398 * @param(sysInt) system interrupt number
399 */
400 Void clearSysInt(UInt id, UInt sysInt);
401
402 /*!
403 * ======== disableAllHostInts ========
404 * Disables all host interrupts.
405 *
406 * Writes a 0 to the Global Enable Register. It does not
407 * override the individual host interrupt enable/disable bits.
408 *
409 * @param(id) Cp_Intc number
410 */
411 Void disableAllHostInts(UInt id);
412
413 /*!
414 * ======== disableHostInt ========
415 * Disables the host interrupts.
416 *
417 * Writes the host interrupt number to the Host Interrupt
418 * Enable Index Clear Register.
419 *
420 * @param(id) Cp_Intc number
421 * @param(hostInt) host interrupt number
422 */
423 Void disableHostInt(UInt id, UInt hostInt);
424
425 /*!
426 * ======== disableSysInt ========
427 * Disables the system interrupt.
428 *
429 * Writes the system interrupt number to the System Interrupt
430 * Enable Indexed Clear Register.
431 *
432 * @param(id) Cp_Intc number
433 * @param(sysInt) system interrupt number
434 */
435 Void disableSysInt(UInt id, UInt sysInt);
436
437 /*!
438 * ======== dispatch ========
439 * The Interrupt service routine handler for CP_INTC events.
440 *
441 * It is used internally, but can also be used by the user.
442 *
443 * @param(hostInt) host interrupt number
444 */
445 Void dispatch(UArg hostInt);
446
447 /*!
448 * ======== dispatchPlug ========
449 * Configures a CpIntc ISR dispatch entry.
450 *
451 * Plugs the function and argument for the specified system interrupt.
452 * Also enables the system interrupt if 'unmask' is set to 'true'.
453 * Function does not map the system interrupt to a Hwi interrupt.
454 *
455 * @param(sysInt) system interrupt number
456 * @param(fxn) function
457 * @param(arg) argument to function
458 * @param(unmask) bool to unmask interrupt
459 */
460 Void dispatchPlug(UInt sysInt, FuncPtr fxn, UArg arg, Bool unmask);
461
462 /*!
463 * ======== enableAllHostInts ========
464 * Enables all host interrupts.
465 *
466 * Writes a 1 to the Global Enable Register. It does not
467 * override the individual host interrupt enable/disable bits.
468 *
469 * @param(id) Cp_Intc number
470 */
471 Void enableAllHostInts(UInt id);
472
473 /*!
474 * ======== enableHostInt ========
475 * Enables the host interrupt.
476 *
477 * Writes the host interrupt number to the Host Interrupt
478 * Enable Indexed Set Register.
479 *
480 * @param(id) Cp_Intc number
481 * @param(hostInt) host interrupt number
482 */
483 Void enableHostInt(UInt id, UInt hostInt);
484
485 /*!
486 * ======== enableSysInt ========
487 * Enables the system interrupt.
488 *
489 * Writes the system interrupt number to the System Interrupt
490 * Enable Indexed Set Register.
491 *
492 * @param(id) Cp_Intc number
493 * @param(sysInt) system interrupt number
494 */
495 Void enableSysInt(UInt id, UInt sysInt);
496
497 /*!
498 * ======== getEventId ========
499 * Returns the event id associated with the host interrupt
500 *
501 * If no event id is associated with the host interrupt, the value
502 * -1 will be returned.
503 *
504 * @param(hostInt) host interrupt number
505 */
506 Int getEventId(UInt hostInt);
507
508 /*!
509 * ======== getHostInt ========
510 * Returns the host interrupt associated with the event id
511 *
512 * If no host interrupt is associated with the event id, the value
513 * -1 will be returned.
514 *
515 * @param(eventId) event id
516 */
517 Int getHostInt(UInt eventId);
518
519 /*!
520 * ======== mapSysIntToHostInt ========
521 * Maps a system interrupt to a host interrupt.
522 *
523 * Writes the Channel Map Register to map a system interrupt to a
524 * channel. There is a 1 to 1 mapping between channels and
525 * host interrupts.
526 *
527 * @param(id) Cp_Intc number
528 * @param(sysInt) system interrupt number
529 * @param(hostInt) host interrupt number
530 */
531 Void mapSysIntToHostInt(UInt id, UInt sysInt, UInt hostInt);
532
533 /*!
534 * ======== postSysInt ========
535 * Triggers the system interrupt.
536 *
537 * Writes the system interrupt number to the System Interrupt
538 * Status Index Set Register. Used for diagnostic and test purposes
539 * only.
540 *
541 * @param(id) Cp_Intc number
542 * @param(sysInt) system interrupt number
543 */
544 Void postSysInt(UInt id, UInt sysInt);
545
546 /*!
547 * @_nodoc
548 * ======== unused ========
549 * Unused exists simply to map a call in the Event Combiner dispatcher
550 * calling context to the System_exit calling context (casts UArg to Int)
551 */
552 Void unused(UArg arg);
553
554 internal:
555
556
557 metaonly struct HostIntObj {
558 Int hwiNum;
559 Bool useEventCombiner;
560 };
561
562
563 metaonly config HostIntObj hostInts[];
564
565
566 metaonly config UInt32 baseAddr;
567
568
569 config UInt32 numSysInts;
570
571
572 config UInt32 numEvents;
573
574
575 config Int numStatusRegs;
576
577
578 config UInt16 sysIntToHostInt[];
579
580
581 config UInt8 hostIntToEventId[][];
582
583
584 config UInt8 eventId[];
585
586 struct DispatchTabElem {
587 FuncPtr fxn;
588 UArg arg;
589 };
590
591 struct Module_State {
592 volatile RegisterMap *controller[];
593 Bits32 initSIER[];
594 UInt16 hostIntToSysInt[];
595 DispatchTabElem dispatchTab[];
596 };
597 }