os/kernelhwsrv/kernel/eka/nkernsmp/arm/nccpu.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
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\nccpu.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <arm.h>
sl@0
    19
#include <arm_gic.h>
sl@0
    20
#include <arm_scu.h>
sl@0
    21
#include <arm_tmr.h>
sl@0
    22
sl@0
    23
extern "C" {
sl@0
    24
extern SVariantInterfaceBlock* VIB;
sl@0
    25
}
sl@0
    26
sl@0
    27
struct SAPBootPage : public SFullArmRegSet
sl@0
    28
	{
sl@0
    29
	volatile T_UintPtr	iAPBootPtr[KMaxCpus];
sl@0
    30
	volatile T_UintPtr	iBootFlags;
sl@0
    31
	volatile T_UintPtr	iBootFlags2;
sl@0
    32
	volatile T_UintPtr	iBootFlags3;
sl@0
    33
	volatile T_UintPtr	iBootFlags4;
sl@0
    34
	volatile TUint64	iBPTimestamp;
sl@0
    35
	volatile TUint64	iAPTimestamp;
sl@0
    36
	};
sl@0
    37
sl@0
    38
extern "C" void _ApEntry();
sl@0
    39
extern "C" void KickCpu(volatile T_UintPtr* aPtr, T_UintPtr aRegsPhys);
sl@0
    40
extern void DumpFullRegSet(SFullArmRegSet& a);
sl@0
    41
sl@0
    42
TInt NKern::BootAP(volatile SAPBootInfo* aInfo)
sl@0
    43
	{
sl@0
    44
	volatile SArmAPBootInfo& a = *(volatile SArmAPBootInfo*)aInfo;
sl@0
    45
	__KTRACE_OPT(KBOOT,DEBUGPRINT("NKern::BootAP %d %08x+%x", a.iCpu, a.iInitStackBase, a.iInitStackSize));
sl@0
    46
sl@0
    47
	T_UintPtr bp_phys = a.iAPBootPhys;
sl@0
    48
	T_UintPtr BootFlagsPhys = bp_phys + (T_UintPtr)_FOFF(SAPBootPage,iBootFlags);
sl@0
    49
	volatile SAPBootPage& bootPage = *(volatile SAPBootPage*)a.iAPBootLin;
sl@0
    50
	Arm::SaveState((SFullArmRegSet&)bootPage);
sl@0
    51
	NKern::EnableAllInterrupts();	// Arm::SaveState() disables interrupts
sl@0
    52
sl@0
    53
	TLinAddr BootFlagsLin = (TLinAddr)&bootPage.iBootFlags;
sl@0
    54
	TLinAddr init_sp = a.iInitStackBase + a.iInitStackSize;
sl@0
    55
sl@0
    56
	volatile T_UintPtr* pB = (volatile T_UintPtr*)BootFlagsLin;
sl@0
    57
	*pB = 0;
sl@0
    58
	pB[1] = 0;
sl@0
    59
	pB[2] = 0;
sl@0
    60
	pB[3] = 0;
sl@0
    61
sl@0
    62
	__KTRACE_OPT(KBOOT,DEBUGPRINT("BootFlagsPhys=%08x BootFlagsLin=%08x RegsPhys=%08x RegsLin=%08x",
sl@0
    63
		BootFlagsPhys, BootFlagsLin, bp_phys, &bootPage));
sl@0
    64
	__KTRACE_OPT(KBOOT,DEBUGPRINT("SCU: iCtrl=%08x iConfig=%08x iCpuStat=%08x", SCU.iCtrl, SCU.iConfig, SCU.iCpuStatus));
sl@0
    65
sl@0
    66
	bootPage.iN.iR13Abt		= a.iInitR13Abt;
sl@0
    67
	bootPage.iN.iR13Und		= a.iInitR13Und;
sl@0
    68
	bootPage.iN.iR13Irq		= a.iInitR13Irq;
sl@0
    69
	bootPage.iN.iR13Fiq		= a.iInitR13Fiq;
sl@0
    70
	bootPage.iN.iR13Svc		= init_sp;
sl@0
    71
	bootPage.iN.iFlags		= 0x1D3;
sl@0
    72
	bootPage.iN.iR1			= (TUint32)a.iAPBootPageDirPhys;
sl@0
    73
	bootPage.iN.iR2			= TUint32(a.iAPBootCodeLin) - TUint32(a.iAPBootCodePhys);
sl@0
    74
	bootPage.iN.iR3			= (TUint32)a.iAPBootLin;
sl@0
    75
	bootPage.iN.iR4			= (TUint32)aInfo;
sl@0
    76
	bootPage.iN.iR5			= BootFlagsPhys;
sl@0
    77
	bootPage.iN.iR6			= BootFlagsLin;
sl@0
    78
	bootPage.iN.iR7			= a.iInitStackSize;
sl@0
    79
	bootPage.iN.iR15		= (TLinAddr)&_ApEntry;
sl@0
    80
	bootPage.iB[0].iRWRWTID	= 0;
sl@0
    81
	bootPage.iB[0].iRWROTID	= 0;
sl@0
    82
	bootPage.iB[0].iRWNOTID	= 0;
sl@0
    83
sl@0
    84
	__KTRACE_OPT(KBOOT,DumpFullRegSet((SFullArmRegSet&)bootPage));
sl@0
    85
sl@0
    86
	arm_dsb();	// ensure writes to uncached memory visible
sl@0
    87
sl@0
    88
	KickCpu(&bootPage.iAPBootPtr[a.iCpu], bp_phys);
sl@0
    89
sl@0
    90
	TUint32 n = TUint32(VIB->iMaxCpuClock >> 3);
sl@0
    91
	n = -n;
sl@0
    92
	TUint32 b = 0;
sl@0
    93
	do	{
sl@0
    94
		++n;
sl@0
    95
		b = *pB;
sl@0
    96
		} while(b!=init_sp && n!=0);
sl@0
    97
	arm_dsb();
sl@0
    98
sl@0
    99
	__KTRACE_OPT(KBOOT,DEBUGPRINT("BootFlag=%08x %08x %08x %08x n=%d", b, n, pB[1], pB[2], pB[3]));
sl@0
   100
	__KTRACE_OPT(KBOOT,DEBUGPRINT("SCU: iCtrl=%08x iConfig=%08x iCpuStat=%08x", SCU.iCtrl, SCU.iConfig, SCU.iCpuStatus));
sl@0
   101
	if (n==0)
sl@0
   102
		return KErrTimedOut;
sl@0
   103
	NKern::DisableAllInterrupts();
sl@0
   104
	arm_dsb();
sl@0
   105
	while (bootPage.iBootFlags2==0)
sl@0
   106
		{}
sl@0
   107
	arm_dsb();
sl@0
   108
	bootPage.iBootFlags2 = 2;
sl@0
   109
	arm_dsb();
sl@0
   110
	bootPage.iBPTimestamp = NKern::Timestamp();
sl@0
   111
	arm_dsb();
sl@0
   112
	while (bootPage.iBootFlags2==2)
sl@0
   113
		{}
sl@0
   114
	arm_dsb();
sl@0
   115
	NKern::EnableAllInterrupts();
sl@0
   116
	return KErrNone;
sl@0
   117
	}
