summaryrefslogtreecommitdiffstats
path: root/src/occ_gpe0/firdata/firData.c
blob: b367104742d1d1832187b89d4efdbef993b06c0b (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_gpe0/firdata/firData.c $                              */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2018                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#include <native.h>

#include <homerData_common.h>
#include <pnorData_common.h>
#include <pnor_util.h>
#include <scom_trgt.h>
#include <scom_util.h>

/** Keeps track of pointers to register lists in the HOMER data for each target
 *  type. */
typedef struct
{
    uint32_t * glbl;     /*/< Global registers */
    uint32_t * fir;      /*/< Normal FIRs */
    uint32_t * reg;      /*/< Normal registers */
    uint64_t * idFir;    /*/< Indirect-SCOM FIRs */
    uint64_t * idReg;    /*/< Indirect-SCOM registers */
} FirData_ListPointers_t;

/** Contains pointers and sizes for the HOMER and PNOR data buffers. */
typedef struct
{
    uint8_t      * hBuf;        /*/< Pointer to the HOMER data buffer */
    uint32_t       maxHBufSize; /*/< Maximum size of the HOMER data buffer */
    HOMER_Data_t * hData;       /*/< Pointer to the HOMER header data */

    uint8_t     * pBuf;        /*/< Pointer to the PNOR data buffer */
    uint32_t      maxPBufSize; /*/< Maximum size of the PNOR data buffer */
    PNOR_Data_t * pData;       /*/< Pointer to the PNOR header data */
    uint32_t      pBufSize;    /*/< Current size of the PNOR data buffer */

    FirData_ListPointers_t hPtrs[TRGT_MAX]; /*/< Pointers to the reg lists */

    HOMER_ChipSpecAddr_t * ecDepReg; /*/< EC dependent regs       */

} FirData_t;

/* Uncomment for additional debug traces */
#if 0
#define DEBUG_PRD_CHKSTOP_ANALYSIS
#endif

/*------------------------------------------------------------------------------ */

/** @brief  Add generic data to the PNOR buffer.
 *  @param  io_fd      The FIR data stuct.
 *  @param  i_data     Pointer to the data to add to the buffer.
 *  @param  i_dataSize Size of the data to add to the buffer.
 *  @return True, if where is no room to add the new data. False, otherwise.
 */
bool FirData_addDataToPnor( FirData_t * io_fd, void * i_data,
                            uint32_t i_dataSize )
{
    bool full = (io_fd->maxPBufSize < io_fd->pBufSize + i_dataSize);
    if ( full )
    {
        /* Indicate the PNOR data is full. */
        io_fd->pData->full = 1;
    }
    else
    {
        /* Copy data to PNOR buffer. */
        uint8_t* l_destPtr = (uint8_t*)(&io_fd->pBuf[io_fd->pBufSize]);
        uint8_t* l_srcPtr  = (uint8_t*)(i_data);
        int i;
        for (i = 0; i < i_dataSize; i++)
        {
            l_destPtr[i] = l_srcPtr[i];
        }
        io_fd->pBufSize += i_dataSize;
    }

    return full;
}

/*------------------------------------------------------------------------------ */

/** @brief  SCOMs hardware and adds a normal register to PNOR.
 *  @param  io_fd     The FIR data stuct.
 *  @param  io_pTrgt  Pointer to PNOR target.
 *  @param  i_sTrgt   SCOM target.
 *  @param  i_addr    32-bit address to SCOM.
 *  @param  o_nonZero True if the value of the register was non-zero. False,
 *                    otherwise.
 *  @return True if the PNOR buffer is full, false if there was room.
 */
bool FirData_addRegToPnor( FirData_t * io_fd, PNOR_Trgt_t * io_pTrgt,
                           SCOM_Trgt_t i_sTrgt, uint32_t i_addr,
                           bool * o_nonZero )
{
    bool full = false;

    int32_t rc = 0;
    PNOR_Reg_t reg = { 0, i_addr };

    *o_nonZero = false;

    do
    {
#ifdef DEBUG_PRD_CHKSTOP_ANALYSIS
        TRAC_ERR( "[FirData_addRegToPnor] t=0x%x p=0x%x u=0x%x scom addr=0x%08x",
                (uint32_t)i_sTrgt.type, (uint32_t)i_sTrgt.procPos,
                (uint32_t)i_sTrgt.procUnitPos, (uint32_t)i_addr);
#endif
        rc = SCOM_getScom( i_sTrgt, i_addr, &(reg.val) );
        if ( SUCCESS != rc )
        {
            TRAC_ERR( "SCOM ERROR: rc=%d t=%u p=%u u=%u",
                      rc, i_sTrgt.type, i_sTrgt.procPos, i_sTrgt.procUnitPos );
            TRAC_ERR( "            addr=0x%08x val=0x%08x%08x",
                      i_addr, (uint32_t)(reg.val >> 32), (uint32_t)reg.val );

            if ( io_pTrgt->scomErrs < PNOR_Trgt_MAX_SCOM_ERRORS )
                io_pTrgt->scomErrs++;

            break;
        }

        // Skip zero value registers.
        if ( 0 == reg.val ) break;

        // Skip chiplet global checkstop registers if only reporting
        // xstop Broadcast via OOB
        if ( ((i_addr & 0x00FFFFFF) == 0x040000) &&
             ((reg.val & 0x3FFFFFFFFFFFFFFF) == 0) ) break;

#ifdef DEBUG_PRD_CHKSTOP_ANALYSIS
        TRAC_IMP("addRegToPnor: got scom value, addr=0x%08X value=0x%08X %08X",
                i_addr, (uint32_t)(reg.val>>32), reg.val);
#endif

        full = FirData_addDataToPnor( io_fd, &reg, sizeof(reg) );
        if ( full ) break;

        *o_nonZero = true;

        if ( io_pTrgt->regs < PNOR_Trgt_MAX_REGS_PER_TRGT )
            io_pTrgt->regs++;

    } while (0);

#ifdef DEBUG_PRD_CHKSTOP_ANALYSIS
    TRAC_IMP("   FirData_addRegToPnor completed for some target ");
#endif

    return full;
}

/*------------------------------------------------------------------------------ */

/** @brief  SCOMs hardware and add a indirect-SCOM register to PNOR.
 *  @param  io_fd     The FIR data stuct.
 *  @param  io_pTrgt  Pointer to PNOR target.
 *  @param  i_sTrgt   SCOM target.
 *  @param  i_sTrgt   Target to SCOM.
 *  @param  i_addr    64-bit address to SCOM.
 *  @param  o_nonZero True if the value of the register was non-zero. False,
 *                    otherwise.
 *  @return True if the PNOR buffer is full, false if there was room.
 */
bool FirData_addIdRegToPnor( FirData_t * io_fd, PNOR_Trgt_t * io_pTrgt,
                             SCOM_Trgt_t i_sTrgt, uint64_t i_addr,
                             bool * o_nonZero )
{
    bool full = false;

    int32_t rc = 0;
    PNOR_IdReg_t reg = { i_addr, 0 };

    *o_nonZero = false;

    do
    {
#ifdef DEBUG_PRD_CHKSTOP_ANALYSIS
        TRAC_ERR( "[FirData_addIdRegToPnor] t=0x%x p=0x%x u=0x%x scom addr=0x%08x",
                    (uint32_t)i_sTrgt.type, (uint32_t)i_sTrgt.procPos,
                    (uint32_t)i_sTrgt.procUnitPos, (uint32_t)i_addr);
#endif
        rc = SCOM_getIdScom( i_sTrgt, i_addr, &(reg.val) );
        if ( SUCCESS != rc )
        {
            if ( io_pTrgt->scomErrs < PNOR_Trgt_MAX_SCOM_ERRORS )
                io_pTrgt->scomErrs++;
            break;
        }


        if ( 0 == reg.val ) break; // Skip zero value registers.

#ifdef DEBUG_PRD_CHKSTOP_ANALYSIS
        TRAC_IMP("addRegToPnor: got scom value, addr=0x%08X %08X value=0x%08X",
                (uint32_t)(i_addr>>32), i_addr, (uint32_t)reg.val);
#endif

        full = FirData_addDataToPnor( io_fd, &reg, sizeof(reg) );
        if ( full ) break;

        *o_nonZero = true;

        if ( io_pTrgt->idRegs < PNOR_Trgt_MAX_ID_REGS_PER_TRGT )
            io_pTrgt->idRegs++;

    } while (0);

    return full;
}

/*------------------------------------------------------------------------------ */

/** @brief  Iterates a list of global registers and adds them to the PNOR.
 *  @param  io_fd    The FIR data stuct.
 *  @param  io_pTrgt Pointer to PNOR target.
 *  @param  i_sTrgt  SCOM target.
 *  @param  o_noAttn True, if the global registers showed no active attentions
 *                   on the target. False, otherwise.
 *  @param  i_chipStruct  Provides chipType and ecLevel we need
 *                        for EC dependent regs
 *
 *  @return True if the PNOR buffer is full, false if there was room.
 */
bool FirData_addGlblsToPnor( FirData_t * io_fd, PNOR_Trgt_t * io_pTrgt,
                             SCOM_Trgt_t i_sTrgt, bool * o_noAttn,
                             HOMER_Chip_t *i_chipStruct )
{
    bool full = false;
    bool l_isAnyGlobal  = false;  /* true when we find global reg      */
    bool l_isAnyNonZero = false;  /* true if ATTN is active on any reg */

    uint8_t t   = i_sTrgt.type;
    uint8_t cnt = io_fd->hData->regCounts[t][REG_GLBL];

    uint32_t i = 0;

    uint32_t addr    = 0;
    bool     nonZero = false;

    *o_noAttn = false; /* Must be false if there are no global regs. */

    if ( 0 != cnt )
    {
        /** If we get here, we have GLOBALS for this target **/
        l_isAnyGlobal = true;

        for ( i = 0; i < cnt; i++ )
        {
            addr    = io_fd->hPtrs[t].glbl[i];
            nonZero = false;

            full = FirData_addRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr,
                                         &nonZero );

            if ( full ) break;

            if ( nonZero ) l_isAnyNonZero = true;
        }
    }


    /** Handle EC dependent registers, if any */
    HOMER_ChipSpecAddr_t  *l_ecAddrtPtr =  io_fd->ecDepReg;
    cnt = io_fd->hData->ecDepCounts;

    /** We have a structure with one element for each EC dep address. */
    /** Need to loop thru and verify we have same regType among       */
    /** other things prior to using the address.                      */
    for ( i = 0; i < cnt; i++ )
    {
#ifdef DEBUG_PRD_CHKSTOP_ANALYSIS
            TRAC_IMP(" addGlblsToPnor In/Array: chipType:%X::%X trgType:%X::%X",
                      (uint32_t)i_chipStruct->chipType, (uint32_t)l_ecAddrtPtr->chipType,
                      (uint32_t)t, (uint32_t)l_ecAddrtPtr->trgtType);
            TRAC_IMP("addGlblsToPnor: regType:%X::%X ecLevel %X::%X",
                      (uint32_t)REG_GLBL, (uint32_t)l_ecAddrtPtr->regType,
                      (uint32_t)i_chipStruct->chipEcLevel, (uint32_t)l_ecAddrtPtr->ddLevel);
#endif

        /** Need same chipType (nimbus,axone,etc..), same target type, */
        /** same register type and EC level must match too             */
        if ( (l_ecAddrtPtr->chipType == i_chipStruct->chipType)     &&
             (l_ecAddrtPtr->trgtType == t )                         &&
             (l_ecAddrtPtr->regType  == REG_GLBL)                   &&
             (l_ecAddrtPtr->ddLevel  == i_chipStruct->chipEcLevel)
           )
        {
            /** If we get here, we have GLOBALS for this target **/
            l_isAnyGlobal = true;

            /* address is right justified in 64 bits */
            addr = (uint32_t)(l_ecAddrtPtr->address);
            nonZero = false;

            full = FirData_addRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr,
                                         &nonZero );
            if ( full ) break;

            if ( nonZero ) l_isAnyNonZero = true;
        } /* end if we found an EC dep reg */

        /* prep pointer for next element (if any) */
        l_ecAddrtPtr++;

    } /** end EC dependent reg loop */

    /* If we have no GLOBALS, we want to collect other regs */
    /*   so then we want to return 'attn is active)'.       */
    /* If we have GLOBALS, then we need non-zero reg to     */
    /*   collect the rest of the regs (attn is active).     */
    if ( (true == l_isAnyGlobal) && (false == l_isAnyNonZero) )
    {
        /* This indicates we won't collect additional regs */
        *o_noAttn = true; /* starts out as false */
    }

    return full;
}

