os/kernelhwsrv/kernel/eka/nkernsmp/arm/ncirq.cia
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-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\nkernsmp\arm\ncirq.cia
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
 @internalTechnology
sl@0
    21
*/
sl@0
    22
sl@0
    23
#include "nk_priv.h"
sl@0
    24
#include "nk_plat.h"
sl@0
    25
#include <nk_irq.h>
sl@0
    26
#include <arm.h>
sl@0
    27
#include <arm_gic.h>
sl@0
    28
#include <arm_scu.h>
sl@0
    29
#include <arm_tmr.h>
sl@0
    30
sl@0
    31
// 
sl@0
    32
// Atomically increment run count provided ECount set or count <2.
sl@0
    33
// If originally zero, atomically set CPU field
sl@0
    34
// Wait for EWait to be clear
sl@0
    35
// Return state of iIState immediately before increment
sl@0
    36
// 
sl@0
    37
__NAKED__ TUint32 NIrq::EnterIsr()
sl@0
    38
	{
sl@0
    39
	GET_RWNO_TID(,r12);
sl@0
    40
	asm("add	r3, r0, #%a0" : : "i" _FOFF(NIrq,iIState));
sl@0
    41
	asm("ldr	r12, [r12, #%a0]" : : "i" _FOFF(TSubScheduler,iCpuNum));
sl@0
    42
sl@0
    43
	asm("1: ");
sl@0
    44
	LDREX(0,3);
sl@0
    45
	asm("mov	r1, r0 ");
sl@0
    46
	asm("cmp	r0, #0x10000 ");		// run count >= 1 ?
sl@0
    47
	asm("biclo	r1, r1, #0xff00 ");		// if not, update CPU
sl@0
    48
	asm("orrlo	r1, r1, r12, lsl #8 ");
sl@0
    49
	asm("add	r1, r1, #0x10000 ");	// increment run count
sl@0
    50
	asm("cmp	r1, #0x20000 ");		// >= 2 ?
sl@0
    51
	asm("bhs	3f ");
sl@0
    52
	asm("2: ");
sl@0
    53
	STREX(2,1,3);
sl@0
    54
	asm("cmp	r2, #0 ");
sl@0
    55
	asm("bne	1b ");
sl@0
    56
sl@0
    57
	asm("4: ");
sl@0
    58
	__DATA_MEMORY_BARRIER__(r2);
sl@0
    59
	asm("tst	r1, #%a0" : : "i" (NIrq::EWait));
sl@0
    60
	asm("bne	5f ");
sl@0
    61
	__JUMP(,lr);
sl@0
    62
sl@0
    63
	asm("3: ");
sl@0
    64
	asm("tst	r1, #%a0" : : "i" (NIrq::ECount|NIrq::ERaw));
sl@0
    65
	asm("bne	2b ");
sl@0
    66
	asm("mov	r2, #0 ");
sl@0
    67
	asm("b		4b ");
sl@0
    68
sl@0
    69
	asm("5: ");
sl@0
    70
	ARM_WFE;
sl@0
    71
	asm("ldr	r1, [r3] ");
sl@0
    72
	asm("b		4b ");
sl@0
    73
	}
sl@0
    74
sl@0
    75
//
sl@0
    76
// Atomically decrement run count
sl@0
    77
// Return TRUE if run count nonzero after decrement
sl@0
    78
//
sl@0
    79
__NAKED__ TBool NIrq::IsrDone()
sl@0
    80
	{
sl@0
    81
	asm("add	r3, r0, #%a0" : : "i" _FOFF(NIrq,iIState));
sl@0
    82
	__DATA_MEMORY_BARRIER_Z__(r2);
sl@0
    83
sl@0
    84
	asm("1: ");
sl@0
    85
	LDREX(0,3);
sl@0
    86
	asm("subs	r1, r0, #0x10000 ");
sl@0
    87
	STREX(2,1,3);
sl@0
    88
	asm("cmp	r2, #0 ");
sl@0
    89
	asm("bne	1b ");
sl@0
    90
	asm("mov	r0, r1, lsr #16 ");	// r0 = new run count = TRUE if nonzero
sl@0
    91
	__JUMP(,lr);
sl@0
    92
	}
sl@0
    93
sl@0
    94
//
sl@0
    95
// Wait (allowing interrupts and preemption) until run count = 0 and EWait clear
sl@0
    96
