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 | |
| 12 | #include <iipchip.h> |
| 13 | #include <prdfScomRegister.H> |
| 14 | #include <iipconst.h> |
| 15 | #include <iipbits.h> |
| 16 | #include <prdfMain.H> |
| 17 | #include <prdfRasServices.H> |
| 18 | #include <prdfRegisterCache.H> |
| 19 | #include <prdfHomRegisterAccess.H> |
| 20 | #include <prdfPlatServices.H> |
| 21 | #include <prdfExtensibleChip.H> |
| 22 | |
| 23 | //---------------------------------------------------------------------- |
| 24 | // User Types |
| 25 | //---------------------------------------------------------------------- |
| 26 | |
| 27 | //---------------------------------------------------------------------- |
| 28 | // Constants |
| 29 | //---------------------------------------------------------------------- |
| 30 | |
| 31 | //---------------------------------------------------------------------- |
| 32 | // Macros |
| 33 | //---------------------------------------------------------------------- |
| 34 | |
| 35 | //---------------------------------------------------------------------- |
| 36 | // Internal Function Prototypes |
| 37 | //---------------------------------------------------------------------- |
| 38 | |
| 39 | //---------------------------------------------------------------------- |
| 40 | // Global Variables |
| 41 | //---------------------------------------------------------------------- |
| 42 | |
| 43 | //--------------------------------------------------------------------- |
| 44 | // Member Function Specifications |
| 45 | //--------------------------------------------------------------------- |
| 46 | |
| 47 | // -------------------------------------------------------------------- |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 48 | namespace libhei |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 49 | { |
| 50 | |
| 51 | // --------------------------------------------------------------------- |
| 52 | |
| 53 | void ScomRegister::SetBitString( const BitString *bs ) |
| 54 | { |
| 55 | BitString & l_string = AccessBitString(); |
| 56 | l_string.setString(*bs); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | //------------------------------------------------------------------------------ |
| 61 | |
| 62 | const BitString * ScomRegister::GetBitString(ATTENTION_TYPE i_type) const |
| 63 | { |
| 64 | // Calling Read() will ensure that an entry exists in the cache and the |
| 65 | // entry has at been synched with hardware at least once. Note that we |
| 66 | // cannot read hardware for write-only registers. In this case, an entry |
| 67 | // will be created in the cache, if it does not exist, when readCache() is |
| 68 | // called below. |
| 69 | if ( ( ACCESS_NONE != iv_operationType ) && |
| 70 | ( ACCESS_WO != iv_operationType ) ) |
| 71 | { |
| 72 | Read(); |
| 73 | } |
| 74 | return &(readCache()); |
| 75 | } |
| 76 | |
| 77 | //------------------------------------------------------------------------------ |
| 78 | |
| 79 | BitString & ScomRegister::AccessBitString() |
| 80 | { |
| 81 | // Calling Read() will ensure that an entry exists in the cache and the |
| 82 | // entry has at been synched with hardware at least once. Note that we |
| 83 | // cannot read hardware for write-only registers. In this case, an entry |
| 84 | // will be created in the cache, if it does not exist, when readCache() is |
| 85 | // called below. |
| 86 | if ( ( ACCESS_NONE != iv_operationType ) && |
| 87 | ( ACCESS_WO != iv_operationType ) ) |
| 88 | { |
| 89 | Read(); |
| 90 | } |
| 91 | |
| 92 | return readCache(); |
| 93 | } |
| 94 | |
| 95 | //------------------------------------------------------------------------------ |
| 96 | |
| 97 | uint32_t ScomRegister::Read() const |
| 98 | { |
| 99 | uint32_t o_rc = SUCCESS; |
| 100 | |
| 101 | // First query the cache for an existing entry. |
| 102 | if ( !queryCache() ) |
| 103 | { |
| 104 | // There was not a previous entry in the cache, so do a ForceRead() to |
| 105 | // sync the cache with hardware. |
| 106 | o_rc = ForceRead(); |
| 107 | } |
| 108 | |
| 109 | return o_rc; |
| 110 | } |
| 111 | |
| 112 | //------------------------------------------------------------------------------ |
| 113 | |
| 114 | uint32_t ScomRegister::ForceRead() const |
| 115 | { |
| 116 | #define PRDF_FUNC "[ScomRegister::ForceRead] " |
| 117 | |
| 118 | uint32_t o_rc = FAIL; |
| 119 | |
| 120 | do |
| 121 | { |
| 122 | // No read allowed if register access attribute is write-only or no |
| 123 | // access. |
| 124 | if ( ( ACCESS_NONE == iv_operationType ) && |
| 125 | ( ACCESS_WO == iv_operationType ) ) |
| 126 | { |
| 127 | PRDF_ERR( PRDF_FUNC "Write-only register: 0x%08x 0x%016llx", |
| 128 | getChip()->GetId(), iv_scomAddress ); |
| 129 | break; |
| 130 | } |
| 131 | |
| 132 | // Read hardware. |
Zane Shelley | ea1a1ac | 2019-08-08 16:27:20 -0500 | [diff] [blame] | 133 | o_rc = Access( readCache(), RegisterAccess::READ ); |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 134 | if ( SUCCESS != o_rc ) |
| 135 | { |
| 136 | // The read failed. Remove the entry from the cache so a subsequent |
| 137 | // Read() will attempt to read from hardware again. |
| 138 | flushCache( getChip() ); |
| 139 | } |
| 140 | |
| 141 | } while (0); |
| 142 | |
| 143 | return o_rc; |
| 144 | |
| 145 | #undef PRDF_FUNC |
| 146 | } |
| 147 | |
| 148 | //------------------------------------------------------------------------------ |
| 149 | |
| 150 | uint32_t ScomRegister::Write() |
| 151 | { |
| 152 | #define PRDF_FUNC "[ScomRegister::Write] " |
| 153 | |
| 154 | uint32_t o_rc = FAIL; |
| 155 | |
| 156 | do |
| 157 | { |
| 158 | // No write allowed if register access attribute is read-only or no |
| 159 | // access. |
| 160 | if ( ( ACCESS_NONE == iv_operationType ) && |
| 161 | ( ACCESS_RO == iv_operationType ) ) |
| 162 | { |
| 163 | PRDF_ERR( PRDF_FUNC "Read-only register: 0x%08x 0x%016llx", |
| 164 | getChip()->GetId(), iv_scomAddress ); |
| 165 | break; |
| 166 | } |
| 167 | |
| 168 | // Query the cache for an existing entry. |
| 169 | if ( !queryCache() ) |
| 170 | { |
| 171 | // Something bad happened and there was nothing in the cache to |
| 172 | // write to hardware. |
| 173 | PRDF_ERR( PRDF_FUNC "No entry found in cache: 0x%08x 0x%016llx", |
| 174 | getChip()->GetId(), iv_scomAddress ); |
| 175 | break; |
| 176 | } |
| 177 | |
| 178 | // Write hardware. |
Zane Shelley | ea1a1ac | 2019-08-08 16:27:20 -0500 | [diff] [blame] | 179 | o_rc = Access( readCache(), RegisterAccess::WRITE ); |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 180 | |
| 181 | } while (0); |
| 182 | |
| 183 | return o_rc; |
| 184 | |
| 185 | #undef PRDF_FUNC |
| 186 | } |
| 187 | |
| 188 | //------------------------------------------------------------------------------ |
| 189 | |
| 190 | uint32_t ScomRegister::Access( BitString & bs, |
Zane Shelley | ea1a1ac | 2019-08-08 16:27:20 -0500 | [diff] [blame] | 191 | RegisterAccess::Operation op ) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 192 | { |
| 193 | int32_t l_rc = SCR_ACCESS_FAILED; |
| 194 | TARGETING::TargetHandle_t i_pchipTarget = getChip()->GetChipHandle(); |
| 195 | l_rc = getScomService().Access( i_pchipTarget,bs,iv_scomAddress,op ); |
| 196 | |
| 197 | return(l_rc); |
| 198 | } |
| 199 | //----------------------------------------------------------------------------- |
| 200 | ExtensibleChip* ScomRegister::getChip( )const |
| 201 | { |
| 202 | ExtensibleChip* l_pchip = NULL; |
| 203 | l_pchip = ServiceDataCollector::getChipAnalyzed(); |
| 204 | TARGETING::TYPE l_type = PlatServices::getTargetType( |
| 205 | l_pchip->GetChipHandle() ); |
| 206 | PRDF_ASSERT( iv_chipType == l_type ) |
| 207 | return l_pchip; |
| 208 | } |
| 209 | |
| 210 | //------------------------------------------------------------------------------ |
| 211 | |
| 212 | bool ScomRegister::queryCache() const |
| 213 | { |
| 214 | RegDataCache & cache = RegDataCache::getCachedRegisters(); |
| 215 | BitString * bs = cache.queryCache( getChip(), this ); |
| 216 | return ( NULL != bs ); |
| 217 | } |
| 218 | |
| 219 | //------------------------------------------------------------------------------ |
| 220 | |
| 221 | BitString & ScomRegister::readCache() const |
| 222 | { |
| 223 | RegDataCache & cache = RegDataCache::getCachedRegisters(); |
| 224 | return cache.read( getChip(), this ); |
| 225 | } |
| 226 | |
| 227 | //------------------------------------------------------------------------------ |
| 228 | |
| 229 | void ScomRegister::flushCache( ExtensibleChip *i_pChip ) const |
| 230 | { |
| 231 | RegDataCache & regDump = RegDataCache::getCachedRegisters(); |
| 232 | if( NULL == i_pChip ) |
| 233 | { |
| 234 | regDump.flush(); |
| 235 | } |
| 236 | else |
| 237 | { |
| 238 | regDump.flush( i_pChip ,this ); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | //----------------------------------------------------------------------------- |
| 243 | |
| 244 | bool ScomRegister::operator == ( const ScomRegister & i_rightRegister ) const |
| 245 | { |
| 246 | if( iv_scomAddress == i_rightRegister.GetAddress() ) |
| 247 | { |
| 248 | return ( iv_chipType == i_rightRegister.getChipType() ); |
| 249 | } |
| 250 | else |
| 251 | { |
| 252 | return false ; |
| 253 | } |
| 254 | |
| 255 | } |
| 256 | |
| 257 | //----------------------------------------------------------------------------- |
| 258 | bool ScomRegister::operator < ( const ScomRegister & i_rightRegister ) const |
| 259 | { |
| 260 | if( iv_scomAddress == i_rightRegister.GetAddress() ) |
| 261 | { |
| 262 | return ( iv_chipType < i_rightRegister.getChipType() ); |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | return( iv_scomAddress < i_rightRegister.GetAddress() ); |
| 267 | } |
| 268 | |
| 269 | |
| 270 | } |
| 271 | //----------------------------------------------------------------------------- |
| 272 | bool ScomRegister::operator >= ( const ScomRegister & i_rightRegister ) const |
| 273 | { |
| 274 | return !( *this < i_rightRegister ); |
| 275 | } |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 276 | |
| 277 | } // end namespace libhei |
| 278 | |