summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/framework/service/prdfTargetServices.C
blob: 8958f787f776cf26ca67e3670fc5e6d1fa5b6956 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/framework/service/prdfTargetServices.C $    */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012                   */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

/**
 * @file prdfTargetServices.C
 * @brief PRD wrapper of targetting code
 */

//------------------------------------------------------------------------------
//  Includes
//------------------------------------------------------------------------------

#include <prdfTargetServices.H>

#include <algorithm>

#include <iipbits.h>
#include <iipsdbug.h>
#include <iipglobl.h>
#include <prdfTrace.H>

#include <errlentry.H>
#include <fapi.H>
#include <targeting/common/targetservice.H>

using namespace TARGETING;

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

namespace PRDF
{

namespace PlatServices
{

//##############################################################################
//##
//##                 Target Manipulation Utility Functions
//##
//##############################################################################

// FIXME: This function is using type PRDF::HUID. I think it should now be using
//        TARGETING::HUID_ATTR. Also, will need equivalent to
//        PRDF::INVALID_HUID. I think HWSV has HWSV_INVALID_HUID, but I don't
//        think that exists in Hostboot. Need a common interface before making
//        changes.
TARGETING::TargetHandle_t getTarget( HUID i_huid )
{
    TargetHandle_t o_target = NULL;

    // FIXME: This is an incredibly inefficient linear search. It is recommended
    //        that the common targeting code provide an interface for us so that
    //        all users can call the potentially optimized function. There is a
    //        function available in HWSV (hwsvTargetUtil.H) but not in Hostboot.
    //        Sadly, the HWSV code does this exact linear search.
    TargetService & l_targetService = targetService();
    for ( TargetIterator l_targetPtr = l_targetService.begin();
          l_targetPtr != l_targetService.end(); ++l_targetPtr )
    {
        if ( i_huid == (l_targetPtr->getAttr<ATTR_HUID>()) )
        {
            o_target = (*l_targetPtr);
            break;
        }
    }

    if ( NULL == o_target )
    {
        PRDF_ERR( "[getTarget] i_huid: 0x%08x failed", i_huid );
    }

    return o_target;
}

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

TARGETING::TargetHandle_t getTarget( const TARGETING::EntityPath & i_path )
{
    TargetHandle_t o_target = targetService().toTarget( i_path );
    if ( NULL == o_target )
    {
        PRDF_ERR( "[getTarget] Failed: i_path=" ); i_path.dump();
    }

    return o_target;
}

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

int32_t getEntityPath( TARGETING::TargetHandle_t i_target,
                       TARGETING::EntityPath & o_path,
                       TARGETING::EntityPath::PATH_TYPE i_pathType )
{
    int32_t o_rc = FAIL;

    do
    {
        if ( NULL == i_target ) break;

        if ( EntityPath::PATH_NA != i_pathType )
            o_path.setType( i_pathType );

        ATTRIBUTE_ID attr = ATTR_NA;
        switch ( o_path.type() )
        {
            case EntityPath::PATH_AFFINITY: attr = ATTR_AFFINITY_PATH; break;
            case EntityPath::PATH_PHYSICAL: attr = ATTR_PHYS_PATH;     break;
            case EntityPath::PATH_POWER:    attr = ATTR_POWER_PATH;    break;
            default: ;
        }
        if ( ATTR_NA == attr )
        {
            PRDF_ERR( "[getEntityPath] Unsupported EntityPath type %d",
                      o_path.type() );
            break;
        }

        if ( !targetService().tryGetPath(attr, i_target, o_path) )
        {
            PRDF_ERR( "[getEntityPath] Failed to get path %d", attr );
            break;
        }

        o_rc = SUCCESS;

    } while (0);

    if ( SUCCESS != o_rc )
    {
        PRDF_ERR( "[getEntityPath] Failed: i_target=0x%08x",
                  getHuid(i_target) );
    }

    return o_rc;
}

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

HUID getHuid( TARGETING::TargetHandle_t i_target )
{
    HUID o_huid = INVALID_HUID;

    do
    {
        if ( NULL == i_target ) break; // return INVALID_HUID

        // TODO: get_huid() (src/include/usr/targeting/common/util.H) can be
        //       called to fetch HUID however this feature is not yet available
        //       in FSP yet.
        if ( !i_target->tryGetAttr<ATTR_HUID>(o_huid) )
        {
            PRDF_ERR( "[getHuid] Failed to get ATTR_HUID" );
            o_huid = INVALID_HUID; // Just in case.
        }

    } while (0);

    return o_huid;
}

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

bool isFunctional( TARGETING::TargetHandle_t i_target )
{
    bool o_funcState = false;

    do
    {
        if ( NULL == i_target )
        {
            PRDF_ERR( "[isFunctional] i_target is NULL" );
            break;
        }

        HwasState l_funcState;
        if ( !i_target->tryGetAttr<ATTR_HWAS_STATE>(l_funcState) )
        {
            PRDF_ERR( "[isFunctional] Failed to get ATTR_HWAS_STATE" );
            break;
        }

        if ( l_funcState.functional ) o_funcState =true;
    } while (0);

    return o_funcState;
}

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

TARGETING::TYPE getTargetType( TARGETING::TargetHandle_t i_target )
{
    TYPE o_type = TYPE_LAST_IN_RANGE;

    if ( NULL != i_target )
    {
        if ( !i_target->tryGetAttr<ATTR_TYPE>(o_type) )
        {
            PRDF_ERR( "[getTargetType] Failed to get ATTR_TYPE" );
            o_type = TYPE_LAST_IN_RANGE; // Just in case
        }
    }

    if ( TYPE_LAST_IN_RANGE == o_type )
    {
        PRDF_ERR( "[getTargetType] Failed: i_target=0x%08x",
                  getHuid(i_target) );
    }

    return o_type;
}

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

TARGETING::CLASS getTargetClass( TARGETING::TargetHandle_t i_target )
{
    CLASS o_class = CLASS_NA;

    if ( NULL != i_target )
    {
        if ( !i_target->tryGetAttr<ATTR_CLASS>(o_class) )
        {
            PRDF_ERR( "[getTargetClass] Failed to get ATTR_CLASS" );
            o_class = CLASS_NA; // Just in case
        }
    }

    if ( CLASS_NA == o_class )
    {
        PRDF_ERR( "[getTargetClass] Failed: i_target=0x%08x",
                  getHuid(i_target) );
    }

    return o_class;
}

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

void printTargetInfo( TARGETING::TargetHandle_t i_target )
{
    EntityPath l_path ( EntityPath::PATH_PHYSICAL );
    int32_t l_rc = getEntityPath( i_target, l_path );
    if ( SUCCESS == l_rc )
    {
        PRDF_DTRAC( "PRDCONFIG: HUID=0x%08x path=", getHuid(i_target) );
        l_path.dump();
    }
    else
    {
        PRDF_ERR( "[printTargetInfo] Failed: i_target=0x%08x",
                  getHuid(i_target) );
    }
}

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

uint8_t getChipLevel( TARGETING::TargetHandle_t i_target )
{
    uint8_t o_chipLvl = 0;

    do
    {
        if ( NULL == i_target ) break;

        TargetHandle_t l_parentTarget = getParentChip( i_target );
        if ( NULL == l_parentTarget ) break;

        if ( !l_parentTarget->tryGetAttr<ATTR_EC>(o_chipLvl) )
        {
            PRDF_ERR( "[getChipLevel] Failed to get ATTR_EC" );
            o_chipLvl = 0xff; // Just in case
        }

    } while (0);

    if ( 0 == o_chipLvl )
    {
        PRDF_ERR( "[getChipLevel] Failed: i_target=0x%08x", getHuid(i_target) );
    }

    return o_chipLvl;
}

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

/* TODO: getChipId() may be available in an attribute, but this design has not
 *       been solidified. Instead, we may need to query for 'reason' attributes
 *       to determine the reason we need to do the checks. Since we don't have
 *       any immediate need for these functions (no workarounds as of yet), we
 *       will leave them commented out in the code.
uint8_t getChipId( TARGETING::TargetHandle_t i_target )
{
    // Returns chip ID enum (i.e. P7, P7+, etc.)
    return 0;
}
*/

//##############################################################################
//##
//##                       getConnected() support functions
//##
//##############################################################################

// This is a helper function for getConnected(). It will return the association
// type (CHILD_BY_AFFINITY or PARENT_BY_AFFINITY) between a target and
// destination target type. The function only characterizes parent or child
// relationships. It does not do any peer-to-peer relationships. The function
// will return non-SUCCESS if a relationship is not supported.

struct conn_t
{
    TYPE from : 8;
    TYPE to : 8;
    TargetService::ASSOCIATION_TYPE type : 8;

