summaryrefslogtreecommitdiffstats
path: root/src/ppe/sbe/sbefw/sbecmdparser.C
blob: 65bf27173986fa4364f29d54f515943e1316e65d (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/ppe/sbe/sbefw/sbecmdparser.C $                            */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015                             */
/* [+] 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: ppe/sbe/sbefw/sbecmdparser.C
 *
 * @brief This file contains the SBE FIFO Commands
 *
 */

#include "sbecmdparser.H"
#include "sbecmdscomaccess.H"
#include "sbecmdiplcontrol.H"
#include "sbetrace.H"
#include "sbe_sp_intf.H"


////////////////////////////////////////////////////////////////
// @brief g_sbeScomCmdArray
////////////////////////////////////////////////////////////////
static sbeCmdStruct_t g_sbeScomCmdArray [] =
{
    {sbeGetScom,
     SBE_CMD_GETSCOM,
     SBE_FENCE_AT_CONTINUOUS_IPL,
     },

    {sbePutScom,
     SBE_CMD_PUTSCOM,
     SBE_FENCE_AT_CONTINUOUS_IPL,
     },
};

////////////////////////////////////////////////////////////////
// @brief g_sbeScomCmdArray
//
////////////////////////////////////////////////////////////////
static sbeCmdStruct_t g_sbeIplControlCmdArray [] =
{
    {sbeHandleIstep,
     SBE_CMD_EXECUTE_ISTEP,
     SBE_FENCE_AT_CONTINUOUS_IPL|SBE_FENCE_AT_RUNTIME|SBE_FENCE_AT_MPIPL,
     },

    {sbeWaitForSbeIplDone,
     SBE_CMD_IS_SBE_IPL_DONE,
     SBE_FENCE_AT_ISTEP|SBE_FENCE_AT_RUNTIME|SBE_FENCE_AT_MPIPL,
     },
};



////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
uint8_t sbeGetCmdStructAttr (const uint8_t  i_cmdClass,
                                   sbeCmdStruct_t **o_ppCmd)
{
    #define SBE_FUNC " sbeGetCmdStructAttr "
    SBE_DEBUG(SBE_FUNC);
    uint8_t l_numCmds  = 0;
    *o_ppCmd = NULL;

    switch(i_cmdClass)
    {
        case SBE_CMD_CLASS_IPL_CONTROL:
            // @TODO via RTC : 128655
            //       Use C++ style typecase
            l_numCmds = sizeof(g_sbeIplControlCmdArray) /
                        sizeof(sbeCmdStruct_t);
            *o_ppCmd    = (sbeCmdStruct_t*)g_sbeIplControlCmdArray;
            break;
        case SBE_CMD_CLASS_SCOM_ACCESS:
            l_numCmds = sizeof(g_sbeScomCmdArray) /
                        sizeof(sbeCmdStruct_t);
            *o_ppCmd    = (sbeCmdStruct_t*)g_sbeScomCmdArray;
            break;

        // This will grow with each class of chipOp in future
        default:
                break;
    }
    return l_numCmds;
    #undef SBE_FUNC
}


////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
uint8_t sbeValidateCmdClass (const uint8_t i_cmdClass,
                             const uint8_t i_cmdOpcode)
{
    #define SBE_FUNC " sbeValidateCmdClass "
    uint8_t l_rc           = SBE_SEC_COMMAND_NOT_SUPPORTED;

    SBE_DEBUG(SBE_FUNC"i_cmdClass[0x%02X], "
              "i_cmdOpcode[0x%02X]", i_cmdClass, i_cmdOpcode);

    do
    {
        uint8_t l_numCmds      = 0;
        sbeCmdStruct_t *l_pCmd = NULL;

        l_numCmds = sbeGetCmdStructAttr (i_cmdClass, &l_pCmd);
        if (!l_numCmds)
        {
            // Command class not supported
            l_rc = SBE_SEC_COMMAND_CLASS_NOT_SUPPORTED;
            break;
        }

        // @TODO via RTC : 128654
        //       Analyze on merging the validation functions into one
        //       and also on using loop vs switch case performance
        for (uint8_t l_cnt = 0; l_cnt < l_numCmds; ++l_cnt, ++l_pCmd)
        {
            if (i_cmdOpcode == l_pCmd->cmd_opcode)
            {
                // Command found
                l_rc = SBE_SEC_OPERATION_SUCCESSFUL;
                break;
            }
        }
    } while (false);

    return l_rc;
    #undef SBE_FUNC
}

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
bool sbeIsCmdAllowedAtState (const uint8_t i_cmdClass,
                             const uint8_t i_cmdOpcode)
{
    // @TODO via RTC : 126146
    //       SBE state management
    return 0;
}

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
sbeCmdFunc_t sbeFindCmdFunc (const uint8_t i_cmdClass,
                             const uint8_t i_cmdOpcode)

{
    #define SBE_FUNC " sbeFindCmdFunc "
    uint8_t l_numCmds      = 0;
    sbeCmdStruct_t *l_pCmd = NULL;

    l_numCmds = sbeGetCmdStructAttr (i_cmdClass, &l_pCmd);

    SBE_DEBUG(SBE_FUNC"i_cmdClass[0x%02X], "
              "i_cmdOpcode[0x%02X], l_numCmds[0x%02X]",
               i_cmdClass, i_cmdOpcode, l_numCmds);

    for (uint8_t l_cnt = 0; l_cnt < l_numCmds; ++l_cnt, ++l_pCmd)
    {
        if (i_cmdOpcode == l_pCmd->cmd_opcode)
        {
            break;
        }
    }

    return l_pCmd ? (l_pCmd->cmd_func) : NULL;
    #undef SBE_FUNC
}
OpenPOWER on IntegriCloud