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)
98 Inst channel, /* channel instance */
99 ProcId low, /* processor ID -- low */
100 ProcId high, /* processor ID -- high */
101 ActvTsk actvTsk, /* activation function */
102 ISTsk isTsk /* interrupt service function */
106 #if (ERRCLASS & ERRCLS_INT_PAR)
108 /* ss029.103: modification: multiple procId related changes */
109 #ifndef SS_MULTIPLE_PROCS
113 /* ss029.103: modification: multiple procId related changes */
114 #ifdef SS_MULTIPLE_PROCS
117 ProcId procIdLst[SS_MAX_PROCS];
118 #endif /* SS_MULTIPLE_PROCS */
123 #if (ERRCLASS & ERRCLS_INT_PAR)
125 /* ss029.103: modification: multiple procId related changes */
126 #ifdef SS_MULTIPLE_PROCS
127 if (SGetProcIdLst(&count, procIdLst) != ROK)
129 SSLOGERROR(ERRCLS_INT_PAR, ESS001, ERRZERO, "Null procId list");
133 for (i = 0; i < count; i++)
135 if (procIdLst[i] >= low && procIdLst[i] <= high)
137 SSLOGERROR(ERRCLS_INT_PAR, ESS002, ERRZERO, "Invalid procId range");
141 #else /* SS_MULTIPLE_PROCS */
142 thisProcId = SFndProcId();
143 if (thisProcId >= low && thisProcId <= high)
145 SSLOGERROR(ERRCLS_INT_PAR, ESS003, ERRZERO, "Invalid procId range");
148 #endif /* SS_MULTIPLE_PROCS */
150 if (channel >= SS_MAX_DRVRTSKS)
152 SSLOGERROR(ERRCLS_INT_PAR, ESS004, channel, "Invalid channel");
156 /* check activation functions */
157 if (actvTsk == NULLP || isTsk == NULLP)
159 SSLOGERROR(ERRCLS_INT_PAR, ESS005, ERRZERO, "Null pointer");
163 /* check if already registered */
164 if (osCp.drvrTskTbl[channel].used == TRUE)
166 SSLOGERROR(ERRCLS_INT_PAR, ESS006, ERRZERO,
167 "Driver task already registered");
173 #if (ERRCLASS & ERRCLS_DEBUG)
174 /* check count of tasks */
175 if (osCp.numDrvrTsks == SS_MAX_DRVRTSKS)
177 SSLOGERROR(ERRCLS_DEBUG, ESS007, ERRZERO, "Too many tasks");
183 if (SInitLock(&osCp.drvrTskTbl[channel].lock, SS_DRVRENTRY_LOCK) != ROK)
186 #if (ERRCLASS & ERRCLS_DEBUG)
187 SSLOGERROR(ERRCLS_DEBUG, ESS008, ERRZERO, "Could not initialize lock");
193 osCp.drvrTskTbl[channel].channel = channel;
194 osCp.drvrTskTbl[channel].actvTsk = actvTsk;
195 osCp.drvrTskTbl[channel].isTsk = isTsk;
196 osCp.drvrTskTbl[channel].low = low;
197 osCp.drvrTskTbl[channel].high = high;
199 ret = ssdRegDrvrTsk(&osCp.drvrTskTbl[channel]);
202 osCp.drvrTskTbl[channel].channel = 0;
203 osCp.drvrTskTbl[channel].actvTsk = NULLP;
204 osCp.drvrTskTbl[channel].isTsk = NULLP;
205 osCp.drvrTskTbl[channel].low = 0;
206 osCp.drvrTskTbl[channel].high = 0;
207 SDestroyLock(&osCp.drvrTskTbl[channel].lock);
211 osCp.drvrTskTbl[channel].used = TRUE;
219 /* ss001.301: Additions */
224 * Desc: This function is used to de-register a driver task.
227 * RFAILED - failed, general (optional)
228 * ROUTRES - failed, out of resources (optional)
237 Inst channel /* channel instance */
240 /* ss002.301 Modifications */
242 #if (ERRCLASS & ERRCLS_INT_PAR)
243 if (channel >= SS_MAX_DRVRTSKS)
245 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, channel, "Invalid channel");
249 /* check if already registered */
250 if (osCp.drvrTskTbl[channel].used != TRUE)
252 SSLOGERROR(ERRCLS_INT_PAR, ESS477, ERRZERO,
253 "Driver task is not registered");
259 if(SLock(&osCp.drvrTskTbl[channel].lock) != ROK)
261 #if (ERRCLASS & ERRCLS_DEBUG)
262 SSLOGERROR(ERRCLS_DEBUG, ESS477, ERRZERO,
263 "Could not lock driver task lock");
267 ssdDeregDrvrTsk(&osCp.drvrTskTbl[channel]);
269 osCp.drvrTskTbl[channel].channel = 0;
270 osCp.drvrTskTbl[channel].actvTsk = NULLP;
271 osCp.drvrTskTbl[channel].isTsk = NULLP;
272 osCp.drvrTskTbl[channel].low = 0;
273 osCp.drvrTskTbl[channel].high = 0;
275 osCp.drvrTskTbl[channel].used = FALSE;
277 if(SUnlock(&osCp.drvrTskTbl[channel].lock) != ROK)
279 #if (ERRCLASS & ERRCLS_DEBUG)
280 SSLOGERROR(ERRCLS_DEBUG, ESS477, ERRZERO,
281 "Could not unlock driver task lock");
285 SDestroyLock(&osCp.drvrTskTbl[channel].lock);
286 /* ss002.301 Modifications */
289 #endif /* SS_DRVR_SUPPORT */
290 /**********************************************************************
292 **********************************************************************/