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
28 void
intel_uuid_compute_device_id(uint8_t * uuid,const struct intel_device_info * devinfo,size_t size)29 intel_uuid_compute_device_id(uint8_t *uuid,
30 const struct intel_device_info *devinfo,
31 size_t size)
32 {
33 /* The device UUID uniquely identifies the given device within the machine.
34 * We use the device information along with PCI information to make sure we
35 * have different UUIDs on a system with multiple identical (discrete)
36 * GPUs.
37 */
38
39 /* We want to have UUID matching between the different drivers (outside the
40 * Mesa project). This structure has been agreed with the various drivers
41 * to be the generated UUID.
42 *
43 * Consult other drivers before changing this.
44 */
45 struct device_uuid {
46 uint16_t vendor_id;
47 uint16_t device_id;
48 uint16_t revision_id;
49 uint16_t pci_domain;
50 uint8_t pci_bus;
51 uint8_t pci_dev;
52 uint8_t pci_func;
53 uint8_t padding[4];
54 uint8_t sub_device_id; /* Tile number */
55 } shared_uuid = {
56 .vendor_id = 0x8086,
57 .device_id = devinfo->pci_device_id,
58 .revision_id = devinfo->pci_revision_id,
59 .pci_domain = devinfo->pci_domain,
60 .pci_bus = devinfo->pci_bus,
61 .pci_dev = devinfo->pci_dev,
62 .pci_func = devinfo->pci_func,
63 };
64
65 /* All the users have a 16byte UUID */
66 assert(size == 16);
67 assert(sizeof(shared_uuid) == 16);
68
69 memcpy(uuid, &shared_uuid, size);
70 }
71
72 void
intel_uuid_compute_driver_id(uint8_t * uuid,const struct intel_device_info * devinfo,size_t size)73 intel_uuid_compute_driver_id(uint8_t *uuid,
74 const struct intel_device_info *devinfo,
75 size_t size)
76 {
77 const char* intelDriver = PACKAGE_VERSION MESA_GIT_SHA1;
78 struct mesa_sha1 sha1_ctx;
79 uint8_t sha1[20];
80
81 assert(size <= sizeof(sha1));
82
83 /* The driver UUID is used for determining sharability of images and memory
84 * between two Vulkan instances in separate processes, but also to
85 * determining memory objects and sharability between Vulkan and OpenGL
86 * driver. People who want to share memory need to also check the device
87 * UUID.
88 */
89 _mesa_sha1_init(&sha1_ctx);
90 _mesa_sha1_update(&sha1_ctx, intelDriver, strlen(intelDriver));
91 _mesa_sha1_update(&sha1_ctx, &devinfo->has_bit6_swizzle,
92 sizeof(devinfo->has_bit6_swizzle));
93 _mesa_sha1_final(&sha1_ctx, sha1);
94 memcpy(uuid, sha1, size);
95 }
96