summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/attn/test/attnfakesys.H
blob: 26ab5946d6e6181bb2e9b16825b405e42515e312 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/attn/test/attnfakesys.H $                        */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,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 __TEST_ATTNFAKESYS_H
#define __TEST_ATTNFAKESYS_H

/**
 * @file attnfakesys.H
 *
 * @brief HBATTN fake system class definition.
 */

#include "../attnscom.H"
#include "attntest.H"
#include "attncomp.H"
#include "attninject.H"
#include <map>

namespace ATTN
{

/**
 * @brief FakeSystem
 *
 * Container that presents an interface to fake hardware
 * implementations.
 */
class FakeSystem : public ScomImpl, public InjectSink
{
    public:

        /**
         * @brief putReg
         *
         * Simulate register modification originating in hardware.
         *
         * @param[in] i_target Target to write register on.
         * @param[in] i_address Register address to write to.
         * @param[in] i_data Data to write to register.
         *
         * @retval[0] No errors.
         * @retval[!0] Unexpected error occurred.
         */
        errlHndl_t putReg(
                TARGETING::TargetHandle_t i_target,
                uint64_t i_address,
                uint64_t i_data);

        /**
         * @brief modifyReg
         *
         * Simulate register modification originating in hardware.
         *
         * @param[in] i_target Target to update register on.
         * @param[in] i_address Register address to update.
         * @param[in] i_data Data to write to register.
         * @param[in] i_op and/or behavior.
         *
         * @retval[0] No errors.
         * @retval[!0] Unexpected error occurred.
         */
        errlHndl_t modifyReg(
                TARGETING::TargetHandle_t i_target,
                uint64_t i_address,
                uint64_t i_data,
                ScomOp i_op);

        /**
         * @brief getReg Register read originating in hardware.
         *
         * @param[in] i_target Target to read register from.
         * @param[in] i_address Register address to read from.
         *
         * @return Register data.
         */
        uint64_t getReg(
                TARGETING::TargetHandle_t i_target,
                uint64_t i_address);

        /**
         * @brief putAttentions
         *
         * Instruct the system to inject the specified attention.
         *
         * @param[in] i_list The attentions to inject.
         *
         * @retval[0] No error occurred.
         * @retval[!0] Unexpected error occurred.
         */
        errlHndl_t putAttentions(
                const PRDF::AttnList & i_list);

        /**
         * @brief clearAttention
         *
         * Instruct the system clear the specified attention.
         *
         * @param[in] i_attn The attention to clear.
         *
         * @retval[0] No error occurred.
         * @retval[!0] Unexpected error occurred.
         */
        errlHndl_t clearAttention(
                const PRDF::AttnData & i_attn);

        /**
         * @brief clearAllAttentions
         *
         * Instruct the system clear all instances of the specified attention.
         *
         * @param[in] i_attn The attention to clear.
         *
         * @retval[0] No error occurred.
         * @retval[!0] Unexpected error occurred.
         */
        errlHndl_t clearAllAttentions(
                const PRDF::AttnData & i_attn);

        /**
         * @brief count
         *
         * For the provided attention type, obtain the number
         * of times it is being reported by the system.
         *
         * @param[in] i_attn The attention type for which the count should be
         *                obtained.
         */
        uint64_t count(
                const PRDF::AttnData & i_attn);

        /**
         * @brief wait
         *
         * Block the calling thread until no attentions are
         * being reported on the system.
         *
         * @param[in] i_maxTimeNs Max amount of time to wait
         *                once system has reached stable state
         *                (number of attentions isn't changing)
         *
         * @retval[true] No attentions being reported.
         * @retval[false].Attentions still being reported
         *                  after waiting i_maxTimeNs.
         */
        bool wait(uint64_t i_maxTimeNs);

        /**
         * @brief wait
         *
         * Block the calling thread until no attentions are
         * being reported on the system.
         */
        void wait();

        /**
         * @brief addReg
         *
         * Register a register implementaion with the system.
         *
         * @param[in] i_address The address for which the implementation
         *              wishes to monitor.
         * @param[in] i_reg The register implementation to add to the system.
         */
        void addReg(
                uint64_t i_address,
                FakeReg & i_reg);

        /**
         * @brief addSource
         *
         * Register an attention source implementation with the system.
         *
         * @param[in] i_targetType The target type for which the implementation
         *              wishes to monitor.
         * @param[in] i_type The attention type for which the implementation
         *              wishes to monitor.
         * @param[in] i_source The source to add to the system.
         */
        void addSource(
                TARGETING::TYPE i_targetType,
                PRDF::ATTENTION_VALUE_TYPE i_type,
                FakeSource & i_source);

