SDOCM00106584 Notify mailbox driver support on DRA7xx (IPU, HOST) - Part 1
[ipc/ipcdev.git] / packages / ti / sdo / ipc / family / vayu / NotifySetup.xs
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.xs ========
35  */
36 var MultiProc = null;
37 var Core = null;
38 var isaChain = "";
40 /*
41  *  ======== isMbxDrv ========
42  */
43 function isMbxDrv(mod, name)
44 {
45     if (mod.connections == undefined) {
46         return (false);
47     }
49     for (var i = 0; i < mod.connections.length; i++) {
50         if (mod.connections[i].procName == name) {
51             if (mod.connections[i].driver == mod.Driver_MAILBOX) {
52                 return (true);
53             }
54             else {
55                 return (false);
56             }
57         }
58     }
60     return (false);
61 }
63 /*
64  *  ======== module$use ========
65  */
66 function module$use()
67 {
68     /* load modules needed in meta domain and in target domain */
69     var TableInit = xdc.useModule("ti.sdo.ipc.family.vayu.TableInit");
70     MultiProc = xdc.useModule('ti.sdo.utils.MultiProc');
71     xdc.useModule('xdc.runtime.Assert');
72     xdc.useModule('xdc.runtime.Error');
73     xdc.useModule('xdc.runtime.Startup');
75     /* concatinate isa chain into single string for easier matching */
76     isaChain = "#" + Program.build.target.getISAChain().join("#") + "#";
78     if (isaChain.match(/#64P#/)) {
79         xdc.useModule('ti.sysbios.family.c64p.EventCombiner');
80         xdc.useModule('ti.sysbios.family.c64p.Hwi');
81         xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');
82     }
83     else if (isaChain.match(/#arp32#/)) {
84         xdc.useModule('ti.sysbios.family.arp32.Hwi');
85     }
86     else if (isaChain.match(/#v7M#/)) {
87         Core = xdc.useModule("ti.sysbios.family.arm.ducati.Core");
88     }
90     xdc.useModule('ti.sdo.ipc.Ipc');
91     xdc.useModule('ti.sdo.ipc.Notify');
93     /* initialize procIdTable */
94     TableInit.initProcId(this);
96     /* initialize mailboxTable */
97     TableInit.generateTable(this);
99     if (isaChain.match(/#64P#|#v7A#/)) {
100         /* initialize mailbox base address table */
101         this.mailboxBaseAddr[0]  = 0x4208B000;  /* EVE1 Internal Mailbox 0 */
102         this.mailboxBaseAddr[1]  = 0x4208C000;  /* EVE1 Internal Mailbox 1 */
103         this.mailboxBaseAddr[2]  = 0x4208D000;  /* EVE1 Internal Mailbox 2 */
104         this.mailboxBaseAddr[3]  = 0x4218B000;  /* EVE2 Internal Mailbox 0 */
105         this.mailboxBaseAddr[4]  = 0x4218C000;  /* EVE2 Internal Mailbox 1 */
106         this.mailboxBaseAddr[5]  = 0x4218D000;  /* EVE2 Internal Mailbox 2 */
107         this.mailboxBaseAddr[6]  = 0x4228B000;  /* EVE3 Internal Mailbox 0 */
108         this.mailboxBaseAddr[7]  = 0x4228C000;  /* EVE3 Internal Mailbox 1 */
109         this.mailboxBaseAddr[8]  = 0x4228D000;  /* EVE3 Internal Mailbox 2 */
110         this.mailboxBaseAddr[9]  = 0x4238B000;  /* EVE4 Internal Mailbox 0 */
111         this.mailboxBaseAddr[10] = 0x4238C000;  /* EVE4 Internal Mailbox 1 */
112         this.mailboxBaseAddr[11] = 0x4238D000;  /* EVE4 Internal Mailbox 2 */
113         this.mailboxBaseAddr[12] = 0x48840000;  /* System Mailbox 5 */
114         this.mailboxBaseAddr[13] = 0x48842000;  /* System Mailbox 6 */
115         this.mailboxBaseAddr[14] = 0x48844000;  /* System Mailbox 7 */
116         this.mailboxBaseAddr[15] = 0x48846000;  /* System Mailbox 8 */
117     }
118     else if (isaChain.match(/#arp32#/)) {
119         this.mailboxBaseAddr[0]  = 0x4008B000;  /* EVE1 Internal Mailbox 0 */
120         this.mailboxBaseAddr[1]  = 0x4008C000;  /* EVE1 Internal Mailbox 1 */
121         this.mailboxBaseAddr[2]  = 0x4208D000;  /* EVE1 Internal Mailbox 2 */
122         this.mailboxBaseAddr[3]  = 0x4008B000;  /* EVE2 Internal Mailbox 0 */
123         this.mailboxBaseAddr[4]  = 0x4008C000;  /* EVE2 Internal Mailbox 1 */
124         this.mailboxBaseAddr[5]  = 0x4218D000;  /* EVE2 Internal Mailbox 2 */
125         this.mailboxBaseAddr[6]  = 0x4008B000;  /* EVE3 Internal Mailbox 0 */
126         this.mailboxBaseAddr[7]  = 0x4008C000;  /* EVE3 Internal Mailbox 1 */
127         this.mailboxBaseAddr[8]  = 0x4228D000;  /* EVE3 Internal Mailbox 2 */
128         this.mailboxBaseAddr[9]  = 0x4008B000;  /* EVE4 Internal Mailbox 0 */
129         this.mailboxBaseAddr[10] = 0x4008C000;  /* EVE4 Internal Mailbox 1 */
130         this.mailboxBaseAddr[11] = 0x4238D000;  /* EVE4 Internal Mailbox 2 */
131         this.mailboxBaseAddr[12] = 0x48840000;  /* System Mailbox 5 */
132         this.mailboxBaseAddr[13] = 0x48842000;  /* System Mailbox 6 */
133         this.mailboxBaseAddr[14] = 0x48844000;  /* System Mailbox 7 */
134         this.mailboxBaseAddr[15] = 0x48846000;  /* System Mailbox 8 */
136         /* each EVE receives its message using the local mailbox address */
137         if (MultiProc.id == this.eve1ProcId) {
138             this.mailboxBaseAddr[2] = 0x4008D000;
139         }
140         else if (MultiProc.id == this.eve2ProcId) {
141             this.mailboxBaseAddr[5] = 0x4008D000;
142         }
143         else if (MultiProc.id == this.eve3ProcId) {
144             this.mailboxBaseAddr[8] = 0x4008D000;
145         }
146         else if (MultiProc.id == this.eve4ProcId) {
147             this.mailboxBaseAddr[11] = 0x4008D000;
148         }
149     }
150     else if (isaChain.match(/#v7M#/)) {
151         /* initialize mailbox base address table */
152         if (this.mailboxBaseAddr[0] == undefined) {
153             this.mailboxBaseAddr[0]  = 0x6208B000;  /* EVE1 MBOX0 */
154         }
155         if (this.mailboxBaseAddr[1] == undefined) {
156             this.mailboxBaseAddr[1]  = 0x6208C000;  /* EVE1 MBOX1 */
157         }
158         if (this.mailboxBaseAddr[2] == undefined) {
159             this.mailboxBaseAddr[2]  = 0;           /* EVE1 MBOX2 */
160         } else {
161             this.$logWarning("NotifySetup.mailboxBaseAddr[2] is EVE1 MBOX2, "
162                     + "which is not used for IPU communication and should "
163                     + "not be configured.", this);
164         }
165         if (this.mailboxBaseAddr[3] == undefined) {
166             this.mailboxBaseAddr[3]  = 0x6218B000;  /* EVE2 MBOX0 */
167         }
168         if (this.mailboxBaseAddr[4] == undefined) {
169             this.mailboxBaseAddr[4]  = 0x6218C000;  /* EVE2 MBOX1 */
170         }
171         if (this.mailboxBaseAddr[5] == undefined) {
172             this.mailboxBaseAddr[5]  = 0;           /* EVE2 MBOX2 */
173         } else {
174             this.$logWarning("NotifySetup.mailboxBaseAddr[5] is EVE2 MBOX2, "
175                     + "which is not used for IPU communication and should "
176                     + "not be configured.", this);
177         }
179         if (this.mailboxBaseAddr[6] == undefined) {
180             this.mailboxBaseAddr[6]  = 0x6228B000;  /* EVE3 MBOX0 */
181         }
182         if (this.mailboxBaseAddr[7] == undefined) {
183             this.mailboxBaseAddr[7]  = 0x6228C000;  /* EVE3 MBOX1 */
184         }
185         if (this.mailboxBaseAddr[8] == undefined) {
186             this.mailboxBaseAddr[8]  = 0;           /* EVE3 MBOX2 */
187         } else {
188             this.$logWarning("NotifySetup.mailboxBaseAddr[8] is EVE3 MBOX2, "
189                     + "which is not used for IPU communication and should "
190                     + "not be configured.", this);
191         }
193         if (this.mailboxBaseAddr[9] == undefined) {
194             this.mailboxBaseAddr[9]  = 0x6238B000;  /* EVE4 MBOX0 */
195         }
196         if (this.mailboxBaseAddr[10] == undefined) {
197             this.mailboxBaseAddr[10]  = 0x6238C000; /* EVE4 MBOX1 */
198         }
199         if (this.mailboxBaseAddr[11] == undefined) {
200             this.mailboxBaseAddr[11]  = 0;          /* EVE4 MBOX2 */
201         } else {
202             this.$logWarning("NotifySetup.mailboxBaseAddr[11] is EVE4 MBOX2, "
203                     + "which is not used for IPU communication and should "
204                     + "not be configured.", this);
205         }
207         if (this.mailboxBaseAddr[12] == undefined) {
208             this.mailboxBaseAddr[12] = 0x68840000;  /* System Mailbox 5 */
209         }
210         if (this.mailboxBaseAddr[13] == undefined) {
211             this.mailboxBaseAddr[13] = 0x68842000;  /* System Mailbox 6 */
212         }
213         if (this.mailboxBaseAddr[14] == undefined) {
214             this.mailboxBaseAddr[14] = 0x68844000;  /* System Mailbox 7 */
215         }
216         if (this.mailboxBaseAddr[15] == undefined) {
217             this.mailboxBaseAddr[15] = 0x68846000;  /* System Mailbox 8 */
218         }
219     }
220     else {
221         throw("Invalid target: " + Program.build.target.$name);
222     }
224     /* determine which notify drivers to include */
225     this.$private.driverMask = 0;
227     /* for unspecfied connections, the default is shared memory */
228     if (this.connections.length < (MultiProc.numProcessors - 1)) {
229         this.$private.driverMask |= this.Driver_SHAREDMEMORY;
230     }
232     /* remember which notify drivers have been specified */
233     for (var i = 0; i < this.connections.length; i++) {
234         if (this.connections[i].driver == this.Driver_SHAREDMEMORY) {
235             this.$private.driverMask |= this.Driver_SHAREDMEMORY;
236         }
237         if (this.connections[i].driver == this.Driver_MAILBOX) {
238             this.$private.driverMask |= this.Driver_MAILBOX;
239         }
240     }
242     /* load notify drivers into configuration model */
243     if (this.$private.driverMask & this.Driver_SHAREDMEMORY) {
244         xdc.useModule('ti.sdo.ipc.notifyDrivers.NotifyDriverShm');
245     }
246     if (this.$private.driverMask & this.Driver_MAILBOX) {
247         xdc.useModule('ti.sdo.ipc.family.vayu.NotifyDriverMbx');
248     }
251 /*
252  *  ======== module$static$init ========
253  *  Initialize the target state object.
254  */
255 function module$static$init(state, mod)
257     var procId;
259     /*  Initialize the state connAry from the config params. Translate
260      *  processor names into IDs for better runtime performance.
261      */
262     state.connAry.length = mod.connections.length;
264     for (var i = 0; i < mod.connections.length; i++) {
265         procId = MultiProc.getIdMeta(mod.connections[i].procName);
266         state.connAry[i].procId = procId;
267         state.connAry[i].driver = mod.connections[i].driver;
268     }
270     if (isaChain.match(/#64P#/)) {
271         state.numPlugged.length = 1;
272         for (var i = 0; i < state.numPlugged.length; i++) {
273             state.numPlugged[i] = 0;
274         }
276         /* interrupt event IDs used by this processor */
277         state.interruptTable[0] = 55; /* EVE1 -> DSP1 or DSP2 */
278         state.interruptTable[1] = 56; /* EVE2 -> DSP1 or DSP2 */
279         state.interruptTable[2] = 58; /* EVE3 -> DSP1 or DSP2 */
280         state.interruptTable[3] = 59; /* EVE4 -> DSP1 or DSP2 */
281         state.interruptTable[4] = 60; /* DSP1 -> DSP2 */
282         state.interruptTable[5] = 60; /* DSP2 -> DSP1 */
283         state.interruptTable[8] = 57; /* HOST -> DSP1 or DSP2 */
285         /* these are not known at config time, set at runtime */
286         state.interruptTable[6] = 0; /* IPU1 -> DSP1 or DSP2 */
287         state.interruptTable[7] = 0; /* IPU2 -> DSP1 or DSP2 */
288         state.interruptTable[9] = 0; /* IPU1-1 -> DSP1 or DSP2 */
289         state.interruptTable[10] = 0; /* IPU2-1 -> DSP1 or DSP2 */
290     }
291     else if (isaChain.match(/#arp32#/)) {
292         state.numPlugged.length = this.NUM_EVE_MBX / this.NUM_EVES;
293         for (var i = 0; i < state.numPlugged.length; i++) {
294             state.numPlugged[i] = 0;
295         }
297         /* interrupt event IDs used by this processor */
298         state.interruptTable[0] = 60; /* EVE1 - Group1/INTC1 */
299         state.interruptTable[1] = 60; /* EVE2 - Group1/INTC1 */
300         state.interruptTable[2] = 60; /* EVE3 - Group1/INTC1 */
301         state.interruptTable[3] = 60; /* EVE4 - Group1/INTC1 */
302         state.interruptTable[4] = 29; /* DSP1 - Group0/INTC0 */
303         state.interruptTable[5] = 30; /* DSP2 - Group0/INTC0 */
304         state.interruptTable[6] = 29; /* IPU1-0 */
305         state.interruptTable[7] = 30; /* IPU2-0 */
306         state.interruptTable[8] = 29; /* HOST */
307         state.interruptTable[9] = 30; /* IPU1-1 */
308         state.interruptTable[10] = 30; /* IPU2-1 */
309     }
310     else if (isaChain.match(/#v7M#/)) {
311         state.numPlugged.length = mod.NUM_EVE_MBX + mod.NUM_SYS_MBX;
312         for (var i = 0; i < state.numPlugged.length; i++) {
313             state.numPlugged[i] = 0;
314         }
316         if (Core.id == 0) {
317             /* interrupt event IDs used by this processor */
318             state.interruptTable[0] = 64; /* EVE1 */
319             state.interruptTable[1] = 65; /* EVE2 */
320             state.interruptTable[2] = 67; /* EVE3 */
321             state.interruptTable[3] = 68; /* EVE4 */
323             if (Core.ipuId == 1) { /* IPU1-0 */
324                 state.interruptTable[4] = 66;  /* DSP1 */
325                 state.interruptTable[5] = 69;  /* DSP2 */
326                 state.interruptTable[6] = 0;   /* IPU1-0 */
327                 state.interruptTable[7] = 69;  /* Ipu2-0 */
328                 state.interruptTable[8] = 66;  /* HOST */
329                 var mbxDrv = isMbxDrv(mod, "IPU1-1");
330                 state.interruptTable[9] = mbxDrv ? 69 : 19;  /* IPU1-1 */
331                 state.interruptTable[10] = 70; /* Ipu2-1 */
332             }
333             else { /* IPU2-0 */
334                 state.interruptTable[4] = 69;  /* DSP1 */
335                 state.interruptTable[5] = 66;  /* DSP2 */
336                 state.interruptTable[6] = 69;  /* IPU1-0 */
337                 state.interruptTable[7] = 0;   /* Ipu2-0 */
338                 state.interruptTable[8] = 66;  /* HOST */
339                 state.interruptTable[9] = 70;  /* IPU1-1 */
340                 state.interruptTable[10] = 19; /* Ipu2-1 */
341             }
342         }
343         else {
344             /* interrupt event IDs used by this processor */
345             state.interruptTable[0] = 71; /* EVE1 */
346             state.interruptTable[1] = 72; /* EVE2 */
347             state.interruptTable[2] = 74; /* EVE3 */
348             state.interruptTable[3] = 75; /* EVE4 */
350             if (Core.ipuId == 1) { /* IPU1-1 */
351                 state.interruptTable[4] = 73;  /* DSP1 */
352                 state.interruptTable[5] = 76;  /* DSP2 */
353                 var mbxDrv = isMbxDrv(mod, "IPU1-0");
354                 state.interruptTable[6] = mbxDrv ? 76 : 19;  /* IPU1-0 */
355                 state.interruptTable[7] = 76;  /* Ipu2-0 */
356                 state.interruptTable[8] = 73;  /* HOST */
357                 state.interruptTable[9] = 0;   /* IPU1-1 */
358                 state.interruptTable[10] = 0;  /* Ipu2-1 */
359             }
360             else { /* IPU2-1 */
361                 state.interruptTable[4] = 76;  /* DSP1 */
362                 state.interruptTable[5] = 73;  /* DSP2 */
363                 state.interruptTable[6] = 76;  /* IPU1-0 */
364                 state.interruptTable[7] = 19;  /* Ipu2-0 */
365                 state.interruptTable[8] = 73;  /* HOST */
366                 state.interruptTable[9] = 0;   /* IPU1-1 */
367                 state.interruptTable[10] = 0;  /* Ipu2-1 */
368             }
369         }
370     }
371     else if (isaChain.match(/#v7A#/)) {
372         state.numPlugged.length = 1;
374         /* interrupt event IDs used by this processor */
375         for (var i = 0; i < state.interruptTable.length; i++) {
376             state.interruptTable[i] = 0xFFFF; /* TODO */
377         }
379         /* TODO */
380         // Hwi.construct(state.hwi, 77, NotifyDriverMbx.isr);
381     }
382     else {
383         throw("Invalid target: " + Program.build.target.$name);
384     }
386     /* initialize the driver table */
387     for (var i = 0; i < state.isrDispatchTable.length; i++) {
388         state.isrDispatchTable[i] = null;
389     }