-
-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix missing view for IT8792E and allow fan control for IT8792E on som…
…e Gigabyte AMD boards (#1313) * Check before entering bugged 0x4E IT87 * Specify fan control registers for IT8792E * Refactor chip ID reading using TryReadWord * Introduce ECIO gigabyte EC control * Add ECIO compatibility check * Refactor to consider result of read/write * Refactor styles and syntaxes * Rename SMFI to Smfi * Remove public modifier for consistency * Update code style * Increase timeout and remove sleep for ecio waits * Remove extra WaitIBE
- Loading branch information
Showing
7 changed files
with
289 additions
and
27 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/EcioPortGigabyteController.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,77 @@ | ||
// 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 <mmoeller@openhardwaremonitor.org> and Contributors. | ||
// All Rights Reserved. | ||
|
||
using System; | ||
using System.Threading; | ||
|
||
namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc; | ||
|
||
internal class EcioPortGigabyteController : IGigabyteController | ||
{ | ||
private const ushort ControllerVersionOffset = 0x00; | ||
private const ushort ControllerEnableRegister = 0x47; | ||
private const ushort ControllerFanControlArea = 0x900; | ||
|
||
private const ushort EcioRegisterPort = 0x3F4; | ||
private const ushort EcioValuePort = 0x3F0; | ||
|
||
private readonly IT879xEcioPort _port; | ||
|
||
private bool? _initialState; | ||
|
||
private EcioPortGigabyteController(IT879xEcioPort port) | ||
{ | ||
_port = port; | ||
} | ||
|
||
public static EcioPortGigabyteController TryCreate() | ||
{ | ||
IT879xEcioPort port = new(EcioRegisterPort, EcioValuePort); | ||
|
||
// Check compatibility by querying its version. | ||
if (!port.Read(ControllerFanControlArea + ControllerVersionOffset, out byte majorVersion) || majorVersion != 1) | ||
{ | ||
return null; | ||
} | ||
|
||
return new EcioPortGigabyteController(port); | ||
} | ||
|
||
public bool Enable(bool enabled) | ||
{ | ||
ushort offset = ControllerFanControlArea + ControllerEnableRegister; | ||
|
||
if (!_port.Read(offset, out byte bCurrent)) | ||
{ | ||
return false; | ||
} | ||
|
||
bool current = Convert.ToBoolean(bCurrent); | ||
|
||
_initialState ??= current; | ||
|
||
if (current != enabled) | ||
{ | ||
if (!_port.Write(offset, Convert.ToByte(enabled))) | ||
{ | ||
return false; | ||
} | ||
|
||
// Allow the system to catch up. | ||
Thread.Sleep(500); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public void Restore() | ||
{ | ||
if (_initialState.HasValue) | ||
{ | ||
Enable(_initialState.Value); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/IGigabyteController.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,14 @@ | ||
// 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 <mmoeller@openhardwaremonitor.org> and Contributors. | ||
// All Rights Reserved. | ||
|
||
namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc; | ||
|
||
internal interface IGigabyteController | ||
{ | ||
bool Enable(bool enabled); | ||
|
||
void Restore(); | ||
} |
139 changes: 139 additions & 0 deletions
139
LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/IT879xEcioPort.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,139 @@ | ||
// 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 <mmoeller@openhardwaremonitor.org> and Contributors. | ||
// All Rights Reserved. | ||
|
||
using System.Diagnostics; | ||
|
||
namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc; | ||
|
||
internal class IT879xEcioPort | ||
{ | ||
public IT879xEcioPort(ushort registerPort, ushort valuePort) | ||
{ | ||
RegisterPort = registerPort; | ||
ValuePort = valuePort; | ||
} | ||
|
||
public ushort RegisterPort { get; } | ||
|
||
public ushort ValuePort { get; } | ||
|
||
public bool Read(ushort offset, out byte value) | ||
{ | ||
if (!Init(0xB0, offset)) | ||
{ | ||
value = 0; | ||
return false; | ||
} | ||
|
||
return ReadFromValue(out value); | ||
} | ||
|
||
public bool Write(ushort offset, byte value) | ||
{ | ||
if (!Init(0xB1, offset)) | ||
{ | ||
return false; | ||
} | ||
|
||
return WriteToValue(value); | ||
} | ||
|
||
private bool Init(byte command, ushort offset) | ||
{ | ||
if (!WriteToRegister(command)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (!WriteToValue((byte)((offset >> 8) & 0xFF))) | ||
{ | ||
return false; | ||
} | ||
|
||
if (!WriteToValue((byte)(offset & 0xFF))) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private bool WriteToRegister(byte value) | ||
{ | ||
if (!WaitIBE()) | ||
{ | ||
return false; | ||
} | ||
|
||
Ring0.WriteIoPort(RegisterPort, value); | ||
return true; | ||
} | ||
|
||
private bool WriteToValue(byte value) | ||
{ | ||
if (!WaitIBE()) | ||
{ | ||
return false; | ||
} | ||
|
||
Ring0.WriteIoPort(ValuePort, value); | ||
return true; | ||
} | ||
|
||
private bool ReadFromValue(out byte value) | ||
{ | ||
if (!WaitOBF()) | ||
{ | ||
value = 0; | ||
return false; | ||
} | ||
|
||
value = Ring0.ReadIoPort(ValuePort); | ||
return true; | ||
} | ||
|
||
private bool WaitIBE() | ||
{ | ||
Stopwatch stopwatch = Stopwatch.StartNew(); | ||
try | ||
{ | ||
while ((Ring0.ReadIoPort(RegisterPort) & 2) != 0) | ||
{ | ||
if (stopwatch.ElapsedMilliseconds > WAIT_TIMEOUT) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
finally | ||
{ | ||
stopwatch.Stop(); | ||
} | ||
} | ||
|
||
private bool WaitOBF() | ||
{ | ||
Stopwatch stopwatch = Stopwatch.StartNew(); | ||
try | ||
{ | ||
while ((Ring0.ReadIoPort(RegisterPort) & 1) == 0) | ||
{ | ||
if (stopwatch.ElapsedMilliseconds > WAIT_TIMEOUT) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
finally | ||
{ | ||
stopwatch.Stop(); | ||
} | ||
} | ||
|
||
private const long WAIT_TIMEOUT = 1000L; | ||
} |
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
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
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
Oops, something went wrong.