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