summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/pm/p9_pm_fir_class.H
blob: 22ef191950f52b72c53bd4784548d1aef60650b8 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: chips/p9/procedures/hwp/pm/p9_pm_fir_class.H $                */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* EKB Project                                                            */
/*                                                                        */
/* COPYRIGHT 2015,2016                                                    */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* 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.                              */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

///
/// @file p9_pm_fir_class.H
/// @brief  common .H file for all FIRINITS
///
// *HWP HWP Owner: Amit Kumar <akumar3@us.ibm.com>
// *HWP Backup HWP Owner: Greg Still <stillgs@us.ibm.com>
// *HWP FW Owner: Sangeetha T S <sangeet2@in.ibm.com>
// *HWP Team: PM
// *HWP Level: 2
// *HWP Consumed by: FSP:HS

#ifndef _P9_PM_FIR_CLASS_H_
#define _P9_PM_FIR_CLASS_H_
//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include <fapi2.H>
#include <p9_pm.H>
#include <p9_perv_scom_addresses.H>
#include <p9_quad_scom_addresses.H>
#include <p9_misc_scom_addresses.H>

namespace p9pmFIR
{

//--------------------------------------------------------------------------
// Constants and class definition
//--------------------------------------------------------------------------

//FIR types
enum FIRType
{
    FIRTYPE_OCC_LFIR = 0x00000001, // OCC LFIR
    FIRTYPE_PBA_LFIR = 0x00000002, // PBA LFIR
    FIRTYPE_CME_LFIR = 0x00000003, // CME LFIR
    FIRTYPE_PPM_LFIR = 0x00000004  // PPM LFIR
};

// Register
enum regType
{
    REG_ACTION0,
    REG_ACTION1,
    REG_FIR,
    REG_FIRMASK,
    REG_ALL,
    REG_ERRMASK
};

//FIR register offset from base
enum FIROffset
{
    BASE_WAND_INCR  = 1,
    BASE_WOR_INCR   = 2,
    MASK_INCR       = 3,
    MASK_WAND_INCR  = 4,
    MASK_WOR_INCR   = 5,
    ACTION0_INCR    = 6,
    ACTION1_INCR    = 7
};

// Target type
enum Target
{
    PROC_TARGET,
    EX_TARGET,
    EQ_TARGET,
    CORE_TARGET
};
/*

typedef struct FIRDetails_t
{
    uint32_t    bit_number;
    char        bit_name[64];
};

typedef struct FIRDef_t
{
    uint64_t    base_fir_address;
    char        fir_name[64];
    uint32_t    number_of_bits;
    std::vectorchar*       bit_names[];
};
*/

template <FIRType Ftype>
class PMFir
{
        // Fapi Targets for the FIRs and Error masks
        fapi2::Target < fapi2::TARGET_TYPE_PROC_CHIP > iv_proc;
        fapi2::Target < fapi2::TARGET_TYPE_EX > iv_ex;
        fapi2::Target < fapi2::TARGET_TYPE_EQ > iv_eq;
        fapi2::Target < fapi2::TARGET_TYPE_CORE > iv_core;

        // Buffers to hold the FIR, masks and action register data
        fapi2::buffer<uint64_t> iv_fir;
        fapi2::buffer<uint64_t> iv_action0;
        fapi2::buffer<uint64_t> iv_action1;
        fapi2::buffer<uint64_t> iv_mask;

        // Addresses of the FIRs, Masks, and action registers
        uint64_t iv_fir_address;
        uint64_t iv_action0_address;
        uint64_t iv_action1_address;
        uint64_t iv_mask_address;

        // Flags if class value was modified
        bool iv_fir_write;
        bool iv_action0_write;
        bool iv_action1_write;
        bool iv_mask_write;

        uint8_t iv_targetType;

    public:

        PMFir(const fapi2::Target < fapi2::TARGET_TYPE_PROC_CHIP >& i_target);
        PMFir(const fapi2::Target < fapi2::TARGET_TYPE_EX >& i_target);
        PMFir(const fapi2::Target < fapi2::TARGET_TYPE_EQ >& i_target);
        PMFir(const fapi2::Target < fapi2::TARGET_TYPE_CORE >& i_target);

        fapi2::ReturnCode get(const regType i_reg);

        fapi2::ReturnCode put();

        fapi2::ReturnCode setCheckStop(const uint32_t i_bit);

        fapi2::ReturnCode setRecvAttn(const uint32_t i_bit);

