diff -r 000000000000 -r 96e5fb8b040d kernel/eka/drivers/medlfs/flash_media.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kernel/eka/drivers/medlfs/flash_media.cpp Thu Dec 17 09:24:54 2009 +0200 @@ -0,0 +1,377 @@ +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// e32\drivers\medlfs\flash_media.cpp +// +// + +#include +#include "variantmediadef.h" + +_LIT(KPddName, "Media.Flash"); +_LIT(KFlashThreadName,"FlashThread"); + +const TInt KFlashThreadPriority=24; // same as file server + +GLDEF_C TDfcQue FlashDfcQ; + +class DPhysicalDeviceMediaFlash : public DPhysicalDevice + { +public: + DPhysicalDeviceMediaFlash(); + virtual TInt Install(); + virtual void GetCaps(TDes8& aDes) const; + virtual TInt Create(DBase*& aChannel, TInt aMediaId, const TDesC8* anInfo, const TVersion& aVer); + virtual TInt Validate(TInt aDeviceType, const TDesC8* anInfo, const TVersion& aVer); + virtual TInt Info(TInt aFunction, TAny* a1); + }; + +DPhysicalDeviceMediaFlash::DPhysicalDeviceMediaFlash() +// +// Constructor +// + { + iUnitsMask=0x2; + iVersion=TVersion(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion); + } + +TInt DPhysicalDeviceMediaFlash::Install() +// +// Install the media drives PDD. +// + { + + return SetName(&KPddName); + } + +void DPhysicalDeviceMediaFlash::GetCaps(TDes8& /*aDes*/) const +// +// Return the media drivers capabilities. +// + { + } + +TInt DPhysicalDeviceMediaFlash::Create(DBase*& aChannel, TInt aMediaId, const TDesC8* /* anInfo */,const TVersion &aVer) +// +// Create an LFFS media driver. +// + { + if (!Kern::QueryVersionSupported(iVersion,aVer)) + return KErrNotSupported; + DMediaDriverFlash *pD=DMediaDriverFlash::New(aMediaId); + aChannel=pD; + TInt r=KErrNoMemory; + if (pD) + r=pD->DoCreate(aMediaId); + if (r==KErrNone) + pD->OpenMediaDriverComplete(KErrNone); + return r; + } + +TInt DPhysicalDeviceMediaFlash::Validate(TInt aDeviceType, const TDesC8* /*anInfo*/, const TVersion& aVer) + { + if (!Kern::QueryVersionSupported(iVersion,aVer)) + return KErrNotSupported; + if (aDeviceType!=MEDIA_DEVICE_LFFS) + return KErrNotSupported; + return KErrNone; + } + +TInt DPhysicalDeviceMediaFlash::Info(TInt aFunction, TAny*) +// +// Return the priority of this media driver +// + { + if (aFunction==EPriority) + return KMediaDriverPriorityNormal; + return KErrNotSupported; + } + + + + +/** +@internalComponent +*/ +DMediaDriverFlash::DMediaDriverFlash(TInt aMediaId) +// +// Constructor. +// + : DMediaDriver(aMediaId) + {} + + + + +/** +@internalComponent +*/ +TInt DMediaDriverFlash::DoCreate(TInt /*aMediaId*/) +// +// Create the media driver. +// + { + + TInt r=Initialise(); // interrogate FLASH etc. + if (r==KErrNone) + { + TUint32 size=TotalSize(); + SetTotalSizeInBytes(size); + } + return r; + } + + + + +/** +A function called by the local media subsystem to deal with a request; +this is implemented by the generic layer of the LFFS media driver. + +The implementation delegates the handling of reading, writing and erasing +to the specific layer's DoRead(), DoWrite() and DoErase() functions +respectively. + +@param aRequest An object that encapsulates information about the request. + +@return A value indicating the result: + KErrNone, if the request has been sucessfully initiated; + KErrNotSupported, if the request cannot be handled by the device; + KMediaDriverDeferRequest, if the request cannot be handled + immediately because of an outstanding request (this request will be + deferred until the outstanding request has completed); + otherwise one of the other system-wide error codes. + +@see DMediaDriverFlash::DoRead() +@see DMediaDriverFlash::DoWrite() +@see DMediaDriverFlash::DoErase() +*/ +TInt DMediaDriverFlash::Request(TLocDrvRequest& m) + { + TInt r=KErrNotSupported; + TInt id=m.Id(); + __KTRACE_OPT(KLOCDRV,Kern::Printf(">DMediaDriverFlash::Request %d",id)); + if (id==DLocalDrive::ECaps) + { + TLocalDriveCapsV2& c=*(TLocalDriveCapsV2*)m.RemoteDes(); + r=Caps(c); + c.iSize=m.Drive()->iPartitionLen; + c.iPartitionType=m.Drive()->iPartitionType; + return r; + } + switch (id) + { + case DLocalDrive::ERead: + if (iReadReq) + return KMediaDriverDeferRequest; // read already in progress so defer this one + iReadReq=&m; + r=DoRead(); + if (r!=KErrNone) + iReadReq=NULL; + break; + case DLocalDrive::EWrite: + if (iWriteReq) + return KMediaDriverDeferRequest; // write already in progress so defer this one + iWriteReq=&m; + r=DoWrite(); + if (r!=KErrNone) + iWriteReq=NULL; + break; + case DLocalDrive::EFormat: + if (iEraseReq) + return KMediaDriverDeferRequest; // erase already in progress so defer this one + iEraseReq=&m; + r=DoErase(); + if (r!=KErrNone) + iEraseReq=NULL; + break; + case DLocalDrive::EEnlarge: + case DLocalDrive::EReduce: + default: + r=KErrNotSupported; + break; + } + __KTRACE_OPT(KLOCDRV,Kern::Printf("iDfcQ=&FlashDfcQ; + r=LocDrv::RegisterMediaDevice(EFixedMedia1,LFFS_DRIVECOUNT,&LffsDriveNumbers[0],pM,LFFS_NUMMEDIA,KFlashDriveName); + if (r==KErrNone) + pM->iMsgQ.Receive(); + } + } + __KTRACE_OPT(KBOOT,Kern::Printf("Registering FLASH drive - return %d",r)); + return r; + } +