        /**
         * @brief putScom Write a register using SCOM.
         *
         * @param[in] i_target Target to write register on.
         * @param[in] i_address Register address to write to.
         * @param[in] i_data Data to write to register.
         *
         * @retval[0] No errors.
         * @retval[!0] Unexpected error occurred.
         */
        errlHndl_t putScom(
                TARGETING::TargetHandle_t i_target,
                uint64_t i_address,
                uint64_t i_data);

        /**
         * @brief getScom Read a register using SCOM.
         *
         * @param[in] i_target Target to read register from.
         * @param[in] i_address Register address to read from.
         * @param[out] o_data Buffer to write register content to.
         *
         * @retval[0] No errors.
         * @retval[!0] Unexpected error occurred.
         */
        errlHndl_t getScom(
                TARGETING::TargetHandle_t i_target,
                uint64_t i_address,
                uint64_t & o_data);

        /**
         * @brief modifyScom RMW a register using SCOM.
         *
         * @param[in] i_target Target to update register on.
         * @param[in] i_address Register address to update.
         * @param[in] i_data Data to write to register.
         * @param[out] o_data Data read from register.
         * @param[in] i_op and/or behavior.
         *
         * @retval[0] No errors.
         * @retval[!0] Unexpected error occurred.
         */
        errlHndl_t modifyScom(
                TARGETING::TargetHandle_t i_target,
                uint64_t i_address,
                uint64_t i_data,
                uint64_t & o_data,
                ScomOp i_op);

        /**
         * @brief dump Dump active attentions to trace.
         */
        void dump();

        /*
         * @brief count Obtain the number of attentions present
         *          on the system.
         *
         * @return The number of attentions present on the system.
         */
        uint64_t count();

        /**
         * @brief ctor
         */
        FakeSystem();

        /**
         * @brief dtor
         */
        virtual ~FakeSystem();

    private:

        /**
         * @brief Reg Register/address association alias.
         */
        typedef std::map<uint64_t, uint64_t> RegAddrDataAssoc;

        /**
         * @brief Regs Registers/target association alias.
         */
        typedef std::map<TARGETING::TargetHandle_t, RegAddrDataAssoc> Regs;

        /**
         * @brief iv_regs Current register content.
         */
        Regs iv_regs;

        /**
         * @brief makeAttnCallbacks
         *
         * Notify registered sources of attention state changes.
         *
         * @param[in] i_list List of attentions changing state.
         * @param[in] i_set Attentions turning on / off.
         *
         * @retval[0] No error occurred.
         * @retval[!0] Unexpected error occurred.
         */
        errlHndl_t makeAttnCallbacks(
                const PRDF::AttnList & i_list,
                bool i_set);

        /**
         * @brief makeRegCallbacks
         *
         * Notify registered registers of content changes.
         *
         * @param[in] i_target Target being updated.
         * @param[in] i_address Address of register being updated.
         * @param[in] i_new Post update register content.
         * @param[in] i_new Pre update register content.
         *
         * @retval[0] No error occurred.
         * @retval[!0] Unexpected error occurred.
         */
        errlHndl_t makeRegCallbacks(
                TARGETING::TargetHandle_t i_target,
                uint64_t i_address,
                uint64_t i_new,
                uint64_t i_old);

        /**
         * @brief clearAttentionUnsafe
         *
         * Thread unsafe wrapper for clearAttention.
         *
         * @param[in] i_attn The attention to clear.
         *
         * @retval[0] No error occurred.
         * @retval[!0] Unexpected error occurred.
         */
        void clearAttentionUnsafe(
                const PRDF::AttnData & i_attn);

        /**
         * @brief putRegUnsafe
         *
         * Thread unsafe wrapper for putReg.
         *
         * @param[in] i_target Target to write register on.
         * @param[in] i_address Register address to write to.
         * @param[in] i_data Data to write to register.
         */
        void putRegUnsafe(
                TARGETING::TargetHandle_t i_target,
                uint64_t i_address,
                uint64_t i_data);

        /**
         * @brief iv_attentions Current active attentions.
         */
        AttnDataMap<uint64_t> iv_attentions;

        /**
         * @brief iv_regImpl registered register implementations.
         */
        std::vector<std::pair<uint64_t, FakeReg *> > iv_regImpl;

        /**
         * @brief Key Registered source key alias.
         */
        typedef std::pair<TARGETING::TYPE, PRDF::ATTENTION_VALUE_TYPE> Key;

        /**
         * @brief Entry Registered source key/value alias.
         */
        typedef std::pair<Key, FakeSource *> Entry;

        /**
         * @brief iv_source Registered sources.
         */
        std::vector<Entry> iv_sources;

        /**
         * @brief iv_mutex Shared data access serialization.
         */
        mutex_t iv_mutex;

        /**
         * @brief iv_cond Zero attentions condition.
         */
        sync_cond_t iv_cond;
};
}
#endif
OpenPOWER on IntegriCloud