summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/framework/register/prdfCaptureData.C
blob: 72e2fc17fbb1e888e384495314c947f6ee34f14f (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/framework/register/prdfCaptureData.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2003,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                                                     */

/**
  @file prdfCaptureData.C
  @brief Squadrons implementation of capture data
*/
//----------------------------------------------------------------------
//  Includes
//----------------------------------------------------------------------

#include <iipbits.h>
#include <prdfHomRegisterAccess.H>  // dg06a
#include <prdfScomRegister.H>
#include <iipchip.h>
#include <iipCaptureData.h>
#include <string.h>
#include <algorithm>    // @jl04 a Add this for the Drop function.

namespace PRDF
{

//---------------------------------------------------------------------
// Member Function Specifications
//---------------------------------------------------------------------

CaptureData::CaptureData(void):data()
{
//  data.reserve(INITIAL_DATA_COUNT);
}

// dg05d CaptureData::~CaptureData(void)
// dg05d {
// dg05d   if(!data.empty())
// dg05d   {
// dg05d     Clear();
// dg05d   }
// dg05d }

void CaptureData::Clear(void)
{

  if(!data.empty())
  {
// dg05d   for(DataContainerType::iterator i  = data.begin();i != data.end();i++)
// dg05d   {
// dg05d     delete [] (*i).dataPtr;
// dg05d   }

    data.erase(data.begin(), data.end());

  }                             /* if not empty */
}


// @jl04 c Changed this to add the type parm.
void CaptureData::Add(  TARGETING::TargetHandle_t i_pchipHandle, int scomId,
                        SCAN_COMM_REGISTER_CLASS & scr, Place place, RegType type)
{
  uint16_t bufferLength = scr.GetBitLength() / 8;

  if((scr.GetBitLength() % 8) != 0)
    bufferLength += 1;

  Data dataElement(i_pchipHandle, scomId, bufferLength, NULL);

  AddDataElement(dataElement, scr, place, type);
}

// start dg02
void CaptureData::Add( TARGETING::TargetHandle_t i_pchipHandle, int scomId,
                       BIT_STRING_CLASS & bs, Place place)
{
  uint16_t bufferLength = bs.GetLength() / 8;

  if((bs.GetLength() % 8) != 0)
    bufferLength += 1;

  Data dataElement(i_pchipHandle, scomId, bufferLength, NULL);

  DataIterator dataIterator;

  if(place == FRONT)
  {
    data.insert(data.begin(), dataElement);
    dataIterator = data.begin();
  }
  else
  {
    data.push_back(dataElement);
    dataIterator = data.end();
    dataIterator--;
  }
  if(!bs.IsZero())
  {
    uint8_t *bufferPtr = new uint8_t[(*dataIterator).dataByteLength];
    BIT_STRING_ADDRESS_CLASS bitString(0, bs.GetLength(), (CPU_WORD *) bufferPtr);

    bitString.SetBits(bs);
    (*dataIterator).dataPtr = bufferPtr;
  }
  else
  {
    (*dataIterator).dataByteLength = 0;
  }


}

// end dg02


// start jl04a
void CaptureData::Drop(RegType i_type)
{
  //  Function below requires a predicate function above to Drop
  //  a data element from the capture data if it is
  //    defined as secondary data instead of primary data in the rule files.
  //  This predicate has to exist within the CaptureData Class because the
  //  class "Data" is defined within CaptureData class.
  data.erase( std::remove_if(data.begin(),data.end(),
              prdfCompareCaptureDataType(i_type)), data.end() );
}
// end jl04a

// @jl04 c Changed the AddDataElement to include a type.
void CaptureData::AddDataElement( Data & dataElement,
                                  SCAN_COMM_REGISTER_CLASS & scr,
                                  Place place, RegType type )
{
  DataIterator dataIterator;

  if(place == FRONT)
  {
    data.insert(data.begin(), dataElement);
    dataIterator = data.begin();
  }
  else
  {
    data.push_back(dataElement);
    dataIterator = data.end();
    dataIterator--;
  }

//$TEMP @jl04 or @jl05.
      (*dataIterator).registerType = type;
//$TEMP @jl04 or @jl05.

  if(scr.Read() == SUCCESS)
  {
    const BIT_STRING_CLASS *bitStringPtr = scr.GetBitString();

    if(!bitStringPtr->IsZero())
    {
      uint8_t *bufferPtr = new uint8_t[(*dataIterator).dataByteLength];
      BIT_STRING_ADDRESS_CLASS bitString(0, bitStringPtr->GetLength(),
                                         (CPU_WORD *) bufferPtr);

      bitString.SetBits(*bitStringPtr);
      (*dataIterator).dataPtr = bufferPtr;
    }
    else
    {
      (*dataIterator).dataByteLength = 0;
    }
  }
  else
  {
    // Zero out data length if SCRs failed
    (*dataIterator).dataByteLength = 0;
  }

}
// ------------------------------------------------------------------------------------------------

/* CaptureData Format:
 *        capture data -> ( <chip header> <registers> )*
 *        chip header -> ( <chip id:32> <# registers:32> )
 *        registers -> ( <reg id:16> <reg byte len:16> <bytes>+ )
 */
unsigned int CaptureData::Copy(uint8_t *i_buffer, unsigned int i_bufferSize) const
{
    using namespace TARGETING;

    TargetHandle_t  l_pcurrentChipHandle =NULL ;
    uint8_t * l_entryCountPos = NULL;
    uint32_t l_regEntries = 0;

    uint32_t l_bytesWritten = 0;
    for (ConstDataIterator i = data.begin(); i != data.end(); i++)
    {
        // Check for new chip.
        if (i->chipHandle != l_pcurrentChipHandle)
        {   // Update previous header, write new header.

            if (NULL != l_entryCountPos) // Update previous entry count.
            {
                l_regEntries = htonl(l_regEntries);
                memcpy(l_entryCountPos, &l_regEntries, sizeof(l_regEntries));
                l_regEntries = 0;
            }

            // Update chip Handles....
            TargetHandle_t l_ptempHandle = l_pcurrentChipHandle = i->chipHandle;
            HUID l_chipHuid =PlatServices::getHuid(l_ptempHandle);
            const size_t l_huidSize = sizeof(l_chipHuid);
            l_chipHuid = htonl(l_chipHuid);

            // Verify space.
            if (i_bufferSize < l_bytesWritten + 2 * l_huidSize)
            {
                break;
            }
            // Write header.
            memcpy(&i_buffer[l_bytesWritten],
                   &l_chipHuid, l_huidSize);
            l_bytesWritten += l_huidSize;
            l_entryCountPos = &i_buffer[l_bytesWritten];
            l_ptempHandle = NULL;
            memcpy(l_entryCountPos, &l_chipHuid, l_huidSize);
            l_bytesWritten += l_huidSize;
        }

        // Go to next entry if 0 data length.
        if (0 == i->dataByteLength)
            continue;

        // Check room.
        if ((l_bytesWritten + 2*sizeof(uint16_t) + i->dataByteLength) >
                i_bufferSize)
            continue;

        // Write register ID.
        uint16_t l_regId = htons(i->address);
        memcpy(&i_buffer[l_bytesWritten], &l_regId, sizeof(l_regId));
        l_bytesWritten += sizeof(l_regId);

        // Write register length.
        uint16_t l_regLen = htons(i->dataByteLength);
        memcpy(&i_buffer[l_bytesWritten], &l_regLen, sizeof(l_regLen));
        l_bytesWritten += sizeof(l_regLen);

        // Write register data.
        uint32_t l_dataWritten = 0;
        while ((l_dataWritten + 4) <= i->dataByteLength)
        {
            uint32_t l_temp32;
            memcpy(&l_temp32, &i->dataPtr[l_dataWritten], sizeof(l_temp32));
            l_temp32 = htonl(l_temp32);
            memcpy(&i_buffer[l_bytesWritten], &l_temp32, 4);
            l_dataWritten += 4; l_bytesWritten += 4;
        }
        if (l_dataWritten != i->dataByteLength)
        {
            uint32_t l_temp32;
            memcpy(&l_temp32, &i->dataPtr[l_dataWritten], sizeof(l_temp32));
            l_temp32 = htonl(l_temp32);
            memcpy(&i_buffer[l_bytesWritten],
                   &l_temp32, i->dataByteLength - l_dataWritten);
            l_bytesWritten += i->dataByteLength - l_dataWritten;
        }

        // Update entry count.
        l_regEntries++;
    }

    // Update previous entry count.
    if (NULL != l_entryCountPos)
    {
        l_regEntries = htonl(l_regEntries);
        memcpy(l_entryCountPos, &l_regEntries, sizeof(l_regEntries));
        l_regEntries = 0;
    }

    return l_bytesWritten;
}

// dg08a -->
CaptureData & CaptureData::operator=(const uint8_t *i_flatdata)
{
    using namespace TARGETING;

    uint32_t l_tmp32 = 0;
    uint16_t l_tmp16 = 0;

    HUID  l_chipHuid = INVALID_HUID;
    const size_t l_huidSize = sizeof(l_chipHuid);

    // Read size.
    memcpy(&l_tmp32, i_flatdata, sizeof(uint32_t));
    uint32_t size = ntohl(l_tmp32);
    i_flatdata += sizeof(uint32_t);

    Clear();

    // Calculate end of buffer.
    const uint8_t *eptr = i_flatdata + size;

    while(i_flatdata < eptr)
    {
        // Read chip Handle.
        memcpy(&l_chipHuid , i_flatdata,l_huidSize );
        i_flatdata += l_huidSize ;
        TargetHandle_t l_pchipHandle  =NULL;
        l_chipHuid =  ntohl(l_chipHuid);
        l_pchipHandle = PlatServices::getTarget(l_chipHuid );
        if(NULL ==l_pchipHandle)
        {
            continue;
        }

        // Read # of entries.
        memcpy(&l_tmp32, i_flatdata, sizeof(uint32_t));
        i_flatdata += sizeof(l_tmp32);
        uint32_t entries = ntohl(l_tmp32);

        // Input each entry.
        for(uint32_t i = 0; i < entries; ++i)
        {
            // Read register id.
            memcpy(&l_tmp16, i_flatdata, sizeof(uint16_t));
            i_flatdata += sizeof(uint16_t);
            int regid = ntohs(l_tmp16);

            // Read byte count.
            memcpy(&l_tmp16, i_flatdata, sizeof(uint16_t));
            i_flatdata += sizeof(uint16_t);
            uint32_t bytecount = ntohs(l_tmp16);

            // Read data for register.
            BitStringBuffer bs(bytecount * 8);
            for(uint32_t bc = 0; bc < bytecount; ++bc)
            {
                bs.SetFieldJustify(bc*8,8,(CPU_WORD)(*(i_flatdata+bc))); //mp01a
            }
            i_flatdata += bytecount;

            // Add to capture data.
            Add(l_pchipHandle, regid, bs);
        }
    }

    return *this;
}

// <-- dg08a

void CaptureData::mergeData(CaptureData & i_cd)
{
    DataContainerType l_data = *(i_cd.getData());

    // Remove duplicate entries from secondary capture data
    for (ConstDataIterator i = data.begin(); i != data.end(); i++)
    {
        l_data.remove_if(
            prdfCompareCaptureDataEntry(i->chipHandle,
                                          i->address) );
    }

    // Add secondary capture data to primary one
    data.insert( data.end(),
                 l_data.begin(),
                 l_data.end() );
}


// copy ctor for Data class
CaptureData::Data::Data(const Data & d):
chipHandle(d.chipHandle), address(d.address),
dataByteLength(d.dataByteLength), dataPtr(NULL)
{
    if(d.dataPtr != NULL)
    {
        dataPtr = new uint8_t[dataByteLength];

        memcpy(dataPtr, d.dataPtr, dataByteLength);
    }
}

CaptureData::Data & CaptureData::Data::operator=(const Data & d)
{
    chipHandle = d.chipHandle;
    address = d.address;
    dataByteLength = d.dataByteLength;
    if(dataPtr != NULL)
    {
        delete[]dataPtr;
        dataPtr = NULL;
    }
    if(d.dataPtr != NULL)
    {
        dataPtr = new uint8_t[dataByteLength];
        memcpy(dataPtr, d.dataPtr, dataByteLength);
    }

    return *this;
}

} // end of namespace PRDF
OpenPOWER on IntegriCloud