sl@0
|
1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32\drivers\pbus\mmc\mmccd_init.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <drivers/mmccd_ifc.h>
|
sl@0
|
19 |
#include <drivers/pbusmedia.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
|
sl@0
|
24 |
/**
|
sl@0
|
25 |
Starts the sequence of operations that creates the platform specific objects,
|
sl@0
|
26 |
registers the socket, and initialises the stack.
|
sl@0
|
27 |
|
sl@0
|
28 |
The function is called in the Variant DLL's entry point code, i.e. when
|
sl@0
|
29 |
the kernel extension is initialised.
|
sl@0
|
30 |
|
sl@0
|
31 |
Note that the Variant DLL is a kernel extension.
|
sl@0
|
32 |
|
sl@0
|
33 |
@return KErrNone if creation and initialisation is successful;
|
sl@0
|
34 |
one of the other system wide error codes otherwise.
|
sl@0
|
35 |
|
sl@0
|
36 |
@see TMMCardControllerInterface::NewStack()
|
sl@0
|
37 |
@see TMMCardControllerInterface::NewMediaChange()
|
sl@0
|
38 |
@see TMMCardControllerInterface::NewVcc()
|
sl@0
|
39 |
@see TMMCardControllerInterface::Init()
|
sl@0
|
40 |
@see TMMCardControllerInterface::IsMMCStack()
|
sl@0
|
41 |
@see TMMCardControllerInterface::MediaChangeID()
|
sl@0
|
42 |
@see TMMCardControllerInterface::VccID()
|
sl@0
|
43 |
*/
|
sl@0
|
44 |
EXPORT_C TInt TMMCardControllerInterface::Create()
|
sl@0
|
45 |
//
|
sl@0
|
46 |
// Allocate any resources. Only done once on kernel initialization so don't
|
sl@0
|
47 |
// worry about cleanup if it fails.
|
sl@0
|
48 |
//
|
sl@0
|
49 |
{
|
sl@0
|
50 |
TInt r=KErrNone;
|
sl@0
|
51 |
__KTRACE_OPT(KPBUS1,Kern::Printf(">TMMCardControllerInterface::Create"));
|
sl@0
|
52 |
|
sl@0
|
53 |
// Create the password store (a single password store
|
sl@0
|
54 |
// is allocated for the use of all MMC stacks
|
sl@0
|
55 |
|
sl@0
|
56 |
TMMCPasswordStore* theMmcPasswordStore = (TMMCPasswordStore*)LocDrv::PasswordStore();
|
sl@0
|
57 |
if(theMmcPasswordStore == NULL)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
theMmcPasswordStore = new TMMCPasswordStore();
|
sl@0
|
60 |
if(theMmcPasswordStore)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
if((r = theMmcPasswordStore->Init()) == KErrNone)
|
sl@0
|
63 |
r = LocDrv::RegisterPasswordStore(theMmcPasswordStore);
|
sl@0
|
64 |
|
sl@0
|
65 |
if(r != KErrNone)
|
sl@0
|
66 |
delete theMmcPasswordStore;
|
sl@0
|
67 |
}
|
sl@0
|
68 |
else
|
sl@0
|
69 |
{
|
sl@0
|
70 |
r = KErrNoMemory;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
if(r!= KErrNone)
|
sl@0
|
75 |
return r;
|
sl@0
|
76 |
|
sl@0
|
77 |
r = Init();
|
sl@0
|
78 |
if (r != KErrNone)
|
sl@0
|
79 |
return r;
|
sl@0
|
80 |
|
sl@0
|
81 |
|
sl@0
|
82 |
SMediaDeviceInfo mdi;
|
sl@0
|
83 |
TInt i;
|
sl@0
|
84 |
for (i=0; i<KMaxPBusSockets && r==KErrNone; i++)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
if (IsMMCSocket(i,mdi))
|
sl@0
|
87 |
{
|
sl@0
|
88 |
__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d is MMC card",i));
|
sl@0
|
89 |
|
sl@0
|
90 |
// Allocate a new socket
|
sl@0
|
91 |
DMMCSocket* pS = NewSocket(i, theMmcPasswordStore);
|
sl@0
|
92 |
if (!pS)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
r=KErrNoMemory;
|
sl@0
|
95 |
break;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
TheSockets[i]=pS;
|
sl@0
|
98 |
|
sl@0
|
99 |
// Allocate a variant specific stack object via the interface
|
sl@0
|
100 |
DMMCStack* pStack=NewStack(i, pS);
|
sl@0
|
101 |
if (!pStack)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
r=KErrNoMemory;
|
sl@0
|
104 |
break;
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
pS->iStack=pStack;
|
sl@0
|
108 |
|
sl@0
|
109 |
TInt mcid=MediaChangeID(i);
|
sl@0
|
110 |
__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d Media Change %d",i,mcid));
|
sl@0
|
111 |
DMMCMediaChange* pM=(DMMCMediaChange*)TheMediaChanges[mcid];
|
sl@0
|
112 |
if (!pM)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
__KTRACE_OPT(KPBUS1,Kern::Printf("New Media Change"));
|
sl@0
|
115 |
pM=NewMediaChange(mcid);
|
sl@0
|
116 |
if (!pM)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
r=KErrNoMemory;
|
sl@0
|
119 |
break;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
TheMediaChanges[mcid]=pM;
|
sl@0
|
122 |
__KTRACE_OPT(KPBUS1,Kern::Printf("Media Change %d at %08x",mcid,pM));
|
sl@0
|
123 |
r=pM->Create();
|
sl@0
|
124 |
if (r!=KErrNone)
|
sl@0
|
125 |
break;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
else
|
sl@0
|
128 |
{
|
sl@0
|
129 |
__KTRACE_OPT(KPBUS1,Kern::Printf("Media Change %d already exists at %08x",mcid,pM));
|
sl@0
|
130 |
++pM->iReplyCount;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
TInt vcc=VccID(i);
|
sl@0
|
133 |
__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d Vcc %d",i,vcc));
|
sl@0
|
134 |
DMMCPsu* pV=(DMMCPsu*)TheVccs[vcc];
|
sl@0
|
135 |
if (!pV)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
__KTRACE_OPT(KPBUS1,Kern::Printf("New Vcc"));
|
sl@0
|
138 |
pV=NewVcc(vcc,mcid);
|
sl@0
|
139 |
if (!pV)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
r=KErrNoMemory;
|
sl@0
|
142 |
break;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
TheVccs[vcc]=pV;
|
sl@0
|
145 |
|
sl@0
|
146 |
// Assign Socket here such that iDFc can be obtained
|
sl@0
|
147 |
pV->iSocket=pS;
|
sl@0
|
148 |
|
sl@0
|
149 |
__KTRACE_OPT(KPBUS1,Kern::Printf("Vcc %d at %08x",vcc,pV));
|
sl@0
|
150 |
r=pV->Create();
|
sl@0
|
151 |
if (r!=KErrNone)
|
sl@0
|
152 |
break;
|
sl@0
|
153 |
}
|
sl@0
|
154 |
else
|
sl@0
|
155 |
{
|
sl@0
|
156 |
__KTRACE_OPT(KPBUS1,Kern::Printf("Vcc %d already exists at %08x, mcid=%d",vcc,pV,pV->iMediaChangeNum));
|
sl@0
|
157 |
// DISALLOW SHARED PSUs UNTIL SOMEONE NEEDS THEM
|
sl@0
|
158 |
// if (pV->iMediaChangeNum!=mcid)
|
sl@0
|
159 |
// {
|
sl@0
|
160 |
r=KErrInUse;
|
sl@0
|
161 |
// break;
|
sl@0
|
162 |
// }
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
DMMCPsu* pVCore=(DMMCPsu*)TheVccCores[vcc];
|
sl@0
|
166 |
// N.B. Assume paired vcc & vccQ unit are numbered identically!
|
sl@0
|
167 |
pVCore=NewVccCore(vcc,mcid);
|
sl@0
|
168 |
if (pVCore)
|
sl@0
|
169 |
{
|
sl@0
|
170 |
TheVccCores[vcc]=pVCore;
|
sl@0
|
171 |
__KTRACE_OPT(KPBUS1,Kern::Printf("VccCore %d at %08x",vcc,pVCore));
|
sl@0
|
172 |
|
sl@0
|
173 |
// Assign Socket here such that iDFcQ can be obtained
|
sl@0
|
174 |
pVCore->iSocket=pS;
|
sl@0
|
175 |
|
sl@0
|
176 |
r=pVCore->Create();
|
sl@0
|
177 |
if (r!=KErrNone)
|
sl@0
|
178 |
break;
|
sl@0
|
179 |
|
sl@0
|
180 |
// VccCore must issue sleep instead of power down
|
sl@0
|
181 |
pVCore->iPwrDownCheckFn = DMMCPsu::SleepCheck;
|
sl@0
|
182 |
}
|
sl@0
|
183 |
//else do nothing doesn't matter if its not supported
|
sl@0
|
184 |
|
sl@0
|
185 |
r=pS->Create(mdi.iDeviceName);
|
sl@0
|
186 |
if (r!=KErrNone)
|
sl@0
|
187 |
break;
|
sl@0
|
188 |
|
sl@0
|
189 |
pS->iMediaChangeNumber=mcid;
|
sl@0
|
190 |
pS->iMediaChange=pM;
|
sl@0
|
191 |
pS->iVcc=pV;
|
sl@0
|
192 |
if (pVCore)
|
sl@0
|
193 |
{
|
sl@0
|
194 |
pS->iVccCore = pVCore;
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@0
|
197 |
r=pS->Init();
|
sl@0
|
198 |
if (r!=KErrNone)
|
sl@0
|
199 |
break;
|
sl@0
|
200 |
|
sl@0
|
201 |
r = RegisterMediaDevices(i);
|
sl@0
|
202 |
if(r != KErrNone)
|
sl@0
|
203 |
break;
|
sl@0
|
204 |
|
sl@0
|
205 |
__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d Created OK",i));
|
sl@0
|
206 |
}
|
sl@0
|
207 |
else
|
sl@0
|
208 |
__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d not MMC card",i));
|
sl@0
|
209 |
}
|
sl@0
|
210 |
|
sl@0
|
211 |
__KTRACE_OPT(KPBUS1,Kern::Printf("<TMMCardControllerInterface::Create, ret %d",r));
|
sl@0
|
212 |
return r;
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
EXPORT_C TInt TMMCardControllerInterface::RegisterMediaDevices(TInt aSocket)
|
sl@0
|
216 |
/**
|
sl@0
|
217 |
Registers the media devices for the specified socket.
|
sl@0
|
218 |
By default, All MMC derivatives register at least an MMC driver
|
sl@0
|
219 |
@internal
|
sl@0
|
220 |
*/
|
sl@0
|
221 |
{
|
sl@0
|
222 |
TInt err = KErrNone;
|
sl@0
|
223 |
|
sl@0
|
224 |
SMediaDeviceInfo mdi;
|
sl@0
|
225 |
|
sl@0
|
226 |
if (IsMMCSocket(aSocket, mdi) == EFalse)
|
sl@0
|
227 |
return(KErrNotSupported);
|
sl@0
|
228 |
|
sl@0
|
229 |
DMMCSocket* pS = (DMMCSocket*) TheSockets[aSocket];
|
sl@0
|
230 |
if(pS == NULL)
|
sl@0
|
231 |
return(KErrNoMemory);
|
sl@0
|
232 |
|
sl@0
|
233 |
TMMCMachineInfo mi;
|
sl@0
|
234 |
pS->iStack->MachineInfo(mi);
|
sl@0
|
235 |
|
sl@0
|
236 |
// There may be more than one physical card slot for this socket/stack;
|
sl@0
|
237 |
// if this is the case, then we have to create a separate DPBusPrimaryMedia
|
sl@0
|
238 |
// for each one. This is the only way to get the local media sub-system to iterate
|
sl@0
|
239 |
// through the installed set of media drivers repeatedly for each card slot
|
sl@0
|
240 |
// (rather than once for the entire stack). We also need to share the number of
|
sl@0
|
241 |
// drives/partitions (SMediaDeviceInfo.iDriveCount) and the number of media
|
sl@0
|
242 |
// (SMediaDeviceInfo.iNumMedia) equally between the slots...
|
sl@0
|
243 |
__ASSERT_ALWAYS(mdi.iDriveCount >= mi.iTotalSockets, DMMCSocket::Panic(DMMCSocket::EMMCInvalidNumberOfCardSlots) );
|
sl@0
|
244 |
__ASSERT_ALWAYS(mdi.iNumMedia >= mi.iTotalSockets, DMMCSocket::Panic(DMMCSocket::EMMCInvalidNumberOfCardSlots) );
|
sl@0
|
245 |
|
sl@0
|
246 |
TInt physicalCardSlots = mi.iTotalSockets;
|
sl@0
|
247 |
TInt drivesPerSlot = mdi.iDriveCount / physicalCardSlots;
|
sl@0
|
248 |
TInt numMediaPerSlot = mdi.iNumMedia / physicalCardSlots;
|
sl@0
|
249 |
TInt driveListIndex = 0;
|
sl@0
|
250 |
|
sl@0
|
251 |
#if !defined(__WINS__)
|
sl@0
|
252 |
DMMCStack::TDemandPagingInfo demandPagingInfo;
|
sl@0
|
253 |
demandPagingInfo.iPagingDriveList = NULL;
|
sl@0
|
254 |
demandPagingInfo.iDriveCount = 0;
|
sl@0
|
255 |
TBool demandPagingSupported =
|
sl@0
|
256 |
pS->iStack->DemandPagingInfo(demandPagingInfo) == KErrNone ? (TBool)ETrue : (TBool)EFalse;
|
sl@0
|
257 |
|
sl@0
|
258 |
#endif // __WINS__
|
sl@0
|
259 |
|
sl@0
|
260 |
|
sl@0
|
261 |
for (TInt i=0; i<physicalCardSlots ; i++)
|
sl@0
|
262 |
{
|
sl@0
|
263 |
DPBusPrimaryMedia* pMedia = new DPBusPrimaryMedia(pS);
|
sl@0
|
264 |
if (pMedia == NULL)
|
sl@0
|
265 |
return(KErrNoMemory);
|
sl@0
|
266 |
// store the slot number in DPBusPrimaryMedia so that it can
|
sl@0
|
267 |
// subsequently be passed to the media driver.
|
sl@0
|
268 |
pMedia->iSlotNumber = i;
|
sl@0
|
269 |
|
sl@0
|
270 |
err = LocDrv::RegisterMediaDevice(
|
sl@0
|
271 |
mdi.iDevice,
|
sl@0
|
272 |
drivesPerSlot,
|
sl@0
|
273 |
mdi.iDriveList+driveListIndex,
|
sl@0
|
274 |
pMedia,
|
sl@0
|
275 |
numMediaPerSlot,
|
sl@0
|
276 |
*mdi.iDeviceName);
|
sl@0
|
277 |
if (err != KErrNone)
|
sl@0
|
278 |
break;
|
sl@0
|
279 |
|
sl@0
|
280 |
#if !defined(__WINS__)
|
sl@0
|
281 |
if (demandPagingSupported && demandPagingInfo.iSlotNumber == i)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
err = LocDrv::RegisterPagingDevice(
|
sl@0
|
284 |
pMedia,
|
sl@0
|
285 |
demandPagingInfo.iPagingDriveList,
|
sl@0
|
286 |
demandPagingInfo.iDriveCount,
|
sl@0
|
287 |
demandPagingInfo.iPagingType,
|
sl@0
|
288 |
demandPagingInfo.iReadShift,
|
sl@0
|
289 |
demandPagingInfo.iNumPages);
|
sl@0
|
290 |
|
sl@0
|
291 |
// Ignore error if demand paging not supported by kernel
|
sl@0
|
292 |
if (err == KErrNotSupported)
|
sl@0
|
293 |
err = KErrNone;
|
sl@0
|
294 |
|
sl@0
|
295 |
if (err != KErrNone)
|
sl@0
|
296 |
break;
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
if (mi.iFlags & TMMCMachineInfo::ESupportsDMA)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
err = LocDrv::RegisterDmaDevice(pMedia,
|
sl@0
|
302 |
KMMCardHighCapBlockSize,
|
sl@0
|
303 |
pS->MaxDataTransferLength(),
|
sl@0
|
304 |
pS->DmaAlignment());
|
sl@0
|
305 |
if (err != KErrNone)
|
sl@0
|
306 |
break;
|
sl@0
|
307 |
}
|
sl@0
|
308 |
#endif // __WINS__
|
sl@0
|
309 |
|
sl@0
|
310 |
driveListIndex+= drivesPerSlot;
|
sl@0
|
311 |
}
|
sl@0
|
312 |
|
sl@0
|
313 |
return(err);
|
sl@0
|
314 |
}
|