summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/occ/occ_procedures/p8_pmc_init.C
blob: aefe1e2489ad0a3d9bfe8f48a2eee8d6fb681593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/occ/occ_procedures/p8_pmc_init.C $           */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2013,2014              */
/*                                                                        */
/* 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                                                     */
// $Id: p8_pmc_init.C,v 1.42 2014/04/10 21:12:22 stillgs Exp $
// $Source: /afs/awd/projects/eclipz/KnowledgeBase/.cvsroot/eclipz/chips/p8/working/procedures/ipl/fapi/p8_pmc_init.C,v $
//------------------------------------------------------------------------------
// *! (C) Copyright International Business Machines Corp. 2011
// *! All Rights Reserved -- Property of IBM
// *! *** IBM Confidential ***
//------------------------------------------------------------------------------
// *! OWNER NAME: Pradeep CN         Email: pradeepcn@in.ibm.com
// *! OWNER NAME: Greg Still         Email: stillgs@us.ibm.com
// *!
/// \verbatim
/// High-level procedure flow:
///
///     T
///
///  \endverbatim
///  buildfapiprcd -e "../../xml/error_info/p8_pmc_errors.xml,../../xml/error_info/p8_pstate_registers.xml" p8_pmc_init.C
//------------------------------------------------------------------------------


// ----------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------
#include "p8_pm.H"
#include "p8_pmc_init.H"

#define INTERCHIP_HALT_POLL_COUNT 256
#define VOLTAGE_CHANGE_POLL_COUNT 100
#define O2S_POLL_COUNT 256
#define O2P_POLL_COUNT 8
#define PSTATE_HALT_POLL_COUNT 256
#define PORE_REQ_POLL_COUNT 256

#define MASTER_SIDE 0
#define SLAVE_SIDE  1

extern "C" {

using namespace fapi;

// ----------------------------------------------------------------------
// Function prototypes
// ----------------------------------------------------------------------

fapi::ReturnCode
p8_pmc_poll_pstate_halt(    const fapi::Target &    i_target,
                            const uint8_t           i_side);

fapi::ReturnCode
p8_pmc_poll_idle_halt(      const fapi::Target &    i_target,
                            const uint8_t           i_side);

fapi::ReturnCode
p8_pmc_poll_interchip_halt( const fapi::Target&  i_target,
                            const uint8_t        i_side,
                            bool                 i_is_MasterPMC,
                            const fapi::Target&  i_dcm_target);

fapi::ReturnCode
p8_pmc_poll_spivid_halt(    const fapi::Target& i_target,
                            const uint8_t       i_side);

fapi::ReturnCode
p8_pmc_poll_o2p_halt(       const fapi::Target& i_target,
                            const uint8_t       i_side);

// ----------------------------------------------------------------------
/**
 * pmc_config_spivid_settings
 *
 * @param[in] i_target Chip target
 *
 * @retval ECMD_SUCCESS
 * @retval ERROR defined in xml
 */
fapi::ReturnCode
pmc_config_spivid_settings(const Target& l_pTarget)
{
    fapi::ReturnCode rc;

    // SPIVID Defaults

    const uint32_t  default_spivid_frequency = 1;  // MHz
    // Units: nanoseconds;  Value 15 microseconds
    const uint32_t  default_spivid_interframe_delay_write_status = 15000;
    // Units: nanoseconds;  Value 40 microsecond
    const uint32_t  default_spivid_inter_retry_delay = 40000;


    uint32_t attr_pm_spivid_frequency = 1;
    uint32_t attr_proc_nest_frequency = 2000;

    uint32_t attr_pm_spivid_clock_divider;
    uint32_t attr_pm_spivid_interframe_delay_write_status;
    uint32_t attr_pm_spivid_interframe_delay_write_status_value;
    uint32_t attr_pm_spivid_inter_retry_delay_value;
    uint32_t attr_pm_spivid_inter_retry_delay;

    FAPI_INF("pmc_config_spivid start...");
    do
    {

        //----------------------------------------------------------
        GETATTR(            rc,
                            ATTR_FREQ_PB,
                            "ATTR_FREQ_PB",
                            NULL,
                            attr_proc_nest_frequency);

        //----------------------------------------------------------
        GETATTR_DEFAULT(    rc,
                            ATTR_PM_SPIVID_FREQUENCY,
                            "ATTR_PM_SPIVID_FREQUENCY",
                            NULL,
                            attr_pm_spivid_frequency,
                            default_spivid_frequency);

        // calculation of clock divider
        attr_pm_spivid_clock_divider =  (attr_proc_nest_frequency /
                                            (attr_pm_spivid_frequency*8)-1 );


        SETATTR(            rc,
                            ATTR_PM_SPIVID_CLOCK_DIVIDER,
                            "ATTR_PM_SPIVID_CLOCK_DIVIDER",
                            &l_pTarget,
                            attr_pm_spivid_clock_divider);

        //----------------------------------------------------------
        // Delay between command and status frames of a SPIVID WRITE operation
        // (binary in nanoseconds)

        GETATTR_DEFAULT(    rc,
                            ATTR_PM_SPIVID_INTERFRAME_DELAY_WRITE_STATUS,
                            "ATTR_PM_SPIVID_INTERFRAME_DELAY_WRITE_STATUS",
                            &l_pTarget,
                            attr_pm_spivid_interframe_delay_write_status,
                            default_spivid_interframe_delay_write_status);

        // Delay is computed as: (value * ~100ns_hang_pulse)
        // +0/-~100ns_hang_pulse time
        // Thus, value = delay / 100
        attr_pm_spivid_interframe_delay_write_status_value =
                attr_pm_spivid_interframe_delay_write_status / 100;

        SETATTR(            rc,
                            ATTR_PM_SPIVID_INTERFRAME_DELAY_WRITE_STATUS_VALUE,
                            "ATTR_PM_SPIVID_INTERFRAME_DELAY_WRITE_STATUS_VALUE",
                            &l_pTarget,
                            attr_pm_spivid_interframe_delay_write_status_value);

        //----------------------------------------------------------

        // Delay between SPIVID reture attempts when WRITE command status
        // indicates an error (binary in nanoseconds)

        GETATTR_DEFAULT(    rc,
                            ATTR_PM_SPIVID_INTER_RETRY_DELAY,
                            "ATTR_PM_SPIVID_INTER_RETRY_DELAY",
                            &l_pTarget,
                            attr_pm_spivid_inter_retry_delay,
                            default_spivid_inter_retry_delay);

        FAPI_DBG (" attr_pm_spivid_inter_retry_delay value in config function = 0x%x",
                            attr_pm_spivid_inter_retry_delay );

        // Delay is computed as: (value * ~100ns_hang_pulse)
        // +0/-~100ns_hang_pulse time
        // Thus, value = delay / 100
        attr_pm_spivid_inter_retry_delay_value =
                attr_pm_spivid_inter_retry_delay / 100;

        SETATTR(            rc,
                            ATTR_PM_SPIVID_INTER_RETRY_DELAY_VALUE,
                            "ATTR_PM_SPIVID_INTER_RETRY_DELAY_VALUE",
                            &l_pTarget,
                            attr_pm_spivid_inter_retry_delay_value);


    } while(0);

    FAPI_INF("pmc_config_spivid end...");

    return rc ;
}


// ----------------------------------------------------------------------
/**
 * pmc_reset_function
 *
 * @param[in] i_target1 Primary Chip target:   Murano - chip0; Venice - chip
 * @param[in] i_target2 Secondary Chip target: Murano - chip1; Venice - NULL
 *
 * @retval ECMD_SUCCESS
 * @retval ERROR defined in xml
 */
fapi::ReturnCode
pmc_reset_function( const fapi::Target& i_target1 ,
                    const fapi::Target& i_target2,
                    uint32_t i_mode)
{

    fapi::ReturnCode rc;
    ecmdDataBufferBase data(64);
    ecmdDataBufferBase pmcstatus(64);
    ecmdDataBufferBase porr(64);
    ecmdDataBufferBase pmcmode_master(64);
    ecmdDataBufferBase pmcmode_slave(64);

    uint32_t e_rc = 0;
//    uint32_t count = 0 ;
//    bool is_stopped = false ;
//    bool is_pstate_error_stopped = false ;
//    bool is_spivid_stopped = false ;
//    bool is_intchp_error_stopped= false ;
    bool master_enable_pstate_voltage_changes = false ;
    bool master_is_MasterPMC= false ;
//    bool master_enable_fw_pstate_mode= false ;
    bool master_is_enable_interchip_interface= false ;


//    bool slave_enable_pstate_voltage_changes = false ;
    bool slave_is_MasterPMC= false ;
//    bool slave_enable_fw_pstate_mode= false ;
    bool slave_is_enable_interchip_interface= false ;


    fapi::Target master_target;
    fapi::Target slave_target;
    uint8_t attr_pm_spivid_port_enable1 = 0;
    uint8_t attr_dcm_installed_1 = 0;
    uint8_t attr_dcm_installed_2 = 0;
    uint64_t any_error = 0;

    FAPI_INF("pmc_reset start...");

    do
    {
        // Check for validity of passed parms
        bool dcm = false;

        FAPI_INF("Performing STEP 1");
        rc = FAPI_ATTR_GET(ATTR_PROC_DCM_INSTALLED, &i_target1, attr_dcm_installed_1);
        if (rc)
        {
            FAPI_ERR("fapiGetAttribute of ATTR_DCM_INSTALLED with rc = 0x%x", (uint32_t)rc);
            break;
        }

        FAPI_INF (" ATTR_DCM_INSTALLED value in reset function = 0x%x", attr_dcm_installed_1 );

        if (attr_dcm_installed_1 == 0)
        {

            // target2 should be NULL
            // if not NULL, exit with config error
            if (i_target2.getType() != TARGET_TYPE_NONE  )
            {
                FAPI_ERR ("Config error : target2 is not null for target1 SCM case");
                const fapi::Target& MASTER_TARGET = i_target1;
                const fapi::Target& SLAVE_TARGET = i_target2;
                const uint8_t & DCM_INSTALLED_1 =  attr_dcm_installed_1;
                const uint8_t & DCM_INSTALLED_2 =  attr_dcm_installed_2;
                FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCRESET_SCM_INSTALL_ERROR);
                break;
            }
        }
        else
        {
            // GSS: test removed as this can be the case for a deconfigured DCM
            //         if target2 is NULL, exit with config error
            //         if target2 dcm attr not 1, exit with config error
            //if (i_target2.getType() == TARGET_TYPE_NONE )
            //{
            //    FAPI_ERR ("config error : target2 is null for target1 dcm installed case");
            //    FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCRESET_DCM_INSTALL_ERROR);
            //    break;
            //}

            if (i_target2.getType() != TARGET_TYPE_NONE  )
            {
                rc = FAPI_ATTR_GET(ATTR_PROC_DCM_INSTALLED, &i_target2, attr_dcm_installed_2);
                if (rc)
                {
                    FAPI_ERR("fapiGetAttribute of ATTR_DCM_INSTALLED with rc = 0x%x", (uint32_t)rc);
                    break;
                }
                FAPI_INF (" ATTR_DCM_INSTALLED value in reset function = 0x%x", attr_dcm_installed_2 );

                if (attr_dcm_installed_2 != 1)
                {
                    FAPI_ERR ("Config error:  DCM_INSTALLED target2 does not match target1\n" \
                              "   target1: %08x attr:%02x, target2:%08x attr:%02x",
                              i_target1.getType(), attr_dcm_installed_1,
                              i_target2.getType(), attr_dcm_installed_2);
                    const fapi::Target& MASTER_TARGET = i_target1;
                    const fapi::Target& SLAVE_TARGET = i_target2;
                    const uint8_t & DCM_INSTALLED_1 =  attr_dcm_installed_1;
                    const uint8_t & DCM_INSTALLED_2 =  attr_dcm_installed_2;
                    FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCRESET_DCM_INSTALL_ERROR);
                    break;
                }

                dcm = true;

            }
        }

        ////////////////////////////////////////////////////////////////////////////
        // 1) Determine master chip and slave chip. By reading the SPIVID_EN attribute
        //    If SPIVID_EN is != 0 then that target is master
        //    If SPIVID_EN is == 0 then that target is slave
        //    If both SPIVID_EN are != 0 then its an error
        ////////////////////////////////////////////////////////////////////////////


        FAPI_INF("Determine master chip and slave targets");
        rc = FAPI_ATTR_GET( ATTR_PM_SPIVID_PORT_ENABLE,
                            &i_target1,
                            attr_pm_spivid_port_enable1);
        if (rc)
        {
            FAPI_ERR("fapiGetAttribute of ATTR_PM_SPIVID_PORT_ENABLE with rc = 0x%x", (uint32_t)rc);
            break;
        }
        FAPI_INF (" value read from the attribute attr_pm_spivid_port_enable in reset function = 0x%x",
                    attr_pm_spivid_port_enable1);


        if (attr_pm_spivid_port_enable1 != 0 )
        {
            master_target = i_target1;
            slave_target = i_target2;
        }
        else
        {
            FAPI_ERR("Master target does not have SPIVID ports enabled: ATTR_PM_SPIVID_PORT_ENABLE must be non-zero.");
            const fapi::Target& MASTER_TARGET = i_target1;
            const uint64_t& ATTR_SPIVID_PORT_ENABLE = (uint64_t)attr_pm_spivid_port_enable1;
            FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCRESET_SPIVID_CONFIG_ERROR);
            break;
        }

        ////////////////////////////////////////////////////////////////////////////
        // 2.0 cRQ_TD_IntMaskRQ: Mask OCC interrupts in OIMR1
        //     PMC_PSTATE_REQUEST, PMC_PROTOCOL_ONGOING, PMC_VOLTAGE_CHANGE_ONGOING,
        //     PMC_INTERCHIP_MSG_SEND_ONGOING, PMC_IDLE_ENTER, PMC_IDLE_EXIT, PMC_SYNC
        //       12
        //       13
        //       14
        //       15
        //       18
        //       20
        //       22  of OCB_OCI_OIMR1_0x0006a014
        //
        // 2.1 cRQ_TD_IntMaskER: Mask OCC interrupts in OIMR0
        //     PMC_ERROR, PMC_MALF_ALERT, PMC_INTERCHIP_MSG_RECVD
        //         9
        //        13
        //        21  of OCB_OCI_OIMR0_0x0006a004
        ////////////////////////////////////////////////////////////////////////////

        // ******************************************************
        // Master
        // ******************************************************

        FAPI_INF("Mask OCC interrupts in OIMR0 and OIMR1 on Master");

        // CHECKING PMC_FIRS

        e_rc = data.flushTo0();
        if (e_rc)
        {
            rc.setEcmdError(e_rc);
            break;
        }
        rc = fapiGetScom(master_target, PMC_LFIR_0x01010840 , data );
        if (rc)
        {
           FAPI_ERR("fapiGetScom(PMC_LFIR_0x01010840) failed.");
           break;
        }

        any_error = data.getDoubleWord(0);

        if (any_error)
        {
           FAPI_INF(" PMC_FIR has error(s) active.  Continuing though  0x%16llX ", data.getDoubleWord(0));
        }

        e_rc = data.flushTo0();
        if (e_rc)
        {
            rc.setEcmdError(e_rc);
            break;
        }

        rc = fapiGetScom(master_target, OCB_OCI_OIMR1_0x0006a014 , data );
        if (rc)
        {
             FAPI_ERR("fapiGetScom(OCB_OCI_OIMR1_0x0006a014) failed.");
             break;
        }

        e_rc |= data.setBit(12);
        e_rc |= data.setBit(13);
        e_rc |= data.setBit(14);
        e_rc |= data.setBit(15);
        e_rc |= data.setBit(18);
        e_rc |= data.setBit(20);
        e_rc |= data.setBit(22);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up OCB_OCI_OIMR1_0x0006a014 on Master");
            rc.setEcmdError(e_rc);
            break;
        }

        rc = fapiPutScom(master_target, OCB_OCI_OIMR1_0x0006a014 , data );
        if (rc)
        {
             FAPI_ERR("fapiPutScom(OCB_OCI_OIMR1_0x0006a014) failed.");
             break;
        }

        rc = fapiGetScom(master_target, OCB_OCI_OIMR0_0x0006a004 , data );
        if (rc)
        {
             FAPI_ERR("fapiGetScom(OCB_OCI_OIMR0_0x0006a004) failed.");
             break;
        }

        e_rc |= data.setBit(9);
        e_rc |= data.setBit(13);
        e_rc |= data.setBit(21);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up OCB_OCI_OIMR0_0x0006a004 on Master");
            rc.setEcmdError(e_rc);
            break;
        }

        rc = fapiPutScom(master_target, OCB_OCI_OIMR0_0x0006a004 , data );
        if (rc)
        {
             FAPI_ERR("fapiPutScom(OCB_OCI_OIMR0_0x0006a004) failed.");
             break;
        }

        // ******************************************************
        // Slave
        // ******************************************************

        if (dcm)
        {

            FAPI_INF("Mask OCC interrupts in OIMR0 and OIMR1 on Slave");

            // CHECKING PMC_FIRS

            e_rc = data.flushTo0();
            if (e_rc)
            {
                FAPI_ERR("ecmdDataBufferBase error flushing buffer");
                rc.setEcmdError(e_rc);
                break;
            }

            rc = fapiGetScom(slave_target, PMC_LFIR_0x01010840 , data );
            if (rc)
            {
                FAPI_ERR("fapiGetScom(PMC_LFIR_0x01010840) failed.");
                break;
            }

            any_error = data.getDoubleWord(0);

            if (any_error)
            {
                FAPI_DBG(" PMC_FIR has error(s) active.  Continuing though  0x%16llX ", data.getDoubleWord(0));
            }

            e_rc = data.flushTo0();
            if (e_rc)
            {
                FAPI_ERR("ecmdDataBufferBase error flushing buffer");
                rc.setEcmdError(e_rc);
                break;
            }

            rc = fapiGetScom(slave_target, OCB_OCI_OIMR1_0x0006a014 , data );
            if (rc)
            {
                FAPI_ERR("fapiGetScom(OCB_OCI_OIMR1_0x0006a014) failed."); break;
            }

            e_rc |= data.setBit(12);
            e_rc |= data.setBit(13);
            e_rc |= data.setBit(14);
            e_rc |= data.setBit(15);
            e_rc |= data.setBit(18);
            e_rc |= data.setBit(20);
            e_rc |= data.setBit(22);
            if (e_rc)
            {
                FAPI_ERR("ecmdDataBufferBase error setting up OIMR1");
                rc.setEcmdError(e_rc);
                break;
            }

            rc = fapiPutScom(slave_target, OCB_OCI_OIMR1_0x0006a014 , data );
            if (rc)
            {
                FAPI_ERR("fapiPutScom(OCB_OCI_OIMR1_0x0006a014) failed.");
                break;
            }

            rc = fapiGetScom(slave_target, OCB_OCI_OIMR0_0x0006a004 , data );
            if (rc)
            {
                 FAPI_ERR("fapiGetScom(OCB_OCI_OIMR0_0x0006a004) failed.");
                 break;
            }

            e_rc |= data.setBit(9);
            e_rc |= data.setBit(13);
            e_rc |= data.setBit(21);
            if (e_rc)
            {
                FAPI_ERR("ecmdDataBufferBase error setting up OIMR0");
                rc.setEcmdError(e_rc);
                break;
            }

            rc = fapiPutScom(slave_target, OCB_OCI_OIMR0_0x0006a004 , data );
            if (rc)
            {
                 FAPI_ERR("fapiPutScom(OCB_OCI_OIMR0_0x0006a004) failed."); break;
            }
        }

        ////////////////////////////////////////////////////////////////////////////
        // Issue halt to Pstate Master FSM on master_chiptarget
        // Issue halt to Pstate Master FSM on slave_chiptarget
        //
        // 3. cRQ_TD_DisableMPS: Write PMC_MODE_REG to halt things
        //    halt_pstate_master_fsm<-1          <-1 indicates to write the bit with the value 1
        //    halt_idle_state_master_fsm<-1      <-1 indicates to write the bit with the value 1
        //    Note: Other bits are left as setup so the configuration remains as things halt, and new
        //          requests are queued (just now processed now).
        ////////////////////////////////////////////////////////////////////////////


        // ******************************************************
        // Master
        // ******************************************************
        FAPI_INF("Halt Pstates and Idles on Master");

        rc = fapiGetScom(master_target, PMC_MODE_REG_0x00062000 , data );
        if (rc)
        {
             FAPI_ERR("fapiGetScom(PMC_MODE_REG_0x00062000) failed.");
             break;
        }

        e_rc |= data.setBit(05);
        e_rc |= data.setBit(14);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_MODE_REG_0x00062000 on Master during reset");
            rc.setEcmdError(e_rc);
            break;
        }

        rc = fapiPutScom(master_target, PMC_MODE_REG_0x00062000 , data );
        if (rc)
        {
             FAPI_ERR("fapiPutScom(PMC_MODE_REG_0x00062000) failed.");
             break;
        }

        master_is_MasterPMC = pmcmode_master.isBitSet(6) && pmcmode_master.isBitSet(7) ;
        master_enable_pstate_voltage_changes = pmcmode_master.isBitSet(3) ;
