<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hdat/hdatspsubsys.C $                                 */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,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                                                     */

/**
 * @file hdatspsubsys.C
 *
 * @brief This file contains the implementation of the HdatSpSubsys class.
 *
 */


/*---------------------------------------------------------------------------*/
/* Includes                                                                  */
/*---------------------------------------------------------------------------*/
#include <stdlib.h>
#include <sys/mm.h>
#include <sys/mmio.h>
#include <pnor/pnorif.H>
#include <lpc/lpc_const.H>
#include <console/uartif.H>
#include <ipmi/ipmiif.H>
#include <util/align.H>
#include "hdatspsubsys.H"
#include "hdathdif.H"
#include "hdatutil.H"
#include "hdatvpd.H"
#include <targeting/common/util.H>

using namespace TARGETING;

namespace HDAT
{

/*----------------------------------------------------------------------------*/
/* Global variables                                                           */
/*----------------------------------------------------------------------------*/
uint32_t HdatSpSubsys::cv_actualCnt;


vpdData mvpdDataTable[] =
{
    { MVPD::VINI, MVPD::RT },
    { MVPD::VINI, MVPD::DR },
    { MVPD::VINI, MVPD::VZ },
    { MVPD::VINI, MVPD::CC },
    { MVPD::VINI, MVPD::CE },
    { MVPD::VINI, MVPD::FN },
    { MVPD::VINI, MVPD::PN },
    { MVPD::VINI, MVPD::SN },
    { MVPD::VINI, MVPD::PR },
    { MVPD::VINI, MVPD::HE },
    { MVPD::VINI, MVPD::CT },
    { MVPD::VINI, MVPD::HW },
};

const HdatKeywordInfo l_mvpdKeywords[] =
{
    { MVPD::RT, "RT" },
    { MVPD::DR, "DR" },
    { MVPD::VZ, "VZ" },
    { MVPD::CC, "CC" },
    { MVPD::CE, "CE" },
    { MVPD::FN, "FN" },
    { MVPD::PN, "PN" },
    { MVPD::SN, "SN" },
    { MVPD::PR, "PR" },
    { MVPD::HE, "HE" },
    { MVPD::CT, "CT" },
    { MVPD::HW, "HW" },

};

extern trace_desc_t *g_trac_hdat;

/**
 * @brief This routine fill up the SP I/O path information.          
 *
 * @pre The o_pathArray must be set to zero.
 *
 * @post None
 *
 * @param l_pSpTarget  - input parameter - Target handle of the SP
 * @param o_arrayHdr   - output parameter - The I/O path array header structure
 * @param o_pathArray  - output parameter - The structure to update with the SP
 *                       I/O path information
 * @return A null error log handle if successful, else the return code pointed
 *         to by errlHndl_t contains one of:
 *
 * @retval
 */
static errlHndl_t hdatGetPathInfo(
                                  uint32_t &io_numOfIoPaths,
                                  hdatHDIFDataArray_t &o_arrayHdr,
                                  hdatSpIoPath_t o_pathArray[])
{

    HDAT_ENTER();

    errlHndl_t  l_errlHndl = NULL;

    // Set the number of Io Paths.
    // For now, we have only 1, may change in future
    io_numOfIoPaths = HDAT_NUM_IO_PATHS_FOR_BMC;

    // Set fields in the array header
    o_arrayHdr.hdatOffset    = sizeof(hdatHDIFDataArray_t);
    o_arrayHdr.hdatAllocSize = sizeof(hdatSpIoPath_t);
    o_arrayHdr.hdatActSize   = sizeof(hdatSpIoPath_t);
    o_arrayHdr.hdatArrayCnt  = 0;

    for( ; o_arrayHdr.hdatArrayCnt < io_numOfIoPaths ; )
    {
        o_pathArray[o_arrayHdr.hdatArrayCnt].
                                hdatPathType = HDAT_LPC_PATH_TYPE;
        o_pathArray[o_arrayHdr.hdatArrayCnt].
                                hdatLinkStatus = HDAT_CURRENT_LINK;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatML2ChipVer  = 0x10;

        // Get the master proc handle.

        TARGETING::Target* l_pMasterProcChipTargetHandle = NULL;
        (void)TARGETING::targetService().masterProcChipTargetHandle(
                                    l_pMasterProcChipTargetHandle);

        if (l_pMasterProcChipTargetHandle == NULL)
        {
            /*@
            * @errortype
            * @moduleid         HDAT::MOD_GET_PATH_INFO
            * @reasoncode       HDAT::RC_MASTER_PROC_TARGET_NULL
            * @devdesc          Master proc target returned is Null
            * @custdesc         Firmware encountered an internal
            *                   error while retrieving target handle
            */
            hdatBldErrLog(l_errlHndl,
                          MOD_GET_PATH_INFO,
                          RC_MASTER_PROC_TARGET_NULL,
                          0,0,0,0);

            HDAT_ERR("Master proc target handle is Null");
        }
        else
        {

            o_pathArray[o_arrayHdr.hdatArrayCnt].hdatProcChipId =
                l_pMasterProcChipTargetHandle->getAttr<ATTR_ORDINAL_ID>();

        }

        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatLPCHCBarIOAdrSpc =
                                                            LPC::LPCHC_IO_SPACE;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatLPCHCBarMemAdrSpc =
                                                            LPC::LPCHC_MEM_SPACE;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatLPCHCBarFwAdrSpc =
                                                         LPC::LPCHC_FW_SPACE;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatLPCHCBarIntRegSpc =
                                                         LPC::LPCHC_REG_SPACE;
#ifdef CONFIG_CONSOLE
        CONSOLE::UartInfo_t l_uartInfo = CONSOLE::getUartInfo();
    
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatBarOfUARTDev = 
                                                    l_uartInfo.lpcBaseAddr;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatSizeofUARTAdrSpc =
                                                    l_uartInfo.lpcSize;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatUARTFreqHz =
                                                    l_uartInfo.clockFreqHz;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatCurUARTDevBaudRate =
                                                    l_uartInfo.freqHz;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatUARTInterruptDetails.
                                hdatUARTIntrNum = l_uartInfo.interruptNum;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatUARTInterruptDetails.
                                hdatTriggerType = l_uartInfo.interruptTrigger;
#endif

#ifdef CONFIG_BMC_IPMI
        IPMI::BmcInfo_t l_bmcInfo = IPMI::getBmcInfo();
        
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatBARofBTDevAdrSpc =
                                                l_bmcInfo.bulkTransferLpcBaseAddr;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatSizeofBTDevAdrSpc =
                                                l_bmcInfo.bulkTransferSize;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatBTInterruptDetails.
                                 hdatSMSAttnIntrNum = l_bmcInfo.smsAttnInterrupt;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatBTInterruptDetails.
                                 hdatBMCtoHostRespIntrNum = l_bmcInfo.bmcToHostInterrupt;
#endif

        // LPC link doesn't have any FRU's in the path<commit_msg>Temporarily remove HDAT IPMI<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hdat/hdatspsubsys.C $                                 */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,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                                                     */

/**
 * @file hdatspsubsys.C
 *
 * @brief This file contains the implementation of the HdatSpSubsys class.
 *
 */


/*---------------------------------------------------------------------------*/
/* Includes                                                                  */
/*---------------------------------------------------------------------------*/
#include <stdlib.h>
#include <sys/mm.h>
#include <sys/mmio.h>
#include <pnor/pnorif.H>
#include <lpc/lpc_const.H>
#include <console/uartif.H>
#include <ipmi/ipmiif.H>
#include <util/align.H>
#include "hdatspsubsys.H"
#include "hdathdif.H"
#include "hdatutil.H"
#include "hdatvpd.H"
#include <targeting/common/util.H>

using namespace TARGETING;

namespace HDAT
{

/*----------------------------------------------------------------------------*/
/* Global variables                                                           */
/*----------------------------------------------------------------------------*/
uint32_t HdatSpSubsys::cv_actualCnt;


vpdData mvpdDataTable[] =
{
    { MVPD::VINI, MVPD::RT },
    { MVPD::VINI, MVPD::DR },
    { MVPD::VINI, MVPD::VZ },
    { MVPD::VINI, MVPD::CC },
    { MVPD::VINI, MVPD::CE },
    { MVPD::VINI, MVPD::FN },
    { MVPD::VINI, MVPD::PN },
    { MVPD::VINI, MVPD::SN },
    { MVPD::VINI, MVPD::PR },
    { MVPD::VINI, MVPD::HE },
    { MVPD::VINI, MVPD::CT },
    { MVPD::VINI, MVPD::HW },
};

const HdatKeywordInfo l_mvpdKeywords[] =
{
    { MVPD::RT, "RT" },
    { MVPD::DR, "DR" },
    { MVPD::VZ, "VZ" },
    { MVPD::CC, "CC" },
    { MVPD::CE, "CE" },
    { MVPD::FN, "FN" },
    { MVPD::PN, "PN" },
    { MVPD::SN, "SN" },
    { MVPD::PR, "PR" },
    { MVPD::HE, "HE" },
    { MVPD::CT, "CT" },
    { MVPD::HW, "HW" },

};

extern trace_desc_t *g_trac_hdat;

/**
 * @brief This routine fill up the SP I/O path information.          
 *
 * @pre The o_pathArray must be set to zero.
 *
 * @post None
 *
 * @param l_pSpTarget  - input parameter - Target handle of the SP
 * @param o_arrayHdr   - output parameter - The I/O path array header structure
 * @param o_pathArray  - output parameter - The structure to update with the SP
 *                       I/O path information
 * @return A null error log handle if successful, else the return code pointed
 *         to by errlHndl_t contains one of:
 *
 * @retval
 */
static errlHndl_t hdatGetPathInfo(
                                  uint32_t &io_numOfIoPaths,
                                  hdatHDIFDataArray_t &o_arrayHdr,
                                  hdatSpIoPath_t o_pathArray[])
{

    HDAT_ENTER();

    errlHndl_t  l_errlHndl = NULL;

    // Set the number of Io Paths.
    // For now, we have only 1, may change in future
    io_numOfIoPaths = HDAT_NUM_IO_PATHS_FOR_BMC;

    // Set fields in the array header
    o_arrayHdr.hdatOffset    = sizeof(hdatHDIFDataArray_t);
    o_arrayHdr.hdatAllocSize = sizeof(hdatSpIoPath_t);
    o_arrayHdr.hdatActSize   = sizeof(hdatSpIoPath_t);
    o_arrayHdr.hdatArrayCnt  = 0;

    for( ; o_arrayHdr.hdatArrayCnt < io_numOfIoPaths ; )
    {
        o_pathArray[o_arrayHdr.hdatArrayCnt].
                                hdatPathType = HDAT_LPC_PATH_TYPE;
        o_pathArray[o_arrayHdr.hdatArrayCnt].
                                hdatLinkStatus = HDAT_CURRENT_LINK;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatML2ChipVer  = 0x10;

        // Get the master proc handle.

        TARGETING::Target* l_pMasterProcChipTargetHandle = NULL;
        (void)TARGETING::targetService().masterProcChipTargetHandle(
                                    l_pMasterProcChipTargetHandle);

        if (l_pMasterProcChipTargetHandle == NULL)
        {
            /*@
            * @errortype
            * @moduleid         HDAT::MOD_GET_PATH_INFO
            * @reasoncode       HDAT::RC_MASTER_PROC_TARGET_NULL
            * @devdesc          Master proc target returned is Null
            * @custdesc         Firmware encountered an internal
            *                   error while retrieving target handle
            */
            hdatBldErrLog(l_errlHndl,
                          MOD_GET_PATH_INFO,
                          RC_MASTER_PROC_TARGET_NULL,
                          0,0,0,0);

            HDAT_ERR("Master proc target handle is Null");
        }
        else
        {

            o_pathArray[o_arrayHdr.hdatArrayCnt].hdatProcChipId =
                l_pMasterProcChipTargetHandle->getAttr<ATTR_ORDINAL_ID>();

        }

        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatLPCHCBarIOAdrSpc =
                                                            LPC::LPCHC_IO_SPACE;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatLPCHCBarMemAdrSpc =
                                                            LPC::LPCHC_MEM_SPACE;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatLPCHCBarFwAdrSpc =
                                                         LPC::LPCHC_FW_SPACE;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatLPCHCBarIntRegSpc =
                                                         LPC::LPCHC_REG_SPACE;
#ifdef CONFIG_CONSOLE
        CONSOLE::UartInfo_t l_uartInfo = CONSOLE::getUartInfo();
    
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatBarOfUARTDev = 
                                                    l_uartInfo.lpcBaseAddr;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatSizeofUARTAdrSpc =
                                                    l_uartInfo.lpcSize;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatUARTFreqHz =
                                                    l_uartInfo.clockFreqHz;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatCurUARTDevBaudRate =
                                                    l_uartInfo.freqHz;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatUARTInterruptDetails.
                                hdatUARTIntrNum = l_uartInfo.interruptNum;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatUARTInterruptDetails.
                                hdatTriggerType = l_uartInfo.interruptTrigger;
#endif

#if 0 //Temp remove until ready CONFIG_BMC_IPMI
        IPMI::BmcInfo_t l_bmcInfo = IPMI::getBmcInfo();
        
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatBARofBTDevAdrSpc =
                                                l_bmcInfo.bulkTransferLpcBaseAddr;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatSizeofBTDevAdrSpc =
                                                l_bmcInfo.bulkTransferSize;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatBTInterruptDetails.
                                 hdatSMSAttnIntrNum = l_bmcInfo.smsAttnInterrupt;
        o_pathArray[o_arrayHdr.hdatArrayCnt].hdatBTInterruptDetails.
                                 hdatBMCtoHostRespIntrNum = l_bmcInfo.bmcToHostInterrupt;
#endif

        // LPC link doesn't have any FRU's in the path
{'fraction_non_alphanumeric': 0.1223994452149792, 'fraction_numerical': 0.0030628756356911695, 'mean_word_length': 1.261204756304717, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 124, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3683784', 'n_tokens_mistral': 5031, 'n_tokens_neox': 4825, 'n_words': 877}