os/kernelhwsrv/kernel/eka/memmodel/epoc/nvram.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/memmodel/epoc/nvram.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,141 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\memmodel\epoc\nvram.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "plat_priv.h"
    1.22 +
    1.23 +_LIT(KLitMachineConfigMutex,"MCConfMutex");
    1.24 +_LIT(KLitRamDriveMutex,"RamDriveMutex");
    1.25 +_LIT(KLitTheRamDriveChunk,"TheRamDriveChunk");
    1.26 +
    1.27 +void K::InitNvRam()
    1.28 +	{
    1.29 +	__KTRACE_OPT(KBOOT,Kern::Printf("InitNvRam"));
    1.30 +	TInt r=K::MutexCreate(K::MachineConfigMutex, KLitMachineConfigMutex, NULL, EFalse, KMutexOrdMachineConfig);
    1.31 +	if (r!=KErrNone)
    1.32 +		K::Fault(K::EMachineConfigMutexCreateFailed);
    1.33 +	if (K::ColdStart)
    1.34 +		{
    1.35 +		TheSuperPage().iRamDriveSize=0;
    1.36 +		TheMachineConfig().iLogSize=0;
    1.37 +		TheMachineConfig().iLogMaxSize=0;
    1.38 +		}
    1.39 +#ifdef __MEMMODEL_FLEXIBLE__
    1.40 +	TheSuperPage().iRamDriveSize=0;
    1.41 +#endif
    1.42 +	SChunkCreateInfo c;
    1.43 +	TInt ramDriveSize=TheSuperPage().iRamDriveSize;
    1.44 +	c.iGlobal=EFalse;
    1.45 +	c.iAtt=TChunkCreate::ENormal;
    1.46 +	c.iForceFixed=EFalse;
    1.47 +#ifndef __MEMMODEL_FLEXIBLE__
    1.48 +	c.iOperations=SChunkCreateInfo::EAdjust|SChunkCreateInfo::EAdd;
    1.49 +#else
    1.50 +	c.iOperations=SChunkCreateInfo::EAdjust;
    1.51 +#endif
    1.52 +	c.iRunAddress=PP::RamDriveStartAddress;
    1.53 +	c.iPreallocated=ramDriveSize;
    1.54 +	c.iType=ERamDrive;
    1.55 +	c.iMaxSize=PP::RamDriveMaxSize;
    1.56 +	c.iInitialBottom=0;
    1.57 +	c.iInitialTop=0;
    1.58 +	c.iName.Set(KLitTheRamDriveChunk);
    1.59 +	c.iOwner=K::TheKernelProcess;
    1.60 +	TLinAddr runAddr;
    1.61 +	r=K::TheKernelProcess->NewChunk((DChunk*&)PP::TheRamDriveChunk,c,runAddr);
    1.62 +	if (r!=KErrNone)
    1.63 +		K::Fault(K::ERamDriveChunkCreateFailed);
    1.64 +	__KTRACE_OPT(KBOOT,Kern::Printf("Ram Drive size = %08x", ramDriveSize));
    1.65 +	r=TInternalRamDrive::Create();
    1.66 +	if (r!=KErrNone)
    1.67 +		K::Fault(K::ERamDriveInitFailed);
    1.68 +
    1.69 +	__KTRACE_OPT(KBOOT,Kern::Printf("K::InitNvRam() completed"));
    1.70 +	}
    1.71 +
    1.72 +TInt TInternalRamDrive::Create()
    1.73 +	{
    1.74 +	__KTRACE_OPT(KBOOT,Kern::Printf("TInternalRamDrive::Create()"));
    1.75 +
    1.76 +	// create the RAM drive mutex
    1.77 +	TInt r=K::MutexCreate((DMutex*&)Mutex, KLitRamDriveMutex, NULL, EFalse, KMutexOrdRamDrive);
    1.78 +	if (r!=KErrNone)
    1.79 +		return r;
    1.80 +	__KTRACE_OPT(KBOOT,Kern::Printf("RAM drive mutex created at %08x",Mutex));
    1.81 +	return KErrNone;
    1.82 +	}
    1.83 +
    1.84 +#ifndef __MEMMODEL_FLEXIBLE__
    1.85 +EXPORT_C TLinAddr TInternalRamDrive::Base()
    1.86 +//
    1.87 +// Return the Internal Ram Drive base address
    1.88 +//
    1.89 +	{
    1.90 +	return (TLinAddr)PP::TheRamDriveChunk->Base(&Kern::CurrentProcess());
    1.91 +	}
    1.92 +#endif
    1.93 +
    1.94 +EXPORT_C TInt TInternalRamDrive::Size()
    1.95 +//
    1.96 +// Return the Internal Ram Drive size
    1.97 +//
    1.98 +	{
    1.99 +	return TheSuperPage().iRamDriveSize;
   1.100 +	}
   1.101 +
   1.102 +EXPORT_C TInt TInternalRamDrive::Adjust(TInt aNewSize)
   1.103 +//
   1.104 +// Adjust the size of the internal ram drive
   1.105 +//
   1.106 +	{
   1.107 +	// If we are shrinking the drive, change the size now in case the
   1.108 +	// machine is reset half way through the chunk adjust
   1.109 +	if (aNewSize<0)
   1.110 +		return KErrArgument;
   1.111 +	if (aNewSize<TheSuperPage().iRamDriveSize)
   1.112 +		{
   1.113 +		TheSuperPage().iRamDriveSize=aNewSize;
   1.114 +		return PP::TheRamDriveChunk->Adjust(aNewSize);
   1.115 +		}
   1.116 +
   1.117 +	// If we are growing the drive, change the size after the adjustment is complete
   1.118 +	// If a reset occurs in the middle of the adjust, the ram drive will be
   1.119 +	// restored to its original state before the adjustment.
   1.120 +	else if (aNewSize>TheSuperPage().iRamDriveSize)
   1.121 +		{
   1.122 +		if (aNewSize>PP::RamDriveMaxSize)
   1.123 +			return KErrDiskFull;
   1.124 +		TInt r=PP::TheRamDriveChunk->Adjust(aNewSize);
   1.125 +		if (r==KErrNoMemory)
   1.126 +			return(KErrDiskFull);
   1.127 +		else if(r==KErrNone)
   1.128 +			TheSuperPage().iRamDriveSize=aNewSize;
   1.129 +		return(r);
   1.130 +		}
   1.131 +	return KErrNone;
   1.132 +	}
   1.133 +
   1.134 +EXPORT_C void TInternalRamDrive::Wait()
   1.135 +	{
   1.136 +	Kern::MutexWait(*Mutex);
   1.137 +	UNLOCK_USER_MEMORY();
   1.138 +	}
   1.139 +
   1.140 +EXPORT_C void TInternalRamDrive::Signal()
   1.141 +	{
   1.142 +	LOCK_USER_MEMORY();
   1.143 +	Kern::MutexSignal(*Mutex);
   1.144 +	}