summaryrefslogtreecommitdiffstats
path: root/src/include/usr/fapi2/target.H
blob: 940e5b62e476412ba6858b591e9fe6372c99f358 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/usr/fapi2/target.H $                              */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2016                        */
/* [+] 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 target.H
///
/// @brief Defines the platform target functions that needs to be
/// specialized for platform implementation.
///
/**
 * @file target.H
 * @brief platform specializations for fapi2 targets
 */

#ifndef __FAPI2_TARGET__
#define __FAPI2_TARGET__

#include <plat_target.H>
#include <stdio.h>
#include <stdint.h>
#include <vector>
#include <target_types.H>
#include <return_code_defs.H>
#include <fapi2_target.H>

#include <hwpf_fapi2_reasoncodes.H>


// HB platform support
#include <fapiPlatTrace.H>
#include <targeting/common/target.H>
#include <targeting/common/commontargeting.H>
#include <targeting/common/targetservice.H>
#include <targeting/common/utilFilter.H>
#include <targeting/common/predicates/predicatectm.H>
#include <targeting/common/predicates/predicateisfunctional.H>

//@TODO RTC:150675 get error info from getOtherEnd fails
//#include <errl/errlentry.H>
//#include <errl/errlmanager.H>



namespace PLAT_TARGET
{
///
/// @brief         Helper function for specialized system target allows
///                for the constructor to call targetservice::getTopLevel
/// @param[in/out] io_handle Reference to TARGETING::Target to assign
///                iv_handle to.
/// @return void
///
void systemTargCtorHelperFunc(fapi2::plat_target_handle_t& io_handle);
}

