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 if (!id->chip_id)
49 return false;
50
51 /* Match on either:
52 * (a) exact match:
53 */
54 if (ref->chip_id == id->chip_id)
55 return true;
56 /* (b) device table entry has 0xff wildcard patch_id and core/
57 * major/minor match:
58 */
59 if (((ref->chip_id & 0xff) == 0xff) &&
60 ((ref->chip_id & UINT64_C(0xffffff00)) ==
61 (id->chip_id & UINT64_C(0xffffff00))))
62 return true;
63 #define WILDCARD_FUSE_ID UINT64_C(0x0000ffff00000000)
64 /* If the reference id has wildcard fuse-id value (ie. bits 47..32
65 * are all ones, then try matching ignoring the device fuse-id:
66 */
67 if ((ref->chip_id & WILDCARD_FUSE_ID) == WILDCARD_FUSE_ID) {
68 uint64_t chip_id = id->chip_id | WILDCARD_FUSE_ID;
69 /* (c) exact match (ignoring the fuse-id from kernel):
70 */
71 if (ref->chip_id == chip_id)
72 return true;
73 /* (d) device table entry has 0xff wildcard patch_id and core/
74 * major/minor match (ignoring fuse-id from kernel):
75 */
76 if (((ref->chip_id & 0xff) == 0xff) &&
77 ((ref->chip_id & UINT64_C(0xffffff00)) ==
78 (chip_id & UINT64_C(0xffffff00))))
79 return true;
80 }
81 return false;
82 }
83 }
84
85 const struct fd_dev_info *
fd_dev_info_raw(const struct fd_dev_id * id)86 fd_dev_info_raw(const struct fd_dev_id *id)
87 {
88 for (int i = 0; i < ARRAY_SIZE(fd_dev_recs); i++) {
89 if (dev_id_compare(&fd_dev_recs[i].id, id)) {
90 return fd_dev_recs[i].info;
91 }
92 }
93 return NULL;
94 }
95
96 const struct fd_dev_info
fd_dev_info(const struct fd_dev_id * id)97 fd_dev_info(const struct fd_dev_id *id)
98 {
99 struct fd_dev_info modified = {};
100 const struct fd_dev_info *orig = fd_dev_info_raw(id);
101 if (orig) {
102 modified = *orig;
103 fd_dev_info_apply_dbg_options(&modified);
104 }
105
106 return modified;
107 }
108
109 const char *
fd_dev_name(const struct fd_dev_id * id)110 fd_dev_name(const struct fd_dev_id *id)
111 {
112 for (int i = 0; i < ARRAY_SIZE(fd_dev_recs); i++) {
113 if (dev_id_compare(&fd_dev_recs[i].id, id)) {
114 return fd_dev_recs[i].name;
115 }
116 }
117 return NULL;
118 }
119