Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 1 | #pragma once |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 2 | |
| 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 Shelley | 52cb1a9 | 2019-08-21 14:38:31 -0500 | [diff] [blame] | 13 | #include <hei_includes.hpp> |
| 14 | #include <register/hei_register.hpp> |
| 15 | #include <util/hei_bit_string.hpp> |
| 16 | |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 17 | namespace libhei |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 18 | { |
| 19 | |
Zane Shelley | b77b573 | 2019-08-30 22:01:06 -0500 | [diff] [blame] | 20 | #if 0 |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 21 | // Forward References |
| 22 | class CHIP_CLASS; |
| 23 | class MopsRegisterAccess; |
| 24 | class ExtensibleChip; |
Zane Shelley | b77b573 | 2019-08-30 22:01:06 -0500 | [diff] [blame] | 25 | #endif |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 26 | |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame^] | 27 | /** |
| 28 | * @brief Stores information (e.g. address, type, length, etc.) for an actual |
| 29 | * hardware register. |
| 30 | * |
| 31 | * Hardware access: |
| 32 | * |
| 33 | * Actual hardware access is defined by the user application via the user |
| 34 | * interface APIs. In order to tell the user application which chip to target, |
| 35 | * the user application gives the isolator pointers to its chip objects. As |
| 36 | * each chip needs to be accessed, the isolator must store the chip in a |
| 37 | * static variable defined in this class. The intended use is: |
| 38 | * |
| 39 | * - Call HardwareRegister::setAccessor() with the target chip. |
| 40 | * - Perform all necessary hardware accesses to that chip. |
| 41 | * - Call HardwareRegister::clearAccessor() to remove the chip access. This |
| 42 | * helps ensure we don't try to access the wrong chip. |
| 43 | */ |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 44 | class HardwareRegister : public Register |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 45 | { |
| 46 | public: |
| 47 | |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame^] | 48 | #if 0 |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 49 | /** |
| 50 | * @brief constructor |
| 51 | * @param i_address address of the register |
| 52 | * @param i_bitLength bit length of register |
| 53 | * @param i_targetType target type associated with register |
| 54 | */ |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 55 | HardwareRegister( uint64_t i_address, uint32_t i_bitLength, |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 56 | TARGETING::TYPE i_targetType, AccessLevel i_access ) : |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 57 | Register(), |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 58 | iv_bitLength( i_bitLength ), |
| 59 | iv_chipType( i_targetType ), |
| 60 | iv_scomAddress( i_address ), |
| 61 | iv_operationType( i_access ) |
| 62 | {} |
| 63 | |
| 64 | /** |
| 65 | * @brief constructor .Added this because we save object of this type in |
| 66 | * @ FlyweightS |
| 67 | */ |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 68 | HardwareRegister(): |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 69 | Register(), |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 70 | iv_bitLength( 0 ), |
| 71 | iv_chipType( TARGETING::TYPE_NA ), |
| 72 | iv_scomAddress( 0 ), |
| 73 | iv_operationType( ACCESS_NONE ) |
| 74 | {} |
| 75 | |
| 76 | /** |
| 77 | * @brief Returns the pointer to bit string |
| 78 | * @param i_type attention type |
| 79 | * @return BitString * pointer to bit string |
| 80 | */ |
| 81 | |
| 82 | virtual const BitString * GetBitString(ATTENTION_TYPE i_type = |
| 83 | INVALID_ATTENTION_TYPE) const; |
| 84 | /** |
| 85 | * @brief Updates bit string contents associated with register |
| 86 | * @param i_bs poiner to bit string |
| 87 | * @return Nil |
| 88 | */ |
| 89 | |
| 90 | virtual void SetBitString(const BitString * i_bs) ; |
| 91 | |
| 92 | /** |
| 93 | * @brief Returns length of the bits string associated with register |
| 94 | * @return length of bit string |
| 95 | */ |
| 96 | uint32_t GetBitLength(void) const { return iv_bitLength ;} |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame^] | 97 | #endif |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 98 | |
| 99 | /** |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame^] | 100 | * @brief Reads a register from hardware via the user interface APIs. |
| 101 | * @param i_force When false, this function will only read from hardware if |
| 102 | * an entry for this instance does not already exist in the |
| 103 | * register cache. When true, the entry in the register |
| 104 | * cache is flushed, if it exists. Then this function will |
| 105 | * read from hardware and update the cache. |
| 106 | * @return See the return code from the registerRead() user interface API. |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 107 | */ |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame^] | 108 | ReturnCode read( bool i_force = false ) const; |
| 109 | |
| 110 | #ifndef __HEI_READ_ONLY |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 111 | |
| 112 | /** |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame^] | 113 | * @brief Writes the value stored in the register cache to hardware via the |
| 114 | * user interface APIs. |
| 115 | * @return See the return code from the registerWrite() user interface API. |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 116 | */ |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame^] | 117 | ReturnCode write() const; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 118 | |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame^] | 119 | #endif // __HEI_READ_ONLY |
| 120 | |
| 121 | #if 0 |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 122 | /** |
| 123 | * @brief Returns the hash id of register |
| 124 | * @return returns hash id of register |
| 125 | * @pre None |
| 126 | * @post None |
| 127 | * @note |
| 128 | */ |
| 129 | virtual uint16_t GetId(void) const { return iv_shortId; }; |
| 130 | |
| 131 | /** |
| 132 | * @brief Sets the hash id of register |
| 133 | * @param i_id hash id of register |
| 134 | * @return Nil |
| 135 | */ |
| 136 | virtual void SetId(uint16_t i_id) { iv_shortId = i_id; }; |
| 137 | |
| 138 | /** |
| 139 | * @brief Returns type of Target associated with register. |
| 140 | * @return Refer to function description |
| 141 | */ |
| 142 | TARGETING::TYPE getChipType()const{ return iv_chipType ;} ; |
| 143 | /** |
| 144 | * @brief Returns scom address of register |
| 145 | * @return Refer to function description |
| 146 | */ |
| 147 | uint64_t GetAddress( ) const {return iv_scomAddress ;}; |
| 148 | /** |
| 149 | * @brief compares two ScomRegisterAccess register for equality |
| 150 | * @param i_rightRegister register to be compared against |
| 151 | * @return Returns true if registers are equal false otherwise |
| 152 | */ |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 153 | bool operator == ( const HardwareRegister & i_rightRegister ) const ; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 154 | /** |
| 155 | * @brief defines < operation for ScomRegisterAccess |
| 156 | * @param i_rightRegister register to be compared against |
| 157 | * @return Returns false if i_rightRegisters is less and true otherwise |
| 158 | */ |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 159 | bool operator < ( const HardwareRegister & i_rightRegister ) const ; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 160 | /** |
| 161 | * @brief defines >= operation for ScomRegisterAccess |
| 162 | * @param i_rightRegister register to be compared against |
| 163 | * @return Returns true if registers is >= i_rightRegister false |
| 164 | * otherwise |
| 165 | */ |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 166 | bool operator >= ( const HardwareRegister & i_rightRegister ) const; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 167 | |
| 168 | /** @return The register access level (see enum AccessLevel). */ |
| 169 | virtual AccessLevel getAccessLevel() const { return iv_operationType; } |
| 170 | |
| 171 | /** @brief Sets the register access level (see enum AccessLevel). */ |
| 172 | virtual void setAccessLevel( AccessLevel i_op ) { iv_operationType = i_op; } |
| 173 | |
| 174 | protected: // Functions |
| 175 | |
| 176 | /** |
| 177 | * @brief copy constructor |
| 178 | * @param i_scomRegister scomRegister instance to be copied |
| 179 | */ |
Zane Shelley | cd36f43 | 2019-08-30 21:22:07 -0500 | [diff] [blame] | 180 | HardwareRegister( const Register & i_scomRegister ): |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 181 | Register(), |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 182 | iv_bitLength( i_scomRegister.GetBitLength() ), |
| 183 | iv_shortId( i_scomRegister.GetId() ), |
| 184 | iv_chipType( i_scomRegister.getChipType() ), |
| 185 | iv_scomAddress( i_scomRegister.GetAddress() ), |
| 186 | iv_operationType( i_scomRegister.getAccessLevel() ) |
| 187 | {} |
| 188 | |
| 189 | /** |
| 190 | * @brief Returns reference to bit string associated with register |
| 191 | * @return Refer to function description |
| 192 | */ |
| 193 | virtual BitString & AccessBitString( ); |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 194 | |
| 195 | private: // functions |
| 196 | |
| 197 | friend class CaptureData; |
| 198 | |
| 199 | /** @return TRUE if entry for this register exist in this cache. */ |
| 200 | bool queryCache() const; |
| 201 | |
| 202 | /** |
| 203 | * @brief Reads register contents from cache. |
| 204 | * @return Reference to bit string buffer maintained in cache. |
| 205 | */ |
| 206 | BitString & readCache() const; |
| 207 | |
| 208 | /** |
| 209 | * @brief Deletes one or all entry in the cache |
| 210 | * @param RuleChip pointer associated with register |
| 211 | * @return Nil |
| 212 | */ |
Zane Shelley | 05bac98 | 2019-09-02 20:57:42 -0500 | [diff] [blame] | 213 | void flushCache( ExtensibleChip *i_pChip = nullptr ) const; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 214 | |
| 215 | private: // Data |
| 216 | |
| 217 | uint32_t iv_bitLength; // bit length of scom |
| 218 | uint16_t iv_shortId; // unique hash id of register |
| 219 | TARGETING::TYPE iv_chipType; // type of target associated with register |
| 220 | uint64_t iv_scomAddress; // scom address associated with regiser |
| 221 | AccessLevel iv_operationType; // Operation supported (RO, WO, or RW) |
| 222 | |
Zane Shelley | b77b573 | 2019-08-30 22:01:06 -0500 | [diff] [blame] | 223 | #endif |
Zane Shelley | 61565dc | 2019-09-18 21:57:10 -0500 | [diff] [blame^] | 224 | |
| 225 | private: // Hardware accessor class variable |
| 226 | |
| 227 | /** @brief A simple class that stores the chip used to access hardware. */ |
| 228 | class Accessor |
| 229 | { |
| 230 | public: |
| 231 | |
| 232 | /** |
| 233 | * @brief Constructor. |
| 234 | * @param i_chip The chip used to access hardware. |
| 235 | */ |
| 236 | explicit Accessor( const Chip & i_chip ) : |
| 237 | iv_chip( i_chip ) |
| 238 | {} |
| 239 | |
| 240 | /** @brief Destructor. */ |
| 241 | ~Accessor() = default; |
| 242 | |
| 243 | /** @brief Copy constructor. */ |
| 244 | Accessor( const Accessor & ) = delete; |
| 245 | |
| 246 | /** @brief Assignment operator. */ |
| 247 | Accessor & operator=( const Accessor & ) = delete; |
| 248 | |
| 249 | /** @return The chip used to access hardware. */ |
| 250 | const Chip & getChip() const { return iv_chip; } |
| 251 | |
| 252 | private: |
| 253 | |
| 254 | /** |
| 255 | * A Chip object provided by the user application. The isolator does not |
| 256 | * know anything about this object nor how to use it. Its only purpose |
| 257 | * is to get passed back to the user application for hardware access |
| 258 | * operations. |
| 259 | */ |
| 260 | const Chip iv_chip; |
| 261 | |
| 262 | }; // end class Accessor |
| 263 | |
| 264 | /** |
| 265 | * This allows all HardwareRegister objects access to a chip via the user |
| 266 | * interface APIs. It is intentially defined as a pointer. It can be set to |
| 267 | * nullptr to signify that access is restricted at this time. This is useful |
| 268 | * to prevent users from accidentally accessing registers on the wrong chip. |
| 269 | * It is recommended to use setAccessor() and clearAccessor() to manage this |
| 270 | * variable. |
| 271 | */ |
| 272 | static Accessor * cv_accessor; |
| 273 | |
| 274 | public: // Hardware accessor management functions. |
| 275 | |
| 276 | /** |
| 277 | * @brief Initializes a new hardware accessor. |
| 278 | * @param i_chip The chip used to access hardware. |
| 279 | */ |
| 280 | static void setAccessor( const Chip & i_chip ) |
| 281 | { |
| 282 | clearAccessor(); |
| 283 | cv_accessor = new Accessor( i_chip ); |
| 284 | } |
| 285 | |
| 286 | /** @brief Deletes the current hardware accessor. */ |
| 287 | static void clearAccessor() |
| 288 | { |
| 289 | delete cv_accessor; |
| 290 | cv_accessor = nullptr; |
| 291 | } |
| 292 | |
| 293 | private: // Hardware accessor management functions. |
| 294 | |
| 295 | /** @return The chip stored in cv_accessor. */ |
| 296 | const Chip & getAccessorChip() const |
| 297 | { |
| 298 | HEI_ASSERT( nullptr != cv_accessor ); |
| 299 | |
| 300 | #if 0 |
| 301 | // Extra sanity check to verify this register belongs on the target |
| 302 | // accessor chip. |
| 303 | HEI_ASSERT( getChipType() != cv_accessor->getChip().getChipType() ); |
| 304 | #endif |
| 305 | |
| 306 | return cv_accessor->getChip(); |
| 307 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 308 | }; |
| 309 | |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 310 | } // end namespace libhei |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 311 | |