more bpmpfw shenanigans

This commit is contained in:
souldbminersmwc committed 2026-08-25 13:37:05 -04:00
1 parent 7660650129
commit b20d20edff
54 files changed
+1275 -30

No files matched your search

@@ -182,6 +182,7 @@ namespace board {
if (R_FAILED(bpmpfwRc)) {
fileUtils::LogLine("[bpmp] StartBpmfwExecution failed: 0x%x", bpmpfwRc);
}
bpmp::StartSleepMonitorThread();
// PMC exosphere check
SecmonArgs args = {};
@@ -211,6 +212,8 @@ namespace board {
}
void Exit() {
bpmp::StopSleepMonitorThread();
if (HOSSVC_HAS_CLKRST) {
clkrstExit();
} else {
@@ -64,6 +64,38 @@ namespace bpmp {
return *reinterpret_cast<volatile u32 *>(base_va + offset);
}
// Late in the boot chain, otherwise a fatal will occur from invalid boot state
constexpr u32 pscDependencies[] = { PscPmModuleId_Olsc };
constexpr PscPmModuleId PscModuleId = (PscPmModuleId)705;
PscPmModule s_pscModule;
bool s_pscPrepared = false;
Thread s_pscThread;
bool s_pscExit = false;
void PscThreadFunc(void *) {
while (!s_pscExit) {
Result rc = eventWait(&s_pscModule.event, 1'000'000'000ULL);
if (R_FAILED(rc)) {
continue; // Timeout
}
PscPmState state;
u32 flags;
rc = pscPmModuleGetRequest(&s_pscModule, &state, &flags);
if (R_SUCCEEDED(rc)) {
if (state == PscPmState_Awake) {
Result wrc = StartBpmfwExecution();
if (R_FAILED(wrc)) {
fileUtils::LogLine("[bpmp] restart after wake failed: 0x%x", wrc);
}
}
pscPmModuleAcknowledge(&s_pscModule, state);
}
}
}
} // namespace
Result StartBpmfwExecution() {
@@ -137,4 +169,48 @@ namespace bpmp {
return 0;
}
void StartSleepMonitorThread() {
if (!IsPatchedExosphere()) {
fileUtils::LogLine("[bpmp] Cant start BPMP without exosphere patch");
return;
}
Result rc = pscmInitialize();
if (R_FAILED(rc)) {
fileUtils::LogLine("[bpmp] pscmInitialize failed: 0x%x", rc);
return;
}
rc = pscmGetPmModule(&s_pscModule, PscModuleId, pscDependencies, sizeof(pscDependencies) / sizeof(u32), true);
if (R_FAILED(rc)) {
fileUtils::LogLine("[bpmp] pscmGetPmModule failed: 0x%x", rc);
pscmExit();
return;
}
s_pscPrepared = true;
rc = threadCreate(&s_pscThread, PscThreadFunc, nullptr, NULL, 0x1000, 0x10, 3);
if (R_FAILED(rc)) {
fileUtils::LogLine("[bpmp] failed to create psc thread: 0x%x", rc);
return;
}
threadStart(&s_pscThread);
}
void StopSleepMonitorThread() {
if (!s_pscPrepared) {
return;
}
s_pscExit = true;
eventFire(&s_pscModule.event);
threadWaitForExit(&s_pscThread);
threadClose(&s_pscThread);
pscPmModuleFinalize(&s_pscModule);
pscPmModuleClose(&s_pscModule);
pscmExit();
s_pscPrepared = false;
}
} // namespace bpmp
@@ -20,4 +20,7 @@
namespace bpmp {
Result StartBpmfwExecution();
void StartSleepMonitorThread();
void StopSleepMonitorThread();
}
@@ -103,7 +103,7 @@ namespace fileUtils {
va_list args;
va_start(args, format);
char buff[0xfff];
char buff[0x200];
int len = vsnprintf(buff, sizeof(buff), format, args);
va_end(args);
+1 -1
View File
@@ -38,7 +38,7 @@
#include "mgr/clock_manager.hpp"
#define INNER_HEAP_SIZE 0x40000
#define INNER_HEAP_SIZE 0x48000
extern "C" {
void virtmemSetup(void);
@@ -30,7 +30,6 @@
#include <i2c.h>
#include "../board/board.hpp"
#include "../bpmp/bpmp.hpp"
#include "../display/aula.hpp"
#include "../display/display_refresh_rate.hpp"
#include "../file/config.hpp"
@@ -41,7 +40,6 @@
#include "../hos/process_management.hpp"
#include "../i2c/i2cDrv.h"
#include "../ipc/ipc_service.hpp"
#include "../mapping/mem_map.hpp"
#include "../soc/gm20b.hpp"
#include "../util/lockable_mutex.h"
#include "clock_manager.hpp"
@@ -357,23 +355,6 @@ namespace clockManager {
if (++tick > 10) {
tick = 0;
// Restart BPMP after sleep.
if (IsPatchedExosphere()) {
svcSleepThread(1'500'000'000);
constexpr u32 FlowCtlrPhysBase = 0x60007000;
constexpr u32 FlowCtlrHaltCopEvents = 0x004;
constexpr u32 HaltCopEventsModeShift = 29;
constexpr u32 HaltCopEventsModeStop = 2;
u32 haltReg = SmcReadWriteRegister(FlowCtlrPhysBase + FlowCtlrHaltCopEvents, 0, 0);
if ((haltReg >> HaltCopEventsModeShift) == HaltCopEventsModeStop) {
Result rc = bpmp::StartBpmfwExecution();
if (R_FAILED(rc)) {
fileUtils::LogLine("[bpmp] restart after sleep failed: 0x%x", rc);
}
}
}
if (config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent)) {
I2c_Bq24193_SetFastChargeCurrentLimit(config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent));
}