diff options
Diffstat (limited to 'src/usr')
-rw-r--r-- | src/usr/errl/errlmanager.C | 6 | ||||
-rw-r--r-- | src/usr/ipmi/ipmisensor.C | 138 | ||||
-rwxr-xr-x | src/usr/targeting/common/genHwsvMrwXml.pl | 67 | ||||
-rw-r--r-- | src/usr/targeting/common/xmltohb/attribute_types.xml | 150 | ||||
-rw-r--r-- | src/usr/targeting/targplatutil.C | 184 |
5 files changed, 383 insertions, 162 deletions
diff --git a/src/usr/errl/errlmanager.C b/src/usr/errl/errlmanager.C index 2de94634b..77a2eacae 100644 --- a/src/usr/errl/errlmanager.C +++ b/src/usr/errl/errlmanager.C @@ -1339,8 +1339,8 @@ void ErrlManager::sendErrLogToBmc(errlHndl_t &io_err) // look thru the errlog for any Callout UserDetail sections // to determine the sensor information for the SEL - uint8_t l_sensorNumber = SENSOR::INVALID_SENSOR; - uint8_t l_sensorType = SENSOR::INVALID_SENSOR; + uint8_t l_sensorNumber = TARGETING::UTIL::INVALID_IPMI_SENSOR; + uint8_t l_sensorType = TARGETING::UTIL::INVALID_IPMI_SENSOR; HWAS::callOutPriority l_priority = HWAS::SRCI_PRIORITY_NONE; for(std::vector<ErrlUD*>::const_iterator it = io_err->iv_SectionVector.begin(); @@ -1380,7 +1380,7 @@ void ErrlManager::sendErrLogToBmc(errlHndl_t &io_err) #if 0 // TODO: RTC 119440 - if (l_sensorNumber != SENSOR::INVALID_SENSOR) + if (l_sensorNumber != TARGETING::UTLI::INVALID_IPMI_SENSOR) { l_sensorType = SENSOR::getSensorType(l_sensorNumber); } diff --git a/src/usr/ipmi/ipmisensor.C b/src/usr/ipmi/ipmisensor.C index 84a7d31de..3c6a282ed 100644 --- a/src/usr/ipmi/ipmisensor.C +++ b/src/usr/ipmi/ipmisensor.C @@ -206,7 +206,7 @@ namespace SENSOR iv_msg->iv_sensor_number = getSensorNumber(); - if( iv_msg->iv_sensor_number != INVALID_SENSOR ) + if( iv_msg->iv_sensor_number != TARGETING::UTIL::INVALID_IPMI_SENSOR ) { IPMI::completion_code l_rc = IPMI::CC_UNKBAD; @@ -283,7 +283,7 @@ namespace SENSOR // 3 and 5 bytes of data. size_t len = 1; - // need to allocate some mem to hold the sensor number this will be + // need to allocate some memory to hold the sensor number this will be // deleted by the IPMI transport layer uint8_t * l_data = new uint8_t[len]; @@ -297,7 +297,8 @@ namespace SENSOR // if we didn't get an error back from the BT interface, but see a // bad completion code from the BMC, process the CC to see if we - // need to create a PEL + // need to create a PEL - if an error occurs sendrcv will clean up + // l_data for us if( l_err == NULL ) { l_err = processCompletionCode( cc ); @@ -362,8 +363,9 @@ namespace SENSOR } - delete[] l_data; } + + delete[] l_data; } return l_err; }; @@ -388,14 +390,50 @@ namespace SENSOR return l_err; } - - // given an array[][2] compare the sensor name, located in the first column, - // to the passed in key value - static inline bool compare_it( uint16_t (&a)[2], uint16_t key ) + // return the sensor type and event reading data + errlHndl_t SensorBase::getSensorType(uint32_t i_sensorNumber, + uint8_t &o_sensorType, + uint8_t &o_eventReadingType ) { - return a[TARGETING::IPMI_SENSOR_ARRAY_NAME_OFFSET] < key; + + size_t len = 1; + + // need to allocate some memory to hold the sensor number this will be + // deleted by the IPMI transport layer + uint8_t *l_data = new uint8_t[len]; + + l_data[0] = i_sensorNumber; + + IPMI::completion_code cc = IPMI::CC_UNKBAD; + + // l_data will hold the response when this returns + errlHndl_t l_err = sendrecv(IPMI::get_sensor_type(), cc, len, + l_data); + + // if we didn't get an error back from the BT interface, + // process the CC to see if we need to create a PEL - sendrecv will + // delete l_data if an error occurs + if( l_err == NULL ) + { + // check the completion code + l_err = processCompletionCode( cc ); + + // $TODO RTC:123045 - Remove when SDR is finalized + if( l_err == NULL && (cc!=IPMI::CC_BADSENSOR) ) + { + // grab the type and reading code to pass back to the caller + o_sensorType = l_data[0]; + + // high order bit is reserved + o_eventReadingType = ( 0x7f & l_data[1]); + + } + delete[] l_data; + } + return l_err; }; + /** * @brief Returns major type of input sensor name * @@ -468,73 +506,6 @@ namespace SENSOR return getMajorType(i_sensorRecord[0]) == getMajorType(i_sensorName); } - // $TODO RTC:123035 investigate pre-populating some info if we end up - // doing this multiple times per sensor - // - // Helper function to search the sensor data for the correct sensor number - // based on the sensor name. - // - uint8_t SensorBase::getSensorNumber( TARGETING::Target * i_targ, - TARGETING::SENSOR_NAME i_name ) - { - - uint8_t l_sensor_number = INVALID_SENSOR; - - if( i_targ == NULL ) - { - // use the system target - TARGETING::targetService().getTopLevelTarget(i_targ); - - // die if there is no system target - assert(i_targ); - - } - - TARGETING::AttributeTraits<TARGETING::ATTR_IPMI_SENSORS>::Type - l_sensors; - - if( i_targ->tryGetAttr<TARGETING::ATTR_IPMI_SENSORS>(l_sensors) ) - { - - // get the number of rows by dividing the total size by the size of - // the first row - uint16_t array_rows = (sizeof(l_sensors)/sizeof(l_sensors[0])); - - // create an iterator pointing to the first element of the array - uint16_t (*begin)[2] = &l_sensors[0]; - - // using the number entries as the index into the array will set the - // end iterator to the correct position or one entry past the last - // element of the array - uint16_t (*end)[2] = &l_sensors[array_rows]; - - uint16_t (*ptr)[2] = - std::lower_bound(begin, end, i_name, &compare_it); - - // we have not reached the end of the array and the iterator - // returned from lower_bound is pointing to an entry which equals - // the one we are searching for. - if( ( ptr != end ) && - ( (*ptr)[TARGETING::IPMI_SENSOR_ARRAY_NAME_OFFSET] == i_name ) ) - { - // found it - l_sensor_number = - (*ptr)[TARGETING::IPMI_SENSOR_ARRAY_NUMBER_OFFSET]; - - TRACFCOMP(g_trac_ipmi,"Found sensor number %d for HUID=0x%x", - l_sensor_number, TARGETING::get_huid(i_targ)); - } - } - else - { - // bug here... - assert(0,"no IPMI_SENSOR attribute check target HUID=0x%x", - TARGETING::get_huid(i_targ)); - } - - return l_sensor_number; - } - /// // FirmwareProgressSensor constructor - uses system target // @@ -1041,12 +1012,12 @@ namespace SENSOR }; // returns a sensor number based on input target type - uint8_t getFaultSensorNumber( TARGETING::TargetHandle_t i_pTarget ) + uint32_t getFaultSensorNumber( TARGETING::TargetHandle_t i_pTarget ) { TARGETING::TYPE l_type = i_pTarget->getAttr<TARGETING::ATTR_TYPE>(); - uint8_t l_sensor_number = INVALID_SENSOR; + uint32_t l_sensor_number = TARGETING::UTIL::INVALID_IPMI_SENSOR; switch( l_type ) { @@ -1105,15 +1076,16 @@ namespace SENSOR const uint16_t (* &o_sensor_numbers)[16]) { - static const uint16_t numbers[16] = { 0x47, 0x38, 0x39, 0x3A, - 0x3B, 0x3C, 0x3D, 0x3E, - 0x3F, 0x40, 0x41, 0x42, - 0x43, 0x44, 0x45, 0x46 }; + + // habanero only.. + static const uint16_t numbers[16] = { 161, 162, 163, 164, + 165, 166, 167, 168, + 169, 170, 171, 172, + 173, 174, 175, 176}; o_sensor_numbers = &numbers; return NULL; - } }; // end name space diff --git a/src/usr/targeting/common/genHwsvMrwXml.pl b/src/usr/targeting/common/genHwsvMrwXml.pl index 0a90e72e6..051a8481f 100755 --- a/src/usr/targeting/common/genHwsvMrwXml.pl +++ b/src/usr/targeting/common/genHwsvMrwXml.pl @@ -2172,16 +2172,16 @@ sub generate_sys <attribute> <id>IPMI_SENSORS</id> <default> - 0x0700,0x07, <!-- OS_Boot --> + 0x0700,90, <!-- OS_Boot --> 0x0800,0x04, <!-- Host_Status --> 0x0900,0x05, <!-- FW_Boot_Progress --> - 0x0b00,0x09, <!-- Power_Cap --> - 0x0c00,0x06, <!-- PCI --> + 0x0b00, 88, <!-- Power_Cap --> + 0x0c00, 85, <!-- PCI --> 0x0d00,0x00, <!-- Boot_watchdog --> - 0x0e00,0x1d, <!-- Boot_Count --> - 0x1000,0x82, <!-- System_Event --> - 0x1010,0x83, <!-- APSS Fault --> - 0xC615,0x88, <!-- Activate Power Limit --> + 0x0e00, 80, <!-- Boot_Count --> + 0x1000, 82, <!-- System_Event --> + 0x1010, 87, <!-- APSS Fault --> + 0xC615, 83, <!-- Activate Power Limit --> 0xFFFF,0xFF, 0xFFFF,0xFF, 0xFFFF,0xFF, @@ -2619,10 +2619,10 @@ sub generate_system_node <attribute> <id>IPMI_SENSORS</id> <default> - 0x1000,0x80, <!-- Backplane fault sensor --> - 0x1017,0x14, <!-- TOD clock fault sensor --> - 0x101A,0x15, <!-- REF clock fault sensor --> - 0x101B,0x16, <!-- PCI clock fault sensor --> + 0x1000, 81, <!-- Backplane fault sensor --> + 0x1017, 86, <!-- TOD clock fault sensor --> + 0x101A, 84, <!-- REF clock fault sensor --> + 0x101B, 85, <!-- PCI clock fault sensor --> 0xFFFF,0xFF, 0xFFFF,0xFF, 0xFFFF,0xFF, @@ -3190,8 +3190,8 @@ sub generate_proc <attribute> <id>IPMI_SENSORS</id> <default> - 0x0100, 0x12, <!-- Temperature sensor --> - 0x0500, 0x03, <!-- State sensor --> + 0x0100, 100, <!-- Temperature sensor --> + 0x0500, 78, <!-- State sensor --> 0xFFFF, 0xFF, 0xFFFF, 0xFF, 0xFFFF, 0xFF, @@ -3287,19 +3287,26 @@ sub generate_ex_core # call to do any fsp per-ex_core attributes do_plugin('fsp_ex_core', $proc, $ex, $ordinalId ); - my $snbase=0x4d; + my $snbase=62; + my $tempsnbase= 137; + my $freqsnbase= 149; # $TODO RTC:110399 if( $haveFSPs == 0 ) { - my $procsn = sprintf("0x%02X",($snbase+$ordinalId)); + + my $procsn = $snbase+$ordinalId; + my $tempsn = $tempsnbase+$ordinalId; + my $freqsn = $freqsnbase+$ordinalId; + + print "\n<!-- IPMI Sensor numbers for Core status --> <attribute> <id>IPMI_SENSORS</id> <default> - 0x0100, 0x13, <!-- Temperature sensor --> + 0x0100, $tempsn, <!-- Temperature sensor --> 0x0500, $procsn, <!-- State sensor --> - 0xFFFF, 0xFF, + 0xC100, $freqsn, <!-- Frequency sensor --> 0xFFFF, 0xFF, 0xFFFF, 0xFF, 0xFFFF, 0xFF, @@ -4104,16 +4111,24 @@ sub generate_centaur $scanFspAsize, $scomFspBpath, $scomFspBsize, $scanFspBpath, $scanFspBsize, $relativeCentaurRid, $ordinalId, $membufVrmUuidHash); + # $TODO RTC:110399 if( $haveFSPs == 0 ) { + my @CentaurSensors = ( + [74,101],[75,102],[76,103],[77,104] ); + + my $temp_sensor = $CentaurSensors[$ordinalId][1]; + my $state_sensor = $CentaurSensors[$ordinalId][0]; + + print "<!-- IPMI Sensor numbers for Centaur status --> <attribute> <id>IPMI_SENSORS</id> <default> - 0x0100, 0x0F, <!-- Temperature sensor --> - 0x0500, 0x01, <!-- State sensor --> + 0x0100, $temp_sensor, <!-- Temperature sensor --> + 0x0500, $state_sensor, <!-- State sensor --> 0xFFFF, 0xFF, 0xFFFF, 0xFF, 0xFFFF, 0xFF, @@ -4430,16 +4445,16 @@ sub generate_is_dimm # $TODO RTC:110399 if( $haveFSPs == 0 ) { - my $snbase = 0x49; - my $sntbase = 0x10; - my $dimmsn = sprintf("0x%02X",($snbase+$dimmPos)); - my $dimmtsn = sprintf("0x%02X",($sntbase+$dimmPos)); - print "\n<!-- IPMI Sensor numbers for DIMM status --> + + my $status_base = 30+$dimm; + my $temp_base = 105+$dimm; + + print "\n<!-- IPMI Sensor numbers for DIMM status --> <attribute> <id>IPMI_SENSORS</id> <default> - 0x0100, $dimmtsn, <!-- Temperature sensor --> - 0x0500, $dimmsn, <!-- State sensor --> + 0x0100, $temp_base, <!-- Temperature sensor --> + 0x0500, $status_base, <!-- State sensor --> 0xFFFF, 0xFF, 0xFFFF, 0xFF, 0xFFFF, 0xFF, diff --git a/src/usr/targeting/common/xmltohb/attribute_types.xml b/src/usr/targeting/common/xmltohb/attribute_types.xml index 66cb3cf03..d5781b858 100644 --- a/src/usr/targeting/common/xmltohb/attribute_types.xml +++ b/src/usr/targeting/common/xmltohb/attribute_types.xml @@ -301,8 +301,6 @@ </enumerator> <default>NO_MASTER</default> </enumerationType> - - <enumerationType> <id>ENTITY_ID</id> <description>Enumeration indicating the IPMI entity ID, these values are @@ -313,6 +311,10 @@ <value>0</value> </enumerator> <enumerator> + <name>OTHER</name> + <value>0x01</value> + </enumerator> + <enumerator> <name>PROCESSOR</name> <value>0x03</value> </enumerator> @@ -321,11 +323,11 @@ <value>0x07</value> </enumerator> <enumerator> - <name>POWER_UNIT</name> - <value>0x13</value> + <name>POWER_MGMT</name> + <value>0x15</value> </enumerator> <enumerator> - <name>SYSTEM_CHASSIS</name> + <name>CHASSIS</name> <value>0x17</value> </enumerator> <enumerator> @@ -340,6 +342,34 @@ <name>OS</name> <value>0x23</value> </enumerator> + <enumerator> + <name>CORE</name> + <value>0xD0</value> + </enumerator> + <enumerator> + <name>MEMBUF</name> + <value>0xD1</value> + </enumerator> + <enumerator> + <name>OCC</name> + <value>0xD2</value> + </enumerator> + <enumerator> + <name>REF_CLOCK</name> + <value>0xD4</value> + </enumerator> + <enumerator> + <name>PCI_CLOCK</name> + <value>0xD5</value> + </enumerator> + <enumerator> + <name>TOD_CLOCK</name> + <value>0xD6</value> + </enumerator> + <enumerator> + <name>APSS</name> + <value>0xD7</value> + </enumerator> </enumerationType> <enumerationType> @@ -430,7 +460,10 @@ <name>APSS_CHANNEL</name> <!-- Power sensors --> <value>0x1100</value> <!-- 16 channels --> </enumerator> - + <enumerator> + <name>FREQUENCY</name> + <value>0xC100</value> + </enumerator> </enumerationType> <enumerationType> @@ -471,6 +504,14 @@ <value>0x09</value> </enumerator> <enumerator> + <name>SYS_FW_PROGRESS</name> + <value>0x0F</value> + </enumerator> + <enumerator> + <name>SYS_EVENT</name> + <value>0x12</value> + </enumerator> + <enumerator> <name>OS_BOOT</name> <value>0x1F</value> </enumerator> @@ -479,12 +520,62 @@ <value>0x22</value> </enumerator> <enumerator> - <name>SYSTEM_FIRMWARE_PROGRESS</name> - <value>0x0F</value> + <name>FREQ</name> + <value>0xC1</value> </enumerator> - <enumerator> - <name>REBOOT_COUNT</name> - <value>0xC0</value> + <enumerator> + <name>POWER</name> + <value>0xC2</value> + </enumerator> + <enumerator> + <name>BOOT_COUNT</name> + <value>0xC3</value> + </enumerator> + <enumerator> + <name>PCI_LINK_PRES</name> + <value>0xC4</value> + </enumerator> + <enumerator> + <name>PWR_LIMIT_ACTIVE</name> + <value>0xC4</value> + </enumerator> + <enumerator> + <name>FAULT</name> + <value>0xC7</value> + </enumerator> +</enumerationType> + +<!-- IPMI Sensor numbers are defined in the IPMI spec as 8 bit values. However +in the hostboot code they will be defined as a uint16_t to allow us to add +additonal information. An example relates to error logs returned by the OCC, +we might want to pass the Entity ID in the upper byte of the sensor ID, this +would allow hostboot to search only the target type identifed by the Entity +ID for the sensor number returned with the elog. --> + +<!-- attribute to hold 16 pairs of sensor type, sensor number values --> +<attribute> + <id>IPMI_SENSORS</id> + <description>Attribute to hold 16 pairs of sensor name, sensor number + pairs. A sensor name consists of one byte of general sensor type + and one byte of sub-type</description> + <simpleType> + <uint16_t></uint16_t> + <array>16,2</array> + </simpleType> + <persistency>non-volatile</persistency> + <readable/> +</attribute> +<enumerationType> + <id>IPMI_SENSOR_ARRAY</id> + <description>Enumeration defining the offsets into the + IPMI_SENSORS array.</description> + <enumerator> + <name>NAME_OFFSET</name> + <value>0x00</value> + </enumerator> + <enumerator> + <name>NUMBER_OFFSET</name> + <value>0x01</value> </enumerator> </enumerationType> @@ -539,42 +630,6 @@ <readable/> <hasStringConversion/> </attribute> - -<!-- IPMI Sensor numbers are defined in the IPMI spec as 8 bit values. However -in the hostboot code they will be defined as a uint16_t to allow us to add -additonal information. An example relates to error logs returned by the OCC, -we might want to pass the Entity ID in the upper byte of the sensor ID, this -would allow hostboot to search only the target type identifed by the Entity -ID for the sensor number returned with the elog. --> - -<!-- attribute to hold 16 pairs of sensor type, sensor number values --> -<attribute> - <id>IPMI_SENSORS</id> - <description>Attribute to hold 16 pairs of sensor name, sensor number - pairs. A sensor name consists of one byte of general sensor type - and one byte of sub-type</description> - <simpleType> - <uint16_t></uint16_t> - <array>16,2</array> - </simpleType> - <persistency>non-volatile</persistency> - <readable/> -</attribute> - -<enumerationType> - <id>IPMI_SENSOR_ARRAY</id> - <description>Enumeration defining the offsets into the - IPMI_SENSORS array.</description> - <enumerator> - <name>NAME_OFFSET</name> - <value>0x00</value> - </enumerator> - <enumerator> - <name>NUMBER_OFFSET</name> - <value>0x01</value> - </enumerator> -</enumerationType> - <attribute> <id>SCRATCH_UINT8_1</id> <description>Scratch attribute that can be used for dev/test</description> @@ -1469,7 +1524,6 @@ ID for the sensor number returned with the elog. --> <readable/> </attribute> - <attribute> <id>EEPROM_VPD_BACKUP_INFO</id> <description>Information needed to address the EERPROM slaves</description> diff --git a/src/usr/targeting/targplatutil.C b/src/usr/targeting/targplatutil.C index 704e3deed..a1b483473 100644 --- a/src/usr/targeting/targplatutil.C +++ b/src/usr/targeting/targplatutil.C @@ -5,7 +5,9 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* COPYRIGHT International Business Machines Corp. 2013,2014 */ +/* Contributors Listed Below - COPYRIGHT 2013,2015 */ +/* [+] International Business Machines Corp. */ +/* */ /* */ /* Licensed under the Apache License, Version 2.0 (the "License"); */ /* you may not use this file except in compliance with the License. */ @@ -39,13 +41,20 @@ #include <targeting/targplatutil.H> #include <targeting/common/predicates/predicates.H> #include <errl/errlmanager.H> - +#include <config.h> +#include <algorithm> namespace TARGETING { namespace UTIL { +#ifdef CONFIG_BMC_IPMI + uint32_t getIPMISensorNumber( const TARGETING::Target*& i_targ, + TARGETING::SENSOR_NAME i_name ); +#endif + + #define TARG_NAMESPACE "TARGETING::UTIL" #define TARG_CLASS "" @@ -101,6 +110,177 @@ void getMasterNodeTarget(Target*& o_masterNodeTarget) o_masterNodeTarget = masterNodeTarget; } +// return the sensor number from the passed in target +uint32_t getSensorNumber( const TARGETING::Target* i_pTarget, + TARGETING::SENSOR_NAME i_name ) +{ + +#ifdef CONFIG_BMC_IPMI + // get the IPMI sensor number from the array, these are unique for each + // sensor + sensor owner in an IPMI system + return getIPMISensorNumber( i_pTarget, i_name ); +#else + // pass back the HUID - this will be the sensor number for non ipmi based + // systems + return get_huid( i_pTarget ); + +#endif + +} + +// convert sensor number to a target +TARGETING::Target * getSensorTarget(const uint32_t i_sensorNumber ) +{ + +#ifdef CONFIG_BMC_IPMI + return TARGETING::UTIL::getTargetFromIPMISensor( i_sensorNumber ); +#else + // in non ipmi systems huid == sensor number + return Target::getTargetFromHuid( i_sensorNumber ); +#endif + +} + +// predicate for binary search of ipmi sensors array. +// given an array[][2] compare the sensor name, located in the first column, +// to the passed in key value +static inline bool name_predicate( uint16_t (&a)[2], uint16_t key ) +{ + return a[TARGETING::IPMI_SENSOR_ARRAY_NAME_OFFSET] < key; +}; + +#ifdef CONFIG_BMC_IPMI +// given a target and sensor name, return the IPMI sensor number +// from the IPMI_SENSORS attribute. +uint32_t getIPMISensorNumber( const TARGETING::Target*& i_targ, + TARGETING::SENSOR_NAME i_name ) +{ + // $TODO RTC:123035 investigate pre-populating some info if we end up + // doing this multiple times per sensor + // + // Helper function to search the sensor data for the correct sensor number + // based on the sensor name. + // + uint8_t l_sensor_number = INVALID_IPMI_SENSOR; + + const TARGETING::Target * l_targ = i_targ; + + if( i_targ == NULL ) + { + TARGETING::Target * sys; + // use the system target + TARGETING::targetService().getTopLevelTarget(sys); + + // die if there is no system target + assert(sys); + + l_targ = sys; + } + + TARGETING::AttributeTraits<TARGETING::ATTR_IPMI_SENSORS>::Type l_sensors; + + // if there is no sensor attribute, we will return INVALID_IPMI_SENSOR(0xFF) + if( l_targ->tryGetAttr<TARGETING::ATTR_IPMI_SENSORS>(l_sensors) ) + { + // get the number of rows by dividing the total size by the size of + // the first row + uint16_t array_rows = (sizeof(l_sensors)/sizeof(l_sensors[0])); + + // create an iterator pointing to the first element of the array + uint16_t (*begin)[2] = &l_sensors[0]; + + // using the number entries as the index into the array will set the + // end iterator to the correct position or one entry past the last + // element of the array + uint16_t (*end)[2] = &l_sensors[array_rows]; + + uint16_t (*ptr)[2] = + std::lower_bound(begin, end, i_name, &name_predicate); + + // we have not reached the end of the array and the iterator + // returned from lower_bound is pointing to an entry which equals + // the one we are searching for. + if( ( ptr != end ) && + ( (*ptr)[TARGETING::IPMI_SENSOR_ARRAY_NAME_OFFSET] == i_name ) ) + { + // found it + l_sensor_number = + (*ptr)[TARGETING::IPMI_SENSOR_ARRAY_NUMBER_OFFSET]; + + } + } + return l_sensor_number; +} + +class number_predicate +{ + public: + + number_predicate( const uint32_t number ) + :iv_number(number) + {}; + + bool operator()( const uint16_t (&a)[2] ) const + { + return a[TARGETING::IPMI_SENSOR_ARRAY_NUMBER_OFFSET] == iv_number; + } + + private: + uint32_t iv_number; +}; + +//****************************************************************************** +// getTargetFromIPMISensor() +//****************************************************************************** +Target * getTargetFromIPMISensor( uint32_t i_sensorNumber ) +{ + + // if the size of HUID is made larger than a uint32_t the compile will fail + CPPASSERT((sizeof(TARGETING::ATTR_HUID_type) > sizeof(i_sensorNumber))); + + // 1. find targets with IPMI_SENSOR attribute which has sensor numbers + // 2. search array for the sensor number (not sorted on this column) + // 3. return the target + + TARGETING::Target * l_target = NULL; + + TARGETING::AttributeTraits<TARGETING::ATTR_IPMI_SENSORS>::Type l_sensors; + + for (TargetIterator itr = TARGETING::targetService().begin(); + itr != TARGETING::targetService().end(); ++itr) + { + // if there is a sensors attribute, see if our number is in it + if( (*itr)->tryGetAttr<TARGETING::ATTR_IPMI_SENSORS>(l_sensors)) + { + uint16_t array_rows = (sizeof(l_sensors)/sizeof(l_sensors[0])); + + // create an iterator pointing to the first sensor number of the + // array. + uint16_t (*begin)[2] = + &l_sensors[TARGETING::IPMI_SENSOR_ARRAY_NAME_OFFSET]; + + // using the number entries as the index into the array will set the + // end iterator to the correct position or one entry past the last + // element of the array + uint16_t (*end)[2] = &l_sensors[array_rows]; + + uint16_t (*ptr)[2] = std::find_if(begin, end, + number_predicate(i_sensorNumber)); + + if ( ptr != end ) + { + // found it + l_target = *itr; + break; + } + } + } + return l_target; +} + + +#endif + #undef TARG_NAMESPACE #undef TARG_CLASS |