author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 11:08:29 +0300 | |
changeset 247 | d8d70de2bd36 |
parent 109 | b3a1d9898418 |
child 294 | 039a3e647356 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1996-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\drivers\medint\iram.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include "locmedia.h" |
|
19 |
#include "platform.h" |
|
20 |
#include "variantmediadef.h" |
|
21 |
||
22 |
_LIT(KPddName, "Media.IRam"); |
|
23 |
||
24 |
class DPhysicalDeviceMediaIRam : public DPhysicalDevice |
|
25 |
{ |
|
26 |
public: |
|
27 |
DPhysicalDeviceMediaIRam(); |
|
28 |
virtual TInt Install(); |
|
29 |
virtual void GetCaps(TDes8& aDes) const; |
|
30 |
virtual TInt Create(DBase*& aChannel, TInt aMediaId, const TDesC8* anInfo, const TVersion& aVer); |
|
31 |
virtual TInt Validate(TInt aDeviceType, const TDesC8* anInfo, const TVersion& aVer); |
|
32 |
virtual TInt Info(TInt aFunction, TAny* a1); |
|
33 |
}; |
|
34 |
||
35 |
class DMediaDriverIRam : public DMediaDriver |
|
36 |
{ |
|
37 |
public: |
|
38 |
DMediaDriverIRam(TInt aMediaId); |
|
39 |
public: |
|
40 |
// replacing pure virtual |
|
41 |
virtual TInt Request(TLocDrvRequest& aRequest); |
|
42 |
virtual void Disconnect(DLocalDrive* aLocalDrive, TThreadMessage* aMsg); |
|
43 |
virtual TInt PartitionInfo(TPartitionInfo &anInfo); |
|
44 |
virtual void NotifyPowerDown(); |
|
45 |
virtual void NotifyEmergencyPowerDown(); |
|
46 |
public: |
|
47 |
TInt DoCreate(TInt aMediaId); |
|
48 |
TInt Caps(TLocDrvRequest& aRequest); |
|
49 |
TInt Read(TLocDrvRequest& aRequest); |
|
50 |
TInt Write(TLocDrvRequest& aRequest); |
|
51 |
TInt Format(TLocDrvRequest& aRequest); |
|
52 |
TInt Enlarge(TLocDrvRequest& aRequest); |
|
53 |
TInt Reduce(TLocDrvRequest& aRequest); |
|
54 |
}; |
|
55 |
||
56 |
DPhysicalDeviceMediaIRam::DPhysicalDeviceMediaIRam() |
|
57 |
// |
|
58 |
// Constructor |
|
59 |
// |
|
60 |
{ |
|
61 |
iUnitsMask=0x1; |
|
62 |
iVersion=TVersion(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion); |
|
63 |
} |
|
64 |
||
65 |
TInt DPhysicalDeviceMediaIRam::Install() |
|
66 |
// |
|
67 |
// Install the Internal Ram Media PDD. |
|
68 |
// |
|
69 |
{ |
|
70 |
||
71 |
return SetName(&KPddName); |
|
72 |
} |
|
73 |
||
74 |
void DPhysicalDeviceMediaIRam::GetCaps(TDes8& /*aDes*/) const |
|
75 |
// |
|
76 |
// Return the media drivers capabilities. |
|
77 |
// |
|
78 |
{ |
|
79 |
} |
|
80 |
||
81 |
TInt DPhysicalDeviceMediaIRam::Create(DBase*& aChannel, TInt aMediaId, const TDesC8* /* anInfo */,const TVersion &aVer) |
|
82 |
// |
|
83 |
// Create an Internal Ram media driver. |
|
84 |
// |
|
85 |
{ |
|
86 |
if (!Kern::QueryVersionSupported(iVersion,aVer)) |
|
87 |
return KErrNotSupported; |
|
88 |
TInt r=KErrNoMemory; |
|
89 |
DMediaDriverIRam* pD=new DMediaDriverIRam(aMediaId); |
|
90 |
aChannel=pD; |
|
91 |
if (pD) |
|
92 |
r=pD->DoCreate(aMediaId); |
|
93 |
TInternalRamDrive::Unlock(); |
|
94 |
return r; |
|
95 |
} |
|
96 |
||
97 |
TInt DPhysicalDeviceMediaIRam::Validate(TInt aDeviceType, const TDesC8* /*anInfo*/, const TVersion& aVer) |
|
98 |
{ |
|
99 |
if (!Kern::QueryVersionSupported(iVersion,aVer)) |
|
100 |
return KErrNotSupported; |
|
101 |
if (aDeviceType!=MEDIA_DEVICE_IRAM) |
|
102 |
return KErrNotSupported; |
|
103 |
return KErrNone; |
|
104 |
} |
|
105 |
||
106 |
TInt DPhysicalDeviceMediaIRam::Info(TInt aFunction, TAny*) |
|
107 |
// |
|
108 |
// Return the priority of this media driver |
|
109 |
// |
|
110 |
{ |
|
111 |
if (aFunction==EPriority) |
|
112 |
return KMediaDriverPriorityNormal; |
|
113 |
return KErrNotSupported; |
|
114 |
} |
|
115 |
||
116 |
DMediaDriverIRam::DMediaDriverIRam(TInt aMediaId) |
|
117 |
// |
|
118 |
// Constructor. |
|
119 |
// |
|
120 |
: DMediaDriver(aMediaId) |
|
121 |
{} |
|
122 |
||
123 |
TInt DMediaDriverIRam::DoCreate(TInt /*aMediaId*/) |
|
124 |
// |
|
125 |
// Create the media driver. |
|
126 |
// |
|
127 |
{ |
|
128 |
||
129 |
TInt size=TInternalRamDrive::Size(); |
|
130 |
if (size<0) |
|
131 |
return KErrGeneral; // no RAM drive! |
|
132 |
SetTotalSizeInBytes(size); |
|
133 |
return(KErrNone); |
|
134 |
} |
|
135 |
||
136 |
TInt DMediaDriverIRam::Request(TLocDrvRequest& m) |
|
137 |
{ |
|
138 |
TInt request=m.Id(); |
|
139 |
__KTRACE_OPT(KLOCDRV,Kern::Printf(">DMediaDriverIRam::Request %d",request)); |
|
140 |
TInt r=KErrNotSupported; |
|
141 |
NKern::ThreadEnterCS(); |
|
142 |
TInternalRamDrive::Wait(); |
|
143 |
switch (request) |
|
144 |
{ |
|
145 |
case DLocalDrive::ECaps: |
|
146 |
r=Caps(m); |
|
147 |
break; |
|
148 |
case DLocalDrive::ERead: |
|
149 |
r=Read(m); |
|
150 |
break; |
|
151 |
case DLocalDrive::EWrite: |
|
152 |
r=Write(m); |
|
153 |
break; |
|
154 |
case DLocalDrive::EFormat: |
|
155 |
r=Format(m); |
|
156 |
break; |
|
157 |
case DLocalDrive::EEnlarge: |
|
158 |
r=Enlarge(m); |
|
159 |
break; |
|
160 |
case DLocalDrive::EReduce: |
|
161 |
r=Reduce(m); |
|
162 |
break; |
|
163 |
default: |
|
164 |
r=KErrNotSupported; |
|
165 |
break; |
|
166 |
} |
|
167 |
TInternalRamDrive::Signal(); |
|
168 |
NKern::ThreadLeaveCS(); |
|
169 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("<DMediaDriverIRam::Request %d",r)); |
|
170 |
return r; |
|
171 |
} |
|
172 |
||
173 |
void DMediaDriverIRam::Disconnect(DLocalDrive* /*aLocalDrive*/, TThreadMessage*) |
|
174 |
{ |
|
175 |
// no action required |
|
176 |
} |
|
177 |
||
178 |
void DMediaDriverIRam::NotifyPowerDown() |
|
179 |
{ |
|
180 |
// no action required |
|
181 |
} |
|
182 |
||
183 |
void DMediaDriverIRam::NotifyEmergencyPowerDown() |
|
184 |
{ |
|
185 |
// no action required |
|
186 |
} |
|
187 |
||
188 |
TInt DMediaDriverIRam::Caps(TLocDrvRequest& m) |
|
189 |
{ |
|
190 |
TLocalDriveCapsV6& caps=*(TLocalDriveCapsV6*)m.RemoteDes(); |
|
191 |
caps.iType=EMediaRam; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
caps.iConnectionBusType=EConnectionBusInternal; |
0 | 193 |
caps.iDriveAtt=KDriveAttLocal|KDriveAttInternal; |
194 |
caps.iMediaAtt=KMediaAttVariableSize|KMediaAttFormattable; |
|
195 |
caps.iBaseAddress=(TUint8*)TInternalRamDrive::Base(); |
|
196 |
caps.iFileSystemId=KDriveFileSysFAT; |
|
197 |
caps.iPartitionType=KPartitionTypeFAT16; |
|
198 |
caps.iSize=m.Drive()->iPartitionLen; |
|
199 |
caps.iHiddenSectors=0; |
|
200 |
caps.iEraseBlockSize=TInternalRamDrive::MaxSize(); // overload for RAM drive to avoid |
|
201 |
// F32 depending on memory model |
|
202 |
caps.iBlockSize=1; |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
203 |
SetTotalSizeInBytes(caps); |
0 | 204 |
return KErrNone; |
205 |
} |
|
206 |
||
207 |
TInt DMediaDriverIRam::Read(TLocDrvRequest& m) |
|
208 |
{ |
|
209 |
Int64 pos=m.Pos(); |
|
210 |
Int64 length=m.Length(); |
|
211 |
if (length<0 || pos<0 || (pos+length)>KMaxTInt) |
|
212 |
return KErrGeneral; |
|
213 |
TInt p=(TInt)pos; |
|
214 |
TInt l=(TInt)length; |
|
215 |
if (p+l>TInternalRamDrive::Size()) |
|
216 |
return KErrGeneral; |
|
217 |
TPtrC8 des((TUint8*)TInternalRamDrive::Base()+p,l); |
|
218 |
TInt r=m.WriteRemote(&des,0); |
|
219 |
return r; |
|
220 |
} |
|
221 |
||
222 |
TInt DMediaDriverIRam::Write(TLocDrvRequest& m) |
|
223 |
{ |
|
224 |
Int64 pos=m.Pos(); |
|
225 |
Int64 length=m.Length(); |
|
226 |
if (length<0 || pos<0 || (pos+length)>KMaxTInt) |
|
227 |
return KErrGeneral; |
|
228 |
TInt p=(TInt)pos; |
|
229 |
TInt l=(TInt)length; |
|
230 |
if (p+l>TInternalRamDrive::Size()) |
|
231 |
return KErrGeneral; |
|
232 |
TPtr8 des((TUint8*)TInternalRamDrive::Base()+p,l,l); |
|
233 |
TInt r=m.ReadRemote(&des,0); |
|
234 |
return r; |
|
235 |
} |
|
236 |
||
237 |
TInt DMediaDriverIRam::Format(TLocDrvRequest& m) |
|
238 |
{ |
|
239 |
Int64 pos=m.Pos(); |
|
240 |
Int64 length=m.Length(); |
|
241 |
if (length<0 || pos<0 || (pos+length)>KMaxTInt) |
|
242 |
return KErrGeneral; |
|
243 |
TInt p=(TInt)pos; |
|
244 |
TInt l=(TInt)length; |
|
245 |
if (p+l>TInternalRamDrive::Size()) |
|
246 |
return KErrGeneral; |
|
247 |
memclr((TUint8*)TInternalRamDrive::Base()+p, l); |
|
248 |
return KErrNone; |
|
249 |
} |
|
250 |
||
251 |
TInt DMediaDriverIRam::Enlarge(TLocDrvRequest& m) |
|
252 |
// |
|
253 |
// Enlarge the drive |
|
254 |
// |
|
255 |
{ |
|
256 |
TInt length=(TInt)m.Length(); |
|
257 |
__KTRACE_OPT(KLOCDRV,Kern::Printf(">IRam::Enlarge (%d)",length)); |
|
258 |
||
259 |
Int64 newLen=TotalSizeInBytes(); |
|
260 |
newLen+=length; |
|
261 |
if (newLen>KMaxTInt) |
|
262 |
return(KErrGeneral); |
|
263 |
||
264 |
TInt r=TInternalRamDrive::Adjust((TInt)newLen); |
|
265 |
if (r==KErrNone) |
|
266 |
{ |
|
267 |
SetTotalSizeInBytes(newLen,m.Drive()); |
|
268 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("Enlarge-Success (S:0x%lx RS:%d)",TotalSizeInBytes(),TInternalRamDrive::Size())); |
|
269 |
} |
|
270 |
else if (r==KErrNoMemory) |
|
271 |
r=KErrDiskFull; |
|
272 |
return r; |
|
273 |
} |
|
274 |
||
275 |
TInt DMediaDriverIRam::Reduce(TLocDrvRequest& m) |
|
276 |
// |
|
277 |
// Reduce in size the drive |
|
278 |
// |
|
279 |
{ |
|
280 |
Int64 pos=m.Pos(); |
|
281 |
TInt length=(TInt)m.Length(); |
|
282 |
if (pos>KMaxTInt) |
|
283 |
return(KErrGeneral); |
|
284 |
||
285 |
__KTRACE_OPT(KLOCDRV,Kern::Printf(">IRam::ReduceSize (%d@%d)",length,(TInt)pos)); |
|
286 |
||
287 |
TUint8 *Trg=(TUint8*)TInternalRamDrive::Base()+(TInt)pos; |
|
288 |
TInt len=TInternalRamDrive::Size()-((TInt)pos+length); |
|
289 |
memmove((TAny*)Trg,(TAny*)(Trg+length),len); |
|
290 |
len=TInternalRamDrive::Size()-length; |
|
291 |
TInt r=TInternalRamDrive::Adjust(len); |
|
292 |
if (r==KErrNone) |
|
293 |
{ |
|
294 |
SetTotalSizeInBytes(len,m.Drive()); |
|
295 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("ReduceSize-Success (S:0x%lx RS:%d)",TotalSizeInBytes(),TInternalRamDrive::Size())); |
|
296 |
} |
|
297 |
return r; |
|
298 |
} |
|
299 |
||
300 |
TInt DMediaDriverIRam::PartitionInfo(TPartitionInfo& anInfo) |
|
301 |
// |
|
302 |
// Return partition information on the media. |
|
303 |
// |
|
304 |
{ |
|
305 |
||
306 |
anInfo.iPartitionCount=1; |
|
307 |
anInfo.iEntry[0].iPartitionBaseAddr=0; |
|
308 |
anInfo.iEntry[0].iPartitionLen=anInfo.iMediaSizeInBytes=TotalSizeInBytes(); |
|
309 |
anInfo.iEntry[0].iPartitionType=KPartitionTypeFAT16; |
|
310 |
return KErrNone; |
|
311 |
} |
|
312 |
||
313 |
DECLARE_EXTENSION_PDD() |
|
314 |
{ |
|
315 |
return new DPhysicalDeviceMediaIRam; |
|
316 |
} |
|
317 |
||
318 |
static const TInt IRamDriveNumbers[IRAM_DRIVECOUNT]={IRAM_DRIVELIST}; |
|
319 |
_LIT(KIRamDriveName,IRAM_DRIVENAME); |
|
320 |
||
321 |
DECLARE_STANDARD_EXTENSION() |
|
322 |
{ |
|
323 |
__KTRACE_OPT(KBOOT,Kern::Printf("Registering IRAM drive")); |
|
324 |
TInt r=KErrNoMemory; |
|
325 |
DPrimaryMediaBase* pM=new DPrimaryMediaBase; |
|
326 |
if (pM) |
|
327 |
{ |
|
328 |
r=LocDrv::RegisterMediaDevice(MEDIA_DEVICE_IRAM,IRAM_DRIVECOUNT,&IRamDriveNumbers[0],pM,IRAM_NUMMEDIA,KIRamDriveName); |
|
329 |
} |
|
330 |
__KTRACE_OPT(KBOOT,Kern::Printf("Registering IRAM drive - return %d",r)); |
|
331 |
return r; |
|
332 |
} |
|
333 |
||
334 |