summaryrefslogtreecommitdiffstats
path: root/src/usr/fapi2/attribute_service.C
blob: d1a301169757765425a087062d847d41f9c4c460 (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
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/fapi2/attribute_service.C $                           */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
///
/// @file attribute_service.C
///
/// @brief Implements the platform functions that access attributes for FAPI2
///

//******************************************************************************
// Includes
//******************************************************************************

// The following file checks at compile time that all HWPF attributes are
// handled by Hostboot. This is done to ensure that the HTML file listing
// supported HWPF attributes lists attributes handled by Hostboot

#include <stdint.h>
#include <config.h>
#include <return_code.H>
#include <attribute_ids.H>
#include <attributeenums.H>
#include <fapi2platattrmacros.H>
#include <fapi2_attribute_service.H>
#include <attribute_service.H>
#include <attribute_plat_check.H>
#include <targeting/common/attributes.H>
#include <target.H>
#include <target_types.H>
#include <hwpf_fapi2_reasoncodes.H>
#include <chipids.H>

#include <devicefw/driverif.H>
#include <plat_attr_override_sync.H>
#include <vpd/spdenums.H>
#include <p9_pm_get_poundv_bucket_attr.H>
#include <p9_pm_get_poundw_bucket_attr.H>
#include <p9_frequency_buckets.H>
#include <errl/errlmanager.H>

#include <targeting/common/targetservice.H>
#include <targeting/common/predicates/predicatectm.H>
#include <targeting/common/utilFilter.H>
#include <targeting/common/util.H>
#include <../memory/lib/shared/dimmConsts.H>
#include <../memory/lib/shared/mss_const.H>
#include <../memory/lib/rosetta_map/rosetta_map.H>
#include <util/utilcommonattr.H>

#include <secureboot/service.H>

#include<vpd_accessors/accessMBvpdL4BankDelete.H>
#include<vpd_accessors/getControlCapableData.H>
#include<vpd_accessors/getDQAttrISDIMM.H>
#include<vpd_accessors/getDQSAttrISDIMM.H>
#include<vpd_accessors/getISDIMMTOC4DAttrs.H>
#include<vpd_accessors/getMBvpdAddrMirrorData.H>
#include<vpd_accessors/getMBvpdDram2NModeEnabled.H>
#include<vpd_accessors/getMBvpdMemoryDataVersion.H>
#include<vpd_accessors/getMBvpdSPDXRecordVersion.H>
#include<vpd_accessors/getMBvpdSlopeInterceptData.H>
#include<vpd_accessors/getMBvpdSensorMap.H>
#include<vpd_accessors/getMBvpdSpareDramData.H>
#include<vpd_accessors/getMBvpdVersion.H>
#include<vpd_accessors/getMBvpdVoltageSettingData.H>
#include<vpd_accessors/getMBvpdAttr.H>

//******************************************************************************
// Implementation
//******************************************************************************

namespace fapi2
{
namespace platAttrSvc
{

///
/// @brief Gets the TARGETING object for the input FAPI target
///        See doxygen in attribute_service.H
///
errlHndl_t getTargetingTarget(const Target<TARGET_TYPE_ALL>& i_pFapiTarget,
                   TARGETING::Target* & o_pTarget,
                   const TARGETING::TYPE i_expectedType)
{
    errlHndl_t l_errl = NULL;
    do
    {
        if (i_pFapiTarget.get() == NULL)
        {
            // Fapi Target object isnt point to a real target
            FAPI_ERR("getTargetingTarget. NULL Fapi Target");

            /*@
            * @errortype
            * @moduleid          fapi2::MOD_FAPI2_GET_TARGETING_TARGET
            * @reasoncode        RC_NULL_FAPI_TARGET
            * @userdata1[0:31]   Fapi2 Expected Type
            * @userdata1[32:63]  <unused>
            * @userdata2[0:7]    Is Chip
            * @userdata2[8:15]   Is Chiplet
            * @userdata2[16:63]  <unused>
            * @devdesc           Unable to resolve FapiTarget from input
            * @custdesc          Firmware Error
            */
            l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            MOD_FAPI2_GET_TARGETING_TARGET,
                                            RC_NULL_FAPI_TARGET,
                                            i_expectedType,
                                            TWO_UINT8_TO_UINT16(
                                            i_pFapiTarget.isChip(),
                                            i_pFapiTarget.isChiplet()));

            l_errl->collectTrace(FAPI_TRACE_NAME);
            l_errl->collectTrace(FAPI_IMP_TRACE_NAME);

            break;
        }

        o_pTarget = reinterpret_cast<TARGETING::Target*>(i_pFapiTarget.get());
        if(i_expectedType != TARGETING::TYPE_NA)
        {
            TARGETING::TYPE l_type = o_pTarget->getAttr<TARGETING::ATTR_TYPE>();

            if (l_type != i_expectedType)
            {
                FAPI_ERR("getTargetingTarget. Type: %d, expected %d", l_type,
                        i_expectedType);
                /*@
                * @errortype
                * @moduleid          fapi2::MOD_FAPI2_GET_TARGETING_TARGET
                * @reasoncode        RC_MISMATCHED_FAPI_TARG_TARGET
                * @userdata1[0:31]   Actual Type
                * @userdata1[32:63]  Expected Type
                * @userdata2[0:31]   Initial FAPI2 Type
                * @userdata2[32:47]  Is Chip
                * @userdata2[48:63]  Is Chiplet
                * @devdesc           When coverting from FAPI2::target to
                *                    Targeting::target the resulting
                                    Targeting::target's was incorrect
                * @custdesc          Firmware Error
                */
                l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                                MOD_FAPI2_GET_TARGETING_TARGET,
                                                RC_MISMATCHED_FAPI_TARG_TARGET,
                                                TWO_UINT32_TO_UINT64(l_type,
                                                i_expectedType),
                                                TWO_UINT32_TO_UINT64(
                                                i_pFapiTarget.getType(),
                                                TWO_UINT16_TO_UINT32(
                                                i_pFapiTarget.isChip(),
                                                i_pFapiTarget.isChiplet())));

                l_errl->collectTrace(FAPI_TRACE_NAME);
                l_errl->collectTrace(FAPI_IMP_TRACE_NAME);
                break;
            }
        }
    } while(0);

    return l_errl;
}

bool getTargetingAttrHelper(TARGETING::Target * i_pTargTarget,
                            const TARGETING::ATTRIBUTE_ID i_targAttrId,
                            const uint32_t i_attrSize, void * o_pAttr)
{
    return i_pTargTarget->_tryGetAttr(i_targAttrId, i_attrSize, o_pAttr);
}

///
/// @brief Gets a Targeting attribute, this is called by the macro that maps a
///        FAPI Attribute get to a TARGETING attribute and should not be called
///        directly.
///        See doxygen in H file.
///
ReturnCode getTargetingAttr(
           const Target< TARGET_TYPE_ALL, MULTICAST_OR,
                plat_target_handle_t >& i_pFapiTarget,
           const TARGETING::ATTRIBUTE_ID i_targAttrId,
           const uint32_t i_attrSize,
           void * o_pAttr)
{
    errlHndl_t l_errl = NULL;
    ReturnCode l_rc;
    TARGETING::Target * l_pTargTarget = NULL;
    l_errl = getTargetingTarget(i_pFapiTarget, l_pTargTarget);

    if (l_errl)
    {
        FAPI_ERR("getTargetingAttr: Error from getTargetingTarget");
        l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        // Note directly calling Target's private _tryGetAttr function for code
        // size optimization, the public function is a template function that
        // cannot be called with a variable attribute ID, the template function
        // checks at compile time that the Targeting attribute is readable, but
        // that is already checked by the Targeting compiler
        bool l_success = getTargetingAttrHelper(l_pTargTarget,
                                                i_targAttrId,
                                                i_attrSize, o_pAttr);

        if (!l_success)
        {
            FAPI_ERR("getTargetingAttr: Error from getTargetingAttrHelper "
                     "for target 0x%.8X and attribute 0x%x",
                     TARGETING::get_huid(l_pTargTarget), i_targAttrId);

            /*@
             * @errortype
             * @moduleid          fapi2::MOD_FAPI2_GET_TARGETING_ATTR
             * @reasoncode        RC_INVALID_ATTRIBUTE
             * @userdata1[0:31]   FAPI2 Target Type
             * @userdata1[32:63]  HB Target HUID
             * @userdata2         Requested attribute ID
             * @devdesc           Invalid attribute read request
             * @custdesc          Firmware Error
             */
            l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                             MOD_FAPI2_GET_TARGETING_ATTR,
                                             RC_INVALID_ATTRIBUTE,
                                             TWO_UINT32_TO_UINT64(
                                              i_pFapiTarget.getType(),
                                              TARGETING::get_huid(l_pTargTarget)
                                             ),
                                             i_targAttrId);

            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
        }
    }
    return l_rc;
}

bool setTargetingAttrHelper(TARGETING::Target * l_pTargTarget,
                            const TARGETING::ATTRIBUTE_ID i_targAttrId,
                            const uint32_t i_attrSize,
                            void * o_pAttr)
{
    return l_pTargTarget->_trySetAttr(i_targAttrId, i_attrSize, o_pAttr);
}

///
/// @brief Sets a Targeting attribute, this is called by the macro that maps a
///        FAPI Attribute set to a FAPI2 TARGETING attribute and should not be
///        called directly
///        See doxygen in H file
///
ReturnCode setTargetingAttr(
           const Target<TARGET_TYPE_ALL, MULTICAST_OR,
                plat_target_handle_t >& i_pFapiTarget,
           const TARGETING::ATTRIBUTE_ID i_targAttrId,
           const uint32_t i_attrSize,
           void * i_pAttr)
{
    ReturnCode l_rc;
    errlHndl_t l_errl = NULL;
    TARGETING::Target * l_pTargTarget = NULL;
    l_errl = getTargetingTarget(i_pFapiTarget, l_pTargTarget);

    if (l_errl)
    {
        FAPI_ERR("setTargetingAttr: Error from getTargetingTarget");
        l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        // Note directly calling Target's private _trySetAttr function for code
        // size optimization, the public function is a template function that
        // cannot be called with a variable attribute ID, the template function
        // checks at compile time that the Targeting attribute is readable, but
        // that is already checked by the Targeting compiler
        bool l_success = setTargetingAttrHelper(l_pTargTarget,
                                                i_targAttrId,
                                                i_attrSize,
                                                    i_pAttr);

        if (!l_success)
        {
            FAPI_ERR("setTargetingAttr: Error from setTargetingAttrHelper "
                     "for target 0x%.8X and attribute 0x%x",
                     TARGETING::get_huid(l_pTargTarget), i_targAttrId);

            /*@
             * @errortype
             * @moduleid          fapi2::MOD_FAPI2_SET_TARGETING_ATTR
             * @reasoncode        RC_INVALID_ATTRIBUTE
             * @userdata1[0:31]   FAPI2 Target Type
             * @userdata1[32:63]  HB Target HUID
             * @userdata2         Requested attribute ID
             * @devdesc           Invalid attribute write request
             * @custdesc          Firmware Error
             */
            l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                             MOD_FAPI2_SET_TARGETING_ATTR,
                                             RC_INVALID_ATTRIBUTE,
                                             TWO_UINT32_TO_UINT64(
                                              i_pFapiTarget.getType(),
                                              TARGETING::get_huid(l_pTargTarget)
                                             ),
                                             i_targAttrId);

            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
        }
    }
    return l_rc;
}

