diff options
Diffstat (limited to 'src/include/usr/hwpf/plat/fapiPlatAttributeService.H')
-rwxr-xr-x | src/include/usr/hwpf/plat/fapiPlatAttributeService.H | 288 |
1 files changed, 288 insertions, 0 deletions
diff --git a/src/include/usr/hwpf/plat/fapiPlatAttributeService.H b/src/include/usr/hwpf/plat/fapiPlatAttributeService.H index 834f2facf..a60abcb38 100755 --- a/src/include/usr/hwpf/plat/fapiPlatAttributeService.H +++ b/src/include/usr/hwpf/plat/fapiPlatAttributeService.H @@ -52,8 +52,10 @@ #include <fapiplatattrmacros.H> #include <hwpf/fapi/fapiReturnCode.H> #include <hwpf/fapi/fapiTarget.H> +#include <hwpf/fapi/fapiAttributeOverride.H> #include <spd/spdenums.H> #include <dimmConsts.H> +#include <util/singleton.H> //****************************************************************************** // Interface @@ -163,10 +165,290 @@ fapi::ReturnCode fapiPlatGetTargetName(const fapi::Target * i_pTarget, fapi::ReturnCode fapiPlatGetFunctional(const fapi::Target * i_pTarget, uint8_t & o_functional); +/** + * @brief This function is called by the FAPI_ATTR_GET macro when getting + * ATTR_POS. It should not be called directly + * + * This is needed because the HWPF attribute is a uint32_t and the Hostboot + * attribute is a uint16_t so a direct map will not work + * + * @param[in] i_pFapiTarget Target pointer + * @param[out] o_pos Output Posititon + * @return ReturnCode. Zero on success, else platform specified error + */ +fapi::ReturnCode fapiPlatGetTargetPos(const fapi::Target * i_pFapiTarget, + uint32_t & o_pos); + +/** + * @brief This wrapper function is called by the getAttrOverride function + * templates (which are called by FAPI_PLAT_GET_ATTR_OVERRIDE) to get an + * attribute override value + * + * This wrapper just invokes getAttrOverride on the AttributeOverrides singleton + * in the local (plat) module, it is needed because Singletons cannot be + * accessed outside of a module (this results in a duplicate singleton) + * + * @param[in] i_attrId Attribute ID + * @param[in] i_pTarget Pointer to Target (NULL if system) + * @param[out] o_overrideVal Reference to value filled in with the override + * @param[in] i_arrayD1 Array dimension 1 if applicable + * @param[in] i_arrayD2 Array dimension 2 if applicable + * @param[in] i_arrayD3 Array dimension 3 if applicable + * @param[in] i_arrayD4 Array dimension 4 if applicable + * @return bool True if override value was returned + */ +bool getOverrideWrap(const fapi::AttributeId i_attrId, + const fapi::Target * const i_pTarget, + uint64_t & o_overrideVal, + const uint8_t i_arrayD1 = ATTR_ARRAYD_NA, + const uint8_t i_arrayD2 = ATTR_ARRAYD_NA, + const uint8_t i_arrayD3 = ATTR_ARRAYD_NA, + const uint8_t i_arrayD4 = ATTR_ARRAYD_NA); + +/** + * @brief This wrapper function is called by + * FAPI_PLAT_CLEAR_NON_CONST_ATTR_OVERRIDE to clear a non-const attribute + * override. + * + * This wrapper just invokes clearNonConstOverride on the AttributeOverrides + * singleton in the local (plat) module, it is needed because Singletons cannot + * be accessed outside of a module (this results in a duplicate singleton) + * + * @param[in] i_attrId Attribute ID + * @param[in] i_pTarget Pointer to Target (NULL if system) + */ +void clearNonConstOverrideWrap(const fapi::AttributeId i_attrId, + const fapi::Target * const i_pTarget); + +/** + * @brief This wrapper function is called by HWP unit test to set an attribute + * override. It is not called by production code (outside of unit test, + * attribute overrides are set by the FSP or by a debug tool) + * + * This wrapper just invokes setOverride on the AttributeOverrides singleton in + * the local (plat) module, it is needed because Singletons cannot be accessed + * outside of a module (this results in a duplicate singleton) + * + * @param[in] i_override Reference to override + */ +void setOverrideWrap(const AttributeOverride & i_override); + +/** + * @brief This wrapper function is called by HWP unit test to clear all + * attribute overrides. It is not called by production code (outside of + * unit test, attribute overrides are cleared by the FSP or by a debug + * tool) + * + * This wrapper just invokes clearOverrides on the AttributeOverrides singleton + * in the local (plat) module, it is needed because Singletons cannot be + * accessed outside of a module (this results in a duplicate singleton) + */ +void clearOverridesWrap(); + +/** + * @brief This wrapper function is called by HWP unit test to test if any + * attribute overrides exist. It is not called by production code. + * + * This wrapper just invokes overridesExist on the AttributeOverrides singleton + * in the local (plat) module, it is needed because Singletons cannot be + * accessed outside of a module (this results in a duplicate singleton) + */ +bool overridesExistWrap(); + +/** + * @brief This function template is called by the FAPI_PLAT_GET_ATTR_OVERRIDE + * macro to get any override for a 1D array attribute + * + * @param[in] i_attrId Attribute ID + * @param[in] i_pTarget Pointer to Target (NULL if system) + * @param[out] o_1dArray Reference to 1D array where override will be copied to + * @return bool True if override was returned + */ +template <typename T, uint8_t SZ1> +bool getOverrideT(const fapi::AttributeId i_attrId, + const fapi::Target * const i_pTarget, + T(&o_1dArray)[SZ1]) +{ + uint64_t l_overrideVal = 0; + + for (uint8_t d1 = 0; d1 < SZ1; d1++) + { + if (!(getOverrideWrap(i_attrId, i_pTarget, l_overrideVal, d1))) + { + // For array attributes, all elements must be overridden + return false; + } + else + { + // Standard conversion converts uint64_t to attribute type + o_1dArray[d1] = l_overrideVal; + } + } + + return true; +} + +/** + * @brief This function template is called by the FAPI_PLAT_GET_ATTR_OVERRIDE + * macro to get any override for a 2D array attribute + * + * @param[in] i_attrId Attribute ID + * @param[in] i_pTarget Pointer to Target (NULL if system) + * @param[out] o_2dArray Reference to 2D array where override will be copied to + * @return bool True if override was returned + */ +template <typename T, uint8_t SZ1, uint8_t SZ2> +bool getOverrideT(const fapi::AttributeId i_attrId, + const fapi::Target * const i_pTarget, + T(&o_2dArray)[SZ1][SZ2]) +{ + uint64_t l_overrideVal = 0; + + for (uint8_t d1 = 0; d1 < SZ1; d1++) + { + for (uint8_t d2 = 0; d2 < SZ2; d2++) + { + if (!(getOverrideWrap(i_attrId, i_pTarget, l_overrideVal, d1, d2))) + { + // For array attributes, all elements must be overridden + return false; + } + else + { + // Standard conversion converts uint64_t to attribute type + o_2dArray[d1][d2] = l_overrideVal; + } + } + } + + return true; +} + +/** + * @brief This function template is called by the FAPI_PLAT_GET_ATTR_OVERRIDE + * macro to get any override for a 3D array attribute + * + * @param[in] i_attrId Attribute ID + * @param[in] i_pTarget Pointer to Target (NULL if system) + * @param[out] o_3dArray Reference to 3D array where override will be copied to + * @return bool True if override was returned + */ +template <typename T, uint8_t SZ1, uint8_t SZ2, uint8_t SZ3> +bool getOverrideT(const fapi::AttributeId i_attrId, + const fapi::Target * const i_pTarget, + T(&o_3dArray)[SZ1][SZ2][SZ3]) +{ + uint64_t l_overrideVal = 0; + + for (uint8_t d1 = 0; d1 < SZ1; d1++) + { + for (uint8_t d2 = 0; d2 < SZ2; d2++) + { + for (uint8_t d3 = 0; d3 < SZ3; d3++) + { + if (!(getOverrideWrap(i_attrId, i_pTarget, l_overrideVal, d1, + d2, d3))) + { + // For array attributes, all elements must be overridden + return false; + } + else + { + // Standard conversion converts uint64_t to attribute type + o_3dArray[d1][d2][d3] = l_overrideVal; + } + } + } + } + + return true; +} + +/** + * @brief This function template is called by the FAPI_PLAT_GET_ATTR_OVERRIDE + * macro to get any override for a 4D array attribute + * + * @param[in] i_attrId Attribute ID + * @param[in] i_pTarget Pointer to Target (NULL if system) + * @param[out] o_4dArray Reference to 4D array where override will be copied to + * @return bool True if override was returned + */ +template <typename T, uint8_t SZ1, uint8_t SZ2, uint8_t SZ3, uint8_t SZ4> +bool getOverrideT(const fapi::AttributeId i_attrId, + const fapi::Target * const i_pTarget, + T(&o_4dArray)[SZ1][SZ2][SZ3][SZ4]) +{ + uint64_t l_overrideVal = 0; + + for (uint8_t d1 = 0; d1 < SZ1; d1++) + { + for (uint8_t d2 = 0; d2 < SZ2; d2++) + { + for (uint8_t d3 = 0; d3 < SZ3; d3++) + { + for (uint8_t d4 = 0; d4 < SZ4; d4++) + { + if (!(getOverrideWrap(i_attrId, i_pTarget, l_overrideVal, + d1, d2, d3, d4))) + { + // For array attributes, all elements must be overridden + return false; + } + else + { + // Standard conversion converts uint64_t to attribute + // type + o_4dArray[d1][d2][d3][d4] = l_overrideVal; + } + } + } + } + } + + return true; } +/** + * @brief This function template is called by the FAPI_PLAT_GET_ATTR_OVERRIDE + * macro to get any override for a non-array attribute + * + * @param[in] i_attrId Attribute ID + * @param[in] i_pTarget Pointer to Target (NULL if system) + * @param[out] o_val Reference to variable where override will be copied to + * @return bool True if override was returned + */ +template <typename T> +bool getOverrideT(const fapi::AttributeId i_attrId, + const fapi::Target * const i_pTarget, + T & o_val) +{ + uint64_t l_overrideVal = 0; + + if (!(getOverrideWrap(i_attrId, i_pTarget, l_overrideVal))) + { + return false; + } + + o_val = static_cast<T>(l_overrideVal); + return true; } +} // namespace platAttrSvc + +} // namespace fapi + +/** + * @brief Macro that returns any attribute override + */ +#define FAPI_PLAT_GET_ATTR_OVERRIDE(ID, PTARGET, VAL) \ + fapi::platAttrSvc::getOverrideT(ID, PTARGET, VAL) + +/** + * @brief Macro that clears any non-const attribute override + */ +#define FAPI_PLAT_CLEAR_NON_CONST_ATTR_OVERRIDE(ID, PTARGET) \ + fapi::platAttrSvc::clearNonConstOverrideWrap(ID, PTARGET) + /** * @brief Macro which directly maps a FAPI request to get a platform * attribute to the equivalent host boot request @@ -315,4 +597,10 @@ fapi::ReturnCode fapiPlatGetFunctional(const fapi::Target * i_pTarget, #define ATTR_FUNCTIONAL_GETMACRO(ID, PTARGET, VAL) \ fapi::platAttrSvc::fapiPlatGetFunctional(PTARGET, VAL) +//------------------------------------------------------------------------------ +// MACRO to route ATTR_POS access to the correct Hostboot function +//------------------------------------------------------------------------------ +#define ATTR_POS_GETMACRO(ID, PTARGET, VAL) \ + fapi::platAttrSvc::fapiPlatGetTargetPos(PTARGET, VAL) + #endif // FAPIPLATATTRIBUTESERVICE_H_ |