summaryrefslogtreecommitdiffstats
path: root/sbe/sbefw/sberegaccess.C
blob: be5bdb2a33af40167a5de43ab6e7853602d8245a (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
 * @file: ppe/sbe/sbefw/sberegaccess.C
 *
 * @brief This file contains interfaces to get/set FW flags either in the
 * scratch registers and/or the FW attributes.
 */

#include "sberegaccess.H"
#include "sbetrace.H"
#include "fapi2.H"
#include <ppe42_scom.h>

using namespace fapi2;

/**
 * @brief Initizlize the class
 *
 * @return An RC indicating success/failure
 */
uint32_t SbeRegAccess::init()
{
    #define SBE_FUNC "SbeRegAccess::SbeRegAccess "
    static bool l_initDone = false;
    uint32_t l_rc = 0;
    uint64_t l_mbx8 = 0;
    do
    {
        if(l_initDone)
        {
            break;
        }
        Target<TARGET_TYPE_PROC_CHIP> l_chip = plat_getChipTarget();
        // Read SBE messaging register into iv_messagingReg
        l_rc = getscom_abs(SBE_MESSAGING_REGISTER_ADDR, &iv_messagingReg);
        if(PCB_ERROR_NONE != l_rc)
        {
            SBE_ERROR(SBE_FUNC"Failed reading sbe messaging reg., RC: 0x%08X. ",
                      l_rc);
            break;
        }
        // Read Mailbox register 8 to check if the mailbox registers 3 and 6 are
        // valid
        l_rc = getscom_abs(SBE_MBX8_REGISTER_ADDR, &l_mbx8);
        if(PCB_ERROR_NONE != l_rc)
        {
            SBE_ERROR(SBE_FUNC"Failed reading mailbox reg 7, RC: 0x%08X. ",
                      l_rc);
            break;
        }
        if(l_mbx8 & SBE_MBX8_MBX3_VALID_MASK)
        {
            // Read MBX3
            l_rc = getscom_abs(SBE_MBX3_REGISTER_ADDR, &iv_mbx3);
            if(PCB_ERROR_NONE != l_rc)
            {
                SBE_ERROR(SBE_FUNC"Failed reading mailbox reg 3, RC: 0x%08X. ",
                        l_rc);
                break;
            }
        }
        else
        {
            // Need to read the values off the attributes
            // TODO: via RTC 150291 : Needs to be changed when all FW control
            // attributes are to be combined into one
            uint8_t l_attr = 0;
            FAPI_ATTR_GET(ATTR_ISTEP_MODE, l_chip, l_attr);
            iv_istepMode = l_attr;
            FAPI_ATTR_GET(ATTR_SBE_RUNTIME_MODE, l_chip, l_attr);
            iv_sbeDestRuntime = l_attr;
            FAPI_ATTR_GET(ATTR_IS_SP_MODE, l_chip, l_attr);
            iv_fspAttached = l_attr;
            FAPI_ATTR_GET(ATTR_SBE_FFDC_ENABLE, l_chip, l_attr);
            iv_collectFFDC = l_attr;
            FAPI_ATTR_GET(ATTR_SBE_INTERNAL_FFDC_ENABLE, l_chip, l_attr);
            iv_sendFFDC = l_attr;
        }
        if(l_mbx8 & SBE_MBX8_MBX6_VALID_MASK)
        {
            // Read MBX6
            l_rc = getscom_abs(SBE_MBX6_REGISTER_ADDR, &iv_mbx6);
            if(PCB_ERROR_NONE != l_rc)
            {
                SBE_ERROR(SBE_FUNC"Failed reading mailbox reg 6, RC: 0x%08X. "
                          l_rc);
                break;
            }
        }
        // TODO via RTC:150291 Need to get the exact attribute name that
        // provides the master/slave role
    } while(false);
    SBE_DEBUG(SBE_FUNC"Read mailbox registers: mbx8: 0x%08X, mbx3: 0x%08X, "
              "mbx6: 0x%08X", (uint32_t)(l_mbx8 >> 32),
              (uint32_t)(iv_mbx3 >> 32), (uint32_t)(iv_mbx6 >> 32));
    l_initDone = true;
    return l_rc;
    #undef SBE_FUNC
}

/**
 * @brief Update the SBE states into the SBE messaging register. The
 * function does a read-modify-write, so any bits other than the state
 * bits are preserved. The current state of the register is set to
 * i_state, whereas the old current state is copied to previous state
 *
 * @param [in] i_state The current SBE state
 *
 * @return RC indicating success/failure.
 *
 */
uint32_t SbeRegAccess::updateSbeState(const sbeState &i_state)
{
    #define SBE_FUNC "SbeRegAccess::updateSbeState "
    uint32_t l_rc = 0;

    iv_prevState = iv_currState;
    iv_currState = i_state;
    l_rc = putscom_abs(SBE_MESSAGING_REGISTER_ADDR, iv_messagingReg);
    if(PCB_ERROR_NONE != l_rc)
    {
        SBE_ERROR(SBE_FUNC"Failed to update state to messaging "
                "register. RC: 0x%08X", l_rc);
    }
    return l_rc;
    #undef SBE_FUNC
}

/**
 * @brief Update the SBE IPL steps into the SBE messaging register. The
 * function does a read-modify-write, so any bits other than the IPL
 * steps are retianed
 *
 * @param [in] i_major IPL major step number
 * @param [in] i_minor IPL minor step number
 *
 * @return RC indicating success/failure.
 *
 */
uint32_t SbeRegAccess::updateSbeStep(const uint8_t i_major,
                                     const uint8_t i_minor)
{
    #define SBE_FUNC "SbeRegAccess::updateSbeStep "
    uint32_t l_rc = 0;

    iv_majorStep = i_major;
    iv_minorStep = i_minor;

    l_rc = putscom_abs(SBE_MESSAGING_REGISTER_ADDR, iv_messagingReg);
    if(l_rc)
    {
        SBE_ERROR(SBE_FUNC"Failed to update SBE step to messaging "
                "register. RC: 0x%08X", l_rc);
    }
    return l_rc;
    #undef SBE_FUNC
}

/**
 * @brief Set the SBE ready bit into the SBE messaging register
 * (meaning that SBE control loop is initialized) The function does a
 * read-modify-write, so any bits other than the SBE ready bit remain
 * unchanged.
 *
 * @return RC indicating success/failure.
 *
 */
uint32_t SbeRegAccess::setSbeReady()
{
    #define SBE_FUNC "SbeRegAccess::setSbeReady "
    uint32_t l_rc = 0;

    iv_sbeBooted = true;
    l_rc = putscom_abs(SBE_MESSAGING_REGISTER_ADDR, iv_messagingReg);
    if(l_rc)
    {
        SBE_ERROR(SBE_FUNC"Failed to update SBE ready state to "
                "messaging register. RC: 0x%08X", l_rc);
    }
    return l_rc;
    #undef SBE_FUNC
}


/**
 * @brief Set the MPIPL mode bit into the mailbox scratch reg. 3
 * The function does a read-modify-write, so any bits other than the
 * SBE ready bit remain unchanged.
 *
 * @param i_set [in] Whether to set or clear the MPIPL flag
 *
 * @return RC indicating success/failure.
 *
 */
uint32_t SbeRegAccess::setMpIplMode(const bool i_set)
{
    #define SBE_FUNC "SbeRegAccess::setMpIplMode"
    uint32_t l_rc = 0;
    uint8_t l_set = i_set;
    iv_mpiplMode = i_set;
    FAPI_ATTR_SET(ATTR_IS_MPIPL, Target<TARGET_TYPE_SYSTEM>(), l_set);
    l_rc = putscom_abs(SBE_MBX3_REGISTER_ADDR, iv_mbx3);
    if(l_rc)
    {
        SBE_ERROR(SBE_FUNC"Failed to set/clear MPIPL flag in "
                "mbx reg. 3. RC: 0x%08X", l_rc);
    }
    return l_rc;
    #undef SBE_FUNC
}

OpenPOWER on IntegriCloud