//******************************************************************************
// platGetTargetName function
//******************************************************************************
ReturnCode platGetTargetName(const Target<TARGET_TYPE_ALL>& i_pFapiTarget,
                                 uint8_t & o_name)
{
    ReturnCode l_rc;
    errlHndl_t l_errl = NULL;
    TARGETING::Target * l_pHbTarget = NULL;
    o_name = ENUM_ATTR_NAME_NONE;

    do
    {
        l_errl = getTargetingTarget(i_pFapiTarget, l_pHbTarget);

        if (l_errl)
        {
            FAPI_ERR("platGetTargetName: Error from getTargetingTarget");
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        TARGETING::MODEL l_model =
            l_pHbTarget->getAttr<TARGETING::ATTR_MODEL>();

        if (l_model == TARGETING::MODEL_NIMBUS)
        {
            o_name = ENUM_ATTR_NAME_NIMBUS;
        }
        else if (l_model == TARGETING::MODEL_CUMULUS)
        {
            o_name = ENUM_ATTR_NAME_CUMULUS;
        }
        else if (l_model == TARGETING::MODEL_CENTAUR)
        {
            o_name = ENUM_ATTR_NAME_CENTAUR;
        }
        else if (l_model == TARGETING::MODEL_AXONE)
        {
            o_name = ENUM_ATTR_NAME_AXONE;
        }
        else if (l_model == TARGETING::MODEL_OCMB)
        {
            // For MODEL_OCMB the ATTR_CHIP_ID determines if it is a
            // Gemini or an Explorer chip
            uint32_t l_chipID =
                l_pHbTarget->getAttr<TARGETING::ATTR_CHIP_ID>();

            if (l_chipID == POWER_CHIPID::EXPLORER_16)
            {
                o_name = ENUM_ATTR_NAME_EXPLORER;
            }
            else if (l_chipID == POWER_CHIPID::GEMINI_16)
            {
                o_name = ENUM_ATTR_NAME_GEMINI;
            }
            else
            {
                FAPI_ERR("platGetTargetName. Unknown CHIP_ID 0x%x for MODEL_OCMB 0x%x", l_chipID, l_model);

                /*@
                * @errortype
                * @moduleid          fapi2::MOD_FAPI2_GET_TARGETING_TARGET
                * @reasoncode        RC_UNKNOWN_OCMB_CHIP_TYPE
                * @userdata1[0:31]    FAPI2 Type
                * @userdata1[32:63]   HB Target HUID
                * @userdata2[0:31]    HB Type
                * @userdata2[32:63]   HB Target CHIP_ID
                * @devdesc           HB OCMB_CHIP target found with unknown
                *                    model based on ATTR_CHIP_ID
                * @custdesc          Firmware Error
                */
                l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            MOD_FAPI2_GET_TARGETING_TARGET,
                                            RC_UNKNOWN_OCMB_CHIP_TYPE,
                                            TWO_UINT32_TO_UINT64(
                                            i_pFapiTarget.getType(),
                                            TARGETING::get_huid(l_pHbTarget)
                                            ),
                                            TWO_UINT32_TO_UINT64(
                                            l_pHbTarget->
                                            getAttr<TARGETING::ATTR_TYPE>(),
                                            l_chipID));

                l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
                break;
            }
        }
        else
        {
            FAPI_ERR("platGetTargetName. Unknown name 0x%x", l_model);

            /*@
            * @errortype
            * @moduleid          fapi2::MOD_FAPI2_GET_TARGETING_TARGET
            * @reasoncode        RC_UNKNOWN_MODEL
            * @userdata1[0:31]    FAPI2 Type
            * @userdata1[32:63]   HB Target HUID
            * @userdata2[0:31]    HB Type
            * @userdata2[32:63]   HB Model
            * @devdesc           HB target found with unknown model attribute
            * @custdesc          Firmware Error
            */
            l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            MOD_FAPI2_GET_TARGETING_TARGET,
                                            RC_UNKNOWN_MODEL,
                                            TWO_UINT32_TO_UINT64(
                                            i_pFapiTarget.getType(),
                                            TARGETING::get_huid(l_pHbTarget)
                                            ),
                                            TWO_UINT32_TO_UINT64(
                                            l_pHbTarget->
                                            getAttr<TARGETING::ATTR_TYPE>(),
                                            l_model));

            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }
    } while (0);

    return l_rc;
}

//******************************************************************************
// platGetFunctional function
//******************************************************************************
ReturnCode platGetFunctional(const Target<TARGET_TYPE_ALL>& i_pFapiTarget,
                                 uint8_t & o_functional)
{
    errlHndl_t l_errl = NULL;
    ReturnCode l_rc;
    TARGETING::Target * l_pHbTarget = NULL;
    o_functional = 0;

    l_errl = getTargetingTarget(i_pFapiTarget, l_pHbTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetFunctional: Error from getTargetingTarget");
        l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        TARGETING::PredicateIsFunctional l_functional;
        if (l_functional(l_pHbTarget))
        {
            o_functional = 1;
        }
    }

    return l_rc;
}

//******************************************************************************
// fapi::platAttrSvc::platGetTargetPos function
//******************************************************************************
ReturnCode platGetTargetPos(const Target<TARGET_TYPE_ALL>& i_pFapiTarget,
                                uint32_t & o_pos)
{
    errlHndl_t l_errl = NULL;
    ReturnCode l_rc;
    TARGETING::Target * l_pTarget = NULL;

    // Get the Targeting Target
    l_errl = getTargetingTarget(i_pFapiTarget, l_pTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetTargetPos: Error from getTargetingTarget");
        l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        uint16_t l_pos = l_pTarget->getAttr<TARGETING::ATTR_FAPI_POS>();

        //@todo-RTC:161594-ATTR_POS is defined as per-drawer, so need to
        //  mod the value down appropriately

        o_pos = l_pos;
    }

    return l_rc;
}

//******************************************************************************
// fapi::platAttrSvc::platErrorOnSet function
//******************************************************************************
ReturnCode platErrorOnSet( TARGETING::Target * i_pTargTarget,
                           const fapi2::AttributeId i_fapiAttrId )
{
    // Just create an error to return back
    FAPI_ERR("platErrorOnSet: Set not valid for Attribute %X on Target %.8X",
             i_fapiAttrId, TARGETING::get_huid(i_pTargTarget) );
    /*@
     * @errortype
     * @moduleid     fapi2::MOD_FAPI2_PLAT_ERROR_ON_SET
     * @reasoncode   fapi2::RC_SET_ATTR_NOT_VALID
     * @userdata1    Target HUID
     * @userdata2    FAPI Attribute Id
     * @devdesc      platErrorOnSet> Set operation not valid
     * @custdesc     Firmware error
     */
    errlHndl_t l_errl = new ERRORLOG::ErrlEntry(
                                     ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                     fapi2::MOD_FAPI2_PLAT_ERROR_ON_SET,
                                     fapi2::RC_SET_ATTR_NOT_VALID,
                                     TARGETING::get_huid(i_pTargTarget),
                                     i_fapiAttrId,
                                     ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);
    l_errl->collectTrace(FAPI_TRACE_NAME);
    l_errl->collectTrace(FAPI_IMP_TRACE_NAME);

    // attach our log to the fapi RC and return it
    ReturnCode l_rc;
    l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    return l_rc;
}

//******************************************************************************
// fapi::platAttrSvc::platGetFusedCoreMode function
//******************************************************************************
ReturnCode platGetFusedCoreMode(uint8_t & o_isFused)
{
    o_isFused = TARGETING::is_fused_mode();
    return fapi2::ReturnCode();
}

//******************************************************************************
// fapi2::platAttrSvc::platGetPoundVBucketData function
//******************************************************************************
ReturnCode platGetPoundVBucketData(const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                             uint8_t * o_poundVData)
{
    fapi2::ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);
    if (l_errl)
    {
        FAPI_ERR("platGetPoundVBucketData: Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        fapi2::Target<TARGET_TYPE_EQ> l_fapiTarget( l_pTarget);
        rc = p9_pm_get_poundv_bucket_attr(l_fapiTarget,o_poundVData);
    }

    return rc;
}

//******************************************************************************
// fapi2::platAttrSvc::platGetPoundWBucketData function
//******************************************************************************
ReturnCode platGetPoundWBucketData(const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                             uint8_t * o_poundWData)
{
    fapi2::ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);
    if (l_errl)
    {
        FAPI_ERR("platGetPoundWBucketData: Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        fapi2::Target<TARGET_TYPE_EQ> l_fapiTarget( l_pTarget);
        rc = p9_pm_get_poundw_bucket_attr(l_fapiTarget,o_poundWData);
    }

    return rc;
}

ReturnCode platParseWOFTables(uint8_t* o_wofData);

//******************************************************************************
// fapi2::platAttrSvc::platGetWOFTableData function
//******************************************************************************
ReturnCode platGetWOFTableData(const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                               uint8_t * o_wofTableData)
{
    fapi2::ReturnCode rc;

    // Parse the tables and return a single wof table
    rc = platParseWOFTables(o_wofTableData);

    return rc;
}

//******************************************************************************
// ATTR_BAD_DQ_BITMAP getter/setter constant definitions
//******************************************************************************

// define structure for the format of DIMM_BAD_DQ_DATA
struct dimmBadDqDataFormat
{
    uint32_t iv_magicNumber;
    uint8_t  iv_version;
    uint8_t  iv_reserved1;
    uint8_t  iv_reserved2;
    uint8_t  iv_reserved3;
    uint8_t  iv_bitmaps[mss::MAX_RANK_PER_DIMM][mss::BAD_DQ_BYTE_COUNT];
    uint8_t  iv_rowRepairData[mss::MAX_RANK_PER_DIMM]
                             [mss::ROW_REPAIR_BYTE_COUNT];
    uint8_t  iv_unused[16];
};

// constant definitions
const uint8_t  SPARE_DRAM_DQ_BYTE_NUMBER_INDEX = 9;
const uint32_t DIMM_BAD_DQ_MAGIC_NUMBER = 0xbadd4471;
const uint8_t  DIMM_BAD_DQ_VERSION = 1;
const uint8_t  DIMM_BAD_DQ_NUM_BYTES = 80;
size_t DIMM_BAD_DQ_SIZE_BYTES = 0x50;

union wiringData
{
    uint8_t nimbus[mss::PORTS_PER_MCS][mss::MAX_DQ_BITS];
    uint8_t cumulus[MAX_PORTS_PER_CEN][DIMM_BAD_DQ_NUM_BYTES];
    uint8_t memport[mss::MAX_DQ_BITS];
};

//******************************************************************************
// fapi2::platAttrSvc::__getChipModel function
//******************************************************************************
TARGETING::ATTR_MODEL_type __getChipModel()
{
    // determine the chip's model
    TARGETING::Target * masterProc = nullptr;
    TARGETING::targetService().masterProcChipTargetHandle(masterProc);

    return masterProc->getAttr<TARGETING::ATTR_MODEL>();
}

//******************************************************************************
// fapi2::platAttrSvc::__getTranslationPortSlct function
//******************************************************************************
ReturnCode __getTranslationPortSlct( const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
                                     uint8_t &o_ps )
{
    // NOTE: this function returns the port select we need for the translation
    // attribute. This means, for Cumulus it returns the MBA port from the
    // centaur perspective (0-3), and for Nimbus it returns the port select from
    // an MCS perspective (0-1).

    o_ps = 0;
    TARGETING::ATTR_MODEL_type l_procType = __getChipModel();

    // If the proc is Cumulus, we need to get the MBA.
    if ( TARGETING::MODEL_CUMULUS == l_procType )
    {
        Target<TARGET_TYPE_MBA> l_fapiMba =
            i_fapiDimm.getParent<TARGET_TYPE_MBA>();

        // Get the MBA's position
        uint8_t mbaPos = 0;
        FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_CHIP_UNIT_POS, l_fapiMba, mbaPos) );
        mbaPos = mbaPos % MAX_MBA_PER_CEN; // 0-1

        // Get the port select from the MBA perspective
        uint8_t mbaPort = 0;
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_MBA_PORT, i_fapiDimm, mbaPort));
        mbaPort = mbaPort % MAX_PORTS_PER_MBA; // 0-1

        // Find the port select from the Centaur perspective
        o_ps = (mbaPos*MAX_PORTS_PER_MBA)+mbaPort; // 0-3
    }
    // If the proc is Nimbus, we need to get the MCA.
    else if ( TARGETING::MODEL_NIMBUS == l_procType )
    {
        Target<TARGET_TYPE_MCA> l_fapiMca =
            i_fapiDimm.getParent<TARGET_TYPE_MCA>();

        // Get the port select from the MCS perspective
        FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_CHIP_UNIT_POS, l_fapiMca, o_ps) );
        o_ps = o_ps % mss::PORTS_PER_MCS; // 0-1
    }
    else
    {
        // In the generic case, the translation attribute exists on the MEM_PORT
        // trgt so there's no need to know the port slct, so just set it to 0.
        o_ps = 0;
    }


fapi_try_exit:
    return fapi2::current_err;
}


//******************************************************************************
// fapi2::platAttrSvc::__badDqBitmapGetHelperAttrs function
//******************************************************************************
ReturnCode __badDqBitmapGetHelperAttrs(
    const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
    wiringData &o_wiringData, uint64_t &o_allMnfgFlags, uint8_t &o_ps )
{
    TARGETING::ATTR_MODEL_type procType = __getChipModel();

    FAPI_TRY( __getTranslationPortSlct(i_fapiDimm, o_ps) );

    // Get the DQ to DIMM Connector DQ Wiring attribute.
    // Note that for C-DIMMs, this will return a simple 1:1 mapping.
    // This code cannot tell the difference between C-DIMMs and IS-DIMMs.
    if ( TARGETING::MODEL_NIMBUS == procType )
    {
        // memset to avoid known syntax issue with previous compiler
        // versions and ensure zero initialized array.
        memset( o_wiringData.nimbus, 0, sizeof(o_wiringData.nimbus) );

        Target<TARGET_TYPE_MCA> l_fapiMca =
            i_fapiDimm.getParent<TARGET_TYPE_MCA>();

        // Get the MCS.
        Target<TARGET_TYPE_MCS> l_fapiMcs;
        l_fapiMcs = l_fapiMca.getParent<TARGET_TYPE_MCS>();

        FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_MSS_VPD_DQ_MAP, l_fapiMcs,
                                o_wiringData.nimbus) );
    }
    else if ( TARGETING::MODEL_CUMULUS == procType )
    {
        // memset to avoid known syntax issue with previous compiler
        // versions and ensure zero initialized array.
        memset( o_wiringData.cumulus, 0, sizeof(o_wiringData.cumulus) );

        // Check DIMM type
        uint8_t l_dimmType = 0;

        Target<TARGET_TYPE_MBA> l_fapiMba =
            i_fapiDimm.getParent<TARGET_TYPE_MBA>();

        FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_CEN_EFF_CUSTOM_DIMM, l_fapiMba,
                                l_dimmType) );

        // C-DIMMs return a direct 1:1 mapping
        if ( fapi2::ENUM_ATTR_CEN_EFF_CUSTOM_DIMM_YES == l_dimmType )
        {
            for ( uint8_t port = 0; port < MAX_PORTS_PER_CEN; port++ )
            {
                for ( uint8_t i = 0; i < DIMM_BAD_DQ_NUM_BYTES; i++ )
                {
                    o_wiringData.cumulus[port][i] = i;
                }
            }
        }
        // ISDIMMs require the mapping from ATTR_CEN_VPD_ISDIMMTOC4DQ
        else
        {
            Target<TARGET_TYPE_MEMBUF_CHIP> l_fapiMembuf =
                l_fapiMba.getParent<TARGET_TYPE_MEMBUF_CHIP>();

            FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_CEN_VPD_ISDIMMTOC4DQ,
                                    l_fapiMembuf, o_wiringData.cumulus) );
        }
    }
    else
    {
        // memset to avoid known syntax issue with previous compiler
        // versions and ensure zero initialized array.
        memset( o_wiringData.memport, 0, sizeof(o_wiringData.memport) );

        // Get the MEM_PORT target
        Target<TARGET_TYPE_MEM_PORT> l_fapiMemPort =
            i_fapiDimm.getParent<TARGET_TYPE_MEM_PORT>();

        FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_MEM_VPD_DQ_MAP, l_fapiMemPort,
                                o_wiringData.memport) );
    }


    // Manufacturing flags attribute
    o_allMnfgFlags = 0;

    // Get the manufacturing flags bitmap to be used in both get and set
    FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_MNFG_FLAGS,
                            fapi2::Target<fapi2::TARGET_TYPE_SYSTEM>(),
                            o_allMnfgFlags) );

