Lines Matching +full:sub +full:- +full:bus

6 # supports I2C, FSI, SPI, FSI-I2C, and FSI-SPI devices.  The output is a JSON
8 # type. I2c uses a bus and address, FSI uses a link, and SPI uses a bus
10 # keys is used. Multi-hop FSI links are indicated by a dash in between the
11 # links, eg "0-1".
21 # "LocationCode": "P1-C50",
22 # "MRU":"/sys-0/node-0/motherboard/proc_socket-0/module-0/power9-0",
23 # "Name":"/sys-0/node-0/motherboard/cpu0"
27 # "LocationCode": "P1-C42",
28 # "MRU":"/sys-0/node-0/motherboard/ebmc-card/BMC-0",
29 # "Name":"/sys-0/node-0/motherboard/ebmc-card"
34 # "Name":"/sys-0/node-0/motherboard"
37 # "Dest":"/sys-0/node-0/motherboard-0/proc_socket-0/module-0/power9-0",
38 # "Source":"/sys-0/node-0/motherboard-0/ebmc-card-connector-0/card-0/bmc-0"
43 # The optional --segments argument will output a JSON file of all the bus
54 sub new
67 sub sourceChip
70 return $self->{sourceChip};
73 sub destChip
76 return $self->{destChip};
79 sub type
82 return $self->{type};
85 sub calloutList
88 return $self->{calloutList};
94 sub new
98 my $self = $class->SUPER::new("I2C", $_[1], $_[2], $_[3]);
99 $self->{i2cBus} = $_[4];
100 $self->{i2cAddr} = $_[5];
104 sub i2cBus
107 return $self->{i2cBus};
110 sub i2cAddress
113 return $self->{i2cAddr};
119 sub new
122 my $self = $class->SUPER::new("FSI", $_[1], $_[2], $_[3]);
123 $self->{FSILink} = $_[4];
128 sub fsiLink
131 return $self->{FSILink};
137 sub new
140 my $self = $class->SUPER::new("SPI", $_[1], $_[2], $_[3]);
141 $self->{SPIBus} = $_[4];
146 sub spiBus
149 return $self->{SPIBus};
152 # FSII2CCallout object for FSI-I2C callouts
158 sub new
162 my $self = $class->SUPER::new("FSI-I2C", $_[1], $_[2], $_[3]);
163 $self->{FSILink} = $_[4];
164 $self->{i2cBus} = $_[5];
165 $self->{i2cAddr} = $_[6];
169 sub fsiLink
172 return $self->{FSILink};
175 sub i2cBus
178 return $self->{i2cBus};
181 sub i2cAddress
184 return $self->{i2cAddr};
187 #FSISPICallout object for FSI-SPI callouts
191 sub new
195 my $self = $class->SUPER::new("FSI-SPI", $_[1], $_[2], $_[3]);
196 $self->{FSILink} = $_[4];
197 $self->{SPIBus} = $_[5];
201 sub fsiLink
204 return $self->{FSILink};
207 sub spiBus
210 return $self->{SPIBus};
229 # Segment bus types
246 my $targets = Targets->new;
247 $targets->loadXML($mrwFile);
268 my $json = JSON->new;
269 $json->indent(1);
270 $json->canonical(1);
271 my $text = $json->encode(\%allSegments);
277 sub getPathSegments
280 foreach my $target (sort keys %{$targets->getAllTargets()})
282 my $numConnections = $targets->getNumConnections($target);
291 my $connBusObj = $targets->getConnectionBus($target, $connIndex);
292 my $busType = $connBusObj->{bus_type};
294 # We only care about certain bus types
300 my $dest = $targets->getConnectionDestination($target, $connIndex);
325 my $parent = $targets->getTargetParent($dest);
326 if ($targets->getAttribute($parent, "CLASS") eq "CONNECTOR")
345 my $fruPath = $targets->getBusAttribute(
363 # If the bus goes through a mux, then the I2C_BUS_ALIAS field
364 # will be filled in with the bus alias number. For example
365 # 28 could be an alias for bus 5 mux channel 2. Old parts may
371 $segment{I2CBus} = $targets->getBusAttribute(
382 $segment{I2CBus} = $targets->getAttribute($target, "I2C_PORT");
386 hex($targets->getAttribute($dest, "I2C_ADDRESS"));
395 hex($targets->getAttribute($target, "FSI_LINK"));
399 $segment{SPIBus} = $targets->getAttribute($target, "SPI_PORT");
420 sub getFRUPathCallouts
443 if ($targets->isBadAttribute($path, "CLASS"))
463 sub getParentByClass
466 my $parent = $targets->getTargetParent($target);
470 if (!$targets->isBadAttribute($parent, "CLASS"))
472 if ($class eq $targets->getAttribute($parent, "CLASS"))
477 $parent = $targets->getTargetParent($parent);
484 sub buildCallouts
496 sub buildBMCSingleSegmentCallouts
504 my $chipType = $targets->getType($segment->{SourceChip});
520 sub buildSingleSegmentCallout
524 if ($segment->{BusType} eq "I2C")
528 elsif ($segment->{BusType} eq "FSIM")
532 elsif ($segment->{BusType} eq "SPI")
543 sub buildMultiSegmentCallouts
563 if ($callout->type() ne "FSI")
568 # link numbers are separated by '-'s in the link field,
569 # so 0-5 = 1 hop
570 my @numHops = $callout->fsiLink() =~ /(-)/g;
585 if ($callout->destChip() eq $segment->{SourceChip})
615 sub mergeCallouts
623 push @calloutList, @{$secondCallout->calloutList()};
624 push @calloutList, @{$firstCallout->calloutList()};
627 if (($firstCallout->type() eq "FSI") && ($secondCallout->type() eq "FSI"))
629 # combine the FSI links with a -
630 my $FSILink = $firstCallout->fsiLink() . "-" .
631 $secondCallout->fsiLink();
633 my $fsiCallout = new FSICallout($firstCallout->sourceChip(),
634 $secondCallout->destChip(), \@calloutList, $FSILink);
638 # FSI-I2C
639 elsif (($firstCallout->type() eq "FSI") &&
640 ($secondCallout->type() eq "I2C"))
642 my $i2cCallout = new FSII2CCallout($firstCallout->sourceChip(),
643 $secondCallout->destChip(), \@calloutList,
644 $firstCallout->fsiLink(), $secondCallout->i2cBus(),
645 $secondCallout->i2cAddress());
649 # FSI-SPI
650 elsif (($firstCallout->type() eq "FSI") &&
651 ($secondCallout->type() eq "SPI"))
653 my $spiCallout = new FSISPICallout($firstCallout->sourceChip(),
654 $secondCallout->destChip(), \@calloutList,
655 $firstCallout->fsiLink(), $secondCallout->spiBus());
660 die "Unrecognized callouts to merge: " . $firstCallout->type() .
661 " " . $secondCallout->type() . "\n";
665 sub createI2CCallout
668 my $bus = $segment->{I2CBus};
671 if ($targets->getAttribute($segment->{SourceChip}, "TYPE") eq "BMC")
673 $bus = Util::adjustI2CPort($segment->{I2CBus});
675 if ($bus < 0)
677 die "After adjusting BMC I2C bus $segment->{I2CBus}, " .
682 my $i2cCallout = new I2CCallout($segment->{SourceChip},
683 $segment->{DestChip}, $segment->{Callouts}, $bus,
684 $segment->{I2CAddress});
690 sub createFSICallout
694 my $fsiCallout = new FSICallout($segment->{SourceChip},
695 $segment->{DestChip}, $segment->{Callouts},
696 $segment->{FSILink}, $segment);
702 sub createSPICallout
706 my $spiCallout = new SPICallout($segment->{SourceChip},
707 $segment->{DestChip}, $segment->{Callouts},
708 $segment->{SPIBus});
716 sub printJSON
724 $c{Source} = $callout->sourceChip();
725 $c{Dest} = $callout->destChip();
727 for my $fruCallout (@{$callout->calloutList()})
731 if (length($fruCallout->{Name}) == 0)
734 " (" . $callout->sourceChip() . ") ->\n" .
735 " (" . $callout->destChip() . ")\n";
738 $entry{Name} = $fruCallout->{Name};
741 Util::getLocationCode($targets, $fruCallout->{Name});
743 # MRUs - for now just use the path + MRU name
744 if (exists $fruCallout->{MRU})
746 $entry{MRU} = $entry{Name} . "/" . $fruCallout->{MRU};
749 $entry{Priority} = validatePriority($fruCallout->{Priority});
759 if ($callout->type() eq "I2C")
763 $c{HexAddress} = $callout->i2cAddress();
764 my $decimal = hex($callout->i2cAddress());
766 $output{"I2C"}{$callout->i2cBus()}{$decimal} = \%c;
768 elsif ($callout->type() eq "SPI")
770 $output{"SPI"}{$callout->spiBus()} = \%c;
772 elsif ($callout->type() eq "FSI")
774 $output{"FSI"}{$callout->fsiLink()} = \%c;
776 elsif ($callout->type() eq "FSI-I2C")
778 $c{HexAddress} = $callout->i2cAddress();
779 my $decimal = hex($callout->i2cAddress());
781 $output{"FSI-I2C"}{$callout->fsiLink()}
782 {$callout->i2cBus()}{$decimal} = \%c;
784 elsif ($callout->type() eq "FSI-SPI")
786 $output{"FSI-SPI"}{$callout->fsiLink()}{$callout->spiBus()} = \%c;
791 my $json = JSON->new->utf8;
792 $json->indent(1);
793 $json->canonical(1);
794 my $text = $json->encode(\%output);
804 sub sortCallouts
809 for (my $i = 0; $i < (scalar @callouts) - 1; $i++)
817 if ($callouts[$i]->{LocationCode} eq $callouts[$j]->{LocationCode})
820 $callouts[$i]->{Priority} = getHighestPriority(
821 $callouts[$i]->{Priority}, $callouts[$j]->{Priority});
824 if (defined $callouts[$j]->{MRU})
826 $callouts[$i]->{MRU} = $callouts[$j]->{MRU};
839 $priorities{$b->{Priority}} <=> $priorities{$a->{Priority}}
846 sub getHighestPriority
858 sub validatePriority
870 # Check if the attribute is present on the bus
871 sub isValidBusAttribute
877 if (defined($targets->getTarget($target)->
878 {CONNECTION}->{BUS}->[$connIndex]->{bus_attribute}->
879 {$attr}->{default}))
886 sub printUsage
888 print "$0 -m <MRW file> -o <Output filename> [--segments] [-n]\n" .
889 " -m <MRW file> = The MRW XML\n" .
890 " -o <Output filename> = The output JSON\n" .
891 " -n = Non-strict - Don't fail on some MRW structure problems\n" .
892 " [--segments] = Optionally create a segments.json file\n";