-
Notifications
You must be signed in to change notification settings - Fork 97
/
rt_cmds.C
1583 lines (1428 loc) · 52.7 KB
/
rt_cmds.C
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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/usr/util/runtime/rt_cmds.C $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2015,2019 */
/* [+] 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 */
#include <runtime/interface.h>
#include <stdio.h>
#include <trace/interface.H>
#include <string.h>
#include "../utilbase.H"
#include <targeting/common/target.H>
#include <targeting/common/targetservice.H>
#include <targeting/common/predicates/predicateattrval.H>
#include <targeting/common/iterators/rangefilter.H>
#include <targeting/common/utilFilter.H>
#include <pnor/pnorif.H>
#include <devicefw/userif.H>
#include <devicefw/driverif.H>
#include <util/util_reasoncodes.H>
#include <errl/errlmanager.H>
#include <errl/errlreasoncodes.H>
#include <vector>
#include <isteps/pm/pm_common_ext.H>
#include <p9_hcd_memmap_base.H> // for reload_pm_complex
#include <p9_stop_data_struct.H> // for reload_pm_complex
#include <scom/runtime/rt_scomif.H> // sendScomOpToFsp,
// sendMultiScomReadToFsp,
// switchToFspScomAccess
#ifdef CONFIG_NVDIMM
#include <isteps/nvdimm/nvdimm.H> // notify NVDIMM protection change
#endif
extern char hbi_ImageId;
// need this here so compile works, linker will later find this
namespace RTPM
{
int load_pm_complex( uint64_t i_chip,
uint64_t i_homer_addr,
uint64_t i_occ_common_addr,
uint32_t i_mode );
}
namespace Util
{
/**
* @brief Poor-man's version of strtoul, see man page
*/
uint64_t strtou64(const char *nptr, char **endptr, int base)
{
uint64_t l_data = 0;
size_t i = 0;
while( nptr[i] != '\0' )
{
uint64_t l_nib = 0;
switch(nptr[i])
{
// handle leading '0x' or 'x'
case('x'): case('X'):
l_data = 0;
break;
case('0'): l_nib = 0; break;
case('1'): l_nib = 1; break;
case('2'): l_nib = 2; break;
case('3'): l_nib = 3; break;
case('4'): l_nib = 4; break;
case('5'): l_nib = 5; break;
case('6'): l_nib = 6; break;
case('7'): l_nib = 7; break;
case('8'): l_nib = 8; break;
case('9'): l_nib = 9; break;
case('A'): case('a'): l_nib = 0xA; break;
case('B'): case('b'): l_nib = 0xB; break;
case('C'): case('c'): l_nib = 0xC; break;
case('D'): case('d'): l_nib = 0xD; break;
case('E'): case('e'): l_nib = 0xE; break;
case('F'): case('f'): l_nib = 0xF; break;
default:
UTIL_FT( "strtou64> nptr=%s, nptr[%d]=%c", nptr, i, nptr[i] );
return 0xDEADBEEF;
}
l_data <<= 4;
l_data |= l_nib;
i++;
}
return l_data;
}
/**
* @brief Fetch a target by HUID
* @param[in] i_huid HUID to translate
* @return Target Pointer, NULL if no match found
*/
TARGETING::Target* getTargetFromHUID( uint32_t i_huid )
{
TARGETING::PredicateAttrVal<TARGETING::ATTR_HUID> l_huidMatches(i_huid);
TARGETING::TargetRangeFilter l_targetsWithHuid(
TARGETING::targetService().begin(),
TARGETING::targetService().end(),
&l_huidMatches);
if(l_targetsWithHuid)
{
return *l_targetsWithHuid;
}
else
{
UTIL_FT( "bad huid - %.8X!", i_huid );
return NULL;
}
}
/**
* @brief Read the value of an attribute by name
* @param[out] o_output Output display buffer, memory allocated here
* @param[in] i_huid HUID associated with Target to get attribute from
* @param[in] i_attrId Hash of attribute to read
* @param[in] i_size Size of attribute data in bytes
*/
void cmd_getattr( char*& o_output,
uint32_t i_huid,
uint32_t i_attrId,
uint32_t i_size )
{
UTIL_FT( "cmd_getattr> huid=%.8X, attr=%.8X, size=%d",
i_huid, i_attrId, i_size );
TARGETING::Target* l_targ{};
if(0xFFFFFFFF == i_huid)
{
TARGETING::targetService().getTopLevelTarget(l_targ);
}
else
{
l_targ = getTargetFromHUID(i_huid);
}
if( l_targ == NULL )
{
o_output = new char[100];
sprintf( o_output, "HUID %.8X not found", i_huid );
return;
}
uint8_t l_data[i_size];
bool l_try = l_targ->_tryGetAttr( (TARGETING::ATTRIBUTE_ID)i_attrId,
i_size, l_data );
if( !l_try )
{
o_output = new char[100];
sprintf( o_output, "Error reading %.8X", i_attrId );
return;
}
// "Targ[12345678] Attr[12345678] = 0x12345678...\n"
o_output = new char[50 + i_size*2];
if( i_size == 1 )
{
uint8_t* l_data8 = (uint8_t*)(l_data);
sprintf( o_output, "Targ[%.8X] Attr[%.8X] = 0x%.2X\n",
i_huid, i_attrId, *l_data8 );
}
else if( i_size == 2 )
{
uint16_t* l_data16 = (uint16_t*)(l_data);
sprintf( o_output, "Targ[%.8X] Attr[%.8X] = 0x%.4X\n",
i_huid, i_attrId, *l_data16 );
}
else if( i_size == 4 )
{
uint32_t* l_data32 = (uint32_t*)(l_data);
sprintf( o_output, "Targ[%.8X] Attr[%.8X] = 0x%.8X\n",
i_huid, i_attrId, *l_data32 );
}
else if( i_size == 8 )
{
uint64_t* l_data64 = (uint64_t*)(l_data);
sprintf( o_output, "Targ[%.8X] Attr[%.8X] = 0x%.8X%.8X\n",
i_huid, i_attrId, (uint32_t)(*l_data64>>32),
(uint32_t)*l_data64 );
}
else // give up on pretty-printing and just dump the hex
{
sprintf( o_output, "Targ[%.8X] Attr[%.8X] = 0x", i_huid, i_attrId );
size_t l_len1 = strlen(o_output);
for( size_t i=0; i<i_size; i++ )
{
sprintf( &(o_output[l_len1+i]), "%.2X", l_data[i] );
}
o_output[l_len1+i_size*2] = '-';
o_output[l_len1+i_size*2+1] = '\n';
o_output[l_len1+i_size*2+2] = '\0';
}
}
/**
* @brief Read or write data out/into SPD, MVPD or PVPD
* @param[out] o_output Output display buffer, memory allocated here
* @param[in] i_rtCmd write or read data flag
* @param[in] i_huid HUID associated with Target to read/write to/from
* @param[in] i_keyword keyword to be used for SPD, MVPD or PVPD
* @param[in] i_record record to be used for MVPD or PVPD
* @param[in] i_data The data supplied for a write or returned from a read
*/
void cmd_readwritevpd(char*& o_output, DeviceFW::OperationType i_rtCmd,
uint32_t i_huid, uint64_t i_keyword,
uint64_t i_record = 0, uint64_t i_data = 0)
{
UTIL_FT( "cmd_readwritevpd> rtcmd=%s, huid=%.8X, "
"keyword=%lx, record=%lx, data=%lx",
(i_rtCmd == DeviceFW::OperationType::READ ? "read" : "write"),
i_huid, i_keyword, i_record, i_data);
o_output = new char[100]; // info for user to consume
char o_readWriteCmd[20]; // repeat the command the user requested
bool l_isSpd(false); // are we doing SPD command
size_t l_size(0); // size of the date from/to device read/write
errlHndl_t l_errhdl(nullptr); // handle to capture errors
do
{
// get the target, if it exists from user supplied HUID
TARGETING::Target* l_target = getTargetFromHUID(i_huid);
if (nullptr == l_target)
{
sprintf( o_output, "HUID %.8X not found", i_huid );
break;
}
// get the TYPE of the HUID (we are looking for DIMM, PROC and NODE)
TARGETING::AttributeTraits<TARGETING::ATTR_TYPE>::Type l_targetType;
if (!l_target->tryGetAttr<TARGETING::ATTR_TYPE>(l_targetType))
{
sprintf( o_output, "No TARGETING::ATTR_TYPE associated "
"with HUID %.8X", i_huid );
break;
}
// vector to hold data that will be returned/sent to device read/write
std::vector<uint64_t> l_dataVec;
if (DeviceFW::OperationType::READ == i_rtCmd) // reading data from vpd
{
if (TARGETING::TYPE_DIMM == l_targetType) // SPD
{
sprintf( o_readWriteCmd, "read SPD");
l_isSpd = true;
// first get size of data with NULL call
l_errhdl = deviceRead(l_target, NULL, l_size,
DEVICE_SPD_ADDRESS(i_keyword));
if (l_errhdl)
{
break;
}
// resize buffer to hold data, +1 to get "trailing bytes"
l_dataVec.resize(l_size/sizeof(uint64_t) + 1);
// read in the data
l_errhdl = deviceRead(l_target, &l_dataVec.front(), l_size,
DEVICE_SPD_ADDRESS(i_keyword));
if (l_errhdl)
{
break;
}
}
else if (TARGETING::TYPE_PROC == l_targetType) // MVPD
{
sprintf( o_readWriteCmd, "read MVPD");
// first get size of data with NULL call
l_errhdl = deviceRead(l_target, NULL, l_size,
DEVICE_MVPD_ADDRESS(i_record, i_keyword));
if (l_errhdl)
{
break;
}
// resize buffer to hold data, +1 to get "trailing bytes"
l_dataVec.resize(l_size/sizeof(uint64_t) + 1);
// read in the data
l_errhdl = deviceRead(l_target, &l_dataVec.front(), l_size,
DEVICE_MVPD_ADDRESS(i_record, i_keyword));
if (l_errhdl)
{
break;
}
}
else if (TARGETING::TYPE_NODE == l_targetType) // PVPD
{
sprintf( o_readWriteCmd, "read PVPD");
// first get size of data with NULL call
l_errhdl = deviceRead(l_target, NULL, l_size,
DEVICE_PVPD_ADDRESS(i_record, i_keyword));
if (l_errhdl)
{
break;
}
// resize buffer to hold data, +1 to get "trailing bytes"
l_dataVec.resize(l_size/sizeof(uint64_t) + 1);
// read in the data
l_errhdl = deviceRead(l_target, &l_dataVec.front(), l_size,
DEVICE_PVPD_ADDRESS(i_record, i_keyword));
if (l_errhdl)
{
break;
}
}
else
{
sprintf( o_output, "cmd_readvpd> VPD %.8X is currently not"
" supported for HUID %.8x", l_targetType, i_huid);
break;
}
}
else // writing data to vpd
{
if (TARGETING::TYPE_DIMM == l_targetType) // SPD
{
sprintf( o_readWriteCmd, "write SPD");
l_isSpd = true;
// first get size of data with NULL call
l_errhdl = deviceRead(l_target, NULL, l_size,
DEVICE_SPD_ADDRESS(i_keyword));
if (l_errhdl)
{
break;
}
// resize buffer to hold data, +1 to get "trailing bytes"
l_dataVec.resize(l_size/sizeof(uint64_t) + 1);
// populate buffer with user data, repeat user data
// if necessary to fill buffer
for (size_t i = 0; i < l_dataVec.size(); ++i)
{
l_dataVec[i] = i_data;
}
// write the data to the VPD
l_errhdl = deviceWrite(l_target, &l_dataVec.front(), l_size,
DEVICE_SPD_ADDRESS(i_keyword));
if (l_errhdl)
{
break;
}
}
else if (TARGETING::TYPE_PROC == l_targetType) // MVPD
{
sprintf( o_readWriteCmd, "write MVPD");
// first get size of data with NULL call
l_errhdl = deviceRead(l_target, NULL, l_size,
DEVICE_MVPD_ADDRESS(i_record, i_keyword));
if (l_errhdl)
{
break;
}
// resize buffer to hold data, +1 to get "trailing bytes"
l_dataVec.resize(l_size/sizeof(uint64_t) + 1);
// populate buffer with user data, repeat user data
// if necessary to fill buffer
for (size_t i = 0; i < l_dataVec.size(); ++i)
{
l_dataVec[i] = i_data;
}
l_errhdl = deviceWrite(l_target, &l_dataVec.front(), l_size,
DEVICE_MVPD_ADDRESS(i_record, i_keyword));
if (l_errhdl)
{
break;
}
}
else if (TARGETING::TYPE_NODE == l_targetType) // PVPD
{
sprintf( o_readWriteCmd, "write PVPD");
// first get size of data with NULL call
l_errhdl = deviceRead(l_target, NULL, l_size,
DEVICE_PVPD_ADDRESS(i_record, i_keyword));
if (l_errhdl)
{
break;
}
// resize buffer to hold data, +1 to get "trailing bytes"
l_dataVec.resize(l_size/sizeof(uint64_t) + 1);
// populate buffer with user data, repeat user data
// if necessary to fill buffer
for (size_t i = 0; i < l_dataVec.size(); ++i)
{
l_dataVec[i] = i_data;
}
l_errhdl = deviceWrite(l_target, &l_dataVec.front(), l_size,
DEVICE_PVPD_ADDRESS(i_record, i_keyword));
if (l_errhdl)
{
break;
}
}
else
{
sprintf( o_output, "cmd_writevpd> VPD %.8X is currently not"
" supported for HUID %.8x", l_targetType, i_huid);
break;
}
}
// resize o_output to hold the extra data from the device read/writes
delete o_output;
size_t l_newOutputSize = 100 +
(l_dataVec.size() * sizeof(uint64_t) * 2) + l_dataVec.size();
o_output = new char[l_newOutputSize];
if (l_isSpd)
{
// write out results for SPD
sprintf( o_output, "%s - HUID=%.8X Keyword=%.8X %.8X, Data=",
&o_readWriteCmd,
i_huid,
(uint32_t)(i_keyword>>32), (uint32_t)i_keyword);
}
else
{
// write out results for MVPD or PVPD
sprintf( o_output, "%s - HUID=%.8X Record=%.8X %.8X, "
"Keyword=%.8X %.8X, Data=",
&o_readWriteCmd,
i_huid,
(uint32_t)(i_record>>32), (uint32_t)i_record,
(uint32_t)(i_keyword>>32), (uint32_t)i_keyword);
}
// write out the data from the device read/write
// first get the data that is a multiple of 8
size_t l_len(strlen(o_output));
uint64_t l_tempValue(0);
size_t i(0);
for (; i < l_dataVec.size() -1; ++i )
{
if( i % 4 == 0 )
{
sprintf(&o_output[l_len],"\n");
l_len = strlen(o_output);
}
l_tempValue = l_dataVec[i];
sprintf(&o_output[l_len],"%.8X ",(uint32_t)(l_tempValue>>32));
l_len = strlen(o_output);
sprintf(&o_output[l_len],"%.8X",(uint32_t)(l_tempValue));
l_len = strlen(o_output);
}
// write out the rest of the date that is not a multiple of 8
uint8_t* l_lastBytes = (uint8_t*)(&(l_dataVec[i]));
size_t l_numLastBytes = l_size % sizeof(uint64_t);
if (l_numLastBytes)
{
sprintf(&o_output[l_len],"\n");
l_len = strlen(o_output);
for (size_t i = 0; i < l_numLastBytes; ++i)
{
sprintf(&o_output[l_len],"%.2X", l_lastBytes[i]);
l_len = strlen(o_output);
if (i == 4)
{
sprintf(&o_output[l_len]," ");
l_len = strlen(o_output);
}
}
}
} while(0);
if (l_errhdl)
{
sprintf( o_output, "cmd_readwritevpd> FAIL - %s: RC=%.4X",
&o_readWriteCmd,
ERRL_GETRC_SAFE(l_errhdl) );
}
}
/**
* @brief Read data out of pnor
* @param[out] o_output Output display buffer, memory allocated here
* @param[in] i_section PNOR section id
* @param[in] i_bytes Number of bytes to read
*/
void cmd_readpnor( char*& o_output,
uint32_t i_section,
uint32_t i_bytes )
{
UTIL_FT( "cmd_readpnor> section=%d, bytes=%d", i_section, i_bytes );
PNOR::SectionInfo_t l_pnor;
errlHndl_t l_errhdl = PNOR::getSectionInfo( (PNOR::SectionId)i_section,
l_pnor );
if( l_errhdl )
{
UTIL_FT( "cmd_readpnor> Error from getSectionInfo()" );
o_output = new char[100];
sprintf( o_output, "Error from getSectionInfo()" );
delete l_errhdl;
l_errhdl = nullptr;
return;
}
o_output = new char[50 + i_bytes*2];
sprintf( o_output, "PNOR[%d] : name=%s, size=0x%X = 0x",
i_section, l_pnor.name, l_pnor.size );
uint8_t* l_ptr = (uint8_t*)l_pnor.vaddr;
size_t l_len1 = strlen(o_output);
for( size_t i=0; i<i_bytes; i++ )
{
sprintf( &(o_output[l_len1+2*i]), "%.2X", l_ptr[i] );
}
o_output[l_len1+i_bytes*2] = '-';
o_output[l_len1+i_bytes*2+1] = '\n';
o_output[l_len1+i_bytes*2+2] = '\0';
UTIL_FT( "PNOR[%d] : name=%s, size=0x%X = 0x",
i_section, l_pnor.name, l_pnor.size );
TRACFBIN( Util::g_util_trace, "PNOR", l_ptr, i_bytes );
}
/**
* @brief Read a scom register
* @param[out] o_output Output display buffer, memory allocated here
* @param[in] i_huid Target to read scom from
* @param[in] i_addr Scom address
*/
void cmd_getscom( char*& o_output,
uint32_t i_huid,
uint64_t i_addr )
{
UTIL_FT( "cmd_getscom> huid=%.8X, addr=%X%.8X",
i_huid, (uint32_t)(i_addr>>32), (uint32_t)i_addr );
o_output = new char[100];
TARGETING::Target* l_targ = getTargetFromHUID(i_huid);
if( l_targ == NULL )
{
sprintf( o_output, "HUID %.8X not found", i_huid );
return;
}
uint64_t l_data = 0;
size_t l_size = sizeof(uint64_t);
errlHndl_t l_errhdl = deviceRead(l_targ,
&l_data,
l_size,
DEVICE_SCOM_ADDRESS(i_addr));
if( l_errhdl )
{
sprintf( o_output, "cmd_getscom> FAIL: RC=%.4X",
ERRL_GETRC_SAFE(l_errhdl) );
return;
}
else
{
sprintf( o_output, "HUID=%.8X Addr=%X%.8X, Data=%.8X %.8X",
i_huid, (uint32_t)(i_addr>>32), (uint32_t)i_addr,
(uint32_t)(l_data>>32), (uint32_t)l_data );
return;
}
}
/**
* @brief Write a scom register
* @param[out] o_output Output display buffer, memory allocated here
* @param[in] i_huid Target to read scom from
* @param[in] i_addr Scom address
* @param[in] i_data Scom data to write
*/
void cmd_putscom( char*& o_output,
uint32_t i_huid,
uint64_t i_addr,
uint64_t i_data )
{
UTIL_FT( "cmd_putscom> huid=%.8X, addr=%X%.8X, data=%.8X %.8X",
i_huid, (uint32_t)(i_addr>>32), (uint32_t)i_addr,
(uint32_t)(i_data>>32), (uint32_t)i_data );
o_output = new char[100];
TARGETING::Target* l_targ = getTargetFromHUID(i_huid);
if( l_targ == NULL )
{
sprintf( o_output, "HUID %.8X not found", i_huid );
return;
}
size_t l_size = sizeof(uint64_t);
errlHndl_t l_errhdl = deviceWrite( l_targ,
&i_data,
l_size,
DEVICE_SCOM_ADDRESS(i_addr));
if( l_errhdl )
{
sprintf( o_output, "cmd_putscom> FAIL: RC=%.4X",
ERRL_GETRC_SAFE(l_errhdl) );
return;
}
else
{
sprintf( o_output, "HUID=%.8X Addr=%X%.8X",
i_huid, (uint32_t)(i_addr>>32), (uint32_t)i_addr );
return;
}
}
/**
* @brief Create and commit an error log
* @param[out] o_output Output display buffer, memory allocated here
* @param[in] i_word1 Userdata 1 & 2
* @param[in] i_word2 Userdata 3 & 4
* @param[in] i_callout HUID of target to callout (zero if none)
* @param[in] i_ffdcLength Additional ffdc data bytes to add to the error log
* @param[in] i_deconfig Indication if callout target should be deconfigured
* @param[in] i_gard Indication of type of failure for callout
*/
void cmd_errorlog( char*& o_output,
uint64_t i_word1,
uint64_t i_word2,
uint32_t i_callout,
uint32_t i_ffdcLength,
HWAS::DeconfigEnum i_deconfig,
HWAS::GARD_ErrorType i_gard )
{
UTIL_FT( "cmd_errorlog> word1=%.8X%.8X, word2=%.8X%.8X, i_callout=%.8X ffdcLength=%ld, deconfig=%.2X, gard=%.2X",
(uint32_t)(i_word1>>32), (uint32_t)i_word1,
(uint32_t)(i_word2>>32), (uint32_t)i_word2, i_callout,
i_ffdcLength, i_deconfig, i_gard );
o_output = new char[100];
errlHndl_t l_err = new ERRORLOG::ErrlEntry( ERRORLOG::ERRL_SEV_PREDICTIVE,
Util::UTIL_RT_CMDS,
Util::UTIL_ERC_NONE,
i_word1,
i_word2,
false );
TARGETING::Target* l_targ = getTargetFromHUID(i_callout);
if( l_targ != NULL )
{
l_err->addHwCallout( l_targ,
HWAS::SRCI_PRIORITY_HIGH,
i_deconfig,
i_gard );
}
if (i_ffdcLength > 0)
{
uint8_t l_count = 0;
uint16_t l_packet_size = 256; // break i_ffdcLength into packets
uint8_t data[l_packet_size];
do {
if (i_ffdcLength > l_packet_size)
{
i_ffdcLength -= l_packet_size;
}
else
{
l_packet_size = i_ffdcLength;
i_ffdcLength = 0;
}
memset(data, l_count, l_packet_size);
l_err->addFFDC(UTIL_COMP_ID,
&data,
l_packet_size,
0, // Version
ERRORLOG::ERRL_UDT_NOFORMAT, // parser ignores data
false ); // merge
l_count++;
} while (i_ffdcLength > 0);
// Change the default eSEL type if i_word1 is equal to 1
if (i_word1 == 1)
{
// mark error as callhome information eSEL 'dd' type
// Mimics error passed down by the OCC
l_err->setSev(ERRORLOG::ERRL_SEV_INFORMATIONAL);
l_err->setEselCallhomeInfoEvent(true);
}
}
l_err->collectTrace("UTIL", 1024);
uint32_t l_plid = l_err->plid();
errlCommit(l_err, UTIL_COMP_ID);
sprintf( o_output, "Committed plid 0x%.8X", l_plid );
}
/**
* @brief Process an SBE Message with a pass-through request
* @param[out] o_output Output display buffer, memory allocated here
* @param[in] i_chipId Processor chip ID
*/
void cmd_sbemsg( char*& o_output,
uint32_t i_chipId)
{
UTIL_FT( "cmd_sbemsg> chipId=%.8X",
i_chipId);
o_output = new char[100];
int rc = 0;
do
{
// Get the runtime interface object
runtimeInterfaces_t *l_rt_intf = getRuntimeInterfaces();
if(nullptr == l_rt_intf)
{
rc = -2;
sprintf( o_output, "Not able to get run time interface object");
return;
}
rc = l_rt_intf->sbe_message_passing(i_chipId);
if(0 != rc)
{
sprintf( o_output, "Unexpected return from RT SBE message passing. "
"Return code: 0x%.8X for chipID: 0x%.8X", rc, i_chipId);
return;
}
}while (0);
sprintf( o_output, "SBE message passing command for chipID 0x%.8X returned "
"rc 0x%.8X", i_chipId, rc );
}
int cmd_reload_pm_complex( char*& o_output, uint64_t stopAt )
{
// NOTE: this is running in a 32K hbrt -exec stack instead of
// the normal 64K hbrt stack
o_output = new char[100*8];
char l_tmpstr[100];
int rc = 0;
sprintf(o_output, "cmd_reload_pm_complex >>\n");
UTIL_FT("cmd_reload_pm_complex >>");
uint64_t l_chip;
uint64_t l_occ_common_addr;
uint64_t l_homerPhysAddr;
uint32_t l_mode = HBRT_PM_RELOAD;
stopImageSection::SprRestoreArea_t * coreThreadRestoreBEFORE =
(stopImageSection::SprRestoreArea_t *) new stopImageSection::SprRestoreArea_t[MAX_CORES_PER_CHIP][MAX_THREADS_PER_CORE];
uint64_t coreThreadRestoreSize = sizeof(stopImageSection::SprRestoreArea_t)*MAX_CORES_PER_CHIP*MAX_THREADS_PER_CORE;
TARGETING::Target* l_sys = nullptr;
TARGETING::targetService().getTopLevelTarget(l_sys);
assert(l_sys != nullptr);
l_occ_common_addr = l_sys->getAttr<TARGETING::ATTR_OCC_COMMON_AREA_PHYS_ADDR>();
TARGETING::TargetHandleList l_procChips;
TARGETING::getAllChips(l_procChips, TARGETING::TYPE_PROC, true);
// auto run through processor chips using attribute settings
for (const auto & l_procChip: l_procChips)
{
// This attr was set during istep15 HCODE build
l_homerPhysAddr = l_procChip->
getAttr<TARGETING::ATTR_HOMER_PHYS_ADDR>();
l_chip = l_procChip->getAttr<TARGETING::ATTR_POSITION>();
// GET BEFORE SNAPSHOT OF MEMORY
// Use this function as the virtual address gets reset to 0
void* l_homerVAddr = HBPM::convertHomerPhysToVirt(l_procChip,
l_homerPhysAddr);
if(nullptr == l_homerVAddr)
{
UTIL_FT(ERR_MRK"cmd_reload_pm_complex: "
"convertHomerPhysToVirt failed! "
"HOMER_Phys=0x%0lX", l_homerPhysAddr );
break;
}
UTIL_FT("Get BEFORE snapshot of memory");
stopImageSection::HomerSection_t *l_virt_addr =
reinterpret_cast<stopImageSection::HomerSection_t*>(l_homerVAddr);
if (l_virt_addr == nullptr)
{
sprintf(o_output, "ATTR_HOMER_VIRT_ADDR for %d chip returned 0\n",
l_chip);
break;
}
UTIL_FT("%d: memcpy(%p, %p, %ld)", l_chip, coreThreadRestoreBEFORE,
l_virt_addr->iv_coreThreadRestore, coreThreadRestoreSize);
sprintf( l_tmpstr, "%d: memcpy(%p, %p, %ld)\n", l_chip,
coreThreadRestoreBEFORE, l_virt_addr->iv_coreThreadRestore,
coreThreadRestoreSize );
strcat( o_output, l_tmpstr );
if (stopAt == 1)
{
break;
}
memcpy( coreThreadRestoreBEFORE,
l_virt_addr->iv_coreThreadRestore,
coreThreadRestoreSize);
// RUN LOAD_PM_COMPLEX
UTIL_FT("Calling reload_pm_complex(%d, 0x%16llX, 0x%16llX, %s)",
l_chip, l_homerPhysAddr, l_occ_common_addr,
(HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD");
sprintf( l_tmpstr,
"Calling reload_pm_complex(%d, 0x%16llX, 0x%16llX, %s)\n",
l_chip, l_homerPhysAddr, l_occ_common_addr,
(HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD");
strcat( o_output, l_tmpstr );
if (stopAt == 2)
{
break;
}
rc = RTPM::load_pm_complex( l_chip, l_homerPhysAddr,
l_occ_common_addr, l_mode );
if (rc)
{
sprintf( l_tmpstr,
"FAILURE: reload_pm_complex(%x, 0x%llx, 0x%llx, %x) returned %d\n",
l_chip, l_homerPhysAddr, l_occ_common_addr, l_mode, rc );
strcat( o_output, l_tmpstr );
break;
}
// GET AFTER SNAPSHOT OF MEMORY
UTIL_FT("Get AFTER snapshot of memory");
if (stopAt == 3)
{
break;
}
// NOW COMPARE THE TWO SNAPSHOTS
uint8_t lastMatch = memcmp(coreThreadRestoreBEFORE,
l_virt_addr->iv_coreThreadRestore,
coreThreadRestoreSize);
// Both sections should be equal as
// hostboot should NOT touch this section of memory
if (lastMatch == 0)
{
// Verify non-zero exists
stopImageSection::SprRestoreArea_t zeroedSprArea;
memset(&zeroedSprArea, 0x00, sizeof(zeroedSprArea));
bool foundNonZero = false;
for (int x = 0; x < MAX_CORES_PER_CHIP; x++)
{
for (int y = 0; y < MAX_THREADS_PER_CORE; y++)
{
// Check for non-zero threadArea
if ( 0 != memcmp(&(((stopImageSection::SprRestoreArea_t*)((char*)coreThreadRestoreBEFORE + (sizeof(zeroedSprArea)*x + sizeof(zeroedSprArea)*y)))->iv_threadArea),
&zeroedSprArea.iv_threadArea,
sizeof(zeroedSprArea.iv_threadArea)))
{
UTIL_FT("Found non-zero value in row %d, column %d threadArea", x, y);
UTIL_FBIN("Thread Area",
&(((stopImageSection::SprRestoreArea_t*)((char*)coreThreadRestoreBEFORE + (sizeof(zeroedSprArea)*x + sizeof(zeroedSprArea)*y)))->iv_threadArea),
sizeof(zeroedSprArea.iv_threadArea));
foundNonZero = true;
}
// Check for non-zero coreArea
if ( 0 != memcmp(&(((stopImageSection::SprRestoreArea_t*)((char*)coreThreadRestoreBEFORE + (sizeof(zeroedSprArea)*x + sizeof(zeroedSprArea)*y)))->iv_coreArea),
&zeroedSprArea.iv_coreArea,
sizeof(zeroedSprArea.iv_coreArea)))
{
UTIL_FT("Found non-zero value in row %d, column %d coreArea", x, y);
UTIL_FBIN("Core Area",
&(((stopImageSection::SprRestoreArea_t*)((char*)coreThreadRestoreBEFORE + (sizeof(zeroedSprArea)*x + sizeof(zeroedSprArea)*y)))->iv_coreArea),
sizeof(zeroedSprArea.iv_coreArea));
foundNonZero = true;
}
}
}
if (foundNonZero)
{
UTIL_FT("SUCCESS: reload_pm_complex in %s mode: CHIP %d worked", (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD", l_chip);
sprintf( l_tmpstr, "SUCCESS: reload_pm_complex in %s mode: CHIP %d worked\n", (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD", l_chip);
strcat( o_output, l_tmpstr );
}
else
{
UTIL_FT("CONDITIONAL SUCCESS: reload_pm_complex in %s mode: CHIP %d worked with zeroed area", (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD", l_chip);
sprintf( l_tmpstr, "CONDITIONAL SUCCESS: reload_pm_complex in %s mode: CHIP %d worked with zeroed area\n", (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD", l_chip);
strcat( o_output, l_tmpstr );
}
}
else
{
UTIL_FT("FAILURE: reload_pm_complex in %s mode: CHIP %d, first mismatch at %d", (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD", l_chip, lastMatch);
sprintf( l_tmpstr, "FAILURE: reload_pm_complex in %s mode: CHIP %d, first mismatch at %d\n", (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD", l_chip, lastMatch);
strcat( o_output, l_tmpstr );
UTIL_FBIN("BEFORE coreThreadRestore", &coreThreadRestoreBEFORE, coreThreadRestoreSize);
UTIL_FBIN("AFTER coreThreadRestore", l_virt_addr->iv_coreThreadRestore, coreThreadRestoreSize);
}
}
delete coreThreadRestoreBEFORE;
sprintf(l_tmpstr, "<< cmd_reload_pm_complex\n");
strcat(o_output, l_tmpstr);
UTIL_FT("<< cmd_reload_pm_complex");
return rc;
}
/**
* @brief Read version of HBRT
* @param[out] o_output Output display buffer, memory allocated here
*/
void cmd_readHBRTversion( char*& o_output )
{
UTIL_FT( "cmd_readHBRTversion");
const char * const l_title = "Hostboot Build ID: ";
o_output = new char[strlen(l_title) + strlen(&hbi_ImageId) + 1];
// Set beginning of output string
strcpy(o_output, l_title);
// Concatenate the Hostboot Image ID
strcat(o_output, &hbi_ImageId);
UTIL_FT( "%s", o_output);
}
/**
* @brief Execute function to prepare targeting data for an HBRT update
* @param[out] o_output Output display buffer, memory allocated here
*/
void cmd_hbrt_update(char*& o_output)
{
UTIL_FT( "cmd_hbrt_update>");
o_output = new char[100];
int rc = 0;
do
{
// Get the runtime interface object
runtimeInterfaces_t *l_rt_intf = getRuntimeInterfaces();
if(nullptr == l_rt_intf)
{
rc = -2;
sprintf( o_output, "Not able to get run time interface object");
return;
}
rc = l_rt_intf->prepare_hbrt_update();
if(0 != rc)
{
sprintf( o_output, "Unexpected return from RT prepare HBRT update. "
"Return code: 0x%.8X", rc);
return;