Hardware/CPU/AMD10CPU.cs
changeset 196 5e9a8595296c
parent 195 0ee888c485d5
child 197 fb66f749b7ff
     1.1 --- a/Hardware/CPU/AMD10CPU.cs	Tue Sep 21 20:32:36 2010 +0000
     1.2 +++ b/Hardware/CPU/AMD10CPU.cs	Wed Sep 22 19:12:12 2010 +0000
     1.3 @@ -35,22 +35,25 @@
     1.4   
     1.5  */
     1.6  
     1.7 +using System;
     1.8 +using System.Globalization;
     1.9 +using System.Text;
    1.10 +
    1.11  namespace OpenHardwareMonitor.Hardware.CPU {
    1.12  
    1.13 -  internal sealed class AMD10CPU : GenericCPU {
    1.14 -
    1.15 -    private readonly uint pciAddress;
    1.16 +  internal sealed class AMD10CPU : AMDCPU {
    1.17  
    1.18      private readonly Sensor coreTemperature;
    1.19  
    1.20 -    private const ushort PCI_AMD_VENDOR_ID = 0x1022;
    1.21 -    private const ushort PCI_AMD_10H_MISCELLANEOUS_DEVICE_ID = 0x1203;
    1.22 -    private const ushort PCI_AMD_11H_MISCELLANEOUS_DEVICE_ID = 0x1303;
    1.23 -    private const uint REPORTED_TEMPERATURE_CONTROL_REGISTER = 0xA4;
    1.24 +    private const byte MISCELLANEOUS_CONTROL_FUNCTION = 3;
    1.25 +    private const ushort MISCELLANEOUS_CONTROL_DEVICE_ID = 0x1203;
    1.26 +    private const byte REPORTED_TEMPERATURE_CONTROL_REGISTER = 0xA4;
    1.27 +    
    1.28 +    private readonly uint miscellaneousControlAddress;
    1.29  
    1.30      public AMD10CPU(int processorIndex, CPUID[][] cpuid, ISettings settings)
    1.31        : base(processorIndex, cpuid, settings) 
    1.32 -    {      
    1.33 +    {            
    1.34        // AMD family 10h processors support only one temperature sensor
    1.35        coreTemperature = new Sensor(
    1.36          "Core" + (coreCount > 1 ? " #1 - #" + coreCount : ""), 0,
    1.37 @@ -58,11 +61,9 @@
    1.38              new ParameterDescription("Offset [°C]", "Temperature offset.", 0)
    1.39            }, settings);
    1.40  
    1.41 -      pciAddress = WinRing0.FindPciDeviceById(PCI_AMD_VENDOR_ID,
    1.42 -        PCI_AMD_10H_MISCELLANEOUS_DEVICE_ID, (byte)processorIndex);
    1.43 -      if (pciAddress == 0xFFFFFFFF) 
    1.44 -        pciAddress = WinRing0.FindPciDeviceById(PCI_AMD_VENDOR_ID,
    1.45 -          PCI_AMD_11H_MISCELLANEOUS_DEVICE_ID, (byte)processorIndex);
    1.46 +      // get the pci address for the Miscellaneous Control registers 
    1.47 +      miscellaneousControlAddress = GetPciAddress(
    1.48 +        MISCELLANEOUS_CONTROL_FUNCTION, MISCELLANEOUS_CONTROL_DEVICE_ID);
    1.49  
    1.50        Update();                   
    1.51      }
    1.52 @@ -71,12 +72,24 @@
    1.53        return new uint[] { };
    1.54      }
    1.55  
    1.56 +    public override string GetReport() {
    1.57 +      StringBuilder r = new StringBuilder();
    1.58 +      r.Append(base.GetReport());
    1.59 +
    1.60 +      r.Append("Miscellaneous Control Address: ");
    1.61 +      r.AppendLine((miscellaneousControlAddress).ToString("X",
    1.62 +        CultureInfo.InvariantCulture));
    1.63 +      r.AppendLine();
    1.64 +
    1.65 +      return r.ToString();
    1.66 +    }
    1.67 +
    1.68      public override void Update() {
    1.69        base.Update();
    1.70  
    1.71 -      if (pciAddress != 0xFFFFFFFF) {
    1.72 +      if (miscellaneousControlAddress != WinRing0.InvalidPciAddress) {
    1.73          uint value;
    1.74 -        if (WinRing0.ReadPciConfigDwordEx(pciAddress,
    1.75 +        if (WinRing0.ReadPciConfigDwordEx(miscellaneousControlAddress,
    1.76            REPORTED_TEMPERATURE_CONTROL_REGISTER, out value)) {
    1.77            coreTemperature.Value = ((value >> 21) & 0x7FF) / 8.0f +
    1.78              coreTemperature.Parameters[0].Value;