From 5bdb1f8ec34124c68db869dbb46b27e5a5fc24b5 Mon Sep 17 00:00:00 2001 From: Jaymes Wilks Date: Fri, 24 Feb 2017 15:08:57 -0600 Subject: Populate HDAT TPM Info Populate TPM Info during the secureboot runtime routine. Change-Id: I02b960c175d51dc9b5941e15a529bd1587747444 RTC:166834 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/37187 Tested-by: Jenkins Server Tested-by: Jenkins OP Build CI Tested-by: FSP CI Jenkins Reviewed-by: Stephen M. Cprek Reviewed-by: Michael Baiocchi Reviewed-by: Daniel M. Crowell --- src/usr/hdat/hdatcommonutil.C | 109 ++++++++++++++++++++++++++++++++++++++++++ src/usr/hdat/hdathdif.C | 6 --- src/usr/hdat/hdattpmdata.C | 60 +---------------------- src/usr/hdat/hdattpmdata.H | 42 ++++++++++++++-- src/usr/hdat/hdatutil.C | 6 +-- 5 files changed, 150 insertions(+), 73 deletions(-) create mode 100644 src/usr/hdat/hdatcommonutil.C (limited to 'src/usr/hdat') diff --git a/src/usr/hdat/hdatcommonutil.C b/src/usr/hdat/hdatcommonutil.C new file mode 100644 index 000000000..350b5b727 --- /dev/null +++ b/src/usr/hdat/hdatcommonutil.C @@ -0,0 +1,109 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/hdat/hdatcommonutil.C $ */ +/* */ +/* OpenPOWER HostBoot Project */ +/* */ +/* Contributors Listed Below - COPYRIGHT 2017 */ +/* [+] International Business Machines Corp. */ +/* */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); */ +/* you may not use this file except in compliance with the License. */ +/* You may obtain a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ +/* implied. See the License for the specific language governing */ +/* permissions and limitations under the License. */ +/* */ +/* IBM_PROLOG_END_TAG */ +#include +#include "hdattpmdata.H" +#include +#include + +#include +#include +#include + +namespace HDAT +{ +trace_desc_t *g_trac_hdat = nullptr; +TRAC_INIT(&g_trac_hdat,HDAT_COMP_NAME,4096); + +/** @brief Structure id for an HDIF structure*/ +const uint16_t HDAT_HDIF_STRUCT_ID = 0xD1F0; + +/** @brief Align value for HDAT instances */ +const uint8_t HDAT_HDIF_ALIGN = 128; + +const char g_hdatTpmDataEyeCatch[] = "TPMREL"; + +uint16_t hdatCalcMaxTpmsPerNode() +{ + size_t l_maxTpms = 0; + + // calculate max # of TPMs per node + + // look for class ENC type NODE and class chip TPM to find TPMs + TARGETING::TargetHandleList l_nodeEncList; + + getEncResources(l_nodeEncList, TARGETING::TYPE_NODE, + TARGETING::UTIL_FILTER_ALL); + + // loop thru the nodes and check number of TPMs + std::for_each(l_nodeEncList.begin(), l_nodeEncList.end(), + [&l_maxTpms](const TARGETING::Target* const i_pNode) + { + // for this Node, get a list of tpms + TARGETING::TargetHandleList l_tpmChipList; + + getChildAffinityTargets ( l_tpmChipList, i_pNode, + TARGETING::CLASS_CHIP, TARGETING::TYPE_TPM, false ); + + l_maxTpms = std::max(l_maxTpms, l_tpmChipList.size()); + } ); + return l_maxTpms; +} + +uint32_t hdatTpmDataCalcMaxSize() +{ + uint32_t l_size = 0; + + // TODO RTC 167290 - In order to support multiple nodes, this calculation + // needs to be #nodes * [ the entire 18.x set of structures ] and the + // initialization needs to be done on each instance. The reported size + // (in variable o_size) needs to be the size of a single instance and the + // reported count (via o_count) needs to be the number of nodes. For now, + // we assume one node. + + // account for the size of the TPM data header + l_size += sizeof(hdatTpmData_t); + + // account for the size of the TPM Info array header + l_size += sizeof(hdatSbTpmInfo_t); + + // account for each element of the TPM Info array + l_size += ((sizeof(hdatSbTpmInstInfo_t) + + TPM_SRTM_EVENT_LOG_MAX + + TPM_DRTM_EVENT_LOG_MAX) + * hdatCalcMaxTpmsPerNode()); + + // account for User physical interaction mechanism info struct + // and Host I2C device information pointers + l_size += (sizeof(hdatPhysInterMechInfo_t) + sizeof(hdatI2cDevInfoPtrs_t) * + NUM_I2C_PHYS_PRESENCE_DEVICES); + + // Align size value to match actual allocated size, because we also want to + // zero the padded part, and thus simplify multinode support going forward. + l_size = ALIGN_X(l_size, HDAT_HDIF_ALIGN); + + return l_size; +} + +} diff --git a/src/usr/hdat/hdathdif.C b/src/usr/hdat/hdathdif.C index 7ce7d1bfb..329a1bd37 100755 --- a/src/usr/hdat/hdathdif.C +++ b/src/usr/hdat/hdathdif.C @@ -58,9 +58,6 @@ const int32_t HDAT_FAILURE = -1; /** @brief No children for a data structure*/ const uint32_t HDAT_NO_CHILD = 0; -/** @brief Structure id for an HDIF structure*/ -const uint16_t HDAT_HDIF_STRUCT_ID = 0xD1F0; - /** @brief FFDC Version to classify data in error log */ const uint8_t HDAT_VERSION1 = 1; @@ -72,9 +69,6 @@ const uint8_t HDAT_NACA_FFDC_SUBSEC2 = 3; const uint32_t HDAT_REAL_ADDRESS_MASK = 0x80000000; const uint64_t HDAT_REAL_ADDRESS_MASK64 = 0x8000000000000000ull; -/** @brief Align value for HDAT instances */ -const uint8_t HDAT_HDIF_ALIGN = 128; - /** @brief See the prologue in hdathdif.H */ diff --git a/src/usr/hdat/hdattpmdata.C b/src/usr/hdat/hdattpmdata.C index 8b13fe4e8..dddfc6c67 100644 --- a/src/usr/hdat/hdattpmdata.C +++ b/src/usr/hdat/hdattpmdata.C @@ -46,8 +46,6 @@ namespace HDAT extern trace_desc_t *g_trac_hdat; -const uint8_t g_hdatTpmDataEyeCatch[] = {'T', 'P', 'M', 'R', 'E', 'L'}; - HdatTpmData::HdatTpmData(errlHndl_t &o_errlHndl, const HDAT::hdatMsAddr_t &i_msAddr): iv_msAddr(i_msAddr), @@ -147,36 +145,9 @@ errlHndl_t HdatTpmData::hdatLoadTpmData(uint32_t &o_size, uint32_t &o_count) { errlHndl_t l_errl = nullptr; - o_size = 0; o_count = 0; - // TODO RTC 167290 - In order to support multiple nodes, this calculation - // needs to be #nodes * [ the entire 18.x set of structures ] and the - // initialization needs to be done on each instance. The reported size - // (in variable o_size) needs to be the size of a single instance and the - // reported count (via o_count) needs to be the number of nodes. For now, - // we assume one node. - - // account for the size of the TPM data header - o_size += sizeof(hdatTpmData_t); - - // account for the size of the TPM Info array header - o_size += sizeof(hdatSbTpmInfo_t); - - // account for each element of the TPM Info array - o_size += ((sizeof(hdatSbTpmInstInfo_t) + - TPM_SRTM_EVENT_LOG_MAX + - TPM_DRTM_EVENT_LOG_MAX) - * hdatCalcMaxTpmsPerNode()); - - // account for User physical interaction mechanism info struct - // and Host I2C device information pointers - o_size += (sizeof(hdatPhysInterMechInfo_t) + sizeof(hdatI2cDevInfoPtrs_t) * - NUM_I2C_PHYS_PRESENCE_DEVICES); - - // Align size value to match actual allocated size, because we also want to - // zero the padded part, and thus simplify multinode support going forward. - o_size = ALIGN_X(o_size, HDAT_HDIF_ALIGN); + o_size = hdatTpmDataCalcMaxSize(); // zero all of it memset(iv_hdatTpmData,0,o_size); @@ -191,7 +162,7 @@ errlHndl_t HdatTpmData::hdatLoadTpmData(uint32_t &o_size, uint32_t &o_count) // add the eyecatcher memcpy(iv_hdatTpmData->hdatHdr.hdatStructName, g_hdatTpmDataEyeCatch, - sizeof(g_hdatTpmDataEyeCatch)); + strlen(g_hdatTpmDataEyeCatch)); // account for this one instance of Node TPM Related Data ++o_count; @@ -199,31 +170,4 @@ errlHndl_t HdatTpmData::hdatLoadTpmData(uint32_t &o_size, uint32_t &o_count) return l_errl; } -uint16_t hdatCalcMaxTpmsPerNode() -{ - size_t l_maxTpms = 0; - - // calculate max # of TPMs per node - - // look for class ENC type NODE and class chip TPM to find TPMs - TARGETING::TargetHandleList l_nodeEncList; - - getEncResources(l_nodeEncList, TARGETING::TYPE_NODE, - TARGETING::UTIL_FILTER_ALL); - - // loop thru the nodes and check number of TPMs - std::for_each(l_nodeEncList.begin(), l_nodeEncList.end(), - [&l_maxTpms](const TARGETING::Target* const i_pNode) - { - // for this Node, get a list of tpms - TARGETING::TargetHandleList l_tpmChipList; - - getChildAffinityTargets ( l_tpmChipList, i_pNode, - TARGETING::CLASS_CHIP, TARGETING::TYPE_TPM, false ); - - l_maxTpms = std::max(l_maxTpms, l_tpmChipList.size()); - } ); - return l_maxTpms; -} - } diff --git a/src/usr/hdat/hdattpmdata.H b/src/usr/hdat/hdattpmdata.H index d17172366..ec7ccb3e5 100644 --- a/src/usr/hdat/hdattpmdata.H +++ b/src/usr/hdat/hdattpmdata.H @@ -49,6 +49,28 @@ namespace HDAT { +/** + * @brief Enumeration definition for known defaults to TPM data fields + */ +enum { + TpmDataInstance = 0, + TpmDataVersion = 0x10, + TpmDataHdrSize = 0x20, + TpmDataPtrOffset = 0x20, + TpmDataPtrCnt = 1, + TpmDataChildStrCnt = 0, + TpmDataChildStrOffset = 0, +}; + +/** + * @brief Enumeration definition for the TPM states of existence + */ +enum TpmState { + TpmPresentAndFunctional = 0x1, + TpmPresentNonFunctional = 0x2, + TpmNonPresent = 0x3, +}; + /** * @brief Structure definition for HDAT Tpm Node Data Header */ @@ -68,7 +90,7 @@ struct hdatSbTpmInfo_t { uint32_t hdatSbTpmArrayOffset; uint32_t hdatSbTpmArrayNumEntries; - uint32_t hdatSbTpmArraySize; + uint32_t hdatSbTpmArrayEntrySize; } __attribute__ ((packed)); @@ -91,9 +113,8 @@ struct hdatSbTpmInstInfo_t uint32_t hdatTpmDrtmEventLogEntrySize; } __attribute__ ((packed)); - /** - * @brief Structure definition for HDAT physical interaction mechanism info + * @brief Structure definition for HDAT physical interaction mechanism info */ struct hdatPhysInterMechInfo_t { @@ -102,9 +123,8 @@ struct hdatPhysInterMechInfo_t uint32_t hdatSizeOfI2cDevInfoPtrs; } __attribute__ ((packed)); - /** - * @brief Structure definition for HDAT Host I2c Device Information pointers + * @brief Structure definition for HDAT Host I2C Device Info pointers */ struct hdatI2cDevInfoPtrs_t { @@ -113,6 +133,7 @@ struct hdatI2cDevInfoPtrs_t uint32_t hdatHostI2cLinkId; } __attribute__ ((packed)); +extern const char g_hdatTpmDataEyeCatch[]; /** Begin Class Description * @@ -226,5 +247,16 @@ class HdatTpmData */ uint16_t hdatCalcMaxTpmsPerNode(); +/** + * @brief Calculate the maximum size of the HDAT TPM data section + * + * @pre None + * + * @post None + * + * @retval uint32_t Maximum size of the HDAT TPM data section + */ +uint32_t hdatTpmDataCalcMaxSize(); + } #endif // HDATTPMDATA_H diff --git a/src/usr/hdat/hdatutil.C b/src/usr/hdat/hdatutil.C index 456584316..3e8ef607e 100644 --- a/src/usr/hdat/hdatutil.C +++ b/src/usr/hdat/hdatutil.C @@ -34,11 +34,9 @@ using namespace TARGETING; namespace HDAT { -trace_desc_t *g_trac_hdat = NULL; -TRAC_INIT(&g_trac_hdat,HDAT_COMP_NAME,4096); +extern trace_desc_t *g_trac_hdat; - -/******************************************************************************* +/*****************************************************************************n * hdatBldErrLog *******************************************************************************/ void hdatBldErrLog(errlHndl_t & io_err, -- cgit v1.2.1