wlan_bearer/wlanldd/wlan_symbian/osa_symbian/src/osaplatformhwchunk.cpp
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     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:   WlanPlatformHwChunk implementation
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 8 %
       
    20 */
       
    21 
       
    22 #include "osa_includeme.h"
       
    23 
       
    24 #include <wlanosa.h>
       
    25 #include <platform.h>
       
    26 
       
    27 #include "osaplatformhwchunk.h"
       
    28 #include "osachunk.h"
       
    29 
       
    30 struct WlanPlatformHwChunkImpl : public DBase, public WlanObject
       
    31     {
       
    32 
       
    33     /**
       
    34      * Ctor
       
    35      *
       
    36      * @since S60 v3.2
       
    37      * @param aStartOfBuf begin of the memory buffer
       
    38      * @param aEndOfBuf 1 past end of the memory buffer
       
    39      * @param aPlatChunkHw platform chunk object
       
    40      * @param aPhysRamAddr physical ram address
       
    41      * @param aPhysRamSize size of the physical ram
       
    42      * @param aAllocationUnit size of the allocation unit in bytes
       
    43      */
       
    44     WlanPlatformHwChunkImpl( 
       
    45         TUint8* aStartOfBuf, 
       
    46         TUint8* aEndOfBuf, 
       
    47         DPlatChunkHw** aPlatChunkHw, 
       
    48         TPhysAddr aPhysRamAddr, 
       
    49         TInt aPhysRamSize,
       
    50         TInt aAllocationUnit );
       
    51 
       
    52     /**
       
    53      * Dtor
       
    54      *
       
    55      * @since S60 v3.2
       
    56      */
       
    57     virtual ~WlanPlatformHwChunkImpl();
       
    58 
       
    59     /**
       
    60      * Deallocate acquired resources (if any) 
       
    61      *
       
    62      * @since S60 v3.2
       
    63      */
       
    64     inline void Dispose();
       
    65 
       
    66     /**
       
    67      * the one and only chunk
       
    68      * Own.
       
    69      */
       
    70     WlanChunk*      iChunk;
       
    71 
       
    72     /**
       
    73      * the one and only platform chunk
       
    74      * Own.
       
    75      */
       
    76     DPlatChunkHw*   iPlatChunk;
       
    77 
       
    78     /**
       
    79      * physical ram address
       
    80      */
       
    81     TPhysAddr       iPhysRamAddr;
       
    82 
       
    83     /**
       
    84      * physical ram size
       
    85      */
       
    86     TInt            iPhysRamSize;
       
    87     
       
    88 private:
       
    89         
       
    90     // Prohibit copy constructor.
       
    91     WlanPlatformHwChunkImpl( const WlanPlatformHwChunkImpl& );
       
    92     // Prohibit assigment operator.
       
    93     WlanPlatformHwChunkImpl& operator= ( 
       
    94         const WlanPlatformHwChunkImpl& );        
       
    95     };
       
    96 
       
    97 // ======== MEMBER FUNCTIONS ========
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // 
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 inline TInt WlanPlatformHwChunk::RoundToPageSize(  TInt aSizeInBytes  )
       
   104     {
       
   105     TraceDump(INFO_LEVEL, ("[WLAN] WlanPlatformHwChunk::RoundToPageSize +"));
       
   106 
       
   107     // extract MMU page size in bytes
       
   108 	aSizeInBytes = Kern::RoundToPageSize( aSizeInBytes );
       
   109 
       
   110     TraceDump(INFO_LEVEL, ("[WLAN] WlanPlatformHwChunk::RoundToPageSize -"));
       
   111 
       
   112     return aSizeInBytes;
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // 
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 inline TBool WlanPlatformHwChunk::AllocatePhysicalRam( TInt aSizeInBytes, 
       
   120                                                        TPhysAddr& aPhysAddr )
       
   121     {
       
   122     TBool ret( ETrue );
       
   123     TraceDump(INFO_LEVEL, 
       
   124         ("[WLAN] WlanPlatformHwChunk::AllocatePhysicalRam +"));
       
   125 
       
   126     const TInt ret_code( Epoc::AllocPhysicalRam( aSizeInBytes, aPhysAddr ) );
       
   127     if ( ret_code != KErrNone )
       
   128     {
       
   129     // this can happen if we have  no memory
       
   130     ret = EFalse;
       
   131     TraceDump(ERROR_LEVEL, (("[WLAN] error: allocation: %d"), ret_code));
       
   132     Trace( ERROR_LEVEL, 
       
   133         reinterpret_cast<const TInt8*>(WLAN_FILE), __LINE__ );
       
   134     }
       
   135 
       
   136     TraceDump(INFO_LEVEL, 
       
   137         ("[WLAN] WlanPlatformHwChunk::AllocatePhysicalRam -"));
       
   138 
       
   139     return ret;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // 
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 inline void WlanPlatformHwChunk::FreePhysicalRam( TPhysAddr aPhysRamAddr, 
       
   147                                                   TInt aPhysRamSize )
       
   148     {
       
   149     TraceDump(INFO_LEVEL, ("[WLAN] WlanPlatformHwChunk::FreePhysicalRam +"));
       
   150 
       
   151     const TInt ret = Epoc::FreePhysicalRam( aPhysRamAddr, aPhysRamSize );
       
   152     if ( ret != KErrNone )
       
   153         {
       
   154         // no valid use case exists for this code path to be taken
       
   155         TraceDump(CRIT_LEVEL, (("[WLAN] critical: value: %d"), ret));
       
   156         MWlanOsa::Assert( 
       
   157             reinterpret_cast<const TInt8*>(WLAN_FILE), __LINE__ );
       
   158         }
       
   159     else
       
   160         {
       
   161         // left intentionally empty
       
   162         }
       
   163 
       
   164     TraceDump(INFO_LEVEL, ("[WLAN] WlanPlatformHwChunk::FreePhysicalRam -"));
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // 
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 WlanPlatformHwChunkImpl::WlanPlatformHwChunkImpl( 
       
   172     TUint8* aStartOfBuf, 
       
   173     TUint8* aEndOfBuf,
       
   174     DPlatChunkHw** aPlatChunkHw,
       
   175     TPhysAddr aPhysRamAddr, 
       
   176     TInt aPhysRamSize,
       
   177     TInt aAllocationUnit )
       
   178     : iChunk( NULL ), iPlatChunk( *aPlatChunkHw ), 
       
   179     iPhysRamAddr( aPhysRamAddr ), iPhysRamSize( aPhysRamSize )
       
   180     {
       
   181     TraceDump(INFO_LEVEL, 
       
   182         (("[WLAN] WlanPlatformHwChunkImpl ctor +: 0x%08x"), this));
       
   183 
       
   184     iChunk = new WlanChunk( aStartOfBuf, aEndOfBuf, aAllocationUnit );
       
   185     if ( iChunk )
       
   186         {
       
   187         if ( iChunk->IsValid() )
       
   188             {
       
   189             Validate();     // mark as valid
       
   190             }
       
   191         else
       
   192             {
       
   193             TraceDump(ERROR_LEVEL, ("[WLAN] error: allocation"));
       
   194             Trace( ERROR_LEVEL, 
       
   195                 reinterpret_cast<const TInt8*>(WLAN_FILE), __LINE__ );
       
   196 
       
   197             InValidate();   // mark as invalid
       
   198 
       
   199             // chunk deallocated in dtor so we don't have to do it here
       
   200             }
       
   201         }
       
   202     else
       
   203         {
       
   204         // allocation failure
       
   205         TraceDump(ERROR_LEVEL, ("[WLAN] error: allocation"));
       
   206         Trace( ERROR_LEVEL, 
       
   207             reinterpret_cast<const TInt8*>(WLAN_FILE), __LINE__ );
       
   208 
       
   209         InValidate();   // mark as invalid
       
   210         }
       
   211 
       
   212     TraceDump(INFO_LEVEL, 
       
   213         (("[WLAN] WlanPlatformHwChunkImpl ctor -: 0x%08x"), this));
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // 
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 WlanPlatformHwChunkImpl::~WlanPlatformHwChunkImpl()
       
   221     {
       
   222     TraceDump(INFO_LEVEL, 
       
   223         (("[WLAN] WlanPlatformHwChunkImpl dtor +: 0x%08x"), this));
       
   224 
       
   225     Dispose();
       
   226 
       
   227     TraceDump(INFO_LEVEL, 
       
   228         (("[WLAN] WlanPlatformHwChunkImpl dtor +: 0x%08x"), this));
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // only 1 call point. That's the reason for inlining
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 inline void WlanPlatformHwChunkImpl::Dispose()
       
   236     {
       
   237     TraceDump(INFO_LEVEL, 
       
   238         (("[WLAN] WlanPlatformHwChunkImpl::Dispose +: 0x%08x"), this));
       
   239 
       
   240     // NOTE: always dellocate the chunk prior freeing the memory associated to
       
   241     // it
       
   242     delete iChunk;
       
   243     iChunk = NULL;
       
   244 
       
   245     if ( iPlatChunk )
       
   246         {
       
   247         // close the chunk. This also automatically deletes the object 
       
   248         // as its reference count goes to 0
       
   249         iPlatChunk->Close( NULL );
       
   250         // free the physical ram which was associated with the chunk
       
   251         WlanPlatformHwChunk::FreePhysicalRam( iPhysRamAddr, iPhysRamSize );
       
   252         }
       
   253     else
       
   254         {
       
   255         // left intentionally empty
       
   256         }
       
   257 
       
   258     TraceDump(INFO_LEVEL, 
       
   259         (("[WLAN] WlanPlatformHwChunkImpl::Dispose -: 0x%08x"), this));
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // 
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 inline WlanPlatformHwChunkImpl& WlanPlatformHwChunk::Pimpl()
       
   267     {
       
   268     return *iPimpl;
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // 
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 inline const WlanPlatformHwChunkImpl& WlanPlatformHwChunk::Pimpl() const
       
   276     {
       
   277     return *iPimpl;
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // 
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 WlanPlatformHwChunk::WlanPlatformHwChunk( 
       
   285     TInt aSizeInBytes, 
       
   286     TBool aUseCachedMemory,
       
   287     TInt aAllocationUnit ) 
       
   288     : iPimpl( NULL ), iUseCachedMemory ( aUseCachedMemory )
       
   289     {
       
   290     TraceDump(INFO_LEVEL, 
       
   291         (("[WLAN] WlanPlatformHwChunk ctor +: 0x%08x"), this));
       
   292 
       
   293     TBool ret( EFalse );
       
   294     TPhysAddr phys_ram_addr( 0 );   // physical ram address
       
   295 
       
   296     TraceDump(PLAT_HW_CHUNK, 
       
   297         (("[WLAN] WlanPlatformHwChunk requested memory size: %d"), 
       
   298         aSizeInBytes));
       
   299 
       
   300     // round up request to MMU page size boundary
       
   301     const TInt phys_ram_size( RoundToPageSize( aSizeInBytes ) );
       
   302 
       
   303     TraceDump(PLAT_HW_CHUNK, 
       
   304         (("[WLAN] WlanPlatformHwChunk memory size to be aquired: %d"), 
       
   305         phys_ram_size));
       
   306 
       
   307     // allocate the physical ram
       
   308     ret = AllocatePhysicalRam( phys_ram_size, phys_ram_addr );
       
   309     
       
   310     if ( ret )
       
   311         {
       
   312         // physical ram allocation success
       
   313         // allocate hw chunk for the physical ram
       
   314         ret = AllocateHardwareChunk( 
       
   315                 phys_ram_addr, 
       
   316                 phys_ram_size, 
       
   317                 aAllocationUnit );
       
   318         if ( ret )
       
   319             {
       
   320             // chunk creation success
       
   321             Validate();     // mark as valid
       
   322             }
       
   323         else
       
   324             {
       
   325             // chunk creation failure
       
   326             // free the physical ram 
       
   327             FreePhysicalRam( phys_ram_addr, phys_ram_size );
       
   328             InValidate();   // mark as invalid
       
   329             }
       
   330         }
       
   331     else
       
   332         {
       
   333         // physical ram allocation failure
       
   334         InValidate();   // mark as invalid
       
   335         }
       
   336 
       
   337     TraceDump(INFO_LEVEL, 
       
   338         (("[WLAN] WlanPlatformHwChunk ctor -: 0x%08x"), this));
       
   339     }
       
   340 
       
   341 // ---------------------------------------------------------------------------
       
   342 // 
       
   343 // ---------------------------------------------------------------------------
       
   344 //
       
   345 WlanPlatformHwChunk::~WlanPlatformHwChunk()
       
   346     {
       
   347     TraceDump(INFO_LEVEL, 
       
   348         (("[WLAN] WlanPlatformHwChunk dtor +: 0x%08x"), this));
       
   349 
       
   350     delete iPimpl;
       
   351 
       
   352     TraceDump(INFO_LEVEL, 
       
   353         (("[WLAN] WlanPlatformHwChunk dtor -: 0x%08x"), this));
       
   354     }
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // only 1 call point thats the reason for inlining
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 inline TBool WlanPlatformHwChunk::AllocateHardwareChunk( 
       
   361     TPhysAddr aPhysRamAddr, 
       
   362     TInt aPhysRamSize,
       
   363     TInt aAllocationUnit )
       
   364     {
       
   365     TraceDump(INFO_LEVEL, 
       
   366         (("[WLAN] WlanPlatformHwChunk::AllocateHardwareChunk +: 0x%08x"), 
       
   367         this));
       
   368 
       
   369     TBool ret( EFalse );
       
   370 
       
   371     // determine if cached memory shall be used
       
   372     TUint cacheOption = iUseCachedMemory ? 
       
   373         EMapAttrCachedMax : 
       
   374         EMapAttrFullyBlocking;
       
   375 
       
   376     // lets create a hw chunk for our physical ram
       
   377     DPlatChunkHw* chunk = NULL;
       
   378     TInt code = DPlatChunkHw::New( 
       
   379         chunk, aPhysRamAddr, aPhysRamSize, 
       
   380         EMapAttrSupRw | cacheOption );
       
   381 
       
   382     if ( KErrNone != code )
       
   383         {
       
   384         // creation error -> bail out
       
   385         TraceDump(ERROR_LEVEL, (("[WLAN] error: allocation %d"), code));
       
   386         Trace( ERROR_LEVEL, 
       
   387             reinterpret_cast<const TInt8*>(WLAN_FILE), __LINE__ );
       
   388 
       
   389         TraceDump(INFO_LEVEL, 
       
   390             (("[WLAN] WlanPlatformHwChunk::AllocateHardwareChunk -: 0x%08x"), 
       
   391             this));
       
   392 
       
   393         return ret;
       
   394         }
       
   395     else
       
   396         {
       
   397         TraceDump(PLAT_HW_CHUNK, 
       
   398             (("[WLAN] Platform Hw Chunk create success with cacheOption: 0x%08x"), 
       
   399             cacheOption));
       
   400         }
       
   401 
       
   402     // hw chunk creation success proceed
       
   403     iPimpl = new WlanPlatformHwChunkImpl( 
       
   404         reinterpret_cast<TUint8*>(chunk->LinearAddress()), 
       
   405         (reinterpret_cast<TUint8*>(chunk->LinearAddress())) + aPhysRamSize,
       
   406         &chunk,
       
   407         aPhysRamAddr,
       
   408         aPhysRamSize,
       
   409         aAllocationUnit );
       
   410 
       
   411     if ( iPimpl )
       
   412         {
       
   413         // success -> validate implementation
       
   414         if ( Pimpl().IsValid() )
       
   415             {
       
   416             Validate();     // we are valid to go
       
   417             ret = ETrue;
       
   418             }
       
   419         else
       
   420             {
       
   421             TraceDump(ERROR_LEVEL, ("[WLAN] error: allocation"));
       
   422             Trace( ERROR_LEVEL, 
       
   423                 reinterpret_cast<const TInt8*>(WLAN_FILE), __LINE__ );
       
   424 
       
   425             InValidate();   // we are invalid to go
       
   426 
       
   427             // allways dealloc in dtor
       
   428             }       
       
   429         }
       
   430     else
       
   431         {
       
   432         // allocation failed -> trace
       
   433         TraceDump(ERROR_LEVEL, ("[WLAN] error: allocation"));
       
   434         Trace( ERROR_LEVEL, 
       
   435             reinterpret_cast<const TInt8*>(WLAN_FILE), __LINE__ );
       
   436 
       
   437         // we must now deallocate allocated resources
       
   438         // allways close the chunk
       
   439         // this also automatically deletes the object 
       
   440         // as its reference count goes to 0
       
   441         chunk->Close( NULL );
       
   442         }
       
   443 
       
   444     TraceDump(INFO_LEVEL, 
       
   445         (("[WLAN] WlanPlatformHwChunk::AllocateHardwareChunk -: 0x%08x"), 
       
   446         this));
       
   447 
       
   448     return ret;
       
   449     }
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // 
       
   453 // ---------------------------------------------------------------------------
       
   454 //
       
   455 MWlanOsaChunkBase& WlanPlatformHwChunk::Chunk()
       
   456     {
       
   457     return *(Pimpl().iChunk);
       
   458     }
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // 
       
   462 // ---------------------------------------------------------------------------
       
   463 //
       
   464 const MWlanOsaChunkBase& WlanPlatformHwChunk::Chunk() const
       
   465     {
       
   466     return *(Pimpl().iChunk);
       
   467     }