summaryrefslogtreecommitdiffstats
path: root/utils/trimpciids
blob: ba946297381909cf46a3b194a658644daac58a59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/python
#
# trimpciids
#
# Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import sys
import os
import string

vendors = []
devices = []

f = open(sys.argv[1])
if f:
	pcitable = f.readlines()
	f.close()
	for line in pcitable:
	    if not line.startswith("alias pci:"):
		continue
	    vend = "0x%s" % (line[15:19],)
	    dev = "0x%s" % (line[24:28],)
	    vend = vend.upper()
	    dev = dev.upper()
	    if vend not in vendors:
		vendors.append(vend)
	    if (vend, dev) not in devices:
		devices.append( (vend, dev) )

for file in sys.argv[2:]:
   if not os.path.exists(file):
       sys.stderr.write("WARNING: non-existent file %s for trimpciids\n" %(file,))
       continue
   f = open(file)
   if f:
	pcitable = f.readlines()
	f.close()
	for line in pcitable:
	    if not line.startswith("alias pcivideo:"):
		continue
	    vend = "0x%s" % (line[20:24],)
	    dev = "0x%s" % (line[29:33],)
	    vend = vend.upper()
	    dev = dev.upper()
	    if vend not in vendors:
		vendors.append(vend)
	    if (vend, dev) not in devices:
		devices.append( (vend, dev) )

pciids = sys.stdin.readlines()
current_vend = 0
for line in pciids:
    if line.startswith("#") or line == "\n":
	continue
    if line.startswith("\t\t"):
	continue
    if not line.startswith("\t"):
	current_vend = "0x%s" % line.split()[0]
	current_vend = current_vend.upper()
	if current_vend in vendors:
	    print line,
	continue
    dev = "0x%s" % line.split()[0]
    dev = dev.upper()
    if (current_vend, dev) in devices:
	print line,