blob: 4fb0949e9c4f8764ef8f8216aeea02cdc15b4034 [file] [log] [blame]
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05001/* 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 Shelley52cb1a92019-08-21 14:38:31 -050026#include <hei_includes.hpp>
27
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050028#include <prdfRegisterCache.H>
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050029
30namespace PRDF
31{
32
33//------------------------------------------------------------------------------
34
35RegDataCache & RegDataCache::getCachedRegisters()
36{
37 return PRDF_GET_SINGLETON( ReadCache );
38}
39
40//------------------------------------------------------------------------------
41
42RegDataCache::~RegDataCache()
43{
44 flush();
45}
46
47//------------------------------------------------------------------------------
48
49BitString & RegDataCache::read( ExtensibleChip * i_chip,
Zane Shelley23244cb2019-08-30 21:12:12 -050050 const Register * i_reg )
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050051{
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
68void 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
83void RegDataCache::flush( ExtensibleChip* i_pChip,
Zane Shelley23244cb2019-08-30 21:12:12 -050084 const Register * i_pRegister )
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050085{
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
100BitString * RegDataCache::queryCache(
101 ExtensibleChip* i_pChip,
Zane Shelley23244cb2019-08-30 21:12:12 -0500102 const Register * i_pRegister )const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500103{
104 ScomRegisterAccess l_scomAccessKey ( *i_pRegister,i_pChip );
105 return queryCache( l_scomAccessKey );
106}
107
108//------------------------------------------------------------------------------
109
110BitString * 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