From 246b96829ffac2007288e1e85a057fc80fbd52da Mon Sep 17 00:00:00 2001 From: Mel Henning Date: Fri, 19 Sep 2025 20:25:50 -0400 Subject: [PATCH] nouveau/headers: Deduplicate push dump impls Note that this changes the output so it lists the method as being in the class where it most recently changed rather than always in the class of the running gpu. Personally, I find this more useful than the old behavior. Reviewed-by: Mary Guillemard Part-of: --- src/nouveau/headers/class_parser.py | 36 +++++++++++++++++++++++++++++ src/nouveau/headers/meson.build | 17 ++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/nouveau/headers/class_parser.py b/src/nouveau/headers/class_parser.py index 27a3d386c26..feec5e3c552 100644 --- a/src/nouveau/headers/class_parser.py +++ b/src/nouveau/headers/class_parser.py @@ -169,14 +169,37 @@ TEMPLATE_C = Template("""\ %endif +<%def name="prev_cases()"> + %for mthd in methods: + %if prev_methods.get(mthd.name, None) == mthd: + ${cases(mthd)} + %endif + %endfor + + +%if prev_nvcl: +const char *P_PARSE_${prev_nvcl}_MTHD(uint16_t idx) ATTRIBUTE_COLD; +void P_DUMP_${prev_nvcl}_MTHD_DATA(FILE *fp, uint16_t idx, uint32_t data, + const char *prefix) ATTRIBUTE_COLD; +%endif + const char* P_PARSE_${nvcl}_MTHD(uint16_t idx) { switch (idx) { + +%if prev_nvcl: + ${prev_cases()} + return P_PARSE_${prev_nvcl}_MTHD(idx); +%endif + %for mthd in methods: %if mthd.is_array and mthd.array_size == 0: <% continue %> %endif + %if prev_methods.get(mthd.name, None) == mthd: + <% continue %> + %endif %if mthd.is_array: %for i in range(mthd.array_size): case ${nvcl}_${mthd.name}(${i}): @@ -187,6 +210,7 @@ P_PARSE_${nvcl}_MTHD(uint16_t idx) return "${nvcl}_${mthd.name}"; %endif %endfor + default: return "unknown method"; } @@ -198,10 +222,20 @@ P_DUMP_${nvcl}_MTHD_DATA(FILE *fp, uint16_t idx, uint32_t data, { UNUSED uint32_t parsed; switch (idx) { + +%if prev_nvcl: + ${prev_cases()} + P_DUMP_${prev_nvcl}_MTHD_DATA(fp, idx, data, prefix); + break; +%endif + %for mthd in methods: %if mthd.is_array and mthd.array_size == 0: <% continue %> %endif + %if prev_methods.get(mthd.name, None) == mthd: + <% continue %> + %endif ${cases(mthd)} %for field in mthd.fields: <% field_width = field.end - field.start + 1 %> @@ -589,6 +623,7 @@ def main(): prev_mod = None prev_methods = {} + prev_nvcl = None if args.prev_in_h is not None: prev_clheader = os.path.basename(args.prev_in_h) prev_nvcl = nvcl_for_filename(prev_clheader) @@ -603,6 +638,7 @@ def main(): 'methods': list(methods.values()), 'prev_mod': prev_mod, 'prev_methods': prev_methods, + 'prev_nvcl': prev_nvcl, 'to_camel': to_camel, 'bs': '\\' } diff --git a/src/nouveau/headers/meson.build b/src/nouveau/headers/meson.build index 91445ffc03e..ab6030f21f0 100644 --- a/src/nouveau/headers/meson.build +++ b/src/nouveau/headers/meson.build @@ -75,12 +75,25 @@ flat_nv_classes = '' cl_generated = [] foreach cl : nv_classes + prev_cl_h = [] + prev_cl_args = [] + foreach prev_cl : nv_classes + if prev_cl == cl + break + endif + + if prev_cl.substring(-2) == cl.substring(-2) + prev_cl_h = 'nvidia/classes/'+prev_cl+'.h' + prev_cl_args = ['--prev-in-h', '@INPUT2@'] + endif + endforeach + flat_nv_classes = flat_nv_classes + cl + ' ' cl_generated += custom_target( cl + '.h', - input : ['class_parser.py', 'nvidia/classes/'+cl+'.h', 'util.py'], + input : ['class_parser.py', 'nvidia/classes/'+cl+'.h', prev_cl_h, 'util.py'], output : ['nv_push_'+cl+'.h', 'nv_push_'+cl+'.c'], - command : [prog_python, '@INPUT0@', '--in-h', '@INPUT1@', + command : [prog_python, '@INPUT0@', '--in-h', '@INPUT1@', prev_cl_args, '--out-h', '@OUTPUT0@', '--out-c', '@OUTPUT1@'], ) endforeach