Zane Shelley | dd156ad | 2019-10-25 20:59:55 -0500 | [diff] [blame] | 1 | // clang-format off |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 2 | /* IBM_PROLOG_BEGIN_TAG */ |
| 3 | /* This is an automatically generated prolog. */ |
| 4 | /* */ |
| 5 | /* $Source: src/usr/diag/prdf/common/framework/register/iipCaptureData.h $ */ |
| 6 | /* */ |
| 7 | /* OpenPOWER HostBoot Project */ |
| 8 | /* */ |
| 9 | /* Contributors Listed Below - COPYRIGHT 2012,2019 */ |
| 10 | /* [+] International Business Machines Corp. */ |
| 11 | /* */ |
| 12 | /* */ |
| 13 | /* Licensed under the Apache License, Version 2.0 (the "License"); */ |
| 14 | /* you may not use this file except in compliance with the License. */ |
| 15 | /* You may obtain a copy of the License at */ |
| 16 | /* */ |
| 17 | /* http://www.apache.org/licenses/LICENSE-2.0 */ |
| 18 | /* */ |
| 19 | /* Unless required by applicable law or agreed to in writing, software */ |
| 20 | /* distributed under the License is distributed on an "AS IS" BASIS, */ |
| 21 | /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ |
| 22 | /* implied. See the License for the specific language governing */ |
| 23 | /* permissions and limitations under the License. */ |
| 24 | /* */ |
| 25 | /* IBM_PROLOG_END_TAG */ |
| 26 | |
| 27 | #ifndef iipCaptureData_h |
| 28 | #define iipCaptureData_h |
| 29 | |
| 30 | // Class Specification ************************************************* |
| 31 | // |
| 32 | // Class name: CaptureData |
| 33 | // Parent class: None. |
| 34 | // |
| 35 | // Summary: This class provides a queue-like buffer for recording Scan |
| 36 | // Comm Register data. |
| 37 | // |
| 38 | // When this class is constructed or the Clear() member |
| 39 | // function is called, the buffer is empty. The Add() |
| 40 | // function adds data to the front or back of this buffer. |
| 41 | // The data is ordered according to the sequence of Add() |
| 42 | // calls and the Place parameter (FRONT or BACK). A Scan |
| 43 | // Comm Register is passed to the Add() function and the |
| 44 | // register is read during the Add() function. The data is |
| 45 | // then stored internally. Whenever the Copy() member |
| 46 | // function is called, the current internal data is copied to |
| 47 | // the specified buffer with respect to the current ordering. |
| 48 | // Only the number of bytes specified are copied. Therefore, |
| 49 | // any data that MUST be copied should be added using the |
| 50 | // FRONT placement. |
| 51 | // |
| 52 | // Cardinality: N |
| 53 | // |
| 54 | // Performance/Implementation: |
| 55 | // Space Complexity: Linear based on the number of Add() calls |
| 56 | // Time Complexity: All member functions constant unless otherwise |
| 57 | // stated. |
| 58 | // |
| 59 | // Usage Examples: |
| 60 | // |
| 61 | // BIT8 data[BUFFER_SIZE]; |
| 62 | // |
| 63 | // void foo(TARGETING::TargetHandle_t chipId, ScanCommRegisterAccess & scr) |
| 64 | // { |
| 65 | // CaptureData captureData; |
| 66 | // |
| 67 | // captureData.Add(chipId, scr, CaptureData::FRONT); |
| 68 | // captureData.Add(chipId, scr, CaptureData::BACK); |
| 69 | // |
| 70 | // int bytesCopied = captureData.Copy(data, BUFFER_SIZE); |
| 71 | // } |
| 72 | // |
| 73 | // End Class Specification ********************************************* |
| 74 | |
| 75 | /*--------------------------------------------------------------------*/ |
| 76 | /* Reference the virtual function tables and inline function |
| 77 | defintions in another translation unit. */ |
| 78 | /*--------------------------------------------------------------------*/ |
| 79 | |
| 80 | #include <list> |
| 81 | |
Zane Shelley | 52cb1a9 | 2019-08-21 14:38:31 -0500 | [diff] [blame] | 82 | #include <hei_includes.hpp> |
| 83 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 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 | |
Zane Shelley | fd275a2 | 2019-09-05 23:13:59 -0500 | [diff] [blame] | 113 | namespace libhei |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 114 | { |
| 115 | |
| 116 | // Forward Declarations |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 117 | class Register; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 118 | class ScanCommRegisterAccess; |
| 119 | class 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 | */ |
| 135 | class CaptureData |
| 136 | { |
| 137 | public: |
| 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, |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 198 | Register & scr, Place place = BACK, |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 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 | |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 214 | void Add(TARGETING::TargetHandle_t chipId, Register & scr, |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 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 | */ |
| 247 | void 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 | |
| 278 | private: |
| 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 |
Zane Shelley | 05bac98 | 2019-09-02 20:57:42 -0500 | [diff] [blame] | 303 | Data(TARGETING::TargetHandle_t i_pchipHandle= nullptr, // dg01 |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 304 | uint16_t a = 0, |
| 305 | uint16_t dbl = 0, |
Zane Shelley | 05bac98 | 2019-09-02 20:57:42 -0500 | [diff] [blame] | 306 | uint8_t * dPtr = nullptr) |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 307 | : |
| 308 | chipHandle(i_pchipHandle), |
| 309 | address(a), |
| 310 | dataByteLength(dbl), |
| 311 | dataPtr(dPtr) |
| 312 | {} |
| 313 | |
| 314 | ~Data(void) // dg05a |
| 315 | { // dg05a |
Zane Shelley | 05bac98 | 2019-09-02 20:57:42 -0500 | [diff] [blame] | 316 | if(dataPtr != nullptr) // dg05a |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 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 | |
| 385 | public: |
| 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 | |
Zane Shelley | fd275a2 | 2019-09-05 23:13:59 -0500 | [diff] [blame] | 403 | } // end namespace libhei |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 404 | |
| 405 | #endif |
Zane Shelley | dd156ad | 2019-10-25 20:59:55 -0500 | [diff] [blame] | 406 | // clang-format on |