|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: WlanOsa implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 9 % |
|
20 */ |
|
21 |
|
22 #include "osa_includeme.h" |
|
23 |
|
24 #include <kern_priv.h> |
|
25 |
|
26 #include "osa.h" |
|
27 #include "osadfc.h" |
|
28 #include "osatimer.h" |
|
29 |
|
30 #ifdef __WLAN_ENABLE_DMA |
|
31 #include "osamemorypool.h" |
|
32 #else |
|
33 // allocator for general purpose memory |
|
34 extern void* GpAlloc( TInt aSize, TBool aZeroStamp ); |
|
35 // free for general purpose memory |
|
36 extern void GpFree( void* aPtr ); |
|
37 #endif // __WLAN_ENABLE_DMA |
|
38 |
|
39 struct WlanOsaImpl : public DBase, public WlanObject |
|
40 { |
|
41 |
|
42 /** |
|
43 * Ctor |
|
44 * |
|
45 * @since S60 v3.2 |
|
46 */ |
|
47 inline WlanOsaImpl(); |
|
48 |
|
49 /** |
|
50 * Dtor |
|
51 * |
|
52 * @since S60 v3.2 |
|
53 */ |
|
54 virtual ~WlanOsaImpl(); |
|
55 |
|
56 /** |
|
57 * Initializes the object instance. |
|
58 * Note! Needs to be executed successfully after object instance |
|
59 * construction to be able to use the instance. |
|
60 * |
|
61 * @param aUseCachedMemory ETrue if cached interconnect memory shall be used |
|
62 * EFalse otherwise |
|
63 * @param aAllocationUnit allocation unit size for interconnect memory in |
|
64 * bytes |
|
65 * @return ETrue when successful |
|
66 * EFalse otherwise |
|
67 */ |
|
68 TBool Initialize( TBool aUseCachedMemory, TInt aAllocationUnit ); |
|
69 |
|
70 /** |
|
71 * mutex |
|
72 * Not Own. |
|
73 */ |
|
74 DMutex* iMutex; |
|
75 |
|
76 #ifdef __WLAN_ENABLE_DMA |
|
77 /** |
|
78 * memorypool |
|
79 */ |
|
80 WlanMemoryPool* iMemoryPool; |
|
81 #endif // __WLAN_ENABLE_DMA |
|
82 |
|
83 private: |
|
84 |
|
85 // Prohibit copy constructor. |
|
86 WlanOsaImpl( const WlanOsaImpl& ); |
|
87 // Prohibit assigment operator. |
|
88 WlanOsaImpl& operator= ( const WlanOsaImpl& ); |
|
89 }; |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 WlanOsaImpl::WlanOsaImpl(): iMutex( NULL ), iMemoryPool( NULL ) |
|
96 { |
|
97 Validate(); |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 WlanOsaImpl::~WlanOsaImpl() |
|
106 { |
|
107 #ifdef __WLAN_ENABLE_DMA |
|
108 if ( iMemoryPool ) |
|
109 { |
|
110 delete iMemoryPool; |
|
111 iMemoryPool = NULL; |
|
112 } |
|
113 #endif // __WLAN_ENABLE_DMA |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 TBool WlanOsaImpl::Initialize( TBool aUseCachedMemory, TInt aAllocationUnit ) |
|
121 { |
|
122 TBool status( ETrue ); |
|
123 |
|
124 #ifdef __WLAN_ENABLE_DMA |
|
125 iMemoryPool = new WlanMemoryPool( aUseCachedMemory, aAllocationUnit ); |
|
126 if ( iMemoryPool ) |
|
127 { |
|
128 if ( !iMemoryPool->IsValid() ) |
|
129 { |
|
130 TraceDump(ERROR_LEVEL, |
|
131 ("[WLAN] WlanOsaImpl::Initialize: ERROR: WLAN mem pool invalid")); |
|
132 |
|
133 status = EFalse; |
|
134 // memory pool will be freed in the destructor |
|
135 } |
|
136 } |
|
137 else |
|
138 { |
|
139 TraceDump(ERROR_LEVEL, |
|
140 ("[WLAN] WlanOsaImpl::Initialize: ERROR: WLAN mem pool alloc failed")); |
|
141 |
|
142 status = EFalse; |
|
143 } |
|
144 #endif // __WLAN_ENABLE_DMA |
|
145 |
|
146 return status; |
|
147 } |
|
148 |
|
149 |
|
150 // ======== MEMBER FUNCTIONS ======== |
|
151 |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 WlanOsa::~WlanOsa() |
|
158 { |
|
159 TraceDump(INFO_LEVEL, ("[WLAN] WlanOsa dtor")); |
|
160 |
|
161 iDfcQueue = NULL; |
|
162 |
|
163 if ( IsValid() ) |
|
164 { |
|
165 // we are valid -> proceed |
|
166 // close the mutex |
|
167 TraceDump(MUTEX_LEVEL, ("[WLAN] WlanOsa close mutex")); |
|
168 |
|
169 if ( Pimpl().iMutex ) |
|
170 { |
|
171 Pimpl().iMutex->Close( NULL ); |
|
172 } |
|
173 |
|
174 if ( iPimpl ) |
|
175 { |
|
176 delete iPimpl; |
|
177 iPimpl = NULL; |
|
178 } |
|
179 } |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 WlanOsa::WlanOsa() : iPimpl( NULL ), iDfcQueue( NULL ) |
|
187 { |
|
188 TraceDump(INFO_LEVEL, ("[WLAN] WlanOsa ctor")); |
|
189 |
|
190 iPimpl = new WlanOsaImpl(); |
|
191 if ( iPimpl ) |
|
192 { |
|
193 if ( iPimpl->IsValid() ) |
|
194 { |
|
195 // allocation success & object valid -> proceed |
|
196 |
|
197 Validate(); |
|
198 |
|
199 const TUint mutex_order( KMutexOrdGeneral7 ); |
|
200 TraceDump(MUTEX_LEVEL, |
|
201 (("[WLAN] WlanOsa mutex create: order: %d"), mutex_order)); |
|
202 |
|
203 const TInt ret( Kern::MutexCreate( |
|
204 Pimpl().iMutex, KNullDesC, mutex_order) ); |
|
205 |
|
206 if ( ret != KErrNone ) |
|
207 { |
|
208 delete iPimpl; |
|
209 // and invalidate |
|
210 InValidate(); |
|
211 } |
|
212 } |
|
213 else |
|
214 { |
|
215 // osa impl is invalid. Deallocate it |
|
216 delete iPimpl; |
|
217 // we are invalid, too |
|
218 InValidate(); |
|
219 } |
|
220 } |
|
221 else |
|
222 { |
|
223 // allocation failed invalidate object |
|
224 InValidate(); |
|
225 } |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 TBool WlanOsa::Initialize( |
|
233 TBool aUseCachedMemory, |
|
234 TInt aAllocationUnit, |
|
235 void* aDfcQueue ) |
|
236 { |
|
237 TraceDump(INFO_LEVEL, ("[WLAN] WlanOsa::Initialize()")); |
|
238 |
|
239 TBool status( ETrue ); |
|
240 |
|
241 iDfcQueue = aDfcQueue; |
|
242 |
|
243 if ( iPimpl ) |
|
244 { |
|
245 status = Pimpl().Initialize( aUseCachedMemory, aAllocationUnit ); |
|
246 } |
|
247 else |
|
248 { |
|
249 status = EFalse; |
|
250 } |
|
251 |
|
252 TraceDump(INFO_LEVEL, (("[WLAN] WlanOsa::Initialize(): status (bool): %d"), |
|
253 status)); |
|
254 |
|
255 return status; |
|
256 } |
|
257 |
|
258 // --------------------------------------------------------------------------- |
|
259 // From class MWlanOsa. |
|
260 // |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 void* WlanOsa::Alloc( TOsaMemoryType aOsaMemoryType, TInt aSize, TUint aFlags ) |
|
264 { |
|
265 #ifdef __WLAN_ENABLE_DMA |
|
266 |
|
267 return Pimpl().iMemoryPool->Alloc( |
|
268 aOsaMemoryType, |
|
269 aSize, |
|
270 (aFlags & KAllocZeroStampMask) ); |
|
271 |
|
272 #else |
|
273 |
|
274 return GpAlloc( aSize, (aFlags & KAllocZeroStampMask) ); |
|
275 |
|
276 #endif // __WLAN_ENABLE_DMA |
|
277 } |
|
278 |
|
279 // --------------------------------------------------------------------------- |
|
280 // From class MWlanOsa. |
|
281 // |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 void WlanOsa::Free( void* aPtr ) |
|
285 { |
|
286 #ifdef __WLAN_ENABLE_DMA |
|
287 |
|
288 Pimpl().iMemoryPool->Free( aPtr ); |
|
289 |
|
290 #else |
|
291 |
|
292 GpFree( aPtr ); |
|
293 |
|
294 #endif // __WLAN_ENABLE_DMA |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------------------------- |
|
298 // From class MWlanOsa. |
|
299 // |
|
300 // --------------------------------------------------------------------------- |
|
301 // |
|
302 MWlanDfc* WlanOsa::DfcCreate() |
|
303 { |
|
304 TraceDump(INFO_LEVEL, ("[WLAN] WlanOsa::DfcCreate()")); |
|
305 |
|
306 WlanDfc* dfc( new WlanDfc( *this, iDfcQueue ) ); |
|
307 if ( dfc ) |
|
308 { |
|
309 if ( !(dfc->IsValid()) ) |
|
310 { |
|
311 // construct failure -> destroy |
|
312 delete dfc; |
|
313 dfc = NULL; |
|
314 } |
|
315 } |
|
316 |
|
317 TraceDump(INFO_LEVEL, (("dfc addr: 0x%08x"), dfc)); |
|
318 |
|
319 return dfc; |
|
320 } |
|
321 |
|
322 // --------------------------------------------------------------------------- |
|
323 // From class MWlanOsa. |
|
324 // |
|
325 // --------------------------------------------------------------------------- |
|
326 // |
|
327 void WlanOsa::DfcDestroy( MWlanDfc* aWlanDfc ) |
|
328 { |
|
329 TraceDump(INFO_LEVEL, ("[WLAN] WlanOsa::DfcDestroy()")); |
|
330 |
|
331 delete aWlanDfc; |
|
332 } |
|
333 |
|
334 // --------------------------------------------------------------------------- |
|
335 // From class MWlanOsa. |
|
336 // |
|
337 // --------------------------------------------------------------------------- |
|
338 // |
|
339 MWlanTimer* WlanOsa::TimerCreate() |
|
340 { |
|
341 TraceDump(INFO_LEVEL, ("[WLAN] WlanOsa::TimerCreate()")); |
|
342 |
|
343 WlanTimer* timer( new WlanTimer( *this, iDfcQueue ) ); |
|
344 if ( timer ) |
|
345 { |
|
346 if ( !(timer->IsValid()) ) |
|
347 { |
|
348 // construct failure -> destroy |
|
349 delete timer; |
|
350 timer = NULL; |
|
351 } |
|
352 } |
|
353 else |
|
354 { |
|
355 TraceDump(INFO_LEVEL, ("[WLAN] WlanOsa::TimerCreate() no memory")); |
|
356 } |
|
357 |
|
358 return timer; |
|
359 } |
|
360 |
|
361 // --------------------------------------------------------------------------- |
|
362 // From class MWlanOsa. |
|
363 // |
|
364 // --------------------------------------------------------------------------- |
|
365 // |
|
366 void WlanOsa::TimerDestroy( MWlanTimer* aWlanTimer ) |
|
367 { |
|
368 TraceDump(INFO_LEVEL, ("[WLAN] WlanOsa::TimerDestroy()")); |
|
369 |
|
370 WlanTimer* timer = static_cast< WlanTimer* >( aWlanTimer ); |
|
371 |
|
372 // dequeue just in case |
|
373 timer->Dequeue(); |
|
374 |
|
375 // remove the final reference to the timer instance - this will |
|
376 // cause the object to destroy itself when it is ready to go |
|
377 // (the timer DFC been completed.) |
|
378 timer->RefDel(); |
|
379 |
|
380 } |
|
381 |
|
382 // --------------------------------------------------------------------------- |
|
383 // From class MWlanOsa. |
|
384 // --------------------------------------------------------------------------- |
|
385 // |
|
386 TInt MWlanOsa::MemCmp( const void* aLhs, |
|
387 const void* aRhs, |
|
388 TInt aNumOfBytes ) |
|
389 { |
|
390 return memcompare( |
|
391 static_cast<const TUint8*>(aLhs), aNumOfBytes, |
|
392 static_cast<const TUint8*>(aRhs), aNumOfBytes ); |
|
393 } |
|
394 |
|
395 // --------------------------------------------------------------------------- |
|
396 // From class MWlanOsa. |
|
397 // --------------------------------------------------------------------------- |
|
398 // |
|
399 void* MWlanOsa::MemCpy( void* aDest, |
|
400 const void* aSrc, |
|
401 TUint aLengthinBytes ) |
|
402 { |
|
403 return memcpy( aDest, aSrc, aLengthinBytes ); |
|
404 } |
|
405 |
|
406 // --------------------------------------------------------------------------- |
|
407 // From class MWlanOsa. |
|
408 // --------------------------------------------------------------------------- |
|
409 // |
|
410 void* MWlanOsa::WordCpy( TInt* aDest, const TInt* aSrc, TUint aLengthinBytes ) |
|
411 { |
|
412 return wordmove( aDest, aSrc, aLengthinBytes ); |
|
413 } |
|
414 |
|
415 // --------------------------------------------------------------------------- |
|
416 // From class MWlanOsa. |
|
417 // --------------------------------------------------------------------------- |
|
418 // |
|
419 void* MWlanOsa::MemClr( void* aDest, TUint aLengthinBytes ) |
|
420 { |
|
421 return memclr( aDest, aLengthinBytes ); |
|
422 } |
|
423 |
|
424 // --------------------------------------------------------------------------- |
|
425 // From class MWlanOsa. |
|
426 // --------------------------------------------------------------------------- |
|
427 // |
|
428 void* MWlanOsa::MemSet( void* aDest, |
|
429 TInt aValue, |
|
430 TUint aCount ) |
|
431 { |
|
432 return memset( aDest, aValue, aCount ); |
|
433 } |
|
434 |
|
435 // --------------------------------------------------------------------------- |
|
436 // From class MWlanOsa. |
|
437 // --------------------------------------------------------------------------- |
|
438 // |
|
439 TInt64 MWlanOsa::Time() |
|
440 { |
|
441 return Kern::SystemTime(); |
|
442 } |
|
443 |
|
444 // --------------------------------------------------------------------------- |
|
445 // From class MWlanOsa. |
|
446 // --------------------------------------------------------------------------- |
|
447 // |
|
448 void MWlanOsa::BusyWait( TUint aWaitTimeInMicroSeconds ) |
|
449 { |
|
450 const TInt KMicroSecsToNanoSecs( 1000 ); |
|
451 Kern::NanoWait( aWaitTimeInMicroSeconds * KMicroSecsToNanoSecs ); |
|
452 } |
|
453 |
|
454 // --------------------------------------------------------------------------- |
|
455 // From class MWlanOsaExt. |
|
456 // --------------------------------------------------------------------------- |
|
457 // |
|
458 void WlanOsa::MutexAcquire() |
|
459 { |
|
460 TraceDump(MUTEX_LEVEL, ("[WLAN] WlanOsa::MutexAcquire() +")); |
|
461 TraceDump(MUTEX_LEVEL, (("[WLAN] current thread id: %d"), |
|
462 (Kern::CurrentThread()).iId)); |
|
463 |
|
464 // acquire mutex |
|
465 Kern::MutexWait( *(Pimpl().iMutex) ); |
|
466 |
|
467 TraceDump(MUTEX_LEVEL, ("[WLAN] WlanOsa::MutexAcquire() -")); |
|
468 TraceDump(MUTEX_LEVEL, (("[WLAN] current thread id: %d"), |
|
469 (Kern::CurrentThread()).iId)); |
|
470 } |
|
471 |
|
472 // --------------------------------------------------------------------------- |
|
473 // From class MWlanOsaExt. |
|
474 // --------------------------------------------------------------------------- |
|
475 // |
|
476 void WlanOsa::MutexRelease() |
|
477 { |
|
478 TraceDump(MUTEX_LEVEL, ("[WLAN] WlanOsa::MutexRelease() +")); |
|
479 TraceDump(MUTEX_LEVEL, (("[WLAN] current thread id: %d"), |
|
480 (Kern::CurrentThread()).iId)); |
|
481 |
|
482 // release mutex |
|
483 Kern::MutexSignal( *(Pimpl().iMutex) ); |
|
484 |
|
485 TraceDump(MUTEX_LEVEL, ("[WLAN] WlanOsa::MutexRelease() -")); |
|
486 TraceDump(MUTEX_LEVEL, (("[WLAN] current thread id: %d"), |
|
487 (Kern::CurrentThread()).iId)); |
|
488 } |
|
489 |