]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - linux/src/api/Ipc.c
Linux: Added GateMP support for DRA7XX devices
[ipc/ipcdev.git] / linux / src / api / Ipc.c
1 /*
2  * Copyright (c) 2012-2014, 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  *  @file       Ipc.c
34  *
35  *  @brief      Starts and stops user side Ipc
36  *              All setup/destroy APIs on user side will be call from this
37  *              module.
38  *
39  *  @ver        0002
40  *
41  */
43 /* Standard headers */
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <signal.h>
48 /* Common IPC headers: */
49 #include <ti/ipc/Std.h>
50 #include <ti/ipc/Ipc.h>
51 #include <ti/ipc/NameServer.h>
53 /* User side headers */
54 #include <ladclient.h>
56 /* IPC startup/shutdown stuff: */
57 #include <ti/ipc/MultiProc.h>
58 #include <GateHWSpinlock.h>
59 #include <_GateMP.h>
60 #include <_MultiProc.h>
61 #include <_MessageQ.h>
62 #include <_NameServer.h>
64 GateHWSpinlock_Config _GateHWSpinlock_cfgParams;
66 static LAD_ClientHandle ladHandle;
68 static void cleanup(int arg);
70 /** ============================================================================
71  *  Functions
72  *  ============================================================================
73  */
74 /* Function to start Ipc */
75 Int Ipc_start (Void)
76 {
77     MessageQ_Config        msgqCfg;
78     MultiProc_Config       mpCfg;
79     GateHWSpinlock_Config  gateHWCfg;
80     Int32                  status;
81     LAD_Status             ladStatus;
82     UInt16                 rprocId;
83     Int32                  attachedAny = 0;
85     /* Catch ctrl-C, and cleanup: */
86     (void) signal(SIGINT, cleanup);
88     ladStatus = LAD_connect(&ladHandle);
89     if (ladStatus != LAD_SUCCESS) {
90         printf("Ipc_start: LAD_connect() failed: %d\n", ladStatus);
91         status = Ipc_E_FAIL;
92         goto exit;
93     }
95     /* 
96      * Get MultiProc configuration from LAD and initialize local MultiProc
97      * config structure.
98      */
99     MultiProc_getConfig(&mpCfg);
100     _MultiProc_initCfg(&mpCfg);
102     status = NameServer_setup();
103     if (status >= 0) {
104         MessageQ_getConfig(&msgqCfg);
105         MessageQ_setup(&msgqCfg);
107         /* Now attach to all remote processors, assuming they are up. */
108         for (rprocId = 0; rprocId < MultiProc_getNumProcessors(); rprocId++) {
109             if (0 == rprocId) {
110                 /* Skip host, which should always be 0th entry. */
111                 continue;
112             }
113             status = MessageQ_attach(rprocId, NULL);
114             if (status == MessageQ_E_RESOURCE) {
115                 continue;
116             }
117             if (status < 0) {
118                 printf("Ipc_start: MessageQ_attach(%d) failed: %d\n",
119                        rprocId, status);
120                 status = Ipc_E_FAIL;
122                 break;
123             }
124             else {
125                 attachedAny = 1;
126             }
127         }
128         if (attachedAny) {
129             status = Ipc_S_SUCCESS;
130         }
131     }
132     else {
133         printf("Ipc_start: NameServer_setup() failed: %d\n", status);
134         status = Ipc_E_FAIL;
135     }
137     /* Start GateMP only if device has support */
138 #if defined(GATEMP_SUPPORT)
139     if (GateMP_isSetup()) {
140         /*
141          * Get HWSpinlock base address and size from LAD and
142          * initialize the local config structure.
143          */
144         GateHWSpinlock_getConfig(&gateHWCfg);
145         _GateHWSpinlock_cfgParams = gateHWCfg;
147         status = GateHWSpinlock_start();
148         if (status < 0) {
149             printf("Ipc_start: GateHWSpinlock_start failed: %d\n",
150                 status);
151             status = Ipc_E_FAIL;
152             goto gatehwspinlockstart_fail;
153         }
154         else {
155             status = GateMP_start();
156             if (status < 0) {
157                 printf("Ipc_start: GateMP_start failed: %d\n",
158                 status);
159                 status = Ipc_E_FAIL;
160                 goto gatempstart_fail;
161             }
162         }
163     }
164 #endif
165     /* Success */
166     goto exit;
167 #if defined(GATEMP_SUPPORT)
168 gatempstart_fail:
169     GateHWSpinlock_stop();
170 gatehwspinlockstart_fail:
171     for (rprocId = rprocId - 1; (rprocId > 0) && (status >= 0); rprocId--) {
172         MessageQ_detach(rprocId);
173     }
174 #endif
176 exit:
177     return (status);
181 /* Function to stop Ipc */
182 Int Ipc_stop (Void)
184     Int32             status = Ipc_S_SUCCESS;
185     LAD_Status        ladStatus;
186     UInt16            rprocId;
188     /* Now detach from all remote processors, assuming they are up. */
189     for (rprocId = 0;
190          (rprocId < MultiProc_getNumProcessors()) && (status >= 0);
191          rprocId++) {
192         if (0 == rprocId) {
193           /* Skip host, which should always be 0th entry. */
194           continue;
195         }
196         status = MessageQ_detach(rprocId);
197         if (status < 0) {
198             printf("Ipc_stop: MessageQ_detach(%d) failed: %d\n",
199                 rprocId, status);
200             status = Ipc_E_FAIL;
201             goto exit;
202        }
203     }
205     status = MessageQ_destroy();
206     if (status < 0) {
207         printf("Ipc_stop: MessageQ_destroy() failed: %d\n", status);
208         status = Ipc_E_FAIL;
209         goto exit;
210     }
212     status = NameServer_destroy();
213     if (status < 0) {
214         printf("Ipc_stop: NameServer_destroy() failed: %d\n", status);
215         status = Ipc_E_FAIL;
216         goto exit;
217     }
219     ladStatus = LAD_disconnect(ladHandle);
220     if (ladStatus != LAD_SUCCESS) {
221         printf("LAD_disconnect() failed: %d\n", ladStatus);
222         status = Ipc_E_FAIL;
223         goto exit;
224     }
226 exit:
227     return (status);
230 static void cleanup(int arg)
232     printf("Ipc: Caught SIGINT, calling Ipc_stop...\n");
233     Ipc_stop();
234     exit(0);