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