/*------------------------------------------------------------------------------ */

/** @brief  Iterates a list of FIRs and adds them to the PNOR.
 *  @param  io_fd    The FIR data stuct.
 *  @param  io_pTrgt Pointer to PNOR target.
 *  @param  i_sTrgt  SCOM target.
 *  @param  i_chipStruct  Provides chipType and ecLevel we need
 *                        for EC dependent regs
 *
 *  @return True if the PNOR buffer is full, false if there was room.
 */
bool FirData_addFirsToPnor( FirData_t * io_fd, PNOR_Trgt_t * io_pTrgt,
                            SCOM_Trgt_t i_sTrgt,
                            HOMER_Chip_t *i_chipStruct )
{
    bool full = false;

    uint8_t t   = i_sTrgt.type;
    uint8_t cnt = io_fd->hData->regCounts[t][REG_FIR];

    uint32_t i = 0;

    uint32_t addr    = 0;
    bool     nonZero = false;
    bool     tmp     = false; /* ignored, not used */

    for ( i = 0; i < cnt; i++ )
    {
        addr    = io_fd->hPtrs[t].fir[i];
        nonZero = false;

        /* Add FIR */
        full = FirData_addRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr, &nonZero );
        if ( full ) break;

        /* Add MASK */
        full = FirData_addRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr + 3, &tmp );
        if ( full ) break;

        if ( nonZero )
        {
            /* Add ACT0 */
            full = FirData_addRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr + 6,
                                         &tmp );
            if ( full ) break;

            /* Add ACT1 */
            full = FirData_addRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr + 7,
                                         &tmp );
            if ( full ) break;
        }
    }


    /** Handle EC dependent registers, if any */
    HOMER_ChipSpecAddr_t  *l_ecAddrtPtr =  io_fd->ecDepReg;
    cnt = io_fd->hData->ecDepCounts;

    /** We have a structure with one element for each EC dep address. */
    /** Need to loop thru and verify we have same regType among       */
    /** other things prior to using the address.                      */
    for ( i = 0; i < cnt; i++ )
    {
#ifdef DEBUG_PRD_CHKSTOP_ANALYSIS
        TRAC_IMP(" addFirsToPnor In/Array: chipType:%X::%X trgType:%X::%X",
                  (uint32_t)i_chipStruct->chipType, (uint32_t)l_ecAddrtPtr->chipType,
                  (uint32_t)t, (uint32_t)l_ecAddrtPtr->trgtType);
        TRAC_IMP("regType:%X::%X ecLevel %X::%X",
                  (uint32_t)REG_FIR, (uint32_t)l_ecAddrtPtr->regType,
                  (uint32_t)i_chipStruct->chipEcLevel, (uint32_t)l_ecAddrtPtr->ddLevel);
#endif

        /** Need same chipType (nimbus,axone,etc..), same target type, */
        /** same register type and EC level must match too             */
        if ( (l_ecAddrtPtr->chipType == i_chipStruct->chipType)     &&
             (l_ecAddrtPtr->trgtType == t )                         &&
             (l_ecAddrtPtr->regType  == REG_FIR)                    &&
             (l_ecAddrtPtr->ddLevel  == i_chipStruct->chipEcLevel)
           )

        {   /* address is right justified in 64 bits */
            addr = (uint32_t)(l_ecAddrtPtr->address);
            nonZero = false;

            /* Add FIR */
            full = FirData_addRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr, &nonZero );
            if ( full ) break;

            /* Add MASK */
            full = FirData_addRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr + 3, &tmp );
            if ( full ) break;

            if ( nonZero )
            {
                /* Add ACT0 */
                full = FirData_addRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr + 6,
                                             &tmp );
                if ( full ) break;

                /* Add ACT1 */
                full = FirData_addRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr + 7,
                                         &tmp );
                if ( full ) break;
            }

        } /* end if we found an EC dep reg */

        /* prep pointer for next element (if any) */
        l_ecAddrtPtr++;

    } /** end EC dependent reg loop */


    return full;
}

