1/*
2 * Copyright © 2020 Intel Corporation
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#include "intel_uuid.h"
25#include "git_sha1.h"
26#include "util/mesa-sha1.h"
27
28void
29intel_uuid_compute_device_id(uint8_t *uuid,
30                             const struct isl_device *isldev,
31                             size_t size)
32{
33   struct mesa_sha1 sha1_ctx;
34   uint8_t sha1[20];
35   const struct intel_device_info *devinfo = isldev->info;
36
37   assert(size <= sizeof(sha1));
38
39   /* The device UUID uniquely identifies the given device within the machine.
40    * Since we never have more than one device, this doesn't need to be a real
41    * UUID.  However, on the off-chance that someone tries to use this to
42    * cache pre-tiled images or something of the like, we use the PCI ID and
43    * some bits of ISL info to ensure that this is safe.
44    */
45   _mesa_sha1_init(&sha1_ctx);
46   _mesa_sha1_update(&sha1_ctx, &devinfo->chipset_id,
47                     sizeof(devinfo->chipset_id));
48   _mesa_sha1_update(&sha1_ctx, &isldev->has_bit6_swizzling,
49                     sizeof(isldev->has_bit6_swizzling));
50   _mesa_sha1_final(&sha1_ctx, sha1);
51   memcpy(uuid, sha1, size);
52}
53
54void
55intel_uuid_compute_driver_id(uint8_t *uuid,
56                             const struct intel_device_info *devinfo,
57                             size_t size)
58{
59   const char* intelDriver = PACKAGE_VERSION MESA_GIT_SHA1;
60   struct mesa_sha1 sha1_ctx;
61   uint8_t sha1[20];
62
63   assert(size <= sizeof(sha1));
64
65   /* The driver UUID is used for determining sharability of images and memory
66    * between two Vulkan instances in separate processes, but also to
67    * determining memory objects and sharability between Vulkan and OpenGL
68    * driver. People who want to share memory need to also check the device
69    * UUID.
70    */
71   _mesa_sha1_init(&sha1_ctx);
72   _mesa_sha1_update(&sha1_ctx, intelDriver, strlen(intelDriver) * sizeof(char));
73   _mesa_sha1_final(&sha1_ctx, sha1);
74   memcpy(uuid, sha1, size);
75}
76