• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
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    }
43
44    for name in family_name_map:
45        if name in mesa_name:
46            return family_name_map[name]
47    return ''
48
49
50def main():
51    """Extract Intel GPU PCI IDs from Mesa and write to JSON file.
52    """
53
54    in_files = ['i915_pci_ids.h', 'i965_pci_ids.h']
55    script_dir = os.path.dirname(os.path.realpath(__file__))
56    out_file = os.path.join(script_dir, 'intel_pci_ids.json')
57    local_repo = os.path.join(script_dir, '../../../../mesa')
58
59    pci_ids = {}
60    chipsets = []
61    cmd = 'cd %s; git show HEAD:include/pci_ids/' % local_repo
62    for id_file in in_files:
63        chipsets.extend(sp.check_output(cmd + id_file,
64                                        shell=True).splitlines())
65    for cset in chipsets:
66        cset_attr = cset[len('CHIPSET('):-2].split(',')
67
68        # Remove leading and trailing spaces and double quotes.
69        for i in range(0, len(cset_attr)):
70            cset_attr[i] = cset_attr[i].strip(' "').rstrip(' "')
71
72        pci_id = cset_attr[0].lower()
73        family_name = map_gpu_name(cset_attr[2])
74
75        # Ignore GPU families not in family_name_map.
76        if family_name:
77            pci_ids[pci_id] = family_name
78
79    with open(out_file, 'w') as out_f:
80        json.dump(pci_ids, out_f, sort_keys=True, indent=4,
81                  separators=(',', ': '))
82
83
84if __name__ == '__main__':
85    main()
86