/*------------------------------------------------------------------------------ */

/** @brief  Iterates a list of REGs and adds them to the PNOR.
 *  @param  io_fd    The FIR data stuct.
 *  @param  io_pTrgt Pointer to PNOR target.
 *  @param  i_sTrgt  SCOM target.
 *  @param  i_chipStruct  Provides chipType and ecLevel we need
 *                        for EC dependent regs
 *
 *  @return True if the PNOR buffer is full, false if there was room.
 */
bool FirData_addRegsToPnor( FirData_t * io_fd, PNOR_Trgt_t * io_pTrgt,
                            SCOM_Trgt_t i_sTrgt,
                            HOMER_Chip_t *i_chipStruct )
{
    bool full = false;

    uint8_t t   = i_sTrgt.type;
    uint8_t cnt = io_fd->hData->regCounts[t][REG_REG];

    uint32_t i = 0;

    uint32_t addr    = 0;
    bool     tmp     = false; /* ignored, not used */

    for ( i = 0; i < cnt; i++ )
    {
        addr = io_fd->hPtrs[t].reg[i];

        full = FirData_addRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr, &tmp );
        if ( full ) break;
    }

    /** Handle EC dependent registers, if any */
    HOMER_ChipSpecAddr_t  *l_ecAddrtPtr =  io_fd->ecDepReg;
    cnt = io_fd->hData->ecDepCounts;

    /** We have a structure with one element for each EC dep address. */
    /** Need to loop thru and verify we have same regType among       */
    /** other things prior to using the address.                      */
    for ( i = 0; i < cnt; i++ )
    {
#ifdef DEBUG_PRD_CHKSTOP_ANALYSIS
        TRAC_IMP(" addRegsToPnor In/Array: chipType:%X::%X trgType:%X::%X",
                  i_chipStruct->chipType, l_ecAddrtPtr->chipType,
                  t, l_ecAddrtPtr->trgtType);
        TRAC_IMP(" regType:%X::%X ecLevel %X::%X",
                  REG_GLBL, l_ecAddrtPtr->regType,
                  i_chipStruct->chipEcLevel, l_ecAddrtPtr->ddLevel );
#endif

        /** Need same chipType (nimbus,axone,etc..), same target type, */
        /** same register type and EC level must match too             */
        if ( (l_ecAddrtPtr->chipType == i_chipStruct->chipType)     &&
             (l_ecAddrtPtr->trgtType == t )                         &&
             (l_ecAddrtPtr->regType  == REG_REG)                    &&
             (l_ecAddrtPtr->ddLevel  == i_chipStruct->chipEcLevel)
           )
        {   /* address is right justified in 64 bits */
            addr = (uint32_t)(l_ecAddrtPtr->address);

            full = FirData_addRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr,
                                         &tmp );
            if ( full ) break;
        } /* end if we found an EC dep reg */

        /* prep pointer for next element (if any) */
        l_ecAddrtPtr++;

    } /** end EC dependent reg loop */

    return full;
}

