summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/attn/attntarget.C
blob: 0826ef6ded37197fedd70d45c140d877a33d7419 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/attn/attntarget.C $                              */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,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 attntarget.C
 *
 * @brief HBATTN Target service wrapper class method definitions.
 */

#include "attntarget.H"
#include "attntrace.H"
#include "targeting/common/predicates/predicates.H"
#include "targeting/common/utilFilter.H"
#include <util/singleton.H>

using namespace TARGETING;

namespace ATTN
{

void TargetServiceImpl::getAllChips(
        TARGETING::TargetHandleList & o_list,
        TARGETING::TYPE i_type,
        bool i_functional)
{
    TARGETING::getAllChips(o_list, i_type, i_functional);
}

void TargetServiceImpl::getMcsList(
        TargetHandle_t i_proc,
        TargetHandleList & o_list)
{
    getChildChiplets(o_list, i_proc, TYPE_MCS);
}

TargetHandle_t TargetServiceImpl::getProc(
        TargetHandle_t i_membuf)
{
    TargetHandle_t proc = NULL;

    TargetHandleList list;
    PredicateCTM pred(CLASS_CHIP, TYPE_PROC);

    targetService().getAssociated(
            list,
            i_membuf,
            TARGETING::TargetService::PARENT_BY_AFFINITY,
            TARGETING::TargetService::ALL,
            &pred);

    if(list.size() == 1)
    {
        proc = list[0];
    }

    return proc;
}

TargetHandle_t TargetServiceImpl::getMcs(
        TargetHandle_t i_membuf)
{
    TargetHandle_t mcs = NULL;

    TargetHandleList list;
    PredicateCTM pred(CLASS_UNIT, TYPE_MCS);

    targetService().getAssociated(
            list,
            i_membuf,
            TARGETING::TargetService::PARENT_BY_AFFINITY,
            TARGETING::TargetService::IMMEDIATE,
            &pred);

    if(list.size() == 1)
    {
        mcs = list[0];
    }

    return mcs;
}

TargetHandle_t TargetServiceImpl::getMcs(
        TargetHandle_t i_proc,
        uint64_t i_pos)
{
    PredicateCTM classTypeMatch(CLASS_UNIT, TYPE_MCS);
    PredicateIsFunctional functionalMatch;
    PredicatePostfixExpr pred;

    class ChipUnitMatch : public PredicateBase
    {
        uint8_t iv_pos;

        public:

        bool operator()(const Target * i_target) const
        {
            uint8_t pos;

            bool match = false;

            if(i_target->tryGetAttr<ATTR_CHIP_UNIT>(pos))
            {
                match = iv_pos == pos;
            }

            return match;
        }

        explicit ChipUnitMatch(uint8_t i_pos)
            : iv_pos(i_pos) {}

    } chipUnitMatch(i_pos);

    pred.push(&classTypeMatch).push(
            &functionalMatch).And();

    pred.push(&chipUnitMatch).And();

    TargetHandleList list;
    TargetHandle_t mcs = NULL;

    targetService().getAssociated(
            list,
            i_proc,
            TARGETING::TargetService::CHILD_BY_AFFINITY,
            TARGETING::TargetService::ALL,
            &pred);

    if(list.size() == 1)
    {
        mcs = list[0];
    }

    return mcs;
}

void TargetServiceImpl::getMcsPos(
        TargetHandle_t i_mcs,
        uint64_t & o_pos)
{
    o_pos = i_mcs->getAttr<ATTR_CHIP_UNIT>();
}

TargetHandle_t TargetServiceImpl::getMembuf(
        TargetHandle_t i_mcs)
{
    TargetHandle_t membuf = NULL;

    TargetHandleList list;
    getChildAffinityTargets(list, i_mcs, CLASS_CHIP, TYPE_MEMBUF);

    if(list.size() == 1)
    {
        membuf = list[0];
    }

    return membuf;
}

bool TargetServiceImpl::getAttribute(
        ATTRIBUTE_ID i_attribute,
        TargetHandle_t i_target,
        uint64_t & o_val)
{
    bool found = false;
    uint8_t u8;

    switch (i_attribute)
    {
        case ATTR_FABRIC_NODE_ID:

            found = i_target->tryGetAttr<ATTR_FABRIC_NODE_ID>(u8);
            o_val = u8;

            break;

        case ATTR_FABRIC_CHIP_ID:

            found = i_target->tryGetAttr<ATTR_FABRIC_CHIP_ID>(u8);
            o_val = u8;

            break;

        default:

            break;
    }

    return found;
}

TYPE TargetServiceImpl::getType(TargetHandle_t i_target)
{
    return i_target->getAttr<ATTR_TYPE>();
}

TargetServiceImpl::~TargetServiceImpl()
{
    // restore the default

    getTargetService().setImpl(Singleton<TargetServiceImpl>::instance());

    TargetService & wrapper = getTargetService();
    TargetServiceImpl * defaultImpl = &Singleton<TargetServiceImpl>::instance();

    if(wrapper.iv_impl == this)
    {
        if(this != defaultImpl)
        {
            wrapper.setImpl(*defaultImpl);
        }
    }
}

TargetService & getTargetService()
{
    return Singleton<TargetService>::instance();
}
}
OpenPOWER on IntegriCloud