Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 1 | // Module Description ************************************************** |
| 2 | // |
| 3 | // Description: This module provides the implementation for the PRD Scan |
| 4 | // Comm Register Chip class. |
| 5 | // |
| 6 | // End Module Description ********************************************** |
| 7 | |
| 8 | //---------------------------------------------------------------------- |
| 9 | // Includes |
| 10 | //---------------------------------------------------------------------- |
| 11 | |
Zane Shelley | 52cb1a9 | 2019-08-21 14:38:31 -0500 | [diff] [blame] | 12 | #include <hei_includes.hpp> |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 13 | #include <hei_user_interface.hpp> |
Zane Shelley | 52cb1a9 | 2019-08-21 14:38:31 -0500 | [diff] [blame] | 14 | #include <register/hei_hardware_register.hpp> |
| 15 | #include <util/hei_bit_string.hpp> |
| 16 | |
Zane Shelley | b77b573 | 2019-08-30 22:01:06 -0500 | [diff] [blame] | 17 | #if 0 |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 18 | #include <iipchip.h> |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 19 | #include <prdfMain.H> |
| 20 | #include <prdfRasServices.H> |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 21 | #include <prdfPlatServices.H> |
| 22 | #include <prdfExtensibleChip.H> |
| 23 | |
| 24 | //---------------------------------------------------------------------- |
| 25 | // User Types |
| 26 | //---------------------------------------------------------------------- |
| 27 | |
| 28 | //---------------------------------------------------------------------- |
| 29 | // Constants |
| 30 | //---------------------------------------------------------------------- |
| 31 | |
| 32 | //---------------------------------------------------------------------- |
| 33 | // Macros |
| 34 | //---------------------------------------------------------------------- |
| 35 | |
| 36 | //---------------------------------------------------------------------- |
| 37 | // Internal Function Prototypes |
| 38 | //---------------------------------------------------------------------- |
| 39 | |
| 40 | //---------------------------------------------------------------------- |
| 41 | // Global Variables |
| 42 | //---------------------------------------------------------------------- |
| 43 | |
| 44 | //--------------------------------------------------------------------- |
| 45 | // Member Function Specifications |
| 46 | //--------------------------------------------------------------------- |
| 47 | |
| 48 | // -------------------------------------------------------------------- |
Zane Shelley | b77b573 | 2019-08-30 22:01:06 -0500 | [diff] [blame] | 49 | #endif |
| 50 | |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 51 | namespace libhei |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 52 | { |
| 53 | |
Zane Shelley | 8deb090 | 2019-10-14 15:52:27 -0500 | [diff] [blame^] | 54 | //------------------------------------------------------------------------------ |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 55 | |
Zane Shelley | 8deb090 | 2019-10-14 15:52:27 -0500 | [diff] [blame^] | 56 | HardwareRegister::~HardwareRegister() {} |
| 57 | |
| 58 | //------------------------------------------------------------------------------ |
| 59 | |
| 60 | #if 0 |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 61 | void HardwareRegister::SetBitString( const BitString *bs ) |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 62 | { |
| 63 | BitString & l_string = AccessBitString(); |
| 64 | l_string.setString(*bs); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | //------------------------------------------------------------------------------ |
| 69 | |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 70 | const BitString * HardwareRegister::GetBitString(ATTENTION_TYPE i_type) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 71 | { |
| 72 | // Calling Read() will ensure that an entry exists in the cache and the |
| 73 | // entry has at been synched with hardware at least once. Note that we |
| 74 | // cannot read hardware for write-only registers. In this case, an entry |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 75 | // will be created in the cache, if it does not exist, when the cache is |
| 76 | // read below. |
| 77 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 78 | if ( ( ACCESS_NONE != iv_operationType ) && |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 79 | ( ACCESS_WO != iv_operationType ) ) |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 80 | { |
| 81 | Read(); |
| 82 | } |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 83 | |
| 84 | return &( accessCache() ); |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | //------------------------------------------------------------------------------ |
| 88 | |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 89 | BitString & HardwareRegister::AccessBitString() |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 90 | { |
| 91 | // Calling Read() will ensure that an entry exists in the cache and the |
| 92 | // entry has at been synched with hardware at least once. Note that we |
| 93 | // cannot read hardware for write-only registers. In this case, an entry |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 94 | // will be created in the cache, if it does not exist, when the cache is |
| 95 | // read below. |
| 96 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 97 | if ( ( ACCESS_NONE != iv_operationType ) && |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 98 | ( ACCESS_WO != iv_operationType ) ) |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 99 | { |
| 100 | Read(); |
| 101 | } |
| 102 | |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 103 | return accessCache(); |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 104 | } |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 105 | #endif |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 106 | |
| 107 | //------------------------------------------------------------------------------ |
| 108 | |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 109 | ReturnCode HardwareRegister::read( bool i_force ) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 110 | { |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 111 | ReturnCode rc; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 112 | |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 113 | // Read from hardware only if the read is forced or the entry for this |
| 114 | // instance does not exist in the cache. |
| 115 | if ( i_force || !queryCache() ) |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 116 | { |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 117 | #if 0 |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 118 | // This register must be readable. |
| 119 | HEI_ASSERT( ( ACCESS_NONE != iv_operationType ) && |
| 120 | ( ACCESS_WO != iv_operationType ) ); |
| 121 | |
| 122 | // Get the buffer from the register cache. |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 123 | BitString & bs = accessCache(); |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 124 | |
| 125 | // Get the byte size of the buffer. |
| 126 | size_t sz_buffer = BitString::getMinBytes( bs.getBitLen() ); |
| 127 | |
| 128 | // Read this register from hardware. |
| 129 | rc = registerRead( getAccessorChip().getChip(), bs.getBufAddr(), |
| 130 | sz_buffer, getRegisterType(), getAddress() ); |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 131 | #endif |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 132 | if ( RC_SUCCESS != rc ) |
| 133 | { |
| 134 | // The read failed and we can't trust what was put in the register |
| 135 | // cache. So remove this instance's entry from the cache. |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 136 | cv_cache.flush( getAccessorChip(), this ); |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 137 | } |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 138 | #if 0 |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 139 | else |
| 140 | { |
| 141 | // Sanity check. The returned size of the data written to the buffer |
| 142 | // should match the register size. |
| 143 | HEI_ASSERT( getSize() == sz_buffer ); |
| 144 | } |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 145 | #endif |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 146 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 147 | |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 148 | return rc; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | //------------------------------------------------------------------------------ |
| 152 | |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 153 | #ifndef __HEI_READ_ONLY |
| 154 | |
| 155 | ReturnCode HardwareRegister::write() const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 156 | { |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 157 | ReturnCode rc; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 158 | |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 159 | #if 0 |
| 160 | // This register must be writable. |
| 161 | HEI_ASSERT( ( ACCESS_NONE != iv_operationType ) && |
| 162 | ( ACCESS_RO != iv_operationType ) ); |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 163 | |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 164 | // An entry for this register must exist in the cache. |
| 165 | HEI_ASSERT( queryCache() ); |
| 166 | |
| 167 | // Get the buffer from the register cache. |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 168 | BitString & bs = accessCache(); |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 169 | |
| 170 | // Get the byte size of the buffer. |
| 171 | size_t sz_buffer = BitString::getMinBytes( bs.getBitLen() ); |
| 172 | |
| 173 | // Write to this register to hardware. |
| 174 | rc = registerWrite( getAccessorChip().getChip(), bs.getBufAddr(), |
| 175 | sz_buffer, getRegisterType(), getAddress() ); |
| 176 | |
| 177 | if ( RC_SUCCESS == rc ) |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 178 | { |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 179 | // Sanity check. The returned size of the data written to the buffer |
| 180 | // should match the register size. |
| 181 | HEI_ASSERT( getSize() == sz_buffer ); |
| 182 | } |
| 183 | #endif |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 184 | |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 185 | return rc; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 186 | } |
| 187 | |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 188 | #endif // __HEI_READ_ONLY |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 189 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 190 | //------------------------------------------------------------------------------ |
| 191 | |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 192 | bool HardwareRegister::operator == ( const HardwareRegister & i_rightRegister ) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 193 | { |
Zane Shelley | 65ed96a | 2019-10-14 13:06:11 -0500 | [diff] [blame] | 194 | #if 0 |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 195 | if( iv_scomAddress == i_rightRegister.GetAddress() ) |
| 196 | { |
| 197 | return ( iv_chipType == i_rightRegister.getChipType() ); |
| 198 | } |
| 199 | else |
| 200 | { |
| 201 | return false ; |
| 202 | } |
Zane Shelley | 65ed96a | 2019-10-14 13:06:11 -0500 | [diff] [blame] | 203 | #endif |
| 204 | return false; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | //----------------------------------------------------------------------------- |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 208 | bool HardwareRegister::operator < ( const HardwareRegister & i_rightRegister ) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 209 | { |
Zane Shelley | 65ed96a | 2019-10-14 13:06:11 -0500 | [diff] [blame] | 210 | #if 0 |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 211 | if( iv_scomAddress == i_rightRegister.GetAddress() ) |
| 212 | { |
| 213 | return ( iv_chipType < i_rightRegister.getChipType() ); |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | return( iv_scomAddress < i_rightRegister.GetAddress() ); |
| 218 | } |
Zane Shelley | 65ed96a | 2019-10-14 13:06:11 -0500 | [diff] [blame] | 219 | #endif |
| 220 | return false; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 221 | } |
Zane Shelley | 65ed96a | 2019-10-14 13:06:11 -0500 | [diff] [blame] | 222 | #if 0 |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 223 | //----------------------------------------------------------------------------- |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 224 | bool HardwareRegister::operator >= ( const HardwareRegister & i_rightRegister ) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 225 | { |
| 226 | return !( *this < i_rightRegister ); |
| 227 | } |
Zane Shelley | b77b573 | 2019-08-30 22:01:06 -0500 | [diff] [blame] | 228 | #endif |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 229 | |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame] | 230 | //------------------------------------------------------------------------------ |
| 231 | |
| 232 | HardwareRegister::Accessor * HardwareRegister::cv_accessor = nullptr; |
| 233 | |
| 234 | //------------------------------------------------------------------------------ |
| 235 | |
Zane Shelley | d0af358 | 2019-09-19 10:48:59 -0500 | [diff] [blame] | 236 | HardwareRegister::Cache HardwareRegister::cv_cache {}; |
| 237 | |
| 238 | //------------------------------------------------------------------------------ |
| 239 | |
| 240 | bool HardwareRegister::Cache::query( const Chip & i_chip, |
| 241 | const HardwareRegister * i_hwReg ) const |
| 242 | { |
| 243 | // Does i_chip exist in the cache? |
| 244 | auto chipPairItr = iv_cache.find( i_chip ); |
| 245 | if ( iv_cache.end() != chipPairItr ) |
| 246 | { |
| 247 | auto & hwRegMap = chipPairItr->second; // for ease of use |
| 248 | |
| 249 | // Does i_hwReg exist in the cache? |
| 250 | auto hwRegPairItr = hwRegMap.find( i_hwReg ); |
| 251 | if ( hwRegMap.end() != hwRegPairItr ) |
| 252 | { |
| 253 | return true; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | return false; |
| 258 | } |
| 259 | |
| 260 | //------------------------------------------------------------------------------ |
| 261 | |
| 262 | BitString & HardwareRegister::Cache::access( const Chip & i_chip, |
| 263 | const HardwareRegister * i_hwReg ) |
| 264 | { |
| 265 | // If the entry does not exist, create a new entry. |
| 266 | if ( !query(i_chip, i_hwReg) ) |
| 267 | { |
| 268 | BitString * bs = new BitStringBuffer { i_hwReg->getByteSize() * 8 }; |
| 269 | iv_cache[i_chip][i_hwReg] = bs; |
| 270 | } |
| 271 | |
| 272 | // Return a reference to the target entry. |
| 273 | return *(iv_cache[i_chip][i_hwReg]); |
| 274 | } |
| 275 | |
| 276 | //------------------------------------------------------------------------------ |
| 277 | |
| 278 | void HardwareRegister::Cache::flush() |
| 279 | { |
| 280 | // Delete all of the BitStrings. |
| 281 | for ( auto & chipPair : iv_cache ) |
| 282 | { |
| 283 | for ( auto & hwRegPair : chipPair.second ) |
| 284 | { |
| 285 | delete hwRegPair.second; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | // !!! Do not delete the HardwareRegisters !!! |
| 290 | // Those are deleted when the main uninitialize() API is called. |
| 291 | |
| 292 | // Flush the rest of the cache. |
| 293 | iv_cache.clear(); |
| 294 | } |
| 295 | |
| 296 | //------------------------------------------------------------------------------ |
| 297 | |
| 298 | void HardwareRegister::Cache::flush( const Chip & i_chip, |
| 299 | const HardwareRegister * i_hwReg ) |
| 300 | { |
| 301 | // Does i_chip exist in the cache? |
| 302 | auto chipPairItr = iv_cache.find( i_chip ); |
| 303 | if ( iv_cache.end() != chipPairItr ) |
| 304 | { |
| 305 | auto & hwRegMap = chipPairItr->second; // for ease of use |
| 306 | |
| 307 | // Does i_hwReg exist in the cache? |
| 308 | auto hwRegPairItr = hwRegMap.find( i_hwReg ); |
| 309 | if ( hwRegMap.end() != hwRegPairItr ) |
| 310 | { |
| 311 | delete hwRegPairItr->second; // delete the BitString |
| 312 | hwRegMap.erase(i_hwReg); // remove the entry for this register |
| 313 | } |
| 314 | |
| 315 | // If i_hwReg was the only entry for i_chip, we can remove i_chip from |
| 316 | // the cache. |
| 317 | if ( hwRegMap.empty() ) |
| 318 | { |
| 319 | iv_cache.erase(i_chip); |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | //------------------------------------------------------------------------------ |
| 325 | |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 326 | } // end namespace libhei |
| 327 | |