        fapi2::ReturnCode setRecvIntr(const uint32_t i_bit);

        fapi2::ReturnCode setMalfAlert(const uint32_t i_bit);

        fapi2::ReturnCode mask(const uint32_t i_bit);

        fapi2::ReturnCode unmask(const uint32_t i_bit);

        fapi2::ReturnCode setAllRegBits(const regType i_reg);

        fapi2::ReturnCode clearAllRegBits(const regType i_reg);

        fapi2::ReturnCode saveMask();

        fapi2::ReturnCode restoreSavedMask();

};


/// @brief Base constructor for FIR class to build object based on FIR type
///
/// @param [in] <F>              FIR type (template parameter)
/// @param [in] i_target         Chip Target
///
template < FIRType Ftype >
PMFir<Ftype>::PMFir(
    const fapi2::Target < fapi2::TARGET_TYPE_PROC_CHIP >& i_target)
{
}

/// @brief The constructor for FIR class for OCC FIR
///
/// @param [in] <FIRTYPE_OCC_LFIR>  FIR Type for OCC
/// @param [in] i_target            Chip Target
///
template <> inline
PMFir<FIRTYPE_OCC_LFIR>::PMFir(
    const fapi2::Target < fapi2::TARGET_TYPE_PROC_CHIP >& i_target)
{
    iv_fir_address = PERV_TP_OCC_SCOM_OCCLFIR;
    iv_action0_address = iv_fir_address + ACTION0_INCR;
    iv_action1_address = iv_fir_address + ACTION1_INCR;
    iv_mask_address = iv_fir_address + MASK_INCR;
    iv_proc = i_target;
    iv_targetType = PROC_TARGET;
    iv_fir_write = false;
    iv_action0_write = false;
    iv_action1_write = false;
    iv_mask_write = false;
}

/// @brief The constructor for FIR class for PBA FIR
///
/// @param [in] <FIRTYPE_PBA_LFIR>  FIR Type for PBA
/// @param [in] i_target            Chip Target
///
template <> inline
PMFir<FIRTYPE_PBA_LFIR>::PMFir(
    const fapi2::Target < fapi2::TARGET_TYPE_PROC_CHIP >& i_target)
{
    iv_fir_address = PU_PBAFIR;
    iv_action0_address = iv_fir_address + ACTION0_INCR;
    iv_action1_address = iv_fir_address + ACTION1_INCR;
    iv_mask_address = iv_fir_address + MASK_INCR;
    iv_proc = i_target;
    iv_targetType = PROC_TARGET;
    iv_fir_write = false;
    iv_action0_write = false;
    iv_action1_write = false;
    iv_mask_write = false;
}

/// @brief Base constructor for FIR class to build object based on FIR type
///
/// @param [in] <F>              FIR type (template parameter)
/// @param [in] i_target         EX Target
///
template < FIRType Ftype >
PMFir<Ftype>::PMFir(
    const fapi2::Target < fapi2::TARGET_TYPE_EX >& i_target)
{
}

/// @brief The constructor for FIR class for CME FIR
///
/// @param [in] <FIRTYPE_CME_LFIR>  FIR Type for CME
/// @param [in] i_target            EX Target
///
template <> inline
PMFir<FIRTYPE_CME_LFIR>::PMFir(
    const fapi2::Target < fapi2::TARGET_TYPE_EX >& i_target)
{
    uint8_t l_chpltNumber = 0;

    // Fetch the position of the EX Target
    fapi2::ReturnCode l_rc = FAPI_ATTR_GET(fapi2::ATTR_CHIP_UNIT_POS, i_target,
                                           l_chpltNumber);
    FAPI_DBG("EX number = %d", l_chpltNumber);

    iv_fir_address =  EX_CME_SCOM_LFIR;
    iv_action0_address = iv_fir_address + ACTION0_INCR;
    iv_action1_address = iv_fir_address + ACTION1_INCR;
    iv_mask_address = iv_fir_address + MASK_INCR;
    iv_ex = i_target;
    iv_targetType = EX_TARGET;
    iv_fir_write = false;
    iv_action0_write = false;
    iv_action1_write = false;
    iv_mask_write = false;
}

/// @brief Base constructor for FIR class to build object based on FIR type
///
/// @param [in] <F>              FIR type (template parameter)
/// @param [in] i_target         EQ Target
///
template < FIRType Ftype >
PMFir<Ftype>::PMFir(
    const fapi2::Target < fapi2::TARGET_TYPE_EQ >& i_target)
{
}

/// @brief The constructor for FIR class for PPM Error
///
/// @param [in] <FIRTYPE_PPM_LFIR>  FIR Type for PPM
/// @param [in] i_target            EQ Target
///
template <> inline
PMFir<FIRTYPE_PPM_LFIR>::PMFir(
    const fapi2::Target < fapi2::TARGET_TYPE_EQ >& i_target)
{
    uint8_t l_chpltNumber = 0;

    // Fetch the position of the EQ Target
    fapi2::ReturnCode l_rc = FAPI_ATTR_GET(fapi2::ATTR_CHIP_UNIT_POS, i_target,
                                           l_chpltNumber);
    FAPI_DBG("EQ number = %d", l_chpltNumber);

    iv_mask_address = EQ_QPPM_ERRMSK;
    iv_eq = i_target;
    iv_targetType = EQ_TARGET;
    iv_fir_write = false;
    iv_action0_write = false;
    iv_action1_write = false;
    iv_mask_write = false;
}

/// @brief Base constructor for FIR class to build object based on FIR type
///
/// @param [in] <F>              FIR type (template parameter)
/// @param [in] i_target         Core Target
///
template < FIRType Ftype >
PMFir<Ftype>::PMFir(
    const fapi2::Target < fapi2::TARGET_TYPE_CORE >& i_target)
{
}

/// @brief The constructor for FIR class for PPM Error
///
/// @param [in] <FIRTYPE_PPM_LFIR>  FIR Type for PPM
/// @param [in] i_target            Core Target
///
template <> inline
PMFir<FIRTYPE_PPM_LFIR>::PMFir(
    const fapi2::Target < fapi2::TARGET_TYPE_CORE >& i_target)
{
    uint8_t l_chpltNumber = 0;

    // Fetch the position of the CORE Target
    fapi2::ReturnCode l_rc = FAPI_ATTR_GET(fapi2::ATTR_CHIP_UNIT_POS, i_target,
                                           l_chpltNumber);
    FAPI_DBG("CORE number = %d", l_chpltNumber);

    iv_mask_address = C_CPPM_ERRMSK;
    iv_core = i_target;
    iv_targetType = CORE_TARGET;
    iv_fir_write = false;
    iv_action0_write = false;
    iv_action1_write = false;
    iv_mask_write = false;
}

/// @brief Get the values of FIRs, FIR masks & FIR actions
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <FIRType Ftype>
fapi2::ReturnCode PMFir<Ftype>::get(const regType i_reg)
{
    if (iv_targetType == PROC_TARGET)
    {
        if (i_reg == REG_FIR || i_reg == REG_ALL)
        {
            FAPI_TRY(fapi2::getScom(iv_proc, iv_fir_address, iv_fir));
            iv_fir_write = false;
        }

        if(i_reg == REG_ACTION0 || i_reg == REG_ALL)
        {
            FAPI_TRY(fapi2::getScom(iv_proc, iv_action0_address, iv_action0));
            iv_action0_write = false;
        }

        if(i_reg == REG_ACTION1 || i_reg == REG_ALL)
        {
            FAPI_TRY(fapi2::getScom(iv_proc, iv_action1_address, iv_action1));
            iv_action1_write = false;
        }

        if(i_reg == REG_FIRMASK || i_reg == REG_ALL)
        {
            FAPI_TRY(fapi2::getScom(iv_proc, iv_mask_address, iv_mask));
            iv_mask_write = false;
        }
    }

    else if (iv_targetType == EX_TARGET)
    {
        if (i_reg == REG_FIR || i_reg == REG_ALL)
        {
            FAPI_TRY(fapi2::getScom(iv_ex, iv_fir_address, iv_fir));
            iv_fir_write = false;
        }

        if(i_reg == REG_ACTION0 || i_reg == REG_ALL)
        {
            FAPI_TRY(fapi2::getScom(iv_ex, iv_action0_address, iv_action0));
            iv_action0_write = false;
        }

        if(i_reg == REG_ACTION1 || i_reg == REG_ALL)
        {
            FAPI_TRY(fapi2::getScom(iv_ex, iv_action1_address, iv_action1));
            iv_action1_write = false;
        }

        if(i_reg == REG_FIRMASK || i_reg == REG_ALL)
        {
            FAPI_TRY(fapi2::getScom(iv_ex, iv_mask_address, iv_mask));
            iv_mask_write = false;
        }
    }

    else if (iv_targetType == EQ_TARGET)
    {
        if (i_reg == REG_ERRMASK)
        {
            FAPI_TRY(fapi2::getScom(iv_eq, iv_mask_address, iv_mask));
            iv_mask_write = false;
        }
    }

    else if (iv_targetType == CORE_TARGET)
    {
        if (i_reg == REG_ERRMASK)
        {
            FAPI_TRY(fapi2::getScom(iv_core, iv_mask_address, iv_mask));
            iv_mask_write = false;
        }
    }

fapi_try_exit:
    return fapi2::current_err;
}


/// @brief Put the modified values to the registers
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <FIRType Ftype>
fapi2::ReturnCode PMFir<Ftype>::put()
{
    uint64_t l_address = 0;

    if (iv_targetType == PROC_TARGET)
    {
        if (iv_fir_write == true)
        {
            l_address = iv_fir_address + BASE_WOR_INCR;
            FAPI_TRY(putScom(iv_proc, l_address, iv_fir));
        }

        if (iv_action0_write == true)
        {
            FAPI_TRY(putScom(iv_proc, iv_action0_address, iv_action0));
        }

        if (iv_action1_write == true)
        {
            FAPI_TRY(putScom(iv_proc, iv_action1_address, iv_action1));
        }

        if (iv_mask_write == true)
        {
            l_address = iv_fir_address + MASK_WOR_INCR;
            FAPI_TRY(putScom(iv_proc, l_address, iv_mask));
        }
    }

    else if (iv_targetType == EX_TARGET)
    {
        if (iv_fir_write == true)
        {
            l_address = iv_fir_address + BASE_WOR_INCR;
            FAPI_TRY(putScom(iv_ex, l_address, iv_fir));
        }

        if (iv_action0_write == true)
        {
            FAPI_TRY(putScom(iv_ex, iv_action0_address, iv_action0));
        }

        if (iv_action1_write == true)
        {
            FAPI_TRY(putScom(iv_ex, iv_action1_address, iv_action1));
        }

        if (iv_mask_write == true)
        {
            l_address = iv_fir_address + MASK_WOR_INCR;
            FAPI_TRY(putScom(iv_ex, l_address, iv_mask));
        }
    }

    else if (iv_targetType == EQ_TARGET)
    {
        if (iv_mask_write == true)
        {
            FAPI_TRY(fapi2::putScom(iv_eq, iv_mask_address, iv_mask));
        }
    }

    else if (iv_targetType == CORE_TARGET)
    {
        if (iv_mask_write == true)
        {
            FAPI_TRY(fapi2::putScom(iv_core, iv_mask_address, iv_mask));
        }
    }

fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Set FIR bit action to checkstop (00)
///
/// @param [in] i_bit  FIR bit to act upon
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <FIRType Ftype>
fapi2::ReturnCode PMFir<Ftype>::setCheckStop(const uint32_t i_bit)
{
    FAPI_TRY(iv_action0.clearBit(i_bit));
    FAPI_TRY(iv_action1.clearBit(i_bit));
    FAPI_TRY(iv_mask.clearBit(i_bit));
    iv_action0_write = true;
    iv_action1_write = true;
    iv_mask_write = true;

fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Set FIR bit action to recoverable attention (01)
///
/// @param [in] i_bit  FIR bit to act upon
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <FIRType Ftype>
fapi2::ReturnCode PMFir<Ftype>::setRecvAttn(const uint32_t i_bit)
{
    FAPI_TRY(iv_action0.clearBit(i_bit));
    FAPI_TRY(iv_action1.setBit(i_bit));
    FAPI_TRY(iv_mask.clearBit(i_bit));
    iv_action0_write = true;
    iv_action1_write = true;
    iv_mask_write = true;

fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Set FIR bit action to recoverable interrupt (10)
///
/// @param [in] i_bit       FIR bit to act upon
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <FIRType Ftype>
fapi2::ReturnCode PMFir<Ftype>::setRecvIntr(const uint32_t i_bit)
{
    FAPI_TRY(iv_action0.setBit(i_bit));
    FAPI_TRY(iv_action1.clearBit(i_bit));
    FAPI_TRY(iv_mask.clearBit(i_bit));
    iv_action0_write = true;
    iv_action1_write = true;
    iv_mask_write = true;

fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Set FIR bit action to malfunction alert (11)
///
/// @param [in] i_bit       FIR bit to act upon
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <FIRType Ftype>
fapi2::ReturnCode PMFir<Ftype>::setMalfAlert(const uint32_t i_bit)
{
    FAPI_TRY(iv_action0.setBit(i_bit));
    FAPI_TRY(iv_action1.setBit(i_bit));
    FAPI_TRY(iv_mask.clearBit(i_bit));
    iv_action0_write = true;
    iv_action1_write = true;
    iv_mask_write = true;

fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Mask a given bit
///
/// @param [in] i_bit  FIR bit to act upon
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <FIRType Ftype>
fapi2::ReturnCode PMFir<Ftype>::mask(const uint32_t i_bit)
{
    FAPI_TRY(iv_mask.setBit(i_bit));
    iv_mask_write = true;

fapi_try_exit:
    return fapi2::current_err;
}

/// @brief unmask a given bit
///
/// @param [in] i_bit  FIR bit to act upon
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <FIRType Ftype>
fapi2::ReturnCode PMFir<Ftype>::unmask(const uint32_t i_bit)
{
    FAPI_TRY(iv_mask.clearBit(i_bit));
    iv_mask_write = true;

fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Set all bits of FIR/MASK/Action
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <FIRType Ftype>
fapi2::ReturnCode PMFir<Ftype>::setAllRegBits(const regType i_reg)
{
    if (i_reg == REG_FIR || i_reg == REG_ALL)
    {
        iv_fir.flush<1>();
        iv_fir_write = true;
    }

    if(i_reg == REG_ACTION0 || i_reg == REG_ALL)
    {
        iv_action0.flush<1>();
        iv_action0_write = true;
    }

    if(i_reg == REG_ACTION1 || i_reg == REG_ALL)
    {
        iv_action1.flush<1>();
        iv_action1_write = true;
    }

    if(i_reg == REG_FIRMASK || i_reg == REG_ERRMASK || i_reg == REG_ALL)
    {
        iv_mask.flush<1>();
        iv_mask_write = true;
    }

    return fapi2::current_err;
}

/// @brief Clear all bits of FIR/MASK/Action
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <FIRType Ftype>
fapi2::ReturnCode PMFir<Ftype>::clearAllRegBits(const regType i_reg)
{
    if (i_reg == REG_FIR || i_reg == REG_ALL)
    {
        iv_fir.flush<0>();
        iv_fir_write = true;
    }

    if(i_reg == REG_ACTION0 || i_reg == REG_ALL)
    {
        iv_action0.flush<0>();
        iv_action0_write = true;
    }

    if(i_reg == REG_ACTION1 || i_reg == REG_ALL)
    {
        iv_action1.flush<0>();
        iv_action1_write = true;
    }

    if(i_reg == REG_FIRMASK || i_reg == REG_ERRMASK || i_reg == REG_ALL)
    {
        iv_mask.flush<0>();
        iv_mask_write = true;
    }

    return fapi2::current_err;
}

/// @brief Base function to save the present FIR mask into attribute
///
/// @param [in] <Ftype>  FIR Type
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template < FIRType Ftype >
fapi2::ReturnCode PMFir<Ftype>::saveMask()
{
    return fapi2::current_err;
}

/// @brief Save the present OCC LFIR mask into attribute
///
/// @param [in] <FIRTYPE_OCC_LFIR> OCC FIR Type
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <> inline
fapi2::ReturnCode PMFir<FIRTYPE_OCC_LFIR>::saveMask()
{
    uint32_t l_mask;
    iv_mask.extract<0, 32>(l_mask);
    FAPI_TRY(FAPI_ATTR_SET(fapi2::ATTR_OCC_LFIR, iv_proc, l_mask),
             "ERROR: Failed to save OCC LFIR");

fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Save the present PBA LFIR mask into attribute
///
/// @param [in] <FIRTYPE_PBA_LFIR> PBA FIR Type
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <> inline
fapi2::ReturnCode PMFir<FIRTYPE_PBA_LFIR>::saveMask()
{
    uint32_t l_mask;
    iv_mask.extract<0, 32>(l_mask);
    FAPI_TRY(FAPI_ATTR_SET(fapi2::ATTR_PBA_LFIR, iv_proc, l_mask),
             "ERROR: Failed to save PBA LFIR");
fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Save the present CME LFIR mask into attribute
///
/// @param [in] <FIRTYPE_CME_LFIR> CME FIR Type
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <> inline
fapi2::ReturnCode PMFir<FIRTYPE_CME_LFIR>::saveMask()
{
    uint32_t l_mask;
    iv_mask.extract<0, 32>(l_mask);
    FAPI_TRY(FAPI_ATTR_SET(fapi2::ATTR_CME_LOCAL_FIRMASK, iv_ex, l_mask),
             "ERROR: Failed to save CME LFIR");
fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Save the present PPM Error mask into attribute
///
/// @param [in] <FIRTYPE_PPM_LFIR> PPM FIR Type
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <> inline
fapi2::ReturnCode PMFir<FIRTYPE_PPM_LFIR>::saveMask()
{
    uint32_t l_mask;
    iv_mask.extract<0, 32>(l_mask);

    if (iv_targetType == EQ_TARGET)
    {
        FAPI_TRY(FAPI_ATTR_SET(fapi2::ATTR_QUAD_PPM_ERRMASK, iv_eq, l_mask),
                 "ERROR: Failed to save Quad Error mask");
    }
    else if (iv_targetType == CORE_TARGET)
    {
        FAPI_TRY(FAPI_ATTR_SET(fapi2::ATTR_CORE_PPM_ERRMASK, iv_core, l_mask),
                 "ERROR: Failed to save Core Error mask");
    }

fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Base function to restore saved value to the FIR Mask
///
/// @param [in] <Ftype>    FIR Type
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template < FIRType Ftype >
fapi2::ReturnCode PMFir<Ftype>::restoreSavedMask()
{
    return fapi2::current_err;
}

/// @brief Restore saved OCC LFIR Mask
///
/// @param [in] <FIRTYPE_OCC_LFIR> OCC LFIR type
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <> inline
fapi2::ReturnCode PMFir<FIRTYPE_OCC_LFIR>::restoreSavedMask()
{
    uint32_t l_mask;
    uint32_t l_tempMask;

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_OCC_LFIR, iv_proc, l_mask),
             "ERROR: Failed to retrieve saved OCC LFIR");
    iv_mask.extract<0, 32>(l_tempMask);
    l_mask |= l_tempMask;
    iv_mask.insertFromRight<0, 32>(l_mask);
    iv_mask_write = true;

fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Restore saved PBA LFIR Mask
///
/// @param [in] <FIRTYPE_PBA_LFIR> PBA LFIR type
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <> inline
fapi2::ReturnCode PMFir<FIRTYPE_PBA_LFIR>::restoreSavedMask()
{
    uint32_t l_mask;
    uint32_t l_tempMask;

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PBA_LFIR, iv_proc, l_mask),
             "ERROR: Failed to retrieve saved PBA LFIR");
    iv_mask.extract<0, 32>(l_tempMask);
    l_mask |= l_tempMask;
    iv_mask.insertFromRight<0, 32>(l_mask);
    iv_mask_write = true;

fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Restore saved CME LFIR Mask
///
/// @param [in] <FIRTYPE_CME_LFIR> CME LFIR type
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <> inline
fapi2::ReturnCode PMFir<FIRTYPE_CME_LFIR>::restoreSavedMask()
{
    uint32_t l_mask;
    uint32_t l_tempMask;

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CME_LOCAL_FIRMASK, iv_ex, l_mask),
             "ERROR: Failed to retrieve saved CME LFIR mask");
    iv_mask.extract<0, 32>(l_tempMask);
    l_mask |= l_tempMask;
    iv_mask.insertFromRight<0, 32>(l_mask);
    iv_mask_write = true;

fapi_try_exit:
    return fapi2::current_err;
}

/// @brief Restore saved PPM Error Mask
///
/// @param [in] <FIRTYPE_PPM_LFIR> PPM LFIR type
///
/// @return FAPI2_RC_SUCCESS if success, else error code
///
template <> inline
fapi2::ReturnCode PMFir<FIRTYPE_PPM_LFIR>::restoreSavedMask()
{
    uint32_t l_mask;
    uint32_t l_tempMask;

    if (iv_targetType == EQ_TARGET)
    {
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_QUAD_PPM_ERRMASK, iv_eq, l_mask),
                 "ERROR: Failed to retrieve saved Quad Error Mask");
    }
    else if (iv_targetType == CORE_TARGET)
    {
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CORE_PPM_ERRMASK, iv_core, l_mask),
                 "ERROR: Failed to retrieve saved Core Error Mask");
    }

    iv_mask.extract<0, 32>(l_tempMask);
    l_mask |= l_tempMask;
    iv_mask.insertFromRight<0, 32>(l_mask);
    iv_mask_write = true;

fapi_try_exit:
    return fapi2::current_err;
}

}
#endif //_P9_PM_FIR_CLASS_H_
OpenPOWER on IntegriCloud