summaryrefslogtreecommitdiffstats
path: root/src/usr/hwas/hwas.C
blob: b77c37dd13bf88d78d3864db81d9c361127fe9cf (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
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/usr/hwas/hwas.C $
//
//  IBM CONFIDENTIAL
//
//  COPYRIGHT International Business Machines Corp. 2011
//
//  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 other-
//  wise divested of its trade secrets, irrespective of what has
//  been deposited with the U.S. Copyright Office.
//
//  Origin: 30
//
//  IBM_PROLOG_END

/**
 *  @file hwas.C
 *
 *  HardWare Availability Service functions.
 *  See hwas.H for doxygen documentation tags.
 *
 */


/******************************************************************************/
// Includes
/******************************************************************************/
#include    <stdint.h>
#include    <assert.h>

#include    <targeting/targetservice.H>
#include    <targeting/iterators/rangefilter.H>
#include    <targeting/predicates/predicates.H>
#include    <targeting/util.H>

#include    <hwas/hwas.H>
#include    <hwas/hwasCommon.H>

namespace   HWAS
{

using   namespace   TARGETING;


//@todo - This should come from the target/attribute code somewhere
uint64_t target_to_uint64(const Target* i_target)
{
    uint64_t id = 0;
    if (i_target == NULL)
    {
        id = 0x0;
    }
    else if (i_target == MASTER_PROCESSOR_CHIP_TARGET_SENTINEL)
    {
        id = 0xFFFFFFFFFFFFFFFF;
    }
    else
    {
        // physical path, 3 nibbles per type/instance pair
        //   TIITIITII... etc.
        EntityPath epath;
        i_target->tryGetAttr<ATTR_PHYS_PATH>(epath);
        for (uint32_t x = 0; x < epath.size(); x++)
        {
            id = id << 12;
            id |= (uint64_t)((epath[x].type << 8) & 0xF00);
            id |= (uint64_t)(epath[x].instance & 0x0FF);
        }
    }
    return id;
}


/**
 * @brief       simple helper function to get and set hwas to clear state
 *
 * @param[in]   i_target    pointer to target that we're looking at
 *
 * @return      none
 */
void clearHwasState(Target * i_target)
{
    HwasState hwasState             = i_target->getAttr<ATTR_HWAS_STATE>();
    hwasState.poweredOn             = false;
    hwasState.present               = false;
    hwasState.functional            = false;
    hwasState.changedSinceLastIPL   = false;
    hwasState.gardLevel             = 0;
    i_target->setAttr<ATTR_HWAS_STATE>(hwasState);
}

/**
 * @brief       simple helper fn to get and set hwas state to poweredOn,
 *                  present, functional
 *
 * @param[in]   i_target    pointer to target that we're looking at
 *
 * @return      none
 *
 */
void enableHwasState(Target *i_target)
{
    HwasState hwasState     = i_target->getAttr<ATTR_HWAS_STATE>();
    hwasState.poweredOn     = true;
    hwasState.present       = true;
    hwasState.functional    = true;
    i_target->setAttr<ATTR_HWAS_STATE>( hwasState );
}

errlHndl_t discoverTargets()
{
    HWAS_DBG("discoverTargets entry");
    errlHndl_t errl = NULL;

    //  loop through all the targets and set HWAS_STATE to a known default
    for (TargetIterator target = targetService().begin();
            target != targetService().end();
            ++target)
    {
        clearHwasState(*target);
    }

    // ASSUMPTIONS: Physical hierarchy is:
    // CLASS_SYS (exactly 1)
    //  \->children: CLASS_ENC
    //     \->children: CLASS_* where ALL require hardware query
    //        \->children: CLASS_* where NONE require hardware query

    // find CLASS_SYS (the top level target)
    Target* pSys;
    targetService().getTopLevelTarget(pSys);

    do
    {
        if (pSys == NULL)
        {
            // shouldn't happen; if it does, then we're done - nothing present.
            HWAS_ERR("pSys NULL - nothing present");
            break; // break out of the do/while so that we can return
        }

        // mark this as present
        enableHwasState(pSys);
        HWAS_DBG("pSys   %x (%p) %x/%x - marked present",
            target_to_uint64(pSys), pSys,
            pSys->getAttr<ATTR_CLASS>(), pSys->getAttr<ATTR_TYPE>());

        // find CLASS_ENC
        PredicateCTM predEnc(CLASS_ENC);
        TargetHandleList pEncList;
        targetService().getAssociated( pEncList, pSys,
            TargetService::CHILD, TargetService::ALL, &predEnc );

        for (TargetHandleList::iterator pEnc_it = pEncList.begin();
                pEnc_it != pEncList.end();
                pEnc_it++)
        {
            TargetHandle_t pEnc = *pEnc_it;

            // mark it as present
            enableHwasState(pEnc);
            HWAS_DBG("pEnc   %x (%p) %x/%x - marked present",
                target_to_uint64(pEnc), pEnc,
                pEnc->getAttr<ATTR_CLASS>(), pEnc->getAttr<ATTR_TYPE>());

            // now find the physical children
            TargetHandleList pChildList;
            targetService().getAssociated(pChildList, pEnc,
                TargetService::CHILD, TargetService::IMMEDIATE);

            // pass this list of children to the hwas common api
            // pChildList will be modified to only have present targets
            HWAS_DBG("pChildList size before %d", pChildList.size());
            errl = platPresenceDetect(pChildList);
            HWAS_DBG("pChildList size after %d", pChildList.size());

            if (errl != NULL)
            {
                break; // get out of the pEnc loop
            }

            // read Chip ID/EC data from these physical chips, since they
            //  are present
            errl = platReadIDEC(pChildList);

            if (errl != NULL)
            {
                break; // get out of the pEnc loop
            }

            // no errors - keep going

            // at this point, pChildList only has present targets
            // for each, mark them and their descendants as present
            for (TargetHandleList::iterator pChild_it = pChildList.begin();
                    pChild_it != pChildList.end();
                    pChild_it++)
            {
                TargetHandle_t pChild = *pChild_it;

                // set HWAS state to show it's present
                enableHwasState(pChild);
                HWAS_DBG("pChild %x (%p) %x/%x - detected present",
                    target_to_uint64(pChild), pChild,
                    pChild->getAttr<ATTR_CLASS>(),
                    pChild->getAttr<ATTR_TYPE>());

                // now need to mark all of this target's
                //  physical descendants as present
                TargetHandleList pDescList;
                targetService().getAssociated( pDescList, pChild,
                    TargetService::CHILD, TargetService::ALL);
                for (TargetHandleList::iterator pDesc_it = pDescList.begin();
                        pDesc_it != pDescList.end();
                        pDesc_it++)
                {
                    TargetHandle_t pDesc = *pDesc_it;
                    enableHwasState(pDesc);
                    HWAS_DBG("pDsnds %x (%p) %x/%x - marked present",
                        target_to_uint64(pDesc), pDesc,
                        pDesc->getAttr<ATTR_CLASS>(),
                        pDesc->getAttr<ATTR_TYPE>());
                }
            } // for pChild_it
        } // for pEnc_it
    } while (0);

    if (errl != NULL)
    {
        HWAS_ERR("returning errl %p", errl);
    }
    return errl;
} // discoverTargets

};   // end namespace

OpenPOWER on IntegriCloud