summaryrefslogtreecommitdiffstats
path: root/src/include/usr/sbeio/runtime/sbe_msg_passing.H
blob: e50b4493e0571bdccd27e9b3c8d81ba4d266cc92 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/usr/sbeio/runtime/sbe_msg_passing.H $             */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2017,2018                        */
/* [+] 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                                                     */
#ifndef SBE_MSG_PASSING_H
#define SBE_MSG_PASSING_H

#include <stdint.h>
#include <map>
#include <errl/errlmanager.H>
#include <targeting/common/target.H>

//Determine the Data Offset of an SBE Message
#define SBE_MSG_DATA_OFFSET \
static_cast<uint32_t>((reinterpret_cast<uint64_t>(\
 (((const SBE_MSG::sbeMessage_t*)(0))->data)) - \
reinterpret_cast<uint64_t>( \
&(((const SBE_MSG::sbeMessage_t*)(0))->cmdHdr))))

namespace SBE_MSG
{
    // SBE Communication Buffer for Pass-through commands
    /**
     * @brief SBE Communication package size in number of pages
     */
    const uint8_t SBE_COMM_PKG_SIZE = 2;

    /**
     * @brief SBE Communication buffer size
     */
    const uint32_t SBE_COMM_BUFFER_SIZE = SBE_COMM_PKG_SIZE * PAGESIZE;

    /**
     * @brief SBE Message size / Pass-through Command size
     */
    const uint32_t SBE_MSG_SIZE = SBE_COMM_BUFFER_SIZE;


    // SBE Header Version enums for SBE Header version field
    enum sbeHdrVersion
    {
        SBEHDRVER_FIRST             = 0x00010000, // First SBE Header version
        // NOTE: Update SBEHDRVER_LATEST with each new version
        SBEHDRVER_LATEST            = SBEHDRVER_FIRST
    };

    #define ENUM_SBEHDRVER_CHECK(version) (((version) >= SBEHDRVER_FIRST) \
                                        && ((version) <= SBEHDRVER_LATEST))


    // Command Header Version enums for Command Header version field
    enum cmdHdrVersion
    {
        CMDHDRVER_FIRST             = 0x00010000, // First Command Hdr version
        // NOTE: Update CMDHDRVER_LATEST with each new version
        CMDHDRVER_LATEST            = CMDHDRVER_FIRST
    };

    #define ENUM_CMDHDRVER_CHECK(version) (((version) >= CMDHDRVER_FIRST) \
                                        && ((version) <= CMDHDRVER_LATEST))


    // Pass-Through Command enums for Command Header command field
    enum passThruCmds
    {
        // Command Class 0xE0 - HTMGT Messages
        PASSTHRU_HTMGT_GENERIC      = 0x00E00001, // HTMGT Generic Message
        PASSTHRU_HTMGT_GET_PSTATE   = 0x00E00002, // HTMGT Get PState Table
        // Command Class 0xE1 - HBRT Messages
        PASSTHRU_HBRT_GET_PSTATE    = 0x00E10001, // HBRT Get PState Table
        PASSTHRU_HBRT_OVERRIDE_ATTR = 0x00E10002, // HBRT Apply Override
                                                  // attributes
    };


    // SBE Header at start of SBE Message
    typedef struct sbeHeader
    {
        uint32_t version;        // SBE header version
        uint32_t msgSize;        // Message size (Pass-through cmd or rsp)
                                 // Size includes SBE and Command Headers
        uint32_t seqId;          // Sequence ID
    } PACKED sbeHeader_t;

    // Command Header following SBE Header in SBE Message
    typedef struct cmdHeader
    {
        uint32_t version;        // Command header version
        uint32_t status;         // Status of processing (rsp only)
        uint32_t dataOffset;     // Data offset (cmd or rsp)
                                 // Offset is from beginning of Command Header
        uint32_t dataSize;       // Data size (cmd or rsp)
                                 // Size does NOT include ANY Header fields
        uint32_t command;        // Pass-through command
    } PACKED cmdHeader_t;

    // Max Pass-through command/response data size
    const uint32_t SBE_MSG_MAX_DATA =
        SBE_MSG_SIZE - sizeof(sbeHeader_t) - sizeof(cmdHeader_t);

    // SBE Message (Pass-through command or response)
    typedef struct sbeMessage
    {
        sbeHeader_t sbeHdr;              // SBE header
        cmdHeader_t cmdHdr;              // Command header
        uint8_t data[SBE_MSG_MAX_DATA];  // Pass-through command/response data
    } sbeMessage_t;


    /**
     * @brief Function to process pass-through command from SBE message
     *
     * @param[in]  i_procTgt      HB processor target
     * @param[in]  i_reqDataSize  Pass-through command request data size
     * @param[in]  i_reqData      Pass-through command request data
     * @param[out] o_rspStatus    Pass-through command response status
     * @param[out] o_rspDataSize  Pass-through command response data size
     * @param[out] o_rspData      Pass-through command response data
     *
     * @return errlHndl_t    Error log handle on failure.
     */
    typedef errlHndl_t (*processCmdFunction_t)(TARGETING::TargetHandle_t,
                                            uint32_t,
                                            uint8_t*,
                                            uint32_t*,
                                            uint32_t*,
                                            uint8_t*);

    // Process Command Map of pass-through command to function used to process
    typedef std::map<uint32_t, processCmdFunction_t> ProcessCmdMap_t;

    /**
     * @brief Set process pass-through command function in Process Command Map
     *
     * @param[in]  i_command      Process pass-through command
     * @param[in]  i_function     Function to process pass-through command
     *
     * @return int    Return code.
     */
    int setProcessCmdFunction(enum passThruCmds    i_command,
                              processCmdFunction_t i_function);

    /**
     * @brief Erase process pass-through command function in Process Command Map
     *
     * @param[in]  i_command      Process pass-through command
     *
     * @return int    Return code.
     */
    int eraseProcessCmdFunction(enum passThruCmds i_command);

    //------------------------------------------------------------------------
    // Constants for setting/clearing bits in SCOM_ADDR_5003B
    //------------------------------------------------------------------------
    const uint32_t SCOM_ADDR_5003B = 0x0005003B; // CFAM Reg 0x283B
    const uint32_t SBE_MESSAGE_PROCESSING_IN_PROGRESS = 0x40000000;
    const uint32_t SBE_MESSAGE_PROCESSING_COMPLETE = 0x80000000;

    /**
     *  @brief SBE message update bit(s) in CFAM register
     *
     *  @details  This is a call that will update bit(s) in CFAM register 0x283B
     *            or SCOM_ADDR_5003B.
     *
     *  @param[in]  i_proc        HB processor target
     *  @param[in]  i_set_mask    CFAM register mask (mark bits to set)
     *  @param[in]  i_clear_mask  CFAM register mask (mark bits to clear)
     *
     *  @returns  errlHndl_t  NULL on success
     */
    errlHndl_t process_sbe_msg_update_cfam(TARGETING::TargetHandle_t i_proc,
                                           const uint32_t i_set_mask,
                                           const uint32_t i_clear_mask);

} // namespace SBE_MSG


#endif
OpenPOWER on IntegriCloud