diff --git a/Controllers/NVIDIAIlluminationController/NVIDIAIlluminationControllerDetect_Windows.cpp b/Controllers/NVIDIAIlluminationController/NVIDIAIlluminationControllerDetect_Windows_Linux.cpp similarity index 98% rename from Controllers/NVIDIAIlluminationController/NVIDIAIlluminationControllerDetect_Windows.cpp rename to Controllers/NVIDIAIlluminationController/NVIDIAIlluminationControllerDetect_Windows_Linux.cpp index 827e516f..c9c60abd 100644 --- a/Controllers/NVIDIAIlluminationController/NVIDIAIlluminationControllerDetect_Windows.cpp +++ b/Controllers/NVIDIAIlluminationController/NVIDIAIlluminationControllerDetect_Windows_Linux.cpp @@ -1,5 +1,5 @@ /*---------------------------------------------------------*\ -| NVIDIAIlluminationControllerDetect_Windows.cpp | +| NVIDIAIlluminationControllerDetect_Windows_Linux.cpp | | | | Detector for NVIDIA Illumination GPU | | | @@ -15,7 +15,7 @@ #include "Detector.h" #include "LogManager.h" #include "RGBController.h" -#include "RGBController_NVIDIAIllumination_Windows.h" +#include "RGBController_NVIDIAIllumination_Windows_Linux.h" #include "pci_ids.h" enum @@ -32,7 +32,7 @@ typedef struct int gpu_rgb_version; bool treats_rgbw_as_rgb; const char * name; -} gpu_pci_device; +} nv_gpu_pci_device; #define GPU_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[ 0 ])) @@ -44,7 +44,7 @@ typedef struct #define TREATS_RGBW_AS_RGB true #define TREATS_RGBW_AS_RGBW false -static const gpu_pci_device device_list[] = +static const nv_gpu_pci_device device_list[] = { {NVIDIA_VEN, NVIDIA_RTX2070S_DEV, NVIDIA_VEN, NVIDIA_RTX2070_FE_SUPER_SUB_DEV, NVIDIA_ILLUMINATION_V1, TREATS_RGBW_AS_RGBW, "NVIDIA RTX 2070 SUPER FE" }, {NVIDIA_VEN, NVIDIA_RTX2080_A_DEV, NVIDIA_VEN, NVIDIA_RTX2080_FE_SUB_DEV, NVIDIA_ILLUMINATION_V1, TREATS_RGBW_AS_RGBW, "NVIDIA RTX 2080 FE" }, diff --git a/Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller_Windows.cpp b/Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller_Windows_Linux.cpp similarity index 98% rename from Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller_Windows.cpp rename to Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller_Windows_Linux.cpp index b85307b8..57a08629 100644 --- a/Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller_Windows.cpp +++ b/Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller_Windows_Linux.cpp @@ -1,5 +1,5 @@ /*---------------------------------------------------------*\ -| NVIDIAIlluminationV1Controller_Windows.cpp | +| NVIDIAIlluminationV1Controller_Windows_Linux.cpp | | | | Driver for NVIDIA Illumination V1 GPU | | | @@ -9,7 +9,7 @@ | SPDX-License-Identifier: GPL-2.0-only | \*---------------------------------------------------------*/ -#include "NVIDIAIlluminationV1Controller_Windows.h" +#include "NVIDIAIlluminationV1Controller_Windows_Linux.h" NVIDIAIlluminationV1Controller::NVIDIAIlluminationV1Controller(nvapi_accessor* nvapi_ptr, bool treats_rgbw_as_rgb) { diff --git a/Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller_Windows.h b/Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller_Windows_Linux.h similarity index 94% rename from Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller_Windows.h rename to Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller_Windows_Linux.h index 08635f9a..389c80f9 100644 --- a/Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller_Windows.h +++ b/Controllers/NVIDIAIlluminationController/NVIDIAIlluminationV1Controller_Windows_Linux.h @@ -1,5 +1,5 @@ /*---------------------------------------------------------*\ -| NVIDIAIlluminationV1Controller_Windows.h | +| NVIDIAIlluminationV1Controller_Windows_Linux.h | | | | Driver for NVIDIA Illumination V1 GPU | | | @@ -14,7 +14,7 @@ #include #include #include -#include "nvapi_accessor_Windows.h" +#include "nvapi_accessor_Windows_Linux.h" #include "RGBController.h" #include "LogManager.h" diff --git a/Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination_Windows.cpp b/Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination_Windows_Linux.cpp similarity index 98% rename from Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination_Windows.cpp rename to Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination_Windows_Linux.cpp index e18c8d1e..b1e2945b 100644 --- a/Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination_Windows.cpp +++ b/Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination_Windows_Linux.cpp @@ -1,5 +1,5 @@ /*---------------------------------------------------------*\ -| RGBController_NVIDIAIllumination.cpp | +| RGBController_NVIDIAIllumination_Windows_Linux.cpp | | | | RGBController for NVIDIA Illumination GPU | | | @@ -10,7 +10,7 @@ \*---------------------------------------------------------*/ #include -#include "RGBController_NVIDIAIllumination_Windows.h" +#include "RGBController_NVIDIAIllumination_Windows_Linux.h" /**------------------------------------------------------------------*\ @name NVIDIA Illumination diff --git a/Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination_Windows.h b/Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination_Windows_Linux.h similarity index 92% rename from Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination_Windows.h rename to Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination_Windows_Linux.h index dbe5da83..fb78064c 100644 --- a/Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination_Windows.h +++ b/Controllers/NVIDIAIlluminationController/RGBController_NVIDIAIllumination_Windows_Linux.h @@ -1,5 +1,5 @@ /*---------------------------------------------------------*\ -| RGBController_NVIDIAIllumination.h | +| RGBController_NVIDIAIllumination_Windows_Linux.h | | | | RGBController for NVIDIA Illumination GPU | | | @@ -13,7 +13,7 @@ #include #include "RGBController.h" -#include "NVIDIAIlluminationV1Controller_Windows.h" +#include "NVIDIAIlluminationV1Controller_Windows_Linux.h" #define NVIDIA_FOUNDERS_V1_CONTROLLER_NAME "NVIDIA_FOUNDERS_V1" diff --git a/Controllers/NVIDIAIlluminationController/nvapi_accessor_Windows.cpp b/Controllers/NVIDIAIlluminationController/nvapi_accessor_Windows_Linux.cpp similarity index 93% rename from Controllers/NVIDIAIlluminationController/nvapi_accessor_Windows.cpp rename to Controllers/NVIDIAIlluminationController/nvapi_accessor_Windows_Linux.cpp index e2b84b2e..af9c96fb 100644 --- a/Controllers/NVIDIAIlluminationController/nvapi_accessor_Windows.cpp +++ b/Controllers/NVIDIAIlluminationController/nvapi_accessor_Windows_Linux.cpp @@ -1,5 +1,5 @@ /*---------------------------------------------------------*\ -| nvapi_accessor_Windows.cpp | +| nvapi_accessor_Windows_Linux.cpp | | | | NVAPI accessor for NVIDIA NVAPI illumination API | | | @@ -11,7 +11,7 @@ #include #include -#include "nvapi_accessor_Windows.h" +#include "nvapi_accessor_Windows_Linux.h" nvapi_accessor::nvapi_accessor(NV_PHYSICAL_GPU_HANDLE handle) { diff --git a/Controllers/NVIDIAIlluminationController/nvapi_accessor_Windows.h b/Controllers/NVIDIAIlluminationController/nvapi_accessor_Windows_Linux.h similarity index 93% rename from Controllers/NVIDIAIlluminationController/nvapi_accessor_Windows.h rename to Controllers/NVIDIAIlluminationController/nvapi_accessor_Windows_Linux.h index 9b130e05..8ff70b6b 100644 --- a/Controllers/NVIDIAIlluminationController/nvapi_accessor_Windows.h +++ b/Controllers/NVIDIAIlluminationController/nvapi_accessor_Windows_Linux.h @@ -1,5 +1,5 @@ /*---------------------------------------------------------*\ -| nvapi_accessor_Windows.h | +| nvapi_accessor_Windows_Linux.h | | | | NVAPI accessor for NVIDIA NVAPI illumination API | | | diff --git a/OpenRGB.pro b/OpenRGB.pro index 7628810a..2560b09e 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -479,10 +479,12 @@ contains(QMAKE_PLATFORM, linux) { HEADERS += $$CONTROLLER_H_LINUX HEADERS += \ + dependencies/NVFC/nvapi.h \ i2c_smbus/i2c_smbus_linux.h \ AutoStart/AutoStart-Linux.h \ INCLUDEPATH += \ + dependencies/NVFC \ /usr/include/mbedtls2/ \ LIBS += \ @@ -528,6 +530,7 @@ contains(QMAKE_PLATFORM, linux) { SOURCES += \ dependencies/hueplusplus-1.1.0/src/LinHttpHandler.cpp \ + dependencies/NVFC/nvapi.cpp \ i2c_smbus/i2c_smbus_linux.cpp \ scsiapi/scsiapi_linux.c \ serial_port/find_usb_serial_port_linux.cpp \ diff --git a/dependencies/NVFC/nvapi.cpp b/dependencies/NVFC/nvapi.cpp index 36862dd0..5f1d1fd7 100644 --- a/dependencies/NVFC/nvapi.cpp +++ b/dependencies/NVFC/nvapi.cpp @@ -1,7 +1,14 @@ -#define _WIN32_LEAN_AND_MEAN -#include +#ifdef _WIN32 + #define _WIN32_LEAN_AND_MEAN + #include +#elif __linux__ + #include +#endif #include "nvapi.h" +#include + +typedef void * (*nvapi_QueryInterface_t)(int); // Constructors for NvAPI structures that just zero the memory and set the right version NV_DELTA_ENTRY::NV_DELTA_ENTRY() @@ -248,7 +255,7 @@ static NV_STATUS(*pNvAPI_GPU_ClientIllumZonesSetControl)( NV_PHYSICAL_GPU_HANDLE physical_gpu_handle, NV_GPU_CLIENT_ILLUM_ZONE_CONTROL_PARAMS* pIllumZonesControl); -static bool QueryInterfaceOpaque(FARPROC query_interface, NV_U32 id, void **result) +static bool QueryInterfaceOpaque(nvapi_QueryInterface_t query_interface, NV_U32 id, void **result) { void *address = ((void *(*)(NV_U32))query_interface)(id); if (address) { @@ -259,7 +266,7 @@ static bool QueryInterfaceOpaque(FARPROC query_interface, NV_U32 id, void **resu } template -static void QueryInterfaceCast(FARPROC query_interface, NV_U32 id, const char *function_name, F &function_pointer) +static void QueryInterfaceCast(nvapi_QueryInterface_t query_interface, NV_U32 id, const char *function_name, F &function_pointer) { const bool result = QueryInterfaceOpaque(query_interface, id, (void **)&function_pointer); ////Log::write("%s querying interface '0x%08x' '%s'", result ? "success" : "failure", id, function_name); @@ -268,7 +275,7 @@ static void QueryInterfaceCast(FARPROC query_interface, NV_U32 id, const char *f #define QueryInterface(query_interface, id, function) \ QueryInterfaceCast((query_interface), (id), #function, p ## function) -static void QueryInterfaces(FARPROC query_interface) +static void QueryInterfaces(nvapi_QueryInterface_t query_interface) { //Log::write("querying interfaces with '0x%p'", query_interface); @@ -308,20 +315,35 @@ static void QueryInterfaces(FARPROC query_interface) NV_STATUS NvAPI_Initialize() { if (!pNvAPI_Initialize) { +#ifdef _WIN32 const char *name = sizeof(void*) == 4 ? "nvapi.dll" : "nvapi64.dll"; HMODULE nvapi = LoadLibraryA(name); if (!nvapi) { //Log::write("failed to load '%s'", name); return -1; } - //Log::write("loaded '%s' '0x%p'", name, nvapi); - - FARPROC query_interface = GetProcAddress(nvapi, "nvapi_QueryInterface"); + nvapi_QueryInterface_t query_interface = (nvapi_QueryInterface_t) GetProcAddress(nvapi, "nvapi_QueryInterface"); if (!query_interface) { //Log::write("failed to find 'nvapi_QueryInterface'"); return -1; } +#elif __linux__ + void* nvapi; + if (!nvapi) nvapi = dlopen("libnvidia-api.so.1", RTLD_LAZY); + if (!nvapi) nvapi = dlopen("libnvidia-api.so", RTLD_LAZY); + if (!nvapi) { + // NVIDIA Driver is not installed + //Log::write("failed to load libnvidia-api.so, NVIDIA Driver is not installed"); + return -1; + } + nvapi_QueryInterface_t query_interface = (nvapi_QueryInterface_t) dlsym(nvapi, "nvapi_QueryInterface"); + if (!query_interface) { + // NVIDIA Driver is probably not up to date, requires at least driver version 525 + //Log::write("failed to load QueryInterface from libnvidia-api.so, NVIDIA Driver is not up to date"); + return -1; + } +#endif QueryInterfaces(query_interface); } diff --git a/dependencies/NVFC/nvapi.h b/dependencies/NVFC/nvapi.h index 73668b03..50823ff6 100644 --- a/dependencies/NVFC/nvapi.h +++ b/dependencies/NVFC/nvapi.h @@ -1024,12 +1024,12 @@ NV_STATUS NvAPI_I2CReadEx( // Interface: 73C01D58 NV_STATUS NvAPI_GPU_ClientIllumZonesGetControl( - __in NV_PHYSICAL_GPU_HANDLE physical_gpu_handle, - __inout NV_GPU_CLIENT_ILLUM_ZONE_CONTROL_PARAMS* pIllumZonesControl); + NV_PHYSICAL_GPU_HANDLE physical_gpu_handle, + NV_GPU_CLIENT_ILLUM_ZONE_CONTROL_PARAMS* pIllumZonesControl); // Interface: 57024C62 NV_STATUS NvAPI_GPU_ClientIllumZonesSetControl( - __in NV_PHYSICAL_GPU_HANDLE physical_gpu_handle, - __inout NV_GPU_CLIENT_ILLUM_ZONE_CONTROL_PARAMS* pIllumZonesControl); + NV_PHYSICAL_GPU_HANDLE physical_gpu_handle, + NV_GPU_CLIENT_ILLUM_ZONE_CONTROL_PARAMS* pIllumZonesControl); #endif