fapi_try_exit:
    return fapi2::current_err;
}

//******************************************************************************
// fapi2::platAttrSvc::__dimmUpdateDqBitmapEccByte function
//******************************************************************************
ReturnCode __dimmUpdateDqBitmapEccByte(
    const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
    uint8_t (&o_data)[mss::MAX_RANK_PER_DIMM][mss::BAD_DQ_BYTE_COUNT] )
{
    ReturnCode l_rc;
    errlHndl_t l_errl = nullptr;

    const uint8_t ECC_DQ_BYTE_NUMBER_INDEX = 8;
    const uint8_t ENUM_ATTR_SPD_MODULE_MEMORY_BUS_WIDTH_WE8 = 0x08;
    size_t MEM_BUS_WIDTH_SIZE = 0x01;
    uint8_t *l_eccBits = static_cast<uint8_t*>(malloc(MEM_BUS_WIDTH_SIZE));

    do
    {
        TARGETING::TargetHandle_t l_dimm = nullptr;
        l_errl = getTargetingTarget( i_fapiDimm, l_dimm );
        if ( l_errl )
        {
            FAPI_ERR( "__dimmUpdateDqBitmapEccByte: Error from "
                      "getTargetingTarget" );
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        l_errl = deviceRead( l_dimm, l_eccBits, MEM_BUS_WIDTH_SIZE,
                             DEVICE_SPD_ADDRESS(SPD::MODULE_MEMORY_BUS_WIDTH) );
        if ( l_errl )
        {
            FAPI_ERR( "__dimmUpdateDqBitmapEccByte: Failed to get "
                      "SPD::MODULE_MEMORY_BUS_WIDTH." );
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        // The ATTR_SPD_MODULE_MEMORY_BUS_WIDTH contains ENUM values
        // for bus widths of 8, 16, 32, and 64 bits both with ECC
        // and without ECC.  WExx ENUMS denote the ECC extension
        // is present, and all have bit 3 set.  Therefore,
        // it is only required to check against the WE8 = 0x08 ENUM
        // value in order to determine if ECC lines are present.
        if ( !(ENUM_ATTR_SPD_MODULE_MEMORY_BUS_WIDTH_WE8 & *l_eccBits) )
        {
            // Iterate through each rank and set DQ bits in
            // caller's data.
            for ( uint8_t i = 0; i < mss::MAX_RANK_PER_DIMM; i++ )
            {
                // Set DQ bits in caller's data
                o_data[i][ECC_DQ_BYTE_NUMBER_INDEX] = 0xFF;
            }
        }
    }while(0);

    if ( l_eccBits != nullptr )
    {
        free( l_eccBits );
        l_eccBits = nullptr;
    }

    return l_rc;
}

//******************************************************************************
// fapi2::platAttrSvc::__dimmGetDqBitmapSpareByte function
//******************************************************************************
ReturnCode __dimmGetDqBitmapSpareByte(
    const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
    uint8_t (&o_spareByte)[mss::MAX_RANK_PER_DIMM])
{
    ReturnCode l_rc;
    TARGETING::ATTR_MODEL_type procType = __getChipModel();
    uint8_t l_ps = 0;

    // Spare DRAM Attribute: Returns spare DRAM availability for
    // all DIMMs associated with the target MCS.
    uint8_t l_dramSpare[mss::PORTS_PER_MCS][mss::MAX_DIMM_PER_PORT]
                       [mss::MAX_RANK_PER_DIMM] = {};

    uint32_t l_ds = 0;
    FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_FAPI_POS, i_fapiDimm, l_ds) );
    l_ds = l_ds % mss::MAX_DIMM_PER_PORT;

    if ( TARGETING::MODEL_NIMBUS == procType )
    {
        // We need the port select from the MCS perspective here so we
        // can just use __getTranslationPortSlct.
        __getTranslationPortSlct( i_fapiDimm, l_ps );

        Target<TARGET_TYPE_MCA> l_fapiMca =
            i_fapiDimm.getParent<TARGET_TYPE_MCA>();

        // Get the MCS.
        Target<TARGET_TYPE_MCS> l_fapiMcs;
        l_fapiMcs = l_fapiMca.getParent<TARGET_TYPE_MCS>();

        FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_EFF_DIMM_SPARE, l_fapiMcs,
                                l_dramSpare) );
    }
    else if ( TARGETING::MODEL_CUMULUS == procType )
    {
        // In this case we need the port select from the MBA perspective
        // not the centaur perspective that __getTranslationPortSlct gives
        // us, so we can't use that function.
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CEN_MBA_PORT, i_fapiDimm, l_ps));
        l_ps = l_ps % MAX_PORTS_PER_MBA;

        Target<TARGET_TYPE_MBA> l_fapiMba =
            i_fapiDimm.getParent<TARGET_TYPE_MBA>();

        FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_CEN_VPD_DIMM_SPARE, l_fapiMba,
                                l_dramSpare) );
    }
    else
    {
        // Get the MEM_PORT target
        Target<TARGET_TYPE_MEM_PORT> l_fapiMemPort =
            i_fapiDimm.getParent<TARGET_TYPE_MEM_PORT>();

        // The attribute exists on the MEM_PORT so we don't need to worry about
        // the port slct, just set the attribute in the space for port slct 0.
        FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_MEM_EFF_DIMM_SPARE, l_fapiMemPort,
                                l_dramSpare[0]) );
        l_ps = 0;
    }

    // Iterate through each rank of this DIMM
    for ( uint8_t i = 0; i < mss::MAX_RANK_PER_DIMM; i++ )
    {
        // Handle spare DRAM configuration cases
        switch ( l_dramSpare[l_ps][l_ds][i] )
        {
            case fapi2::ENUM_ATTR_EFF_DIMM_SPARE_NO_SPARE:
                // Set DQ bits reflecting unconnected
                // spare DRAM in caller's data
                o_spareByte[i] = 0xFF;
                break;

            case fapi2::ENUM_ATTR_EFF_DIMM_SPARE_LOW_NIBBLE:
                o_spareByte[i] = 0x0F;
                break;

            case fapi2::ENUM_ATTR_EFF_DIMM_SPARE_HIGH_NIBBLE:
                o_spareByte[i] = 0xF0;
                break;

                // As erroneous value will not be encountered.
            case fapi2::ENUM_ATTR_EFF_DIMM_SPARE_FULL_BYTE:
            default:
                o_spareByte[i] = 0x0;
                break;
        }
    }

fapi_try_exit:
    return fapi2::current_err;
}

//******************************************************************************
// fapi2::platAttrSvc::__dimmUpdateDqBitmapSpareByte function
//******************************************************************************
ReturnCode __dimmUpdateDqBitmapSpareByte(
    const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
    uint8_t (&o_data)[mss::MAX_RANK_PER_DIMM][mss::BAD_DQ_BYTE_COUNT] )
{
    ReturnCode l_rc;

    uint8_t spareByte[mss::MAX_RANK_PER_DIMM];
    memset( spareByte, 0, sizeof(spareByte) );

    FAPI_TRY( __dimmGetDqBitmapSpareByte(i_fapiDimm, spareByte) );

    for ( uint32_t i = 0; i < mss::MAX_RANK_PER_DIMM; i++ )
    {
        o_data[i][SPARE_DRAM_DQ_BYTE_NUMBER_INDEX] |= spareByte[i];
    }

fapi_try_exit:
    return fapi2::current_err;
}

//******************************************************************************
// fapi2::platAttrSvc::__compareEccAndSpare function
//******************************************************************************
ReturnCode __compareEccAndSpare(const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
    bool & o_mfgModeBadBitsPresent,
    uint8_t i_bitmap[mss::MAX_RANK_PER_DIMM][mss::BAD_DQ_BYTE_COUNT],
    uint8_t (&o_eccSpareBitmap)[mss::MAX_RANK_PER_DIMM][mss::BAD_DQ_BYTE_COUNT])
{
    // This function will compare o_eccSpareBitmap, which represents a bad dq
    // bitmap with the appropriate spare/ECC bits set (if any) and all other DQ
    // lines functional, to the caller's data. If discrepancies are found, we
    // know this is the result of a manufacturing mode process and these bits
    // should not be recorded.

    ReturnCode l_rc;
    errlHndl_t l_errl = nullptr;

    do
    {
        // Set a clean bitmap with only the appropriate spare/ECC bits set
        memset( o_eccSpareBitmap, 0, sizeof(o_eccSpareBitmap) );
        FAPI_TRY( __dimmUpdateDqBitmapEccByte(i_fapiDimm, o_eccSpareBitmap) );
        FAPI_TRY( __dimmUpdateDqBitmapSpareByte(i_fapiDimm, o_eccSpareBitmap) );

        // Compare o_eccSpareBitmap to i_bitmap.
        for ( uint8_t i = 0; i < mss::MAX_RANK_PER_DIMM; i++ )
        {
            for (uint8_t j = 0; j < mss::BAD_DQ_BYTE_COUNT; j++)
            {
                if ( i_bitmap[i][j] != o_eccSpareBitmap[i][j] )
                {
                    o_mfgModeBadBitsPresent = true;
                    break;
                }
            }
            if ( o_mfgModeBadBitsPresent ) break;
        }

        // Create and log error if discrepancies were found.
        if ( o_mfgModeBadBitsPresent )
        {
            FAPI_ERR( "__compareEccAndSpare: Read/write requested while in "
                      "DISABLE_DRAM_REPAIRS mode found extra bad bits set for "
                      "DIMM" );

            TARGETING::TargetHandle_t l_dimm = nullptr;
            l_errl = getTargetingTarget( i_fapiDimm, l_dimm );
            if ( l_errl )
            {
                FAPI_ERR("__compareEccAndSpare: Error from getTargetingTarget");
                l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
                break;
            }

            /*@
             * @errortype
             * @moduleid     MOD_FAPI2_BAD_DQ_BITMAP
             * @reasoncode   RC_BAD_DQ_MFG_MODE_BITS
             * @userdata1    DIMM Target HUID
             * @userdata2    <unused>
             * @devdesc      Extra bad bits set for DIMM
             * @custdesc     Read/write requested while in
             *               DISABLE_DRAM_REPAIRS mode found
             *               extra bad bits set for DIMM
             */
            l_errl = new ERRORLOG::ErrlEntry(
                    ERRORLOG::ERRL_SEV_PREDICTIVE,
                    MOD_FAPI2_BAD_DQ_BITMAP,
                    RC_BAD_DQ_MFG_MODE_BITS,
                    TARGETING::get_huid(l_dimm) );

            l_errl->addFFDC( HWPF_COMP_ID, &o_eccSpareBitmap[0],
                             sizeof(o_eccSpareBitmap[0]), 1,
                             CLEAN_BAD_DQ_BITMAP_RANK0 );

            l_errl->addFFDC( HWPF_COMP_ID, &o_eccSpareBitmap[1],
                             sizeof(o_eccSpareBitmap[1]), 1,
                             CLEAN_BAD_DQ_BITMAP_RANK1 );

            l_errl->addFFDC( HWPF_COMP_ID, &o_eccSpareBitmap[2],
                             sizeof(o_eccSpareBitmap[2]), 1,
                             CLEAN_BAD_DQ_BITMAP_RANK2 );

            l_errl->addFFDC( HWPF_COMP_ID, &o_eccSpareBitmap[3],
                             sizeof(o_eccSpareBitmap[3]), 1,
                             CLEAN_BAD_DQ_BITMAP_RANK3 );

            l_errl->addFFDC( HWPF_COMP_ID, &i_bitmap[0],
                             sizeof(i_bitmap[0]), 1,
                             CURRENT_BAD_DQ_BITMAP_RANK0 );

            l_errl->addFFDC( HWPF_COMP_ID, &i_bitmap[1],
                             sizeof(i_bitmap[1]), 1,
                             CURRENT_BAD_DQ_BITMAP_RANK1 );

            l_errl->addFFDC( HWPF_COMP_ID, &i_bitmap[2],
                             sizeof(i_bitmap[2]), 1,
                             CURRENT_BAD_DQ_BITMAP_RANK2 );

            l_errl->addFFDC( HWPF_COMP_ID, &i_bitmap[3],
                             sizeof(i_bitmap[3]), 1,
                             CURRENT_BAD_DQ_BITMAP_RANK3 );

            l_errl->addHwCallout(l_dimm, HWAS::SRCI_PRIORITY_HIGH,
                                 HWAS::DELAYED_DECONFIG, HWAS::GARD_Predictive);

            errlCommit( l_errl, HWPF_COMP_ID );
        }
    }while(0);

    if ( l_rc )
    {
        return l_rc;
    }

fapi_try_exit:
    return fapi2::current_err;
}

