summaryrefslogtreecommitdiffstats
path: root/src/usr/lpc/lpcdd.C
blob: 48f56a1f24a61914aceb5910689e2c31f12ed985 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/lpc/lpcdd.C $                                         */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2014,2018                        */
/* [+] Google Inc.                                                        */
/* [+] 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                                                     */
/**
 *  @file lpcdd.C
 *
 *  @brief Implementation of the LPC Device Driver
 */

#include <sys/mmio.h>
#include <sys/mm.h>
#include <sys/task.h>
#include <sys/sync.h>
#include <string.h>
#include <devicefw/driverif.H>
#include <trace/interface.H>
#include <errl/errlentry.H>
#include <targeting/common/targetservice.H>
#include <errl/errlmanager.H>
#include "lpcdd.H"
#include <lpc/lpc_const.H>
#include <sys/time.h>
#include <lpc/lpc_reasoncodes.H>
#include <initservice/initserviceif.H>
#include <kernel/console.H> //@todo - RTC:97495 -- Resolve console access
#include <kernel/bltohbdatamgr.H>
#include <errl/errludlogregister.H>
#include <initservice/taskargs.H>
#include <config.h>
#include <arch/memorymap.H>
#include <util/misc.H>
#include <errl/errlreasoncodes.H>


trace_desc_t* g_trac_lpc;
TRAC_INIT( & g_trac_lpc, LPC_COMP_NAME, 2*KILOBYTE, TRACE::BUFFER_SLOW);

