summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/tod_init/TodControls.C
blob: 8a09dbe4a5ff0c5cb8eea8ce3e9b8f63b4b24ff6 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/tod_init/TodControls.C $                     */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2013                   */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

/**
 *  @file TodControls.C
 *
 *  @brief This file implements the methods declared in TodControls class
 *
 *  HWP_IGNORE_VERSION_CHECK
 *
 */

#include <fapiPlatHwpInvoker.H>
#include <targeting/common/attributes.H>
#include <targeting/common/targetservice.H>
#include <targeting/common/utilFilter.H>
#include <p8_scom_addresses.H>
#include <tod_init/tod_init_reasoncodes.H>
#include "TodAssert.H"
#include "TodTrace.H"
#include "TodDrawer.H"
#include "TodProc.H"
#include "TodTypes.H"
#include "TodControls.H"
#include "TodSvcUtil.H"
#include "proc_tod_setup/proc_tod_setup.H"
#include <list>
#include <map>

using namespace TARGETING;

namespace TOD
{

//------------------------------------------------------------------------------
//Static globals
//------------------------------------------------------------------------------
//const static char DIR_PATH_SERERATOR = '/';
//const static mode_t DIR_CREATION_MODE = 0777;
//const static char * FILE_WRITE_MODE = "w+";
//const static char * FILE_READ_MODE = "r";

TodControls & TodControls::getTheInstance()
{
    return Singleton<TodControls>::instance();
}

//******************************************************************************
//TodControls::TodControls
//******************************************************************************
TodControls::TodControls()
{
    TOD_ENTER("TodControls constructor");
    TOD_EXIT("TodControls constructor");
}

//******************************************************************************
//TodControls::~TodControls
//******************************************************************************
TodControls::~TodControls()
{
    TOD_ENTER("TodControls destructor");

    destroy(TOD_PRIMARY);
    destroy(TOD_SECONDARY);

    TOD_EXIT("TodControls destructor");
}

//******************************************************************************
//TodControls::pickMDMT
//******************************************************************************
errlHndl_t TodControls::pickMdmt(const proc_tod_setup_tod_sel i_config)
{
   TOD_ENTER("pickMdmt");
   errlHndl_t l_errHdl=NULL;

   //MDMT is the master processor that drives TOD signals to all the remaining
   //processors on the system, as such wherever possible algoritm will try to
   //ensure that primary and secondary topology provides redundancy of MDMT.

   //Whenever there is an existing MDMT for the opposite configuration following
   //considerations will go in deciding the MDMT for configuration passed
   //through i_config
   //1. MDMT will be chosen from a node other that the node on which other MDMDT
   //   belongs in multinode system
   //2. In single node system MDMT will be chosen from a different fabric node
   //   (tod drawer )
   //3. Last a processor different from MDMT on the same fabric node will be
   //   chosen, if other options are not feasible

    do
    {
        proc_tod_setup_tod_sel l_oppConfig = (i_config == TOD_PRIMARY ) ?
                                              TOD_SECONDARY : TOD_PRIMARY;

        TodProc * l_pTodProc = NULL;
        TodProc * l_oppMdmt = iv_todConfig[l_oppConfig].iv_mdmt;
        TodDrawerContainer l_todDrawerList;
        l_todDrawerList = iv_todConfig[i_config].iv_todDrawerList;

        TodProc * l_lastProcWithMaxCores = NULL;
        TodDrawer * l_lastMasterTodDrawer = NULL;
        uint32_t l_lastMaxCoreCount = 0;
        uint32_t l_coreCount=0;
        uint32_t l_maxPossibleCoresPerProc = getMaxPossibleCoresPerProc();

        if ( l_oppMdmt  )
        {
            //1.Try to find MDMT on a TOD drawer that is not on the same
            //  physical node as opposite MDMT

            //Iterate the list of TOD drawers
            for (TodDrawerContainer::iterator l_todDrawerIter =
                    l_todDrawerList.begin();
                    l_todDrawerIter != l_todDrawerList.end() ;
                    ++l_todDrawerIter)
            {
                //TodProc --> TodDrawer --> Node
                if ( l_oppMdmt->getParentDrawer()->getParentNodeTarget()->
                        getAttr<ATTR_HUID>()
                        !=
                     (*l_todDrawerIter)->getParentNodeTarget()->
                        getAttr<ATTR_HUID>())
                {
                    l_pTodProc = NULL;
                    l_coreCount = 0;
                    (*l_todDrawerIter)->
                    getProcWithMaxCores(NULL,l_pTodProc,l_coreCount);
                    if ( l_pTodProc )
                    {
                        TOD_INF("returned core count = %d ",l_coreCount);
                        if ( l_coreCount > l_lastMaxCoreCount)
                        {
                            l_lastProcWithMaxCores = l_pTodProc;
                            l_lastMaxCoreCount = l_coreCount;
                            l_lastMasterTodDrawer = (*l_todDrawerIter);
                            if (l_lastMaxCoreCount == l_maxPossibleCoresPerProc)
                            {
                                break;
                            }
                        }
                    }

                }
            }

            if ( l_lastProcWithMaxCores )
            {
                l_lastMasterTodDrawer->setMasterDrawer(true);
                iv_todConfig[i_config].iv_mdmt = l_lastProcWithMaxCores;
                l_lastProcWithMaxCores->setMasterType(TodProc::TOD_MASTER);
                break;
            }

            //2.Try to find MDMT on a TOD drawer that is on the same physical
            //  node as the possible opposite MDMT but on different TOD drawer
            for (TodDrawerContainer::iterator l_todDrawerIter =
                    l_todDrawerList.begin();
                    l_todDrawerIter != l_todDrawerList.end() ;
                    ++l_todDrawerIter)
            {
                if ( (l_oppMdmt->getParentDrawer()->getParentNodeTarget()->
                            getAttr<ATTR_HUID>()
                            ==
                     (*l_todDrawerIter)->getParentNodeTarget()->
                            getAttr<ATTR_HUID>())
                        //Same node as opposite MDMT
                        &&
                     (l_oppMdmt->getParentDrawer()->getId()
                            !=
                     (*l_todDrawerIter)->getId()))//Different Drawer
                {
                    l_pTodProc = NULL;
                    l_coreCount = 0;
                    (*l_todDrawerIter)->
                        getProcWithMaxCores(NULL,l_pTodProc,l_coreCount);
                    if ( l_pTodProc )
                    {
                        if ( l_coreCount > l_lastMaxCoreCount)
                        {
                            l_lastProcWithMaxCores =  l_pTodProc;
                            l_lastMaxCoreCount = l_coreCount;
                            l_lastMasterTodDrawer = (*l_todDrawerIter);
                            if (l_lastMaxCoreCount == l_maxPossibleCoresPerProc)
                            {
                                break;
                            }
                        }

                    }

                }
            }

            if ( l_lastProcWithMaxCores )
            {
                l_lastMasterTodDrawer->setMasterDrawer(true);
                iv_todConfig[i_config].iv_mdmt = l_lastProcWithMaxCores;
                l_lastProcWithMaxCores->setMasterType(TodProc::TOD_MASTER);
                break;
            }

            //3.Try to find MDMT on the same TOD drawer as the TOD Drawer of
            //  opposite MDMT
            for (TodDrawerContainer::iterator l_todDrawerIter =
                    l_todDrawerList.begin();
                    l_todDrawerIter != l_todDrawerList.end() ;
                    ++l_todDrawerIter)
            {
                l_coreCount = 0;
                if ( l_oppMdmt->getParentDrawer()->getId() ==
                        (*l_todDrawerIter)->getId() )
                {
                    //This is the TOD drawer on which opposite MDMT exists,
                    //try to avoid processor chip of opposite MDMT while
                    //getting the proc with max cores
                    (*l_todDrawerIter)->getProcWithMaxCores(
                            iv_todConfig[l_oppConfig].iv_mdmt,l_pTodProc
                            ,l_coreCount);
                    if ( l_pTodProc )
                    {
                        iv_todConfig[i_config].iv_mdmt = l_pTodProc;
                        (*l_todDrawerIter)->setMasterDrawer(true);
                        l_pTodProc->setMasterType(TodProc::TOD_MASTER);
                        break;
                    }
                }
            }

            if ( iv_todConfig[i_config].iv_mdmt )
            {
                break;
            }

            //If we reach here only option left is MDMT on the other config so
            //select it. So we look for a proc in this config's set of TOD
            //drawers, find the one which is same as the MDMT on the other
            //config (based on the HUID).
            bool l_mdmtFound = false;
            for(TodDrawerContainer::iterator l_drwItr =
                iv_todConfig[i_config].iv_todDrawerList.begin();
                l_drwItr != iv_todConfig[i_config].iv_todDrawerList.end();
                ++l_drwItr)
            {
                const TodProcContainer& l_procs = (*l_drwItr)->getProcs();
                for(TodProcContainer::const_iterator
                    l_procItr = l_procs.begin();
                    l_procItr != l_procs.end();
                    ++l_procItr)
                {
                    if( (*l_procItr)->getTarget()->getAttr<ATTR_HUID>()
                          ==
                        (iv_todConfig[l_oppConfig].iv_mdmt)->
                        getTarget()->getAttr<ATTR_HUID>() )
                    {
                        iv_todConfig[i_config].iv_mdmt = (*l_procItr);
                        (*l_procItr)->setMasterType(TodProc::TOD_MASTER);
                        (*l_drwItr)->setMasterDrawer(true);
                        l_mdmtFound = true;
                        break;
                    }
                }

                if(l_mdmtFound)
                {
                    break;
                }
            }

            if(l_mdmtFound)
            {
                break;
            }
        }
        else
        { //There is no MDMT configured for the other topology hence select
          //the MDMT from any TOD drawer
            for (TodDrawerContainer::iterator l_todDrawerIter =
                    l_todDrawerList.begin();
                    l_todDrawerIter != l_todDrawerList.end() ;
                    ++l_todDrawerIter)
            {
                l_pTodProc = NULL;
                l_coreCount = 0;
                (*l_todDrawerIter)->getProcWithMaxCores(
                        NULL,l_pTodProc,l_coreCount);
                if ( l_pTodProc )
                {
                    if ( l_coreCount > l_lastMaxCoreCount)
                    {
                        l_lastProcWithMaxCores =  l_pTodProc;
                        l_lastMaxCoreCount = l_coreCount;
                        l_lastMasterTodDrawer = (*l_todDrawerIter);
                        if (l_lastMaxCoreCount == l_maxPossibleCoresPerProc)
                        {
                            break;
                        }
                    }
                }
            }

            if ( l_lastProcWithMaxCores )
            {
                l_lastMasterTodDrawer->setMasterDrawer(true);
                iv_todConfig[i_config].iv_mdmt = l_lastProcWithMaxCores;
                l_lastProcWithMaxCores->setMasterType(TodProc::TOD_MASTER);
                break;
            }
        }

        if ( !iv_todConfig[i_config].iv_mdmt )
        {
            TOD_ERR("MDMT NOT FOUND for configuration 0x%02X",i_config);

            /*@
             * @errortype
             * @reasoncode   TOD_NO_MASTER_PROC
             * @moduleid     TOD_PICK_MDMT
             * @userdata1    TOD configuration type
             * @devdesc      MDMT could not be found for the supplied topology
             *               type
             */
            l_errHdl = new ERRORLOG::ErrlEntry(
                               ERRORLOG::ERRL_SEV_INFORMATIONAL,
                               TOD_PICK_MDMT,
                               TOD_NO_MASTER_PROC,
                               i_config);
        }

    }while(0);

    if ( iv_todConfig[i_config].iv_mdmt )
    {
        TOD_INF("MDMT for configuration %d , is proc "
                "0%08X", i_config, iv_todConfig[i_config].iv_mdmt->
                getTarget()->getAttr<ATTR_HUID>());
    }
    TOD_EXIT("pickMdmt. errHdl = %p", l_errHdl);
    return l_errHdl;

}

//******************************************************************************
//TodControls::buildTodDrawers
//******************************************************************************
errlHndl_t  TodControls::buildTodDrawers(
        const proc_tod_setup_tod_sel i_config)
{
    TOD_ENTER("buildTodDrawers");
    errlHndl_t l_errHdl = NULL;

    do{

        TARGETING::TargetHandleList l_funcNodeTargetList;

        //Get the system pointer
        TARGETING::Target* l_pSysTarget = NULL;
        (void)TARGETING::targetService().getTopLevelTarget(l_pSysTarget);

        //We should not be reaching here without a valid system target
        TOD_ASSERT(l_pSysTarget,"NULL system target ");

        //Build the list of functional nodes
        l_errHdl = getFuncNodeTargetsOnSystem( l_pSysTarget,
                                               l_funcNodeTargetList);
        if ( l_errHdl )
        {
            TOD_ERR("For System target 0x%08X getFuncNodeTargetsOnSystem "
                    "returned  error ",l_pSysTarget->getAttr<ATTR_HUID>());
            break;
        }

        //If there was no functional node found then we must return
        if ( l_funcNodeTargetList.empty() )
        {
            TOD_ERR("For System target 0x%08X no functional node found ",
                    l_pSysTarget->getAttr<TARGETING::ATTR_HUID>());
            /*@
             * @errortype
             * @reasoncode   TOD_NO_FUNC_NODE_AVAILABLE
             * @moduleid     TOD_BUILD_TOD_DRAWERS
             * @userdata1    system target's HUID
             * @devdesc      MDMT could not find a functional node
             */
            l_errHdl = new ERRORLOG::ErrlEntry(
                               ERRORLOG::ERRL_SEV_INFORMATIONAL,
                               TOD_BUILD_TOD_DRAWERS,
                               TOD_NO_FUNC_NODE_AVAILABLE,
                               l_pSysTarget->getAttr<ATTR_HUID>());
            break;
        }

        //For each node target find the prcessor chip on it
        TARGETING::TargetHandleList l_funcProcTargetList;

        TARGETING::PredicateCTM
            l_procCTM(TARGETING::CLASS_CHIP,TARGETING::TYPE_PROC);

        TARGETING::PredicateHwas l_funcPred;
        l_funcPred.functional(true);
        TARGETING::PredicatePostfixExpr l_funcProcPostfixExpr;
        l_funcProcPostfixExpr.push(&l_procCTM).push(&l_funcPred).And();

        TodDrawerContainer& l_todDrawerList =
            iv_todConfig[i_config].iv_todDrawerList;
        TodDrawerContainer::iterator l_todDrawerIter;
        bool b_foundDrawer = false;

        for( uint32_t l_nodeIndex = 0;
                l_nodeIndex < l_funcNodeTargetList.size();
                ++l_nodeIndex )
        {
            l_funcProcTargetList.clear();

            //Find the funcational Proc targets on the system
            TARGETING::targetService().getAssociated(l_funcProcTargetList,
                    l_funcNodeTargetList[l_nodeIndex],
                    TARGETING::TargetService::CHILD,
                    TARGETING::TargetService::ALL,
                    &l_funcProcPostfixExpr);

            //Go over the list of procs and insert them in respective fabric
            //node list ( TOD drawer )
            for ( uint32_t l_procIndex =0 ;
                    l_procIndex < l_funcProcTargetList.size();
                    ++l_procIndex )
            {
                b_foundDrawer = false;
                //Traverse over the fabric node list (TOD drawer) and find if
                //there is an existing fabric node for this proc

                for ( l_todDrawerIter = l_todDrawerList.begin() ;
                        l_todDrawerIter != l_todDrawerList.end() ;
                        ++l_todDrawerIter)
                {
                    if ( (*l_todDrawerIter)->getId() ==
                            l_funcProcTargetList[l_procIndex]->
                            getAttr<ATTR_FABRIC_NODE_ID>())
                    {
                        //Add the proc to this fabric node, such that
                        //TodProc has the target pointer and the pointer to
                        //the TOD drawer to which it belongs
                        TodProc *l_procPtr =
                            new TodProc
                            (l_funcProcTargetList[l_procIndex],
                             (*l_todDrawerIter));
                        (*l_todDrawerIter)->addProc(l_procPtr);
                        l_procPtr = NULL; //Nullifying the pointer after
                        //transferring ownership

                        b_foundDrawer = true;
                        break;
                    }

                } // end drawer list loop

                if (!b_foundDrawer )
                {
                    //Create a new TOD drawer and add it to the TOD drawer list
                    //Create a TOD drawer with the fabric node id and the
                    //pointer to the node to which this fabric node belongs
                    TodDrawer *l_pTodDrawer = new
                        TodDrawer(l_funcProcTargetList[l_procIndex]->
                                getAttr<ATTR_FABRIC_NODE_ID>(),
                                l_funcNodeTargetList[l_nodeIndex]);

                    //Create a TodProc passing the target pointer and the
                    //pointer of TodDrawer to which this processor belongs
                    TodProc *l_pTodProc = new
                        TodProc(l_funcProcTargetList[l_procIndex],
                                l_pTodDrawer);

                    //push the processor ( TodProc ) , into the TOD drawer
                    l_pTodDrawer->addProc(l_pTodProc);

                    //push the Tod drawer ( TodDrawer ) , into the
                    //TodControls
                    l_todDrawerList.push_back(l_pTodDrawer);
                    //Nullify the pointers after transfering the ownership
                    l_pTodDrawer = NULL;
                    l_pTodProc = NULL;

                }

            }// end proc list loop

        } // end node list loop

        //Validate that we had atlease one TOD drawer at the end of this process
        //else generate an error
        if (iv_todConfig[i_config].iv_todDrawerList.empty())
        {
            TOD_ERR("No TOD drawer could be built for the configuration "
                    " %s ", (i_config == TOD_PRIMARY ? "Primary " :
                        "Secondary") );
            /*@
             * @errortype
             * @reasoncode   TOD_NO_DRAWERS
             * @moduleid     TOD_BUILD_TOD_DRAWERS
             * @userdata1    TOD configuration
             * @devdesc      No TOD drawer could be configured for this topology
             *               type
             */
            l_errHdl = new ERRORLOG::ErrlEntry(
                               ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                               TOD_BUILD_TOD_DRAWERS,
                               TOD_NO_DRAWERS,
                               i_config);
        }

    }while(0);
    TOD_EXIT("buildTodDrawers. errHdl = %p", l_errHdl);
    return l_errHdl;
}

//******************************************************************************
//TodControls::getTodConfigState
//******************************************************************************
errlHndl_t TodControls::getTodConfigState(
        TOD_CONFIG_STATE& o_configState,
        proc_tod_setup_tod_sel& o_activeConfig,
        bool& o_isTodRunning)const
{
    TOD_ENTER("getTodConfigState");
    errlHndl_t l_errHdl = NULL;
    o_configState = TOD_UNCHANGED;
    o_activeConfig = TOD_PRIMARY;
    o_isTodRunning = false;

    do
    {
        //Get the currently active TOD configuration
        l_errHdl = queryActiveConfig (o_activeConfig,o_isTodRunning);
        if ( l_errHdl )
        {
            TOD_ERR("Call to queryActiveConfig failed ");
            break;
        }
        //Need to read the TodSystemFile to decide if HW configuration has
        //changed since the last time TOD was configured
        std::vector<TodChipData> l_todChipDataVector;
        l_errHdl = TodControls::readTodProcDataFromFile(l_todChipDataVector);
        if ( l_errHdl ) //Indicates hard failure not limited to failure of tod
            //logic only, we cannot continue with flow
        {
            TOD_ERR("Failed loading TodChipData from TodSystemFile");
            break;
        }

        //Determine if the TOD HW has changed since the last time topology was
        //created
        //1) File data is valid but HW has changed => Report TOD_MODIFIED
        //2) File data is valid and HW has not changed => Report TOD_UNCHANGED
        //3) Authenticity of file data is in question => Report
        //TOD_UNKNOWN

        //Check if TodSystemFile has topology data for atleast one node
        if ( hasNoValidData ( l_todChipDataVector ))
        {
            TOD_INF("No valid data found in the file TodSystemFile");
            o_configState = TOD_UNKNOWN;
            break;
        }

        //For each functional processor present in the system, if we
        //have, old  configuration data in the TodSystemConfig file then
        //validate it.

        //Get the processors present in the system
        TARGETING::PredicateCTM
            l_procFilter(TARGETING::CLASS_CHIP,TARGETING::TYPE_PROC,
                    TARGETING::MODEL_NA);

        TARGETING::PredicateHwas l_presencePredicate;
        l_presencePredicate.present(true);

        TARGETING::PredicatePostfixExpr l_presenceAndProcChipFilter;
        l_presenceAndProcChipFilter.push(&l_procFilter).
            push(&l_presencePredicate).And();

        TARGETING::TargetRangeFilter l_filter(
                TARGETING::targetService().begin(),
                TARGETING::targetService().end(),
                &l_presenceAndProcChipFilter);

        bool l_state = false;  //Variable for keeping functional state of
        //the processor
        uint32_t l_ordinalId = TOD_INVALID_UNITID;
        //Initializing to some value not expected to be ordinal id

        ecmdDataBufferBase l_chipCtrlRegBuf(64);

        //Initialize l_chipCtrlRegBuf it will be used later

        FAPI_INVOKE_HWP(l_errHdl, init_chip_ctrl_reg, l_chipCtrlRegBuf);
        if ( l_errHdl )
        {
            TOD_ERR("init_chip_ctrl_reg returned error ");
            break;
        }

        for ( ; l_filter ; ++l_filter )
        {
            l_state = false;
            if ((*l_filter)->getAttr<ATTR_HWAS_STATE>().functional)
            {
                l_state = true;
            }

            // use position attribute on one drawer only machine
            l_ordinalId=(*l_filter)->getAttr<ATTR_POSITION>();

            if ( l_state ) //Functional processor
            {
                //Check if TodSystemData file also indicates the processor as
                //functional

                //Indexing into l_todChipDataVector is safe as size of vector is
                //always determined by the maximum possible processors for this
                //system type
                if(((l_todChipDataVector[l_ordinalId].header.flags) &
                            TOD_FUNC) != 0 )
                {

                    //File data says that the chip is functional do some more
                    //validation on the data

                    //Check if the chip control register (0x40010) data is valid
                    //This data does not depend on topology, so it should tally
                    if ( (l_todChipDataVector[l_ordinalId].regs.ccr) !=
                            l_chipCtrlRegBuf.getWord(0)  )
                    {
                        TOD_INF("Chip control register read from TodSystemData"
                                "is not valid for the processor 0x%08X",
                                (*l_filter)->getAttr<TARGETING::ATTR_HUID>());
                        //We do not have a valid data no need to continue
                        //further
                        o_configState = TOD_UNKNOWN;
                        break;
                    }
                }
                else
                {
                    //New hardware has been added
                    TOD_INF("New processor detected 0x%08X",
                            (*l_filter)->getAttr<ATTR_HUID>());
                    o_configState = TOD_MODIFIED;
                }

            }
            else
            {
                //Check if this chip was functional earlier
                if ( ((l_todChipDataVector[l_ordinalId].header.flags) &
                            TOD_FUNC) != 0 )
                {
                    //HW has been removed
                    o_configState = TOD_MODIFIED;
                    TOD_INF("Processor 0x%08X is no more available ",
                            (*l_filter)->getAttr<ATTR_HUID>());
                }
            }
        }

    }while(0);

    TOD_EXIT(" config state = %d, active config = %d, TOD HW State = "
            "%d errHdl = %p",
            o_configState, o_activeConfig , o_isTodRunning, l_errHdl);

    return l_errHdl;
}

//******************************************************************************
//TodControls::isTodRunning
//******************************************************************************
errlHndl_t TodControls::isTodRunning(bool& o_isTodRunning)const
{
    TOD_ENTER("isTodRunning");
    errlHndl_t l_errHdl = NULL;
    TARGETING::Target* l_primaryMdmt=NULL;
    TARGETING::Target* l_secondaryMdmt=NULL;
    o_isTodRunning = false;

    do
    {
        //Read the TOD HW to get the configured MDMT
        l_errHdl = getConfiguredMdmt(l_primaryMdmt,l_secondaryMdmt);
        if ( l_errHdl )
        {
            TOD_ERR("Failed getting configured MDMTs" );
            break;
        }

        if ( l_primaryMdmt || l_secondaryMdmt ) //If there is atleast one MDMT
            //configured , check the chipTOD HW status by reading the TOD
            //status register TOD_PSS_MSS_STATUS_REG_00040008
        {
            ecmdDataBufferBase l_primaryMdmtBuf(64);
            ecmdDataBufferBase l_secondaryMdmtBuf(64);

            if ( l_primaryMdmt )
            {
                l_errHdl = todGetScom(l_primaryMdmt,
                        TOD_PSS_MSS_STATUS_REG_00040008,
                        l_primaryMdmtBuf);
                if ( l_errHdl )
                {
                    TOD_ERR("Scom failed for status register "
                            "TOD_PSS_MSS_STATUS_REG_00040008 on primary MDMT");
                    break;
                }
            }

            if ( l_secondaryMdmt )
            {
                l_errHdl = todGetScom(l_secondaryMdmt,
                        TOD_PSS_MSS_STATUS_REG_00040008,
                        l_secondaryMdmtBuf);
                if ( l_errHdl )
                {
                    TOD_ERR("Scom failed for status register "
                           "TOD_PSS_MSS_STATUS_REG_00040008 on secondary MDMT");
                    break;
                }
            }

            //If all the bits of TOD_PSS_MSS_STATUS_REG_00040008 are off then
            //ChipTOD HW is not running
            if ((l_primaryMdmtBuf.getWord(0) == 0 ) &&
                    (l_secondaryMdmtBuf.getWord(0)== 0))
            {
                break;
            }

            o_isTodRunning = true;
        }

    }while(0);

    TOD_EXIT("TOD HW State = %d errHdl = %p",o_isTodRunning, l_errHdl);
    return l_errHdl;
}

//******************************************************************************
//TodControls::queryActiveConfig
//******************************************************************************
errlHndl_t TodControls::queryActiveConfig(
        proc_tod_setup_tod_sel& o_activeConfig,
        bool& o_isTodRunning)const
{
    TOD_ENTER("queryActiveConfig");
    errlHndl_t l_errHdl = NULL;
    TARGETING::Target* l_primaryMdmt=NULL;
    TARGETING::Target* l_secondaryMdmt=NULL;

    o_isTodRunning = false;
    o_activeConfig = TOD_PRIMARY;

    do
    {
        //Read the configured Mdmt from TOD HW
        l_errHdl = getConfiguredMdmt(l_primaryMdmt,l_secondaryMdmt);
        if ( l_errHdl )
        {
            TOD_ERR("Failed to get configured MDMTs" );
            break;
        }

        if ( l_primaryMdmt || l_secondaryMdmt ) //If there is atleast one MDMT
            //configured,` check the ChipTOD HW status by reading the TOD
            //status register TOD_PSS_MSS_STATUS_REG_00040008
        {
            ecmdDataBufferBase l_primaryMdmtBuf(64);
            ecmdDataBufferBase l_secondaryMdmtBuf(64);

            if ( l_primaryMdmt )
            {
                l_errHdl = todGetScom(l_primaryMdmt,
                        TOD_PSS_MSS_STATUS_REG_00040008,
                        l_primaryMdmtBuf);
                if ( l_errHdl )
                {
                    TOD_ERR("Scom failed for status register "
                            "TOD_PSS_MSS_STATUS_REG_00040008 on primary MDMT");
                    break;
                }
            }

            if ( l_secondaryMdmt )
            {
                l_errHdl = todGetScom(l_secondaryMdmt,
                        TOD_PSS_MSS_STATUS_REG_00040008,
                        l_secondaryMdmtBuf);
                if ( l_errHdl )
                {
                    TOD_ERR("Scom failed for status register "
                            "TOD_PSS_MSS_STATUS_REG_00040008 secondary MDMT ");
                    break;
                }
            }

            //If all the bits of TOD_PSS_MSS_STATUS_REG_00040008 are off then
            //ChipTOD HW is not running
            if ((l_primaryMdmtBuf.getWord(0) == 0 ) &&
                    (l_secondaryMdmtBuf.getWord(0)== 0))
            {
                break;
            }

            o_isTodRunning = true;

            //First 3 bits of TOD_PSS_MSS_STATUS_REG_00040008  indicates
            //active TOD topology
            // [0:2] == '111' secondary, '000' is primary - just check bit 0

            //Putting the below check because of  past TOD HW error.
            //Both primary and secondary MDMT would claim that it is the active
            //one,this happened during CHARM operation after failover from
            //primary to econdary
            //May be that error does not exists in P8 HW but in case it still
            //exists we will be able to catch it
            if (  l_primaryMdmt &&  l_secondaryMdmt )
            {
                if (
                        l_primaryMdmtBuf.isBitSet
                        (TOD_PSS_MSS_STATUS_REG_00040008_ACTIVE_BIT)
                        !=
                        l_secondaryMdmtBuf.isBitSet
                        (TOD_PSS_MSS_STATUS_REG_00040008_ACTIVE_BIT)
                   )
                {
                    TOD_ERR("TOD HW error, primary and secondary MDMT do not"
                            "agree on bits 0 of TOD status register 0x40008");
                    /*@
                     * @errortype
                     * @reasoncode   TOD_HW_ERROR
                     * @moduleid     TOD_QUERY_ACTIVE_CONFIG
                     * @userdata1    Status register bits of primary MDMT
                     * @userdata2    Status register bits of secondary MDMT
                     * @devdesc      Error: primary and secondary MDMT do not
                     *               agree on bits 0 of TOD status register
                     *               0x40008
                     */
                    l_errHdl = new ERRORLOG::ErrlEntry(
                                      ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                      TOD_QUERY_ACTIVE_CONFIG,
                                      TOD_HW_ERROR,
                                      l_primaryMdmtBuf.getWord(0),
                                      l_secondaryMdmtBuf.getWord(0) );
                    break;
                }
            }

            if(l_primaryMdmtBuf.isBitSet
                (TOD_PSS_MSS_STATUS_REG_00040008_ACTIVE_BIT))
            {
                TOD_INF("Primary MDMT says secondary is configured ");
                o_activeConfig = TOD_SECONDARY;
                //  If the primary says the secondary is active then what the
                //  secondary MDMT says is not important - no more checking
                //  required.
                break;
            }

            //The secondaryMDMT only needs to be checked if the primaryMDMT
            //said it is active ( i.e. bit 0 is clear )

            //If the secondary says the secondary is active then primary was
            //not found
            if ( l_secondaryMdmtBuf.isBitSet
                    (TOD_PSS_MSS_STATUS_REG_00040008_ACTIVE_BIT))
            {
                TOD_INF("Secondary MDMT says secondary is configured ");
                o_activeConfig = TOD_SECONDARY;
                break;
            }
        }
        //Else not yet initialized, just return primary

    }while(0);

    TOD_EXIT("queryActiveConfig. errHdl = %p", l_errHdl);
    return l_errHdl;
}

//******************************************************************************
//TodControls::getConfiguredMdmt
//******************************************************************************
errlHndl_t TodControls::getConfiguredMdmt(
        TARGETING::Target*& o_primaryMdmt,
        TARGETING::Target*& o_secondaryMdmt) const
{
    TOD_ENTER("getConfiguredMdmt");
    errlHndl_t l_errHdl = NULL;
    o_primaryMdmt = NULL;
    o_secondaryMdmt = NULL;

    do
    {
        //Find MDMT for primary and secondary topology from HW

        //Get the functional procs on the system
        TARGETING::PredicateCTM
            l_procFilter(TARGETING::CLASS_CHIP,TARGETING::TYPE_PROC,
                    TARGETING::MODEL_NA);

        TARGETING::PredicateHwas l_funcPred;
        l_funcPred.functional(true);

        TARGETING::PredicatePostfixExpr l_stateAndProcChipFilter;
        l_stateAndProcChipFilter.push(&l_procFilter).
            push(&l_funcPred).And();

        TARGETING::TargetHandleList l_procTargetList;

        ecmdDataBufferBase l_todCtrlReg(64);

        //TOD_PSS_MSS_CTRL_REG_00040007

        TARGETING::TargetRangeFilter l_filter(
                TARGETING::targetService().begin(),
                TARGETING::targetService().end(),
                &l_stateAndProcChipFilter);

        //Read the TOD control register TOD_PSS_MSS_CTRL_REG_00040007 for each
        //processor and check for bits 1 and 9
        for (   ; l_filter; ++l_filter  )
        {
            l_errHdl = todGetScom(*l_filter,
                    TOD_PSS_MSS_CTRL_REG_00040007,
                    l_todCtrlReg);

            if ( l_errHdl )
            {
                TOD_ERR("Scom failed for target 0x%08X on register"
                        "TOD_PSS_MSS_CTRL_REG_00040007 ",
                        (*l_filter)->getAttr<ATTR_HUID>());
                break;
            }

            if (
                l_todCtrlReg.isBitSet
                (TOD_PSS_MSS_CTRL_REG_00040007_PRIMARY_MDMT_BIT) )//primary MDMT
            {
                o_primaryMdmt = *l_filter;
                TOD_INF("found primary MDMT HUID = 0x%08X",
                        o_primaryMdmt->getAttr<ATTR_HUID>());
            }

            if (
                l_todCtrlReg.isBitSet
                (TOD_PSS_MSS_CTRL_REG_00040007_SECONDARY_MDMT_BIT) )
                //secondary MDMT
            {
                o_secondaryMdmt = *l_filter;
                TOD_INF("found secondary MDMT HUID = 0x%08X",
                        o_secondaryMdmt->getAttr<ATTR_HUID>());
            }

            if ( o_primaryMdmt && o_secondaryMdmt )
            {
                break;
            }
        }

    }while(0);

    TOD_EXIT("getConfiguredMdmt. errHdl = %p", l_errHdl);
    return l_errHdl;
}

//******************************************************************************
//TodControls::destroy
//******************************************************************************
void TodControls::destroy(const proc_tod_setup_tod_sel i_config)
{
    TOD_ENTER("destroy");

    for(TodDrawerContainer::iterator l_itr =
            iv_todConfig[i_config].iv_todDrawerList.begin();
            l_itr != iv_todConfig[i_config].iv_todDrawerList.end();
            ++l_itr)
    {
        if(*l_itr)
        {
            delete (*l_itr);
        }
    }
    iv_todConfig[i_config].iv_todDrawerList.clear();
    iv_todConfig[i_config].iv_mdmt = NULL;
    iv_todConfig[i_config].iv_isConfigured = false;

    TOD_EXIT("destroy");
}

//******************************************************************************
//TodControls::writeTodProcData
//******************************************************************************
errlHndl_t TodControls::writeTodProcData(
        const proc_tod_setup_tod_sel i_config)
{
    TOD_ENTER("writeTodProcData");
    errlHndl_t l_errHdl = NULL;

    do
    {
        //As per the requirement specified by PHYP/HDAT, HB needs to fill
        //data for every chip that can be installed on the system.
        //It is also required that chip ID match the index of the entry in the
        //array so we can possibly have valid chip data at different indexes in
        //the array and the intermittent locations filled with the chip entries
        //that does not exist on the system. All such entires will have default
        //non-significant values

        TodChipData blank;
        uint32_t l_maxProcCount = getMaxProcsOnSystem();

        TOD_INF("Max possible processor chips for this system when configured "
                "completely is %d",l_maxProcCount);

        iv_todChipDataVector.assign(l_maxProcCount,blank);

        TARGETING::ATTR_POSITION_type l_ordId = 0x0;
        //Ordinal Id of the processors that form the topology

        //Fill the TodChipData structures with the actual value in the
        //ordinal order
        for(TodDrawerContainer::iterator l_itr =
                iv_todConfig[i_config].iv_todDrawerList.begin();
                l_itr != iv_todConfig[i_config].iv_todDrawerList.end();
                ++l_itr)
        {
            const TodProcContainer&  l_procs =
                (*l_itr)->getProcs();

            for(TodProcContainer::const_iterator
                    l_procItr = l_procs.begin();
                    l_procItr != l_procs.end();
                    ++l_procItr)
            {
                l_ordId =
                    (*l_procItr)->getTarget()->getAttr<ATTR_POSITION>();

                //Clear the default flag for this chip, defaults to
                //NON_FUNCTIONAL however this is a functional chip
                iv_todChipDataVector[l_ordId].header.flags = TOD_NONE;

                //Fill the todChipData structure at position l_ordId
                //inside iv_todChipDataVector with TOD register data
                //values
                (*l_procItr )->setTodChipData(
                        iv_todChipDataVector[l_ordId]);

                //Set flags to indicate if the proc chip is an MDMT
                //See if the current proc chip is MDMT of the primary
                //topology
                if ( getConfigStatus(TOD_PRIMARY)
                        &&
                        getMDMT(TOD_PRIMARY))
                {
                    if (
                            (getMDMT(TOD_PRIMARY)->getTarget()->
                             getAttr<ATTR_HUID>())
                            ==
                            ((*l_procItr)->getTarget()->
                             getAttr<ATTR_HUID>())
                       )
                    {

                        iv_todChipDataVector[l_ordId].header.flags |=
                            TOD_PRI_MDMT;
                    }
                }

                //See if the current proc chip is MDMT of the secondary
                //network
                //Note: The chip can be theoretically both primary and
                //secondary MDMDT
                if ( getConfigStatus(TOD_SECONDARY)
                        &&
                        getMDMT(TOD_SECONDARY))
                {
                    if (
                            (getMDMT(TOD_SECONDARY)->getTarget()->
                             getAttr<ATTR_HUID>())
                            ==
                            ((*l_procItr)->getTarget()->
                             getAttr<ATTR_HUID>())
                       )
                    {

                        iv_todChipDataVector[l_ordId].header.flags |=
                            TOD_SEC_MDMT;
                    }

                }

            }
        }

        //Done with setting the data write it to the file
        l_errHdl = writeTodProcDataToFile();
        if ( l_errHdl )
        {
            TOD_ERR( "Failed writing TOD chip data to the file ");
            break;
        }

    }while(0);

    TOD_EXIT("writeTodProcData. errHdl = %p", l_errHdl);
    return l_errHdl;

}//end of writeTodProcData


//******************************************************************************
//TodControls::writeTodProcDataToFile()
//******************************************************************************
errlHndl_t TodControls::writeTodProcDataToFile()
{
    TOD_ENTER("writeTodProcDataToFile");
    errlHndl_t l_errHdl = NULL;
#ifndef __HOSTBOOT_MODULE
    do
    {
        std::string l_fileOpenMode(FILE_WRITE_MODE);
        char l_fileName[128];
        l_errHdl = getTodProcDataFilePath(l_fileName);
        if(l_errHdl)
        {
            TOD_ERR("Failed getting the file path for sharing TOD data with "
                    "   HDAT ");
            break;
        }

        //Create the parent directory in which file has to be written
        std::string l_dirPath = l_fileName.substr
            (0,l_fileName.find_last_of(DIR_PATH_SERERATOR));
        int rc = mkdir(l_dirPath.c_str(),DIR_CREATION_MODE);

        if ( rc != 0 )
        {
            //EEXIST just means it already exists, which is fine
            if (errno != EEXIST)
            {
                TOD_ERR("Error creating the directory %s "
                        "system returned error code %d",
                        l_dirPath.c_str(),errno);
                break;
            }
        }

        UtilFile file;
        l_errHdl = file.open(l_fileName.c_str(), l_fileOpenMode.c_str());
        if ( l_errHdl )
        {
            TOD_ERR("Failed opening the file %s, with mode %s" ,
                    l_fileName.c_str(),l_fileOpenMode.c_str());
            break;
        }

        TodChipDataContainer::iterator l_chipDataItr =
            iv_todChipDataVector.begin();
        file.write(reinterpret_cast<void *>((&(*l_chipDataItr))),
                (iv_todChipDataVector.size()* sizeof(TodChipData)));

        l_errHdl = file.getLastError();
        if ( l_errHdl )
        {
            TOD_ERR("Failed writing the tod chip data to file ");
            break;
        }

        l_errHdl = file.close();
        if ( l_errHdl )
        {
            TOD_ERR("Failed closing the file %s",  l_fileName.c_str());
            break;
        }

    }while(0);
#endif
    TOD_EXIT("writeTodProcDataToFile. errHdl = %p", l_errHdl);
    return l_errHdl;

}

//*****************************************************************************
//TodControls::readTodProcDataFromFile
//******************************************************************************
errlHndl_t TodControls::readTodProcDataFromFile(
        std::vector<TodChipData>& o_todChipDataVector )const
{
    TOD_ENTER("readTodProcDataFromFile");
    errlHndl_t l_errHdl = NULL;
#ifndef __HOSTBOOT_MODULE
    do
    {
        std::string l_todProcDataFile;
        UtilFile l_file;

        l_errHdl = getTodProcDataFilePath(l_todProcDataFile);
        if(l_errHdl)
        {
            TOD_ERR("Failed getting the path of TodSystemFile ");
            break;
        }

        if ( !UtilFile::exists(l_todProcDataFile.c_str()))
        {
            TOD_INF("File %s , does not exist",l_todProcDataFile.c_str());
            break;
        }

        //Open the file for reading
        l_errHdl = l_file.open(l_todProcDataFile.c_str(),FILE_READ_MODE);
        if ( l_errHdl )
        {
            TOD_ERR("Failed opening the file %s, with mode %s" ,
                    l_todProcDataFile.c_str(),FILE_READ_MODE);
            break;
        }

        //The amount of data stored on TodSystemFile always depend on the
        //maximum processor possible for the given system type
        uint32_t l_maxProcCount = getMaxProcsOnSystem();

        uint32_t l_bytesToRead = l_file.size();

        if ( (l_bytesToRead == 0)  || (l_bytesToRead > (l_maxProcCount *
            sizeof(TodChipData))))  //Check for further safeguards
        {
            TOD_ERR("Error, File %s is corrupted"
                    ,l_todProcDataFile.c_str());

            //Commit this locally, because system can still proceed if TOD HW is
            //not running
            l_errHdl->commit(HWSV_COMP_ID, ERRL_ACTION_REPORT,
                    ERRL_SEV_INFORMATIONAL);
            delete l_errHdl;
            l_errHdl = 0;
            break;
        }

        TodChipData blank;
        o_todChipDataVector.assign(l_maxProcCount,blank); //Allocate memory with
        //default values

        //Read the data from file
        l_file.read(reinterpret_cast<void *>(&(*(o_todChipDataVector.begin()))),
                l_bytesToRead);


        l_errHdl = l_file.getLastError();
        if ( l_errHdl )
        {
            TOD_ERR("Failed reading tod chip data from file ");
            break;

        }

        l_errHdl = l_file.close();
        if ( l_errHdl )
        {
            TOD_ERR("Failed closing the file %s", l_todProcDataFile.c_str());
            break;
        }
        //Not going to close the file in error path , UtilFile will close it.

    }while(0);
#endif
     TOD_EXIT("readTodProcDataFromFile. errHdl = %p", l_errHdl);
     return l_errHdl;
}

//******************************************************************************
//TodControls::getTodProcDataFilePath()
//******************************************************************************
errlHndl_t TodControls::getTodProcDataFilePath(char * o_fileName)
    const
{
    TOD_ENTER("getTodProcDataFilePath");
    errlHndl_t l_errHdl = NULL;
#ifndef __HOSTBOOT_MODULE
    char *l_buf = NULL;
    do
    {
        uint32_t     l_fileSize = 0;
        const char* l_stringToAppend = NULL;
        const char* l_filePathKey[2] =
        {   P1_ROOT_PATH,
            CINI_SYSTODFILE_PATH
        };


        l_errHdl = UtilReg::path(l_filePathKey,(sizeof(l_filePathKey) /
        sizeof(l_filePathKey[0])),
        l_stringToAppend,l_buf,l_fileSize);

        if ( l_errHdl )
        {
            TOD_ERR("Failed getting file path from the registry using keys"
            "P1_ROOT_PATH and CINI_SYSTODFILE_PATH " );
            break;
        }

        o_fileName = std::string(l_buf);
        TOD_INF("Found file path %s",o_fileName.c_str());


    }while(0);

    if ( l_buf )
    {
        delete l_buf;
    }
#endif
    TOD_EXIT("getTodProcDataFilePath. errHdl = %p", l_errHdl);
    return l_errHdl;
}


//******************************************************************************
//HwsvTodControls::hasNoValidData()
//******************************************************************************
bool TodControls::hasNoValidData(const std::vector<TodChipData>&
        i_todChipDataVector)const
{
    TOD_ENTER("hasNoValidData");
    bool result = true;
    for(std::vector<TodChipData>::const_iterator l_iter =
            i_todChipDataVector.begin();
            l_iter != i_todChipDataVector.end(); ++l_iter)
    {
        if(((*l_iter).header.flags & TOD_FUNC) != 0)
        {
            result = false;
            break;
        }
    }
    TOD_EXIT("hasNoValidData");
    return result;
}


}//end of namespace
OpenPOWER on IntegriCloud