//******************************************************************************
// fapi2::platAttrSvc::__mcLogicalToDimmDqHelper function
//******************************************************************************
ReturnCode __mcLogicalToDimmDqHelper(
    const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
    wiringData  i_wiringData, uint8_t i_ps, uint8_t i_mcPin,
    uint8_t &o_dimm_dq )
{
    uint64_t l_c4 = 0;

    TARGETING::ATTR_MODEL_type procType = __getChipModel();

    if ( TARGETING::MODEL_NIMBUS == procType )
    {
        Target<TARGET_TYPE_MCA> l_fapiMca =
            i_fapiDimm.getParent<TARGET_TYPE_MCA>();

        // For Nimbus, translate from MC Logical to C4 format
        FAPI_TRY( mss::rosetta_map::mc_to_c4<mss::rosetta_type::DQ>(
                  l_fapiMca, i_mcPin, l_c4 ) );

        // use wiring data to translate c4 pin to dimm dq format
        // Note: the wiring data maps from dimm dq format to c4 format
        for ( uint8_t bit = 0; bit < mss::MAX_DQ_BITS; bit++ )
        {
            // Check to see which bit in the wiring data corresponds to our
            // DIMM DQ format pin.
            if ( i_wiringData.nimbus[i_ps][bit] == l_c4 )
            {
                o_dimm_dq = bit;
                break;
            }
        }
    }
    else if ( TARGETING::MODEL_CUMULUS == procType )
    {
        // For Cumulus, MC to C4 is 1-to-1
        l_c4 = i_mcPin;

        // use wiring data to translate c4 pin to dimm dq format
        // Note: the wiring data maps from dimm dq format to c4 format
        for ( uint8_t bit = 0; bit < DIMM_BAD_DQ_NUM_BYTES; bit++ )
        {
            // Check to see which bit in the wiring data corresponds to our
            // DIMM DQ format pin.
            if ( i_wiringData.cumulus[i_ps][bit] == l_c4 )
            {
                o_dimm_dq = bit;
                break;
            }
        }
    }
    else
    {
        // use wiring data to translate mc pin to dimm dq format
        // Note: the wiring data maps from dimm dq format to mc format
        for ( uint8_t bit = 0; bit < mss::MAX_DQ_BITS; bit++ )
        {
            // Check to see which bit in the wiring data corresponds to our
            // DIMM DQ format pin.
            if ( i_wiringData.memport[bit] == i_mcPin )
            {
                o_dimm_dq = bit;
                break;
            }
        }
    }

fapi_try_exit:
    return fapi2::current_err;
}

//******************************************************************************
// fapi2::platAttrSvc::__dimmDqToMcLogicalHelper function
//******************************************************************************
ReturnCode __dimmDqToMcLogicalHelper(
    const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
    wiringData  i_wiringData, uint8_t i_ps, uint8_t i_dimm_dq,
    uint8_t &o_mcPin )
{
    uint64_t l_c4 = 0;

    TARGETING::ATTR_MODEL_type procType = __getChipModel();

    if ( TARGETING::MODEL_NIMBUS == procType )
    {

        // Translate from DIMM DQ format to C4 using wiring data
        // Note: the wiring data maps from dimm dq format to c4 format
        l_c4 = i_wiringData.nimbus[i_ps][i_dimm_dq];

        Target<TARGET_TYPE_MCA> l_fapiMca =
            i_fapiDimm.getParent<TARGET_TYPE_MCA>();

        // For Nimbus, translate from C4 to MC Logical format
        uint64_t l_tmp = 0;
        FAPI_TRY( mss::rosetta_map::c4_to_mc<mss::rosetta_type::DQ>(l_fapiMca,
                  l_c4, l_tmp) );
        o_mcPin = static_cast<uint8_t>(l_tmp);
    }
    else if ( TARGETING::MODEL_CUMULUS == procType )
    {

        // Translate from DIMM DQ format to C4 using wiring data
        // Note: the wiring data maps from dimm dq format to c4 format
        l_c4 = i_wiringData.cumulus[i_ps][i_dimm_dq];

        // For Cumulus, C4 to MC Logical is 1-to-1
        o_mcPin = l_c4;
    }
    else
    {
        // Translate from DIMM DQ format to MC using wiring data
        // Note: the wiring data maps from dimm dq format to mc logical format
        o_mcPin = i_wiringData.memport[i_dimm_dq];
    }

fapi_try_exit:
    return fapi2::current_err;

}

//******************************************************************************
// fapi2::platAttrSvc::__badDqBitTranslation function
//******************************************************************************
ReturnCode __badDqBitTranslation( const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
    uint8_t i_initial_bm[mss::MAX_RANK_PER_DIMM][mss::BAD_DQ_BYTE_COUNT],
    uint8_t (&o_translated_bm)[mss::MAX_RANK_PER_DIMM][mss::BAD_DQ_BYTE_COUNT],
    wiringData i_wiringData, uint8_t i_spareByte[mss::MAX_RANK_PER_DIMM],
    uint8_t i_ps, bool i_mcLogicalToDimmDq )
{
    memset(o_translated_bm, 0, sizeof(o_translated_bm));

    // We need to translate the bad dq bits from MC logical format to
    // Connector/DIMM DQ format or back. This may require two translations
    // depending on the chip.

    // MC Logical/PHY<-->Module/C4 Package<-->Connector/DIMM DQ format

    // Note: MC Logical (0-71) maps linearly to PHY DP0(lane 0-15),
    // DP1(lane 0-15)...DP4(lane 0-15)

    // loop through iv_bitmaps ranks
    for ( uint8_t rank = 0; rank < mss::MAX_RANK_PER_DIMM; rank++ )
    {
        // loop through iv_bitmaps bytes
        for ( uint8_t byte = 0; byte < mss::BAD_DQ_BYTE_COUNT; byte++ )
        {
            // if bit found on
            if ( 0 != i_initial_bm[rank][byte] )
            {
                // find the set bit
                for ( uint8_t bit = 0; bit < mss::BITS_PER_BYTE; bit++ )
                {
                    if ( i_initial_bm[rank][byte] & (0x80 >> bit) )
                    {
                        // Check the spares
                        if ( byte == SPARE_DRAM_DQ_BYTE_NUMBER_INDEX &&
                             i_spareByte[rank] & (0x80 >> bit) )
                        {
                            // The spareByte can be one of: 0x00 0x0F 0xF0
                            // 0xFF If a bit is set, then that spare is
                            // unconnected so continue to the next bit,
                            // do not translate
                            continue;
                        }

                        // get the pin/bit position
                        uint8_t l_pin = (byte*8) + bit; // pin 0-79
                        uint8_t l_translatedPin = 0;

                        if ( i_mcLogicalToDimmDq )
                        {
                            // translate the MC logical pin to DIMM DQ format
                            FAPI_TRY( __mcLogicalToDimmDqHelper(i_fapiDimm,
                                      i_wiringData, i_ps, l_pin,
                                      l_translatedPin) );
                            FAPI_INF( "__badDqBitTranslation: Bad bit set, "
                                      "rank:%d before translation:%d, after "
                                      "translation:%d", rank, l_pin,
                                      l_translatedPin );
                        }
                        else
                        {
                            // translate the DIMM DQ pin to MC logical format
                            FAPI_TRY( __dimmDqToMcLogicalHelper(i_fapiDimm,
                                      i_wiringData, i_ps, l_pin,
                                      l_translatedPin) );
                        }

                        // set bit in new o_translated_bm
                        uint8_t l_setByte = l_translatedPin/8;
                        uint8_t l_setBit  = 0x80 >> (l_translatedPin%8);
                        o_translated_bm[rank][l_setByte] |= l_setBit;

                    }
                }
            }
        }
    }

fapi_try_exit:
    return fapi2::current_err;

}

//******************************************************************************
// fapi2::platAttrSvc::__badDqBitmapCheckForReconfigLoop function
//******************************************************************************
ReturnCode __badDqBitmapCheckForReconfigLoop(
    const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
    uint8_t i_bitmap[mss::MAX_RANK_PER_DIMM][mss::BAD_DQ_BYTE_COUNT] )
{
    // If, when setting the bad dq bitmap, we find new bits are set, we will
    // want to trigger a reconfig loop.
    bool l_badDqSet = false;

    // Read current BadDqBitmap into l_prev_data
    uint8_t l_prev_data[mss::MAX_RANK_PER_DIMM][mss::BAD_DQ_BYTE_COUNT];
    FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_BAD_DQ_BITMAP, i_fapiDimm,
              l_prev_data) );

    // Check if Bad DQ bit set
    // Loop through all ranks
    for ( uint8_t i = 0; i < mss::MAX_RANK_PER_DIMM; i++ )
    {
        // Loop through all DQs
        for ( uint8_t j = 0; j < mss::BAD_DQ_BYTE_COUNT; j++ )
        {
            // Loop through all bits
            for ( uint8_t k = 0; k < mss::BITS_PER_BYTE; k++ )
            {
                uint8_t prevBit = (l_prev_data[i][j] >> k) & 0x01;
                uint8_t newBit  = (i_bitmap[i][j] >> k) & 0x01;
                // Check for differences, and the bit was set, not cleared
                if ( (prevBit != newBit) && (newBit != 0) )
                {
                    l_badDqSet = true;
                    break;
                }
            }
            if ( l_badDqSet ) break;
        }
        if ( l_badDqSet ) break;
    }

    // Set ATTR_RECONFIGURE_LOOP to indicate a bad DqBitMap was set
    if ( l_badDqSet )
    {
        FAPI_INF( "__badDqBitmapCheckForReconfigLoop: Reconfigure needed, "
                  "Bad DQ set" );

        fapi2::ATTR_RECONFIGURE_LOOP_Type l_reconfigAttr = 0;
        FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_RECONFIGURE_LOOP,
                  fapi2::Target<fapi2::TARGET_TYPE_SYSTEM>(), l_reconfigAttr) );

        // 'OR' values in case of multiple reasons for reconfigure
        l_reconfigAttr |= fapi2::ENUM_ATTR_RECONFIGURE_LOOP_BAD_DQ_BIT_SET;

        FAPI_TRY( FAPI_ATTR_SET(fapi2::ATTR_RECONFIGURE_LOOP,
                  fapi2::Target<fapi2::TARGET_TYPE_SYSTEM>(), l_reconfigAttr) );
    }

fapi_try_exit:
    return fapi2::current_err;
}