/*------------------------------------------------------------------------------ */

/** @brief  Iterates a list of IDFIRs and adds them to the PNOR.
 *  @param  io_fd    The FIR data stuct.
 *  @param  io_pTrgt Pointer to PNOR target.
 *  @param  i_sTrgt  SCOM target.
 *  @param  i_chipStruct  Provides chipType and ecLevel we need
 *                        for EC dependent regs
 *
 *  @return True if the PNOR buffer is full, false if there was room.
 */
bool FirData_addIdFirsToPnor( FirData_t * io_fd, PNOR_Trgt_t * io_pTrgt,
                              SCOM_Trgt_t i_sTrgt,
                              HOMER_Chip_t *i_chipStruct )
{
    bool full = false;

    uint8_t t   = i_sTrgt.type;
    uint8_t cnt = io_fd->hData->regCounts[t][REG_IDFIR];

    uint32_t i = 0;

    uint64_t addr    = 0;
    bool     nonZero = false;
    bool     tmp     = false; /* ignored, not used */

    for ( i = 0; i < cnt; i++ )
    {
        addr    = io_fd->hPtrs[t].idFir[i];
        nonZero = false;

        /* Add FIR */
        full = FirData_addIdRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr,
                                       &nonZero );
        if ( full ) break;

        /* Add MASK */
        full = FirData_addIdRegToPnor( io_fd, io_pTrgt, i_sTrgt,
                                       addr + 0x300000000ll, &tmp );
        if ( full ) break;

        if ( nonZero )
        {
            /* Add ACT0 */
            full = FirData_addIdRegToPnor( io_fd, io_pTrgt, i_sTrgt,
                                           addr + 0x600000000ll, &tmp );
            if ( full ) break;

            /* Add ACT1 */
            full = FirData_addIdRegToPnor( io_fd, io_pTrgt, i_sTrgt,
                                           addr + 0x700000000ll, &tmp );
            if ( full ) break;
        }
    }


    /** Handle EC dependent registers, if any */
    HOMER_ChipSpecAddr_t  *l_ecAddrtPtr =  io_fd->ecDepReg;
    cnt = io_fd->hData->ecDepCounts;

    /** We have a structure with one element for each EC dep address. */
    /** Need to loop thru and verify we have same regType among       */
    /** other things prior to using the address.                      */
    for ( i = 0; i < cnt; i++ )
    {
#ifdef DEBUG_PRD_CHKSTOP_ANALYSIS
        TRAC_IMP(" addIdFirsToPnor In/Array: chipType:%X::%X trgType:%X::%X",
                  i_chipStruct->chipType, l_ecAddrtPtr->chipType,
                  t, l_ecAddrtPtr->trgtType);
        TRAC_IMP(" regType:%X::%X ecLevel %X::%X",
                  REG_GLBL, l_ecAddrtPtr->regType,
                  i_chipStruct->chipEcLevel, l_ecAddrtPtr->ddLevel );
#endif

        /** Need same chipType (nimbus,axone,etc..), same target type, */
        /** same register type and EC level must match too             */
        if ( (l_ecAddrtPtr->chipType == i_chipStruct->chipType)     &&
             (l_ecAddrtPtr->trgtType == t )                         &&
             (l_ecAddrtPtr->regType  == REG_IDFIR)                  &&
             (l_ecAddrtPtr->ddLevel  == i_chipStruct->chipEcLevel)
           )
        {   /* need full 64 bit address here */
            addr = l_ecAddrtPtr->address;
            nonZero = false;

            /* Add FIR */
            full = FirData_addIdRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr,
                                           &nonZero );
            if ( full ) break;

            /* Add MASK */
            full = FirData_addIdRegToPnor( io_fd, io_pTrgt, i_sTrgt,
                                           addr + 0x300000000ll, &tmp );
            if ( full ) break;

            if ( nonZero )
            {
                /* Add ACT0 */
                full = FirData_addIdRegToPnor( io_fd, io_pTrgt, i_sTrgt,
                                               addr + 0x600000000ll, &tmp );
                if ( full ) break;

                /* Add ACT1 */
                full = FirData_addIdRegToPnor( io_fd, io_pTrgt, i_sTrgt,
                                               addr + 0x700000000ll, &tmp );
                if ( full ) break;
            }

        } /* end if we found an EC dep reg */

        /* prep pointer for next element (if any) */
        l_ecAddrtPtr++;

    } /** end EC dependent reg loop */

    return full;
}

