summaryrefslogtreecommitdiffstats
path: root/src/include/usr/util/utillidmgr.H
blob: c2ac2d9a0aa07abc5cac105d4add268979ae087e (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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/usr/util/utillidmgr.H $                           */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2013,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                                                     */
#ifndef _UTILLIDMGR_H
#define _UTILLIDMGR_H

/**
 *  @file util/utillidmgr.H
 *
 *  @brief  Interface to support loading lids into memory.  The utilities are
 *          smart enough to determine if a lid is available in PNOR.  If not,
 *          it will attempt to get the LID from the FSP via mailbox messages.
 */

#include <mbox/mbox_queues.H>
#include <mbox/mboxif.H>
#include <errl/errlentry.H>
#include <sys/msg.h>
#include <pnor/pnorif.H>

namespace Util
{

// Lid Ids
//  A Container Lid can be referred to as a Secure Header. The Container Lid ID
//  is associated with the header data that sits in front of an image.
enum LidId
{
    TEST_LIDID = 0x00000111,
    OCC_LIDID = 0x81e00430,
    OCC_CONTAINER_LIDID = 0x80d0000b,
    MCL_LIDID = 0x80d00020,
    // TODO RTC 172767 Make utillidmgr LIDID structure attribute driven
    WOF_LIDID = 0x81e00440,
    WOF_CONTAINER_LIDID = 0x80d00015,
    // Hcode Reference Image LIDs
    NIMBUS_HCODE_LIDID = 0x81e00602,
    CUMULUS_HCODE_LIDID = 0x81e00603,
    HCODE_CONTAINER_LIDID = 0x80d0000c,
    HWREFIMG_RINGOVD_LIDID = 0x81e00620,
    INVALID_LIDID = 0xFFFFFFFF
};

}

class UtilLidMgr
{
  private:
    /**
     *  @brief Default constructor.
     *
     *  @par Detailed Description
     *      Forcing user to use constructor with input parm/
     */
    UtilLidMgr();


  public:
    /**
     *  @brief Initialize Lid Manager object.
     *
     *  @par Detailed Description
     *      Ensures member variables are initialized to sane values.
     *      Sets the initial LID ID.
     *
     *  @param[in] i_lidId
     *                LID ID.
     *
     */
    explicit UtilLidMgr(uint32_t i_lidId);

    /**
     *  @brief Destroy the Lid Manager object resources
     *
     *  @par Detailed Description:
     *      Frees any allocated memory
     *
     */
    ~UtilLidMgr();

    /**
     *  @brief  Sets the desired LID ID in an instance variable.
     *
     *  @par Detailed Description:
     *          This is how the user declares which LID they want
     *          to work with.  It can also be used to reset the
     *          object to a different LID Id..
     *
     *  @param[in] i_lidId
     *                   LID ID.
     *
     *  @return     errlHndl_t
     *                  return errl ==  NULL  -> success
     *                  return errl !=  NULL  -> failure
     */
    errlHndl_t setLidId(uint32_t i_lidId);

    /**
     *  @brief Get LID Size
     *
     *  @par Detailed Description:
     *          Returns useful LID metrics to the user.  Currently
     *          this is only the size of the LID in bytes.
     *
     *  @param[out] o_lidSize
     *                   Size of the LID in bytes.
     *
     *  @return     errlHndl_t
     *                  return errl ==  NULL  -> success
     *                  return errl !=  NULL  -> failure
     */
    errlHndl_t getLidSize(size_t& o_lidSize);

    /**
     *  @brief Get LID
     *
     *  @par Detailed Description:
     *          Gets lid and puts it into space allocated
     *          by the caller.  The caller is required to
     *          allocate the indicated memory space before
     *          calling this function.
     *
     *  @param[in] i_dest
     *          Pointer to where LID should be stored in
     *          hostboot memory
     *
     *  @param[in] i_destSeze
     *          Reserved space in bytes at destintion address
     *          for LID.
     *
     *  @return     errlHndl_t
     *                  return errl ==  NULL  -> success
     *                  return errl !=  NULL  -> failure
     */
    errlHndl_t getLid(void* i_dest, size_t i_destSize);

    /**
     *  @brief Get Stored LID Image
     *
     *  @par Detailed Description:
     *          Determines if a lid image is stored in hostboot
     *          memory space for this UtilLidMgr object.  If an
     *          image is not stored, then the lid image is stored.
     *          Returns pointer and size for the lid image.
     *
     *  @param[out] o_pLidImage
     *          Pointer to where lid image is stored in hostboot
     *          memory
     *
     *  @param[out] o_lidImageSize
     *          Size of lid image is stored in hostboot memory
     *
     *
     *  @return     errlHndl_t
     *                  return errl ==  NULL  -> success
     *                  return errl !=  NULL  -> failure
     */
    errlHndl_t getStoredLidImage(void*& o_pLidImage,
                                 size_t& o_lidImageSize);

    /**
     *  @brief Release LID Image
     *
     *  @par Detailed Description:
     *          Frees memory space allocated for the lid image.
     *          Clears variables associated with storing the image.
     *
     *  @return     errlHndl_t
     *                  return errl ==  NULL  -> success
     *                  return errl !=  NULL  -> failure
     */
    errlHndl_t releaseLidImage(void);

#ifdef CONFIG_IPLTIME_CHECKSTOP_ANALYSIS
    /**
     *  @brief Get lid managers' pointer to the lid vaddr.
     *
     *  @return void* - Returns pointer to virtual address the lid lives in.
     *                  Null if the lid is not in virtual address space.
     *                  NOTE: Only supporting PNOR Virt Addr now
     */
    inline const void* getLidVirtAddr() const
    {
        const void* l_addr = NULL;
        // Get pointer to PNOR vaddr
        if (iv_isLidInPnor)
        {
            l_addr = reinterpret_cast<const void*>(iv_lidPnorInfo.vaddr);
        }
        // Add support for other virtual address spaces here

        return l_addr;
    }
#endif

#ifdef __HOSTBOOT_RUNTIME
    /**
     * @brief Get a list of LID numbers
     * @param[out] number of entrees in the list
     * @return pointer to the list
     */
    static
        const uint32_t * getLidList(size_t * o_num);
#endif

  protected:

    /**
     *  @brief  Updates the lidId in the object
     *
     *  @par Detailed Description:
     *          Updates the lidId in the object
     *          Also composes the LID filename
     *          This function assumes the lid name is of the format
     *          <uppercase hex>.lidbin
     *          The file is not technically a lid, thus the slightly
     *          different name
     *
     *  @param[in] i_lidId
     *                   LID ID.
     */
    void updateLid(uint32_t i_lidId);

   /**
    *  @brief performs object cleanup when a new lidId is set
    *         Function is also called by the destructor.
    */
   errlHndl_t cleanup();

    /**
     * @brief value indicating if lid is in its own pnor partition
     *
     */
    bool iv_isLidInPnor;
#ifndef __HOSTBOOT_RUNTIME
    /**
     *  @brief Get LID Size PNOR
     *
     *  @par Detailed Description:
     *          Checks if LID is in Hostboot Ext image and
     *          gets the size from there if available.
     *          This function assumes the lid name is of the format
     *          <uppercase hex>.lidbin
     *          The file is not technically a lid, thus the slightly
     *          different name
     *
     *  @param[out] o_lidSize
     *                   Size of the LID in bytes.
     *
     *  @param[out] o_imgInPnor
     *                   Indicates image was found in PNOR
     *
     *  @return     errlHndl_t
     *                  return errl ==  NULL  -> success
     *                  return errl !=  NULL  -> failure
     */
    errlHndl_t getLidSizePnor(size_t& o_lidSize, bool& o_imgInPnor);

    /**
     *  @brief Get LID PNOR
     *
     *  @par Detailed Description:
     *          Gets the LID from the PNOR extended image
     *          if it exists.  The caller is required to
     *          allocate the indicated memory space before
     *          calling this function.
     *          This function assumes the lid name is of the format
     *          <uppercase hex>.lidbin
     *          The file is not technically a lid, thus the slightly
     *          different name
     *
     *  @param[in] i_dest
     *          pointer where LID should be stored in
     *          hostboot memory
     *
     *  @param[in] i_destSeze
     *          Reserved space in bytes at destintion address
     *          for LID.
     *
     *  @param[out] o_imgInPnor
     *                   Indicates image was found in PNOR
     *
     *  @return     errlHndl_t
     *                  return errl ==  NULL  -> success
     *                  return errl !=  NULL  -> failure
     */
    errlHndl_t getLidPnor(void* i_dest,
                          size_t i_destSize,
                          bool& o_imgInPnor);

    /**
     * @enum UtilLidMgr::MBOX_MSG_TYPE
     *
     * @brief  Message enum to determine if msg should be sent
     *         asynchronously or if the call should be synchronous
     *
     */
    enum MBOX_MSG_TYPE
    {
        ASYNCHRONOUS,
        SYNCHRONOUS
    };

    /**
     *  @brief Create message queue
     *
     *  @par Detailed Description:
     *          Creates LID message queue and registers with mbox.
     *          It also locks the cv_mutex.  This ensures only the
     *            current instance will listen for response messages
     *            from FSP.
     *          Any function that calls this function must also call
     *            unregisterMsgQueue() to free the queue and unlock
     *            the mutex.
     *
     *  @return     errlHndl_t
     *                  return errl ==  NULL  -> success
     *                  return errl !=  NULL  -> failure
     */
    errlHndl_t createMsgQueue();

    /**
     *  @brief Unregister Msg Queue
     *
     *  @par Detailed Description:
     *          Unregisters LID msg queue with mbox
     */
    void unregisterMsgQueue();

    /**
     *  @brief  Uses the internal mailbox to send a message to the FSP
     *
     *
     *  @par Detailed Description:
     *          This funciton will call into mailboxsp code using the
     *          UtilLidMgr as a target message queue..
     *
     *  @param[in] i_type
     *           ::MBOX_MSG_TYPE passed in to define the
     *           message sending policy.
     *
     *  @param[in/out] i_msg
     *                    This parameter is used as both input and an
     *                    output parameter. If the message is sent
     *                    synchronusly the response will be populated
     *                    in an object pointed to by this pointer. If
     *                    the message is asynchronus the object
     *                    pointed to by this parameter will be sent to
     *                    the fsp.
     *
     *  @return     errlHndl_t
     *                  return errl ==  NULL  -> success
     *                  return errl !=  NULL  -> failure
     */
    errlHndl_t  sendMboxMessage( MBOX_MSG_TYPE i_type, msg_t * i_msg  );

    /**
     * @brief Mutex to prevent concurrent LID operations.
     *     This needs to be static so we can mutex across multiple instances
     */
    static mutex_t cv_mutex;

    /**
     * @brief Keep track of mutex state
     */
    bool iv_needUnlock;

    /**
     * @brief Keep track of Msg queue registered state
     */
    bool iv_queueRegistered;

    /**
     * @brief Pointer to message queue
     */
    msg_q_t iv_HbMsgQ;

    /**
     * @brief pointer to buffer with image of current LID
     */
    void* iv_pLidImage;

    /**
     * @brief size of buffer with image of current LID
     */
    size_t iv_lidImageSize;


#else // __HOSTBOOT_RUNTIME

    /**
     * @brief Loads the LID using the Host interfaces.
     */
    errlHndl_t loadLid();

    /**
     * @brief Pointer to the buffer containing the LID.
     */
    void* iv_lidBuffer;

    /**
     *  @brief Indicates that a lid is pre-verified in HbResvMem
     *
     *  @param[in] i_section - Lid Id
     *
     *  @return bool - True if lid is in HB reserved memory, false otherwise
    */
    bool lidInHbResvMem(uint32_t i_lidId) const;

#endif // __HOSTBOOT_RUNTIME

    /**
     *  @brief Determines if a Lid Id has a corresponding PNOR section ID
     *         and sets PNOR info if it exists
     *
     *  @param[in] i_lidId          - lid id to search for
     *  @param[out] o_lidPnorInfo   - pnor section info associated with the lid
     *                                if it exists in pnor
     *
     *  @return bool - True if lid is in a section, false otherwise
    */
    bool getLidPnorSectionInfo(uint32_t i_lidId,
                               PNOR::SectionInfo_t &o_lidPnorInfo);
    /**
     * @brief LID fileName
     */
    char iv_lidFileName[16];

    /**
     * @brief current LID ID
     */
    uint32_t iv_lidId;

    /**
     * @brief reported size of current LID
     */
    size_t iv_lidSize;

    /**
     * @brief pnor section (other than ext img) current lid is in
     *        PNOR::INVALID_SECTION if not in other sections
     */
    PNOR::SectionInfo_t iv_lidPnorInfo;

    /**
     * @brief value indicating if a fsp exists
     */
    bool iv_spBaseServicesEnabled;

    /**
     * @brief value indicating if lid is in extended image
     */
    bool iv_isLidInVFS;

    /**
     * @brief value indicating if lid is in hostboot reserved memory
     */
    bool iv_isLidInHbResvMem;

};

#endif /* _UTILLIDMGR_H */

OpenPOWER on IntegriCloud