gen_path_callouts: Looks for I2C_BUS_ALIAS

The I2C_BUS_ALIAS bus attribute holds the alias value the BMC uses for
I2C buses behind I2C muxes.  For example, a value of 30 could be an
alias for the bus on channel 3 of a mux on I2C bus 5.  This is the
actual value the BMC uses, so it doesn't need to be adjusted later
(subtract 1) like the other buses in the MRW require.

If this attribute is filled in for a device, use that value as the I2C
bus.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I502d3cdabe19c8f47011fa941ad1c09e446c3a50
diff --git a/gen_path_callouts.pl b/gen_path_callouts.pl
index 74da21d..de437ac 100755
--- a/gen_path_callouts.pl
+++ b/gen_path_callouts.pl
@@ -342,12 +342,31 @@
 
             if ($busType eq "I2C")
             {
-                $segment{I2CBus} = $targets->getAttribute($target, "I2C_PORT");
+                # If the bus goes through a mux, then the I2C_BUS_ALIAS field
+                # will be filled in with the bus alias number.  For example
+                # 28 could be an alias for bus 5 mux channel 2.  Old parts may
+                # not have this attribute.  Note this is the actual alias value
+                # so doesn't need a 1 subtracted later, so account for that now.
+                #
+                if (isValidBusAttribute($target, $connIndex, "I2C_BUS_ALIAS"))
+                {
+                    $segment{I2CBus} = $targets->getBusAttribute(
+                        $target, $connIndex, "I2C_BUS_ALIAS");
+
+                    if ($segment{I2CBus} ne "")
+                    {
+                        $segment{I2CBus} = $segment{I2CBus} + 1;
+                    }
+                }
+
+                if ($segment{I2CBus} eq "")
+                {
+                    $segment{I2CBus} = $targets->getAttribute($target, "I2C_PORT");
+                }
+
                 $segment{I2CAddress} =
                     hex($targets->getAttribute($dest, "I2C_ADDRESS"));
 
-                $segment{I2CBus} = $segment{I2CBus};
-
                 # Convert to the 7 bit address that linux uses
                 $segment{I2CAddress} =
                     Util::adjustI2CAddress($segment{I2CAddress});
@@ -830,6 +849,22 @@
     return $priority;
 }
 
+# Check if the attribute is present on the bus
+sub isValidBusAttribute
+{
+    my $target = shift;
+    my $connIndex = shift;
+    my $attr = shift;
+
+    if (defined($targets->getTarget($target)->
+            {CONNECTION}->{BUS}->[$connIndex]->{bus_attribute}->
+            {$attr}->{default}))
+    {
+        return 1;
+    }
+    return 0;
+}
+
 sub printUsage
 {
     print "$0 -m <MRW file> -o <Output filename> [--segments] [-n]\n" .