author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 07 Jan 2010 13:38:45 +0200 | |
changeset 33 | 0173bcd7697c |
parent 0 | a41df078684a |
child 39 | 5d2844f35677 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-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". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32\drivers\locmedia\locmedia.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include "locmedia.h" |
|
19 |
#include <d32locd.h> |
|
20 |
#include "dmasupport.h" |
|
21 |
#include <kernel/cache.h> |
|
22 |
||
23 |
#if defined(_DEBUG) && defined(__DEMAND_PAGING__) |
|
24 |
//#define __DEBUG_DEMAND_PAGING__ |
|
25 |
#endif |
|
26 |
||
27 |
||
28 |
#if 0 |
|
29 |
#define CHECK_RET(r) if ((r)==KErrNotSupported && (KDebugNum(KSCRATCH))) {NKern::Lock(); *(TInt*)0xfaece5=0;} |
|
30 |
//#define CHECK_RET(r) |
|
31 |
#else |
|
32 |
#define CHECK_RET(r) |
|
33 |
#endif |
|
34 |
||
35 |
_LIT(KLddName,"LocDrv"); |
|
36 |
_LIT(KLitMediaDriverName, "Media.*"); |
|
37 |
_LIT(KLitLocMedia,"LocMedia"); |
|
38 |
||
39 |
#define LOCM_FAULT() Kern::Fault("LOCMEDIA",__LINE__) |
|
40 |
||
41 |
const TInt KMaxLocalDriveCapsLength=256; |
|
42 |
const TInt KMaxQueryDeviceLength=256; |
|
43 |
||
44 |
// The maximum amount of user-data which will be pinned. If a request is longer |
|
45 |
// than this value it will be split up into a number of requests |
|
46 |
// This value is a bit arbitrary - it needs to be sufficiently large so that transfer |
|
47 |
// rates don't suffer too much - but it can't be too big or we'd be "stealing" too much |
|
48 |
// memory from the demand paging pool and starving other processes |
|
49 |
const TInt KMaxPinData = 256*1024; |
|
50 |
||
51 |
// The number of locks available for pinning shared by all the drive threads in the system. |
|
52 |
// If all locks are in use then a single pre-allocated lock is used. |
|
53 |
const TInt KDynamicPagingLockCount = 8; |
|
54 |
||
55 |
TLocDrv* TheDrives[KMaxLocalDrives]; |
|
56 |
DMedia* TheMedia[KMaxLocalDrives]; |
|
57 |
HBuf* DriveNames[KMaxLocalDrives]; |
|
58 |
TInt UsedMedia=0; |
|
59 |
TPasswordStore* ThePasswordStore=NULL; |
|
60 |
||
61 |
class DPrimaryMediaBase::DBody : public DBase |
|
62 |
{ |
|
63 |
public: |
|
64 |
TInt iPhysDevIndex; |
|
65 |
TInt iRequestCount; |
|
66 |
#ifdef __DEMAND_PAGING__ |
|
67 |
DMediaPagingDevice* iPagingDevice; |
|
68 |
TInt iPageSizeMsk; // Mask of page size (e.g. 4096-1 -> 4095) |
|
69 |
TInt iMediaChanges; |
|
70 |
#endif |
|
71 |
}; |
|
72 |
||
73 |
#ifdef __DEMAND_PAGING__ |
|
74 |
DMediaPagingDevice* ThePagingDevices[KMaxLocalDrives]; |
|
75 |
DPrimaryMediaBase* TheRomPagingMedia = NULL; |
|
76 |
DPrimaryMediaBase* TheDataPagingMedia = NULL; |
|
77 |
TBool DataPagingDeviceRegistered = EFalse; |
|
78 |
class DPinObjectAllocator; |
|
79 |
DPinObjectAllocator* ThePinObjectAllocator = NULL; |
|
80 |
||
81 |
// The paging media might share a DfcQ with other non-paging media (e.g. 2 MMC/SD cards sharing the same stack) |
|
82 |
// In this case, we need to avoid taking page faults on the non-paging media too, hence the need for these checks: |
|
83 |
inline TBool DataPagingDfcQ(DPrimaryMediaBase* aPrimaryMedia) |
|
84 |
{return TheDataPagingMedia && TheDataPagingMedia->iDfcQ == aPrimaryMedia->iDfcQ;} |
|
85 |
inline TBool RomPagingDfcQ(DPrimaryMediaBase* aPrimaryMedia) |
|
86 |
{return TheRomPagingMedia && TheRomPagingMedia->iDfcQ == aPrimaryMedia->iDfcQ;} |
|
87 |
||
88 |
||
89 |
||
90 |
/* |
|
91 |
DPinObjectAllocator |
|
92 |
||
93 |
Internal class which contains : |
|
94 |
(1) a queue of pre-allocated TVirtualPinObject's; |
|
95 |
(2) a single pre-allocated DFragmentationPagingLock object: |
|
96 |
this may be used if there are no TVirtualPinObject's available or if Kern::PinVirtualMemory() fails |
|
97 |
*/ |
|
98 |
NONSHARABLE_CLASS(DPinObjectAllocator) : public DBase |
|
99 |
{ |
|
100 |
public: |
|
101 |
/* |
|
102 |
SVirtualPinContainer |
|
103 |
Internal class encapsulating a TVirtualPinObject. |
|
104 |
Contains a SDblQueLink so that it may form part of a SDblQue |
|
105 |
*/ |
|
106 |
typedef struct |
|
107 |
{ |
|
108 |
TVirtualPinObject* iObject; |
|
109 |
SDblQueLink iLink; |
|
110 |
} SVirtualPinContainer; |
|
111 |
||
112 |
public: |
|
113 |
inline DPinObjectAllocator() {}; |
|
114 |
~DPinObjectAllocator(); |
|
115 |
TInt Construct(TInt aObjectCount, TUint aNumPages); |
|
116 |
||
117 |
SVirtualPinContainer* AcquirePinObject(); |
|
118 |
void ReleasePinObject(SVirtualPinContainer* aVirtualPinObject); |
|
119 |
||
120 |
inline DFragmentationPagingLock& PreAllocatedDataLock() {return *iPreAllocatedDataLock;} |
|
121 |
||
122 |
private: |
|
123 |
// array of SVirtualPinContainer's |
|
124 |
SVirtualPinContainer* iVirtualPinContainers; |
|
125 |
TInt iObjectCount; |
|
126 |
||
127 |
// queues containing SVirtualPinContainer's |
|
128 |
SDblQue iFreeQ; |
|
129 |
||
130 |
// pre-allocated (small) buffers for locking client data should Kern::PinVirtualMemory() fail |
|
131 |
DFragmentationPagingLock* iPreAllocatedDataLock; |
|
132 |
||
133 |
// A mutex to protect access to the pinning objects. |
|
134 |
NFastMutex iLock; |
|
135 |
||
136 |
public: |
|
137 |
TUint iFragmentGranularity; |
|
138 |
}; |
|
139 |
||
140 |
||
141 |
DPinObjectAllocator::~DPinObjectAllocator() |
|
142 |
{ |
|
143 |
if (iPreAllocatedDataLock) |
|
144 |
{ |
|
145 |
iPreAllocatedDataLock->Cleanup(); |
|
146 |
delete iPreAllocatedDataLock; |
|
147 |
} |
|
148 |
||
149 |
for (TInt n=0; n<iObjectCount; n++) |
|
150 |
{ |
|
151 |
SVirtualPinContainer& virtualPinContainer = iVirtualPinContainers[n]; |
|
152 |
if (virtualPinContainer.iObject) |
|
153 |
Kern::DestroyVirtualPinObject(virtualPinContainer.iObject); |
|
154 |
} |
|
155 |
||
156 |
delete [] iVirtualPinContainers; |
|
157 |
} |
|
158 |
||
159 |
TInt DPinObjectAllocator::Construct(TInt aObjectCount, TUint aNumPages) |
|
160 |
{ |
|
161 |
TInt pageSize = Kern::RoundToPageSize(1); |
|
162 |
iFragmentGranularity = pageSize * aNumPages; |
|
163 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Fragmentation granularity set to 0x%x", iFragmentGranularity)); |
|
164 |
||
165 |
// construct the paging lock containing pre-allocated buffers |
|
166 |
||
167 |
iPreAllocatedDataLock = new DFragmentationPagingLock(); |
|
168 |
if(!iPreAllocatedDataLock) |
|
169 |
return KErrNoMemory; |
|
170 |
TInt r = iPreAllocatedDataLock->Construct(aNumPages); |
|
171 |
if (r != KErrNone) |
|
172 |
return r; |
|
173 |
||
174 |
||
175 |
SVirtualPinContainer* iVirtualPinContainers = new SVirtualPinContainer[aObjectCount]; |
|
176 |
if (iVirtualPinContainers == NULL) |
|
177 |
return KErrNoMemory; |
|
178 |
memclr(iVirtualPinContainers, sizeof(SVirtualPinContainer) * aObjectCount); |
|
179 |
iObjectCount = aObjectCount; |
|
180 |
||
181 |
// construct the queue of dynamic paging locks |
|
182 |
for (TInt n=0; n<aObjectCount; n++) |
|
183 |
{ |
|
184 |
SVirtualPinContainer& pinContainer = iVirtualPinContainers[n]; |
|
185 |
||
186 |
TInt r = Kern::CreateVirtualPinObject(pinContainer.iObject); |
|
187 |
if (r != KErrNone) |
|
188 |
return KErrNoMemory; |
|
189 |
||
190 |
||
191 |
iFreeQ.Add(&pinContainer.iLink); |
|
192 |
} |
|
193 |
return KErrNone; |
|
194 |
} |
|
195 |
||
196 |
/** |
|
197 |
returns a SVirtualPinContainer object or NULL if NULL available |
|
198 |
*/ |
|
199 |
DPinObjectAllocator::SVirtualPinContainer* DPinObjectAllocator::AcquirePinObject() |
|
200 |
{ |
|
201 |
SVirtualPinContainer* pinContainer = NULL; |
|
202 |
||
203 |
NKern::FMWait(&iLock); |
|
204 |
||
205 |
if (!iFreeQ.IsEmpty()) |
|
206 |
{ |
|
207 |
SDblQueLink* link = iFreeQ.First(); |
|
208 |
pinContainer = _LOFF(link, SVirtualPinContainer, iLink); |
|
209 |
link->Deque(); |
|
210 |
} |
|
211 |
||
212 |
||
213 |
NKern::FMSignal(&iLock); |
|
214 |
return pinContainer; |
|
215 |
} |
|
216 |
||
217 |
/** |
|
218 |
returns a SVirtualPinContainer object to the pool |
|
219 |
*/ |
|
220 |
void DPinObjectAllocator::ReleasePinObject(SVirtualPinContainer* aPinContainer) |
|
221 |
{ |
|
222 |
NKern::FMWait(&iLock); |
|
223 |
||
224 |
iFreeQ.Add(&aPinContainer->iLink); |
|
225 |
||
226 |
NKern::FMSignal(&iLock); |
|
227 |
} |
|
228 |
||
229 |
#endif // __DEMAND_PAGING__ |
|
230 |
||
231 |
||
232 |
/******************************************** |
|
233 |
* Local drive device base class |
|
234 |
********************************************/ |
|
235 |
DECLARE_EXTENSION_LDD() |
|
236 |
{ |
|
237 |
return new DLocalDriveFactory; |
|
238 |
} |
|
239 |
||
240 |
DLocalDriveFactory::DLocalDriveFactory() |
|
241 |
// |
|
242 |
// Constructor |
|
243 |
// |
|
244 |
{ |
|
245 |
iParseMask=KDeviceAllowUnit|KDeviceAllowInfo; |
|
246 |
iUnitsMask=~(0xffffffff<<KMaxLocalDrives); |
|
247 |
iVersion=TVersion(KLocalDriveMajorVersion,KLocalDriveMinorVersion,KLocalDriveBuildVersion); |
|
248 |
} |
|
249 |
||
250 |
TInt DLocalDriveFactory::Install() |
|
251 |
// |
|
252 |
// Install the device driver. |
|
253 |
// |
|
254 |
{ |
|
255 |
return SetName(&KLddName); |
|
256 |
} |
|
257 |
||
258 |
void DLocalDriveFactory::GetCaps(TDes8& /*aDes*/) const |
|
259 |
// |
|
260 |
// Return the Comm capabilities. |
|
261 |
// |
|
262 |
{ |
|
263 |
// TCapsLocalDriveV01 b; |
|
264 |
// b.version=iVersion; |
|
265 |
// aDes.FillZ(aDes.MaxLength()); |
|
266 |
// aDes.Copy((TUint8 *)&b,Min(aDes.MaxLength(),sizeof(b))); |
|
267 |
} |
|
268 |
||
269 |
TInt DLocalDriveFactory::Create(DLogicalChannelBase*& aChannel) |
|
270 |
// |
|
271 |
// Create a channel on the device. |
|
272 |
// |
|
273 |
{ |
|
274 |
aChannel=new DLocalDrive; |
|
275 |
return aChannel?KErrNone:KErrNoMemory; |
|
276 |
} |
|
277 |
||
278 |
/******************************************** |
|
279 |
* Local drive interface class |
|
280 |
********************************************/ |
|
281 |
DLocalDrive::DLocalDrive() |
|
282 |
{ |
|
283 |
// iLink.iNext=NULL; |
|
284 |
} |
|
285 |
||
286 |
DLocalDrive::~DLocalDrive() |
|
287 |
{ |
|
288 |
if (iDrive) |
|
289 |
{ |
|
290 |
__KTRACE_OPT(KLOCDRV,Kern::Printf(">DLocalDrive::DoClose D:%d, M:%08x",iDrive->iDriveNumber,iDrive->iMedia)); |
|
291 |
iDrive->Disconnect(this); |
|
292 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("<DLocalDrive::DoClose D:%d, M:%08x",iDrive->iDriveNumber,iDrive->iMedia)); |
|
293 |
} |
|
294 |
DThread* pC=NULL; |
|
295 |
NKern::LockSystem(); |
|
296 |
if (iCleanup.iThread) |
|
297 |
{ |
|
298 |
pC=iCleanup.iThread; |
|
299 |
iCleanup.Remove(); |
|
300 |
iCleanup.iThread=NULL; |
|
301 |
} |
|
302 |
NKern::UnlockSystem(); |
|
303 |
if (pC) // original client may already have terminated |
|
304 |
{ |
|
305 |
if (iNotifyChangeRequest) |
|
306 |
Kern::QueueRequestComplete(pC,iNotifyChangeRequest,KErrCancel); |
|
307 |
pC->Close(NULL); // balances Open() in DoCreate |
|
308 |
} |
|
309 |
if (iNotifyChangeRequest) |
|
310 |
Kern::DestroyClientRequest(iNotifyChangeRequest); |
|
311 |
} |
|
312 |
||
313 |
TInt DLocalDrive::DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer) |
|
314 |
{ |
|
315 |
if(!Kern::CurrentThreadHasCapability(ECapabilityTCB,__PLATSEC_DIAGNOSTIC_STRING("Checked by ELOCD.LDD (Local Media Driver)"))) |
|
316 |
return KErrPermissionDenied; |
|
317 |
if (!Kern::QueryVersionSupported(TVersion(KLocalDriveMajorVersion,KLocalDriveMinorVersion,KLocalDriveBuildVersion),aVer)) |
|
318 |
return KErrNotSupported; |
|
319 |
||
320 |
NKern::ThreadEnterCS(); |
|
321 |
TInt r = Kern::CreateClientDataRequest(iNotifyChangeRequest); |
|
322 |
NKern::ThreadLeaveCS(); |
|
323 |
if (r != KErrNone) |
|
324 |
return r; |
|
325 |
||
326 |
DThread& t=Kern::CurrentThread(); |
|
327 |
NKern::LockSystem(); |
|
328 |
t.AddCleanup(&iCleanup); |
|
329 |
NKern::UnlockSystem(); |
|
330 |
t.Open(); |
|
331 |
iNotifyChangeRequest->SetDestPtr((TBool*) anInfo); |
|
332 |
||
333 |
iDrive=TheDrives[aUnit]; |
|
334 |
if (!iDrive) |
|
335 |
return KErrNotSupported; |
|
336 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DLocalDrive Create - connect to drive %d, M:%08x",iDrive->iDriveNumber,iDrive->iMedia)); |
|
337 |
r=iDrive->Connect(this); |
|
338 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("<DLocalDrive Create D:%d, M:%08x r:%d",iDrive->iDriveNumber,iDrive->iMedia,r)); |
|
339 |
if (r!=KErrNone) |
|
340 |
iDrive=NULL; // didn't connect so don't disconnect |
|
341 |
return r; |
|
342 |
} |
|
343 |
||
344 |
#if defined(_DEBUG) |
|
345 |
void DebugDumpDriveCaps(const TLocDrv* aDrive, const TAny* aCaps) |
|
346 |
{ |
|
347 |
const TLocalDriveCapsV5& c=*(const TLocalDriveCapsV5*)aCaps; |
|
348 |
Kern::Printf("Drive %d Caps:", aDrive->iDriveNumber); |
|
349 |
Kern::Printf("Size: %lx", c.iSize); |
|
350 |
Kern::Printf("Type: %08x", c.iType); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
351 |
Kern::Printf("Bus : %08x", c.iConnectionBusType); |
0 | 352 |
Kern::Printf("DAtt: %08x", c.iDriveAtt); |
353 |
Kern::Printf("MAtt: %08x", c.iMediaAtt); |
|
354 |
Kern::Printf("Base: %08x", c.iBaseAddress); |
|
355 |
Kern::Printf("FSID: %04x", c.iFileSystemId); |
|
356 |
Kern::Printf("PTYP: %04x", c.iPartitionType); |
|
357 |
Kern::Printf("HIDN: %08x", c.iHiddenSectors); |
|
358 |
Kern::Printf("EBSZ: %08x", c.iEraseBlockSize); |
|
359 |
//---------------- V5 ------------------// |
|
360 |
if (c.iSerialNumLength != 0) |
|
361 |
{ |
|
362 |
Kern::Printf("SN: length is %d", c.iSerialNumLength); |
|
363 |
TBuf8<2*KMaxSerialNumLength+20> snBuf; |
|
364 |
snBuf.Append(_L8("SN: content is ")); |
|
365 |
for (TUint i=0; i<c.iSerialNumLength; i++) |
|
366 |
snBuf.AppendNumFixedWidth(c.iSerialNum[i], EHex, 2); |
|
367 |
Kern::Printf((const char*)snBuf.Ptr()); |
|
368 |
} |
|
369 |
else |
|
370 |
Kern::Printf("SN: not supported"); |
|
371 |
} |
|
372 |
#endif |
|
373 |
||
374 |
/* |
|
375 |
* Requests are passed in message as follows: |
|
376 |
* iValue = request ID |
|
377 |
* iArg[0,1]= Position |
|
378 |
* iArg[2,3]= Length |
|
379 |
* iArg[4] = Pointer to remote thread (NULL if client) |
|
380 |
* iArg[5] = Pointer to remote descriptor |
|
381 |
* iArg[6] = Offset into remote descriptor |
|
382 |
* iArg[7] = Flags (whole media) |
|
383 |
* iArg[8] = Pointer to TLocDrv |
|
384 |
*/ |
|
385 |
||
386 |
TInt DLocalDrive::Request(TInt aFunction, TAny* a1, TAny* a2) |
|
387 |
{ |
|
388 |
__TRACE_TIMING(0); |
|
389 |
__KTRACE_OPT(KLOCDRV,Kern::Printf(">DLocalDrive::DoControl D:%d M:%08x F:%d A1:%08x A2:%08x", |
|
390 |
iDrive->iDriveNumber, iDrive->iMedia, aFunction, a1, a2)); |
|
391 |
TInt r=KErrNotSupported; |
|
392 |
TLocDrvRequest& m=TLocDrvRequest::Get(); |
|
393 |
m.Flags()=0; |
|
394 |
m.Drive()=iDrive; |
|
395 |
switch (aFunction) |
|
396 |
{ |
|
397 |
case RLocalDrive::EControlRead: |
|
398 |
{ |
|
399 |
m.Id()=ERead; |
|
400 |
r=m.ProcessMessageData(a1); |
|
401 |
__TRACE_TIMING(1); |
|
402 |
if (r==KErrNone) |
|
403 |
{ |
|
404 |
__TRACE_TIMING(2); |
|
405 |
r=iDrive->Request(m); |
|
406 |
__TRACE_TIMING(3); |
|
407 |
} |
|
408 |
m.CloseRemoteThread(); |
|
409 |
break; |
|
410 |
} |
|
411 |
case RLocalDrive::EControlWrite: |
|
412 |
{ |
|
413 |
m.Id()=EWrite; |
|
414 |
r=m.ProcessMessageData(a1); |
|
415 |
if (r==KErrNone) |
|
416 |
r=iDrive->Request(m); |
|
417 |
m.CloseRemoteThread(); |
|
418 |
break; |
|
419 |
} |
|
420 |
case RLocalDrive::EControlCaps: |
|
421 |
{ |
|
422 |
TBuf8<KMaxLocalDriveCapsLength> capsBuf; |
|
423 |
capsBuf.SetMax(); |
|
424 |
capsBuf.FillZ(); |
|
425 |
m.Id()=ECaps; |
|
426 |
m.RemoteDes()=(TAny*)capsBuf.Ptr(); // overload this |
|
427 |
m.Length()=KMaxLocalDriveCapsLength; // for pinning |
|
428 |
r=iDrive->Request(m); |
|
429 |
||
430 |
if(r == KErrNone && iDrive->iMedia != NULL && iDrive->iMedia->iDriver != NULL) |
|
431 |
{ |
|
432 |
// Fill in default media size if not specified by the driver |
|
433 |
// |
|
434 |
// - This uses the members of TLocalDriveCapsV4 which was primarily used |
|
435 |
// to report NAND flash characteristics, but are general enough to be |
|
436 |
// used to report the size of any type of media without adding yet |
|
437 |
// another extension to TLocalDriveCapsVx. |
|
438 |
// |
|
439 |
||
440 |
TLocalDriveCapsV4& caps = *(TLocalDriveCapsV4*)capsBuf.Ptr(); |
|
441 |
||
442 |
if(caps.iSectorSizeInBytes == 0) |
|
443 |
{ |
|
444 |
// Fill in a default value for the disk sector size |
|
445 |
caps.iSectorSizeInBytes = 512; |
|
446 |
||
447 |
// Zero the number of sectors, as a sector count makes no sense without a sector size |
|
448 |
// - Fault in debug mode if a sector count is provided to ensure that media driver creators |
|
449 |
// set this value,but in release mode continue gracefully be recalculating the sector count. |
|
450 |
__ASSERT_DEBUG(caps.iNumberOfSectors == 0, LOCM_FAULT()); |
|
451 |
caps.iNumberOfSectors = 0; |
|
452 |
caps.iNumPagesPerBlock = 1; // ...to ensure compatiility with NAND semantics |
|
453 |
} |
|
454 |
||
455 |
if(caps.iNumberOfSectors == 0) |
|
456 |
{ |
|
457 |
const Int64 totalSizeInSectors = iDrive->iMedia->iDriver->TotalSizeInBytes() / caps.iSectorSizeInBytes; |
|
458 |
__ASSERT_DEBUG(I64HIGH(totalSizeInSectors) == 0, LOCM_FAULT()); |
|
459 |
||
460 |
if(I64HIGH(totalSizeInSectors) == 0) |
|
461 |
{ |
|
462 |
caps.iNumberOfSectors = I64LOW(totalSizeInSectors); |
|
463 |
} |
|
464 |
} |
|
465 |
} |
|
466 |
||
467 |
#if defined(_DEBUG) |
|
468 |
__KTRACE_OPT(KLOCDRV,DebugDumpDriveCaps(iDrive,capsBuf.Ptr())); |
|
469 |
#endif |
|
470 |
Kern::InfoCopy(*(TDes8*)a1, capsBuf); |
|
471 |
break; |
|
472 |
} |
|
473 |
case RLocalDrive::EControlFormat: |
|
474 |
{ |
|
475 |
m.Id()=EFormat; |
|
476 |
r=m.ProcessMessageData(a1); |
|
477 |
if (r==KErrNone) |
|
478 |
r=iDrive->Request(m); |
|
479 |
break; |
|
480 |
} |
|
481 |
case RLocalDrive::EControlEnlarge: |
|
482 |
if ((TInt)a1<0) |
|
483 |
{ |
|
484 |
r=KErrArgument; |
|
485 |
break; |
|
486 |
} |
|
487 |
m.Length()=(TInt)a1; |
|
488 |
m.Id()=EEnlarge; |
|
489 |
r=iDrive->Request(m); |
|
490 |
break; |
|
491 |
case RLocalDrive::EControlReduce: |
|
492 |
{ |
|
493 |
if ((TInt)a1<0 || (TInt)a2<0) |
|
494 |
{ |
|
495 |
r=KErrArgument; |
|
496 |
break; |
|
497 |
} |
|
498 |
m.Pos()=(TInt)a1; |
|
499 |
m.Length()=(TInt)a2; |
|
500 |
m.Id()=EReduce; |
|
501 |
r=iDrive->Request(m); |
|
502 |
break; |
|
503 |
} |
|
504 |
case RLocalDrive::EControlForceMediaChange: |
|
505 |
m.Pos()=(TInt)a1; |
|
506 |
m.Id()=EForceMediaChange; |
|
507 |
r = iDrive->Request(m); |
|
508 |
break; |
|
509 |
case RLocalDrive::EControlMediaDevice: |
|
510 |
r=iDrive->iPrimaryMedia->iDevice; |
|
511 |
break; |
|
512 |
case RLocalDrive::EControlIsRemovable: |
|
513 |
{ |
|
514 |
TInt sockNum; |
|
515 |
r=iDrive->iPrimaryMedia->IsRemovableDevice(sockNum); |
|
516 |
if (r) |
|
517 |
kumemput32(a1,&sockNum,sizeof(TInt)); |
|
518 |
break; |
|
519 |
} |
|
520 |
case RLocalDrive::EControlControlIO: |
|
521 |
{ |
|
522 |
TLocalDriveControlIOData d; |
|
523 |
kumemget32(&d,a1,sizeof(d)); |
|
524 |
||
525 |
m.Id() = EControlIO; |
|
526 |
m.iArg[0] = (TAny*) d.iCommand; |
|
527 |
m.iArg[1] = d.iParam1; |
|
528 |
m.iArg[2] = d.iParam2; |
|
529 |
||
530 |
// if d.iHandle is == KLocalMessageHandle (-1), |
|
531 |
// d.aParam1 and d.aParam2 are TAny* pointers |
|
532 |
// |
|
533 |
// if d.iHandle is == 0, |
|
534 |
// d.aParam1 and d.aParam2 are TInts |
|
535 |
// |
|
536 |
// if d.iHandle is > 0, |
|
537 |
// d.aParam1 is a data pointer (TUint8*) |
|
538 |
// d.aParam2 is an optional extra paramater (TInt) |
|
539 |
// d.iHandle is a data length (TInt) |
|
540 |
m.iArg[3] = (TAny*) d.iHandle; |
|
541 |
||
542 |
//We're highjacking fields representing |
|
543 |
//length and position in a normal message, so |
|
544 |
//let's not have the dispatcher function attempt |
|
545 |
//to adjust for partition size. |
|
546 |
m.Flags() |= TLocDrvRequest::EAdjusted; |
|
547 |
||
548 |
r=iDrive->Request(m); |
|
549 |
break; |
|
550 |
} |
|
551 |
case RLocalDrive::EControlSetMountInfo: |
|
552 |
{ |
|
553 |
m.Id()=ERead; |
|
554 |
r=m.ProcessMessageData(a1); |
|
555 |
DPrimaryMediaBase* pM=iDrive->iPrimaryMedia; |
|
556 |
if(!pM || r!=KErrNone) |
|
557 |
break; |
|
558 |
||
559 |
if (pM->iMountInfo.iThread) |
|
560 |
{ |
|
561 |
NKern::ThreadEnterCS(); |
|
562 |
//Close original thread |
|
563 |
Kern::SafeClose((DObject*&) pM->iMountInfo.iThread,NULL); |
|
564 |
if (m.RemoteDes()!=NULL) |
|
565 |
{ |
|
566 |
//Set new mount info and leave setting thread open |
|
567 |
#ifdef __DEMAND_PAGING__ |
|
568 |
// lock the mount info if this is a data paging media - and keep it locked |
|
569 |
if ((DataPagingDfcQ(pM)) && ((r = LockMountInfo(*pM, m)) != KErrNone)) |
|
570 |
break; |
|
571 |
#endif |
|
572 |
pM->iMountInfo.iInfo=(TDesC8*)m.RemoteDes(); |
|
573 |
pM->iMountInfo.iThread=m.RemoteThread(); |
|
574 |
} |
|
575 |
else |
|
576 |
{ |
|
577 |
//Clear existing mount info and close setting thread |
|
578 |
||
579 |
#ifdef __DEMAND_PAGING__ |
|
580 |
// unlock the mount info if this is a data paging media |
|
581 |
UnlockMountInfo(*pM); |
|
582 |
#endif |
|
583 |
||
584 |
pM->iMountInfo.iInfo=NULL; |
|
585 |
pM->iMountInfo.iThread=NULL; |
|
586 |
m.CloseRemoteThread(); |
|
587 |
} |
|
588 |
NKern::ThreadLeaveCS(); |
|
589 |
r=KErrNone; |
|
590 |
} |
|
591 |
else |
|
592 |
{ |
|
593 |
//Setting mount info for the first time |
|
594 |
if (m.RemoteDes()==NULL) |
|
595 |
{ |
|
596 |
// if no mount info, close setting thread opened in ProcessMessageData() |
|
597 |
m.CloseRemoteThread(); |
|
598 |
break; |
|
599 |
} |
|
600 |
||
601 |
NKern::ThreadEnterCS(); |
|
602 |
#ifdef __DEMAND_PAGING__ |
|
603 |
// lock the mount info if this is a data paging media - and keep it locked |
|
604 |
if ((DataPagingDfcQ(pM)) && ((r = LockMountInfo(*pM, m)) != KErrNone)) |
|
605 |
break; |
|
606 |
#endif |
|
607 |
||
608 |
pM->iMountInfo.iInfo=(TDesC8*)m.RemoteDes(); |
|
609 |
pM->iMountInfo.iThread=m.RemoteThread(); |
|
610 |
NKern::ThreadLeaveCS(); |
|
611 |
r=KErrNone; |
|
612 |
} |
|
613 |
break; |
|
614 |
} |
|
615 |
case RLocalDrive::EControlPasswordLock: |
|
616 |
{ |
|
617 |
m.Id()=EPasswordLock; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
618 |
m.RemoteDes() = a1; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
619 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
620 |
TMediaPassword oldPasswd; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
621 |
TMediaPassword newPasswd; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
622 |
TLocalDrivePasswordData pswData; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
623 |
r = ReadPasswordData(m, pswData, oldPasswd, newPasswd); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
624 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
625 |
if (r == KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
626 |
r = iDrive->Request(m); |
0 | 627 |
break; |
628 |
} |
|
629 |
case RLocalDrive::EControlPasswordUnlock: |
|
630 |
{ |
|
631 |
m.Id()=EPasswordUnlock; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
632 |
m.RemoteDes() = a1; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
633 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
634 |
TMediaPassword oldPasswd; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
635 |
TMediaPassword newPasswd; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
636 |
TLocalDrivePasswordData pswData; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
637 |
r = ReadPasswordData(m, pswData, oldPasswd, newPasswd); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
638 |
|
0 | 639 |
if(r == KErrNone) |
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
640 |
r=iDrive->Request(m); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
641 |
if (r == KErrNone) |
0 | 642 |
iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0; |
643 |
break; |
|
644 |
} |
|
645 |
case RLocalDrive::EControlPasswordClear: |
|
646 |
{ |
|
647 |
m.Id()=EPasswordClear; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
648 |
m.RemoteDes() = a1; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
649 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
650 |
TMediaPassword oldPasswd; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
651 |
TMediaPassword newPasswd; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
652 |
TLocalDrivePasswordData pswData; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
653 |
r = ReadPasswordData(m, pswData, oldPasswd, newPasswd); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
654 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
655 |
if (r == KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
656 |
r = iDrive->Request(m); |
0 | 657 |
break; |
658 |
} |
|
659 |
case RLocalDrive::EControlPasswordErase: |
|
660 |
{ |
|
661 |
m.Id()=EPasswordErase; |
|
662 |
r=iDrive->Request(m); |
|
663 |
if(r == KErrNone) |
|
664 |
iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0; |
|
665 |
break; |
|
666 |
} |
|
667 |
case RLocalDrive::EControlNotifyChange: |
|
668 |
if (iCleanup.iThread != &Kern::CurrentThread()) |
|
669 |
Kern::PanicCurrentThread(KLitLocMedia,KErrAccessDenied); |
|
670 |
r=KErrNone; |
|
671 |
if (!iNotifyChangeRequest->StatusPtr()) |
|
672 |
r = iNotifyChangeRequest->SetStatus((TRequestStatus*) a1); |
|
673 |
break; |
|
674 |
case RLocalDrive::EControlNotifyChangeCancel: |
|
675 |
if (iCleanup.iThread != &Kern::CurrentThread()) |
|
676 |
Kern::PanicCurrentThread(KLitLocMedia,KErrAccessDenied); |
|
677 |
Kern::QueueRequestComplete(iCleanup.iThread,iNotifyChangeRequest,KErrCancel); |
|
678 |
break; |
|
679 |
case RLocalDrive::EControlReadPasswordStore: |
|
680 |
{ |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
681 |
TUint8 passData[TPasswordStore::EMaxPasswordLength]; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
682 |
m.RemoteDes() = (TAny*) passData; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
683 |
m.Length() = sizeof(passData); |
0 | 684 |
m.Id()=EReadPasswordStore; |
685 |
r=iDrive->Request(m); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
686 |
if (r==KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
687 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
688 |
TPtr8 pData(passData, (TInt) m.Length(), TPasswordStore::EMaxPasswordLength); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
689 |
m.RemoteDes()=(TDes8*)a1; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
690 |
r = m.WriteRemote(&pData,0); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
691 |
} |
0 | 692 |
break; |
693 |
} |
|
694 |
case RLocalDrive::EControlWritePasswordStore: |
|
695 |
{ |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
696 |
TUint8 passData[TPasswordStore::EMaxPasswordLength]; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
697 |
TPtr8 pData(passData, TPasswordStore::EMaxPasswordLength); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
698 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
699 |
DThread* pT=m.RemoteThread(); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
700 |
if (!pT) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
701 |
pT=m.Client(); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
702 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
703 |
m.RemoteDes() = (TDes8*)a1; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
704 |
r = Kern::ThreadGetDesLength(pT, m.RemoteDes()); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
705 |
if ( r > pData.MaxLength() ) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
706 |
r = KErrOverflow; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
707 |
if ( r < KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
708 |
break; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
709 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
710 |
r = m.ReadRemote(&pData,0); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
711 |
if (r != KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
712 |
break; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
713 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
714 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
715 |
m.RemoteDes() = (TAny*) pData.Ptr(); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
716 |
m.Length() = pData.Length(); |
0 | 717 |
m.Id()=EWritePasswordStore; |
718 |
r=iDrive->Request(m); |
|
719 |
if(r == KErrNone) |
|
720 |
iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0; |
|
721 |
break; |
|
722 |
} |
|
723 |
case RLocalDrive::EControlPasswordStoreLengthInBytes: |
|
724 |
{ |
|
725 |
m.Id()=EPasswordStoreLengthInBytes; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
726 |
TInt length; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
727 |
m.RemoteDes() = (TAny*) &length; |
0 | 728 |
r=iDrive->Request(m); |
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
729 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
730 |
if (r == KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
731 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
732 |
m.RemoteDes()=a1; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
733 |
r = m.WriteRemoteRaw(&length,sizeof(TInt)); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
734 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
735 |
|
0 | 736 |
break; |
737 |
} |
|
738 |
case RLocalDrive::EControlGetLastErrorInfo: |
|
739 |
{ |
|
740 |
m.Id()=EGetLastErrorInfo; |
|
741 |
m.iArg[0]=this; |
|
742 |
TErrorInfoBuf errorInfoBuf; |
|
743 |
errorInfoBuf.SetMax(); |
|
744 |
errorInfoBuf.FillZ(); |
|
745 |
m.RemoteDes()=(TAny*) errorInfoBuf.Ptr(); // overload this |
|
746 |
m.Length() = errorInfoBuf.MaxLength(); |
|
747 |
r=iDrive->Request(m); |
|
748 |
Kern::InfoCopy(*(TDes8*)a1, errorInfoBuf); |
|
749 |
break; |
|
750 |
} |
|
751 |
case RLocalDrive::EControlDeleteNotify: |
|
752 |
{ |
|
753 |
m.Id()=EDeleteNotify; |
|
754 |
r=m.ProcessMessageData(a1); |
|
755 |
if (r==KErrNone) |
|
756 |
r=iDrive->Request(m); |
|
757 |
break; |
|
758 |
} |
|
759 |
||
760 |
case RLocalDrive::EControlQueryDevice: |
|
761 |
{ |
|
762 |
TBuf8<KMaxQueryDeviceLength> queryBuf; |
|
763 |
queryBuf.SetMax(); |
|
764 |
queryBuf.FillZ(); |
|
765 |
||
766 |
m.Id() = EQueryDevice; |
|
767 |
m.iArg[0] = a1; // RLocalDrive::TQueryDevice |
|
768 |
m.RemoteDes() = (TAny*)queryBuf.Ptr(); // overload this |
|
769 |
m.Length() = KMaxLocalDriveCapsLength; // for pinning |
|
770 |
r=iDrive->Request(m); |
|
771 |
||
772 |
Kern::InfoCopy(*(TDes8*)a2, queryBuf); |
|
773 |
break; |
|
774 |
} |
|
775 |
||
776 |
} |
|
777 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("<DLocalDrive::DoControl D:%d M:%08x ret %d",iDrive->iDriveNumber, iDrive->iMedia, r)); |
|
778 |
__TRACE_TIMING(4); |
|
779 |
return r; |
|
780 |
} |
|
781 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
782 |
TInt DLocalDrive::ReadPasswordData(TLocDrvRequest& aReq, TLocalDrivePasswordData& aPswData, TMediaPassword& aOldPasswd, TMediaPassword& aNewPasswd) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
783 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
784 |
TLocalDrivePasswordData clientData; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
785 |
TInt r = aReq.ReadRemoteRaw(&clientData, sizeof(TLocalDrivePasswordData)); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
786 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
787 |
DThread* pT = aReq.RemoteThread(); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
788 |
if (!pT) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
789 |
pT = aReq.Client(); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
790 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
791 |
if (r == KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
792 |
r = Kern::ThreadDesRead(pT, clientData.iOldPasswd, aOldPasswd, 0 ,KChunkShiftBy0); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
793 |
if (r == KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
794 |
r = Kern::ThreadDesRead(pT, clientData.iNewPasswd, aNewPasswd, 0 ,KChunkShiftBy0); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
795 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
796 |
aPswData.iStorePasswd = clientData.iStorePasswd; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
797 |
aPswData.iOldPasswd = &aOldPasswd; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
798 |
aPswData.iNewPasswd = &aNewPasswd; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
799 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
800 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
801 |
aReq.RemoteDes() = (TAny*) &aPswData; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
802 |
aReq.Flags()|= TLocDrvRequest::EKernelBuffer; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
803 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
804 |
return r; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
805 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
806 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
807 |
|
0 | 808 |
#ifdef __DEMAND_PAGING__ |
809 |
TInt DLocalDrive::LockMountInfo(DPrimaryMediaBase& aPrimaryMedia, TLocDrvRequest& aReq) |
|
810 |
{ |
|
811 |
DMediaPagingDevice* pagingDevice = aPrimaryMedia.iBody->iPagingDevice; |
|
812 |
if (pagingDevice == NULL) |
|
813 |
return KErrNone; |
|
814 |
||
815 |
__ASSERT_DEBUG(pagingDevice->iMountInfoDataLock == NULL, LOCM_FAULT()); |
|
816 |
__ASSERT_DEBUG(pagingDevice->iMountInfoDescHdrLock == NULL, LOCM_FAULT()); |
|
817 |
__ASSERT_DEBUG(pagingDevice->iMountInfoDescLenLock == NULL, LOCM_FAULT()); |
|
818 |
||
819 |
DThread* pT = aReq.RemoteThread(); |
|
820 |
if (!pT) |
|
821 |
pT = &Kern::CurrentThread(); // e.g. when using TBusLocalDrive directly |
|
822 |
||
823 |
TInt length = 0; |
|
824 |
TInt maxLength = 0; |
|
825 |
TUint8* desAddress = NULL; |
|
826 |
TInt r = Kern::ThreadGetDesInfo(pT,aReq.RemoteDes(),length,maxLength,desAddress,EFalse); // get descriptor length, maxlength and desAddress |
|
827 |
if (r != KErrNone) |
|
828 |
return r; |
|
829 |
if (length == 0) |
|
830 |
return KErrNone; |
|
831 |
||
832 |
||
833 |
static const TUint8 LengthLookup[16]={4,8,12,8,12,0,0,0,0,0,0,0,0,0,0,0}; |
|
834 |
TUint32 desHdr; |
|
835 |
r = Kern::ThreadRawRead(pT, aReq.RemoteDes(), &desHdr, sizeof(desHdr)); |
|
836 |
if(r!=KErrNone) |
|
837 |
return r; |
|
838 |
TInt desType = desHdr >>KShiftDesType8; |
|
839 |
TInt desHdrLen = LengthLookup[desType]; |
|
840 |
if(!desHdrLen) |
|
841 |
return KErrBadDescriptor; |
|
842 |
||
843 |
||
844 |
pagingDevice->iMountInfoDataLock = ThePinObjectAllocator->AcquirePinObject(); |
|
845 |
pagingDevice->iMountInfoDescHdrLock = ThePinObjectAllocator->AcquirePinObject(); |
|
846 |
pagingDevice->iMountInfoDescLenLock = ThePinObjectAllocator->AcquirePinObject(); |
|
847 |
||
848 |
if (pagingDevice->iMountInfoDataLock == NULL || |
|
849 |
pagingDevice->iMountInfoDescHdrLock == NULL || |
|
850 |
pagingDevice->iMountInfoDescLenLock == NULL) |
|
851 |
{ |
|
852 |
UnlockMountInfo(aPrimaryMedia); // tidy up |
|
853 |
return KErrNoMemory; |
|
854 |
} |
|
855 |
||
856 |
||
857 |
// First pin the descriptor header |
|
858 |
DPinObjectAllocator::SVirtualPinContainer* lock; |
|
859 |
lock = (DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDescHdrLock; |
|
860 |
r = Kern::PinVirtualMemory(lock->iObject, (TLinAddr) (TUint8*) aReq.RemoteDes(), desHdrLen, pT); |
|
861 |
if (r != KErrNone) |
|
862 |
{ |
|
863 |
UnlockMountInfo(aPrimaryMedia); // tidy up |
|
864 |
return KErrNoMemory; |
|
865 |
} |
|
866 |
||
867 |
||
868 |
||
869 |
// For EBufCPtr-type descriptors, need to pin the extra length before the buffer (!) |
|
870 |
lock = (DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDescLenLock; |
|
871 |
if (desType == EBufCPtr) |
|
872 |
{ |
|
873 |
TLinAddr extraLenAddr = TLinAddr(desAddress) - aReq.RemoteDesOffset() - sizeof(TUint32); |
|
874 |
r = Kern::PinVirtualMemory(lock->iObject, (TLinAddr) (TUint8*) extraLenAddr, sizeof(TUint32), pT); |
|
875 |
if (r != KErrNone) |
|
876 |
{ |
|
877 |
UnlockMountInfo(aPrimaryMedia); // tidy up |
|
878 |
return KErrNoMemory; |
|
879 |
} |
|
880 |
} |
|
881 |
||
882 |
||
883 |
// Now pin the descriptor contents |
|
884 |
lock = (DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDataLock; |
|
885 |
r = Kern::PinVirtualMemory(lock->iObject, (TLinAddr) desAddress, length, pT); |
|
886 |
if (r != KErrNone) |
|
887 |
{ |
|
888 |
UnlockMountInfo(aPrimaryMedia); // tidy up |
|
889 |
return KErrNoMemory; |
|
890 |
} |
|
891 |
||
892 |
||
893 |
return KErrNone; |
|
894 |
} |
|
895 |
||
896 |
||
897 |
void DLocalDrive::UnlockMountInfo(DPrimaryMediaBase& aPrimaryMedia) |
|
898 |
{ |
|
899 |
DMediaPagingDevice* pagingDevice = aPrimaryMedia.iBody->iPagingDevice; |
|
900 |
if (pagingDevice == NULL || pagingDevice->iMountInfoDataLock == NULL) |
|
901 |
return; |
|
902 |
||
903 |
||
904 |
if (pagingDevice->iMountInfoDataLock) |
|
905 |
{ |
|
906 |
Kern::UnpinVirtualMemory(((DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDataLock)->iObject); |
|
907 |
ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDataLock); |
|
908 |
pagingDevice->iMountInfoDataLock = NULL; |
|
909 |
} |
|
910 |
||
911 |
if (pagingDevice->iMountInfoDescHdrLock) |
|
912 |
{ |
|
913 |
Kern::UnpinVirtualMemory(((DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDescHdrLock)->iObject); |
|
914 |
ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDescHdrLock); |
|
915 |
pagingDevice->iMountInfoDescHdrLock = NULL; |
|
916 |
} |
|
917 |
||
918 |
if (pagingDevice->iMountInfoDescLenLock) |
|
919 |
{ |
|
920 |
Kern::UnpinVirtualMemory(((DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDescLenLock)->iObject); |
|
921 |
ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDescLenLock); |
|
922 |
pagingDevice->iMountInfoDescLenLock = NULL; |
|
923 |
} |
|
924 |
||
925 |
} |
|
926 |
#endif // __DEMAND_PAGING__ |
|
927 |
||
928 |
void DLocalDrive::NotifyChange(DPrimaryMediaBase& aPrimaryMedia, TBool aMediaChange) |
|
929 |
{ |
|
930 |
#ifndef __DEMAND_PAGING__ |
|
931 |
aPrimaryMedia; |
|
932 |
#endif |
|
933 |
||
934 |
// Complete any notification request on media change or power down |
|
935 |
if (aMediaChange) |
|
936 |
{ |
|
937 |
DThread* pC=NULL; |
|
938 |
NKern::LockSystem(); |
|
939 |
if (iCleanup.iThread) |
|
940 |
{ |
|
941 |
pC=iCleanup.iThread; |
|
942 |
pC->Open(); |
|
943 |
} |
|
944 |
NKern::UnlockSystem(); |
|
945 |
if (pC) |
|
946 |
{ |
|
947 |
TBool b = ETrue; |
|
948 |
// if change not yet queued, queue it now |
|
949 |
if (iNotifyChangeRequest->IsReady()) |
|
950 |
{ |
|
951 |
*((TBool*) iNotifyChangeRequest->Buffer()) = b; |
|
952 |
Kern::QueueRequestComplete(pC,iNotifyChangeRequest,KErrNone); |
|
953 |
} |
|
954 |
// If change has not even been requested by the client, maintain the pre-wdp behaviour |
|
955 |
// and write data immediately back to client (possibly taking a page fault) |
|
956 |
// N.B. Must NOT do this on data paging media |
|
957 |
#ifdef __DEMAND_PAGING__ |
|
958 |
else if (!DataPagingDfcQ(&aPrimaryMedia)) |
|
959 |
#else |
|
960 |
else |
|
961 |
#endif |
|
962 |
{ |
|
963 |
Kern::ThreadRawWrite(pC, iNotifyChangeRequest->DestPtr(), &b, sizeof(b), NULL); |
|
964 |
} |
|
965 |
pC->AsyncClose(); |
|
966 |
} |
|
967 |
} |
|
968 |
} |
|
969 |
||
970 |
TLocalDriveCleanup::TLocalDriveCleanup() |
|
971 |
{ |
|
972 |
} |
|
973 |
||
974 |
// This will be called when the original client thread exits |
|
975 |
// It is called in the context of the exiting thread with the system locked. |
|
976 |
void TLocalDriveCleanup::Cleanup() |
|
977 |
{ |
|
978 |
DLocalDrive& d=LocalDrive(); |
|
979 |
d.iNotifyChangeRequest=NULL; |
|
980 |
DThread* pC=iThread; |
|
981 |
Remove(); |
|
982 |
iThread=NULL; |
|
983 |
NKern::UnlockSystem(); |
|
984 |
pC->Close(NULL); // balances Open() in DoCreate |
|
985 |
NKern::LockSystem(); |
|
986 |
} |
|
987 |
||
988 |
/******************************************** |
|
989 |
* Local drive request class |
|
990 |
********************************************/ |
|
991 |
||
992 |
/** |
|
993 |
Reads data from the descriptor specified in the request, from the requesting |
|
994 |
thread's process. |
|
995 |
||
996 |
This is used by the media driver to read data from a descriptor in the |
|
997 |
requesting thread. The remote data is copied into the specified descriptor, |
|
998 |
starting at the specified offset within that descriptor's data area. |
|
999 |
||
1000 |
@param aDes The target descriptor into which data from the remote thread |
|
1001 |
is to be put. |
|
1002 |
@param anOffset The offset within the target descriptor data area, where data |
|
1003 |
from the remote thread is to be put. Note that this parameter |
|
1004 |
may be useful when write operations to the media must be broken |
|
1005 |
up into smaller chunks than the length requested. |
|
1006 |
||
1007 |
@return KErrNone,if successful, otherwise one of the other |
|
1008 |
system-wide error codes. |
|
1009 |
||
1010 |
@see Kern::ThreadDesRead() |
|
1011 |
*/ |
|
1012 |
EXPORT_C TInt TLocDrvRequest::ReadRemote(TDes8* aDes, TInt anOffset) |
|
1013 |
{ |
|
1014 |
DThread* pT=RemoteThread(); |
|
1015 |
if (!pT) |
|
1016 |
pT=Client(); |
|
1017 |
||
1018 |
#ifdef __DEMAND_PAGING__ // only if driver has its own thread, we don't support paging in MD which run in the context of their clients |
|
1019 |
if (Flags() & ETClientBuffer) |
|
1020 |
return Kern::ThreadBufRead(pT, (TClientBuffer*) RemoteDes(),*aDes,anOffset+RemoteDesOffset(),KChunkShiftBy0); |
|
1021 |
||
1022 |
__ASSERT_ALWAYS((Flags() & ETClientBuffer) == 0, LOCM_FAULT()); |
|
1023 |
#endif |
|
1024 |
||
1025 |
return Kern::ThreadDesRead(pT,RemoteDes(),*aDes,anOffset+RemoteDesOffset(),KChunkShiftBy0); |
|
1026 |
} |
|
1027 |
||
1028 |
||
1029 |
||
1030 |
||
1031 |
/** |
|
1032 |
Reads data from an arbitrary descriptor in the requesting thread's process. |
|
1033 |
||
1034 |
This is used by the media driver to read data from a descriptor in the |
|
1035 |
requesting thread. |
|
1036 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1037 |
NB This is NOT supported on datapaging media as there is no guarantee |
0 | 1038 |
that the remote descriptor won't be paged out. If this function is called and |
1039 |
data-paging is enabled the kernel will fault in debug mode and return |
|
1040 |
KErrNotSupported in release mode. |
|
1041 |
||
1042 |
@param aSrc A pointer to the source descriptor in the requesting thread's |
|
1043 |
address space. |
|
1044 |
@param aDes The target descriptor into which data from the remote thread |
|
1045 |
is to be put. |
|
1046 |
||
1047 |
@return KErrNone,if successful, |
|
1048 |
KErrNotSupported if data-paging is enabled |
|
1049 |
otherwise one of the other system-wide error codes. |
|
1050 |
||
1051 |
@see Kern::ThreadDesRead() |
|
1052 |
*/ |
|
1053 |
EXPORT_C TInt TLocDrvRequest::ReadRemote(const TAny* aSrc, TDes8* aDes) |
|
1054 |
{ |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1055 |
if (Flags() & TLocDrvRequest::EKernelBuffer) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1056 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1057 |
aDes->Copy(* (TDesC8*) aSrc); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1058 |
return KErrNone; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1059 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1060 |
|
0 | 1061 |
DThread* pT=RemoteThread(); |
1062 |
if (!pT) |
|
1063 |
pT=Client(); |
|
1064 |
||
1065 |
#ifdef __DEMAND_PAGING__ |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1066 |
__ASSERT_DEBUG(!DataPagingDfcQ(Drive()->iPrimaryMedia), LOCM_FAULT()); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1067 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1068 |
if (DataPagingDfcQ(Drive()->iPrimaryMedia)) |
0 | 1069 |
return KErrNotSupported; |
1070 |
#endif |
|
1071 |
||
1072 |
return Kern::ThreadDesRead(pT,aSrc,*aDes,0,KChunkShiftBy0); |
|
1073 |
} |
|
1074 |
||
1075 |
||
1076 |
||
1077 |
||
1078 |
/** |
|
1079 |
Reads raw data from the requesting thread's process. |
|
1080 |
||
1081 |
This is used by the media driver to read raw data from a location in requesting |
|
1082 |
thread's address space. The remote data is copied into the specified |
|
1083 |
buffer. |
|
1084 |
||
1085 |
@param aDest A pointer to the buffer where the data is to be written. |
|
1086 |
@param aSize The number of bytes to read. |
|
1087 |
||
1088 |
@return KErrNone,if successful, otherwise one of the other |
|
1089 |
system-wide error codes. |
|
1090 |
||
1091 |
@see Kern::ThreadRawRead() |
|
1092 |
*/ |
|
1093 |
EXPORT_C TInt TLocDrvRequest::ReadRemoteRaw(TAny* aDest, TInt aSize) |
|
1094 |
{ |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1095 |
if (Flags() & TLocDrvRequest::EKernelBuffer) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1096 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1097 |
(void)memcpy(aDest, (TAny*) RemoteDes(), aSize); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1098 |
return KErrNone; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1099 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1100 |
|
0 | 1101 |
DThread* pT=RemoteThread(); |
1102 |
if (!pT) |
|
1103 |
pT=Client(); |
|
1104 |
||
1105 |
#ifdef __DEMAND_PAGING__ |
|
1106 |
__ASSERT_ALWAYS((Flags() & ETClientBuffer) == 0, LOCM_FAULT()); |
|
1107 |
#endif |
|
1108 |
||
1109 |
return Kern::ThreadRawRead(pT,RemoteDes(),aDest,aSize); |
|
1110 |
} |
|
1111 |
||
1112 |
||
1113 |
/** |
|
1114 |
Writes data to a descriptor in the requesting thread's process. |
|
1115 |
||
1116 |
This is used by the media driver to write data to a descriptor in the requesting |
|
1117 |
thread. Data is copied from the specified descriptor, starting at the specified |
|
1118 |
offset within that descriptor's data area. |
|
1119 |
||
1120 |
@param aDes The source descriptor from which data is to be written to |
|
1121 |
the remote thread. |
|
1122 |
||
1123 |
@param anOffset The offset within the source descriptor data area, from where data |
|
1124 |
is to be written to the remote thread. Note that this parameter |
|
1125 |
may be useful when read operations from the media must be broken |
|
1126 |
up into smaller chunks than the length requested. |
|
1127 |
||
1128 |
@return KErrNone,if successful, otherwise one of the other |
|
1129 |
system-wide error codes. |
|
1130 |
||
1131 |
@see Kern::ThreadDesWrite() |
|
1132 |
*/ |
|
1133 |
EXPORT_C TInt TLocDrvRequest::WriteRemote(const TDesC8* aDes, TInt anOffset) |
|
1134 |
{ |
|
1135 |
DThread* pC=Client(); |
|
1136 |
DThread* pT=RemoteThread(); |
|
1137 |
if (!pT) |
|
1138 |
pT=pC; |
|
1139 |
||
1140 |
#ifdef __DEMAND_PAGING__ |
|
1141 |
if (Flags() & ETClientBuffer) |
|
1142 |
return Kern::ThreadBufWrite(pT, (TClientBuffer*) RemoteDes(),*aDes,anOffset+RemoteDesOffset(),KChunkShiftBy0,pC); |
|
1143 |
#endif |
|
1144 |
||
1145 |
return Kern::ThreadDesWrite(pT,RemoteDes(),*aDes,anOffset+RemoteDesOffset(),KChunkShiftBy0,pC); |
|
1146 |
} |
|
1147 |
||
1148 |
||
1149 |
/** |
|
1150 |
Writes raw data to the requesting thread's process. |
|
1151 |
||
1152 |
This is used by the media driver to write raw data to a location in the |
|
1153 |
requesting thread's address space. |
|
1154 |
||
1155 |
@param aSrc The source addres from which data is to be written to |
|
1156 |
the remote thread. |
|
1157 |
||
1158 |
@param aSize The number of bytes to write. |
|
1159 |
||
1160 |
@return KErrNone,if successful, otherwise one of the other |
|
1161 |
system-wide error codes. |
|
1162 |
||
1163 |
@see Kern::ThreadRawWrite() |
|
1164 |
*/ |
|
1165 |
EXPORT_C TInt TLocDrvRequest::WriteRemoteRaw(const TAny* aSrc, TInt aSize) |
|
1166 |
{ |
|
1167 |
DThread* pC=Client(); |
|
1168 |
DThread* pT=RemoteThread(); |
|
1169 |
if (!pT) |
|
1170 |
pT=pC; |
|
1171 |
||
1172 |
#ifdef __DEMAND_PAGING__ |
|
1173 |
__ASSERT_ALWAYS((Flags() & ETClientBuffer) == 0, LOCM_FAULT()); |
|
1174 |
#endif |
|
1175 |
||
1176 |
return Kern::ThreadRawWrite(pT,RemoteDes(),aSrc,aSize,pC); |
|
1177 |
} |
|
1178 |
||
1179 |
||
1180 |
TInt TLocDrvRequest::ProcessMessageData(TAny* aPtr) |
|
1181 |
// |
|
1182 |
// Get read/write parameters from client and open remote thread |
|
1183 |
// |
|
1184 |
{ |
|
1185 |
RemoteThread()=NULL; |
|
1186 |
DThread& t=Kern::CurrentThread(); |
|
1187 |
TLocalDriveMessageData d; |
|
1188 |
kumemget32(&d,aPtr,sizeof(d)); |
|
1189 |
if (d.iHandle!=KLocalMessageHandle && Id()!=DLocalDrive::EFormat) |
|
1190 |
{ |
|
1191 |
NKern::LockSystem(); |
|
1192 |
DThread* pT = RMessageK::MessageK(d.iHandle)->iClient; |
|
1193 |
if (!pT || pT->Open()!=KErrNone) |
|
1194 |
{ |
|
1195 |
NKern::UnlockSystem(); |
|
1196 |
return KErrBadHandle; |
|
1197 |
} |
|
1198 |
t.iExtTempObj=pT; |
|
1199 |
RemoteThread()=pT; |
|
1200 |
NKern::UnlockSystem(); |
|
1201 |
} |
|
1202 |
Pos()=d.iPos; |
|
1203 |
Length()=d.iLength; |
|
1204 |
RemoteDes()=(TAny*)d.iPtr; |
|
1205 |
RemoteDesOffset()=d.iOffset; |
|
1206 |
DriverFlags()=d.iFlags; |
|
1207 |
if (Pos()<0 || Length()<0) |
|
1208 |
return KErrArgument; |
|
1209 |
return KErrNone; |
|
1210 |
} |
|
1211 |
||
1212 |
void TLocDrvRequest::CloseRemoteThread() |
|
1213 |
{ |
|
1214 |
if (!RemoteThread()) |
|
1215 |
return; |
|
1216 |
NKern::ThreadEnterCS(); |
|
1217 |
DThread& t=Kern::CurrentThread(); |
|
1218 |
RemoteThread()=NULL; |
|
1219 |
Kern::SafeClose((DObject*&)t.iExtTempObj,NULL); |
|
1220 |
NKern::ThreadLeaveCS(); |
|
1221 |
} |
|
1222 |
||
1223 |
EXPORT_C TInt TLocDrvRequest::CheckAndAdjustForPartition() |
|
1224 |
{ |
|
1225 |
TLocDrv& d=*Drive(); |
|
1226 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("CheckAndAdjustForPartition drive %d partition len %lx",d.iDriveNumber,d.iPartitionLen)); |
|
1227 |
Flags() |= EAdjusted; |
|
1228 |
switch (Id()) |
|
1229 |
{ |
|
1230 |
case DLocalDrive::ECaps: |
|
1231 |
case DLocalDrive::EForceMediaChange: |
|
1232 |
case DLocalDrive::EPasswordLock: |
|
1233 |
case DLocalDrive::EPasswordUnlock: |
|
1234 |
case DLocalDrive::EPasswordClear: |
|
1235 |
case DLocalDrive::EPasswordErase: |
|
1236 |
case DLocalDrive::EReadPasswordStore: |
|
1237 |
case DLocalDrive::EWritePasswordStore: |
|
1238 |
case DLocalDrive::EPasswordStoreLengthInBytes: |
|
1239 |
case DLocalDrive::EQueryDevice: |
|
1240 |
return KErrNone; |
|
1241 |
case DLocalDrive::EEnlarge: |
|
1242 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("Enlarge request %lx",Length())); |
|
1243 |
if (Length()>KMaxTInt) |
|
1244 |
return KErrArgument; |
|
1245 |
return KErrNone; |
|
1246 |
case DLocalDrive::EReduce: |
|
1247 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("Reduce request %lx@%lx",Length(),Pos())); |
|
1248 |
if (Pos()+Length()>d.iPartitionLen) |
|
1249 |
return KErrArgument; |
|
1250 |
return KErrNone; |
|
1251 |
case DLocalDrive::EFormat: |
|
1252 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("Format request %lx@%lx",Length(),Pos())); |
|
1253 |
if (!(DriverFlags() & RLocalDrive::ELocDrvWholeMedia)) |
|
1254 |
{ |
|
1255 |
if (Pos()>d.iPartitionLen) |
|
1256 |
{ |
|
1257 |
Length()=0; |
|
1258 |
return KErrEof; |
|
1259 |
} |
|
1260 |
Int64 left=d.iPartitionLen-Pos(); |
|
1261 |
if (left<Length()) |
|
1262 |
Length()=left; |
|
1263 |
Pos()+=d.iPartitionBaseAddr; |
|
1264 |
if (Length()==0) |
|
1265 |
return KErrEof; |
|
1266 |
} |
|
1267 |
return KErrNone; |
|
1268 |
||
1269 |
#ifdef __DEMAND_PAGING__ |
|
1270 |
case DMediaPagingDevice::ERomPageInRequest: |
|
1271 |
// if the ROM was reported to LOCM then it will also need to be adjusted.... |
|
1272 |
// Otherwise the media driver adjust it internally |
|
1273 |
case DMediaPagingDevice::ECodePageInRequest: |
|
1274 |
__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Adjusted Paging read request %lx@%lx",Length(),Pos())); |
|
1275 |
if (Pos()+Length()>d.iPartitionLen) |
|
1276 |
return KErrArgument; |
|
1277 |
Pos()+=d.iPartitionBaseAddr; |
|
1278 |
return KErrNone; |
|
1279 |
#endif |
|
1280 |
||
1281 |
default: // read or write or fragment |
|
1282 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("R/W request %lx@%lx",Length(),Pos())); |
|
1283 |
||
1284 |
if (DriverFlags() & RLocalDrive::ELocDrvWholeMedia) |
|
1285 |
{ |
|
1286 |
if (d.iMedia && d.iMedia->iDriver && Pos()+Length() > d.iMedia->iDriver->iTotalSizeInBytes) |
|
1287 |
return KErrArgument; |
|
1288 |
} |
|
1289 |
else |
|
1290 |
{ |
|
1291 |
if (Pos()+Length() > d.iPartitionLen) |
|
1292 |
return KErrArgument; |
|
1293 |
Pos()+=d.iPartitionBaseAddr; |
|
1294 |
} |
|
1295 |
return KErrNone; |
|
1296 |
} |
|
1297 |
} |
|
1298 |
||
1299 |
/******************************************** |
|
1300 |
* Local drive class |
|
1301 |
********************************************/ |
|
1302 |
TLocDrv::TLocDrv(TInt aDriveNumber) |
|
1303 |
{ |
|
1304 |
memclr(this, sizeof(TLocDrv)); |
|
1305 |
iDriveNumber=aDriveNumber; |
|
1306 |
iPartitionNumber=-1; |
|
1307 |
} |
|
1308 |
||
1309 |
/** |
|
1310 |
Initialises the DMedia entity with the media device number and ID. |
|
1311 |
||
1312 |
@param aDevice The unique ID for this device. This can take one of the |
|
1313 |
enumerated values defined in TMediaDevice enum. |
|
1314 |
||
1315 |
@param aMediaId The unique ID to associate with this media entity. |
|
1316 |
||
1317 |
@return KErrNone,if successful, otherwise one of the other |
|
1318 |
system-wide error codes. |
|
1319 |
||
1320 |
@see TMediaDevice |
|
1321 |
*/ |
|
1322 |
EXPORT_C TInt DMedia::Create(TMediaDevice aDevice, TInt aMediaId, TInt) |
|
1323 |
{ |
|
1324 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DMedia::Create media %d device %d",aMediaId,aDevice)); |
|
1325 |
iMediaId=aMediaId; |
|
1326 |
iDevice=aDevice; |
|
1327 |
return KErrNone; |
|
1328 |
} |
|
1329 |
||
1330 |
/******************************************** |
|
1331 |
* Primary Media Class |
|
1332 |
********************************************/ |
|
1333 |
void asyncDfc(TAny* aPtr) |
|
1334 |
{ |
|
1335 |
DPrimaryMediaBase* pM=(DPrimaryMediaBase*)aPtr; |
|
1336 |
if (pM->iState==DMedia::EOpening) |
|
1337 |
pM->DoOpenMediaDriverComplete(pM->iAsyncErrorCode); |
|
1338 |
else if (pM->iState==DMedia::EReadPartitionInfo) |
|
1339 |
pM->DoPartitionInfoComplete(pM->iAsyncErrorCode); |
|
1340 |
} |
|
1341 |
||
1342 |
void handleMsg(TAny* aPtr) |
|
1343 |
{ |
|
1344 |
DPrimaryMediaBase* primaryMedia=(DPrimaryMediaBase*)aPtr; |
|
1345 |
||
1346 |
for(TLocDrvRequest* m = (TLocDrvRequest*) primaryMedia->iMsgQ.iMessage; |
|
1347 |
m != NULL; |
|
1348 |
m = (TLocDrvRequest*) primaryMedia->iMsgQ.Poll()) |
|
1349 |
{ |
|
1350 |
#if defined(_DEBUG) |
|
1351 |
if (!primaryMedia->iMsgQ.iQ.IsEmpty()) |
|
1352 |
__KTRACE_OPT(KLOCDRV, Kern::Printf("TRACE: handleMsg, queue not empty %08X", m)); |
|
1353 |
#endif |
|
1354 |
primaryMedia->HandleMsg(*m); |
|
1355 |
||
1356 |
#ifdef __DEMAND_PAGING__ |
|
1357 |
// don't empty the queue if this media is paging as there |
|
1358 |
// may be a (higher-priority) paging DFC waiting to run... |
|
1359 |
if (primaryMedia->iPagingMedia) |
|
1360 |
break; |
|
1361 |
#endif |
|
1362 |
} |
|
1363 |
||
1364 |
||
1365 |
primaryMedia->iMsgQ.Receive(); // allow reception of more messages |
|
1366 |
} |
|
1367 |
||
1368 |
EXPORT_C DPrimaryMediaBase::DPrimaryMediaBase() |
|
1369 |
: iMsgQ(handleMsg, this, NULL, 1), |
|
1370 |
iDeferred(NULL, NULL, NULL, 0), // callback never used |
|
1371 |
iWaitMedChg(NULL, NULL, NULL, 0), // callback never used |
|
1372 |
iAsyncDfc(asyncDfc, this, 1) |
|
1373 |
/** |
|
1374 |
Constructor of DPrimaryMediaBase class. |
|
1375 |
Initialises the media state as closed. |
|
1376 |
*/ |
|
1377 |
{ |
|
1378 |
iState = EClosed; |
|
1379 |
} |
|
1380 |
||
1381 |
||
1382 |
||
1383 |
EXPORT_C TInt DPrimaryMediaBase::Create(TMediaDevice aDevice, TInt aMediaId, TInt aLastMediaId) |
|
1384 |
/** |
|
1385 |
Called from LocDrv::RegisterMediaDevice() function. |
|
1386 |
Calls DMedia::Create() |
|
1387 |
||
1388 |
@param aDevice Local media ID |
|
1389 |
@param aMediaId Media Id (unique for a media subsystem) |
|
1390 |
@param aLastMediaId This indicates number of used media ids+ number of DMedia objects to be associated with the media driver. |
|
1391 |
||
1392 |
@return KErrNone |
|
1393 |
@see TMediaDevice |
|
1394 |
||
1395 |
*/ |
|
1396 |
{ |
|
1397 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase::Create media %d-%d device %d",aMediaId,aLastMediaId,aDevice)); |
|
1398 |
TInt r=DMedia::Create(aDevice,aMediaId,0); |
|
1399 |
if (r != KErrNone) |
|
1400 |
return r; |
|
1401 |
iBody = new DBody; |
|
1402 |
if (iBody == NULL) |
|
1403 |
return KErrNoMemory; |
|
1404 |
||
1405 |
#ifdef __DEMAND_PAGING__ |
|
1406 |
TInt pageSize = Kern::RoundToPageSize(1); |
|
1407 |
iBody->iPageSizeMsk = pageSize-1; |
|
1408 |
#endif |
|
1409 |
||
1410 |
iLastMediaId=aLastMediaId; |
|
1411 |
if (r==KErrNone && iDfcQ) |
|
1412 |
{ |
|
1413 |
iMsgQ.SetDfcQ(iDfcQ); |
|
1414 |
iDeferred.SetDfcQ(iDfcQ); |
|
1415 |
iWaitMedChg.SetDfcQ(iDfcQ); |
|
1416 |
iAsyncDfc.SetDfcQ(iDfcQ); |
|
1417 |
} |
|
1418 |
return KErrNone; |
|
1419 |
} |
|
1420 |
||
1421 |
||
1422 |
EXPORT_C TInt DPrimaryMediaBase::Connect(DLocalDrive* aLocalDrive) |
|
1423 |
/** |
|
1424 |
Connects to a local drive |
|
1425 |
||
1426 |
@param aLocalDrive Local drive logical channel abstraction |
|
1427 |
||
1428 |
@pre Kernel must be unlocked |
|
1429 |
@pre Current thread in critical section |
|
1430 |
||
1431 |
@post Kernel must be unlocked |
|
1432 |
||
1433 |
@return KErrNone, if successful |
|
1434 |
KErrNotFound, If no PDD matches criteria while getting driver list |
|
1435 |
KErrNoMemory, If the array could not be expanded at some point while getting driver list or ran out of memory while opening media driver |
|
1436 |
KErrNotReady, If not ready when trying to open media driver |
|
1437 |
otherwise, one of the other system wide error codes. |
|
1438 |
||
1439 |
@see DLocalDrive |
|
1440 |
*/ |
|
1441 |
{ |
|
1442 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::Connect %O",iMediaId,aLocalDrive)); |
|
1443 |
if (iDfcQ) |
|
1444 |
{ |
|
1445 |
TThreadMessage& m=Kern::Message(); |
|
1446 |
m.iValue=EConnect; |
|
1447 |
m.iArg[0]=aLocalDrive; |
|
1448 |
return m.SendReceive(&iMsgQ); |
|
1449 |
} |
|
1450 |
||
1451 |
// If no DFC queue, must be a fixed media device |
|
1452 |
// If this is the first connection, open media driver now |
|
1453 |
// Assume no non-primary media exist on this device |
|
1454 |
TInt r=KErrNone; |
|
1455 |
NKern::LockSystem(); |
|
1456 |
TBool first=iConnectionQ.IsEmpty(); |
|
1457 |
iConnectionQ.Add(&aLocalDrive->iLink); |
|
1458 |
NKern::UnlockSystem(); |
|
1459 |
if (first) |
|
1460 |
{ |
|
1461 |
r=OpenMediaDriver(); |
|
1462 |
if (r!=KErrNone) |
|
1463 |
{ |
|
1464 |
NKern::LockSystem(); |
|
1465 |
aLocalDrive->Deque(); |
|
1466 |
NKern::UnlockSystem(); |
|
1467 |
} |
|
1468 |
} |
|
1469 |
if (r==KErrNone) |
|
1470 |
aLocalDrive->iDrive->iMedia=this; |
|
1471 |
return r; |
|
1472 |
} |
|
1473 |
||
1474 |
||
1475 |
||
1476 |
||
1477 |
EXPORT_C void DPrimaryMediaBase::Disconnect(DLocalDrive* aLocalDrive) |
|
1478 |
/** |
|
1479 |
Disconnects from a local drive |
|
1480 |
||
1481 |
@param aLocalDrive Local drive logical channel abstraction |
|
1482 |
||
1483 |
@pre Kernel must be unlocked |
|
1484 |
@pre Current thread in critical section |
|
1485 |
||
1486 |
@post Kernel must be unlocked |
|
1487 |
@see DLocalDrive |
|
1488 |
*/ |
|
1489 |
||
1490 |
{ |
|
1491 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::Disconnect %O",iMediaId,aLocalDrive)); |
|
1492 |
if (iDfcQ) |
|
1493 |
{ |
|
1494 |
TThreadMessage& m=Kern::Message(); |
|
1495 |
m.iValue=EDisconnect; |
|
1496 |
m.iArg[0]=aLocalDrive; |
|
1497 |
m.SendReceive(&iMsgQ); |
|
1498 |
return; |
|
1499 |
} |
|
1500 |
||
1501 |
// If no DFC queue, must be a fixed media device |
|
1502 |
// If this is the last connection, close media driver now |
|
1503 |
// Assume no non-primary media exist on this device |
|
1504 |
DMediaDriver* pD=NULL; |
|
1505 |
NKern::LockSystem(); |
|
1506 |
aLocalDrive->iDrive->iMedia=NULL; |
|
1507 |
aLocalDrive->Deque(); |
|
1508 |
if (iConnectionQ.IsEmpty()) |
|
1509 |
{ |
|
1510 |
pD=iDriver; |
|
1511 |
iDriver=NULL; |
|
1512 |
} |
|
1513 |
NKern::UnlockSystem(); |
|
1514 |
if (pD) |
|
1515 |
pD->Close(); |
|
1516 |
} |
|
1517 |
||
1518 |
EXPORT_C TInt DPrimaryMediaBase::Request(TLocDrvRequest& aReq) |
|
1519 |
/** |
|
1520 |
Issues a local drive request. It is called from TLocDrv::Request() function . |
|
1521 |
Each local drive request is encapsulated as a TLocDrvRequest- a class derived from TThreadMessage, the kernel message class. |
|
1522 |
TLocDrvRequest contains information pertaining to the request, including the ID and any associated parameters such as drive position, length and source/destination location. |
|
1523 |
Passes the request through to the media driver. |
|
1524 |
||
1525 |
@param m Encapsulates the request information received from the client |
|
1526 |
||
1527 |
@pre Enter with kernel unlocked |
|
1528 |
||
1529 |
@post Leave with Kernel unlocked |
|
1530 |
||
1531 |
@return KErrNone,if successful |
|
1532 |
KErrBadDescriptor, if request encapsulates a bad descriptor |
|
1533 |
Otherwise, one of the other system wide error codes. |
|
1534 |
||
1535 |
@see TLocDrvRequest |
|
1536 |
*/ |
|
1537 |
{ |
|
1538 |
||
1539 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::Request(%08x)",iMediaId,&aReq)); |
|
1540 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("this=%x, ReqId=%d, Pos=%lx, Len=%lx, remote thread %O",this,aReq.Id(),aReq.Pos(),aReq.Length(),aReq.RemoteThread())); |
|
1541 |
||
1542 |
TInt reqId = aReq.Id(); |
|
1543 |
||
1544 |
if (reqId == DLocalDrive::ECaps) |
|
1545 |
DefaultDriveCaps(*(TLocalDriveCapsV2*)aReq.RemoteDes()); // fill in stuff we know even if no media present |
|
1546 |
||
1547 |
TInt r = QuickCheckStatus(); |
|
1548 |
if (r != KErrNone && aReq.Id()!=DLocalDrive::EForceMediaChange && // EForceMediaChange, and |
|
1549 |
aReq.Id()!=DLocalDrive::EReadPasswordStore && // Password store operations |
|
1550 |
aReq.Id()!=DLocalDrive::EWritePasswordStore && // do not require the media |
|
1551 |
aReq.Id()!=DLocalDrive::EPasswordStoreLengthInBytes) // to be ready.) |
|
1552 |
{ |
|
1553 |
return r; |
|
1554 |
} |
|
1555 |
||
1556 |
||
1557 |
// for ERead & EWrite requests, get the linear address for pinning & DMA |
|
1558 |
TUint8* linAddress = NULL; |
|
1559 |
TClientBuffer clientBuffer; |
|
1560 |
DThread* pT = NULL; |
|
1561 |
||
1562 |
if (reqId == DLocalDrive::ERead || reqId == DLocalDrive::EWrite) |
|
1563 |
{ |
|
1564 |
pT = aReq.RemoteThread(); |
|
1565 |
if (!pT) |
|
1566 |
pT = &Kern::CurrentThread(); // e.g. when using TBusLocalDrive directly |
|
1567 |
||
1568 |
// for silly zero-length requests, return immediately, setting the client |
|
1569 |
// descriptor length to zero if it's a read request |
|
1570 |
if (aReq.Length() == 0) |
|
1571 |
{ |
|
1572 |
DThread* pC = &Kern::CurrentThread(); |
|
1573 |
r = KErrNone; |
|
1574 |
if (reqId == DLocalDrive::ERead) |
|
1575 |
{ |
|
1576 |
TPtrC8 ptr(NULL, 0); |
|
1577 |
r = Kern::ThreadDesWrite(pT, aReq.RemoteDes(), ptr, aReq.RemoteDesOffset(), KChunkShiftBy0,pC); |
|
1578 |
} |
|
1579 |
return r; |
|
1580 |
} |
|
1581 |
||
1582 |
clientBuffer.SetFromDescriptor(aReq.RemoteDes(), pT); |
|
1583 |
||
1584 |
TInt length = 0; |
|
1585 |
TInt maxLength = 0; |
|
1586 |
TInt r = Kern::ThreadGetDesInfo(pT,aReq.RemoteDes(),length,maxLength,linAddress,EFalse); // get descriptor length, maxlength and linAddress |
|
1587 |
if (r != KErrNone) |
|
1588 |
return r; |
|
1589 |
linAddress+= aReq.RemoteDesOffset(); |
|
1590 |
||
1591 |
#ifdef __DEMAND_PAGING__ |
|
1592 |
// NB change in behavior IF DATA PAGING IS ENABLED: TLocDrvRequest::RemoteDes() points |
|
1593 |
// to a TClientBuffer rather than the client's remote descriptor |
|
1594 |
if (DataPagingDeviceRegistered) |
|
1595 |
{ |
|
1596 |
aReq.RemoteDes() = &clientBuffer; |
|
1597 |
aReq.Flags() |= TLocDrvRequest::ETClientBuffer; |
|
1598 |
} |
|
1599 |
#endif |
|
1600 |
} |
|
1601 |
||
1602 |
if (iDfcQ) |
|
1603 |
{ |
|
1604 |
__TRACE_TIMING(0x10); |
|
1605 |
||
1606 |
||
1607 |
#ifdef __DEMAND_PAGING__ |
|
1608 |
// If this is a ROM/Code paging media, pin writes |
|
1609 |
// If there is a Data paging media registered, pin all requests with descriptors |
|
1610 |
if ( (DataPagingDeviceRegistered) || (reqId == DLocalDrive::EWrite && RomPagingDfcQ(this)) ) |
|
1611 |
r = PinSendReceive(aReq, (TLinAddr) linAddress); |
|
1612 |
else |
|
1613 |
#endif // __DEMAND_PAGING__ |
|
1614 |
||
1615 |
r = SendReceive(aReq, (TLinAddr) linAddress); |
|
1616 |
} |
|
1617 |
else |
|
1618 |
{ |
|
1619 |
// If no DFC queue, must be a fixed media device |
|
1620 |
// Media driver must already have been opened |
|
1621 |
// Assume no non-primary media exist on this device |
|
1622 |
// Just pass request straight through to media driver |
|
1623 |
r = aReq.CheckAndAdjustForPartition(); |
|
1624 |
if (r == KErrNone) |
|
1625 |
r = iDriver->Request(aReq); |
|
1626 |
} |
|
1627 |
||
1628 |
#ifdef __DEMAND_PAGING__ |
|
1629 |
// NB change in behavior IF DATA PAGING IS ENABLED: TLocDrvRequest::RemoteDes() points |
|
1630 |
// to a TClientBuffer rather than the client's remote descriptor |
|
1631 |
if (reqId == DLocalDrive::ERead && DataPagingDeviceRegistered && r == KErrNone) |
|
1632 |
{ |
|
1633 |
r = clientBuffer.UpdateDescriptorLength(pT); |
|
1634 |
} |
|
1635 |
#endif |
|
1636 |
||
1637 |
return r; |
|
1638 |
} |
|
1639 |
||
1640 |
||
1641 |
#ifdef __DEMAND_PAGING__ |
|
1642 |
TInt DPrimaryMediaBase::PinSendReceive(TLocDrvRequest& aReq, TLinAddr aLinAddress) |
|
1643 |
{ |
|
1644 |
__ASSERT_DEBUG(ThePinObjectAllocator, LOCM_FAULT()); |
|
1645 |
||
1646 |
||
1647 |
TInt msgId = aReq.Id(); |
|
1648 |
||
1649 |
||
1650 |
switch(msgId) |
|
1651 |
{ |
|
1652 |
case DLocalDrive::EControlIO: |
|
1653 |
{ |
|
1654 |
TInt controlIoType = aReq.Int3(); |
|
1655 |
switch(controlIoType) |
|
1656 |
{ |
|
1657 |
case KLocalMessageHandle: |
|
1658 |
// ControlIo is not supported if either of the two bare (TAny*) pointers are non-NULL |
|
1659 |
// as it's not possible to determine what the pointers are pointing at... |
|
1660 |
if (aReq.Int1() || aReq.Int2()) |
|
1661 |
{ |
|
1662 |
__KTRACE_OPT(KDATAPAGEWARN, Kern::Printf("Data paging: Naked EControlIO not supported on paging device: fn=%x", aReq.Int0())); |
|
1663 |
return KErrNotSupported; |
|
1664 |
} |
|
1665 |
// fall into... |
|
1666 |
case 0: |
|
1667 |
return SendReceive(aReq); |
|
1668 |
||
1669 |
default: |
|
1670 |
// if Int3() is > 0, Int1() is a data pointer, and Int3() is a length |
|
1671 |
if (controlIoType > (TInt) ThePinObjectAllocator->iFragmentGranularity) |
|
1672 |
return KErrTooBig; |
|
1673 |
if (controlIoType < 0) |
|
1674 |
return KErrArgument; |
|
1675 |
return PinFragmentSendReceive(aReq, (TLinAddr) aReq.Ptr1(), controlIoType); |
|
1676 |
} |
|
1677 |
} |
|
1678 |
||
1679 |
case DLocalDrive::ERead: |
|
1680 |
case DLocalDrive::EWrite: |
|
1681 |
{ |
|
1682 |
return PinFragmentSendReceive(aReq, aLinAddress, aReq.Length()); |
|
1683 |
} |
|
1684 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1685 |
// For all these requests, aReq.RemoteDes() points to a buffer on the stack in DLocalDrive::Request() |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1686 |
// This is a kernel stack & so should be unpaged & not require pinning... |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1687 |
case DLocalDrive::ECaps: |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1688 |
case DLocalDrive::EGetLastErrorInfo: |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1689 |
case DLocalDrive::EQueryDevice: |
0 | 1690 |
case DLocalDrive::EPasswordLock: |
1691 |
case DLocalDrive::EPasswordUnlock: |
|
1692 |
case DLocalDrive::EPasswordClear: |
|
1693 |
case DLocalDrive::EReadPasswordStore: |
|
1694 |
case DLocalDrive::EWritePasswordStore: |
|
1695 |
case DLocalDrive::EPasswordStoreLengthInBytes: |
|
1696 |
case DLocalDrive::EPasswordErase: |
|
1697 |
||
1698 |
default: |
|
1699 |
return SendReceive(aReq); |
|
1700 |
} |
|
1701 |
} |
|
1702 |
||
1703 |
TInt DPrimaryMediaBase::PinFragmentSendReceive(TLocDrvRequest& aReq, TLinAddr aLinAddress, TInt aLength) |
|
1704 |
{ |
|
1705 |
TLocDrvRequest fragment = aReq; // create a request on the stack for use during fragmentation, pre-fill with the original req args, leave original Kernel message as repository (thread will block, message contents won't change) |
|
1706 |
TInt r = KErrNone; |
|
1707 |
||
1708 |
// Kern::Printf(">PFSR %02X aReq %08X aLinAddress %08X aLen %08X offset %08X", aReq.Id(), &aReq, aLinAddress, aLength, aReq.RemoteDesOffset()); |
|
1709 |
||
1710 |
DThread* pT = aReq.RemoteThread(); |
|
1711 |
if (!pT) |
|
1712 |
pT=&Kern::CurrentThread(); // e.g. when using TBusLocalDrive directly |
|
1713 |
||
1714 |
__KTRACE_OPT2(KLOCDPAGING,KLOCDRV,Kern::Printf("Fragmenting Read/Write Request(0x%08x) on drive(%d), remote des(0x%x), offset into des(0x%x), original req Length(0x%x)",&aReq,aReq.Drive()->iDriveNumber,(TInt)(aReq.RemoteDes()),aReq.RemoteDesOffset(),aLength)); |
|
1715 |
__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Remote thread(0x%08x), current thread(0x%08x), start of data to write(0x%08x)",aReq.RemoteThread(),&Kern::CurrentThread(),(TInt)aLinAddress)); |
|
1716 |
||
1717 |
// don't want this thread to be terminated until last fragment is sent to MD and mem can be free'd up |
|
1718 |
NKern::ThreadEnterCS(); |
|
1719 |
||
1720 |
__ASSERT_DEBUG(ThePinObjectAllocator, LOCM_FAULT()); |
|
1721 |
||
1722 |
TUint fragmentGranularity = ThePinObjectAllocator->iFragmentGranularity; |
|
1723 |
TInt dataLockResult = 0; |
|
1724 |
// fragmentation only allowed for read/write requests |
|
1725 |
__ASSERT_DEBUG(aLength <= (TInt) fragmentGranularity || (aReq.Id() == DLocalDrive::EWrite || aReq.Id() == DLocalDrive::ERead), LOCM_FAULT()); |
|
1726 |
||
1727 |
// Pin the client buffer |
|
1728 |
TInt pinnedLen; |
|
1729 |
for (TInt pos = 0; pos < aLength; pos+= pinnedLen, aLinAddress+= pinnedLen) |
|
1730 |
{ |
|
1731 |
pinnedLen = 0; |
|
1732 |
||
1733 |
// pin memory |
|
1734 |
TInt remainingLen = aLength - pos; // remaining length |
|
1735 |
||
1736 |
// first attempt to pin memory with no pre-allocated buffers (which may fail) |
|
1737 |
DPinObjectAllocator::SVirtualPinContainer* pinDataObject = ThePinObjectAllocator->AcquirePinObject(); |
|
1738 |
||
1739 |
if (pinDataObject) |
|
1740 |
{ |
|
1741 |
TInt lenToPin = Min(KMaxPinData, remainingLen); |
|
1742 |
||
1743 |
TInt r = Kern::PinVirtualMemory(pinDataObject->iObject, aLinAddress, lenToPin, pT); |
|
1744 |
if (r == KErrNone) |
|
1745 |
{ |
|
1746 |
pinnedLen = lenToPin; |
|
1747 |
} |
|
1748 |
else |
|
1749 |
{ |
|
1750 |
#ifdef __DEBUG_DEMAND_PAGING__ |
|
1751 |
Kern::Printf("Kern::PinVirtualMemory() error %d", r); |
|
1752 |
#endif |
|
1753 |
// pin failed, so use preallocated buffer instead |
|
1754 |
ThePinObjectAllocator->ReleasePinObject(pinDataObject); |
|
1755 |
pinDataObject = NULL; |
|
1756 |
} |
|
1757 |
} |
|
1758 |
||
1759 |
if (!pinDataObject) |
|
1760 |
{ |
|
1761 |
ThePinObjectAllocator->PreAllocatedDataLock().LockFragmentation(); |
|
1762 |
||
1763 |
TLinAddr start = aLinAddress; |
|
1764 |
do |
|
1765 |
{ |
|
1766 |
TInt lenToPin = Min((TInt) fragmentGranularity, remainingLen - pinnedLen); |
|
1767 |
||
1768 |
#ifdef __DEBUG_DEMAND_PAGING__ |
|
1769 |
Kern::Printf(">SR PinS Id %d aLinAddress %08X lenToPin %08X offset %08X", aReq.Id(), aLinAddress, lenToPin); |
|
1770 |
#endif |
|
1771 |
||
1772 |
dataLockResult = ThePinObjectAllocator->PreAllocatedDataLock().Lock(pT, start, lenToPin); |
|
1773 |
||
1774 |
#ifdef __DEBUG_DEMAND_PAGING__ |
|
1775 |
Kern::Printf("<SR PinS Id %d aLinAddress %08X lenToPin %08X offset %08X r %d", aReq.Id(), aLinAddress, lenToPin, r); |
|
1776 |
#endif |
|
1777 |
||
1778 |
start+= lenToPin; |
|
1779 |
pinnedLen+= lenToPin; |
|
1780 |
} |
|
1781 |
while (dataLockResult == 0 && pinnedLen < remainingLen); |
|
1782 |
||
1783 |
// if nothing pinned (dataLockResult == 0) or error (dataLockResult <0), release the mutex, |
|
1784 |
// otherwise (dataLockResult > 0) release it after calling SendReceive() |
|
1785 |
if (dataLockResult <= 0) |
|
1786 |
ThePinObjectAllocator->PreAllocatedDataLock().UnlockFragmentation(); |
|
1787 |
||
1788 |
#ifdef __DEBUG_DEMAND_PAGING__ |
|
1789 |
if (dataLockResult < 0) |
|
1790 |
Kern::Printf("DFragmentationPagingLock::Lock() %d", dataLockResult); |
|
1791 |
#endif |
|
1792 |
||
1793 |
if (dataLockResult < 0) // if lock returned an error then give up |
|
1794 |
{ |
|
1795 |
r = dataLockResult; |
|
1796 |
break; |
|
1797 |
} |
|
1798 |
} |
|
1799 |
||
1800 |
// fragment request Id defaults to same as original request |
|
1801 |
fragment.Id() = aReq.Id(); |
|
1802 |
fragment.Length() = Int64(pinnedLen); |
|
1803 |
fragment.RemoteDesOffset() = aReq.RemoteDesOffset() + pos; |
|
1804 |
fragment.Pos() = aReq.Pos() + pos; |
|
1805 |
fragment.Flags() = aReq.Flags(); |
|
1806 |
||
1807 |
__KTRACE_OPT2(KLOCDPAGING,KLOCDRV,Kern::Printf("Send fragment (0x%08x) type(%d), length(0x%x), offset within original req(0x%x), pos in media(0x%lx)",&fragment,fragment.Id(), pinnedLen, pos, fragment.Pos())); |
|
1808 |
||
1809 |
#ifdef BTRACE_PAGING_MEDIA |
|
1810 |
TInt buf[4]; |
|
1811 |
buf[0] = pinnedLen; // fragment length |
|
1812 |
buf[1] = pos; // offset within original request |
|
1813 |
buf[2] = fragment.Pos(); // offset in media |
|
1814 |
buf[3] = (TInt)&pT->iNThread; // thread that issued the original write req |
|
1815 |
BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedFragmentBegin,&fragment,fragment.Id(),buf,sizeof(buf)); |
|
1816 |
#endif |
|
1817 |
||
1818 |
r = SendReceive(fragment, aLinAddress); // only come back here when message (fragment) has been completed |
|
1819 |
||
1820 |
// unpin memory |
|
1821 |
if (pinDataObject) |
|
1822 |
{ |
|
1823 |
Kern::UnpinVirtualMemory(pinDataObject->iObject); |
|
1824 |
ThePinObjectAllocator->ReleasePinObject(pinDataObject); |
|
1825 |
} |
|
1826 |
else if (dataLockResult > 0) // pinDataObject = NULL |
|
1827 |
{ |
|
1828 |
__ASSERT_DEBUG(dataLockResult == 1, LOCM_FAULT()); |
|
1829 |
ThePinObjectAllocator->PreAllocatedDataLock().Unlock(); |
|
1830 |
ThePinObjectAllocator->PreAllocatedDataLock().UnlockFragmentation(); |
|
1831 |
} |
|
1832 |
||
1833 |
#ifdef BTRACE_PAGING_MEDIA |
|
1834 |
BTraceContext8(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedFragmentEnd,&fragment,r); |
|
1835 |
#endif |
|
1836 |
||
1837 |
if (r != KErrNone) |
|
1838 |
break; |
|
1839 |
} |
|
1840 |
||
1841 |
NKern::ThreadLeaveCS(); |
|
1842 |
||
1843 |
// Kern::Printf("<PFSR %02X aReq %08X aLinAddress %08X aLen %08X offset %08X", aReq.Id(), &aReq, aLinAddress, aLength, aReq.RemoteDesOffset()); |
|
1844 |
||
1845 |
return r; |
|
1846 |
} |
|
1847 |
||
1848 |
#endif // __DEMAND_PAGING__ |
|
1849 |
||
1850 |
||
1851 |
TInt DPrimaryMediaBase::SendReceive(TLocDrvRequest& aReq, TLinAddr aLinAddress) |
|
1852 |
/** |
|
1853 |
* If a Physical memory helper object is present for given drive, |
|
1854 |
* then message is routed via helper; |
|
1855 |
* |
|
1856 |
* @return KErrNone, if successful; |
|
1857 |
* otherwise, one of the other system wide error codes. |
|
1858 |
* |
|
1859 |
* @see TLocDrvRequest::SendReceive() |
|
1860 |
* @see DDmaHelper::SendReceive() |
|
1861 |
*/ |
|
1862 |
{ |
|
1863 |
DDmaHelper* dmaHelper = aReq.Drive()->iDmaHelper; |
|
1864 |
||
1865 |
#ifdef __DEMAND_PAGING__ |
|
1866 |
RequestCountInc(); |
|
1867 |
#endif |
|
1868 |
||
1869 |
TInt r; |
|
1870 |
||
1871 |
if (dmaHelper) |
|
1872 |
r = dmaHelper->SendReceive(aReq, aLinAddress); |
|
1873 |
else |
|
1874 |
r = aReq.SendReceive(&iMsgQ); |
|
1875 |
||
1876 |
#ifdef __DEMAND_PAGING__ |
|
1877 |
RequestCountDec(); |
|
1878 |
#endif |
|
1879 |
||
1880 |
return r; |
|
1881 |
} |
|
1882 |
||
1883 |
||
1884 |
||
1885 |
EXPORT_C TInt DPrimaryMediaBase::ForceMediaChange(TInt) |
|
1886 |
/** |
|
1887 |
Forces a media change.The method can be overridden in the derived classes. |
|
1888 |
@param mode Media change mode |
|
1889 |
||
1890 |
@return KErrNotSupported, in the default implementation |
|
1891 |
KErrNone, if successful |
|
1892 |
Otherwise, one of the other system wide error codes. |
|
1893 |
||
1894 |
*/ |
|
1895 |
{ |
|
1896 |
// default implementation |
|
1897 |
return KErrNotSupported; |
|
1898 |
} |
|
1899 |
||
1900 |
EXPORT_C TInt DPrimaryMediaBase::InitiatePowerUp() |
|
1901 |
/** |
|
1902 |
Initiates Power up sequence |
|
1903 |
@return KErrCompletion, operation is complete successfully or otherwise |
|
1904 |
KErrNone, if successful |
|
1905 |
Otherwise, one of the other system wide error codes. |
|
1906 |
||
1907 |
*/ |
|
1908 |
{ |
|
1909 |
// default implementation, this is the default implementation. |
|
1910 |
return KErrCompletion; |
|
1911 |
} |
|
1912 |
||
1913 |
EXPORT_C TInt DPrimaryMediaBase::QuickCheckStatus() |
|
1914 |
/** |
|
1915 |
Checks the status of the media device, whether the device is present,absent,not ready,etc. |
|
1916 |
The function can be overridden in the derived classes |
|
1917 |
||
1918 |
@return KErrNone, if successful |
|
1919 |
Otherwise, one of the other system wide error codes. |
|
1920 |
||
1921 |
*/ |
|
1922 |
{ |
|
1923 |
// default implementation |
|
1924 |
return KErrNone; |
|
1925 |
} |
|
1926 |
||
1927 |
EXPORT_C void DPrimaryMediaBase::DefaultDriveCaps(TLocalDriveCapsV2& aCaps) |
|
1928 |
/** |
|
1929 |
Fills in the default drive capabilities in TLocalDriveCapsV2 . |
|
1930 |
It initializes media type of drive as unknown and has to be overridden in the derived class. Called from the Request ( ) function of the same class. |
|
1931 |
||
1932 |
@param aCaps Media drive capability fields. Extension to Capabilities fields(i.e) in addition to TLocalDriveCaps mainly to support Nor flash |
|
1933 |
@see TLocalDriveCapsV2 |
|
1934 |
*/ |
|
1935 |
||
1936 |
{ |
|
1937 |
// default implementation |
|
1938 |
// aCaps is zeroed beforehand |
|
1939 |
aCaps.iType = EMediaUnknown; |
|
1940 |
} |
|
1941 |
||
1942 |
EXPORT_C TBool DPrimaryMediaBase::IsRemovableDevice(TInt& /*aSocketNum*/) |
|
1943 |
/** |
|
1944 |
Checks whether it is a removable device or not |
|
1945 |
@param aSocketNum Socket number |
|
1946 |
@return ETrue=Removable Device |
|
1947 |
EFalse=Non-Removable device, default implementation |
|
1948 |
||
1949 |
*/ |
|
1950 |
{ |
|
1951 |
// default implementation |
|
1952 |
return(EFalse); |
|
1953 |
} |
|
1954 |
||
1955 |
EXPORT_C void DPrimaryMediaBase::HandleMsg(TLocDrvRequest& m) |
|
1956 |
/** |
|
1957 |
It handles the drive request encapsulated in TLocDrvRequest depending on the message id. |
|
1958 |
||
1959 |
@param aRequest Encapsulates the request information received from the client |
|
1960 |
@see TLocDrvRequest |
|
1961 |
*/ |
|
1962 |
{ |
|
1963 |
switch (m.iValue) |
|
1964 |
{ |
|
1965 |
case EConnect: |
|
1966 |
{ |
|
1967 |
DLocalDrive* pD=(DLocalDrive*)m.Ptr0(); |
|
1968 |
iConnectionQ.Add(&pD->iLink); |
|
1969 |
m.Complete(KErrNone, EFalse); |
|
1970 |
return; |
|
1971 |
} |
|
1972 |
case EDisconnect: |
|
1973 |
{ |
|
1974 |
DLocalDrive* pD=(DLocalDrive*)m.Ptr0(); |
|
1975 |
TLocDrv* pL=pD->iDrive; |
|
1976 |
DMedia* media=pL->iMedia; |
|
1977 |
if (iState==EReady && media && media->iDriver) |
|
1978 |
media->iDriver->Disconnect(pD,&m); |
|
1979 |
else |
|
1980 |
{ |
|
1981 |
pD->Deque(); |
|
1982 |
m.Complete(KErrNone, EFalse); |
|
1983 |
} |
|
1984 |
return; |
|
1985 |
} |
|
1986 |
case DLocalDrive::EForceMediaChange: |
|
1987 |
{ |
|
1988 |
TUint flags = (TUint) m.Pos(); |
|
1989 |
||
1990 |
// if KForceMediaChangeReOpenDriver specified wait for power up, |
|
1991 |
// and then re-open this drive's media driver |
|
1992 |
__KTRACE_OPT(KLOCDRV, Kern::Printf("EForceMediaChange, flags %08X\n", flags)); |
|
1993 |
if (flags == (TUint) KForceMediaChangeReOpenMediaDriver) |
|
1994 |
{ |
|
1995 |
TInt sock; |
|
1996 |
if (!IsRemovableDevice(sock)) |
|
1997 |
{ |
|
1998 |
CompleteRequest(m, KErrNotSupported); |
|
1999 |
return; |
|
2000 |
} |
|
2001 |
// wait for power up and then call DPrimaryMediaBase::DoRequest() |
|
2002 |
break; |
|
2003 |
} |
|
2004 |
||
2005 |
TInt r=ForceMediaChange(flags); |
|
2006 |
if (r==KErrNone) |
|
2007 |
{ |
|
2008 |
// wait for media change notification to complete message |
|
2009 |
m.Forward(&iWaitMedChg,EFalse); |
|
2010 |
} |
|
2011 |
else |
|
2012 |
{ |
|
2013 |
if (r==KErrNotSupported || r==KErrCompletion) |
|
2014 |
r=KErrNone; |
|
2015 |
CompleteRequest(m, r); |
|
2016 |
} |
|
2017 |
return; |
|
2018 |
} |
|
2019 |
case DLocalDrive::ECaps: |
|
2020 |
if (iState==EPoweredDown) |
|
2021 |
{ |
|
2022 |
// The media is powered down, but the media driver still exists. |
|
2023 |
// - Issue the ECaps request without powering the media back up. |
|
2024 |
DoRequest(m); |
|
2025 |
__TRACE_TIMING(0x101); |
|
2026 |
return; |
|
2027 |
} |
|
2028 |
break; |
|
2029 |
||
2030 |
case DLocalDrive::ERead: |
|
2031 |
case DLocalDrive::EWrite: |
|
2032 |
case DLocalDrive::EFormat: |
|
2033 |
case DLocalDrive::EEnlarge: |
|
2034 |
case DLocalDrive::EReduce: |
|
2035 |
case DLocalDrive::EPasswordLock: |
|
2036 |
case DLocalDrive::EPasswordUnlock: |
|
2037 |
case DLocalDrive::EPasswordClear: |
|
2038 |
case DLocalDrive::EPasswordErase: |
|
2039 |
case DLocalDrive::EControlIO: |
|
2040 |
case DLocalDrive::EDeleteNotify: |
|
2041 |
case DLocalDrive::EQueryDevice: |
|
2042 |
||
2043 |
#ifdef __DEMAND_PAGING__ |
|
2044 |
case DMediaPagingDevice::ERomPageInRequest: |
|
2045 |
case DMediaPagingDevice::ECodePageInRequest: |
|
2046 |
#endif |
|
2047 |
break; |
|
2048 |
case DLocalDrive::EGetLastErrorInfo: |
|
2049 |
{ |
|
2050 |
DLocalDrive* pD=(DLocalDrive*)m.Ptr0(); |
|
2051 |
TLocDrv* pL=pD->iDrive; |
|
2052 |
*((TErrorInfo*) m.RemoteDes()) = pL->iLastErrorInfo; |
|
2053 |
CompleteRequest(m, KErrNone); |
|
2054 |
return; |
|
2055 |
} |
|
2056 |
case DLocalDrive::EReadPasswordStore: |
|
2057 |
{ |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2058 |
TPtr8 pswData ((TUint8*) m.RemoteDes(), (TInt) m.Length()); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2059 |
TInt r = ThePasswordStore->ReadPasswordData(pswData); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2060 |
m.Length() = pswData.Length(); |
0 | 2061 |
CompleteRequest(m, r); |
2062 |
return; |
|
2063 |
} |
|
2064 |
case DLocalDrive::EWritePasswordStore: |
|
2065 |
{ |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2066 |
TPtrC8 pData((TUint8*) m.RemoteDes(), (TInt) m.Length()); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2067 |
TInt r = ThePasswordStore->WritePasswordData(pData); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2068 |
|
0 | 2069 |
if(r != KErrNone) |
2070 |
{ |
|
2071 |
CompleteRequest(m, r); |
|
2072 |
return; |
|
2073 |
} |
|
2074 |
||
2075 |
r = QuickCheckStatus(); |
|
2076 |
if(r != KErrNone) |
|
2077 |
{ |
|
2078 |
// Don't try to power up the device if it's not ready. |
|
2079 |
// - Note that this isn't an error that needs to be returned to the client. |
|
2080 |
CompleteRequest(m, KErrNone); |
|
2081 |
return; |
|
2082 |
} |
|
2083 |
||
2084 |
break; |
|
2085 |
} |
|
2086 |
case DLocalDrive::EPasswordStoreLengthInBytes: |
|
2087 |
{ |
|
2088 |
TInt length = ThePasswordStore->PasswordStoreLengthInBytes(); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2089 |
*(TInt*) m.RemoteDes() = length; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2090 |
CompleteRequest(m, KErrNone); |
0 | 2091 |
return; |
2092 |
} |
|
2093 |
default: |
|
2094 |
CHECK_RET(KErrNotSupported); |
|
2095 |
CompleteRequest(m, KErrNotSupported); |
|
2096 |
return; |
|
2097 |
} |
|
2098 |
||
2099 |
__KTRACE_OPT(KFAIL,Kern::Printf("mdrq %d",m.Id())); |
|
2100 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::HandleMsg state %d req %d",iMediaId,iState,m.Id())); |
|
2101 |
||
2102 |
// if media driver already open, pass request through |
|
2103 |
if (iState==EReady) |
|
2104 |
{ |
|
2105 |
DoRequest(m); |
|
2106 |
__TRACE_TIMING(0x101); |
|
2107 |
return; |
|
2108 |
} |
|
2109 |
||
2110 |
// if open or close in progress, defer this message |
|
2111 |
if (iState!=EClosed && iState!=EPoweredDown) |
|
2112 |
{ |
|
2113 |
#ifdef __DEMAND_PAGING__ |
|
2114 |
if (DMediaPagingDevice::PagingRequest(m)) |
|
2115 |
{ |
|
2116 |
__ASSERT_ALWAYS(iPagingMedia,LOCM_FAULT()); |
|
2117 |
__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT()); |
|
2118 |
__ASSERT_ALWAYS( ((m.Flags() & TLocDrvRequest::ECodePaging) == 0) || (m.Drive()->iPagingDrv), LOCM_FAULT()); |
|
2119 |
||
2120 |
__KTRACE_OPT2(KLOCDPAGING,KLOCDRV,Kern::Printf("Deferring PageIn request 0x%08x because opening or closing",&m)); |
|
2121 |
iBody->iPagingDevice->SendToDeferredQ(&m); |
|
2122 |
} |
|
2123 |
else |
|
2124 |
#endif |
|
2125 |
m.Forward(&iDeferred,EFalse); |
|
2126 |
return; |
|
2127 |
} |
|
2128 |
||
2129 |
// nothing is open, so try to open something |
|
2130 |
__ASSERT_ALWAYS(!iCurrentReq,LOCM_FAULT()); |
|
2131 |
||
2132 |
#ifdef __DEMAND_PAGING__ |
|
2133 |
||
2134 |
#ifdef BTRACE_PAGING_MEDIA |
|
2135 |
if (DMediaPagingDevice::PagingRequest(m)) |
|
2136 |
BTraceContext12(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInQuietlyDeferred,&m,iState,m.iValue); |
|
2137 |
#endif // BTRACE_PAGING_MEDIA |
|
2138 |
||
2139 |
#ifdef _DEBUG |
|
2140 |
__ASSERT_ALWAYS( ((m.Flags() & TLocDrvRequest::ECodePaging) == 0) || (m.Drive()->iPagingDrv), LOCM_FAULT()); |
|
2141 |
||
2142 |
if (DMediaPagingDevice::PagingRequest(m)) |
|
2143 |
{ |
|
2144 |
__ASSERT_DEBUG(iPagingMedia,LOCM_FAULT()); |
|
2145 |
__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT()); |
|
2146 |
__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Page request 0x%08x received -> opening MD",&m)); |
|
2147 |
} |
|
2148 |
#endif // _DEBUG |
|
2149 |
||
2150 |
#endif // __DEMAND_PAGING__ |
|
2151 |
||
2152 |
iCurrentReq=&m; |
|
2153 |
if(iState == EClosed) |
|
2154 |
{ |
|
2155 |
iState=EPoweringUp1; |
|
2156 |
} |
|
2157 |
else if (iState == EPoweredDown) |
|
2158 |
{ |
|
2159 |
iState=EPoweringUp2; |
|
2160 |
} |
|
2161 |
||
2162 |
TInt r=InitiatePowerUp(); |
|
2163 |
if (r==KErrNone || r==KErrServerBusy) |
|
2164 |
{ |
|
2165 |
// wait for completion of power up request |
|
2166 |
return; |
|
2167 |
} |
|
2168 |
if (r==KErrCompletion) |
|
2169 |
r=KErrNone; // device already powered up |
|
2170 |
PowerUpComplete(r); |
|
2171 |
} |
|
2172 |
||
2173 |
EXPORT_C TInt DPrimaryMediaBase::DoRequest(TLocDrvRequest& m) |
|
2174 |
/** |
|
2175 |
If the media exists, it tries to get the partition information if not there. |
|
2176 |
It then passes on the request to the media driver by calling its Request( ) function. |
|
2177 |
Then it completes the kernel thread message and the reference count of the thread is closed asynchronously. |
|
2178 |
||
2179 |
@param aRequest Encapsulates the request information received from the client |
|
2180 |
||
2181 |
@return KErrNone, if successful |
|
2182 |
KErrNotReady, if missing partitions on removable media |
|
2183 |
KErrNotSupported, if missing partitions on fixed media |
|
2184 |
KErrArgument Out of range argument ,encapsulated in Local drive request , passed while checking and adjusting for partition |
|
2185 |
KErrEOF, Reached the end of file |
|
2186 |
KErrBadDescriptor, if request encapsulates a bad descriptor |
|
2187 |
Otherwise, one of the other system wide error codes. |
|
2188 |
||
2189 |
*/ |
|
2190 |
{ |
|
2191 |
__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DPrimaryMediaBase::DoRequest %d",m.Id())); |
|
2192 |
TLocDrv* pL=m.Drive(); |
|
2193 |
DMedia* media=pL->iMedia; |
|
2194 |
TInt r=KErrNone; |
|
2195 |
||
2196 |
// re-open this drive's media driver ? |
|
2197 |
if (m.iValue == DLocalDrive::EForceMediaChange) |
|
2198 |
{ |
|
2199 |
__ASSERT_DEBUG(((TUint) m.Pos()) == (TUint) KForceMediaChangeReOpenMediaDriver, LOCM_FAULT()); |
|
2200 |
||
2201 |
iCurrentReq=NULL; |
|
2202 |
||
2203 |
TLocDrv* pL = m.Drive(); |
|
2204 |
DMedia* media = pL->iMedia; |
|
2205 |
if (media && media->iDriver) |
|
2206 |
CloseMediaDrivers(media); |
|
2207 |
||
2208 |
iState=EOpening; |
|
2209 |
StartOpenMediaDrivers(); |
|
2210 |
||
2211 |
NotifyClients(ETrue,pL); |
|
2212 |
CompleteRequest(m, r); |
|
2213 |
return r; |
|
2214 |
} |
|
2215 |
||
2216 |
if (!media || !media->iDriver || iState == EClosed) |
|
2217 |
{ |
|
2218 |
// Return KErrNotReady for missing partitions on removable media |
|
2219 |
// as opposed to KErrNotSupported for missing partitions on fixed media |
|
2220 |
// since the latter don't exist whereas the former might exist at some time. |
|
2221 |
TInt sock; |
|
2222 |
r=IsRemovableDevice(sock) ? KErrNotReady : KErrNotSupported; |
|
2223 |
} |
|
2224 |
||
2225 |
iCurrentReq=&m; |
|
2226 |
if (r==KErrNone) |
|
2227 |
{ |
|
2228 |
if(iTotalPartitionsOpened == 0) |
|
2229 |
{ |
|
2230 |
UpdatePartitionInfo(); |
|
2231 |
return KErrNone; |
|
2232 |
} |
|
2233 |
if (!(m.Flags() & TLocDrvRequest::EAdjusted)) |
|
2234 |
{ |
|
2235 |
// If this isn't the only partition, don't allow access to the whole media |
|
2236 |
if (iTotalPartitionsOpened > 1) |
|
2237 |
m.DriverFlags() &= ~RLocalDrive::ELocDrvWholeMedia; |
|
2238 |
r=m.CheckAndAdjustForPartition(); |
|
2239 |
} |
|
2240 |
if (r==KErrNone) |
|
2241 |
{ |
|
2242 |
r=media->iDriver->Request(m); |
|
2243 |
if (r>0) |
|
2244 |
{ |
|
2245 |
// defer request |
|
2246 |
#ifdef __DEMAND_PAGING__ |
|
2247 |
if (DMediaPagingDevice::PagingRequest(m)) |
|
2248 |
{ |
|
2249 |
__ASSERT_ALWAYS(iPagingMedia,LOCM_FAULT()); |
|
2250 |
__ASSERT_ALWAYS( ((m.Flags() & TLocDrvRequest::ECodePaging) == 0) || (m.Drive()->iPagingDrv), LOCM_FAULT()); |
|
2251 |
__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT()); |
|
2252 |
__KTRACE_OPT2(KLOCDPAGING,KLOCDRV,Kern::Printf("Defer PageIn request 0x%08x",&m)); |
|
2253 |
DMediaPagingDevice* pagingdevice=iBody->iPagingDevice; |
|
2254 |
||
2255 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
2256 |
TInt id=m.iValue; |
|
2257 |
if (id==DMediaPagingDevice::ERomPageInRequest) |
|
2258 |
{ |
|
2259 |
NKern::FMWait(&pagingdevice->iInstrumentationLock); |
|
2260 |
if(pagingdevice->iEmptyingQ & DMediaPagingDevice::EDeferredQ) |
|
2261 |
pagingdevice->iROMStats.iTotalReDeferrals++; |
|
2262 |
else if(pagingdevice->iEmptyingQ & DMediaPagingDevice::EMainQ) |
|
2263 |
pagingdevice->iROMStats.iTotalSynchDeferredFromMainQ++; |
|
2264 |
NKern::FMSignal(&pagingdevice->iInstrumentationLock); |
|
2265 |
} |
|
2266 |
else if (m.Flags() & TLocDrvRequest::ECodePaging) |
|
2267 |
{ |
|
2268 |
NKern::FMWait(&pagingdevice->iInstrumentationLock); |
|
2269 |
if(pagingdevice->iEmptyingQ & DMediaPagingDevice::EDeferredQ) |
|
2270 |
pagingdevice->iCodeStats.iTotalReDeferrals++; |
|
2271 |
else if(pagingdevice->iEmptyingQ & DMediaPagingDevice::EMainQ) |
|
2272 |
pagingdevice->iCodeStats.iTotalSynchDeferredFromMainQ++; |
|
2273 |
NKern::FMSignal(&pagingdevice->iInstrumentationLock); |
|
2274 |
} |
|
2275 |
else if (m.Flags() & TLocDrvRequest::EDataPaging) |
|
2276 |
{ |
|
2277 |
NKern::FMWait(&pagingdevice->iInstrumentationLock); |
|
2278 |
if(pagingdevice->iEmptyingQ & DMediaPagingDevice::EDeferredQ) |
|
2279 |
pagingdevice->iDataStats.iTotalReDeferrals++; |
|
2280 |
else if(pagingdevice->iEmptyingQ & DMediaPagingDevice::EMainQ) |
|
2281 |
pagingdevice->iDataStats.iTotalSynchDeferredFromMainQ++; |
|
2282 |
NKern::FMSignal(&pagingdevice->iInstrumentationLock); |
|
2283 |
} |
|
2284 |
#endif |
|
2285 |
pagingdevice->SendToDeferredQ(&m); |
|
2286 |
} |
|
2287 |
else |
|
2288 |
#endif |
|
2289 |
m.Forward(&iDeferred,EFalse); |
|
2290 |
r=KErrNone; |
|
2291 |
} |
|
2292 |
#if defined(__DEMAND_PAGING__) && defined(_DEBUG) |
|
2293 |
else if (r == KErrNone && DMediaPagingDevice::PagingRequest(m)) |
|
2294 |
__KTRACE_OPT(KLOCDPAGING,Kern::Printf("PageIn req 0x%08x completing asynchronously",&m)); |
|
2295 |
#endif |
|
2296 |
} |
|
2297 |
} |
|
2298 |
||
2299 |
if (r!=KErrNone && iCurrentReq) |
|
2300 |
{ |
|
2301 |
TInt s=(r==KErrCompletion)?KErrNone:r; |
|
2302 |
CHECK_RET(s); |
|
2303 |
||
2304 |
#ifdef __DEMAND_PAGING__ |
|
2305 |
// got here because media driver cannot service or defer this request or did service it synchronously |
|
2306 |
if (DMediaPagingDevice::PagingRequest(m)) |
|
2307 |
{ |
|
2308 |
__ASSERT_ALWAYS(iPagingMedia,LOCM_FAULT()); |
|
2309 |
__ASSERT_ALWAYS( ((m.Flags() & TLocDrvRequest::ECodePaging) == 0) || (m.Drive()->iPagingDrv), LOCM_FAULT()); |
|
2310 |
__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT()); |
|
2311 |
__KTRACE_OPT(KLOCDPAGING,Kern::Printf("media driver cannot service or defer PageIn request 0x%08x or serviced it synchronously (%d)",&m, s)); |
|
2312 |
iBody->iPagingDevice->CompleteRequest(&m, s); |
|
2313 |
} |
|
2314 |
else |
|
2315 |
#endif |
|
2316 |
||
2317 |
CompleteRequest(m, s); |
|
2318 |
||
2319 |
} |
|
2320 |
||
2321 |
iCurrentReq=NULL; |
|
2322 |
return r; |
|
2323 |
} |
|
2324 |
||
2325 |
EXPORT_C void DPrimaryMediaBase::PowerUpComplete(TInt anError) |
|
2326 |
/** |
|
2327 |
Called after the device is powered up or there is some error while powering up the device. |
|
2328 |
If there is an error powering up the devices then it just completes the current running requests with an error |
|
2329 |
and also completes the outstanding requests on the iDeferred message queue by calling SetClosed( ). |
|
2330 |
If the device is powered up OK then it either opens the media drivers |
|
2331 |
and if they are already open then it handles the current/pending requests. |
|
2332 |
||
2333 |
@param anError Error code to be passed on while completing outstanding requests. |
|
2334 |
*/ |
|
2335 |
{ |
|
2336 |
__KTRACE_OPT(KLOCDRV,Kern::Printf(">DPrimaryMediaBase(%d)::PowerUpComplete err %d iState %d",iMediaId,anError,iState)); |
|
2337 |
if (anError!=KErrNone) |
|
2338 |
{ |
|
2339 |
// error powering up device |
|
2340 |
if (iState==EPoweringUp1 || iState==EPoweringUp2) |
|
2341 |
SetClosed(anError); |
|
2342 |
return; |
|
2343 |
} |
|
2344 |
||
2345 |
// Powered up OK - now open media drivers |
|
2346 |
if (iState==EPoweringUp1) |
|
2347 |
{ |
|
2348 |
iState=EOpening; |
|
2349 |
StartOpenMediaDrivers(); |
|
2350 |
} |
|
2351 |
else if (iState==EPoweringUp2) |
|
2352 |
{ |
|
2353 |
// media is powered up and ready, so handle the current/pending requests |
|
2354 |
MediaReadyHandleRequest(); |
|
2355 |
} |
|
2356 |
} |
|
2357 |
||
2358 |
void DPrimaryMediaBase::CloseMediaDrivers(DMedia* aMedia) |
|
2359 |
{ |
|
2360 |
__KTRACE_OPT(KLOCDRV,Kern::Printf(">DPrimaryMediaBase(%d)::CloseMediaDrivers",iMediaId)); |
|
2361 |
||
2362 |
// we mustn't ever close the media driver if it's responsible for data paging as re-opening the drive |
|
2363 |
// would involve memory allocation which might cause deadlock if the kernel heap were to grow |
|
2364 |
#ifdef __DEMAND_PAGING__ |
|
2365 |
if (DataPagingDfcQ(this)) |
|
2366 |
{ |
|
2367 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("CloseMediaDrivers aborting for data paging media %08X", this)); |
|
2368 |
return; |
|
2369 |
} |
|
2370 |
#endif |
|
2371 |
||
2372 |
TInt i; |
|
2373 |
for (i=0; i<KMaxLocalDrives; i++) |
|
2374 |
{ |
|
2375 |
TLocDrv* pL=TheDrives[i]; |
|
2376 |
if (pL && pL->iPrimaryMedia==this) |
|
2377 |
{ |
|
2378 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("Drive %d",i)); |
|
2379 |
if (aMedia == NULL || pL->iMedia == aMedia) |
|
2380 |
{ |
|
2381 |
pL->iMedia=NULL; |
|
2382 |
} |
|
2383 |
} |
|
2384 |
} |
|
2385 |
for (i=iLastMediaId; i>=iMediaId; i--) |
|
2386 |
{ |
|
2387 |
DMedia* pM=TheMedia[i]; |
|
2388 |
if (aMedia == NULL || pM == aMedia) |
|
2389 |
{ |
|
2390 |
DMediaDriver* pD=pM->iDriver; |
|
2391 |
pM->iDriver=NULL; |
|
2392 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DMedia[%d] @ %08x Driver @ %08x",i,pM,pD)); |
|
2393 |
if (pD) |
|
2394 |
pD->Close(); |
|
2395 |
} |
|
2396 |
} |
|
2397 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("<DPrimaryMediaBase(%d)::CloseMediaDrivers",iMediaId)); |
|
2398 |
} |
|
2399 |
||
2400 |
void DPrimaryMediaBase::StartOpenMediaDrivers() |
|
2401 |
{ |
|
2402 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::StartOpenMediaDrivers",iMediaId)); |
|
2403 |
TVersion ver(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion); |
|
2404 |
||
2405 |
// Get a list of all currently loaded media drivers |
|
2406 |
// Most media drivers do not make use of the pointer iMountInfo.iInfo when |
|
2407 |
// their Validate() procedures are called from RPhysicalDeviceArray::GetDriverList(). |
|
2408 |
// However, a group of media drivers sharing the same id (passed in iDevice) may use |
|
2409 |
// the additional information pointed to by iMountInfo.iInfo to distinguish |
|
2410 |
// group members. This information is passed when the media driver is registered |
|
2411 |
// using LocDrv::RegisterMediaDevice(). |
|
2412 |
TInt r=iPhysDevArray.GetDriverList(KLitMediaDriverName,iDevice,iMountInfo.iInfo,ver); |
|
2413 |
if (r!=KErrNone) |
|
2414 |
{ |
|
2415 |
// out of memory or no driver exists |
|
2416 |
SetClosed(r); |
|
2417 |
return; |
|
2418 |
} |
|
2419 |
||
2420 |
// Go through them starting with highest priority |
|
2421 |
iNextMediaId=iMediaId; |
|
2422 |
iBody->iPhysDevIndex=iPhysDevArray.Count()-1; |
|
2423 |
iTotalPartitionsOpened=0; |
|
2424 |
iMediaDriversOpened=0; |
|
2425 |
iNextMediaDriver=NULL; |
|
2426 |
OpenNextMediaDriver(); |
|
2427 |
} |
|
2428 |
||
2429 |
void DPrimaryMediaBase::OpenNextMediaDriver() |
|
2430 |
{ |
|
2431 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::OpenNextMediaDriver, this %x mediaId %d iBody->iPhysDevIndex %d",iNextMediaId, this, iMediaId, iBody->iPhysDevIndex)); |
|
2432 |
||
2433 |
TVersion ver(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion); |
|
2434 |
SPhysicalDeviceEntry& e=iPhysDevArray[iBody->iPhysDevIndex]; |
|
2435 |
DPhysicalDevice* pD=e.iPhysicalDevice; |
|
2436 |
||
2437 |
iState = EOpening; |
|
2438 |
||
2439 |
DMedia* pM=TheMedia[iNextMediaId]; |
|
2440 |
if (pM && pM->iDriver != NULL) |
|
2441 |
{ |
|
2442 |
iNextMediaDriver = pM->iDriver; |
|
2443 |
DoOpenMediaDriverComplete(KErrNone); |
|
2444 |
return; |
|
2445 |
} |
|
2446 |
||
2447 |
// this may be asynchronous |
|
2448 |
TInt s=pD->Create( (DBase*&)iNextMediaDriver, iMediaId, (TDesC8*) &iMountInfo, ver); |
|
2449 |
||
2450 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("Media:Open-Opening %o(PRI:%d)-%d",pD,e.iPriority,s)); |
|
2451 |
if (s!=KErrNone) |
|
2452 |
{ |
|
2453 |
iAsyncErrorCode=s; |
|
2454 |
iAsyncDfc.Enque(); |
|
2455 |
} |
|
2456 |
} |
|
2457 |
||
2458 |
// Called when a media driver has responded to the Open request |
|
2459 |
void DPrimaryMediaBase::DoOpenMediaDriverComplete(TInt anError) |
|
2460 |
{ |
|
2461 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::DoOpenMediaDriverComplete error %d iNextMediaDriver %x",iNextMediaId,anError,iNextMediaDriver)); |
|
2462 |
||
2463 |
if (anError!=KErrNone) |
|
2464 |
{ |
|
2465 |
DMediaDriver* md = iNextMediaDriver; |
|
2466 |
iNextMediaDriver = NULL; |
|
2467 |
if (md) |
|
2468 |
md->Close(); |
|
2469 |
} |
|
2470 |
if (anError==KErrNotReady || anError==KErrNoMemory) |
|
2471 |
{ |
|
2472 |
// if it's not ready or we're out of memory, abort |
|
2473 |
CloseMediaDrivers(); |
|
2474 |
SetClosed(anError); |
|
2475 |
return; |
|
2476 |
} |
|
2477 |
if (anError==KErrNone) |
|
2478 |
{ |
|
2479 |
DMedia* pM=TheMedia[iNextMediaId]; |
|
2480 |
pM->iDriver=iNextMediaDriver; |
|
2481 |
DPhysicalDevice*& pD=iPhysDevArray[iBody->iPhysDevIndex].iPhysicalDevice; |
|
2482 |
iNextMediaDriver->iPhysicalDevice=pD; |
|
2483 |
pD=NULL; // so it won't be closed when we tidy up |
|
2484 |
++iMediaDriversOpened; |
|
2485 |
} |
|
2486 |
||
2487 |
// if no error, read partition info on media |
|
2488 |
iState = EReadPartitionInfo; |
|
2489 |
||
2490 |
if (anError == KErrNone) |
|
2491 |
{ |
|
2492 |
DMedia* pM=TheMedia[iNextMediaId]; |
|
2493 |
TInt r = pM->iDriver->PartitionInfo(pM->iPartitionInfo); |
|
2494 |
if (r!=KErrNone) |
|
2495 |
{ |
|
2496 |
if (r==KErrCompletion) |
|
2497 |
r=KErrNone; |
|
2498 |
DoPartitionInfoComplete(r); |
|
2499 |
} |
|
2500 |
} |
|
2501 |
else |
|
2502 |
{ |
|
2503 |
DoPartitionInfoComplete(anError); |
|
2504 |
} |
|
2505 |
} |
|
2506 |
||
2507 |
void DPrimaryMediaBase::DoPartitionInfoComplete(TInt anError) |
|
2508 |
{ |
|
2509 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::DoPartitionInfoComplete error %d",iNextMediaId,anError)); |
|
2510 |
||
2511 |
DMedia* pM=TheMedia[iNextMediaId]; |
|
2512 |
if (anError==KErrNone || anError == KErrLocked) |
|
2513 |
{ |
|
2514 |
// successfully read partition info |
|
2515 |
iTotalPartitionsOpened+=pM->PartitionCount(); |
|
2516 |
} |
|
2517 |
else |
|
2518 |
{ |
|
2519 |
// couldn't read partition info or driver failed to open |
|
2520 |
if (pM->iDriver) |
|
2521 |
{ |
|
2522 |
#ifdef __DEMAND_PAGING__ |
|
2523 |
if (DataPagingDfcQ(this)) |
|
2524 |
{ |
|
2525 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DoPartitionInfoComplete(%d) Close Media Driver aborted for data paging media %08X", this)); |
|
2526 |
} |
|
2527 |
else |
|
2528 |
#endif |
|
2529 |
{ |
|
2530 |
pM->iDriver->Close(); |
|
2531 |
pM->iDriver=NULL; |
|
2532 |
} |
|
2533 |
} |
|
2534 |
if (anError==KErrNotReady || anError==KErrNoMemory) |
|
2535 |
{ |
|
2536 |
// if it's not ready or we're out of memory, or the drive is locked, abort |
|
2537 |
CloseMediaDrivers(); |
|
2538 |
SetClosed(anError); |
|
2539 |
return; |
|
2540 |
} |
|
2541 |
} |
|
2542 |
||
2543 |
// Open next media driver, if there is one |
|
2544 |
TBool complete = EFalse; |
|
2545 |
if (++iNextMediaId>iLastMediaId) |
|
2546 |
complete=ETrue; |
|
2547 |
if (iBody->iPhysDevIndex==0) |
|
2548 |
complete=ETrue; |
|
2549 |
else |
|
2550 |
iBody->iPhysDevIndex--; |
|
2551 |
if (!complete) |
|
2552 |
{ |
|
2553 |
OpenNextMediaDriver(); |
|
2554 |
return; |
|
2555 |
} |
|
2556 |
||
2557 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase %d All media drivers open & partitions read",iMediaId)); |
|
2558 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("%d media drivers opened",iMediaDriversOpened)); |
|
2559 |
if (iMediaDriversOpened==0) |
|
2560 |
{ |
|
2561 |
SetClosed(KErrNotSupported); |
|
2562 |
return; |
|
2563 |
} |
|
2564 |
||
2565 |
// we are now finished with media driver list |
|
2566 |
iPhysDevArray.Close(); |
|
2567 |
||
2568 |
// Finished reading partition info |
|
2569 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase %d Read partition info complete",iMediaId)); |
|
2570 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("%d total partitions",iTotalPartitionsOpened)); |
|
2571 |
if (iTotalPartitionsOpened==0) |
|
2572 |
{ |
|
2573 |
SetClosed(KErrNotSupported); |
|
2574 |
return; |
|
2575 |
} |
|
2576 |
||
2577 |
// work out mapping of drives to partitions/media |
|
2578 |
TInt totalPartitions=iTotalPartitionsOpened; |
|
2579 |
TInt id=iMediaId; // start with primary media |
|
2580 |
TInt partitionsOnThisMedia=PartitionCount(); |
|
2581 |
TInt partition=0; |
|
2582 |
TInt j; |
|
2583 |
for (j=0; j<KMaxLocalDrives; j++) |
|
2584 |
{ |
|
2585 |
TLocDrv* pD=TheDrives[j]; |
|
2586 |
if (pD && pD->iPrimaryMedia==this) |
|
2587 |
{ |
|
2588 |
if (totalPartitions==0) |
|
2589 |
{ |
|
2590 |
pD->iMedia=NULL; |
|
2591 |
continue; |
|
2592 |
} |
|
2593 |
if (partition==partitionsOnThisMedia) |
|
2594 |
{ |
|
2595 |
id++; |
|
2596 |
partition=0; |
|
2597 |
partitionsOnThisMedia=TheMedia[id]->PartitionCount(); |
|
2598 |
} |
|
2599 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("Drive %d = Media %d Partition %d",j,id,partition)); |
|
2600 |
pD->iMedia=TheMedia[id]; |
|
2601 |
pD->iPartitionNumber=partition; |
|
2602 |
memcpy(pD, pD->iMedia->iPartitionInfo.iEntry+partition, sizeof(TPartitionEntry)); |
|
2603 |
partition++; |
|
2604 |
totalPartitions--; |
|
2605 |
} |
|
2606 |
} |
|
2607 |
||
2608 |
// media is now ready - handle current or deferred requests |
|
2609 |
MediaReadyHandleRequest(); |
|
2610 |
} |
|
2611 |
||
2612 |
void DPrimaryMediaBase::MediaReadyHandleRequest() |
|
2613 |
{ |
|
2614 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase::MediaReadyHandleRequest() this %x", this)); |
|
2615 |
iState = EReady; |
|
2616 |
||
2617 |
// now we can process the current request |
|
2618 |
// careful - thread may have exited while we were powering up |
|
2619 |
if (iCurrentReq) |
|
2620 |
{ |
|
2621 |
DoRequest(*iCurrentReq); // this sets iCurrentReq=NULL |
|
2622 |
} |
|
2623 |
||
2624 |
// see if we can process any other requests concurrently |
|
2625 |
RunDeferred(); |
|
2626 |
} |
|
2627 |
||
2628 |
void DPrimaryMediaBase::UpdatePartitionInfo() |
|
2629 |
{ |
|
2630 |
iState=EReadPartitionInfo; |
|
2631 |
iNextMediaId=iMediaId; |
|
2632 |
DMedia* pM=TheMedia[iNextMediaId]; |
|
2633 |
TInt r=pM->iDriver->PartitionInfo(pM->iPartitionInfo); |
|
2634 |
if (r!=KErrNone) |
|
2635 |
{ |
|
2636 |
if (r==KErrCompletion) |
|
2637 |
r=KErrNone; |
|
2638 |
DoPartitionInfoComplete(r); |
|
2639 |
} |
|
2640 |
} |
|
2641 |
||
2642 |
void DPrimaryMediaBase::CompleteCurrent(TInt anError) |
|
2643 |
{ |
|
2644 |
if (iCurrentReq) |
|
2645 |
{ |
|
2646 |
CHECK_RET(anError); |
|
2647 |
#ifdef __DEMAND_PAGING__ |
|
2648 |
// got here because it was powered down when powering up, or failed powering up or failed opening MD or got media change |
|
2649 |
if (DMediaPagingDevice::PagingRequest(*iCurrentReq)) |
|
2650 |
{ |
|
2651 |
__ASSERT_ALWAYS(iPagingMedia,LOCM_FAULT()); |
|
2652 |
__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT()); |
|
2653 |
__ASSERT_ALWAYS( ((iCurrentReq->Flags() & TLocDrvRequest::ECodePaging) == 0) || (iCurrentReq->Drive()->iPagingDrv), LOCM_FAULT()); |
|
2654 |
||
2655 |
__KTRACE_OPT2(KLOCDPAGING,KFAIL,Kern::Printf("Got here because it was powered down when powering up, or failed powering up or failed opening MD or got media change")); |
|
2656 |
iBody->iPagingDevice->CompleteRequest(iCurrentReq, anError); |
|
2657 |
} |
|
2658 |
else |
|
2659 |
#endif |
|
2660 |
CompleteRequest(*iCurrentReq, anError); |
|
2661 |
iCurrentReq=NULL; |
|
2662 |
} |
|
2663 |
} |
|
2664 |
||
2665 |
||
2666 |
void DPrimaryMediaBase::CompleteRequest(TLocDrvRequest& aMsg, TInt aResult) |
|
2667 |
{ |
|
2668 |
aMsg.Complete(aResult,EFalse); |
|
2669 |
} |
|
2670 |
||
2671 |
EXPORT_C void DPrimaryMediaBase::RunDeferred() |
|
2672 |
/** |
|
2673 |
Runs deferred Requests. Initiated from DPrimaryMediaBase::PowerUpComplete() function |
|
2674 |
to see if any other requests can be processed concurrently. |
|
2675 |
Can also be called from DPrimaryMediaBase::NotifyPowerDown |
|
2676 |
or DPrimaryMediaBase::NotifyEmergencyPowerDown() function or DMediaDriver::Complete() |
|
2677 |
*/ |
|
2678 |
{ |
|
2679 |
// Do nothing if an open or close is in progress - this might be the case, for example, |
|
2680 |
// if a EForceMediaChange request (with the KForceMediaChangeReOpenMediaDriver flag) |
|
2681 |
// has recently been processed |
|
2682 |
if (iState!=EReady && iState!=EClosed && iState!=EPoweredDown) |
|
2683 |
return; |
|
2684 |
||
2685 |
// rerun deferred requests; |
|
2686 |
#ifdef __DEMAND_PAGING__ |
|
2687 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
2688 |
TInt countROM=0; |
|
2689 |
TInt countCode=0; |
|
2690 |
#endif |
|
2691 |
||
2692 |
if(iPagingMedia) |
|
2693 |
{ |
|
2694 |
__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT()); |
|
2695 |
if(iBody->iPagingDevice->iEmptyingQ & DMediaPagingDevice::EDeferredQ) // if already emptying deferred page in queue, don't reenter |
|
2696 |
{ |
|
2697 |
__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Already emptying deferred queue")); |
|
2698 |
return; |
|
2699 |
} |
|
2700 |
||
2701 |
DMediaPagingDevice* pagingdevice=iBody->iPagingDevice; |
|
2702 |
TLocDrvRequest* pL = (TLocDrvRequest*) pagingdevice->iDeferredQ.Last(); |
|
2703 |
if(pL) |
|
2704 |
{ |
|
2705 |
pagingdevice->iEmptyingQ|= DMediaPagingDevice::EDeferredQ; // prevent reentering when already emptying this queue |
|
2706 |
TLocDrvRequest* pM=NULL; |
|
2707 |
while (pM != pL && (pM = (TLocDrvRequest*) pagingdevice->iDeferredQ.Poll()) != NULL) // synchronously empty deferred queue but ignore re-deferrals |
|
2708 |
{ |
|
2709 |
__ASSERT_ALWAYS( DMediaPagingDevice::PagingRequest(*pL), LOCM_FAULT() ); |
|
2710 |
||
2711 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
2712 |
(pM->iValue==DMediaPagingDevice::ERomPageInRequest)?(countROM++):(countCode++); |
|
2713 |
if(pM==pL) |
|
2714 |
{ |
|
2715 |
NKern::FMWait(&pagingdevice->iInstrumentationLock); |
|
2716 |
if(pM->iValue==DMediaPagingDevice::ERomPageInRequest && pagingdevice->iROMStats.iMaxReqsInDeferred<countROM) |
|
2717 |
pagingdevice->iROMStats.iMaxReqsInDeferred=countROM; |
|
2718 |
else if ((pM->Flags() & TLocDrvRequest::ECodePaging) && pagingdevice->iCodeStats.iMaxReqsInDeferred<countCode) |
|
2719 |
pagingdevice->iCodeStats.iMaxReqsInDeferred=countCode; |
|
2720 |
else if ((pM->Flags() & TLocDrvRequest::EDataPaging) && pagingdevice->iDataStats.iMaxReqsInDeferred<countCode) |
|
2721 |
pagingdevice->iDataStats.iMaxReqsInDeferred=countCode; |
|
2722 |
NKern::FMSignal(&pagingdevice->iInstrumentationLock); |
|
2723 |
} |
|
2724 |
#endif |
|
2725 |
__KTRACE_OPT(KLOCDPAGING,Kern::Printf("RunDeferred: process req 0x%08x, last in deferred queue 0x%08x",pM,pL)); |
|
2726 |
#ifdef BTRACE_PAGING_MEDIA |
|
2727 |
BTraceContext8(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInDeferredReposted,pM,pM->iValue); |
|
2728 |
#endif |
|
2729 |
// if Page In requests are synchronous this services them all in sequence, |
|
2730 |
// if they're asynch it re-defers them |
|
2731 |
DoRequest(*(TLocDrvRequest*)pM); |
|
2732 |
} |
|
2733 |
pagingdevice->iEmptyingQ&= ~DMediaPagingDevice::EDeferredQ; |
|
2734 |
} |
|
2735 |
||
2736 |
// the reason we now try an empty the main Page In queue is there is at least one type of Page In request |
|
2737 |
// serviced synchronously in which case when we empty the deferred Page In queue as above, received Page In |
|
2738 |
// requests are left in the main queue (not deferred) and we don't want to start processing deferred normal |
|
2739 |
// requests before these Page In requests. If all deferred normal requests are synchronous, the received Page |
|
2740 |
// In requests will have to wait until all are serviced. NB: requests may be deferred even if the MD services |
|
2741 |
// all requests synchronously, but runs background tasks that cannot be interrupted. In this last case the |
|
2742 |
// normal deferred queue may have some very long latency requests. |
|
2743 |
if(pagingdevice->iEmptyingQ & DMediaPagingDevice::EMainQ) // already emptying main Page In queue, skip (any Page In requests will be deferred) |
|
2744 |
{ |
|
2745 |
__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Already emptying main queue")); |
|
2746 |
return; |
|
2747 |
} |
|
2748 |
||
2749 |
TLocDrvRequest* pM=NULL; |
|
2750 |
if (!pagingdevice->iMainQ.iReady) // if it's ready, then queue is empty |
|
2751 |
{ |
|
2752 |
pM = (TLocDrvRequest*) pagingdevice->iMainQ.iMessage; |
|
2753 |
pagingdevice->iMainQ.iMessage = NULL; |
|
2754 |
if (pM == NULL) |
|
2755 |
pM = (TLocDrvRequest*) pagingdevice->iMainQ.Poll(); |
|
2756 |
} |
|
2757 |
||
2758 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
2759 |
countROM = countCode=0; |
|
2760 |
#endif |
|
2761 |
if(pM) |
|
2762 |
{ |
|
2763 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
2764 |
__e32_atomic_add_ord32(&pagingdevice->iROMStats.iTotalSynchEmptiedMainQ, 1); |
|
2765 |
#endif |
|
2766 |
pagingdevice->iEmptyingQ|=DMediaPagingDevice::EMainQ; |
|
2767 |
for ( ; pM != NULL; pM = (TLocDrvRequest*) pagingdevice->iMainQ.Poll()) |
|
2768 |
{ |
|
2769 |
__ASSERT_ALWAYS(DMediaPagingDevice::PagingRequest(*pM), LOCM_FAULT()); |
|
2770 |
||
2771 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
2772 |
(pM->iValue==DMediaPagingDevice::ERomPageInRequest)?(countROM++):(countCode++); |
|
2773 |
#endif |
|
2774 |
||
2775 |
__KTRACE_OPT(KLOCDPAGING,Kern::Printf("RunDeferred: process req 0x%08x",pM)); |
|
2776 |
DoRequest(*(TLocDrvRequest*)pM); // if Page In requests are synchronous this services them all in sequence, if they're asynch it defers them |
|
2777 |
} |
|
2778 |
||
2779 |
pagingdevice->iEmptyingQ&= ~DMediaPagingDevice::EMainQ; |
|
2780 |
||
2781 |
||
2782 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
2783 |
NKern::FMWait(&pagingdevice->iInstrumentationLock); |
|
2784 |
pagingdevice->iROMStats.iTotalSynchServicedFromMainQ+=countROM; |
|
2785 |
if(pagingdevice->iROMStats.iMaxReqsInPending<countROM) |
|
2786 |
pagingdevice->iROMStats.iMaxReqsInPending=countROM; |
|
2787 |
pagingdevice->iCodeStats.iTotalSynchServicedFromMainQ+=countCode; |
|
2788 |
if(pagingdevice->iCodeStats.iMaxReqsInPending<countCode) |
|
2789 |
pagingdevice->iCodeStats.iMaxReqsInPending=countCode; |
|
2790 |
NKern::FMSignal(&pagingdevice->iInstrumentationLock); |
|
2791 |
#endif |
|
2792 |
} // if (pM) |
|
2793 |
} // if(iPagingMedia) |
|
2794 |
#endif |
|
2795 |
if (iRunningDeferred) |
|
2796 |
return; |
|
2797 |
TMessageBase* pL = iDeferred.Last(); |
|
2798 |
if (!pL) |
|
2799 |
return; // no deferred requests |
|
2800 |
iRunningDeferred=1; |
|
2801 |
TMessageBase* pM=NULL; |
|
2802 |
||
2803 |
while( pM != pL && (pM=iDeferred.Poll()) != NULL) // stop after processing last one (requests may be re-deferred) |
|
2804 |
DoRequest(*(TLocDrvRequest*)pM); |
|
2805 |
iRunningDeferred=0; |
|
2806 |
} |
|
2807 |
||
2808 |
void DPrimaryMediaBase::SetClosed(TInt anError) |
|
2809 |
{ |
|
2810 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::SetClosed error %d",iMediaId,anError)); |
|
2811 |
CHECK_RET(anError); |
|
2812 |
||
2813 |
// cancel DMediaDriver::OpenMediaDriverComplete() / DMediaDriver::PartitionInfoComplete() DFC |
|
2814 |
iAsyncDfc.Cancel(); |
|
2815 |
||
2816 |
iDeferred.CompleteAll(anError); |
|
2817 |
||
2818 |
#ifdef __DEMAND_PAGING__ |
|
2819 |
if(iPagingMedia) |
|
2820 |
iBody->iPagingDevice->iDeferredQ.CompleteAll(anError); |
|
2821 |
#endif |
|
2822 |
||
2823 |
CompleteCurrent(anError); |
|
2824 |
||
2825 |
||
2826 |
||
2827 |
if (iState==EOpening) |
|
2828 |
iPhysDevArray.Close(); |
|
2829 |
||
2830 |
iState = EClosed; |
|
2831 |
||
2832 |
iWaitMedChg.CompleteAll(KErrNone); |
|
2833 |
} |
|
2834 |
||
2835 |
void DPrimaryMediaBase::NotifyClients(TBool aMediaChange,TLocDrv* aLocDrv) |
|
2836 |
||
2837 |
// |
|
2838 |
// Notify all clients of a media change or power-down event |
|
2839 |
// |
|
2840 |
{ |
|
2841 |
SDblQueLink* pL=iConnectionQ.iA.iNext; |
|
2842 |
while (pL!=&iConnectionQ.iA) |
|
2843 |
{ |
|
2844 |
DLocalDrive* pD=_LOFF(pL,DLocalDrive,iLink); |
|
2845 |
// Issue the notification if the caller wants to notify all drives (aLocDrv == NULL) or |
|
2846 |
// the specified drive matches this one |
|
2847 |
if (aLocDrv == NULL || aLocDrv == pD->iDrive) |
|
2848 |
pD->NotifyChange(*this, aMediaChange); |
|
2849 |
pL=pL->iNext; |
|
2850 |
} |
|
2851 |
} |
|
2852 |
||
2853 |
EXPORT_C void DPrimaryMediaBase::NotifyMediaChange() |
|
2854 |
/** |
|
2855 |
Closes all media drivers on this device and notifies all connections that media change has occurred |
|
2856 |
and completes any outstanding requests with KErrNotReady. |
|
2857 |
This also completes any force media change requests with KErrNone. |
|
2858 |
*/ |
|
2859 |
{ |
|
2860 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::NotifyMediaChange state %d",iMediaId,iState)); |
|
2861 |
||
2862 |
TInt state=iState; |
|
2863 |
||
2864 |
__ASSERT_DEBUG(iBody, LOCM_FAULT()); |
|
2865 |
||
2866 |
#ifdef __DEMAND_PAGING__ |
|
2867 |
iBody->iMediaChanges++; |
|
2868 |
||
2869 |
// As data paging media never close, need to ensure the media driver cancels |
|
2870 |
// any requests it owns as the stack may be powered down by DPBusPrimaryMedia::ForceMediaChange(). |
|
2871 |
// DMediaDriver::NotifyPowerDown() should do this |
|
2872 |
if(DataPagingDfcQ(this)) |
|
2873 |
NotifyPowerDown(); |
|
2874 |
#endif |
|
2875 |
||
2876 |
// complete any outstanding requests with KErrNotReady |
|
2877 |
// and any force media change requests with KErrNone |
|
2878 |
SetClosed(KErrNotReady); |
|
2879 |
||
2880 |
// close all media drivers on this device |
|
2881 |
if (state>=EOpening) |
|
2882 |
{ |
|
2883 |
CloseMediaDrivers(); |
|
2884 |
} |
|
2885 |
||
2886 |
// notify all connections that media change has occurred |
|
2887 |
NotifyClients(ETrue); |
|
2888 |
||
2889 |
// complete any force media change requests |
|
2890 |
iWaitMedChg.CompleteAll(KErrNone); |
|
2891 |
} |
|
2892 |
||
2893 |
||
2894 |
EXPORT_C void DPrimaryMediaBase::NotifyPowerDown() |
|
2895 |
/** |
|
2896 |
Called on machine power-down. Notifies all media drivers on this device. |
|
2897 |
If device is not ready then it completes current requests but leaves other outstanding requests |
|
2898 |
If ready, media driver should complete current request. |
|
2899 |
||
2900 |
*/ |
|
2901 |
{ |
|
2902 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::NotifyPowerDown state %d",iMediaId,iState)); |
|
2903 |
||
2904 |
TInt id; |
|
2905 |
TBool allPersistent = ETrue; |
|
2906 |
TBool allOpen = ETrue; |
|
2907 |
||
2908 |
// notify all media drivers on this device |
|
2909 |
for (id=iMediaId; id<=iLastMediaId; id++) |
|
2910 |
{ |
|
2911 |
DMedia* pM = TheMedia[id]; |
|
2912 |
DMediaDriver* pD = pM->iDriver; |
|
2913 |
||
2914 |
if ((pD) && (iState==EReady || iState==EReadPartitionInfo || iState==EOpening || iState==EPoweringUp2 || iState==ERecovering)) |
|
2915 |
pD->NotifyPowerDown(); |
|
2916 |
||
2917 |
if (pD == NULL || pD->iPhysicalDevice == NULL) |
|
2918 |
allOpen = EFalse; |
|
2919 |
else if (pD->iPhysicalDevice->Info(DPhysicalDevice::EMediaDriverPersistent, NULL) != KErrNone) |
|
2920 |
{ |
|
2921 |
// We must NOT destroy the media driver if this media is responsible for data paging as |
|
2922 |
// re-opening the media driver would involve memory allocation which might cause a deadlock |
|
2923 |
#ifdef __DEMAND_PAGING__ |
|
2924 |
__ASSERT_ALWAYS(!DataPagingDfcQ(this), LOCM_FAULT()); |
|
2925 |
#endif |
|
2926 |
allPersistent = EFalse; |
|
2927 |
} |
|
2928 |
} |
|
2929 |
||
2930 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("allPersistent(%d)::allOpen %d",allPersistent, allOpen)); |
|
2931 |
||
2932 |
if (allPersistent && allOpen && iState == EReady) |
|
2933 |
{ |
|
2934 |
// |
|
2935 |
// The EPoweredDown state indicates that the media is powered down, but the media driver still exists. |
|
2936 |
// |
|
2937 |
// - This allows the media driver to still be accessed (ie - to determine driver capabilities) without |
|
2938 |
// the need to power up the device, which can be a lengthy operation. |
|
2939 |
// |
|
2940 |
// - NOTE : This will need re-visiting if we ever re-enable standby mode on a platform that is not capable |
|
2941 |
// of detecting door interrupts while in standby. In such a scenario, problems could occur as |
|
2942 |
// the device capabilities may change without the local media subsystem recognising. |
|
2943 |
// |
|
2944 |
iState=EPoweredDown; |
|
2945 |
} |
|
2946 |
else |
|
2947 |
{ |
|
2948 |
CloseMediaDrivers(); |
|
2949 |
SetClosed(KErrNotReady); |
|
2950 |
} |
|
2951 |
||
2952 |
NotifyClients(EFalse); |
|
2953 |
} |
|
2954 |
||
2955 |
||
2956 |
EXPORT_C void DPrimaryMediaBase::NotifyPsuFault(TInt anError) |
|
2957 |
/** |
|
2958 |
Closes all media drivers on this device and completes any outstanding requests with error code. |
|
2959 |
@param anError Error code to be passed on while closing media drivers and completing outstanding requests. |
|
2960 |
*/ |
|
2961 |
||
2962 |
{ |
|
2963 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::NotifyPsuFault state %d, err %d",iMediaId,iState,anError)); |
|
2964 |
||
2965 |
if (iState>=EOpening) |
|
2966 |
{ |
|
2967 |
CloseMediaDrivers(); |
|
2968 |
} |
|
2969 |
||
2970 |
// complete any outstanding requests with error |
|
2971 |
SetClosed(anError); |
|
2972 |
} |
|
2973 |
||
2974 |
EXPORT_C void DPrimaryMediaBase::NotifyEmergencyPowerDown() |
|
2975 |
/** |
|
2976 |
Called on emergency power down. Notifies all media drivers on this device. |
|
2977 |
If it is not in a ready state then it completes the current request but leaves other outstanding requests. |
|
2978 |
If it is ready then the media driver should complete the current request. |
|
2979 |
It closes all media drivers and notifies all clients of a power down event. |
|
2980 |
*/ |
|
2981 |
{ |
|
2982 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::NotifyEmergencyPowerDown state %d",iMediaId,iState)); |
|
2983 |
TBool recover=EFalse; |
|
2984 |
if (iState==EReady && iCritical!=0) |
|
2985 |
{ |
|
2986 |
// check if emergency power recovery supported |
|
2987 |
; |
|
2988 |
} |
|
2989 |
if (recover) |
|
2990 |
{ |
|
2991 |
} |
|
2992 |
||
2993 |
// else just return KErrAbort |
|
2994 |
// notify all media drivers on this device |
|
2995 |
if (iState==EReady || iState==EOpening || iState==EPoweringUp2 || iState==ERecovering) |
|
2996 |
{ |
|
2997 |
TInt id; |
|
2998 |
for (id=iMediaId; id<=iLastMediaId; id++) |
|
2999 |
{ |
|
3000 |
DMedia* pM=TheMedia[id]; |
|
3001 |
DMediaDriver* pD=pM->iDriver; |
|
3002 |
if (pD) |
|
3003 |
pD->NotifyEmergencyPowerDown(); |
|
3004 |
} |
|
3005 |
} |
|
3006 |
||
3007 |
if (iState!=EReady) |
|
3008 |
{ |
|
3009 |
// complete current request but leave other outstanding requests |
|
3010 |
// if ready, media driver should complete current request |
|
3011 |
CompleteCurrent(KErrNotReady); |
|
3012 |
} |
|
3013 |
CloseMediaDrivers(); |
|
3014 |
SetClosed(KErrNotReady); |
|
3015 |
NotifyClients(EFalse); |
|
3016 |
} |
|
3017 |
||
3018 |
EXPORT_C void DPrimaryMediaBase::NotifyMediaPresent() |
|
3019 |
/** |
|
3020 |
Notifies clients of a media change by calling NotifyClients ( ) function to indicate that media is present. |
|
3021 |
*/ |
|
3022 |
{ |
|
3023 |
NotifyClients(ETrue); |
|
3024 |
} |
|
3025 |
||
3026 |
EXPORT_C TInt DPrimaryMediaBase::DoInCritical() |
|
3027 |
/** |
|
3028 |
Flags the media driver as entering a critical part of its processing. |
|
3029 |
||
3030 |
In this context, critical means that the driver must be allowed to complete |
|
3031 |
its current activity. |
|
3032 |
For example, a request to power down the device must be deferred until |
|
3033 |
the driver exits the critical part. |
|
3034 |
||
3035 |
@return KErrNone, if the driver has been successfully flagged as being in |
|
3036 |
a critical part; otherwise, one of the other system-wide error codes. |
|
3037 |
The default implementation just returns KErrNone and can be overridden in the derived class |
|
3038 |
@see DPrimaryMediaBase::DoEndInCritical() |
|
3039 |
*/ |
|
3040 |
||
3041 |
{ |
|
3042 |
return KErrNone; |
|
3043 |
} |
|
3044 |
||
3045 |
EXPORT_C void DPrimaryMediaBase::DoEndInCritical() |
|
3046 |
/** |
|
3047 |
Flags the media driver as leaving a critical part of its processing. |
|
3048 |
||
3049 |
Default implementation does nothing |
|
3050 |
@see DPrimaryMediaBase::DoEndInCritical() |
|
3051 |
*/ |
|
3052 |
{ |
|
3053 |
} |
|
3054 |
||
3055 |
TInt DPrimaryMediaBase::InCritical() |
|
3056 |
{ |
|
3057 |
if (iCritical==0) |
|
3058 |
{ |
|
3059 |
TInt r=DoInCritical(); |
|
3060 |
if (r!=KErrNone) |
|
3061 |
return r; |
|
3062 |
} |
|
3063 |
++iCritical; |
|
3064 |
return KErrNone; |
|
3065 |
} |
|
3066 |
||
3067 |
void DPrimaryMediaBase::EndInCritical() |
|
3068 |
{ |
|
3069 |
if (--iCritical==0) |
|
3070 |
DoEndInCritical(); |
|
3071 |
} |
|
3072 |
||
3073 |
EXPORT_C void DPrimaryMediaBase::DeltaCurrentConsumption(TInt /*aCurrent*/) |
|
3074 |
/** |
|
3075 |
Sets the incremental value of current consumption to aCurrent. |
|
3076 |
The default implementation does nothing . |
|
3077 |
||
3078 |
@param aCurrent Delta Current in Milliamps |
|
3079 |
*/ |
|
3080 |
{ |
|
3081 |
// default implementation |
|
3082 |
} |
|
3083 |
||
3084 |
TInt DPrimaryMediaBase::OpenMediaDriver() |
|
3085 |
// |
|
3086 |
// Synchronous open for devices with no DFC queue (e.g. IRAM) |
|
3087 |
// |
|
3088 |
{ |
|
3089 |
__KTRACE_OPT(KLOCDRV,Kern::Printf(">DPrimaryMediaBase:OpenMediaDriver-%d",iMediaId)); |
|
3090 |
TVersion ver(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion); |
|
3091 |
||
3092 |
// Get a list of all currently loaded media drivers |
|
3093 |
// Most media drivers do not make use of the pointer iMountInfo.iInfo when |
|
3094 |
// their Validate() procedures are called from RPhysicalDeviceArray::GetDriverList(). |
|
3095 |
// However, a group of media drivers sharing the same id (passed in iDevice) may use |
|
3096 |
// the additional information pointed to by iMountInfo.iInfo to distinguish |
|
3097 |
// group members. This information is passed when the media driver is registered |
|
3098 |
// using LocDrv::RegisterMediaDevice(). |
|
3099 |
TInt r=iPhysDevArray.GetDriverList(KLitMediaDriverName,iDevice,iMountInfo.iInfo,ver); |
|
3100 |
if (r!=KErrNone) |
|
3101 |
return r; |
|
3102 |
||
3103 |
// Go through them starting with highest priority |
|
3104 |
TInt totalPartitions=0; |
|
3105 |
TInt c=iPhysDevArray.Count(); // can't be zero |
|
3106 |
TInt i=c-1; |
|
3107 |
r=KErrNotSupported; |
|
3108 |
for (iNextMediaId=iMediaId; i>=0 && iNextMediaId<=iLastMediaId && r!=KErrNotReady; i--) |
|
3109 |
{ |
|
3110 |
DPhysicalDevice* pD=iPhysDevArray[i].iPhysicalDevice; |
|
3111 |
DMediaDriver *pM=NULL; |
|
3112 |
||
3113 |
// try to open media driver |
|
3114 |
TInt s=pD->Create( (DBase*&)pM, iMediaId, NULL, ver); |
|
3115 |
||
3116 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("Media:Open-Opening %o(PRI:%d)-%d",pD,iPhysDevArray[i].iPriority,s)); |
|
3117 |
if (s!=KErrNone && pM) |
|
3118 |
{ |
|
3119 |
pM->Close(); |
|
3120 |
pM=NULL; |
|
3121 |
} |
|
3122 |
if (s==KErrNotReady) |
|
3123 |
{ |
|
3124 |
r=KErrNotReady; // If it isn't ready - nothing will open. |
|
3125 |
break; |
|
3126 |
} |
|
3127 |
if (s==KErrNoMemory) |
|
3128 |
{ |
|
3129 |
r=KErrNoMemory; // If we are out of memory, give up now |
|
3130 |
break; |
|
3131 |
} |
|
3132 |
if (s==KErrNone) |
|
3133 |
{ |
|
3134 |
// Found a media driver for this device - check for valid partitions. |
|
3135 |
DMedia* media=TheMedia[iNextMediaId]; |
|
3136 |
s=pM->PartitionInfo(media->iPartitionInfo); |
|
3137 |
if (s==KErrNone) |
|
3138 |
{ |
|
3139 |
r=KErrNone; |
|
3140 |
media->iDriver=pM; |
|
3141 |
pM->iPhysicalDevice=pD; |
|
3142 |
iPhysDevArray[i].iPhysicalDevice=NULL; // so it won't be closed when we tidy up |
|
3143 |
totalPartitions+=media->PartitionCount(); |
|
3144 |
} |
|
3145 |
else |
|
3146 |
pM->Close(); |
|
3147 |
} |
|
3148 |
} |
|
3149 |
||
3150 |
// we are now finished with media driver list |
|
3151 |
iPhysDevArray.Close(); |
|
3152 |
||
3153 |
// if driver opened OK, work out mapping of drives to partitions/media |
|
3154 |
if (r==KErrNone) |
|
3155 |
{ |
|
3156 |
TInt id=iMediaId; // start with primary media |
|
3157 |
TInt partitionsOnThisMedia=PartitionCount(); |
|
3158 |
TInt partition=0; |
|
3159 |
TInt j; |
|
3160 |
for (j=0; j<KMaxLocalDrives; j++) |
|
3161 |
{ |
|
3162 |
TLocDrv* pD=TheDrives[j]; |
|
3163 |
if (pD && pD->iPrimaryMedia==this) |
|
3164 |
{ |
|
3165 |
if (totalPartitions==0) |
|
3166 |
{ |
|
3167 |
pD->iMedia=NULL; |
|
3168 |
continue; |
|
3169 |
} |
|
3170 |
if (partition==partitionsOnThisMedia) |
|
3171 |
{ |
|
3172 |
id++; |
|
3173 |
partition=0; |
|
3174 |
partitionsOnThisMedia=TheMedia[id]->PartitionCount(); |
|
3175 |
} |
|
3176 |
pD->iMedia=TheMedia[id]; |
|
3177 |
pD->iPartitionNumber=partition; |
|
3178 |
memcpy(pD, pD->iMedia->iPartitionInfo.iEntry+partition, sizeof(TPartitionEntry)); |
|
3179 |
partition++; |
|
3180 |
totalPartitions--; |
|
3181 |
} |
|
3182 |
} |
|
3183 |
} |
|
3184 |
||
3185 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("<DPrimaryMediaBase:OpenMediaDriver-%d",r)); |
|
3186 |
return r; |
|
3187 |
} |
|
3188 |
||
3189 |
#ifdef __DEMAND_PAGING__ |
|
3190 |
// RequestCountInc() |
|
3191 |
// |
|
3192 |
// Counts the number of outstanding requests |
|
3193 |
// For data-paging media, calls DPagingDevice::NotifyBusy() when count goes positive |
|
3194 |
// |
|
3195 |
void DPrimaryMediaBase::RequestCountInc() |
|
3196 |
{ |
|
3197 |
__ASSERT_DEBUG(iBody, LOCM_FAULT()); |
|
3198 |
TInt oldVal = (TInt) __e32_atomic_add_ord32(&iBody->iRequestCount, (TUint) 1); |
|
3199 |
//Kern::Printf("RCINC: this %x cnt %d, old %d", this, iBody->iRequestCount, oldVal); |
|
3200 |
if (oldVal == 0 && iBody->iPagingDevice) |
|
3201 |
{ |
|
3202 |
//Kern::Printf("RCINC: NotifyBusy()"); |
|
3203 |
iBody->iPagingDevice->NotifyBusy(); |
|
3204 |
} |
|
3205 |
} |
|
3206 |
||
3207 |
// RequestCountDec() |
|
3208 |
// |
|
3209 |
// Counts the number of outstanding requests |
|
3210 |
// For data-paging media, calls DPagingDevice::NotifyIdle() when count reaches zero |
|
3211 |
// |
|
3212 |
void DPrimaryMediaBase::RequestCountDec() |
|
3213 |
{ |
|
3214 |
__ASSERT_DEBUG(iBody, LOCM_FAULT()); |
|
3215 |
TInt oldVal = (TInt) __e32_atomic_add_ord32(&iBody->iRequestCount, (TUint) -1); |
|
3216 |
//Kern::Printf("RCDEC: this %x cnt %d, old %d", this, iBody->iRequestCount, oldVal); |
|
3217 |
if (oldVal == 1 && iBody->iPagingDevice) |
|
3218 |
{ |
|
3219 |
//Kern::Printf("RCDEC: NotifyIdle()"); |
|
3220 |
iBody->iPagingDevice->NotifyIdle(); |
|
3221 |
} |
|
3222 |
__ASSERT_DEBUG(iBody->iRequestCount >= 0, LOCM_FAULT()); |
|
3223 |
} |
|
3224 |
#endif // __DEMAND_PAGING__ |
|
3225 |
||
3226 |
||
3227 |
TPartitionInfo::TPartitionInfo() |
|
3228 |
// |
|
3229 |
// Constructor |
|
3230 |
// |
|
3231 |
{ |
|
3232 |
memclr(this, sizeof(TPartitionInfo)); |
|
3233 |
} |
|
3234 |
||
3235 |
#ifdef __DEMAND_PAGING__ |
|
3236 |
||
3237 |
void pageInDfc(TAny* aPtr) |
|
3238 |
{ |
|
3239 |
__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("pageInDfc")); |
|
3240 |
DPrimaryMediaBase* primaryMedia=(DPrimaryMediaBase*)aPtr; |
|
3241 |
__ASSERT_ALWAYS(primaryMedia && primaryMedia->iPagingMedia && primaryMedia->iBody->iPagingDevice,LOCM_FAULT()); |
|
3242 |
DMediaPagingDevice* pagingdevice=primaryMedia->iBody->iPagingDevice; |
|
3243 |
||
3244 |
TLocDrvRequest* m = (TLocDrvRequest*) pagingdevice->iMainQ.iMessage; |
|
3245 |
pagingdevice->iMainQ.iMessage = NULL; |
|
3246 |
||
3247 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
3248 |
if (!m) |
|
3249 |
__e32_atomic_add_ord8(&pagingdevice->iROMStats.iTotalRunDry, 1); |
|
3250 |
#endif |
|
3251 |
||
3252 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
3253 |
TInt countROM=0; |
|
3254 |
TInt countCode=0; |
|
3255 |
#endif |
|
3256 |
||
3257 |
for ( ; m != NULL; m = (TLocDrvRequest*) pagingdevice->iMainQ.Poll()) |
|
3258 |
{ |
|
3259 |
__ASSERT_ALWAYS(DMediaPagingDevice::PagingRequest(*m), LOCM_FAULT()); |
|
3260 |
||
3261 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
3262 |
(m->iValue == DMediaPagingDevice::ERomPageInRequest)?(countROM++):(countCode++); |
|
3263 |
#endif |
|
3264 |
__KTRACE_OPT(KLOCDPAGING, Kern::Printf("pageInDfc: process request 0x%08x, last in queue 0x%08x",m, pagingdevice->iMainQ.Last()) ); |
|
3265 |
||
3266 |
primaryMedia->HandleMsg(*m); |
|
3267 |
} |
|
3268 |
||
3269 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
3270 |
NKern::FMWait(&pagingdevice->iInstrumentationLock); |
|
3271 |
if (pagingdevice->iROMStats.iMaxReqsInPending<countROM) |
|
3272 |
pagingdevice->iROMStats.iMaxReqsInPending=countROM; |
|
3273 |
if (pagingdevice->iCodeStats.iMaxReqsInPending<countCode) |
|
3274 |
pagingdevice->iCodeStats.iMaxReqsInPending=countCode; |
|
3275 |
NKern::FMSignal(&pagingdevice->iInstrumentationLock); |
|
3276 |
#endif |
|
3277 |
||
3278 |
pagingdevice->iMainQ.Receive(); // allow reception of more messages |
|
3279 |
} |
|
3280 |
||
3281 |
DMediaPagingDevice::DMediaPagingDevice(DPrimaryMediaBase* aPtr) |
|
3282 |
: iMainQ(pageInDfc, aPtr, NULL, KMaxDfcPriority), |
|
3283 |
iDeferredQ(NULL, NULL, NULL, 0), // callback never used |
|
3284 |
iEmptyingQ(NULL), |
|
3285 |
iInstrumentationLock() |
|
3286 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
3287 |
,iServicingROM(NULL), iServicingCode(NULL) |
|
3288 |
#endif |
|
3289 |
{ |
|
3290 |
iPrimaryMedia = aPtr; |
|
3291 |
if (iPrimaryMedia->iDfcQ) // media driver has its own thread |
|
3292 |
{ |
|
3293 |
iMainQ.SetDfcQ(iPrimaryMedia->iDfcQ); |
|
3294 |
} |
|
3295 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
3296 |
memclr((TAny*)&iROMStats,sizeof(SMediaROMPagingConcurrencyInfo)+sizeof(SMediaCodePagingConcurrencyInfo)); |
|
3297 |
#endif |
|
3298 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
|
3299 |
iROMBenchmarkData.iCount=iROMBenchmarkData.iTotalTime=iROMBenchmarkData.iMaxTime=0; |
|
3300 |
iROMBenchmarkData.iMinTime = KMaxTInt; |
|
3301 |
iCodeBenchmarkData.iCount=iCodeBenchmarkData.iTotalTime=iCodeBenchmarkData.iMaxTime=0; |
|
3302 |
iCodeBenchmarkData.iMinTime = KMaxTInt; |
|
3303 |
iDataInBenchmarkData.iCount=iDataInBenchmarkData.iTotalTime=iDataInBenchmarkData.iMaxTime=0; |
|
3304 |
iDataInBenchmarkData.iMinTime = KMaxTInt; |
|
3305 |
iDataOutBenchmarkData.iCount=iDataOutBenchmarkData.iTotalTime=iDataOutBenchmarkData.iMaxTime=0; |
|
3306 |
iDataOutBenchmarkData.iMinTime = KMaxTInt; |
|
3307 |
#endif |
|
3308 |
||
3309 |
iMainQ.Receive(); |
|
3310 |
} |
|
3311 |
||
3312 |
DMediaPagingDevice::~DMediaPagingDevice() |
|
3313 |
{ |
|
3314 |
||
3315 |
if (iMountInfoDataLock) |
|
3316 |
ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) iMountInfoDataLock); |
|
3317 |
||
3318 |
if (iMountInfoDescHdrLock) |
|
3319 |
ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) iMountInfoDescHdrLock); |
|
3320 |
||
3321 |
if (iMountInfoDescLenLock) |
|
3322 |
ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) iMountInfoDescLenLock); |
|
3323 |
} |
|
3324 |
||
3325 |
||
3326 |
void DMediaPagingDevice::SendToMainQueueDfcAndBlock(TThreadMessage* aMsg) |
|
3327 |
{ |
|
3328 |
__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("Send request 0x%08x to main queue",aMsg)); |
|
3329 |
__ASSERT_ALWAYS(aMsg->iState==TMessageBase::EFree,LOCM_FAULT()); // check that message was previously completed or never queued |
|
3330 |
||
3331 |
// if drive supports DMA, turn on Physical memory flag & sync memory |
|
3332 |
TLocDrvRequest& m=*(TLocDrvRequest*)(aMsg); |
|
3333 |
||
3334 |
TLinAddr addr = (TLinAddr) m.RemoteDes(); |
|
3335 |
TInt len = I64LOW(m.Length()); |
|
3336 |
||
3337 |
TBool needSyncAfterRead = EFalse; |
|
3338 |
if (m.Drive()->iDmaHelper) |
|
3339 |
{ |
|
3340 |
m.Flags() |= TLocDrvRequest::EPhysAddr; |
|
3341 |
if (m.Id() == DLocalDrive::EWrite) |
|
3342 |
{ |
|
3343 |
Cache::SyncMemoryBeforeDmaWrite(addr, len); |
|
3344 |
} |
|
3345 |
else |
|
3346 |
{ |
|
3347 |
Cache::SyncMemoryBeforeDmaRead(addr, len); |
|
3348 |
needSyncAfterRead = ETrue; |
|
3349 |
} |
|
3350 |
} |
|
3351 |
||
3352 |
// Count the number of outstanding requests if this is the data-paging media, so that |
|
3353 |
// we can call DPagingDevice::NotifyBusy() / DPagingDevice::NotifyIdle() |
|
3354 |
if ((m.Flags() & TLocDrvRequest::EBackgroundPaging) == 0) |
|
3355 |
iPrimaryMedia->RequestCountInc(); |
|
3356 |
||
3357 |
aMsg->SendReceive(&iMainQ); |
|
3358 |
||
3359 |
#ifdef __DEMAND_PAGING__ |
|
3360 |
if ((m.Flags() & TLocDrvRequest::EBackgroundPaging) == 0) |
|
3361 |
iPrimaryMedia->RequestCountDec(); |
|
3362 |
#endif |
|
3363 |
||
3364 |
if (needSyncAfterRead) |
|
3365 |
{ |
|
3366 |
Cache::SyncMemoryAfterDmaRead(addr, len); |
|
3367 |
} |
|
3368 |
||
3369 |
||
3370 |
// come back here when request is completed |
|
3371 |
__ASSERT_DEBUG(aMsg->iState==TMessageBase::EFree,LOCM_FAULT()); // check message has been completed |
|
3372 |
} |
|
3373 |
||
3374 |
void DMediaPagingDevice::SendToDeferredQ(TThreadMessage* aMsg) |
|
3375 |
{ |
|
3376 |
// This queue is only accessed from MD thread |
|
3377 |
__ASSERT_ALWAYS(aMsg->iState==TMessageBase::EAccepted,LOCM_FAULT()); // check that message was previously dequeued |
|
3378 |
#ifdef BTRACE_PAGING_MEDIA |
|
3379 |
if(iEmptyingQ&DMediaPagingDevice::EDeferredQ) // already deferring |
|
3380 |
BTraceContext8(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInReDeferred,aMsg,aMsg->iValue); |
|
3381 |
else |
|
3382 |
BTraceContext8(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInDeferred,aMsg,aMsg->iValue); |
|
3383 |
#endif |
|
3384 |
||
3385 |
aMsg->Forward(&iDeferredQ, EFalse); |
|
3386 |
} |
|
3387 |
||
3388 |
||
3389 |
void DMediaPagingDevice::CompleteRequest(TThreadMessage* aMsg, TInt aResult) |
|
3390 |
{ |
|
3391 |
__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DMediaPagingDevice::CompleteRequest, request 0x%08x result %d", aMsg, aResult)); |
|
3392 |
__ASSERT_DEBUG(aMsg->iState==TMessageBase::EAccepted,LOCM_FAULT()); |
|
3393 |
||
3394 |
#ifdef BTRACE_PAGING_MEDIA |
|
3395 |
BTraceContext12(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInPagedIn,aMsg,aResult,aMsg->iValue); |
|
3396 |
#endif |
|
3397 |
||
3398 |
iPrimaryMedia->CompleteRequest(*((TLocDrvRequest*) aMsg), aResult); |
|
3399 |
} |
|
3400 |
||
3401 |
TInt DMediaPagingDevice::Read(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize,TInt aDrvNumber) |
|
3402 |
{ |
|
3403 |
__ASSERT_ALWAYS(NKern::CurrentThread()!=iPrimaryMedia->iDfcQ->iThread,LOCM_FAULT()); // that would lock up the system, thus better die now |
|
3404 |
__ASSERT_ALWAYS(aReq,LOCM_FAULT()); |
|
3405 |
__ASSERT_CRITICAL |
|
3406 |
||
3407 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
|
3408 |
TUint32 bmStart = NKern::FastCounter(); |
|
3409 |
#endif |
|
3410 |
||
3411 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
3412 |
TUint8* servicingCount; |
|
3413 |
NKern::FMWait(&iInstrumentationLock); |
|
3414 |
if(aDrvNumber == EDriveRomPaging) // ROM paging |
|
3415 |
{ |
|
3416 |
servicingCount = &iServicingROM; |
|
3417 |
if(iServicingROM) |
|
3418 |
iROMStats.iTotalConcurrentReqs++; |
|
3419 |
if(!(++iServicingROM)) |
|
3420 |
{ |
|
3421 |
iServicingROM=1; // overflow... |
|
3422 |
iROMStats.iTotalConcurrentReqs=0; // ...reset this |
|
3423 |
} |
|
3424 |
TBool empty = iMainQ.iReady && iDeferredQ.iQ.IsEmpty(); |
|
3425 |
if(!empty) |
|
3426 |
iROMStats.iTotalReqIssuedNonEmptyQ++; |
|
3427 |
} |
|
3428 |
else if (aDrvNumber == EDriveDataPaging) // Data paging |
|
3429 |
{ |
|
3430 |
servicingCount = &iServicingDataIn; |
|
3431 |
if(iServicingDataIn) |
|
3432 |
iDataStats.iTotalConcurrentReqs++; |
|
3433 |
if(!(++iServicingDataIn)) |
|
3434 |
{ |
|
3435 |
iServicingDataIn=1; // overflow... |
|
3436 |
iDataStats.iTotalConcurrentReqs=0; // ...reset this |
|
3437 |
} |
|
3438 |
TBool empty = iMainQ.iReady && iDeferredQ.iQ.IsEmpty(); |
|
3439 |
if(!empty) |
|
3440 |
iDataStats.iTotalReqIssuedNonEmptyQ++; |
|
3441 |
} |
|
3442 |
else |
|
3443 |
{ |
|
3444 |
servicingCount = &iServicingCode; |
|
3445 |
if(iServicingCode) |
|
3446 |
iCodeStats.iTotalConcurrentReqs++; |
|
3447 |
if(!(++iServicingCode)) |
|
3448 |
{ |
|
3449 |
iServicingCode=1; // overflow... |
|
3450 |
iCodeStats.iTotalConcurrentReqs=0; // ...reset this |
|
3451 |
} |
|
3452 |
TBool empty = iMainQ.iReady && iDeferredQ.iQ.IsEmpty(); |
|
3453 |
if(!empty) |
|
3454 |
iCodeStats.iTotalReqIssuedNonEmptyQ++; |
|
3455 |
} |
|
3456 |
NKern::FMSignal(&iInstrumentationLock); |
|
3457 |
#endif |
|
3458 |
||
3459 |
TUint offset=aOffset<<iReadUnitShift; |
|
3460 |
TUint size=aSize<<iReadUnitShift; |
|
3461 |
||
3462 |
#ifdef BTRACE_PAGING_MEDIA |
|
3463 |
TInt buf[3]; |
|
3464 |
buf[0]=size; // page in request length |
|
3465 |
buf[1]=aDrvNumber; // local drive number (-1 if ROM) |
|
3466 |
buf[2]=(TInt)aReq; // address of request object |
|
3467 |
BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInBegin,aBuffer,offset,buf,sizeof(buf)); |
|
3468 |
#endif |
|
3469 |
||
3470 |
__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DMediaPagingDevice::Read, Req(0x%08x), Buff(0x%x),Offset(%d),Size(%d),DrvNo(%d)",aReq,aBuffer,offset,size,aDrvNumber)); |
|
3471 |
||
3472 |
// no DFCQ, media driver executes in the context of calling thread |
|
3473 |
if (!iPrimaryMedia->iDfcQ) |
|
3474 |
{ |
|
3475 |
LOCM_FAULT(); // don't allow paging |
|
3476 |
return KErrNone; // keep compiler happy |
|
3477 |
} |
|
3478 |
||
3479 |
||
3480 |
TLocDrvRequest& m=*(TLocDrvRequest*)(aReq); |
|
3481 |
||
3482 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
|
3483 |
SPagingBenchmarkInfo* info = NULL; |
|
3484 |
#endif |
|
3485 |
||
3486 |
||
3487 |
// Read from the media and allow for retries in the unlikely event of an error. |
|
3488 |
const TInt KPageInRetries = 5; |
|
3489 |
TInt retVal = KErrGeneral; |
|
3490 |
for (TInt i=0; retVal != KErrNone && i < KPageInRetries; i++) |
|
3491 |
{ |
|
3492 |
m.Flags() = TLocDrvRequest::EPaging; |
|
3493 |
TLocDrv* pL=NULL; |
|
3494 |
if(aDrvNumber == EDriveRomPaging) // ROM paging |
|
3495 |
{ |
|
3496 |
m.Id() = DMediaPagingDevice::ERomPageInRequest; |
|
3497 |
if (iRomPagingDriveNumber == KErrNotFound) |
|
3498 |
{ |
|
3499 |
// ROM partition has not been reported by the media driver |
|
3500 |
// it is assumed that the media driver will adjust the request accordingly |
|
3501 |
m.Flags() |= TLocDrvRequest::EAdjusted; |
|
3502 |
// Use a media drive number so the request reaches the correct media... |
|
3503 |
m.Drive() = TheDrives[iFirstLocalDriveNumber]; |
|
3504 |
} |
|
3505 |
else |
|
3506 |
{ |
|
3507 |
//ROM partition has been reported |
|
3508 |
//Set drive for use with CheckAndAdjustForPartition |
|
3509 |
m.Drive() = TheDrives[iRomPagingDriveNumber]; |
|
3510 |
} |
|
3511 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
|
3512 |
__e32_atomic_add_ord32(&iMediaPagingInfo.iRomPageInCount, (TUint) 1); |
|
3513 |
info = &iROMBenchmarkData; |
|
3514 |
#endif |
|
3515 |
} |
|
3516 |
else if(aDrvNumber == EDriveDataPaging) // Data paging |
|
3517 |
{ |
|
3518 |
m.Id() = DLocalDrive::ERead; |
|
3519 |
m.Flags() |= TLocDrvRequest::EDataPaging; |
|
3520 |
m.Drive() = TheDrives[iDataPagingDriveNumber]; |
|
3521 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
|
3522 |
__e32_atomic_add_ord32(&iMediaPagingInfo.iDataPageInCount, (TUint) 1); |
|
3523 |
info = &iDataInBenchmarkData; |
|
3524 |
#endif |
|
3525 |
} |
|
3526 |
else if ((aDrvNumber >=0) && (aDrvNumber<KMaxLocalDrives)) // Code paging |
|
3527 |
{ |
|
3528 |
m.Id() = DMediaPagingDevice::ECodePageInRequest; |
|
3529 |
m.Flags() |= TLocDrvRequest::ECodePaging; |
|
3530 |
pL=TheDrives[aDrvNumber]; |
|
3531 |
__ASSERT_DEBUG(pL&&(pL->iPrimaryMedia==iPrimaryMedia),LOCM_FAULT()); // valid drive number? |
|
3532 |
m.Drive()=pL; |
|
3533 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
|
3534 |
__e32_atomic_add_ord32(&iMediaPagingInfo.iCodePageInCount, (TUint) 1); |
|
3535 |
info = &iCodeBenchmarkData; |
|
3536 |
#endif |
|
3537 |
} |
|
3538 |
else |
|
3539 |
LOCM_FAULT(); // invalid drive number |
|
3540 |
||
3541 |
m.RemoteThread()=NULL; |
|
3542 |
m.Pos()=offset; |
|
3543 |
m.Length()=Int64(size); |
|
3544 |
m.RemoteDes()=(TAny*)aBuffer; |
|
3545 |
m.RemoteDesOffset()=0; // pre-aligned |
|
3546 |
m.DriverFlags()=0; |
|
3547 |
__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("ReqId=%d, Pos=0x%lx, Len=0x%lx, remote Des 0x%x",m.Id(),m.Pos(),m.Length(),m.RemoteDes())); |
|
3548 |
||
3549 |
__ASSERT_DEBUG(iPrimaryMedia->iBody, LOCM_FAULT()); |
|
3550 |
TInt mediaChanges = iPrimaryMedia->iBody->iMediaChanges; |
|
3551 |
||
3552 |
SendToMainQueueDfcAndBlock(&m); // queues request, sets and opens client thread, queues dfc and blocks thread until request is completed |
|
3553 |
retVal = m.iValue; |
|
3554 |
||
3555 |
#ifdef __DEBUG_DEMAND_PAGING__ |
|
3556 |
if (retVal != KErrNone) |
|
3557 |
Kern::Printf("Pagin Failure %d, retry %d", retVal, i); |
|
3558 |
#endif |
|
3559 |
||
3560 |
// reset retry count if there's ben a media change |
|
3561 |
if (retVal != KErrNone && mediaChanges != iPrimaryMedia->iBody->iMediaChanges) |
|
3562 |
i = 0; |
|
3563 |
} // for () |
|
3564 |
||
3565 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
3566 |
NKern::FMWait(&iInstrumentationLock); |
|
3567 |
if (*servicingCount) |
|
3568 |
(*servicingCount)--; |
|
3569 |
NKern::FMSignal(&iInstrumentationLock); |
|
3570 |
#endif |
|
3571 |
||
3572 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
|
3573 |
TUint32 bmEnd = NKern::FastCounter(); |
|
3574 |
++info->iCount; |
|
3575 |
#if !defined(HIGHIGH_RES_TIMER) || defined(HIGH_RES_TIMER_COUNTS_UP) |
|
3576 |
TInt64 elapsed=bmEnd-bmStart; |
|
3577 |
#else |
|
3578 |
TInt64 elapsed=bmStart-bmEnd; |
|
3579 |
#endif |
|
3580 |
info->iTotalTime += elapsed; |
|
3581 |
if (elapsed > info->iMaxTime) |
|
3582 |
info->iMaxTime = elapsed; |
|
3583 |
if (elapsed < info->iMinTime) |
|
3584 |
info->iMinTime = elapsed; |
|
3585 |
#endif // __DEMAND_PAGING_BENCHMARKS__ |
|
3586 |
||
3587 |
return retVal; |
|
3588 |
} |
|
3589 |
||
3590 |
TInt DMediaPagingDevice::Write(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize,TBool aBackground) |
|
3591 |
{ |
|
3592 |
__ASSERT_ALWAYS(NKern::CurrentThread()!=iPrimaryMedia->iDfcQ->iThread,LOCM_FAULT()); // that would lock up the system, thus better die now |
|
3593 |
__ASSERT_ALWAYS(aReq,LOCM_FAULT()); |
|
3594 |
__ASSERT_CRITICAL |
|
3595 |
||
3596 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
|
3597 |
TUint32 bmStart = NKern::FastCounter(); |
|
3598 |
#endif |
|
3599 |
||
3600 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
3601 |
NKern::FMWait(&iInstrumentationLock); |
|
3602 |
if(iServicingDataOut) |
|
3603 |
iDataStats.iTotalConcurrentReqs++; |
|
3604 |
if(!(++iServicingDataOut)) |
|
3605 |
{ |
|
3606 |
iServicingDataOut=1; // overflow... |
|
3607 |
iDataStats.iTotalConcurrentReqs=0; // ...reset this |
|
3608 |
} |
|
3609 |
TBool empty = iMainQ.iReady && iDeferredQ.iQ.IsEmpty(); |
|
3610 |
if(!empty) |
|
3611 |
iDataStats.iTotalReqIssuedNonEmptyQ++; |
|
3612 |
NKern::FMSignal(&iInstrumentationLock); |
|
3613 |
#endif |
|
3614 |
||
3615 |
TUint offset=aOffset<<iReadUnitShift; |
|
3616 |
TUint size=aSize<<iReadUnitShift; |
|
3617 |
||
3618 |
#ifdef BTRACE_PAGING_MEDIA |
|
3619 |
TInt buf[2]; |
|
3620 |
buf[0] = size; // page out request length |
|
3621 |
buf[1] = (TInt)aReq; // address of request object |
|
3622 |
BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageOutBegin,aBuffer,offset,buf,sizeof(buf)); |
|
3623 |
#endif |
|
3624 |
||
3625 |
__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DMediaPagingDevice::Write, Req(0x%08x), Buff(0x%x),Offset(%d),Size(%d)",aReq,aBuffer,offset,size)); |
|
3626 |
||
3627 |
// no DFCQ, media driver executes in the context of calling thread |
|
3628 |
if (!iPrimaryMedia->iDfcQ) |
|
3629 |
{ |
|
3630 |
LOCM_FAULT(); // don't allow paging |
|
3631 |
return KErrNone; // keep compiler happy |
|
3632 |
} |
|
3633 |
||
3634 |
||
3635 |
TLocDrvRequest& m=*(TLocDrvRequest*)(aReq); |
|
3636 |
||
3637 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
|
3638 |
__e32_atomic_add_ord32(&iMediaPagingInfo.iDataPageOutCount, (TUint) 1); |
|
3639 |
if (aBackground) |
|
3640 |
__e32_atomic_add_ord32(&iMediaPagingInfo.iDataPageOutBackgroundCount, (TUint) 1); |
|
3641 |
#endif |
|
3642 |
||
3643 |
// Write to the media and allow for retries in the unlikely event of an error. |
|
3644 |
const TInt KPageOutRetries = 5; |
|
3645 |
TInt retVal = KErrGeneral; |
|
3646 |
for (TInt i=0; retVal != KErrNone && i < KPageOutRetries; i++) |
|
3647 |
{ |
|
3648 |
m.Flags() = TLocDrvRequest::EPaging | TLocDrvRequest::EDataPaging | (aBackground ? TLocDrvRequest::EBackgroundPaging : 0); |
|
3649 |
||
3650 |
m.Id() = DLocalDrive::EWrite; |
|
3651 |
m.Drive() = TheDrives[iDataPagingDriveNumber]; |
|
3652 |
||
3653 |
m.RemoteThread()=NULL; |
|
3654 |
m.Pos()=offset; |
|
3655 |
m.Length()=Int64(size); |
|
3656 |
m.RemoteDes()=(TAny*)aBuffer; |
|
3657 |
m.RemoteDesOffset()=0; // pre-aligned |
|
3658 |
m.DriverFlags()=0; |
|
3659 |
__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("ReqId=%d, Pos=0x%lx, Len=0x%lx, remote Des 0x%x",m.Id(),m.Pos(),m.Length(),m.RemoteDes())); |
|
3660 |
||
3661 |
__ASSERT_DEBUG(iPrimaryMedia->iBody, LOCM_FAULT()); |
|
3662 |
TInt mediaChanges = iPrimaryMedia->iBody->iMediaChanges; |
|
3663 |
||
3664 |
SendToMainQueueDfcAndBlock(&m); // queues request, sets and opens client thread, queues dfc and blocks thread until request is completed |
|
3665 |
retVal = m.iValue; |
|
3666 |
||
3667 |
#ifdef __DEBUG_DEMAND_PAGING__ |
|
3668 |
if (retVal != KErrNone) |
|
3669 |
Kern::Printf("Pagout Failure %d, retry %d", retVal, i); |
|
3670 |
#endif |
|
3671 |
// reset retry count if there's ben a media change |
|
3672 |
if (retVal != KErrNone && mediaChanges != iPrimaryMedia->iBody->iMediaChanges) |
|
3673 |
i = 0; |
|
3674 |
} // for () |
|
3675 |
||
3676 |
#ifdef __CONCURRENT_PAGING_INSTRUMENTATION__ |
|
3677 |
NKern::FMWait(&iInstrumentationLock); |
|
3678 |
if (iServicingDataOut) |
|
3679 |
iServicingDataOut--; |
|
3680 |
NKern::FMSignal(&iInstrumentationLock); |
|
3681 |
#endif |
|
3682 |
||
3683 |
#ifdef __DEMAND_PAGING_BENCHMARKS__ |
|
3684 |
SPagingBenchmarkInfo& info = iDataOutBenchmarkData; |
|
3685 |
TUint32 bmEnd = NKern::FastCounter(); |
|
3686 |
++info.iCount; |
|
3687 |
#if !defined(HIGHIGH_RES_TIMER) || defined(HIGH_RES_TIMER_COUNTS_UP) |
|
3688 |
TInt64 elapsed=bmEnd-bmStart; |
|
3689 |
#else |
|
3690 |
TInt64 elapsed=bmStart-bmEnd; |
|
3691 |
#endif |
|
3692 |
info.iTotalTime += elapsed; |
|
3693 |
if (elapsed > info.iMaxTime) |
|
3694 |
info.iMaxTime = elapsed; |
|
3695 |
if (elapsed < info.iMinTime) |
|
3696 |
info.iMinTime = elapsed; |
|
3697 |
#endif // __DEMAND_PAGING_BENCHMARKS__ |
|
3698 |
||
3699 |
return retVal; |
|
3700 |
} |
|
3701 |
||
3702 |
||
3703 |
TInt DMediaPagingDevice::DeleteNotify(TThreadMessage* aReq,TUint aOffset,TUint aSize) |
|
3704 |
{ |
|
3705 |
if (iDeleteNotifyNotSupported) |
|
3706 |
return KErrNotSupported; |
|
3707 |
||
3708 |
__ASSERT_ALWAYS(NKern::CurrentThread()!=iPrimaryMedia->iDfcQ->iThread,LOCM_FAULT()); // that would lock up the system, thus better die now |
|
3709 |
__ASSERT_ALWAYS(aReq,LOCM_FAULT()); |
|
3710 |
__ASSERT_ALWAYS(DataPagingDfcQ(iPrimaryMedia),LOCM_FAULT()); |
|
3711 |
__ASSERT_CRITICAL |
|
3712 |
||
3713 |
TUint offset = aOffset<<iReadUnitShift; |
|
3714 |
TUint size = aSize<<iReadUnitShift; |
|
3715 |
||
3716 |
#ifdef BTRACE_PAGING_MEDIA |
|
3717 |
TInt buf[2]; |
|
3718 |
buf[0] = size; // delete notify length |
|
3719 |
buf[1] = (TInt)aReq; // address of request object |
|
3720 |
BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedDeleteNotifyBegin,NULL,offset,buf,sizeof(buf)); |
|
3721 |
#endif |
|
3722 |
||
3723 |
__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DMediaPagingDevice::Write, Req(0x%08x), Offset(%d),Size(%d)",aReq,offset,size)); |
|
3724 |
||
3725 |
// no DFCQ, media driver executes in the context of calling thread |
|
3726 |
if (!iPrimaryMedia->iDfcQ) |
|
3727 |
{ |
|
3728 |
LOCM_FAULT(); // don't allow paging |
|
3729 |
return KErrNone; // keep compiler happy |
|
3730 |
} |
|
3731 |
||
3732 |
TLocDrvRequest& m=*(TLocDrvRequest*)(aReq); |
|
3733 |
||
3734 |
||
3735 |
m.Flags() = TLocDrvRequest::EPaging | TLocDrvRequest::EDataPaging; |
|
3736 |
m.Id() = DLocalDrive::EDeleteNotify; |
|
3737 |
m.Drive() = TheDrives[iDataPagingDriveNumber]; |
|
3738 |
||
3739 |
m.RemoteThread() = NULL; |
|
3740 |
m.Pos() = offset; |
|
3741 |
m.Length() = Int64(size); |
|
3742 |
m.RemoteDes() = NULL; |
|
3743 |
m.RemoteDesOffset() = 0; // pre-aligned |
|
3744 |
m.DriverFlags()=0; |
|
3745 |
__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("ReqId=%d, Pos=0x%lx, Len=0x%lx, remote Des 0x%x",m.Id(),m.Pos(),m.Length(),m.RemoteDes())); |
|
3746 |
||
3747 |
||
3748 |
// send request aynchronously as we don't particularly care about the result |
|
3749 |
// and waiting would slow down the thread taking the page fault |
|
3750 |
iPrimaryMedia->RequestCountInc(); |
|
3751 |
||
3752 |
m.SendReceive(&iMainQ); // send request synchronously |
|
3753 |
||
3754 |
#ifdef __DEMAND_PAGING__ |
|
3755 |
iPrimaryMedia->RequestCountDec(); |
|
3756 |
#endif |
|
3757 |
||
3758 |
TInt retVal = m.iValue; |
|
3759 |
||
3760 |
if (retVal == KErrNotSupported) |
|
3761 |
iDeleteNotifyNotSupported = ETrue; |
|
3762 |
||
3763 |
return retVal; |
|
3764 |
} |
|
3765 |
||
3766 |
||
3767 |
||
3768 |
EXPORT_C TInt TLocDrvRequest::WriteToPageHandler(const TAny* aSrc, TInt aSize, TInt anOffset) |
|
3769 |
{ |
|
3770 |
#ifdef BTRACE_PAGING_MEDIA |
|
3771 |
TMediaDevice medDev=Drive()->iMedia->iDevice; |
|
3772 |
TInt buf[3]; |
|
3773 |
buf[0]=(TUint32)RemoteDes(); |
|
3774 |
buf[1]=anOffset; |
|
3775 |
buf[2]=aSize; |
|
3776 |
BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaMedDrvWriteBack,medDev,this,buf,sizeof(buf)); |
|
3777 |
#endif |
|
3778 |
__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("TLocDrvRequest::WriteToPageHandler, memcpy((aTrg)%08x, (aSrc)%08x, (aLength)%08x)",(TUint32)RemoteDes()+anOffset,aSrc,aSize)); |
|
3779 |
(void)memcpy((TAny*)((TUint32)RemoteDes()+anOffset), aSrc, aSize); // maybe in later versions this could be something else |
|
3780 |
return KErrNone; |
|
3781 |
} |
|
3782 |
||
3783 |
EXPORT_C TInt TLocDrvRequest::ReadFromPageHandler(TAny* aDst, TInt aSize, TInt anOffset) |
|
3784 |
{ |
|
3785 |
#ifdef BTRACE_PAGING_MEDIA |
|
3786 |
TMediaDevice medDev=Drive()->iMedia->iDevice; |
|
3787 |
TInt buf[3]; |
|
3788 |
buf[0]=(TUint32)RemoteDes(); |
|
3789 |
buf[1]=anOffset; |
|
3790 |
buf[2]=aSize; |
|
3791 |
BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaMedDrvRead,medDev,this,buf,sizeof(buf)); |
|
3792 |
#endif |
|
3793 |
__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("TLocDrvRequest::ReadFromPageHandler, memcpy((aDst)%08x, (aTrg)%08x, (aLength)%08x)",aDst,(TUint32)RemoteDes()+anOffset,aSize)); |
|
3794 |
(void)memcpy(aDst, (TAny*)((TUint32)RemoteDes()+anOffset), aSize); // maybe in later versions this could be something else |
|
3795 |
return KErrNone; |
|
3796 |
} |
|
3797 |
||
3798 |
_LIT(KLitFragmentationMutexName, "FRAGMENTATION_MUTEX"); |
|
3799 |
||
3800 |
TInt DFragmentationPagingLock::Construct(TUint aNumPages) |
|
3801 |
{ |
|
3802 |
TInt r=KErrNone; |
|
3803 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Fragmentation Lock: creating Mutex")); |
|
3804 |
r=Kern::MutexCreate(this->iFragmentationMutex, KLitFragmentationMutexName, KMutexOrdNone); |
|
3805 |
if (r!=KErrNone) |
|
3806 |
return r; |
|
3807 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Fragmentation Lock: Mutex created OK")); |
|
3808 |
||
3809 |
iFragmentGranularity = 0; |
|
3810 |
if (aNumPages == 0) |
|
3811 |
return KErrNone; |
|
3812 |
||
3813 |
// in CS |
|
3814 |
TInt pageSize=Kern::RoundToPageSize(1); |
|
3815 |
LockFragmentation(); |
|
3816 |
r=Alloc(pageSize*aNumPages); // alloc pages |
|
3817 |
UnlockFragmentation(); |
|
3818 |
||
3819 |
if(r==KErrNone) |
|
3820 |
{ |
|
3821 |
iFragmentGranularity = pageSize * aNumPages; |
|
3822 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Fragmentation granularity set to 0x%x", iFragmentGranularity)); |
|
3823 |
} |
|
3824 |
||
3825 |
return r; |
|
3826 |
} |
|
3827 |
||
3828 |
void DFragmentationPagingLock::Cleanup() |
|
3829 |
{ |
|
3830 |
// in CS |
|
3831 |
if (iFragmentationMutex) |
|
3832 |
{ |
|
3833 |
LockFragmentation(); |
|
3834 |
Free(); // at last! |
|
3835 |
UnlockFragmentation(); |
|
3836 |
Kern::SafeClose((DObject*&)iFragmentationMutex,NULL); |
|
3837 |
} |
|
3838 |
} |
|
3839 |
||
3840 |
#else |
|
3841 |
#if !defined(__WINS__) |
|
3842 |
EXPORT_C TInt TLocDrvRequest::WriteToPageHandler(const TAny* , TInt , TInt) |
|
3843 |
{ |
|
3844 |
return KErrNone; // stub for def file |
|
3845 |
} |
|
3846 |
#endif // __WINS__ |
|
3847 |
#endif //__DEMAND_PAGING__ |
|
3848 |
/******************************************** |
|
3849 |
* Media driver base class |
|
3850 |
********************************************/ |
|
3851 |
||
3852 |
||
3853 |
||
3854 |
||
3855 |
/** |
|
3856 |
Constructor. |
|
3857 |
||
3858 |
This is called, typically, by a derived class constructor in its ctor list. |
|
3859 |
||
3860 |
@param aMediaId The value of the unique media ID assigned when the media |
|
3861 |
driver is registered. |
|
3862 |
||
3863 |
@see LocDrv::RegisterMediaDevice() |
|
3864 |
*/ |
|
3865 |
EXPORT_C DMediaDriver::DMediaDriver(TInt aMediaId) |
|
3866 |
{ |
|
3867 |
// iPhysicalDevice=NULL; |
|
3868 |
// iTotalSizeInBytes=0; |
|
3869 |
// iCurrentConsumption=0; |
|
3870 |
// iPrimaryMedia=NULL; |
|
3871 |
// iCritical=EFalse; |
|
3872 |
iPrimaryMedia=(DPrimaryMediaBase*)TheMedia[aMediaId]; |
|
3873 |
} |
|
3874 |
||
3875 |
||
3876 |
||
3877 |
||
3878 |
/** |
|
3879 |
Destructor. |
|
3880 |
||
3881 |
Sets the device's current consumption to zero, and calls Close() on |
|
3882 |
the PDD factory object. |
|
3883 |
||
3884 |
@see DObject::Close() |
|
3885 |
*/ |
|
3886 |
EXPORT_C DMediaDriver::~DMediaDriver() |
|
3887 |
{ |
|
3888 |
SetCurrentConsumption(0); |
|
3889 |
Kern::SafeClose((DObject*&)iPhysicalDevice,NULL); |
|
3890 |
} |
|
3891 |
||
3892 |
||
3893 |
||
3894 |
||
3895 |
/** |
|
3896 |
Closes the media driver. |
|
3897 |
||
3898 |
This default implementation simply deletes this DMediaDriver object. |
|
3899 |
||
3900 |
Media drivers can provide their own implementation, which gives them |
|
3901 |
the opportunity to clean up resources before closure; for example, |
|
3902 |
cancelling a DFC. |
|
3903 |
Any replacement function must call this base class function as |
|
3904 |
the last instruction. |
|
3905 |
*/ |
|
3906 |
EXPORT_C void DMediaDriver::Close() |
|
3907 |
{ |
|
3908 |
delete this; |
|
3909 |
} |
|
3910 |
||
3911 |
||
3912 |
||
3913 |
||
3914 |
/** |
|
3915 |
Sets the total size of the media device. |
|
3916 |
||
3917 |
The function must be called by the media driver's implementation of PartitionInfo(). |
|
3918 |
||
3919 |
@param aTotalSizeInBytes The total size of the media, in bytes. |
|
3920 |
@param aLocDrv This is not used by media drivers; the class |
|
3921 |
definition provides a default value. |
|
3922 |
||
3923 |
@see DMediaDriver::PartitionInfo() |
|
3924 |
*/ |
|
3925 |
EXPORT_C void DMediaDriver::SetTotalSizeInBytes(Int64 aTotalSizeInBytes, TLocDrv* aLocDrv) |
|
3926 |
{ |
|
3927 |
iTotalSizeInBytes=aTotalSizeInBytes; |
|
3928 |
if (aLocDrv) |
|
3929 |
aLocDrv->iPartitionLen=aTotalSizeInBytes; |
|
3930 |
} |
|
3931 |
||
3932 |
||
3933 |
||
3934 |
||
3935 |
/** |
|
3936 |
Gets the total size of the media. |
|
3937 |
||
3938 |
@return The total size of the media, in bytes. |
|
3939 |
||
3940 |
@see DMediaDriver::SetTotalSizeInBytes() |
|
3941 |
*/ |
|
3942 |
EXPORT_C Int64 DMediaDriver::TotalSizeInBytes() |
|
3943 |
{ |
|
3944 |
return iTotalSizeInBytes; |
|
3945 |
} |
|
3946 |
||
3947 |
||
3948 |
||
3949 |
||
3950 |
/** |
|
3951 |
Flags the media driver as entering a critical part of its processing. |
|
3952 |
||
3953 |
In this context, critical means that the driver must be allowed to complete |
|
3954 |
its current activity. |
|
3955 |
For example, a request to power down the device must be deferred until |
|
3956 |
the driver exits the critical part. |
|
3957 |
||
3958 |
@return KErrNone, if the driver has been successfully flagged as being in |
|
3959 |
a critical part; otherwise, one of the other system-wide error codes. |
|
3960 |
||
3961 |
@see DMediaDriver::EndInCritical() |
|
3962 |
*/ |
|
3963 |
EXPORT_C TInt DMediaDriver::InCritical() |
|
3964 |
{ |
|
3965 |
if (!iCritical) |
|
3966 |
{ |
|
3967 |
TInt r=iPrimaryMedia->InCritical(); |
|
3968 |
if (r!=KErrNone) |
|
3969 |
return r; |
|
3970 |
iCritical=ETrue; |
|
3971 |
} |
|
3972 |
return KErrNone; |
|
3973 |
} |
|
3974 |
||
3975 |
||
3976 |
||
3977 |
||
3978 |
/** |
|
3979 |
Flags the media driver as leaving a critical part of its processing. |
|
3980 |
||
3981 |
@see DMediaDriver::InCritical() |
|
3982 |
*/ |
|
3983 |
EXPORT_C void DMediaDriver::EndInCritical() |
|
3984 |
{ |
|
3985 |
if (iCritical) |
|
3986 |
{ |
|
3987 |
iCritical=EFalse; |
|
3988 |
iPrimaryMedia->EndInCritical(); |
|
3989 |
} |
|
3990 |
} |
|
3991 |
||
3992 |
||
3993 |
||
3994 |
||
3995 |
/** |
|
3996 |
@internalComponent |
|
3997 |
*/ |
|
3998 |
EXPORT_C void DMediaDriver::SetCurrentConsumption(TInt aValue) |
|
3999 |
{ |
|
4000 |
TInt old = (TInt)__e32_atomic_swp_ord32(&iCurrentConsumption, aValue); |
|
4001 |
TInt delta = aValue - old; |
|
4002 |
iPrimaryMedia->DeltaCurrentConsumption(delta); |
|
4003 |
} |
|
4004 |
||
4005 |
||
4006 |
||
4007 |
||
4008 |
/** |
|
4009 |
Informs the media driver subsystem that an asynchronous request is complete. |
|
4010 |
||
4011 |
@param m The request that this call is completing. |
|
4012 |
@param aResult The return code for the asynchronous request. Typically, this |
|
4013 |
is KErrNone to report success, or one of the other system-wide |
|
4014 |
error codes to report failure or other problems. |
|
4015 |
*/ |
|
4016 |
EXPORT_C void DMediaDriver::Complete(TLocDrvRequest& m, TInt aResult) |
|
4017 |
{ |
|
4018 |
CHECK_RET(aResult); |
|
4019 |
#ifdef __DEMAND_PAGING__ |
|
4020 |
if (DMediaPagingDevice::PagingRequest(m)) |
|
4021 |
{ |
|
4022 |
__ASSERT_ALWAYS(iPrimaryMedia && iPrimaryMedia->iPagingMedia && iPrimaryMedia->iBody->iPagingDevice,LOCM_FAULT()); |
|
4023 |
__ASSERT_ALWAYS( ((m.Flags() & TLocDrvRequest::ECodePaging) == 0) || (m.Drive()->iPagingDrv), LOCM_FAULT()); |
|
4024 |
DMediaPagingDevice* pagingdevice = iPrimaryMedia->iBody->iPagingDevice; |
|
4025 |
pagingdevice->CompleteRequest(&m, aResult); |
|
4026 |
} |
|
4027 |
else |
|
4028 |
#endif |
|
4029 |
iPrimaryMedia->CompleteRequest(m, aResult); |
|
4030 |
||
4031 |
if (&m == iPrimaryMedia->iCurrentReq) // Complete() called on request serviced synchronously |
|
4032 |
iPrimaryMedia->iCurrentReq = NULL; |
|
4033 |
||
4034 |
iPrimaryMedia->RunDeferred(); |
|
4035 |
} |
|
4036 |
||
4037 |
||
4038 |
||
4039 |
||
4040 |
/** |
|
4041 |
Informs the media driver subsystem that the media driver is open |
|
4042 |
and has been initialised. |
|
4043 |
||
4044 |
This can be called from the PDD factory function Create(), if opening and |
|
4045 |
initialising the media driver is synchronous, otherwise it should be called by |
|
4046 |
the asynchronous media driver function that is responsible for opening and |
|
4047 |
initialising the driver. |
|
4048 |
||
4049 |
@param anError KErrNone if successful, otherwise one of the other system wide |
|
4050 |
error codes. |
|
4051 |
*/ |
|
4052 |
EXPORT_C void DMediaDriver::OpenMediaDriverComplete(TInt anError) |
|
4053 |
{ |
|
4054 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DMediaDriver::OpenMediaDriverComplete(%d) this %x iPrimaryMedia %x", anError, this, iPrimaryMedia)); |
|
4055 |
DPrimaryMediaBase* pM=iPrimaryMedia; |
|
4056 |
pM->iAsyncErrorCode=anError; |
|
4057 |
pM->iAsyncDfc.Enque(); |
|
4058 |
} |
|
4059 |
||
4060 |
||
4061 |
||
4062 |
||
4063 |
/** |
|
4064 |
Informs the media driver subsystem that the media driver has completed |
|
4065 |
the provision of partition information. |
|
4066 |
||
4067 |
The media driver provides partition information in its implementation |
|
4068 |
of PartitionInfo(). |
|
4069 |
||
4070 |
@param anError KErrNone if successful, otherwise one of the other system wide |
|
4071 |
error codes. |
|
4072 |
||
4073 |
@see DMediaDriver::PartitionInfo() |
|
4074 |
*/ |
|
4075 |
EXPORT_C void DMediaDriver::PartitionInfoComplete(TInt anError) |
|
4076 |
{ |
|
4077 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("DMediaDriver::PartitionInfoComplete(%d) anError %d this %x iPrimaryMedia %x", anError, this, iPrimaryMedia)); |
|
4078 |
DPrimaryMediaBase* pM=iPrimaryMedia; |
|
4079 |
pM->iAsyncErrorCode=anError; |
|
4080 |
pM->iAsyncDfc.Enque(); |
|
4081 |
} |
|
4082 |
||
4083 |
||
4084 |
||
4085 |
||
4086 |
/** |
|
4087 |
@internalComponent |
|
4088 |
*/ |
|
4089 |
// Default implementation |
|
4090 |
EXPORT_C void DMediaDriver::Disconnect(DLocalDrive* aLocalDrive, TThreadMessage* aMsg) |
|
4091 |
{ |
|
4092 |
// don't need to worry about DLocalDrive going away |
|
4093 |
aLocalDrive->Deque(); |
|
4094 |
||
4095 |
aMsg->Complete(KErrNone, EFalse); |
|
4096 |
} |
|
4097 |
||
4098 |
||
4099 |
||
4100 |
||
4101 |
/** |
|
4102 |
Registers a media driver with the Local Media Subsystem, and provides |
|
4103 |
information about the number of supported drives, partitions, |
|
4104 |
names and drive numbers. |
|
4105 |
||
4106 |
@param aDevice The unique Media ID for this device. |
|
4107 |
This can take one of the enumerated values defined |
|
4108 |
by the TMediaDevice enum. |
|
4109 |
@param aDriveCount Specifies the number of local drive objects to be assigned |
|
4110 |
to the media driver. Drives that support more than one |
|
4111 |
partition must specify a number greater than 1. |
|
4112 |
@param aDriveList A pointer to an array of TInt values, which define |
|
4113 |
the drive numbers that are to be allocated to each partition. |
|
4114 |
0 signifies Drive C, 1 signifies drive D, etc. For example, |
|
4115 |
to allocate drive letters J and K, specify an array |
|
4116 |
containing the values [7,8]. |
|
4117 |
Note that the size of this array must be the same as the value |
|
4118 |
specified by aDriveCount. |
|
4119 |
@param aPrimaryMedia A pointer to the primary DPrimaryMedia object to be |
|
4120 |
associated with the media. This object is responsible for |
|
4121 |
the overall state of the media, i.e. powering up, reading |
|
4122 |
partition information etc. It also has overall control over |
|
4123 |
all partitions as represented by the additional (aNumMedia-1) |
|
4124 |
DMedia objects. |
|
4125 |
@param aNumMedia Specifies the total number of DMedia objects to be |
|
4126 |
associated with the media driver. This number includes the |
|
4127 |
primary DPrimaryMedia object referred to by aPrimaryMedia, |
|
4128 |
plus all of the DMedia objects that are created for each |
|
4129 |
additional drive, and which hold basic information about |
|
4130 |
partitions. |
|
4131 |
@param aName The name of the media driver, for example: PCCard |
|
4132 |
||
4133 |
@return KErrNone, if successful; |
|
4134 |
KErrInUse, if a drive is already in use; |
|
4135 |
KErrNoMemory, if there is insufficient memory; |
|
4136 |
or one of the other system-wide error codes. |
|
4137 |
*/ |
|
4138 |
EXPORT_C TInt LocDrv::RegisterMediaDevice(TMediaDevice aDevice, TInt aDriveCount, const TInt* aDriveList, DPrimaryMediaBase* aPrimaryMedia, TInt aNumMedia, const TDesC& aName) |
|
4139 |
{ |
|
4140 |
// Create TLocDrv / DMedia objects to handle a media device |
|
4141 |
__KTRACE_OPT(KBOOT,Kern::Printf("RegisterMediaDevice %lS dev=%1d #drives=%d 1st=%d PM=%08x #media=%d",&aName,aDevice,aDriveCount,*aDriveList,aPrimaryMedia,aNumMedia)); |
|
4142 |
const TInt* p=aDriveList; |
|
4143 |
TInt i; |
|
4144 |
TInt r=0; |
|
4145 |
if (UsedMedia+aNumMedia>KMaxLocalDrives) |
|
4146 |
return KErrInUse; |
|
4147 |
for (i=0; i<aDriveCount; ++i) |
|
4148 |
{ |
|
4149 |
TInt drv = *p++; |
|
4150 |
// -1 means not used; this is to enable Dual-slot MMC support |
|
4151 |
if (drv == -1) |
|
4152 |
continue; |
|
4153 |
__KTRACE_OPT(KBOOT,Kern::Printf("Registering drive %d", drv)); |
|
4154 |
if (TheDrives[drv]) |
|
4155 |
{ |
|
4156 |
__KTRACE_OPT(KBOOT,Kern::Printf("Drive %d already in use", drv)); |
|
4157 |
return KErrInUse; |
|
4158 |
} |
|
4159 |
} |
|
4160 |
HBuf* pN=HBuf::New(aName); |
|
4161 |
if (!pN) |
|
4162 |
return KErrNoMemory; |
|
4163 |
TInt lastMedia=UsedMedia+aNumMedia-1; |
|
4164 |
for (i=UsedMedia; i<=lastMedia; ++i) |
|
4165 |
{ |
|
4166 |
if (i==UsedMedia) |
|
4167 |
TheMedia[i]=aPrimaryMedia; |
|
4168 |
else |
|
4169 |
TheMedia[i]=new DMedia; |
|
4170 |
if (!TheMedia[i]) |
|
4171 |
return KErrNoMemory; |
|
4172 |
r=TheMedia[i]->Create(aDevice,i,lastMedia); |
|
4173 |
__KTRACE_OPT(KBOOT,Kern::Printf("Media %d Create() returns %d",i,r)); |
|
4174 |
if (r!=KErrNone) |
|
4175 |
return r; |
|
4176 |
} |
|
4177 |
||
4178 |
__KTRACE_OPT(KBOOT,Kern::Printf("FirstMedia %d LastMedia %d",UsedMedia,lastMedia)); |
|
4179 |
UsedMedia+=aNumMedia; |
|
4180 |
p=aDriveList; |
|
4181 |
for (i=0; i<aDriveCount; ++i) |
|
4182 |
{ |
|
4183 |
TInt drv=*p++; |
|
4184 |
if (drv == -1) |
|
4185 |
continue; |
|
4186 |
TLocDrv* pL=new TLocDrv(drv); |
|
4187 |
if (!pL) |
|
4188 |
return KErrNoMemory; |
|
4189 |
TheDrives[drv]=pL; |
|
4190 |
DriveNames[drv]=pN; |
|
4191 |
pL->iPrimaryMedia=aPrimaryMedia; |
|
4192 |
__KTRACE_OPT(KBOOT,Kern::Printf("Drive %d: TLocDrv @ %08x",drv,pL)); |
|
4193 |
} |
|
4194 |
return KErrNone; |
|
4195 |
} |
|
4196 |
||
4197 |
||
4198 |
||
4199 |
||
4200 |
/** |
|
4201 |
A utility function that is used internally to register the specified |
|
4202 |
password store. |
|
4203 |
||
4204 |
The password store is used to save passwords for local media. |
|
4205 |
||
4206 |
@param aStore A pointer to the password store to be registered. |
|
4207 |
||
4208 |
@return KErrNone, if successful; |
|
4209 |
KErrAlreadyExists, if a password store has already been registered. |
|
4210 |
*/ |
|
4211 |
EXPORT_C TInt LocDrv::RegisterPasswordStore(TPasswordStore* aStore) |
|
4212 |
{ |
|
4213 |
// Create TLocDrv / DMedia objects to handle a media device |
|
4214 |
__KTRACE_OPT(KBOOT,Kern::Printf("RegisterPasswordStore")); |
|
4215 |
||
4216 |
TInt r = KErrNone; |
|
4217 |
||
4218 |
if(ThePasswordStore == NULL) |
|
4219 |
ThePasswordStore = aStore; |
|
4220 |
else |
|
4221 |
r = KErrAlreadyExists; |
|
4222 |
||
4223 |
return r; |
|
4224 |
} |
|
4225 |
||
4226 |
/** |
|
4227 |
Returns a pointer to the registered password store. |
|
4228 |
||
4229 |
The password store is used to save passwords for local media. |
|
4230 |
||
4231 |
@return A pointer to the registered password store. |
|
4232 |
*/ |
|
4233 |
EXPORT_C TPasswordStore* LocDrv::PasswordStore() |
|
4234 |
{ |
|
4235 |
return ThePasswordStore; |
|
4236 |
} |
|
4237 |
||
4238 |
||
4239 |
#ifdef __DEMAND_PAGING__ |
|
4240 |
/** |
|
4241 |
Registers a paging device with the Local Media Subsystem, and provides |
|
4242 |
information about drive numbers used in Code Paging. |
|
4243 |
||
4244 |
@param aPrimaryMedia A pointer to the primary DPrimaryMedia object associated |
|
4245 |
with the media. |
|
4246 |
@param aPagingDriveList A pointer to an array of TInt values, which define |
|
4247 |
the drive numbers used as Code backup in Code Paging, which |
|
4248 |
are the target of Page In requests. For NAND these will |
|
4249 |
will be usually associated with ROFS and/or User Data drives. |
|
4250 |
In ROM pagigng systems no drive is specified, it is assumed |
|
4251 |
a fixed media for which no non-primary media exists, will be |
|
4252 |
used. |
|
4253 |
@param aDriveCount Specifies the number of local drives associated with this |
|
4254 |
media device which can be used for code paging. |
|
4255 |
@param aPagingType Identifies the type of Paging this media device is capable |
|
4256 |
of servicing. |
|
4257 |
@param aReadShift Log2 of the read unit size. A read unit is the number of bytes |
|
4258 |
which the device can optimally read from the underlying media. |
|
4259 |
E.g. for small block NAND, a read unit would be equal to the |
|
4260 |
page size, 512 bytes, therefore iReadShift would be set to 9. |
|
4261 |
@param aNumPages The number of pages to alloc for each drive associated with this |
|
4262 |
media driver. The pages are used in request fragmentation. |
|
4263 |
||
4264 |
@return KErrNone, if successful; |
|
4265 |
KErrNotFound, if at least one of the drive numbers |
|
4266 |
specified has not yet been mapped. |
|
4267 |
KErrArgument, if the passed in an invalid argument. |
|
4268 |
KErrNotSupported, if at least one of the drive numbers |
|
4269 |
specifed is not associated with this Primary Media. |
|
4270 |
KErrNoMemory, if there is insufficient memory; |
|
4271 |
or one of the other system-wide error codes. |
|
4272 |
*/ |
|
4273 |
EXPORT_C TInt LocDrv::RegisterPagingDevice(DPrimaryMediaBase* aPrimaryMedia, const TInt* aPagingDriveList, TInt aDriveCount, TUint aPagingType, TInt aReadShift, TUint aNumPages) |
|
4274 |
{ |
|
4275 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf(">RegisterPagingDevice: paging type=%d PM=0x%x read shift=%d",aPagingType,aPrimaryMedia,aReadShift)); |
|
4276 |
TInt i; |
|
4277 |
||
4278 |
if(!aPagingType || (aPagingType&~(DPagingDevice::ERom | DPagingDevice::ECode | DPagingDevice::EData))) |
|
4279 |
{ |
|
4280 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Unsupported paging type, exiting")); |
|
4281 |
return KErrArgument; |
|
4282 |
} |
|
4283 |
||
4284 |
||
4285 |
||
4286 |
for(i=0; i<KMaxLocalDrives; i++) |
|
4287 |
{ |
|
4288 |
if (ThePagingDevices[i] == NULL) |
|
4289 |
continue; |
|
4290 |
if ((ThePagingDevices[i]->iType&DPagingDevice::ERom) && (aPagingType & DPagingDevice::ERom)) |
|
4291 |
{ |
|
4292 |
aPagingType&=~DPagingDevice::ERom; // already have a ROM paging device |
|
4293 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Already has ROM pager on locdrv no %d",i)); |
|
4294 |
} |
|
4295 |
if ((ThePagingDevices[i]->iType&DPagingDevice::EData) && (aPagingType & DPagingDevice::EData)) |
|
4296 |
{ |
|
4297 |
aPagingType&=~DPagingDevice::EData; // already have a Data paging device |
|
4298 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Already has Data pager on locdrv no %d",i)); |
|
4299 |
} |
|
4300 |
} |
|
4301 |
||
4302 |
||
4303 |
if (aPagingType == 0) |
|
4304 |
{ |
|
4305 |
// there's already a ROM or Data paging device & this doesn't support code paging so quietly exit without further addo |
|
4306 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Nothing left to register on locdrv no %d, exiting",i)); |
|
4307 |
return KErrNone; |
|
4308 |
} |
|
4309 |
||
4310 |
const TInt* p=aPagingDriveList; |
|
4311 |
if(aPagingType&DPagingDevice::ECode) // supports code paging, do argument check |
|
4312 |
{ |
|
4313 |
if(!aDriveCount || (aDriveCount>=KMaxLocalDrives)) |
|
4314 |
{ |
|
4315 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Invalid code paging drive count: %d", aDriveCount)); |
|
4316 |
return KErrArgument; |
|
4317 |
} |
|
4318 |
||
4319 |
TInt drvCount=0; |
|
4320 |
for(i=0; i<KMaxLocalDrives; i++) |
|
4321 |
if(TheDrives[i] && TheDrives[i]->iPrimaryMedia==aPrimaryMedia) |
|
4322 |
drvCount++; |
|
4323 |
if(aDriveCount>drvCount) // can't exceed number of drives registered by this device |
|
4324 |
{ |
|
4325 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Invalid code paging drive count: %d total %d", aDriveCount, drvCount)); |
|
4326 |
return KErrArgument; |
|
4327 |
} |
|
4328 |
||
4329 |
for (i=0; i<aDriveCount; ++i) |
|
4330 |
{ |
|
4331 |
__KTRACE_OPT(KBOOT,Kern::Printf("RegisterPagingDevice: registering drive=%d ",*p)); |
|
4332 |
TInt drv=*p++; |
|
4333 |
if(drv>=KMaxLocalDrives) |
|
4334 |
{ |
|
4335 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Invalid code paging drive number: %d", drv)); |
|
4336 |
return KErrArgument; |
|
4337 |
} |
|
4338 |
TLocDrv* pD=TheDrives[drv]; |
|
4339 |
if (!pD) |
|
4340 |
return KErrNotFound; |
|
4341 |
if (pD->iPrimaryMedia!=aPrimaryMedia) |
|
4342 |
return KErrNotSupported; |
|
4343 |
} |
|
4344 |
} |
|
4345 |
||
4346 |
||
4347 |
TInt firstLocalDriveNumber = KErrNotFound; |
|
4348 |
TInt romPagingDriveNumber = KErrNotFound; |
|
4349 |
||
4350 |
TInt dataPagingDriveNumber = KErrNotFound; |
|
4351 |
TInt swapSize = 0; |
|
4352 |
||
4353 |
// find the local drive assocated with the primary media |
|
4354 |
for (i=0; i<KMaxLocalDrives; ++i) |
|
4355 |
{ |
|
4356 |
if(TheDrives[i] && TheDrives[i]->iPrimaryMedia == aPrimaryMedia) |
|
4357 |
{ |
|
4358 |
firstLocalDriveNumber = i; |
|
4359 |
break; |
|
4360 |
} |
|
4361 |
} |
|
4362 |
__ASSERT_ALWAYS(i < KMaxLocalDrives, LOCM_FAULT()); |
|
4363 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("DMediaPagingDevice(), firstLocalDriveNumber %d", firstLocalDriveNumber)); |
|
4364 |
||
4365 |
||
4366 |
// Send an ECaps message to wake up the media driver & ensure all partitions are |
|
4367 |
// reported, then search for paged-data or paged-ROM partitions |
|
4368 |
if ((aPagingType & DPagingDevice::EData) || |
|
4369 |
(aPagingType & DPagingDevice::ERom && aPrimaryMedia->iDfcQ && aPrimaryMedia->iMsgQ.iReady)) |
|
4370 |
{ |
|
4371 |
// the message queue must have been started already (by the media driver calling iMsgQ.Receive()) |
|
4372 |
// otherwise we can't send the DLocalDrive::EQueryDevice request |
|
4373 |
if (aPrimaryMedia->iDfcQ && !aPrimaryMedia->iMsgQ.iReady) |
|
4374 |
{ |
|
4375 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: Message queue not started")); |
|
4376 |
return KErrNotReady; |
|
4377 |
} |
|
4378 |
||
4379 |
||
4380 |
TLocDrvRequest m; |
|
4381 |
memclr(&m, sizeof(m)); |
|
4382 |
||
4383 |
||
4384 |
// Get the Caps from the device. NB for MMC/SD we may need to retry as some PSLs start up |
|
4385 |
// in "door open" or "media not present" state which can result in the cancellation of requests |
|
4386 |
TInt i; |
|
4387 |
const TInt KRetries = 5; |
|
4388 |
TInt r = KErrNotReady; |
|
4389 |
for (i=0; r == KErrNotReady && i < KRetries; i++) |
|
4390 |
{ |
|
4391 |
TBuf8<KMaxLocalDriveCapsLength> capsBuf; |
|
4392 |
capsBuf.SetMax(); |
|
4393 |
capsBuf.FillZ(); |
|
4394 |
m.Drive() = TheDrives[firstLocalDriveNumber]; |
|
4395 |
m.Id() = DLocalDrive::ECaps; |
|
4396 |
m.RemoteDes() = (TAny*)capsBuf.Ptr(); // overload this |
|
4397 |
m.Length() = KMaxLocalDriveCapsLength; // for pinning |
|
4398 |
r = aPrimaryMedia->Request(m); |
|
4399 |
||
4400 |
//Kern::Printf("EQueryPageDeviceInfo: i %d: r %d ", i, r); |
|
4401 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("Paging device ECaps: i %d: r %d ", i, r)); |
|
4402 |
} |
|
4403 |
||
4404 |
if (r != KErrNone) |
|
4405 |
return r; |
|
4406 |
||
4407 |
TLocDrv* drive; |
|
4408 |
for (i=0; i<KMaxLocalDrives; ++i) |
|
4409 |
{ |
|
4410 |
drive = TheDrives[i]; |
|
4411 |
if(drive && drive->iPrimaryMedia == aPrimaryMedia) |
|
4412 |
{ |
|
4413 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("RegisterPagingDevice: local drive %d, partition type %x size %x", i, drive->iPartitionType, I64LOW(drive->iPartitionLen))); |
|
4414 |
// ROM partition ? |
|
4415 |
if ((romPagingDriveNumber == KErrNotFound) && (drive->iPartitionType == KPartitionTypeROM)) |
|
4416 |
{ |
|
4417 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("Found ROM partition on local drive %d, size %x", i, I64LOW(drive->iPartitionLen))); |
|
4418 |
romPagingDriveNumber = i; |
|
4419 |
} |
|
4420 |
// swap partition ? |
|
4421 |
else if ((dataPagingDriveNumber == KErrNotFound) && (drive->iPartitionType == KPartitionTypePagedData)) |
|
4422 |
{ |
|
4423 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("Found swap partition on local drive %d, size %x", i, I64LOW(drive->iPartitionLen))); |
|
4424 |
dataPagingDriveNumber = i; |
|
4425 |
swapSize = drive->iPartitionLen >> aReadShift; |
|
4426 |
} |
|
4427 |
} |
|
4428 |
} |
|
4429 |
||
4430 |
if (swapSize == 0) |
|
4431 |
{ |
|
4432 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("Disabling data paging")); |
|
4433 |
aPagingType &= ~DPagingDevice::EData; |
|
4434 |
} |
|
4435 |
||
4436 |
} |
|
4437 |
||
4438 |
||
4439 |
// create and set up a DPagingDevice to allow PageIn request servicing |
|
4440 |
DMediaPagingDevice* pagingDevice = new DMediaPagingDevice(aPrimaryMedia); |
|
4441 |
if(!pagingDevice) |
|
4442 |
{ |
|
4443 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: could not create paging device")); |
|
4444 |
return KErrNoMemory; |
|
4445 |
} |
|
4446 |
||
4447 |
pagingDevice->iType = aPagingType; |
|
4448 |
pagingDevice->iReadUnitShift = aReadShift; |
|
4449 |
||
4450 |
pagingDevice->iFirstLocalDriveNumber = firstLocalDriveNumber; |
|
4451 |
pagingDevice->iRomPagingDriveNumber = romPagingDriveNumber; |
|
4452 |
||
4453 |
pagingDevice->iDataPagingDriveNumber = dataPagingDriveNumber; |
|
4454 |
pagingDevice->iSwapSize = swapSize; |
|
4455 |
||
4456 |
#ifdef __DEBUG_DEMAND_PAGING__ |
|
4457 |
Kern::Printf("PagingDevice :"); |
|
4458 |
Kern::Printf("iType 0x%x\n", pagingDevice->iType); |
|
4459 |
Kern::Printf("iReadUnitShift 0x%x\n", pagingDevice->iReadUnitShift); |
|
4460 |
Kern::Printf("iFirstLocalDriveNumber 0x%x\n", pagingDevice->iFirstLocalDriveNumber); |
|
4461 |
Kern::Printf("iRomPagingDriveNumber 0x%x\n", pagingDevice->iRomPagingDriveNumber); |
|
4462 |
Kern::Printf("iDataPagingDriveNumber 0x%x\n", pagingDevice->iDataPagingDriveNumber); |
|
4463 |
Kern::Printf("iSwapSize 0x%x\n", pagingDevice->iSwapSize); |
|
4464 |
#endif |
|
4465 |
||
4466 |
||
4467 |
// This table is indexed by DPagingDevice::TType |
|
4468 |
const char* DeviceName[] = |
|
4469 |
{ |
|
4470 |
"Error", |
|
4471 |
"RomPagingDevice", |
|
4472 |
"CodePagingDevice", |
|
4473 |
"RomAndCodePagingDevice", |
|
4474 |
"DataPagingDevice", |
|
4475 |
"RomAndDataPagingDevice", |
|
4476 |
"CodeAndDataPagingDevice", |
|
4477 |
"RomAndCodeAndDataPagingDevice" |
|
4478 |
}; |
|
4479 |
||
4480 |
||
4481 |
if(aPagingType & DPagingDevice::ECode) |
|
4482 |
{ |
|
4483 |
for (i=0; i<aDriveCount; ++i) |
|
4484 |
pagingDevice->iDrivesSupported|=(0x1<<aPagingDriveList[i]); |
|
4485 |
} |
|
4486 |
pagingDevice->iName = DeviceName[aPagingType]; |
|
4487 |
||
4488 |
if (ThePinObjectAllocator == NULL) |
|
4489 |
ThePinObjectAllocator = new DPinObjectAllocator(); |
|
4490 |
if(!ThePinObjectAllocator) |
|
4491 |
{ |
|
4492 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: could not create ThePinObjectAllocator")); |
|
4493 |
return KErrNoMemory; |
|
4494 |
} |
|
4495 |
TInt r = ThePinObjectAllocator->Construct(KDynamicPagingLockCount, aNumPages); |
|
4496 |
if (r != KErrNone) |
|
4497 |
{ |
|
4498 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: could not construct ThePinObjectAllocator")); |
|
4499 |
return r; |
|
4500 |
} |
|
4501 |
||
4502 |
||
4503 |
// Register our DPagingDevice with the Kernel |
|
4504 |
r=Kern::InstallPagingDevice(pagingDevice); |
|
4505 |
||
4506 |
#ifdef __DEBUG_DEMAND_PAGING__ |
|
4507 |
Kern::Printf("Kern::InstallPagingDevice() r %d", r); |
|
4508 |
#endif |
|
4509 |
||
4510 |
if (r!=KErrNone) |
|
4511 |
{ |
|
4512 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: could not install paging device")); |
|
4513 |
delete pagingDevice; |
|
4514 |
return r; |
|
4515 |
} |
|
4516 |
||
4517 |
// all hunky dory, save paging device and mark our media as pageable |
|
4518 |
ThePagingDevices[aPrimaryMedia->iMediaId] = pagingDevice; // association created between PrimaryMedia and PagingDevice via iMediaId |
|
4519 |
aPrimaryMedia->iPagingMedia = 1; |
|
4520 |
||
4521 |
// mark our drives as pageable |
|
4522 |
p=aPagingDriveList; |
|
4523 |
if (aPagingType&DPagingDevice::ECode) |
|
4524 |
{ |
|
4525 |
for (i=0; i<aDriveCount; ++i) |
|
4526 |
{ |
|
4527 |
TLocDrv* pD=TheDrives[*p++]; |
|
4528 |
pD->iPagingDrv=1; |
|
4529 |
} |
|
4530 |
} |
|
4531 |
||
4532 |
// Flags to indicate that a paging device is registered and pinning of user requests may be required |
|
4533 |
aPrimaryMedia->iPagingMedia = 1; |
|
4534 |
||
4535 |
// point the primary media to the paging device |
|
4536 |
aPrimaryMedia->iBody->iPagingDevice = pagingDevice; |
|
4537 |
||
4538 |
if (aPagingType & DPagingDevice::ERom) |
|
4539 |
{ |
|
4540 |
aPrimaryMedia->iRomPagingMedia = 1; |
|
4541 |
TheRomPagingMedia = aPrimaryMedia; |
|
4542 |
} |
|
4543 |
||
4544 |
// Is data paging enabled in this ROM ? |
|
4545 |
TInt memModelAttributes = Kern::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL); |
|
4546 |
TBool dataPagingSupported = memModelAttributes & EMemModelAttrDataPaging; |
|
4547 |
#ifdef __DEBUG_DEMAND_PAGING__ |
|
4548 |
Kern::Printf("memModelAttributes %08X", memModelAttributes); |
|
4549 |
Kern::Printf("DataPagingSupported %d", dataPagingSupported); |
|
4550 |
#endif |
|
4551 |
if (!dataPagingSupported) |
|
4552 |
{ |
|
4553 |
#ifdef __DEBUG_DEMAND_PAGING__ |
|
4554 |
if (aPagingType & DPagingDevice::EData) |
|
4555 |
Kern::Printf("Disabling data paging, not supported in this ROM"); |
|
4556 |
#endif |
|
4557 |
aPagingType&= ~DPagingDevice::EData; |
|
4558 |
} |
|
4559 |
||
4560 |
||
4561 |
if (aPagingType & DPagingDevice::EData) |
|
4562 |
{ |
|
4563 |
DataPagingDeviceRegistered = ETrue; |
|
4564 |
aPrimaryMedia->iDataPagingMedia = 1; |
|
4565 |
TheDataPagingMedia = aPrimaryMedia; |
|
4566 |
} |
|
4567 |
||
4568 |
__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("<RegisterPagingDevice")); |
|
4569 |
return KErrNone; |
|
4570 |
} |
|
4571 |
||
4572 |
#else //__DEMAND_PAGING__ |
|
4573 |
||
4574 |
#if !defined(__WINS__) |
|
4575 |
EXPORT_C TInt LocDrv::RegisterPagingDevice(DPrimaryMediaBase* , const TInt* , TInt , TUint , TInt , TUint ) |
|
4576 |
{ |
|
4577 |
return KErrNotSupported; |
|
4578 |
} // stub for def file |
|
4579 |
#endif // __WINS__ |
|
4580 |
||
4581 |
#endif //__DEMAND_PAGING__ |
|
4582 |
||
4583 |
||
4584 |
/** |
|
4585 |
Registers a media device with physical memory addressing capabilities with the |
|
4586 |
Local Media Subsystem. |
|
4587 |
||
4588 |
@param aPrimaryMedia A pointer to the primary DPrimaryMedia object associated |
|
4589 |
with the media device. |
|
4590 |
@param aMediaBlockSize The Minimum transfer size (bytes) for the media device. |
|
4591 |
@param aDmaMaxAddressable The Maximum Addressing Range for the media device's DMA controller, 0 if None. |
|
4592 |
@param aDmaAlignment The required memory alignment for the media device's DMA controller. |
|
4593 |
||
4594 |
@return KErrNone, Always; |
|
4595 |
*/ |
|
4596 |
EXPORT_C TInt LocDrv::RegisterDmaDevice(DPrimaryMediaBase* aPrimaryMedia, |
|
4597 |
TInt aMediaBlockSize, // Minimum transfer size (bytes) for the media |
|
4598 |
TInt aDmaMaxAddressable, // Max Addressing Range for DMA controller, 0 if None. |
|
4599 |
TInt aDmaAlignment) // DMA Alignment e.g. word alignment required = 2 |
|
4600 |
{ |
|
4601 |
__KTRACE_OPT(KBOOT ,Kern::Printf("RegisterPhysicalAddrDevice: PM=0x%x BS=%d MaxAddr=%d DMA=%d", |
|
4602 |
aPrimaryMedia, aMediaBlockSize, aDmaMaxAddressable, aDmaAlignment)); |
|
4603 |
||
4604 |
for (TInt i=0; i<KMaxLocalDrives; ++i) |
|
4605 |
{ |
|
4606 |
TLocDrv* pL=TheDrives[i]; |
|
4607 |
if (pL && pL->iPrimaryMedia == aPrimaryMedia && pL->iDmaHelper == NULL) |
|
4608 |
{ |
|
4609 |
pL->iDmaHelper = new DDmaHelper; |
|
4610 |
__ASSERT_ALWAYS(pL != NULL, LOCM_FAULT()); |
|
4611 |
||
4612 |
// if no limit stated on addressing range use 1MB |
|
4613 |
TInt MaxAddress = aDmaMaxAddressable ? (1024*1024) : aDmaMaxAddressable; |
|
4614 |
||
4615 |
TInt r = pL->iDmaHelper->Construct(MaxAddress, aMediaBlockSize, aDmaAlignment); |
|
4616 |
__ASSERT_ALWAYS(r == KErrNone, LOCM_FAULT()); |
|
4617 |
} |
|
4618 |
} |
|
4619 |
||
4620 |
return KErrNone; |
|
4621 |
} |
|
4622 |
||
4623 |
void GetDriveInfo(TDriveInfoV1& info) |
|
4624 |
{ |
|
4625 |
TInt i; |
|
4626 |
TInt drives=0; |
|
4627 |
TUint32 sock_mask=0; |
|
4628 |
TInt sockets=0; |
|
4629 |
||
4630 |
info.iRegisteredDriveBitmask = 0; |
|
4631 |
||
4632 |
for (i=0; i<KMaxPBusSockets; ++i) |
|
4633 |
info.iSocketName[i].Zero(); |
|
4634 |
for (i=0; i<KMaxLocalDrives; ++i) |
|
4635 |
{ |
|
4636 |
TLocDrv* pL=TheDrives[i]; |
|
4637 |
if (pL) |
|
4638 |
{ |
|
4639 |
++drives; |
|
4640 |
TInt sockNum; |
|
4641 |
DPrimaryMediaBase* pM=pL->iPrimaryMedia; |
|
4642 |
if (pM->IsRemovableDevice(sockNum)) |
|
4643 |
{ |
|
4644 |
if (!(sock_mask & (1<<sockNum))) |
|
4645 |
{ |
|
4646 |
info.iSocketName[sockNum]=*DriveNames[i]; |
|
4647 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("Socket %d device %d name %lS", sockNum, pM->iDevice, DriveNames[i])); |
|
4648 |
if ( (sockNum + 1) > sockets ) |
|
4649 |
sockets = sockNum + 1; |
|
4650 |
} |
|
4651 |
sock_mask |= (1<<sockNum); |
|
4652 |
} |
|
4653 |
info.iDriveName[i]=*DriveNames[i]; |
|
4654 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("Drive %d device %d name %lS",i,pM->iDevice,DriveNames[i])); |
|
4655 |
||
4656 |
info.iRegisteredDriveBitmask |= (0x01 << i); |
|
4657 |
} |
|
4658 |
} |
|
4659 |
info.iTotalSupportedDrives=drives; |
|
4660 |
info.iTotalSockets=sockets; |
|
4661 |
info.iRuggedFileSystem=ETrue; |
|
4662 |
__KTRACE_OPT(KLOCDRV,Kern::Printf("Total drives=%d, sockets=%d",drives,sockets)); |
|
4663 |
} |
|
4664 |
||
4665 |
#if defined(__DEMAND_PAGING__) && defined(__CONCURRENT_PAGING_INSTRUMENTATION__) |
|
4666 |
void ResetConcurrencyStats(DMediaPagingDevice* aDevice, TMediaPagingStats aStats) |
|
4667 |
{ |
|
4668 |
NKern::FMWait(&aDevice->iInstrumentationLock); |
|
4669 |
switch(aStats) |
|
4670 |
{ |
|
4671 |
case EMediaPagingStatsRom: |
|
4672 |
aDevice->iServicingROM=0; |
|
4673 |
memclr(&aDevice->iROMStats,sizeof(SMediaROMPagingConcurrencyInfo)); |
|
4674 |
break; |
|
4675 |
case EMediaPagingStatsCode: |
|
4676 |
aDevice->iServicingCode=0; |
|
4677 |
memclr(&aDevice->iCodeStats,sizeof(SMediaCodePagingConcurrencyInfo)); |
|
4678 |
break; |
|
4679 |
case EMediaPagingStatsDataIn: |
|
4680 |
aDevice->iServicingDataIn=0; |
|
4681 |
memclr(&aDevice->iDataStats,sizeof(SMediaDataPagingConcurrencyInfo)); |
|
4682 |
break; |
|
4683 |
case EMediaPagingStatsDataOut: |
|
4684 |
aDevice->iServicingDataOut=0; |
|
4685 |
memclr(&aDevice->iDataStats,sizeof(SMediaDataPagingConcurrencyInfo)); |
|
4686 |
break; |
|
4687 |
case EMediaPagingStatsAll: |
|
4688 |
aDevice->iServicingROM=0; |
|
4689 |
aDevice->iServicingCode=0; |
|
4690 |
aDevice->iServicingDataIn=0; |
|
4691 |
aDevice->iServicingDataOut=0; |
|
4692 |
memclr(&aDevice->iROMStats,sizeof(SMediaROMPagingConcurrencyInfo)); |
|
4693 |
memclr(&aDevice->iCodeStats,sizeof(SMediaCodePagingConcurrencyInfo)); |
|
4694 |
memclr(&aDevice->iDataStats,sizeof(SMediaDataPagingConcurrencyInfo)); |
|
4695 |
break; |
|
4696 |
} |
|
4697 |
NKern::FMSignal(&aDevice->iInstrumentationLock); |
|
4698 |
} |
|
4699 |
#endif |
|
4700 |
#if defined(__DEMAND_PAGING__) && defined(__DEMAND_PAGING_BENCHMARKS__) |
|
4701 |
void ResetBenchmarkStats(DMediaPagingDevice* aDevice, TMediaPagingStats aStats) |
|
4702 |
{ |
|
4703 |
NKern::FMWait(&aDevice->iInstrumentationLock); |
|
4704 |
switch(aStats) |
|
4705 |
{ |
|
4706 |
case EMediaPagingStatsRom: |
|
4707 |
aDevice->iROMBenchmarkData.iCount = 0; |
|
4708 |
aDevice->iROMBenchmarkData.iTotalTime = 0; |
|
4709 |
aDevice->iROMBenchmarkData.iMaxTime = 0; |
|
4710 |
aDevice->iROMBenchmarkData.iMinTime = KMaxTInt; |
|
4711 |
break; |
|
4712 |
case EMediaPagingStatsCode: |
|
4713 |
aDevice->iCodeBenchmarkData.iCount = 0; |
|
4714 |
aDevice->iCodeBenchmarkData.iTotalTime = 0; |
|
4715 |
aDevice->iCodeBenchmarkData.iMaxTime = 0; |
|
4716 |
aDevice->iCodeBenchmarkData.iMinTime = KMaxTInt; |
|
4717 |
break; |
|
4718 |
case EMediaPagingStatsDataIn: |
|
4719 |
aDevice->iDataInBenchmarkData.iCount = 0; |
|
4720 |
aDevice->iDataInBenchmarkData.iTotalTime = 0; |
|
4721 |
aDevice->iDataInBenchmarkData.iMaxTime = 0; |
|
4722 |
aDevice->iDataInBenchmarkData.iMinTime = KMaxTInt; |
|
4723 |
break; |
|
4724 |
case EMediaPagingStatsDataOut: |
|
4725 |
aDevice->iDataOutBenchmarkData.iCount = 0; |
|
4726 |
aDevice->iDataOutBenchmarkData.iTotalTime = 0; |
|
4727 |
aDevice->iDataOutBenchmarkData.iMaxTime = 0; |
|
4728 |
aDevice->iDataOutBenchmarkData.iMinTime = KMaxTInt; |
|
4729 |
break; |
|
4730 |
case EMediaPagingStatsAll: |
|
4731 |
aDevice->iDataInBenchmarkData.iCount = 0; |
|
4732 |
aDevice->iDataInBenchmarkData.iTotalTime = 0; |
|
4733 |
aDevice->iDataInBenchmarkData.iMaxTime = 0; |
|
4734 |
aDevice->iDataInBenchmarkData.iMinTime = KMaxTInt; |
|
4735 |
||
4736 |
aDevice->iDataOutBenchmarkData.iCount = 0; |
|
4737 |
aDevice->iDataOutBenchmarkData.iTotalTime = 0; |
|
4738 |
aDevice->iDataOutBenchmarkData.iMaxTime = 0; |
|
4739 |
aDevice->iDataOutBenchmarkData.iMinTime = KMaxTInt; |
|
4740 |
||
4741 |
aDevice->iROMBenchmarkData.iCount = 0; |
|
4742 |
aDevice->iROMBenchmarkData.iTotalTime = 0; |
|
4743 |
aDevice->iROMBenchmarkData.iMaxTime = 0; |
|
4744 |
aDevice->iROMBenchmarkData.iMinTime = KMaxTInt; |
|
4745 |
||
4746 |
aDevice->iCodeBenchmarkData.iCount = 0; |
|
4747 |
aDevice->iCodeBenchmarkData.iTotalTime = 0; |
|
4748 |
aDevice->iCodeBenchmarkData.iMaxTime = 0; |
|
4749 |
aDevice->iCodeBenchmarkData.iMinTime = KMaxTInt; |
|
4750 |
break; |
|
4751 |
} |
|
4752 |
NKern::FMSignal(&aDevice->iInstrumentationLock); |
|
4753 |
} |
|
4754 |
#endif |
|
4755 |
||
4756 |
TInt MediaHalFunction(TAny*, TInt aFunction, TAny* a1, TAny* a2) |
|
4757 |
{ |
|
4758 |
TInt r=KErrNotSupported; |
|
4759 |
switch (aFunction) |
|
4760 |
{ |
|
4761 |
case EMediaHalDriveInfo: |
|
4762 |
{ |
|
4763 |
(void) a2; |
|
4764 |
TDriveInfoV1Buf infoBuf; |
|
4765 |
TDriveInfoV1& info=infoBuf(); |
|
4766 |
GetDriveInfo(info); |
|
4767 |
Kern::InfoCopy(*(TDes8*)a1,infoBuf); |
|
4768 |
r=KErrNone; |
|
4769 |
break; |
|
4770 |
} |
|
4771 |
#if defined(__DEMAND_PAGING__) && defined(__CONCURRENT_PAGING_INSTRUMENTATION__) |
|
4772 |
case EMediaHalGetROMConcurrencyInfo: |
|
4773 |
{ |
|
4774 |
TInt drvNo=(TInt)a1; |
|
4775 |
TLocDrv* drv=TheDrives[drvNo]; |
|
4776 |
if(!drv) |
|
4777 |
break; |
|
4778 |
DMediaPagingDevice* device = drv->iPrimaryMedia->iBody->iPagingDevice; |
|
4779 |
if(!device) |
|
4780 |
break; |
|
4781 |
NKern::FMWait(&device->iInstrumentationLock); |
|
4782 |
SMediaROMPagingConcurrencyInfo info=device->iROMStats; |
|
4783 |
NKern::FMSignal(&device->iInstrumentationLock); |
|
4784 |
kumemput32(a2,&info,sizeof(info)); |
|
4785 |
r=KErrNone; |
|
4786 |
break; |
|
4787 |
} |
|
4788 |
case EMediaHalGetCodeConcurrencyInfo: |
|
4789 |
{ |
|
4790 |
TInt drvNo=(TInt)a1; |
|
4791 |
TLocDrv* drv=TheDrives[drvNo]; |
|
4792 |
if(!drv) |
|
4793 |
break; |
|
4794 |
DMediaPagingDevice* device=drv->iPrimaryMedia->iBody->iPagingDevice; |
|
4795 |
if(!device) |
|
4796 |
break; |
|
4797 |
NKern::FMWait(&device->iInstrumentationLock); |
|
4798 |
SMediaCodePagingConcurrencyInfo info=device->iCodeStats; |
|
4799 |
NKern::FMSignal(&device->iInstrumentationLock); |
|
4800 |
kumemput32(a2,&info,sizeof(info)); |
|
4801 |
r=KErrNone; |
|
4802 |
break; |
|
4803 |
} |
|
4804 |
case EMediaHalGetDataConcurrencyInfo: |
|
4805 |
{ |
|
4806 |
TInt drvNo=(TInt)a1; |
|
4807 |
TLocDrv* drv=TheDrives[drvNo]; |
|
4808 |
if(!drv) |
|
4809 |
break; |
|
4810 |
DMediaPagingDevice* device = drv->iPrimaryMedia->iBody->iPagingDevice; |
|
4811 |
if(!device) |
|
4812 |
break; |
|
4813 |
NKern::FMWait(&device->iInstrumentationLock); |
|
4814 |
SMediaDataPagingConcurrencyInfo info=device->iDataStats; |
|
4815 |
NKern::FMSignal(&device->iInstrumentationLock); |
|
4816 |
kumemput32(a2,&info,sizeof(info)); |
|
4817 |
r=KErrNone; |
|
4818 |
break; |
|
4819 |
} |
|
4820 |
case EMediaHalResetConcurrencyInfo: |
|
4821 |
{ |
|
4822 |
TInt drvNo=(TInt)a1; |
|
4823 |
TLocDrv* drv=TheDrives[drvNo]; |
|
4824 |
if(!drv) |
|
4825 |
break; |
|
4826 |
DMediaPagingDevice* device=drv->iPrimaryMedia->iBody->iPagingDevice; |
|
4827 |
if(!device) |
|
4828 |
break; |
|
4829 |
TUint index=(TInt)a2; |
|
4830 |
if(index>EMediaPagingStatsCode) |
|
4831 |
break; |
|
4832 |
ResetConcurrencyStats(device, (TMediaPagingStats)index); |
|
4833 |
r=KErrNone; |
|
4834 |
break; |
|
4835 |
} |
|
4836 |
#endif |
|
4837 |
#if defined(__DEMAND_PAGING__) && defined(__DEMAND_PAGING_BENCHMARKS__) |
|
4838 |
case EMediaHalGetROMPagingBenchmark: |
|
4839 |
{ |
|
4840 |
TInt drvNo=(TInt)a1; |
|
4841 |
TLocDrv* drv=TheDrives[drvNo]; |
|
4842 |
if(!drv) |
|
4843 |
break; |
|
4844 |
DMediaPagingDevice* device=drv->iPrimaryMedia->iBody->iPagingDevice; |
|
4845 |
if(!device) |
|
4846 |
break; |
|
4847 |
NKern::FMWait(&device->iInstrumentationLock); |
|
4848 |
SPagingBenchmarkInfo info = device->iROMBenchmarkData; |
|
4849 |
NKern::FMSignal(&device->iInstrumentationLock); |
|
4850 |
kumemput32(a2,&info,sizeof(info)); |
|
4851 |
r=KErrNone; |
|
4852 |
break; |
|
4853 |
} |
|
4854 |
case EMediaHalGetCodePagingBenchmark: |
|
4855 |
{ |
|
4856 |
TInt drvNo=(TInt)a1; |
|
4857 |
TLocDrv* drv=TheDrives[drvNo]; |
|
4858 |
if(!drv) |
|
4859 |
break; |
|
4860 |
DMediaPagingDevice* device=drv->iPrimaryMedia->iBody->iPagingDevice; |
|
4861 |
if(!device) |
|
4862 |
break; |
|
4863 |
NKern::FMWait(&device->iInstrumentationLock); |
|
4864 |
SPagingBenchmarkInfo info = device->iCodeBenchmarkData; |
|
4865 |
NKern::FMSignal(&device->iInstrumentationLock); |
|
4866 |
kumemput32(a2,&info,sizeof(info)); |
|
4867 |
r=KErrNone; |
|
4868 |
break; |
|
4869 |
} |
|
4870 |
case EMediaHalGetDataInPagingBenchmark: |
|
4871 |
{ |
|
4872 |
TInt drvNo=(TInt)a1; |
|
4873 |
TLocDrv* drv=TheDrives[drvNo]; |
|
4874 |
if(!drv) |
|
4875 |
break; |
|
4876 |
DMediaPagingDevice* device=drv->iPrimaryMedia->iBody->iPagingDevice; |
|
4877 |
if(!device) |
|
4878 |
break; |
|
4879 |
NKern::FMWait(&device->iInstrumentationLock); |
|
4880 |
SPagingBenchmarkInfo info = device->iDataInBenchmarkData; |
|
4881 |
NKern::FMSignal(&device->iInstrumentationLock); |
|
4882 |
kumemput32(a2,&info,sizeof(info)); |
|
4883 |
r=KErrNone; |
|
4884 |
break; |
|
4885 |
} |
|
4886 |
case EMediaHalGetDataOutPagingBenchmark: |
|
4887 |
{ |
|
4888 |
TInt drvNo=(TInt)a1; |
|
4889 |
TLocDrv* drv=TheDrives[drvNo]; |
|
4890 |
if(!drv) |
|
4891 |
break; |
|
4892 |
DMediaPagingDevice* device=drv->iPrimaryMedia->iBody->iPagingDevice; |
|
4893 |
if(!device) |
|
4894 |
break; |
|
4895 |
NKern::FMWait(&device->iInstrumentationLock); |
|
4896 |
SPagingBenchmarkInfo info = device->iDataOutBenchmarkData; |
|
4897 |
NKern::FMSignal(&device->iInstrumentationLock); |
|
4898 |
kumemput32(a2,&info,sizeof(info)); |
|
4899 |
r=KErrNone; |
|
4900 |
break; |
|
4901 |
} |
|
4902 |
case EMediaHalResetPagingBenchmark: |
|
4903 |
{ |
|
4904 |
TInt drvNo=(TInt)a1; |
|
4905 |
TLocDrv* drv=TheDrives[drvNo]; |
|
4906 |
if(!drv) |
|
4907 |
break; |
|
4908 |
DMediaPagingDevice* device=drv->iPrimaryMedia->iBody->iPagingDevice; |
|
4909 |
if(!device) |
|
4910 |
break; |
|
4911 |
TUint index=(TInt)a2; |
|
4912 |
if(index>EMediaPagingStatsCode) |
|
4913 |
break; |
|
4914 |
ResetBenchmarkStats(device, (TMediaPagingStats)index); |
|
4915 |
r=KErrNone; |
|
4916 |
break; |
|
4917 |
} |
|
4918 |
case EMediaHalGetPagingInfo: |
|
4919 |
{ |
|
4920 |
TInt drvNo=(TInt)a1; |
|
4921 |
TLocDrv* drv=TheDrives[drvNo]; |
|
4922 |
if(!drv) |
|
4923 |
break; |
|
4924 |
DMediaPagingDevice* device=drv->iPrimaryMedia->iBody->iPagingDevice; |
|
4925 |
if(!device) |
|
4926 |
break; |
|
4927 |
NKern::FMWait(&device->iInstrumentationLock); |
|
4928 |
SMediaPagingInfo info = device->iMediaPagingInfo; |
|
4929 |
NKern::FMSignal(&device->iInstrumentationLock); |
|
4930 |
kumemput32(a2,&info,sizeof(info)); |
|
4931 |
r=KErrNone; |
|
4932 |
break; |
|
4933 |
} |
|
4934 |
#endif |
|
4935 |
default: |
|
4936 |
break; |
|
4937 |
} |
|
4938 |
return r; |
|
4939 |
} |
|
4940 |
||
4941 |
||
4942 |
/****************************************************************************** |
|
4943 |
Partition table scanner |
|
4944 |
******************************************************************************/ |
|
4945 |
||
4946 |
#ifdef _DEBUG |
|
4947 |
#define DMEMDUMP(base,size) DbgMemDump((TLinAddr)base,size) |
|
4948 |
void DbgMemDump(TLinAddr aBase, TInt aSize) |
|
4949 |
{ |
|
4950 |
TInt off; |
|
4951 |
const TUint8* p=(const TUint8*)aBase; |
|
4952 |
NKern::Lock(); |
|
4953 |
for (off=0; off<aSize; off+=16, p+=16) |
|
4954 |
{ |
|
4955 |
Kern::Printf("%04x: %02x %02x %02x %02x %02x %02x %02x %02x | %02x %02x %02x %02x %02x %02x %02x %02x", |
|
4956 |
off, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], |
|
4957 |
p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]); |
|
4958 |
} |
|
4959 |
NKern::Unlock(); |
|
4960 |
} |
|
4961 |
#else |
|
4962 |
#define DMEMDUMP(base,size) |
|
4963 |
#endif |
|
4964 |
||
4965 |
EXPORT_C void TPartitionTableScanner::Set(TUint8* aSectorBuffer, TPartitionEntry* aEntry, TInt aMaxPartitions, TInt64 aMediaSize) |
|
4966 |
{ |
|
4967 |
__KTRACE_OPT(KLOCDRV, Kern::Printf("TPartitionTableScanner @ %08x : buf %08x entry %08x max %d sz %08x %08x", |
|
4968 |
this, aSectorBuffer, aEntry, aMaxPartitions, I64HIGH(aMediaSize), I64LOW(aMediaSize))); |
|
4969 |
__ASSERT_ALWAYS(aMaxPartitions>0, LOCM_FAULT()); |
|
4970 |
memclr(this, sizeof(TPartitionTableScanner)); |
|
4971 |
iLBA = -1; |
|
4972 |
iSectorBuffer = aSectorBuffer; |
|
4973 |
iFirstEntry = aEntry; |
|
4974 |
iNextEntry = aEntry; |
|
4975 |
iLimit = aEntry + aMaxPartitions; |
|
4976 |
iMediaSize = aMediaSize; |
|
4977 |
} |
|
4978 |
||
4979 |
EXPORT_C TInt TPartitionTableScanner::NumberOfPartitionsFound() const |
|
4980 |
{ |
|
4981 |
TInt n = iNextEntry - iFirstEntry; |
|
4982 |
__KTRACE_OPT(KLOCDRV, Kern::Printf("TPartitionTableScanner N=%d", n)); |
|
4983 |
return n; |
|
4984 |
} |
|
4985 |
||
4986 |
TPartitionTableScanner::SPart::SPart(const TUint8* a) |
|
4987 |
{ |
|
4988 |
iBootInd = a[0]; |
|
4989 |
iType = a[4]; |
|
4990 |
iRSS = a[8]|(a[9]<<8)|(a[10]<<16)|(a[11]<<24); |
|
4991 |
iSectors = a[12]|(a[13]<<8)|(a[14]<<16)|(a[15]<<24); |
|
4992 |
__KTRACE_OPT(KLOCDRV, Kern::Printf("SPart: BI=%02x TYPE=%02x RSS=%08x SIZE=%08x", iBootInd, iType, iRSS, iSectors)); |
|
4993 |
} |
|
4994 |
||
4995 |
TInt TPartitionTableScanner::MakeEntry(const SPart& a) |
|
4996 |
{ |
|
4997 |
if (iNextEntry == iLimit) |
|
4998 |
return KErrOverflow; |
|
4999 |
if (a.iRSS<=0 || a.iSectors<=0 || a.iRSS>=iMediaSize) |
|
5000 |
return KErrCorrupt; |
|
5001 |
if (TUint64(a.iRSS) + TUint64(a.iSectors) > TUint64(iMediaSize)) |
|
5002 |
return KErrCorrupt; |
|
5003 |
iNextEntry->iBootIndicator = a.iBootInd; |
|
5004 |
iNextEntry->iPartitionType = a.iType; |
|
5005 |
iNextEntry->iPartitionBaseAddr = TInt64(a.iRSS)<<ESectorShift; |
|
5006 |
iNextEntry->iPartitionLen = TInt64(a.iSectors)<<ESectorShift; |
|
5007 |
++iNextEntry; |
|
5008 |
return KErrNone; |
|
5009 |
} |
|
5010 |
||
5011 |
EXPORT_C TInt64 TPartitionTableScanner::NextLBA() |
|
5012 |
{ |
|
5013 |
__KTRACE_OPT(KLOCDRV, Kern::Printf(">TPartitionTableScanner iLBA=%08x %08x", I64HIGH(iLBA), I64LOW(iLBA))); |
|
5014 |
TInt r; |
|
5015 |
TUint8* b = iSectorBuffer; |
|
5016 |
TUint8* pS = b + 0x1be; |
|
5017 |
TUint8* pE = pS + 64; |
|
5018 |
TUint8* p = pS; |
|
5019 |
TInt orig_sp = iStackPointer; |
|
5020 |
TInt sp; |
|
5021 |
if (iLBA < 0) |
|
5022 |
{ |
|
5023 |
iLBA = 0; |
|
5024 |
goto end; |
|
5025 |
} |
|
5026 |
__KTRACE_OPT(KLOCDRV,DMEMDUMP(b, ESectorSize)); |
|
5027 |
if (b[ESectorSize-2]!=0x55 || b[ESectorSize-1]!=0xaa) |
|
5028 |
{ |
|
5029 |
__KTRACE_OPT(KLOCDRV, Kern::Printf("Bad signature")); |
|
5030 |
iLBA = KErrCorrupt; |
|
5031 |
goto end; |
|
5032 |
} |
|
5033 |
if (iLBA==0 && iNextEntry==iFirstEntry) |
|
5034 |
{ |
|
5035 |
// Look for bootable partition first |
|
5036 |
for (; p<pE; p+=16) |
|
5037 |
{ |
|
5038 |
SPart pt(p); |
|
5039 |
if (pt.iBootInd==0x80 && pt.iType && pt.iSectors>0) |
|
5040 |
{ |
|
5041 |
p[4] = 0; |
|
5042 |
r = MakeEntry(pt); |
|
5043 |
if (r!=KErrNone) |
|
5044 |
{ |
|
5045 |
iLBA = r; |
|
5046 |
goto end; |
|
5047 |
} |
|
5048 |
} |
|
5049 |
} |
|
5050 |
} |
|
5051 |
// Look for extended partitions |
|
5052 |
for (p=pE-16; p>=pS; p-=16) |
|
5053 |
{ |
|
5054 |
SPart pt(p); |
|
5055 |
if ((pt.iType==0x05 || pt.iType==0x0f) && pt.iSectors>0) |
|
5056 |
{ |
|
5057 |
// This one is an EBR |
|
5058 |
p[4] = 0; |
|
5059 |
if (iStackPointer == EMaxNest) |
|
5060 |
{ |
|
5061 |
if (iStackPointer == orig_sp) |
|
5062 |
continue; |
|
5063 |
--iStackPointer; |
|
5064 |
for(sp = orig_sp; sp<iStackPointer; ++sp) |
|
5065 |
iStack[sp] = iStack[sp+1]; |
|
5066 |
} |
|
5067 |
iStack[iStackPointer].iRSS = pt.iRSS; |
|
5068 |
iStack[iStackPointer].iSectors = pt.iSectors; |
|
5069 |
++iStackPointer; |
|
5070 |
#ifdef _DEBUG |
|
5071 |
for (sp=0; sp<iStackPointer; ++sp) |
|
5072 |
{ |
|
5073 |
const TInt64& rss = iStack[sp].iRSS; |
|
5074 |
const TInt64& size = iStack[sp].iSectors; |
|
5075 |
__KTRACE_OPT(KLOCDRV, Kern::Printf("Stack[%d] RSS %08x %08x SIZE %08x %08x", sp, |
|
5076 |
I64HIGH(rss), I64LOW(rss), I64HIGH(size), I64LOW(size) )); |
|
5077 |
} |
|
5078 |
#endif |
|
5079 |
} |
|
5080 |
} |
|
5081 |
// Look for other data partitions |
|
5082 |
for (p=pS; p<pE; p+=16) |
|
5083 |
{ |
|
5084 |
SPart pt(p); |
|
5085 |
if (pt.iType && pt.iSectors>0) |
|
5086 |
{ |
|
5087 |
pt.iRSS += TUint32(iLBA); // data partitions are specified relative to the EBR they appear in |
|
5088 |
r = MakeEntry(pt); |
|
5089 |
if (r!=KErrNone) |
|
5090 |
{ |
|
5091 |
iLBA = r; |
|
5092 |
goto end; |
|
5093 |
} |
|
5094 |
} |
|
5095 |
} |
|
5096 |
// If any EBRs on stack, pop off the first and process it |
|
5097 |
if (iStackPointer) |
|
5098 |
{ |
|
5099 |
--iStackPointer; |
|
5100 |
iLBA = iFirstEBR + iStack[iStackPointer].iRSS; // LBA of second and subsequent EBR is specified relative to first EBR |
|
5101 |
if (!iFirstEBR) |
|
5102 |
iFirstEBR = iLBA; |
|
5103 |
} |
|
5104 |
else |
|
5105 |
iLBA = KErrEof; // finished |
|
5106 |
||
5107 |
end: |
|
5108 |
__KTRACE_OPT(KLOCDRV, Kern::Printf("<TPartitionTableScanner iLBA=%08x %08x", I64HIGH(iLBA), I64LOW(iLBA))); |
|
5109 |
return iLBA; |
|
5110 |
} |
|
5111 |
||
5112 |
/** |
|
5113 |
* Returns Address and Length of next contiguous Physical memory fragment |
|
5114 |
* |
|
5115 |
* @param aAddr On success, populated with the Physical Address of the next fragment. |
|
5116 |
* @param aLen On success, populated with the length in bytes of the next fragment. |
|
5117 |
* |
|
5118 |
* @return KErrNone, if successful; |
|
5119 |
* KErrNoMemory, if no more memory fragments left. |
|
5120 |
* KErrNotSupported, if Physical Memory addressing is not supported by this Media. |
|
5121 |
*/ |
|
5122 |
EXPORT_C TInt TLocDrvRequest::GetNextPhysicalAddress(TPhysAddr& aAddr, TInt& aLen) |
|
5123 |
{ |
|
5124 |
if (Flags() & EPhysAddr) |
|
5125 |
{ |
|
5126 |
||
5127 |
#ifdef __DEMAND_PAGING__ |
|
5128 |
if (DMediaPagingDevice::PagingRequest(*this)) |
|
5129 |
{ |
|
5130 |
return DDmaHelper::GetPhysicalAddress(*this, aAddr, aLen); |
|
5131 |
} |
|
5132 |
#endif |
|
5133 |
return Drive()->iDmaHelper->GetPhysicalAddress(aAddr, aLen); |
|
5134 |
} |
|
5135 |
else |
|
5136 |
{ |
|
5137 |
return KErrNotSupported; |
|
5138 |
} |
|
5139 |
} |
|
5140 |
||
5141 |
||
5142 |
/****************************************************************************** |
|
5143 |
Entry point |
|
5144 |
******************************************************************************/ |
|
5145 |
DECLARE_STANDARD_EXTENSION() |
|
5146 |
{ |
|
5147 |
__KTRACE_OPT(KBOOT,Kern::Printf("Starting LOCMEDIA extension")); |
|
5148 |
||
5149 |
// install the HAL function |
|
5150 |
TInt r=Kern::AddHalEntry(EHalGroupMedia,MediaHalFunction,NULL); |
|
5151 |
#ifdef __DEMAND_PAGING__ |
|
5152 |
if (r==KErrNone) |
|
5153 |
{ |
|
5154 |
__KTRACE_OPT(KBOOT,Kern::Printf("Creating LocDrv device")); |
|
5155 |
DLocalDriveFactory* device = new DLocalDriveFactory; |
|
5156 |
if (device==NULL) |
|
5157 |
r=KErrNoMemory; |
|
5158 |
else |
|
5159 |
r=Kern::InstallLogicalDevice(device); |
|
5160 |
__KTRACE_OPT(KBOOT,Kern::Printf("Installing LocDrv device in kernel returned %d",r)); |
|
5161 |
} |
|
5162 |
#endif // __DEMAND_PAGING__ |
|
5163 |
return r; |
|
5164 |
} |
|
5165 |
||
5166 |