summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/framework/rule/prdfRuleChip.C
blob: 5a0f1f5d1aa8b2313f61fcb9d7b462786e5c1691 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/framework/rule/prdfRuleChip.C $             */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2004,2012              */
/*                                                                        */
/* 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                                                     */

#ifndef __HOSTBOOT_MODULE
  #include <utilreg.H> // for UtilReg
  #include <prdfMfgThresholdMgr.H>
  #include <prdfSdcFileControl.H> //for SyncAnalysis
#endif

#include <iipglobl.h> // for SystemPtr.

#include <prdfRuleChip.H>
#include <prdrLoadChip.H>
#include <prdrLoadChipCache.H>
#include <prdfOperatorRegister.H>
#include <prdfGroup.H>
#include <prdfPluginMap.H>
#include <prdrCommon.H> // for enums.

#include <prdfScanFacility.H> // for ScanFacility
#include <iipResolutionFactory.h> // for ResolutionFactory
#include <iipCaptureData.h> // for CaptureData
#include <iipServiceDataCollector.h> // for ServiceDataCollector
#include <prdfErrorSignature.H> // for ErrorSignature
#include <iipResolution.h> // for Resolutions
#include <iipEregResolution.h> // for EregResolution
#include <xspprdDumpResolution.h> // for DumpResolution
#include <xspprdTryResolution.h> // for TryResolution
#include <prdfPluginCallResolution.H> // for PrdfPluginCallResolution
#include <prdfAnalyzeConnected.H> // for prdfAnalyzeConnected
#include <iipSystem.h> // for System
#include <xspprdFlagResolution.h>
#include <prdfPfa5Data.h> // for errl user data flags.

#include <prdfPlatServices.H> // for getConnected

#include <errlentry.H> // for errl.
#include <utilfile.H>  // for UtilFile
#include <UtilHash.H> // for Util::hashString

#include <prdfResetOperators.H>
#include <algorithm>

template <bool Type>
struct ResetAndMaskTransformer
    : public std::unary_function<Prdr::PrdrRegister::ResetOrMaskStruct,
                                 ResetAndMaskErrorRegister::ResetRegisterStruct>
{
    ResetAndMaskTransformer(ScanFacility & i_scanFactory,
                            TARGETING::TargetHandle_t i_pchipHandle ,
                            size_t i_scomlen)
            : cv_scanFactory(i_scanFactory),
              cv_pchipHandle (i_pchipHandle ),
              cv_scomlen(i_scomlen)
        {};

    virtual ~ResetAndMaskTransformer() {};  // zs01

    virtual ResetAndMaskErrorRegister::ResetRegisterStruct
        operator()(const Prdr::PrdrRegister::ResetOrMaskStruct & i)
    {
        ResetAndMaskErrorRegister::ResetRegisterStruct o;

        o.read = &cv_scanFactory.GetScanCommRegister(cv_pchipHandle ,
                                                     i.addr_r,
                                                     cv_scomlen);
        o.write = &cv_scanFactory.GetScanCommRegister(cv_pchipHandle ,
                                                      i.addr_w,
                                                      cv_scomlen);

        switch (i.op)
        {
            case Prdr::OR:
                o.op = getStaticResetOperator<OrOperator<Type> >();
                break;

            case Prdr::AND:
                o.op = getStaticResetOperator<AndOperator<Type> >();
                break;

            case Prdr::XOR:
                o.op = getStaticResetOperator<XorOperator<Type> >();
                break;

            case Prdr::NOT:
                o.op = getStaticResetOperator<NotOperator<Type> >();
                break;

            default:
                o.op = NULL; // TODO: ERROR!  Assert...
                break;
        }

        return o;
    };

    private:
        ScanFacility & cv_scanFactory;
        TARGETING::TargetHandle_t  cv_pchipHandle ;
        size_t cv_scomlen;
};