//******************************************************************************
// fapi2::platAttrSvc::fapiAttrGetBadDqBitmap function
//******************************************************************************
ReturnCode fapiAttrGetBadDqBitmap(
    const Target<TARGET_TYPE_ALL>& i_fapiTarget,
    ATTR_BAD_DQ_BITMAP_Type (&o_data) )
{
    FAPI_INF(">>fapiAttrGetBadDqBitmap: Getting bitmap");

    fapi2::ReturnCode l_rc;
    errlHndl_t l_errl = nullptr;
    uint8_t * l_badDqData =
        static_cast<uint8_t*>( malloc(DIMM_BAD_DQ_SIZE_BYTES) );

    do
    {
        // Get the TARGETING dimm target
        TARGETING::TargetHandle_t l_dimmTarget = nullptr;
        l_errl = getTargetingTarget( i_fapiTarget, l_dimmTarget );
        if ( l_errl )
        {
            FAPI_ERR( "fapiAttrGetBadDqBitmap: Error from getTargetingTarget" );
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        // Get the FAPI dimm target
        Target<TARGET_TYPE_DIMM> l_fapiDimm( l_dimmTarget );

        wiringData l_wiringData;
        uint64_t l_allMnfgFlags;
        uint8_t l_ps = 0;

        FAPI_TRY( __badDqBitmapGetHelperAttrs(l_fapiDimm, l_wiringData,
                                              l_allMnfgFlags, l_ps) );

        l_errl = deviceRead( l_dimmTarget, l_badDqData, DIMM_BAD_DQ_SIZE_BYTES,
                             DEVICE_SPD_ADDRESS(SPD::DIMM_BAD_DQ_DATA) );
        if ( l_errl )
        {
            FAPI_ERR( "fapiAttrGetBadDqBitmap: Failed to read DIMM Bad DQ "
                      "data." );
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        dimmBadDqDataFormat l_spdData;
        memcpy( &l_spdData, l_badDqData, sizeof(dimmBadDqDataFormat) );

        // Zero caller's data
        memset(o_data, 0, sizeof(o_data));

        // Check the magic number and version number. Note that the
        // magic number is stored in SPD in big endian format and
        // platforms of any endianness can access it
        if ( (be32toh(l_spdData.iv_magicNumber) != DIMM_BAD_DQ_MAGIC_NUMBER) ||
             (l_spdData.iv_version != DIMM_BAD_DQ_VERSION) )
        {
            FAPI_INF( "fapiAttrGetBadDqBitmap: SPD DQ not initialized." );

            // We still set the ECC and spare bytes in the output data to
            // avoid issues in the setter when SPD DQ is not initialized.
            // Set bits for any unconnected DQs.
            // First, check ECC.
            FAPI_TRY( __dimmUpdateDqBitmapEccByte(l_fapiDimm, o_data) );

            // Check spare DRAM.
            FAPI_TRY( __dimmUpdateDqBitmapSpareByte(l_fapiDimm, o_data) );
        }
        else
        {
            // Get the spare byte
            uint8_t l_spareByte[mss::MAX_RANK_PER_DIMM];
            memset( l_spareByte, 0, sizeof(l_spareByte) );

            FAPI_TRY( __dimmGetDqBitmapSpareByte(l_fapiDimm, l_spareByte) );

            // Translate bitmap from DIMM DQ to MC Logical format
            FAPI_TRY( __badDqBitTranslation(l_fapiDimm, l_spdData.iv_bitmaps,
                                            o_data, l_wiringData, l_spareByte,
                                            l_ps, false) );

            // Set bits for any unconnected DQs.
            // First, check ECC.
            FAPI_TRY( __dimmUpdateDqBitmapEccByte(l_fapiDimm, o_data) );

            // Check spare DRAM.
            FAPI_TRY( __dimmUpdateDqBitmapSpareByte(l_fapiDimm, o_data) );

            if ( l_allMnfgFlags &
                    fapi2::ENUM_ATTR_MNFG_FLAGS_MNFG_DISABLE_DRAM_REPAIRS )
            {
                // Flag to set if the discrepancies are found.
                bool l_mfgModeBadBitsPresent = false;

                uint8_t l_eccSpareBitmap[mss::MAX_RANK_PER_DIMM]
                                        [mss::BAD_DQ_BYTE_COUNT];

                FAPI_TRY( __compareEccAndSpare(l_fapiDimm,
                          l_mfgModeBadBitsPresent, o_data, l_eccSpareBitmap) );

                if ( l_mfgModeBadBitsPresent )
                {
                    // correct the output bit map
                    for (uint8_t i = 0; i < mss::MAX_RANK_PER_DIMM; i++)
                    {
                        for ( uint8_t j=0; j < (mss::BAD_DQ_BYTE_COUNT);
                                j++ )
                        {
                            o_data[i][j] = l_eccSpareBitmap[i][j];
                        }
                    }
                }
            }

        }

    }while(0);

fapi_try_exit:

    FAPI_INF("<<fapiAttrGetBadDqBitmap: Finished getting bitmap");

    if ( l_badDqData != nullptr )
    {
        free( l_badDqData );
        l_badDqData = nullptr;
    }

    if ( l_rc )
    {
        return l_rc;
    }

    return fapi2::current_err;

}

//******************************************************************************
// fapi2::platAttrSvc::fapiAttrSetBadDqBitmap function
//******************************************************************************
ReturnCode fapiAttrSetBadDqBitmap(
    const Target<TARGET_TYPE_ALL>& i_fapiTarget,
    ATTR_BAD_DQ_BITMAP_Type (&i_data) )
{
    FAPI_INF(">>fapiAttrSetBadDqBitmap: Setting bitmap");

    fapi2::ReturnCode l_rc;
    errlHndl_t l_errl = nullptr;
    uint8_t * l_badDqData =
        static_cast<uint8_t*>( malloc(DIMM_BAD_DQ_SIZE_BYTES) );
    do
    {
        // Get the TARGETING dimm target
        TARGETING::TargetHandle_t l_dimmTarget = nullptr;
        l_errl = getTargetingTarget( i_fapiTarget, l_dimmTarget );
        if ( l_errl )
        {
            FAPI_ERR( "fapiAttrSetBadDqBitmap: Error from getTargetingTarget" );
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        // Get the FAPI dimm target
        Target<TARGET_TYPE_DIMM> l_fapiDimm( l_dimmTarget );

        wiringData l_wiringData;
        uint64_t l_allMnfgFlags;
        uint8_t l_ps = 0;

        // Get the helper attributes
        FAPI_TRY( __badDqBitmapGetHelperAttrs(l_fapiDimm, l_wiringData,
                                              l_allMnfgFlags, l_ps) );

        // Make sure to update the ecc and spare bytes in the inputted bitmap
        // just to make sure we don't see any differences there.
        uint8_t l_tmpBitmap[mss::MAX_RANK_PER_DIMM][mss::BAD_DQ_BYTE_COUNT];
        memcpy( &l_tmpBitmap, &i_data, sizeof(i_data) );

        FAPI_TRY( __dimmUpdateDqBitmapEccByte(l_fapiDimm, l_tmpBitmap) );
        FAPI_TRY( __dimmUpdateDqBitmapSpareByte(l_fapiDimm, l_tmpBitmap) );

        // Check if we need to trigger a reconfig loop.
        FAPI_TRY( __badDqBitmapCheckForReconfigLoop(l_fapiDimm, l_tmpBitmap) );

        // If system is in DISABLE_DRAM_REPAIRS mode
        if ( l_allMnfgFlags &
             fapi2::ENUM_ATTR_MNFG_FLAGS_MNFG_DISABLE_DRAM_REPAIRS )
        {

            uint8_t l_eccSpareBitmap[mss::MAX_RANK_PER_DIMM]
                                    [mss::BAD_DQ_BYTE_COUNT];

            bool l_mfgModeBadBitsPresent = false;
            FAPI_TRY( __compareEccAndSpare(l_fapiDimm, l_mfgModeBadBitsPresent,
                                           l_tmpBitmap, l_eccSpareBitmap) );

            // Don't write bad dq bitmap if discrepancies are found
            // Break out of do while loop
            if ( l_mfgModeBadBitsPresent ) break;
        }

        // Set up the data to write to SPD
        dimmBadDqDataFormat l_spdData;
        l_spdData.iv_magicNumber = htobe32( DIMM_BAD_DQ_MAGIC_NUMBER );
        l_spdData.iv_version = DIMM_BAD_DQ_VERSION;
        l_spdData.iv_reserved1 = 0;
        l_spdData.iv_reserved2 = 0;
        l_spdData.iv_reserved3 = 0;
        memset( l_spdData.iv_bitmaps, 0, sizeof(l_spdData.iv_bitmaps) );

        // We need to make sure the rest of the data in VPD beyond the bad dq
        // bitmap is unchanged.
        l_errl = deviceRead( l_dimmTarget, l_badDqData,
                             DIMM_BAD_DQ_SIZE_BYTES,
                             DEVICE_SPD_ADDRESS(SPD::DIMM_BAD_DQ_DATA) );
        if ( l_errl )
        {
            FAPI_ERR( "fapiAttrSetBadDqBitmap: Failed to read DIMM Bad DQ "
                      "data." );
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        dimmBadDqDataFormat l_prevSpdData;
        memcpy( &l_prevSpdData, l_badDqData, sizeof(dimmBadDqDataFormat) );
        memcpy( &l_spdData.iv_rowRepairData, l_prevSpdData.iv_rowRepairData,
                sizeof(l_spdData.iv_rowRepairData) );
        memcpy( &l_spdData.iv_unused, l_prevSpdData.iv_unused,
                sizeof(l_spdData.iv_unused) );

        // Get the spare byte
        uint8_t l_spareByte[mss::MAX_RANK_PER_DIMM];
        memset( l_spareByte, 0, sizeof(l_spareByte) );

        FAPI_TRY( __dimmGetDqBitmapSpareByte(l_fapiDimm, l_spareByte) );

        // Translate bitmap from MC Logical to DIMM DQ format
        FAPI_TRY( __badDqBitTranslation(l_fapiDimm, i_data,
                                        l_spdData.iv_bitmaps, l_wiringData,
                                        l_spareByte, l_ps, true) );

        l_errl = deviceWrite( l_dimmTarget, &l_spdData, DIMM_BAD_DQ_SIZE_BYTES,
                              DEVICE_SPD_ADDRESS(SPD::DIMM_BAD_DQ_DATA) );
        if ( l_errl )
        {
            FAPI_ERR( "fapiAttrSetBadDqBitmap: Failed to write DIMM "
                      "Bad DQ data." );
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

    }while(0);

fapi_try_exit:

    FAPI_INF("<<fapiAttrSetBadDqBitmap: Finished setting bitmap");

    if ( l_badDqData != nullptr )
    {
        free( l_badDqData );
        l_badDqData = nullptr;
    }

    if ( l_rc )
    {
        return l_rc;
    }

    return fapi2::current_err;
}

//******************************************************************************
// fapi2::platAttrSvc::__isX4Dram function
//******************************************************************************
ReturnCode __isX4Dram( const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
                       bool & o_isX4Dram )
{
    o_isX4Dram = false;

    TARGETING::ATTR_MODEL_type procType = __getChipModel();

    // Get if drams are x4 or x8
    if ( TARGETING::MODEL_NIMBUS == procType )
    {
        // Nimbus only supports x4 DRAMs
        o_isX4Dram = true;
    }
    else if ( TARGETING::MODEL_CUMULUS == procType )
    {
        // Get the MBA
        Target<TARGET_TYPE_MBA> l_fapiMba =
            i_fapiDimm.getParent<TARGET_TYPE_MBA>();

        uint8_t l_dramWidth;
        FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_CEN_EFF_DRAM_WIDTH, l_fapiMba,
                                l_dramWidth) );
        o_isX4Dram = ( fapi2::ENUM_ATTR_CEN_EFF_DRAM_WIDTH_X4 == l_dramWidth );
    }
    else
    {
        // Get the MEM_PORT target
        Target<TARGET_TYPE_MEM_PORT> l_fapiMemPort =
            i_fapiDimm.getParent<TARGET_TYPE_MEM_PORT>();

        // Get the dram width attr and the dimm slct
        uint8_t l_dramWidth[2];
        FAPI_TRY( FAPI_ATTR_GET(fapi2::ATTR_MEM_EFF_DRAM_WIDTH, l_fapiMemPort,
                                l_dramWidth) );

        TARGETING::TargetHandle_t l_dimmTrgt;
        errlHndl_t l_errl = getTargetingTarget( i_fapiDimm, l_dimmTrgt );
        if ( l_errl )
        {
            FAPI_ERR("__isX4Dram: Error getting dimm from getTargetingTarget");
            fapi2::ReturnCode l_rc;
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            return l_rc;
        }
        uint8_t l_dimmSlct =
            l_dimmTrgt->getAttr<TARGETING::ATTR_POS_ON_MEM_PORT>();

        o_isX4Dram = ( fapi2::ENUM_ATTR_MEM_EFF_DRAM_WIDTH_X4 ==
                       l_dramWidth[l_dimmSlct] );
    }

fapi_try_exit:
    return fapi2::current_err;
}
//******************************************************************************
// fapi2::platAttrSvc::__dramToDq function
//******************************************************************************
ReturnCode __dramToDq( const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
    uint8_t i_dram, uint8_t & o_dq )
{
    o_dq = 0;

    // Convert dram pos to symbol
    // Get if drams are x4 or x8
    bool l_isX4 = false;
    FAPI_TRY( __isX4Dram(i_fapiDimm, l_isX4) );

    o_dq = i_dram * ( l_isX4 ? 4 : 8 );

fapi_try_exit:
    return fapi2::current_err;
}

//******************************************************************************
// fapi2::platAttrSvc::__dqToDram function
//******************************************************************************
ReturnCode __dqToDram( const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
    uint8_t i_dq, uint8_t & o_dram )
{
    o_dram = 0;

    // Convert symbol to dram pos
    // Get if drams are x4 or x8
    bool l_isX4 = false;
    FAPI_TRY( __isX4Dram(i_fapiDimm, l_isX4) );

    o_dram = i_dq / ( l_isX4 ? 4 : 8 );

fapi_try_exit:
    return fapi2::current_err;
}

//******************************************************************************
// fapi2::platAttrSvc::__rowRepairTranslateDramPos function
//******************************************************************************
ReturnCode __rowRepairTranslateDramPos(
    const Target<TARGET_TYPE_DIMM>& i_fapiDimm,
    bool i_mcLogicalToDimmDq,
    ATTR_ROW_REPAIR_DATA_Type & io_translatedData )
{
    wiringData l_wiringData;
    uint64_t l_allMnfgFlags;
    uint8_t l_ps = 0;

    // Get the wiring data and port select for translation.
    FAPI_TRY( __badDqBitmapGetHelperAttrs(i_fapiDimm, l_wiringData,
                                          l_allMnfgFlags, l_ps) );

    // Loop through each rank.
    for ( uint8_t rank = 0; rank < mss::MAX_RANK_PER_DIMM; rank++ )
    {
        // The first 5 bits of the stored row repair are the dram position
        // that needs to be translated. The next three are the slave rank.
        uint8_t l_dramPosAndSrank = io_translatedData[rank][0];
        uint8_t l_dramPos = (l_dramPosAndSrank >> 3) & 0x1f;
        uint8_t l_srank = l_dramPosAndSrank & 0x07;

        // The last bit of the row repair stores the validity bit
        bool l_valid = io_translatedData[rank][mss::ROW_REPAIR_BYTE_COUNT-1]
            & 0x01;

        // If the row repair isn't valid, no need to translate anything
        if ( !l_valid ) continue;

        uint8_t l_dq = 0;
        FAPI_TRY( __dramToDq(i_fapiDimm, l_dramPos, l_dq) );

        uint8_t l_translatedDq = 0;

        if ( i_mcLogicalToDimmDq )
        {
            FAPI_TRY( __mcLogicalToDimmDqHelper(i_fapiDimm, l_wiringData,
                                                l_ps, l_dq, l_translatedDq) );
        }
        else
        {
            FAPI_TRY( __dimmDqToMcLogicalHelper(i_fapiDimm, l_wiringData,
                                                l_ps, l_dq, l_translatedDq) );
        }

        uint8_t l_translatedDram = 0;
        FAPI_TRY( __dqToDram(i_fapiDimm, l_translatedDq, l_translatedDram) );

        if ( i_mcLogicalToDimmDq )
        {
            FAPI_INF( "__rowRepairTranslateDramPos: Row repair set, rank:%d "
                      "dram pos before translation:%d, after translation:%d",
                      rank, l_dramPos, l_translatedDram );
        }

        uint8_t l_updatedData = (l_translatedDram << 3) | l_srank;

        io_translatedData[rank][0] = l_updatedData;
    }

fapi_try_exit:
    return fapi2::current_err;

}

//******************************************************************************
// fapi2::platAttrSvc::getRowRepairData function
//******************************************************************************
ReturnCode getRowRepairData( const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                             ATTR_ROW_REPAIR_DATA_Type (&o_data) )
{
    FAPI_INF(">>getRowRepairData: Getting row repair data");

    fapi2::ReturnCode l_rc;
    errlHndl_t l_errl = nullptr;
    uint8_t * l_data =
        static_cast<uint8_t*>( malloc(DIMM_BAD_DQ_SIZE_BYTES) );
    do
    {
        // Get the TARGETING dimm target
        TARGETING::TargetHandle_t l_dimmTarget = nullptr;
        l_errl = getTargetingTarget( i_fapiTarget, l_dimmTarget );
        if ( l_errl )
        {
            FAPI_ERR( "getRowRepairData: Error from getTargetingTarget" );
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        // Get the FAPI dimm target
        Target<TARGET_TYPE_DIMM> l_fapiDimm( l_dimmTarget );

        // Zero callers data.
        memset(o_data, 0, sizeof(o_data));

        // Read the data
        l_errl = deviceRead( l_dimmTarget, l_data, DIMM_BAD_DQ_SIZE_BYTES,
                             DEVICE_SPD_ADDRESS(SPD::DIMM_BAD_DQ_DATA) );
        if ( l_errl )
        {
            FAPI_ERR( "getRowRepairData: Failed to call deviceRead to get "
                      "l_data." );
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        dimmBadDqDataFormat l_spdData;
        memcpy( &l_spdData, l_data, sizeof(dimmBadDqDataFormat) );

        // Check the header for correct data.
        if ( (be32toh(l_spdData.iv_magicNumber) != DIMM_BAD_DQ_MAGIC_NUMBER) ||
             (l_spdData.iv_version != DIMM_BAD_DQ_VERSION) )
        {
            FAPI_INF( "getRowRepairData: DIMM VPD not initialized." );
        }
        else
        {
            // Get the row repair data.
            memcpy( &o_data, &l_spdData.iv_rowRepairData,
                    sizeof(ATTR_ROW_REPAIR_DATA_Type) );

            // Translate the DRAM position in the row repair data
            FAPI_TRY( __rowRepairTranslateDramPos(l_fapiDimm, false, o_data ) );
        }

    }while(0);

fapi_try_exit:

    FAPI_INF("<<getRowRepairData: Finished getting row repair data");

    if ( l_data != nullptr )
    {
        free( l_data );
        l_data = nullptr;
    }

    if ( l_rc )
    {
        return l_rc;
    }

    return fapi2::current_err;
}

//******************************************************************************
// fapi2::platAttrSvc::setRowRepairData function
//******************************************************************************
ReturnCode setRowRepairData( const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                             ATTR_ROW_REPAIR_DATA_Type (&i_data) )
{
    FAPI_INF(">>setRowRepairData: Setting row repair data");

    fapi2::ReturnCode l_rc;
    errlHndl_t l_errl = nullptr;
    uint8_t * l_data =
        static_cast<uint8_t*>( malloc(DIMM_BAD_DQ_SIZE_BYTES) );
    do
    {
        // Get the TARGETING dimm target
        TARGETING::TargetHandle_t l_dimmTarget = nullptr;
        l_errl = getTargetingTarget( i_fapiTarget, l_dimmTarget );
        if ( l_errl )
        {
            FAPI_ERR( "setRowRepairData: Error from getTargetingTarget" );
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        // Get the FAPI dimm target
        Target<TARGET_TYPE_DIMM> l_fapiDimm( l_dimmTarget );

        // Get the original data.
        l_errl = deviceRead( l_dimmTarget, l_data, DIMM_BAD_DQ_SIZE_BYTES,
                             DEVICE_SPD_ADDRESS(SPD::DIMM_BAD_DQ_DATA) );
        if ( l_errl )
        {
            FAPI_ERR( "setRowRepairData: Failed to call deviceRead to get "
                      "l_data." );
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        dimmBadDqDataFormat l_spdData;
        memcpy( &l_spdData, l_data, sizeof(dimmBadDqDataFormat) );

        // Update the header
        l_spdData.iv_magicNumber = htobe32( DIMM_BAD_DQ_MAGIC_NUMBER );
        l_spdData.iv_version = DIMM_BAD_DQ_VERSION;
        l_spdData.iv_reserved1 = 0;
        l_spdData.iv_reserved2 = 0;
        l_spdData.iv_reserved3 = 0;

        // Translate the input data
        ATTR_ROW_REPAIR_DATA_Type l_translatedData;
        memcpy( &l_translatedData, i_data, sizeof(ATTR_ROW_REPAIR_DATA_Type) );
        FAPI_TRY( __rowRepairTranslateDramPos(l_fapiDimm, true,
                                              l_translatedData) );
        // Update the row repair data
        memcpy( &l_spdData.iv_rowRepairData, l_translatedData,
                sizeof(ATTR_ROW_REPAIR_DATA_Type) );

        // Write the data back to VPD.
        l_errl = deviceWrite( l_dimmTarget, &l_spdData, DIMM_BAD_DQ_SIZE_BYTES,
                              DEVICE_SPD_ADDRESS(SPD::DIMM_BAD_DQ_DATA) );
        if ( l_errl )
        {
            FAPI_ERR( "setRowRepairData: Failed to call deviceWrite to set "
                      "l_spdData." );
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

    }while(0);

fapi_try_exit:

    FAPI_INF("<<setRowRepairData: Finished setting row repair data");

    if ( l_data != nullptr )
    {
        free( l_data );
        l_data = nullptr;
    }

    if ( l_rc )
    {
        return l_rc;
    }

    return fapi2::current_err;
}

//******************************************************************************
// fapi::platAttrSvc::platGetSecurityMode function
//******************************************************************************
ReturnCode platGetSecurityMode(uint8_t & o_securityMode)
{
    #ifndef __HOSTBOOT_RUNTIME
    o_securityMode = SECUREBOOT::getSbeSecurityMode();
    #else
    o_securityMode = 0xFF;
    FAPI_INF("Get SECURITY_MODE not supported from hostboot runtime");
    #endif
    return fapi2::ReturnCode();
}

//******************************************************************************
// fapi::platAttrSvc::platSetSecurityMode function
//******************************************************************************
ReturnCode platSetSecurityMode()
{
    FAPI_INF("Set SECURITY_MODE ignored when called from FAPI code");
    return fapi2::ReturnCode();
}

//-----------------------------------------------------------------------------
ReturnCode platGetControlCapableData(
                                const Target<TARGET_TYPE_ALL>& i_fapiTarget,
        ATTR_CEN_VPD_POWER_CONTROL_CAPABLE_Type& o_vpdPowerControlCapableVal
                                    )
{
    ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetControlCapableData: Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP> l_fapiTarget(l_pTarget);
        rc = getControlCapableData(l_fapiTarget, o_vpdPowerControlCapableVal);
    }

    return rc;
}

template<typename T1>
struct VPD_CACHING_PAIR
{
    TARGETING::ATTR_HUID_type huid;
    T1 value;

    inline bool operator==(TARGETING::ATTR_HUID_type huid_rhs) {
        return huid_rhs == huid;
    }
} ;

//-----------------------------------------------------------------------------
ReturnCode platGetDQAttrISDIMM(
                           const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                           ATTR_CEN_VPD_ISDIMMTOC4DQ_Type &o_vpdIsDimmTOC4DQVal
                              )
{
    ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    static std::vector<VPD_CACHING_PAIR<ATTR_CEN_VPD_ISDIMMTOC4DQ_Type>> l_cachedC4DQValues;
    static mutex_t l_C4DQmutex = MUTEX_INITIALIZER;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetDQAttrISDIMM: Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        mutex_lock(&l_C4DQmutex);
        auto l_huid = TARGETING::get_huid(l_pTarget);
        auto l_iterator = std::find ( l_cachedC4DQValues.begin(),
                                      l_cachedC4DQValues.end(),
                                      l_huid);

        if(l_iterator == l_cachedC4DQValues.end())
        {
            fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP> l_fapiTarget(l_pTarget);
            VPD_CACHING_PAIR<ATTR_CEN_VPD_ISDIMMTOC4DQ_Type> l_kvPair = VPD_CACHING_PAIR<ATTR_CEN_VPD_ISDIMMTOC4DQ_Type>();
            l_kvPair.huid = l_huid;
            rc = getDQAttrISDIMM(l_fapiTarget, l_kvPair.value);
            memcpy(o_vpdIsDimmTOC4DQVal, l_kvPair.value, sizeof(ATTR_CEN_VPD_ISDIMMTOC4DQ_Type));
            l_cachedC4DQValues.push_back(l_kvPair);
        }
        else
        {
            memcpy(o_vpdIsDimmTOC4DQVal, (*l_iterator).value, sizeof(ATTR_CEN_VPD_ISDIMMTOC4DQ_Type));
        }
        mutex_unlock(&l_C4DQmutex);
    }

    return rc;
}


//-----------------------------------------------------------------------------
ReturnCode platGetDQSAttrISDIMM(
                    const Target<TARGET_TYPE_ALL>& i_fapiTarget,
          ATTR_CEN_VPD_ISDIMMTOC4DQS_Type& o_vpdIsDimmTOC4DQSVal
                               )
{
    ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    static std::vector<VPD_CACHING_PAIR<ATTR_CEN_VPD_ISDIMMTOC4DQS_Type>> l_cachedC4DQSValues;
    static mutex_t l_C4DQSmutex = MUTEX_INITIALIZER;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetDQSAttrISDIMM: Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        mutex_lock(&l_C4DQSmutex);
        auto l_huid = TARGETING::get_huid(l_pTarget);
        auto l_iterator = std::find ( l_cachedC4DQSValues.begin(),
                                      l_cachedC4DQSValues.end(),
                                      l_huid);

        if(l_iterator == l_cachedC4DQSValues.end())
        {
            fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP> l_fapiTarget(l_pTarget);
            VPD_CACHING_PAIR<ATTR_CEN_VPD_ISDIMMTOC4DQS_Type>l_kvPair =
                                  VPD_CACHING_PAIR<ATTR_CEN_VPD_ISDIMMTOC4DQS_Type>();
            l_kvPair.huid = l_huid;
            rc = getDQSAttrISDIMM(l_fapiTarget, l_kvPair.value);
            memcpy(o_vpdIsDimmTOC4DQSVal, l_kvPair.value, sizeof(ATTR_CEN_VPD_ISDIMMTOC4DQS_Type));
            l_cachedC4DQSValues.push_back(l_kvPair);
        }
        else
        {
            memcpy(o_vpdIsDimmTOC4DQSVal, (*l_iterator).value, sizeof(ATTR_CEN_VPD_ISDIMMTOC4DQS_Type));
        }
        mutex_unlock(&l_C4DQSmutex);
    }

    return rc;
}

//-----------------------------------------------------------------------------
ReturnCode platGetMBvpdSensorMapPrimary(
                                   const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                   ATTR_CEN_VPD_CDIMM_SENSOR_MAP_PRIMARY_Type& o_SensorMapType
                                        )
{
    ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetMBvpdSensorMapPrimary: "
                                              "Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP> l_fapiTarget(l_pTarget);
        rc = getMBvpdSensorMap(l_fapiTarget, fapi2::SENSOR_MAP_PRIMARY, o_SensorMapType);
    }

    return rc;
}

//-----------------------------------------------------------------------------
ReturnCode platGetMBvpdSensorMapSecondary(
                                   const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                   ATTR_CEN_VPD_CDIMM_SENSOR_MAP_SECONDARY_Type& o_SensorMapType
                                        )
{
    ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetMBvpdSensorMapSecondary: "
                                              "Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP> l_fapiTarget(l_pTarget);
        rc = getMBvpdSensorMap(l_fapiTarget, fapi2::SENSOR_MAP_SECONDARY, o_SensorMapType);
    }

    return rc;
}

//-----------------------------------------------------------------------------
ReturnCode platGetMBvpdDramAddressMirroring(
                                   const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                   ATTR_CEN_VPD_DRAM_ADDRESS_MIRRORING_Type& o_dramAddressMirroring
                                        )
{
    ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetMBvpdDramAddressMirroring: "
                                              "Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        fapi2::Target<fapi2::TARGET_TYPE_MBA> l_fapiTarget(l_pTarget);
        rc = getMBvpdAddrMirrorData(l_fapiTarget, o_dramAddressMirroring);
    }

    return rc;
}

//-----------------------------------------------------------------------------
ReturnCode platGetMBvpdDram2NModeEnabled(
                                   const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                   ATTR_CEN_VPD_DRAM_2N_MODE_ENABLED_Type& o_dram2NModeEnabled
                                        )
{
    ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetMBvpdDram2NModeEnabled: "
                                              "Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        fapi2::Target<fapi2::TARGET_TYPE_MBA> l_fapiTarget(l_pTarget);
        rc = getMBvpdDram2NModeEnabled(l_fapiTarget, o_dram2NModeEnabled);
    }

    return rc;
}

//-----------------------------------------------------------------------------
ReturnCode platGetMBvpdMemoryDataVersion(
                                   const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                                ATTR_CEN_VPD_VM_KEYWORD_Type& o_vpdVMKeywordVal
                                        )
{
    ReturnCode rc;

    do
    {
        // Don't need to check the type here, the FAPI_ATTR_GET macro clause
        // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
        // to enable a streamlined dump of the attributes, all plat code must
        // use the generic TARGET_TYPE_ALL -- so convert back to the correct
        // type manually
        TARGETING::Target * l_pTarget = NULL;
        errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

        if (l_errl)
        {
            FAPI_ERR("platGetMBvpdMemoryDataVersion: "
                                           "Error from getTargetingTarget");

            rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }
        else
        {
            fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP>
                                                    l_fapiTarget(l_pTarget);

            rc = getMBvpdMemoryDataVersion(l_fapiTarget, o_vpdVMKeywordVal);
        }
    }
    while(0);

    return rc;
}

//-----------------------------------------------------------------------------
ReturnCode platGetMBvpdSPDXRecordVersion(
                                   const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                                ATTR_CEN_VPD_VD_KEYWORD_Type& o_vpdVDKeywordVal
                                        )
{
    ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetMBvpdSPDXRecordVersion: "
                                              "Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP> l_fapiTarget(l_pTarget);
        rc = getMBvpdSPDXRecordVersion(l_fapiTarget, o_vpdVDKeywordVal);
    }

    return rc;
}

