From 183d1d89e624456cd831ca5dceb6c03edf07035c Mon Sep 17 00:00:00 2001 From: Dean Sanner Date: Tue, 28 Jun 2016 09:56:14 -0500 Subject: Utility functions for mbox scratch reg access Change-Id: If262e891934b5228ea1fa9081a0c85a40a52036d RTC:127348 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/26346 Tested-by: Jenkins Server Reviewed-by: Prachi Gupta Tested-by: FSP CI Jenkins Reviewed-by: Corey V. Swenson Reviewed-by: William G. Hoffa --- src/usr/util/makefile | 3 +- src/usr/util/utilmbox_scratch.C | 119 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src/usr/util/utilmbox_scratch.C (limited to 'src/usr/util') diff --git a/src/usr/util/makefile b/src/usr/util/makefile index 7a5aa7651..70df3b790 100644 --- a/src/usr/util/makefile +++ b/src/usr/util/makefile @@ -5,7 +5,7 @@ # # OpenPOWER HostBoot Project # -# Contributors Listed Below - COPYRIGHT 2012,2015 +# Contributors Listed Below - COPYRIGHT 2012,2016 # [+] International Business Machines Corp. # # @@ -32,6 +32,7 @@ OBJS += utilmem.o OBJS += utilfile.o OBJS += utillidmgr.o OBJS += utillidpnor.o +OBJS += utilmbox_scratch.o SUBDIRS += test.d SUBDIRS += runtime.d diff --git a/src/usr/util/utilmbox_scratch.C b/src/usr/util/utilmbox_scratch.C new file mode 100644 index 000000000..9a38b8dff --- /dev/null +++ b/src/usr/util/utilmbox_scratch.C @@ -0,0 +1,119 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/util/utilmbox_scratch.C $ */ +/* */ +/* OpenPOWER HostBoot Project */ +/* */ +/* Contributors Listed Below - COPYRIGHT 2016 */ +/* [+] 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 */ +/** + * @file utilmem.C + * + * @brief Stream manipulation + * + * Used for creating and manipulating streams + */ + +/*****************************************************************************/ +// I n c l u d e s +/*****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +#include "utilbase.H" + +using namespace ERRORLOG; + +namespace Util +{ + + // ---------------------------------------------- + // Globals + // ---------------------------------------------- + mutex_t g_mutex = MUTEX_INITIALIZER; + + + uint64_t readScratchReg(uint64_t i_addr) + { + size_t l_size = sizeof(uint64_t); + uint64_t value = 0; + + errlHndl_t l_errl = + deviceRead(TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL, + &value, l_size, + DEVICE_SCOM_ADDRESS(i_addr)); + + if (l_errl) + { + errlCommit(l_errl, UTIL_COMP_ID); + } + + return value; + } + + void writeScratchReg(uint64_t i_addr, uint64_t i_data) + { + size_t l_size = sizeof(uint64_t); + + errlHndl_t l_errl = + deviceWrite(TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL, + &i_data, l_size, + DEVICE_SCOM_ADDRESS(i_addr)); + + if (l_errl) + { + errlCommit(l_errl, UTIL_COMP_ID); + } + } + + void writeDebugCommRegs(uint8_t i_usage, uint32_t i_addr, uint32_t i_size) + { + //convert input into uint64_t for scom write + uint64_t l_bufAddr = i_addr; + uint64_t l_bufSize = (i_size & MSG_DATA_SIZE_MASK) | + (i_usage << MSG_USAGE_SHIFT); + + l_bufAddr <<=32; + l_bufSize <<=32; + + //Lock to prevent concurrent access + mutex_lock(&g_mutex); + + + //Write out the data to be xferred to debug tool + writeScratchReg(INITSERVICE::SPLESS::MBOX_SCRATCH_REG1, l_bufAddr); + writeScratchReg(INITSERVICE::SPLESS::MBOX_SCRATCH_REG2, l_bufSize); + + //wait paitently until tool has gotten the data + //tool will zero addr when ready to continue + while(0 != readScratchReg(INITSERVICE::SPLESS::MBOX_SCRATCH_REG1)) + { + task_yield(); + } + + //Release lock + mutex_unlock(&g_mutex); + } + +}; -- cgit v1.2.1