summaryrefslogtreecommitdiffstats
path: root/src/usr/hdat/hdathdif.H
blob: a02f9a63411bd153fe6c51e83432a6bd77199ad0 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hdat/hdathdif.H $                                     */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016                             */
/* [+] 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 HDATHDIF_H
#define HDATHDIF_H

/**
 *  @file hdathdif.H
 *
 *  @brief This file contains the class definition for the object provding the
 *         HDIF header for most hypervisor data structures.
 *
 */


/*----------------------------------------------------------------------------*/
/* Includes                                                                   */
/*----------------------------------------------------------------------------*/
#include <stdint.h>
#include <hdat/hdat.H>
#include <hdat/hdat_reasoncodes.H>
#include <errl/errlentry.H>
#include <util/utilmem.H>



namespace HDAT
{

/*----------------------------------------------------------------------------*/
/* C++ class definition                                                       */
/*----------------------------------------------------------------------------*/

/** Begin Class Description
 *
 * @brief  The HdatHdif class provides the base class for hypervisor data areas
 *     that have an HDIF header.  Other C++ classes that build specific
 *     hypervisor data area structures are derived from this class.
 *
 * Description: This object is not intended to be constructed directly.  Rather,
 *              it provides the base class upon which other derived classes are
 *              built.
 *
 * Thread safety:  An HdatHdif object is not thread safe.  That is, a single
 *                 object cannot be shared and used concurrently by
 *                 multiple threads at the same time.  An object can be used by
 *                 multiple threads if the threads serialize access.  And of
 *                 course, each thread can use its own object with no concerns
 *                 about what other threads are doing.
 *
 * Signal handler usage:
 *                This class is not intended to be used in a signal handler
 *                and nothing has been done to try and make it safe to use
 *                in a signal handler.
 *
 * End Class Description
 */
class HdatHdif
{
    public:

       /**
        * @brief Construct an HdatHdif base object.
        *
        *       This is the constructor for the HdatHdif object
        *
        *       If you are constructing this object on the heap by using new,
        *       you must check the pointer returned from new null value.
        *       If null, new failed to allocate storage and the constructor
        *       was not called.  If not null, then you must check o_errlHndl
        *       to see if the constructor ran successfully.If o_errlHndl
        *       indicates an error was reported by the constructor, new has
        *       already allocated heap storage and the object must be deleted in
        *       order to free the heap storage.
        *
        * @pre None
        * @param o_errlHndl  output error handle
        *
        * @param i_eyeCatcher input the eyecatcher string
        * @param i_dataPtrCnt input data array pointer count
        * @param i_instance input object instance
        * @param i_childCnt input child count
        * @param i_ver input version number
        *
        * @post An HdatHdif object has been constructed.  Heap storage has been
        * allocated.
        *
        * @return A null error log handle if successful, else the return code
        *         pointed to by errlHndl_t contains one of:
        *
        * @retval HDAT_ALLOC_ERROR
        */
        HdatHdif();

        HdatHdif(errlHndl_t &o_errlHndl,
                 const char i_eyeCatcher[],
                 uint32_t i_dataPtrCnt,
                 uint32_t i_instance = 0,
                 uint32_t i_childCnt = 0,
                 uint32_t i_ver = 1);


       /**
        * @brief HdatHdif object destructor
        *
        * @pre None
        *
        * @post Heap storage is deallocated
        *
        */
        virtual ~HdatHdif();


       /**
        * @brief Change the offset to the beginning of a set of children
        *
        * @pre i_childCnt from ctor must be greater than 0 (not checked)
        *
        * @post Total object size is updated.  Child structure pointer entry is
        * updated
        *
        * @param i_whichChildEntry -
        *        input parameter - An array index for the children being added.
        *        This is a 0 based array index so the first entry being added
        *        would specify 0 for this parameter.
        *        i_whichChildEntry < i_childCnt from ctor (not checked)
        * @param i_size            -
        *        input parameter - The size of the child structure(s)
        * @param i_numChildStr     -
        *        input parameter - The number of children being added.
        *
        */
        void addChild(uint32_t i_whichChildEntry,
                        uint32_t i_size,
                        uint32_t i_numChildStr);


       /**
        * @brief Add a grandchild structure entry to the base object.
        *
        * @pre None
        *
        * @post Total object size is updated.
        *
        * @param i_size - input parameter - The size of the grandchild structure
        *
        */
        void addGrandChild(uint32_t i_size);


       /**
        * @brief Add internal data pointer entry to the base object.
        *        When a hypervisor data structure has internal data , an array
        *        of data pointers(hdatHDIFDataHdr_t) is maintained to address
        *        the internal data areas.  This method is used to maintain the
        *        array of data pointers.
        *
        * @pre i_dataPtrCnt from ctor must be greater than 0 (not checked)
        *
        * @post Total object size is updated.  Internal data pointer entry is
        * updated
        *
        * @param i_whichDataEntry -
        *        input parameter - An array index for the data entry being added
        *        This is a 0 based array index so the first entry being added
        *        would specify 0 for this parameter.
        *        i_whichDataEntry < i_dataPtrCnt from ctor (not checked)
        * @param i_size           -
        *        input parameter - The size of the internal data
        *
        */
        void addData(uint32_t i_whichDataEntry,
                     uint32_t i_size);

