diff options
author | Marri Devender Rao <devenrao@in.ibm.com> | 2018-03-12 09:21:29 -0500 |
---|---|---|
committer | Matt Spinler <spinler@us.ibm.com> | 2018-03-23 17:11:04 +0000 |
commit | 694e8dc744efa2ee4ce8bb74c866c817b3f91fc3 (patch) | |
tree | 5a2bec639c301daa395c8e651293f5c2d8667651 | |
parent | 17f0679b8acee7565adbc7a461d8d280826fed18 (diff) | |
download | phosphor-mrw-tools-694e8dc744efa2ee4ce8bb74c866c817b3f91fc3.tar.gz phosphor-mrw-tools-694e8dc744efa2ee4ce8bb74c866c817b3f91fc3.zip |
Parse temperature sensors in gen_ipmi_sensor script
At present temperature sensors are added with hand coded
YAML file the same has been modified to auto-generate
by reading the MRW file.
Change-Id: I4d7294395305dba09bfb526682cb32977c79ee05
Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
-rw-r--r-- | Util.pm | 23 | ||||
-rwxr-xr-x | gen_ipmi_sensor.pl | 131 |
2 files changed, 133 insertions, 21 deletions
@@ -43,6 +43,24 @@ sub getChildUnitsWithTargetType return @units; } +#Returns size of child units based on their Type. +# param[in] $targetObj = The Targets object +# param[in] $type = The type of the units to find +# param[in] $chip = The chip target to find the units on +sub getSizeOfChildUnitsWithType +{ + my ($targetObj, $type, $chip) = @_; + my @units; + my @children = $targetObj->getAllTargetChildren($chip); + for my $child (@children) { + if ($targetObj->getType($child) eq $type) { + push @units, $child; + } + } + my $size = @units; + return $size; +} + # Returns OBMC name corresponding to a Target name # param[in] \@inventory = reference to array of inventory items # param[in] $targetName = A Target name @@ -155,6 +173,11 @@ it will die. Currently supports single BMC systems. Returns an array of targets that have target-type C<TargetType> and are children (any level) of target C<ChipTarget>. +=item getSizeOfChildUnitsWithType(C<TargetsObj>, C<Type>, C<ChipTarget>) + +Returns size of targets that have Type C<Type> +and are children (any level) of target C<ChipTarget>. + =item getObmcName(C<InventoryItems>, C<TargetName>) Returns an OBMC name corresponding to a Target name. Returns diff --git a/gen_ipmi_sensor.pl b/gen_ipmi_sensor.pl index 74c95da..9cd6728 100755 --- a/gen_ipmi_sensor.pl +++ b/gen_ipmi_sensor.pl @@ -114,21 +114,101 @@ foreach my $target (sort keys %{$targetObj->getAllTargets()}) my $serviceInterface = $sensorTypeConfig->{$sensorName}->{"serviceInterface"}; my $readingType = $sensorTypeConfig->{$sensorName}->{"readingType"}; - my $sensorNamePattern = $sensorTypeConfig->{$sensorName}->{"sensorNamePattern"}; + my $sensorNamePattern = + $sensorTypeConfig->{$sensorName}->{"sensorNamePattern"}; + + # store the values in hash + my %data; + $data{'SENSOR_NAME'} = $sensorName; + $data{'SENSOR_TYPE'} = $sensorType; + $data{'SERVICE_INTF'} = $serviceInterface; + $data{'READING_TYPE'} = $readingType; + $data{'SENSOR_NAME_PATTERN'} = $sensorNamePattern; + $data{'ENTITY_ID'} = $entityID; + $data{'ENTITY_INSTANCE'} = $entityInstance; + $data{'FH'} = $fh; my $debug = "$sensorID : $sensorName : $sensorType : "; - $debug .= "$sensorReadingType : $entityID : $entityInstance : "; - $debug .= "$obmcPath \n"; + $debug .= "$serviceInterface: $readingType : $sensorNamePattern : "; + $debug .= "$entityID : $entityInstance : "; + # temperature sensor + if($sensorType == 0x01) { + my $dbusPath = + temperatureSensorPathFixup($sensorName, $target, $obmcPath); + if (not defined $dbusPath) { + warn("Unsupported sensor $sensorName, Ignoring\n"); + next; + } + my $multiplierM = $sensorTypeConfig->{$sensorName}->{"multiplierM"}; + my $offsetB = $sensorTypeConfig->{$sensorName}->{"offsetB"}; + my $bExp = $sensorTypeConfig->{$sensorName}->{"bExp"}; + my $rExp = $sensorTypeConfig->{$sensorName}->{"rExp"}; + my $unit = $sensorTypeConfig->{$sensorName}->{"unit"}; + my $scale = $sensorTypeConfig->{$sensorName}->{"scale"}; + $data{'MULTIPLIER_M'} = $multiplierM; + $data{'OFFSET_B'} = $offsetB; + $data{'B_EXP'} = $bExp; + $data{'R_EXP'} = $rExp; + $data{'UNIT'} = $unit; + $data{'SCALE'} = $scale; + $data{'PATH'} = $dbusPath; + $debug .= "$multiplierM : $offsetB : $bExp : $rExp : $unit : "; + $debug .= "$scale : $dbusPath : $obmcPath : "; + } + else { + $debug .= "$obmcPath : "; + $data{'PATH'} = $obmcPath; + } + $data{'SENSOR_READING_TYPE'} = $sensorReadingType; + writeToFile(%data); + $debug .= "$sensorReadingType\n"; printDebug("$debug"); - writeToFile($sensorName,$sensorType,$sensorReadingType,$obmcPath,$serviceInterface, - $readingType,$sensorTypeConfig,$entityID,$entityInstance,$sensorNamePattern,$fh); - } - } close $fh; +# Construct DBus object path for temperature sensors +sub temperatureSensorPathFixup +{ + my ($sensorName, $target, $path) = @_; + $path = "/xyz/openbmc_project/sensors/temperature/"; + if($sensorName eq "cpucore_temp_sensor") { + my $core = $targetObj->getTargetParent($target); + my $coreNo = $targetObj->getAttribute($core, "IPMI_INSTANCE"); + my $proc = Util::getEnclosingFru($targetObj, $core); + my $procNo = $targetObj->getAttribute($proc, "POSITION"); + my $size = Util::getSizeOfChildUnitsWithType($targetObj, "CORE", $proc); + $coreNo = $coreNo - ($procNo * $size); + $path .= "p" . $procNo . "_core" . $coreNo . "_temp"; + } + elsif ($sensorName eq "dimm_temp_sensor") { + my $dimm = $targetObj->getTargetParent($target); + my $dimmconn = $targetObj->getTargetParent($dimm); + my $pos = $targetObj->getAttribute($dimmconn, "POSITION"); + $path .= "dimm" . $pos . "_temp"; + } + elsif ($sensorName eq "vrm_vdd_temp_sensor") { + my $proc = Util::getEnclosingFru($targetObj, $target); + my $procNo = $targetObj->getAttribute($proc, "POSITION"); + $path .= "p" . $procNo . "_vdd_temp"; + } + elsif ($sensorName eq "memory_temp_sensor") { + my $gvcard = $targetObj->getTargetParent($target); + my $pos = $targetObj->getAttribute($gvcard, "IPMI_INSTANCE"); + $path .= "gpu" . $pos . "_mem_temp"; + } + elsif ($sensorName eq "gpu_temp_sensor") { + my $gvcard = $targetObj->getTargetParent($target); + my $pos = $targetObj->getAttribute($gvcard, "IPMI_INSTANCE"); + $path .= "gpu" . $pos . "_core_temp"; + } + else { + return undef; + } + return $path; +} + #Write the interfaces data into the output file sub writeInterfaces { @@ -159,25 +239,34 @@ sub writeInterfaces #Write the sensor data into the output file sub writeToFile { - my ($sensorName,$sensorType,$sensorReadingType,$path,$serviceInterface, - $readingType,$sensorTypeConfig,$entityID,$entityInstance, - $sensorNamePattern,$fh) = @_; - - print $fh " entityID: ".$entityID."\n"; - print $fh " entityInstance: ".$entityInstance."\n"; - print $fh " sensorType: ".$sensorType."\n"; - print $fh " path: ".$path."\n"; - - print $fh " sensorReadingType: ".$sensorReadingType."\n"; - print $fh " serviceInterface: ".$serviceInterface."\n"; - print $fh " readingType: ".$readingType."\n"; - print $fh " sensorNamePattern: ".$sensorNamePattern."\n"; + my (%data) = @_; + my $sensorType = $data{'SENSOR_TYPE'}; + my $fs = $data{'FH'}; + print $fh " entityID: ".$data{'ENTITY_ID'}."\n"; + print $fh " entityInstance: ".$data{'ENTITY_INSTANCE'}."\n"; + print $fh " sensorType: ".$data{'SENSOR_TYPE'}."\n"; + print $fh " path: ".$data{'PATH'}."\n"; + print $fh " sensorReadingType: ".$data{'SENSOR_READING_TYPE'}."\n"; + print $fh " serviceInterface: ".$data{'SERVICE_INTF'}."\n"; + print $fh " readingType: ".$data{'READING_TYPE'}."\n"; + print $fh " sensorNamePattern: ".$data{'SENSOR_NAME_PATTERN'}."\n"; + + # temperature sensor + if ($sensorType == 0x01) { + print $fh " multiplierM: ".$data{'MULTIPLIER_M'}."\n"; + print $fh " offsetB: ".$data{'OFFSET_B'}."\n"; + print $fh " bExp: ".$data{'B_EXP'}."\n"; + print $fh " rExp: ".$data{'R_EXP'}."\n"; + print $fh " unit: ".$data{'UNIT'}."\n"; + print $fh " scale: ".$data{'SCALE'}."\n"; + } + my $sensorName = $data{'SENSOR_NAME'}; my $interfaces = $sensorTypeConfig->{$sensorName}->{"interfaces"}; writeInterfaces($interfaces, $fh); } -#Convert MRW OCC inventory path to application d-bus path +# Convert MRW OCC inventory path to application d-bus path sub checkOccPathFixup { my ($path) = @_; |