summaryrefslogtreecommitdiffstats
path: root/src/usr/dump/dumpCollect.C
blob: 970231213ce2cf803301bc4e95e82b564c8dd09a (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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/dump/dumpCollect.C $                                  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2012,2020                        */
/* [+] 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                                                     */

/*****************************************************************************/
// I n c l u d e s
/*****************************************************************************/

#include <sys/mmio.h>
#include "dumpCollect.H"
#include <dump/dumpreasoncodes.H>
#include <trace/interface.H>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <targeting/common/commontargeting.H>
#include <targeting/common/utilFilter.H>
#include <runtime/runtime.H>
#include <util/align.H>
#include <sys/mm.h>
#include <dump/dumpif.H>
#include <util/utiltce.H>
#include <isteps/mem_utils.H>
#include <string.h>
#include <stdio.h>

#include <sys/msg.h>                     //  message Q's
#include <mbox/mbox_queues.H>            //
#include <kernel/vmmmgr.H>

// Trace definition
trace_desc_t* g_trac_dump = NULL;
TRAC_INIT(&g_trac_dump, "DUMP", 4*KILOBYTE);

#define SBE_FFDC_SIZE 128

namespace DUMP
{
////////////
// Define an SPR number to name str map.  Note that this inverse of how
// the HWP uses it... so use the same mechanism/data - just inverse
std::map<uint32_t, const char*> SPRNUM_MAP;
typedef std::map<uint32_t, const char*>::iterator SPRNUM_MAP_IT;

#define LIST_SPR_NAME_REG(_op_)\
    _op_(XER      ,1   )\
    _op_(DSCR_RU  ,3   )\
    _op_(LR       ,8   )\
    _op_(CTR      ,9   )\
    _op_(UAMR     ,13  )\
    _op_(DSCR     ,17  )\
    _op_(DSISR    ,18  )\
    _op_(DAR      ,19  )\
    _op_(DEC      ,22  )\
    _op_(SDR1     ,25  )\
    _op_(SRR0     ,26  )\
    _op_(SRR1     ,27  )\
    _op_(CFAR     ,28  )\
    _op_(AMR      ,29  )\
    _op_(PIDR     ,48  )\
    _op_(IAMR     ,61  )\
    _op_(TFHAR    ,128 )\
    _op_(TFIAR    ,129 )\
    _op_(TEXASR   ,130 )\
    _op_(TEXASRU  ,131 )\
    _op_(CTRL_RU  ,136 )\
    _op_(TIDR     ,144 )\
    _op_(CTRL     ,152 )\
    _op_(FSCR     ,153 )\
    _op_(UAMOR    ,157 )\
    _op_(GSR      ,158 )\
    _op_(PSPB     ,159 )\
    _op_(DPDES    ,176 )\
    _op_(DAWR0    ,180 )\
    _op_(RPR      ,186 )\
    _op_(CIABR    ,187 )\
    _op_(DAWRX0   ,188 )\
    _op_(HFSCR    ,190 )\
    _op_(VRSAVE   ,256 )\
    _op_(SPRG3_RU ,259 )\
    _op_(TB       ,268 )\
    _op_(TBU_RU   ,269 )\
    _op_(SPRG0    ,272 )\
    _op_(SPRG1    ,273 )\
    _op_(SPRG2    ,274 )\
    _op_(SPRG3    ,275 )\
    _op_(SPRC     ,276 )\
    _op_(SPRD     ,277 )\
    _op_(CIR      ,283 )\
    _op_(TBL      ,284 )\
    _op_(TBU      ,285 )\
    _op_(TBU40    ,286 )\
    _op_(PVR      ,287 )\
    _op_(HSPRG0   ,304 )\
    _op_(HSPRG1   ,305 )\
    _op_(HDSISR   ,306 )\
    _op_(HDAR     ,307 )\
    _op_(SPURR    ,308 )\
    _op_(PURR     ,309 )\
    _op_(HDEC     ,310 )\
    _op_(HRMOR    ,313 )\
    _op_(HSRR0    ,314 )\
    _op_(HSRR1    ,315 )\
    _op_(TFMR     ,317 )\
    _op_(LPCR     ,318 )\
    _op_(LPIDR    ,319 )\
    _op_(HMER     ,336 )\
    _op_(HMEER    ,337 )\
    _op_(PCR      ,338 )\
    _op_(HEIR     ,339 )\
    _op_(AMOR     ,349 )\
    _op_(TIR      ,446 )\
    _op_(PTCR     ,464 )\
    _op_(USPRG0   ,496 )\
    _op_(USPRG1   ,497 )\
    _op_(UDAR     ,499 )\
    _op_(SEIDR    ,504 )\
    _op_(URMOR    ,505 )\
    _op_(USRR0    ,506 )\
    _op_(USRR1    ,507 )\
    _op_(UEIR     ,509 )\
    _op_(ACMCR    ,510 )\
    _op_(SMFCTRL  ,511 )\
    _op_(SIER_RU  ,768 )\
    _op_(MMCR2_RU ,769 )\
    _op_(MMCRA_RU ,770 )\
    _op_(PMC1_RU  ,771 )\
    _op_(PMC2_RU  ,772 )\
    _op_(PMC3_RU  ,773 )\
    _op_(PMC4_RU  ,774 )\
    _op_(PMC5_RU  ,775 )\
    _op_(PMC6_RU  ,776 )\
    _op_(MMCR0_RU ,779 )\
    _op_(SIAR_RU  ,780 )\
    _op_(SDAR_RU  ,781 )\
    _op_(MMCR1_RU ,782 )\
    _op_(SIER     ,784 )\
    _op_(MMCR2    ,785 )\
    _op_(MMCRA    ,786 )\
    _op_(PMC1     ,787 )\
    _op_(PMC2     ,788 )\
    _op_(PMC3     ,789 )\
    _op_(PMC4     ,790 )\
    _op_(PMC5     ,791 )\
    _op_(PMC6     ,792 )\
    _op_(MMCR0    ,795 )\
    _op_(SIAR     ,796 )\
    _op_(SDAR     ,797 )\
    _op_(MMCR1    ,798 )\
    _op_(IMC      ,799 )\
    _op_(BESCRS   ,800 )\
    _op_(BESCRSU  ,801 )\
    _op_(BESCRR   ,802 )\
    _op_(BESCRRU  ,803 )\
    _op_(EBBHR    ,804 )\
    _op_(EBBRR    ,805 )\
    _op_(BESCR    ,806 )\
    _op_(LMRR     ,813 )\
    _op_(LMSER    ,814 )\
    _op_(TAR      ,815 )\
    _op_(ASDR     ,816 )\
    _op_(PSSCR_SU ,823 )\
    _op_(IC       ,848 )\
    _op_(VTB      ,849 )\
    _op_(LDBAR    ,850 )\
    _op_(MMCRC    ,851 )\
    _op_(PMSR     ,853 )\
    _op_(PMMAR    ,854 )\
    _op_(PSSCR    ,855 )\
    _op_(L2QOSR   ,861 )\
    _op_(WORC     ,863 )\
    _op_(TRIG0    ,880 )\
    _op_(TRIG1    ,881 )\
    _op_(TRIG2    ,882 )\
    _op_(PMCR     ,884 )\
    _op_(RWMR     ,885 )\
    _op_(WORT     ,895 )\
    _op_(PPR      ,896 )\
    _op_(PPR32    ,898 )\
    _op_(TSCR     ,921 )\
    _op_(TTR      ,922 )\
    _op_(TRACE    ,1006)\
    _op_(HID      ,1008)\
    _op_(PIR      ,1023)\
    _op_(NIA      ,2000)\
    _op_(MSR      ,2001)\
    _op_(CR       ,2002)\
    _op_(FPSCR    ,2003)\
    _op_(VSCR     ,2004)\
    _op_(SLBE     ,2005)\
    _op_(SLBV     ,2006)


#define DO_SPRNUM_MAP(in_name, in_number)\
    SPRNUM_MAP[in_number] = #in_name;

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

errlHndl_t doDumpCollect(void)
{
    TRACFCOMP(g_trac_dump, "doDumpCollect - start ");
    errlHndl_t l_err = NULL;

    // Table Sizes
    uint64_t srcTableSize = 0;
    uint64_t destTableSize = 0;
    uint64_t resultsTableSize = 0;

    // Dump table struct pointers
    dumpEntry *srcTableEntry = NULL;
    dumpEntry *destTableEntry = NULL;
    resultsEntry *resultsTableEntry = NULL;

    do
    {
        // Get the Data pointers to the locations we need from HDAT
        //     MS_DUMP_SRC_TBL, < MDST: Memory Dump Source Table
        //     MS_DUMP_DST_TBL, < MDDT: Memory Dump Destination Table
        //     MS_DUMP_RESULTS_TBL,  <MDRT:Memory Dump Results Table
        l_err = getHostDataPtrs(srcTableEntry, srcTableSize,
                                destTableEntry, destTableSize,
                                resultsTableEntry, resultsTableSize);

        if (l_err)
        {
            TRACFCOMP(g_trac_dump, "doDumpCollect: Got an error back from getHostDataPtrs");
            break;
        }

        l_err = copySrcToDest(srcTableEntry,srcTableSize,
                              destTableEntry,destTableSize,
                              resultsTableEntry,resultsTableSize);

        if (l_err)
        {
            TRACFCOMP(g_trac_dump, "doDumpCollect: Got an error back from copySrcToDest");
            break;
        }

    }while (0);

    return (l_err);
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Replace reg num with name
void replaceRegNumWithName( hostArchRegDataEntry *hostRegData )
{
    char str[sizeof(reg_t)];

    if(hostRegData->reg.type == DUMP_ARCH_REG_TYPE_GPR)
    {
        snprintf(str,sizeof(reg_t), "GPR%d\0", hostRegData->reg.num);
        strncpy(hostRegData->reg.name, str, sizeof(reg_t));
    }
    else if (hostRegData->reg.type == DUMP_ARCH_REG_TYPE_SPR)
    {
        if(SPRNUM_MAP.find(hostRegData->reg.num) != SPRNUM_MAP.end())
        {
            strncpy(hostRegData->reg.name, SPRNUM_MAP[hostRegData->reg.num], sizeof(reg_t));
        }
        //else unknown... leave as number for debug
    }
    //else unknown type... leave as number for debug

}


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Returns the physical address corresponding to a PHYP MDST/MDRT entry
void* getPhysAddr( uint64_t i_phypAddr )
{
    uint64_t phys_addr = 0;

    // Physical Address
    if( VmmManager::FORCE_PHYS_ADDR & i_phypAddr )
    {
        // lop off the top bit so our vmm code works
        phys_addr = (i_phypAddr & ~VmmManager::FORCE_PHYS_ADDR);
    }
    // Relative to PHYP HRMOR
    else
    {
        TARGETING::Target * sys = NULL;
        TARGETING::targetService().getTopLevelTarget( sys );
        assert(sys != NULL);

        // add the hrmor/payload_base to the value in the table
        TARGETING::ATTR_PAYLOAD_BASE_type payload_base
          = sys->getAttr<TARGETING::ATTR_PAYLOAD_BASE>();
        phys_addr = payload_base*MEGABYTE + i_phypAddr;
    }

    return reinterpret_cast<void*>(ALIGN_PAGE_DOWN(phys_addr));
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
errlHndl_t copyArchitectedRegs(void)
{
    TRACFCOMP(g_trac_dump, "copyArchitectedRegs - start ");
    errlHndl_t l_err = nullptr;
    int rc;
    // Processor dump area address and size from HDAT
    uint64_t procTableAddr = 0;
    uint64_t procTableSize = 0;
    // Pointer to architected register reserved memory
    void *pSrcAddrBase = nullptr;
    void *vMapSrcAddrBase = nullptr;
    // Pointers to Hypervisor allocated memory for register data content
    void *pDstAddrBase = nullptr;
    void *vMapDstAddrBase = nullptr;
    // Architected Reg Dump table struct pointers
    procDumpAreaEntry *procTableEntry = nullptr;

    //Setup SPR num to string mapping
    LIST_SPR_NAME_REG(DO_SPRNUM_MAP)

    do
    {
        // Get the PROC_DUMP_AREA_TBL address from SPIRAH
        l_err = RUNTIME::get_host_data_section(RUNTIME::PROC_DUMP_AREA_TBL,
                                               0,
                                               procTableAddr,
                                               procTableSize);
        if (l_err)
        {
            // Got an errorlog back from get_host_data_sections
            TRACFCOMP(g_trac_dump, "copyArchitectedRegs get_host_data_sections "
                                   "for PDAT failed");
            break;
        }

        // If the address or size is zero - error out
        if ((procTableAddr == 0) || (procTableSize == 0))
        {
            // Invalid address or size
            TRACFCOMP(g_trac_dump, "copyArchitectedRegs address or size invalid"
                                   " for PDAT: addr =0x%X, size =0x%X,",
                                   procTableAddr, procTableSize);
            /*@
             * @errortype
             * @moduleid     DUMP::DUMP_ARCH_REGS
             * @reasoncode   DUMP::DUMP_PDAT_INVALID_ADDR
             * @userdata1    Table address returned
             * @userdata2    Table size returned
             * @devdesc      Invalid address and size returned from HDAT
             */
            l_err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            DUMP_ARCH_REGS,
                                            DUMP_PDAT_INVALID_ADDR,
                                            procTableAddr,
                                            procTableSize,
                                           ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);
            break;
        }

        // Map processor dump area destination address to VA addresses
        procTableEntry = reinterpret_cast<procDumpAreaEntry *>(procTableAddr);
        pDstAddrBase = getPhysAddr(procTableEntry->dstArrayAddr);
        vMapDstAddrBase = mm_block_map(pDstAddrBase,
                       (ALIGN_PAGE(procTableEntry->dstArraySize) + PAGESIZE));

        //Need to adjust actual virtual address due to mm_block_map only
        //mapping on page boundary to account for non page aligned addresses
        //from PHYP/OPAL
        uint64_t tmpAddr = reinterpret_cast<uint64_t>(vMapDstAddrBase);
        vMapDstAddrBase = reinterpret_cast<void*>(tmpAddr +
                               (procTableEntry->dstArrayAddr & (PAGESIZE-1)));

        // Map architected register reserved memory to VA addresses
        TARGETING::Target * l_sys = NULL;
        TARGETING::targetService().getTopLevelTarget( l_sys );
        assert(l_sys != NULL);
        auto srcAddr =
                  l_sys->getAttr<TARGETING::ATTR_SBE_ARCH_DUMP_ADDR>();

        pSrcAddrBase = reinterpret_cast<void * const>(srcAddr);
        vMapSrcAddrBase = mm_block_map(pSrcAddrBase,
                                       VMM_ARCH_REG_DATA_SIZE_ALL_PROC);

        TRACDCOMP(g_trac_dump, "src address [0x%X] [%p], destArrayaddr"
                 " [%X] dest[%p] [%p]", srcAddr, vMapSrcAddrBase,
                  procTableEntry->dstArrayAddr, pDstAddrBase, vMapDstAddrBase);

        // Get list of functional processor chips, in MPIPL path we
        // don't expect any deconfiguration
        TARGETING::TargetHandleList procChips;
        TARGETING::getAllChips( procChips, TARGETING::TYPE_PROC, true);


        uint64_t dstTempAddr = reinterpret_cast<uint64_t>(vMapDstAddrBase);
        procTableEntry->capArraySize = 0;
        for (uint32_t procNum = 0; procNum < procChips.size(); procNum++)
        {
            // Base addresses w.r.t PROC positions. This is static here
            // and used for reference below to calculate all other addresses
            uint64_t procSrcAddr = (reinterpret_cast<uint64_t>(vMapSrcAddrBase)+
                                    procNum * VMM_ARCH_REG_DATA_PER_PROC_SIZE);
            TRACDCOMP(g_trac_dump, "SBE Proc[%d] [%p]", procNum, procSrcAddr);
            procNum++;

            sbeArchRegDumpProcHdr_t *sbeProcHdr =
                       reinterpret_cast<sbeArchRegDumpProcHdr_t *>(procSrcAddr);
            uint16_t threadCount = sbeProcHdr->thread_cnt;
            uint16_t regCount = sbeProcHdr->reg_cnt;

            //Validate the structure versions used by SBE and HB for sharing the
            //data
            if( sbeProcHdr->version != REG_DUMP_SBE_HB_STRUCT_VER )
            {
                /*@
                 * @errortype
                 * @moduleid     DUMP::DUMP_ARCH_REGS
                 * @reasoncode   DUMP::DUMP_PDAT_VERSION_MISMATCH
                 * @userdata1    Structure version obtained from SBE
                 * @userdata2    Structure version supported by HB
                 * @devdesc      Mismatch between the version of structure
                 *               supported by both SBE and HB.
                 *
                 */
                l_err = new ERRORLOG::ErrlEntry(
                        ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                        DUMP_ARCH_REGS,
                        DUMP_PDAT_VERSION_MISMATCH,
                        sbeProcHdr->version,
                        REG_DUMP_SBE_HB_STRUCT_VER,
                        ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);
                errlCommit(l_err, DUMP_COMP_ID);
                break;
            }

            //Update the data source address to point to the thread specific
            //header data obtained by SBE
            procSrcAddr = reinterpret_cast<uint64_t>(procSrcAddr +
                                               sizeof(sbeArchRegDumpProcHdr_t));

            procTableEntry->threadRegSize = sizeof(hostArchRegDataHdr)+
                                      (regCount * sizeof(hostArchRegDataEntry));
            procTableEntry->capArraySize = procTableEntry->capArraySize +
                                          (procTableEntry->threadRegSize
                                           * threadCount);
            if (procTableEntry->dstArraySize < procTableEntry->capArraySize)
            {
                /*@
                 * @errortype
                 * @moduleid     DUMP::DUMP_ARCH_REGS
                 * @reasoncode   DUMP::DUMP_PDAT_INSUFFICIENT_SPACE
                 * @userdata1    Hypervisor reserved memory size
                 * @userdata2    Memory needed to copy architected
                 *               register data
                 * @devdesc      Insufficient space to copy architected
                 *               registers
                 */
                l_err = new ERRORLOG::ErrlEntry(
                        ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                        DUMP_ARCH_REGS,
                        DUMP_PDAT_INSUFFICIENT_SPACE,
                        procTableEntry->dstArraySize,
                        procTableEntry->capArraySize,
                        ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);
                errlCommit(l_err, DUMP_COMP_ID);
                break;
            }

            // Total Number of Threads possible in one Proc
            for(uint32_t idx = 0; idx < threadCount; idx++)
            {
                sbeArchRegDumpThreadHdr_t *sbeTdHdr =
                     reinterpret_cast<sbeArchRegDumpThreadHdr_t *>(procSrcAddr);

                hostArchRegDataHdr *hostHdr =
                     reinterpret_cast<hostArchRegDataHdr *>(dstTempAddr);

                TRACDCOMP(g_trac_dump, "  Thread[%d] src[%p] dest[%p]",
                          idx, procSrcAddr, dstTempAddr);

                // Fill thread header info
                memset(hostHdr, 0x0, sizeof(hostHdr));
                hostHdr->pir = sbeTdHdr->pir;
                hostHdr->coreState = sbeTdHdr->coreState;
                hostHdr->iv_regArrayHdr.hdatOffset =
                                              sizeof(hostArchRegDataHdr);
                hostHdr->iv_regArrayHdr.hdatArrayCnt = regCount;
                hostHdr->iv_regArrayHdr.hdatAllocSize =
                                              sizeof(hostArchRegDataEntry);
                hostHdr->iv_regArrayHdr.hdatActSize =
                                              sizeof(hostArchRegDataEntry);

                dstTempAddr = reinterpret_cast<uint64_t>(dstTempAddr +
                                                    sizeof(hostArchRegDataHdr));
                //Update SBE data source address to point to the register data
                //related to the current thread.
                procSrcAddr = reinterpret_cast<uint64_t>(procSrcAddr +
                                             sizeof(sbeArchRegDumpThreadHdr_t));

                //Validate the CoreState to find if the buffer has register data
                if (sbeTdHdr->coreState != 0)
                {
                    //Bump up the destination address to skip the memory
                    //required to store the register details.
                    dstTempAddr = reinterpret_cast<uint64_t>(dstTempAddr +
                                     (regCount * sizeof(hostArchRegDataEntry)));
                    continue;
                }

                // Fill register data
                for(uint8_t cnt = 0; cnt < regCount; cnt++)
                {
                    sbeArchRegDumpEntries_t *sbeRegData =
                       reinterpret_cast<sbeArchRegDumpEntries_t *>(procSrcAddr);
                    hostArchRegDataEntry *hostRegData =
                         reinterpret_cast<hostArchRegDataEntry *>(dstTempAddr);

                    hostRegData->reg.type = sbeRegData->regType;
                    hostRegData->reg.num  = sbeRegData->regNum;
                    hostRegData->regVal  = sbeRegData->regVal;

                    // If HOST type is PHYP replace register number with strings
                    if (TARGETING::is_phyp_load())
                    {
                        replaceRegNumWithName(hostRegData);
                    }

                    dstTempAddr = reinterpret_cast<uint64_t>(dstTempAddr +
                                                  sizeof(hostArchRegDataEntry));
                    //Update the SBE data source address to point to the
                    //next register data related to the same thread.
                    procSrcAddr = reinterpret_cast<uint64_t>(procSrcAddr +
                                               sizeof(sbeArchRegDumpEntries_t));
                    if( sbeRegData->isLastReg )
                    {
                        //Skip the FFDC for now
                        if(sbeRegData->isFfdcPresent)
                        {
                            //Move the source address to skip theFFDC
                            procSrcAddr = procSrcAddr + (sizeof(uint32_t)*SBE_FFDC_SIZE);
                            //Adjust the destination address accordingly to skip
                            //the mememory required for remaining registers
                            uint32_t remaingRegCount = regCount - (cnt+1);
                            if(remaingRegCount)
                            {
                                dstTempAddr = reinterpret_cast<uint64_t>(
                                               dstTempAddr + (remaingRegCount *
                                               sizeof(hostArchRegDataEntry)));
                            }
                        }
                        break;
                    }
                }
            }
        }
        // Update Process Dump Area tuple
        procTableEntry->threadRegVersion = REG_DUMP_HDAT_STRUCT_VER;
        procTableEntry->capArrayAddr = procTableEntry->dstArrayAddr;

        // Update the PDA Table Entries to Attribute to be fetched in istep 21
        l_sys->setAttr<TARGETING::ATTR_PDA_THREAD_REG_STATE_ENTRY_FORMAT>(
                                              procTableEntry->threadRegVersion);
        l_sys->setAttr<TARGETING::ATTR_PDA_THREAD_REG_ENTRY_SIZE>(
                                                 procTableEntry->threadRegSize);
        l_sys->setAttr<TARGETING::ATTR_PDA_CAPTURED_THREAD_REG_ARRAY_ADDR>(
                                                  procTableEntry->capArrayAddr);
        l_sys->setAttr<TARGETING::ATTR_PDA_CAPTURED_THREAD_REG_ARRAY_SIZE>(
                                                  procTableEntry->capArraySize);

    } while (0);

    // Unmap destination memory
    if (vMapDstAddrBase)
    {
        rc = mm_block_unmap(vMapDstAddrBase);
        if (rc != 0)
        {
            /*@
             * @errortype
             * @moduleid     DUMP::DUMP_ARCH_REGS
             * @reasoncode   DUMP::DUMP_PDAT_CANNOT_UNMAP_DST_ADDR
             * @userdata1    VA of Destination Array Address for PDAT
             * @userdata2    rc value from unmap
             * @devdesc      Cannot unmap the PDAT Destinatin Array Addr
             */
            l_err = new ERRORLOG::ErrlEntry(
                                  ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                  DUMP_ARCH_REGS,
                                  DUMP_PDAT_CANNOT_UNMAP_DST_ADDR,
                                  (uint64_t)vMapDstAddrBase,
                                  rc,
                                  ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);

            // Commit the error and continue.
            // Leave the devices unmapped?
            errlCommit(l_err, DUMP_COMP_ID);
            l_err = NULL;
        }
    }

    // Unmap source memory
    if(vMapSrcAddrBase)
    {
        rc = mm_block_unmap(vMapSrcAddrBase);
        if (rc != 0)
        {
            /*@
             * @errortype
             * @moduleid     DUMP::DUMP_ARCH_REGS
             * @reasoncode   DUMP::DUMP_PDAT_CANNOT_UNMAP_SRC_ADDR
             * @userdata1    VA address of Source Array Address for PDAT
             * @userdata2    rc value from unmap
             * @devdesc      Cannot unmap the PDAT Source Array Address
             */
            l_err = new ERRORLOG::ErrlEntry(
                                  ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                  DUMP_ARCH_REGS,
                                  DUMP_PDAT_CANNOT_UNMAP_SRC_ADDR,
                                  (uint64_t)vMapSrcAddrBase,
                                  rc,
                                  ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);

            // Commit the error and continue.
            // Leave the devices unmapped?
            errlCommit(l_err, DUMP_COMP_ID);
            l_err = NULL;
        }
    }
    TRACFCOMP(g_trac_dump, "copyArchitectedRegs - end ");
    return (l_err);
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

errlHndl_t copySrcToDest(dumpEntry *srcTableEntry,
                         uint64_t srcTableSize,
                         dumpEntry *destTableEntry,
                         uint64_t destTableSize,
                         resultsEntry *resultsTableEntry,
                         uint64_t resultsTableSize)
{
    TRACFCOMP(g_trac_dump, "copySrcToDest - start ");

    errlHndl_t l_err = NULL;
    int rc = 0;
    bool invalidSrcSize = false;
    bool invalidDestSize = false;
    uint32_t l_resultCount = 0x0;

    // local src table info
    uint64_t *vaSrcTableAddr = 0;
    uint64_t *vaMapSrcTableAddr = 0;
    uint64_t curSrcTableAddr = 0;

    // destination table info
    uint64_t *vaDestTableAddr = 0;
    uint64_t *vaMapDestTableAddr = 0;
    uint64_t curDestTableAddr = 0;

    // Data sizes
    uint64_t sizeToCopy = 0;
    uint64_t bytesLeftInSrc = 0;
    uint64_t bytesLeftInDest = 0;

    do
    {

        // Need to loop through all the source entries.. Copying into a
        // destination entry.  Note the src could be larger than the
        // destination size and could require multiple copies.. In addition
        // the size of the destination could be larger than 1 source entry.
        // These entries need to be packed into the destination.. so 1
        // destination entry could have multiple source entries in it.
        // After each copy need to write an entry into the results table
        // source/destination/size.

        // Figure out the num of entries in the src table
        uint64_t maxSrcEntries = srcTableSize/(sizeof (dumpEntry));

        // Figure out the num of entries in the dest table
        uint64_t maxDestEntries = destTableSize/(sizeof (dumpEntry));

        // Figure out the max result entires
        uint64_t maxResultEntries = resultsTableSize/(sizeof
                                                      (resultsEntry));

        // Index into each Dump table
        uint64_t curSourceIndex = 0;
        uint64_t curDestIndex = 0;
        uint64_t curResultIndex = 0;

        // Map in the first source and destination entries from their
        // corresponding tables.
        // NOTE: When mapping a device the address we are mapping needs to
        // be page aligned.  In addition the VA returned is page
        // aligned so we need to add the offset of the page aligned address
        // to the VA returned

        // Get the first Source address and size
        curSrcTableAddr = srcTableEntry[curSourceIndex].dataAddr;
        bytesLeftInSrc = srcTableEntry[curSourceIndex].dataSize;

        // Get the first destination address and size.
        curDestTableAddr = destTableEntry[curDestIndex].dataAddr;
        bytesLeftInDest = destTableEntry[curDestIndex].dataSize;

        // Determine the src and destination offset.
        uint64_t destOffset = curDestTableAddr
          - ALIGN_PAGE_DOWN(curDestTableAddr);
        uint64_t srcOffset = curSrcTableAddr
          - ALIGN_PAGE_DOWN(curSrcTableAddr);

        // If the data size is greater then 32GB after page alignment
        // create an error.  Current limitation on DevMap is 32GB in size.
        // Not sure yet if we will ever see a table entry > 3GB.
        if (bytesLeftInSrc + srcOffset > THIRTYTWO_GB)
        {
            invalidSrcSize = true;
            break;
        }
        else if ((bytesLeftInDest + destOffset > THIRTYTWO_GB))
        {
            invalidDestSize = true;
            break;
        }

        vaMapSrcTableAddr = (static_cast<uint64_t*>(mm_block_map(
                              getPhysAddr(curSrcTableAddr),
                              THIRTYTWO_GB)));

        vaSrcTableAddr = vaMapSrcTableAddr;

        vaMapDestTableAddr = (static_cast<uint64_t*>(mm_block_map(
                               getPhysAddr(curDestTableAddr),
                               THIRTYTWO_GB)));

        vaDestTableAddr = vaMapDestTableAddr;

        // add the offset to the src and destination VAs,
        vaSrcTableAddr += (srcOffset/(sizeof (uint64_t)));

        vaDestTableAddr += (destOffset/(sizeof (uint64_t)));

        // Current Source physical and Va address
        TRACFCOMP(g_trac_dump, "copySrcToDest SrcTableIndex = %d, srcTableAddr = %.16X, VA = %.16X",  curSourceIndex, curSrcTableAddr, vaSrcTableAddr);

        // Current Destination physical and Va address
        TRACFCOMP(g_trac_dump, "HBDumpCopySrcToDest DestTableIndex = %d, DestTableAddr = %.16X, VA = %.16X", curDestIndex, curDestTableAddr, vaDestTableAddr);

        resultsTableEntry->dataSize = 0x0;

        while(1)
        {
            // If we have copied all the bytes in the src entry
            if (bytesLeftInSrc == 0)
            {
                // unmap the previous src entry
                rc =  mm_block_unmap(
                            reinterpret_cast<void*>(vaMapSrcTableAddr));

                if (rc != 0)
                {
                    /*@
                     * @errortype
                     * @moduleid     DUMP::DUMP_COLLECT
                     * @reasoncode   DUMP::DUMP_CANNOT_UNMAP_SRC
                     * @userdata1    VA address of the MDST to unmap
                     * @userdata2    rc value from unmap
                     * @devdesc      Cannot unmap the source table section
                     */
                    l_err = new ERRORLOG::ErrlEntry(
                                          ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                          DUMP_COLLECT,
                                          DUMP_CANNOT_UNMAP_SRC,
                                          (uint64_t)vaMapSrcTableAddr,
                                          rc);

                    // commit the error and continue.
                    // Leave the devices unmapped for now.
                    errlCommit(l_err,DUMP_COMP_ID);

                    l_err = NULL;

                }

                // increment to the next src entry
                curSourceIndex++;

                // if we have reach all entries
                if (curSourceIndex >= maxSrcEntries)
                {
                    TRACFCOMP(g_trac_dump, "HBDumpCopySrcToDest - through all src entries");
                    break;
                }

                curSrcTableAddr = srcTableEntry[curSourceIndex].dataAddr;
                bytesLeftInSrc = srcTableEntry[curSourceIndex].dataSize;

                // src address 0 is valid source address on OPAL sytems
                if (!TARGETING::is_sapphire_load())
                {
                    // If the current Src table Address is 0 we are done
                    if (curSrcTableAddr == 0)
                    {
                        break;
                    }
                }

                srcOffset =  curSrcTableAddr -
                  ALIGN_PAGE_DOWN(curSrcTableAddr);

                // If the data size is less then 32GB after page alignment
                if (bytesLeftInSrc + srcOffset > THIRTYTWO_GB)
                {
                    invalidSrcSize = true;
                    break;
                }

                // map the MDST entry to a device such that we can read and
                //  write from that memory address
                vaMapSrcTableAddr = (static_cast<uint64_t*>(mm_block_map(
                                      getPhysAddr(curSrcTableAddr),
                                      THIRTYTWO_GB)));

                vaSrcTableAddr = vaMapSrcTableAddr;

                vaSrcTableAddr += (srcOffset/(sizeof (uint64_t)));

                // Current Source physical and Va address
                TRACFCOMP(g_trac_dump, "copySrcToDest SrcTableIndex = %d, srcTableAddr = %.16X, VA = %.16X",  curSourceIndex, curSrcTableAddr, vaSrcTableAddr);

            }

            // If there is no more space in the destination area
            if (bytesLeftInDest == 0)
            {
                // unmap the previous dest entry
                rc =  mm_block_unmap(
                            reinterpret_cast<void*>(vaMapDestTableAddr));
                if (rc != 0)
                {
                    /*@
                     * @errortype
                     * @moduleid     DUMP::DUMP_COLLECT
                     * @reasoncode   DUMP::DUMP_CANNOT_UNMAP_DEST
                     * @userdata1    VA address of the MDDT to unmap
                     * @userdata2    rc value from unmap
                     * @devdesc      Cannot unmap the source table section
                     */
                    l_err = new ERRORLOG::ErrlEntry(
                                          ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                          DUMP_COLLECT,
                                          DUMP_CANNOT_UNMAP_DEST,
                                          (uint64_t)vaMapDestTableAddr,
                                          rc);

                    // commit the error and continue.
                    //  Leave the devices unmapped?
                    errlCommit(l_err,DUMP_COMP_ID);

                    l_err = NULL;
                }

                // increment to the next dest entry
                curDestIndex++;

                // if made it through all dest entries.
                if (curDestIndex >= maxDestEntries)
                {
                    // need to check here to see if we still have SRC
                    // entries not copied.
                    if (bytesLeftInSrc != 0)
                    {
                        // Write an error because we have more src entries
                        // then destination space available.
                        TRACFCOMP(g_trac_dump, "HBDumpCopySrcToDest: not enough Destination table entries");

                        /*@
                         * @errortype
                         * @moduleid     DUMP::DUMP_COLLECT
                         * @reasoncode   DUMP::DUMP_MDDT_INSUFFICIENT_ENTRIES
                         * @userdata1    Source Entires bytes left to copy
                         * @userdata2    Index into the MDST table
                         * @devdesc      MDDT table is not big enough to
                         *               hold all src entries
                         */
                        l_err = new ERRORLOG::ErrlEntry(
                                              ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                              DUMP_COLLECT,
                                              DUMP_MDDT_INSUFFICIENT_ENTRIES,
                                              bytesLeftInSrc,
                                              curSourceIndex);

                        // do not commit this errorlog error as this is a
                        // real problem.

                        // TODO:  RTC: 64399
                        //  Need to add the src entries and sizes? that did
                        //  not get copied to the destination. This error
                        //  condition is such that the table entries are
                        // exceeded.
                    }

                    break;
                }

                curDestTableAddr = destTableEntry[curDestIndex].dataAddr;
                bytesLeftInDest = destTableEntry[curDestIndex].dataSize;

                //check to see if there are contiguous destination addresses
                while ((destTableEntry[curDestIndex].dataAddr +
                        destTableEntry[curDestIndex].dataSize) ==
                       destTableEntry[curDestIndex+1].dataAddr)
                {
                    curDestIndex++;
                    bytesLeftInDest +=destTableEntry[curDestIndex].dataSize;
                }

                // If the current dest addr or the size to copy are zero.
                if ((curDestTableAddr == 0) || (bytesLeftInDest == 0))
                {

                    // If there are still SRC entries to copy with no
                    // destination send an error back.
                    if (bytesLeftInSrc != 0)
                    {
                        // Write an error because we have more src entries
                        // then destination space available.
                        TRACFCOMP(g_trac_dump, "HBDumpCopySrcToDest: not enough Destination table space");

                        /*@
                         * @errortype
                         * @moduleid     DUMP::DUMP_COLLECT
                         * @reasoncode   DUMP::DUMP_MDDT_INSUFFICIENT_SPACE
                         * @userdata1    Source Entires bytes left to copy
                         * @userdata2    Index into the MDST table
                         * @devdesc      MDDT table is not big enough to
                         *               hold all src entries
                         */
                        l_err = new ERRORLOG::ErrlEntry(
                                              ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                              DUMP_COLLECT,
                                              DUMP_MDDT_INSUFFICIENT_SPACE,
                                              bytesLeftInSrc,
                                              curSourceIndex);

                        // do not commit this errorlog error as this is a
                        // real problem.

                        // TODO:  RTC: 64399
                        //  Need to add the src entries and sizes? that did
                        //  not get copied to the destination.  This
                        //  condition is such that we have a destination
                        //  entry that either has a zero address or zero
                        //  size.. Perhaps put the bad destination entry
                        //  there as well
                    }

                    break;
                }

                destOffset =  curDestTableAddr
                  - ALIGN_PAGE_DOWN(curDestTableAddr);

                // If the data size is less then 32GB after page alignment
                if (bytesLeftInDest + destOffset > THIRTYTWO_GB)
                {
                    invalidDestSize = true;
                    break;
                }

                // map the MDDT to a VA addresss
                vaMapDestTableAddr = (static_cast<uint64_t*>(mm_block_map(
                                       getPhysAddr(curDestTableAddr),
                                       THIRTYTWO_GB)));

                vaDestTableAddr = vaMapDestTableAddr;

                vaDestTableAddr += (destOffset/(sizeof(uint64_t)));

                // Current Destination physical and Va address
                TRACFCOMP(g_trac_dump, "HBDumpCopySrcToDest DestTableIndex = %d, DestTableAddr = %.16X, VA = %.16X", curDestIndex, curDestTableAddr, vaDestTableAddr);

            }


            // Determine how much to copy..
            sizeToCopy = std::min(bytesLeftInSrc, bytesLeftInDest);

            // Do the copy of the data from the source to the destination
            mm_tolerate_ue(1);
            memcpy( vaDestTableAddr,vaSrcTableAddr, sizeToCopy);
            mm_tolerate_ue(0);

            if (curResultIndex < maxResultEntries)
            {
                // Update the results table
                resultsTableEntry->srcAddr =
                  VmmManager::FORCE_PHYS_ADDR|curSrcTableAddr;
                resultsTableEntry->destAddr =
                  VmmManager::FORCE_PHYS_ADDR|curDestTableAddr;
                resultsTableEntry->dataSize = sizeToCopy;
                // Size field in source/destination table is of 4 bytes.
                // So result table size field will never cross 4 bytes.
                // Hence use top 2 bytes to copy data_type from source
                // table to result table (see HDAT spec for details).
                if (TARGETING::is_sapphire_load())
                {
                    uint64_t data_type = srcTableEntry[curSourceIndex].data_type;
                    resultsTableEntry->dataSize |= (data_type << 48);
                }
                resultsTableEntry++;
                l_resultCount++;
                curResultIndex++;
            }
            else
            {
                TRACFCOMP(g_trac_dump, "HBDumpCopySrcToDest: not enough result table space");

                /*@
                 * @errortype
                 * @moduleid     DUMP::DUMP_COLLECT
                 * @reasoncode   DUMP::DUMP_MDRT_INSUFFICIENT_SPACE
                 * @userdata1    Index into the MDRT
                 * @userdata2    max entries allowed given space allocated
                 * @devdesc      MDRT table is not big enough to hold all
                 *               entries
                 */
                l_err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                                DUMP_COLLECT,
                                                DUMP_MDRT_INSUFFICIENT_SPACE,
                                                curResultIndex,
                                                maxResultEntries);

                // commit the error and continue.
                errlCommit(l_err,DUMP_COMP_ID);

                l_err = NULL;
            }

            // decrement the amount copied from the source and destination
            bytesLeftInSrc -= sizeToCopy;
            bytesLeftInDest -= sizeToCopy;

            uint64_t addrOffset = sizeToCopy/(sizeof (uint64_t));

            // increment the current src and dest addresses in both the
            // physical and virtual addresses.
            curSrcTableAddr += sizeToCopy;
            curDestTableAddr += sizeToCopy;
            vaSrcTableAddr += addrOffset;
            vaDestTableAddr += addrOffset;
        } // end of while loop


        if (invalidSrcSize)
        {
            // Write an error because we have more src entries
            // then destination space available.
            TRACFCOMP(g_trac_dump, "HBDumpCopySrcToDest: Source TableSize > 32GB");

            /*@
             * @errortype
             * @moduleid     DUMP::DUMP_COLLECT
             * @reasoncode   DUMP::DUMP_MDST_INVALID_TABLE_SIZE
             * @userdata1    Size of Source Table Entry
             * @userdata2    Size of Page Aligned Source Table Entry
             * @devdesc      MDST table entry with page aligned is
             *               greater than 32GB
             */
            l_err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            DUMP_COLLECT,
                                            DUMP_MDST_INVALID_TABLE_SIZE,
                                            bytesLeftInSrc,
                                            bytesLeftInSrc + srcOffset);
            break;

        }
        if (invalidDestSize)
        {
            // Write an error because we have more src entries
            // then destination space available.
            TRACFCOMP(g_trac_dump, "HBDumpCopySrcToDest: Destination TableSize > 32GB");

            /*@
             * @errortype
             * @moduleid     DUMP::DUMP_COLLECT
             * @reasoncode   DUMP::DUMP_MDDT_INVALID_TABLE_SIZE
             * @userdata1    Size of Destination Table Entry
             * @userdata2    Size of Page Aligned Destination Table Entry
             * @devdesc      MDDT table entry with page aligned is
             *               greater than 32GB
             */
            l_err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            DUMP_COLLECT,
                                            DUMP_MDDT_INVALID_TABLE_SIZE,
                                            bytesLeftInDest,
                                            bytesLeftInDest + destOffset);

            break;
        }

        // Update the MDRT Count to Attribute to be fetched in istep 21
        TARGETING::TargetService& l_targetService = TARGETING::targetService();
        TARGETING::Target* l_sys = NULL;
        l_targetService.getTopLevelTarget(l_sys);
        l_sys->setAttr<TARGETING::ATTR_MPIPL_HB_MDRT_COUNT>(l_resultCount);

        //Update actual count in RUNTIME
        RUNTIME::saveActualCount(RUNTIME::MS_DUMP_RESULTS_TBL,
                                 l_resultCount);

        //Write actual count into memory as well
        // We know this will get whacked when FSP reloads the PHYP
        // lid, but we want it to be valid before that to allow
        // FSP code to consume the data from mainstore
        RUNTIME::writeActualCount(RUNTIME::MS_DUMP_RESULTS_TBL);
    }while(0);// end of do-while loop

    // Got an errorlog back from get_host_data_sections
    TRACFCOMP(g_trac_dump, "HBDumpCopySrcToDest - COMPLETE ");

    return l_err;
}



    ///////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////

    errlHndl_t getHostDataPtrs(dumpEntry *&srcTableEntry,
                               uint64_t &srcTableSize,
                               dumpEntry *&destTableEntry,
                               uint64_t &destTableSize,
                               resultsEntry *&resultsTableEntry,
                               uint64_t &resultsTableSize)

    {

        errlHndl_t l_err = NULL;
        int rc = 0;
        bool l_error = false;
        uint64_t l_section = 0;
        uint64_t l_addr = 0;
        uint64_t srcTableAddr = 0;
        uint64_t destTableAddr = 0;
        uint64_t resultsTableAddr = 0;


        do
        {

            // Get the Src Table address  (MDST)
            l_err = RUNTIME::get_host_data_section(RUNTIME::MS_DUMP_SRC_TBL,
                                                   0,
                                                   srcTableAddr,
                                                   srcTableSize);


            if (l_err)
            {
                // Got an errorlog back from get_host_data_sections
                TRACFCOMP(g_trac_dump, "HBDumpGetHostData get_host_data_sections for MDST failed rc=0x%X", rc);

                break;
            }

            // If the address or size is zero - error out
            if ((srcTableSize == 0) || (srcTableAddr == 0))
            {
                // Invalid size or address
                TRACFCOMP(g_trac_dump, "HBDumpGetHostData address or size invalie for MDST: addr =0x%X, size =0x%X," , srcTableAddr, srcTableSize);

                l_section = RUNTIME::MS_DUMP_SRC_TBL;
                l_addr = srcTableAddr;
                l_error = true;
                // got back a bad address
                break;
            }

            srcTableEntry = reinterpret_cast<dumpEntry *>(srcTableAddr);

            // Get the Destination Table Address (MDDT)
            l_err = RUNTIME::get_host_data_section(RUNTIME::MS_DUMP_DST_TBL,
                                                   0,
                                                   destTableAddr,
                                                   destTableSize);


            if (l_err)
            {
                // Got an errorlog back from get_host_data_sections
                TRACFCOMP(g_trac_dump, "HBDumpGetHostData get_host_data_sections for MDDT failed rc=0x%X", rc);

                break;
            }

            // If the address or size is zero - error out
            if ((destTableSize == 0) || (destTableAddr == 0))
            {
                // Invalid size or address
                TRACFCOMP(g_trac_dump,
                          "HBDumpGetHostData address or size invalie for MDDT: addr =0x%X, size =0x%X," ,
                          destTableAddr, destTableSize);

                l_section = RUNTIME::MS_DUMP_DST_TBL;
                l_addr = destTableAddr;
                l_error = true;

                // got back a bad address
                break;
            }

            destTableEntry = reinterpret_cast<dumpEntry *>(destTableAddr);

            // Get the Results Table Address
            l_err = RUNTIME::get_host_data_section(RUNTIME::MS_DUMP_RESULTS_TBL,
                                                   0,
                                                   resultsTableAddr,
                                                   resultsTableSize);


            if (l_err)
            {
                // Got an errorlog back from get_host_data_sections
                TRACFCOMP(g_trac_dump, "HBDumpGetHostData get_host_data_sections for MDDT failed rc=0x%X", rc);

                break;
            }

            // If the address or size is zero - error out
            if ((resultsTableSize == 0) || (resultsTableAddr == 0))
            {
                // Invalid size or address
                TRACFCOMP(g_trac_dump,
                          "HBDumpGetHostData address or size invalid for MDRT: addr =0x%X, size =0x%X," ,
                          resultsTableAddr, resultsTableSize);

                l_section = RUNTIME::MS_DUMP_RESULTS_TBL;
                l_addr = resultsTableAddr;
                l_error = true;
                // got back a bad address
                break;
            }

            // Each results table entry has the Source,Destination and Size for
            // each copy that is done from source to destination
            resultsTableEntry =
              reinterpret_cast<resultsEntry *>(resultsTableAddr);

            TRACFCOMP(g_trac_dump,
                      "gethostDataPtrs SrcTableAddr = %.16x, DestTableAddr = %.16X, resultTableAddr = %.16X",
                      srcTableAddr, destTableAddr, resultsTableAddr);

        }while(0);

        if (l_error)
        {

            /*@
             * @errortype
             * @moduleid     DUMP::DUMP_COLLECT
             * @reasoncode   DUMP::DUMP_NO_HDAT_ADDR
             * @userdata1    Address returned
             * @userdata2    Table type Requested
             * @devdesc      Invalid address and size returned from HDAT
             */
            l_err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            DUMP_COLLECT,
                                            DUMP_NO_HDAT_ADDR,
                                            l_addr,
                                            l_section);

        }

        return (l_err);
    }


    // ------------------------------------------------------------------
    // sendMboxMsg
    // ------------------------------------------------------------------
    errlHndl_t sendMboxMsg(DUMP_MSG_TYPE i_type)

    {
        errlHndl_t l_err = NULL;
        msg_t* msg = NULL;
        TRACFCOMP( g_trac_dump,
                   ENTER_MRK"sendMboxMsg()" );

        do
        {

            //Create a mailbox message to send to FSP
            msg = msg_allocate();
            msg->type = i_type;

            // If this is not a dump start message, need to collect the
            // Results table and size as well as the results table itself.
            if (i_type != DUMP_MSG_START_MSG_TYPE)
            {
                uint64_t resultsTableAddr = 0;
                uint64_t resultsTableSize = 0;

                // Get the Results Table Address
                l_err =
                  RUNTIME::get_host_data_section(RUNTIME::MS_DUMP_RESULTS_TBL,
                                                 0,
                                                 resultsTableAddr,
                                                 resultsTableSize);


                if (l_err)
                {
                    // Got an errorlog back from get_host_data_sections
                    TRACFCOMP(g_trac_dump, "HBDumpGetHostData get_host_data_sections for MDDT failed rc=0x%X", l_err->reasonCode());
                }
                // If the address or size is zero - error out
                else if ((resultsTableSize == 0) || (resultsTableAddr == 0))
                {
                    // Invalid size or address
                    TRACFCOMP(g_trac_dump,
                              "HBDumpGetHostData address or size invalid for MDRT: addr =0x%X, size =0x%X," ,
                              resultsTableAddr, resultsTableSize);


                    // Create an errorlog and change the type to error and add
                    // the plid to the data section.

                    /*@
                     * @errortype
                     * @moduleid     DUMP::DUMP_SEND_MBOX_MSG
                     * @reasoncode   DUMP::DUMP_NO_HDAT_ADDR
                     * @userdata1    Address returned
                     * @userdata2    Table type Requested
                     * @devdesc      Invalid address and size returned from HDAT
                     */
                    l_err =
                      new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                              DUMP_SEND_MBOX_MSG,
                                              DUMP_NO_HDAT_ADDR,
                                              resultsTableAddr,
                                              i_type);

                }

                // if no error then collect as expected.
                if (!l_err)
                {
                    // Physical Address of the results table
                    uint64_t l_mdrt_phys =
                      mm_virt_to_phys(
                          reinterpret_cast<void*>(resultsTableAddr));

                    // If TCEs are enabled setup TCEs in TCE Table to allow
                    // the FSP to read this memory
                    if (TCE::utilUseTcesForDmas())
                    {
                        // Align Physical addr down for TCE requirement
                        uint64_t mdrt_phys_aligned =
                                   ALIGN_PAGE_DOWN(l_mdrt_phys);

                        uint64_t offset = l_mdrt_phys - mdrt_phys_aligned;

                        TRACFCOMP( g_trac_dump,"Setup TCEs for FSP to use for "
                                   "l_mdrt_phys=0x%.16llX (virt=0x%.16llX, "
                                   "aligned_phys=0x%.16llX, offset=0x%X)",
                                   l_mdrt_phys, resultsTableAddr,
                                   mdrt_phys_aligned, offset);

                        uint32_t token = 0;
                        l_err = TCE::utilAllocateTces(mdrt_phys_aligned,
                                                      resultsTableSize+offset,
                                                      token,
                                                      false); //Read-Only

                        if (l_err)
                        {
                            // Got an errorlog back from utilAllocateTces
                            TRACFCOMP(g_trac_dump, "HBDumpGetHostData utilAllocateTces failed rc=0x%X", l_err->reasonCode());
                        }
                        else
                        {
                            // Put the token with the offset into the msg
                            msg->data[0] = token + offset;
                        }
                    }
                    else
                    {
                        msg->data[0] = l_mdrt_phys;
                    }

                    // Number of bytes in the results table
                    msg->data[1] = resultsTableSize;

                    // No extra data to worry about
                    msg->extra_data = NULL;

                }

                if (l_err)
                {
                    TRACFCOMP( g_trac_dump,
                               INFO_MRK"Got an error trying to send msg. %.8X,",
                               i_type);

                    // change the msg type to be error type
                    i_type = DUMP_MSG_ERROR_MSG_TYPE;

                    l_err->collectTrace("DUMP",1024);

                    // Put a default value into the data[0] indicating plid to in data[1]
                    msg->data[0] = 0xFFFF;

                    msg->data[1] = l_err->plid(); // plid

                    // just commit the log from failure on Read.. and
                    // send an error msg to FSP.
                    errlCommit( l_err, DUMP_COMP_ID );
                    l_err = NULL;

                }
            }


            TRACFCOMP( g_trac_dump,
                       INFO_MRK"Send msg to FSP about DUMP %.8X,",
                       i_type);

            // Send the message
            l_err = MBOX::send( MBOX::FSP_DUMP_MSGQ_ID, msg );

            // got an error.. Free the msg space allocated above.
            if( l_err )
            {
                TRACFCOMP(g_trac_dump,
                          ERR_MRK "Failed sending DUMP to FSP for %.8X",i_type);

                l_err->collectTrace("DUMP",1024);

                free( msg->extra_data );
                msg->extra_data = NULL;
                msg_free( msg );
            }
        } while( 0 );


        TRACFCOMP( g_trac_dump,
                   EXIT_MRK"sendMboxMsg()" );

        return l_err;
    }


}; // end of namespace
OpenPOWER on IntegriCloud