// Set to enable LPC tracing.
//#define LPC_TRACING 1
#ifdef LPC_TRACING
#define LPC_TRACFCOMP(des,printf_string,args...) \
    TRACFCOMP(des,printf_string,##args)
#else
#define LPC_TRACFCOMP(args...)
#endif

// Device Drive instance used for alt-master access
static LpcDD* g_altLpcDD = NULL;

namespace LPC
{
/**
 * @brief Performs an LPC Read Operation
 *
 * @param[in]   i_opType        Operation type, see DeviceFW::OperationType
 *                              in driverif.H
 * @param[in]   i_target        LPC target
 * @param[in/out] io_buffer     Read: Pointer to output data storage
 *                              Write: Pointer to input data storage
 * @param[in/out] io_buflen     Input: size of io_buffer (in bytes)
 *                              Output:
 *                                  Read: Size of output data
 *                                  Write: Size of data written
 * @param[in]   i_accessType    DeviceFW::AccessType enum (usrif.H)
 * @param[in]   i_args          This is an argument list for DD framework.
 * @return  errlHndl_t
 */
errlHndl_t lpcRead(DeviceFW::OperationType i_opType,
                   TARGETING::Target* i_target,
                   void* io_buffer,
                   size_t& io_buflen,
                   int64_t i_accessType, va_list i_args)
{
    LPC::TransType l_type = static_cast<LPC::TransType>(
        va_arg(i_args,uint64_t) );
    uint64_t l_addr = va_arg(i_args,uint64_t);
    errlHndl_t l_err = NULL;

    // For speed, we support larger ops on FW space, otherwise
    // we are only able to do 1,2,4 byte LPC operations
    assert( (io_buflen == sizeof(uint8_t)) ||
            (io_buflen == sizeof(uint16_t)) ||
            (io_buflen == sizeof(uint32_t)) ||
                    (l_type == LPC::TRANS_FW) );

    // if the request is for something besides the master sentinel
    //  then we have to use our special side copy of the driver
    if( i_target == TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL )
    {
        //First check/clear the LPC bus of errors and commit any errors found
        l_err = Singleton<LpcDD>::instance().checkForLpcErrors();
        if (l_err)
        {
            errlCommit(l_err, LPC_COMP_ID);
        }

        l_err = Singleton<LpcDD>::instance().readLPC( l_type,
                                                      l_addr,
                                                      io_buffer,
                                                      io_buflen );
    }
    else
    {
        if( g_altLpcDD
            && (i_target == g_altLpcDD->getProc()) )
        {
            //First check/clear the LPC bus of errors and commit
            //   any errors found
            l_err = g_altLpcDD->checkForLpcErrors();
            if (l_err)
            {
                errlCommit(l_err, LPC_COMP_ID);
            }

            l_err = g_altLpcDD->readLPC( l_type,
                                         l_addr,
                                         io_buffer,
                                         io_buflen );
        }
        else
        {
            TRACFCOMP( g_trac_lpc, "Unexpected target for LPC read : i_target=%.8X", TARGETING::get_huid(i_target) );
            uint32_t alt_huid = 0;
            if( g_altLpcDD )
            {
                alt_huid = TARGETING::get_huid(g_altLpcDD->getProc());
            }
            /*@
             * @errortype    ERRL_SEV_UNRECOVERABLE
             * @moduleid     LPC::MOD_READLPC
             * @reasoncode   LPC::RC_BAD_TARGET
             * @userdata1[00:31]    Requested target
             * @userdata1[00:31]    Current alt target
             * @userdata2    Read address
             * @devdesc      readLPC> Unexpected target
             * @custdesc     Firmware error during boot flash diagnostics
             */
            l_err = new ERRORLOG::ErrlEntry(
                                            ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            LPC::MOD_READLPC,
                                            LPC::RC_BAD_TARGET,
                                            TWO_UINT32_TO_UINT64(
                                                TARGETING::get_huid(i_target),
                                                alt_huid ),
                                            l_addr,
                                            true /*SW error*/);
            l_err->collectTrace(PNOR_COMP_NAME);
            l_err->collectTrace(LPC_COMP_NAME);
        }
    }

    return l_err;
}

/**
 * @brief Performs a LPC Write Operation
 * This function performs a LPC Write operation. It follows a pre-defined
 * prototype functions in order to be registered with the device-driver
 * framework.
 *
 * @param[in]   i_opType        Operation type, see DeviceFW::OperationType
 *                              in driverif.H
 * @param[in]   i_target        LPC target
 * @param[in/out] io_buffer     Read: Pointer to output data storage
 *                              Write: Pointer to input data storage
 * @param[in/out] io_buflen     Input: size of io_buffer (in bytes)
 *                              Output:
 *                                  Read: Size of output data
 *                                  Write: Size of data written
 * @param[in]   i_accessType    DeviceFW::AccessType enum (usrif.H)
 * @param[in]   i_args          This is an argument list for DD framework.
 * @return  errlHndl_t
 */
errlHndl_t lpcWrite(DeviceFW::OperationType i_opType,
                    TARGETING::Target* i_target,
                    void* io_buffer,
                    size_t& io_buflen,
                    int64_t i_accessType, va_list i_args)
{
    LPC::TransType l_type = static_cast<LPC::TransType>(
        va_arg(i_args,uint64_t) );
    uint64_t l_addr = va_arg(i_args,uint64_t);
    errlHndl_t l_err = NULL;

    // For speed, we support larger ops on FW space, otherwise
    // we are only able to do 1,2,4 byte LPC operations
    assert( (io_buflen == sizeof(uint8_t)) ||
            (io_buflen == sizeof(uint16_t)) ||
            (io_buflen == sizeof(uint32_t)) ||
                    (l_type == LPC::TRANS_FW) );

    // if the request is for something besides the master sentinel
    //  then we have to use our special side copy of the driver
    if( i_target == TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL )
    {
        //First check/clear the LPC bus of errors and commit any errors found
        l_err = Singleton<LpcDD>::instance().checkForLpcErrors();
        if (!l_err)
        {
            l_err = Singleton<LpcDD>::instance().writeLPC( l_type,
                                                           l_addr,
                                                           io_buffer,
                                                           io_buflen );
        }
    }
    else
    {
        if( g_altLpcDD
            && (i_target == g_altLpcDD->getProc()) )
        {
            //First check/clear the LPC bus of errors and commit
            //   any errors found
            l_err = g_altLpcDD->checkForLpcErrors();
            if (l_err)
            {
                errlCommit(l_err, LPC_COMP_ID);
            }

            l_err = g_altLpcDD->writeLPC( l_type,
                                          l_addr,
                                          io_buffer,
                                          io_buflen );
        }
        else
        {
            TRACFCOMP( g_trac_lpc, "Unexpected target for LPC write : i_target=%.8X", TARGETING::get_huid(i_target) );
            uint32_t alt_huid = 0;
            if( g_altLpcDD )
            {
                alt_huid = TARGETING::get_huid(g_altLpcDD->getProc());
            }
            /*@
             * @errortype    ERRL_SEV_UNRECOVERABLE
             * @moduleid     LPC::MOD_WRITELPC
             * @reasoncode   LPC::RC_BAD_TARGET
             * @userdata1[00:31]    Requested target
             * @userdata1[00:31]    Current alt target
             * @userdata2    Write address
             * @devdesc      writeLPC> Unexpected target
             * @custdesc     Firmware error during boot flash diagnostics
             */
            l_err = new ERRORLOG::ErrlEntry(
                                            ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            LPC::MOD_WRITELPC,
                                            LPC::RC_BAD_TARGET,
                                            TWO_UINT32_TO_UINT64(
                                                TARGETING::get_huid(i_target),
                                                alt_huid ),
                                            l_addr,
                                            true /*SW error*/);
            l_err->collectTrace(PNOR_COMP_NAME);
            l_err->collectTrace(LPC_COMP_NAME);
        }
    }

    return l_err;
}

// Register LPC access functions to DD framework
DEVICE_REGISTER_ROUTE( DeviceFW::READ,
                       DeviceFW::LPC,
                       TARGETING::TYPE_PROC,
                       lpcRead );
DEVICE_REGISTER_ROUTE( DeviceFW::WRITE,
                       DeviceFW::LPC,
                       TARGETING::TYPE_PROC,
                       lpcWrite );


/**
 * @brief Create/delete software objects to support non-master access
 */
errlHndl_t create_altmaster_objects( bool i_create,
                                     TARGETING::Target* i_proc )
{
    TRACFCOMP(g_trac_lpc, "LPC::create_altmaster_objects> i_create=%d, i_proc=%.8X", i_create, TARGETING::get_huid(i_proc) );
    errlHndl_t l_err = NULL;

    do {
        if( i_create && g_altLpcDD )
        {
            TRACFCOMP(g_trac_lpc, "LPC::create_altmaster_objects> Alt-master object already exists");
            /*@
             * @errortype    ERRL_SEV_UNRECOVERABLE
             * @moduleid     LPC::MOD_CREATE_ALTMASTER
             * @reasoncode   LPC::RC_ALTMASTER_EXISTS
             * @userdata1    Requested proc
             * @userdata2    <unused>
             * @devdesc      create_altmaster_objects> Alt-master object
             *               already exists
             * @custdesc     Firmware error during boot flash diagnostics
             */
            l_err = new ERRORLOG::ErrlEntry(
                                            ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            LPC::MOD_CREATE_ALTMASTER,
                                            LPC::RC_ALTMASTER_EXISTS,
                                            TARGETING::get_huid(i_proc),
                                            0,
                                            true /*SW error*/);

            l_err->collectTrace(PNOR_COMP_NAME);
            l_err->collectTrace(LPC_COMP_NAME);
            break;
        }

        if( i_create )
        {
            if( i_proc == TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL )
            {
                TRACFCOMP(g_trac_lpc, "LPC::create_altmaster_objects> Cannot create another object using master sentinel");
                /*@
                 * @errortype    ERRL_SEV_UNRECOVERABLE
                 * @moduleid     LPC::MOD_CREATE_ALTMASTER
                 * @reasoncode   LPC::RC_CANT_USE_SENTINEL
                 * @userdata1    <unused>
                 * @userdata2    <unused>
                 * @devdesc      create_altmaster_objects> Cannot create
                 *               another object using master sentinel
                 * @custdesc     Firmware error during boot flash diagnostics
                 */
                l_err = new ERRORLOG::ErrlEntry(
                                           ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                           LPC::MOD_CREATE_ALTMASTER,
                                           LPC::RC_CANT_USE_SENTINEL,
                                           0,
                                           0,
                                           true /*SW error*/);

                l_err->collectTrace(PNOR_COMP_NAME);
                l_err->collectTrace(LPC_COMP_NAME);
                break;
            }

            // Check if input processor is MASTER
            TARGETING::ATTR_PROC_MASTER_TYPE_type type_enum =
              i_proc->getAttr<TARGETING::ATTR_PROC_MASTER_TYPE>();
            if ( type_enum == TARGETING::PROC_MASTER_TYPE_ACTING_MASTER )
            {
                TRACFCOMP(g_trac_lpc, "LPC::create_altmaster_objects> Cannot create another object using master proc");
                /*@
                 * @errortype    ERRL_SEV_UNRECOVERABLE
                 * @moduleid     LPC::MOD_CREATE_ALTMASTER
                 * @reasoncode   LPC::RC_CANT_USE_MASTER
                 * @userdata1    <unused>
                 * @userdata2    <unused>
                 * @devdesc      create_altmaster_objects> Cannot create
                 *               another object using master proc
                 * @custdesc     Firmware error during boot flash diagnostics
                 */
                l_err = new ERRORLOG::ErrlEntry(
                                           ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                           LPC::MOD_CREATE_ALTMASTER,
                                           LPC::RC_CANT_USE_MASTER,
                                           0,
                                           0,
                                           true /*SW error*/);

                l_err->collectTrace(PNOR_COMP_NAME);
                l_err->collectTrace(LPC_COMP_NAME);
                break;
            }

            g_altLpcDD = new LpcDD( i_proc );
        }
        else
        {
            if( g_altLpcDD )
            {
                delete g_altLpcDD;
            }
            else
            {
                TRACFCOMP(g_trac_lpc,"LPC::create_altmaster_objects> Nothing to remove, but not a big deal");
            }
        }
    } while(0);

    return l_err;
}


/**
 * @brief Block/unblock all LPC operations
 * @param[in] i_block  true: block ops, false: allow ops
 *
 */
void block_lpc_ops( bool i_block )
{
    // Note: this is ignoring the alt-master because the usecase for
    //  this function is only applicable for DD1
    Singleton<LpcDD>::instance().lock(i_block);
}

/**
 * @brief Return the value of the LPC BAR that the driver is using
 */
uint64_t get_lpc_bar( void )
{
    LpcDD l_LpcDD = Singleton<LpcDD>::instance();
    return mm_virt_to_phys( reinterpret_cast<void*>(
                            l_LpcDD.getLPCBaseAddr() )) -
                            l_LpcDD.getLPCStartAddr();
}


}; //namespace LPC

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

mutex_t LpcDD::cv_mutex = MUTEX_INITIALIZER;

LpcDD::LpcDD( TARGETING::Target* i_proc )
: ivp_mutex(NULL)
,iv_proc(i_proc)
,iv_ffdcActive(false)
,iv_errorHandledCount(0)
,iv_errorRecoveryFailed(false)
,iv_resetActive(false)
{
    TRACFCOMP(g_trac_lpc, "LpcDD::LpcDD> " );
    mutex_init( &iv_mutex );
    LPCBase_t baseAddr;

    if( i_proc == TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL )
    {
        ivp_mutex = &cv_mutex;
        //Retrieve the LPC phys base from the bootloader/hostboot data manager
        baseAddr = g_BlToHbDataManager.getLpcBAR() + LPC_ADDR_START;
    }
    else
    {
        // Master target could collide and cause deadlocks with singleton
        // used for ddRead/ddWrite with MASTER_PROCESSOR_CHIP_TARGET_SENTINEL
        TARGETING::Target* master = NULL;
        TARGETING::targetService().masterProcChipTargetHandle( master );
        assert( i_proc != master );

        // Just use the local mutex
        ivp_mutex = &iv_mutex;

        //Correct LPC_BUS address attribute should be correct for alt_lpcdd
        baseAddr =   i_proc->getAttr<TARGETING::ATTR_LPC_BUS_ADDR>() + LPC_ADDR_START;
    }

    setLPCBaseAddr( static_cast<uint64_t *>(
                  mmio_dev_map(reinterpret_cast<void *>(baseAddr),
                               LPC_SPACE_SIZE )));

    /*  @todo RTC:126644
    Initialize the hardware
    errlHndl_t l_errl = hwReset(LpcDD::RESET_INIT);
    if( l_errl )
    {
        TRACFCOMP( g_trac_lpc, "Errors initializing LPC logic... Beware! PLID=%.8X", l_errl->plid() );
        errlCommit(l_errl, LPC_COMP_ID);
    }
    **/
}

LpcDD::~LpcDD()
{
    mutex_destroy( &iv_mutex );
}


/**
 * @brief Reset hardware to get into clean state
 */
errlHndl_t LpcDD::hwReset( ResetLevels i_resetLevel )
{
    errlHndl_t l_err = NULL;
    uint32_t i_addr = 0;
    uint64_t l_addr = 0;

    TRACFCOMP( g_trac_lpc, ENTER_MRK"LpcDD::hwReset(i_resetLevel=%d)>", i_resetLevel );

    // check iv_resetActive to avoid infinite loops
    // and don't reset if in the middle of FFDC collection
    // and don't bother if we already failed the recovery once
    if ( ( iv_resetActive == false ) &&
         ( iv_ffdcActive == false  ) &&
         ( iv_errorRecoveryFailed == false) )
    {
        iv_resetActive = true;

        do {
            /***************************************/
            /* Handle the different reset levels   */
            /***************************************/
            switch(i_resetLevel)
            {
                case RESET_CLEAR:
                    {// Nothing to do here, so just break
                        break;
                    }
/*   @todo - RTC:179179
                  case RESET_INIT:
                    {
                        // Set OPB LPCM FIR Mask
                        //  hostboot will monitor these FIR bits
                        size_t scom_size = sizeof(uint64_t);
                        uint64_t fir_mask_data = OPB_LPCM_FIR_ERROR_MASK;
                        // Write FIR Register
                        l_err = deviceOp( DeviceFW::WRITE,
                                      iv_proc,
                                      &(fir_mask_data),
                                      scom_size,
                                      DEVICE_SCOM_ADDRESS(
                                         OPB_LPCM_FIR_MASK_WO_OR_REG));
                        if( l_err ) { break; }
                    }
**/

                case RESET_OPB_LPCHC_HARD:
                    {
                        TRACFCOMP(g_trac_lpc, "LpcDD::hwReset> Writing OPB_MASTER_LS_CONTROL_REG to disable then enable First Error Data Capture");

                        //Clear all error indicators in LPCM OPB Master Actual
                        //      Status Reg
                        i_addr = OPBM_STATUS_REG;
                        l_err = checkAddr( LPC::TRANS_ERR, i_addr, &l_addr );
                        if (l_err) { break; }
                        uint32_t * l_status_ptr
                               = reinterpret_cast<uint32_t*>(l_addr);
                        //Clear under mask - aka write 1 clears
                        *l_status_ptr = OPB_ERROR_MASK;
                        eieio();

                        //Clear related bits in the LPCM OPB Master Accumulated
                        //   Status Reg
                        i_addr = OPBM_ACCUM_STATUS_REG;
                        l_err = checkAddr( LPC::TRANS_ERR, i_addr, &l_addr );
                        if (l_err) { break; }
                        uint32_t * l_accum_status_ptr
                                = reinterpret_cast<uint32_t*>(l_addr);
                        //Clear under mask - aka write 1 clears
                        *l_accum_status_ptr = OPB_ERROR_MASK;
                        eieio();

                        //Reset LPCHC Logic
                        TRACFCOMP(g_trac_lpc, "LpcDD::hwReset> Writing LPCHC_RESET_REG to reset LPCHC Logic");
                        i_addr = LPCHC_RESET_REG;
                        l_err = checkAddr( LPC::TRANS_ERR, i_addr, &l_addr );
                        if (l_err) { break; }
                        uint32_t * l_reset_ptr
                                = reinterpret_cast<uint32_t*>(l_addr);
                        //The spec states the act of a write is all that matters
                        //The data itself doesn't matter, so using an arbitrary
                        //value
                        *l_reset_ptr = 0x12345678;
                        eieio();

                        //Issue LPC Abort
                        i_addr = LPCHC_LPC_BUS_ABORT_REG;
                        l_err = checkAddr( LPC::TRANS_ERR, i_addr, &l_addr );
                        if (l_err) { break; }
                        uint32_t * l_abort_ptr
                                = reinterpret_cast<uint32_t*>(l_addr);
                        //The spec states the act of a write is all that matters
                        //The data itself doesn't matter, so using an arbitrary
                        //value
                        *l_abort_ptr = 0x12345678;
                        eieio();

/*   @todo - RTC:179179 - Re-enable FEDC
                        // First read OPB_MASTER_LS_CONTROL_REG
                        uint32_t lpc_data = 0x0;
                        l_err = _readLPC( LPC::TRANS_REG,
                                          OPB_MASTER_LS_CONTROL_REG,
                                          &lpc_data,
                                          opsize );

                        if (l_err) { break; }

                        // Disable 'First Error Data Capture'
                        // - set bit 29 to 0b1
                        lpc_data |= 0x00000004;

                        l_err = _writeLPC( LPC::TRANS_REG,
                                           OPB_MASTER_LS_CONTROL_REG,
                                           &lpc_data,
                                           opsize );
                        if (l_err) { break; }


                        // Enable 'First Error Data Capture' - set bit 29 to 0b0
                        // No wait-time needed
                        lpc_data &= 0xFFFFFFFB;

                        l_err = _writeLPC( LPC::TRANS_REG,
                                           OPB_MASTER_LS_CONTROL_REG,
                                           &lpc_data,
                                           opsize );

                        if (l_err) { break; }
                        // Clear FIR register
                        scom_data_64 = ~(OPB_LPCM_FIR_ERROR_MASK);
                        l_err = deviceOp(
                             DeviceFW::WRITE,
                             iv_proc,
                             &(scom_data_64),
                             scom_size,
                             DEVICE_SCOM_ADDRESS(OPB_LPCM_FIR_WOX_AND_REG) );
                        if (l_err) { break; }
**/
                        break;
                    }

/*   @todo - RTC:179179 - Properly categorize errors into SOFT/HARD errors and
                        update this implementation based on results
                case RESET_OPB_LPCHC_SOFT:
                    {
                        break;
                    }
**/

                    // else - unsupported reset level
                default:
                    {
                        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::hwReset> Unsupported Reset Level Passed In: 0x%X", i_resetLevel);

                        /*@
                         * @errortype    ERRL_SEV_UNRECOVERABLE
                         * @moduleid     LPC::MOD_LPCDD_HWRESET
                         * @reasoncode   LPC::RC_UNSUPPORTED_OPERATION
                         * @userdata1    Unsupported Reset Level Parameter
                         * @userdata2    <unused>
                         * @devdesc      LpcDD::hwReset> Unsupported Reset Level
                         *               requested
                         * @custdesc     Unsupported Reset Level requested
                         */
                        l_err = new ERRORLOG::ErrlEntry(
                                            ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            LPC::MOD_LPCDD_HWRESET,
                                            LPC::RC_UNSUPPORTED_OPERATION,
                                            i_resetLevel,
                                            0,
                                            true /*SW error*/);

                        l_err->collectTrace(LPC_COMP_NAME);

                        break;
                    }
            }// end switch

            if ( l_err )
            {
                // Indicate that we weren't successful in resetting
                iv_errorRecoveryFailed = true;
                TRACFCOMP( g_trac_lpc,ERR_MRK"LpcDD::hwReset> Fail doing LPC reset at level 0x%X (recovery count=%d): eid=0x%X", i_resetLevel, iv_errorHandledCount, l_err->eid());
            }
            else
            {
                // Successful, so increment recovery count
                if( i_resetLevel != RESET_CLEAR )
                {
                    iv_errorHandledCount++;
                }

                TRACFCOMP( g_trac_lpc,INFO_MRK"LpcDD::hwReset> Successful LPC reset at level 0x%X (recovery count=%d)", i_resetLevel, iv_errorHandledCount);
            }


        } while(0);

        // reset RESET active flag
        iv_resetActive = false;
    }

    TRACFCOMP( g_trac_lpc, EXIT_MRK"LpcDD::hwReset()=%.8X:%.4X", ERRL_GETEID_SAFE(l_err), ERRL_GETRC_SAFE(l_err) );
    return l_err;
}

/**
 * @brief Sanity check the input address for a LPC op and return
 *   full absolute address
 */
errlHndl_t LpcDD::checkAddr(LPC::TransType i_type,
                            uint32_t i_addr,
                            uint64_t *o_addr)
{
    bool invalid_address = false;
    switch ( i_type )
    {
        case LPC::TRANS_IO:
            if( i_addr >= 0x10000 )
            {
                invalid_address = true;
                break;
            }
            *o_addr =
            getLPCBaseAddr()+ i_addr+ LPC::LPCHC_IO_SPACE- LPC_ADDR_START;
            break;
        case LPC::TRANS_MEM:
            if( i_addr >= 0x10000000 )
            {
                invalid_address = true;
                break;
            }
            *o_addr =
            getLPCBaseAddr()+ i_addr+ LPC::LPCHC_MEM_SPACE- LPC_ADDR_START;
            break;
        case LPC::TRANS_FW:
            if( i_addr >= 0x10000000 )
            {
                invalid_address = true;
                break;
            }
            *o_addr =
            getLPCBaseAddr()+ i_addr + LPC::LPCHC_FW_SPACE- LPC_ADDR_START;
            break;
        case LPC::TRANS_REG:
          if( i_addr >= 0x100 )
            {
                invalid_address = true;
                break;
            }
            *o_addr =
            getLPCBaseAddr()+ i_addr + LPC::LPCHC_REG_SPACE- LPC_ADDR_START;
            break;
        case LPC::TRANS_ERR:
          if( i_addr >= 0x10000 )
            {
                invalid_address = true;
                break;
            }
            *o_addr =
            getLPCBaseAddr()+ i_addr + LPC::LPCHC_ERR_SPACE- LPC_ADDR_START;
            break;
        case LPC::TRANS_ABS:
            //Just use the address as given
            *o_addr = getLPCBaseAddr() + i_addr;
            break;
        default:
            invalid_address = true;
    }

    if( invalid_address )
    {
        TRACFCOMP( g_trac_lpc, "LpcDD::checkAddr() Invalid address : i_type=%d, i_addr=%X", i_type, i_addr );
        /*@
         * @errortype    ERRL_SEV_UNRECOVERABLE
         * @moduleid     LPC::MOD_LPCDD_CHECKADDR
         * @reasoncode   LPC::RC_INVALID_ADDR
         * @userdata1[0:31]   LPC Address
         * @userdata1[32:63]  LPC Transaction Type
         * @devdesc      LpcDD> LPC invalid address
         * @custdesc     Firmware error accessing internal bus during IPL
         */
        return new ERRORLOG::ErrlEntry( ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                        LPC::MOD_LPCDD_CHECKADDR,
                                        LPC::RC_INVALID_ADDR,
                                        TWO_UINT32_TO_UINT64(
                                            i_addr, i_type),
                                        0,
                                        true/*SW Error*/);
    }

    return NULL;
}

/**
 * @brief Read an address from LPC space, assumes lock is already held
 */
errlHndl_t LpcDD::_readLPC(LPC::TransType i_type,
                           uint32_t i_addr,
                           void* o_buffer,
                           size_t& io_buflen)
{
    errlHndl_t l_err = NULL;
    uint64_t l_addr = 0;

    do {
        // Generate the full absolute LPC address
        l_err = checkAddr( i_type, i_addr, &l_addr );
        if( l_err ) { break; }

//TODO CQ:SW328950 to work around Simics AST2400 bug
#if CONFIG_SFC_IS_AST2400 || CONFIG_SFC_IS_AST2500
        if( io_buflen <= sizeof(uint32_t) )
        {
            memcpy( o_buffer, reinterpret_cast<void*>(l_addr), io_buflen );
        }
#else
        // Copy data out to caller's buffer.
        if( io_buflen == sizeof(uint8_t) )
        {
            uint8_t * l_ptr = reinterpret_cast<uint8_t*>(l_addr);
            uint8_t * o_ptr = reinterpret_cast<uint8_t*>(o_buffer);
            *o_ptr = *l_ptr;
        }
        else if( io_buflen == sizeof(uint16_t) )
        {
            uint16_t * l_ptr = reinterpret_cast<uint16_t*>(l_addr);
            uint16_t * o_ptr = reinterpret_cast<uint16_t*>(o_buffer);
            *o_ptr = *l_ptr;
        }
        else if ( io_buflen == sizeof(uint32_t) )
        {
            uint32_t * l_ptr = reinterpret_cast<uint32_t*>(l_addr);
            uint32_t * o_ptr = reinterpret_cast<uint32_t*>(o_buffer);
            *o_ptr = *l_ptr;
        }
        else if ( i_type == LPC::TRANS_FW
                  && (i_addr + io_buflen) <= LPC::FW_WINDOW_SIZE)
        {
            memcpy( o_buffer, reinterpret_cast<void*>(l_addr), io_buflen );
        }
#endif
        else
        {
            TRACFCOMP( g_trac_lpc, "readLPC> Unsupported buffer size : %d", io_buflen );
            /*@
             * @errortype    ERRL_SEV_UNRECOVERABLE
             * @moduleid     LPC::MOD_LPCDD_READLPC
             * @reasoncode   LPC::RC_BAD_ARG
             * @userdata1[0:31]   LPC Address
             * @userdata1[32:63]  LPC Transaction Type
             * @userdata2    Requested buffer size
             * @devdesc      LpcDD::_readLPC> Invalid buffer size requested
             *               (>4 bytes)
             * @custdesc     Firmware error accessing internal bus during IPL
             */
            l_err = new ERRORLOG::ErrlEntry( ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                             LPC::MOD_LPCDD_READLPC,
                                             LPC::RC_BAD_ARG,
                                             TWO_UINT32_TO_UINT64(
                                                            i_addr, i_type),
                                             io_buflen,
                                             true/*SW Error*/);
            break;
        }

        //Sync the IO op
        eieio();

        // Check Error bits
        l_err = checkForLpcErrors();

    } while(0);

    LPC_TRACFCOMP( g_trac_lpc, "readLPC> %08X[%d] = %08X", l_addr, io_buflen, *reinterpret_cast<uint32_t*>( o_buffer )  >> (8 * (4 - io_buflen)) );

    return l_err;
}

/**
 * @brief Write an address from LPC space, assumes lock is already held
 */
errlHndl_t LpcDD::_writeLPC(LPC::TransType i_type,
                            uint32_t i_addr,
                            const void* i_buffer,
                            size_t& io_buflen)
{
    errlHndl_t l_err = NULL;
    uint64_t l_addr = 0;

    do {
        // Generate the full absolute LPC address
        l_err = checkAddr( i_type, i_addr, &l_addr );
        if( l_err ) { break; }

//TODO CQ:SW328950 to work around Simics AST2400 bug
#if CONFIG_SFC_IS_AST2400 || CONFIG_SFC_IS_AST2500
        memcpy(reinterpret_cast<void*>(l_addr), i_buffer, io_buflen);
#else
        if( io_buflen == sizeof(uint8_t) )
        {
            uint8_t * l_ptr = reinterpret_cast<uint8_t*>(l_addr);
            const uint8_t * i_ptr =reinterpret_cast<const uint8_t*>(i_buffer);
            *l_ptr = *i_ptr;
        }
        else if( io_buflen == sizeof(uint16_t) )
        {
            uint16_t * l_ptr = reinterpret_cast<uint16_t*>(l_addr);
            const uint16_t * i_ptr =reinterpret_cast<const uint16_t*>(i_buffer);
            *l_ptr = *i_ptr;
        }
        else if ( io_buflen == sizeof(uint32_t) )
        {
            uint32_t * l_ptr = reinterpret_cast<uint32_t*>(l_addr);
            const uint32_t * i_ptr =reinterpret_cast<const uint32_t*>(i_buffer);
            *l_ptr = *i_ptr;
        }
        else if ( i_type == LPC::TRANS_FW
                                 && (i_addr + io_buflen) < LPC::FW_WINDOW_SIZE)
        {
            memcpy( reinterpret_cast<void*>(l_addr), i_buffer, io_buflen );
        }
        eieio();
#endif

        // Check Error bits
        l_err = checkForLpcErrors();

    } while(0);

    return l_err;
}

/**
 * @brief Add Error Registers to an existing Error Log
 */
void LpcDD::addFFDC(errlHndl_t & io_errl)
{
    errlHndl_t l_err = nullptr;
    uint32_t i_addr = 0;
    uint64_t l_addr = 0;
    uint32_t lpcAddr_buffer;
    size_t l_buflen = sizeof(uint32_t);

    // check iv_ffdcActive to avoid infinite loops
    do{

        if ( iv_ffdcActive == false )
        {
            iv_ffdcActive = true;

            TRACFCOMP( g_trac_lpc, "LpcDD::addFFDC> adding FFDC to Error Log EID=0x%X, PLID=0x%X",
                       io_errl->eid(), io_errl->plid() );

            i_addr = LPCHC_ERROR_ADDR_REG;
            l_err = checkAddr( LPC::TRANS_ERR, i_addr, &l_addr );
            if (l_err)
            {
                // Additional FFDC is not necessary, just delete error and break
                delete l_err;
                l_err = nullptr;
                break;
            }

            memcpy(&lpcAddr_buffer, reinterpret_cast<void*>(l_addr), l_buflen);
            eieio();

            io_errl->addFFDC(LPC_COMP_ID,
                           &lpcAddr_buffer,
                           l_buflen,
                           0,                             // version
                           ERRORLOG::ERRL_UDT_NOFORMAT,   // parser ignores data
                           false);

            // reset FFDC active flag
            iv_ffdcActive = false;
        }

    }while(0);

    return;
}

/**
 * @brief Compute error severity from OPBM Status Register
 */
void LpcDD::computeOpbmErrSev(OpbmErrReg_t i_opbmErrData,
                              ResetLevels &o_resetLevel)
{
    o_resetLevel = RESET_CLEAR;

    // First check the soft errors
    /*   @todo - RTC:179179 Revisit below Reset Levels **/
    if( i_opbmErrData.rxits )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeOpbmErrSev> Invalid Transfer Size Error: OPBM Status Reg =0x%8X, ResetLevel=%d",
                   i_opbmErrData, o_resetLevel);
    }
    if( i_opbmErrData.rxicmd )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeOpbmErrSev> Invalid Command Error: OPBM Status Reg =0x%8X, ResetLevel=%d",
                   i_opbmErrData, o_resetLevel);
    }
    if( i_opbmErrData.rxiaa )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeOpbmErrSev> Invalid Address Alignment Error: OPBM Status Reg =0x%8X, ResetLevel=%d",
                   i_opbmErrData, o_resetLevel);
    }
    if( i_opbmErrData.rxopbe )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeOpbmErrSev> OPB Error Acknowledged: OPBM Status Reg =0x%8X, ResetLevel=%d",
                   i_opbmErrData, o_resetLevel);
    }
    if( i_opbmErrData.rxicmdb )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeOpbmErrSev> OPB Master Command Buffer Parity Error: OPBM Status Reg =0x%8X, ResetLevel=%d",
                   i_opbmErrData, o_resetLevel);
    }
    if( i_opbmErrData.rxidatab )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeOpbmErrSev> OPM Master Data Buffer Parity Error: OPBM Status Reg =0x%8X, ResetLevel=%d",
                   i_opbmErrData, o_resetLevel);
    }

    // Now look for HARD errors that will override SOFT errors reset Level
    if( i_opbmErrData.rxopbt )
    {
        o_resetLevel = RESET_OPB_LPCHC_HARD;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeOpbmErrSev> OPM Timeout Error: OPBM Status Reg =0x%8X, ResetLevel=%d",
                   i_opbmErrData, o_resetLevel);
    }
    if( i_opbmErrData.rxiaddr )
    {
        o_resetLevel = RESET_OPB_LPCHC_HARD;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeOpbmErrSev> Invalid Address Error: OPBM Status Reg =0x%8X, ResetLevel=%d",
                   i_opbmErrData, o_resetLevel);
    }
    if( i_opbmErrData.rxctgtel )
    {
        o_resetLevel = RESET_OPB_LPCHC_HARD;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeOpbmErrSev> OPB Master Timeout: OPBM Status Reg =0x%8X, ResetLevel=%d",
                   i_opbmErrData, o_resetLevel);
    }
}

