1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /********************************************************************20**
21 Name: System Services -- Driver
25 Desc: Source code for those functions in System Services
26 that exist for driver support.
30 *********************************************************************21*/
34 /* header include files (.h) */
36 #include "envopt.h" /* environment options */
37 #include "envdep.h" /* environment dependent */
38 #include "envind.h" /* environment independent */
40 #include "gen.h" /* general layer */
41 #include "ssi.h" /* system services */
43 #include "ss_err.h" /* errors */
44 #include "ss_dep.h" /* implementation-specific */
45 #include "ss_queue.h" /* queues */
46 #include "ss_msg.h" /* messaging */
47 #include "ss_mem.h" /* memory management interface */
48 #include "ss_gen.h" /* general */
49 #include "cm_mem.h" /* memory management */
53 /* header/extern include files (.x) */
55 #include "gen.x" /* general layer */
56 #include "ssi.x" /* system services */
59 #include "ss_dep.x" /* implementation-specific */
60 #include "ss_queue.x" /* queues */
61 #include "ss_task.x" /* tasking */
62 #include "ss_timer.x" /* timers */
63 #include "ss_strm.x" /* STREAMS */
64 #include "ss_msg.x" /* messaging */
65 #include "ss_mem.x" /* memory management interface */
66 #include "ss_drvr.x" /* driver tasks */
67 #ifdef SS_LOCKLESS_MEMORY
70 #include "cm_mem_wl.x" /* common memory manager */
72 #include "cm_mem.x" /* common memory manager */
73 #endif /* SS_LOCKLESS_MEMORY */
74 #include "ss_gen.x" /* general */
77 #ifdef SS_DRVR_SUPPORT
85 * Desc: This function is used to register a driver task.
88 * RFAILED - failed, general (optional)
89 * ROUTRES - failed, out of resources (optional)
97 PUBLIC S16 SRegDrvrTsk
99 Inst channel, /* channel instance */
100 ProcId low, /* processor ID -- low */
101 ProcId high, /* processor ID -- high */
102 ActvTsk actvTsk, /* activation function */
103 ISTsk isTsk /* interrupt service function */
106 PUBLIC S16 SRegDrvrTsk(channel, low, high, actvTsk, isTsk)
107 Inst channel; /* channel instance */
108 ProcId low; /* processor ID -- low */
109 ProcId high; /* processor ID -- high */
110 ActvTsk actvTsk; /* activation function */
111 ISTsk isTsk; /* interrupt service function */
115 #if (ERRCLASS & ERRCLS_INT_PAR)
117 /* ss029.103: modification: multiple procId related changes */
118 #ifndef SS_MULTIPLE_PROCS
122 /* ss029.103: modification: multiple procId related changes */
123 #ifdef SS_MULTIPLE_PROCS
126 ProcId procIdLst[SS_MAX_PROCS];
127 #endif /* SS_MULTIPLE_PROCS */
133 #if (ERRCLASS & ERRCLS_INT_PAR)
135 /* ss029.103: modification: multiple procId related changes */
136 #ifdef SS_MULTIPLE_PROCS
137 if (SGetProcIdLst(&count, procIdLst) != ROK)
139 SSLOGERROR(ERRCLS_INT_PAR, ESS001, ERRZERO, "Null procId list");
143 for (i = 0; i < count; i++)
145 if (procIdLst[i] >= low && procIdLst[i] <= high)
147 SSLOGERROR(ERRCLS_INT_PAR, ESS002, ERRZERO, "Invalid procId range");
151 #else /* SS_MULTIPLE_PROCS */
152 thisProcId = SFndProcId();
153 if (thisProcId >= low && thisProcId <= high)
155 SSLOGERROR(ERRCLS_INT_PAR, ESS003, ERRZERO, "Invalid procId range");
158 #endif /* SS_MULTIPLE_PROCS */
160 if (channel >= SS_MAX_DRVRTSKS)
162 SSLOGERROR(ERRCLS_INT_PAR, ESS004, channel, "Invalid channel");
166 /* check activation functions */
167 if (actvTsk == NULLP || isTsk == NULLP)
169 SSLOGERROR(ERRCLS_INT_PAR, ESS005, ERRZERO, "Null pointer");
173 /* check if already registered */
174 if (osCp.drvrTskTbl[channel].used == TRUE)
176 SSLOGERROR(ERRCLS_INT_PAR, ESS006, ERRZERO,
177 "Driver task already registered");
183 #if (ERRCLASS & ERRCLS_DEBUG)
184 /* check count of tasks */
185 if (osCp.numDrvrTsks == SS_MAX_DRVRTSKS)
187 SSLOGERROR(ERRCLS_DEBUG, ESS007, ERRZERO, "Too many tasks");
193 if (SInitLock(&osCp.drvrTskTbl[channel].lock, SS_DRVRENTRY_LOCK) != ROK)
196 #if (ERRCLASS & ERRCLS_DEBUG)
197 SSLOGERROR(ERRCLS_DEBUG, ESS008, ERRZERO, "Could not initialize lock");
203 osCp.drvrTskTbl[channel].channel = channel;
204 osCp.drvrTskTbl[channel].actvTsk = actvTsk;
205 osCp.drvrTskTbl[channel].isTsk = isTsk;
206 osCp.drvrTskTbl[channel].low = low;
207 osCp.drvrTskTbl[channel].high = high;
209 ret = ssdRegDrvrTsk(&osCp.drvrTskTbl[channel]);
212 osCp.drvrTskTbl[channel].channel = 0;
213 osCp.drvrTskTbl[channel].actvTsk = NULLP;
214 osCp.drvrTskTbl[channel].isTsk = NULLP;
215 osCp.drvrTskTbl[channel].low = 0;
216 osCp.drvrTskTbl[channel].high = 0;
217 SDestroyLock(&osCp.drvrTskTbl[channel].lock);
221 osCp.drvrTskTbl[channel].used = TRUE;
229 /* ss001.301: Additions */
234 * Desc: This function is used to de-register a driver task.
237 * RFAILED - failed, general (optional)
238 * ROUTRES - failed, out of resources (optional)
246 PUBLIC S16 SDeregDrvrTsk
248 Inst channel /* channel instance */
251 PUBLIC S16 SDeregDrvrTsk(channel)
255 /* ss002.301 Modifications */
258 #if (ERRCLASS & ERRCLS_INT_PAR)
259 if (channel >= SS_MAX_DRVRTSKS)
261 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, channel, "Invalid channel");
265 /* check if already registered */
266 if (osCp.drvrTskTbl[channel].used != TRUE)
268 SSLOGERROR(ERRCLS_INT_PAR, ESS477, ERRZERO,
269 "Driver task is not registered");
275 if(SLock(&osCp.drvrTskTbl[channel].lock) != ROK)
277 #if (ERRCLASS & ERRCLS_DEBUG)
278 SSLOGERROR(ERRCLS_DEBUG, ESS477, ERRZERO,
279 "Could not lock driver task lock");
283 ssdDeregDrvrTsk(&osCp.drvrTskTbl[channel]);
285 osCp.drvrTskTbl[channel].channel = 0;
286 osCp.drvrTskTbl[channel].actvTsk = NULLP;
287 osCp.drvrTskTbl[channel].isTsk = NULLP;
288 osCp.drvrTskTbl[channel].low = 0;
289 osCp.drvrTskTbl[channel].high = 0;
291 osCp.drvrTskTbl[channel].used = FALSE;
293 if(SUnlock(&osCp.drvrTskTbl[channel].lock) != ROK)
295 #if (ERRCLASS & ERRCLS_DEBUG)
296 SSLOGERROR(ERRCLS_DEBUG, ESS477, ERRZERO,
297 "Could not unlock driver task lock");
301 SDestroyLock(&osCp.drvrTskTbl[channel].lock);
302 /* ss002.301 Modifications */
305 #endif /* SS_DRVR_SUPPORT */
306 /**********************************************************************
308 **********************************************************************/