summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/test/prdfsimServices.C
blob: c9d119bb5e1b55e8a51677d45da80a4aba512486 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/test/prdfsimServices.C $                    */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,2013              */
/*                                                                        */
/* 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                                                     */

#include "prdfsimServices.H"
#include <prdfPlatServices.H>
#include <prdfMain.H>
#include <prdfTrace.H>
#include <prdfGlobal.H>

#include "prdfsimUtil.H"
#include "prdsimSignatureParser.H"
#include "prdfsimScrDB.H"
#include "prdfsimHomRegisterAccess.H"
#include "prdfsimRasServices.H"

#include <targeting/common/targetservice.H>

namespace PRDF
{

    using namespace TARGETING;
    using namespace PlatServices;

    /**
     *  @brief Returns a reference to the SimServices singleton
     *
     *  @return Reference to the SimServices
     */
    SimServices& getSimServices()
    {
        return PRDF_GET_SINGLETON(theSimServices);
    }

    SimServices::SimServices()
    {
        reset();

        ServiceGeneratorClass & serviceGenerator =
            ServiceGeneratorClass::ThisServiceGenerator();
        serviceGenerator.Initialize();

        // overloading default prdfErrDataService
        // will be deleted in RasServices dtor
        SimErrDataService* l_SimErrDataService = new SimErrDataService();
        serviceGenerator.setErrDataService(*l_SimErrDataService);

        // overloading default Scom Accessor
        // will be deleted in prdfScomService dtor
        SimScomAccessor* l_SimScomAccessor = new SimScomAccessor();
        getScomService().setScomAccessor(*l_SimScomAccessor);

        PRDF_TRAC( "SimServices::SimServices()" );
    }

    SimServices::~SimServices()
    {
        //initTargeting();
        if(true == iv_reinitTarget)
        {
            iv_reinitTarget = false;
            setHwasState(iv_attnList[0].targetHndl, false);
            errlHndl_t l_pErr = NULL;
            //l_pErr = PRDF::initialize();
            if (l_pErr)
            {
                PRDF_ERR( "prdfsimServices::~prdfsimServices(): PRDF::initialize returned error" );
                PRDF_COMMIT_ERRL(l_pErr, ERRL_ACTION_REPORT);
            }
        }

        iv_attnList.clear();

        if(NULL != iv_ScrDB)
        {
            delete iv_ScrDB; iv_ScrDB = NULL;
        }

        if(NULL != iv_SimSignatureParser)
        {
            delete iv_SimSignatureParser; iv_SimSignatureParser = NULL;
        }

        PRDF_TRAC( "SimServices::~SimServices()" );
    }

    void SimServices::reset()
    {
        iv_attnList.clear();

        if(NULL != iv_ScrDB) delete iv_ScrDB;
        iv_ScrDB = new ScrDB();

        if(NULL != iv_SimSignatureParser) delete iv_SimSignatureParser;
        iv_SimSignatureParser = new SimSignatureParser();

        //initTargeting();

        PRDF_TRAC( "SimServices::reset()" );
    }

    void SimServices::startSim()
    {
        PRDF_TRAC( "SimServices::startSim() Test: %s",
            (iv_testName ? iv_testName : "No Test Name specified"));

        errlHndl_t l_pErr = NULL;
        l_pErr = PRDF::main(iv_attnList[0].attnType, iv_attnList);

        if (l_pErr)
        {
            PRDF_ERR( "SimServices::startSim(): PRDF::main returned error" );
            PRDF_COMMIT_ERRL(l_pErr, ERRL_ACTION_REPORT);
        }
        else
        {
            PRDF_INF( "SimServices::startSim(): PRDF::main completed with no error" );
        }
    }

    bool SimServices::endSim()
    {
        bool l_testStatus = false;
        l_testStatus = summarySig();
        PRDF_TRAC( "SimServices::endSim() Test: %s",
                    (iv_testName ? iv_testName : "No Test Name specified"));
        return l_testStatus;
    }

