summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/memory/p9_mss_freq_system.C
blob: 128bd149866cc410b8d0e25c5a82f1ac1ba5d92b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: chips/p9/procedures/hwp/memory/p9_mss_freq_system.C $         */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* EKB Project                                                            */
/*                                                                        */
/* COPYRIGHT 2015,2016                                                    */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

///
/// @file p9_freq_system.C
/// @brief Sets synchronous mode an
///
// *HWP HWP Owner: Andre A. Marin  <aamarin@us.ibm.com>
// *HWP FW Owner: Brian Silver <bsilver@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: FSP:HB
#include <vector>
#include <map>

#include <fapi2.H>
#include <mss.H>

#include <p9_mss_freq_system.H>
#include <lib/utils/find.H>
#include <lib/utils/count_dimm.H>
#include <lib/freq/sync.H>

using fapi2::TARGET_TYPE_SYSTEM;
using fapi2::TARGET_TYPE_PROC_CHIP;
using fapi2::TARGET_TYPE_MCBIST;
using fapi2::TARGET_TYPE_MCS;

extern "C"
{
    ///
    /// @brief Set synchronous mode
    /// @param[in] i_targets vector of controllers (e.g., MCS)
    /// @return FAPI2_RC_SUCCESS iff ok
    ///
    fapi2::ReturnCode p9_mss_freq_system( const std::vector< fapi2::Target<TARGET_TYPE_MCBIST> >& i_targets )
    {
        FAPI_INF("----- In p9_mss_freq_system ----");

        // If there are no DIMM we don't need to bother. In fact, we can't as we didn't setup
        // attributes for the PHY, etc. If there is even one DIMM on any of this list of MCBIST,
        // we do the right thing.
        uint64_t l_dimm_count = 0;
        std::for_each( i_targets.begin(), i_targets.end(),
                       [&l_dimm_count](const fapi2::Target<TARGET_TYPE_MCBIST>& i_target)
        {
            l_dimm_count += mss::count_dimm(i_target);
        }
                     );

        if (l_dimm_count == 0)
        {
            FAPI_INF("... skipping freq_system - no DIMM ...");
            return fapi2::FAPI2_RC_SUCCESS;
        }

        std::map< fapi2::Target<TARGET_TYPE_MCBIST>, uint64_t > l_freq_map;
        uint32_t l_nest_freq = 0;
        uint8_t l_required_sync_mode = 0;
        mss::sync_mode l_mc_in_sync;
        mss::speed_equality l_equal_dimm_speed;

        // Populate dimm speed map
        FAPI_TRY( mss::dimm_speed_map(i_targets, l_freq_map, l_equal_dimm_speed),
                  "Failed to get dimm speed mapping" );

        FAPI_INF("Dimm speed for all MCBISTs are the same : %s",
                 uint8_t(l_equal_dimm_speed) ? "true" : "false");

        // Get nest freq && F/W attr that tells me if sync mode is required
        // or if I have to figure that out
        FAPI_TRY( FAPI_ATTR_GET( fapi2::ATTR_REQUIRED_SYNCH_MODE,
                                 fapi2::Target<TARGET_TYPE_SYSTEM>(),
                                 l_required_sync_mode ) );

        FAPI_TRY( FAPI_ATTR_GET( fapi2::ATTR_FREQ_PB_MHZ,
                                 fapi2::Target<TARGET_TYPE_SYSTEM>(),
                                 l_nest_freq) );

        FAPI_INF("Retrieved req'd sync mode: %d and nest freq %d", l_required_sync_mode, l_nest_freq);

        // Select SYNCH mode
        FAPI_TRY( mss::select_sync_mode(l_freq_map,
                                        l_equal_dimm_speed,
                                        l_nest_freq,
                                        l_required_sync_mode,
                                        l_mc_in_sync) );

        FAPI_INF("Selected SYNC mode : %s", uint8_t(l_mc_in_sync) ? "MC in sync" : "MC NOT in sync");

        // Set attribute
        for(const auto& l_mcbist : i_targets)
        {
            const auto& l_proc_chip = mss::find_target<TARGET_TYPE_PROC_CHIP>(l_mcbist);

            // Cast converts enum class to uint8_t& expected for ATTR_SET
            FAPI_TRY( FAPI_ATTR_SET( fapi2::ATTR_MC_SYNC_MODE,
                                     l_proc_chip,
                                     reinterpret_cast<uint8_t(&)>(l_mc_in_sync) ),
                      "Failed to set ATTR_MC_SYNC_MODE");
        }

    fapi_try_exit:
        return fapi2::current_err;

    } // p9_freq_system

} //extern "C"
OpenPOWER on IntegriCloud