void PrdfRuleChip::loadRuleFile(ScanFacility & i_scanFactory,
                                ResolutionFactory & i_reslFactory)
{
    using namespace PRDF;

    RegMap_t l_regMap;
    Reset_t l_resetMap;
    PrdfResetAndMaskPair l_currentResets;
    uint32_t l_regMax = 0;
    uint32_t l_vregMax = 0;
    GroupMap_t l_groupMap;
    uint32_t l_groupMax = 0;
    ActionMap_t l_actionMap;
    uint32_t l_actionMax = 0;
    uint32_t l_id = 1;

    SharedThreshold_t l_sharedThresholds;

    Prdr::PrdrChip * l_chip;

    /* Initialize local data struct to pass to sub-functions */
    RuleFileData l_localData = { l_regMap, l_groupMap, l_actionMap,
                                 i_scanFactory, i_reslFactory,
                                 this->GetChipHandle(), l_chip,
                                 l_resetMap, l_currentResets,
                                 l_sharedThresholds
                               };

    // Parse chip file.
    cv_errl = Prdr::LoadChipCache::loadChip(cv_fileName, &l_chip);
    if (NULL == l_chip)
    {
        // TODO: Do we need to percAbend?  We were unable to succesfully
        // load our chip objects.
        return;
    }

    // Get default dump type.
    cv_dumpType = l_chip->cv_dumpType;

    // Set signature offset for capture data output.
    iv_sigOff = l_chip->cv_signatureOffset;

    // create hardware regs.
    for (int i = 0; i < l_chip->cv_regCount; i++)
    {
        uint16_t hashId = l_chip->cv_registers[i].cv_name;

        l_regMap[l_id] = cv_hwRegs[hashId]
                       = &i_scanFactory.GetScanCommRegister(
                                        this->GetChipHandle(),
                                        l_chip->cv_registers[i].cv_scomAddr,
                                        l_chip->cv_registers[i].cv_scomLen );
        l_regMap[l_id]->SetId(hashId);

        // Copy reset registers.
        std::transform
                (l_chip->cv_registers[i].cv_resets.begin(),
                 l_chip->cv_registers[i].cv_resets.end(),
                 std::back_inserter(l_resetMap[l_id].first),
                 ResetAndMaskTransformer<RESETOPERATOR_RESET>(
                        i_scanFactory,
                        this->GetChipHandle(),
                        l_chip->cv_registers[i].cv_scomLen)
                );

        // Copy mask registers.
        std::transform
                (l_chip->cv_registers[i].cv_masks.begin(),
                 l_chip->cv_registers[i].cv_masks.end(),
                 std::back_inserter(l_resetMap[l_id].second),
                 ResetAndMaskTransformer<RESETOPERATOR_MASK>(
                        i_scanFactory,
                        this->GetChipHandle(),
                        l_chip->cv_registers[i].cv_scomLen)
                );

        //This flag signifies that a mapping IS or ISN'T created between a
        //  uint32_t mapping and a vector of SCAN_COMM_REGISTER_CLASS pointers.
        //If there is no mapping outside of the for loop then it is because
        //  there is a capture type or requirement without a group statement in the rule file.
        bool l_group_is_created = false;
        // Copy into capture groups.
        std::vector<Prdr::PrdrRegister::CaptureInfoStruct>::const_iterator
            l_capturesEnd = l_chip->cv_registers[i].cv_captures.end();
        //For each capture in this register save a Group Type or Requirement.
        for(std::vector<Prdr::PrdrRegister::CaptureInfoStruct>::const_iterator
                j = l_chip->cv_registers[i].cv_captures.begin();
            j != l_capturesEnd;
            ++j)
        {
            if ('G' == (*j).op)
            {
                cv_hwCaptureGroups[(*j).data[0]].push_back(l_regMap[l_id]);
                l_group_is_created = true;   //@jl06 Added this to indicate group was created.
            }
            // @jl04 a  Start.
            // This else if was added for a new capture "type" for registers primary/secondary.
            // Cannot put the "type" in with the G group otherwise it will show up as a
            //   i_group of 2 which is not called.
            else if('T' == (*j).op)
            {
                //@jl06. d Deleted temporary declaration of PrdfCaptureType in
                //         favor of an anonymous declaration.  Calls ctor twice.
                cv_hwCaptureType[l_regMap[l_id]] =
                 PrdfCaptureType((RegType)(*j).data[0]); //@jl06 c.
            }
            // @jl04 a Stop.
            else if ('f' == (*j).op)
            {
                PrdfCaptureRequirement req;
                req.cv_func = this->getExtensibleFunction(j->func);

                cv_hwCaptureReq[l_regMap[l_id]] = req;
            }
            else // 'C'
            {
                PrdfCaptureRequirement req;
                req.cv_TargetType = (*j).data[0];
                req.cv_TargetIndex = (*j).data[1];
                req.cv_func = NULL;

                cv_hwCaptureReq[l_regMap[l_id]] = req;
            }
        }
        if (!l_group_is_created)  // @jl06 c Add to default group if none there.
        {
            // Add to default if no group specified.
            cv_hwCaptureGroups[1].push_back(l_regMap[l_id]);
        }

        l_regMax = l_id++;

    }

    for (int i = 0; i < l_chip->cv_ruleCount; i++)
    {
        if (l_regMap[l_id]) // check if it already exists.
        {
            l_vregMax = l_id++;
            continue;
        }

        l_currentResets = PrdfResetAndMaskPair();

        SCAN_COMM_REGISTER_CLASS * l_tmp =
            this->createVirtualRegister(&l_chip->cv_rules[i], l_localData);

        l_regMap[l_id] = l_tmp;
        l_resetMap[l_id] = l_currentResets;
        l_vregMax = l_id++;
    };

    // initialize all the pointers for the groups, but don't construct their
    // data yet.
    Resolution & l_defaultResolution =
                    i_reslFactory.GetCalloutResolution( this->GetChipHandle(),
                                                        MRU_MED );
    for (int i = 0; i < l_chip->cv_groupCount; i++)
    {
        PrdfGroup * l_tmp = new PrdfGroup(l_defaultResolution);
        l_groupMap[l_id] = l_tmp;
        l_groupMax = l_id++;
    };

    for (int i = 0; i < l_chip->cv_actionCount; i++)
    {
        if (l_actionMap[i])
        {
            l_actionMax = l_id++;
            continue;
        }

        // createActionClass will add to the actionMap.
        this->createActionClass(i, l_localData);
        //l_actionMap[l_id] = l_tmp;
        l_actionMax = l_id++;
    }

    for (int i = 0; i < l_chip->cv_groupCount; i++)
    {
        this->createGroup((PrdfGroup *) l_groupMap[i+l_vregMax+1],
                          i,
                          l_localData);
    }
    for (int i = 0; i < NUM_GROUP_ATTN; i++)  // @jl02 UNIT_CS Changes. JL
        cv_groupAttn[i] = l_groupMap[l_chip->cv_groupAttn[i]];

    // Call initialize plugin.
    PrdfExtensibleChipFunction * l_init = getExtensibleFunction("Initialize", true);
    if (NULL != l_init)
    {
        (*l_init)
            (this,
             PrdfPluginDef::bindParm<void*>(NULL)
            );
    }

    return;
};

