kernel/eka/nkernsmp/arm/nccpu.cpp
branchRCL_3
changeset 256 c1f20ce4abcf
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
249:a179b74831c9 256:c1f20ce4abcf
    18 #include <arm.h>
    18 #include <arm.h>
    19 #include <arm_gic.h>
    19 #include <arm_gic.h>
    20 #include <arm_scu.h>
    20 #include <arm_scu.h>
    21 #include <arm_tmr.h>
    21 #include <arm_tmr.h>
    22 
    22 
    23 extern "C" {
       
    24 extern SVariantInterfaceBlock* VIB;
       
    25 }
       
    26 
    23 
    27 struct SAPBootPage : public SFullArmRegSet
    24 struct SAPBootPage : public SFullArmRegSet
    28 	{
    25 	{
    29 	volatile T_UintPtr	iAPBootPtr[KMaxCpus];
    26 	volatile T_UintPtr	iAPBootPtr[KMaxCpus];
    30 	volatile T_UintPtr	iBootFlags;
    27 	volatile T_UintPtr	iBootFlags;
    31 	volatile T_UintPtr	iBootFlags2;
    28 	volatile T_UintPtr	iBootFlags2;
    32 	volatile T_UintPtr	iBootFlags3;
    29 	volatile T_UintPtr	iBootFlags3;
    33 	volatile T_UintPtr	iBootFlags4;
    30 	volatile T_UintPtr	iBootFlags4;
    34 	volatile TUint64	iBPTimestamp;
    31 	volatile TUint64	iBPTimestamp;
    35 	volatile TUint64	iAPTimestamp;
    32 	volatile TUint64	iAPTimestamp;
       
    33 
       
    34 	TUint32				i_SAPBootPage_Spare[624];
       
    35 
       
    36 	UPerCpuUncached		iPerCpu[KMaxCpus];
    36 	};
    37 	};
       
    38 
       
    39 __ASSERT_COMPILE(sizeof(SAPBootPage)==4096);
       
    40 
    37 
    41 
    38 extern "C" void _ApEntry();
    42 extern "C" void _ApEntry();
    39 extern "C" void KickCpu(volatile T_UintPtr* aPtr, T_UintPtr aRegsPhys);
    43 extern "C" void KickCpu(volatile T_UintPtr* aPtr, T_UintPtr aRegsPhys);
    40 extern void DumpFullRegSet(SFullArmRegSet& a);
    44 extern void DumpFullRegSet(SFullArmRegSet& a);
    41 
    45 
    85 
    89 
    86 	arm_dsb();	// ensure writes to uncached memory visible
    90 	arm_dsb();	// ensure writes to uncached memory visible
    87 
    91 
    88 	KickCpu(&bootPage.iAPBootPtr[a.iCpu], bp_phys);
    92 	KickCpu(&bootPage.iAPBootPtr[a.iCpu], bp_phys);
    89 
    93 
    90 	TUint32 n = TUint32(VIB->iMaxCpuClock >> 3);
    94 	TUint32 n = TUint32(TheScheduler.iVIB->iMaxCpuClock >> 3);
    91 	n = -n;
    95 	n = -n;
    92 	TUint32 b = 0;
    96 	TUint32 b = 0;
    93 	do	{
    97 	do	{
    94 		++n;
    98 		++n;
    95 		b = *pB;
    99 		b = *pB;
    98 
   102 
    99 	__KTRACE_OPT(KBOOT,DEBUGPRINT("BootFlag=%08x %08x %08x %08x n=%d", b, n, pB[1], pB[2], pB[3]));
   103 	__KTRACE_OPT(KBOOT,DEBUGPRINT("BootFlag=%08x %08x %08x %08x n=%d", b, n, pB[1], pB[2], pB[3]));
   100 	__KTRACE_OPT(KBOOT,DEBUGPRINT("SCU: iCtrl=%08x iConfig=%08x iCpuStat=%08x", SCU.iCtrl, SCU.iConfig, SCU.iCpuStatus));
   104 	__KTRACE_OPT(KBOOT,DEBUGPRINT("SCU: iCtrl=%08x iConfig=%08x iCpuStat=%08x", SCU.iCtrl, SCU.iConfig, SCU.iCpuStatus));
   101 	if (n==0)
   105 	if (n==0)
   102 		return KErrTimedOut;
   106 		return KErrTimedOut;
   103 	NKern::DisableAllInterrupts();
   107 
   104 	arm_dsb();
   108 #if defined(__NKERN_TIMESTAMP_USE_LOCAL_TIMER__)
   105 	while (bootPage.iBootFlags2==0)
   109 #error Use of local timer for NKern::Timestamp() no longer supported
   106 		{}
   110 #endif
   107 	arm_dsb();
   111 
   108 	bootPage.iBootFlags2 = 2;
       
   109 	arm_dsb();
       
   110 	bootPage.iBPTimestamp = NKern::Timestamp();
       
   111 	arm_dsb();
       
   112 	while (bootPage.iBootFlags2==2)
       
   113 		{}
       
   114 	arm_dsb();
       
   115 	NKern::EnableAllInterrupts();
       
   116 	return KErrNone;
   112 	return KErrNone;
   117 	}
   113 	}
   118 
   114 
   119 void InitAPTimestamp(SNThreadCreateInfo& aInfo)
   115 void InitTimestamp(TSubScheduler* aSS, SNThreadCreateInfo& aInfo)
   120 	{
   116 	{
   121 	volatile SArmAPBootInfo& a = *(volatile SArmAPBootInfo*)aInfo.iParameterBlock;
   117 	NThread* t = (NThread*)aSS->iCurrentThread;
   122 	volatile SAPBootPage& bootPage = *(volatile SAPBootPage*)a.iAPBootLin;
   118 	t->iActiveState = 1;
   123 	NKern::DisableAllInterrupts();
   119 	if (aSS->iCpuNum == 0)
   124 	bootPage.iBootFlags2 = 1;
   120 		{
   125 	arm_dsb();
   121 		aSS->iLastTimestamp.i64 = 0;
   126 	while (bootPage.iBootFlags2==1)
   122 		t->iLastActivationTime.i64 = 0;
   127 		{}
   123 		return;
   128 	arm_dsb();
   124 		}
   129 	bootPage.iAPTimestamp = NKern::Timestamp();
   125 	TUint64 ts = 0;
   130 	arm_dsb();
   126 #if defined(__NKERN_TIMESTAMP_USE_LOCAL_TIMER__)
   131 	TUint64 bpt = bootPage.iBPTimestamp;
   127 #error Use of local timer for NKern::Timestamp() no longer supported
   132 	TUint64 apt = bootPage.iAPTimestamp;
   128 #endif
   133 	TUint64 delta = bpt - apt;
   129 	ts = NKern::Timestamp();
   134 	SubScheduler().iLastTimestamp64 += delta;
   130 	aSS->iLastTimestamp.i64 = ts;
   135 	__KTRACE_OPT(KBOOT,DEBUGPRINT("APT=0x%lx BPT=0x%lx Delta=0x%lx", apt, bpt, delta));
   131 	t->iLastActivationTime.i64 = ts;
   136 	arm_dsb();
       
   137 	bootPage.iBootFlags2 = 3;
       
   138 	NKern::EnableAllInterrupts();
       
   139 	}
   132 	}
   140 
   133