os/kernelhwsrv/kerneltest/e32test/nkernsa/nirqx.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/nkernsa/nirqx.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,151 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\nkernsa\nirqx.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <nk_irq.h>
    1.22 +
    1.23 +#ifdef __X86__
    1.24 +#include <apic.h>
    1.25 +#endif
    1.26 +
    1.27 +class NIrqXTest : public NIrqX
    1.28 +	{
    1.29 +public:
    1.30 +	NIrqXTest();
    1.31 +	void Kick();
    1.32 +	void Set(TBool aLevel);
    1.33 +public:
    1.34 +	static void DoEoi(NIrq* aIrq);
    1.35 +	static void DoEnable(NIrq* aIrq);
    1.36 +	static void DoDisable(NIrq* aIrq);
    1.37 +	static void DoSetCpu(NIrq* aIrq, TUint32 aMask);
    1.38 +	static void DoInit(NIrq* aIrq);
    1.39 +	static TBool DoPending(NIrq* aIrq);
    1.40 +	static void DoWait(NIrq* aIrq);
    1.41 +public:
    1.42 +	TSpinLock			iLock;
    1.43 +	NIrq*				iIrq;
    1.44 +	TUint32				iCpuMask;
    1.45 +	TUint8				iEnabled;
    1.46 +	TUint8				iPending;
    1.47 +	TUint8				iLevel;
    1.48 +	};
    1.49 +
    1.50 +NIrqXTest::NIrqXTest()
    1.51 +	{
    1.52 +	iIrq = 0;
    1.53 +	iCpuMask = 0x1;
    1.54 +	iEnabled = 0;
    1.55 +	iPending = 0;
    1.56 +	iLevel = 0;
    1.57 +	}
    1.58 +
    1.59 +void NIrqXTest::Set(TBool aLevel)
    1.60 +	{
    1.61 +	TBool active = FALSE;
    1.62 +	TInt irq = __SPIN_LOCK_IRQSAVE(iLock);
    1.63 +	TUint32 f = iIrq->iStaticFlags;
    1.64 +	if (f & NIrq::ELevel)
    1.65 +		{
    1.66 +		if (f & NIrq::EPolarity)
    1.67 +			{
    1.68 +			active = aLevel;
    1.69 +			}
    1.70 +		else
    1.71 +			{
    1.72 +			active = !aLevel;
    1.73 +			}
    1.74 +		}
    1.75 +	else
    1.76 +		{
    1.77 +		if (f & NIrq::EPolarity)
    1.78 +			{
    1.79 +			active = aLevel && !iLevel;
    1.80 +			}
    1.81 +		else
    1.82 +			{
    1.83 +			active = !aLevel && iLevel;
    1.84 +			}
    1.85 +		}
    1.86 +	iLevel = (TUint8)(aLevel ? 1 : 0);
    1.87 +	if (active && iEnabled)
    1.88 +		Kick();
    1.89 +	__SPIN_UNLOCK_IRQRESTORE(iLock,irq);
    1.90 +	}
    1.91 +
    1.92 +#if defined (__X86__)
    1.93 +__NAKED__ void NIrqXTest::Kick()
    1.94 +	{
    1.95 +	_asm mov al, 1
    1.96 +	_asm lock xchg al, [ecx]NIrqXTest.iPending
    1.97 +	_asm cmp al, 0
    1.98 +	_asm jne short kick0
    1.99 +	_asm mov eax, [ecx]NIrqXTest.iCpuMask
   1.100 +	_asm shl eax, 24
   1.101 +	_asm jz short kick0	// no CPUs, so nothing to do
   1.102 +	_asm mov ds:[X86_LOCAL_APIC_BASE + X86_LOCAL_APIC_OFFSET_ICRH], eax
   1.103 +	_asm mov eax, [ecx]NIrqXTest.iIrq
   1.104 +	_asm mov eax, [eax]NIrq.iVector
   1.105 +	_asm or eax, 0x4800
   1.106 +	_asm mov ds:[X86_LOCAL_APIC_BASE + X86_LOCAL_APIC_OFFSET_ICRL], eax
   1.107 +	_asm kick0:
   1.108 +	_asm ret
   1.109 +	}
   1.110 +#endif
   1.111 +
   1.112 +void NIrqXTest::DoEoi(NIrq* aIrq)
   1.113 +	{
   1.114 +	NIrqXTest* pX = (NIrqXTest*)iX;
   1.115 +	TInt irq = __SPIN_LOCK_IRQSAVE(pX->iLock);
   1.116 +	if (pX->iPending)
   1.117 +		{
   1.118 +		pX->iPending = 0;
   1.119 +		TUint32 f = aIrq->iStaticFlags;
   1.120 +		if (f & NIrq::ELevel)
   1.121 +			{
   1.122 +			TUint active_level = (f & NIrq::EPolarity) ? 1 : 0;
   1.123 +			if (pX->iLevel==active_level && pX->iEnabled)
   1.124 +				pX->Kick();
   1.125 +			}
   1.126 +		}
   1.127 +	__SPIN_UNLOCK_IRQRESTORE(pX->iLock,irq);
   1.128 +	}
   1.129 +
   1.130 +void NIrqXTest::DoEnable(NIrq* aIrq)
   1.131 +	{
   1.132 +	}
   1.133 +
   1.134 +void NIrqXTest::DoDisable(NIrq* aIrq)
   1.135 +	{
   1.136 +	}
   1.137 +
   1.138 +void NIrqXTest::DoSetCpu(NIrq* aIrq, TUint32 aMask)
   1.139 +	{
   1.140 +	}
   1.141 +
   1.142 +void NIrqXTest::DoInit(NIrq* aIrq)
   1.143 +	{
   1.144 +	iIrq = aIrq;
   1.145 +	}
   1.146 +
   1.147 +TBool NIrqXTest::DoPending(NIrq* aIrq)
   1.148 +	{
   1.149 +	}
   1.150 +
   1.151 +void NIrqXTest::DoWait(NIrq* aIrq)
   1.152 +	{
   1.153 +	}
   1.154 +