PrdfRuleChip::~PrdfRuleChip()
{
    if (NULL != cv_dataBundle)
    {
        delete cv_dataBundle;
    }
};


int32_t PrdfRuleChip::Analyze(STEP_CODE_DATA_STRUCT & i_serviceData,
                              ATTENTION_TYPE i_attnType)
{
    using namespace PRDF;
    ServiceDataCollector & i_sdc = *(i_serviceData.service_data);
    ErrorSignature & l_errSig = *(i_sdc.GetErrorSignature());
    CaptureData & capture = i_serviceData.service_data->GetCaptureData();  // @jl04 a Add this for Drop call.

    // Set current ATTN type to input value.
    // If we don't do this, then the AttnRegisters don't work.
    i_sdc.SetCauseAttentionType(i_attnType); // @pw02 @pw04

    int32_t l_rc = SUCCESS;

    // Set Signature Chip Id.
    l_errSig.setChipId( GetId() );

    // Set default dump flags.  //@ecdf
    //FIXME: take out hwTableContent for now for Hostboot
    #ifdef __HOSTBOOT_MODULE
    i_sdc.SetDump(/*(hwTableContent)cv_dumpType,*/ GetChipHandle());
    #else
    i_sdc.SetDump((hwTableContent)cv_dumpType, GetChipHandle());
    #endif

    // Get capture data for this chip.  Allow override.
    PrdfExtensibleChipFunction * l_ignoreCapture =
            getExtensibleFunction("PreventDefaultCapture", true);
    bool l_shouldPreventDefaultCapture = false;

    (*l_ignoreCapture)
        (this, PrdfPluginDef::bindParm<STEP_CODE_DATA_STRUCT&, bool&>
                 (i_serviceData, l_shouldPreventDefaultCapture));

    if (!l_shouldPreventDefaultCapture)
    {
        // Drop secondary capture from earlier chips.
        capture.Drop(SECONDARY);

        // Read capture data.
        this->CaptureErrorData(i_sdc.GetCaptureData());
    }

    // Analyze group.
    ErrorRegisterType * l_errReg = NULL;
    switch (i_attnType)
    {
        case CHECK_STOP:
            l_errReg = cv_groupAttn[0];
            break;

        case RECOVERABLE:
            l_errReg = cv_groupAttn[1];
            break;

        case SPECIAL:
            l_errReg = cv_groupAttn[2];
            break;

        case UNIT_CS:                    // @jl02 JL Added this code to support the new Unit Check Stop.
            l_errReg = cv_groupAttn[3];  // @jl02 JL I don't know if this is the correct cv_groupAttn to add here or if it's needed.
            break;

    }
    if (NULL != l_errReg)
    {  //mp02 a Start
        //Call any pre analysis functions
        PrdfExtensibleChipFunction * l_preAnalysis =
                getExtensibleFunction("PreAnalysis", true);
        bool analyzed = false;
        (*l_preAnalysis)(this,
                 PrdfPluginDef::bindParm<STEP_CODE_DATA_STRUCT&,bool&>
                 (i_serviceData,analyzed));
        if ( !analyzed)
            l_rc = l_errReg->Analyze(i_serviceData);
    }    //mp02 a Stop
       // mp02d l_rc = l_errReg->Analyze(i_serviceData);
    else                                      //@jl07
       l_rc = PRD_SCAN_COMM_REGISTER_ZERO;    //@jl07

    // Don't do reset or mask on CS. @pw03
    if (CHECK_STOP != i_serviceData.service_data->GetAttentionType()) //@pw04
    {
        #ifndef __HOSTBOOT_MODULE
        SyncAnalysis (i_sdc);  //mp01 Add call to Sync SDC
        #endif
        // Call mask plugin.
        if (i_serviceData.service_data->IsAtThreshold())
        {
            PrdfExtensibleChipFunction * l_mask =
                    getExtensibleFunction("MaskError", true);
            (*l_mask)(this,
                 PrdfPluginDef::bindParm<STEP_CODE_DATA_STRUCT&>(i_serviceData)
                ); //@pw01
        }

        // Call reset plugin.
        PrdfExtensibleChipFunction * l_reset =
                getExtensibleFunction("ResetError", true);
        (*l_reset)(this,
             PrdfPluginDef::bindParm<STEP_CODE_DATA_STRUCT&>(i_serviceData)
            ); //@pw01
    }

    // Call postanalysis plugin.
    // @jl02 JL Adding PostAnalysis plugin call.
    PrdfExtensibleChipFunction * l_postanalysis =
            getExtensibleFunction("PostAnalysis", true);
    // @jl02 the true above means that a plugin may not exist for this call.
    // @jl02 JL Adding call for post analysis.
    (*l_postanalysis)(this,
              PrdfPluginDef::bindParm<STEP_CODE_DATA_STRUCT&>(i_serviceData));

    return l_rc;
};

