Skip to content

Commit d6fa547

Browse files
committed
Merge remote-tracking branch 'lib/master'
# Conflicts: # OpenHardwareMonitorLib/Hardware/Memory/MemoryGroup.cs # OpenHardwareMonitorLib/Hardware/Motherboard/Lpc/LpcIO.cs
2 parents 7d27a3e + 06b714a commit d6fa547

File tree

9 files changed

+286
-101
lines changed

9 files changed

+286
-101
lines changed
Lines changed: 146 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading;
27
using System.Threading.Tasks;
38
using RAMSPDToolkit.I2CSMBus;
49
using RAMSPDToolkit.SPD;
@@ -9,116 +14,196 @@
914

1015
namespace OpenHardwareMonitor.Hardware.Memory;
1116

12-
internal class MemoryGroup : IGroup
17+
internal class MemoryGroup : IGroup, IHardwareChanged
1318
{
14-
//Retry 12x
15-
private const int RetryCount = 12;
16-
//Retry every 2.5 seconds
17-
private const int RetryTime = 2500;
1819
private static readonly object _lock = new();
20+
private List<Hardware> _hardware = [];
1921

20-
private readonly List<Hardware> _hardware = [];
22+
private CancellationTokenSource _cancellationTokenSource;
23+
private Exception _lastException;
24+
private bool _opened = false;
2125

22-
static MemoryGroup()
26+
public MemoryGroup(ISettings settings)
2327
{
24-
if (OperatingSystemHelper.IsAdministrator() && Ring0.IsOpen)
28+
if (Ring0.IsOpen && (DriverManager.Driver is null || !DriverManager.Driver.IsOpen))
2529
{
26-
//Assign implementation of IDriver
30+
// Assign implementation of IDriver.
2731
DriverManager.Driver = new RAMSPDToolkitDriver(Ring0.KernelDriver);
2832
SMBusManager.UseWMI = false;
2933
}
30-
}
3134

32-
public MemoryGroup(ISettings settings)
33-
{
34-
_hardware.Add(new TotalMemory(settings));
3535
_hardware.Add(new VirtualMemory(settings));
36+
_hardware.Add(new TotalMemory(settings));
3637

37-
if (OperatingSystemHelper.IsAdministrator())
38+
if (DriverManager.Driver == null)
3839
{
39-
Task.Run(async () =>
40-
{
41-
var _elapsedCounter = 0;
42-
while (true)
43-
{
44-
//SMBus might not be detected right after boot
45-
if (DetectThermalSensors(out var accessors) || _elapsedCounter++ >= RetryCount)
46-
{
47-
if (accessors != null)
48-
AddDimms(accessors, settings);
49-
break;
50-
}
51-
await Task.Delay(RetryTime);
52-
}
53-
});
40+
return;
5441
}
55-
}
5642

57-
public string GetReport()
58-
{
59-
return null;
43+
if (!TryAddDimms(settings))
44+
{
45+
StartRetryTask(settings);
46+
}
47+
48+
_opened = true;
6049
}
6150

51+
public event HardwareEventHandler HardwareAdded;
52+
public event HardwareEventHandler HardwareRemoved;
53+
6254
public IReadOnlyList<IHardware> Hardware => _hardware;
6355

64-
public void Close()
56+
public string GetReport()
6557
{
66-
foreach (Hardware ram in _hardware)
67-
ram.Close();
58+
StringBuilder report = new();
59+
report.AppendLine("Memory Report:");
60+
if (_lastException != null)
61+
{
62+
report.AppendLine($"Error while detecting memory: {_lastException.Message}");
63+
}
64+
65+
foreach (Hardware hardware in _hardware)
66+
{
67+
report.AppendLine($"{hardware.Name} ({hardware.Identifier}):");
68+
report.AppendLine();
69+
foreach (ISensor sensor in hardware.Sensors)
70+
{
71+
report.AppendLine($"{sensor.Name}: {sensor.Value?.ToString() ?? "No value"}");
72+
}
73+
}
74+
75+
return report.ToString();
6876
}
6977

70-
private static bool DetectThermalSensors(out List<SPDAccessor> accessors)
78+
public void Close()
7179
{
7280
lock (_lock)
7381
{
74-
var list = new List<SPDAccessor>();
82+
_opened = false;
83+
foreach (Hardware ram in _hardware)
84+
ram.Close();
7585

76-
bool ramDetected = false;
86+
_hardware.Clear();
7787

78-
SMBusManager.DetectSMBuses();
88+
_cancellationTokenSource?.Cancel();
89+
_cancellationTokenSource?.Dispose();
90+
_cancellationTokenSource = null;
91+
}
92+
}
7993

80-
//Go through detected SMBuses
81-
foreach (var smbus in SMBusManager.RegisteredSMBuses)
94+
private bool TryAddDimms(ISettings settings)
95+
{
96+
try
97+
{
98+
lock (_lock)
8299
{
83-
//Go through possible RAM slots
84-
for (byte i = SPDConstants.SPD_BEGIN; i <= SPDConstants.SPD_END; ++i)
100+
if (!_opened)
85101
{
86-
//Detect type of RAM, if available
87-
var detector = new SPDDetector(smbus, i);
102+
return true;
103+
}
88104

89-
//RAM available and detected
90-
if (detector.Accessor != null)
105+
if (DetectThermalSensors(out List<SPDAccessor> accessors))
106+
{
107+
AddDimms(accessors, settings);
108+
return true;
109+
}
110+
}
111+
}
112+
catch (Exception ex)
113+
{
114+
_lastException = ex;
115+
Debug.Assert(false, "Exception while detecting RAM: " + ex.Message);
116+
}
117+
118+
return false;
119+
}
120+
121+
private void StartRetryTask(ISettings settings)
122+
{
123+
_cancellationTokenSource = new CancellationTokenSource();
124+
125+
Task.Run(async () =>
126+
{
127+
int retryRemaining = 5;
128+
129+
while (!_cancellationTokenSource.IsCancellationRequested && --retryRemaining > 0)
130+
{
131+
await Task.Delay(TimeSpan.FromSeconds(2.5), _cancellationTokenSource.Token).ConfigureAwait(false);
132+
133+
if (TryAddDimms(settings))
134+
{
135+
lock (_lock)
91136
{
92-
//We are only interested in modules with thermal sensor
93-
if (detector.Accessor is IThermalSensor { HasThermalSensor: true })
94-
list.Add(detector.Accessor);
137+
if (!_opened)
138+
{
139+
return;
140+
}
141+
142+
foreach (Hardware hardware in _hardware.OfType<DimmMemory>())
143+
{
144+
HardwareAdded?.Invoke(hardware);
145+
}
95146

96-
ramDetected = true;
147+
_cancellationTokenSource.Dispose();
148+
_cancellationTokenSource = null;
149+
150+
break;
97151
}
152+
98153
}
99154
}
155+
}, _cancellationTokenSource.Token);
156+
}
100157

101-
accessors = list.Count > 0 ? list : [];
102-
return ramDetected;
158+
private static bool DetectThermalSensors(out List<SPDAccessor> accessors)
159+
{
160+
accessors = [];
161+
162+
bool ramDetected = false;
163+
164+
SMBusManager.DetectSMBuses();
165+
166+
//Go through detected SMBuses
167+
foreach (SMBusInterface smbus in SMBusManager.RegisteredSMBuses)
168+
{
169+
//Go through possible RAM slots
170+
for (byte i = SPDConstants.SPD_BEGIN; i <= SPDConstants.SPD_END; ++i)
171+
{
172+
//Detect type of RAM, if available
173+
SPDDetector detector = new(smbus, i);
174+
175+
//RAM available and detected
176+
if (detector.Accessor != null)
177+
{
178+
//We are only interested in modules with thermal sensor
179+
if (detector.Accessor is IThermalSensor { HasThermalSensor: true })
180+
accessors.Add(detector.Accessor);
181+
182+
ramDetected = true;
183+
}
184+
}
103185
}
186+
187+
return ramDetected;
104188
}
105189

106190
private void AddDimms(List<SPDAccessor> accessors, ISettings settings)
107191
{
108-
foreach (var ram in accessors)
192+
List<Hardware> newHardwareList = [.. _hardware];
193+
194+
foreach (SPDAccessor ram in accessors)
109195
{
110196
//Default value
111197
string name = $"DIMM #{ram.Index}";
112198

113199
//Check if we can switch to the correct page
114200
if (ram.ChangePage(PageData.ModulePartNumber))
115-
{
116201
name = $"{ram.GetModuleManufacturerString()} - {ram.ModulePartNumber()} (#{ram.Index})";
117-
}
118202

119-
var memory = new DimmMemory(ram, name, new Identifier("ram"), settings);
120-
121-
_hardware.Add(memory);
203+
DimmMemory memory = new(ram, name, new Identifier($"memory/dimm/{ram.Index}"), settings);
204+
newHardwareList.Add(memory);
122205
}
206+
207+
_hardware = newHardwareList;
123208
}
124209
}

