sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32\memmodel\epoc\nvram.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "plat_priv.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
_LIT(KLitMachineConfigMutex,"MCConfMutex");
|
sl@0
|
21 |
_LIT(KLitRamDriveMutex,"RamDriveMutex");
|
sl@0
|
22 |
_LIT(KLitTheRamDriveChunk,"TheRamDriveChunk");
|
sl@0
|
23 |
|
sl@0
|
24 |
void K::InitNvRam()
|
sl@0
|
25 |
{
|
sl@0
|
26 |
__KTRACE_OPT(KBOOT,Kern::Printf("InitNvRam"));
|
sl@0
|
27 |
TInt r=K::MutexCreate(K::MachineConfigMutex, KLitMachineConfigMutex, NULL, EFalse, KMutexOrdMachineConfig);
|
sl@0
|
28 |
if (r!=KErrNone)
|
sl@0
|
29 |
K::Fault(K::EMachineConfigMutexCreateFailed);
|
sl@0
|
30 |
if (K::ColdStart)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
TheSuperPage().iRamDriveSize=0;
|
sl@0
|
33 |
TheMachineConfig().iLogSize=0;
|
sl@0
|
34 |
TheMachineConfig().iLogMaxSize=0;
|
sl@0
|
35 |
}
|
sl@0
|
36 |
#ifdef __MEMMODEL_FLEXIBLE__
|
sl@0
|
37 |
TheSuperPage().iRamDriveSize=0;
|
sl@0
|
38 |
#endif
|
sl@0
|
39 |
SChunkCreateInfo c;
|
sl@0
|
40 |
TInt ramDriveSize=TheSuperPage().iRamDriveSize;
|
sl@0
|
41 |
c.iGlobal=EFalse;
|
sl@0
|
42 |
c.iAtt=TChunkCreate::ENormal;
|
sl@0
|
43 |
c.iForceFixed=EFalse;
|
sl@0
|
44 |
#ifndef __MEMMODEL_FLEXIBLE__
|
sl@0
|
45 |
c.iOperations=SChunkCreateInfo::EAdjust|SChunkCreateInfo::EAdd;
|
sl@0
|
46 |
#else
|
sl@0
|
47 |
c.iOperations=SChunkCreateInfo::EAdjust;
|
sl@0
|
48 |
#endif
|
sl@0
|
49 |
c.iRunAddress=PP::RamDriveStartAddress;
|
sl@0
|
50 |
c.iPreallocated=ramDriveSize;
|
sl@0
|
51 |
c.iType=ERamDrive;
|
sl@0
|
52 |
c.iMaxSize=PP::RamDriveMaxSize;
|
sl@0
|
53 |
c.iInitialBottom=0;
|
sl@0
|
54 |
c.iInitialTop=0;
|
sl@0
|
55 |
c.iName.Set(KLitTheRamDriveChunk);
|
sl@0
|
56 |
c.iOwner=K::TheKernelProcess;
|
sl@0
|
57 |
TLinAddr runAddr;
|
sl@0
|
58 |
r=K::TheKernelProcess->NewChunk((DChunk*&)PP::TheRamDriveChunk,c,runAddr);
|
sl@0
|
59 |
if (r!=KErrNone)
|
sl@0
|
60 |
K::Fault(K::ERamDriveChunkCreateFailed);
|
sl@0
|
61 |
__KTRACE_OPT(KBOOT,Kern::Printf("Ram Drive size = %08x", ramDriveSize));
|
sl@0
|
62 |
r=TInternalRamDrive::Create();
|
sl@0
|
63 |
if (r!=KErrNone)
|
sl@0
|
64 |
K::Fault(K::ERamDriveInitFailed);
|
sl@0
|
65 |
|
sl@0
|
66 |
__KTRACE_OPT(KBOOT,Kern::Printf("K::InitNvRam() completed"));
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
TInt TInternalRamDrive::Create()
|
sl@0
|
70 |
{
|
sl@0
|
71 |
__KTRACE_OPT(KBOOT,Kern::Printf("TInternalRamDrive::Create()"));
|
sl@0
|
72 |
|
sl@0
|
73 |
// create the RAM drive mutex
|
sl@0
|
74 |
TInt r=K::MutexCreate((DMutex*&)Mutex, KLitRamDriveMutex, NULL, EFalse, KMutexOrdRamDrive);
|
sl@0
|
75 |
if (r!=KErrNone)
|
sl@0
|
76 |
return r;
|
sl@0
|
77 |
__KTRACE_OPT(KBOOT,Kern::Printf("RAM drive mutex created at %08x",Mutex));
|
sl@0
|
78 |
return KErrNone;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
#ifndef __MEMMODEL_FLEXIBLE__
|
sl@0
|
82 |
EXPORT_C TLinAddr TInternalRamDrive::Base()
|
sl@0
|
83 |
//
|
sl@0
|
84 |
// Return the Internal Ram Drive base address
|
sl@0
|
85 |
//
|
sl@0
|
86 |
{
|
sl@0
|
87 |
return (TLinAddr)PP::TheRamDriveChunk->Base(&Kern::CurrentProcess());
|
sl@0
|
88 |
}
|
sl@0
|
89 |
#endif
|
sl@0
|
90 |
|
sl@0
|
91 |
EXPORT_C TInt TInternalRamDrive::Size()
|
sl@0
|
92 |
//
|
sl@0
|
93 |
// Return the Internal Ram Drive size
|
sl@0
|
94 |
//
|
sl@0
|
95 |
{
|
sl@0
|
96 |
return TheSuperPage().iRamDriveSize;
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
EXPORT_C TInt TInternalRamDrive::Adjust(TInt aNewSize)
|
sl@0
|
100 |
//
|
sl@0
|
101 |
// Adjust the size of the internal ram drive
|
sl@0
|
102 |
//
|
sl@0
|
103 |
{
|
sl@0
|
104 |
// If we are shrinking the drive, change the size now in case the
|
sl@0
|
105 |
// machine is reset half way through the chunk adjust
|
sl@0
|
106 |
if (aNewSize<0)
|
sl@0
|
107 |
return KErrArgument;
|
sl@0
|
108 |
if (aNewSize<TheSuperPage().iRamDriveSize)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
TheSuperPage().iRamDriveSize=aNewSize;
|
sl@0
|
111 |
return PP::TheRamDriveChunk->Adjust(aNewSize);
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
// If we are growing the drive, change the size after the adjustment is complete
|
sl@0
|
115 |
// If a reset occurs in the middle of the adjust, the ram drive will be
|
sl@0
|
116 |
// restored to its original state before the adjustment.
|
sl@0
|
117 |
else if (aNewSize>TheSuperPage().iRamDriveSize)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
if (aNewSize>PP::RamDriveMaxSize)
|
sl@0
|
120 |
return KErrDiskFull;
|
sl@0
|
121 |
TInt r=PP::TheRamDriveChunk->Adjust(aNewSize);
|
sl@0
|
122 |
if (r==KErrNoMemory)
|
sl@0
|
123 |
return(KErrDiskFull);
|
sl@0
|
124 |
else if(r==KErrNone)
|
sl@0
|
125 |
TheSuperPage().iRamDriveSize=aNewSize;
|
sl@0
|
126 |
return(r);
|
sl@0
|
127 |
}
|
sl@0
|
128 |
return KErrNone;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
EXPORT_C void TInternalRamDrive::Wait()
|
sl@0
|
132 |
{
|
sl@0
|
133 |
Kern::MutexWait(*Mutex);
|
sl@0
|
134 |
UNLOCK_USER_MEMORY();
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
EXPORT_C void TInternalRamDrive::Signal()
|
sl@0
|
138 |
{
|
sl@0
|
139 |
LOCK_USER_MEMORY();
|
sl@0
|
140 |
Kern::MutexSignal(*Mutex);
|
sl@0
|
141 |
}
|