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)
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 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 */
132 #if (ERRCLASS & ERRCLS_INT_PAR)
134 /* ss029.103: modification: multiple procId related changes */
135 #ifdef SS_MULTIPLE_PROCS
136 if (SGetProcIdLst(&count, procIdLst) != ROK)
138 SSLOGERROR(ERRCLS_INT_PAR, ESS001, ERRZERO, "Null procId list");
142 for (i = 0; i < count; i++)
144 if (procIdLst[i] >= low && procIdLst[i] <= high)
146 SSLOGERROR(ERRCLS_INT_PAR, ESS002, ERRZERO, "Invalid procId range");
150 #else /* SS_MULTIPLE_PROCS */
151 thisProcId = SFndProcId();
152 if (thisProcId >= low && thisProcId <= high)
154 SSLOGERROR(ERRCLS_INT_PAR, ESS003, ERRZERO, "Invalid procId range");
157 #endif /* SS_MULTIPLE_PROCS */
159 if (channel >= SS_MAX_DRVRTSKS)
161 SSLOGERROR(ERRCLS_INT_PAR, ESS004, channel, "Invalid channel");
165 /* check activation functions */
166 if (actvTsk == NULLP || isTsk == NULLP)
168 SSLOGERROR(ERRCLS_INT_PAR, ESS005, ERRZERO, "Null pointer");
172 /* check if already registered */
173 if (osCp.drvrTskTbl[channel].used == TRUE)
175 SSLOGERROR(ERRCLS_INT_PAR, ESS006, ERRZERO,
176 "Driver task already registered");
182 #if (ERRCLASS & ERRCLS_DEBUG)
183 /* check count of tasks */
184 if (osCp.numDrvrTsks == SS_MAX_DRVRTSKS)
186 SSLOGERROR(ERRCLS_DEBUG, ESS007, ERRZERO, "Too many tasks");
192 if (SInitLock(&osCp.drvrTskTbl[channel].lock, SS_DRVRENTRY_LOCK) != ROK)
195 #if (ERRCLASS & ERRCLS_DEBUG)
196 SSLOGERROR(ERRCLS_DEBUG, ESS008, ERRZERO, "Could not initialize lock");
202 osCp.drvrTskTbl[channel].channel = channel;
203 osCp.drvrTskTbl[channel].actvTsk = actvTsk;
204 osCp.drvrTskTbl[channel].isTsk = isTsk;
205 osCp.drvrTskTbl[channel].low = low;
206 osCp.drvrTskTbl[channel].high = high;
208 ret = ssdRegDrvrTsk(&osCp.drvrTskTbl[channel]);
211 osCp.drvrTskTbl[channel].channel = 0;
212 osCp.drvrTskTbl[channel].actvTsk = NULLP;
213 osCp.drvrTskTbl[channel].isTsk = NULLP;
214 osCp.drvrTskTbl[channel].low = 0;
215 osCp.drvrTskTbl[channel].high = 0;
216 SDestroyLock(&osCp.drvrTskTbl[channel].lock);
220 osCp.drvrTskTbl[channel].used = TRUE;
228 /* ss001.301: Additions */
233 * Desc: This function is used to de-register a driver task.
236 * RFAILED - failed, general (optional)
237 * ROUTRES - failed, out of resources (optional)
247 Inst channel /* channel instance */
250 S16 SDeregDrvrTsk(channel)
254 /* ss002.301 Modifications */
256 #if (ERRCLASS & ERRCLS_INT_PAR)
257 if (channel >= SS_MAX_DRVRTSKS)
259 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, channel, "Invalid channel");
263 /* check if already registered */
264 if (osCp.drvrTskTbl[channel].used != TRUE)
266 SSLOGERROR(ERRCLS_INT_PAR, ESS477, ERRZERO,
267 "Driver task is not registered");
273 if(SLock(&osCp.drvrTskTbl[channel].lock) != ROK)
275 #if (ERRCLASS & ERRCLS_DEBUG)
276 SSLOGERROR(ERRCLS_DEBUG, ESS477, ERRZERO,
277 "Could not lock driver task lock");
281 ssdDeregDrvrTsk(&osCp.drvrTskTbl[channel]);
283 osCp.drvrTskTbl[channel].channel = 0;
284 osCp.drvrTskTbl[channel].actvTsk = NULLP;
285 osCp.drvrTskTbl[channel].isTsk = NULLP;
286 osCp.drvrTskTbl[channel].low = 0;
287 osCp.drvrTskTbl[channel].high = 0;
289 osCp.drvrTskTbl[channel].used = FALSE;
291 if(SUnlock(&osCp.drvrTskTbl[channel].lock) != ROK)
293 #if (ERRCLASS & ERRCLS_DEBUG)
294 SSLOGERROR(ERRCLS_DEBUG, ESS477, ERRZERO,
295 "Could not unlock driver task lock");
299 SDestroyLock(&osCp.drvrTskTbl[channel].lock);
300 /* ss002.301 Modifications */
303 #endif /* SS_DRVR_SUPPORT */
304 /**********************************************************************
306 **********************************************************************/