OpenHardwareMonitorLib/Hardware/Motherboard/Identification.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public static Model GetModel(string name)
103103
{
104104
switch (name)
105105
{
106+
case var _ when name.Equals("X870 AORUS ELITE WIFI7", StringComparison.OrdinalIgnoreCase):
107+
return Model.X870_AORUS_ELITE_WIFI7;
106108
case var _ when name.Equals("880GMH/USB3", StringComparison.OrdinalIgnoreCase):
107109
return Model._880GMH_USB3;
108110
case var _ when name.Equals("B85M-DGS", StringComparison.OrdinalIgnoreCase):
@@ -617,12 +619,16 @@ public static Model GetModel(string name)
617619
return Model.X870E_AORUS_PRO;
618620
case var _ when name.Equals("X870E AORUS PRO ICE", StringComparison.OrdinalIgnoreCase):
619621
return Model.X870E_AORUS_PRO_ICE;
622+
case var _ when name.Equals("ROG STRIX X870-I GAMING WIFI", StringComparison.OrdinalIgnoreCase):
623+
return Model.ROG_STRIX_X870_I_GAMING_WIFI;
620624
case var _ when name.Equals("X870E AORUS XTREME AI TOP", StringComparison.OrdinalIgnoreCase):
621625
return Model.X870E_AORUS_XTREME_AI_TOP;
622626
case var _ when name.Equals("PROART X870E-CREATOR WIFI", StringComparison.OrdinalIgnoreCase):
623627
return Model.PROART_X870E_CREATOR_WIFI;
624628
case var _ when name.Equals("PRIME X870-P", StringComparison.OrdinalIgnoreCase):
625629
return Model.PRIME_X870_P;
630+
case var _ when name.Equals("ROG STRIX X870-I GAMING WIFI", StringComparison.OrdinalIgnoreCase):
631+
return Model.ROG_STRIX_X870_I_GAMING_WIFI;
626632
case var _ when name.Equals("ROG CROSSHAIR X870E HERO", StringComparison.OrdinalIgnoreCase):
627633
return Model.ROG_CROSSHAIR_X870E_HERO;
628634
case var _ when name.Equals("MAG X870 TOMAHAWK WIFI (MS-7E51)", StringComparison.OrdinalIgnoreCase):

OpenHardwareMonitorLib/Hardware/Motherboard/Lpc/EC/EmbeddedController.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ public abstract class EmbeddedController : Hardware
274274
ECSensor.CurrCPU,
275275
ECSensor.FanCPUOpt,
276276
ECSensor.FanWaterFlow),
277+
new(Model.ROG_STRIX_X870_I_GAMING_WIFI,
278+
BoardFamily.Amd800,
279+
ECSensor.TempCPU,
280+
ECSensor.TempCPUPackage,
281+
ECSensor.TempMB,
282+
ECSensor.TempVrm),
277283
};
278284