/**
 * @brief Compute error severity from LPCHC Status Register
 */
void LpcDD::computeLpchcErrSev(LpchcErrReg_t i_lpchcErrData,
                               ResetLevels &o_resetLevel)
{
    o_resetLevel = RESET_CLEAR;

    // First check the soft errors
    // All of these errors are set from bad LPC end points. Setting all to soft
    /*   @todo - RTC:179179 Revisit below Reset Levels **/
    if( i_lpchcErrData.lreset )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeLpchcErrSev> Lreset Event: LPCHC Status Reg =0x%8X, ResetLevel=%d",
                   i_lpchcErrData, o_resetLevel);
    }
    if( i_lpchcErrData.syncab )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeLpchcErrSev> Sync Abnormal Error: LPCHC Status Reg =0x%8X, ResetLevel=%d",
                   i_lpchcErrData, o_resetLevel);
    }
    if( i_lpchcErrData.syncnr )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeLpchcErrSev> Sync No Response Error: LPCHC Status Reg =0x%8X, ResetLevel=%d",
                  i_lpchcErrData, o_resetLevel);
    }
    if( i_lpchcErrData.syncne )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeLpchcErrSev> Sync Normal Error: LPCHC Status Reg =0x%8X, ResetLevel=%d",
                   i_lpchcErrData, o_resetLevel);
    }
    if( i_lpchcErrData.syncto )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeLpchcErrSev> Sync Timeout Error: LPCHC Status Reg =0x%8X, ResetLevel=%d",
                   i_lpchcErrData, o_resetLevel);
    }
    if( i_lpchcErrData.tctar )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeLpchcErrSev> Target Cycle TAR Error: LPCHC Status Reg =0x%8X, ResetLevel=%d",
                   i_lpchcErrData, o_resetLevel);
    }
    if( i_lpchcErrData.mctar )
    {
        o_resetLevel = RESET_OPB_LPCHC_SOFT;
        TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::computeLpchcErrSev> LPC Bus Master Cycle TAR Error: LPCHC Status Reg =0x%8X, ResetLevel=%d",
                   i_lpchcErrData, o_resetLevel);
    }

}

