first commit

This commit is contained in:
2025-04-07 07:44:27 -07:00
commit d6cde0c05e
512 changed files with 142392 additions and 0 deletions

View File

@@ -0,0 +1,150 @@
// 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.
// All Rights Reserved.
using System;
using System.Runtime.InteropServices;
// ReSharper disable InconsistentNaming
namespace LibreHardwareMonitor.Interop;
internal class AdvApi32
{
private const string DllName = "advapi32.dll";
[DllImport(DllName, SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern IntPtr OpenSCManager(string lpMachineName, string lpDatabaseName, SC_MANAGER_ACCESS_MASK dwDesiredAccess);
[DllImport(DllName, CallingConvention = CallingConvention.Winapi)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool CloseServiceHandle(IntPtr hSCObject);
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern IntPtr CreateService
(
IntPtr hSCManager,
string lpServiceName,
string lpDisplayName,
SERVICE_ACCESS_MASK dwDesiredAccess,
SERVICE_TYPE dwServiceType,
SERVICE_START dwStartType,
SERVICE_ERROR dwErrorControl,
string lpBinaryPathName,
string lpLoadOrderGroup,
string lpdwTagId,
string lpDependencies,
string lpServiceStartName,
string lpPassword);
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, SERVICE_ACCESS_MASK dwDesiredAccess);
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DeleteService(IntPtr hService);
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool StartService(IntPtr hService, uint dwNumServiceArgs, string[] lpServiceArgVectors);
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool ControlService(IntPtr hService, SERVICE_CONTROL dwControl, ref SERVICE_STATUS lpServiceStatus);
[Flags]
internal enum SC_MANAGER_ACCESS_MASK : uint
{
SC_MANAGER_CONNECT = 0x00001,
SC_MANAGER_CREATE_SERVICE = 0x00002,
SC_MANAGER_ENUMERATE_SERVICE = 0x00004,
SC_MANAGER_LOCK = 0x00008,
SC_MANAGER_QUERY_LOCK_STATUS = 0x00010,
SC_MANAGER_MODIFY_BOOT_CONFIG = 0x00020,
SC_MANAGER_ALL_ACCESS = 0xF003F
}
internal enum SERVICE_ACCESS_MASK : uint
{
SERVICE_QUERY_CONFIG = 0x00001,
SERVICE_CHANGE_CONFIG = 0x00002,
SERVICE_QUERY_STATUS = 0x00004,
SERVICE_ENUMERATE_DEPENDENTS = 0x00008,
SERVICE_START = 0x00010,
SERVICE_STOP = 0x00020,
SERVICE_PAUSE_CONTINUE = 0x00040,
SERVICE_INTERROGATE = 0x00080,
SERVICE_USER_DEFINED_CONTROL = 0x00100,
SERVICE_ALL_ACCESS = 0xF01FF
}
internal enum SERVICE_TYPE : uint
{
SERVICE_DRIVER = 0x0000000B,
SERVICE_WIN32 = 0x00000030,
SERVICE_ADAPTER = 0x00000004,
SERVICE_FILE_SYSTEM_DRIVER = 0x00000002,
SERVICE_KERNEL_DRIVER = 0x00000001,
SERVICE_RECOGNIZER_DRIVER = 0x00000008,
SERVICE_WIN32_OWN_PROCESS = 0x00000010,
SERVICE_WIN32_SHARE_PROCESS = 0x00000020,
SERVICE_USER_OWN_PROCESS = 0x00000050,
SERVICE_USER_SHARE_PROCESS = 0x00000060,
SERVICE_INTERACTIVE_PROCESS = 0x00000100
}
internal enum SERVICE_START : uint
{
SERVICE_BOOT_START = 0,
SERVICE_SYSTEM_START = 1,
SERVICE_AUTO_START = 2,
SERVICE_DEMAND_START = 3,
SERVICE_DISABLED = 4
}
internal enum SERVICE_ERROR : uint
{
SERVICE_ERROR_IGNORE = 0,
SERVICE_ERROR_NORMAL = 1,
SERVICE_ERROR_SEVERE = 2,
SERVICE_ERROR_CRITICAL = 3
}
internal enum SERVICE_CONTROL : uint
{
SERVICE_CONTROL_STOP = 1,
SERVICE_CONTROL_PAUSE = 2,
SERVICE_CONTROL_CONTINUE = 3,
SERVICE_CONTROL_INTERROGATE = 4,
SERVICE_CONTROL_SHUTDOWN = 5,
SERVICE_CONTROL_PARAMCHANGE = 6,
SERVICE_CONTROL_NETBINDADD = 7,
SERVICE_CONTROL_NETBINDREMOVE = 8,
SERVICE_CONTROL_NETBINDENABLE = 9,
SERVICE_CONTROL_NETBINDDISABLE = 10,
SERVICE_CONTROL_DEVICEEVENT = 11,
SERVICE_CONTROL_HARDWAREPROFILECHANGE = 12,
SERVICE_CONTROL_POWEREVENT = 13,
SERVICE_CONTROL_SESSIONCHANGE = 14
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct SERVICE_STATUS
{
public uint dwServiceType;
public uint dwCurrentState;
public uint dwControlsAccepted;
public uint dwWin32ExitCode;
public uint dwServiceSpecificExitCode;
public uint dwCheckPoint;
public uint dwWaitHint;
}
}

View File

@@ -0,0 +1,713 @@
// 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.
// All Rights Reserved.
using System;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
// ReSharper disable InconsistentNaming
namespace LibreHardwareMonitor.Interop;
internal static class AtiAdlxx
{
public const int ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED = 1;
public const int ADL_DL_FANCTRL_SPEED_TYPE_PERCENT = 1;
public const int ADL_DL_FANCTRL_SPEED_TYPE_RPM = 2;
public const int ADL_DL_FANCTRL_SUPPORTS_PERCENT_READ = 1;
public const int ADL_DL_FANCTRL_SUPPORTS_PERCENT_WRITE = 2;
public const int ADL_DL_FANCTRL_SUPPORTS_RPM_READ = 4;
public const int ADL_DL_FANCTRL_SUPPORTS_RPM_WRITE = 8;
public const int ADL_DRIVER_OK = 0;
public const int ADL_FALSE = 0;
public const int ADL_MAX_ADAPTERS = 40;
public const int ADL_MAX_DEVICENAME = 32;
public const int ADL_MAX_DISPLAYS = 40;
public const int ADL_MAX_GLSYNC_PORT_LEDS = 8;
public const int ADL_MAX_GLSYNC_PORTS = 8;
public const int ADL_MAX_NUM_DISPLAYMODES = 1024;
public const int ADL_MAX_PATH = 256;
public const int ADL_TRUE = 1;
public const int ATI_VENDOR_ID = 0x1002;
internal const int ADL_PMLOG_MAX_SENSORS = 256;
internal const string DllName = "atiadlxx.dll";
public static Context Context_Alloc = Marshal.AllocHGlobal;
// create a Main_Memory_Alloc delegate and keep it alive
public static ADL_Main_Memory_AllocDelegate Main_Memory_Alloc = Marshal.AllocHGlobal;
public delegate IntPtr ADL_Main_Memory_AllocDelegate(int size);
public delegate IntPtr Context(int size);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Overdrive5_ODParameters_Get(IntPtr context, int adapterIndex, out ADLODParameters parameters);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Overdrive5_CurrentActivity_Get(IntPtr context, int iAdapterIndex, ref ADLPMActivity activity);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Overdrive5_Temperature_Get(IntPtr context, int adapterIndex, int thermalControllerIndex, ref ADLTemperature temperature);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_OverdriveN_Temperature_Get(IntPtr context, int adapterIndex, ADLODNTemperatureType iTemperatureType, ref int temp);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Overdrive5_FanSpeed_Get(IntPtr context, int adapterIndex, int thermalControllerIndex, ref ADLFanSpeedValue fanSpeedValue);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Overdrive5_FanSpeedInfo_Get(IntPtr context, int adapterIndex, int thermalControllerIndex, ref ADLFanSpeedInfo fanSpeedInfo);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Overdrive5_FanSpeedToDefault_Set(IntPtr context, int adapterIndex, int thermalControllerIndex);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Overdrive5_FanSpeed_Set(IntPtr context, int adapterIndex, int thermalControllerIndex, ref ADLFanSpeedValue fanSpeedValue);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_OverdriveN_PerformanceStatus_Get(IntPtr context, int adapterIndex, out ADLODNPerformanceStatus performanceStatus);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Overdrive_Caps(IntPtr context, int adapterIndex, ref int supported, ref int enabled, ref int version);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Overdrive6_Capabilities_Get(IntPtr context, int adapterIndex, ref ADLOD6Capabilities lpODCapabilities);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Overdrive6_CurrentPower_Get(IntPtr context, int adapterIndex, ADLODNCurrentPowerType powerType, ref int currentValue);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Main_Control_Create(ADL_Main_Memory_AllocDelegate callback, int connectedAdapters, ref IntPtr context);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Main_Control_Destroy(IntPtr context);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_New_QueryPMLogData_Get(IntPtr context, int adapterIndex, ref ADLPMLogDataOutput aDLPMLogDataOutput);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_FrameMetrics_Caps(IntPtr context, int adapterIndex, ref int supported);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_FrameMetrics_Get(IntPtr context, int adapterIndex, int displayIndex, ref float fps);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_FrameMetrics_Start(IntPtr context, int adapterIndex, int displayIndex);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_FrameMetrics_Stop(IntPtr context, int adapterIndex, int displayIndex);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_PMLog_Support_Get(IntPtr context, int adapterIndex,
ref ADLPMLogSupportInfo pPMLogSupportInfo);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_PMLog_Start(IntPtr context, int adapterIndex,
ref ADLPMLogStartInput pPMLogStartInput,
ref ADLPMLogStartOutput pPMLogStartOutput,
uint device);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_PMLog_Stop(IntPtr context, int adapterIndex, uint device);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Device_PMLog_Device_Create(IntPtr context, int adapterIndex, ref uint device);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Device_PMLog_Device_Destroy(IntPtr context, uint device);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_GcnAsicInfo_Get(IntPtr context, int adapterIndex, ref ADLGcnInfo gcnInfo);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_NumberOfAdapters_Get(IntPtr context, ref int numAdapters);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_AdapterInfo_Get(IntPtr context, IntPtr adapterInfo, int size);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_ID_Get(IntPtr context, int adapterIndex, out int adapterId);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_Active_Get(IntPtr context, int adapterIndex, out int status);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_DedicatedVRAMUsage_Get(IntPtr context, int adapterIndex, out int iVRAMUsageInMB);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern ADLStatus ADL2_Adapter_MemoryInfoX4_Get(IntPtr context, int adapterIndex, out ADLMemoryInfoX4 memoryInfo);
public static bool ADL_Method_Exists(string ADL_Method)
{
IntPtr module = Kernel32.LoadLibrary(DllName);
if (module != IntPtr.Zero)
{
bool result = Kernel32.GetProcAddress(module, ADL_Method) != IntPtr.Zero;
Kernel32.FreeLibrary(module);
return result;
}
return false;
}
public static ADLStatus ADL2_Adapter_AdapterInfo_Get(ref IntPtr context, ADLAdapterInfo[] info)
{
int elementSize = Marshal.SizeOf(typeof(ADLAdapterInfo));
int size = info.Length * elementSize;
IntPtr ptr = Marshal.AllocHGlobal(size);
ADLStatus result = ADL2_Adapter_AdapterInfo_Get(context, ptr, size);
for (int i = 0; i < info.Length; i++)
info[i] = (ADLAdapterInfo)Marshal.PtrToStructure((IntPtr)((long)ptr + (i * elementSize)), typeof(ADLAdapterInfo));
Marshal.FreeHGlobal(ptr);
// the ADLAdapterInfo.VendorID field reported by ADL is wrong on
// Windows systems (parse error), so we fix this here
for (int i = 0; i < info.Length; i++)
{
// try Windows UDID format
Match m = Regex.Match(info[i].UDID, "PCI_VEN_([A-Fa-f0-9]{1,4})&.*");
if (m.Success && m.Groups.Count == 2)
{
info[i].VendorID = Convert.ToInt32(m.Groups[1].Value, 16);
continue;
}
// if above failed, try Unix UDID format
m = Regex.Match(info[i].UDID, "[0-9]+:[0-9]+:([0-9]+):[0-9]+:[0-9]+");
if (m.Success && m.Groups.Count == 2)
{
info[i].VendorID = Convert.ToInt32(m.Groups[1].Value, 10);
}
}
return result;
}
public static bool UsePmLogForFamily(int familyId)
{
return familyId >= (int)GCNFamilies.FAMILY_AI;
}
internal enum ADLStatus
{
/// <summary>
/// All OK, but need to wait.
/// </summary>
ADL_OK_WAIT = 4,
/// <summary>
/// All OK, but need restart.
/// </summary>
ADL_OK_RESTART = 3,
/// <summary>
/// All OK but need mode change.
/// </summary>
ADL_OK_MODE_CHANGE = 2,
/// <summary>
/// All OK, but with warning.
/// </summary>
ADL_OK_WARNING = 1,
/// <summary>
/// ADL function completed successfully.
/// </summary>
ADL_OK = 0,
/// <summary>
/// Generic Error. Most likely one or more of the Escape calls to the driver
/// failed!
/// </summary>
ADL_ERR = -1,
/// <summary>
/// ADL not initialized.
/// </summary>
ADL_ERR_NOT_INIT = -2,
/// <summary>
/// One of the parameter passed is invalid.
/// </summary>
ADL_ERR_INVALID_PARAM = -3,
/// <summary>
/// One of the parameter size is invalid.
/// </summary>
ADL_ERR_INVALID_PARAM_SIZE = -4,
/// <summary>
/// Invalid ADL index passed.
/// </summary>
ADL_ERR_INVALID_ADL_IDX = -5,
/// <summary>
/// Invalid controller index passed.
/// </summary>
ADL_ERR_INVALID_CONTROLLER_IDX = -6,
/// <summary>
/// Invalid display index passed.
/// </summary>
ADL_ERR_INVALID_DIPLAY_IDX = -7,
/// <summary>
/// Function not supported by the driver.
/// </summary>
ADL_ERR_NOT_SUPPORTED = -8,
/// <summary>
/// Null Pointer error.
/// </summary>
ADL_ERR_NULL_POINTER = -9,
/// <summary>
/// Call can't be made due to disabled adapter.
/// </summary>
ADL_ERR_DISABLED_ADAPTER = -10,
/// <summary>
/// Invalid Callback.
/// </summary>
ADL_ERR_INVALID_CALLBACK = -11,
/// <summary>
/// Display Resource conflict.
/// </summary>
ADL_ERR_RESOURCE_CONFLICT = -12,
/// <summary>
/// Failed to update some of the values. Can be returned by set request that
/// include multiple values if not all values were successfully committed.
/// </summary>
ADL_ERR_SET_INCOMPLETE = -20,
/// <summary>
/// There's no Linux XDisplay in Linux Console environment.
/// </summary>
ADL_ERR_NO_XDISPLAY = -21
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLAdapterInfo
{
public int Size;
public int AdapterIndex;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = ADL_MAX_PATH)]
public string UDID;
public int BusNumber;
public int DeviceNumber;
public int FunctionNumber;
public int VendorID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = ADL_MAX_PATH)]
public string AdapterName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = ADL_MAX_PATH)]
public string DisplayName;
public int Present;
public int Exist;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = ADL_MAX_PATH)]
public string DriverPath;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = ADL_MAX_PATH)]
public string DriverPathExt;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = ADL_MAX_PATH)]
public string PNPString;
public int OSDisplayIndex;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLODParameterRange
{
public int iMin;
public int iMax;
public int iStep;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLODParameters
{
public int iSize;
public int iNumberOfPerformanceLevels;
public int iActivityReportingSupported;
public int iDiscretePerformanceLevels;
public int iReserved;
public ADLODParameterRange sEngineClock;
public ADLODParameterRange sMemoryClock;
public ADLODParameterRange sVddc;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLOD6Capabilities
{
public int iCapabilities;
public int iSupportedStates;
public int iNumberOfPerformanceLevels;
public ADLODParameterRange sEngineClockRange;
public ADLODParameterRange sMemoryClockRange;
public int iExtValue;
public int iExtMask;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLPMActivity
{
public int iSize;
public int iEngineClock;
public int iMemoryClock;
public int iVddc;
public int iActivityPercent;
public int iCurrentPerformanceLevel;
public int iCurrentBusSpeed;
public int iCurrentBusLanes;
public int iMaximumBusLanes;
public int iReserved;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLTemperature
{
public int iSize;
public int iTemperature;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLFanSpeedValue
{
public int iSize;
public int iSpeedType;
public int iFanSpeed;
public int iFlags;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLFanSpeedInfo
{
public int iSize;
public int iFlags;
public int iMinPercent;
public int iMaxPercent;
public int iMinRPM;
public int iMaxRPM;
}
internal enum ADLODNCurrentPowerType
{
ODN_GPU_TOTAL_POWER = 0,
ODN_GPU_PPT_POWER,
ODN_GPU_SOCKET_POWER,
ODN_GPU_CHIP_POWER
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLVersionsInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string DriverVer;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string CatalystVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string CatalystWebLink;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLODNPerformanceStatus
{
public int iCoreClock;
public int iMemoryClock;
public int iDCEFClock;
public int iGFXClock;
public int iUVDClock;
public int iVCEClock;
public int iGPUActivityPercent;
public int iCurrentCorePerformanceLevel;
public int iCurrentMemoryPerformanceLevel;
public int iCurrentDCEFPerformanceLevel;
public int iCurrentGFXPerformanceLevel;
public int iUVDPerformanceLevel;
public int iVCEPerformanceLevel;
public int iCurrentBusSpeed;
public int iCurrentBusLanes;
public int iMaximumBusLanes;
public int iVDDC;
public int iVDDCI;
}
internal enum ADLODNTemperatureType
{
// This typed is named like this in the documentation but for some reason AMD failed to include it...
// Yet it seems these correspond with ADL_PMLOG_TEMPERATURE_xxx.
EDGE = 1,
MEM = 2,
VRVDDC = 3,
VRMVDD = 4,
LIQUID = 5,
PLX = 6,
HOTSPOT = 7
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLSingleSensorData
{
public int supported;
public int value;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLPMLogDataOutput
{
public int size;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ADL_PMLOG_MAX_SENSORS)]
public ADLSingleSensorData[] sensors;
}
internal enum ADLPMLogSensors
{
ADL_SENSOR_MAXTYPES = 0,
ADL_PMLOG_CLK_GFXCLK = 1,
ADL_PMLOG_CLK_MEMCLK = 2,
ADL_PMLOG_CLK_SOCCLK = 3,
ADL_PMLOG_CLK_UVDCLK1 = 4,
ADL_PMLOG_CLK_UVDCLK2 = 5,
ADL_PMLOG_CLK_VCECLK = 6,
ADL_PMLOG_CLK_VCNCLK = 7,
ADL_PMLOG_TEMPERATURE_EDGE = 8,
ADL_PMLOG_TEMPERATURE_MEM = 9,
ADL_PMLOG_TEMPERATURE_VRVDDC = 10,
ADL_PMLOG_TEMPERATURE_VRMVDD = 11,
ADL_PMLOG_TEMPERATURE_LIQUID = 12,
ADL_PMLOG_TEMPERATURE_PLX = 13,
ADL_PMLOG_FAN_RPM = 14,
ADL_PMLOG_FAN_PERCENTAGE = 15,
ADL_PMLOG_SOC_VOLTAGE = 16,
ADL_PMLOG_SOC_POWER = 17,
ADL_PMLOG_SOC_CURRENT = 18,
ADL_PMLOG_INFO_ACTIVITY_GFX = 19,
ADL_PMLOG_INFO_ACTIVITY_MEM = 20,
ADL_PMLOG_GFX_VOLTAGE = 21,
ADL_PMLOG_MEM_VOLTAGE = 22,
ADL_PMLOG_ASIC_POWER = 23,
ADL_PMLOG_TEMPERATURE_VRSOC = 24,
ADL_PMLOG_TEMPERATURE_VRMVDD0 = 25,
ADL_PMLOG_TEMPERATURE_VRMVDD1 = 26,
ADL_PMLOG_TEMPERATURE_HOTSPOT = 27,
ADL_PMLOG_TEMPERATURE_GFX = 28,
ADL_PMLOG_TEMPERATURE_SOC = 29,
ADL_PMLOG_GFX_POWER = 30,
ADL_PMLOG_GFX_CURRENT = 31,
ADL_PMLOG_TEMPERATURE_CPU = 32,
ADL_PMLOG_CPU_POWER = 33,
ADL_PMLOG_CLK_CPUCLK = 34,
ADL_PMLOG_THROTTLER_STATUS = 35, // GFX
ADL_PMLOG_CLK_VCN1CLK1 = 36,
ADL_PMLOG_CLK_VCN1CLK2 = 37,
ADL_PMLOG_SMART_POWERSHIFT_CPU = 38,
ADL_PMLOG_SMART_POWERSHIFT_DGPU = 39,
ADL_PMLOG_BUS_SPEED = 40,
ADL_PMLOG_BUS_LANES = 41,
ADL_PMLOG_TEMPERATURE_LIQUID0 = 42,
ADL_PMLOG_TEMPERATURE_LIQUID1 = 43,
ADL_PMLOG_CLK_FCLK = 44,
ADL_PMLOG_THROTTLER_STATUS_CPU = 45,
ADL_PMLOG_SSPAIRED_ASICPOWER = 46, // apuPower
ADL_PMLOG_SSTOTAL_POWERLIMIT = 47, // Total Power limit
ADL_PMLOG_SSAPU_POWERLIMIT = 48, // APU Power limit
ADL_PMLOG_SSDGPU_POWERLIMIT = 49, // DGPU Power limit
ADL_PMLOG_TEMPERATURE_HOTSPOT_GCD = 50,
ADL_PMLOG_TEMPERATURE_HOTSPOT_MCD = 51,
ADL_PMLOG_THROTTLER_TEMP_EDGE_PERCENTAGE = 52,
ADL_PMLOG_THROTTLER_TEMP_HOTSPOT_PERCENTAGE = 53,
ADL_PMLOG_THROTTLER_TEMP_HOTSPOT_GCD_PERCENTAGE = 54,
ADL_PMLOG_THROTTLER_TEMP_HOTSPOT_MCD_PERCENTAGE = 55,
ADL_PMLOG_THROTTLER_TEMP_MEM_PERCENTAGE = 56,
ADL_PMLOG_THROTTLER_TEMP_VR_GFX_PERCENTAGE = 57,
ADL_PMLOG_THROTTLER_TEMP_VR_MEM0_PERCENTAGE = 58,
ADL_PMLOG_THROTTLER_TEMP_VR_MEM1_PERCENTAGE = 59,
ADL_PMLOG_THROTTLER_TEMP_VR_SOC_PERCENTAGE = 60,
ADL_PMLOG_THROTTLER_TEMP_LIQUID0_PERCENTAGE = 61,
ADL_PMLOG_THROTTLER_TEMP_LIQUID1_PERCENTAGE = 62,
ADL_PMLOG_THROTTLER_TEMP_PLX_PERCENTAGE = 63,
ADL_PMLOG_THROTTLER_TDC_GFX_PERCENTAGE = 64,
ADL_PMLOG_THROTTLER_TDC_SOC_PERCENTAGE = 65,
ADL_PMLOG_THROTTLER_TDC_USR_PERCENTAGE = 66,
ADL_PMLOG_THROTTLER_PPT0_PERCENTAGE = 67,
ADL_PMLOG_THROTTLER_PPT1_PERCENTAGE = 68,
ADL_PMLOG_THROTTLER_PPT2_PERCENTAGE = 69,
ADL_PMLOG_THROTTLER_PPT3_PERCENTAGE = 70,
ADL_PMLOG_THROTTLER_FIT_PERCENTAGE = 71,
ADL_PMLOG_THROTTLER_GFX_APCC_PLUS_PERCENTAGE = 72,
ADL_PMLOG_BOARD_POWER = 73,
ADL_PMLOG_MAX_SENSORS_REAL
}
internal enum GCNFamilies
{
FAMILY_UNKNOWN = 0,
FAMILY_TN = 105, // Trinity APUs
FAMILY_SI = 110, // Southern Islands: Tahiti, Pitcairn, CapeVerde, Oland, Hainan
FAMILY_CI = 120, // Sea Islands: Bonaire, Hawaii
FAMILY_KV = 125, // Kaveri, Kabini, Mullins
FAMILY_VI = 130, // Volcanic Islands: Iceland, Tonga, Fiji
FAMILY_CZ = 135, // Carrizo APUs: Carrizo, Stoney
FAMILY_AI = 141, // Vega: 10, 20
FAMILY_RV = 142, // Raven (Vega GCN 5.0)
FAMILY_NV = 143, // Navi10, Navi2x
FAMILY_VGH = 144, // Van Gogh (RDNA 2.0)
FAMILY_NV3 = 145, // Navi: 3x (GC 11.0.0, RDNA 3.0)
FAMILY_YC = 146, // Rembrandt (Yellow Carp, RDNA 2.0)
FAMILY_GC_11_0_1 = 148, // Phoenix (GC 11.0.1, RDNA 3.0)
FAMILY_GC_10_3_6 = 149, // Raphael (GC 10.3.6, RDNA 2.0)
FAMILY_GC_11_5_0 = 150, // GC 11.5.0
FAMILY_GC_10_3_7 = 151, // Mendocino (GC 10.3.7, RDNA 2.0)
}
//Structure containing information related power management logging.
[StructLayout(LayoutKind.Sequential)]
internal struct ADLPMLogSupportInfo
{
/// list of sensors defined by ADL_PMLOG_SENSORS
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ADL_PMLOG_MAX_SENSORS)]
public ushort[] usSensors;
/// Reserved
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public int[] iReserved;
}
//Structure containing information to start power management logging.
[StructLayout(LayoutKind.Sequential)]
internal struct ADLPMLogStartInput
{
/// list of sensors defined by ADL_PMLOG_SENSORS
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ADL_PMLOG_MAX_SENSORS)]
public ushort[] usSensors;
/// Sample rate in milliseconds
public uint ulSampleRate;
/// Reserved
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
public int[] iReserved;
}
//Structure containing information to start power management logging.
[StructLayout(LayoutKind.Explicit)]
internal struct ADLPMLogStartOutput
{
/// Pointer to memory address containing logging data
[FieldOffset(0)] public IntPtr pLoggingAddress;
[FieldOffset(0)] public ulong ptrLoggingAddress;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLPMLogData
{
/// Structure version
public uint ulVersion;
/// Current driver sample rate
public uint ulActiveSampleRate;
/// Timestamp of last update
public ulong ulLastUpdated;
// 2D array of sensor and values -- unsigned int ulValues[ADL_PMLOG_MAX_SUPPORTED_SENSORS][2]
// the nested array will be accessed like a single dimension array
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ADL_PMLOG_MAX_SENSORS*2)]
public uint[] ulValues;
/// Reserved
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public uint[] ulReserved;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLGcnInfo
{
public int CuCount; //Number of compute units on the ASIC.
public int TexCount; //Number of texture mapping units.
public int RopCount; //Number of Render backend Units.
// see GCNFamilies enum, references:
// https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/amd/addrlib/src/amdgpu_asic_addr.h
// https://github.com/torvalds/linux/blob/master/include/uapi/drm/amdgpu_drm.h
public int ASICFamilyId;
public int ASICRevisionId;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ADLMemoryInfoX4
{
/// Memory size in bytes.
public long iMemorySize;
/// Memory type in string.
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = ADL_MAX_PATH)]
public string strMemoryType;
/// Highest default performance level Memory bandwidth in Mbytes/s
public long iMemoryBandwidth;
/// HyperMemory size in bytes.
public long iHyperMemorySize;
/// Invisible Memory size in bytes.
public long iInvisibleMemorySize;
/// Visible Memory size in bytes.
public long iVisibleMemorySize;
/// Vram vendor ID
public long iVramVendorRevId;
/// Memory Bandiwidth that is calculated and finalized on the driver side, grab and go.
public long iMemoryBandwidthX2;
/// Memory Bit Rate that is calculated and finalized on the driver side, grab and go.
public long iMemoryBitRateX2;
}
}

View File

@@ -0,0 +1,29 @@
// 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.
// All Rights Reserved.
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
using System;
using System.Runtime.InteropServices;
namespace LibreHardwareMonitor.Interop;
internal static class CfgMgr32
{
internal const uint CM_GET_DEVICE_INTERFACE_LIST_PRESENT = 0;
internal const int CR_SUCCESS = 0;
internal const string DllName = "CfgMgr32.dll";
internal static Guid GUID_DISPLAY_DEVICE_ARRIVAL = new("1CA05180-A699-450A-9A0C-DE4FBE3DDD89");
[DllImport(DllName, CharSet = CharSet.Unicode)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern uint CM_Get_Device_Interface_List_Size(out uint size, ref Guid interfaceClassGuid, string deviceID, uint flags);
[DllImport(DllName, CharSet = CharSet.Unicode)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern uint CM_Get_Device_Interface_List(ref Guid interfaceClassGuid, string deviceID, char[] buffer, uint bufferLength, uint flags);
}

View File

@@ -0,0 +1,47 @@
// 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.
// All Rights Reserved.
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
using System.Runtime.InteropServices;
namespace LibreHardwareMonitor.Interop;
internal static class D3dkmdt
{
internal enum DXGK_ENGINE_TYPE
{
DXGK_ENGINE_TYPE_OTHER = 0,
DXGK_ENGINE_TYPE_3D = 1,
DXGK_ENGINE_TYPE_VIDEO_DECODE = 2,
DXGK_ENGINE_TYPE_VIDEO_ENCODE = 3,
DXGK_ENGINE_TYPE_VIDEO_PROCESSING = 4,
DXGK_ENGINE_TYPE_SCENE_ASSEMBLY = 5,
DXGK_ENGINE_TYPE_COPY = 6,
DXGK_ENGINE_TYPE_OVERLAY = 7,
DXGK_ENGINE_TYPE_CRYPTO,
DXGK_ENGINE_TYPE_MAX
}
[StructLayout(LayoutKind.Sequential)]
internal struct DXGK_NODEMETADATA_FLAGS
{
public uint Value;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
internal struct DXGK_NODEMETADATA
{
public DXGK_ENGINE_TYPE EngineType;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string FriendlyName;
public DXGK_NODEMETADATA_FLAGS Flags;
public byte GpuMmuSupported;
public byte IoMmuSupported;
}
}

View File

@@ -0,0 +1,562 @@
// 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.
// All Rights Reserved.
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
using System;
using System.Runtime.InteropServices;
namespace LibreHardwareMonitor.Interop;
internal static class D3dkmth
{
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_CLOSEADAPTER
{
public uint hAdapter;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYADAPTERINFO
{
public uint hAdapter;
public KMTQUERYADAPTERINFOTYPE Type;
public IntPtr pPrivateDriverData;
public int PrivateDriverDataSize;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_OPENADAPTERFROMDEVICENAME
{
[MarshalAs(UnmanagedType.LPWStr)]
public string pDeviceName;
public uint hAdapter;
public WinNt.LUID AdapterLuid;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_ADAPTERTYPE
{
public D3DKMT_ADAPTERTYPE_FLAGS Value;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_QUERY_SEGMENT
{
public uint SegmentId;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_QUERY_NODE
{
public uint NodeId;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_QUERY_VIDPNSOURCE
{
public uint VidPnSourceId;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_REFERENCE_DMA_BUFFER
{
public uint NbCall;
public uint NbAllocationsReferenced;
public uint MaxNbAllocationsReferenced;
public uint NbNULLReference;
public uint NbWriteReference;
public uint NbRenamedAllocationsReferenced;
public uint NbIterationSearchingRenamedAllocation;
public uint NbLockedAllocationReferenced;
public uint NbAllocationWithValidPrepatchingInfoReferenced;
public uint NbAllocationWithInvalidPrepatchingInfoReferenced;
public uint NbDMABufferSuccessfullyPrePatched;
public uint NbPrimariesReferencesOverflow;
public uint NbAllocationWithNonPreferredResources;
public uint NbAllocationInsertedInMigrationTable;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_SEGMENTSIZEINFO
{
public ulong DedicatedVideoMemorySize;
public ulong DedicatedSystemMemorySize;
public ulong SharedSystemMemorySize;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_RENAMING
{
public uint NbAllocationsRenamed;
public uint NbAllocationsShrinked;
public uint NbRenamedBuffer;
public uint MaxRenamingListLength;
public uint NbFailuresDueToRenamingLimit;
public uint NbFailuresDueToCreateAllocation;
public uint NbFailuresDueToOpenAllocation;
public uint NbFailuresDueToLowResource;
public uint NbFailuresDueToNonRetiredLimit;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_COUNTER
{
public uint Count;
public ulong Bytes;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_PREPRATION
{
public uint BroadcastStall;
public uint NbDMAPrepared;
public uint NbDMAPreparedLongPath;
public uint ImmediateHighestPreparationPass;
public D3DKMT_QUERYSTATISTICS_COUNTER AllocationsTrimmed;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_PAGING_FAULT
{
public D3DKMT_QUERYSTATISTICS_COUNTER Faults;
public D3DKMT_QUERYSTATISTICS_COUNTER FaultsFirstTimeAccess;
public D3DKMT_QUERYSTATISTICS_COUNTER FaultsReclaimed;
public D3DKMT_QUERYSTATISTICS_COUNTER FaultsMigration;
public D3DKMT_QUERYSTATISTICS_COUNTER FaultsIncorrectResource;
public D3DKMT_QUERYSTATISTICS_COUNTER FaultsLostContent;
public D3DKMT_QUERYSTATISTICS_COUNTER FaultsEvicted;
public D3DKMT_QUERYSTATISTICS_COUNTER AllocationsMEM_RESET;
public D3DKMT_QUERYSTATISTICS_COUNTER AllocationsUnresetSuccess;
public D3DKMT_QUERYSTATISTICS_COUNTER AllocationsUnresetFail;
public uint AllocationsUnresetSuccessRead;
public uint AllocationsUnresetFailRead;
public D3DKMT_QUERYSTATISTICS_COUNTER Evictions;
public D3DKMT_QUERYSTATISTICS_COUNTER EvictionsDueToPreparation;
public D3DKMT_QUERYSTATISTICS_COUNTER EvictionsDueToLock;
public D3DKMT_QUERYSTATISTICS_COUNTER EvictionsDueToClose;
public D3DKMT_QUERYSTATISTICS_COUNTER EvictionsDueToPurge;
public D3DKMT_QUERYSTATISTICS_COUNTER EvictionsDueToSuspendCPUAccess;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_PAGING_TRANSFER
{
public ulong BytesFilled;
public ulong BytesDiscarded;
public ulong BytesMappedIntoAperture;
public ulong BytesUnmappedFromAperture;
public ulong BytesTransferredFromMdlToMemory;
public ulong BytesTransferredFromMemoryToMdl;
public ulong BytesTransferredFromApertureToMemory;
public ulong BytesTransferredFromMemoryToAperture;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_SWIZZLING_RANGE
{
public uint NbRangesAcquired;
public uint NbRangesReleased;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_LOCKS
{
public uint NbLocks;
public uint NbLocksWaitFlag;
public uint NbLocksDiscardFlag;
public uint NbLocksNoOverwrite;
public uint NbLocksNoReadSync;
public uint NbLocksLinearization;
public uint NbComplexLocks;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_ALLOCATIONS
{
public D3DKMT_QUERYSTATISTICS_COUNTER Created;
public D3DKMT_QUERYSTATISTICS_COUNTER Destroyed;
public D3DKMT_QUERYSTATISTICS_COUNTER Opened;
public D3DKMT_QUERYSTATISTICS_COUNTER Closed;
public D3DKMT_QUERYSTATISTICS_COUNTER MigratedSuccess;
public D3DKMT_QUERYSTATISTICS_COUNTER MigratedFail;
public D3DKMT_QUERYSTATISTICS_COUNTER MigratedAbandoned;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_TERMINATIONS
{
public D3DKMT_QUERYSTATISTICS_COUNTER TerminatedShared;
public D3DKMT_QUERYSTATISTICS_COUNTER TerminatedNonShared;
public D3DKMT_QUERYSTATISTICS_COUNTER DestroyedShared;
public D3DKMT_QUERYSTATISTICS_COUNTER DestroyedNonShared;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_ADAPTER_INFORMATION
{
public uint NbSegments;
public uint NodeCount;
public uint VidPnSourceCount;
public uint VSyncEnabled;
public uint TdrDetectedCount;
public long ZeroLengthDmaBuffers;
public ulong RestartedPeriod;
public D3DKMT_QUERYSTATISTICS_REFERENCE_DMA_BUFFER ReferenceDmaBuffer;
public D3DKMT_QUERYSTATISTICS_RENAMING Renaming;
public D3DKMT_QUERYSTATISTICS_PREPRATION Preparation;
public D3DKMT_QUERYSTATISTICS_PAGING_FAULT PagingFault;
public D3DKMT_QUERYSTATISTICS_PAGING_TRANSFER PagingTransfer;
public D3DKMT_QUERYSTATISTICS_SWIZZLING_RANGE SwizzlingRange;
public D3DKMT_QUERYSTATISTICS_LOCKS Locks;
public D3DKMT_QUERYSTATISTICS_ALLOCATIONS Allocations;
public D3DKMT_QUERYSTATISTICS_TERMINATIONS Terminations;
private readonly ulong Reserved;
private readonly ulong Reserved1;
private readonly ulong Reserved2;
private readonly ulong Reserved3;
private readonly ulong Reserved4;
private readonly ulong Reserved5;
private readonly ulong Reserved6;
private readonly ulong Reserved7;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_MEMORY
{
public ulong TotalBytesEvicted;
public uint AllocsCommitted;
public uint AllocsResident;
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION
{
public ulong CommitLimit;
public ulong BytesCommitted;
public ulong BytesResident;
public D3DKMT_QUERYSTATISTICS_MEMORY Memory;
public uint Aperture; // boolean
public fixed ulong TotalBytesEvictedByPriority[5]; // D3DKMT_QUERYSTATISTICS_SEGMENT_PREFERENCE_MAX
public ulong SystemMemoryEndAddress;
public D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION_POWER_FLAGS PowerFlags;
public fixed ulong Reserved[6];
}
[StructLayout(LayoutKind.Explicit)]
internal struct D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION_POWER_FLAGS
{
[FieldOffset(0)]
public ulong PreservedDuringStandby;
[FieldOffset(1)]
public ulong PreservedDuringHibernate;
[FieldOffset(2)]
public ulong PartiallyPreservedDuringHibernate;
[FieldOffset(3)]
public ulong Reserved;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_VIDEO_MEMORY
{
public uint AllocsCommitted;
public D3DKMT_QUERYSTATISTICS_COUNTER AllocsResidentIn0;
public D3DKMT_QUERYSTATISTICS_COUNTER AllocsResidentIn1;
public D3DKMT_QUERYSTATISTICS_COUNTER AllocsResidentIn2;
public D3DKMT_QUERYSTATISTICS_COUNTER AllocsResidentIn3;
public D3DKMT_QUERYSTATISTICS_COUNTER AllocsResidentIn4;
public D3DKMT_QUERYSTATISTICS_COUNTER AllocsResidentInNonPreferred;
public ulong TotalBytesEvictedDueToPreparation;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT_POLICY
{
public ulong UseMRU;
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT_INFORMATION
{
public ulong BytesCommitted;
public ulong MaximumWorkingSet;
public ulong MinimumWorkingSet;
public uint NbReferencedAllocationEvictedInPeriod;
public D3DKMT_QUERYSTATISTICS_VIDEO_MEMORY VideoMemory;
public D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT_POLICY _Policy;
public fixed ulong Reserved[8];
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_PREEMPTION_INFORMATION
{
public uint PreemptionCounter;
public uint PreemptionCounter1;
public uint PreemptionCounter2;
public uint PreemptionCounter3;
public uint PreemptionCounter4;
public uint PreemptionCounter5;
public uint PreemptionCounter6;
public uint PreemptionCounter7;
public uint PreemptionCounter8;
public uint PreemptionCounter9;
public uint PreemptionCounter10;
public uint PreemptionCounter11;
public uint PreemptionCounter12;
public uint PreemptionCounter13;
public uint PreemptionCounter14;
public uint PreemptionCounter15;
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct D3DKMT_QUERYSTATISTICS_PROCESS_NODE_INFORMATION
{
public WinNt.LARGE_INTEGER RunningTime; // 100ns
public uint ContextSwitch;
private readonly D3DKMT_QUERYSTATISTICS_PREEMPTION_INFORMATION PreemptionStatistics;
private readonly D3DKMT_QUERYSTATISTICS_PACKET_INFORMATION PacketStatistics;
private fixed ulong Reserved[8];
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct D3DKMT_QUERYSTATISTICS_NODE_INFORMATION
{
public D3DKMT_QUERYSTATISTICS_PROCESS_NODE_INFORMATION GlobalInformation; // global
public D3DKMT_QUERYSTATISTICS_PROCESS_NODE_INFORMATION SystemInformation; // system thread
//public UInt32 NodeId; // Win10
public fixed ulong Reserved[8];
}
internal struct D3DKMT_QUERYSTATISTICS_DMA_PACKET_TYPE_INFORMATION
{
public uint PacketSubmitted;
public uint PacketCompleted;
public uint PacketPreempted;
public uint PacketFaulted;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION
{
public uint PacketSubmited;
public uint PacketCompleted;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS_PACKET_INFORMATION
{
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket;
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket1;
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket2;
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket3;
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket4;
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket5;
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket6;
public D3DKMT_QUERYSTATISTICS_QUEUE_PACKET_TYPE_INFORMATION QueuePacket7;
public D3DKMT_QUERYSTATISTICS_DMA_PACKET_TYPE_INFORMATION DmaPacket;
public D3DKMT_QUERYSTATISTICS_DMA_PACKET_TYPE_INFORMATION DmaPacket1;
public D3DKMT_QUERYSTATISTICS_DMA_PACKET_TYPE_INFORMATION DmaPacket2;
public D3DKMT_QUERYSTATISTICS_DMA_PACKET_TYPE_INFORMATION DmaPacket3;
}
[StructLayout(LayoutKind.Explicit)]
internal struct D3DKMT_QUERYSTATISTICS_RESULT
{
[FieldOffset(0), MarshalAs(UnmanagedType.Struct)]
public D3DKMT_QUERYSTATISTICS_ADAPTER_INFORMATION AdapterInformation;
[FieldOffset(0), MarshalAs(UnmanagedType.Struct)]
public D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION SegmentInformation;
[FieldOffset(0), MarshalAs(UnmanagedType.Struct)]
public D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT_INFORMATION ProcessSegmentInformation;
[FieldOffset(0), MarshalAs(UnmanagedType.Struct)]
public D3DKMT_QUERYSTATISTICS_NODE_INFORMATION NodeInformation;
// D3DKMT_QUERYSTATISTICS_PROCESS_INFORMATION ProcessInformation;
// D3DKMT_QUERYSTATISTICS_PROCESS_NODE_INFORMATION ProcessNodeInformation;
// D3DKMT_QUERYSTATISTICS_PHYSICAL_ADAPTER_INFORMATION PhysAdapterInformation;
// D3DKMT_QUERYSTATISTICS_SEGMENT_INFORMATION_V1 SegmentInformationV1; // WIN7
// D3DKMT_QUERYSTATISTICS_VIDPNSOURCE_INFORMATION VidPnSourceInformation;
// D3DKMT_QUERYSTATISTICS_PROCESS_ADAPTER_INFORMATION ProcessAdapterInformation;
// D3DKMT_QUERYSTATISTICS_PROCESS_VIDPNSOURCE_INFORMATION ProcessVidPnSourceInformation;
// D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT_GROUP_INFORMATION ProcessSegmentGroupInformation;
}
[StructLayout(LayoutKind.Explicit)]
internal struct D3DKMT_QUERYSTATISTICS_QUERY_ELEMENT
{
[FieldOffset(0)]
public D3DKMT_QUERYSTATISTICS_QUERY_SEGMENT QuerySegment;
[FieldOffset(0)]
public D3DKMT_QUERYSTATISTICS_QUERY_SEGMENT QueryProcessSegment;
[FieldOffset(0)]
public D3DKMT_QUERYSTATISTICS_QUERY_NODE QueryNode;
[FieldOffset(0)]
public D3DKMT_QUERYSTATISTICS_QUERY_NODE QueryProcessNode;
[FieldOffset(0)]
public D3DKMT_QUERYSTATISTICS_QUERY_VIDPNSOURCE QueryVidPnSource;
[FieldOffset(0)]
public D3DKMT_QUERYSTATISTICS_QUERY_VIDPNSOURCE QueryProcessVidPnSource;
}
[StructLayout(LayoutKind.Sequential)]
internal struct D3DKMT_QUERYSTATISTICS
{
public D3DKMT_QUERYSTATISTICS_TYPE Type;
public WinNt.LUID AdapterLuid;
public IntPtr ProcessHandle;
public D3DKMT_QUERYSTATISTICS_RESULT QueryResult;
public D3DKMT_QUERYSTATISTICS_QUERY_ELEMENT QueryElement;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct D3DKMT_NODEMETADATA
{
public uint NodeOrdinalAndAdapterIndex;
public D3dkmdt.DXGK_NODEMETADATA NodeData;
}
[Flags]
internal enum D3DKMT_ADAPTERTYPE_FLAGS : uint
{
RenderSupported = 0,
DisplaySupported = 1,
SoftwareDevice = 2,
PostDevice = 4,
HybridDiscrete = 8,
HybridIntegrated = 16,
IndirectDisplayDevice = 32,
Paravirtualized = 64,
ACGSupported = 128,
SupportSetTimingsFromVidPn = 256,
Detachable = 512,
ComputeOnly = 1024,
Prototype = 2045
}
internal enum D3DKMT_QUERYSTATISTICS_TYPE
{
D3DKMT_QUERYSTATISTICS_ADAPTER,
D3DKMT_QUERYSTATISTICS_PROCESS,
D3DKMT_QUERYSTATISTICS_PROCESS_ADAPTER,
D3DKMT_QUERYSTATISTICS_SEGMENT,
D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT,
D3DKMT_QUERYSTATISTICS_NODE,
D3DKMT_QUERYSTATISTICS_PROCESS_NODE,
D3DKMT_QUERYSTATISTICS_VIDPNSOURCE,
D3DKMT_QUERYSTATISTICS_PROCESS_VIDPNSOURCE,
D3DKMT_QUERYSTATISTICS_PROCESS_SEGMENT_GROUP,
D3DKMT_QUERYSTATISTICS_PHYSICAL_ADAPTER
}
internal enum D3DKMT_QUERYSTATISTICS_DMA_PACKET_TYPE
{
D3DKMT_ClientRenderBuffer = 0,
D3DKMT_ClientPagingBuffer = 1,
D3DKMT_SystemPagingBuffer = 2,
D3DKMT_SystemPreemptionBuffer = 3,
D3DKMT_DmaPacketTypeMax
}
internal enum KMTQUERYADAPTERINFOTYPE
{
KMTQAITYPE_UMDRIVERPRIVATE = 0,
KMTQAITYPE_UMDRIVERNAME = 1,
KMTQAITYPE_UMOPENGLINFO = 2,
KMTQAITYPE_GETSEGMENTSIZE = 3,
KMTQAITYPE_ADAPTERGUID = 4,
KMTQAITYPE_FLIPQUEUEINFO = 5,
KMTQAITYPE_ADAPTERADDRESS = 6,
KMTQAITYPE_SETWORKINGSETINFO = 7,
KMTQAITYPE_ADAPTERREGISTRYINFO = 8,
KMTQAITYPE_CURRENTDISPLAYMODE = 9,
KMTQAITYPE_MODELIST = 10,
KMTQAITYPE_CHECKDRIVERUPDATESTATUS = 11,
KMTQAITYPE_VIRTUALADDRESSINFO = 12,
KMTQAITYPE_DRIVERVERSION = 13,
KMTQAITYPE_ADAPTERTYPE = 15,
KMTQAITYPE_OUTPUTDUPLCONTEXTSCOUNT = 16,
KMTQAITYPE_WDDM_1_2_CAPS = 17,
KMTQAITYPE_UMD_DRIVER_VERSION = 18,
KMTQAITYPE_DIRECTFLIP_SUPPORT = 19,
KMTQAITYPE_MULTIPLANEOVERLAY_SUPPORT = 20,
KMTQAITYPE_DLIST_DRIVER_NAME = 21,
KMTQAITYPE_WDDM_1_3_CAPS = 22,
KMTQAITYPE_MULTIPLANEOVERLAY_HUD_SUPPORT = 23,
KMTQAITYPE_WDDM_2_0_CAPS = 24,
KMTQAITYPE_NODEMETADATA = 25,
KMTQAITYPE_CPDRIVERNAME = 26,
KMTQAITYPE_XBOX = 27,
KMTQAITYPE_INDEPENDENTFLIP_SUPPORT = 28,
KMTQAITYPE_MIRACASTCOMPANIONDRIVERNAME = 29,
KMTQAITYPE_PHYSICALADAPTERCOUNT = 30,
KMTQAITYPE_PHYSICALADAPTERDEVICEIDS = 31,
KMTQAITYPE_DRIVERCAPS_EXT = 32,
KMTQAITYPE_QUERY_MIRACAST_DRIVER_TYPE = 33,
KMTQAITYPE_QUERY_GPUMMU_CAPS = 34,
KMTQAITYPE_QUERY_MULTIPLANEOVERLAY_DECODE_SUPPORT = 35,
KMTQAITYPE_QUERY_HW_PROTECTION_TEARDOWN_COUNT = 36,
KMTQAITYPE_QUERY_ISBADDRIVERFORHWPROTECTIONDISABLED = 37,
KMTQAITYPE_MULTIPLANEOVERLAY_SECONDARY_SUPPORT = 38,
KMTQAITYPE_INDEPENDENTFLIP_SECONDARY_SUPPORT = 39,
KMTQAITYPE_PANELFITTER_SUPPORT = 40,
KMTQAITYPE_PHYSICALADAPTERPNPKEY = 41,
KMTQAITYPE_GETSEGMENTGROUPSIZE = 42,
KMTQAITYPE_MPO3DDI_SUPPORT = 43,
KMTQAITYPE_HWDRM_SUPPORT = 44,
KMTQAITYPE_MPOKERNELCAPS_SUPPORT = 45,
KMTQAITYPE_MULTIPLANEOVERLAY_STRETCH_SUPPORT = 46,
KMTQAITYPE_GET_DEVICE_VIDPN_OWNERSHIP_INFO = 47,
KMTQAITYPE_QUERYREGISTRY = 48,
KMTQAITYPE_KMD_DRIVER_VERSION = 49,
KMTQAITYPE_BLOCKLIST_KERNEL = 50,
KMTQAITYPE_BLOCKLIST_RUNTIME = 51,
KMTQAITYPE_ADAPTERGUID_RENDER = 52,
KMTQAITYPE_ADAPTERADDRESS_RENDER = 53,
KMTQAITYPE_ADAPTERREGISTRYINFO_RENDER = 54,
KMTQAITYPE_CHECKDRIVERUPDATESTATUS_RENDER = 55,
KMTQAITYPE_DRIVERVERSION_RENDER = 56,
KMTQAITYPE_ADAPTERTYPE_RENDER = 57,
KMTQAITYPE_WDDM_1_2_CAPS_RENDER = 58,
KMTQAITYPE_WDDM_1_3_CAPS_RENDER = 59,
KMTQAITYPE_QUERY_ADAPTER_UNIQUE_GUID = 60,
KMTQAITYPE_NODEPERFDATA = 61,
KMTQAITYPE_ADAPTERPERFDATA = 62,
KMTQAITYPE_ADAPTERPERFDATA_CAPS = 63,
KMTQUITYPE_GPUVERSION = 64,
KMTQAITYPE_DRIVER_DESCRIPTION = 65,
KMTQAITYPE_DRIVER_DESCRIPTION_RENDER = 66,
KMTQAITYPE_SCANOUT_CAPS = 67,
KMTQAITYPE_DISPLAY_UMDRIVERNAME = 71,
KMTQAITYPE_PARAVIRTUALIZATION_RENDER = 68,
KMTQAITYPE_SERVICENAME = 69,
KMTQAITYPE_WDDM_2_7_CAPS = 70,
KMTQAITYPE_TRACKEDWORKLOAD_SUPPORT = 72
}
}

View File

@@ -0,0 +1,183 @@
// 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.
// All Rights Reserved.
using System;
using System.Runtime.InteropServices;
// ReSharper disable InconsistentNaming
namespace LibreHardwareMonitor.Interop;
internal static class Ftd2xx
{
private const string DllName = "Ftd2xx.dll";
public static bool DllExists()
{
IntPtr module = Kernel32.LoadLibrary(DllName);
if (module == IntPtr.Zero)
return false;
Kernel32.FreeLibrary(module);
return true;
}
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_CreateDeviceInfoList(out uint numDevices);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_GetDeviceInfoList([Out] FT_DEVICE_INFO_NODE[] deviceInfoNodes, ref uint length);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_Open(int device, out FT_HANDLE handle);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_Close(FT_HANDLE handle);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_SetBaudRate(FT_HANDLE handle, uint baudRate);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_SetDataCharacteristics(FT_HANDLE handle, byte wordLength, byte stopBits, byte parity);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_SetFlowControl(FT_HANDLE handle, FT_FLOW_CONTROL flowControl, byte xon, byte xoff);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_SetTimeouts(FT_HANDLE handle, uint readTimeout, uint writeTimeout);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_Write(FT_HANDLE handle, byte[] buffer, uint bytesToWrite, out uint bytesWritten);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_Purge(FT_HANDLE handle, FT_PURGE mask);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_GetStatus(FT_HANDLE handle, out uint amountInRxQueue, out uint amountInTxQueue, out uint eventStatus);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_Read(FT_HANDLE handle, [Out] byte[] buffer, uint bytesToRead, out uint bytesReturned);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern FT_STATUS FT_ReadByte(FT_HANDLE handle, out byte buffer, uint bytesToRead, out uint bytesReturned);
public static FT_STATUS Write(FT_HANDLE handle, byte[] buffer)
{
FT_STATUS status = FT_Write(handle, buffer, (uint)buffer.Length, out uint bytesWritten);
if (bytesWritten != buffer.Length)
return FT_STATUS.FT_FAILED_TO_WRITE_DEVICE;
return status;
}
public static int BytesToRead(FT_HANDLE handle)
{
if (FT_GetStatus(handle, out uint amountInRxQueue, out uint _, out uint _) == FT_STATUS.FT_OK)
return (int)amountInRxQueue;
return 0;
}
public static byte ReadByte(FT_HANDLE handle)
{
FT_STATUS status = FT_ReadByte(handle, out byte buffer, 1, out uint bytesReturned);
if (status != FT_STATUS.FT_OK || bytesReturned != 1)
throw new InvalidOperationException();
return buffer;
}
public static void Read(FT_HANDLE handle, byte[] buffer)
{
FT_STATUS status = FT_Read(handle, buffer, (uint)buffer.Length, out uint bytesReturned);
if (status != FT_STATUS.FT_OK || bytesReturned != buffer.Length)
throw new InvalidOperationException();
}
internal enum FT_DEVICE : uint
{
FT_DEVICE_232BM,
FT_DEVICE_232AM,
FT_DEVICE_100AX,
FT_DEVICE_UNKNOWN,
FT_DEVICE_2232C,
FT_DEVICE_232R,
FT_DEVICE_2232H,
FT_DEVICE_4232H
}
internal enum FT_STATUS
{
FT_OK,
FT_INVALID_HANDLE,
FT_DEVICE_NOT_FOUND,
FT_DEVICE_NOT_OPENED,
FT_IO_ERROR,
FT_INSUFFICIENT_RESOURCES,
FT_INVALID_PARAMETER,
FT_INVALID_BAUD_RATE,
FT_DEVICE_NOT_OPENED_FOR_ERASE,
FT_DEVICE_NOT_OPENED_FOR_WRITE,
FT_FAILED_TO_WRITE_DEVICE,
FT_EEPROM_READ_FAILED,
FT_EEPROM_WRITE_FAILED,
FT_EEPROM_ERASE_FAILED,
FT_EEPROM_NOT_PRESENT,
FT_EEPROM_NOT_PROGRAMMED,
FT_INVALID_ARGS,
FT_OTHER_ERROR
}
internal enum FT_FLOW_CONTROL : ushort
{
FT_FLOW_DTR_DSR = 512,
FT_FLOW_NONE = 0,
FT_FLOW_RTS_CTS = 256,
FT_FLOW_XON_XOFF = 1024
}
internal enum FT_PURGE : uint
{
FT_PURGE_RX = 1,
FT_PURGE_TX = 2,
FT_PURGE_ALL = 3
}
[StructLayout(LayoutKind.Sequential)]
internal struct FT_HANDLE
{
private readonly IntPtr _handle;
}
[StructLayout(LayoutKind.Sequential)]
internal struct FT_DEVICE_INFO_NODE
{
public uint Flags;
public FT_DEVICE Type;
public uint ID;
public uint LocId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string SerialNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string Description;
public FT_HANDLE Handle;
}
}

View File

@@ -0,0 +1,32 @@
// 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.
// All Rights Reserved.
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
using System.Runtime.InteropServices;
namespace LibreHardwareMonitor.Interop;
internal static class Gdi32
{
internal const string DllName = "Gdi32.dll";
[DllImport(DllName, ExactSpelling = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern uint D3DKMTCloseAdapter(ref D3dkmth.D3DKMT_CLOSEADAPTER closeAdapter);
[DllImport(DllName, ExactSpelling = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern uint D3DKMTOpenAdapterFromDeviceName(ref D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME openAdapterFromDeviceName);
[DllImport(DllName, ExactSpelling = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern uint D3DKMTQueryAdapterInfo(ref D3dkmth.D3DKMT_QUERYADAPTERINFO queryAdapterInfo);
[DllImport(DllName, ExactSpelling = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern uint D3DKMTQueryStatistics(ref D3dkmth.D3DKMT_QUERYSTATISTICS queryStatistics);
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Runtime.InteropServices;
namespace LibreHardwareMonitor.Interop;
internal class InpOut
{
public delegate IntPtr MapPhysToLinDelegate(IntPtr pbPhysAddr, uint dwPhysSize, out IntPtr pPhysicalMemoryHandle);
public delegate bool UnmapPhysicalMemoryDelegate(IntPtr PhysicalMemoryHandle, IntPtr pbLinAddr);
[DllImport("inpout.dll", EntryPoint = "MapPhysToLin", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr MapPhysToLin(IntPtr pbPhysAddr, uint dwPhysSize, out IntPtr pPhysicalMemoryHandle);
[DllImport("inpout.dll", EntryPoint = "UnmapPhysicalMemory", CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UnmapPhysicalMemory(IntPtr PhysicalMemoryHandle, IntPtr pbLinAddr);
}

View File

@@ -0,0 +1,96 @@
using System.Runtime.InteropServices;
namespace LibreHardwareMonitor.Interop;
internal static class Ipmi
{
// Ported from ipmiutil
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
internal struct Sdr
{
public ushort recid;
public byte sdrver;
public byte rectype;
public byte reclen;
public byte sens_ownid;
public byte sens_ownlun;
public byte sens_num;
public byte entity_id;
public byte entity_inst;
public byte sens_init;
public byte sens_capab;
public byte sens_type;
public byte ev_type;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)]
public string data1;
public byte sens_units;
public byte sens_base;
public byte sens_mod;
public byte linear;
public byte m;
public byte m_t;
public byte b;
public byte b_a;
public byte a_ax;
public byte rx_bx;
public byte flags;
public byte nom_reading;
public byte norm_max;
public byte norm_min;
public byte sens_max_reading;
public byte sens_min_reading;
public byte unr_threshold;
public byte ucr_threshold;
public byte unc_threshold;
public byte lnr_threshold;
public byte lcr_threshold;
public byte lnc_threshold;
public byte pos_hysteresis;
public byte neg_hysteresis;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)]
public string data3;
public byte id_strlen;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string id_string;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
// 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.
// All Rights Reserved.
using System;
using System.Runtime.InteropServices;
// ReSharper disable InconsistentNaming
namespace LibreHardwareMonitor.Interop;
internal class LibC
{
private const string DllName = "libc";
[DllImport(DllName)]
internal static extern int sched_getaffinity(int pid, IntPtr maskSize, ref ulong mask);
[DllImport(DllName)]
internal static extern int sched_setaffinity(int pid, IntPtr maskSize, ref ulong mask);
}

View File

@@ -0,0 +1,53 @@
// 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.
// All Rights Reserved.
using System.Runtime.InteropServices;
// ReSharper disable InconsistentNaming
namespace LibreHardwareMonitor.Interop;
internal class NtDll
{
private const string DllName = "ntdll.dll";
[StructLayout(LayoutKind.Sequential)]
internal struct SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
{
public long IdleTime;
public long KernelTime;
public long UserTime;
public long DpcTime;
public long InterruptTime;
public uint InterruptCount;
}
[StructLayout(LayoutKind.Sequential)]
internal struct SYSTEM_PROCESSOR_IDLE_INFORMATION
{
public long IdleTime;
public long C1Time;
public long C2Time;
public long C3Time;
public uint C1Transitions;
public uint C2Transitions;
public uint C3Transitions;
public uint Padding;
}
internal enum SYSTEM_INFORMATION_CLASS
{
SystemProcessorPerformanceInformation = 8,
SystemProcessorIdleInformation = 42
}
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern int NtQuerySystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, [Out] SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[] SystemInformation, int SystemInformationLength, out int ReturnLength);
[DllImport(DllName)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern int NtQuerySystemInformation(SYSTEM_INFORMATION_CLASS SystemInformationClass, [Out] SYSTEM_PROCESSOR_IDLE_INFORMATION[] SystemInformation, int SystemInformationLength, out int ReturnLength);
}

View File

@@ -0,0 +1,615 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace LibreHardwareMonitor.Interop;
internal static class NvApi
{
public const int MAX_CLOCKS_PER_GPU = 0x120;
public const int MAX_COOLERS_PER_GPU = 20;
public const int MAX_FAN_CONTROLLER_ITEMS = 32;
public const int MAX_FAN_COOLERS_STATUS_ITEMS = 32;
public const int MAX_GPU_PUBLIC_CLOCKS = 32;
public const int MAX_GPU_UTILIZATIONS = 8;
public const int MAX_MEMORY_VALUES_PER_GPU = 5;
public const int MAX_PHYSICAL_GPUS = 64;
public const int MAX_POWER_TOPOLOGIES = 4;
public const int MAX_THERMAL_SENSORS_PER_GPU = 3;
public const int MAX_USAGES_PER_GPU = 8;
public const int SHORT_STRING_MAX = 64;
public const int THERMAL_SENSOR_RESERVED_COUNT = 8;
public const int THERMAL_SENSOR_TEMPERATURE_COUNT = 32;
private const string DllName = "nvapi.dll";
private const string DllName64 = "nvapi64.dll";
public static readonly NvAPI_EnumNvidiaDisplayHandleDelegate NvAPI_EnumNvidiaDisplayHandle;
public static readonly NvAPI_EnumPhysicalGPUsDelegate NvAPI_EnumPhysicalGPUs;
public static readonly NvAPI_GetDisplayDriverVersionDelegate NvAPI_GetDisplayDriverVersion;
public static readonly NvAPI_GetPhysicalGPUsFromDisplayDelegate NvAPI_GetPhysicalGPUsFromDisplay;
public static readonly NvAPI_GPU_ClientFanCoolersGetControlDelegate NvAPI_GPU_ClientFanCoolersGetControl;
public static readonly NvAPI_GPU_ClientFanCoolersGetStatusDelegate NvAPI_GPU_ClientFanCoolersGetStatus;
public static readonly NvAPI_GPU_ClientFanCoolersSetControlDelegate NvAPI_GPU_ClientFanCoolersSetControl;
public static readonly NvAPI_GPU_ClientPowerTopologyGetStatusDelegate NvAPI_GPU_ClientPowerTopologyGetStatus;
public static readonly NvAPI_GPU_GetAllClockFrequenciesDelegate NvAPI_GPU_GetAllClockFrequencies;
public static readonly NvAPI_GPU_GetAllClocksDelegate NvAPI_GPU_GetAllClocks;
public static readonly NvAPI_GPU_GetBusIdDelegate NvAPI_GPU_GetBusId;
public static readonly NvAPI_GPU_GetCoolerSettingsDelegate NvAPI_GPU_GetCoolerSettings;
public static readonly NvAPI_GPU_GetDynamicPstatesInfoExDelegate NvAPI_GPU_GetDynamicPstatesInfoEx;
public static readonly NvAPI_GPU_GetMemoryInfoDelegate NvAPI_GPU_GetMemoryInfo;
public static readonly NvAPI_GPU_GetPCIIdentifiersDelegate NvAPI_GPU_GetPCIIdentifiers;
public static readonly NvAPI_GPU_GetTachReadingDelegate NvAPI_GPU_GetTachReading;
public static readonly NvAPI_GPU_GetThermalSettingsDelegate NvAPI_GPU_GetThermalSettings;
public static readonly NvAPI_GPU_GetUsagesDelegate NvAPI_GPU_GetUsages;
public static readonly NvAPI_GPU_SetCoolerLevelsDelegate NvAPI_GPU_SetCoolerLevels;
public static readonly NvAPI_GPU_GetThermalSensorsDelegate NvAPI_GPU_ThermalGetSensors;
private static readonly NvAPI_GetInterfaceVersionStringDelegate _nvAPI_GetInterfaceVersionString;
private static readonly NvAPI_GPU_GetFullNameDelegate _nvAPI_GPU_GetFullName;
static NvApi()
{
NvAPI_InitializeDelegate nvApiInitialize;
try
{
if (!DllExists())
return;
GetDelegate(0x0150E828, out nvApiInitialize);
}
catch (Exception e) when (e is DllNotFoundException or ArgumentNullException or EntryPointNotFoundException or BadImageFormatException)
{
return;
}
if (nvApiInitialize() == NvStatus.OK)
{
GetDelegate(0xE3640A56, out NvAPI_GPU_GetThermalSettings);
GetDelegate(0xCEEE8E9F, out _nvAPI_GPU_GetFullName);
GetDelegate(0x9ABDD40D, out NvAPI_EnumNvidiaDisplayHandle);
GetDelegate(0x34EF9506, out NvAPI_GetPhysicalGPUsFromDisplay);
GetDelegate(0xE5AC921F, out NvAPI_EnumPhysicalGPUs);
GetDelegate(0x5F608315, out NvAPI_GPU_GetTachReading);
GetDelegate(0x1BD69F49, out NvAPI_GPU_GetAllClocks);
GetDelegate(0x60DED2ED, out NvAPI_GPU_GetDynamicPstatesInfoEx);
GetDelegate(0x189A1FDF, out NvAPI_GPU_GetUsages);
GetDelegate(0xDA141340, out NvAPI_GPU_GetCoolerSettings);
GetDelegate(0x891FA0AE, out NvAPI_GPU_SetCoolerLevels);
GetDelegate(0x774AA982, out NvAPI_GPU_GetMemoryInfo);
GetDelegate(0xF951A4D1, out NvAPI_GetDisplayDriverVersion);
GetDelegate(0x01053FA5, out _nvAPI_GetInterfaceVersionString);
GetDelegate(0x2DDFB66E, out NvAPI_GPU_GetPCIIdentifiers);
GetDelegate(0x1BE0B8E5, out NvAPI_GPU_GetBusId);
GetDelegate(0x35AED5E8, out NvAPI_GPU_ClientFanCoolersGetStatus);
GetDelegate(0xDCB616C3, out NvAPI_GPU_GetAllClockFrequencies);
GetDelegate(0x814B209F, out NvAPI_GPU_ClientFanCoolersGetControl);
GetDelegate(0xA58971A5, out NvAPI_GPU_ClientFanCoolersSetControl);
GetDelegate(0x0EDCF624E, out NvAPI_GPU_ClientPowerTopologyGetStatus);
GetDelegate(0x65FE3AAD, out NvAPI_GPU_ThermalGetSensors);
IsAvailable = true;
}
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_EnumNvidiaDisplayHandleDelegate(int thisEnum, ref NvDisplayHandle displayHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_EnumPhysicalGPUsDelegate([Out] NvPhysicalGpuHandle[] gpuHandles, out int gpuCount);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GetDisplayDriverVersionDelegate(NvDisplayHandle displayHandle, [In, Out] ref NvDisplayDriverVersion nvDisplayDriverVersion);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GetInterfaceVersionStringDelegate(StringBuilder version);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GetPhysicalGPUsFromDisplayDelegate(NvDisplayHandle displayHandle, [Out] NvPhysicalGpuHandle[] gpuHandles, out uint gpuCount);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_ClientFanCoolersGetControlDelegate(NvPhysicalGpuHandle gpuHandle, ref NvFanCoolerControl control);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_ClientFanCoolersGetStatusDelegate(NvPhysicalGpuHandle gpuHandle, ref NvFanCoolersStatus fanCoolersStatus);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_ClientFanCoolersSetControlDelegate(NvPhysicalGpuHandle gpuHandle, ref NvFanCoolerControl control);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_ClientPowerTopologyGetStatusDelegate(NvPhysicalGpuHandle gpuHandle, ref NvPowerTopology powerTopology);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetAllClockFrequenciesDelegate(NvPhysicalGpuHandle gpuHandle, ref NvGpuClockFrequencies clockFrequencies);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetAllClocksDelegate(NvPhysicalGpuHandle gpuHandle, ref NvClocks nvClocks);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetBusIdDelegate(NvPhysicalGpuHandle gpuHandle, out uint busId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetCoolerSettingsDelegate(NvPhysicalGpuHandle gpuHandle, NvCoolerTarget coolerTarget, ref NvCoolerSettings NvCoolerSettings);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetDynamicPstatesInfoExDelegate(NvPhysicalGpuHandle gpuHandle, ref NvDynamicPStatesInfo nvPStates);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetMemoryInfoDelegate(NvDisplayHandle displayHandle, ref NvMemoryInfo nvMemoryInfo);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetPCIIdentifiersDelegate(NvPhysicalGpuHandle gpuHandle, out uint deviceId, out uint subSystemId, out uint revisionId, out uint extDeviceId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetTachReadingDelegate(NvPhysicalGpuHandle gpuHandle, out int value);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetThermalSensorsDelegate(NvPhysicalGpuHandle gpuHandle, ref NvThermalSensors nvThermalSensors);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetThermalSettingsDelegate(NvPhysicalGpuHandle gpuHandle, int sensorIndex, ref NvThermalSettings NvThermalSettings);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_GetUsagesDelegate(NvPhysicalGpuHandle gpuHandle, ref NvUsages nvUsages);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NvStatus NvAPI_GPU_SetCoolerLevelsDelegate(NvPhysicalGpuHandle gpuHandle, int coolerIndex, ref NvCoolerLevels NvCoolerLevels);
public enum NvFanControlMode : uint
{
Auto = 0,
Manual = 1
}
public enum NvLevelPolicy : uint
{
None = 0,
Manual = 1,
Performance = 2,
TemperatureDiscrete = 4,
TemperatureContinuous = 8,
Silent = 16,
Auto = 32
}
public enum NvPowerTopologyDomain : uint
{
Gpu = 0,
Board
}
public enum NvUtilizationDomain
{
Gpu, // Core
FrameBuffer, // Memory Controller
VideoEngine, // Video Engine
BusInterface // Bus
}
public static bool IsAvailable { get; }
[DllImport(DllName, EntryPoint = "nvapi_QueryInterface", CallingConvention = CallingConvention.Cdecl, PreserveSig = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
private static extern IntPtr NvAPI32_QueryInterface(uint interfaceId);
[DllImport(DllName64, EntryPoint = "nvapi_QueryInterface", CallingConvention = CallingConvention.Cdecl, PreserveSig = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
private static extern IntPtr NvAPI64_QueryInterface(uint interfaceId);
public static NvStatus NvAPI_GPU_GetFullName(NvPhysicalGpuHandle gpuHandle, out string name)
{
StringBuilder builder = new(SHORT_STRING_MAX);
NvStatus status = _nvAPI_GPU_GetFullName?.Invoke(gpuHandle, builder) ?? NvStatus.FunctionNotFound;
name = builder.ToString();
return status;
}
public static NvStatus NvAPI_GetInterfaceVersionString(out string version)
{
StringBuilder builder = new(SHORT_STRING_MAX);
NvStatus status = _nvAPI_GetInterfaceVersionString?.Invoke(builder) ?? NvStatus.FunctionNotFound;
version = builder.ToString();
return status;
}
private static void GetDelegate<T>(uint id, out T newDelegate) where T : class
{
IntPtr ptr = Environment.Is64BitProcess ? NvAPI64_QueryInterface(id) : NvAPI32_QueryInterface(id);
if (ptr != IntPtr.Zero)
newDelegate = Marshal.GetDelegateForFunctionPointer(ptr, typeof(T)) as T;
else
newDelegate = null;
}
public static bool DllExists()
{
IntPtr module = Kernel32.LoadLibrary(Environment.Is64BitProcess ? DllName64 : DllName);
if (module == IntPtr.Zero)
return false;
Kernel32.FreeLibrary(module);
return true;
}
internal static int MAKE_NVAPI_VERSION<T>(int ver)
{
return Marshal.SizeOf<T>() | (ver << 16);
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvFanCoolerControl
{
public uint Version;
private readonly uint _reserved;
public uint Count;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8, ArraySubType = UnmanagedType.U4)]
private readonly uint[] _reserved2;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_FAN_CONTROLLER_ITEMS)]
public NvFanCoolerControlItem[] Items;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvFanCoolerControlItem
{
public uint CoolerId;
public uint Level;
public NvFanControlMode ControlMode;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8, ArraySubType = UnmanagedType.U4)]
private readonly uint[] _reserved;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvPowerTopology
{
public int Version;
public uint Count;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_POWER_TOPOLOGIES, ArraySubType = UnmanagedType.Struct)]
public NvPowerTopologyEntry[] Entries;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvPowerTopologyEntry
{
public NvPowerTopologyDomain Domain;
private readonly uint _reserved;
public uint PowerUsage;
private readonly uint _reserved1;
}
internal enum NvStatus
{
OK = 0,
Error = -1,
LibraryNotFound = -2,
NoImplementation = -3,
ApiNotInitialized = -4,
InvalidArgument = -5,
NvidiaDeviceNotFound = -6,
EndEnumeration = -7,
InvalidHandle = -8,
IncompatibleStructVersion = -9,
HandleInvalidated = -10,
OpenGlContextNotCurrent = -11,
NoGlExpert = -12,
InstrumentationDisabled = -13,
ExpectedLogicalGpuHandle = -100,
ExpectedPhysicalGpuHandle = -101,
ExpectedDisplayHandle = -102,
InvalidCombination = -103,
NotSupported = -104,
PortIdNotFound = -105,
ExpectedUnattachedDisplayHandle = -106,
InvalidPerfLevel = -107,
DeviceBusy = -108,
NvPersistFileNotFound = -109,
PersistDataNotFound = -110,
ExpectedTvDisplay = -111,
ExpectedTvDisplayOnConnector = -112,
NoActiveSliTopology = -113,
SliRenderingModeNotAllowed = -114,
ExpectedDigitalFlatPanel = -115,
ArgumentExceedMaxSize = -116,
DeviceSwitchingNotAllowed = -117,
TestingClocksNotSupported = -118,
UnknownUnderscanConfig = -119,
TimeoutReconfiguringGpuTopo = -120,
DataNotFound = -121,
ExpectedAnalogDisplay = -122,
NoVidLink = -123,
RequiresReboot = -124,
InvalidHybridMode = -125,
MixedTargetTypes = -126,
Syswow64NotSupported = -127,
ImplicitSetGpuTopologyChangeNotAllowed = -128,
RequestUserToCloseNonMigratableApps = -129,
OutOfMemory = -130,
WasStillDrawing = -131,
FileNotFound = -132,
TooManyUniqueStateObjects = -133,
InvalidCall = -134,
D3D101LibraryNotFound = -135,
FunctionNotFound = -136
}
internal enum NvThermalController
{
None = 0,
GpuInternal,
Adm1032,
Max6649,
Max1617,
Lm99,
Lm89,
Lm64,
Adt7473,
SbMax6649,
VBiosEvt,
OS,
Unknown = -1
}
internal enum NvThermalTarget
{
None = 0,
Gpu = 1,
Memory = 2,
PowerSupply = 4,
Board = 8,
VisualComputingBoard = 9,
VisualComputingInlet = 10,
VisualComputingOutlet = 11,
All = 15,
Unknown = -1
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvSensor
{
public NvThermalController Controller;
public uint DefaultMinTemp;
public uint DefaultMaxTemp;
public uint CurrentTemp;
public NvThermalTarget Target;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvThermalSettings
{
public uint Version;
public uint Count;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_THERMAL_SENSORS_PER_GPU)]
public NvSensor[] Sensor;
}
[StructLayout(LayoutKind.Sequential)]
internal struct NvDisplayHandle
{
private readonly IntPtr ptr;
}
[StructLayout(LayoutKind.Sequential)]
internal struct NvPhysicalGpuHandle
{
private readonly IntPtr ptr;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvClocks
{
public uint Version;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_CLOCKS_PER_GPU)]
public uint[] Clock;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvDynamicPStatesInfo
{
public uint Version;
public uint Flags;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_GPU_UTILIZATIONS)]
public NvDynamicPState[] Utilizations;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvDynamicPState
{
public bool IsPresent;
public int Percentage;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvUsages
{
public uint Version;
private readonly uint _reserved;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public NvUsagesEntry[] Entries;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvUsagesEntry
{
public uint IsPresent;
public uint Percentage;
private readonly uint _reserved1;
private readonly uint _reserved2;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvCooler
{
public int Type;
public int Controller;
public int DefaultMin;
public int DefaultMax;
public int CurrentMin;
public int CurrentMax;
public int CurrentLevel;
public int DefaultPolicy;
public int CurrentPolicy;
public int Target;
public int ControlType;
public int Active;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvFanCoolersStatus
{
public uint Version;
public uint Count;
public ulong Reserved1;
public ulong Reserved2;
public ulong Reserved3;
public ulong Reserved4;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_FAN_COOLERS_STATUS_ITEMS)]
internal NvFanCoolersStatusItem[] Items;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvFanCoolersStatusItem
{
public uint CoolerId;
public uint CurrentRpm;
public uint CurrentMinLevel;
public uint CurrentMaxLevel;
public uint CurrentLevel;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8, ArraySubType = UnmanagedType.U4)]
private readonly uint[] _reserved;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvCoolerSettings
{
public uint Version;
public uint Count;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_COOLERS_PER_GPU)]
public NvCooler[] Cooler;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvLevel
{
public int Level;
public NvLevelPolicy Policy;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvCoolerLevels
{
public uint Version;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_COOLERS_PER_GPU)]
public NvLevel[] Levels;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct NvThermalSensors
{
internal uint Version;
internal uint Mask;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = THERMAL_SENSOR_RESERVED_COUNT)]
internal int[] Reserved;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = THERMAL_SENSOR_TEMPERATURE_COUNT)]
internal int[] Temperatures;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvMemoryInfo
{
public uint Version;
public uint DedicatedVideoMemory;
public uint AvailableDedicatedVideoMemory;
public uint SystemVideoMemory;
public uint SharedSystemMemory;
public uint CurrentAvailableDedicatedVideoMemory;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvDisplayDriverVersion
{
public uint Version;
public uint DriverVersion;
public uint BldChangeListNum;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = SHORT_STRING_MAX)]
public string BuildBranch;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = SHORT_STRING_MAX)]
public string Adapter;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvGpuClockFrequencies
{
public uint Version;
private readonly uint _reserved;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_GPU_PUBLIC_CLOCKS)]
public NvGpuClockFrequenciesDomain[] Clocks;
}
internal enum NvGpuPublicClockId
{
Graphics = 0,
Memory = 4,
Processor = 7,
Video = 8,
Undefined = MAX_CLOCKS_PER_GPU
}
internal enum NvGpuClockFrequenciesClockType
{
CurrentFrequency,
BaseClock,
BoostClock,
ClockTypeNumber
}
internal enum NvCoolerTarget
{
None = 0,
Gpu,
Memory,
PowerSupply = 4,
All = 7 // This cooler cools all of the components related to its target gpu.
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
internal struct NvGpuClockFrequenciesDomain
{
private readonly uint _isPresent;
public uint Frequency;
public bool IsPresent => (_isPresent & 1) != 0;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate NvStatus NvAPI_InitializeDelegate();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate NvStatus NvAPI_GPU_GetFullNameDelegate(NvPhysicalGpuHandle gpuHandle, StringBuilder name);
}

View File

@@ -0,0 +1,477 @@
// 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.
// All Rights Reserved.
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace LibreHardwareMonitor.Interop;
internal static class NvidiaML
{
private const string LinuxDllName = "nvidia-ml";
private const string WindowsDllName = "nvml.dll";
private static readonly object _syncRoot = new();
private static IntPtr _windowsDll;
private static WindowsNvmlGetHandleDelegate _windowsNvmlDeviceGetHandleByIndex;
private static WindowsNvmlGetHandleByPciBusIdDelegate _windowsNvmlDeviceGetHandleByPciBusId;
private static WindowsNvmlDeviceGetPcieThroughputDelegate _windowsNvmlDeviceGetPcieThroughputDelegate;
private static WindowsNvmlDeviceGetPciInfo _windowsNvmlDeviceGetPciInfo;
private static WindowsNvmlGetPowerUsageDelegate _windowsNvmlDeviceGetPowerUsage;
private static WindowsNvmlDelegate _windowsNvmlInit;
private static WindowsNvmlDelegate _windowsNvmlShutdown;
public enum NvmlPcieUtilCounter
{
TxBytes = 0,
RxBytes = 1
}
public enum NvmlReturn
{
/// <summary>
/// The operation was successful
/// </summary>
Success = 0,
/// <summary>
/// NvidiaML was not first initialized with nvmlInit()
/// </summary>
Uninitialized = 1,
/// <summary>
/// A supplied argument is invalid
/// </summary>
InvalidArgument = 2,
/// <summary>
/// The requested operation is not available on target device
/// </summary>
NotSupported = 3,
/// <summary>
/// The current user does not have permission for operation
/// </summary>
NoPermission = 4,
/// <summary>
/// A query to find an object was unsuccessful
/// </summary>
NotFound = 6,
/// <summary>
/// An input argument is not large enough
/// </summary>
InsufficientSize = 7,
/// <summary>
/// A device's external power cables are not properly attached
/// </summary>
InsufficientPower = 8,
/// <summary>
/// NVIDIA driver is not loaded
/// </summary>
DriverNotLoaded = 9,
/// <summary>
/// User provided timeout passed
/// </summary>
TimeOut = 10,
/// <summary>
/// NVIDIA Kernel detected an interrupt issue with a GPU
/// </summary>
IRQIssue = 11,
/// <summary>
/// NvidiaML Shared Library couldn't be found or loaded
/// </summary>
LibraryNotFound = 12,
/// <summary>
/// Local version of NvidiaML doesn't implement this function
/// </summary>
FunctionNotFound = 13,
/// <summary>
/// infoROM is corrupted
/// </summary>
CorruptedInfoRom = 14,
/// <summary>
/// The GPU has fallen off the bus or has otherwise become inaccessible
/// </summary>
GpuIsLost = 15,
/// <summary>
/// The GPU requires a reset before it can be used again
/// </summary>
ResetRequired = 16,
/// <summary>
/// The GPU control device has been blocked by the operating system/cgroups
/// </summary>
OperatingSystem = 17,
/// <summary>
/// RM detects a driver/library version mismatch
/// </summary>
LibRmVersionMismatch = 18,
/// <summary>
/// An operation cannot be performed because the GPU is currently in use
/// </summary>
InUse = 19,
/// <summary>
/// An public driver error occurred
/// </summary>
Unknown = 999
}
public static bool IsAvailable { get; private set; }
public static bool Initialize()
{
lock (_syncRoot)
{
if (IsAvailable)
{
return true;
}
if (Software.OperatingSystem.IsUnix)
{
try
{
IsAvailable = nvmlInit() == NvmlReturn.Success;
}
catch (DllNotFoundException)
{ }
catch (EntryPointNotFoundException)
{
try
{
IsAvailable = nvmlInitLegacy() == NvmlReturn.Success;
}
catch (EntryPointNotFoundException)
{ }
}
}
else if (IsNvmlCompatibleWindowsVersion())
{
// Attempt to load the Nvidia Management Library from the
// windows standard search order for applications. This will
// help installations that either have the library in
// %windir%/system32 or provide their own library
_windowsDll = Kernel32.LoadLibrary(WindowsDllName);
// If there is no dll in the path, then attempt to load it
// from program files
if (_windowsDll == IntPtr.Zero)
{
string programFilesDirectory = Environment.ExpandEnvironmentVariables("%ProgramW6432%");
string dllPath = Path.Combine(programFilesDirectory, @"NVIDIA Corporation\NVSMI", WindowsDllName);
_windowsDll = Kernel32.LoadLibrary(dllPath);
}
IsAvailable = (_windowsDll != IntPtr.Zero) && InitialiseDelegates() && (_windowsNvmlInit() == NvmlReturn.Success);
}
return IsAvailable;
}
}
private static bool IsNvmlCompatibleWindowsVersion()
{
return Software.OperatingSystem.Is64Bit && ((Environment.OSVersion.Version.Major > 6) || (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor >= 1));
}
private static bool InitialiseDelegates()
{
IntPtr nvmlInit = Kernel32.GetProcAddress(_windowsDll, "nvmlInit_v2");
if (nvmlInit != IntPtr.Zero)
{
_windowsNvmlInit = (WindowsNvmlDelegate)Marshal.GetDelegateForFunctionPointer(nvmlInit, typeof(WindowsNvmlDelegate));
}
else
{
nvmlInit = Kernel32.GetProcAddress(_windowsDll, "nvmlInit");
if (nvmlInit != IntPtr.Zero)
_windowsNvmlInit = (WindowsNvmlDelegate)Marshal.GetDelegateForFunctionPointer(nvmlInit, typeof(WindowsNvmlDelegate));
else
return false;
}
IntPtr nvmlShutdown = Kernel32.GetProcAddress(_windowsDll, "nvmlShutdown");
if (nvmlShutdown != IntPtr.Zero)
_windowsNvmlShutdown = (WindowsNvmlDelegate)Marshal.GetDelegateForFunctionPointer(nvmlShutdown, typeof(WindowsNvmlDelegate));
else
return false;
IntPtr nvmlGetHandle = Kernel32.GetProcAddress(_windowsDll, "nvmlDeviceGetHandleByIndex_v2");
if (nvmlGetHandle != IntPtr.Zero)
_windowsNvmlDeviceGetHandleByIndex = (WindowsNvmlGetHandleDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetHandle, typeof(WindowsNvmlGetHandleDelegate));
else
{
nvmlGetHandle = Kernel32.GetProcAddress(_windowsDll, "nvmlDeviceGetHandleByIndex");
if (nvmlGetHandle != IntPtr.Zero)
_windowsNvmlDeviceGetHandleByIndex = (WindowsNvmlGetHandleDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetHandle, typeof(WindowsNvmlGetHandleDelegate));
else
return false;
}
IntPtr nvmlGetPowerUsage = Kernel32.GetProcAddress(_windowsDll, "nvmlDeviceGetPowerUsage");
if (nvmlGetPowerUsage != IntPtr.Zero)
_windowsNvmlDeviceGetPowerUsage = (WindowsNvmlGetPowerUsageDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetPowerUsage, typeof(WindowsNvmlGetPowerUsageDelegate));
else
return false;
IntPtr nvmlGetPcieThroughput = Kernel32.GetProcAddress(_windowsDll, "nvmlDeviceGetPcieThroughput");
if (nvmlGetPcieThroughput != IntPtr.Zero)
_windowsNvmlDeviceGetPcieThroughputDelegate = (WindowsNvmlDeviceGetPcieThroughputDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetPcieThroughput, typeof(WindowsNvmlDeviceGetPcieThroughputDelegate));
else
return false;
IntPtr nvmlGetHandlePciBus = Kernel32.GetProcAddress(_windowsDll, "nvmlDeviceGetHandleByPciBusId_v2");
if (nvmlGetHandlePciBus != IntPtr.Zero)
_windowsNvmlDeviceGetHandleByPciBusId = (WindowsNvmlGetHandleByPciBusIdDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetHandlePciBus, typeof(WindowsNvmlGetHandleByPciBusIdDelegate));
else
return false;
IntPtr nvmlDeviceGetPciInfo = Kernel32.GetProcAddress(_windowsDll, "nvmlDeviceGetPciInfo_v2");
if (nvmlDeviceGetPciInfo != IntPtr.Zero)
_windowsNvmlDeviceGetPciInfo = (WindowsNvmlDeviceGetPciInfo)Marshal.GetDelegateForFunctionPointer(nvmlDeviceGetPciInfo, typeof(WindowsNvmlDeviceGetPciInfo));
else
return false;
return true;
}
public static void Close()
{
lock (_syncRoot)
{
if (IsAvailable)
{
if (Software.OperatingSystem.IsUnix)
{
nvmlShutdown();
}
else if (_windowsDll != IntPtr.Zero)
{
_windowsNvmlShutdown();
Kernel32.FreeLibrary(_windowsDll);
}
IsAvailable = false;
}
}
}
public static NvmlDevice? NvmlDeviceGetHandleByIndex(int index)
{
if (IsAvailable)
{
NvmlDevice nvmlDevice;
if (Software.OperatingSystem.IsUnix)
{
try
{
if (nvmlDeviceGetHandleByIndex(index, out nvmlDevice) == NvmlReturn.Success)
return nvmlDevice;
}
catch (EntryPointNotFoundException)
{
if (nvmlDeviceGetHandleByIndexLegacy(index, out nvmlDevice) == NvmlReturn.Success)
return nvmlDevice;
}
}
else
{
try
{
if (_windowsNvmlDeviceGetHandleByIndex(index, out nvmlDevice) == NvmlReturn.Success)
return nvmlDevice;
}
catch { }
}
}
return null;
}
public static NvmlDevice? NvmlDeviceGetHandleByPciBusId(string pciBusId)
{
if (IsAvailable)
{
NvmlDevice nvmlDevice;
if (Software.OperatingSystem.IsUnix)
{
if (nvmlDeviceGetHandleByPciBusId(pciBusId, out nvmlDevice) == NvmlReturn.Success)
return nvmlDevice;
}
else
{
try
{
if (_windowsNvmlDeviceGetHandleByPciBusId(pciBusId, out nvmlDevice) == NvmlReturn.Success)
return nvmlDevice;
}
catch { }
}
}
return null;
}
public static int? NvmlDeviceGetPowerUsage(NvmlDevice nvmlDevice)
{
if (IsAvailable)
{
int powerUsage;
if (Software.OperatingSystem.IsUnix)
{
if (nvmlDeviceGetPowerUsage(nvmlDevice, out powerUsage) == NvmlReturn.Success)
return powerUsage;
}
else
{
try
{
if (_windowsNvmlDeviceGetPowerUsage(nvmlDevice, out powerUsage) == NvmlReturn.Success)
return powerUsage;
}
catch { }
}
}
return null;
}
public static uint? NvmlDeviceGetPcieThroughput(NvmlDevice nvmlDevice, NvmlPcieUtilCounter counter)
{
if (IsAvailable)
{
uint pcieThroughput;
if (Software.OperatingSystem.IsUnix)
{
if (nvmlDeviceGetPcieThroughput(nvmlDevice, counter, out pcieThroughput) == NvmlReturn.Success)
return pcieThroughput;
}
else
{
try
{
if (_windowsNvmlDeviceGetPcieThroughputDelegate(nvmlDevice, counter, out pcieThroughput) == NvmlReturn.Success)
return pcieThroughput;
}
catch { }
}
}
return null;
}
public static NvmlPciInfo? NvmlDeviceGetPciInfo(NvmlDevice nvmlDevice)
{
if (IsAvailable)
{
var pci = new NvmlPciInfo();
if (Software.OperatingSystem.IsUnix)
{
if (nvmlDeviceGetPciInfo(nvmlDevice, ref pci) == NvmlReturn.Success)
return pci;
}
else
{
try
{
if (_windowsNvmlDeviceGetPciInfo(nvmlDevice, ref pci) == NvmlReturn.Success)
return pci;
}
catch { }
}
}
return null;
}
[DllImport(LinuxDllName, EntryPoint = "nvmlInit_v2", ExactSpelling = true)]
private static extern NvmlReturn nvmlInit();
[DllImport(LinuxDllName, EntryPoint = "nvmlInit", ExactSpelling = true)]
private static extern NvmlReturn nvmlInitLegacy();
[DllImport(LinuxDllName, EntryPoint = "nvmlShutdown", ExactSpelling = true)]
private static extern NvmlReturn nvmlShutdown();
[DllImport(LinuxDllName, EntryPoint = "nvmlDeviceGetHandleByIndex_v2", ExactSpelling = true)]
private static extern NvmlReturn nvmlDeviceGetHandleByIndex(int index, out NvmlDevice device);
[DllImport(LinuxDllName, EntryPoint = "nvmlDeviceGetHandleByPciBusId_v2", ExactSpelling = true)]
private static extern NvmlReturn nvmlDeviceGetHandleByPciBusId([MarshalAs(UnmanagedType.LPStr)] string pciBusId, out NvmlDevice device);
[DllImport(LinuxDllName, EntryPoint = "nvmlDeviceGetHandleByIndex", ExactSpelling = true)]
private static extern NvmlReturn nvmlDeviceGetHandleByIndexLegacy(int index, out NvmlDevice device);
[DllImport(LinuxDllName, EntryPoint = "nvmlDeviceGetPowerUsage", ExactSpelling = true)]
private static extern NvmlReturn nvmlDeviceGetPowerUsage(NvmlDevice device, out int power);
[DllImport(LinuxDllName, EntryPoint = "nvmlDeviceGetPcieThroughput", ExactSpelling = true)]
private static extern NvmlReturn nvmlDeviceGetPcieThroughput(NvmlDevice device, NvmlPcieUtilCounter counter, out uint value);
[DllImport(LinuxDllName, EntryPoint = "nvmlDeviceGetPciInfo_v2")]
private static extern NvmlReturn nvmlDeviceGetPciInfo(NvmlDevice device, ref NvmlPciInfo pci);
private delegate NvmlReturn WindowsNvmlDelegate();
private delegate NvmlReturn WindowsNvmlGetHandleDelegate(int index, out NvmlDevice device);
private delegate NvmlReturn WindowsNvmlGetHandleByPciBusIdDelegate([MarshalAs(UnmanagedType.LPStr)] string pciBusId, out NvmlDevice device);
private delegate NvmlReturn WindowsNvmlGetPowerUsageDelegate(NvmlDevice device, out int power);
private delegate NvmlReturn WindowsNvmlDeviceGetPcieThroughputDelegate(NvmlDevice device, NvmlPcieUtilCounter counter, out uint value);
private delegate NvmlReturn WindowsNvmlDeviceGetPciInfo(NvmlDevice device, ref NvmlPciInfo pci);
[StructLayout(LayoutKind.Sequential)]
public struct NvmlDevice
{
public IntPtr Handle;
}
[StructLayout(LayoutKind.Sequential)]
public struct NvmlPciInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string busId;
public uint domain;
public uint bus;
public uint device;
public ushort pciVendorId;
public ushort pciDeviceId;
public uint pciSubSystemId;
public uint reserved0;
public uint reserved1;
public uint reserved2;
public uint reserved3;
}
}

View File

@@ -0,0 +1,28 @@
// 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.
// All Rights Reserved.
// ReSharper disable InconsistentNaming
// ReSharper disable IdentifierTypo
namespace LibreHardwareMonitor.Interop;
/// <summary>
/// Driver with access at kernel level.
/// </summary>
internal static class Ring0
{
public const uint INVALID_PCI_ADDRESS = 0xFFFFFFFF;
private const uint OLS_TYPE = 40000;
public static readonly Kernel32.IOControlCode IOCTL_OLS_GET_REFCOUNT = new(OLS_TYPE, 0x801, Kernel32.IOControlCode.Access.Any);
public static readonly Kernel32.IOControlCode IOCTL_OLS_READ_MSR = new(OLS_TYPE, 0x821, Kernel32.IOControlCode.Access.Any);
public static readonly Kernel32.IOControlCode IOCTL_OLS_WRITE_MSR = new(OLS_TYPE, 0x822, Kernel32.IOControlCode.Access.Any);
public static readonly Kernel32.IOControlCode IOCTL_OLS_READ_IO_PORT_BYTE = new(OLS_TYPE, 0x833, Kernel32.IOControlCode.Access.Read);
public static readonly Kernel32.IOControlCode IOCTL_OLS_WRITE_IO_PORT_BYTE = new(OLS_TYPE, 0x836, Kernel32.IOControlCode.Access.Write);
public static readonly Kernel32.IOControlCode IOCTL_OLS_READ_PCI_CONFIG = new(OLS_TYPE, 0x851, Kernel32.IOControlCode.Access.Read);
public static readonly Kernel32.IOControlCode IOCTL_OLS_WRITE_PCI_CONFIG = new(OLS_TYPE, 0x852, Kernel32.IOControlCode.Access.Write);
public static readonly Kernel32.IOControlCode IOCTL_OLS_READ_MEMORY = new(OLS_TYPE, 0x841, Kernel32.IOControlCode.Access.Read);
}

View File

@@ -0,0 +1,57 @@
// 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.
// All Rights Reserved.
using System;
using System.Runtime.InteropServices;
namespace LibreHardwareMonitor.Interop;
internal class SetupApi
{
internal const int DIGCF_DEVICEINTERFACE = 0x00000010;
internal const int DIGCF_PRESENT = 0x00000002;
internal const int ERROR_INSUFFICIENT_BUFFER = 122;
internal const int ERROR_NO_MORE_ITEMS = 259;
private const string DllName = "SetupAPI.dll";
internal static Guid GUID_DEVICE_BATTERY = new(0x72631e54, 0x78A4, 0x11d0, 0xbc, 0xf7, 0x00, 0xaa, 0x00, 0xb7, 0xb3, 0x2a);
internal static readonly IntPtr INVALID_HANDLE_VALUE = new(-1);
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern IntPtr SetupDiGetClassDevs(ref Guid ClassGuid, IntPtr Enumerator, IntPtr hwndParent, uint Flags);
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SetupDiEnumDeviceInterfaces
(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, ref Guid InterfaceClassGuid, uint MemberIndex, ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData);
[DllImport(DllName, SetLastError = true, EntryPoint = "SetupDiGetDeviceInterfaceDetailW", CharSet = CharSet.Unicode)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SetupDiGetDeviceInterfaceDetail
(
IntPtr DeviceInfoSet,
in SP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
[Out, Optional] IntPtr DeviceInterfaceDetailData,
uint DeviceInterfaceDetailDataSize,
out uint RequiredSize,
IntPtr DeviceInfoData = default);
[DllImport(DllName, CallingConvention = CallingConvention.Winapi, SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SetupDiDestroyDeviceInfoList(IntPtr DeviceInfoSet);
[StructLayout(LayoutKind.Sequential)]
internal struct SP_DEVICE_INTERFACE_DATA
{
public uint cbSize;
public Guid InterfaceClassGuid;
public uint Flags;
public IntPtr Reserved;
}
}

View File

@@ -0,0 +1,45 @@
// 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.
// All Rights Reserved.
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
using System.Runtime.InteropServices;
namespace LibreHardwareMonitor.Interop;
/// <summary>
/// Contains Win32 definitions for Windows NT.
/// </summary>
internal static class WinNt
{
internal const int STATUS_SUCCESS = 0;
/// <summary>
/// Describes a local identifier for an adapter.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct LUID
{
public readonly uint LowPart;
public readonly int HighPart;
}
/// <summary>
/// Represents a 64-bit signed integer value.
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 8)]
internal struct LARGE_INTEGER
{
[FieldOffset(0)]
public long QuadPart;
[FieldOffset(0)]
public uint LowPart;
[FieldOffset(4)]
public int HighPart;
}
}