int32_t PrdfRuleChip::CaptureErrorData(CaptureData & i_cap, int i_group)
{
    using namespace TARGETING;
    using namespace PRDF;

    std::vector<SCAN_COMM_REGISTER_CLASS *>::const_iterator l_hwCaptureEnd =
        cv_hwCaptureGroups[i_group].end();
    for (std::vector<SCAN_COMM_REGISTER_CLASS *>::const_iterator i =
            cv_hwCaptureGroups[i_group].begin();
         i != l_hwCaptureEnd;
         ++i)
    {
        // Check that requirements are satisfied.
        if (PrdfCaptureRequirement() != cv_hwCaptureReq[*i])
        {
            PrdfCaptureRequirement req = cv_hwCaptureReq[*i];
            if (NULL != req.cv_func)
            {
                bool l_cap = true;
                (*req.cv_func)(this, PrdfPluginDef::bindParm<bool &>(l_cap));
                if (!l_cap)
                    continue;
            }
            else
            {
                bool l_indexValid =false;
                TargetHandleList  l_ptargetHandleList  =
                    PlatServices::getConnected(this->GetChipHandle(),
                                              (TARGETING::TYPE) req.cv_TargetType);
                TargetHandleList ::iterator itrTarget =l_ptargetHandleList.begin();
                for( ; itrTarget != l_ptargetHandleList.end();itrTarget++ )
                {
                    if (req.cv_TargetIndex == PlatServices::getTargetPosition(*itrTarget))
                    {
                        l_indexValid = true;
                        break;
                    }
                }
                if(false == l_indexValid)
                {
                    continue;
                }
            }
        }

        i_cap.Add(this->GetChipHandle(),
                  (*i)->GetId() ^ this->getSignatureOffset(),
                  *(*i),
                  CaptureData::BACK,                 //@jl04 c change this because of proto.
                  cv_hwCaptureType[*i].cv_regType);  //@jl04 c Changed this function call to add a param.
    }

    // Call "PostCapture" plugin
    PrdfExtensibleChipFunction * l_postCapture =
            getExtensibleFunction("PostCapture", true);

    (*l_postCapture)
        (this,
         PrdfPluginDef::bindParm<CaptureData &, int>(i_cap, i_group)
        );

    return SUCCESS;
}

