]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - packages/ti/srvmgr/omx/OmxSrvMgr.c
7bc0f06b13540bcae51742bb61fb39a72e0b2834
[ipc/ipcdev.git] / packages / ti / srvmgr / omx / OmxSrvMgr.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  *  ======== OmxSrvMgr.c ========
34  *
35  *  The primary task function that serves the incoming requests on the OMX
36  *  Service.
37  */
39 #include <xdc/std.h>
40 #include <xdc/cfg/global.h>
41 #include <xdc/runtime/System.h>
42 #include <xdc/runtime/Startup.h>
43 #include <xdc/runtime/Error.h>
45 #include <ti/sysbios/knl/Task.h>
47 #include <ti/ipc/MultiProc.h>
49 #include <ti/ipc/rpmsg/RPMessage.h>
50 #include <ti/ipc/rpmsg/NameMap.h>
51 #include <ti/srvmgr/rpmsg_omx.h>
52 #include <ti/srvmgr/ServiceMgr.h>
54 #include "package/internal/OmxSrvMgr.xdc.h"
56 /* Hard coded to match rpmsg-omx Host side driver */
57 #define  OMX_MGR_PORT   60
59 Void OmxSrvMgr_taskFxn(UArg arg0, UArg arg1)
60 {
61     RPMessage_Handle msgq;
62     UInt32 local;
63     UInt32 remote;
64     Char msg[HDRSIZE + sizeof(struct omx_connect_req)];
65     struct omx_msg_hdr * hdr = (struct omx_msg_hdr *)msg;
66     struct omx_connect_rsp * rsp = (struct omx_connect_rsp *)hdr->data;
67     struct omx_connect_req * req = (struct omx_connect_req *)hdr->data;
68     struct omx_disc_req * disc_req = (struct omx_disc_req *)hdr->data;
69     struct omx_disc_rsp * disc_rsp = (struct omx_disc_rsp *)hdr->data;
70     UInt16 dstProc;
71     UInt16 len;
72     UInt32 newAddr = 0;
74 #ifdef BIOS_ONLY_TEST
75     dstProc = MultiProc_self();
76 #else
77     dstProc = MultiProc_getId("HOST");
78 #endif
80     msgq = RPMessage_create(OMX_MGR_PORT, NULL, NULL, &local);
82     System_printf("OmxSrvMgr: started on port: %d\n", OMX_MGR_PORT);
84 #ifdef SMP
85     NameMap_register("rpmsg-omx", "rpmsg-omx1", OMX_MGR_PORT);
86     System_printf("OmxSrvMgr: Proc#%d sending BOOTINIT_DONE\n",
87                         MultiProc_self());
88 #else
89     if (MultiProc_self() == MultiProc_getId("CORE0")) {
90         NameMap_register("rpmsg-omx", "rpmsg-omx0", OMX_MGR_PORT);
91     }
92     if (MultiProc_self() == MultiProc_getId("CORE1")) {
93         NameMap_register("rpmsg-omx", "rpmsg-omx1", OMX_MGR_PORT);
94     }
95     if (MultiProc_self() == MultiProc_getId("DSP") ||
96         MultiProc_self() == MultiProc_getId("DSP1")) {
97         NameMap_register("rpmsg-omx", "rpmsg-omx2", OMX_MGR_PORT);
98     }
99 #endif
101     while (1) {
102        RPMessage_recv(msgq, (Ptr)msg, &len, &remote, RPMessage_FOREVER);
103        System_printf("OmxSrvMgr: received msg type: %d from addr: %d\n",
104                       hdr->type, remote);
105        switch (hdr->type) {
106            case OMX_CONN_REQ:
107             /* This is a request to create a new service, and return
108              * it's connection endpoint.
109              */
110             System_printf("OmxSrvMgr: CONN_REQ: len: %d, name: %s\n",
111                  hdr->len, req->name);
113             rsp->status = ServiceMgr_createService(req->name, &newAddr);
115             hdr->type = OMX_CONN_RSP;
116             rsp->addr = newAddr;
117             hdr->len = sizeof(struct omx_connect_rsp);
118             len = HDRSIZE + hdr->len;
119             break;
121            case OMX_DISC_REQ:
122             /* Destroy the service instance at given service addr: */
123             System_printf("OmxSrvMgr: OMX_DISCONNECT: len %d, addr: %d\n",
124                  hdr->len, disc_req->addr);
126             disc_rsp->status = ServiceMgr_deleteService(disc_req->addr);
128             /* currently, no response expected from rpmsg_omx: */
129             continue;
130 #if 0       /* rpmsg_omx is not listening for this ... yet. */
131             hdr->type = OMX_DISC_RSP;
132             hdr->len = sizeof(struct omx_disc_rsp);
133             len = HDRSIZE + hdr->len;
134             break;
135 #endif
137            default:
138             System_printf("unexpected msg type: %d\n", hdr->type);
139             hdr->type = OMX_NOTSUPP;
140             break;
141        }
143        System_printf("OmxSrvMgr: Replying with msg type: %d to addr: %d "
144                       " from: %d\n",
145                       hdr->type, remote, local);
146        RPMessage_send(dstProc, remote, local, msg, len);
147     }
150 Int OmxSrvMgr_Module_startup(Int phase)
152     Task_Params params;
154     if (Task_Module_startupDone()) {
155         ServiceMgr_init();
157         /* Create our ServiceMgr Thread: */
158         Task_Params_init(&params);
159         params.instance->name = "OmxSrvMgr";
160         params.priority = 1;   /* Lowest priority thread */
162         ServiceMgr_registerSrvTask(0, OmxSrvMgr_taskFxn, &params);
164         return (Startup_DONE);
165     }
166     else {
167         return (Startup_NOTDONE);
168     }