//        master_enable_fw_pstate_mode = pmcmode_master.isBitSet(2) ;
        master_is_enable_interchip_interface = pmcmode_master.isBitSet(6) ;

        // Resave the updated PMC Mode reg
        pmcmode_master = data;

        // ******************************************************
        // Slave
        // ******************************************************

        if (dcm)
        {
            FAPI_INF("Halt Pstates and Idles on Slave");
            rc = fapiGetScom(slave_target, PMC_MODE_REG_0x00062000 , pmcmode_master );
            if (rc)
            {
              FAPI_ERR("fapiGetScom(PMC_MODE_REG_0x00062000) failed.");
              break;
            }

            e_rc |= data.setBit(05);
            e_rc |= data.setBit(14);
            if (e_rc)
            {
                FAPI_ERR("ecmdDataBufferBase error setting up PMC_MODE_REG_0x00062000 on Slave during reset");
                rc.setEcmdError(e_rc);
                break;
            }

            rc = fapiPutScom(slave_target, PMC_MODE_REG_0x00062000 , data );
            if (rc)
            {
                 FAPI_ERR("fapiPutScom(PMC_MODE_REG_0x00062000) failed.");
                 break;
            }

            slave_is_MasterPMC = pmcmode_slave.isBitSet(6) && pmcmode_slave.isBitSet(7) ;
//            slave_enable_pstate_voltage_changes = pmcmode_slave.isBitSet(3) ;
//            slave_enable_fw_pstate_mode = pmcmode_slave.isBitSet(2) ;
            slave_is_enable_interchip_interface = pmcmode_slave.isBitSet(6) ;

            // Resave the updated PMC Mode reg
            pmcmode_slave = data;

        }



        ////////////////////////////////////////////////////////////////////////////
        // Issue halt to interchip FSM on master_chiptarget
        // Poll for interchip interface to stop on master_chiptarget
        // If poll not complete, flag "reset_suspicious" and save the poll point; continue

        // Issue halt to interchip FSM on slave_chiptarget
        // Poll for interchip interface to stop on slave_chiptarget
        // If poll not complete, flag "reset_suspicious" and save the poll point; continue

        // Poll for Pstate Master FSM being stopped on slave_chiptarget
        // If poll not complete, flag "reset_suspicious" and save the poll point; continue
        // Poll for Pstate Master FSM being stopped on slave_chiptarget
        // If poll not complete, flag "reset_suspicious" and save the poll point; continue
        //
        // 4. if enable_interchip_interface==1
        //       cRQ_TD_HaltInterchip_On: Write PMC_INTCHP_COMMAND_REG.interchip_halt_msg_fsm<-1 Should we write the command register here ? That's why I specified the command register, PMC_INTCHP_COMMAND_REG.
        //    cRQ_TD_HaltInterchip_Wait1: Read PMC_STATUS_REG
        //    cRQ_TD_HaltInterchip_Wait2: Read PMC_INTCHP_STATUS_REG
        //       is_pstate_error_stopped = pstate_processing_is_suspended || gpsa_bdcst_error || gpsa_vchg_error || gpsa_timeout_error || pstate_interchip_error
        //       is_intchp_error_stopped = interchip_ecc_ue_err || interchip_fsm_err || (is_MasterPMC && interchip_slave_error_code != 0) is_MasterPMC where is this bit ?
        //       is_stopped = (interchip_ga_ongoing == 0) || is_pstate_error_stopped || is_intchp_error_stopped
        //       If !is_stopped Then -->cRQ_TD_HaltInterchip_Wait1  (Wait limit is parm TD_Interchip_HaltWait_max=260)
        //    cRQ_TD_HaltInterchipIf: PMC_MODE_REG.interchip_halt_if<-1 interchip_halt_if where is this bit ? PMC_MODE_REG bit 15 as documented.


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

        // ******************************************************
        // Master
        // ******************************************************
        if (dcm)
        {
            FAPI_INF("Halt interchip interface on Master");
            if (master_is_enable_interchip_interface == 1)
            {
                rc = p8_pmc_poll_interchip_halt(master_target, MASTER_SIDE, master_is_MasterPMC, slave_target );
                if (rc)
                {
                    FAPI_ERR("p8_pmc_poll_interchip_halt detected a failure.");
                    break;
                }
            }

            // ******************************************************
            // Slave
            // ******************************************************
            FAPI_INF("Halt interchip interface on Slave");
            if (slave_is_enable_interchip_interface ==1)
            {
                rc = p8_pmc_poll_interchip_halt(slave_target, SLAVE_SIDE, slave_is_MasterPMC, master_target);
                if (rc)
                {
                    FAPI_ERR("p8_pmc_poll_interchip_halt detected a failure.");
                    break;
                }
            }
        } // end dcm

        ////////////////////////////////////////////////////////////////////////////
        // If voltage changes are enabled, issue halt to SPIVID controller on FSM on master_chiptarget
        // Poll for SPIVID FSM to halt on master_chiptarget
        // If poll not complete, flag "reset_suspicious" and save the poll point; continue
        //
        // 5. if enable_pstate_voltage_changes==1
        //         HaltSpivid: PMC_SPIV_COMMAND_REG.spivid_halt_fsm<-1
        //    Spivid_HaltWait: Read PMC_SPIV_STATUS_REG
        //       is_spivid_error = spivid_retry_timeout || spivid_fsm_err
        //       if spivid_ongoing && !is_spivid_error Then -->Spivid_HaltWait
        //       else -->MPS_HaltWait
        ////////////////////////////////////////////////////////////////////////////

        if (master_enable_pstate_voltage_changes==1)
        {
            FAPI_INF("Halt SPIVID controller on Master");
            rc = p8_pmc_poll_spivid_halt(master_target, MASTER_SIDE);
            if (rc)
            {
                FAPI_ERR("p8_pmc_poll_spivid_halt detected a failure.");
                break;
            }
        }

        ////////////////////////////////////////////////////////////////////////////
        // Poll for Pstate Master FSM being stopped on master_chiptarget
        //   If poll not complete, flag "reset_suspicious" and save the poll point; continue
        // Poll for Pstate Master FSM being stopped on slave_chiptarget
        //   If poll not complete, flag "reset_suspicious" and save the poll point; continue
        //
        // 6. MPS_HaltWait: Read PMC_STATUS_REG
        //
        //       if (fw_pstate_mode)
        //          is_not_ongoing = (enable_pstate_voltage_changes==0 || volt_chg_ongoing==0) && (brd_cst_ongoing == 0)
        //       else
        //          is_not_ongoing = (enable_pstate_voltage_changes==0 || gpsa_chg_ongoing==0)
        //
        //       is_pstate_error = (pstate_interchip_error || pstate_processing_is_suspended || gpsa_bdcst_error || gpsa_vchg_error || gpsa_timeout_error)
        //            is_stopped = is_not_ongoing || is_pstate_error
        //
        //       if (!is_stopped) then -->MPS_HaltWait   (Wait limit)
        ////////////////////////////////////////////////////////////////////////////

         FAPI_INF("Check for Pstate FSM being stopped on Master");

         rc = p8_pmc_poll_pstate_halt(master_target, MASTER_SIDE);
         if (rc)
         {
             FAPI_ERR("p8_pmc_poll_pstate_halt error detected for PMC Master");
             break;
         }

        // ******************************************************
        // Slave
        // ******************************************************
        if (dcm)
        {
            FAPI_INF("Check for Pstate FSM being stopped on Slave");

            rc = p8_pmc_poll_pstate_halt(master_target, SLAVE_SIDE);
            if (rc)
            {
                FAPI_ERR("p8_pmc_poll_pstate_halt error detected for PMC Slave");
                break;
            }

        } // dcm


        ///////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Poll for O2P bridge being complete on master_chiptarget
        // As the OCC (PPC405) has been halt prior to entry of this procedure,
        //      this poll will be immediate if there are no PIB related errors present
        // Poll for O2P bridge being complete on slave_chiptarget
        // As the OCC (PPC405) has been halt prior to entry of this procedure,
        //      this poll will be immediate if there are no PIB related errors present
        //
        // Poll for O2S bridge being complete on master_chiptarget
        // As the OCC (PPC405) has been halt prior to entry of this procedure,
        //      this poll will be immediate if there are no SPIVID related errors present
        //
        // 7. Wait
        //      - If an O2P or O2S Op is pending and did not hit an error
        //      - Queisce after traffic generation or last FW GA_Step
        //    The O2P and O2S bridges are treated separately.  The firmware should handle these
        //    recognizing they are still busy, hit an error, or hit a firmware timeout.  The
        //    firmware can then choose a halt sequence for them.
        //    O2S: Write PMC_O2S_COMMAND_REG.o2s_halt_retries<-1
        //         Read PMC_O2S_STATUS_REG
        //         Wait for o2s_ongoing==0 or error (o2s_retry_timeout | o2s_write_while_bridge_busy_err | o2s_fsm_err)
        //    O2P: No halt command in PMC - wait for PIB timeout.
        //         Read PMC_O2P_CTRL_STATUS_REG
        //         Wait for o2p_ongoing==0 or error (o2p_write_while_bridge_busy_err | o2p_fsm_err | o2p_abort | o2p_parity_error)
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////

        // ******************************************************
        // Master
        // ******************************************************

        FAPI_INF("Poll for O2P bridge being complete on Master");

        rc = p8_pmc_poll_o2p_halt(master_target, MASTER_SIDE);
        if (rc)
        {
            FAPI_ERR("p8_pmc_poll_o2p_halt error detected for PMC Master");
            break;
        }

        // ******************************************************
        // Slave
        // ******************************************************

        if (dcm)
        {
            FAPI_INF("Poll for O2P bridge being complete on Slave");

            rc = p8_pmc_poll_o2p_halt(slave_target, SLAVE_SIDE);
            if (rc)
            {
                FAPI_ERR("p8_pmc_poll_o2p_halt error detected for PMC Slave");
                break;
            }
        }


        ///////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 8) Poll for Idle FSM being quiesced (timeout: 500ms to cover the case of having all 4 types of Deep Idle
        // transitions in flight)
        // Note: Previously issued special wake-ups could have triggered PORE activity through the Idle FSM (and
        // the related pending queues). if poll timeout, FAIL THE OCC RESET AS SLW RECOVER IS COMPROMISED
        //
        // Note on Idle/PORE-SLW state (prior to reset)
        // Given that special wake-up occurred before this point, any errors that resulted from that special wake-up
        // (eg PORE-SLW fatal or timeout indicated in PMC LFIR) will have fired a malfunction alert to PHYP whereby
        // the execution of p8_poreslw_recovery.C will have taken place.
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////

        // ******************************************************
        // Master
        // ******************************************************

        FAPI_INF("Poll for Idle FSM being quiesced on Master");

        rc = p8_pmc_poll_idle_halt(master_target, MASTER_SIDE);
        if (rc)
        {
            FAPI_ERR("p8_pmc_poll_idle_halt error detected for PMC Master");
            break;
        }


        // ******************************************************
        // Slave
        // ******************************************************

        if (dcm)
        {
            FAPI_INF("Poll for Idle FSM being quiesced on Slave");
            rc = p8_pmc_poll_idle_halt(slave_target, SLAVE_SIDE);
            if (rc)
            {
                FAPI_ERR("p8_pmc_poll_idle_halt error detected for PMC Slave");
                break;
            }
        }

        ///////////////////////////////////////////////////////////////////////////////
        // Issue interchip interface reset (if enabled) on master_chiptarget
        // PMC_INTCHP_COMMAND_REG.reset (0) = 1
        // PMC_INTCHP_COMMAND_REG.reset (0) = 0
        // Issue interchip interface reset (if enabled) on slave_chiptarget
        // PMC_INTCHP_COMMAND_REG.reset (0) = 1
        // PMC_INTCHP_COMMAND_REG.reset (0) = 0
        ///////////////////////////////////////////////////////////////////////////////

        // ******************************************************
        // Master
        // ******************************************************


        FAPI_INF("Reset interchip interface on Master");

        if ( master_is_enable_interchip_interface == 1)
        {

            rc = fapiGetScom(master_target, PMC_INTCHP_COMMAND_REG_0x00062014 , data );
            if (rc)
            {
                FAPI_ERR("fapiGetScom(PMC_INTCHP_COMMAND_REG_0x00062014) failed.");
                break;
            }

            e_rc = data.setBit(0);
            if (e_rc)
            {
                FAPI_ERR("ecmdDataBufferBase error setting up PMC_INTCHP_COMMAND_REG_0x00062014 on Master reset");
                rc.setEcmdError(e_rc);
                break;
            }

            rc = fapiPutScom(master_target, PMC_INTCHP_COMMAND_REG_0x00062014 , data );
            if (rc)
            {
                FAPI_ERR("fapiPutScom(PMC_INTCHP_COMMAND_REG_0x00062014) failed.");
                break;
            }

            e_rc = data.clearBit(0);
            if (e_rc)
            {
                FAPI_ERR("ecmdDataBufferBase error clearing up PMC_INTCHP_COMMAND_REG_0x00062014 on Master reset");
                rc.setEcmdError(e_rc);
                break;
            }

            rc = fapiPutScom(master_target, PMC_INTCHP_COMMAND_REG_0x00062014 , data );
            if (rc)
            {
                FAPI_ERR("fapiPutScom(PMC_INTCHP_COMMAND_REG_0x00062014) failed.");
                break;
            }
        }

        // ******************************************************
        // Slave
        // ******************************************************

         if (dcm)
         {
             FAPI_INF("Reset interchip interface on Slave");

             if ( slave_is_enable_interchip_interface == 1)
             {

                rc = fapiGetScom(slave_target, PMC_INTCHP_COMMAND_REG_0x00062014 , data );
                if (rc)
                {
                    FAPI_ERR("fapiGetScom(PMC_INTCHP_COMMAND_REG_0x00062014) failed.");
                    break;
                }

                e_rc = data.setBit(0);
                if (e_rc)
                {
                    FAPI_ERR("ecmdDataBufferBase error setting up PMC_INTCHP_COMMAND_REG_0x00062014 on Slave reset");
                    rc.setEcmdError(e_rc);
                    break;
                }

                rc = fapiPutScom(slave_target, PMC_INTCHP_COMMAND_REG_0x00062014 , data );
                if (rc)
                {
                    FAPI_ERR("fapiPutScom(PMC_INTCHP_COMMAND_REG_0x00062014) failed.");
                    break;
                }

                e_rc = data.clearBit(0);
                if (e_rc)
                {
                    FAPI_ERR("ecmdDataBufferBase error clearing up PMC_INTCHP_COMMAND_REG_0x00062014 on Slave reset");
                    rc.setEcmdError(e_rc);
                    break;
                }

                rc = fapiPutScom(slave_target, PMC_INTCHP_COMMAND_REG_0x00062014 , data );
                if (rc)
                {
                    FAPI_ERR("fapiPutScom(PMC_INTCHP_COMMAND_REG_0x00062014) failed.");
                    break;
                }
            }
        }

        ////////////////////////////////////////////////////////////////////////
        // Issue reset to the PMC
        // Note:  this action will wipe out the Idle Pending queue so that
        // requests for idle transitions (entry and exit) will be lost which
        // means that PHYP notification needs to happen.
        //
        // Write PMC_MODE_REG.pmc_reset_all_voltage_registers = 1.
        // Clearing LFIRs will have  been done by PRD
        // Note:  this will remove CONFIG settings
        // This puts the PMC into firmware mode which halts any future Global Actual operations
        ////////////////////////////////////////////////////////////////////////

        // ******************************************************
        // Master
        // ******************************************************
        // RESET_ALL_PMC_REGISTERS

        if (i_mode == PM_RESET)
        {
            FAPI_INF("Hard reset detected");
            FAPI_INF("Reset PMC on Master");
            rc = fapiGetScom(master_target, PMC_MODE_REG_0x00062000 , data );
            if (rc)
            {
                FAPI_ERR("fapiGetScom(PMC_MODE_REG_0x00062000) failed.");
                break;
            }

            e_rc = data.setBit(12);
                if (e_rc)
                {
                    FAPI_ERR("ecmdDataBufferBase error setting up PMC_INTCHP_COMMAND_REG_0x00062014 on Master reset");
                    rc.setEcmdError(e_rc);
                    break;
                }
            if (rc)
            {
                FAPI_ERR("fapiPutScom(PMC_INTCHP_COMMAND_REG_0x00062014) failed.");
                break;
            }

            rc = fapiPutScom(master_target, PMC_MODE_REG_0x00062000 , data );
            if (rc)
            {
                 FAPI_ERR("fapiPutScom(PMC_MODE_REG_0x00062000) failed.");
                 break;
            }

            // ******************************************************
            // Slave
            // ******************************************************
            if (dcm)
            {
                FAPI_INF("Reset PMC on Slave");

                rc = fapiGetScom(slave_target, PMC_MODE_REG_0x00062000 , data );
                if (rc)
                {
                     FAPI_ERR("fapiGetScom(PMC_MODE_REG_0x00062000) failed.");
                     break;
                }

                e_rc = data.setBit(12);
                if (e_rc)
                {
                    FAPI_ERR("ecmdDataBufferBase error setting up PMC_MODE_REG_0x00062000 on Slave reset");
                    rc.setEcmdError(e_rc);
                    break;
                }

                rc = fapiPutScom(slave_target, PMC_MODE_REG_0x00062000 , data );
                if (rc)
                {
                    FAPI_ERR("fapiPutScom(PMC_MODE_REG_0x00062000) failed.");
                    break;
                }
            }
        }
        else
        {
            FAPI_INF("Soft reset detected. PMC register reset skipped.");
        }
    } while(0);

    FAPI_INF("pmc_reset end...");

    return rc;
}

