diff options
author | Donald Washburn <dwashbur@us.ibm.com> | 2017-07-25 08:42:11 -0500 |
---|---|---|
committer | Daniel M. Crowell <dcrowell@us.ibm.com> | 2017-08-24 15:53:30 -0400 |
commit | d93a520bdb774eefa74839aa124789516999b587 (patch) | |
tree | 7b34d79e74c91693ff6114735c0a75596b072cae /src/usr/sbeio | |
parent | 24eb981a9b4e452fd59d82136000adb6e0d16f2a (diff) | |
download | talos-hostboot-d93a520bdb774eefa74839aa124789516999b587.tar.gz talos-hostboot-d93a520bdb774eefa74839aa124789516999b587.zip |
Implemented SBE Passthrough for Attribute Override.
*Wrote a runtime SBE pass-through function to invoke the
runtime apply_attribute_overrides function. The caller
is required to place the request data in the
SBE COMMS reserved memory area and invoke the
sbe_message_passing function. The request data consists
of an sbeMessage_t header followed by binary override
data which can be obtained from the attributeOverride tool.
Upon completion of the sbe_message_passing function, the
respose data will be written to the SBE COMMS AREA.
*Added support for accessing system attributes at runtime.
RTC: 152409
Change-Id: Ieed3e026350cc272e6268e7802971551d3f39ed4
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/44311
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Reviewed-by: Roland Veloz <rveloz@us.ibm.com>
Reviewed-by: Martin Gloff <mgloff@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src/usr/sbeio')
-rw-r--r-- | src/usr/sbeio/runtime/makefile | 1 | ||||
-rw-r--r-- | src/usr/sbeio/runtime/rt_sbeio.C | 3 | ||||
-rw-r--r-- | src/usr/sbeio/runtime/sbeio_attr_override.C | 125 | ||||
-rw-r--r-- | src/usr/sbeio/runtime/test/sbeioAttrOverrideTests.H | 1312 | ||||
-rw-r--r-- | src/usr/sbeio/runtime/test/sbeiotestRt.H | 9 | ||||
-rw-r--r-- | src/usr/sbeio/runtime/test/sbeiotestRtConstants.H | 34 | ||||
-rw-r--r-- | src/usr/sbeio/runtime/test/sbemsg-utils.sh | 299 |
7 files changed, 1778 insertions, 5 deletions
diff --git a/src/usr/sbeio/runtime/makefile b/src/usr/sbeio/runtime/makefile index aa5251764..c10c4e95b 100644 --- a/src/usr/sbeio/runtime/makefile +++ b/src/usr/sbeio/runtime/makefile @@ -32,6 +32,7 @@ MODULE = sbeio_rt ## Objects unique to HBRT OBJS += rt_sbeio.o +OBJS += sbeio_attr_override.o SUBDIRS += test.d diff --git a/src/usr/sbeio/runtime/rt_sbeio.C b/src/usr/sbeio/runtime/rt_sbeio.C index 1ff66a649..30381c874 100644 --- a/src/usr/sbeio/runtime/rt_sbeio.C +++ b/src/usr/sbeio/runtime/rt_sbeio.C @@ -28,6 +28,7 @@ #include <vmmconst.h> #include <sys/misc.h> #include <sbeio/runtime/sbe_msg_passing.H> +#include <sbeio/runtime/sbeio_attr_override.H> #include <sbeio/sbeioreasoncodes.H> #include <errno.h> #include <errl/errlentry.H> @@ -848,6 +849,8 @@ namespace RT_SBEIO SBE_MSG::setProcessCmdFunction(PASSTHRU_HTMGT_GENERIC, htmgt_pass_thru_wrapper); #endif + SBE_MSG::setProcessCmdFunction(PASSTHRU_HBRT_OVERRIDE_ATTR, + sbeApplyAttrOverrides); } }; diff --git a/src/usr/sbeio/runtime/sbeio_attr_override.C b/src/usr/sbeio/runtime/sbeio_attr_override.C new file mode 100644 index 000000000..ee5770001 --- /dev/null +++ b/src/usr/sbeio/runtime/sbeio_attr_override.C @@ -0,0 +1,125 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/sbeio/runtime/sbeio_attr_override.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 <sbeio/runtime/sbeio_attr_override.H> + +#include <runtime/interface.h> +#include <sbeio/sbeioreasoncodes.H> + +extern trace_desc_t* g_trac_sbeio; + +using namespace ERRORLOG; + +namespace SBE_MSG +{ + +//------------------------------------------------------------------------- +errlHndl_t sbeApplyAttrOverrides( + TARGETING::TargetHandle_t i_procTgt, + uint32_t i_reqDataSize, + uint8_t * i_reqData, + uint32_t * o_rspStatus, + uint32_t * o_rspDataSize, + uint8_t * o_rspData + ) +{ + errlHndl_t errl{}; + + do + { + *o_rspDataSize = 0; //No return data + + runtimeInterfaces_t *rt_intf = getRuntimeInterfaces(); + + if(nullptr == rt_intf) + { + TRACFCOMP( g_trac_sbeio, + ERR_MRK"sbeApplyAttrOverrides: " + "Unable to get runtime interfaces." + ); + + /*@ + * @errortype + * @moduleid SBEIO::SBEIO_RUNTIME_ATTR_OVERRIDE + * @reasoncode SBEIO::SBEIO_RT_NO_INTERFACE_POINTER + * @userdata1 Processor HUID + * @userdata2 Reserved + * + * @devdesc SBEIO RT Process Pass-through command RuntimeRT + * Interface pointer not set. + * @custdesc Firmware error communicating with boot device + */ + errl = new ErrlEntry(ERRL_SEV_INFORMATIONAL, + SBEIO::SBEIO_RUNTIME_ATTR_OVERRIDE, + SBEIO::SBEIO_RT_NO_INTERFACE_POINTER, + get_huid(i_procTgt), + 0 + ); + + errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE, + HWAS::SRCI_PRIORITY_HIGH); + + errl->collectTrace(SBEIO_COMP_NAME); + break; + } + else if(nullptr == rt_intf->apply_attr_override) + { + TRACFCOMP( g_trac_sbeio, + ERR_MRK"sbeApplyAttrOverrides: " + "Function pointer to apply_attr_override not set." + ); + /*@ + * @errortype + * @moduleid SBEIO::SBEIO_RUNTIME_ATTR_OVERRIDE + * @reasoncode SBEIO::SBEIO_RT_NO_APPLY_ATTR_FUNCTION + * @userdata1 Processor HUID + * @userdata2 Reserved + * + * @devdesc SBEIO RT Process Pass-through command RuntimeRT + * Interface pointer for apply_attr_override not set. + * @custdesc Firmware error communicating with boot device + */ + errl = new ErrlEntry(ERRL_SEV_INFORMATIONAL, + SBEIO::SBEIO_RUNTIME_ATTR_OVERRIDE, + SBEIO::SBEIO_RT_NO_APPLY_ATTR_FUNCTION, + get_huid(i_procTgt), + 0 + ); + + errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE, + HWAS::SRCI_PRIORITY_HIGH); + + errl->collectTrace(SBEIO_COMP_NAME); + break; + } + + //apply_attr_override will take care of handling errors it encounters. + *o_rspStatus = rt_intf->apply_attr_override(i_reqData, i_reqDataSize); + } + while(0); + + return errl; +} + +}//End namespace diff --git a/src/usr/sbeio/runtime/test/sbeioAttrOverrideTests.H b/src/usr/sbeio/runtime/test/sbeioAttrOverrideTests.H new file mode 100644 index 000000000..903bf08f6 --- /dev/null +++ b/src/usr/sbeio/runtime/test/sbeioAttrOverrideTests.H @@ -0,0 +1,1312 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/sbeio/runtime/test/sbeioAttrOverrideTests.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 __SBEIO_SBEIO_ATTR_OVERRIDES_TEST_H +#define __SBEIO_SBEIO_ATTR_OVERRIDES_TEST_H + +#include <cxxtest/TestSuite.H> +#include <runtime/interface.h> +#include <runtime/rt_targeting.H> +#include <sbeio/runtime/sbe_msg_passing.H> +#include <sbeio/sbeioreasoncodes.H> +#include <secureboot/service.H> +#include <targeting/common/attributeTank.H> +#include <targeting/common/target.H> +#include <targeting/common/targetservice.H> +#include <targeting/common/utilFilter.H> +#include <errl/errlmanager.H> +#include <devicefw/userif.H> + +#include <string.h> +#include <stdio.h> + +#include "sbeiotestRtConstants.H" + +extern trace_desc_t* g_trac_sbeio; + +#define SBE_PASSTHROUGH_TRACD(printf_string,args...) \ + TRACDCOMP(g_trac_sbeio,"SbePassThroughTests: " printf_string,##args) + + +//======================================= +// Test Data - overrides +//======================================= +/* +target +ATTR_SCRATCH_UINT8_1 0xCE +ATTR_SCRATCH_UINT8_2 0xFE +ATTR_SCRATCH_UINT32_1 0x12345678 +ATTR_SCRATCH_UINT32_2 0xAABBCCDD +ATTR_SCRATCH_UINT64_1 0x1234567890ABCDEF +ATTR_SCRATCH_UINT64_2 0x1A2B3C4D5E6F7890 +*/ + +const uint16_t attrOverrideData[] = { + 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0011, + 0x0c7b, 0xc372, 0x0000, 0x0001, 0xffff, 0xfff0, 0x0000, 0x0001, + 0xce00, 0x0000, 0x0200, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x110e, 0x9341, 0x9a00, 0x0000, 0x01ff, 0xffff, 0xf000, 0x0000, + 0x01fe, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0014, 0x0782, 0xc053, 0x0000, 0x0001, 0xffff, 0xfff0, 0x0000, + 0x0004, 0x1234, 0x5678, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0014, 0x0002, 0x156b, 0x0000, 0x0001, 0xffff, + 0xfff0, 0x0000, 0x0004, 0xaabb, 0xccdd, 0x0000, 0x0002, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0018, 0x0eee, 0x9926, 0x0000, + 0x0001, 0xffff, 0xfff0, 0x0000, 0x0008, 0x1234, 0x5678, 0x90ab, + 0xcdef, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0018, 0x018a, 0x17a2, 0x0000, 0x0001, 0xffff, 0xfff0, 0x0000, + 0x0008, 0x1a2b, 0x3c4d, 0x5e6f, 0x7890 +}; + +#define CHECK_PRTF_RESULT(rc, remaining, ptr) \ +if(rc > 0 && rc < remaining) \ +{ \ + remaining -= rc; \ + ptr += rc; \ + if(remaining <= 0) \ + { \ + break; \ + } \ +} \ +else \ +{ \ + break; \ +} + +using namespace SBE_MSG; + +enum class TestResult{OK, WARN, FAIL}; + +//------------------------------------------------------------------ +class SbePassThroughApplyAttrOverrides: public CxxTest::TestSuite +{ +public: + + //------------------------------------------------------ + void testApplyAtrr() + { + //############################################################# + //STEPS: + // 1) Get Chip ID + // 2) Ensure that Another SBE pass-through is not in progress + // 3) Get pointer to SBE COMMS AREA + // 4) Setup Request Data + // 5) Setup Expected Response + // 6) Copy Request Data to SBE COMMS AREA + // 7) Invoke sbe_message_passing + // 8) Check Response Message + // 9) Clear register CFAM Reg 0x283B + // 10) Validate Attribute Tank was Updated + // 11) Validate Target Override Values + + using sbeCommAddr_t = void*; + TARGETING::TargetHandle_t l_proc{}; + bool result{true}; + bool l_allowOverrides{true}; + +#ifdef CONFIG_SECUREBOOT + l_allowOverrides = SECUREBOOT::allowAttrOverrides(); +#endif + + SBE_PASSTHROUGH_TRACD("SBE_MSG_DATA_OFFSET: 0x%08X", + SBE_MSG_DATA_OFFSET + ); + + do + { + //############################################## + // Step 1 - Get Chip ID + //############################################# + + //get runtime interfaces + runtimeInterfaces_t* l_rt = getRuntimeInterfaces(); + if(nullptr == l_rt) + { + TS_FAIL("SbePassThroughApplyAttrOverrides: " + "Unable to get runtime interfaces."); + + result = false; + break; + } + else if(not l_rt->sbe_message_passing) + { + TS_FAIL("SbePassThroughApplyAttrOverrides: " + "sbe_message_passing runtime interface " + "has not been set."); + + result = false; + break; + } + + TARGETING::TargetHandleList procList; + getAllChips(procList, TARGETING::TYPE_PROC, true); + + if(0 == procList.size()) + { + TS_FAIL("SbePassThroughApplyAttrOverrides: " + "Unable to get proc targets." + ); + + result = false; + break; + } + + l_proc = procList[0]; + RT_TARG::rtChipId_t l_chipId = 0; + errlHndl_t l_err = RT_TARG::getRtTarget(l_proc, l_chipId); + + if(nullptr != l_err) + { + TS_FAIL("SbePassThroughApplyAttrOverrides: " + "RT_TARG::getRtTarget returned an error." + ); + + errlCommit(l_err, SBEIO_COMP_ID); + + result = false; + break; + } + + printAttributes("Attributes Before SBE Passthrough:"); + + //################################################################# + // Step 2 - Ensure that Another SBE pass-through is not in progress + //################################################################# + + TestResult clearToSend = ensureClearToSend(l_proc); + if(TestResult::WARN == clearToSend) + { + clearControlRegister(l_proc); + } + else if(TestResult::FAIL == clearToSend) + { + result = false; + break; + } + + //######################################## + // Step 3 - Get pointer to SBE COMMS AREA + //######################################## + + SBE_PASSTHROUGH_TRACD("applyAtrrTest. ChipId: 0x%016llX", l_chipId); + + sbeCommAddr_t l_sbeCommAddr{}; + uint64_t address; + + bool bGotAttr = + l_proc->tryGetAttr<TARGETING::ATTR_SBE_COMM_ADDR>(address); + + if(not bGotAttr || 0 == address) + { + uint64_t l_instance = + l_proc->getAttr<TARGETING::ATTR_POSITION>(); + + address = g_hostInterfaces->get_reserved_mem( + HBRT_RSVD_MEM__SBE_COMM, + l_instance); + + if(0 == address) + { + TS_FAIL("SbePassThroughApplyAttrOverrides: " + "Unable to get SBE communications area." + ); + result = false; + break; + } + } + + l_sbeCommAddr = reinterpret_cast<void*>(address); + SBE_PASSTHROUGH_TRACD("applyAtrrTest, SBE Area Address: " + "0x%016llX. ", + address + ); + + //######################################## + // Step 4 - Setup Request Data + //######################################## + + SBE_MSG::sbeMessage_t l_request; + + //Setup request message. + l_request.sbeHdr.version = SBE_MSG::SBEHDRVER_LATEST; + l_request.sbeHdr.msgSize = sizeof(sbeHeader_t) + + sizeof(cmdHeader_t) + + sizeof(attrOverrideData); + l_request.sbeHdr.seqId = ++iv_seqNumber; + + l_request.cmdHdr.version = SBE_MSG::CMDHDRVER_LATEST; + l_request.cmdHdr.status = 0; + l_request.cmdHdr.dataOffset = SBE_MSG_DATA_OFFSET; + l_request.cmdHdr.dataSize = sizeof(attrOverrideData); + l_request.cmdHdr.command = SBE_MSG::PASSTHRU_HBRT_OVERRIDE_ATTR; + + memset(l_request.data, + 0xFF, + sizeof(l_request.data)); + + memcpy(l_request.data, + attrOverrideData, + l_request.cmdHdr.dataSize); + + //######################################## + // Step 5 - Setup Expected Response + //######################################## + + SBE_MSG::sbeMessage_t l_expectedResponse; + + memset(&l_expectedResponse, 0, sizeof(SBE_MSG::sbeMessage_t)); + + l_expectedResponse.sbeHdr.version = SBE_MSG::SBEHDRVER_LATEST; + l_expectedResponse.sbeHdr.msgSize = sizeof(sbeHeader_t) + + sizeof(cmdHeader_t); + l_expectedResponse.sbeHdr.seqId = l_request.sbeHdr.seqId; + + l_expectedResponse.cmdHdr.version = SBE_MSG::CMDHDRVER_LATEST; + + if(l_allowOverrides) + { + l_expectedResponse.cmdHdr.status = 0; + } + else + { + l_expectedResponse.cmdHdr.status = 0xFFFFFFFF; + } + + l_expectedResponse.cmdHdr.dataOffset = SBE_MSG_DATA_OFFSET; + l_expectedResponse.cmdHdr.dataSize = 0; + l_expectedResponse.cmdHdr.command = l_request.cmdHdr.command; + memset(l_expectedResponse.data, + 0, + sizeof(l_expectedResponse.data)); + + //############################################# + // Step 6 - Copy Request Data to SBE COMMS AREA + //############################################# + + memcpy(l_sbeCommAddr, &l_request, l_request.sbeHdr.msgSize); + + { + char msgBuffer[256] = {0}; + printSbeMessage(msgBuffer, + "Pre Call SBE Area Dump", + *(reinterpret_cast<SBE_MSG::sbeMessage_t*> + (l_sbeCommAddr)) + ); + SBE_PASSTHROUGH_TRACD("applyAtrrTest, %s", msgBuffer); + } + + //############################################# + // Step 7 - Invoke sbe_message_passing + //############################################# + + int rc = l_rt->sbe_message_passing(l_chipId); + + if(0 != rc) + { + TS_FAIL("SbePassThroughApplyAttrOverrides: " + "sbe_message_passing failed. rc: %d", + rc + ); + result = false; + break; + } + + { + char msgBuffer[256] = {0}; + printSbeMessage(msgBuffer, + "Post Call SBE Area Dump", + *(reinterpret_cast<SBE_MSG::sbeMessage_t*> + (l_sbeCommAddr)) + ); + SBE_PASSTHROUGH_TRACD("applyAtrrTest, %s", msgBuffer); + } + + //############################################# + // Step 8 - Check Response Message + //############################################# + + SBE_MSG::sbeMessage_t l_response; + memset(&l_response, 0, sizeof(SBE_MSG::sbeMessage_t)); + memcpy(&l_response, + l_sbeCommAddr, + l_expectedResponse.sbeHdr.msgSize); + + memset(l_sbeCommAddr, 0, l_request.sbeHdr.msgSize); + + //see if the response matches the expectations. + if( + (memcmp(&l_response.cmdHdr, + &l_expectedResponse.cmdHdr, + sizeof(cmdHeader_t))) != 0 || + (memcmp(&l_response.sbeHdr, + &l_expectedResponse.sbeHdr, + sizeof(sbeHeader_t)) != 0) + ) + { + char msgBuffer[256] = {0}; + printSbeMessage(msgBuffer, "Actual Response", l_response); + SBE_PASSTHROUGH_TRACD("applyAtrrTest, actual response " + "differs from expected response."); + SBE_PASSTHROUGH_TRACD("applyAtrrTest, %s", msgBuffer); + printSbeMessage(msgBuffer, + "Expected Response", l_expectedResponse); + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, %s", msgBuffer); + + TS_FAIL("applyAtrrTest: The actual response differs " + "from the expected response."); + result = false; + break; + } + + //############################################# + // Step 9 - Clear Register CFAM Reg 0x283B + //############################################# + bool controlRegisterCleared = clearControlRegister(l_proc); + + if(not l_allowOverrides) + { + break; + } + + //############################################# + // Step 10 - Validate Attribute Tank Updated + //############################################# + uint8_t scratch_8_1{}; + constexpr uint8_t scratch_8_1_expected = 0xCE; + + uint8_t scratch_8_2{}; + constexpr uint8_t scratch_8_2_expected = 0xFE; + + uint32_t scratch_32_1{}; + constexpr uint32_t scratch_32_1_expected = 0x12345678; + + uint32_t scratch_32_2{}; + constexpr uint32_t scratch_32_2_expected = 0xAABBCCDD; + + uint64_t scratch_64_1{}; + constexpr uint64_t scratch_64_1_expected = 0x1234567890ABCDEF; + + uint64_t scratch_64_2{}; + constexpr uint64_t scratch_64_2_expected = 0x1A2B3C4D5E6F7890; + + constexpr uint16_t TARG_POS = 0xFFFF; + constexpr uint8_t TARG_CHIP_POS = 0xFF; + constexpr uint8_t TARG_NODE = 0x0F; + + const TARGETING::AttributeTank& l_tank = + TARGETING::Target::theTargOverrideAttrTank(); + + //ATTR_SCRATCH_UINT8_1 + //=================================================== + if(not l_tank.getAttribute( + TARGETING::ATTR_SCRATCH_UINT8_1, + TARGETING::TYPE_SYS, + TARG_POS, + TARG_CHIP_POS, + TARG_NODE, + &scratch_8_1 + )) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "getAttribute failed for " + "ATTR_SCRATCH_UINT8_1" + ); + TS_FAIL("getAttribute failed for " + "ATTR_SCRATCH_UINT8_1"); + + result = false; + break; + } + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT8_1: 0x%02X", + scratch_8_1 + ); + + if(scratch_8_1_expected != scratch_8_1) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT8_1 value " + "differs from expected! " + "Expected 0x%02X, Actual 0x%02X", + scratch_8_1_expected, + scratch_8_1 + ); + + TS_FAIL("applyAtrrTest, " + "ATTR_SCRATCH_UINT8_1 value " + "differs from expected! " + "Expected 0x%02X, Actual 0x%02X", + scratch_8_1_expected, + scratch_8_1 + ); + + result = false; + break; + } + + + //ATTR_SCRATCH_UINT8_2 + //=================================================== + if(not l_tank.getAttribute( + TARGETING::ATTR_SCRATCH_UINT8_2, + TARGETING::TYPE_SYS, + TARG_POS, + TARG_CHIP_POS, + TARG_NODE, + &scratch_8_2 + )) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "getAttribute failed for " + "ATTR_SCRATCH_UINT8_2" + ); + TS_FAIL("getAttribute failed for " + "ATTR_SCRATCH_UINT8_2"); + + result = false; + break; + } + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT8_2: 0x%02X", + scratch_8_2 + ); + + if(scratch_8_2_expected != scratch_8_2) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT8_2 value " + "differs from expected! " + "Expected 0x%02X, Actual 0x%02X", + scratch_8_2_expected, + scratch_8_2 + ); + + TS_FAIL("applyAtrrTest, " + "ATTR_SCRATCH_UINT8_2 value " + "differs from expected! " + "Expected 0x%02X, Actual 0x%02X", + scratch_8_2_expected, + scratch_8_2 + ); + + result = false; + break; + } + + + //ATTR_SCRATCH_UINT32_1 + //=================================================== + if(not l_tank.getAttribute( + TARGETING::ATTR_SCRATCH_UINT32_1, + TARGETING::TYPE_SYS, + TARG_POS, + TARG_CHIP_POS, + TARG_NODE, + &scratch_32_1 + )) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "getAttribute failed for " + "ATTR_SCRATCH_UINT32_1" + ); + TS_FAIL("getAttribute failed for " + "ATTR_SCRATCH_UINT32_1"); + + result = false; + break; + } + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT32_1: 0x%08X", + scratch_32_1 + ); + + if(scratch_32_1_expected != scratch_32_1) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT32_1 value " + "differs from expected! " + "Expected 0x%08X, Actual 0x%08X", + scratch_32_1_expected, + scratch_32_1 + ); + + TS_FAIL("applyAtrrTest, " + "ATTR_SCRATCH_UINT32_1 value " + "differs from expected! " + "Expected 0x%08X, Actual 0x%08X", + scratch_32_1_expected, + scratch_32_1 + ); + + result = false; + break; + } + + + //ATTR_SCRATCH_UINT32_2 + //=================================================== + if(not l_tank.getAttribute( + TARGETING::ATTR_SCRATCH_UINT32_2, + TARGETING::TYPE_SYS, + TARG_POS, + TARG_CHIP_POS, + TARG_NODE, + &scratch_32_2 + )) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "getAttribute failed for " + "ATTR_SCRATCH_UINT32_2" + ); + TS_FAIL("getAttribute failed for " + "ATTR_SCRATCH_UINT32_2"); + + result = false; + break; + } + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT32_2: 0x%08X", + scratch_32_2 + ); + + if(scratch_32_2_expected != scratch_32_2) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT32_2 value " + "differs from expected! " + "Expected 0x%08X, Actual 0x%08X", + scratch_32_2_expected, + scratch_32_2 + ); + + TS_FAIL("applyAtrrTest, " + "ATTR_SCRATCH_UINT32_2 value " + "differs from expected! " + "Expected 0x%08X, Actual 0x%08X", + scratch_32_2_expected, + scratch_32_2 + ); + + result = false; + break; + } + + //ATTR_SCRATCH_UINT64_1 + //=================================================== + if(not l_tank.getAttribute( + TARGETING::ATTR_SCRATCH_UINT64_1, + TARGETING::TYPE_SYS, + TARG_POS, + TARG_CHIP_POS, + TARG_NODE, + &scratch_64_1 + )) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "getAttribute failed for " + "ATTR_SCRATCH_UINT64_1" + ); + TS_FAIL("getAttribute failed for " + "ATTR_SCRATCH_UINT64_1"); + + result = false; + break; + } + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT64_1: 0x%016llX", + scratch_64_1 + ); + + if(scratch_64_1_expected != scratch_64_1) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT64_1 value " + "differs from expected! " + "Expected 0x%016llX, Actual 0x%016llX", + scratch_64_1_expected, + scratch_64_1 + ); + + TS_FAIL("applyAtrrTest, " + "ATTR_SCRATCH_UINT64_1 value " + "differs from expected! " + "Expected 0x%016llX, Actual 0x%016llX", + scratch_64_1_expected, + scratch_64_1 + ); + + result = false; + break; + } + + //ATTR_SCRATCH_UINT64_2 + //=================================================== + if(not l_tank.getAttribute( + TARGETING::ATTR_SCRATCH_UINT64_2, + TARGETING::TYPE_SYS, + TARG_POS, + TARG_CHIP_POS, + TARG_NODE, + &scratch_64_2 + )) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "getAttribute failed for " + "ATTR_SCRATCH_UINT64_2" + ); + TS_FAIL("getAttribute failed for " + "ATTR_SCRATCH_UINT64_2"); + + result = false; + break; + } + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT64_2: 0x%016llX", + scratch_64_2 + ); + + if(scratch_64_2_expected != scratch_64_2) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT64_2 value " + "differs from expected! " + "Expected 0x%016llX, Actual 0x%016llX", + scratch_64_2_expected, + scratch_64_2 + ); + + TS_FAIL("applyAtrrTest, " + "ATTR_SCRATCH_UINT64_2 value " + "differs from expected! " + "Expected 0x%016llX, Actual 0x%016llX", + scratch_64_2_expected, + scratch_64_2 + ); + + result = false; + break; + } + + //############################################# + // Step 11 - Validate Target Override Values + //############################################# + + TARGETING::Target* l_sys{}; + TARGETING::targetService().getTopLevelTarget(l_sys); + + if(nullptr == l_sys) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "Failed to obtain Sys Target." + ); + + TS_FAIL("Failed to obtain Sys Target"); + result = false; + break; + } + + //ATTR_SCRATCH_UINT8_1 + //=================================================== + if(not l_sys-> + tryGetAttr<TARGETING::ATTR_SCRATCH_UINT8_1>(scratch_8_1)) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "tryGetAttr failed for " + "ATTR_SCRATCH_UINT8_1" + ); + TS_FAIL("tryGetAttr failed for " + "ATTR_SCRATCH_UINT8_1"); + + result = false; + break; + } + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT8_1: 0x%02X", + scratch_8_1 + ); + + if(scratch_8_1_expected != scratch_8_1) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT8_1 value " + "differs from expected! " + "Expected 0x%02X, Actual 0x%02X", + scratch_8_1_expected, + scratch_8_1 + ); + + TS_FAIL("applyAtrrTest, " + "ATTR_SCRATCH_UINT8_1 value " + "differs from expected! " + "Expected 0x%02X, Actual 0x%02X", + scratch_8_1_expected, + scratch_8_1 + ); + + result = false; + break; + } + + //ATTR_SCRATCH_UINT8_2 + //=================================================== + if(not l_sys-> + tryGetAttr<TARGETING::ATTR_SCRATCH_UINT8_2>(scratch_8_2)) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "tryGetAttr failed for " + "ATTR_SCRATCH_UINT8_2" + ); + TS_FAIL("tryGetAttr failed for " + "ATTR_SCRATCH_UINT8_2"); + + result = false; + break; + } + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT8_2: 0x%02X", + scratch_8_2 + ); + + if(scratch_8_2_expected != scratch_8_2) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT8_2 value " + "differs from expected! " + "Expected 0x%02X, Actual 0x%02X", + scratch_8_2_expected, + scratch_8_2 + ); + + TS_FAIL("applyAtrrTest, " + "ATTR_SCRATCH_UINT8_2 value " + "differs from expected! " + "Expected 0x%02X, Actual 0x%02X", + scratch_8_2_expected, + scratch_8_2 + ); + + result = false; + break; + } + + //ATTR_SCRATCH_UINT32_1 + //=================================================== + if(not l_sys-> + tryGetAttr<TARGETING::ATTR_SCRATCH_UINT32_1>(scratch_32_1)) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "tryGetAttr failed for " + "ATTR_SCRATCH_UINT32_1" + ); + TS_FAIL("tryGetAttr failed for " + "ATTR_SCRATCH_UINT32_1"); + + result = false; + break; + } + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT32_1: 0x%08X", + scratch_32_1 + ); + + if(scratch_32_1_expected != scratch_32_1) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT32_1 value " + "differs from expected! " + "Expected 0x%08X, Actual 0x%08X", + scratch_32_1_expected, + scratch_32_1 + ); + + TS_FAIL("applyAtrrTest, " + "ATTR_SCRATCH_UINT32_1 value " + "differs from expected! " + "Expected 0x%08X, Actual 0x%08X", + scratch_32_1_expected, + scratch_32_1 + ); + + result = false; + break; + } + + //ATTR_SCRATCH_UINT32_2 + //=================================================== + if(not l_sys-> + tryGetAttr<TARGETING::ATTR_SCRATCH_UINT32_2>(scratch_32_2)) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "tryGetAttr failed for " + "ATTR_SCRATCH_UINT32_2" + ); + TS_FAIL("tryGetAttr failed for " + "ATTR_SCRATCH_UINT32_2"); + + result = false; + break; + } + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT32_2: 0x%08X", + scratch_32_2 + ); + + if(scratch_32_2_expected != scratch_32_2) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT32_2 value " + "differs from expected! " + "Expected 0x%08X, Actual 0x%08X", + scratch_32_2_expected, + scratch_32_2 + ); + + TS_FAIL("applyAtrrTest, " + "ATTR_SCRATCH_UINT32_2 value " + "differs from expected! " + "Expected 0x%08X, Actual 0x%08X", + scratch_32_2_expected, + scratch_32_2 + ); + + result = false; + break; + } + + //ATTR_SCRATCH_UINT64_1 + //=================================================== + if(not l_sys-> + tryGetAttr<TARGETING::ATTR_SCRATCH_UINT64_1>(scratch_64_1)) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "tryGetAttr failed for " + "ATTR_SCRATCH_UINT64_1" + ); + TS_FAIL("tryGetAttr failed for " + "ATTR_SCRATCH_UINT64_1"); + + result = false; + break; + } + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT64_1: 0x%016llX", + scratch_64_1 + ); + + if(scratch_64_1_expected != scratch_64_1) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT64_1 value " + "differs from expected! " + "Expected 0x%016llX, Actual 0x%016llX", + scratch_64_1_expected, + scratch_64_1 + ); + + TS_FAIL("applyAtrrTest, " + "ATTR_SCRATCH_UINT64_1 value " + "differs from expected! " + "Expected 0x%016llX, Actual 0x%016llX", + scratch_64_1_expected, + scratch_64_1 + ); + + result = false; + break; + } + + //ATTR_SCRATCH_UINT64_2 + //=================================================== + if(not l_sys-> + tryGetAttr<TARGETING::ATTR_SCRATCH_UINT64_2>(scratch_64_2)) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "tryGetAttr failed for " + "ATTR_SCRATCH_UINT64_2" + ); + TS_FAIL("tryGetAttr failed for " + "ATTR_SCRATCH_UINT64_2"); + + result = false; + break; + } + + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT64_2: 0x%016llX", + scratch_64_2 + ); + + if(scratch_64_2_expected != scratch_64_2) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest, " + "ATTR_SCRATCH_UINT64_2 value " + "differs from expected! " + "Expected 0x%016llX, Actual 0x%016llX", + scratch_64_2_expected, + scratch_64_2 + ); + + TS_FAIL("applyAtrrTest, " + "ATTR_SCRATCH_UINT64_2 value " + "differs from expected! " + "Expected 0x%016llX, Actual 0x%016llX", + scratch_64_2_expected, + scratch_64_2 + ); + + result = false; + break; + } + + printAttributes("Attributes After SBE Passthrough:"); + + if(not controlRegisterCleared) + { + result = false; + break; + } + } + while(0); + + clearControlRegister(l_proc); + + if(result) + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest passed!"); + } + else + { + SBE_PASSTHROUGH_TRACD("applyAtrrTest failed!"); + } + } + +private: + + uint32_t iv_seqNumber{0}; + + //----------------------------------------------------------- + TestResult ensureClearToSend(TARGETING::TargetHandle_t i_proc) + { + TestResult retval{TestResult::OK}; + + do + { + if(not i_proc) + { + SBE_PASSTHROUGH_TRACD("ensureClearToSend, " + "i_proc is NULL!" + ); + + TS_FAIL("ensureClearToSend, i_proc is NULL!"); + + retval = TestResult::FAIL; + break; + } + + uint32_t l_register{}; + size_t l_size = sizeof(uint64_t); + + errlHndl_t errl = + deviceRead(i_proc, + &l_register, + l_size, + DEVICE_SCOM_ADDRESS(SCOM_ADDR_5003B) + ); + + if(nullptr != errl) + { + delete errl; + errl = nullptr; + + SBE_PASSTHROUGH_TRACD("ensureClearToSend, " + "Failed to read scom register." + ); + TS_FAIL("Failed to read scom register."); + + retval = TestResult::FAIL; + break; + } + + if((l_register & SBE_MSG_IN_PROGRESS) != 0) + { + TS_WARN("SCOM_ADDR_5003B SBE_MSG_IN_PROGRESS set!"); + + retval = TestResult::WARN; + break; + } + } + while(0); + + return retval; + } + + //----------------------------------------------------------- + bool clearControlRegister(TARGETING::TargetHandle_t i_proc) + { + bool retval{true}; + + do + { + if(not i_proc) + { + SBE_PASSTHROUGH_TRACD("ensureClearToSend, " + "i_proc is NULL!" + ); + + TS_FAIL("ensureClearToSend, i_proc is NULL!"); + + retval = false; + break; + } + + uint32_t l_register{}; + size_t l_size = sizeof(uint64_t); + + errlHndl_t errl = + deviceRead(i_proc, + &l_register, + l_size, + DEVICE_SCOM_ADDRESS(SCOM_ADDR_5003B) + ); + + if(nullptr != errl) + { + delete errl; + errl = nullptr; + + SBE_PASSTHROUGH_TRACD("ensureClearToSend, " + "Failed to read scom register." + ); + TS_FAIL("Failed to read scom register."); + + retval = false; + break; + } + + l_register &= ~(SBE_MSG_COMPLETE | SBE_MSG_IN_PROGRESS); + + errl = deviceWrite(i_proc, + &l_register, + l_size, + DEVICE_SCOM_ADDRESS(SCOM_ADDR_5003B) + ); + + if(nullptr != errl) + { + delete errl; + errl = nullptr; + + SBE_PASSTHROUGH_TRACD("ensureClearToSend, " + "Failed to write to scom register." + ); + TS_FAIL("Failed to read scom register."); + + retval = false; + break; + } + } + while(0); + + return retval; + } + + //----------------------------------------------------------- + template<size_t N> + void printSbeMessage(char (&strbuffer)[N], + const char* prefix, + const SBE_MSG::sbeMessage_t& msg) + { + memset(strbuffer, 0, N); + char* ptr = strbuffer; + + do + { + int remaining = static_cast<int>(N - 1); + int rc = 0; + + rc = snprintf(ptr, + static_cast<size_t>(remaining), + "%s\n", + prefix + ); + CHECK_PRTF_RESULT(rc, remaining, ptr); + + rc = snprintf(ptr, + static_cast<size_t>(remaining), + "\tsbeHdr.version: 0x%08X\n", + msg.sbeHdr.version + ); + CHECK_PRTF_RESULT(rc, remaining, ptr); + + rc = snprintf(ptr, + static_cast<size_t>(remaining), + "\tsbeHdr.msgSize: 0x%08X\n", + msg.sbeHdr.msgSize + ); + CHECK_PRTF_RESULT(rc, remaining, ptr); + + rc = snprintf(ptr, + static_cast<size_t>(remaining), + "\tsbeHdr.seqId 0x%08X\n", + msg.sbeHdr.seqId + ); + CHECK_PRTF_RESULT(rc, remaining, ptr); + + rc = snprintf(ptr, + static_cast<size_t>(remaining), + "\tcmdHdr.version 0x%08X\n", + msg.cmdHdr.version + ); + CHECK_PRTF_RESULT(rc, remaining, ptr); + + rc = snprintf(ptr, + static_cast<size_t>(remaining), + "\tcmdHdr.status 0x%08X\n", + msg.cmdHdr.status + ); + CHECK_PRTF_RESULT(rc, remaining, ptr); + + rc = snprintf(ptr, + static_cast<size_t>(remaining), + "\tcmdHdr.dataOffset 0x%08X\n", + msg.cmdHdr.dataOffset + ); + CHECK_PRTF_RESULT(rc, remaining, ptr); + + rc = snprintf(ptr, + static_cast<size_t>(remaining), + "\tcmdHdr.dataSize 0x%08X\n", + msg.cmdHdr.dataSize + ); + CHECK_PRTF_RESULT(rc, remaining, ptr); + + rc = snprintf(ptr, + static_cast<size_t>(remaining), + "\tcmdHdr.command 0x%08X\n", + msg.cmdHdr.command + ); + CHECK_PRTF_RESULT(rc, remaining, ptr); + } + while(0); + } + + + //--------------------------------------------------------------- + void printAttributes(const char* prefix) + { + uint8_t scratch_8_1{}; + uint8_t scratch_8_2{}; + uint32_t scratch_32_1{}; + uint32_t scratch_32_2{}; + uint64_t scratch_64_1{}; + uint64_t scratch_64_2{}; + + TARGETING::Target* l_sys{}; + TARGETING::targetService().getTopLevelTarget(l_sys); + + if(nullptr == l_sys) + { + return; + } + + SBE_PASSTHROUGH_TRACD("%s", prefix); + + //ATTR_SCRATCH_UINT8_1 + //=================================================== + if(l_sys->tryGetAttr<TARGETING::ATTR_SCRATCH_UINT8_1>(scratch_8_1)) + { + SBE_PASSTHROUGH_TRACD( + "\t\tATTR_SCRATCH_UINT8_1: 0x%02X", + scratch_8_1 + ); + } + + //ATTR_SCRATCH_UINT8_2 + //=================================================== + if(l_sys->tryGetAttr<TARGETING::ATTR_SCRATCH_UINT8_2>(scratch_8_2)) + { + SBE_PASSTHROUGH_TRACD( + "\t\tATTR_SCRATCH_UINT8_2: 0x%02X", + scratch_8_2 + ); + } + + //ATTR_SCRATCH_UINT32_1 + //=================================================== + if(l_sys->tryGetAttr<TARGETING::ATTR_SCRATCH_UINT32_1>(scratch_32_1)) + { + SBE_PASSTHROUGH_TRACD( + "\t\tATTR_SCRATCH_UINT32_1: 0x%08X", + scratch_32_1 + ); + } + + //ATTR_SCRATCH_UINT32_2 + //=================================================== + if(l_sys->tryGetAttr<TARGETING::ATTR_SCRATCH_UINT32_2>(scratch_32_2)) + { + SBE_PASSTHROUGH_TRACD( + "\t\tATTR_SCRATCH_UINT32_2: 0x%08X", + scratch_32_2 + ); + } + + //ATTR_SCRATCH_UINT64_1 + //=================================================== + if(l_sys->tryGetAttr<TARGETING::ATTR_SCRATCH_UINT64_1>(scratch_64_1)) + { + SBE_PASSTHROUGH_TRACD( + "\t\tATTR_SCRATCH_UINT64_1: 0x%016llX", + scratch_64_1 + ); + } + + //ATTR_SCRATCH_UINT64_2 + //=================================================== + if(l_sys->tryGetAttr<TARGETING::ATTR_SCRATCH_UINT64_2>(scratch_64_2)) + { + SBE_PASSTHROUGH_TRACD( + "\t\tATTR_SCRATCH_UINT64_2: 0x%016llX", + scratch_64_2 + ); + } + + } +}; + + + +#endif diff --git a/src/usr/sbeio/runtime/test/sbeiotestRt.H b/src/usr/sbeio/runtime/test/sbeiotestRt.H index f2425d104..ee5e5522b 100644 --- a/src/usr/sbeio/runtime/test/sbeiotestRt.H +++ b/src/usr/sbeio/runtime/test/sbeiotestRt.H @@ -36,10 +36,13 @@ #include <sbeio/runtime/sbe_msg_passing.H> #include <sbeio/sbeioreasoncodes.H> #include <runtime/rt_targeting.H> +#include <targeting/common/attributes.H> #include <targeting/common/utilFilter.H> #include <errl/errlmanager.H> #include <devicefw/userif.H> +#include "sbeiotestRtConstants.H" + //trace extern trace_desc_t* g_trac_sbeio; @@ -62,11 +65,7 @@ using namespace TARGETING; using namespace SBE_MSG; using namespace CxxTest; -// Constants for SBE Message bits in SCOM_ADDR_5003B -const uint32_t SCOM_ADDR_5003B = 0x0005003B; // CFAM Reg 0x283B -const uint32_t SBE_MSG_IN_PROGRESS = 0x40000000; -const uint32_t SBE_MSG_COMPLETE = 0x80000000; -const uint32_t SBE_MSG_MASK = SBE_MSG_COMPLETE | SBE_MSG_IN_PROGRESS; + /** * @brief SbeMessagePassingRtTest Unit test for runtime SBE message passing. diff --git a/src/usr/sbeio/runtime/test/sbeiotestRtConstants.H b/src/usr/sbeio/runtime/test/sbeiotestRtConstants.H new file mode 100644 index 000000000..4ea937a3b --- /dev/null +++ b/src/usr/sbeio/runtime/test/sbeiotestRtConstants.H @@ -0,0 +1,34 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/sbeio/runtime/test/sbeiotestRtConstants.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 __SBEIO_SBEIO_TEST_RT_CONSTANTS_H +#define __SBEIO_SBEIO_TEST_RT_CONSTANTS_H + +// Constants for SBE Message bits in SCOM_ADDR_5003B +const uint32_t SCOM_ADDR_5003B = 0x0005003B; // CFAM Reg 0x283B +const uint32_t SBE_MSG_IN_PROGRESS = 0x40000000; +const uint32_t SBE_MSG_COMPLETE = 0x80000000; +const uint32_t SBE_MSG_MASK = SBE_MSG_COMPLETE | SBE_MSG_IN_PROGRESS; + +#endif diff --git a/src/usr/sbeio/runtime/test/sbemsg-utils.sh b/src/usr/sbeio/runtime/test/sbemsg-utils.sh new file mode 100644 index 000000000..85e323c16 --- /dev/null +++ b/src/usr/sbeio/runtime/test/sbemsg-utils.sh @@ -0,0 +1,299 @@ +#!/bin/bash +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/usr/sbeio/runtime/test/sbemsg-utils.sh $ +# +# 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 + +#----------------------------------------------------------------------- +# print-getscom +# Filter value returned by getscom +# +# print-getscom <addr> +#---------------------------------------------------------------------- +print-getscom(){ + getscom pu $1 | grep -e '0x[0-9A-Fa-f]\{16\}' | sed -e 's/.*0x/0x/' +} + +#----------------------------------------------------------------------- +# print-getscom-32 +# Filter value returned by getscom and return lsw +# +# print-getscom-32 <addr> +#---------------------------------------------------------------------- +print-getscom-32(){ + let temp=$(dw-getscom $1) + let temp=$(($temp >>32)) + let temp=$(($temp&0x00000000FFFFFFFF)) + printf "0x%08x\n" $temp +} + +#----------------------------------------------------------------------- +# append-u8() +# Append a u8 hex value to a binary file. +# +# append-u8 <hex value> <file> +# +#------------------------------------------------------------------------ +append-u8(){ + if [ -z "$1" ] || [ -z "$2" ] + then + echo "Usage: append-u8 <value> <file>" + echo " param value: A uint8_t value to append to <file>" + echo " param file: The file to which the binary uint8_t" + echo " value is to be appended." + fi + + x=$1 + + if [[ "${x:0:2}" != "0x" ]] + then + x="0x$x" + fi + + let x=$(($x&0x00FF)) + printf "0000000: %02x" $x | xxd -r -g0 >> $2 +} + +#-------------------------------------------------------------------------- +# append-u16() +# Append a u16 hex value to a binary file. The xxd utility will store the +# value in Big Endian format. +# +# append-u16 <hex value> <file> +#--------------------------------------------------------------------------- +append-u16(){ + if [ -z "$1" ] || [ -z "$2" ] + then + echo "Usage: append-u16 <value> <file>" + echo " param value: A uint16_t value to append to <file>" + echo " param file: The file to which the binary uint16_t" + echo " value is to be appended." + fi + + x=$1 + + if [[ "${x:0:2}" != "0x" ]] + then + x="0x$x" + fi + + let x=$(($x& 0x0000FFFF)) + printf "0000000: %04x" $x | xxd -r -g0 >> $2 +} + +#--------------------------------------------------------------------------- +# append-u32() +# Append a u32 hex value to a binary file. The xxd utility will store the +# value in Big Endian format. +# +# append-u32 <hex value> <file> +#--------------------------------------------------------------------------- +append-u32(){ + if [ -z "$1" ] || [ -z "$2" ] + then + echo "Usage: append-u32 <value> <file>" + echo " param value: A uint32_t value to append to <file>" + echo " param file: The file to which the binary uint32_t" + echo " value is to be appended." + fi + + x=$1 + + if [[ "${x:0:2}" != "0x" ]] + then + x="0x$x" + fi + + let x=$(($x& 0x00000000FFFFFFFF)) + printf "0000000: %08x" $x | xxd -r -g0 >> $2 +} + +#--------------------------------------------------------------------------- +# append-u64() +# Append a u64 hex value to a binary file. The xxd utility will store the +# value in Big Endian format. +# +# append-u64 <hex value> <file> +#--------------------------------------------------------------------------- +append-u64(){ + if [ -z "$1" ] || [ -z "$2" ] + then + echo "Usage: append-u64 <value> <file>" + echo " param value: A uint64_t value to append to <file>" + echo " param file: The file to which the binary uint64_t" + echo " value is to be appended." + fi + + x=$1 + + if [[ "${x:0:2}" != "0x" ]] + then + x="0x$x" + fi + + let x=$(($x)) + printf "0000000: %016x" $x | xxd -r -g0 >> $2 +} + +#---------------------------------------------------------------------------- +# write-attr-request-hdr +# Writes an SbeMessage Header to file. +# write-attr-request-hdr $1 <out file> $2 <payload size> $3 [sequence number] +# +# HEADER SCHEMA +# SBE HEADER VERSION(u32) - 0x00010000 +# SBE HEADER MSG SIZE(u32) - The size of the entire message HEADER + PAYLOAD +# SBE HEADER SEQ NUMBER(u32) - The Sequence Number for the Message. +# CMD HEADER VERSION(u32) - 0x00010000 +# CMD HEADER STATUS(u32) - The response status. +# CMD HEADER DATA OFFSET(u32) - 0x14. +# CMD HEADER DATA SIZE(u32) - The payload size. +# CMD HEADER COMMAND(u32) - 0x00E10002 (Attribute Override Command) +#---------------------------------------------------------------------------- +write-attr-request-hdr(){ + if [ -z "$1" ] || [ -z "$2" ] + then + echo "Usage write-attr-request-hdr <outfile> <payload size> [sequence]" + return + fi + + if [ -z "$3" ] + then + sbe_hdr_seq_id=0x00000001 + else + sbe_hdr_seq_id=$3 + fi + + sbe_hdr_version=0x00010000 + let sbe_hdr_msg_size=$(($2 + 0x20 )) + sbe_hdr_msg_size=$(printf "0x%08x" $sbe_hdr_msg_size) + cmd_hdr_version=0x00010000 + cmd_hdr_status=0x00000000 + cmd_hdr_data_offset=0x00000014 + cmd_hdr_data_size=$2 + cmd_hdr_command=0x00E10002 + + append-u32 $sbe_hdr_version $1 + append-u32 $sbe_hdr_msg_size $1 + append-u32 $sbe_hdr_seq_id $1 + append-u32 $cmd_hdr_version $1 + append-u32 $cmd_hdr_status $1 + append-u32 $cmd_hdr_data_offset $1 + append-u32 $cmd_hdr_data_size $1 + append-u32 $cmd_hdr_command $1 +} + +#------------------------------------------------------------------------ +# write-attr-request +# +# Produce a binary file that can be copied to the +# SBE COMMS AREA for use as an SBE Pass-through +# request. The caller should pass the path of a binary file +# that contains attribute override information. The contents of +# the attribute override file will be concatenated to a file +# containing a request header. This file should be copied to +# the SBE COMMS AREA prior to invoking sbeMsg. +# +# write-attr-request $1 <attribute override data file> +# $2 <outfile> +# $3 [Sequence Number of the request] +# +# Parameters: +# attr data file: A file produced by the attributeOverride tool. +# This file contains attribute overrides in binary +# form. +# outfile: The request file. This file is the concatenation of an +# SBE Pass-through request header and the attribute +# override data from the first parameter. +# sequence : A sequence number to identify the request/response. +#------------------------------------------------------------------------- +write-attr-request(){ + if [ -z "$1" ] || [ -z "$2" ] + then + echo "usage write-attr-request <attr data file> <outfile> [sequence]" + return + fi + + #Get payload size + attrsize=$(wc -c $1 | awk '{print $1; exit}') + let attrsize=$(($attrsize)) + attrsize=$(printf "0x%08x" $attrsize) + + #Set sequence number + if [ -z $3 ] + then + sb_hdr_seq_id=0x00000001 + else + sb_hdr_seq_id=$3 + fi + + #write request header to temp file + tmpfile=/tmp/attr_override_request_$$ + write-attr-request-hdr $tmpfile $attrsize $sb_hdr_seq_id + + #Create request file and remove temporary + cat $tmpfile $1 > $2 + rm -f $tmpfile +} + +#---------------------------------------------------------- +# parse-attr-resp +# Parses a binary file, the contents of which represent +# a response to an SBE Pass-Through command. The xxd +# utility will convert the values returned from Big Endian +# to host byte order. +# +# parse-attr-resp $1 <input binary file> +#---------------------------------------------------------- +parse-attr-resp(){ + if [ -z "$1" ] + then + echo "usage parse-attr-resp <bin file>" + return + fi + + let sbe_hdr_version=0x$(xxd -p -l4 -s0 $1) + let sbe_hdr_msg_size=0x$(xxd -p -l4 -s4 $1) + let sbe_hdr_seq_id=0x$(xxd -p -l4 -s8 $1) + let cmd_hdr_version=0x$(xxd -p -l4 -s12 $1) + let cmd_hdr_status=0x$(xxd -p -l4 -s16 $1) + let cmd_hdr_data_offset=0x$(xxd -p -l4 -s20 $1) + let cmd_hdr_data_size=0x$(xxd -p -l4 -s24 $1) + let cmd_hdr_command=0x$(xxd -p -l4 -s28 $1) + + echo "" + echo "Attribute Override Response:" + printf "\tSBE HDR Version: 0x%08X\n" $sbe_hdr_version + printf "\tSBE HDR MSG Size: 0x%08X (%d)\n" $sbe_hdr_msg_size \ + $sbe_hdr_msg_size + printf "\tSBE HDR SEQ ID: 0x%08X (%d)\n" $sbe_hdr_seq_id \ + $sbe_hdr_seq_id + printf "\tCMD HDR VERSION: 0x%08X\n" $cmd_hdr_version + printf "\tCMD HDR STATUS: 0x%08X\n" $cmd_hdr_status + printf "\tCMD HDR DATA OFFSET: 0x%08X (%d)\n" $cmd_hdr_data_offset \ + $cmd_hdr_data_offset + printf "\tCMD HDR DATA SIZE: 0x%08X (%d)\n" $cmd_hdr_data_size \ + $cmd_hdr_data_size + printf "\tCMD HDR CMD: 0x%08X\n" $cmd_hdr_command + echo "" +} |