ronnie
2022-10-14 1504bb53e29d3d46222c0b3ea994fc494b48e153
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
#!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
 
"""Create a JSON file containing PCI ID-to-name mappings for Intel GPUs.
 
This script gets the latest PCI ID list from Mesa.
The list is used by get_gpu_family() in utils.py.
This script should be run whenever Mesa is updated
to keep the list up-to-date.
"""
 
import json
import os
import shutil
import subprocess as sp
 
 
def map_gpu_name(mesa_name):
    """Map Mesa GPU names to autotest names.
    """
    family_name_map = {
        'Pineview': 'pinetrail',
        'Ironlake': 'ironlake',
        'Sandybridge': 'sandybridge',
        'Ivybridge': 'ivybridge',
        'Haswell': 'haswell',
        'Bay Trail': 'baytrail',
        'Broadwell': 'broadwell',
        'Cherryview': 'braswell',
        'Cherrytrail': 'braswell',
        'Braswell': 'braswell',
        'Skylake': 'skylake',
        'Broxton': 'broxton',
        'Kabylake': 'kabylake',
        'Kaby Lake': 'kabylake',
        'Geminilake': 'geminilake',
        'Cannonlake': 'cannonlake',
        'Coffeelake': 'coffeelake',
        'Ice Lake': 'icelake'
    }
 
    for name in family_name_map:
        if name in mesa_name:
            return family_name_map[name]
    return ''
 
 
def main():
    """Extract Intel GPU PCI IDs from Mesa and write to JSON file.
    """
 
    in_files = ['i915_pci_ids.h', 'i965_pci_ids.h']
    script_dir = os.path.dirname(os.path.realpath(__file__))
    out_file = os.path.join(script_dir, 'intel_pci_ids.json')
    local_repo = os.path.join(script_dir, '../../../../mesa')
 
    pci_ids = {}
    chipsets = []
    cmd = 'cd %s; git show HEAD:include/pci_ids/' % local_repo
    for id_file in in_files:
        chipsets.extend(sp.check_output(cmd + id_file,
                                        shell=True).splitlines())
    for cset in chipsets:
        cset_attr = cset[len('CHIPSET('):-2].split(',')
 
        # Remove leading and trailing spaces and double quotes.
        for i in range(0, len(cset_attr)):
            cset_attr[i] = cset_attr[i].strip(' "').rstrip(' "')
 
        pci_id = cset_attr[0].lower()
        family_name = map_gpu_name(cset_attr[2])
 
        # Ignore GPU families not in family_name_map.
        if family_name:
            pci_ids[pci_id] = family_name
 
    with open(out_file, 'w') as out_f:
        json.dump(pci_ids, out_f, sort_keys=True, indent=4,
                  separators=(',', ': '))
 
 
if __name__ == '__main__':
    main()