SCAN_COMM_REGISTER_CLASS *
PrdfRuleChip::createVirtualRegister(
        Prdr::PrdrExpr * i_vReg,
        RuleFileData & i_data
    )
{
    SCAN_COMM_REGISTER_CLASS * l_arg[4] = { NULL };
    uint32_t l_tmp32 = 0;
    SCAN_COMM_REGISTER_CLASS * l_rc = NULL;

    switch(i_vReg->cv_op)
    {
        case Prdr::NOT:
            l_arg[0] = createVirtualRegister(i_vReg->cv_value[0].p, i_data);
            l_rc = &i_data.cv_scanFactory.GetNotRegister(*l_arg[0]);
            break;

        case Prdr::LSHIFT:
        case Prdr::RSHIFT:
            l_arg[0] = createVirtualRegister(i_vReg->cv_value[0].p, i_data);
            l_tmp32 = i_vReg->cv_value[1].p->cv_value[0].i;
            l_rc = (Prdr::LSHIFT == i_vReg->cv_op
                    ?
                        &i_data.cv_scanFactory.GetLeftShiftRegister(*l_arg[0],
                                                                    l_tmp32)
                    :
                        &i_data.cv_scanFactory.GetRightShiftRegister(*l_arg[0],
                                                                     l_tmp32)
                   );
            break;

        case Prdr::OR:
        case Prdr::AND:
            l_arg[0] = createVirtualRegister(i_vReg->cv_value[0].p, i_data);
            l_arg[1] = createVirtualRegister(i_vReg->cv_value[1].p, i_data);
            l_rc = (Prdr::OR == i_vReg->cv_op
                    ?
                        &i_data.cv_scanFactory.GetOrRegister(*l_arg[0],
                                                             *l_arg[1])
                    :
                        &i_data.cv_scanFactory.GetAndRegister(*l_arg[0],
                                                              *l_arg[1])
                    );
            break;


        case Prdr::REF_REG:
            std::copy(i_data.cv_resets[i_vReg->cv_value[0].i].first.begin(),
                      i_data.cv_resets[i_vReg->cv_value[0].i].first.end(),
                      std::back_inserter(i_data.cv_currentResets.first));
            std::copy(i_data.cv_resets[i_vReg->cv_value[0].i].second.begin(),
                      i_data.cv_resets[i_vReg->cv_value[0].i].second.end(),
                      std::back_inserter(i_data.cv_currentResets.second));
            l_rc = i_data.cv_regMap[i_vReg->cv_value[0].i];
            break;

        case Prdr::REF_RULE:
            if (NULL == i_data.cv_regMap[i_vReg->cv_value[0].i])
                i_data.cv_regMap[i_vReg->cv_value[0].i] =
                            createVirtualRegister(
                                    &i_data.cv_loadChip->
                                            cv_rules[i_vReg->cv_value[0].i],
                                    i_data);
            l_rc = i_data.cv_regMap[i_vReg->cv_value[0].i];
            break;

        case Prdr::ATTNLINK:
            if (NULL != i_vReg->cv_value[0].p)
                l_arg[0] = createVirtualRegister(i_vReg->cv_value[0].p, i_data);

            if (NULL != i_vReg->cv_value[1].p)
                l_arg[1] = createVirtualRegister(i_vReg->cv_value[1].p, i_data);

            if (NULL != i_vReg->cv_value[2].p)
                l_arg[2] = createVirtualRegister(i_vReg->cv_value[2].p, i_data);

            if (NULL != i_vReg->cv_value[3].p)
                l_arg[3] = createVirtualRegister(i_vReg->cv_value[3].p, i_data);

            l_rc = &i_data.cv_scanFactory.GetAttnTypeRegister(*l_arg[0],  /*passing null object*/
                                                              *l_arg[1],  /*passing null object*/
                                                              *l_arg[2],  /*passing null object*/
                                                              *l_arg[3]); /*passing null object*/
            break;

        case Prdr::BIT_STR:
            {
                uint32_t l_size = i_vReg->cv_bitStrVect.size();
                BIT_STRING_BUFFER_CLASS l_bs(l_size * 64);

                for (uint32_t i = 0; i < l_size; i++)
                {
                    l_bs.SetFieldJustify(32*(2*i)    , 32,
                           (i_vReg->cv_bitStrVect[i] >> 32) & 0xFFFFFFFF);
                    l_bs.SetFieldJustify(32*((2*i)+1), 32,
                           (i_vReg->cv_bitStrVect[i] & 0xFFFFFFFF));
                }

                l_rc = &i_data.cv_scanFactory.GetConstantRegister(l_bs);
            }
            break;

    }

    return l_rc;
};

