real freqs + ram load on bpmp
gpu freq is excluded due to smmu issue (carveout?)
This commit is contained in:
1 parent
8222fe6b0c
commit
d8c6a86bb0
20 files changed
+411
-368
No files matched your search
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "freq.hpp"
|
||||
#include "regs.hpp"
|
||||
|
||||
#include <hocclk/bpmp.h>
|
||||
|
||||
namespace actmon {
|
||||
|
||||
constexpr u32 ActmonBase = 0x6000C800;
|
||||
constexpr u32 ActmonDevBase = ActmonBase + 0x80;
|
||||
constexpr u32 ActmonDevSize = 0x40;
|
||||
|
||||
constexpr u32 ActmonGlbStatus = 0x0;
|
||||
constexpr u32 ActmonGlbPeriodCtrl = 0x4;
|
||||
constexpr u32 ActmonMccpuMonAct = (1u << 8);
|
||||
constexpr u32 ActmonMcallMonAct = (1u << 9);
|
||||
|
||||
constexpr u32 ActmonDevCtrlKVal3 = (3u << 10);
|
||||
constexpr u32 ActmonDevCtrlEnbPeriodic = (1u << 18);
|
||||
constexpr u32 ActmonDevCtrlEnb = (1u << 31);
|
||||
|
||||
constexpr u32 ActmonPeriodMs = 20;
|
||||
|
||||
enum ActmonDev : u32 {
|
||||
DevCpu = 0,
|
||||
DevBpmp,
|
||||
DevAhb,
|
||||
DevApb,
|
||||
DevCpuFreq,
|
||||
DevMcAll,
|
||||
DevMcCpu,
|
||||
};
|
||||
|
||||
constexpr u32 DevCtrl = 0x00;
|
||||
constexpr u32 DevInitAvg = 0x0C;
|
||||
constexpr u32 DevCountWeight = 0x18;
|
||||
constexpr u32 DevAvgCount = 0x20;
|
||||
|
||||
inline u32 DevReg(ActmonDev dev, u32 off) {
|
||||
return ActmonDevBase + (static_cast<u32>(dev) * ActmonDevSize) + off;
|
||||
}
|
||||
|
||||
inline void EnableDev(ActmonDev dev, u32 freqKhz, u32 weight) {
|
||||
MMIO32(DevReg(dev, DevInitAvg)) = freqKhz * ActmonPeriodMs / 2;
|
||||
MMIO32(DevReg(dev, DevCountWeight)) = weight;
|
||||
MMIO32(DevReg(dev, DevCtrl)) = ActmonDevCtrlEnb | ActmonDevCtrlEnbPeriodic | ActmonDevCtrlKVal3;
|
||||
}
|
||||
|
||||
inline void Init() {
|
||||
const u32 emcFreqKhz = static_cast<u32>(freq::MeasurePtoFreqHz(freq::ClkPtoEmc, 1) / 1000);
|
||||
|
||||
if (!(MMIO32(ActmonBase + ActmonGlbStatus) & ActmonMcallMonAct)) {
|
||||
MMIO32(ActmonBase + ActmonGlbPeriodCtrl) = (ActmonPeriodMs - 1) & 0xFF;
|
||||
EnableDev(DevMcAll, emcFreqKhz, 256 * 4);
|
||||
}
|
||||
|
||||
if (!(MMIO32(ActmonBase + ActmonGlbStatus) & ActmonMccpuMonAct)) {
|
||||
EnableDev(DevMcCpu, emcFreqKhz, 256 * 4);
|
||||
}
|
||||
}
|
||||
|
||||
inline void Update(HocClkBpmpSharedInfo &info) {
|
||||
const u32 emcFreqKhz = info.freqMem;
|
||||
if (emcFreqKhz == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const u32 avgAll = MMIO32(DevReg(DevMcAll, DevAvgCount));
|
||||
const u32 avgCpu = MMIO32(DevReg(DevMcCpu, DevAvgCount));
|
||||
|
||||
// Get 1000 -> 100.0.
|
||||
info.emcLoadAll = static_cast<u32>((static_cast<u64>(avgAll) * 10 * 100) / (emcFreqKhz * ActmonPeriodMs));
|
||||
info.emcLoadCpu = static_cast<u32>((static_cast<u64>(avgCpu) * 10 * 100) / (emcFreqKhz * ActmonPeriodMs));
|
||||
|
||||
info.emcBwAll = static_cast<u32>((static_cast<u64>(emcFreqKhz) * 16 * info.emcLoadAll) / 1000000);
|
||||
info.emcBwCpu = static_cast<u32>((static_cast<u64>(emcFreqKhz) * 16 * info.emcLoadCpu) / 1000000);
|
||||
|
||||
// Not 100% accurate but should be enough.
|
||||
info.emcBwGpu = (info.emcBwAll > info.emcBwCpu) ? (info.emcBwAll - info.emcBwCpu) : 0;
|
||||
}
|
||||
|
||||
} // namespace actmon
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2025 CTCaer
|
||||
* Copyright (c) Souldbminer, Lightos and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "regs.hpp"
|
||||
|
||||
// NOTE: MMU won't allow access to gpu address space (smmu carveout issue?)
|
||||
namespace bpmpMmu {
|
||||
|
||||
constexpr u32 CacheBase = 0x50040000;
|
||||
|
||||
constexpr u32 CacheConfig = 0x000;
|
||||
constexpr u32 CfgEnableCache = (1u << 0);
|
||||
constexpr u32 CfgForceWriteThrough = (1u << 3);
|
||||
constexpr u32 CfgMmuTagModeShift = 8;
|
||||
constexpr u32 TagModeParallel = 0;
|
||||
constexpr u32 CfgTagChkAbrtOnErr = (1u << 14);
|
||||
|
||||
constexpr u32 MaintReq = 0x028;
|
||||
constexpr u32 MaintReqWayBitmapAll = (0xFu << 8);
|
||||
|
||||
constexpr u32 IntClear = 0x044;
|
||||
constexpr u32 IntRawEvent = 0x048;
|
||||
constexpr u32 IntMaintDone = (1u << 0);
|
||||
|
||||
constexpr u32 MmuFallbackEntry = 0x0A0;
|
||||
constexpr u32 MmuShadowCopyMask = 0x0A4;
|
||||
|
||||
constexpr u32 MmuCfg = 0x0AC;
|
||||
constexpr u32 MmuCfgSeqEn = (1u << 1);
|
||||
constexpr u32 MmuCfgTlbEn = (1u << 2);
|
||||
constexpr u32 MmuCfgAbortStoreLast = (1u << 4);
|
||||
|
||||
constexpr u32 MmuCmd = 0x0B0;
|
||||
constexpr u32 MmuCmdInit = 1;
|
||||
constexpr u32 MmuCmdCopyShadow = 2;
|
||||
|
||||
constexpr u32 ShadowEntryBase = CacheBase + 0x400;
|
||||
|
||||
constexpr u32 MmuEnCached = (1u << 0);
|
||||
constexpr u32 MmuEnExec = (1u << 1);
|
||||
constexpr u32 MmuEnRead = (1u << 2);
|
||||
constexpr u32 MmuEnWrite = (1u << 3);
|
||||
|
||||
constexpr u32 MaintCleanInvalidWay = 19;
|
||||
constexpr u32 MaintInvalidWay = 18;
|
||||
|
||||
constexpr u32 CacheLineSize = 0x20;
|
||||
|
||||
constexpr u32 DramStart = 0x80000000;
|
||||
constexpr u32 IramBase = 0x40000000;
|
||||
constexpr u32 IramEnd = 0x4003FFFF;
|
||||
|
||||
struct MmuEntry {
|
||||
u32 startAddr;
|
||||
u32 endAddr;
|
||||
u32 attr;
|
||||
};
|
||||
|
||||
constexpr MmuEntry Entries[] = {
|
||||
{ DramStart, 0xFFFFFFFF, MmuEnRead | MmuEnWrite | MmuEnExec | MmuEnCached },
|
||||
{ IramBase, IramEnd, MmuEnRead | MmuEnWrite | MmuEnExec | MmuEnCached },
|
||||
};
|
||||
|
||||
inline u32 AlignUp(u32 x, u32 a) {
|
||||
return (x + a - 1) & ~(a - 1);
|
||||
}
|
||||
inline u32 AlignDown(u32 x, u32 a) {
|
||||
return x & ~(a - 1);
|
||||
}
|
||||
|
||||
inline void Maintenance(u32 op, bool force) {
|
||||
if (!force && !(MMIO32(CacheBase + CacheConfig) & CfgEnableCache)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MMIO32(CacheBase + IntClear) = IntMaintDone;
|
||||
|
||||
// Blocking operation.
|
||||
MMIO32(CacheBase + MaintReq) = MaintReqWayBitmapAll | op;
|
||||
|
||||
while (!(MMIO32(CacheBase + IntRawEvent) & IntMaintDone))
|
||||
;
|
||||
|
||||
MMIO32(CacheBase + IntClear) = MMIO32(CacheBase + IntRawEvent);
|
||||
}
|
||||
|
||||
inline void SetEntry(u32 idx, const MmuEntry &entry) {
|
||||
MMIO32(ShadowEntryBase + sizeof(u32) * 4 * idx + 0x0) = AlignUp(entry.startAddr, CacheLineSize);
|
||||
MMIO32(ShadowEntryBase + sizeof(u32) * 4 * idx + 0x4) = AlignDown(entry.endAddr, CacheLineSize);
|
||||
MMIO32(ShadowEntryBase + sizeof(u32) * 4 * idx + 0x8) = entry.attr;
|
||||
|
||||
MMIO32(CacheBase + MmuShadowCopyMask) |= (1u << idx);
|
||||
}
|
||||
|
||||
inline void Enable() {
|
||||
if (MMIO32(CacheBase + CacheConfig) & CfgEnableCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Init BPMP MMU.
|
||||
MMIO32(CacheBase + MmuCmd) = MmuCmdInit;
|
||||
MMIO32(CacheBase + MmuFallbackEntry) = MmuEnRead | MmuEnWrite | MmuEnExec; // RWX for non-defined regions.
|
||||
MMIO32(CacheBase + MmuCfg) = MmuCfgSeqEn | MmuCfgTlbEn | MmuCfgAbortStoreLast;
|
||||
|
||||
// Init BPMP MMU entries.
|
||||
MMIO32(CacheBase + MmuShadowCopyMask) = 0;
|
||||
for (u32 idx = 0; idx < sizeof(Entries) / sizeof(Entries[0]); idx++) {
|
||||
SetEntry(idx, Entries[idx]);
|
||||
}
|
||||
|
||||
MMIO32(CacheBase + MmuCmd) = MmuCmdCopyShadow;
|
||||
|
||||
// Invalidate cache.
|
||||
Maintenance(MaintInvalidWay, true);
|
||||
|
||||
// Enable cache.
|
||||
MMIO32(CacheBase + CacheConfig) = CfgEnableCache | CfgForceWriteThrough |
|
||||
(TagModeParallel << CfgMmuTagModeShift) | CfgTagChkAbrtOnErr;
|
||||
|
||||
// HW bug. Invalidate cache again.
|
||||
Maintenance(MaintInvalidWay, false);
|
||||
}
|
||||
|
||||
inline void Disable() {
|
||||
if (!(MMIO32(CacheBase + CacheConfig) & CfgEnableCache)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean and invalidate cache.
|
||||
Maintenance(MaintCleanInvalidWay, false);
|
||||
|
||||
// Disable cache.
|
||||
MMIO32(CacheBase + CacheConfig) = 0;
|
||||
}
|
||||
|
||||
} // namespace bpmpMmu
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "regs.hpp"
|
||||
|
||||
#include <hocclk/bpmp.h>
|
||||
|
||||
namespace freq {
|
||||
|
||||
constexpr u32 CarBase = 0x60006000;
|
||||
constexpr u32 CarPtoClkCntCntl = 0x60;
|
||||
constexpr u32 CarPtoClkCntStatus = 0x64;
|
||||
|
||||
constexpr u32 PtoCntEn = (1u << 9);
|
||||
constexpr u32 PtoCntRst = (1u << 10);
|
||||
constexpr u32 PtoClkEnable = (1u << 13);
|
||||
constexpr u32 PtoSrcSelShift = 14;
|
||||
constexpr u32 PtoDivSelDiv1 = (1u << 23);
|
||||
constexpr u32 PtoClkCntBusy = (1u << 31);
|
||||
constexpr u32 PtoClkCntMask = 0xFFFFFF;
|
||||
|
||||
constexpr u32 ClkPtoCclkGDiv2 = 0x13;
|
||||
constexpr u32 ClkPtoEmc = 0x24;
|
||||
|
||||
inline u64 MeasurePtoFreqHz(u32 srcId, u32 multiplier) {
|
||||
constexpr u32 win = 16;
|
||||
constexpr u32 osc = 32768;
|
||||
|
||||
const u32 val = (srcId << PtoSrcSelShift) | PtoDivSelDiv1 | PtoClkEnable | (win - 1);
|
||||
|
||||
MMIO32(CarBase + CarPtoClkCntCntl) = val;
|
||||
(void)MMIO32(CarBase + CarPtoClkCntCntl);
|
||||
usleep(2);
|
||||
|
||||
MMIO32(CarBase + CarPtoClkCntCntl) = val | PtoCntRst;
|
||||
(void)MMIO32(CarBase + CarPtoClkCntCntl);
|
||||
usleep(2);
|
||||
|
||||
MMIO32(CarBase + CarPtoClkCntCntl) = val;
|
||||
(void)MMIO32(CarBase + CarPtoClkCntCntl);
|
||||
usleep(2);
|
||||
|
||||
MMIO32(CarBase + CarPtoClkCntCntl) = val | PtoCntEn;
|
||||
(void)MMIO32(CarBase + CarPtoClkCntCntl);
|
||||
usleep((1000000u * win / osc) + 12 + 2); // 502us
|
||||
|
||||
while (MMIO32(CarBase + CarPtoClkCntStatus) & PtoClkCntBusy)
|
||||
;
|
||||
|
||||
const u32 cnt = MMIO32(CarBase + CarPtoClkCntStatus) & PtoClkCntMask;
|
||||
|
||||
MMIO32(CarBase + CarPtoClkCntCntl) = 0;
|
||||
(void)MMIO32(CarBase + CarPtoClkCntCntl);
|
||||
usleep(2);
|
||||
|
||||
return (static_cast<u64>(cnt) * multiplier * osc) / win;
|
||||
}
|
||||
|
||||
inline void Update(HocClkBpmpSharedInfo &info) {
|
||||
info.freqMem = static_cast<u32>(MeasurePtoFreqHz(ClkPtoEmc, 1) / 1000);
|
||||
info.freqCpu = static_cast<u32>(MeasurePtoFreqHz(ClkPtoCclkGDiv2, 2) / 1000);
|
||||
}
|
||||
|
||||
} // namespace freq
|
||||
@@ -18,6 +18,9 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "actmon.hpp"
|
||||
#include "bpmp_mmu.hpp"
|
||||
#include "freq.hpp"
|
||||
#include "libc_platform.hpp"
|
||||
#include "regs.hpp"
|
||||
#include "sensors.hpp"
|
||||
@@ -34,6 +37,10 @@ namespace {
|
||||
|
||||
void MainLoop(HocClkBpmpSharedInfo &info) {
|
||||
for (;;) {
|
||||
if (info.exitRequested) {
|
||||
break;
|
||||
}
|
||||
|
||||
const u32 temp1 = MMIO32(SocthermBase + SocthermSensorTemp1);
|
||||
const u32 temp2 = MMIO32(SocthermBase + SocthermSensorTemp2);
|
||||
|
||||
@@ -42,11 +49,23 @@ void MainLoop(HocClkBpmpSharedInfo &info) {
|
||||
info.tempMem = TranslateSocthermTemp(static_cast<u16>(temp2 >> 16));
|
||||
info.tempPllx = TranslateSocthermTemp(static_cast<u16>(temp2));
|
||||
|
||||
msleep(500);
|
||||
freq::Update(info);
|
||||
actmon::Update(info);
|
||||
|
||||
msleep(250);
|
||||
}
|
||||
|
||||
/* Deinit MMU otherwise sleep will fatal. */
|
||||
bpmpMmu::Disable();
|
||||
info.magic = 0x0;
|
||||
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
|
||||
extern "C" void main() {
|
||||
bpmpMmu::Enable();
|
||||
|
||||
InitializeLibc();
|
||||
|
||||
printf("[hoc-bpmpfw]: Starting bpmpfw\n");
|
||||
@@ -54,6 +73,9 @@ extern "C" void main() {
|
||||
HocClkBpmpSharedInfo &info = SharedInfo();
|
||||
memset(&info, 0, sizeof(info));
|
||||
info.status = 0;
|
||||
|
||||
actmon::Init();
|
||||
|
||||
info.magic = HOCCLK_BPMP_MAGIC; // written last
|
||||
|
||||
/* If the main loop exits then it is a panic or invalid state */
|
||||
|
||||
Reference in new issue
Block a user