sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\drivers\medint\iram.cpp sl@0: // sl@0: // sl@0: sl@0: #include "locmedia.h" sl@0: #include "platform.h" sl@0: #include "variantmediadef.h" sl@0: sl@0: _LIT(KPddName, "Media.IRam"); sl@0: sl@0: class DPhysicalDeviceMediaIRam : public DPhysicalDevice sl@0: { sl@0: public: sl@0: DPhysicalDeviceMediaIRam(); sl@0: virtual TInt Install(); sl@0: virtual void GetCaps(TDes8& aDes) const; sl@0: virtual TInt Create(DBase*& aChannel, TInt aMediaId, const TDesC8* anInfo, const TVersion& aVer); sl@0: virtual TInt Validate(TInt aDeviceType, const TDesC8* anInfo, const TVersion& aVer); sl@0: virtual TInt Info(TInt aFunction, TAny* a1); sl@0: }; sl@0: sl@0: class DMediaDriverIRam : public DMediaDriver sl@0: { sl@0: public: sl@0: DMediaDriverIRam(TInt aMediaId); sl@0: public: sl@0: // replacing pure virtual sl@0: virtual TInt Request(TLocDrvRequest& aRequest); sl@0: virtual void Disconnect(DLocalDrive* aLocalDrive, TThreadMessage* aMsg); sl@0: virtual TInt PartitionInfo(TPartitionInfo &anInfo); sl@0: virtual void NotifyPowerDown(); sl@0: virtual void NotifyEmergencyPowerDown(); sl@0: public: sl@0: TInt DoCreate(TInt aMediaId); sl@0: TInt Caps(TLocDrvRequest& aRequest); sl@0: TInt Read(TLocDrvRequest& aRequest); sl@0: TInt Write(TLocDrvRequest& aRequest); sl@0: TInt Format(TLocDrvRequest& aRequest); sl@0: TInt Enlarge(TLocDrvRequest& aRequest); sl@0: TInt Reduce(TLocDrvRequest& aRequest); sl@0: }; sl@0: sl@0: DPhysicalDeviceMediaIRam::DPhysicalDeviceMediaIRam() sl@0: // sl@0: // Constructor sl@0: // sl@0: { sl@0: iUnitsMask=0x1; sl@0: iVersion=TVersion(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion); sl@0: } sl@0: sl@0: TInt DPhysicalDeviceMediaIRam::Install() sl@0: // sl@0: // Install the Internal Ram Media PDD. sl@0: // sl@0: { sl@0: sl@0: return SetName(&KPddName); sl@0: } sl@0: sl@0: void DPhysicalDeviceMediaIRam::GetCaps(TDes8& /*aDes*/) const sl@0: // sl@0: // Return the media drivers capabilities. sl@0: // sl@0: { sl@0: } sl@0: sl@0: TInt DPhysicalDeviceMediaIRam::Create(DBase*& aChannel, TInt aMediaId, const TDesC8* /* anInfo */,const TVersion &aVer) sl@0: // sl@0: // Create an Internal Ram media driver. sl@0: // sl@0: { sl@0: if (!Kern::QueryVersionSupported(iVersion,aVer)) sl@0: return KErrNotSupported; sl@0: TInt r=KErrNoMemory; sl@0: DMediaDriverIRam* pD=new DMediaDriverIRam(aMediaId); sl@0: aChannel=pD; sl@0: if (pD) sl@0: r=pD->DoCreate(aMediaId); sl@0: TInternalRamDrive::Unlock(); sl@0: return r; sl@0: } sl@0: sl@0: TInt DPhysicalDeviceMediaIRam::Validate(TInt aDeviceType, const TDesC8* /*anInfo*/, const TVersion& aVer) sl@0: { sl@0: if (!Kern::QueryVersionSupported(iVersion,aVer)) sl@0: return KErrNotSupported; sl@0: if (aDeviceType!=MEDIA_DEVICE_IRAM) sl@0: return KErrNotSupported; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DPhysicalDeviceMediaIRam::Info(TInt aFunction, TAny*) sl@0: // sl@0: // Return the priority of this media driver sl@0: // sl@0: { sl@0: if (aFunction==EPriority) sl@0: return KMediaDriverPriorityNormal; sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: DMediaDriverIRam::DMediaDriverIRam(TInt aMediaId) sl@0: // sl@0: // Constructor. sl@0: // sl@0: : DMediaDriver(aMediaId) sl@0: {} sl@0: sl@0: TInt DMediaDriverIRam::DoCreate(TInt /*aMediaId*/) sl@0: // sl@0: // Create the media driver. sl@0: // sl@0: { sl@0: sl@0: TInt size=TInternalRamDrive::Size(); sl@0: if (size<0) sl@0: return KErrGeneral; // no RAM drive! sl@0: SetTotalSizeInBytes(size); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: TInt DMediaDriverIRam::Request(TLocDrvRequest& m) sl@0: { sl@0: TInt request=m.Id(); sl@0: __KTRACE_OPT(KLOCDRV,Kern::Printf(">DMediaDriverIRam::Request %d",request)); sl@0: TInt r=KErrNotSupported; sl@0: NKern::ThreadEnterCS(); sl@0: TInternalRamDrive::Wait(); sl@0: switch (request) sl@0: { sl@0: case DLocalDrive::ECaps: sl@0: r=Caps(m); sl@0: break; sl@0: case DLocalDrive::ERead: sl@0: r=Read(m); sl@0: break; sl@0: case DLocalDrive::EWrite: sl@0: r=Write(m); sl@0: break; sl@0: case DLocalDrive::EFormat: sl@0: r=Format(m); sl@0: break; sl@0: case DLocalDrive::EEnlarge: sl@0: r=Enlarge(m); sl@0: break; sl@0: case DLocalDrive::EReduce: sl@0: r=Reduce(m); sl@0: break; sl@0: default: sl@0: r=KErrNotSupported; sl@0: break; sl@0: } sl@0: TInternalRamDrive::Signal(); sl@0: NKern::ThreadLeaveCS(); sl@0: __KTRACE_OPT(KLOCDRV,Kern::Printf("iPartitionLen; sl@0: caps.iHiddenSectors=0; sl@0: caps.iEraseBlockSize=TInternalRamDrive::MaxSize(); // overload for RAM drive to avoid sl@0: // F32 depending on memory model sl@0: caps.iBlockSize=1; sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DMediaDriverIRam::Read(TLocDrvRequest& m) sl@0: { sl@0: Int64 pos=m.Pos(); sl@0: Int64 length=m.Length(); sl@0: if (length<0 || pos<0 || (pos+length)>KMaxTInt) sl@0: return KErrGeneral; sl@0: TInt p=(TInt)pos; sl@0: TInt l=(TInt)length; sl@0: if (p+l>TInternalRamDrive::Size()) sl@0: return KErrGeneral; sl@0: TPtrC8 des((TUint8*)TInternalRamDrive::Base()+p,l); sl@0: TInt r=m.WriteRemote(&des,0); sl@0: return r; sl@0: } sl@0: sl@0: TInt DMediaDriverIRam::Write(TLocDrvRequest& m) sl@0: { sl@0: Int64 pos=m.Pos(); sl@0: Int64 length=m.Length(); sl@0: if (length<0 || pos<0 || (pos+length)>KMaxTInt) sl@0: return KErrGeneral; sl@0: TInt p=(TInt)pos; sl@0: TInt l=(TInt)length; sl@0: if (p+l>TInternalRamDrive::Size()) sl@0: return KErrGeneral; sl@0: TPtr8 des((TUint8*)TInternalRamDrive::Base()+p,l,l); sl@0: TInt r=m.ReadRemote(&des,0); sl@0: return r; sl@0: } sl@0: sl@0: TInt DMediaDriverIRam::Format(TLocDrvRequest& m) sl@0: { sl@0: Int64 pos=m.Pos(); sl@0: Int64 length=m.Length(); sl@0: if (length<0 || pos<0 || (pos+length)>KMaxTInt) sl@0: return KErrGeneral; sl@0: TInt p=(TInt)pos; sl@0: TInt l=(TInt)length; sl@0: if (p+l>TInternalRamDrive::Size()) sl@0: return KErrGeneral; sl@0: memclr((TUint8*)TInternalRamDrive::Base()+p, l); sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt DMediaDriverIRam::Enlarge(TLocDrvRequest& m) sl@0: // sl@0: // Enlarge the drive sl@0: // sl@0: { sl@0: TInt length=(TInt)m.Length(); sl@0: __KTRACE_OPT(KLOCDRV,Kern::Printf(">IRam::Enlarge (%d)",length)); sl@0: sl@0: Int64 newLen=TotalSizeInBytes(); sl@0: newLen+=length; sl@0: if (newLen>KMaxTInt) sl@0: return(KErrGeneral); sl@0: sl@0: TInt r=TInternalRamDrive::Adjust((TInt)newLen); sl@0: if (r==KErrNone) sl@0: { sl@0: SetTotalSizeInBytes(newLen,m.Drive()); sl@0: __KTRACE_OPT(KLOCDRV,Kern::Printf("Enlarge-Success (S:0x%lx RS:%d)",TotalSizeInBytes(),TInternalRamDrive::Size())); sl@0: } sl@0: else if (r==KErrNoMemory) sl@0: r=KErrDiskFull; sl@0: return r; sl@0: } sl@0: sl@0: TInt DMediaDriverIRam::Reduce(TLocDrvRequest& m) sl@0: // sl@0: // Reduce in size the drive sl@0: // sl@0: { sl@0: Int64 pos=m.Pos(); sl@0: TInt length=(TInt)m.Length(); sl@0: if (pos>KMaxTInt) sl@0: return(KErrGeneral); sl@0: sl@0: __KTRACE_OPT(KLOCDRV,Kern::Printf(">IRam::ReduceSize (%d@%d)",length,(TInt)pos)); sl@0: sl@0: TUint8 *Trg=(TUint8*)TInternalRamDrive::Base()+(TInt)pos; sl@0: TInt len=TInternalRamDrive::Size()-((TInt)pos+length); sl@0: memmove((TAny*)Trg,(TAny*)(Trg+length),len); sl@0: len=TInternalRamDrive::Size()-length; sl@0: TInt r=TInternalRamDrive::Adjust(len); sl@0: if (r==KErrNone) sl@0: { sl@0: SetTotalSizeInBytes(len,m.Drive()); sl@0: __KTRACE_OPT(KLOCDRV,Kern::Printf("ReduceSize-Success (S:0x%lx RS:%d)",TotalSizeInBytes(),TInternalRamDrive::Size())); sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: TInt DMediaDriverIRam::PartitionInfo(TPartitionInfo& anInfo) sl@0: // sl@0: // Return partition information on the media. sl@0: // sl@0: { sl@0: sl@0: anInfo.iPartitionCount=1; sl@0: anInfo.iEntry[0].iPartitionBaseAddr=0; sl@0: anInfo.iEntry[0].iPartitionLen=anInfo.iMediaSizeInBytes=TotalSizeInBytes(); sl@0: anInfo.iEntry[0].iPartitionType=KPartitionTypeFAT16; sl@0: return KErrNone; sl@0: } sl@0: sl@0: DECLARE_EXTENSION_PDD() sl@0: { sl@0: return new DPhysicalDeviceMediaIRam; sl@0: } sl@0: sl@0: static const TInt IRamDriveNumbers[IRAM_DRIVECOUNT]={IRAM_DRIVELIST}; sl@0: _LIT(KIRamDriveName,IRAM_DRIVENAME); sl@0: sl@0: DECLARE_STANDARD_EXTENSION() sl@0: { sl@0: __KTRACE_OPT(KBOOT,Kern::Printf("Registering IRAM drive")); sl@0: TInt r=KErrNoMemory; sl@0: DPrimaryMediaBase* pM=new DPrimaryMediaBase; sl@0: if (pM) sl@0: { sl@0: r=LocDrv::RegisterMediaDevice(MEDIA_DEVICE_IRAM,IRAM_DRIVECOUNT,&IRamDriveNumbers[0],pM,IRAM_NUMMEDIA,KIRamDriveName); sl@0: } sl@0: __KTRACE_OPT(KBOOT,Kern::Printf("Registering IRAM drive - return %d",r)); sl@0: return r; sl@0: } sl@0: sl@0: