summaryrefslogtreecommitdiffstats
path: root/src/usr/hwas/common/deconfigGard.C
blob: f844ec9121c33badcd68791798f4a87339a20fbb (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
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwas/common/deconfigGard.C $                          */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2012,2018                        */
/* [+] 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 deconfigGard.C
 *
 *  @brief Implements the DeconfigGard class
 */
#include <stdint.h>
#include <algorithm>
#include <vector>

#include <hwas/common/hwas.H>
#include <hwas/common/hwasCommon.H>
#include <hwas/common/deconfigGard.H>
#include <hwas/common/hwas_reasoncodes.H>
#include <targeting/common/utilFilter.H>

#include <targeting/common/commontargeting.H>
#include <targeting/common/utilFilter.H>

#ifdef __HOSTBOOT_MODULE
#include <config.h>
#if (!defined(CONFIG_CONSOLE_OUTPUT_TRACE) && defined(CONFIG_CONSOLE))
#include <console/consoleif.H>
#endif
#endif

#ifdef CONFIG_BMC_IPMI
#include <ipmi/ipmisensor.H>
#endif

#ifdef CONFIG_TPMDD
#include <../../usr/secureboot/trusted/trustedbootUtils.H>
#endif


// Trace definition
#define __COMP_TD__ g_trac_deconf

namespace HWAS
{

using namespace HWAS::COMMON;
using namespace TARGETING;

#ifndef __HOSTBOOT_RUNTIME
//******************************************************************************
errlHndl_t collectGard(const PredicateBase *i_pPredicate)
{
    HWAS_DBG("collectGard entry" );
    errlHndl_t errl = NULL;

    do
    {
        errl = theDeconfigGard().clearGardRecordsForReplacedTargets();
        if (errl)
        {
            HWAS_ERR("ERROR: collectGard failed to clear GARD Records for replaced Targets");
            break;
        }

        (void)theDeconfigGard().clearFcoDeconfigures();

        errl = theDeconfigGard().
                    deconfigureTargetsFromGardRecordsForIpl(i_pPredicate);
        if (errl)
        {
            HWAS_ERR("ERROR: collectGard failed to deconfigure Targets from GARD Records for IPL");
            break;
        }

        errl = theDeconfigGard().processFieldCoreOverride();
        if (errl)
        {
            HWAS_ERR("ERROR: collectGard failed to process Field Core Override");
            break;
        }
    }
    while(0);

    if (errl)
    {
        HWAS_ERR("collectGard failed (plid 0x%X)", errl->plid());
    }
    else
    {
        HWAS_INF("collectGard completed successfully");
    }
    return errl;
} // collectGard

errlHndl_t clearGardByType(const GARD_ErrorType i_type)
{
    return theDeconfigGard().clearGardRecordsByType(i_type);
}

#endif //__HOSTBOOT_RUNTIME

//******************************************************************************
DeconfigGard & theDeconfigGard()
{
    return HWAS_GET_SINGLETON(theDeconfigGardSingleton);
}

//******************************************************************************
DeconfigGard::DeconfigGard()
: iv_platDeconfigGard(NULL),
  iv_XAOBusEndpointDeconfigured(false)
{
    HWAS_DBG("DeconfigGard Constructor");
    HWAS_MUTEX_INIT(iv_mutex);
}

//******************************************************************************
DeconfigGard::~DeconfigGard()
{
    HWAS_DBG("DeconfigGard Destructor");
    HWAS_MUTEX_DESTROY(iv_mutex);
    free(iv_platDeconfigGard);
}

#ifndef __HOSTBOOT_RUNTIME
//******************************************************************************
errlHndl_t DeconfigGard::applyGardRecord(Target *i_pTarget,
        GardRecord &i_gardRecord,
        const DeconfigureFlags i_deconfigRule)
{
    HWAS_INF("Apply gard record for a target");
    errlHndl_t l_pErr = NULL;
    do
    {
        // skip if not present
        if (!i_pTarget->getAttr<ATTR_HWAS_STATE>().present)
        {
            HWAS_INF("skipping %.8X - target not present",
                        get_huid(i_pTarget));
            l_pErr = platLogEvent(i_pTarget, GARD_NOT_APPLIED);
            if (l_pErr)
            {
                    HWAS_ERR("platLogEvent returned an error");
            }
            break;
        }

        // special case - use errlogEid UNLESS it's a Manual Gard
        uint32_t l_errlogEid =
                (i_gardRecord.iv_errorType == GARD_User_Manual) ?
                    DECONFIGURED_BY_MANUAL_GARD : i_gardRecord.iv_errlogEid;

        // all ok - do the work
        HWAS_MUTEX_LOCK(iv_mutex);

        // Deconfigure the Target
        // don't need to check ATTR_DECONFIG_GARDABLE -- if we get
        //  here, it's because of a gard record on this target
        _deconfigureTarget(*i_pTarget, l_errlogEid,NULL,i_deconfigRule);

        // Deconfigure other Targets by association
        _deconfigureByAssoc(*i_pTarget, l_errlogEid,i_deconfigRule);

        HWAS_MUTEX_UNLOCK(iv_mutex);

        if(i_deconfigRule == SPEC_DECONFIG)
        {
            break;
        }

        update_hwas_changed_mask(i_pTarget, HWAS_CHANGED_BIT_GARD_APPLIED);
        l_pErr = platLogEvent(i_pTarget, GARD_APPLIED);
        if (l_pErr)
        {
            HWAS_ERR("platLogEvent returned an error");
            break;
        }
    }
    while(0);
    return l_pErr;
}//applyGardRecord

//******************************************************************************
errlHndl_t DeconfigGard::clearGardRecordsForReplacedTargets()
{
    HWAS_INF("Clear GARD Records for replaced Targets");
    errlHndl_t l_pErr = NULL;

    // Create the predicate with HWAS changed state and our GARD bit
    PredicateHwasChanged l_predicateHwasChanged;
    l_predicateHwasChanged.changedBit(HWAS_CHANGED_BIT_GARD, true);
    std::vector<uint32_t> l_gardedRecordEids;

    do
    {
        GardRecords_t l_gardRecords;
        l_pErr = platGetGardRecords(NULL, l_gardRecords);
        if (l_pErr)
        {
            HWAS_ERR("Error from platGetGardRecords");
            break;
        }

        // For each GARD Record
        for (GardRecordsCItr_t l_itr = l_gardRecords.begin();
             l_itr != l_gardRecords.end();
             ++l_itr)
        {
            GardRecord l_gardRecord = *l_itr;

            // Find the associated Target
            Target* l_pTarget = targetService().
                            toTarget(l_gardRecord.iv_targetId);

            if (l_pTarget == NULL)
            {
                // could be a platform specific target for the other
                // ie, we are hostboot and this is an FSP target, or vice-versa
                HWAS_INF_BIN("Could not find Target for:",
                             &(l_gardRecord.iv_targetId),
                             sizeof(l_gardRecord.iv_targetId));

                // we just skip this GARD record
                continue;
            }

            // if target is unchanged, continue to next in loop
            if (l_predicateHwasChanged(l_pTarget) == false)
            {
                HWAS_INF("skipping %.8X - GARD changed bit false",
                        get_huid(l_pTarget));
                continue;
            }

            // if record is USER garded then don't clear it here and
            // continue to next in loop
            if (l_gardRecord.iv_errorType == GARD_User_Manual)
            {
                HWAS_INF("skipping %.8X - GARD user manual",
                        get_huid(l_pTarget));
                continue;
            }

            // we have made it this far so we know the target has changed
            // requiring its gard record to be cleared and eid stored
            // Clear the gard record

            ATTR_HWAS_STATE_CHANGED_FLAG_type l_actual =
              l_pTarget->getAttr<ATTR_HWAS_STATE_CHANGED_FLAG>();

            ATTR_HWAS_STATE_CHANGED_SUBSCRIPTION_MASK_type l_subscriptionMask =
              l_pTarget->getAttr<ATTR_HWAS_STATE_CHANGED_SUBSCRIPTION_MASK>();

            uint64_t * l_pPred =
               reinterpret_cast<uint64_t *>(&l_predicateHwasChanged);
            uint64_t * l_pPred_iv_desired = l_pPred + 1;
            uint64_t * l_pPred_iv_valid = l_pPred + 2;

            HWAS_INF( "clearGardRecordsForReplacedTargets() "
                      "HUID :0x%08x "
                      "\npredicate ATTR_HWAS_STATE_CHANGED_FLAG "
                      "iv_valid : 0x%08x%08x "
                      "predicate ATTR_HWAS_STATE_CHANGED_FLAG "
                      "iv_desired : 0x%08x%08x "
                      "\nTarget ATTR_HWAS_STATE_CHANGED_FLAG : 0x%08x%08x "
                      "Target ATTR_HWAS_STATE_CHANGED_SUBSCRIPTION_MASK "
                      ": 0x%08x%08x ",
                      get_huid(l_pTarget),
                      (*l_pPred_iv_valid) >> 32, (*l_pPred_iv_valid),
                      (*l_pPred_iv_desired) >> 32, (*l_pPred_iv_desired),
                      l_actual >> 32, l_actual,
                      l_subscriptionMask >> 32, l_subscriptionMask );

            HWAS_INF("clearing GARD for %.8X, recordId %d",
                        get_huid(l_pTarget),
                        l_gardRecord.iv_recordId);

            l_pErr = platClearGardRecords(l_pTarget);
            if (l_pErr)
            {
                HWAS_ERR("Error from platClearGardRecords");
                break;
            }
            // add gardRecord eid to vector so we can clear other records with
            // the same eid
            l_gardedRecordEids.push_back(l_gardRecord.iv_errlogEid);
        } // for

        if(!l_pErr)
        {
            // Second pass over present gard records to look for Errlog Ids
            GardRecords_t l_gardRecordsSecond;
            l_pErr = platGetGardRecords(NULL, l_gardRecordsSecond);
            if (l_pErr)
            {
                HWAS_ERR("Error from platGetGardRecords");
                break;
            }
            //PASS TWO: Check for other like error log Ids
            for(GardRecordsCItr_t l_itr = l_gardRecordsSecond.begin();
                    l_itr != l_gardRecordsSecond.end();
                    ++l_itr)
            {
                GardRecord l_gardRecord = *l_itr;

                // Find the associated Target
                Target* l_pTarget = targetService().
                                toTarget(l_gardRecord.iv_targetId);

                if (l_pTarget == NULL)
                {
                    // could be a platform specific target for the other
                    // ie, we are hostboot and this is an FSP target,
                    // or vice-versa
                    HWAS_INF_BIN("Could not find Target for:",
                                 &(l_gardRecord.iv_targetId),
                                 sizeof(l_gardRecord.iv_targetId));

                    // we just skip this GARD record
                    continue;
                }

                if (l_gardRecord.iv_errorType == GARD_User_Manual)
                {
                    // do not clear user garded records
                    HWAS_INF("Still skipping USER garded record %08X",
                        get_huid(l_pTarget));

                    // skip this GARD record
                    continue;
                }

                // Compare the current GARD record against all the stored
                // EIDs from the first pass. If there is a match,
                // clear the GARD record.

                if(l_gardedRecordEids.end() != std::find(
                                                     l_gardedRecordEids.begin(),
                                                     l_gardedRecordEids.end(),
                                                     l_gardRecord.iv_errlogEid))
                {
                    // we have found a gard record that has a matching EID
                    // as something else that has been cleared, so clear
                    // GARD record.
                    HWAS_INF("clearing GARD for %08x, recordId %d due to"
                             " matching EID of %08x",
                                get_huid(l_pTarget),
                                l_gardRecord.iv_recordId,
                                l_gardRecord.iv_errlogEid);
                    l_pErr = platClearGardRecords(l_pTarget);

                    if (l_pErr)
                    {
                        HWAS_ERR("Error from platClearGardRecords");
                        break;
                    }
                }
            }
        }
        // now we need to go thru and clear all of the GARD bits in the
        // changed flags for all targets
        for (TargetIterator t_iter = targetService().begin();
                t_iter != targetService().end();
                ++t_iter)
        {
            Target* l_pTarget = *t_iter;

            if (l_predicateHwasChanged(l_pTarget))
            {
                clear_hwas_changed_bit(l_pTarget,HWAS_CHANGED_BIT_GARD);
            }
        }
    }
    while (0);

    return l_pErr;
} // clearGardRecordsForReplacedTargets

//******************************************************************************
errlHndl_t DeconfigGard::clearGardRecordsByType(const GARD_ErrorType i_type)
{
    HWAS_INF("Clear GARD Records by type %x", i_type);
    errlHndl_t l_pErr = nullptr;

    do
    {
        GardRecords_t l_gardRecords;
        l_pErr = platGetGardRecords(nullptr, l_gardRecords);
        if (l_pErr)
        {
            HWAS_ERR("Error from platGetGardRecords");
            break;
        }

        // For each GARD Record
        for (const auto & l_gardRecord : l_gardRecords)
        {
            //If this is the type to clear
            if(l_gardRecord.iv_errorType == i_type)
            {
                // Find the associated Target
                Target* l_pTarget = targetService().
                  toTarget(l_gardRecord.iv_targetId);

                if (l_pTarget == nullptr)
                {
                    // could be a platform specific target for the other
                    // ie, we are hostboot and this is an FSP target, or
                    // vice-versa
                    // we just skip this GARD record
                    continue;
                }

                l_pErr = platClearGardRecords(l_pTarget);
                if (l_pErr)
                {
                    HWAS_ERR("Error from platClearGardRecords");
                    break;
                }

            }
        }
    }
    while (0);

    return l_pErr;
} // clearGardRecordsByType

//******************************************************************************
errlHndl_t DeconfigGard::updateSpecDeconfigTargetStates(
        const PredicateBase *i_pPredicate)
{
    errlHndl_t l_pErr = NULL;

    do
    {
        // It is a caller error if this function is called and spec deconfig
        // is not enabled.
        Target * pSys;
        targetService().getTopLevelTarget(pSys);
        HWAS_ASSERT((pSys->getAttr<ATTR_BLOCK_SPEC_DECONFIG>() == 1),
                "HWAS updateSpecDeconfigTargetStates: "
                "ATTR_BLOCK_SPEC_DECONFIG != 1");

        // Get all GARD Records
        GardRecords_t l_gardRecords;
        l_pErr = platGetGardRecords(NULL, l_gardRecords);
        if (l_pErr)
        {
            HWAS_ERR("Error from platGetGardRecords");
            break;
        }

        for (GardRecordsCItr_t l_itr = l_gardRecords.begin();
             (l_itr != l_gardRecords.end());
             ++l_itr)
        {
            GardRecord l_gardRecord = *l_itr;

            // Find the associated Target
            Target * l_pTarget =
                targetService().toTarget(l_gardRecord.iv_targetId);

            if (l_pTarget == NULL)
            {
                // could be a platform specific target for the other
                // ie, we are hostboot and this is an FSP target, or vice-versa
                // Binary trace the iv_targetId (EntityPath)
                HWAS_INF_BIN("Could not find Target for:",
                             &(l_gardRecord.iv_targetId),
                             sizeof(l_gardRecord.iv_targetId));
                continue;
            }

            // if this does NOT match, continue to next in loop
            if (i_pPredicate && ((*i_pPredicate)(l_pTarget) == false))
            {
                HWAS_INF("skipping %.8X - predicate didn't match",
                        get_huid(l_pTarget));
                continue;
            }

            // Since all GARD records have already been processed, if we find
            // any target that is functional, it means it has been resource
            // recovered. Update it's HWAS state to reflect this
            TARGETING::HwasState l_hwasState =
                    l_pTarget->getAttr<TARGETING::ATTR_HWAS_STATE>();
            if(l_hwasState.functional)
            {
                HWAS_INF("Found GARDED target 0x%08X is functional, set state",
                        TARGETING::get_huid(l_pTarget));
                l_hwasState.deconfiguredByEid =
                        DeconfigGard::CONFIGURED_BY_RESOURCE_RECOVERY;
                l_pTarget->setAttr<TARGETING::ATTR_HWAS_STATE>(l_hwasState);
            }
        }
    }while (0);

    return l_pErr;
}

//******************************************************************************
errlHndl_t DeconfigGard::deconfigureTargetsFromGardRecordsForIpl(
        const PredicateBase *i_pPredicate)
{
    HWAS_INF("Deconfigure Targets from GARD Records for IPL");
    errlHndl_t l_pErr = NULL;

    do
    {
        Target* pSys;
        targetService().getTopLevelTarget(pSys);
        HWAS_ASSERT(pSys, "HWAS deconfigTargetsFromGardRecordsForIpl: no TopLevelTarget");

        // check for system CDM Policy
        const ATTR_CDM_POLICIES_type l_sys_policy =
                pSys->getAttr<ATTR_CDM_POLICIES>();
        if (l_sys_policy & CDM_POLICIES_MANUFACTURING_DISABLED)
        {
            // manufacturing records are disabled
            //  - don't process
            HWAS_INF("Manufacturing policy: disabled - skipping GARD Records");
            l_pErr = platLogEvent(NULL, MFG);
            if (l_pErr)
            {
                HWAS_ERR("platLogEvent returned an error");
            }
            break;
        }

        // Get all GARD Records
        GardRecords_t l_gardRecords;
        l_pErr = platGetGardRecords(NULL, l_gardRecords);
        if (l_pErr)
        {
            HWAS_ERR("Error from platGetGardRecords");
            break;
        }

        HWAS_DBG("%d GARD Records found", l_gardRecords.size());

        std::vector<uint32_t> errlLogEidList;
        //First apply all Unrecoverable or Fatal gard records and
        //check whether system is bootable, if not bootable
        //exit from this funtion or try to apply remaining records
        for (GardRecordsCItr_t l_itr = l_gardRecords.begin();
             l_itr != l_gardRecords.end();
             ++l_itr)
        {
            GardRecord l_gardRecord = *l_itr;

            //Continue only with FATAL/UNRECOVERABLE gard errors.
            if((l_gardRecord.iv_errorType != GARD_Fatal)&&
               (l_gardRecord.iv_errorType != GARD_Unrecoverable))
            {
                //Skip recoverable gard records
                continue;
            }
            // Find the associated Target
            Target * l_pTarget =
                targetService().toTarget(l_gardRecord.iv_targetId);

            if (l_pTarget == NULL)
            {
                // could be a platform specific target for the other
                // ie, we are hostboot and this is an FSP target, or vice-versa
                // Binary trace the iv_targetId (EntityPath)
                HWAS_INF_BIN("Could not find Target for:",
                             &(l_gardRecord.iv_targetId),
                             sizeof(l_gardRecord.iv_targetId));
                continue;
            }

            // if this does NOT match, continue to next in loop
            if (i_pPredicate && ((*i_pPredicate)(l_pTarget) == false))
            {
                HWAS_INF("skipping %.8X - predicate didn't match",
                        get_huid(l_pTarget));
                l_pErr = platLogEvent(l_pTarget, PREDICATE);
                if (l_pErr)
                {
                    HWAS_ERR("platLogEvent returned an error");
                    break;
                }
                continue;
            }
            l_pErr = applyGardRecord(l_pTarget, l_gardRecord);
            if (l_pErr)
            {
                HWAS_ERR("applyGardRecord returned an error");
                break;
            }
            uint32_t l_errlogEid = l_gardRecord.iv_errlogEid;
            //If the errlogEid is already in the errLogEidList, then
            //don't need to log it again as a single error log can
            //create multiple guard records and we only need to repost
            //it once.
            std::vector<uint32_t>::iterator low =
                    std::lower_bound(errlLogEidList.begin(),
                    errlLogEidList.end(), l_errlogEid);
            if((low == errlLogEidList.end()) || ((*low) != l_errlogEid))
            {
                errlLogEidList.insert(low, l_errlogEid);
                l_pErr = platReLogGardError(l_gardRecord);
                if (l_pErr)
                {
                    HWAS_ERR("platReLogGardError returned an error");
                    break;
                }
            }

#if (!defined(CONFIG_CONSOLE_OUTPUT_TRACE) && defined(CONFIG_CONSOLE))
            CONSOLE::displayf("HWAS", "Deconfig HUID 0x%08X, %s",
                    get_huid(l_pTarget),
                    l_pTarget->getAttr<TARGETING::ATTR_PHYS_PATH>().toString());
#endif
        } // for

        if (l_pErr)
        {
            break;
        }

        bool l_isSystemBootable = false;
        l_pErr = checkMinimumHardware(pSys,&l_isSystemBootable);
        if (l_pErr)
        {
            HWAS_ERR("checkMinimumHardware returned an error");
            break;
        }

        if(!l_isSystemBootable)
        {
            //Break here system is not bootable after applying
            //non recoverable gard records.
            HWAS_ERR("System is not bootable after applying gard record");
            break;
        }

        // If any targets have been replaced, clear Block Spec Deconfig
        TARGETING::ATTR_BLOCK_SPEC_DECONFIG_type l_block_spec_deconfig =
            DeconfigGard::clearBlockSpecDeconfigForReplacedTargets();

        l_pErr =
            clearBlockSpecDeconfigForUngardedTargets(l_block_spec_deconfig);
        if (l_pErr)
        {
            HWAS_ERR("clearBlockSpecDeconfigForUngardedTargets returned an "
                     "error");
            break;
        }

        if(l_block_spec_deconfig != 0)
        {
#if (!defined(CONFIG_CONSOLE_OUTPUT_TRACE) && defined(CONFIG_CONSOLE))
            CONSOLE::displayf("HWAS", "Blocking Speculative Deconfig");
#endif
            HWAS_INF("Blocking Speculative Deconfig: skipping Predictive GARD "
                     " and updating recovered resources");

            l_pErr = updateSpecDeconfigTargetStates(i_pPredicate);
            if(l_pErr)
            {
                HWAS_ERR("updateSpecDeconfigTargetStates returned an error");
                break;
            }
        }

        GardRecords_t l_specDeconfigVector;

        //If allowed, that is if Block Spec Deconfig is cleared,
        //loop through all gard records and apply recoverable
        //gard records(non Fatal and non Unrecoverable).  Check
        //whether system can be booted after applying all gard
        //records.  If system can't be booted after applying gard
        //records, then need to rolled them back.
        for (GardRecordsCItr_t l_itr = l_gardRecords.begin();
             (l_block_spec_deconfig == 0) && (l_itr != l_gardRecords.end());
             ++l_itr)
        {
            GardRecord l_gardRecord = *l_itr;
            // Find the associated Target
            Target * l_pTarget =
                targetService().toTarget(l_gardRecord.iv_targetId);

            if (l_pTarget == NULL)
            {
                // could be a platform specific target for the other
                // ie, we are hostboot and this is an FSP target, or vice-versa
                // Binary trace the iv_targetId (EntityPath)
                HWAS_INF_BIN("Could not find Target for:",
                             &(l_gardRecord.iv_targetId),
                             sizeof(l_gardRecord.iv_targetId));
                continue;
            }
            if ((l_sys_policy & CDM_POLICIES_PREDICTIVE_DISABLED) &&
                (l_gardRecord.iv_errorType == GARD_Predictive))
            {
                // predictive records are disabled AND gard record is predictive
                //  - don't process
                HWAS_INF("Predictive policy: disabled - skipping GARD Record");
                l_pErr = platLogEvent(l_pTarget, PREDICTIVE);
                if (l_pErr)
                {
                    HWAS_ERR("platLogEvent returned an error");
                    break;
                }
                continue;
            }
            //Continue only with recoverable gard errors.
            if((l_gardRecord.iv_errorType == GARD_Fatal)||
               (l_gardRecord.iv_errorType == GARD_Unrecoverable))
            {
                //Skip non-recoverable gard records
                continue;
            }

            // if this does NOT match, continue to next in loop
            if (i_pPredicate && ((*i_pPredicate)(l_pTarget) == false))
            {
                HWAS_INF("skipping %.8X - predicate didn't match",
                        get_huid(l_pTarget));
                l_pErr = platLogEvent(l_pTarget, PREDICATE);
                if (l_pErr)
                {
                    HWAS_ERR("platLogEvent returned an error");
                    break;
                }
                continue;
            }

            //Apply the gard record.
            l_pErr = applyGardRecord(l_pTarget, l_gardRecord, SPEC_DECONFIG);
            if (l_pErr)
            {
                HWAS_ERR("applyGardRecord returned an error");
                break;
            }
            else
            {
                // Keep track of spec deconfig gard record
                l_specDeconfigVector.push_back(l_gardRecord);
            }
        } // for

        if(l_pErr)
        {
            break;
        }

        l_pErr = checkMinimumHardware(pSys,&l_isSystemBootable);
        if (l_pErr)
        {
            HWAS_ERR("checkMinimumHardware returned an error");
            break;
        }

        if(!l_isSystemBootable)
        {
            HWAS_INF("System cannot ipl, rolling back the gard for "
                     "speculatively deconfigured targets");

            const uint64_t userdata1 = l_specDeconfigVector.size();
            const uint64_t userdata2 = 0;
            /*@
             * @errortype
             * @severity          ERRL_SEV_INFORMATIONAL
             * @moduleid          MOD_DECONFIG_TARGETS_FROM_GARD
             * @reasoncode        RC_RESOURCE_RECOVERED
             * @devdesc           Gard record(s) not applied due to a
             *                    lack of resources.
             * @custdesc          A previously discovered hardware issue is
             *                    being ignored to allow the system to boot.
             * @userdata1         Number of gard records not applied
             * @userdata2         0
             */

            l_pErr = hwasError(ERRL_SEV_INFORMATIONAL,
                               MOD_DECONFIG_TARGETS_FROM_GARD,
                               RC_RESOURCE_RECOVERED,
                               userdata1,
                               userdata2);
            errlCommit(l_pErr, HWAS_COMP_ID);

            //Now go through all targets which are speculatively
            //deconfigured and roll back gard on them.
            PredicateHwas predSpecDeconfig;
            predSpecDeconfig.specdeconfig(true);
            TargetHandleList l_specDeconfgList;
            targetService().getAssociated(l_specDeconfgList, pSys,
                            TargetService::CHILD, TargetService::ALL,
                            &predSpecDeconfig);

            //Loop through gard records where spec deconfig was applied
            for (TargetHandleList::const_iterator
                 l_sdIter = l_specDeconfgList.begin();
                 l_sdIter != l_specDeconfgList.end();
                 ++l_sdIter)
            {
                HwasState l_state = (*l_sdIter)->getAttr<ATTR_HWAS_STATE>();
                l_state.deconfiguredByEid = CONFIGURED_BY_RESOURCE_RECOVERY;
                l_state.specdeconfig = 0;
                (*l_sdIter)->setAttr<ATTR_HWAS_STATE>(l_state);

                //Mark parent node as resource recovered
                PredicateCTM predNode(CLASS_ENC, TYPE_NODE);
                PredicateHwas predFunctional;
                predFunctional.functional(true);
                PredicatePostfixExpr nodeCheckExpr;
                nodeCheckExpr.push(&predNode).push(&predFunctional).And();

                TargetHandleList pNodeList;
                targetService().getAssociated(pNodeList, *l_sdIter,
                                TargetService::PARENT, TargetService::ALL,
                                &nodeCheckExpr);
                if(!pNodeList.empty())
                {
                    HwasState l_state =
                            pNodeList[0]->getAttr<ATTR_HWAS_STATE>();
                    l_state.deconfiguredByEid =
                            CONFIGURED_BY_RESOURCE_RECOVERY;
                    pNodeList[0]->setAttr<ATTR_HWAS_STATE>(l_state);
                }
            } // for

            //After recovery go through all recovered gard records and
            //log an event.
            for (GardRecordsCItr_t l_itr = l_specDeconfigVector.begin();
                 l_itr != l_specDeconfigVector.end();
                 ++l_itr)
            {
                Target * l_pTarget =
                   targetService().toTarget((*l_itr).iv_targetId);

                l_pErr = platLogEvent(l_pTarget, RESOURCE_RECOVERED);
                if (l_pErr)
                {
                    HWAS_ERR("platLogEvent returned an error");
                    break;
                }
            } // for
        }
        else
        {
            //Loop through gard records where spec deconfig was applied
            while(!l_specDeconfigVector.empty())
            {
                // Get gard record and associated target
                GardRecord l_gardRecord = l_specDeconfigVector.front();
                Target * l_pTarget =
                    targetService().toTarget(l_gardRecord.iv_targetId);

                //Apply the gard record.
                l_pErr = applyGardRecord(l_pTarget, l_gardRecord);
                if (l_pErr)
                {
                    HWAS_ERR("applyGardRecord returned an error");
                    break;
                }

                uint32_t l_errlogEid = l_gardRecord.iv_errlogEid;
                //If the errlogEid is already in the errLogEidList, then
                //don't need to log it again as a single error log can
                //create multiple guard records and we only need to repost
                //it once.
                std::vector<uint32_t>::iterator low =
                        std::lower_bound(errlLogEidList.begin(),
                        errlLogEidList.end(), l_errlogEid);
                if((low == errlLogEidList.end()) || ((*low) != l_errlogEid))
                {
                    errlLogEidList.insert(low, l_errlogEid);
                    l_pErr = platReLogGardError(l_gardRecord);
                    if (l_pErr)
                    {
                        HWAS_ERR("platReLogGardError returned an error");
                        break;
                    }
                }

#if (!defined(CONFIG_CONSOLE_OUTPUT_TRACE) && defined(CONFIG_CONSOLE))
                CONSOLE::displayf("HWAS", "Deconfig HUID 0x%08X, %s",
                    get_huid(l_pTarget),
                    l_pTarget->getAttr<TARGETING::ATTR_PHYS_PATH>().toString());
#endif

                l_specDeconfigVector.erase(l_specDeconfigVector.begin());
            } // while
        }

        if (iv_XAOBusEndpointDeconfigured)
        {
            // Check if Abus deconfigures should be considered in algorithm
            bool l_doAbusDeconfig = pSys->getAttr<ATTR_DO_ABUS_DECONFIG>();

            // Get all functional nodes
            TargetHandleList l_funcNodes;
            getEncResources(l_funcNodes, TYPE_NODE, UTIL_FILTER_FUNCTIONAL);

            for (TargetHandleList::const_iterator
                 l_nodesIter = l_funcNodes.begin();
                 l_nodesIter != l_funcNodes.end();
                 ++l_nodesIter)
            {
                l_pErr = _invokeDeconfigureAssocProc(*l_nodesIter,
                                                      l_doAbusDeconfig);
                if (l_pErr)
                {
                    HWAS_ERR("Error from _invokeDeconfigureAssocProc");
                    break;
                }
                // Set for deconfigure algorithm to run on every node even if
                // no buses deconfigured (needed for multi-node systems)
                setXAOBusEndpointDeconfigured(true);
            }
            setXAOBusEndpointDeconfigured(false);
        }
    }
    while (0);

    return l_pErr;
} // deconfigureTargetsFromGardRecordsForIpl

void DeconfigGard::clearFcoDeconfigures()
{
    // Get top level target
    Target* pSys = nullptr;
    targetService().getTopLevelTarget(pSys);
    HWAS_ASSERT(pSys!=nullptr,"Top level target was nullptr");

    // Find all the nodes below it
    PredicateCTM isNode(CLASS_ENC, TYPE_NODE);
    PredicateHwas isFunctional;
    isFunctional.functional(true);
    PredicatePostfixExpr isFunctionalNode;
    isFunctionalNode.push(&isNode).push(&isFunctional).And();

    TargetHandleList nodeHandleList;
    targetService().getAssociated(nodeHandleList, pSys,
                    TargetService::CHILD, TargetService::IMMEDIATE,
                    &isFunctionalNode);

    // Clear the FCO deconfigures for each one
    for(auto const& pNode : nodeHandleList)
    {
        _clearFCODeconfigure(pNode);
    }
}

//******************************************************************************
errlHndl_t DeconfigGard::processFieldCoreOverride()
{
    HWAS_DBG("Process Field Core Override FCO");
    errlHndl_t l_pErr = NULL;

    do
    {
        // otherwise, process and reduce cores.
        // find all functional NODE targets
        Target* pSys;
        targetService().getTopLevelTarget(pSys);
        PredicateCTM predNode(CLASS_ENC, TYPE_NODE);
        PredicateHwas predFunctional;
        predFunctional.functional(true);
        PredicatePostfixExpr nodeCheckExpr;
        nodeCheckExpr.push(&predNode).push(&predFunctional).And();

        TargetHandleList pNodeList;
        targetService().getAssociated(pNodeList, pSys,
                        TargetService::CHILD, TargetService::IMMEDIATE,
                        &nodeCheckExpr);

        // sort the list by ATTR_HUID to ensure that we
        //  start at the same place each time
        std::sort(pNodeList.begin(), pNodeList.end(),
                    compareTargetHuid);

        // for each of the nodes
        for (TargetHandleList::const_iterator
                pNode_it = pNodeList.begin();
                pNode_it != pNodeList.end();
                ++pNode_it
            )
        {
            const TargetHandle_t pNode = *pNode_it;

            // Get FCO value
            uint32_t l_fco = 0;
            l_pErr = platGetFCO(pNode, l_fco);
            if (l_pErr)
            {
                HWAS_ERR("Error from platGetFCO");
                break;
            }

            // FCO of 0 means no overrides for this node
            if (l_fco == 0)
            {
                HWAS_INF("FCO: node %.8X: no overrides, done.",
                        get_huid(pNode));
                continue; // next node
            }
            else if (is_fused_mode())
            {
                l_fco += l_fco;
                HWAS_INF("FCO: node %.8X: Doubling EC count in fused_mode. "
                         "l_fco=0x%X", get_huid(pNode), l_fco);
            }
            else
            {
                HWAS_INF("FCO: node %.8X: value %d",
                         get_huid(pNode), l_fco);
            }

            // find all functional child PROC targets
            TargetHandleList pProcList;
            getChildAffinityTargets(pProcList, pNode,
                    CLASS_CHIP, TYPE_PROC, true);

            // sort the list by ATTR_HUID to ensure that we
            //  start at the same place each time
            std::sort(pProcList.begin(), pProcList.end(),
                    compareTargetHuid);

            // create list for restrictECunits() function
            procRestrict_t l_procEntry;
            std::vector <procRestrict_t> l_procRestrictList;
            for (TargetHandleList::const_iterator
                    pProc_it = pProcList.begin();
                    pProc_it != pProcList.end();
                    ++pProc_it
                )
            {
                const TargetHandle_t pProc = *pProc_it;

                // save info so that we can
                //  restrict the number of EC units
                HWAS_DBG("pProc %.8X - pushing to proclist",
                    get_huid(pProc));
                l_procEntry.target = pProc;
                l_procEntry.group = 0;
                l_procEntry.procs = pProcList.size();
                l_procEntry.maxECs = l_fco;
                l_procRestrictList.push_back(l_procEntry);
            } // for pProc_it

            // restrict the EC units; units turned off are marked
            //  present=true, functional=false, and marked with the
            //  appropriate deconfigure code.
            HWAS_INF("FCO: calling restrictECunits with %d entries",
                    l_procRestrictList.size());
            l_pErr = restrictECunits(l_procRestrictList,
                        true, DECONFIGURED_BY_FIELD_CORE_OVERRIDE);
            if (l_pErr)
            {
                break;
            }
        } // for pNode_it
    }
    while (0);

    return l_pErr;
}

//******************************************************************************
errlHndl_t DeconfigGard::clearGardRecords(
    const Target * const i_pTarget)
{
    errlHndl_t l_pErr = platClearGardRecords(i_pTarget);
    return l_pErr;
}

//******************************************************************************
errlHndl_t DeconfigGard::getGardRecords(
    const Target * const i_pTarget,
    GardRecords_t & o_records)
{
    errlHndl_t l_pErr = platGetGardRecords(i_pTarget, o_records);
    return l_pErr;
}
#endif //__HOSTBOOT_RUNTIME

//******************************************************************************
errlHndl_t DeconfigGard::deconfigureTarget(
        Target & i_target,
        const uint32_t i_errlEid,
        bool *o_targetDeconfigured,
        const DeconfigureFlags i_deconfigRule)
{
    HWAS_DBG("Deconfigure Target");
    errlHndl_t l_pErr = NULL;

    do
    {
        // Do not deconfig Target if we're NOT being asked to force AND
        // the System is at runtime
        if ((i_deconfigRule == NOT_AT_RUNTIME) &&
                platSystemIsAtRuntime())
        {
            HWAS_INF("Skipping deconfigureTarget: at Runtime; target %.8X",
                get_huid(&i_target));
            break;
        }

        // just to make sure that we haven't missed anything in development
        //  AT RUNTIME: we should only be called to deconfigure these types.
        if (i_deconfigRule != NOT_AT_RUNTIME)
        {
            TYPE target_type = i_target.getAttr<ATTR_TYPE>();
            // TODO RTC 88471: use attribute vs hardcoded list.
            if (!((target_type == TYPE_MEMBUF) ||
                  (target_type == TYPE_NX) ||
                  (target_type == TYPE_EQ) ||
                  (target_type == TYPE_EX) ||
                  (target_type == TYPE_CORE) ||
                  (target_type == TYPE_PORE)))
            {
                HWAS_INF("Skipping deconfigureTarget: atRuntime with unexpected target %.8X type %d -- SKIPPING",
                    get_huid(&i_target), target_type);
                break;
            }
        }

        const ATTR_DECONFIG_GARDABLE_type lDeconfigGardable =
                i_target.getAttr<ATTR_DECONFIG_GARDABLE>();
        const uint8_t lPresent =
                i_target.getAttr<ATTR_HWAS_STATE>().present;
        if (!lDeconfigGardable || !lPresent)
        {
            // Target is not Deconfigurable. Create an error
            HWAS_ERR("Target %.8X not Deconfigurable (ATTR_DECONFIG_GARDABLE=%d, present=%d)",
                get_huid(&i_target), lDeconfigGardable, lPresent);

            /*@
             * @errortype
             * @moduleid          HWAS::MOD_DECONFIG_GARD
             * @reasoncode        HWAS::RC_TARGET_NOT_DECONFIGURABLE
             * @devdesc           Attempt to deconfigure a target that is not
             *                    deconfigurable or not present.
             * @userdata1[00:31]  HUID of input target
             * @userdata1[32:63]  GARD errlog EID
             * @userdata2[00:31]  ATTR_DECONFIG_GARDABLE
             * @userdata2[32:63]  ATTR_HWAS_STATE.present

             */
            const uint64_t userdata1 =
                (static_cast<uint64_t>(get_huid(&i_target)) << 32) | i_errlEid;
            const uint64_t userdata2 =
                (static_cast<uint64_t>(lDeconfigGardable) << 32) | lPresent;
            l_pErr = hwasError(
                ERRL_SEV_INFORMATIONAL,
                HWAS::MOD_DECONFIG_GARD,
                HWAS::RC_TARGET_NOT_DECONFIGURABLE,
                userdata1, userdata2);
            break;
        }

        // all ok - do the work
        HWAS_MUTEX_LOCK(iv_mutex);

        // Deconfigure the Target
        _deconfigureTarget(i_target, i_errlEid, o_targetDeconfigured,
                i_deconfigRule);

        // Deconfigure other Targets by association
        _deconfigureByAssoc(i_target, i_errlEid, i_deconfigRule);

        HWAS_MUTEX_UNLOCK(iv_mutex);
    }
    while (0);

    return l_pErr;
} // deconfigureTarget

#ifndef __HOSTBOOT_RUNTIME
//******************************************************************************
void DeconfigGard::registerDeferredDeconfigure(
        const Target & i_target,
        const uint32_t i_errlEid)
{
    HWAS_INF("registerDeferredDeconfigure Target %.8X, errlEid 0x%X",
            get_huid(&i_target), i_errlEid);

    // Create a Deconfigure Record
    HWAS_MUTEX_LOCK(iv_mutex);

    _createDeconfigureRecord(i_target, i_errlEid);

    HWAS_MUTEX_UNLOCK(iv_mutex);
}

//******************************************************************************
errlHndl_t DeconfigGard::_getDeconfigureRecords(
    const Target * const i_pTarget,
    DeconfigureRecords_t & o_records)
{
    HWAS_DBG("Get Deconfigure Record(s)");
    o_records.clear();

    HWAS_MUTEX_LOCK(iv_mutex);
    DeconfigureRecordsCItr_t l_itr = iv_deconfigureRecords.begin();

    if (i_pTarget == NULL)
    {
        HWAS_INF("Getting all %d Deconfigure Records",
                 iv_deconfigureRecords.size());

        for (; l_itr != iv_deconfigureRecords.end(); ++l_itr)
        {
            o_records.push_back(*l_itr);
        }
    }
    else
    {
        // Look for a Deconfigure Record for the specified Target (there can
        // only be one record)
        for (; l_itr != iv_deconfigureRecords.end(); ++l_itr)
        {
            if ((*l_itr).iv_target == i_pTarget)
            {
                HWAS_INF("Getting Deconfigure Record for %.8X",
                               get_huid(i_pTarget));
                o_records.push_back(*l_itr);
                break;
            }
        }

        if (l_itr == iv_deconfigureRecords.end())
        {
            HWAS_INF("Did not find a Deconfigure Record for %.8X",
                           get_huid(i_pTarget));
        }
    }

    HWAS_MUTEX_UNLOCK(iv_mutex);
    return NULL;
}
#endif //__HOSTBOOT_RUNTIME

//******************************************************************************
/**
 * @brief       simple helper fn to find and return the MCS which is paired to
 *              the input MCS
 *
 * @param[in]   i_startMcs      pointer to starting MCS target
 *
 * @return      Target          Pointer to Partner MCS of i_startMcs
 *
 */
Target * findPartnerForMcs(const Target *i_startMcs)
{
    // Get CHIP_UNIT of the input MCS (0..7)
    const ATTR_CHIP_UNIT_type startMcsUnit = i_startMcs->getAttr<ATTR_CHIP_UNIT>();
    // Declare partner MCS CHIP_UNIT
    ATTR_CHIP_UNIT_type partnerMcsUnit = 0;

    // If CHIP_UNIT is even, its partner will be the next MCS
    if (!(startMcsUnit % 2))
    {
        partnerMcsUnit = startMcsUnit + 1;
    }
    // else, partner will be the previous MCS
    else
    {
        partnerMcsUnit = startMcsUnit - 1;
    }

    // Get parent proc of i_startMcs to get other child MCSs
    const Target *l_proc = getParentChip(i_startMcs);
    HWAS_INF("findPartnerForMcs MCS %.8X (%d) under proc %.8X",
                 get_huid(i_startMcs), startMcsUnit, get_huid(l_proc));

    // Retrieve MCS target whose CHIP_UNIT matches partnerMcsUnit
    TargetHandleList l_funcMcsList;
    PredicateCTM predMcs(CLASS_UNIT, TYPE_MCS);
    PredicateIsFunctional isFunctional;
    PredicateAttrVal<ATTR_CHIP_UNIT> unitPosAttr(partnerMcsUnit);
    PredicatePostfixExpr checkExpr;
    checkExpr.push(&predMcs).push(&isFunctional).
              push(&unitPosAttr).And().And();
    targetService().getAssociated(l_funcMcsList, l_proc,
        TargetService::CHILD_BY_AFFINITY, TargetService::IMMEDIATE,
        &checkExpr);

    // List should either be empty or contain one element
    HWAS_ASSERT((l_funcMcsList.size() <= 1),
        "HWAS _deconfigureByAssoc: pParentMcsList > 1");

    // If no partner found (partner MCS already deconfigured)
    if (l_funcMcsList.empty())
    {
        HWAS_INF("findPartnerMcs: Partner for MCS %.8X was not found in"
                 " functional list. Returning NULL",
                 get_huid(i_startMcs));
        return NULL;
    }
    else
    {
        HWAS_INF("findPartnerForMcs found partner: MCS %.8X (%d)",
                 get_huid(l_funcMcsList[0]),
                 l_funcMcsList[0]->getAttr<ATTR_CHIP_UNIT>());
        return l_funcMcsList[0];
    }
} // findPartnerForMcs

//******************************************************************************

errlHndl_t DeconfigGard::deconfigureAssocProc()
{
    HWAS_INF("Deconfiguring chip resources "
             "based on fabric bus deconfigurations");

    HWAS_MUTEX_LOCK(iv_mutex);
    // call _invokeDeconfigureAssocProc() to obtain state of system,
    // call algorithm function, and then deconfigure targets
    // based on output
    errlHndl_t l_pErr = _invokeDeconfigureAssocProc();
    HWAS_MUTEX_UNLOCK(iv_mutex);
    return l_pErr;
}

//******************************************************************************
errlHndl_t DeconfigGard::_invokeDeconfigureAssocProc(
            TARGETING::ConstTargetHandle_t i_node,
            bool i_doAbusDeconfig)
{
    HWAS_INF("Preparing data for _deconfigureAssocProc");
    // Return error
    errlHndl_t l_pErr = NULL;

    // Define vector of ProcInfo structs to be used by
    // _deconfigAssocProc algorithm. Declared here so
    // "delete" can be used outside of do {...} while(0)
    ProcInfoVector l_procInfo;

    do
    {
        // If flag indicating deconfigured bus endpoints is not set,
        // then there's no work for _invokeDeconfigureAssocProc to do
        // as this implies there are no deconfigured endpoints or
        // processors.
        if (!(iv_XAOBusEndpointDeconfigured))
        {
            HWAS_INF("_invokeDeconfigureAssocProc: No deconfigured x/a/o"
                     " bus endpoints. Deconfiguration of "
                     "associated procs unnecessary.");
            break;
        }

        // Clear flag as this function is called multiple times
        iv_XAOBusEndpointDeconfigured = false;

        // Get top 'starting' level target - use top level target if no
        // i_node given (hostboot)
        Target *pTop;
        if (i_node == NULL)
        {
            HWAS_INF("_invokeDeconfigureAssocProc: i_node not specified");
            targetService().getTopLevelTarget(pTop);
            HWAS_ASSERT(pTop, "_invokeDeconfigureAssocProc: no TopLevelTarget");
        }
        else
        {
            HWAS_INF("_invokeDeconfigureAssocProc: i_node 0x%X specified",
                     i_node->getAttr<ATTR_HUID>());
            pTop = const_cast<Target *>(i_node);
        }

        // Define and populate vector of procs
        // Define predicate
        PredicateCTM predProc(CLASS_CHIP, TYPE_PROC);
        PredicateHwas predPres;
        predPres.present(true);

        // Populate vector
        TargetHandleList l_procs;
        targetService().getAssociated(l_procs,
                                      pTop,
                                      TargetService::CHILD,
                                      TargetService::ALL,
                                      &predProc);

        // Sort by HUID
        std::sort(l_procs.begin(),
                  l_procs.end(), compareTargetHuid);

        // General predicate to determine if target is functional
        PredicateIsFunctional isFunctional;

        // Define and populate vector of present A bus endpoint chiplets and
        // all X bus endpoint chiplets
        PredicateCTM predXbus(CLASS_UNIT, TYPE_XBUS);
        PredicateCTM predAbus(CLASS_UNIT, TYPE_ABUS);
        PredicatePostfixExpr busses;
        busses.push(&predAbus).push(&predPres).And().push(&predXbus).Or();

        // Iterate through procs and populate l_procInfo vector with system
        // information regarding procs to be used by _deconfigAssocProc
        // algorithm.
        ProcInfoVector l_procInfo;
        for (TargetHandleList::const_iterator
             l_procsIter = l_procs.begin();
             l_procsIter != l_procs.end();
             ++l_procsIter)
        {
            ProcInfo l_ProcInfo = ProcInfo();
            // Iterate through present procs and populate structs in l_procInfo
            // Target pointer
            l_ProcInfo.iv_pThisProc =
                *l_procsIter;
            // HUID
            l_ProcInfo.procHUID =
                (*l_procsIter)->getAttr<ATTR_HUID>();
            // FABRIC_GROUP_ID
            l_ProcInfo.procFabricGroup =
                (*l_procsIter)->getAttr<ATTR_FABRIC_GROUP_ID>();
            // FABRIC_CHIP_ID
            l_ProcInfo.procFabricChip =
                (*l_procsIter)->getAttr<ATTR_FABRIC_CHIP_ID>();
            // HWAS state
            l_ProcInfo.iv_deconfigured =
                !(isFunctional(*l_procsIter));
            // iv_masterCapable - this includes both master and alternate master
            // This is done to ensure that both the master and alt master don't
            // get deconfigured in _deconfigAssocProc()
            if ( (*l_procsIter)->getAttr<ATTR_PROC_MASTER_TYPE>() ==
                 PROC_MASTER_TYPE_NOT_MASTER)
            {
                l_ProcInfo.iv_masterCapable = false;
            }
            else
            {
                l_ProcInfo.iv_masterCapable = true;
            }
            HWAS_INF( "_invokeDeconfigureAssocProc> %.8X : G=%d, C=%d, D=%d, M=%d", l_ProcInfo.procHUID, l_ProcInfo.procFabricGroup, l_ProcInfo.procFabricChip, l_ProcInfo.iv_deconfigured, l_ProcInfo.iv_masterCapable );
            l_procInfo.push_back(l_ProcInfo);
        }
        HWAS_INF("----------------------------------------------------------");
        // Iterate through l_procInfo and populate child bus endpoint
        // chiplet information
        for (ProcInfoVector::iterator
             l_procInfoIter = l_procInfo.begin();
             l_procInfoIter != l_procInfo.end();
             ++l_procInfoIter)
        {
            // Populate vector of bus endpoints associated with this proc
            TargetHandleList l_busChiplets;
            targetService().getAssociated(l_busChiplets,
                                         (*l_procInfoIter).iv_pThisProc,
                                         TargetService::CHILD,
                                         TargetService::IMMEDIATE,
                                         &busses);
            // Sort by HUID
            std::sort(l_busChiplets.begin(),
                l_busChiplets.end(), compareTargetHuid);
            // iv_pA/XProcs[] and iv_A/XDeconfigured[] indexes
            uint8_t xBusIndex = 0;
            uint8_t aBusIndex = 0;

            // Iterate through bus endpoint chiplets
            for (TargetHandleList::const_iterator
                 l_busIter = l_busChiplets.begin();
                 l_busIter != l_busChiplets.end();
                 ++l_busIter)
            {
                // Declare peer endpoint target
                const Target * l_pTarget = *l_busIter;
                // Get peer endpoint target
                const Target * l_pDstTarget = l_pTarget->
                              getAttr<ATTR_PEER_TARGET>();
                // Only interested in endpoint chiplets which lead to a
                // present proc:
                // If no peer for this endpoint or peer endpoint
                // is not present, continue
                if ((!l_pDstTarget) ||
                    (!(l_pDstTarget->getAttr<ATTR_HWAS_STATE>().present)))
                {
                    if (l_pDstTarget == nullptr)
                    {
                      HWAS_INF("Proc %.8X Skipping non-peer endpt of BUS %.8X",
                        get_huid((*l_procInfoIter).iv_pThisProc),
                        l_pTarget->getAttr<ATTR_HUID>());
                    }
                    else
                    {
                      HWAS_INF("Proc %.8X Skipping non-present endpt target %.8X of %.8X BUS",
                          get_huid((*l_procInfoIter).iv_pThisProc),
                          l_pDstTarget->getAttr<ATTR_HUID>(),
                          l_pTarget->getAttr<ATTR_HUID>());
                    }

                    continue;
                }

                // Chiplet has a valid (present) peer
                // Handle iv_pA/XProcs[]:
                // Define target for peer proc
                const Target* l_pPeerProcTarget;
                // Get parent chip from xbus chiplet
                l_pPeerProcTarget = getParentChip(l_pDstTarget);

                // Find matching ProcInfo struct
                for (ProcInfoVector::iterator
                     l_matchProcInfoIter = l_procInfo.begin();
                     l_matchProcInfoIter != l_procInfo.end();
                     ++l_matchProcInfoIter)
                {
                    // If Peer proc target matches this ProcInfo struct's
                    // Identifier target
                    if (l_pPeerProcTarget ==
                        (*l_matchProcInfoIter).iv_pThisProc)
                    {
                        // Update struct of current proc to point to this
                        // struct, and also handle iv_A/XDeconfigured[]
                        // and increment appropriate index:
                        if (TYPE_XBUS == (*l_busIter)->getAttr<ATTR_TYPE>())
                        {
                            (*l_procInfoIter).iv_pXProcs[xBusIndex] =
                                &(*l_matchProcInfoIter);
                            // HWAS state
                            (*l_procInfoIter).iv_XDeconfigured[xBusIndex] =
                                !(isFunctional(*l_busIter));
                            HWAS_INF( "%.8X add X[%d]> %.8X : G=%d, C=%d, D=%d, M=%d", (*l_procInfoIter).procHUID, xBusIndex, (*l_matchProcInfoIter).procHUID, (*l_matchProcInfoIter).procFabricGroup, (*l_matchProcInfoIter).procFabricChip, (*l_matchProcInfoIter).iv_deconfigured, (*l_matchProcInfoIter).iv_masterCapable );
                            xBusIndex++;
                        }
                        // If subsystem owns abus deconfigs consider them
                        else if (i_doAbusDeconfig &&
                                TYPE_ABUS == (*l_busIter)->getAttr<ATTR_TYPE>())
                        {
                            (*l_procInfoIter).iv_pAProcs[aBusIndex] =
                                &(*l_matchProcInfoIter);
                            // HWAS state
                            (*l_procInfoIter).iv_ADeconfigured[aBusIndex] =
                               !(isFunctional(*l_busIter));
                            HWAS_INF( "%.8X add A[%d]> %.8X : G=%d, C=%d, D=%d, M=%d", (*l_procInfoIter).procHUID, aBusIndex, (*l_matchProcInfoIter).procHUID, (*l_matchProcInfoIter).procFabricGroup, (*l_matchProcInfoIter).procFabricChip, (*l_matchProcInfoIter).iv_deconfigured, (*l_matchProcInfoIter).iv_masterCapable );
                            aBusIndex++;
                        }
                        break;
                    }
                }
            }
        }

        // call _deconfigureAssocProc() to run deconfig algorithm
        // based on current state of system obtained above
        l_pErr = _deconfigureAssocProc(l_procInfo);
        if (l_pErr)
        {
            HWAS_ERR("Error from _deconfigureAssocProc ");
            break;
        }

        // Iterate through l_procInfo and deconfigure any procs
        // which _deconfigureAssocProc marked for deconfiguration
        for (ProcInfoVector::const_iterator
             l_procInfoIter = l_procInfo.begin();
             l_procInfoIter != l_procInfo.end();
             ++l_procInfoIter)
        {
            if ((*l_procInfoIter).iv_deconfigured &&
                (isFunctional((*l_procInfoIter).iv_pThisProc)))
            {
                // Deconfigure marked procs
                HWAS_INF("_invokeDeconfigureAssocProc is "
                                "deconfiguring proc: %.8X",
                    get_huid((*l_procInfoIter).iv_pThisProc));
                _deconfigureTarget(*(*l_procInfoIter).
                                iv_pThisProc, DECONFIGURED_BY_BUS_DECONFIG);
                _deconfigureByAssoc(*(*l_procInfoIter).
                                iv_pThisProc, DECONFIGURED_BY_BUS_DECONFIG);
            }
        }
    }while(0);

    return l_pErr;
}


//******************************************************************************
void DeconfigGard::_deconfigureByAssoc(
        Target & i_target,
        const uint32_t i_errlEid,
        const DeconfigureFlags i_deconfigRule)
{
    HWAS_INF("_deconfigureByAssoc for %.8X (i_deconfigRule %d)",
            get_huid(&i_target), i_deconfigRule);

    // some common variables used below
    TargetHandleList pChildList;
    PredicateHwas isFunctional;
    isFunctional.functional(true);
    if(i_deconfigRule == SPEC_DECONFIG)
    {
        isFunctional.specdeconfig(false);
    }

    // If there are child targets deconfig by FCO, override the reason
    // with that of the parent's deconfg EID
    PredicateHwas isFCO;
    isFCO.present(true).functional(false)
         .deconfiguredByEid(DECONFIGURED_BY_FIELD_CORE_OVERRIDE);

    PredicatePostfixExpr funcOrFco;
    funcOrFco.push(&isFunctional).push(&isFCO).Or();

    // note - ATTR_DECONFIG_GARDABLE is NOT checked for all 'by association'
    // deconfigures, as that attribute is only for direct deconfigure requests.

    // find all CHILD targets and deconfigure them
    targetService().getAssociated(pChildList, &i_target,
        TargetService::CHILD, TargetService::ALL, &funcOrFco);
    for (TargetHandleList::iterator pChild_it = pChildList.begin();
            pChild_it != pChildList.end();
            ++pChild_it)
    {
        TargetHandle_t pChild = *pChild_it;

        HWAS_INF("_deconfigureByAssoc CHILD: %.8X", get_huid(pChild));
        _deconfigureTarget(*pChild, i_errlEid, NULL,
                i_deconfigRule);
        // Deconfigure other Targets by association
        _deconfigureByAssoc(*pChild, i_errlEid, i_deconfigRule);
    } // for CHILD

    // Retrieve the target type from the given target
    TYPE l_targetType = i_target.getAttr<ATTR_TYPE>();

    if ((i_deconfigRule == NOT_AT_RUNTIME) ||
        (i_deconfigRule == SPEC_DECONFIG)  ||
        (l_targetType == TYPE_EQ)          ||
        (l_targetType == TYPE_EX)          ||
        (l_targetType == TYPE_CORE))
    {
        // if the rule is NOT_AT_RUNTIME and we got here, then we are
        // not at runtime.
        // only do these 'by association' checks if we are NOT at runtime
        // reason is, we're not really deconfigureing anything, we're just
        // marking them as non-functional. we only want to do that for the
        // desired target and it's CHILD
        // Except for target EQ, EX, CORE.  Deconfigure these regardless of the
        // runtime status


        // find all CHILD_BY_AFFINITY targets and deconfigure them
        targetService().getAssociated(pChildList, &i_target,
            TargetService::CHILD_BY_AFFINITY, TargetService::ALL,
            &funcOrFco);
        for (TargetHandleList::iterator pChild_it = pChildList.begin();
                pChild_it != pChildList.end();
                ++pChild_it)
        {
            TargetHandle_t pChild = *pChild_it;

            HWAS_INF("_deconfigureByAssoc CHILD_BY_AFFINITY: %.8X",
                    get_huid(pChild));
            _deconfigureTarget(*pChild, i_errlEid, NULL,
                    i_deconfigRule);
            // Deconfigure other Targets by association
            _deconfigureByAssoc(*pChild, i_errlEid, i_deconfigRule);
        } // for CHILD_BY_AFFINITY

        // Handles bus endpoint (TYPE_XBUS, TYPE_ABUS, TYPE_PSI) and
        // memory (TYPE_MEMBUF, TYPE_MBA, TYPE_DIMM)
        // chip  (TYPE_EQ, TYPE_EX, TYPE_CORE)
        // deconfigureByAssociation rules

        switch (l_targetType)
        {
            case TYPE_CORE:
            {
                //
                // In Fused Core Mode, Cores must be de-configureed
                // in pairs
                //
                // In Normal Core Mode if both cores are non-functional
                // EX should be deconfigured
                //
                // First get parent i.e EX
                // Other errors may have affected parent state so use
                // UTIL_FILTER_ALL
                TargetHandleList pParentExList;
                getParentAffinityTargetsByState(pParentExList, &i_target,
                        CLASS_UNIT, TYPE_EX, UTIL_FILTER_ALL);
                HWAS_ASSERT((pParentExList.size() == 1),
                    "HWAS _deconfigureByAssoc: pParentExList != 1");
                Target *l_parentEX = pParentExList[0];

                if (isFunctional(l_parentEX))
                {
                    // Fused Core Mode
                    if (is_fused_mode())
                    {
                        // If parent is functional, deconfigure it
                        _deconfigureTarget(*l_parentEX,
                           i_errlEid, NULL,i_deconfigRule);
                        _deconfigureByAssoc(*l_parentEX,
                          i_errlEid,i_deconfigRule);
                        // After deconfiguring EX the other EX of EQ
                        // is non-functional, case TYPE_EX takes care
                    }
                    // Normal Core Mode
                    // if both cores of EX non-functional, de-config EX
                    else if (!anyChildFunctional(*l_parentEX))
                    {
                       uint32_t l_errlEidOverride = i_errlEid;

                       // If any sibling is not functional due to FCO, override
                       // the deconfig by Eid reason of its parent to FCO
                       if (anyChildFCO(*l_parentEX))
                       {
                           HWAS_INF("Override EX %.8X deconfigByEid %.8X->FCO",
                                    get_huid(l_parentEX), i_errlEid);
                           l_errlEidOverride =
                                    DECONFIGURED_BY_FIELD_CORE_OVERRIDE;
                       }

                       // If parent is functional, deconfigure it
                       _deconfigureTarget(*l_parentEX,
                          l_errlEidOverride, NULL, i_deconfigRule);
                       _deconfigureByAssoc(*l_parentEX,
                          l_errlEidOverride, i_deconfigRule);
                    } // is_fused
                } // isFunctional
                break;
            } // TYPE_CORE

            case TYPE_EX:
            {
                //
                // EQ with no good EX should be de-configured
                //
                // Other errors may have affected parent state so use
                // UTIL_FILTER_ALL
                TargetHandleList pEqList;
                getParentAffinityTargetsByState(pEqList,
                        &i_target, CLASS_UNIT, TYPE_EQ,
                        UTIL_FILTER_ALL);

                HWAS_ASSERT((pEqList.size() == 1),
                    "HWAS _deconfigureByAssoc: pEqList != 1");
                Target *l_targetEq = pEqList[0];

                if (!anyChildFunctional(*l_targetEq))
                {
                    uint32_t l_errlEidOverride = i_errlEid;

                    // If any sibling is not functional due to FCO, override
                    // the deconfig by Eid reason of its parent to FCO
                    if (anyChildFCO(*l_targetEq))
                    {
                        HWAS_INF("Override EQ %.8X deconfigByEid %.8X->FCO",
                                 get_huid(l_targetEq), i_errlEid);
                        l_errlEidOverride =
                                 DECONFIGURED_BY_FIELD_CORE_OVERRIDE;
                    }

                    _deconfigureTarget(*l_targetEq, l_errlEidOverride, NULL,
                                    i_deconfigRule);
                }

                break;
            } // TYPE_EX

            case TYPE_MEMBUF:
            {
                //  get parent DMI
                TargetHandleList pParentDmiList;
                // Other errors may have affected parent state so use
                // UTIL_FILTER_ALL
                getParentAffinityTargetsByState(pParentDmiList, &i_target,
                        CLASS_UNIT, TYPE_DMI, UTIL_FILTER_ALL);
                HWAS_ASSERT((pParentDmiList.size() == 1),
                    "HWAS _deconfigureByAssoc: pParentDmiList > 1");
                const Target *l_parentDmi = pParentDmiList[0];

                // If parent is functional, deconfigure it
                if (isFunctional(l_parentDmi))
                {
                    // deconfigure the parent
                    HWAS_INF("_deconfigureByAssoc MEMBUF parent DMI: %.8X",
                        get_huid(l_parentDmi));
                    _deconfigureTarget(const_cast<Target &> (*l_parentDmi),
                        i_errlEid, NULL, i_deconfigRule);
                    _deconfigureByAssoc(const_cast<Target &> (*l_parentDmi),
                        i_errlEid, i_deconfigRule);
                }
                break;
            } // TYPE_MEMBUF

            case TYPE_MCA:
            {
                // get parent MCS
                // Other errors may have affected parent state so use
                // UTIL_FILTER_ALL
                TargetHandleList pParentMcsList;
                getParentAffinityTargetsByState(pParentMcsList, &i_target,
                                                CLASS_UNIT, TYPE_MCS,
                                                UTIL_FILTER_ALL);

                HWAS_ASSERT((pParentMcsList.size() == 1),
                "HWAS _deconfigureByAssoc: pParentMcsList != 1");

                Target *l_parentMcs = pParentMcsList[0];
                // if parent MCS hasn't already been deconfigured
                if (!pParentMcsList.empty() &&
                    isFunctional(l_parentMcs) &&
                    !anyChildFunctional(*l_parentMcs))
                {
                    // deconfigure parent MCS
                    HWAS_INF("_deconfigureByAssoc MCS parent with no functional MCAs: %.8X", get_huid(l_parentMcs));
                    _deconfigureTarget(*l_parentMcs,
                                        i_errlEid, NULL, i_deconfigRule);
                    _deconfigureByAssoc(*l_parentMcs,
                                        i_errlEid,i_deconfigRule);
                }

                // and we're done, so break;
                break;
            }

            case TYPE_MCS:
            {
                // get parent MCBIST
                // Other errors may have affected parent state so use
                // UTIL_FILTER_ALL
                TargetHandleList pParentMcbistList;
                getParentAffinityTargetsByState(pParentMcbistList, &i_target,
                                                CLASS_UNIT, TYPE_MCBIST,
                                                UTIL_FILTER_ALL);

                HWAS_ASSERT((pParentMcbistList.size() <= 1),
                            "HWAS _deconfigureByAssoc: MCS has multiple MCBIST parents, this is impossible");

                Target *l_parentMcbist = pParentMcbistList[0];

                // if parent MCBIST hasn't already been deconfigured
                if (!pParentMcbistList.empty() &&
                    isFunctional(l_parentMcbist) &&
                    !anyChildFunctional(*l_parentMcbist))
                {
                    // deconfigure parent MCBIST
                    HWAS_INF("_deconfigureByAssoc MCBIST parent with no functional children: %.8X",
                    get_huid(l_parentMcbist));
                    _deconfigureTarget(*l_parentMcbist,
                                        i_errlEid, NULL, i_deconfigRule);
                    _deconfigureByAssoc(*l_parentMcbist,
                                        i_errlEid,i_deconfigRule);
                }
                else
                {
                    HWAS_ASSERT((pParentMcbistList.size() <= 1),
                                "HWAS _deconfigureByAssoc: No MCBIST parents for for MCS w/ HUID: %lx", get_huid(&i_target));
                }
                // and we're done, so break;
                break;
            }

            case TYPE_MI:
            {
                // get parent MC
                // Other errors may have affected parent state so use
                // UTIL_FILTER_ALL
                TargetHandleList pParentMctList;
                getParentAffinityTargetsByState(pParentMctList, &i_target,
                                                CLASS_UNIT, TYPE_MC,
                                                UTIL_FILTER_ALL);

                HWAS_ASSERT((pParentMctList.size() <= 1),
                            "HWAS _deconfigureByAssoc: MI has multiple MC parents, this is impossible");

                Target *l_parentMc = pParentMctList[0];

                // if parent MC hasn't already been deconfigured
                if (!pParentMctList.empty() &&
                    isFunctional(l_parentMc) &&
                    !anyChildFunctional(*l_parentMc))
                {
                    // deconfigure parent MC
                    HWAS_INF("_deconfigureByAssoc MC parent with no functional children: %.8X",
                    get_huid(l_parentMc));
                    _deconfigureTarget(*l_parentMc,
                                        i_errlEid, NULL, i_deconfigRule);
                    _deconfigureByAssoc(*l_parentMc,
                                        i_errlEid,i_deconfigRule);
                }
                else
                {
                    HWAS_ASSERT((pParentMctList.size() <= 1),
                                "HWAS _deconfigureByAssoc: No MC parents for for MI w/ HUID: %lx", get_huid(&i_target));
                }
                // and we're done, so break;
                break;
            }

            case TYPE_DMI:
            {
                // get parent MI
                // Other errors may have affected parent state so use
                // UTIL_FILTER_ALL
                TargetHandleList pParentMitList;
                getParentAffinityTargetsByState(pParentMitList, &i_target,
                                                CLASS_UNIT, TYPE_MI,
                                                UTIL_FILTER_ALL);

                HWAS_ASSERT((pParentMitList.size() <= 1),
                            "HWAS _deconfigureByAssoc: DMI has multiple MI parents, this is impossible");

                Target *l_parentMi = pParentMitList[0];

                // if parent MI hasn't already been deconfigured
                if (!pParentMitList.empty() &&
                    isFunctional(l_parentMi) &&
                    !anyChildFunctional(*l_parentMi))
                {
                    // deconfigure parent MI
                    HWAS_INF("_deconfigureByAssoc MI parent with no functional children: %.8X",
                    get_huid(l_parentMi));
                    _deconfigureTarget(*l_parentMi,
                                        i_errlEid, NULL, i_deconfigRule);
                    _deconfigureByAssoc(*l_parentMi,
                                        i_errlEid,i_deconfigRule);
                }
                else
                {
                    HWAS_ASSERT((pParentMitList.size() <= 1),
                                "HWAS _deconfigureByAssoc: No MI parents for for DMI w/ HUID: %lx", get_huid(&i_target));
                }
                // and we're done, so break;
                break;
            }

            case TYPE_MBA:
            {
                // get parent MEMBUF (Centaur)
                const Target *l_parentMembuf = getParentChip(&i_target);

                // get children DIMM that are functional
                TargetHandleList pDimmList;
                PredicateCTM predDimm(CLASS_LOGICAL_CARD, TYPE_DIMM);
                PredicatePostfixExpr funcDimms;
                funcDimms.push(&predDimm).push(&isFunctional).And();
                targetService().getAssociated(pDimmList,
                        l_parentMembuf,
                        TargetService::CHILD_BY_AFFINITY,
                        TargetService::ALL,
                        &funcDimms);

                // if parent MEMBUF (Centaur) has no functional memory
                if (pDimmList.empty())
                {
                    // deconfigure parent MEMBUF (Centaur)
                    HWAS_INF("_deconfigureByAssoc MEMBUF parent with no memory: %.8X",
                        get_huid(l_parentMembuf));
                    _deconfigureTarget(const_cast<Target &> (*l_parentMembuf),
                        i_errlEid, NULL, i_deconfigRule);
                    _deconfigureByAssoc(const_cast<Target &> (*l_parentMembuf),
                        i_errlEid, i_deconfigRule);
                }

                // and we're done, so break;
                break;
            } // TYPE_MBA

            case TYPE_DIMM:
            {
                //  get immediate parent (MCA/MBA/etc)
                TargetHandleList pParentList;
                PredicatePostfixExpr funcParent;
                funcParent.push(&isFunctional);
                targetService().getAssociated(pParentList,
                        &i_target,
                        TargetService::PARENT_BY_AFFINITY,
                        TargetService::IMMEDIATE,
                        &funcParent);

                HWAS_ASSERT((pParentList.size() <= 1),
                    "HWAS _deconfigureByAssoc: pParentList > 1");

                // if parent hasn't already been deconfigured
                //  then deconfigure it
                if (!pParentList.empty())
                {
                    const Target *l_parentMba = pParentList[0];
                    HWAS_INF("_deconfigureByAssoc DIMM parent: %.8X",
                             get_huid(l_parentMba));
                    _deconfigureTarget(const_cast<Target &> (*l_parentMba),
                                       i_errlEid, NULL, i_deconfigRule);
                    _deconfigureByAssoc(const_cast<Target &> (*l_parentMba),
                                        i_errlEid, i_deconfigRule);
                }

                break;
            } // TYPE_DIMM

            // If target is a bus endpoint, deconfigure its peer
            case TYPE_XBUS:
            case TYPE_ABUS:
            case TYPE_PSI:
            {
                // Get peer endpoint target
                const Target * l_pDstTarget = i_target.
                              getAttr<ATTR_PEER_TARGET>();
                // If target is valid
                if (l_pDstTarget)
                {
                    // Deconfigure peer endpoint
                    HWAS_INF("_deconfigureByAssoc BUS Peer: %.8X",
                        get_huid(l_pDstTarget));
                    _deconfigureTarget(const_cast<Target &> (*l_pDstTarget),
                                       i_errlEid, NULL,
                                       i_deconfigRule);
                }
                break;
            } // TYPE_XBUS, TYPE_ABUS, TYPE_PSI
            case TYPE_OBUS:
            {
                // Only deconfigure peer endpoint if OBUS set to SMP mode
                if (i_target.getAttr<ATTR_OPTICS_CONFIG_MODE>() ==
                        OPTICS_CONFIG_MODE_SMP)
                {
                    // Get peer endpoint target
                    const Target * l_pDstTarget =
                        i_target.getAttr<ATTR_PEER_TARGET>();

                    // If target is valid
                    if (l_pDstTarget)
                    {
                        // Deconfigure peer endpoint
                        HWAS_INF("_deconfigureByAssoc OBUS Peer: 0x%.8X",
                            get_huid(l_pDstTarget));
                        _deconfigureTarget(
                                    const_cast<Target &>(*l_pDstTarget),
                                    i_errlEid, NULL, i_deconfigRule);
                    }
                }
                break;
            }
            case TYPE_PORE:
            {
                // Get parent proc target of PORE
                const Target * l_pParentProc = getParentChip(&i_target);
                // Deconfigure parent proc
                HWAS_INF("deconfigByAssoc parent proc: %.8X",
                    get_huid(l_pParentProc));
                _deconfigureTarget(const_cast<Target &> (*l_pParentProc),
                                   i_errlEid, NULL,
                                   i_deconfigRule);
                _deconfigureByAssoc(const_cast<Target &> (*l_pParentProc),
                                    i_errlEid, i_deconfigRule);
                break;
            } // TYPE_PORE
            case TYPE_PHB:
            {
                // Other errors may have affected parent state so use
                // UTIL_FILTER_ALL
                TargetHandleList pParentPECList;
                getParentAffinityTargetsByState(pParentPECList, &i_target,
                                                CLASS_UNIT, TYPE_PEC,
                                                UTIL_FILTER_ALL);
                HWAS_ASSERT((pParentPECList.size() == 1),
                            "HWAS _deconfigureByAssoc: pParentPECList != 1");
                Target *l_parentPEC = pParentPECList[0];

                if (isFunctional(l_parentPEC))
                {
                    if (!anyChildFunctional(*l_parentPEC))
                    {
                        _deconfigureTarget(*l_parentPEC,
                                           i_errlEid, NULL, i_deconfigRule);
                        _deconfigureByAssoc(*l_parentPEC,
                                            i_errlEid,i_deconfigRule);
                    }
                }

                break;
            } // TYPE_PHB
            case TYPE_OBUS_BRICK:
            {
                // Other errors may have affected parent state so use
                // UTIL_FILTER_ALL
                TargetHandleList pParentObusList;
                getParentAffinityTargetsByState(pParentObusList, &i_target,
                                                CLASS_UNIT, TYPE_OBUS,
                                                UTIL_FILTER_ALL);
                HWAS_ASSERT((pParentObusList.size() == 1),
                            "HWAS _deconfigureByAssoc: pParentObusList != 1");

                Target *l_parentObus = pParentObusList[0];
                if ((isFunctional(l_parentObus)) &&
                   (!anyChildFunctional(*l_parentObus)))
                {

                    _deconfigureTarget(*l_parentObus,
                                       i_errlEid, NULL, i_deconfigRule);
                    _deconfigureByAssoc(*l_parentObus,
                                       i_errlEid,i_deconfigRule);
                }

                break;
            } // TYPE_OBUS_BRICK
            case TYPE_NPU:
            {
                //Get the parent proc associated with this npu
                auto l_proc = getParentChip(&i_target);

                //Get all the obus children associated with this proc
                TargetHandleList pChildObusList;
                getChildAffinityTargetsByState(pChildObusList, l_proc,
                        CLASS_UNIT, TYPE_OBUS, UTIL_FILTER_PRESENT);

                for (auto l_obus : pChildObusList)
                {
                    // NPU controls non-smp obus,
                    // so need to mark the non-smp ones as not functional
                    // when the NPU is bad

                    //deconfigure each obus that is non-smp
                    if (l_obus->getAttr<ATTR_OPTICS_CONFIG_MODE>() !=
                            OPTICS_CONFIG_MODE_SMP)
                    {
                        _deconfigureTarget(*l_obus,
                                           i_errlEid, NULL, i_deconfigRule);
                        _deconfigureByAssoc(*l_obus,
                                           i_errlEid,i_deconfigRule);
                    }
                }

                break;
            } // TYPE_NPU
            case TYPE_SMPGROUP:
            {
                // Deconfigure peer SMPGROUP target
                const Target * l_pDstTarget =
                    i_target.getAttr<ATTR_PEER_TARGET>();

                if (l_pDstTarget)
                {
                    HWAS_INF("_deconfigureByAssoc SMPGROUP Peer: 0x%.8X",
                        get_huid(l_pDstTarget));
                    _deconfigureTarget(
                                const_cast<Target &>(*l_pDstTarget),
                                i_errlEid, NULL, i_deconfigRule);
                }

                //OBUS with no good SMPGROUP should be de-configured
                TargetHandleList pObusList;
                getParentAffinityTargetsByState(pObusList,
                        &i_target, CLASS_UNIT, TYPE_OBUS,
                        UTIL_FILTER_PRESENT);

                HWAS_ASSERT((pObusList.size() == 1),
                    "HWAS _deconfigureByAssoc: pObusList != 1");
                Target *l_targetObus = pObusList[0];

                if ((l_targetObus->getAttr<ATTR_OPTICS_CONFIG_MODE>() ==
                            OPTICS_CONFIG_MODE_SMP) &&
                   (!anyChildFunctional(*l_targetObus)))
                {
                    _deconfigureTarget(*l_targetObus, i_errlEid, NULL,
                                    i_deconfigRule);
                }

                break;
            } // TYPE_SMPGROUP
            default:
                // no action
            break;
        } // switch
    } // !i_Runtime
    else
    {
        HWAS_INF("_deconfigureByAssoc() - system is at runtime"
                " skipping all association checks beyond"
                " the CHILD");
    }

    HWAS_DBG("_deconfigureByAssoc exiting: %.8X", get_huid(&i_target));
} // _deconfigByAssoc

//******************************************************************************
void DeconfigGard::_deconfigureTarget(
        Target & i_target,
        const uint32_t i_errlEid,
        bool *o_targetDeconfigured,
        const DeconfigureFlags i_deconfigRule)
{
    HWAS_INF("Deconfiguring Target %.8X, errlEid 0x%X",
            get_huid(&i_target), i_errlEid);

    // Set the Target state to non-functional. The assumption is that it is
    // not possible for another thread (other than deconfigGard) to be
    // updating HWAS_STATE concurrently.
    HwasState l_state = i_target.getAttr<ATTR_HWAS_STATE>();

    // if the rule is DUMP_AT_RUNTIME and we got here, then we are at runtime.
    if (i_deconfigRule == DUMP_AT_RUNTIME)
    {
        l_state.dumpfunctional = 1;
    }
    else
    {
        l_state.dumpfunctional = 0;
    }

    if (!l_state.functional)
    {
        HWAS_DBG(
        "Target HWAS_STATE already has functional=0; deconfiguredByEid=0x%X",
                l_state.deconfiguredByEid);

        if (i_deconfigRule != NOT_AT_RUNTIME)
        {
            // if FULLY_AT_RUNTIME or DUMP_AT_RUNTIME, then the dumpfunctional
            // state changed, so do the setAttr
            i_target.setAttr<ATTR_HWAS_STATE>(l_state);
        }

        if (l_state.deconfiguredByEid == DECONFIGURED_BY_FIELD_CORE_OVERRIDE)
        {
            // A child target was deconfig by FCO, and parent is being deconfig
            // with a non-FCO reason .. override with parent's EID
            HWAS_INF("HUID %.8X, Overriding deconfigByEid from FCO->%.8X",
                     get_huid(&i_target), i_errlEid);
            l_state.deconfiguredByEid = i_errlEid;
            i_target.setAttr<ATTR_HWAS_STATE>(l_state);
        }
    }
    else
    {
        if(i_deconfigRule == SPEC_DECONFIG)
        {
            HWAS_INF("Setting speculative deconfig");
            l_state.specdeconfig = 1;
            l_state.deconfiguredByEid = i_errlEid;
            i_target.setAttr<ATTR_HWAS_STATE>(l_state);
        }
        else
        {
            HWAS_INF(
                    "Setting Target HWAS_STATE: functional=0, deconfiguredByEid=0x%X",
                    i_errlEid);
            l_state.functional = 0;
            l_state.specdeconfig = 0;

            l_state.deconfiguredByEid = i_errlEid;
            i_target.setAttr<ATTR_HWAS_STATE>(l_state);
            if (o_targetDeconfigured)
            {
                *o_targetDeconfigured = true;
            }

            // if this is a real error, trigger a reconfigure loop
            if (i_errlEid & DECONFIGURED_BY_PLID_MASK)
            {
                // Set RECONFIGURE_LOOP attribute to indicate it was caused by
                // a hw deconfigure
                TARGETING::Target* l_pTopLevel = NULL;
                TARGETING::targetService().getTopLevelTarget(l_pTopLevel);
                TARGETING::ATTR_RECONFIGURE_LOOP_type l_reconfigAttr =
                        l_pTopLevel->getAttr<ATTR_RECONFIGURE_LOOP>();
                // 'OR' values in case of multiple reasons for reconfigure
                l_reconfigAttr |= TARGETING::RECONFIGURE_LOOP_DECONFIGURE;
                l_pTopLevel->setAttr<ATTR_RECONFIGURE_LOOP>(l_reconfigAttr);
            }

            // Do any necessary Deconfigure Actions
            _doDeconfigureActions(i_target); /*no effect*/ // to quiet BEAM
            // If target being deconfigured is an x/a/o bus endpoint
            if ((TYPE_XBUS == i_target.getAttr<ATTR_TYPE>()) ||
                (TYPE_ABUS == i_target.getAttr<ATTR_TYPE>()) ||
                (TYPE_OBUS == i_target.getAttr<ATTR_TYPE>()))
            {
                // Set flag indicating x/a/o bus endpoint deconfiguration
                iv_XAOBusEndpointDeconfigured = true;
            }

            // The target has been successfully de-configured,
            // perform any other post-deconfig operations,
            // e.g. syncing state with other subsystems
            // TODO RTC:184521: Allow function platPostDeconfigureTarget
            // to run once FSP supports it
            // Remove the #ifdef ... #endif, once FSP is ready for code
            #ifdef __HOSTBOOT_MODULE
                platPostDeconfigureTarget(&i_target);
            #endif
        }
    }
} // _deconfigureTarget

//******************************************************************************
void DeconfigGard::_doDeconfigureActions(Target & i_target)
{
 // Placeholder for any necessary deconfigure actions

#ifdef CONFIG_BMC_IPMI
    // set the BMC status for this target
    SENSOR::StatusSensor l_sensor( &i_target );

    // can assume the presence sensor is in the correct state, just
    // assert that it is now non functional.
    errlHndl_t err = l_sensor.setStatus( SENSOR::StatusSensor::NON_FUNCTIONAL );

    if(err)
    {
        HWAS_ERR("Error returned from call to set sensor status for HUID 0x%x",
                 TARGETING::get_huid( &i_target) );
        err->collectTrace(HWAS_COMP_NAME, 512);
        errlCommit(err, HWAS_COMP_ID);
    }
#endif

}

#ifndef __HOSTBOOT_RUNTIME
//******************************************************************************
void DeconfigGard::_createDeconfigureRecord(
    const Target & i_target,
    const uint32_t i_errlEid)
{
    // Look for an existing Deconfigure Record for the Target
    DeconfigureRecordsCItr_t l_itr = iv_deconfigureRecords.begin();

    for (; l_itr != iv_deconfigureRecords.end(); ++l_itr)
    {
        if ((*l_itr).iv_target == &i_target)
        {
            HWAS_DBG("Not creating Deconfigure Record, one exists errlEid 0x%X",
                (*l_itr).iv_errlogEid);
            break;
        }
    }

    // didn't find a match
    if (l_itr == iv_deconfigureRecords.end())
    {
        // Create a DeconfigureRecord
        HWAS_INF("Creating a Deconfigure Record");

        DeconfigureRecord l_record;
        l_record.iv_target = &i_target;
        l_record.iv_errlogEid = i_errlEid;

        iv_deconfigureRecords.push_back(l_record);
    }
}

//******************************************************************************
void DeconfigGard::clearDeconfigureRecords(
        const Target * const i_pTarget)
{
    if (i_pTarget == NULL)
    {
        HWAS_INF("Clearing all %d Deconfigure Records",
                 iv_deconfigureRecords.size());
        iv_deconfigureRecords.clear();
    }
    else
    {
        // Look for a Deconfigure Record for the specified Target (there can
        // only be one record)
        bool l_foundRecord = false;

        for (DeconfigureRecordsItr_t l_itr = iv_deconfigureRecords.begin();
             l_itr != iv_deconfigureRecords.end(); ++l_itr)
        {
            if ((*l_itr).iv_target == i_pTarget)
            {
                HWAS_INF("Clearing Deconfigure Record for %.8X",
                                get_huid(i_pTarget));
                iv_deconfigureRecords.erase(l_itr);
                l_foundRecord = true;
                break;
            }
        }

        if (!l_foundRecord)
        {
            HWAS_INF("Did not find a Deconfigure Record to clear for %.8X",
                           get_huid(i_pTarget));
        }
    }
}


//******************************************************************************
void DeconfigGard::processDeferredDeconfig()
{
    HWAS_DBG(">processDeferredDeconfig");

    // get all deconfigure records, process them, and delete them.
    HWAS_MUTEX_LOCK(iv_mutex);

    for (DeconfigureRecordsItr_t l_itr = iv_deconfigureRecords.begin();
            l_itr != iv_deconfigureRecords.end();
            ++l_itr)
    {
        // do the deconfigure
        DeconfigureRecord l_record = *l_itr;
        _deconfigureTarget(const_cast<Target &> (*(l_record.iv_target)),
                l_record.iv_errlogEid);
        _deconfigureByAssoc(const_cast<Target &> (*(l_record.iv_target)),
                l_record.iv_errlogEid);
    } // for

    // clear the list - handled them all
    iv_deconfigureRecords.clear();

    HWAS_MUTEX_UNLOCK(iv_mutex);

    HWAS_DBG("<processDeferredDeconfig");
} // processDeferredDeconfig
#endif // __HOSTBOOT_RUNTIME


//******************************************************************************
errlHndl_t DeconfigGard::_deconfigureAssocProc(ProcInfoVector &io_procInfo)
{
    // Defined for possible use in future applications
    errlHndl_t l_errlHdl = NULL;

    do
    {
        // STEP 1:
        // Find master proc and iterate through its bus endpoint chiplets.
        // For any chiplets which are deconfigured, mark peer proc as
        // deconfigured

        // Find master proc
        ProcInfo * l_pMasterProcInfo = NULL;
        for (ProcInfoVector::iterator
                 l_procInfoIter = io_procInfo.begin();
                 l_procInfoIter != io_procInfo.end();
                 ++l_procInfoIter)
        {
            if ( ((*l_procInfoIter).iv_masterCapable) &&
                 (!(*l_procInfoIter).iv_deconfigured) )
            {
                // Save for subsequent use
                l_pMasterProcInfo = &(*l_procInfoIter);
                // Iterate through bus endpoints, and if deconfigured,
                // mark peer proc to be deconfigured
                for (uint8_t i = 0; i < NUM_A_BUSES; i++)
                {
                    if ((*l_procInfoIter).iv_ADeconfigured[i])
                    {
                        HWAS_INF("deconfigureAssocProc marked proc: "
                                 "%.8X for deconfiguration "
                                 "due to deconfigured abus endpoint "
                                 "on master proc.",
                                 (*l_procInfoIter).iv_pAProcs[i]->procHUID);
                        (*l_procInfoIter).iv_pAProcs[i]->
                                        iv_deconfigured = true;
                    }
                }
                for (uint8_t i = 0; i < NUM_X_BUSES; i++)
                {
                    if ((*l_procInfoIter).iv_XDeconfigured[i])
                    {
                        HWAS_INF("deconfigureAssocProc marked proc: "
                                 "%.8X for deconfiguration "
                                 "due to deconfigured xbus endpoint "
                                 "on master proc.",
                                 (*l_procInfoIter).iv_pXProcs[i]->procHUID);
                        (*l_procInfoIter).iv_pXProcs[i]->
                                        iv_deconfigured = true;
                    }
                }
                break;
            }
        } // STEP 1

        // If no master proc found, mark all proc as deconfigured
        if (l_pMasterProcInfo == NULL)
        {
            HWAS_INF("deconfigureAssocProc: Master proc not found");
            // Iterate through procs, and mark deconfigured all proc
            for (ProcInfoVector::iterator
                     l_procInfoIter = io_procInfo.begin();
                     l_procInfoIter != io_procInfo.end();
                     ++l_procInfoIter)
            {
                (*l_procInfoIter).iv_deconfigured = true;
            }
            // break now since all of the rest of the processing is moot.
            break;
        }

        // STEP 2:
        // Iterate through procs, and mark deconfigured any
        // non-master proc which has more than one bus endpoint
        // chiplet deconfigured
        for (ProcInfoVector::iterator
                 l_procInfoIter = io_procInfo.begin();
                 l_procInfoIter != io_procInfo.end();
                 ++l_procInfoIter)
        {
            // Don't deconfigure master proc
            if ((*l_procInfoIter).iv_masterCapable)
            {
                continue;
            }
            // Don't examine previously marked proc
            if ((*l_procInfoIter).iv_deconfigured)
            {
                continue;
            }
            // Deconfigured bus chiplet counter
            uint8_t deconfigBusCounter = 0;
            // Check and increment counter if A/X bus endpoints found
            // which are deconfigured
            for (uint8_t i = 0; i < NUM_A_BUSES; i++)
            {
                if ((*l_procInfoIter).iv_ADeconfigured[i])
                {
                    // Only increment deconfigBusCounter if peer proc exists
                    //  and is functional
                    if((*l_procInfoIter).iv_pAProcs[i] &&
                      (!(*l_procInfoIter).iv_pAProcs[i]->iv_deconfigured))
                    {
                        deconfigBusCounter++;
                    }
                }
            }
            for (uint8_t i = 0; i < NUM_X_BUSES; i++)
            {
                if ((*l_procInfoIter).iv_XDeconfigured[i])
                {
                    // Only increment deconfigBusCounter if peer proc exists
                    // and is functional
                    if((*l_procInfoIter).iv_pXProcs[i] &&
                      (!(*l_procInfoIter).iv_pXProcs[i]->iv_deconfigured))
                    {
                        deconfigBusCounter++;
                    }
                }
            }
            // If number of endpoints deconfigured is > 1
            if (deconfigBusCounter > 1)
            {
                // Mark current proc to be deconfigured
                HWAS_INF("deconfigureAssocProc marked proc: "
                                 "%.8X for deconfiguration "
                                 "due to %d deconfigured bus endpoints "
                                 "on this proc.",
                                 (*l_procInfoIter).procHUID,
                                  deconfigBusCounter);
                (*l_procInfoIter).iv_deconfigured = true;
            }
        }// STEP 2


        // STEP 3:
        // If a deconfigured bus connects two non-master procs,
        // both of which are in the master-containing logical group,
        // mark proc with higher HUID to be deconfigured.

        // Iterate through procs and check xbus chiplets
        for (ProcInfoVector::iterator
                 l_procInfoIter = io_procInfo.begin();
                 l_procInfoIter != io_procInfo.end();
                 ++l_procInfoIter)
        {
            // Master proc handled in STEP 1
            if ((*l_procInfoIter).iv_masterCapable)
            {
                continue;
            }
            // Don't examine previously marked proc
            if ((*l_procInfoIter).iv_deconfigured)
            {
                continue;
            }
            // If current proc is on master logical group
            if (l_pMasterProcInfo->procFabricGroup ==
                (*l_procInfoIter).procFabricGroup)
            {
                // Check xbus endpoints
                for (uint8_t i = 0; i < NUM_X_BUSES; i++)
                {
                    // If endpoint deconfigured and endpoint peer proc is
                    // not already marked deconfigured
                    if (((*l_procInfoIter).iv_XDeconfigured[i]) &&
                        (!((*l_procInfoIter).iv_pXProcs[i]->iv_deconfigured)))
                    {
                        // Mark proc with higher HUID to be deconfigured
                        if ((*l_procInfoIter).iv_pXProcs[i]->procHUID >
                            (*l_procInfoIter).procHUID)
                        {
                            HWAS_INF("deconfigureAssocProc marked remote proc:"
                                 " %.8X for deconfiguration "
                                 "due to higher HUID than peer "
                                 "proc on same master-containing logical "
                                 "group.",
                                 (*l_procInfoIter).iv_pXProcs[i]->procHUID);
                            (*l_procInfoIter).iv_pXProcs[i]->
                                               iv_deconfigured = true;
                        }
                        else
                        {
                            HWAS_INF("deconfigureAssocProc marked proc: "
                                 "%.8X for deconfiguration "
                                 "due to higher HUID than peer "
                                 "proc on same master-containing logical "
                                 "group.",
                                 (*l_procInfoIter).procHUID);
                            (*l_procInfoIter).iv_deconfigured = true;
                        }
                    }
                }
            }
        }// STEP 3


        // STEP 4:
        // If a deconfigured bus connects two procs, both in the same
        // non-master-containing logical group, mark current proc
        // deconfigured if there is a same position proc marked deconfigured
        // in the master logical group, else mark remote proc if there is
        // a same position proc marked deconfigured in the master logical
        // group otherwise, mark the proc with the higher HUID.

        // Iterate through procs and, if in non-master
        // logical group, check xbus chiplets
        for (ProcInfoVector::iterator
                 l_procInfoIter = io_procInfo.begin();
                 l_procInfoIter != io_procInfo.end();
                 ++l_procInfoIter)
        {
            // Don't examine previously marked proc
            if ((*l_procInfoIter).iv_deconfigured)
            {
                continue;
            }
            // Don't examine procs on master logical group
            if (l_pMasterProcInfo->procFabricGroup ==
                (*l_procInfoIter).procFabricGroup)
            {
                continue;
            }
            // Check xbuses because they connect procs which
            // are in the same logical group
            for (uint8_t i = 0; i < NUM_X_BUSES; i++)
            {
                // If endpoint deconfigured and endpoint peer proc
                // is not already marked deconfigured
                if (((*l_procInfoIter).iv_XDeconfigured[i]) &&
                    (!((*l_procInfoIter).iv_pXProcs[i]->iv_deconfigured)))
                {
                    // Variable to indicate If this step results in
                    // finding a proc to mark deconfigured
                    bool l_chipIDmatch = false;
                    // Iterate through procs and examine ones found to
                    // be on the master-containing logical group
                    for (ProcInfoVector::const_iterator
                         l_mGroupProcInfoIter = io_procInfo.begin();
                         l_mGroupProcInfoIter != io_procInfo.end();
                         ++l_mGroupProcInfoIter)
                    {
                        if (l_pMasterProcInfo->procFabricGroup ==
                            (*l_mGroupProcInfoIter).procFabricGroup)
                        {
                            // If master logical group proc deconfigured with
                            // same FABRIC_CHIP_ID as current proc
                            if (((*l_mGroupProcInfoIter).iv_deconfigured) &&
                                ((*l_mGroupProcInfoIter).procFabricChip ==
                                 (*l_procInfoIter).procFabricChip))
                            {
                                // Mark current proc to be deconfigured
                                // and set chipIDmatch
                                HWAS_INF("deconfigureAssocProc marked proc: "
                                 "%.8X for deconfiguration "
                                 "due to same position deconfigured "
                                 "proc on master-containing logical "
                                 "group.",
                                 (*l_procInfoIter).procHUID);
                                (*l_procInfoIter).iv_deconfigured =\
                                                                  true;
                                l_chipIDmatch = true;
                                break;
                            }
                            // If master logical group proc deconfigured with
                            // same FABRIC_CHIP_ID as current proc's xbus peer
                            // proc
                            else if (((*l_mGroupProcInfoIter).
                                        iv_deconfigured) &&
                                    ((*l_mGroupProcInfoIter).
                                        procFabricChip ==
                                    (*l_procInfoIter).iv_pXProcs[i]->
                                        procFabricChip))
                            {
                                // Mark peer proc to be deconfigured
                                // and set chipIDmatch
                                HWAS_INF("deconfigureAssocProc marked remote "
                                 "proc: %.8X for deconfiguration "
                                 "due to same position deconfigured "
                                 "proc on master-containing logical "
                                 "group.",
                                 (*l_procInfoIter).iv_pXProcs[i]->procHUID);
                                (*l_procInfoIter).iv_pXProcs[i]->
                                 iv_deconfigured = true;
                                l_chipIDmatch = true;
                                break;
                            }
                        }
                    }
                    // If previous step did not find a proc to mark
                    if (!(l_chipIDmatch))
                    {
                        // Deconfigure proc with higher HUID
                        if ((*l_procInfoIter).procHUID >
                            (*l_procInfoIter).iv_pXProcs[i]->procHUID)
                        {
                             HWAS_INF("deconfigureAssocProc marked proc:"
                             " %.8X for deconfiguration "
                             "due to higher HUID than peer "
                             "proc on same non master-containing logical "
                             "group.",
                             (*l_procInfoIter).procHUID);
                            (*l_procInfoIter).iv_deconfigured =
                                                          true;
                        }
                        else
                        {
                            HWAS_INF("deconfigureAssocProc marked remote proc:"
                             " %.8X for deconfiguration "
                             "due to higher HUID than peer "
                             "proc on same non master-containing logical "
                             "group.",
                             (*l_procInfoIter).iv_pXProcs[i]->procHUID);
                            (*l_procInfoIter).iv_pXProcs[i]->
                            iv_deconfigured = true;
                        }
                    }
                }
            }
        }// STEP 4

        // STEP 5:
        // If a deconfigured bus connects two procs on different logical groups,
        // and neither proc is the master proc: If current proc's xbus peer
        // proc is marked as deconfigured, mark current proc. Else, mark
        // abus peer proc.

        // Iterate through procs and check for deconfigured abus endpoints
        for (ProcInfoVector::iterator
                 l_procInfoIter = io_procInfo.begin();
                 l_procInfoIter != io_procInfo.end();
                 ++l_procInfoIter)
        {
            // Master proc handled in STEP 1
            if ((*l_procInfoIter).iv_masterCapable)
            {
                continue;
            }
            // Don't examine procs which are already marked
            if ((*l_procInfoIter).iv_deconfigured)
            {
                continue;
            }
            // Check abuses because they connect procs which are in
            // different logical groups
            for (uint8_t i = 0; i < NUM_A_BUSES; i++)
            {
                // If endpoint deconfigured and endpoint peer proc
                // is not already marked deconfigured
                if (((*l_procInfoIter).iv_ADeconfigured[i]) &&
                    (!((*l_procInfoIter).iv_pAProcs[i]->iv_deconfigured)))
                {
                    // Check XBUS peer
                    bool l_xbusPeerProcDeconfigured = false;
                    for (uint8_t j = 0; j < NUM_X_BUSES; j++)
                    {
                        // If peer proc exists
                        if ((*l_procInfoIter).iv_pXProcs[j])
                        {
                            // If xbus peer proc deconfigured
                            if ((*l_procInfoIter).iv_pXProcs[j]->
                                                    iv_deconfigured)
                            {
                                // Set xbusPeerProcDeconfigured and deconfigure
                                // current proc
                                 HWAS_INF("deconfigureAssocProc marked proc:"
                                 " %.8X for deconfiguration "
                                 "due to deconfigured xbus peer proc.",
                                 (*l_procInfoIter).procHUID);
                                l_xbusPeerProcDeconfigured = true;
                                (*l_procInfoIter).iv_deconfigured = true;
                                break;
                            }
                        }
                    }
                    // If previous step did not result in marking a proc
                    // mark abus peer proc
                    if (!(l_xbusPeerProcDeconfigured))
                    {
                        HWAS_INF("deconfigureAssocProc marked "
                             "remote proc: %.8X for deconfiguration "
                             "due to functional xbus peer proc.",
                             (*l_procInfoIter).iv_pAProcs[i]->procHUID);
                        (*l_procInfoIter).iv_pAProcs[i]->
                                          iv_deconfigured = true;
                    }
                }
            }
        }// STEP 5
    }while(0);
    if (!l_errlHdl)
    {
        // Perform SMP group balancing
        l_errlHdl = _symmetryValidation(io_procInfo);
    }
    return l_errlHdl;

}

//******************************************************************************

errlHndl_t DeconfigGard::_symmetryValidation(ProcInfoVector &io_procInfo)
{
    // Defined for possible use in future applications
    errlHndl_t l_errlHdl = NULL;

    // Perform SMP group balancing
    do
    {
        Target* pSys;
        targetService().getTopLevelTarget(pSys);
        HWAS_ASSERT(pSys, "HWAS _symmetryValidation: no TopLevelTarget");
        if ( pSys->getAttr<ATTR_PROC_FABRIC_PUMP_MODE>() ==
             TARGETING::PROC_FABRIC_PUMP_MODE_CHIP_IS_GROUP )
        {
          // When CHIP_IS_GROUP is set, that means a single fabric CHIP
          // per GROUP (or NODE). If we apply symmetry deconfig, it will
          // deconfig all the other chips because they all have the same
          // relative position to group.

          break;
        }

        // STEP 1:
        // If a proc is deconfigured in a logical group
        // containing the master proc, iterate through all procs
        // and mark as deconfigured those in other logical groups
        // with the same FABRIC_CHIP_ID (procFabricChip)

        // Find master proc
        ProcInfo * l_pMasterProcInfo = NULL;
        for (ProcInfoVector::iterator
                 l_procInfoIter = io_procInfo.begin();
                 l_procInfoIter != io_procInfo.end();
                 ++l_procInfoIter)
        {
            // If master proc
            if ((*l_procInfoIter).iv_masterCapable)
            {
                // Save for subsequent use
                l_pMasterProcInfo = &(*l_procInfoIter);
                break;
            }
        }
        // If no master proc found, abort
        HWAS_ASSERT(l_pMasterProcInfo, "HWAS _symmetryValidation:"
                                       "Master proc not found");
        // Iterate through procs and check if in master logical group
        for (ProcInfoVector::const_iterator
                 l_procInfoIter = io_procInfo.begin();
                 l_procInfoIter != io_procInfo.end();
                 ++l_procInfoIter)
        {
            // Skip master proc
            if ((*l_procInfoIter).iv_masterCapable)
            {
                continue;
            }
            // If current proc is on master logical group
            // and marked as deconfigured
            if ((l_pMasterProcInfo->procFabricGroup ==
                (*l_procInfoIter).procFabricGroup) &&
                ((*l_procInfoIter).iv_deconfigured))
            {
                // Iterate through procs and mark any same-
                // position procs as deconfigured
                for (ProcInfoVector::iterator
                     l_posProcInfoIter = io_procInfo.begin();
                     l_posProcInfoIter != io_procInfo.end();
                     ++l_posProcInfoIter)
                {
                    if ((*l_procInfoIter).procFabricChip ==
                        (*l_posProcInfoIter).procFabricChip)
                    {
                        HWAS_INF("symmetryValidation step 1 marked proc: "
                             "%.8X for deconfiguration. Previously marked %d",
                           (*l_posProcInfoIter).procHUID,
                           (*l_posProcInfoIter).iv_deconfigured?1:0);
                        (*l_posProcInfoIter).iv_deconfigured = true;
                    }
                }
            }
        }// STEP 1

        // STEP 2:
        // If a deconfigured proc is found on a non-master-containing group
        // and has the same position (FABRIC_CHIP_ID) as a functional
        // non-master chip on the master logical group,
        // mark its xbus peer proc(s) for deconfiguration

        // Iterate through procs, if marked deconfigured, compare chip
        // position to functional chip on master group.
        for (ProcInfoVector::const_iterator
                 l_procInfoIter = io_procInfo.begin();
                 l_procInfoIter != io_procInfo.end();
                 ++l_procInfoIter)
        {
            // If proc is marked deconfigured
            if ((*l_procInfoIter).iv_deconfigured)
            {
                // Iterate through procs, examining those on
                // the master logical group
                for (ProcInfoVector::const_iterator
                     l_mGroupProcInfoIter = io_procInfo.begin();
                     l_mGroupProcInfoIter != io_procInfo.end();
                     ++l_mGroupProcInfoIter)
                {
                    // If proc found is on the master-containing logical group
                    // functional, and matches the position of the deconfigured
                    // proc from the outer loop
                    if ((l_pMasterProcInfo->procFabricGroup ==
                        (*l_mGroupProcInfoIter).procFabricGroup) &&
                        (!((*l_mGroupProcInfoIter).iv_deconfigured)) &&
                        ((*l_mGroupProcInfoIter).procFabricChip ==
                                (*l_procInfoIter).procFabricChip))
                    {
                        // Find xbus peer proc to mark deconfigured
                        for (uint8_t i = 0; i < NUM_X_BUSES; i++)
                        {
                            // If xbus peer proc exists, mark it
                            if ((*l_procInfoIter).iv_pXProcs[i])
                            {
                                HWAS_INF( "procs> %.8X : G=%d, C=%d, D=%d, M=%d", (*l_procInfoIter).procHUID, (*l_procInfoIter).procFabricGroup, (*l_procInfoIter).procFabricChip, (*l_procInfoIter).iv_deconfigured, (*l_procInfoIter).iv_masterCapable );
                                HWAS_INF( "mGroup> %.8X : G=%d, C=%d, D=%d, M=%d", (*l_mGroupProcInfoIter).procHUID, (*l_mGroupProcInfoIter).procFabricGroup, (*l_mGroupProcInfoIter).procFabricChip, (*l_mGroupProcInfoIter).iv_deconfigured, (*l_mGroupProcInfoIter).iv_masterCapable );
                                HWAS_INF( "xbus%d> %.8X : G=%d, C=%d, D=%d, M=%d", i,  (*l_procInfoIter).iv_pXProcs[i]->procHUID, (*l_procInfoIter).iv_pXProcs[i]->procFabricGroup, (*l_procInfoIter).iv_pXProcs[i]->procFabricChip, (*l_procInfoIter).iv_pXProcs[i]->iv_deconfigured, (*l_procInfoIter).iv_pXProcs[i]->iv_masterCapable );

                                // If the chip we found is the master then do NOT
                                //  deconfigure it
                                if( (*l_procInfoIter).iv_pXProcs[i]->iv_masterCapable )
                                {
                                    HWAS_INF( "Skipping deconfig of master proc %.8X", l_pMasterProcInfo->procHUID );
                                }
                                else
                                {
                                    HWAS_INF("symmetryValidation step 2 "
                                             "marked proc: %.8X for "
                                             "deconfiguration.",
                                             (*l_procInfoIter).
                                             iv_pXProcs[i]->procHUID);
                                    (*l_procInfoIter).iv_pXProcs[i]->
                                        iv_deconfigured = true;
                                }
                            }
                        }
                    }
                }
            }
        }// STEP 2
    }while(0);
    return l_errlHdl;
}

#ifndef __HOSTBOOT_RUNTIME
//******************************************************************************

void DeconfigGard::setXAOBusEndpointDeconfigured(bool deconfig)
{
    HWAS_INF("Set iv_XAOBusEndpointDeconfigured = %d", deconfig?1:0);
    iv_XAOBusEndpointDeconfigured = deconfig;
}

//*****************************************************************************

void DeconfigGard::_clearFCODeconfigure(ConstTargetHandle_t i_nodeTarget)
{
    HWAS_DBG("Clear all FCO deconfigure");

    //Get all targets in the node present and non-functional.
    PredicateHwas predNonFunctional;
    predNonFunctional.present(true).functional(false);
    TargetHandleList l_targetList;
    targetService().getAssociated(l_targetList,i_nodeTarget,
                              TargetService::CHILD, TargetService::ALL,
                              &predNonFunctional);
    for (TargetHandleList::const_iterator
             l_target_it = l_targetList.begin();
             l_target_it != l_targetList.end();
             l_target_it++)
    {
        TargetHandle_t l_pTarget = *l_target_it;
        HwasState l_state = l_pTarget->getAttr<ATTR_HWAS_STATE>();
        if(l_state.deconfiguredByEid == DECONFIGURED_BY_FIELD_CORE_OVERRIDE)
        {
            l_state.functional = 1;
            l_state.deconfiguredByEid = 0;
            l_pTarget->setAttr<ATTR_HWAS_STATE>(l_state);
        }
    }
}
//******************************************************************************
#endif // __HOSTBOOT_RUNTIME

//Note this will not find child DIMMs because they are
//affinity children, not physical
bool DeconfigGard::anyChildFunctional(Target & i_parent)
{
    bool retVal = false;
    TargetHandleList pChildList;
    PredicateHwas isFunctional;
    isFunctional.functional(true);

    if (isFunctional(&i_parent))
    {
        // find all CHILD targets, that match the predicate
        // if any of them are functional return true
        // if all of them are non-functional return false
        targetService().getAssociated(pChildList, &i_parent,
            TargetService::CHILD, TargetService::ALL, &isFunctional);

        if (pChildList.size() >= 1)
        {
            retVal = true;
        }
    }
    return retVal;
} //anyChildFunctional

bool DeconfigGard::anyChildFCO (Target & i_parent)
{
    bool retVal = false;

    TargetHandleList pChildList;
    PredicateHwas predFCO;
    predFCO.present(true)
           .functional(false)
           .deconfiguredByEid(DECONFIGURED_BY_FIELD_CORE_OVERRIDE);

    // find all CHILD targets, that match the predicate
    // if any of them are FCO return true
    // if none of them are FCO return false
    targetService().getAssociated(pChildList, &i_parent,
        TargetService::CHILD, TargetService::ALL, &predFCO);

    if (pChildList.size() >= 1)
    {
        retVal = true;
    }

    return retVal;
} //anyChildFCO

#ifdef __HOSTBOOT_MODULE
/******************************************************************************/
// deconfigureTargetAtRuntime
/******************************************************************************/
errlHndl_t DeconfigGard::deconfigureTargetAtRuntime(
        TARGETING::TargetHandle_t i_pTarget,
        const DeconfigGard::DeconfigureFlags i_deconfigureAction,
        const errlHndl_t i_deconfigErrl)

{

    errlHndl_t l_errl = nullptr;

    uint32_t deconfigReason =
        (i_deconfigErrl) ?
        i_deconfigErrl->eid() : DeconfigGard::DECONFIGURED_BY_PRD;

    HWAS_INF(">>>deconfigureTargetAtRuntime() - "
            "Input Target HUID:0x%08X Deconfig Action"
            " 0x%08X Deconfig Reason :0x%08X",
            get_huid(i_pTarget),i_deconfigureAction,
            deconfigReason);

#ifdef __HOSTBOOT_RUNTIME

    l_errl = platDeconfigureTargetAtRuntime(
                                            i_pTarget,
                                            i_deconfigureAction,
                                            i_deconfigErrl
                                           );
#else
    HWAS_ERR("deconfigureTargetAtRuntime() - "
            "called outside of hbrt context");
    /*@
     * @errortype
     * @moduleid     MOD_RUNTIME_DECONFIG
     * @reasoncode   RC_NOT_AT_RUNTIME
     * @userdata1    HUID of the target
     * @userdata2    deconfig reason - either error log id, or
     *                                 DeconfigGard::DECONFIGURED_BY_PRD
     *
     * @devdesc      deconfigureTargetAtRuntime is currently only
     *               supported in hostboot runtime, this error
     *               indicates the function was called outside of
     *               the hostboot runtime context.
     * @custdesc     Host firmware encountered an
     *               internal error
     */

    l_errl = hwasError(
                       ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                       MOD_RUNTIME_DECONFIG,RC_NOT_AT_RUNTIME,
                       get_huid(i_pTarget),deconfigReason
                       );
#endif
    HWAS_INF(">>>deconfigureTargetAtRuntime()" );
    return l_errl ;
}
#endif

//******************************************************************************
uint8_t DeconfigGard::clearBlockSpecDeconfigForReplacedTargets()
{
    HWAS_INF("Clear Block Spec Deconfig for replaced Targets");

    // Get Block Spec Deconfig value
    Target *pSys;
    targetService().getTopLevelTarget(pSys);
    ATTR_BLOCK_SPEC_DECONFIG_type l_block_spec_deconfig =
        pSys->getAttr<ATTR_BLOCK_SPEC_DECONFIG>();

    do
    {
        // Check Block Spec Deconfig value
        if(l_block_spec_deconfig == 0)
        {
            // Block Spec Deconfig is already cleared
            HWAS_INF("Block Spec Deconfig already cleared");
        }

        // Create the predicate with HWAS changed state and our RESRC_RECOV bit
        PredicateHwasChanged l_predicateHwasChanged;
        l_predicateHwasChanged.changedBit(HWAS_CHANGED_BIT_RESRC_RECOV, true);

        // Go through all targets
        for (TargetIterator t_iter = targetService().begin();
             t_iter != targetService().end();
             ++t_iter)
        {
            Target* l_pTarget = *t_iter;

            // Check if target has changed
            if (l_predicateHwasChanged(l_pTarget))
            {
                // Check if Block Spec Deconfig is set
                if(l_block_spec_deconfig == 1)
                {
                    l_block_spec_deconfig = 0;
                    pSys->setAttr
                        <ATTR_BLOCK_SPEC_DECONFIG>(l_block_spec_deconfig);
                    HWAS_INF("Block Spec Deconfig cleared due to HWAS state "
                             "change for 0x%.8x",
                             get_huid(l_pTarget));
                }

                // Clear RESRC_RECOV bit in changed flags for the target
                HWAS_DBG("RESRC_RECOV bit cleared for 0x%.8x",
                         get_huid(l_pTarget));
                clear_hwas_changed_bit(l_pTarget, HWAS_CHANGED_BIT_RESRC_RECOV);
            }
        } // for
    } while (0);

    return l_block_spec_deconfig;
} // clearBlockSpecDeconfigForReplacedTargets

//******************************************************************************
errlHndl_t
   DeconfigGard::clearBlockSpecDeconfigForUngardedTargets(uint8_t &io_blockAttr)
{
    HWAS_INF("Clear Block Spec Deconfig for ungarded Targets");

    errlHndl_t l_pErr = NULL;
    GardRecords_t l_records;

    // Get system target
    Target *pSys;
    targetService().getTopLevelTarget(pSys);

    do
    {
        // Check Block Spec Deconfig value
        if(io_blockAttr == 0)
        {
            // Block Spec Deconfig is already cleared
            HWAS_INF("Block Spec Deconfig already cleared");
        }

        // Create the predicate with HWAS changed state and our GARD_APPLIED bit
        PredicateHwasChanged l_predicateHwasChanged;
        l_predicateHwasChanged.changedBit(HWAS_CHANGED_BIT_GARD_APPLIED, true);

        // Go through all targets
        for (TargetIterator t_iter = targetService().begin();
             t_iter != targetService().end();
             ++t_iter)
        {
            Target* l_pTarget = *t_iter;

            // Check if target has gard applied
            if (l_predicateHwasChanged(l_pTarget))
            {
                // Get gard records for the target
                l_pErr = platGetGardRecords(l_pTarget, l_records);
                if (l_pErr)
                {
                    break;
                }

                // If there are gard records, continue to next target
                if (l_records.size() > 0)
                {
                    continue;
                }

                // Check if Block Spec Deconfig is set
                if(io_blockAttr == 1)
                {
                    io_blockAttr = 0;
                    pSys->setAttr<ATTR_BLOCK_SPEC_DECONFIG>(io_blockAttr);
                    HWAS_INF("Block Spec Deconfig cleared due to no gard "
                             "records for 0x%.8x",
                             get_huid(l_pTarget));
                }

                // Clear GARD_APPLIED bit in HWAS changed flags for the target
                HWAS_INF("HWAS_CHANGED_BIT_GARD_APPLIED cleared for 0x%.8x",
                         get_huid(l_pTarget));
                clear_hwas_changed_bit(l_pTarget,
                                       HWAS_CHANGED_BIT_GARD_APPLIED);
            }
        } // for
    } while (0);

    return l_pErr;
} // clearBlockSpecDeconfigForUngardedTargets

} // namespace HWAS

OpenPOWER on IntegriCloud