From 56425669e8e4e83e908158920041d7efd4e432d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Wed, 4 Aug 2010 20:27:05 +0000 Subject: [PATCH] Added an ISA bus mutex. --- Hardware/LPC/F718XX.cs | 14 ++++++++++-- Hardware/LPC/IT87XX.cs | 13 +++++++++-- Hardware/LPC/W836XX.cs | 10 +++++++++ Hardware/WinRing0.cs | 49 ++++++++++++++++++++++++++++-------------- 4 files changed, 66 insertions(+), 20 deletions(-) diff --git a/Hardware/LPC/F718XX.cs b/Hardware/LPC/F718XX.cs index 84c8033..a824bda 100644 --- a/Hardware/LPC/F718XX.cs +++ b/Hardware/LPC/F718XX.cs @@ -87,9 +87,12 @@ namespace OpenHardwareMonitor.Hardware.LPC { r.AppendLine(); r.Append("Base Adress: 0x"); r.AppendLine(address.ToString("X4")); r.AppendLine(); + + if (!WinRing0.WaitIsaBusMutex()) + return r.ToString(); + r.AppendLine("Hardware Monitor Registers"); r.AppendLine(); - r.AppendLine(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F"); r.AppendLine(); for (int i = 0; i <= 0xF; i++) { @@ -101,10 +104,15 @@ namespace OpenHardwareMonitor.Hardware.LPC { r.AppendLine(); } r.AppendLine(); + + WinRing0.ReleaseIsaBusMutex(); + return r.ToString(); } public void Update() { + if (!WinRing0.WaitIsaBusMutex()) + return; for (int i = 0; i < voltages.Length; i++) { int value = ReadByte((byte)(VOLTAGE_BASE_REG + i)); @@ -154,7 +162,9 @@ namespace OpenHardwareMonitor.Hardware.LPC { fans[i] = (value < 0x0fff) ? 1.5e6f / value : 0; else fans[i] = null; - } + } + + WinRing0.ReleaseIsaBusMutex(); } } } diff --git a/Hardware/LPC/IT87XX.cs b/Hardware/LPC/IT87XX.cs index c0a3f88..64a5e63 100644 --- a/Hardware/LPC/IT87XX.cs +++ b/Hardware/LPC/IT87XX.cs @@ -118,9 +118,12 @@ namespace OpenHardwareMonitor.Hardware.LPC { r.Append("Chip Version: 0x"); r.AppendLine(version.ToString("X")); r.Append("Base Address: 0x"); r.AppendLine(address.ToString("X4")); r.AppendLine(); + + if (!WinRing0.WaitIsaBusMutex()) + return r.ToString(); + r.AppendLine("Environment Controller Registers"); r.AppendLine(); - r.AppendLine(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F"); r.AppendLine(); for (int i = 0; i <= 0xA; i++) { @@ -138,10 +141,14 @@ namespace OpenHardwareMonitor.Hardware.LPC { } r.AppendLine(); + WinRing0.ReleaseIsaBusMutex(); + return r.ToString(); } public void Update() { + if (!WinRing0.WaitIsaBusMutex()) + return; for (int i = 0; i < voltages.Length; i++) { bool valid; @@ -182,7 +189,9 @@ namespace OpenHardwareMonitor.Hardware.LPC { } else { fans[i] = null; } - } + } + + WinRing0.ReleaseIsaBusMutex(); } } } diff --git a/Hardware/LPC/W836XX.cs b/Hardware/LPC/W836XX.cs index f7e8751..0462a2c 100644 --- a/Hardware/LPC/W836XX.cs +++ b/Hardware/LPC/W836XX.cs @@ -194,6 +194,8 @@ namespace OpenHardwareMonitor.Hardware.LPC { public float?[] Fans { get { return fans; } } public void Update() { + if (!WinRing0.WaitIsaBusMutex()) + return; for (int i = 0; i < voltages.Length; i++) { if (voltageRegister[i] != VOLTAGE_VBAT_REG) { @@ -279,6 +281,8 @@ namespace OpenHardwareMonitor.Hardware.LPC { if (oldByte != newByte) WriteByte(0, FAN_BIT_REG[i], newByte); } + + WinRing0.ReleaseIsaBusMutex(); } public string GetReport() { @@ -290,6 +294,10 @@ namespace OpenHardwareMonitor.Hardware.LPC { r.Append("Chip revision: 0x"); r.AppendLine(revision.ToString("X")); r.Append("Base Adress: 0x"); r.AppendLine(address.ToString("X4")); r.AppendLine(); + + if (!WinRing0.WaitIsaBusMutex()) + return r.ToString(); + r.AppendLine("Hardware Monitor Registers"); r.AppendLine(); r.AppendLine(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F"); @@ -316,6 +324,8 @@ namespace OpenHardwareMonitor.Hardware.LPC { } r.AppendLine(); + WinRing0.ReleaseIsaBusMutex(); + return r.ToString(); } } diff --git a/Hardware/WinRing0.cs b/Hardware/WinRing0.cs index 8f57941..5a04de5 100644 --- a/Hardware/WinRing0.cs +++ b/Hardware/WinRing0.cs @@ -39,7 +39,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; -using System.Text; +using System.Threading; namespace OpenHardwareMonitor.Hardware { @@ -56,6 +56,7 @@ namespace OpenHardwareMonitor.Hardware { } private static bool available = false; + public static Mutex isaBusMutex; private static string GetDllName() { int p = (int)System.Environment.OSVersion.Platform; @@ -103,20 +104,22 @@ namespace OpenHardwareMonitor.Hardware { private static InitializeOlsDelegate InitializeOls; private static DeinitializeOlsDelegate DeinitializeOls; - public static GetDllStatusDelegate GetDllStatus; - public static IsCpuidDelegate IsCpuid; - public static CpuidDelegate Cpuid; - public static CpuidTxDelegate CpuidTx; - public static RdmsrDelegate Rdmsr; - public static RdmsrTxDelegate RdmsrTx; - public static ReadIoPortByteDelegate ReadIoPortByte; - public static WriteIoPortByteDelegate WriteIoPortByte; - public static SetPciMaxBusIndexDelegate SetPciMaxBusIndex; - public static FindPciDeviceByIdDelegate FindPciDeviceById; - public static ReadPciConfigDwordExDelegate ReadPciConfigDwordEx; - public static WritePciConfigDwordExDelegate WritePciConfigDwordEx; - public static RdtscTxDelegate RdtscTx; - public static RdtscDelegate Rdtsc; + public static readonly GetDllStatusDelegate GetDllStatus; + public static readonly IsCpuidDelegate IsCpuid; + public static readonly CpuidDelegate Cpuid; + public static readonly CpuidTxDelegate CpuidTx; + public static readonly RdmsrDelegate Rdmsr; + public static readonly RdmsrTxDelegate RdmsrTx; + public static readonly ReadIoPortByteDelegate ReadIoPortByte; + public static readonly WriteIoPortByteDelegate WriteIoPortByte; + public static readonly SetPciMaxBusIndexDelegate SetPciMaxBusIndex; + public static readonly FindPciDeviceByIdDelegate FindPciDeviceById; + public static readonly ReadPciConfigDwordExDelegate ReadPciConfigDwordEx; + public static readonly WritePciConfigDwordExDelegate WritePciConfigDwordEx; + public static readonly RdtscTxDelegate RdtscTx; + public static readonly RdtscDelegate Rdtsc; + + private static void GetDelegate(string entryPoint, out T newDelegate) where T : class @@ -150,18 +153,32 @@ namespace OpenHardwareMonitor.Hardware { try { if (InitializeOls != null && InitializeOls()) available = true; - } catch (DllNotFoundException) { } + } catch (DllNotFoundException) { } + + isaBusMutex = new Mutex(false, "Access_ISABUS.HTP.Method"); } public static bool IsAvailable { get { return available; } } + public static bool WaitIsaBusMutex() { + try { + return isaBusMutex.WaitOne(10); + } catch { return false; } + } + + public static void ReleaseIsaBusMutex() { + isaBusMutex.ReleaseMutex(); + } + private static Deinitializer deinitializer = new Deinitializer(); private class Deinitializer { ~Deinitializer() { if (available) DeinitializeOls(); + + isaBusMutex.Close(); } } }