os/kernelhwsrv/kernel/eka/include/nkernsmp/nk_irq.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-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\include\nkernsmp\nk_irq.h
sl@0
    15
// 
sl@0
    16
// WARNING: This file contains some APIs which are internal and are subject
sl@0
    17
//          to change without notice. Such APIs should therefore not be used
sl@0
    18
//          outside the Kernel and Hardware Services package.
sl@0
    19
//
sl@0
    20
sl@0
    21
/**
sl@0
    22
 @file
sl@0
    23
 @internalTechnology
sl@0
    24
*/
sl@0
    25
sl@0
    26
#ifndef __NK_IRQ_H__
sl@0
    27
#define __NK_IRQ_H__
sl@0
    28
sl@0
    29
#ifndef NK_MAX_IRQS
sl@0
    30
#if defined(__CPU_ARM)
sl@0
    31
#define NK_MAX_IRQS			96	// 32-127 on GIC
sl@0
    32
#else
sl@0
    33
#define NK_MAX_IRQS			32
sl@0
    34
#endif
sl@0
    35
#endif
sl@0
    36
sl@0
    37
#ifndef NK_MAX_IRQ_HANDLERS
sl@0
    38
#if defined(__CPU_ARM)
sl@0
    39
#define NK_MAX_IRQ_HANDLERS	(1*NK_MAX_IRQS)
sl@0
    40
#else
sl@0
    41
#define NK_MAX_IRQ_HANDLERS	(2*NK_MAX_IRQS)
sl@0
    42
#endif
sl@0
    43
#endif
sl@0
    44
sl@0
    45
#include <nklib.h>
sl@0
    46
#include <nk_event.h>
sl@0
    47
sl@0
    48
class NSchedulable;
sl@0
    49
class NThreadBase;
sl@0
    50
class NThread;
sl@0
    51
class NFastSemaphore;
sl@0
    52
class NFastMutex;
sl@0
    53
sl@0
    54
/******************************************************************************
sl@0
    55
 * Class per peripheral interrupt
sl@0
    56
 ******************************************************************************/
sl@0
    57
class NIrqHandler;
sl@0
    58
class NIrqX;
sl@0
    59
class NIrq
sl@0
    60
	{
sl@0
    61
public:
sl@0
    62
	NIrq();
sl@0
    63
public:
sl@0
    64
	// client services
sl@0
    65
	TInt BindRaw(NIsr aIsr, TAny* aPtr);
sl@0
    66
	TInt UnbindRaw();
sl@0
    67
	TInt DisableRaw(TBool aUnbind);
sl@0
    68
	TInt EnableRaw();
sl@0
    69
	TInt Bind(NIrqHandler* aH);
sl@0
    70
	static TInt FromHandle(TInt& aHandle, NIrq*& aIrq, NIrqHandler*& aHandler);
sl@0
    71
public:
sl@0
    72
	// HW access
sl@0
    73
	void HwIsr();
sl@0
    74
	void HwEoi();
sl@0
    75
	void HwEnable();
sl@0
    76
	void HwDisable();
sl@0
    77
	void HwSetCpu(TInt aCpu);
sl@0
    78
	void HwSetCpuMask(TUint32 aMask);
sl@0
    79
	void HwInit();
sl@0
    80
	static void HwInit0();
sl@0
    81
	static void HwInit1();
sl@0
    82
	static void HwInit2AP();
sl@0
    83
	TBool HwPending();
sl@0
    84
	void HwWaitCpus();
sl@0
    85
public:
sl@0
    86
	// functions to manipulate iIState
sl@0
    87
	TUint32 EnterIsr();			// wait for EWait clear, increment run count, return original iIState
sl@0
    88
	TBool IsrDone();			// decrement run count, return TRUE if still not zero
sl@0
    89
	void Wait();				// wait until run count is zero and we can transition EWait from 0 to 1
sl@0
    90
	void Done();				// set EWait back to 0
sl@0
    91
public:
sl@0
    92
	enum	{	// iStaticFlags
sl@0
    93
			ELevel=0x01,		// set for level triggered, clear for edge
sl@0
    94
			EPolarity=0x02,		// set for active high, clear for active low
sl@0
    95
			EShared=0x10,		// set if interrupt can be shared
sl@0
    96
			};
sl@0
    97
	enum	{	// iIState bits 0-7
sl@0
    98
			EWait=0x01,
sl@0
    99
			ERaw=0x02,			// raw ISR with no processing, can't be shared
sl@0
   100
			ECount=0x04,		// if set count all interrupts else limit pending count to 1
sl@0
   101
			EUnbind=0x08,		// raw ISR being unbound
sl@0
   102
			};
sl@0
   103
public:
sl@0
   104
	TSpinLock			iNIrqLock;
sl@0
   105
	SDblQue				iHandlers;
sl@0
   106
	volatile TUint32	iIState;		// bits 0-7=flags, bits 8-15=CPU on which it is running, bits 16-31=run count
sl@0
   107
	TUint16				iStaticFlags;
sl@0
   108
	TUint16				iIndex;
sl@0
   109
	volatile TUint32	iEventsPending;
sl@0
   110
	volatile TUint32	iEnabledEvents;	// bits 1-31 = count of enabled handlers, bit 0 = 1 if temporarily disabled
sl@0
   111
	volatile TUint32	iGeneration;	// incremented on unbind raw or enable while bound as raw
sl@0
   112
	TUint32				iHwId;
sl@0
   113
	TUint32				iVector;
sl@0
   114
	NIrqX*				iX;
sl@0
   115
	TUint32				iNIrqSpare[16-10-sizeof(TSpinLock)/sizeof(TUint32)];
sl@0
   116
	};
