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