os/kernelhwsrv/kernel/eka/drivers/pbus/pccard/epoc/pccd_init.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 1995-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\pbus\pccard\epoc\pccd_init.cpp
    15 // 
    16 //
    17 
    18 #include <pccd_ifc.h>
    19 #include "pbusmedia.h"
    20 
    21 GLDEF_D TPcCardControllerInterface* ThePccdCntrlInterface=NULL;
    22 
    23 EXPORT_C TInt TPcCardControllerInterface::Create()
    24 //
    25 // Allocate any resources. Only done once on kernel initialization so don't
    26 // worry about cleanup if it fails.
    27 //
    28 	{
    29 	__KTRACE_OPT(KPBUS1,Kern::Printf(">TPcCardControllerInterface::Create"));
    30 	ThePccdCntrlInterface=this;
    31 	Init();
    32 	TInt r=KErrNone;
    33 	SMediaDeviceInfo mdi;
    34 	TInt i;
    35 	for (i=0; i<KMaxPBusSockets && r==KErrNone; i++)
    36 		{
    37 		if (IsPcCardSocket(i,mdi))
    38 			{
    39 			__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d is PC card",i));
    40 			DPcCardSocket* pS=PccdIfc::NewSocket(i);
    41 			if (!pS)
    42 				{
    43 				r=KErrNoMemory;
    44 				break;
    45 				}
    46 			TheSockets[i]=pS;
    47 			TInt mcid=MediaChangeFromSocket(i);
    48 			__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d Media Change %d",i,mcid));
    49 			DPcCardMediaChange* pM=(DPcCardMediaChange*)TheMediaChanges[mcid];
    50 			if (!pM)
    51 				{
    52 				__KTRACE_OPT(KPBUS1,Kern::Printf("New Media Change"));
    53 				pM=PccdIfc::NewMediaChange(mcid);
    54 				if (!pM)
    55 					{
    56 					r=KErrNoMemory;
    57 					break;
    58 					}
    59 				TheMediaChanges[mcid]=pM;
    60 				__KTRACE_OPT(KPBUS1,Kern::Printf("Media Change %d at %08x",mcid,pM));
    61 				r=pM->Create();
    62 				if (r!=KErrNone)
    63 					break;
    64 				}
    65 			else
    66 				{
    67 				__KTRACE_OPT(KPBUS1,Kern::Printf("Media Change %d already exists at %08x",mcid,pM));
    68 				++pM->iReplyCount;
    69 				}
    70 			TInt vcc=VccFromSocket(i);
    71 			__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d Vcc %d",i,vcc));
    72 			DPcCardVcc* pV=(DPcCardVcc*)TheVccs[vcc];
    73 			if (!pV)
    74 				{
    75 				__KTRACE_OPT(KPBUS1,Kern::Printf("New Vcc"));
    76 				pV=PccdIfc::NewVcc(vcc,mcid);
    77 				if (!pV)
    78 					{
    79 					r=KErrNoMemory;
    80 					break;
    81 					}
    82 				TheVccs[vcc]=pV;
    83 				__KTRACE_OPT(KPBUS1,Kern::Printf("Vcc %d at %08x",vcc,pV));
    84 				r=pV->Create();
    85 				if (r!=KErrNone)
    86 					break;
    87 				}
    88 			else 
    89 				{
    90 				__KTRACE_OPT(KPBUS1,Kern::Printf("Vcc %d already exists at %08x, mcid=%d",vcc,pV,pV->iMediaChangeNum));
    91 // DISALLOW SHARED PSUs UNTIL SOMEONE NEEDS THEM
    92 //				if (pV->iMediaChangeNum!=mcid)
    93 //					{
    94 					r=KErrInUse;
    95 //					break;
    96 //					}
    97 				}
    98 			r=pS->Create(mdi.iDeviceName);
    99 			if (r!=KErrNone)
   100 				break;
   101 			pS->iMediaChangeNumber=mcid;
   102 			pS->iMediaChange=pM;
   103 			pS->iVcc=pV;
   104 			pV->iSocket=pS;
   105 			
   106 			r=pS->Init();
   107 			if (r!=KErrNone)		
   108 				break;
   109 
   110 			__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d Created OK",i));
   111 			}
   112 		else
   113 			__KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d not PC card",i));
   114 		}
   115 	
   116 	for (i=0; i<KMaxPBusSockets && r==KErrNone; i++)
   117 		{
   118 		if (IsPcCardSocket(i,mdi))
   119 			{
   120 			DPBusSocket* pS=TheSockets[i];
   121 			DPBusPrimaryMedia* pM=new DPBusPrimaryMedia(pS);
   122 			if (!pM)
   123 				return KErrNoMemory;
   124 			r=LocDrv::RegisterMediaDevice(mdi.iDevice,mdi.iDriveCount,mdi.iDriveList,pM,mdi.iNumMedia,*mdi.iDeviceName);
   125 			__KTRACE_OPT(KPBUS1,Kern::Printf("Registering PcCard device %lS (socket %d) for %d drives returns %d",mdi.iDeviceName,pM->iSocket->iSocketNumber,mdi.iDriveCount,r));
   126 			if (r!=KErrNone)
   127 				return r;
   128 			}
   129 		}
   130 	__KTRACE_OPT(KPBUS1,Kern::Printf("<TPcCardControllerInterface::Create, ret %d",r));
   131 	return r;
   132 	}
   133