Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
irusanov committed Jan 22, 2020
1 parent 85fc611 commit c17ae90
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 132 deletions.
114 changes: 42 additions & 72 deletions ZenStatesSrv/CPUHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,32 +767,22 @@ public bool SetOcMode(bool manual)
return res;
}

private bool SmuWriteReg(UInt32 addr, UInt32 data)
private bool SmuWriteReg(uint addr, uint data)
{
int res = 0;

// Clear response
res = ols.WritePciConfigDwordEx(cpuSettings.SMU_PCI_ADDR, cpuSettings.SMU_OFFSET_ADDR, addr);
if (res == 1)
if (ols.WritePciConfigDwordEx(cpuSettings.SMU_PCI_ADDR, cpuSettings.SMU_OFFSET_ADDR, addr) == 1)
{
res = ols.WritePciConfigDwordEx(cpuSettings.SMU_PCI_ADDR, cpuSettings.SMU_OFFSET_DATA, data);
return ols.WritePciConfigDwordEx(cpuSettings.SMU_PCI_ADDR, cpuSettings.SMU_OFFSET_DATA, data) == 1;
}

return (res == 1);
return false;
}

private bool SmuReadReg(UInt32 addr, ref UInt32 data)
private bool SmuReadReg(uint addr, ref uint data)
{
int res = 0;

// Clear response
res = ols.WritePciConfigDwordEx(cpuSettings.SMU_PCI_ADDR, cpuSettings.SMU_OFFSET_ADDR, addr);
if (res == 1)
if (ols.WritePciConfigDwordEx(cpuSettings.SMU_PCI_ADDR, cpuSettings.SMU_OFFSET_ADDR, addr) == 1)
{
res = ols.ReadPciConfigDwordEx(cpuSettings.SMU_PCI_ADDR, cpuSettings.SMU_OFFSET_DATA, ref data);
return ols.ReadPciConfigDwordEx(cpuSettings.SMU_PCI_ADDR, cpuSettings.SMU_OFFSET_DATA, ref data) == 1;
}

return (res == 1);
return false;
}

private bool SmuWaitDone()
Expand All @@ -810,72 +800,52 @@ private bool SmuWaitDone()
return res;
}

private bool SmuRead(UInt32 msg, ref UInt32 data)
private bool SmuRead(uint msg, ref uint data)
{
bool res;

// Clear response
res = SmuWriteReg(cpuSettings.SMU_ADDR_RSP, 0);

if (res)
if (SmuWriteReg(cpuSettings.SMU_ADDR_RSP, 0))
{
// Send message
res = SmuWriteReg(cpuSettings.SMU_ADDR_MSG, msg);
if (res)
if (SmuWriteReg(cpuSettings.SMU_ADDR_MSG, msg))
{
// Check completion
res = SmuWaitDone();

if (res)
if (SmuWaitDone())
{
res = SmuReadReg(cpuSettings.SMU_ADDR_ARG0, ref data);
return SmuReadReg(cpuSettings.SMU_ADDR_ARG0, ref data);
}
}
}

return res;
return false;
}

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

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

// Clear response
if (res)
if (hMutexPci.WaitOne(5000))
{
res = SmuWriteReg(cpuSettings.SMU_ADDR_RSP, 0);
}

if (res)
{
// Write data
res = SmuWriteReg(cpuSettings.SMU_ADDR_ARG0, data);

if (res)
// Clear response
if (SmuWriteReg(cpuSettings.SMU_ADDR_RSP, 0))
{
SmuWriteReg(cpuSettings.SMU_ADDR_ARG1, 0);
}
// Send message
res = SmuWriteReg(cpuSettings.SMU_ADDR_MSG, msg);
// Write data
if (SmuWriteReg(cpuSettings.SMU_ADDR_ARG0, value))
{
SmuWriteReg(cpuSettings.SMU_ADDR_ARG1, 0);
}

if (res)
{
res = SmuWaitDone();
// Send message
if (SmuWriteReg(cpuSettings.SMU_ADDR_MSG, msg))
{
res = SmuWaitDone();
}
}
}

hMutexPci.ReleaseMutex();

return res;
}

public uint ReadDword(uint value)
private uint ReadDword(uint value)
{
ols.WritePciConfigDword(cpuSettings.SMU_PCI_ADDR, (byte)cpuSettings.SMU_OFFSET_ADDR, value);
Thread.Sleep(5000);
return ols.ReadPciConfigDword(cpuSettings.SMU_PCI_ADDR, (byte)cpuSettings.SMU_OFFSET_DATA);
}

