summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/nest/p9_query_mssinfo.C
blob: 3309552eca42d0ad60f3728d26d4ed5564ae2b71 (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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/nest/p9_query_mssinfo.C $  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016                             */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */


//----------------------------------------------------------------------
//  FAPI function Includes
//----------------------------------------------------------------------

#include <fapi2.H>
#include <string>
#include <vector>
#include <p9_query_mssinfo.H>

//----------------------------------------------------------------------
//  Constants
//----------------------------------------------------------------------
class cage_node
{
    public:
        uint32_t nodeNum;
        uint32_t cageNum;
        uint32_t slotNum;
};


fapi2::ReturnCode p9_query_mssinfo(const std::vector<fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>> i_vect_pu_targets,
                                   bool i_ignore_ready_check)
{
    fapi2::ReturnCode l_rc;
    uint32_t vect_idx;

    //vars for node and total system sizes
    cage_node curCageNode, puCageNode;
    std::vector<uint64_t> nodeMemSize;
    std::vector<cage_node> nodeNum;
    uint64_t totalSysMem = 0;
    curCageNode.cageNum = 999;
    curCageNode.nodeNum = 999;
    curCageNode.slotNum = 999;
    uint64_t curNodeSize = 0;

    //vars for attrs
    uint64_t sizes[8];
    uint64_t bases[8];
    uint64_t mirror_sizes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
    uint64_t mirror_bases[8] = {0, 0, 0, 0, 0, 0, 0, 0};
    uint32_t groupID[MBA_GROUP_SIZE][MBA_GROUP_DATA];
    uint64_t nhtm_base;
    uint64_t nhtm_size;
    uint64_t chtm_bases[24];
    uint64_t chtm_sizes[24];
    uint64_t smf_base;
    uint64_t smf_size;
    uint64_t occ_base;
    uint64_t occ_size;
    uint8_t  mirror_policy;
    uint8_t  l_mirrorEnabled;
    char     chipid[200];
    char l_target_string[fapi2::MAX_ECMD_STRING_LEN];


    const int ONE_GIG = 30;

    FAPI_DBG("i_vect_pu_targets.size(): %d", i_vect_pu_targets.size());

    //loop over all elements in the vector
    for(uint32_t i = 0; i < i_vect_pu_targets.size(); i++)
    {
        if (!i_ignore_ready_check)
        {
            uint8_t l_mem_ipl_complete;
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_MSS_MEM_IPL_COMPLETE, i_vect_pu_targets[i], l_mem_ipl_complete),
                     "Error from FAPI_ATTR_GET (ATTR_MSS_MEM_IPL_COMPLETE)");
            FAPI_ASSERT(l_mem_ipl_complete,
                        fapi2::P9_QUERY_MSSINFO_NOT_READY_ERR().set_TARGET(i_vect_pu_targets[i]),
                        "IPL IS NOT COMPLETE. Unable to determine final memory sizes and addreses!");
        }

        fapi2::toString(i_vect_pu_targets[i], l_target_string, fapi2::MAX_ECMD_STRING_LEN );   //change to ecmd string
        sprintf(chipid, "%s", l_target_string);
        int x = 0;
        puCageNode.cageNum = 0;
        puCageNode.nodeNum = 0;
        puCageNode.slotNum = 0;

        while(chipid[x] != 'k' && chipid[x] != '\0')
        {
            x++;
        }

        if(chipid[x] == 'k')
        {
            x++;
        }

        while(chipid[x] != '\0')
        {
            if(chipid[x] == ':')
            {
                break;
            }

            puCageNode.cageNum = puCageNode.cageNum * 10 + chipid[x] - '0';
            x++;
        }

        while(chipid[x] != 'n' && chipid[x] != '\0')
        {
            x++;
        }

        if(chipid[x] == 'n')
        {
            x++;
        }

        while(chipid[x] != '\0')
        {
            if(chipid[x] == ':')
            {
                break;
            }

            puCageNode.nodeNum = puCageNode.nodeNum * 10 + chipid[x] - '0';
            x++;
        }

        while(chipid[x] != 's' && chipid[x] != '\0')
        {
            x++;
        }

        if(chipid[x] == 's')
        {
            x++;
        }

        while(chipid[x] != '\0')
        {
            if(chipid[x] == ':')
            {
                break;
            }

            puCageNode.slotNum = puCageNode.slotNum * 10 + chipid[x] - '0';
            x++;
        }


        if( (curCageNode.cageNum != 999) && (curCageNode.cageNum != puCageNode.cageNum &&
                                             curCageNode.nodeNum != puCageNode.nodeNum ) )
        {
            nodeMemSize.push_back(curNodeSize);
            nodeNum.push_back(curCageNode);
            curNodeSize = 0;
        }

        //set current node
        curCageNode = puCageNode;

        //------------------------------------------------------------------------------------------------------------------------
        //  Here is where you use the targets to do some get attributes and print out whatever croquery msinfo need to
        //------------------------------------------------------------------------------------------------------------------------
        // ATTR_PROC_MEM_SIZES
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_MEM_SIZES, i_vect_pu_targets[i], sizes),
                 "Error reading ATTR_PROC_MEM_SIZES, l_rc 0x%.8X",
                 (uint64_t)fapi2::current_err);

        // ATTR_PROC_MEM_BASES
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_MEM_BASES, i_vect_pu_targets[i], bases),
                 "Error reading ATTR_PROC_MEM_BASES, l_rc 0x%.8X",
                 (uint64_t)fapi2::current_err);

        // ATTR_MSS_MCS_GROUP_32
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_MSS_MCS_GROUP_32, i_vect_pu_targets[i], groupID),
                 "Error reading ATTR_MSS_MCS_GROUP_32, l_rc 0x%.8X",
                 (uint64_t)fapi2::current_err);

        //Mirrored memory attributes read if enabled
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_MRW_HW_MIRRORING_ENABLE,
                               i_vect_pu_targets[i].getParent<fapi2::TARGET_TYPE_SYSTEM>(), l_mirrorEnabled),
                 "Error reading ATTR_MRW_HW_MIRRORING_ENABLE, l_rc 0x%.8X",
                 (uint64_t)fapi2::current_err);

        FAPI_DBG("p9_query_mssinfo: Current l_mirrorEnabled=%u!\n", l_mirrorEnabled);

        // retrieve mirroring placement policy attribute
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_MEM_MIRROR_PLACEMENT_POLICY,
                               i_vect_pu_targets[i].getParent<fapi2::TARGET_TYPE_SYSTEM>(), mirror_policy),
                 "Error reading ATTR_MEM_MIRROR_PLACEMENT_POLICY, l_rc 0x%.8X",
                 (uint64_t)fapi2::current_err);

        FAPI_DBG("p9_query_mssinfo: Current mirror_policy=%u!\n", mirror_policy);


        if (l_mirrorEnabled != fapi2::ENUM_ATTR_MRW_HW_MIRRORING_ENABLE_FALSE)
        {
            // ATTR_PROC_MIRROR_SIZES
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_MIRROR_SIZES, i_vect_pu_targets[i], mirror_sizes),
                     "Error reading ATTR_PROC_MIRROR_SIZES, l_rc 0x%.8X",
                     (uint64_t)fapi2::current_err);

            // ATTR_PROC_MIRROR_BASES
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_MIRROR_BASES, i_vect_pu_targets[i], mirror_bases),
                     "Error reading ATTR_PROC_MIRROR_BASES, l_rc 0x%.8X",
                     (uint64_t)fapi2::current_err);
        }


        bool any_mem = false;

        for (int j = 0; (j < 8) && !any_mem; j++)
        {
            if (groupID[j][2] != 0)
            {
                any_mem = true;
            }
        }

        for (int j = 0; (j < 4) && !any_mem; j++)
        {
            if (groupID[8 + j][2] != 0)
            {
                any_mem = true;
            }
        }


        //------------------------------------------------------------------------------------------------------------------------
        // Print out per group information
        //------------------------------------------------------------------------------------------------------------------------
        if (any_mem)
        {
            printf("\n%s\n", chipid);

            for(int j = 0; j < 8; j++)
            {
                if ((sizes[j] != 0) ||
                    ((mirror_sizes[j] != 0)))
                {
                    printf("Group:%d (", j);

                    for(uint8_t jj = 4; jj < 4 + groupID[j][1]; jj++)
                    {
                        printf(" mcs%d", groupID[j][jj]);
                    }

                    printf(" )\n");
                }

                if (sizes[j] != 0)
                {
                    if (mirror_policy == fapi2::ENUM_ATTR_MEM_MIRROR_PLACEMENT_POLICY_NORMAL)
                    {
                        curNodeSize += (sizes[j] >> ONE_GIG);
                    }

#ifdef _LP64
                    printf("  Base Address = 0x%016lx  Size = %ld (GB)\n", bases[j], sizes[j] >> ONE_GIG);
#else
                    printf("  Base Address = 0x%016llx  Size = %lld (GB)\n", bases[j], sizes[j] >> ONE_GIG);
#endif
                }


                if ((mirror_sizes[j] != 0))
                {
                    if (mirror_policy == fapi2::ENUM_ATTR_MEM_MIRROR_PLACEMENT_POLICY_FLIPPED)
                    {
                        curNodeSize += (mirror_sizes[j] >> ONE_GIG);
                    }

#ifdef _LP64
                    printf("  Mirror Base Address = 0x%016lx  Size = %ld (GB)\n", mirror_bases[j], mirror_sizes[j] >> ONE_GIG);
#else
                    printf("  Mirror Base Address = 0x%016llx  Size = %lld (GB)\n", mirror_bases[j], mirror_sizes[j] >> ONE_GIG);
#endif
                }

            }
        }

        //------------------------------------------------------------------------------------------------------------------------
        // Print out memory reservations
        //------------------------------------------------------------------------------------------------------------------------
        if((mirror_policy == fapi2::ENUM_ATTR_MEM_MIRROR_PLACEMENT_POLICY_NORMAL ) ||
           (mirror_policy == fapi2::ENUM_ATTR_MEM_MIRROR_PLACEMENT_POLICY_FLIPPED))
        {
            // ATTR_PROC_NHTM_BAR_BASE_ADDR: Get Nest Hardware Trace Macro (NHTM) bar base addr
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_NHTM_BAR_BASE_ADDR, i_vect_pu_targets[i], nhtm_base),
                     "Error reading ATTR_PROC_NHTM_BAR_BASE_ADDR, l_rc 0x%.8X",
                     (uint64_t)fapi2::current_err);

            // ATTR_PROC_NHTM_BAR_SIZE: Get Nest Hardware Trace Macro (NHTM) bar size
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_NHTM_BAR_SIZE, i_vect_pu_targets[i], nhtm_size),
                     "Error reading ATTR_PROC_NHTM_BAR_SIZE, l_rc 0x%.8X",
                     (uint64_t)fapi2::current_err);

            // ATTR_PROC_CHTM_BAR_BASE_ADDR: Get Nest Hardware Trace Macro (CHTM) bar base addr array
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_CHTM_BAR_BASE_ADDR, i_vect_pu_targets[i], chtm_bases),
                     "Error reading ATTR_PROC_CHTM_BAR_BASE_ADDR, l_rc 0x%.8X",
                     (uint64_t)fapi2::current_err);

            // ATTR_PROC_CHTM_BAR_SIZES: Get Core Hardware Trace Macro (CHTM) bar size array
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_CHTM_BAR_SIZES, i_vect_pu_targets[i], chtm_sizes),
                     "Error reading ATTR_PROC_CHTM_BAR_SIZES, l_rc 0x%.8X",
                     (uint64_t)fapi2::current_err);

            // ATTR_PROC_SMF_BAR_BASE_ADDR: Get Secure Memory Facility (SMF) bar base addr
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_SMF_BAR_BASE_ADDR, i_vect_pu_targets[i], smf_base),
                     "Error reading ATTR_PROC_SMF_BAR_BASE_ADDR, l_rc 0x%.8X",
                     (uint64_t)fapi2::current_err);

            // ATTR_PROC_SMF_BAR_SIZE: Get Secure Memory Facility (SMF) bar size
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_SMF_BAR_SIZE, i_vect_pu_targets[i], smf_size),
                     "Error reading ATTR_PROC_SMF_BAR_SIZE, l_rc 0x%.8X",
                     (uint64_t)fapi2::current_err);

            // ATTR_PROC_OCC_SANDBOX_BASE_ADDR
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_OCC_SANDBOX_BASE_ADDR, i_vect_pu_targets[i], occ_base),
                     "Error reading ATTR_PROC_OCC_SANDBOX_BASE_ADDR, l_rc 0x%.8X",
                     (uint64_t)fapi2::current_err);

            // ATTR_PROC_OCC_SANDBOX_SIZE
            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_OCC_SANDBOX_SIZE, i_vect_pu_targets[i], occ_size),
                     "Error reading ATTR_PROC_OCC_SANDBOX_SIZE, l_rc 0x%.8X",
                     (uint64_t)fapi2::current_err);

            uint64_t  chtm_total_size = 0;

            for (uint8_t i = 0; i < CHTM_REGIONS; i++)
            {
                chtm_total_size += chtm_sizes[i];
            }

            if ((nhtm_size != 0) ||
                (chtm_total_size != 0) ||
                (smf_size != 0) ||
                (occ_size != 0))
            {
                printf("\n");
            }

            if (occ_size != 0)
            {
                std::string suffix = "B";

                if (occ_size >= (1024 * 1024 * 1024))
                {
                    suffix = "GB";
                    occ_size /= (1024 * 1024 * 1024);
                }
                else if (occ_size >= (1024 * 1024))
                {
                    suffix = "MB";
                    occ_size /= (1024 * 1024);
                }
                else if (occ_size >= (1024))
                {
                    suffix = "KB";
                    occ_size /= (1024);
                }

#ifdef _LP64
                printf("OCC Base Address = 0x%016lx  Size = %ld (%s)\n", occ_base, occ_size, suffix.c_str());
#else
                printf("OCC Base Address = 0x%016llx  Size = %lld (%s)\n", occ_base, occ_size, suffix.c_str());
#endif
            }

            if (nhtm_size != 0)
            {
                std::string suffix = "B";

                if (nhtm_size >= (1024 * 1024 * 1024))
                {
                    suffix = "GB";
                    nhtm_size /= (1024 * 1024 * 1024);
                }
                else if (nhtm_size >= (1024 * 1024))
                {
                    suffix = "MB";
                    nhtm_size /= (1024 * 1024);
                }
                else if (nhtm_size >= (1024))
                {
                    suffix = "KB";
                    nhtm_size /= (1024);
                }

#ifdef _LP64
                printf("NHTM Base Address = 0x%016lx  Size = %ld (%s)\n", nhtm_base, nhtm_size, suffix.c_str());
#else
                printf("NHTM Base Address = 0x%016llx  Size = %lld (%s)\n", nhtm_base, nhtm_size, suffix.c_str());
#endif
            }

            if (chtm_total_size != 0)
            {
                for (uint8_t i = 0; i < CHTM_REGIONS; i++)
                {
                    std::string suffix = "B";

                    if (chtm_sizes[i] >= (1024 * 1024 * 1024))
                    {
                        suffix = "GB";
                        chtm_sizes[i] /= (1024 * 1024 * 1024);
                    }
                    else if (chtm_sizes[i] >= (1024 * 1024))
                    {
                        suffix = "MB";
                        chtm_sizes[i] /= (1024 * 1024);
                    }
                    else if (chtm_sizes[i] >= (1024))
                    {
                        suffix = "KB";
                        chtm_sizes[i] /= (1024);
                    }

#ifdef _LP64
                    printf("CHTM Base Address = 0x%016lx  Size = %ld (%s)\n", chtm_bases[i], chtm_sizes[i], suffix.c_str());
#else
                    printf("CHTM Base Address = 0x%016llx  Size = %lld (%s)\n", chtm_bases[i], chtm_sizes[i], suffix.c_str());
#endif
                }
            }

            if (smf_size != 0)
            {
                std::string suffix = "B";

                if (smf_size >= (1024 * 1024 * 1024))
                {
                    suffix = "GB";
                    smf_size /= (1024 * 1024 * 1024);
                }
                else if (smf_size >= (1024 * 1024))
                {
                    suffix = "MB";
                    smf_size /= (1024 * 1024);
                }
                else if (smf_size >= (1024))
                {
                    suffix = "KB";
                    smf_size /= (1024);
                }

#ifdef _LP64
                printf("SMF Base Address = 0x%016lx  Size = %ld (%s)\n", smf_base, smf_size, suffix.c_str());
#else
                printf("SMF Base Address = 0x%016llx  Size = %lld (%s)\n", smf_base, smf_size, suffix.c_str());
#endif
            }

        }

        //------------------------------------------------------------------------------------------------------------------------

    }//end for loop over target vector


    //need to push the last node onto the vector
    if(curCageNode.cageNum != 999)
    {
        nodeMemSize.push_back(curNodeSize);
        nodeNum.push_back(curCageNode);
    }



    //------------------------------------------------------------------------------------------------------------------
    // Print out node and total system memory
    //------------------------------------------------------------------------------------------------------------------
    printf("\n");

    for(vect_idx = 0; vect_idx < nodeNum.size(); vect_idx++)
    {
#ifdef _LP64
        printf("TOTAL NODE k%d:n%d MEMORY(GB): %ld\n", nodeNum[vect_idx].cageNum,
#else
        printf("TOTAL NODE k%d:n%d MEMORY(GB): %lld\n", nodeNum[vect_idx].cageNum,
#endif
               nodeNum[vect_idx].nodeNum, nodeMemSize[vect_idx]);
        totalSysMem = totalSysMem + nodeMemSize[vect_idx];
    }

    /* Print total system memory */
#ifdef _LP64
    printf("TOTAL SYSTEM MEMORY(GB): %ld\n\n", totalSysMem);
#else
    printf("TOTAL SYSTEM MEMORY(GB): %lld\n\n", totalSysMem);
#endif
    //------------------------------------------------------------------------------------------------------------------


fapi_try_exit:
    FAPI_DBG("Exiting p9_query_mssinfo");
    return fapi2::current_err;
}
OpenPOWER on IntegriCloud