• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python2
2# Copyright 2015 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Create a JSON file containing PCI ID-to-name mappings for Intel GPUs.
7
8This script gets the latest PCI ID list from Mesa.
9The list is used by get_gpu_family() in utils.py.
10This script should be run whenever Mesa is updated
11to keep the list up-to-date.
12"""
13
14import json
15import os
16import shutil
17import subprocess as sp
18
19
20def map_gpu_name(mesa_name):
21    """Map Mesa GPU names to autotest names.
22    """
23    family_name_map = {
24        'Pineview': 'pinetrail',
25        'Ironlake': 'ironlake',
26        'Sandybridge': 'sandybridge',
27        'Ivybridge': 'ivybridge',
28        'Haswell': 'haswell',
29        'Bay Trail': 'baytrail',
30        'Broadwell': 'broadwell',
31        'Cherryview': 'braswell',
32        'Cherrytrail': 'braswell',
33        'Braswell': 'braswell',
34        'Skylake': 'skylake',
35        'Broxton': 'broxton',
36        'Kabylake': 'kabylake',
37        'Kaby Lake': 'kabylake',
38        'Geminilake': 'geminilake',
39        'Cannonlake': 'cannonlake',
40        'Coffeelake': 'coffeelake',
41        'Ice Lake': 'icelake',
42        'Comet Lake': 'cometlake',
43        'Whiskey Lake': 'whiskeylake',
44        'TGL': 'tigerlake',
45        'Jasper Lake': 'jasperlake'
46    }
47
48    for name in family_name_map:
49        if name in mesa_name:
50            return family_name_map[name]
51    return ''
52
53
54def main():
55    """Extract Intel GPU PCI IDs from Mesa and write to JSON file.
56    """
57
58    in_files = ['i915_pci_ids.h', 'i965_pci_ids.h', 'iris_pci_ids.h']
59    script_dir = os.path.dirname(os.path.realpath(__file__))
60    out_file = os.path.join(script_dir, 'intel_pci_ids.json')
61    local_repo = os.path.join(script_dir, '../../../../mesa')
62
63    pci_ids = {}
64    chipsets = []
65    cmd = 'cd %s; git show HEAD:include/pci_ids/' % local_repo
66    for id_file in in_files:
67        chipsets.extend(sp.check_output(cmd + id_file,
68                                        shell=True).splitlines())
69    for cset in chipsets:
70        # Prevent unexpected lines from being parsed
71        if not 'CHIPSET(' in cset:
72            continue
73        cset_attr = cset[len('CHIPSET('):-2].split(',')
74
75        # Remove leading and trailing spaces and double quotes.
76        for i in range(0, len(cset_attr)):
77            cset_attr[i] = cset_attr[i].strip(' "').rstrip(' "')
78
79        pci_id = cset_attr[0].lower()
80        family_name = map_gpu_name(cset_attr[2])
81
82        # Ignore GPU families not in family_name_map.
83        if family_name:
84            pci_ids[pci_id] = family_name
85
86    with open(out_file, 'w') as out_f:
87        json.dump(pci_ids, out_f, sort_keys=True, indent=4,
88                  separators=(',', ': '))
89
90
91if __name__ == '__main__':
92    main()
93