Expand Down Expand Up @@ -903,28 +873,28 @@ public bool GetTemp(ref double Temp)
res = SmuReadReg(cpuSettings.THM_TCON_CUR_TMP, ref thmData);
if (res)
{
// Range sel = 0 to 255C (Temp = Tctl - offset)
Temp = (thmData >> 21) * 0.125 - TctlOffset;

// THMx000[31:21] = CUR_TEMP, THMx000[19] = CUR_TEMP_RANGE_SEL
if ((thmData & (1 << 19)) == 0)
{
// Range sel = 0 to 255C (Temp = Tctl - offset)
Temp = (thmData >> 21) * 0.125 - TctlOffset;
}
else
if ((thmData & (1 << 19)) != 0)
{
// Range sel = -49 to 206C (Temp = Tctl - offset - 49)
Temp = (thmData >> 21) * 0.125 - TctlOffset - 49;
Temp -= 49;
}
}

return res;
}

public UInt32 getSmuVersion()
public uint GetSmuVersion()
{
UInt32 version = 0;

SmuRead(cpuSettings.SMC_MSG_GetSmuVersion, ref version);
return version;
uint version = 0;
if (SmuRead(cpuSettings.SMC_MSG_GetSmuVersion, ref version))
{
return version;
}
return 0;
}

public bool WritePort80Temp(double temp)
Expand Down
61 changes: 1 addition & 60 deletions ZenStatesSrv/ZenStatesSrv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void Init()
di.MemWrite(DataInterface.REG_NOTIFY_STATUS, 0x00);
di.MemWrite(DataInterface.REG_SERVER_VERSION, DataInterface.ServiceVersion);
di.MemWrite(DataInterface.REG_PING_PONG, 0x01);
di.MemWrite(DataInterface.REG_SMU_VERSION, cpuh.getSmuVersion());
di.MemWrite(DataInterface.REG_SMU_VERSION, cpuh.GetSmuVersion());

for (int i = 0; i < CPUHandler.NumPstates; i++) di.MemWrite(DataInterface.REG_P0 + i, cpuh.Pstate[i]);
for (int i = 0; i < 2; i++) di.MemWrite(DataInterface.REG_BOOST_FREQ_0 + i, cpuh.Pstate[0]);
Expand Down Expand Up @@ -253,46 +253,6 @@ private static void t1Handler(object source, ElapsedEventArgs e)
{
cpuh.BoostFreq[i] = di.MemRead(DataInterface.REG_BOOST_FREQ_0 + i);
}
/*
// Apply settings
SetStartupService(true);
SetStartupGUI(cpuh.TrayIconAtStart);
// Write new P-states
if (cpuh.ZenOc)
{
if (cpuh.SetOcMode(true)) cpuh.setOverclockFrequencyAllCores(di.MemRead(DataInterface.REG_PSTATE_OC));
//cpuh.setCmdTemp(Convert.ToUInt32(cpuh.ZenScalar), Convert.ToUInt32(cpuh.ZenEDC));
}
else
{
cpuh.SetOcMode(false);
for (int i = 0; i < CPUHandler.NumPstates; i++)
{
cpuh.WritePstate(i, di.MemRead(DataInterface.REG_P0 + i));
}
if (cpuh.cpuType >= CPUHandler.CPUType.Matisse)
{
cpuh.setBoostFrequencySingleCore(di.MemRead(DataInterface.REG_BOOST_FREQ_0));
cpuh.setBoostFrequencyAllCores(di.MemRead(DataInterface.REG_BOOST_FREQ_1));
}
}
cpuh.SetC6Core(cpuh.ZenC6Core);
cpuh.SetC6Package(cpuh.ZenC6Package);
cpuh.SetCpb(cpuh.ZenCorePerfBoost);
if (cpuh.cpuType < CPUHandler.CPUType.Matisse)
{
cpuh.SetPPT(cpuh.ZenPPT);
cpuh.SetTDC(cpuh.ZenTDC);
cpuh.SetEDC(cpuh.ZenEDC);
}
cpuh.SetScalar(cpuh.ZenScalar);
cpuh.SetPerfBias(cpuh.PerformanceBias);
*/

applySettings();
cpuh.SettingsSaved = false;
Expand Down Expand Up @@ -475,25 +435,6 @@ static void SetStartupService(bool enable)
if (enable) ServiceHelper.ChangeStartMode(svc, ServiceStartMode.Automatic);
else ServiceHelper.ChangeStartMode(svc, ServiceStartMode.Manual);
}

static bool CheckUpdate()
{
using (WebClient client = new WebClient())
{

byte[] response =
client.UploadValues("http://elmorlabs.com/AsusZsUpdate", new NameValueCollection()
{
{ "version", Environment.Version.ToString() }

});

string result = System.Text.Encoding.UTF8.GetString(response);

if (result == "Yes") return true;
else return false;
}
}
}

public static class ServiceHelper
Expand Down

0 comments on commit c17ae90

Please sign in to comment.