279285
private static readonly Dictionary<BoardFamily, Dictionary<ECSensor, EmbeddedControllerSource>> _knownSensors = new()
@@ -322,6 +328,17 @@ public abstract class EmbeddedController : Hardware
322328
{ ECSensor.TempWaterOut, new EmbeddedControllerSource("Water Out", SensorType.Temperature, 0x0101, blank: -40) }
323329
}
324330
},
331+
{
332+
BoardFamily.Amd800, new Dictionary<ECSensor, EmbeddedControllerSource>
333+
{
334+
{ ECSensor.TempCPU, new EmbeddedControllerSource("CPU", SensorType.Temperature, 0x0030) },
335+
{ ECSensor.TempCPUPackage, new EmbeddedControllerSource("CPU Package", SensorType.Temperature, 0x0031) },
336+
{ ECSensor.TempMB, new EmbeddedControllerSource("Motherboard", SensorType.Temperature, 0x0032) },
337+
{ ECSensor.TempVrm, new EmbeddedControllerSource("VRM", SensorType.Temperature, 0x0033) },
338+
{ ECSensor.TempTSensor, new EmbeddedControllerSource("T Sensor", SensorType.Temperature, 0x0036, blank: -40) },
339+
{ ECSensor.FanCPUOpt, new EmbeddedControllerSource("CPU Optional Fan", SensorType.Fan, 0x00b0, 2) }
340+
}
341+
},
325342
{
326343
BoardFamily.Intel100, new Dictionary<ECSensor, EmbeddedControllerSource>
327344
{
@@ -532,6 +549,9 @@ private enum ECSensor
532549

533550
/// <summary>CPU temperature [℃]</summary>
534551
TempCPU,
552+
553+
/// <summary>CPU Package temperature [℃]</summary>
554+
TempCPUPackage,
535555

536556
/// <summary>motherboard temperature [℃]</summary>
537557
TempMB,
@@ -582,6 +602,7 @@ private enum BoardFamily
582602
Amd400,
583603
Amd500,
584604
Amd600,
605+
Amd800,
585606
Intel100,
586607
Intel300,
587608
Intel400,

OpenHardwareMonitorLib/Hardware/Motherboard/Lpc/IT87XX.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public IT87XX(Chip chip, ushort address, ushort gpioAddress, byte version, Mothe
6969
{
7070
Chip.IT8665E or Chip.IT8625E => new byte[] { 0x15, 0x16, 0x17, 0x1e, 0x1f, 0x92 },
7171
Chip.IT8792E => new byte[] { 0x15, 0x16, 0x17 },
72+
Chip.IT8696E => new byte[] { 0, 0, 0, 0, 0 },
7273
_ => new byte[] { 0x15, 0x16, 0x17, 0x7f, 0xa7, 0xaf }
7374
};
7475

@@ -155,8 +156,8 @@ Chip.IT8631E or
155156
case Chip.IT8696E:
156157
Voltages = new float?[10];
157158
Temperatures = new float?[6];
158-
Fans = new float?[6];
159-
Controls = new float?[6];
159+
Fans = new float?[5];
160+
Controls = new float?[5];
160161
break;
161162

162163
case Chip.IT87952E:

OpenHardwareMonitorLib/Hardware/Motherboard/Lpc/LpcIO.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ private bool DetectWinbondFintek(LpcPort port, Motherboard motherboard)
383383
case 0xD5:
384384
switch (revision)
385385
{
386-
case 0x92:
386+
case 0x92:
387387
switch (motherboard.Model)
388388
{
389389
case Model.B840P_PRO_WIFI:
@@ -405,14 +405,13 @@ private bool DetectWinbondFintek(LpcPort port, Motherboard motherboard)
405405
case Model.Z890_EDGE_TI_WIFI:
406406
case Model.Z890P_PRO_WIFI:
407407
case Model.Z890A_PRO_WIFI:
408-
case Model.Z890_GAMING_PLUS_WIFI:
409-
case Model.Z890S_PRO_WIFI_PROJECT_ZERO:
410408
chip = Chip.NCT6687DR; // MSI AM5/LGA1851 Compatibility
411409
break;
412410
default:
413411
chip = Chip.NCT6687D;
414412
break;
415413
}
414+
416415
logicalDeviceNumber = WINBOND_NUVOTON_HARDWARE_MONITOR_LDN;
417416
break;
418417
}
@@ -774,6 +773,7 @@ private IGigabyteController FindGigabyteECUsingSmfi(LpcPort port, Chip chip, Ven
774773
private const byte IT87_LD_ACTIVE_REGISTER = 0x30;
775774

776775
private readonly ushort[] REGISTER_PORTS = { 0x2E, 0x4E };
776+
777777
private readonly ushort[] VALUE_PORTS = { 0x2F, 0x4F };
778778
// ReSharper restore InconsistentNaming
779779
}

0 commit comments

Comments
 (0)