summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9
diff options
context:
space:
mode:
Diffstat (limited to 'src/import/chips/p9')
-rw-r--r--src/import/chips/p9/procedures/hwp/memory/lib/shared/mss_kind.H23
-rw-r--r--src/import/chips/p9/procedures/hwp/memory/lib/utils/c_str.C65
-rw-r--r--src/import/chips/p9/procedures/hwp/memory/lib/utils/c_str.H110
3 files changed, 29 insertions, 169 deletions
diff --git a/src/import/chips/p9/procedures/hwp/memory/lib/shared/mss_kind.H b/src/import/chips/p9/procedures/hwp/memory/lib/shared/mss_kind.H
index b89fc304c..564fe22bb 100644
--- a/src/import/chips/p9/procedures/hwp/memory/lib/shared/mss_kind.H
+++ b/src/import/chips/p9/procedures/hwp/memory/lib/shared/mss_kind.H
@@ -7,7 +7,7 @@
/* */
/* EKB Project */
/* */
-/* COPYRIGHT 2015 */
+/* COPYRIGHT 2015,2016 */
/* [+] International Business Machines Corp. */
/* */
/* */
@@ -22,7 +22,7 @@
/// @brief Implementation of mss specific types
///
// *HWP HWP Owner: Brian Silver <bsilver@us.ibm.com>
-// *HWP HWP Backup: Craig Hamilton <cchamilt@us.ibm.com>
+// *HWP HWP Backup: Andre Marin <aamarin@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: HB:FSP
@@ -32,28 +32,11 @@
#include <fapi2.H>
-///
-/// @brief Class to compile-time inspect whether an API has an overload
-/// @note contains a static bool which defaults to false. Any overload
-/// will specialize this template and replace the value with true.
-///
-#define REGISTER_API( __api_name, ... ) \
- template< mss::kind_t K, __VA_ARGS__ > \
- struct __api_name##_overload \
- { static const bool available = false; };
-
-//
-// Overload definitions for the specializations
-//
-#define REGISTER_OVERLOAD( __api_name, __kind, ... ) \
- template<> \
- struct __api_name##_overload< __kind, __VA_ARGS__> \
- { static const bool available = true; };
-
namespace mss
{
// These must be contiguous and unique
+/// Kind's of DIMM/DRAM used to descriminate in templates.
enum kind_t
{
// The default, base, etc. kind. Used to define the function
diff --git a/src/import/chips/p9/procedures/hwp/memory/lib/utils/c_str.C b/src/import/chips/p9/procedures/hwp/memory/lib/utils/c_str.C
index 6db3cc45c..ad7a80941 100644
--- a/src/import/chips/p9/procedures/hwp/memory/lib/utils/c_str.C
+++ b/src/import/chips/p9/procedures/hwp/memory/lib/utils/c_str.C
@@ -22,7 +22,7 @@
/// @brief Storage for the C-string name of a thing
///
// *HWP HWP Owner: Brian Silver <bsilver@us.ibm.com>
-// *HWP HWP Backup: Craig Hamilton <cchamilt@us.ibm.com>
+// *HWP HWP Backup: Andre Marin <aamarin@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: HB:FSP
@@ -44,42 +44,15 @@ namespace mss
// Thread local storage for the string we're going to create.
thread_local char c_str_storage[fapi2::MAX_ECMD_STRING_LEN];
-template< fapi2::TargetType T >
-char const* make_c_str_helper( char const* s, const fapi2::Target<T>& i_target);
-
-template<>
-char const* c_str<DEFAULT_KIND, TARGET_TYPE_DIMM>( const fapi2::Target<TARGET_TYPE_DIMM>& i_target )
-{
- return make_c_str_helper(" unknown dimm", i_target);
-}
-
-template<>
-char const* c_str<KIND_RDIMM_DDR4, TARGET_TYPE_DIMM>( const fapi2::Target<TARGET_TYPE_DIMM>& i_target )
-{
- return make_c_str_helper(" rdimm (ddr4)", i_target);
-}
-
-template<>
-char const* c_str<KIND_RDIMM_EMPTY, TARGET_TYPE_DIMM>( const fapi2::Target<TARGET_TYPE_DIMM>& i_target )
-{
- return make_c_str_helper(" rdimm (empty)", i_target);
-}
-
-template<>
-char const* c_str<KIND_LRDIMM_DDR4, TARGET_TYPE_DIMM>( const fapi2::Target<TARGET_TYPE_DIMM>& i_target )
-{
- return make_c_str_helper(" lrdimm (ddr4)", i_target);
-}
-
template<>
-char const* c_str<KIND_LRDIMM_EMPTY, TARGET_TYPE_DIMM>( const fapi2::Target<TARGET_TYPE_DIMM>& i_target )
+const char* c_str( const fapi2::template Target<fapi2::TARGET_TYPE_DIMM>& i_target )
{
- return make_c_str_helper(" lrdimm (empty)", i_target);
-}
+ constexpr auto l_max_gen = 3;
+ constexpr auto l_max_type = 4;
+ static const char* l_map_gen_to_string[l_max_gen] = {"empty", "DDR3", "DDR4"};
+ static const char* l_map_type_to_string[l_max_type] = {"empty", "RDIMM", "UDIMM", "LRDIMM"};
+ char l_buffer[fapi2::MAX_ECMD_STRING_LEN];
-template<>
-char const* c_str<FORCE_DISPATCH, TARGET_TYPE_DIMM>( const fapi2::Target<TARGET_TYPE_DIMM>& i_target )
-{
uint8_t l_type = 0;
uint8_t l_gen = 0;
@@ -87,6 +60,8 @@ char const* c_str<FORCE_DISPATCH, TARGET_TYPE_DIMM>( const fapi2::Target<TARGET_
auto l_mca = i_target.getParent<TARGET_TYPE_MCA>();
auto l_mcs = l_mca.getParent<TARGET_TYPE_MCS>();
+ fapi2::toString( i_target, c_str_storage, fapi2::MAX_ECMD_STRING_LEN );
+
// Had to unroll FAPI_TRY so that fapi2::current_err doesn't get overwritten, causes errors
// when calling c_str inside of a function that returns fapi2::ReturnCode
if (FAPI_ATTR_GET(fapi2::ATTR_EFF_DIMM_TYPE, l_mcs, l_value) != FAPI2_RC_SUCCESS)
@@ -96,6 +71,11 @@ char const* c_str<FORCE_DISPATCH, TARGET_TYPE_DIMM>( const fapi2::Target<TARGET_
l_type = l_value[mss::index(l_mca)][mss::index(i_target)];
+ if (l_type >= l_max_type)
+ {
+ goto fapi_try_exit;
+ }
+
// Had to unroll FAPI_TRY so that fapi2::current_err doesn't get overwritten, causes errors
// when calling c_str inside of a function that returns fapi2::ReturnCode
if (FAPI_ATTR_GET(fapi2::ATTR_EFF_DRAM_GEN, l_mcs, l_value) != FAPI2_RC_SUCCESS)
@@ -105,18 +85,17 @@ char const* c_str<FORCE_DISPATCH, TARGET_TYPE_DIMM>( const fapi2::Target<TARGET_
l_gen = l_value[mss::index(l_mca)][mss::index(i_target)];
- return c_str_dispatch<FORCE_DISPATCH, TARGET_TYPE_DIMM>(dimm_kind( l_type, l_gen ), i_target);
+ if (l_gen >= l_max_gen)
+ {
+ goto fapi_try_exit;
+ }
+
+ snprintf(l_buffer, fapi2::MAX_ECMD_STRING_LEN, " %s (%s)", l_map_type_to_string[l_type], l_map_gen_to_string[l_gen]);
+ return strncat( c_str_storage, l_buffer, fapi2::MAX_ECMD_STRING_LEN - strlen(c_str_storage) );
fapi_try_exit:
// Probably the best we're going to do ...
- return "couldn't get dimm type, dram gen";
-}
-
-template< fapi2::TargetType T >
-char const* make_c_str_helper( char const* s, const fapi2::Target<T>& i_target)
-{
- fapi2::toString( i_target, c_str_storage, fapi2::MAX_ECMD_STRING_LEN );
- return strncat( c_str_storage, s, fapi2::MAX_ECMD_STRING_LEN - strlen(c_str_storage) );
+ return c_str_storage;
}
}
diff --git a/src/import/chips/p9/procedures/hwp/memory/lib/utils/c_str.H b/src/import/chips/p9/procedures/hwp/memory/lib/utils/c_str.H
index 7a8855b04..0b6263dc4 100644
--- a/src/import/chips/p9/procedures/hwp/memory/lib/utils/c_str.H
+++ b/src/import/chips/p9/procedures/hwp/memory/lib/utils/c_str.H
@@ -7,7 +7,7 @@
/* */
/* EKB Project */
/* */
-/* COPYRIGHT 2015 */
+/* COPYRIGHT 2015,2016 */
/* [+] International Business Machines Corp. */
/* */
/* */
@@ -22,7 +22,7 @@
/// @brief Function to return the C-string name of a thing
///
// *HWP HWP Owner: Brian Silver <bsilver@us.ibm.com>
-// *HWP HWP Backup: Craig Hamilton <cchamilt@us.ibm.com>
+// *HWP HWP Backup: Andre Marin <aamarin@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: HB:FSP
@@ -32,123 +32,21 @@
#include <fapi2.H>
-///
-/// @remark To create an overloaded function a few things need to be defined.
-/// Sorry.
-///
-
-/// -# Document the function and define its signature *as a comment* Why as a comment?
-/// We're going to use SFINAE to expose this signature if there has been no overload
-/// defined for any of the template arguments. So, we don't know if this signature will
-/// be the correct one until we instantiate the template. So this is here simply for
-/// documentation. We do need a simple way for our callers to know how to call this
-/// non-traditionally defined function - so we do that here.
-
-///
-/// @brief return the c-string name of the input, including any extension to the name defined by its type
-/// @tparam T, the fapi2::TargetType of the input - derived.
-/// @param[in] i_target, the fapi2::Target of interest
-/// @return char const* a thread-safe c-string containing the element's name
-/// @note to call: char* s = c_str(i_target);
-///
-//template< fapi2::TargetType T>
-//const char* c_str( const fapi2::Target<T>& i_target);
-
-///
-/// -# Include the header which defines all the macros which will
-/// expand into our overload templates. Note that the pre-processor
-/// is single-pass so all of the pre-requisites for the larger macros
-/// need to be defined prior to including them.
-///
-#include "../shared/mss_kind.H"
-
namespace mss
{
// Thread local storage for the string we're going to create.
extern thread_local char c_str_storage[fapi2::MAX_ECMD_STRING_LEN];
-/// -# Register the API.
-/// -# Define the template parameters for the overloaded function
-/// @note the first argument is the api name, and the rest are the api's template parameters.
-/// @note this creates __api_name##_overload - so in this case it defines
-/// c_str_overload which is used below to mame decisions.
-REGISTER_API( c_str, fapi2::TargetType T );
-
-/// -# Register the specific overloads. The first parameter is the name
-/// of the api, the second is the kind of the element which is being
-/// overloaded - an RDIMM, an LRDIMM, etc. The remaining parameters
-/// indicate the specialization of the api itself.
-/// @note You need to define the "DEFAULT_KIND" here as an overload. This
-/// allows the mechanism to find the "base" implementation for things which
-/// have no specific overload.
-REGISTER_OVERLOAD( c_str, DEFAULT_KIND, fapi2::TARGET_TYPE_DIMM );
-REGISTER_OVERLOAD( c_str, KIND_RDIMM_DDR4, fapi2::TARGET_TYPE_DIMM );
-REGISTER_OVERLOAD( c_str, KIND_RDIMM_EMPTY, fapi2::TARGET_TYPE_DIMM );
-REGISTER_OVERLOAD( c_str, KIND_LRDIMM_DDR4, fapi2::TARGET_TYPE_DIMM );
-REGISTER_OVERLOAD( c_str, KIND_LRDIMM_EMPTY, fapi2::TARGET_TYPE_DIMM );
-
-///
-/// -# Define the default case for overloaded calls. enable_if states that
-/// if there is a DEFAULT_KIND overload for this TargetType, then this
-/// entry point will be defined. Note the general case below is enabled if
-/// there is no overload defined for this TargetType
-///
-
-template< mss::kind_t K = FORCE_DISPATCH, fapi2::TargetType T >
-typename std::enable_if< c_str_overload<DEFAULT_KIND, T>::available, const char*>::type
-c_str( const fapi2::template Target<T>& i_target );
-
-///
-/// -# Register the handler for the API, not the overloads. This is the
-/// code which implements the general case of the template. Because it
-/// is not a full specialization of the template, it must be defiend in
-/// this header.
-///
template< fapi2::TargetType T >
-typename std::enable_if < ! c_str_overload<DEFAULT_KIND, T>::available, const char* >::type
-c_str( const fapi2::template Target<T>& i_target )
+const char* c_str( const fapi2::template Target<T>& i_target )
{
fapi2::toString( i_target, c_str_storage, fapi2::MAX_ECMD_STRING_LEN );
return c_str_storage;
}
-//
-// We know we registered overloads for c_str, so we need the entry point to
-// the dispatcher. Add a set of these for all TargetTypes which get overloads
-// for this API
-//
-template<>
-char const* c_str<FORCE_DISPATCH, fapi2::TARGET_TYPE_DIMM>( const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target );
-
-template<>
-char const* c_str<DEFAULT_KIND, fapi2::TARGET_TYPE_DIMM>( const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target );
-
-//
-// Boilerplate dispatcher
-//
-template< kind_t K, fapi2::TargetType T, bool B = c_str_overload<K, T>::available >
-inline char const * c_str_dispatch( const kind_t& i_kind, const fapi2::Target<T>& i_target )
-{
- // We dispatch to another kind if:
- // We don't have an overload defined (B == false)
- // Or, if we do have an overload (B == true) and this is not out kind.
- if ((B == false) || ((B == true) && (K != i_kind)))
- {
- return c_str_dispatch < (kind_t)(K - 1), T > (i_kind, i_target);
- }
-
- // Otherwise, we call the overload.
- return c_str<K, T>(i_target);
-}
-
-// DEFAULT_KIND is 0 so this is the end of the recursion
template<>
-inline char const* c_str_dispatch<DEFAULT_KIND, fapi2::TARGET_TYPE_DIMM>(const kind_t&,
- const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target)
-{
- return c_str<DEFAULT_KIND, fapi2::TARGET_TYPE_DIMM>(i_target);
-}
+const char* c_str( const fapi2::template Target<fapi2::TARGET_TYPE_DIMM>& i_target );
}
#endif
OpenPOWER on IntegriCloud