-
-
Notifications
You must be signed in to change notification settings - Fork 558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix missing view for IT8792E and allow fan control for IT8792E on some Gigabyte AMD boards #1313
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3100899
Check before entering bugged 0x4E IT87
pwnedgod 853d10f
Specify fan control registers for IT8792E
pwnedgod c24837e
Refactor chip ID reading using TryReadWord
pwnedgod 1e7b351
Introduce ECIO gigabyte EC control
pwnedgod 03a2d9a
Add ECIO compatibility check
pwnedgod 5a76249
Refactor to consider result of read/write
pwnedgod 41714f7
Refactor styles and syntaxes
pwnedgod da88a0f
Rename SMFI to Smfi
pwnedgod d3287ed
Remove public modifier for consistency
pwnedgod 4705194
Update code style
pwnedgod c2fd6ac
Increase timeout and remove sleep for ecio waits
pwnedgod 474c4ca
Remove extra WaitIBE
pwnedgod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
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,69 @@ | ||
// 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, (byte)(enabled ? 1 : 0))) | ||
return false; | ||
|
||
// Allow the system to catch up. | ||
Thread.Sleep(250); | ||
} | ||
|
||
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(); | ||
} |
112 changes: 112 additions & 0 deletions
112
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,112 @@ | ||
// 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; | ||
using System.Threading; | ||
|
||
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) | ||
{ | ||
value = 0; | ||
|
||
if (!WriteToRegister(0xB0) || | ||
!WriteToValue((byte)((offset >> 8) & 0xFF)) || | ||
!WriteToValue((byte)(offset & 0xFF))) | ||
return false; | ||
|
||
return ReadFromValue(out value); | ||
} | ||
|
||
public bool Write(ushort offset, byte value) | ||
{ | ||
if (!WriteToRegister(0xB1) || | ||
!WriteToValue((byte)((offset >> 8) & 0xFF)) || | ||
!WriteToValue((byte)(offset & 0xFF))) | ||
return false; | ||
|
||
return WriteToValue(value); | ||
} | ||
|
||
private bool WriteToRegister(byte value) | ||
{ | ||
if (!WaitIBE()) | ||
return false; | ||
Ring0.WriteIoPort(RegisterPort, value); | ||
return WaitIBE(); | ||
} | ||
|
||
private bool WriteToValue(byte value) | ||
{ | ||
if (!WaitIBE()) | ||
return false; | ||
Ring0.WriteIoPort(ValuePort, value); | ||
return WaitIBE(); | ||
} | ||
|
||
private bool ReadFromValue(out byte value) | ||
{ | ||
value = 0; | ||
if (!WaitOBF()) | ||
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; | ||
|
||
Thread.Sleep(1); | ||
} | ||
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; | ||
|
||
Thread.Sleep(1); | ||
} | ||
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow code style in this file (add braces, new lines, etc).