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