<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/perv/p9_mem_pll_setup.C $  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] 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  p9_mem_pll_setup.C
///
/// @brief setup PLL for MBAs
//------------------------------------------------------------------------------
// *HWP HW Owner        : <NAME> <<EMAIL>>
// *HWP HW Backup Owner : <NAME> <<EMAIL>>
// *HWP FW Owner        : <NAME> <<EMAIL>>
// *HWP Team            : Perv
// *HWP Level           : 2
// *HWP Consumed by     : HB
//------------------------------------------------------------------------------


//## auto_generated
#include "p9_mem_pll_setup.H"

#include "p9_perv_scom_addresses.H"
#include <p9_perv_scom_addresses_fld.H>

enum P9_MEM_PLL_SETUP_Private_Constants
{
    NS_DELAY = 5000000, // unit is nano seconds
    SIM_CYCLE_DELAY = 100000, // unit is sim cycles
    OPCG_ALIGN_SCAN_RATIO = 0b00011
};


fapi2::ReturnCode p9_mem_pll_setup(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& i_target_chip)
{
    uint8_t l_read_attr = 0;
    fapi2::buffer<uint64_t> l_data64;
    uint8_t l_mem_bypass;

    FAPI_INF("Entering ...");

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_NEST_MEM_X_O_PCI_BYPASS, i_target_chip, l_mem_bypass),
             "Error from FAPI_ATTR_GET (ATTR_NEST_MEM_X_O_PCI_BYPASS");

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_MC_SYNC_MODE, i_target_chip, l_read_attr),
             "Error from FAPI_ATTR_GET (ATTR_MC_SYNC_MODE)");

    if (!l_read_attr )
    {
        for (auto l_chplt_trgt :  i_target_chip.getChildren<fapi2::TARGET_TYPE_PERV>
             (fapi2::TARGET_FILTER_ALL_MC, fapi2::TARGET_STATE_FUNCTIONAL))
        {
            FAPI_DBG("Drop PLDY bypass of Progdelay logic");
            l_data64.flush<1>();
            //NET_CTRL1.TP_MC_PDLY_BYPASS_EN_DC = 0
            l_data64.clearBit<PERV_1_NET_CTRL1_CLK_PDLY_BYPASS_EN>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL1_WAND, l_data64));

            FAPI_DBG("Drop DCC bypass of DCC logic");
            l_data64.flush<1>();
            //NET_CTRL1.TP_MC_PDLY_BYPASS_EN_DC = 0
            l_data64.clearBit<PERV_1_NET_CTRL1_CLK_DCC_BYPASS_EN>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL1_WAND, l_data64));

            if (l_mem_bypass == 0)
            {
                FAPI_DBG("Drop PLL test enable");
                l_data64.flush<1>();
                //NET_CTRL0.TP_PLL_TEST_EN_DC
                l_data64.clearBit<PERV_1_NET_CTRL0_PLL_TEST_EN>();
                FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WAND, l_data64));

                FAPI_DBG("Drop PLL reset");
                l_data64.flush<1>();
                //NET_CTRL0.TP_PLLRST_DC
                l_data64.clearBit<PERV_1_NET_CTRL0_PLL_RESET>();
                FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WAND, l_data64));

                fapi2::delay(NS_DELAY, SIM_CYCLE_DELAY);

                FAPI_DBG("check PLL lock");

                //Getting PLL_LOCK_REG register value
                FAPI_TRY(fapi2::getScom(l_chplt_trgt, PERV_PLL_LOCK_REG,
                                        l_data64)); //l_read_reg = PERV.PLL_LOCK_REG
                FAPI_ASSERT(l_data64.getBit<0>() == 1,
                            fapi2::MEM_PLL_LOCK_ERR()
                            .set_MEM_PLL_READ(l_data64),
                            "ERROR:MEM PLL LOCK NOT SET");

                FAPI_DBG("Drop PLL Bypass");
                l_data64.flush<1>();
                //NET_CTRL0.TP_PLLBYP_DC =  0
                l_data64.clearBit<PERV_1_NET_CTRL0_PLL_BYPASS>();<commit_msg>p9_{mem,sbe_chiplet}_pll_setup: Level 3<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/perv/p9_mem_pll_setup.C $  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] 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  p9_mem_pll_setup.C
