Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 1 | /* IBM_PROLOG_BEGIN_TAG */ |
| 2 | /* This is an automatically generated prolog. */ |
| 3 | /* */ |
| 4 | /* $Source: src/usr/diag/prdf/common/framework/register/prdfRegisterCache.C $ */ |
| 5 | /* */ |
| 6 | /* OpenPOWER HostBoot Project */ |
| 7 | /* */ |
| 8 | /* Contributors Listed Below - COPYRIGHT 2012,2017 */ |
| 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 | #include <prdfRegisterCache.H> |
| 27 | #include <iipconst.h> |
| 28 | |
| 29 | namespace PRDF |
| 30 | { |
| 31 | |
| 32 | //------------------------------------------------------------------------------ |
| 33 | |
| 34 | RegDataCache & RegDataCache::getCachedRegisters() |
| 35 | { |
| 36 | return PRDF_GET_SINGLETON( ReadCache ); |
| 37 | } |
| 38 | |
| 39 | //------------------------------------------------------------------------------ |
| 40 | |
| 41 | RegDataCache::~RegDataCache() |
| 42 | { |
| 43 | flush(); |
| 44 | } |
| 45 | |
| 46 | //------------------------------------------------------------------------------ |
| 47 | |
| 48 | BitString & RegDataCache::read( ExtensibleChip * i_chip, |
| 49 | const SCAN_COMM_REGISTER_CLASS * i_reg ) |
| 50 | { |
| 51 | ScomRegisterAccess l_scomAccessKey ( *i_reg, i_chip ); |
| 52 | BitString * l_pBitString = queryCache( l_scomAccessKey ); |
| 53 | |
| 54 | if ( NULL == l_pBitString ) |
| 55 | { |
| 56 | // Creating new entry |
| 57 | l_pBitString = new BitStringBuffer( i_reg->GetBitLength() ); |
| 58 | // Adding register in the cache |
| 59 | iv_cachedRead[l_scomAccessKey] = l_pBitString; |
| 60 | } |
| 61 | |
| 62 | return *l_pBitString; |
| 63 | } |
| 64 | |
| 65 | //------------------------------------------------------------------------------ |
| 66 | |
| 67 | void RegDataCache::flush() |
| 68 | { |
| 69 | for ( CacheDump::iterator it = iv_cachedRead.begin(); |
| 70 | it != iv_cachedRead.end(); it++ ) |
| 71 | { |
| 72 | // Freeing up the bit string memory reserved on heap |
| 73 | delete it->second; |
| 74 | } |
| 75 | |
| 76 | // Deleting all the entry from the cache |
| 77 | iv_cachedRead.clear(); |
| 78 | } |
| 79 | |
| 80 | //------------------------------------------------------------------------------ |
| 81 | |
| 82 | void RegDataCache::flush( ExtensibleChip* i_pChip, |
| 83 | const SCAN_COMM_REGISTER_CLASS * i_pRegister ) |
| 84 | { |
| 85 | ScomRegisterAccess l_scomAccessKey ( *i_pRegister,i_pChip ); |
| 86 | // Find the entries associated with the given target in the map |
| 87 | CacheDump::iterator it = iv_cachedRead.find( l_scomAccessKey ); |
| 88 | |
| 89 | // If entry exists delete the entry for given scom address |
| 90 | if ( it !=iv_cachedRead.end() ) |
| 91 | { |
| 92 | delete it->second; |
| 93 | iv_cachedRead.erase( it ); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | //------------------------------------------------------------------------------ |
| 98 | |
| 99 | BitString * RegDataCache::queryCache( |
| 100 | ExtensibleChip* i_pChip, |
| 101 | const SCAN_COMM_REGISTER_CLASS * i_pRegister )const |
| 102 | { |
| 103 | ScomRegisterAccess l_scomAccessKey ( *i_pRegister,i_pChip ); |
| 104 | return queryCache( l_scomAccessKey ); |
| 105 | } |
| 106 | |
| 107 | //------------------------------------------------------------------------------ |
| 108 | |
| 109 | BitString * RegDataCache::queryCache( |
| 110 | const ScomRegisterAccess & i_scomAccessKey ) const |
| 111 | { |
| 112 | BitString * l_pBitString = NULL; |
| 113 | CacheDump::const_iterator itDump = iv_cachedRead.find( i_scomAccessKey ); |
| 114 | if( iv_cachedRead.end() != itDump ) |
| 115 | { |
| 116 | l_pBitString = itDump->second ; |
| 117 | } |
| 118 | |
| 119 | return l_pBitString; |
| 120 | } |
| 121 | |
| 122 | //------------------------------------------------------------------------------ |
| 123 | }// end namespace PRDF |