| #!/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() |