1/* 2 * Copyright © 2020 Igalia S.L. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 */ 23 24#include "freedreno_dev_info.h" 25#include "freedreno_uuid.h" 26 27#include <assert.h> 28#include <stdio.h> 29#include <string.h> 30 31#include "util/mesa-sha1.h" 32#include "git_sha1.h" 33 34/* (Re)define UUID_SIZE to avoid including vulkan.h (or p_defines.h) here. */ 35#define UUID_SIZE 16 36 37void 38fd_get_driver_uuid(void *uuid) 39{ 40 const char *driver_id = PACKAGE_VERSION MESA_GIT_SHA1; 41 42 /* The driver UUID is used for determining sharability of images and memory 43 * between two Vulkan instances in separate processes, but also to 44 * determining memory objects and sharability between Vulkan and OpenGL 45 * driver. People who want to share memory need to also check the device 46 * UUID. 47 */ 48 struct mesa_sha1 sha1_ctx; 49 _mesa_sha1_init(&sha1_ctx); 50 51 _mesa_sha1_update(&sha1_ctx, driver_id, strlen(driver_id)); 52 53 uint8_t sha1[SHA1_DIGEST_LENGTH]; 54 _mesa_sha1_final(&sha1_ctx, sha1); 55 56 assert(SHA1_DIGEST_LENGTH >= UUID_SIZE); 57 memcpy(uuid, sha1, UUID_SIZE); 58} 59 60void 61fd_get_device_uuid(void *uuid, const struct fd_dev_id *id) 62{ 63 struct mesa_sha1 sha1_ctx; 64 _mesa_sha1_init(&sha1_ctx); 65 66 /* The device UUID uniquely identifies the given device within the machine. 67 * Since we never have more than one device, this doesn't need to be a real 68 * UUID, so we use SHA1("freedreno" + gpu_id). 69 * 70 * @TODO: Using the GPU id could be too restrictive on the off-chance that 71 * someone would like to use this UUID to cache pre-tiled images or something 72 * of the like, and use them across devices. In the future, we could allow 73 * that by: 74 * * Being a bit loose about GPU id and hash only the generation's 75 * 'major' number (e.g, '6' instead of '630'). 76 * 77 * * Include HW specific constants that are relevant for layout resolving, 78 * like minimum width to enable UBWC, tile_align_w, etc. 79 * 80 * This would allow cached device memory to be safely used from HW in 81 * (slightly) different revisions of the same generation. 82 */ 83 84 static const char *device_name = "freedreno"; 85 _mesa_sha1_update(&sha1_ctx, device_name, strlen(device_name)); 86 87 _mesa_sha1_update(&sha1_ctx, id, sizeof(*id)); 88 89 uint8_t sha1[SHA1_DIGEST_LENGTH]; 90 _mesa_sha1_final(&sha1_ctx, sha1); 91 92 assert(SHA1_DIGEST_LENGTH >= UUID_SIZE); 93 memcpy(uuid, sha1, UUID_SIZE); 94} 95