Resolution *
PrdfRuleChip::createActionClass(uint32_t i_action,
                                PrdfRuleChip::RuleFileData & i_data)
{
    if (NULL != i_data.cv_actionMap[i_action])
        return i_data.cv_actionMap[i_action];

    Resolution * l_tmpRes = NULL, * l_retRes = NULL;
    for (int i = 0; i < i_data.cv_loadChip->cv_actionSize[i_action]; i++)
    {
        l_tmpRes = this->createResolution(
                                &(i_data.cv_loadChip->cv_actions[i_action][i]),
                                i_data);
        if (0 == i)
        {
            l_retRes = l_tmpRes;
        }
        else
        {
            l_retRes = &i_data.cv_reslFactory.
                            LinkResolutions(*l_retRes, *l_tmpRes);
        }
    }

    if (NULL == l_retRes) // @pw05
    {
        class NullResolution : public Resolution
        {
            public:
                int32_t Resolve(STEP_CODE_DATA_STRUCT & data)
                            { return SUCCESS; };
        };

        static NullResolution l_nullRes;
        l_retRes = &l_nullRes;
    }

    i_data.cv_actionMap[i_action] = l_retRes;
    return l_retRes;
};

Resolution *
PrdfRuleChip::createResolution(Prdr::PrdrExpr * i_action,
                               PrdfRuleChip::RuleFileData & i_data)
{
    using namespace PRDF;

    Resolution * l_rc = NULL;

    switch (i_action->cv_op)
    {
        case Prdr::REF_ACT:
            l_rc = this->createActionClass(i_action->cv_value[0].i -
                                            (i_data.cv_loadChip->cv_regCount +
                                             i_data.cv_loadChip->cv_ruleCount +
                                             i_data.cv_loadChip->cv_groupCount +
                                             1),
                                           i_data);
            break;

        case Prdr::REF_GRP:
            l_rc = &i_data.cv_reslFactory.GetEregResolution(
                            *i_data.cv_groupMap[i_action->cv_value[0].i]);
            break;

        case Prdr::ACT_TRY: // TRY
            l_rc = &i_data.cv_reslFactory.GetTryResolution(
                    *(this->createResolution(i_action->cv_value[0].p,
                                             i_data)),
                    *(this->createResolution(i_action->cv_value[1].p,
                                             i_data))
                    );
            break;

        case Prdr::ACT_FUNC: // FUNCCALL
            l_rc = &i_data.cv_reslFactory.GetPluginCallResolution(
                        this,
                        this->getExtensibleFunction(i_action->cv_actFunc)
                    );
            break;

        case Prdr::ACT_FLAG: // FLAG
            l_rc = &i_data.cv_reslFactory.GetFlagResolution(
                        (ServiceDataCollector::Flag) i_action->cv_value[0].i);
            break;

        case Prdr::ACT_THRES: // Threshold
            // The values which different parameter will have
            // cv_value[0,1] error frequency and time in sec for field threshold
            //cv_value[4] true if mnfg threshols needs to be picked up from mnfg file, false otherwise
            // cv_value [2,3]: error frequency and time in sec for mnfg threshold if cv_value[4] is false
            // otheiwse cv_value[3] tells which threshold needs to pick up from mnfg file
            // cv_value[5] maski id if shared threshold
            if (0 == i_action->cv_value[5].i)
            {
                if ( !PlatServices::mfgMode() )
                {
                    l_rc = &i_data.cv_reslFactory.GetThresholdSigResolution(
                                                     ThresholdResolution::ThresholdPolicy(
                                                            (uint16_t)i_action->cv_value[0].i, i_action->cv_value[1].i));
                }
                else if(i_action->cv_value[4].i)
                {
                    // FIXME : need to uncomment PrdfMfgThresholdMgr after we figure it out
                    #ifndef __HOSTBOOT_MODULE
                    l_rc = &i_data.cv_reslFactory.GetThresholdSigResolution(
                                    *(PrdfMfgThresholdMgr::getInstance()->
                                            getThresholdP(i_action->cv_value[3].i)));
                    #endif
                }
                else
                {
                    l_rc = &i_data.cv_reslFactory.GetThresholdSigResolution(
                                                     ThresholdResolution::ThresholdPolicy(
                                                            (uint16_t)i_action->cv_value[2].i, i_action->cv_value[3].i));
                }
            }
            else
                if (NULL == i_data.cv_sharedThresholds[i_action->cv_value[5].i])
                {
                    if ( !PRDF::PlatServices::mfgMode() )
                    {
                        l_rc = &i_data.cv_reslFactory.
                                   GetThresholdResolution(i_action->cv_value[5].i,
                                      ThresholdResolution::ThresholdPolicy((uint16_t)i_action->cv_value[0].i, i_action->cv_value[1].i));
                    }
                    else if(i_action->cv_value[4].i)
                    {
                        // FIXME : need to uncomment PrdfMfgThresholdMgr after we figure it out
                        #ifndef __HOSTBOOT_MODULE
                        l_rc = &i_data.cv_reslFactory.
                                GetThresholdResolution(i_action->cv_value[5].i,
                                    *(PrdfMfgThresholdMgr::getInstance()->
                                        getThresholdP(i_action->cv_value[3].i)));
                        #endif
                    }
                    else
                    {
                        l_rc = &i_data.cv_reslFactory.
                                GetThresholdResolution(i_action->cv_value[5].i,
                                  ThresholdResolution::ThresholdPolicy((uint16_t)i_action->cv_value[2].i, i_action->cv_value[3].i));
                    }
                    i_data.cv_sharedThresholds[i_action->cv_value[5].i] = l_rc;
                }
                else
                {
                    l_rc = i_data.cv_sharedThresholds[i_action->cv_value[5].i];
                }
            break;


        case Prdr::ACT_DUMP: // DUMP : TODO: Allow dump connected.
            #ifdef __HOSTBOOT_MODULE
            //FIXME: comment out hwtablecontent for hostboot
            l_rc = &i_data.cv_reslFactory.GetDumpResolution(
                                /*(hwTableContent)    i_action->cv_value[0].i,*/
                                GetChipHandle());
            #else
            l_rc = &i_data.cv_reslFactory.GetDumpResolution(
                                (hwTableContent)    i_action->cv_value[0].i,
                                GetChipHandle());
            #endif
            break;

        case Prdr::ACT_GARD: // GARD
            l_rc = &i_data.cv_reslFactory.GetGardResolution(
                    (GardResolution::ErrorType) i_action->cv_value[0].i);
            break;

        case Prdr::ACT_ANALY: // ANALYZE
            l_rc = &i_data.cv_reslFactory.GetAnalyzeConnectedResolution(
                                                     this->GetChipHandle(),
                            (TARGETING::TYPE)        i_action->cv_value[0].i,
                                                     i_action->cv_value[1].i);
            break;

        case Prdr::ACT_CALL: // CALLOUT
            switch ((char)i_action->cv_value[0].i)
            {
                case 'c': // connected chip.
                    l_rc = &i_data.cv_reslFactory.GetConnectedCalloutResolution(
                                                          this->GetChipHandle(),
                                (TARGETING::TYPE)         i_action->cv_value[2].i,
                                                          i_action->cv_value[3].i,
                                (CalloutPriorityEnum)     i_action->cv_value[1].i,
                                (NULL == i_action->cv_value[4].p ? NULL :
                                    (this->createResolution(
                                            i_action->cv_value[4].p, i_data)))

                            );
                    break;

                case 'p': // Procedure.
                    l_rc = &i_data.cv_reslFactory.GetCalloutResolution(
                                (SymbolicFru)         i_action->cv_value[2].i,
                                (CalloutPriorityEnum) i_action->cv_value[1].i);
                    break;

                case 's': // SELF
                default:
                    l_rc = &i_data.cv_reslFactory.GetCalloutResolution(
                                                      this->GetChipHandle(),
                                (CalloutPriorityEnum) i_action->cv_value[1].i);
                    break;

            };
            break;

        case Prdr::ACT_CAPT:  // Capture resolution.
            l_rc = &i_data.cv_reslFactory.GetCaptureResolution(
                                this,
                                i_action->cv_value[0].i);
            break;
    };

    return l_rc;
};

