]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - packages/ti/sdo/ipc/transports/TransportShmNotify.c
Shared memory cache management
[ipc/ipcdev.git] / packages / ti / sdo / ipc / transports / TransportShmNotify.c
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;
73     UInt16 regionId;
75     msg = SharedRegion_getPtr((SharedRegion_SRPtr)payload);
77     /* Read new data into memory instead of old data from cache */
78     regionId = SharedRegion_getId(msg);
79     if (SharedRegion_isCacheEnabled(regionId)) {
80         /* invalidate header before reading header */
81         Cache_inv(msg,
82                   sizeof(MessageQ_MsgHeader),
83                   Cache_Type_ALL,
84                   TRUE);
85         /* invalidate the rest of the message */
86         Cache_inv(((char *)msg) + sizeof(MessageQ_MsgHeader),
87                   msg->msgSize - sizeof(MessageQ_MsgHeader),
88                   Cache_Type_ALL,
89                   TRUE);
90     }
92     queueId = MessageQ_getDstQueue(msg);
94     MessageQ_put(queueId, msg);
95 }
97 /*
98  *************************************************************************
99  *                       Instance functions
100  *************************************************************************
101  */
103 /*
104  *  ======== TransportShmNotify_Instance_init ========
105  */
106 Int TransportShmNotify_Instance_init(TransportShmNotify_Object *obj,
107         UInt16 procId, const TransportShmNotify_Params *params,
108         Error_Block *eb)
110     Int status;
111     Bool flag;
113     obj->priority      = params->priority;
114     obj->remoteProcId  = procId;
116     /* register the event with Notify */
117     status = Notify_registerEventSingle(
118                  procId,    /* remoteProcId */
119                  0,         /* lineId */
120                  TransportShmNotify_notifyEventId,
121                  (Notify_FnNotifyCbck)TransportShmNotify_notifyFxn, 0);
123     if (status < 0) {
124         Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0);
125         return (1);
126     }
128     /* Register the transport with MessageQ */
129     flag = ti_sdo_ipc_MessageQ_registerTransport(
130             TransportShmNotify_Handle_upCast(obj), procId, params->priority);
132     if (flag == FALSE) {
133         Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0);
134         return (2);
135     }
137     return (0);
140 /*
141  *  ======== TransportShmNotify_Instance_finalize ========
142  */
143 Void TransportShmNotify_Instance_finalize(TransportShmNotify_Object* obj,
144         Int status)
146     switch(status) {
147         case 0: /* MessageQ_registerTransport succeeded */
148             ti_sdo_ipc_MessageQ_unregisterTransport(obj->remoteProcId,
149                 obj->priority);
151             /* fall thru OK */
152         case 1: /* Notify_registerEventSingle failed */
153         case 2: /* MessageQ_registerTransport failed */
154             Notify_unregisterEventSingle(
155                 obj->remoteProcId,
156                 0,
157                 TransportShmNotify_notifyEventId);
158             break;
159     }
162 /*
163  *  ======== TransportShmNotify_put ========
164  *  Assuming MessageQ_put is making sure that the arguments are ok
165  */
166 Bool TransportShmNotify_put(TransportShmNotify_Object *obj, Ptr msg)
168     UInt16 regionId = SharedRegion_INVALIDREGIONID;
169     SharedRegion_SRPtr msgSRPtr;
170     Int status;
172     /*
173      *  If translation is disabled and we always have to write back the message
174      *  then we can avoid calling SharedRegion_getId()
175      */
176     if (ti_sdo_ipc_SharedRegion_translate ||
177             !TransportShmNotify_alwaysWriteBackMsg ) {
178         regionId = SharedRegion_getId(msg);
179         if (SharedRegion_isCacheEnabled(regionId)) {
180             Cache_wbInv(msg, ((MessageQ_Msg)(msg))->msgSize, Cache_Type_ALL,
181                     TRUE);
182         }
183     }
184     else {
185         Cache_wbInv(msg, ((MessageQ_Msg)(msg))->msgSize, Cache_Type_ALL, TRUE);
186     }
188     /*
189      *  Get the msg's SRPtr.  OK if (regionId == SharedRegion_INVALIDID &&
190      *  SharedRegion_translate == FALSE)
191      */
192     msgSRPtr = SharedRegion_getSRPtr(msg, regionId);
194     /*
195      * Notify the remote processor and send msg via payload parameter
196      * use waitClear = TRUE to make sure prior message was received
197      */
198     status = Notify_sendEvent(obj->remoteProcId, 0,
199         TransportShmNotify_notifyEventId, (UInt32)msgSRPtr, TRUE);
200     if (status < 0) {
201         return (FALSE);
202     }
204     return (TRUE);
207 /*
208  *  ======== TransportShmNotify_control ========
209  */
210 Bool TransportShmNotify_control(TransportShmNotify_Object *obj, UInt cmd,
211     UArg cmdArg)
213     return (FALSE);
216 /*
217  *  ======== TransportShmNotify_getStatus ========
218  */
219 Int TransportShmNotify_getStatus(TransportShmNotify_Object *obj)
221     return (0);
224 /*
225  *************************************************************************
226  *                      Module functions
227  *************************************************************************
228  */
230 /*
231  *  ======== TransportShmNotify_setErrFxn ========
232  */
233 Void TransportShmNotify_setErrFxn(TransportShmNotify_ErrFxn errFxn)
235     /* Ignore the errFxn */