// ----------------------------------------------------------------------
/**
 * pmc_init_function
 *
 * @param[in] i_target Primary Chip target:   Murano - chip0; Venice - chip
 * @param[in] i_dcm     Boolean to run in DCM or SCM mode
 *
 * @retval ECMD_SUCCESS
 * @retval ERROR defined in xml
 */
fapi::ReturnCode pmc_init_function(const fapi::Target& i_target, bool i_dcm )
{
    fapi::ReturnCode rc;
    uint32_t        e_rc;
    ecmdDataBufferBase data(64);
    uint8_t         attr_pm_spivid_frame_size;
    uint8_t         attr_pm_spivid_in_delay_frame1;
    uint8_t         attr_pm_spivid_in_delay_frame2;
    uint8_t         attr_pm_spivid_clock_polarity;
    uint8_t         attr_pm_spivid_clock_phase;
    uint32_t        attr_pm_spivid_clock_divider;
    uint8_t         attr_pm_spivid_port_enable = 7;
    uint32_t        attr_pm_spivid_interframe_delay_write_status_value;
    uint32_t        attr_pm_spivid_inter_retry_delay_value;
    uint8_t         attr_pm_spivid_crc_gen_enable;
    uint8_t         attr_pm_spivid_crc_check_enable;
    uint8_t         attr_pm_spivid_majority_vote_enable;
    uint8_t         attr_pm_spivid_max_retries;
    uint8_t         attr_pm_spivid_crc_polynomial_enables;


    const uint8_t   default_spivid_frame_size = 32;
    const uint8_t   default_spivid_in_delay_frame1 = 0;
    const uint8_t   default_spivid_in_delay_frame2 = 0;
    const uint8_t   default_spivid_clock_polarity = 0;
    const uint8_t   default_spivid_clock_phase = 0;
    const uint32_t  default_spivid_port_enable = 0x0;
    const uint8_t   default_spivid_crc_gen_enable = 1;
    const uint8_t   default_spivid_crc_check_enable = 0;
    const uint8_t   default_spivid_majority_vote_enable = 1;
    const uint8_t   default_spivid_max_retries = 5;
    const uint8_t   default_spivid_crc_polynomial_enables = 0xD5;

    uint32_t        var_100ns_div_value = 0;
    uint32_t        proc_nest_frequency = 2400;
    uint32_t        attr_pm_interchip_frequency = 10;
    uint32_t        interchip_clock_divider = 0 ;

    do
    {

        rc = FAPI_ATTR_GET(ATTR_FREQ_PB, NULL, proc_nest_frequency);
        if (rc)
        {
            FAPI_ERR("fapiGetAttribute of ATTR_FREQ_PB with rc = 0x%x", (uint32_t)rc);
            break;
        }

        //    var_100ns_div_value = (( attr_proc_pss_init_nest_frequency * 1000000 * 100) /4000000000);
        var_100ns_div_value =    (( proc_nest_frequency ) /40);
        interchip_clock_divider = ( proc_nest_frequency /(attr_pm_interchip_frequency*8)-1 );

            //----------------------------------------------------------
        GETATTR_DEFAULT(rc,
                        ATTR_PM_SPIVID_FRAME_SIZE,
                        "ATTR_PM_SPIVID_FRAME_SIZE",
                        &i_target,
                        attr_pm_spivid_frame_size,
                        default_spivid_frame_size );

            //----------------------------------------------------------
        GETATTR_DEFAULT(rc,
                        ATTR_PM_SPIVID_IN_DELAY_FRAME1,
                        "ATTR_PM_SPIVID_IN_DELAY_FRAME1",
                        &i_target,
                        attr_pm_spivid_in_delay_frame1,
                        default_spivid_in_delay_frame1 );

            //----------------------------------------------------------
        GETATTR_DEFAULT(rc,
                        ATTR_PM_SPIVID_IN_DELAY_FRAME1,
                        "ATTR_PM_SPIVID_IN_DELAY_FRAME1",
                        &i_target,
                        attr_pm_spivid_in_delay_frame2,
                        default_spivid_in_delay_frame2 );

            //----------------------------------------------------------
        GETATTR_DEFAULT(rc,
                        ATTR_PM_SPIVID_CLOCK_POLARITY,
                        "ATTR_PM_SPIVID_CLOCK_POLARITY",
                        &i_target,
                        attr_pm_spivid_clock_polarity,
                        default_spivid_clock_polarity );

            //----------------------------------------------------------
        GETATTR_DEFAULT(rc,
                        ATTR_PM_SPIVID_CLOCK_PHASE,
                        "ATTR_PM_SPIVID_CLOCK_PHASE",
                        &i_target,
                        attr_pm_spivid_clock_phase,
                        default_spivid_clock_phase );

            //----------------------------------------------------------
        GETATTR_DEFAULT(rc,
                        ATTR_PM_SPIVID_CRC_GEN_ENABLE,
                        "ATTR_PM_SPIVID_CRC_GEN_ENABLE",
                        &i_target,
                        attr_pm_spivid_crc_gen_enable,
                        default_spivid_crc_gen_enable );

            //----------------------------------------------------------
        GETATTR_DEFAULT(rc,
                        ATTR_PM_SPIVID_CRC_CHECK_ENABLE,
                        "ATTR_PM_SPIVID_CRC_CHECK_ENABLE",
                        &i_target,
                        attr_pm_spivid_crc_check_enable,
                        default_spivid_crc_check_enable );

            //----------------------------------------------------------
        GETATTR_DEFAULT(rc,
                        ATTR_PM_SPIVID_MAJORITY_VOTE_ENABLE,
                        "ATTR_PM_SPIVID_CRC_CHECK_ENABLE",
                        &i_target,
                        attr_pm_spivid_majority_vote_enable,
                        default_spivid_majority_vote_enable );

            //----------------------------------------------------------
        GETATTR_DEFAULT(rc,
                        ATTR_PM_SPIVID_MAX_RETRIES,
                        "ATTR_PM_SPIVID_MAX_RETRIES",
                        &i_target,
                        attr_pm_spivid_max_retries,
                        default_spivid_max_retries );

            //----------------------------------------------------------
        GETATTR_DEFAULT(rc,
                        ATTR_PM_SPIVID_CRC_POLYNOMIAL_ENABLES,
                        "ATTR_PM_SPIVID_CRC_POLYNOMIAL_ENABLES",
                        &i_target,
                        attr_pm_spivid_crc_polynomial_enables,
                        default_spivid_crc_polynomial_enables );

            //----------------------------------------------------------
        GETATTR_DEFAULT(rc,
                        ATTR_PM_SPIVID_PORT_ENABLE,
                        "ATTR_PM_SPIVID_PORT_ENABLE",
                        &i_target,
                        attr_pm_spivid_port_enable,
                        default_spivid_port_enable );

           //----------------------------------------------------------
        GETATTR(        rc,
                        ATTR_PM_SPIVID_CLOCK_DIVIDER,
                        "ATTR_PM_SPIVID_CLOCK_DIVIDER",
                        &i_target,
                        attr_pm_spivid_clock_divider);

            //----------------------------------------------------------
        GETATTR(        rc,
                        ATTR_PM_SPIVID_INTERFRAME_DELAY_WRITE_STATUS_VALUE,
                        "ATTR_PM_SPIVID_INTERFRAME_DELAY_WRITE_STATUS_VALUE",
                        &i_target,
                        attr_pm_spivid_interframe_delay_write_status_value);

            //----------------------------------------------------------
        GETATTR(        rc,
                        ATTR_PM_SPIVID_INTER_RETRY_DELAY_VALUE,
                        "ATTR_PM_SPIVID_INTER_RETRY_DELAY_VALUE",
                        &i_target,
                        attr_pm_spivid_inter_retry_delay_value);

        FAPI_INF("PMC initialization as %s ...", i_dcm ? "DCM" : "SCM");

        uint8_t     o2s_frame_size = attr_pm_spivid_frame_size;
        uint8_t     o2s_in_delay1  = attr_pm_spivid_in_delay_frame1;
        uint8_t     o2s_in_delay2  = attr_pm_spivid_in_delay_frame2;
        uint8_t     o2s_clk_pol    = attr_pm_spivid_clock_polarity;
        uint8_t     o2s_clk_pha    = attr_pm_spivid_clock_phase;
        uint8_t     o2s_port_enable = attr_pm_spivid_port_enable;
        uint32_t    o2s_inter_frame_delay = attr_pm_spivid_interframe_delay_write_status_value;
        uint8_t     o2s_crc_gen_en = attr_pm_spivid_crc_gen_enable;
        uint8_t     o2s_crc_check_en = attr_pm_spivid_crc_check_enable;
        uint8_t     o2s_majority_vote_en = attr_pm_spivid_majority_vote_enable;
        uint8_t     o2s_max_retries = attr_pm_spivid_max_retries;
        uint8_t     o2s_crc_polynomial_enables = attr_pm_spivid_crc_polynomial_enables;
        uint16_t    o2s_clk_divider = attr_pm_spivid_clock_divider;
        //spivid_freq =  attr_pm_spivid_frequency;
        uint8_t     o2s_in_count2        = o2s_frame_size ;
        uint8_t     o2s_out_count2          = 0 ;
        uint8_t     o2s_bridge_enable = 0x1 ;
        uint8_t     o2s_nr_of_frames        = 2 ;
        uint8_t     o2s_in_count1        = 0 ;
        uint8_t     o2s_out_count1        = o2s_frame_size ;
        uint8_t     hangpulse_predivider = 1;
        uint8_t     gpsa_timeout_value   = 100;
        uint8_t     one=1;
        uint8_t     zero=0;
        uint8_t     is_master=0;
        uint8_t     is_slave=1;

        uint8_t     is_simulation = 0;
        uint64_t    any_error = 0;

        rc = FAPI_ATTR_GET( ATTR_IS_SIMULATION, NULL, is_simulation);
        if (rc)
        {
            FAPI_ERR("Failed to get attribute: ATTR_IS_SIMULATION.");
            break ;
        }

        if (is_simulation)
        {
            // Simulation value
            gpsa_timeout_value   = 100;
        }
        else
        {
            // Hardware
            gpsa_timeout_value   = 255;
        }

        // Here to bypass feature attribute passing until these as moved into proc.pm.pmc.scom.initfile
        o2s_bridge_enable = 0x1 ;

        e_rc = data.flushTo0();
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error flushing buffer");
            rc.setEcmdError(e_rc);
            break;
        }

        rc = fapiGetScom(i_target, PMC_LFIR_0x01010840 , data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_LFIR_0x01010840) failed.");
            break;
        }

        any_error = data.getDoubleWord(0);

        if (any_error)
        {
            // Once clear FIRs are established, this will throw errors.
            FAPI_INF("WARNING: PMC_FIR has error(s) active.  0x%016llX ", data.getDoubleWord(0));
            //FAPI_ERR(" PMC_FIR has error(s) active.  0x%16llX ", data.getDoubleWord(0));
            //FAPI_SET_HWP_ERROR(rc, RC_PROCPM_FIR_ERROR);
            //break;
        }

        //  ******************************************************************
        //     - set PMC_o2s_CTRL_REG0A (24b)
        //  ******************************************************************

        rc = fapiGetScom(i_target, PMC_O2S_CTRL_REG0A_0x00062050, data );
        if (rc)
        {
             FAPI_ERR("fapiGetScom(PMC_O2S_CTRL_REG0A) failed.");
             break;
        }

        e_rc  = data.insertFromRight(o2s_frame_size , 0,6);
        e_rc |= data.insertFromRight(o2s_out_count1 , 6,6);
        e_rc |= data.insertFromRight(o2s_in_delay1  ,12,6);
        e_rc |= data.insertFromRight(o2s_in_count1  ,18,6);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_O2S_CTRL_REG0A on Master init");
            rc.setEcmdError(e_rc);
            break;
        }

        FAPI_INF("  PMC_O2S_CTRL_REG0A / PMC_SPIV_CTRL_REG0A  Configuration");
        FAPI_INF("    frame size                 => %d ",  o2s_frame_size);
        FAPI_INF("    o2s_out_count1             => %d ",  o2s_out_count1);
        FAPI_INF("    o2s_in_delay1              => %d ",  o2s_in_delay1);
        FAPI_INF("    o2s_in_count1              => %d ",  o2s_in_count1);

        rc = fapiPutScom(i_target, PMC_O2S_CTRL_REG0A_0x00062050, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_O2S_CTRL_REG0A_0x00062050) failed.");
            break;
        }

        rc = fapiPutScom(i_target, PMC_SPIV_CTRL_REG0A_0x00062040, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_SPIV_CTRL_REG0A_0x00062040) failed.");
            break;
        }

        //  ******************************************************************
        //     - set PMC_O2S_CTRL_REG0B (24b)
        //  ******************************************************************

        rc = fapiGetScom(i_target, PMC_O2S_CTRL_REG0B_0x00062051, data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_O2S_CTRL_REG0B) failed.");
            break;
        }

        e_rc  = data.insertFromRight(o2s_out_count2,00,6);
        e_rc |= data.insertFromRight(o2s_in_delay2 ,06,6);
        e_rc |= data.insertFromRight(o2s_in_count2 ,12,6);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_O2S_CTRL_REG0B_0x00062051 on Master init");
            rc.setEcmdError(e_rc);
            break;
        }

        FAPI_INF("  PMC_O2S_CTRL_REG0B_ / PMC_SPIV_CTRL_REG0B Configuration");
        FAPI_INF("    o2s_out_count2             => %d ",  o2s_out_count2);
        FAPI_INF("    o2s_in_delay2              => %d ",  o2s_in_delay2 );
        FAPI_INF("    o2s_in_count2              => %d ",  o2s_in_count2 );

        rc = fapiPutScom(i_target, PMC_O2S_CTRL_REG0B_0x00062051, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_O2S_CTRL_REG0B_0x00062051) failed.");
            break;
        }

        rc = fapiPutScom(i_target, PMC_SPIV_CTRL_REG0B_0x00062041, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_SPIV_CTRL_REG0B_0x00062041) failed.");
            break;
        }

        //  ******************************************************************
        //     - set PMC_O2S_CTRL_REG1
        //  ******************************************************************

        rc = fapiGetScom(i_target, PMC_O2S_CTRL_REG1_0x00062052, data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_O2S_CTRL_REG1) failed.");
            break;
        }

        o2s_nr_of_frames--;
        e_rc = data.insertFromRight(o2s_bridge_enable   ,0 ,1);
        e_rc |= data.insertFromRight(o2s_clk_pol         ,2 ,1);
        e_rc |= data.insertFromRight(o2s_clk_pha         ,3 ,1);
        e_rc |= data.insertFromRight(o2s_clk_divider     ,4 ,10);
        e_rc |= data.insertFromRight(o2s_nr_of_frames    ,17,1);
        e_rc |= data.insertFromRight(o2s_port_enable     ,18,3);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_O2S_CTRL_REG1 on Master init");
            rc.setEcmdError(e_rc);
            break;
        }

        o2s_nr_of_frames++ ;
        FAPI_INF("  PMC_O2S_CTRL_REG1 / PMC_SPIV_CTRL_REG1 ");
        FAPI_INF("    o2s_bridge_enable           => %d ",  o2s_bridge_enable );
        FAPI_INF("    o2s_clk_pol                 => %d ",  o2s_clk_pol    );
        FAPI_INF("    o2s_clk_pha                 => %d ",  o2s_clk_pha    );
        FAPI_INF("    o2s_clk_divider             => 0x%x", o2s_clk_divider);
        FAPI_INF("    o2s_nr_of_frames            => %d ",  o2s_nr_of_frames);
        FAPI_INF("    o2s_port_enable             => %d ",  o2s_port_enable);


        rc = fapiPutScom(i_target, PMC_O2S_CTRL_REG1_0x00062052, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_O2S_CTRL_REG1_0x00062052) failed.");
             break;
        }

        rc = fapiPutScom(i_target, PMC_SPIV_CTRL_REG1_0x00062042, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_SPIV_CTRL_REG1_0x00062042) failed.");
            break;
        }

        //  ******************************************************************
        //     - set PMC_O2S_CTRL_REG2
        //  ******************************************************************

        rc = fapiGetScom(i_target, PMC_O2S_CTRL_REG2_0x00062053, data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_O2S_CTRL_REG2) failed.");
            break;
        }

        e_rc = data.insertFromRight(  o2s_inter_frame_delay   ,0,17);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_O2S_CTRL_REG2 on Master init");
            rc.setEcmdError(e_rc);
            break;
        }


        FAPI_INF("  PMC_O2S_CTRL_REG2_ / PMC_SPIV_CTRL_REG2Configuration");
        FAPI_INF("    o2s_inter_frame_delay       => %d ",  o2s_inter_frame_delay );

        rc = fapiPutScom(i_target, PMC_O2S_CTRL_REG2_0x00062053, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_O2S_CTRL_REG2_0x00062053) failed.");
            break;
        }

        rc = fapiPutScom(i_target, PMC_SPIV_CTRL_REG2_0x00062043, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_SPIV_CTRL_REG2_0x00062043) failed.");
            break;
        }

        //  ******************************************************************
        //     - set PMC_SPIV_CTRL_REG3
        //  ******************************************************************

        rc = fapiGetScom(i_target, PMC_SPIV_CTRL_REG3_0x00062044, data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_SPIV_CTRL_REG3) failed.");
            break;
        }

        e_rc = data.insertFromRight(  attr_pm_spivid_inter_retry_delay_value   ,0,17);
        e_rc |= data.insertFromRight(  var_100ns_div_value , 17 , 6);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_SPIV_CTRL_REG3 on Master init");
            rc.setEcmdError(e_rc);
            break;
        }

        FAPI_INF("  PMC_SPIV_CTRL_REG3 Configuration                  ");
        FAPI_INF("    spivid_inter_retry_delay_value => %d ",  attr_pm_spivid_inter_retry_delay_value );
        FAPI_INF("    100ns_div_value                => %d ",  var_100ns_div_value);

        rc = fapiPutScom(i_target, PMC_SPIV_CTRL_REG3_0x00062044, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_SPIV_CTRL_REG3_0x00062044) failed.");
            break;
        }

            //  ******************************************************************
        //     - set PMC_O2S_CTRL_REG4
        //  ******************************************************************

        rc = fapiGetScom(i_target, PMC_O2S_CTRL_REG4_0x00062055, data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_O2S_CTRL_REG4) failed.");
            break;
        }

        e_rc  = data.insertFromRight(  o2s_crc_gen_en         ,0,1);
        e_rc |= data.insertFromRight(  o2s_crc_check_en       ,1,1);
        e_rc |= data.insertFromRight(  o2s_majority_vote_en   ,2,1);
        e_rc |= data.insertFromRight(  o2s_max_retries        ,3,5);
        e_rc |= data.insertFromRight(  o2s_crc_polynomial_enables,8,8);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_O2S_CTRL_REG on Master init");
            rc.setEcmdError(e_rc);
            break;
        }

        FAPI_INF("  PMC_O2S_CTRL_REG4 Configuration");
        FAPI_INF("    o2s_crc_gen_en           => %d ",  o2s_crc_gen_en          );
        FAPI_INF("    o2s_crc_check_en         => %d ",  o2s_crc_check_en        );
        FAPI_INF("    o2s_majority_vote_en     => %d ",  o2s_majority_vote_en    );
        FAPI_INF("    o2s_max_retries          => %d ",  o2s_max_retries         );
        FAPI_INF("    o2s_crc_polynomial_enab  => 0x%x ",  o2s_crc_polynomial_enables );


        rc = fapiPutScom(i_target, PMC_O2S_CTRL_REG4_0x00062055, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_O2S_CTRL_REG4_0x00062055) failed.");
            break;
        }

        //  ******************************************************************
        //   Program crc polynomials
        //  ******************************************************************

        rc = fapiGetScom(i_target, PMC_SPIV_CTRL_REG4_0x00062045, data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_SPIV_CTRL_REG4) failed.");
            break;
        }

        e_rc  = data.insertFromRight(  o2s_crc_gen_en         ,0,1);
        e_rc |= data.insertFromRight(  o2s_crc_check_en       ,1,1);
        e_rc |= data.insertFromRight(  o2s_majority_vote_en   ,2,1);
        e_rc |= data.insertFromRight(  o2s_max_retries        ,3,5);
        e_rc |= data.insertFromRight(  o2s_crc_polynomial_enables,8,8);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_SPIV_CTRL_REG4 on Master init");
            rc.setEcmdError(e_rc);
            break;
        }

        FAPI_INF("  PMC_SPIV_CTRL_REG4 Configuration");
        FAPI_INF("    spiv_crc_gen_en           => %d ",  o2s_crc_gen_en          );
        FAPI_INF("    spiv_crc_check_en         => %d ",  o2s_crc_check_en        );
        FAPI_INF("    spiv_majority_vote_en     => %d ",  o2s_majority_vote_en    );
        FAPI_INF("    spiv_max_retries          => %d ",  o2s_max_retries         );
        FAPI_INF("    spiv_crc_polynomial_enab  => 0x%x ",  o2s_crc_polynomial_enables );

        rc = fapiPutScom(i_target, PMC_SPIV_CTRL_REG4_0x00062045, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_SPIV_CTRL_REG4_0x00062045) failed.");
            break;
        }

        //  ******************************************************************
        //     - write PMC_PARAMETER_REG0
        //  ******************************************************************
        rc = fapiGetScom(i_target, PMC_PARAMETER_REG0_0x00062005, data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_PARAMETER_REG0_0x00062005) failed.");
            break;
        }

        e_rc = data.insertFromRight(hangpulse_predivider ,15,6);
        e_rc |= data.insertFromRight(gpsa_timeout_value   ,21,8);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_PARAMETER_REG0_0x00062005 on Master init");
            rc.setEcmdError(e_rc);
            break;
        }

        FAPI_INF("  PMC_PARAMETER_REG0 Configuration");
        FAPI_INF("    hangpulse_predivider       => 0x%x ",  hangpulse_predivider);
        FAPI_INF("    gpsa_timeout_value         => 0x%x ",  gpsa_timeout_value  );

        rc = fapiPutScom(i_target, PMC_PARAMETER_REG0_0x00062005, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_PARAMETER_REG0_0x00062005) failed.");
            break;
        }

        //  ******************************************************************
        //     - write PMC_RAIL_BOUNDS_0x00062003 to place open defaults into
        //          the rail bounds as the hardware defaults to both being
        //          00 --- which may be a turbo frequency.
        //  ******************************************************************
        //  Added for SW207759
        rc = fapiGetScom(i_target, PMC_RAIL_BOUNDS_0x00062003, data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_RAIL_BOUNDS_0x00062003) failed.");
            break;
        }

        e_rc |= data.setByte(0, -128);  // Pmin
        e_rc |= data.setByte(1,  127);  // Pmax
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_RAIL_BOUNDS_0x00062003 on Master init");
            rc.setEcmdError(e_rc);
            break;
        }

        FAPI_INF("  PMC_RAIL_BOUNDS_0x00062003 Configuration");
        FAPI_INF("    pmin_rail       => 0x%x ",  data.getByte(0));
        FAPI_INF("    pmax_rail       => 0x%x ",  data.getByte(1));

        rc = fapiPutScom(i_target, PMC_RAIL_BOUNDS_0x00062003, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_RAIL_BOUNDS_0x00062003) failed.");
            break;
        }

        //  ******************************************************************
        //     - write PMC_MODE_REG
        //  ******************************************************************
        rc = fapiGetScom(i_target, PMC_MODE_REG_0x00062000, data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_MODE_REG_0x00062000) failed.");
            break;
        }

        e_rc  = data.insertFromRight(zero , 0  ,1); //HW_PSTATE_MODE
        e_rc |= data.insertFromRight(zero , 1  ,1); //FW_PSTATE_AUCTI
        e_rc |= data.insertFromRight(one  , 2  ,1); //FW_PSTATE_MODEON_MODE
        e_rc |= data.insertFromRight(one  , 9  ,1); //ENABLE_PSTATE_STEPPING (hack for PSS miss)
        e_rc |= data.insertFromRight(zero , 13 ,1); //SAFE_MODE_WITHOUT_SPIVID
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_SPIV_CTRL_REG4 on Master init");
            rc.setEcmdError(e_rc);
            break;
        }

        FAPI_INF("  PMC_MODE_REG Configuration");
        FAPI_INF("    SAFE_MODE_WITHOUT_SPIVID       => %d ",  zero);

        rc = fapiPutScom(i_target, PMC_MODE_REG_0x00062000, data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_MODE_REG_0x00062000) failed.");
            break;
        }

        // *************************************************************
        // REGISTER WRITES FOR DCMS
        // *************************************************************

        if (i_dcm)
        {
            rc = fapiGetScom(i_target, DEVICE_ID_REG_0x000F000F, data );
            if (rc)
            {
                FAPI_ERR("fapiGetScom(DEVICE_ID_REG_0x000F000F) failed.");
                break;
            }

            is_master = data.isBitClear(39) ;
            is_slave = not is_master ;

            if (is_master)
            {
                FAPI_INF ("**** Setting up DCM Master ****");
            }
            else
            {
                FAPI_INF ("**** Setting up DCM Slave ****");
            }
            //  ****************************************************************
            //     - write PMC_MODE_REG
            //  ****************************************************************
            rc = fapiGetScom(i_target, PMC_MODE_REG_0x00062000, data );
            if (rc)
            {
                FAPI_ERR("fapiGetScom(PMC_MODE_REG_0x00062000) failed.");
                break;
            }

            e_rc  = data.insertFromRight( one      , 6 ,1); //ENABLE_INTERCHIP_INTERFACE
            e_rc |= data.insertFromRight( is_master, 7 ,1); //INTERCHIP_MODE
            e_rc |= data.insertFromRight( is_master, 8 ,1); //ENABLE_INTERCHIP_PSTATE_IN_HAPS
            e_rc |= data.insertFromRight( is_slave ,13 ,1); //SAFEMODE_WITHOUT_SPIVID
            if (e_rc)
            {
                FAPI_ERR("ecmdDataBufferBase error setting up PMC_MODE_REG_0x00062000 on Master DCM init");
                rc.setEcmdError(e_rc);
                break;
            }

            FAPI_INF("  PMC_MODE_REG Configuration");
            FAPI_DBG("    ENABLE_INTERCHIP_INTERFACE             => %d ", one       );
            FAPI_DBG("    INTERCHIP_MODE                         => %d ", is_master );
            FAPI_DBG("    ENABLE_INTERCHIP_PSTATE_IN_HAPS        => %d ", is_master );
            FAPI_DBG("    SAFE_MODE_WITHOUT_SPIVID               => %d ", is_slave  );

            rc = fapiPutScom(i_target, PMC_MODE_REG_0x00062000, data );
            if (rc)
            {
                FAPI_ERR("fapiPutScom(PMC_MODE_REG_0x00062000) failed.");
                break;
            }
            FAPI_DBG(" before exiting pmc_init PMC_MODE_REG_0x00062000  =>0x%16llx", data.getDoubleWord(0));

            //  ******************************************************************
            //     - set PMC_O2S_CTRL_REG1
            //  ******************************************************************

            rc = fapiGetScom(i_target, PMC_O2S_CTRL_REG1_0x00062052, data );
            if (rc)
            {
                FAPI_ERR("fapiGetScom(PMC_O2S_CTRL_REG1) failed.");
                break;
            }

            // Force the port enables on the slave or else the SPIVID on the slave
            // chip will hang
            if (is_slave)
            {
                 o2s_port_enable = 4 ;
                 e_rc = data.insertFromRight(o2s_port_enable     ,18,3);
                 if (e_rc)
                 {
                     FAPI_ERR("ecmdDataBufferBase error setting up forced slave port enable on Slave DCM init");
                     rc.setEcmdError(e_rc);
                     break;
                 }
                 FAPI_INF("Forcing port enable on slave to avoid SPIVID controller hang");
                 FAPI_INF("  PMC O2S CTRL_REG_1 / PMC_SPIV_CTRL_REG1 Configuration");
                 FAPI_INF("    spiv/o2s_port_enable       => %d ",  o2s_port_enable  );
            }

            // \todo this should be looked at for removal to avoid future problems
            rc = fapiPutScom(i_target, PMC_O2S_CTRL_REG1_0x00062052, data );
            if (rc)
            {
                FAPI_ERR("fapiPutScom(PMC_O2S_CTRL_REG1_0x00062052) failed.");
                break;
            }

            rc = fapiPutScom(i_target, PMC_SPIV_CTRL_REG1_0x00062042, data );
            if (rc)
            {
                FAPI_ERR("fapiPutScom(PMC_SPIV_CTRL_REG1_0x00062042) failed.");
                break;
            }

            //  ******************************************************************
            //     - write PMC_INTCHP_CTRL_REG1
            //  ******************************************************************
            rc = fapiGetScom(i_target, PMC_INTCHP_CTRL_REG1_0x00062010, data );
            if (rc)
            {
                FAPI_ERR("fapiGetScom(PMC_INTCHP_CTRL_REG1_0x00062010) failed.");
                break;
            }

            e_rc  = data.insertFromRight(one , 0 ,1);                      //INTERCHIP_GA_FSM_ENABLE
            e_rc |= data.insertFromRight(zero, 7 ,1);                      //INTERCHIP_CPHA
            e_rc |= data.insertFromRight( interchip_clock_divider, 4 ,10); //INTERCHIP_CLOCK_DIVIDER
            if (e_rc)
            {
                FAPI_ERR("ecmdDataBufferBase error setting up PMC_INTCHP_CTRL_REG1_0x00062010 on Master DCM init");
                rc.setEcmdError(e_rc);
                break;
            }

            FAPI_INF("  PMC_INTCHP_CTRL_REG1 Configuration                  ");
            FAPI_DBG("    INTERCHIP_GA_FSM_ENABLE        =>   %d ",  one          );
            FAPI_DBG("    INTERCHIP_CPHA                 =>   %d ", zero     );
            FAPI_DBG("    INTERCHIP_CLOCK_DIVIDER        => 0x%x ", interchip_clock_divider     );

            rc = fapiPutScom(i_target, PMC_INTCHP_CTRL_REG1_0x00062010, data );
            if (rc)
            {
                FAPI_ERR("fapiPutScom(PMC_INTCHP_CTRL_REG1_0x00062010) failed.");
                break;
            }
            FAPI_DBG(" before exiting pmc_init PMC_INTCHP_CTRL_REG1_0x00062010  =>0x%16llx", data.getDoubleWord(0));

            //  ******************************************************************
            //     - write PMC_INTCHP_CTRL_REG4
            //  ******************************************************************
            rc = fapiGetScom(i_target, PMC_INTCHP_CTRL_REG4_0x00062012, data );
            if (rc)
            {
                FAPI_ERR("fapiGetScom(PMC_INTCHP_CTRL_REG4_0x00062012) failed.");
                break;
            }
            e_rc  = data.insertFromRight(one , 0 ,1); //INTERCHIP_ECC_GEN_EN
            e_rc |= data.insertFromRight(one , 1 ,1); //INTERCHIP_ECC_CHECK_EN
            e_rc |= data.insertFromRight(one , 2 ,1); //INTERCHIP_MSG_RCV_OVERFLOW_CHECK_EN
            e_rc |= data.insertFromRight(one , 3 ,1); //INTERCHIP_ECC_UE_BLOCK_EN
            if (e_rc)
            {
                FAPI_ERR("ecmdDataBufferBase error setting up PMC_INTCHP_CTRL_REG1_0x00062010 on Master DCM init");
                rc.setEcmdError(e_rc);
                break;
            }

            FAPI_INF("  PMC_INTCHP_CTRL_REG4 Configuration                  ");
            FAPI_DBG("    INTERCHIP_ECC_GEN_EN                       =>   %d ",  one          );
            FAPI_DBG("    INTERCHIP_ECC_CHECK_EN                     =>   %d ",  one          );
            FAPI_DBG("    INTERCHIP_MSG_RCV_OVERFLOW_CHECK_EN        =>   %d ",  one          );
            FAPI_DBG("    INTERCHIP_ECC_UE_BLOCK_EN                  =>   %d ",  one          );

            rc = fapiPutScom(i_target, PMC_INTCHP_CTRL_REG4_0x00062012, data );
            if (rc)
            {
                FAPI_ERR("fapiPutScom(PMC_INTCHP_CTRL_REG4_0x00062012) failed.");
                break;
            }
            FAPI_DBG(" before exiting pmc_init PMC_INTCHP_CTRL_REG4_0x00062012  =>0x%16llx", data.getDoubleWord(0));
        } // dcm

    } while(0);


    FAPI_INF ("Done with the init");
    return rc;

}


