From d6aaf2fe4f15c5360bb67fde5fc96f437ba3d271 Mon Sep 17 00:00:00 2001 From: Jaymes Wilks Date: Mon, 13 Feb 2017 13:50:26 -0600 Subject: Setup TPM Related Info Section in HDAT Add the ability to store TPM Related Information in HDAT for OpenPower systems. Change-Id: I3782ac3d5717565cacc60902c35178ec013b7711 RTC:166834 Signed-off-by: Jaymes Wilks Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/36374 Reviewed-by: Nicholas E. Bofferding Tested-by: Jenkins Server Tested-by: Jenkins OP Build CI Tested-by: FSP CI Jenkins Reviewed-by: Michael Baiocchi Reviewed-by: Stephen M. Cprek Reviewed-by: Daniel M. Crowell --- src/usr/hdat/hdatspiraS.C | 30 ++++++- src/usr/hdat/hdatspiraS.H | 4 +- src/usr/hdat/hdattpmdata.C | 145 ++++++++++++++++++++++++++++++++++ src/usr/hdat/hdattpmdata.H | 191 +++++++++++++++++++++++++++++++++++++++++++++ src/usr/hdat/hdatutil.C | 3 +- src/usr/hdat/hdatutil.H | 7 +- src/usr/hdat/makefile | 1 + 7 files changed, 375 insertions(+), 6 deletions(-) create mode 100644 src/usr/hdat/hdattpmdata.C create mode 100644 src/usr/hdat/hdattpmdata.H (limited to 'src/usr/hdat') diff --git a/src/usr/hdat/hdatspiraS.C b/src/usr/hdat/hdatspiraS.C index da84e275b..df36a0ae5 100755 --- a/src/usr/hdat/hdatspiraS.C +++ b/src/usr/hdat/hdatspiraS.C @@ -55,6 +55,7 @@ #include "hdatiohub.H" #include "hdathbrt.H" #include "hdatipmi.H" +#include "hdattpmdata.H" #include #include @@ -573,7 +574,7 @@ errlHndl_t HdatSpiraS::loadDataArea( const hdat5Tuple_t& i_spirasHostEntry, } } break; - case HDAT_SPIRAS_IPMI: + case HDAT_SPIRAS_IPMI: { HDAT_DBG("Calling IPMI Sensor Data structure from spiras"); l_err = hdatLoadIpmi(l_addrToPass,l_size,l_count); @@ -587,11 +588,36 @@ errlHndl_t HdatSpiraS::loadDataArea( const hdat5Tuple_t& i_spirasHostEntry, } } break; + case HDAT_SPIRAS_TPM_RELATED: + { + HDAT_DBG("calling TPM DATA from spiras"); + HdatTpmData l_tpmData(l_err, l_addrToPass); + + if ( nullptr == l_err) + { + l_err = l_tpmData.hdatLoadTpmData(l_size, l_count); + + if ( nullptr == l_err ) + { + HDAT_DBG("returned from TPM DATA, size=0x%x,count=%d", + l_size, l_count); + } + else + { + HDAT_ERR("could not load TPM DATA"); + } + } + else + { + HDAT_ERR("could not create TPM DATA object"); + } + } + break; default: { HDAT_ERR("not a valid data area"); } - break; + break; } if (l_err) diff --git a/src/usr/hdat/hdatspiraS.H b/src/usr/hdat/hdatspiraS.H index d536f3652..e8f3de188 100755 --- a/src/usr/hdat/hdatspiraS.H +++ b/src/usr/hdat/hdatspiraS.H @@ -81,8 +81,8 @@ enum hdatSpiraSDataAreas HDAT_SPIRAS_HOSTSR = 14, // HOSTSR (Host service data) HDAT_SPIRAS_HBRT = 15, //HBRT (runtime data) HDAT_SPIRAS_IPMI = 16, // IPMI Sensor MApping Data - - HDAT_SPIRAS_DA_LAST = 17 + HDAT_SPIRAS_TPM_RELATED = 17, // Node TPM Related Data + HDAT_SPIRAS_DA_LAST = 18 }; diff --git a/src/usr/hdat/hdattpmdata.C b/src/usr/hdat/hdattpmdata.C new file mode 100644 index 000000000..b714ba1df --- /dev/null +++ b/src/usr/hdat/hdattpmdata.C @@ -0,0 +1,145 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/hdat/hdattpmdata.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 "hdatutil.H" +#include +#include +#include +#include +#include + +#include +#include + +namespace HDAT +{ + +extern trace_desc_t *g_trac_hdat; + +HdatTpmData::HdatTpmData(errlHndl_t &o_errlHndl, + const HDAT::hdatMsAddr_t &i_msAddr): + iv_msAddr(i_msAddr), + iv_hdatTpmData(nullptr) +{ + assert(o_errlHndl == nullptr,"The error log handle passed must be nullptr"); + + const uint64_t l_baseAddr = static_cast(i_msAddr.hi) << 32 + | i_msAddr.lo; + + const uint64_t l_size = ALIGN_PAGE(sizeof(hdatTpmData_t)) + PAGESIZE; + + const uint64_t l_alignedAddr = ALIGN_PAGE_DOWN(l_baseAddr); + + auto l_virtAddr = reinterpret_cast( + mm_block_map(reinterpret_cast(l_alignedAddr),l_size)); + if (l_virtAddr) + { + const auto l_offset = l_baseAddr - l_alignedAddr; + + iv_hdatTpmData = reinterpret_cast(l_virtAddr + + l_offset); + + // TODO RTC 167290 - This memset needs to be revisited for multinode + // support. We may need to do this memset once per node or use some + // other approach to initialization. + memset(iv_hdatTpmData, 0x0, sizeof(hdatTpmData_t)); + + HDAT_DBG("Ctr iv_hdatTpmData addr 0x%.16llX virtual addr 0x%.16llX", + reinterpret_cast(iv_hdatTpmData), + reinterpret_cast(l_virtAddr)); + } + else + { + /*@ + * @errortype + * @moduleid HDAT::MOD_TPMDATA_CONSTRUCTOR + * @reasoncode HDAT::RC_DEV_MAP_FAIL + * @userdata1[00:31] Address attempted to map upper + * @userdata1[32:63] Address attempted to map lower + * @userdata2[00:31] Size of mapped region upper + * @userdata2[32:63] Size of mapped region lower + * @devdesc Creation of mapped region failed + * @custdesc Firmware encountered an internal error + */ + hdatBldErrLog(o_errlHndl, + MOD_TPMDATA_CONSTRUCTOR, + RC_DEV_MAP_FAIL, + static_cast(UINT64_HIGH(l_alignedAddr)), + static_cast(UINT64_LOW(l_alignedAddr)), + static_cast(UINT64_HIGH(l_size)), + static_cast(UINT64_LOW(l_size)), + ERRORLOG::ERRL_SEV_UNRECOVERABLE, + HDAT_VERSION1, + false); + } +} + +HdatTpmData::~HdatTpmData() +{ + const uint64_t l_unmapAddr = ALIGN_PAGE_DOWN( + reinterpret_cast(iv_hdatTpmData)); + + // if the constructor successfully mapped the region then + // it must be unmapped + if (iv_hdatTpmData) + { + auto rc = mm_block_unmap(reinterpret_cast(l_unmapAddr)); + if (rc) + { + errlHndl_t l_errl = nullptr; + /*@ + * @errortype + * @severity ERRL_SEV_UNRECOVERABLE + * @moduleid HDAT::MOD_TPMDATA_DESTRUCTOR + * @reasoncode HDAT::RC_DEV_MAP_FAIL + * @userdata1[00:31] Address attempted to unmap upper + * @userdata1[32:63] Address attempted to unmap lower + * @devdesc Unmap of a mapped region failed + * @custdesc Firmware encountered an internal error + */ + hdatBldErrLog(l_errl, + MOD_TPMDATA_DESTRUCTOR, + RC_DEV_MAP_FAIL, + static_cast(UINT64_HIGH(l_unmapAddr)), + static_cast(UINT64_LOW(l_unmapAddr)), + 0, 0, + ERRORLOG::ERRL_SEV_UNRECOVERABLE, + HDAT_VERSION1, + true); + } + iv_hdatTpmData = nullptr; + } +} + +errlHndl_t HdatTpmData::hdatLoadTpmData(uint32_t &o_size,uint32_t &o_count) +{ + errlHndl_t l_errl = nullptr; + + return l_errl; +} + +} diff --git a/src/usr/hdat/hdattpmdata.H b/src/usr/hdat/hdattpmdata.H new file mode 100644 index 000000000..ce92b46a7 --- /dev/null +++ b/src/usr/hdat/hdattpmdata.H @@ -0,0 +1,191 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/hdat/hdattpmdata.H $ */ +/* */ +/* 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 */ +#ifndef HDATTPMDATA_H +#define HDATTPMDATA_H + +/** + * @file hdattpmdata.H + * + * @brief This file contains the class definition for the TPM data object + * which manages the HDAT TPM section. + * + */ + +#include +#include +#include +#include "hdatutil.H" +#include + +namespace HDAT +{ + +/** + * @brief Structure definition for HDAT Tpm Node Related Data header + */ +struct hdatTpmData_t +{ + hdatHDIF_t hdatHdr; + hdatHDIFDataHdr_t hdatSbTpmInfo; // Pointer pair to secure boot TPM info + hdatHDIFDataHdr_t hdatPhysInter; // Physical interaction mechanism details + uint8_t hdatReserved1[16]; // Padding for alignment and growth/compatibility +} __attribute__ ((packed)); + + +/** + * @brief Structure definition for Secureboot TPM Info Array + */ +struct hdatSbTpmInfo_t +{ + uint32_t hdatSbTpmArrayOffset; + uint32_t hdatSbTpmArrayNumEntries; + uint32_t hdatsbTpmArraySize; +} __attribute__ ((packed)); + + +/** + * @brief Structure definition for Secureboot TPM Instance Info + */ +struct hdatSbTpmInstInfo_t +{ + uint32_t hdatChipId; + uint32_t hdatDbobId; // Drawer/Book/Octant/Blade ID + uint8_t hdatLocality1Addr; + uint8_t hdatLocality2Addr; + uint8_t hdatLocality3Addr; + uint8_t hdatLocality4Addr; + uint8_t hdatFunctionalStatus; + uint8_t reserved[3]; + uint32_t hdatTpmSrtmEventLogOffset; + uint32_t hdatTpmSrtmEventLogEntrySize; + uint32_t hdatTpmDrtmEventLogOffset; + uint32_t hdatTpmDrtmEventLogEntrySize; +} __attribute__ ((packed)); + + +/** Begin Class Description + * + * @brief The HdatTpmData class is used to construct the Node TPM Related Data + * hypervisor data area. + * + * Description: This class defines a specialized object. It is not intended + * that any component can create an object of this type. + * In particular, the object is built only by the hdat component. + * + * The real purpose of the object is to create the Node TPM + * data structure as defined by the PHYP Initialization + * architecture. This data structure is eventually copied to + * main memory. The class is not defined to be a general purpose + * interface for building this object by anyone other than the + * hdat process. + * + * Thread safety: An HdatTpmData object is not thread safe. That is, a + * single object cannot be shared and used concurrently by + * multiple threads at the same time. An object can be used by + * multiple threads if the threads serialize access. And of + * course, each thread can use its own object with no concerns + * about what other threads are doing. + * + * Signal handler usage: This class is not intended to be used in a signal + * handler and nothing has been done to try and make + * it safe to use in a signal handler. + * + * End Class Description + */ +class HdatTpmData +{ + public: + /** + * @brief Construct an HdatTpmData object. + * + * This is the constructor for the HdatTpmData object. + * + * After creating a new HdatTpmData object via new, you must + * check o_errlHndl to see if the constructor ran successfully. + * If o_errHndl indicates an error was reported by the + * constructor, then new has already allocated heap storage and + * the object must be deleted in order to free the heap storage. + * + * @pre None + * + * @post An HdatTpmData object has been constructed. + * Heap storage has been allocated. + * + * @param[out] o_errlHndl If any errors occur, the HdatTpmData object is + * NOT constructed and an error is + * returned in this parameter + * @param[in] i_msAddr The main memory address that the service + * processor subsystem structure + * will be DMA'd to. + */ + HdatTpmData(errlHndl_t &o_errlHndl, const HDAT::hdatMsAddr_t &i_msAddr); + + + /** + * @brief HdatTpmData object destructor + * + * This is the destructor for an HdatTpmData object. + * Any heap storage allocated for the object is deallocated. + * + * @pre No preconditions exist + * + * @post The HdatTpmData object has been destroyed and can + * no longer be used. + * + */ + ~HdatTpmData(); + + /** + * @brief Load TPM Related Data to Mainstore + * + * @pre None + * + * @post None + * + * @param[out] o_size Size of TPM Data structure + * @param[out] o_count Number of TPM Data structures + * + * @retval errlHndl_t nullptr on success, error log on error + */ + errlHndl_t hdatLoadTpmData(uint32_t &o_size,uint32_t &o_count); + + // delete copy/move constructors and operators + HdatTpmData(const HdatTpmData& ) = delete; + HdatTpmData& operator=(const HdatTpmData& ) = delete; + HdatTpmData(HdatTpmData&&) = delete; + HdatTpmData& operator=(HdatTpmData&&) = delete; + + private: + + HDAT::hdatMsAddr_t iv_msAddr; + + hdatTpmData_t *iv_hdatTpmData; + + +}; // end of HdatTpmData class + + +} +#endif // HDATTPMDATA_H diff --git a/src/usr/hdat/hdatutil.C b/src/usr/hdat/hdatutil.C index 747205b6c..456584316 100644 --- a/src/usr/hdat/hdatutil.C +++ b/src/usr/hdat/hdatutil.C @@ -96,6 +96,7 @@ void hdatBldErrLog(errlHndl_t & io_err, } } + /******************************************************************************* * isFunctional *******************************************************************************/ @@ -1710,7 +1711,7 @@ void hdatGetI2cDeviceInfo(TARGETING::Target* i_pTarget, l_hostI2cObj.hdatI2cSlavePort = l_i2cDevEle.slavePort; l_hostI2cObj.hdatI2cSlaveDevPurp = l_i2cDevEle.devicePurpose; l_hostI2cObj.hdatI2cLinkId = l_I2cLinkId++; - + o_i2cDevEntries.push_back(l_hostI2cObj); } } diff --git a/src/usr/hdat/hdatutil.H b/src/usr/hdat/hdatutil.H index 9dfa0b95b..bb29db916 100755 --- a/src/usr/hdat/hdatutil.H +++ b/src/usr/hdat/hdatutil.H @@ -91,13 +91,18 @@ const uint16_t HDAT_VERSION3 = 3; #define HDAT_INF( _fmt_, _args_...) \ TRACFCOMP( g_trac_hdat,DBG_MRK _fmt_, ##_args_ ); +#define UINT64_HIGH(u) ((u & 0xFFFFFFFF00000000) >> 32) + +#define UINT64_LOW(u) (u & 0x00000000FFFFFFFF) + + namespace HDAT { extern trace_desc_t* g_trac_hdat; -/** @brief Defines the Host I2C device info +/** @brief Defines the Host I2C device info */ struct hdatI2cData_t { diff --git a/src/usr/hdat/makefile b/src/usr/hdat/makefile index 810c05022..f04be84a7 100644 --- a/src/usr/hdat/makefile +++ b/src/usr/hdat/makefile @@ -47,6 +47,7 @@ OBJS += hdatbldda.o OBJS += hdatnodedata.o OBJS += hdathostservices.o OBJS += hdathbrt.o +OBJS += hdattpmdata.o OBJS += hdatspiraS.o OBJS += hdatspiraH.o OBJS += hdatipmi.o -- cgit v1.2.1