1 /*
2 * Copyright (c) 2012-2013, Texas Instruments Incorporated
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 */
32 /*
33 * ======== TransportShmNotify.c ========
34 */
36 #include <xdc/std.h>
37 #include <xdc/runtime/Assert.h>
38 #include <xdc/runtime/Error.h>
40 #include <ti/sysbios/hal/Cache.h>
42 #include "package/internal/TransportShmNotify.xdc.h"
44 #include <ti/sdo/ipc/_Ipc.h>
45 #include <ti/sdo/ipc/_SharedRegion.h>
46 #include <ti/sdo/ipc/_Notify.h>
47 #include <ti/sdo/ipc/_MessageQ.h>
49 /* Need to use reserved notify events */
50 #undef TransportShmNotify_notifyEventId
51 #define TransportShmNotify_notifyEventId \
52 ti_sdo_ipc_transports_TransportShmNotify_notifyEventId + \
53 (UInt32)((UInt32)Notify_SYSTEMKEY << 16)
55 /*
56 *************************************************************************
57 * Module functions
58 *************************************************************************
59 */
62 /*
63 * ======== TransportShmNotify_notifyFxn ========
64 */
65 Void TransportShmNotify_notifyFxn(UInt16 procId,
66 UInt16 lineId,
67 UInt32 eventId,
68 UArg arg,
69 UInt32 payload)
70 {
71 UInt32 queueId;
72 MessageQ_Msg msg;
74 msg = SharedRegion_getPtr((SharedRegion_SRPtr)payload);
76 queueId = MessageQ_getDstQueue(msg);
78 MessageQ_put(queueId, msg);
79 }
81 /*
82 *************************************************************************
83 * Instance functions
84 *************************************************************************
85 */
87 /*
88 * ======== TransportShmNotify_Instance_init ========
89 */
90 Int TransportShmNotify_Instance_init(TransportShmNotify_Object *obj,
91 UInt16 procId, const TransportShmNotify_Params *params,
92 Error_Block *eb)
93 {
94 Int status;
95 Bool flag;
97 obj->priority = params->priority;
98 obj->remoteProcId = procId;
100 /* register the event with Notify */
101 status = Notify_registerEventSingle(
102 procId, /* remoteProcId */
103 0, /* lineId */
104 TransportShmNotify_notifyEventId,
105 (Notify_FnNotifyCbck)TransportShmNotify_notifyFxn, 0);
107 if (status < 0) {
108 Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0);
109 return (1);
110 }
112 /* Register the transport with MessageQ */
113 flag = ti_sdo_ipc_MessageQ_registerTransport(
114 TransportShmNotify_Handle_upCast(obj), procId, params->priority);
116 if (flag == FALSE) {
117 Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0);
118 return (2);
119 }
121 return (0);
122 }
124 /*
125 * ======== TransportShmNotify_Instance_finalize ========
126 */
127 Void TransportShmNotify_Instance_finalize(TransportShmNotify_Object* obj,
128 Int status)
129 {
130 switch(status) {
131 case 0: /* MessageQ_registerTransport succeeded */
132 ti_sdo_ipc_MessageQ_unregisterTransport(obj->remoteProcId,
133 obj->priority);
135 /* fall thru OK */
136 case 1: /* Notify_registerEventSingle failed */
137 case 2: /* MessageQ_registerTransport failed */
138 Notify_unregisterEventSingle(
139 obj->remoteProcId,
140 0,
141 TransportShmNotify_notifyEventId);
142 break;
143 }
144 }
146 /*
147 * ======== TransportShmNotify_put ========
148 * Assuming MessageQ_put is making sure that the arguments are ok
149 */
150 Bool TransportShmNotify_put(TransportShmNotify_Object *obj, Ptr msg)
151 {
152 UInt16 regionId = SharedRegion_INVALIDREGIONID;
153 SharedRegion_SRPtr msgSRPtr;
154 Int status;
156 /*
157 * If translation is disabled and we always have to write back the message
158 * then we can avoid calling SharedRegion_getId()
159 */
160 if (ti_sdo_ipc_SharedRegion_translate ||
161 !TransportShmNotify_alwaysWriteBackMsg ) {
162 regionId = SharedRegion_getId(msg);
163 if (SharedRegion_isCacheEnabled(regionId)) {
164 Cache_wbInv(msg, ((MessageQ_Msg)(msg))->msgSize, Cache_Type_ALL,
165 TRUE);
166 }
167 }
168 else {
169 Cache_wbInv(msg, ((MessageQ_Msg)(msg))->msgSize, Cache_Type_ALL, TRUE);
170 }
172 /*
173 * Get the msg's SRPtr. OK if (regionId == SharedRegion_INVALIDID &&
174 * SharedRegion_translate == FALSE)
175 */
176 msgSRPtr = SharedRegion_getSRPtr(msg, regionId);
178 /*
179 * Notify the remote processor and send msg via payload parameter
180 * use waitClear = TRUE to make sure prior message was received
181 */
182 status = Notify_sendEvent(obj->remoteProcId, 0,
183 TransportShmNotify_notifyEventId, (UInt32)msgSRPtr, TRUE);
184 if (status < 0) {
185 return (FALSE);
186 }
188 return (TRUE);
189 }
191 /*
192 * ======== TransportShmNotify_control ========
193 */
194 Bool TransportShmNotify_control(TransportShmNotify_Object *obj, UInt cmd,
195 UArg cmdArg)
196 {
197 return (FALSE);
198 }
200 /*
201 * ======== TransportShmNotify_getStatus ========
202 */
203 Int TransportShmNotify_getStatus(TransportShmNotify_Object *obj)
204 {
205 return (0);
206 }
208 /*
209 *************************************************************************
210 * Module functions
211 *************************************************************************
212 */
214 /*
215 * ======== TransportShmNotify_setErrFxn ========
216 */
217 Void TransportShmNotify_setErrFxn(TransportShmNotify_ErrFxn errFxn)
218 {
219 /* Ignore the errFxn */
220 }