// ----------------------------------------------------------------------
/**
 * p8_pmc_init
 *
 * @param[in] i_target1 Primary Chip target:   Murano - chip0; Venice - chip
 * @param[in] i_target2 Secondary Chip target: Murano - chip1; Venice - NULL
 * @param[in] mode (PM_INIT , PM_CONFIG, PM_RESET, PM_RESET_SOFT)
 *
 * @retval ECMD_SUCCESS
 * @retval ERROR defined in xml
 */
fapi::ReturnCode
p8_pmc_init(const fapi::Target& i_target1, const fapi::Target& i_target2, uint32_t mode)
{
    fapi::ReturnCode    rc;

    uint8_t         attr_dcm_installed_1 = 0;
    uint8_t         attr_dcm_installed_2 = 0;
    bool            dcm = false;

    do
    {

        // ------------------------------------------------
        // CONFIG mode
        // ------------------------------------------------
        if (mode == PM_CONFIG)
        {
            rc = pmc_config_spivid_settings(i_target1);
            if (rc)
            {
                FAPI_ERR("Error from pmc_config_spivid_settings for target1");
                break;
            }

            if ( i_target2.getType() != TARGET_TYPE_NONE )
            {
                rc = pmc_config_spivid_settings(i_target2);
                if (rc)
                {
                    FAPI_ERR("Error from pmc_config_spivid_settings for target2");
                    break;
                }
            }
        }

        // ------------------------------------------------
        // INIT mode
        // ------------------------------------------------
        else if (mode == PM_INIT)
        {

            // Per SW250226, determine if initialization should be as a real DCM
            // or as a garded SCM
            rc = FAPI_ATTR_GET(ATTR_PROC_DCM_INSTALLED, &i_target1, attr_dcm_installed_1);
            if (rc)
            {
                FAPI_ERR("fapiGetAttribute of ATTR_DCM_INSTALLED with rc = 0x%x", (uint32_t)rc);
                break;
            }

            FAPI_INF (" ATTR_DCM_INSTALLED value in init function = 0x%x", attr_dcm_installed_1 );

            // Default is dcm = false
            if (attr_dcm_installed_1 == 0)
            {

                // target2 should be NULL
                // if not NULL, exit with config error
                if (i_target2.getType() != TARGET_TYPE_NONE  )
                {
                    FAPI_ERR ("Config error : target2 is not null for target1 SCM case");
                    const fapi::Target& MASTER_TARGET = i_target1;
                    const fapi::Target& SLAVE_TARGET = i_target2;
                    const uint8_t & DCM_INSTALLED_1 =  attr_dcm_installed_1;
                    const uint8_t & DCM_INSTALLED_2 =  attr_dcm_installed_2;
                    FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCINIT_SCM_INSTALL_ERROR);
                    break;
                }
            }
            // Target 1 indicates a physical DCM
            else
            {
                // Check if Target 2 indicates a real DCM.  If not, gard defaults to SCM
                if (i_target2.getType() != TARGET_TYPE_NONE  )
                {
                    rc = FAPI_ATTR_GET(ATTR_PROC_DCM_INSTALLED, &i_target2, attr_dcm_installed_2);
                    if (rc)
                    {
                        FAPI_ERR("fapiGetAttribute of ATTR_DCM_INSTALLED with rc = 0x%x", (uint32_t)rc);
                        break;
                    }
                    FAPI_INF (" ATTR_DCM_INSTALLED value in INIT function = 0x%x", attr_dcm_installed_2 );

                    if (attr_dcm_installed_2 != 1)
                    {
                        FAPI_ERR ("Config error:  DCM_INSTALLED target2 does not match target1\n" \
                                  "   target1: %08x attr:%02x, target2:%08x attr:%02x",
                                  i_target1.getType(), attr_dcm_installed_1,
                                  i_target2.getType(), attr_dcm_installed_2);
                        const fapi::Target& MASTER_TARGET = i_target1;
                        const fapi::Target& SLAVE_TARGET = i_target2;
                        const uint8_t & DCM_INSTALLED_1 =  attr_dcm_installed_1;
                        const uint8_t & DCM_INSTALLED_2 =  attr_dcm_installed_2;
                        FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCINIT_DCM_INSTALL_ERROR);
                        break;
                    }
                    dcm = true;
                }
            }


            FAPI_INF("Executing p8_pmc_init for as %s for Target %s ...",
                            dcm ? "DCM" : "SCM",
                            i_target1.toEcmdString());
            rc = pmc_init_function(i_target1, dcm);
            if (rc)
            {
                FAPI_ERR("Error from pmc_init_function for target1");
                break;
            }

            if ( i_target2.getType() != TARGET_TYPE_NONE )
            {
                FAPI_INF("Executing p8_pmc_init for Target %s ...", i_target2.toEcmdString());
                rc = pmc_init_function(i_target2, dcm);
                if (rc)
                {
                  FAPI_ERR("Error from pmc_init_function for target2");
                  break;
                }
            }
        }

        /// -------------------------------
        /// Reset:  perform hard reset of PMC
        /// -------------------------------
        else if (mode == PM_RESET)
        {
            FAPI_INF("Hard reset detected.  Calling pmc_reset_function");
            rc = pmc_reset_function(i_target1 , i_target2, mode);
            if (rc)
            {
                FAPI_ERR("Error from pmc_reset_function");
                break;
            }
        }

        // -------------------------------
        /// Reset:  perform soft reset of PMC
        /// -------------------------------
        else if (mode == PM_RESET_SOFT)
        {
            FAPI_INF("Soft reset detected.  Calling pmc_reset_function");
            rc = pmc_reset_function(i_target1 , i_target2, mode);
            if (rc)
            {
                FAPI_ERR("Error from pmc_reset_function");
                break;
            }
        }


        /// -------------------------------
        /// Unsupported Mode
        /// -------------------------------
        else
        {
            FAPI_ERR("Unknown mode passed to p8_pmc_init. Mode %x ", mode);
            const uint64_t & MODE = (uint64_t)mode;
            FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMC_CODE_BAD_MODE);
        }

    } while(0);
    //    FAPI_INF("im here ");
    return rc;

} // end p8_pmc_init