//-----------------------------------------------------------------------------
ReturnCode platGetMBvpdSpareDramData(
                                  const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                                 ATTR_CEN_VPD_DIMM_SPARE_Type& o_vpdDimmSpare
                                    )
{
    ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetMBvpdSpareDramData: Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        fapi2::Target<fapi2::TARGET_TYPE_MBA> l_fapiTarget(l_pTarget);
        rc = getMBvpdSpareDramData(l_fapiTarget, o_vpdDimmSpare);
    }

    return rc;
}

//-----------------------------------------------------------------------------
ReturnCode platGetMBvpdVersion(
                                 const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                                 ATTR_CEN_VPD_VERSION_Type& o_vpdVersion
                               )
{
    ReturnCode rc;

    do
    {
        // Don't need to check the type here, the FAPI_ATTR_GET macro clause
        // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
        // to enable a streamlined dump of the attributes, all plat code must use
        // the generic TARGET_TYPE_ALL -- so convert back to the correct type
        // manually
        TARGETING::Target * l_pTarget = NULL;
        errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

        if (l_errl)
        {
            FAPI_ERR("platGetMBvpdVersion: Error from getTargetingTarget");
            rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
        }
        else
        {
            TARGETING::TargetHandleList l_mbaList;

            // Find MBA target from DIMM target
            getParentAffinityTargets(l_mbaList,
                                     l_pTarget,
                                     TARGETING::CLASS_UNIT,
                                     TARGETING::TYPE_MBA,
                                     false);

            const bool hbSwError = true;

            if(l_mbaList.empty())
            {
                /*@
                 * @errortype
                 * @moduleid     fapi2::MOD_FAPI2_GET_ATTR_CEN_VPD_VERSION
                 * @reasoncode   fapi2::RC_NO_PARENT_MBA
                 * @userdata1    DIMM HUID
                 * @userdata2    0
                 * @devdesc      platGetMBvpdMemoryDataVersion could not find
                 *               an mba parent target from the passed in
                 *               dimm target.
                 */
                l_errl = new ERRORLOG::ErrlEntry(
                                     ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                     fapi2::MOD_FAPI2_GET_ATTR_CEN_VPD_VERSION,
                                     fapi2::RC_NO_SINGLE_MBA,
                                     TARGETING::get_huid(l_pTarget),
                                     0,
                                     hbSwError);

                FAPI_ERR("platGetMBvpdVersion: "
                                "Error could not find an MBA parent for DIMM");

                rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
                break;
            }
            else if(l_mbaList.size() != 1)
            {
                /*@
                 * @errortype
                 * @moduleid     fapi2::MOD_FAPI2_GET_ATTR_CEN_VPD_VERSION
                 * @reasoncode   fapi2::RC_NO_SINGLE_MBA
                 * @userdata1    Number of MBAs
                 * @userdata2    DIMM HUID
                 * @devdesc      platGetMBvpdMemoryDataVersion could not find
                 *               the expected 1 mba from the passed dimm target
                 */
                l_errl = new ERRORLOG::ErrlEntry(
                                     ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                     fapi2::MOD_FAPI2_GET_ATTR_CEN_VPD_VERSION,
                                     fapi2::RC_NO_SINGLE_MBA,
                                     l_mbaList.size(),
                                     TARGETING::get_huid(l_pTarget),
                                     hbSwError);

                FAPI_ERR("platGetMBvpdVersion: "
                         "Found multiple MBA chips while "
                         "seeking parent for DIMM");

                rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
                break;
            }

            fapi2::Target<fapi2::TARGET_TYPE_MBA>
                                            l_fapiTarget(l_mbaList.front());

            rc = getMBvpdVersion(l_fapiTarget, o_vpdVersion);
        }

    }
    while(0);

    return rc;
}

