E
Eric Schwartz
I'm trying to parse the output of 'lspci -t' on a Linux system. This
output looks something like:
-+-[a0]-+-01.0-[a1]--+-01.0
| | \-02.0
| \-02.0
+-[80]-+-01.0
| +-02.0-[81]--+-04.0
| | +-05.0
| | \-06.0
| \-04.0
\-[00]---00.0
[xx] is the bus number, nn.n is the PCI device.function number. If
there is a [xx] on a line after a nn.n number, then the [xx] is the
address of a PCI<->PCI bridge.
What I'm trying to figure out is, given bus and device numbers that
identify a PCI bridge, how can I find the PCI bridge number?
I have tried:
#!/usr/bin/perl
use warnings;
use strict;
my $pci_tree;
{ local $/; $pci_tree = <DATA> }
sub get_bridge_addr
{
my ($bus,$dev) = @_;
if ($pci_tree =~ /^[ -]\+- # line starts with ' ' or '-'
[$bus]-.*(?<!\n \+) # bus number, followed by anything
# that ISN'T '^ +' (signifying a new
# top-level bus number)
$dev.*-\[([^]])+\] # device number is always on the same
# line as the bridge address
/smx) {
return $1;
}
die ("Can't find a bus address for $bus : $dev!");
}
print "bridge address on the same line as top-level bus: [",
get_bridge_addr('a0', '01'), "]\n";
print "bridge address on a different line: [",
get_bridge_addr('80', '02'), "]\n";
__DATA__
-+-[a0]-+-01.0-[a1]--+-01.0
| | \-02.0
| \-02.0
+-[80]-+-01.0
| +-02.0-[81]--+-04.0
| | +-05.0
| | \-06.0
| \-04.0
\-[00]---00.0
but I get:
Can't find a bus address for a0 : 01! at /tmp/bah line 22, <DATA> line 1.
I've been staring at this regex for approximately forever, and though
I'm certain there's a blindingly obvious bug in it, I can't find
it. (Obviously, or I wouldn't have posted here!) Suggestions,
comments, boots to da head are all welcome.
-=Eric
output looks something like:
-+-[a0]-+-01.0-[a1]--+-01.0
| | \-02.0
| \-02.0
+-[80]-+-01.0
| +-02.0-[81]--+-04.0
| | +-05.0
| | \-06.0
| \-04.0
\-[00]---00.0
[xx] is the bus number, nn.n is the PCI device.function number. If
there is a [xx] on a line after a nn.n number, then the [xx] is the
address of a PCI<->PCI bridge.
What I'm trying to figure out is, given bus and device numbers that
identify a PCI bridge, how can I find the PCI bridge number?
I have tried:
#!/usr/bin/perl
use warnings;
use strict;
my $pci_tree;
{ local $/; $pci_tree = <DATA> }
sub get_bridge_addr
{
my ($bus,$dev) = @_;
if ($pci_tree =~ /^[ -]\+- # line starts with ' ' or '-'
[$bus]-.*(?<!\n \+) # bus number, followed by anything
# that ISN'T '^ +' (signifying a new
# top-level bus number)
$dev.*-\[([^]])+\] # device number is always on the same
# line as the bridge address
/smx) {
return $1;
}
die ("Can't find a bus address for $bus : $dev!");
}
print "bridge address on the same line as top-level bus: [",
get_bridge_addr('a0', '01'), "]\n";
print "bridge address on a different line: [",
get_bridge_addr('80', '02'), "]\n";
__DATA__
-+-[a0]-+-01.0-[a1]--+-01.0
| | \-02.0
| \-02.0
+-[80]-+-01.0
| +-02.0-[81]--+-04.0
| | +-05.0
| | \-06.0
| \-04.0
\-[00]---00.0
but I get:
Can't find a bus address for a0 : 01! at /tmp/bah line 22, <DATA> line 1.
I've been staring at this regex for approximately forever, and though
I'm certain there's a blindingly obvious bug in it, I can't find
it. (Obviously, or I wouldn't have posted here!) Suggestions,
comments, boots to da head are all welcome.
-=Eric