ac/gpu: add driver/device UUID query helpers
authorAndres Rodriguez <andresx7@gmail.com>
Wed, 12 Jul 2017 22:45:25 +0000 (18:45 -0400)
committerTimothy Arceri <tarceri@itsqueeze.com>
Sun, 6 Aug 2017 02:42:07 +0000 (12:42 +1000)
We need vulkan and gl to produce the same UUIDs. Therefore we should
keep the mechanism to compute these in a common location to guarantee
they are updated in lockstep.

Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/amd/common/ac_gpu_info.c
src/amd/common/ac_gpu_info.h

index 929dfd2946ff4e27129a5794b88efdc3ed4b1fd1..e55d864187d59b97cbfe06c2cbb97721f52603a2 100644 (file)
@@ -314,3 +314,30 @@ bool ac_query_gpu_info(int fd, amdgpu_device_handle dev,
        return true;
 }
 
+void ac_compute_driver_uuid(char *uuid, size_t size)
+{
+       char amd_uuid[] = "AMD-MESA-DRV";
+
+       assert(size >= sizeof(amd_uuid));
+
+       memset(uuid, 0, size);
+       strncpy(uuid, amd_uuid, size);
+}
+
+void ac_compute_device_uuid(struct radeon_info *info, char *uuid, size_t size)
+{
+       uint32_t *uint_uuid = (uint32_t*)uuid;
+
+       assert(size >= sizeof(uint32_t)*4);
+
+       /**
+        * Use the device info directly instead of using a sha1. GL/VK UUIDs
+        * are 16 byte vs 20 byte for sha1, and the truncation that would be
+        * required would get rid of part of the little entropy we have.
+        * */
+       memset(uuid, 0, size);
+       uint_uuid[0] = info->pci_domain;
+       uint_uuid[1] = info->pci_bus;
+       uint_uuid[2] = info->pci_dev;
+       uint_uuid[3] = info->pci_func;
+}
index 20907c2620f915c162deb0dcd408cb5764f8ca92..06b0c77546653ae4301588e8fb7860ab4eb6ecc9 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef AC_GPU_INFO_H
 #define AC_GPU_INFO_H
 
+#include <stddef.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include "amd_family.h"
@@ -106,6 +107,10 @@ bool ac_query_gpu_info(int fd, amdgpu_device_handle dev,
                       struct radeon_info *info,
                       struct amdgpu_gpu_info *amdinfo);
 
+void ac_compute_driver_uuid(char *uuid, size_t size);
+
+void ac_compute_device_uuid(struct radeon_info *info, char *uuid, size_t size);
+
 #ifdef __cplusplus
 }
 #endif