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/usr/targeting/common/xmltohb/xmltohb.pl | |
parent | f27bc3697954b533d4ce6eaec260d250cda527de (diff) | |
download | talos-hostboot-a61fc8350beb8439fedd080b04c5d83789a36dcd.tar.gz talos-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/usr/targeting/common/xmltohb/xmltohb.pl')
-rwxr-xr-x | src/usr/targeting/common/xmltohb/xmltohb.pl | 382 |
1 files changed, 382 insertions, 0 deletions
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 ##### |