summaryrefslogtreecommitdiffstats
path: root/src/include/usr/fapi2/plat_attr_override_sync.H
blob: 07bcd5a9a4af1e233088820039868380364606cf (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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/usr/fapi2/plat_attr_override_sync.H $             */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2017                        */
/* [+] 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 plat_attr_override_sync.H
///
/// @brief Defines the AttrOverrideSync class that contains functions for
///        Attribute Override and Sync.
///

#ifndef PLATATTROVERRIDESYNC_H_
#define PLATATTROVERRIDESYNC_H_

//******************************************************************************
// Includes
//******************************************************************************
#include <stdint.h>
#include <mbox/mboxif.H>
#include <targeting/common/attributeTank.H>
#include <pnor/pnorif.H>

#include <attribute_ids.H>
#include <return_code.H>
#include <target.H>
#include <target_types.H>


//******************************************************************************
// Interface
//******************************************************************************
namespace TARGETING
{
    errlHndl_t getAttrOverrides(PNOR::SectionInfo_t &i_sectionInfo,
                      AttributeTank* io_tanks[AttributeTank::TANK_LAYER_LAST]);

    class AttrRP;
}

namespace RT_TARG
{
    int apply_attr_override(uint8_t* i_data,
                            size_t i_size );
}

namespace fapi2
{

// Forward references
class AttrOverrideSync;
//class Target;

/**
 *  @brief Return the AttrOverrideSync Singleton. Other modules must call this
 *         rather than using Singleton<>
 *
 *  @return Reference to the AttrOverrideSync Singleton
 */
AttrOverrideSync & theAttrOverrideSync();

/**
 * @class AttrOverrideSync
 *
 * This class contains the FAPI Attribute Override and Sync tanks. It provides
 * functions to:
 * - Monitor for incoming attribute override/sync messages from the FSP
 * - Send attribute override/syncs to the FSP
 * - Return any attribute override on an attribute get
 * - Cancel any non-const attribute override and save the attribute in the sync
 *   tank on an attribute set
 */
class AttrOverrideSync
{
public:
    /**
     * @brief Allow a debug tool to directly access the override tank
     */
    friend void directOverride();

    /**
     * @brief Allow a attribute override to directly access the override tank
     */
    friend errlHndl_t TARGETING::getAttrOverrides(
                    PNOR::SectionInfo_t &i_sectionInfo,
                    TARGETING::AttributeTank*
                        io_tanks[TARGETING::AttributeTank::TANK_LAYER_LAST]);

    friend int RT_TARG::apply_attr_override(uint8_t* i_data,
                                            size_t i_size );

    friend class TARGETING::AttrRP;

    /**
     * @brief Maximum size of a direct attribute override
     */
    static const size_t MAX_DIRECT_OVERRIDE_ATTR_SIZE_BYTES = 64;

    /**
     * @brief Attribute Override/Sync Mailbox Message Type Constants
     *        These must be kept in sync with FSP firmware
     */
    enum MAILBOX_MSG_TYPE
    {
        MSG_SET_OVERRIDES       = MBOX::FIRST_UNSECURE_MSG + 0x10, // FSP<->Hb
        MSG_CLEAR_ALL_OVERRIDES = MBOX::FIRST_UNSECURE_MSG + 0x11, // FSP<->Hb
        MSG_SET_SYNC_ATTS       = MBOX::FIRST_UNSECURE_MSG + 0x12, // FSP<--Hb
        MSG_GET_OVERRIDES       = MBOX::FIRST_UNSECURE_MSG + 0x13, // FSP<--Hb
    };

    /**
     * @brief Default constructor
     */
    AttrOverrideSync();

    /**
     * @brief Destructor
     */
    ~AttrOverrideSync();

    /**
     * @brief Monitors for incoming attribute override messages from the FSP.
     *        This function never returns and must be called by a task
     *        specifically started to monitor for these messages
     */
    void monitorForFspMessages();

    /**
     * @brief Sends Attribute Overrides and Syncs to the FSP
     *
     * This is called at the end of an IStep. For both FAPI/TARG tanks it:
     * - Clears the FSP Attribute Overrides
     * - Sends the Hostboot Attribute Overrides to the FSP
     * - Sends the Hostboot Attribute Syncs to the FSP
     */
    void sendAttrOverridesAndSyncsToFsp();

    /**
     * @brief Gets Attribute Overrides and Syncs from the FSP
     *
     * This is called at the start of a normal (non-istep) IPL if an attribute
     * is set indicating that the FSP has attribute overrides in place
     */
    void getAttrOverridesFromFsp();

    /**
     * @brief This function gets any Attribute Override on an attribute get
     *
     * This is called for those FAPI Attributes that do not map to Targeting
     * attributes - their overrides live in the FAPI Attribute tanks.
     *
     * @param[in] i_attrId  FAPI Attribute ID
     * @param[in] i_pTarget Pointer to FAPI Target
     * @param[in] o_pVal    Pointer to attribute value
     *
     * @return true if an override exists and was written to o_pVal
     */
    bool getAttrOverride(const AttributeId i_attrId,
                         const Target<TARGET_TYPE_ALL>* i_pTarget,
                         void * o_pVal) const;

    /**
     * @brief This function gets any Attribute Override on an attribute get
     *
     * This is a wrapper that calls getAttrOverride on the AttrOverrideSync
     * singleton, it should be called by external modules to avoid the
     * performance penalty of calling theAttrOverrideSync() then getAttrOverride
     *
     * @param[in] i_attrId  FAPI Attribute ID
     * @param[in] i_pTarget Reference to FAPI2 Target
     * @param[in] o_pVal    Pointer to attribute value
     *
     * @return true if an override exists and was written to o_pVal
     */
    static bool getAttrOverrideFunc(const AttributeId i_attrId,
                                const Target<TARGET_TYPE_ALL>& i_pTarget,
                                void * o_pVal);

    /**
     * @brief This function performs the actions required on an attribute set
     *
     * This is called for those FAPI Attributes that do not map to Targeting
     * attributes - their overrides/syncs live in the FAPI Attribute tanks.
     *
     * - Any non-const attribute override is cleared
     * - The attribute is saved to be synced to Cronus (if Cronus Sync enabled)
     *
     * @param[in] i_attrId  FAPI Attribute ID
     * @param[in] i_pTarget Pointer to FAPI Target
     * @param[in] i_size    Size of attribute value
     * @param[in] i_pVal    Pointer to attribute value
     */
    void setAttrActions(const AttributeId i_attrId,
                        const Target<TARGET_TYPE_ALL>* i_pTarget,
                        const uint32_t i_size,
                        const void * i_pVal);

    /**
     * @brief This will force a sync of all FAPI attr to the FSP or the
     *  debug interface using the built in attribute sync tank
     *
     * This is called for ALL FAPI Attributes even if they are
     * directly backed into HB targeting
     *
     * @param[in] i_type     FAPI type to limit scope to, default none
     * @param[in] i_fapiPos  FAPI pos to limit scope to, default none
     * @param[in] i_attrHash Attribute hash to limit scope to, default none
     *
     * - The attribute is saved to be synced to debug interface (Cronus)
     *
     */
    void triggerAttrSync(fapi2::TargetType i_type = fapi2::TARGET_TYPE_NONE,
                         uint32_t i_fapiPos = TARGETING::FAPI_POS_NA,
                         uint32_t i_attrHash = 0x0);

    /**
     * @brief This function will clear all attribute overrides in effect.
     *        This function is called by the debug interface
     *
     */
    void clearAttrOverrides();

    /**
     * @brief This function will allow the debug interface to set
     *        attribute overrides "dynamically" at any point in the IPL
     *        between isteps.  The debug interface is used to process
     *        the attributes in the same format as the ATTR_TMP and ATTR_PERM
     *        PNOR partition binary blobs
     *
     */
    void dynSetAttrOverrides();

    /**
     * @brief This function will allow the debug interface to dump a
     *        specific attribute from a given fapi target type/pos
     *        at any point in the IPL between isteps.  The debug interface
     *        is used to process a simple request, and then dump the
     *        atrribute(s) back down the debug interface via same
     *        mechanism as triggerAttrSync
     *
     */
    void dynAttrGet();

    /**
     * @brief This function actually sends the FAPI Sync tank attributes
     *  across the debug interface
     */
    void sendFapiAttrSyncs();

    /**
     * @brief This function performs the actions required on an attribute set
     *
     * This is a wrapper that calls setAttrActions on the AttrOverrideSync
     * singleton, it should be called by external modules to avoid the
     * performance penalty of calling theAttrOverrideSync() then setAttrActions
     *
     * @param[in] i_attrId  FAPI Attribute ID
     * @param[in] i_pTarget Reference to FAPI2 Target
     * @param[in] i_size    Size of attribute value
     * @param[in] i_pVal    Pointer to attribute value
     */
    static void setAttrActionsFunc(const AttributeId i_attrId,
                                   const Target<TARGET_TYPE_ALL>& i_pTarget,
                                   const uint32_t i_size,
                                   const void * i_pVal);

private:

    /**
     * @brief Utility function that sends attributes to the FSP
     *
     * This function frees the allocated memory in the input vector of chunks
     * and empties the vector
     *
     * @param[in] i_msgType     Message type (ID) to send
     * @param[in] i_tankLayer   Tank Layer to send attribute to
     * @param[io] io_attributes Attributes to send.
     *
     * @return error log handle
     */
    static errlHndl_t sendAttrsToFsp(
        const MAILBOX_MSG_TYPE i_msgType,
        const TARGETING::AttributeTank::TankLayer i_tankLayer,
        std::vector<TARGETING::AttributeTank::AttributeSerializedChunk> &
            io_attributes);

    /**
     * @brief Utility function that gets the target type of a FAPI Target as
     *        used in an attribute tank
     *
     * @param[in] i_pTarget Pointer to FAPI Target (NULL = system)
     *
     * @return Target Type
     */
    static uint32_t getTargetType(const Target<TARGET_TYPE_ALL>* i_pTarget);

    // The FAPI Attribute Tanks
    TARGETING::AttributeTank iv_overrideTank;
    TARGETING::AttributeTank iv_syncTank;
};

} // namespace fapi2

#endif // PLATATTROVERRIDESYNC_H_
OpenPOWER on IntegriCloud