nvapi_sys/gpu/
cooler.rs

1use status::NvAPI_Status;
2use handles::NvPhysicalGpuHandle;
3
4nvapi! {
5    pub type GPU_GetTachReadingFn = extern "C" fn(hPhysicalGPU: NvPhysicalGpuHandle, pValue: *mut u32) -> NvAPI_Status;
6
7    /// This API retrieves the fan speed tachometer reading for the specified physical GPU.
8    pub unsafe fn NvAPI_GPU_GetTachReading;
9}
10
11/// Undocumented API
12pub mod private {
13    use status::NvAPI_Status;
14    use handles::NvPhysicalGpuHandle;
15
16    pub const NVAPI_MIN_COOLER_LEVEL: usize = 0;
17    pub const NVAPI_MAX_COOLER_LEVEL: usize = 100;
18    pub const NVAPI_MAX_COOLER_LEVELS: usize = 24;
19    pub const NVAPI_MAX_COOLERS_PER_GPU: usize = 3;
20
21    nvenum! {
22        pub enum NV_COOLER_TYPE / CoolerType {
23            NVAPI_COOLER_TYPE_NONE / None = 0,
24            NVAPI_COOLER_TYPE_FAN / Fan = 1,
25            NVAPI_COOLER_TYPE_WATER / Water = 2,
26            NVAPI_COOLER_TYPE_LIQUID_NO2 / LiquidNO2 = 3,
27        }
28    }
29
30    nvenum_display! {
31        CoolerType => _
32    }
33
34    nvenum! {
35        pub enum NV_COOLER_CONTROLLER / CoolerController {
36            NVAPI_COOLER_CONTROLLER_NONE / None = 0,
37            NVAPI_COOLER_CONTROLLER_ADI / ADI = 1,
38            NVAPI_COOLER_CONTROLLER_INTERNAL / Internal = 2,
39        }
40    }
41
42    nvenum_display! {
43        CoolerController => _
44    }
45
46    nvenum! {
47        pub enum NV_COOLER_POLICY / CoolerPolicy {
48            NVAPI_COOLER_POLICY_NONE / None = 0,
49            /// Manual adjustment of cooler level. Gets applied right away independent of temperature or performance level.
50            NVAPI_COOLER_POLICY_MANUAL / Manual = 1,
51            /// GPU performance controls the cooler level.
52            NVAPI_COOLER_POLICY_PERF / Performance = 2,
53            /// Discrete thermal levels control the cooler level.
54            NVAPI_COOLER_POLICY_TEMPERATURE_DISCRETE / TemperatureDiscrete = 4,
55            /// Cooler level adjusted at continuous thermal levels.
56            NVAPI_COOLER_POLICY_TEMPERATURE_CONTINUOUS / TemperatureContinuous = 8,
57            /// Hybrid of performance and temperature levels.
58            NVAPI_COOLER_POLICY_HYBRID / Hybrid = 9, // are you sure this isn't just a bitmask?
59            /// Fan turns off at idle, default of MSI Gaming X
60            NVAPI_COOLER_POLICY_SILENT / Silent = 16,
61            /// Apparently a default of some GPUs
62            NVAPI_COOLER_POLICY_UNKNOWN_32 / Unknown32 = 32,
63        }
64    }
65
66    nvenum_display! {
67        CoolerPolicy => {
68            TemperatureDiscrete = "Discrete Thermal",
69            TemperatureContinuous = "Continuous Thermal",
70            Silent = "Silent",
71            _ = _,
72        }
73    }
74
75    nvenum! {
76        pub enum NV_COOLER_TARGET / CoolerTarget {
77            NVAPI_COOLER_TARGET_NONE / None = 0,
78            NVAPI_COOLER_TARGET_GPU / GPU = 1,
79            NVAPI_COOLER_TARGET_MEMORY / Memory = 2,
80            NVAPI_COOLER_TARGET_POWER_SUPPLY / PowerSupply = 4,
81            /// This cooler cools all of the components related to its target gpu.
82            NVAPI_COOLER_TARGET_ALL / All = 7,
83        }
84    }
85
86    nvenum_display! {
87        CoolerTarget => {
88            GPU = "Core",
89            PowerSupply = "VRM",
90            _ = _,
91        }
92    }
93
94    nvenum! {
95        pub enum NV_COOLER_CONTROL / CoolerControl {
96            NVAPI_COOLER_CONTROL_NONE / None = 0,
97            /// ON/OFF
98            NVAPI_COOLER_CONTROL_TOGGLE / Toggle = 1,
99            /// Suppports variable control.
100            NVAPI_COOLER_CONTROL_VARIABLE / Variable = 2,
101        }
102    }
103
104    nvenum_display! {
105        CoolerControl => _
106    }
107
108    nvenum! {
109        pub enum NV_COOLER_ACTIVITY_LEVEL / CoolerActivityLevel {
110            NVAPI_INACTIVE / Inactive = 0,
111            NVAPI_ACTIVE / Active = 1,
112        }
113    }
114
115    impl CoolerActivityLevel {
116        pub fn get(&self) -> bool {
117            match *self {
118                CoolerActivityLevel::Active => true,
119                CoolerActivityLevel::Inactive => false,
120            }
121        }
122    }
123
124    nvstruct! {
125        pub struct NV_GPU_COOLER_SETTINGS_COOLER {
126            /// type of cooler - FAN, WATER, LIQUID_NO2...
127            pub type_: NV_COOLER_TYPE,
128            /// internal, ADI...
129            pub controller: NV_COOLER_CONTROLLER,
130            /// the min default value % of the cooler
131            pub defaultMinLevel: u32,
132            /// the max default value % of the cooler
133            pub defaultMaxLevel: u32,
134            /// the current allowed min value % of the cooler
135            pub currentMinLevel: u32,
136            /// the current allowed max value % of the cooler
137            pub currentMaxLevel: u32,
138            /// the current value % of the cooler
139            pub currentLevel: u32,
140            /// cooler control policy - auto-perf, auto-thermal, manual, hybrid...
141            pub defaultPolicy: NV_COOLER_POLICY,
142            /// cooler control policy - auto-perf, auto-thermal, manual, hybrid...
143            pub currentPolicy: NV_COOLER_POLICY,
144            /// cooling target - GPU, memory, chipset, powersupply, canoas...
145            pub target: NV_COOLER_TARGET,
146            /// toggle or variable
147            pub controlType: NV_COOLER_CONTROL,
148            /// is the cooler active - fan spinning...
149            pub active: NV_COOLER_ACTIVITY_LEVEL,
150        }
151    }
152
153    nvstruct! {
154        pub struct NV_GPU_COOLER_SETTINGS_V1 {
155            pub version: u32,
156            pub count: u32,
157            pub cooler: [NV_GPU_COOLER_SETTINGS_COOLER; NVAPI_MAX_COOLERS_PER_GPU],
158        }
159    }
160
161    const NV_GPU_COOLER_SETTINGS_COOLER_SIZE: usize = 4 * 12;
162
163    nvversion! { NV_GPU_COOLER_SETTINGS_VER_1(NV_GPU_COOLER_SETTINGS_V1 = 4 * 2 + NV_GPU_COOLER_SETTINGS_COOLER_SIZE * NVAPI_MAX_COOLERS_PER_GPU, 1) }
164    nvversion! { NV_GPU_COOLER_SETTINGS_VER = NV_GPU_COOLER_SETTINGS_VER_1 }
165
166    pub type NV_GPU_COOLER_SETTINGS = NV_GPU_COOLER_SETTINGS_V1;
167
168    nvapi! {
169        pub type GPU_GetCoolerSettingsFn = extern "C" fn(hPhysicalGPU: NvPhysicalGpuHandle, coolerIndex: u32, pCoolerInfo: *mut NV_GPU_COOLER_SETTINGS) -> NvAPI_Status;
170
171        /// Undocumented function.
172        /// Retrieves the cooler information of all coolers or a specific cooler associated with the selected GPU.
173        ///
174        /// Coolers are indexed 0 to NVAPI_MAX_COOLERS_PER_GPU-1.
175        /// To retrieve specific cooler info set the coolerIndex to the appropriate cooler index.
176        /// To retrieve info for all cooler set coolerIndex to NVAPI_COOLER_TARGET_ALL.
177        pub unsafe fn NvAPI_GPU_GetCoolerSettings;
178    }
179
180    nvstruct! {
181        pub struct NV_GPU_SETCOOLER_LEVEL_COOLER {
182            /// the new value % of the cooler
183            pub currentLevel: u32,
184            /// the new cooler control policy - auto-perf, auto-thermal, manual, hybrid...
185            pub currentPolicy: NV_COOLER_POLICY,
186        }
187    }
188
189    nvstruct! {
190        pub struct NV_GPU_SETCOOLER_LEVEL_V1 {
191            pub version: u32,
192            pub cooler: [NV_GPU_SETCOOLER_LEVEL_COOLER; NVAPI_MAX_COOLERS_PER_GPU],
193        }
194    }
195
196    const NV_GPU_SETCOOLER_LEVEL_COOLER_SIZE: usize = 4 * 2;
197
198    nvversion! { NV_GPU_SETCOOLER_LEVEL_VER_1(NV_GPU_SETCOOLER_LEVEL_V1 = 4 + NV_GPU_SETCOOLER_LEVEL_COOLER_SIZE * NVAPI_MAX_COOLERS_PER_GPU, 1) }
199    nvversion! { NV_GPU_SETCOOLER_LEVEL_VER = NV_GPU_SETCOOLER_LEVEL_VER_1 }
200
201    pub type NV_GPU_SETCOOLER_LEVEL = NV_GPU_SETCOOLER_LEVEL_V1;
202
203    nvapi! {
204        pub type GPU_SetCoolerLevelsFn = extern "C" fn(hPhysicalGPU: NvPhysicalGpuHandle, coolerIndex: u32, pCoolerLevels: *const NV_GPU_SETCOOLER_LEVEL) -> NvAPI_Status;
205
206        /// Undocumented function.
207        /// Set the cooler levels for all coolers or a specific cooler associated with the selected GPU.
208        ///
209        /// Coolers are indexed 0 to NVAPI_MAX_COOLERS_PER_GPU-1. Every cooler level with non-zero currentpolicy gets applied.
210        ///
211        /// The new level should be in the range of minlevel and maxlevel retrieved from GetCoolerSettings API or between
212        /// and NVAPI_MIN_COOLER_LEVEL to MAX_COOLER_LEVEL.
213        /// To set level for a specific cooler set the coolerIndex to the appropriate cooler index.
214        /// To set level for all coolers set coolerIndex to NVAPI_COOLER_TARGET_ALL.
215        ///
216        /// NOTE: To lock the fan speed independent of the temperature or performance changes set the cooler currentPolicy to
217        /// NVAPI_COOLER_POLICY_MANUAL else set it to the current policy retrieved from the GetCoolerSettings API.
218        pub unsafe fn NvAPI_GPU_SetCoolerLevels;
219    }
220
221    nvapi! {
222        pub type GPU_RestoreCoolerSettingsFn = extern "C" fn(hPhysicalGPU: NvPhysicalGpuHandle, coolerIndex: *const u32, coolerCount: u32) -> NvAPI_Status;
223
224        /// Undocumented function.
225        /// Restore the modified cooler settings to NVIDIA defaults.
226        ///
227        /// pCoolerIndex: Array containing absolute cooler indexes to restore. Pass NULL restore all coolers.
228        ///
229        /// coolerCount: Number of coolers to restore.
230        pub unsafe fn NvAPI_GPU_RestoreCoolerSettings;
231    }
232
233    nvstruct! {
234        pub struct NV_GPU_COOLER_POLICY_LEVEL {
235            /// level indicator for a policy
236            pub levelId: u32,
237            /// new cooler level for the selected policy level indicator.
238            pub currentLevel: u32,
239            /// default cooler level for the selected policy level indicator.
240            pub defaultLevel: u32,
241        }
242    }
243
244    const NV_GPU_COOLER_POLICY_LEVEL_SIZE: usize = 4 * 3;
245
246    nvstruct! {
247        pub struct NV_GPU_COOLER_POLICY_TABLE_V1 {
248            /// structure version
249            pub version: u32,
250            /// selected policy to update the cooler levels for, example NVAPI_COOLER_POLICY_PERF
251            pub policy: NV_COOLER_POLICY,
252            pub policyCoolerLevel: [NV_GPU_COOLER_POLICY_LEVEL; NVAPI_MAX_COOLER_LEVELS],
253        }
254    }
255
256    nvversion! { NV_GPU_COOLER_POLICY_TABLE_VER_1(NV_GPU_COOLER_POLICY_TABLE_V1 = 4 * 2 + NV_GPU_COOLER_POLICY_LEVEL_SIZE * NVAPI_MAX_COOLER_LEVELS, 1) }
257    nvversion! { NV_GPU_COOLER_POLICY_TABLE_VER = NV_GPU_COOLER_POLICY_TABLE_VER_1 }
258
259    pub type NV_GPU_COOLER_POLICY_TABLE = NV_GPU_COOLER_POLICY_TABLE_V1;
260
261    nvapi! {
262        pub type GPU_GetCoolerPolicyTableFn = extern "C" fn(hPhysicalGPU: NvPhysicalGpuHandle, coolerIndex: u32, pCoolerTable: *mut NV_GPU_COOLER_POLICY_TABLE, count: *mut u32) -> NvAPI_Status;
263
264        /// Undocumented function.
265        /// Retrieves the table of cooler and policy levels for the selected policy. Supported only for NVAPI_COOLER_POLICY_PERF.
266        pub unsafe fn NvAPI_GPU_GetCoolerPolicyTable;
267    }
268
269    nvapi! {
270        pub type GPU_SetCoolerPolicyTableFn = extern "C" fn(hPhysicalGPU: NvPhysicalGpuHandle, coolerIndex: u32, pCoolerTable: *const NV_GPU_COOLER_POLICY_TABLE, count: u32) -> NvAPI_Status;
271
272        /// Undocumented function.
273        /// Restore the modified cooler settings to NVIDIA defaults. Supported only for NVAPI_COOLER_POLICY_PERF.
274        ///
275        /// pCoolerTable: Updated table of policy levels and associated cooler levels. Every non-zero policy level gets updated.
276        ///
277        /// count: Number of valid levels in the policy table.
278        pub unsafe fn NvAPI_GPU_SetCoolerPolicyTable;
279    }
280
281    nvapi! {
282        pub type GPU_RestoreCoolerPolicyTableFn = extern "C" fn(hPhysicalGPU: NvPhysicalGpuHandle, coolerIndex: *const u32, coolerCount: u32, policy: NV_COOLER_POLICY) -> NvAPI_Status;
283
284        /// Undocumented function.
285        /// Restores the perf table policy levels to the defaults.
286        ///
287        /// pCoolerIndex: Array containing absolute cooler indexes to restore. Pass NULL restore all coolers.
288        ///
289        /// coolerCount: Number of coolers to restore.
290        pub unsafe fn NvAPI_GPU_RestoreCoolerPolicyTable;
291    }
292}