summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/test/prdfsimScrDB.C
blob: 25c13ba7eedaaf61c199f5c3e5eec3b959bca401 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/test/prdfsimScrDB.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 "prdfsimScrDB.H"
#include <iipMopRegisterAccess.h>
#include <prdfTrace.H>
#include <prdfPlatServices.H>
#include "prdfsimServices.H"

namespace PRDF
{

    using namespace TARGETING;
    using namespace PlatServices;

    /**
     *  @brief Returns a reference to the ScrDB singleton
     *
     *  @return Reference to the ScrDB
     */
    /*
       ScrDB& GetScrDB()
       {
       return PRDF_GET_SINGLETON(theScrDB);
       }
       */

    ScrDB::ScrDB()
    {
        PRDF_TRAC( "ScrDB::ScrDB()" );
    }

    void ScrDB::processCmd(TARGETING::TargetHandle_t i_ptargetHandle,
                           BIT_STRING_CLASS & bs,
                           uint64_t registerId,
                           SimOp i_op)
    {
        // set target state to functional if not already functional
        if(false == isFunctional(i_ptargetHandle))
        {
            getSimServices().setHwasState(i_ptargetHandle, true);
        }

        switch (i_op)
        {
            case WRITE:
                Write(i_ptargetHandle, bs, registerId);
                break;
            case READ:
                Read(i_ptargetHandle, bs, registerId);
                break;
            case EXPECT:
                Expect(i_ptargetHandle, bs, registerId);
                break;
            default:
                PRDF_ERR( "ScrDB::processCmd() unsupported operation: 0x%X", i_op );
                break;
        }

        return;
    }

    void ScrDB::Read(TARGETING::TargetHandle_t i_ptargetHandle,
                     BIT_STRING_CLASS & bs,
                     uint64_t registerId)
    {
        //PRDF_DENTER( "ScrDB::Read() huid: 0x%X, addr: 0x%016X",
        //            getHuid(i_ptargetHandle), registerId );
        DataList data;
        unsigned int dataWordSize = bs.GetLength()/32;
        dataWordSize += (bs.GetLength() % 32) ? 1 : 0;

        // if the register has a predetermined value than get it
        if(pChipset.find(i_ptargetHandle) != pChipset.end())
        {
            PreScrMap pscrmap = pChipset[i_ptargetHandle];
            if(pscrmap.find(registerId) != pscrmap.end())  // we must have a predetermined value
            {
                SimScrDataSet pValues = pscrmap[registerId];
                data = pValues.GetData(); // get next set of values
                // pValues has changed - copy it back
                pscrmap[registerId] = pValues;
                pChipset[i_ptargetHandle] = pscrmap;
            }
        }
        if(data.size() == 0) // use the last value written to this reg
        {
            // get a copy of the scrMap for this chip - if one does not exist it will be created
            ScrMap scrMap = chipset[i_ptargetHandle];
            // get a copy of the data for this address from the scrMap for this chip
            // if data structure does not exist, it will be created, but will be empty
            data = scrMap[registerId];
            if(data.size() == 0)  // This is the first time this register has been accessed
            {
                while(data.size() < dataWordSize) data.push_back(0); // zero fill
                scrMap[registerId] = data;
                chipset[i_ptargetHandle] = scrMap;     // update the persistant copy of the scrMap
            }
        }

        if(0 != data.size())
        {
            for(unsigned int i = 0; i < data.size(); ++i)
            {
                bs.SetFieldJustify((i*32), 32, data[i]);
            }
            PRDF_TRAC( "ScrDB::Read() huid: %X, addr: %016X, data: %08X %08X",
                           getHuid(i_ptargetHandle), registerId, data[0],
                           2 == data.size() ? data[1] : 0  );
        }
        //PRDF_DEXIT( "ScrDB::Read()" );

    }

