Skip to content

Commit

Permalink
Optimize some of the methods
Browse files Browse the repository at this point in the history
  • Loading branch information
irusanov committed Aug 28, 2019
1 parent ff4f271 commit 89e2624
Showing 1 changed file with 16 additions and 135 deletions.
151 changes: 16 additions & 135 deletions AsusZsSrv/CPUHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public enum PerfBias { None = 0, Cinebench_R15, Cinebench_R11p5, Geekbench_3 };
const UInt32 SMU_OFFSET_ADDR = 0xB8;
const UInt32 SMU_OFFSET_DATA = 0xBC;

//const UInt32 SMU_ADDR_MSG = 0x03B10530;
//const UInt32 SMU_ADDR_MSG = 0x03B10528;
const UInt32 SMU_ADDR_MSG = 0x03B10530; // Matisse;
// const UInt32 SMU_ADDR_RSP = 0x03B1057C;
// const UInt32 SMU_ADDR_RSP = 0x03B10564;
const UInt32 SMU_ADDR_RSP = 0x03B1057C; // Matisse;
//const UInt32 SMU_ADDR_ARG0 = 0x03B10998;
const UInt32 SMU_ADDR_ARG0 = 0x03B109C4; // Matisse
Expand Down Expand Up @@ -546,144 +546,44 @@ public bool SetPerfBias(PerfBias pb)

public bool SetPPT(int ppt)
{

bool res;

// Mutex
res = hMutexPci.WaitOne(5000);

// Clear response
if (res)
{
res = SmuWriteReg(SMU_ADDR_RSP, 0);
if (res)
{
// Set arg0
res = SmuWriteReg(SMU_ADDR_ARG0, (UInt32)ppt * 1000);
if (res)
{
// Send message
res = SmuWriteReg(SMU_ADDR_MSG, SMC_MSG_SetPPTLimit);
if (res)
{
res = SmuWaitDone();
}
}
}

hMutexPci.ReleaseMutex();
}
res = SmuWrite(SMC_MSG_SetPPTLimit, (UInt32)ppt * 1000);

if (res) ZenPPT = ppt;

return res;

}

public bool SetTDC(int tdc)
{

bool res;

// Mutex
res = hMutexPci.WaitOne(5000);

// Clear response
if (res)
{
res = SmuWriteReg(SMU_ADDR_RSP, 0);
if (res)
{
// Set arg0
res = SmuWriteReg(SMU_ADDR_ARG0, (UInt32)tdc * 1000);
if (res)
{
// Send message
res = SmuWriteReg(SMU_ADDR_MSG, SMC_MSG_SetTDCLimit);
if (res)
{
res = SmuWaitDone();
}
}
}

hMutexPci.ReleaseMutex();
}
res = SmuWrite(SMC_MSG_SetTDCLimit, (UInt32)tdc * 1000);

if (res) ZenTDC = tdc;

return res;

}

public bool SetEDC(int edc)
{

bool res;

// Mutex
res = hMutexPci.WaitOne(5000);

// Clear response
if (res)
{
res = SmuWriteReg(SMU_ADDR_RSP, 0);
if (res)
{
// Set arg0
res = SmuWriteReg(SMU_ADDR_ARG0, (UInt32)edc * 1000);
if (res)
{
// Send message
res = SmuWriteReg(SMU_ADDR_MSG, SMC_MSG_SetEDCLimit);
if (res)
{
res = SmuWaitDone();
}
}
}

hMutexPci.ReleaseMutex();
}
res = SmuWrite(SMC_MSG_SetEDCLimit, (UInt32)edc * 1000);

if (res) ZenEDC = edc;

return res;

}

public bool SetScalar(int scalar)
{

bool res;
res = SmuWrite(SMC_MSG_SetFITLimitScalar, (UInt32)scalar);

// Mutex
res = hMutexPci.WaitOne(5000);

// Clear response
if (res)
{
res = SmuWriteReg(SMU_ADDR_RSP, 0);
if (res)
{
// Set arg0
res = SmuWriteReg(SMU_ADDR_ARG0, (UInt32)scalar);
if (res)
{
// Send message
res = SmuWriteReg(SMU_ADDR_MSG, SMC_MSG_SetFITLimitScalar);
if (res)
{
res = SmuWaitDone();
}
}
}

hMutexPci.ReleaseMutex();
}
if (res) ZenScalar = scalar;

return res;

}

/*public bool SetPerfEnhancer(PerfEnh pe) {
Expand Down Expand Up @@ -880,15 +780,7 @@ private bool SmuRead(UInt32 msg, ref UInt32 data)
if (res)
{
// Check completion
UInt32 status = 0;
UInt32 timeout = 1000;

while ((!res || status != 1) && --timeout > 0)
{
res = SmuReadReg(SMU_ADDR_RSP, ref status);
}

if (status != 1 || timeout == 0) res = false;
res = SmuWaitDone();

if (res)
{
Expand All @@ -898,43 +790,36 @@ private bool SmuRead(UInt32 msg, ref UInt32 data)
}

return res;

}

private bool SmuWrite(UInt32 msg, UInt32 data)
{
bool res;

// Mutex
res = hMutexPci.WaitOne(5000);

// Clear response
res = SmuWriteReg(SMU_ADDR_RSP, 0);
if (res) res = SmuWriteReg(SMU_ADDR_RSP, 0);
if (res)
{
// Write data
res = SmuWriteReg(SMU_ADDR_ARG0, data);
if (res)
{
res = SmuWriteReg(SMU_ADDR_ARG1, 0);
SmuWriteReg(SMU_ADDR_ARG1, 0);
}
// Send message
res = SmuWriteReg(SMU_ADDR_MSG, msg);
if (res)
{
// Check completion
UInt32 status = 0;
UInt32 timeout = 1000;

while (!res && status != 1 && --timeout > 0)
{
res = SmuReadReg(SMU_ADDR_RSP, ref status);
}

if (status != 1 || timeout == 0) res = false;

res = SmuWaitDone();
}
}

return res;
hMutexPci.ReleaseMutex();

return res;
}

public bool GetTctlOffset(ref UInt32 offset)
Expand Down Expand Up @@ -979,7 +864,6 @@ public bool GetTemp(ref double Temp)

public bool WritePort80Temp(double temp)
{

if (temp > 99) temp = 99;
else if (temp < 0) temp = 0;

Expand Down Expand Up @@ -1014,12 +898,10 @@ public void Restore()

// Perf Bias
SetPerfBias(PerfBias.None);

}

public void SaveSettings()
{

SettingsStore.TrayIconAtStart = TrayIconAtStart;
SettingsStore.ApplyAtStart = ApplyAtStart;
SettingsStore.P80Temp = P80Temp;
Expand All @@ -1044,7 +926,6 @@ public void SaveSettings()
SettingsStore.Save();

SettingsSaved = true;

}

public void Unload()
Expand Down

0 comments on commit 89e2624

Please sign in to comment.