// Then atomically set EWait and return with interrupts disabled
sl@0
    97
//
sl@0
    98
__NAKED__ void NIrq::Wait()
sl@0
    99
	{
sl@0
   100
	asm("add	r3, r0, #%a0" : : "i" _FOFF(NIrq,iIState));
sl@0
   101
sl@0
   102
	asm("0: ");
sl@0
   103
	__ASM_CLI();
sl@0
   104
sl@0
   105
	asm("1: ");
sl@0
   106
	LDREX(0,3);
sl@0
   107
	asm("mov	r1, r0, ror #1 ");	// bit 31 = wait, bits 15-30 = run count
sl@0
   108
	asm("cmp	r1, #0x8000 ");		// run count and EWait both zero?
sl@0
   109
	asm("bcs	2f ");				// if not, must wait
sl@0
   110
	asm("orr	r1, r0, #1 ");		// else try to set EWait
sl@0
   111
	STREX(2,1,3);
sl@0
   112
	asm("cmp	r2, #0 ");
sl@0
   113
	asm("bne	1b ");
sl@0
   114
	__DATA_MEMORY_BARRIER__(r2);
sl@0
   115
	__JUMP(,lr);					// success - return with interrupts disabled
sl@0
   116
sl@0
   117
	// spin, allowing interrupts, while we wait for run count and EWait both zero
sl@0
   118
	asm("2: ");
sl@0
   119
	__ASM_STI();
sl@0
   120
	asm("nop ");
sl@0
   121
	ARM_WFE;
sl@0
   122
	asm("nop ");
sl@0
   123
	asm("b		0b ");
sl@0
   124
	}
sl@0
   125
sl@0
   126
//
sl@0
   127
// Atomically clear EWait and reenable interrupts
sl@0
   128
//
sl@0
   129
__NAKED__ void NIrq::Done()
sl@0
   130
	{
sl@0
   131
	asm("add	r3, r0, #%a0" : : "i" _FOFF(NIrq,iIState));
sl@0
   132
	__DATA_MEMORY_BARRIER_Z__(r2);
sl@0
   133
sl@0
   134
	asm("1: ");
sl@0
   135
	LDREX(0,3);
sl@0
   136
	asm("bic	r0, r0, #1 ");		// clear EWait
sl@0
   137
	STREX(2,0,3);
sl@0
   138
	asm("cmp	r2, #0 ");
sl@0
   139
	asm("bne	1b ");
sl@0
   140
	__DATA_SYNC_BARRIER__(r2);		// ensure completion before SEV
sl@0
   141
	ARM_SEV;						// kick any waiting processors
sl@0
   142
	__ASM_STI();					// interrupts back on
sl@0
   143
	__JUMP(,lr);
sl@0
   144
	}
sl@0
   145
sl@0
   146
sl@0
   147
sl@0
   148
//
sl@0
   149
// atomic { if !EUnbind && !ENotReady clear EDisable }
sl@0
   150
// Return the initial value of iHState
sl@0
   151
//
sl@0
   152
__NAKED__ TUint32 NIrqHandler::DoSetEnabled()
sl@0
   153
	{
sl@0
   154
	asm("add	r3, r0, #%a0" : : "i" _FOFF(NIrqHandler,iHState));
sl@0
   155
	__DATA_MEMORY_BARRIER_Z__(r2);
sl@0
   156
sl@0
   157
	asm("1: ");
sl@0
   158
	LDREX(0,3);
sl@0
   159
	asm("tst	r0, #%a0" : : "i" (NIrqHandler::EUnbind|NIrqHandler::ENotReady));
sl@0
   160
	asm("bne	2f ");			// if EUnbind or ENotReady, finished
sl@0
   161
	asm("bic	r1, r0, #%a0" : : "i" (NIrqHandler::EDisable|NIrqHandler::EBind));
sl@0
   162
	STREX(2,1,3);
sl@0
   163
	asm("cmp	r2, #0 ");
sl@0
   164
	asm("bne	1b ");
sl@0
   165
sl@0
   166
	asm("2: ");
sl@0
   167
	__DATA_MEMORY_BARRIER__(r2);
sl@0
   168
	__JUMP(,lr);
sl@0
   169
	}
sl@0
   170
sl@0
   171
//
sl@0
   172
// Atomically increment run count by aCount if ECount set or run count initially zero.
sl@0
   173
