summaryrefslogtreecommitdiffstats
path: root/src/usr/util/runtime/utillidmgr_rt.C
blob: 397cc60748260c0ccbbc4d1cfcb4db08623b3881 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/util/runtime/utillidmgr_rt.C $                        */
/*                                                                        */
/* 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                                                     */
#include <stdio.h>
#include <algorithm>

#include <util/utillidmgr.H>
#include <util/util_reasoncodes.H>
#include <errl/errlmanager.H>
#include <vfs/vfs.H>
#include <runtime/interface.h>

UtilLidMgr::UtilLidMgr(uint32_t i_lidId) :
    iv_isPnor(false), iv_lidBuffer(NULL), iv_lidSize(0)
{
    updateLid(i_lidId);
}

UtilLidMgr::~UtilLidMgr()
{
    errlHndl_t l_err = NULL;

    l_err = cleanup();
    if(l_err)
    {
        //cleanup errors are extermely rare
        ERRORLOG::errlCommit( l_err, UTIL_COMP_ID );
    }
}

errlHndl_t UtilLidMgr::setLidId(uint32_t i_lidId)
{
    errlHndl_t l_err = NULL;

    //must call cleanup before updateLid
    l_err = cleanup();

    updateLid(i_lidId);

    return l_err;
}

errlHndl_t UtilLidMgr::getLidSize(size_t& o_lidSize)
{
    errlHndl_t l_err = loadLid();
    o_lidSize = iv_lidSize;

    return l_err;
}

errlHndl_t UtilLidMgr::getLid(void* i_dest, size_t i_destSize)
{
    errlHndl_t l_err = loadLid();

    if (iv_lidBuffer != NULL)
    {
        memcpy(i_dest, iv_lidBuffer, std::min(i_destSize, iv_lidSize));
    }

    return l_err;
}

errlHndl_t UtilLidMgr::loadLid()
{
    // Check if it is already loaded.
    if (NULL != iv_lidBuffer) return NULL;

    const char* l_addr = NULL;
    size_t l_size = 0;
    errlHndl_t l_errl = VFS::module_address(iv_lidFileName, l_addr, l_size);

    if (l_errl)
    {
        delete l_errl;
        int rc =
            g_hostInterfaces->lid_load(iv_lidId, &iv_lidBuffer, &iv_lidSize);

        if (0 != rc)
        {
            /*@
             * @errortype       ERRL_SEV_INFORMATIONAL
             * @moduleid        Util::UTIL_LIDMGR_RT
             * @reasoncode      Util::UTIL_LIDMGR_RC_FAIL
             * @userdata1       Return code from lid_load call.
             * @devdesc         Unable to load LID via host interface.
             */
            l_errl = new ERRORLOG::ErrlEntry(
                ERRORLOG::ERRL_SEV_INFORMATIONAL,
                Util::UTIL_LIDMGR_RT,
                Util::UTIL_LIDMGR_RC_FAIL,
                rc);
        }
    }
    else
    {
        iv_isPnor = true;
        iv_lidBuffer = const_cast<void*>(reinterpret_cast<const void*>(l_addr));
        iv_lidSize = l_size;
    }

    return l_errl;
}

errlHndl_t UtilLidMgr::cleanup()
{
    if ((!iv_isPnor) && (NULL != iv_lidBuffer))
    {
        g_hostInterfaces->lid_unload(iv_lidBuffer);
    }
    iv_lidBuffer = NULL;

    iv_lidSize = 0;
    iv_isPnor = false;
    return NULL;
}

void UtilLidMgr::updateLid(uint32_t i_lidId)
{
    iv_lidId = i_lidId;

    //if it's in PNOR, it's not technically lid, so use a slightly
    //different extension.
    sprintf(iv_lidFileName, "%x.lidbin", iv_lidId);

    return;
}
OpenPOWER on IntegriCloud