///
/// @brief setup PLL for MBAs
//------------------------------------------------------------------------------
// *HWP HW Owner        : <NAME> <<EMAIL>>
// *HWP HW Backup Owner : <NAME> <<EMAIL>>
// *HWP FW Owner        : <NAME> <<EMAIL>>
// *HWP Team            : Perv
// *HWP Level           : 3
// *HWP Consumed by     : HB
//------------------------------------------------------------------------------


//## auto_generated
#include "p9_mem_pll_setup.H"

#include "p9_perv_scom_addresses.H"
#include <p9_perv_scom_addresses_fld.H>

enum P9_MEM_PLL_SETUP_Private_Constants
{
    NS_DELAY = 5000000, // unit is nano seconds
    SIM_CYCLE_DELAY = 100000, // unit is sim cycles
    OPCG_ALIGN_SCAN_RATIO = 0b00011
};


fapi2::ReturnCode p9_mem_pll_setup(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& i_target_chip)
{
    uint8_t l_read_attr = 0;
    fapi2::buffer<uint64_t> l_data64;
    uint8_t l_mem_bypass;

    FAPI_INF("Entering ...");

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_NEST_MEM_X_O_PCI_BYPASS, i_target_chip, l_mem_bypass),
             "Error from FAPI_ATTR_GET (ATTR_NEST_MEM_X_O_PCI_BYPASS");

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_MC_SYNC_MODE, i_target_chip, l_read_attr),
             "Error from FAPI_ATTR_GET (ATTR_MC_SYNC_MODE)");

    if (!l_read_attr )
    {
        for (auto l_chplt_trgt :  i_target_chip.getChildren<fapi2::TARGET_TYPE_PERV>
             (fapi2::TARGET_FILTER_ALL_MC, fapi2::TARGET_STATE_FUNCTIONAL))
        {
            FAPI_DBG("Drop PLDY bypass of Progdelay logic");
            l_data64.flush<1>();
            //NET_CTRL1.TP_MC_PDLY_BYPASS_EN_DC = 0
            l_data64.clearBit<PERV_1_NET_CTRL1_CLK_PDLY_BYPASS_EN>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL1_WAND, l_data64));

            FAPI_DBG("Drop DCC bypass of DCC logic");
            l_data64.flush<1>();
            //NET_CTRL1.TP_MC_PDLY_BYPASS_EN_DC = 0
            l_data64.clearBit<PERV_1_NET_CTRL1_CLK_DCC_BYPASS_EN>();
            FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL1_WAND, l_data64));

            if (l_mem_bypass == 0)
            {
                FAPI_DBG("Drop PLL test enable");
                l_data64.flush<1>();
                //NET_CTRL0.TP_PLL_TEST_EN_DC
                l_data64.clearBit<PERV_1_NET_CTRL0_PLL_TEST_EN>();
                FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WAND, l_data64));

                FAPI_DBG("Drop PLL reset");
                l_data64.flush<1>();
                //NET_CTRL0.TP_PLLRST_DC
                l_data64.clearBit<PERV_1_NET_CTRL0_PLL_RESET>();
                FAPI_TRY(fapi2::putScom(l_chplt_trgt, PERV_NET_CTRL0_WAND, l_data64));

                fapi2::delay(NS_DELAY, SIM_CYCLE_DELAY);

                FAPI_DBG("check PLL lock");

                //Getting PLL_LOCK_REG register value
                FAPI_TRY(fapi2::getScom(l_chplt_trgt, PERV_PLL_LOCK_REG,
                                        l_data64)); //l_read_reg = PERV.PLL_LOCK_REG
                FAPI_ASSERT(l_data64.getBit<0>() == 1,
                            fapi2::PLL_LOCK_ERR()
                            .set_TARGET_CHIPLET(l_chplt_trgt)
                            .set_TARGET_CHIP(i_target_chip)
                            .set_PLL_READ(l_data64),
                            "ERROR:MEM PLL LOCK NOT SET");

                FAPI_DBG("Drop PLL Bypass");
                l_data64.flush<1>();
                //NET_CTRL0.TP_PLLBYP_DC =  0
                l_data64.clearBit<PERV_1_NET_CTRL0_PLL_BYPASS>();
{'fraction_non_alphanumeric': 0.1346153846153846, 'fraction_numerical': 0.023443223443223443, 'mean_word_length': 1.2624818727988398, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 64, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4261967', 'n_tokens_mistral': 3369, 'n_tokens_neox': 3115, 'n_words': 541}