First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\drivers\medint\iram.cpp
20 #include "variantmediadef.h"
22 _LIT(KPddName, "Media.IRam");
24 class DPhysicalDeviceMediaIRam : public DPhysicalDevice
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);
35 class DMediaDriverIRam : public DMediaDriver
38 DMediaDriverIRam(TInt aMediaId);
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();
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);
56 DPhysicalDeviceMediaIRam::DPhysicalDeviceMediaIRam()
62 iVersion=TVersion(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion);
65 TInt DPhysicalDeviceMediaIRam::Install()
67 // Install the Internal Ram Media PDD.
71 return SetName(&KPddName);
74 void DPhysicalDeviceMediaIRam::GetCaps(TDes8& /*aDes*/) const
76 // Return the media drivers capabilities.
81 TInt DPhysicalDeviceMediaIRam::Create(DBase*& aChannel, TInt aMediaId, const TDesC8* /* anInfo */,const TVersion &aVer)
83 // Create an Internal Ram media driver.
86 if (!Kern::QueryVersionSupported(iVersion,aVer))
87 return KErrNotSupported;
89 DMediaDriverIRam* pD=new DMediaDriverIRam(aMediaId);
92 r=pD->DoCreate(aMediaId);
93 TInternalRamDrive::Unlock();
97 TInt DPhysicalDeviceMediaIRam::Validate(TInt aDeviceType, const TDesC8* /*anInfo*/, const TVersion& aVer)
99 if (!Kern::QueryVersionSupported(iVersion,aVer))
100 return KErrNotSupported;
101 if (aDeviceType!=MEDIA_DEVICE_IRAM)
102 return KErrNotSupported;
106 TInt DPhysicalDeviceMediaIRam::Info(TInt aFunction, TAny*)
108 // Return the priority of this media driver
111 if (aFunction==EPriority)
112 return KMediaDriverPriorityNormal;
113 return KErrNotSupported;
116 DMediaDriverIRam::DMediaDriverIRam(TInt aMediaId)
120 : DMediaDriver(aMediaId)
123 TInt DMediaDriverIRam::DoCreate(TInt /*aMediaId*/)
125 // Create the media driver.
129 TInt size=TInternalRamDrive::Size();
131 return KErrGeneral; // no RAM drive!
132 SetTotalSizeInBytes(size);
136 TInt DMediaDriverIRam::Request(TLocDrvRequest& m)
139 __KTRACE_OPT(KLOCDRV,Kern::Printf(">DMediaDriverIRam::Request %d",request));
140 TInt r=KErrNotSupported;
141 NKern::ThreadEnterCS();
142 TInternalRamDrive::Wait();
145 case DLocalDrive::ECaps:
148 case DLocalDrive::ERead:
151 case DLocalDrive::EWrite:
154 case DLocalDrive::EFormat:
157 case DLocalDrive::EEnlarge:
160 case DLocalDrive::EReduce:
167 TInternalRamDrive::Signal();
168 NKern::ThreadLeaveCS();
169 __KTRACE_OPT(KLOCDRV,Kern::Printf("<DMediaDriverIRam::Request %d",r));
173 void DMediaDriverIRam::Disconnect(DLocalDrive* /*aLocalDrive*/, TThreadMessage*)
175 // no action required
178 void DMediaDriverIRam::NotifyPowerDown()
180 // no action required
183 void DMediaDriverIRam::NotifyEmergencyPowerDown()
185 // no action required
188 TInt DMediaDriverIRam::Caps(TLocDrvRequest& m)
190 TLocalDriveCapsV6& caps=*(TLocalDriveCapsV6*)m.RemoteDes();
191 caps.iType=EMediaRam;
192 caps.iConnectionBusType=EConnectionBusInternal;
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
206 TInt DMediaDriverIRam::Read(TLocDrvRequest& m)
209 Int64 length=m.Length();
210 if (length<0 || pos<0 || (pos+length)>KMaxTInt)
214 if (p+l>TInternalRamDrive::Size())
216 TPtrC8 des((TUint8*)TInternalRamDrive::Base()+p,l);
217 TInt r=m.WriteRemote(&des,0);
221 TInt DMediaDriverIRam::Write(TLocDrvRequest& m)
224 Int64 length=m.Length();
225 if (length<0 || pos<0 || (pos+length)>KMaxTInt)
229 if (p+l>TInternalRamDrive::Size())
231 TPtr8 des((TUint8*)TInternalRamDrive::Base()+p,l,l);
232 TInt r=m.ReadRemote(&des,0);
236 TInt DMediaDriverIRam::Format(TLocDrvRequest& m)
239 Int64 length=m.Length();
240 if (length<0 || pos<0 || (pos+length)>KMaxTInt)
244 if (p+l>TInternalRamDrive::Size())
246 memclr((TUint8*)TInternalRamDrive::Base()+p, l);
250 TInt DMediaDriverIRam::Enlarge(TLocDrvRequest& m)
255 TInt length=(TInt)m.Length();
256 __KTRACE_OPT(KLOCDRV,Kern::Printf(">IRam::Enlarge (%d)",length));
258 Int64 newLen=TotalSizeInBytes();
263 TInt r=TInternalRamDrive::Adjust((TInt)newLen);
266 SetTotalSizeInBytes(newLen,m.Drive());
267 __KTRACE_OPT(KLOCDRV,Kern::Printf("Enlarge-Success (S:0x%lx RS:%d)",TotalSizeInBytes(),TInternalRamDrive::Size()));
269 else if (r==KErrNoMemory)
274 TInt DMediaDriverIRam::Reduce(TLocDrvRequest& m)
276 // Reduce in size the drive
280 TInt length=(TInt)m.Length();
284 __KTRACE_OPT(KLOCDRV,Kern::Printf(">IRam::ReduceSize (%d@%d)",length,(TInt)pos));
286 TUint8 *Trg=(TUint8*)TInternalRamDrive::Base()+(TInt)pos;
287 TInt len=TInternalRamDrive::Size()-((TInt)pos+length);
288 memmove((TAny*)Trg,(TAny*)(Trg+length),len);
289 len=TInternalRamDrive::Size()-length;
290 TInt r=TInternalRamDrive::Adjust(len);
293 SetTotalSizeInBytes(len,m.Drive());
294 __KTRACE_OPT(KLOCDRV,Kern::Printf("ReduceSize-Success (S:0x%lx RS:%d)",TotalSizeInBytes(),TInternalRamDrive::Size()));
299 TInt DMediaDriverIRam::PartitionInfo(TPartitionInfo& anInfo)
301 // Return partition information on the media.
305 anInfo.iPartitionCount=1;
306 anInfo.iEntry[0].iPartitionBaseAddr=0;
307 anInfo.iEntry[0].iPartitionLen=anInfo.iMediaSizeInBytes=TotalSizeInBytes();
308 anInfo.iEntry[0].iPartitionType=KPartitionTypeFAT16;
312 DECLARE_EXTENSION_PDD()
314 return new DPhysicalDeviceMediaIRam;
317 static const TInt IRamDriveNumbers[IRAM_DRIVECOUNT]={IRAM_DRIVELIST};
318 _LIT(KIRamDriveName,IRAM_DRIVENAME);
320 DECLARE_STANDARD_EXTENSION()
322 __KTRACE_OPT(KBOOT,Kern::Printf("Registering IRAM drive"));
324 DPrimaryMediaBase* pM=new DPrimaryMediaBase;
327 r=LocDrv::RegisterMediaDevice(MEDIA_DEVICE_IRAM,IRAM_DRIVECOUNT,&IRamDriveNumbers[0],pM,IRAM_NUMMEDIA,KIRamDriveName);
329 __KTRACE_OPT(KBOOT,Kern::Printf("Registering IRAM drive - return %d",r));