/*------------------------------------------------------------------------------ */

/** @brief  Iterates a list of IDREGs and adds them to the PNOR.
 *  @param  io_fd    The FIR data stuct.
 *  @param  io_pTrgt Pointer to PNOR target.
 *  @param  i_sTrgt  SCOM target.
 *  @param  i_chipStruct  Provides chipType and ecLevel we need
 *                        for EC dependent regs
 *
 *  @return True if the PNOR buffer is full, false if there was room.
 */
bool FirData_addIdRegsToPnor( FirData_t * io_fd, PNOR_Trgt_t * io_pTrgt,
                              SCOM_Trgt_t i_sTrgt,
                              HOMER_Chip_t *i_chipStruct )
{
    bool full = false;

    uint8_t t   = i_sTrgt.type;
    uint8_t cnt = io_fd->hData->regCounts[t][REG_IDREG];

    uint32_t i = 0;

    uint64_t addr    = 0;
    bool     tmp     = false; /* ignored, not used */

    for ( i = 0; i < cnt; i++ )
    {
        addr = io_fd->hPtrs[t].idReg[i];

        full = FirData_addIdRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr, &tmp );
        if ( full ) break;
    }


    /** Handle EC dependent registers, if any */
    HOMER_ChipSpecAddr_t  *l_ecAddrtPtr =  io_fd->ecDepReg;
    cnt = io_fd->hData->ecDepCounts;

    /** We have a structure with one element for each EC dep address. */
    /** Need to loop thru and verify we have same regType among       */
    /** other things prior to using the address.                      */
    for ( i = 0; i < cnt; i++ )
    {
#ifdef DEBUG_PRD_CHKSTOP_ANALYSIS
        TRAC_IMP(" addIdRegsToPnor In/Array: chipType:%X::%X trgType:%X::%X",
                  i_chipStruct->chipType, l_ecAddrtPtr->chipType,
                  t, l_ecAddrtPtr->trgtType);
        TRAC_IMP(" regType:%X::%X ecLevel %X::%X",
                  REG_GLBL, l_ecAddrtPtr->regType,
                  i_chipStruct->chipEcLevel, l_ecAddrtPtr->ddLevel );
#endif

        /** Need same chipType (nimbus,axone,etc..), same target type, */
        /** same register type and EC level must match too             */
        if ( (l_ecAddrtPtr->chipType == i_chipStruct->chipType)     &&
             (l_ecAddrtPtr->trgtType == t )                         &&
             (l_ecAddrtPtr->regType  == REG_IDREG)                  &&
             (l_ecAddrtPtr->ddLevel  == i_chipStruct->chipEcLevel)
           )
        {   /* Using full 64 bit address here */
            addr = l_ecAddrtPtr->address;

            full = FirData_addIdRegToPnor( io_fd, io_pTrgt, i_sTrgt, addr, &tmp );
            if ( full ) break;
        } /* end if we found an EC dep reg */

        /* prep pointer for next element (if any) */
        l_ecAddrtPtr++;

    } /** end EC dependent reg loop */


    return full;
}


/*------------------------------------------------------------------------------ */

/** @brief  Adds a target to the PNOR.
 *  @param  io_fd    The FIR data stuct.
 *  @param  i_sTrgt   SCOM Target.
 *  @param  o_noAttn True, if the global registers showed no active
 *                   attentions on the target. False, otherwise.
 *  @param  i_chipStruct  Provides chipType and ecLevel we need
 *                        for EC dependent regs
 *
 *  @return True if the PNOR buffer is full, false if there was room.
 */
bool FirData_addTrgtToPnor( FirData_t * io_fd, SCOM_Trgt_t i_sTrgt,
                            bool * o_noAttn, HOMER_Chip_t *i_chipStruct )
{
    bool full = false;
    PNOR_Trgt_t * pTrgt = (PNOR_Trgt_t *)(&io_fd->pBuf[io_fd->pBufSize]);


    /* may be able to remove   PNOR_getTrgt  function */
    /* had some issue with local var return in diff function so take out */
    /* init to zero */
    PNOR_Trgt_t tmp_pTrgt; memset( &tmp_pTrgt, 0x00, sizeof(tmp_pTrgt) );

    tmp_pTrgt.trgtType = i_sTrgt.type;
    tmp_pTrgt.chipPos  = i_sTrgt.procPos,
    tmp_pTrgt.unitPos  = i_sTrgt.procUnitPos;

    *o_noAttn = false; /* Must be false if there are no global regs. */

#ifdef DEBUG_PRD_CHKSTOP_ANALYSIS
    TRAC_IMP( "FIRDATA: t=%d p=%d u=%d FSI=0x%08x", i_sTrgt.type,
              i_sTrgt.procPos, i_sTrgt.procUnitPos, (uint32_t)i_sTrgt.fsiBaseAddr);
#endif

    do
    {
        /* Add the target info to PNOR. */
        full = FirData_addDataToPnor( io_fd, &tmp_pTrgt, sizeof(tmp_pTrgt) );

        if ( full ) break;

        /* Update the number of targets in the PNOR data. */
        io_fd->pData->trgts++;

        /* NOTE: Must add all regular registers (REG_GLBL, REG_FIR, REG_REG)
         *       before all indirect-SCOM registers. Also, must check REG_GLBL
         *       registers first to determine whether it is necessary to do the
         *       other registers. */

        /* Add the GLBLs. */
        full = FirData_addGlblsToPnor( io_fd, pTrgt, i_sTrgt, o_noAttn, i_chipStruct );
        if ( full || *o_noAttn ) break;

        /* Add the FIRs. */
        full = FirData_addFirsToPnor( io_fd, pTrgt, i_sTrgt, i_chipStruct );
        if ( full ) break;

        /* Add the REGs. */
        full = FirData_addRegsToPnor( io_fd, pTrgt, i_sTrgt, i_chipStruct );
        if ( full ) break;

        /* Add the IDFIRs. */
        full = FirData_addIdFirsToPnor( io_fd, pTrgt, i_sTrgt, i_chipStruct );
        if ( full ) break;

        /* Add the IDREGs. */
        full = FirData_addIdRegsToPnor( io_fd, pTrgt, i_sTrgt, i_chipStruct );
        if ( full ) break;

    } while (0);

    return full;
}


