Hardware/Nvidia/NVAPI.cs
changeset 309 65a1ae21325d
parent 195 0ee888c485d5
child 334 013e148e8f12
     1.1 --- a/Hardware/Nvidia/NVAPI.cs	Thu Jul 07 20:41:09 2011 +0000
     1.2 +++ b/Hardware/Nvidia/NVAPI.cs	Thu Jul 07 21:53:09 2011 +0000
     1.3 @@ -16,10 +16,11 @@
     1.4  
     1.5    The Initial Developer of the Original Code is 
     1.6    Michael Möller <m.moeller@gmx.ch>.
     1.7 -  Portions created by the Initial Developer are Copyright (C) 2009-2010
     1.8 +  Portions created by the Initial Developer are Copyright (C) 2009-2011
     1.9    the Initial Developer. All Rights Reserved.
    1.10  
    1.11    Contributor(s):
    1.12 +  Christian Vallières
    1.13  
    1.14    Alternatively, the contents of this file may be used under the terms of
    1.15    either the GNU General Public License Version 2 or later (the "GPL"), or
    1.16 @@ -97,17 +98,17 @@
    1.17  
    1.18    internal enum NvThermalController {
    1.19      NONE = 0,
    1.20 -    GPU_INTERNAL,  
    1.21 +    GPU_INTERNAL,
    1.22      ADM1032,
    1.23 -    MAX6649,       
    1.24 -    MAX1617,      
    1.25 -    LM99,      
    1.26 -    LM89,         
    1.27 -    LM64,         
    1.28 +    MAX6649,
    1.29 +    MAX1617,
    1.30 +    LM99,
    1.31 +    LM89,
    1.32 +    LM64,
    1.33      ADT7473,
    1.34      SBMAX6649,
    1.35 -    VBIOSEVT,  
    1.36 -    OS,    
    1.37 +    VBIOSEVT,
    1.38 +    OS,
    1.39      UNKNOWN = -1,
    1.40    }
    1.41  
    1.42 @@ -127,14 +128,14 @@
    1.43      public uint DefaultMinTemp;
    1.44      public uint DefaultMaxTemp;
    1.45      public uint CurrentTemp;
    1.46 -    public NvThermalTarget Target;     
    1.47 +    public NvThermalTarget Target;
    1.48    }
    1.49  
    1.50    [StructLayout(LayoutKind.Sequential, Pack = 8)]
    1.51    internal struct NvGPUThermalSettings {
    1.52      public uint Version;
    1.53      public uint Count;
    1.54 -    [MarshalAs(UnmanagedType.ByValArray, 
    1.55 +    [MarshalAs(UnmanagedType.ByValArray,
    1.56        SizeConst = NVAPI.MAX_THERMAL_SENSORS_PER_GPU)]
    1.57      public NvSensor[] Sensor;
    1.58    }
    1.59 @@ -202,9 +203,22 @@
    1.60    }
    1.61  
    1.62    [StructLayout(LayoutKind.Sequential, Pack = 8)]
    1.63 +  internal struct NvLevel {
    1.64 +    public int Level;
    1.65 +    public int Policy;
    1.66 +  }
    1.67 +
    1.68 +  [StructLayout(LayoutKind.Sequential, Pack = 8)]
    1.69 +  internal struct NvGPUCoolerLevels {
    1.70 +    public uint Version;
    1.71 +    [MarshalAs(UnmanagedType.ByValArray, SizeConst = NVAPI.MAX_COOLER_PER_GPU)]
    1.72 +    public NvLevel[] Levels;
    1.73 +  }
    1.74 +
    1.75 +  [StructLayout(LayoutKind.Sequential, Pack = 8)]
    1.76    internal struct NvMemoryInfo {
    1.77      public uint Version;
    1.78 -    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 
    1.79 +    [MarshalAs(UnmanagedType.ByValArray, SizeConst =
    1.80        NVAPI.MAX_MEMORY_VALUES_PER_GPU)]
    1.81      public uint[] Values;
    1.82    }
    1.83 @@ -225,7 +239,7 @@
    1.84      public const int MAX_PHYSICAL_GPUS = 64;
    1.85      public const int SHORT_STRING_MAX = 64;
    1.86  
    1.87 -    public const int MAX_THERMAL_SENSORS_PER_GPU = 3;    
    1.88 +    public const int MAX_THERMAL_SENSORS_PER_GPU = 3;
    1.89      public const int MAX_CLOCKS_PER_GPU = 0x120;
    1.90      public const int MAX_PSTATES_PER_GPU = 8;
    1.91      public const int MAX_USAGES_PER_GPU = 33;
    1.92 @@ -242,23 +256,25 @@
    1.93        Marshal.SizeOf(typeof(NvUsages)) | 0x10000;
    1.94      public static readonly uint GPU_COOLER_SETTINGS_VER = (uint)
    1.95        Marshal.SizeOf(typeof(NvGPUCoolerSettings)) | 0x20000;
    1.96 -    public static readonly uint GPU_MEMORY_INFO_VER = (uint) 
    1.97 +    public static readonly uint GPU_MEMORY_INFO_VER = (uint)
    1.98        Marshal.SizeOf(typeof(NvMemoryInfo)) | 0x20000;
    1.99      public static readonly uint DISPLAY_DRIVER_VERSION_VER = (uint)
   1.100        Marshal.SizeOf(typeof(NvDisplayDriverVersion)) | 0x10000;
   1.101 -      
   1.102 +    public static readonly uint GPU_COOLER_LEVELS_VER = (uint)
   1.103 +      Marshal.SizeOf(typeof(NvGPUCoolerLevels)) | 0x10000;
   1.104 +
   1.105      private delegate IntPtr nvapi_QueryInterfaceDelegate(uint id);
   1.106      private delegate NvStatus NvAPI_InitializeDelegate();
   1.107      private delegate NvStatus NvAPI_GPU_GetFullNameDelegate(
   1.108        NvPhysicalGpuHandle gpuHandle, StringBuilder name);
   1.109  
   1.110      public delegate NvStatus NvAPI_GPU_GetThermalSettingsDelegate(
   1.111 -      NvPhysicalGpuHandle gpuHandle, int sensorIndex, 
   1.112 +      NvPhysicalGpuHandle gpuHandle, int sensorIndex,
   1.113        ref NvGPUThermalSettings nvGPUThermalSettings);
   1.114      public delegate NvStatus NvAPI_EnumNvidiaDisplayHandleDelegate(int thisEnum,
   1.115        ref NvDisplayHandle displayHandle);
   1.116      public delegate NvStatus NvAPI_GetPhysicalGPUsFromDisplayDelegate(
   1.117 -      NvDisplayHandle displayHandle, [Out] NvPhysicalGpuHandle[] gpuHandles, 
   1.118 +      NvDisplayHandle displayHandle, [Out] NvPhysicalGpuHandle[] gpuHandles,
   1.119        out uint gpuCount);
   1.120      public delegate NvStatus NvAPI_EnumPhysicalGPUsDelegate(
   1.121        [Out] NvPhysicalGpuHandle[] gpuHandles, out int gpuCount);
   1.122 @@ -273,6 +289,9 @@
   1.123      public delegate NvStatus NvAPI_GPU_GetCoolerSettingsDelegate(
   1.124        NvPhysicalGpuHandle gpuHandle, int coolerIndex,
   1.125        ref NvGPUCoolerSettings nvGPUCoolerSettings);
   1.126 +    public delegate NvStatus NvAPI_GPU_SetCoolerLevelsDelegate(
   1.127 +      NvPhysicalGpuHandle gpuHandle, int coolerIndex,
   1.128 +      ref NvGPUCoolerLevels NvGPUCoolerLevels);
   1.129      public delegate NvStatus NvAPI_GPU_GetMemoryInfoDelegate(
   1.130        NvDisplayHandle displayHandle, ref NvMemoryInfo nvMemoryInfo);
   1.131      public delegate NvStatus NvAPI_GetDisplayDriverVersionDelegate(
   1.132 @@ -284,12 +303,12 @@
   1.133      private static readonly bool available;
   1.134      private static readonly nvapi_QueryInterfaceDelegate nvapi_QueryInterface;
   1.135      private static readonly NvAPI_InitializeDelegate NvAPI_Initialize;
   1.136 -    private static readonly NvAPI_GPU_GetFullNameDelegate 
   1.137 +    private static readonly NvAPI_GPU_GetFullNameDelegate
   1.138        _NvAPI_GPU_GetFullName;
   1.139      private static readonly NvAPI_GetInterfaceVersionStringDelegate
   1.140        _NvAPI_GetInterfaceVersionString;
   1.141  
   1.142 -    public static readonly NvAPI_GPU_GetThermalSettingsDelegate 
   1.143 +    public static readonly NvAPI_GPU_GetThermalSettingsDelegate
   1.144        NvAPI_GPU_GetThermalSettings;
   1.145      public static readonly NvAPI_EnumNvidiaDisplayHandleDelegate
   1.146        NvAPI_EnumNvidiaDisplayHandle;
   1.147 @@ -307,6 +326,8 @@
   1.148        NvAPI_GPU_GetUsages;
   1.149      public static readonly NvAPI_GPU_GetCoolerSettingsDelegate
   1.150        NvAPI_GPU_GetCoolerSettings;
   1.151 +    public static readonly NvAPI_GPU_SetCoolerLevelsDelegate
   1.152 +      NvAPI_GPU_SetCoolerLevels;
   1.153      public static readonly NvAPI_GPU_GetMemoryInfoDelegate
   1.154        NvAPI_GPU_GetMemoryInfo;
   1.155      public static readonly NvAPI_GetDisplayDriverVersionDelegate
   1.156 @@ -345,9 +366,8 @@
   1.157        }
   1.158      }
   1.159  
   1.160 -    private static void GetDelegate<T>(uint id, out T newDelegate) 
   1.161 -      where T : class 
   1.162 -    {
   1.163 +    private static void GetDelegate<T>(uint id, out T newDelegate)
   1.164 +      where T : class {
   1.165        IntPtr ptr = nvapi_QueryInterface(id);
   1.166        if (ptr != IntPtr.Zero) {
   1.167          newDelegate =
   1.168 @@ -357,7 +377,7 @@
   1.169        }
   1.170      }
   1.171  
   1.172 -    static NVAPI() { 
   1.173 +    static NVAPI() {
   1.174        DllImportAttribute attribute = new DllImportAttribute(GetDllName());
   1.175        attribute.CallingConvention = CallingConvention.Cdecl;
   1.176        attribute.PreserveSig = true;
   1.177 @@ -382,6 +402,7 @@
   1.178          GetDelegate(0x60DED2ED, out NvAPI_GPU_GetPStates);
   1.179          GetDelegate(0x189A1FDF, out NvAPI_GPU_GetUsages);
   1.180          GetDelegate(0xDA141340, out NvAPI_GPU_GetCoolerSettings);
   1.181 +        GetDelegate(0x891FA0AE, out NvAPI_GPU_SetCoolerLevels);
   1.182          GetDelegate(0x774AA982, out NvAPI_GPU_GetMemoryInfo);
   1.183          GetDelegate(0xF951A4D1, out NvAPI_GetDisplayDriverVersion);
   1.184          GetDelegate(0x01053FA5, out _NvAPI_GetInterfaceVersionString);