diff options
| author | Nick Bofferding <bofferdn@us.ibm.com> | 2013-09-22 16:33:03 -0500 |
|---|---|---|
| committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2013-09-30 21:10:45 -0500 |
| commit | a61fc8350beb8439fedd080b04c5d83789a36dcd (patch) | |
| tree | 26224f3a8dfc0f6f64827b3e50f348335375fd59 /src | |
| parent | f27bc3697954b533d4ce6eaec260d250cda527de (diff) | |
| download | blackbird-hostboot-a61fc8350beb8439fedd080b04c5d83789a36dcd.tar.gz blackbird-hostboot-a61fc8350beb8439fedd080b04c5d83789a36dcd.zip | |
Support attribute write callback and generate attribute metadata
- Added targeting support to register/deregister/invoke attribute write callback
- Modified attribute compiler to generate attribute metadata source files
- Added generated attribute metadata source files to common targeting makefile
Change-Id: I4496dd5351bbf107ae6c2bc790d8e4289815b4a3
RTC: 82231
Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/6286
Tested-by: Jenkins Server
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/include/usr/targeting/common/target.H | 68 | ||||
| -rw-r--r-- | src/usr/targeting/common/target.C | 41 | ||||
| -rw-r--r-- | src/usr/targeting/common/xmltohb/common.mk | 6 | ||||
| -rwxr-xr-x | src/usr/targeting/common/xmltohb/xmltohb.pl | 382 |
4 files changed, 481 insertions, 16 deletions
diff --git a/src/include/usr/targeting/common/target.H b/src/include/usr/targeting/common/target.H index f41a96e4c..f3f9be002 100644 --- a/src/include/usr/targeting/common/target.H +++ b/src/include/usr/targeting/common/target.H @@ -86,6 +86,11 @@ typedef Target* TargetHandle_t; typedef std::vector<TargetHandle_t> TargetHandleList; typedef std::vector<Target> TargetList; +// Function pointer declaration to install/uninstall the attribute write +// callback +typedef void (*pCallbackFuncPtr) (const Target* const, const ATTRIBUTE_ID, \ + const uint32_t, const void* const); + class Target { @@ -210,7 +215,7 @@ class Target * @brief Returns pointer to a mutex attribute associated with the * target * - * @pre Target service must be initialized and the mutex attribute + * @pre Target service must be initialized and the mutex attribute * must exist * * @post See brief section @@ -242,7 +247,7 @@ class Target * updated with the address of the mutex attribute if it exists * (ignored otherwise) * - * @pre Target service must be initialized + * @pre Target service must be initialized * * @post See brief section * @@ -250,7 +255,7 @@ class Target * * @retval true Attribute was found (and returned) * @retval false Attribute was not found, o_pMutex was not updated - */ + */ template<const ATTRIBUTE_ID A> bool tryGetHbMutexAttr( mutex_t*& o_pMutex) const; @@ -272,7 +277,7 @@ class Target typename AttributeTraits<A>::Type const& i_attrValue) { bool l_wrote = trySetAttr<A>(i_attrValue); - + //@TODO: Remove assert once release has stabilized TARG_ASSERT(l_wrote,"TARGETING::Target::setAttr<0x%7x>: trySetAttr returned false",A); } @@ -290,7 +295,7 @@ class Target uint8_t * targetFFDC( uint32_t & o_size ) const; /** - * @brief Returns the target handle referencing a target whose HUID + * @brief Returns the target handle referencing a target whose HUID * matches the caller supplied value * * @param[in] i_huid HUID of target to find @@ -303,9 +308,9 @@ class Target * @retval !NULL Target handle referencing a target whose HUID matches * the caller supplied value. * @retval NULL No target found whose HUID matches the caller supplied - * value. + * value. */ - Target* getTargetFromHuid(const ATTR_HUID_type i_huid) const; + static Target* getTargetFromHuid(const ATTR_HUID_type i_huid); /** * @brief Return the Targeting Override Attribute Tank @@ -327,6 +332,34 @@ class Target return cv_syncTank; } + /** + * @brief Install the targeting attribute write callback, + * provided by user. This gets triggered on every setAttr/trySetAttr + * instantiation on the targeting interface. User might write a + * method as per the callback function type provided, to have + * use-case as per the requirement. + * + * @param[in] i_callBackFunc, User defined callback function of the + * type pCallbackFuncPtr. + * + * @return bool, indicates the status of the request. + * @retval true, if the callback installation is success + * @retval false, if callback is already installed. + */ + static bool installWriteAttributeCallback( + pCallbackFuncPtr & i_callBackFunc); + + /** + * @brief uninstall the targeting attribute write callback, provided + * by user. which gets installed via installWriteAttributeCallback + * method. + * + * @return bool, indicates the status of the request. + * @retval true, if the callback is uninstalled + * @retval false, if the callback uninstall fails. + */ + static bool uninstallWriteAttributeCallback(); + private: // Private helper interfaces /** @@ -404,7 +437,7 @@ class Target * * @param[in] i_attribute Mutex attribute to return * - * @pre Target service must be initialized and the mutex attribute + * @pre Target service must be initialized and the mutex attribute * must exist * * @post See brief section @@ -439,7 +472,7 @@ class Target * updated with the address of the mutex attribute if it exists * (ignored otherwise) * - * @pre Target service must be initialized + * @pre Target service must be initialized * * @post See brief section * @@ -447,7 +480,7 @@ class Target * * @retval true Attribute was found (and returned) * @retval false Attribute was not found, o_pMutex was not updated - */ + */ bool _tryGetHbMutexAttr( const ATTRIBUTE_ID i_attribute, mutex_t*& o_pMutex) const; @@ -485,11 +518,15 @@ class Target */ uint8_t getAttrTankTargetUnitPos() const; + private: // Function pointer variable declaration + + static pCallbackFuncPtr cv_pCallbackFuncPtr; + private: // Private instance variables uint32_t iv_attrs; ///< Total attributes allowed for this ///< instance - + // Pointer to array of valid attributes TARGETING::AbstractPointer<ATTRIBUTE_ID> iv_pAttrNames; @@ -531,6 +568,11 @@ class Target const fapi::Target *, TARGETING::ATTRIBUTE_ID, const uint32_t, void *); + /* + * @brief allow targetattrbulksync access to the target class store. + */ + friend class TargetAttrBulkSync; + } PACKED; template<const ATTRIBUTE_ID A> @@ -538,8 +580,8 @@ typename AttributeTraits<A>::Type Target::getAttr() const { typename AttributeTraits<A>::Type l_attrValue; bool l_read = tryGetAttr<A>(l_attrValue); - - //@TODO Remove assert once release has stablized + + //@TODO Remove assert once release has stablized TARG_ASSERT(l_read,"TARGETING::Target::getAttr<0x%7x>: tryGetAttr returned false",A); return l_attrValue; } diff --git a/src/usr/targeting/common/target.C b/src/usr/targeting/common/target.C index 86e8440e6..5209c3891 100644 --- a/src/usr/targeting/common/target.C +++ b/src/usr/targeting/common/target.C @@ -51,6 +51,9 @@ namespace TARGETING #define TARG_NAMESPACE "TARGETING::" #define TARG_CLASS "Target::" +// Static function pointer variable allocation +pCallbackFuncPtr Target::cv_pCallbackFuncPtr = NULL; + //****************************************************************************** // Target::~Target //****************************************************************************** @@ -180,6 +183,10 @@ bool Target::_trySetAttr( if (l_pAttrData) { memcpy(l_pAttrData, i_pAttrData, i_size); + if( unlikely(cv_pCallbackFuncPtr != NULL) ) + { + cv_pCallbackFuncPtr(this, i_attr, i_size, i_pAttrData); + } } return (l_pAttrData != NULL); @@ -398,7 +405,7 @@ uint8_t * Target::targetFFDC( uint32_t & o_size ) const //****************************************************************************** Target* Target::getTargetFromHuid( - const ATTR_HUID_type i_huid) const + const ATTR_HUID_type i_huid) { #define TARG_FN "getTargetFromHuid" Target* l_pTarget = NULL; @@ -506,6 +513,38 @@ uint8_t Target::getAttrTankTargetUnitPos() const } //****************************************************************************** +// Target::installWriteAttributeCallback +//****************************************************************************** +bool Target::installWriteAttributeCallback( + TARGETING::pCallbackFuncPtr & i_callBackFunc) +{ + #define TARG_FN "installWriteAttributeCallback" + TARG_ENTER(); + + return __sync_bool_compare_and_swap(&cv_pCallbackFuncPtr, + NULL, i_callBackFunc); + TARG_EXIT(); + #undef TARG_FN +} + +//****************************************************************************** +// Target::uninstallWriteAttributeCallback +//****************************************************************************** +bool Target::uninstallWriteAttributeCallback() +{ + #define TARG_FN "uninstallWriteAttributeCallback" + TARG_ENTER(); + + __sync_synchronize(); + cv_pCallbackFuncPtr = NULL; + __sync_synchronize(); + return true; + + TARG_EXIT(); + #undef TARG_FN +} + +//****************************************************************************** // Attribute Tanks //****************************************************************************** AttributeTank Target::cv_overrideTank; diff --git a/src/usr/targeting/common/xmltohb/common.mk b/src/usr/targeting/common/xmltohb/common.mk index 26f470b8d..8561911fd 100644 --- a/src/usr/targeting/common/xmltohb/common.mk +++ b/src/usr/targeting/common/xmltohb/common.mk @@ -36,13 +36,15 @@ XMLTOHB_HEADER_TARGETS = \ attributestructs.H \ pnortargeting.H \ fapiplatattrmacros.H \ - test_ep.H + test_ep.H \ + mapattrmetadata.H XMLTOHB_SOURCE_TARGETS = \ attributestrings.C \ attributedump.C \ errludattribute.C \ - errludtarget.C + errludtarget.C \ + mapattrmetadata.C XMLTOHB_SYSTEM_BINARIES = \ vbu_VENICE_targeting.bin \ diff --git a/src/usr/targeting/common/xmltohb/xmltohb.pl b/src/usr/targeting/common/xmltohb/xmltohb.pl index 3397c2f20..d180ac0f9 100755 --- a/src/usr/targeting/common/xmltohb/xmltohb.pl +++ b/src/usr/targeting/common/xmltohb/xmltohb.pl @@ -248,6 +248,22 @@ if( !($cfgSrcOutputDir =~ "none") ) my $attrInfoCsvFile = *ATTR_INFO_CSV_FILE; writeAttrInfoCsvFile($attributes,$attrInfoCsvFile); close $attrInfoCsvFile; + + open(MAP_ATTR_METADATA_H_FILE,">$cfgSrcOutputDir"."mapattrmetadata.H") + or fatal ("Attribute metadata map file Header: \"$cfgSrcOutputDir" + . "mapattrmetadata.H\" could not be opened."); + my $attrMetadataMapHFile = *MAP_ATTR_METADATA_H_FILE; + writeAttrMetadataMapHFile($attrMetadataMapHFile); + close $attrMetadataMapHFile; + + open(MAP_ATTR_METADATA_C_FILE,">$cfgSrcOutputDir"."mapattrmetadata.C") + or fatal ("Attribute metadata map C file: \"$cfgSrcOutputDir" + . "mapattrmetadata.C\" could not be opened."); + my $attrMetadataMapCFile = *MAP_ATTR_METADATA_C_FILE; + writeAttrMetadataMapCFileHeader($attrMetadataMapCFile); + writeAttrMetadataMapCFile($attributes,$attrMetadataMapCFile); + writeAttrMetadataMapCFileFooter($attrMetadataMapCFile); + close $attrMetadataMapCFile; } if( !($cfgImgOutputDir =~ "none") ) @@ -2368,6 +2384,372 @@ sub writeAttrInfoCsvFile { } } # sub writeAttrInfoCsvFile +################################################################################ +# Writes the unordered/Ordered map of all target attribute metadata +# C file header +################################################################################ + +sub writeAttrMetadataMapCFileHeader { + my($outFile) = @_; + +print $outFile <<VERBATIM; + +/** + * \@file mapattrmetadata.C + * + * \@brief Interface to get the unordered/ordered map of all target attributes + * with respective attribute size and read/write properties. This file is + * autogenerated and should not be altered. + */ + +// TARG +#include <mapattrmetadata.H> + +//****************************************************************************** +// Macros +//****************************************************************************** + +#undef TARG_NAMESPACE +#undef TARG_CLASS +#undef TARG_FUNC + +//****************************************************************************** +// Implementation +//****************************************************************************** + +namespace TARGETING +{ + +#define TARG_NAMESPACE "TARGETING::" +#define TARG_CLASS "MapAttrMetadata::" + +// Persistency defines +static const char * P0_PERSISTENCY = "p0"; +static const char * P1_PERSISTENCY = "p1"; +static const char * P3_PERSISTENCY = "p3"; + +//****************************************************************************** +// TARGETING::mapAttrMetadata +//****************************************************************************** + +TARGETING::MapAttrMetadata& mapAttrMetadata() +{ + #define TARG_FN "mapAttrMetadata()" + + return TARG_GET_SINGLETON(TARGETING::theMapAttrMetadata); + + #undef TARG_FN +} + +//****************************************************************************** +// TARGETING::MapAttrMetadata::~MapAttrMetadata +//****************************************************************************** + +MapAttrMetadata::~MapAttrMetadata() +{ + #define TARG_FN "~MapAttrMetadata()" + #undef TARG_FN +} + +//****************************************************************************** +// TARGETING::MapAttrMetadata::getMapMetadataForAllAttributes +//****************************************************************************** + +const AttrMetadataMapper& +MapAttrMetadata::getMapMetadataForAllAttributes() const +{ + #define TARG_FN "getMapMetadataForAllAttributes()" + TARG_ENTER(); + + TARG_EXIT(); + return iv_mapAttrMetadata; + + #undef TARG_FN +} + +//****************************************************************************** +// TARGETING::MapAttrMetadata::MapAttrMetadata +//****************************************************************************** + +MapAttrMetadata::MapAttrMetadata() +{ + #define TARG_FN "MapAttrMetadata()" +VERBATIM + +} + +################################################################################ +# Create a .C file to put All Target Attributes along with there respective +# Size and read/write properties in a unordered/ordered map variable +################################################################################ + +sub writeAttrMetadataMapCFile{ + my($attributes,$outFile) = @_; + my %finalAttrhash = (); + + # look for all attributes in the XML + foreach my $attribute (@{$attributes->{attribute}}) + { + $finalAttrhash{$attribute->{id}} = $attribute; + } + + print $outFile "\n"; + print $outFile " static const Pair_t l_pair[] = {\n"; + + foreach my $key ( keys %finalAttrhash) + { + if(!(exists $finalAttrhash{$key}->{hbOnly})) + { + # Fetch the Size of the attribute + my $keySize = "ATTR_"."$key"."_type"; + if(exists $finalAttrhash{$key}->{simpleType}) + { + if(exists $finalAttrhash{$key}->{simpleType}->{string}) + { + if(exists $finalAttrhash{$key}->{simpleType}->{string}-> + {sizeInclNull}) + { + $keySize = "$keySize"."[$finalAttrhash{$key}-> + {simpleType}->{string}->{sizeInclNull}]"; + } + } + } + elsif(!(exists $finalAttrhash{$key}->{complexType}) && + !(exists $finalAttrhash{$key}->{nativeType})) + { + print STDOUT "\t// ### Attribute $key is Not Supported\n"; + next; + } + print $outFile " std::make_pair( ATTR_".$key.","; + print $outFile " AttrMetadataStr(sizeof($keySize),"; + + # Fetch Read/Writeable Property + if(exists $finalAttrhash{$key}->{writeable}) + { + print $outFile " true,"; + } + else + { + print $outFile " false,"; + } + + if(!(exists $finalAttrhash{$key}->{persistency})) + { + fatal("Attribute[$key] should have persistency by default"); + } + if($finalAttrhash{$key}->{persistency} eq "non-volatile") + { + print $outFile " P3_PERSISTENCY) ),\n"; + } + elsif(($finalAttrhash{$key}->{persistency} eq + "semi-non-volatile-zeroed") || + ($finalAttrhash{$key}->{persistency} eq "semi-non-volatile")) + { + print $outFile " P1_PERSISTENCY) ),\n"; + } + elsif(($finalAttrhash{$key}->{persistency} eq "volatile") || + ($finalAttrhash{$key}->{persistency} eq "volatile-zeroed")) + { + print $outFile " P0_PERSISTENCY) ),\n"; + } + else + { + fatal("Not a defined" . + "Persistency[$finalAttrhash{$key}->{persistency}] for" . + "attribute [$key]"); + } + } + } + print $outFile " };\n"; + print $outFile " iv_mapAttrMetadata\.insert( l_pair,\n"; + print $outFile " l_pair + (sizeof(l_pair)/sizeof(l_pair[0])) );\n\n"; +} + +################################################################################ +# Writes the map all attr size C file Footer +################################################################################ + +sub writeAttrMetadataMapCFileFooter { + my($outFile) = @_; + + print $outFile <<VERBATIM; + #undef TARG_FN +} + +}// namespace TARGETING + +VERBATIM +} + +################################################################################ +# Create a .H file to put All Target Attributes along with their respective +# Size and read/write properties in a unordered/ordered map variable +################################################################################ + +sub writeAttrMetadataMapHFile{ + my($outFile) = @_; + print $outFile <<VERBATIM; + +#ifndef MAPATTRMETADATA_H +#define MAPATTRMETADATA_H + +/** + * \@file mapattrmetadata.H + * + * \@brief Interface to get the unordered/ordered map of all target attributes + * respective attribute size and read/write properties. This file is + * autogenerated and should not be altered. + */ + +// STD +#ifndef __HOSTBOOT_MODULE +#include <tr1/unordered_map> +#else +#include <map> +#endif + +// TARG +#include <targeting/common/trace.H> +#include <targeting/common/target.H> + +//****************************************************************************** +// Macros +//****************************************************************************** + +#undef TARG_NAMESPACE +#undef TARG_CLASS +#undef TARG_FUNC + +//****************************************************************************** +// Interface +//****************************************************************************** + +#ifndef __HOSTBOOT_MODULE +/* + * \@brief Specialized Hash function Template to be inserted with unordered_map + */ +namespace std +{ + +namespace tr1 +{ + template <> + struct hash<TARGETING::ATTRIBUTE_ID> : public unary_function< + TARGETING::ATTRIBUTE_ID, size_t> + { + size_t operator()(const TARGETING::ATTRIBUTE_ID& attrId) const + { + return attrId; + } + }; +} + +} +#endif + +namespace TARGETING +{ + +/* + * \@brief - Data Struct to contain attribute related info + * + * Field Description + * \@field1 - Size: Size of the attribute + * \@field2 - readWriteable: true if read and writeable else false only readable + * \@field3 - Persistency level of the attribute + */ +struct attrMetadataStr +{ + uint32_t size; + bool readWriteable; + const char* persistency; + + attrMetadataStr() : + size(0), readWriteable(false), persistency(NULL) {} + + attrMetadataStr(uint32_t i_size, bool i_rw, const char* i_persistency) : + size(i_size), readWriteable(i_rw), persistency(i_persistency) {} +}; + +/* + * \@brief Typedef for struct attrMetadataStr + */ +typedef struct attrMetadataStr AttrMetadataStr; + +/* + * \@brief Typedef for pair<ATTRIBUTE_ID, AttrMetadataStr> + */ +typedef std::pair<ATTRIBUTE_ID, AttrMetadataStr> Pair_t; + +#ifndef __HOSTBOOT_MODULE +/* + * \@brief Typedef std::tr1::unordered_map <attr, struct attrMetadataStr, + * hash_method> + */ +typedef std::tr1::unordered_map<ATTRIBUTE_ID, AttrMetadataStr, \ + std::tr1::hash<TARGETING::ATTRIBUTE_ID> > AttrMetadataMapper; +#else +/* + * \@brief Typedef std::map <attr, struct attrMetadataStr> + */ +typedef std::map<ATTRIBUTE_ID, AttrMetadataStr> AttrMetadataMapper; +#endif + +class MapAttrMetadata +{ + public: + /** + * \@brief Destroy the MapAttrMetadata class + */ + ~MapAttrMetadata(); + + /** + * \@brief Create the MapAttrMetadata class + */ + MapAttrMetadata(); + + /* + * \@brief returns the unordered/ordered map of all attributes as + * key and struct attrMetadataStr as value, which contains the size + * of the attribute along with read/writeable properties + * + * \@return, returns the unordered/ordered map which has the all + * attributes as key and struct attrMetadataStr as value pair, + * variable <ATTRIBUTE_ID::struct attrMetadataStr> + */ + const AttrMetadataMapper& getMapMetadataForAllAttributes() const; + + private: + + /* Unordered/Ordered map variable for All Attribute Ids vs Size & + * Read/Write properties */ + AttrMetadataMapper iv_mapAttrMetadata; + + /* Disable Copy constructor and assignment operator */ + MapAttrMetadata( + const MapAttrMetadata& i_right); + + MapAttrMetadata& operator = ( + const MapAttrMetadata& i_right); +}; + +/** + * \@brief Provide singleton access to the MapAttrMetadata + */ +TARG_DECLARE_SINGLETON(TARGETING::MapAttrMetadata, theMapAttrMetadata); + +#undef TARG_CLASS +#undef TARG_NAMESPACE + + +}// namespace TARGETING + +#endif // MAPATTRMETADATA_H + +VERBATIM + +} + ###### #Create a .C file to put target into the errlog ##### |

