summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/framework/resolution/prdfCallouts.H
blob: c7eaab21f94c95e27d6ec6c2f6d170e8a03bb70b (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/framework/resolution/prdfCallouts.H $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2000,2014              */
/*                                                                        */
/* 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                                                     */

#ifndef prdfCallouts_H
#define prdfCallouts_H

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

#include <prdfCalloutMap.H>
#include <prdfCalloutsData.H>
#include <prdfEnums.H>
#include <prdfMemoryMru.H>
#include <prdfPlatServices.H>

namespace PRDF
{

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

typedef CalloutPriorityEnum PRDpriority;

/**
 * @brief Wrapper class for PRD callouts (TargetHandle_t, MemoryMru, and
 *        SymbolicFru).
 * @note  It is a requirement that all supported callout types have a 32-bit
 *        representation for storage in the service data collector.
 * @note  This is a simple container of callout types. It does not translate
 *        between the different types.
 */
class PRDcallout
{
  public:

    /** @brief Constructor */
    PRDcallout() : iv_type(PRDcalloutData::TYPE_NONE)
    { iv_meldValue.u32 = 0; }

    /** @brief Constructor from TargetHandle_t */
    PRDcallout( TARGETING::TargetHandle_t i_target ) :
        iv_type(PRDcalloutData::TYPE_TARGET)
    { iv_meldValue.target = i_target; }

    /** @brief Constructor from TargetHandle_t
     *         with clock type info
     */
    PRDcallout( TARGETING::TargetHandle_t i_target,
                PRDcalloutData::MruType i_type ) :
        iv_type(i_type)
    { iv_meldValue.target = i_target; }

    /** @brief Constructor from MemoryMru */
    PRDcallout( const MemoryMru & i_memmru ) :
        iv_type(PRDcalloutData::TYPE_MEMMRU)
    { iv_meldValue.u32 = i_memmru.toUint32(); }

    /** @brief Constructor from SymbolicFru */
    PRDcallout( SymbolicFru i_symfru ) : iv_type(PRDcalloutData::TYPE_SYMFRU)
    { iv_meldValue.symfru = i_symfru; }

    /** @brief Constructor from raw data */
    PRDcallout( uint32_t i_val, PRDcalloutData::MruType i_type ) :
        iv_type(i_type)
    {
        switch ( iv_type )
        {
            case PRDcalloutData::TYPE_TARGET:
            case PRDcalloutData::TYPE_PROCCLK:
            case PRDcalloutData::TYPE_PCICLK:
                iv_meldValue.target = PlatServices::getTarget(i_val); break;
            case PRDcalloutData::TYPE_MEMMRU:
            case PRDcalloutData::TYPE_SYMFRU:
                iv_meldValue.u32 = i_val; break;
            default:
                iv_type          = PRDcalloutData::TYPE_NONE;
                iv_meldValue.u32 = 0;
        }
    }

    /** @brief Assignment from TargetHandle_t */
    PRDcallout & operator=( TARGETING::TargetHandle_t i_target )
    {
        iv_type = PRDcalloutData::TYPE_TARGET;
        iv_meldValue.target = i_target;
        return *this;
    }

    /** @brief Assignment from MemoryMru */
    PRDcallout & operator=( const MemoryMru & i_memmru )
    {
        iv_type = PRDcalloutData::TYPE_MEMMRU;
        iv_meldValue.u32 = i_memmru.toUint32();
        return *this;
    }

    /** @brief Assignment from SymbolicFru */
    PRDcallout & operator=( SymbolicFru i_symfru )
    {
        iv_type = PRDcalloutData::TYPE_SYMFRU;
        iv_meldValue.symfru = i_symfru;
        return *this;
    }

    // NOTE: The == operator must be declared within the class definition.
    // Meaning, you can't declare this outside the class:
    //
    //      bool operator==( const PRDcallout & l, const PRDcallout & r ) const;
    //
    // Otherwise, the single-argument constructors listed above will do
    // automatic type conversion, which will allow code like this:
    //
    //      TargetHandle_t t; MemoryMru m;
    //      if ( t == m ) ...
    //
    // The safest way to prevent this is to make all of the single-argument
    // constructors explicit. However, this will force us to create additional
    // code to handle the different callout types. For example,
    // ServiceDataCollector::SetCallout() will need to be implemented for each
    // callout type.

    /** @brief Overloaded == operator */
    bool operator==( const PRDcallout & r ) const
    {
        if ( iv_type == r.iv_type )
        {
            return ( PRDcalloutData::TYPE_TARGET == iv_type )
                    ? iv_meldValue.target == r.iv_meldValue.target
                    : iv_meldValue.u32    == r.iv_meldValue.u32;
        }

        return false;
    }

    /** @brief Returns the callout type. */
    PRDcalloutData::MruType getType() const { return iv_type; }

    /** @returns Returns the TargetHandle_t. */
    TARGETING::TargetHandle_t getTarget() const { return iv_meldValue.target; }

    /** @returns Returns the MemoryMru. */
    MemoryMru getMemMru() const { return MemoryMru(iv_meldValue.u32); }

    /** @brief Returns a uint32_t representation of the callout */
    uint32_t flatten() const
    {
        switch ( iv_type )
        {
            case PRDcalloutData::TYPE_TARGET:
                return PlatServices::getHuid(iv_meldValue.target); break;
            case PRDcalloutData::TYPE_MEMMRU:
            case PRDcalloutData::TYPE_SYMFRU:
                return iv_meldValue.u32; break;
            default:
                return 0;
        }
    }

  private:

    PRDcalloutData::MruType iv_type;

    union
    {
        TARGETING::TargetHandle_t target;
        SymbolicFru               symfru;
        uint32_t                  u32;
    } iv_meldValue;

};

} // end namespace PRDF

#endif /* prdfCallouts_H */

OpenPOWER on IntegriCloud