namespace fapi2
{


///
/// @brief         Specialization for TARGET_TYPE_SYSTEM targets
///                for the constructor to call targetservice::getTopLevel
/// @param[in/out] io_handle Reference to TARGETING::Target to assign
///                iv_handle to.
/// @return void
///
/// @note          the default templated constructor is delagated to constructors
///                take take in a plat_target_handle_t
///
template<>
inline Target<TARGET_TYPE_SYSTEM, plat_target_handle_t>
::Target(const plat_target_handle_t& v)
{
    PLAT_TARGET::systemTargCtorHelperFunc(iv_handle);
}

///
/// @brief Assignment Operator.
/// @tparam K The type of target of which this is called
/// @tparam V the type of the target's Value
/// @param[in] i_right Reference to Target to assign from.
/// @return Reference to 'this' Target
///
template<TargetType K, typename V>
Target<K, V>& Target<K, V>::operator=(const Target& i_right)
{ iv_handle = i_right.iv_handle; return *this; }

///
/// @brief Equality Comparison Operator
/// @tparam K The type of target of which this is called
/// @tparam V the type of the target's Value
/// @param[in] i_right Reference to Target to compare.
/// @return bool. True if equal.
/// @note This platform uses handles for comparison as
/// target handles are statically defined so the order
/// is consistent.
///
template<TargetType K, typename V>
bool Target<K, V>::operator==(const Target& i_right) const
{ return i_right.iv_handle == iv_handle; }

///
/// @brief Inquality Comparison Operator
/// @tparam K The type of target of which this is called
/// @tparam V the type of the target's Value
/// @param[in] i_right Reference to Target to compare.
/// @return bool. True if not equal.
/// @note This platform uses handles for comparison as
/// target handles are statically defined so the order
/// is consistent.
///
template<TargetType K, typename V>
bool Target<K, V>::operator!=(const Target& i_right) const
{ return i_right.iv_handle != iv_handle; }

///
/// @brief Less Than Comparison Operator
/// @param[in] i_right Reference to Target to compare.
/// @return bool. True if less than i_right
/// @note This platform uses handles for comparison as
/// target handles are statically defined so the order
/// is consistent.
///
template<TargetType K, typename V>
bool Target<K, V>::operator<(const Target& i_right) const
{
    return  iv_handle < i_right.iv_handle;
}

///
/// @brief This function takes in a FAPI2 Type and returns the corresponding
///         TARGETING::Target type
///
/// @param[in] i_fapi2Type
///
/// @returns TARGETTING::Type equivelent to fapi2 type
inline TARGETING::TYPE convertFapi2TypeToTargeting(fapi2::TargetType i_T)
{
    TARGETING::TYPE o_targetingType = TARGETING::TYPE_NA;

   switch (i_T)
    {
        case fapi2::TARGET_TYPE_NONE:
            o_targetingType = TARGETING::TYPE_NA;
            break;
        case fapi2::TARGET_TYPE_SYSTEM:
            o_targetingType = TARGETING::TYPE_SYS;
            break;
        case fapi2::TARGET_TYPE_DIMM:
            o_targetingType = TARGETING::TYPE_DIMM;
            break;
        case fapi2::TARGET_TYPE_PROC_CHIP:
            o_targetingType = TARGETING::TYPE_PROC;
            break;
        case fapi2::TARGET_TYPE_MEMBUF_CHIP:
            o_targetingType = TARGETING::TYPE_MEMBUF;
            break;
        case fapi2::TARGET_TYPE_EX:
            o_targetingType = TARGETING::TYPE_EX;
            break;
        case fapi2::TARGET_TYPE_MBA:
            o_targetingType = TARGETING::TYPE_MBA;
            break;
        case fapi2::TARGET_TYPE_MCS:
            o_targetingType = TARGETING::TYPE_MCS;
            break;
        case fapi2::TARGET_TYPE_XBUS:
            o_targetingType = TARGETING::TYPE_XBUS;
            break;
        case fapi2::TARGET_TYPE_ABUS:
            o_targetingType = TARGETING::TYPE_ABUS;
            break;
        case fapi2::TARGET_TYPE_L4:
            o_targetingType = TARGETING::TYPE_L4;
            break;
        case fapi2::TARGET_TYPE_CORE:
            o_targetingType = TARGETING::TYPE_CORE;
            break;
        case fapi2::TARGET_TYPE_EQ:
            o_targetingType = TARGETING::TYPE_EQ;
            break;
        case fapi2::TARGET_TYPE_MCA:
            o_targetingType = TARGETING::TYPE_MCA;
            break;
        case fapi2::TARGET_TYPE_MCBIST:
            o_targetingType = TARGETING::TYPE_MCBIST;
            break;
        case fapi2::TARGET_TYPE_MI:
            o_targetingType = TARGETING::TYPE_MI;
            break;
        case fapi2::TARGET_TYPE_CAPP:
            o_targetingType = TARGETING::TYPE_CAPP;
            break;
        case fapi2::TARGET_TYPE_DMI:
            o_targetingType = TARGETING::TYPE_DMI;
            break;
        case fapi2::TARGET_TYPE_OBUS:
            o_targetingType = TARGETING::TYPE_OBUS;
            break;
        case fapi2::TARGET_TYPE_NV:
            o_targetingType = TARGETING::TYPE_NV;
            break;
        case fapi2::TARGET_TYPE_SBE:
            o_targetingType = TARGETING::TYPE_SBE;
            break;
        case fapi2::TARGET_TYPE_PPE:
            o_targetingType = TARGETING::TYPE_PPE;
            break;
        case fapi2::TARGET_TYPE_PERV:
            o_targetingType = TARGETING::TYPE_PERV;
            break;
        case fapi2::TARGET_TYPE_PEC:
            o_targetingType = TARGETING::TYPE_PEC;
            break;
        case fapi2::TARGET_TYPE_PHB:
            o_targetingType = TARGETING::TYPE_PHB;
            break;
        default:
            FAPI_ERR("convertFapi2TypeToTargeting:: Chiplet type not supported 0x%.8X!", i_T);
            assert(false);
            break;
    }

    return o_targetingType;
}


///
/// @brief Get this target's immediate parent
/// @tparam T The desired type of the parent target
/// @tparam K The type of target of which this is called
/// @tparam V the type of the target's Value
/// @return Target<T> a target representing the parent
///
template<TargetType K, typename V>
template<TargetType T>
inline Target<T, V> Target<K, V>::getParent(void) const
{

    FAPI_DBG(ENTER_MRK "getParent. Type of parent 0x%08x", T);

    // General compound chiplet check for proc parent

    const fapi2::TargetType TARGET_TYPE_PROC_CHIPLETS = fapi2::TARGET_TYPE_EX |
            fapi2::TARGET_TYPE_MCS |
            fapi2::TARGET_TYPE_XBUS |
            fapi2::TARGET_TYPE_CORE |
            fapi2::TARGET_TYPE_EQ |
            fapi2::TARGET_TYPE_MCA |
            fapi2::TARGET_TYPE_MCBIST |
            fapi2::TARGET_TYPE_MI |
            fapi2::TARGET_TYPE_CAPP |
            fapi2::TARGET_TYPE_DMI |
            fapi2::TARGET_TYPE_OBUS |
            fapi2::TARGET_TYPE_NV |
            fapi2::TARGET_TYPE_SBE |
            fapi2::TARGET_TYPE_PPE |
            fapi2::TARGET_TYPE_PERV |
            fapi2::TARGET_TYPE_PEC |
            fapi2::TARGET_TYPE_PHB;

    static_assert( !((T == fapi2::TARGET_TYPE_PROC_CHIP) &&
                     ((K & TARGET_TYPE_PROC_CHIPLETS) == fapi2::TARGET_TYPE_NONE)),
                   "fapi2::TARGET_TYPE_PROC_CHIP is not a valid parent" );

    const fapi2::TargetType TARGET_TYPE_PERV_CHIPLETS = fapi2::TARGET_TYPE_EQ |
            fapi2::TARGET_TYPE_CORE |
            fapi2::TARGET_TYPE_XBUS |
            fapi2::TARGET_TYPE_OBUS |
            fapi2::TARGET_TYPE_CAPP |
            fapi2::TARGET_TYPE_NV |
            fapi2::TARGET_TYPE_MCBIST |
            fapi2::TARGET_TYPE_MCS |
            fapi2::TARGET_TYPE_MCA |
            fapi2::TARGET_TYPE_MI |
            fapi2::TARGET_TYPE_DMI |
            fapi2::TARGET_TYPE_PEC |
            fapi2::TARGET_TYPE_PHB;

    static_assert( !((T == fapi2::TARGET_TYPE_PERV) &&
                     ((K & TARGET_TYPE_PERV_CHIPLETS) == fapi2::TARGET_TYPE_NONE)),
                   "fapi2::TARGET_TYPE_PERV is not a valid parent" );

    // Specific parent checks for each TargetType

    // valid parents for DIMM
    // DIMM -> MCA
    // DIMM -> MBA
    static_assert(!((K == fapi2::TARGET_TYPE_DIMM) &&
                    (T != fapi2::TARGET_TYPE_MCA) &&
                    (T != fapi2::TARGET_TYPE_MBA)),
                  "improper parent of fapi2::TARGET_TYPE_DIMM");

    // valid parents for PROC
    // PROC -> SYSTEM
    static_assert(!((K == fapi2::TARGET_TYPE_PROC_CHIP) &&
                    (T != fapi2::TARGET_TYPE_SYSTEM)),
                  "improper parent of fapi2::TARGET_TYPE_PROC_CHIP");

    // valid parents for MEMBUF
    // MEMBUF -> SYSTEM
    // MEMBUF -> DMI
    static_assert(!((K == fapi2::TARGET_TYPE_MEMBUF_CHIP) &&
                    (T != fapi2::TARGET_TYPE_SYSTEM) &&
                    (T != fapi2::TARGET_TYPE_DMI)),
                  "improper parent of fapi2::TARGET_TYPE_MEMBUF_CHIP");

    // valid parents for EX
    // EX -> EQ
    // EX -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_EX) &&
                    (T != fapi2::TARGET_TYPE_EQ) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_EX");

    // valid parents for MBA
    // MBA -> MEMBUF
    static_assert(!((K == fapi2::TARGET_TYPE_MBA) &&
                    (T != fapi2::TARGET_TYPE_MEMBUF_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_MBA");

    // valid parents for MCS
    // MCS -> MCBIST
    // MCS -> PERV
    // MCS -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_MCS) &&
                    (T != fapi2::TARGET_TYPE_MCBIST) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_MCS");

    // valid parents for L4
    // L4 -> MEMBUF
    static_assert(!((K == fapi2::TARGET_TYPE_L4) &&
                    (T != fapi2::TARGET_TYPE_MEMBUF_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_L4");

    // valid parents for CORE
    // CORE -> EX
    // CORE -> EQ
    // CORE -> PERV
    // CORE -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_CORE) &&
                    (T != fapi2::TARGET_TYPE_EX) &&
                    (T != fapi2::TARGET_TYPE_EQ) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_CORE");

    // valid parents for EQ
    // EQ -> PROC
    // EQ -> PERV
    static_assert(!((K == fapi2::TARGET_TYPE_EQ) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_EQ");

    // valid parents for MCA
    // MCA -> MCS
    // MCA -> MCBIST
    // MCA -> PERV
    // MCA -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_MCA) &&
                    (T != fapi2::TARGET_TYPE_MCS) &&
                    (T != fapi2::TARGET_TYPE_MCBIST) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_MCA");

    // valid parents for MCBIST
    // MCBIST -> PERV
    // MCBIST -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_MCBIST) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_MCBIST");

    // valid parents for MI
    // MI -> PERV
    // MI -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_MI) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_MI");

    // valid parents for DMI
    // DMI -> MI
    // DMI -> PERV
    // DMI -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_DMI) &&
                    (T != fapi2::TARGET_TYPE_MI) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_DMI");

    // valid parents for SBE
    // SBE -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_SBE) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_SBE");

    // valid parents for PPE
    // PPE -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_PPE) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_PPE");

    // valid parents for PERV
    // PERV -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_PERV");

    // valid parents for PEC
    // PEC -> PERV
    // PEC -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_PEC) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_PEC");

    // valid parents for PHB
    // PHB -> PERV
    // PHB -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_PHB) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_PHB");

    // valid parents for XBUS
    // XBUS -> PERV
    // XBUS -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_XBUS) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_XBUS");

    // valid parents for OBUS
    // OBUS -> PERV
    // OBUS -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_OBUS) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_OBUS");

    // valid parents for NV
    // NV -> PERV
    // NV -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_NV) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_NV");

    // valid parents for CAPP
    // CAPP -> PERV
    // CAPP -> PROC
    static_assert(!((K == fapi2::TARGET_TYPE_CAPP) &&
                    (T != fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP)),
                  "improper parent of fapi2::TARGET_TYPE_CAPP");



    TARGETING::TargetHandleList l_parentList;

    TARGETING::TYPE requiredPType = fapi2::convertFapi2TypeToTargeting(T);

    if(T == fapi2::TARGET_TYPE_PERV)
    {
        TARGETING::getParentPervasiveTargetsByState(
            l_parentList,
            static_cast<TARGETING::Target*>(this->get()),
            TARGETING::CLASS_NA,
            requiredPType,
            TARGETING::UTIL_FILTER_ALL);
    }
    else
    {
        TARGETING::getParentAffinityTargetsByState(
            l_parentList,
            static_cast<TARGETING::Target*>(this->get()),
            TARGETING::CLASS_NA,
            requiredPType,
            TARGETING::UTIL_FILTER_ALL);
    }

    assert(l_parentList.size() == 1, "Found %d parents of the same type. Target HUID %x ,\
          looking for parents of type %x", l_parentList.size(), TARGETING::get_huid(this->get()) , requiredPType);

    TARGETING::Target * l_parentTarget = l_parentList[0];

    assert(l_parentTarget != NULL,
                "No parent of type %x was found for the target of type %x \
                Found required parent plat type to be %x", T, K, requiredPType)


    Target<T> outTarget(l_parentTarget);
    FAPI_DBG(EXIT_MRK "getParent");
    return outTarget;
}

///
/// @brief Get this target's children
/// @tparam T The desired type of child target
/// @tparam K The type of target of which this is called
/// @tparam V the type of the target's Value
/// @param[in] i_state The desired TargetState of the children
/// @return std::vector<Target<T> > a vector of present/functional
/// children
/// @warning The children of EX's (cores) are expected to be returned
/// in order. That is, core 0 is std::vector[0].
///
template<TargetType K, typename V>
template< TargetType T>
inline std::vector<Target<T, V> >
    Target<K, V>::getChildren(const TargetState i_state) const
{

FAPI_DBG(ENTER_MRK "getChildren. Type 0x%08x State:0x%08x", T, i_state);
#define INVALID_CHILD(PARENT, CHILD) \
    static_assert(!((K == PARENT) && (T == CHILD)), \
                  #CHILD " is not a child of " #PARENT );

    // invalid children for proc
    INVALID_CHILD(fapi2::TARGET_TYPE_PROC_CHIP, fapi2::TARGET_TYPE_NONE)
    INVALID_CHILD(fapi2::TARGET_TYPE_PROC_CHIP, fapi2::TARGET_TYPE_SYSTEM)
    INVALID_CHILD(fapi2::TARGET_TYPE_PROC_CHIP, fapi2::TARGET_TYPE_DIMM)
    INVALID_CHILD(fapi2::TARGET_TYPE_PROC_CHIP, fapi2::TARGET_TYPE_PROC_CHIP)
    INVALID_CHILD(fapi2::TARGET_TYPE_PROC_CHIP, fapi2::TARGET_TYPE_MEMBUF_CHIP)
    INVALID_CHILD(fapi2::TARGET_TYPE_PROC_CHIP, fapi2::TARGET_TYPE_MBA)
#undef INVALID_CHILD

    // valid children for PERV
    // PERV -> EQ
    // PERV -> CORE
    // PERV -> XBUS
    // PERV -> OBUS
    // PERV -> CAPP
    // PERV -> NV
    // PERV -> MCBIST
    // PERV -> MCS
    // PERV -> MCA
    // PERV -> PEC
    // PERV -> PHB
    // PERV -> MI
    // PERV -> DMI
    static_assert(!((K == fapi2::TARGET_TYPE_PERV) &&
                    (T != fapi2::TARGET_TYPE_EQ) &&
                    (T != fapi2::TARGET_TYPE_CORE) &&
                    (T != fapi2::TARGET_TYPE_XBUS) &&
                    (T != fapi2::TARGET_TYPE_OBUS) &&
                    (T != fapi2::TARGET_TYPE_CAPP) &&
                    (T != fapi2::TARGET_TYPE_NV) &&
                    (T != fapi2::TARGET_TYPE_MCBIST) &&
                    (T != fapi2::TARGET_TYPE_MCS) &&
                    (T != fapi2::TARGET_TYPE_MCA) &&
                    (T != fapi2::TARGET_TYPE_PEC) &&
                    (T != fapi2::TARGET_TYPE_PHB) &&
                    (T != fapi2::TARGET_TYPE_MI) &&
                    (T != fapi2::TARGET_TYPE_DMI)),
                  "improper child of fapi2::TARGET_TYPE_PERV");

    // valid children for MEMBUF
    // MEMBUF -> L4
    // MEMBUF -> MBA
    static_assert(!((K == fapi2::TARGET_TYPE_MEMBUF_CHIP) &&
                    (T != fapi2::TARGET_TYPE_L4) &&
                    (T != fapi2::TARGET_TYPE_MBA)),
                  "improper child of fapi2::TARGET_TYPE_MEMBUF_CHIP");

    // valid children for system
    // SYSTEM -> PROC
    // SYSTEM -> MEMBUF
    // SYSTEM -> DIMM ??? disabled for now
    static_assert(!((K == fapi2::TARGET_TYPE_SYSTEM) &&
                    (T != fapi2::TARGET_TYPE_PROC_CHIP) &&
                    (T != fapi2::TARGET_TYPE_MEMBUF_CHIP)),
                  "improper child of fapi2::TARGET_TYPE_SYSTEM");

    // valid children for EQ
    // EQ -> CORE
    // EQ -> EX
    static_assert(!((K == fapi2::TARGET_TYPE_EQ) &&
                    (T != fapi2::TARGET_TYPE_CORE) &&
                    (T != fapi2::TARGET_TYPE_EX)),
                  "improper child of fapi2::TARGET_TYPE_EQ");

    // valid children for EX
    // EX -> CORE
    static_assert(!((K == fapi2::TARGET_TYPE_EX) &&
                    (T != fapi2::TARGET_TYPE_CORE)),
                  "improper child of fapi2::TARGET_TYPE_EX");

    // Nimbus Memory
    // valid children for MCS
    // MCS -> MCA
    static_assert(!((K == fapi2::TARGET_TYPE_MCS) &&
                    (T != fapi2::TARGET_TYPE_MCA)),
                  "improper child of fapi2::TARGET_TYPE_MCS");

    // valid children for MCA
    // MCA -> DIMM
    static_assert(!((K == fapi2::TARGET_TYPE_MCA) &&
                    (T != fapi2::TARGET_TYPE_DIMM)),
                  "improper child of fapi2::TARGET_TYPE_MCA");

    // valid children for MCBIST
    // MCBIST -> MCA
    // MCBIST -> MCS
    static_assert(!((K == fapi2::TARGET_TYPE_MCBIST) &&
                    (T != fapi2::TARGET_TYPE_MCA) &&
                    (T != fapi2::TARGET_TYPE_MCS)),
                  "improper child of fapi2::TARGET_TYPE_MCBIST");

    // Cumulus Memory
    // valid children for MI
    // MI -> DMI
    static_assert(!((K == fapi2::TARGET_TYPE_MI) &&
                    (T != fapi2::TARGET_TYPE_DMI)),
                  "improper child of fapi2::TARGET_TYPE_MI");

    // valid children for DMI
    // DMI -> MEMBUF
    static_assert(!((K == fapi2::TARGET_TYPE_DMI) &&
                    (T != fapi2::TARGET_TYPE_MEMBUF_CHIP)),
                  "improper child of fapi2::TARGET_TYPE_DMI");

    // valid children for MBA
    // MBA -> DIMM
    static_assert(!((K == fapi2::TARGET_TYPE_MBA) &&
                    (T != fapi2::TARGET_TYPE_DIMM)),
                  "improper child of fapi2::TARGET_TYPE_MBA");

    //Check that we are not calling this on a target with no children
    static_assert((K != fapi2::TARGET_TYPE_NONE),
                  "fapi2::TARGET_TYPE_NONE has no children");
    static_assert((K != fapi2::TARGET_TYPE_XBUS),
                  "fapi2::TARGET_TYPE_XBUS has no children");
    static_assert((K != fapi2::TARGET_TYPE_ABUS),
                  "fapi2::TARGET_TYPE_ABUS has no children");
    static_assert((K != fapi2::TARGET_TYPE_L4),
                  "fapi2::TARGET_TYPE_L4 has no children");
    static_assert((K != fapi2::TARGET_TYPE_CORE),
                  "fapi2::TARGET_TYPE_CORE has no children");
    static_assert((K != fapi2::TARGET_TYPE_CAPP),
                  "fapi2::TARGET_TYPE_CAPP has no children");
    static_assert((K != fapi2::TARGET_TYPE_OBUS),
                  "fapi2::TARGET_TYPE_OBUS has no children");
    static_assert((K != fapi2::TARGET_TYPE_NV),
                  "fapi2::TARGET_TYPE_NV has no children");
    static_assert((K != fapi2::TARGET_TYPE_SBE),
                  "fapi2::TARGET_TYPE_SBE has no children");
    static_assert((K != fapi2::TARGET_TYPE_PPE),
                  "fapi2::TARGET_TYPE_PPE has no children");
    static_assert((K != fapi2::TARGET_TYPE_PEC),
                  "fapi2::TARGET_TYPE_PEC has no children");
    static_assert((K != fapi2::TARGET_TYPE_PHB),
                  "fapi2::TARGET_TYPE_PHB has no children");


    std::vector<Target<T>> l_children;
    //Get the platform target type of the current fapi2::target
    TARGETING::TYPE l_type = fapi2::convertFapi2TypeToTargeting(T);
    TARGETING::TargetHandleList l_childList;
    bool l_functional = (i_state & fapi2::TARGET_STATE_FUNCTIONAL)? true:false;

    if(!l_functional)
    {
        if(K == fapi2::TARGET_TYPE_PERV)
        {
            TARGETING::getPervasiveChildTargetsByState(l_childList,
                          static_cast<TARGETING::Target*>(this->get()),
                          TARGETING::CLASS_NA,
                          l_type,
                          TARGETING::UTIL_FILTER_ALL);
        }
        else
        {
            TARGETING::getChildAffinityTargetsByState(l_childList,
                          static_cast<TARGETING::Target*>(this->get()),
                          TARGETING::CLASS_NA,
                          l_type,
                          TARGETING::UTIL_FILTER_ALL);
        }
    }
    else
    {
        if(K == fapi2::TARGET_TYPE_PERV)
        {
            TARGETING::getPervasiveChildTargetsByState(l_childList,
                          static_cast<TARGETING::Target*>(this->get()),
                          TARGETING::CLASS_NA,
                          l_type,
                          TARGETING::UTIL_FILTER_FUNCTIONAL);
        }
        else
        {
             TARGETING::getChildAffinityTargetsByState(l_childList,
                          static_cast<TARGETING::Target*>(this->get()),
                          TARGETING::CLASS_NA,
                          l_type,
                          TARGETING::UTIL_FILTER_FUNCTIONAL);
        }
    }

    FAPI_DBG("getChildren: l_functional 0x%.8X, l_type = 0x%.8X, ChipUnitId 0x%.8X",
                l_functional, l_type, TARGETING::get_huid(this->get()));
    FAPI_DBG("getChildren: l_childList size %d", l_childList.size());

    // Return fapi2::Targets to the caller
    for (TARGETING::TargetHandleList::const_iterator
            chipletIter = l_childList.begin();
            chipletIter != l_childList.end();
            ++chipletIter)
    {
        fapi2::Target<T> l_target(*chipletIter);
        l_children.push_back(l_target);
    }
    FAPI_DBG(EXIT_MRK "getChildren. %d results", l_children.size());

    return l_children;
}


///
/// @brief Get this target's children, filtered
/// @tparam T The type of the parent
/// @tparam K The type of target of which this is called
/// @tparam V the type of the target's Value
/// @param[in] i_filter The desired chiplet filter
/// @param[in] i_state The desired TargetState of the children
/// @return std::vector<Target<T> > a vector of present/functional
/// children
///
template<TargetType K, typename V>
template< TargetType T>
inline std::vector<Target<T, V> >
    Target<K, V>::getChildren(const TargetFilter i_filter,
                              const TargetState i_state) const
{
    std::vector<Target<T>> l_children;

    l_children = this->getChildren<T>(i_state);

    FAPI_DBG("getChildrenFilter: Tgt=0x%.8X, i_filter=0x%.16X,"
             "K-Type=0x%.8X, T-Type=0x%.8X, sizeA=%d",
             TARGETING::get_huid(this->get()), i_filter, K, T, l_children.size());

    // Limit to getting Pervasive children from proc_chip parent for now
    //@TODO RTC:155755 to track possible additional support
    static_assert(((T == fapi2::TARGET_TYPE_PERV) &&
                   (K == fapi2::TARGET_TYPE_PROC_CHIP)),
                   "fapi2::getChildren-Filter only supports getting fapi2::TARGET_TYPE_PERV children on a fapi2::TARGET_TYPE_PROC_CHIP");

    for ( auto childIter =  l_children.begin();
               childIter != l_children.end();
               // ++childIter incremented below
        )
    {
        const TARGETING::Target * l_platTarget =
                         static_cast<const TARGETING::Target*>(childIter->get());
        uint8_t  l_chiplet_num = 0;
        uint32_t l_fapi2_type = childIter->getType();
        uint64_t l_bitMask = 0x0;

        // ATTR_CHIP_UNIT represents the Pervasive Chiplet numbering and is
        // needed to create the l_bitMask to use against i_filter
        if(!l_platTarget->tryGetAttr<TARGETING::ATTR_CHIP_UNIT>(l_chiplet_num))
        {
            FAPI_ERR("ERROR: getChildrenFilter: Can not read CHIP_UNIT attribute"
                     "Keeping Target 0x%lx for 0x%x", l_platTarget, T);
            l_bitMask = 0xFFFFFFFFFFFFFFFF;
        }
        else
        {
            l_bitMask = 0x8000000000000000 >> l_chiplet_num;
        }

        if (i_filter & l_bitMask) // keep child
        {
          FAPI_DBG("getChildrenFilter: keep child=0x%.8X, type=0x%.8X, l_bitMask=0x%.16X, num=0x%.2X",
                   TARGETING::get_huid(l_platTarget), l_fapi2_type, l_bitMask, l_chiplet_num );

          ++childIter;
        }
        else // remove child
        {
          childIter = l_children.erase(childIter); // this increments childIter

          FAPI_DBG("getChildrenFilter: removed child=0x%.8X, type=0x%.8X, l_bitMask=0x%.16X, num=0x%.2X",
                   TARGETING::get_huid(l_platTarget), l_fapi2_type, l_bitMask, l_chiplet_num );
        }
    }

    // Return filtered fapi2::Targets to the caller
    return l_children;
}

///
/// @brief Get the target at the other end of a bus
/// @tparam T The type of the target on the other end
/// @param[out] o_target A target representing the thing on the other end
/// @param[in] i_state The desired TargetState of the other end
/// @return FAPI2_RC_SUCCESS if OK, platforms will return a non-success
/// ReturnCode in the event of failure
/// @note o_target is only valid if return is FAPI2_RC_SUCCESS
///
template<TargetType K, typename V>
template<TargetType T>
inline fapi2::ReturnCodes
Target<K, V>::getOtherEnd(fapi2::Target<T, V>& o_target,
                          const TargetState i_state) const
{
    ReturnCodes l_rc;
//     errlHndl_t l_errl = NULL;
    TARGETING::TargetHandleList l_peerTargetList;
    TARGETING::CLASS targetClass = TARGETING::CLASS_NA;

    // Only supporting these relationships:
    //  XBUS <-> XBUS
    //  ABUS <-> ABUS
    //  OBUS <-> OBUS

    static_assert( K==T, "both ends must be of same fapi2::TARGET_TYPE");
    static_assert ( ( (K==fapi2::TARGET_TYPE_XBUS) ||
                      (K==fapi2::TARGET_TYPE_ABUS) ||
                      (K==fapi2::TARGET_TYPE_OBUS) ),
                    "Only types of XBUS, ABUS, and OBUS are supported");

    // for the supported types above, only one option supported
    targetClass = TARGETING::CLASS_UNIT;

    TARGETING::PredicateCTM l_peerFilter(targetClass,
                                         fapi2::convertFapi2TypeToTargeting(T));

    if(i_state == TARGET_STATE_FUNCTIONAL)
    {
        TARGETING::PredicateIsFunctional l_funcFilter;
        TARGETING::PredicatePostfixExpr l_funcAndpeerFilter;
        l_funcAndpeerFilter.push(&l_peerFilter).push(&l_funcFilter).And();
        getPeerTargets( l_peerTargetList,    // list of targets on other end
        static_cast<TARGETING::Target*>(this->get()),//To this target
        NULL/*&l_peerFilter*/, // Don't need to filter peers
        &l_funcAndpeerFilter);//filter results to be the right class & state
    }
    else if(i_state == TARGET_STATE_PRESENT)
    {
        TARGETING::PredicatePostfixExpr l_presAndpeerFilter;
        l_presAndpeerFilter.push(&l_peerFilter);

        getPeerTargets( l_peerTargetList,   // list of targets on other end
        static_cast<TARGETING::Target*>(this->get()), //to this target
        NULL,                               //No need to filter peers
        &l_presAndpeerFilter);//filter results to be the right class & state
    }

    fapi2::Target<T> fapi2_peerTarget = NULL;

    if(l_peerTargetList.size() == 0)
    {
        l_rc = FAPI2_RC_FALSE;
        //@TODO RTC:150675 get error info from getOtherEnd fails
#if 0
        /*@
        * @errortype          ERRORLOG::ERRL_SEV_UNRECOVERABLE
        * @moduleid           fapi2::MOD_FAPI2_PLAT_GET_OTHER_END
        * @reasoncode         fapi2::RC_FOUND_NO_PEERS
        * @userdata1[0:31]    Unused
        * @userdata1[32:63]   Unused
        * @userdata2          Unused
        * @devdesc            Unable to resolve other end of xbus
        */
        l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                      fapi2::MOD_FAPI2_PLAT_GET_OTHER_END,
                                      fapi2::RC_FOUND_NO_PEERS,
                                      NULL,
                                      NULL,
                                      true/*SW Error*/);
        errlCommit(l_errl,FAPI2_COMP_ID);
        // Add the error log pointer as data to the ReturnCode
        l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_errl));
#endif
    }
    else if(l_peerTargetList.size() > 1)
    {
        l_rc = FAPI2_RC_FALSE;
        //@TODO RTC:150675 get error info from getOtherEnd fails
#if 0
        /*@
        * @errortype          ERRORLOG::ERRL_SEV_UNRECOVERABLE
        * @moduleid           fapi2::MOD_FAPI2_PLAT_GET_OTHER_END
        * @reasoncode         fapi2::RC_FOUND_TOO_MANY_PEERS
        * @userdata1[0:31]    Unused
        * @userdata1[32:63]   Unused
        * @userdata2          Unused
        * @devdesc            Unable to resolve other end of xbus
        */
        l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                      fapi2::MOD_FAPI2_PLAT_GET_OTHER_END,
                                      fapi2::RC_FOUND_TOO_MANY_PEERS,
                                      NULL,
                                      NULL,
                                      true/*SW Error*/);
        errlCommit(l_errl,FAPI2_COMP_ID);
        // Add the error log pointer as data to the ReturnCode
        l_rc.setPlatDataPtr(reinterpret_cast<void *> (l_err));
#endif
    }
    else
    {
        fapi2_peerTarget = fapi2::Target<T>(l_peerTargetList[0]);
    }
    o_target = fapi2_peerTarget;

    return l_rc;
}


///
/// @brief Determine whether the target is functional or not
/// @return true if the target is functional, false otherwise
///
template< TargetType K, typename V >
inline bool Target< K, V >::isFunctional(void) const
{
    TARGETING::PredicateIsFunctional l_functional;
    return l_functional(static_cast<TARGETING::Target*>(this->get()));
}


///
/// @brief Return the string interpretation of this target
/// @tparam T The type of the target
/// @param[in] i_target Target<T>
/// @param[in/out] io_buffer buffer to write in to
/// @param[in] i_bsize size of the buffer
/// @return void
/// @post The contents of the buffer is replaced with the string
/// representation of the target
///
template< TargetType T, typename V >
inline void toString(const Target<T, V>& i_target, char* io_buffer, size_t i_bsize)
{
    TARGETING::ATTR_FAPI_NAME_type l_nameString = {0};
    const TARGETING::Target * l_platTarget =
                          static_cast<const TARGETING::Target*>(i_target.get());

    if(!l_platTarget->tryGetAttr<TARGETING::ATTR_FAPI_NAME>(l_nameString))
    {
      FAPI_ERR("ERROR: Can not read FAPI_NAME attribute");
      snprintf(io_buffer, i_bsize, "Target 0x%lx/0x%x", l_platTarget, T);
    }
    else
    {
      size_t needed_buffer_size = strlen((const char*)l_nameString) + 1;

      // Is i_buffer large enough for the entire string + null
      if (i_bsize < needed_buffer_size)
      {
        FAPI_INF("Should use a larger buffer size (%d instead of %d) for %s",
                  needed_buffer_size, i_bsize, l_nameString);
        memcpy(io_buffer, l_nameString, i_bsize);
        if (i_bsize > 0)
        {
          io_buffer[i_bsize-1] = '\0';
        }
      }
      else
      {
        // copy full attribute string + null character
        memcpy(io_buffer, l_nameString, needed_buffer_size);
      }
    }
}

///
/// @brief Return the string interpretation of this target
/// @tparam T The type of the target
/// @param[in] A pointer to the Target<T>
/// @param[in/out] io_buffer buffer to write in to
/// @param[in] i_bsize size of the buffer
/// @return void
/// @post The contents of the buffer is replaced with the string
/// representation of the target
///
template< TargetType T, typename V >
inline void toString(const Target<T, V> *i_target, char* io_buffer, size_t i_bsize)
{
    toString(*i_target, io_buffer, i_bsize);
}

///
/// @brief Get an enumerated target of a specific type
/// @tparam T The type of the target
/// @param[in] Ordinal representing the ordinal number of
/// the desired target
/// @return Target<T> the target requested
///
template<TargetType T, typename V>
inline Target<T, V> getTarget(uint64_t Ordinal)
{
  //@TODO RTC:129517
    // For testing
    return Target<T>(Ordinal);
}

///
/// @brief Returns the chiplet number associated with the Target
/// @return The chiplet number for the Target. 0 is returned if the
/// Target does not have a chiplet number (for ex, the PROC_CHIP Target)
/// @note For logical targets such as the EX, the chiplet number of
/// their immediate parent chiplet is returned
///
template< TargetType K, typename V >
inline uint8_t Target< K, V >::getChipletNumber(void) const
{
    const TARGETING::Target * l_pTarget =
        static_cast<TARGETING::Target*>(this->get());
    uint8_t  l_chiplet_id = 0;
    if(!l_pTarget->tryGetAttr<TARGETING::ATTR_CHIPLET_ID>(l_chiplet_id))
    {
        FAPI_ERR("ERROR: getChipletNumber: Can not read CHIPLET_ID attribute");
    }
    return l_chiplet_id;
}

} // End namespace fapi2

#endif // End __FAPI2_TARGET__
OpenPOWER on IntegriCloud