xref: /aosp_15_r20/external/mesa3d/src/freedreno/common/freedreno_dev_info.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2020 Valve Corporation
3  * SPDX-License-Identifier: MIT
4  *
5  */
6 
7 #include "freedreno_dev_info.h"
8 #include "util/macros.h"
9 
10 /**
11  * Table entry for a single GPU version
12  */
13 struct fd_dev_rec {
14    struct fd_dev_id id;
15    const char *name;
16    const struct fd_dev_info *info;
17 };
18 
19 #include "freedreno_devices.h"
20 
21 /**
22  * Compare device 'id' against reference id ('ref') from gpu table.
23  */
24 static bool
dev_id_compare(const struct fd_dev_id * ref,const struct fd_dev_id * id)25 dev_id_compare(const struct fd_dev_id *ref, const struct fd_dev_id *id)
26 {
27    if (ref->gpu_id && id->gpu_id) {
28       return ref->gpu_id == id->gpu_id;
29    } else {
30       if (!id->chip_id)
31          return false;
32 
33       /* Match on either:
34        * (a) exact match:
35        */
36       if (ref->chip_id == id->chip_id)
37          return true;
38       /* (b) device table entry has 0xff wildcard patch_id and core/
39        *     major/minor match:
40        */
41       if (((ref->chip_id & 0xff) == 0xff) &&
42             ((ref->chip_id & UINT64_C(0xffffff00)) ==
43              (id->chip_id & UINT64_C(0xffffff00))))
44          return true;
45 #define WILDCARD_FUSE_ID UINT64_C(0x0000ffff00000000)
46       /* If the reference id has wildcard fuse-id value (ie. bits 47..32
47        * are all ones, then try matching ignoring the device fuse-id:
48        */
49       if ((ref->chip_id & WILDCARD_FUSE_ID) == WILDCARD_FUSE_ID) {
50          uint64_t chip_id = id->chip_id | WILDCARD_FUSE_ID;
51          /* (c) exact match (ignoring the fuse-id from kernel):
52           */
53          if (ref->chip_id == chip_id)
54             return true;
55          /* (d) device table entry has 0xff wildcard patch_id and core/
56           *     major/minor match (ignoring fuse-id from kernel):
57           */
58          if (((ref->chip_id & 0xff) == 0xff) &&
59                ((ref->chip_id & UINT64_C(0xffffff00)) ==
60                 (chip_id & UINT64_C(0xffffff00))))
61             return true;
62       }
63       return false;
64    }
65 }
66 
67 const struct fd_dev_info *
fd_dev_info_raw(const struct fd_dev_id * id)68 fd_dev_info_raw(const struct fd_dev_id *id)
69 {
70    for (int i = 0; i < ARRAY_SIZE(fd_dev_recs); i++) {
71       if (dev_id_compare(&fd_dev_recs[i].id, id)) {
72          return fd_dev_recs[i].info;
73       }
74    }
75    return NULL;
76 }
77 
78 const struct fd_dev_info
fd_dev_info(const struct fd_dev_id * id)79 fd_dev_info(const struct fd_dev_id *id)
80 {
81    struct fd_dev_info modified = {};
82    const struct fd_dev_info *orig = fd_dev_info_raw(id);
83    if (orig) {
84       modified = *orig;
85       fd_dev_info_apply_dbg_options(&modified);
86    }
87 
88    return modified;
89 }
90 
91 const struct fd_dev_info *
fd_dev_info_raw_by_name(const char * name)92 fd_dev_info_raw_by_name(const char *name)
93 {
94    for (int i = 0; i < ARRAY_SIZE(fd_dev_recs); i++) {
95       if (!strcmp(fd_dev_recs[i].name, name)) {
96          return fd_dev_recs[i].info;
97       }
98    }
99 
100    return NULL;
101 }
102 
103 const char *
fd_dev_name(const struct fd_dev_id * id)104 fd_dev_name(const struct fd_dev_id *id)
105 {
106    for (int i = 0; i < ARRAY_SIZE(fd_dev_recs); i++) {
107       if (dev_id_compare(&fd_dev_recs[i].id, id)) {
108          return fd_dev_recs[i].name;
109       }
110    }
111    return NULL;
112 }
113