    bool operator<( const conn_t & r )
    {
        if ( this->from == r.from )
            return ( this->to < r.to );
        else
            return ( this->from < r.from );
    }

} PACKED;

int32_t getAssociationType( TARGETING::TargetHandle_t i_target,
                            TARGETING::TYPE i_connType,
                            TARGETING::TargetService::ASSOCIATION_TYPE & o_type)
{
    int32_t o_rc = SUCCESS;

    static conn_t lookups[] =
    {
        // This table must be sorted based on the < operator of struct conn_t.
        // FIXME: Create a Cxx test case that will catch if the values of the
        //        TYPE enum changes.
        { TYPE_NODE, TYPE_DIMM,   TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_MEMBUF, TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_PROC,   TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_EX,     TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_CORE,   TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_L2,     TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_L3,     TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_L4,     TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_MCS,    TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_MBS,    TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_MBA,    TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_XBUS,   TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_ABUS,   TargetService::CHILD_BY_AFFINITY },
        { TYPE_NODE, TYPE_PCI,    TargetService::CHILD_BY_AFFINITY },

        { TYPE_DIMM, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_DIMM, TYPE_MEMBUF, TargetService::PARENT_BY_AFFINITY },
        { TYPE_DIMM, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_DIMM, TYPE_MCS,    TargetService::PARENT_BY_AFFINITY },
        { TYPE_DIMM, TYPE_MBA,    TargetService::PARENT_BY_AFFINITY },

        { TYPE_MEMBUF, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_MEMBUF, TYPE_DIMM,   TargetService::CHILD_BY_AFFINITY  },
        { TYPE_MEMBUF, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_MEMBUF, TYPE_L4,     TargetService::CHILD_BY_AFFINITY  },
        { TYPE_MEMBUF, TYPE_MCS,    TargetService::PARENT_BY_AFFINITY },
        { TYPE_MEMBUF, TYPE_MBS,    TargetService::CHILD_BY_AFFINITY  },
        { TYPE_MEMBUF, TYPE_MBA,    TargetService::CHILD_BY_AFFINITY  },

        { TYPE_PROC, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_PROC, TYPE_DIMM,   TargetService::CHILD_BY_AFFINITY  },
        { TYPE_PROC, TYPE_MEMBUF, TargetService::CHILD_BY_AFFINITY  },
        { TYPE_PROC, TYPE_EX,     TargetService::CHILD_BY_AFFINITY  },
        { TYPE_PROC, TYPE_CORE,   TargetService::CHILD_BY_AFFINITY  },
        { TYPE_PROC, TYPE_L2,     TargetService::CHILD_BY_AFFINITY  },
        { TYPE_PROC, TYPE_L3,     TargetService::CHILD_BY_AFFINITY  },
        { TYPE_PROC, TYPE_L4,     TargetService::CHILD_BY_AFFINITY  },
        { TYPE_PROC, TYPE_MCS,    TargetService::CHILD_BY_AFFINITY  },
        { TYPE_PROC, TYPE_MBS,    TargetService::CHILD_BY_AFFINITY  },
        { TYPE_PROC, TYPE_MBA,    TargetService::CHILD_BY_AFFINITY  },
        { TYPE_PROC, TYPE_XBUS,   TargetService::CHILD_BY_AFFINITY  },
        { TYPE_PROC, TYPE_ABUS,   TargetService::CHILD_BY_AFFINITY  },
        { TYPE_PROC, TYPE_PCI,    TargetService::CHILD_BY_AFFINITY  },

        { TYPE_EX, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_EX, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_EX, TYPE_CORE,   TargetService::CHILD_BY_AFFINITY  },
        { TYPE_EX, TYPE_L2,     TargetService::CHILD_BY_AFFINITY  },
        { TYPE_EX, TYPE_L3,     TargetService::CHILD_BY_AFFINITY  },

        { TYPE_CORE, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_CORE, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_CORE, TYPE_EX,     TargetService::PARENT_BY_AFFINITY },

        { TYPE_L2, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_L2, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_L2, TYPE_EX,     TargetService::PARENT_BY_AFFINITY },

        { TYPE_L3, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_L3, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_L3, TYPE_EX,     TargetService::PARENT_BY_AFFINITY },

        { TYPE_MBS, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_MBS, TYPE_MEMBUF, TargetService::PARENT_BY_AFFINITY },
        { TYPE_MBS, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_MBS, TYPE_MCS,    TargetService::PARENT_BY_AFFINITY },

        { TYPE_MCS, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_MCS, TYPE_DIMM,   TargetService::CHILD_BY_AFFINITY  },
        { TYPE_MCS, TYPE_MEMBUF, TargetService::CHILD_BY_AFFINITY  },
        { TYPE_MCS, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_MCS, TYPE_L4,     TargetService::CHILD_BY_AFFINITY  },
        { TYPE_MCS, TYPE_MBS,    TargetService::CHILD_BY_AFFINITY  },
        { TYPE_MCS, TYPE_MBA,    TargetService::CHILD_BY_AFFINITY  },

        { TYPE_MBS, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_MBS, TYPE_MEMBUF, TargetService::PARENT_BY_AFFINITY },
        { TYPE_MBS, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_MBS, TYPE_MCS,    TargetService::PARENT_BY_AFFINITY },

        { TYPE_MBA, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_MBA, TYPE_DIMM,   TargetService::CHILD_BY_AFFINITY  },
        { TYPE_MBA, TYPE_MEMBUF, TargetService::PARENT_BY_AFFINITY },
        { TYPE_MBA, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_MBA, TYPE_MCS,    TargetService::PARENT_BY_AFFINITY },

        { TYPE_XBUS, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_XBUS, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },

        { TYPE_ABUS, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_ABUS, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },

        { TYPE_PCI, TYPE_NODE,   TargetService::PARENT_BY_AFFINITY },
        { TYPE_PCI, TYPE_PROC,   TargetService::PARENT_BY_AFFINITY },
    };

    const size_t sz_lookups = sizeof(lookups) / sizeof(conn_t);

    conn_t match = { getTargetType(i_target), i_connType,
                     TargetService::CHILD_BY_AFFINITY };

    conn_t * it = std::lower_bound( lookups, lookups + sz_lookups, match );

    if ( it != lookups + sz_lookups )
        o_type = it->type;
    else
    {
        PRDF_ERR( "[getAssociationType] Failed: i_target=0x%08x i_connType=%d",
                  getHuid(i_target), i_connType );
        o_rc = FAIL;
    }

    return o_rc;
}

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

// Helper function to return a parent or container target of a specified type.
// For example, get EX target from CORE or PROC target from MEMBUF. Note, that
// the input target could be the parent. Will return NULL if the parent is not
// found. For example, a DIMM could not be a parent of a PROC.
TARGETING::TargetHandle_t getParent( TARGETING::TargetHandle_t i_target,
                                     TARGETING::TYPE i_connType )
{
    TARGETING::TargetHandle_t o_target = i_target; // Assume it is the parent.

    if ( i_connType != getTargetType(i_target) )
    {
        TargetHandleList list = getConnected( i_target, i_connType );
        o_target = ( 1 == list.size() ) ? list[0] : NULL;
    }

    if ( NULL == o_target )
    {
        PRDF_ERR( "[getParent] Failed: i_target=0x%08x i_connType=%d",
                  getHuid(i_target), i_connType );
    }

    return o_target;
}

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

TARGETING::TargetHandleList getConnected( TARGETING::TargetHandle_t i_target,
                                          TARGETING::TYPE i_connType )
{
    TargetHandleList o_list; // Default empty list

    do
    {
        // Parameter checks. Error trace output is in NULL check below.
        if ( NULL == i_target ) break;

        TargetService::ASSOCIATION_TYPE l_assocType;
        int32_t l_rc = getAssociationType( i_target, i_connType, l_assocType );
        if ( SUCCESS != l_rc ) break;

        // Match any class, specified type, and functional.
        PredicateCTM predType( CLASS_NA, i_connType );
        PredicateIsFunctional predFunc;
        PredicatePostfixExpr predAnd;
        predAnd.push(&predType).push(&predFunc).And();

        targetService().getAssociated( o_list, i_target, l_assocType,
                                       TargetService::ALL, &predAnd );

    } while(0);

    if ( 0 == o_list.size() )
    {
        PRDF_ERR( "[getConnected] Failed: i_target=0x%08x i_connType=%d",
                  getHuid(i_target), i_connType );
    }

    return o_list;
}

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

TARGETING::TargetHandle_t getConnectedPeerProc(
                                         TARGETING::TargetHandle_t i_procTarget,
                                         TARGETING::TYPE i_busType,
                                         uint32_t i_busPos )
{
    #define FUNC "[getConnectedPeerProc] "

    TargetHandle_t o_target = NULL;

    do
    {
        // Parameter checks. Error trace output is in NULL check below.
        if ( NULL == i_procTarget ) break;

        if ( TYPE_PROC != getTargetType(i_procTarget) )
        {
            PRDF_ERR( FUNC"Given target is not of TYPE_PROC" ); break;
        }

        if ( !( ((TYPE_XBUS == i_busType) && (MAX_XBUS_PER_PROC > i_busPos)) ||
                ((TYPE_ABUS == i_busType) && (MAX_ABUS_PER_PROC > i_busPos)) ) )
            break;

        // Starting PROC -> starting XBUS/ABUS.
        TargetHandleList list = getConnected( i_procTarget, i_busType );
        TargetHandle_t busTarget = NULL;
        for (TargetHandleList::iterator i = list.begin(); i != list.end(); ++i)
        {
            if ( i_busPos == getTargetPosition(*i) )
            {
                busTarget = *i;
                break; // for loop
            }
        }
        if ( NULL == busTarget )
        {
            PRDF_ERR( FUNC"Couldn't find connected bus" ); break;
        }

        // Starting XBUS/ABUS -> ATTR_PEER_TARGET -> destination XBUS/ABUS.
        TargetHandle_t destTarget = NULL;
// FIXME - ATTR_PEER_TARGET support has not been ported to FSP yet.
//        if ( !busTarget->tryGetAttr<ATTR_PEER_TARGET>(destTarget) )
        if ( true )
        {
            PRDF_ERR( FUNC"Couldn't find destination bus" ); break;
        }

        // Destination XBUS/ABUS <-> destination PROC.
        list = getConnected( destTarget, TYPE_PROC );
        if ( 1 != list.size() )
        {
            PRDF_ERR( FUNC"Couldn't find destination PROC" ); break;
        }
        o_target = list[0];

    } while(0);

    if ( NULL == o_target )
    {
        PRDF_ERR( FUNC"Failed: i_procTarget=0x%08x i_busType=%d i_busPos=%d",
                  getHuid(i_procTarget), i_busType, i_busPos );
    }

    #undef FUNC

    return o_target;
}

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

TARGETING::TargetHandle_t getSystemTarget()
{
    TargetHandle_t sysTarget = NULL;
    targetService().getTopLevelTarget( sysTarget );

    if ( NULL == sysTarget )
    {
        PRDF_ERR( "[getSystemTarget] Failed" );
    }

    return sysTarget;
}

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

TARGETING::TargetHandle_t getParentChip( TARGETING::TargetHandle_t i_target )
{
    TargetHandle_t o_chipTarget = NULL;

    CLASS l_class = getTargetClass( i_target );
    switch ( l_class )
    {
        case CLASS_CHIP:
            o_chipTarget = i_target;
            break;

        case CLASS_UNIT:
        {
            TargetHandleList l_list;
            PredicateCTM l_predClass( CLASS_CHIP );
            targetService().getAssociated( l_list, i_target,
                                           TargetService::PARENT,
                                           TargetService::IMMEDIATE,
                                           &l_predClass );
            if ( 1 == l_list.size() )
            {
                o_chipTarget = l_list[0];
            }
            else
            {
                PRDF_ERR( "[getParentChip] Could not find parent chip" );
            }
            break;
        }

        default:
            PRDF_ERR( "[getParentChip] Unsupported class: %d", l_class );
    }

    if ( NULL == o_chipTarget )
    {
        PRDF_ERR( "[getParentChip] Failed: i_target=0x%08x",
                  getHuid(i_target) );
    }

    return o_chipTarget;
}

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

TARGETING::TargetHandleList getFunctionalTargetList( TARGETING::TYPE i_type )
{
    TargetHandleList o_list; // Default empty list.

    TargetService & l_targetService = targetService();

    // Match any class, specified type, and functional.
    PredicateCTM l_predType( CLASS_NA, i_type );
    PredicateIsFunctional l_predFunc;
    PredicatePostfixExpr l_predAnd;
    l_predAnd.push(&l_predType).push(&l_predFunc).And();

    // Defining a filter to get a list of all targets of i_type.
    TargetRangeFilter l_filter( l_targetService.begin(), l_targetService.end(),
                                &l_predAnd );
    for( ; l_filter; ++l_filter )
    {
        // Adding functional target to the vector.
        o_list.push_back( *l_filter );
    }

    if ( 0 == o_list.size() )
    {
        PRDF_ERR( "[getFunctionalTargetList] Failed: i_type=%d", i_type );
    }

    return o_list;
}

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

// FIXME: In the past, this was a wrapper for a GARD interface. Need to make
//        sure that we have the equivelant functionality.
bool checkLastFuncCore( TARGETING::TargetHandle_t i_coreTarget )
{
    bool o_lastCore = false;

    // TODO: Possibly support TYPE_EX, TYPE_L2, and TYPE_L3 as target input.

    TargetHandleList l_list = getFunctionalTargetList( TYPE_CORE );
    if ( 1 == l_list.size() && l_list[0] == i_coreTarget )
        o_lastCore = true;

    return o_lastCore;
}

//##############################################################################
//##
//##                       Target position support code
//##
//##############################################################################

uint32_t getTargetPosition( TARGETING::TargetHandle_t i_target )
{
    #define FUNC "[getTargetPosition] "

    uint32_t o_pos = INVALID_POSITION_BOUND;

    CLASS l_class = getTargetClass( i_target );
    switch ( l_class )
    {
        case CLASS_CHIP:
        {
            TYPE l_type = getTargetType( i_target );
            switch ( l_type )
            {
                case TYPE_PROC:
                {
                    uint16_t tmpPos = 0;
                    if ( !i_target->tryGetAttr<ATTR_POSITION>(tmpPos) )
                        PRDF_ERR( FUNC"Failed to get ATTR_POSITION" );
                    else
                        o_pos = (uint32_t)tmpPos;
                    break;
                }

                case TYPE_MEMBUF:
                    o_pos = getMemChnl( i_target );
                    break;

                default:
                    PRDF_ERR( FUNC"Unsupported type: %d", l_type );
            }
            break;
        }

        case CLASS_UNIT:
        {
            uint8_t tmpPos = 0;
            if ( !i_target->tryGetAttr<ATTR_CHIP_UNIT>(tmpPos) )
                PRDF_ERR( FUNC"Failed to get ATTR_CHIP_UNIT" );
            else
                o_pos = (uint32_t)tmpPos;
            break;
        }

        case CLASS_ENC:
            o_pos = getNodePosition( i_target );
            break;

        default:
            PRDF_ERR( FUNC"Unsupported class: %d", l_class );
    }

    if ( INVALID_POSITION_BOUND == o_pos )
    {
        PRDF_ERR( FUNC"Failed: target=0x%08x", getHuid(i_target) );
    }

    #undef FUNC

    return o_pos;
}

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

uint32_t getNodePosition( TARGETING::TargetHandle_t i_target )
{
    uint32_t o_pos = INVALID_POSITION_BOUND;

    do
    {
        // Get the node handle.
        TargetHandle_t l_node = NULL;
        TargetHandleList l_list = getConnected( i_target, TYPE_NODE );
        if ( 1 == l_list.size() )
            l_node = l_list[0];
        else
        {
            PRDF_ERR( "[getNodePosition] Failed to get node target" );
            break;
        }

        // FIXME: While this code works, it is preferred to use the POSITION
        //        attribute of the node. Currently, this attribute does not
        //        exist but it will, eventually. (RTC WI expected from Nick
        //        Bofferding)
        EntityPath l_path ( EntityPath::PATH_PHYSICAL );
        int32_t l_rc = getEntityPath( l_node, l_path );
        if ( SUCCESS != l_rc ) break;

        o_pos = l_path[l_path.size()-1].instance;

    } while (0);

    if ( INVALID_POSITION_BOUND == o_pos )
    {
        PRDF_ERR( "[getNodePosition] Failed: target=0x%08x",
                  getHuid(i_target) );
    }

    return o_pos;
}

//##############################################################################
//##
//##                       DUMP and Runtime Deconfig support code
//##
//##############################################################################

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

errlHndl_t dumpHWURequest(errlHndl_t i_errl, HUID i_huid )
{
    // FIXME : need to implement this once P8 DUMP support is in
    PRDF_ERR( "[dumpHWURequest] i_huid=0x%08x - Function not implemented yet", i_huid );

    return NULL;
}

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

errlHndl_t runtimeDeconfig( HUID i_huid )
{
    // FIXME : need to implement this once Story 42422
    //        in CEC HW Enablement is done
    PRDF_ERR( "[runtimeDeconfig] i_huid=0x%08x - Function not implemented yet", i_huid );

    return NULL;
}

//##############################################################################
//##
//##                        Memory specific functions
//##
//##############################################################################

int32_t getMasterRanks( TARGETING::TargetHandle_t i_memTarget,
                        uint32_t i_portSlct, uint32_t i_dimmSlct,
                        std::vector<uint32_t> & o_ranks )
{
    int32_t o_rc = FAIL;

    do
    {
        if ( NULL == i_memTarget ) break;

        if ( (MAX_PORT_PER_MBA  <= i_portSlct) ||
             (MAX_DIMM_PER_PORT <= i_dimmSlct) )
            break;

        TARGETING::TargetHandle_t mbaTarget = getParent(i_memTarget, TYPE_MBA);
        if ( NULL == mbaTarget ) break;

        uint8_t rankInfo[MAX_PORT_PER_MBA][MAX_DIMM_PER_PORT];
        if( !mbaTarget->tryGetAttr<ATTR_EFF_DIMM_RANKS_CONFIGED>(rankInfo) )
        {
            PRDF_ERR( "[getMasterRanks] Failed to get attribute" );
            break;
        }

        uint8_t rankMask = rankInfo[i_portSlct][i_dimmSlct];
        if ( 0 == (rankMask & 0xf0) )
        {
            PRDF_ERR( "[getMasterRanks] Attribute value invalid: 0x%02x",
                      rankMask );
            break;
        }

        for ( uint32_t rank = 0; rank < 4; rank++ )
        {
            if ( 0 != (rankMask & (0x80 >> rank)) )
            {
                o_ranks.push_back(rank);
            }
        }

        o_rc = SUCCESS;

    } while (0);

    if ( SUCCESS != o_rc )
    {
        PRDF_ERR( "[getMasterRanks] Failed: i_memTarget=0x%08x i_portSlct=%d "
                  "i_dimmSlct=%d",
                  getHuid(i_memTarget), i_portSlct, i_dimmSlct );
    }

    return o_rc;
}

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

uint32_t getMemChnl( TARGETING::TargetHandle_t i_memTarget )
{
    uint32_t o_chnl = INVALID_POSITION_BOUND; // Intentially set to
                                              // INVALID_POSITION_BOUND for call
                                              // from getTargetPosition().

    do
    {
        if ( NULL == i_memTarget ) break;

        TARGETING::TargetHandle_t mcsTarget = getParent(i_memTarget, TYPE_MCS);
        if ( NULL == mcsTarget ) break;

        o_chnl = getTargetPosition( mcsTarget );

    } while (0);

    if ( MAX_MCS_PER_PROC <= o_chnl ) // Real MCS position check.
    {
        PRDF_ERR( "[getMemChnl] Failed: i_memTarget=0x%08x",
                  getHuid(i_memTarget) );
    }

    return o_chnl;
}

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

int32_t isMembufOnDimm( TARGETING::TargetHandle_t i_memTarget,
                        bool & o_isBuffered )
{
    int32_t o_rc = FAIL;

    o_isBuffered = false;

    do
    {
        // The DIMMs in an node should either all be buffered or all not. So we
        // can check the attribute from ANY MBA.
        TargetHandleList list = getConnected( i_memTarget, TYPE_MBA );
        if ( 0 == list.size() )
        {
            PRDF_ERR( "[isMembufOnDimm] Couldn't find an MBA target" );
            break;
        }

        // FIXME - Currently TARGETING::ATTR_EFF_DIMM_TYPE is mapped to
        //         fapi::ATTR_EFF_DIMM_TYPE, but there is no guarantee it will
        //         stay mapped. The values of this attribute is mapped in a fapi
        //         enum, but we are encouraged to use the TARGETING attribute.
        //         Either we need to use fapi::ATTR_EFF_DIMM_TYPE (no preferred)
        //         or get a TARGETING enum (preferred).
        // FIXME - dimmtype should be of an enum type.
        uint8_t dimmtype;
        if ( !list[0]->tryGetAttr<ATTR_EFF_DIMM_TYPE>(dimmtype) )
        {
            PRDF_ERR( "[isMembufOnDimm] Failed to get DIMM type" );
            break;
        }

        // FIXME - See note above.
        if ( fapi::ENUM_ATTR_EFF_DIMM_TYPE_CDIMM == dimmtype )
            o_isBuffered = true;

        o_rc = SUCCESS;

    } while (0);

    if ( SUCCESS != o_rc )
    {
        PRDF_ERR( "[isMembufOnDimm] Failed: i_memTarget=0x%08x",
                  getHuid(i_memTarget) );
    }

    return o_rc;
}

//##############################################################################
//##
//##                        Clock specific functions
//##
//##############################################################################

bool areClocksOn(TARGETING::TargetHandle_t i_pGivenTarget)
{
    bool o_clocksOn = false;

    #ifdef __HOSTBOOT_MODULE

    // TODO No such target or attribute available for now
    o_clocksOn = true;

    #else

    if ( NULL != i_pGivenTarget )
    {
        errlHndl_t errl = NULL;
        // TODO: all relevant header files are not exported yet
        //errl =HWSV::hwsvClockQueryOn(i_pGivenTarget,
        //                  HWSV::NO_MODE, o_clocksOn);
        if ( NULL != errl )
        {
            PRDF_ERR( "[areClocksOn] In areClocksOn failed" );
            PRDF_COMMIT_ERRL(errl, ERRL_ACTION_REPORT);
        }
    }
    else
    {
        PRDF_ERR( "[areClocksOn] given target is null" );
    }

    #endif

    return o_clocksOn;
}

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

TARGETING::TargetHandle_t getClockId(TARGETING::TargetHandle_t
                            i_pGivenTarget,
                            TARGETING ::TYPE targetype)
{
    TargetHandleList l_clockCardlist;
    TargetHandle_t o_pClockCardHandle = NULL;

    // TODO  Cards are not getting modeled for now
    return o_pClockCardHandle ;
}

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

TARGETING::TargetHandle_t getClockMux(TARGETING::TargetHandle_t
                            i_pGivenTarget)
{
    //Modeling info of card and Clock mux is required
    //TODO specify correct association type needs to be determined.
    // PredicateCTM l_ClockMux(CLASS_UNIT,TYPE_CLOCK_MUX);
    //defined for compilation
    PredicateCTM l_ClockMux(CLASS_UNIT);
    TargetHandle_t o_ptargetClockMux = NULL;
    //TODO: Clock support for target not present yet.
    #if 0
    do
    {
        if(NULL != i_pGivenTarget)
        {
            TargetHandleList l_list;
            if(TYPE_PROC==(i_pGivenTarget->getAttr<ATTR_TYPE>()))
            {
                    targetService().getAssociated(l_list,
                                        i_pGivenTarget,
                                        TargetService::CHILD_BY_AFFINITY,
                                        TargetService::ALL,
                                        &l_ClockMux);
            }
            else
            {
                //TODO: If given target is not a proc  how to query all mux units
                //      which relation  to be used
            }

            if (l_list.size() > 0)
            {
                // Pick out first item
                o_ptargetClockMux = l_list[0];
            }
        }
        else
        {
            PRDF_ERR("[getClockMux] given target is NULL");
        }
    }while(0);
    #endif
    return o_ptargetClockMux;
}

} // end namespace PlatServices

} // end namespace PRDF

OpenPOWER on IntegriCloud