aosp12/external/autotest/client/bin/update_intel_pci_ids

93 lines
2.6 KiB
Python
Executable File

#!/usr/bin/env python2
# 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
from six.moves import range
def map_gpu_name(mesa_name):
"""Map Mesa GPU names to autotest names.
"""
family_name_map = {
'Pineview': 'pinetrail',
'ILK': 'ironlake',
'SNB': 'sandybridge',
'IVB': 'ivybridge',
'HSW': 'haswell',
'BYT': 'baytrail',
'BDW': 'broadwell',
'CHV': 'braswell',
'BSW': 'braswell',
'SKL': 'skylake',
'APL': 'broxton',
'BXT': 'broxton',
'KBL': 'kabylake',
'GLK': 'geminilake',
'CNL': 'cannonlake',
'CFL': 'coffeelake',
'ICL': 'icelake',
'CML': 'cometlake',
'WHL': 'whiskeylake',
'TGL': 'tigerlake',
'JSL': 'jasperlake'
}
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', 'iris_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:
# Prevent unexpected lines from being parsed
if not 'CHIPSET(' in cset:
continue
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()