// ----------------------------------------------------------------------
/**
 * p8_pmc_poll_pstate_halt
 *
 * @param[in] i_target  Chip target
 * @param[in] i_side    Master - 0; Slave - 1
 *
 * @retval ECMD_SUCCESS
 * @retval ERROR defined in xml
 */
fapi::ReturnCode
p8_pmc_poll_pstate_halt(const fapi::Target& i_target, uint8_t const i_side)
{
    fapi::ReturnCode    rc;
    ecmdDataBufferBase  pmcstatus(64);
    ecmdDataBufferBase  porr(64);

    bool is_pstate_error_stopped = false ;
    bool is_error_stopped = false;

    uint32_t count = 0 ;
    bool is_stopped = false ;

    do
    {

        // Confirm that Pstate hardware is quiesced before changing modes
        rc = fapiGetScom(i_target, PMC_STATUS_REG_0x00062009 , pmcstatus );
        if (rc)
        {
             FAPI_ERR("fapiGetScom(PMC_STATUS_REG_0x00062009) failed.");
             break;
        }

        //  Poll for local Pstates being stopped
        for (count = 0 , is_stopped = 0 ; count <= PSTATE_HALT_POLL_COUNT && is_stopped == 0;  count++)
        {

            //  is_stopped = (GPSA_CHG_ONGOING == 0 ||
            //                VOLT_CHG_ONGOING == 0 ||
            //                BRD_CST_ONGOING  == 0) ;
            is_stopped = pmcstatus.isBitClear(7)  || pmcstatus.isBitClear(8) || pmcstatus.isBitClear(9);

            // Leave if stopped
            if (is_stopped)
                continue;

            // wait for 1 millisecond/loop in hardware
            rc = fapiDelay(1000*1000, 20000000);
            if (rc)
            {
                FAPI_ERR("FAPI delay ends up with error");
                break;
            }

            // Re-read
            rc = fapiGetScom(i_target, PMC_STATUS_REG_0x00062009 , pmcstatus );
            if (rc)
            {
                 FAPI_ERR("fapiGetScom(PMC_STATUS_REG_0x00062009) failed.");
                 break;
            }

        } // end_for
        // Error check
        if (!rc.ok())
        {
            break;
        }

        // check for Pstate errors
        is_pstate_error_stopped =   pmcstatus.isBitSet(0) ||
                                    pmcstatus.isBitSet(1) ||
                                    pmcstatus.isBitSet(5) ||
                                    pmcstatus.isBitSet(6) ||
                                    pmcstatus.isBitSet(11);

        if (is_pstate_error_stopped)
        {
            FAPI_ERR("Pstate errors exist. Reset may be suspicious but NOT failing as it could be cleared ... ");
        }

        if (count > PSTATE_HALT_POLL_COUNT)
        {
            FAPI_ERR("Timed out in polling for Local Pstates to quiesce. Reset may be suspicious but NOT failing as it could be cleared ... ");
        }


        rc = fapiGetScom(i_target, PMC_PORRR0_REG_0x0006208E , porr );
        if (rc)
        {
             FAPI_ERR("fapiGetScom(PMC_PORRR0_REG_0x0006208E) failed.");
             break;
        }

        // Poll for local Idle being stopped.  As specical wake-up was to have
        // occured prior to this, execution should be quick.  If this times out,
        // there is a significant problem.
        for (count = 0 , is_stopped = 0 ; count <= PORE_REQ_POLL_COUNT && is_stopped == 0;  count++)
        {
            //  is_stopped = (PORRR_PORE_BUSY == 0) ;
            is_stopped = porr.isBitClear(20);

            // Leave if stopped
            if (is_stopped)
                continue;

            // wait for 1 millisecond/loop in hardware
            rc = fapiDelay(1000*1000, 20000000);
            if (rc)
            {
                FAPI_ERR("FAPI delay ends up with error");
                break;
            }

            // Re-read
            rc = fapiGetScom(i_target, PMC_PORRR0_REG_0x0006208E , porr );
            if (rc)
            {
                 FAPI_ERR("fapiGetScom(PMC_PORRR0_REG_0x0006208E) failed.");
                 break;
            }

        } // end_for
        // Error check
        if (!rc.ok())
        {
            break;
        }

        // check for Idle errors
        is_error_stopped =   porr.isBitSet(21) || pmcstatus.isBitSet(12);

        if (is_error_stopped)
        {
            FAPI_ERR("PMC Idle halt errors exist.  OCC recovery cannot proceed ... ");
            const fapi::Target& TARGET = i_target;
            const uint64_t & PORR = porr.getDoubleWord(0);
            const uint64_t & PMCSTATUS = pmcstatus.getDoubleWord(0);
            FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCRESET_IDLE_ERROR);
            break;
        }

        if (count > PORE_REQ_POLL_COUNT)
        {
            FAPI_ERR("PMC Timed out in polling for Idle to Halt. OCC recovery cannot proceed ... ");
            const fapi::Target& TARGET = i_target;
            const uint64_t & PORR = porr.getDoubleWord(0);
            const uint64_t & PMCSTATUS = pmcstatus.getDoubleWord(0);
            FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCRESET_IDLE_TIMEOUT_ERROR);
            break;
        }

    }
    while (0);
    return rc;
}

