Ben Widawsky | 0e89319 | 2013-05-10 15:25:49 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Damien Lespiau | b9765af | 2013-05-03 16:08:25 +0100 | [diff] [blame] | 2 | |
| 3 | import os,sys |
| 4 | import optparse |
| 5 | import subprocess |
| 6 | import re |
| 7 | import operator |
| 8 | |
| 9 | # map of Workaround names -> (list of platforms) |
| 10 | workarounds = {} |
| 11 | verbose = False |
| 12 | |
| 13 | def find_nth(haystack, needle, n): |
| 14 | start = haystack.find(needle) |
| 15 | while start >= 0 and n > 1: |
| 16 | start = haystack.find(needle, start + len(needle)) |
| 17 | n -= 1 |
| 18 | return start |
| 19 | |
Damien Lespiau | 8c4dd1d | 2013-05-31 15:33:21 +0100 | [diff] [blame^] | 20 | valid_platforms = ('ctg', 'elk', 'ilk', 'snb', 'ivb', 'vlv', 'hsw', 'bdw', |
| 21 | 'chv') |
Damien Lespiau | b9765af | 2013-05-03 16:08:25 +0100 | [diff] [blame] | 22 | def parse_platforms(p): |
| 23 | l = p.split(',') |
| 24 | for p in l: |
| 25 | if p not in valid_platforms: |
| 26 | sys.stdout.write("unknown platform %s\n" % p) |
| 27 | return l |
| 28 | |
Damien Lespiau | 17523ef | 2013-06-06 16:52:09 +0100 | [diff] [blame] | 29 | wa_re = re.compile('(?P<name>W[aA][A-Z0-9][a-zA-Z0-9_]+):(?P<platforms>[a-z,]+)') |
| 30 | waname_re = re.compile('(?P<name>W[aA][A-Z0-9][a-zA-Z0-9_]+)') |
Damien Lespiau | b9765af | 2013-05-03 16:08:25 +0100 | [diff] [blame] | 31 | def parse(me): |
| 32 | for line in me.splitlines(): |
Ben Widawsky | 0e89319 | 2013-05-10 15:25:49 -0700 | [diff] [blame] | 33 | match = wa_re.search(str(line)) |
Damien Lespiau | b9765af | 2013-05-03 16:08:25 +0100 | [diff] [blame] | 34 | if not match: |
| 35 | if not verbose: |
| 36 | continue |
| 37 | |
| 38 | # Those lines come from a git grep that looks for Wa |
| 39 | # names, so if we don't match wa_re here it's because |
| 40 | # no platform has been specified |
| 41 | name = waname_re.search(line).group('name') |
| 42 | path = line[:find_nth(line, ':', 2)] |
| 43 | sys.stdout.write("%s: no platform for %s\n" |
| 44 | % (path, name)) |
| 45 | continue |
| 46 | |
| 47 | wa_name = match.group('name') |
| 48 | platforms = match.group('platforms') |
| 49 | |
| 50 | if wa_name in workarounds: |
Damien Lespiau | 397dcb7 | 2013-05-10 14:37:10 +0100 | [diff] [blame] | 51 | platforms = parse_platforms(platforms) |
| 52 | for p in platforms: |
| 53 | if not p in workarounds[wa_name]: |
| 54 | workarounds[wa_name].append(p) |
Damien Lespiau | b9765af | 2013-05-03 16:08:25 +0100 | [diff] [blame] | 55 | else: |
| 56 | workarounds[wa_name] = parse_platforms(platforms) |
| 57 | |
| 58 | |
| 59 | def execute(cmd): |
| 60 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
| 61 | stderr=subprocess.PIPE) |
| 62 | out, err = p.communicate() |
| 63 | return out, err |
| 64 | |
| 65 | def parse_options(args): |
| 66 | usage = "Usage: list-workarounds [options] path-to-kernel" |
| 67 | parser = optparse.OptionParser(usage, version=1.0) |
| 68 | |
| 69 | parser.add_option("-v", "--verbose", action="store_true", |
| 70 | dest="verbose", default=False, |
| 71 | help="be more verbose") |
| 72 | |
| 73 | parser.add_option("-p", "--platform", dest="platform", default=None, |
| 74 | help="List workarounds for the specified platform") |
| 75 | |
| 76 | (options, args) = parser.parse_args() |
| 77 | |
| 78 | return (options, args) |
| 79 | |
| 80 | if __name__ == '__main__': |
| 81 | (options, args) = parse_options(sys.argv[1:]) |
| 82 | verbose = options.verbose |
| 83 | |
| 84 | if not len(args): |
| 85 | sys.stderr.write("error: A path to a kernel tree is required\n") |
| 86 | sys.exit(1) |
| 87 | |
| 88 | kernel_path = args[0] |
| 89 | kconfig = os.path.join(kernel_path, 'Kconfig') |
| 90 | if not os.path.isfile(kconfig): |
| 91 | sys.stderr.write("error: %s does not point to a kernel tree \n" |
| 92 | % kernel_path) |
| 93 | sys.exit(1) |
| 94 | |
Damien Lespiau | 81ba005 | 2013-05-23 12:11:26 +0100 | [diff] [blame] | 95 | i915_dir = os.path.join('drivers', 'gpu', 'drm', 'i915') |
Damien Lespiau | b9765af | 2013-05-03 16:08:25 +0100 | [diff] [blame] | 96 | olddir = os.getcwd() |
| 97 | os.chdir(kernel_path) |
| 98 | work_arounds, err = execute(['git', 'grep', '-n', |
Damien Lespiau | 17523ef | 2013-06-06 16:52:09 +0100 | [diff] [blame] | 99 | '-e', 'W[aA][A-Z0-9][a-zA-Z0-9_]\+', |
Damien Lespiau | b9765af | 2013-05-03 16:08:25 +0100 | [diff] [blame] | 100 | i915_dir]) |
| 101 | os.chdir(olddir) |
| 102 | if err: |
| 103 | print(err) |
| 104 | sys.exit(1) |
| 105 | |
| 106 | parse(work_arounds) |
Ben Widawsky | 0e89319 | 2013-05-10 15:25:49 -0700 | [diff] [blame] | 107 | for wa in sorted(workarounds.keys()): |
Damien Lespiau | b9765af | 2013-05-03 16:08:25 +0100 | [diff] [blame] | 108 | if not options.platform: |
| 109 | print("%s: %s" % (wa, ', '.join(workarounds[wa]))) |
| 110 | elif options.platform in workarounds[wa]: |
| 111 | print(wa) |