master ohmu/fastfetch-openbsd / scripts / gen-amdgpuids.py
ohmu  ·  2026-10-15
 1#!/usr/bin/env python3
 2
 3import sys
 4
 5def main(amdgpu_ids_path: str):
 6    with open(amdgpu_ids_path, 'r') as f:
 7        full_text = f.read()
 8
 9    if full_text == '':
10        sys.exit(f'Error: {amdgpu_ids_path} file is empty')
11
12    products = []
13    for line in full_text.split('\n'):
14        if not line or line[0] == '#' or not ',\t' in line:
15            continue
16        device, revision, name = line.split(',\t', maxsplit=2)
17        products.append((device, revision, name))
18
19    code = """\
20// SPDX-License-Identifier: MIT
21// https://opensource.org/license/mit
22// Generated from https://gitlab.freedesktop.org/mesa/drm/-/raw/main/data/amdgpu.ids
23
24#include <stdint.h>
25#include <stddef.h>
26
27typedef struct FFArmGpuProduct
28{
29    const uint32_t id; // device << 8 | revision
30    const char* name;
31} FFArmGpuProduct;
32
33const FFArmGpuProduct ffAmdGpuProducts[] = {
34"""
35
36    for device, revision, name in products:
37        code += f"    {{ 0x{device} << 8 | 0x{revision}, \"{name}\" }},\n"
38
39    code += "};\n"
40
41    print(code)
42
43if __name__ == '__main__':
44    len(sys.argv) == 2 or sys.exit('Usage: gen-amdgpuids.py </path/to/amdgpu.ids>')
45
46    main(sys.argv[1])