// ----------------------------------------------------------------------
/**
 * p8_pmc_poll_idle_halt
 *
 * @param[in] i_target  Chip target
 * @param[in] i_side    Master - 0; Slave - 1
 *
 * @retval ECMD_SUCCESS
 * @retval ERROR defined in xml
 */
fapi::ReturnCode
p8_pmc_poll_idle_halt(const fapi::Target& i_target, const uint8_t i_side)
{
    fapi::ReturnCode    rc;
    ecmdDataBufferBase  pmcstatus(64);
    ecmdDataBufferBase  porr(64);

    bool is_error_stopped = false;

    uint32_t count = 0 ;
    bool is_stopped = false ;

    do
    {

        // Poll for local Idle being stopped.  As special wake-up was to have
        // occured prior to this, execution should be quick.  If this times out,
        // there is a significant problem.
        for (count = 0 , is_stopped = 0 ; count <= PORE_REQ_POLL_COUNT && is_stopped == 0;  count++)
        {
            //  is_stopped = (PORRR_PORE_BUSY == 0) ;
            is_stopped = porr.isBitClear(20);

            // Leave if stopped
            if (is_stopped)
                continue;

            // wait for 1 millisecond/loop in hardware
            rc = fapiDelay(1000*1000, 20000000);
            if (rc)
            {
                FAPI_ERR("FAPI delay ends up with error");
                break;
            }

            // Re-read
            rc = fapiGetScom(i_target, PMC_PORRR0_REG_0x0006208E , porr );
            if (rc)
            {
                 FAPI_ERR("fapiGetScom(PMC_PORRR0_REG_0x0006208E) failed.");
                 break;
            }

        } // end_for
        // Error check
        if (!rc.ok())
        {
            break;
        }

        // check for Idle errors
        is_error_stopped =   porr.isBitSet(21) || pmcstatus.isBitSet(12);

        if (is_error_stopped)
        {
            FAPI_ERR("PMC Idle halt errors exist.  OCC recovery cannot proceed ... ");
            const fapi::Target& TARGET = i_target;
            const uint64_t & PORR = porr.getDoubleWord(0);
            const uint64_t & PMCSTATUS = pmcstatus.getDoubleWord(0);
            FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCRESET_IDLE_ERROR);
            break;
        }

        if (count > PORE_REQ_POLL_COUNT)
        {
            FAPI_ERR("PMC Timed out in polling for Idle to Halt. OCC recovery cannot proceed ... ");
            const fapi::Target& TARGET = i_target;
            const uint64_t & PORR = porr.getDoubleWord(0);
            const uint64_t & PMCSTATUS = pmcstatus.getDoubleWord(0);
            FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCRESET_IDLE_TIMEOUT_ERROR);
            break;
        }

    }
    while (0);
    return rc;
}

