summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/plat/fapiPlatTarget.C
blob: 54ea0770c564b7c6224b8955b08888ee11448b03 (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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/plat/fapiPlatTarget.C $                          */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2011,2014              */
/*                                                                        */
/* 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 platTarget.C
 *
 *  @brief Implements the platform part of the Target class.
 *
 *  Note that platform code must provide the implementation.
 *
 *  FAPI has provided a default implementation for platforms that use the
 *  handle pointer to point to a Component that is not created/deleted when a
 *  Target object is created/deleted (i.e. two Target objects that reference
 *  the same component have the same pointer). It could be possible for a
 *  platform specific ID structure to be created and pointed to each time a new
 *  Target is created, in that case, the pointed to object's type needs to be
 *  be known in order to do a deep compare/copy and a delete.
 */

#include <fapiTarget.H>
#include <fapiPlatTrace.H>
#include <fapiUtil.H>
#include <targeting/common/attributes.H>
#include <string.h>

namespace fapi
{

//******************************************************************************
// Compare the handle
//
// If the pointers point to the same component then the handles are the same
//******************************************************************************
bool Target::compareHandle(const Target & i_right) const
{
    return (iv_pHandle == i_right.iv_pHandle);
}

//******************************************************************************
// Copy the handle
//
// Note shallow copy of iv_pHandle. Both Targets point to the same component
//******************************************************************************
void Target::copyHandle(const Target & i_right)
{
    iv_pHandle = i_right.iv_pHandle;
}

//******************************************************************************
// Delete the handle
//******************************************************************************
void Target::deleteHandle()
{
    // Intentionally does nothing. The component must not be deleted
}

//******************************************************************************
// Get the ecmd-format string
//******************************************************************************
const char * Target::toEcmdString() const
{
    if (iv_pEcmdString == NULL)
    {
        iv_pEcmdString = reinterpret_cast<char(*)>(
                fapiMalloc(fapi::MAX_ECMD_STRING_LEN * sizeof(char)));
        char (&l_ecmdString)[fapi::MAX_ECMD_STRING_LEN] =
            *(reinterpret_cast<char(*)[fapi::MAX_ECMD_STRING_LEN]>
                (iv_pEcmdString));
        toString(l_ecmdString);
    }

    return iv_pEcmdString;
}

//******************************************************************************
// Get the ECMD String
//******************************************************************************
void Target::toString(char (&o_ecmdString)[MAX_ECMD_STRING_LEN]) const
{
    // Extract the Targeting target pointer
    TARGETING::Target* l_pTarget =
        reinterpret_cast<TARGETING::Target*>(iv_pHandle);

    if (l_pTarget == NULL)
    {
        FAPI_ERR("toString: Called on NULL target");
        strcpy(o_ecmdString, "ecmd-no-target");
    }
    else
    {
        // TODO. RTC 98421
        // This is a temporary function that constructs the ECMD String from the
        // target's physical path attribute, eventually, the ECMD String will be
        // its own attribute (sourced from the MRW) and this function will be
        // changed to simply get the attribute

        // Try to get the physical path attribute
        TARGETING::EntityPath l_path;
        if (l_pTarget->tryGetAttr<TARGETING::ATTR_PHYS_PATH>(l_path))
        {
            uint32_t l_sizePath = l_path.size();

            // This function returns the ecmd string for chips and chiplets. The
            // output string is:
            // Chiplet: <chip>.<unit> kX:nX:sX:pXX:cX
            // Chip:    <chip> kX:nX:sX:pXX
            // There is officially a tab character between ">" and "k", this is
            // replaced with the number of spaces seen in the Cronus trace
            // If the k.. string is less than 19 chars, it is padded to 19 chars
            //
            // <chip> = chip type ("p8" = processor, "centaur" = memory buffer)
            // <unit> = unit type ("ex", "mcs", "mba", "abus", "xbus")
            // kX     = cage number. Always zero
            // nX     = node number. Always zero (right now)
            // sX     = slot number. Always zero
            // pXX    = chip position
            // cX     = unit position
            //
            // Examples:
            //   "p8 k0:n0:s0:p01       "
            //   "p8.ex      k0:n0:s0:p01:c0    "
            //   "p8.mcs     k0:n0:s0:p01:c0    "
            //   "centaur    k0:n0:s0:p01       "
            const char * const ECMD_CHIP_PROC = "p8";
            const char * const ECMD_CHIP_PROC_SPC = " ";
            const char * const ECMD_CHIP_MEMBUF = "centaur";
            const char * const ECMD_CHIP_MEMBUF_SPC = "    ";
            const char * const ECMD_CHIPLET_EX   = "ex      ";
            const char * const ECMD_CHIPLET_MCS  = "mcs     ";
            const char * const ECMD_CHIPLET_MBA  = "mba     ";
            const char * const ECMD_CHIPLET_XBUS = "xbus    ";
            const char * const ECMD_CHIPLET_ABUS = "abus    ";
            const int K_STRING_LEN = 19;

            // Look for a chip in the path
            const char * l_pChipType = NULL;
            const char * l_pChipTypeSpc = NULL;
            uint32_t l_chipPos = 0;

            for (uint32_t i = 0; ((i < l_sizePath) && (l_pChipType == NULL));
                 i++)
            {
                if (l_path[i].type == TARGETING::TYPE_PROC)
                {
                    l_pChipType = ECMD_CHIP_PROC;
                    l_pChipTypeSpc = ECMD_CHIP_PROC_SPC;
                    l_chipPos = l_path[i].instance;
                }
                else if (l_path[i].type == TARGETING::TYPE_MEMBUF)
                {
                    l_pChipType = ECMD_CHIP_MEMBUF;
                    l_pChipTypeSpc = ECMD_CHIP_MEMBUF_SPC;
                    l_chipPos = l_path[i].instance;
                }
            }

            if (l_pChipType == NULL)
            {
                FAPI_ERR("toString: Physical Path does not contain known chip");
                strcpy(o_ecmdString, "ecmd-no-chip");
            }
            else
            {
                // Look for the last chiplet in the path (some chiplets are
                // children of other chiplets in PHYS_PATH e.g. MBS->MBA)
                const char * l_pChipletType = NULL;
                uint32_t l_chipletPos = 0;

                for (int32_t i = l_sizePath - 1;
                     ((i >= 0) && (l_pChipletType == NULL));
                     i--)
                {
                    if (l_path[i].type == TARGETING::TYPE_EX)
                    {
                        l_pChipletType = ECMD_CHIPLET_EX;
                        l_chipletPos = l_path[i].instance;
                    }
                    else if (l_path[i].type == TARGETING::TYPE_MCS)
                    {
                        l_pChipletType = ECMD_CHIPLET_MCS;
                        l_chipletPos = l_path[i].instance;
                    }
                    else if (l_path[i].type == TARGETING::TYPE_MBA)
                    {
                        l_pChipletType = ECMD_CHIPLET_MBA;
                        l_chipletPos = l_path[i].instance;
                    }
                    else if (l_path[i].type == TARGETING::TYPE_XBUS)
                    {
                        l_pChipletType = ECMD_CHIPLET_XBUS;
                        l_chipletPos = l_path[i].instance;
                    }
                    else if (l_path[i].type == TARGETING::TYPE_ABUS)
                    {
                        l_pChipletType = ECMD_CHIPLET_ABUS;
                        l_chipletPos = l_path[i].instance;
                    }
                }

                // Construct the ecmd string
                char * l_pStr = &o_ecmdString[0];

                // Chip Type
                strcpy(l_pStr, l_pChipType);
                l_pStr += strlen(l_pChipType);

                if (l_pChipletType != NULL)
                {
                    // Chiplet Type
                    *l_pStr = '.';
                    l_pStr++;

                    strcpy(l_pStr, l_pChipletType);
                    l_pStr += strlen(l_pChipletType);
                }
                else
                {
                    strcpy(l_pStr, l_pChipTypeSpc);
                    l_pStr += strlen(l_pChipTypeSpc);
                }

                // Middle of the string
                strcpy(l_pStr, "k0:n0:s0:p");
                l_pStr += strlen("k0:n0:s0:p");
                int l_kstringlen = strlen("k0:n0:s0:p");

                // Chip Pos.
                int l_num = sprintf(l_pStr, "%02d", l_chipPos);
                l_pStr += l_num;
                l_kstringlen += l_num;

                if (l_pChipletType != NULL)
                {
                    // Chiplet Pos
                    strcpy(l_pStr, ":c");
                    l_pStr += strlen(":c");
                    l_kstringlen += strlen(":c");
                    int l_num = sprintf(l_pStr, "%d", l_chipletPos);
                    l_pStr += l_num;
                    l_kstringlen += l_num;
                }

                // Pad the k-string to K_STRING_LEN characters
                while (l_kstringlen < K_STRING_LEN)
                {
                    *l_pStr = ' ';
                    l_pStr++;
                    l_kstringlen++;
                }

                *l_pStr = '\0';
            }
        }
        else
        {
            FAPI_ERR("toString: Physical Path Attribute does not exist");
            strcpy(o_ecmdString, "ecmd-no-path");
        }
    }
}

}

OpenPOWER on IntegriCloud