//-----------------------------------------------------------------------------
ReturnCode platGetMBvpdVoltageSettingData(
                                const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                               ATTR_CEN_VPD_DW_KEYWORD_Type& o_vpdDWKeyword
                                         )
{
    ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetMBvpdVoltageSettingData: "
                                              "Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP> l_fapiTarget(l_pTarget);
        rc = getMBvpdVoltageSettingData(l_fapiTarget, o_vpdDWKeyword);
    }

    return rc;
}

//----------------------------------------------------------------------------
ReturnCode platGetMBvpdAttr(
                           const fapi2::Target<TARGET_TYPE_ALL>&  i_fapiTarget,
                           const fapi2::AttributeId i_attr,
                           void*   o_pVal,
                           const size_t i_valSize
                           )
{
    ReturnCode rc;
    constexpr bool hbSwError{true};

    do
    {
        // Don't need to check the type here, the FAPI_ATTR_GET macro clause
        // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
        // to enable a streamlined dump of the attributes, all plat code must
        // use the generic TARGET_TYPE_ALL -- so convert back to the correct
        // type manually
        TARGETING::Target * l_pTarget = NULL;
        errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

        if (l_errl)
        {
            FAPI_ERR("platGetMBvpdAttr: Error from getTargetingTarget");
            rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
        }
        else
        {
            TARGETING::TYPE l_type =
                                l_pTarget->getAttr<TARGETING::ATTR_TYPE>();

            if(TARGETING::TYPE_MBA != l_type)
            {
                if(TARGETING::TYPE_MEMBUF != l_type)
                {
                    /*@
                     * @errortype
                     * @moduleid     fapi2::MOD_FAPI2_GET_MB_VPD_ATTR
                     * @reasoncode   fapi2::RC_INVALID_TARGET_TYPE
                     * @userdata1    Target Type
                     * @userdata2    Target HUID
                     * @devdesc      platGetMBvpdMemoryDataVersion requires
                     *               a target of type TYPE_MBA or TYPE_MEMBUF
                     */
                    l_errl = new ERRORLOG::ErrlEntry(
                                      ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                      fapi2::MOD_FAPI2_GET_ATTR_CEN_VPD_VERSION,
                                      fapi2::RC_INVALID_TARGET_TYPE,
                                      l_type,
                                      TARGETING::get_huid(l_pTarget),
                                      hbSwError);

                    rc = ReturnCode(fapi2::RC_INVALID_TARGET_TYPE);
                    rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
                    FAPI_ERR("platGetMBvpdAttr: Invalid Target Type.");
                    break;
                }

                TARGETING::TargetHandleList l_mbaList;
                TARGETING::getChildAffinityTargets(l_mbaList,
                                                   l_pTarget,
                                                   TARGETING::CLASS_UNIT,
                                                   TARGETING::TYPE_MBA,
                                                   false);

                if(l_mbaList.empty())
                {
                    /*@
                     * @errortype
                     * @moduleid     fapi2::MOD_FAPI2_GET_MB_VPD_ATTR
                     * @reasoncode   fapi2::RC_NO_CHILD_MBA
                     * @userdata1    Target Type
                     * @userdata2    Target HUID
                     * @devdesc      platGetMBvpdMemoryDataVersion could not
                     *               find any child mba's from the passed in
                     *               target of type TYPE_MEMBUF
                     */
                    l_errl = new ERRORLOG::ErrlEntry(
                                      ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                      fapi2::MOD_FAPI2_GET_ATTR_CEN_VPD_VERSION,
                                      fapi2::RC_NO_CHILD_MBA,
                                      l_type,
                                      TARGETING::get_huid(l_pTarget),
                                      hbSwError);

                    rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
                    FAPI_ERR("platGetMBvpdAttr: Could not find a child mba "
                             "for the passed in membuf target."
                            );
                    break;
                }

                //since we have to get the value from a child mba, try all
                //child mba's until successful.
                for(auto l_currentMba: l_mbaList)
                {
                    fapi2::Target<fapi2::TARGET_TYPE_MBA>
                                                   l_fapiTarget(l_currentMba);

                    rc = getMBvpdAttr(l_fapiTarget,
                                      i_attr,
                                      o_pVal,
                                      i_valSize);

                    if(rc == fapi2::FAPI2_RC_SUCCESS)
                    {
                        break;
                    }
                }
            }
            else
            {

                fapi2::Target<fapi2::TARGET_TYPE_MBA> l_fapiTarget(l_pTarget);
                rc = getMBvpdAttr(l_fapiTarget,
                                  i_attr,
                                  o_pVal,
                                  i_valSize);
            }
        }
    }
    while(0);

    return rc;
}

//******************************************************************************
// fapi::platAttrSvc::getPllBucket function
//******************************************************************************
ReturnCode getPllBucket(const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                        uint8_t & o_bucket_val,
                        const uint8_t i_index)
{
    fapi2::ReturnCode l_rc;
    errlHndl_t l_errl = nullptr;

    TARGETING::Target * l_chipTarget = nullptr;
    l_errl = getTargetingTarget(i_fapiTarget, l_chipTarget);
    if(l_errl)
    {
        FAPI_ERR("getPllBucket: Error from getTargetingTarget");
        l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        l_errl = Util::getObusPllBucket(l_chipTarget, o_bucket_val, i_index);
        if (l_errl)
        {
            FAPI_ERR("getPllBucket: Error from getObusPllBucket");
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
        }
    }
    return l_rc;
}

//-----------------------------------------------------------------------------
ReturnCode platGetMBvpdSlopeInterceptData(
                                   const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                                   const uint32_t i_attr,
                                   uint32_t& o_val)
{
    ReturnCode rc;

    // Don't need to check the type here, the FAPI_ATTR_GET macro clause
    // "fapi2::Target<ID##_TargetType>(TARGET)" does it for us.  However,
    // to enable a streamlined dump of the attributes, all plat code must use
    // the generic TARGET_TYPE_ALL -- so convert back to the correct type
    // manually
    TARGETING::Target * l_pTarget = NULL;
    errlHndl_t l_errl = getTargetingTarget(i_fapiTarget, l_pTarget);

    if (l_errl)
    {
        FAPI_ERR("platGetMBvpdSPDXRecordVersion: "
                                              "Error from getTargetingTarget");
        rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        MBvpdSlopeIntercept l_val;

        switch (i_attr)
        {
            case ATTR_CEN_CDIMM_VPD_MASTER_POWER_INTERCEPT:
                l_val = MASTER_POWER_INTERCEPT;
                break;
            case ATTR_CEN_CDIMM_VPD_MASTER_POWER_SLOPE:
                l_val = MASTER_POWER_SLOPE;
                break;
            case ATTR_CEN_CDIMM_VPD_MASTER_TOTAL_POWER_INTERCEPT:
                l_val = MASTER_TOTAL_POWER_INTERCEPT;
                break;
            case ATTR_CEN_CDIMM_VPD_MASTER_TOTAL_POWER_SLOPE:
                l_val = MASTER_TOTAL_POWER_SLOPE;
                break;
            case ATTR_CEN_CDIMM_VPD_SUPPLIER_POWER_INTERCEPT:
                l_val = SUPPLIER_POWER_INTERCEPT;
                break;
            case ATTR_CEN_CDIMM_VPD_SUPPLIER_POWER_SLOPE:
                l_val = SUPPLIER_POWER_SLOPE;
                break;
            case ATTR_CEN_CDIMM_VPD_SUPPLIER_TOTAL_POWER_INTERCEPT:
                l_val = SUPPLIER_TOTAL_POWER_INTERCEPT;
                break;
            case ATTR_CEN_CDIMM_VPD_SUPPLIER_TOTAL_POWER_SLOPE:
                l_val = SUPPLIER_TOTAL_POWER_SLOPE;
                break;
            default:
                l_val = MASTER_POWER_INTERCEPT;
        }

        fapi2::Target<fapi2::TARGET_TYPE_MEMBUF_CHIP> l_fapiTarget(l_pTarget);
        rc = getMBvpdSlopeInterceptData(l_fapiTarget, l_val, o_val);
    }

    return rc;
}

#ifndef CONFIG_AXONE
//******************************************************************************
// fapi::platAttrSvc::platGetFreqMcaMhz function
//******************************************************************************
ReturnCode platGetFreqMcaMhz(const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                             ATTR_FREQ_MCA_MHZ_Type & o_val)
{
    // The POR config for Cumulus is to run the MC/DMI clocks directly
    // off of the NEST PLL in 'sync' mode.  To support 'sync' mode FW
    // can pin ATTR_FREQ_MCA_MHZ == ATTR_FREQ_PB_MHZ.

    fapi2::ReturnCode l_rc;
    errlHndl_t l_errl = nullptr;

    TARGETING::Target * l_chipTarget = nullptr;
    l_errl = getTargetingTarget(i_fapiTarget, l_chipTarget);
    if(l_errl)
    {
        FAPI_ERR("platGetFreqMcaMhz: Error from getTargetingTarget");
        l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
    }
    else
    {
        o_val = l_chipTarget->getAttr<TARGETING::ATTR_FREQ_PB_MHZ>();
    }
    return l_rc;
}

