forked from LibreHardwareMonitor/LibreHardwareMonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4e7f97
commit 01962cb
Showing
6 changed files
with
538 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: pull requests | |
|
||
on: | ||
pull_request: | ||
branches: [ master ] | ||
branches: [ 0.8.9 ] | ||
|
||
jobs: | ||
build: | ||
|
122 changes: 122 additions & 0 deletions
122
LibreHardwareMonitorLib/Hardware/Memory/AmdDimmSensor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. | ||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// Copyright (C) LibreHardwareMonitor and Contributors. | ||
// Partial Copyright (C) Michael Möller <[email protected]> and Contributors. | ||
// All Rights Reserved. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace LibreHardwareMonitor.Hardware.Memory | ||
{ | ||
internal sealed class AmdDimmSensor : DimmSensor | ||
{ | ||
public AmdDimmSensor(string name, int index, Hardware hardware, ISettings settings, byte address) : base(name, index, hardware, settings, address) | ||
{ | ||
|
||
} | ||
|
||
public override void UpdateSensor() | ||
{ | ||
try | ||
{ | ||
ushort data = GetWord(_address, 0x05); | ||
var temp = BitConverter.GetBytes(data); | ||
Array.Reverse(temp); | ||
|
||
temp[1] = (byte)(temp[1] & 0x0F); | ||
ushort count = BitConverter.ToUInt16(temp, 0); | ||
double value = count * 0.0625f; | ||
if (value > 0) | ||
{ | ||
Value = (float)value; | ||
} | ||
} | ||
catch { } | ||
} | ||
|
||
public static byte SmbDetect(byte addr) | ||
{ | ||
Ring0.WriteSmbus(SMB_HSTADD, (addr << 1) | SMB_WRITE); | ||
Ring0.WriteSmbus(SMB_HSTCNT, 0); | ||
if (Transaction() == true) | ||
{ | ||
return addr; | ||
} | ||
return 0x00; | ||
} | ||
|
||
private static ushort GetWord(byte addr, byte command) | ||
{ | ||
Ring0.WriteSmbus(SMB_HSTADD, (addr << 1) | SMB_READ); | ||
Ring0.WriteSmbus(SMB_HSTCMD, command); | ||
|
||
Ring0.WriteSmbus(SMB_HSTCNT, 0x0C); | ||
|
||
Transaction(); | ||
|
||
ushort temp = (ushort)(Ring0.ReadSmbus(SMB_HSTDAT0) + (Ring0.ReadSmbus(SMB_HSTDAT1) << 8)); | ||
return temp; | ||
} | ||
|
||
private static bool Transaction() | ||
{ | ||
byte temp = (byte)Ring0.ReadSmbus(SMB_HSTSTS); | ||
|
||
if (temp != 0x00) | ||
{ | ||
Ring0.WriteSmbus(SMB_HSTSTS, temp); | ||
|
||
temp = (byte)Ring0.ReadSmbus(SMB_HSTSTS); | ||
|
||
if (temp != 0x00) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
temp = (byte)Ring0.ReadSmbus(SMB_HSTCNT); | ||
Ring0.WriteSmbus(SMB_HSTCNT, (byte)(temp | 0x040)); | ||
|
||
temp = 0; | ||
int timeout = 0; | ||
int MAX_TIMEOUT = 5000; | ||
while ((++timeout < MAX_TIMEOUT) && temp <= 1) | ||
{ | ||
temp = (byte)Ring0.ReadSmbus(SMB_HSTSTS); | ||
} | ||
|
||
if (timeout == MAX_TIMEOUT || (temp & 0x10) > 0 || (temp & 0x08) > 0 || (temp & 0x04) > 0) | ||
{ | ||
return false; | ||
} | ||
|
||
temp = (byte)Ring0.ReadSmbus(SMB_HSTSTS); | ||
if (temp != 0x00) | ||
{ | ||
Ring0.WriteSmbus(SMB_HSTSTS, temp); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private const byte SMB_READ = 0x01; | ||
private const byte SMB_WRITE = 0x00; | ||
|
||
private const ushort SMB_ADDRESS = 0x0B00; | ||
|
||
private const ushort SMB_HSTSTS = (0 + SMB_ADDRESS); | ||
//private const ushort SMB_HSLVSTS = (1 + SMB_ADDRESS); | ||
private const ushort SMB_HSTCNT = (2 + SMB_ADDRESS); | ||
private const ushort SMB_HSTCMD = (3 + SMB_ADDRESS); | ||
private const ushort SMB_HSTADD = (4 + SMB_ADDRESS); | ||
private const ushort SMB_HSTDAT0 = (5 + SMB_ADDRESS); | ||
private const ushort SMB_HSTDAT1 = (6 + SMB_ADDRESS); | ||
//private const ushort SMB_BLKDAT = (7 + SMB_ADDRESS); | ||
//private const ushort SMB_SLVCNT = (8 + SMB_ADDRESS); | ||
//private const ushort SMB_SHDWCMD = (9 + SMB_ADDRESS); | ||
//private const ushort SMB_SLVEVT = (0xA + SMB_ADDRESS); | ||
//private const ushort SMB_SLVDAT = (0xC + SMB_ADDRESS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. | ||
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// Copyright (C) LibreHardwareMonitor and Contributors. | ||
// Partial Copyright (C) Michael Möller <[email protected]> and Contributors. | ||
// All Rights Reserved. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
|
||
namespace LibreHardwareMonitor.Hardware.Memory | ||
{ | ||
internal class DimmSensor : Sensor | ||
{ | ||
protected byte _address; | ||
|
||
public DimmSensor(string name, int index, Hardware hardware, ISettings settings, byte address) : base(name, index, SensorType.Temperature, hardware, settings) | ||
{ | ||
_address = address; | ||
} | ||
|
||
public virtual void UpdateSensor() | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,10 @@ | |
// Partial Copyright (C) Michael Möller <[email protected]> and Contributors. | ||
// All Rights Reserved. | ||
|
||
using System.Collections.Generic; | ||
using System.Management; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using LibreHardwareMonitor.Interop; | ||
|
||
namespace LibreHardwareMonitor.Hardware.Memory | ||
|
@@ -18,6 +21,8 @@ internal sealed class GenericMemory : Hardware | |
private readonly Sensor _virtualMemoryLoad; | ||
private readonly Sensor _virtualMemoryUsed; | ||
|
||
private readonly List<DimmSensor> _dimmSensorList = new List<DimmSensor>(); | ||
|
||
public GenericMemory(string name, ISettings settings) : base(name, new Identifier("ram"), settings) | ||
{ | ||
_physicalMemoryUsed = new Sensor("Memory Used", 0, SensorType.Data, this, settings); | ||
|
@@ -37,6 +42,93 @@ internal sealed class GenericMemory : Hardware | |
|
||
_virtualMemoryLoad = new Sensor("Virtual Memory", 1, SensorType.Load, this, settings); | ||
ActivateSensor(_virtualMemoryLoad); | ||
|
||
|
||
AddDimm(settings); | ||
} | ||
|
||
private void AddDimm(ISettings settings) | ||
{ | ||
try | ||
{ | ||
string wmiQuery = "SELECT * FROM Win32_PnPSignedDriver WHERE Description LIKE '%%SMBUS%%' OR Description LIKE '%%SM BUS%%'"; | ||
var searcher = new ManagementObjectSearcher(wmiQuery); | ||
var collection = searcher.Get(); | ||
string manufacturer = ""; | ||
foreach (var obj in collection) | ||
{ | ||
manufacturer = obj["Manufacturer"].ToString().ToUpper(); | ||
if (manufacturer.Equals("INTEL") == true) | ||
{ | ||
wmiQuery = "SELECT * FROM Win32_PnPAllocatedResource"; | ||
string deviceID = obj["DeviceID"].ToString().Substring(4, 33); | ||
|
||
var searcher2 = new ManagementObjectSearcher(wmiQuery); | ||
var collection2 = searcher2.Get(); | ||
foreach (var obj2 in collection2) | ||
{ | ||
string dependent = obj2["Dependent"].ToString(); | ||
string antecedent = obj2["Antecedent"].ToString(); | ||
|
||
if (dependent.IndexOf(deviceID) >= 0 && antecedent.IndexOf("Port") >= 0) | ||
{ | ||
var antecedentArray = antecedent.Split('='); | ||
if (antecedentArray.Length >= 2) | ||
{ | ||
string addressString = antecedentArray[1].Replace("\"", ""); | ||
if (addressString.Length > 0) | ||
{ | ||
ushort startAddress = ushort.Parse(addressString); | ||
IntelDimmSensor.SetSMBAddress(startAddress); | ||
|
||
if (Ring0.WaitsmBusMutex(100)) | ||
{ | ||
int index = 0; | ||
for (byte addr = 0x18; addr <= 0x20; addr++) | ||
{ | ||
var data = IntelDimmSensor.SmbDetect(addr); | ||
if (data == addr) | ||
{ | ||
var sensor = new IntelDimmSensor("DIMM #" + index, index, this, settings, addr); | ||
_dimmSensorList.Add(sensor); | ||
ActivateSensor(sensor); | ||
} | ||
Thread.Sleep(10); | ||
index++; | ||
} | ||
Ring0.ReleasesmBusMutex(); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
else if (manufacturer.Equals("ADVANCED MICRO DEVICES, INC") == true) | ||
{ | ||
if (Ring0.WaitsmBusMutex(100)) | ||
{ | ||
int index = 0; | ||
for (byte addr = 0x18; addr <= 0x20; addr++) | ||
{ | ||
var data = AmdDimmSensor.SmbDetect(addr); | ||
if (data == addr) | ||
{ | ||
var sensor = new AmdDimmSensor("DIMM #" + index, index, this, settings, addr); | ||
_dimmSensorList.Add(sensor); | ||
ActivateSensor(sensor); | ||
} | ||
Thread.Sleep(10); | ||
index++; | ||
} | ||
Ring0.ReleasesmBusMutex(); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
catch { } | ||
} | ||
|
||
public override HardwareType HardwareType | ||
|
@@ -59,6 +151,19 @@ public override void Update() | |
_virtualMemoryUsed.Value = (float)(status.ullTotalPageFile - status.ullAvailPageFile) / (1024 * 1024 * 1024); | ||
_virtualMemoryAvailable.Value = (float)status.ullAvailPageFile / (1024 * 1024 * 1024); | ||
_virtualMemoryLoad.Value = 100.0f - (100.0f * status.ullAvailPageFile) / status.ullTotalPageFile; | ||
|
||
|
||
if (!Ring0.WaitsmBusMutex(10)) | ||
return; | ||
|
||
for (int i = 0; i < _dimmSensorList.Count; i++) | ||
{ | ||
_dimmSensorList[i].UpdateSensor(); | ||
Thread.Sleep(10); | ||
} | ||
|
||
Ring0.ReleasesmBusMutex(); | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.