    void SimServices::addAttnEntry(const char * i_epath,
                                       ATTENTION_VALUE_TYPE i_attnType)
    {
        AttnData l_attnEntry;
        l_attnEntry.targetHndl = string2Target(i_epath);
        l_attnEntry.attnType = i_attnType;
        iv_attnList.push_back(l_attnEntry);

        // If the target in sim is not functional,
        // set to functional and destroy the PRD config
        // so new one can be built
        if(false == isFunctional(l_attnEntry.targetHndl))
        {
            iv_reinitTarget = true;
            setHwasState(l_attnEntry.targetHndl, true);
            errlHndl_t l_pErr = NULL;
            //l_pErr = PRDF::initialize();
            if (l_pErr)
            {
                PRDF_ERR( "prdfsimServices::addAttnEntry(): PRDF::initialize returned error" );
                PRDF_COMMIT_ERRL(l_pErr, ERRL_ACTION_REPORT);
            }
        }
    }

    void SimServices::writeScr(const char * i_epath,
                                   uint64_t i_address,
                                   uint64_t i_data)
    {
        TARGETING::Target* l_ptargetHandle = string2Target(i_epath);
        CPU_WORD l_cpuWord[(64)/(sizeof(CPU_WORD)*8)] = {0};
        BIT_STRING_CLASS l_bs(64, l_cpuWord);
        l_bs.SetFieldJustify(0, 32, (i_data >> 32) & 0xFFFFFFFF);
        l_bs.SetFieldJustify(32, 32, (i_data & 0xFFFFFFFF));

        iv_ScrDB->processCmd(l_ptargetHandle,
                             l_bs,
                             i_address,
                             ScrDB::WRITE);
    }

    void SimServices::expectScr(const char * i_epath,
                                    uint64_t i_address,
                                    uint64_t i_data)
    {
        TARGETING::Target* l_ptargetHandle = string2Target(i_epath);
        CPU_WORD l_cpuWord[(64)/(sizeof(CPU_WORD)*8)] = {0};
        BIT_STRING_CLASS l_bs(64, l_cpuWord);
        l_bs.SetFieldJustify(0, 32, (i_data >> 32) & 0xFFFFFFFF);
        l_bs.SetFieldJustify(32, 32, (i_data & 0xFFFFFFFF));

        iv_ScrDB->processCmd(l_ptargetHandle,
                             l_bs,
                             i_address,
                             ScrDB::EXPECT);
    }

    void SimServices::processCmd(TARGETING::TargetHandle_t i_ptargetHandle,
                                     BIT_STRING_CLASS & bs,
                                     uint64_t registerId,
                                     ScrDB::SimOp i_op)
    {
        iv_ScrDB->processCmd(i_ptargetHandle,
                             bs,
                             registerId,
                             i_op);
    }

    void SimServices::addSig(const char * i_epath, uint32_t i_sig)
    {
        TARGETING::Target* l_ptargetHandle = string2Target(i_epath);
        uint32_t i_chip = getHuid(l_ptargetHandle);
        iv_SimSignatureParser->Add(i_chip, i_sig);
    }

    void SimServices::reportSig(uint32_t i_chip, uint32_t i_sig)
    {
        iv_SimSignatureParser->Report(i_chip, i_sig);
    }

    bool SimServices::summarySig()
    {
        return iv_SimSignatureParser->Summary();
    }

    void SimServices::setTestName(const char * i_testName)
    {
        reset();
        iv_testName = i_testName;
    }

    void SimServices::initTargeting()
    {
        //targetService().init();
        TargetService& l_targetService = targetService();
        TargetIterator l_pIt;
        for( l_pIt = l_targetService.begin(); l_pIt != l_targetService.end(); l_pIt++)
        {
            setHwasState(*l_pIt, true);
        }
    }

    void SimServices::setHwasState(TARGETING::TargetHandle_t i_target, bool i_functional)
    {
        HwasState hwasState     = i_target->getAttr<ATTR_HWAS_STATE>();
        PRDF_TRAC("[setHwasState] i_target=0x%08x, func: %d, new func: %d",
                  getHuid(i_target), hwasState.functional, i_functional);

        //hwasState.poweredOn     = true;
        //hwasState.present       = true;
        hwasState.functional    = i_functional;
        i_target->setAttr<ATTR_HWAS_STATE>( hwasState );
    }

} // End namespace PRDF
OpenPOWER on IntegriCloud