sl@0
   117
sl@0
   118
__ASSERT_COMPILE(!(_FOFF(NIrq,iNIrqLock)&7));
sl@0
   119
__ASSERT_COMPILE(sizeof(NIrq)==64);
sl@0
   120
sl@0
   121
class NIrqX
sl@0
   122
	{
sl@0
   123
public:
sl@0
   124
	typedef void (*TEoiFn)(NIrq*);
sl@0
   125
	typedef void (*TEnableFn)(NIrq*);
sl@0
   126
	typedef void (*TDisableFn)(NIrq*);
sl@0
   127
	typedef void (*TSetCpuFn)(NIrq*, TUint32);
sl@0
   128
	typedef void (*TInitFn)(NIrq*);
sl@0
   129
	typedef TBool (*TPendingFn)(NIrq*);
sl@0
   130
	typedef void (*TWaitFn)(NIrq*);
sl@0
   131
public:
sl@0
   132
	TEoiFn				iEoiFn;
sl@0
   133
	TEnableFn			iEnableFn;
sl@0
   134
	TDisableFn			iDisableFn;
sl@0
   135
	TSetCpuFn			iSetCpuFn;
sl@0
   136
	TInitFn				iInitFn;
sl@0
   137
	TPendingFn			iPendingFn;
sl@0
   138
	TWaitFn				iWaitFn;
sl@0
   139
	};
sl@0
   140
sl@0
   141
/******************************************************************************
sl@0
   142
 * Class per interrupt handler
sl@0
   143
 ******************************************************************************/
sl@0
   144
typedef NEventFn NIsr;
sl@0
   145
class TSubScheduler;
sl@0
   146
class NIrqHandler : public NEventHandler
sl@0
   147
	{
sl@0
   148
public:
sl@0
   149
	NIrqHandler();
sl@0
   150
	static NIrqHandler* Alloc();
sl@0
   151
	void Free();
sl@0
   152
	void Activate(TInt aCount);
sl@0
   153
	TInt Enable(TInt aHandle);
sl@0
   154
	TInt Disable(TBool aUnbind, TInt aHandle);
sl@0
   155
	TInt Unbind(TInt aId, NSchedulable* aTied);
sl@0
   156
	void DoUnbind();
sl@0
   157
public:
sl@0
   158
	// functions to manipulate iHState
sl@0
   159
	TUint32 DoSetEnabled();			// if EUnbound clear, clear EDisable. Return original iHState
sl@0
   160
	TUint32 DoActivate(TInt);
sl@0
   161
	TUint32 EventBegin();
sl@0
   162
	TUint32 EventDone();
sl@0
   163
public:
sl@0
   164
	enum	{	// iHState bits 8-31
sl@0
   165
			EDisable		=0x00000100u,
sl@0
   166
			EUnbind			=0x00000200u,				// this handler is being unbound
sl@0
   167
			EBind			=0x00000400u,				// this handler has been bound but not enabled
sl@0
   168
			ENotReady		=0x00000800u,				// this handler is being bound
sl@0
   169
			ECount			=0x00001000u,				// if set count all interrupts else limit pending count to 1
sl@0
   170
			EActive			=0x00002000u,				// handler is running or about to run
sl@0
   171
			EExclusive		=0x00004000u,				// exclusive access to shared interrupt
sl@0
   172
			ERunCountMask	=0xffff0000u
sl@0
   173
			};
sl@0
   174
public:
sl@0
   175
	SDblQueLink				iIrqLink;		// link to NIrq
sl@0
   176
	NIrq* volatile			iIrq;
sl@0
   177
	volatile TUint32		iGeneration;	// incremented on enable or bind
sl@0
   178
	volatile TUint32		iHandle;		// bits 0-15 = array index, bits 16-30 = cookie, 1-32767
sl@0
   179
	TUint32					iNIrqHandlerSpare[3];		// round to power of 2
sl@0
   180
public:
sl@0
   181
	static NIrqHandler*		FirstFree;		// protected by NEventHandler::TiedLock
sl@0
   182
	};
sl@0
   183
sl@0
   184
__ASSERT_COMPILE(sizeof(NIrqHandler)==64);
sl@0
   185
sl@0
   186
sl@0
   187
#if 0
sl@0
   188
#include <e32btrace.h>
sl@0
   189
#define IRQ_TRACE_CAT			253			// FIXME
sl@0
   190
#define	TRACE_IRQ0(n)			BTraceContextPc0(IRQ_TRACE_CAT, n)
sl@0
   191
#define	TRACE_IRQ4(n,a)			BTraceContextPc4(IRQ_TRACE_CAT, n, a)
sl@0
   192
#define	TRACE_IRQ8(n,a,b)		BTraceContextPc8(IRQ_TRACE_CAT, n, a, b)
sl@0
   193
#define	TRACE_IRQ12(n,a,b,c)	BTraceContextPc12(IRQ_TRACE_CAT, n, a, b, c)
sl@0
   194
#else
sl@0
   195
#define	TRACE_IRQ0(n)
sl@0
   196
#define	TRACE_IRQ4(n,a)
sl@0
   197
#define	TRACE_IRQ8(n,a,b)
sl@0
   198
#define	TRACE_IRQ12(n,a,b,c)
sl@0
   199
#endif
sl@0
   200
sl@0
   201
#endif	// __NK_IRQ_H__