From bed103fa4c741d2c22764e45e496b3af5ea104ac Mon Sep 17 00:00:00 2001 From: spashabk-in Date: Thu, 9 Mar 2017 01:20:04 -0600 Subject: Consolidating globals in SBE Overall an increase in size of 88bytes Change-Id: I975ec1536bc2d8153772133d26f750688a849a70 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/37714 Reviewed-by: Sachin Gupta Tested-by: Jenkins Server Tested-by: FSP CI Jenkins --- src/hwpf/src/plat/plat_utils.C | 5 +- src/sbefw/sbeFifoMsgUtils.C | 8 ++- src/sbefw/sbeFifoMsgUtils.H | 8 +-- src/sbefw/sbeHostMsg.C | 36 +++++++++++++ src/sbefw/sbeHostMsg.H | 16 +----- src/sbefw/sbeHostUtils.C | 9 ++-- src/sbefw/sbeSpMsg.C | 37 ++++++++++++++ src/sbefw/sbeSpMsg.H | 17 +------ src/sbefw/sbecmdCntrlTimer.C | 15 +++--- src/sbefw/sbecmdcntrldmt.C | 13 ++--- src/sbefw/sbecmdgeneric.C | 7 +-- src/sbefw/sbecmdiplcontrol.C | 21 ++++---- src/sbefw/sbecmdprocessor.C | 53 +++++++++---------- src/sbefw/sbecmdreceiver.C | 83 ++++++++++++++---------------- src/sbefw/sbecmdringaccess.C | 11 ++-- src/sbefw/sbecmdscomaccess.C | 19 +++---- src/sbefw/sbeexeintf.H | 23 +-------- src/sbefw/sbefwfiles.mk | 3 ++ src/sbefw/sbeglobals.C | 33 ++++++++++++ src/sbefw/sbeglobals.H | 112 +++++++++++++++++++++++++++++++++++++++++ src/sbefw/sbeirq.C | 13 +++-- src/sbefw/sbemain.C | 55 +++++--------------- src/sbefw/sbestates.H | 4 +- src/sbefw/sbeutil.C | 7 +-- src/sbefw/sbeutil.H | 1 - 25 files changed, 377 insertions(+), 232 deletions(-) create mode 100644 src/sbefw/sbeHostMsg.C create mode 100644 src/sbefw/sbeSpMsg.C create mode 100644 src/sbefw/sbeglobals.C create mode 100644 src/sbefw/sbeglobals.H (limited to 'src') diff --git a/src/hwpf/src/plat/plat_utils.C b/src/hwpf/src/plat/plat_utils.C index 73a2609d..fe810f4f 100644 --- a/src/hwpf/src/plat/plat_utils.C +++ b/src/hwpf/src/plat/plat_utils.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER sbe Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2015,2016 */ +/* Contributors Listed Below - COPYRIGHT 2015,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -35,6 +35,7 @@ #include #include #include +#include namespace fapi2 { @@ -44,7 +45,7 @@ namespace fapi2 // frequency till istep 2.7 inline uint64_t delayCycles(uint64_t i_nanoSeconds ) { - return ( i_nanoSeconds/1000) * ( g_sbefreq /(1000*1000)); + return ( i_nanoSeconds/1000) * ( SBE_GLOBAL->sbefreq /(1000*1000)); } /// @brief Delay this thread. /// diff --git a/src/sbefw/sbeFifoMsgUtils.C b/src/sbefw/sbeFifoMsgUtils.C index 99af2802..bed08a42 100644 --- a/src/sbefw/sbeFifoMsgUtils.C +++ b/src/sbefw/sbeFifoMsgUtils.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER sbe Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2015,2016 */ +/* Contributors Listed Below - COPYRIGHT 2015,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -38,6 +38,7 @@ #include "assert.h" #include "sbeFFDC.H" #include "hwp_error_info.H" +#include "sbeglobals.H" // If we can not perform FIFO operation ( FIFO FULL while writing // or EMPTY while reading ) we will sleep for FIFO_WAIT_SLEEP_TIME @@ -49,6 +50,11 @@ static const uint32_t FIFO_WAIT_SLEEP_TIME = 1; static const uint64_t DOWNSTREAM_EOT_DATA = 0x100000000ull; using namespace fapi2; +inline uint32_t sbeBuildRespHeaderStatusWordGlobal (void) +{ + return ( (((uint32_t)SBE_GLOBAL->sbeCmdRespHdr.prim_status)<<16) | + (SBE_GLOBAL->sbeCmdRespHdr.sec_status) ); +} ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// uint32_t sbeUpFifoDeq_mult (uint32_t &io_len, diff --git a/src/sbefw/sbeFifoMsgUtils.H b/src/sbefw/sbeFifoMsgUtils.H index f652b296..877f0b17 100644 --- a/src/sbefw/sbeFifoMsgUtils.H +++ b/src/sbefw/sbeFifoMsgUtils.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER sbe Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2016 */ +/* Contributors Listed Below - COPYRIGHT 2016,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -105,11 +105,7 @@ extern uint32_t sbeDownFifoEnq_mult (uint32_t &io_len, * @return Returns the status word in the response header * */ -extern inline uint32_t sbeBuildRespHeaderStatusWordGlobal (void) -{ - return ( (((uint32_t)g_sbeCmdRespHdr.prim_status)<<16) | - (g_sbeCmdRespHdr.sec_status) ); -} +extern inline uint32_t sbeBuildRespHeaderStatusWordGlobal (void); /** * @brief sbeBuildRespHeaderStatusWordLocal diff --git a/src/sbefw/sbeHostMsg.C b/src/sbefw/sbeHostMsg.C new file mode 100644 index 00000000..720e1e89 --- /dev/null +++ b/src/sbefw/sbeHostMsg.C @@ -0,0 +1,36 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/sbefw/sbeHostMsg.C $ */ +/* */ +/* OpenPOWER sbe 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 "sbetrace.H" +#include "sbeHostMsg.H" +#include "sbeglobals.H" + +void sbeSbe2PsuRespHdr_t::init(void) +{ + primStatus = SBE_PRI_OPERATION_SUCCESSFUL; + secStatus = SBE_SEC_OPERATION_SUCCESSFUL; + seqID = SBE_GLOBAL->sbePsu2SbeCmdReqHdr.seqID; + cmdClass = SBE_GLOBAL->sbePsu2SbeCmdReqHdr.cmdClass; + command = SBE_GLOBAL->sbePsu2SbeCmdReqHdr.command; +} diff --git a/src/sbefw/sbeHostMsg.H b/src/sbefw/sbeHostMsg.H index ceca1bc5..8fa6fe2c 100644 --- a/src/sbefw/sbeHostMsg.H +++ b/src/sbefw/sbeHostMsg.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER sbe Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2016 */ +/* Contributors Listed Below - COPYRIGHT 2016,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -68,9 +68,6 @@ typedef struct } } sbePsu2SbeCmdReqHdr_t; -extern sbePsu2SbeCmdReqHdr_t g_sbePsu2SbeCmdReqHdr; - - /*****************************************************************/ /* SBE->PSU response structures */ /*****************************************************************/ @@ -118,16 +115,7 @@ typedef struct * @brief initialize the response fields contained in PSU Mbx3 * */ - void init() - { - primStatus = SBE_PRI_OPERATION_SUCCESSFUL; - secStatus = SBE_SEC_OPERATION_SUCCESSFUL; - seqID = g_sbePsu2SbeCmdReqHdr.seqID; - cmdClass = g_sbePsu2SbeCmdReqHdr.cmdClass; - command = g_sbePsu2SbeCmdReqHdr.command; - } + void init(); } sbeSbe2PsuRespHdr_t; -extern sbeSbe2PsuRespHdr_t g_sbeSbe2PsuRespHdr; - #endif // __SBEFW_SBEHOST_MSG_H diff --git a/src/sbefw/sbeHostUtils.C b/src/sbefw/sbeHostUtils.C index 4cd95049..310bf9dc 100644 --- a/src/sbefw/sbeHostUtils.C +++ b/src/sbefw/sbeHostUtils.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER sbe Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2016 */ +/* Contributors Listed Below - COPYRIGHT 2016,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -37,6 +37,7 @@ #include "sbeerrorcodes.H" #include "assert.h" #include "fapi2.H" +#include "sbeglobals.H" /////////////////////////////////////////////////////////////////// @@ -109,7 +110,7 @@ uint32_t sbeIntrHostUponRespWaiting () // Interrupt the host by setting bit0 in SBE->PSU DB register // if the caller requested for it. - if (g_sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_RESP_REQUIRED) + if (SBE_GLOBAL->sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_RESP_REQUIRED) { l_rc = sbeSetSbe2PsuDbBitX(SBE_SBE2PSU_DOORBELL_SET_BIT0); } @@ -124,7 +125,7 @@ uint32_t sbeAcknowledgeHost () // Set the Ack bit in SBE->PSU DB register // if the caller requested for it. - if (g_sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_ACK_REQUIRED) + if (SBE_GLOBAL->sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_ACK_REQUIRED) { l_rc = sbeSetSbe2PsuDbBitX(SBE_SBE2PSU_DOORBELL_SET_BIT1); } @@ -147,7 +148,7 @@ uint32_t sbeWriteSbe2PsuMbxReg (uint32_t i_addr, assert( (SBE_HOST_PSU_MBOX_REG4 <= i_addr) && (SBE_HOST_PSU_MBOX_REG7 >= (i_addr + i_count - 1)) ) - if( g_sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_RESP_REQUIRED ) + if( SBE_GLOBAL->sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_RESP_REQUIRED ) { while (l_count < i_count) { diff --git a/src/sbefw/sbeSpMsg.C b/src/sbefw/sbeSpMsg.C new file mode 100644 index 00000000..04556f52 --- /dev/null +++ b/src/sbefw/sbeSpMsg.C @@ -0,0 +1,37 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/sbefw/sbeSpMsg.C $ */ +/* */ +/* OpenPOWER sbe 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 "sbeutil.H" +#include "sbetrace.H" +#include "sbeSpMsg.H" +#include "sbeglobals.H" + +void sbeRespGenHdr_t::init(void) +{ + magicCode = 0xC0DE; + cmdClass = SBE_GLOBAL->sbeFifoCmdHdr.cmdClass; + command = SBE_GLOBAL->sbeFifoCmdHdr.command; + primaryStatus = SBE_PRI_OPERATION_SUCCESSFUL; + secondaryStatus = SBE_SEC_OPERATION_SUCCESSFUL; +} diff --git a/src/sbefw/sbeSpMsg.H b/src/sbefw/sbeSpMsg.H index c711c223..78b6e168 100644 --- a/src/sbefw/sbeSpMsg.H +++ b/src/sbefw/sbeSpMsg.H @@ -57,8 +57,6 @@ typedef struct uint32_t command:8; }sbeFifoCmdReqBuf_t; -extern sbeFifoCmdReqBuf_t g_sbeFifoCmdHdr; - /** * @brief structure for generic header for fifo response. * @@ -89,19 +87,11 @@ typedef struct * @brief set initial values for response header * * @note We did not set this in constructor as based on use case - * it is possible that g_sbeFifoCmdHdr does not have proper + * it is possible that SBE_GLOBAL->sbeFifoCmdHdr does not have proper * values at time of object creation. * */ - void init() - { - magicCode = 0xC0DE; - cmdClass = g_sbeFifoCmdHdr.cmdClass; - command = g_sbeFifoCmdHdr.command; - primaryStatus = SBE_PRI_OPERATION_SUCCESSFUL; - secondaryStatus = SBE_SEC_OPERATION_SUCCESSFUL; - } - + void init(); }sbeRespGenHdr_t; /** @@ -505,9 +495,6 @@ typedef struct } } sbeCmdRespHdr_t; -extern sbeCmdRespHdr_t g_sbeCmdRespHdr; - - /** * @brief structure for Stop Clocks Chipop (0xA901) contents. * diff --git a/src/sbefw/sbecmdCntrlTimer.C b/src/sbefw/sbecmdCntrlTimer.C index 62324979..db07076a 100644 --- a/src/sbefw/sbecmdCntrlTimer.C +++ b/src/sbefw/sbecmdCntrlTimer.C @@ -36,6 +36,7 @@ #include "sbeHostMsg.H" #include "sbeHostUtils.H" #include "sbeTimerSvc.H" +#include "sbeglobals.H" #include "fapi2.H" using namespace fapi2; @@ -78,7 +79,7 @@ uint32_t sbeCntrlTimer( uint8_t *i_pArg ) do { - if(g_sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_START_TIMER) + if(SBE_GLOBAL->sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_START_TIMER) { uint64_t time = 0; l_rc = sbeReadPsu2SbeMbxReg(SBE_HOST_PSU_MBOX_REG1, @@ -98,7 +99,7 @@ uint32_t sbeCntrlTimer( uint8_t *i_pArg ) (PkTimerCallback)&sbeTimerExpiryCallback); if(SBE_SEC_OPERATION_SUCCESSFUL != l_rc) { - g_sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INTERNAL_ERROR, l_rc); + SBE_GLOBAL->sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INTERNAL_ERROR, l_rc); SBE_ERROR(SBE_FUNC" g_hostTimerSvc.startTimer failed"); l_rc = SBE_SEC_OPERATION_SUCCESSFUL; break; @@ -114,13 +115,13 @@ uint32_t sbeCntrlTimer( uint8_t *i_pArg ) break; } - if(g_sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_STOP_TIMER) + if(SBE_GLOBAL->sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_STOP_TIMER) { SBE_INFO(SBE_FUNC "Stop Timer."); l_rc = g_hostTimerSvc.stopTimer( ); if(SBE_SEC_OPERATION_SUCCESSFUL != l_rc) { - g_sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INTERNAL_ERROR, l_rc); + SBE_GLOBAL->sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INTERNAL_ERROR, l_rc); SBE_ERROR(SBE_FUNC" g_hostTimerSvc.stopTimer failed"); l_rc = SBE_SEC_OPERATION_SUCCESSFUL; break; @@ -128,14 +129,14 @@ uint32_t sbeCntrlTimer( uint8_t *i_pArg ) break; } - g_sbeSbe2PsuRespHdr.setStatus( SBE_PRI_INVALID_COMMAND, + SBE_GLOBAL->sbeSbe2PsuRespHdr.setStatus( SBE_PRI_INVALID_COMMAND, SBE_SEC_COMMAND_NOT_SUPPORTED); SBE_ERROR(SBE_FUNC" Not a valid flag 0x%4X", - (uint16_t) g_sbePsu2SbeCmdReqHdr.flags); + (uint16_t) SBE_GLOBAL->sbePsu2SbeCmdReqHdr.flags); }while(0); // Send the response - sbePSUSendResponse(g_sbeSbe2PsuRespHdr, l_fapiRc, l_rc); + sbePSUSendResponse(SBE_GLOBAL->sbeSbe2PsuRespHdr, l_fapiRc, l_rc); SBE_EXIT(SBE_FUNC); return l_rc; diff --git a/src/sbefw/sbecmdcntrldmt.C b/src/sbefw/sbecmdcntrldmt.C index d630c59f..79c61697 100644 --- a/src/sbefw/sbecmdcntrldmt.C +++ b/src/sbefw/sbecmdcntrldmt.C @@ -43,6 +43,7 @@ #include "p9_perv_scom_addresses.H" #include "p9_block_wakeup_intr.H" #include "sbeTimerSvc.H" +#include "sbeglobals.H" using namespace fapi2; @@ -109,12 +110,12 @@ uint32_t sbeStartCntlDmt() (PkTimerCallback)&sbeDmtPkExpiryCallback); if(SBE_SEC_OPERATION_SUCCESSFUL != l_rc) { - g_sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INTERNAL_ERROR, l_rc); + SBE_GLOBAL->sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INTERNAL_ERROR, l_rc); SBE_ERROR(SBE_FUNC" g_sbe_pk_dmt_timer.startTimer failed"); l_rc = SBE_SEC_OPERATION_SUCCESSFUL; } - sbePSUSendResponse(g_sbeSbe2PsuRespHdr, l_fapiRc, l_rc); + sbePSUSendResponse(SBE_GLOBAL->sbeSbe2PsuRespHdr, l_fapiRc, l_rc); if(SBE_SEC_OPERATION_SUCCESSFUL != l_rc) { @@ -204,7 +205,7 @@ uint32_t sbeStopCntlDmt() l_rc = g_sbe_pk_dmt_timer.stopTimer( ); if(SBE_SEC_OPERATION_SUCCESSFUL != l_rc) { - g_sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INTERNAL_ERROR, l_rc); + SBE_GLOBAL->sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INTERNAL_ERROR, l_rc); SBE_ERROR(SBE_FUNC"g_sbe_pk_dmt_timer.stopTimer failed"); l_rc = SBE_SEC_OPERATION_SUCCESSFUL; break; @@ -214,7 +215,7 @@ uint32_t sbeStopCntlDmt() SBE_DMT_COMP_EVENT); }while(0); // Send the response - sbePSUSendResponse(g_sbeSbe2PsuRespHdr, l_fapiRc, l_rc); + sbePSUSendResponse(SBE_GLOBAL->sbeSbe2PsuRespHdr, l_fapiRc, l_rc); return l_rc; #undef SBE_FUNC @@ -230,7 +231,7 @@ uint32_t sbeControlDeadmanTimer (uint8_t *i_pArg) do { - if(g_sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_START_DMT) + if(SBE_GLOBAL->sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_START_DMT) { l_rc = sbeStartCntlDmt(); if(SBE_SEC_OPERATION_SUCCESSFUL != l_rc) @@ -250,7 +251,7 @@ uint32_t sbeControlDeadmanTimer (uint8_t *i_pArg) break; } - if(g_sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_STOP_DMT) + if(SBE_GLOBAL->sbePsu2SbeCmdReqHdr.flags & SBE_PSU_FLAGS_STOP_DMT) { l_rc = sbeStopCntlDmt(); if(SBE_SEC_OPERATION_SUCCESSFUL != l_rc) diff --git a/src/sbefw/sbecmdgeneric.C b/src/sbefw/sbecmdgeneric.C index 444548ee..e9bf8a47 100644 --- a/src/sbefw/sbecmdgeneric.C +++ b/src/sbefw/sbecmdgeneric.C @@ -40,6 +40,7 @@ #include "sbestates.H" #include "sbeHostMsg.H" #include "sbeHostUtils.H" +#include "sbeglobals.H" #include "fapi2.H" @@ -274,8 +275,8 @@ uint32_t sbePsuQuiesce( uint8_t *i_pArg ) SBE_QUIESCE_EVENT); rc = sbeWriteSbe2PsuMbxReg(SBE_HOST_PSU_MBOX_REG4, - (uint64_t*)(&g_sbeSbe2PsuRespHdr), - (sizeof(g_sbeSbe2PsuRespHdr)/sizeof(uint64_t)), + (uint64_t*)(&SBE_GLOBAL->sbeSbe2PsuRespHdr), + (sizeof(SBE_GLOBAL->sbeSbe2PsuRespHdr)/sizeof(uint64_t)), true); if(rc != SBE_SEC_OPERATION_SUCCESSFUL) { @@ -324,7 +325,7 @@ uint32_t sbeSetSystemFabricMap( uint8_t *i_pArg ) }while(0); // Send the response - sbePSUSendResponse(g_sbeSbe2PsuRespHdr, l_fapiRc, l_rc); + sbePSUSendResponse(SBE_GLOBAL->sbeSbe2PsuRespHdr, l_fapiRc, l_rc); SBE_EXIT(SBE_FUNC); return l_rc; diff --git a/src/sbefw/sbecmdiplcontrol.C b/src/sbefw/sbecmdiplcontrol.C index cc428f48..9b4e34fd 100644 --- a/src/sbefw/sbecmdiplcontrol.C +++ b/src/sbefw/sbecmdiplcontrol.C @@ -38,6 +38,7 @@ #include "sberegaccess.H" #include "sbestates.H" #include "sbecmdcntrldmt.H" +#include "sbeglobals.H" #include "fapi2.H" #include "p9_misc_scom_addresses_fld.H" @@ -214,9 +215,7 @@ static const uint64_t N3_FIR_SYSTEM_CHECKSTOP_BIT = 33; // Globals // TODO: via RTC 123602 This global needs to move to a class that will store the // SBE FFDC. -fapi2::ReturnCode g_iplFailRc = FAPI2_RC_SUCCESS; - -sbeRole g_sbeRole = SBE_ROLE_MASTER; +static fapi2::ReturnCode g_iplFailRc = FAPI2_RC_SUCCESS; static istepMap_t g_istepMpiplStartPtrTbl[MPIPL_START_MAX_SUBSTEPS] = { @@ -540,7 +539,7 @@ bool validateIstep (const uint8_t i_major, const uint8_t i_minor) case SBE_ISTEP3: if( (i_minor > ISTEP3_MAX_SUBSTEPS ) || - ((SBE_ROLE_SLAVE == g_sbeRole) && + ((SBE_ROLE_SLAVE == SBE_GLOBAL->SBERole) && (i_minor > SLAVE_LAST_MINOR_ISTEP)) ) { valid = false; @@ -549,7 +548,7 @@ bool validateIstep (const uint8_t i_major, const uint8_t i_minor) case SBE_ISTEP4: if( (i_minor > ISTEP4_MAX_SUBSTEPS ) || - (SBE_ROLE_SLAVE == g_sbeRole) ) + (SBE_ROLE_SLAVE == SBE_GLOBAL->SBERole) ) { valid = false; } @@ -557,7 +556,7 @@ bool validateIstep (const uint8_t i_major, const uint8_t i_minor) case SBE_ISTEP5: if( (i_minor > ISTEP5_MAX_SUBSTEPS ) || - (SBE_ROLE_SLAVE == g_sbeRole) ) + (SBE_ROLE_SLAVE == SBE_GLOBAL->SBERole) ) { valid = false; } @@ -807,10 +806,10 @@ ReturnCode istepCheckSbeMaster( sbeIstepHwp_t i_hwp) SBE_ERROR(SBE_FUNC" performTpmReset failed"); break; } - g_sbeRole = SbeRegAccess::theSbeRegAccess().isSbeSlave() ? + SBE_GLOBAL->SBERole = SbeRegAccess::theSbeRegAccess().isSbeSlave() ? SBE_ROLE_SLAVE : SBE_ROLE_MASTER; - SBE_INFO(SBE_FUNC"g_sbeRole [%x]", g_sbeRole); - if(SBE_ROLE_SLAVE == g_sbeRole) + SBE_INFO(SBE_FUNC"SBE_GLOBAL->SBERole [%x]", SBE_GLOBAL->SBERole); + if(SBE_ROLE_SLAVE == SBE_GLOBAL->SBERole) { (void)SbeRegAccess::theSbeRegAccess().stateTransition( SBE_RUNTIME_EVENT); @@ -878,7 +877,7 @@ void sbeDoContinuousIpl() // Check if we are at step 3.20 on the slave SBE if(((SBE_ISTEP_LAST_SLAVE == l_major) && (SLAVE_LAST_MINOR_ISTEP == l_minor)) && - (SBE_ROLE_SLAVE == g_sbeRole)) + (SBE_ROLE_SLAVE == SBE_GLOBAL->SBERole)) { l_done = true; break; @@ -1109,7 +1108,7 @@ ReturnCode istepMpiplQuadPoweroff( sbeIstepHwp_t i_hwp) #define SBE_FUNC "istepMpiplQuadPoweroff" SBE_ENTER(SBE_FUNC); ReturnCode l_rc = FAPI2_RC_SUCCESS; - if(g_sbeRole == SBE_ROLE_MASTER) + if(SBE_GLOBAL->SBERole == SBE_ROLE_MASTER) { Target l_proc = plat_getChipTarget(); // Fetch the MASTER_CORE attribute diff --git a/src/sbefw/sbecmdprocessor.C b/src/sbefw/sbecmdprocessor.C index 56c4c153..6339268b 100644 --- a/src/sbefw/sbecmdprocessor.C +++ b/src/sbefw/sbecmdprocessor.C @@ -46,6 +46,7 @@ #include "sbestates.H" #include "fapi2.H" #include "sbeutil.H" +#include "sbeglobals.H" using namespace fapi2; // Forward declaration for performAttrSetup @@ -74,27 +75,27 @@ void sbeHandlePsuResponse (const uint32_t i_rc) break; } // Set primary and secondary status - g_sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INVALID_COMMAND, i_rc); + SBE_GLOBAL->sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INVALID_COMMAND, i_rc); // Now Update SBE->PSU Mbx Reg4 with response - l_cnt = sizeof(g_sbeSbe2PsuRespHdr)/ + l_cnt = sizeof(SBE_GLOBAL->sbeSbe2PsuRespHdr)/ sizeof(uint64_t); l_rc = sbeWriteSbe2PsuMbxReg(SBE_HOST_PSU_MBOX_REG4, reinterpret_cast( - &g_sbeSbe2PsuRespHdr), l_cnt, true); + &SBE_GLOBAL->sbeSbe2PsuRespHdr), l_cnt, true); break; case SBE_SEC_OS_FAILURE: // Set primary and secondary status - g_sbeSbe2PsuRespHdr.setStatus(SBE_PRI_GENERIC_EXECUTION_FAILURE, + SBE_GLOBAL->sbeSbe2PsuRespHdr.setStatus(SBE_PRI_GENERIC_EXECUTION_FAILURE, i_rc); // Now Update SBE->PSU Mbx Reg4 with response - l_cnt = sizeof(g_sbeSbe2PsuRespHdr)/ + l_cnt = sizeof(SBE_GLOBAL->sbeSbe2PsuRespHdr)/ sizeof(uint64_t); l_rc = sbeWriteSbe2PsuMbxReg(SBE_HOST_PSU_MBOX_REG4, reinterpret_cast( - &g_sbeSbe2PsuRespHdr), l_cnt, true); + &SBE_GLOBAL->sbeSbe2PsuRespHdr), l_cnt, true); break; case SBE_SEC_OPERATION_SUCCESSFUL: @@ -280,7 +281,7 @@ void sbeSyncCommandProcessor_routine(void *i_pArg) // Wait for new command processing int l_rcPk = pk_semaphore_pend ( - &g_sbeSemCmdProcess, PK_WAIT_FOREVER); + &SBE_GLOBAL->sbeSemCmdProcess, PK_WAIT_FOREVER); do { @@ -295,35 +296,35 @@ void sbeSyncCommandProcessor_routine(void *i_pArg) fapi2::current_err = fapi2::FAPI2_RC_SUCCESS; // Check on the Rx Thread Interrupt Bits for Interrupt Status - if ( g_sbeIntrSource.isSet(SBE_RX_ROUTINE, + if ( SBE_GLOBAL->sbeIntrSource.isSet(SBE_RX_ROUTINE, SBE_INTERFACE_PSU) ) { - l_rc = g_sbeSbe2PsuRespHdr.secStatus; - l_cmdClass = g_sbePsu2SbeCmdReqHdr.cmdClass; - l_cmdOpCode = g_sbePsu2SbeCmdReqHdr.command; + l_rc = SBE_GLOBAL->sbeSbe2PsuRespHdr.secStatus; + l_cmdClass = SBE_GLOBAL->sbePsu2SbeCmdReqHdr.cmdClass; + l_cmdOpCode = SBE_GLOBAL->sbePsu2SbeCmdReqHdr.command; // Set this here, so that during response handling we know which // interrupt we are processing, need not check for - // g_sbeIntrSource again - g_sbeIntrSource.setIntrSource(SBE_PROC_ROUTINE, + // SBE_GLOBAL->sbeIntrSource again + SBE_GLOBAL->sbeIntrSource.setIntrSource(SBE_PROC_ROUTINE, SBE_INTERFACE_PSU); } - else if ( g_sbeIntrSource.isSet(SBE_RX_ROUTINE, + else if ( SBE_GLOBAL->sbeIntrSource.isSet(SBE_RX_ROUTINE, SBE_INTERFACE_FIFO) ) { - l_rc = g_sbeCmdRespHdr.sec_status; - l_cmdClass = g_sbeFifoCmdHdr.cmdClass; - l_cmdOpCode = g_sbeFifoCmdHdr.command; + l_rc = SBE_GLOBAL->sbeCmdRespHdr.sec_status; + l_cmdClass = SBE_GLOBAL->sbeFifoCmdHdr.cmdClass; + l_cmdOpCode = SBE_GLOBAL->sbeFifoCmdHdr.command; // Set this here, so that during response handling we know which // interrupt we are processing, need not check for - // g_sbeIntrSource again - g_sbeIntrSource.setIntrSource(SBE_PROC_ROUTINE, + // SBE_GLOBAL->sbeIntrSource again + SBE_GLOBAL->sbeIntrSource.setIntrSource(SBE_PROC_ROUTINE, SBE_INTERFACE_FIFO); } else // SBE_INTERFACE_FIFO_RESET or SBE_INTERFACE_UNKNOWN { SBE_ERROR(SBE_FUNC"Unexpected interrupt communicated to the " "processor thread. Interrupt source: 0x%02X 0x%02X", - g_sbeIntrSource.intrSource, g_sbeIntrSource.rxThrIntrSource); + SBE_GLOBAL->sbeIntrSource.intrSource, SBE_GLOBAL->sbeIntrSource.rxThrIntrSource); assert(false); break; } @@ -332,8 +333,8 @@ void sbeSyncCommandProcessor_routine(void *i_pArg) if (l_rcPk != PK_OK) { SBE_ERROR(SBE_FUNC"pk_semaphore_pend failed, " - "l_rcPk=%d, g_sbeSemCmdRecv.count=%d", - l_rcPk, g_sbeSemCmdRecv.count); + "l_rcPk=%d, SBE_GLOBAL->sbeSemCmdRecv.count=%d", + l_rcPk, SBE_GLOBAL->sbeSemCmdRecv.count); // If it's a semphore_pend error then update the same to show // internal failure @@ -357,20 +358,20 @@ void sbeSyncCommandProcessor_routine(void *i_pArg) SBE_INFO (SBE_FUNC"Command processesed. l_rc=[0x%04X]", l_rc ); - if ( g_sbeIntrSource.isSet(SBE_PROC_ROUTINE, SBE_INTERFACE_PSU) ) + if ( SBE_GLOBAL->sbeIntrSource.isSet(SBE_PROC_ROUTINE, SBE_INTERFACE_PSU) ) { sbeHandlePsuResponse (l_rc); // Enable Host interrupt - g_sbeIntrSource.clearIntrSource(SBE_ALL_HANDLER,SBE_INTERFACE_PSU); + SBE_GLOBAL->sbeIntrSource.clearIntrSource(SBE_ALL_HANDLER,SBE_INTERFACE_PSU); pk_irq_enable(SBE_IRQ_HOST_PSU_INTR); } - else if ( g_sbeIntrSource.isSet(SBE_PROC_ROUTINE, SBE_INTERFACE_FIFO) ) + else if ( SBE_GLOBAL->sbeIntrSource.isSet(SBE_PROC_ROUTINE, SBE_INTERFACE_FIFO) ) { sbeHandleFifoResponse (l_rc); // Enable the new data available interrupt - g_sbeIntrSource.clearIntrSource(SBE_ALL_HANDLER,SBE_INTERFACE_FIFO); + SBE_GLOBAL->sbeIntrSource.clearIntrSource(SBE_ALL_HANDLER,SBE_INTERFACE_FIFO); pk_irq_enable(SBE_IRQ_SBEFIFO_DATA); pk_irq_enable(SBE_IRQ_SBEFIFO_RESET); } diff --git a/src/sbefw/sbecmdreceiver.C b/src/sbefw/sbecmdreceiver.C index a68d9288..855cf458 100644 --- a/src/sbefw/sbecmdreceiver.C +++ b/src/sbefw/sbecmdreceiver.C @@ -42,12 +42,7 @@ #include "sbeHostUtils.H" #include "sberegaccess.H" #include "sbeutil.H" - -sbeFifoCmdReqBuf_t g_sbeFifoCmdHdr; -sbeCmdRespHdr_t g_sbeCmdRespHdr; -sbePsu2SbeCmdReqHdr_t g_sbePsu2SbeCmdReqHdr; -sbeSbe2PsuRespHdr_t g_sbeSbe2PsuRespHdr; -sbeIntrHandle_t g_sbeIntrSource; +#include "sbeglobals.H" ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// @@ -66,7 +61,7 @@ void sbeCommandReceiver_routine(void *i_pArg) // @TODO via RTC: 128944 // Read Scratchpad // Wait for new data in FIFO or FIFO reset interrupt or PSU interrupt - int l_rcPk = pk_semaphore_pend (&g_sbeSemCmdRecv, PK_WAIT_FOREVER); + int l_rcPk = pk_semaphore_pend (&SBE_GLOBAL->sbeSemCmdRecv, PK_WAIT_FOREVER); do { @@ -86,7 +81,7 @@ void sbeCommandReceiver_routine(void *i_pArg) // class and the command opcode parameters. // Received FIFO Reset interrupt - if ( g_sbeIntrSource.isSet(SBE_INTERRUPT_ROUTINE, + if ( SBE_GLOBAL->sbeIntrSource.isSet(SBE_INTERRUPT_ROUTINE, SBE_INTERFACE_FIFO_RESET) ) { SBE_ERROR(SBE_FUNC"FIFO reset received"); @@ -95,11 +90,11 @@ void sbeCommandReceiver_routine(void *i_pArg) } // Received PSU interrupt - if ( g_sbeIntrSource.isSet(SBE_INTERRUPT_ROUTINE, + if ( SBE_GLOBAL->sbeIntrSource.isSet(SBE_INTERRUPT_ROUTINE, SBE_INTERFACE_PSU) ) { //Clear the Interrupt Source bit for PSU - g_sbeIntrSource.clearIntrSource(SBE_INTERRUPT_ROUTINE, + SBE_GLOBAL->sbeIntrSource.clearIntrSource(SBE_INTERRUPT_ROUTINE, SBE_INTERFACE_PSU); curInterface = SBE_INTERFACE_PSU; // First clear PSU->SBE DB bit 0 @@ -109,25 +104,25 @@ void sbeCommandReceiver_routine(void *i_pArg) break; } - // Initialize the g_sbePsu2SbeCmdReqHdr - g_sbePsu2SbeCmdReqHdr.init(); + // Initialize the SBE_GLOBAL->sbePsu2SbeCmdReqHdr + SBE_GLOBAL->sbePsu2SbeCmdReqHdr.init(); // Read the request field from PSU->SBE Mbx Reg0 - uint8_t l_cnt = sizeof(g_sbePsu2SbeCmdReqHdr)/sizeof(uint64_t); + uint8_t l_cnt = sizeof(SBE_GLOBAL->sbePsu2SbeCmdReqHdr)/sizeof(uint64_t); l_rc = sbeReadPsu2SbeMbxReg(SBE_HOST_PSU_MBOX_REG0, l_cnt, - (uint64_t *)&g_sbePsu2SbeCmdReqHdr); + (uint64_t *)&SBE_GLOBAL->sbePsu2SbeCmdReqHdr); - g_sbeSbe2PsuRespHdr.init(); - l_cmdClass = g_sbePsu2SbeCmdReqHdr.cmdClass; - l_command = g_sbePsu2SbeCmdReqHdr.command; + SBE_GLOBAL->sbeSbe2PsuRespHdr.init(); + l_cmdClass = SBE_GLOBAL->sbePsu2SbeCmdReqHdr.cmdClass; + l_command = SBE_GLOBAL->sbePsu2SbeCmdReqHdr.command; } // end if loop for PSU interface chipOp handling // Received FIFO New Data interrupt - else if ( g_sbeIntrSource.isSet(SBE_INTERRUPT_ROUTINE, + else if ( SBE_GLOBAL->sbeIntrSource.isSet(SBE_INTERRUPT_ROUTINE, SBE_INTERFACE_FIFO) ) { //Clear the Interrupt Source bit for FIFO - g_sbeIntrSource.clearIntrSource(SBE_INTERRUPT_ROUTINE, + SBE_GLOBAL->sbeIntrSource.clearIntrSource(SBE_INTERRUPT_ROUTINE, SBE_INTERFACE_FIFO); curInterface = SBE_INTERFACE_FIFO; @@ -139,14 +134,14 @@ void sbeCommandReceiver_routine(void *i_pArg) // validation failure. // - if there is a need to handle FIFO reset - // Accordingly, this will update g_sbeCmdRespHdr.prim_status - // and g_sbeCmdRespHdr.sec_status for command processor thread + // Accordingly, this will update SBE_GLOBAL->sbeCmdRespHdr.prim_status + // and SBE_GLOBAL->sbeCmdRespHdr.sec_status for command processor thread // to handle them later in the sequence. - g_sbeFifoCmdHdr.cmdClass = SBE_CMD_CLASS_UNKNOWN; - g_sbeCmdRespHdr.init(); - uint32_t len = sizeof(g_sbeFifoCmdHdr)/sizeof(uint32_t); - l_rc = sbeUpFifoDeq_mult ( len, (uint32_t *)&g_sbeFifoCmdHdr, + SBE_GLOBAL->sbeFifoCmdHdr.cmdClass = SBE_CMD_CLASS_UNKNOWN; + SBE_GLOBAL->sbeCmdRespHdr.init(); + uint32_t len = sizeof(SBE_GLOBAL->sbeFifoCmdHdr)/sizeof(uint32_t); + l_rc = sbeUpFifoDeq_mult ( len, (uint32_t *)&SBE_GLOBAL->sbeFifoCmdHdr, false ); // If FIFO reset is requested, @@ -162,7 +157,7 @@ void sbeCommandReceiver_routine(void *i_pArg) { SBE_ERROR(SBE_FUNC"sbeUpFifoDeq_mult failure, " " l_rc=[0x%08X]", l_rc); - g_sbeCmdRespHdr.setStatus(SBE_PRI_INVALID_DATA, l_rc); + SBE_GLOBAL->sbeCmdRespHdr.setStatus(SBE_PRI_INVALID_DATA, l_rc); // Reassign l_rc to Success to Unblock command processor // thread and let that take the necessary action. @@ -170,8 +165,8 @@ void sbeCommandReceiver_routine(void *i_pArg) break; } - l_cmdClass = g_sbeFifoCmdHdr.cmdClass; - l_command = g_sbeFifoCmdHdr.command; + l_cmdClass = SBE_GLOBAL->sbeFifoCmdHdr.cmdClass; + l_command = SBE_GLOBAL->sbeFifoCmdHdr.command; } // end else if loop for FIFO interface chipOp handling // Any other FIFO access issue @@ -189,11 +184,11 @@ void sbeCommandReceiver_routine(void *i_pArg) SBE_ERROR(SBE_FUNC"Command validation failed"); if ( SBE_INTERFACE_PSU == curInterface ) { - g_sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INVALID_COMMAND,l_rc); + SBE_GLOBAL->sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INVALID_COMMAND,l_rc); } else if ( SBE_INTERFACE_FIFO == curInterface ) { - g_sbeCmdRespHdr.setStatus(SBE_PRI_INVALID_COMMAND, l_rc); + SBE_GLOBAL->sbeCmdRespHdr.setStatus(SBE_PRI_INVALID_COMMAND, l_rc); } // Reassign l_rc to Success to Unblock command processor @@ -214,12 +209,12 @@ void sbeCommandReceiver_routine(void *i_pArg) if ( SBE_INTERFACE_PSU == curInterface ) { - g_sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INVALID_COMMAND, + SBE_GLOBAL->sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INVALID_COMMAND, SBE_SEC_COMMAND_NOT_ALLOWED_IN_THIS_STATE); } else if ( SBE_INTERFACE_FIFO == curInterface ) { - g_sbeCmdRespHdr.setStatus(SBE_PRI_INVALID_COMMAND, + SBE_GLOBAL->sbeCmdRespHdr.setStatus(SBE_PRI_INVALID_COMMAND, SBE_SEC_COMMAND_NOT_ALLOWED_IN_THIS_STATE); } @@ -229,7 +224,7 @@ void sbeCommandReceiver_routine(void *i_pArg) } while (false); // Inner do..while ends - g_sbeIntrSource.setIntrSource(SBE_RX_ROUTINE, curInterface ); + SBE_GLOBAL->sbeIntrSource.setIntrSource(SBE_RX_ROUTINE, curInterface ); // If there was a FIFO reset request, if (l_rc == SBE_FIFO_RESET_RECEIVED) { @@ -243,16 +238,16 @@ void sbeCommandReceiver_routine(void *i_pArg) // Collect FFDC? } - if ( g_sbeIntrSource.isSet(SBE_RX_ROUTINE, SBE_INTERFACE_FIFO) ) + if ( SBE_GLOBAL->sbeIntrSource.isSet(SBE_RX_ROUTINE, SBE_INTERFACE_FIFO) ) { - g_sbeIntrSource.clearIntrSource(SBE_ALL_HANDLER, + SBE_GLOBAL->sbeIntrSource.clearIntrSource(SBE_ALL_HANDLER, SBE_INTERFACE_FIFO); } - if ( g_sbeIntrSource.isSet(SBE_INTERRUPT_ROUTINE, + if ( SBE_GLOBAL->sbeIntrSource.isSet(SBE_INTERRUPT_ROUTINE, SBE_INTERFACE_FIFO_RESET) ) { - g_sbeIntrSource.clearIntrSource(SBE_ALL_HANDLER, + SBE_GLOBAL->sbeIntrSource.clearIntrSource(SBE_ALL_HANDLER, SBE_INTERFACE_FIFO_RESET); } @@ -265,7 +260,7 @@ void sbeCommandReceiver_routine(void *i_pArg) // if we could dequeue the header successfully, if ((l_rcPk == PK_OK) && (l_rc == SBE_SEC_OPERATION_SUCCESSFUL)) { - l_rcPk = pk_semaphore_post(&g_sbeSemCmdProcess); + l_rcPk = pk_semaphore_post(&SBE_GLOBAL->sbeSemCmdProcess); } // Handle Cmd not in a valid state here @@ -280,29 +275,29 @@ void sbeCommandReceiver_routine(void *i_pArg) // Add Error trace, collect FFDC and // continue wait for the next interrupt SBE_ERROR(SBE_FUNC"Unexpected failure, " - "l_rcPk=[%d], g_sbeSemCmdProcess.count=[%d], l_rc=[%d]", - l_rcPk, g_sbeSemCmdProcess.count, l_rc); + "l_rcPk=[%d], SBE_GLOBAL->sbeSemCmdProcess.count=[%d], l_rc=[%d]", + l_rcPk, SBE_GLOBAL->sbeSemCmdProcess.count, l_rc); pk_halt(); } if ( SBE_INTERFACE_PSU == curInterface ) { sbeHandlePsuResponse(l_rc); - g_sbeIntrSource.clearIntrSource(SBE_ALL_HANDLER, + SBE_GLOBAL->sbeIntrSource.clearIntrSource(SBE_ALL_HANDLER, SBE_INTERFACE_PSU); pk_irq_enable(SBE_IRQ_HOST_PSU_INTR); } else if ( SBE_INTERFACE_FIFO == curInterface ) { sbeHandleFifoResponse(l_rc); - g_sbeIntrSource.clearIntrSource(SBE_ALL_HANDLER, + SBE_GLOBAL->sbeIntrSource.clearIntrSource(SBE_ALL_HANDLER, SBE_INTERFACE_FIFO); pk_irq_enable(SBE_IRQ_SBEFIFO_DATA); } continue; } - SBE_DEBUG(SBE_FUNC"Posted g_sbeSemCmdProcess, " - "g_sbeSemCmdProcess.count=[%d]", g_sbeSemCmdProcess.count); + SBE_DEBUG(SBE_FUNC"Posted SBE_GLOBAL->sbeSemCmdProcess, " + "SBE_GLOBAL->sbeSemCmdProcess.count=[%d]", SBE_GLOBAL->sbeSemCmdProcess.count); } while (true); // thread always exists #undef SBE_FUNC diff --git a/src/sbefw/sbecmdringaccess.C b/src/sbefw/sbecmdringaccess.C index 071647cb..985de100 100644 --- a/src/sbefw/sbecmdringaccess.C +++ b/src/sbefw/sbecmdringaccess.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER sbe Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2016 */ +/* Contributors Listed Below - COPYRIGHT 2016,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -40,6 +40,7 @@ #include "sbefapiutil.H" #include "fapi2.H" #include "plat_hw_access.H" +#include "sbeglobals.H" using namespace fapi2; @@ -77,7 +78,7 @@ uint32_t sbePutRingFromImagePSU (uint8_t *i_pArg) { SBE_ERROR(SBE_FUNC "Invalid target type [0x%04x]", (uint16_t)l_cmd.TargetType); - g_sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INVALID_DATA, + SBE_GLOBAL->sbeSbe2PsuRespHdr.setStatus(SBE_PRI_INVALID_DATA, SBE_SEC_INVALID_TARGET_TYPE_PASSED); break; } @@ -102,7 +103,7 @@ uint32_t sbePutRingFromImagePSU (uint8_t *i_pArg) }while(0); // End of do-while // Send the response - sbePSUSendResponse(g_sbeSbe2PsuRespHdr, l_fapiRc, l_rc); + sbePSUSendResponse(SBE_GLOBAL->sbeSbe2PsuRespHdr, l_fapiRc, l_rc); SBE_EXIT(SBE_FUNC); return l_rc; @@ -260,8 +261,8 @@ uint32_t sbePutRing(uint8_t *i_pArg) { // Get the length of payload // Length is not part of chipop. So take length from total length - len = g_sbeFifoCmdHdr.len - - sizeof(g_sbeFifoCmdHdr)/sizeof(uint32_t); + len = SBE_GLOBAL->sbeFifoCmdHdr.len - + sizeof(SBE_GLOBAL->sbeFifoCmdHdr)/sizeof(uint32_t); uint32_t rs4FifoEntries = len - sizeof(sbePutRingMsgHdr_t)/sizeof(uint32_t); diff --git a/src/sbefw/sbecmdscomaccess.C b/src/sbefw/sbecmdscomaccess.C index 286dcc9a..c74ed133 100644 --- a/src/sbefw/sbecmdscomaccess.C +++ b/src/sbefw/sbecmdscomaccess.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER sbe Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2015,2016 */ +/* Contributors Listed Below - COPYRIGHT 2015,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -37,6 +37,7 @@ #include "sbeutil.H" #include "sbeFifoMsgUtils.H" #include "plat_hw_access.H" +#include "sbeglobals.H" ////////////////////////////////////////////////////// @@ -51,8 +52,8 @@ uint32_t sbeGetScom (uint8_t *i_pArg) do { - uint16_t l_primStatus = g_sbeCmdRespHdr.prim_status; - uint16_t l_secStatus = g_sbeCmdRespHdr.sec_status ; + uint16_t l_primStatus = SBE_GLOBAL->sbeCmdRespHdr.prim_status; + uint16_t l_secStatus = SBE_GLOBAL->sbeCmdRespHdr.sec_status ; // Will attempt to dequeue two entries for // the scom addresses plus the expected @@ -141,8 +142,8 @@ uint32_t sbePutScom (uint8_t *i_pArg) do { - uint16_t l_primStatus = g_sbeCmdRespHdr.prim_status; - uint16_t l_secStatus = g_sbeCmdRespHdr.sec_status ; + uint16_t l_primStatus = SBE_GLOBAL->sbeCmdRespHdr.prim_status; + uint16_t l_secStatus = SBE_GLOBAL->sbeCmdRespHdr.sec_status ; // Will attempt to dequeue four entries for // the scom address (two entries) and the @@ -226,8 +227,8 @@ uint32_t sbeModifyScom (uint8_t *i_pArg) do { - uint16_t l_primStatus = g_sbeCmdRespHdr.prim_status; - uint16_t l_secStatus = g_sbeCmdRespHdr.sec_status ; + uint16_t l_primStatus = SBE_GLOBAL->sbeCmdRespHdr.prim_status; + uint16_t l_secStatus = SBE_GLOBAL->sbeCmdRespHdr.sec_status ; // Will attempt to dequeue the following entries: // Entry 1 : Operation Mode @@ -357,8 +358,8 @@ uint32_t sbePutScomUnderMask (uint8_t *i_pArg) do { - uint16_t l_primStatus = g_sbeCmdRespHdr.prim_status; - uint16_t l_secStatus = g_sbeCmdRespHdr.sec_status ; + uint16_t l_primStatus = SBE_GLOBAL->sbeCmdRespHdr.prim_status; + uint16_t l_secStatus = SBE_GLOBAL->sbeCmdRespHdr.sec_status ; // Will attempt to dequeue the following entries: // Entry 1 : Scom Register Address (0..31) diff --git a/src/sbefw/sbeexeintf.H b/src/sbefw/sbeexeintf.H index ddfba8b1..22bd7745 100644 --- a/src/sbefw/sbeexeintf.H +++ b/src/sbefw/sbeexeintf.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER sbe Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2015,2016 */ +/* Contributors Listed Below - COPYRIGHT 2015,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -82,25 +82,6 @@ enum sbeThreadStackSize SBE_THREAD_SYNC_CMD_PROC_STACK_SIZE = 2048, }; -/** - * @brief Global semaphore : g_sbeSemCmdRecv - * - * This is used to synchronize between the ISR and - * the command receiver thread. - * - */ -extern PkSemaphore g_sbeSemCmdRecv; - -/** - * @brief Global semaphore : g_sbeSemCmdProcess - * - * This is used to synchronize between command receiver thread - * and synchronous command processor thread. - * - */ -extern PkSemaphore g_sbeSemCmdProcess; - - /** * @brief SBE Interface source * @@ -178,8 +159,6 @@ typedef struct return l_ret; } } sbeIntrHandle_t; -extern sbeIntrHandle_t g_sbeIntrSource ; - /** * @TODO via RTC : 128658 diff --git a/src/sbefw/sbefwfiles.mk b/src/sbefw/sbefwfiles.mk index 43b680ad..7c64f036 100644 --- a/src/sbefw/sbefwfiles.mk +++ b/src/sbefw/sbefwfiles.mk @@ -49,6 +49,9 @@ SBEFW-CPP-SOURCES += sbecmdtracearray.C SBEFW-CPP-SOURCES += sbeTimerSvc.C SBEFW-CPP-SOURCES += sbecmdCntrlTimer.C SBEFW-CPP-SOURCES += sbecmdfastarray.C +SBEFW-CPP-SOURCES += sbeHostMsg.C +SBEFW-CPP-SOURCES += sbeSpMsg.C +SBEFW-CPP-SOURCES += sbeglobals.C SBEFW-C-SOURCES = SBEFW-S-SOURCES = diff --git a/src/sbefw/sbeglobals.C b/src/sbefw/sbeglobals.C new file mode 100644 index 00000000..74257635 --- /dev/null +++ b/src/sbefw/sbeglobals.C @@ -0,0 +1,33 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/sbefw/sbeglobals.C $ */ +/* */ +/* OpenPOWER sbe 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 "sbetrace.H" +#include "sbeglobals.H" + +SBEGlobalsSingleton* sbeGlobal = &SBEGlobalsSingleton::getInstance(); +SBEGlobalsSingleton& SBEGlobalsSingleton::getInstance() +{ + static SBEGlobalsSingleton iv_instance; + return iv_instance; +} diff --git a/src/sbefw/sbeglobals.H b/src/sbefw/sbeglobals.H new file mode 100644 index 00000000..26f89391 --- /dev/null +++ b/src/sbefw/sbeglobals.H @@ -0,0 +1,112 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/sbefw/sbeglobals.H $ */ +/* */ +/* OpenPOWER sbe 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 __SBE_GLOBALS_H +#define __SBE_GLOBALS_H + +#include "sbeutil.H" +#include "sbeSpMsg.H" +#include "sbeHostMsg.H" +#include "sbestates.H" +#include "sbeexeintf.H" + +#define SBE_GLOBAL sbeGlobal + +class SBEGlobalsSingleton +{ + public: + // Disable copy contructor and assingment operator + SBEGlobalsSingleton(const SBEGlobalsSingleton&) = delete; + SBEGlobalsSingleton& operator=(const SBEGlobalsSingleton&) = delete; + static SBEGlobalsSingleton& getInstance(); + + sbeFifoCmdReqBuf_t sbeFifoCmdHdr; + sbeCmdRespHdr_t sbeCmdRespHdr; + sbePsu2SbeCmdReqHdr_t sbePsu2SbeCmdReqHdr; + sbeSbe2PsuRespHdr_t sbeSbe2PsuRespHdr; + sbeIntrHandle_t sbeIntrSource; + //////////////////////////////////////////////////////////////// + //// @brief Global semaphores + ///////////////////////////////////////////////////////////////// + /** + * @brief Global semaphore : SBE_GLOBAL->sbeSemCmdRecv + * + * This is used to synchronize between the ISR and + * the command receiver thread. + * + */ + PkSemaphore sbeSemCmdRecv; + /** + * @brief Global semaphore : SBE_GLOBAL->sbeSemCmdProcess + * + * This is used to synchronize between command receiver thread + * and synchronous command processor thread. + * + */ + PkSemaphore sbeSemCmdProcess; + sbeRole SBERole; + // SBE Frequency. Initially nest frequency is 133 MHZ + uint32_t sbefreq; + + //////////////////////////////////////////////////////////////// + //// @brief Stacks for Non-critical Interrupts and Threads + ////////////////////////////////////////////////////////////////// + uint8_t sbe_Kernel_NCInt_stack[SBE_NONCRITICAL_STACK_SIZE]; + uint8_t sbeCommandReceiver_stack[SBE_THREAD_CMD_RECV_STACK_SIZE]; + uint8_t sbeSyncCommandProcessor_stack[SBE_THREAD_SYNC_CMD_PROC_STACK_SIZE]; + uint8_t sbeAsyncCommandProcessor_stack[SBE_THREAD_ASYNC_CMD_PROC_STACK_SIZE]; + + //////////////////////////////////////////////////////////////// + //// @brief PkThread structure for SBE Command Receiver thread + ////////////////////////////////////////////////////////////////// + PkThread sbeCommandReceiver_thread; + //////////////////////////////////////////////////////////////// + //// @brief PkThread structure for SBE Synchronous ChipOps + //// processing thread + ////////////////////////////////////////////////////////////////// + PkThread sbeSyncCommandProcessor_thread; + //////////////////////////////////////////////////////////////// + ////// @brief PkThread structure for SBE Asynchronous ChipOps + ////// processing thread + ////////////////////////////////////////////////////////////////// + PkThread sbeAsyncCommandProcessor_thread; + private: + /* Constructor + */ + SBEGlobalsSingleton(): + sbeFifoCmdHdr(), + sbeCmdRespHdr(), + sbePsu2SbeCmdReqHdr(), + sbeSbe2PsuRespHdr(), + sbeIntrSource(), + sbeSemCmdRecv(), + sbeSemCmdProcess(), + SBERole(SBE_ROLE_MASTER), + sbefreq(( 133 * 1000 * 1000)/SBE::SBE_TO_NEST_FREQ_FACTOR) + { + } +}; +extern SBEGlobalsSingleton* sbeGlobal; +#endif //__SBE_GLOBALS_H + diff --git a/src/sbefw/sbeirq.C b/src/sbefw/sbeirq.C index 3c0a2ef0..b5c2328b 100644 --- a/src/sbefw/sbeirq.C +++ b/src/sbefw/sbeirq.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER sbe Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2015,2016 */ +/* Contributors Listed Below - COPYRIGHT 2015,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -33,8 +33,7 @@ #include "sbeirq.H" #include "sbetrace.H" #include "assert.h" - -extern sbeIntrHandle_t g_sbeIntrSource ; +#include "sbeglobals.H" //////////////////////////////////////////////////////////////// // @brief: SBE control loop ISR: @@ -56,18 +55,18 @@ void sbe_interrupt_handler (void *i_pArg, PkIrqId i_irq) switch (i_irq) { case SBE_IRQ_HOST_PSU_INTR: - g_sbeIntrSource.setIntrSource(SBE_INTERRUPT_ROUTINE, + SBE_GLOBAL->sbeIntrSource.setIntrSource(SBE_INTERRUPT_ROUTINE, SBE_INTERFACE_PSU); break; case SBE_IRQ_SBEFIFO_DATA: - g_sbeIntrSource.setIntrSource(SBE_INTERRUPT_ROUTINE, + SBE_GLOBAL->sbeIntrSource.setIntrSource(SBE_INTERRUPT_ROUTINE, SBE_INTERFACE_FIFO); pk_irq_disable(SBE_IRQ_SBEFIFO_RESET); break; case SBE_IRQ_SBEFIFO_RESET: - g_sbeIntrSource.setIntrSource(SBE_INTERRUPT_ROUTINE, + SBE_GLOBAL->sbeIntrSource.setIntrSource(SBE_INTERRUPT_ROUTINE, SBE_INTERFACE_FIFO_RESET); pk_irq_disable(SBE_IRQ_SBEFIFO_DATA); break; @@ -81,7 +80,7 @@ void sbe_interrupt_handler (void *i_pArg, PkIrqId i_irq) pk_irq_disable(i_irq); // Unblock the command receiver thread - l_rc = pk_semaphore_post(&g_sbeSemCmdRecv); + l_rc = pk_semaphore_post(&SBE_GLOBAL->sbeSemCmdRecv); if (l_rc) { // If we received an error while posting the semaphore, diff --git a/src/sbefw/sbemain.C b/src/sbefw/sbemain.C index 101da9c4..663705b8 100644 --- a/src/sbefw/sbemain.C +++ b/src/sbefw/sbemain.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER sbe Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2015,2016 */ +/* Contributors Listed Below - COPYRIGHT 2015,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -43,42 +43,11 @@ #include "sbestates.H" #include "fapi2.H" // For target init #include "sbeutil.H" // For getting SBE_TO_NEST_FREQ_FACTOR - -//////////////////////////////////////////////////////////////// -// @brief Global semaphores -//////////////////////////////////////////////////////////////// -PkSemaphore g_sbeSemCmdRecv; -PkSemaphore g_sbeSemCmdProcess; +#include "sbeglobals.H" // Max defines for Semaphores static uint32_t MAX_SEMAPHORE_COUNT = 3; -//////////////////////////////////////////////////////////////// -// @brief Stacks for Non-critical Interrupts and Threads -//////////////////////////////////////////////////////////////// -uint8_t g_sbe_Kernel_NCInt_stack[SBE_NONCRITICAL_STACK_SIZE]; -uint8_t g_sbeCommandReceiver_stack[SBE_THREAD_CMD_RECV_STACK_SIZE]; -uint8_t g_sbeSyncCommandProcessor_stack[SBE_THREAD_SYNC_CMD_PROC_STACK_SIZE]; -uint8_t g_sbeAsyncCommandProcessor_stack[SBE_THREAD_ASYNC_CMD_PROC_STACK_SIZE]; - -//////////////////////////////////////////////////////////////// -// @brief PkThread structure for SBE Command Receiver thread -//////////////////////////////////////////////////////////////// -PkThread g_sbeCommandReceiver_thread; - -//////////////////////////////////////////////////////////////// -// @brief PkThread structure for SBE Synchronous ChipOps -// processing thread -//////////////////////////////////////////////////////////////// -PkThread g_sbeSyncCommandProcessor_thread; - -//////////////////////////////////////////////////////////////// -//// @brief PkThread structure for SBE Asynchronous ChipOps -//// processing thread -//////////////////////////////////////////////////////////////// -PkThread g_sbeAsyncCommandProcessor_thread; -// SBE Frequency. Initially nest frequency is 133 MHZ -uint32_t g_sbefreq = ( 133 * 1000 * 1000)/SBE::SBE_TO_NEST_FREQ_FACTOR; extern "C" { // These variables are declared in linker script to keep track of @@ -131,12 +100,12 @@ uint32_t sbeInitSems(void) do { - l_rc = pk_semaphore_create(&g_sbeSemCmdRecv, 0, MAX_SEMAPHORE_COUNT); + l_rc = pk_semaphore_create(&SBE_GLOBAL->sbeSemCmdRecv, 0, MAX_SEMAPHORE_COUNT); if (l_rc) { break; } - l_rc = pk_semaphore_create(&g_sbeSemCmdProcess, 0, MAX_SEMAPHORE_COUNT); + l_rc = pk_semaphore_create(&SBE_GLOBAL->sbeSemCmdProcess, 0, MAX_SEMAPHORE_COUNT); if (l_rc) { break; @@ -222,10 +191,10 @@ int sbeInitThreads(void) do { // Initialize Command receiver thread - l_rc = createAndResumeThreadHelper(&g_sbeCommandReceiver_thread, + l_rc = createAndResumeThreadHelper(&SBE_GLOBAL->sbeCommandReceiver_thread, sbeCommandReceiver_routine, (void *)0, - (PkAddress)g_sbeCommandReceiver_stack, + (PkAddress)SBE_GLOBAL->sbeCommandReceiver_stack, SBE_THREAD_CMD_RECV_STACK_SIZE, THREAD_PRIORITY_5); if (l_rc) @@ -234,10 +203,10 @@ int sbeInitThreads(void) } // Initialize Synchronous Command Processor thread - l_rc = createAndResumeThreadHelper(&g_sbeSyncCommandProcessor_thread, + l_rc = createAndResumeThreadHelper(&SBE_GLOBAL->sbeSyncCommandProcessor_thread, sbeSyncCommandProcessor_routine, (void *)0, - (PkAddress)g_sbeSyncCommandProcessor_stack, + (PkAddress)SBE_GLOBAL->sbeSyncCommandProcessor_stack, SBE_THREAD_SYNC_CMD_PROC_STACK_SIZE, THREAD_PRIORITY_7); if (l_rc) @@ -246,10 +215,10 @@ int sbeInitThreads(void) } // Initialize Asynchronous Command Processor thread - l_rc = createAndResumeThreadHelper(&g_sbeAsyncCommandProcessor_thread, + l_rc = createAndResumeThreadHelper(&SBE_GLOBAL->sbeAsyncCommandProcessor_thread, sbeAsyncCommandProcessor_routine, (void *)0, - (PkAddress)g_sbeAsyncCommandProcessor_stack, + (PkAddress)SBE_GLOBAL->sbeAsyncCommandProcessor_stack, SBE_THREAD_ASYNC_CMD_PROC_STACK_SIZE, THREAD_PRIORITY_6); if (l_rc) @@ -284,10 +253,10 @@ uint32_t main(int argc, char **argv) { // initializes kernel data - // stack, threads, timebase, timers, etc. - l_rc = pk_initialize((PkAddress)g_sbe_Kernel_NCInt_stack, + l_rc = pk_initialize((PkAddress)SBE_GLOBAL->sbe_Kernel_NCInt_stack, SBE_NONCRITICAL_STACK_SIZE, 0, - g_sbefreq ); + SBE_GLOBAL->sbefreq ); if (l_rc) { break; diff --git a/src/sbefw/sbestates.H b/src/sbefw/sbestates.H index 204b73af..419456aa 100644 --- a/src/sbefw/sbestates.H +++ b/src/sbefw/sbestates.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER sbe Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2016 */ +/* Contributors Listed Below - COPYRIGHT 2016,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -60,7 +60,5 @@ enum sbeRole SBE_ROLE_SLAVE = 1 }; -extern sbeRole g_sbeRole; - #endif //__SBEFW_SBESTATES_H diff --git a/src/sbefw/sbeutil.C b/src/sbefw/sbeutil.C index 8ad99bca..7b854ca0 100644 --- a/src/sbefw/sbeutil.C +++ b/src/sbefw/sbeutil.C @@ -25,6 +25,7 @@ #include "sbeutil.H" #include "fapi2.H" #include "sbetrace.H" +#include "sbeglobals.H" // Nest frequency array #include "p9_frequency_buckets.H" namespace SBE @@ -51,10 +52,10 @@ namespace SBE uint8_t nestPllBkt = 0; FAPI_ATTR_GET( ATTR_NEST_PLL_BUCKET, sys, nestPllBkt ); assert( nestPllBkt && (nestPllBkt <= NEST_PLL_FREQ_BUCKETS )); - g_sbefreq = ( NEST_PLL_FREQ_LIST[ nestPllBkt - 1 ] * 1000 * 1000 )/ + SBE_GLOBAL->sbefreq = ( NEST_PLL_FREQ_LIST[ nestPllBkt - 1 ] * 1000 * 1000 )/ SBE::SBE_TO_NEST_FREQ_FACTOR; - SBE_INFO(SBE_FUNC"Setting new frequency:0x%08X", g_sbefreq); - pk_timebase_freq_set(g_sbefreq); + SBE_INFO(SBE_FUNC"Setting new frequency:0x%08X", SBE_GLOBAL->sbefreq); + pk_timebase_freq_set(SBE_GLOBAL->sbefreq); } } diff --git a/src/sbefw/sbeutil.H b/src/sbefw/sbeutil.H index 76793927..58614fb3 100644 --- a/src/sbefw/sbeutil.H +++ b/src/sbefw/sbeutil.H @@ -128,7 +128,6 @@ inline void SBE_MAGIC_INSTRUCTION(int _n) void sbeHandleFifoResponse (const uint32_t i_rc); void sbeHandlePsuResponse (const uint32_t i_rc); -extern uint32_t g_sbefreq; namespace SBE { -- cgit v1.2.1