1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
# Copyright © 2023 Intel Corporation
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
import argparse
import collections
import json
import os
import sys
from mako.template import Template
HEADER_TEMPLATE = Template("""\
/*
* Copyright © 2023 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
#ifndef INTEL_WA_H
#define INTEL_WA_H
#include "util/macros.h"
#ifdef __cplusplus
extern "C" {
#endif
struct intel_device_info;
void intel_device_info_init_was(struct intel_device_info *devinfo);
enum intel_wa_steppings {
% for a in stepping_enum:
INTEL_STEPPING_${a},
% endfor
INTEL_STEPPING_RELEASE
};
enum intel_workaround_id {
% for a in wa_def:
INTEL_WA_${a},
% endfor
INTEL_WA_NUM
};
/* These defines are used to identify when a workaround potentially applies
* in genxml code. They should not be used directly. intel_needs_workaround()
* checks these definitions to eliminate bitset tests at compile time.
*/
% for a in wa_def:
#define INTEL_WA_${a}_GFX_VER ${wa_macro[a]}
% endfor
/* These defines are suitable for use to compile out genxml code using #if
* guards. Workarounds that apply to part of a generation must use a
* combination of run time checks and INTEL_WA_{NUM}_GFX_VER macros. Those
* workarounds are 'poisoned' below.
*/
% for a in partial_gens:
% if partial_gens[a]:
PRAGMA_POISON(INTEL_NEEDS_WA_${a})
% else:
#define INTEL_NEEDS_WA_${a} INTEL_WA_${a}_GFX_VER
% endif
% endfor
#define INTEL_ALL_WA ${"\\\\"}
% for wa_id in wa_def:
INTEL_WA(${wa_id}), ${"\\\\"}
% endfor
#ifdef __cplusplus
}
#endif
#endif /* INTEL_WA_H */
""")
IMPL_TEMPLATE = Template("""\
/*
* Copyright © 2023 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
#include "dev/intel_wa.h"
#include "dev/intel_device_info.h"
#include "util/bitset.h"
void intel_device_info_init_was(struct intel_device_info *devinfo)
{
switch(devinfo->platform) {
% for platform in platform_bugs:
case ${platform}:
% if platform in stepping_bugs:
switch(intel_device_info_wa_stepping(devinfo)) {
% for stepping, ids in stepping_bugs[platform].items():
case INTEL_STEPPING_${stepping}:
% for id in ids:
BITSET_SET(devinfo->workarounds, INTEL_WA_${id});
% endfor
break;
% endfor
default:
break;
}
% endif
% for id in platform_bugs[platform]:
BITSET_SET(devinfo->workarounds, INTEL_WA_${id});
% endfor
break;
% endfor
default:
/* unsupported platform */
break;
};
}
""")
def stepping_enums(wa_def):
"""provide a sorted list of all known steppings"""
stepping_enum = []
for bug in wa_def.values():
for platform_info in bug["mesa_platforms"].values():
steppings = platform_info["steppings"]
if steppings == "all":
continue
steppings = steppings.split("..")
for stepping in steppings:
stepping = stepping.upper()
if stepping and stepping != "None" and stepping not in stepping_enum:
stepping_enum.append(stepping)
return sorted(stepping_enum)
_PLATFORM_GFXVERS = {"INTEL_PLATFORM_BDW" : 80,
"INTEL_PLATFORM_CHV" : 80,
"INTEL_PLATFORM_SKL" : 90,
"INTEL_PLATFORM_BXT" : 90,
"INTEL_PLATFORM_KBL" : 90,
"INTEL_PLATFORM_GLK" : 90,
"INTEL_PLATFORM_CFL" : 90,
"INTEL_PLATFORM_ICL" : 110,
"INTEL_PLATFORM_EHL" : 110,
"INTEL_PLATFORM_TGL" : 120,
"INTEL_PLATFORM_RKL" : 120,
"INTEL_PLATFORM_DG1" : 120,
"INTEL_PLATFORM_ADL" : 120,
"INTEL_PLATFORM_RPL" : 120,
"INTEL_PLATFORM_DG2_G10" : 125,
"INTEL_PLATFORM_DG2_G11" : 125,
"INTEL_PLATFORM_DG2_G12" : 125,
"INTEL_PLATFORM_MTL_M" : 125,
"INTEL_PLATFORM_MTL_P" : 125,
}
def macro_versions(wa_def):
"""provide a map of workaround id -> GFX_VERx10 macro test"""
wa_macro = {}
for bug_id, bug in wa_def.items():
platforms = set()
for platform in bug["mesa_platforms"]:
gfxver = _PLATFORM_GFXVERS[platform]
if gfxver not in platforms:
platforms.add(gfxver)
if not platforms:
continue
ver_cmps = [f"(GFX_VERx10 == {platform})" for platform in sorted(platforms)]
wa_macro[bug_id] = ver_cmps[0]
if len(ver_cmps) > 1:
wa_macro[bug_id] = f"({' || '.join(ver_cmps)})"
return wa_macro
def partial_gens(wa_def):
"""provide a map of workaround id -> true/false, indicating whether the wa
applies to a subset of platforms in a generation"""
wa_partial_gen = {}
# map of gfxver -> set(all platforms for gfxver)
generations = collections.defaultdict(set)
for platform, gfxver in _PLATFORM_GFXVERS.items():
generations[gfxver].add(platform)
# map of platform -> set(all required platforms for gen completeness)
required_platforms = collections.defaultdict(set)
for gen_set in generations.values():
for platform in gen_set:
required_platforms[platform] = gen_set
for bug_id, bug in wa_def.items():
# for the given wa, create a set which includes all platforms that
# match any of the affected gfxver.
wa_required_for_completeness = set()
for platform in bug["mesa_platforms"]:
wa_required_for_completeness.update(required_platforms[platform])
# eliminate each platform specifically indicated by the WA, to see if
# are left over.
for platform in bug["mesa_platforms"]:
wa_required_for_completeness.remove(platform)
# if any platform remains in the required set, then this wa *partially*
# applies to one of the gfxvers.
wa_partial_gen[bug_id] = bool(wa_required_for_completeness)
return wa_partial_gen
def platform_was(wa_def):
"""provide a map of platform -> list of workarounds"""
platform_bugs = collections.defaultdict(list)
for workaround, bug in wa_def.items():
for platform, desc in bug["mesa_platforms"].items():
if desc["steppings"] != "all":
# stepping-specific workaround, not platform-wide
continue
platform_bugs[platform].append(workaround)
return platform_bugs
def stepping_was(wa_def, all_steppings):
"""provide a map of wa[platform][stepping] -> [ids]"""
stepping_bugs = collections.defaultdict(lambda: collections.defaultdict(list))
for workaround, bug in wa_def.items():
for platform, desc in bug["mesa_platforms"].items():
if desc["steppings"] == "all":
continue
first_stepping, fixed_stepping = desc["steppings"].split("..")
first_stepping = first_stepping.upper()
fixed_stepping = fixed_stepping.upper()
steppings = []
for step in all_steppings:
if step <first_stepping:
continue
if step >= fixed_stepping:
break
steppings.append(step)
for step in steppings:
u_step = step.upper()
stepping_bugs[platform][u_step].append(workaround)
stepping_bugs[platform][u_step].sort()
return stepping_bugs
def main():
"""writes c/h generated files to outdir"""
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("wa_file", type=str,
help="json data file with workaround definitions")
parser.add_argument("header_file", help="include file to generate")
parser.add_argument("impl_file", help="implementation file to generate")
args = parser.parse_args()
if not os.path.exists(args.wa_file):
print(f"Error: workaround definition not found: {args.wa_file}")
sys.exit(-1)
# json dictionary of workaround definitions
wa_def = {}
with open(args.wa_file, encoding='utf8') as wa_fh:
wa_def = json.load(wa_fh)
steppings = stepping_enums(wa_def)
with open(args.header_file, 'w', encoding='utf8') as header:
header.write(HEADER_TEMPLATE.render(wa_def=wa_def,
stepping_enum=steppings,
wa_macro=macro_versions(wa_def),
partial_gens=partial_gens(wa_def)))
with open(args.impl_file, 'w', encoding='utf8') as impl:
impl.write(IMPL_TEMPLATE.render(platform_bugs=platform_was(wa_def),
stepping_bugs=stepping_was(wa_def, steppings)))
main()
|