Explorar o código

Error with invalid device or vendor values

Marc Di Luzio %!s(int64=6) %!d(string=hai) anos
pai
achega
fe9b5c8744
Modificáronse 3 ficheiros con 25 adicións e 5 borrados
  1. 1 1
      daemon/daemon_config.c
  2. 22 2
      daemon/gamemode-gpu.c
  3. 2 2
      daemon/gpu-query.h

+ 1 - 1
daemon/daemon_config.c

@@ -261,7 +261,7 @@ static void load_config_files(GameModeConfig *self)
 	self->inhibit_screensaver = 1; /* Defaults to on */
 	self->apply_gpu_optimisations = 0;
 	self->gpu_vendor = 0;
-	self->gpu_device = 0;
+	self->gpu_device = -1; /* 0 is a valid device ID so use -1 to indicate no value */
 	self->nv_core_clock_mhz_offset = 0;
 	self->nv_mem_clock_mhz_offset = 0;
 	self->amd_core_clock_percentage = 0;

+ 22 - 2
daemon/gamemode-gpu.c

@@ -68,12 +68,31 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info)
 	GameModeGPUInfo *new_info = malloc(sizeof(GameModeGPUInfo));
 	memset(new_info, 0, sizeof(GameModeGPUInfo));
 
-	// TODO: Fill in the GPU vendor and device automatically
-
 	/* Get the config parameters */
 	config_get_gpu_vendor(config, &new_info->vendor);
 	config_get_gpu_device(config, &new_info->device);
 
+	/* TODO: Detect the GPU vendor and device automatically when these aren't set */
+
+	/* verify device ID */
+	if (new_info->device == -1) {
+		LOG_ERROR("Invalid gpu_device value set in configuration, will not appli optimisations!\n");
+		free(new_info);
+		return -1;
+	}
+
+	/* verify GPU vendor */
+	if (new_info->vendor != Vendor_NVIDIA && new_info->vendor != Vendor_AMD &&
+	    new_info->vendor != Vendor_Intel) {
+		LOG_ERROR("Invalid gpu_vendor value set in configuration, will not apply optimisations!\n");
+		LOG_ERROR("Possible values are: 0x%04x (NVIDIA) 0x%04x (AMD) 0x%04x (Intel)\n",
+		          Vendor_NVIDIA,
+		          Vendor_AMD,
+		          Vendor_Intel);
+		free(new_info);
+		return -1;
+	}
+
 	/* Load the config based on GPU */
 	switch (new_info->vendor) {
 	case Vendor_NVIDIA:
@@ -87,6 +106,7 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info)
 	default:
 		break;
 	}
+	/* TODO : Sanity check these values */
 
 	/* Give back the new gpu info */
 	*info = new_info;

+ 2 - 2
daemon/gpu-query.h

@@ -41,8 +41,8 @@ enum GPUVendor {
 
 /* Storage for GPU info*/
 struct GameModeGPUInfo {
-	enum GPUVendor vendor;
-	int device; /* path to device, ie. /sys/class/drm/card#/ */
+	long vendor;
+	long device; /* path to device, ie. /sys/class/drm/card#/ */
 
 	long core; /* Core clock to apply */
 	long mem;  /* Mem clock to apply */