From f79af2d77bdc37321d3de5e1c645b6f7b44ece61 Mon Sep 17 00:00:00 2001 From: "Richard J. Knight" Date: Tue, 9 Aug 2016 14:06:44 -0500 Subject: Add support for getTarget(type, instance) -Add function to convert an arbitrary target type and instance into a fapi2 target type. Change-Id: I41a70a881160bebeeac97ff4e8b74c002d6224d8 Depends-on: I1de1da708146427ada3f9cc4e1977dd608172cf4 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/28107 Tested-by: Jenkins Server Tested-by: FSP CI Jenkins Reviewed-by: Daniel M. Crowell Reviewed-by: Sachin Gupta Reviewed-by: William G. Hoffa --- src/include/usr/fapi2/target.H | 65 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) (limited to 'src/include/usr/fapi2') diff --git a/src/include/usr/fapi2/target.H b/src/include/usr/fapi2/target.H index 737313e5a..a02142d77 100644 --- a/src/include/usr/fapi2/target.H +++ b/src/include/usr/fapi2/target.H @@ -1105,9 +1105,70 @@ inline void toString(const Target *i_target, char* io_buffer, size_t i_bsi { toString(*i_target, io_buffer, i_bsize); } - /// -/// @brief Get an enumerated target of a specific type +/// @brief Get a target from its Type and instance info +/// @tparam T The type of the target to return +/// @tparam V type of the targets value +/// @param[in] i_type - Type of target to find +/// @param[in] instance - instance of the target to find +/// +/// @return Target* pointer to a target of type T +/// +/// NOTE: Function caller owns the object returned. +/// +#ifdef FAPI2_ENABLE_PLATFORM_GET_TARGET +template +inline Target* getTarget(TargetType i_type, uint8_t instance) +{ + + Target * l_target = NULL; + + TARGETING::TYPE l_type = convertFapi2TypeToTargeting(i_type); + + // get a list of all the targets + TARGETING::TargetService& l_targetService = TARGETING::targetService(); + TARGETING::TargetRangeFilter l_targets(l_targetService.begin(), + l_targetService.end()); + + // create a check for the desired target type + TARGETING::PredicateCTM l_typePredicate; + + l_typePredicate.setType(l_type); + + // create a check for the FAPI_POS of a target + TARGETING::PredicateAttrVal + l_fapiPosAttr(instance); + + TARGETING::PredicatePostfixExpr l_Query; + + // look for the type and instance + l_Query.push(&l_typePredicate).push(&l_fapiPosAttr).And(); + + l_targets.setPredicate(&l_Query); + + // reset l_targets to contain only the targets matching our predicates + l_targets.reset(); + + TARGETING::Target * l_t = NULL; + + uint32_t l_count = 0; + for(; l_targets; ++l_targets, ++l_count) + { + l_t = *l_targets; + } + + // we should not find more than one target + assert(!(l_count > 1)); + + if(l_count == 1) + { + l_target = new fapi2::Target(l_t); + } + + return l_target; + +} +#endif /// @tparam T The type of the target /// @param[in] Ordinal representing the ordinal number of /// the desired target -- cgit v1.2.3