2 # Copyright (C) 2008 Michal Vaner (vorner@ucw.cz)
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # he Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 package PciIds::Address::Pci;
22 use PciIds::Address::Toplevel;
23 use base 'PciIds::Address::Base';
27 return PciIds::Address::Toplevel::new( $address ) if( $address =~ /^PC\/?$/ );
28 return bless PciIds::Address::Base::new( $address );
50 s/([0-9a-f]{4})([0-9a-f]{4})/$1 $2/g;
53 $prefix = 'Subsystem';
59 return $prefix.' '. $_;
63 my( $new ) = ( shift->get() );
64 $new =~ s/.*\/(.)/$1/;
65 $new =~ s/([0-9a-f]{4})([0-9a-f]{4})/$1 $2/g;
69 sub restrictRex( $$ ) {
70 my( $self, $restrict ) = @_;
71 my( $result ) = ( $restrict =~ /^([a-f0-9]{1,4})/ );#TODO every time?
76 return ( shift->get() =~ /\/.*\/.*\// );
80 my( $self, $suffix ) = @_;
81 return ( undef, 'You can not add to leaf node' ) if( $self->leaf() );
83 return ( undef, "Invalid ID syntax" ) unless ( ( ( $self->get() !~ /^PC\/.*\// ) && ( $suffix =~ /^[0-9a-f]{4}$/ ) ) || ( ( $self->get() =~ /^PC\/.*\// ) && ( $suffix =~ /^[0-9a-f]{8}$/ ) ) );
84 return ( PciIds::Address::new( $self->{'value'} . ( ( $self->{'value'} =~ /\/$/ ) ? '' : '/' ) . $suffix ), undef );
89 my $result = PciIds::Address::Base::path( $self );
90 my( $vid ) = ( $self->get() =~ /^PC\/[0-9a-f]{4}\/[0-9a-f]{4}\/([0-9a-f]{4})/ );
91 unshift @{$result}, [ PciIds::Address::new( "PC/$vid" ), 1 ] if( defined $vid );# && ( $result->[1]->[0]->get() ne "PC/$vid" );
99 sub addressDeps( $ ) {
100 my( $addr ) = ( shift->get() =~ /^PC\/....\/....\/(....)/ );
101 return [] unless defined $addr;
102 return [ [ PciIds::Address::new( "PC/$addr" ), "Subsystem vendor $addr does not exist" ] ];
107 return 'Subsystems' if $self->get() =~ /^PC\/....\/..../;
108 return 'Devices' if $self->get() =~ /^PC\/..../;
109 die "Can not happend\n";
114 return 9 if $self->get() =~ /^PC\/....\/..../;
115 return 4 if $self->get() =~ /^PC\/..../;
116 die "Can not happen\n";