baseport/syborg/svpsnapdriver/src/svpsnapdriver.cpp
changeset 2 d55eb581a87c
parent 0 ffa851df0825
equal deleted inserted replaced
1:2fb8b9db1c86 2:d55eb581a87c
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "svpsnapdriver.h"
       
    19 #include "rsvpsnapdriver.h"
       
    20 #include "system.h"
       
    21 
       
    22 static inline TUint32 ReadReg(ESVPSnapReg aReg)
       
    23 {
       
    24   DP("** (SVPSNAPDRIVER) ReadReg(%d)",aReg);
       
    25 
       
    26 	return *(volatile TUint32 *)(KHwSVPSnapDevice + (aReg << 2));
       
    27 }
       
    28 
       
    29 static inline void WriteReg(ESVPSnapReg aReg, TUint32 aVal)
       
    30 {
       
    31   DP("** (SVPSNAPDRIVER) WriteReg(%d,%d)",aReg,aVal);
       
    32 
       
    33   *(volatile TUint32*)(KHwSVPSnapDevice + (aReg << 2)) = aVal;
       
    34 }
       
    35 
       
    36 //
       
    37 // DSVPSnapDriverFactory
       
    38 //
       
    39 
       
    40 DSVPSnapDriverFactory::DSVPSnapDriverFactory()
       
    41 {
       
    42   DP("** (SVPSNAPDRIVER) DSVPSnapDriverFactory::DSVPSnapDriverFactory()");
       
    43 
       
    44   iVersion = TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);    
       
    45 }
       
    46 
       
    47 TInt DSVPSnapDriverFactory::Create(DLogicalChannelBase*& aChannel)
       
    48 {
       
    49   DP("** (SVPSNAPDRIVER) DSVPSnapDriverFactory::Create()");
       
    50 	
       
    51 #if 0
       
    52   if (iOpenChannels != 0)
       
    53 	return KErrInUse; // a channel is already open
       
    54 #endif
       
    55 	
       
    56 	aChannel = new DSVPSnapChannel(this);
       
    57 	
       
    58 	return aChannel ? KErrNone : KErrNoMemory;
       
    59 }
       
    60 
       
    61 TInt DSVPSnapDriverFactory::Install()
       
    62 {
       
    63   DP("** (SVPSNAPDRIVER) DSVPSnapDriverFactory::Install()");
       
    64 
       
    65   return(SetName(&KSVPSnapDriverName));
       
    66 }
       
    67 
       
    68 void DSVPSnapDriverFactory::GetCaps(TDes8& aDes) const
       
    69 {
       
    70   DP("** (SVPSNAPDRIVER) DSVPSnapDriverFactory::GetCaps()");
       
    71 
       
    72   TCapsSVPSnapDriver b;
       
    73   b.iVersion = TVersion(KMajorVersionNumber, KMinorVersionNumber, KBuildVersionNumber);
       
    74   aDes.FillZ(aDes.MaxLength());
       
    75   aDes.Copy((TUint8 *)&b, Min(aDes.MaxLength(), sizeof(b)));
       
    76 }
       
    77 
       
    78 //
       
    79 // DSVPSnapChannel
       
    80 //
       
    81 
       
    82 DSVPSnapChannel::DSVPSnapChannel(DLogicalDevice* aLogicalDevice)
       
    83 {
       
    84   DP("** (SVPSNAPDRIVER) DSVPSnapChannel::DSVPSnapChannel()");
       
    85 
       
    86   iDevice = aLogicalDevice;
       
    87   
       
    88   iClientThread = &Kern::CurrentThread();
       
    89   iClientThread->Open();
       
    90 }
       
    91 
       
    92 DSVPSnapChannel::~DSVPSnapChannel()
       
    93 {
       
    94   DP("** (SVPSNAPDRIVER) DSVPSnapChannel::~DSVPSnapChannel() ->");
       
    95   Kern::SafeClose((DObject*&)iClientThread, NULL);
       
    96   DP("** (SVPSNAPDRIVER) DSVPSnapChannel::~DSVPSnapChannel() <-");
       
    97 }
       
    98 
       
    99 TInt DSVPSnapChannel::DoCreate(TInt /*aUnit*/, const TDesC* anInfo, const TVersion& aVer)
       
   100 {
       
   101   DP("** (SVPSNAPDRIVER) DSVPSnapChannel::DoCreate()");
       
   102 
       
   103   if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber, KMinorVersionNumber, KBuildVersionNumber), aVer))
       
   104 	return KErrNotSupported; 
       
   105 		       
       
   106   //Setup the driver for receiving client messages
       
   107   SetDfcQ(Kern::DfcQue0());
       
   108   iMsgQ.Receive();  	
       
   109 
       
   110   DP("** (SVPSNAPDRIVER) DSVPSnapChannel::DoCreate()- checking device");
       
   111   TUint id = ReadReg(ESnapshot_Id);
       
   112   DP("** (SVPSNAPDRIVER) DSVPSnapChannel::DoCreate()- checked device- 0x%08x", id);
       
   113   WriteReg(ESnapshot_Address, 0);
       
   114   return KErrNone;
       
   115 }
       
   116 
       
   117 void DSVPSnapChannel::DoCancel(TInt aReqNo)
       
   118 {
       
   119   DP("** (SVPSNAPDRIVER) DSVPSnapChannel::DoCancel() %x(%d)", aReqNo, aReqNo);
       
   120 }
       
   121 
       
   122 TInt DSVPSnapChannel::DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2)
       
   123 {
       
   124   DP("** (SVPSNAPDRIVER) DSVPSnapChannel::DoRequest() %x(%d)", aReqNo, aReqNo);
       
   125 
       
   126   TInt err = KErrGeneral;         
       
   127 
       
   128   switch(aReqNo)
       
   129 	{
       
   130 	case RSVPSnapDriver::ESaveVM:
       
   131 	  	  DP("RSVPSnapDriver::ESaveVM");
       
   132 	  	  err = SaveVM((const TDesC8*)a1);
       
   133 	  break;
       
   134 	case RSVPSnapDriver::ELoadVM:
       
   135 	  	 DP("RSVPSnapDriver::ELoadVM");
       
   136 	  	 err= LoadVM((const TDesC8*)a1);
       
   137 	  break;
       
   138 	default:
       
   139 	  	  DP("default");
       
   140 	  err = KErrGeneral;
       
   141 	  break;
       
   142 	}
       
   143 	
       
   144   if (KErrNone != err)
       
   145 	DP("** (SVPSNAPDRIVER) Error %d from DoRequest", err);
       
   146 	
       
   147   return err;
       
   148 }
       
   149 
       
   150 TInt DSVPSnapChannel::DoControl(TInt aFunction, TAny* a1, TAny* a2)
       
   151 {
       
   152   DP("** (SVPSNAPDRIVER) DSVPSnapChannel::DoControl(%d)", aFunction);
       
   153 
       
   154   TInt err = KErrGeneral;         
       
   155   /* There should be a good reason to use a control rather than a request. */
       
   156 
       
   157   if (KErrNone != err) {
       
   158 	DP("** (SVPSNAPDRIVER) Error %d from control function", err);
       
   159   }
       
   160 	
       
   161   return err;
       
   162 }
       
   163 
       
   164 void DSVPSnapChannel::HandleMsg(TMessageBase* aMsg)
       
   165 {
       
   166 	
       
   167   TThreadMessage& m = *(TThreadMessage*)aMsg;
       
   168   TInt id = m.iValue;
       
   169   
       
   170   DP("** (SVPSNAPDRIVER) DSVPSnapChannel::HandleMsg() %x(%d)", id, id);
       
   171 
       
   172   if (id == (TInt)ECloseMsg)
       
   173 	{
       
   174 	  m.Complete(KErrNone, EFalse); 
       
   175 	  return;
       
   176 	}
       
   177   if (id == KMaxTInt)
       
   178 	{
       
   179 	  // DoCancel
       
   180 	  DoCancel(m.Int0());
       
   181 	  m.Complete(KErrNone, ETrue); 
       
   182 	  return;
       
   183 	}
       
   184   if (id < 0)
       
   185 	{
       
   186 	  // DoRequest
       
   187 	  TRequestStatus* pStatus = (TRequestStatus*)m.Ptr0();
       
   188 	  TInt r = DoRequest(~id, pStatus, m.Ptr1(), m.Ptr2());
       
   189 	  //	  if (r != KErrNone)
       
   190 	  Kern::RequestComplete(iClientThread,pStatus,r);
       
   191 	  m.Complete(KErrNone, ETrue);
       
   192 	}
       
   193   else
       
   194 	{
       
   195 	  // DoControl
       
   196 	  TInt r = DoControl(id, m.Ptr0(), m.Ptr1());
       
   197 	  m.Complete(r, ETrue);
       
   198 	}
       
   199 }
       
   200 
       
   201 TInt DSVPSnapChannel::SaveVM(const TDesC8* aData)
       
   202 {
       
   203   DP("** DSVPSnapChannel::SaveVM()");
       
   204    
       
   205   TInt err = KErrNone; 
       
   206   RET_IF_ERROR(err, Kern::ThreadDesRead(iClientThread, aData, iSendDataBuffer,0));
       
   207   TUint32 * ptr = (TUint32*) iSendDataBuffer.Ptr();
       
   208   
       
   209   WriteReg(ESnapshot_Address, Epoc::LinearToPhysical((TUint32)ptr));
       
   210   WriteReg(ESnapshot_Length, (TUint32) (iSendDataBuffer.Length()));
       
   211   WriteReg(ESnapshot_Trigger, RSVPSnapDriver::ESaveVM);
       
   212   
       
   213   return err;
       
   214 }
       
   215 
       
   216 TInt DSVPSnapChannel::LoadVM(const TDesC8* aData)
       
   217 {
       
   218   DP("** DSVPSnapChannel::LoadVM()");  
       
   219 
       
   220   TInt err = KErrNone; 
       
   221   RET_IF_ERROR(err, Kern::ThreadDesRead(iClientThread, aData, iSendDataBuffer,0));
       
   222   
       
   223   TUint32 * ptr = (TUint32*) iSendDataBuffer.Ptr();  
       
   224   WriteReg(ESnapshot_Address, Epoc::LinearToPhysical((TUint32)ptr));
       
   225   
       
   226   return ReadReg(ESnapshot_Address);
       
   227 }
       
   228 
       
   229 DECLARE_EXTENSION_LDD()
       
   230 {
       
   231   // FIXME: Not needed?
       
   232   DP("** (SVPSNAPDRIVER) DSVPSnapDriverFactory created");
       
   233   return new DSVPSnapDriverFactory;
       
   234 }
       
   235 
       
   236 DECLARE_STANDARD_EXTENSION()
       
   237 {
       
   238   DP("** (SVPSNAPDRIVER) SVPSnap extension entry point");
       
   239   TInt r;
       
   240   DSVPSnapDriverFactory* device = new DSVPSnapDriverFactory;
       
   241   if (device==NULL)
       
   242 	r=KErrNoMemory;
       
   243   else
       
   244 	r=Kern::InstallLogicalDevice(device);
       
   245   
       
   246   return r;
       
   247 }