]> Chaos Git - corbenik/ctrulib.git/commitdiff
Add code to manage New 3DS CPU speedup
authorfincs <fincs.alt1@gmail.com>
Sun, 11 Oct 2015 21:44:10 +0000 (23:44 +0200)
committerfincs <fincs.alt1@gmail.com>
Sun, 11 Oct 2015 21:44:10 +0000 (23:44 +0200)
libctru/include/3ds/os.h
libctru/include/3ds/services/ptm.h
libctru/source/os.c
libctru/source/services/apt.c
libctru/source/services/ptm.c

index 9c433f811a088c7eaa5ba13147d6e33e45b4d740..edd596360d0b9ad8489ca34f212b98d91158abfd 100644 (file)
@@ -83,3 +83,9 @@ u64 osGetTime(void);
  * These values correspond with the number of wifi bars displayed by Home Menu.
  */
 u8 osGetWifiStrength(void);
+
+/**
+ * @brief Configures the New 3DS speedup.
+ * @param enable Specifies whether to enable or disable the speedup.
+ */
+void osSetSpeedupEnable(bool enable);
index 17f3ea8c41fe55fca29a7775a0793adc0d417d82..1ee87afeabcb6c560dfb1fe01a5db1a8a7e5ecd1 100644 (file)
@@ -10,6 +10,12 @@ Result ptmInit(void);
 /// Exits PTM.
 Result ptmExit(void);
 
+/// Initializes ptm:sysm.
+Result ptmSysmInit(void);
+
+/// Exits ptm:sysm.
+Result ptmSysmExit(void);
+
 /**
  * @brief Gets the system's current shell state.
  * @param servhandle Optional pointer to the handle to use.
@@ -44,3 +50,9 @@ Result PTMU_GetPedometerState(Handle* servhandle, u8 *out);
  * @param steps Pointer to write the total step count to.
  */
 Result PTMU_GetTotalStepCount(Handle* servhandle, u32 *steps);
+
+/**
+ * @brief Configures the New 3DS' CPU clock speed and L2 cache.
+ * @param value Bit0: enable higher clock, Bit1: enable L2 cache.
+ */
+Result PTMSYSM_ConfigureNew3DSCPU(u8 value);
index edb19c7c0bbf2ad20434476da742e57bebc65697..338546d8410f9fdd0f047f066be0988481faf8ef 100644 (file)
@@ -1,6 +1,7 @@
 #include <3ds/types.h>
 #include <3ds/os.h>
 #include <3ds/svc.h>
+#include <3ds/services/ptm.h>
 
 #include <sys/time.h>
 #include <reent.h>
@@ -26,6 +27,7 @@ static volatile datetime_t* __datetime0 =
 static volatile datetime_t* __datetime1 =
        (datetime_t*) 0x1FF81040;
 
+__attribute__((weak)) bool __ctru_speedup = false;
 
 //---------------------------------------------------------------------------------
 u32 osConvertVirtToPhys(u32 vaddr) {
@@ -155,3 +157,18 @@ u8 osGetWifiStrength(void) {
 //---------------------------------------------------------------------------------
        return *((u8*)0x1FF81066);
 }
+
+void __ctru_speedup_config(void)
+{
+       if (ptmSysmInit()==0)
+       {
+               PTMSYSM_ConfigureNew3DSCPU(__ctru_speedup ? 3 : 0);
+               ptmSysmExit();
+       }
+}
+
+void osSetSpeedupEnable(bool enable)
+{
+       __ctru_speedup = enable;
+       __ctru_speedup_config();
+}
index 6e7e1362c2cfb4d956ffe6fc05897b63a55a09d6..70686d7ef0bbba7afa0f7206136de9d894f2e995 100644 (file)
@@ -63,6 +63,8 @@ __attribute__((weak)) void _aptDebug(int a, int b)
 {
 }
 
+void __ctru_speedup_config(void);
+
 static void aptAppStarted(void);
 
 static bool aptIsReinit(void)
@@ -396,7 +398,7 @@ static bool __handle_incoming_parameter(void) {
                aptSetStatus(APP_APPLETCLOSED);
                return true;
        case 0xB: // Just returned from menu.
-               if (aptStatusMutex)
+               if (aptGetStatus() != APP_NOTINITIALIZED)
                {
                        GSPGPU_AcquireRight(0x0);
                        GSPGPU_RestoreVramSysArea();
@@ -463,6 +465,8 @@ Result aptInit(void)
 
        svcCreateEvent(&aptStatusEvent, 0);
        svcCreateEvent(&aptSleepSync, 0);
+       svcCreateMutex(&aptStatusMutex, false);
+       aptStatus=0;
 
        if(!aptIsCrippled())
        {
@@ -627,10 +631,6 @@ void aptAppStarted(void)
 {
        u8 buf1[4], buf2[4];
 
-       svcCreateMutex(&aptStatusMutex, true);
-       aptStatus=0;
-       svcReleaseMutex(aptStatusMutex);
-
        aptSetStatus(APP_RUNNING);
 
        if(!aptIsCrippled())
@@ -670,6 +670,8 @@ void aptSetStatus(APP_STATUS status)
 
        //if(prevstatus != APP_NOTINITIALIZED)
        //{
+               if(status == APP_RUNNING)
+                       __ctru_speedup_config();
                if(status == APP_RUNNING || status == APP_EXITING || status == APP_APPLETSTARTED || status == APP_APPLETCLOSED)
                        svcSignalEvent(aptStatusEvent);
        //}
index 96de48ada75b8e698e6d92fee947b70a0ec3f50f..c3851c1540f95ee21826614f4a6e206c8e0e4a48 100644 (file)
@@ -6,11 +6,11 @@
 #include <3ds/ipc.h>
 
 
-static Handle ptmHandle;
+static Handle ptmHandle, ptmSysmHandle;
 
 Result ptmInit(void)
 {
-       return srvGetServiceHandle(&ptmHandle, "ptm:u");        
+       return srvGetServiceHandle(&ptmHandle, "ptm:u");
 }
 
 Result ptmExit(void)
@@ -18,6 +18,16 @@ Result ptmExit(void)
        return svcCloseHandle(ptmHandle);
 }
 
+Result ptmSysmInit(void)
+{
+       return srvGetServiceHandle(&ptmSysmHandle, "ptm:sysm");
+}
+
+Result ptmSysmExit(void)
+{
+       return svcCloseHandle(ptmSysmHandle);
+}
+
 Result PTMU_GetShellState(Handle* servhandle, u8 *out)
 {
        if(!servhandle)servhandle=&ptmHandle;
@@ -92,3 +102,16 @@ Result PTMU_GetTotalStepCount(Handle* servhandle, u32 *steps)
 
        return (Result)cmdbuf[1];
 }
+
+Result PTMSYSM_ConfigureNew3DSCPU(u8 value)
+{
+       Result ret;
+       u32 *cmdbuf = getThreadCommandBuffer();
+
+       cmdbuf[0] = IPC_MakeHeader(0x818,1,0); // 0x08180040
+       cmdbuf[1] = value;
+
+       if((ret = svcSendSyncRequest(ptmSysmHandle))!=0)return ret;
+
+       return (Result)cmdbuf[1];
+}