// ----------------------------------------------------------------------
/**
 * p8_pmc_poll_interchip_halt
 *
 * @param[in] i_target  Chip target
 * @param[in] i_side    Master - 0; Slave - 1
 *
 * @retval ECMD_SUCCESS
 * @retval ERROR defined in xml
 */
fapi::ReturnCode
p8_pmc_poll_interchip_halt( const fapi::Target& i_target,
                            const uint8_t       i_side,
                            bool                i_MasterPMC,
                            const fapi::Target& i_dcm_target)
{
    fapi::ReturnCode    rc;
    uint32_t            e_rc;
    ecmdDataBufferBase  data(64);

    bool is_stopped = false ;
    bool is_pstate_error_stopped = false;
    bool is_intchp_error_stopped = false;

    uint32_t count = 0 ;


    do
    {
        rc = fapiGetScom(i_target, PMC_INTCHP_COMMAND_REG_0x00062014 , data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_INTCHP_COMMAND_REG_0x00062014) failed.");
            break;
        }

        e_rc = data.setBit(01);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_INTCHP_COMMAND_REG_0x00062014 on Master during reset");
            rc.setEcmdError(e_rc);
            break;
        }

        rc = fapiPutScom(i_target, PMC_INTCHP_COMMAND_REG_0x00062014 , data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_INTCHP_COMMAND_REG_0x00062014) failed.");
            break;
        }

        //  Poll for interchip interface to stop
        for (count = 0 , is_stopped = 0 ; count <= INTERCHIP_HALT_POLL_COUNT && is_stopped == 0;  count++)
        {

            rc = fapiGetScom(i_target, PMC_STATUS_REG_0x00062009 , data );
            if (rc)
            {
                FAPI_ERR("fapiGetScom(PMC_STATUS_REG_0x00062009) failed.");
                break;
            }

            //    Interchip_Wait1: Read PMC_STATUS_REG
            //       is_pstate_error_stopped =  pstate_processing_is_suspended ||
            //                                  gpsa_bdcst_error ||
            //                                  gpsa_vchg_error ||
            //                                  gpsa_timeout_error ||
            //                                  pstate_interchip_error;
            is_pstate_error_stopped =   data.isBitSet(0) ||
                                        data.isBitSet(1) ||
                                        data.isBitSet(5) ||
                                        data.isBitSet(6) ||
                                        data.isBitSet(11);

            //    Interchip_Wait2: Read PMC_INTCHP_STATUS_REG
            //       is_intchp_error_stopped =  interchip_ecc_ue_err ||
            //                                  interchip_fsm_err ||
            //                                  (is_MasterPMC && interchip_slave_error_code != 0) is_MasterPMC
            rc = fapiGetScom(i_target, PMC_INTCHP_STATUS_REG_0x00062013 , data );
            if (rc)
            {
                FAPI_ERR("fapiGetScom(PMC_INTCHP_STATUS_REG_0x00062013) failed.");
                break;
            }
            is_intchp_error_stopped =   data.isBitSet(1) ||
                                        data.isBitSet(7) ||
                                        (~( data.isBitClear(16,4) &&  i_MasterPMC)) ;

            //    is_stopped = (interchip_ga_ongoing == 0) ||
            //                  is_pstate_error_stopped ||
            //                  is_intchp_error_stopped ;
            is_stopped = data.isBitClear(0)  || is_pstate_error_stopped || is_intchp_error_stopped;

            if (is_stopped)
                continue;

            FAPI_DBG("polling interchip ongoing :  ... ");

            //       If !is_stopped Then -->Interchip_Wait1  (Wait limit is parm TD_Interchip_HaltWait_max=260)

            // wait for 1 millisecond/loop in hardware
            rc = fapiDelay(1000*1000, 20000000);
            if (rc)
            {
                FAPI_ERR("fapi delay ends up with error");
                break;
            }

        } // end_for
        // Error check
        if (!rc.ok())
        {
            break;
        }

        if (count > INTERCHIP_HALT_POLL_COUNT)
        {
            FAPI_INF("Timed out in polling interchip ongoing : Reset may be suspicious but NOT failing as it could be cleared ... ");
            const fapi::Target& THISTARGET = i_target;
            const fapi::Target& DCMTARGET = i_dcm_target;
            FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCRESET_INTCHP_TIMEOUT_ERROR);
            fapiLogError(rc, fapi::FAPI_ERRL_SEV_RECOVERED);
        }

        // InterchipIf: PMC_MODE_REG.interchip_halt_if<-1 interchip_halt_if

        rc = fapiGetScom(i_target, PMC_MODE_REG_0x00062000 , data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_MODE_REG_0x00062000) failed.");
            break;
        }

        e_rc = data.setBit(15);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_MODE_REG_0x00062000 on Master during reset");
            rc.setEcmdError(e_rc);
            break;
        }

        rc = fapiPutScom(i_target, PMC_MODE_REG_0x00062000 , data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_MODE_REG_0x00062000) failed.");
            break;
        }

    }
    while (0);
    return rc;
}

