blob: e65e94d3ff4457eb99fa66ca6047a297435633aa [file] [log] [blame]
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05001/* IBM_PROLOG_BEGIN_TAG */
2/* This is an automatically generated prolog. */
3/* */
4/* $Source: src/usr/diag/prdf/common/framework/register/iipCaptureData.h $ */
5/* */
6/* OpenPOWER HostBoot Project */
7/* */
8/* Contributors Listed Below - COPYRIGHT 2012,2019 */
9/* [+] International Business Machines Corp. */
10/* */
11/* */
12/* Licensed under the Apache License, Version 2.0 (the "License"); */
13/* you may not use this file except in compliance with the License. */
14/* You may obtain a copy of the License at */
15/* */
16/* http://www.apache.org/licenses/LICENSE-2.0 */
17/* */
18/* Unless required by applicable law or agreed to in writing, software */
19/* distributed under the License is distributed on an "AS IS" BASIS, */
20/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
21/* implied. See the License for the specific language governing */
22/* permissions and limitations under the License. */
23/* */
24/* IBM_PROLOG_END_TAG */
25
26#ifndef iipCaptureData_h
27#define iipCaptureData_h
28
29// Class Specification *************************************************
30//
31// Class name: CaptureData
32// Parent class: None.
33//
34// Summary: This class provides a queue-like buffer for recording Scan
35// Comm Register data.
36//
37// When this class is constructed or the Clear() member
38// function is called, the buffer is empty. The Add()
39// function adds data to the front or back of this buffer.
40// The data is ordered according to the sequence of Add()
41// calls and the Place parameter (FRONT or BACK). A Scan
42// Comm Register is passed to the Add() function and the
43// register is read during the Add() function. The data is
44// then stored internally. Whenever the Copy() member
45// function is called, the current internal data is copied to
46// the specified buffer with respect to the current ordering.
47// Only the number of bytes specified are copied. Therefore,
48// any data that MUST be copied should be added using the
49// FRONT placement.
50//
51// Cardinality: N
52//
53// Performance/Implementation:
54// Space Complexity: Linear based on the number of Add() calls
55// Time Complexity: All member functions constant unless otherwise
56// stated.
57//
58// Usage Examples:
59//
60// BIT8 data[BUFFER_SIZE];
61//
62// void foo(TARGETING::TargetHandle_t chipId, ScanCommRegisterAccess & scr)
63// {
64// CaptureData captureData;
65//
66// captureData.Add(chipId, scr, CaptureData::FRONT);
67// captureData.Add(chipId, scr, CaptureData::BACK);
68//
69// int bytesCopied = captureData.Copy(data, BUFFER_SIZE);
70// }
71//
72// End Class Specification *********************************************
73
74/*--------------------------------------------------------------------*/
75/* Reference the virtual function tables and inline function
76 defintions in another translation unit. */
77/*--------------------------------------------------------------------*/
78
79#include <list>
80
81#ifndef IIPCONST_H
82#include <iipconst.h>
83#endif
84#include <prdfPlatServices.H>
85#include <functional> // @jl04 a Needed for the unary function in new predicate.
86
87#ifdef __HOSTBOOT_MODULE
88
89 // FIXME: RTC 73204 was opened to add support for these in hostboot. They will
90 // need to be removed once the issue has been resolved.
91 #ifndef htonl
92 #define htonl(foo) (foo)
93 #endif
94
95 #ifndef htons
96 #define htons(foo) (foo)
97 #endif
98
99 #ifndef ntohl
100 #define ntohl(foo) (foo)
101 #endif
102
103 #ifndef ntohs
104 #define ntohs(foo) (foo)
105 #endif
106
107#else
108
109 #include <netinet/in.h>
110
111#endif
112
113namespace PRDF
114{
115
116// Forward Declarations
117class SCAN_COMM_REGISTER_CLASS;
118class ScanCommRegisterAccess;
119class BitString;
120
121// @jl04 a start
122// @jl04 a Added this enumeration for error log compression, elimination of secondary regs.
123 enum RegType
124 {
125 PRIMARY = 1,
126 SECONDARY = 2
127 };
128// @jl04 a Stop
129
130/**
131 Capture data class
132 @author Doug Gilbert
133 @version V5R2
134*/
135class CaptureData
136{
137public:
138
139 enum Place
140 {
141 FRONT,
142 BACK
143 };
144
145 enum
146 {
147 INITIAL_DATA_COUNT = 80,
148 ENTRY_FIXED_SIZE = 8,
149 MAX_ENTRY_SIZE = 128
150 };
151
152 /**
153 Constructor
154 */
155 CaptureData(void);
156
157 /*
158 Copy constructor - default is ok
159 */
160// CaptureData(const CaptureData & c);
161
162 /*
163 Assignment operator - default is ok
164 */
165// CaptureData & operator=(const CaptureData & c);
166
167 /**
168 Destructor
169 */
170// dg05d ~CaptureData(void); // compiler default is ok
171
172 /**
173 Clear out capture data
174 <ul>
175 <br><b>Parameters:None
176 <br><b>Returns:Nothing
177 <br><b>Requirments:None.
178 <br><b>Promises: All capture data cleared ( copy(...) == 0 )
179 </ul><br>
180 */
181 void Clear(void);
182
183 // dg00 start
184 /**
185 Add scr & data to capture log
186 <ul>
187 <br><b>Parameter: chipHandle target handle of chip object
188 <br><b>Parameter: scan comm id (unique one btye code representing scan comm address)
189 <br><b>Parameter: Scan comm register object
190 <br><b>Parameter: Optional location in capure vector [FRONT | BACK] def = BACK
191 <br><b>Returns: Nothing
192 <br><b>Requires: Nothing
193 <br><b>Promises: scr.Read()
194 <br><b>Notes: This is the required Add() method for Regatta and beyond
195 </ul><br>
196 */
197 void Add( TARGETING::TargetHandle_t i_pchipHandle, int scomId,
198 SCAN_COMM_REGISTER_CLASS & scr, Place place = BACK,
199 RegType type = PRIMARY); // @jl04 c. Changed this to add the type to the end of the parms.
200 // dg00 end
201
202 /* REMOVE for FSP
203 Add scr & data to capture log
204 <ul>
205 <br><b>Parameter: chipHandle target handle of chip object
206 <br><b>Parameter: Scan comm register object
207 <br><b>Parameter: Optional location in capure vector [FRONT | BACK] def = BACK
208 <br><b>Returns: Nothing
209 <br><b>Requires: Nothing
210 <br><b>Promises: scr.Read()
211 <br><b>Notes: This is the required Add() method for pre-Regatta
212 </ul><br>
213
214 void Add(TARGETING::TargetHandle_t chipId, SCAN_COMM_REGISTER_CLASS & scr,
215 Place place = BACK);
216*/
217
218 // dg02 start
219 /**
220 Add scr & data to capture log
221 <ul>
222 <br><b>Parameter: i_pchipHandle Handle of chip object
223 <br><b>Parameter: scan comm id (unique one btye code representing scan comm address)
224 <br><b>Parameter: BitString
225 <br><b>Parameter: Optional location in capure vector [FRONT | BACK] def = BACK
226 <br><b>Returns: Nothing
227 <br><b>Requires: Nothing
228 <br><b>Promises:
229 <br><b>Notes: This is available for Regatta and beyond. Not implemented on Condor
230 </ul><br>
231 */
232 void Add( TARGETING::TargetHandle_t i_pchipHandle, int scomId,
233 const BitString & bs, Place place = BACK);
234
235 // dg02 end
236
237// start @jl04a
238 /**
239 Drop scr & data from capture log
240 <ul>
241 <br><b>Parameter: Type of capture vector [PRIMARY | SECONDARY] def = PRIMARY. SECONDARIES dropped on connected.
242 <br><b>Returns: Nothing
243 <br><b>Requires: Nothing
244 <br><b>Promises:
245 </ul><br>
246 */
247void Drop(RegType type); //@jl04a
248// end @jl04a
249
250 /**
251 * @brief Copies the capture data to a buffer.
252 *
253 * The capture data is copied to the buffer in the order it exists in the
254 * vector until all entries have been added or until the buffer is full.
255 *
256 * @param i_buffer Pointer to buffer.
257 * @param i_bufferSize Maximum size of the buffer.
258 * @return The actual size of the data buffer. The value will always be less
259 * than or equal to the maximum buffer size.
260 */
261 uint32_t Copy( uint8_t * i_buffer, uint32_t i_bufferSize ) const;
262
263 // dg08a -->
264 /**
265 Reconstruct data from flat data
266 <ul>
267 <br><b>Parameter: i_flatdata ptr to flat data
268 <br><b>Returns: reference to the new capture data
269 <br><b>Requirements: None
270 <br><b>Promises: CaptureData created form flatdata
271 <br><b>Note: i_flatdata -> (uin32_t)size + data created by Copy()
272 data is network ordered bytes.
273 <ul><br>
274 */
275 CaptureData & operator=(const uint8_t *i_flatdata);
276 // <-- dg08a
277
278private:
279
280 // Notes *************************************************************
281 //
282 // Instead of maintaining an actual data buffer, an auxiliary data
283 // structure is used to maintain data in a specific order. The main
284 // reason for this is that since data can be entered in the front or
285 // back of the buffer, the data must be copied to maintain the order.
286 // It is more efficient to copy a number of pointers than a large
287 // data buffer. However, there is added complexity since the data
288 // structure contains a pointer to dynamic data that must be
289 // allocated/deallocated properly.
290 //
291 // A vector of data structures is maintained that is given an initial
292 // size. The vector can grow dynamically, but this can be expensive
293 // in terms of copying and memory fragmentation. To prevent this, the
294 // number of calls to Add() between calls to Clear() should not exceed
295 // the enum INITIAL_DATA_COUNT.
296 //
297 // End Notes *********************************************************
298
299 class Data
300 {
301 public:
302 // Ctor
303 Data(TARGETING::TargetHandle_t i_pchipHandle= NULL, // dg01
304 uint16_t a = 0,
305 uint16_t dbl = 0,
306 uint8_t * dPtr = NULL)
307 :
308 chipHandle(i_pchipHandle),
309 address(a),
310 dataByteLength(dbl),
311 dataPtr(dPtr)
312 {}
313
314 ~Data(void) // dg05a
315 { // dg05a
316 if(dataPtr != NULL) // dg05a
317 { // dg05a
318 delete [] dataPtr; // pw01
319 } // dg05a
320 } // dg05a
321 // Data
322 TARGETING::TargetHandle_t chipHandle;
323 uint16_t address;
324 uint16_t dataByteLength;
325 uint8_t * dataPtr;
326
327 RegType registerType; // @jl04a
328
329 Data(const Data & d);
330 Data & operator=(const Data & d);
331 };
332
333// We should probably use a link list instead of a vector
334 typedef std::list<Data> DataContainerType;
335 typedef DataContainerType::iterator DataIterator;
336 typedef DataContainerType::const_iterator ConstDataIterator;
337
338 DataContainerType data;
339
340 /** Private function to facilitate the adding of caputre data to the
341 * internal vector */
342 void AddDataElement( TARGETING::TargetHandle_t i_trgt, int i_scomId,
343 const BitString * i_bs, Place i_place,
344 RegType i_type = PRIMARY );
345
346 // Predicate for deciding to delete an element of data from a Capture Data list.
347 class prdfCompareCaptureDataType : public std::unary_function<Data &, bool>
348 {
349 public:
350 prdfCompareCaptureDataType(RegType i_ctor_input) : __private_storage(i_ctor_input){};
351 bool operator() (Data &i)
352 {
353 return (i.registerType == __private_storage);
354 };
355
356
357 private:
358 //Private storage for value passed in.
359 RegType __private_storage;
360 //Constructor allows a value to be passed in to compare against.
361 };
362
363 // Predicate for deciding whether to delete an
364 // element of data from a Capture Data list.
365 class prdfCompareCaptureDataEntry :
366 public std::unary_function<Data &, bool>
367 {
368 public:
369 prdfCompareCaptureDataEntry(
370 TARGETING::TargetHandle_t chipHandle,
371 uint16_t address) :
372 __chipHandle(chipHandle),
373 __address(address) {};
374 bool operator() (Data &i)
375 {
376 return ((i.chipHandle == __chipHandle) &&
377 (i.address == __address));
378 };
379
380 private:
381 TARGETING::TargetHandle_t __chipHandle;
382 uint16_t __address;
383 };
384
385public:
386
387 /**
388 * @brief Merge scom register data from two captures
389 * @param i_cd secondary capture data to merge
390 */
391 void mergeData(CaptureData & i_cd);
392
393 /**
394 * @brief Get the Scom data pointer
395 * @return the Scom data pointer
396 */
397 DataContainerType * getData() { return &data; }
398
399
400
401};
402
403} // end namespace PRDF
404
405#endif