sl@0
   118
sl@0
   119
void InitAPTimestamp(SNThreadCreateInfo& aInfo)
sl@0
   120
	{
sl@0
   121
	volatile SArmAPBootInfo& a = *(volatile SArmAPBootInfo*)aInfo.iParameterBlock;
sl@0
   122
	volatile SAPBootPage& bootPage = *(volatile SAPBootPage*)a.iAPBootLin;
sl@0
   123
	NKern::DisableAllInterrupts();
sl@0
   124
	bootPage.iBootFlags2 = 1;
sl@0
   125
	arm_dsb();
sl@0
   126
	while (bootPage.iBootFlags2==1)
sl@0
   127
		{}
sl@0
   128
	arm_dsb();
sl@0
   129
	bootPage.iAPTimestamp = NKern::Timestamp();
sl@0
   130
	arm_dsb();
sl@0
   131
	TUint64 bpt = bootPage.iBPTimestamp;
sl@0
   132
	TUint64 apt = bootPage.iAPTimestamp;
sl@0
   133
	TUint64 delta = bpt - apt;
sl@0
   134
	SubScheduler().iLastTimestamp64 += delta;
sl@0
   135
	__KTRACE_OPT(KBOOT,DEBUGPRINT("APT=0x%lx BPT=0x%lx Delta=0x%lx", apt, bpt, delta));
sl@0
   136
	arm_dsb();
sl@0
   137
	bootPage.iBootFlags2 = 3;
sl@0
   138
	NKern::EnableAllInterrupts();
sl@0
   139
	}
sl@0
   140