Path: blob/21.2-virgl/src/intel/common/intel_uuid.c
4547 views
/*1* Copyright © 2020 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "intel_uuid.h"24#include "git_sha1.h"25#include "util/mesa-sha1.h"2627void28intel_uuid_compute_device_id(uint8_t *uuid,29const struct isl_device *isldev,30size_t size)31{32struct mesa_sha1 sha1_ctx;33uint8_t sha1[20];34const struct intel_device_info *devinfo = isldev->info;3536assert(size <= sizeof(sha1));3738/* The device UUID uniquely identifies the given device within the machine.39* Since we never have more than one device, this doesn't need to be a real40* UUID. However, on the off-chance that someone tries to use this to41* cache pre-tiled images or something of the like, we use the PCI ID and42* some bits of ISL info to ensure that this is safe.43*/44_mesa_sha1_init(&sha1_ctx);45_mesa_sha1_update(&sha1_ctx, &devinfo->chipset_id,46sizeof(devinfo->chipset_id));47_mesa_sha1_update(&sha1_ctx, &isldev->has_bit6_swizzling,48sizeof(isldev->has_bit6_swizzling));49_mesa_sha1_final(&sha1_ctx, sha1);50memcpy(uuid, sha1, size);51}5253void54intel_uuid_compute_driver_id(uint8_t *uuid,55const struct intel_device_info *devinfo,56size_t size)57{58const char* intelDriver = PACKAGE_VERSION MESA_GIT_SHA1;59struct mesa_sha1 sha1_ctx;60uint8_t sha1[20];6162assert(size <= sizeof(sha1));6364/* The driver UUID is used for determining sharability of images and memory65* between two Vulkan instances in separate processes, but also to66* determining memory objects and sharability between Vulkan and OpenGL67* driver. People who want to share memory need to also check the device68* UUID.69*/70_mesa_sha1_init(&sha1_ctx);71_mesa_sha1_update(&sha1_ctx, intelDriver, strlen(intelDriver) * sizeof(char));72_mesa_sha1_final(&sha1_ctx, sha1);73memcpy(uuid, sha1, size);74}757677