summaryrefslogtreecommitdiffstats
path: root/src/include/usr/util/utillidmgr.H
blob: 53560faa80e5a9981e2d22f92237831254fb17e6 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/usr/util/utillidmgr.H $                           */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2013                   */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* 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>



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);

  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();

#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 paramter 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;
#else // __HOSTBOOT_RUNTIME

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

    /**
     * @brief Cached value of the LID location.  (Host vs PNOR)
     */
    bool iv_isPnor;

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

#endif // __HOSTBOOT_RUNTIME

    /**
     * @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;


};

#endif /* _UTILLIDMGR_H */

OpenPOWER on IntegriCloud