blob: ddea721919dc0ce8631872da037c28294c97b550 [file] [log] [blame]
Zane Shelley871adec2019-07-30 11:01:39 -05001#pragma once
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05002
3/**
4 * @brief Models register.It does not contain target.
5 *
6 * This class stores the hash id and bit length of scom registers It models
7 * registers without maintaining target information. Instances of this class
8 * are shared across rule chip objects of same type.Once prd object model is
9 * built, instances of this register are saved in flyweight.These instances
10 * persist as long as prd object model survives.
11 */
12
Zane Shelley52cb1a92019-08-21 14:38:31 -050013#include <hei_includes.hpp>
14#include <register/hei_register.hpp>
15#include <util/hei_bit_string.hpp>
16
Zane Shelleyea1a1ac2019-08-08 16:27:20 -050017#include <prdfHomRegisterAccess.H>
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050018
Zane Shelley871adec2019-07-30 11:01:39 -050019namespace libhei
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050020{
21
22// Forward References
23class CHIP_CLASS;
24class MopsRegisterAccess;
25class ExtensibleChip;
26
Zane Shelleycd36f432019-08-30 21:22:07 -050027class HardwareRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050028{
29 public:
30
31 /**
32 * @brief constructor
33 * @param i_address address of the register
34 * @param i_bitLength bit length of register
35 * @param i_targetType target type associated with register
36 */
Zane Shelleycd36f432019-08-30 21:22:07 -050037 HardwareRegister( uint64_t i_address, uint32_t i_bitLength,
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050038 TARGETING::TYPE i_targetType, AccessLevel i_access ) :
Zane Shelley23244cb2019-08-30 21:12:12 -050039 Register(),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050040 iv_bitLength( i_bitLength ),
41 iv_chipType( i_targetType ),
42 iv_scomAddress( i_address ),
43 iv_operationType( i_access )
44 {}
45
46 /**
47 * @brief constructor .Added this because we save object of this type in
48 * @ FlyweightS
49 */
Zane Shelleycd36f432019-08-30 21:22:07 -050050 HardwareRegister():
Zane Shelley23244cb2019-08-30 21:12:12 -050051 Register(),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050052 iv_bitLength( 0 ),
53 iv_chipType( TARGETING::TYPE_NA ),
54 iv_scomAddress( 0 ),
55 iv_operationType( ACCESS_NONE )
56 {}
57
58 /**
59 * @brief Returns the pointer to bit string
60 * @param i_type attention type
61 * @return BitString * pointer to bit string
62 */
63
64 virtual const BitString * GetBitString(ATTENTION_TYPE i_type =
65 INVALID_ATTENTION_TYPE) const;
66 /**
67 * @brief Updates bit string contents associated with register
68 * @param i_bs poiner to bit string
69 * @return Nil
70 */
71
72 virtual void SetBitString(const BitString * i_bs) ;
73
74 /**
75 * @brief Returns length of the bits string associated with register
76 * @return length of bit string
77 */
78 uint32_t GetBitLength(void) const { return iv_bitLength ;}
79
80 /**
81 * @brief Directly reads from hardware register
82 * @return SUCCESS|FAIL
83 */
84 virtual uint32_t ForceRead() const;
85
86 /**
87 * @brief Returns contents of register.If entry does not exist in cache
88 * a fresh entry is created and hardware is read.
89 * @return SUCCESS|FAIL
90 */
91 virtual uint32_t Read() const;
92
93 /**
94 * @brief Writes cache contents to register.
95 * @return SUCCESS|FAIL
96 */
97 virtual uint32_t Write();
98
99 /**
100 * @brief Returns the hash id of register
101 * @return returns hash id of register
102 * @pre None
103 * @post None
104 * @note
105 */
106 virtual uint16_t GetId(void) const { return iv_shortId; };
107
108 /**
109 * @brief Sets the hash id of register
110 * @param i_id hash id of register
111 * @return Nil
112 */
113 virtual void SetId(uint16_t i_id) { iv_shortId = i_id; };
114
115 /**
116 * @brief Returns type of Target associated with register.
117 * @return Refer to function description
118 */
119 TARGETING::TYPE getChipType()const{ return iv_chipType ;} ;
120 /**
121 * @brief Returns scom address of register
122 * @return Refer to function description
123 */
124 uint64_t GetAddress( ) const {return iv_scomAddress ;};
125 /**
126 * @brief compares two ScomRegisterAccess register for equality
127 * @param i_rightRegister register to be compared against
128 * @return Returns true if registers are equal false otherwise
129 */
Zane Shelleycd36f432019-08-30 21:22:07 -0500130 bool operator == ( const HardwareRegister & i_rightRegister ) const ;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500131 /**
132 * @brief defines < operation for ScomRegisterAccess
133 * @param i_rightRegister register to be compared against
134 * @return Returns false if i_rightRegisters is less and true otherwise
135 */
Zane Shelleycd36f432019-08-30 21:22:07 -0500136 bool operator < ( const HardwareRegister & i_rightRegister ) const ;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500137 /**
138 * @brief defines >= operation for ScomRegisterAccess
139 * @param i_rightRegister register to be compared against
140 * @return Returns true if registers is >= i_rightRegister false
141 * otherwise
142 */
Zane Shelleycd36f432019-08-30 21:22:07 -0500143 bool operator >= ( const HardwareRegister & i_rightRegister ) const;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500144
145 /** @return The register access level (see enum AccessLevel). */
146 virtual AccessLevel getAccessLevel() const { return iv_operationType; }
147
148 /** @brief Sets the register access level (see enum AccessLevel). */
149 virtual void setAccessLevel( AccessLevel i_op ) { iv_operationType = i_op; }
150
151 protected: // Functions
152
153 /**
154 * @brief copy constructor
155 * @param i_scomRegister scomRegister instance to be copied
156 */
Zane Shelleycd36f432019-08-30 21:22:07 -0500157 HardwareRegister( const Register & i_scomRegister ):
Zane Shelley23244cb2019-08-30 21:12:12 -0500158 Register(),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500159 iv_bitLength( i_scomRegister.GetBitLength() ),
160 iv_shortId( i_scomRegister.GetId() ),
161 iv_chipType( i_scomRegister.getChipType() ),
162 iv_scomAddress( i_scomRegister.GetAddress() ),
163 iv_operationType( i_scomRegister.getAccessLevel() )
164 {}
165
166 /**
167 * @brief Returns reference to bit string associated with register
168 * @return Refer to function description
169 */
170 virtual BitString & AccessBitString( );
171 /**
172 * @brief Gets the register read and write done by calling access
173 * function of scom accessor service.
174 * @param reference to bit string maintained in caller class
175 * @param Read or write operation
176 * @return [SUCCESS|FAIL]
177 */
178 uint32_t Access( BitString & bs,
Zane Shelleyea1a1ac2019-08-08 16:27:20 -0500179 RegisterAccess::Operation op )const;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500180
181 /**
182 * @brief Returns rulechip pointer associated with the register
183 * @return Refer to function description
184 */
185 virtual ExtensibleChip * getChip() const;
186
187private: // functions
188
189 friend class CaptureData;
190
191 /** @return TRUE if entry for this register exist in this cache. */
192 bool queryCache() const;
193
194 /**
195 * @brief Reads register contents from cache.
196 * @return Reference to bit string buffer maintained in cache.
197 */
198 BitString & readCache() const;
199
200 /**
201 * @brief Deletes one or all entry in the cache
202 * @param RuleChip pointer associated with register
203 * @return Nil
204 */
205 void flushCache( ExtensibleChip *i_pChip = NULL ) const;
206
207 private: // Data
208
209 uint32_t iv_bitLength; // bit length of scom
210 uint16_t iv_shortId; // unique hash id of register
211 TARGETING::TYPE iv_chipType; // type of target associated with register
212 uint64_t iv_scomAddress; // scom address associated with regiser
213 AccessLevel iv_operationType; // Operation supported (RO, WO, or RW)
214
215};
216
Zane Shelley871adec2019-07-30 11:01:39 -0500217} // end namespace libhei
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500218