72e60bdc54f9a410e32648c55b411858ddf9de80
1 /*
2 * Copyright (c) 2012-2014 Texas Instruments Incorporated - http://www.ti.com
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
33 /*
34 * ======== NotifySetup.c ========
35 */
36 #include <xdc/std.h>
37 #include <xdc/runtime/Assert.h>
38 #include <xdc/runtime/Error.h>
39 #include <xdc/runtime/Startup.h>
41 #include <ti/sdo/ipc/_Notify.h>
42 #include <ti/sdo/ipc/family/vayu/NotifyDriverMbx.h>
43 #include <ti/sdo/ipc/notifyDrivers/NotifyDriverShm.h>
44 #include <ti/sdo/utils/_MultiProc.h>
46 #if defined(xdc_target__isaCompatible_64P)
48 #include <ti/sysbios/family/c64p/EventCombiner.h>
49 #include <ti/sysbios/family/c64p/Hwi.h>
50 #include <ti/sysbios/family/shared/vayu/IntXbar.h>
52 #elif defined(xdc_target__isaCompatible_arp32)
54 #include <ti/sysbios/family/arp32/Hwi.h>
56 #elif defined(xdc_target__isaCompatible_v7M)
58 #include <ti/sysbios/BIOS.h>
59 #include <ti/sysbios/family/arm/ducati/Core.h>
60 #include <ti/sysbios/family/arm/m3/Hwi.h>
61 #include <ti/sysbios/family/shared/vayu/IntXbar.h>
63 #elif defined(xdc_target__isaCompatible_v7A)
65 #include <ti/sysbios/family/arm/gic/Hwi.h>
66 #include <ti/sysbios/family/shared/vayu/IntXbar.h>
68 #else
69 #error Invalid target
70 #endif
72 #include "package/internal/NotifySetup.xdc.h"
75 #define EVENT_GROUP_SIZE 32
77 /* register access methods */
78 #define REG16(A) (*(volatile UInt16 *)(A))
79 #define REG32(A) (*(volatile UInt32 *)(A))
81 /* ipc helper macros */
82 #define MAILBOX_REG_VAL(m) (0x1 << (2 * (m)))
84 #define VIRTID(procId) (NotifySetup_procIdTable[(procId)])
86 #define MBX_BASEADDR_IDX(idx) ((NotifySetup_mailboxTable[(idx)] >> 16) & 0xFFFF)
88 #define MBX_USER_IDX(idx) ((NotifySetup_mailboxTable[(idx)] >> 8) & 0xFF)
90 #define SUBMBX_IDX(idx) (NotifySetup_mailboxTable[(idx)] & 0xFF)
92 #define MAILBOX_ADDR(idx) \
93 (NotifySetup_mailboxBaseAddr[MBX_BASEADDR_IDX(idx)])
95 #define MAILBOX_STATUS(idx) \
96 (MAILBOX_ADDR((idx)) + 0xC0 + (0x4 * SUBMBX_IDX((idx))))
98 #define MAILBOX_IRQENABLE_SET(idx) \
99 (MAILBOX_ADDR((idx)) + 0x108 + (0x10 * MBX_USER_IDX((idx))))
101 #define MBOX_IRQ_ENABLE(idx) \
102 ((REG32(MAILBOX_IRQENABLE_SET((idx))) & \
103 MAILBOX_REG_VAL(SUBMBX_IDX((idx)))) != 0)
105 #define MBOX_MSG_COUNT(idx) (REG32(MAILBOX_STATUS((idx))))
108 /*
109 *************************************************************************
110 * Module functions
111 *************************************************************************
112 */
114 /*
115 * ======== NotifySetup_Module_startup ========
116 */
117 Int NotifySetup_Module_startup(Int phase)
118 {
119 #if defined(xdc_target__isaCompatible_64P)
121 extern cregister volatile UInt DNUM;
123 if (!IntXbar_Module_startupDone()) {
124 return (Startup_NOTDONE);
125 }
127 /* connect mailbox interrupts at startup */
128 if (DNUM == 0) { /* DSP1 */
129 IntXbar_connect(24, 284); // eve1 mailbox 0 user 1
130 IntXbar_connect(25, 293); // eve2 mailbox 0 user 1
131 IntXbar_connect(26, 249); // system mailbox 5 user 0
132 NotifySetup_module->interruptTable[6] = 57; // IPU1-0
133 NotifySetup_module->interruptTable[9] = 57; // IPU1-1
135 /* plug eve3 and eve4 mbxs only if eve3 and eve4 exists */
136 if ((MultiProc_getId("EVE3") != MultiProc_INVALIDID) ||
137 (MultiProc_getId("EVE4") != MultiProc_INVALIDID)) {
138 IntXbar_connect(27, 302); // eve3 mailbox 0 user 1
139 IntXbar_connect(28, 311); // eve4 mailbox 0 user 1
140 }
142 /* plug mbx7 only if DSP2 or IPU2 exists */
143 if ((MultiProc_getId("DSP2") != MultiProc_INVALIDID) ||
144 (MultiProc_getId("IPU2") != MultiProc_INVALIDID) ||
145 (MultiProc_getId("IPU2-0") != MultiProc_INVALIDID)) {
146 IntXbar_connect(29, 257); // system mailbox 7 user 0
147 NotifySetup_module->interruptTable[7] = 60; // IPU2-0
148 }
150 /* plug mbx8 only if IPU2-1 exists */
151 if (MultiProc_getId("IPU2-1") != MultiProc_INVALIDID) {
152 IntXbar_connect(30, 261); // system mailbox 8 user 0
153 NotifySetup_module->interruptTable[10] = 61; // IPU2-1
154 }
155 }
156 else if (DNUM == 1) { /* DSP2 */
157 IntXbar_connect(24, 287); // eve1 mailbox 1 user 1
158 IntXbar_connect(25, 296); // eve2 mailbox 1 user 1
159 IntXbar_connect(26, 253); // system mailbox 6 user 0
160 NotifySetup_module->interruptTable[7] = 57; // IPU2-0
161 NotifySetup_module->interruptTable[10] = 57; // IPU2-1
163 /* plug eve3 and eve4 mbxs only if eve3 and eve4 exists */
164 if ((MultiProc_getId("EVE3") != MultiProc_INVALIDID) ||
165 (MultiProc_getId("EVE4") != MultiProc_INVALIDID)) {
166 IntXbar_connect(27, 305); // eve3 mailbox 1 user 1
167 IntXbar_connect(28, 314); // eve4 mailbox 1 user 1
168 }
170 /* plug mbx7 only if DSP1 or IPU1 exists */
171 if ((MultiProc_getId("DSP1") != MultiProc_INVALIDID) ||
172 (MultiProc_getId("IPU1") != MultiProc_INVALIDID) ||
173 (MultiProc_getId("IPU1-0") != MultiProc_INVALIDID)) {
174 IntXbar_connect(29, 258); // system mailbox 7 user 1
175 NotifySetup_module->interruptTable[6] = 60; // IPU1-0
176 }
178 /* plug mbx8 only if IPU1-1 exists */
179 if (MultiProc_getId("IPU1-1") != MultiProc_INVALIDID) {
180 IntXbar_connect(30, 262); // system mailbox 8 user 1
181 NotifySetup_module->interruptTable[9] = 61; // IPU1-1
182 }
183 }
185 return (Startup_DONE);
187 #elif defined(xdc_target__isaCompatible_arp32)
189 /* nothing to do on this processor */
190 return (Startup_DONE);
192 #elif defined(xdc_target__isaCompatible_v7M)
194 if (!IntXbar_Module_startupDone()) {
195 return (Startup_NOTDONE);
196 }
198 /* connect mailbox interrupts at startup */
199 if (Core_ipuId == 1) {
200 if ((BIOS_smpEnabled) || (Core_getId() == 0)) {
201 /* IPU1-0 */
202 IntXbar_connect(42, 285); // eve1 mailbox 0 user 2
203 IntXbar_connect(43, 294); // eve2 mailbox 0 user 2
204 IntXbar_connect(44, 250); // system mailbox 5 user 1
206 /* plug eve3 and eve4 mbxs only if eve3 and eve4 exists */
207 if ((MultiProc_getId("EVE3") != MultiProc_INVALIDID) ||
208 (MultiProc_getId("EVE4") != MultiProc_INVALIDID)) {
209 IntXbar_connect(45, 303); // eve3 mailbox 0 user 2
210 IntXbar_connect(46, 312); // eve4 mailbox 0 user 2
211 }
213 /* plug mbx7 only if DSP2, IPU1-1, or IPU2 exists */
214 if ((MultiProc_getId("DSP2") != MultiProc_INVALIDID) ||
215 (MultiProc_getId("IPU1-1") != MultiProc_INVALIDID) ||
216 (MultiProc_getId("IPU2") != MultiProc_INVALIDID) ||
217 (MultiProc_getId("IPU2-0") != MultiProc_INVALIDID)) {
218 IntXbar_connect(47, 259); // system mailbox 7 user 2
219 }
221 /* plug mbx8 only if IPU2-1 exists */
222 if (MultiProc_getId("IPU2-1") != MultiProc_INVALIDID) {
223 IntXbar_connect(48, 263); // system mailbox 8 user 2
224 }
225 }
226 else { /* IPU1-1 */
227 IntXbar_connect(49, 289); // eve1 mailbox 1 user 3
228 IntXbar_connect(50, 298); // eve2 mailbox 1 user 3
229 IntXbar_connect(51, 252); // system mailbox 5 user 3
231 /* plug eve3 and eve4 mbxs only if eve3 and eve4 exists */
232 if ((MultiProc_getId("EVE3") != MultiProc_INVALIDID) ||
233 (MultiProc_getId("EVE4") != MultiProc_INVALIDID)) {
234 IntXbar_connect(52, 307); // eve3 mailbox 1 user 3
235 IntXbar_connect(53, 316); // eve4 mailbox 1 user 3
236 }
238 /* plug mbx8 only if DSP2, IPU1-0, or IPU2 exists */
239 if ((MultiProc_getId("DSP2") != MultiProc_INVALIDID) ||
240 (MultiProc_getId("IPU1-0") != MultiProc_INVALIDID) ||
241 (MultiProc_getId("IPU2") != MultiProc_INVALIDID) ||
242 (MultiProc_getId("IPU2-0") != MultiProc_INVALIDID)) {
243 IntXbar_connect(54, 263); // system mailbox 8 user 2
244 }
245 }
246 }
247 else {
248 if ((BIOS_smpEnabled) || (Core_getId() == 0)) {
249 /* IPU2-0 */
250 IntXbar_connect(42, 288); // eve1 mailbox 1 user 2
251 IntXbar_connect(43, 297); // eve2 mailbox 1 user 2
252 IntXbar_connect(44, 254); // system mailbox 6 user 1
254 /* plug eve3 and eve4 mbxs only if eve3 and eve4 exists */
255 if ((MultiProc_getId("EVE3") != MultiProc_INVALIDID) ||
256 (MultiProc_getId("EVE4") != MultiProc_INVALIDID)) {
257 IntXbar_connect(45, 306); // eve3 mailbox 1 user 2
258 IntXbar_connect(46, 315); // eve4 mailbox 1 user 2
259 }
261 /* plug mbx7 only if DSP1 or IPU1 exists */
262 if ((MultiProc_getId("DSP1") != MultiProc_INVALIDID) ||
263 (MultiProc_getId("IPU1") != MultiProc_INVALIDID) ||
264 (MultiProc_getId("IPU1-0") != MultiProc_INVALIDID)) {
265 IntXbar_connect(47, 260); // system mailbox 7 user 3
266 }
268 /* plug mbx8 only if IPU1-1 exists */
269 if (MultiProc_getId("IPU1-1") != MultiProc_INVALIDID) {
270 IntXbar_connect(48, 264); // system mailbox 8 user 3
271 }
272 }
273 else { /* IPU2-1 */
274 IntXbar_connect(49, 289); // eve1 mailbox 1 user 3
275 IntXbar_connect(50, 298); // eve2 mailbox 1 user 3
276 IntXbar_connect(51, 256); // system mailbox 6 user 3
278 /* plug eve3 and eve4 mbxs only if eve3 and eve4 exists */
279 if ((MultiProc_getId("EVE3") != MultiProc_INVALIDID) ||
280 (MultiProc_getId("EVE4") != MultiProc_INVALIDID)) {
281 IntXbar_connect(52, 307); // eve3 mailbox 1 user 3
282 IntXbar_connect(53, 316); // eve4 mailbox 1 user 3
283 }
285 /* plug mbx8 only if DSP2 or IPU2 exists */
286 if ((MultiProc_getId("DSP1") != MultiProc_INVALIDID) ||
287 (MultiProc_getId("IPU1") != MultiProc_INVALIDID) ||
288 (MultiProc_getId("IPU1-0") != MultiProc_INVALIDID)) {
289 IntXbar_connect(54, 264); // system mailbox 8 user 3
290 }
291 }
292 }
294 return (Startup_DONE);
296 #elif defined(xdc_target__isaCompatible_v7A)
298 if (!IntXbar_Module_startupDone()) {
299 return (Startup_NOTDONE);
300 }
302 /* connect mailbox interrupts at startup */
303 IntXbar_connect(127, 286); // eve1 mailbox 0 user 3
304 IntXbar_connect(128, 295); // eve2 mailbox 0 user 3
305 IntXbar_connect(129, 251); // system mailbox 5 user 2
307 /* plug eve3 and eve4 mbxs only if eve3 and eve4 exists */
308 if ((MultiProc_getId("EVE3") != MultiProc_INVALIDID) ||
309 (MultiProc_getId("EVE4") != MultiProc_INVALIDID)) {
310 IntXbar_connect(130, 304); // eve3 mailbox 0 user 3
311 IntXbar_connect(131, 313); // eve4 mailbox 0 user 3
312 }
314 /* plug mbx6 only if DSP2 or IPU2 exists */
315 if ((MultiProc_getId("DSP2") != MultiProc_INVALIDID) ||
316 (MultiProc_getId("IPU2") != MultiProc_INVALIDID) ||
317 (MultiProc_getId("IPU2-0") != MultiProc_INVALIDID)) {
318 IntXbar_connect(134, 255); // system mailbox 6 user 2
319 }
321 return (Startup_DONE);
323 #else
324 #error Invalid target
325 #endif
326 }
328 /*
329 * ======== NotifySetup_interruptTable ========
330 */
331 UInt16 NotifySetup_interruptTable(Int srcVirtId)
332 {
333 return (NotifySetup_module->interruptTable[srcVirtId]);
334 }
336 /*
337 * ======== NotifySetup_attach ========
338 * Create driver instance specified at config time.
339 *
340 * This functions is generated by the NotifySetup.xdt template.
341 */
343 /*
344 * ======== NotifySetup_sharedMemReq ========
345 * Compute how much shared memory is required by the driver.
346 *
347 * This functions is generated by the NotifySetup.xdt template.
348 */
350 /*
351 * ======== NotifySetup_numIntLines ========
352 * Return number of available interrupt lines to the current processor.
353 */
354 UInt16 NotifySetup_numIntLines(UInt16 remoteProcId)
355 {
356 return (1);
357 }
359 /*
360 * ======== NotifySetup_driverType ========
361 * Find driver type for given connection.
362 *
363 * Search the connection array for the given remote processor. If
364 * found, return the requested notify driver type.
365 */
366 NotifySetup_Driver NotifySetup_driverType(UInt16 remoteProcId)
367 {
368 Int i;
369 NotifySetup_Driver driver = NotifySetup_Driver_SHAREDMEMORY;
371 /* look for remote processor in connection array */
372 for (i = 0; i < NotifySetup_module->connAry.length; i++) {
373 if (remoteProcId == NotifySetup_module->connAry.elem[i].procId) {
374 driver = NotifySetup_module->connAry.elem[i].driver;
375 break;
376 }
377 }
379 return (driver);
380 }
382 /*
383 * ======== NotifySetup_plugHwi ========
384 */
385 Void NotifySetup_plugHwi(UInt16 remoteProcId, Int cpuIntrNum,
386 NotifySetup_DriverIsr isr)
387 {
388 Error_Block eb;
389 UInt key;
390 Hwi_Params hwiParams;
391 UInt16 srcVirtId;
392 #if defined(xdc_target__isaCompatible_64P)
393 Int eventId;
394 UInt combinedEventId;
395 #elif defined(xdc_target__isaCompatible_arp32)
396 UInt mbxIdx;
397 Int eventId;
398 Bits16 mask;
399 #elif defined(xdc_target__isaCompatible_v7M) \
400 || defined(xdc_target__isaCompatible_v7A)
401 UInt16 idx;
402 UInt mbxIdx;
403 #endif
405 Error_init(&eb);
407 /* disable interrupts */
408 key = Hwi_disable();
410 /* map remote processor id to virtual id */
411 srcVirtId = VIRTID(remoteProcId);
413 /* save driver ISR in dispatch table */
414 NotifySetup_module->isrDispatchTable[srcVirtId] = isr;
416 #if defined(xdc_target__isaCompatible_64P)
418 /* program the event dispatcher */
419 eventId = NotifySetup_module->interruptTable[srcVirtId];
420 EventCombiner_dispatchPlug(eventId, NotifySetup_dispatchIsr, eventId, TRUE);
422 /* make sure the interrupt is plugged only once */
423 NotifySetup_module->numPlugged[0]++;
425 if (NotifySetup_module->numPlugged[0] == 1) {
426 combinedEventId = eventId / EVENT_GROUP_SIZE;
428 Hwi_Params_init(&hwiParams);
429 hwiParams.eventId = combinedEventId;
430 hwiParams.arg = combinedEventId;
431 hwiParams.enableInt = TRUE;
433 Hwi_create(cpuIntrNum, &ti_sysbios_family_c64p_EventCombiner_dispatch,
434 &hwiParams, &eb);
435 /* TODO: add error handling */
437 Hwi_enableInterrupt(cpuIntrNum);
438 }
440 #elif defined(xdc_target__isaCompatible_arp32)
442 if ((remoteProcId == NotifySetup_dsp1ProcId) ||
443 (remoteProcId == NotifySetup_ipu1_0ProcId) ||
444 (remoteProcId == NotifySetup_hostProcId)) {
446 mbxIdx = 0;
447 }
448 else if ((remoteProcId == NotifySetup_dsp2ProcId) ||
449 (remoteProcId == NotifySetup_ipu2_0ProcId) ||
450 (remoteProcId == NotifySetup_ipu1_1ProcId) ||
451 (remoteProcId == NotifySetup_ipu2_1ProcId)) {
453 mbxIdx = 1;
454 }
455 else {
456 mbxIdx = 2; /* remote processor must be EVEx */
457 }
459 /* make sure the interrupt is plugged only once */
460 NotifySetup_module->numPlugged[mbxIdx]++;
462 if (NotifySetup_module->numPlugged[mbxIdx] == 1) {
463 eventId = NotifySetup_module->interruptTable[srcVirtId];
465 /* compute the hwi mask */
466 mask = (1 << NotifySetup_eveIntVectId_INTC0)
467 | (1 << NotifySetup_eveIntVectId_INTC1);
469 Hwi_Params_init(&hwiParams);
470 hwiParams.arg = eventId;
471 hwiParams.vectorNum = cpuIntrNum;
472 hwiParams.maskSetting = Hwi_MaskingOption_BITMASK;
473 hwiParams.disableIerMask = mask;
474 hwiParams.restoreIerMask = mask;
476 Hwi_create(eventId, NotifySetup_dispatchIsr, &hwiParams, &eb);
477 /* TODO: add error handling */
479 Hwi_enableInterrupt(NotifySetup_module->interruptTable[srcVirtId]);
480 }
482 #elif defined(xdc_target__isaCompatible_v7M) \
483 || defined(xdc_target__isaCompatible_v7A)
485 /* compute table index for given source and destination */
486 idx = (srcVirtId * NotifySetup_NUM_CORES) + MultiProc_self();
488 /* compute mailbox index */
489 mbxIdx = MBX_BASEADDR_IDX(idx);
491 /* make sure the interrupt is plugged only once */
492 NotifySetup_module->numPlugged[mbxIdx]++;
494 if (NotifySetup_module->numPlugged[mbxIdx] == 1) {
496 Hwi_Params_init(&hwiParams);
497 hwiParams.maskSetting = Hwi_MaskingOption_LOWER;
498 hwiParams.arg = cpuIntrNum;
500 Hwi_create(cpuIntrNum, NotifySetup_dispatchIsr, &hwiParams, &eb);
501 /* TODO: add error handling */
503 Hwi_enableInterrupt(cpuIntrNum);
504 }
506 #else
507 #error Invalid target
508 #endif
510 /* restore interrupts */
511 Hwi_restore(key);
512 }
514 /*
515 * ======== NotifySetup_unplugHwi ========
516 */
517 Void NotifySetup_unplugHwi(UInt16 remoteProcId, Int cpuIntrNum)
518 {
519 UInt key;
520 Hwi_Handle hwi;
521 UInt16 srcVirtId;
522 #if defined(xdc_target__isaCompatible_64P)
523 Int eventId;
524 #elif defined(xdc_target__isaCompatible_arp32)
525 UInt mbxIdx;
526 #elif defined(xdc_target__isaCompatible_v7M) \
527 || defined(xdc_target__isaCompatible_v7A)
528 UInt16 idx;
529 UInt mbxIdx;
530 #endif
532 /* disable global interrupts (TODO: should be a gated module) */
533 key = Hwi_disable();
535 /* map processor id to virtual id */
536 srcVirtId = VIRTID(remoteProcId);
538 /* remove driver isr from dispatch table */
539 NotifySetup_module->isrDispatchTable[srcVirtId] = NULL;
541 #if defined(xdc_target__isaCompatible_64P)
543 /* unplug interrupt if last user */
544 NotifySetup_module->numPlugged[0]--;
546 if (NotifySetup_module->numPlugged[0] == 0) {
547 hwi = Hwi_getHandle(cpuIntrNum);
548 Hwi_delete(&hwi);
549 }
551 /* unprogram the event dispatcher */
552 eventId = NotifySetup_module->interruptTable[srcVirtId];
553 EventCombiner_disableEvent(eventId);
555 #elif defined(xdc_target__isaCompatible_arp32)
557 if ((remoteProcId == NotifySetup_dsp1ProcId) ||
558 (remoteProcId == NotifySetup_ipu1_0ProcId) ||
559 (remoteProcId == NotifySetup_hostProcId)) {
561 mbxIdx = 0;
562 }
563 else if ((remoteProcId == NotifySetup_dsp2ProcId) ||
564 (remoteProcId == NotifySetup_ipu2_0ProcId) ||
565 (remoteProcId == NotifySetup_ipu1_1ProcId) ||
566 (remoteProcId == NotifySetup_ipu2_1ProcId)) {
568 mbxIdx = 1;
569 }
570 else {
571 mbxIdx = 2; /* remote processor must be EVEx */
572 }
574 /* unplug interrupt if last user */
575 NotifySetup_module->numPlugged[mbxIdx]--;
577 if (NotifySetup_module->numPlugged[0] == 0) {
578 hwi = Hwi_getHandle(cpuIntrNum);
579 Hwi_delete(&hwi);
580 }
582 #elif defined(xdc_target__isaCompatible_v7M) \
583 || defined(xdc_target__isaCompatible_v7A)
585 /* decrement plug count */
586 idx = (srcVirtId * NotifySetup_NUM_CORES) + MultiProc_self();
587 mbxIdx = MBX_BASEADDR_IDX(idx);
588 NotifySetup_module->numPlugged[mbxIdx]--;
590 /* unplug interrupt if last user */
591 if (NotifySetup_module->numPlugged[0] == 0) {
592 hwi = Hwi_getHandle(cpuIntrNum);
593 Hwi_delete(&hwi);
594 }
596 #else
597 #error Invalid target
598 #endif
600 /* restore global interrupts */
601 Hwi_restore(key);
602 }
604 /*
605 * ======== NotifySetup_Shm_attach ========
606 */
607 Int NotifySetup_Shm_attach(UInt16 remoteProcId, Ptr sharedAddr)
608 {
609 NotifyDriverShm_Params notifyShmParams;
610 NotifyDriverShm_Handle shmDrvHandle;
611 ti_sdo_ipc_Notify_Handle notifyHandle;
612 Int status = Notify_S_SUCCESS;
613 Error_Block eb;
615 Error_init(&eb);
617 NotifyDriverShm_Params_init(¬ifyShmParams);
618 notifyShmParams.sharedAddr = sharedAddr;
619 notifyShmParams.remoteProcId = remoteProcId;
621 /* Set the intVectorId if on the DSP */
622 if ((MultiProc_self() == NotifySetup_dsp1ProcId) ||
623 (MultiProc_self() == NotifySetup_dsp2ProcId)) {
624 notifyShmParams.intVectorId = NotifySetup_dspIntVectId;
625 }
627 /* Set the intVectorId if on the EVE */
628 if ((MultiProc_self() == NotifySetup_eve1ProcId) ||
629 (MultiProc_self() == NotifySetup_eve2ProcId) ||
630 (MultiProc_self() == NotifySetup_eve3ProcId) ||
631 (MultiProc_self() == NotifySetup_eve4ProcId)) {
633 if (VIRTID(remoteProcId) < 4) {
634 notifyShmParams.intVectorId = NotifySetup_eveIntVectId_INTC1;
635 }
636 else {
637 notifyShmParams.intVectorId = NotifySetup_eveIntVectId_INTC0;
638 }
639 }
641 /* create the notify driver instance */
642 shmDrvHandle = NotifyDriverShm_create(¬ifyShmParams, &eb);
644 if (shmDrvHandle == NULL) {
645 return (Notify_E_FAIL);
646 }
648 /* create the front-end notify instance */
649 notifyHandle = ti_sdo_ipc_Notify_create(
650 NotifyDriverShm_Handle_upCast(shmDrvHandle), remoteProcId, 0,
651 NULL, &eb);
653 if (notifyHandle == NULL) {
654 NotifyDriverShm_delete(&shmDrvHandle);
655 status = Notify_E_FAIL;
656 }
658 return (status);
659 }
661 /*!
662 * ======== NotifySetup_Shm_sharedMemReq ========
663 */
664 SizeT NotifySetup_Shm_sharedMemReq(UInt16 remoteProcId, Ptr sharedAddr)
665 {
666 SizeT memReq;
667 NotifyDriverShm_Params notifyShmParams;
669 NotifyDriverShm_Params_init(¬ifyShmParams);
670 notifyShmParams.sharedAddr = sharedAddr;
672 memReq = NotifyDriverShm_sharedMemReq(¬ifyShmParams);
674 return (memReq);
675 }
677 /*
678 * ======== NotifySetup_Mbx_attach ========
679 */
680 Int NotifySetup_Mbx_attach(UInt16 remoteProcId, Ptr sharedAddr)
681 {
682 Int status = Notify_S_SUCCESS;
683 NotifyDriverMbx_Params params;
684 NotifyDriverMbx_Handle driver;
685 ti_sdo_ipc_Notify_Handle notify;
686 UInt16 virtId;
687 Error_Block eb;
689 Error_init(&eb);
691 NotifyDriverMbx_Params_init(¶ms);
692 params.remoteProcId = remoteProcId;
694 /* set the intVectorId if on the DSP */
695 if ((MultiProc_self() == NotifySetup_dsp1ProcId) ||
696 (MultiProc_self() == NotifySetup_dsp2ProcId)) {
697 params.intVectorId = NotifySetup_dspIntVectId;
698 }
700 /* set the intVectorId if on the EVE */
701 if ((MultiProc_self() == NotifySetup_eve1ProcId) ||
702 (MultiProc_self() == NotifySetup_eve2ProcId) ||
703 (MultiProc_self() == NotifySetup_eve3ProcId) ||
704 (MultiProc_self() == NotifySetup_eve4ProcId)) {
706 if (VIRTID(remoteProcId) < 4) {
707 params.intVectorId = NotifySetup_eveIntVectId_INTC1;
708 }
709 else {
710 params.intVectorId = NotifySetup_eveIntVectId_INTC0;
711 }
712 }
714 /* set the intVectorId if on the IPU */
715 if ((MultiProc_self() == NotifySetup_ipu1_0ProcId) ||
716 (MultiProc_self() == NotifySetup_ipu1_1ProcId) ||
717 (MultiProc_self() == NotifySetup_ipu2_0ProcId) ||
718 (MultiProc_self() == NotifySetup_ipu2_1ProcId)) {
720 virtId = VIRTID(remoteProcId);
721 params.intVectorId = NotifySetup_module->interruptTable[virtId];
722 }
724 /* set the intVectorId if on the HOST */
725 if (MultiProc_self() == NotifySetup_hostProcId) {
726 virtId = VIRTID(remoteProcId);
727 params.intVectorId = NotifySetup_module->interruptTable[virtId];
728 }
730 /* create the notify driver instance */
731 driver = NotifyDriverMbx_create(¶ms, &eb);
733 if (driver == NULL) {
734 return (Notify_E_FAIL);
735 }
737 /* create the front-end notify instance */
738 notify = ti_sdo_ipc_Notify_create(NotifyDriverMbx_Handle_upCast(driver),
739 remoteProcId, 0, NULL, &eb);
741 if (notify == NULL) {
742 NotifyDriverMbx_delete(&driver);
743 status = Notify_E_FAIL;
744 }
746 return (status);
747 }
749 /*!
750 * ======== NotifySetup_Mbx_sharedMemReq ========
751 */
752 SizeT NotifySetup_Mbx_sharedMemReq(UInt16 remoteProcId, Ptr sharedAddr)
753 {
754 SizeT memReq = 0;
756 return (memReq);
757 }
759 /*
760 *************************************************************************
761 * Internal functions
762 *************************************************************************
763 */
765 /*
766 * ======== NotifySetup_dispatchIsr ========
767 * Dispatch the current interrupt to the appropriate notify driver
768 *
769 * The given interrupt may be shared by multiple notify drivers. This
770 * ISR inspects the mailbox which raised the interrupt and looks for
771 * all FIFOs which have data and raise the given interrupt. For each
772 * one, the interrupt is dispatched to the registered driver for that
773 * FIFO.
774 *
775 * @param(arg) The eventId which raised the interrupt.
776 */
777 Void NotifySetup_dispatchIsr(UArg arg)
778 {
779 Int numProcessed;
780 UInt16 idx;
781 UInt16 srcVirtId;
782 UInt16 dstVirtId = VIRTID(MultiProc_self());
783 NotifySetup_DriverIsr driver;
785 do {
786 numProcessed = 0;
788 for (srcVirtId = 0; srcVirtId < NotifySetup_NUM_CORES; srcVirtId++) {
790 /* skip null drivers, processor not in system or self */
791 driver = NotifySetup_module->isrDispatchTable[srcVirtId];
793 if (driver == NULL) {
794 continue;
795 }
797 /* check if processor would raise the given hardware eventId */
798 if (arg == NotifySetup_module->interruptTable[srcVirtId]) {
800 /* compute table index for given source and destination */
801 idx = (srcVirtId * NotifySetup_NUM_CORES) + dstVirtId;
803 /* check if submailbox has a message and irq is enabled */
804 if ((MBOX_MSG_COUNT(idx) != 0) && MBOX_IRQ_ENABLE(idx)) {
806 /* invoke driver isr to deliver the event */
807 (*driver)(idx);
809 /* event has been delivered */
810 numProcessed++;
811 }
812 }
813 }
814 } while (numProcessed != 0);
815 }