// ----------------------------------------------------------------------
/**
 * p8_pmc_poll_spivid_halt
 *
 * @param[in] i_target  Chip target
 * @param[in] i_side    Master - 0; Slave - 1
 *
 * @retval ECMD_SUCCESS
 * @retval ERROR defined in xml
 */
fapi::ReturnCode
p8_pmc_poll_spivid_halt(const fapi::Target& i_target,
                        const uint8_t       i_side)
{
    fapi::ReturnCode    rc;
    uint32_t            e_rc;
    ecmdDataBufferBase  data(64);

    bool is_spivid_stopped = false ;

    uint32_t count = 0 ;


    do
    {
        //  HaltSpivid: PMC_SPIV_COMMAND_REG.spivid_halt_fsm<-1
        rc = fapiGetScom(i_target, PMC_SPIV_COMMAND_REG_0x00062047 , data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_SPIV_COMMAND_REG_0x00062047) failed.");
            break;
        }

        e_rc = data.setBit(0);
        if (e_rc)
        {
            FAPI_ERR("ecmdDataBufferBase error setting up PMC_SPIV_COMMAND_REG_0x00062047 on Side %d during reset",
                                    i_side);
            rc.setEcmdError(e_rc);
            break;
        }

        rc = fapiPutScom(i_target, PMC_SPIV_COMMAND_REG_0x00062047 , data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_SPIV_COMMAND_REG_0x00062047) failed.");
            break;
        }

        //    Spivid_HaltWait: Read PMC_SPIV_STATUS_REG
        for (count = 0 , is_spivid_stopped=0; count <= VOLTAGE_CHANGE_POLL_COUNT  && is_spivid_stopped==0  ; count++)
        {

            rc = fapiGetScom(i_target, PMC_SPIV_STATUS_REG_0x00062046 , data );
            if (rc)
            {
              FAPI_ERR("fapiGetScom(PMC_SPIV_STATUS_REG_0x00062046) failed.");
              break;
            }
            is_spivid_stopped =   data.isBitClear(0) ||
                                  data.isBitSet(1)   ||
                                  data.isBitSet(2)   ||
                                  data.isBitSet(3)   ||
                                  data.isBitSet(4) ;

            if (is_spivid_stopped)
                continue;

            FAPI_DBG("Polling spivid ongoing on Side %d", i_side);

            // wait for 1 millisecond/loop in hardware
            rc = fapiDelay(1000*1000, 20000000);
            if (rc)
            {
                FAPI_ERR("fapi delay ends up with error");
                break;
            }

        } // end for

        // Error check
        if (!rc.ok())
        {
            break;
        }

        // Timeout check
        if (count > VOLTAGE_CHANGE_POLL_COUNT)
        {
            FAPI_ERR("Timed out in polling SPIVID ongoing  : Reset_suspicious    ... ");
            const fapi::Target& TARGET = i_target;
            FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCRESET_SPIVID_TIMEOUT_ERROR);
            fapiLogError(rc, fapi::FAPI_ERRL_SEV_RECOVERED);
        }

    }
    while (0);
    return rc;
}

// ----------------------------------------------------------------------
/**
 * p8_pmc_poll_o2p_halt
 *
 * @param[in] i_target  Chip target
 * @param[in] i_side    Master - 0; Slave - 1
 *
 * @retval ECMD_SUCCESS
 * @retval ERROR defined in xml
 */
fapi::ReturnCode
p8_pmc_poll_o2p_halt(const fapi::Target& i_target,
                     const uint8_t       i_side)
{
    fapi::ReturnCode    rc;
    uint32_t            e_rc;
    ecmdDataBufferBase  data(64);

    bool is_stopped = false ;

    uint32_t count = 0 ;


    do
    {
        rc = fapiGetScom(i_target, PMC_O2S_COMMAND_REG_0x00062057 , data );
        if (rc)
        {
            FAPI_ERR("fapiGetScom(PMC_O2S_COMMAND_REG__0x00062057) failed.");
            break;
        }

        e_rc = data.setBit(00);
        if(e_rc)
        {
            rc.setEcmdError(e_rc);
            break;
        }

        rc = fapiPutScom(i_target, PMC_O2S_COMMAND_REG_0x00062057 , data );
        if (rc)
        {
            FAPI_ERR("fapiPutScom(PMC_O2S_COMMAND_REG__0x00062057) failed.");
            break;
        }

        // Poll for O2S to be stopped
        for (count = 0 , is_stopped = 0 ; count <= O2S_POLL_COUNT && is_stopped == 0 ; count++)
        {
            // wait for 1 millisecond/loop in hardware
            rc = fapiDelay(1000*1000, 20000000);
            if (rc)
            {
                FAPI_ERR("fapi delay ends up with error");
                break;
            }
            rc = fapiGetScom(i_target, PMC_O2S_STATUS_REG_0x00062056 , data );
            if (rc)
            {
                FAPI_ERR("fapiGetScom(PMC_O2S_STATUS_REG__0x00062056) failed.");
                break;
            }

            is_stopped = (  data.isBitClear(0) ||
                            data.isBitSet(4)   ||
                            data.isBitSet(5)   ||
                            data.isBitSet(7));
            FAPI_DBG("Polling O2S ongoing . :   .. ");
        }

        // Error check
        if (!rc.ok())
        {
            break;
        }

        // Timeout check
        if (count > O2P_POLL_COUNT)
        {
            FAPI_ERR("Timed out in polling O2P ongoing . : Reset_suspicious .. ");
            const fapi::Target& TARGET = i_target;
            const uint64_t & O2PSTATUS = data.getDoubleWord(0);
            FAPI_SET_HWP_ERROR(rc, RC_PROCPM_PMCRESET_O2P_TIMEOUT_ERROR);
            fapiLogError(rc, fapi::FAPI_ERRL_SEV_RECOVERED);
        }

    }
    while (0);
    return rc;
}

} //end extern C

/*
*************** Do not edit this area ***************
This section is automatically updated by CVS when you check in this file.
Be sure to create CVS comments when you commit so that they can be included here.

$Log: p8_pmc_init.C,v $
Revision 1.42  2014/04/10 21:12:22  stillgs
Per SW256701, hardcode the enablement of Pstate Stepping in PMC Mode reg for GA1

Revision 1.41  2014/04/03 20:29:13  cmolsen
Removed three bool variables that were set only but not used.

Revision 1.40  2014/03/12 21:03:15  stillgs
Per SW251617, updates for HostCompiler tool flagged logical errors (bitwise operators were scalar was intended

Revision 1.39  2014/03/06 16:26:54  stillgs
SW250226 (deconfigured chip on DCM)

Revision 1.38  2014/03/05 22:13:13  stillgs

- Updates per RAS/callout reviews.  In dealing with these comments, did some
restructuring of common code into subroutines.  Runs through the Cronus
OCC reset shift cleanly.

Revision 1.37  2013/11/07 14:00:09  stillgs

Per SW232699, updated SPIVID parameters
/!/ Units: nanoseconds;  Value 15 microseconds
const uint32_t  default_spivid_interframe_delay_write_status = 15000;
/!/ Units: nanoseconds;  Value 40 microseconds
 const uint32_t  default_spivid_inter_retry_delay = 40000;

Revision 1.36  2013/08/02 19:09:07  stillgs

- Support for p8_pm.H.
- Temporarily changed the detection of set FIR bit from FAPI_ERR to FAPI_INF until fully complete with testing.
This keeps "FAPI ERR" from showing up in log for things that do not give non-zero RCs.
- Added plumbing support for "soft" rest.  FUNCTION IS NOT YET SUPPORTED

Revision 1.35  2013/06/07 19:17:24  stillgs

Fix swap of Pmin and PMax rail settings

Revision 1.34  2013/06/05 21:09:03  stillgs

Fix for SW207759:  Added setting of PMC Rail Bounds register to +127/-127
to deal with hardware reset values being 0s --- the turbo value for P8 machines

Revision 1.33  2013/05/24 10:53:38  pchatnah
Assigning boolean variables to false by default

Revision 1.32  2013/05/16 11:41:16  pchatnah
fixing gerrit comments

Revision 1.31  2013/05/09 10:26:33  pchatnah
fixing gerrot comments

Revision 1.30  2013/04/30 11:20:22  pchatnah
fixing memory fault issue for scm

Revision 1.29  2013/04/17 13:11:28  pchatnah
fixing some more SCM issues

Revision 1.28  2013/04/16 12:00:26  pchatnah
fixing Daniels failures on hardware

Revision 1.27  2013/04/12 01:25:02  stillgs

Update for DCM initialization and reset function per hardware testing

Revision 1.25  2013/04/06 02:14:03  pchatnah
 restructuring

Revision 1.24  2013/04/04 12:43:49  pchatnah
fixing sm_without_spivid

Revision 1.23  2013/04/02 14:17:55  pchatnah
fixing spivid_enable for slave

Revision 1.22  2013/04/01 04:11:54  stillgs

Output formating changes only to remove extraneous log content

Revision 1.21  2013/03/28 14:42:02  pchatnah
adding FIR check

Revision 1.20  2013/03/28 14:29:04  pchatnah
adding FIR check

Revision 1.19  2013/03/15 12:25:57  pchatnah
fixing no_of_ports

Revision 1.18  2013/03/04 16:15:35  pchatnah
fising more issues for prep_for_reset

Revision 1.17  2013/02/25 19:27:01  pchatnah
fising compilation issues

Revision 1.16  2013/02/21 08:58:37  pchatnah
fixing 100ns calculation

Revision 1.15  2013/02/11 15:44:16  pchatnah
fixing pstate

Revision 1.14  2013/02/07 18:44:49  pchatnah
adding PM_LFIR reset also into it

Revision 1.13  2013/01/24 11:58:12  pchatnah
adding log inside the file

*/
OpenPOWER on IntegriCloud