wlan_bearer/wlanldd/wlan_symbian/wlanldd_symbian/src/wlldddmausablememory.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:   Implementation of the WlanDmaUsableMemory class.
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 11 %
       
    20 */
       
    21 
       
    22 #include "WlLddWlanLddConfig.h"
       
    23 #include "wlldddmausablememory.h"
       
    24 
       
    25 #include <platform.h>
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // 
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 TUint32 WlanDmaUsableMemory::Init( 
       
    34     TUint32 aSizeInBytes, 
       
    35     TBool aUseCachedMemory )
       
    36     {
       
    37     TraceDump(INIT_LEVEL, (("WLANLDD: init dma usable memory")));
       
    38     TraceDump(INIT_LEVEL, (("size requested: %d"), aSizeInBytes));
       
    39 
       
    40     // extract MMU page size in bytes
       
    41 	iSizeInBytes = Kern::RoundToPageSize( aSizeInBytes );
       
    42 
       
    43     TraceDump(INIT_LEVEL, (("MMU page size: %d"), iSizeInBytes));
       
    44 
       
    45     // allocate a block of physically contiguous RAM  
       
    46     TInt ret( Epoc::AllocPhysicalRam( iSizeInBytes, iPhysicalRamAddr ) );
       
    47     if ( ret != KErrNone )
       
    48         {
       
    49         // this can happen if we have  no memory
       
    50         TraceDump(ERROR_LEVEL, (("WLANLDD: physical RAM alloc failure: %d"), 
       
    51             ret));
       
    52         iSizeInBytes = 0;
       
    53         return 0;
       
    54         }
       
    55 
       
    56     TraceDump(INIT_LEVEL, (("physical RAM address: 0x%08x"), iPhysicalRamAddr));
       
    57 
       
    58     // determine if cached memory shall be used
       
    59     TUint cacheOption = aUseCachedMemory ? 
       
    60         EMapAttrCachedMax : 
       
    61         EMapAttrFullyBlocking;
       
    62 
       
    63     // use a DPlatChunk
       
    64     ret = DPlatChunkHw::New( iChunk, iPhysicalRamAddr,
       
    65                           iSizeInBytes,
       
    66                           EMapAttrUserRw | cacheOption );
       
    67     if ( ret != KErrNone )
       
    68         {
       
    69         // can not fail
       
    70         TraceDump(ERROR_LEVEL, (("WLANLDD: DPlatChunkHw alloc failure: %d"), ret));
       
    71         os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
    72         return 0;
       
    73         }
       
    74 
       
    75     // init success
       
    76     TraceDump(INIT_LEVEL, 
       
    77         (("WlanDmaUsableMemory::Init: Platform Hw Chunk create success with cacheOption: 0x%08x"), 
       
    78         cacheOption));
       
    79     iFlags |= KResourceAcquired;
       
    80     return iSizeInBytes;
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // 
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 void WlanDmaUsableMemory::Finit()
       
    88     {
       
    89     if ( iFlags & KResourceAcquired )
       
    90         {
       
    91         TraceDump(INIT_LEVEL, (("WLANLDD: finit dma usable memory")));
       
    92 
       
    93         iFlags &= ~KResourceAcquired;
       
    94         // close the chunk. This also automatically deletes the object 
       
    95         // as its reference count goes to 0
       
    96         iChunk->Close( NULL );
       
    97 
       
    98         // free the physical ram which was associated with the chunk
       
    99         const TInt ret( Epoc::FreePhysicalRam( 
       
   100             iPhysicalRamAddr, iSizeInBytes ) );
       
   101 
       
   102         iPhysicalRamAddr = 0;
       
   103         iSizeInBytes = 0;
       
   104 
       
   105 #ifndef NDEBUG
       
   106         if ( ret != KErrNone )
       
   107             {
       
   108             // can not fail
       
   109             TraceDump(ERROR_LEVEL, (("WLANLDD: physical RAM free failure: %d"), ret));
       
   110             os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   111             }
       
   112 #endif        
       
   113         }
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // 
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 TLinAddr WlanDmaUsableMemory::Addr( 
       
   121     TUint32 aSizeInBytes )
       
   122     {
       
   123     return (aSizeInBytes <= iSizeInBytes) 
       
   124         ? iChunk->LinearAddress() : NULL;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // 
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 TLinAddr WlanDmaUsableMemory::Addr()
       
   132     {
       
   133     return iChunk->LinearAddress();
       
   134     }