#else

/// @brief This function is called by the FAPI_ATTR_GET functions that lookup
/// values in the MEM_PLL_FREQ_BUCKETS tree. The key's used to lookup values in that
/// tree are the ATTR_FREQ_OMI_MHZ and ATTR_OMI_PLL_VCO attributes. These are on the
/// processor target but it is expected that all of the values match.
///  @param[out] o_omiFreq  OMI Frequency of the system
///  @param[out] o_omiVco   OMI VCO of the system
///  @return ReturnCode Zero on success, else platform specified error.
errlHndl_t getOmiFreqAndVco(TARGETING::ATTR_FREQ_OMI_MHZ_type & o_omiFreq,
                            TARGETING::ATTR_OMI_PLL_VCO_type & o_omiVco)
{
    errlHndl_t l_errl = nullptr;

    // Get all functional Proc targets
    TARGETING::TargetHandleList l_procsList;
    getAllChips(l_procsList, TARGETING::TYPE_PROC);
    uint8_t l_firstValidProc = 0;
    bool l_outValueSet = false;

    // Until we are told we need to support individual processor frequency
    // assert that all of the processors have the same values
    for(uint8_t i = 0; i < l_procsList.size(); i++)
    {
        // Get a list of functional OCMB targets under this processor
        TARGETING::TargetHandleList l_childOcmbList;
        TARGETING::getChildAffinityTargets(l_childOcmbList, l_procsList[i],
                                           TARGETING::CLASS_CHIP,
                                           TARGETING::TYPE_OCMB_CHIP);
        // If there are no OCMB children for this processor then ignore it;
        if(l_childOcmbList.size() == 0)
        {
            continue;
        }

        // First valid processor's values will be used to compare against all other processors
        if(!l_outValueSet)
        {
            o_omiFreq = l_procsList[i]->getAttr<TARGETING::ATTR_FREQ_OMI_MHZ>();
            o_omiVco = l_procsList[i]->getAttr<TARGETING::ATTR_OMI_PLL_VCO>();
            l_outValueSet = true;
            l_firstValidProc = i;
            continue;
        }

        TARGETING::ATTR_FREQ_OMI_MHZ_type l_omiFreqToCmp = l_procsList[i]->getAttr<TARGETING::ATTR_FREQ_OMI_MHZ>();
        TARGETING::ATTR_OMI_PLL_VCO_type  l_omiVcoToCmp  = l_procsList[i]->getAttr<TARGETING::ATTR_OMI_PLL_VCO>();

        // If we found that this processor's OMI freq / vco values do not match the first processor's values then
        // return an error
        if (l_omiFreqToCmp != o_omiFreq ||
            l_omiVcoToCmp  != o_omiVco )
        {
            FAPI_ERR("platGetMcPllBucket: Detected two processors with difference OMI VCO / FREQ combinations."
                      " Proc 0x%.08X has OMI freq = %d and OMI vco = %d. "
                      " Proc 0x%.08X has OMI freq = %d and OMI vco = %d. " ,
                    get_huid(l_procsList[l_firstValidProc]), o_omiFreq, o_omiVco,
                    get_huid(l_procsList[i]), l_omiFreqToCmp, l_omiVcoToCmp );

            /*@
              * @errortype
              * @moduleid     fapi2::MOD_GET_OMI_FREQ_AND_VCO
              * @reasoncode   fapi2::RC_PROC_FREQ_MISMATCH
              * @userdata1[0:31]  first ATTR_FREQ_OMI_MHZ found
              * @userdata1[32:63] first ATTR_FREQ_PLL_VCO found
              * @userdata2[0:31]  ATTR_FREQ_OMI_MHZ mismatch found
              * @userdata2[32:63] ATTR_FREQ_PLL_VCO mismatch found
              * @devdesc      Found mismatching processor attribute settings
              *               when we expect them to all be in sync
              */
            l_errl = new ERRORLOG::ErrlEntry(
                              ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                              fapi2::MOD_GET_OMI_FREQ_AND_VCO,
                              fapi2::RC_NO_MATCHING_FREQ,
                              TWO_UINT32_TO_UINT64(o_omiFreq, o_omiVco),
                              TWO_UINT32_TO_UINT64(l_omiFreqToCmp, l_omiVcoToCmp),
                              ERRORLOG::ErrlEntry::NO_SW_CALLOUT);
            l_errl->collectTrace(FAPI_IMP_TRACE_NAME, 256);
            break;
        }
    }

    return l_errl;
}

// OMI bucket descriptor
struct OmiFreqVcoBucketSelect_t
{
    uint32_t omifreq;   // OMI Frequency in MHz
    uint32_t vco;       // VCO selector
    uint8_t pll_bucket; // MCA Frequency in MHz
};


//******************************************************************************
// fapi::platAttrSvc::platGetMcPllBucket function
//******************************************************************************
ReturnCode platGetMcPllBucket(const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                             ATTR_MC_PLL_BUCKET_Type & o_val)
{
    fapi2::ReturnCode l_rc;
    errlHndl_t l_errl = nullptr;
    TARGETING::Target * l_sysTarget = nullptr;
    TARGETING::ATTR_FREQ_OMI_MHZ_type l_omiFreq = 0;
    TARGETING::ATTR_OMI_PLL_VCO_type  l_omiVco  = 0;
    bool l_matchFound = false;

    // There can be up to 2 matches for OMI frequencies. If only 1 match is found
    // then we ignore the VCO attribute
    std::vector<OmiFreqVcoBucketSelect_t> l_omiFreqMatches;

    do{
        // Convert to platform-style target
        l_errl = getTargetingTarget(i_fapiTarget, l_sysTarget);

        if(l_errl)
        {
            FAPI_ERR("platGetMcPllBucket: Error from getTargetingTarget");
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        // Use helper function to lookup omi frequency and omi vco for this system
        l_errl = getOmiFreqAndVco(l_omiFreq, l_omiVco);

        if(l_errl)
        {
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        // Loop through the MEM_PLL frequency buckets to see if we can find a bucket that
        // matches what we have found for omi freq and vco
        for(uint8_t i = 0; i < MEM_PLL_FREQ_BUCKETS; i++)
        {
            if(OMI_PLL_FREQ_LIST[i].omifreq == l_omiFreq)
            {
                OmiFreqVcoBucketSelect_t l_tmpBucketSelect = {OMI_PLL_FREQ_LIST[i].omifreq, OMI_PLL_FREQ_LIST[i].vco, i};
                l_omiFreqMatches.push_back(l_tmpBucketSelect);
            }
        }

        if(l_omiFreqMatches.size() > 1)
        {
            for(uint8_t i = 0; i < l_omiFreqMatches.size(); i++)
            {
                if(l_omiFreqMatches[i].vco == l_omiVco)
                {
                    FAPI_INF("Found match to be bucket %d for freq %d, vco %d",
                             l_omiFreqMatches[i].pll_bucket,
                             OMI_PLL_FREQ_LIST[i].omifreq,
                             OMI_PLL_FREQ_LIST[i].vco);
                    l_matchFound = true;
                    // Value returned in this case is the bucket number that had the matching values
                    // MC_PLL_BUCKET attribute is 1-based so increment bucket ID by 1
                    o_val = l_omiFreqMatches[i].pll_bucket + 1;
                    break;
                }
            }
        }
        else if (l_omiFreqMatches.size() == 1)
        {
            FAPI_INF("Single match for OMI freq %d found in OMI_PLL_FREQ_LIST, ignoring VCO attribute. PLL Bucket = %d",
                     l_omiFreq,
                     l_omiFreqMatches[0].pll_bucket);
            l_matchFound = true;
            // MC_PLL_BUCKET attribute is 1-based so increment bucket ID by 1
            o_val = l_omiFreqMatches[0].pll_bucket + 1;
        }

        // If not match is found return an error
        if(!l_matchFound)
        {
            FAPI_ERR("platGetMcPllBucket: Could not find matching bucket for omiFreq = %d and vco = %d",
                    l_omiFreq, l_omiVco);

            /*@
              * @errortype
              * @moduleid     fapi2::MOD_FAPI2_PLAT_GET_MC_PLL_BUCKET
              * @reasoncode   fapi2::RC_NO_MATCHING_FREQ
              * @userdata1[0:31]  ATTR_FREQ_OMI_MHZ
              * @userdata1[32:63] ATTR_FREQ_PLL_VCO
              * @userdata2    Target HUID
              * @devdesc      Invalid omi frequence and omi vco settings
              */
            l_errl = new ERRORLOG::ErrlEntry(
                              ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                              fapi2::MOD_FAPI2_PLAT_GET_MC_PLL_BUCKET,
                              fapi2::RC_NO_MATCHING_FREQ,
                              TWO_UINT32_TO_UINT64(l_omiFreq, l_omiVco),
                              TARGETING::get_huid(l_sysTarget),
                              ERRORLOG::ErrlEntry::NO_SW_CALLOUT);
            l_errl->collectTrace(FAPI_IMP_TRACE_NAME, 256);
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

    }while(0);
    return l_rc;
}

//******************************************************************************
// fapi::platAttrSvc::platGetFreqMcaMhz function
//******************************************************************************
ReturnCode platGetFreqMcaMhz(const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                             ATTR_FREQ_MCA_MHZ_Type & o_val)
{
    fapi2::ReturnCode l_rc;
    errlHndl_t l_errl = nullptr;
    TARGETING::Target * l_sysTarget = nullptr;
    TARGETING::ATTR_FREQ_OMI_MHZ_type l_omiFreq = 0;
    TARGETING::ATTR_OMI_PLL_VCO_type  l_omiVco  = 0;
    bool l_matchFound = false;

    // There can be up to 2 matches for OMI frequencies. If only 1 match is found
    // then we ignore the VCO attribute
    std::vector<OmiBucketDescriptor_t> l_matchingOmiBucketDescriptors;

    do{
        // Convert to platform-style target
        l_errl = getTargetingTarget(i_fapiTarget, l_sysTarget);

        if(l_errl)
        {
            FAPI_ERR("platGetFreqMcaMhz: Error from getTargetingTarget");
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        // Use helper function to lookup omi frequency and omi vco for this system
        l_errl = getOmiFreqAndVco(l_omiFreq, l_omiVco);

        if(l_errl)
        {
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

        // Loop through the MEM_PLL frequency buckets to see if we can find a bucket that
        // matches what we have found for omi freq and vco
        for(uint8_t i = 0; i < MEM_PLL_FREQ_BUCKETS; i++)
        {
            if(OMI_PLL_FREQ_LIST[i].omifreq == l_omiFreq)
            {
                l_matchingOmiBucketDescriptors.push_back(OMI_PLL_FREQ_LIST[i]);
            }
        }

        if(l_matchingOmiBucketDescriptors.size() > 1)
        {
            for(uint8_t i = 0; i < l_matchingOmiBucketDescriptors.size(); i++)
            {
                if(l_matchingOmiBucketDescriptors[i].vco == l_omiVco)
                {
                    FAPI_INF("found match for freq %d, vco %d. Mca freq = %d",
                             OMI_PLL_FREQ_LIST[i].omifreq, OMI_PLL_FREQ_LIST[i].vco);
                    l_matchFound = true;
                    // Value returned in this case is the bucket number that had the matching values
                    o_val = l_matchingOmiBucketDescriptors[i].mcafreq;
                    break;
                }
            }
        }
        else if (l_matchingOmiBucketDescriptors.size() == 1)
        {
            FAPI_INF("Single match for OMI freq %d found in OMI_PLL_FREQ_LIST, MCA freq found = %d, ignoring VCO attribute",
                     l_omiFreq,
                     l_matchingOmiBucketDescriptors[0].mcafreq);
            l_matchFound = true;
            o_val = l_matchingOmiBucketDescriptors[0].mcafreq;
        }

        if(!l_matchFound)
        {
            FAPI_ERR("platGetFreqMcaMhz: Could not find matching bucket for omiFreq = %d and vco = %d",
                    l_omiFreq, l_omiVco);

            /*@
              * @errortype
              * @moduleid     fapi2::MOD_FAPI2_PLAT_GET_FREQ_MCA_MHZ
              * @reasoncode   fapi2::RC_NO_MATCHING_FREQ
              * @userdata1[0:31]  ATTR_FREQ_OMI_MHZ
              * @userdata1[32:63] ATTR_FREQ_PLL_VCO
              * @userdata2    Target HUID
              * @devdesc      Invalid omi frequence and omi vco settings
              */
            l_errl = new ERRORLOG::ErrlEntry(
                              ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                              fapi2::MOD_FAPI2_PLAT_GET_FREQ_MCA_MHZ,
                              fapi2::RC_NO_MATCHING_FREQ,
                              TWO_UINT32_TO_UINT64(l_omiFreq, l_omiVco),
                              TARGETING::get_huid(l_sysTarget),
                              ERRORLOG::ErrlEntry::NO_SW_CALLOUT);
            l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
            break;
        }

    }while(0);
    return l_rc;
}



#endif


} // End platAttrSvc namespace

} // End fapi2 namespace
OpenPOWER on IntegriCloud