summaryrefslogtreecommitdiffstats
path: root/src/usr/errl/errlprvt.C
blob: 7ae87b64530184350057bf6b51cae734e5982af6 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/errl/errlprvt.C $                                     */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,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 errlprvt.C
 *
 *  @brief Implemenation of ErrlPrvt, a class for the management
 *  of the Private Header (PH) section of PEL.
 *
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hbotcompid.H>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <arch/ppc.H>



namespace ERRORLOG
{


extern trace_desc_t* g_trac_errl;



/****************************************************************************/
// Constructor for the private header (PH) section of PEL.

ErrlPrvt::ErrlPrvt( compId_t  i_CreatorCompId ) :
    // contruct the ErrlSctnHdr
    iv_header( ERRL_SID_PRIVATE_HEADER,
               ErrlPrvt::SLEN,
               ErrlPrvt::VER,
               ErrlPrvt::SST,
               i_CreatorCompId ),
    iv_created( 0 ),              // created time
    iv_committed( 0 ),            // committed time
    iv_cid( ERRL_CID_HOSTBOOT ),  // 'B' See errlCreator_t in errltypes.H
    iv_sctns( 0 )
{
    // Ask the errl manager for the next ID to assign.
    iv_plid = iv_eid = ERRORLOG::theErrlManager::instance().getUniqueErrId();

    // Set the time of creation.
    // TODO RTC 35258 The field iv_created and iv_committed expect an 8-byte
    // BCD-encoded timestamp.  However, the FSP errl tool does not complain
    // about displaying the timebase value. Perhaps we can apply a transform
    // on time base to get an approximation of real time.
    iv_created = getTB();

}


/*****************************************************************************/
// Data export.
// Flatten the data to the output pointer given as PEL as defined in
// eCLipz and P7 Platform Event Log and SRC PLDD  mcdoc 1675
// Return how many bytes flattened, or else zero for error.


uint64_t ErrlPrvt::flatten( void * o_pBuffer, const uint64_t i_cbBuffer )
{
    uint64_t  l_rc = 0;
    uint64_t  l_cb = 0;

    do
    {

        if( i_cbBuffer < iv_header.iv_slen )
        {
            TRACFCOMP( g_trac_errl, "ErrlPrvt::flatten: buffer too small");
            break;
        }

        CPPASSERT( 48 == sizeof( pelPrivateHeaderSection_t ));

        // See errltypes.H for pelPrivateHeaderSection_t
        pelPrivateHeaderSection_t * p;
        p  = static_cast<pelPrivateHeaderSection_t *>(o_pBuffer);
        memset( p, 0, sizeof( *p ));

        // Get the ErrlSctnHdr to flatten its data first.
        l_cb = iv_header.flatten( &p->sectionheader, i_cbBuffer );
        if( 0 == l_cb )
        {
            // Rare.
            TRACFCOMP(g_trac_errl,"ErrlPrvt::flatten: header.flatten problem");
            break;
        }

        // Set the ErrlPrvt instance data items.
        p->creationTime   = iv_created;
        p->commitTime     = iv_committed;
        p->creatorId      = iv_cid;
        p->sectionCount   = iv_sctns;
        p->plid           = iv_plid;
        p->eid            = iv_eid;

        // return amount of bytes flattened
        l_rc = iv_header.iv_slen;
    }
    while( 0 );

    return l_rc;
}

uint64_t ErrlPrvt::unflatten( const void * i_buf )
{
    const pelPrivateHeaderSection_t * p =
        static_cast<const pelPrivateHeaderSection_t *>(i_buf);

    iv_header.unflatten(&(p->sectionheader));

    iv_created          = p->creationTime;
    iv_committed        = p->commitTime;
    iv_cid              = p->creatorId;
    iv_sctns            = p->sectionCount;
    iv_plid             = p->plid;
    iv_eid              = p->eid;

    return flatSize();
}

} // namespace
OpenPOWER on IntegriCloud