summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/tod_init/TodSvcUtil.C
blob: ebcb4028986ed825a2350e6d3b1b81a3ebedb375 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/tod_init/TodSvcUtil.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                                                     */

/**
 *  @file TodSvcUtil.C
 *
 *  @brief This file implements the various utility methods
 *
 *  HWP_IGNORE_VERSION_CHECK
 *
 */

#include <targeting/common/attributes.H>
#include <targeting/common/targetservice.H>
#include <tod_init/tod_init_reasoncodes.H>
#include <devicefw/userif.H>

#include "TodTrace.H"
#include "TodSvcUtil.H"

using namespace TARGETING;

namespace TOD {

//******************************************************************************
//logInvalidTodConfig
//******************************************************************************
void logInvalidTodConfig(
        const uint32_t i_config,
        errlHndl_t& io_errHdl)
{
    /*@
     * @errortype
     * @reasoncode   TOD_INVALID_CONFIG
     * @moduleid     TOD_LOG_INVALID_CONFIG
     * @userdata1    The problematic configuration (Primary/Secondary)
     * @devdesc      Error: Erroneous TOD configuration
     *               Possible Causes: Programming issue
     *               Resolution: Development team should be contacted.
     */
     io_errHdl = new ERRORLOG::ErrlEntry(
                        ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                        TOD_LOG_INVALID_CONFIG,
                        TOD_INVALID_CONFIG,
                        i_config, 0);
}

//******************************************************************************
//logUnsupportedOrdinalId
//******************************************************************************
void logUnsupportedOrdinalId(
        const uint32_t i_ordinalId,
        errlHndl_t& io_errHdl)
{
    /*@
     * @errortype
     * @reasoncode   TOD_UNSUPORTED_ORDINALID
     * @moduleid     TOD_LOG_UNSUPORTED_ORDINALID
     * @userdata1    Ordinal Id for which the error is logged
     * @devdesc      Error: The ordinal Id of one of the TOD procs did not fall
     *               in the range 0 <= Ordinal Id < getMaxProcsOnSystem
     *               Possible Causes: TOD logic has not been updated to support
     *               the latest system type where the no. of processor chips is
     *               either equal to or more than getMaxProcsOnSystem
     *               Resolution: Development team should be contacted.
     */
     io_errHdl = new ERRORLOG::ErrlEntry(
                        ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                        TOD_LOG_UNSUPORTED_ORDINALID,
                        TOD_UNSUPORTED_ORDINALID,
                        i_ordinalId, 0 );
}

//******************************************************************************
//getMaxProcsOnSystem()
//******************************************************************************
uint32_t getMaxProcsOnSystem()
{
    Target* sys = NULL;
    targetService().getTopLevelTarget(sys);

    uint8_t l_maxProcs = 0;
    sys->tryGetAttr<ATTR_MAX_PROC_CHIPS_PER_NODE>(l_maxProcs);

    return ( (uint32_t)l_maxProcs );
}

//******************************************************************************
//getMaxPossibleCoresPerProc()
//******************************************************************************
uint32_t  getMaxPossibleCoresPerProc()
{
    Target* sys = NULL;
    targetService().getTopLevelTarget(sys);

    uint8_t l_maxCores = 0;
    sys->tryGetAttr<ATTR_MAX_EXS_PER_PROC_CHIP>(l_maxCores);

    return ( (uint32_t)l_maxCores );
}

//******************************************************************************
//todGetScom()
//******************************************************************************
errlHndl_t todGetScom(const TARGETING::Target * i_target,
                      const uint64_t i_address,
                      ecmdDataBufferBase & o_data)
{
    uint32_t l_ecmdRc;
    errlHndl_t l_err = NULL;

    // Perform SCOM read
    uint64_t l_data = 0;
    size_t l_size = sizeof(uint64_t);

    l_err = deviceRead((TARGETING::Target *)i_target,
                       &l_data,
                       l_size,
                       DEVICE_SCOM_ADDRESS(i_address));

    if (!l_err)
    {
        l_ecmdRc  = o_data.setBitLength(64);
        l_ecmdRc |= o_data.setDoubleWord(0, l_data);
        if (l_ecmdRc)
        {
            /*@
             * @errortype
             * @reasoncode   TOD_ECMD_ERROR
             * @moduleid     TOD_GETSCOM
             * @userdata1    return code from ecmdDataBufferBase operation(s)
             * @devdesc      Scom access error
             */
           l_err = new ERRORLOG::ErrlEntry(
                           ERRORLOG::ERRL_SEV_INFORMATIONAL,
                           TOD_LOG_UNSUPORTED_ORDINALID,
                           TOD_UNSUPORTED_ORDINALID,
                           l_ecmdRc, 0 );
       }
    }

    return l_err;
}

//******************************************************************************
//getFuncNodeTargetsOnSystem
//******************************************************************************
errlHndl_t getFuncNodeTargetsOnSystem(const TARGETING::Target*
        i_pInputTarget, TARGETING::TargetHandleList&
        o_functionalNodeTargetList)
{
    TOD_ENTER("getFuncNodeTargetsOnSystem");
    errlHndl_t l_errHdl = NULL;
    o_functionalNodeTargetList.clear();

    do{
        if (i_pInputTarget == NULL )
        {
            TOD_ERR("NULL target passed in the call to method "
                    "getFuncNodeTargetsOnSystem ");
            /*@
             * @errortype
             * @reasoncode   TOD_NULL_INPUT_TARGET
             * @moduleid     TOD_GETFUNCNODETARGETSONSYSTEM
             * @userdata1    HUID of the target that was validated
             * @devdesc      Scom access error
             */
           l_errHdl = new ERRORLOG::ErrlEntry(
                              ERRORLOG::ERRL_SEV_INFORMATIONAL,
                              TOD_GETFUNCNODETARGETSONSYSTEM,
                              TOD_NULL_INPUT_TARGET );
            break;
        }

        CLASS l_class = i_pInputTarget->getAttr<ATTR_CLASS>();
        TYPE  l_type = i_pInputTarget->getAttr<ATTR_TYPE>();

        if((TARGETING::CLASS_SYS == l_class) &&
                (TARGETING::TYPE_SYS ==  l_type))//System target
        {
            //create the predicate with CLASS_ENC and TYPE_NODE
            TARGETING::PredicateCTM
                l_nodeFilter(TARGETING::CLASS_ENC,TARGETING::TYPE_NODE);

            //Use PredicateIsFunctional to filter only functional nodes
            TARGETING::PredicateIsFunctional    l_isFunctional;
            TARGETING::PredicatePostfixExpr     l_functionalAndNodeFilter;

            l_functionalAndNodeFilter.push(&l_nodeFilter).
                push(&l_isFunctional).And();

            //Create an iterator to loop over the selected targets
            TARGETING::TargetRangeFilter    l_pFuncNode(
                    TARGETING::targetService().begin(),
                    TARGETING::targetService().end(),
                    &l_functionalAndNodeFilter );

            for (  ; l_pFuncNode ; ++l_pFuncNode)
            {
                o_functionalNodeTargetList.push_back(*l_pFuncNode);
            }
        }
        else if ((TARGETING::CLASS_ENC == l_class ) &&
                (TARGETING::TYPE_NODE == l_type )) //Node target
        {
            if (i_pInputTarget->getAttr<ATTR_HWAS_STATE>().functional)
            {
                o_functionalNodeTargetList.push_back(
                        const_cast<TARGETING::Target*>(i_pInputTarget));
            }
            else
            {
                TOD_ERR("Failed to get the functional state for target 0x%08X",
                        i_pInputTarget->getAttr<TARGETING::ATTR_HUID>());
                break;
            }
        }
        else
        {
            TOD_ERR("Invalid target 0x%08X  passed in the call to method "
                    "getFuncNodeTargetsOnSystem ",
                    i_pInputTarget->getAttr<TARGETING::ATTR_HUID>());
            /*@
             * @errortype
             * @reasoncode   TOD_INVALID_TARGET
             * @moduleid     TOD_GETFUNCNODETARGETSONSYSTEM
             * @userdata1    HUID of the target that was validated
             * @devdesc      Scom access error
             */
           l_errHdl = new ERRORLOG::ErrlEntry(
                              ERRORLOG::ERRL_SEV_INFORMATIONAL,
                              TOD_GETFUNCNODETARGETSONSYSTEM,
                              TOD_INVALID_TARGET,
                              i_pInputTarget->getAttr<TARGETING::ATTR_HUID>());
            break;
        }
    }while(0);

    if ( l_errHdl )
    {
        o_functionalNodeTargetList.clear();
    }

    TOD_EXIT("getFuncNodeTargetsOnSystem. errHdl = %p", l_errHdl);
    return l_errHdl;
}

} //End  of namespace TOD
OpenPOWER on IntegriCloud