Update contrib.
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\memmodel\epoc\nvram.cpp
18 #include "plat_priv.h"
20 _LIT(KLitMachineConfigMutex,"MCConfMutex");
21 _LIT(KLitRamDriveMutex,"RamDriveMutex");
22 _LIT(KLitTheRamDriveChunk,"TheRamDriveChunk");
26 __KTRACE_OPT(KBOOT,Kern::Printf("InitNvRam"));
27 TInt r=K::MutexCreate(K::MachineConfigMutex, KLitMachineConfigMutex, NULL, EFalse, KMutexOrdMachineConfig);
29 K::Fault(K::EMachineConfigMutexCreateFailed);
32 TheSuperPage().iRamDriveSize=0;
33 TheMachineConfig().iLogSize=0;
34 TheMachineConfig().iLogMaxSize=0;
36 #ifdef __MEMMODEL_FLEXIBLE__
37 TheSuperPage().iRamDriveSize=0;
40 TInt ramDriveSize=TheSuperPage().iRamDriveSize;
42 c.iAtt=TChunkCreate::ENormal;
44 #ifndef __MEMMODEL_FLEXIBLE__
45 c.iOperations=SChunkCreateInfo::EAdjust|SChunkCreateInfo::EAdd;
47 c.iOperations=SChunkCreateInfo::EAdjust;
49 c.iRunAddress=PP::RamDriveStartAddress;
50 c.iPreallocated=ramDriveSize;
52 c.iMaxSize=PP::RamDriveMaxSize;
55 c.iName.Set(KLitTheRamDriveChunk);
56 c.iOwner=K::TheKernelProcess;
58 r=K::TheKernelProcess->NewChunk((DChunk*&)PP::TheRamDriveChunk,c,runAddr);
60 K::Fault(K::ERamDriveChunkCreateFailed);
61 __KTRACE_OPT(KBOOT,Kern::Printf("Ram Drive size = %08x", ramDriveSize));
62 r=TInternalRamDrive::Create();
64 K::Fault(K::ERamDriveInitFailed);
66 __KTRACE_OPT(KBOOT,Kern::Printf("K::InitNvRam() completed"));
69 TInt TInternalRamDrive::Create()
71 __KTRACE_OPT(KBOOT,Kern::Printf("TInternalRamDrive::Create()"));
73 // create the RAM drive mutex
74 TInt r=K::MutexCreate((DMutex*&)Mutex, KLitRamDriveMutex, NULL, EFalse, KMutexOrdRamDrive);
77 __KTRACE_OPT(KBOOT,Kern::Printf("RAM drive mutex created at %08x",Mutex));
81 #ifndef __MEMMODEL_FLEXIBLE__
82 EXPORT_C TLinAddr TInternalRamDrive::Base()
84 // Return the Internal Ram Drive base address
87 return (TLinAddr)PP::TheRamDriveChunk->Base(&Kern::CurrentProcess());
91 EXPORT_C TInt TInternalRamDrive::Size()
93 // Return the Internal Ram Drive size
96 return TheSuperPage().iRamDriveSize;
99 EXPORT_C TInt TInternalRamDrive::Adjust(TInt aNewSize)
101 // Adjust the size of the internal ram drive
104 // If we are shrinking the drive, change the size now in case the
105 // machine is reset half way through the chunk adjust
108 if (aNewSize<TheSuperPage().iRamDriveSize)
110 TheSuperPage().iRamDriveSize=aNewSize;
111 return PP::TheRamDriveChunk->Adjust(aNewSize);
114 // If we are growing the drive, change the size after the adjustment is complete
115 // If a reset occurs in the middle of the adjust, the ram drive will be
116 // restored to its original state before the adjustment.
117 else if (aNewSize>TheSuperPage().iRamDriveSize)
119 if (aNewSize>PP::RamDriveMaxSize)
121 TInt r=PP::TheRamDriveChunk->Adjust(aNewSize);
123 return(KErrDiskFull);
125 TheSuperPage().iRamDriveSize=aNewSize;
131 EXPORT_C void TInternalRamDrive::Wait()
133 Kern::MutexWait(*Mutex);
134 UNLOCK_USER_MEMORY();
137 EXPORT_C void TInternalRamDrive::Signal()
140 Kern::MutexSignal(*Mutex);