summaryrefslogtreecommitdiffstats
path: root/src/usr/hdat/hdatnodedata.C
blob: 6e735b9f428a16e37f824a38923d529fc6c72bfa (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hdat/hdatnodedata.C $                                 */
/*                                                                        */
/* 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                                                     */
/**
 * @file hdatnodedata.C
 *
 * @brief This file contains the implementation of the HdatNodedata class.
 *    
 */

/*-----------------------------------------------------------------------------*/
/* Includes                                                                    */
/*-----------------------------------------------------------------------------*/

#include <stdlib.h>                 // malloc & free
#include <sys/mm.h>
#include <sys/mmio.h>
#include <util/align.H>
#include "hdatnodedata.H"           // HdatNodedata class definition
#include "hdathdif.H"
#include "hdatutil.H"
#include "hdatvpd.H"
#include <targeting/common/util.H>

using namespace HDAT;
namespace HDAT
{
/*-----------------------------------------------------------------------------*/
/* Global variables                                                            */
/*-----------------------------------------------------------------------------*/
extern trace_desc_t *g_trac_hdat;
uint32_t HdatNodedata::cv_actualCnt;

/** @brief See the prologue in hdatnodedata.H
 */
HdatNodedata::HdatNodedata(errlHndl_t &o_errlHndl,
                 uint64_t &io_msAddr,
                 const char *i_eyeCatcher,
                 uint32_t &o_NodeStructSize)
: HdatHdif(o_errlHndl, i_eyeCatcher, HDAT_NODE_DATA_LAST, 
cv_actualCnt++, HDAT_NO_CHILD, HDAT_NODE_DATA_VERSION)
{
    HDAT_ENTER();
    o_errlHndl = NULL;

    // Copy the mainstore address to object variable
    iv_msAddr  = io_msAddr;

    // Total size of Node Data
    iv_size  = sizeof(hdatHDIF_t) +
                     ( sizeof(hdatHDIFDataHdr_t) *
                       HDAT_NODE_DATA_LAST)+
                       HDAT_NODE_ATTR_DATA_SIZE + 0x08; // padding as per spec

    // Create a virtual address mapping
    uint64_t l_base_addr_down = ALIGN_PAGE_DOWN((uint64_t)iv_msAddr);
    iv_virt_addr =(uint8_t *) mm_block_map (
                            reinterpret_cast<void*>(l_base_addr_down),
                            (ALIGN_PAGE(iv_size) + PAGESIZE));
    iv_hdatNodeData = iv_virt_addr +
            ((uint64_t)iv_msAddr - ALIGN_PAGE_DOWN((uint64_t)iv_msAddr));

    o_NodeStructSize = iv_size;

    // Copy the end adress back to input pointer for next node use
    io_msAddr += iv_size;

    HDAT_EXIT();
    return;
}


/** @brief See the prologue in HdatNodedata.H
 */
errlHndl_t HdatNodedata::setNodeData()
{
    HDAT_ENTER();
    errlHndl_t o_errlHndl=NULL;

    // Add the internal pointer Data
    this->addData(HDAT_NODE_ATTRIBUTE, HDAT_NODE_ATTR_DATA_SIZE);
    this->align();

    // initializing the space to zero
    memset(iv_hdatNodeData ,0x0, iv_size );

    iv_hdatNodeData = this->setHdif(iv_hdatNodeData);

    iv_hdatNodeData += HDAT_NODE_ATTR_DATA_SIZE;

    HDAT_EXIT();
    return o_errlHndl;
}

HdatNodedata::~HdatNodedata()
{
    HDAT_ENTER();

    errlHndl_t o_errlHndl=NULL;
    uint32_t rc =  mm_block_unmap(reinterpret_cast<void*>(
                    ALIGN_PAGE_DOWN((uint64_t)iv_virt_addr)));
    if( rc != 0)
    {
        /*@
        * @errortype
        * @moduleid         HDAT::MOD_HDAT_NODEDATA_DTOR
        * @reasoncode       HDAT::RC_DEV_MAP_FAIL
        * @devdesc          Unmap a mapped region failed
        * @custdesc         Firmware encountered an internal error.
        */
        hdatBldErrLog(o_errlHndl,
                HDAT::MOD_HDAT_NODEDATA_DTOR,
                RC_DEV_MAP_FAIL,
                0,0,0,0,
                ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                HDAT_VERSION1,
                true);
    }
    HDAT_EXIT();

}

}// HDAT namespace
OpenPOWER on IntegriCloud