sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\memmodel\epoc\nvram.cpp sl@0: // sl@0: // sl@0: sl@0: #include "plat_priv.h" sl@0: sl@0: _LIT(KLitMachineConfigMutex,"MCConfMutex"); sl@0: _LIT(KLitRamDriveMutex,"RamDriveMutex"); sl@0: _LIT(KLitTheRamDriveChunk,"TheRamDriveChunk"); sl@0: sl@0: void K::InitNvRam() sl@0: { sl@0: __KTRACE_OPT(KBOOT,Kern::Printf("InitNvRam")); sl@0: TInt r=K::MutexCreate(K::MachineConfigMutex, KLitMachineConfigMutex, NULL, EFalse, KMutexOrdMachineConfig); sl@0: if (r!=KErrNone) sl@0: K::Fault(K::EMachineConfigMutexCreateFailed); sl@0: if (K::ColdStart) sl@0: { sl@0: TheSuperPage().iRamDriveSize=0; sl@0: TheMachineConfig().iLogSize=0; sl@0: TheMachineConfig().iLogMaxSize=0; sl@0: } sl@0: #ifdef __MEMMODEL_FLEXIBLE__ sl@0: TheSuperPage().iRamDriveSize=0; sl@0: #endif sl@0: SChunkCreateInfo c; sl@0: TInt ramDriveSize=TheSuperPage().iRamDriveSize; sl@0: c.iGlobal=EFalse; sl@0: c.iAtt=TChunkCreate::ENormal; sl@0: c.iForceFixed=EFalse; sl@0: #ifndef __MEMMODEL_FLEXIBLE__ sl@0: c.iOperations=SChunkCreateInfo::EAdjust|SChunkCreateInfo::EAdd; sl@0: #else sl@0: c.iOperations=SChunkCreateInfo::EAdjust; sl@0: #endif sl@0: c.iRunAddress=PP::RamDriveStartAddress; sl@0: c.iPreallocated=ramDriveSize; sl@0: c.iType=ERamDrive; sl@0: c.iMaxSize=PP::RamDriveMaxSize; sl@0: c.iInitialBottom=0; sl@0: c.iInitialTop=0; sl@0: c.iName.Set(KLitTheRamDriveChunk); sl@0: c.iOwner=K::TheKernelProcess; sl@0: TLinAddr runAddr; sl@0: r=K::TheKernelProcess->NewChunk((DChunk*&)PP::TheRamDriveChunk,c,runAddr); sl@0: if (r!=KErrNone) sl@0: K::Fault(K::ERamDriveChunkCreateFailed); sl@0: __KTRACE_OPT(KBOOT,Kern::Printf("Ram Drive size = %08x", ramDriveSize)); sl@0: r=TInternalRamDrive::Create(); sl@0: if (r!=KErrNone) sl@0: K::Fault(K::ERamDriveInitFailed); sl@0: sl@0: __KTRACE_OPT(KBOOT,Kern::Printf("K::InitNvRam() completed")); sl@0: } sl@0: sl@0: TInt TInternalRamDrive::Create() sl@0: { sl@0: __KTRACE_OPT(KBOOT,Kern::Printf("TInternalRamDrive::Create()")); sl@0: sl@0: // create the RAM drive mutex sl@0: TInt r=K::MutexCreate((DMutex*&)Mutex, KLitRamDriveMutex, NULL, EFalse, KMutexOrdRamDrive); sl@0: if (r!=KErrNone) sl@0: return r; sl@0: __KTRACE_OPT(KBOOT,Kern::Printf("RAM drive mutex created at %08x",Mutex)); sl@0: return KErrNone; sl@0: } sl@0: sl@0: #ifndef __MEMMODEL_FLEXIBLE__ sl@0: EXPORT_C TLinAddr TInternalRamDrive::Base() sl@0: // sl@0: // Return the Internal Ram Drive base address sl@0: // sl@0: { sl@0: return (TLinAddr)PP::TheRamDriveChunk->Base(&Kern::CurrentProcess()); sl@0: } sl@0: #endif sl@0: sl@0: EXPORT_C TInt TInternalRamDrive::Size() sl@0: // sl@0: // Return the Internal Ram Drive size sl@0: // sl@0: { sl@0: return TheSuperPage().iRamDriveSize; sl@0: } sl@0: sl@0: EXPORT_C TInt TInternalRamDrive::Adjust(TInt aNewSize) sl@0: // sl@0: // Adjust the size of the internal ram drive sl@0: // sl@0: { sl@0: // If we are shrinking the drive, change the size now in case the sl@0: // machine is reset half way through the chunk adjust sl@0: if (aNewSize<0) sl@0: return KErrArgument; sl@0: if (aNewSizeAdjust(aNewSize); sl@0: } sl@0: sl@0: // If we are growing the drive, change the size after the adjustment is complete sl@0: // If a reset occurs in the middle of the adjust, the ram drive will be sl@0: // restored to its original state before the adjustment. sl@0: else if (aNewSize>TheSuperPage().iRamDriveSize) sl@0: { sl@0: if (aNewSize>PP::RamDriveMaxSize) sl@0: return KErrDiskFull; sl@0: TInt r=PP::TheRamDriveChunk->Adjust(aNewSize); sl@0: if (r==KErrNoMemory) sl@0: return(KErrDiskFull); sl@0: else if(r==KErrNone) sl@0: TheSuperPage().iRamDriveSize=aNewSize; sl@0: return(r); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: EXPORT_C void TInternalRamDrive::Wait() sl@0: { sl@0: Kern::MutexWait(*Mutex); sl@0: UNLOCK_USER_MEMORY(); sl@0: } sl@0: sl@0: EXPORT_C void TInternalRamDrive::Signal() sl@0: { sl@0: LOCK_USER_MEMORY(); sl@0: Kern::MutexSignal(*Mutex); sl@0: }