        /**
         * @brief Some objects which have siblings must all be the same size
         * so thatPHYP can traverse through them as elements of an array. Since
         * the size of all the siblings is not known until the last sibling has
         * been built, this method is used to ensure all objects are padded
         * to the same size
         *
         * @pre None
         * @post Total object size is updated. Pad size computed
         * @param i_numBytes - input parameter - size, in bytes, of the
         *                     maximum sized object
         */

        void maxSiblingSize(uint32_t i_numBytes);



       /**
        * @brief After the derived object is constructed, all data pointers have
        *        been added,and the maximum number of child structures have been
        *        computed, this method must be called to "pad" the object to a
        *        nice byte boundary (currently 16 byte boundaries are used).
        *
        * @pre actual or maximum number of child structures were provided on
        *      the constructor
        *      all calls to addData() have been completed
        *
        * @post Total object size is updated. Pad size computed.
        *
        */
        void align();

        /**
         * @brief The current object size is returned. This is the size of
         * an HDIF object.  It does NOT include sizes of children or
         * grandchildren
         *
         * @pre None
         *
         * @post None
         *
         * @return Object size
         */
         uint32_t size();

         /*
          * @brief  write Hdif header to memory
          *
          * @pre the object must have been constructed
          *
          * @param io_virt_addr input virtual address to write at
          *
          * @post data is written to host memory
          *
          * @return the next address to write at
          *
          */
         uint8_t * setHdif(uint8_t * io_virt_addr);


         /*
          * @brief write the required padding
          *
          * @pre the object must have been constructed
          *
          * @param io_virt_addr input virtual address to write at
          * @param o_size  output size of the object
          * @post pad is written to host memory
          *
          * @return the next address to write at
          */

         uint8_t *setpadding(uint8_t * io_virt_addr,
                             uint32_t& o_size );


         /*
          * @brief get the child offset
          *
          * daughter data must have been constructed
          *
          * return uint32_t offset value
          */

         uint32_t getChildOffset ();
       /**
        * @brief Update the offset to the beginning of a child structure(s)
        *
        *        Complex strcutures which can have grandchilren (such as the
        *        HdatVpd object) may not be able to build the object pieces in
        *        the desired order.  Thus offsets to chilren structures can be
        *        in error.  When the objects are complete and are ready to be
        *        commited, they can be done so in the correct order but the
        *        offsets will have to be updated first.
        *
        * @pre None
        *
        * @post None
        *
        * @param[in] i_whichChildEntry - An array index for the child triple
        *           entry.This is a 0 based array index so the first entry would
        *           specify 0 for this parameter. i_whichChildEntry < i_childCnt
        *           from ctor (not checked)
        * @param[in] i_offset  - new offset value
        *
        * @return None
        *
        */
        void chgChildOffset(uint32_t i_whichChildEntry,
                               uint32_t i_offset);
       /**
        * @brief The object data is written to ms memory
        *
        *
        * @pre The derived object must be complete.
        *
        * @post The base class data is flattened and written to a ms area
        *
        * @param[in]i_data - input memory that contains data
        *
        */
        void startCommit(UtilMem &i_data);

       /**
        * @brief print out the HdatHdif object data
        *
        * @pre None
        *
        * @post output sent to stdout
        *
        */
        void print();

       /**
        * @brief Any padding that must be done to make the structure align
        * properly is performed and the msarea containing the data structure is 
        * not closed.
        *
        * @pre None
        *
        * @post
        *
        * @param[in]i_data - input memory that contains data
        *
        */
        void endCommit(UtilMem &i_data);

       /**
        * @brief Get endCommit size if there is any padding applied
        * @pre None
        *
        * @post
        *
        * @return - size
        */
        uint32_t endCommitSize();

       /**
        * @brief Get the complete size of base object that needs to be written
        * to MS memory
        * @pre None
        *
        * @post
        *
        * @return - size
        */
        uint32_t getSize();



    private:


        /** Object Instance Data
         *
         * @li iv_totalSize      - total number of bytes of structure and all
         *                         its children and grandchildren
         * @li iv_padSize        - number of bytes to pad structure to a
         *                         boundary (such as a nice 16 byte boundary)
         * @li iv_siblingPadSize - the padding to be added
         * @li iv_dataPtrSize    - size of the internal data pointers array
         *                         section
         * @li iv_childPtrSize   - size of the child pointers section
         * @li iv_hdr            - the basic HDIF header
         * @li iv_dataPtrs       - heap storage for the internal data pointers
         *                         section
         * @li iv_childPtrs      - heap storage for the internal child structure
         *                         pointers section
         */
        uint32_t             iv_totalSize;
        uint32_t             iv_padSize;
        uint32_t             iv_siblingPadSize;
        uint32_t             iv_dataPtrSize;
        uint32_t             iv_childPtrSize;
        hdatHDIF_t           iv_hdr;
        hdatHDIFDataHdr_t   *iv_dataPtrs;
        hdatHDIFChildHdr_t  *iv_childPtrs;

}; // end of HdatHdif class

}//end namespace

#endif // HDATHDIF_H
OpenPOWER on IntegriCloud