/**
 * @brief Check For Errors in OPB and LPCHC Status Registers
 */
errlHndl_t LpcDD::checkForLpcErrors()
{
    errlHndl_t l_err = NULL;

    uint32_t i_addr = 0;
    uint64_t l_addr = 0;
    uint32_t opbm_buffer;
    uint32_t lpchc_buffer;
    size_t l_buflen = sizeof(uint32_t);
    ResetLevels l_opbmResetLevel = RESET_CLEAR;
    ResetLevels l_lpchcResetLevel = RESET_CLEAR;

    OpbmErrReg_t opbm_err_union;
    opbm_err_union.data32 = 0x0;

    LpchcErrReg_t lpchc_err_union;
    lpchc_err_union.data32 = 0x0;

    do {
        // LPC error registers are not modeled in FSP simics.
        // Skip if we are running simics.
        if (Util::isSimicsRunning())
        { break; }

        // Read OPBM Status Register via MMIO
        i_addr = OPBM_ACCUM_STATUS_REG;
        l_err = checkAddr( LPC::TRANS_ERR, i_addr, &l_addr );
        if (l_err) { break; }

        memcpy( &opbm_buffer, reinterpret_cast<void*>(l_addr), l_buflen );
        eieio();

        // Read LPC Host Controller Status register via MMIO
        i_addr = LPCHC_REG;
        l_err = checkAddr( LPC::TRANS_ERR, i_addr, &l_addr );
        if (l_err) { break; }

        memcpy( &lpchc_buffer, reinterpret_cast<void*>(l_addr), l_buflen );
        eieio();

        // Mask error bits
        opbm_err_union.data32 = (opbm_buffer & OPB_ERROR_MASK);
        lpchc_err_union.data32 = (lpchc_buffer & LPCHC_ERROR_MASK);

        // First look for errors in the OPBM bit mask
        if (opbm_err_union.data32 != 0)
        {
            TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::checkForLpcErrors> Error found in OPB Master Status Register: 0x%8X",opbm_err_union.data32);
            computeOpbmErrSev(opbm_err_union, l_opbmResetLevel);

            if(l_opbmResetLevel != RESET_CLEAR)
            {
                /*@
                 * @errortype    ERRL_SEV_UNRECOVERABLE
                 * @moduleid     LPC::MOD_LPCDD_CHECKFORLPCERRORS
                 * @reasoncode   LPC::RC_OPB_ERROR
                 * @userdata1    OPBM Error Status Register
                 * @userdata2    Reset Level
                 * @devdesc      LpcDD::checkLpcErrors> Error(s) found in OPB
                 *               Status Register
                 * @custdesc     Error(s) found in OPB Status Register
                 */
                l_err = new ERRORLOG::ErrlEntry(
                                              ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                              LPC::MOD_LPCDD_CHECKFORLPCERRORS,
                                              LPC::RC_OPB_ERROR,
                                              opbm_buffer,
                                              l_opbmResetLevel);

                // Gather additional ffdc data
                addFFDC(l_err);
                l_err->addHwCallout( iv_proc,
                                     HWAS::SRCI_PRIORITY_NONE,
                                     HWAS::NO_DECONFIG,
                                     HWAS::GARD_NULL );

                /*   @todo - RTC:179179 Use l_opbmResetLevel **/
                hwReset(RESET_OPB_LPCHC_HARD);
            }
        }
        // Check the LPC host controller bit mask, only if there are no errors
        //    from the OPBM bit mask
        if (lpchc_err_union.data32 != 0 && l_err == NULL)
        {
            TRACFCOMP( g_trac_lpc, ERR_MRK"LpcDD::checkForLpcErrors> Error found in LPC Host Controller Status Register: 0x%8X",lpchc_err_union.data32);
            computeLpchcErrSev(lpchc_err_union, l_lpchcResetLevel);

            if(l_lpchcResetLevel != RESET_CLEAR)
            {
                /*@
                 * @errortype    ERRL_SEV_UNRECOVERABLE
                 * @moduleid     LPC::MOD_LPCDD_CHECKFORLPCERRORS
                 * @reasoncode   LPC::RC_LPCHC_ERROR
                 * @userdata1    LPCHC Error Status Register
                 * @userdata2    Reset Level
                 * @devdesc      LpcDD::checkForLpcErrors> Error(s) found in LPCHC
                 *  Status Register
                 * @custdesc     Error(s) found in LPCHC Status Register
                 */
                l_err = new ERRORLOG::ErrlEntry(
                                               ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                               LPC::MOD_LPCDD_CHECKFORLPCERRORS,
                                               LPC::RC_LPCHC_ERROR,
                                               lpchc_buffer,
                                               l_lpchcResetLevel);

                l_err->addHwCallout( iv_proc,
                                     HWAS::SRCI_PRIORITY_NONE,
                                     HWAS::NO_DECONFIG,
                                     HWAS::GARD_NULL );

                // Gather addtional ffdc data
                addFFDC(l_err);
                l_err->collectTrace(LPC_COMP_NAME);
                /*   @todo - RTC:179179 Use l_opbmResetLevel **/
                hwReset(RESET_OPB_LPCHC_HARD);
            }
        }

    }while(0);

    return l_err;
}

/**
 * @brief Read an address from LPC space
 */
errlHndl_t LpcDD::readLPC(LPC::TransType i_type,
                          uint32_t i_addr,
                          void* o_buffer,
                          size_t& io_buflen)
{
    // Grab the lock and call the internal function
    mutex_lock(ivp_mutex);
    errlHndl_t l_err = _readLPC( i_type, i_addr, o_buffer, io_buflen );
    mutex_unlock(ivp_mutex);

    return l_err;
}

/**
 * @brief Write an address to LPC space
 */
errlHndl_t LpcDD::writeLPC(LPC::TransType i_type,
                           uint32_t i_addr,
                           const void* i_buffer,
                           size_t& io_buflen)
{
    // Grab the lock and call the internal function
    mutex_lock(ivp_mutex);
    errlHndl_t l_err = _writeLPC( i_type, i_addr, i_buffer, io_buflen );
    mutex_unlock(ivp_mutex);

    return l_err;
}
OpenPOWER on IntegriCloud