os/kernelhwsrv/kernel/eka/include/drivers/locmedia.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/include/drivers/locmedia.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1381 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\include\drivers\locmedia.h
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#ifndef LOCMEDIA_H
    1.22 +#define LOCMEDIA_H
    1.23 +#include <plat_priv.h>
    1.24 +#include <d32locd.h>
    1.25 +
    1.26 +#if defined(_DEBUG) && defined(__DEMAND_PAGING__)
    1.27 +#define __CONCURRENT_PAGING_INSTRUMENTATION__
    1.28 +#endif
    1.29 +#if defined(_DEBUG) && defined(__DEMAND_PAGING__)
    1.30 +#define __DEMAND_PAGING_BENCHMARKS__
    1.31 +#endif
    1.32 +
    1.33 +#ifdef __WINS__
    1.34 +	#define __EMULATOR_DMA_SUMULATION__
    1.35 +#endif
    1.36 +
    1.37 +/**
    1.38 +@publishedPartner
    1.39 +@released
    1.40 +
    1.41 +A media driver priority value.
    1.42 +
    1.43 +The value can be returned by a media driver's PDD factory Info() function,
    1.44 +and allows Symbian OS to decide the order in which media drivers are to be opened.
    1.45 +
    1.46 +The value is relative to the other media driver priority values.
    1.47 +
    1.48 +@see DPhysicalDevice::Info()
    1.49 +*/
    1.50 +const TInt KMediaDriverPriorityHigh=2;
    1.51 +
    1.52 +
    1.53 +
    1.54 +
    1.55 +/**
    1.56 +@publishedPartner
    1.57 +@released
    1.58 +
    1.59 +A media driver priority value.
    1.60 +
    1.61 +The value can be returned by a media driver's PDD factory Info() function,
    1.62 +and allows Symbian OS to decide the order in which media drivers are to be opened.
    1.63 +
    1.64 +The value is relative to the other media driver priority values, and is
    1.65 +the one most commonly used.
    1.66 +
    1.67 +@see DPhysicalDevice::Info()
    1.68 +*/
    1.69 +const TInt KMediaDriverPriorityNormal=1;
    1.70 +
    1.71 +
    1.72 +
    1.73 +
    1.74 +/**
    1.75 +@publishedPartner
    1.76 +@released
    1.77 +
    1.78 +A media driver priority value.
    1.79 +
    1.80 +The value can be returned by a media driver's PDD factory Info() function,
    1.81 +and allows Symbian OS to decide the order in which media drivers are to be opened.
    1.82 +
    1.83 +The value is relative to the other media driver priority values.
    1.84 +
    1.85 +@see DPhysicalDevice::Info()
    1.86 +*/
    1.87 +const TInt KMediaDriverPriorityLow=0;
    1.88 +
    1.89 +
    1.90 +
    1.91 +
    1.92 +/**
    1.93 +@publishedPartner
    1.94 +@released
    1.95 +
    1.96 +Media driver interface major version number.
    1.97 +*/
    1.98 +const TInt KMediaDriverInterfaceMajorVersion=1;
    1.99 +
   1.100 +
   1.101 +
   1.102 +
   1.103 +/**
   1.104 +@publishedPartner
   1.105 +@released
   1.106 +
   1.107 +Media driver interface minor version number.
   1.108 +*/
   1.109 +const TInt KMediaDriverInterfaceMinorVersion=0;
   1.110 +
   1.111 +
   1.112 +
   1.113 +
   1.114 +
   1.115 +/**
   1.116 +@publishedPartner
   1.117 +@released
   1.118 +
   1.119 +Media driver interface build number.
   1.120 +*/
   1.121 +const TInt KMediaDriverInterfaceBuildVersion=160;
   1.122 +
   1.123 +
   1.124 +
   1.125 +
   1.126 +/**
   1.127 +@publishedPartner
   1.128 +@released
   1.129 +*/
   1.130 +const TInt KMediaDriverDeferRequest=1;
   1.131 +
   1.132 +
   1.133 +
   1.134 +
   1.135 +/**
   1.136 +@internalTechnology
   1.137 +*/
   1.138 +#define __TRACE_TIMING(x)
   1.139 +//#define __TRACE_TIMING(x) *(TInt*)0x63000ff0=x
   1.140 +
   1.141 +/**
   1.142 +@internalComponent
   1.143 +*/
   1.144 +NONSHARABLE_CLASS(DLocalDriveFactory) : public DLogicalDevice
   1.145 +	{
   1.146 +public:
   1.147 +	DLocalDriveFactory();
   1.148 +	virtual TInt Install();
   1.149 +	virtual void GetCaps(TDes8 &aDes) const;
   1.150 +	virtual TInt Create(DLogicalChannelBase*& aChannel);
   1.151 +	};
   1.152 +
   1.153 +class TLocDrv;
   1.154 +class DLocalDrive;
   1.155 +
   1.156 +/**
   1.157 +@internalComponent
   1.158 +*/
   1.159 +NONSHARABLE_CLASS(TLocalDriveCleanup) : public TThreadCleanup
   1.160 +	{
   1.161 +public:
   1.162 +	TLocalDriveCleanup();
   1.163 +	virtual void Cleanup();
   1.164 +	inline DLocalDrive& LocalDrive();
   1.165 +	};
   1.166 +
   1.167 +
   1.168 +
   1.169 +class TLocDrvRequest;
   1.170 +class DPrimaryMediaBase;
   1.171 +
   1.172 +/**
   1.173 +@publishedPartner
   1.174 +@released
   1.175 +
   1.176 +This class is strictly internal to Symbian; the only part of this class that
   1.177 +is publicly exposed to partners is the TRequestId enum.
   1.178 +
   1.179 +@see DLocalDrive::TRequestId
   1.180 +*/
   1.181 +NONSHARABLE_CLASS(DLocalDrive) : public DLogicalChannelBase
   1.182 +	{
   1.183 +public:
   1.184 +	/**
   1.185 +	Identifies the specific local drive operation.
   1.186 +	*/
   1.187 +	enum TRequestId
   1.188 +		{
   1.189 +		/**
   1.190 +		Requests information about the size, type, and attributes of the media.
   1.191 +		*/
   1.192 +		ECaps=0,
   1.193 +		
   1.194 +		/**
   1.195 +		Requests an asynchronous read from the media device.
   1.196 +		*/
   1.197 +		ERead=1,
   1.198 +		
   1.199 +		/**
   1.200 +		Requests an asynchronous write to the media device.
   1.201 +		*/
   1.202 +		EWrite=2,
   1.203 +		
   1.204 +		/**
   1.205 +		Requests the formatting of a section of the media
   1.206 +		*/
   1.207 +		EFormat=3,
   1.208 +		
   1.209 +		/**
   1.210 +		A request to expand the total size of the media.
   1.211 +		*/
   1.212 +		EEnlarge=4,
   1.213 +		
   1.214 +		/**
   1.215 +		A request to reduce the total size of the media.
   1.216 +		*/
   1.217 +		EReduce=5,
   1.218 +		
   1.219 +		/**
   1.220 +		A request to force a remount of the media.
   1.221 +		*/
   1.222 +		EForceMediaChange=6,
   1.223 +		
   1.224 +		/**
   1.225 +		Requests an attempt to lock the media with a password.
   1.226 +		*/
   1.227 +		EPasswordLock=7,
   1.228 +		
   1.229 +		/**
   1.230 +		Requests an attempt to unlock the media.
   1.231 +		*/
   1.232 +		EPasswordUnlock=8,
   1.233 +		
   1.234 +		/**
   1.235 +		Requests an attempt to remove the password from the media.
   1.236 +		*/
   1.237 +		EPasswordClear=9,
   1.238 +		
   1.239 +		/**
   1.240 +		Requests an read of the password store.
   1.241 +		*/
   1.242 +		EReadPasswordStore=10,
   1.243 +		
   1.244 +		/**
   1.245 +		Requests a write of the password store.
   1.246 +		*/
   1.247 +		EWritePasswordStore=11,
   1.248 +		
   1.249 +		/** 
   1.250 +		A request to get the length of the password store.
   1.251 +		*/
   1.252 +		EPasswordStoreLengthInBytes=12,
   1.253 +		/** 
   1.254 +		A Control IO request
   1.255 +		*/
   1.256 +		EControlIO=13,
   1.257 +		/** 
   1.258 +		A request to force an erase of the password from the media
   1.259 +		*/
   1.260 +		EPasswordErase=14,
   1.261 +
   1.262 +		/** 
   1.263 +		A delete notification from the file system
   1.264 +		*/
   1.265 +		EDeleteNotify=15,
   1.266 +
   1.267 +		/** 
   1.268 +		A request for information on the last error
   1.269 +		*/
   1.270 +		EGetLastErrorInfo=16,
   1.271 +
   1.272 +		EFirstReqNumberReservedForPaging=17,
   1.273 +		// DO NOT REUSE ANY OF THE REQUEST NUMBERS BETWEEN THIS AND THE LAST RESERVED REQ NUMBER
   1.274 +		// ALSO DO NOT INSERT ANY REQUEST NUMBERS BEFORE THIS, AS THIS WILL BE A COMPATIBILITY BREEAK
   1.275 +		ELastReqNumberReservedForPaging=31,
   1.276 +
   1.277 +		/**
   1.278 +		Query device 
   1.279 +		*/
   1.280 +		EQueryDevice=32,
   1.281 +
   1.282 +		};
   1.283 +public:
   1.284 +	DLocalDrive(); 
   1.285 +	~DLocalDrive();
   1.286 +public:
   1.287 +	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); /**< @internalComponent */
   1.288 +	virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);                      /**< @internalComponent */
   1.289 +public:
   1.290 +	void NotifyChange(DPrimaryMediaBase& aPrimaryMedia, TBool aMediaChange);
   1.291 +public:
   1.292 +	inline void Deque();                 /**< @internalComponent */
   1.293 +
   1.294 +private:
   1.295 +#ifdef __DEMAND_PAGING__
   1.296 +	TInt LockMountInfo(DPrimaryMediaBase& aPrimaryMedia, TLocDrvRequest& aReq);
   1.297 +	void UnlockMountInfo(DPrimaryMediaBase& aPrimaryMedia);
   1.298 +#endif
   1.299 +	TInt ReadPasswordData(TLocDrvRequest& aReq, TLocalDrivePasswordData& aPswData, TMediaPassword& aOldPasswd, TMediaPassword& aNewPasswd);
   1.300 +
   1.301 +public:
   1.302 +	TLocDrv* iDrive;							/**< @internalComponent */
   1.303 +	SDblQueLink iLink;							/**< @internalComponent */
   1.304 +	TClientDataRequest<TBool>* iNotifyChangeRequest;	/**< @internalComponent */
   1.305 +	TLocalDriveCleanup iCleanup;				 /**< @internalComponent */
   1.306 +	};
   1.307 +
   1.308 +/**
   1.309 +@internalComponent
   1.310 +*/
   1.311 +inline DLocalDrive& TLocalDriveCleanup::LocalDrive()
   1.312 +	{ return *_LOFF(this,DLocalDrive,iCleanup); }
   1.313 +
   1.314 +
   1.315 +
   1.316 +
   1.317 +/**
   1.318 +@publishedPartner
   1.319 +@released
   1.320 +
   1.321 +A class that encapsulates the request information received from the client,
   1.322 +and gives the media driver access to the request ID and other associated
   1.323 +parameters, such as the request length, offset, the requesting thread,
   1.324 +source and destination address etc.
   1.325 +
   1.326 +An object of this type is passed to DMediaDriver::Request().
   1.327 +
   1.328 +@see DMediaDriver::Request()
   1.329 +*/
   1.330 +class TLocDrvRequest : public TThreadMessage
   1.331 +	{
   1.332 +public:
   1.333 +
   1.334 +    /** 
   1.335 +	@internalComponent
   1.336 +    */
   1.337 +	enum TFlags
   1.338 +		{
   1.339 +		EWholeMedia=1,
   1.340 +		EAdjusted=2,
   1.341 +		EPhysAddr=0x04,
   1.342 +		EPaging=0x08,				// a paging request
   1.343 +		EBackgroundPaging=0x10,		// a background paging request. @see DMediaPagingDevice::Write()
   1.344 +		ECodePaging=0x20,			// a code paging request
   1.345 +		EDataPaging=0x40,			// a data paging request
   1.346 +		ETClientBuffer=0x80,		// RemoteDes() points to a TClientBuffer
   1.347 +		EKernelBuffer=0x100,		// RemoteDes() points to a kernel-side buffer
   1.348 +		};
   1.349 +public:
   1.350 +    
   1.351 +    /**
   1.352 +    Gets a reference to the object containing the request information.
   1.353 +    
   1.354 +    @return The request information.
   1.355 +    */
   1.356 +	inline static TLocDrvRequest& Get()
   1.357 +		{return (TLocDrvRequest&)Kern::Message();}
   1.358 +	
   1.359 +		
   1.360 +    /**
   1.361 +    Gets the request ID.
   1.362 +    
   1.363 +    For media drivers, this is one of the DLocalDrive::TRequestId enumerated values.
   1.364 +    
   1.365 +    @return The request ID.
   1.366 +    
   1.367 +    @see DLocalDrive::TRequestId
   1.368 +    */
   1.369 +	inline TInt& Id()
   1.370 +		{return *(TInt*)&iValue;}
   1.371 +		
   1.372 +		
   1.373 +    /**
   1.374 +    Gets the position on the media on which the request operates. 
   1.375 +    
   1.376 +    This applies to operations ERead, EWrite and EFormat.
   1.377 +
   1.378 +    Note that the partition offset is taken into account by the underlying
   1.379 +    local media subsystem.
   1.380 +    
   1.381 +    @return The position on the media.
   1.382 +    
   1.383 +    @see TRequestId::ERead
   1.384 +    @see TRequestId::EWrite
   1.385 +    @see TRequestId::EFormat
   1.386 +    */		
   1.387 +	inline Int64& Pos()
   1.388 +		{return *(Int64*)&iArg[0];}
   1.389 +	
   1.390 +	
   1.391 +	/**
   1.392 +	Gets the length associated with the operation.
   1.393 +	
   1.394 +	This is the number of bytes associated with the media request.
   1.395 +	It applies to operations ERead, EWrite and EFormat.
   1.396 +	
   1.397 +	@return The length, in bytes.
   1.398 +	
   1.399 +    @see TRequestId::ERead
   1.400 +    @see TRequestId::EWrite
   1.401 +    @see TRequestId::EFormat
   1.402 +	*/
   1.403 +	inline Int64& Length()
   1.404 +		{return *(Int64*)&iArg[2];}
   1.405 +		
   1.406 +	
   1.407 +	/**
   1.408 +	Gets a pointer to the remote thread that requested the operation.
   1.409 +	
   1.410 +	This may be used to access the data to be read from the remote thread's process,
   1.411 +	or the area to which data is to be written in the remote thread's process.
   1.412 +	However, it is recommended that	such operations be performed
   1.413 +	using ReadRemote() and WriteRemote()
   1.414 +	
   1.415 +	@return A reference to a pointer to the remote thread.
   1.416 +	
   1.417 +	@see TLocDrvRequest::ReadRemote()
   1.418 +	@see TLocDrvRequest::WriteRemote()
   1.419 +	*/
   1.420 +	inline DThread*& RemoteThread()
   1.421 +		{return *(DThread**)&iArg[4];}
   1.422 +		
   1.423 +		
   1.424 +	/**
   1.425 +	Gets a pointer to the descriptor in the remote thread's process that
   1.426 +	contains the data to be read, or is the target for data to be written.
   1.427 +	
   1.428 +    However, it is recommended that such read or write operations be performed
   1.429 +    using ReadRemote() and WriteRemote().
   1.430 +    
   1.431 +    @return A reference to a pointer to the remote descriptor.
   1.432 +
   1.433 +    @see TLocDrvRequest::ReadRemote()
   1.434 +	@see TLocDrvRequest::WriteRemote()
   1.435 +	*/	
   1.436 +	inline TAny*& RemoteDes()
   1.437 +		{return *(TAny**)&iArg[5];}
   1.438 +		
   1.439 +		
   1.440 +    /**
   1.441 +    Gets the offset within the descriptor in the remote thread's process.
   1.442 +    
   1.443 +    @return The offset within the descriptor.
   1.444 +    */
   1.445 +	inline TInt& RemoteDesOffset()
   1.446 +		{return *(TInt*)&iArg[6];}
   1.447 +		
   1.448 +		
   1.449 +	/**
   1.450 +	@internalComponent
   1.451 +	*/
   1.452 +	inline TInt& Flags()
   1.453 +		{return *(TInt*)&iArg[7];}
   1.454 +		
   1.455 +		
   1.456 +	/**
   1.457 +	@internalComponent
   1.458 +	*/
   1.459 +	inline TLocDrv*& Drive()
   1.460 +		{return *(TLocDrv**)&iArg[8];}
   1.461 +		
   1.462 +		
   1.463 +	/**
   1.464 +	@internalComponent
   1.465 +	*/
   1.466 +	inline TInt& DriverFlags()
   1.467 +		{return *(TInt*)&iArg[9];}
   1.468 +
   1.469 +
   1.470 +	/**
   1.471 +	Returns true if Physical memory addresses are available for this TLocDrvRequest.
   1.472 +	@return ETrue if a physical memory address is available.
   1.473 +	*/
   1.474 +	inline TBool IsPhysicalAddress()
   1.475 +		{return Flags() & EPhysAddr;}
   1.476 +public:
   1.477 +	TInt ProcessMessageData(TAny* args);
   1.478 +	void CloseRemoteThread();
   1.479 +	IMPORT_C TInt ReadRemote(TDes8* aDes, TInt anOffset);
   1.480 +	IMPORT_C TInt ReadRemote(const TAny* aSrc, TDes8* aDes);
   1.481 +	IMPORT_C TInt ReadRemoteRaw(TAny* aDes, TInt aSize);
   1.482 +	IMPORT_C TInt WriteRemote(const TDesC8* aDes, TInt anOffset);
   1.483 +	IMPORT_C TInt WriteRemoteRaw(const TAny* aSrc, TInt aSize);
   1.484 +	IMPORT_C TInt CheckAndAdjustForPartition();
   1.485 +#if !defined(__WINS__)
   1.486 +	IMPORT_C TInt WriteToPageHandler(const TAny* aSrc, TInt aSize, TInt anOffset);
   1.487 +	IMPORT_C TInt ReadFromPageHandler(TAny* aDst, TInt aSize, TInt anOffset);
   1.488 +#endif // __WINS__
   1.489 +	IMPORT_C TInt GetNextPhysicalAddress(TPhysAddr& aPhysAddr, TInt& aLength);
   1.490 +	};
   1.491 +
   1.492 +
   1.493 +
   1.494 +
   1.495 +/**
   1.496 +@internalComponent
   1.497 +*/
   1.498 +inline void DLocalDrive::Deque()
   1.499 +	{ iLink.Deque(); }
   1.500 +
   1.501 +
   1.502 +
   1.503 +
   1.504 +/**
   1.505 +@publishedPartner
   1.506 +@released
   1.507 +
   1.508 +Defines a structure used to contain information that describes an individual
   1.509 +partition. 
   1.510 +
   1.511 +There is one of these for each partition that exists on a media device.
   1.512 +
   1.513 +@see TPartitionInfo
   1.514 +*/
   1.515 +class TPartitionEntry
   1.516 +	{
   1.517 +public:
   1.518 +     
   1.519 +    /**
   1.520 +    The start address of the partition, described as a relative offset,
   1.521 +    in bytes, from the start of the media.
   1.522 +    
   1.523 +    This value is used by the local media subsystem to calculate
   1.524 +    the absolute address on the media whenever an access such as a Read,
   1.525 +    Write or Format request is made.
   1.526 +    */
   1.527 +	Int64 iPartitionBaseAddr;
   1.528 + 
   1.529 + 	
   1.530 +	/**
   1.531 +	The length of the partition, in bytes.
   1.532 +	*/
   1.533 +	Int64 iPartitionLen;
   1.534 +
   1.535 +	
   1.536 +	/**
   1.537 +	The Boot Indicator record, as described in the Master Boot Record on
   1.538 +	FAT Partitioned devices.
   1.539 +
   1.540 +	This is currently unused by the local media subsystem.
   1.541 +	*/
   1.542 +	TUint16 iBootIndicator;
   1.543 +	
   1.544 +	
   1.545 +	/**
   1.546 +	Describes the type of partition.
   1.547 +	
   1.548 +	The File Server uses this to decide the type of filesystem to be mounted
   1.549 +	on the partition. 
   1.550 +	
   1.551 +	Symbian OS supports many partition types, as defined in partitions.h.
   1.552 +	You are, however, free to invent your own partition type, on which
   1.553 +	you could, for example, mount your own filesystem. However, make sure 
   1.554 +	that your partition type does not clash with an existing partition type.
   1.555 +	
   1.556 +	Note that a media driver does not does not have to verify that
   1.557 +	the partition actually contains a file system of this type; it just sets
   1.558 +	this value to indicate the intended use for this partition.
   1.559 +	*/
   1.560 +	TUint16 iPartitionType;
   1.561 +	};
   1.562 +
   1.563 +
   1.564 +
   1.565 +
   1.566 +/**
   1.567 +@publishedPartner
   1.568 +@released
   1.569 +
   1.570 +A constant that defines the maximum number of partitions that can exist on
   1.571 +a media device.
   1.572 +
   1.573 +@see TPartitionInfo::iPartitionCount
   1.574 +*/
   1.575 +const TInt KMaxPartitionEntries=0x10;
   1.576 +
   1.577 +
   1.578 +
   1.579 +
   1.580 +/**
   1.581 +@publishedPartner
   1.582 +@released
   1.583 +
   1.584 +Contains partition information for a media device.
   1.585 +
   1.586 +An object of this type is passed to the media driver's implementation of
   1.587 +DMediaDriver::PartitionInfo() to be filled in.
   1.588 +
   1.589 +@see DMediaDriver::PartitionInfo()
   1.590 +*/
   1.591 +class TPartitionInfo
   1.592 +	{
   1.593 +public:
   1.594 +
   1.595 +    /**
   1.596 +    Default constructor that clears this object's memory to binary zeroes.
   1.597 +    */
   1.598 +	TPartitionInfo();
   1.599 +public:
   1.600 +
   1.601 +    /**
   1.602 +    The total size of the media, in bytes.
   1.603 +    */
   1.604 +	Int64 iMediaSizeInBytes;
   1.605 +	
   1.606 +	
   1.607 +	/**
   1.608 +	The total number of partitions that exist on the media.
   1.609 +	
   1.610 +	This is always less than or equal to KMaxPartitionEntries.
   1.611 +	
   1.612 +    @see KMaxPartitionEntries
   1.613 +	*/
   1.614 +	TInt iPartitionCount;
   1.615 +	
   1.616 +	
   1.617 +	/**
   1.618 +	Information that describes each individual partition on the device.
   1.619 +	
   1.620 +	Each partition is represented by an array of TPartitionEntry objects. 
   1.621 +	Each entry must be created in the order of the start offset, so that 
   1.622 +	iEntry[0] specifies the partition with
   1.623 +	the smallest iPartitionBaseAddr value.
   1.624 +	
   1.625 +	@see TPartitionEntry::iPartitionBaseAddr
   1.626 +	@see TPartitionEntry
   1.627 +	*/
   1.628 +	TPartitionEntry iEntry[KMaxPartitionEntries];
   1.629 +	};
   1.630 +
   1.631 +
   1.632 +
   1.633 +
   1.634 +class DMedia;
   1.635 +class DPrimaryMediaBase;
   1.636 +class DMediaDriver;
   1.637 +#ifdef __DEMAND_PAGING__
   1.638 +class DFragmentationPagingLock;
   1.639 +#endif
   1.640 +class DDmaHelper;
   1.641 +
   1.642 +/**
   1.643 +@internalComponent
   1.644 +*/
   1.645 +class TLocDrv : public TPartitionEntry
   1.646 +	{
   1.647 +public:
   1.648 +	TLocDrv(TInt aDriveNumber);
   1.649 +public:
   1.650 +	inline TInt Connect(DLocalDrive* aLocalDrive);
   1.651 +	inline void Disconnect(DLocalDrive* aLocalDrive);
   1.652 +	inline TInt Request(TLocDrvRequest& aRequest);
   1.653 +public:
   1.654 +	TInt iDriveNumber;
   1.655 +	DMedia* iMedia;
   1.656 +	DPrimaryMediaBase* iPrimaryMedia;
   1.657 +	TInt iPartitionNumber;
   1.658 +	TErrorInfo iLastErrorInfo;
   1.659 +#ifdef __DEMAND_PAGING__
   1.660 +	TInt iSpare0;
   1.661 +	TUint8 iPagingDrv;
   1.662 +	TUint8 iSpare1;
   1.663 +	TUint8 iSpare2;
   1.664 +	TUint8 iSpare3;
   1.665 +#endif
   1.666 +	DDmaHelper* iDmaHelper;
   1.667 +	};
   1.668 +
   1.669 +/**
   1.670 +@publishedPartner
   1.671 +@released
   1.672 +
   1.673 +Kernel-side representation of a media entity. A DMedia object instantiates a 
   1.674 +media driver to provide access to the physical media.
   1.675 +
   1.676 +Multiple DMedia objects may be required by some devices, e.g. multi-media cards
   1.677 +with combined SRAM and Flash or cards containing user and protected areas.
   1.678 +*/
   1.679 +class DMedia : public DBase
   1.680 +	{
   1.681 +public:
   1.682 +	/**
   1.683 +	Declaration of all legal states for the media driver.
   1.684 +	*/
   1.685 +	enum TMediaState
   1.686 +		{
   1.687 +		/** 
   1.688 +		Media is powered down and the media drivers are closed. This is the 
   1.689 +		initial state when a media driver is created and the final state when
   1.690 +		the driver is closed.
   1.691 +		*/
   1.692 +		EClosed=0,
   1.693 +
   1.694 +		/** Media driver has started powerup sequence. */
   1.695 +		EPoweringUp1=1,
   1.696 +
   1.697 +		/** Media is being opened. */
   1.698 +		EOpening=2,
   1.699 +
   1.700 +		/** Media is open and the partition information is being read. */
   1.701 +		EReadPartitionInfo=3,
   1.702 +		
   1.703 +		/** The media driver is open and ready to accept commands. */
   1.704 +		EReady=4,
   1.705 +
   1.706 +		/** Not used. */
   1.707 +		EAborted=5,
   1.708 +
   1.709 +		/** Powering up with media drivers open. */
   1.710 +		EPoweringUp2=6,
   1.711 +
   1.712 +		/** Not used. */
   1.713 +		ERecovering=7,
   1.714 +
   1.715 +		/** The media is powered down, but the media driver still exists. */
   1.716 +		EPoweredDown=8 // powered down with media drivers open
   1.717 +		};
   1.718 +
   1.719 +public:
   1.720 +	IMPORT_C virtual TInt Create(TMediaDevice aDevice, TInt aMediaId, TInt);
   1.721 +	void Close();
   1.722 +public:
   1.723 +	inline Int64 MediaLenInBytes();
   1.724 +	inline TMediaDevice DeviceType();
   1.725 +	inline TInt PartitionCount();
   1.726 +	inline Int64 PartitionBaseAddr(TInt aPartition);
   1.727 +	inline Int64 PartitionLen(TInt aPartition);
   1.728 +public:
   1.729 +    /** Not used. */
   1.730 +	static TInt MediaCallBack(TAny *aPtr);
   1.731 +public:
   1.732 +	/**
   1.733 +	The unique ID associated with this media entity. 
   1.734 +	ID allocated when the media is first created.
   1.735 +	
   1.736 +	@see LocDrv::RegisterMediaDevice
   1.737 +	*/
   1.738 +	TInt iMediaId;
   1.739 +
   1.740 +	/**
   1.741 +	The unique ID for the device.
   1.742 +
   1.743 +	@see TMediaDevice
   1.744 +	*/
   1.745 +	TMediaDevice iDevice;
   1.746 +
   1.747 +	/**
   1.748 +	Partition information for the media device.
   1.749 +
   1.750 +	@see TPartitionInfo
   1.751 +	*/
   1.752 +	TPartitionInfo iPartitionInfo;
   1.753 +
   1.754 +	/**
   1.755 +	The media's physical device driver.
   1.756 +
   1.757 +	@see DMediaDriver
   1.758 +	*/
   1.759 +	DMediaDriver *iDriver;
   1.760 +
   1.761 +	/**
   1.762 +	Mount information for the media device.
   1.763 +	
   1.764 +	@see TMountInfoData
   1.765 +	*/
   1.766 +	TMountInfoData iMountInfo;
   1.767 +	};
   1.768 +
   1.769 +#ifdef __DEMAND_PAGING__
   1.770 +class DFragmentationPagingLock;
   1.771 +class DMediaPagingDevice;
   1.772 +#endif
   1.773 +
   1.774 +
   1.775 +/**
   1.776 +@publishedPartner
   1.777 +@released
   1.778 +The DPrimaryMedia base class which is derived from DMedia class is responsible for controlling the overall state of the media 
   1.779 +(for example whether the power is applied or the partition information has been determined and so on). 
   1.780 +Each media driver or extension that registers for a set of local drives also has to register for a set of DMedia objects at the same time.
   1.781 +This media set must contain just one primary media object. 
   1.782 +The driver that performs drive registration is responsible for creating the primary media object itself, 
   1.783 +which it then passes over to the local media sub-system for ownership. 
   1.784 +If further media objects are specified in the set, then the local media sub-system itself creates DMedia instances for these on behalf of the driver.
   1.785 +*/
   1.786 +class DPrimaryMediaBase : public DMedia
   1.787 +	{
   1.788 +public:
   1.789 +	enum TMsgId
   1.790 +		{
   1.791 +		EConnect=-1,
   1.792 +		EDisconnect=-2,
   1.793 +		};
   1.794 +
   1.795 +	enum TForceMediaChangeFlags
   1.796 +		{
   1.797 +		/**
   1.798 +		Specifying zero as the flag for DPrimaryMediaBase::ForceMediaChange(), 
   1.799 +		results in all media drivers associated with the primary media being 
   1.800 +		closed and reopened.
   1.801 +		All pending requests on all logical drives associated with the primary 
   1.802 +		media will be cancelled.
   1.803 +
   1.804 +		@see DPrimaryMediaBase::ForceMediaChange()
   1.805 +		@see RLocalDrive::ForceMediaChange()
   1.806 +		*/
   1.807 +		KForceMediaChangeReOpenAllMediaDrivers = 0,
   1.808 +		/**
   1.809 +		This flag is used to simulate ejecting and re-inserting the media.
   1.810 +		All pending requests on all logical drives associated with the primary 
   1.811 +		media will be cancelled.
   1.812 +		N.B. This is asynchronous in behaviour i.e. the caller will need to wait 
   1.813 +		for (two) media change notifications before the drive is ready for use
   1.814 +
   1.815 +		@see DPBusPrimaryMedia::ForceMediaChange()
   1.816 +		@see RLocalDrive::ForceMediaChange()
   1.817 +		*/
   1.818 +		KMediaRemountForceMediaChange = 0x00000001,
   1.819 +		/**
   1.820 +		This flag is used to force the media driver for the specified logical 
   1.821 +		drive to be closed and reopened.
   1.822 +		It should not affect any pending requests on other logical drives 
   1.823 +		associated with the primary media.
   1.824 +
   1.825 +		@see DPrimaryMediaBase::ForceMediaChange()
   1.826 +		@see RLocalDrive::ForceMediaChange()
   1.827 +		*/
   1.828 +		KForceMediaChangeReOpenMediaDriver = 0x80000000
   1.829 +		};
   1.830 +
   1.831 +public:
   1.832 +	IMPORT_C DPrimaryMediaBase();
   1.833 +public:
   1.834 +	// provided by implementation
   1.835 +	IMPORT_C virtual TInt Create(TMediaDevice aDevice, TInt aMediaId, TInt aLastMediaId);
   1.836 +	IMPORT_C virtual TInt Connect(DLocalDrive* aLocalDrive);
   1.837 +	IMPORT_C virtual void Disconnect(DLocalDrive* aLocalDrive);
   1.838 +	IMPORT_C virtual TInt Request(TLocDrvRequest& aRequest);
   1.839 +	IMPORT_C virtual TInt QuickCheckStatus();
   1.840 +	IMPORT_C virtual TInt ForceMediaChange(TInt aMode);
   1.841 +	IMPORT_C virtual TInt InitiatePowerUp();
   1.842 +	IMPORT_C virtual TInt DoInCritical();
   1.843 +	IMPORT_C virtual void DoEndInCritical();
   1.844 +	IMPORT_C virtual void DeltaCurrentConsumption(TInt aCurrent);
   1.845 +	IMPORT_C virtual void DefaultDriveCaps(TLocalDriveCapsV2& aCaps);
   1.846 +	IMPORT_C virtual TBool IsRemovableDevice(TInt& aSocketNum);
   1.847 +public:
   1.848 +	// used by implementation
   1.849 +	IMPORT_C void NotifyMediaChange();
   1.850 +	IMPORT_C void NotifyPowerDown();
   1.851 +	IMPORT_C void NotifyEmergencyPowerDown();
   1.852 +	IMPORT_C void NotifyPsuFault(TInt anError);
   1.853 +	IMPORT_C void NotifyMediaPresent();
   1.854 +	IMPORT_C void PowerUpComplete(TInt anError);
   1.855 +public:
   1.856 +	IMPORT_C virtual void HandleMsg(TLocDrvRequest& aRequest);
   1.857 +	IMPORT_C virtual TInt DoRequest(TLocDrvRequest& aRequest);
   1.858 +	TInt OpenMediaDriver();
   1.859 +	void CloseMediaDrivers(DMedia* aMedia = NULL);
   1.860 +	void StartOpenMediaDrivers();
   1.861 +	void OpenNextMediaDriver();
   1.862 +	void DoOpenMediaDriverComplete(TInt anError);
   1.863 +	void DoPartitionInfoComplete(TInt anError);
   1.864 +	void CompleteCurrent(TInt anError);
   1.865 +	void CompleteRequest(TLocDrvRequest& aMsg, TInt aResult);
   1.866 +	IMPORT_C void RunDeferred();
   1.867 +	void SetClosed(TInt anError);
   1.868 +	void NotifyClients(TBool aMediaChange,TLocDrv* aLocDrv=NULL);
   1.869 +	TInt InCritical();
   1.870 +	void EndInCritical();
   1.871 +	void UpdatePartitionInfo();
   1.872 +	void MediaReadyHandleRequest();
   1.873 +	TInt SendReceive(TLocDrvRequest& aReq, TLinAddr aLinAddress = NULL);
   1.874 +
   1.875 +#ifdef __DEMAND_PAGING__
   1.876 +	TInt PinSendReceive(TLocDrvRequest& aReq, TLinAddr aStart = NULL);
   1.877 +	TInt PinFragmentSendReceive(TLocDrvRequest& aReq, TLinAddr aLinAddress, TInt aLength);
   1.878 +
   1.879 +	TBool PagingMediaPinAddress(TLinAddr aLinAddress, TInt aSize);
   1.880 +	void PagingMediaUnpinAddress();
   1.881 +#endif
   1.882 +
   1.883 +#ifdef __DEMAND_PAGING__
   1.884 +	void RequestCountInc();
   1.885 +	void RequestCountDec();
   1.886 +#endif
   1.887 +
   1.888 +public:
   1.889 +	TInt iLastMediaId;					/**< @internalComponent */
   1.890 +	TMessageQue iMsgQ;
   1.891 +	TDfcQue* iDfcQ;
   1.892 +	SDblQue iConnectionQ;				/**< @internalComponent */
   1.893 +	TMessageQue iDeferred;				/**< @internalComponent */
   1.894 +	TMessageQue iWaitMedChg;			/**< @internalComponent */
   1.895 +	TInt iState;						/**< @internalComponent */
   1.896 +	TInt iCritical;						/**< @internalComponent */
   1.897 +	TLocDrvRequest* iCurrentReq;
   1.898 +	TDfc iAsyncDfc;						/**< @internalComponent */
   1.899 +	TInt iAsyncErrorCode;				/**< @internalComponent */
   1.900 +	RPhysicalDeviceArray iPhysDevArray;	/**< @internalComponent */
   1.901 +
   1.902 +	class DBody;
   1.903 +	DBody* iBody;						/**< @internalComponent */
   1.904 +
   1.905 +	TInt iNextMediaId;					/**< @internalComponent */
   1.906 +	TInt iTotalPartitionsOpened;		/**< @internalComponent */
   1.907 +	TInt iMediaDriversOpened;			/**< @internalComponent */
   1.908 +	DMediaDriver* iNextMediaDriver;		/**< @internalComponent */
   1.909 +
   1.910 +
   1.911 +#ifdef __DEMAND_PAGING__
   1.912 +	// keep the size of class as it is used as base for PBus and may not want to bother building DP specific version.
   1.913 +	TUint8 iPagingMedia;				/**< @internalComponent */
   1.914 +	TUint8 iDataPagingMedia;			/**< @internalComponent */
   1.915 +	TUint8 iRomPagingMedia;				/**< @internalComponent */
   1.916 +	TUint8 iRunningDeferred;			/**< @internalComponent */
   1.917 +#else
   1.918 +	TInt iRunningDeferred;				/**< @internalComponent */
   1.919 +#endif
   1.920 +	};
   1.921 +
   1.922 +#ifdef __DEMAND_PAGING__
   1.923 +
   1.924 +/**
   1.925 +@internalComponent
   1.926 +@prototype
   1.927 +*/
   1.928 +NONSHARABLE_CLASS(DMediaPagingDevice) : public DPagingDevice
   1.929 +	{
   1.930 +public:
   1.931 +	enum TPagingRequestId
   1.932 +		{
   1.933 +		/** 
   1.934 +		Identifies any middle fragment of a Write request on a partition of a media that supports paging.
   1.935 +		@deprecated
   1.936 +		*/
   1.937 +		EWriteRequestFragment		=	DLocalDrive::EFirstReqNumberReservedForPaging,
   1.938 +
   1.939 +		/** 
   1.940 +		Identifies the last fragment of a Write request on a partition of a media that supports paging.
   1.941 +		@deprecated
   1.942 +		*/
   1.943 +		EWriteRequestFragmentLast	=	DLocalDrive::EFirstReqNumberReservedForPaging+1,
   1.944 +
   1.945 +		/** 
   1.946 +		Request for paging in (read) data from the ROM store area.
   1.947 +		*/
   1.948 +		ERomPageInRequest			=	DLocalDrive::EFirstReqNumberReservedForPaging+2,
   1.949 +
   1.950 +		/** 
   1.951 +		Request for paging in (read) data from the code store area.
   1.952 +		*/
   1.953 +		ECodePageInRequest			=	DLocalDrive::EFirstReqNumberReservedForPaging+3,
   1.954 +
   1.955 +        /**
   1.956 +        Provided to allow the following compile time assert.
   1.957 +        */
   1.958 +		EPagingRequestHighWaterMark
   1.959 +		};
   1.960 +    __ASSERT_COMPILE(EPagingRequestHighWaterMark <= DLocalDrive::ELastReqNumberReservedForPaging + 1);
   1.961 +
   1.962 +	enum TQueue
   1.963 +		{
   1.964 +		EMainQ = 0x01,
   1.965 +		EDeferredQ=0x02
   1.966 +		};
   1.967 +
   1.968 +public:
   1.969 +	DMediaPagingDevice(DPrimaryMediaBase* aPtr);
   1.970 +	virtual ~DMediaPagingDevice();
   1.971 +	
   1.972 +	// from DPagingDevice
   1.973 +	virtual TInt Read(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize,TInt aDrvNumber);
   1.974 +	virtual TInt Write(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize, TBool aBackground);
   1.975 +	virtual TInt DeleteNotify(TThreadMessage* aReq,TUint aOffset,TUint aSize);
   1.976 +
   1.977 +	void CompleteRequest(TThreadMessage* aMsg, TInt aResult);
   1.978 +	void SendToMainQueueDfcAndBlock(TThreadMessage* aMsg);
   1.979 +	void SendToDeferredQ(TThreadMessage* aMsg);
   1.980 +	inline static TBool PageInRequest(TLocDrvRequest& aReq);
   1.981 +	inline static TBool PageOutRequest(TLocDrvRequest& aReq);
   1.982 +	inline static TBool PagingRequest(TLocDrvRequest& aReq);
   1.983 +public:
   1.984 +	TMessageQue iMainQ;
   1.985 +	TMessageQue iDeferredQ;
   1.986 +	DPrimaryMediaBase* iPrimaryMedia;
   1.987 +
   1.988 +	TUint8 iEmptyingQ;
   1.989 +	TUint8 iDeleteNotifyNotSupported;
   1.990 +	TUint8 iSpare1;
   1.991 +	TUint8 iSpare2;
   1.992 +
   1.993 +	TAny* iMountInfoDataLock;
   1.994 +	TAny* iMountInfoDescHdrLock;
   1.995 +	TAny* iMountInfoDescLenLock;
   1.996 +
   1.997 +	TInt iFirstLocalDriveNumber;
   1.998 +	TInt iRomPagingDriveNumber;
   1.999 +	TInt iDataPagingDriveNumber;
  1.1000 +
  1.1001 +	NFastMutex iInstrumentationLock;			// To protect instrumentation data
  1.1002 +
  1.1003 +#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  1.1004 +	TUint8 iServicingROM;
  1.1005 +	TUint8 iServicingCode;
  1.1006 +	TUint8 iServicingDataIn;
  1.1007 +	TUint8 iServicingDataOut;
  1.1008 +
  1.1009 +	SMediaROMPagingConcurrencyInfo iROMStats;
  1.1010 +	SMediaCodePagingConcurrencyInfo iCodeStats;
  1.1011 +	SMediaDataPagingConcurrencyInfo iDataStats;
  1.1012 +#endif
  1.1013 +
  1.1014 +#ifdef __DEMAND_PAGING_BENCHMARKS__
  1.1015 +	SPagingBenchmarkInfo iROMBenchmarkData;
  1.1016 +	SPagingBenchmarkInfo iCodeBenchmarkData;
  1.1017 +	SPagingBenchmarkInfo iDataInBenchmarkData;
  1.1018 +	SPagingBenchmarkInfo iDataOutBenchmarkData;
  1.1019 +	SMediaPagingInfo iMediaPagingInfo;
  1.1020 +#endif
  1.1021 +	};
  1.1022 +
  1.1023 +inline TBool DMediaPagingDevice::PageInRequest(TLocDrvRequest& aReq)
  1.1024 +	{
  1.1025 +	return 
  1.1026 +		(aReq.Flags() & TLocDrvRequest::EPaging) && 
  1.1027 +		(aReq.Id() == ERomPageInRequest || 
  1.1028 +		 aReq.Id() == ECodePageInRequest || 
  1.1029 +		 aReq.Id() == DLocalDrive::ERead);}
  1.1030 +
  1.1031 +inline TBool DMediaPagingDevice::PageOutRequest(TLocDrvRequest& aReq)
  1.1032 +	{
  1.1033 +	return 
  1.1034 +		(aReq.Flags() & TLocDrvRequest::EPaging) && 
  1.1035 +		(aReq.Id() == DLocalDrive::EWrite);}
  1.1036 +
  1.1037 +inline TBool DMediaPagingDevice::PagingRequest(TLocDrvRequest& aReq)
  1.1038 +	{
  1.1039 +	return (aReq.Flags() & TLocDrvRequest::EPaging);
  1.1040 +	}
  1.1041 +
  1.1042 +
  1.1043 +/**
  1.1044 +@internalComponent
  1.1045 +@prototype
  1.1046 +*/
  1.1047 +class DFragmentationPagingLock: public DDemandPagingLock
  1.1048 +	{
  1.1049 +public:
  1.1050 +	TInt Construct(TUint aNumPages);
  1.1051 +	void Cleanup();
  1.1052 +	void LockFragmentation()
  1.1053 +		{
  1.1054 +		__ASSERT_CRITICAL;
  1.1055 +		__ASSERT_DEBUG(iFragmentationMutex, Kern::Fault("LOCMEDIA_H",__LINE__));
  1.1056 +		// called in CS
  1.1057 +		Kern::MutexWait(*iFragmentationMutex);
  1.1058 +		}
  1.1059 +	void UnlockFragmentation()
  1.1060 +		{
  1.1061 +		__ASSERT_CRITICAL;
  1.1062 +		__ASSERT_DEBUG(iFragmentationMutex, Kern::Fault("LOCMEDIA_H",__LINE__));
  1.1063 +		// called in CS
  1.1064 +		Kern::MutexSignal(*iFragmentationMutex);
  1.1065 +		}
  1.1066 +
  1.1067 +
  1.1068 +public:
  1.1069 +	TUint iFragmentGranularity;
  1.1070 +private:
  1.1071 +	DMutex* iFragmentationMutex; // to protect Kernel memory locking
  1.1072 +	};
  1.1073 +#endif //__DEMAND_PAGING__
  1.1074 +
  1.1075 +/**
  1.1076 +@publishedPartner
  1.1077 +@released
  1.1078 +
  1.1079 +An abstract base class for all media drivers in the local drive system.
  1.1080 +
  1.1081 +All media drivers, whether associated with fixed media, such as the internal
  1.1082 +drive, or removable media, such as a PC Card or MultiMediaCard, must define
  1.1083 +and implement a class derived from this one.
  1.1084 +
  1.1085 +An instance of this class is created by the media driver's PDD factory,
  1.1086 +an instance of a class derived from DPhysicalDevice. 
  1.1087 +
  1.1088 +@see DPhysicalDevice::Create()
  1.1089 +@see DPhysicalDevice
  1.1090 +*/
  1.1091 +class DMediaDriver : public DBase
  1.1092 +	{
  1.1093 +public:
  1.1094 +	IMPORT_C DMediaDriver(TInt aMediaId);
  1.1095 +	IMPORT_C virtual ~DMediaDriver();
  1.1096 +	IMPORT_C virtual void Close();
  1.1097 +// Pure virtual
  1.1098 +	IMPORT_C virtual void Disconnect(DLocalDrive* aLocalDrive, TThreadMessage* aMsg);
  1.1099 +	
  1.1100 +	/**
  1.1101 +	A function called by the local media subsystem to deal with a request, 
  1.1102 +	and which must be implemented by the media driver.
  1.1103 +	
  1.1104 +	@param aRequest An object that encapsulates information about the request.
  1.1105 +	
  1.1106 +	@return A value indicating the result:
  1.1107 +	        KErrNone, if the request has been sucessfully initiated;
  1.1108 +	        KErrNotSupported, if the request cannot be handled by the device;
  1.1109 +	        KMediaDriverDeferRequest, if the request cannot be handled
  1.1110 +	        immediately because of an outstanding request (this request will be
  1.1111 +	        deferred until the outstanding request has completed);
  1.1112 +	        otherwise one of the other system-wide error codes.
  1.1113 +	*/
  1.1114 +	virtual TInt Request(TLocDrvRequest& aRequest)=0;
  1.1115 +
  1.1116 +	/**
  1.1117 +	A function called by the local media subsystem to get partition information
  1.1118 +	for the media device.
  1.1119 +	
  1.1120 +	It is called once the subsystem has been notified that the media driver
  1.1121 +	is open and has been succesfully initialised.
  1.1122 +	
  1.1123 +	This function must be implemented by the media driver.
  1.1124 +	
  1.1125 +	@param anInfo An object that, on successful return, contains
  1.1126 +	              the partition information.
  1.1127 +	
  1.1128 +	@return KErrNone, if retrieval of partition information is to be
  1.1129 +	        done asynchronously;
  1.1130 +	        KErrCompletion, if retrieval of partition information has been
  1.1131 +	        done synchronously, and successfully;
  1.1132 +	        one of the other system-wide error codes, if retrieval of partition
  1.1133 +	        information has been done synchronously, but unsuccessfully.
  1.1134 +	*/
  1.1135 +	virtual TInt PartitionInfo(TPartitionInfo &anInfo)=0;
  1.1136 +
  1.1137 +	/**
  1.1138 +	A function called by the local media subsystem to inform the media driver
  1.1139 +	that the device should power down.
  1.1140 +	
  1.1141 +	This function must be implemented by the media driver.
  1.1142 +	*/
  1.1143 +	virtual void NotifyPowerDown()=0;
  1.1144 +
  1.1145 +	/**
  1.1146 +	A function called by the local media subsystem to inform the media driver
  1.1147 +	that the device is to be immediately powered down.
  1.1148 +	
  1.1149 +    This function must be implemented by the media driver.
  1.1150 +	*/
  1.1151 +	virtual void NotifyEmergencyPowerDown()=0;
  1.1152 +public:
  1.1153 +	IMPORT_C void SetTotalSizeInBytes(Int64 aTotalSizeInBytes, TLocDrv* aLocDrv=NULL);
  1.1154 +	IMPORT_C Int64 TotalSizeInBytes();
  1.1155 +	IMPORT_C void SetCurrentConsumption(TInt aValue);
  1.1156 +	IMPORT_C TInt InCritical();
  1.1157 +	IMPORT_C void EndInCritical();
  1.1158 +	IMPORT_C void Complete(TLocDrvRequest& aRequest, TInt aResult);
  1.1159 +	IMPORT_C void OpenMediaDriverComplete(TInt anError);
  1.1160 +	IMPORT_C void PartitionInfoComplete(TInt anError);
  1.1161 +public:
  1.1162 +	DPhysicalDevice* iPhysicalDevice;/**< @internalComponent */
  1.1163 +	Int64 iTotalSizeInBytes;         /**< @internalComponent */
  1.1164 +    TInt iCurrentConsumption;        /**< @internalComponent */
  1.1165 +	DPrimaryMediaBase* iPrimaryMedia;/**< @internalComponent */
  1.1166 +	TBool iCritical;                 /**< @internalComponent */
  1.1167 +	TMountInfoData* iMountInfo;      /**< @internalComponent */
  1.1168 +	};
  1.1169 +
  1.1170 +
  1.1171 +
  1.1172 +
  1.1173 +/**
  1.1174 +@publishedPartner
  1.1175 +@released
  1.1176 +
  1.1177 +A structure that a media driver may find useful in its implementation,
  1.1178 +and is used to contain the information required when registering
  1.1179 +the media driver with the Local Media Subsystem.
  1.1180 +
  1.1181 +@see LocDrv::RegisterMediaDevice()
  1.1182 +*/
  1.1183 +struct SMediaDeviceInfo
  1.1184 +	{
  1.1185 +	
  1.1186 +	/**
  1.1187 +	The unique Media ID for a device.
  1.1188 +	
  1.1189 +    This can take one of the enumerated values defined
  1.1190 +    by the TMediaDevice enum.
  1.1191 +	*/
  1.1192 +	TMediaDevice iDevice;
  1.1193 +	
  1.1194 +	
  1.1195 +	/**
  1.1196 +	Specifies the number of local drive objects to be assigned to the media driver.
  1.1197 +    
  1.1198 +    Drives that support more than one partition must specify a number greater than 1.
  1.1199 +	*/
  1.1200 +	TInt iDriveCount;
  1.1201 +	
  1.1202 +	
  1.1203 +	/**
  1.1204 +    A pointer to an array of TInt values, which define the drive numbers that
  1.1205 +    are to be allocated to each partition.
  1.1206 +    
  1.1207 +    0 signifies Drive C, 1 signifies drive D, etc. For example, to allocate
  1.1208 +    drive letters J and K, specify an array containing the values [7,8].
  1.1209 +    Note that the size of this array must be the same as the value specified
  1.1210 +    by iDriveCount.
  1.1211 +	*/
  1.1212 +	const TInt* iDriveList;
  1.1213 +	
  1.1214 +	
  1.1215 +	/**
  1.1216 +	Specifies the total number of DMedia objects to be associated with
  1.1217 +	the media driver.
  1.1218 +	
  1.1219 +	This number includes the primary DPrimaryMedia object, plus all of
  1.1220 +	the DMedia objects that are created for each additional drive, and
  1.1221 +	which hold basic information about partitions.
  1.1222 +	*/
  1.1223 +	TInt iNumMedia; 
  1.1224 +	
  1.1225 +	
  1.1226 +	/**
  1.1227 +	A pointer to a descriptor containing the name of the media driver,
  1.1228 +	for example: PCCard
  1.1229 +	*/
  1.1230 +	const TDesC* iDeviceName;
  1.1231 +	};
  1.1232 +
  1.1233 +
  1.1234 +
  1.1235 +
  1.1236 +/**
  1.1237 +@publishedPartner
  1.1238 +@released
  1.1239 +
  1.1240 +A set of utility functions used in the management of local media drivers.
  1.1241 +*/
  1.1242 +class LocDrv
  1.1243 +	{
  1.1244 +public:
  1.1245 +	IMPORT_C static TInt RegisterMediaDevice(TMediaDevice aDevice, TInt aDriveCount, const TInt* aDriveList, DPrimaryMediaBase* aPrimaryMedia, TInt aNumMedia, const TDesC& aName);
  1.1246 +	IMPORT_C static TInt RegisterPasswordStore(TPasswordStore* aStore);
  1.1247 +	IMPORT_C static TPasswordStore* PasswordStore();
  1.1248 +#if !defined(__WINS__)
  1.1249 +	IMPORT_C static TInt RegisterPagingDevice(DPrimaryMediaBase* aPrimaryMedia, const TInt* aPagingDriveList, TInt aDriveCount, TUint aPagingType, TInt aReadShift, TUint aNumPages);
  1.1250 +#endif // __WINS__
  1.1251 +	IMPORT_C static TInt RegisterDmaDevice(DPrimaryMediaBase* aPrimaryMedia,
  1.1252 +										   TInt aMediaBlockSize, 
  1.1253 +										   TInt aDmaMaxAddressable,
  1.1254 +										   TInt aDmaAlignment);
  1.1255 +	};
  1.1256 +
  1.1257 +/**
  1.1258 +@internalComponent
  1.1259 +*/
  1.1260 +inline TInt TLocDrv::Connect(DLocalDrive* aLocalDrive)
  1.1261 +	{ return iPrimaryMedia->Connect(aLocalDrive); }
  1.1262 +
  1.1263 +/**
  1.1264 +@internalComponent
  1.1265 +*/
  1.1266 +inline void TLocDrv::Disconnect(DLocalDrive* aLocalDrive)
  1.1267 +	{ iPrimaryMedia->Disconnect(aLocalDrive); }
  1.1268 +
  1.1269 +/**
  1.1270 +@internalComponent
  1.1271 +*/
  1.1272 +inline TInt TLocDrv::Request(TLocDrvRequest& aRequest)
  1.1273 +	{ return iPrimaryMedia->Request(aRequest); }
  1.1274 +
  1.1275 +/**
  1.1276 +Returns the length of the media, in bytes, according to the partition information.
  1.1277 +
  1.1278 +@return Total length of the media, in bytes.
  1.1279 +
  1.1280 +@see	TPartitionInfo
  1.1281 +*/
  1.1282 +inline Int64 DMedia::MediaLenInBytes()
  1.1283 +	{return(iPartitionInfo.iMediaSizeInBytes);}
  1.1284 +
  1.1285 +/**
  1.1286 +Returns the unique media ID for this device.
  1.1287 +
  1.1288 +@return	The device ID that was set in the call to DMedia::Create().
  1.1289 +		The return value will be one of the enumerators declared in TMediaDevice
  1.1290 +
  1.1291 +@see	TMediaDevice
  1.1292 +*/
  1.1293 +inline TMediaDevice DMedia::DeviceType()
  1.1294 +	{return(iDevice);}
  1.1295 +
  1.1296 +/**
  1.1297 +Returns the total number of partitions that exist on the media according to the
  1.1298 +partition information.
  1.1299 +
  1.1300 +This will always be less than or equal to KMaxPartitionEntries.
  1.1301 +
  1.1302 +@return Number of partitions that exist on the media.
  1.1303 +
  1.1304 +@see	KMaxPartitionEntries
  1.1305 +@see	TPartitionInfo
  1.1306 +*/
  1.1307 +inline TInt DMedia::PartitionCount()
  1.1308 +	{return(iPartitionInfo.iPartitionCount);}
  1.1309 +
  1.1310 +/**
  1.1311 +The start address of the partition, described as a relative offset, in bytes,
  1.1312 +from the start of the media.
  1.1313 +
  1.1314 +This value is used by the local media subsystem to calculate the absolute 
  1.1315 +address on the media whenever an access such as a Read, Write or Format request
  1.1316 +is made.
  1.1317 +
  1.1318 +@param	aPartition	The partition whose start address is to be returned.
  1.1319 +
  1.1320 +@return	The start address of the partition.
  1.1321 +
  1.1322 +@see	TPartitionEntry
  1.1323 +@see	TPartitionInfo
  1.1324 +*/
  1.1325 +inline Int64 DMedia::PartitionBaseAddr(TInt aPartition)
  1.1326 +	{return(iPartitionInfo.iEntry[aPartition].iPartitionBaseAddr);}
  1.1327 +
  1.1328 +/**
  1.1329 +Returns the length of the partition, in bytes.
  1.1330 +
  1.1331 +@param	aPartition	The partition whose length is to be returned.
  1.1332 +
  1.1333 +@return	The length of the partition.
  1.1334 +
  1.1335 +@see	TPartitionEntry
  1.1336 +@see	TPartitionInfo
  1.1337 +*/
  1.1338 +inline Int64 DMedia::PartitionLen(TInt aPartition)
  1.1339 +	{return(iPartitionInfo.iEntry[aPartition].iPartitionLen);}
  1.1340 +
  1.1341 +
  1.1342 +/**
  1.1343 +@internalTechnology
  1.1344 +
  1.1345 +A utility class for scanning MBR/EBR partition tables.
  1.1346 +*/
  1.1347 +class TPartitionTableScanner
  1.1348 +	{
  1.1349 +public:
  1.1350 +	enum {ESectorShift=9, ESectorSize=512};
  1.1351 +	enum {EMaxNest=4};
  1.1352 +	struct SPart
  1.1353 +		{
  1.1354 +		SPart(const TUint8* a);
  1.1355 +		TUint8 iBootInd;
  1.1356 +		TUint8 iType;
  1.1357 +		TUint32 iRSS;
  1.1358 +		TUint32 iSectors;
  1.1359 +		};
  1.1360 +	struct SEBR
  1.1361 +		{
  1.1362 +		TInt64 iRSS;
  1.1363 +		TInt64 iSectors;
  1.1364 +		};
  1.1365 +public:
  1.1366 +	IMPORT_C void Set(TUint8* aSectorBuffer, TPartitionEntry* aEntry, TInt aMaxPartitions, TInt64 aMediaSize);
  1.1367 +	IMPORT_C TInt64 NextLBA();
  1.1368 +	IMPORT_C TInt NumberOfPartitionsFound() const;
  1.1369 +	TInt MakeEntry(const SPart& aP);
  1.1370 +public:
  1.1371 +	TInt64 iMediaSize;				// Total media size in sectors
  1.1372 +	TInt64 iLBA;					// LBA currently in sector buffer
  1.1373 +	TInt64 iFirstEBR;				// LBA of first EBR if any
  1.1374 +	SEBR iStack[EMaxNest];
  1.1375 +	TInt iStackPointer;
  1.1376 +	TUint8* iSectorBuffer;			// Pointer to 512 byte area where sector data is stored
  1.1377 +	TPartitionEntry* iFirstEntry;	// Where first scanned partition is stored
  1.1378 +	TPartitionEntry* iNextEntry;	// Where next scanned partition will be stored
  1.1379 +	TPartitionEntry* iLimit;		// iFirstEntry + max partitions
  1.1380 +	};
  1.1381 +
  1.1382 +
  1.1383 +
  1.1384 +#endif