baseport/src/cedar/generic/base/syborg/specific/assp.cpp
changeset 0 ffa851df0825
equal deleted inserted replaced
-1:000000000000 0:ffa851df0825
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: implementation of class Syborg
       
    15 *
       
    16 */
       
    17 
       
    18 #include <syborg_priv.h>
       
    19 #include <hal_data.h>
       
    20 
       
    21 #ifdef __EMI_SUPPORT__
       
    22 #include <emi.h>
       
    23 #endif
       
    24 
       
    25 //#define ASSP_DEBUG
       
    26 
       
    27 #ifdef ASSP_DEBUG
       
    28 #define __DEBUG_PRINT(format...)    Kern::Printf(format)
       
    29 #else
       
    30 #define __DEBUG_PRINT(format...)    __KTRACE_OPT(KBOOT,Kern::Printf(format))
       
    31 #endif
       
    32 
       
    33 Syborg* Syborg::Variant=NULL;
       
    34 // !@!
       
    35 #if 0
       
    36 TPhysAddr Syborg::VideoRamPhys;
       
    37 TPhysAddr Syborg::VideoRamPhysSecure;		// Secure display memory
       
    38 #endif
       
    39 
       
    40 GLDEF_D Syborg TheVariant;
       
    41 
       
    42 // Wait for interrupt idle routine
       
    43 extern TInt SyborgWFIIdle();
       
    44 
       
    45 DECLARE_STANDARD_ASSP()
       
    46 
       
    47 EXPORT_C Asic* VariantInitialise()
       
    48 {
       
    49 	return &TheVariant;
       
    50 }
       
    51 
       
    52 void Syborg::Idle()
       
    53 {
       
    54 	// Use the basic Wait For Interrupt call to idle
       
    55 	TInt irq = NKern::DisableAllInterrupts();
       
    56 #ifdef __EMI_SUPPORT__
       
    57 	EMI::EnterIdle();
       
    58 #endif
       
    59 	SyborgWFIIdle();
       
    60 #ifdef __EMI_SUPPORT__
       
    61 	EMI::LeaveIdle();
       
    62 #endif
       
    63 	NKern::RestoreInterrupts(irq);
       
    64 }
       
    65 
       
    66 TUint32 Syborg::NanoWaitCalibration()
       
    67 {
       
    68 	return 17;	// 2 cycles approx 17ns at 125MHz
       
    69 }
       
    70 
       
    71 TInt Syborg::VariantHal(TInt aFunction, TAny* a1, TAny* a2)
       
    72 {
       
    73 	__KTRACE_OPT(KHARDWARE,Kern::Printf("Syborg::VariantHal(%d, %0x, %0x)",aFunction,a1,a2));
       
    74 
       
    75 	switch(aFunction)
       
    76     {
       
    77 		case EVariantHalVariantInfo:
       
    78 		{
       
    79 			TVariantInfoV01Buf infoBuf;
       
    80 			TVariantInfoV01& info = infoBuf();
       
    81 			TUint clock=0;
       
    82 			info.iRomVersion = Epoc::RomHeader().iVersion;
       
    83     		info.iMachineUniqueId = (TInt64(HALData::EMachineUid_OmapH4)<<32);
       
    84    			info.iLedCapabilities = (8<<16) + KLedMaskGreen1;
       
    85 			info.iProcessorClockInKHz = clock;
       
    86 			info.iSpeedFactor = clock/25;
       
    87 			Kern::InfoCopy(*(TDes8*)a1,infoBuf);
       
    88 			break;
       
    89 	    }
       
    90 		case EVariantHalDebugPortSet:
       
    91 	    {
       
    92 			TUint32 thePort = (TUint32)a1;
       
    93 			switch(thePort) // Accept UART(0-3)
       
    94 		    {
       
    95 				case 0:
       
    96 				case 1:
       
    97 			    case 2:
       
    98                 case 3:
       
    99                 {
       
   100                     TSyborg::MarkDebugPortOff();           // mark port is not initialised
       
   101 					Kern::SuperPage().iDebugPort = thePort; // update the super page
       
   102                     Syborg::DebugInit();                   // init debug port        
       
   103                     break;
       
   104                 }
       
   105 				case (TUint32)KNullDebugPort:               // debug output supressed
       
   106                 {
       
   107                     TSyborg::MarkDebugPortOff();           // mark port is not initialised
       
   108 					Kern::SuperPage().iDebugPort = thePort; // update the super page
       
   109 					break;
       
   110                 }
       
   111 				default:
       
   112 					return KErrNotSupported;
       
   113 		    }
       
   114 			break;
       
   115 	    }
       
   116 		case EVariantHalDebugPortGet:
       
   117 	    {
       
   118 			TUint32 thePort = Kern::SuperPage().iDebugPort;
       
   119 			kumemput32(a1, &thePort, sizeof(TUint32));
       
   120 			break;
       
   121 	    }
       
   122 		case EVariantHalSwitches:
       
   123 	    {
       
   124 		  TUint32 x = 0; //Register32(KHwBaseSystemReg+KHoRoSystemSw);
       
   125 			kumemput32(a1, &x, sizeof(x));
       
   126 			break;
       
   127 	    }
       
   128 		case EVariantHalLedMaskSet:
       
   129 	    {
       
   130 		  //SetRegister32(KHwBaseSystemReg+KHoRwSystemLed, (TUint32)a1 & 0xFF);
       
   131 			break;
       
   132 	    }
       
   133 		case EVariantHalLedMaskGet:
       
   134 	    {
       
   135 		  TUint32 x = 0; //Register32(KHwBaseSystemReg+KHoRwSystemLed);
       
   136 			kumemput32(a1, &x, sizeof(x));
       
   137 			break;
       
   138 	    }
       
   139 		case EVariantHalCustomRestartReason:
       
   140 	    {
       
   141 			// Restart reason is stored in super page
       
   142 		  TInt x = (Kern::SuperPage().iHwStartupReason); // & KmRestartCustomReasons) >> KsRestartCustomReasons;
       
   143 			kumemput32(a1, &x, sizeof(TInt));
       
   144 			break;
       
   145 	    }
       
   146 		case EVariantHalCustomRestart:
       
   147 	    {
       
   148             __KERNEL_CAPABILITY_CHECK(
       
   149                 if(!Kern::CurrentThreadHasCapability(ECapabilityPowerMgmt,
       
   150 			       __PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EVariantHalCustomRestart")))
       
   151 				    return KErrPermissionDenied;
       
   152             )
       
   153 			  Kern::Restart(0);
       
   154 			break;
       
   155 	    }
       
   156 		default:
       
   157     	{
       
   158 			return KErrNotSupported;
       
   159 	    }
       
   160     }
       
   161 	return KErrNone;
       
   162 }
       
   163 
       
   164 TPtr8 Syborg::MachineConfiguration()
       
   165 {
       
   166 	return TPtr8((TUint8*)&Kern::MachineConfig(),40,40);
       
   167 }
       
   168 
       
   169 EXPORT_C Syborg::Syborg()
       
   170 {
       
   171 	iDebugPortBase = TSyborg::DebugPortAddr(); // initialised in bootstrap
       
   172 }
       
   173 
       
   174 EXPORT_C TMachineStartupType Syborg::StartupReason()
       
   175 {
       
   176 	TUint s = Kern::SuperPage().iHwStartupReason;
       
   177 	__DEBUG_PRINT("Syborg::StartupReason CPU page value 0x%08X", s);
       
   178 	return EStartupColdReset;
       
   179 }
       
   180 
       
   181 EXPORT_C void Syborg::Init1()
       
   182 {
       
   183 	__DEBUG_PRINT("Syborg::Init1()");
       
   184 
       
   185 	// Enable the CLCD in the System registers
       
   186 	SyborgInterrupt::Init1();
       
   187 }
       
   188 
       
   189 EXPORT_C void Syborg::Init3()
       
   190 {
       
   191 	NTimerQ& m = *(NTimerQ*)NTimerQ::TimerAddress();
       
   192 	m.iRounding = -5;
       
   193 		
       
   194 	TInt r = Interrupt::Bind(EIntTimer1,SyborgInterrupt::MsTimerTick,&m);
       
   195 	if (r != KErrNone)
       
   196 	{
       
   197 		Kern::Fault("BindMsTick",r);
       
   198 	}
       
   199 
       
   200 	TSyborg::Init3();
       
   201 	TSyborg::ClearTimerInt(KHwBaseCounterTimer);
       
   202 
       
   203 	r = Interrupt::Enable(EIntTimer1);
       
   204 	if (r != KErrNone)
       
   205 	{
       
   206 		Kern::Fault("EnbMsTick",r);
       
   207 	}
       
   208 
       
   209 	TSyborg::SetTimerLoad(KHwBaseCounterTimer, K1000HzTickMatchLoad);
       
   210 	//	TSyborg::SetTimerLoad(KHwBaseCounterTimer, 1000000);
       
   211 	TSyborg::SetTimerMode(KHwBaseCounterTimer, TSyborg::ETimerModePeriodic);	
       
   212 	TSyborg::EnableTimerInterrupt(KHwBaseCounterTimer);
       
   213 	TSyborg::EnableTimer(KHwBaseCounterTimer, TSyborg::EEnable);
       
   214 	
       
   215 	SyborgInterrupt::Init3();
       
   216 
       
   217 	// !@!
       
   218 #if 0
       
   219 	// Allocate physical RAM for video
       
   220 	TInt vSize = TSyborg::VideoRamSize();
       
   221 
       
   222 	r = Epoc::AllocPhysicalRam(vSize,Syborg::VideoRamPhys);
       
   223 	if (r != KErrNone)
       
   224 	{
       
   225 		Kern::Fault("AllocVideoRam",r);
       
   226 	}
       
   227 
       
   228 	// Allocate physical RAM for secure display
       
   229 	r = Epoc::AllocPhysicalRam(vSize,Syborg::VideoRamPhysSecure);
       
   230 	if (r != KErrNone)
       
   231 	{
       
   232 		Kern::Fault("AllocVideoRam 2",r);
       
   233 	}
       
   234 #endif
       
   235 	__DEBUG_PRINT("Finished Syborg::Init3()");
       
   236 }
       
   237 
       
   238 EXPORT_C void Syborg::DebugInit()
       
   239 {
       
   240 	iDebugPortBase = TSyborg::DebugPortAddr();
       
   241 
       
   242     if(iDebugPortBase != (TUint32)KNullDebugPort)   // supress debug output
       
   243     {
       
   244 	  TUint8 res = ReadReg(iDebugPortBase, 0);
       
   245     }
       
   246 }
       
   247 
       
   248 //
       
   249 // Output a character to the debug port
       
   250 //
       
   251 EXPORT_C void Syborg::DebugOutput(TUint aLetter)
       
   252 {
       
   253 	if(!iDebugPortBase)
       
   254     {
       
   255 		DebugInit();
       
   256 	}
       
   257 
       
   258     if(iDebugPortBase != (TUint32)KNullDebugPort)   // supress debug output
       
   259     {
       
   260 	  WriteReg(iDebugPortBase,1,aLetter);
       
   261     }
       
   262 }
       
   263 
       
   264 EXPORT_C TInt Syborg::MsTickPeriod()
       
   265 {
       
   266 	return 1000;
       
   267 }
       
   268 
       
   269 EXPORT_C TInt Syborg::SystemTimeInSecondsFrom2000(TInt& aTime)
       
   270 {
       
   271 	__KTRACE_OPT(KHARDWARE,Kern::Printf("RTC READ: %d",aTime));
       
   272 	return KErrNone;
       
   273 }
       
   274 
       
   275 EXPORT_C TInt Syborg::SetSystemTimeInSecondsFrom2000(TInt aTime)
       
   276 {
       
   277 	__KTRACE_OPT(KHARDWARE,Kern::Printf("Set RTC: %d",aTime));					// do this here to allow the value to be loaded...
       
   278 	return KErrNone;
       
   279 }