    void ScrDB::Write(TARGETING::TargetHandle_t i_ptargetHandle,
                      BIT_STRING_CLASS & bs,
                      uint64_t registerId)
    {
        PRDF_TRAC( "ScrDB::Write() huid: %X, addr: %016X, data: %08X %08X",
                    getHuid(i_ptargetHandle), registerId,
                    bs.GetFieldJustify(0,32), bs.GetFieldJustify(32,32) );

        unsigned int dataWordSize = bs.GetLength()/32;
        //    PRDF_TRAC("dataWordSize1: %d", dataWordSize);
        dataWordSize += (bs.GetLength() % 32) ? 1 : 0;
        //    PRDF_TRAC("dataWordSize2: %d", dataWordSize);
        DataList data;

        // parse all data given
        data.push_back(bs.GetFieldJustify(0,32));
        data.push_back(bs.GetFieldJustify(32,32));
        //    PRDF_TRAC("parse all data given");
        // look for expected data
        DataList expectedData;
        if(eChipset.find(i_ptargetHandle) != eChipset.end())
        {
            PRDF_TRAC("found target");
            PreScrMap escrmap = eChipset[i_ptargetHandle];
            if(escrmap.find(registerId) != escrmap.end()) // we have expected data value
            {
                PRDF_TRAC("found scom reg");
                SimScrDataSet eValues = escrmap[registerId];
                expectedData = eValues.GetData(); // get next set of values
                escrmap[registerId] = eValues;
                eChipset[i_ptargetHandle] = escrmap;
            }
        }
        if(expectedData.size() > 0)
        {
            if((expectedData[0] != data[0]) || (expectedData[1] != data[1]))
            {
                PRDF_ERR("Verify SC register: %p", i_ptargetHandle);
                PRDF_ERR(" Address: 0x%016X", registerId);
                PRDF_ERR("SCR write Actual  : %08X %08X", data[0], data[1]);
                PRDF_ERR("SCR write Expected: %08X %08X", expectedData[0], expectedData[1]);
            }
            else
            {
                PRDF_TRAC("Verify SC register: %p", i_ptargetHandle);
                PRDF_TRAC(" Address: 0x%016X", registerId);
                PRDF_TRAC("SCR write Actual: %08X %08X", data[0], data[1]);
            }
        }

        //    PRDF_TRAC("get a copy");
        // get a copy of the scrMap for this chip - if one does not exist it will be created
        ScrMap scrMap = chipset[i_ptargetHandle];

        //    PRDF_TRAC("update register value");
        // update register value
        scrMap[registerId] = data; // copy the supplied value to the register

        //    PRDF_TRAC("update the master");
        chipset[i_ptargetHandle] = scrMap; // scrMap is only a copy so must update the master

        //PRDF_EXIT( "ScrDB::Write()" );

    }


    void ScrDB::Expect(TARGETING::TargetHandle_t i_ptargetHandle,
                       BIT_STRING_CLASS & bs,
                       uint64_t registerId)
    {
        PRDF_TRAC( "ScrDB::Expect() huid: %X, addr: %016X, data: %08X %08X",
                    getHuid(i_ptargetHandle), registerId,
                    bs.GetFieldJustify(0,32), bs.GetFieldJustify(32,32) );

        SimScrDataSet eValues;
        DataList data;
        // parse all data given
        data.push_back(bs.GetFieldJustify(0,32));
        data.push_back(bs.GetFieldJustify(32,32));

        eValues.AddData(data);

        //    PRDF_TRAC("get a copy");
        PreScrMap scrMap = eChipset[i_ptargetHandle]; // create/get copy of map

        //    PRDF_TRAC("update register value");
        scrMap[registerId] = eValues; // Add entree

        //    PRDF_TRAC("update the master");
        eChipset[i_ptargetHandle] = scrMap; // copy it back

        //PRDF_EXIT( "ScrDB::Expect()" );

    }

} // End namespace PRDF
OpenPOWER on IntegriCloud