1 /*
2 * Copyright ©2021 Collabora Ltd.
3 * Copyright © 2015 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25 #ifndef GEN_MACROS_H
26 #define GEN_MACROS_H
27
28 /* Macros for handling per-gen compilation.
29 *
30 * The macro GENX() automatically suffixes whatever you give it with _vX
31 *
32 * You can do pseudo-runtime checks in your function such as
33 *
34 * if (PAN_ARCH == 4) {
35 * // Do something
36 * }
37 *
38 * The contents of the if statement must be valid regardless of gen, but
39 * the if will get compiled away on everything except first-generation Midgard.
40 *
41 * For places where you really do have a compile-time conflict, you can
42 * use preprocessor logic:
43 *
44 * #if (PAN_ARCH == 75)
45 * // Do something
46 * #endif
47 *
48 * However, it is strongly recommended that the former be used whenever
49 * possible.
50 */
51
52 /* Returns the architecture version given a GPU ID, either from a table for
53 * old-style Midgard versions or directly for new-style Bifrost/Valhall
54 * versions */
55
56 static inline unsigned
pan_arch(unsigned gpu_id)57 pan_arch(unsigned gpu_id)
58 {
59 switch (gpu_id) {
60 case 0x600:
61 case 0x620:
62 case 0x720:
63 return 4;
64 case 0x750:
65 case 0x820:
66 case 0x830:
67 case 0x860:
68 case 0x880:
69 return 5;
70 default:
71 return gpu_id >> 12;
72 }
73 }
74
75 /* Base macro defined on the command line. */
76 #ifndef PAN_ARCH
77 # include "genxml/common_pack.h"
78 #else
79
80 /* Suffixing macros */
81 #if (PAN_ARCH == 4)
82 # define GENX(X) X##_v4
83 # include "genxml/v4_pack.h"
84 #elif (PAN_ARCH == 5)
85 # define GENX(X) X##_v5
86 # include "genxml/v5_pack.h"
87 #elif (PAN_ARCH == 6)
88 # define GENX(X) X##_v6
89 # include "genxml/v6_pack.h"
90 #elif (PAN_ARCH == 7)
91 # define GENX(X) X##_v7
92 # include "genxml/v7_pack.h"
93 #else
94 # error "Need to add suffixing macro for this architecture"
95 #endif
96
97 #endif /* PAN_ARCH */
98 #endif /* GEN_MACROS_H */
99