os/kernelhwsrv/kerneltest/e32test/mmu/d_asid.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-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 // e32test\mmu\d_asid.cpp
    15 // 
    16 //
    17 
    18 #include <kernel/kern_priv.h>
    19 #include "d_asid.h"
    20 
    21 //
    22 // Class definitions
    23 //
    24 
    25 class DAsidFactory : public DLogicalDevice
    26 	{
    27 public:
    28 	~DAsidFactory();
    29 	virtual TInt Install();
    30 	virtual void GetCaps(TDes8& aDes) const;
    31 	virtual TInt Create(DLogicalChannelBase*& aChannel);
    32 	};
    33 
    34 class DAsidChannel : public DLogicalChannelBase
    35 	{
    36 public:
    37 	DAsidChannel();
    38 	~DAsidChannel();
    39 	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    40 	virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
    41 public:
    42 	DAsidFactory*	iFactory;
    43 private:
    44 	DThread* iThread;
    45 	};
    46 
    47 //
    48 // DAsidFactory
    49 //
    50 
    51 TInt DAsidFactory::Install()
    52 	{
    53 	return SetName(&KMemoryTestLddName);
    54 	}
    55 
    56 DAsidFactory::~DAsidFactory()
    57 	{
    58 	}
    59 
    60 void DAsidFactory::GetCaps(TDes8& /*aDes*/) const
    61 	{
    62 	// Not used but required as DLogicalDevice::GetCaps is pure virtual
    63 	}
    64 
    65 TInt DAsidFactory::Create(DLogicalChannelBase*& aChannel)
    66 	{
    67 	aChannel = NULL;
    68 	DAsidChannel* channel=new DAsidChannel;
    69 	if(!channel)
    70 		return KErrNoMemory;
    71 	channel->iFactory = this;
    72 	aChannel = channel;
    73 	return KErrNone;
    74 	}
    75 
    76 DECLARE_STANDARD_LDD()
    77 	{
    78 	return new DAsidFactory;
    79 	}
    80 
    81 //
    82 // DAsidChannel
    83 //
    84 
    85 TInt DAsidChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
    86 	{
    87 	return KErrNone;
    88 	}
    89 
    90 DAsidChannel::DAsidChannel() : iThread(NULL)
    91 	{
    92 	}
    93 
    94 DAsidChannel::~DAsidChannel()
    95 	{
    96 	if (iThread)
    97 		iThread->Close(NULL);
    98 	}
    99 
   100 
   101 TInt DAsidChannel::Request(TInt aFunction, TAny* a1, TAny* a2)
   102 	{
   103 	TInt r=KErrNotSupported;
   104 
   105 	switch(aFunction)
   106 		{
   107 		case RAsidLdd::EGetCurrentThread:
   108 			{
   109 			DThread* thread = &Kern::CurrentThread();
   110 			kumemput32(a1, (TAny*)&thread, sizeof(DThread*));
   111 			r = KErrNone;
   112 			}
   113 			break;
   114 
   115 		case RAsidLdd::EOpenThread:
   116 			{
   117 			if (iThread)
   118 				{
   119 				r = KErrInUse;
   120 				break;
   121 				}
   122 			iThread = (DThread*) a1;
   123 			iThread->Open();
   124 			r = KErrNone;
   125 			}
   126 			break;
   127 
   128 		case RAsidLdd::ECloseThread:
   129 			{
   130 			if (!iThread)
   131 				{
   132 				r = KErrNotFound;
   133 				break;
   134 				}
   135 			NKern::ThreadEnterCS();
   136 			iThread->Close(NULL);
   137 			iThread = NULL;
   138 			r = KErrNone;
   139 			NKern::ThreadLeaveCS();
   140 			}
   141 			break;
   142 			
   143 		case RAsidLdd::EReadDesHeader:
   144 			{
   145 			SDesHeader hdr;
   146 			TUint8* ptr;
   147 			kumemget32((TAny*)&hdr, a2, sizeof(SDesHeader));
   148 			r = Kern::ThreadGetDesInfo((DThread*)a1, hdr.iDes, hdr.iLength, hdr.iMaxLength, ptr, ETrue);
   149 			if (r == KErrNone)
   150 				{// copy the data back to user side struct.
   151 				kumemput32(a2, &hdr, sizeof(SDesHeader));
   152 				}
   153 			}
   154 			break;
   155 		}
   156 	return r;
   157 	}