blob: 0c1e871e7767e03968dd7e7a80fd303cb64dbce9 [file] [log] [blame]
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05001// 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 Shelley52cb1a92019-08-21 14:38:31 -050012#include <hei_includes.hpp>
Zane Shelley61565dc2019-09-18 21:57:10 -050013#include <hei_user_interface.hpp>
Zane Shelley52cb1a92019-08-21 14:38:31 -050014#include <register/hei_hardware_register.hpp>
15#include <util/hei_bit_string.hpp>
16
Zane Shelleyb77b5732019-08-30 22:01:06 -050017#if 0
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050018#include <iipchip.h>
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050019#include <prdfMain.H>
20#include <prdfRasServices.H>
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050021#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 Shelleyb77b5732019-08-30 22:01:06 -050049#endif
50
Zane Shelley871adec2019-07-30 11:01:39 -050051namespace libhei
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050052{
53
Zane Shelley8deb0902019-10-14 15:52:27 -050054//------------------------------------------------------------------------------
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050055
Zane Shelley8deb0902019-10-14 15:52:27 -050056HardwareRegister::~HardwareRegister() {}
57
58//------------------------------------------------------------------------------
59
60#if 0
Zane Shelleycd36f432019-08-30 21:22:07 -050061void HardwareRegister::SetBitString( const BitString *bs )
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050062{
63 BitString & l_string = AccessBitString();
64 l_string.setString(*bs);
65}
66
67
68//------------------------------------------------------------------------------
69
Zane Shelleycd36f432019-08-30 21:22:07 -050070const BitString * HardwareRegister::GetBitString(ATTENTION_TYPE i_type) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050071{
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 Shelleyd0af3582019-09-19 10:48:59 -050075 // will be created in the cache, if it does not exist, when the cache is
76 // read below.
77
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050078 if ( ( ACCESS_NONE != iv_operationType ) &&
Zane Shelleyd0af3582019-09-19 10:48:59 -050079 ( ACCESS_WO != iv_operationType ) )
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050080 {
81 Read();
82 }
Zane Shelleyd0af3582019-09-19 10:48:59 -050083
84 return &( accessCache() );
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050085}
86
87//------------------------------------------------------------------------------
88
Zane Shelleycd36f432019-08-30 21:22:07 -050089BitString & HardwareRegister::AccessBitString()
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050090{
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 Shelleyd0af3582019-09-19 10:48:59 -050094 // will be created in the cache, if it does not exist, when the cache is
95 // read below.
96
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050097 if ( ( ACCESS_NONE != iv_operationType ) &&
Zane Shelleyd0af3582019-09-19 10:48:59 -050098 ( ACCESS_WO != iv_operationType ) )
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050099 {
100 Read();
101 }
102
Zane Shelleyd0af3582019-09-19 10:48:59 -0500103 return accessCache();
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500104}
Zane Shelley61565dc2019-09-18 21:57:10 -0500105#endif
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500106
107//------------------------------------------------------------------------------
108
Zane Shelley61565dc2019-09-18 21:57:10 -0500109ReturnCode HardwareRegister::read( bool i_force ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500110{
Zane Shelley61565dc2019-09-18 21:57:10 -0500111 ReturnCode rc;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500112
Zane Shelley61565dc2019-09-18 21:57:10 -0500113 // 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 Shelleyfd3f9cc2019-07-29 15:02:24 -0500116 {
Zane Shelleyd0af3582019-09-19 10:48:59 -0500117#if 0
Zane Shelley61565dc2019-09-18 21:57:10 -0500118 // 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 Shelleyd0af3582019-09-19 10:48:59 -0500123 BitString & bs = accessCache();
Zane Shelley61565dc2019-09-18 21:57:10 -0500124
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 Shelleyd0af3582019-09-19 10:48:59 -0500131#endif
Zane Shelley61565dc2019-09-18 21:57:10 -0500132 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 Shelleyd0af3582019-09-19 10:48:59 -0500136 cv_cache.flush( getAccessorChip(), this );
Zane Shelley61565dc2019-09-18 21:57:10 -0500137 }
Zane Shelleyd0af3582019-09-19 10:48:59 -0500138#if 0
Zane Shelley61565dc2019-09-18 21:57:10 -0500139 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 Shelley61565dc2019-09-18 21:57:10 -0500145#endif
Zane Shelleyd0af3582019-09-19 10:48:59 -0500146 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500147
Zane Shelley61565dc2019-09-18 21:57:10 -0500148 return rc;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500149}
150
151//------------------------------------------------------------------------------
152
Zane Shelley61565dc2019-09-18 21:57:10 -0500153#ifndef __HEI_READ_ONLY
154
155ReturnCode HardwareRegister::write() const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500156{
Zane Shelley61565dc2019-09-18 21:57:10 -0500157 ReturnCode rc;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500158
Zane Shelley61565dc2019-09-18 21:57:10 -0500159#if 0
160 // This register must be writable.
161 HEI_ASSERT( ( ACCESS_NONE != iv_operationType ) &&
162 ( ACCESS_RO != iv_operationType ) );
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500163
Zane Shelley61565dc2019-09-18 21:57:10 -0500164 // An entry for this register must exist in the cache.
165 HEI_ASSERT( queryCache() );
166
167 // Get the buffer from the register cache.
Zane Shelleyd0af3582019-09-19 10:48:59 -0500168 BitString & bs = accessCache();
Zane Shelley61565dc2019-09-18 21:57:10 -0500169
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 Shelleyfd3f9cc2019-07-29 15:02:24 -0500178 {
Zane Shelley61565dc2019-09-18 21:57:10 -0500179 // 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 Shelleyfd3f9cc2019-07-29 15:02:24 -0500184
Zane Shelley61565dc2019-09-18 21:57:10 -0500185 return rc;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500186}
187
Zane Shelley61565dc2019-09-18 21:57:10 -0500188#endif // __HEI_READ_ONLY
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500189
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500190//------------------------------------------------------------------------------
191
Zane Shelleycd36f432019-08-30 21:22:07 -0500192bool HardwareRegister::operator == ( const HardwareRegister & i_rightRegister ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500193{
Zane Shelley65ed96a2019-10-14 13:06:11 -0500194#if 0
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500195 if( iv_scomAddress == i_rightRegister.GetAddress() )
196 {
197 return ( iv_chipType == i_rightRegister.getChipType() );
198 }
199 else
200 {
201 return false ;
202 }
Zane Shelley65ed96a2019-10-14 13:06:11 -0500203#endif
204 return false;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500205}
206
207//-----------------------------------------------------------------------------
Zane Shelleycd36f432019-08-30 21:22:07 -0500208bool HardwareRegister::operator < ( const HardwareRegister & i_rightRegister ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500209{
Zane Shelley65ed96a2019-10-14 13:06:11 -0500210#if 0
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500211 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 Shelley65ed96a2019-10-14 13:06:11 -0500219#endif
220 return false;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500221}
Zane Shelley65ed96a2019-10-14 13:06:11 -0500222#if 0
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500223//-----------------------------------------------------------------------------
Zane Shelleycd36f432019-08-30 21:22:07 -0500224bool HardwareRegister::operator >= ( const HardwareRegister & i_rightRegister ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500225{
226 return !( *this < i_rightRegister );
227}
Zane Shelleyb77b5732019-08-30 22:01:06 -0500228#endif
Zane Shelley871adec2019-07-30 11:01:39 -0500229
Zane Shelley61565dc2019-09-18 21:57:10 -0500230//------------------------------------------------------------------------------
231
232HardwareRegister::Accessor * HardwareRegister::cv_accessor = nullptr;
233
234//------------------------------------------------------------------------------
235
Zane Shelleyd0af3582019-09-19 10:48:59 -0500236HardwareRegister::Cache HardwareRegister::cv_cache {};
237
238//------------------------------------------------------------------------------
239
240bool 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
262BitString & 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
278void 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
298void 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 Shelley871adec2019-07-30 11:01:39 -0500326} // end namespace libhei
327