blob: b37036d17ebcc8fd8a52685489d0ac1a52db8150 [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
Zane Shelley52cb1a92019-08-21 14:38:31 -050081#include <hei_includes.hpp>
82
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050083#include <prdfPlatServices.H>
84#include <functional> // @jl04 a Needed for the unary function in new predicate.
85
86#ifdef __HOSTBOOT_MODULE
87
88 // FIXME: RTC 73204 was opened to add support for these in hostboot. They will
89 // need to be removed once the issue has been resolved.
90 #ifndef htonl
91 #define htonl(foo) (foo)
92 #endif
93
94 #ifndef htons
95 #define htons(foo) (foo)
96 #endif
97
98 #ifndef ntohl
99 #define ntohl(foo) (foo)
100 #endif
101
102 #ifndef ntohs
103 #define ntohs(foo) (foo)
104 #endif
105
106#else
107
108 #include <netinet/in.h>
109
110#endif
111
Zane Shelleyfd275a22019-09-05 23:13:59 -0500112namespace libhei
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500113{
114
115// Forward Declarations
Zane Shelley23244cb2019-08-30 21:12:12 -0500116class Register;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500117class ScanCommRegisterAccess;
118class BitString;
119
120// @jl04 a start
121// @jl04 a Added this enumeration for error log compression, elimination of secondary regs.
122 enum RegType
123 {
124 PRIMARY = 1,
125 SECONDARY = 2
126 };
127// @jl04 a Stop
128
129/**
130 Capture data class
131 @author Doug Gilbert
132 @version V5R2
133*/
134class CaptureData
135{
136public:
137
138 enum Place
139 {
140 FRONT,
141 BACK
142 };
143
144 enum
145 {
146 INITIAL_DATA_COUNT = 80,
147 ENTRY_FIXED_SIZE = 8,
148 MAX_ENTRY_SIZE = 128
149 };
150
151 /**
152 Constructor
153 */
154 CaptureData(void);
155
156 /*
157 Copy constructor - default is ok
158 */
159// CaptureData(const CaptureData & c);
160
161 /*
162 Assignment operator - default is ok
163 */
164// CaptureData & operator=(const CaptureData & c);
165
166 /**
167 Destructor
168 */
169// dg05d ~CaptureData(void); // compiler default is ok
170
171 /**
172 Clear out capture data
173 <ul>
174 <br><b>Parameters:None
175 <br><b>Returns:Nothing
176 <br><b>Requirments:None.
177 <br><b>Promises: All capture data cleared ( copy(...) == 0 )
178 </ul><br>
179 */
180 void Clear(void);
181
182 // dg00 start
183 /**
184 Add scr & data to capture log
185 <ul>
186 <br><b>Parameter: chipHandle target handle of chip object
187 <br><b>Parameter: scan comm id (unique one btye code representing scan comm address)
188 <br><b>Parameter: Scan comm register object
189 <br><b>Parameter: Optional location in capure vector [FRONT | BACK] def = BACK
190 <br><b>Returns: Nothing
191 <br><b>Requires: Nothing
192 <br><b>Promises: scr.Read()
193 <br><b>Notes: This is the required Add() method for Regatta and beyond
194 </ul><br>
195 */
196 void Add( TARGETING::TargetHandle_t i_pchipHandle, int scomId,
Zane Shelley23244cb2019-08-30 21:12:12 -0500197 Register & scr, Place place = BACK,
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500198 RegType type = PRIMARY); // @jl04 c. Changed this to add the type to the end of the parms.
199 // dg00 end
200
201 /* REMOVE for FSP
202 Add scr & data to capture log
203 <ul>
204 <br><b>Parameter: chipHandle target handle of chip object
205 <br><b>Parameter: Scan comm register object
206 <br><b>Parameter: Optional location in capure vector [FRONT | BACK] def = BACK
207 <br><b>Returns: Nothing
208 <br><b>Requires: Nothing
209 <br><b>Promises: scr.Read()
210 <br><b>Notes: This is the required Add() method for pre-Regatta
211 </ul><br>
212
Zane Shelley23244cb2019-08-30 21:12:12 -0500213 void Add(TARGETING::TargetHandle_t chipId, Register & scr,
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500214 Place place = BACK);
215*/
216
217 // dg02 start
218 /**
219 Add scr & data to capture log
220 <ul>
221 <br><b>Parameter: i_pchipHandle Handle of chip object
222 <br><b>Parameter: scan comm id (unique one btye code representing scan comm address)
223 <br><b>Parameter: BitString
224 <br><b>Parameter: Optional location in capure vector [FRONT | BACK] def = BACK
225 <br><b>Returns: Nothing
226 <br><b>Requires: Nothing
227 <br><b>Promises:
228 <br><b>Notes: This is available for Regatta and beyond. Not implemented on Condor
229 </ul><br>
230 */
231 void Add( TARGETING::TargetHandle_t i_pchipHandle, int scomId,
232 const BitString & bs, Place place = BACK);
233
234 // dg02 end
235
236// start @jl04a
237 /**
238 Drop scr & data from capture log
239 <ul>
240 <br><b>Parameter: Type of capture vector [PRIMARY | SECONDARY] def = PRIMARY. SECONDARIES dropped on connected.
241 <br><b>Returns: Nothing
242 <br><b>Requires: Nothing
243 <br><b>Promises:
244 </ul><br>
245 */
246void Drop(RegType type); //@jl04a
247// end @jl04a
248
249 /**
250 * @brief Copies the capture data to a buffer.
251 *
252 * The capture data is copied to the buffer in the order it exists in the
253 * vector until all entries have been added or until the buffer is full.
254 *
255 * @param i_buffer Pointer to buffer.
256 * @param i_bufferSize Maximum size of the buffer.
257 * @return The actual size of the data buffer. The value will always be less
258 * than or equal to the maximum buffer size.
259 */
260 uint32_t Copy( uint8_t * i_buffer, uint32_t i_bufferSize ) const;
261
262 // dg08a -->
263 /**
264 Reconstruct data from flat data
265 <ul>
266 <br><b>Parameter: i_flatdata ptr to flat data
267 <br><b>Returns: reference to the new capture data
268 <br><b>Requirements: None
269 <br><b>Promises: CaptureData created form flatdata
270 <br><b>Note: i_flatdata -> (uin32_t)size + data created by Copy()
271 data is network ordered bytes.
272 <ul><br>
273 */
274 CaptureData & operator=(const uint8_t *i_flatdata);
275 // <-- dg08a
276
277private:
278
279 // Notes *************************************************************
280 //
281 // Instead of maintaining an actual data buffer, an auxiliary data
282 // structure is used to maintain data in a specific order. The main
283 // reason for this is that since data can be entered in the front or
284 // back of the buffer, the data must be copied to maintain the order.
285 // It is more efficient to copy a number of pointers than a large
286 // data buffer. However, there is added complexity since the data
287 // structure contains a pointer to dynamic data that must be
288 // allocated/deallocated properly.
289 //
290 // A vector of data structures is maintained that is given an initial
291 // size. The vector can grow dynamically, but this can be expensive
292 // in terms of copying and memory fragmentation. To prevent this, the
293 // number of calls to Add() between calls to Clear() should not exceed
294 // the enum INITIAL_DATA_COUNT.
295 //
296 // End Notes *********************************************************
297
298 class Data
299 {
300 public:
301 // Ctor
Zane Shelley05bac982019-09-02 20:57:42 -0500302 Data(TARGETING::TargetHandle_t i_pchipHandle= nullptr, // dg01
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500303 uint16_t a = 0,
304 uint16_t dbl = 0,
Zane Shelley05bac982019-09-02 20:57:42 -0500305 uint8_t * dPtr = nullptr)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500306 :
307 chipHandle(i_pchipHandle),
308 address(a),
309 dataByteLength(dbl),
310 dataPtr(dPtr)
311 {}
312
313 ~Data(void) // dg05a
314 { // dg05a
Zane Shelley05bac982019-09-02 20:57:42 -0500315 if(dataPtr != nullptr) // dg05a
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500316 { // dg05a
317 delete [] dataPtr; // pw01
318 } // dg05a
319 } // dg05a
320 // Data
321 TARGETING::TargetHandle_t chipHandle;
322 uint16_t address;
323 uint16_t dataByteLength;
324 uint8_t * dataPtr;
325
326 RegType registerType; // @jl04a
327
328 Data(const Data & d);
329 Data & operator=(const Data & d);
330 };
331
332// We should probably use a link list instead of a vector
333 typedef std::list<Data> DataContainerType;
334 typedef DataContainerType::iterator DataIterator;
335 typedef DataContainerType::const_iterator ConstDataIterator;
336
337 DataContainerType data;
338
339 /** Private function to facilitate the adding of caputre data to the
340 * internal vector */
341 void AddDataElement( TARGETING::TargetHandle_t i_trgt, int i_scomId,
342 const BitString * i_bs, Place i_place,
343 RegType i_type = PRIMARY );
344
345 // Predicate for deciding to delete an element of data from a Capture Data list.
346 class prdfCompareCaptureDataType : public std::unary_function<Data &, bool>
347 {
348 public:
349 prdfCompareCaptureDataType(RegType i_ctor_input) : __private_storage(i_ctor_input){};
350 bool operator() (Data &i)
351 {
352 return (i.registerType == __private_storage);
353 };
354
355
356 private:
357 //Private storage for value passed in.
358 RegType __private_storage;
359 //Constructor allows a value to be passed in to compare against.
360 };
361
362 // Predicate for deciding whether to delete an
363 // element of data from a Capture Data list.
364 class prdfCompareCaptureDataEntry :
365 public std::unary_function<Data &, bool>
366 {
367 public:
368 prdfCompareCaptureDataEntry(
369 TARGETING::TargetHandle_t chipHandle,
370 uint16_t address) :
371 __chipHandle(chipHandle),
372 __address(address) {};
373 bool operator() (Data &i)
374 {
375 return ((i.chipHandle == __chipHandle) &&
376 (i.address == __address));
377 };
378
379 private:
380 TARGETING::TargetHandle_t __chipHandle;
381 uint16_t __address;
382 };
383
384public:
385
386 /**
387 * @brief Merge scom register data from two captures
388 * @param i_cd secondary capture data to merge
389 */
390 void mergeData(CaptureData & i_cd);
391
392 /**
393 * @brief Get the Scom data pointer
394 * @return the Scom data pointer
395 */
396 DataContainerType * getData() { return &data; }
397
398
399
400};
401
Zane Shelleyfd275a22019-09-05 23:13:59 -0500402} // end namespace libhei
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500403
404#endif