]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - linux/src/api/Ipc.c
Linux: Moved MultiProc config into the platform specific LAD daemon.
[ipc/ipcdev.git] / linux / src / api / Ipc.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  *  @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>
47 #include <Std.h>
49 /* Common IPC headers: */
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 <_MessageQ.h>
59 #include <_NameServer.h>
61 MultiProc_Config _MultiProc_cfg;
63 static LAD_ClientHandle ladHandle;
65 static void cleanup(int arg);
67 /** ============================================================================
68  *  Functions
69  *  ============================================================================
70  */
71 /* Function to start Ipc */
72 Int Ipc_start (Void)
73 {
74     MessageQ_Config   msgqCfg;
75     MultiProc_Config  mpCfg;
76     Int32             status = Ipc_S_SUCCESS;
77     LAD_Status        ladStatus;
78     UInt16            rprocId;
80     /* Catch ctrl-C, and cleanup: */
81     (void) signal(SIGINT, cleanup);
83     ladStatus = LAD_connect(&ladHandle);
84     if (ladStatus != LAD_SUCCESS) {
85         printf("Ipc_start: LAD_connect() failed: %d\n", ladStatus);
86         status = Ipc_E_FAIL;
87         goto exit;
88     }
90     /* Setup and get MultiProc configuration from LAD */
91     MultiProc_getConfig(&mpCfg);
92     _MultiProc_cfg = mpCfg;
94     status = NameServer_setup();
95     if (status >= 0) {
96         MessageQ_getConfig(&msgqCfg);
97         MessageQ_setup(&msgqCfg);
99         /* Now attach to all remote processors, assuming they are up. */
100         for (rprocId = 0;
101              (rprocId < MultiProc_getNumProcessors()) && (status >= 0);
102              rprocId++) {
103            if (0 == rprocId) {
104                /* Skip host, which should always be 0th entry. */
105                continue;
106            }
107            status = MessageQ_attach (rprocId, NULL);
108            if (status < 0) {
109               printf("Ipc_start: MessageQ_attach(%d) failed: %d\n",
110                      rprocId, status);
111               status = Ipc_E_FAIL;
112            }
113         }
114     }
115     else {
116         printf("Ipc_start: NameServer_setup() failed: %d\n", status);
117         status = Ipc_E_FAIL;
118     }
120 exit:
121     return (status);
125 /* Function to stop Ipc */
126 Int Ipc_stop (Void)
128     Int32             status = Ipc_S_SUCCESS;
129     LAD_Status        ladStatus;
130     UInt16            rprocId;
132     /* Now detach from all remote processors, assuming they are up. */
133     for (rprocId = 0;
134          (rprocId < MultiProc_getNumProcessors()) && (status >= 0);
135          rprocId++) {
136         if (0 == rprocId) {
137           /* Skip host, which should always be 0th entry. */
138           continue;
139         }
140         status = MessageQ_detach(rprocId);
141         if (status < 0) {
142             printf("Ipc_stop: MessageQ_detach(%d) failed: %d\n",
143                 rprocId, status);
144             status = Ipc_E_FAIL;
145             goto exit;
146        }
147     }
149     status = MessageQ_destroy();
150     if (status < 0) {
151         printf("Ipc_stop: MessageQ_destroy() failed: %d\n", status);
152         status = Ipc_E_FAIL;
153         goto exit;
154     }
156     status = NameServer_destroy();
157     if (status < 0) {
158         printf("Ipc_stop: NameServer_destroy() failed: %d\n", status);
159         status = Ipc_E_FAIL;
160         goto exit;
161     }
163     ladStatus = LAD_disconnect(ladHandle);
164     if (ladStatus != LAD_SUCCESS) {
165         printf("LAD_disconnect() failed: %d\n", ladStatus);
166         status = Ipc_E_FAIL;
167         goto exit;
168     }
170 exit:
171     return (status);
174 static void cleanup(int arg)
176     printf("Ipc: Caught SIGINT, calling Ipc_stop...\n");
177     Ipc_stop();
178     exit(0);