void PrdfRuleChip::createGroup(PrdfGroup * i_group,
                               uint32_t i_groupId,
                               PrdfRuleChip::RuleFileData & i_data)
{
    // Internal class to collapse the bit string.
    class CreateBitString
    {
        public:
            static void execute(std::vector<uint8_t> & i_bits,
                    Prdr::PrdrExpr * i_expr)
            {
                if (NULL == i_expr)
                    return;
                if (i_expr->cv_op == Prdr::INT_SHORT)
                {
                    i_bits.push_back(i_expr->cv_value[0].i);
                }
                else // must be an | or & operator.
                {
                    // Expand bit string from left side.
                    CreateBitString::execute(i_bits, i_expr->cv_value[0].p);
                    // Expand bit string from right side.
                    CreateBitString::execute(i_bits, i_expr->cv_value[1].p);
                }
            };
    };

    for (int i = 0; i < i_data.cv_loadChip->cv_groupSize[i_groupId]; i++)
    {
        std::vector<uint8_t> l_bits; // Vector to hold bit string.

        // TODO : handle & transformations.

        // Get expression for group's line.
        Prdr::PrdrExpr * l_expr = &i_data.cv_loadChip->cv_groups[i_groupId][i];

        // Execute internal (recursive) class to generate bit string.
        CreateBitString::execute(l_bits, l_expr->cv_value[1].p);

        // Add expression to group.
        i_group->Add(i_data.cv_regMap[l_expr->cv_value[0].i],
                     &(*l_bits.begin()),
                     l_bits.size(),
                     *(this->createResolution(l_expr->cv_value[2].p, i_data)),
                     i_data.cv_resets[l_expr->cv_value[0].i],
                     (i_data.cv_regMap[l_expr->cv_value[0].i]->GetId()
                            + i_data.cv_loadChip->cv_signatureOffset) & 0xffff,
                     Prdr::AND == l_expr->cv_value[1].p->cv_op
                    );

    } // end for.

    // Do flags. ---

    // Do Priority filter flag.
    if (i_data.cv_loadChip->cv_groupFlags[i_groupId] &
            Prdr::PRDR_GROUP_FILTER_PRIORITY)
    {
        std::vector<uint8_t> l_bits;
        CreateBitString::execute(l_bits,
                i_data.cv_loadChip->cv_groupPriorityBits[i_groupId]);

        prdfFilter * l_filter = new PrioritySingleBitFilter(l_bits);
        i_group->AddFilter(l_filter);
    }

    // Do single bit filter flag.
    if (i_data.cv_loadChip->cv_groupFlags[i_groupId] &
            Prdr::PRDR_GROUP_FILTER_SINGLE_BIT)
    {
        prdfFilter * l_filter = new SingleBitFilter();
        i_group->AddFilter(l_filter);
    }
}