/*----------------------------------------------------------------------------*/

/** @brief Iterates through configured targets and adds the data to PNOR.
 *  @param io_fd The FIR data stuct.
 */
void FirData_addTrgtsToPnor( FirData_t * io_fd )
{
    uint8_t u  = 0;
    uint8_t l_unit = 0;

    // We will need to keep track of where we are in the HOMER buffer.
    uint8_t * byteIdx = io_fd->hBuf;

    // We already have a pointer to the HOMER header data io_fd->hData. So skip
    // past it.
    byteIdx += sizeof(HOMER_Data_t);

    // The HOMER_Data_t struct may have some padding added after the struct to
    // ensure the HOMER_Chip_t structs are 4-byte word aligned.
    uint32_t sz_word = sizeof(uint32_t);
    uint32_t pad = (sz_word - (sizeof(HOMER_Data_t) % sz_word)) % sz_word;
    byteIdx += pad;

    // Start iterating all chips in the HOMER data.
    uint32_t i = 0;
    for ( i = 0; i < io_fd->hData->chipCount; i++ )
    {
        // Keep a pointer of the current chip header.
        HOMER_Chip_t * chipHdr = (HOMER_Chip_t *) byteIdx;
        byteIdx += sizeof(HOMER_Chip_t);

        // Get FSI base address and chip position.
        uint32_t fsi = chipHdr->fsiBaseAddr;
        uint8_t  p   = chipHdr->chipPos;

        bool full   = false; // PNOR data is full so exit
        bool noAttn = false; // No attns found, continue to next chip or unit

        SCOM_Trgt_t sTrgt; // Chip or unit SCOM target
        bool isM = false;  // Is this chip the master processor?

        // Various other variables used below.
        uint32_t mask = 0;

#define PROC_MAX(TYPE) MAX_##TYPE##_PER_PROC

#define ADD_TO_PNOR( TYPE, UNIT ) \
    sTrgt = SCOM_Trgt_getTrgt( TRGT_##TYPE, p, (UNIT), fsi, isM ); \
    full = FirData_addTrgtToPnor( io_fd, sTrgt, &noAttn, chipHdr ); \
    if ( full ) break; \
    if ( noAttn ) continue;

#define ADD_UNIT_TO_PNOR( MASK, TYPE, UNIT ) \
    mask = 1 << ((PROC_MAX(TYPE)-1) - UNIT); \
    if ( 0 == (chipData->MASK & mask) ) continue; \
    ADD_TO_PNOR( TYPE, UNIT )

        if ( HOMER_CHIP_NIMBUS == chipHdr->chipType )
        {
            // Keep a pointer of the current chip data.
            HOMER_ChipNimbus_t * chipData = (HOMER_ChipNimbus_t *) byteIdx;
            byteIdx += sizeof(HOMER_ChipNimbus_t);

            isM = chipData->isMaster;

            ADD_TO_PNOR( PROC, 0 )

            /* gather other chiplets on the processor */
            for ( u = 0; u < MAX_XBUS_PER_PROC; u++ )
            {
                ADD_UNIT_TO_PNOR( xbusMask, XBUS, u )
            }
            if ( full ) break;

            /* gather other chiplets on the processor */
            for ( u = 0; u < MAX_OBUS_PER_PROC; u++ )
            {
                ADD_UNIT_TO_PNOR( obusMask, OBUS, u )
            }
            if ( full ) break;

            /* gather more proc chiplets  */
            for ( u = 0; u < MAX_CAPP_PER_PROC; u++ )
            {
                ADD_UNIT_TO_PNOR( cappMask, CAPP, u )
            }
            if ( full ) break;

            /* gather other chiplets on the processor */
            for ( u = 0; u < MAX_PEC_PER_PROC; u++ )
            {
                ADD_UNIT_TO_PNOR( pecMask, PEC, u )

                /* gather PHB's under the PEC  */
                /*  ************************** */
                /*  PEC0-> PHB0                */
                /*  PEC1-> PHB1 PHB2           */
                /*  PEC2-> PHB3 PHB4 PHB5      */
                /*  ************************** */
                uint32_t l_PhbPos;

                /* u will be 0, l_unit 0             */
                /* u will be 1, l_unit 0 and 1       */
                /* u will be 2, l_unit 0 and 1 and 2 */
                for ( l_unit = 0; l_unit < (u+1); l_unit++ )
                {
                    l_PhbPos = u + l_unit;
                    /** When we hit PEC2, need to bump PHB position */
                    if  ((MAX_PEC_PER_PROC - 1) == u)
                    {
                        l_PhbPos++;
                    } /* if last PEC unit */

                    ADD_UNIT_TO_PNOR( phbMask, PHB, l_PhbPos )

                } /* end for on PHB chiplet */
                if ( full ) break;

            } /* end for on PEC chiplet */
            if ( full ) break;

            /* gather other chiplets on the processor */
            for ( u = 0; u < MAX_EC_PER_PROC; u++ )
            {
                ADD_UNIT_TO_PNOR( ecMask, EC, u )

            } /* end for on EC chiplet */
            if ( full ) break;

            /* gather other chiplets on the processor */
            for ( u = 0; u < MAX_EQ_PER_PROC; u++ )
            {
                ADD_UNIT_TO_PNOR( eqMask, EQ, u )

                /* gather other chiplets on the processor */
                uint32_t l_ExPerEq = (MAX_EX_PER_PROC/MAX_EQ_PER_PROC);
                uint32_t l_ExPos;

                for (l_unit=0; l_unit < l_ExPerEq; l_unit++)
                {
                    l_ExPos = (l_ExPerEq * u) + l_unit;

                    ADD_UNIT_TO_PNOR( exMask, EX, l_ExPos )

                } /* end for on EX chiplet */
                if ( full ) break;

            } /* end for on EQ chiplet */
            if ( full ) break;


            /* processor type can impact next few units */
            uint32_t l_UnitPerMc = MAX_MCA_PER_PROC / MAX_MCBIST_PER_PROC;
            uint8_t  l_unitNumber;

            for ( u = 0; u < MAX_MCBIST_PER_PROC; u++ )
            {
                ADD_UNIT_TO_PNOR( mcbistMask, MCBIST, u )

                /* Grab underlying MCA chiplet */
                for ( l_unit = 0; l_unit < l_UnitPerMc; l_unit++ )
                {
                    /* u=0 or 1 while  l_unit is 0 thru 3 */
                    /* Leading to unit number 0:3 or 4:7  */
                    l_unitNumber = l_unit + (u * l_UnitPerMc);
                    ADD_UNIT_TO_PNOR( mcaMask, MCA, l_unitNumber )

                } /* end for on MCA/DMI */
                if ( full ) break;

            } /* end for on MCBIST */
            if ( full ) break;


            for ( u = 0; u < MAX_MCS_PER_PROC; u++ )
            {
                ADD_UNIT_TO_PNOR( mcsMask, MCS, u )
            }
            if ( full ) break;

        }
        else
        {
            TRAC_ERR( "[FirData_addTrgtsToPnor] invalid chip type:0x%x",
                      (uint32_t)chipHdr->chipType );
            break;
        }

#undef PROC_MAX
#undef ADD_TO_PNOR
#undef ADD_UNIT_TO_PNOR

    }
}

/*------------------------------------------------------------------------------ */

/** @brief  Initializes the FIR data struct. Does range checking for the HOMER
 *          data. Initializes the PNOR header data.
 *  @param  io_fd      The FIR data stuct.
 *  @param  i_hBuf     SRAM pointer to the beginning of the HOMER data buffer.
 *                     This should contain the FIR data information provided by
 *                     PRD that is used to define which registers the OCC will
 *                     need to SCOM.
 *  @param  i_hBufSize Total size of the HOMER data buffer.
 *  @param  i_pBuf     SRAM pointer to the beginning of the PNOR data buffer.
 *                     This will be used by this function as a temporary area of
 *                     memory to store the PNOR data before writing that data to
 *                     the PNOR.
 *  @param  i_pBufSize Total size of the PNOR data buffer.
 *  @return Non-SUCCESS if HOMER or PNOR range checking fails or if an
 *          internal function fails. SUCCESS otherwise.
 */
int32_t FirData_init( FirData_t * io_fd,
                      uint8_t * i_hBuf, uint32_t i_hBufSize,
                      uint8_t * i_pBuf, uint32_t i_pBufSize )
{
    #define FUNC "[FirData_init] "

    int32_t rc = SUCCESS;

    uint32_t sz_hData    = sizeof(HOMER_Data_t);
    uint32_t sz_u32      = sizeof(uint32_t);
    uint32_t sz_u64      = sizeof(uint64_t);

    bool full = false;

    uint32_t x[TRGT_MAX][REG_MAX];
    uint32_t curIdx = 0;

    uint32_t t = TRGT_FIRST;

    uint8_t * reglist = NULL;

    do
    {
        /* Init the struct. */
        io_fd->hBuf        = i_hBuf;
        io_fd->maxHBufSize = i_hBufSize;
        io_fd->hData       = (HOMER_Data_t *)i_hBuf;

        io_fd->pBuf        = i_pBuf;
        io_fd->maxPBufSize = i_pBufSize;
        io_fd->pData       = (PNOR_Data_t *)i_pBuf;
        io_fd->pBufSize    = 0;

        memset( io_fd->hPtrs, 0x00, sizeof(io_fd->hPtrs) );

        /* Check HOMER header data size. */
        if ( io_fd->maxHBufSize < sz_hData )
        {
            TRAC_ERR( FUNC"HOMER header data size %d is larger than HOMER "
                      "data buffer %d", sz_hData, io_fd->maxHBufSize );
            rc = FAIL;
            break;
        }

        /* Check for valid HOMER data. */
        if ( HOMER_FIR2 != io_fd->hData->header )
        {
            break; /* nothing to analyze. */
        }

        /* The actual max PNOR size may possibly be less then the PNOR data */
        /* buffer. If so, adjust maximum size. Hostboot already handled ECC.*/
        /* We have to use smaller of what OCC or Hostboot has.              */
        if ( io_fd->hData->pnorInfo.pnorSize < io_fd->maxPBufSize )
            io_fd->maxPBufSize = io_fd->hData->pnorInfo.pnorSize;

        /* Initialize the PNOR header data. */
        PNOR_Data_t pData;
        memset( &pData, 0x00, sizeof(pData) ); /* init to zero */
        pData.header = PNOR_FIR2;

        full = FirData_addDataToPnor( io_fd, &pData, sizeof(pData) );
        if ( full )
        {
            TRAC_ERR( FUNC"Unable to add header to PNOR buffer" );
            rc = FAIL;
            break;
        }

        /* Copy the IPL state from the HOMER data to the PNOR data. */
        io_fd->pData->iplState = io_fd->hData->iplState;

        /* Get the register list byte indexes in HOMER data buffer */
        memset( x, 0x00, sizeof(x) );
        for ( t = TRGT_FIRST; t < TRGT_MAX; t++ )
        {
            x[t][REG_GLBL]  = curIdx;
            x[t][REG_FIR]   = x[t][REG_GLBL]  + sz_u32 * io_fd->hData->regCounts[t][REG_GLBL];
            x[t][REG_REG]   = x[t][REG_FIR]   + sz_u32 * io_fd->hData->regCounts[t][REG_FIR];
            x[t][REG_IDFIR] = x[t][REG_REG]   + sz_u32 * io_fd->hData->regCounts[t][REG_REG];
            x[t][REG_IDREG] = x[t][REG_IDFIR] + sz_u64 * io_fd->hData->regCounts[t][REG_IDFIR];
            curIdx          = x[t][REG_IDREG] + sz_u64 * io_fd->hData->regCounts[t][REG_IDREG];
        }

        /* Check to make sure the list data is not larger than the available */
        /* Homer buffer. */
        if ( io_fd->maxHBufSize - sz_hData < curIdx )
        {
            TRAC_ERR( "HOMER list size %d is larger than HOMER data buffer %d",
                    curIdx, (io_fd->maxHBufSize - sz_hData ));
            rc = FAIL;
            break;
        }

        /* Now, skip chip sections. Note that the HOMER_Data_t struct may have
         * some padding added after the struct to ensure the HOMER_Chip_t
         * structs are 4-byte word aligned. */
        uint32_t pad = (sz_u32 - (sz_hData % sz_u32)) % sz_u32;
        reglist = io_fd->hBuf + sz_hData + pad;
        HOMER_Chip_t   *l_chiptPtr = NULL;

        /* Need to skip over chip list **/
        uint32_t  l_chipNum;
        for ( l_chipNum=0;
             (l_chipNum <  io_fd->hData->chipCount);
              l_chipNum++ )
        {
            l_chiptPtr = (HOMER_Chip_t *)reglist;

            /* Skip section on chip type, chip position, etc... */
            reglist += sizeof(HOMER_Chip_t);

            /* 'Existing chiplet area' varies in size  */
            if (HOMER_CHIP_NIMBUS == l_chiptPtr->chipType)
            {
                reglist += sizeof(HOMER_ChipNimbus_t);
            }
            else
            {
                TRAC_ERR(FUNC"Chiptype is invalid %X ", (uint32_t)l_chiptPtr->chipType);
                rc = FAIL;
                break;
            }

        } /* end for loop skipping chip info sections */


        /* Now, get the pointers for each list. */
        for ( t = TRGT_FIRST; t < TRGT_MAX; t++ )
        {
            (io_fd->hPtrs[t]).glbl  = (uint32_t *)(reglist + x[t][REG_GLBL] );
            (io_fd->hPtrs[t]).fir   = (uint32_t *)(reglist + x[t][REG_FIR]  );
            (io_fd->hPtrs[t]).reg   = (uint32_t *)(reglist + x[t][REG_REG]  );
            (io_fd->hPtrs[t]).idFir = (uint64_t *)(reglist + x[t][REG_IDFIR]);
            (io_fd->hPtrs[t]).idReg = (uint64_t *)(reglist + x[t][REG_IDREG]);
        }

        /* Set EC level dep reg list ptr - at very end of list */
        io_fd->ecDepReg = (HOMER_ChipSpecAddr_t *)(reglist + curIdx);


    } while (0);
    TRAC_IMP("FirData_init done");

    return rc;

    #undef FUNC
}

/*------------------------------------------------------------------------------ */
/* External functions */
/*------------------------------------------------------------------------------ */

int32_t FirData_captureCsFirData( uint8_t * i_hBuf, uint32_t i_hBufSize,
                                  uint8_t * i_pBuf, uint32_t i_pBufSize )
{
    #define FUNC "[FirData_captureCsFirData] "

    int32_t rc = SUCCESS;

    do
    {
        /* Init the FIR data struct. */
        FirData_t fd;
        rc = FirData_init( &fd, i_hBuf, i_hBufSize, i_pBuf, i_pBufSize );
        if ( SUCCESS != rc )
        {
            TRAC_ERR( FUNC"Failed to init FIR data" );
            break;
        }

#ifdef DEBUG_PRD_CHKSTOP_ANALYSIS
        TRAC_IMP("going to print all pointers from fd");
        TRAC_IMP("hBuf:0x%08X, maxHbufSize:0x%08X, hData:0x%08X",
                (uint32_t)(fd.hBuf), (uint32_t)(fd.maxHBufSize), (uint32_t)(fd.hData));
        TRAC_IMP("pBuf:0x%08X, maxPBufSize:0x%08X, pData:0x%08X, pBufSize:0x%08X",
                (uint32_t)(fd.pBuf), (uint32_t)(fd.maxPBufSize), (uint32_t)(fd.pData),
                (uint32_t)(fd.pBufSize));
        TRAC_IMP("hPtrs:0x%08X, ecDepRegs:0x%08X", (uint32_t)(fd.hPtrs),
                (uint32_t)(fd.ecDepReg));
#endif

        /* Check for valid HOMER data. */
        if ( HOMER_FIR2 != fd.hData->header )
        {
            TRAC_ERR( FUNC"No HOMER data detected: header=0x%08x",
                      fd.hData->header );
            break; /* nothing to analyze. */
        }

        FirData_addTrgtsToPnor( &fd );

        /* Write Buffer to PNOR */
        rc = PNOR_writeFirData( fd.hData->pnorInfo, fd.pBuf, fd.pBufSize );
        if ( SUCCESS != rc )
        {
            TRAC_ERR( FUNC"Failed to process FIR data" );
            break;
        }

    } while (0);

    if ( SUCCESS != rc )
    {
        TRAC_ERR( "Failed: i_hBuf=%p, i_hBufSize=0x%08x, i_pBuf=%p, "
                  "i_pBufSize=%08x", (uint32_t)i_hBuf, (uint32_t)i_hBufSize,
                  (uint32_t)i_pBuf, (uint32_t)i_pBufSize );
    }

    return rc;

    #undef FUNC
}

OpenPOWER on IntegriCloud