1#!/usr/bin/env python3 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 18from six.moves import range 19 20 21def map_gpu_name(mesa_name): 22 """Map Mesa GPU names to autotest names. 23 """ 24 family_name_map = { 25 'Pineview': 'pinetrail', 26 'ILK': 'ironlake', 27 'SNB': 'sandybridge', 28 'IVB': 'ivybridge', 29 'HSW': 'haswell', 30 'BYT': 'baytrail', 31 'BDW': 'broadwell', 32 'CHV': 'braswell', 33 'BSW': 'braswell', 34 'SKL': 'skylake', 35 'APL': 'broxton', 36 'BXT': 'broxton', 37 'KBL': 'kabylake', 38 'GLK': 'geminilake', 39 'CNL': 'cannonlake', 40 'CFL': 'coffeelake', 41 'ICL': 'icelake', 42 'CML': 'cometlake', 43 'WHL': 'whiskeylake', 44 'TGL': 'tigerlake', 45 'JSL': 'jasperlake', 46 'ADL': 'alderlake' 47 } 48 49 for name in family_name_map: 50 if name in mesa_name: 51 return family_name_map[name] 52 return '' 53 54 55def main(): 56 """Extract Intel GPU PCI IDs from Mesa and write to JSON file. 57 """ 58 59 in_files = ['i915_pci_ids.h', 'i965_pci_ids.h', 'iris_pci_ids.h'] 60 script_dir = os.path.dirname(os.path.realpath(__file__)) 61 out_file = os.path.join(script_dir, 'intel_pci_ids.json') 62 local_repo = os.path.join(script_dir, '../../../../mesa') 63 64 pci_ids = {} 65 chipsets = [] 66 cmd = 'cd %s; git show HEAD:include/pci_ids/' % local_repo 67 for id_file in in_files: 68 chipsets.extend(sp.check_output(cmd + id_file, 69 shell=True).splitlines()) 70 for cset in chipsets: 71 # Prevent unexpected lines from being parsed 72 if not 'CHIPSET(' in cset: 73 continue 74 cset_attr = cset[len('CHIPSET('):-2].split(',') 75 76 # Remove leading and trailing spaces and double quotes. 77 for i in range(0, len(cset_attr)): 78 cset_attr[i] = cset_attr[i].strip(' "').rstrip(' "') 79 80 pci_id = cset_attr[0].lower() 81 family_name = map_gpu_name(cset_attr[2]) 82 83 # Ignore GPU families not in family_name_map. 84 if family_name: 85 pci_ids[pci_id] = family_name 86 87 with open(out_file, 'w') as out_f: 88 json.dump(pci_ids, out_f, sort_keys=True, indent=4, 89 separators=(',', ': ')) 90 91 92if __name__ == '__main__': 93 main() 94