PrdfExtensibleChipFunction *
    PrdfRuleChip::getExtensibleFunction(const char * i_func, bool i_expectNull)
{
    PrdfExtensibleFunctionType * plugin =
        prdfGetPluginGlobalMap().getPlugins(cv_fileName)[i_func];
    if (NULL == plugin)
    {
        static PrdfPlugin<PrdfExtensibleChip> l_nullPlugin(NULL);
        plugin = &l_nullPlugin;

        if (!i_expectNull)
        {
            errlHndl_t l_errl = NULL;

            PRDF_CREATE_ERRL(l_errl,
                             ERRL_SEV_UNRECOVERABLE,
                             ERRL_ETYPE_NOT_APPLICABLE,
                             SRCI_ERR_INFO,
                             SRCI_NO_ATTR,
                             PRDF_PRDFRULECHIP,
                             LIC_REFCODE,
                             PRDF_CODE_FAIL,
                             __LINE__,
                             0, 0, 0);

            PRDF_ADD_FFDC(l_errl,
                          cv_fileName,
                          strlen(cv_fileName),
                          prdfErrlVer1,
                          prdfErrlString);

            PRDF_ADD_FFDC(l_errl,
                          i_func,
                          strlen(i_func),
                          prdfErrlVer1,
                          prdfErrlString);

            PRDF_COMMIT_ERRL(l_errl, ERRL_ACTION_REPORT);
        }

    }
    return (PrdfExtensibleChipFunction *) plugin;

}

SCAN_COMM_REGISTER_CLASS * PrdfRuleChip::getRegister(const char * i_reg,
                                                     bool i_expectNull)
{
    uint16_t hashId = Util::hashString( i_reg );

    SCAN_COMM_REGISTER_CLASS * l_register = cv_hwRegs[hashId];

    if (NULL == l_register)
    {
        static PrdfNullRegister l_nullRegister(1024);
        l_register = &l_nullRegister;

        if (!i_expectNull)
        {
            errlHndl_t l_errl = NULL;
            PRDF_CREATE_ERRL(l_errl,
                             ERRL_SEV_UNRECOVERABLE,
                             ERRL_ETYPE_NOT_APPLICABLE,
                             SRCI_ERR_INFO,
                             SRCI_NO_ATTR,
                             PRDF_PRDFRULECHIP,
                             LIC_REFCODE,
                             PRDF_CODE_FAIL,
                             __LINE__,
                             1, 0, 0);

            PRDF_ADD_FFDC(l_errl,
                          cv_fileName,
                          strlen(cv_fileName),
                          prdfErrlVer1,
                          prdfErrlString);


            PRDF_ADD_FFDC(l_errl,
                          i_reg,
                          strlen(i_reg),
                          prdfErrlVer1,
                          prdfErrlString);

            PRDF_COMMIT_ERRL(l_errl, ERRL_ACTION_REPORT);
        }

    }
    return l_register;
}
OpenPOWER on IntegriCloud