1 /*
2 * Copyright © 2020 Valve 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
25 #include "freedreno_dev_info.h"
26 #include "util/macros.h"
27
28 /**
29 * Table entry for a single GPU version
30 */
31 struct fd_dev_rec {
32 struct fd_dev_id id;
33 const char *name;
34 const struct fd_dev_info *info;
35 };
36
37 #include "freedreno_devices.h"
38
39 /**
40 * Compare device 'id' against reference id ('ref') from gpu table.
41 */
42 static bool
dev_id_compare(const struct fd_dev_id * ref,const struct fd_dev_id * id)43 dev_id_compare(const struct fd_dev_id *ref, const struct fd_dev_id *id)
44 {
45 if (ref->gpu_id && id->gpu_id) {
46 return ref->gpu_id == id->gpu_id;
47 } else {
48 assert(ref->chip_id && id->chip_id);
49 /* Match on either:
50 * (a) exact match:
51 */
52 if (ref->chip_id == id->chip_id)
53 return true;
54 /* (b) device table entry has 0xff wildcard patch_id and core/
55 * major/minor match:
56 */
57 if (((ref->chip_id & 0xff) == 0xff) &&
58 ((ref->chip_id & UINT64_C(0xffffff00)) ==
59 (id->chip_id & UINT64_C(0xffffff00))))
60 return true;
61 #define WILDCARD_FUSE_ID UINT64_C(0x0000ffff00000000)
62 /* If the reference id has wildcard fuse-id value (ie. bits 47..32
63 * are all ones, then try matching ignoring the device fuse-id:
64 */
65 if ((ref->chip_id & WILDCARD_FUSE_ID) == WILDCARD_FUSE_ID) {
66 uint64_t chip_id = id->chip_id | WILDCARD_FUSE_ID;
67 /* (c) exact match (ignoring the fuse-id from kernel):
68 */
69 if (ref->chip_id == chip_id)
70 return true;
71 /* (d) device table entry has 0xff wildcard patch_id and core/
72 * major/minor match (ignoring fuse-id from kernel):
73 */
74 if (((ref->chip_id & 0xff) == 0xff) &&
75 ((ref->chip_id & UINT64_C(0xffffff00)) ==
76 (chip_id & UINT64_C(0xffffff00))))
77 return true;
78 }
79 return false;
80 }
81 }
82
83 const struct fd_dev_info *
fd_dev_info(const struct fd_dev_id * id)84 fd_dev_info(const struct fd_dev_id *id)
85 {
86 for (int i = 0; i < ARRAY_SIZE(fd_dev_recs); i++) {
87 if (dev_id_compare(&fd_dev_recs[i].id, id)) {
88 return fd_dev_recs[i].info;
89 }
90 }
91 return NULL;
92 }
93
94 const char *
fd_dev_name(const struct fd_dev_id * id)95 fd_dev_name(const struct fd_dev_id *id)
96 {
97 for (int i = 0; i < ARRAY_SIZE(fd_dev_recs); i++) {
98 if (dev_id_compare(&fd_dev_recs[i].id, id)) {
99 return fd_dev_recs[i].name;
100 }
101 }
102 return NULL;
103 }
104