1 /*
2 * Copyright © 2020 Igalia S.L.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "freedreno_dev_info.h"
7 #include "freedreno_uuid.h"
8
9 #include <assert.h>
10 #include <stdio.h>
11 #include <string.h>
12
13 #include "util/mesa-sha1.h"
14 #include "git_sha1.h"
15
16 /* (Re)define UUID_SIZE to avoid including vulkan.h (or p_defines.h) here. */
17 #define UUID_SIZE 16
18
19 void
fd_get_driver_uuid(void * uuid)20 fd_get_driver_uuid(void *uuid)
21 {
22 const char *driver_id = PACKAGE_VERSION MESA_GIT_SHA1;
23
24 /* The driver UUID is used for determining sharability of images and memory
25 * between two Vulkan instances in separate processes, but also to
26 * determining memory objects and sharability between Vulkan and OpenGL
27 * driver. People who want to share memory need to also check the device
28 * UUID.
29 */
30 struct mesa_sha1 sha1_ctx;
31 _mesa_sha1_init(&sha1_ctx);
32
33 _mesa_sha1_update(&sha1_ctx, driver_id, strlen(driver_id));
34
35 uint8_t sha1[SHA1_DIGEST_LENGTH];
36 _mesa_sha1_final(&sha1_ctx, sha1);
37
38 assert(SHA1_DIGEST_LENGTH >= UUID_SIZE);
39 memcpy(uuid, sha1, UUID_SIZE);
40 }
41
42 void
fd_get_device_uuid(void * uuid,const struct fd_dev_id * id)43 fd_get_device_uuid(void *uuid, const struct fd_dev_id *id)
44 {
45 struct mesa_sha1 sha1_ctx;
46 _mesa_sha1_init(&sha1_ctx);
47
48 /* The device UUID uniquely identifies the given device within the machine.
49 * Since we never have more than one device, this doesn't need to be a real
50 * UUID, so we use SHA1("freedreno" + gpu_id).
51 *
52 * @TODO: Using the GPU id could be too restrictive on the off-chance that
53 * someone would like to use this UUID to cache pre-tiled images or something
54 * of the like, and use them across devices. In the future, we could allow
55 * that by:
56 * * Being a bit loose about GPU id and hash only the generation's
57 * 'major' number (e.g, '6' instead of '630').
58 *
59 * * Include HW specific constants that are relevant for layout resolving,
60 * like minimum width to enable UBWC, tile_align_w, etc.
61 *
62 * This would allow cached device memory to be safely used from HW in
63 * (slightly) different revisions of the same generation.
64 */
65
66 static const char *device_name = "freedreno";
67 _mesa_sha1_update(&sha1_ctx, device_name, strlen(device_name));
68
69 _mesa_sha1_update(&sha1_ctx, id, sizeof(*id));
70
71 uint8_t sha1[SHA1_DIGEST_LENGTH];
72 _mesa_sha1_final(&sha1_ctx, sha1);
73
74 assert(SHA1_DIGEST_LENGTH >= UUID_SIZE);
75 memcpy(uuid, sha1, UUID_SIZE);
76 }
77