// If !EDisable and !EUnbind set EActive
sl@0
   174
// Return initial iHState
sl@0
   175
//
sl@0
   176
__NAKED__ TUint32 NIrqHandler::DoActivate(TInt /*aCount*/)
sl@0
   177
	{
sl@0
   178
	asm("add	r3, r0, #%a0" : : "i" _FOFF(NIrqHandler,iHState));
sl@0
   179
sl@0
   180
	asm("1: ");
sl@0
   181
	LDREX(0,3);
sl@0
   182
	asm("mov	r2, r0 ");
sl@0
   183
	asm("cmp	r0, #0x10000 ");
sl@0
   184
	asm("blo	2f ");			// if run count initially zero, skip
sl@0
   185
	asm("tst	r0, #%a0" : : "i" (NIrqHandler::ECount));
sl@0
   186
	asm("beq	3f ");			// else if !ECount, don't increment
sl@0
   187
	asm("2: ");
sl@0
   188
	asm("add	r2, r2, r1, lsl #16 ");	// add aCount to run count
sl@0
   189
	asm("3: ");
sl@0
   190
	asm("tst	r2, #%a0" : : "i" (NIrqHandler::EUnbind|NIrqHandler::EDisable));
sl@0
   191
	asm("orreq	r2, r2, #%a0" : : "i" (NIrqHandler::EActive));	// if !EUnbind && !EDisable, set EActive
sl@0
   192
	STREX(12,2,3);
sl@0
   193
	asm("cmp	r12, #0 ");
sl@0
   194
	asm("bne	1b ");
sl@0
   195
	__DATA_MEMORY_BARRIER__(r12);
sl@0
   196
	__JUMP(,lr);
sl@0
   197
	}
sl@0
   198
sl@0
   199
//
sl@0
   200
// Decrement run count
sl@0
   201
// Return initial iHState
sl@0
   202
//
sl@0
   203
__NAKED__ TUint32 NIrqHandler::EventBegin()
sl@0
   204
	{
sl@0
   205
	asm("add	r3, r0, #%a0" : : "i" _FOFF(NIrqHandler,iHState));
sl@0
   206
sl@0
   207
	asm("1: ");
sl@0
   208
	LDREX(0,3);
sl@0
   209
	asm("sub	r2, r0, #0x10000 ");
sl@0
   210
	STREX(12,2,3);
sl@0
   211
	asm("cmp	r12, #0 ");
sl@0
   212
	asm("bne	1b ");
sl@0
   213
	__DATA_MEMORY_BARRIER__(r12);
sl@0
   214
	__JUMP(,lr);
sl@0
   215
	}
sl@0
   216
sl@0
   217
//
sl@0
   218
// If count is zero or EDisable or EUnbind
sl@0
   219
// are set, clear EActive.
sl@0
   220
// Return initial iHState, except for new EActive bit
sl@0
   221
//
sl@0
   222
__NAKED__ TUint32 NIrqHandler::EventDone()
sl@0
   223
	{
sl@0
   224
	asm("add	r3, r0, #%a0" : : "i" _FOFF(NIrqHandler,iHState));
sl@0
   225
	__DATA_MEMORY_BARRIER_Z__(r12);
sl@0
   226
sl@0
   227
	asm("1: ");
sl@0
   228
	LDREX(0,3);
sl@0
   229
	asm("mov	r2, r0 ");
sl@0
   230
	asm("cmp	r0, #0x10000 ");	// run count zero ?
sl@0
   231
	asm("tsths	r2, #%a0" : : "i" (NIrqHandler::EUnbind|NIrqHandler::EDisable));	// if so, test EUnbind and EDisable
sl@0
   232
	asm("bicne	r2, r2, #%a0" : : "i" (NIrqHandler::EActive));	// if runcount==0 or EUnbind or EDisable set, clear EActive
sl@0
   233
	STREX(12,2,3);
sl@0
   234
	asm("cmp	r12, #0 ");
sl@0
   235
	asm("bne	1b ");
sl@0
   236
	asm("tst	 r2, #%a0" : : "i" (NIrqHandler::EActive));	// EActive now clear in new value ?
sl@0
   237
	asm("biceq	r0, r0, #%a0" : : "i" (NIrqHandler::EActive));	// if so, clear it in return value
sl@0
   238
	__JUMP(,lr);
sl@0
   239
	}
sl@0
   240